SdkPool
Last updated
Last updated
SDK class encapsulating stableswap pool functions.
This class will either interact with internal StableSwapFacet pools or external StableSwap pools depending on which type of pool is being used for each asset. Note: SDK currently only supports internal StableSwapFacet pools.
SdkShared
↳ SdkPool
▸ addLiquidity(domainId
, tokenAddress
, amounts
, minToMint?
, deadline?
): Promise
<TransactionRequest
>
Prepares the transaction request for adding liquidity to a pool.
Parameters
Name | Type | Default value | Description |
---|---|---|---|
Returns
Promise
<TransactionRequest
>
providers.TransactionRequest object.
▸ calculateAddLiquidityPriceImpact(domainId
, tokenAddress
, amountX
, amountY
): Promise
<undefined
| BigNumber
>
Calculates the price impact of adding liquidity to a pool.
Parameters
Returns
Promise
<undefined
| BigNumber
>
Price impact for adding liquidity, in 1e18 precision.
▸ calculatePriceImpact(tokenInputAmount
, tokenOutputAmount
, virtualPrice?
, isDeposit?
): BigNumber
Calculates the price impact depending on whether liquidity is being deposited or withdrawn.
Parameters
Returns
BigNumber
The price impact.
▸ calculateRemoveLiquidityPriceImpact(domainId
, tokenAddress
, amountX
, amountY
): Promise
<undefined
| BigNumber
>
Returns the price impact of removing liquidity from a pool.
Parameters
Returns
Promise
<undefined
| BigNumber
>
The price impact for removing liquidity, in 1e18 precision.
▸ calculateRemoveSwapLiquidity(domainId
, tokenAddress
, amount
, index
): Promise
<BigNumber
>
Calculates the amounts of underlying tokens returned.
Parameters
Returns
Promise
<BigNumber
>
Calculated amount of underlying token returned.
▸ calculateRemoveSwapLiquidity(domainId
, tokenAddress
, amount
): Promise
<BigNumber
[]>
Calculates the amounts of underlying tokens returned.
Parameters
Returns
Promise
<BigNumber
[]>
Array containing amount of each underlying token returned, in correct index order.
▸ calculateSwap(domainId
, tokenAddress
, tokenIndexFrom
, tokenIndexTo
, amount
): Promise
<BigNumber
>
Calculates the amount of tokens received on a swap.
Parameters
Returns
Promise
<BigNumber
>
Minimum amount received, in the "To" token's native decimal precision.
▸ calculateSwapPriceImpact(domainId
, amountX
, tokenX
, tokenY
): Promise
<BigNumber
>
Calculates the price impact of a swap.
Parameters
Returns
Promise
<BigNumber
>
The price impact for swapping, in 1e18 precision.
▸ calculateTokenAmount(domainId
, tokenAddress
, amounts
, isDeposit?
): Promise
<BigNumber
>
Calculates the minimum LP token amount from deposits or withdrawals.
Parameters
Returns
Promise
<BigNumber
>
Minimum LP tokens received, in 1e18 precision.
▸ calculateYield(feesEarned
, principal
, days
): Object
Calculates apr and apy.
Parameters
Returns
Object
Object containing apr and apy.
▸ getAdopted(domainId
, tokenAddress
): Promise
<string
>
Reads the adopted token.
Parameters
Returns
Promise
<string
>
The adopted token.
▸ getDefaultDeadline(): number
Set to 1 hour from current time.
Returns
number
The default deadline, in unix time.
▸ getLPTokenAddress(domainId
, tokenAddress
): Promise
<string
>
Reads the LP token address of a pool.
Parameters
Returns
Promise
<string
>
The LP token address.
▸ getPoolTokenAddress(domainId
, tokenAddress
, index
): Promise
<string
>
Reads the token address of a specified index in a pool.
Parameters
Returns
Promise
<string
>
The address of the specified token in the pool.
▸ getPoolTokenBalance(domainId
, tokenAddress
, poolTokenAddress
): Promise
<BigNumber
>
Reads the balance of a pool token.
Parameters
Returns
Promise
<BigNumber
>
The balance of the pool token.
▸ getPoolTokenIndex(domainId
, tokenAddress
, poolTokenAddress
): Promise
<number
>
Reads the index of a token in a pool.
Parameters
Returns
Promise
<number
>
The index of the specified token in the pool or -1 if not found.
▸ getPoolTokenDecimals(domainId
, tokenAddress
, poolTokenAddress
): Promise
<number
>
Reads the decimal precision of a token in a pool.
Parameters
Returns
Promise
<number
>
The decimal precision of the specified token in the pool or -1 if not found.
▸ getRepresentation(domainId
, tokenAddress
): Promise
<string
>
Reads the representation asset of the pool. The representation asset is the adopted asset on the canonical domain and local (nextAsset) otherwise.
Parameters
Returns
Promise
<string
>
The representation (local or adopted) token.
▸ getTokenPrice(tokenSymbol
): Promise
<any
>
Fetches the current price of a token.
Parameters
Returns
Promise
<any
>
The price of the token.
▸ getTokenSupply(domainId
, tokenAddress
): Promise
<BigNumber
>
Reads the ERC20 token supply.
Parameters
Returns
Promise
<BigNumber
>
The balance of the address.
▸ getTokenUserBalance(domainId
, tokenAddress
, userAddress
): Promise
<BigNumber
>
Reads the ERC20 token balance of an address.
Parameters
Returns
Promise
<BigNumber
>
The balance of the address.
▸ getUserPools(domainId
, userAddress
): Promise
<{ info
: Pool
; lpTokenBalance
: BigNumber
; poolTokenBalances
: BigNumber
[] }[]>
Retrieves the Pools that a user has LP tokens for.
Parameters
Returns
Promise
<{ info
: Pool
; lpTokenBalance
: BigNumber
; poolTokenBalances
: BigNumber
[] }[]>
Array of Pool objects.
▸ getVirtualPrice(domainId
, tokenAddress
): Promise
<BigNumber
>
Reads the virtual price of a pool.
Parameters
Returns
Promise
<BigNumber
>
The virtual price, scaled to the pool's decimal precision (10^18).
▸ getYieldStatsForDays(domainId
, tokenAddress
, unixTimestamp
, days
): Promise
<undefined
| { totalFeesFormatted
: number
; totalLiquidityFormatted
: number
; totalVolume
: BigNumber
; totalVolumeFormatted
: number
}>
Calculates the fees, liquidity, and volume of a pool for the days prior to the specified unix time.
Parameters
Returns
Promise
<undefined
| { totalFeesFormatted
: number
; totalLiquidityFormatted
: number
; totalVolume
: BigNumber
; totalVolumeFormatted
: number
}>
Object containing fees, liquidity, and volume, in 1e18 precision.
▸ removeLiquidity(domainId
, tokenAddress
, amount
, minAmounts?
, deadline?
): Promise
<TransactionRequest
>
Returns the transaction request for removing liquidity from a pool.
Parameters
Returns
Promise
<TransactionRequest
>
providers.TransactionRequest object.
▸ removeLiquidityOneToken(domainId
, tokenAddress
, amount
, minAmount?
, deadline?
): Promise
<TransactionRequest
>
Returns the transaction request for removing liquidity from a pool.
Parameters
Returns
Promise
<TransactionRequest
>
providers.TransactionRequest object.
▸ removeLiquidityImbalance(domainId
, tokenAddress
, amounts
, maxBurnAmount?
, deadline?
): Promise
<TransactionRequest
>
Returns the transaction request for removing liquidity from a pool.
Parameters
Returns
Promise
<TransactionRequest
>
providers.TransactionRequest object.
▸ swap(domainId
, tokenAddress
, from
, to
, amount
, minDy?
, deadline?
): Promise
<TransactionRequest
>
Returns the transaction request for performing a swap in a pool.
Parameters
Returns
Promise
<TransactionRequest
>
providers.TransactionRequest object.
▸ Static
create(_config
): Promise
<SdkPool
>
Create a singleton instance of the SdkPool class.
Parameters
Returns
Promise
<SdkPool
>
providers.TransactionRequest object.
Example
See the Deployments page for all domain IDs and asset addresses.
Name | Type | Description |
---|---|---|
Name | Type | Default value | Description |
---|---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Default value | Description |
---|---|---|---|
Name | Type | Description |
---|---|---|
Name | Type |
---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Default value | Description |
---|---|---|---|
Name | Type | Default value | Description |
---|---|---|---|
Name | Type | Default value | Description |
---|---|---|---|
Name | Type | Default value | Description |
---|---|---|---|
domainId
string
undefined
The domain ID of the pool.
tokenAddress
string
undefined
The address of local or adopted token.
amounts
string
[]
undefined
The amounts of the tokens to swap.
minToMint
string
"0"
(optional) The minimum acceptable amount of LP tokens to mint.
deadline
number
undefined
(optional) The deadline for the operation.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
amountX
string
The amount of token X (index 0 of the pool), in the token's native precision.
amountY
string
The amount of token Y (index 1 of the pool), in the token's native precision.
tokenInputAmount
BigNumber
undefined
The amount of inbound tokens (LP tokens for withdrawals, total tokens for deposits, dx for swaps), in 1e18 precision.
tokenOutputAmount
BigNumber
undefined
The amount of outbound tokens (total tokens for withdrawals, LP tokens for deposits, dy for swaps), in 1e18 precision.
virtualPrice
BigNumber
undefined
(optional) The current virtual price of the pool.
isDeposit
boolean
true
(optional) Whether this is a deposit or withdrawal.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
amountX
string
The amount of token X (index 0 of the pool), in the token's native precision.
amountY
string
The amount of token Y (index 1 of the pool), in the token's native precision.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
amount
string
The amount of the LP token to burn on withdrawal.
index
number
The index of the token to withdraw.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
amount
string
The amount of the LP token to burn on withdrawal.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
tokenIndexFrom
number
The index of the token to sell.
tokenIndexTo
number
The index of the token to buy.
amount
BigNumberish
The number of tokens to sell, in the "From" token's native decimal precision.
domainId
string
The domain ID of the pool.
amountX
string
The amount of tokens to swap, in the token's native precision.
tokenX
string
The address of the token to swap from.
tokenY
string
The address of the token to swap to.
domainId
string
undefined
The domain ID of the pool.
tokenAddress
string
undefined
The address of local or adopted token.
amounts
string
[]
undefined
The amounts of the tokens to deposit/withdraw, in the correct index order and in each token's native precision.
isDeposit
boolean
true
(optional) Whether this is a deposit or withdrawal.
feesEarned
number
The total fees earned in the period.
principal
number
The principal amount at the start of the period.
days
number
The number of days to look back.
apr
number
apy
number
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
index
number
The index of the token in the pool.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
poolTokenAddress
string
The address of the pool token.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of the local or adopted token.
poolTokenAddress
string
The address of the token in the pool to get the index for.
domainId
string
The domain id of the pool.
tokenAddress
string
The address of local or adopted token.
poolTokenAddress
string
The address of the token in the pool to get the precision for.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
tokenSymbol
string
The symbol for the token.
domainId
string
The domain ID of the ERC20 token.
tokenAddress
string
The address of the ERC20 token.
domainId
string
The domain ID of the ERC20 token.
tokenAddress
string
The address of the ERC20 token.
userAddress
string
The address to get the balance of.
domainId
string
The domain ID of the pool.
userAddress
string
The address of the user to get the pools for.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
unixTimestamp
number
The unix time to start the look back from.
days
number
The number of days to look back.
domainId
string
The domain ID of the pool.
tokenAddress
string
The address of local or adopted token.
amount
string
The amount of LP tokens to burn.
minAmounts
string
[]
(optional) The minimum amounts of each token to withdraw.
deadline
number
(optional) The deadline for the operation.
domainId
string
undefined
The domain ID of the pool.
tokenAddress
string
undefined
The address of local or adopted token.
withdrawTokenAddress
string
undefined
The address of the token to withdraw.
amount
string
undefined
The amount of LP tokens to burn.
minAmount
string
"0"
(optional) The minimum acceptable amount of the token to withdraw.
deadline
number
One hour from current time.
(optional) The deadline for the operation.
domainId
string
undefined
The domain ID of the pool.
tokenAddress
string
undefined
The address of local or adopted token.
amounts
string
[]
undefined
The amount of LP tokens to burn.
maxBurnAmount
string
"0" (Use total LP balance)
(optional) The max LP tokens the user is willing to burn.
deadline
number
One hour from current time.
(optional) The deadline for the operation.
domainId
string
undefined
The domain ID of the pool.
tokenAddress
string
undefined
The address of local or adopted token.
from
string
undefined
The address of the token to sell.
to
string
undefined
The address of the token to buy.
amount
string
undefined
The amount of the selling token to swap.
minDy
number
0
(optional) The minimum amount of the buying token to receive.
deadline
number
undefined
(optional) The deadline for the operation.
_config
Object
undefined
SdkConfig object.
_config.chains
Record
<string
, { providers: string[] }>
undefined
Chain config, at minimum with providers for each chain.
_config.signerAddress
string
undefined
Signer address for transactions.
_config.logLevel
"fatal"
| "error"
| "warn"
| "info"
| "debug"
| "trace"
| "silent"
"info"
(optional) Logging severity level.
_config.network
"testnet"
| "mainnet"
"mainnet"
(optional) Blockchain environment to interact with.