Skip to main content

IAmmalgamPair

Git Source

Inherits: IAmmalgamERC20Controller, ITransferValidator

Functions

MINIMUM_LIQUIDITY

Represents the token amount that is burned during the first liquidity provision.

function MINIMUM_LIQUIDITY() external pure returns (uint256);

Returns

NameTypeDescription
<none>uint2561000

LTV

Returns the Loan-to-Value (LTV) ratio

This LTV ratio could be used to determine the maximum borrowable amount against collateral

function LTV() external view returns (uint8);

Returns

NameTypeDescription
<none>uint8The LTV ratio as a uint8 percentage value (75)

ALLOWED_LIQUIDITY_LEVERAGE

The constant value representing the allowed liquidity leverage in the system.

This value is a constant and cannot be changed.

function ALLOWED_LIQUIDITY_LEVERAGE() external pure returns (uint8);

missingX

Represents the amount of tokenX currently missing in the contract due to asset being lent out.

function missingX() external view returns (uint112);

missingY

Represents the amount of tokenY currently missing in the contract due to asset being lent out.

function missingY() external view returns (uint112);

factory

Represents the address of the factory contract.

This address is immutable.

function factory() external view returns (address);

getReserves

Fetches the current reserves of asset X and asset Y, as well as the block of the last operation.

function getReserves() external view returns (uint112 reserveX, uint112 reserveY, uint256 blockLast);

Returns

NameTypeDescription
reserveXuint112The current reserve of asset X.
reserveYuint112The current reserve of asset Y.
blockLastuint256The block number of the last operation.

kLast

Get the last product of the reserves, immediately after the most recent liquidity event.

function kLast() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256The last product of the reserves.

externalLiquidity

The external liquidity resepresents the liquidity that can be sourced on the external reference market to swap the collatoral asset to the debt asset. It is used in the calculation of slippage in the validation library. It can be set to a number representing the lower bound for the estimated external liquidity availabe for a given pair. This allows more liquid pairs to have less restrictive borrowing checks.

function externalLiquidity() external view returns (uint112);

Returns

NameTypeDescription
<none>uint112The external liquidity in units of liquidity tokens (L).

updateExternalLiquidity

Updates the external liquidity value.

This function sets the external liquidity to a new value and emits an event with the new value. It can only be called by the fee setter.

function updateExternalLiquidity(uint112 externalLiquidity_) external;

Parameters

NameTypeDescription
externalLiquidity_uint112The new external liquidity value.

mint

Mints tokens and assigns them to to address.

Calculates the amount of tokens to mint based on reserves and balances. Requires liquidity > 0. Emits a #Mint event.

function mint(address to) external returns (uint256 liquidity);

Parameters

NameTypeDescription
toaddressaddress to which tokens will be minted

Returns

NameTypeDescription
liquidityuint256amount of tokens minted

burn

Burns liquidity tokens from the contract and sends the underlying assets to to address.

Calculates the amounts of assets to be returned based on liquidity. Requires amountX and amountY to be greater than 0. Emits a #Burn event and performs a safe transfer of assets.

function burn(address to) external returns (uint256 amountX, uint256 amountY);

Parameters

NameTypeDescription
toaddressaddress to which the underlying assets will be transferred

Returns

NameTypeDescription
amountXuint256amount of first token to be returned
amountYuint256amount of second token to be returned

swap

Executes a swap of tokens.

Requires at least one of amountXOut and amountYOut to be greater than 0, and that the amount out does not exceed the reserves. An optimistically transfer of tokens is performed. A callback is executed if data is not empty. Emits a #Swap event.

function swap(uint256 amountXOut, uint256 amountYOut, address to, bytes calldata data) external;

Parameters

NameTypeDescription
amountXOutuint256Amount of first token to be swapped out.
amountYOutuint256Amount of second token to be swapped out.
toaddressAddress to which the swapped tokens are sent.
databytesData to be sent along with the call, can be used for a callback.

deposit

Handles deposits into the contract.

Verifies deposit amounts and types, adjusts reserves if necessary, mints corresponding tokens, and updates missing assets.

function deposit(address to) external;

Parameters

NameTypeDescription
toaddressAddress to which tokens will be minted.

withdraw

Handles withdrawals from the contract.

