Skip to content

Commit b5d169f

Browse files
grasphopernicholaspaibmzigdohakimrice32
authored
feat: [POST AUDIT] OFT changes (#1062)
* fix(ZkSync_SpokePool): Add __gap (#907) * fix(ZkSync_SpokePool): Add __gap This contract gets extended by the Lens_SpokePool which doesn't add any storage but we should add it in case a future variable gets added to the Lens_SpokePool * Update ZkSync_SpokePool.json * Add `OFTTransportAdapter` to support cross-chain token transfers of `USDT0` via `OFT` messaging protocol (#902) * first draft of OFTTransportAdapter Signed-off-by: Ihor Farion <[email protected]> * update yarn.lock file Signed-off-by: Ihor Farion <[email protected]> * Revert "update yarn.lock file" This reverts commit 4c216ea. Signed-off-by: Ihor Farion <[email protected]> * add yarn.lock compatible with master Signed-off-by: Ihor Farion <[email protected]> * polish OFTTransportAdapter, add OFT support to Arbitrum_Adapter on L1, and Arbitrum_SpokePool on L2 Signed-off-by: Ihor Farion <[email protected]> * polish + fix missing approval Signed-off-by: Ihor Farion <[email protected]> * add context for dstEid Signed-off-by: Ihor Farion <[email protected]> * address most of the PR comments about contracts Signed-off-by: Ihor Farion <[email protected]> * update deploy scripts, add tests for OFT messaging, polish contracts Signed-off-by: Ihor Farion <[email protected]> * cleanup comments and extraneous log file Signed-off-by: Ihor Farion <[email protected]> * revert package.json prepublish change Signed-off-by: Ihor Farion <[email protected]> * generalize oft adapter to support multiple tokens. Introduce OFTAddressBook to support that. Update deploy / test scripts to reflect new functionality Signed-off-by: Ihor Farion <[email protected]> * add __gap to ArbitrumSpokePool, update stale comments on OFTTransportAdapter, update layouts of ArbitrumSpokePool and AlephZeroSpokePool Signed-off-by: Ihor Farion <[email protected]> * update some comments; adjust fee cap naming Signed-off-by: Ihor Farion <[email protected]> * address PR comments Signed-off-by: Ihor Farion <[email protected]> * address PR comments Signed-off-by: Ihor Farion <[email protected]> * fix deploy script, remove incorrect values from consts Signed-off-by: Ihor Farion <[email protected]> * improve comment Signed-off-by: Ihor Farion <[email protected]> * add oftFeeCap as a param to arbitrum adapter construction Signed-off-by: Ihor Farion <[email protected]> * move OFT functionality to SpokePool for easy further integration and removing boilerplate code Signed-off-by: Ihor Farion <[email protected]> * remove layerzero from foundry remappings Signed-off-by: Ihor Farion <[email protected]> * address licensing comment; add permalink to LZ OFT code on github Signed-off-by: Ihor Farion <[email protected]> * fix a couple of comment typos Signed-off-by: Ihor Farion <[email protected]> --------- Signed-off-by: Ihor Farion <[email protected]> * feat(SpokePoolPeriphery): Support multiple exchanges (#777) * feat(SpokePoolPeriphery): Support multiple exchanges Currently we can only initialize the periphery contract with a single exchange to swap with. This PR allows us to initialize it with multiple exchanges to swap with. Like before, these initial set of exchanges and function selectors cannot be changed post-initialization, which gives the user assurances. * rename * Update SpokeV3PoolPeriphery.sol * Update SpokeV3PoolPeriphery.sol * Update SpokeV3PoolPeriphery.sol * Add unit tests * Add whitelistExchanges only owner method * rename * Remove onlyOwner * Remove whitelist of exchanges, add proxy to bypass approval abuse Make user approve proxy contract so no one can use `exchange` + `routerCalldata` to steal their already approved funds via the `SpokePoolPeriphery` * Add some protection to callSpokePoolPeriphery * Only call swapAndBridge through proxy * move periphery funcs into proxy * Update SpokePoolV3Periphery.sol * remove depositERC20 * Update SpokePoolV3Periphery.sol * Add back safeTransferFron's to permit funcs * Add unit tests that check if calling deposit and swapAndBridge with no value fails directly * Add interfaces to make sure we don't add new functions as easily * Add Create2Factory * feat: add permit2 entrypoints to the periphery (#782) * feat: add permit2 entrypoints to the periphery Signed-off-by: Bennett <[email protected]> * Update test/evm/foundry/local/SpokePoolPeriphery.t.sol * Update SpokePoolPeriphery.t.sol * move permit2 to proxy * fix permit2 Signed-off-by: bennett <[email protected]> * wip: swap arguments refactor Signed-off-by: bennett <[email protected]> * implement isValidSignature Signed-off-by: bennett <[email protected]> * 1271 Signed-off-by: bennett <[email protected]> * simplify isValidSignature Signed-off-by: bennett <[email protected]> * rebase /programs on master Signed-off-by: nicholaspai <[email protected]> * clean up comments * rebase programs * fix: consolidate structs so that permit2 witnesses cover inputs Signed-off-by: bennett <[email protected]> * begin permit2 unit tests Signed-off-by: bennett <[email protected]> * rebase * Update SpokePoolPeriphery.t.sol * move type definitions to interface Signed-off-by: bennett <[email protected]> * fix permit2 test Signed-off-by: bennett <[email protected]> * transfer type tests Signed-off-by: bennett <[email protected]> * rename EIP1271Signature to Permi2Approval Signed-off-by: bennett <[email protected]> --------- Signed-off-by: Bennett <[email protected]> Signed-off-by: bennett <[email protected]> Signed-off-by: nicholaspai <[email protected]> Co-authored-by: nicholaspai <[email protected]> Co-authored-by: nicholaspai <[email protected]> * feat: sponsored swap and deposits (#790) * feat: add permit2 entrypoints to the periphery Signed-off-by: Bennett <[email protected]> * Update test/evm/foundry/local/SpokePoolPeriphery.t.sol * Update SpokePoolPeriphery.t.sol * move permit2 to proxy * fix permit2 Signed-off-by: bennett <[email protected]> * wip: swap arguments refactor Signed-off-by: bennett <[email protected]> * implement isValidSignature Signed-off-by: bennett <[email protected]> * 1271 Signed-off-by: bennett <[email protected]> * simplify isValidSignature Signed-off-by: bennett <[email protected]> * rebase /programs on master Signed-off-by: nicholaspai <[email protected]> * clean up comments * rebase programs * feat: sponsored swap and deposits Signed-off-by: bennett <[email protected]> * fix: consolidate structs so that permit2 witnesses cover inputs Signed-off-by: bennett <[email protected]> * begin permit2 unit tests Signed-off-by: bennett <[email protected]> * rebase * Update SpokePoolPeriphery.t.sol * move type definitions to interface Signed-off-by: bennett <[email protected]> * fix permit2 test Signed-off-by: bennett <[email protected]> * transfer type tests Signed-off-by: bennett <[email protected]> * rename EIP1271Signature to Permi2Approval Signed-off-by: bennett <[email protected]> * add mockERC20 which implements permit/receiveWithAuthorization Signed-off-by: bennett <[email protected]> * add tests for permit, permit2, and receiveWithAuth swaps/deposits Signed-off-by: bennett <[email protected]> * add tests for invalid witnesses Signed-off-by: bennett <[email protected]> * factor out signature checking Signed-off-by: bennett <[email protected]> --------- Signed-off-by: Bennett <[email protected]> Signed-off-by: bennett <[email protected]> Signed-off-by: nicholaspai <[email protected]> Co-authored-by: nicholaspai <[email protected]> Co-authored-by: nicholaspai <[email protected]> * feat: Delete SwapAndBridge and add submission fees to gasless flow (#809) * feat: add permit2 entrypoints to the periphery Signed-off-by: Bennett <[email protected]> * Update test/evm/foundry/local/SpokePoolPeriphery.t.sol * Update SpokePoolPeriphery.t.sol * move permit2 to proxy * fix permit2 Signed-off-by: bennett <[email protected]> * wip: swap arguments refactor Signed-off-by: bennett <[email protected]> * implement isValidSignature Signed-off-by: bennett <[email protected]> * 1271 Signed-off-by: bennett <[email protected]> * simplify isValidSignature Signed-off-by: bennett <[email protected]> * rebase /programs on master Signed-off-by: nicholaspai <[email protected]> * clean up comments * rebase programs * feat: sponsored swap and deposits Signed-off-by: bennett <[email protected]> * fix: consolidate structs so that permit2 witnesses cover inputs Signed-off-by: bennett <[email protected]> * begin permit2 unit tests Signed-off-by: bennett <[email protected]> * rebase * Update SpokePoolPeriphery.t.sol * move type definitions to interface Signed-off-by: bennett <[email protected]> * fix permit2 test Signed-off-by: bennett <[email protected]> * transfer type tests Signed-off-by: bennett <[email protected]> * rename EIP1271Signature to Permi2Approval Signed-off-by: bennett <[email protected]> * add mockERC20 which implements permit/receiveWithAuthorization Signed-off-by: bennett <[email protected]> * add tests for permit, permit2, and receiveWithAuth swaps/deposits Signed-off-by: bennett <[email protected]> * add tests for invalid witnesses Signed-off-by: bennett <[email protected]> * feat: Delete SwapAndBridge and add submission fees to gasless flow SwapAndBridge is to be replaced with SpokePoolV3Periphery Gasless flows will require user to cover gas cost of whoever submits the transaction, but they can be set to 0 if the user wants to submit themselves. * Internal refactor * Update SpokePoolV3Periphery.sol * Update PeripherySigningLib.sol * Update SpokePoolV3Periphery.sol * Update PeripherySigningLib.sol --------- Signed-off-by: Bennett <[email protected]> Signed-off-by: bennett <[email protected]> Signed-off-by: nicholaspai <[email protected]> Co-authored-by: Bennett <[email protected]> * Update SpokePoolV3Periphery.sol * Update SpokePoolPeriphery.t.sol * Move all comments to interface and use inherit doc * fix: eip712 types and hashes (#821) * refactor comments Signed-off-by: bennett <[email protected]> * Create IERC20Auth.sol * fix tests * Comments --------- Signed-off-by: Bennett <[email protected]> Signed-off-by: bennett <[email protected]> Signed-off-by: nicholaspai <[email protected]> Co-authored-by: bmzig <[email protected]> Co-authored-by: Bennett <[email protected]> Co-authored-by: Dong-Ha Kim <[email protected]> * Single AddressBook for all adapters (#919) * use a single address book instead of 1 per adapter for oft / xerc20 storage needs Signed-off-by: Ihor Farion <[email protected]> * update comments and naming Signed-off-by: Ihor Farion <[email protected]> * add a gas optimization suggested in OFT PR Signed-off-by: Ihor Farion <[email protected]> * address PR comments and minor improvements Signed-off-by: Ihor Farion <[email protected]> * fix spokePool test Signed-off-by: Ihor Farion <[email protected]> * address PR comments Signed-off-by: Ihor Farion <[email protected]> --------- Signed-off-by: Ihor Farion <[email protected]> * feat: add xERC20 standard support via Hyperlane (#914) * first draft of OFTTransportAdapter Signed-off-by: Ihor Farion <[email protected]> * update yarn.lock file Signed-off-by: Ihor Farion <[email protected]> * Revert "update yarn.lock file" This reverts commit 4c216ea. Signed-off-by: Ihor Farion <[email protected]> * add yarn.lock compatible with master Signed-off-by: Ihor Farion <[email protected]> * polish OFTTransportAdapter, add OFT support to Arbitrum_Adapter on L1, and Arbitrum_SpokePool on L2 Signed-off-by: Ihor Farion <[email protected]> * polish + fix missing approval Signed-off-by: Ihor Farion <[email protected]> * add context for dstEid Signed-off-by: Ihor Farion <[email protected]> * address most of the PR comments about contracts Signed-off-by: Ihor Farion <[email protected]> * update deploy scripts, add tests for OFT messaging, polish contracts Signed-off-by: Ihor Farion <[email protected]> * cleanup comments and extraneous log file Signed-off-by: Ihor Farion <[email protected]> * revert package.json prepublish change Signed-off-by: Ihor Farion <[email protected]> * generalize oft adapter to support multiple tokens. Introduce OFTAddressBook to support that. Update deploy / test scripts to reflect new functionality Signed-off-by: Ihor Farion <[email protected]> * add __gap to ArbitrumSpokePool, update stale comments on OFTTransportAdapter, update layouts of ArbitrumSpokePool and AlephZeroSpokePool Signed-off-by: Ihor Farion <[email protected]> * update some comments; adjust fee cap naming Signed-off-by: Ihor Farion <[email protected]> * address PR comments Signed-off-by: Ihor Farion <[email protected]> * address PR comments Signed-off-by: Ihor Farion <[email protected]> * fix deploy script, remove incorrect values from consts Signed-off-by: Ihor Farion <[email protected]> * improve comment Signed-off-by: Ihor Farion <[email protected]> * init commit that adds xerc20 hyperlane adapter and embeds it into arbitrum adapter and spokepool Signed-off-by: Ihor Farion <[email protected]> * complete adapter / spoke modifications to support xerc20 trasnfers through hyperlane Signed-off-by: Ihor Farion <[email protected]> * updated chain adapters with XERC20 support: mode, base, unichain, blast, linea, optimism; updated spokepools: same chains; added spoke + adapter tests: arbitrum, optimism, linea Signed-off-by: Ihor Farion <[email protected]> * update arbitrum spokepool gap Signed-off-by: Ihor Farion <[email protected]> * polish code to fit blast spokepool into a bytecode size limit Signed-off-by: Ihor Farion <[email protected]> * added testing xerc20 functionality for chain adapters: base, blast, mode, unichain Signed-off-by: Ihor Farion <[email protected]> * add spoke pool tests for xerc20 transfers for: base, mode, unichain Signed-off-by: Ihor Farion <[email protected]> * add blast spoke pool tests in a separate commit for easy revert Signed-off-by: Ihor Farion <[email protected]> * add oftFeeCap as a param to arbitrum adapter construction Signed-off-by: Ihor Farion <[email protected]> * move OFT functionality to SpokePool for easy further integration and removing boilerplate code Signed-off-by: Ihor Farion <[email protected]> * remove layerzero from foundry remappings Signed-off-by: Ihor Farion <[email protected]> * remove MockBlast_SpokePool and related test, as they're of limited use Signed-off-by: Ihor Farion <[email protected]> * address licensing comment; add permalink to LZ OFT code on github Signed-off-by: Ihor Farion <[email protected]> * make AddressBook consistent between OFT and XERC20 Signed-off-by: Ihor Farion <[email protected]> * fix a couple of comment typos Signed-off-by: Ihor Farion <[email protected]> * checkpoint: deploy scripts and test modifications for adapter / spokepool constructor changes are still needed Signed-off-by: Ihor Farion <[email protected]> * fix a couple of comment typos Signed-off-by: Ihor Farion <[email protected]> * adjust xerc20 code to fit the new adapter store pattern Signed-off-by: Ihor Farion <[email protected]> * fix adapter tests with new pattern Signed-off-by: Ihor Farion <[email protected]> * fix all spokepool tests Signed-off-by: Ihor Farion <[email protected]> * update storage layouts Signed-off-by: Ihor Farion <[email protected]> * update adapter deployment scripts Signed-off-by: Ihor Farion <[email protected]> * update all deploy scripts; update compiler params so that Blast_Spoke fits in the bytecode limit Signed-off-by: Ihor Farion <[email protected]> * fix foundry tests Signed-off-by: Ihor Farion <[email protected]> * add QOL improvements to package.json , fix CI Signed-off-by: Ihor Farion <[email protected]> * small pre-review polish Signed-off-by: Ihor Farion <[email protected]> * deploy AdapterStore on sepolia, final polish Signed-off-by: Ihor Farion <[email protected]> * polish comments Signed-off-by: Ihor Farion <[email protected]> * make AdapterStore upgradeable; move AdapterStore.sol to a different folder; deploy upgradeable version Signed-off-by: Ihor Farion <[email protected]> * Revert "make AdapterStore upgradeable; move AdapterStore.sol to a different folder; deploy upgradeable version" This reverts commit 7ef6170. Signed-off-by: Ihor Farion <[email protected]> * make AdapterStore future-proof to additional storage requirements Signed-off-by: Ihor Farion <[email protected]> * remove unused imports Signed-off-by: Ihor Farion <[email protected]> * add new AdapterStore deployments, add verification to AdapterStore deploy script Signed-off-by: Ihor Farion <[email protected]> * polish: remove oft / xerc20 chain id libs, change to constants. Rename _setHypXERC20Router and add human error protection Signed-off-by: Ihor Farion <[email protected]> * OFT-specific polish: renaming Signed-off-by: Ihor Farion <[email protected]> * remove named fee cap constants from chain-specific spokepools due to name collision; substitute for a const literal with comment. Fix tests Signed-off-by: Ihor Farion <[email protected]> * add oftDstEid and hypXERC20DstDomain as constructor params wherever possible. Refactor AdapterStore functionality for chain Adapters Signed-off-by: Ihor Farion <[email protected]> * fix all tests Signed-off-by: Ihor Farion <[email protected]> * fix all deployment scripts Signed-off-by: Ihor Farion <[email protected]> * modify evm-contract-sizes.sh to use --optimizer-runs flag insted of modifying foundry.toml on the fly Signed-off-by: Ihor Farion <[email protected]> * adjust var naming and comments in AdapterStore Signed-off-by: Ihor Farion <[email protected]> * clean up deploy scripts; bump constants repo dep Signed-off-by: Ihor Farion <[email protected]> * remove deploy from include Signed-off-by: Ihor Farion <[email protected]> * cleanup hardcoded vars from tests Signed-off-by: Ihor Farion <[email protected]> * address new PR comments Signed-off-by: Ihor Farion <[email protected]> --------- Signed-off-by: Ihor Farion <[email protected]> * feat: remove XERC20 code (#991) * remove Xerc20 code This reverts most of commit 62c4d96. * storage layouts * add OFT to universl adapter * remove extra AdapterStore * Update Universal_SpokePool.json * Add OFT unit tests to Universal spoke * Revert "feat(SpokePoolPeriphery): Support multiple exchanges (#777)" This reverts commit b9a298e. * adjust comments: remove xERC20 references Signed-off-by: Ihor Farion <[email protected]> * add amountSentLD check (#1027) Signed-off-by: Ihor Farion <[email protected]> * update doc comment (#1030) Signed-off-by: Ihor Farion <[email protected]> * add human error protection to AdapterStore.sol (#1033) Signed-off-by: Ihor Farion <[email protected]> * require that returned lzTokenFee is zero. Add tests for fee cap checking (#1029) Signed-off-by: Ihor Farion <[email protected]> * fix typos (#1035) Signed-off-by: Ihor Farion <[email protected]> * use explicit import syntax (#1036) Signed-off-by: Ihor Farion <[email protected]> * add security contact doc comments (#1037) Signed-off-by: Ihor Farion <[email protected]> * [M-04] Insufficient Test Coverage (#1038) * add unhappy-path OFT tests cases for Universal Spoke / Adapter Signed-off-by: Ihor Farion <[email protected]> * add arbitrum adapter / spoke tests Signed-off-by: Ihor Farion <[email protected]> * fork test checkpoint Signed-off-by: Ihor Farion <[email protected]> --------- Signed-off-by: Ihor Farion <[email protected]> * [M-02] Compromised Messengers Cannot Be Removed (#1034) * always allow a zero oft messenger to be set in SpokePool Signed-off-by: Ihor Farion <[email protected]> * add forge test for SpokePool.removeMessenger functonality Signed-off-by: Ihor Farion <[email protected]> * add Arbitrum spoke test and remove extraneous .only Signed-off-by: Ihor Farion <[email protected]> --------- Signed-off-by: Ihor Farion <[email protected]> * update __gap comment (#1039) Signed-off-by: Ihor Farion <[email protected]> * add missing docstrings Signed-off-by: Ihor Farion <[email protected]> * restrict function visibility (#1041) Signed-off-by: Ihor Farion <[email protected]> * [N-08] Missing Named Parameters in Mappings (#1040) * add named mapping params to AdapterStore Signed-off-by: Ihor Farion <[email protected]> * update to popular versions of prettier and prettier-plugin-solidity Signed-off-by: Ihor Farion <[email protected]> * bump SpokePool solidity version + add named params to oftMessengers mapping Signed-off-by: Ihor Farion <[email protected]> --------- Signed-off-by: Ihor Farion <[email protected]> * bump solhint to solhint@^3.6.2 to align with master Signed-off-by: Ihor Farion <[email protected]> * more updates to package.json from master Signed-off-by: Ihor Farion <[email protected]> * revert last 2 commits Signed-off-by: Ihor Farion <[email protected]> * reconcile packages with master Signed-off-by: Ihor Farion <[email protected]> --------- Signed-off-by: Ihor Farion <[email protected]> Signed-off-by: Bennett <[email protected]> Signed-off-by: bennett <[email protected]> Signed-off-by: nicholaspai <[email protected]> Co-authored-by: nicholaspai <[email protected]> Co-authored-by: nicholaspai <[email protected]> Co-authored-by: bmzig <[email protected]> Co-authored-by: Bennett <[email protected]> Co-authored-by: Dong-Ha Kim <[email protected]> Co-authored-by: Matt Rice <[email protected]>
1 parent d7c4413 commit b5d169f

File tree

70 files changed

+1912
-310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1912
-310
lines changed

.github/workflows/pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
name: evm-artifacts-${{ runner.os }}-node-${{ env.NODE_VERSION }}
125125
- name: Test evm-hardhat
126126
shell: bash
127-
run: yarn test-evm
127+
run: yarn test-evm-hardhat
128128
test-svm-verified:
129129
name: Test verified SVM build
130130
needs: upload-svm-artifacts
@@ -212,4 +212,4 @@ jobs:
212212
- name: Inspect storage layouts
213213
run: ./scripts/checkStorageLayout.sh
214214
- name: Test evm-foundry
215-
run: forge test --match-path test/evm/foundry/local/**/*.t.sol
215+
run: yarn test-evm-foundry

contracts/AdapterStore.sol

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.18;
3+
4+
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
5+
import { IOFT } from "./interfaces/IOFT.sol";
6+
7+
/**
8+
* @title MessengerTypes
9+
* @notice Library containing messenger type constants
10+
* @custom:security-contact [email protected]
11+
*/
12+
library MessengerTypes {
13+
/** @notice Identifier for OFT (Omni-chain Fungible Token by LayerZero) messenger type */
14+
bytes32 public constant OFT_MESSENGER = bytes32("OFT_MESSENGER");
15+
}
16+
17+
/**
18+
* @dev A helper contract for chain adapters on the hub chain that support OFT messaging. Handles
19+
* @dev token => messenger mapping storage. Adapters can't store this themselves as they're called
20+
* @dev via `delegateCall` and their storage is not part of available context.
21+
* @custom:security-contact [email protected]
22+
*/
23+
contract AdapterStore is Ownable {
24+
/** @notice Maps messenger type and destination domain to token-messenger pairs */
25+
mapping(bytes32 messengerType => mapping(uint256 dstDomainId => mapping(address srcChainToken => address messengerAddress)))
26+
public crossChainMessengers;
27+
28+
/**
29+
* @notice Emitted when a messenger is set for a specific token and destination
30+
* @param messengerType Type of messenger being set
31+
* @param dstDomainId Destination domain ID
32+
* @param srcChainToken Source chain token address
33+
* @param srcChainMessenger Source chain messenger address
34+
*/
35+
event MessengerSet(
36+
bytes32 indexed messengerType,
37+
uint256 indexed dstDomainId,
38+
address indexed srcChainToken,
39+
address srcChainMessenger
40+
);
41+
42+
/** @notice Thrown when array lengths don't match in batch operations */
43+
error ArrayLengthMismatch();
44+
45+
/** @notice Thrown when IOFT messenger's token doesn't match expected token */
46+
error IOFTTokenMismatch();
47+
48+
/** @notice Thrown when messenger type is not supported */
49+
error NonExistentMessengerType();
50+
51+
/**
52+
* @notice Sets a messenger for a specific token and destination domain
53+
* @param messengerType Type of messenger to set
54+
* @param dstDomainId Destination domain ID
55+
* @param srcChainToken Source chain token address
56+
* @param srcChainMessenger Source chain messenger address
57+
*/
58+
function setMessenger(
59+
bytes32 messengerType,
60+
uint256 dstDomainId,
61+
address srcChainToken,
62+
address srcChainMessenger
63+
) external onlyOwner {
64+
_setMessenger(messengerType, dstDomainId, srcChainToken, srcChainMessenger);
65+
}
66+
67+
/**
68+
* @notice Sets multiple messengers in a single transaction
69+
* @param messengerTypes Array of messenger types
70+
* @param dstDomainIds Array of destination domain IDs
71+
* @param srcChainTokens Array of source chain token addresses
72+
* @param srcChainMessengers Array of source chain messenger addresses
73+
*/
74+
function batchSetMessengers(
75+
bytes32[] calldata messengerTypes,
76+
uint256[] calldata dstDomainIds,
77+
address[] calldata srcChainTokens,
78+
address[] calldata srcChainMessengers
79+
) external onlyOwner {
80+
if (
81+
messengerTypes.length != dstDomainIds.length ||
82+
messengerTypes.length != srcChainTokens.length ||
83+
messengerTypes.length != srcChainMessengers.length
84+
) {
85+
revert ArrayLengthMismatch();
86+
}
87+
88+
for (uint256 i = 0; i < dstDomainIds.length; i++) {
89+
_setMessenger(messengerTypes[i], dstDomainIds[i], srcChainTokens[i], srcChainMessengers[i]);
90+
}
91+
}
92+
93+
/**
94+
* @notice Internal function to set a messenger with validation
95+
* @param _messengerType Type of messenger to set
96+
* @param _dstDomainId Destination domain ID
97+
* @param _srcChainToken Source chain token address
98+
* @param _srcChainMessenger Source chain messenger address
99+
*/
100+
function _setMessenger(
101+
bytes32 _messengerType,
102+
uint256 _dstDomainId,
103+
address _srcChainToken,
104+
address _srcChainMessenger
105+
) internal {
106+
// @dev Always allow zero-messenger to be set: this can be used to 'remove' a stored token <> messenger relationship
107+
if (_srcChainMessenger != address(0)) {
108+
if (_messengerType == MessengerTypes.OFT_MESSENGER) {
109+
// @dev Protect against human error: check that IOFT messenger's token matches the expected one
110+
if (IOFT(_srcChainMessenger).token() != _srcChainToken) {
111+
revert IOFTTokenMismatch();
112+
}
113+
} else {
114+
revert NonExistentMessengerType();
115+
}
116+
}
117+
crossChainMessengers[_messengerType][_dstDomainId][_srcChainToken] = _srcChainMessenger;
118+
emit MessengerSet(_messengerType, _dstDomainId, _srcChainToken, _srcChainMessenger);
119+
}
120+
}

contracts/AlephZero_SpokePool.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ contract AlephZero_SpokePool is Arbitrum_SpokePool {
1717
uint32 _depositQuoteTimeBuffer,
1818
uint32 _fillDeadlineBuffer,
1919
IERC20 _l2Usdc,
20-
ITokenMessenger _cctpTokenMessenger
20+
ITokenMessenger _cctpTokenMessenger,
21+
uint32 _oftDstEid,
22+
uint256 _oftFeeCap
2123
)
2224
Arbitrum_SpokePool(
2325
_wrappedNativeTokenAddress,
2426
_depositQuoteTimeBuffer,
2527
_fillDeadlineBuffer,
2628
_l2Usdc,
27-
_cctpTokenMessenger
29+
_cctpTokenMessenger,
30+
_oftDstEid,
31+
_oftFeeCap
2832
)
2933
{} // solhint-disable-line no-empty-blocks
3034
}

contracts/Arbitrum_SpokePool.sol

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ contract Arbitrum_SpokePool is SpokePool, CircleCCTPAdapter {
2727
uint32 _depositQuoteTimeBuffer,
2828
uint32 _fillDeadlineBuffer,
2929
IERC20 _l2Usdc,
30-
ITokenMessenger _cctpTokenMessenger
30+
ITokenMessenger _cctpTokenMessenger,
31+
uint32 _oftDstEid,
32+
uint256 _oftFeeCap
3133
)
32-
SpokePool(_wrappedNativeTokenAddress, _depositQuoteTimeBuffer, _fillDeadlineBuffer)
34+
SpokePool(_wrappedNativeTokenAddress, _depositQuoteTimeBuffer, _fillDeadlineBuffer, _oftDstEid, _oftFeeCap)
3335
CircleCCTPAdapter(_l2Usdc, _cctpTokenMessenger, CircleDomainIds.Ethereum)
3436
{} // solhint-disable-line no-empty-blocks
3537

@@ -83,9 +85,13 @@ contract Arbitrum_SpokePool is SpokePool, CircleCCTPAdapter {
8385
**************************************/
8486

8587
function _bridgeTokensToHubPool(uint256 amountToReturn, address l2TokenAddress) internal override {
88+
address oftMessenger = _getOftMessenger(l2TokenAddress);
89+
8690
// If the l2TokenAddress is UDSC, we need to use the CCTP bridge.
8791
if (_isCCTPEnabled() && l2TokenAddress == address(usdcToken)) {
8892
_transferUsdc(withdrawalRecipient, amountToReturn);
93+
} else if (oftMessenger != address(0)) {
94+
_transferViaOFT(IERC20(l2TokenAddress), IOFT(oftMessenger), withdrawalRecipient, amountToReturn);
8995
} else {
9096
// Check that the Ethereum counterpart of the L2 token is stored on this contract.
9197
address ethereumTokenToBridge = whitelistedTokens[l2TokenAddress];
@@ -112,4 +118,11 @@ contract Arbitrum_SpokePool is SpokePool, CircleCCTPAdapter {
112118

113119
// Apply AVM-specific transformation to cross domain admin address on L1.
114120
function _requireAdminSender() internal override onlyFromCrossDomainAdmin {}
121+
122+
// Reserve storage slots for future versions of this base contract to add state variables without
123+
// affecting the storage layout of child contracts. Decrement the size of __gap whenever state variables
124+
// are added, so that the total number of slots taken by this contract remains constant. Per-contract
125+
// storage layout information can be found in storage-layouts/
126+
// This is at bottom of contract to make sure it's always at the end of storage.
127+
uint256[1000] private __gap;
115128
}

contracts/Ethereum_SpokePool.sol

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ contract Ethereum_SpokePool is SpokePool, OwnableUpgradeable {
1616
address _wrappedNativeTokenAddress,
1717
uint32 _depositQuoteTimeBuffer,
1818
uint32 _fillDeadlineBuffer
19-
) SpokePool(_wrappedNativeTokenAddress, _depositQuoteTimeBuffer, _fillDeadlineBuffer) {} // solhint-disable-line no-empty-blocks
19+
)
20+
SpokePool(
21+
_wrappedNativeTokenAddress,
22+
_depositQuoteTimeBuffer,
23+
_fillDeadlineBuffer,
24+
// Ethereum_SpokePool does not use OFT messaging; setting destination eid and fee cap to 0
25+
0,
26+
0
27+
)
28+
{} // solhint-disable-line no-empty-blocks
2029

2130
/**
2231
* @notice Construct the Ethereum SpokePool.

contracts/Linea_SpokePool.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ contract Linea_SpokePool is SpokePool, CircleCCTPAdapter {
5454
IERC20 _l2Usdc,
5555
ITokenMessenger _cctpTokenMessenger
5656
)
57-
SpokePool(_wrappedNativeTokenAddress, _depositQuoteTimeBuffer, _fillDeadlineBuffer)
57+
SpokePool(
58+
_wrappedNativeTokenAddress,
59+
_depositQuoteTimeBuffer,
60+
_fillDeadlineBuffer,
61+
// Linea_SpokePool does not use OFT messaging; setting destination eid and fee cap to 0
62+
0,
63+
0
64+
)
5865
CircleCCTPAdapter(_l2Usdc, _cctpTokenMessenger, CircleDomainIds.Ethereum)
5966
{} // solhint-disable-line no-empty-blocks
6067

contracts/Ovm_SpokePool.sol

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ interface IL2ERC20Bridge {
3434
*/
3535
contract Ovm_SpokePool is SpokePool, CircleCCTPAdapter {
3636
using SafeERC20 for IERC20;
37+
3738
// "l1Gas" parameter used in call to bridge tokens from this contract back to L1 via IL2ERC20Bridge. Currently
3839
// unused by bridge but included for future compatibility.
3940
uint32 public l1Gas;
@@ -71,7 +72,14 @@ contract Ovm_SpokePool is SpokePool, CircleCCTPAdapter {
7172
IERC20 _l2Usdc,
7273
ITokenMessenger _cctpTokenMessenger
7374
)
74-
SpokePool(_wrappedNativeTokenAddress, _depositQuoteTimeBuffer, _fillDeadlineBuffer)
75+
SpokePool(
76+
_wrappedNativeTokenAddress,
77+
_depositQuoteTimeBuffer,
78+
_fillDeadlineBuffer,
79+
// Ovm_SpokePool does not use OFT messaging; setting destination eid and fee cap to 0
80+
0,
81+
0
82+
)
7583
CircleCCTPAdapter(_l2Usdc, _cctpTokenMessenger, CircleDomainIds.Ethereum)
7684
{} // solhint-disable-line no-empty-blocks
7785

@@ -210,6 +218,8 @@ contract Ovm_SpokePool is SpokePool, CircleCCTPAdapter {
210218

211219
// Reserve storage slots for future versions of this base contract to add state variables without
212220
// affecting the storage layout of child contracts. Decrement the size of __gap whenever state variables
213-
// are added. This is at bottom of contract to make sure its always at the end of storage.
221+
// are added, so that the total number of slots taken by this contract remains constant. Per-contract
222+
// storage layout information can be found in storage-layouts/
223+
// This is at bottom of contract to make sure it's always at the end of storage.
214224
uint256[999] private __gap;
215225
}

contracts/PolygonZkEVM_SpokePool.sol

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,16 @@ contract PolygonZkEVM_SpokePool is SpokePool, IBridgeMessageReceiver {
9393
address _wrappedNativeTokenAddress,
9494
uint32 _depositQuoteTimeBuffer,
9595
uint32 _fillDeadlineBuffer
96-
) SpokePool(_wrappedNativeTokenAddress, _depositQuoteTimeBuffer, _fillDeadlineBuffer) {} // solhint-disable-line no-empty-blocks
96+
)
97+
SpokePool(
98+
_wrappedNativeTokenAddress,
99+
_depositQuoteTimeBuffer,
100+
_fillDeadlineBuffer,
101+
// PolygonZkEVM_SpokePool does not use OFT messaging; setting destination eid and fee cap to 0
102+
0,
103+
0
104+
)
105+
{} // solhint-disable-line no-empty-blocks
97106

98107
/**
99108
* @notice Construct the Polygon zkEVM SpokePool.

contracts/Polygon_SpokePool.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ contract Polygon_SpokePool is IFxMessageProcessor, SpokePool, CircleCCTPAdapter
8787
IERC20 _l2Usdc,
8888
ITokenMessenger _cctpTokenMessenger
8989
)
90-
SpokePool(_wrappedNativeTokenAddress, _depositQuoteTimeBuffer, _fillDeadlineBuffer)
90+
SpokePool(
91+
_wrappedNativeTokenAddress,
92+
_depositQuoteTimeBuffer,
93+
_fillDeadlineBuffer,
94+
// Polygon_SpokePool does not use OFT messaging; setting destination eid and fee cap to 0
95+
0,
96+
0
97+
)
9198
CircleCCTPAdapter(_l2Usdc, _cctpTokenMessenger, CircleDomainIds.Ethereum)
9299
{} // solhint-disable-line no-empty-blocks
93100

contracts/Scroll_SpokePool.sol

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ contract Scroll_SpokePool is SpokePool {
4848
address _wrappedNativeTokenAddress,
4949
uint32 _depositQuoteTimeBuffer,
5050
uint32 _fillDeadlineBuffer
51-
) SpokePool(_wrappedNativeTokenAddress, _depositQuoteTimeBuffer, _fillDeadlineBuffer) {} // solhint-disable-line no-empty-blocks
51+
)
52+
SpokePool(
53+
_wrappedNativeTokenAddress,
54+
_depositQuoteTimeBuffer,
55+
_fillDeadlineBuffer,
56+
// Scroll_SpokePool does not use OFT messaging, setting destination id and fee cap to 0
57+
0,
58+
0
59+
)
60+
{} // solhint-disable-line no-empty-blocks
5261

5362
/**
5463
* @notice Construct the Scroll SpokePool.

0 commit comments

Comments
 (0)