0.0.21 • Published 10 months ago

kana-aggregator-sdk v0.0.21

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

Kanalabs aggregator sdk

Description

  • SDK to interact with all Amm platform available on Aptos and Solana Blockchain

SDK Usage

1. Solana
2. Aptos

Installation

npm i kana-aggregator-sdk

Testnet TokenList

  //only for testnet
  import { getTokenByChainID } from 'kana-aggregator-sdk'
  //chainID 1 for solana and 2 for Aptos
  let chainId = 2
  let networkId = 2
  const devTokens = getTokenByChainID(chainId,networkId);  //networkId is 1 for mainnet tokens and 2 for testnet

Aptos Aggregator

Using SDk

    import { getRoutesForSwap, getSwapIx} from 'kana-aggregator-sdk'
    import * as aptos from 'aptos';
    const NODE_URL = "https://fullnode.testnet.aptoslabs.com"; //RPC URL

    let client = new aptos.AptosClient(NODE_URL);

    const chainId = "aptos";
    const networkId = 2 // 1 for mainnet
    const inputCoin = "0x1::aptos_coin::AptosCoin";
    const outputCoin = "0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::USDT";
    inputAmount = 100000000;
    const slippage = 1; // Percentage


    async function swap(){
        // Get best routes for the given pair
        let routeData = await getRoutesForSwap(
            chainId,
            inputCoin,
            outputCoin,
            inputAmount,
            slippage,
            //Fee account has to be initialized before collecting fee
            "0xf0dc067a835098c9232a0f3f884c801099c75e1100944974729fa131f066d11e" . //fee account to collect integrator fee 
        );

        let optimalRoute = routeData.routes[0]
        // Get The transaction payload for transaction
        const txnPayload = await getSwapIx(
            chainId,
            optimalRoute
        )
        const txnRequest = await client.generateTransaction(
            account.address(),
            txnPayload,
            {
                max_gas_amount: "20000",
                gas_unit_price: "100",
                expiration_timestamp_secs: `${new Date().getTime() / 1000 + 60}`
            }
        );
        <!-- const signedTxn = await client.signTransaction(account, txnRequest);
        const res = await client.submitTransaction(signedTxn);
        await client.waitForTransactionWithResult(res.hash);
        console.log(res.hash); -->
    }

    swap()

Using API's

let swapQuote = 'https://ag.kanalabs.io/stage-devquote/swapQuote'
let swapIx = 'https://ag.kanalabs.io/stage-devix/swapInstruction'

//For example we have used AXIOS and JS you can use your preferred package or language

 const response = await axios.get(swapQuote, {
      params: {
        chainId: "aptos",
        networkId: 1, // 2 for testnet
        inputCoin: inputCoin,
        outputCoin: outputCoin,
        inputAmount: inputAmount,
        slippage: slippage ? slippage : null,
        directRoutes: directRoutes, //optional currently not suported 
      },
  })

let swaproutes = response.data

const txnPayload = await axios.post(swapIx, {
    networkId: 1, 2 for testnet
    chainId: "aptos",
    swapRoute: swaproutes.routes[0] ,
})
 const txnRequest = await client.generateTransaction(
      account.address(),
      txnPayload,
            {
                max_gas_amount: "20000",
                gas_unit_price: "100",
                expiration_timestamp_secs: `${new Date().getTime() / 1000 + 60}`
            }
        );
        <!-- const signedTxn = await client.signTransaction(account, txnRequest);
        const res = await client.submitTransaction(signedTxn);
        await client.waitForTransactionWithResult(res.hash);
        console.log(res.hash); -->

Outputs

Get Quote

routes [
  {
    RouteA: {
      amm: 'Pontem',
      coinX: '0x1::aptos_coin::AptosCoin',
      coinY: '0x808b4ffe04011cd20327a910518b4bff661f73fa907e9fc41ad690f84fa6f83e::asset::WETH',
      isXtoY: false,
      curve: '0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated',
      curveType: 'Uncorrelated',
      inputAmount: 100000000,
      outputAmount: '2575'
    },
    RouteB: {
      amm: 'Pontem',
      coinX: '0x808b4ffe04011cd20327a910518b4bff661f73fa907e9fc41ad690f84fa6f83e::asset::WETH',
      coinY: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::USDT',
      isXtoY: false,
      curve: '0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated',
      curveType: 'Uncorrelated',
      inputAmount: '2575',
      outputAmount: '876648',
      outAmountWithSlippage: 867882
    },
    outAmountWithSlippage: 867882
  },
  {
    amm: 'Pontem',
    coinX: '0x1::aptos_coin::AptosCoin',
    coinY: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::USDT',
    isXtoY: false,
    curve: '0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated',
    curveType: 'Uncorrelated',
    inputAmount: 100000000,
    outputAmount: '876201',
    outAmountWithSlippage: 867439
  },
]

Swap Instruction

{
  type: 'entry_function_payload',
  function: '0x2fd573969cf2d5f0bf8bc9ec245dec6d031f6e00e50f32785913135c318a2dcd::aggregatorv1::intermediate_route',
  type_arguments: [
    '0x1::aptos_coin::AptosCoin',
    '0x808b4ffe04011cd20327a910518b4bff661f73fa907e9fc41ad690f84fa6f83e::asset::WETH',
    '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::USDT',
    '0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated',
    '0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated'
  ],
  arguments: [ '1', '1', 'false', '1', '1', 'false', '100000000', '867882' ]
}
0.0.21-beta-2

10 months ago

0.0.20

12 months ago

0.0.21

11 months ago

0.0.19

12 months ago

0.0.20-beta-1

11 months ago

0.0.15-beta-0.9

1 year ago

0.0.15-beta-0.8

1 year ago

0.0.15-beta-0.7

1 year ago

0.0.15-beta-0.6

1 year ago

0.0.15-beta-0.5

1 year ago

0.0.18-beta-0.3

1 year ago

0.0.15-beta-0.4

1 year ago

0.0.18-beta-0.2

1 year ago

0.0.15-beta-0.3

1 year ago

0.0.18-beta-0.1

1 year ago

0.0.15-beta-0.2

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.17-beta-0.9

1 year ago

0.0.17-beta-0.8

1 year ago

0.0.17-beta-0.1

1 year ago

0.0.17-beta-0.3

1 year ago

0.0.17-beta-0.2

1 year ago

0.0.17-beta-0.5

1 year ago

0.0.17-beta-0.4

1 year ago

0.0.17-beta-0.7

1 year ago

0.0.17-beta-0.6

1 year ago

0.0.15-beta-1.4

1 year ago

0.0.15-beta-1.3

1 year ago

0.0.15-beta-1.2

1 year ago

0.0.15-beta-1.1

1 year ago

0.0.15-beta-0.1

1 year ago

0.0.15-beta-0

1 year ago

0.0.15

1 year ago

0.0.14-dev.4.8

1 year ago

0.0.14-dev.4.7

1 year ago

0.0.14-dev.4.6

1 year ago

0.0.14-dev.4.5

1 year ago

0.0.14-dev.4.4

1 year ago

0.0.14-dev.4.3

1 year ago

0.0.14-dev.4.2

1 year ago

0.0.14-dev.4.1

1 year ago

0.0.14-dev.4

1 year ago

0.0.14-dev.3

1 year ago

0.0.14-dev.2

1 year ago

0.0.14-dev.1

1 year ago

0.0.14

1 year ago

0.0.13-beta.0

1 year ago

0.0.13-beta

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago