@shapeshiftoss/swapper
TypeScript icon, indicating that this package has built-in type declarations

17.6.3 • Public • Published

@shapeshiftoss/swapper

Getting Started

yarn add @shapeshiftoss/swapper

Usage

Swapper CLI

  • Copy the sample.env to .env
cp sample.env .env
  • Usage:
$ swapcli [sellSymbol] [buySymbol] [sellAmount](denominated in sell asset, not wei)

ie:

$ swapcli ETH USDC 0.001

Setup

import { SwapperManager, SwapperType, ZrxSwapper } from '@shapeshiftoss/swapper'

// in code
const manager = new SwapperManager<MyCustomSwapperTypes>()

// Add a swapper to the manager, you can add your own if it follows the `Swapper` API spec
manager
  .addSwapper(new ZrxSwapper())
  .addSwapper(new ThorchainSwapper())

// Get a swapper from the manager
const swapper = manager.getSwapper(SwapperType.Zrx)

// Remove a swapper from the manager
manager.removeSwapper(SwapperType.ZrxEthereum)

Working with the manager

// Get best quote and swapper for a trading pair
const { swapperType, quote } = await manager.getBestQuote(...args)

// Get the swapper and do stuff
const swapper = manager.getSwapper(swapperType)

Working with a specific swapper

// Get a list of supported assets/trading pairs
const assets = await swapper.getSupportedAssets()

// Get a quote from a swapper
const quote = await swapper.getQuote(...args)

// Execute a Trade
const txToSign = await swapper.buildTransaction(...args)

// broadcast your TX
const tx = await swapper.execute(signedTx)
// or
const tx = await adapter.broadcastTransaction(...args)

Readme

Keywords

none

Package Sidebar

Install

npm i @shapeshiftoss/swapper

Weekly Downloads

1

Version

17.6.3

License

MIT

Unpacked Size

296 kB

Total Files

164

Last publish

Collaborators

  • 0xgomes
  • giantkin
  • 0xean
  • kmart13
  • shapeshift-ci-bot
  • tech-keepkey