Explanation of the Deposit Transaction


In Duality’s concentrated liquidity model, liquidity providers (LPs) can provide liquidity to a specific trading pair by depositing tokens at a specific price into one or both sides of the pair in “a liquidity pool”. When depositing into the pool LPs must choose a fee for their deposit. This fee will be paid every time a trader swaps through a liquidity pool. When a trader wants to buy or sell one of the tokens in the pair, they must first pay the pool fee, which is a percentage of the trade value, to the liquidity pool. This fee is then shared among the LPs in proportion to their share of the liquidity in the pool. By providing liquidity, LPs earn a portion of the transaction fees and may also earn incentives for depositing in certain liquidity pools. In a concentrated liquidity DEX, LPs can set their own price range for each token in the pair. This means that they can set a higher price for selling their token and a lower price for buying the other token, or vice versa. This allows LPs to earn more fees by capturing the spread between the buying and selling prices. However, providing liquidity in a concentrated liquidity DEX can also carry risks, such as impermanent loss, where the value of the tokens in the pool may diverge from their initial ratio due to price fluctuations. LPs may also be exposed to potential losses if the DEX is hacked or suffers from smart contract vulnerabilities. It is important for LPs to carefully consider these risks before providing liquidity.

Deposit Mechanism

When depositing into an LP position (PoolReserves) a user specifies amounts of Token0 and Token1 as well as a TickIndex and a fee. The liquidity is added to the reserves for the respective ticks. Token0 will be deposited into the PoolReserves struct with the matching fee at TickIndex - fee and Token1 will be deposited into the PoolReserves at TickIndex + fee.

In the most basic case, when depositing into a pool, the ratio of Token0 to Token1 will be preserved. If a user does not provide tokens in the same ratio, then only a portion of their total deposit will be used so as to maintain the pool ratio.

true0=min(amountDeposited0,existingReserves0amountDeposited1existingReserves1)true_0 = min(amountDeposited_0, \frac{existingReserves_0 \cdot amountDeposited_1}{existingReserves_1}) true1=min(amountDeposited1,existingReserves1amountDeposited0existingReserves0)true_1 = min(amountDeposited_1, \frac{existingReserves_1 \cdot amountDeposited_0}{existingReserves_0})

NOTE: Most pools will only have Token1 OR Token0, so most deposits will only be providing one tokens to one side of the pool.

In return for depositing tokens into a pool the user is issued PoolShares corresponding to the specific liquidity pool in which they have deposited. These can be used in the future to withdraw the user’s pro-rata share of the PoolLiquidity in the future. The PoolShares are also fungible denoms that can be bought, sold, and traded.

The amount of pool shares issued is calculated using the following formula:

valueDeposited=true0+p(i)true1valueDeposited = true_0 + p(i)\cdot true_1

newShares=valueDepositedtotalSharesvalueTotalnewShares = \frac{valueDeposited \cdot totalShares}{valueTotal}


By default the autoswap option is enabled, which allows use to deposit their full deposit amount. Autoswap provides a mechanism for users to deposit the entirety of their specified deposit amounts by paying a small fee. The fee for performing an autoswap is deducted from the total number of shares the the user is issued. When calculating share issuance the same formula as above is used for the balanced portion of the deposit, with the following formula use to calculate the shares issues that would unbalance the pool:

additionalShares=left0p(fee)+left1p(ifee)additionalShares = left_0 \cdot p(-fee) + left_1 \cdot p(i-fee)

Deposit Message

message MsgDeposit {
    string creator = 1;
    string receiver = 2;
    string token_a = 3;
    string token_b = 4;
    repeated string amounts_a = 5 [
        (gogoproto.moretags) = "yaml:\"amounts_a\"",
        (gogoproto.customtype) = "",
        (gogoproto.nullable) = false,
        (gogoproto.jsontag) = "amounts_a"
    repeated string amounts_b = 6 [
        (gogoproto.moretags) = "yaml:\"amounts_b\"",
        (gogoproto.customtype) = "",
        (gogoproto.nullable) = false,
        (gogoproto.jsontag) = "amounts_b"
    repeated int64 tick_indexes_a_to_b = 7;
    repeated uint64 fees = 8;
    repeated DepositOptions options = 9;



Creator string (sdk.AccAddress)

The account from which deposit Tokens will be debited

Receiver string (sdk.AccAddress)

The account to which PoolShares will be issued

TokenA string

Denom for one side of the deposit

TokenB string

Denom for the opposing side of the deposit

AmountsA []sdk.Int

Amounts of tokenA to deposit

AmountsB []sdk.Int

Amounts of tokenB to deposit

TickIndexesAToB []int64

Tick indexes to deposit at defined in terms of TokenA to TokenB (ie. TokenA is on the left)

Fees []uint64

Fees to use for each deposit

Options []DepositOptions

Additional deposit options



Autoswap bool

Toggle to use autoswap (default true)

Last updated