Skip to main content

IAmmalgamPair

Git Source

Inherits: ITokenController, ITransferValidator

Functions

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 amountXAssets and amountYAssets to be greater than 0. Emits a #Burn event and performs a safe transfer of assets.

function burn(
address to
) external returns (uint256 amountXAssets, uint256 amountYAssets);

Parameters

NameTypeDescription
toaddressaddress to which the underlying assets will be transferred

Returns

NameTypeDescription
amountXAssetsuint256amount of first token to be returned
amountYAssetsuint256amount 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 amountXAssets, uint256 amountYAssets, bytes calldata data) external;

Parameters

NameTypeDescription
toaddressAddress to which the borrowed assets will be transferred.
amountXAssetsuint256Amount of asset X to borrow.
amountYAssetsuint256Amount 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 borrowAmountLShares,
bytes calldata data
) external returns (uint256, uint256);

Parameters

NameTypeDescription
toaddress
borrowAmountLSharesuint256Amount 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 amountXAssets, uint256 amountYAssets, uint256 repayAmountLShares);

Parameters

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

Returns

NameTypeDescription
amountXAssetsuint256Repayment amount for asset X.
amountYAssetsuint256Repayment amount for asset Y.
repayAmountLSharesuint256Amount 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;

Events

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