-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add deployment scripts for protocolFeeController (#221)
* feat: add deployment scripts for protocolFeeController * chore: redeployment * fix: adjust the test error tolerance to 0.05% * fix: excluded out extreme case for fuzz test
- Loading branch information
1 parent
d48491a
commit 2b79b8b
Showing
12 changed files
with
266 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
import "forge-std/Script.sol"; | ||
import {BaseScript} from "./BaseScript.sol"; | ||
import {ProtocolFeeController} from "../src/ProtocolFeeController.sol"; | ||
import {Create3Factory} from "pancake-create3-factory/src/Create3Factory.sol"; | ||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
/** | ||
* Step 1: Deploy | ||
* forge script script/04a_DeployCLProtocolFeeController.s.sol:DeployCLProtocolFeeControllerScript -vvv \ | ||
* --rpc-url $RPC_URL \ | ||
* --broadcast \ | ||
* --slow | ||
* | ||
* Step 2: Get the ABI-encoded form of the constructor arguments | ||
* cast abi-encode "Constructor(address)" <clPoolManager_addr> | ||
* | ||
* Step 3: Verify | ||
* forge verify-contract <address> ProtocolFeeController --watch --chain <chain_id> \ | ||
* --constructor-args <constructor_args_from_step2> | ||
* | ||
* Step 4: Proceed to deploy contract and call protocolFeeController.acceptOwnership | ||
*/ | ||
contract DeployCLProtocolFeeControllerScript is BaseScript { | ||
function getDeploymentSalt() public pure override returns (bytes32) { | ||
return keccak256("PANCAKE-V4-CORE/CLProtocolFeeController/0.91"); | ||
} | ||
|
||
function run() public { | ||
Create3Factory factory = Create3Factory(getAddressFromConfig("create3Factory")); | ||
|
||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
address clPoolManager = getAddressFromConfig("clPoolManager"); | ||
console.log("clPoolManager address: ", address(clPoolManager)); | ||
|
||
/// @dev append the clPoolManager address to the creationCode | ||
bytes memory creationCode = | ||
abi.encodePacked(type(ProtocolFeeController).creationCode, abi.encode(clPoolManager)); | ||
|
||
/// @dev prepare the payload to transfer ownership from deployer to real owner | ||
bytes memory afterDeploymentExecutionPayload = abi.encodeWithSelector( | ||
Ownable.transferOwnership.selector, getAddressFromConfig("protocolFeeControllerOwner") | ||
); | ||
|
||
address clProtocolFeeController = factory.deploy( | ||
getDeploymentSalt(), creationCode, keccak256(creationCode), 0, afterDeploymentExecutionPayload, 0 | ||
); | ||
|
||
console.log("CLProtocolFeeController contract deployed at ", clProtocolFeeController); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
import "forge-std/Script.sol"; | ||
import {BaseScript} from "./BaseScript.sol"; | ||
import {ProtocolFeeController} from "../src/ProtocolFeeController.sol"; | ||
import {IProtocolFees} from "../src/interfaces/IProtocolFees.sol"; | ||
|
||
/** | ||
* Step 1: Set ProtocolFeeController for CLPool | ||
* forge script script/04b_SetProtocolFeeControllerForCLPool.s.sol:SetProtocolFeeControllerForCLPoolScript -vvv \ | ||
* --rpc-url $RPC_URL \ | ||
* --broadcast \ | ||
* --slow | ||
*/ | ||
contract SetProtocolFeeControllerForCLPoolScript is BaseScript { | ||
function run() public { | ||
// @dev this should be the private key of the poolManager owner instead of the deployer | ||
uint256 ownerPrivateKey = vm.envUint("POOL_OWNER_PRIVATE_KEY"); | ||
vm.startBroadcast(ownerPrivateKey); | ||
|
||
IProtocolFees clPoolManager = IProtocolFees(getAddressFromConfig("clPoolManager")); | ||
console.log("clPoolManager address: ", address(clPoolManager)); | ||
|
||
ProtocolFeeController clProtocolFeeController = | ||
ProtocolFeeController(getAddressFromConfig("clProtocolFeeController")); | ||
console.log("clProtocolFeeController address: ", address(clProtocolFeeController)); | ||
|
||
if (clProtocolFeeController.poolManager() != address(clPoolManager)) { | ||
revert("PoolManager mismatch"); | ||
} | ||
|
||
IProtocolFees(clPoolManager).setProtocolFeeController( | ||
ProtocolFeeController(getAddressFromConfig("clProtocolFeeController")) | ||
); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
import "forge-std/Script.sol"; | ||
import {BaseScript} from "./BaseScript.sol"; | ||
import {ProtocolFeeController} from "../src/ProtocolFeeController.sol"; | ||
import {Create3Factory} from "pancake-create3-factory/src/Create3Factory.sol"; | ||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
/** | ||
* Step 1: Deploy | ||
* forge script script/05a_DeployBinProtocolFeeController.s.sol:DeployBinProtocolFeeControllerScript -vvv \ | ||
* --rpc-url $RPC_URL \ | ||
* --broadcast \ | ||
* --slow | ||
* | ||
* Step 2: Get the ABI-encoded form of the constructor arguments | ||
* cast abi-encode "Constructor(address)" <binPoolManager_addr> | ||
* | ||
* Step 3: Verify | ||
* forge verify-contract <address> ProtocolFeeController --watch --chain <chain_id> \ | ||
* --constructor-args <constructor_args_from_step2> | ||
* | ||
* Step 4: Proceed to deploy contract and call protocolFeeController.acceptOwnership | ||
*/ | ||
contract DeployBinProtocolFeeControllerScript is BaseScript { | ||
function getDeploymentSalt() public pure override returns (bytes32) { | ||
return keccak256("PANCAKE-V4-CORE/BinProtocolFeeController/0.91"); | ||
} | ||
|
||
function run() public { | ||
Create3Factory factory = Create3Factory(getAddressFromConfig("create3Factory")); | ||
|
||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
address binPoolManager = getAddressFromConfig("binPoolManager"); | ||
console.log("binPoolManager address: ", address(binPoolManager)); | ||
|
||
/// @dev append the binPoolManager address to the creationCode | ||
bytes memory creationCode = | ||
abi.encodePacked(type(ProtocolFeeController).creationCode, abi.encode(binPoolManager)); | ||
|
||
/// @dev prepare the payload to transfer ownership from deployer to real owner | ||
bytes memory afterDeploymentExecutionPayload = abi.encodeWithSelector( | ||
Ownable.transferOwnership.selector, getAddressFromConfig("protocolFeeControllerOwner") | ||
); | ||
|
||
address binProtocolFeeController = factory.deploy( | ||
getDeploymentSalt(), creationCode, keccak256(creationCode), 0, afterDeploymentExecutionPayload, 0 | ||
); | ||
|
||
console.log("BinProtocolFeeController contract deployed at ", binProtocolFeeController); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.24; | ||
|
||
import "forge-std/Script.sol"; | ||
import {BaseScript} from "./BaseScript.sol"; | ||
import {ProtocolFeeController} from "../src/ProtocolFeeController.sol"; | ||
import {IProtocolFees} from "../src/interfaces/IProtocolFees.sol"; | ||
|
||
/** | ||
* Step 1: Set ProtocolFeeController for BinPool | ||
* forge script script/05b_SetProtocolFeeControllerForBinPool.s.sol:SetProtocolFeeControllerForBinPoolScript -vvv \ | ||
* --rpc-url $RPC_URL \ | ||
* --broadcast \ | ||
* --slow | ||
*/ | ||
contract SetProtocolFeeControllerForBinPoolScript is BaseScript { | ||
function run() public { | ||
// @dev this should be the private key of the poolManager owner instead of the deployer | ||
uint256 ownerPrivateKey = vm.envUint("POOL_OWNER_PRIVATE_KEY"); | ||
vm.startBroadcast(ownerPrivateKey); | ||
|
||
IProtocolFees binPoolManager = IProtocolFees(getAddressFromConfig("binPoolManager")); | ||
console.log("binPoolManager address: ", address(binPoolManager)); | ||
|
||
ProtocolFeeController binProtocolFeeController = | ||
ProtocolFeeController(getAddressFromConfig("binProtocolFeeController")); | ||
console.log("binProtocolFeeController address: ", address(binProtocolFeeController)); | ||
|
||
if (binProtocolFeeController.poolManager() != address(binPoolManager)) { | ||
revert("PoolManager mismatch"); | ||
} | ||
|
||
IProtocolFees(binPoolManager).setProtocolFeeController( | ||
ProtocolFeeController(getAddressFromConfig("binProtocolFeeController")) | ||
); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"create3Factory": "0x38Ab3f2CE00973A51d3A2A04d634C9bcbf20e4e1", | ||
"owner": "0x42571B8414c68B63A2729146CE93F23639d25399", | ||
"poolOwner": "0x42571B8414c68B63A2729146CE93F23639d25399", | ||
"vault": "0xd557753bde3f0EaF32626F8681Ac6d8c1EBA2BBa", | ||
"clPoolManager": "0x70890E308DCE727180ac1B9550928fED342dea52", | ||
"binPoolManager": "0x68554d088F3640Bd2A7B38b43AE70FDcc16ef197" | ||
"binPoolManager": "0x68554d088F3640Bd2A7B38b43AE70FDcc16ef197", | ||
"protocolFeeControllerOwner": "0x42571B8414c68B63A2729146CE93F23639d25399", | ||
"clProtocolFeeController": "0xa3b9Af6E83B5161AC008cafb76712857bE54536D", | ||
"binProtocolFeeController": "0x4eE90A76f4C0b32bce3C941b6Fa409E6c4DCE98A" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"create3Factory": "0x", | ||
"owner": "0x", | ||
"poolOwner": "0x", | ||
"vault": "0x", | ||
"clPoolManager": "0x", | ||
"binPoolManager": "0x" | ||
"binPoolManager": "0x", | ||
"protocolFeeControllerOwner": "0x", | ||
"clProtocolFeeController": "0x", | ||
"binProtocolFeeController": "0x" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
{ | ||
"create3Factory": "0x38Ab3f2CE00973A51d3A2A04d634C9bcbf20e4e1", | ||
"owner": "0x", | ||
"poolOwner": "0x", | ||
"vault": "0x", | ||
"clPoolManager": "0x", | ||
"binPoolManager": "0x" | ||
"binPoolManager": "0x", | ||
"protocolFeeControllerOwner": "0x", | ||
"clProtocolFeeController": "0x", | ||
"binProtocolFeeController": "0x" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters