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): allow multisig transfer via governance #174

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion contracts/governance/AxelarServiceGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ contract AxelarServiceGovernance is InterchainGovernance, IAxelarServiceGovernan
_;
}

modifier onlyMultisigOrSelf() {
if (msg.sender != multisig && msg.sender != address(this)) revert NotAuthorized();
_;
}

/**
* @notice Initializes the contract.
* @param gateway_ The address of the Axelar gateway contract
Expand Down Expand Up @@ -83,7 +88,12 @@ contract AxelarServiceGovernance is InterchainGovernance, IAxelarServiceGovernan
_call(target, callData, nativeValue);
}

function transferMultisig(address newMultisig) external onlyMultisig {
/**
* @notice Transfers the multisig address to a new address
* @dev Only the current multisig or the governance can call this function
* @param newMultisig The new multisig address
*/
function transferMultisig(address newMultisig) external onlyMultisigOrSelf {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
if (newMultisig == address(0)) revert InvalidMultisigAddress();

emit MultisigTransferred(multisig, newMultisig);
Expand Down
7 changes: 7 additions & 0 deletions contracts/interfaces/IAxelarServiceGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ interface IAxelarServiceGovernance is IInterchainGovernance {
bytes calldata callData,
uint256 value
) external payable;

/**
* @notice Transfers the multisig address to a new address
* @dev Only the current multisig or the governance can call this function
* @param newMultisig The new multisig address
*/
function transferMultisig(address newMultisig) external;
}
46 changes: 43 additions & 3 deletions test/governance/AxelarServiceGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
constants: { AddressZero },
} = ethers;
const { expect } = chai;
const { isHardhat, getPayloadAndProposalHash, getEVMVersion, expectRevert } = require('../utils');
const { isHardhat, getPayloadAndProposalHash, getEVMVersion, expectRevert, waitFor } = require('../utils');

describe('AxelarServiceGovernance', () => {
let ownerWallet;
Expand Down Expand Up @@ -352,7 +352,7 @@ describe('AxelarServiceGovernance', () => {
expect(newBalance).to.equal(oldBalance.add(nativeValue));
});

it('should trasfer multisig address to new address', async () => {
it('should transfer multisig address to new address', async () => {
const newMultisig = governanceAddress.address;
await expect(serviceGovernance.connect(multisig).transferMultisig(newMultisig))
.to.emit(serviceGovernance, 'MultisigTransferred')
Expand All @@ -366,12 +366,52 @@ describe('AxelarServiceGovernance', () => {
);
});

it('should transfer multisig by a governance proposal', async () => {
const govCommandID = formatBytes32String('10');
const newMultisig = serviceGovernance.address;
const transferCalldata = serviceGovernance.interface.encodeFunctionData('transferMultisig', [newMultisig]);

const [payload, proposalHash, eta] = await getPayloadAndProposalHash(
ScheduleTimeLockProposal,
serviceGovernance.address,
0,
transferCalldata,
timeDelay,
);

await expect(serviceGovernance.execute(govCommandID, governanceChain, governanceAddress.address, payload))
.to.emit(serviceGovernance, 'ProposalScheduled')
.withArgs(proposalHash, serviceGovernance.address, transferCalldata, 0, eta);

await waitFor(timeDelay);

const tx = await serviceGovernance.executeProposal(serviceGovernance.address, transferCalldata, 0);

const block = await ethers.provider.getBlock(tx.blockNumber);
const executionTimestamp = block.timestamp;

await expect(tx)
.to.emit(serviceGovernance, 'ProposalExecuted')
.withArgs(proposalHash, serviceGovernance.address, transferCalldata, 0, executionTimestamp)
.and.to.emit(serviceGovernance, 'MultisigTransferred')
.withArgs(governanceAddress.address, newMultisig);

await expect(await serviceGovernance.multisig()).to.equal(newMultisig);

await expectRevert(
async (gasOptions) =>
serviceGovernance.connect(governanceAddress).transferMultisig(newMultisig, gasOptions),
serviceGovernance,
'NotAuthorized',
);
});

it('should preserve the bytecode [ @skip-on-coverage ]', async () => {
const bytecode = serviceGovernanceFactory.bytecode;
const bytecodeHash = keccak256(bytecode);

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

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