Skip to content

Commit

Permalink
feat: add forking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
clauBv23 committed Jan 28, 2025
1 parent 3d0cee7 commit 174f8b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/contracts/deploy/00_info/01_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getProductionNetworkName,
isLocal,
} from '../../utils/helpers';
import {forkNetwork} from '../helpers';
import {getNetworkByNameOrAlias} from '@aragon/osx-commons-configs';
import {UnsupportedNetworkError} from '@aragon/osx-commons-sdk';
import {DeployFunction} from 'hardhat-deploy/types';
Expand All @@ -20,7 +21,9 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`\n✨ ${path.basename(__filename)}:`);

const [deployer] = await hre.ethers.getSigners();
if (isLocal(hre)) {
if (process.env.FORKING_RPC_URL) {
await forkNetwork(hre, process.env.FORKING_RPC_URL);
} else if (isLocal(hre)) {
const productionNetworkName: string = getProductionNetworkName(hre);

console.log(
Expand All @@ -32,16 +35,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
if (networkConfig === null) {
throw new UnsupportedNetworkError(productionNetworkName);
}
await hre.network.provider.request({
method: 'hardhat_reset',
params: [
{
forking: {
jsonRpcUrl: networkConfig.url,
},
},
],
});
if (!networkConfig.url) {
throw new Error('RPC Url on network not defined');
}

await forkNetwork(hre, networkConfig.url);
} else {
console.log(`Production deployment on network '${hre.network.name}'.`);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/contracts/deploy/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ export function getLatestContractAddress(
return '';
}

export async function forkNetwork(
hre: HardhatRuntimeEnvironment,
fork_url: string
) {
await hre.network.provider.request({
method: 'hardhat_reset',
params: [
{
forking: {
jsonRpcUrl: fork_url,
},
},
],
});
}

export async function detemineDeployerNextAddress(
index: number,
deployer: SignerWithAddress
Expand Down

0 comments on commit 174f8b0

Please sign in to comment.