Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Osmosis price oracle #155

Merged
merged 18 commits into from
Nov 16, 2023
Merged

Osmosis price oracle #155

merged 18 commits into from
Nov 16, 2023

Conversation

uint
Copy link
Contributor

@uint uint commented Oct 26, 2023

Maybe closes #99

  • check for outdated price data in consumer (store timestamp)
  • review how/when subscriptions are saved/removed in provider (IBC handshake vs explicit local endpoint?)
  • for twap, verify how sdk.Dec gotten from arithmetic_twap_to_now is stringified
  • tests

@uint uint requested a review from maurolacy October 26, 2023 16:24
@uint uint force-pushed the 99-osmosis-price-oracle branch 2 times, most recently from 2585e06 to 305ee37 Compare October 26, 2023 16:27
Copy link
Collaborator

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

Initial review of the price provider. Will take a look at the consumer next.

contracts/consumer/remote-price-feed/Cargo.toml Outdated Show resolved Hide resolved
contracts/consumer/remote-price-feed/README.md Outdated Show resolved Hide resolved
contracts/osmosis-price-provider/Cargo.toml Outdated Show resolved Hide resolved
serde = { workspace = true }
sylvia = { workspace = true }
thiserror = { workspace = true }
osmosis-std = "0.20.1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏼

Comment on lines 163 to 186
#[cw_serde]
pub enum PriceFeedProviderPacket {
Update { twap: Decimal },
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good start. Some ideas / suggestions:

  • Listing the token pair the price is for, for robustness.
  • Adding a timestamp.
  • Adding a source / origin. It can be just a description. Good for logging / tracking.

contracts/osmosis-price-provider/src/state.rs Outdated Show resolved Hide resolved
contracts/osmosis-price-provider/src/contract.rs Outdated Show resolved Hide resolved
contracts/osmosis-price-provider/src/contract.rs Outdated Show resolved Hide resolved
contracts/osmosis-price-provider/src/contract.rs Outdated Show resolved Hide resolved
@uint
Copy link
Contributor Author

uint commented Nov 1, 2023

Initial review of the price provider. Will take a look at the consumer next.

Hey @maurolacy! I appreciate the review, but there's no need to go so in-depth when this is still a draft, pending a cleanup. I feel like the energy is better spent taking a high level view and verifying if this is what we want. I'll address the comments on Monday. Till then!

@maurolacy
Copy link
Collaborator

Thanks for the pointer. Put some comments there as well.

@uint uint force-pushed the 99-osmosis-price-oracle branch 2 times, most recently from 18e9c34 to e21e090 Compare November 8, 2023 17:57
@codecov-commenter
Copy link

codecov-commenter commented Nov 8, 2023

Codecov Report

Attention: 321 lines in your changes are missing coverage. Please review.

Comparison is base (c20eecc) 88.40% compared to head (1dfb124) 87.18%.
Report is 16 commits behind head on main.

Files Patch % Lines
contracts/consumer/remote-price-feed/src/ibc.rs 0.00% 105 Missing ⚠️
contracts/osmosis-price-provider/src/ibc.rs 0.00% 92 Missing ⚠️
...ntracts/consumer/remote-price-feed/src/contract.rs 0.00% 60 Missing ⚠️
contracts/osmosis-price-provider/src/contract.rs 0.00% 30 Missing ⚠️
contracts/consumer/remote-price-feed/src/msg.rs 0.00% 14 Missing ⚠️
...racts/consumer/remote-price-feed/src/bin/schema.rs 0.00% 7 Missing ⚠️
...tracts/consumer/remote-price-feed/src/scheduler.rs 92.06% 0 Missing and 5 partials ⚠️
contracts/consumer/remote-price-feed/src/state.rs 0.00% 2 Missing ⚠️
packages/apis/src/ibc/packet.rs 0.00% 2 Missing ⚠️
contracts/consumer/remote-price-feed/src/error.rs 0.00% 1 Missing ⚠️
... and 3 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
- Coverage   88.40%   87.18%   -1.22%     
==========================================
  Files          69       80      +11     
  Lines       13151    14264    +1113     
  Branches    13151    14264    +1113     
==========================================
+ Hits        11626    12436     +810     
- Misses        992     1310     +318     
+ Partials      533      518      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@uint
Copy link
Contributor Author

uint commented Nov 8, 2023

Alright, I won't stall more. I'll try to add some tests in a separate PR for what I can, although there's very little non-IBC logic here.

@uint uint requested a review from maurolacy November 8, 2023 21:53
@uint uint marked this pull request as ready for review November 8, 2023 21:53
@uint uint force-pushed the 99-osmosis-price-oracle branch from c45ac2c to bac07f7 Compare November 13, 2023 12:55
Copy link
Collaborator

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

Pretty good. Looking forward to some tests, and we can merge.

packages/bindings/src/sudo.rs Outdated Show resolved Hide resolved
contracts/consumer/remote-price-feed/README.md Outdated Show resolved Hide resolved
contracts/osmosis-price-provider/src/error.rs Show resolved Hide resolved
Comment on lines +60 to +64
Decimal::from_str(
&querier
.arithmetic_twap_to_now(pool_id, base.into(), quote.into(), None)?
.arithmetic_twap,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good. Let's confirm this with the Osmosis team at some point, and adjust if needed.

Comment on lines 56 to 57
self.last_epoch
.save(ctx.deps.storage, &Timestamp::from_seconds(0))?;
Copy link
Collaborator

@maurolacy maurolacy Nov 14, 2023

Choose a reason for hiding this comment

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

Does this mean 'never'? You can as well save the current block time here.

I think this is better, as it would schedule a price update at the first en block handler call after instantiation, right?

Copy link
Contributor Author

@uint uint Nov 14, 2023

Choose a reason for hiding this comment

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

No, this is the time of the last update. 0 stands for year 1970 and is pretty much guaranteed to mean "out of date", so that an update is scheduled after instantiation. If we change it to "now", the next update will be at now + epoch_in_secs, so it might introduce an unnecessary lag if anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH if instead of using "end block" we can configure an interval in the native Cosmos module, this whole "epoch length" dance becomes unnecessary here.

Copy link
Collaborator

@maurolacy maurolacy Nov 15, 2023

Choose a reason for hiding this comment

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

Yes, but it doesn't hurt either, and allows for different contracts to have different update periods while using the same SDK.

It's also slightly more robust.

Comment on lines 24 to 25
pub epoch_in_secs: Item<'static, u64>,
pub price_info_ttl_in_secs: Item<'static, u64>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense. Setting a TTL that is slightly larger than the epoch will help with handling delays in the price update process.

Perhaps all this can be derived from a single parameter. Including the IBC timeout as well. But, let's leave that for another iteration.

contracts/consumer/remote-price-feed/src/contract.rs Outdated Show resolved Hide resolved
contracts/consumer/remote-price-feed/src/contract.rs Outdated Show resolved Hide resolved
@uint uint force-pushed the 99-osmosis-price-oracle branch from f2367a2 to 3f5759f Compare November 15, 2023 16:22
@uint uint merged commit 10c4a02 into main Nov 16, 2023
4 checks passed
@uint uint deleted the 99-osmosis-price-oracle branch November 16, 2023 15:43
@uint uint restored the 99-osmosis-price-oracle branch November 16, 2023 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Price oracle contract
3 participants