Skip to content

Commit

Permalink
Update deploy scripts (#194)
Browse files Browse the repository at this point in the history
* forge install: pancake-create3-factory

* deployment: update scripts to adapt to Create3Factory

* docs: update deployment scripts

* chore: corrected comments for deployment scripts

* chore: updated README
  • Loading branch information
chefburger authored Oct 30, 2024
1 parent db82e88 commit d2f07fe
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/pancake-create3-factory"]
path = lib/pancake-create3-factory
url = https://github.com/pancakeswap/pancake-create3-factory
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ See https://github.com/pancakeswap/pancake-v4-core/pull/35 on why `--isolate` fl
The scripts are located in `/script` folder, deployed contract address can be found in `script/config`

### Pre-req: before deployment, the follow env variable needs to be set
```
```bash
// set script config: /script/config/{SCRIPT_CONFIG}.json
export SCRIPT_CONFIG=ethereum-sepolia

Expand All @@ -38,11 +38,19 @@ export ETHERSCAN_API_KEY=xx
Refer to the script source code for the exact command
Example. within `script/01_DeployVault.s.sol`
```
// remove --verify flag if etherscan_api_key is not set
```bash
forge script script/01_DeployVault.s.sol:DeployVaultScript -vvv \
--rpc-url $RPC_URL \
--broadcast \
--slow \
--verify
--slow
```
### Verifying
Each script includes a verification command. Verification needs to be performed separately since the contract is deployed using the create3 method.
Example. within `script/01_DeployVault.s.sol`
```bash
forge verify-contract <address> Vault --watch --chain <chain_id>
```
1 change: 1 addition & 0 deletions lib/pancake-create3-factory
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ forge-gas-snapshot/=lib/forge-gas-snapshot/src/
forge-std/=lib/forge-std/src/
@openzeppelin/=lib/openzeppelin-contracts/
solmate/=lib/solmate/
pancake-create3-factory/=lib/pancake-create3-factory/
31 changes: 27 additions & 4 deletions script/01_DeployVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,44 @@ pragma solidity ^0.8.24;
import "forge-std/Script.sol";
import {BaseScript} from "./BaseScript.sol";
import {Vault} from "../src/Vault.sol";
import {Create3Factory} from "pancake-create3-factory/src/Create3Factory.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

/**
* Step 1: Deploy
* forge script script/01_DeployVault.s.sol:DeployVaultScript -vvv \
* --rpc-url $RPC_URL \
* --broadcast \
* --slow \
* --verify
* --slow
*
* Step 2: Verify there is no need for --constructor-args as there are no constructor arguments for Vault
* forge verify-contract <address> Vault --watch --chain <chain_id>
*/
contract DeployVaultScript is BaseScript {
function getDeploymentSalt() public pure override returns (bytes32) {
return keccak256("PANCAKE-V4-CORE/VAULT/1.0");
}

function run() public {
Create3Factory factory = Create3Factory(getAddressFromConfig("create3Factory"));

uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

Vault vault = new Vault();
console.log("Vault contract deployed at ", address(vault));
/// @dev prepare the payload to transfer ownership from deployer to real owner
bytes memory afterDeploymentExecutionPayload =
abi.encodeWithSelector(Ownable.transferOwnership.selector, getAddressFromConfig("owner"));

address vault = factory.deploy(
getDeploymentSalt(),
type(Vault).creationCode,
keccak256(type(Vault).creationCode),
0,
afterDeploymentExecutionPayload,
0
);

console.log("Vault contract deployed at ", vault);

vm.stopBroadcast();
}
Expand Down
32 changes: 28 additions & 4 deletions script/02_DeployCLPoolManager.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,48 @@ import "forge-std/Script.sol";
import {BaseScript} from "./BaseScript.sol";
import {IVault} from "../src/interfaces/IVault.sol";
import {CLPoolManager} from "../src/pool-cl/CLPoolManager.sol";
import {Create3Factory} from "pancake-create3-factory/src/Create3Factory.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

/**
* Step 1: Deploy
* forge script script/02_DeployCLPoolManager.s.sol:DeployCLPoolManagerScript -vvv \
* --rpc-url $RPC_URL \
* --broadcast \
* --slow \
* --verify
* --slow
*
* Step 2: Get the ABI-encoded form of the constructor arguments
* cast abi-encode "Constructor(address)" <vault_addr>
*
* Step 3: Verify
* forge verify-contract <address> CLPoolManager --watch --chain <chain_id> \
* --constructor-args <constructor_args_from_step2>
*/
contract DeployCLPoolManagerScript is BaseScript {
function getDeploymentSalt() public pure override returns (bytes32) {
return keccak256("PANCAKE-V4-CORE/CLPoolManager/1.0");
}

function run() public {
Create3Factory factory = Create3Factory(getAddressFromConfig("create3Factory"));

uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

address vault = getAddressFromConfig("vault");
console.log("vault address: ", address(vault));

CLPoolManager clPoolManager = new CLPoolManager(IVault(address(vault)));
console.log("CLPoolManager contract deployed at ", address(clPoolManager));
/// @dev append the vault address to the creationCode
bytes memory creationCode = abi.encodePacked(type(CLPoolManager).creationCode, abi.encode(vault));

/// @dev prepare the payload to transfer ownership from deployer to real owner
bytes memory afterDeploymentExecutionPayload =
abi.encodeWithSelector(Ownable.transferOwnership.selector, getAddressFromConfig("owner"));

address clPoolManager = factory.deploy(
getDeploymentSalt(), creationCode, keccak256(creationCode), 0, afterDeploymentExecutionPayload, 0
);
console.log("CLPoolManager contract deployed at ", clPoolManager);

console.log("Registering CLPoolManager");
IVault(address(vault)).registerApp(address(clPoolManager));
Expand Down
33 changes: 29 additions & 4 deletions script/03_DeployBinPoolManager.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,49 @@ import "forge-std/Script.sol";
import {BaseScript} from "./BaseScript.sol";
import {IVault} from "../src/interfaces/IVault.sol";
import {BinPoolManager} from "../src/pool-bin/BinPoolManager.sol";
import {Create3Factory} from "pancake-create3-factory/src/Create3Factory.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

/**
* Step 1: Deploy
* forge script script/03_DeployBinPoolManager.s.sol:DeployBinPoolManagerScript -vvv \
* --rpc-url $RPC_URL \
* --broadcast \
* --slow \
* --verify
* --slow
*
* Step 2: Get the ABI-encoded form of the constructor arguments
* cast abi-encode "Constructor(address)" <vault_addr>
*
* Step 3: Verify
* forge verify-contract <address> BinPoolManager --watch --chain <chain_id> \
* --constructor-args <constructor_args_from_step2>
*/
contract DeployBinPoolManagerScript is BaseScript {
function getDeploymentSalt() public pure override returns (bytes32) {
return keccak256("PANCAKE-V4-CORE/BinPoolManager/1.0");
}

function run() public {
Create3Factory factory = Create3Factory(getAddressFromConfig("create3Factory"));

uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

address vault = getAddressFromConfig("vault");
console.log("vault address: ", address(vault));

BinPoolManager binPoolManager = new BinPoolManager(IVault(address(vault)));
console.log("BinPoolManager contract deployed at ", address(binPoolManager));
/// @dev append the vault address to the creationCode
bytes memory creationCode = abi.encodePacked(type(BinPoolManager).creationCode, abi.encode(vault));

/// @dev prepare the payload to transfer ownership from deployer to real owner
bytes memory afterDeploymentExecutionPayload =
abi.encodeWithSelector(Ownable.transferOwnership.selector, getAddressFromConfig("owner"));

address binPoolManager = factory.deploy(
getDeploymentSalt(), creationCode, keccak256(creationCode), 0, afterDeploymentExecutionPayload, 0
);

console.log("BinPoolManager contract deployed at ", binPoolManager);

console.log("Registering BinPoolManager");
IVault(address(vault)).registerApp(address(binPoolManager));
Expand Down
4 changes: 4 additions & 0 deletions script/BaseScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ abstract contract BaseScript is Script {

return decodedData;
}

/// @notice must be implemented by the inheriting contract to make sure eth deployment salt is unique
/// since the deployment salt will be the only factor to decide the address of the newly deployed contract
function getDeploymentSalt() public view virtual returns (bytes32);
}
2 changes: 2 additions & 0 deletions script/config/bsc-testnet.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"create3Factory": "0x56Ca545C577a0773ACaB85C921deA698f53A0B7b",
"owner": "0xbF0135be6a39257c659fd1955324dc3CDb342f29",
"vault": "0x0a125Bb36e409957Ed951eF1FBe20e81D682EAb6",
"clPoolManager": "0x26Ca53c8C5CE90E22aA1FadDA68AB9a08f7BA06f",
"binPoolManager": "0x1DF0be383e9d17DA4448E57712849aBE5b3Fa33b"
Expand Down
2 changes: 2 additions & 0 deletions script/config/ethereum-mainnet.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"create3Factory": "0x",
"owner": "0x",
"vault": "0x",
"clPoolManager": "0x",
"binPoolManager": "0x"
Expand Down
2 changes: 2 additions & 0 deletions script/config/ethereum-sepolia.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"create3Factory": "0x",
"owner": "0x",
"vault": "0x4670F769Daa625FF5F89719AE5295E9824f5805f",
"clPoolManager": "0xD4EAc75ee0E76EAD6AC6995DF30CA14b38549682",
"binPoolManager": "0x0Ca8430E263A098B998E47e0544C2C82B30CbDB1"
Expand Down

0 comments on commit d2f07fe

Please sign in to comment.