Skip to content

Commit a8dbbdb

Browse files
add support for HyperEVM in the FactoryBurnMintERC20 (#1132)
* add support for HyperEVM in the FactoryBurnMintERC20 * comments and an additional test * comment fixes * typo fix * comment fix * typo fix --------- Co-authored-by: Suryansh <39276431+0xsuryansh@users.noreply.github.com>
1 parent c018503 commit a8dbbdb

File tree

6 files changed

+286
-16
lines changed

6 files changed

+286
-16
lines changed

chains/evm/.gas-snapshot

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,17 @@ FactoryBurnMintERC20_approve:test_Approve() (gas: 56417)
8888
FactoryBurnMintERC20_burn:test_BasicBurn() (gas: 174145)
8989
FactoryBurnMintERC20_burnFrom:test_BurnFrom() (gas: 59013)
9090
FactoryBurnMintERC20_burnFromAlias:test_BurnFrom() (gas: 59128)
91-
FactoryBurnMintERC20_constructor:test_Constructor() (gas: 1267258)
92-
FactoryBurnMintERC20_decreaseApproval:test_DecreaseApproval() (gas: 32589)
91+
FactoryBurnMintERC20_constructor:test_Constructor() (gas: 1310174)
92+
FactoryBurnMintERC20_decreaseApproval:test_DecreaseApproval() (gas: 32624)
9393
FactoryBurnMintERC20_getCCIPAdmin:test_getCCIPAdmin() (gas: 13111)
9494
FactoryBurnMintERC20_getCCIPAdmin:test_setCCIPAdmin() (gas: 24707)
9595
FactoryBurnMintERC20_grantMintAndBurnRoles:test_GrantMintAndBurnRoles() (gas: 123542)
9696
FactoryBurnMintERC20_grantRole:test_GrantBurnAccess() (gas: 54587)
97-
FactoryBurnMintERC20_grantRole:test_GrantMany() (gas: 956926)
98-
FactoryBurnMintERC20_grantRole:test_GrantMintAccess() (gas: 96829)
99-
FactoryBurnMintERC20_increaseApproval:test_IncreaseApproval() (gas: 46250)
97+
FactoryBurnMintERC20_grantRole:test_GrantMany() (gas: 956970)
98+
FactoryBurnMintERC20_grantRole:test_GrantMintAccess() (gas: 96864)
99+
FactoryBurnMintERC20_increaseApproval:test_IncreaseApproval() (gas: 46316)
100100
FactoryBurnMintERC20_mint:test_BasicMint() (gas: 151569)
101+
FactoryBurnMintERC20_setHyperEVMLinker:test_setHyperEVMLinker_Success() (gas: 40631)
101102
FactoryBurnMintERC20_supportsInterface:test_SupportsInterface() (gas: 11447)
102103
FactoryBurnMintERC20_transfer:test_Transfer() (gas: 43439)
103104
FastTransferTokenPool_ccipReceive_Test:test_ccipReceive_FastFill_Settlement() (gas: 125441)
@@ -469,13 +470,13 @@ TokenAdminRegistry_removeRegistryModule:test_removeRegistryModule() (gas: 55248)
469470
TokenAdminRegistry_setPool:test_setPool() (gas: 36816)
470471
TokenAdminRegistry_setPool:test_setPool_ZeroAddressRemovesPool() (gas: 31891)
471472
TokenAdminRegistry_transferAdminRole:test_transferAdminRole() (gas: 50690)
472-
TokenPoolFactory_createTokenPool:test_createTokenPoolLockRelease_ExistingToken_predict() (gas: 12075903)
473-
TokenPoolFactory_createTokenPool:test_createTokenPool_BurnFromMintTokenPool() (gas: 6316345)
474-
TokenPoolFactory_createTokenPool:test_createTokenPool_ExistingRemoteToken_AndPredictPool() (gas: 12926671)
475-
TokenPoolFactory_createTokenPool:test_createTokenPool_RemoteTokenHasDifferentDecimals() (gas: 12934321)
476-
TokenPoolFactory_createTokenPool:test_createTokenPool_WithNoExistingRemoteContracts_predict() (gas: 13308515)
477-
TokenPoolFactory_createTokenPool:test_createTokenPool_WithNoExistingTokenOnRemoteChain() (gas: 6101173)
478-
TokenPoolFactory_createTokenPool:test_createTokenPool_WithRemoteTokenAndRemotePool() (gas: 6313167)
473+
TokenPoolFactory_createTokenPool:test_createTokenPoolLockRelease_ExistingToken_predict() (gas: 12177441)
474+
TokenPoolFactory_createTokenPool:test_createTokenPool_BurnFromMintTokenPool() (gas: 6374730)
475+
TokenPoolFactory_createTokenPool:test_createTokenPool_ExistingRemoteToken_AndPredictPool() (gas: 13029733)
476+
TokenPoolFactory_createTokenPool:test_createTokenPool_RemoteTokenHasDifferentDecimals() (gas: 13037383)
477+
TokenPoolFactory_createTokenPool:test_createTokenPool_WithNoExistingRemoteContracts_predict() (gas: 13414301)
478+
TokenPoolFactory_createTokenPool:test_createTokenPool_WithNoExistingTokenOnRemoteChain() (gas: 6160778)
479+
TokenPoolFactory_createTokenPool:test_createTokenPool_WithRemoteTokenAndRemotePool() (gas: 6371549)
479480
TokenPoolWithAllowList_applyAllowListUpdates:test_SetAllowList() (gas: 180617)
480481
TokenPoolWithAllowList_applyAllowListUpdates:test_SetAllowListSkipsZero() (gas: 24415)
481482
TokenPoolWithAllowList_getAllowList:test_GetAllowList() (gas: 24486)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.24;
3+
4+
import {FactoryBurnMintERC20} from "../../../tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol";
5+
6+
import {HyperEVMLinker} from "../../../tokenAdminRegistry/TokenPoolFactory/HyperEVMLinker.sol";
7+
import {BurnMintERC20Setup} from "./BurnMintERC20Setup.t.sol";
8+
9+
contract FactoryBurnMintERC20_setHyperEVMLinker is BurnMintERC20Setup {
10+
bytes32 public constant HYPER_EVM_LINKER_SLOT = 0x8c306a6a12fff1951878e8621be6674add1102cd359dd968efbbe797629ef84f;
11+
12+
FactoryBurnMintERC20 public s_factoryBurnMintERC20;
13+
14+
function setUp() public override {
15+
super.setUp();
16+
17+
s_factoryBurnMintERC20 = new FactoryBurnMintERC20("MOCK TOKEN", "MOCK", 18, 1e27, 0, OWNER);
18+
}
19+
20+
function test_setHyperEVMLinker_Success() public {
21+
address testHyperEVMLinker = makeAddr("testHyperEVMLinker");
22+
23+
vm.expectEmit();
24+
emit HyperEVMLinker.HyperEVMLinkerSet(testHyperEVMLinker);
25+
s_factoryBurnMintERC20.setHyperEVMLinker(testHyperEVMLinker);
26+
27+
assertEq(s_factoryBurnMintERC20.getHyperEVMLinker(), testHyperEVMLinker);
28+
29+
// Manually inspect the storage at the HYPER_EVM_LINKER_SLOT to ensure the address is stored correctly
30+
bytes32 storedValue = vm.load(address(s_factoryBurnMintERC20), HYPER_EVM_LINKER_SLOT);
31+
assertEq(address(uint160(uint256(storedValue))), testHyperEVMLinker);
32+
}
33+
34+
// Reverts
35+
36+
function test_setHyperEVMLinker_RevertWhen_ZeroAddress() public {
37+
vm.expectRevert(abi.encodeWithSelector(HyperEVMLinker.LinkerAddressCannotBeZero.selector));
38+
s_factoryBurnMintERC20.setHyperEVMLinker(address(0));
39+
}
40+
}

chains/evm/contracts/tokenAdminRegistry/TokenPoolFactory/FactoryBurnMintERC20.sol

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {IGetCCIPAdmin} from "../../interfaces/IGetCCIPAdmin.sol";
55
import {IOwnable} from "@chainlink/contracts/src/v0.8/shared/interfaces/IOwnable.sol";
66
import {IBurnMintERC20} from "@chainlink/contracts/src/v0.8/shared/token/ERC20/IBurnMintERC20.sol";
77

8+
import {HyperEVMLinker} from "./HyperEVMLinker.sol";
89
import {Ownable2StepMsgSender} from "@chainlink/contracts/src/v0.8/shared/access/Ownable2StepMsgSender.sol";
910

1011
import {ERC20} from "@chainlink/contracts/src/v0.8/vendor/openzeppelin-solidity/v4.8.3/contracts/token/ERC20/ERC20.sol";
@@ -20,7 +21,14 @@ import {EnumerableSet} from
2021
/// @notice A basic ERC20 compatible token contract with burn and minting roles.
2122
/// @dev The constructor has been modified to support the deployment pattern used by a factory contract.
2223
/// @dev The total supply can be limited during deployment.
23-
contract FactoryBurnMintERC20 is IBurnMintERC20, IGetCCIPAdmin, IERC165, ERC20Burnable, Ownable2StepMsgSender {
24+
contract FactoryBurnMintERC20 is
25+
IBurnMintERC20,
26+
IGetCCIPAdmin,
27+
IERC165,
28+
ERC20Burnable,
29+
Ownable2StepMsgSender,
30+
HyperEVMLinker
31+
{
2432
using EnumerableSet for EnumerableSet.AddressSet;
2533

2634
error SenderNotMinter(address sender);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
pragma solidity ^0.8.25;
2+
3+
import {Ownable2StepMsgSender} from "@chainlink/contracts/src/v0.8/shared/access/Ownable2StepMsgSender.sol";
4+
5+
/// @title HyperEVMLinker
6+
/// @notice This contract is used to facilitate linking of an ERC20 from HyperEVM to HyperCore by storing the linker
7+
/// address in the required slot.
8+
/// @dev This contract is built in accordance with the Hyperliquid standard at the following URL:
9+
/// https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/hyperevm/hypercore-less-than-greater-than-hyperevm-transfers#linking-core-and-evm-spot-assets
10+
abstract contract HyperEVMLinker is Ownable2StepMsgSender {
11+
// In order to bridge to HyperCore, factory-deployed contracts must store the address of a finalizer linker at
12+
// storage slot keccak256("HyperCore deployer")
13+
bytes32 internal constant HYPER_EVM_LINKER_SLOT = 0x8c306a6a12fff1951878e8621be6674add1102cd359dd968efbbe797629ef84f;
14+
15+
error LinkerAddressCannotBeZero();
16+
17+
event HyperEVMLinkerSet(address indexed hyperEVMLinker);
18+
19+
/// @notice Sets the hyperEVMLinker address.
20+
/// @param newLinker The address of the hyperEVMLinker.
21+
function setHyperEVMLinker(
22+
address newLinker
23+
) external onlyOwner {
24+
if (newLinker == address(0)) {
25+
revert LinkerAddressCannotBeZero();
26+
}
27+
28+
assembly {
29+
sstore(HYPER_EVM_LINKER_SLOT, newLinker)
30+
}
31+
32+
emit HyperEVMLinkerSet(newLinker);
33+
}
34+
35+
/// @notice Gets the hyperEVMLinker address.
36+
/// @return hyperEVMLinker The address of the hyperEVMLinker.
37+
function getHyperEVMLinker() public view returns (address) {
38+
address hyperEVMLinker;
39+
assembly {
40+
hyperEVMLinker := sload(HYPER_EVM_LINKER_SLOT)
41+
}
42+
return hyperEVMLinker;
43+
}
44+
}

chains/evm/gobindings/generated/latest/factory_burn_mint_erc20/factory_burn_mint_erc20.go

Lines changed: 179 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chains/evm/gobindings/generation/generated-wrapper-dependency-versions-do-not-edit.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cctp_message_transmitter_proxy: ../solc/ccip/CCTPMessageTransmitterProxy/CCTPMes
1111
don_id_claimer: ../solc/ccip/DonIDClaimer/DonIDClaimer.sol/DonIDClaimer.abi.json ../solc/ccip/DonIDClaimer/DonIDClaimer.sol/DonIDClaimer.bin 2ef6cba2f8e258c9d6f2dd55f8d2fc59ae5f686af609ed7d298e8ae9c3923448
1212
erc20_lock_box: ../solc/ccip/ERC20LockBox/ERC20LockBox.sol/ERC20LockBox.abi.json ../solc/ccip/ERC20LockBox/ERC20LockBox.sol/ERC20LockBox.bin 1fbb6f36d1c346337a862950ef9620bdb6296d026febb3a5a6541c88c27e3c1f
1313
ether_sender_receiver: ../solc/ccip/EtherSenderReceiver/EtherSenderReceiver.sol/EtherSenderReceiver.abi.json ../solc/ccip/EtherSenderReceiver/EtherSenderReceiver.sol/EtherSenderReceiver.bin c862bb4e4aec2f889fae514872f1f287cc2bcdc2870e9134ffa3bdfd806ffb67
14-
factory_burn_mint_erc20: ../solc/ccip/FactoryBurnMintERC20/FactoryBurnMintERC20.sol/FactoryBurnMintERC20.abi.json ../solc/ccip/FactoryBurnMintERC20/FactoryBurnMintERC20.sol/FactoryBurnMintERC20.bin 5c4d7396a6fb8fd5087d28e15c64785426609670beb681547e7f924fb32c5f14
14+
factory_burn_mint_erc20: ../solc/ccip/FactoryBurnMintERC20/FactoryBurnMintERC20.sol/FactoryBurnMintERC20.abi.json ../solc/ccip/FactoryBurnMintERC20/FactoryBurnMintERC20.sol/FactoryBurnMintERC20.bin 9116aae17ec2850111336f5fadb1eae9a76760bebe47f6fd0588fe0ce58020be
1515
fast_transfer_token_pool: ../solc/ccip/BurnMintFastTransferTokenPool/BurnMintFastTransferTokenPool.sol/BurnMintFastTransferTokenPool.abi.json ../solc/ccip/BurnMintFastTransferTokenPool/BurnMintFastTransferTokenPool.sol/BurnMintFastTransferTokenPool.bin c375296327f6f310785b499206e983c8848967465dc336eed5d1dcdffb02f7e8
1616
fee_quoter: ../solc/ccip/FeeQuoter/FeeQuoter.sol/FeeQuoter.abi.json ../solc/ccip/FeeQuoter/FeeQuoter.sol/FeeQuoter.bin 9c5997da2f7d38a98b2acba22146fa73f964139b29fae4996be708f34a4e9878
1717
hybrid_lock_release_usdc_token_pool: ../solc/ccip/HybridLockReleaseUSDCTokenPool/HybridLockReleaseUSDCTokenPool.sol/HybridLockReleaseUSDCTokenPool.abi.json ../solc/ccip/HybridLockReleaseUSDCTokenPool/HybridLockReleaseUSDCTokenPool.sol/HybridLockReleaseUSDCTokenPool.bin 914ea0b94e07a336e993f16422f5039f76db7c1949832f3fb29c4b69aabbd1ba

0 commit comments

Comments
 (0)