Skip to content

Commit

Permalink
price aggregator changes from mx-sdk-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
alyn509 committed Oct 4, 2024
1 parent 9acd488 commit 0f04715
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
16 changes: 16 additions & 0 deletions contracts/price-aggregator/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ pub trait EventsModule {
#[indexed] epoch: u64,
new_round_event: &NewRoundEvent<Self::Api>,
);

#[event("discard_round")]
fn discard_round_event(
&self,
#[indexed] from: &ManagedBuffer,
#[indexed] to: &ManagedBuffer,
#[indexed] round: usize,
);

#[event("add_submission")]
fn add_submission_event(
&self,
#[indexed] caller: &ManagedAddress,
#[indexed] price: &BigUint,
#[indexed] round: usize,
);
}
18 changes: 15 additions & 3 deletions contracts/price-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,15 @@ pub trait PriceAggregator:
let accepted = !submissions.contains_key(&caller)
&& (is_first_submission || submission_timestamp >= first_submission_timestamp);
if accepted {
submissions.insert(caller, price);
submissions.insert(caller.clone(), price.clone());
last_sub_time_mapper.set(current_timestamp);

self.create_new_round(token_pair, submissions, decimals);
self.create_new_round(token_pair.clone(), submissions, decimals);
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.add_submission_event(&caller, &price, round_id);
}

self.oracle_status()
Expand Down Expand Up @@ -282,6 +287,13 @@ pub trait PriceAggregator:
.get()
.push(&price_feed);
self.emit_new_round_event(&token_pair, &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

0 comments on commit 0f04715

Please sign in to comment.