Skip to content

Commit

Permalink
Merge branch 'npai/exclusivity-switch' into mrice32/deterministic-new
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai committed Oct 30, 2024
2 parents 6fe3534 + dddfaee commit 2432944
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 268 deletions.
169 changes: 55 additions & 114 deletions contracts/SpokePool.sol

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions contracts/erc7683/ERC7683Across.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct AcrossOrderData {
uint32 destinationChainId;
address recipient;
address exclusiveRelayer;
uint256 depositNonce;
uint32 exclusivityPeriod;
bytes message;
}
Expand All @@ -35,7 +34,6 @@ bytes constant ACROSS_ORDER_DATA_TYPE = abi.encodePacked(
"uint32 destinationChainId,",
"address recipient,",
"address exclusiveRelayer,"
"uint256 depositNonce,",
"uint32 exclusivityPeriod,",
"bytes message)"
);
Expand Down
20 changes: 4 additions & 16 deletions contracts/erc7683/ERC7683OrderDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
acrossOrderData.outputAmount,
acrossOrderData.destinationChainId,
acrossOriginFillerData.exclusiveRelayer,
acrossOrderData.depositNonce,
// Note: simplifying assumption to avoid quote timestamps that cause orders to expire before the deadline.
SafeCast.toUint32(order.openDeadline - QUOTE_BEFORE_DEADLINE),
order.fillDeadline,
Expand Down Expand Up @@ -101,7 +100,6 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
acrossOrderData.outputAmount,
acrossOrderData.destinationChainId,
acrossOrderData.exclusiveRelayer,
acrossOrderData.depositNonce,
// Note: simplifying assumption to avoid the order type having to bake in the quote timestamp.
SafeCast.toUint32(block.timestamp),
order.fillDeadline,
Expand Down Expand Up @@ -160,17 +158,6 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
return SafeCast.toUint32(block.timestamp); // solhint-disable-line not-rely-on-time
}

/**
* @notice Convenience method to compute the Across depositId for orders sent through 7683.
* @dev if a 0 depositNonce is used, the depositId will not be deterministic (meaning it can change depending on
* when the open txn is mined), but you will be safe from collisions. See the unsafeDepositV3 method on SpokePool
* for more details on how to choose between deterministic and non-deterministic.
* @param depositNonce the depositNonce field in the order.
* @param depositor the sender or signer of the order.
* @return the resulting Across depositId.
*/
function computeDepositId(uint256 depositNonce, address depositor) public view virtual returns (uint256);

function _resolveFor(GaslessCrossChainOrder calldata order, bytes calldata fillerData)
internal
view
Expand Down Expand Up @@ -236,7 +223,7 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
acrossOrderData.inputAmount,
acrossOrderData.outputAmount,
block.chainid,
computeDepositId(acrossOrderData.depositNonce, order.user),
_currentDepositId(),
order.fillDeadline,
acrossOrderData.exclusivityPeriod,
acrossOrderData.message
Expand Down Expand Up @@ -299,7 +286,7 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
acrossOrderData.inputAmount,
acrossOrderData.outputAmount,
block.chainid,
computeDepositId(acrossOrderData.depositNonce, msg.sender),
_currentDepositId(),
order.fillDeadline,
acrossOrderData.exclusivityPeriod,
acrossOrderData.message
Expand Down Expand Up @@ -360,12 +347,13 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
uint256 outputAmount,
uint256 destinationChainId,
address exclusiveRelayer,
uint256 depositNonce,
uint32 quoteTimestamp,
uint32 fillDeadline,
uint32 exclusivityDeadline,
bytes memory message
) internal virtual;

function _currentDepositId() internal view virtual returns (uint32);

