1.0.3 • Published 1 year ago
test-swap-sdk-knv-2 v1.0.3
PANORA SDK
SDK to perform the most optimal swap
Installtion
Using npm
npm i @panoraexchange/swap-sdk
Using yarn
yarn add @panoraexchange/swap-sdk
Using pnpm
pnpm add @panoraexchange/swap-sdk
For complete example of SDK usage please refer to: https://docs.panora.exchange
Usage
Execute Swap Transactions
Scenario 1: For ExactIn Swap where fromTokenAmount is entered (instead of toTokenAmount), the endpoint executes the transaction to get maximum toTokenAmount
ExactInSwap = async(SwapParams, private_key);
SwapParams is an object with the below field
SwapParams | Required | Description |
---|---|---|
chainId | No | ID for the chain for which the endpoint is being invoked. Note: Default chainID is 1 for Aptos Mainnet |
fromTokenAddress | Yes | Address of the token being swapped from.Example: If you want to swap 10.5 APT to lzUSDC, then fromTokenAddress is 0x1::aptos_coin::AptosCoin |
toTokenAddress | Yes | Address of the token being swapped to.Example: If you want to swap 10.5 APT to lzUSDC, then toTokenAddress is 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC |
fromTokenAmount | Yes | Amount of the token being swapped from. Please set the amount without Token decimalsExample: If you want to swap 10.5 APT to lzUSDC, then fromTokenAmount is 10.5 |
toWalletAddress | Yes | Address of the wallet to which the swapped tokens will be sent |
slippagePercentage | No | Slippage tolerance as a percentage value.Example: For 3% slippage tolerance, set the value as 3. This can be set as 0.1, 0.5, 1.0 or any custom slippage percentage between 0 and 100Note: If nothing is entered, slippage tolerance will be set to 1 by default. Anything after two decimals will be truncated |
integratorFeePercentage | No | Integrator fee as a percentage value.Example: For 2% integrator fee, set the value as 2. This can be set as 0.1, 0.5, 1.0 or any custom integrator fee between 0 and 2.Note: If nothing is entered, integrator fee will be set to 0 by default. Anything after two decimals will be truncated |
Scenario 2: For ExactOut Swap where toTokenAmount is entered (instead of fromTokenAmount), the endpoint executes the transaction to pay minimum fromTokenAmount
ExactOutSwap = async(SwapParams, private_key);
SwapParams is an object with the below field
SwapParams | Required | Description |
---|---|---|
chainId | No | ID for the chain for which the endpoint is being invoked. Note: Default chainID is 1 for Aptos Mainnet |
fromTokenAddress | Yes | Address of the token being swapped from.Example: If you want to swap 10.5 APT to lzUSDC, then fromTokenAddress is 0x1::aptos_coin::AptosCoin |
toTokenAddress | Yes | Address of the token being swapped to.Example: If you want to swap 10.5 APT to lzUSDC, then toTokenAddress is 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC |
toTokenAmount | Yes | Amount of the token being swapped to. Please set the amount without Token decimalsExample: If you want to swap from APT to 100 lzUSDC, then toTokenAmount is 100 |
toWalletAddress | Yes | Address of the wallet to which the swapped tokens will be sent |
slippagePercentage | No | Slippage tolerance as a percentage value.Example: For 3% slippage tolerance, set the value as 3. This can be set as 0.1, 0.5, 1.0 or any custom slippage percentage between 0 and 100Note: If nothing is entered, slippage tolerance will be set to 1 by default. Anything after two decimals will be truncated |
integratorFeePercentage | No | Integrator fee as a percentage value.Example: For 2% integrator fee, set the value as 2. This can be set as 0.1, 0.5, 1.0 or any custom integrator fee between 0 and 2.Note: If nothing is entered, integrator fee will be set to 0 by default. Anything after two decimals will be truncated |
Get Quote Details for the swap
Scenario 1: For ExactIn Swap where fromTokenAmount is entered (instead of toTokenAmount), the endpoint returns the maximum toTokenAmount
ExactInSwapQuote = async(GetQuotesParams);
GetQuoteParams is an object with the below fields
GetQuotesParams | Required | Description |
---|---|---|
chainId | No | ID for the chain for which the endpoint is being invoked. Note: Default chainID is 1 for Aptos Mainnet |
fromTokenAddress | Yes | Address of the token being swapped from.Example: If you want to swap 10.5 APT to lzUSDC, then fromTokenAddress is 0x1::aptos_coin::AptosCoin |
toTokenAddress | Yes | Address of the token being swapped to.Example: If you want to swap 10.5 APT to lzUSDC, then toTokenAddress is 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC |
fromTokenAmount | Yes | Amount of the token being swapped from. Please set the amount without Token decimalsExample: If you want to swap 10.5 APT to lzUSDC, then fromTokenAmount is 10.5 |
slippagePercentage | No | Slippage tolerance as a percentage value.Example: For 3% slippage tolerance, set the value as 3. This can be set as 0.1, 0.5, 1.0 or any custom slippage percentage between 0 and 100Note: If nothing is entered, slippage tolerance will be set to 1 by default. Anything after two decimals will be truncated |
integratorFeePercentage | No | Integrator fee as a percentage value.Example: For 2% integrator fee, set the value as 2. This can be set as 0.1, 0.5, 1.0 or any custom integrator fee between 0 and 2.Note: If nothing is entered, integrator fee will be set to 0 by default. Anything after two decimals will be truncated |
Scenario 2: For ExactOut Swap where toTokenAmount is entered (instead of fromTokenAmount), the endpoint returns the minimum fromTokenAmount
ExactOutSwapQuote = async(GetQuotesParams);
GetQuoteParams is an object with the below fields
GetQuotesParams | Required | Description |
---|---|---|
chainId | No | ID for the chain for which the endpoint is being invoked. Note: Default chainID is 1 for Aptos Mainnet |
fromTokenAddress | Yes | Address of the token being swapped from.Example: If you want to swap 10.5 APT to lzUSDC, then fromTokenAddress is 0x1::aptos_coin::AptosCoin |
toTokenAddress | Yes | Address of the token being swapped to.Example: If you want to swap 10.5 APT to lzUSDC, then toTokenAddress is 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC |
toTokenAmount | Yes | Amount of the token being swapped to. Please set the amount without Token decimalsExample: If you want to swap from APT to 100 lzUSDC, then toTokenAmount is 100 |
slippagePercentage | No | Slippage tolerance as a percentage value.Example: For 3% slippage tolerance, set the value as 3. This can be set as 0.1, 0.5, 1.0 or any custom slippage percentage between 0 and 100Note: If nothing is entered, slippage tolerance will be set to 1 by default. Anything after two decimals will be truncated |
integratorFeePercentage | No | Integrator fee as a percentage value.Example: For 2% integrator fee, set the value as 2. This can be set as 0.1, 0.5, 1.0 or any custom integrator fee between 0 and 2.Note: If nothing is entered, integrator fee will be set to 0 by default. Anything after two decimals will be truncated |