Skip to content

Commit

Permalink
chore: add new comet wasm with 256 bit math
Browse files Browse the repository at this point in the history
  • Loading branch information
mootz12 committed Apr 30, 2024
1 parent d09c98a commit 27ee315
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 59 deletions.
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
Binary file modified comet.wasm
100644 → 100755
Binary file not shown.
14 changes: 4 additions & 10 deletions pool/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,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)
}
6 changes: 3 additions & 3 deletions test-suites/tests/test_wasm_happy_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ fn test_wasm_happy_path() {
&vec![&fixture.env, pool_fixture.pool.address.clone()],
&frodo,
);
assert_eq!(claim_amount, 420798_0000000);
assert_eq!(claim_amount, 420797_9966204);
backstop_blnd_balance -= claim_amount;
assert_eq!(
fixture.tokens[TokenIndex::BLND].balance(&fixture.backstop.address),
Expand Down Expand Up @@ -433,8 +433,8 @@ fn test_wasm_happy_path() {
&vec![&fixture.env, pool_fixture.pool.address.clone()],
&frodo,
);
assert_eq!(claim_amount, 22014719_9998450); //actual amount is 22014720_0000000 but get's rounded down // 22014719_9998450
backstop_blnd_balance -= 22014719_9998450;
assert_eq!(claim_amount, 22014719_9894996); //actual amount is 22014720_0000000 but get's rounded down
backstop_blnd_balance -= 22014719_9894996;
assert_eq!(
fixture.tokens[TokenIndex::BLND].balance(&fixture.backstop.address),
backstop_blnd_balance
Expand Down

0 comments on commit 27ee315

Please sign in to comment.