Skip to content

Latest commit

 

History

History
357 lines (317 loc) · 12 KB

PriceFeedsLocal.md

File metadata and controls

357 lines (317 loc) · 12 KB

Price Feeds Local contract.

  • (PriceFeedsLocal.sol)

View Source: contracts/feeds/testnet/PriceFeedsLocal.sol

↗ Extends: PriceFeeds

PriceFeedsLocal contract

This contract code comes from bZx. bZx is a protocol for tokenized margin trading and lending https://bzx.network similar to the dYdX protocol.

  • This contract contains the logic of setting and getting rates between two tokens.

Contract Members

Constants & Variables

mapping(address => mapping(address => uint256)) public rates;

Functions


constructor

Deploy local price feed contract. *

function (address _wrbtcTokenAddress, address _protocolTokenAddress) public nonpayable PriceFeeds 

Arguments

Name Type Description
_wrbtcTokenAddress address The address of the wrBTC instance.
_protocolTokenAddress address The address of the protocol token instance.
Source Code
constructor(address _wrbtcTokenAddress, address _protocolTokenAddress)
        public
        PriceFeeds(_wrbtcTokenAddress, _protocolTokenAddress, _wrbtcTokenAddress)
    {}

_queryRate

undefined

Calculate the price ratio between two tokens. *

function _queryRate(address sourceToken, address destToken) internal view
returns(rate uint256, precision uint256)

Arguments

Name Type Description
sourceToken address The address of the source tokens.
destToken address The address of the destiny tokens. *

Returns

rate The price ratio source/dest.

Source Code
function _queryRate(address sourceToken, address destToken)
        internal
        view
        returns (uint256 rate, uint256 precision)
    {
        require(!globalPricingPaused, "pricing is paused");

        if (sourceToken == destToken) {
            rate = 10**18;
            precision = 10**18;
        } else {
            if (sourceToken == protocolTokenAddress) {
                /// Hack for testnet; only returns price in rBTC.
                rate = protocolTokenEthPrice;
            } else if (destToken == protocolTokenAddress) {
                /// Hack for testnet; only returns price in rBTC.
                rate = SafeMath.div(10**36, protocolTokenEthPrice);
            } else {
                if (rates[sourceToken][destToken] != 0) {
                    rate = rates[sourceToken][destToken];
                } else {
                    uint256 sourceToEther =
                        rates[sourceToken][address(wrbtcToken)] != 0
                            ? rates[sourceToken][address(wrbtcToken)]
                            : 10**18;
                    uint256 etherToDest =
                        rates[address(wrbtcToken)][destToken] != 0
                            ? rates[address(wrbtcToken)][destToken]
                            : 10**18;

                    rate = sourceToEther.mul(etherToDest).div(10**18);
                }
            }
            precision = _getDecimalPrecision(sourceToken, destToken);
        }
    }

setRates

Owner set price ratio between two tokens. *

function setRates(address sourceToken, address destToken, uint256 rate) public nonpayable onlyOwner 

Arguments

Name Type Description
sourceToken address The address of the source tokens.
destToken address The address of the destiny tokens.
rate uint256 The price ratio source/dest.
Source Code
function setRates(
        address sourceToken,
        address destToken,
        uint256 rate
    ) public onlyOwner {
        if (sourceToken != destToken) {
            rates[sourceToken][destToken] = rate;
            rates[destToken][sourceToken] = SafeMath.div(10**36, rate);
        }
    }

Contracts