Verifies withdrawal amounts, burns corresponding tokens, transfers the assets, and updates missing assets.

function withdraw(address to) external;

Parameters

NameTypeDescription
toaddressAddress to which the withdrawn assets will be transferred.

borrow

Handles borrowing from the contract.

Verifies the borrowing amounts, mints corresponding debt tokens, transfers the assets, and updates missing assets. Also supports flash loan interactions.

function borrow(address to, uint256 amountX, uint256 amountY, bytes calldata data) external;

Parameters

NameTypeDescription
toaddressAddress to which the borrowed assets will be transferred.
amountXuint256Amount of asset X to borrow.
amountYuint256Amount of asset Y to borrow.
databytesCall data to be sent to external contract if flash loan interaction is desired.

borrowLiquidity

Handles liquidity borrowing from the contract.

Verifies the borrowing amount, mints corresponding tokens, transfers the assets, and updates reserves. Also supports flash loan interactions.

function borrowLiquidity(address to, uint256 borrowAmountL, bytes calldata data) external returns (uint256, uint256);

Parameters

NameTypeDescription
toaddress
borrowAmountLuint256Amount of liquidity to borrow.
databytesCall data to be sent to external contract if flash loan is desired.

Returns

NameTypeDescription
<none>uint256borrowedLX Amount of asset X borrowed.
<none>uint256borrowedLY Amount of asset Y borrowed.

repay

Handles repayment of borrowed assets.

Burns corresponding borrowed tokens, adjusts the reserves, and updates missing assets.

function repay(address onBehalfOf) external;

Parameters

NameTypeDescription
onBehalfOfaddressAddress of the entity on whose behalf the repayment is made.

repayLiquidity

Handles repayment of borrowed liquidity.

Calculates repayable liquidity, burns corresponding tokens, adjusts reserves, and updates active liquidity.

function repayLiquidity(address onBehalfOf) external returns (uint256 amountX, uint256 amountY, uint256 repayAmountL);

Parameters

NameTypeDescription
onBehalfOfaddressAddress of the entity on whose behalf the liquidity repayment is made.

Returns

NameTypeDescription
amountXuint256Repayment amount for asset X.
amountYuint256Repayment amount for asset Y.
repayAmountLuint256Amount of liquidity repaid.

skim

Transfers excess tokens to a specified address.

Calculates the excess of tokenX and tokenY balances and transfers them to the specified address.

function skim(address to) external;

Parameters

NameTypeDescription
toaddressThe address to which the excess tokens are transferred.

sync

Updates the reserves to match the current token balances.

Reads the current balance of tokenX and tokenY in the contract, and updates the reserves to match these balances.

function sync() external;

configLongTermInterval

Resets the long-term interval configuration.

Allows the contract owner to reset the long-term interval configuration to the specified value.

function configLongTermInterval(uint24 _longTermIntervalConfig) external;

Parameters

NameTypeDescription
_longTermIntervalConfiguint24The new value for the long-term interval configuration.

getObservations

Retrieves the current observations from the contract.

Returns the GeometricBWAP Observation struct.

function getObservations() external view returns (GeometricBWAP.Observations memory);

Returns

NameTypeDescription
<none>GeometricBWAP.Observationsobservations A struct containing the current observations data.

getTickRange

Retrieves the tick range values.

Returns the minimum and maximum tick values that define a tick range.

function getTickRange() external view returns (int24 minTick, int24 maxTick);

Returns

NameTypeDescription
minTickint24The minimum tick value among current, mid-term, and long-term ticks.
maxTickint24The maximum tick value among current, mid-term, and long-term ticks.

Events

Mint

Emitted when tokens are minted

event Mint(address indexed sender, uint256 amountX, uint256 amountY);

Parameters

NameTypeDescription
senderaddressSupplies assets into the pair contract and receives Ammalgam Liquidity in exchange
amountXuint256The amount of token X minted
amountYuint256The amount of token Y minted

Burn

Emitted when tokens are burned

event Burn(address indexed sender, uint256 amountX, uint256 amountY, address indexed to);

Parameters

NameTypeDescription
senderaddressSupplies Ammalgam Liquidity token into the pair contract and receives the minted assets in exchange
amountXuint256The amount of token X burned
amountYuint256The amount of token Y burned
toaddressAddress where burned tokens are sent

