2.0.0-rc4 • Published 3 months ago

zilswap-sdk v2.0.0-rc4

Weekly downloads
9
License
MIT
Repository
github
Last release
3 months ago

Zilswap Typescript SDK

Setup

Install from npm:

npm install zilswap-sdk

ZilSwap-V1 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.

ZilSwap-V2 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 { ZilSwapV2 } from 'zilswap-sdk'

  (async () => {
    const zilswap = new ZilSwapV2(Network.TestNet)
    await zilswap.initialize()
    await zilswap.addLiquidity(tokenAHash, tokenBHash, poolHash, '1000', '1000', '0', '0', 5)
    await zilswap.teardown()
  })()

Methods

All public ZilswapV2 methods can be found on the ZilswapV2 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.
  • deployAndAddPool - Deploys a new pool, and adds to the router
  • deployPool - Deploys a new pool
  • addPool - Adds an existing pool to the router
  • addLiquidity - adds liquidity to the pool
  • addLiquidityZIL - adds liquidity to the pool, with ZIL as one of the tokens. Contract accepts user's ZIL and wraps it, before transferring to pool
  • removeLiquidity - removes liquidity to the pool
  • removeLiquidityZIL - removes liquidity to the pool. Returns ZIL as one of the tokens to the user
  • swapExactTokensForTokens - swaps a token for another token, specifying the exact amount that should be given.
  • swapTokensForExactTokens - swaps a token for another token, specifying the exact amount that should be received.
  • swapExactZILForTokens - swaps ZIL for another token, specifying the exact amount that should be given.
  • swapZILForExactTokens - swaps ZIL for another token, specifying the exact amount that should be received.
  • swapExactTokensForZIL - swaps a token for ZIL, specifying the exact amount that should be given.
  • swapTokensForExactZIL - swaps a token for ZIL, specifying the exact amount that should be received.

Getters

  • getAppState - gets the current dApp state
  • getRouterState - gets the current router state
  • getPoolStates - gets the states of all pools on the router
  • getTokenPools - gets a mapping of tokens to pools
  • getTokens - gets an array of tokens in the pools, including the pool LP tokens
  • getObservedTxs - gets the txs that the SDK is observing
  • getOutputForExactInput - get the estimated output amount for a pool by giving an input amount.
  • getInputForExactOutput - get the estimated input amount for a pool by giving an output amount.

Configuration

  • 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.

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 --plugin typedoc-plugin-markdown

Contributing

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

2.0.0-rc5

3 months ago

2.0.0-rc4

10 months ago

2.0.0-rc3

10 months ago

1.3.25

1 year ago

2.0.0-rc2

1 year ago

2.0.0-rc1

1 year ago

1.3.24

2 years ago

1.3.23

2 years ago

1.3.22

2 years ago

1.3.17

2 years ago

1.3.18

2 years ago

1.3.19

2 years ago

1.3.20

2 years ago

1.3.21

2 years ago

1.3.15

2 years ago

1.3.16

2 years ago

1.3.14

3 years ago

1.3.13

3 years ago

1.3.12

3 years ago

1.3.11

3 years ago

1.3.10

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.2.2

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

4 years ago

1.0.0-rc.6

4 years ago

1.0.0-rc.5

4 years ago

1.0.0-rc.4

4 years ago

1.0.0-rc.3

4 years ago

1.0.0-rc.2

4 years ago

1.0.0-rc.1

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago