GM Price Oracle
Last updated
Last updated
GM Lending/Looping asset prices are obtained via a combination of the USDC Chainlink Oracle and previously deployed GMI Price Oracle contracts. As such, this current Oracle version behaves more like a Price Router in practice, but for simplicity's and posterity's sakes, it is labeled as a Price Oracle here.
At deployment, the Oracle contract stores addresses (the GMX GM token addresses and the USDC token address) for use in getUnderlyingPrice()
.
Sets msg.sender
as the owner and _authorityContract
as the Authority (both hereafter referred to as Admin). It then stores the addresses for the arbSequencerUptimeFeed
and usdcUSD_ARBPriceFeed
.
_authorityContract
Authority
The Authority contract for the Oracle
Updates/stores the Chainlink Arbitrum Sequencer Uptime Feed and the USDC Price Feed, along with its heartbeat. Only the Admin can call this function. The Sequencer Uptime Feed address is typecast to the AggregatorV3Interface
type. Upon success, the call emits an OracleFeedsUpdated
event with all three arguments as parameters.
_sequencerUptimeFeed
address
The address for the Chainlink Arbitrum Sequencer Uptime Feed
usdcUSD_ARBPriceFeed
address
The address of the Chainlink USDC Price Feed for Arbitrum Mainnet
usdcFeedHeartbeat
uint256
Time interval for Chainlink Price Feeds
Retrieves the current price of asset
. If the asset is USDC, then the function calls the internal function and relays the USDC price returned by that function call (see the section below for details). Since the Chainlink USDC Price Feed returns 8 decimals, the answer is scaled up by 1e10
to 18 decimals. If the asset is a valid GM token (gmBTC, gmETH, or gmSOL), then the respective GMI price oracle contract is stored in the oracle
variable. getPrice()
is then called on the oracle instance, and the final price is returned. If the asset is not a valid GM token, then the call reverts.
Parameters:
asset
ERC20
Retrieves the price for this asset
x
uint256
If a GM token, the is determined by the GMX reader
contract. If USDC, the price is returned by the Chainlink Arbitrum Mainnet USDC Price Feed. The price will have 18 decimals.
Retrieves the current price of Chainlink's Arbitrum Mainnet USDC Price Feed. The function first calls latestRoundData()
on the Sequencer Uptime Feed instance to retrieve the latest uptimeAnswer
and startedAt
. If uptimeAnswer
does not equal 0, the Arbitrum Sequencer is down, and the function call reverts. If uptimeAnswer
equals 0, then the Arb Sequencer is up. If the sequencer has just gone down, but was started back up, calls made within the GRACE_PERIOD
of 1 hour will revert. Once the sequencer has been up for longer than an hour, calls will function normally.
The function then calls latestRoundData()
on the price feed instance to retrieve the latest answer
and updatedAt
time. If updatedAt
is less than block.timestamp - usdcFeedHeartbeat
, the returned price is considered "stale," and the function will revert.
If the Arbitrum Sequencer is up and the Price Feed price is not stale, the price is returned by the function.
asset
ERC20
The token to retrieve the price for
answer
uint256
The Oracle-returned price of the token. (USDC price uses 8 decimals.)
To see how getPrice()
interacts with GMX architecture to retrieve current asset prices, please head to the section.