Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
127 lines (91 sloc) 4.76 KB

Validator is a smart contract used to check for failures prior to attempting a swap.

Validator Client

Add the @airswap/protocols package to your application.

$ yarn add @airswap/protocols

Import the Validator client.

import { Validator } from '@airswap/protocols'

constructor

Create a new Validator client.

public constructor(
  chainId = chainIds.RINKEBY,
  walletOrProvider?: ethers.Wallet | ethers.providers.Provider
)
Param Type Optionality Description
chainId string optional Ethereum chain ID of the network to connect to, either 1 or 4.
walletOrProvider ethers.Wallet or ethers.providers.Provider optional Ethers wallet or provider to use for the contract instance

Basic Example

Create a client for the Rinkeby Validator using the default provider.

const validator = new Validator()

Custom Provider Example

Create a client for the Mainnet Validator using an INFURA provider.

import { chainIds } from '@airswap/constants'
const provider = new ethers.providers.InfuraProvider(...)
const validator = new Validator(chainIds.MAINNET, provider);

See a list of available providers on the ethers.js documentation.

getReason

Get a plain language reason for a swap failure.

public static getReason(reason: string): string
Param Type Optionality Description
reason string required The error text emitted by a check* function.

checkSwap

Check swap given an order.

public async checkSwap(order: Order): Promise<Array<string>>
Param Type Optionality Description
order Order required The order that would be swapped.

checkWrappedSwap

Check swap through a Wrapper given an order.

public async checkWrappedSwap(
  order: Order,
  fromAddress: string,
  wrapperAddress: string
): Promise<Array<string>>
Param Type Optionality Description
order Order required Order that would be swapped.
fromAddress address required Wallet address that would send the transaction.
wrapperAddress address required Address of the wrapper contract to use.

checkDelegate

Check swap through a Delegate given an order.

public async checkDelegate(
  order: Order,
  delegateAddress: string
): Promise<Array<string>>
Param Type Optionality Description
order Order required Order that would be swapped.
delegateAddress address required Address of the delegate contract to use.

checkWrappedDelegate

Check swap through a Wrapper and Delegate given an order.

public async checkWrappedDelegate(
  order: Order,
  delegateAddress: string,
  wrapperAddress: string
): Promise<Array<string>>
Param Type Optionality Description
order Order required Order that would be swapped.
delegateAddress address required Address of the delegate contract to use.
wrapperAddress address required Address of the wrapper contract to use.
You can’t perform that action at this time.