Skip to content

Commit

Permalink
chore: add patched comet version and fix tests due to comet rounding …
Browse files Browse the repository at this point in the history
…update
  • Loading branch information
mootz12 committed May 1, 2024
1 parent daa1660 commit a1fcf09
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 119 deletions.
3 changes: 2 additions & 1 deletion backstop/src/dependencies/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pub use pool_factory::Client as PoolFactoryClient;

mod comet;
pub use comet::Client as CometClient;
#[cfg(any(test, feature = "testutils"))]

#[cfg(test)]
pub use comet::WASM as COMET_WASM;

mod emitter;
Expand Down
54 changes: 27 additions & 27 deletions backstop/src/emissions/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mod tests {
assert_eq!(result, 75_3145677 + 6_2904190);
assert_eq!(
lp_client.balance(&backstop_address),
backstop_lp_balance + 6_5244800
backstop_lp_balance + 6_4729326
);
assert_eq!(
blnd_token_client.balance(&backstop_address),
Expand All @@ -221,18 +221,18 @@ mod tests {
let sam_balance_1 = storage::get_user_balance(&e, &pool_1_id, &samwise);
assert_eq!(sam_balance_1.shares, 9_0000000);
let frodo_balance_1 = storage::get_user_balance(&e, &pool_1_id, &frodo);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_5761820);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_5400274);
let sam_balance_2 = storage::get_user_balance(&e, &pool_2_id, &samwise);
assert_eq!(sam_balance_2.shares, 7_5000000);
let frodo_balance_2 = storage::get_user_balance(&e, &pool_2_id, &frodo);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 0_3947102);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 0_3915917);

let pool_balance_1 = storage::get_pool_balance(&e, &pool_1_id);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 6_1015761);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_5761820);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 6_0533699);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_5400274);
let pool_balance_2 = storage::get_pool_balance(&e, &pool_2_id);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 0_4229038);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 0_3947102);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 0_4195626);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 0_3915917);

let new_backstop_1_data =
storage::get_backstop_emis_data(&e, &pool_1_id).unwrap_optimized();
Expand Down Expand Up @@ -371,7 +371,7 @@ mod tests {
assert_eq!(result, 75_3145677 + 6_2904190);
assert_eq!(
lp_client.balance(&backstop_address),
backstop_lp_balance + 6_5244800
backstop_lp_balance + 6_4729326
);
assert_eq!(
blnd_token_client.balance(&backstop_address),
Expand All @@ -380,18 +380,18 @@ mod tests {
let sam_balance_1 = storage::get_user_balance(&e, &pool_1_id, &samwise);
assert_eq!(sam_balance_1.shares, 9_0000000);
let frodo_balance_1 = storage::get_user_balance(&e, &pool_1_id, &frodo);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_5761820);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_5400274);
let sam_balance_2 = storage::get_user_balance(&e, &pool_2_id, &samwise);
assert_eq!(sam_balance_2.shares, 7_5000000);
let frodo_balance_2 = storage::get_user_balance(&e, &pool_2_id, &frodo);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 0_3947102);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 0_3915917);

let pool_balance_1 = storage::get_pool_balance(&e, &pool_1_id);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 6_1015761);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_5761820);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 6_0533699);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_5400274);
let pool_balance_2 = storage::get_pool_balance(&e, &pool_2_id);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 0_4229038);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 0_3947102);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 0_4195626);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 0_3915917);

let new_backstop_1_data =
storage::get_backstop_emis_data(&e, &pool_1_id).unwrap_optimized();
Expand Down Expand Up @@ -435,47 +435,47 @@ mod tests {
&vec![&e, pool_1_id.clone(), pool_2_id.clone()],
&frodo,
);
assert_eq!(result_1, 1005009202);
assert_eq!(result_1, 1005194703);
assert_eq!(
blnd_token_client.balance(&backstop_address),
200_0000000 - (75_3145677 + 6_2904190) - (1005009202)
200_0000000 - (75_3145677 + 6_2904190) - (1005194703)
);
assert_eq!(
lp_client.balance(&backstop_address),
backstop_lp_balance + 7_9137036
backstop_lp_balance + 7_7889107
);
let sam_balance_1 = storage::get_user_balance(&e, &pool_1_id, &samwise);
assert_eq!(sam_balance_1.shares, 9_0000000);
let frodo_balance_1 = storage::get_user_balance(&e, &pool_1_id, &frodo);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_3004891);
assert_eq!(frodo_balance_1.shares, pre_frodo_balance_1 + 4_2609092);
let sam_balance_2 = storage::get_user_balance(&e, &pool_2_id, &samwise);
assert_eq!(sam_balance_2.shares, 7_5000000);
let frodo_balance_2 = storage::get_user_balance(&e, &pool_2_id, &frodo);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 2_0344033);
assert_eq!(frodo_balance_2.shares, pre_frodo_balance_2 + 2_0152958);

