Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comet update #143

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified comet.wasm
Binary file not shown.
22 changes: 21 additions & 1 deletion pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@ 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
/// * `backstop_take_rate` - The new take rate for the backstop
///
/// ### 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
///
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test-suites/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
8 changes: 7 additions & 1 deletion test-suites/tests/test_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
46 changes: 38 additions & 8 deletions test-suites/tests/test_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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(),
Expand All @@ -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)
)
]
Expand Down Expand Up @@ -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(),
Expand Down