Pricing Functions

Naming Convention

The naming convention for the smart-contract functions is fairly straight forward. As an example, getEthToToken refers to the VET (eth) to token exchange rate, InputPrice refers to the price you get based for a certain amount of input. As our function is VET to token, we will be returned the price for x amount of VET inputted. Note that the price will change based on the volume of your trade.

Differentiating Between Markets

Each market manages a single token and its exchange rate to VET. As such, you can only get the price for a token from its own market. To lookup a token's market address, you will need to use the factory. Doing this is covered here.

Contract Functions (Simple Swaps)

getEthToTokenInputPrice(eth_sold: uint256(wei))

  • Returns the exchange rate for a market's TOKEN, based on the amount of VET a user is trading to the market.

getEthToTokenOutputPrice(tokens_bought: uint256)

  • Returns the exchange rate for a market's TOKEN, based on the amount of TOKEN a user is purchasing from the market.

getTokenToEthInputPrice(tokens_sold: uint256)

  • Returns the exchange rate for a market's VET, based on the amount of TOKEN a user is trading to the market.

getTokenToEthOutputPrice(eth_bought: uint256(wei))

  • Returns the exchange rate for a market's VET, based on the amount of VET a user is purchasing from the market.

Contract Functions (Token to Token Swaps)

For token to token swaps, there is no native pricing function. Instead, you can call the function to get the returned amount of tokens. If you want to convert this to a price, simply divide the returned amount by the inputted amount.

tokenToTokenSwapInput(tokens_sold: uint256, min_tokens_bought: uint256, min_eth_bought: uint256(wei), deadline: timestamp, token_addr: address)

  • tokens_sold: Amount of tokens you are selling, denominated in wei. Tokens sold is the traded token of the current market you are interfacing with (the native token).

  • min_tokens_bought: The minimum amount of foreign tokens you want returned. For pricing you can set this to 1 (wei).

  • min_eth_bought: The minimum amount of VET bought as the bridge currency. For pricing you can set this to 1 (wei).

  • deadline: A unix timestamp by when the trade must have been executed. For pricing just make sure you have set a time that is sufficiently far in the future.

  • token_addr: The address of the VIP-180 you are looking to buy. Note that this is the token address not the address of the token's market.

tokenToTokenSwapOutput(tokens_bought: uint256, max_tokens_sold: uint256, max_eth_sold: uint256(wei), deadline: timestamp, token_addr: address)

  • tokens_bought: The amount of tokens your are buying, denominated in wei. Tokens bought is the foreign token that is not native to the market you are currently interfacing with.

  • max_tokens_sold: The maximum amount of native tokens you want to sell in order to purchase the foreign tokens. You can set this to a sufficiently large number for pricing purposes.

  • max_eth_sold: The maximum amount of eth you want to trade for the foreign tokens. You can set this to a sufficiently high number for pricing purposes.

  • deadline: A unix timestamp by when the trade must have been executed. For pricing just make sure you have set a time that is sufficiently far in the future.

  • token_addr: The address of the VIP-180 you are looking to buy. Note that this is the token address not the address of the token's market.

Last updated