2.0.1 • Published 2 years ago

@currie0612/crema-sdk v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Install:

npm i @cremafinance/crema-sdk

Build:

npm run build

Instructions:

import { TokenSwap } from '@cremafinance/crema-sdk'
const swap = await new TokenSwap(conn, swapProgramId, swapKey, null).load()
const amountOut: any = await swap.preSwapA(amountIn) // a->b
const amountOut: any = await swap.preSwapB(amountIn) // b->a

Parameters Description:

amountIn: Decimal (using decimal.js repo)

Liquidity Calculation Formula

Assuming the current price is $P{c}$,the price range that users add liquidity in is $[P{a},P_{b}]$

$ \LARGE L = \begin {cases} ¦ {Δx} \over {1 \over {\sqrt{P{a}}}} - {1 \over {\sqrt{P{b}}}} &, \text P{c} < P{a} \ \ ¦ {Δy} \over {\sqrt{P{b}} - \sqrt{P{a}}} &, \text P{c} > P{b}\ ¦ {{Δx} \over {1 \over {\sqrt{P{c}}}} - {1 \over {\sqrt{P{b}}}}} = {{Δy} \over {\sqrt{P{c}} - \sqrt{P{a}}}} &, \text P{c} \in [P{a},P_{b}] \ \ \end {cases} $