Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update function and event naming for backwards compatibility #805

Open
wants to merge 25 commits into
base: svm-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 49 additions & 14 deletions contracts/SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ abstract contract SpokePool is
* @param message The message to send to the recipient on the destination chain if the recipient is a contract.
* If the message is not empty, the recipient contract must implement handleV3AcrossMessage() or the fill will revert.
*/
function depositV3(
function depositV3Bytes32(
bytes32 depositor,
bytes32 recipient,
bytes32 inputToken,
Expand Down Expand Up @@ -596,7 +596,7 @@ abstract contract SpokePool is
uint32 exclusivityParameter,
bytes calldata message
) public payable override {
depositV3(
depositV3Bytes32(
depositor.toBytes32(),
recipient.toBytes32(),
inputToken.toBytes32(),
Expand Down Expand Up @@ -633,8 +633,8 @@ abstract contract SpokePool is
uint32 fillDeadline,
uint32 exclusivityParameter,
bytes calldata message
) public payable {
unsafeDepositV3(
) public payable override {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this did not have override, so I've added it to the interface.

unsafeDepositV3Bytes32(
depositor.toBytes32(),
recipient.toBytes32(),
inputToken.toBytes32(),
Expand Down Expand Up @@ -683,7 +683,7 @@ abstract contract SpokePool is
* @param exclusivityParameter See identically named parameter in depositV3() comments.
* @param message See identically named parameter in depositV3() comments.
*/
function unsafeDepositV3(
function unsafeDepositV3Bytes32(
bytes32 depositor,
bytes32 recipient,
bytes32 inputToken,
Expand Down Expand Up @@ -754,7 +754,7 @@ abstract contract SpokePool is
* @param message The message to send to the recipient on the destination chain if the recipient is a contract.
* If the message is not empty, the recipient contract must implement handleV3AcrossMessage() or the fill will revert.
*/
function depositV3Now(
function depositV3NowBytes32(
bytes32 depositor,
bytes32 recipient,
bytes32 inputToken,
Expand All @@ -766,8 +766,8 @@ abstract contract SpokePool is
uint32 fillDeadlineOffset,
uint32 exclusivityPeriod,
bytes calldata message
) external payable {
depositV3(
) external payable override {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was also missing from interface.

depositV3Bytes32(
depositor,
recipient,
inputToken,
Expand Down Expand Up @@ -827,7 +827,7 @@ abstract contract SpokePool is
uint32 fillDeadlineOffset,
uint32 exclusivityPeriod,
bytes calldata message
) external payable {
) external payable override {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was also missing from interface.

depositV3(
depositor,
recipient,
Expand Down Expand Up @@ -862,7 +862,7 @@ abstract contract SpokePool is
* account. If depositor is a contract, then should implement EIP1271 to sign as a contract. See
* _verifyUpdateV3DepositMessage() for more details about how this signature should be constructed.
*/
function speedUpV3Deposit(
function speedUpV3DepositBytes32(
bytes32 depositor,
uint256 depositId,
uint256 updatedOutputAmount,
Expand Down Expand Up @@ -994,7 +994,7 @@ abstract contract SpokePool is
* @param repaymentChainId Chain of SpokePool where relayer wants to be refunded after the challenge window has
* passed. Will receive inputAmount of the equivalent token to inputToken on the repayment chain.
*/
function fillV3Relay(
function fillV3RelayBytes32(
V3RelayData calldata relayData,
uint256 repaymentChainId,
bytes32 repaymentAddress
Expand All @@ -1020,6 +1020,39 @@ abstract contract SpokePool is
_fillRelayV3(relayExecution, repaymentAddress, false);
}

// Exposes the same function as fillV3Relay but with a legacy V3RelayData struct that takes in address types. Inner
// function fillV3Relay() applies reentrancy & non-paused checks.
function fillV3Relay(V3RelayDataLegacy calldata relayData, uint256 repaymentChainId) public override {
// Convert V3RelayDataLegacy to V3RelayData using the .toBytes32() method
V3RelayData memory convertedRelayData = V3RelayData({
depositor: relayData.depositor.toBytes32(),
recipient: relayData.recipient.toBytes32(),
exclusiveRelayer: relayData.exclusiveRelayer.toBytes32(),
inputToken: relayData.inputToken.toBytes32(),
outputToken: relayData.outputToken.toBytes32(),
inputAmount: relayData.inputAmount,
outputAmount: relayData.outputAmount,
originChainId: relayData.originChainId,
depositId: relayData.depositId,
fillDeadline: relayData.fillDeadline,
exclusivityDeadline: relayData.exclusivityDeadline,
message: relayData.message
});

// Call the existing fillV3Relay function
(bool success, bytes memory data) = address(this).delegatecall(
abi.encodeWithSignature(
"fillV3RelayBytes32((bytes32,bytes32,bytes32,bytes32,bytes32,uint256,uint256,uint256,uint256,uint32,uint32,bytes),uint256,bytes32)",
convertedRelayData,
repaymentChainId,
msg.sender.toBytes32()
)
);
if (!success) {
revert LowLevelCallFailed(data);
}
}

/**
* @notice Identical to fillV3Relay except that the relayer wants to use a depositor's updated output amount,
* recipient, and/or message. The relayer should only use this function if they can supply a message signed
Expand Down Expand Up @@ -1149,9 +1182,11 @@ abstract contract SpokePool is

// Must do a delegatecall because the function requires the inputs to be calldata.
(bool success, bytes memory data) = address(this).delegatecall(
abi.encodeCall(
V3SpokePoolInterface.fillV3Relay,
(relayData, destinationFillerData.repaymentChainId, msg.sender.toBytes32())
abi.encode(
"fillV3Relay((bytes32,bytes32,bytes32,bytes32,bytes32,uint256,uint256,uint256,uint256,uint32,uint32,bytes),uint256,bytes32)",
relayData,
destinationFillerData.repaymentChainId,
msg.sender.toBytes32()
)
);
if (!success) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/SpokePoolVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract SpokePoolVerifier {
if (msg.value != inputAmount) revert InvalidMsgValue();
if (!address(spokePool).isContract()) revert InvalidSpokePool();
// Set msg.sender as the depositor so that msg.sender can speed up the deposit.
spokePool.depositV3{ value: msg.value }(
spokePool.depositV3Bytes32{ value: msg.value }(
msg.sender.toBytes32(),
recipient,
inputToken,
Expand Down
2 changes: 1 addition & 1 deletion contracts/SwapAndBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ abstract contract SwapAndBridgeBase is Lockable, MultiCaller {
DepositData calldata depositData
) internal {
_acrossInputToken.safeIncreaseAllowance(address(spokePool), _acrossInputAmount);
spokePool.depositV3(
spokePool.depositV3Bytes32(
depositData.depositor.toBytes32(),
depositData.recipient.toBytes32(),
address(_acrossInputToken).toBytes32(), // input token
Expand Down
82 changes: 78 additions & 4 deletions contracts/interfaces/V3SpokePoolInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ interface V3SpokePoolInterface {
bytes message;
}

// Same as V3RelayData but using addresses instead of bytes32 & depositId is uint32.
// Will be deprecated in favor of V3RelayData in the future.
struct V3RelayDataLegacy {
address depositor;
address recipient;
address exclusiveRelayer;
address inputToken;
address outputToken;
uint256 inputAmount;
uint256 outputAmount;
uint256 originChainId;
uint32 depositId;
uint32 fillDeadline;
uint32 exclusivityDeadline;
bytes message;
}

// Contains parameters passed in by someone who wants to execute a slow relay leaf.
struct V3SlowFill {
V3RelayData relayData;
Expand Down Expand Up @@ -182,7 +199,7 @@ interface V3SpokePoolInterface {
* FUNCTIONS *
**************************************/

function depositV3(
function depositV3Bytes32(
bytes32 depositor,
bytes32 recipient,
bytes32 inputToken,
Expand Down Expand Up @@ -212,7 +229,7 @@ interface V3SpokePoolInterface {
bytes calldata message
) external payable;

function depositV3Now(
function depositV3NowBytes32(
bytes32 depositor,
bytes32 recipient,
bytes32 inputToken,
Expand All @@ -226,7 +243,53 @@ interface V3SpokePoolInterface {
bytes calldata message
) external payable;

function speedUpV3Deposit(
function depositV3Now(
address depositor,
address recipient,
address inputToken,
address outputToken,
uint256 inputAmount,
uint256 outputAmount,
uint256 destinationChainId,
address exclusiveRelayer,
uint32 fillDeadlineOffset,
uint32 exclusivityDeadline,
bytes calldata message
) external payable;

function unsafeDepositV3Bytes32(
bytes32 depositor,
bytes32 recipient,
bytes32 inputToken,
bytes32 outputToken,
uint256 inputAmount,
uint256 outputAmount,
uint256 destinationChainId,
bytes32 exclusiveRelayer,
uint256 depositNonce,
uint32 quoteTimestamp,
uint32 fillDeadline,
uint32 exclusivityParameter,
bytes calldata message
) external payable;

function unsafeDepositV3(
address depositor,
address recipient,
address inputToken,
address outputToken,
uint256 inputAmount,
uint256 outputAmount,
uint256 destinationChainId,
address exclusiveRelayer,
uint256 depositNonce,
uint32 quoteTimestamp,
uint32 fillDeadline,
uint32 exclusivityParameter,
bytes calldata message
) external payable;

function speedUpV3DepositBytes32(
bytes32 depositor,
uint256 depositId,
uint256 updatedOutputAmount,
Expand All @@ -235,12 +298,23 @@ interface V3SpokePoolInterface {
bytes calldata depositorSignature
) external;

function fillV3Relay(
function speedUpV3Deposit(
address depositor,
uint256 depositId,
uint256 updatedOutputAmount,
address updatedRecipient,
bytes calldata updatedMessage,
bytes calldata depositorSignature
) external;

function fillV3RelayBytes32(
V3RelayData calldata relayData,
uint256 repaymentChainId,
bytes32 repaymentAddress
) external;

function fillV3Relay(V3RelayDataLegacy calldata relayData, uint256 repaymentChainId) external;

function fillV3RelayWithUpdatedDeposit(
V3RelayData calldata relayData,
uint256 repaymentChainId,
Expand Down
2 changes: 1 addition & 1 deletion contracts/permit2-order/Permit2Depositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract Permit2Depositor {
uint256 amountToDeposit = order.input.amount + order.fillerCollateral.amount;

IERC20(order.input.token).safeIncreaseAllowance(address(SPOKE_POOL), amountToDeposit);
SPOKE_POOL.depositV3(
SPOKE_POOL.depositV3Bytes32(
order.info.offerer.toBytes32(),
// Note: Permit2OrderLib checks that order only has a single output.
order.outputs[0].recipient.toBytes32(),
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/MockSpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract MockSpokePool is SpokePool, MockV2SpokePoolInterface, OwnableUpgradeabl
_verifyDepositorSignature(depositor, expectedTypedDataV4Hash, depositorSignature);
}

function verifyUpdateV3DepositMessage(
function verifyUpdateV3DepositMessageBytes32(
bytes32 depositor,
uint256 depositId,
uint256 originChainId,
Expand Down
Loading
Loading