Skip to content

Commit

Permalink
feat(sequencer): implement oracle module actions (#1878)
Browse files Browse the repository at this point in the history
## Summary
implement oracle module actions `AddCurrencyPair` and
`RemoveCurrencyPair`

see
https://github.com/skip-mev/connect/blob/main/proto/connect/oracle/v2/tx.proto
and
https://github.com/skip-mev/connect/blob/9ea31680774e2f71e683c0a4989df5bf2d5f2302/x/oracle/keeper/msg_server.go#L28
for relevant connect code

## Background

these are required for the oracle authorities to be able to add/remove
currency pairs from state; these are the pairs whose prices will be
included in VEs.

## Changes
- implement oracle module actions `AddCurrencyPair` and
`RemoveCurrencyPair`
- make `CurrencyPairState.QuotePrice` optional, to reflect that this may
not be set upon currency pair initialization (as no oracle price has
been received for it)
- remove `get/put_num_removed_currency_pairs` from the oracle state_ext
as it's not needed for our logic due to the fact that we execute txs in
the proposal phase, so by the time vote extensions are issued for a
block, the state has already been updated and currency pairs that are
removed in that block have already been removed.

## Testing
unit tests

## Breaking Changelist
- adds new actions to the sequencer
- sequencer genesis is also updated (new fees)

## Related Issues

part of # #1446
  • Loading branch information
noot authored Jan 8, 2025
2 parents 37e21b0 + 179dc9c commit 0a03d83
Show file tree
Hide file tree
Showing 41 changed files with 1,615 additions and 244 deletions.
36 changes: 12 additions & 24 deletions crates/astria-core/src/connect/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub mod v2 {

#[derive(Debug, Clone, PartialEq)]
pub struct CurrencyPairState {
pub price: QuotePrice,
pub price: Option<QuotePrice>,
pub nonce: CurrencyPairNonce,
pub id: CurrencyPairId,
}
Expand All @@ -121,14 +121,11 @@ pub mod v2 {
/// - if the `price` field is missing
/// - if the `price` field is invalid
pub fn try_from_raw(raw: raw::CurrencyPairState) -> Result<Self, CurrencyPairStateError> {
let Some(price) = raw
let price = raw
.price
.map(QuotePrice::try_from_raw)
.transpose()
.map_err(CurrencyPairStateError::quote_price_parse_error)?
else {
return Err(CurrencyPairStateError::missing_price());
};
.map_err(CurrencyPairStateError::quote_price_parse_error)?;
let nonce = CurrencyPairNonce::new(raw.nonce);
let id = CurrencyPairId::new(raw.id);
Ok(Self {
Expand All @@ -141,7 +138,7 @@ pub mod v2 {
#[must_use]
pub fn into_raw(self) -> raw::CurrencyPairState {
raw::CurrencyPairState {
price: Some(self.price.into_raw()),
price: self.price.map(QuotePrice::into_raw),
nonce: self.nonce.get(),
id: self.id.get(),
}
Expand All @@ -153,11 +150,6 @@ pub mod v2 {
pub struct CurrencyPairStateError(CurrencyPairStateErrorKind);

impl CurrencyPairStateError {
#[must_use]
fn missing_price() -> Self {
Self(CurrencyPairStateErrorKind::MissingPrice)
}

#[must_use]
fn quote_price_parse_error(err: QuotePriceError) -> Self {
Self(CurrencyPairStateErrorKind::QuotePriceParseError(err))
Expand All @@ -166,16 +158,14 @@ pub mod v2 {

#[derive(Debug, thiserror::Error)]
enum CurrencyPairStateErrorKind {
#[error("missing price")]
MissingPrice,
#[error("failed to parse quote price")]
QuotePriceParseError(#[source] QuotePriceError),
}

#[derive(Debug, Clone)]
pub struct CurrencyPairGenesis {
pub currency_pair: CurrencyPair,
pub currency_pair_price: QuotePrice,
pub currency_pair_price: Option<QuotePrice>,
pub id: CurrencyPairId,
pub nonce: CurrencyPairNonce,
}
Expand All @@ -201,7 +191,7 @@ pub mod v2 {
}

#[must_use]
pub fn currency_pair_price(&self) -> &QuotePrice {
pub fn currency_pair_price(&self) -> &Option<QuotePrice> {
&self.currency_pair_price
}

Expand Down Expand Up @@ -232,13 +222,11 @@ pub mod v2 {
.ok_or_else(|| CurrencyPairGenesisError::field_not_set("currency_pair"))?
.try_into()
.map_err(CurrencyPairGenesisError::currency_pair)?;
let currency_pair_price = {
let wire = raw.currency_pair_price.ok_or_else(|| {
CurrencyPairGenesisError::field_not_set("currency_pair_price")
})?;
QuotePrice::try_from_raw(wire)
.map_err(CurrencyPairGenesisError::currency_pair_price)?
};
let currency_pair_price = raw
.currency_pair_price
.map(QuotePrice::try_from_raw)
.transpose()
.map_err(CurrencyPairGenesisError::currency_pair_price)?;

let id = CurrencyPairId::new(raw.id);
let nonce = CurrencyPairNonce::new(raw.nonce);
Expand All @@ -254,7 +242,7 @@ pub mod v2 {
pub fn into_raw(self) -> raw::CurrencyPairGenesis {
raw::CurrencyPairGenesis {
currency_pair: Some(self.currency_pair.into_raw()),
currency_pair_price: Some(self.currency_pair_price.into_raw()),
currency_pair_price: self.currency_pair_price.map(QuotePrice::into_raw),
id: self.id.get(),
nonce: self.nonce.get(),
}
Expand Down
8 changes: 8 additions & 0 deletions crates/astria-core/src/connect/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ pub mod v2 {
quote: self.quote.0,
}
}

#[must_use]
pub fn to_raw(&self) -> raw::CurrencyPair {
raw::CurrencyPair {
base: self.base.0.clone(),
quote: self.quote.0.clone(),
}
}
}

impl TryFrom<raw::CurrencyPair> for CurrencyPair {
Expand Down
30 changes: 30 additions & 0 deletions crates/astria-core/src/generated/astria.protocol.fees.v1.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

216 changes: 216 additions & 0 deletions crates/astria-core/src/generated/astria.protocol.fees.v1.serde.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0a03d83

Please sign in to comment.