From 0799e2ede15db11de605abbc3d8e146d6e8eec6e Mon Sep 17 00:00:00 2001 From: markuspluna <59978114+markuspluna@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:27:34 -0500 Subject: [PATCH] Backstop: removed blnd oracle call --- pool/src/auctions/bad_debt_auction.rs | 6 +-- test-suites/src/test_fixture.rs | 2 +- test-suites/tests/test_liquidation.rs | 53 +++++++++++++++++++++------ 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/pool/src/auctions/bad_debt_auction.rs b/pool/src/auctions/bad_debt_auction.rs index 05282690..a925d51c 100644 --- a/pool/src/auctions/bad_debt_auction.rs +++ b/pool/src/auctions/bad_debt_auction.rs @@ -48,15 +48,11 @@ pub fn create_bad_debt_auction_data(e: &Env, backstop: &Address) -> AuctionData let backstop_token = backstop_client.backstop_token(); let pool_backstop_data = backstop_client.pool_data(&e.current_contract_address()); let usdc_token = storage::get_usdc_token(e); - let blnd_token = storage::get_blnd_token(e); let usdc_to_base = pool.load_price(e, &usdc_token); - let blnd_to_base = pool.load_price(e, &blnd_token); let backstop_value_base = usdc_to_base .fixed_mul_floor(pool_backstop_data.usdc, SCALAR_7) .unwrap_optimized() - + blnd_to_base - .fixed_mul_floor(pool_backstop_data.blnd, SCALAR_7) - .unwrap_optimized(); + * 5; // Since the backstop LP token is an 80/20 split of USDC/BLND, we multiply by 5 to get the value of the BLND portion let backstop_token_to_base = backstop_value_base .fixed_div_floor(pool_backstop_data.tokens, SCALAR_7) .unwrap_optimized(); diff --git a/test-suites/src/test_fixture.rs b/test-suites/src/test_fixture.rs index 596199fc..4197a095 100644 --- a/test-suites/src/test_fixture.rs +++ b/test-suites/src/test_fixture.rs @@ -131,7 +131,7 @@ impl TestFixture<'_> { ); mock_oracle_client.set_price_stable(&svec![ &e, - 0_0500000, // blnd + 0_2500000, // blnd 2000_0000000, // eth 1_0000000, // usdc 0_1000000, // xlm diff --git a/test-suites/tests/test_liquidation.rs b/test-suites/tests/test_liquidation.rs index dc356230..10adb95d 100644 --- a/test-suites/tests/test_liquidation.rs +++ b/test-suites/tests/test_liquidation.rs @@ -373,7 +373,7 @@ fn test_liquidations() { //tank eth price fixture.oracle.set_price_stable(&vec![ &fixture.env, - 0_0500000, // blnd + 0_0250000, // blnd 500_0000000, // eth 1_0000000, // usdc 0_1000000, // xlm @@ -501,25 +501,56 @@ fn test_liquidations() { // create a bad debt auction let auction_type: u32 = 1; let bad_debt_auction_data = pool_fixture.pool.new_auction(&auction_type); + let pool_backstop_data = fixture.backstop.pool_data(&pool_fixture.pool.address); + println!( + "backstop usdc {}", + backstop_positions.liabilities.get(0).unwrap() + ); + println!( + "backstop xlm {}", + backstop_positions.liabilities.get(1).unwrap() + ); + println!("usdc: {:?}", pool_backstop_data.usdc); + println!("tokens: {:?}", pool_backstop_data.tokens); + assert_eq!(bad_debt_auction_data.bid.len(), 2); assert_eq!(bad_debt_auction_data.lot.len(), 1); + println!( + "bid usdc {}", + bad_debt_auction_data + .bid + .get_unchecked(fixture.tokens[TokenIndex::STABLE].address.clone()) + ); + println!( + "bid xlm {}", + bad_debt_auction_data + .bid + .get_unchecked(fixture.tokens[TokenIndex::XLM].address.clone()) + ); + println!( + "lot lp {}", + bad_debt_auction_data + .lot + .get_unchecked(fixture.lp.address.clone()) + ); + assert_eq!( bad_debt_auction_data .bid .get_unchecked(fixture.tokens[TokenIndex::STABLE].address.clone()), - samwise_positions_pre_bd.liabilities.get(0).unwrap() + samwise_positions_pre_bd.liabilities.get(0).unwrap() //d rate 1.071330239 ); assert_eq!( bad_debt_auction_data .bid .get_unchecked(fixture.tokens[TokenIndex::XLM].address.clone()), - samwise_positions_pre_bd.liabilities.get(1).unwrap() + samwise_positions_pre_bd.liabilities.get(1).unwrap() //d rate 1.013853805 ); assert_approx_eq_abs( bad_debt_auction_data .lot .get_unchecked(fixture.lp.address.clone()), - 1195_17392182, // lp_token value is $0.75 each + 7171_0435309, // lp_token value is $1.25 each SCALAR_7, ); let events = fixture.env.events().all(); @@ -577,12 +608,12 @@ fn test_liquidations() { ); assert_approx_eq_abs( fixture.lp.balance(&frodo), - frodo_bstop_pre_fill + 1195_1739218, + frodo_bstop_pre_fill + 717_1043530, SCALAR_7, ); assert_approx_eq_abs( fixture.lp.balance(&fixture.backstop.address), - backstop_bstop_pre_fill - 1195_1739218, + backstop_bstop_pre_fill - 717_1043531, SCALAR_7, ); let new_auction = pool_fixture @@ -617,7 +648,7 @@ fn test_liquidations() { bad_debt_auction_data .lot .get_unchecked(fixture.lp.address.clone()) - - 2390_3478436, + - 1434_2087060, SCALAR_7, ); assert_eq!(new_auction.block, bad_debt_auction_data.block); @@ -676,12 +707,12 @@ fn test_liquidations() { ); assert_approx_eq_abs( fixture.lp.balance(&frodo), - frodo_bstop_pre_fill + 7171_0435309, + frodo_bstop_pre_fill + 4302_6261190, SCALAR_7, ); assert_approx_eq_abs( fixture.lp.balance(&fixture.backstop.address), - backstop_bstop_pre_fill - 7171_0435309, + backstop_bstop_pre_fill - 4302_6261190, SCALAR_7, ); let events = fixture.env.events().all(); @@ -722,7 +753,7 @@ fn test_liquidations() { .withdraw(&frodo, &pool_fixture.pool.address, &original_deposit); assert_approx_eq_abs( fixture.lp.balance(&frodo) - pre_withdraw_frodo_bstp, - original_deposit - 7171_0435309 - 1195_1739218, + original_deposit - 717_1043530 - 4302_6261190, SCALAR_7, ); fixture @@ -752,7 +783,7 @@ fn test_liquidations() { // Nuke eth price more fixture.oracle.set_price_stable(&vec![ &fixture.env, - 0_0500000, // blnd + 0_2500000, // blnd 10_0000000, // eth 1_0000000, // usdc 0_1000000, // xlm