Swap

Emitted on a token swap

event Swap(
address indexed sender,
uint256 amountXIn,
uint256 amountYIn,
uint256 amountXOut,
uint256 amountYOut,
address indexed to
);

Parameters

NameTypeDescription
senderaddressThe address initiating the swap
amountXInuint256The amount of token X provided for the swap
amountYInuint256The amount of token Y provided for the swap
amountXOutuint256The amount of token X received from the swap
amountYOutuint256The amount of token Y received from the swap
toaddressAddress where the swapped tokens are sent

Deposit

Emitted on a deposit of tokens

When assets X and Y are being lent out and depleted, the modified invariant curve is utilized, which approaches infinity faster than the normal invariant curve. Depositers who deposits the depleted assets will earn additional deposit credit as they are helping move the modified invariant curve back to the original curve.

event Deposit(address indexed sender, uint256 amountX, uint256 amountY, uint256 fromReserveX, uint256 fromReserveY);

Parameters

NameTypeDescription
senderaddressSupplies assets into the pair contract and receives Ammalgam Deposit Tokens in exchange
amountXuint256The amount of token X deposited
amountYuint256The amount of token Y deposited
fromReserveXuint256The prior reserve of token X before deposit
fromReserveYuint256The prior reserve of token Y before deposit

Withdraw

Emitted on a withdrawal of tokens

event Withdraw(address indexed sender, uint256 amountX, uint256 amountY);

Parameters

NameTypeDescription
senderaddressSupplies Ammalgam Deposit Tokens and receives the underlying assets in exchange
amountXuint256The amount of token X withdrawn
amountYuint256The amount of token Y withdrawn

Borrow

Emitted on a borrow of tokens

event Borrow(address indexed sender, uint256 amountX, uint256 amountY, address indexed to);

Parameters

NameTypeDescription
senderaddressThe address initiating the borrowing action
amountXuint256The amount of token X borrowed
amountYuint256The amount of token Y borrowed
toaddressAddress where the borrowed tokens are sent

BorrowLiquidity

Emitted on a liquidity borrow

event BorrowLiquidity(address indexed sender, uint256 borrowAmountL, address indexed to);

Parameters

NameTypeDescription
senderaddressThe address initiating the borrowing action
borrowAmountLuint256The amount of liquidity borrowed
toaddressAddress where the borrowed liquidity is sent

Repay

Emitted on a token repayment

When assets X and Y are being lent out and depleted, the modified invariant curve is utilized, which approaches infinity faster than the normal invariant curve. Depositers who deposits the depleted assets will earn additional deposit credit as they are helping move the modified invariant curve back to the original curve.

event Repay(
address indexed sender,
address indexed onBehalfOf,
uint256 amountX,
uint256 amountY,
uint256 fromReserveX,
uint256 fromReserveY
);

Parameters

NameTypeDescription
senderaddressSupplies borrowed underlying assets into the pair contract and the corresponding Ammalgam Debt tokens will be destroyed
onBehalfOfaddressAddress for whom the repayment is made
amountXuint256The amount of token X repaid
amountYuint256The amount of token Y repaid
fromReserveXuint256The prior reserve of token X before repayment
fromReserveYuint256The prior reserve of token Y before repayment

RepayLiquidity

Emitted on a liquidity repayment

event RepayLiquidity(address indexed sender, address indexed onBehalfOf, uint256 amountLX, uint256 amountLY);

Parameters

NameTypeDescription
senderaddressSupplies borrowed liquidity into the pair contract and the corresponding Ammalgam Debt tokens will be destroyed
onBehalfOfaddressAddress for whom the repayment is made
amountLXuint256The amount of liquidity X repaid
amountLYuint256The amount of liquidity Y repaid

Sync

Emitted when reserves are synchronized

event Sync(uint112 reserveX, uint112 reserveY);

Parameters

NameTypeDescription
reserveXuint112The updated reserve for token X
reserveYuint112The updated reserve for token Y

UpdateExternalLiquidity

Emitted when external liquidity is updated

event UpdateExternalLiquidity(uint112 externalLiquidity);

Parameters

NameTypeDescription
externalLiquidityuint112The updated value for external liquidity