let pool_balance_1 = storage::get_pool_balance(&e, &pool_1_id);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 5_7339856);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_3004891);
assert_eq!(pool_balance_1.tokens, pre_pool_tokens_1 + 5_6812124);
assert_eq!(pool_balance_1.shares, pre_pool_shares_1 + 4_2609092);
let pool_balance_2 = storage::get_pool_balance(&e, &pool_2_id);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 2_1797179);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 2_0344033);
assert_eq!(pool_balance_2.tokens, pre_pool_tokens_2 + 2_1592456);
assert_eq!(pool_balance_2.shares, pre_pool_shares_2 + 2_0152958);
let new_backstop_1_data =
storage::get_backstop_emis_data(&e, &pool_1_id).unwrap_optimized();
let new_user_1_data =
storage::get_user_emis_data(&e, &pool_1_id, &samwise).unwrap_optimized();
assert_eq!(new_backstop_1_data.last_time, block_timestamp_1);
assert_eq!(new_backstop_1_data.index, 164344784);
assert_eq!(new_backstop_1_data.index, 164363961);
assert_eq!(new_user_1_data.accrued, 0);
assert_eq!(new_user_1_data.index, 164344784);
assert_eq!(new_user_1_data.index, 164363961);

let new_backstop_2_data =
storage::get_backstop_emis_data(&e, &pool_2_id).unwrap_optimized();
let new_user_2_data =
storage::get_user_emis_data(&e, &pool_2_id, &samwise).unwrap_optimized();
assert_eq!(new_backstop_2_data.last_time, block_timestamp_1);
assert_eq!(new_backstop_2_data.index, 43961378);
assert_eq!(new_backstop_2_data.index, 43963099);
assert_eq!(new_user_2_data.accrued, 0);
assert_eq!(new_user_2_data.index, 43961378);
assert_eq!(new_user_2_data.index, 43963099);
});
}

Expand Down
14 changes: 4 additions & 10 deletions backstop/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,15 @@ pub(crate) fn create_comet_lp_pool<'a>(
let usdc_client = MockTokenClient::new(e, usdc_token);
blnd_client.mint(&admin, &1_000_0000000);
usdc_client.mint(&admin, &25_0000000);
let exp_ledger = e.ledger().sequence() + 100;
blnd_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);
usdc_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);

client.init(&Address::generate(e), &admin);
client.bundle_bind(
client.init(
admin,
&vec![e, blnd_token.clone(), usdc_token.clone()],
&vec![e, 0_8000000, 0_2000000],
&vec![e, 1_000_0000000, 25_0000000],
&vec![e, 8_0000000, 2_0000000],
&0_0030000,
);

client.set_swap_fee(&0_0030000, &admin);
client.set_public_swap(&admin, &true);
client.finalize();

(contract_address, client)
}

Expand Down
23 changes: 5 additions & 18 deletions blend-contract-sdk/src/testutils.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use soroban_sdk::{testutils::Address as _, token::StellarAssetClient, vec, Address, Env, Map};
use soroban_sdk::{token::StellarAssetClient, vec, Address, Env, Map};

use crate::{backstop, emitter, pool, pool_factory};

pub mod comet {
soroban_sdk::contractimport!(file = "./wasm/comet.wasm");
}

pub mod comet_factory {
soroban_sdk::contractimport!(file = "./wasm/comet_factory.wasm");
}

