Integrate Your dApp With the Aggregator
The AMM Aggregator provides a set of fully on-chain, general-purpose Solidity APIs that any dApp can use to integrate the Aggregator, and thus exploit its full potential. There are two main interfaces that enable this at the contract level: the AMM Interface (IAMM) and the AMM Aggregator Interface (IAMMAggregator).
The IAMM facilitates interaction with the API of any one AMM whitelisted by the Aggregator (such as Uniswap or Balancer). For each, there is a dedicated interface for dApp integration. Each interface is unique, but since all inherit the same code and interfaces, they are fundamentally similar, making integration with different AMMs very easy.
The IAMMAggregator
, on the other hand, facilitates direct interaction with the APIs of the Aggregator.
Retrieve the IAMM name and current version
Retrieve, for a specific AMM, the
address
by which it represents Ethereum (e.g. the WETHaddress
in case of Uniswap), the max number of tokens composing a pair, and a boolean value representing if the AMM of that specific pair supports multiple LPs with the same tokens inside (true
) or not (false
)
Pass the
LP token address
and theLP token holder
(owner) to retrieve theLP token balance
, the respective LP token for the pair and theaddresses
of the pair tokens
Pass an
LP token address
and retrieve: the circulating amount of the LP token of that pool; the total amounts of the pair tokens in the pool; and theaddresses
of the pair tokens.
Pass the
pair token addresses
and retrieve the circulating mount of the LP token of that pool; the LP token'saddress
; the amounts of the pair tokens in that pool; and addresses of the pair tokens. This method works only if_hasUniqueLiquidityPools
is true for that specific AMM; so, only if the AMM does not support multiple LPs with the same pairs. The function always returns the ordered list of tokens exactly as the AMM itself returns it:
Pass an
LP token token address
, a numerator and a denominator useful for calculating a precise percentage, and retrieve: the relevantLP token amount percentage
(calculated asLP token circulating total amount * numerator)/denominator
); the pair token amounts as percentages (calculated astoken amount in the pool * numerator)/denominator
); and theaddresses
of the pair tokens
Pass an
LP token address
and anLP token amount
to retrieve the amounts of the pair tokens and theaddresses
of the pair tokens.
Pass an
LP token address
, theaddress
of one of the pair tokens and an amount of that token to retrieve the equivalent amount of the LP token, the equivalent amount of the pair token (so the first one will be the amount expressed in the token amount input field); and theaddresses
of the pair tokens
This function is used to create a new liquidity pool and add liquidity to it in a specific AMM. Pass the array of token
addresses
, the token amounts, a boolean value representing if ETH is involved as one of the tokens (true
) or not (false
), and the receiver address. Retrieves theLP token amount
achieved, the array containing the corresponding pair token amounts, the createdLP token address
and the array containing the correspondingtokens addresses
. This method is not supported in Balancer verticalization.
Pass the
LiquidityPoolData
data to add liquidity to a specific AMM. Retrieves the resultingLP amount
, an array containing the respective equivalent in pair tokens, and an array containing theaddresses
of the pair tokens.
Pass an array containing one or more
LiquidityPoolData
data (look at the previous point) and retrieve the resultingLP amount
array, an array containing the array of the respective equivalent in pair tokens, and an array containing the array of thepair tokens addresses
.
Pass the
LiquidityPoolData
data to remove liquidity from a specific AMM and retrieve the resultingLP amount
, an array containing the respective equivalent in pair tokens, and an array containing the pair tokenaddresses
.
Pass an array containing one or more
LiquidityPoolData
and retrieve the resultingLP amount
array, an array containing the array of the respective equivalent in pair tokens, and an array containing the array of the pair tokenaddresses
.
Pass a
token address
, the desired amount to swap, an array containing theLP addresses
involved in the swap operation and an array representing the path the operation must follow, and retrieve an array containing the amount of tokens used during the swap operation, including the final token amount (in the last position) and the input token amount (in the first position).
Pass the
swapData
to swap liquidity through a specific AMM following a fixed path. Retrieves the output token amount swapped.
Pass an array of
swapData
to swap multiple liquidities through specific AMMs following a fixed path. Retrieves an array containing the swapped output tokens.
AMM Data Structures
The LiquidityPoolData
struct used in addLiquidity
, addLiquidityBatch
, removeLiquidity
and removeLiquidityBatch
operations is composed as follows:
liquidityPoolAddress
-> the LPaddress
chosen. This parameter must always be populated with the relative LPaddress
even if you are using a pair tokenamount
-> the LP token amount or the pair token amount desired to be added/removed. If an LP token is being used the parameter represents the amount of LP tokens, if a pair token is being used the parameter represents the amount of pair tokens.tokenAddress
-> represents the address of the pair token (if used). If an LP token is being used (and thereforeamountIsLiquidityPool
==true
), this parameter must be passed to0x0000000000000000000000000000000000000000
.amountIsLiquidityPool
-> a boolean value representing if the amount passed is a LP token (true
) or pair token amount (false
). In any case, as stated in the first point, the LPaddress
parameter must always be passedinvolvingETH
-> a boolean value representing if ETH is involved in the LP or one of the pair tokens -> this is crucial for AMMs like Uniswap where Ethereum is represented by WETH. So for example if the LP is ETH/BUIDLinvolvingETH
istrue
, if it is WETH/BUIDLinvolvingETH
isfalse
receiver
-> the receiver address of theaddLiquidity
orremoveLiquidity
operation
The SwapData
struct used in swapLiquidity
and swapLiquidityBatch
operations is composed as follows:
enterInETH
-> a boolean value representing if the input token is ETH (true
) or not (false
). So for example if the input token is ETHenterInETH
istrue
; if the input token is WETHenterInETH
isfalse
exitInETH
-> a boolean value representing if the output token is ETH (true
) or not (false
). So for example if the output token is ETHexitInETH
istrue
, if output token is WETHexitInETH
isfalse
liquidityPoolAddresses
-> array containing theliquidity pool token addresses
to be used in the swap operation. The first element of the array must necessarily contain the input token.path
-> array containing the path (represented by the tokens used) that the swap operation must followinputToken
-> theaddress
of the input token you want to swapamount
-> the input tokenamount
to swap in the operationreceiver
-> the output token receiveraddress
For example, if an operation swaps BUIDL for UNIFI and then for ARTE, BUIDL will be the input token and ARTE will be the output token. The liquidityPoolAddresses
array will contain the BUIDL/UNIFI LP address
in the first position, and the UNIFI/ARTE LP address
in the second one.
The swapPath
array will contain UNIFI in the first position, and ARTE in the second one.
Last updated