Skip to content

Commit 31d06a3

Browse files
committed
Merge branch 'main' of https://github.com/w3hc/gov into 158-improve-scripts-2
2 parents 97f3b17 + dcb4164 commit 31d06a3

29 files changed

+1881
-5356
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ artifacts
1212
!.env.template
1313
NOTES.md
1414
deployments
15-
data.json
15+
data.json

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ The following functions are `onlyOwner`, and since the NFT contract ownership is
9292
| Base Mainnet | 8453 | [Documentation](https://docs.base.org/docs/network-information#base-mainnet) |
9393
| Arbitrum One | 42161 | [Documentation](https://docs.arbitrum.io/welcome/get-started) |
9494
| Sepolia Testnet | 11155111 | [Documentation](https://ethereum.org/nb/developers/docs/networks/#sepolia) |
95-
| OP Sepolia Testnet | 11155420 | [Documentation](https://docs.optimism.io/chain/networks#op-sepolia) |
95+
| OP Sepolia Testnet | 11155420 | [Documentation](https://docs.optimism.io/chain/networks#opSepolia) |
9696
| Base Sepolia Testnet | 84532 | [Documentation](https://docs.base.org/docs/network-information/#base-testnet-sepolia) |
9797
| Arbitrum Sepolia | 421614 | [Documentation](https://docs.arbitrum.io/welcome/get-started) |
9898

contracts/NFT.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ contract NFT is
6363
uint256 tokenId = _nextTokenId++;
6464
_safeMint(to, tokenId);
6565
_setTokenURI(tokenId, uri);
66+
_delegate(to, to);
6667
}
6768

6869
/// @notice Updates the NFT ownership

contracts/variants/crosschain/Gov.sol

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol";
66
import "@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol";
77
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
88
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
9+
import "./ProofHandler.sol";
910

1011
/**
1112
* @title Cross-chain Governance Contract
@@ -134,7 +135,7 @@ contract Gov is
134135

135136
string memory oldManifesto = manifesto;
136137
manifesto = newManifesto;
137-
emit ManifestoUpdated(oldManifesto, newManifesto);
138+
emit ManifestoUpdated(oldManifesto, newManifesto, nonce);
138139
}
139140

140141
/**
@@ -264,6 +265,136 @@ contract Gov is
264265
* @notice Gets the current voting delay
265266
* @return Current voting delay in blocks
266267
*/
268+
function setVotingPeriod(
269+
uint32 newVotingPeriod
270+
) public virtual override onlyGovernance onlyHomeChain {
271+
uint256 nonce = ProofHandler.incrementNonce(
272+
_proofStorage,
273+
uint8(OperationType.UPDATE_VOTING_PERIOD)
274+
);
275+
uint256 oldValue = votingPeriod();
276+
_setVotingPeriod(newVotingPeriod);
277+
emit GovernanceParameterUpdated(
278+
OperationType.UPDATE_VOTING_PERIOD,
279+
oldValue,
280+
newVotingPeriod,
281+
nonce
282+
);
283+
}
284+
285+
/**
286+
* @notice Updates the proposal threshold parameter on the home chain
287+
* @param newProposalThreshold New proposal threshold value
288+
*/
289+
function setProposalThreshold(
290+
uint256 newProposalThreshold
291+
) public virtual override onlyGovernance onlyHomeChain {
292+
uint256 nonce = ProofHandler.incrementNonce(
293+
_proofStorage,
294+
uint8(OperationType.UPDATE_PROPOSAL_THRESHOLD)
295+
);
296+
uint256 oldValue = proposalThreshold();
297+
_setProposalThreshold(newProposalThreshold);
298+
emit GovernanceParameterUpdated(
299+
OperationType.UPDATE_PROPOSAL_THRESHOLD,
300+
oldValue,
301+
newProposalThreshold,
302+
nonce
303+
);
304+
}
305+
306+
/**
307+
* @notice Updates the quorum numerator on the home chain
308+
* @param newQuorumNumerator New quorum numerator value
309+
*/
310+
function updateQuorumNumerator(
311+
uint256 newQuorumNumerator
312+
) public virtual override onlyGovernance onlyHomeChain {
313+
uint256 nonce = ProofHandler.incrementNonce(
314+
_proofStorage,
315+
uint8(OperationType.UPDATE_QUORUM)
316+
);
317+
uint256 oldValue = quorumNumerator();
318+
_updateQuorumNumerator(newQuorumNumerator);
319+
emit GovernanceParameterUpdated(
320+
OperationType.UPDATE_QUORUM,
321+
oldValue,
322+
newQuorumNumerator,
323+
nonce
324+
);
325+
}
326+
327+
/**
328+
* @notice Generates proof for parameter updates
329+
* @param operationType Type of parameter being updated
330+
* @param value Encoded parameter value
331+
* @return proof Encoded proof data
332+
*/
333+
function generateParameterProof(
334+
uint8 operationType,
335+
bytes memory value
336+
) external view returns (bytes memory proof) {
337+
require(block.chainid == home, "Proofs only generated on home chain");
338+
uint256 nextNonce = ProofHandler.getNextNonce(_proofStorage, operationType);
339+
return ProofHandler.generateProof(address(this), operationType, value, nextNonce);
340+
}
341+
342+
/**
343+
* @notice Claims a parameter update on a foreign chain
344+
* @param proof Proof generated by home chain
345+
*/
346+
function claimParameterUpdate(bytes memory proof) external {
347+
(uint8 operationType, bytes memory value, uint256 nonce) = ProofHandler.verifyAndClaimProof(
348+
proof,
349+
address(this),
350+
_proofStorage
351+
);
352+
353+
if (operationType == uint8(OperationType.SET_MANIFESTO)) {
354+
string memory newManifesto = abi.decode(value, (string));
355+
string memory oldManifesto = manifesto;
356+
manifesto = newManifesto;
357+
emit ManifestoUpdated(oldManifesto, newManifesto, nonce);
358+
} else if (operationType == uint8(OperationType.UPDATE_VOTING_DELAY)) {
359+
uint48 newValue = uint48(bytes6(value));
360+
uint256 oldValue = votingDelay();
361+
_setVotingDelay(newValue);
362+
emit GovernanceParameterUpdated(
363+
OperationType.UPDATE_VOTING_DELAY,
364+
oldValue,
365+
newValue,
366+
nonce
367+
);
368+
} else if (operationType == uint8(OperationType.UPDATE_VOTING_PERIOD)) {
369+
uint32 newValue = uint32(bytes4(value));
370+
uint256 oldValue = votingPeriod();
371+
_setVotingPeriod(newValue);
372+
emit GovernanceParameterUpdated(
373+
OperationType.UPDATE_VOTING_PERIOD,
374+
oldValue,
375+
newValue,
376+
nonce
377+
);
378+
} else if (operationType == uint8(OperationType.UPDATE_PROPOSAL_THRESHOLD)) {
379+
uint256 newValue = abi.decode(value, (uint256));
380+
uint256 oldValue = proposalThreshold();
381+
_setProposalThreshold(newValue);
382+
emit GovernanceParameterUpdated(
383+
OperationType.UPDATE_PROPOSAL_THRESHOLD,
384+
oldValue,
385+
newValue,
386+
nonce
387+
);
388+
} else if (operationType == uint8(OperationType.UPDATE_QUORUM)) {
389+
uint256 newValue = abi.decode(value, (uint256));
390+
uint256 oldValue = quorumNumerator();
391+
_updateQuorumNumerator(newValue);
392+
emit GovernanceParameterUpdated(OperationType.UPDATE_QUORUM, oldValue, newValue, nonce);
393+
}
394+
}
395+
396+
// Required overrides
397+
267398
function votingDelay() public view override(Governor, GovernorSettings) returns (uint256) {
268399
return super.votingDelay();
269400
}

0 commit comments

Comments
 (0)