Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .changeset/lemon-wombats-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@fuel-bridge/solidity-contracts': minor
'@fuel-bridge/test-utils': minor
---

ci for contract upgrade test suite
4 changes: 4 additions & 0 deletions packages/solidity-contracts/deploy/hardhat/001.chain_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
upgrades: { deployProxy, erc1967 },
deployments: { save },
} = hre;

const isForking = hre.config.networks[hre.network.name]?.forking?.enabled;
if (isForking) return;

const [deployer] = await ethers.getSigners();

const contract = await deployProxy(new FuelChainState(deployer), [], {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
upgrades: { deployProxy, erc1967 },
deployments: { get, save },
} = hre;

const isForking = hre.config.networks[hre.network.name]?.forking?.enabled;
if (isForking) return;

const [deployer] = await ethers.getSigners();

const { address: fuelChainState } = await get('FuelChainState');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
upgrades: { deployProxy, erc1967 },
deployments: { get, save },
} = hre;

const isForking = hre.config.networks[hre.network.name]?.forking?.enabled;
if (isForking) return;

const [deployer] = await ethers.getSigners();

const fuelMessagePortal = await get('FuelMessagePortal');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ const COMMITTER_ADDRESS = '0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { ethers, deployments } = hre;

const isForking = hre.config.networks[hre.network.name]?.forking?.enabled;

const [deployer] = await ethers.getSigners();

const { address } = await deployments.get('FuelChainState');
if (!isForking) {
const { address } = await deployments.get('FuelChainState');

const fuelChainState = FuelChainState__factory.connect(address, deployer);
const COMMITTER_ROLE = await fuelChainState.COMMITTER_ROLE();
const fuelChainState = FuelChainState__factory.connect(address, deployer);
const COMMITTER_ROLE = await fuelChainState.COMMITTER_ROLE();

await fuelChainState
.grantRole(COMMITTER_ROLE, COMMITTER_ADDRESS)
.then((tx) => tx.wait());
await fuelChainState
.grantRole(COMMITTER_ROLE, COMMITTER_ADDRESS)
.then((tx) => tx.wait());
}

console.log('Granted role COMMITTER_ROLE to', COMMITTER_ADDRESS);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import fs from 'fs';
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import type { DeployFunction } from 'hardhat-deploy/dist/types';
import path from 'path';

import { FuelERC721GatewayV2__factory as FuelERC721GatewayV2 } from '../../typechain';

Expand All @@ -9,13 +11,33 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
upgrades: { deployProxy, erc1967 },
deployments: { get, save },
} = hre;

const isForking = hre.config.networks[hre.network.name]?.forking?.enabled;

const [deployer] = await ethers.getSigners();

const fuelMessagePortal = await get('FuelMessagePortal');
let portlAddress;
if (isForking) {
const deploymentPath = path.join(
__dirname,
'..',
'..',
'/',
'deployments',
'mainnet',
'FuelMessagePortal.json'
);

const deployment = JSON.parse(fs.readFileSync(deploymentPath, 'utf8'));
portlAddress = deployment.address;
} else {
const fuelMessagePortal = await get('FuelMessagePortal');
portlAddress = fuelMessagePortal.address;
}

const contract = await deployProxy(
new FuelERC721GatewayV2(deployer),
[fuelMessagePortal.address],
[portlAddress],
{
initializer: 'initialize',
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const ASSET_ISSUER_ID =

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { ethers, deployments } = hre;

const isForking = hre.config.networks[hre.network.name]?.forking?.enabled;
if (isForking) return;

const [deployer] = await ethers.getSigners();

await deployments.execute(
Expand Down
101 changes: 101 additions & 0 deletions packages/solidity-contracts/deploy/hardhat/009.chain_state_upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import fs from 'fs';
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import type { DeployFunction } from 'hardhat-deploy/dist/types';
import path from 'path';

import { FuelChainState__factory } from '../../typechain';

const BLOCKS_PER_COMMIT_INTERVAL = 30;
const TIME_TO_FINALIZE = 5;
const COMMIT_COOLDOWN = TIME_TO_FINALIZE;

const ADMIN = '0x32da601374b38154f05904B16F44A1911Aa6f314';
let COMMITTER_ADDRESS = '0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {
ethers,
upgrades: { erc1967 },
} = hre;

const [deployer] = await ethers.getSigners();

const isForking = hre.config.networks[hre.network.name]?.forking?.enabled;
let address;

if (isForking) {
const deploymentPath = path.join(
__dirname,
'..',
'..',
'/',
'deployments',
'mainnet',
'FuelChainState.json'
);

const deployment = JSON.parse(fs.readFileSync(deploymentPath, 'utf8'));
address = deployment.address;

const chainState = FuelChainState__factory.connect(address, deployer);

const factory = await hre.ethers.getContractFactory('FuelChainState');

const newImplementation = await factory.deploy(
TIME_TO_FINALIZE,
BLOCKS_PER_COMMIT_INTERVAL,
COMMIT_COOLDOWN
);

const newImplementationAddress = await newImplementation.getAddress();

let txData = chainState.interface.encodeFunctionData('upgradeTo', [
newImplementationAddress,
]);

await deployer.sendTransaction({
to: ADMIN,
value: ethers.parseEther('100'),
});

const impersonatedSigner = await ethers.getImpersonatedSigner(ADMIN);
await impersonatedSigner.sendTransaction({
to: address,
data: txData,
});

const COMMITTER_ROLE = await chainState.COMMITTER_ROLE();

txData = await chainState.interface.encodeFunctionData('grantRole', [
COMMITTER_ROLE,
COMMITTER_ADDRESS,
]);

await impersonatedSigner.sendTransaction({
to: address,
data: txData,
});

COMMITTER_ADDRESS = '0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65';

txData = await chainState.interface.encodeFunctionData('grantRole', [
COMMITTER_ROLE,
COMMITTER_ADDRESS,
]);

await impersonatedSigner.sendTransaction({
to: address,
data: txData,
});

const implementation = await erc1967.getImplementationAddress(address);

console.log('Upgraded FuelChainState to', implementation);

return true;
}
};

func.tags = ['upgrade_chain_state'];
func.id = 'upgrade_chain_state';
export default func;
86 changes: 86 additions & 0 deletions packages/solidity-contracts/deploy/hardhat/010.portal_upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { MaxUint256 } from 'ethers';
import fs from 'fs';
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import type { DeployFunction } from 'hardhat-deploy/dist/types';
import path from 'path';

import { FuelMessagePortalV3__factory as FuelMessagePortal } from '../../typechain';

const RATE_LIMIT_DURATION = 3600 * 24 * 7;

const ADMIN = '0x32da601374b38154f05904B16F44A1911Aa6f314';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {
ethers,
upgrades: { erc1967 },
} = hre;

const [deployer] = await ethers.getSigners();

const isForking = hre.config.networks[hre.network.name]?.forking?.enabled;
let address;

if (isForking) {
const deploymentPath = path.join(
__dirname,
'..',
'..',
'/',
'deployments',
'mainnet',
'FuelMessagePortal.json'
);

const deployment = JSON.parse(fs.readFileSync(deploymentPath, 'utf8'));
address = deployment.address;

const portal = FuelMessagePortal.connect(address, deployer);

const SET_RATE_LIMITER_ROLE = await portal.SET_RATE_LIMITER_ROLE();

const factory = await hre.ethers.getContractFactory('FuelMessagePortalV3');

const newImplementation = await factory.deploy(
MaxUint256,
RATE_LIMIT_DURATION
);

const newImplementationAddress = await newImplementation.getAddress();

let txData = portal.interface.encodeFunctionData('upgradeTo', [
newImplementationAddress,
]);

await deployer.sendTransaction({
to: ADMIN,
value: ethers.parseEther('100'),
});

const impersonatedSigner = await ethers.getImpersonatedSigner(ADMIN);
await impersonatedSigner.sendTransaction({
to: address,
data: txData,
});

txData = await portal.interface.encodeFunctionData('grantRole', [
SET_RATE_LIMITER_ROLE,
await deployer.getAddress(),
]);

await impersonatedSigner.sendTransaction({
to: address,
data: txData,
});

const implementation = await erc1967.getImplementationAddress(address);

console.log('Upgraded FuelMessagePortal to', implementation);

return true;
}
};

func.tags = ['upgrade_portal'];
func.id = 'upgrade_portal';
export default func;
Loading
Loading