This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add script to deploy token voting modules (#74)
**Motivation:** Add support for JSON-based token voting module config deployments. **Modifications:** Added the script, added the commands to the justfile, and added a sample JSON config. **Result:** Developers can deploy token voting modules by creating a JSON config.
- Loading branch information
1 parent
dd2b930
commit 0e843a4
Showing
11 changed files
with
124 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {Script, stdJson} from "forge-std/Script.sol"; | ||
|
||
import {DeployUtils} from "script/DeployUtils.sol"; | ||
|
||
import {ILlamaCore} from "src/interfaces/ILlamaCore.sol"; | ||
import {CasterConfig, LlamaTokenVotingConfig} from "src/lib/Structs.sol"; | ||
import {ILlamaTokenAdapter} from "src/token-voting/interfaces/ILlamaTokenAdapter.sol"; | ||
import {LlamaTokenActionCreator} from "src/token-voting/LlamaTokenActionCreator.sol"; | ||
import {LlamaTokenCaster} from "src/token-voting/LlamaTokenCaster.sol"; | ||
import {LlamaTokenVotingFactory} from "src/token-voting/LlamaTokenVotingFactory.sol"; | ||
import {DeployUtils} from "script/DeployUtils.sol"; | ||
|
||
contract DeployLlamaTokenVotingModule is Script { | ||
using stdJson for string; | ||
|
||
function run(address deployer, string memory configFile) public { | ||
string memory jsonInput = DeployUtils.readScriptInput(configFile); | ||
|
||
LlamaTokenVotingFactory factory = LlamaTokenVotingFactory(jsonInput.readAddress(".factory")); | ||
|
||
DeployUtils.print(string.concat("Deploying Llama token voting module to chain:", vm.toString(block.chainid))); | ||
|
||
CasterConfig memory casterConfig = CasterConfig( | ||
abi.decode(jsonInput.parseRaw(".casterConfig.voteQuorumPct"), (uint16)), | ||
abi.decode(jsonInput.parseRaw(".casterConfig.vetoQuorumPct"), (uint16)), | ||
abi.decode(jsonInput.parseRaw(".casterConfig.delayPeriodPct"), (uint16)), | ||
abi.decode(jsonInput.parseRaw(".casterConfig.castingPeriodPct"), (uint16)), | ||
abi.decode(jsonInput.parseRaw(".casterConfig.submissionPeriodPct"), (uint16)) | ||
); | ||
|
||
LlamaTokenVotingConfig memory config = LlamaTokenVotingConfig( | ||
ILlamaCore(jsonInput.readAddress(".llamaCore")), | ||
ILlamaTokenAdapter(jsonInput.readAddress(".tokenAdapterLogic")), | ||
DeployUtils.readTokenAdapter(jsonInput), | ||
abi.decode(jsonInput.parseRaw(".nonce"), (uint256)), | ||
abi.decode(jsonInput.parseRaw(".actionCreatorRole"), (uint8)), | ||
abi.decode(jsonInput.parseRaw(".casterRole"), (uint8)), | ||
abi.decode(jsonInput.parseRaw(".creationThreshold"), (uint256)), | ||
casterConfig | ||
); | ||
|
||
vm.broadcast(deployer); | ||
(LlamaTokenActionCreator actionCreator, LlamaTokenCaster caster) = factory.deploy(config); | ||
|
||
DeployUtils.print("Successfully deployed a new Llama token voting module"); | ||
DeployUtils.print(string.concat(" LlamaTokenActionCreator: ", vm.toString(address(actionCreator)))); | ||
DeployUtils.print(string.concat(" LlamaTokenCaster: ", vm.toString(address(caster)))); | ||
} | ||
} |
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,13 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {console2} from "forge-std/Script.sol"; | ||
import {VmSafe} from "forge-std/Vm.sol"; | ||
import {console2, stdJson} from "forge-std/Script.sol"; | ||
|
||
import {LlamaTokenAdapterVotesTimestamp} from "src/token-voting/token-adapters/LlamaTokenAdapterVotesTimestamp.sol"; | ||
|
||
library DeployUtils { | ||
using stdJson for string; | ||
|
||
address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code")))); | ||
VmSafe internal constant VM = VmSafe(VM_ADDRESS); | ||
|
||
function readScriptInput(string memory filename) internal view returns (string memory) { | ||
string memory inputDir = string.concat(VM.projectRoot(), "/script/input/"); | ||
string memory chainDir = string.concat(VM.toString(block.chainid), "/"); | ||
return VM.readFile(string.concat(inputDir, chainDir, filename)); | ||
} | ||
|
||
function print(string memory message) internal view { | ||
// Avoid getting flooded with logs during tests. Note that fork tests will show logs with this | ||
// approach, because there's currently no way to tell which environment we're in, e.g. script | ||
// or test. This is being tracked in https://github.com/foundry-rs/foundry/issues/2900. | ||
if (block.chainid != 31_337) console2.log(message); | ||
} | ||
|
||
function readTokenAdapter(string memory jsonInput) internal pure returns (bytes memory) { | ||
address tokenAddress = jsonInput.readAddress(".tokenAddress"); | ||
return abi.encode(LlamaTokenAdapterVotesTimestamp.Config(tokenAddress)); | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"comment": "This is an example token voting module deployment on Sepolia.", | ||
"factory": "0x2997f4D6899DC91dE9Ae0FcD98b49CA88b8Fc85e", | ||
"llamaCore": "0xc68046794327490F953EA15522367FFBA0b64f86", | ||
"tokenAdapterLogic": "0x88D63b8c5F8C3e95743F1d26Df8aDd0669614278", | ||
"tokenAddress": "0xf44d44a54440F22e5DC5adb7efA3233645f04007", | ||
"nonce": 0, | ||
"actionCreatorRole": 0, | ||
"casterRole": 0, | ||
"creationThreshold": 10000e18, | ||
"casterConfig": { | ||
"voteQuorumPct": 2000, | ||
"vetoQuorumPct": 1000, | ||
"delayPeriodPct": 2500, | ||
"castingPeriodPct": 5000, | ||
"submissionPeriodPct": 2500 | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ pragma solidity ^0.8.23; | |
import {Clones} from "@openzeppelin/proxy/Clones.sol"; | ||
|
||
import {ILlamaCore} from "src/interfaces/ILlamaCore.sol"; | ||
import {CasterConfig} from "src/lib/Structs.sol"; | ||
import {CasterConfig, LlamaTokenVotingConfig} from "src/lib/Structs.sol"; | ||
import {ILlamaTokenAdapter} from "src/token-voting/interfaces/ILlamaTokenAdapter.sol"; | ||
import {LlamaTokenActionCreator} from "src/token-voting/LlamaTokenActionCreator.sol"; | ||
import {LlamaTokenCaster} from "src/token-voting/LlamaTokenCaster.sol"; | ||
|
@@ -13,22 +13,6 @@ import {LlamaTokenCaster} from "src/token-voting/LlamaTokenCaster.sol"; | |
/// @author Llama ([email protected]) | ||
/// @notice This contract enables Llama instances to deploy a token voting module. | ||
contract LlamaTokenVotingFactory { | ||
// ========================= | ||
// ======== Structs ======== | ||
// ========================= | ||
|
||
/// @dev Configuration of a new Llama token voting module. | ||
struct LlamaTokenVotingConfig { | ||
ILlamaCore llamaCore; // The address of the Llama core. | ||
ILlamaTokenAdapter tokenAdapterLogic; // The logic contract of the token adapter. | ||
bytes adapterConfig; // The configuration of the token adapter. | ||
uint256 nonce; // The nonce to be used in the salt of the deterministic deployment. | ||
uint8 actionCreatorRole; // The role required by the `LlamaTokenActionCreator` to create an action. | ||
uint8 casterRole; // The role required by the `LlamaTokenCaster` to cast approvals and disapprovals. | ||
uint256 creationThreshold; // The number of tokens required to create an action. | ||
CasterConfig casterConfig; // The quorum and period data for the `LlamaTokenCaster`. | ||
} | ||
|
||
// ======================== | ||
// ======== Errors ======== | ||
// ======================== | ||
|
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