Remove Liquidity
Removing liquidity occurs in one asset. Let's have look at the example of the Gas Token Index Pool (which includes all native assets of each supported chain) with the following weights:
Asset | Weight Points | Share |
---|---|---|
BNB | 1000 | 0,1428 % |
AVAX | 1000 | 0,1428 % |
ETH | 1000 | 0,1428 % |
MATIC | 1000 | 0,1428 % |
FTM | 1000 | 0,1428 % |
ETH (arbitrum) | 1000 | 0,1428 % |
ETH (optimism) | 1000 | 0,1428 % |
Total Weight = 1000 * 7 = 7000
When a Liquidity Provider wants to redeem their LP tokens for a certain asset, they need to choose one of the assets to be used for the redemption. Let's take ETH as an example once again.
Liquidity Provider calls removeLiquidity() method on MasterRouter.sol on Avalanche network (considered as masterchain)
MasterRouter.sol finds InterswapPool.sol by poolID using Factory.sol:
- Reduces reserves of ETH in the pool state.
- Reduces the weight of the ETH in the pool using formula in Dynamic Weights
- Burn LP's.
- Calculation of token amount to be withdrawn
- MasterRouter.sol sends an Axelar message to ChildRouter.sol on Ethereum network with the following payload:
{
address pool,
uint256 lpAmount,
bytes[] calldata tokens,
string[] calldata chains,
bytes[] calldata receivers,
uint256[] calldata removeLiquidityFees ,
}
- ChildRouter.sol receives a message, calls a InterswapLock.sol by the address (the InterswapLock.sol address is determined by the poolID). And it unlocks ETH to receiver.
ETH weight decreased by 50 points. After removing liquidity we can see such a picture of pool structure:
Asset | Weight Points | Share |
---|---|---|
BNB | 1000 | 0,1438 % |
AVAX | 1000 | 0,1438 % |
ETH | 950 | 0,1366 % |
MATIC | 1000 | 0,1438 % |
FTM | 1000 | 0,1438 % |
ETH (arbitrum) | 1000 | 0,1438 % |
ETH (optimism) | 1000 | 0,1438 % |
Total Weight = 6950