Skip to content

Commit

Permalink
feat: change deadline to be block.number (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangerousfood authored Nov 20, 2023
1 parent 15f71cf commit b180bb2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gas-snapshot
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Starport.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 3 additions & 4 deletions test/StarportTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
});
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration-testing/TestCaveats.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/integration-testing/TestNewLoan.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
});
Expand Down
18 changes: 9 additions & 9 deletions test/unit-testing/TestStrategistOriginator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)),
Expand Down

0 comments on commit b180bb2

Please sign in to comment.