diff --git a/comet.wasm b/comet.wasm index 193b33da..a6a14345 100644 Binary files a/comet.wasm and b/comet.wasm differ diff --git a/pool/src/contract.rs b/pool/src/contract.rs index e804d1c0..25b8cbc5 100644 --- a/pool/src/contract.rs +++ b/pool/src/contract.rs @@ -39,6 +39,15 @@ pub trait Pool { usdc_id: Address, ); + /// (Admin only) Set a new address as the admin of this pool + /// + /// ### Arguments + /// * `new_admin` - The new admin address + /// + /// ### Panics + /// If the caller is not the admin + fn set_admin(e: Env, new_admin: Address); + /// (Admin only) Update the pool /// /// ### Arguments @@ -46,7 +55,7 @@ pub trait Pool { /// /// ### Panics /// If the caller is not the admin - fn update_pool(e: Env, backstiop_take_rate: u64); + fn update_pool(e: Env, backstop_take_rate: u64); /// (Admin only) Initialize a reserve in the pool /// @@ -233,6 +242,17 @@ impl Pool for PoolContract { ); } + fn set_admin(e: Env, new_admin: Address) { + storage::bump_instance(&e); + let admin = storage::get_admin(&e); + admin.require_auth(); + + storage::set_admin(&e, &new_admin); + + e.events() + .publish((Symbol::new(&e, "set_admin"), admin), new_admin); + } + fn update_pool(e: Env, backstop_take_rate: u64) { storage::bump_instance(&e); let admin = storage::get_admin(&e); diff --git a/test-suites/src/setup.rs b/test-suites/src/setup.rs index 5a8e2352..e62862e2 100644 --- a/test-suites/src/setup.rs +++ b/test-suites/src/setup.rs @@ -60,9 +60,9 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> TestFixture<'a> { // mint LP tokens with whale fixture.tokens[TokenIndex::BLND].mint(&frodo, &(500_001 * SCALAR_7)); - fixture.tokens[TokenIndex::BLND].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); + // fixture.tokens[TokenIndex::BLND].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); fixture.tokens[TokenIndex::USDC].mint(&frodo, &(12_501 * SCALAR_7)); - fixture.tokens[TokenIndex::USDC].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); + // fixture.tokens[TokenIndex::USDC].approve(&frodo, &fixture.lp.address, &i128::MAX, &99999); fixture.lp.join_pool( &(50_000 * SCALAR_7), &vec![&fixture.env, 500_001 * SCALAR_7, 12_501 * SCALAR_7], diff --git a/test-suites/tests/test_emitter.rs b/test-suites/tests/test_emitter.rs index 14034cc6..2cf9c1d5 100644 --- a/test-suites/tests/test_emitter.rs +++ b/test-suites/tests/test_emitter.rs @@ -72,7 +72,13 @@ fn test_emitter() { // Mint enough tokens to a new backstop address to perform a swap, then swap the backstops let old_backstop_balance = bstop_token.balance(&fixture.backstop.address); let new_backstop = Address::random(&fixture.env); - bstop_token.mint(&new_backstop, &(old_backstop_balance + 1)); + fixture.tokens[TokenIndex::BLND].mint(&new_backstop, &(505_001 * SCALAR_7)); + fixture.tokens[TokenIndex::USDC].mint(&new_backstop, &(13_501 * SCALAR_7)); + fixture.lp.join_pool( + &(old_backstop_balance + 1), + &vec![&fixture.env, 505_001 * SCALAR_7, 13_501 * SCALAR_7], + &new_backstop, + ); fixture.emitter.swap_backstop(&new_backstop); assert_eq!(fixture.env.auths().len(), 0); assert_eq!(fixture.emitter.get_backstop(), new_backstop.clone()); diff --git a/test-suites/tests/test_pool.rs b/test-suites/tests/test_pool.rs index 5f13fc6f..4a3ec7d2 100644 --- a/test-suites/tests/test_pool.rs +++ b/test-suites/tests/test_pool.rs @@ -535,7 +535,7 @@ fn test_pool_user() { /// Does not test internal state management of the lending pool, only external effects. #[test] fn test_pool_config() { - let fixture = create_fixture_with_data(true); + let fixture = create_fixture_with_data(false); let pool_fixture = &fixture.pools[0]; @@ -682,12 +682,46 @@ fn test_pool_config() { ] ); + // Set admin (admin only) + let new_admin = Address::random(&fixture.env); + pool_fixture.pool.set_admin(&new_admin); + assert_eq!( + fixture.env.auths()[0], + ( + fixture.bombadil.clone(), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + pool_fixture.pool.address.clone(), + Symbol::new(&fixture.env, "set_admin"), + vec![&fixture.env, new_admin.to_val(),] + )), + sub_invocations: std::vec![] + } + ) + ); + let event = vec![&fixture.env, fixture.env.events().all().last_unchecked()]; + assert_eq!( + event, + vec![ + &fixture.env, + ( + pool_fixture.pool.address.clone(), + ( + Symbol::new(&fixture.env, "set_admin"), + fixture.bombadil.clone() + ) + .into_val(&fixture.env), + new_admin.into_val(&fixture.env) + ) + ] + ); + // Set status (admin only) pool_fixture.pool.set_status(&1); assert_eq!( fixture.env.auths()[0], ( - fixture.bombadil.clone(), + new_admin.clone(), AuthorizedInvocation { function: AuthorizedFunction::Contract(( pool_fixture.pool.address.clone(), @@ -707,11 +741,7 @@ fn test_pool_config() { &fixture.env, ( pool_fixture.pool.address.clone(), - ( - Symbol::new(&fixture.env, "set_status"), - fixture.bombadil.clone() - ) - .into_val(&fixture.env), + (Symbol::new(&fixture.env, "set_status"), new_admin.clone()).into_val(&fixture.env), 1u32.into_val(&fixture.env) ) ] @@ -758,7 +788,7 @@ fn test_pool_config() { assert_eq!( fixture.env.auths()[0], ( - fixture.bombadil.clone(), + new_admin.clone(), AuthorizedInvocation { function: AuthorizedFunction::Contract(( pool_fixture.pool.address.clone(),