function _destinationSettler(uint256 chainId) internal view virtual returns (address);
}
54 changes: 16 additions & 38 deletions contracts/erc7683/ERC7683OrderDepositorExternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,53 +50,31 @@ contract ERC7683OrderDepositorExternal is ERC7683OrderDepositor, Ownable, MultiC
uint256 outputAmount,
uint256 destinationChainId,
address exclusiveRelayer,
uint256 depositNonce,
uint32 quoteTimestamp,
uint32 fillDeadline,
uint32 exclusivityDeadline,
bytes memory message
) internal override {
IERC20(inputToken).safeIncreaseAllowance(address(SPOKE_POOL), inputAmount);

if (depositNonce == 0) {
SPOKE_POOL.depositV3(
depositor,
recipient,
inputToken,
outputToken,
inputAmount,
outputAmount,
destinationChainId,
exclusiveRelayer,
quoteTimestamp,
fillDeadline,
exclusivityDeadline,
message
);
} else {
SPOKE_POOL.unsafeDepositV3(
depositor,
recipient,
inputToken,
outputToken,
inputAmount,
outputAmount,
destinationChainId,
exclusiveRelayer,
depositNonce,
quoteTimestamp,
fillDeadline,
exclusivityDeadline,
message
);
}
SPOKE_POOL.depositV3(
depositor,
recipient,
inputToken,
outputToken,
inputAmount,
outputAmount,
destinationChainId,
exclusiveRelayer,
quoteTimestamp,
fillDeadline,
exclusivityDeadline,
message
);
}

function computeDepositId(uint256 depositNonce, address depositor) public view override returns (uint256) {
return
depositNonce == 0
? SPOKE_POOL.numberOfDeposits()
: SPOKE_POOL.getUnsafeDepositId(address(this), depositor, depositNonce);
function _currentDepositId() internal view override returns (uint32) {
return SPOKE_POOL.numberOfDeposits();
}

function _destinationSettler(uint256 chainId) internal view override returns (address) {
Expand Down
14 changes: 7 additions & 7 deletions contracts/interfaces/V3SpokePoolInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface V3SpokePoolInterface {
// Origin chain id.
uint256 originChainId;
// The id uniquely identifying this deposit on the origin chain.
uint256 depositId;
uint32 depositId;
// The timestamp on the destination chain after which this deposit can no longer be filled.
uint32 fillDeadline;
// The timestamp on the destination chain after which any relayer can fill the deposit.
Expand Down Expand Up @@ -102,7 +102,7 @@ interface V3SpokePoolInterface {
uint256 inputAmount,
uint256 outputAmount,
uint256 indexed destinationChainId,
uint256 indexed depositId,
uint32 indexed depositId,
uint32 quoteTimestamp,
uint32 fillDeadline,
uint32 exclusivityDeadline,
Expand All @@ -114,7 +114,7 @@ interface V3SpokePoolInterface {

event RequestedSpeedUpV3Deposit(
uint256 updatedOutputAmount,
uint256 indexed depositId,
uint32 indexed depositId,
address indexed depositor,
address updatedRecipient,
bytes updatedMessage,
Expand All @@ -128,7 +128,7 @@ interface V3SpokePoolInterface {
uint256 outputAmount,
uint256 repaymentChainId,
uint256 indexed originChainId,
uint256 indexed depositId,
uint32 indexed depositId,
uint32 fillDeadline,
uint32 exclusivityDeadline,
address exclusiveRelayer,
Expand All @@ -145,7 +145,7 @@ interface V3SpokePoolInterface {
uint256 inputAmount,
uint256 outputAmount,
uint256 indexed originChainId,
uint256 indexed depositId,
uint32 indexed depositId,
uint32 fillDeadline,
uint32 exclusivityDeadline,
address exclusiveRelayer,
Expand Down Expand Up @@ -189,7 +189,7 @@ interface V3SpokePoolInterface {

function speedUpV3Deposit(
address depositor,
uint256 depositId,
uint32 depositId,
uint256 updatedOutputAmount,
address updatedRecipient,
bytes calldata updatedMessage,
Expand Down Expand Up @@ -222,7 +222,7 @@ interface V3SpokePoolInterface {
error DisabledRoute();
error InvalidQuoteTimestamp();
error InvalidFillDeadline();
error InvalidExclusivityDeadline();
error InvalidExclusiveRelayer();
error MsgValueDoesNotMatchInputAmount();
error NotExclusiveRelayer();
error NoSlowFillsInExclusivityWindow();
Expand Down
Loading

0 comments on commit 2432944

Please sign in to comment.