1.0.8 • Published 11 months ago
@panoraexchange/swap-sdk v1.0.8
PANORA SDK
SDK to perform the most optimal swap
Installtion
Using npm
npm i @panoraexchange/swap-sdkUsing yarn
yarn add @panoraexchange/swap-sdkUsing pnpm
pnpm add @panoraexchange/swap-sdkFor complete example of SDK usage please refer to: https://docs.panora.exchange
Attribution
Kindly include proper attribution when using the SDK in projects or presentations. Mention “Powered by Panora” whenever applicable.
Usage
Initialize Panora SDK
import Panora, { PanoraConfig } from "@panoraexchange/swap-sdk"
const config: PanoraConfig = {
apiKey: "YOUR API KEY",
rpcUrl: "CUSTOM RPC URL"
}
const panora = new Panora(config)Execute Swap Transactions
Swap = 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 USDT, 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 USDT, then toTokenAddress is 0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b |
| fromTokenAmount | No | Amount of the token being swapped from. Please set the amount without Token decimalsExample: If you want to swap 10.5 APT to USDT, then fromTokenAmount is 10.5 |
| toTokenAmount | No | Amount of the token being swapped to. Please set the amount without Token decimalsExample: If you want to swap from APT to 100 USDT, then toTokenAmount is 100 |
| toWalletAddress | Yes | Address of the wallet to which the swapped tokens will be sent |
| slippagePercentage | No | Slippage tolerance as 'auto' (which lets Panora choose the optimal slippage for the transaction, up to a maximum of 5%) or 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 auto by default. If a numeric value is entered, anything after one decimal 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 one decimal will be truncated |
| integratorFeeAddress | No | Wallet Address where integrators want to receive their fee share.Note: Ensure it starts with 0x followed by 64 characters |
| includeSources | No | List of liquidity sources to be included for route calculation.Example: "ThalaSwapV2", "Liquidswap"Note: If not specified, all available sources are included by default. |
| excludeSources | No | List of liquidity sources to be excluded from the route.Example: "Aux"Note: If not specified, none of the sources will be excluded by default. |
| onlyDirectRoutes | No | Set to true to restrict to direct routes without intermediate hops or splits.Example: For direct swaps without hops or splits, set to true.Default is false. |
Get Quote Details for the swap transaction
SwapQuote = async(SwapQuoteParams);SwapQuoteParams is an object with the below fields
| SwapQuoteParams | 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 USDT, 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 USDT, then toTokenAddress is 0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b |
| 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 USDT, then fromTokenAmount is 10.5 |
| 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 USDT, then toTokenAmount is 100 |
| slippagePercentage | No | Slippage tolerance as 'auto' (which lets Panora choose the optimal slippage for the transaction, up to a maximum of 5%) or 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 auto by default. If a numeric value is entered, anything after one decimal 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 one decimal will be truncated |
| integratorFeeAddress | No | Wallet Address where integrators want to receive their fee share.Note: Ensure it starts with 0x followed by 64 characters |
| getTransactionData | No | Enter "rawTransaction" or "transactionPayload" to be included in the response. |
| includeSources | No | List of liquidity sources to be included for route calculation.Example: "ThalaSwapV2", "Liquidswap"Note: If not specified, all available sources are included by default. |
| excludeSources | No | List of liquidity sources to be excluded from the route.Example: "Aux"Note: If not specified, none of the sources will be excluded by default. |
| onlyDirectRoutes | No | Set to true to restrict to direct routes without intermediate hops or splits.Example: For direct swaps without hops or splits, set to true.Default is false. |