-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Deploy keyless zkevm deployer script
Signed-off-by: JDawg287 <sjcool420@hotmail.co.uk>
- Loading branch information
Showing
2 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Script.sol"; | ||
|
||
contract DeployPolygonZkEVMDeployer is Script { | ||
using stdJson for string; | ||
|
||
uint256 constant GAS_PRICE = 100 gwei; | ||
uint256 constant GAS_LIMIT = 1000000; | ||
|
||
address polygonZkEVMDeployerAddr = | ||
0x68276c6b151e998eD7997035601c0b56a9629743; | ||
address keylessSignerAddr = 0xC5A8c8242a366B72418ef3924eE26804B3F55cc1; | ||
|
||
function run() public { | ||
bytes memory fundingPrivateKey = vm.envBytes("PRIVATE_KEY"); | ||
bytes | ||
memory keylessDeploymentTx = hex"f90c718085174876e800830f42408080b90c55608060405234801561000f575f80fd5b50604051610c35380380610c3583398101604081905261002e91610095565b61003733610046565b61004081610046565b506100c2565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b5f602082840312156100a5575f80fd5b81516001600160a01b03811681146100bb575f80fd5b9392505050565b610b66806100cf5f395ff3fe60806040526004361061006e575f3560e01c8063715018a61161004c578063715018a6146100e25780638da5cb5b146100f6578063e11ae6cb1461011f578063f2fde38b14610132575f80fd5b80632b79805a146100725780634a94d487146100875780636d07dbf81461009a575b5f80fd5b610085610080366004610908565b610151565b005b6100856100953660046109a2565b6101c2565b3480156100a5575f80fd5b506100b96100b43660046109f5565b610203565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b3480156100ed575f80fd5b50610085610215565b348015610101575f80fd5b505f5473ffffffffffffffffffffffffffffffffffffffff166100b9565b61008561012d366004610a15565b610228565b34801561013d575f80fd5b5061008561014c366004610a61565b61028e565b61015961034a565b5f6101658585856103ca565b90506101718183610527565b5060405173ffffffffffffffffffffffffffffffffffffffff821681527fba82f25fed02cd2a23d9f5d11c2ef588d22af5437cbf23bfe61d87257c480e4c9060200160405180910390a15050505050565b6101ca61034a565b6101d583838361056a565b506040517f25adb19089b6a549831a273acdf7908cff8b7ee5f551f8d1d37996cf01c5df5b905f90a1505050565b5f61020e8383610598565b9392505050565b61021d61034a565b6102265f6105a4565b565b61023061034a565b5f61023c8484846103ca565b60405173ffffffffffffffffffffffffffffffffffffffff821681529091507fba82f25fed02cd2a23d9f5d11c2ef588d22af5437cbf23bfe61d87257c480e4c9060200160405180910390a150505050565b61029661034a565b73ffffffffffffffffffffffffffffffffffffffff811661033e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f646472657373000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b610347816105a4565b50565b5f5473ffffffffffffffffffffffffffffffffffffffff163314610226576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610335565b5f83471015610435576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f437265617465323a20696e73756666696369656e742062616c616e63650000006044820152606401610335565b81515f0361049f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f437265617465323a2062797465636f6465206c656e677468206973207a65726f6044820152606401610335565b8282516020840186f5905073ffffffffffffffffffffffffffffffffffffffff811661020e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f437265617465323a204661696c6564206f6e206465706c6f79000000000000006044820152606401610335565b606061020e83835f6040518060400160405280601e81526020017f416464726573733a206c6f772d6c6576656c2063616c6c206661696c65640000815250610618565b6060610590848484604051806060016040528060298152602001610b0860299139610618565b949350505050565b5f61020e83833061072d565b5f805473ffffffffffffffffffffffffffffffffffffffff8381167fffffffffffffffffffffffff0000000000000000000000000000000000000000831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6060824710156106aa576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610335565b5f808673ffffffffffffffffffffffffffffffffffffffff1685876040516106d29190610a9c565b5f6040518083038185875af1925050503d805f811461070c576040519150601f19603f3d011682016040523d82523d5f602084013e610711565b606091505b509150915061072287838387610756565b979650505050505050565b5f604051836040820152846020820152828152600b8101905060ff815360559020949350505050565b606083156107eb5782515f036107e45773ffffffffffffffffffffffffffffffffffffffff85163b6107e4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610335565b5081610590565b61059083838151156108005781518083602001fd5b806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103359190610ab7565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f82601f830112610870575f80fd5b813567ffffffffffffffff8082111561088b5761088b610834565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019082821181831017156108d1576108d1610834565b816040528381528660208588010111156108e9575f80fd5b836020870160208301375f602085830101528094505050505092915050565b5f805f806080858703121561091b575f80fd5b8435935060208501359250604085013567ffffffffffffffff80821115610940575f80fd5b61094c88838901610861565b93506060870135915080821115610961575f80fd5b5061096e87828801610861565b91505092959194509250565b803573ffffffffffffffffffffffffffffffffffffffff8116811461099d575f80fd5b919050565b5f805f606084860312156109b4575f80fd5b6109bd8461097a565b9250602084013567ffffffffffffffff8111156109d8575f80fd5b6109e486828701610861565b925050604084013590509250925092565b5f8060408385031215610a06575f80fd5b50508035926020909101359150565b5f805f60608486031215610a27575f80fd5b8335925060208401359150604084013567ffffffffffffffff811115610a4b575f80fd5b610a5786828701610861565b9150509250925092565b5f60208284031215610a71575f80fd5b61020e8261097a565b5f5b83811015610a94578181015183820152602001610a7c565b50505f910152565b5f8251610aad818460208701610a7a565b9190910192915050565b602081525f8251806020840152610ad5816040850160208701610a7a565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016919091016040019291505056fe416464726573733a206c6f772d6c6576656c2063616c6c20776974682076616c7565206661696c6564a2646970667358221220330b94dc698c4d290bf55c23f13b473cde6a6bae0030cb902de18af54e35839f64736f6c634300081400330000000000000000000000009ab254be10f6df45e5c58ba2ce6cb3c9a1aff9541b8505ca1ab1e0845ca1ab1e"; | ||
|
||
// verify if the deployer has already been deployed | ||
require( | ||
polygonZkEVMDeployerAddr.codehash == 0, | ||
"PolygonZkEVMDeployer already deployed" | ||
); | ||
|
||
// fund the keyless signer account | ||
string memory fundTxRes = _sendTransaction( | ||
fundingPrivateKey, | ||
keylessSignerAddr, | ||
GAS_LIMIT * GAS_PRICE | ||
); | ||
console.log("Funding transaction: %s\n", fundTxRes); | ||
|
||
// TODO: switch to this after the issue upstream is fixed | ||
// vm.startBroadcast(vm.envUint("PRIVATE_KEY")); | ||
// (bool success, ) = keylessSignerAddr.call{value: 0}(""); | ||
// require(success, "Failed to fund keyless signer account"); | ||
// vm.stopBroadcast(); | ||
|
||
// deploy the PolygonZkEVMDeployer contract | ||
string memory deployTxRes = _publishRawTransaction(keylessDeploymentTx); | ||
console.log( | ||
"PolygonZkEVMDeployer deployment transaction: %s\n", | ||
deployTxRes | ||
); | ||
|
||
// TODO: switch to this after the issue upstream is fixed | ||
// vm.sendRawTransaction(keylessDeploymentTx); | ||
|
||
console.log( | ||
"PolygonZkEVMDeployer deployed successfully at: %s!\n", | ||
polygonZkEVMDeployerAddr | ||
); | ||
} | ||
|
||
// TODO: remove this | ||
function _sendTransaction( | ||
bytes memory from, | ||
address to, | ||
uint256 value | ||
) internal returns (string memory) { | ||
string[] memory exe = new string[](8); | ||
exe[0] = "cast"; | ||
exe[1] = "send"; | ||
exe[2] = vm.toString(to); | ||
exe[3] = "--value"; | ||
exe[4] = vm.toString(value); | ||
exe[5] = "--private-key"; | ||
exe[6] = vm.toString(from); | ||
exe[7] = "--json"; | ||
|
||
string memory result = string(vm.ffi(exe)); | ||
console.log("Transaction sent successfully!"); | ||
// console.log(string(result)); | ||
return string(result); | ||
} | ||
|
||
// TODO: remove this | ||
function _publishRawTransaction( | ||
bytes memory rawTx | ||
) internal returns (string memory) { | ||
string[] memory exe = new string[](3); | ||
exe[0] = "cast"; | ||
exe[1] = "publish"; | ||
exe[2] = vm.toString(rawTx); | ||
|
||
string memory result = string(vm.ffi(exe)); | ||
console.log("Transaction published successfully!"); | ||
// console.log(string(result)); | ||
return string(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters