From dcbe6cd4d67f81265b2e6b643511a42dafb87d08 Mon Sep 17 00:00:00 2001 From: Joseph Delong Date: Tue, 16 Jan 2024 12:30:30 -0600 Subject: [PATCH 1/2] fix: allow collateral amounts lower than specified --- package.json | 3 +- src/enforcers/AstariaV1BorrowerEnforcer.sol | 21 +++++++++++-- test/TestV1BorrowerEnforcer.sol | 33 ++++++++++++++++++++- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 04de2fa..1c170f5 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ }, "scripts": { "prepare": "husky install", - "snapshot": "forge snapshot --diff --no-match-path *fuzz*" + "snapshot": "forge snapshot --diff --no-match-path *fuzz*", + "test": "forge test --no-match-path *fuzz*" }, "dependencies": { "@mermaid-js/mermaid-cli": "^10.6.1", diff --git a/src/enforcers/AstariaV1BorrowerEnforcer.sol b/src/enforcers/AstariaV1BorrowerEnforcer.sol index 860df5b..16395e0 100644 --- a/src/enforcers/AstariaV1BorrowerEnforcer.sol +++ b/src/enforcers/AstariaV1BorrowerEnforcer.sol @@ -27,6 +27,7 @@ contract AstariaV1BorrowerEnforcer is BorrowerEnforcer { error DebtBundlesNotSupported(); error LoanAmountOutOfBounds(); error LoanRateExceedsCurrentRate(); + error AmountExceedsCaveatCollateral(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STRUCTS */ @@ -81,7 +82,7 @@ contract AstariaV1BorrowerEnforcer is BorrowerEnforcer { ); V1BorrowerDetails memory v1Details = abi.decode(caveatData, (V1BorrowerDetails)); - + if (loanAmount < v1Details.minAmount || loanAmount > v1Details.maxAmount) { // Debt amount is less than the current caveat amount revert LoanAmountOutOfBounds(); @@ -92,14 +93,28 @@ contract AstariaV1BorrowerEnforcer is BorrowerEnforcer { // Loan rate is greater than the current caveat rate revert LoanRateExceedsCurrentRate(); } + + BorrowerEnforcer.Details memory caveatDetails = v1Details.details; // Update the caveat loan rate and amount - Starport.Loan memory caveatLoan = v1Details.details.loan; + Starport.Loan memory caveatLoan = caveatDetails.loan; + uint256 i = 0; + for(;i Date: Tue, 16 Jan 2024 12:36:35 -0600 Subject: [PATCH 2/2] fix: forge fmt --- src/enforcers/AstariaV1BorrowerEnforcer.sol | 10 ++++------ test/TestV1BorrowerEnforcer.sol | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/enforcers/AstariaV1BorrowerEnforcer.sol b/src/enforcers/AstariaV1BorrowerEnforcer.sol index 16395e0..2c6b204 100644 --- a/src/enforcers/AstariaV1BorrowerEnforcer.sol +++ b/src/enforcers/AstariaV1BorrowerEnforcer.sol @@ -82,7 +82,7 @@ contract AstariaV1BorrowerEnforcer is BorrowerEnforcer { ); V1BorrowerDetails memory v1Details = abi.decode(caveatData, (V1BorrowerDetails)); - + if (loanAmount < v1Details.minAmount || loanAmount > v1Details.maxAmount) { // Debt amount is less than the current caveat amount revert LoanAmountOutOfBounds(); @@ -93,17 +93,15 @@ contract AstariaV1BorrowerEnforcer is BorrowerEnforcer { // Loan rate is greater than the current caveat rate revert LoanRateExceedsCurrentRate(); } - BorrowerEnforcer.Details memory caveatDetails = v1Details.details; // Update the caveat loan rate and amount Starport.Loan memory caveatLoan = caveatDetails.loan; uint256 i = 0; - for(;i