ERC20 Dex Berachain
Note: Link to existing contract ABI's can be found on Github here.
Interface of the erc20 dex module's precompiled contract
Functions
getPreviewSwapExact
previews a single swap into a pool.
function getPreviewSwapExact(
SwapKind kind,
address pool,
address baseAsset,
uint256 baseAssetAmount,
address quoteAsset
) external view returns (address asset, uint256 amount);
function getPreviewSwapExact(
SwapKind kind,
address pool,
address baseAsset,
uint256 baseAssetAmount,
address quoteAsset
) external view returns (address asset, uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
kind | SwapKind | The swap kind. (GIVEN_IN vs GIVEN_OUT) |
pool | address | The address of the pool. |
baseAsset | address | The base asset. |
baseAssetAmount | uint256 | The amount of base asset. |
quoteAsset | address | The quote asset. |
Returns
Name | Type | Description |
---|---|---|
asset | address | The token to be received from the pool. |
amount | uint256 | The amount of tokens to be received from the pool. |
getPreviewBatchSwap
previews a batch swap.
function getPreviewBatchSwap(SwapKind kind, BatchSwapStep[] memory swaps)
external
view
returns (address asset, uint256 amount);
function getPreviewBatchSwap(SwapKind kind, BatchSwapStep[] memory swaps)
external
view
returns (address asset, uint256 amount);
Parameters
Name | Type | Description |
---|---|---|
kind | SwapKind | The swap kind. (GIVEN_IN vs GIVEN_OUT) |
swaps | BatchSwapStep[] | The swaps to be executed. |
Returns
Name | Type | Description |
---|---|---|
asset | address | The token to be received from the pool. |
amount | uint256 | The amount of tokens to be received from the pool. |
getLiquidity
previews the balance of tokens currently in the liquidity pool.
function getLiquidity(address pool) external view returns (address[] memory asset, uint256[] memory amounts);
function getLiquidity(address pool) external view returns (address[] memory asset, uint256[] memory amounts);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
Returns
Name | Type | Description |
---|---|---|
asset | address[] | The tokens in the pool. |
amounts | uint256[] | The amount of tokens in the pool. |
getTotalShares
previews the total amount of shares of the liquidity pool.
function getTotalShares(address pool) external view returns (address[] memory assets, uint256[] memory amounts);
function getTotalShares(address pool) external view returns (address[] memory assets, uint256[] memory amounts);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
Returns
Name | Type | Description |
---|---|---|
assets | address[] | The share tokens / LP tokens of the pool. |
amounts | uint256[] | The amount share tokens / LP tokens of the pool. |
getExchangeRate
previews the exchange rate between two assets in a pool. Note: the returned uint is represented as a value of up to 18 decimal precision
function getExchangeRate(address pool, address baseAsset, address quoteAsset) external view returns (uint256);
function getExchangeRate(address pool, address baseAsset, address quoteAsset) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
baseAsset | address | The base asset to get the exchange rate for. |
quoteAsset | address | The quote asset to get the exchange rate for. |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | rate The exchange rate between the two assets. |
getPreviewSharesForLiquidity
previews the amount of LP tokens that will be received for adding liquidity to a pool.
function getPreviewSharesForLiquidity(address pool, address[] memory assets, uint256[] memory amounts)
external
view
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liquidity,
uint256[] memory liquidityAmounts
);
function getPreviewSharesForLiquidity(address pool, address[] memory assets, uint256[] memory amounts)
external
view
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liquidity,
uint256[] memory liquidityAmounts
);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
assets | address[] | The assets to add to the pool. |
amounts | uint256[] | The amounts of assets to add to the pool. |
Returns
Name | Type | Description |
---|---|---|
shares | address[] | The LP tokens that will be received for adding liquidity to the pool. |
shareAmounts | uint256[] | The amount of LP tokens that will be received for adding liquidity to the pool. |
liquidity | address[] | The liquidity in the pool. |
liquidityAmounts | uint256[] | The amount of liquidity in the pool. |
getPreviewAddLiquidityStaticPrice
previews the amount of tokens that can be added to a pool without impacting the exchange rate.
function getPreviewAddLiquidityStaticPrice(address pool, address[] memory liquidity, uint256[] memory amounts)
external
view
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liqOut,
uint256[] memory liquidityAmounts
);
function getPreviewAddLiquidityStaticPrice(address pool, address[] memory liquidity, uint256[] memory amounts)
external
view
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liqOut,
uint256[] memory liquidityAmounts
);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
liquidity | address[] | The tokens to add to the pool. |
amounts | uint256[] | The amounts of tokens to add to the pool. |
Returns
Name | Type | Description |
---|---|---|
shares | address[] | The LP tokens that will be received for adding liquidity to the pool. |
shareAmounts | uint256[] | The amount of LP tokens that will be received for adding liquidity to the pool. |
liqOut | address[] | The pool's asset tokens. |
liquidityAmounts | uint256[] | The amount of liquidity assets not used. |
getPreviewSharesForSingleSidedLiquidityRequest
previews the amount of shares that will be received from adding one sided liquidity to a pool.
function getPreviewSharesForSingleSidedLiquidityRequest(address pool, address asset, uint256 amount)
external
view
returns (address[] memory assets, uint256[] memory amounts);
function getPreviewSharesForSingleSidedLiquidityRequest(address pool, address asset, uint256 amount)
external
view
returns (address[] memory assets, uint256[] memory amounts);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
asset | address | The token to be added into the liquidity pool. |
amount | uint256 | The amount of token to be added into the liquidity pool. |
Returns
Name | Type | Description |
---|---|---|
assets | address[] | The share/LP token to be received |
amounts | uint256[] | The amount of LP tokens to be received. |
getPreviewAddLiquidityNoSwap
previews the amount of tokens that will be received from adding liquidity without swapping.
function getPreviewAddLiquidityNoSwap(address pool, address[] memory assets, uint256[] memory amounts)
external
view
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liqOut,
uint256[] memory liquidityAmounts
);
function getPreviewAddLiquidityNoSwap(address pool, address[] memory assets, uint256[] memory amounts)
external
view
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liqOut,
uint256[] memory liquidityAmounts
);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
assets | address[] | The tokens to be added into the liquidity pool. |
amounts | uint256[] | The amounts of tokens to be added into the liquidity pool. |
Returns
Name | Type | Description |
---|---|---|
shares | address[] | The LP tokens that will be received for adding liquidity to the pool. |
shareAmounts | uint256[] | The amount of LP tokens that will be received for adding liquidity to the pool. |
liqOut | address[] | The pool's asset tokens. |
liquidityAmounts | uint256[] | The amount of liquidity assets added. |
getPreviewBurnShares
previews the amount of tokens that will be received from burning LP tokens to remove liquidity.
function getPreviewBurnShares(address pool, address asset, uint256 amount)
external
view
returns (address[] memory assets, uint256[] memory amounts);
function getPreviewBurnShares(address pool, address asset, uint256 amount)
external
view
returns (address[] memory assets, uint256[] memory amounts);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
asset | address | The LP token to be burned. |
amount | uint256 | The amount of LP tokens to be burned. |
Returns
Name | Type | Description |
---|---|---|
assets | address[] | The tokens to be received for burning shares/LP tokens. |
amounts | uint256[] | The amount of tokens to be received for burning shares/LP tokens. |
getRemoveLiquidityExactAmountOut
previews the amount of LP tokens required to be removed to withdraw a specific amount of one asset from the pool.
function getRemoveLiquidityExactAmountOut(address pool, address assetIn, uint256 assetAmount)
external
view
returns (address[] memory assets, uint256[] memory amounts);
function getRemoveLiquidityExactAmountOut(address pool, address assetIn, uint256 assetAmount)
external
view
returns (address[] memory assets, uint256[] memory amounts);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
assetIn | address | The target asset to be received from burning LP tokens. |
assetAmount | uint256 | The amount of target asset to be received from burning LP tokens. |
Returns
Name | Type | Description |
---|---|---|
assets | address[] | The asset received for burning the LP tokens. |
amounts | uint256[] | The amount of asset received for burning the LP tokens. |
getRemoveLiquidityOneSideOut
previews the amount of one asset that will be received for burning LP tokens.
function getRemoveLiquidityOneSideOut(address pool, address assetOut, uint256 sharesIn)
external
view
returns (address[] memory assets, uint256[] memory amounts);
function getRemoveLiquidityOneSideOut(address pool, address assetOut, uint256 sharesIn)
external
view
returns (address[] memory assets, uint256[] memory amounts);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
assetOut | address | The target asset to be received from burning LP tokens. |
sharesIn | uint256 | The amount of LP tokens to be burned. |
Returns
Name | Type | Description |
---|---|---|
assets | address[] | The asset received for burning the LP tokens. |
amounts | uint256[] | The amount of target asset received for burning the LP tokens. |
getPoolName
gets the pool name for a given pool address.
function getPoolName(address pool) external view returns (string memory);
function getPoolName(address pool) external view returns (string memory);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
Returns
Name | Type | Description |
---|---|---|
<none> | string | name The name of the pool. |
getPoolOptions
gets the pool options for a given pool address.
function getPoolOptions(address pool) external view returns (PoolOptions memory);
function getPoolOptions(address pool) external view returns (PoolOptions memory);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
Returns
Name | Type | Description |
---|---|---|
<none> | PoolOptions | options The options of the pool. |
swap
Performs a swap with a single Pool. NOTE: If the limit is set as 0, there is no maximum slippage set. NOTE: The type of swap (GIVEN_IN vs GIVEN_OUT) determines if the limit is a max input, or a min output.
function swap(
SwapKind kind,
address poolId,
address assetIn,
uint256 amountIn,
address assetOut,
uint256 amountOut,
uint256 deadline
) external payable returns (address[] memory assets, uint256[] memory amounts);
function swap(
SwapKind kind,
address poolId,
address assetIn,
uint256 amountIn,
address assetOut,
uint256 amountOut,
uint256 deadline
) external payable returns (address[] memory assets, uint256[] memory amounts);
Parameters
Name | Type | Description |
---|---|---|
kind | SwapKind | The type of swap. |
poolId | address | The address of the pool. |
assetIn | address | The asset to be sent to the pool. |
amountIn | uint256 | The amount of asset in to be sent to the pool. |
assetOut | address | The asset to be received from the pool. |
amountOut | uint256 | The amount of asset out to be received from the pool. |
deadline | uint256 | The deadline for the swap. |
Returns
Name | Type | Description |
---|---|---|
assets | address[] | The asset received from the swap. |
amounts | uint256[] | The amount of asset received from the swap. |
batchSwap
Performs a swap with a single Pool. NOTE: If the limit is set as 0, there is no maximum slippage set. NOTE: The type of swap (GIVEN_IN vs GIVEN_OUT) determines if the limit is a max input, or a min output.
function batchSwap(SwapKind kind, BatchSwapStep[] memory swaps, uint256 deadline)
external
payable
returns (address[] memory assets, uint256[] memory amounts);
function batchSwap(SwapKind kind, BatchSwapStep[] memory swaps, uint256 deadline)
external
payable
returns (address[] memory assets, uint256[] memory amounts);
Parameters
Name | Type | Description |
---|---|---|
kind | SwapKind | The type of swap. |
swaps | BatchSwapStep[] | The swap steps to be executed. |
deadline | uint256 | The deadline for the swap. |
Returns
Name | Type | Description |
---|---|---|
assets | address[] | The asset received from the swap. |
amounts | uint256[] | The amount of asset received from the swap. |
createPool
Creates a new pool.
function createPool(
string memory name,
address[] memory assetsIn,
uint256[] memory amountsIn,
string memory poolType,
PoolOptions memory options
) external payable returns (address);
function createPool(
string memory name,
address[] memory assetsIn,
uint256[] memory amountsIn,
string memory poolType,
PoolOptions memory options
) external payable returns (address);
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the pool. |
assetsIn | address[] | The assets to be added to the pool. |
amountsIn | uint256[] | The amounts of assets to be added to the pool. |
poolType | string | The type of pool to be created. (Currently only balancer style pools are supported) |
options | PoolOptions | The options for the pool. |
Returns
Name | Type | Description |
---|---|---|
<none> | address | pool The address of the newly created pool. |
addLiquidity
Adds liquidity to a pool.
function addLiquidity(address pool, address receiver, address[] memory assetsIn, uint256[] memory amountsIn)
external
payable
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liquidity,
uint256[] memory liquidityAmounts
);
function addLiquidity(address pool, address receiver, address[] memory assetsIn, uint256[] memory amountsIn)
external
payable
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liquidity,
uint256[] memory liquidityAmounts
);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
receiver | address | The address to receive the LP tokens. |
assetsIn | address[] | The assets to be added to the pool. |
amountsIn | uint256[] | The amounts of assets to be added to the pool. |
Returns
Name | Type | Description |
---|---|---|
shares | address[] | The LP tokens that were received for adding liquidity to the pool. |
shareAmounts | uint256[] | The amount of LP tokens that were received for adding liquidity to the pool. |
liquidity | address[] | The liquidity in the pool. |
liquidityAmounts | uint256[] | The amount of liquidity in the pool. |
removeLiquidityBurningShares
Removes liquidity from a pool by burning shares.
function removeLiquidityBurningShares(address pool, address withdrawAddress, address assetIn, uint256 amountIn)
external
payable
returns (address[] memory liquidity, uint256[] memory liquidityAmounts);
function removeLiquidityBurningShares(address pool, address withdrawAddress, address assetIn, uint256 amountIn)
external
payable
returns (address[] memory liquidity, uint256[] memory liquidityAmounts);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
withdrawAddress | address | The address to receive the assets from burning the LP shares. |
assetIn | address | The LP token to be burned. |
amountIn | uint256 | The amount of LP tokens to be burned. |
Returns
Name | Type | Description |
---|---|---|
liquidity | address[] | The tokens received from burning the LP tokens. |
liquidityAmounts | uint256[] | The amount of tokens received from burning the LP tokens. |
removeLiquidityExactAmount
Removes a specific amount of liquidity from the pool, with a maximum number of shares to be burned.
function removeLiquidityExactAmount(
address pool,
address withdrawAddress,
address assetOut,
uint256 amountOut,
address sharesIn,
uint256 maxSharesIn
)
external
payable
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liquidity,
uint256[] memory liquidityAmounts
);
function removeLiquidityExactAmount(
address pool,
address withdrawAddress,
address assetOut,
uint256 amountOut,
address sharesIn,
uint256 maxSharesIn
)
external
payable
returns (
address[] memory shares,
uint256[] memory shareAmounts,
address[] memory liquidity,
uint256[] memory liquidityAmounts
);
Parameters
Name | Type | Description |
---|---|---|
pool | address | The address of the pool. |
withdrawAddress | address | The address to receive the assets from burning the LP shares. |
assetOut | address | The target asset to be received from burning the LP shares. |
amountOut | uint256 | The target amount of asset to be received from burning the LP shares. |
sharesIn | address | The LP token to be burned |
maxSharesIn | uint256 | The maximum amount (limit) of LP tokens to be burned. |
Returns
Name | Type | Description |
---|---|---|
shares | address[] | The LP tokens that were burned. |
shareAmounts | uint256[] | The amount of LP tokens that were burned. |
liquidity | address[] | The tokens received from burning the LP tokens. |
liquidityAmounts | uint256[] | The amount of tokens received from burning the LP tokens. |
Structs
BatchSwapStep
A single swap step to be executed in a batch swap. NOTE: The steps are executed sequentially, so the order in which they're passed in must logically make sense. Example: Given pools of (A,B) (B,C) (C,D), the following steps would be valid: A-B, B->C, C->D. The following steps would be invalid: A->B, C->D, B->C.
struct BatchSwapStep {
address poolId;
address assetIn;
uint256 amountIn;
address assetOut;
uint256 amountOut;
bytes userData;
}
struct BatchSwapStep {
address poolId;
address assetIn;
uint256 amountIn;
address assetOut;
uint256 amountOut;
bytes userData;
}
Properties
Name | Type | Description |
---|---|---|
poolId | address | The address of the pool. |
assetIn | address | The input asset of the swap. |
amountIn | uint256 | The amount of the input asset. |
assetOut | address | The output asset of the swap. |
amountOut | uint256 | The amount of the output asset. |
userData | bytes | The user data to be passed to the pool. |
PoolOptions
The configuration options for a pool. This contains asset weights, and swap fees. NOTE: The swap fees must be one of the following options: (0.05%, 0.3%, 1%)
struct PoolOptions {
AssetWeight[] weights;
uint256 swapFee;
}
struct PoolOptions {
AssetWeight[] weights;
uint256 swapFee;
}
AssetWeight
An asset weight to be used for pool options. NOTE: The weights do not have to add up to any specific number. The weight given here is normalized against the total weight.
struct AssetWeight {
address asset;
uint256 weight;
}
struct AssetWeight {
address asset;
uint256 weight;
}
Enums
SwapKind
*SwapKind is an enum which represents what type of swap it is. There are two swap kinds:
- 'GIVEN_IN' swaps, where the amount of tokens in (sent to the Pool) is known, and the Pool determines the amount of tokens out.
- 'GIVEN_OUT' swaps, where the amount of tokens out (received from the Pool) is known, and the Pool determines the amount of tokens in.*
enum SwapKind {
GIVEN_IN,
GIVEN_OUT
}
enum SwapKind {
GIVEN_IN,
GIVEN_OUT
}