Skip to content

Commit

Permalink
fix rate update: change order of elements
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKuczma committed Jul 8, 2024
1 parent 29dbc27 commit cf57c2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions amm/contracts/stable_pool/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]
mod token_rate;
/// StableSwap implementation based on the CurveFi stableswap model.
///
/// Stabelswap implementation based on the CurveFi stableswap model.
///
/// This pool contract supports PSP22 tokens which value increases at some
/// on-chain discoverable rate in terms of some other token, e.g. AZERO x sAZERO.
/// The rate oracle contract must implement [`RateProvider`](trait@traits::RateProvider).
///
///
/// IMPORTANT:
/// This stableswap implementation is NOT meant for yield-bearing assets which adjusts
/// its total supply to try and maintain a stable price a.k.a. rebasing tokens.
Expand Down Expand Up @@ -295,7 +295,7 @@ pub mod stable_pool {
let current_time = self.env().block_timestamp();
let mut rate_changed = false;
for rate in self.pool.token_rates.iter_mut() {
rate_changed = rate_changed | rate.update_rate(current_time);
rate_changed = rate.update_rate(current_time) || rate_changed;
}
if rate_changed {
Self::env().emit_event(RatesUpdated {
Expand Down Expand Up @@ -530,10 +530,10 @@ pub mod stable_pool {
}

/// Handles PSP22 token transfer,
///
/// If `amount` is `Some(amount)`, transfer this amount of `token_id`
///
/// If `amount` is `Some(amount)`, transfer this amount of `token_id`
/// from the caller to this contract.
///
///
/// If `amount` of `None`, calculate the difference between
/// this contract balance and recorded reserve of `token_id`.
fn _transfer_in(
Expand Down Expand Up @@ -721,7 +721,7 @@ pub mod stable_pool {
let current_time = self.env().block_timestamp();
let mut rate_changed = false;
for rate in self.pool.token_rates.iter_mut() {
rate_changed = rate_changed | rate.update_rate_no_cache(current_time);
rate_changed = rate.update_rate_no_cache(current_time) || rate_changed;
}
if rate_changed {
Self::env().emit_event(RatesUpdated {
Expand Down
6 changes: 3 additions & 3 deletions amm/contracts/stable_pool/token_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl TokenRate {
}

/// Returns cached rate.
///
///
/// NOTE: To make sure the rate is up-to-date, the caller should call `update_rate` before calling this method.
pub fn get_rate(&self) -> u128 {
match self {
Expand All @@ -48,7 +48,7 @@ impl TokenRate {
}

/// Update rate.
///
///
/// Returns `true` if the rate was expired and value of the new rate is different than the previous.
pub fn update_rate(&mut self, current_time: u64) -> bool {
match self {
Expand All @@ -58,7 +58,7 @@ impl TokenRate {
}

/// Update rate without expiry check.
///
///
/// Returns `true` if value of the new rate is different than the previous.
pub fn update_rate_no_cache(&mut self, current_time: u64) -> bool {
match self {
Expand Down

0 comments on commit cf57c2a

Please sign in to comment.