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

feat(sequencer): implement oracle module actions #1878

Open
wants to merge 9 commits into
base: feat/oracle
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading