Add initial PriceOracle & PriceData interfaces & implementation in BandOracleAdapters#5
Add initial PriceOracle & PriceData interfaces & implementation in BandOracleAdapters#5sisyphusSmiling merged 102 commits intomainfrom
Conversation
cadence/contracts/interfaces/DFB.cdc
Outdated
| /// 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 |
There was a problem hiding this comment.
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): BoolThere was a problem hiding this comment.
I think returning an optional and having the isPriceAvailable() is a good idea just to be clear
There was a problem hiding this comment.
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.
| /// 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 |
There was a problem hiding this comment.
How would we represent USD here?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
cadence/contracts/interfaces/DFB.cdc
Outdated
| /// 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 |
There was a problem hiding this comment.
I think returning an optional and having the isPriceAvailable() is a good idea just to be clear
Stacked on #1
Description
PriceOracleconnector interface and supportingPriceDatareturn typePriceOracleimplementationType's symbol or symbol's associated TypeFungibleToken.resolveContractViewto retrieve they type'sFTVaultDisplay.symbol.baseandquotefromTypetoStringand 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.