Liquidity Provisioning
Overview
To provide liquidity to a specific DeDust pool, you must supply both assets. After doing so, the pool issues LP tokens to the depositor's address.
Due to TON's limitations, executing two transfers simultaneously isn't feasible. Thus, the balances of user deposits must be retained until the LP tokens are distributed.
To manage this process, the DeDust Protocol uses a Liquidity Deposit contract. This contract is activated when one of the assets is deposited and automatically terminates after the pool has either accepted the liquidity or the deposit has been withdrawn.
Deposit liquidity
To add liquidity to a Pool (A, B), deposit asset A into Vault (A) and asset B into Vault (B).
That's all.
Now, let's attempt to add some liquidity to the Pool (TON, SCALE).
Step 1. Prepare input
Next, we'll need both assets
and targetBalances
to be identical for each deposit.
import { Asset } from '@dedust/sdk';
/* ... */
const tonAmount = toNano("5"); // 5 TON
const scaleAmount = toNano("10"); // 10 SCALE
const TON = Asset.native();
const SCALE = Asset.jetton(SCALE_ADDRESS);
const assets: [Asset, Asset] = [TON, SCALE];
const targetBalances: [bigint, bigint] = [tonAmount, scaleAmount];
Step 2. Deposit TON to Vault (TON)
import { PoolType } from '@dedust/sdk';
/* ... */
const tonVault = tonClient.open(await factory.getNativeVault());
await tonVault.sendDepositLiquidity(sender, {
poolType: PoolType.VOLATILE,
assets,
targetBalances,
amount: tonAmount,
});
Step 3. Deposit SCALE to Vault (SCALE)
import { JettonRoot, PoolType, VaultJetton } from '@dedust/sdk';
/* ... */
const scaleRoot = tonClient.open(JettonRoot.createFromAddress(SCALE_ADDR));
const scaleWallet = tonClient.open(await scaleRoot.getWallet(sender.address));
await scaleWallet.sendTransfer(sender, toNano('0.5'), {
amount: scaleAmount,
destination: scaleVault.address,
responseAddress: sender.address,
forwardAmount: toNano('0.4'),
forwardPayload: VaultJetton.createDepositLiquidityPayload({
poolType: PoolType.VOLATILE,
assets,
targetBalances,
}),
});
Withdraw liquidity
To withdraw liquidity, we need to burn LP tokens. Here's how:
const pool = tonClient.open(await factory.getPool(PoolType.VOLATILE, [TON, SCALE]));
const lpWallet = tonClient.open(await pool.getWallet(sender.address));
await lpWallet.sendBurn(sender, toNano('0.5'), {
amount: await lpWallet.getBalance(),
});
Cancel pending deposits
const liquidityDeposit = tonClient.open(
await factory.getLiquidityDeposit({
ownerAddress: sender.address,
poolType: PoolType.VOLATILE,
assets,
}),
);
await liquidityDeposit.sendCancelDeposit(sender, {});
Updated 11 months ago