Skip to content

Commit

Permalink
1.0.6: Bugfix of USN reserve value + execution flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Usn Zorro committed May 1, 2022
1 parent 1e7e597 commit a2e351e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2018"
name = "usn"
version = "1.0.5"
version = "1.0.6"

[lib]
crate-type = ["cdylib"]
Expand Down
26 changes: 20 additions & 6 deletions src/treasury/balance_treasury.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
) -> Promise {
self.assert_owner_or_guardian();

// Buy case: 2 yoctoNEAR, sell case: 3 yoctoNEAR.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -141,6 +147,7 @@ trait SelfHandler {
&mut self,
pool_id: u64,
decision_limit: Option<u64>,
execute: bool,
#[callback] predicted_amounts: Vec<U128>,
#[callback] info: StablePoolInfo,
) -> PromiseOrValue<()>;
Expand Down Expand Up @@ -173,6 +180,7 @@ trait SelfHandler {
&mut self,
pool_id: u64,
decision_limit: Option<u64>,
execute: bool,
predicted_amounts: Vec<U128>,
info: StablePoolInfo,
) -> PromiseOrValue<()>;
Expand Down Expand Up @@ -229,6 +237,7 @@ impl SelfHandler for Contract {
&mut self,
pool_id: u64,
decision_limit: Option<u64>,
execute: bool,
#[callback] predicted_amounts: Vec<U128>,
#[callback] info: StablePoolInfo,
) -> PromiseOrValue<()> {
Expand Down Expand Up @@ -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);
Expand All @@ -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(())
}
}

Expand Down

0 comments on commit a2e351e

Please sign in to comment.