-
Notifications
You must be signed in to change notification settings - Fork 64
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: ERC20Custody and ZetaConnector uups upgradable #385
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,8 @@ | |||||||||||||||
pragma solidity 0.8.26; | ||||||||||||||||
|
||||||||||||||||
import "forge-std/Script.sol"; | ||||||||||||||||
import "src/evm/ZetaConnectorNonNative.sol"; | ||||||||||||||||
import "contracts/evm/ZetaConnectorNonNative.sol"; | ||||||||||||||||
import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol"; | ||||||||||||||||
|
||||||||||||||||
contract DeployZetaConnectorNonNative is Script { | ||||||||||||||||
function run() external { | ||||||||||||||||
|
@@ -11,19 +12,47 @@ contract DeployZetaConnectorNonNative is Script { | |||||||||||||||
address gateway = vm.envAddress("GATEWAY_PROXY_EVM"); | ||||||||||||||||
address zeta = vm.envAddress("ZETA_ERC20_EVM"); | ||||||||||||||||
|
||||||||||||||||
bytes32 salt = keccak256("ZetaConnectorNonNative"); | ||||||||||||||||
address expectedImplAddress; | ||||||||||||||||
address expectedProxyAddress; | ||||||||||||||||
|
||||||||||||||||
bytes32 implSalt = keccak256("ZetaConnectorNonNative"); | ||||||||||||||||
bytes32 proxySalt = keccak256("ZetaConnectorNonNativeProxy"); | ||||||||||||||||
Comment on lines
+18
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Define salt strings as constants for clarity Consider defining the salt strings used in Apply this diff to define the salt strings as constants: + string constant IMPL_SALT_STRING = "ZetaConnectorNonNative";
+ string constant PROXY_SALT_STRING = "ZetaConnectorNonNativeProxy";
- bytes32 implSalt = keccak256("ZetaConnectorNonNative");
- bytes32 proxySalt = keccak256("ZetaConnectorNonNativeProxy");
+ bytes32 implSalt = keccak256(abi.encodePacked(IMPL_SALT_STRING));
+ bytes32 proxySalt = keccak256(abi.encodePacked(PROXY_SALT_STRING)); 📝 Committable suggestion
Suggested change
|
||||||||||||||||
|
||||||||||||||||
vm.startBroadcast(); | ||||||||||||||||
|
||||||||||||||||
ZetaConnectorNonNative connector = new ZetaConnectorNonNative{salt: salt}(gateway, zeta, tss, admin); | ||||||||||||||||
require(address(connector) != address(0), "deployment failed"); | ||||||||||||||||
expectedImplAddress = vm.computeCreate2Address( | ||||||||||||||||
implSalt, | ||||||||||||||||
hashInitCode(type(ZetaConnectorNonNative).creationCode) | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
ZetaConnectorNonNative connectorImpl = new ZetaConnectorNonNative{salt: implSalt}(); | ||||||||||||||||
require(address(connectorImpl) != address(0), "connectorImpl deployment failed"); | ||||||||||||||||
|
||||||||||||||||
require(expectedImplAddress == address(connectorImpl), "impl address doesn't match expected address"); | ||||||||||||||||
|
||||||||||||||||
address expectedAddr = vm.computeCreate2Address( | ||||||||||||||||
salt, | ||||||||||||||||
hashInitCode(type(ZetaConnectorNonNative).creationCode, abi.encode(gateway, zeta, tss, admin)) | ||||||||||||||||
expectedProxyAddress = vm.computeCreate2Address( | ||||||||||||||||
proxySalt, | ||||||||||||||||
hashInitCode( | ||||||||||||||||
type(ERC1967Proxy).creationCode, | ||||||||||||||||
abi.encode( | ||||||||||||||||
address(connectorImpl), | ||||||||||||||||
abi.encodeWithSelector(ZetaConnectorNonNative.initialize.selector, gateway, zeta, tss, admin) | ||||||||||||||||
) | ||||||||||||||||
) | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
require(expectedAddr == address(connector), "zeta connector non native address doesn't match expected address"); | ||||||||||||||||
ERC1967Proxy connectorProxy = new ERC1967Proxy{salt: proxySalt}( | ||||||||||||||||
address(connectorImpl), | ||||||||||||||||
abi.encodeWithSelector(ZetaConnectorNonNative.initialize.selector, gateway, zeta, tss, admin) | ||||||||||||||||
); | ||||||||||||||||
require(address(connectorProxy) != address(0), "connectorProxy deployment failed"); | ||||||||||||||||
|
||||||||||||||||
require(expectedProxyAddress == address(connectorProxy), "proxy address doesn't match expected address"); | ||||||||||||||||
|
||||||||||||||||
ZetaConnectorNonNative connector = ZetaConnectorNonNative(address(connectorProxy)); | ||||||||||||||||
require(connector.tssAddress() == tss, "tss not set"); | ||||||||||||||||
require(address(connector.gateway()) == gateway, "gateway not set"); | ||||||||||||||||
require(address(connector.zetaToken()) == zeta, "zeta not set"); | ||||||||||||||||
|
||||||||||||||||
vm.stopBroadcast(); | ||||||||||||||||
} | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Refactor repetitive deployment logic into helper functions
The code for computing expected addresses and deploying both the implementation and proxy contracts is repetitive. To enhance maintainability and reduce duplication, consider abstracting this logic into reusable helper functions.
For example, you could create helper functions like
computeExpectedAddress
anddeployContract
:Refactored implementation deployment:
Refactored proxy deployment:
Also applies to: 32-49