Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import type { DeployFunction } from 'hardhat-deploy/dist/types';

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

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {
ethers,
upgrades: { upgradeProxy, erc1967 },
deployments: { get, save },
} = hre;
const [deployer] = await ethers.getSigners();

const fuelChainState = await get('FuelChainState');

const BLOCKS_PER_COMMIT_INTERVAL = 10800;
const TIME_TO_FINALIZE = 3600 * 24;
const COMMIT_COOLDOWN = TIME_TO_FINALIZE;

const constructorArgs = [
TIME_TO_FINALIZE,
BLOCKS_PER_COMMIT_INTERVAL,
COMMIT_COOLDOWN,
];
const contract = await upgradeProxy(
fuelChainState.address,
new FuelChainState(deployer),
{
unsafeAllow: ['constructor'],
constructorArgs,
}
);
const address = await contract.getAddress();

const implementation = await erc1967.getImplementationAddress(address);

console.log('Upgraded FuelChainState at', address);
await save('FuelChainState', {
address,
abi: [...FuelChainState.abi],
implementation,
linkedData: {
constructorArgs,
factory: 'FuelChainState',
},
});

return true;
};

func.tags = ['chain_state_time_finalize_upgrade'];
func.id = 'chain_state_time_finalize_upgrade';
export default func;
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { TransactionResponse } from 'ethers';
import type { HardhatRuntimeEnvironment } from 'hardhat/types';
import type { DeployFunction } from 'hardhat-deploy/dist/types';

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

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

const contractDeployment = await hre.deployments.get('FuelChainState');

const BLOCKS_PER_COMMIT_INTERVAL = 10800;
const TIME_TO_FINALIZE = 3600 * 24;
const COMMIT_COOLDOWN = TIME_TO_FINALIZE;

const constructorArgs = [
TIME_TO_FINALIZE,
BLOCKS_PER_COMMIT_INTERVAL,
COMMIT_COOLDOWN,
];

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

const response = (await prepareUpgrade(contractDeployment.address, factory, {
kind: 'uups',
constructorArgs,
getTxResponse: true,
redeployImplementation: 'always',
})) as TransactionResponse;

const receipt = await hre.ethers.provider.getTransactionReceipt(
response.hash
);

const implementation = receipt?.contractAddress ?? '';

if (implementation === '')
throw new Error(
`Upgrade proposal failed for FuelChainState proxy (${contractDeployment.address})`
);

await save('FuelChainState', {
address: contractDeployment.address,
abi: [...FuelChainState.abi],
implementation,
transactionHash: response.hash,
linkedData: {
constructorArgs,
factory: 'FuelChainState',
},
});
};

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