Module hydra_dx_math::xyk
source · Functions
Calculating amount to be sent to the pool given the amount to be received from the pool and both reserves.
Formula : IN_RESERVE * AMOUNT_OUT / (OUT_RESERVE - AMOUNT_OUT) + 1
Calculating required amount of asset b given asset a.
Formula : AMOUNT * ASSET_B_RESERVE / ASSET_A_RESERVE
Calculating amount of assets returned when removing liquidity.
Formula A: AMOUNT * ASSET_A_RESERVE / TOTAL_LIQUIDITY
Formula B: AMOUNT * ASSET_B_RESERVE / TOTAL_LIQUIDITY
Calculating amount to be received from the pool given the amount to be sent to the pool and both reserves.
Formula : OUT_RESERVE * AMOUNT_IN / (IN_RESERVE + AMOUNT_IN)
Calculating amount of shares given to LP for added liquidity
shares = issuance * amount / reserve
Calculating spot price given reserve of selling asset and reserve of buying asset.
Formula : OUT_RESERVE * AMOUNT / IN_RESERVE