Skip to content

Commit

Permalink
Release preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Abliazimov committed Jul 31, 2024
1 parent a574d10 commit be07f95
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 131 deletions.
2 changes: 1 addition & 1 deletion contracts/pool/src/methods/flash_loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn flash_loan(
&env.current_contract_address(),
receiver,
s_token_address,
&received_asset.amount,
&(received_asset.amount + received_asset.premium),
);

add_protocol_fee_vault(env, &received_asset.asset, received_asset.premium)?;
Expand Down
83 changes: 9 additions & 74 deletions contracts/pool/src/tests/flash_loan.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::tests::sut::{fill_pool, init_pool};
use common::FixedI128;
use pool_interface::types::flash_loan_asset::FlashLoanAsset;
use pool_interface::types::pool_config::PoolConfig;
use soroban_sdk::testutils::Events;
Expand Down Expand Up @@ -79,10 +78,10 @@ fn should_require_borrower_to_pay_fee() {
let s_token_undetlying_asset_0_before = sut.reserves[0]
.token
.balance(&sut.reserves[0].s_token().address);
let s_token_undetlying_asset_1_before = sut.reserves[0]
let s_token_undetlying_asset_1_before = sut.reserves[1]
.token
.balance(&sut.reserves[1].s_token().address);
let s_token_undetlying_asset_2_before = sut.reserves[0]
let s_token_undetlying_asset_2_before = sut.reserves[2]
.token
.balance(&sut.reserves[2].s_token().address);

Expand All @@ -100,26 +99,26 @@ fn should_require_borrower_to_pay_fee() {
let s_token_undetlying_asset_0_after = sut.reserves[0]
.token
.balance(&sut.reserves[0].s_token().address);
let s_token_undetlying_asset_1_after = sut.reserves[0]
let s_token_undetlying_asset_1_after = sut.reserves[1]
.token
.balance(&sut.reserves[1].s_token().address);
let s_token_undetlying_asset_2_after = sut.reserves[0]
let s_token_undetlying_asset_2_after = sut.reserves[2]
.token
.balance(&sut.reserves[2].s_token().address);

assert_eq!(treasury_asset_0_before, 0);
assert_eq!(treasury_asset_1_before, 0);
assert_eq!(treasury_asset_2_before, 0);
assert_eq!(s_token_undetlying_asset_0_before, 2_000_000);
assert_eq!(s_token_undetlying_asset_1_before, 0);
assert_eq!(s_token_undetlying_asset_2_before, 0);
assert_eq!(s_token_undetlying_asset_1_before, 100_000_000);
assert_eq!(s_token_undetlying_asset_2_before, 100_000_000);

assert_eq!(treasury_asset_0_after, 5);
assert_eq!(treasury_asset_1_after, 1000);
assert_eq!(treasury_asset_2_after, 1500);
assert_eq!(s_token_undetlying_asset_0_after, 2_000_000);
assert_eq!(s_token_undetlying_asset_1_after, 0);
assert_eq!(s_token_undetlying_asset_2_after, 0);
assert_eq!(s_token_undetlying_asset_0_after, 2_000_005);
assert_eq!(s_token_undetlying_asset_1_after, 100_001_000);
assert_eq!(s_token_undetlying_asset_2_after, 100_001_500);
}

#[test]
Expand Down Expand Up @@ -437,67 +436,3 @@ fn should_not_fail_in_grace_period() {
&Bytes::new(&env),
);
}

