ExchangeRateModel.sol
↗ Extends: Exponential
Enums

OracleError

1
enum OracleError {
2
NO_ERROR,
3
UNAUTHORIZED,
4
FAILED_TO_SET_PRICE
5
}
Copied!

OracleFailureInfo

1
enum OracleFailureInfo {
2
ACCEPT_ANCHOR_ADMIN_PENDING_ANCHOR_ADMIN_CHECK,
3
SET_PAUSED_OWNER_CHECK,
4
SET_PENDING_ANCHOR_ADMIN_OWNER_CHECK,
5
SET_PENDING_ANCHOR_PERMISSION_CHECK,
6
SET_PRICE_CALCULATE_SWING,
7
SET_PRICE_CAP_TO_MAX,
8
SET_PRICE_MAX_SWING_CHECK,
9
SET_PRICE_NO_ANCHOR_PRICE_OR_INITIAL_PRICE_ZERO,
10
SET_PRICE_PERMISSION_CHECK,
11
SET_PRICE_ZERO_PRICE,
12
SET_PRICES_PARAM_VALIDATION,
13
SET_PRICE_IS_READER_ASSET
14
}
Copied!

Structs

ExchangeRateInfo

1
struct ExchangeRateInfo {
2
address exchangeRateModel,
3
uint256 exchangeRate,
4
uint256 maxSwingRate,
5
uint256 maxSwingDuration
6
}
Copied!

Anchor

1
struct Anchor {
2
uint256 period,
3
uint256 priceMantissa
4
}
Copied!

SetPriceLocalVars

1
struct SetPriceLocalVars {
2
struct Exponential.Exp price,
3
struct Exponential.Exp swing,
4
struct Exponential.Exp anchorPrice,
5
uint256 anchorPeriod,
6
uint256 currentPeriod,
7
bool priceCapped,
8
uint256 cappingAnchorPriceMantissa,
9
uint256 pendingAnchorMantissa
10
}
Copied!

Contract Members

Constants & Variables
1
bool public paused;
2
uint256 public constant numBlocksPerPeriod;
3
uint256 public constant maxSwingMantissa;
4
mapping(address => struct PriceOracle.ExchangeRateInfo) public exchangeRates;
5
mapping(address => struct Exponential.Exp) public _assetPrices;
6
address public anchorAdmin;
7
address public pendingAnchorAdmin;
8
address public poster;
9
struct Exponential.Exp public maxSwing;
10
mapping(address => struct PriceOracle.Anchor) public anchors;
11
mapping(address => uint256) public pendingAnchors;
Copied!
Events
1
event OracleFailure(address msgSender, address asset, uint256 error, uint256 info, uint256 detail);
2
event NewPendingAnchor(address anchorAdmin, address asset, uint256 oldScaledPrice, uint256 newScaledPrice);
3
event SetExchangeRate(address asset, address exchangeRateModel, uint256 exchangeRate, uint256 maxSwingRate, uint256 maxSwingDuration);
4
event SetMaxSwingRate(address asset, uint256 oldMaxSwingRate, uint256 newMaxSwingRate, uint256 maxSwingDuration);
5
event PricePosted(address asset, uint256 previousPriceMantissa, uint256 requestedPriceMantissa, uint256 newPriceMantissa);
6
event CappedPricePosted(address asset, uint256 requestedPriceMantissa, uint256 anchorPriceMantissa, uint256 cappedPriceMantissa);
7
event SetPaused(bool newState);
8
event NewPendingAnchorAdmin(address oldPendingAnchorAdmin, address newPendingAnchorAdmin);
9
event NewAnchorAdmin(address oldAnchorAdmin, address newAnchorAdmin);
10
event NewPoster(address oldPoster, address newPoster);
Copied!

Functions

  • scale()
  • getExchangeRate()
  • getMaxSwingRate(uint256 interval)
  • getFixedInterestRate(uint256 interval)
  • getFixedExchangeRate(uint256 interval)
  • ()
  • failOracle(address asset, enum PriceOracle.OracleError err, enum PriceOracle.OracleFailureInfo info)
  • failOracleWithDetails(address asset, enum PriceOracle.OracleError err, enum PriceOracle.OracleFailureInfo info, uint256 details)
  • _setPendingAnchor(address asset, uint256 newScaledPrice)
  • _setPaused(bool requestedState)
  • _setPendingAnchorAdmin(address newPendingAnchorAdmin)
  • _acceptAnchorAdmin()
  • _setPoster(address newPoster)
  • setExchangeRate(address asset, address exchangeRateModel, uint256 maxSwingDuration)
  • setMaxSwingRate(address asset, uint256 maxSwingDuration)
  • assetPrices(address asset)
  • getPrice(address asset)
  • setPrice(address asset, uint256 requestedPriceMantissa)
  • setPriceInternal(address asset, uint256 requestedPriceMantissa)
  • setPriceStorageInternal(address asset, uint256 priceMantissa)
  • calculateSwing(struct Exponential.Exp anchorPrice, struct Exponential.Exp price)
  • capToMax(struct Exponential.Exp anchorPrice, struct Exponential.Exp price)
  • setPrices(address[] assets, uint256[] requestedPriceMantissas)

scale

1
function scale() external view
2
returns(uint256)
Copied!
Arguments
Name
Type
Description

getExchangeRate

1
function getExchangeRate() external view
2
returns(uint256)
Copied!
Arguments
Name
Type
Description

getMaxSwingRate

1
function getMaxSwingRate(uint256 interval) external view
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
interval
uint256

getFixedInterestRate

1
function getFixedInterestRate(uint256 interval) external view
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
interval
uint256

getFixedExchangeRate

