👩‍💻
Builder Portal
  • Sovryn Builder Portal
    • Contribution
  • Design System
    • Design principles
    • Structure
    • Usage by Sovryn
  • UI Library
    • Overview
    • Getting Started
    • Atoms
      • Accordion
      • Badge
      • HealthBar
      • Button
      • DynamicValue
      • Heading
      • ErrorBadge
      • Icon
      • Input
      • Lottie
      • Paragraph
      • Toggle
      • Link
      • Checkbox
    • Molecules
      • AmountInput
      • ContextLink
      • Dialog
      • Dropdown
      • ErrorList
      • Footer
      • FormGroup
      • Header
      • HelperButton
      • Menu
      • NavMenuItem
      • Notification
      • Overlay
      • Pagination
      • RadioButton
      • RadioButtonGroup
      • Select
      • SimpleTable
      • StatusItem
      • Table
      • TableBase
      • Tabs
      • Tooltip
      • TransactionId
      • VerticalTabs
      • VerticalTabsMobile
      • WalletContainer
      • WalletIdentity
    • Working with Components
    • Links
    • Contribution
  • Sovryn SDK
    • Smart Router
      • Creating a New Swap Route
      • Available routes
        • AMM
        • MoC integration
        • MYNT bAsset
        • MYNT fixed rate
    • Sovryn Onboard
      • Installation
      • Usage
      • Custom Connectors
      • Custom UI
      • Contribution
    • The Graph
      • Overview
      • Usage
      • Sovryn Subgraphs
      • Advanced Usage
  • sovryn.app
    • Overview
    • Sovryn UI Library Usage
    • The Graph Usage
    • Links
    • Contribution
    • Dapp specific components
      • MaxButton
  • Smart Contracts
    • Overview
    • AMM
      • Liquidity
        • V1 Converters
        • V2 Converters
      • Conversion
      • Wrapper
        • V1 liquidity
        • V2 liquidity
        • Swaps
    • Sovryn Protocol
      • Lending
        • Mint
        • Burn
      • Borrowing
        • Borrow
        • Repay
      • Margin Trading
        • Open
        • Close
      • Collateral Management
    • Liquidity Mining
      • Deposit
      • Withdraw
      • Rewards
    • FastBTC
      • RSK->BTC
    • Bitocracy
      • Staking
      • Governor
      • Fee Sharing
      • Vesting
    • Zero
      • Borrower operations
      • Trove Manager
      • Satability Pool
      • Rewards
    • Mynt & DLLR
      • Basset to Masset Conversion
      • Masset to Basset Conversion
      • MOC Integration Conversion
Powered by GitBook
On this page
  • SwapRoute API
  • name: string
  • pairs(): Promise<SwapPairs>
  • quote(entry: string, destination: string, amount: BigNumberish, options?: Partial<Options>, overrides?: Partial<TransactionRequest>): Promise<BigNumber>
  • swap(entry: string, destination: string, amount: BigNumberish, options?: Partial<Options>, overrides?: Partial<TransactionRequest>): Promise<TransactionRequest>
  • approve(entry: string, destination: string, amount: BigNumberish, from: string, overrides?: Partial<TransactionRequest>): Promise<TransactionRequest | undefined>
  • permit(entry: string, destination: string, amount: BigNumberish, from: string, overrides?: Partial<PermitTransactionRequest>): Promise<PermitTransactionRequest | undefined>
  1. Sovryn SDK
  2. Smart Router

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.

// smart route type
type SwapRouteFunction = (provider: providers.Provider) => SwapRoute;

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.

async pairs() {
    return new Map([
       // RBTC -> SOV, XUSD
       '0x0000000000000000000000000000000000000000': [
         '0xefc78fc7d48b64958315949279ba181c2114abbd', // SOV
         '0xb5999795be0ebb5bab23144aa5fd6a02d080299f', // XUSD
       ],
       // SOV -> RBTC
       '0xefc78fc7d48b64958315949279ba181c2114abbd': [
         '0x0000000000000000000000000000000000000000' // BTC
       ],
    ]);
} 

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.

swap(entry, destination, amount, options, overrides) {
    return {
        to: '0xefc78fc7d48b64958315949279ba181c2114abbd',
        data: '0x00000',
        value: '0',
        ...overrides,
    };
}

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 permits, then you can use this instead of approve to make swap cheaper.

PreviousSmart RouterNextAvailable routes

Last updated 1 year ago