/// Create a "good enough" ReserveConfig for most testing usecases
///
/// Can be used when creating reserves for a pool.
Expand Down Expand Up @@ -70,22 +66,13 @@ impl<'a> BlendFixture<'a> {
.mint(deployer, &(25_0000000 * 2001));

let comet_client: comet::Client<'a> = comet::Client::new(env, &comet);
comet_client
.mock_all_auths()
.init(&Address::generate(env), deployer);

comet_client.mock_all_auths().bundle_bind(
comet_client.mock_all_auths().init(
&deployer,
&vec![env, blnd.clone(), usdc.clone()],
&vec![env, 0_8000000, 0_2000000],
&vec![env, 1_000_0000000, 25_0000000],
&vec![env, 8_0000000, 2_0000000],
&0_0030000,
);
comet_client
.mock_all_auths()
.set_swap_fee(&30000_i128, deployer);
comet_client
.mock_all_auths()
.set_public_swap(deployer, &true);
comet_client.mock_all_auths().finalize();

comet_client.mock_all_auths().join_pool(
&199_900_0000000, // finalize mints 100
Expand Down
Binary file modified comet.wasm
100644 → 100755
Binary file not shown.
2 changes: 0 additions & 2 deletions pool/src/dependencies/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
mod backstop;
#[cfg(any(test, feature = "testutils"))]
pub use backstop::{BackstopDataKey, WASM as BACKSTOP_WASM};
pub use backstop::{Client as BackstopClient, PoolBackstopData};
14 changes: 4 additions & 10 deletions pool/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,15 @@ pub(crate) fn create_comet_lp_pool<'a>(
let usdc_client = MockTokenClient::new(e, usdc_token);
blnd_client.mint(&admin, &1_000_0000000);
usdc_client.mint(&admin, &25_0000000);
let exp_ledger = e.ledger().sequence() + 100;
blnd_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);
usdc_client.approve(&admin, &contract_address, &2_000_0000000, &exp_ledger);

client.init(&Address::generate(e), &admin);
client.bundle_bind(
client.init(
admin,
&vec![e, blnd_token.clone(), usdc_token.clone()],
&vec![e, 0_8000000, 0_2000000],
&vec![e, 1_000_0000000, 25_0000000],
&vec![e, 8_0000000, 2_0000000],
&0_0030000,
);

client.set_swap_fee(&0_0030000, &admin);
client.set_public_swap(&admin, &true);
client.finalize();

(contract_address, client)
}

Expand Down
13 changes: 4 additions & 9 deletions test-suites/src/liquidity_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ pub(crate) fn create_lp_pool<'a>(
let token_2_client = MockTokenClient::new(e, token_2);
token_1_client.mint(&admin, &1_000_0000000);
token_2_client.mint(&admin, &25_0000000);
token_1_client.approve(&admin, &contract_address, &1_000_0000000, &5356700);
token_2_client.approve(&admin, &contract_address, &1_000_0000000, &5356700);

client.init(&Address::generate(e), &admin);
client.bundle_bind(
client.init(
admin,
&vec![e, token_1.clone(), token_2.clone()],
&vec![e, 0_8000000, 0_2000000],
&vec![e, 1_000_0000000, 25_0000000],
&vec![e, 8_0000000, 2_0000000],
&0_0030000,
);

client.set_swap_fee(&0_0030000, &admin);
client.set_public_swap(&admin, &true);
client.finalize();

(contract_address, client)
}
43 changes: 16 additions & 27 deletions test-suites/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,18 @@ pub fn create_fixture_with_data<'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());
let frodo = fixture.users[0].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);
// frodo has 40m BLND from drop
fixture.tokens[TokenIndex::BLND].mint(&frodo, &(70_000_000 * SCALAR_7));
fixture.tokens[TokenIndex::USDC].mint(&frodo, &(2_600_000 * SCALAR_7));
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,
],
&(10_000_000 * SCALAR_7),
&svec![&fixture.env, 110_000_000 * SCALAR_7, 2_600_000 * SCALAR_7,],
&frodo,
);

Expand Down Expand Up @@ -91,20 +85,6 @@ pub fn create_fixture_with_data<'a>(wasm: bool) -> TestFixture<'a> {

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);

// supply and borrow STABLE for 80% utilization (close to target)
let requests: SVec<Request> = svec![
&fixture.env,
Expand Down Expand Up @@ -172,11 +152,15 @@ mod tests {
let frodo = fixture.users.get(0).unwrap();
let pool_fixture: &PoolFixture = fixture.pools.get(0).unwrap();

// validate backstop deposit
// validate backstop deposit and drop
assert_eq!(
50_000 * SCALAR_7,
fixture.lp.balance(&fixture.backstop.address)
);
assert_eq!(
10_000_000 * SCALAR_7,
fixture.tokens[TokenIndex::BLND].balance(&fixture.bombadil)
);

// validate pool actions
assert_eq!(
Expand Down Expand Up @@ -224,11 +208,16 @@ mod tests {
let fixture = create_fixture_with_data(false);
let frodo = fixture.users.get(0).unwrap();
let pool_fixture: &PoolFixture = fixture.pools.get(0).unwrap();

// validate backstop deposit
assert_eq!(
50_000 * SCALAR_7,
fixture.lp.balance(&fixture.backstop.address)
);
assert_eq!(
10_000_000 * SCALAR_7,
fixture.tokens[TokenIndex::BLND].balance(&fixture.bombadil)
);

// validate pool actions
assert_eq!(
Expand Down
18 changes: 6 additions & 12 deletions test-suites/tests/test_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,18 @@ use test_suites::{
fn test_emitter_no_reward_zone() {
let mut fixture = TestFixture::create(false);
// mint whale tokens
let frodo = Address::generate(&fixture.env);
fixture.users.push(frodo.clone());
let frodo = fixture.users[0].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);
// frodo has 40m BLND from drop
fixture.tokens[TokenIndex::BLND].mint(&frodo, &(70_000_000 * SCALAR_7));
fixture.tokens[TokenIndex::USDC].mint(&frodo, &(2_600_000 * SCALAR_7));
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,
],
&(10_000_000 * SCALAR_7),
&svec![&fixture.env, 110_000_000 * SCALAR_7, 2_600_000 * SCALAR_7,],
&frodo,
);

Expand Down
Loading

0 comments on commit a1fcf09

Please sign in to comment.