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

uniform price aggregator events #1805

Merged
Merged
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
10 changes: 6 additions & 4 deletions contracts/core/price-aggregator/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ pub trait EventsModule {
fn emit_new_round_event(
&self,
token_pair: &TokenPair<Self::Api>,
round_id: usize,
price_feed: &TimestampedPrice<Self::Api>,
) {
let epoch = self.blockchain().get_block_epoch();
self.new_round_event(
&token_pair.from.clone(),
&token_pair.to.clone(),
epoch,
round_id,
&NewRoundEvent {
price: price_feed.price.clone(),
timestamp: price_feed.timestamp,
Expand All @@ -40,7 +41,7 @@ pub trait EventsModule {
&self,
#[indexed] from: &ManagedBuffer,
#[indexed] to: &ManagedBuffer,
#[indexed] epoch: u64,
#[indexed] round: usize,
new_round_event: &NewRoundEvent<Self::Api>,
);

Expand All @@ -55,8 +56,9 @@ pub trait EventsModule {
#[event("add_submission")]
fn add_submission_event(
&self,
#[indexed] caller: &ManagedAddress,
#[indexed] price: &BigUint,
#[indexed] from: &ManagedBuffer,
#[indexed] to: &ManagedBuffer,
#[indexed] round: usize,
price: &BigUint,
);
}
16 changes: 6 additions & 10 deletions contracts/core/price-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ pub trait PriceAggregator:
submissions.insert(caller.clone(), price.clone());
last_sub_time_mapper.set(current_timestamp);

self.create_new_round(token_pair.clone(), submissions, decimals);
let wrapped_rounds = self.rounds().get(&token_pair);
let mut round_id = 0;
let wrapped_rounds = self.rounds().get(&token_pair);
if wrapped_rounds.is_some() {
round_id = wrapped_rounds.unwrap().len();
round_id = wrapped_rounds.unwrap().len() + 1;
}
self.add_submission_event(&caller, &price, round_id);
self.create_new_round(token_pair.clone(), round_id, submissions, decimals);
self.add_submission_event(&token_pair.from.clone(), &token_pair.to.clone(), round_id, &price);
}

self.oracle_status()
Expand Down Expand Up @@ -254,6 +254,7 @@ pub trait PriceAggregator:
fn create_new_round(
&self,
token_pair: TokenPair<Self::Api>,
round_id: usize,
mut submissions: MapMapper<ManagedAddress, BigUint>,
decimals: u8,
) {
Expand Down Expand Up @@ -287,13 +288,8 @@ pub trait PriceAggregator:
.or_default()
.get()
.push(&price_feed);
self.emit_new_round_event(&token_pair, &price_feed);
self.emit_new_round_event(&token_pair, round_id, &price_feed);
} else {
let wrapped_rounds = self.rounds().get(&token_pair);
let mut round_id = 0;
if wrapped_rounds.is_some() {
round_id = wrapped_rounds.unwrap().len();
}
self.discard_round_event(&token_pair.from.clone(), &token_pair.to.clone(), round_id);
}
}
Expand Down
Loading