Creating a New Swap Route
A swap route is a function which accepts a single argument of ethers provider and returns object of SwapRoute
type.
SwapRoute API
name: string
Define a name for your swap route.
pairs(): Promise<SwapPairs>
Map of all supported tokens. Give an entry token as a key and all possible destination tokens as its value in array. Tokens must be defined as lowercased contract addresses. It's expected to define RBTC token as zero address.
In the example above, the swap route supports swaps from RBTC to SOV and XUSD, but SOV can be swapped only to RBTC, and XUSD has no destinations at all.
quote(entry: string, destination: string, amount: BigNumberish, options?: Partial<Options>, overrides?: Partial<TransactionRequest>): Promise<BigNumber>
Use entry, destination, and amount to calculate quote amount and return it as a BigNumber.
swap(entry: string, destination: string, amount: BigNumberish, options?: Partial<Options>, overrides?: Partial<TransactionRequest>): Promise<TransactionRequest>
Build an ethers transaction request which can be used to sign and broadcast transaction later. overrides
must be merged to the end result.
to
, data
and value
must be defined in the response.
approve(entry: string, destination: string, amount: BigNumberish, from: string, overrides?: Partial<TransactionRequest>): Promise<TransactionRequest | undefined>
If swap must have tokens approved to be used, you need to prepare transaction request here, if it's not required or required amount is already approved - just return undefined
entry
is likely to be a token you will need to approve.
amount
is amount we want to swap later, so also an amount we need to have approved
from
wallet address of an user who owns tokens.
permit(entry: string, destination: string, amount: BigNumberish, from: string, overrides?: Partial<PermitTransactionRequest>): Promise<PermitTransactionRequest | undefined>
If token supports permit
s, then you can use this instead of approve
to make swap cheaper.
Last updated