Skip to main content

TpdaLiquidationRouter

Git Source

Inherits: IFlashSwapCallback

Author: G9 Software Inc.

Serves as the user-facing swapping interface for Liquidation Pairs.

State Variables

_liquidationPairFactory

The TpdaLiquidationPairFactory that this router uses.

TpdaLiquidationPairs will be checked to ensure they were created by the factory

TpdaLiquidationPairFactory internal immutable _liquidationPairFactory;

Functions

constructor

Constructs a new LiquidationRouter

constructor(TpdaLiquidationPairFactory liquidationPairFactory_);

Parameters

NameTypeDescription
liquidationPairFactory_TpdaLiquidationPairFactoryThe factory that pairs will be verified to have been created by

swapExactAmountOut

Swaps the given amount of output tokens for at most input tokens

function swapExactAmountOut(
TpdaLiquidationPair _liquidationPair,
address _receiver,
uint256 _amountOut,
uint256 _amountInMax,
uint256 _deadline
) external onlyTrustedTpdaLiquidationPair(address(_liquidationPair)) returns (uint256);

Parameters

NameTypeDescription
_liquidationPairTpdaLiquidationPairThe pair to swap against
_receiveraddressThe account to receive the output tokens
_amountOutuint256The exact amount of output tokens expected
_amountInMaxuint256The maximum of input tokens to spend
_deadlineuint256The timestamp that the swap must be completed by

Returns

NameTypeDescription
<none>uint256The actual number of input tokens used

flashSwapCallback

Called on the token receiver by the LiquidationPair during a liquidation if the flashSwap data length is non-zero

function flashSwapCallback(address _sender, uint256 _amountIn, uint256, bytes calldata _flashSwapData)
external
override
onlyTrustedTpdaLiquidationPair(msg.sender)
onlySelf(_sender);

Parameters

NameTypeDescription
_senderaddressThe address that triggered the liquidation swap
_amountInuint256The amount of tokens expected to be sent to the target
<none>uint256
_flashSwapDatabytesThe flash swap data that was passed into the swap function.

onlyTrustedTpdaLiquidationPair

Checks that the given pair was created by the factory

modifier onlyTrustedTpdaLiquidationPair(address _liquidationPair);

Parameters

NameTypeDescription
_liquidationPairaddressThe pair address to check

onlySelf

Checks that the given address matches this contract

modifier onlySelf(address _sender);

Parameters

NameTypeDescription
_senderaddressThe address that called the liquidation pair

Events

LiquidationRouterCreated

Emitted when the router is created

event LiquidationRouterCreated(TpdaLiquidationPairFactory indexed liquidationPairFactory);

SwappedExactAmountOut

Emitted after a swap occurs

event SwappedExactAmountOut(
TpdaLiquidationPair indexed liquidationPair,
address indexed sender,
address indexed receiver,
uint256 amountOut,
uint256 amountInMax,
uint256 amountIn,
uint256 deadline
);

Parameters

NameTypeDescription
liquidationPairTpdaLiquidationPairThe pair that was swapped against
senderaddressThe address that initiated the swap
receiveraddressThe address that received the output tokens
amountOutuint256The amount of output tokens received
amountInMaxuint256The maximum amount of input tokens that could have been used
amountInuint256The amount of input tokens that were actually used
deadlineuint256The deadline for the swap