Skip to content

Commit

Permalink
feat: use AxelarGMPExecutable in Governance (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahramy authored Sep 4, 2024
1 parent 849152c commit b53530c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 44 deletions.
21 changes: 4 additions & 17 deletions contracts/governance/InterchainGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.0;

import { AxelarExecutable } from '../executable/AxelarExecutable.sol';
import { AxelarGMPExecutable } from '../executable/AxelarGMPExecutable.sol';
import { TimeLock } from '../utils/TimeLock.sol';
import { SafeNativeTransfer } from '../libs/SafeNativeTransfer.sol';
import { IInterchainGovernance } from '../interfaces/IInterchainGovernance.sol';
Expand All @@ -13,7 +13,7 @@ import { Caller } from '../utils/Caller.sol';
* @notice This contract handles cross-chain governance actions. It includes functionality
* to create, cancel, and execute governance proposals.
*/
contract InterchainGovernance is AxelarExecutable, TimeLock, Caller, IInterchainGovernance {
contract InterchainGovernance is AxelarGMPExecutable, TimeLock, Caller, IInterchainGovernance {
using SafeNativeTransfer for address;

enum GovernanceCommand {
Expand All @@ -38,7 +38,7 @@ contract InterchainGovernance is AxelarExecutable, TimeLock, Caller, IInterchain
string memory governanceChain_,
string memory governanceAddress_,
uint256 minimumTimeDelay
) AxelarExecutable(gateway_) TimeLock(minimumTimeDelay) {
) AxelarGMPExecutable(gateway_) TimeLock(minimumTimeDelay) {
if (bytes(governanceChain_).length == 0 || bytes(governanceAddress_).length == 0) {
revert InvalidAddress();
}
Expand Down Expand Up @@ -126,6 +126,7 @@ contract InterchainGovernance is AxelarExecutable, TimeLock, Caller, IInterchain
* @param payload The payload of the proposal
*/
function _execute(
bytes32, /* commandId */
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
Expand Down Expand Up @@ -183,20 +184,6 @@ contract InterchainGovernance is AxelarExecutable, TimeLock, Caller, IInterchain
return keccak256(abi.encode(target, callData, nativeValue));
}

/**
* @notice Overrides internal function of AxelarExecutable, will always revert
* as this governance module does not support execute with token.
*/
function _executeWithToken(
string calldata, /* sourceChain */
string calldata, /* sourceAddress */
bytes calldata, /* payload */
string calldata, /* tokenSymbol */
uint256 /* amount */
) internal pure override {
revert TokenNotSupported();
}

/**
* @notice Allow contract to receive native gas token
*/
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/IInterchainGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

pragma solidity ^0.8.0;

import { IAxelarExecutable } from './IAxelarExecutable.sol';
import { IAxelarGMPExecutable } from './IAxelarGMPExecutable.sol';
import { ICaller } from './ICaller.sol';
import { ITimeLock } from './ITimeLock.sol';

/**
* @title IInterchainGovernance Interface
* @notice This interface extends IAxelarExecutable for interchain governance mechanisms.
* @notice This interface extends IAxelarGMPExecutable for interchain governance mechanisms.
*/
interface IInterchainGovernance is IAxelarExecutable, ICaller, ITimeLock {
interface IInterchainGovernance is IAxelarGMPExecutable, ICaller, ITimeLock {
error NotGovernance();
error NotSelf();
error InvalidCommand();
Expand Down
13 changes: 2 additions & 11 deletions contracts/test/governance/TestInterchainGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,11 @@ contract TestInterchainGovernance is InterchainGovernance {
) InterchainGovernance(gatewayAddress, governanceChain_, governanceAddress_, minimumTimeDelay) {}

function executeProposalAction(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) external {
_execute(sourceChain, sourceAddress, payload);
}

function executeToken(
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) external pure {
_executeWithToken(sourceChain, sourceAddress, payload, tokenSymbol, amount);
_execute(commandId, sourceChain, sourceAddress, payload);
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@axelar-network/axelar-gmp-sdk-solidity",
"version": "5.10.0",
"version": "5.11.0",
"description": "Solidity GMP SDK and utilities provided by Axelar for cross-chain development",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/governance/AxelarServiceGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ describe('AxelarServiceGovernance', () => {
const bytecodeHash = keccak256(bytecode);

const expected = {
london: '0x5e40ac38c1162aa207054ab1f4d6f9205cdde1627f644eb6dfdb0fbfe17445fd',
london: '0x4ee32f41f8ec59746ff29e3e6c4f9e3a291868f98caeb21b87de446c3655ce78',
}[getEVMVersion()];

expect(bytecodeHash).to.be.equal(expected);
Expand Down
10 changes: 1 addition & 9 deletions test/governance/InterchainGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,6 @@ describe('InterchainGovernance', () => {
interchainGovernance.executeProposal(target, invalidCalldata, nativeValue, { value: nativeValue }),
).to.be.revertedWithCustomError(interchainGovernance, 'ExecutionFailed');
});

it('should revert on execute with token', async () => {
await expect(
interchainGovernance.executeWithToken(govCommandID, governanceChain, AddressZero, '0x', 'abc', 123),
).to.be.revertedWithCustomError(interchainGovernance, 'TokenNotSupported');
});
});

describe('positive tests', () => {
Expand Down Expand Up @@ -386,9 +380,7 @@ describe('InterchainGovernance', () => {
const bytecodeHash = keccak256(bytecode);

const expected = {
istanbul: '0x2534d1533c9ffce84d3174c1f846a4041d07b56d1e7b5cb7138e06fb42086325',
berlin: '0x1084d7de843267ed6f4ad87cbdc541bfb2aa003c67c285d0b4f90b3026370f7e',
london: '0x9d89dce5b3087d6f9a1b80cc3e96ae9c204a1ce3c2c4eb5bce7671a20a635f97',
london: '0x034b9b57bed553b7c9cfa5e4a14304776b65d8a3caefc87df9339203b04df56e',
}[getEVMVersion()];

expect(bytecodeHash).to.be.equal(expected);
Expand Down

0 comments on commit b53530c

Please sign in to comment.