npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pantinho

v0.0.9

Published

SDK for use any functions of LiquidSwap

Downloads

10

Readme

Installation

npm i @pantinhoswaptest/aptos-liquidity-sdk

Usage

Init SDK

import { SDK } from '@pantinhoswaptest/aptos-liquidity-sdk';

const sdk = new SDK({
  nodeUrl: 'https://fullnode.devnet.aptoslabs.com', // Node URL
  networkOptions: {
    nativeToken: '0x1::test_coin::TestCoin', // Type of Native network token
    modules: {
      Scripts:
        '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::scripts', // This module is used for Swap
      CoinInfo: '0x1::coin::CoinInfo', // Type of base CoinInfo module
      CoinStore: '0x1::coin::CoinStore', // Type of base CoinStore module
    },
  }
})

You want swap EXACTLY 1 APTOS to SLIPPAGED BTC amount

(async () => {
  // Get BTC amount
  const amount = await sdk.Swap.calculateRates({
    fromToken: '0x1::test_coin::TestCoin',
    toToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
    amount: 1000000, // 1 APTOS
    interactiveToken: 'from',
    pool: {
      address: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
      moduleAddress: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
      lpToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::lp::LP<0x1::test_coin::TestCoin, 0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC>'
    }
  })
  console.log(amount) // 1584723 (0.01584723 BTC)

  // Generate TX payload for swap 1 APTOS to maximum 0.01584723 BTC
  // and minimum 0.01584723 BTC - 5% (with slippage 5%)
  const txPayload = sdk.Swap.createSwapTransactionPayload({
    fromToken: '0x1::test_coin::TestCoin',
    toToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
    fromAmount: 1000000, // 1 APTOS,
    toAmount: 1584723, // 0.01584723 BTC,
    interactiveToken: 'from',
    slippage: 0.05, // 5% (1 - 100%, 0 - 0%)
    pool: {
      address: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
      moduleAddress: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
      lpToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::lp::LP<0x1::test_coin::TestCoin, 0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC>'
    }
  })
  console.log(txPayload);
  /**
   Output:
   {
      type: 'script_function_payload',
      function: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::scripts::swap',
      typeArguments: [
        '0x1::test_coin::TestCoin',
        '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
        '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::lp::LP<0x1::test_coin::TestCoin, 0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC>'
      ],
      arguments: [
        '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
        '1000000',
        '1505487'
      ]
    }
   */
})()

You want get EXACTLY 0.001 BTC and send SLIPPAGED APTOS amount

(async () => {
  // Get APTOS amount
  const amount = await sdk.Swap.calculateRates({
    fromToken: '0x1::test_coin::TestCoin',
    toToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
    amount: 100000, // 0.001 BTC
    interactiveToken: 'to', // from - calculate TO amount, to - calculate FROM amount
    pool: {
      address: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
      moduleAddress: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
      lpToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::lp::LP<0x1::test_coin::TestCoin, 0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC>'
    }
  })
  console.log(amount) // 116831 (0.116831 APTOS)

  // Generate TX payload for get EXACTLY 0.001 BTC
  // and minimum send 0.116831 + 5% (with slippage 5%)
  const txPayload = sdk.Swap.createSwapTransactionPayload({
    fromToken: '0x1::test_coin::TestCoin',
    toToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
    fromAmount: 116831, // 0.116831 APTOS,
    toAmount: 100000, // 0.001 BTC,
    interactiveToken: 'to',
    slippage: 0.05, // 5% (1 - 100%, 0 - 0%)
    pool: {
      address: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
      moduleAddress: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
      lpToken: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::lp::LP<0x1::test_coin::TestCoin, 0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC>'
    }
  })
  console.log(txPayload);
  /**
   Output:
   {
      type: 'script_function_payload',
      function: '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::scripts::swap_into',
      typeArguments: [
        '0x1::test_coin::TestCoin',
        '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC',
        '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::lp::LP<0x1::test_coin::TestCoin, 0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9::coins::BTC>'
      ],
      arguments: [
        '0x43417434fd869edee76cca2a4d2301e528a1551b1d719b75c350c3c97d15b8b9',
        '110989',
        '100000'
      ]
    }
   */
})()