From 031fe345b39c49ea82bbfd2e647a7612d1fff230 Mon Sep 17 00:00:00 2001 From: jordan <41rjordan@proton.me> Date: Sat, 16 Nov 2024 00:51:42 +0700 Subject: [PATCH] deployment scripts (yippiee!!!) --- contracts/.env.example | 10 +--- contracts/script/Deploy.s.sol | 90 ++++++++++++++++++++++++++++ contracts/script/DeployMainnet.s.sol | 73 ++++++++++++++++++++++ 3 files changed, 164 insertions(+), 9 deletions(-) create mode 100644 contracts/script/Deploy.s.sol create mode 100644 contracts/script/DeployMainnet.s.sol diff --git a/contracts/.env.example b/contracts/.env.example index f52c4dd..90459f1 100644 --- a/contracts/.env.example +++ b/contracts/.env.example @@ -1,10 +1,2 @@ # private key that will be used to deploy the contracts -PRIVATE_KEY=0x... -# the address that ADMIN_ROLE will be moved to -ADMIN_ADDRESS=0x... -# the address that UNLIMITED_CREATOR_ROLE will be moved to -UNLIMITED_CREATOR_ADDRESS=0x... -# the address that REGISTRAR_ROLE will be moved to -REGISTRAR_ADDRESS=0x... -# verification key for the SP1 Untron program -SP1_VKEY=0x... \ No newline at end of file +PRIVATE_KEY=0x... \ No newline at end of file diff --git a/contracts/script/Deploy.s.sol b/contracts/script/Deploy.s.sol new file mode 100644 index 0000000..52b9a46 --- /dev/null +++ b/contracts/script/Deploy.s.sol @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.20; + +import "forge-std/Script.sol"; +import "../src/UntronCore.sol"; +import "../src/UntronCoreProxy.sol"; +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; + +// Mock contracts for testing +contract MockUSDT is ERC20 { + constructor() ERC20("Mock USDT", "USDT") { + _mint(msg.sender, 1000000 * 10**decimals()); + } +} + +contract MockLiFi { + function call(bytes calldata) external returns (bool) { + return true; + } +} + +contract MockSP1Verifier { + function verifyProof(bytes32, bytes calldata, bytes calldata) external pure returns (bool) { + return true; + } +} + +contract DeployScript is Script { + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + // Deploy mock contracts + MockUSDT mockUSDT = new MockUSDT(); + MockLiFi mockLiFi = new MockLiFi(); + MockSP1Verifier mockVerifier = new MockSP1Verifier(); + + // Deploy implementation + UntronCore implementation = new UntronCore(); + + // Deploy proxy + bytes memory initData = abi.encodeWithSelector( + UntronCore.initialize.selector, + "" // empty genesis state + ); + + UntronCoreProxy proxy = new UntronCoreProxy( + address(implementation), + vm.addr(deployerPrivateKey), // admin + initData + ); + + // Configure the proxy + UntronCore untron = UntronCore(address(proxy)); + + // Set core variables + untron.setCoreVariables( + 1000000 * 1e6, // maxOrderSize: 1M USDT + 1000 * 1e6, // requiredCollateral: 1000 USDT + 3600 * 1000 // orderTtlMillis: 1 hour + ); + + // Set fees variables + untron.setFeesVariables( + 1000, // relayerFee: 0.1% + 10 * 1e6 // fulfillerFee: 10 USDT + ); + + // Set transfers variables + untron.setTransfersVariables( + address(mockUSDT), + address(mockLiFi) + ); + + // Set ZK variables + untron.setZKVariables( + vm.addr(deployerPrivateKey), // trusted relayer + address(mockVerifier), + bytes32(0) // empty vkey + ); + + vm.stopBroadcast(); + + console.log("Deployed UntronCore implementation at:", address(implementation)); + console.log("Deployed UntronCore proxy at:", address(proxy)); + console.log("Deployed Mock USDT at:", address(mockUSDT)); + console.log("Deployed Mock LiFi at:", address(mockLiFi)); + console.log("Deployed Mock Verifier at:", address(mockVerifier)); + } +} \ No newline at end of file diff --git a/contracts/script/DeployMainnet.s.sol b/contracts/script/DeployMainnet.s.sol new file mode 100644 index 0000000..d9f98c6 --- /dev/null +++ b/contracts/script/DeployMainnet.s.sol @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: BUSL-1.1 +pragma solidity ^0.8.20; + +import "forge-std/Script.sol"; +import "../src/UntronCore.sol"; +import "../src/UntronCoreProxy.sol"; +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; + +contract MockSP1Verifier { + function verifyProof(bytes32, bytes calldata, bytes calldata) external pure returns (bool) { + return true; + } +} + +contract DeployMainnetScript is Script { + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + // Deploy mock verifier + MockSP1Verifier mockVerifier = new MockSP1Verifier(); + + // Deploy implementation + UntronCore implementation = new UntronCore(); + + // Deploy proxy + bytes memory initData = abi.encodeWithSelector( + UntronCore.initialize.selector, + "" // empty genesis state + ); + + UntronCoreProxy proxy = new UntronCoreProxy( + address(implementation), + vm.addr(deployerPrivateKey), // admin + initData + ); + + // Configure the proxy + UntronCore untron = UntronCore(address(proxy)); + + // Set core variables + untron.setCoreVariables( + 10000 * 1e6, // maxOrderSize: 10K USDT + 0 * 1e6, // requiredCollateral: 0 USDT + 300 * 1000 // orderTtlMillis: 5 minutes + ); + + // Set fees variables + untron.setFeesVariables( + 0, // relayerFee: 0% + 0.05 * 1e6 // fulfillerFee: 0.05 USDT + ); + + // Set transfers variables + untron.setTransfersVariables( + 0x493257fD37EDB34451f62EDf8D2a0C418852bA4C, // USDT + 0x341e94069f53234fE6DabeF707aD424830525715 // LiFi + ); + + // Set ZK variables + untron.setZKVariables( + vm.addr(deployerPrivateKey), // trusted relayer + address(mockVerifier), + bytes32(0) // empty vkey + ); + + vm.stopBroadcast(); + + console.log("Deployed UntronCore implementation at:", address(implementation)); + console.log("Deployed UntronCore proxy at:", address(proxy)); + console.log("Deployed Mock Verifier at:", address(mockVerifier)); + } +} \ No newline at end of file