Git Product home page Git Product logo

zilswap-sdk's Introduction

Zilswap Typescript SDK

Setup

Install from npm:

npm install zilswap-sdk

SDK Usage

Initialize the sdk based on the required network, then call the required methods which will automatically map and call the corresponding smart contract correct transitions.

  import { Zilswap } from 'zilswap-sdk'

  (async () => {
    const zilswap = new Zilswap(Network.TestNet)
    await zilswap.initialize()
    await zilswap.addLiquidity('SWTH', '42', '42')
    await zilswap.teardown()
  })()

Methods

All public Zilswap methods can be found on the Zilswap SDK object.

All public Zilo methods can be found on the Zilo SDK object.

Full typescript definitions can also be found in the Modules.

The following is a list of methods to quickly get you started:

Swap & Liquidity

  • approveTokenTransferIfRequired - approves transfers to zilswap for the given token contract, if the current approval amount is insufficient.
  • addLiquidity - adds liquidity to the pool
  • removeLiquidity - removes liquidity to the pool
  • swapWithExactInput - swaps a token for another token, specifying the exact amount that should be given.
  • swapWithExactOutput - swaps a token for another token, specifying the exact amount that should be received.

Getters

  • getAppState - gets the current dApp state
  • getPool - gets the reserve values for a pool
  • getObservedTxs - gets the txs that the SDK is observing

Configuration

  • addToken - adds a token that is not in the pre-built list
  • observeTx - observe a zilliqa blockchain tx
  • setDeadlineBlocks - set the number of blocks before a transition sent by the SDK to expires

Helpers

  • toUnitless - converts a human amount into a unitless integer that is used by Scilla.
  • toUnit - converts a unitless integer used by scilla into a human readable amount.
  • getRatesForInput - get the current exchange rates for a pool by giving an input amount.
  • getRatesForOutput - get the current exchange rates for a pool by giving an output amount.

Test Usage

  1. Ensure enough tokens minted to your address on testnet
  2. Run PRIVATE_KEY=xxx yarn run test

Developing

Generate documentation with typedoc. Install with:

npm i typedoc typedoc-plugin-markdown --global

then run:

typedoc --out ./doc ./src --excludePrivate --excludeNotExported --plugin typedoc-plugin-markdown

Contributing

Please review the contribution guidelines before contributing or opening pull requests.

zilswap-sdk's People

Contributors

dependabot[bot] avatar intsol avatar junw3i avatar jx-willdo avatar melvinbeemer avatar ravenxce avatar snowsledge avatar stevenkhong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zilswap-sdk's Issues

About the way of constructing a zilswap class

constructor(readonly network: Network, walletProviderOrKey?: WalletProvider | string, options?: Options)

I want to know how to use WalletProvider not the privateKey as the second param of the function? That would be better if you can give an example. I look forward to your reply. Thanks!

[BUG] Bug when calling intialize() for Zilswap

Describe the bug

To Reproduce
Steps to reproduce the behavior:

  1. Switch to use MainNet
  2. run intialize()
  3. See error FetchError: invalid json response body at https://api.zilliqa.com/ reason: Unexpected token < in JSON at position 0

Expected behavior
Expected it to work

Screenshots
Screenshot 2021-07-07 at 11 14 06 PM

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

[BUG] ...on the Zilswap platform there’s a problem viewing pools that have been entered. For some reason they showed up for a couple weeks then I haven’t been able to see them since. So I have no clue the totals or the rewards I have in or from the pools. I try and keep all pools equal so it’s been a little bit of a problem. I contacted Discord but wanted to touch base here as well since there was starting to be a rather large portion in the ZIL Zwap pool. Hope this helps a little and let me know if I can be of any further assistance

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

[Bug] AddLiquidity - null check, wrong param for IncreaseAllowance

Ref 1 - accessing undefined when allowances_map haven't yet contain user address key.
Ref 2 - increasing allowance for the wrong address.

public async approveTokenTransferIfRequired(tokenID: string, amount: BN): Promise<TxReceipt | null> {
    …
    // Ref 1
    const allowance = new BN(tokenState.allowances_map[this.appState!.currentUser!][this.contractHash] || 0)

    if (allowance.lt(amount)) {
      console.log('sending increase allowance txn..')
      const approveTxn = await token.contract.call(
        'IncreaseAllowance',
        [
          {
            vname: 'spender',
            type: 'ByStr20',
            // Ref 2
            value: this.contractHash,
          },
        …
        ],
  …
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.