#[test]
fn flashloan_should_pay_protocol_fee_if_not_borrow() {
let env = Env::default();
env.mock_all_auths();

let sut = init_pool(&env, false);
let (_, borrower, _) = fill_pool(&env, &sut, false);

let _: Val = env.invoke_contract(
&sut.flash_loan_receiver.address,
&Symbol::new(&env, "initialize"),
vec![&env, sut.pool.address.into_val(&env), false.into_val(&env)],
);

let flash_loan_fee =
FixedI128::from_percentage(sut.pool.pool_configuration().flash_loan_fee).unwrap();

let protocol_fee_0_before = sut.pool.protocol_fee(&sut.reserves[0].token.address);
let protocol_fee_1_before = sut.pool.protocol_fee(&sut.reserves[1].token.address);

let loan_assets = Vec::from_array(
&env,
[
FlashLoanAsset {
asset: sut.reserves[0].token.address.clone(),
amount: 1000000,
borrow: false,
},
FlashLoanAsset {
asset: sut.reserves[1].token.address.clone(),
amount: 2000000,
borrow: false,
},
FlashLoanAsset {
asset: sut.reserves[2].token.address.clone(),
amount: 3000000,
borrow: true,
},
],
);

sut.pool.flash_loan(
&borrower,
&sut.flash_loan_receiver.address,
&loan_assets,
&Bytes::new(&env),
);

let protocol_fee_0_after = sut.pool.protocol_fee(&sut.reserves[0].token.address);
let protocol_fee_1_after = sut.pool.protocol_fee(&sut.reserves[1].token.address);

assert!(protocol_fee_0_after > protocol_fee_0_before);
assert!(protocol_fee_1_after > protocol_fee_1_before);

assert_eq!(
protocol_fee_0_after - protocol_fee_0_before,
flash_loan_fee.mul_int(1000000).unwrap()
);
assert_eq!(
protocol_fee_1_after - protocol_fee_1_before,
flash_loan_fee.mul_int(2000000).unwrap()
);
}
112 changes: 56 additions & 56 deletions contracts/pool/src/tests/snapshots/budget_utilization.snap
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
['pool::tests::budget::account_position'] = {
"cpu_cost": 12075929,
"memory_cost": 5797350,
"cpu_cost": 12081299,
"memory_cost": 5798758,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::borrow'] = {
"cpu_cost": 16915864,
"memory_cost": 8938583,
"cpu_cost": 16921234,
"memory_cost": 8939991,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::collat_coeff'] = {
"cpu_cost": 8393472,
"memory_cost": 2971234,
"cpu_cost": 8398842,
"memory_cost": 2972642,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::configure_as_collateral'] = {
"cpu_cost": 8944306,
"memory_cost": 3088682,
"cpu_cost": 8949676,
"memory_cost": 3090090,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::debt_coeff'] = {
"cpu_cost": 8083271,
"memory_cost": 2917320,
"cpu_cost": 8088641,
"memory_cost": 2918728,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::deposit'] = {
"cpu_cost": 11706450,
"memory_cost": 4704735,
"cpu_cost": 11711820,
"memory_cost": 4706143,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::enable_borrowing_on_reserve'] = {
"cpu_cost": 8370858,
"memory_cost": 2990354,
"cpu_cost": 8376228,
"memory_cost": 2991762,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::flash_loan_with_borrow'] = {
"cpu_cost": 32047924,
"memory_cost": 19588426,
"cpu_cost": 32054750,
"memory_cost": 19589834,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::flash_loan_without_borrow'] = {
"cpu_cost": 18695925,
"memory_cost": 9493613,
"cpu_cost": 18702751,
"memory_cost": 9495021,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::get_reserve'] = {
"cpu_cost": 7909842,
"memory_cost": 2881106,
"cpu_cost": 7915212,
"memory_cost": 2882514,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
Expand All @@ -65,62 +65,62 @@
"memory_limit_exceeded": false,
}
['pool::tests::budget::liquidate_receive_underlying_when_borrower_has_one_debt'] = {
"cpu_cost": 18840055,
"memory_cost": 9201429,
"cpu_cost": 18845425,
"memory_cost": 9202837,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::liquidate_receive_underlying_when_borrower_has_two_debts'] = {
"cpu_cost": 19120548,
"memory_cost": 9199901,
"cpu_cost": 19125918,
"memory_cost": 9201309,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::pause_info'] = {
"cpu_cost": 7857702,
"memory_cost": 2879604,
"cpu_cost": 7863072,
"memory_cost": 2881012,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::price_feed'] = {
"cpu_cost": 7869866,
"memory_cost": 2879871,
"cpu_cost": 7875236,
"memory_cost": 2881279,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::repay_full'] = {
"cpu_cost": 13895130,
"memory_cost": 6173401,
"cpu_cost": 13900500,
"memory_cost": 6174809,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::repay_partial'] = {
"cpu_cost": 15285942,
"memory_cost": 7506074,
"cpu_cost": 15291312,
"memory_cost": 7507482,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::s_token_transfer'] = {
"cpu_cost": 14309651,
"memory_cost": 7367630,
"cpu_cost": 14315021,
"memory_cost": 7369038,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_as_collateral'] = {
"cpu_cost": 11630258,
"memory_cost": 5746643,
"cpu_cost": 11635628,
"memory_cost": 5748051,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_pause'] = {
"cpu_cost": 8308380,
"memory_cost": 2988209,
"cpu_cost": 8313750,
"memory_cost": 2989617,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_pool_configuration'] = {
"cpu_cost": 8524923,
"memory_cost": 3024452,
"cpu_cost": 8530293,
"memory_cost": 3025860,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
Expand All @@ -131,50 +131,50 @@
"memory_limit_exceeded": false,
}
['pool::tests::budget::set_reserve_status'] = {
"cpu_cost": 8365934,
"memory_cost": 2990216,
"cpu_cost": 8371304,
"memory_cost": 2991624,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::stoken_underlying_balance'] = {
"cpu_cost": 7605022,
"memory_cost": 2840546,
"cpu_cost": 7610392,
"memory_cost": 2841954,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::upgrade'] = {
"cpu_cost": 8085795,
"memory_cost": 2941618,
"cpu_cost": 8091165,
"memory_cost": 2943026,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::upgrade_debt_token'] = {
"cpu_cost": 9394053,
"memory_cost": 4297565,
"cpu_cost": 9398991,
"memory_cost": 4298973,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::upgrade_s_token'] = {
"cpu_cost": 9890812,
"memory_cost": 4398131,
"cpu_cost": 9896182,
"memory_cost": 4399539,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::user_configuration'] = {
"cpu_cost": 7613176,
"memory_cost": 2843541,
"cpu_cost": 7618546,
"memory_cost": 2844949,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::withdraw_full'] = {
"cpu_cost": 15390399,
"memory_cost": 7487192,
"cpu_cost": 15395769,
"memory_cost": 7488600,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
['pool::tests::budget::withdraw_partial'] = {
"cpu_cost": 15254389,
"memory_cost": 7503166,
"cpu_cost": 15259759,
"memory_cost": 7504574,
"cpu_limit_exceeded": false,
"memory_limit_exceeded": false,
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit be07f95

Please sign in to comment.