From a2e351eee8471c54a2bafe108391bca992eef140 Mon Sep 17 00:00:00 2001 From: Usn Zorro <> Date: Sun, 1 May 2022 20:07:28 +0300 Subject: [PATCH] 1.0.6: Bugfix of USN reserve value + execution flag --- Cargo.toml | 2 +- src/treasury/balance_treasury.rs | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d025f3..c1a95af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] edition = "2018" name = "usn" -version = "1.0.5" +version = "1.0.6" [lib] crate-type = ["cdylib"] diff --git a/src/treasury/balance_treasury.rs b/src/treasury/balance_treasury.rs index 4e94977..e725df1 100644 --- a/src/treasury/balance_treasury.rs +++ b/src/treasury/balance_treasury.rs @@ -62,7 +62,12 @@ impl std::fmt::Display for TreasuryDecision { #[near_bindgen] impl Contract { #[payable] - pub fn balance_treasury(&mut self, pool_id: u64, limits: Option<[u64; 2]>) -> Promise { + pub fn balance_treasury( + &mut self, + pool_id: u64, + limits: Option<[u64; 2]>, + execute: Option, + ) -> Promise { self.assert_owner_or_guardian(); // Buy case: 2 yoctoNEAR, sell case: 3 yoctoNEAR. @@ -113,6 +118,7 @@ impl Contract { .then(ext_self::handle_start_treasury_balancing( pool.id, decision_limit, + execute.unwrap_or(false), env::current_account_id(), env::attached_deposit(), GAS_SURPLUS * 6 @@ -141,6 +147,7 @@ trait SelfHandler { &mut self, pool_id: u64, decision_limit: Option, + execute: bool, #[callback] predicted_amounts: Vec, #[callback] info: StablePoolInfo, ) -> PromiseOrValue<()>; @@ -173,6 +180,7 @@ trait SelfHandler { &mut self, pool_id: u64, decision_limit: Option, + execute: bool, predicted_amounts: Vec, info: StablePoolInfo, ) -> PromiseOrValue<()>; @@ -229,6 +237,7 @@ impl SelfHandler for Contract { &mut self, pool_id: u64, decision_limit: Option, + execute: bool, #[callback] predicted_amounts: Vec, #[callback] info: StablePoolInfo, ) -> PromiseOrValue<()> { @@ -261,7 +270,7 @@ impl SelfHandler for Contract { // Convert everything into floats. let near = near as f64 / ONE_NEAR as f64; - let usn = usn as f64 / 10f64.powi(USDT_DECIMALS as i32); + let usn = usn as f64 / 10f64.powi(USN_DECIMALS as i32); let last_exch_rate = *exchange_rates.last().unwrap(); let usdt = usdt as f64 / 10f64.powi(USDT_DECIMALS as i32); let limit = decision_limit.map(|x| x as f64); @@ -271,10 +280,15 @@ impl SelfHandler for Contract { env::log_str(format!("{}", decision).as_str()); - match decision { - TreasuryDecision::DoNothing => PromiseOrValue::Value(()), - TreasuryDecision::Buy(f_amount) => buy(pool.id, f_amount, last_exch_rate).into(), - TreasuryDecision::Sell(f_amount) => sell(pool.id, f_amount, last_exch_rate).into(), + if execute { + match decision { + TreasuryDecision::DoNothing => PromiseOrValue::Value(()), + TreasuryDecision::Buy(f_amount) => buy(pool.id, f_amount, last_exch_rate).into(), + TreasuryDecision::Sell(f_amount) => sell(pool.id, f_amount, last_exch_rate).into(), + } + } else { + env::log_str("Execution bypassed"); + PromiseOrValue::Value(()) } }