Copy while (current_borrower != null_identity_address() && current_cr < MCR) {
current_borrower = sorted_troves.get_prev(current_borrower, asset);
current_cr = trove_manager.get_current_icr(current_borrower, price);
}
Copy #[storage(read)]
fn internal_get_prev(id: Identity, asset: AssetId) -> Identity {
match storage.nodes.get((id, asset)).try_read() {
Some(node) => return node.prev_id,
None => return Identity::Address(Address::zero()),
}
https://github.com/Hydrogen-Labs/fluid-protocol/blob/main/contracts/protocol-manager-contract/src/main.sw#L159
https://github.com/Hydrogen-Labs/fluid-protocol/blob/main/contracts/protocol-manager-contract/src/main.sw#L331
https://github.com/Hydrogen-Labs/fluid-protocol/blob/main/contracts/sorted-troves-contract/src/main.sw#L183
Copy use fuels::{prelude::*, types::Identity};
use test_utils::data_structures::{ContractInstance, PRECISION};
use test_utils::interfaces::oracle::oracle_abi;
use test_utils::interfaces::protocol_manager::ProtocolManager;
use test_utils::interfaces::pyth_oracle::PYTH_TIMESTAMP;
use test_utils::{
interfaces::{
borrow_operations::{borrow_operations_abi, BorrowOperations},
protocol_manager::protocol_manager_abi,
pyth_oracle::{pyth_oracle_abi, pyth_price_feed,pyth_price_no_precision_with_time},
token::token_abi,
trove_manager::{trove_manager_abi, trove_manager_utils, Status},
},
setup::common::setup_protocol,
};
#[tokio::test]
async fn can_not_redeem_when_all_asset_mcr_less_than_1_35() {
let (contracts, _admin, mut wallets) = setup_protocol(5, true, false).await;
let healthy_wallet1 = wallets.pop().unwrap();
let healthy_wallet2 = wallets.pop().unwrap();
let healthy_wallet3 = wallets.pop().unwrap();
let balance: u64 = 12_000 * PRECISION;
token_abi::mint_to_id(
&contracts.asset_contracts[0].asset,
balance,
Identity::Address(healthy_wallet1.address().into()),
)
.await;
token_abi::mint_to_id(
&contracts.asset_contracts[0].asset,
balance,
Identity::Address(healthy_wallet2.address().into()),
)
.await;
token_abi::mint_to_id(
&contracts.asset_contracts[0].asset,
balance,
Identity::Address(healthy_wallet3.address().into()),
)
.await;
let borrow_operations_healthy_wallet1 = ContractInstance::new(
BorrowOperations::new(
contracts.borrow_operations.contract.contract_id().clone(),
healthy_wallet1.clone(),
),
contracts.borrow_operations.implementation_id.clone(),
);
let coll1 = 12_000 * PRECISION;
let debt1 = 6_000 * PRECISION;
oracle_abi::set_debug_timestamp(&contracts.asset_contracts[0].oracle, PYTH_TIMESTAMP).await;
pyth_oracle_abi::update_price_feeds(
&contracts.asset_contracts[0].mock_pyth_oracle,
// pyth_price_feed(1),
pyth_price_no_precision_with_time(1 * PRECISION, PYTH_TIMESTAMP),
)
.await;
borrow_operations_abi::open_trove(
&borrow_operations_healthy_wallet1,
&contracts.asset_contracts[0].oracle,
&contracts.asset_contracts[0].mock_pyth_oracle,
&contracts.asset_contracts[0].mock_redstone_oracle,
&contracts.asset_contracts[0].asset,
&contracts.usdf,
&contracts.fpt_staking,
&contracts.sorted_troves,
&contracts.asset_contracts[0].trove_manager,
&contracts.active_pool,
coll1,
debt1,
Identity::Address(Address::zeroed()),
Identity::Address(Address::zeroed()),
)
.await
.unwrap();
let borrow_operations_healthy_wallet2 = ContractInstance::new(
BorrowOperations::new(
contracts.borrow_operations.contract.contract_id().clone(),
healthy_wallet2.clone(),
),
contracts.borrow_operations.implementation_id.clone(),