Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Maree <[email protected]>
  • Loading branch information
chrismaree committed Jan 10, 2025
2 parents 29e28d5 + 6a2f8ac commit 41bb920
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
10 changes: 6 additions & 4 deletions contracts/SpokePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ abstract contract SpokePool is
* handleV3AcrossMessage() public function
* @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.
* @param repaymentAddress Address the relayer wants to be receive their refund at.
*/
function fillRelay(
V3RelayData memory relayData,
Expand Down Expand Up @@ -1018,6 +1019,7 @@ abstract contract SpokePool is
* @param relayData struct containing all the data needed to identify the deposit to be filled. See fillV3Relay().
* @param repaymentChainId Chain of SpokePool where relayer wants to be refunded after the challenge window has
* passed. See fillV3Relay().
* @param repaymentAddress Address the relayer wants to be receive their refund at.
* @param updatedOutputAmount New output amount to use for this deposit.
* @param updatedRecipient New recipient to use for this deposit.
* @param updatedMessage New message to use for this deposit.
Expand Down Expand Up @@ -1251,10 +1253,10 @@ abstract contract SpokePool is
* @param l2TokenAddress Address of the L2 token to claim refunds for.
* @param refundAddress Address to send the refund to.
*/
function claimRelayerRefund(bytes32 l2TokenAddress, bytes32 refundAddress) public {
function claimRelayerRefund(bytes32 l2TokenAddress, bytes32 refundAddress) external {
uint256 refund = relayerRefund[l2TokenAddress.toAddress()][msg.sender];
if (refund == 0) revert NoRelayerRefundToClaim();
relayerRefund[l2TokenAddress.toAddress()][refundAddress.toAddress()] = 0;
relayerRefund[l2TokenAddress.toAddress()][msg.sender] = 0;
IERC20Upgradeable(l2TokenAddress.toAddress()).safeTransfer(refundAddress.toAddress(), refund);

emit ClaimedRelayerRefund(l2TokenAddress, refundAddress, refund, msg.sender);
Expand Down Expand Up @@ -1283,7 +1285,7 @@ abstract contract SpokePool is
/**
* @notice Returns the deposit ID for an unsafe deposit. This function is used to compute the deposit ID
* in unsafeDepositV3 and is provided as a convenience.
* @dev msgSenderand depositor are both used as inputs to allow passthrough depositors to create unique
* @dev msgSender and depositor are both used as inputs to allow passthrough depositors to create unique
* deposit hash spaces for unique depositors.
* @param msgSender The caller of the transaction used as input to produce the deposit ID.
* @param depositor The depositor address used as input to produce the deposit ID.
Expand Down Expand Up @@ -1488,7 +1490,7 @@ abstract contract SpokePool is
bool success = _noRevertTransfer(l2TokenAddress, refundAddresses[i], refundAmounts[i]);

// If the transfer failed then track a deferred transfer for the relayer. Given this function would
// have revered if there was insufficient balance, this will only happen if the transfer call
// have reverted if there was insufficient balance, this will only happen if the transfer call
// reverts. This will only occur if the underlying transfer method on the l2Token reverts due to
// recipient blacklisting or other related modifications to the l2Token.transfer method.
if (!success) {
Expand Down
32 changes: 12 additions & 20 deletions contracts/erc7683/ERC7683OrderDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import { Output, GaslessCrossChainOrder, OnchainCrossChainOrder, ResolvedCrossChainOrder, IOriginSettler, FillInstruction } from "./ERC7683.sol";
import { AcrossOrderData, AcrossOriginFillerData, ERC7683Permit2Lib, ACROSS_ORDER_DATA_TYPE_HASH } from "./ERC7683Permit2Lib.sol";
import { AddressToBytes32 } from "../libraries/AddressConverters.sol";
import { AddressToBytes32, Bytes32ToAddress } from "../libraries/AddressConverters.sol";

/**
* @notice ERC7683OrderDepositor processes an external order type and translates it into an AcrossV3 deposit.
Expand All @@ -19,6 +19,7 @@ import { AddressToBytes32 } from "../libraries/AddressConverters.sol";
*/
abstract contract ERC7683OrderDepositor is IOriginSettler {
using SafeERC20 for IERC20;
using Bytes32ToAddress for bytes32;
using AddressToBytes32 for address;

error WrongSettlementContract();
Expand Down Expand Up @@ -66,7 +67,7 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {

_callDeposit(
order.user,
_toAddress(acrossOrderData.recipient),
acrossOrderData.recipient.toAddress(),
acrossOrderData.inputToken,
acrossOrderData.outputToken,
acrossOrderData.inputAmount,
Expand Down Expand Up @@ -97,7 +98,7 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {

_callDeposit(
msg.sender,
_toAddress(acrossOrderData.recipient),
acrossOrderData.recipient.toAddress(),
acrossOrderData.inputToken,
acrossOrderData.outputToken,
acrossOrderData.inputAmount,
Expand Down Expand Up @@ -208,7 +209,7 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {

Output[] memory maxSpent = new Output[](1);
maxSpent[0] = Output({
token: _toBytes32(acrossOrderData.outputToken),
token: acrossOrderData.outputToken.toBytes32(),
amount: acrossOrderData.outputAmount,
recipient: acrossOrderData.recipient,
chainId: acrossOrderData.destinationChainId
Expand All @@ -220,9 +221,9 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
// repayment on.
Output[] memory minReceived = new Output[](1);
minReceived[0] = Output({
token: _toBytes32(acrossOrderData.inputToken),
token: acrossOrderData.inputToken.toBytes32(),
amount: acrossOrderData.inputAmount,
recipient: _toBytes32(acrossOriginFillerData.exclusiveRelayer),
recipient: acrossOriginFillerData.exclusiveRelayer.toBytes32(),
chainId: block.chainid
});

Expand All @@ -242,7 +243,7 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
relayData.message = acrossOrderData.message;
fillInstructions[0] = FillInstruction({
destinationChainId: SafeCast.toUint64(acrossOrderData.destinationChainId),
destinationSettler: _toBytes32(_destinationSettler(acrossOrderData.destinationChainId)),
destinationSettler: _destinationSettler(acrossOrderData.destinationChainId).toBytes32(),
originData: abi.encode(relayData)
});

Expand Down Expand Up @@ -272,7 +273,7 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {

Output[] memory maxSpent = new Output[](1);
maxSpent[0] = Output({
token: _toBytes32(acrossOrderData.outputToken),
token: acrossOrderData.outputToken.toBytes32(),
amount: acrossOrderData.outputAmount,
recipient: acrossOrderData.recipient,
chainId: acrossOrderData.destinationChainId
Expand All @@ -284,9 +285,9 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
// repayment on.
Output[] memory minReceived = new Output[](1);
minReceived[0] = Output({
token: _toBytes32(acrossOrderData.inputToken),
token: acrossOrderData.inputToken.toBytes32(),
amount: acrossOrderData.inputAmount,
recipient: _toBytes32(acrossOrderData.exclusiveRelayer),
recipient: acrossOrderData.exclusiveRelayer.toBytes32(),
chainId: block.chainid
});

Expand All @@ -306,7 +307,7 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
relayData.message = acrossOrderData.message;
fillInstructions[0] = FillInstruction({
destinationChainId: SafeCast.toUint64(acrossOrderData.destinationChainId),
destinationSettler: _toBytes32(_destinationSettler(acrossOrderData.destinationChainId)),
destinationSettler: _destinationSettler(acrossOrderData.destinationChainId).toBytes32(),
originData: abi.encode(relayData)
});

Expand Down Expand Up @@ -352,15 +353,6 @@ abstract contract ERC7683OrderDepositor is IOriginSettler {
);
}

function _toBytes32(address input) internal pure returns (bytes32) {
return bytes32(uint256(uint160(input)));
}

function _toAddress(bytes32 _bytes32) internal pure returns (address) {
require(uint256(_bytes32) >> 160 == 0, "Invalid bytes32: highest 12 bytes must be 0");
return address(uint160(uint256(_bytes32)));
}

function _callDeposit(
address depositor,
address recipient,
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/V3SpokePoolInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ interface V3SpokePoolInterface {
bytes32[] calldata proof
) external;

function claimRelayerRefund(bytes32 l2TokenAddress, bytes32 refundAddress) external;

/**************************************
* ERRORS *
**************************************/
Expand Down
2 changes: 1 addition & 1 deletion contracts/libraries/AddressConverters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ library Bytes32ToAddress {
error InvalidBytes32();

function toAddress(bytes32 _bytes32) internal pure returns (address) {
if (uint256(_bytes32) >> 192 != 0) {
if (uint256(_bytes32) >> 160 != 0) {
revert InvalidBytes32();
}
return address(uint160(uint256(_bytes32)));
Expand Down

0 comments on commit 41bb920

Please sign in to comment.