LiquidSwap SDK
The typescript SDK for Liquidswap.
Installation
npm i @pontem/liquidswap-sdk
Usage
Init SDK
import { SDK } from '@pontem/liquidswap-sdk';
import Decimal from 'decimal.js';
const sdk = new SDK({
nodeUrl: 'https://fullnode.testnet.aptoslabs.com/v1',
networkOptions: {
nativeToken: '0x1::aptos_coin::AptosCoin'', // Type of Native network token
modules: {
Scripts:
'0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::scripts_v2', // This module is used for Swap
CoinInfo: '0x1::coin::CoinInfo', // Type of base CoinInfo module
CoinStore: '0x1::coin::CoinStore', // Type of base CoinStore module
LiquidityPool: '0x05a97986a9d031c4567e15b797be516910cfcb4156312482efc6a19c0a30c948::liquidity_pool' // Liquidity pool module
},
}
})
You want swap EXACTLY 1 APTOS to SLIPPAGED USDT amount
(async () => {
const amount = await sdk.Swap.calculateRates({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::USDT',
amount: new Decimal(1000000),
interactiveToken: 'from',
curveType: 'stable',
})
console.log(amount)
const txPayload = sdk.Swap.createSwapTransactionPayload({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
fromAmount: new Decimal(1000000),
toAmount: new Decimal(1584723),
interactiveToken: 'from',
slippage: new Decimal(0.05),
stableSwapType: 'high',
curveType: 'stable',
})
console.log(txPayload);
})()
You want get EXACTLY 0.001 BTC and send SLIPPAGED APTOS amount
(async () => {
const amount = await sdk.Swap.calculateRates({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
amount: new Decimal(100000),
interactiveToken: 'to',
curveType: 'stable',
})
console.log(amount)
const txPayload = sdk.Swap.createSwapTransactionPayload({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
fromAmount: new Decimal(2741440068),
toAmount: new Decimal(100000),
interactiveToken: 'to',
slippage: new Decimal(0.05),
stableSwapType: 'high',
curveType: 'stable',
})
console.log(txPayload);
})()