Skip to main content

TpdaLiquidationPair

Git Source

Inherits: ILiquidationPair

Author: G9 Software Inc.

This contract sells one token for another at a target time interval. The pricing algorithm is designed such that the price of the auction is inversely proportional to the time since the last auction. auctionPrice = (targetAuctionPeriod / elapsedTimeSinceLastAuction) * lastAuctionPrice

Constants

MIN_PRICE

uint192 constant MIN_PRICE = 100;

State Variables

source

The liquidation source

ILiquidationSource public immutable source;

targetAuctionPeriod

The target time interval between auctions

uint256 public immutable targetAuctionPeriod;

_tokenIn

The token that is being purchased

IERC20 internal immutable _tokenIn;

_tokenOut

The token that is being sold

IERC20 internal immutable _tokenOut;

smoothingFactor

The degree of smoothing to apply to the available token balance

uint256 public immutable smoothingFactor;

lastAuctionAt

The time at which the last auction occurred

uint64 public lastAuctionAt;

lastAuctionPrice

The price of the last auction

uint192 public lastAuctionPrice;

Functions

constructor

Constructors a new TpdaLiquidationPair

constructor(
ILiquidationSource _source,
address __tokenIn,
address __tokenOut,
uint64 _targetAuctionPeriod,
uint192 _targetAuctionPrice,
uint256 _smoothingFactor
);

Parameters

NameTypeDescription
_sourceILiquidationSourceThe liquidation source
__tokenInaddressThe token that is being purchased by the source
__tokenOutaddressThe token that is being sold by the source
_targetAuctionPerioduint64The target time interval between auctions
_targetAuctionPriceuint192The first target price of the auction
_smoothingFactoruint256The degree of smoothing to apply to the available token balance

tokenIn

Returns the token that is used to pay for auctions.

function tokenIn() external view returns (address);

Returns

NameTypeDescription
<none>addressaddress of the token coming in

tokenOut

Returns the token that is being auctioned.

function tokenOut() external view returns (address);

Returns

NameTypeDescription
<none>addressaddress of the token coming out

target

Get the address that will receive tokenIn.

function target() external returns (address);

Returns

NameTypeDescription
<none>addressAddress of the target

maxAmountOut

Gets the maximum amount of tokens that can be swapped out from the source.

function maxAmountOut() external returns (uint256);

Returns

NameTypeDescription
<none>uint256The maximum amount of tokens that can be swapped out.

swapExactAmountOut

Swaps the given amount of tokens out and ensures the amount of tokens in doesn't exceed the given maximum.

The amount of tokens being swapped in must be sent to the target before calling this function.

function swapExactAmountOut(address _receiver, uint256 _amountOut, uint256 _amountInMax, bytes calldata _flashSwapData)
external
returns (uint256);

Parameters

NameTypeDescription
_receiveraddressThe address to send the tokens to.
_amountOutuint256The amount of tokens to receive out.
_amountInMaxuint256The maximum amount of tokens to send in.
_flashSwapDatabytesIf non-zero, the _receiver is called with this data prior to

Returns

NameTypeDescription
<none>uint256The amount of tokens sent in.

computeExactAmountIn

Computes the exact amount of tokens to send in for the given amount of tokens to receive out.

function computeExactAmountIn(uint256) external view returns (uint256);

Parameters

NameTypeDescription
<none>uint256

Returns

NameTypeDescription
<none>uint256The amount of tokens to send in.

computeTimeForPrice

Computes the time at which the given auction price will occur

function computeTimeForPrice(uint256 price) external view returns (uint256);

Parameters

NameTypeDescription
priceuint256The price of the auction

Returns

NameTypeDescription
<none>uint256The timestamp at which the given price will occur

_availableBalance

Computes the available balance of the tokens to be sold

function _availableBalance() internal returns (uint256);

Returns

NameTypeDescription
<none>uint256The available balance of the tokens

_computePrice

Computes the current auction price

function _computePrice() internal view returns (uint192);

Returns

NameTypeDescription
<none>uint192The current auction price

Events

SwappedExactAmountOut

Emitted when a swap is made

event SwappedExactAmountOut(
address indexed sender,
address indexed receiver,
uint256 amountOut,
uint256 amountInMax,
uint256 amountIn,
bytes flashSwapData
);

Parameters

NameTypeDescription
senderaddressThe sender of the swap
receiveraddressThe receiver of the swap
amountOutuint256The amount of tokens out
amountInMaxuint256The maximum amount of tokens in
amountInuint256The actual amount of tokens in
flashSwapDatabytesThe data used for the flash swap