Skip to content

Commit

Permalink
fix: rename enforcer structs to Details
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerousfood committed Feb 6, 2024
1 parent 5d12830 commit 34065ff
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
28 changes: 14 additions & 14 deletions src/enforcers/AstariaV1BorrowerEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract AstariaV1BorrowerEnforcer is CaveatEnforcer {
/* STRUCTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

struct V1BorrowerDetails {
struct Details {
uint256 startTime;
uint256 endTime;
uint256 startRate;
Expand All @@ -51,8 +51,8 @@ contract AstariaV1BorrowerEnforcer is CaveatEnforcer {

/// @notice Calculates the current maximum valid rate of a caveat
function locateCurrentRate(bytes calldata caveatData) external view returns (uint256 currentRate) {
V1BorrowerDetails memory v1Details = abi.decode(caveatData, (V1BorrowerDetails));
return _locateCurrentRate(v1Details);
Details memory details = abi.decode(caveatData, (Details));
return _locateCurrentRate(details);
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
Expand Down Expand Up @@ -84,21 +84,21 @@ contract AstariaV1BorrowerEnforcer is CaveatEnforcer {
AstariaV1Lib.getBasePricingDecimals(loanTerms.pricingData) // decimals
);

V1BorrowerDetails memory v1Details = abi.decode(caveatData, (V1BorrowerDetails));
Details memory details = abi.decode(caveatData, (Details));

if (loanAmount < v1Details.minAmount || loanAmount > v1Details.maxAmount) {
if (loanAmount < details.minAmount || loanAmount > details.maxAmount) {
// Debt amount is less than the current caveat amount
revert LoanAmountOutOfBounds();
}

uint256 currentRate = _locateCurrentRate(v1Details);
uint256 currentRate = _locateCurrentRate(details);
if (loanRate > currentRate) {
// Loan rate is greater than the current caveat rate
revert LoanRateExceedsCurrentRate();
}

// Update the caveat loan rate and amount
Starport.Loan memory caveatLoan = v1Details.loan;
Starport.Loan memory caveatLoan = details.loan;
uint256 i = 0;
for (; i < caveatLoan.collateral.length;) {
if (caveatLoan.collateral[i].amount < loan.collateral[i].amount) {
Expand All @@ -122,20 +122,20 @@ contract AstariaV1BorrowerEnforcer is CaveatEnforcer {
/* INTERNAL FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

function _locateCurrentRate(V1BorrowerDetails memory v1Details) internal view returns (uint256 currentRate) {
uint256 endRate = AstariaV1Lib.getBasePricingRate(v1Details.loan.terms.pricingData);
function _locateCurrentRate(Details memory details) internal view returns (uint256 currentRate) {
uint256 endRate = AstariaV1Lib.getBasePricingRate(details.loan.terms.pricingData);

// if endRate == startRate, or startTime == endTime, or block.timestamp > endTime
if (
endRate == v1Details.startRate || v1Details.startTime == v1Details.endTime
|| block.timestamp > v1Details.endTime
endRate == details.startRate || details.startTime == details.endTime
|| block.timestamp > details.endTime
) {
return endRate;
}

// Will revert if startTime > endTime
uint256 duration = v1Details.endTime - v1Details.startTime;
uint256 elapsed = block.timestamp - v1Details.startTime;
uint256 duration = details.endTime - details.startTime;
uint256 elapsed = block.timestamp - details.startTime;
uint256 remaining;
assembly ("memory-safe") {
// block.timestamp <= endTime, can't underflow
Expand All @@ -144,7 +144,7 @@ contract AstariaV1BorrowerEnforcer is CaveatEnforcer {

// Calculate rate with a linear growth
// Weight startRate by the remaining time, and endRate by the elapsed time
uint256 totalBeforeDivision = (v1Details.startRate * remaining) + (endRate * elapsed);
uint256 totalBeforeDivision = (details.startRate * remaining) + (endRate * elapsed);
assembly ("memory-safe") {
// duration > 0, as startTime != endTime and endTime - startTime did not underflow
currentRate := div(totalBeforeDivision, duration)
Expand Down
14 changes: 7 additions & 7 deletions src/enforcers/AstariaV1LenderEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract AstariaV1LenderEnforcer is CaveatEnforcer {
/* STRUCTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

struct V1LenderDetails {
struct Details {
bool matchIdentifier;
uint256 minDebtAmount;
Starport.Loan loan;
Expand Down Expand Up @@ -76,16 +76,16 @@ contract AstariaV1LenderEnforcer is CaveatEnforcer {
AstariaV1Lib.getBasePricingDecimals(loanTerms.pricingData)
);

V1LenderDetails memory v1Details = abi.decode(caveatData, (V1LenderDetails));
Starport.Loan memory caveatLoan = v1Details.loan;
Details memory details = abi.decode(caveatData, (Details));
Starport.Loan memory caveatLoan = details.loan;
SpentItem memory caveatDebt = caveatLoan.debt[0];

if (v1Details.minDebtAmount > caveatDebt.amount) {
if (details.minDebtAmount > caveatDebt.amount) {
revert MinDebtAmountExceedsMax();
}
if (loanAmount > caveatDebt.amount || loanAmount < v1Details.minDebtAmount) {
if (loanAmount > caveatDebt.amount || loanAmount < details.minDebtAmount) {
// Debt amount is greater than the max amount or the caveatDebt amount
revert DebtAmountOOB(v1Details.minDebtAmount, caveatDebt.amount, loanAmount);
revert DebtAmountOOB(details.minDebtAmount, caveatDebt.amount, loanAmount);
}

bytes memory caveatPricingData = caveatLoan.terms.pricingData;
Expand All @@ -99,7 +99,7 @@ contract AstariaV1LenderEnforcer is CaveatEnforcer {
// Update the caveat loan amount
caveatDebt.amount = loanAmount;

if (!v1Details.matchIdentifier) {
if (!details.matchIdentifier) {
// Update the caveat loan identifier
uint256 i = 0;
for (; i < caveatLoan.collateral.length;) {
Expand Down
10 changes: 5 additions & 5 deletions test/AstariaV1Test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ contract AstariaV1Test is StarportTest {
{
loan = loanCopy(loan);
loan.issuer = address(0);
AstariaV1BorrowerEnforcer.V1BorrowerDetails memory v1BorrowerDetails = AstariaV1BorrowerEnforcer
.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory Details = AstariaV1BorrowerEnforcer
.Details({
startTime: block.timestamp,
endTime: block.timestamp,
startRate: AstariaV1Lib.getBasePricingRate(loan.terms.pricingData),
Expand All @@ -109,7 +109,7 @@ contract AstariaV1Test is StarportTest {
loan: loan
});
CaveatEnforcer.Caveat memory caveat =
CaveatEnforcer.Caveat({enforcer: address(borrowerEnforcer), data: abi.encode(v1BorrowerDetails)});
CaveatEnforcer.Caveat({enforcer: address(borrowerEnforcer), data: abi.encode(Details)});
return signCaveatForAccount(caveat, salt, signer, true);
}

Expand All @@ -123,14 +123,14 @@ contract AstariaV1Test is StarportTest {
loan = loanCopy(loan);
loan.borrower = address(0);

AstariaV1LenderEnforcer.V1LenderDetails memory v1LenderDetails = AstariaV1LenderEnforcer.V1LenderDetails({
AstariaV1LenderEnforcer.Details memory Details = AstariaV1LenderEnforcer.Details({
matchIdentifier: true,
minDebtAmount: loan.debt[0].amount,
loan: loan
});

CaveatEnforcer.Caveat memory caveat =
CaveatEnforcer.Caveat({enforcer: address(lenderEnforcer), data: abi.encode(v1LenderDetails)});
CaveatEnforcer.Caveat({enforcer: address(lenderEnforcer), data: abi.encode(Details)});

return signCaveatForAccount(caveat, salt, signer, invalidate);
}
Expand Down
16 changes: 8 additions & 8 deletions test/TestV1BorrowerEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract TestV1BorrowerEnforcer is AstariaV1Test, AstariaV1BorrowerEnforcer {
function testV1BorrowerEnforcerEnd() public {
Starport.Loan memory loan = generateDefaultLoanTerms();

AstariaV1BorrowerEnforcer.V1BorrowerDetails memory details = AstariaV1BorrowerEnforcer.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory details = AstariaV1BorrowerEnforcer.Details({
startTime: block.timestamp,
endTime: block.timestamp + 10,
startRate: endRate / 2,
Expand All @@ -53,7 +53,7 @@ contract TestV1BorrowerEnforcer is AstariaV1Test, AstariaV1BorrowerEnforcer {
function testV1BorrowerEnforcerStart() public {
Starport.Loan memory loan = generateDefaultLoanTerms();

AstariaV1BorrowerEnforcer.V1BorrowerDetails memory details = AstariaV1BorrowerEnforcer.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory details = AstariaV1BorrowerEnforcer.Details({
startTime: block.timestamp,
endTime: block.timestamp + 10,
startRate: endRate / 2,
Expand All @@ -68,7 +68,7 @@ contract TestV1BorrowerEnforcer is AstariaV1Test, AstariaV1BorrowerEnforcer {

function testRevertLocateCurrentRateAndAmount() public {
Starport.Loan memory loan = generateDefaultLoanTerms();
AstariaV1BorrowerEnforcer.V1BorrowerDetails memory details = AstariaV1BorrowerEnforcer.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory details = AstariaV1BorrowerEnforcer.Details({
startTime: block.timestamp + 10,
endTime: block.timestamp,
startRate: endRate / 2,
Expand All @@ -91,7 +91,7 @@ contract TestV1BorrowerEnforcer is AstariaV1Test, AstariaV1BorrowerEnforcer {
function testV1BorrowerEnforcerHalfway() public {
Starport.Loan memory loan = generateDefaultLoanTerms();

AstariaV1BorrowerEnforcer.V1BorrowerDetails memory details = AstariaV1BorrowerEnforcer.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory details = AstariaV1BorrowerEnforcer.Details({
startTime: block.timestamp,
endTime: block.timestamp + 10,
startRate: endRate / 2,
Expand All @@ -112,7 +112,7 @@ contract TestV1BorrowerEnforcer is AstariaV1Test, AstariaV1BorrowerEnforcer {
function testV1BorrowerEnforcerDebtAmountOOB() public {
Starport.Loan memory loan = generateDefaultLoanTerms();

AstariaV1BorrowerEnforcer.V1BorrowerDetails memory details = AstariaV1BorrowerEnforcer.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory details = AstariaV1BorrowerEnforcer.Details({
startTime: block.timestamp,
endTime: block.timestamp + 10,
startRate: endRate / 2,
Expand Down Expand Up @@ -142,7 +142,7 @@ contract TestV1BorrowerEnforcer is AstariaV1Test, AstariaV1BorrowerEnforcer {
identifier: 0 // 0 for ERC20
});

AstariaV1BorrowerEnforcer.V1BorrowerDetails memory details = AstariaV1BorrowerEnforcer.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory details = AstariaV1BorrowerEnforcer.Details({
startTime: block.timestamp,
endTime: block.timestamp + 10,
startRate: endRate / 2,
Expand All @@ -167,7 +167,7 @@ contract TestV1BorrowerEnforcer is AstariaV1Test, AstariaV1BorrowerEnforcer {
function testV1BorrowerEnforcerRateGTCurrent() public {
Starport.Loan memory loan = generateDefaultLoanTerms();

AstariaV1BorrowerEnforcer.V1BorrowerDetails memory details = AstariaV1BorrowerEnforcer.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory details = AstariaV1BorrowerEnforcer.Details({
startTime: block.timestamp,
endTime: block.timestamp + 10,
startRate: endRate / 2,
Expand All @@ -187,7 +187,7 @@ contract TestV1BorrowerEnforcer is AstariaV1Test, AstariaV1BorrowerEnforcer {
function testV1BorrowerEnforcerRateLTCurrent() public {
Starport.Loan memory loan = generateDefaultLoanTerms();

AstariaV1BorrowerEnforcer.V1BorrowerDetails memory details = AstariaV1BorrowerEnforcer.V1BorrowerDetails({
AstariaV1BorrowerEnforcer.Details memory details = AstariaV1BorrowerEnforcer.Details({
startTime: block.timestamp,
endTime: block.timestamp + 10,
startRate: endRate / 2,
Expand Down
12 changes: 6 additions & 6 deletions test/TestV1LenderEnforcer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract TestV1LenderEnforcer is AstariaV1Test, AstariaV1LenderEnforcer {
function testV1LenderEnforcerAmount() public {
Starport.Loan memory loan = generateDefaultLoanTerms();
uint256 max = loan.debt[0].amount;
AstariaV1LenderEnforcer.V1LenderDetails memory details = AstariaV1LenderEnforcer.V1LenderDetails({
AstariaV1LenderEnforcer.Details memory details = AstariaV1LenderEnforcer.Details({
matchIdentifier: true,
minDebtAmount: loan.debt[0].amount / 2,
loan: loanCopy(loan)
Expand Down Expand Up @@ -57,7 +57,7 @@ contract TestV1LenderEnforcer is AstariaV1Test, AstariaV1LenderEnforcer {

function testV1LenderEnforcerMinDebtExceedsMax() public {
Starport.Loan memory loan = generateDefaultLoanTerms();
AstariaV1LenderEnforcer.V1LenderDetails memory details = AstariaV1LenderEnforcer.V1LenderDetails({
AstariaV1LenderEnforcer.Details memory details = AstariaV1LenderEnforcer.Details({
matchIdentifier: true,
minDebtAmount: loan.debt[0].amount + 1,
loan: loanCopy(loan)
Expand All @@ -71,7 +71,7 @@ contract TestV1LenderEnforcer is AstariaV1Test, AstariaV1LenderEnforcer {
function testV1LenderEnforcerRate() public {
Starport.Loan memory loan = generateDefaultLoanTerms();

AstariaV1LenderEnforcer.V1LenderDetails memory details = AstariaV1LenderEnforcer.V1LenderDetails({
AstariaV1LenderEnforcer.Details memory details = AstariaV1LenderEnforcer.Details({
matchIdentifier: true,
minDebtAmount: loan.debt[0].amount,
loan: loanCopy(loan)
Expand All @@ -95,7 +95,7 @@ contract TestV1LenderEnforcer is AstariaV1Test, AstariaV1LenderEnforcer {
function testV1LenderEnforcerMatchIdentifier() public {
Starport.Loan memory loan = generateDefaultLoanTerms();

AstariaV1LenderEnforcer.V1LenderDetails memory details = AstariaV1LenderEnforcer.V1LenderDetails({
AstariaV1LenderEnforcer.Details memory details = AstariaV1LenderEnforcer.Details({
matchIdentifier: false,
minDebtAmount: loan.debt[0].amount,
loan: loanCopy(loan)
Expand All @@ -122,7 +122,7 @@ contract TestV1LenderEnforcer is AstariaV1Test, AstariaV1LenderEnforcer {
});

Starport.Loan memory loan = generateDefaultLoanTerms();
AstariaV1LenderEnforcer.V1LenderDetails memory details = AstariaV1LenderEnforcer.V1LenderDetails({
AstariaV1LenderEnforcer.Details memory details = AstariaV1LenderEnforcer.Details({
matchIdentifier: false,
minDebtAmount: loan.debt[0].amount,
loan: loan
Expand All @@ -143,7 +143,7 @@ contract TestV1LenderEnforcer is AstariaV1Test, AstariaV1LenderEnforcer {
debt[1] = _getERC721SpentItem(TestERC721(loan.debt[0].token), loan.debt[0].identifier + 1);
loan.debt = debt;

AstariaV1LenderEnforcer.V1LenderDetails({matchIdentifier: false, minDebtAmount: loan.debt[0].amount, loan: loan});
AstariaV1LenderEnforcer.Details({matchIdentifier: false, minDebtAmount: loan.debt[0].amount, loan: loan});

vm.expectRevert(DebtBundlesNotSupported.selector);
lenderEnforcer.validate(new AdditionalTransfer[](0), loan, abi.encode(LenderEnforcer.Details({loan: loan})));
Expand Down
2 changes: 1 addition & 1 deletion test/fuzz-testing/TestFuzzV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ contract TestFuzzV1 is AstariaV1Test, TestFuzzStarport {
refiLoan.terms.pricingData = pricingData;
refiLoan.debt = SP.applyRefinanceConsiderationToLoan(considerationPayment, carryPayment);

AstariaV1LenderEnforcer.V1LenderDetails memory lenderDetails = AstariaV1LenderEnforcer.V1LenderDetails({
AstariaV1LenderEnforcer.Details memory lenderDetails = AstariaV1LenderEnforcer.Details({
matchIdentifier: true,
minDebtAmount: refiLoan.debt[0].amount,
loan: refiLoan
Expand Down

0 comments on commit 34065ff

Please sign in to comment.