diff --git a/Cargo.lock b/Cargo.lock index d850e06..9198b17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2348,7 +2348,7 @@ dependencies = [ [[package]] name = "ref-exchange" -version = "1.9.9" +version = "1.9.10" dependencies = [ "hex", "mock-boost-farming", diff --git a/ref-exchange/Cargo.toml b/ref-exchange/Cargo.toml index db69216..4b36e3c 100644 --- a/ref-exchange/Cargo.toml +++ b/ref-exchange/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ref-exchange" -version = "1.9.9" +version = "1.9.10" authors = ["Illia Polosukhin "] edition = "2018" publish = false diff --git a/ref-exchange/release_notes.md b/ref-exchange/release_notes.md index 0397184..e04a85b 100644 --- a/ref-exchange/release_notes.md +++ b/ref-exchange/release_notes.md @@ -1,5 +1,12 @@ # Release Notes +### Version 1.9.10 +``` +H2sfzjphuQSTzrQByyPXoAnQnkYFejWCNsT9uwq51XnS +``` +1. amendments according to audition recommendations. +2. add skip_degen_price_sync param. + ### Version 1.9.9 ``` 2VqDt4y5CYDi1FCKu5LLVCTXNzh3kEvXpjfSe1XbDJcG diff --git a/ref-exchange/src/lib.rs b/ref-exchange/src/lib.rs index 6158b68..a9c62d2 100644 --- a/ref-exchange/src/lib.rs +++ b/ref-exchange/src/lib.rs @@ -188,6 +188,7 @@ impl Contract { amp_factor: u64, ) -> u64 { assert!(self.is_owner_or_guardians(), "{}", ERR100_NOT_ALLOWED); + assert!(tokens.len() == decimals.len(), "The number of tokens is inconsistent with the number of decimals."); check_token_duplicates(&tokens); self.internal_add_pool(Pool::StableSwapPool(StableSwapPool::new( self.pools.len() as u32, @@ -208,6 +209,7 @@ impl Contract { amp_factor: u64, ) -> u64 { assert!(self.is_owner_or_guardians(), "{}", ERR100_NOT_ALLOWED); + assert!(tokens.len() == decimals.len(), "The number of tokens is inconsistent with the number of decimals."); check_token_duplicates(&tokens); self.internal_add_pool(Pool::RatedSwapPool(RatedSwapPool::new( self.pools.len() as u32, @@ -227,6 +229,7 @@ impl Contract { amp_factor: u64, ) -> u64 { assert!(self.is_owner_or_guardians(), "{}", ERR100_NOT_ALLOWED); + assert!(tokens.len() == decimals.len(), "The number of tokens is inconsistent with the number of decimals."); check_token_duplicates(&tokens); self.internal_add_pool(Pool::DegenSwapPool(DegenSwapPool::new( self.pools.len() as u32, @@ -243,6 +246,7 @@ impl Contract { use_tokens: HashMap, actions: Vec, referral_id: Option, + skip_degen_price_sync: Option, ) -> HashMap { self.assert_contract_running(); assert_ne!(actions.len(), 0, "{}", ERR72_AT_LEAST_ONE_SWAP); @@ -276,6 +280,7 @@ impl Contract { &referral_info, &actions, ActionResult::None, + skip_degen_price_sync.unwrap_or(false) ); let mut result = HashMap::new(); for (token, amount) in virtual_account.tokens.to_vec() { @@ -300,6 +305,7 @@ impl Contract { &mut self, actions: Vec, referral_id: Option, + skip_degen_price_sync: Option, ) -> ActionResult { self.assert_contract_running(); assert_ne!(actions.len(), 0, "{}", ERR72_AT_LEAST_ONE_SWAP); @@ -325,7 +331,7 @@ impl Contract { .map(|fee| (referral_id.unwrap().into(), fee)); let result = - self.internal_execute_actions(&mut account, &referral_info, &actions, ActionResult::None); + self.internal_execute_actions(&mut account, &referral_info, &actions, ActionResult::None, skip_degen_price_sync.unwrap_or(false)); self.internal_save_account(&sender_id, account); result } @@ -334,7 +340,7 @@ impl Contract { /// If referrer provided, pays referral_fee to it. /// If no attached deposit, outgoing tokens used in swaps must be whitelisted. #[payable] - pub fn swap(&mut self, actions: Vec, referral_id: Option) -> U128 { + pub fn swap(&mut self, actions: Vec, referral_id: Option, skip_degen_price_sync: Option) -> U128 { U128( self.execute_actions( actions @@ -342,6 +348,7 @@ impl Contract { .map(|swap_action| Action::Swap(swap_action)) .collect(), referral_id, + skip_degen_price_sync ) .to_amount(), ) @@ -351,7 +358,7 @@ impl Contract { /// If referrer provided, pays referral_fee to it. /// If no attached deposit, outgoing tokens used in swaps must be whitelisted. #[payable] - pub fn swap_by_output(&mut self, actions: Vec, referral_id: Option) -> U128 { + pub fn swap_by_output(&mut self, actions: Vec, referral_id: Option, skip_degen_price_sync: Option) -> U128 { U128( self.execute_actions( actions @@ -359,6 +366,7 @@ impl Contract { .map(|swap_by_output_action| Action::SwapByOutput(swap_by_output_action)) .collect(), referral_id, + skip_degen_price_sync, ) .to_amount(), ) @@ -704,6 +712,7 @@ impl Contract { referral_info: &Option<(AccountId, u32)>, actions: &[Action], prev_result: ActionResult, + skip_degen_price_sync: bool, ) -> ActionResult { assert_all_same_action_type(actions); // fronzen token feature @@ -737,8 +746,10 @@ impl Contract { self.finalize_prev_swap_chain(account, prev_action, &result); } } - let degen_token_ids = self.get_degen_tokens_in_actions(actions).into_iter().collect::>(); - internal_batch_update_degen_token_price(degen_token_ids); + if !skip_degen_price_sync { + let degen_token_ids = self.get_degen_tokens_in_actions(actions).into_iter().collect::>(); + internal_batch_update_degen_token_price(degen_token_ids); + } result } @@ -921,7 +932,7 @@ impl Contract { &swap_action.token_in, amount_in, &swap_action.token_out, - 0, + swap_action.min_amount_out.0, referral_info, ); token_cache.add(&swap_action.token_out, amount_out); @@ -994,7 +1005,7 @@ impl Contract { exchange_id: env::current_account_id(), referral_info: referral_info.clone(), }, - false + true ); pool_cache.insert(pool_id, pool); amount_in @@ -1104,6 +1115,7 @@ mod tests { min_amount_out: U128(1), }], None, + None, ) .0 } @@ -1359,6 +1371,7 @@ mod tests { min_amount_out: U128(0), }], None, + None, ); } @@ -1472,7 +1485,7 @@ mod tests { testing_env!(context .predecessor_account_id(acc.clone()) .build()); - contract.execute_actions(actions, None); + contract.execute_actions(actions, None, None); } #[test] @@ -1532,6 +1545,7 @@ mod tests { min_amount_out: U128(1_000_000), }], None, + None, ); } @@ -1551,7 +1565,7 @@ mod tests { testing_env!(context.attached_deposit(to_yocto("1")).build()); contract.storage_deposit(None, None); testing_env!(context.attached_deposit(1).build()); - contract.swap(vec![], None); + contract.swap(vec![], None, None); } /// Check that can not swap non whitelisted tokens when attaching 0 deposit (access key). @@ -1617,6 +1631,7 @@ mod tests { }, ], None, + None, ); // Roundtrip returns almost everything except 0.25% fee. assert_eq!(contract.get_deposit(acc, accounts(1)).0, 1_000_000 - 6); diff --git a/ref-exchange/src/token_receiver.rs b/ref-exchange/src/token_receiver.rs index 0b1f457..a334f1f 100644 --- a/ref-exchange/src/token_receiver.rs +++ b/ref-exchange/src/token_receiver.rs @@ -30,12 +30,14 @@ enum TokenReceiverMessage { /// to send token_out back to predecessor with this msg. client_echo: Option, skip_unwrap_near: Option, - swap_out_recipient: Option + swap_out_recipient: Option, + skip_degen_price_sync: Option, }, HotZap { referral_id: Option, hot_zap_actions: Vec, - add_liquidity_infos: Vec + add_liquidity_infos: Vec, + skip_degen_price_sync: Option, }, } @@ -48,6 +50,7 @@ impl Contract { amount_in: Balance, referral_id: Option, actions: &[Action], + skip_degen_price_sync: bool, ) -> Vec<(AccountId, Balance)> { // let @ be the virtual account @@ -66,6 +69,7 @@ impl Contract { Action::Swap(_) => ActionResult::Amount(U128(amount_in)), Action::SwapByOutput(_) => ActionResult::None, }, + skip_degen_price_sync ); let mut result = vec![]; @@ -110,6 +114,7 @@ impl FungibleTokenReceiver for Contract { client_echo, skip_unwrap_near, swap_out_recipient, + skip_degen_price_sync, } => { assert!(!(swap_out_recipient.is_some() && client_echo.is_some()), "client_echo and swap_out_recipient cannot have value at the same time"); assert_ne!(actions.len(), 0, "{}", ERR72_AT_LEAST_ONE_SWAP); @@ -122,6 +127,7 @@ impl FungibleTokenReceiver for Contract { amount.0, referral_id, &actions, + skip_degen_price_sync.unwrap_or(false), ); if client_echo.is_some() && sender_id.to_string() == self.burrowland_id { assert!(out_amounts.len() == 1, "Invalid actions, only one out token is allowed"); @@ -139,7 +145,8 @@ impl FungibleTokenReceiver for Contract { TokenReceiverMessage::HotZap { referral_id, hot_zap_actions, - add_liquidity_infos + add_liquidity_infos, + skip_degen_price_sync, } => { assert!(hot_zap_actions.len() > 0 && add_liquidity_infos.len() > 0); let sender_id: AccountId = sender_id.into(); @@ -160,6 +167,7 @@ impl FungibleTokenReceiver for Contract { amount.0, referral_id, &hot_zap_actions, + skip_degen_price_sync.unwrap_or(false) ); let mut token_cache = TokenCache::new(); diff --git a/ref-exchange/tests/fuzzy/pool_swap.rs b/ref-exchange/tests/fuzzy/pool_swap.rs index 4916680..ec2842a 100644 --- a/ref-exchange/tests/fuzzy/pool_swap.rs +++ b/ref-exchange/tests/fuzzy/pool_swap.rs @@ -27,6 +27,7 @@ pub fn swap_action(pool :&ContractAccount, operator: &Operator, token_ token_out: token_out, min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -225,6 +226,7 @@ pub fn do_stable_pool_swap(token_contracts: &Vec>, rn token_out: token_out.clone(), min_amount_out: U128(1) }], + None, None ), deposit = 1 diff --git a/ref-exchange/tests/test_admin_fee.rs b/ref-exchange/tests/test_admin_fee.rs index e9d225d..3daaa8d 100644 --- a/ref-exchange/tests/test_admin_fee.rs +++ b/ref-exchange/tests/test_admin_fee.rs @@ -62,6 +62,7 @@ fn modify_admin_fee() { token_out: eth(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -110,6 +111,7 @@ fn modify_admin_fee() { token_out: eth(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -221,7 +223,8 @@ fn referral_fee() { token_out: eth(), min_amount_out: U128(1) }], - Some(referral1.valid_account_id()) + Some(referral1.valid_account_id()), + None ), deposit = 1 ); diff --git a/ref-exchange/tests/test_degen_pool.rs b/ref-exchange/tests/test_degen_pool.rs index 9188652..f9d1408 100644 --- a/ref-exchange/tests/test_degen_pool.rs +++ b/ref-exchange/tests/test_degen_pool.rs @@ -157,6 +157,7 @@ fn sim_degen() { token_out: eth(), min_amount_out: U128(1) }], + None, None ), gas = 300000000000000 @@ -318,6 +319,7 @@ fn sim_degen1() { token_out: eth(), min_amount_out: U128(1) }], + None, None ), gas = 300000000000000 diff --git a/ref-exchange/tests/test_errors.rs b/ref-exchange/tests/test_errors.rs index 4ef356b..74c2c43 100644 --- a/ref-exchange/tests/test_errors.rs +++ b/ref-exchange/tests/test_errors.rs @@ -150,6 +150,7 @@ fn sim_stable_e63 () { token_out: usdt(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -424,6 +425,7 @@ fn sim_stable_e68 () { token_out: usdt(), min_amount_out: U128(2 * ONE_USDT) }], + None, None ), deposit = 1 @@ -489,6 +491,7 @@ fn sim_stable_e69 () { token_out: dai(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -503,6 +506,7 @@ fn sim_stable_e69 () { token_out: dai(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -546,6 +550,7 @@ fn sim_stable_e71 () { token_out: dai(), min_amount_out: U128(1) }], + None, None ), deposit = 1 diff --git a/ref-exchange/tests/test_frozenlist.rs b/ref-exchange/tests/test_frozenlist.rs index 59f7274..f618b97 100644 --- a/ref-exchange/tests/test_frozenlist.rs +++ b/ref-exchange/tests/test_frozenlist.rs @@ -164,6 +164,7 @@ fn frozenlist_scenario_02() { token_out: eth(), min_amount_out: U128(1) })], + None, None ), deposit = 1 @@ -183,6 +184,7 @@ fn frozenlist_scenario_02() { token_out: eth(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -232,6 +234,7 @@ fn frozenlist_scenario_02() { token_out: dai(), min_amount_out: U128(1) }], + None, None ), deposit = 1 diff --git a/ref-exchange/tests/test_guardians.rs b/ref-exchange/tests/test_guardians.rs index 619f6c6..720d888 100644 --- a/ref-exchange/tests/test_guardians.rs +++ b/ref-exchange/tests/test_guardians.rs @@ -213,6 +213,7 @@ fn guardians_scenario_01() { token_out: eth(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -323,6 +324,7 @@ fn guardians_scenario_02() { token_out: eth(), min_amount_out: U128(1) }], + None, None ), deposit = 1 diff --git a/ref-exchange/tests/test_migrate.rs b/ref-exchange/tests/test_migrate.rs index b6158d9..f532698 100644 --- a/ref-exchange/tests/test_migrate.rs +++ b/ref-exchange/tests/test_migrate.rs @@ -51,7 +51,7 @@ fn test_upgrade() { .assert_success(); let metadata = get_metadata(&pool); // println!("{:#?}", metadata); - assert_eq!(metadata.version, "1.9.9".to_string()); + assert_eq!(metadata.version, "1.9.10".to_string()); assert_eq!(metadata.admin_fee_bps, 5); assert_eq!(metadata.boost_farm_id, "boost_farm".to_string()); assert_eq!(metadata.burrowland_id, "burrowland".to_string()); diff --git a/ref-exchange/tests/test_rated_pool.rs b/ref-exchange/tests/test_rated_pool.rs index 9b0be0c..70bfea3 100644 --- a/ref-exchange/tests/test_rated_pool.rs +++ b/ref-exchange/tests/test_rated_pool.rs @@ -357,6 +357,7 @@ fn sim_rated_swap_two_no_rated() { token_out: stnear(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -463,6 +464,7 @@ fn sim_rated_swap_rate_one_with_fee() { token_out: stnear(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -570,6 +572,7 @@ fn sim_rated_swap_rate_one_no_fee() { token_out: stnear(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -654,6 +657,7 @@ fn sim_rated_swap_three_no_rated() { token_out: stnear(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -671,6 +675,7 @@ fn sim_rated_swap_three_no_rated() { token_out: linear(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -792,6 +797,7 @@ fn sim_rated_swap() { token_out: linear(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -819,6 +825,7 @@ fn sim_rated_swap() { token_out: linear(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -1017,6 +1024,7 @@ fn sim_rated_swap_out_zero() { token_out: stnear(), min_amount_out: U128(0) }], + None, None ), deposit = 1 @@ -1034,6 +1042,7 @@ fn sim_rated_swap_out_zero() { token_out: stnear(), min_amount_out: U128(0) }], + None, None ), deposit = 1 @@ -1524,6 +1533,7 @@ fn sim_rated_swap_two_no_rated_with_nearx() { token_out: nearx(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -1630,6 +1640,7 @@ fn sim_rated_swap_rate_one_with_fee_with_nearx() { token_out: nearx(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -1736,6 +1747,7 @@ fn sim_rated_swap_rate_one_no_fee_with_nearx() { token_out: nearx(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -1987,6 +1999,7 @@ fn sim_sfrax_rated_swap_rate_one_price_oracle() { token_out: sfrax(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -2236,6 +2249,7 @@ fn sim_sfrax_rated_swap_rate_one_pyth() { token_out: sfrax(), min_amount_out: U128(1) }], + None, None ), deposit = 1 diff --git a/ref-exchange/tests/test_stable_pool.rs b/ref-exchange/tests/test_stable_pool.rs index b1832c1..df6140d 100644 --- a/ref-exchange/tests/test_stable_pool.rs +++ b/ref-exchange/tests/test_stable_pool.rs @@ -76,6 +76,7 @@ fn sim_stable_swap() { token_out: usdc(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -93,6 +94,7 @@ fn sim_stable_swap() { token_out: usdt(), min_amount_out: U128(1) }], + None, None ), deposit = 1 diff --git a/ref-exchange/tests/test_storage.rs b/ref-exchange/tests/test_storage.rs index 15d38f6..1d5dbb9 100644 --- a/ref-exchange/tests/test_storage.rs +++ b/ref-exchange/tests/test_storage.rs @@ -201,6 +201,7 @@ fn storage_scenario_02() { token_out: usdc(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -234,6 +235,7 @@ fn storage_scenario_02() { token_out: usdc(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -263,6 +265,7 @@ fn storage_scenario_02() { token_out: usdc(), min_amount_out: U128(1) }], + None, None ), deposit = 1 diff --git a/ref-exchange/tests/test_swap.rs b/ref-exchange/tests/test_swap.rs index c4b8fb5..b9af2d9 100644 --- a/ref-exchange/tests/test_swap.rs +++ b/ref-exchange/tests/test_swap.rs @@ -240,6 +240,7 @@ fn test_swap() { token_out: eth(), min_amount_out: U128(1) }], + None, None ), deposit = 1 @@ -906,6 +907,7 @@ fn test_execute_actions_in_va() { token_out: eth(), min_amount_out: U128(1) })], + None, None ), gas = 300000000000000 diff --git a/releases/ref_exchange_release.wasm b/releases/ref_exchange_release.wasm index bb2b387..63ce22c 100644 Binary files a/releases/ref_exchange_release.wasm and b/releases/ref_exchange_release.wasm differ diff --git a/releases/ref_exchange_release_v198.wasm b/releases/ref_exchange_release_v198.wasm new file mode 100644 index 0000000..27c0dd6 Binary files /dev/null and b/releases/ref_exchange_release_v198.wasm differ diff --git a/releases/ref_exchange_release_v199.wasm b/releases/ref_exchange_release_v199.wasm new file mode 100644 index 0000000..bb2b387 Binary files /dev/null and b/releases/ref_exchange_release_v199.wasm differ