1
function getFixedExchangeRate(uint256 interval) public view
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
interval
uint256

Do not pay into PriceOracle
1
function () public payable
Copied!
Arguments
Name
Type
Description

failOracle

use this when reporting a known error from the price oracle or a non-upgradeable collaborator Using Oracle in name because we already inherit a fail function from ErrorReporter.sol via Exponential.sol
1
function failOracle(address asset, enum PriceOracle.OracleError err, enum PriceOracle.OracleFailureInfo info) internal nonpayable
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
asset
address
err
enum PriceOracle.OracleError
info
enum PriceOracle.OracleFailureInfo

failOracleWithDetails

Use this when reporting an error from the Alkemi Earn Verified. Give the Alkemi Earn Verified result as details
1
function failOracleWithDetails(address asset, enum PriceOracle.OracleError err, enum PriceOracle.OracleFailureInfo info, uint256 details) internal nonpayable
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
asset
address
err
enum PriceOracle.OracleError
info
enum PriceOracle.OracleFailureInfo
details
uint256

_setPendingAnchor

provides ability to override the anchor price for an asset
1
function _setPendingAnchor(address asset, uint256 newScaledPrice) public nonpayable
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure (see enum OracleError for details)
Arguments
Name
Type
Description
asset
address
Asset for which to override the anchor price
newScaledPrice
uint256
New anchor price

_setPaused

set paused to the specified state
1
function _setPaused(bool requestedState) public nonpayable
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure
Arguments
Name
Type
Description
requestedState
bool
value to assign to paused

_setPendingAnchorAdmin

Begins transfer of anchor admin rights. The newPendingAnchorAdmin must call _acceptAnchorAdmin to finalize the transfer.
1
function _setPendingAnchorAdmin(address newPendingAnchorAdmin) public nonpayable
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure
Arguments
Name
Type
Description
newPendingAnchorAdmin
address
New pending anchor admin.

_acceptAnchorAdmin

Accepts transfer of anchor admin rights. msg.sender must be pendingAnchorAdmin
1
function _acceptAnchorAdmin() public nonpayable
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure
Arguments
Name
Type
Description

_setPoster

Set new poster.
1
function _setPoster(address newPoster) public nonpayable
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure
Arguments
Name
Type
Description
newPoster
address
New poster.

setExchangeRate

set new exchange rate model
1
function setExchangeRate(address asset, address exchangeRateModel, uint256 maxSwingDuration) public nonpayable
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure (see enum OracleError for details)
Arguments
Name
Type
Description
asset
address
asset for which to set the exchangeRateModel
exchangeRateModel
address
exchangeRateModel address, if the exchangeRateModel is address(0), cancel the exchangeRates
maxSwingDuration
uint256
maxSwingDuration uint, Is a value greater than zero and less than a second of a week

setMaxSwingRate

set new exchange rate maxSwingRate
1
function setMaxSwingRate(address asset, uint256 maxSwingDuration) public nonpayable
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure (see enum OracleError for details)
Arguments
Name
Type
Description
asset
address
asset for which to set the exchange rate maxSwingRate
maxSwingDuration
uint256
Interval time

assetPrices

retrieves price of an asset
1
function assetPrices(address asset) public view
2
returns(uint256)
Copied!
Returns
uint mantissa of asset price (scaled by 1e18) or zero if unset or contract paused
Arguments
Name
Type
Description
asset
address
Asset for which to get the price

getPrice

retrieves price of an asset
1
function getPrice(address asset) public view
2
returns(uint256)
Copied!
Returns
uint mantissa of asset price (scaled by 1e18) or zero if unset or contract paused
Arguments
Name
Type
Description
asset
address
Asset for which to get the price

setPrice

entry point for updating prices
1
function setPrice(address asset, uint256 requestedPriceMantissa) public nonpayable
2
returns(uint256)
Copied!
Returns
uint 0=success, otherwise a failure (see enum OracleError for details)
Arguments
Name
Type
Description
asset
address
Asset for which to set the price
requestedPriceMantissa
uint256
requested new price, scaled by 10**18

setPriceInternal

1
function setPriceInternal(address asset, uint256 requestedPriceMantissa) internal nonpayable
2
returns(uint256)
Copied!
Arguments
Name
Type
Description
asset
address
requestedPriceMantissa
uint256

setPriceStorageInternal

1
function setPriceStorageInternal(address asset, uint256 priceMantissa) internal nonpayable
Copied!
Arguments
Name
Type
Description
asset
address
priceMantissa
uint256

calculateSwing

1
function calculateSwing(struct Exponential.Exp anchorPrice, struct Exponential.Exp price) internal pure
2
returns(enum ErrorReporter.Error, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
anchorPrice
struct Exponential.Exp
price
struct Exponential.Exp

capToMax

1
function capToMax(struct Exponential.Exp anchorPrice, struct Exponential.Exp price) internal view
2
returns(enum ErrorReporter.Error, bool, struct Exponential.Exp)
Copied!
Arguments
Name
Type
Description
anchorPrice
struct Exponential.Exp
price
struct Exponential.Exp

setPrices

entry point for updating multiple prices
1
function setPrices(address[] assets, uint256[] requestedPriceMantissas) public nonpayable
2
returns(uint256[])
Copied!
Returns
uint values in same order as inputs. For each: 0=success, otherwise a failure (see enum OracleError for details)
Arguments
Name
Type
Description
assets
address[]
a list of up to assets for which to set a price. required: 0 < assets.length == requestedPriceMantissas.length
requestedPriceMantissas
uint256[]
requested new prices for the assets, scaled by 10**18. required: 0 < assets.length == requestedPriceMantissas.length
Last modified 4mo ago