Skip to main content

calculateTokenXToAddByTokenY

@bidask-protocol/sdk


@bidask-protocol/sdk / calculateTokenXToAddByTokenY

Function: calculateTokenXToAddByTokenY()

calculateTokenXToAddByTokenY(tokenXAmount, tokenYAmount, tokenYToAdd): bigint

Calculates the amount of tokenX to add (autofill) when adding a specified amount of tokenY. When providing liquidity, virtual tokens scale proportionally with real tokens. The ratio must be: deltaX / X = deltaY / Y Formula: deltaX = deltaY * X / Y

Parameters

tokenXAmount

bigint

Current amount of token X

tokenYAmount

bigint

Current amount of token Y

tokenYToAdd

bigint

Amount of token Y to add

Returns

bigint

Amount of token X to add to maintain proportional liquidity