Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/w3hc/gov into 158-improve-s…
Browse files Browse the repository at this point in the history
…cripts-2
  • Loading branch information
julienbrg committed Dec 12, 2024
2 parents 97f3b17 + dcb4164 commit 31d06a3
Showing 29 changed files with 1,881 additions and 5,356 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -12,4 +12,4 @@ artifacts
!.env.template
NOTES.md
deployments
data.json
data.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ The following functions are `onlyOwner`, and since the NFT contract ownership is
| Base Mainnet | 8453 | [Documentation](https://docs.base.org/docs/network-information#base-mainnet) |
| Arbitrum One | 42161 | [Documentation](https://docs.arbitrum.io/welcome/get-started) |
| Sepolia Testnet | 11155111 | [Documentation](https://ethereum.org/nb/developers/docs/networks/#sepolia) |
| OP Sepolia Testnet | 11155420 | [Documentation](https://docs.optimism.io/chain/networks#op-sepolia) |
| OP Sepolia Testnet | 11155420 | [Documentation](https://docs.optimism.io/chain/networks#opSepolia) |
| Base Sepolia Testnet | 84532 | [Documentation](https://docs.base.org/docs/network-information/#base-testnet-sepolia) |
| Arbitrum Sepolia | 421614 | [Documentation](https://docs.arbitrum.io/welcome/get-started) |

1 change: 1 addition & 0 deletions contracts/NFT.sol
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ contract NFT is
uint256 tokenId = _nextTokenId++;
_safeMint(to, tokenId);
_setTokenURI(tokenId, uri);
_delegate(to, to);
}

/// @notice Updates the NFT ownership
133 changes: 132 additions & 1 deletion contracts/variants/crosschain/Gov.sol
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
import "./ProofHandler.sol";

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

string memory oldManifesto = manifesto;
manifesto = newManifesto;
emit ManifestoUpdated(oldManifesto, newManifesto);
emit ManifestoUpdated(oldManifesto, newManifesto, nonce);
}

/**
@@ -264,6 +265,136 @@ contract Gov is
* @notice Gets the current voting delay
* @return Current voting delay in blocks
*/
function setVotingPeriod(
uint32 newVotingPeriod
) public virtual override onlyGovernance onlyHomeChain {
uint256 nonce = ProofHandler.incrementNonce(
_proofStorage,
uint8(OperationType.UPDATE_VOTING_PERIOD)
);
uint256 oldValue = votingPeriod();
_setVotingPeriod(newVotingPeriod);
emit GovernanceParameterUpdated(
OperationType.UPDATE_VOTING_PERIOD,
oldValue,
newVotingPeriod,
nonce
);
}

/**
* @notice Updates the proposal threshold parameter on the home chain
* @param newProposalThreshold New proposal threshold value
*/
function setProposalThreshold(
uint256 newProposalThreshold
) public virtual override onlyGovernance onlyHomeChain {
uint256 nonce = ProofHandler.incrementNonce(
_proofStorage,
uint8(OperationType.UPDATE_PROPOSAL_THRESHOLD)
);
uint256 oldValue = proposalThreshold();
_setProposalThreshold(newProposalThreshold);
emit GovernanceParameterUpdated(
OperationType.UPDATE_PROPOSAL_THRESHOLD,
oldValue,
newProposalThreshold,
nonce
);
}

/**
* @notice Updates the quorum numerator on the home chain
* @param newQuorumNumerator New quorum numerator value
*/
function updateQuorumNumerator(
uint256 newQuorumNumerator
) public virtual override onlyGovernance onlyHomeChain {
uint256 nonce = ProofHandler.incrementNonce(
_proofStorage,
uint8(OperationType.UPDATE_QUORUM)
);
uint256 oldValue = quorumNumerator();
_updateQuorumNumerator(newQuorumNumerator);
emit GovernanceParameterUpdated(
OperationType.UPDATE_QUORUM,
oldValue,
newQuorumNumerator,
nonce
);
}

/**
* @notice Generates proof for parameter updates
* @param operationType Type of parameter being updated
* @param value Encoded parameter value
* @return proof Encoded proof data
*/
function generateParameterProof(
uint8 operationType,
bytes memory value
) external view returns (bytes memory proof) {
require(block.chainid == home, "Proofs only generated on home chain");
uint256 nextNonce = ProofHandler.getNextNonce(_proofStorage, operationType);
return ProofHandler.generateProof(address(this), operationType, value, nextNonce);
}

/**
* @notice Claims a parameter update on a foreign chain
* @param proof Proof generated by home chain
*/
function claimParameterUpdate(bytes memory proof) external {
(uint8 operationType, bytes memory value, uint256 nonce) = ProofHandler.verifyAndClaimProof(
proof,
address(this),
_proofStorage
);

if (operationType == uint8(OperationType.SET_MANIFESTO)) {
string memory newManifesto = abi.decode(value, (string));
string memory oldManifesto = manifesto;
manifesto = newManifesto;
emit ManifestoUpdated(oldManifesto, newManifesto, nonce);
} else if (operationType == uint8(OperationType.UPDATE_VOTING_DELAY)) {
uint48 newValue = uint48(bytes6(value));
uint256 oldValue = votingDelay();
_setVotingDelay(newValue);
emit GovernanceParameterUpdated(
OperationType.UPDATE_VOTING_DELAY,
oldValue,
newValue,
nonce
);
} else if (operationType == uint8(OperationType.UPDATE_VOTING_PERIOD)) {
uint32 newValue = uint32(bytes4(value));
uint256 oldValue = votingPeriod();
_setVotingPeriod(newValue);
emit GovernanceParameterUpdated(
OperationType.UPDATE_VOTING_PERIOD,
oldValue,
newValue,
nonce
);
} else if (operationType == uint8(OperationType.UPDATE_PROPOSAL_THRESHOLD)) {
uint256 newValue = abi.decode(value, (uint256));
uint256 oldValue = proposalThreshold();
_setProposalThreshold(newValue);
emit GovernanceParameterUpdated(
OperationType.UPDATE_PROPOSAL_THRESHOLD,
oldValue,
newValue,
nonce
);
} else if (operationType == uint8(OperationType.UPDATE_QUORUM)) {
uint256 newValue = abi.decode(value, (uint256));
uint256 oldValue = quorumNumerator();
_updateQuorumNumerator(newValue);
emit GovernanceParameterUpdated(OperationType.UPDATE_QUORUM, oldValue, newValue, nonce);
}
}

// Required overrides

function votingDelay() public view override(Governor, GovernorSettings) returns (uint256) {
return super.votingDelay();
}
Loading

0 comments on commit 31d06a3

Please sign in to comment.