|
| 1 | +// SPDX-License-Identifier: UNLICENSED |
| 2 | +pragma solidity ^0.8.17; |
| 3 | + |
| 4 | +import "forge-std/Script.sol"; |
| 5 | +import "stringutils/strings.sol"; |
| 6 | + |
| 7 | +import {IntentGatewayV2, Params} from "../src/apps/IntentGatewayV2.sol"; |
| 8 | +import {SolverAccount} from "../src/utils/SolverAccount.sol"; |
| 9 | +import {CallDispatcher} from "../src/utils/CallDispatcher.sol"; |
| 10 | +import {VWAPOracle} from "../src/utils/VWAPOracle.sol"; |
| 11 | +import {BaseScript} from "./BaseScript.sol"; |
| 12 | + |
| 13 | +contract DeployScript is BaseScript { |
| 14 | + using strings for *; |
| 15 | + |
| 16 | + function deploy() internal override { |
| 17 | + // Load optional configuration from environment |
| 18 | + bool solverSelection = vm.envOr("SOLVER_SELECTION", false); |
| 19 | + uint256 surplusShareBps = vm.envOr("SURPLUS_SHARE_BPS", uint256(5000)); // 50% default |
| 20 | + uint256 protocolFeeBps = vm.envOr("PROTOCOL_FEE_BPS", uint256(0)); // 0% default |
| 21 | + |
| 22 | + // Check if we should deploy CallDispatcher and VWAPOracle |
| 23 | + bool deployCallDispatcher = vm.envOr("DEPLOY_CALL_DISPATCHER", true); |
| 24 | + bool deployVWAPOracle = vm.envOr("DEPLOY_VWAP_ORACLE", true); |
| 25 | + |
| 26 | + // Deploy CallDispatcher if needed |
| 27 | + address callDispatcherAddr; |
| 28 | + if (deployCallDispatcher) { |
| 29 | + CallDispatcher callDispatcher = new CallDispatcher{salt: salt}(); |
| 30 | + callDispatcherAddr = address(callDispatcher); |
| 31 | + console.log("CallDispatcher deployed at:", callDispatcherAddr); |
| 32 | + } else { |
| 33 | + callDispatcherAddr = config.get("CALL_DISPATCHER").toAddress(); |
| 34 | + console.log("Using existing CallDispatcher at:", callDispatcherAddr); |
| 35 | + } |
| 36 | + |
| 37 | + // Deploy VWAPOracle (Price Oracle) if needed |
| 38 | + address vwapOracleAddr; |
| 39 | + if (deployVWAPOracle) { |
| 40 | + VWAPOracle vwapOracle = new VWAPOracle{salt: salt}(admin); |
| 41 | + vwapOracleAddr = address(vwapOracle); |
| 42 | + console.log("VWAPOracle deployed at:", vwapOracleAddr); |
| 43 | + } else { |
| 44 | + vwapOracleAddr = vm.envOr("PRICE_ORACLE", address(0)); |
| 45 | + console.log("Using existing VWAPOracle at:", vwapOracleAddr); |
| 46 | + } |
| 47 | + |
| 48 | + // Deploy IntentGatewayV2 |
| 49 | + IntentGatewayV2 intentGatewayV2 = new IntentGatewayV2{salt: salt}(admin); |
| 50 | + console.log("IntentGatewayV2 deployed at:", address(intentGatewayV2)); |
| 51 | + |
| 52 | + // Set parameters on IntentGatewayV2 |
| 53 | + intentGatewayV2.setParams( |
| 54 | + Params({ |
| 55 | + host: HOST_ADDRESS, |
| 56 | + dispatcher: callDispatcherAddr, |
| 57 | + solverSelection: solverSelection, |
| 58 | + surplusShareBps: surplusShareBps, |
| 59 | + protocolFeeBps: protocolFeeBps, |
| 60 | + priceOracle: vwapOracleAddr |
| 61 | + }) |
| 62 | + ); |
| 63 | + |
| 64 | + // Deploy SolverAccount |
| 65 | + SolverAccount solverAccount = new SolverAccount{salt: salt}(address(intentGatewayV2)); |
| 66 | + console.log("SolverAccount deployed at:", address(solverAccount)); |
| 67 | + |
| 68 | + // Update config |
| 69 | + if (deployCallDispatcher) { |
| 70 | + config.set("CALL_DISPATCHER", callDispatcherAddr); |
| 71 | + } |
| 72 | + if (deployVWAPOracle) { |
| 73 | + config.set("VWAP_ORACLE", vwapOracleAddr); |
| 74 | + } |
| 75 | + config.set("INTENT_GATEWAY_V2", address(intentGatewayV2)); |
| 76 | + config.set("SOLVER_ACCOUNT", address(solverAccount)); |
| 77 | + |
| 78 | + console.log(""); |
| 79 | + console.log("=== Deployment Summary ==="); |
| 80 | + console.log("CallDispatcher:", callDispatcherAddr); |
| 81 | + console.log("VWAPOracle:", vwapOracleAddr); |
| 82 | + console.log("IntentGatewayV2:", address(intentGatewayV2)); |
| 83 | + console.log("SolverAccount:", address(solverAccount)); |
| 84 | + |
| 85 | + if (deployVWAPOracle) { |
| 86 | + console.log(""); |
| 87 | + console.log("=== IMPORTANT: Post-deployment step ==="); |
| 88 | + console.log("VWAPOracle needs initialization. Call VWAPOracle.init() with:"); |
| 89 | + console.log(" - hostAddr:", HOST_ADDRESS); |
| 90 | + console.log(" - updates: TokenDecimalsUpdate[] for token decimals on remote chains"); |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments