swap-router-sdk
v1.21.1
Published
Library that helps you ti find most profitable way to swap tokens on Tezos ecosystem.
Downloads
339
Readme
Tezos Swap Router SDK
Library that helps you ti find most profitable way to swap tokens on Tezos ecosystem.
Supported DEXes:
- QuipuSwap
- Plenty
- Liquidity Baking
- QuipuSwap Token to Token
- Youves
- Vortex
- QuipuSwap curve-like DEXes, also known as Stableswap
- Spicy
- Spicy Wrap
- Quipuswap Dex 2.0
- Quipuswap V3
Installation
yarn add swap-router-sdk
Prerequisites & explenation
TEZOS_DEXES_API_URL: string
- url to the WebSocket server that returns list of available pairs and their liquidityinputAssetSlug: string
- slug (address_id
|| tez
) of input tokenoutputAssetSlug: string
- slug (address_id
|| tez
) of desired output tokeninputMutezAmount: BigNumber
- number of input token (1 TEZ
= 1 000 000 mutez
)outputMutezAmount: BigNumber
- number of output token (1 TEZ
= 1 000 000 mutez
)slippageTolerance: number | undefined
- slippage tolerance percent
maxDepth?: number
- maximal depth of search, which is equal to maximal route length. Default value is 3
receiverPublicKeyHash?: string
- public key hash of swap output receiver. Default value is sender's public key hash
referralAddress?: string
- the address of referral fees receiver for QuipuSwap curve-like DEXes
referralCode?: string | null
- the ID of V3 pool methods calls source. 1 stands for Quipuswap, 2 stands for Temple Wallet.
Usage
const allRoutePairs = useAllRoutePairs(TEZOS_DEXES_API_URL);
const routePairsCombinations = useRoutePairsCombinations(
inputAssetSlug,
outputAssetSlug,
allRoutePairs.data,
maxDepth
);
...
const bestTradeExactIn = getBestTradeExactInput(inputMutezAmount, routePairsCombinations);
const bestTradeExactOutput = getBestTradeExactOutput(outputMutezAmount, routePairsCombinations);
...
const bestTradeWithSlippageTolerance = useTradeWithSlippageTolerance(
inputMutezAmount,
bestTrade,
slippageTolerance
);
...
const tradeTransferParams = await getTradeOpParams(bestTradeWithSlippageTolerance, account.publicKeyHash, tezos, referralAddress, receiverPublicKeyHash);
const walletParamsWithKind = tradeTransferParams.map(transferParams => parseTransferParamsToParamsWithKind(transferParams));