Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Governance): new module based on TimeLock #196

Merged
merged 15 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions contracts/governance/AxelarGovernance.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;
milapsheth marked this conversation as resolved.
Show resolved Hide resolved

import { AxelarExecutable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol';
import { TimeLock } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/TimeLock.sol';
import { IAxelarGovernance } from '../interfaces/IAxelarGovernance.sol';

contract AxelarGovernance is AxelarExecutable, TimeLock, IAxelarGovernance {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
enum Command {
ScheduleProposal,
CancelProposal
}

bytes32 public immutable governanceChainHash;
bytes32 public immutable governanceAddressHash;

// solhint-disable-next-line no-empty-blocks
constructor(
address gatewayAddress,
string memory governanceChain_,
string memory governanceAddress_,
uint256 minimumTimeDelay
) AxelarExecutable(gatewayAddress) TimeLock(minimumTimeDelay) {
governanceChainHash = keccak256(bytes(governanceChain_));
governanceAddressHash = keccak256(bytes(governanceAddress_));
}

function executeProposal(address target, bytes calldata callData) external payable virtual {
_executeProposal(target, callData);
}

function _executeProposal(address target, bytes calldata callData) internal {
bytes32 proposalHash = keccak256(abi.encodePacked(target, callData));

_executeTimeLock(proposalHash);

(bool success, ) = target.call{ value: msg.value }(callData);
milapsheth marked this conversation as resolved.
Show resolved Hide resolved

if (!success) {
revert ExecutionFailed();
}

emit ProposalExecuted(proposalHash);
}

function _execute(
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) internal override {
if (keccak256(bytes(sourceChain)) != governanceChainHash || keccak256(bytes(sourceAddress)) != governanceAddressHash)
revert NotGovernance();

(Command command, address target, bytes memory callData, uint256 eta) = abi.decode(payload, (Command, address, bytes, uint256));

if (target == address(0)) revert InvalidTarget();
if (callData.length == 0) revert InvalidCallData();

bytes32 proposalHash = keccak256(abi.encodePacked(target, callData));

if (command == Command.ScheduleProposal) {
eta = _scheduleTimeLock(proposalHash, eta);

emit ProposalScheduled(proposalHash, target, callData, eta);
} else if (command == Command.CancelProposal) {
_cancelTimeLock(proposalHash);

emit ProposalCancelled(proposalHash);
} else {
revert InvalidCommand();
}
}

function _executeWithToken(
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
string calldata, /* sourceChain */
string calldata, /* sourceAddress */
bytes calldata, /* payload */
string calldata, /* tokenSymbol */
uint256 /* amount */
) internal pure override {
revert TokenNotSupported();
}
}
20 changes: 20 additions & 0 deletions contracts/interfaces/IAxelarGovernance.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;
milapsheth marked this conversation as resolved.
Show resolved Hide resolved

import '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarExecutable.sol';

interface IAxelarGovernance is IAxelarExecutable {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
error NotGovernance();
error InvalidCommand();
error InvalidTarget();
error InvalidCallData();
error ExecutionFailed();
error TokenNotSupported();

event ProposalScheduled(bytes32 indexed proposalHash, address indexed targetContract, bytes callData, uint256 eta);
event ProposalCancelled(bytes32 indexed proposalHash);
event ProposalExecuted(bytes32 indexed proposalHash);

function executeProposal(address targetContract, bytes calldata callData) external payable;
}