Gloop
WebsiteTwitterDiscord
  • gLoop Litepaper v2
    • Introduction
    • The Two Tokens
    • Roadmap
  • PRODUCTS
    • GM Index
      • Providing/Removing Liquidity
      • Fees and Reflection
      • Deposit/Withdrawal Examples
    • GM Lend/Borrow
      • Lending USDC
      • Depositing Collateral Assets
      • Withdrawing Assets
      • Borrowing USDC
      • Repaying Debt
      • gLooping GM Assets
      • Position Management
        • Withdrawing Assets
        • Health Factor and Liquidations
      • Lending/Borrowing GMI (Coming Soon)
      • Frequently Asked Questions (FAQs)
    • GLOOP Staking (Coming Soon)
  • GM Points (COMING SOON)
  • Technical
    • Gloop Protocol Parameters
    • Gloop Parameters
    • Contracts
      • GM Lending and Looping
        • GM Lending Pool
        • GM Price Oracle
        • GM Vaults
        • GM Interest Rate Model
        • GM Incentives
      • GMI
        • GM Index
        • GMI USDC Zap
        • Token Banks
        • Token Oracles
        • Fees
  • FREQUENTLY ASKED QUESTIONS (FAQs)
    • GM Index (GMI)
    • GM Lending/Looping
    • GLOOP Staking (Coming Soon)
  • GLoop Ecosystem
    • Tokenomics
  • Security and Risk
    • Risks
    • Audits
  • Social
    • Socials
Powered by GitBook
On this page
  • constructor
  • updateChainlinkFeeds
  • getUnderlyingPrice
  • _getPriceFromChainlink
  1. Technical
  2. Contracts
  3. GM Lending and Looping

GM Price Oracle

PreviousGM Lending PoolNextGM Vaults

Last updated 24 days ago

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().

constructor

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.

Parameters:

Name
Type
Description

_authorityContract

Authority

The Authority contract for the Oracle

updateChainlinkFeeds

function updateChainlinkFeeds(address _sequencerUptimeFeed, address _usdcPriceFeed, uint256 _usdcFeedHeartbeat) external requiresAuth

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.

Parameters:

Name
Type
Description

_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

getUnderlyingPrice

function getUnderlyingPrice(ERC20 asset) public view returns (uint256)

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:

Name
Type
Description

asset

ERC20

Retrieves the price for this asset

Returns:

Name
Type
Description

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.

_getPriceFromChainlink

function _getPriceFromChainlink(address feedId) internal view returns (uint256)

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.

Parameters:

Name
Type
Description

asset

ERC20

The token to retrieve the price for

Returns:

Name
Type
Description

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.

_getPriceFromChainlink()
GMI Token Oracles