👩‍💻
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
  • Conversion Path
  • Conversion Rate
  • Conversion
  1. Smart Contracts
  2. AMM

Conversion

Swaps happen according to the provided conversion path and can involve one or multiple liquidity pools.

Conversion Path

conversionPath returns the conversion path between two tokens in the network. Please note that this method is quite expensive in terms of gas and should generally be called off-chain. Moreover, the function returns the shortest path, not necessarily the one with the best rate.

function conversionPath(IERC20Token _sourceToken, IERC20Token _targetToken) public view
returns(address[])

Arguments

Name
Type
Description

_sourceToken

IERC20Token

source token address

_targetToken

IERC20Token

target token address

Returns

The conversion path between the two tokens. Format:

[source token, converter anchor, target token, converter anchor, target token...]

Conversion Rate

rateByPath returns the expected target amount of converting a given amount on a given path.

function rateByPath(IERC20Token[] _path, uint256 _amount) public view
returns(uint256)

Arguments

Name
Type
Description

_path

IERC20Token[]

conversion path (see conversion path format above)

_amount

uint256

amount of _path[0] tokens received from the sender

Returns

The expected target amount.

Conversion

convertByPath converts the token to any other token in the Sovryn swap network by following a predefined conversion path and transfers the result tokens to a target account. Affiliate account/fee can also be passed in to receive a conversion fee (on top of the liquidity provider fees). Please note that the network should already have been given allowance of the source token.

function convertByPath(IERC20Token[] _path, uint256 _amount, uint256 _minReturn, address _beneficiary, address _affiliateAccount, uint256 _affiliateFee) public payable protected greaterThanZero 
returns(uint256)

Arguments

Name
Type
Description

_path

IERC20Token[]

conversion path, see conversion path format above

_amount

uint256

amount to convert from, in the source token

_minReturn

uint256

if the conversion results in an amount smaller than the minimum return - it is cancelled, must be greater than zero

_beneficiary

address

account that will receive the conversion result or 0x0 to send the result to the sender account

_affiliateAccount

address

wallet address to receive the affiliate fee or 0x0 to disable affiliate fee

_affiliateFee

uint256

affiliate fee in PPM or 0 to disable affiliate fee *

Returns

The amount of tokens to receive from the conversion.

PreviousV2 ConvertersNextWrapper

Last updated 1 year ago