Skip to content

Commit

Permalink
Merge pull request #120 from Hydrogen-Labs/braqzen-119
Browse files Browse the repository at this point in the history
Update code to latest versions
  • Loading branch information
diyahir authored Jul 22, 2024
2 parents 855f704 + f41a025 commit 9955fd0
Show file tree
Hide file tree
Showing 92 changed files with 3,705 additions and 1,917 deletions.
3,892 changes: 2,833 additions & 1,059 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ members = [

[workspace.dependencies]
dotenv = "0.15.0"
fuels = { version = "0.55.0", features = ["fuel-core-lib"] }
fuels = { version = "0.65.1", features = ["fuel-core-lib"] }
futures = "0.3.17"
pbr = "1.1.1"
rand = { version = "0.8.5", default-features = false, features = [
rand = { version = "0.8.5", features = [
"std_rng",
"getrandom",
] }
Expand Down
4 changes: 2 additions & 2 deletions contracts/active-pool-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2021"
license = "Apache-2.0"

[dependencies]
fuels = { workspace = true, default-features = false }
fuels = { workspace = true }
test-utils = { path = "../../test-utils" }
tokio = { workspace = true, default-features = false }
tokio = { workspace = true }

# Not the latest version because of indexer bug o.o

Expand Down
4 changes: 2 additions & 2 deletions contracts/active-pool-contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ impl ActivePool for Contract {
require_caller_is_bo_or_tm_or_sp_or_pm();
let new_amount = storage.asset_amount.get(asset_id).read() - amount;
storage.asset_amount.insert(asset_id, new_amount);
let dafault_pool = abi(ActivePool, storage.default_pool_contract.read().value);
let dafault_pool = abi(ActivePool, storage.default_pool_contract.read().bits());
dafault_pool
.recieve {
coins: amount,
asset_id: asset_id.value,
asset_id: asset_id.bits(),
}();
}
// --- Receive functionality ---
Expand Down
25 changes: 14 additions & 11 deletions contracts/active-pool-contract/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ async fn get_contract_instance() -> (

active_pool_abi::add_asset(
&instance,
asset.contract_id().asset_id(&BASE_ASSET_ID.into()).into(),
asset
.contract_id()
.asset_id(&AssetId::zeroed().into())
.into(),
Identity::Address(wallet.address().into()),
)
.await;
Expand All @@ -67,7 +70,7 @@ async fn proper_intialize() {
&active_pool,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await
Expand All @@ -78,7 +81,7 @@ async fn proper_intialize() {
&active_pool,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await
Expand All @@ -95,7 +98,7 @@ async fn proper_adjust_debt() {
1000,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await;
Expand All @@ -104,7 +107,7 @@ async fn proper_adjust_debt() {
&active_pool,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await
Expand All @@ -116,7 +119,7 @@ async fn proper_adjust_debt() {
500,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await;
Expand All @@ -125,7 +128,7 @@ async fn proper_adjust_debt() {
&active_pool,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await
Expand All @@ -150,7 +153,7 @@ async fn proper_adjust_asset_col() {
&active_pool,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await
Expand All @@ -161,7 +164,7 @@ async fn proper_adjust_asset_col() {

let asset_id = mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into();

let balance_before = provdier
Expand All @@ -175,7 +178,7 @@ async fn proper_adjust_asset_col() {
500_000,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await;
Expand All @@ -184,7 +187,7 @@ async fn proper_adjust_asset_col() {
&active_pool,
mock_fuel
.contract_id()
.asset_id(&BASE_ASSET_ID.into())
.asset_id(&AssetId::zeroed().into())
.into(),
)
.await
Expand Down
4 changes: 2 additions & 2 deletions contracts/borrow-operations-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ edition = "2021"
license = "Apache-2.0"

[dependencies]
fuels = { workspace = true, default-features = false }
fuels = { workspace = true }
test-utils = { path = "../../test-utils" }
tokio = { workspace = true, default-features = false }
tokio = { workspace = true }

# Not the latest version because of indexer bug o.o

Expand Down
46 changes: 23 additions & 23 deletions contracts/borrow-operations-contract/src/data_structures.sw
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
library;

pub struct LocalVariables_OpenTrove {
price: u64,
usdf_fee: u64,
net_debt: u64,
composite_debt: u64,
icr: u64,
nicr: u64,
stake: u64,
array_index: u64,
pub price: u64,
pub usdf_fee: u64,
pub net_debt: u64,
pub composite_debt: u64,
pub icr: u64,
pub nicr: u64,
pub stake: u64,
pub array_index: u64,
}

pub struct AssetContracts {
trove_manager: ContractId,
oracle: ContractId,
pub trove_manager: ContractId,
pub oracle: ContractId,
}

impl LocalVariables_OpenTrove {
Expand All @@ -32,19 +32,19 @@ impl LocalVariables_OpenTrove {
}

pub struct LocalVariables_AdjustTrove {
price: u64,
coll_change: u64,
net_debt_change: u64,
is_coll_increase: bool,
debt: u64,
coll: u64,
old_icr: u64,
new_icr: u64,
new_tcr: u64,
usdf_fee: u64,
new_debt: u64,
new_coll: u64,
stake: u64,
pub price: u64,
pub coll_change: u64,
pub net_debt_change: u64,
pub is_coll_increase: bool,
pub debt: u64,
pub coll: u64,
pub old_icr: u64,
pub new_icr: u64,
pub new_tcr: u64,
pub usdf_fee: u64,
pub new_debt: u64,
pub new_coll: u64,
pub stake: u64,
}

impl LocalVariables_AdjustTrove {
Expand Down
44 changes: 22 additions & 22 deletions contracts/borrow-operations-contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ impl BorrowOperations for Contract {
let fpt_staking_contract = storage.fpt_staking_contract.read();
let active_pool_contract = storage.active_pool_contract.read();
let sorted_troves_contract = storage.sorted_troves_contract.read();
let oracle = abi(MockOracle, asset_contracts.oracle.value);
let trove_manager = abi(TroveManager, asset_contracts.trove_manager.value);
let sorted_troves = abi(SortedTroves, sorted_troves_contract.value);
let oracle = abi(MockOracle, asset_contracts.oracle.bits());
let trove_manager = abi(TroveManager, asset_contracts.trove_manager.bits());
let sorted_troves = abi(SortedTroves, sorted_troves_contract.bits());
let mut vars = LocalVariables_OpenTrove::new();
let sender = msg_sender().unwrap();
vars.net_debt = usdf_amount;
Expand Down Expand Up @@ -204,8 +204,8 @@ impl BorrowOperations for Contract {
let asset_contracts_cache = storage.asset_contracts.get(asset_contract).read();
let usdf_contract_cache = storage.usdf_contract.read();
let active_pool_contract_cache = storage.active_pool_contract.read();
let trove_manager = abi(TroveManager, asset_contracts_cache.trove_manager.value);
let active_pool = abi(ActivePool, active_pool_contract_cache.value);
let trove_manager = abi(TroveManager, asset_contracts_cache.trove_manager.bits());
let active_pool = abi(ActivePool, active_pool_contract_cache.bits());
let borrower = msg_sender().unwrap();
require_trove_is_active(borrower, asset_contracts_cache.trove_manager);
trove_manager.apply_pending_rewards(borrower);
Expand Down Expand Up @@ -235,7 +235,7 @@ impl BorrowOperations for Contract {
}
#[storage(read)]
fn claim_collateral(asset: AssetId) {
let coll_surplus = abi(CollSurplusPool, storage.coll_surplus_pool_contract.read().value);
let coll_surplus = abi(CollSurplusPool, storage.coll_surplus_pool_contract.read().bits());
coll_surplus.claim_coll(msg_sender().unwrap(), asset);
}
#[storage(read)]
Expand All @@ -249,8 +249,8 @@ fn internal_trigger_borrowing_fee(
usdf_contract: ContractId,
fpt_staking_contract: ContractId,
) -> u64 {
let usdf = abi(USDFToken, usdf_contract.value);
let fpt_staking = abi(FPTStaking, fpt_staking_contract.value);
let usdf = abi(USDFToken, usdf_contract.bits());
let fpt_staking = abi(FPTStaking, fpt_staking_contract.bits());
let usdf_fee = fm_compute_borrow_fee(usdf_amount);
// Mint usdf to fpt staking contract
usdf.mint(usdf_fee, Identity::ContractId(fpt_staking_contract));
Expand All @@ -274,9 +274,9 @@ fn internal_adjust_trove(
let fpt_staking_contract_cache = storage.fpt_staking_contract.read();
let active_pool_contract_cache = storage.active_pool_contract.read();
let sorted_troves_contract_cache = storage.sorted_troves_contract.read();
let oracle = abi(MockOracle, asset_contracts_cache.oracle.value);
let trove_manager = abi(TroveManager, asset_contracts_cache.trove_manager.value);
let sorted_troves = abi(SortedTroves, sorted_troves_contract_cache.value);
let oracle = abi(MockOracle, asset_contracts_cache.oracle.bits());
let trove_manager = abi(TroveManager, asset_contracts_cache.trove_manager.bits());
let sorted_troves = abi(SortedTroves, sorted_troves_contract_cache.bits());
let price = oracle.get_price();
let mut vars = LocalVariables_AdjustTrove::new();
if is_debt_increase {
Expand Down Expand Up @@ -364,7 +364,7 @@ fn require_is_protocol_manager() {
}
#[storage(read)]
fn require_trove_is_not_active(borrower: Identity, trove_manager: ContractId) {
let trove_manager = abi(TroveManager, trove_manager.value);
let trove_manager = abi(TroveManager, trove_manager.bits());
let status = trove_manager.get_trove_status(borrower);
require(
status != Status::Active,
Expand All @@ -373,7 +373,7 @@ fn require_trove_is_not_active(borrower: Identity, trove_manager: ContractId) {
}
#[storage(read)]
fn require_trove_is_active(borrower: Identity, trove_manage_contract: ContractId) {
let trove_manager = abi(TroveManager, trove_manage_contract.value);
let trove_manager = abi(TroveManager, trove_manage_contract.bits());
let status = trove_manager.get_trove_status(borrower);
require(
status == Status::Active,
Expand Down Expand Up @@ -437,8 +437,8 @@ fn internal_withdraw_usdf(
usdf_contract: ContractId,
asset_contract: AssetId,
) {
let active_pool = abi(ActivePool, active_pool_contract.value);
let usdf = abi(USDFToken, usdf_contract.value);
let active_pool = abi(ActivePool, active_pool_contract.bits());
let usdf = abi(USDFToken, usdf_contract.bits());
active_pool.increase_usdf_debt(net_debt_increase, asset_contract);
usdf.mint(amount, recipient);
}
Expand Down Expand Up @@ -497,7 +497,7 @@ fn internal_update_trove_from_adjustment(
is_debt_increase: bool,
trove_manager: ContractId,
) -> (u64, u64) {
let trove_manager = abi(TroveManager, trove_manager.value);
let trove_manager = abi(TroveManager, trove_manager.bits());
let mut new_coll = 0;
let mut new_debt = 0;
if is_coll_increase {
Expand Down Expand Up @@ -534,11 +534,11 @@ fn internal_get_new_trove_amounts(
}
#[storage(read)]
fn internal_active_pool_add_coll(coll_change: u64, asset: AssetId, active_pool: ContractId) {
let active_pool = abi(ActivePool, active_pool.value);
let active_pool = abi(ActivePool, active_pool.bits());
active_pool
.recieve {
coins: coll_change,
asset_id: asset.value,
asset_id: asset.bits(),
}();
}
#[storage(read)]
Expand All @@ -548,12 +548,12 @@ fn internal_repay_usdf(
usdf_contract: ContractId,
asset_contract: AssetId,
) {
let active_pool = abi(ActivePool, active_pool_contract.value);
let usdf = abi(USDFToken, usdf_contract.value);
let active_pool = abi(ActivePool, active_pool_contract.bits());
let usdf = abi(USDFToken, usdf_contract.bits());
usdf
.burn {
coins: usdf_amount,
asset_id: storage.usdf_asset_id.read().value,
asset_id: storage.usdf_asset_id.read().bits(),
}();
active_pool.decrease_usdf_debt(usdf_amount, asset_contract);
}
Expand All @@ -569,7 +569,7 @@ fn internal_move_usdf_and_asset_from_adjustment(
active_pool_contract: ContractId,
usdf_contract: ContractId,
) {
let active_pool = abi(ActivePool, active_pool_contract.value);
let active_pool = abi(ActivePool, active_pool_contract.bits());
if coll_change > 0 {
if is_coll_increase {
internal_active_pool_add_coll(coll_change, asset, active_pool_contract);
Expand Down
Loading

0 comments on commit 9955fd0

Please sign in to comment.