From b180bb293d3b3557efa2b96a74ed07e09bc59442 Mon Sep 17 00:00:00 2001 From: Joseph Delong Date: Mon, 20 Nov 2023 17:24:43 -0600 Subject: [PATCH] feat: change deadline to be block.number (#78) --- .gas-snapshot | 2 +- src/Starport.sol | 2 +- test/StarportTest.sol | 7 +++---- test/integration-testing/TestCaveats.sol | 2 +- test/integration-testing/TestNewLoan.sol | 6 +++--- test/unit-testing/TestStrategistOriginator.sol | 18 +++++++++--------- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 9659f5ad..80691aef 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -1,7 +1,7 @@ IntegrationTestCaveats:testOriginateUnapprovedFulfiller() (gas: 327586) IntegrationTestCaveats:testOriginateWBorrowerApproval() (gas: 281010) IntegrationTestCaveats:testOriginateWCaveatsAsBorrower() (gas: 303246) -IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 157436) +IntegrationTestCaveats:testOriginateWCaveatsExpired() (gas: 157348) IntegrationTestCaveats:testOriginateWCaveatsIncrementedNonce() (gas: 166167) IntegrationTestCaveats:testOriginateWCaveatsInvalidSalt() (gas: 281357) IntegrationTestCaveats:testOriginateWCaveatsInvalidSaltManual() (gas: 140098) diff --git a/src/Starport.sol b/src/Starport.sol index 51dd67ad..7cd710aa 100644 --- a/src/Starport.sol +++ b/src/Starport.sol @@ -537,7 +537,7 @@ contract Starport is PausableNonReentrant { emit CaveatFilled(validator, hash, signedCaveats.salt); } - if (block.timestamp > signedCaveats.deadline) { + if (block.number > signedCaveats.deadline) { revert CaveatDeadlineExpired(); } if (!SignatureCheckerLib.isValidSignatureNowCalldata(validator, hash, signedCaveats.signature)) { diff --git a/test/StarportTest.sol b/test/StarportTest.sol index 346a4148..45fbc6ac 100644 --- a/test/StarportTest.sol +++ b/test/StarportTest.sol @@ -46,7 +46,6 @@ import {TestERC721} from "seaport/contracts/test/TestERC721.sol"; import {TestERC1155} from "seaport/contracts/test/TestERC1155.sol"; import {TestERC20} from "seaport/contracts/test/TestERC20.sol"; import {ConsiderationItemLib} from "seaport/lib/seaport-sol/src/lib/ConsiderationItemLib.sol"; -//import {AAVEPoolCustodian} from "starport-core/custodians/AAVEPoolCustodian.sol"; import {Custodian} from "starport-core/Custodian.sol"; import "seaport/lib/seaport-sol/src/lib/AdvancedOrderLib.sol"; import {Status} from "starport-core/status/Status.sol"; @@ -307,7 +306,7 @@ contract StarportTest is BaseOrderTest { signedCaveats = CaveatEnforcer.SignedCaveats({ signature: "", singleUse: invalidate, - deadline: block.timestamp + 1 days, + deadline: block.number + (1 days / 12), salt: salt, caveats: new CaveatEnforcer.Caveat[](1) }); @@ -410,7 +409,7 @@ contract StarportTest is BaseOrderTest { signedCaveats.caveats = new CaveatEnforcer.Caveat[](1); signedCaveats.salt = salt; signedCaveats.singleUse = true; - signedCaveats.deadline = block.timestamp + 1 days; + signedCaveats.deadline = block.number + (1 days / 12); signedCaveats.caveats[0] = CaveatEnforcer.Caveat({enforcer: enforcer, data: abi.encode(details)}); bytes32 hash = SP.hashCaveatWithSaltAndNonce( signer.addr, signedCaveats.singleUse, salt, signedCaveats.deadline, signedCaveats.caveats @@ -429,7 +428,7 @@ contract StarportTest is BaseOrderTest { signedCaveats.caveats = new CaveatEnforcer.Caveat[](1); signedCaveats.salt = salt; signedCaveats.singleUse = true; - signedCaveats.deadline = block.timestamp + 1 days; + signedCaveats.deadline = block.number + (1 days / 12); signedCaveats.caveats[0] = CaveatEnforcer.Caveat({enforcer: enforcer, data: abi.encode(details)}); bytes32 hash = SP.hashCaveatWithSaltAndNonce( signer.addr, signedCaveats.singleUse, salt, signedCaveats.deadline, signedCaveats.caveats diff --git a/test/integration-testing/TestCaveats.sol b/test/integration-testing/TestCaveats.sol index 4479896a..1e4f2529 100644 --- a/test/integration-testing/TestCaveats.sol +++ b/test/integration-testing/TestCaveats.sol @@ -68,7 +68,7 @@ contract IntegrationTestCaveats is StarportTest, DeepEq, MockCall { salt: bytes32(uint256(1)), enforcer: address(borrowerEnforcer) }); - skip(borrowerCaveat.deadline + 1); + vm.roll(borrowerCaveat.deadline + 1); _setApprovalsForSpentItems(borrower.addr, loan.collateral); _setApprovalsForSpentItems(lender.addr, loan.debt); diff --git a/test/integration-testing/TestNewLoan.sol b/test/integration-testing/TestNewLoan.sol index 5099ee4d..590a0aa7 100644 --- a/test/integration-testing/TestNewLoan.sol +++ b/test/integration-testing/TestNewLoan.sol @@ -293,7 +293,7 @@ contract TestNewLoan is StarportTest { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -334,7 +334,7 @@ contract TestNewLoan is StarportTest { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -548,7 +548,7 @@ contract TestNewLoan is StarportTest { signedCaveats = CaveatEnforcer.SignedCaveats({ signature: "", singleUse: invalidate, - deadline: block.timestamp + 1 days, + deadline: block.number + (1 days / 12), salt: salt, caveats: new CaveatEnforcer.Caveat[](1) }); diff --git a/test/unit-testing/TestStrategistOriginator.sol b/test/unit-testing/TestStrategistOriginator.sol index c58b749f..7ba01d3b 100644 --- a/test/unit-testing/TestStrategistOriginator.sol +++ b/test/unit-testing/TestStrategistOriginator.sol @@ -68,7 +68,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -110,7 +110,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -153,7 +153,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -196,7 +196,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -240,7 +240,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -282,7 +282,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -324,7 +324,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -368,7 +368,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(0), @@ -412,7 +412,7 @@ contract TestStrategistOriginator is StarportTest, DeepEq { StrategistOriginator.Details memory newLoanDetails = StrategistOriginator.Details({ custodian: SP.defaultCustodian(), issuer: lender.addr, - deadline: block.timestamp + 100, + deadline: block.number + 8, offer: StrategistOriginator.Offer({ terms: loan.terms, salt: bytes32(uint256(1)),