diff --git a/backstop/src/backstop/deposit.rs b/backstop/src/backstop/deposit.rs index 583c6b74..4448d567 100644 --- a/backstop/src/backstop/deposit.rs +++ b/backstop/src/backstop/deposit.rs @@ -121,7 +121,6 @@ mod tests { e.as_contract(&backstop_address, || { execute_deposit(&e, &samwise, &pool_0_id, 100_0000001); - // TODO: Handle token errors gracefully assert!(false); }); } diff --git a/backstop/src/backstop/user.rs b/backstop/src/backstop/user.rs index f1739900..39ad4016 100644 --- a/backstop/src/backstop/user.rs +++ b/backstop/src/backstop/user.rs @@ -1,6 +1,9 @@ use soroban_sdk::{contracttype, panic_with_error, vec, Env, Vec}; -use crate::errors::BackstopError; +use crate::{ + constants::{MAX_Q4W_SIZE, Q4W_LOCK_TIME}, + errors::BackstopError, +}; /// A deposit that is queued for withdrawal #[derive(Clone)] @@ -51,14 +54,15 @@ impl UserBalance { if self.shares < to_q { panic_with_error!(e, BackstopError::BalanceError); } + if self.q4w.len() >= MAX_Q4W_SIZE { + panic_with_error!(e, BackstopError::TooManyQ4WEntries); + } self.shares = self.shares - to_q; // user has enough tokens to withdrawal, add Q4W - // TODO: Consider capping how many active Q4Ws a user can have - let twentyone_days_in_sec = 21 * 24 * 60 * 60; let new_q4w = Q4W { amount: to_q, - exp: e.ledger().timestamp() + twentyone_days_in_sec, + exp: e.ledger().timestamp() + Q4W_LOCK_TIME, }; self.q4w.push_back(new_q4w.clone()); } @@ -210,6 +214,75 @@ mod tests { assert_eq_vec_q4w(&user.q4w, &cur_q4w); } + #[test] + fn test_q4w_new_to_max_works() { + let e = Env::default(); + let exp = 12592000; + let mut cur_q4w = vec![&e]; + for i in 0..20 { + cur_q4w.push_back(Q4W { + amount: 200, + exp: exp + i, + }); + } + let mut user = UserBalance { + shares: 1000, + q4w: cur_q4w.clone(), + }; + + e.ledger().set(LedgerInfo { + protocol_version: 20, + sequence_number: 1, + timestamp: 11000000, + network_id: Default::default(), + base_reserve: 10, + min_temp_entry_ttl: 10, + min_persistent_entry_ttl: 10, + max_entry_ttl: 3110400, + }); + + let to_queue = 500; + user.queue_shares_for_withdrawal(&e, to_queue); + cur_q4w.push_back(Q4W { + amount: to_queue, + exp: 11000000 + 21 * 24 * 60 * 60, + }); + assert_eq_vec_q4w(&user.q4w, &cur_q4w); + } + + #[test] + #[should_panic(expected = "Error(Contract, #1007)")] + fn test_q4w_new_over_max_panics() { + let e = Env::default(); + + let exp = 12592000; + let mut cur_q4w = vec![&e]; + for i in 0..21 { + cur_q4w.push_back(Q4W { + amount: 200, + exp: exp + i, + }); + } + let mut user = UserBalance { + shares: 1000, + q4w: cur_q4w.clone(), + }; + + e.ledger().set(LedgerInfo { + protocol_version: 20, + sequence_number: 1, + timestamp: 11000000, + network_id: Default::default(), + base_reserve: 10, + min_temp_entry_ttl: 10, + min_persistent_entry_ttl: 10, + max_entry_ttl: 3110400, + }); + + let to_queue = 500; + user.queue_shares_for_withdrawal(&e, to_queue); + } + #[test] #[should_panic(expected = "Error(Contract, #10)")] fn test_q4w_over_shares_panics() { diff --git a/backstop/src/constants.rs b/backstop/src/constants.rs index 26e7f9ce..d2bd2bad 100644 --- a/backstop/src/constants.rs +++ b/backstop/src/constants.rs @@ -1,5 +1,14 @@ /// Fixed-point scalar for 7 decimal numbers pub const SCALAR_7: i128 = 1_0000000; -// The approximate deployment date of the backstop module TODO: pick one -pub const BACKSTOP_EPOCH: u64 = 1441065600; +/// The approximate deployment time in seconds since epoch of the backstop module. This is NOT the +/// actual deployment time and should not be considered accruate. It is only used to determine reward +/// zone size on ~90 day intervals, starting at 10 on or before April 15th, 2024 00:00:00 UTC. +pub const BACKSTOP_EPOCH: u64 = 1713139200; + +/// The maximum amount of active Q4W entries that a user can have against a single backstop. +/// Set such that a user can create a maximum of 1 entry per day over the 21 day lock period. +pub const MAX_Q4W_SIZE: u32 = 21; + +/// The time in seconds that a Q4W entry is locked for (21 days). +pub const Q4W_LOCK_TIME: u64 = 21 * 24 * 60 * 60; diff --git a/backstop/src/emissions/manager.rs b/backstop/src/emissions/manager.rs index 968707ee..5c2f3b36 100644 --- a/backstop/src/emissions/manager.rs +++ b/backstop/src/emissions/manager.rs @@ -17,7 +17,11 @@ use super::distributor::update_emission_data_with_config; /// Add a pool to the reward zone. If the reward zone is full, attempt to swap it with the pool to remove. pub fn add_to_reward_zone(e: &Env, to_add: Address, to_remove: Address) { let mut reward_zone = storage::get_reward_zone(e); - let max_rz_len = 10 + (i128(e.ledger().timestamp() - BACKSTOP_EPOCH) >> 23); // bit-shift 23 is ~97 day interval + let max_rz_len = if e.ledger().timestamp() < BACKSTOP_EPOCH { + 10 + } else { + 10 + (i128(e.ledger().timestamp() - BACKSTOP_EPOCH) >> 23) // bit-shift 23 is ~97 day interval + }; // ensure an entity in the reward zone cannot be included twice if reward_zone.contains(to_add.clone()) { @@ -89,8 +93,6 @@ pub fn gulp_emissions(e: &Env) -> i128 { let mut rz_balance: Vec = vec![e]; - // TODO: Potential to assume optimization of backstop token balances ~= RZ tokens - // However, linear iteration over the RZ will still occur // fetch total tokens of BLND in the reward zone let mut total_non_queued_tokens: i128 = 0; for rz_pool_index in 0..rz_len { @@ -136,12 +138,12 @@ pub fn gulp_pool_emissions(e: &Env, pool_id: &Address) -> i128 { let blnd_token_client = TokenClient::new(e, &storage::get_blnd_token(e)); let current_allowance = blnd_token_client.allowance(&e.current_contract_address(), pool_id); let new_tokens = current_allowance + pool_emissions; - let new_seq = e.ledger().sequence() + 17_280 * 30; // ~30 days: TODO: check phase 1 limits + let new_seq = e.ledger().sequence() + storage::LEDGER_BUMP_USER; // ~120 days blnd_token_client.approve( &e.current_contract_address(), pool_id, &new_tokens, - &new_seq, // ~30 days: TODO: check phase 1 limits + &new_seq, ); storage::set_pool_emissions(e, pool_id, 0); pool_emissions @@ -574,6 +576,55 @@ mod tests { }); } + #[test] + fn test_add_to_rz_before_epoch_max_10() { + let e = Env::default(); + e.ledger().set(LedgerInfo { + timestamp: BACKSTOP_EPOCH - 100000, + protocol_version: 20, + sequence_number: 0, + network_id: Default::default(), + base_reserve: 10, + min_temp_entry_ttl: 10, + min_persistent_entry_ttl: 10, + max_entry_ttl: 3110400, + }); + + let backstop_id = create_backstop(&e); + let to_add = Address::generate(&e); + let mut reward_zone: Vec
= vec![ + &e, + Address::generate(&e), + Address::generate(&e), + Address::generate(&e), + Address::generate(&e), + Address::generate(&e), + Address::generate(&e), + Address::generate(&e), + Address::generate(&e), + Address::generate(&e), + ]; + + e.as_contract(&backstop_id, || { + storage::set_reward_zone(&e, &reward_zone); + storage::set_pool_balance( + &e, + &to_add, + &PoolBalance { + shares: 90_000_0000000, + tokens: 100_000_0000000, + q4w: 1_000_0000000, + }, + ); + storage::set_lp_token_val(&e, &(5_0000000, 0_1000000)); + + add_to_reward_zone(&e, to_add.clone(), Address::generate(&e)); + let actual_rz = storage::get_reward_zone(&e); + reward_zone.push_front(to_add); + assert_eq!(actual_rz, reward_zone); + }); + } + #[test] #[should_panic(expected = "Error(Contract, #1002)")] fn test_add_to_rz_empty_pool_under_backstop_threshold() { @@ -660,6 +711,7 @@ mod tests { assert_eq!(actual_rz, reward_zone); }); } + #[test] #[should_panic(expected = "Error(Contract, #1002)")] fn test_add_to_rz_takes_floor_for_size() { diff --git a/backstop/src/errors.rs b/backstop/src/errors.rs index e5d3966c..46fe86c5 100644 --- a/backstop/src/errors.rs +++ b/backstop/src/errors.rs @@ -24,4 +24,5 @@ pub enum BackstopError { NotPool = 1004, InvalidShareMintAmount = 1005, InvalidTokenWithdrawAmount = 1006, + TooManyQ4WEntries = 1007, } diff --git a/backstop/src/storage.rs b/backstop/src/storage.rs index 33da90d8..112c75db 100644 --- a/backstop/src/storage.rs +++ b/backstop/src/storage.rs @@ -16,7 +16,7 @@ const LEDGER_THRESHOLD_SHARED: u32 = ONE_DAY_LEDGERS * 45; // ~ 45 days const LEDGER_BUMP_SHARED: u32 = LEDGER_THRESHOLD_SHARED + ONE_DAY_LEDGERS; // ~ 46 days const LEDGER_THRESHOLD_USER: u32 = ONE_DAY_LEDGERS * 100; // ~ 100 days -const LEDGER_BUMP_USER: u32 = LEDGER_THRESHOLD_USER + 20 * ONE_DAY_LEDGERS; // ~ 120 days +pub(crate) const LEDGER_BUMP_USER: u32 = LEDGER_THRESHOLD_USER + 20 * ONE_DAY_LEDGERS; // ~ 120 days /********** Storage Types **********/ @@ -314,8 +314,6 @@ pub fn set_last_distribution_time(e: &Env, timestamp: &u64) { } /// Get the current pool addresses that are in the reward zone -/// -// @dev - TODO: Once data access costs are available, find the breakeven point for splitting this up pub fn get_reward_zone(e: &Env) -> Vec
{ get_persistent_default( e, diff --git a/mocks/mock-pool-factory/src/pool_factory.rs b/mocks/mock-pool-factory/src/pool_factory.rs index 0eefef10..233f882e 100644 --- a/mocks/mock-pool-factory/src/pool_factory.rs +++ b/mocks/mock-pool-factory/src/pool_factory.rs @@ -85,7 +85,6 @@ impl MockPoolFactoryTrait for MockPoolFactory { init_args.push_back(max_positions.into_val(&e)); init_args.push_back(pool_init_meta.backstop.to_val()); init_args.push_back(pool_init_meta.blnd_id.to_val()); - init_args.push_back(pool_init_meta.usdc_id.to_val()); let pool_address = e.register_contract(None, PoolContract {}); e.invoke_contract::(&pool_address, &Symbol::new(&e, "initialize"), init_args); diff --git a/mocks/mock-pool-factory/src/storage.rs b/mocks/mock-pool-factory/src/storage.rs index b3712438..ae8521f9 100644 --- a/mocks/mock-pool-factory/src/storage.rs +++ b/mocks/mock-pool-factory/src/storage.rs @@ -23,7 +23,6 @@ pub struct PoolInitMeta { pub pool_hash: BytesN<32>, pub backstop: Address, pub blnd_id: Address, - pub usdc_id: Address, } /// Bump the instance rent for the contract @@ -35,14 +34,8 @@ pub fn extend_instance(e: &Env) { /// Fetch the pool initialization metadata pub fn get_pool_init_meta(e: &Env) -> PoolInitMeta { - // TODO: Change to instance - https://github.com/stellar/rs-soroban-sdk/issues/1040 - e.storage().persistent().extend_ttl( - &PoolFactoryDataKey::PoolInitMeta, - LEDGER_THRESHOLD_SHARED, - LEDGER_BUMP_SHARED, - ); e.storage() - .persistent() + .instance() .get::(&PoolFactoryDataKey::PoolInitMeta) .unwrap_optimized() } @@ -53,14 +46,14 @@ pub fn get_pool_init_meta(e: &Env) -> PoolInitMeta { /// * `pool_init_meta` - The metadata to initialize pools pub fn set_pool_init_meta(e: &Env, pool_init_meta: &PoolInitMeta) { e.storage() - .persistent() + .instance() .set::(&PoolFactoryDataKey::PoolInitMeta, pool_init_meta) } /// Check if the factory has a WASM hash set pub fn has_pool_init_meta(e: &Env) -> bool { e.storage() - .persistent() + .instance() .has(&PoolFactoryDataKey::PoolInitMeta) } diff --git a/pool-factory/src/pool_factory.rs b/pool-factory/src/pool_factory.rs index 298021e8..c282e01f 100644 --- a/pool-factory/src/pool_factory.rs +++ b/pool-factory/src/pool_factory.rs @@ -98,7 +98,6 @@ impl PoolFactory for PoolFactoryContract { init_args.push_back(max_positions.into_val(&e)); init_args.push_back(pool_init_meta.backstop.to_val()); init_args.push_back(pool_init_meta.blnd_id.to_val()); - init_args.push_back(pool_init_meta.usdc_id.to_val()); let pool_address = e .deployer() .with_current_contract(new_salt) diff --git a/pool-factory/src/storage.rs b/pool-factory/src/storage.rs index ea07bd95..9b857932 100644 --- a/pool-factory/src/storage.rs +++ b/pool-factory/src/storage.rs @@ -24,7 +24,6 @@ pub struct PoolInitMeta { pub pool_hash: BytesN<32>, pub backstop: Address, pub blnd_id: Address, - pub usdc_id: Address, //Must have 7 token decimals due to lot decimal restriction in backstop interest auctions } /// Bump the instance rent for the contract diff --git a/pool-factory/src/test.rs b/pool-factory/src/test.rs index 987bbd84..acdfa473 100644 --- a/pool-factory/src/test.rs +++ b/pool-factory/src/test.rs @@ -32,13 +32,11 @@ fn test_pool_factory() { let backstop_rate: u32 = 0_1000000; let max_positions: u32 = 6; let blnd_id = Address::generate(&e); - let usdc_id = Address::generate(&e); let pool_init_meta = PoolInitMeta { backstop: backstop_id.clone(), pool_hash: wasm_hash.clone(), blnd_id: blnd_id.clone(), - usdc_id: usdc_id.clone(), }; pool_factory_client.initialize(&pool_init_meta); @@ -116,13 +114,6 @@ fn test_pool_factory() { .unwrap(), blnd_id.clone() ); - assert_eq!( - e.storage() - .instance() - .get::<_, Address>(&Symbol::new(&e, "USDCTkn")) - .unwrap(), - usdc_id.clone() - ); }); assert_ne!(deployed_pool_address_1, deployed_pool_address_2); assert!(pool_factory_client.is_pool(&deployed_pool_address_1)); @@ -142,13 +133,11 @@ fn test_pool_factory_invalid_pool_init_args_backstop_rate() { let backstop_id = Address::generate(&e); let blnd_id = Address::generate(&e); - let usdc_id = Address::generate(&e); let pool_init_meta = PoolInitMeta { backstop: backstop_id.clone(), pool_hash: wasm_hash.clone(), blnd_id: blnd_id.clone(), - usdc_id: usdc_id.clone(), }; pool_factory_client.initialize(&pool_init_meta); @@ -182,13 +171,11 @@ fn test_pool_factory_invalid_pool_init_args_max_positions() { let backstop_id = Address::generate(&e); let blnd_id = Address::generate(&e); - let usdc_id = Address::generate(&e); let pool_init_meta = PoolInitMeta { backstop: backstop_id.clone(), pool_hash: wasm_hash.clone(), blnd_id: blnd_id.clone(), - usdc_id: usdc_id.clone(), }; pool_factory_client.initialize(&pool_init_meta); @@ -228,13 +215,11 @@ fn test_pool_factory_frontrun_protection() { let backstop_rate: u32 = 0_1000000; let max_positions: u32 = 6; let blnd_id = Address::generate(&e); - let usdc_id = Address::generate(&e); let pool_init_meta = PoolInitMeta { backstop: backstop_id.clone(), pool_hash: wasm_hash.clone(), blnd_id: blnd_id.clone(), - usdc_id: usdc_id.clone(), }; pool_factory_client.initialize(&pool_init_meta); diff --git a/pool/src/auctions/auction.rs b/pool/src/auctions/auction.rs index cb84b5e4..91433008 100644 --- a/pool/src/auctions/auction.rs +++ b/pool/src/auctions/auction.rs @@ -311,7 +311,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -444,7 +444,7 @@ mod tests { let bombadil = Address::generate(&e); let pool_address = create_pool(&e); - let (usdc_id, _) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc_id, _) = testutils::create_token_contract(&e, &bombadil); let (blnd_id, _) = testutils::create_blnd_token(&e, &pool_address, &bombadil); let (backstop_token_id, _) = create_comet_lp_pool(&e, &bombadil, &blnd_id, &usdc_id); diff --git a/pool/src/auctions/backstop_interest_auction.rs b/pool/src/auctions/backstop_interest_auction.rs index dded3605..396683f6 100644 --- a/pool/src/auctions/backstop_interest_auction.rs +++ b/pool/src/auctions/backstop_interest_auction.rs @@ -201,7 +201,7 @@ mod tests { let bombadil = Address::generate(&e); let pool_address = create_pool(&e); - let (usdc_id, _) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc_id, _) = testutils::create_token_contract(&e, &bombadil); let (backstop_address, _backstop_client) = testutils::create_backstop(&e); testutils::setup_backstop( &e, @@ -302,7 +302,7 @@ mod tests { let bombadil = Address::generate(&e); let pool_address = create_pool(&e); - let (usdc_id, _) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc_id, _) = testutils::create_token_contract(&e, &bombadil); let (blnd_id, _) = testutils::create_blnd_token(&e, &pool_address, &bombadil); let (backstop_token_id, _) = create_comet_lp_pool(&e, &bombadil, &blnd_id, &usdc_id); @@ -413,13 +413,13 @@ mod tests { base_reserve: 10, min_temp_entry_ttl: 10, min_persistent_entry_ttl: 10, - max_entry_ttl: 2000000, + max_entry_ttl: 3110400, }); let bombadil = Address::generate(&e); let pool_address = create_pool(&e); - let (usdc_id, _) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc_id, _) = testutils::create_token_contract(&e, &bombadil); let (blnd_id, _) = testutils::create_blnd_token(&e, &pool_address, &bombadil); let (backstop_token_id, _) = create_comet_lp_pool(&e, &bombadil, &blnd_id, &usdc_id); @@ -542,7 +542,7 @@ mod tests { let bombadil = Address::generate(&e); let pool_address = create_pool(&e); - let (usdc_id, _) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc_id, _) = testutils::create_token_contract(&e, &bombadil); let (blnd_id, _) = testutils::create_blnd_token(&e, &pool_address, &bombadil); let (backstop_token_id, _) = create_comet_lp_pool(&e, &bombadil, &blnd_id, &usdc_id); @@ -668,7 +668,7 @@ mod tests { let pool_address = create_pool(&e); - let (usdc_id, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc_id, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (blnd_id, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); let (backstop_token_id, backstop_token_client) = @@ -754,7 +754,6 @@ mod tests { ); storage::set_pool_config(&e, &pool_config); storage::set_backstop(&e, &backstop_address); - storage::set_usdc_token(&e, &usdc_id); let mut pool = Pool::load(&e); let backstop_token_balance_pre_fill = backstop_token_client.balance(&backstop_address); fill_interest_auction(&e, &mut pool, &mut auction_data, &samwise); @@ -798,7 +797,7 @@ mod tests { let pool_address = create_pool(&e); - let (usdc_id, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc_id, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (backstop_address, _backstop_client) = testutils::create_backstop(&e); testutils::setup_backstop( &e, @@ -859,7 +858,6 @@ mod tests { ); storage::set_pool_config(&e, &pool_config); storage::set_backstop(&e, &backstop_address); - storage::set_usdc_token(&e, &usdc_id); let mut pool = Pool::load(&e); fill_interest_auction(&e, &mut pool, &mut auction_data, &backstop_address); diff --git a/pool/src/auctions/bad_debt_auction.rs b/pool/src/auctions/bad_debt_auction.rs index a050a558..c26760f9 100644 --- a/pool/src/auctions/bad_debt_auction.rs +++ b/pool/src/auctions/bad_debt_auction.rs @@ -45,7 +45,6 @@ pub fn create_bad_debt_auction_data(e: &Env, backstop: &Address) -> AuctionData // get value of backstop_token (BLND-USDC LP token) to base let backstop_client = BackstopClient::new(e, backstop); - // TODO: Remove backstop_token getter call if WASM cache is not implemented let backstop_token = backstop_client.backstop_token(); let pool_backstop_data = backstop_client.pool_data(&e.current_contract_address()); let backstop_value_base = pool_backstop_data @@ -151,7 +150,7 @@ mod tests { let samwise = Address::generate(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -226,7 +225,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -352,7 +351,7 @@ mod tests { base_reserve: 10, min_temp_entry_ttl: 10, min_persistent_entry_ttl: 10, - max_entry_ttl: 2000000, + max_entry_ttl: 3110400, }); let bombadil = Address::generate(&e); @@ -360,7 +359,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -500,7 +499,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -635,7 +634,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -771,7 +770,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -915,7 +914,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -1068,7 +1067,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); @@ -1233,7 +1232,7 @@ mod tests { let pool_address = create_pool(&e); let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); - let (usdc, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (lp_token, lp_token_client) = testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc); let (backstop_address, backstop_client) = testutils::create_backstop(&e); diff --git a/pool/src/contract.rs b/pool/src/contract.rs index 3ad13a8f..d0566c60 100644 --- a/pool/src/contract.rs +++ b/pool/src/contract.rs @@ -27,7 +27,6 @@ pub trait Pool { /// Pool Factory supplied: /// * `backstop_id` - The contract address of the pool's backstop module /// * `blnd_id` - The contract ID of the BLND token - /// * `usdc_id` - The contract ID of the BLND token #[allow(clippy::too_many_arguments)] fn initialize( e: Env, @@ -38,7 +37,6 @@ pub trait Pool { max_positions: u32, backstop_id: Address, blnd_id: Address, - usdc_id: Address, ); /// (Admin only) Set a new address as the admin of this pool @@ -244,7 +242,6 @@ impl Pool for PoolContract { max_postions: u32, backstop_id: Address, blnd_id: Address, - usdc_id: Address, ) { storage::extend_instance(&e); admin.require_auth(); @@ -258,7 +255,6 @@ impl Pool for PoolContract { &max_postions, &backstop_id, &blnd_id, - &usdc_id, ); } diff --git a/pool/src/pool/actions.rs b/pool/src/pool/actions.rs index 05cf3bda..5a1845f8 100644 --- a/pool/src/pool/actions.rs +++ b/pool/src/pool/actions.rs @@ -1361,7 +1361,7 @@ mod tests { let samwise = Address::generate(&e); let pool_address = create_pool(&e); - let (usdc_id, usdc_client) = testutils::create_usdc_token(&e, &pool_address, &bombadil); + let (usdc_id, usdc_client) = testutils::create_token_contract(&e, &bombadil); let (blnd_id, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil); let (backstop_token_id, backstop_token_client) = diff --git a/pool/src/pool/config.rs b/pool/src/pool/config.rs index bfffdd83..acec63e6 100644 --- a/pool/src/pool/config.rs +++ b/pool/src/pool/config.rs @@ -22,7 +22,6 @@ pub fn execute_initialize( max_positions: &u32, backstop_address: &Address, blnd_id: &Address, - usdc_id: &Address, ) { if storage::get_is_init(e) { panic_with_error!(e, PoolError::AlreadyInitializedError); @@ -51,7 +50,6 @@ pub fn execute_initialize( }, ); storage::set_blnd_token(e, blnd_id); - storage::set_usdc_token(e, usdc_id); storage::set_is_init(e); } @@ -203,7 +201,6 @@ mod tests { let max_positions = 2; let backstop_address = Address::generate(&e); let blnd_id = Address::generate(&e); - let usdc_id = Address::generate(&e); e.as_contract(&pool, || { execute_initialize( @@ -215,7 +212,6 @@ mod tests { &max_positions, &backstop_address, &blnd_id, - &usdc_id, ); assert_eq!(storage::get_admin(&e), admin); @@ -225,7 +221,6 @@ mod tests { assert_eq!(pool_config.status, 6); assert_eq!(storage::get_backstop(&e), backstop_address); assert_eq!(storage::get_blnd_token(&e), blnd_id); - assert_eq!(storage::get_usdc_token(&e), usdc_id); }); } @@ -242,7 +237,6 @@ mod tests { let max_positions = 3; let backstop_address = Address::generate(&e); let blnd_id = Address::generate(&e); - let usdc_id = Address::generate(&e); e.as_contract(&pool, || { execute_initialize( @@ -254,7 +248,6 @@ mod tests { &max_positions, &backstop_address, &blnd_id, - &usdc_id, ); execute_initialize( @@ -266,7 +259,6 @@ mod tests { &max_positions, &backstop_address, &blnd_id, - &usdc_id, ); }); } @@ -284,7 +276,6 @@ mod tests { let max_positions = 3; let backstop_address = Address::generate(&e); let blnd_id = Address::generate(&e); - let usdc_id = Address::generate(&e); e.as_contract(&pool, || { execute_initialize( @@ -296,7 +287,6 @@ mod tests { &max_positions, &backstop_address, &blnd_id, - &usdc_id, ); }); } @@ -314,7 +304,6 @@ mod tests { let max_positions = 1; let backstop_address = Address::generate(&e); let blnd_id = Address::generate(&e); - let usdc_id = Address::generate(&e); e.as_contract(&pool, || { execute_initialize( @@ -326,7 +315,6 @@ mod tests { &max_positions, &backstop_address, &blnd_id, - &usdc_id, ); }); } diff --git a/pool/src/storage.rs b/pool/src/storage.rs index ac073f16..cb9947d8 100644 --- a/pool/src/storage.rs +++ b/pool/src/storage.rs @@ -108,7 +108,6 @@ const ADMIN_KEY: &str = "Admin"; const NAME_KEY: &str = "Name"; const BACKSTOP_KEY: &str = "Backstop"; const BLND_TOKEN_KEY: &str = "BLNDTkn"; -const USDC_TOKEN_KEY: &str = "USDCTkn"; const POOL_CONFIG_KEY: &str = "Config"; const RES_LIST_KEY: &str = "ResList"; const POOL_EMIS_KEY: &str = "PoolEmis"; @@ -127,7 +126,6 @@ pub struct AuctionKey { auct_type: u32, // the type of auction taking place } -// TODO: See if we can avoid publishing this #[derive(Clone)] #[contracttype] pub enum PoolDataKey { @@ -302,24 +300,6 @@ pub fn set_blnd_token(e: &Env, blnd_token_id: &Address) { .set::(&Symbol::new(e, BLND_TOKEN_KEY), blnd_token_id); } -/// Fetch the USDC token ID -pub fn get_usdc_token(e: &Env) -> Address { - e.storage() - .instance() - .get(&Symbol::new(e, USDC_TOKEN_KEY)) - .unwrap_optimized() -} - -/// Set a new USDC token ID -/// -/// ### Arguments -/// * `usdc_token_id` - The ID of the USDC token -pub fn set_usdc_token(e: &Env, usdc_token_id: &Address) { - e.storage() - .instance() - .set::(&Symbol::new(e, USDC_TOKEN_KEY), usdc_token_id); -} - /********** Pool Config **********/ /// Fetch the pool configuration diff --git a/pool/src/testutils.rs b/pool/src/testutils.rs index c51f98cd..86d4e63f 100644 --- a/pool/src/testutils.rs +++ b/pool/src/testutils.rs @@ -51,19 +51,6 @@ pub(crate) fn create_blnd_token<'a>( (contract_address, client) } -pub(crate) fn create_usdc_token<'a>( - e: &Env, - pool_address: &Address, - admin: &Address, -) -> (Address, MockTokenClient<'a>) { - let (contract_address, client) = create_token_contract(e, admin); - - e.as_contract(pool_address, || { - storage::set_usdc_token(e, &contract_address); - }); - (contract_address, client) -} - //***** Oracle ****** pub(crate) fn create_mock_oracle(e: &Env) -> (Address, MockPriceOracleClient) { diff --git a/test-suites/src/test_fixture.rs b/test-suites/src/test_fixture.rs index 1b596fb0..5e96a179 100644 --- a/test-suites/src/test_fixture.rs +++ b/test-suites/src/test_fixture.rs @@ -117,7 +117,6 @@ impl TestFixture<'_> { backstop: backstop_id.clone(), pool_hash: pool_hash.clone(), blnd_id: blnd_id.clone(), - usdc_id: usdc_id.clone(), }; let pool_factory_client = PoolFactoryClient::new(&e, &pool_factory_id); pool_factory_client.initialize(&pool_init_meta); diff --git a/test-suites/tests/test_pool.rs b/test-suites/tests/test_pool.rs index 1c5d23db..384aeba8 100644 --- a/test-suites/tests/test_pool.rs +++ b/test-suites/tests/test_pool.rs @@ -548,7 +548,6 @@ fn test_pool_config() { &4, &Address::generate(&fixture.env), &Address::generate(&fixture.env), - &Address::generate(&fixture.env), ); assert!(result.is_err());