LiquidSwap SDK
Table of Contents
- Installation
- Usage
- Roadmap
- Contributing
- License
The typescript SDK for Liquidswap.
Installation
For NPM:
npm i @pontem/liquidswap-sdk
For Yarn:
yarn add @pontem/liquidswap-sdk
(back to top)
Usage
Init SDK
import { SDK, convertValueToDecimal } from '@pontem/liquidswap-sdk';
const sdk = new SDK({
nodeUrl: 'https://fullnode.mainnet.aptoslabs.com/v1',
})
Convert 15 coins to Decimal type with 8 decimals (coins like APTOS, BTC, etc);
const decimalValue = convertValueToDecimal(15, 8);
or
const decimalValue2 = convertValueToDecimal('0.005', 8);
Swap EXACTLY 1 APTOS to SLIPPAGED layerzero USDT amount
(async () => {
try {
const output = await sdk.Swap.calculateRates({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT',
amount: 100000000,
curveType: 'uncorrelated',
interactiveToken: 'from',
version: 0
})
console.log(output)
const txPayload = sdk.Swap.createSwapTransactionPayload({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT',
fromAmount: 100000000,
toAmount: 4304638,
interactiveToken: 'from',
slippage: 0.005,
stableSwapType: 'high',
curveType: 'uncorrelated',
version: 0
})
console.log(txPayload);
} catch(e) {
console.log(e)
}
})()
Get EXACTLY 1 USDT and send SLIPPAGED APTOS amount
(async () => {
try {
const amount = await sdk.Swap.calculateRates({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT',
amount: 1000000,
interactiveToken: 'to',
curveType: 'uncorrelated',
version: 0
})
console.log(amount)
const txPayload = sdk.Swap.createSwapTransactionPayload({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT',
fromAmount: convertValueToDecimal(0.23211815, 8),
toAmount: convertValueToDecimal(1, 6),
interactiveToken: 'to',
slippage: 0.005,
stableSwapType: 'hign',
curveType: 'uncorrelated',
version: 0
})
console.log(txPayload);
} catch (e) {
console.log(e);
}
})()
Swap EXACTLY 1 APTOS to wormhole WETH with curve - 'stable', stableSwapType - 'normal' and 0.5% slippage
(async () => {
try {
const amount = await sdk.Swap.calculateRates({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0xcc8a89c8dce9693d354449f1f73e60e14e347417854f029db5bc8e7454008abb::coin::T',
amount: 100000000,
interactiveToken: 'from',
curveType: 'stable',
version: 0
})
console.log(amount)
const txPayload = sdk.Swap.createSwapTransactionPayload({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT',
fromAmount: convertValueToDecimal(1, 8),
toAmount: convertValueToDecimal(0.00175257, 8),
interactiveToken: 'from',
slippage: 0.005,
stableSwapType: 'normal',
curveType: 'stable',
version: 0
})
console.log(txPayload);
} catch (e) {
console.log(e);
}
})()
Get EXACTLY 1 USDA and send SLIPPAGED APTOS amount with curve - 'stable', stableSwapType - 'high' and 0.5% slippage
(async () => {
try {
const amount = await sdk.Swap.calculateRates({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0x1000000fa32d122c18a6a31c009ce5e71674f22d06a581bb0a15575e6addadcc::usda::USDA',
amount: 1000000,
interactiveToken: 'to',
curveType: 'stable',
version: 0
})
console.log(amount)
const txPayload = sdk.Swap.createSwapTransactionPayload({
fromToken: '0x1::aptos_coin::AptosCoin',
toToken: '0x1000000fa32d122c18a6a31c009ce5e71674f22d06a581bb0a15575e6addadcc::usda::USDA',
fromAmount: convertValueToDecimal(0.12356861, 8),
toAmount: convertValueToDecimal(1, 6),
interactiveToken: 'to',
slippage: 0.005,
stableSwapType: 'high',
curveType: 'stable',
version: 0
})
console.log(txPayload);
} catch (e) {
console.log(e);
}
})()
Check Pool Existence
(async() => {
const output = await sdk.Liquidity.checkPoolExistence({
fromToken: "0x1::aptos_coin::AptosCoin",
toToken: "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
curveType: 'uncorrelated',
version: 0
});
console.log(output);
})
Pools v.0.5: Swap 0.8 LayerZero USDT to LayerZero USDC
(async () => {
try {
const output = await sdk.Swap.calculateRates({
fromToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC',
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT',
amount: 800000,
curveType: 'stable',
interactiveToken: 'from',
version: 0.5
})
console.log(output)
const txPayload = sdk.Swap.createSwapTransactionPayload({
fromToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC',
toToken: '0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT',
fromAmount: 800000,
toAmount: 601018,
interactiveToken: 'from',
slippage: 0.005,
stableSwapType: 'high',
curveType: 'stable',
version: 0.5,
})
console.log(txPayload);
} catch(e) {
console.log(e)
}
})()
Creating Liquidity Pool for pair APTOS / lzUSDC
(async () => {
const { rate, receiveLp } = await sdk.Liquidity.calculateRateAndMinReceivedLP({
fromToken: TokensMapping.APTOS,
toToken: TokensMapping.USDC,
amount: 100000000,
curveType: 'uncorrelated',
interactiveToken: 'from',
slippage: 0.005,
version: 0
});
console.log(rate)
console.log(receiveLp)
const payload = await sdk.Liquidity.createAddLiquidityPayload({
fromToken: TokensMapping.APTOS,
toToken: TokensMapping.USDC,
fromAmount: 100000000,
toAmount: 4472498,
interactiveToken: 'from',
slippage: 0.005,
stableSwapType: 'normal',
curveType: 'uncorrelated',
version: 0
})
console.log(payload);
})
Calculate Output Burn for x and y coin with slippage and without slippage
(async()=> {
const output = await sdk.Liquidity.calculateOutputBurn({
fromToken: "0x1::aptos_coin::AptosCoin",
toToken: "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
slippage: 0.005,
curveType: 'uncorrelated',
burnAmount: 100000,
version: 0
});
console.log(output);
})
Create Burn Liquidity payload
(async() => {
const output = await sdk.Liquidity.createBurnLiquidityPayload({
fromToken: "0x1::aptos_coin::AptosCoin",
toToken: "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
slippage: 0.005,
curveType: 'uncorrelated',
burnAmount: 100000,
version: 0
});
console.log(output);
})
More examples
More examples you can find in the following directory: src/tests/
.
Code examples to work with Aptos SDK can be found in the examples directory.
(back to top)
Roadmap
See the open issues for a full list of proposed features (and known issues).
(back to top)
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
(back to top)
License
Distributed under the GPL v3 License. See LICENSE
for more information.
(back to top)