From 2c630a3dd4d04c5a028402aa2f39a00468859171 Mon Sep 17 00:00:00 2001 From: chefburger Date: Wed, 21 Aug 2024 14:20:32 +0800 Subject: [PATCH] deploy: adding deployment scripts --- foundry.toml | 5 ++- script/01_DeployMockVeToken.s.sol | 26 +++++++++++++++ script/02_DeployCLVeCakeExclusiveHook.s.sol | 34 ++++++++++++++++++++ script/03_DeployBinVeCakeExclusiveHook.s.sol | 34 ++++++++++++++++++++ script/BaseScript.sol | 29 +++++++++++++++++ script/config/bsc-testnet.json | 17 ++++++++++ 6 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 script/01_DeployMockVeToken.s.sol create mode 100644 script/02_DeployCLVeCakeExclusiveHook.s.sol create mode 100644 script/03_DeployBinVeCakeExclusiveHook.s.sol create mode 100644 script/BaseScript.sol create mode 100644 script/config/bsc-testnet.json diff --git a/foundry.toml b/foundry.toml index 28dc252..b966d03 100644 --- a/foundry.toml +++ b/foundry.toml @@ -11,7 +11,10 @@ optimizer_runs = 1000 via_ir = true evm_version = 'cancun' ffi = true -fs_permissions = [{ access = "read-write", path = ".forge-snapshots/" }] +fs_permissions = [ + { access = "read-write", path = ".forge-snapshots/" }, + { access = "read", path = "./script/config" }, +] [profile.default.fuzz] runs = 1000 diff --git a/script/01_DeployMockVeToken.s.sol b/script/01_DeployMockVeToken.s.sol new file mode 100644 index 0000000..19b806c --- /dev/null +++ b/script/01_DeployMockVeToken.s.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.24; + +import "forge-std/Script.sol"; +import {BaseScript} from "./BaseScript.sol"; + +import {MockERC20} from "solmate/src/test/utils/mocks/MockERC20.sol"; + +/** + * forge script script/01_DeployMockVeToken.s.sol:DeployMockVeTokenScript -vvv \ + * --rpc-url $RPC_URL \ + * --broadcast \ + * --slow \ + * --verify + */ +contract DeployMockVeTokenScript is BaseScript { + function run() public { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + MockERC20 VeCake = new MockERC20("MockVeCake", "VeCake", 18); + emit log_named_address("MockVeCake", address(VeCake)); + + vm.stopBroadcast(); + } +} diff --git a/script/02_DeployCLVeCakeExclusiveHook.s.sol b/script/02_DeployCLVeCakeExclusiveHook.s.sol new file mode 100644 index 0000000..80e4644 --- /dev/null +++ b/script/02_DeployCLVeCakeExclusiveHook.s.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.24; + +import "forge-std/Script.sol"; +import {BaseScript} from "./BaseScript.sol"; + +import {CLVeCakeExclusiveHook} from "../src/pool-cl/vecake-exclusive/CLVeCakeExclusiveHook.sol"; +import {ICLPoolManager} from "pancake-v4-core/src/pool-cl/interfaces/ICLPoolManager.sol"; + +/** + * forge script script/02_DeployCLVeCakeExclusiveHook.s.sol:DeployCLVeCakeExclusiveHookScript -vvv \ + * --rpc-url $RPC_URL \ + * --broadcast \ + * --slow \ + * --verify + */ +contract DeployCLVeCakeExclusiveHookScript is BaseScript { + function run() public { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + address clPoolManager = getAddressFromConfig("clPoolManager"); + emit log_named_address("CLPoolManager", clPoolManager); + + address veCake = getAddressFromConfig("veCake"); + emit log_named_address("VeCake", veCake); + + CLVeCakeExclusiveHook clVeCakeExclusiveHook = + new CLVeCakeExclusiveHook(ICLPoolManager(clPoolManager), address(veCake)); + emit log_named_address("CLVeCakeExclusiveHook", address(clVeCakeExclusiveHook)); + + vm.stopBroadcast(); + } +} diff --git a/script/03_DeployBinVeCakeExclusiveHook.s.sol b/script/03_DeployBinVeCakeExclusiveHook.s.sol new file mode 100644 index 0000000..6d80cf8 --- /dev/null +++ b/script/03_DeployBinVeCakeExclusiveHook.s.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.24; + +import "forge-std/Script.sol"; +import {BaseScript} from "./BaseScript.sol"; + +import {BinVeCakeExclusiveHook} from "../src/pool-bin/vecake-exclusive/BinVeCakeExclusiveHook.sol"; +import {IBinPoolManager} from "pancake-v4-core/src/pool-bin/interfaces/IBinPoolManager.sol"; + +/** + * forge script script/03_DeployBinVeCakeExclusiveHook.s.sol:DeployBinVeCakeExclusiveHookScript -vvv \ + * --rpc-url $RPC_URL \ + * --broadcast \ + * --slow \ + * --verify + */ +contract DeployBinVeCakeExclusiveHookScript is BaseScript { + function run() public { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + vm.startBroadcast(deployerPrivateKey); + + address binPoolManager = getAddressFromConfig("binPoolManager"); + emit log_named_address("BinPoolManager", binPoolManager); + + address veCake = getAddressFromConfig("veCake"); + emit log_named_address("VeCake", veCake); + + BinVeCakeExclusiveHook binVeCakeExclusiveHook = + new BinVeCakeExclusiveHook(IBinPoolManager(binPoolManager), address(veCake)); + emit log_named_address("CLVeCakeExclusiveHook", address(binVeCakeExclusiveHook)); + + vm.stopBroadcast(); + } +} diff --git a/script/BaseScript.sol b/script/BaseScript.sol new file mode 100644 index 0000000..cce3c75 --- /dev/null +++ b/script/BaseScript.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.24; + +import {Test} from "forge-std/Test.sol"; + +abstract contract BaseScript is Test { + string path; + + function setUp() public virtual { + string memory scriptConfig = vm.envString("SCRIPT_CONFIG"); + emit log(string.concat("[BaseScript] SCRIPT_CONFIG: ", scriptConfig)); + + string memory root = vm.projectRoot(); + path = string.concat(root, "/script/config/", scriptConfig, ".json"); + emit log(string.concat("[BaseScript] Reading config from: ", path)); + } + + // reference: https://github.com/foundry-rs/foundry/blob/master/testdata/default/cheats/Json.t.sol + function getAddressFromConfig(string memory key) public view returns (address) { + string memory json = vm.readFile(path); + bytes memory data = vm.parseJson(json, string.concat(".", key)); + + // seems like foundry decode as 0x20 when address is not set or as "0x" + address decodedData = abi.decode(data, (address)); + require(decodedData != address(0x20), "Address not set"); + + return decodedData; + } +} diff --git a/script/config/bsc-testnet.json b/script/config/bsc-testnet.json new file mode 100644 index 0000000..1f68afd --- /dev/null +++ b/script/config/bsc-testnet.json @@ -0,0 +1,17 @@ +{ + "permit2": "0x31c2F6fcFf4F8759b3Bd5Bf0e1084A055615c768", + "weth": "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd", + "vault": "0x79D5A618c43eCAda2BaaC65A9979cF120128f6Fa", + "clPoolManager": "0x40a081A39E9638fa6e2463B92A4eff4Bdf877179", + "binPoolManager": "0xc51DE4C65d6e3fb612050E383495e9457840d2c9", + "clPositionManager": "0xF254D17B9Ccae6BC3a40c8caDF3B8Ef563362C2D", + "binPositionManager": "0x45caADA89A3E257EA17fA3B56c3E09b63CD241B1", + "clQuoter:": "0x1E51cB768587C7A22AEBdCe787fb68A0953ec113", + "binQuoter": "0x76A1DFf6c0c64CE0906269228e89256b20A1fa2f", + "clMigrator": "0xF4a2f2A173ef10dF3733bb501d9DFFaD024567FC", + "binMigrator": "0x7a6689073890AFAa6d592B840d2fA73b2D52B820", + "veCake": "0x6B1fdFc5dFB10DC5735bB242D014B4d4F1fb2c7A", + "clVeCakeExclusiveHook": "0x470a9995c3bf588eE90A7F8e1b5372da1643Bca1", + "binVeCakeExclusiveHook": "0xb8848825d56D32679A1B451CE581ba665c4786B3" + } + \ No newline at end of file