solidity-governor
Generate smart contract code for implementing DAO governance with configurable voting parameters, timelocks, and upgradeability options.
Instructions
Make a contract to implement governance, such as for a DAO.
Returns the source code of the generated contract, formatted in a Markdown code block. Does not write to disk.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | The name of the contract | |
| delay | Yes | The delay since proposal is created until voting starts, default is "1 day" | |
| period | Yes | The length of period during which people can cast their vote, default is "1 week" | |
| votes | No | The type of voting to use | |
| clockMode | No | The clock mode used by the voting token. For Governor, this must be chosen to match what the ERC20 or ERC721 voting token uses. | |
| timelock | No | The type of timelock to use | |
| blockTime | No | The block time of the chain, default is 12 | |
| decimals | No | The number of decimals to use for the contract, default is 18 for ERC20Votes and 0 for ERC721Votes (because it does not apply to ERC721Votes) | |
| proposalThreshold | No | Minimum number of votes an account must have to create a proposal, default is 0. | |
| quorumMode | No | The type of quorum mode to use | |
| quorumPercent | No | The percent required, in cases of quorumMode equals percent | |
| quorumAbsolute | No | The absolute quorum required, in cases of quorumMode equals absolute | |
| storage | No | Enable storage of proposal details and enumerability of proposals | |
| settings | No | Allow governance to update voting settings (delay, period, proposal threshold) | |
| upgradeable | No | Whether the smart contract is upgradeable. Transparent uses more complex proxy with higher overhead, requires less changes in your contract. Can also be used with beacons. UUPS uses simpler proxy with less overhead, requires including extra code in your contract. Allows flexibility for authorizing upgrades. | |
| info | No | Metadata about the contract and author |
Implementation Reference
- Handler function that destructures input parameters, constructs GovernorOptions, and generates Solidity code using OpenZeppelin Wizard's governor.print() inside safePrintSolidityCodeBlock.async ({ name, delay, period, votes, clockMode, timelock, blockTime, decimals, proposalThreshold, quorumMode, quorumPercent, quorumAbsolute, storage, settings, upgradeable, info, }) => { const opts: GovernorOptions = { name, delay, period, votes, clockMode, timelock, blockTime, decimals, proposalThreshold, quorumMode, quorumPercent, quorumAbsolute, storage, settings, upgradeable, info, }; return { content: [ { type: 'text', text: safePrintSolidityCodeBlock(() => governor.print(opts)), }, ], }; },
- Zod schema for validating inputs to the solidity-governor tool, defining all GovernorOptions fields with descriptions.export const governorSchema = { name: z.string().describe(commonDescriptions.name), delay: z.string().describe(solidityGovernorDescriptions.delay), period: z.string().describe(solidityGovernorDescriptions.period), votes: z.literal('erc20votes').or(z.literal('erc721votes')).optional().describe(solidityGovernorDescriptions.votes), clockMode: z .literal('blocknumber') .or(z.literal('timestamp')) .optional() .describe(solidityGovernorDescriptions.clockMode), timelock: z .literal(false) .or(z.literal('openzeppelin')) .or(z.literal('compound')) .optional() .describe(solidityGovernorDescriptions.timelock), blockTime: z.number().optional().describe(solidityGovernorDescriptions.blockTime), decimals: z.number().optional().describe(solidityGovernorDescriptions.decimals), proposalThreshold: z.string().optional().describe(solidityGovernorDescriptions.proposalThreshold), quorumMode: z .literal('percent') .or(z.literal('absolute')) .optional() .describe(solidityGovernorDescriptions.quorumMode), quorumPercent: z.number().optional().describe(solidityGovernorDescriptions.quorumPercent), quorumAbsolute: z.string().optional().describe(solidityGovernorDescriptions.quorumAbsolute), storage: z.boolean().optional().describe(solidityGovernorDescriptions.storage), settings: z.boolean().optional().describe(solidityGovernorDescriptions.settings), upgradeable: commonSchema.upgradeable, info: commonSchema.info, } as const satisfies z.ZodRawShape;
- packages/mcp/src/solidity/tools/governor.ts:8-59 (registration)Registers the solidity-governor tool on the MCP server with its name, detailed prompt, schema, and handler function.export function registerSolidityGovernor(server: McpServer): RegisteredTool { return server.tool( 'solidity-governor', makeDetailedPrompt(solidityPrompts.Governor), governorSchema, async ({ name, delay, period, votes, clockMode, timelock, blockTime, decimals, proposalThreshold, quorumMode, quorumPercent, quorumAbsolute, storage, settings, upgradeable, info, }) => { const opts: GovernorOptions = { name, delay, period, votes, clockMode, timelock, blockTime, decimals, proposalThreshold, quorumMode, quorumPercent, quorumAbsolute, storage, settings, upgradeable, info, }; return { content: [ { type: 'text', text: safePrintSolidityCodeBlock(() => governor.print(opts)), }, ], }; }, ); }
- packages/mcp/src/solidity/tools.ts:25-27 (registration)Includes the governor tool registration in the getRegisterFunctions map, called by registerSolidityTools.Governor: () => registerSolidityGovernor(server), Custom: () => registerSolidityCustom(server), };
- packages/mcp/src/server.ts:25-25 (registration)Calls registerSolidityTools which ultimately registers all Solidity tools including solidity-governor.registerSolidityTools(server);