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

permaswap

v0.1.1

Published

permaswap client JS-SDK, supports web and nodeJS to make swap

Downloads

18

Readme

permaswap-js

Please upgrade to version 0.1.0 or later

Installation

Using yarn

yarn add permaswap

Using npm

npm install permaswap

Configuration

| params | Description | |-------------|---| |debug|Used for development and production environment selection| |account| everPay account string | |everpay|Everpay instance, please flow everpay-js docs|

Example

import Permaswap from 'permaswap'
import { ethers } from 'ethers'
import Everpay from 'everpay'

const wallet = {
  address: '0x26361130d5d6E798E9319114643AF8c868412859',
  privateKey: '94c97d4cc865d77afaf2d64147f7c067890e1485eb5d8e2c15cc0b7528a08b47'
}

const provider = new ethers.providers.InfuraProvider('goerli')
const signer = new ethers.Wallet(wallet.privateKey, provider)
const everpay = new Everpay({
  debug: true,
  account: wallet.address,
  ethConnectedSigner: signer
})

const permaswap = new Permaswap({
  debug: true,
  account: wallet.address,
  everpay
})

Methods

permaswap.init(callback)

Establish a websocket connection with Permaswap Router, callback will be executed after the connection is established.

permaswap.subscribe({ payTokenAmount, payTokenTag, receiveTokenTag }, subscribeHandler)

payTokenTag and receiveTokenTag represent the paid token tag and the received token tag, and the unique token tag corresponding to the token symbol is available via everpay.info().

Subscribe to order via payTokenTag, receiveTokenTag, payTokenAmount. The order is pushed to the subscribeHandler function.

subscribeHandler function, which takes two parameters, error and order.

order contains field examples

{
  event: 'order',
  userAddr: '0x26361130d5d6E798E9319114643AF8c868412859',
  tokenIn: 'ethereum-eth-0x0000000000000000000000000000000000000000',
  tokenOut: 'ethereum-usdt-0xd85476c906b5301e8e9eb58d174a6f96b9dfc5ee',
  price: '0.0003053731',
  priceImpact: '0.0039111582',
  bundle: {
    items: [
      //...
    ],
    expiration: 1666855442,
    salt: '2076d49c-7d53-44db-a664-3b4dcc33e46c',
    version: 'v1'
  },
  paths: [
    //...
  ],
  rate: '3274.6826',
  receiveTokenAmount: '32.746822',
  orderHash: '0x6985580ad60114fcdeabda7455cf43bcb3a5db0a4a80db33a1816ab1718f442a'
}

Where rate and receiveTokenAmount can be used by the developer to determine if the order is worthy of being filled.

orderHash is the unique identifier for the order.

permaswap.trade(tokenIn, tokenOut, bundle, paths, tradeHandler)

tokenIn, tokenOut, bundle, paths are all from order. The traderHandler function accepts one argument as the following example.

{
  event: 'status',
  orderHash: '0xb9586b38e624dd31654f3449f16ad23095ae7b6ce16c8abe2955f1028c85b101',
  everHash: '0x6153cac909ef7ba329412015985e68ab1e405f51934184d86b283953598d2971',
  status: 'success'
}

When status is 'success', it means the order was successful.

permaswap.close()

Close the websocket connection between permaswap and router.

Other

For more examples see test.ts