Skip to content

Commit

Permalink
Merge pull request #6 from blend-capital/prep-1.1.0
Browse files Browse the repository at this point in the history
chore: use pubnet comet wasm and patch testing gaps
  • Loading branch information
mootz12 authored Jun 28, 2024
2 parents ee958e4 + 11ffa70 commit a3b2ed2
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "backstop_bootstrapper"
version = "1.0.0"
version = "1.1.0"
authors = ["Script3 Ltd. <[email protected]>"]
license = "AGPL-3.0"
edition = "2021"
Expand Down
Binary file modified comet.wasm
100755 → 100644
Binary file not shown.
1 change: 0 additions & 1 deletion src/tests/test_claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ fn test_claim_twice() {
let blnd_client = StellarAssetClient::new(&e, &blnd);
let blnd_token = TokenClient::new(&e, &blnd);
let usdc_client = StellarAssetClient::new(&e, &usdc);
let usdc_token = TokenClient::new(&e, &usdc);

let blend_fixture = BlendFixture::deploy(&e, &bombadil, &blnd, &usdc);
let pool_address = blend_fixture.pool_factory.deploy(
Expand Down
6 changes: 6 additions & 0 deletions src/tests/test_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ fn test_close_validates_status() {

let result = bootstrap_client.try_close(&id);
assert_eq!(result.err(), Some(Ok(Error::from_contract_error(104))));

// verify close cannot be run once cancelled
e.jump(14 * ONE_DAY_LEDGERS + 2);

let result = bootstrap_client.try_close(&id);
assert_eq!(result.err(), Some(Ok(Error::from_contract_error(104))));
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions src/tests/test_create_bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ fn test_bootstrap_validates_config() {
let result = bootstrap_client.try_bootstrap(&config_close_long);
assert_eq!(result.err(), Some(Ok(Error::from_contract_error(100))));

let mut config_close_pre_ledger = config.clone();
config_close_pre_ledger.close_ledger = e.ledger().sequence() - 1;
let result = bootstrap_client.try_bootstrap(&config_close_long);
assert_eq!(result.err(), Some(Ok(Error::from_contract_error(100))));

// pool
let mut config_pool = config.clone();
config_pool.pool = Address::generate(&e);
Expand Down
173 changes: 173 additions & 0 deletions src/tests/test_refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,179 @@ fn test_refund_pair_after_partial_close() {
assert_eq!(result.err(), Some(Ok(Error::from_contract_error(108))));
}

#[test]
fn test_refund_pair_after_partial_close_multiple_joiners() {
let e = Env::default();
e.budget().reset_unlimited();
e.set_default_info();
e.mock_all_auths_allowing_non_root_auth();

let bombadil = Address::generate(&e);
let frodo = Address::generate(&e);
let samwise = Address::generate(&e);
let pippin = Address::generate(&e);
let sauron = Address::generate(&e);

let blnd = e.register_stellar_asset_contract(bombadil.clone());
let usdc = e.register_stellar_asset_contract(bombadil.clone());
let blnd_client = StellarAssetClient::new(&e, &blnd);
let blnd_token = TokenClient::new(&e, &blnd);
let usdc_client = StellarAssetClient::new(&e, &usdc);
let usdc_token = TokenClient::new(&e, &usdc);

let blend_fixture = BlendFixture::deploy(&e, &bombadil, &blnd, &usdc);
let pool_address = blend_fixture.pool_factory.deploy(
&bombadil,
&String::from_str(&e, "test"),
&BytesN::<32>::random(&e),
&Address::generate(&e),
&0,
&2,
);
let bootstrapper = testutils::create_bootstrapper(&e, &blend_fixture);
let bootstrap_client = BackstopBootstrapperClient::new(&e, &bootstrapper);

let bootstrap_amount = 1000 * SCALAR_7;
blnd_client.mint(&frodo, &bootstrap_amount);
let config = BootstrapConfig {
pair_min: 1 * SCALAR_7,
close_ledger: e.ledger().sequence() + ONE_DAY_LEDGERS,
bootstrapper: frodo.clone(),
pool: pool_address.clone(),
amount: bootstrap_amount,
token_index: 0,
};
let id = bootstrap_client.bootstrap(&config);
assert_eq!(bootstrap_amount, blnd_token.balance(&bootstrapper));
assert_eq!(0, blnd_token.balance(&frodo));

let join_amount_samwise = 20000000 * SCALAR_7;
usdc_client.mint(&samwise, &join_amount_samwise);
bootstrap_client.join(&samwise, &id, &join_amount_samwise);
assert_eq!(join_amount_samwise, usdc_token.balance(&bootstrapper));
assert_eq!(0, usdc_token.balance(&samwise));

let join_amount_pippin = 5000000 * SCALAR_7;
usdc_client.mint(&pippin, &join_amount_pippin);
bootstrap_client.join(&pippin, &id, &join_amount_pippin);
assert_eq!(
join_amount_pippin + join_amount_samwise,
usdc_token.balance(&bootstrapper)
);
assert_eq!(0, usdc_token.balance(&pippin));

let share_samwise = join_amount_samwise
.fixed_div_floor(join_amount_pippin + join_amount_samwise, SCALAR_7)
.unwrap();
let share_pippin = join_amount_pippin
.fixed_div_floor(join_amount_pippin + join_amount_samwise, SCALAR_7)
.unwrap();

// partial close
e.jump(ONE_DAY_LEDGERS + 1);
bootstrap_client.close(&id);
let backstop_tokens = blend_fixture
.backstop_token
.balance(&bootstrap_client.address);
let claim_joiners = backstop_tokens
.fixed_mul_floor(200_0000 as i128, SCALAR_7)
.unwrap();
let refund_joiners = usdc_token.balance(&bootstrapper);

// window for close expries
e.jump(14 * ONE_DAY_LEDGERS);

// refund non-joiner
let result = bootstrap_client.refund(&sauron, &id);
assert_eq!(result, 0);
assert_eq!(0, usdc_token.balance(&sauron));

// claim pippin
let claim_amount_pippin = claim_joiners
.fixed_mul_floor(share_pippin, SCALAR_7)
.unwrap();
let claimed_pippin = bootstrap_client.claim(&pippin, &id);
assert_approx_eq_abs(claim_amount_pippin, claimed_pippin, MAX_DUST_AMOUNT);
assert_approx_eq_abs(
claim_amount_pippin,
blend_fixture
.backstop
.user_balance(&pool_address, &pippin)
.shares,
MAX_DUST_AMOUNT,
);

// claim bootstrapper
let claim_amount = backstop_tokens
.fixed_mul_floor(800_0000 as i128, SCALAR_7)
.unwrap();
let claimed = bootstrap_client.claim(&frodo, &id);
assert_approx_eq_abs(claim_amount, claimed, MAX_DUST_AMOUNT);
assert_approx_eq_abs(
claim_amount,
blend_fixture
.backstop
.user_balance(&pool_address, &frodo)
.shares,
MAX_DUST_AMOUNT,
);

// refund samwise
let refund_samwise = refund_joiners
.fixed_mul_floor(share_samwise, SCALAR_7)
.unwrap();
let refunded_samwise = bootstrap_client.refund(&samwise, &id);
assert_approx_eq_abs(
refund_joiners - refunded_samwise,
usdc_token.balance(&bootstrapper),
MAX_DUST_AMOUNT,
);
assert_approx_eq_abs(
refund_samwise,
usdc_token.balance(&samwise),
MAX_DUST_AMOUNT,
);
assert_approx_eq_abs(refund_samwise, refunded_samwise, MAX_DUST_AMOUNT);

// claim samwise
let claim_amount_samwise = claim_joiners
.fixed_mul_floor(share_samwise, SCALAR_7)
.unwrap();
let claimed_samwise = bootstrap_client.claim(&samwise, &id);
assert_approx_eq_abs(claim_amount_samwise, claimed_samwise, MAX_DUST_AMOUNT);
assert_approx_eq_abs(
claim_amount_samwise,
blend_fixture
.backstop
.user_balance(&pool_address, &samwise)
.shares,
MAX_DUST_AMOUNT,
);

// refund pippin
let refund_pippin = refund_joiners
.fixed_mul_floor(share_pippin, SCALAR_7)
.unwrap();
let refunded_pippin = bootstrap_client.refund(&pippin, &id);
assert_approx_eq_abs(0, usdc_token.balance(&bootstrapper), MAX_DUST_AMOUNT);
assert_approx_eq_abs(
refunded_pippin,
usdc_token.balance(&pippin),
MAX_DUST_AMOUNT,
);
assert_approx_eq_abs(refund_pippin, refunded_pippin, MAX_DUST_AMOUNT);

// verify bootstrapper refund is 0
let result = bootstrap_client.refund(&frodo, &id);
assert_eq!(result, 0);

let result = bootstrap_client.try_refund(&samwise, &id);
assert_eq!(result.err(), Some(Ok(Error::from_contract_error(108))));

let result = bootstrap_client.try_refund(&pippin, &id);
assert_eq!(result.err(), Some(Ok(Error::from_contract_error(108))));
}

#[test]
fn test_refund_bootstrap_after_partial_close() {
let e = Env::default();
Expand Down

0 comments on commit a3b2ed2

Please sign in to comment.