Skip to content

Commit

Permalink
Merge pull request #10 from pancakeswap/deploy/scripts
Browse files Browse the repository at this point in the history
deploy: adding deployment scripts
  • Loading branch information
chefburger committed Aug 29, 2024
2 parents 75f5bbd + be93474 commit 2b85e16
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
/broadcast/*

# Docs
docs/
Expand Down
5 changes: 4 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions script/01_DeployMockVeToken.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}
34 changes: 34 additions & 0 deletions script/02_DeployCLVeCakeExclusiveHook.s.sol
Original file line number Diff line number Diff line change
@@ -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("mockVeCake");
emit log_named_address("VeCake", veCake);

CLVeCakeExclusiveHook clVeCakeExclusiveHook =
new CLVeCakeExclusiveHook(ICLPoolManager(clPoolManager), address(veCake));
emit log_named_address("CLVeCakeExclusiveHook", address(clVeCakeExclusiveHook));

vm.stopBroadcast();
}
}
34 changes: 34 additions & 0 deletions script/03_DeployBinVeCakeExclusiveHook.s.sol
Original file line number Diff line number Diff line change
@@ -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("mockVeCake");
emit log_named_address("VeCake", veCake);

BinVeCakeExclusiveHook binVeCakeExclusiveHook =
new BinVeCakeExclusiveHook(IBinPoolManager(binPoolManager), address(veCake));
emit log_named_address("BinVeCakeExclusiveHook", address(binVeCakeExclusiveHook));

vm.stopBroadcast();
}
}
29 changes: 29 additions & 0 deletions script/BaseScript.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 11 additions & 0 deletions script/config/bsc-testnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"vault": "0x08F012b8E2f3021db8bd2A896A7F422F4041F131",
"clPoolManager": "0x969D90aC74A1a5228b66440f8C8326a8dA47A5F9",
"binPoolManager": "0x437ef7C8C00d20a8535ae1786c5800c88413e7Af",
"clPositionManager": "0x89A7D45D007077485CB5aE2abFB740b1fe4FF574",
"binPositionManager": "0xfB84c0D67f217f078E949d791b8d3081FE91Bca2",
"mockVeCake": "0x86668337a40CaAd59F463E89550c6Aa59C056988",
"clVeCakeExclusiveHook": "0x7B07026C721F824ee913D65C5810884dEDf9ED50",
"binVeCakeExclusiveHook": "0x6D211114Ef77F89CD6912441CbaFfFBF71E25587"
}

0 comments on commit 2b85e16

Please sign in to comment.