How To Remove Liquidity
In order to remove liquidity, you will need to pass as inputs to the contract the percentage of the exposition on the options side and the token side you want to withdraw.
But how are you going to know how much real assets you will get in exchange for that initial exposure? First of all, you can call the function getRemoveLiquidityAmounts passing the same percentages. This function will return the withdrawal amounts of options and tokens. If you want to understand deeper the topic about exposure and position, check this section.
Keep in mind that the withdrawal amounts between calling the getRemoveLiquidityAmounts and removeLiquiditymay change due to market changes.

Example 1 - Full Liquidity Remove

Imagine you have added some amount of liquidity of options and some liquidity of tokenB. Now you want to remove 100% of your exposition of both tokens. The steps you should do are:
1) Call getRemoveLiquidityAmounts first in order to estimate the withdrawal amounts 2) Call removeLiquidty on OptionAMMPoolwith the percents that you want to remove your exposition.
Solidity
Web3
1
// Instantiate OptionAMMPool
2
OptionAMMPool optionAMMPool = optionAMMPool("/*address*/");
3
uint256 percentA = 100 // if you want to remove 100%
4
uint256 percentB = 100 // if you want to remove 100%
5
6
// You can check with getRemoveLiquidityAmounts to estimate the amount of assets you will remove
7
(uint256 withdrawAmountA, uint256 withdrawAmountB) = optionAMMPool.getRemoveLiquidityAmounts(percentA, percentB);
8
9
optionAMMPool.removeLiquidity(percentA, percentB);
10
11
Copied!
1
// Parameters example
2
const owner = '0x3ab...';
3
const optionAMMPoolAddress = '0x3c...'
4
5
/////////////
6
// Web3.js
7
8
// Instantiate contract
9
const optionAMMPool = await web3.eth.Contract('Contract ABI', optionAMMPoolAddress)
10
11
const [withdrawAmountOptions, withdrawTokenB] = await optionAMMPool.methods.getRemoveLiquidityAmounts(percentA, percentB).call()
12
13
await optionAMMPool.methods.removeLiquidity(percentA, percentB).send({})
14
15
/////////////
16
// Ethers.js
17
18
// Instantiate contract
19
const optionAMMPool = await ethers.getContractAt(optionAMMPoolAddress, 'Contract ABI')
20
21
const [withdrawAmountOptions, withdrawTokenB] = await optionAMMPool.getRemoveLiquidityAmounts(percentA, percentB)
22
23
await optionAMMPool.removeLiquidity(percentA, percentB)
Copied!
Last modified 7mo ago