From 268c2324432db9ee6a74d2022f05e1a1de0abe43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9=20=28WSL=20Win11=20Pro=29?= Date: Thu, 18 Apr 2024 00:34:11 +0100 Subject: [PATCH 1/6] Update `.gitignore` with Sui Move migration `.patch` --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c09f1f4..e2bd78b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,7 @@ build/ *.bpl # cargo stuff -target/ \ No newline at end of file +target/ + +# Sui Move migration artifacts +*.patch \ No newline at end of file From df8c4358a562449775d0a5d28f47389956b4a4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9=20=28WSL=20Win11=20Pro=29?= Date: Thu, 18 Apr 2024 00:35:32 +0100 Subject: [PATCH 2/6] Migrate `ramm-sui` to Sui Move 2024 (beta) --- ramm-sui/Move.lock | 38 ----- ramm-sui/Move.toml | 1 + ramm-sui/sources/events.move | 38 ++--- ramm-sui/sources/interface2.move | 40 ++--- ramm-sui/sources/interface3.move | 54 +++---- ramm-sui/sources/math.move | 66 ++++---- ramm-sui/sources/oracles.move | 2 +- ramm-sui/sources/ramm.move | 132 ++++++++-------- .../tests/interface2_oracle_safety_tests.move | 24 +-- ramm-sui/tests/interface2_safety_tests.move | 112 +++++++------- ramm-sui/tests/interface2_tests.move | 20 +-- .../tests/interface3_oracle_safety_tests.move | 24 +-- ramm-sui/tests/interface3_safety_tests.move | 112 +++++++------- ramm-sui/tests/interface3_tests.move | 24 +-- .../tests/liquidity_provision_fees_tests.move | 10 +- ramm-sui/tests/math_tests.move | 28 ++-- ramm-sui/tests/ramm_tests.move | 74 ++++----- ramm-sui/tests/test_util.move | 142 +++++++++--------- ramm-sui/tests/volatility2_tests.move | 32 ++-- ramm-sui/tests/volatility3_tests.move | 40 ++--- 20 files changed, 488 insertions(+), 525 deletions(-) delete mode 100644 ramm-sui/Move.lock diff --git a/ramm-sui/Move.lock b/ramm-sui/Move.lock deleted file mode 100644 index 7743a57..0000000 --- a/ramm-sui/Move.lock +++ /dev/null @@ -1,38 +0,0 @@ -# @generated by Move, please check-in and do not edit manually. - -[move] -version = 0 -manifest_digest = "E78137C746596EC13830EFFA68C134750EAE0456EF877CBFE762ED8E55D2DD64" -deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" - -dependencies = [ - { name = "MoveStdlib" }, - { name = "Sui" }, - { name = "SwitchboardStdLib" }, -] - -[[move.package]] -name = "MoveStdlib" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } - -[[move.package]] -name = "Sui" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } - -dependencies = [ - { name = "MoveStdlib" }, -] - -[[move.package]] -name = "SwitchboardStdLib" -source = { git = "https://github.com/switchboard-xyz/sbv2-sui.git", rev = "main", subdir = "move/mainnet/switchboard_std/" } - -dependencies = [ - { name = "MoveStdlib" }, - { name = "Sui" }, -] - -[move.toolchain-version] -compiler-version = "1.21.1" -edition = "legacy" -flavor = "sui" diff --git a/ramm-sui/Move.toml b/ramm-sui/Move.toml index 59ac7f3..4098490 100644 --- a/ramm-sui/Move.toml +++ b/ramm-sui/Move.toml @@ -1,6 +1,7 @@ [package] name = "ramm_sui" version = "0.0.1" +edition = "2024.beta" # First version of package published in testnet with ID: #published-at = "0xd3283fa556731370cd2a7f389b3e35c630184118b5af416ce9e57edfce751496" # Upgraded to ID: diff --git a/ramm-sui/sources/events.move b/ramm-sui/sources/events.move index cf54add..6e2817c 100644 --- a/ramm-sui/sources/events.move +++ b/ramm-sui/sources/events.move @@ -5,9 +5,9 @@ module ramm_sui::events { use sui::object::ID; use sui::vec_map::VecMap; - friend ramm_sui::ramm; - friend ramm_sui::interface2; - friend ramm_sui::interface3; + /* friend ramm_sui::ramm; */ + /* friend ramm_sui::interface2; */ + /* friend ramm_sui::interface3; */ /// --------- /// IMPORTANT @@ -26,7 +26,7 @@ module ramm_sui::events { As such, they are defined here. */ - struct PoolStateEvent has copy, drop { + public struct PoolStateEvent has copy, drop { ramm_id: ID, sender: address, asset_types: vector, @@ -34,7 +34,7 @@ module ramm_sui::events { asset_lpt_issued: vector, } - public(friend) fun pool_state_event( + public(package) fun pool_state_event( ramm_id: ID, sender: address, asset_types: vector, @@ -53,16 +53,16 @@ module ramm_sui::events { } /// Phantom type to mark a `TradeEvent` as the result of `trade_amount_in` - struct TradeIn {} + public struct TradeIn {} /// Phantom type to mark a `TradeEvent` as the result of `trade_amount_out` - struct TradeOut {} + public struct TradeOut {} /// Datatype used to emit, to the Sui blockchain, information on a successful trade. /// /// A phantom type is used to mark whether it's the result of a call to `trade_amount_in` /// (selling an exact amount of an asset to the RAMM), or to `trade_amount_out` (buying /// an exact amount of an asset from the RAMM). - struct TradeEvent has copy, drop { + public struct TradeEvent has copy, drop { ramm_id: ID, trader: address, token_in: TypeName, @@ -74,7 +74,7 @@ module ramm_sui::events { /// Given all the information necessary to identify a given RAMM's trade event, /// emit it. - public(friend) fun trade_event( + public(package) fun trade_event( ramm_id: ID, trader: address, token_in: TypeName, @@ -96,7 +96,7 @@ module ramm_sui::events { ) } - struct PriceEstimationEvent has copy, drop { + public struct PriceEstimationEvent has copy, drop { ramm_id: ID, trader: address, token_in: TypeName, @@ -111,7 +111,7 @@ module ramm_sui::events { /// Note that no changes are made to the RAMM's state when estimating prices, /// and that the price is not guaranteed to be the same when the trade is /// executed. - public(friend) fun price_estimation_event( + public(package) fun price_estimation_event( ramm_id: ID, trader: address, token_in: TypeName, @@ -134,7 +134,7 @@ module ramm_sui::events { } /// Datatype used to emit, to the Sui blockchain, information on a successful liquidity deposit. - struct LiquidityDepositEvent has copy, drop { + public struct LiquidityDepositEvent has copy, drop { ramm_id: ID, trader: address, token_in: TypeName, @@ -144,7 +144,7 @@ module ramm_sui::events { /// Given all the information necessary to identify a given RAMM's liquidity deposit event, /// emit it. - public(friend) fun liquidity_deposit_event( + public(package) fun liquidity_deposit_event( ramm_id: ID, trader: address, token_in: TypeName, @@ -163,7 +163,7 @@ module ramm_sui::events { } /// Datatype describing a Sui event for a given RAMM's liquidity withdrawal. - struct LiquidityWithdrawalEvent has copy, drop { + public struct LiquidityWithdrawalEvent has copy, drop { ramm_id: ID, trader: address, token_out: TypeName, @@ -174,7 +174,7 @@ module ramm_sui::events { /// Given all the information necessary to identify a given RAMM's liquidity withdrawal event, /// emit it. - public(friend) fun liquidity_withdrawal_event( + public(package) fun liquidity_withdrawal_event( ramm_id: ID, trader: address, token_out: TypeName, @@ -200,14 +200,14 @@ module ramm_sui::events { /// * its keys are each of the RAMM asset's `TypeName`s /// * its values are the imbalance ratios for each of the RAMM's assets, represented with /// as `u64`s with `PRECISION_DECIMAL_PLACES` - struct ImbalanceRatioEvent has copy, drop { + public struct ImbalanceRatioEvent has copy, drop { ramm_id: ID, requester: address, imb_ratios: VecMap, } /// Given the required data, emit an event with a RAMM's imbalance ratios. - public(friend) fun imbalance_ratios_event( + public(package) fun imbalance_ratios_event( ramm_id: ID, requester: address, imb_ratios: VecMap, @@ -222,7 +222,7 @@ module ramm_sui::events { } /// Datatype describing a Sui event for a given RAMM's fee collection. - struct FeeCollectionEvent has copy, drop { + public struct FeeCollectionEvent has copy, drop { ramm_id: ID, admin: address, fee_collector: address, @@ -231,7 +231,7 @@ module ramm_sui::events { /// Given all the information necessary to identify a given RAMM's fee collection event, /// emit it. - public(friend) fun fee_collection_event( + public(package) fun fee_collection_event( ramm_id: ID, admin: address, fee_collector: address, diff --git a/ramm-sui/sources/interface2.move b/ramm-sui/sources/interface2.move index 1928d36..7369b90 100644 --- a/ramm-sui/sources/interface2.move +++ b/ramm-sui/sources/interface2.move @@ -80,9 +80,9 @@ module ramm_sui::interface2 { ramm::check_trade_amount_in(self, (coin::value(&amount_in) as u256)); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -162,7 +162,7 @@ module ramm_sui::interface2 { let amount_out_u64: u64 = (amount_out_u256 as u64); if (ramm::is_successful(&trade)) { if (amount_out_u64 >= min_ao) { - let amount_in: Balance = coin::into_balance(amount_in); + let mut amount_in: Balance = coin::into_balance(amount_in); let fee: u64 = (ramm::protocol_fee(&trade) as u64); let fee_bal: Balance = balance::split(&mut amount_in, fee); @@ -246,9 +246,9 @@ module ramm_sui::interface2 { ramm::check_trade_amount_out(self, (amount_out as u256)); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -321,8 +321,8 @@ module ramm_sui::interface2 { let max_ai_u64: u64 = coin::value(&max_ai); if (ramm::is_successful(&trade)) { if (trade_amount <= max_ai_u64) { - let max_ai: Balance = coin::into_balance(max_ai); - let amount_in: Balance = balance::split(&mut max_ai, trade_amount); + let mut max_ai: Balance = coin::into_balance(max_ai); + let mut amount_in: Balance = balance::split(&mut max_ai, trade_amount); let remainder = max_ai; let fee: u64 = (ramm::protocol_fee(&trade) as u64); @@ -404,9 +404,9 @@ module ramm_sui::interface2 { let oth = ramm::get_asset_index(self); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -522,9 +522,9 @@ module ramm_sui::interface2 { let o = ramm::get_asset_index(self); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -555,7 +555,7 @@ module ramm_sui::interface2 { self, snd, *vec_map::get(&new_prices, &snd), *vec_map::get(&new_price_timestamps, &snd) ); - let volatility_fees: VecMap = vec_map::empty(); + let mut volatility_fees: VecMap = vec_map::empty(); vec_map::insert(&mut volatility_fees, fst, fst_vol_fee); vec_map::insert(&mut volatility_fees, snd, snd_vol_fee); /* @@ -610,7 +610,7 @@ module ramm_sui::interface2 { }; let burn_amount: u64 = (*lpt_amount as u64); - let lp_token: Balance> = coin::into_balance(lp_token); + let mut lp_token: Balance> = coin::into_balance(lp_token); let burn_tokens: Balance> = balance::split(&mut lp_token, burn_amount); // Update RAMM's untyped count of LP tokens for outgoing asset ramm::decr_lptokens_issued(self, burn_amount); @@ -650,8 +650,8 @@ module ramm_sui::interface2 { // Build required data structures for liquidity withdrawal event emission. - let amounts_out_u64: VecMap = vec_map::empty(); - let fees_u64: VecMap = vec_map::empty(); + let mut amounts_out_u64: VecMap = vec_map::empty(); + let mut fees_u64: VecMap = vec_map::empty(); vec_map::insert(&mut amounts_out_u64, type_name::get(), (*vec_map::get(&amounts_out, &fst) as u64)); vec_map::insert(&mut fees_u64, type_name::get(), (*vec_map::get(&fees, &fst) as u64)); if (vec_map::contains(&amounts_out, &snd)) { @@ -696,7 +696,7 @@ module ramm_sui::interface2 { let value_fst: u64 = coin::value(&fst); let value_snd: u64 = coin::value(&snd); - let collected_fees: VecMap = vec_map::empty(); + let mut collected_fees: VecMap = vec_map::empty(); vec_map::insert(&mut collected_fees, type_name::get(), value_fst); vec_map::insert(&mut collected_fees, type_name::get(), value_snd); diff --git a/ramm-sui/sources/interface3.move b/ramm-sui/sources/interface3.move index a8f0479..2293ea6 100644 --- a/ramm-sui/sources/interface3.move +++ b/ramm-sui/sources/interface3.move @@ -82,9 +82,9 @@ module ramm_sui::interface3 { let oth = ramm::get_asset_index(self); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -185,7 +185,7 @@ module ramm_sui::interface3 { let amount_out_u64: u64 = (amount_out_u256 as u64); if (ramm::is_successful(&trade)) { if (amount_out_u64 >= min_ao) { - let amount_in: Balance = coin::into_balance(amount_in); + let mut amount_in: Balance = coin::into_balance(amount_in); let fee: u64 = (ramm::protocol_fee(&trade) as u64); let fee_bal: Balance = balance::split(&mut amount_in, fee); @@ -275,9 +275,9 @@ module ramm_sui::interface3 { let oth = ramm::get_asset_index(self); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -392,9 +392,9 @@ module ramm_sui::interface3 { ramm::check_trade_amount_out(self, (amount_out as u256)); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -494,8 +494,8 @@ module ramm_sui::interface3 { let max_ai_u64: u64 = coin::value(&max_ai); if (ramm::is_successful(&trade)) { if (trade_amount <= max_ai_u64) { - let max_ai: Balance = coin::into_balance(max_ai); - let amount_in: Balance = balance::split(&mut max_ai, trade_amount); + let mut max_ai: Balance = coin::into_balance(max_ai); + let mut amount_in: Balance = balance::split(&mut max_ai, trade_amount); let remainder = max_ai; let fee: u64 = (ramm::protocol_fee(&trade) as u64); @@ -579,9 +579,9 @@ module ramm_sui::interface3 { let anoth = ramm::get_asset_index(self); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -727,9 +727,9 @@ module ramm_sui::interface3 { let o = ramm::get_asset_index(self); let current_timestamp: u64 = clock::timestamp_ms(clock); - let new_prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut new_prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -772,7 +772,7 @@ module ramm_sui::interface3 { self, trd, *vec_map::get(&new_prices, &trd), *vec_map::get(&new_price_timestamps, &trd) ); - let volatility_fees: VecMap = vec_map::empty(); + let mut volatility_fees: VecMap = vec_map::empty(); vec_map::insert(&mut volatility_fees, fst, fst_vol_fee); vec_map::insert(&mut volatility_fees, snd, snd_vol_fee); vec_map::insert(&mut volatility_fees, trd, trd_vol_fee); @@ -834,7 +834,7 @@ module ramm_sui::interface3 { }; let burn_amount: u64 = (*lpt_amount as u64); - let lp_token: Balance> = coin::into_balance(lp_token); + let mut lp_token: Balance> = coin::into_balance(lp_token); let burn_tokens: Balance> = balance::split(&mut lp_token, burn_amount); // Update RAMM's untyped count of LP tokens for outgoing asset ramm::decr_lptokens_issued(self, burn_amount); @@ -882,8 +882,8 @@ module ramm_sui::interface3 { // Build required data structures for liquidity withdrawal event emission. - let amounts_out_u64: VecMap = vec_map::empty(); - let fees_u64: VecMap = vec_map::empty(); + let mut amounts_out_u64: VecMap = vec_map::empty(); + let mut fees_u64: VecMap = vec_map::empty(); vec_map::insert(&mut amounts_out_u64, type_name::get(), (*vec_map::get(&amounts_out, &fst) as u64)); vec_map::insert(&mut fees_u64, type_name::get(), (*vec_map::get(&fees, &fst) as u64)); if (vec_map::contains(&amounts_out, &snd)) { @@ -931,9 +931,9 @@ module ramm_sui::interface3 { let trd = ramm::get_asset_index(self); let current_timestamp: u64 = clock::timestamp_ms(clock); - let prices = vec_map::empty(); - let factors_for_prices = vec_map::empty(); - let new_price_timestamps = vec_map::empty(); + let mut prices = vec_map::empty(); + let mut factors_for_prices = vec_map::empty(); + let mut new_price_timestamps = vec_map::empty(); ramm::check_feed_and_get_price_data( self, current_timestamp, @@ -963,7 +963,7 @@ module ramm_sui::interface3 { ); let imb_ratios: VecMap = ramm::imbalance_ratios(self, &prices, &factors_for_prices); - let event_imb_ratios = vec_map::empty(); + let mut event_imb_ratios = vec_map::empty(); let fst_imb_ratio: u64 = (*vec_map::get(&imb_ratios, &fst) as u64); vec_map::insert(&mut event_imb_ratios, type_name::get(), fst_imb_ratio); @@ -1012,7 +1012,7 @@ module ramm_sui::interface3 { let value_snd: u64 = coin::value(&snd); let value_trd: u64 = coin::value(&trd); - let collected_fees: VecMap = vec_map::empty(); + let mut collected_fees: VecMap = vec_map::empty(); vec_map::insert(&mut collected_fees, type_name::get(), value_fst); vec_map::insert(&mut collected_fees, type_name::get(), value_snd); vec_map::insert(&mut collected_fees, type_name::get(), value_trd); diff --git a/ramm-sui/sources/math.move b/ramm-sui/sources/math.move index cf39688..3216f4c 100644 --- a/ramm-sui/sources/math.move +++ b/ramm-sui/sources/math.move @@ -2,8 +2,8 @@ module ramm_sui::math { //use std::debug; use sui::vec_map::{Self, VecMap}; - friend ramm_sui::oracles; - friend ramm_sui::ramm; + /* friend ramm_sui::oracles; */ + /* friend ramm_sui::ramm; */ const EMulOverflow: u64 = 0; const EDividendTooLarge: u64 = 1; @@ -17,12 +17,12 @@ module ramm_sui::math { /// Operators /// --------- - public(friend) fun abs_diff_u64(x: u64, y: u64): u64 { + public(package) fun abs_diff_u64(x: u64, y: u64): u64 { if (x >= y) { x - y } else { y - x } } /// Given a `u256` value, forecefully clamp it to the range `[0, max]`. - public(friend) fun clamp(val: u256, max: u256): u256 { + public(package) fun clamp(val: u256, max: u256): u256 { if (val >= max) { return max }; val } @@ -32,8 +32,8 @@ module ramm_sui::math { /// # Aborts /// /// If the calculation overflows. - public fun pow(base: u256, exp: u8): u256 { - let res = 1; + public fun pow(mut base: u256, mut exp: u8): u256 { + let mut res = 1; while (exp >= 1) { if (exp % 2 == 0) { base = base * base; @@ -79,7 +79,7 @@ module ramm_sui::math { /// # Aborts /// /// * If the dividend or the result overflow past `pow(10, max_prec)`. - public(friend) fun div(x: u256, y: u256, prec: u8, max_prec: u8): u256 { + public(package) fun div(x: u256, y: u256, prec: u8, max_prec: u8): u256 { let max = pow(10u256, max_prec); assert!(x <= max, EDividendTooLarge); let result = x * pow(10u256, prec) / y; @@ -96,13 +96,13 @@ module ramm_sui::math { /// * If the exponent exceeds `127` /// * If the base exceeds `10^max_prec` /// * If during intermediate operations, any value exceeds `10^max_prec` - public(friend) fun pow_n(x: u256, n: u256, one: u256, prec: u8, max_prec:u8): u256 { + public(package) fun pow_n(x: u256, mut n: u256, one: u256, prec: u8, max_prec:u8): u256 { let max = pow(10u256, max_prec); assert!(n <= 127, EPowNExponentTooLarge); assert!(x <= max, EPowNBaseTooLarge); - let result: u256 = one; - let a: u256 = x; + let mut result: u256 = one; + let mut a: u256 = x; while (n != 0) { if (n % 2 == 1) { @@ -125,20 +125,20 @@ module ramm_sui::math { /// /// * If it is not the case that `0.67 <= x <= 1.5`. /// * If the exponent is not in `[0, 1[` (with `prec` decimal places) - public(friend) fun pow_d(x: u256, a: u256, one: u256, prec: u8, max_prec: u8): u256 { + public(package) fun pow_d(x: u256, a: u256, one: u256, prec: u8, max_prec: u8): u256 { let pow = pow(10, prec - 2); assert!(67 * pow <= x && x <= 150 * pow, EPowDBaseOutOfBounds); assert!(a < one, EPowDExpTooLarge); - let result: u256 = one; - let n: u256 = 0; - let tn: u256 = one; - let sign: bool = true; + let mut result: u256 = one; + let mut n: u256 = 0; + let mut tn: u256 = one; + let mut sign: bool = true; let iters = 30; while (n < iters) { - let _factor1: u256 = 0; - let _factor2: u256 = 0; + let mut _factor1: u256 = 0; + let mut _factor2: u256 = 0; if (a >= n * one) { _factor1 = a - n * one; @@ -178,7 +178,7 @@ module ramm_sui::math { /// Both `a` and `x` have to be given with `prec` decimal places. /// /// The result is given in the same format. - public(friend) fun power(x: u256, a: u256, one: u256, prec: u8, max_prec: u8): u256 { + public(package) fun power(x: u256, a: u256, one: u256, prec: u8, max_prec: u8): u256 { let n = a / pow(10u256, prec); mul( pow_n(x, n, one, prec, max_prec), @@ -188,7 +188,7 @@ module ramm_sui::math { } /// Base function that adjusts the leverage parameter and the base fee. - public(friend) fun adjust(x: u256, prec: u8, max_prec: u8): u256 { + public(package) fun adjust(x: u256, prec: u8, max_prec: u8): u256 { mul3(x, x, x, prec, max_prec) } @@ -207,16 +207,16 @@ module ramm_sui::math { prec: u8, max_prec: u8, ): VecMap { - let _W = vec_map::empty(); - let _B: u256 = 0; - let i: u8 = 0; + let mut _W = vec_map::empty(); + let mut _B: u256 = 0; + let mut i: u8 = 0; let _N = (vec_map::size(balances) as u8); while (i < _N) { vec_map::insert(&mut _W, i, 0u256); i = i + 1; }; - let j: u8 = 0; + let mut j: u8 = 0; while (j < _N) { let w_j = vec_map::get_mut(&mut _W, &j); *w_j = mul( @@ -228,7 +228,7 @@ module ramm_sui::math { j = j + 1; }; - let k: u8 = 0; + let mut k: u8 = 0; while (k < _N) { let w_k = vec_map::get_mut(&mut _W, &k); *w_k = div(*w_k, _B, prec, max_prec); @@ -241,7 +241,7 @@ module ramm_sui::math { /// Returns a tuple with the values of `B` and `L` (see whitepaper, page 5). /// /// The result is given in `u256` with `prec` decimal places. - public(friend) fun compute_B_and_L( + public(package) fun compute_B_and_L( balances: &VecMap, lp_tokens_issued: &VecMap, prices: &VecMap, @@ -251,11 +251,11 @@ module ramm_sui::math { prec: u8, max_prec: u8, ): (u256, u256) { - let _B: u256 = 0; - let _L: u256 = 0; + let mut _B: u256 = 0; + let mut _L: u256 = 0; let _N = (vec_map::size(balances) as u8); - let j: u8 = 0; + let mut j: u8 = 0; while (j < _N) { let price_j = *vec_map::get(prices, &j) * *vec_map::get(factors_for_prices, &j); _B = _B + mul(price_j, *vec_map::get(balances, &j) * *vec_map::get(factors_for_balances, &j), prec, max_prec); @@ -291,10 +291,10 @@ module ramm_sui::math { max_prec, ); - let imbs = vec_map::empty(); + let mut imbs = vec_map::empty(); let _N = (vec_map::size(balances) as u8); - let j: u8 = 0; + let mut j: u8 = 0; while (j < _N) { if (*vec_map::get(lp_tokens_issued, &j) != 0) { let val = div( @@ -340,10 +340,10 @@ module ramm_sui::math { ): bool { let _N = (vec_map::size(balances) as u8); - let balances_before = vec_map::empty(); - let balances_after = vec_map::empty(); + let mut balances_before = vec_map::empty(); + let mut balances_after = vec_map::empty(); - let k = 0; + let mut k = 0; while (k < _N) { let balance_current = *vec_map::get(balances, &k); vec_map::insert(&mut balances_before, k, balance_current); diff --git a/ramm-sui/sources/oracles.move b/ramm-sui/sources/oracles.move index 07201e3..f9c69e8 100644 --- a/ramm-sui/sources/oracles.move +++ b/ramm-sui/sources/oracles.move @@ -4,7 +4,7 @@ module ramm_sui::oracles { use ramm_sui::math; - friend ramm_sui::ramm; + /* friend ramm_sui::ramm; */ const ENegativeSbD: u64 = 0; const EStalePrice: u64 = 1; diff --git a/ramm-sui/sources/ramm.move b/ramm-sui/sources/ramm.move index 5917197..43529c9 100644 --- a/ramm-sui/sources/ramm.move +++ b/ramm-sui/sources/ramm.move @@ -16,8 +16,8 @@ module ramm_sui::ramm { use ramm_sui::oracles; use ramm_sui::math as ramm_math; - friend ramm_sui::interface2; - friend ramm_sui::interface3; + /* friend ramm_sui::interface2; */ + /* friend ramm_sui::interface3; */ const ERAMMInvalidInitState: u64 = 0; const EInvalidAggregator: u64 = 1; @@ -100,13 +100,13 @@ module ramm_sui::ramm { /// of a liquidity provider. /// /// The parameter `Asset` is for the coin held in the pool. - struct LP has drop, store {} + public struct LP has drop, store {} /// Admin capability to circumvent restricted actions on the RAMM pool: /// * transfer RAMM protocol fees out of the pool, /// * enable/disable deposits for a certain asset /// * etc. - struct RAMMAdminCap has key { id: UID } + public struct RAMMAdminCap has key { id: UID } /// Transfer a RAMM's admin capability to another address. /// @@ -131,7 +131,7 @@ module ramm_sui::ramm { /// function like `transfer_admin_cap`, and it does not have `store` either. /// This is by design, as it is not intended for a RAMM to be created and remain without assets /// for long, and disallowing transfer of this cap disincentivizes delays. - struct RAMMNewAssetCap has key { id: UID } + public struct RAMMNewAssetCap has key { id: UID } /// RAMM data structure, allows /// * adding/removing liquidity for one of its assets @@ -162,7 +162,7 @@ module ramm_sui::ramm { /// any further operations. /// /// See this repository's README for more information. - struct RAMM has key { + public struct RAMM has key { // UID of a `RAMM` object. Required for `RAMM` to have the `key` ability, // and ergo become a shared object. id: UID, @@ -295,19 +295,19 @@ module ramm_sui::ramm { const FAILED_LOW_OUT_TOKEN_IMB_RATIO: u8 = 3; /// Code for a successful trade i.e. one which the RAMM can execute. - public(friend) fun success(): u8 { + public(package) fun success(): u8 { SUCCESS } - public(friend) fun failed_pool_imbalance(): u8 { + public(package) fun failed_pool_imbalance(): u8 { FAILED_POOL_IMBALANCE } - public(friend) fun failed_insufficient_out_token_balance(): u8 { + public(package) fun failed_insufficient_out_token_balance(): u8 { FAILED_INSUFFICIENT_OUT_TOKEN_BALANCE } - public(friend) fun failed_low_out_token_imb_ratio(): u8 { + public(package) fun failed_low_out_token_imb_ratio(): u8 { FAILED_LOW_OUT_TOKEN_IMB_RATIO } @@ -320,7 +320,7 @@ module ramm_sui::ramm { /// Note that even if the trade is classified "successful", it is possible the trade is not /// executed - because the `TradeOutput`'s `amount` does not conform to the trader's slippage /// tolerance, for example. - public(friend) fun is_successful(to: &TradeOutput): bool { + public(package) fun is_successful(to: &TradeOutput): bool { to.trade_outcome == success() } @@ -330,7 +330,7 @@ module ramm_sui::ramm { /// as well as the fee to be levied on the inbound asset /// * in the case of an asset withdrawal, the amount of the inbound asset is specified, /// as well as the fee to be levied on the inbound asset - struct TradeOutput has drop { + public struct TradeOutput has drop { amount: u256, protocol_fee: u256, trade_outcome: u8, @@ -338,19 +338,19 @@ module ramm_sui::ramm { /// Return a `TradeOutput`'s calculated amount - might be `0`, depending on the `execute` /// flag. - public(friend) fun amount(to: &TradeOutput): u256 { + public(package) fun amount(to: &TradeOutput): u256 { to.amount } /// Return a trade's calculated protocol fees. - public(friend) fun protocol_fee(to: &TradeOutput): u256 { + public(package) fun protocol_fee(to: &TradeOutput): u256 { to.protocol_fee } /// Return a `TradeOutput`'s trade outcome, represented as a `u8`: /// * `0` for success /// * `1, 2, ...` for different types of failure. - public(friend) fun trade_outcome(to: &TradeOutput): u8 { + public(package) fun trade_outcome(to: &TradeOutput): u8 { to.trade_outcome } @@ -362,7 +362,7 @@ module ramm_sui::ramm { /// * the value of liquidity withdrawal fee applied to each asset, 0.4% of the amount /// * the total value of the redeemed tokens /// * the remaining value - struct WithdrawalOutput has drop { + public struct WithdrawalOutput has drop { amounts: VecMap, fees: VecMap, value: u256, @@ -371,25 +371,25 @@ module ramm_sui::ramm { /// Return a `WithdrawalOutput's` mapping of assets to liquidity withdrawal values /// for that asset. - public(friend) fun amounts(wo: &WithdrawalOutput): VecMap { + public(package) fun amounts(wo: &WithdrawalOutput): VecMap { wo.amounts } /// Return a `WithdrawalOutput's` mapping of assets to liquidity withdrawal fees /// for that asset. - public(friend) fun fees(wo: &WithdrawalOutput): VecMap { + public(package) fun fees(wo: &WithdrawalOutput): VecMap { wo.fees } /// Return the value given to the liquidity provider in terms of token `o`, which the provider /// wants. - public(friend) fun value(wo: &WithdrawalOutput): u256 { + public(package) fun value(wo: &WithdrawalOutput): u256 { wo.value } /// Return the remaining amount of token `o` to be given to the liquidity provider (if any) /// in case the process could not be completed. - public(friend) fun remaining(wo: &WithdrawalOutput): u256 { + public(package) fun remaining(wo: &WithdrawalOutput): u256 { wo.remaining } @@ -428,7 +428,7 @@ module ramm_sui::ramm { ramm_math::power(x, a, ONE, PRECISION_DECIMAL_PLACES, MAX_PRECISION_DECIMAL_PLACES) } - public(friend) fun adjust(x: u256): u256 { + public(package) fun adjust(x: u256): u256 { ramm_math::adjust(x, PRECISION_DECIMAL_PLACES, MAX_PRECISION_DECIMAL_PLACES) } @@ -507,7 +507,7 @@ module ramm_sui::ramm { use sui::test_scenario; let admin = @0xA1; - let scenario_val = test_scenario::begin(admin); + let mut scenario_val = test_scenario::begin(admin); let scenario = &mut scenario_val; { new_ramm(admin, test_scenario::ctx(scenario)); @@ -668,7 +668,7 @@ module ramm_sui::ramm { ERAMMInvalidInitState ); - let ix = 0; + let mut ix = 0; while (ix < self.asset_count) { set_deposit_status(self, ix, true); ix = ix + 1; @@ -690,7 +690,7 @@ module ramm_sui::ramm { /// state such as trading or liquidity deposits/withdrawals, because /// * if the invariant does not hold at the start, the operation should not be performed /// * if it did hold, but then failed to, the operation should be rolled back - public(friend) fun check_ramm_invariants_2(self: &RAMM) { + public(package) fun check_ramm_invariants_2(self: &RAMM) { // This invariant checking function must only be used on RAMMs with 2 assets. assert!(get_asset_count(self) == TWO, EBrokenRAMMInvariants); @@ -709,7 +709,7 @@ module ramm_sui::ramm { /// state such as trading or liquidity deposits/withdrawals, because /// * if the invariant does not hold at the start, the operation should not be performed /// * if it did hold, but then failed to, the operation should be rolled back - public(friend) fun check_ramm_invariants_3(self: &RAMM) { + public(package) fun check_ramm_invariants_3(self: &RAMM) { // This invariant checking function must only be used on RAMMs with 3 assets. assert!(get_asset_count(self) == THREE, EBrokenRAMMInvariants); @@ -753,7 +753,7 @@ module ramm_sui::ramm { /// RAMM ID /// Return a RAMM's `ID`. - public(friend) fun get_id(self: &RAMM): ID { + public(package) fun get_id(self: &RAMM): ID { object::id(self) } @@ -833,7 +833,7 @@ module ramm_sui::ramm { /// `balance::split` in such a way that /// - `balance::zero` is left in the bag /// - the original balance is returned - public(friend) fun get_fees_for_asset(self: &mut RAMM, ix: u8): Balance { + public(package) fun get_fees_for_asset(self: &mut RAMM, ix: u8): Balance { let mut_bal: &mut Balance = bag::borrow_mut>(&mut self.collected_protocol_fees, ix); let curr_fee = balance::value(mut_bal); @@ -841,7 +841,7 @@ module ramm_sui::ramm { } /// Increase the RAMM's collected fees for a certain asset given a `Balance` of it. - public(friend) fun join_protocol_fees(self: &mut RAMM, index: u8, fee: Balance) { + public(package) fun join_protocol_fees(self: &mut RAMM, index: u8, fee: Balance) { let fee_bal = bag::borrow_mut>(&mut self.collected_protocol_fees, index); balance::join(fee_bal, fee); } @@ -855,7 +855,7 @@ module ramm_sui::ramm { /// Minimum trading amounts /// Get an asset's minimum trading amount, in `u64`. - public(friend) fun get_min_trade_amount(self: &RAMM, index: u8): u64 { + public(package) fun get_min_trade_amount(self: &RAMM, index: u8): u64 { *vec_map::get(&self.minimum_trade_amounts, &index) } @@ -902,7 +902,7 @@ module ramm_sui::ramm { /// # Aborts /// /// * If no asset has the provided index - public(friend) fun can_deposit_asset(self: &RAMM, index: u8): bool { + public(package) fun can_deposit_asset(self: &RAMM, index: u8): bool { *vec_map::get(&self.deposits_enabled, &index) } @@ -993,7 +993,7 @@ module ramm_sui::ramm { /// # Aborts /// /// If the provided index does not match any existing asset's. - public(friend) fun get_prev_prc(self: &RAMM, index: u8): u256 { + public(package) fun get_prev_prc(self: &RAMM, index: u8): u256 { *vec_map::get(&self.previous_prices, &index) } @@ -1015,7 +1015,7 @@ module ramm_sui::ramm { /// Given a RAMM, an asset and its new price queried from an aggregator, update the RAMM's /// internal state. - public(friend) fun set_previous_price(self: &mut RAMM, new_price: u256) { + public(package) fun set_previous_price(self: &mut RAMM, new_price: u256) { let ix = get_asset_index(self); set_prev_prc(self, ix, new_price) } @@ -1026,7 +1026,7 @@ module ramm_sui::ramm { /// # Aborts /// /// If the provided index does not match any existing asset's. - public(friend) fun get_prev_prc_tmstmp(self: &RAMM, index: u8): u64 { + public(package) fun get_prev_prc_tmstmp(self: &RAMM, index: u8): u64 { *vec_map::get(&self.previous_price_timestamps, &index) } @@ -1053,7 +1053,7 @@ module ramm_sui::ramm { /// Given a RAMM, one of its assets and a timestamp for its most recently queried price data, /// update the RAMM's internal state. - public(friend) fun set_previous_price_timestamp( + public(package) fun set_previous_price_timestamp( self: &mut RAMM, new_price_timestamp: u64 ) { @@ -1113,7 +1113,7 @@ module ramm_sui::ramm { /// Get an asset's typed balance, meaning the untyped, pure scalar value (`u256`) used /// internally by the RAMM to represent an asset's balance. - public(friend) fun get_bal(self: &RAMM, index: u8): u256 { + public(package) fun get_bal(self: &RAMM, index: u8): u256 { *vec_map::get(&self.balances, &index) } @@ -1134,7 +1134,7 @@ module ramm_sui::ramm { /// It is the caller's responsibility to ensure this change is also /// reflected in, or is a reflection of, equivalent changes in the asset's typed /// balance. - public(friend) fun join_bal(self: &mut RAMM, index: u8, bal: u256) { + public(package) fun join_bal(self: &mut RAMM, index: u8, bal: u256) { let asset_bal: &mut u256 = get_mut_bal(self, index); *asset_bal = *asset_bal + bal; } @@ -1144,7 +1144,7 @@ module ramm_sui::ramm { /// It is the caller's responsibility to ensure this change is also /// reflected in, or is a reflection of, equivalent changes in the asset's typed /// balance. - public(friend) fun split_bal(self: &mut RAMM, index: u8, val: u256) { + public(package) fun split_bal(self: &mut RAMM, index: u8, val: u256) { let asset_bal: &mut u256 = get_mut_bal(self, index); *asset_bal = *asset_bal - val; } @@ -1173,7 +1173,7 @@ module ramm_sui::ramm { /// It is the caller's responsibility to ensure this change is also /// reflected in, or is a reflection of, equivalent changes in the asset's untyped /// balance. - public(friend) fun join_typed_bal(self: &mut RAMM, index: u8, bal: Balance) { + public(package) fun join_typed_bal(self: &mut RAMM, index: u8, bal: Balance) { let asset_bal: &mut Balance = get_mut_typed_bal(self, index); balance::join(asset_bal, bal); } @@ -1184,7 +1184,7 @@ module ramm_sui::ramm { /// It is the caller's responsibility to ensure this change is also /// reflected in, or is a reflection of, equivalent changes in the asset's untyped /// balance. - public(friend) fun split_typed_bal(self: &mut RAMM, index: u8, val: u64): Balance { + public(package) fun split_typed_bal(self: &mut RAMM, index: u8, val: u64): Balance { let asset_bal: &mut Balance = get_mut_typed_bal(self, index); balance::split(asset_bal, val) } @@ -1222,7 +1222,7 @@ module ramm_sui::ramm { /// /// It is the user's responsibility to ensure that there is also an /// update to the typed count for this token. - public(friend) fun incr_lptokens_issued(self: &mut RAMM, minted: u64) { + public(package) fun incr_lptokens_issued(self: &mut RAMM, minted: u64) { let ix = get_asset_index(self); let lptoks = vec_map::get_mut(&mut self.lp_tokens_issued, &ix); *lptoks = *lptoks + (minted as u256); @@ -1232,7 +1232,7 @@ module ramm_sui::ramm { /// /// It is the user's responsibility to ensure that there is also an /// update to the typed count for this token. - public(friend) fun decr_lptokens_issued(self: &mut RAMM, burned: u64) { + public(package) fun decr_lptokens_issued(self: &mut RAMM, burned: u64) { let ix = get_asset_index(self); let lptoks = vec_map::get_mut(&mut self.lp_tokens_issued, &ix); *lptoks = *lptoks - (burned as u256); @@ -1273,7 +1273,7 @@ module ramm_sui::ramm { /// /// It's is the user's responsibility to ensure that there is also an /// update to the untyped LP token count for this token. - public(friend) fun mint_lp_tokens(self: &mut RAMM, amount: u64): Balance> { + public(package) fun mint_lp_tokens(self: &mut RAMM, amount: u64): Balance> { let supply = get_lptoken_supply(self); balance::increase_supply(supply, amount) } @@ -1282,7 +1282,7 @@ module ramm_sui::ramm { /// /// It's is the user's responsibility to ensure that there is also an /// update to the untyped LP token count for this token. - public(friend) fun burn_lp_tokens(self: &mut RAMM, lp_tokens: Balance>): u64 { + public(package) fun burn_lp_tokens(self: &mut RAMM, lp_tokens: Balance>): u64 { let supply = get_lptoken_supply(self); balance::decrease_supply(supply, lp_tokens) } @@ -1306,7 +1306,7 @@ module ramm_sui::ramm { /// # Aborts /// /// * If the index doesn't many any asset - public(friend) fun get_fact_for_bal(self: &RAMM, index: u8): u256 { + public(package) fun get_fact_for_bal(self: &RAMM, index: u8): u256 { *vec_map::get(&self.factors_for_balances, &index) } @@ -1356,9 +1356,9 @@ module ramm_sui::ramm { // The vectors can't be `copy`ed, `vec_map::values` does not exist, and // `vec_map::into_keys_values` shouldn't be used, as by traversing the balance vectors, it // is certain the balances will be in the correct order. - let i = 0; - let asset_balances: vector = vector::empty(); - let asset_lpt_issued: vector = vector::empty(); + let mut i = 0; + let mut asset_balances: vector = vector::empty(); + let mut asset_lpt_issued: vector = vector::empty(); while (i < self.asset_count) { vector::push_back(&mut asset_balances, get_bal(self, i)); vector::push_back(&mut asset_lpt_issued, get_lptok_issued(self, i)); @@ -1380,14 +1380,14 @@ module ramm_sui::ramm { /// # Aborts /// /// This function will abort if the RAMM has no assets with the given type. - public(friend) fun get_asset_index(self: &RAMM): u8 { + public(package) fun get_asset_index(self: &RAMM): u8 { let type_name = type_name::get(); let n: &u8 = vec_map::get(&self.types_to_indexes, &type_name); *n } /// For a given `Asset` in the RAMM, return how many LP tokens are in circulation. - public(friend) fun lptok_in_circulation(self: &RAMM, index: u8): u64 { + public(package) fun lptok_in_circulation(self: &RAMM, index: u8): u64 { let supply: &Supply> = bag::borrow(&self.typed_lp_tokens_issued, index); balance::supply_value(supply) } @@ -1396,7 +1396,7 @@ module ramm_sui::ramm { /// of the RAMM's balance for that asset. /// /// The value of `MU` is to be taken as a percentage. - public(friend) fun check_trade_amount_in(self: &RAMM, amount_in: u256) { + public(package) fun check_trade_amount_in(self: &RAMM, amount_in: u256) { let cmp: u256 = mul(div(MU, ONE - MU), get_typed_balance(self)); assert!(amount_in <= cmp, ETradeExcessAmountIn); } @@ -1405,7 +1405,7 @@ module ramm_sui::ramm { /// of the RAMM's balance for that asset. /// /// The value of `MU` is to be taken as a percentage. - public(friend) fun check_trade_amount_out(self: &RAMM, amount_out: u256) { + public(package) fun check_trade_amount_out(self: &RAMM, amount_out: u256) { let cmp: u256 = mul(get_typed_balance(self), MU); assert!(amount_out <= cmp, ETradeExcessAmountOut); } @@ -1418,7 +1418,7 @@ module ramm_sui::ramm { /// 2. Deducting `a` from the RAMM's reserves, and creating a `Coin` object from it (`c`) /// 3. Incrementing the RAMM's collected fees with `f` /// 4. Returning `c` to be transferred by the calling function - public(friend) fun liq_withdraw_helper( + public(package) fun liq_withdraw_helper( // RAMM self: &mut RAMM, ix: u8, @@ -1447,7 +1447,7 @@ module ramm_sui::ramm { /// * its timestamp, /// /// update that asset's data in the RAMM's internal state. - public(friend) fun update_pricing_data( + public(package) fun update_pricing_data( self: &mut RAMM, new_price: u256, new_price_timestamp: u64 @@ -1482,7 +1482,7 @@ module ramm_sui::ramm { /// * from asset indices to their prices' scaling factors /// /// These maps are passed into the function as mutable arguments. - public(friend) fun check_feed_and_get_price_data( + public(package) fun check_feed_and_get_price_data( self: &RAMM, current_timestamp: u64, ix: u8, @@ -1636,7 +1636,7 @@ module ramm_sui::ramm { /// /// The value will represent a percentage i.e. a value between `0` and `ONE`, where /// `ONE` is the value `1` with `PRECISION_DECIMAL_PLACES` decimal places. - public(friend) fun compute_volatility_fee( + public(package) fun compute_volatility_fee( self: &RAMM, asset_index: u8, new_price: u256, @@ -1659,7 +1659,7 @@ module ramm_sui::ramm { } /// Update a given asset's volatility index/timestamp. - public(friend) fun update_volatility_data( + public(package) fun update_volatility_data( self: &mut RAMM, asset_index: u8, previous_price: u256, @@ -1712,7 +1712,7 @@ module ramm_sui::ramm { /// functions. /// /// This function can be used on a RAMM of any size. - public(friend) fun trade_i( + public(package) fun trade_i( self: &RAMM, // index of incoming token i: u8, @@ -1793,7 +1793,7 @@ module ramm_sui::ramm { /// functions. /// /// This function can be used on a RAMM of any size. - public(friend) fun trade_o( + public(package) fun trade_o( self: &RAMM, // index of incoming token i: u8, @@ -1873,7 +1873,7 @@ module ramm_sui::ramm { /// the caller. /// /// Unlike the client-facing API, this function can be used on a RAMM of any size. - public(friend) fun liq_dep( + public(package) fun liq_dep( self: &RAMM, i: u8, ai: u64, @@ -1925,7 +1925,7 @@ module ramm_sui::ramm { /// This function is internal to the RAMM, and it can/should only be used indirectly. /// In other words, by being called in the client facing modules of the package, e.g. /// `interface3` for 3-asset RAMMs. - public(friend) fun liq_wthdrw( + public(package) fun liq_wthdrw( self: &RAMM, o: u8, lpt: u64, @@ -1935,20 +1935,20 @@ module ramm_sui::ramm { ): WithdrawalOutput { let lpt: u256 = (lpt as u256); - let amounts_out = vec_map::empty(); + let mut amounts_out = vec_map::empty(); // Required to initialize this `VecMap` to zeroes, or `liquidity_withdrawal` // will fail. - let t: u8 = 0; + let mut t: u8 = 0; while (t < get_asset_count(self)) { vec_map::insert(&mut amounts_out, t, 0); t = t + 1; }; - let fees: VecMap = copy amounts_out; + let mut fees: VecMap = copy amounts_out; let a_remaining: &mut u256 = &mut 0; let factor_o: u256 = get_fact_for_bal(self, o); let bo: u256 = get_typed_bal(self, o) * factor_o; - let imb_ratios: VecMap = imbalance_ratios(self, &prices, &factors_for_prices); + let mut imb_ratios: VecMap = imbalance_ratios(self, &prices, &factors_for_prices); let ao: &mut u256 = &mut 0; let (_B, _L): (u256, u256) = compute_B_and_L(self, &prices, &factors_for_prices); @@ -2026,12 +2026,12 @@ module ramm_sui::ramm { // Potential case: withdrawal continued with different tokens *vec_map::get_mut(&mut imb_ratios, &o) = 0; - let j: u8 = 0; + let mut j: u8 = 0; while (j < get_asset_count(self)) { let max_imb_ratio: &mut u256 = &mut 0; let index: &mut u8 = &mut copy o; - let l: u8 = 0; + let mut l: u8 = 0; while (l < get_asset_count(self)) { if (*max_imb_ratio < *vec_map::get(&imb_ratios, &l)) { *index = l; diff --git a/ramm-sui/tests/interface2_oracle_safety_tests.move b/ramm-sui/tests/interface2_oracle_safety_tests.move index 77f5cfb..120d755 100644 --- a/ramm-sui/tests/interface2_oracle_safety_tests.move +++ b/ramm-sui/tests/interface2_oracle_safety_tests.move @@ -42,13 +42,13 @@ module ramm_sui::interface2_oracle_safety_tests { #[test] #[expected_failure(abort_code = oracles::EStalePrice)] fun trade_amount_in_2_stale_aggregator_price() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); - let clock = test_scenario::take_shared(scenario); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut clock = test_scenario::take_shared(scenario); let btc_amount: u64 = (1 * test_util::btc_factor() as u64); let amount_in = coin::mint_for_testing(btc_amount, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -78,13 +78,13 @@ module ramm_sui::interface2_oracle_safety_tests { #[test] #[expected_failure(abort_code = oracles::EStalePrice)] fun trade_amount_out_2_stale_aggregator_price() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); - let clock = test_scenario::take_shared(scenario); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut clock = test_scenario::take_shared(scenario); let btc_amount: u64 = (1 * test_util::btc_factor() as u64); let max_amount_in = coin::mint_for_testing(btc_amount, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -114,13 +114,13 @@ module ramm_sui::interface2_oracle_safety_tests { #[test] #[expected_failure(abort_code = oracles::EStalePrice)] fun liquidity_deposit_2_stale_aggregator_price() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); - let clock = test_scenario::take_shared(scenario); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut clock = test_scenario::take_shared(scenario); let btc_amount: u64 = (1 * test_util::btc_factor() as u64); let amount_in = coin::mint_for_testing(btc_amount, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -150,13 +150,13 @@ module ramm_sui::interface2_oracle_safety_tests { #[expected_failure(abort_code = oracles::EStalePrice)] fun liquidity_withdrawal_2_zero_deposit() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); - let clock = test_scenario::take_shared(scenario); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut clock = test_scenario::take_shared(scenario); let lp_btc_amount: u64 = (1 * test_util::btc_factor() as u64); let lp_tokens = coin::mint_for_testing>(lp_btc_amount, test_scenario::ctx(scenario)); diff --git a/ramm-sui/tests/interface2_safety_tests.move b/ramm-sui/tests/interface2_safety_tests.move index 26b7e05..9b12ddc 100644 --- a/ramm-sui/tests/interface2_safety_tests.move +++ b/ramm-sui/tests/interface2_safety_tests.move @@ -56,12 +56,12 @@ module ramm_sui::interface2_safety_tests { #[expected_failure(abort_code = interface2::ERAMMInvalidSize)] /// Check that calling `trade_amount_in_2` on a RAMM without *exactly* 2 assets fails. fun trade_amount_in_2_invalid_ramm_size() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, _, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, _, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -93,12 +93,12 @@ module ramm_sui::interface2_safety_tests { /// This test *must* fail. fun trade_amount_in_2_invalid_asset() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -130,12 +130,12 @@ module ramm_sui::interface2_safety_tests { /// This *must* fail. fun trade_amount_in_2_insufficient_amount_in() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(999, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -168,12 +168,12 @@ module ramm_sui::interface2_safety_tests { /// This test *must* fail. fun trade_amount_in_2_no_minted_lptoken() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1 * (test_util::btc_factor() as u64), test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -204,18 +204,18 @@ module ramm_sui::interface2_safety_tests { /// /// This *must* fail. fun trade_amount_in_2_insufficient_outbound_balance() { - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, 1000); vec_map::insert(&mut initial_asset_liquidity, 1, 0); vec_map::insert(&mut initial_asset_liquidity, 2, 0); // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth(ALICE, initial_asset_liquidity); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -246,12 +246,12 @@ module ramm_sui::interface2_safety_tests { /// for the inbound asset will fail. fun trade_amount_in_2_excessive_amount_in() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -284,12 +284,12 @@ module ramm_sui::interface2_safety_tests { /// for the outbound asset will fail. fun trade_amount_in_2_excessive_amount_out() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -325,12 +325,12 @@ module ramm_sui::interface2_safety_tests { /// This *must* fail. fun trade_amount_in_2_invalid_aggregator() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -365,12 +365,12 @@ module ramm_sui::interface2_safety_tests { #[expected_failure(abort_code = interface2::ERAMMInvalidSize)] /// Check that calling `trade_amount_out_2` on a RAMM without *exactly* 2 assets fails. fun trade_amount_out_2_invalid_ramm_size() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, _, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, _, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let max_amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -402,12 +402,12 @@ module ramm_sui::interface2_safety_tests { /// This test *must* fail. fun trade_amount_out_2_invalid_asset() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let max_amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -439,12 +439,12 @@ module ramm_sui::interface2_safety_tests { /// This *must* fail. fun trade_amount_out_2_insufficient_amount_in() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); // Recall that `create_ramm_2_test_scenario_with_liquidity_in` sets a 0.001 ETH // minimum trade amount, and that this ETH has 8 decimal places of precision @@ -479,12 +479,12 @@ module ramm_sui::interface2_safety_tests { /// This test *must* fail. fun trade_amount_out_2_no_minted_lptoken() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let max_amount_in = coin::mint_for_testing(1 * (test_util::btc_factor() as u64), test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -515,18 +515,18 @@ module ramm_sui::interface2_safety_tests { /// /// This *must* fail. fun trade_amount_out_2_insufficient_outbound_balance() { - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, 1000); vec_map::insert(&mut initial_asset_liquidity, 1, 0); vec_map::insert(&mut initial_asset_liquidity, 2, 0); // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth(ALICE, initial_asset_liquidity); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -557,12 +557,12 @@ module ramm_sui::interface2_safety_tests { /// for the outbound asset will fail. fun trade_amount_out_2_excessive_amount_out() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -593,12 +593,12 @@ module ramm_sui::interface2_safety_tests { /// for the inbound asset will fail. fun trade_amount_out_2_excessive_amount_in() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -632,12 +632,12 @@ module ramm_sui::interface2_safety_tests { /// This *must* fail. fun trade_amount_out_2_invalid_aggregator() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -673,12 +673,12 @@ module ramm_sui::interface2_safety_tests { /// This *must* fail. fun trade_amount_out_2_balance_empty_balance_with_circ_lp_tokens() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -715,12 +715,12 @@ module ramm_sui::interface2_safety_tests { #[expected_failure(abort_code = interface2::ERAMMInvalidSize)] /// Check that calling `liquidity_deposit_2` on a RAMM without *exactly* 2 assets fails. fun liquidity_deposit_2_invalid_ramm_size() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, _, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, _, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -751,12 +751,12 @@ module ramm_sui::interface2_safety_tests { /// This test *must* fail. fun liquidity_deposit_2_invalid_asset() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -787,12 +787,12 @@ module ramm_sui::interface2_safety_tests { /// This test *must* fail. fun liquidity_deposit_2_zero_deposit() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(0, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -823,12 +823,12 @@ module ramm_sui::interface2_safety_tests { /// This *must* fail. fun liquidity_deposit_2_invalid_aggregator() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -862,12 +862,12 @@ module ramm_sui::interface2_safety_tests { #[expected_failure(abort_code = interface2::ERAMMInvalidSize)] /// Check that calling `liquidity_withdrawal_2` on a RAMM without *exactly* 2 assets fails. fun liquidity_withdrawal_2_invalid_ramm_size() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, _, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, _, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let lp_token = coin::mint_for_testing>(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -898,12 +898,12 @@ module ramm_sui::interface2_safety_tests { /// This test *must* fail. fun liquidity_withdrawal_2_invalid_asset() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let lp_tokens = coin::mint_for_testing>(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -934,12 +934,12 @@ module ramm_sui::interface2_safety_tests { /// This *must* fail. fun liquidity_withdrawal_2_invalid_aggregator() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -972,12 +972,12 @@ module ramm_sui::interface2_safety_tests { /// This test *must* fail. fun liquidity_withdrawal_2_zero_deposit() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let lp_tokens = coin::mint_for_testing>(0, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -1013,12 +1013,12 @@ module ramm_sui::interface2_safety_tests { #[expected_failure(abort_code = interface2::ERAMMInvalidSize)] /// Check that calling `collect_fees_2` on a RAMM without *exactly* 2 assets fails. fun collect_fees_2_invalid_ramm_size() { - let (alice_ramm_id, _, _, _, scenario_val) = + let (alice_ramm_id, _, _, _, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let admin_cap = test_scenario::take_from_address(scenario, ALICE); @@ -1044,7 +1044,7 @@ module ramm_sui::interface2_safety_tests { /// It *must* fail. fun collect_fees_2_wrong_admin_cap() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, _, _, scenario_val) = test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); + let (alice_ramm_id, _, _, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); let scenario = &mut scenario_val; test_scenario::next_tx(scenario, BOB); @@ -1056,7 +1056,7 @@ module ramm_sui::interface2_safety_tests { test_scenario::next_tx(scenario, ALICE); { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let bob_admin_cap = test_scenario::take_from_address(scenario, BOB); diff --git a/ramm-sui/tests/interface2_tests.move b/ramm-sui/tests/interface2_tests.move index 410c146..42c080a 100644 --- a/ramm-sui/tests/interface2_tests.move +++ b/ramm-sui/tests/interface2_tests.move @@ -27,7 +27,7 @@ module ramm_sui::interface2_tests { /// 2. Next, a redemption of every LPETH token by a provider /// 3. Finally, a redemption of every LPUSDT token by a provider fun liquidity_withdrawal_2_test() { - let (ramm_id, eth_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); + let (ramm_id, eth_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); let scenario = &mut scenario_val; // First part of the test: a trader, Alice, wishes to buy 20 ETH @@ -36,7 +36,7 @@ module ramm_sui::interface2_tests { test_scenario::next_tx(scenario, ALICE); let (total_usdt, usdt_trade_fees) : (u256, u256) = { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); @@ -115,7 +115,7 @@ module ramm_sui::interface2_tests { test_scenario::next_tx(scenario, ADMIN); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); @@ -163,7 +163,7 @@ module ramm_sui::interface2_tests { let collected_usdt_liquidity_withdrawal_fees: u256 = { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); @@ -220,7 +220,7 @@ module ramm_sui::interface2_tests { /// protocol fees from this trade, and 0 of any other asset. /// * futhermore, the RAMM's fees should be null after the collection fun collect_fees_2_test_1() { - let (ramm_id, eth_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); + let (ramm_id, eth_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); let scenario = &mut scenario_val; let eth_trade_amount: u64 = 10 * (test_util::eth_factor() as u64); @@ -237,7 +237,7 @@ module ramm_sui::interface2_tests { // Trade: 10 ETH in, roughly 20k USDT out // The pool is fresh, so all imbalance ratios are 1 let eth_trade_fee: u256 = { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); @@ -302,7 +302,7 @@ module ramm_sui::interface2_tests { // Next step: collect the RAMM fees to the collection address (in this case, the admin's) { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let admin_cap = test_scenario::take_from_address(scenario, ADMIN); interface2::collect_fees_2( @@ -351,7 +351,7 @@ module ramm_sui::interface2_tests { /// protocol fees from this withdrawal, and 0 of any other asset. /// * futhermore, the RAMM's fees should be null after the collection fun collect_fees_2_test_2() { - let (ramm_id, eth_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); + let (ramm_id, eth_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); let scenario = &mut scenario_val; let prec: u8 = test_util::eth_dec_places(); @@ -363,7 +363,7 @@ module ramm_sui::interface2_tests { // First step: the admin withdraws the ETH they've provided to the pool let (initial_eth_balance, initial_usdt_balance): (u256, u256) = { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); @@ -404,7 +404,7 @@ module ramm_sui::interface2_tests { // Second step: the admin performs the fee collection { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let admin_cap = test_scenario::take_from_address(scenario, ADMIN); interface2::collect_fees_2( diff --git a/ramm-sui/tests/interface3_oracle_safety_tests.move b/ramm-sui/tests/interface3_oracle_safety_tests.move index f7cf4c0..0734ffb 100644 --- a/ramm-sui/tests/interface3_oracle_safety_tests.move +++ b/ramm-sui/tests/interface3_oracle_safety_tests.move @@ -42,13 +42,13 @@ module ramm_sui::interface3_oracle_safety_tests { #[test] #[expected_failure(abort_code = oracles::EStalePrice)] fun trade_amount_in_3_stale_aggregator_price() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); - let clock = test_scenario::take_shared(scenario); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut clock = test_scenario::take_shared(scenario); let btc_amount: u64 = (1 * test_util::btc_factor() / 10as u64); let amount_in = coin::mint_for_testing(btc_amount, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -81,13 +81,13 @@ module ramm_sui::interface3_oracle_safety_tests { #[test] #[expected_failure(abort_code = oracles::EStalePrice)] fun trade_amount_out_3_stale_aggregator_price() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); - let clock = test_scenario::take_shared(scenario); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut clock = test_scenario::take_shared(scenario); let btc_amount: u64 = (1 * test_util::btc_factor() as u64); let max_amount_in = coin::mint_for_testing(btc_amount, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -120,13 +120,13 @@ module ramm_sui::interface3_oracle_safety_tests { #[test] #[expected_failure(abort_code = oracles::EStalePrice)] fun liquidity_deposit_3_stale_aggregator_price() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); - let clock = test_scenario::take_shared(scenario); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut clock = test_scenario::take_shared(scenario); let btc_amount: u64 = (1 * test_util::btc_factor() as u64); let amount_in = coin::mint_for_testing(btc_amount, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -159,13 +159,13 @@ module ramm_sui::interface3_oracle_safety_tests { #[expected_failure(abort_code = oracles::EStalePrice)] fun liquidity_withdrawal_3_zero_deposit() { // Create a 2-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val) = + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); - let clock = test_scenario::take_shared(scenario); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut clock = test_scenario::take_shared(scenario); let lp_btc_amount: u64 = (1 * test_util::btc_factor() as u64); let lp_tokens = coin::mint_for_testing>(lp_btc_amount, test_scenario::ctx(scenario)); diff --git a/ramm-sui/tests/interface3_safety_tests.move b/ramm-sui/tests/interface3_safety_tests.move index 704888e..b8aee68 100644 --- a/ramm-sui/tests/interface3_safety_tests.move +++ b/ramm-sui/tests/interface3_safety_tests.move @@ -57,11 +57,11 @@ module ramm_sui::interface3_safety_tests { #[expected_failure(abort_code = interface3::ERAMMInvalidSize)] /// Check that calling `trade_amount_in_3` on a RAMM without *exactly* 3 assets fails. fun trade_amount_in_3_invalid_ramm_size() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val)= test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -94,12 +94,12 @@ module ramm_sui::interface3_safety_tests { /// This test *must* fail. fun trade_amount_in_3_invalid_asset() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -134,12 +134,12 @@ module ramm_sui::interface3_safety_tests { /// This *must* fail. fun trade_amount_in_3_insufficient_amount_in() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val) + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(999, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -175,12 +175,12 @@ module ramm_sui::interface3_safety_tests { /// This test *must* fail. fun trade_amount_in_3_no_minted_lptoken() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1 * (test_util::btc_factor() as u64), test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -214,18 +214,18 @@ module ramm_sui::interface3_safety_tests { /// /// This *must* fail. fun trade_amount_in_3_insufficient_outbound_balance() { - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, 1000); vec_map::insert(&mut initial_asset_liquidity, 1, 0); vec_map::insert(&mut initial_asset_liquidity, 2, 0); // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol(ALICE, initial_asset_liquidity); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -259,12 +259,12 @@ module ramm_sui::interface3_safety_tests { /// for the inbound asset will fail. fun trade_amount_in_3_excessive_amount_in() { // Create a 3-asset pool with BTC, ETH - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -300,12 +300,12 @@ module ramm_sui::interface3_safety_tests { /// for the outbound asset will fail. fun trade_amount_in_3_excessive_amount_out() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -344,12 +344,12 @@ module ramm_sui::interface3_safety_tests { /// This *must* fail. fun trade_amount_in_3_invalid_aggregator() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -387,11 +387,11 @@ module ramm_sui::interface3_safety_tests { #[expected_failure(abort_code = interface3::ERAMMInvalidSize)] /// Check that calling `trade_amount_out_3` on a RAMM without *exactly* 3 assets fails. fun trade_amount_out_3_invalid_ramm_size() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val)= test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let max_amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -424,12 +424,12 @@ module ramm_sui::interface3_safety_tests { /// This test *must* fail. fun trade_amount_out_3_invalid_asset() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let max_amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -464,12 +464,12 @@ module ramm_sui::interface3_safety_tests { /// This *must* fail. fun trade_amount_out_3_insufficient_amount_in() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val) + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); // Recall that `create_ramm_3_test_scenario_with_liquidity_in` sets a 0.001 ETH // minimum trade amount, and that this ETH has 8 decimal places of precision @@ -507,12 +507,12 @@ module ramm_sui::interface3_safety_tests { /// This test *must* fail. fun trade_amount_out_3_no_minted_lptoken() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let max_amount_in = coin::mint_for_testing(1 * (test_util::btc_factor() as u64), test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -546,18 +546,18 @@ module ramm_sui::interface3_safety_tests { /// /// This *must* fail. fun trade_amount_out_3_insufficient_outbound_balance() { - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, 1000); vec_map::insert(&mut initial_asset_liquidity, 1, 0); vec_map::insert(&mut initial_asset_liquidity, 2, 0); // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol(ALICE, initial_asset_liquidity); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -591,12 +591,12 @@ module ramm_sui::interface3_safety_tests { /// for the outbound asset will fail. fun trade_amount_out_3_excessive_amount_out() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -630,12 +630,12 @@ module ramm_sui::interface3_safety_tests { /// for the inbound asset will fail. fun trade_amount_out_3_excessive_amount_in() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -674,12 +674,12 @@ module ramm_sui::interface3_safety_tests { /// This *must* fail. fun trade_amount_out_3_invalid_aggregator() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -718,12 +718,12 @@ module ramm_sui::interface3_safety_tests { /// This *must* fail. fun trade_amount_out_3_balance_empty_balance_with_circ_lp_tokens() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -760,12 +760,12 @@ module ramm_sui::interface3_safety_tests { #[expected_failure(abort_code = interface3::ERAMMInvalidSize)] /// Check that calling `liquidity_deposit_3` on a RAMM without *exactly* 3 assets fails. fun liquidity_deposit_3_invalid_ramm_size() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -797,12 +797,12 @@ module ramm_sui::interface3_safety_tests { /// This test *must* fail. fun liquidity_deposit_3_invalid_asset() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -836,12 +836,12 @@ module ramm_sui::interface3_safety_tests { /// This test *must* fail. fun liquidity_deposit_3_zero_deposit() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let amount_in = coin::mint_for_testing(0, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -875,12 +875,12 @@ module ramm_sui::interface3_safety_tests { /// This *must* fail. fun liquidity_deposit_3_invalid_aggregator() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -917,11 +917,11 @@ module ramm_sui::interface3_safety_tests { #[expected_failure(abort_code = interface3::ERAMMInvalidSize)] /// Check that calling `liquidity_withdrawal_3` on a RAMM without *exactly* 3 assets fails. fun liquidity_withdrawal_3_invalid_ramm_size() { - let (alice_ramm_id, btc_ag_id, eth_ag_id, scenario_val)= test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); + let (alice_ramm_id, btc_ag_id, eth_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let lp_token = coin::mint_for_testing>(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -953,12 +953,12 @@ module ramm_sui::interface3_safety_tests { /// This test *must* fail. fun liquidity_withdrawal_3_invalid_asset() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let lp_tokens = coin::mint_for_testing>(1000, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -992,12 +992,12 @@ module ramm_sui::interface3_safety_tests { /// This *must* fail. fun liquidity_withdrawal_3_invalid_aggregator() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); @@ -1033,12 +1033,12 @@ module ramm_sui::interface3_safety_tests { /// This test *must* fail. fun liquidity_withdrawal_3_zero_deposit() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val)= + let (alice_ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let lp_tokens = coin::mint_for_testing>(0, test_scenario::ctx(scenario)); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); @@ -1077,11 +1077,11 @@ module ramm_sui::interface3_safety_tests { #[expected_failure(abort_code = interface3::ERAMMInvalidSize)] /// Check that calling `collect_fees_3` on a RAMM without *exactly* 3 assets fails. fun collect_fees_3_invalid_ramm_size() { - let (alice_ramm_id, _, _, scenario_val)= test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); + let (alice_ramm_id, _, _, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_no_liq(ALICE); let scenario = &mut scenario_val; { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let admin_cap = test_scenario::take_from_address(scenario, ALICE); @@ -1107,7 +1107,7 @@ module ramm_sui::interface3_safety_tests { /// It *must* fail. fun collect_fees_3_wrong_admin_cap() { // Create a 3-asset pool with BTC, ETH, SOL - let (alice_ramm_id, _, _, _, scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); + let (alice_ramm_id, _, _, _, mut scenario_val)= test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ALICE); let scenario = &mut scenario_val; test_scenario::next_tx(scenario, BOB); @@ -1119,7 +1119,7 @@ module ramm_sui::interface3_safety_tests { test_scenario::next_tx(scenario, ALICE); { - let alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); + let mut alice_ramm = test_scenario::take_shared_by_id(scenario, alice_ramm_id); let clock = test_scenario::take_shared(scenario); let bob_admin_cap = test_scenario::take_from_address(scenario, BOB); diff --git a/ramm-sui/tests/interface3_tests.move b/ramm-sui/tests/interface3_tests.move index 32371df..c16afb1 100644 --- a/ramm-sui/tests/interface3_tests.move +++ b/ramm-sui/tests/interface3_tests.move @@ -28,13 +28,13 @@ module ramm_sui::interface3_tests { /// asset the pool can provide. /// The trader receives no "change". fun trade_amount_in_3_test() { - let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); + let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); let scenario = &mut scenario_val; test_scenario::next_tx(scenario, ALICE); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); @@ -137,7 +137,7 @@ module ramm_sui::interface3_tests { test_utils::assert_eq(test_scenario::num_user_events(&tx_fx), 0); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); @@ -185,13 +185,13 @@ module ramm_sui::interface3_tests { /// of an asset they desire, and provide an upper bound of the inbound asset, /// being returned the remainder. fun trade_amount_out_3_test() { - let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); + let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); let scenario = &mut scenario_val; test_scenario::next_tx(scenario, BOB); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); @@ -272,7 +272,7 @@ module ramm_sui::interface3_tests { #[test] /// Check that emitting an event with the pool's imbalance ratios does so. fun imbalance_ratios_event_3_test() { - let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, scenario_val) = + let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); let scenario = &mut scenario_val; @@ -322,7 +322,7 @@ module ramm_sui::interface3_tests { /// protocol fees from this trade, and 0 of any other asset. /// * futhermore, the RAMM's fees should be null after the collection fun collect_fees_3_test_1() { - let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); + let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); let scenario = &mut scenario_val; let eth_trade_amount: u64 = 10 * (test_util::eth_factor() as u64); @@ -339,7 +339,7 @@ module ramm_sui::interface3_tests { // Trade: 10 ETH in, roughly 18k USDT out // The pool is fresh, so all imbalance ratios are 1 let eth_trade_fee: u256 = { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); @@ -414,7 +414,7 @@ module ramm_sui::interface3_tests { // Next step: collect the RAMM fees to the collection address (in this case, the admin's) { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let admin_cap = test_scenario::take_from_address(scenario, ADMIN); interface3::collect_fees_3( @@ -465,7 +465,7 @@ module ramm_sui::interface3_tests { /// protocol fees from this withdrawal, and 0 of any other asset. /// * futhermore, the RAMM's fees should be null after the collection fun collect_fees_3_test_2() { - let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); + let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); let scenario = &mut scenario_val; let prec: u8 = test_util::eth_dec_places(); @@ -477,7 +477,7 @@ module ramm_sui::interface3_tests { // First step: the admin withdraws the ETH they've provided to the pool let (initial_eth_balance, initial_matic_balance, initial_usdt_balance): (u256, u256, u256) = { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); @@ -522,7 +522,7 @@ module ramm_sui::interface3_tests { // Second step: the admin performs the fee collection { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let admin_cap = test_scenario::take_from_address(scenario, ADMIN); interface3::collect_fees_3( diff --git a/ramm-sui/tests/liquidity_provision_fees_tests.move b/ramm-sui/tests/liquidity_provision_fees_tests.move index 9b198f7..58903d9 100644 --- a/ramm-sui/tests/liquidity_provision_fees_tests.move +++ b/ramm-sui/tests/liquidity_provision_fees_tests.move @@ -76,7 +76,7 @@ module ramm_sui::liquidity_provision_fees_tests { admin_address: address, max_iterations: u64 ) { - let (ramm_id, eth_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(admin_address); + let (ramm_id, eth_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(admin_address); let scenario = &mut scenario_val; test_scenario::next_tx(scenario, ALICE); @@ -85,14 +85,14 @@ module ramm_sui::liquidity_provision_fees_tests { // printing the RAMM's balances after each trade, if the trade's ordinal is a power of two { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); let eth_amnt = (10 * test_util::eth_factor() as u64); let usdt_amnt = (20_000 * test_util::usdt_factor() as u64); - let i: u64 = 1; + let mut i: u64 = 1; while (i <= max_iterations) { let amount_in = coin::mint_for_testing(eth_amnt, test_scenario::ctx(scenario)); interface2::trade_amount_in_2( @@ -140,7 +140,7 @@ module ramm_sui::liquidity_provision_fees_tests { test_scenario::next_tx(scenario, admin_address); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); @@ -200,7 +200,7 @@ module ramm_sui::liquidity_provision_fees_tests { test_scenario::next_tx(scenario, admin_address); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let admin_cap: RAMMAdminCap = test_scenario::take_from_address(scenario, admin_address); interface2::collect_fees_2( diff --git a/ramm-sui/tests/math_tests.move b/ramm-sui/tests/math_tests.move index 0bea09b..c561fee 100644 --- a/ramm-sui/tests/math_tests.move +++ b/ramm-sui/tests/math_tests.move @@ -206,10 +206,10 @@ module ramm_sui::math_tests { prices_decimal_places: u8, balances_decimal_places: u8 ): VecMap { - let balances = vec_map::empty(); - let prices = vec_map::empty(); - let factors_prices = vec_map::empty(); - let factors_balances = vec_map::empty(); + let mut balances = vec_map::empty(); + let mut prices = vec_map::empty(); + let mut factors_prices = vec_map::empty(); + let mut factors_balances = vec_map::empty(); vec_map::insert(&mut balances, 0, bal_0); vec_map::insert(&mut prices, 0, 1_800_000_000_000); @@ -280,11 +280,11 @@ module ramm_sui::math_tests { bal_2: u256, prices_decimal_places: u8, ): (VecMap, VecMap, VecMap, VecMap, VecMap,) { - let balances = vec_map::empty(); - let lp_tokens_issued = vec_map::empty(); - let prices = vec_map::empty(); - let factors_prices = vec_map::empty(); - let factors_balances = vec_map::empty(); + let mut balances = vec_map::empty(); + let mut lp_tokens_issued = vec_map::empty(); + let mut prices = vec_map::empty(); + let mut factors_prices = vec_map::empty(); + let mut factors_balances = vec_map::empty(); vec_map::insert(&mut balances, 0, bal_0); vec_map::insert(&mut lp_tokens_issued, 0, 200 * test_util::eth_factor()); @@ -598,7 +598,7 @@ module ramm_sui::math_tests { MAX_PRECISION_DECIMAL_PLACES, ); - let new_balances: VecMap = copy prev_balances; + let mut new_balances: VecMap = copy prev_balances; vec_map::remove(&mut new_balances, &i); vec_map::insert(&mut new_balances, i, new_eth); vec_map::remove(&mut new_balances, &o); @@ -720,7 +720,7 @@ module ramm_sui::math_tests { MAX_PRECISION_DECIMAL_PLACES, ); - let new_balances: VecMap = copy prev_balances; + let mut new_balances: VecMap = copy prev_balances; vec_map::remove(&mut new_balances, &i); vec_map::insert(&mut new_balances, i, new_eth); vec_map::remove(&mut new_balances, &o); @@ -841,7 +841,7 @@ module ramm_sui::math_tests { MAX_PRECISION_DECIMAL_PLACES, ); - let new_balances: VecMap = copy prev_balances; + let mut new_balances: VecMap = copy prev_balances; vec_map::remove(&mut new_balances, &i); vec_map::insert(&mut new_balances, i, new_usdt); vec_map::remove(&mut new_balances, &o); @@ -965,7 +965,7 @@ module ramm_sui::math_tests { MAX_PRECISION_DECIMAL_PLACES, ); - let new_balances: VecMap = copy prev_balances; + let mut new_balances: VecMap = copy prev_balances; vec_map::remove(&mut new_balances, &i); vec_map::insert(&mut new_balances, i, new_usdt); vec_map::remove(&mut new_balances, &o); @@ -1071,7 +1071,7 @@ module ramm_sui::math_tests { let new_usdt = 27_418_571 * test_util::usdt_factor() / 100; let ao: u256 = prev_usdt - new_usdt; - let (balances, lp_tokens_issued, prices, factors_prices, factors_balances) = + let (mut balances, lp_tokens_issued, prices, factors_prices, factors_balances) = imbalance_ratios(prev_eth, 200_000 * test_util::matic_factor(), prev_usdt, 9); let before_imbs = ramm_math::imbalance_ratios( diff --git a/ramm-sui/tests/ramm_tests.move b/ramm-sui/tests/ramm_tests.move index 2a66f5e..ca0eb18 100644 --- a/ramm-sui/tests/ramm_tests.move +++ b/ramm-sui/tests/ramm_tests.move @@ -26,7 +26,7 @@ module ramm_sui::ramm_tests { /// 2b. Share aggregator objects /// 3. Initialize the RAMM fun create_ramm() { - let scenario_val = test_scenario::begin(ADMIN); + let mut scenario_val = test_scenario::begin(ADMIN); let scenario = &mut scenario_val; // Check that the RAMM and caps don't yet exist before the RAMM's creation @@ -53,7 +53,7 @@ module ramm_sui::ramm_tests { { let admin_cap = test_scenario::take_from_address(scenario, ADMIN); let new_asset_cap = test_scenario::take_from_address(scenario, ADMIN); - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared(scenario); @@ -72,7 +72,7 @@ module ramm_sui::ramm_tests { // 2. initialize the RAMM, and // 3. check that the new_asset_cap used to add new objects no longer exists { - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); let admin_cap = test_scenario::take_from_address(scenario, ADMIN); let new_asset_cap = test_scenario::take_from_address(scenario, ADMIN); @@ -102,7 +102,7 @@ module ramm_sui::ramm_tests { /// 3. Add an asset (test BTC) to the RAMM /// 4. Verify the RAMM's internal state after the asset addition fun add_asset_to_ramm_tests() { - let scenario_val = test_scenario::begin(ADMIN); + let mut scenario_val = test_scenario::begin(ADMIN); let scenario = &mut scenario_val; // Create the RAMM @@ -120,7 +120,7 @@ module ramm_sui::ramm_tests { { let admin_cap = test_scenario::take_from_address(scenario, ADMIN); let new_asset_cap = test_scenario::take_from_address(scenario, ADMIN); - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared(scenario); @@ -177,7 +177,7 @@ module ramm_sui::ramm_tests { /// 4. Initialize the RAMM /// 5. Verify that its deposits are now enabled, and nothing else in its internal state changed fun check_deposit_status_after_init() { - let scenario_val = test_scenario::begin(ADMIN); + let mut scenario_val = test_scenario::begin(ADMIN); let scenario = &mut scenario_val; // Create RAMM @@ -192,7 +192,7 @@ module ramm_sui::ramm_tests { test_scenario::next_tx(scenario, ADMIN); { - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); let admin_cap = test_scenario::take_from_address(scenario, ADMIN); let new_asset_cap = test_scenario::take_from_address(scenario, ADMIN); @@ -267,7 +267,7 @@ module ramm_sui::ramm_tests { /// /// Useful for the tests below. fun double_create(): (ID, ID, test_scenario::Scenario) { - let scenario_val = test_scenario::begin(ALICE); + let mut scenario_val = test_scenario::begin(ALICE); let scenario = &mut scenario_val; // Create first RAMM @@ -297,11 +297,11 @@ module ramm_sui::ramm_tests { /// /// This *must* fail. fun add_asset_mismatched_admin_cap() { - let (_, bob_ramm_id, scenario_val) = double_create(); + let (_, bob_ramm_id, mut scenario_val) = double_create(); let scenario = &mut scenario_val; { - let bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); + let mut bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); let alice_admin_cap = test_scenario::take_from_address(scenario, ALICE); let alice_cap = test_scenario::take_from_address(scenario, ALICE); @@ -324,11 +324,11 @@ module ramm_sui::ramm_tests { /// /// This *must* fail. fun add_asset_mismatched_new_asset_cap() { - let (_, bob_ramm_id, scenario_val) = double_create(); + let (_, bob_ramm_id, mut scenario_val) = double_create(); let scenario = &mut scenario_val; { - let bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); + let mut bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); let bob_admin = test_scenario::take_from_address(scenario, BOB); let alice_cap = test_scenario::take_from_address(scenario, ALICE); @@ -352,7 +352,7 @@ module ramm_sui::ramm_tests { scenario: &mut test_scenario::Scenario ) { test_scenario::next_tx(scenario, sender); - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let admin = test_scenario::take_from_address(scenario, sender); let new_asset_cap = test_scenario::take_from_address(scenario, sender); let aggr = test_scenario::take_shared(scenario); @@ -369,7 +369,7 @@ module ramm_sui::ramm_tests { /// Create two test RAMMs with different owners, and then add the same asset /// to both. fun double_add_asset(): (ID, ID, test_scenario::Scenario) { - let (alice_ramm_id, bob_ramm_id, scenario_val) = double_create(); + let (alice_ramm_id, bob_ramm_id, mut scenario_val) = double_create(); let scenario = &mut scenario_val; add_asset_to_ramm(alice_ramm_id, ALICE, scenario); @@ -385,11 +385,11 @@ module ramm_sui::ramm_tests { /// /// This *must* fail. fun initialize_mismatch_admin_cap() { - let (_alice_ramm_id, bob_ramm_id, scenario_val) = double_add_asset(); + let (_alice_ramm_id, bob_ramm_id, mut scenario_val) = double_add_asset(); let scenario = &mut scenario_val; { - let bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); + let mut bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); let alice_admin_cap = test_scenario::take_from_address(scenario, ALICE); let alice_cap = test_scenario::take_from_address(scenario, ALICE); @@ -409,11 +409,11 @@ module ramm_sui::ramm_tests { /// /// This *must* fail. fun initialize_mismatch_new_asset_cap() { - let (_alice_ramm_id, bob_ramm_id, scenario_val) = double_add_asset(); + let (_alice_ramm_id, bob_ramm_id, mut scenario_val) = double_add_asset(); let scenario = &mut scenario_val; { - let bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); + let mut bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); let bob_admin_cap = test_scenario::take_from_address(scenario, BOB); let alice_new_asset_cap = test_scenario::take_from_address(scenario, ALICE); @@ -435,7 +435,7 @@ module ramm_sui::ramm_tests { ) { test_scenario::next_tx(scenario, sender); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let admin = test_scenario::take_from_address(scenario, sender); let new_asset_cap = test_scenario::take_from_address(scenario, sender); ramm::initialize_ramm(&mut ramm, &admin, new_asset_cap); @@ -446,7 +446,7 @@ module ramm_sui::ramm_tests { } fun double_initialize(): (ID, ID, test_scenario::Scenario) { - let (alice_ramm_id, bob_ramm_id, scenario_val) = double_add_asset(); + let (alice_ramm_id, bob_ramm_id, mut scenario_val) = double_add_asset(); let scenario = &mut scenario_val; initialize_ramm(alice_ramm_id, ALICE, scenario); @@ -459,10 +459,10 @@ module ramm_sui::ramm_tests { #[expected_failure(abort_code = ramm::ENotAdmin)] /// Check that setting a new fee collecting address with the wrong `RAMMAdminCap` will fail. fun set_fee_collector_admin_cap_mismatch() { - let (_alice_ramm_id, bob_ramm_id, scenario_val) = double_initialize(); + let (_alice_ramm_id, bob_ramm_id, mut scenario_val) = double_initialize(); let scenario = &mut scenario_val; { - let bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); + let mut bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); let alice_admin_cap = test_scenario::take_from_address(scenario, ALICE); ramm::set_fee_collector(&mut bob_ramm, &alice_admin_cap, ALICE); @@ -478,10 +478,10 @@ module ramm_sui::ramm_tests { #[expected_failure(abort_code = ramm::ENotAdmin)] /// Check that setting minimum trade amounts with the wrong `RAMMAdminCap` will fail. fun set_minimum_trade_amount_admin_cap_mismatch() { - let (_alice_ramm_id, bob_ramm_id, scenario_val) = double_initialize(); + let (_alice_ramm_id, bob_ramm_id, mut scenario_val) = double_initialize(); let scenario = &mut scenario_val; { - let bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); + let mut bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); let alice_admin_cap = test_scenario::take_from_address(scenario, ALICE); ramm::set_minimum_trade_amount(&mut bob_ramm, &alice_admin_cap, 1); @@ -496,7 +496,7 @@ module ramm_sui::ramm_tests { #[test] /// Check that setting minimum trade amounts works as intended. fun set_minimum_trade_amount_test() { - let scenario_val = test_scenario::begin(ADMIN); + let mut scenario_val = test_scenario::begin(ADMIN); let scenario = &mut scenario_val; let _aggr_id = test_util::create_write_share_aggregator(scenario, 2780245000000, 8, false, 100); @@ -512,7 +512,7 @@ module ramm_sui::ramm_tests { { let admin_cap = test_scenario::take_from_address(scenario, ADMIN); let new_asset_cap = test_scenario::take_from_address(scenario, ADMIN); - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared(scenario); @@ -545,7 +545,7 @@ module ramm_sui::ramm_tests { #[test] /// Check that changing the fee collection address works as intended. fun set_fee_collector_test() { - let scenario_val = test_scenario::begin(ADMIN); + let mut scenario_val = test_scenario::begin(ADMIN); let scenario = &mut scenario_val; // Create the RAMM @@ -557,7 +557,7 @@ module ramm_sui::ramm_tests { // Retrieve RAMM and caps from storage, and add above assets to it { let admin_cap = test_scenario::take_from_address(scenario, ADMIN); - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); test_utils::assert_eq(ramm::get_fee_collector(&ramm), ADMIN); ramm::set_fee_collector(&mut ramm, &admin_cap, ALICE); @@ -576,10 +576,10 @@ module ramm_sui::ramm_tests { #[expected_failure(abort_code = ramm::ENotAdmin)] /// Check that enabling deposits for an asset with the wrong `RAMMAdminCap` will fail. fun enable_deposits_admin_cap_mismatch() { - let (_alice_ramm_id, bob_ramm_id, scenario_val) = double_initialize(); + let (_alice_ramm_id, bob_ramm_id, mut scenario_val) = double_initialize(); let scenario = &mut scenario_val; { - let bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); + let mut bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); let alice_admin_cap = test_scenario::take_from_address(scenario, ALICE); ramm::enable_deposits(&mut bob_ramm, &alice_admin_cap); @@ -595,10 +595,10 @@ module ramm_sui::ramm_tests { #[expected_failure(abort_code = ramm::ENotAdmin)] /// Check that disabling deposits for an asset with the wrong `RAMMAdminCap` will fail. fun disable_deposits_admin_cap_mismatch() { - let (_alice_ramm_id, bob_ramm_id, scenario_val) = double_initialize(); + let (_alice_ramm_id, bob_ramm_id, mut scenario_val) = double_initialize(); let scenario = &mut scenario_val; { - let bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); + let mut bob_ramm = test_scenario::take_shared_by_id(scenario, bob_ramm_id); let alice_admin_cap = test_scenario::take_from_address(scenario, ALICE); ramm::disable_deposits(&mut bob_ramm, &alice_admin_cap); @@ -613,7 +613,7 @@ module ramm_sui::ramm_tests { #[test] /// Check that setting (enabling/disabling) deposit status works as intended. fun set_deposit_status_test() { - let scenario_val = test_scenario::begin(ADMIN); + let mut scenario_val = test_scenario::begin(ADMIN); let scenario = &mut scenario_val; let _aggr_id = test_util::create_write_share_aggregator(scenario, 2780245000000, 8, false, 100); @@ -629,7 +629,7 @@ module ramm_sui::ramm_tests { { let admin_cap = test_scenario::take_from_address(scenario, ADMIN); let new_asset_cap = test_scenario::take_from_address(scenario, ADMIN); - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared(scenario); @@ -663,7 +663,7 @@ module ramm_sui::ramm_tests { #[test] /// Check that setting a new address of an `Aggregator` works as intended. fun set_aggregator_address_test() { - let scenario_val = test_scenario::begin(ADMIN); + let mut scenario_val = test_scenario::begin(ADMIN); let scenario = &mut scenario_val; let fst_aggr_addr: address = @@ -687,7 +687,7 @@ module ramm_sui::ramm_tests { { let admin_cap = test_scenario::take_from_address(scenario, ADMIN); let new_asset_cap = test_scenario::take_from_address(scenario, ADMIN); - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); // Add the asset with the address of the first created aggregator. let btc_aggr = test_scenario::take_shared_by_id(scenario, object::id_from_address(fst_aggr_addr)); @@ -719,7 +719,7 @@ module ramm_sui::ramm_tests { #[test] /// Check that emitting an event with a pool's state works. fun get_pool_state_test() { - let (ramm_id, _, _, _, scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); + let (ramm_id, _, _, _, mut scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); let scenario = &mut scenario_val; test_scenario::next_tx(scenario, ALICE); diff --git a/ramm-sui/tests/test_util.move b/ramm-sui/tests/test_util.move index 62bb100..057bd77 100644 --- a/ramm-sui/tests/test_util.move +++ b/ramm-sui/tests/test_util.move @@ -19,24 +19,24 @@ module ramm_sui::test_util { use ramm_sui::math as ramm_math; use ramm_sui::ramm::{Self, RAMM, RAMMAdminCap, RAMMNewAssetCap}; - friend ramm_sui::interface2_safety_tests; - friend ramm_sui::interface2_oracle_safety_tests; - friend ramm_sui::interface2_tests; - friend ramm_sui::interface3_safety_tests; - friend ramm_sui::interface3_oracle_safety_tests; - friend ramm_sui::interface3_tests; - friend ramm_sui::liquidity_provision_fees_tests; - friend ramm_sui::math_tests; - friend ramm_sui::ramm_tests; - friend ramm_sui::volatility2_tests; - friend ramm_sui::volatility3_tests; + /* friend ramm_sui::interface2_safety_tests; */ + /* friend ramm_sui::interface2_oracle_safety_tests; */ + /* friend ramm_sui::interface2_tests; */ + /* friend ramm_sui::interface3_safety_tests; */ + /* friend ramm_sui::interface3_oracle_safety_tests; */ + /* friend ramm_sui::interface3_tests; */ + /* friend ramm_sui::liquidity_provision_fees_tests; */ + /* friend ramm_sui::math_tests; */ + /* friend ramm_sui::ramm_tests; */ + /* friend ramm_sui::volatility2_tests; */ + /* friend ramm_sui::volatility3_tests; */ /// ---------------- /// Useful operators /// ---------------- /// Check that the first operand is stricly less (`<`) than the second. - public(friend) fun assert_lt(t1: u256, t2: u256) { + public(package) fun assert_lt(t1: u256, t2: u256) { let res = t1 < t2; if (!res) { test_utils::print(b"Assertion failed:"); @@ -50,7 +50,7 @@ module ramm_sui::test_util { /// Compare two `u256`s up to a given `eps: u256`. /// /// If the numbers are farther apart than `eps`, the assertion fails. - public(friend) fun assert_eq_eps(t1: u256, t2: u256, eps: u256) { + public(package) fun assert_eq_eps(t1: u256, t2: u256, eps: u256) { let sub: u256; if (t1 > t2) { sub = t1 - t2; } else { sub = t2 - t1; }; if (!(sub <= eps)) { @@ -70,60 +70,60 @@ module ramm_sui::test_util { /// Coins used in testing - for coins to be using in the test*net*, see the `ramm-misc` package. /// -------------------------------------------------------------------------------------------- - struct BTC has drop {} - struct ETH has drop {} - struct MATIC has drop {} - struct SOL has drop {} - struct USDC has drop {} - struct USDT has drop {} + public struct BTC has drop {} + public struct ETH has drop {} + public struct MATIC has drop {} + public struct SOL has drop {} + public struct USDC has drop {} + public struct USDT has drop {} /// Decimal places of this module's BTC coin type. - public(friend) fun btc_dec_places(): u8 { + public(package) fun btc_dec_places(): u8 { 8 } /// Scaling factor for BTC coin type. - public(friend) fun btc_factor(): u256 { + public(package) fun btc_factor(): u256 { ramm_math::pow(10u256, btc_dec_places()) } /// Decimal places of this module's ETH coin type. - public(friend) fun eth_dec_places(): u8 { + public(package) fun eth_dec_places(): u8 { 8 } /// Scaling factor for ETH coin type. - public(friend) fun eth_factor(): u256 { + public(package) fun eth_factor(): u256 { ramm_math::pow(10u256, eth_dec_places()) } /// Decimal places of this module's SOL coin type. - public(friend) fun sol_dec_places(): u8 { + public(package) fun sol_dec_places(): u8 { 8 } /// Scaling factor for SOL coin type. - public(friend) fun sol_factor(): u256 { + public(package) fun sol_factor(): u256 { ramm_math::pow(10u256, sol_dec_places()) } /// Decimal places of this module's MATIC coin type. - public(friend) fun matic_dec_places(): u8 { + public(package) fun matic_dec_places(): u8 { 8 } /// Scaling factor for MATIC coin type. - public(friend) fun matic_factor(): u256 { + public(package) fun matic_factor(): u256 { ramm_math::pow(10u256, matic_dec_places()) } /// Decimal places of this module's USDT coin type. - public(friend) fun usdt_dec_places(): u8 { + public(package) fun usdt_dec_places(): u8 { 8 } /// Scaling factor for USDT coin type. - public(friend) fun usdt_factor(): u256 { + public(package) fun usdt_factor(): u256 { ramm_math::pow(10u256, usdt_dec_places()) } @@ -132,11 +132,11 @@ module ramm_sui::test_util { /// ---------------- /// For testing use only - one time witness for aggregator creation. - struct SecretKey has drop {} + public struct SecretKey has drop {} #[test_only] /// Create an `Aggregator` for testing - public(friend) fun create_aggregator_for_testing(ctx: &mut TxContext): Aggregator { + public(package) fun create_aggregator_for_testing(ctx: &mut TxContext): Aggregator { aggregator::new( b"test", // name @0x0, // queue_addr @@ -161,7 +161,7 @@ module ramm_sui::test_util { #[test_only] /// Set a test `Aggregator`'s value. - public(friend) fun set_aggregator_value( + public(package) fun set_aggregator_value( value: u128, // example the number 10 would be 10 * 10^dec (dec automatically scaled to 9) scale_factor: u8, // example 9 would be 10^9, 10 = 1000000000 negative: bool, // example -10 would be true @@ -184,7 +184,7 @@ module ramm_sui::test_util { /// Create an `Aggregator`, and populate it with the providede values. /// /// This function does not create a shared object, see `create_write_share_aggregator`. - public(friend) fun create_write_aggregator( + public(package) fun create_write_aggregator( scenario: &mut Scenario, val: u128, scale: u8, @@ -192,7 +192,7 @@ module ramm_sui::test_util { timestamp: u64 ): Aggregator { let ctx = test_scenario::ctx(scenario); - let aggr = create_aggregator_for_testing(ctx); + let mut aggr = create_aggregator_for_testing(ctx); set_aggregator_value(val, scale, neg, &mut aggr, timestamp, ctx); aggr } @@ -204,7 +204,7 @@ module ramm_sui::test_util { /// 2. populate it with the values passed as arguments to this function /// 3. Transform it into a shared object /// 4. Return its ID - public(friend) fun create_write_share_aggregator( + public(package) fun create_write_share_aggregator( scenario: &mut Scenario, val: u128, scale: u8, @@ -228,7 +228,7 @@ module ramm_sui::test_util { /// * minimum trade amounts for each asset /// * decimal places for each asset /// * per-asset liquidity (or its absence) - public(friend) fun create_populate_initialize_ramm_2_asset( + public(package) fun create_populate_initialize_ramm_2_asset( asset_prices: VecMap, asset_price_scales: VecMap, asset_minimum_trade_amounts: VecMap, @@ -236,7 +236,7 @@ module ramm_sui::test_util { initial_asset_liquidity: VecMap, sender: address ): (ID, ID, ID, test_scenario::Scenario) { - let scenario_val = test_scenario::begin(sender); + let mut scenario_val = test_scenario::begin(sender); let scenario = &mut scenario_val; // Create a clock for testing, and immediately share it to avoid @@ -272,7 +272,7 @@ module ramm_sui::test_util { // The pattern is the same - create the required aggregators, add their respective assets to // the RAMM, initialize it, etc let ramm_id = { - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); let clock = test_scenario::take_shared(scenario); let rid = object::id(&ramm); let admin_cap = test_scenario::take_from_address(scenario, sender); @@ -349,7 +349,7 @@ module ramm_sui::test_util { /// * minimum trade amounts for each asset /// * decimal places for each asset /// * per-asset liquidity (or its absence) - public(friend) fun create_populate_initialize_ramm_3_asset( + public(package) fun create_populate_initialize_ramm_3_asset( asset_prices: VecMap, asset_price_scales: VecMap, asset_minimum_trade_amounts: VecMap, @@ -357,7 +357,7 @@ module ramm_sui::test_util { initial_asset_liquidity: VecMap, sender: address ): (ID, ID, ID, ID, test_scenario::Scenario) { - let scenario_val = test_scenario::begin(sender); + let mut scenario_val = test_scenario::begin(sender); let scenario = &mut scenario_val; // Create a clock for testing, and immediately share it to avoid @@ -400,7 +400,7 @@ module ramm_sui::test_util { // The pattern is the same - create the required aggregators, add their respective assets to // the RAMM, initialize it, etc let ramm_id = { - let ramm = test_scenario::take_shared(scenario); + let mut ramm = test_scenario::take_shared(scenario); let clock = test_scenario::take_shared(scenario); let rid = object::id(&ramm); let admin_cap = test_scenario::take_from_address(scenario, sender); @@ -506,22 +506,22 @@ module ramm_sui::test_util { /// * a 2-asset BTC/ETH RAMM /// * valid prices and aggregators, and /// * per-asset starting liquidity specified in a `VecMap` argument - public(friend) fun create_ramm_test_scenario_btc_eth( + public(package) fun create_ramm_test_scenario_btc_eth( sender: address, initial_asset_liquidity: VecMap ): (ID, ID, ID, test_scenario::Scenario) { - let asset_prices: VecMap = vec_map::empty(); + let mut asset_prices: VecMap = vec_map::empty(); vec_map::insert(&mut asset_prices, 0, 27_800_000000000); vec_map::insert(&mut asset_prices, 1, 1_880_000000000); - let asset_price_scales: VecMap = vec_map::empty(); + let mut asset_price_scales: VecMap = vec_map::empty(); vec_map::insert(&mut asset_price_scales, 0, 9); vec_map::insert(&mut asset_price_scales, 1, 9); - let asset_minimum_trade_amounts: VecMap = vec_map::empty(); + let mut asset_minimum_trade_amounts: VecMap = vec_map::empty(); // min trade amount for BTC is 0.0001 BTC vec_map::insert(&mut asset_minimum_trade_amounts, 0, (btc_factor() / 10000 as u64)); // min trade amount for ETH is 0.001 ETH vec_map::insert(&mut asset_minimum_trade_amounts, 1, (eth_factor() / 1000 as u64)); - let asset_decimal_places: VecMap = vec_map::empty(); + let mut asset_decimal_places: VecMap = vec_map::empty(); vec_map::insert(&mut asset_decimal_places, 0, 8); vec_map::insert(&mut asset_decimal_places, 1, 8); @@ -540,9 +540,9 @@ module ramm_sui::test_util { /// * a 2-asset BTC/ETH RAMM /// * valid prices and aggregators, and /// * 1000 units of starting liquidity in all assets - public(friend) fun create_ramm_test_scenario_btc_eth_with_liq(sender: address) + public(package) fun create_ramm_test_scenario_btc_eth_with_liq(sender: address) : (ID, ID, ID, test_scenario::Scenario) { - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, (1000 * btc_factor() as u64)); vec_map::insert(&mut initial_asset_liquidity, 1, (1000 * eth_factor() as u64)); @@ -557,9 +557,9 @@ module ramm_sui::test_util { /// * a 2-asset BTC/ETH RAMM /// * valid prices and aggregators, and /// * no starting liquidity - public(friend) fun create_ramm_test_scenario_btc_eth_no_liq(sender: address) + public(package) fun create_ramm_test_scenario_btc_eth_no_liq(sender: address) : (ID, ID, ID, test_scenario::Scenario) { - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, 0); vec_map::insert(&mut initial_asset_liquidity, 1, 0); @@ -581,23 +581,23 @@ module ramm_sui::test_util { /// 1. the ID of the created RAMM /// 2. the IDs of the created aggregators in the order their assets were added to the RAMM, and /// 3. the populated test scenario. - public(friend) fun create_ramm_test_scenario_btc_eth_sol( + public(package) fun create_ramm_test_scenario_btc_eth_sol( sender: address, initial_asset_liquidity: VecMap ): (ID, ID, ID, ID, test_scenario::Scenario) { - let asset_prices: VecMap = vec_map::empty(); + let mut asset_prices: VecMap = vec_map::empty(); vec_map::insert(&mut asset_prices, 0, 27_800_000000000); vec_map::insert(&mut asset_prices, 1, 1_880_000000000); vec_map::insert(&mut asset_prices, 2, 20_000000000); - let asset_price_scales: VecMap = vec_map::empty(); + let mut asset_price_scales: VecMap = vec_map::empty(); vec_map::insert(&mut asset_price_scales, 0, 9); vec_map::insert(&mut asset_price_scales, 1, 9); vec_map::insert(&mut asset_price_scales, 2, 9); - let asset_minimum_trade_amounts: VecMap = vec_map::empty(); + let mut asset_minimum_trade_amounts: VecMap = vec_map::empty(); vec_map::insert(&mut asset_minimum_trade_amounts, 0, (btc_factor() / 10000 as u64)); vec_map::insert(&mut asset_minimum_trade_amounts, 1, (eth_factor() / 1000 as u64)); vec_map::insert(&mut asset_minimum_trade_amounts, 2, (sol_factor() / 10 as u64)); - let asset_decimal_places: VecMap = vec_map::empty(); + let mut asset_decimal_places: VecMap = vec_map::empty(); vec_map::insert(&mut asset_decimal_places, 0, 8); vec_map::insert(&mut asset_decimal_places, 1, 8); vec_map::insert(&mut asset_decimal_places, 2, 8); @@ -618,10 +618,10 @@ module ramm_sui::test_util { /// 1. 10 BTC /// 2. 100 ETH /// 3. 10000 SOL - public(friend) fun create_ramm_test_scenario_btc_eth_sol_with_liq( + public(package) fun create_ramm_test_scenario_btc_eth_sol_with_liq( sender: address, ): (ID, ID, ID, ID, test_scenario::Scenario) { - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, (10 * btc_factor() as u64)); vec_map::insert(&mut initial_asset_liquidity, 1, (100 * eth_factor() as u64)); vec_map::insert(&mut initial_asset_liquidity, 2, (10000 * sol_factor() as u64)); @@ -635,10 +635,10 @@ module ramm_sui::test_util { #[test_only] /// Does the same as `create_ramm_test_scenario_btc_eth_sol`, without initial liquidity /// for any of the BTC/ETH/SOL assets in the RAMM. - public(friend) fun create_ramm_test_scenario_btc_eth_sol_no_liq( + public(package) fun create_ramm_test_scenario_btc_eth_sol_no_liq( sender: address, ): (ID, ID, ID, ID, test_scenario::Scenario) { - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, 0); vec_map::insert(&mut initial_asset_liquidity, 1, 0); vec_map::insert(&mut initial_asset_liquidity, 2, 0); @@ -656,20 +656,20 @@ module ramm_sui::test_util { #[test_only] /// Create an ETH/USDT pool with the parameters from the whitepaper's second /// practical example. - public(friend) fun create_ramm_test_scenario_eth_usdt(sender: address): (ID, ID, ID, Scenario) { - let asset_prices: VecMap = vec_map::empty(); + public(package) fun create_ramm_test_scenario_eth_usdt(sender: address): (ID, ID, ID, Scenario) { + let mut asset_prices: VecMap = vec_map::empty(); vec_map::insert(&mut asset_prices, 0, 2_000_000000000); vec_map::insert(&mut asset_prices, 1, 1_000000000); - let asset_price_scales: VecMap = vec_map::empty(); + let mut asset_price_scales: VecMap = vec_map::empty(); vec_map::insert(&mut asset_price_scales, 0, 9); vec_map::insert(&mut asset_price_scales, 1, 9); - let asset_minimum_trade_amounts: VecMap = vec_map::empty(); + let mut asset_minimum_trade_amounts: VecMap = vec_map::empty(); vec_map::insert(&mut asset_minimum_trade_amounts, 0, 1 * (eth_factor() as u64) / 1000); vec_map::insert(&mut asset_minimum_trade_amounts, 1, 1 * (usdt_factor() as u64)); - let asset_decimal_places: VecMap = vec_map::empty(); + let mut asset_decimal_places: VecMap = vec_map::empty(); vec_map::insert(&mut asset_decimal_places, 0, eth_dec_places()); vec_map::insert(&mut asset_decimal_places, 1, usdt_dec_places()); - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, 500 * (eth_factor() as u64)); vec_map::insert(&mut initial_asset_liquidity, 1, 900_000 * (usdt_factor() as u64)); @@ -686,24 +686,24 @@ module ramm_sui::test_util { #[test_only] /// Create an ETH/MATIC/USDT pool with the parameters from the whitepaper's first /// practical example. - public(friend) fun create_ramm_test_scenario_eth_matic_usdt(sender: address): (ID, ID, ID, ID, Scenario) { - let asset_prices: VecMap = vec_map::empty(); + public(package) fun create_ramm_test_scenario_eth_matic_usdt(sender: address): (ID, ID, ID, ID, Scenario) { + let mut asset_prices: VecMap = vec_map::empty(); vec_map::insert(&mut asset_prices, 0, 1_800_000000000); vec_map::insert(&mut asset_prices, 1, 1_200000000); vec_map::insert(&mut asset_prices, 2, 1_000000000); - let asset_price_scales: VecMap = vec_map::empty(); + let mut asset_price_scales: VecMap = vec_map::empty(); vec_map::insert(&mut asset_price_scales, 0, 9); vec_map::insert(&mut asset_price_scales, 1, 9); vec_map::insert(&mut asset_price_scales, 2, 9); - let asset_minimum_trade_amounts: VecMap = vec_map::empty(); + let mut asset_minimum_trade_amounts: VecMap = vec_map::empty(); vec_map::insert(&mut asset_minimum_trade_amounts, 0, 1 * (eth_factor() as u64) / 1000); vec_map::insert(&mut asset_minimum_trade_amounts, 1, 1 * (matic_factor() as u64)); vec_map::insert(&mut asset_minimum_trade_amounts, 2, 1 * (usdt_factor() as u64)); - let asset_decimal_places: VecMap = vec_map::empty(); + let mut asset_decimal_places: VecMap = vec_map::empty(); vec_map::insert(&mut asset_decimal_places, 0, eth_dec_places()); vec_map::insert(&mut asset_decimal_places, 1, matic_dec_places()); vec_map::insert(&mut asset_decimal_places, 2, usdt_dec_places()); - let initial_asset_liquidity: VecMap = vec_map::empty(); + let mut initial_asset_liquidity: VecMap = vec_map::empty(); vec_map::insert(&mut initial_asset_liquidity, 0, 200 * (eth_factor() as u64)); vec_map::insert(&mut initial_asset_liquidity, 1, 200_000 * (matic_factor() as u64)); vec_map::insert(&mut initial_asset_liquidity, 2, 400_000 * (usdt_factor() as u64)); diff --git a/ramm-sui/tests/volatility2_tests.move b/ramm-sui/tests/volatility2_tests.move index d6cf1f7..fa4d490 100644 --- a/ramm-sui/tests/volatility2_tests.move +++ b/ramm-sui/tests/volatility2_tests.move @@ -39,7 +39,7 @@ module ramm_sui::volatility2_tests { /// - 0.1% base trading fee /// - protocol fee is 30% of the total, so 3.03% fun trade_amount_in_2_volatility_test() { - let (ramm_id, eth_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); + let (ramm_id, eth_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); let scenario = &mut scenario_val; // First part of the test: the RAMM's admin, who also happens to have administrative rights @@ -49,8 +49,8 @@ module ramm_sui::volatility2_tests { { let clock = test_scenario::take_shared(scenario); - let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); - let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); + let mut eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); + let mut usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); let current_timestamp: u64 = clock::timestamp_ms(&clock); @@ -106,7 +106,7 @@ module ramm_sui::volatility2_tests { test_scenario::next_tx(scenario, ALICE); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); @@ -220,7 +220,7 @@ module ramm_sui::volatility2_tests { /// - 0.1% base trading fee /// - protocol fee is 30% of the total, so 3.03% fun trade_amount_out_2_volatility_test() { - let (ramm_id, eth_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); + let (ramm_id, eth_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); let scenario = &mut scenario_val; // First part of the test: the RAMM's admin, who also happens to have administrative rights @@ -230,8 +230,8 @@ module ramm_sui::volatility2_tests { { let clock = test_scenario::take_shared(scenario); - let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); - let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); + let mut eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); + let mut usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); let current_timestamp: u64 = clock::timestamp_ms(&clock); @@ -290,7 +290,7 @@ module ramm_sui::volatility2_tests { // from the ETH/USDT RAMM, with the new price of 2100 USDT per ETH. test_scenario::next_tx(scenario, ALICE); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); @@ -411,15 +411,15 @@ module ramm_sui::volatility2_tests { /// Inbound/outbound deposit*LP token amounts should not be affected by volatility, but they should /// still update the RAMM's internal volatility data after each asset's respective oracle query. fun liquidity_deposit_2_volatility_test() { - let (ramm_id, btc_ag_id, eth_ag_id, scenario_val) = test_util::create_ramm_test_scenario_btc_eth_no_liq(ADMIN); + let (ramm_id, btc_ag_id, eth_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_no_liq(ADMIN); let scenario = &mut scenario_val; test_scenario::next_tx(scenario, ADMIN); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); - let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); - let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); + let mut btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); + let mut eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let current_timestamp: u64 = clock::timestamp_ms(&clock); @@ -591,7 +591,7 @@ module ramm_sui::volatility2_tests { /// - 5% volatility for outbound asset, plus /// - 0.4% base liquidity withdrawal fee fun liquidity_withdrawal_2_volatility_test() { - let (ramm_id, eth_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); + let (ramm_id, eth_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_usdt(ADMIN); let scenario = &mut scenario_val; // First part of the test: the RAMM's admin, who also happens to have administrative rights @@ -601,8 +601,8 @@ module ramm_sui::volatility2_tests { { let clock = test_scenario::take_shared(scenario); - let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); - let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); + let mut eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); + let mut usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); let current_timestamp: u64 = clock::timestamp_ms(&clock); @@ -660,7 +660,7 @@ module ramm_sui::volatility2_tests { test_scenario::next_tx(scenario, ADMIN); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); diff --git a/ramm-sui/tests/volatility3_tests.move b/ramm-sui/tests/volatility3_tests.move index fae5a1d..328a25f 100644 --- a/ramm-sui/tests/volatility3_tests.move +++ b/ramm-sui/tests/volatility3_tests.move @@ -42,7 +42,7 @@ module ramm_sui::volatility3_tests { /// The uninvolved asset's volatility should not affect the result, but should still lead /// to an update of that asset's volatility data. fun trade_amount_in_3_volatility_test() { - let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); + let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); let scenario = &mut scenario_val; // First part of the test: the RAMM's admin, who also happens to have administrative rights @@ -52,9 +52,9 @@ module ramm_sui::volatility3_tests { { let clock = test_scenario::take_shared(scenario); - let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); - let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); - let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); + let mut eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); + let mut matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); + let mut usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); let current_timestamp: u64 = clock::timestamp_ms(&clock); @@ -130,7 +130,7 @@ module ramm_sui::volatility3_tests { test_scenario::next_tx(scenario, ALICE); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); @@ -252,7 +252,7 @@ module ramm_sui::volatility3_tests { /// The uninvolved asset's volatility should not affect the result, but its pricing/volatility /// data should still be updated. fun trade_amount_out_3_volatility_test() { - let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); + let (ramm_id, eth_ag_id, matic_ag_id, usdt_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_eth_matic_usdt(ADMIN); let scenario = &mut scenario_val; // First part of the test: the RAMM's admin, who also happens to have administrative rights @@ -262,9 +262,9 @@ module ramm_sui::volatility3_tests { { let clock = test_scenario::take_shared(scenario); - let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); - let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); - let usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); + let mut eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); + let mut matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); + let mut usdt_aggr = test_scenario::take_shared_by_id(scenario, usdt_ag_id); let current_timestamp: u64 = clock::timestamp_ms(&clock); @@ -343,7 +343,7 @@ module ramm_sui::volatility3_tests { // from the ETH/USDT RAMM, with the new price of 1960 USDT per ETH. test_scenario::next_tx(scenario, ALICE); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); let matic_aggr = test_scenario::take_shared_by_id(scenario, matic_ag_id); @@ -469,16 +469,16 @@ module ramm_sui::volatility3_tests { /// /// The uninvolved assets' volatility/pricing should also be updated. fun liquidity_deposit_3_volatility_test() { - let (ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ADMIN); + let (ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_no_liq(ADMIN); let scenario = &mut scenario_val; test_scenario::next_tx(scenario, ADMIN); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); - let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); - let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); - let sol_aggr = test_scenario::take_shared_by_id(scenario, sol_ag_id); + let mut btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); + let mut eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); + let mut sol_aggr = test_scenario::take_shared_by_id(scenario, sol_ag_id); let current_timestamp: u64 = clock::timestamp_ms(&clock); @@ -690,7 +690,7 @@ module ramm_sui::volatility3_tests { /// - 5% volatility for outbound asset, plus /// - 0.4% base liquidity withdrawal fee fun liquidity_withdrawal_3_volatility_test() { - let (ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ADMIN); + let (ramm_id, btc_ag_id, eth_ag_id, sol_ag_id, mut scenario_val) = test_util::create_ramm_test_scenario_btc_eth_sol_with_liq(ADMIN); let scenario = &mut scenario_val; // First part of the test: the RAMM's admin, who also happens to have administrative rights @@ -700,9 +700,9 @@ module ramm_sui::volatility3_tests { { let clock = test_scenario::take_shared(scenario); - let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); - let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); - let sol_aggr = test_scenario::take_shared_by_id(scenario, sol_ag_id); + let mut btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); + let mut eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); + let mut sol_aggr = test_scenario::take_shared_by_id(scenario, sol_ag_id); let current_timestamp: u64 = clock::timestamp_ms(&clock); @@ -779,7 +779,7 @@ module ramm_sui::volatility3_tests { test_scenario::next_tx(scenario, ADMIN); { - let ramm = test_scenario::take_shared_by_id(scenario, ramm_id); + let mut ramm = test_scenario::take_shared_by_id(scenario, ramm_id); let clock = test_scenario::take_shared(scenario); let btc_aggr = test_scenario::take_shared_by_id(scenario, btc_ag_id); let eth_aggr = test_scenario::take_shared_by_id(scenario, eth_ag_id); From f00d49bf93469e778c8f198b26a0312e41d23a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9=20=28WSL=20Win11=20Pro=29?= Date: Thu, 18 Apr 2024 00:35:49 +0100 Subject: [PATCH 3/6] Rebuild `Move.lock` file --- ramm-sui/Move.lock | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ramm-sui/Move.lock diff --git a/ramm-sui/Move.lock b/ramm-sui/Move.lock new file mode 100644 index 0000000..29ecb0b --- /dev/null +++ b/ramm-sui/Move.lock @@ -0,0 +1,37 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 1 +manifest_digest = "DEB875FBA47B190BDFA78409585FBEF193587B3C4165F49EA7519C7C45116102" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +dependencies = [ + { name = "MoveStdlib" }, + { name = "Sui" }, + { name = "SwitchboardStdLib" }, +] + +[[move.package]] +name = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +name = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "mainnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { name = "MoveStdlib" }, +] + +[[move.package]] +name = "SwitchboardStdLib" +source = { git = "https://github.com/switchboard-xyz/sbv2-sui.git", rev = "main", subdir = "move/mainnet/switchboard_std/" } + +dependencies = [ + { name = "MoveStdlib" }, + { name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.22.0" +edition = "legacy" +flavor = "sui" From 26b9897a8ef1912c4126854f51884130b28777ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9=20=28WSL=20Win11=20Pro=29?= Date: Sat, 20 Apr 2024 17:03:04 +0100 Subject: [PATCH 4/6] Delete `Move.lock` as prelude to migration --- ramm-misc/Move.lock | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 ramm-misc/Move.lock diff --git a/ramm-misc/Move.lock b/ramm-misc/Move.lock deleted file mode 100644 index 818efb3..0000000 --- a/ramm-misc/Move.lock +++ /dev/null @@ -1,38 +0,0 @@ -# @generated by Move, please check-in and do not edit manually. - -[move] -version = 0 -manifest_digest = "5A89B8E8F764B52614AE57B04BAE162EFD7C96F2E8074906D90E7309A04DCC14" -deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" - -dependencies = [ - { name = "MoveStdlib" }, - { name = "Sui" }, - { name = "SwitchboardStdLib" }, -] - -[[move.package]] -name = "MoveStdlib" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet", subdir = "crates/sui-framework/packages/move-stdlib" } - -[[move.package]] -name = "Sui" -source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet", subdir = "crates/sui-framework/packages/sui-framework" } - -dependencies = [ - { name = "MoveStdlib" }, -] - -[[move.package]] -name = "SwitchboardStdLib" -source = { git = "https://github.com/switchboard-xyz/sbv2-sui.git", rev = "main", subdir = "move/testnet/switchboard_std/" } - -dependencies = [ - { name = "MoveStdlib" }, - { name = "Sui" }, -] - -[move.toolchain-version] -compiler-version = "1.19.1" -edition = "legacy" -flavor = "sui" From 9f255e523b821ca1ac237da1370e82989f5f4692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9=20=28WSL=20Win11=20Pro=29?= Date: Sat, 20 Apr 2024 17:03:18 +0100 Subject: [PATCH 5/6] Execute `sui move migrate` --- ramm-misc/Move.toml | 3 ++- .../sources/switchboard_feed_parser.move | 2 +- ramm-misc/sources/test_coin_faucet.move | 2 +- ramm-misc/sources/test_coins.move | 20 +++++++++---------- ramm-misc/tests/coin_bag.move | 6 +++--- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ramm-misc/Move.toml b/ramm-misc/Move.toml index 3fb3495..bc27c53 100644 --- a/ramm-misc/Move.toml +++ b/ramm-misc/Move.toml @@ -1,6 +1,7 @@ [package] name = "ramm_misc" version = "0.0.1" +edition = "2024.beta" [dependencies] Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "testnet" } @@ -11,4 +12,4 @@ SwitchboardStdLib = { git = "https://github.com/switchboard-xyz/sbv2-sui.git", s ramm_misc = "0x0" std = "0x1" sui = "0x2" -switchboard = "0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e" \ No newline at end of file +switchboard = "0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e" diff --git a/ramm-misc/sources/switchboard_feed_parser.move b/ramm-misc/sources/switchboard_feed_parser.move index c9e5c8d..c892e75 100644 --- a/ramm-misc/sources/switchboard_feed_parser.move +++ b/ramm-misc/sources/switchboard_feed_parser.move @@ -17,7 +17,7 @@ module ramm_misc::switchboard_feed_parser { where decimal = neg * value * 10^(-1 * dec) */ - struct AggregatorInfo has store, key { + public struct AggregatorInfo has store, key { id: UID, aggregator_addr: address, latest_result: u128, diff --git a/ramm-misc/sources/test_coin_faucet.move b/ramm-misc/sources/test_coin_faucet.move index a61aac7..4a6a92e 100644 --- a/ramm-misc/sources/test_coin_faucet.move +++ b/ramm-misc/sources/test_coin_faucet.move @@ -13,7 +13,7 @@ module ramm_misc::test_coin_faucet { const ENonexistentCoinType: u64 = 0; - struct Faucet has key { + public struct Faucet has key { id: UID, coins: Bag, creator: address, diff --git a/ramm-misc/sources/test_coins.move b/ramm-misc/sources/test_coins.move index 962dfa0..968799f 100644 --- a/ramm-misc/sources/test_coins.move +++ b/ramm-misc/sources/test_coins.move @@ -5,23 +5,23 @@ module ramm_misc::test_coins { use sui::balance; use sui::tx_context::TxContext; - friend ramm_misc::test_coin_faucet; + /* friend ramm_misc::test_coin_faucet; */ // These coins below are the only ones for which a Switchboard Testnet feed exists // as of 2024-01-22. - struct USDT has drop {} - struct USDC has drop {} - struct ETH has drop {} - struct BTC has drop {} - struct SOL has drop {} - struct DOT has drop {} - struct ADA has drop {} + public struct USDT has drop {} + public struct USDC has drop {} + public struct ETH has drop {} + public struct BTC has drop {} + public struct SOL has drop {} + public struct DOT has drop {} + public struct ADA has drop {} //struct SUI has drop {} /// For every currently available `Aggregator` in the Sui testnet, create a `Supply` for it, /// control of which will belong to this package's publisher. See `ramm_misc::faucet::init()`. - public(friend) fun create_test_coin_suplies(ctx: &mut TxContext): Bag { - let coins = bag::new(ctx); + public(package) fun create_test_coin_suplies(ctx: &mut TxContext): Bag { + let mut coins = bag::new(ctx); bag::add(&mut coins, (type_name::get()), balance::create_supply(USDT {})); bag::add(&mut coins, (type_name::get()), balance::create_supply(USDC {})); diff --git a/ramm-misc/tests/coin_bag.move b/ramm-misc/tests/coin_bag.move index 8851076..adbd8e5 100644 --- a/ramm-misc/tests/coin_bag.move +++ b/ramm-misc/tests/coin_bag.move @@ -21,7 +21,7 @@ module ramm_misc::coin_bag { #[test] fun test_bag() { - let new_scenario = test_scenario::begin(ADDRESS); + let mut new_scenario = test_scenario::begin(ADDRESS); let scenario = &mut new_scenario; let ctx = test_scenario::ctx(scenario); @@ -31,7 +31,7 @@ module ramm_misc::coin_bag { let usdc = coin::mint_for_testing(amount * 3, ctx); let eth = coin::mint_for_testing(amount * 4, ctx); - let bag = bag::new(ctx); + let mut bag = bag::new(ctx); test_scenario::next_tx(scenario, ADDRESS); bag::add>(&mut bag, 0, btc); @@ -39,7 +39,7 @@ module ramm_misc::coin_bag { bag::add>(&mut bag, 2, eth); bag::add>(&mut bag, 3, usdc); - let amnt: u64 = 0; + let mut amnt: u64 = 0; let btc = bag::remove>(&mut bag, 0); amnt = amnt + coin::burn_for_testing(btc); From c86bfdb7daab24b0e98f052b4c5824f37f3a5d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bald=C3=A9=20=28WSL=20Win11=20Pro=29?= Date: Sat, 20 Apr 2024 17:03:41 +0100 Subject: [PATCH 6/6] Rebuild `Move.lock` by running `sui move build` --- ramm-misc/Move.lock | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ramm-misc/Move.lock diff --git a/ramm-misc/Move.lock b/ramm-misc/Move.lock new file mode 100644 index 0000000..9ca7bf5 --- /dev/null +++ b/ramm-misc/Move.lock @@ -0,0 +1,37 @@ +# @generated by Move, please check-in and do not edit manually. + +[move] +version = 1 +manifest_digest = "B60B9767384B4488DCEB014F8CD337366AD318F3A833A3074496141AF33EC065" +deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3" +dependencies = [ + { name = "MoveStdlib" }, + { name = "Sui" }, + { name = "SwitchboardStdLib" }, +] + +[[move.package]] +name = "MoveStdlib" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet", subdir = "crates/sui-framework/packages/move-stdlib" } + +[[move.package]] +name = "Sui" +source = { git = "https://github.com/MystenLabs/sui.git", rev = "testnet", subdir = "crates/sui-framework/packages/sui-framework" } + +dependencies = [ + { name = "MoveStdlib" }, +] + +[[move.package]] +name = "SwitchboardStdLib" +source = { git = "https://github.com/switchboard-xyz/sbv2-sui.git", rev = "main", subdir = "move/testnet/switchboard_std/" } + +dependencies = [ + { name = "MoveStdlib" }, + { name = "Sui" }, +] + +[move.toolchain-version] +compiler-version = "1.22.0" +edition = "legacy" +flavor = "sui"