- (PriceFeedsLocal.sol)
View Source: contracts/feeds/testnet/PriceFeedsLocal.sol
↗ Extends: PriceFeeds
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.
Constants & Variables
mapping(address => mapping(address => uint256)) public rates;
- constructor(address _wrbtcTokenAddress, address _protocolTokenAddress)
- _queryRate(address sourceToken, address destToken)
- setRates(address sourceToken, address destToken, uint256 rate)
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)
{}
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);
}
}
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);
}
}
- Address
- Administered
- AdminRole
- AdvancedToken
- AdvancedTokenStorage
- Affiliates
- AffiliatesEvents
- ApprovalReceiver
- BProPriceFeed
- CheckpointsShared
- Constants
- Context
- DevelopmentFund
- DummyContract
- EnumerableAddressSet
- EnumerableBytes32Set
- EnumerableBytes4Set
- ERC20
- ERC20Detailed
- ErrorDecoder
- Escrow
- EscrowReward
- FeedsLike
- FeesEvents
- FeeSharingCollector
- FeeSharingCollectorProxy
- FeeSharingCollectorStorage
- FeesHelper
- FourYearVesting
- FourYearVestingFactory
- FourYearVestingLogic
- FourYearVestingStorage
- GenericTokenSender
- GovernorAlpha
- GovernorVault
- IApproveAndCall
- IChai
- IContractRegistry
- IConverterAMM
- IERC1820Registry
- IERC20_
- IERC20
- IERC777
- IERC777Recipient
- IERC777Sender
- IFeeSharingCollector
- IFourYearVesting
- IFourYearVestingFactory
- IFunctionsList
- ILiquidityMining
- ILiquidityPoolV1Converter
- ILoanPool
- ILoanToken
- ILoanTokenLogicBeacon
- ILoanTokenLogicModules
- ILoanTokenLogicProxy
- ILoanTokenModules
- ILoanTokenWRBTC
- ILockedSOV
- IMoCState
- IModulesProxyRegistry
- Initializable
- InterestUser
- IPot
- IPriceFeeds
- IPriceFeedsExt
- IProtocol
- IRSKOracle
- ISovryn
- ISovrynSwapNetwork
- IStaking
- ISwapsImpl
- ITeamVesting
- ITimelock
- IV1PoolOracle
- IVesting
- IVestingFactory
- IVestingRegistry
- IWrbtc
- IWrbtcERC20
- LenderInterestStruct
- LiquidationHelper
- LiquidityMining
- LiquidityMiningConfigToken
- LiquidityMiningProxy
- LiquidityMiningStorage
- LoanClosingsEvents
- LoanClosingsLiquidation
- LoanClosingsRollover
- LoanClosingsShared
- LoanClosingsWith
- LoanClosingsWithoutInvariantCheck
- LoanInterestStruct
- LoanMaintenance
- LoanMaintenanceEvents
- LoanOpenings
- LoanOpeningsEvents
- LoanParamsStruct
- LoanSettings
- LoanSettingsEvents
- LoanStruct
- LoanToken
- LoanTokenBase
- LoanTokenLogicBeacon
- LoanTokenLogicLM
- LoanTokenLogicProxy
- LoanTokenLogicStandard
- LoanTokenLogicStorage
- LoanTokenLogicWrbtc
- LoanTokenSettingsLowerAdmin
- LockedSOV
- MarginTradeStructHelpers
- Medianizer
- ModuleCommonFunctionalities
- ModulesCommonEvents
- ModulesProxy
- ModulesProxyRegistry
- MultiSigKeyHolders
- MultiSigWallet
- Mutex
- Objects
- OrderStruct
- OrigingVestingCreator
- OriginInvestorsClaim
- Ownable
- Pausable
- PausableOz
- PreviousLoanToken
- PreviousLoanTokenSettingsLowerAdmin
- PriceFeedRSKOracle
- PriceFeeds
- PriceFeedsLocal
- PriceFeedsMoC
- PriceFeedV1PoolOracle
- ProtocolAffiliatesInterface
- ProtocolLike
- ProtocolSettings
- ProtocolSettingsEvents
- ProtocolSettingsLike
- ProtocolSwapExternalInterface
- ProtocolTokenUser
- Proxy
- ProxyOwnable
- ReentrancyGuard
- RewardHelper
- RSKAddrValidator
- SafeERC20
- SafeMath
- SafeMath96
- setGet
- SharedReentrancyGuard
- SignedSafeMath
- SOV
- sovrynProtocol
- StakingAdminModule
- StakingGovernanceModule
- StakingInterface
- StakingProxy
- StakingRewards
- StakingRewardsProxy
- StakingRewardsStorage
- StakingShared
- StakingStakeModule
- StakingStorageModule
- StakingStorageShared
- StakingVestingModule
- StakingWithdrawModule
- State
- SwapsEvents
- SwapsExternal
- SwapsImplLocal
- SwapsImplSovrynSwap
- SwapsUser
- TeamVesting
- Timelock
- TimelockHarness
- TimelockInterface
- TokenSender
- UpgradableProxy
- USDTPriceFeed
- Utils
- VaultController
- Vesting
- VestingCreator
- VestingFactory
- VestingLogic
- VestingRegistry
- VestingRegistry2
- VestingRegistry3
- VestingRegistryLogic
- VestingRegistryProxy
- VestingRegistryStorage
- VestingStorage
- WeightedStakingModule
- WRBTC