yarn add permaswap
npm install permaswap
params | Description |
---|---|
debug | Used for development and production environment selection |
account | everPay account string |
everpay | Everpay instance, please flow everpay-js docs |
import Permaswap from 'permaswap'
import { ethers } from 'ethers'
import Everpay from 'everpay'
const wallet = {
address: '0x26361130d5d6E798E9319114643AF8c868412859',
privateKey: '94c97d4cc865d77afaf2d64147f7c067890e1485eb5d8e2c15cc0b7528a08b47'
}
const provider = new ethers.providers.InfuraProvider('kovan')
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
})
Establish a websocket connection with Permaswap Router, callback will be executed after the connection is established.
Subscribe to order
via paySymbol
, receiveSymbol
, payAmount
. order
is continuously 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',
receiveAmount: '32.746822',
orderHash: '0x6985580ad60114fcdeabda7455cf43bcb3a5db0a4a80db33a1816ab1718f442a'
}
Where rate
and receiveAmount
can be used by the developer to determine if the order is worthy of being filled.
orderHash
is the unique identifier for the order
.
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.
Close the websocket connection between permaswap and router.
For more examples see test.ts