Understanding Token Deposit Ratio
This guide outlines the token Deposit ratio, how to find it, and how to reach there with a single token
Overview
When providing liquidity to a Kodiak Island, tokens must be deposited in a specific ratio determined by the current price and position of the underlying Kodiak V3 pool.
Core Concepts
Island Token Ratio: Each Island has a target ratio of its underlying tokens (token0 and token1). This ratio is determined by the current price of the tokens and the position's boundaries.
Single-Sided Deposits: Users often want to deposit a single token. In this case, a portion of the input token must be swapped for the other token to match the Island's target ratio.
Price Impact: Swapping tokens can cause price impact, which is the change in price due to the size of the trade. We want to minimize this impact while still achieving the desired token ratio.
Optimal Swap Amount: The goal is to find the swap amount that results in the most efficient deposit into the Island, considering the target ratio and minimizing price impact.
Make sure to account for difference in token decimals in all calculations carried out.
Depositing with Both Tokens
The ratio of tokens to be deposited in an island can be found by calling the function island.getMintAmounts(amount0Max, amount1Max)
on the particular island with the max amounts of token0 and token1 the user is willing to deposit. This returns (amount0, amount1, liquidityMinted)
where amount0 and amount1 correspond to the amount of tokens that will be used by the island and the amount of liquidity that is minted using (amount0, amount1)
. This is the ratio of tokens that needs to be deposited into the island based on the current island position and the underlying Kodiak pool's current token price.
Finding Deposit Ratio and Swap Data for Zaps
We will describe below the process of finding the swap amount and to keep it simple we will assume that the liquidity is high and swap does not have a large price impact thus ignoring it for the following example.
Step 1 - Finding the correct ratio of tokens to deposit
We use one unit of both tokens and call the getMintAmounts
function on the island to check the amounts of tokens deposited thus giving us a ratio. We then normalize it to 18 decimals to remove all decimal discrepancy
Step 2 - We get the swap price of inputToken -> OutputToken from the Swap router(KodiakRouter)
We use the kodiak quoter api to fetch the current price of the input token in terms of the output token.
The response returns the quote
which is the amount of output token you would receive for 1 unit of input token. We normalize this to 18 decimals to correspond to step1 and bring everything normalized to 18 decimals
Step 3 - Calculate the swap amount based on the information from step 1 and step 2
This step calculates the ideal swap amount assuming no price impact.
The formula depends on whether the input token is token0 or token1.
If input token is token0:
If input token is token1:
Where:
4. Get Final Swap Data
Now fetch the final swap data using the amount from step3, this returns the outputQuote and the calldata for the transaction which need to be used for constructing the RouterSwapParams
passed to the IslandRouter.
Last updated