Skip to content

Commit

Permalink
Backstop: removed blnd oracle call
Browse files Browse the repository at this point in the history
  • Loading branch information
markuspluna committed Nov 9, 2023
1 parent de6ce25 commit 0799e2e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
6 changes: 1 addition & 5 deletions pool/src/auctions/bad_debt_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test-suites/src/test_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 42 additions & 11 deletions test-suites/tests/test_liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0799e2e

Please sign in to comment.