diff --git a/pool/src/pool/config.rs b/pool/src/pool/config.rs index 9eefd53e..4185fe54 100644 --- a/pool/src/pool/config.rs +++ b/pool/src/pool/config.rs @@ -101,12 +101,23 @@ fn initialize_reserve(e: &Env, asset: &Address, config: &ReserveConfig) -> u32 { if storage::has_res(e, asset) { // accrue and store reserve data to the ledger let pool = Pool::load(e); - let reserve = pool.load_reserve(e, asset); + let mut reserve = pool.load_reserve(e, asset); reserve.store(e); index = reserve.index; - if reserve.scalar != 10i128.pow(config.decimals) { + let reserve_config = storage::get_res_config(e, asset); + // decimals cannot change + if reserve_config.decimals != config.decimals { panic_with_error!(e, PoolError::InvalidReserveMetadata); } + // if any of the IR parameters were changed reset the IR modifier + if reserve_config.r_one != config.r_one + || reserve_config.r_two != config.r_two + || reserve_config.r_three != config.r_three + || reserve_config.util != config.util + { + reserve.ir_mod = 1_000_000_000; + } + reserve.store(e); } else { index = storage::push_res_list(e, asset); let init_data = ReserveData { @@ -646,6 +657,63 @@ mod tests { }); } + #[test] + fn test_execute_update_reserve_resets_ir_mod() { + let e = Env::default(); + e.mock_all_auths(); + e.ledger().set(LedgerInfo { + timestamp: 500, + protocol_version: 20, + sequence_number: 100, + network_id: Default::default(), + base_reserve: 10, + min_temp_entry_ttl: 10, + min_persistent_entry_ttl: 10, + max_entry_ttl: 2000000, + }); + + let pool = testutils::create_pool(&e); + let bombadil = Address::generate(&e); + + let (underlying, _) = testutils::create_token_contract(&e, &bombadil); + let (reserve_config, reserve_data) = testutils::default_reserve_meta(); + testutils::create_reserve(&e, &pool, &underlying, &reserve_config, &reserve_data); + + let new_metadata = ReserveConfig { + index: 99, + decimals: 7, + c_factor: 0_7500000, + l_factor: 0_7500000, + util: 1_0777777, + max_util: 0_9500000, + r_one: 0_0500000, + r_two: 0_7500000, + r_three: 1_5000000, + reactivity: 105, + }; + + let pool_config = PoolConfig { + oracle: Address::generate(&e), + bstop_rate: 0_100_000_000, + status: 0, + }; + e.as_contract(&pool, || { + storage::set_pool_config(&e, &pool_config); + + storage::set_queued_reserve_set( + &e, + &QueuedReserveInit { + new_config: new_metadata.clone(), + unlock_time: e.ledger().timestamp(), + }, + &underlying, + ); + execute_set_queued_reserve(&e, &underlying); + let res_data = storage::get_res_data(&e, &underlying); + assert_eq!(res_data.ir_mod, 1_000_000_000); + }); + } + #[test] fn test_validate_reserve_metadata() { let e = Env::default(); diff --git a/test-suites/tests/test_liquidation.rs b/test-suites/tests/test_liquidation.rs index 1f2bce1b..6a7ce85b 100644 --- a/test-suites/tests/test_liquidation.rs +++ b/test-suites/tests/test_liquidation.rs @@ -799,16 +799,6 @@ fn test_liquidations() { .pool .submit(&samwise, &samwise, &samwise, &sam_requests); - println!( - "samwise_positions_post borrow {:?}", - sam_positions.liabilities - ); - println!("current ledger {}", fixture.env.ledger().sequence()); - println!( - "current ledger timestamp {}", - fixture.env.ledger().timestamp() - ); - // Nuke eth price more fixture.oracle.set_price_stable(&vec![ &fixture.env, @@ -869,19 +859,16 @@ fn test_liquidations() { .pool .submit(&frodo, &frodo, &frodo, &bad_debt_fill_request); // transfer bad debt to backstop - let samwise_positions_pre_bd = - pool_fixture - .pool - .submit(&samwise, &samwise, &samwise, &blank_request); - println!( - "samwise_positions_pre_bd {:?}", - samwise_positions_pre_bd.liabilities - ); + + pool_fixture + .pool + .submit(&samwise, &samwise, &samwise, &blank_request); + pool_fixture.pool.bad_debt(&samwise); let events = fixture.env.events().all(); let event = vec![&fixture.env, events.get_unchecked(events.len() - 1)]; - let bad_debt: i128 = 92587244; //92587244 //92903018 + let bad_debt: i128 = 92903018; assert_eq!( event, vec![ @@ -927,7 +914,7 @@ fn test_liquidations() { assert_eq!(positions.liabilities.get(0).unwrap(), bad_debt); }); // check d_supply - let d_supply = 19104301981; //19104604033 + let d_supply = 19104604034; fixture.env.as_contract(&pool_fixture.pool.address, || { let key = PoolDataKey::ResData(fixture.tokens[TokenIndex::STABLE].address.clone()); let data = fixture diff --git a/test-suites/tests/test_pool.rs b/test-suites/tests/test_pool.rs index 2426c96a..61d0cc95 100644 --- a/test-suites/tests/test_pool.rs +++ b/test-suites/tests/test_pool.rs @@ -601,7 +601,7 @@ fn test_pool_config() { AuthorizedInvocation { function: AuthorizedFunction::Contract(( pool_fixture.pool.address.clone(), - Symbol::new(&fixture.env, "queue_init_reserve"), + Symbol::new(&fixture.env, "queue_set_reserve"), vec![ &fixture.env, blnd.address.to_val(), @@ -684,12 +684,8 @@ fn test_pool_config() { &fixture.env, ( pool_fixture.pool.address.clone(), - ( - Symbol::new(&fixture.env, "update_reserve"), - fixture.bombadil.clone() - ) - .into_val(&fixture.env), - blnd.address.to_val() + (Symbol::new(&fixture.env, "set_reserve"),).into_val(&fixture.env), + event_data.into_val(&fixture.env) ) ] );