Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove blnd oracle calls #144

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 4 additions & 32 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);
markuspluna marked this conversation as resolved.
Show resolved Hide resolved
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 Expand Up @@ -289,19 +285,11 @@ mod tests {
Asset::Stellar(underlying_1.clone()),
Asset::Stellar(underlying_2),
Asset::Stellar(usdc),
Asset::Stellar(blnd),
],
&7,
&300,
);
oracle_client.set_price_stable(&vec![
&e,
2_0000000,
4_0000000,
100_0000000,
1_0000000,
0_1000000,
]);
oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 100_0000000, 1_0000000]);

let positions: Positions = Positions {
collateral: map![&e],
Expand Down Expand Up @@ -430,19 +418,11 @@ mod tests {
Asset::Stellar(underlying_1.clone()),
Asset::Stellar(underlying_2),
Asset::Stellar(usdc),
Asset::Stellar(blnd),
],
&7,
&300,
);
oracle_client.set_price_stable(&vec![
&e,
2_0000000,
4_0000000,
100_0000000,
1_0000000,
0_1000000,
]);
oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 100_0000000, 1_0000000]);

let positions: Positions = Positions {
collateral: map![&e],
Expand Down Expand Up @@ -572,19 +552,11 @@ mod tests {
Asset::Stellar(underlying_1.clone()),
Asset::Stellar(underlying_2),
Asset::Stellar(usdc),
Asset::Stellar(blnd),
],
&7,
&300,
);
oracle_client.set_price_stable(&vec![
&e,
2_0000000,
4_0000000,
100_0000000,
1_0000000,
0_1000000,
]);
oracle_client.set_price_stable(&vec![&e, 2_0000000, 4_0000000, 100_0000000, 1_0000000]);

let positions: Positions = Positions {
collateral: map![&e],
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
24 changes: 13 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,27 @@ 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);

assert_eq!(bad_debt_auction_data.bid.len(), 2);
assert_eq!(bad_debt_auction_data.lot.len(), 1);

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 +579,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 +619,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 +678,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 +724,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 +754,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