GM Price Oracle
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()
. The contract has no constructor.
getUnderlyingPrice
Retrieves the current price of the token provided. If the asset is USDC, then the function calls the internal function getPriceFromChainlink()
and relays the USDC price returned by that function call (see the section below for details). 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 function returns zero.
To see how getPrice()
interacts with GMX architecture to retrieve current asset prices, please head to the GMI Token Oracles section.
Parameters:
Name | Type | Description |
---|---|---|
| ERC20 | Retrieves the price for this asset |
Returns:
Name | Type | Description |
---|---|---|
| uint256 | The price of the GM token, determined by the GMX |
getPriceFromChainlink
Retrieves the current price of USDC. Chainlink's USDC price feed address is typecast to the AggregatorV3Interface
type. The function then calls latestRoundData()
on the price feed instance to retrieve the latest round's price. After a type conversion, the answer is fed back into getUnderlyingPrice()
where it is upscaled to 18 decimals to play nice with collateral asset decimals, and the final price is returned by the function.
Parameters:
Name | Type | Description |
---|---|---|
| address | The Chainlink Price Feed contract address of the token |
Returns:
Name | Type | Description |
---|---|---|
| uint256 | The Oracle-returned price (with 8 decimals) of the token. |
Last updated