πŸ–₯️Aggregator SDK

A wrapper over the Panora API to provide functions to swap between any two tokens easily

Installation

Using npm

npm install @panoraexchange/swap-sdk

Using yarn

yarn add @panoraexchange/swap-sdk

Using pnpm

pnpm add @panoraexchange/swap-sdk

Atrribution

Kindly include proper attribution when using the SDK in projects or presentations. Mention β€œPowered by Panora” whenever applicable.

Usage

1. Initialize Panora SDK

import Panora, { PanoraConfig } from "@panoraexchange/swap-sdk"

const config: PanoraConfig = {
  apiKey: "YOUR API KEY",
  rpcUrl: "CUSTOM RPC URL"
}

const client = new Panora(config)

2. Swap Functions

i. ExactInSwap:

const exactInSwap = async () => {
  const response = await client.ExactInSwap(
    {
      chainId: "1",
      fromTokenAddress: "0x1::aptos_coin::AptosCoin",
      toTokenAddress:
        "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
      fromTokenAmount: "1",
      toWalletAddress: "YOUR WALLET ADDRESS",
      slippagePercentage: "1",
      integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
      integratorFeePercentage: "1",
    },
    "YOUR PRIVATE KEY"
  )
}

ii. ExactOutSwap:

const exactOutSwap = async () => {
  const response = await client.ExactOutSwap(
    {
      chainId: "1",
      fromTokenAddress: "0x1::aptos_coin::AptosCoin",
      toTokenAddress:
        "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
      toTokenAmount: "12",
      toWalletAddress: "YOUR WALLET ADDRESS",
      slippagePercentage: "1",
      integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
      integratorFeePercentage: "1",
    },
    "YOUR PRIVATE KEY"
  )
}

iii. ExactInSwapBatch:

const exactInSwapBatch = async () => {
  const response = await client.ExactInSwapBatch(
    [
      {
        chainId: "1",
        fromTokenAddress: "0x1::aptos_coin::AptosCoin",
        toTokenAddress:
          "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
        fromTokenAmount: "1",
        toWalletAddress: "YOUR WALLET ADDRESS",
        slippagePercentage: "1",
        integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
        integratorFeePercentage: "1",
      },
      {
        chainId: "1",
        fromTokenAddress:
          "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT",
        toTokenAddress:
          "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::WETH",
        fromTokenAmount: "1",
        toWalletAddress: "YOUR WALLET ADDRESS",
        slippagePercentage: "1",
        integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
        integratorFeePercentage: "1",
      },
    ],
    "YOUR PRIVATE KEY"
  )
}

iv. ExactOutSwapBatch:

const exactOutSwapBatch = async () => {
  const response = await client.ExactOutSwapBatch(
    [
      {
        chainId: "1",
        fromTokenAddress: "0x1::aptos_coin::AptosCoin",
        toTokenAddress:
          "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
        toTokenAmount: "1",
        toWalletAddress: "YOUR WALLET ADDRESS",
        slippagePercentage: "1",
        integratorFeeAddress: "INTEGRATOR FEE ADDRESS",
        integratorFeePercentage: "1",
      },
      {
        chainId: "1",
        fromTokenAddress:
          "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT",
        toTokenAddress:
          "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::WETH",
        toTokenAmount: "1",
        toWalletAddress: "YOUR WALLET ADDRESS",
        slippagePercentage: "1",
        integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
        integratorFeePercentage: "1",
      },
    ],
    "YOUR PRIVATE KEY"
  )
}

3. Quote Functions

i. ExactInSwapQuote

const exactInSwapQuote = async () => {
  const response = await client.ExactInSwapQuote({
    chainId: "1",
    fromTokenAddress: "0x1::aptos_coin::AptosCoin",
    toTokenAddress:
      "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
    fromTokenAmount: "1",
    toWalletAddress: "YOUR WALLET ADDRESS",
    slippagePercentage: "1",
    integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
    integratorFeePercentage: "1",
    // "rawTransaction" | "transactionPayload" depending on the use case
    getTransactionData: "rawTransaction"
  })
}

ii. ExactOutSwapQuote

const exactOutSwapQuote = async () => {
  const response = await client.ExactOutSwapQuote({
    chainId: "1",
    fromTokenAddress: "0x1::aptos_coin::AptosCoin",
    toTokenAddress:
      "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC",
    toTokenAmount: "1",
    toWalletAddress: "YOUR WALLET ADDRESS",
    slippagePercentage: "1",
    integratorFeeAddress: "INTEGRATOR FEE WALLET ADDRESS",
    integratorFeePercentage: "1",
  })
}

Last updated