Instant AI
  • INSTRUCTION
    • What is Instant AI
    • Tokenomics
    • Governance Process Overview
    • Become a Strategist
  • Smart Contracts
    • Protocol (V2) Contract Architecture
      • Smart Contract Architecture Walk-Through
    • Roles & Permissions
    • External Protocol Integration
      • Building Adaptors
        • BaseAdaptor
        • Protocol-Specific Functionality
        • Adaptor Configuration
        • Security Considerations
        • Debt Adaptors
        • Adaptor Uses to Keep in Mind
      • Building Pricing Extensions
    • Smart Contracts & Governance
    • Smart Contract Addresses
    • Advanced Smart Contracts
      • Registry Details
        • Registry.sol API
      • PriceRouter Details
        • Oracle Usage and Asset Pricing
        • PriceRouter.sol API
      • Cellars (aka ERC 4626 Vaults)
      • Adaptors
        • BaseAdaptor.sol API
      • Fees And Reserves
      • Portfolio (V1.5) Contract Architecture
  • Strategists
    • Overview
    • Protobuf
    • Requests
    • Adaptors
  • PROTOCOL
    • How does the protocol work?
    • Validators
    • Gravity Bridge
    • Steward
    • Auction module and participation
Powered by GitBook
On this page
  1. Smart Contracts
  2. Advanced Smart Contracts

PriceRouter Details

A detailed breakdown of the PriceRouter.sol contract.

PreviousRegistry.sol APINextOracle Usage and Asset Pricing

Last updated 6 months ago

Cellars rely on efficient and reliable pricing of any assets and positions held by the strategist. Pricing is used not only to determine Cellar performance and earned fees for the protocol and strategist, but it is also a critical part of the Cellar security model: pricing is used to make sure that strategist rebalances do not change the Cellar's TVL outside a defined envelope, preventing both mistakes and malicious operations by strategists.

Instant AI Cellars mainly use for pricing. The provides a pricing frontend to all other components of the Instant AI Cellars protocol. Each position that a Cellar takes must have a supported pricing mechanism: the Registry during a trustPosition call by checking PriceRouter#isSupported. Given the universal nature of the Price Router (used by all Cellars), the Price Router is owned by governance.

The principal governance workflow for the Price Router is the calling of addAsset , in order to set up pricing for new adaptors and positions. Each Adaptor specifies an underlying asset (see ), and before any adaptor is trusted by the registry, pricing for the underlying asset must be registered by calling addAsset. When adding an asset, different token types follow different pricing logic defined by _settings.derivative. For instance, for LP tokens, pricing is set up such that each token is broken down into its component ERC20 parts, and the prices of each token are fetched separately and summed to create a total pricing for the LP token.

Current PriceRouterV2 contract accepts settings.derivative equal to 1, 2, or 3. The first two options correspond to a ChainlinkPriceFeed and TWAP, respectively. The third option points to a contract following the Extension contract structure where custom pricing methods can be created. See section for more information.

PriceRouter Schematic

In addition to providing logical instructions on how to price the asset, the addAsset call requires the caller to provide an _expectedAnswer, which will be checked against the price calculated on-chain. Assets whose reported on-chain pricing does not match the expected answer will fail when being added. This may mean that the pricing logic is incorrect and needs to be changed, the settings parameters are incorrect, or the expected answer was calculated incorrectly.

Once an asset is added via addAsset, any of the view functions that represent pricing operations can be called:

  • getPriceInUSD

  • getValue

  • getValuesDelta

  • getValues

  • getExchangeRate

  • getExchangeRates

Gas Savings, Automation, and the SharePriceOracle.sol

CellarV2.5 architecture uses Chainlink automation with an `ERC4626SharePriceOracle` smart contract that stores prices from performUpkeep performed for a respective Cellar. The respective Cellar will use the ERC4626SharePriceOracle for pricing by default. It carries out comparisons between the latest price and the TWAP.

For V2.5 Cellars using share price oracles, if the oracle is deemed notSafeToUse, the TXs will REVERT. This is to avoid the share price having massive movements because the real share price has diverged from the oracle value (because the oracle has not been running, and thus is not safe to use).

ERC4626 Share Price Oracle Schematic

See the next page for a current API for PriceRouter.sol.

Chainlink Data Feeds
PriceRouter contract
validates this
BaseAdaptor#assetOf
"Building Pricing Extensions"