From fbd4bc1ba2b15be0dc234238749a3e81be882da1 Mon Sep 17 00:00:00 2001 From: markuspluna <59978114+markuspluna@users.noreply.github.com> Date: Sun, 24 Mar 2024 12:20:14 +0300 Subject: [PATCH 1/2] fixed bug updated test --- backstop/src/emissions/manager.rs | 8 +- test-suites/src/lib.rs | 2 +- test-suites/src/setup.rs | 97 +++++++++++++++++++ test-suites/tests/test_emitter.rs | 152 +++++++++++++++++++++++++++--- 4 files changed, 244 insertions(+), 15 deletions(-) diff --git a/backstop/src/emissions/manager.rs b/backstop/src/emissions/manager.rs index 4130c6cc..b46bd6cf 100644 --- a/backstop/src/emissions/manager.rs +++ b/backstop/src/emissions/manager.rs @@ -62,6 +62,12 @@ pub fn add_to_reward_zone(e: &Env, to_add: Address, to_remove: Address) { /// Assign emissions from the Emitter to backstops and pools in the reward zone #[allow(clippy::zero_prefixed_literal)] pub fn gulp_emissions(e: &Env) -> i128 { + let reward_zone = storage::get_reward_zone(e); + let rz_len = reward_zone.len(); + // reward zone must have at least one pool for emissions to start + if rz_len == 0 { + panic_with_error!(e, BackstopError::BadRequest); + } let emitter = storage::get_emitter(e); let emitter_last_distribution = EmitterClient::new(&e, &emitter).get_last_distro(&e.current_contract_address()); @@ -81,8 +87,6 @@ pub fn gulp_emissions(e: &Env) -> i128 { .fixed_mul_floor(0_3000000, SCALAR_7) .unwrap_optimized(); - let reward_zone = storage::get_reward_zone(e); - let rz_len = reward_zone.len(); let mut rz_balance: Vec = vec![e]; // TODO: Potential to assume optimization of backstop token balances ~= RZ tokens diff --git a/test-suites/src/lib.rs b/test-suites/src/lib.rs index e32c4c4d..c7c35c30 100644 --- a/test-suites/src/lib.rs +++ b/test-suites/src/lib.rs @@ -6,7 +6,7 @@ pub mod oracle; pub mod pool; pub mod pool_factory; mod setup; -pub use setup::create_fixture_with_data; +pub use setup::{create_fixture_no_rzone_add, create_fixture_with_data}; pub mod assertions; pub mod test_fixture; pub mod token; diff --git a/test-suites/src/setup.rs b/test-suites/src/setup.rs index 3912cb06..51c04d4d 100644 --- a/test-suites/src/setup.rs +++ b/test-suites/src/setup.rs @@ -159,6 +159,103 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> TestFixture<'a> { fixture } +/// Create a test fixture with a pool and a whale depositing and borrowing all assets +pub fn create_fixture_no_rzone_add<'a>(wasm: bool) -> TestFixture<'a> { + let mut fixture = TestFixture::create(wasm); + // mint whale tokens + let frodo = Address::generate(&fixture.env); + fixture.users.push(frodo.clone()); + fixture.tokens[TokenIndex::STABLE].mint(&frodo, &(100_000 * 10i128.pow(6))); + fixture.tokens[TokenIndex::XLM].mint(&frodo, &(1_000_000 * SCALAR_7)); + fixture.tokens[TokenIndex::WETH].mint(&frodo, &(100 * 10i128.pow(9))); + + // mint LP tokens with whale + fixture.tokens[TokenIndex::BLND].mint(&frodo, &(500_0010_000_0000_0000 * SCALAR_7)); + // fixture.tokens[TokenIndex::BLND].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); + fixture.tokens[TokenIndex::USDC].mint(&frodo, &(12_5010_000_0000_0000 * SCALAR_7)); + // fixture.tokens[TokenIndex::USDC].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); + fixture.lp.join_pool( + &(500_000_0000 * SCALAR_7), + &svec![ + &fixture.env, + 500_0010_000_0000_0000 * SCALAR_7, + 12_5010_000_0000_0000 * SCALAR_7, + ], + &frodo, + ); + + // create pool + fixture.create_pool(Symbol::new(&fixture.env, "Teapot"), 0_1000000, 6); + + let mut stable_config = default_reserve_metadata(); + stable_config.decimals = 6; + stable_config.c_factor = 0_900_0000; + stable_config.l_factor = 0_950_0000; + stable_config.util = 0_850_0000; + fixture.create_pool_reserve(0, TokenIndex::STABLE, &stable_config); + + let mut xlm_config = default_reserve_metadata(); + xlm_config.c_factor = 0_750_0000; + xlm_config.l_factor = 0_750_0000; + xlm_config.util = 0_500_0000; + fixture.create_pool_reserve(0, TokenIndex::XLM, &xlm_config); + + let mut weth_config = default_reserve_metadata(); + weth_config.decimals = 9; + weth_config.c_factor = 0_800_0000; + weth_config.l_factor = 0_800_0000; + weth_config.util = 0_700_0000; + fixture.create_pool_reserve(0, TokenIndex::WETH, &weth_config); + + // enable emissions for pool + let pool_fixture = &fixture.pools[0]; + + let reserve_emissions: soroban_sdk::Vec = soroban_sdk::vec![ + &fixture.env, + ReserveEmissionMetadata { + res_index: 0, // STABLE + res_type: 0, // d_token + share: 0_600_0000 + }, + ReserveEmissionMetadata { + res_index: 1, // XLM + res_type: 1, // b_token + share: 0_400_0000 + }, + ]; + pool_fixture.pool.set_emissions_config(&reserve_emissions); + + // deposit into backstop + + // enable emissions + // fixture.emitter.distribute(); + + fixture.jump(60); + + // fixture.tokens[TokenIndex::STABLE].approve( + // &frodo, + // &pool_fixture.pool.address, + // &i128::MAX, + // &(fixture.env.ledger().sequence() + 100), + // ); + // fixture.tokens[TokenIndex::WETH].approve( + // &frodo, + // &pool_fixture.pool.address, + // &i128::MAX, + // &(fixture.env.ledger().sequence() + 100), + // ); + // fixture.tokens[TokenIndex::XLM].approve(&frodo, &pool_fixture.pool.address, &i128::MAX, &50000); + + fixture.jump(60 * 60); // 1 hr + assert_eq!( + 0, + fixture.tokens[TokenIndex::BLND].balance(&fixture.backstop.address) + ); + + fixture.env.budget().reset_unlimited(); + fixture +} + #[cfg(test)] mod tests { diff --git a/test-suites/tests/test_emitter.rs b/test-suites/tests/test_emitter.rs index 766e5334..6f7890f1 100644 --- a/test-suites/tests/test_emitter.rs +++ b/test-suites/tests/test_emitter.rs @@ -1,15 +1,142 @@ #![cfg(test)] use emitter::Swap; +use pool::{Request, RequestType}; use soroban_sdk::{ testutils::{Address as _, Events}, - vec, Address, IntoVal, Symbol, + vec as svec, Address, IntoVal, Symbol, Vec as SVec, }; use test_suites::{ - create_fixture_with_data, + create_fixture_no_rzone_add, create_fixture_with_data, test_fixture::{TokenIndex, SCALAR_7}, }; +/// Test user exposed functions on the emitter for basic functionality, auth, and events. +/// Does not test internal state management of the emitter, only external effects. +#[test] +fn test_emitter_no_reward_zone() { + let fixture = create_fixture_no_rzone_add(false); + let frodo = &fixture.users[0]; + let pool_fixture = &fixture.pools[0]; + let blnd_token = &fixture.tokens[TokenIndex::BLND]; + blnd_token.balance(&fixture.emitter.address); + blnd_token.balance(&fixture.backstop.address); + + // Allow 6 days to pass and call distribute + // @dev: 1h1m have passed since the emitter was deployed during setup + assert_eq!(blnd_token.balance(&fixture.backstop.address), 0); + fixture.jump(6 * 24 * 60 * 60); + let result = fixture.emitter.distribute(); + assert_eq!(result, (13 * 24 * 60 * 60 + 61 * 60) * SCALAR_7); // 1 token per second are emitted + let result = fixture.backstop.try_gulp_emissions(); + assert!(result.is_err()); + + assert_eq!(fixture.env.auths().len(), 0); + assert_eq!( + blnd_token.balance(&fixture.backstop.address), + (13 * 24 * 60 * 60 + 61 * 60) * SCALAR_7 + ); // 1 token per second are emitted + assert_eq!(fixture.env.auths().len(), 0); + // Validate Emissions can't be claimed + let result = pool_fixture.pool.claim( + &fixture.users[0], + &svec![&fixture.env, 0, 1, 2], + &fixture.users[0], + ); + assert!(result == 0); + let result = fixture.backstop.claim( + &fixture.users[0], + &svec![&fixture.env, pool_fixture.pool.address.clone()], + &fixture.users[0], + ); + assert!(result == 0); + + fixture.backstop.deposit( + &fixture.users[0], + &pool_fixture.pool.address, + &(50_000 * SCALAR_7), + ); + fixture.backstop.update_tkn_val(); + pool_fixture.pool.set_status(&3); + pool_fixture.pool.update_status(); + // supply and borrow STABLE for 80% utilization (close to target) + let requests: SVec = svec![ + &fixture.env, + Request { + request_type: RequestType::SupplyCollateral as u32, + address: fixture.tokens[TokenIndex::STABLE].address.clone(), + amount: 10_000 * 10i128.pow(6), + }, + Request { + request_type: RequestType::Borrow as u32, + address: fixture.tokens[TokenIndex::STABLE].address.clone(), + amount: 8_000 * 10i128.pow(6), + }, + ]; + pool_fixture.pool.submit(&frodo, &frodo, &frodo, &requests); + + // supply and borrow WETH for 50% utilization (below target) + let requests: SVec = svec![ + &fixture.env, + Request { + request_type: RequestType::SupplyCollateral as u32, + address: fixture.tokens[TokenIndex::WETH].address.clone(), + amount: 10 * 10i128.pow(9), + }, + Request { + request_type: RequestType::Borrow as u32, + address: fixture.tokens[TokenIndex::WETH].address.clone(), + amount: 5 * 10i128.pow(9), + }, + ]; + pool_fixture.pool.submit(&frodo, &frodo, &frodo, &requests); + + // supply and borrow XLM for 65% utilization (above target) + let requests: SVec = svec![ + &fixture.env, + Request { + request_type: RequestType::SupplyCollateral as u32, + address: fixture.tokens[TokenIndex::XLM].address.clone(), + amount: 100_000 * SCALAR_7, + }, + Request { + request_type: RequestType::Borrow as u32, + address: fixture.tokens[TokenIndex::XLM].address.clone(), + amount: 65_000 * SCALAR_7, + }, + ]; + pool_fixture.pool.submit(&frodo, &frodo, &frodo, &requests); + + fixture + .backstop + .add_reward(&pool_fixture.pool.address, &Address::generate(&fixture.env)); + fixture.backstop.gulp_emissions(); + + let result = pool_fixture.pool.gulp_emissions(); + assert_eq!(result, (13 * 24 * 60 * 60 + 61 * 60) * 300_0000); + // Let some time go by + fixture.jump(7 * 24 * 60 * 60); + let pre_claim_balance = blnd_token.balance(&fixture.users[0]); + let result = pool_fixture.pool.claim( + &fixture.users[0], + &svec![&fixture.env, 0, 1, 2, 3,], + &fixture.users[0], + ); + let post_claim_1_balance = blnd_token.balance(&fixture.users[0]); + assert_eq!(post_claim_1_balance - pre_claim_balance, result); + assert_eq!(result, (13 * 24 * 60 * 60 + 61 * 60) * 300_0000 - 300000); //pool claim is only 30% of the total emissions + let result_1 = fixture.backstop.claim( + &fixture.users[0], + &svec![&fixture.env, pool_fixture.pool.address.clone()], + &fixture.users[0], + ); + assert_eq!( + result_1 + result, + (13 * 24 * 60 * 60 + 61 * 60) * SCALAR_7 - 400000 + ); + assert_eq!(result_1, (13 * 24 * 60 * 60 + 61 * 60) * 700_0000 - 100000); +} + /// Test user exposed functions on the emitter for basic functionality, auth, and events. /// Does not test internal state management of the emitter, only external effects. #[test] @@ -40,6 +167,7 @@ fn test_emitter() { let result = fixture.emitter.distribute(); backstop_blnd_balance += result; assert_eq!(fixture.env.auths().len(), 0); + println!("timestamp: {}", fixture.env.ledger().timestamp()); assert_eq!(result, (6 * 24 * 60 * 60 + 61 * 60) * SCALAR_7); // 1 token per second are emitted assert_eq!( blnd_token.balance(&fixture.emitter.address), @@ -49,15 +177,15 @@ fn test_emitter() { blnd_token.balance(&fixture.backstop.address), backstop_blnd_balance ); - let event = vec![&fixture.env, fixture.env.events().all().last_unchecked()]; + let event = svec![&fixture.env, fixture.env.events().all().last_unchecked()]; assert_eq!( event, - vec![ + svec![ &fixture.env, ( fixture.emitter.address.clone(), (Symbol::new(&fixture.env, "distribute"),).into_val(&fixture.env), - vec![ + svec![ &fixture.env, fixture.backstop.address.to_val(), result.into_val(&fixture.env) @@ -74,7 +202,7 @@ fn test_emitter() { fixture.tokens[TokenIndex::USDC].mint(&new_backstop, &(20_501 * SCALAR_7)); fixture.lp.join_pool( &(old_backstop_balance + 1), - &vec![&fixture.env, 505_001 * SCALAR_7, 13_501 * SCALAR_7], + &svec![&fixture.env, 505_001 * SCALAR_7, 13_501 * SCALAR_7], &new_backstop, ); fixture @@ -86,10 +214,10 @@ fn test_emitter() { fixture.emitter.get_backstop(), fixture.backstop.address.clone() ); - let event = vec![&fixture.env, fixture.env.events().all().last_unchecked()]; + let event = svec![&fixture.env, fixture.env.events().all().last_unchecked()]; assert_eq!( event, - vec![ + svec![ &fixture.env, ( fixture.emitter.address.clone(), @@ -115,10 +243,10 @@ fn test_emitter() { fixture.emitter.get_backstop(), fixture.backstop.address.clone() ); - let event = vec![&fixture.env, fixture.env.events().all().last_unchecked()]; + let event = svec![&fixture.env, fixture.env.events().all().last_unchecked()]; assert_eq!( event, - vec![ + svec![ &fixture.env, ( fixture.emitter.address.clone(), @@ -141,10 +269,10 @@ fn test_emitter() { let swap_unlock_time = fixture.env.ledger().timestamp() + 31 * 24 * 60 * 60; fixture.jump(swap_unlock_time + 1); fixture.emitter.swap_backstop(); - let event = vec![&fixture.env, fixture.env.events().all().last_unchecked()]; + let event = svec![&fixture.env, fixture.env.events().all().last_unchecked()]; assert_eq!( event, - vec![ + svec![ &fixture.env, ( fixture.emitter.address.clone(), From 7b6d8f6358b2a54ee14e3a1bc8a4be8488be279a Mon Sep 17 00:00:00 2001 From: markuspluna <59978114+markuspluna@users.noreply.github.com> Date: Wed, 27 Mar 2024 12:53:34 +0300 Subject: [PATCH 2/2] requested changed --- test-suites/src/lib.rs | 2 +- test-suites/src/setup.rs | 97 ---------------------- test-suites/tests/test_emitter.rs | 128 +++++++++++++++++------------- 3 files changed, 76 insertions(+), 151 deletions(-) diff --git a/test-suites/src/lib.rs b/test-suites/src/lib.rs index c7c35c30..e32c4c4d 100644 --- a/test-suites/src/lib.rs +++ b/test-suites/src/lib.rs @@ -6,7 +6,7 @@ pub mod oracle; pub mod pool; pub mod pool_factory; mod setup; -pub use setup::{create_fixture_no_rzone_add, create_fixture_with_data}; +pub use setup::create_fixture_with_data; pub mod assertions; pub mod test_fixture; pub mod token; diff --git a/test-suites/src/setup.rs b/test-suites/src/setup.rs index 51c04d4d..3912cb06 100644 --- a/test-suites/src/setup.rs +++ b/test-suites/src/setup.rs @@ -159,103 +159,6 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> TestFixture<'a> { fixture } -/// Create a test fixture with a pool and a whale depositing and borrowing all assets -pub fn create_fixture_no_rzone_add<'a>(wasm: bool) -> TestFixture<'a> { - let mut fixture = TestFixture::create(wasm); - // mint whale tokens - let frodo = Address::generate(&fixture.env); - fixture.users.push(frodo.clone()); - fixture.tokens[TokenIndex::STABLE].mint(&frodo, &(100_000 * 10i128.pow(6))); - fixture.tokens[TokenIndex::XLM].mint(&frodo, &(1_000_000 * SCALAR_7)); - fixture.tokens[TokenIndex::WETH].mint(&frodo, &(100 * 10i128.pow(9))); - - // mint LP tokens with whale - fixture.tokens[TokenIndex::BLND].mint(&frodo, &(500_0010_000_0000_0000 * SCALAR_7)); - // fixture.tokens[TokenIndex::BLND].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); - fixture.tokens[TokenIndex::USDC].mint(&frodo, &(12_5010_000_0000_0000 * SCALAR_7)); - // fixture.tokens[TokenIndex::USDC].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); - fixture.lp.join_pool( - &(500_000_0000 * SCALAR_7), - &svec![ - &fixture.env, - 500_0010_000_0000_0000 * SCALAR_7, - 12_5010_000_0000_0000 * SCALAR_7, - ], - &frodo, - ); - - // create pool - fixture.create_pool(Symbol::new(&fixture.env, "Teapot"), 0_1000000, 6); - - let mut stable_config = default_reserve_metadata(); - stable_config.decimals = 6; - stable_config.c_factor = 0_900_0000; - stable_config.l_factor = 0_950_0000; - stable_config.util = 0_850_0000; - fixture.create_pool_reserve(0, TokenIndex::STABLE, &stable_config); - - let mut xlm_config = default_reserve_metadata(); - xlm_config.c_factor = 0_750_0000; - xlm_config.l_factor = 0_750_0000; - xlm_config.util = 0_500_0000; - fixture.create_pool_reserve(0, TokenIndex::XLM, &xlm_config); - - let mut weth_config = default_reserve_metadata(); - weth_config.decimals = 9; - weth_config.c_factor = 0_800_0000; - weth_config.l_factor = 0_800_0000; - weth_config.util = 0_700_0000; - fixture.create_pool_reserve(0, TokenIndex::WETH, &weth_config); - - // enable emissions for pool - let pool_fixture = &fixture.pools[0]; - - let reserve_emissions: soroban_sdk::Vec = soroban_sdk::vec![ - &fixture.env, - ReserveEmissionMetadata { - res_index: 0, // STABLE - res_type: 0, // d_token - share: 0_600_0000 - }, - ReserveEmissionMetadata { - res_index: 1, // XLM - res_type: 1, // b_token - share: 0_400_0000 - }, - ]; - pool_fixture.pool.set_emissions_config(&reserve_emissions); - - // deposit into backstop - - // enable emissions - // fixture.emitter.distribute(); - - fixture.jump(60); - - // fixture.tokens[TokenIndex::STABLE].approve( - // &frodo, - // &pool_fixture.pool.address, - // &i128::MAX, - // &(fixture.env.ledger().sequence() + 100), - // ); - // fixture.tokens[TokenIndex::WETH].approve( - // &frodo, - // &pool_fixture.pool.address, - // &i128::MAX, - // &(fixture.env.ledger().sequence() + 100), - // ); - // fixture.tokens[TokenIndex::XLM].approve(&frodo, &pool_fixture.pool.address, &i128::MAX, &50000); - - fixture.jump(60 * 60); // 1 hr - assert_eq!( - 0, - fixture.tokens[TokenIndex::BLND].balance(&fixture.backstop.address) - ); - - fixture.env.budget().reset_unlimited(); - fixture -} - #[cfg(test)] mod tests { diff --git a/test-suites/tests/test_emitter.rs b/test-suites/tests/test_emitter.rs index 6f7890f1..dee2c598 100644 --- a/test-suites/tests/test_emitter.rs +++ b/test-suites/tests/test_emitter.rs @@ -1,21 +1,85 @@ #![cfg(test)] use emitter::Swap; -use pool::{Request, RequestType}; +use pool::{Request, RequestType, ReserveEmissionMetadata}; use soroban_sdk::{ testutils::{Address as _, Events}, vec as svec, Address, IntoVal, Symbol, Vec as SVec, }; use test_suites::{ - create_fixture_no_rzone_add, create_fixture_with_data, - test_fixture::{TokenIndex, SCALAR_7}, + create_fixture_with_data, + pool::default_reserve_metadata, + test_fixture::{TestFixture, TokenIndex, SCALAR_7}, }; /// Test user exposed functions on the emitter for basic functionality, auth, and events. /// Does not test internal state management of the emitter, only external effects. #[test] fn test_emitter_no_reward_zone() { - let fixture = create_fixture_no_rzone_add(false); + let mut fixture = TestFixture::create(false); + // mint whale tokens + let frodo = Address::generate(&fixture.env); + fixture.users.push(frodo.clone()); + fixture.tokens[TokenIndex::STABLE].mint(&frodo, &(100_000 * 10i128.pow(6))); + fixture.tokens[TokenIndex::XLM].mint(&frodo, &(1_000_000 * SCALAR_7)); + fixture.tokens[TokenIndex::WETH].mint(&frodo, &(100 * 10i128.pow(9))); + + // mint LP tokens with whale + fixture.tokens[TokenIndex::BLND].mint(&frodo, &(500_0010_000_0000_0000 * SCALAR_7)); + // fixture.tokens[TokenIndex::BLND].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); + fixture.tokens[TokenIndex::USDC].mint(&frodo, &(12_5010_000_0000_0000 * SCALAR_7)); + // fixture.tokens[TokenIndex::USDC].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); + fixture.lp.join_pool( + &(500_000_0000 * SCALAR_7), + &svec![ + &fixture.env, + 500_0010_000_0000_0000 * SCALAR_7, + 12_5010_000_0000_0000 * SCALAR_7, + ], + &frodo, + ); + + // create pool + fixture.create_pool(Symbol::new(&fixture.env, "Teapot"), 0_1000000, 6); + + let mut stable_config = default_reserve_metadata(); + stable_config.decimals = 6; + stable_config.c_factor = 0_900_0000; + stable_config.l_factor = 0_950_0000; + stable_config.util = 0_850_0000; + fixture.create_pool_reserve(0, TokenIndex::STABLE, &stable_config); + + let mut xlm_config = default_reserve_metadata(); + xlm_config.c_factor = 0_750_0000; + xlm_config.l_factor = 0_750_0000; + xlm_config.util = 0_500_0000; + fixture.create_pool_reserve(0, TokenIndex::XLM, &xlm_config); + + let mut weth_config = default_reserve_metadata(); + weth_config.decimals = 9; + weth_config.c_factor = 0_800_0000; + weth_config.l_factor = 0_800_0000; + weth_config.util = 0_700_0000; + fixture.create_pool_reserve(0, TokenIndex::WETH, &weth_config); + + // enable emissions for pool + let pool_fixture = &fixture.pools[0]; + + let reserve_emissions: soroban_sdk::Vec = soroban_sdk::vec![ + &fixture.env, + ReserveEmissionMetadata { + res_index: 1, // XLM + res_type: 1, // b_token + share: 1_000_0000 + }, + ]; + pool_fixture.pool.set_emissions_config(&reserve_emissions); + assert_eq!( + 0, + fixture.tokens[TokenIndex::BLND].balance(&fixture.backstop.address) + ); + + fixture.env.budget().reset_unlimited(); let frodo = &fixture.users[0]; let pool_fixture = &fixture.pools[0]; let blnd_token = &fixture.tokens[TokenIndex::BLND]; @@ -23,24 +87,23 @@ fn test_emitter_no_reward_zone() { blnd_token.balance(&fixture.backstop.address); // Allow 6 days to pass and call distribute - // @dev: 1h1m have passed since the emitter was deployed during setup assert_eq!(blnd_token.balance(&fixture.backstop.address), 0); fixture.jump(6 * 24 * 60 * 60); let result = fixture.emitter.distribute(); - assert_eq!(result, (13 * 24 * 60 * 60 + 61 * 60) * SCALAR_7); // 1 token per second are emitted + assert_eq!(result, (13 * 24 * 60 * 60) * SCALAR_7); // 1 token per second are emitted let result = fixture.backstop.try_gulp_emissions(); assert!(result.is_err()); assert_eq!(fixture.env.auths().len(), 0); assert_eq!( blnd_token.balance(&fixture.backstop.address), - (13 * 24 * 60 * 60 + 61 * 60) * SCALAR_7 + (13 * 24 * 60 * 60) * SCALAR_7 ); // 1 token per second are emitted assert_eq!(fixture.env.auths().len(), 0); // Validate Emissions can't be claimed let result = pool_fixture.pool.claim( &fixture.users[0], - &svec![&fixture.env, 0, 1, 2], + &svec![&fixture.env, 0, 1, 2, 3], &fixture.users[0], ); assert!(result == 0); @@ -59,39 +122,7 @@ fn test_emitter_no_reward_zone() { fixture.backstop.update_tkn_val(); pool_fixture.pool.set_status(&3); pool_fixture.pool.update_status(); - // supply and borrow STABLE for 80% utilization (close to target) - let requests: SVec = svec![ - &fixture.env, - Request { - request_type: RequestType::SupplyCollateral as u32, - address: fixture.tokens[TokenIndex::STABLE].address.clone(), - amount: 10_000 * 10i128.pow(6), - }, - Request { - request_type: RequestType::Borrow as u32, - address: fixture.tokens[TokenIndex::STABLE].address.clone(), - amount: 8_000 * 10i128.pow(6), - }, - ]; - pool_fixture.pool.submit(&frodo, &frodo, &frodo, &requests); - // supply and borrow WETH for 50% utilization (below target) - let requests: SVec = svec![ - &fixture.env, - Request { - request_type: RequestType::SupplyCollateral as u32, - address: fixture.tokens[TokenIndex::WETH].address.clone(), - amount: 10 * 10i128.pow(9), - }, - Request { - request_type: RequestType::Borrow as u32, - address: fixture.tokens[TokenIndex::WETH].address.clone(), - amount: 5 * 10i128.pow(9), - }, - ]; - pool_fixture.pool.submit(&frodo, &frodo, &frodo, &requests); - - // supply and borrow XLM for 65% utilization (above target) let requests: SVec = svec![ &fixture.env, Request { @@ -99,11 +130,6 @@ fn test_emitter_no_reward_zone() { address: fixture.tokens[TokenIndex::XLM].address.clone(), amount: 100_000 * SCALAR_7, }, - Request { - request_type: RequestType::Borrow as u32, - address: fixture.tokens[TokenIndex::XLM].address.clone(), - amount: 65_000 * SCALAR_7, - }, ]; pool_fixture.pool.submit(&frodo, &frodo, &frodo, &requests); @@ -113,7 +139,7 @@ fn test_emitter_no_reward_zone() { fixture.backstop.gulp_emissions(); let result = pool_fixture.pool.gulp_emissions(); - assert_eq!(result, (13 * 24 * 60 * 60 + 61 * 60) * 300_0000); + assert_eq!(result, (13 * 24 * 60 * 60) * 300_0000); // Let some time go by fixture.jump(7 * 24 * 60 * 60); let pre_claim_balance = blnd_token.balance(&fixture.users[0]); @@ -124,17 +150,14 @@ fn test_emitter_no_reward_zone() { ); let post_claim_1_balance = blnd_token.balance(&fixture.users[0]); assert_eq!(post_claim_1_balance - pre_claim_balance, result); - assert_eq!(result, (13 * 24 * 60 * 60 + 61 * 60) * 300_0000 - 300000); //pool claim is only 30% of the total emissions + assert_eq!(result, (13 * 24 * 60 * 60) * 300_0000 - 400000); //pool claim is only 30% of the total emissions - subtracting 400000 for rounding let result_1 = fixture.backstop.claim( &fixture.users[0], &svec![&fixture.env, pool_fixture.pool.address.clone()], &fixture.users[0], ); - assert_eq!( - result_1 + result, - (13 * 24 * 60 * 60 + 61 * 60) * SCALAR_7 - 400000 - ); - assert_eq!(result_1, (13 * 24 * 60 * 60 + 61 * 60) * 700_0000 - 100000); + assert_eq!(result_1, (13 * 24 * 60 * 60) * 700_0000); + assert_eq!(result_1 + result, (13 * 24 * 60 * 60) * SCALAR_7 - 400000); } /// Test user exposed functions on the emitter for basic functionality, auth, and events. @@ -167,7 +190,6 @@ fn test_emitter() { let result = fixture.emitter.distribute(); backstop_blnd_balance += result; assert_eq!(fixture.env.auths().len(), 0); - println!("timestamp: {}", fixture.env.ledger().timestamp()); assert_eq!(result, (6 * 24 * 60 * 60 + 61 * 60) * SCALAR_7); // 1 token per second are emitted assert_eq!( blnd_token.balance(&fixture.emitter.address),