Skip to content

Commit

Permalink
make Dorin proud
Browse files Browse the repository at this point in the history
  • Loading branch information
alyn509 committed Oct 9, 2024
1 parent 3426a85 commit 2250319
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
31 changes: 18 additions & 13 deletions contracts/core/price-aggregator/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,27 @@ multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use crate::price_aggregator_data::{TimestampedPrice, TokenPair};
pub type RoundId = usize;
pub type Round = usize;
pub type Block = u64;
pub type Epoch = u64;
pub type Timestamp = u64;

#[type_abi]
#[derive(TopEncode)]
pub struct NewRoundEvent<M: ManagedTypeApi> {
price: BigUint<M>,
timestamp: u64,
timestamp: Timestamp,
decimals: u8,
block: u64,
epoch: u64,
block: Block,
epoch: Epoch,
}

#[type_abi]
#[derive(TopEncode)]
pub struct DiscardSubmissionEvent {
submission_timestamp: u64,
first_submission_timestamp: u64,
submission_timestamp: Timestamp,
first_submission_timestamp: Timestamp,
has_caller_already_submitted: bool,
}

Expand All @@ -26,7 +31,7 @@ pub trait EventsModule {
fn emit_new_round_event(
&self,
token_pair: &TokenPair<Self::Api>,
round_id: usize,
round_id: RoundId,
price_feed: &TimestampedPrice<Self::Api>,
) {
let epoch = self.blockchain().get_block_epoch();
Expand All @@ -49,16 +54,16 @@ pub trait EventsModule {
&self,
#[indexed] from: &ManagedBuffer,
#[indexed] to: &ManagedBuffer,
#[indexed] round: usize,
#[indexed] round: Round,
new_round_event: &NewRoundEvent<Self::Api>,
);

fn emit_discard_submission_event(
&self,
token_pair: &TokenPair<Self::Api>,
round_id: usize,
submission_timestamp: u64,
first_submission_timestamp: u64,
round_id: RoundId,
submission_timestamp: Timestamp,
first_submission_timestamp: Timestamp,
has_caller_already_submitted: bool,
) {
self.discard_submission_event(
Expand All @@ -78,7 +83,7 @@ pub trait EventsModule {
&self,
#[indexed] from: &ManagedBuffer,
#[indexed] to: &ManagedBuffer,
#[indexed] round: usize,
#[indexed] round: Round,
discard_submission_event: &DiscardSubmissionEvent,
);

Expand All @@ -87,15 +92,15 @@ pub trait EventsModule {
&self,
#[indexed] from: &ManagedBuffer,
#[indexed] to: &ManagedBuffer,
#[indexed] round: usize,
#[indexed] round: Round,
);

#[event("add_submission")]
fn add_submission_event(
&self,
#[indexed] from: &ManagedBuffer,
#[indexed] to: &ManagedBuffer,
#[indexed] round: usize,
#[indexed] round: Round,
price: &BigUint,
);
}
13 changes: 8 additions & 5 deletions contracts/core/price-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod events;
pub mod median;
pub mod price_aggregator_data;

use events::{RoundId, Timestamp};
use multiversx_sc_modules::staking;
use price_aggregator_data::{OracleStatus, PriceFeed, TimestampedPrice, TokenPair};

Expand Down Expand Up @@ -123,7 +124,7 @@ pub trait PriceAggregator:
&self,
from: ManagedBuffer,
to: ManagedBuffer,
submission_timestamp: u64,
submission_timestamp: Timestamp,
price: BigUint,
decimals: u8,
) {
Expand Down Expand Up @@ -230,7 +231,9 @@ pub trait PriceAggregator:
#[endpoint(submitBatch)]
fn submit_batch(
&self,
submissions: MultiValueEncoded<MultiValue5<ManagedBuffer, ManagedBuffer, u64, BigUint, u8>>,
submissions: MultiValueEncoded<
MultiValue5<ManagedBuffer, ManagedBuffer, Timestamp, BigUint, u8>,
>,
) {
self.require_not_paused();
self.require_is_oracle();
Expand Down Expand Up @@ -267,7 +270,7 @@ pub trait PriceAggregator:
fn create_new_round(
&self,
token_pair: TokenPair<Self::Api>,
round_id: usize,
round_id: RoundId,
mut submissions: MapMapper<ManagedAddress, BigUint>,
decimals: u8,
) {
Expand Down Expand Up @@ -444,13 +447,13 @@ pub trait PriceAggregator:
fn first_submission_timestamp(
&self,
token_pair: &TokenPair<Self::Api>,
) -> SingleValueMapper<u64>;
) -> SingleValueMapper<Timestamp>;

#[storage_mapper("last_submission_timestamp")]
fn last_submission_timestamp(
&self,
token_pair: &TokenPair<Self::Api>,
) -> SingleValueMapper<u64>;
) -> SingleValueMapper<Timestamp>;

#[storage_mapper("submissions")]
fn submissions(
Expand Down

0 comments on commit 2250319

Please sign in to comment.