Skip to content

Add initial PriceOracle & PriceData interfaces & implementation in BandOracleAdapters#5

Merged
sisyphusSmiling merged 102 commits intomainfrom
gio/add-oracle
May 23, 2025
Merged

Add initial PriceOracle & PriceData interfaces & implementation in BandOracleAdapters#5
sisyphusSmiling merged 102 commits intomainfrom
gio/add-oracle

Conversation

@sisyphusSmiling
Copy link
Contributor

@sisyphusSmiling sisyphusSmiling commented May 14, 2025

Stacked on #1

Description

  • Adds a PriceOracle connector interface and supporting PriceData return type
  • Adapts BandOracle's price oracle contract for use as an initial PriceOracle implementation
    • BandOracle operates on symbols and unfortunately does not have a mechanism by which a caller can lookup a given Type's symbol or symbol's associated Type
      • One potential workaround here is to attempt to lookup the vault's symbol via FungibleToken.resolveContractView to retrieve they type's FTVaultDisplay.symbol.
      • Another solution is to change base and quote from Type to String and rely on callers to pass the proper arguments in. This would allow for these parameters to be Type identifiers, EVM addresses, or symbols and for implementations to handle parameters according to their adapted protocols.
      • For the sake of time and to get eyes on the PriceOracle interface, a lookup table was added to BandOracleAdapters, but either of the former options could be implemented before deployment.
  • Adds initial BandOracleAdapters test setup

@sisyphusSmiling sisyphusSmiling self-assigned this May 14, 2025
@sisyphusSmiling sisyphusSmiling added the enhancement New feature or request label May 14, 2025
@sisyphusSmiling sisyphusSmiling marked this pull request as ready for review May 14, 2025 21:42
@sisyphusSmiling sisyphusSmiling changed the title Add initial PriceOracle DFB interface Add initial PriceOracle & PriceData interfaces & implementation in BandOracleAdapters May 14, 2025
/// Returns the asset type serving as the price basis - e.g. USD in FLOW/USD
access(all) view fun unitOfAccount(): Type
/// Returns the latest price data for a given asset denominated in unitOfAccount()
access(all) fun price(ofToken: Type): UFix64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll want to return an optional and/or add a method that exposes whether or not a price is available. Without some designation that a price is available for a given token, callers have no way to detect a possible reversion before it happens.

Thinking something like

access(all) fun isPriceAvailable(forToken: Type): Bool

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning an optional and having the isPriceAvailable() is a good idea just to be clear

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately after looking at the BandOracle contract, it looks like there isn't a getter for determining if a price is available without actually paying for a request. Paying for a simple check doesn't make sense IMO. I suppose there are no guarantees that any oracle exposes this information. I'm thinking that perhaps we have price return an optional since the expectation when calling is that the a request is made and therefore paid if needed and nil returned if it's either not available or the price data doesn't meet certain conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in ad1ccea

/// An interface for a price oracle adapter. Implementations should adapt this interface to various price feed
/// oracles deployed on Flow
access(all) struct interface PriceOracle {
/// Returns the asset type serving as the price basis - e.g. USD in FLOW/USD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would we represent USD here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we would use a stablecoin. For example, a PriceOracle where unitOfAccount() == Type<@USDCFlow.Vault>() would denominate all prices in USDCFlow which for the most part can be considered equivalent to USD.
The big assumption of course is that the price for any stablecoin is exactly par for USD which isn't always the case. That said, there's not a type that can be used exactly as USD so all prices served by this PriceOracle would always be relative to some other token type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, though using USDCFlow is probably risky, since the Flow foundation basically gave up on it in favor of the other bridged USDC representations. Probably better to rely on those. We should talk to Zach or someone to get an idea of which on will be the most stable

/// Returns the asset type serving as the price basis - e.g. USD in FLOW/USD
access(all) view fun unitOfAccount(): Type
/// Returns the latest price data for a given asset denominated in unitOfAccount()
access(all) fun price(ofToken: Type): UFix64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning an optional and having the isPriceAvailable() is a good idea just to be clear

Base automatically changed from gio/prototype to main May 20, 2025 22:56
@sisyphusSmiling sisyphusSmiling changed the base branch from main to gio/evm-swap-adapter May 21, 2025 00:00
Base automatically changed from gio/evm-swap-adapter to main May 23, 2025 02:04
@sisyphusSmiling sisyphusSmiling merged commit 4a51090 into main May 23, 2025
3 checks passed
@sisyphusSmiling sisyphusSmiling deleted the gio/add-oracle branch May 23, 2025 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants