The home for Hyperlane core contracts, sdk packages, and other infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyperlane-monorepo/solidity/apps/test/governance/lib/utils.ts

96 lines
2.3 KiB

import { types, utils } from '@abacus-network/utils';
import { ethers } from 'ethers';
export enum GovernanceMessage {
CALL = 1,
SETGOVERNOR = 2,
ENROLLREMOTEROUTER = 3,
SETXAPPCONNECTIONMANAGER = 5,
}
export function formatSetGovernor(address: types.Address): string {
return ethers.utils.solidityPack(
['bytes1', 'bytes32'],
[GovernanceMessage.SETGOVERNOR, utils.addressToBytes32(address)],
);
}
export function formatSetXAppConnectionManager(address: types.Address): string {
return ethers.utils.solidityPack(
['bytes1', 'bytes32'],
[
GovernanceMessage.SETXAPPCONNECTIONMANAGER,
utils.addressToBytes32(address),
],
);
}
export function formatEnrollRemoteRouter(
domain: types.Domain,
address: types.Address,
): string {
return ethers.utils.solidityPack(
['bytes1', 'uint32', 'bytes32'],
[
GovernanceMessage.ENROLLREMOTEROUTER,
domain,
utils.addressToBytes32(address),
],
);
}
export function formatCalls(callsData: types.CallData[]): string {
let callBody = '0x';
const numCalls = callsData.length;
for (let i = 0; i < numCalls; i++) {
const { to, data } = callsData[i];
const dataLen = utils.getHexStringByteLength(data);
if (!to || !data) {
throw new Error(`Missing data in Call ${i + 1}: \n ${callsData[i]}`);
}
let hexBytes = ethers.utils.solidityPack(
['bytes32', 'uint256', 'bytes'],
[to, dataLen, data],
);
// remove 0x before appending
callBody += hexBytes.slice(2);
}
return ethers.utils.solidityPack(
['bytes1', 'bytes1', 'bytes'],
[GovernanceMessage.CALL, numCalls, callBody],
);
}
export function formatCall<
C extends ethers.Contract,
I extends Parameters<C['interface']['encodeFunctionData']>,
>(
destinationContract: C,
functionName: I[0],
functionArgs: I[1],
): types.CallData {
// Set up data for call message
const callData = utils.formatCallData(
destinationContract,
functionName as any,
functionArgs as any,
);
return {
to: utils.addressToBytes32(destinationContract.address),
data: callData,
};
}
export const increaseTimestampBy = async (
provider: ethers.providers.JsonRpcProvider,
increaseTime: number,
) => {
await provider.send('evm_increaseTime', [increaseTime]);
await provider.send('evm_mine', []);
};