diff --git a/Cargo.lock b/Cargo.lock index 5750738..0d6c4b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2314,7 +2314,7 @@ dependencies = [ [[package]] name = "ref-exchange" -version = "1.5.2" +version = "1.5.3" dependencies = [ "near-contract-standards", "near-sdk", @@ -2721,7 +2721,7 @@ dependencies = [ [[package]] name = "test-rated-token" -version = "0.1.1" +version = "0.1.2" dependencies = [ "near-contract-standards", "near-sdk", diff --git a/ref-exchange/Cargo.toml b/ref-exchange/Cargo.toml index de24f91..be38566 100644 --- a/ref-exchange/Cargo.toml +++ b/ref-exchange/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ref-exchange" -version = "1.5.2" +version = "1.5.3" authors = ["Illia Polosukhin "] edition = "2018" publish = false diff --git a/ref-exchange/release_notes.md b/ref-exchange/release_notes.md index 78b14aa..ea827c5 100644 --- a/ref-exchange/release_notes.md +++ b/ref-exchange/release_notes.md @@ -1,5 +1,10 @@ # Release Notes +### Version 1.5.3 +1. Support nearx in rated stable pool; +2. Add check when initializing simple pool liquidity +3. Add ERR36_SHARES_TOTAL_SUPPLY_OVERFLOW + ### Version 1.5.2 1. Lower MIN_RESERVE to 1*10**15; diff --git a/ref-exchange/src/errors.rs b/ref-exchange/src/errors.rs index 7154f55..dcb04a0 100644 --- a/ref-exchange/src/errors.rs +++ b/ref-exchange/src/errors.rs @@ -33,6 +33,7 @@ pub const ERR32_ZERO_SHARES: &str = "E32: minting zero shares"; pub const ERR33_TRANSFER_TO_SELF: &str = "E33: transfer to self"; pub const ERR34_INSUFFICIENT_LP_SHARES: &str = "E34: insufficient lp shares"; pub const ERR35_AT_LEAST_ONE_YOCTO: &str = "E35: requires attached deposit of at least 1 yoctoNEAR"; +pub const ERR36_SHARES_TOTAL_SUPPLY_OVERFLOW: &str = "E36: shares_total_supply overflow"; // Action result. diff --git a/ref-exchange/src/lib.rs b/ref-exchange/src/lib.rs index a80e25a..57a2895 100644 --- a/ref-exchange/src/lib.rs +++ b/ref-exchange/src/lib.rs @@ -781,6 +781,62 @@ mod tests { assert_eq!(amounts[1].0 + deposit2, to_yocto("100")); } + #[test] + #[should_panic(expected = "E31: adding zero amount")] + fn test_init_zero_liquidity() { + let (mut context, mut contract) = setup_contract(); + deposit_tokens( + &mut context, + &mut contract, + accounts(3), + vec![ + (accounts(1), to_yocto("1000000")), + (accounts(2), to_yocto("1000000")), + ], + ); + testing_env!(context + .predecessor_account_id(accounts(3)) + .attached_deposit(to_yocto("1")) + .build()); + let id0 = contract.add_simple_pool(vec![accounts(1), accounts(2)], 1); + testing_env!(context.attached_deposit(to_yocto("0.0007")).build()); + contract.add_liquidity(id0, vec![U128(0), U128(0)], None); + } + + #[test] + #[should_panic(expected = "E36: shares_total_supply overflow")] + fn test_shares_total_supply_overflow() { + let (mut context, mut contract) = setup_contract(); + deposit_tokens( + &mut context, + &mut contract, + accounts(3), + vec![ + (accounts(1), to_yocto("1000000")), + (accounts(2), to_yocto("1000000")), + ], + ); + testing_env!(context + .predecessor_account_id(accounts(3)) + .attached_deposit(to_yocto("1")) + .build()); + let id0 = contract.add_simple_pool(vec![accounts(1), accounts(2)], 1); + testing_env!(context.attached_deposit(to_yocto("0.0007")).build()); + contract.add_liquidity(id0, vec![U128(4801823983302), U128(14399)], None); + testing_env!(context.attached_deposit(to_yocto("0.0007")).build()); + contract.add_liquidity(id0, vec![U128(340282366920167 * 4801823983302), U128(340282366920167 * 14399)], None); + contract.swap( + vec![SwapAction { + pool_id: 0, + token_in: accounts(1).into(), + amount_in: Some(U128(12446461932933863316530306u128)), + token_out: accounts(2).into(), + min_amount_out: U128(0), + }], + None, + ); + } + /// Should deny creating a pool with duplicate tokens. #[test] #[should_panic(expected = "E92: token duplicated")] diff --git a/ref-exchange/src/rated_swap/mod.rs b/ref-exchange/src/rated_swap/mod.rs index da19145..8747849 100644 --- a/ref-exchange/src/rated_swap/mod.rs +++ b/ref-exchange/src/rated_swap/mod.rs @@ -17,6 +17,7 @@ mod math; pub mod rate; mod stnear_rate; mod linear_rate; +mod nearx_rate; pub const TARGET_DECIMAL: u8 = 24; pub const MIN_DECIMAL: u8 = 1; diff --git a/ref-exchange/src/rated_swap/nearx_rate.rs b/ref-exchange/src/rated_swap/nearx_rate.rs new file mode 100644 index 0000000..87e8835 --- /dev/null +++ b/ref-exchange/src/rated_swap/nearx_rate.rs @@ -0,0 +1,61 @@ +use super::{rate::RateTrait, PRECISION}; +use crate::errors::ERR126_FAILED_TO_PARSE_RESULT; +use crate::utils::{GAS_FOR_BASIC_OP, NO_DEPOSIT}; +use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::{ + env, ext_contract, json_types::U128, serde_json::from_slice, AccountId, Balance, Promise, +}; + +// default expire time is 24 hours +const EXPIRE_TS: u64 = 24 * 3600 * 10u64.pow(9); + +#[derive(BorshSerialize, BorshDeserialize, Clone)] +pub struct NearxRate { + /// * + pub stored_rates: Balance, + /// * + pub rates_updated_at: u64, + /// * + pub contract_id: AccountId, +} + +#[ext_contract(ext_nearx)] +pub trait ExtNearx { + //https://github.com/stader-labs/near-liquid-token/blob/1420b7ceb2cd28577f9e89481a98280d8d13739c/contracts/near-x/src/contract/public.rs#L427 + fn get_nearx_price(&self) -> U128; +} + +impl RateTrait for NearxRate { + fn are_actual(&self) -> bool { + env::block_timestamp() <= self.rates_updated_at + EXPIRE_TS + } + fn get(&self) -> Balance { + self.stored_rates + } + fn last_update_ts(&self) -> u64 { + self.rates_updated_at + } + fn async_update(&self) -> Promise { + ext_nearx::get_nearx_price(&self.contract_id, NO_DEPOSIT, GAS_FOR_BASIC_OP) + } + fn set(&mut self, cross_call_result: &Vec) -> u128 { + if let Ok(U128(price)) = from_slice::(cross_call_result) { + self.stored_rates = price; + self.rates_updated_at = env::block_timestamp(); + price + } else { + env::panic(ERR126_FAILED_TO_PARSE_RESULT.as_bytes()); + } + } +} + +impl NearxRate { + pub fn new(contract_id: AccountId) -> Self { + Self { + stored_rates: PRECISION, + rates_updated_at: 0, + contract_id, + } + } +} + diff --git a/ref-exchange/src/rated_swap/rate.rs b/ref-exchange/src/rated_swap/rate.rs index e5d825d..9dae946 100644 --- a/ref-exchange/src/rated_swap/rate.rs +++ b/ref-exchange/src/rated_swap/rate.rs @@ -1,5 +1,6 @@ use super::stnear_rate::StnearRate; use super::linear_rate::LinearRate; +use super::nearx_rate::NearxRate; use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; use near_sdk::{env, AccountId, Balance, Promise}; use crate::ERR127_INVALID_RATE_TYPE; @@ -18,6 +19,7 @@ pub static RATES: Lazy>> = Lazy::new(|| Mutex::ne pub enum Rate { Stnear(StnearRate), Linear(LinearRate), + Nearx(NearxRate), } pub trait RateTrait { @@ -33,30 +35,35 @@ impl RateTrait for Rate { match self { Rate::Stnear(rates) => rates.are_actual(), Rate::Linear(rates) => rates.are_actual(), + Rate::Nearx(rates) => rates.are_actual(), } } fn get(&self) -> Balance { match self { Rate::Stnear(rates) => rates.get(), Rate::Linear(rates) => rates.get(), + Rate::Nearx(rates) => rates.get(), } } fn last_update_ts(&self) -> u64 { match self { Rate::Stnear(rates) => rates.last_update_ts(), Rate::Linear(rates) => rates.last_update_ts(), + Rate::Nearx(rates) => rates.last_update_ts(), } } fn async_update(&self) -> Promise { match self { Rate::Stnear(rates) => rates.async_update(), Rate::Linear(rates) => rates.async_update(), + Rate::Nearx(rates) => rates.async_update(), } } fn set(&mut self, cross_call_result: &Vec) -> u128 { match self { Rate::Stnear(rates) => rates.set(cross_call_result), Rate::Linear(rates) => rates.set(cross_call_result), + Rate::Nearx(rates) => rates.set(cross_call_result), } } } @@ -66,6 +73,7 @@ impl Rate { match rates_type.as_str() { "STNEAR" => Rate::Stnear(StnearRate::new(contract_id)), "LINEAR" => Rate::Linear(LinearRate::new(contract_id)), + "NEARX" => Rate::Nearx(NearxRate::new(contract_id)), _ => unimplemented!(), } } @@ -74,6 +82,7 @@ impl Rate { match self { Rate::Stnear(_) => "STNEAR".to_string(), Rate::Linear(_) => "LINEAR".to_string(), + Rate::Nearx(_) => "NEARX".to_string(), } } @@ -81,6 +90,7 @@ impl Rate { match rates_type { "STNEAR" => true, "LINEAR" => true, + "NEARX" => true, _ => false, } } diff --git a/ref-exchange/src/simple_pool.rs b/ref-exchange/src/simple_pool.rs index df700f1..49a0512 100644 --- a/ref-exchange/src/simple_pool.rs +++ b/ref-exchange/src/simple_pool.rs @@ -133,6 +133,7 @@ impl SimplePool { fair_supply.as_u128() } else { for i in 0..self.token_account_ids.len() { + assert!(amounts[i] > 0, "{}", ERR31_ZERO_AMOUNT); self.amounts[i] += amounts[i]; } INIT_SHARES_SUPPLY @@ -159,7 +160,7 @@ impl SimplePool { if shares == 0 { return; } - self.shares_total_supply += shares; + self.shares_total_supply = self.shares_total_supply.checked_add(shares).expect(ERR36_SHARES_TOTAL_SUPPLY_OVERFLOW); add_to_collection(&mut self.shares, &account_id, shares); } diff --git a/ref-exchange/tests/common/utils.rs b/ref-exchange/tests/common/utils.rs index ac3a95e..a2b0f0b 100644 --- a/ref-exchange/tests/common/utils.rs +++ b/ref-exchange/tests/common/utils.rs @@ -281,6 +281,10 @@ pub fn linear() -> AccountId { "linear".to_string() } +pub fn nearx() -> AccountId { + "nearx".to_string() +} + pub fn to_va(a: AccountId) -> ValidAccountId { ValidAccountId::try_from(a).unwrap() } diff --git a/ref-exchange/tests/test_migrate.rs b/ref-exchange/tests/test_migrate.rs index b7267c4..d760557 100644 --- a/ref-exchange/tests/test_migrate.rs +++ b/ref-exchange/tests/test_migrate.rs @@ -46,7 +46,7 @@ fn test_upgrade() { .assert_success(); let metadata = get_metadata(&pool); // println!("{:#?}", metadata); - assert_eq!(metadata.version, "1.5.2".to_string()); + assert_eq!(metadata.version, "1.5.3".to_string()); assert_eq!(metadata.exchange_fee, 4); assert_eq!(metadata.referral_fee, 1); assert_eq!(metadata.state, RunningState::Running); diff --git a/ref-exchange/tests/test_rated_pool.rs b/ref-exchange/tests/test_rated_pool.rs index 9288415..868bd2f 100644 --- a/ref-exchange/tests/test_rated_pool.rs +++ b/ref-exchange/tests/test_rated_pool.rs @@ -15,6 +15,7 @@ const ONE_LPT: u128 = 10u128.pow(24 as u32); const ONE_NEAR: u128 = 10u128.pow(24 as u32); const ONE_STNEAR: u128 = 10u128.pow(24 as u32); const ONE_LINEAR: u128 = 10u128.pow(24 as u32); +const ONE_NEARX: u128 = 10u128.pow(24 as u32); #[test] fn sim_rated_swap_liquidity_two() { @@ -1344,4 +1345,385 @@ fn sim_rated_swap_lp_storage() { let sb = get_storage_balance(&pool, user.valid_account_id()).unwrap(); assert_eq!(sb.total.0, to_yocto("0.00546")); assert_eq!(sb.available.0, 0); +} + +#[test] +fn sim_rated_swap_liquidity_two_with_nearx() { + let (root, owner, pool, tokens, token_rated_contracts) = + setup_rated_pool( + vec![near()], + vec![nearx()], + vec![24, 24], + 25, + 10000, + ); + + let nearx_contract = &token_rated_contracts[0]; + + call!( + owner, + pool.register_rated_token( + "NEARX".to_string(), + token_rated_contracts[0].valid_account_id() + ), + deposit = 1 + ).assert_success(); + + call!( + root, + nearx_contract.set_price(U128(2 * 10u128.pow(24))) + ).assert_success(); + + call!( + owner, + pool.update_token_rate( + nearx_contract.valid_account_id() + ), + deposit = 1 + ).assert_success(); + + let user = root.create_user("user".to_string(), to_yocto("100")); + mint_and_deposit_token(&user, &tokens[0], &pool, 100000*ONE_NEAR); + mint_and_deposit_rated_token(&user, &token_rated_contracts[0], &pool, 100000*ONE_NEARX); + let out_come = call!( + user, + pool.add_stable_liquidity(0, vec![ + U128(100000*ONE_NEAR), U128(50000*ONE_NEARX)], U128(1)), + deposit = to_yocto("0.0007") + ); + out_come.assert_success(); + println!("{:#?}", get_logs(&out_come)); + assert_eq!(mft_balance_of(&pool, ":0", &user.account_id()), 200000*ONE_LPT); + assert_eq!(mft_total_supply(&pool, ":0"), 200000*ONE_LPT); + let last_share_price = pool_share_price(&pool, 0); + assert_eq!(100000000, last_share_price); + + let user1 = root.create_user("user1".to_string(), to_yocto("100")); + mint_and_deposit_token(&user1, &tokens[0], &pool, 100000*ONE_NEAR); + mint_and_deposit_rated_token(&user1, &token_rated_contracts[0], &pool, 100000*ONE_NEARX); + let out_come = call!( + user1, + pool.add_stable_liquidity(0, vec![ + U128(100000*ONE_NEAR), U128(50000*ONE_NEARX)], U128(1)), + deposit = to_yocto("0.0007") + ); + out_come.assert_success(); + println!("{:#?}", get_logs(&out_come)); + assert_eq!(mft_balance_of(&pool, ":0", &user1.account_id()), 200000*ONE_LPT); + assert_eq!(mft_total_supply(&pool, ":0"), 400000*ONE_LPT); + let last_share_price = pool_share_price(&pool, 0); + assert_eq!(100000000, last_share_price); + + let out_come = call!( + user1, + pool.remove_liquidity(0, U128(200000*ONE_LPT), vec![U128(1*ONE_NEAR), U128(1*ONE_NEARX)]), + deposit = 1 + ); + out_come.assert_success(); + println!("{:#?}", get_logs(&out_come)); + assert_eq!(mft_balance_of(&pool, ":0", &user1.account_id()), 0); + assert_eq!(mft_total_supply(&pool, ":0"), 200000*ONE_LPT); + assert_eq!(100000000, pool_share_price(&pool, 0)); + + let out_come = call!( + user, + pool.remove_liquidity(0, U128(200000*ONE_LPT), vec![U128(1*ONE_NEAR), U128(1*ONE_NEARX)]), + deposit = 1 + ); + assert_eq!(get_error_count(&out_come), 1); + assert!(get_error_status(&out_come).contains("E69: pool reserved token balance less than MIN_RESERVE")); + +} + +#[test] +fn sim_rated_swap_two_no_rated_with_nearx() { + let (root, _owner, pool, tokens, _token_rated_contracts) = + setup_rated_pool_with_liquidity( + vec![near()], + vec![nearx()], + vec![100000*ONE_NEAR], + vec![100000*ONE_NEARX], + vec![24, 24], + 25, + 10000, + ); + assert_eq!( + view!(pool.get_pool(0)).unwrap_json::(), + PoolInfo { + pool_kind: "RATED_SWAP".to_string(), + amp: 10000, + token_account_ids: vec![near(), nearx()], + amounts: vec![U128(100000*ONE_NEAR), U128(100000*ONE_NEARX)], + total_fee: 25, + shares_total_supply: U128(200000*ONE_LPT), + } + ); + assert_eq!( + view!(pool.mft_metadata(":0".to_string())) + .unwrap_json::() + .name, + "ref-pool-0" + ); + assert_eq!( + view!(pool.mft_balance_of(":0".to_string(), to_va(root.account_id.clone()))) + .unwrap_json::() + .0, + 200000*ONE_LPT + ); + let balances = view!(pool.get_deposits(root.valid_account_id())) + .unwrap_json::>(); + let balances = balances.values().cloned().collect::>(); + assert_eq!(balances, vec![U128(0), U128(0)]); + + let c = tokens.get(0).unwrap(); + call!( + root, + c.ft_transfer_call(pool.valid_account_id(), U128(ONE_NEAR), None, "".to_string()), + deposit = 1 + ) + .assert_success(); + + let out_come = call!( + root, + pool.swap( + vec![SwapAction { + pool_id: 0, + token_in: near(), + amount_in: Some(U128(ONE_NEAR)), + token_out: nearx(), + min_amount_out: U128(1) + }], + None + ), + deposit = 1 + ); + out_come.assert_success(); + println!("{:#?}", get_logs(&out_come)); + + let balances = view!(pool.get_deposits(root.valid_account_id())) + .unwrap_json::>(); + assert_eq!(balances[&near()].0, 0); + assert_eq!(balances[&nearx()].0, 997499999501274936452669); + + assert_eq!( + view!(pool.get_pool(0)).unwrap_json::(), + PoolInfo { + pool_kind: "RATED_SWAP".to_string(), + amp: 10000, + token_account_ids: vec![near(), nearx()], + amounts: vec![U128(100001*ONE_NEAR), U128(99999*ONE_NEARX+2500000498725063547331)], + total_fee: 25, + shares_total_supply: U128(200000*ONE_LPT + 499999994999720058346), + } + ); +} + +#[test] +fn sim_rated_swap_rate_one_with_fee_with_nearx() { + let (root, owner, pool, tokens, token_rated_contracts) = + setup_rated_pool_with_liquidity( + vec![near()], + vec![nearx()], + vec![100000*ONE_NEAR], + vec![100000*ONE_NEARX], + vec![24, 24], + 25, + 10000, + ); + let nearx_contract = &token_rated_contracts[0]; + assert_eq!( + view!(pool.get_pool(0)).unwrap_json::(), + PoolInfo { + pool_kind: "RATED_SWAP".to_string(), + amp: 10000, + token_account_ids: vec![near(), nearx()], + amounts: vec![U128(100000*ONE_NEAR), U128(100000*ONE_NEARX)], + total_fee: 25, + shares_total_supply: U128(200000*ONE_LPT), + } + ); + assert_eq!( + view!(pool.mft_metadata(":0".to_string())) + .unwrap_json::() + .name, + "ref-pool-0" + ); + assert_eq!( + view!(pool.mft_balance_of(":0".to_string(), to_va(root.account_id.clone()))) + .unwrap_json::() + .0, + 200000*ONE_LPT + ); + let balances = view!(pool.get_deposits(root.valid_account_id())) + .unwrap_json::>(); + let balances = balances.values().cloned().collect::>(); + assert_eq!(balances, vec![U128(0), U128(0)]); + + let c = tokens.get(0).unwrap(); + call!( + root, + c.ft_transfer_call(pool.valid_account_id(), U128(ONE_NEAR), None, "".to_string()), + deposit = 1 + ) + .assert_success(); + + call!( + owner, + pool.register_rated_token( + "NEARX".to_string(), + token_rated_contracts[0].valid_account_id() + ), + deposit = 1 + ).assert_success(); + + call!( + owner, + pool.update_token_rate( + nearx_contract.valid_account_id() + ), + deposit = 1 + ).assert_success(); + + let rated_infos = view!(pool.list_rated_tokens()).unwrap_json::>(); + + println!("{:?}", rated_infos); + + let out_come = call!( + root, + pool.swap( + vec![SwapAction { + pool_id: 0, + token_in: near(), + amount_in: Some(U128(ONE_NEAR)), + token_out: nearx(), + min_amount_out: U128(1) + }], + None + ), + deposit = 1 + ); + out_come.assert_success(); + println!("{:#?}", get_logs(&out_come)); + + let balances = view!(pool.get_deposits(root.valid_account_id())) + .unwrap_json::>(); + assert_eq!(balances[&near()].0, 0); + assert_eq!(balances[&nearx()].0, 997499999501274936452669); + + assert_eq!( + view!(pool.get_pool(0)).unwrap_json::(), + PoolInfo { + pool_kind: "RATED_SWAP".to_string(), + amp: 10000, + token_account_ids: vec![near(), nearx()], + amounts: vec![U128(100001*ONE_NEAR), U128(99999*ONE_NEARX+2500000498725063547331)], + total_fee: 25, + shares_total_supply: U128(200000*ONE_LPT + 499999994999720058346), + } + ); +} + +#[test] +fn sim_rated_swap_rate_one_no_fee_with_nearx() { + let (root, owner, pool, tokens, token_rated_contracts) = + setup_rated_pool_with_liquidity( + vec![near()], + vec![nearx()], + vec![100000*ONE_NEAR], + vec![100000*ONE_NEARX], + vec![24, 24], + 0, + 10000, + ); + let nearx_contract = &token_rated_contracts[0]; + assert_eq!( + view!(pool.get_pool(0)).unwrap_json::(), + PoolInfo { + pool_kind: "RATED_SWAP".to_string(), + amp: 10000, + token_account_ids: vec![near(), nearx()], + amounts: vec![U128(100000*ONE_NEAR), U128(100000*ONE_NEARX)], + total_fee: 0, + shares_total_supply: U128(200000*ONE_LPT), + } + ); + assert_eq!( + view!(pool.mft_metadata(":0".to_string())) + .unwrap_json::() + .name, + "ref-pool-0" + ); + assert_eq!( + view!(pool.mft_balance_of(":0".to_string(), to_va(root.account_id.clone()))) + .unwrap_json::() + .0, + 200000*ONE_LPT + ); + let balances = view!(pool.get_deposits(root.valid_account_id())) + .unwrap_json::>(); + let balances = balances.values().cloned().collect::>(); + assert_eq!(balances, vec![U128(0), U128(0)]); + + let c = tokens.get(0).unwrap(); + call!( + root, + c.ft_transfer_call(pool.valid_account_id(), U128(ONE_NEAR), None, "".to_string()), + deposit = 1 + ) + .assert_success(); + + call!( + owner, + pool.register_rated_token( + "NEARX".to_string(), + token_rated_contracts[0].valid_account_id() + ), + deposit = 1 + ).assert_success(); + + call!( + owner, + pool.update_token_rate( + nearx_contract.valid_account_id() + ), + deposit = 1 + ).assert_success(); + + let rated_infos = view!(pool.list_rated_tokens()).unwrap_json::>(); + + println!("{:?}", rated_infos); + + let out_come = call!( + root, + pool.swap( + vec![SwapAction { + pool_id: 0, + token_in: near(), + amount_in: Some(U128(ONE_NEAR)), + token_out: nearx(), + min_amount_out: U128(1) + }], + None + ), + deposit = 1 + ); + out_come.assert_success(); + println!("{:#?}", get_logs(&out_come)); + + let balances = view!(pool.get_deposits(root.valid_account_id())) + .unwrap_json::>(); + assert_eq!(balances[&near()].0, 0); + assert_eq!(balances[&nearx()].0, 999999999500024998950044); + + assert_eq!( + view!(pool.get_pool(0)).unwrap_json::(), + PoolInfo { + pool_kind: "RATED_SWAP".to_string(), + amp: 10000, + token_account_ids: vec![near(), nearx()], + amounts: vec![U128(100001*ONE_NEAR), U128(99999*ONE_NEARX+499975001049956)], + total_fee: 0, + shares_total_supply: U128(200000*ONE_LPT), + } + ); } \ No newline at end of file diff --git a/releases/ref_exchange_release.wasm b/releases/ref_exchange_release.wasm index ae4fa68..388b170 100755 Binary files a/releases/ref_exchange_release.wasm and b/releases/ref_exchange_release.wasm differ diff --git a/test-rated-token/Cargo.toml b/test-rated-token/Cargo.toml index 8616424..c5ea880 100644 --- a/test-rated-token/Cargo.toml +++ b/test-rated-token/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "test-rated-token" -version = "0.1.1" +version = "0.1.2" authors = ["Marco Sun ", "MagicGordon"] edition = "2018" publish = false diff --git a/test-rated-token/src/lib.rs b/test-rated-token/src/lib.rs index 0149ecc..bf2c87e 100644 --- a/test-rated-token/src/lib.rs +++ b/test-rated-token/src/lib.rs @@ -48,6 +48,10 @@ impl Contract { U128(self.price) } + pub fn get_nearx_price(&self) -> U128 { + U128(self.price) + } + pub fn mint(&mut self, account_id: ValidAccountId, amount: U128) { self.token .internal_deposit(account_id.as_ref(), amount.into()); @@ -117,10 +121,12 @@ mod tests { assert_eq!(contract.ft_price().0, 10u128.pow(24 as u32)); assert_eq!(contract.get_st_near_price().0, 10u128.pow(24 as u32)); + assert_eq!(contract.get_nearx_price().0, 10u128.pow(24 as u32)); contract.set_price(U128(2 * 10u128.pow(24 as u32))); assert_eq!(contract.ft_price().0, 2 * 10u128.pow(24 as u32)); assert_eq!(contract.get_st_near_price().0, 2 * 10u128.pow(24 as u32)); + assert_eq!(contract.get_nearx_price().0, 2 * 10u128.pow(24 as u32)); } } \ No newline at end of file