Skip to content

Commit

Permalink
make use of useChainIdOfForkedNetwork for forks indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Apr 13, 2024
1 parent dd6dfea commit 9f69970
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 129 deletions.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"fs-extra": "^11.2.0",
"hardhat": "^2.20.1",
"hardhat-preprocessor": "^0.1.5",
"hardhat-rocketh": "^4.0.9",
"hardhat-rocketh": "^4.0.12",
"ldenv": "^0.3.10",
"prettier": "^3.2.5",
"prettier-plugin-solidity": "^1.3.1",
Expand Down
4 changes: 3 additions & 1 deletion contracts/scripts/data/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import {keepStreamOnFile} from 'ethereum-indexer-fs';
import contractsInfo from './contracts';
import hre from 'hardhat';
import {createProcessor} from 'stratagems-indexer';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

export const processor = createProcessor();
export const {state, init, indexToLatest} = createIndexerState(processor, {
keepStream: keepStreamOnFile('.data', 'stratagems'),
});

export async function indexAll() {
const env = await loadEnvironmentFromHardhat({hre}, {useChainIdOfForkedNetwork: true});
await init({
provider: hre.network.provider as any, // TOD type
provider: env.network.provider,
source: {
chainId: contractsInfo.chainId,
contracts: Object.keys(contractsInfo.contracts).map((name) => (contractsInfo as any).contracts[name]),
Expand Down
4 changes: 3 additions & 1 deletion contracts/scripts/data/playerWithWithdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Color} from 'stratagems-common';

import type {MergedAbis, JSProcessor} from 'ethereum-indexer-js-processor';
import {fromJSProcessor} from 'ethereum-indexer-js-processor';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

export type Data = {
players: {
Expand Down Expand Up @@ -45,8 +46,9 @@ export const {state, init, indexToLatest} = createIndexerState(processor, {
});

export async function indexPlayersWithWithdrawals() {
const env = await loadEnvironmentFromHardhat({hre}, {useChainIdOfForkedNetwork: true});
await init({
provider: hre.network.provider as any, // TOD type
provider: env.network.provider,
source: {
chainId: contractsInfo.chainId,
contracts: Object.keys(contractsInfo.contracts).map((name) => (contractsInfo as any).contracts[name]),
Expand Down
4 changes: 3 additions & 1 deletion contracts/scripts/data/players.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import hre from 'hardhat';
import type {MergedAbis, JSProcessor} from 'ethereum-indexer-js-processor';
import {fromJSProcessor} from 'ethereum-indexer-js-processor';
import {formatEther, zeroAddress} from 'viem';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

const testTokenAddress = contractsInfo.contracts['TestTokens'].address.toLowerCase();
const stratagemsAddress = contractsInfo.contracts['Stratagems'].address.toLowerCase();
Expand Down Expand Up @@ -92,8 +93,9 @@ export const {state, init, indexToLatest} = createIndexerState(processor, {
});

export async function indexPlayers() {
const env = await loadEnvironmentFromHardhat({hre}, {useChainIdOfForkedNetwork: true});
await init({
provider: hre.network.provider as any, // TOD type
provider: env.network.provider,
source: {
chainId: contractsInfo.chainId,
contracts: Object.keys(contractsInfo.contracts).map((name) => (contractsInfo as any).contracts[name]),
Expand Down
10 changes: 2 additions & 8 deletions contracts/scripts/distributeMoreTokens.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import {loadEnvironment} from 'rocketh';
import {context} from '../deploy/_context';
import {formatEther, parseUnits} from 'viem';
import hre from 'hardhat';
import 'rocketh-deploy';
import prompts from 'prompts';

import {indexPlayers} from './data/players';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as any,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const state = await indexPlayers();

Expand Down
10 changes: 2 additions & 8 deletions contracts/scripts/distributeTokens.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import {loadEnvironment} from 'rocketh';
import {context} from '../deploy/_context';
import {parseUnits} from 'viem';
import hre from 'hardhat';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const TestTokens = env.get<typeof context.artifacts.TestTokens.abi>('TestTokens');
const decimals = await env.read(TestTokens, {functionName: 'decimals'});
Expand Down
10 changes: 2 additions & 8 deletions contracts/scripts/fixDistribution.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import {loadEnvironment} from 'rocketh';
import {context} from '../deploy/_context';
import {formatEther, formatUnits, parseEther, parseUnits} from 'viem';
import hre from 'hardhat';
import 'rocketh-deploy';
import prompts from 'prompts';

import {indexPlayers} from './data/players';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as any,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const state = await indexPlayers();

Expand Down
14 changes: 2 additions & 12 deletions contracts/scripts/fixPointsBalance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {loadEnvironment} from 'rocketh';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';
import {context} from '../deploy/_context';
import {formatEther, formatUnits, parseEther, parseUnits} from 'viem';
import hre from 'hardhat';
Expand All @@ -7,17 +7,7 @@ import prompts from 'prompts';
import {indexAll} from './data/main';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as any,
network: process.env.HARDHAT_FORK // TODO move that in rocketh-harchat somehow
? {
fork: process.env.HARDHAT_FORK,
}
: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const state = await indexAll();

Expand Down
15 changes: 5 additions & 10 deletions contracts/scripts/gas.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {getGasPriceEstimate, getRoughGasPriceEstimate, loadEnvironment} from 'rocketh';
import type {EIP1193BlockTag, EIP1193GenericRequestProvider} from 'eip-1193';
import {getGasPriceEstimate, getRoughGasPriceEstimate} from 'rocketh';
import type {EIP1193BlockTag} from 'eip-1193';
import {context} from '../deploy/_context';
import hre from 'hardhat';
import {decodeFunctionResult, encodeFunctionData, formatEther} from 'viem';
import {formatEther} from 'viem';
import {getBaseFee, getGasPrice, getL1BaseFee, getL1Fee, getL1GasUsed} from './op';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

const args = process.argv.slice(2);
const blockTag = (args[0] || 'latest') as EIP1193BlockTag;
Expand All @@ -25,13 +26,7 @@ function formatAll(obj: object) {
}

async function main() {
const env = await loadEnvironment(
{
network: hre.network.name,
provider: hre.network.provider as EIP1193GenericRequestProvider,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});
const provider = env.network.provider;

const gasPriceEstimates = await getRoughGasPriceEstimate(provider);
Expand Down
12 changes: 3 additions & 9 deletions contracts/scripts/generateTokenLinks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {generatePrivateKey, privateKeyToAccount} from 'viem/accounts';

import {Deployment, loadEnvironment} from 'rocketh';
import {Deployment} from 'rocketh';
import {context} from '../deploy/_context';
import {formatEther, parseEther, parseUnits} from 'viem';
import hre from 'hardhat';
import fs from 'fs-extra';
import prompts from 'prompts';
import 'rocketh-deploy';
import {EIP1193GenericRequestProvider} from 'eip-1193';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

const args = process.argv.slice(2);
const num = (args[0] && parseInt(args[0])) || 100;
Expand All @@ -20,13 +20,7 @@ const valuePerChainId = {
};

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as EIP1193GenericRequestProvider,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const TestTokens = env.get<typeof context.artifacts.TestTokens.abi>('TestTokens');
const decimals = await env.read(TestTokens, {functionName: 'decimals'});
Expand Down
11 changes: 2 additions & 9 deletions contracts/scripts/getGasFee.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {loadEnvironment} from 'rocketh';
import {context} from '../deploy/_context';
import {EIP1193ProviderWithoutEvents} from 'eip-1193';
import {parseUnits} from 'viem';
import hre from 'hardhat';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

function avg(arr: bigint[]) {
const sum = arr.reduce((a: bigint, v: bigint) => a + v);
Expand Down Expand Up @@ -46,13 +45,7 @@ export async function estimateGasPrice(provider: EIP1193ProviderWithoutEvents) {
}

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const result = await estimateGasPrice(env.network.provider);
console.log(result);
Expand Down
10 changes: 2 additions & 8 deletions contracts/scripts/poke.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import {loadEnvironment} from 'rocketh';
import {context} from '../deploy/_context';
import {xyToBigIntID} from 'stratagems-common';
import hre from 'hardhat';
import 'rocketh-deploy';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as any,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const args = process.argv.slice(2);
const positionStr = args[0];
Expand Down
12 changes: 3 additions & 9 deletions contracts/scripts/readConfig.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import {Deployment, loadEnvironment} from 'rocketh';
import {Deployment} from 'rocketh';
import {context} from '../deploy/_context';
import hre from 'hardhat';
import {fetchContract} from '../utils/connection';
import {EIP1193GenericRequestProvider} from 'eip-1193';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as EIP1193GenericRequestProvider,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const args = process.argv.slice(2);
const account = (args[0] || process.env.ACCOUNT) as `0x${string}`;
Expand Down
12 changes: 3 additions & 9 deletions contracts/scripts/readReward.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import {Deployment, loadEnvironment} from 'rocketh';
import {Deployment} from 'rocketh';
import 'rocketh-deploy';
import {context} from '../deploy/_context';
import hre from 'hardhat';
import {EIP1193GenericRequestProvider} from 'eip-1193';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

const args = process.argv.slice(2) as `0x${string}`[];

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as EIP1193GenericRequestProvider,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const GemsGenerator = env.deployments.GemsGenerator as Deployment<typeof context.artifacts.RewardsGenerator.abi>;
const value = await env.read(GemsGenerator, {
Expand Down
23 changes: 10 additions & 13 deletions contracts/scripts/readTimestamp.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import {Deployment, loadEnvironment} from 'rocketh';
import {Deployment} from 'rocketh';
import {context} from '../deploy/_context';
import hre from 'hardhat';
import {fetchContract} from '../utils/connection';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';
import artifacts from 'solidity-kit/generated/artifacts';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const args = process.argv.slice(2);
const account = (args[0] || process.env.ACCOUNT) as `0x${string}`;
const Stratagems = env.deployments.Stratagems as Deployment<typeof context.artifacts.IStratagemsDebug.abi>;
const StratagemsContract = await fetchContract(Stratagems);
const timestamp = await StratagemsContract.read.timestamp();
const Time = env.deployments.Stratagems as Deployment<typeof artifacts.Time.abi>;
const timestamp = await env.read(Time, {
functionName: 'timestamp',
args: [],
});

console.log({account, timeContract: StratagemsContract.address, timestamp: timestamp.toString()});
console.log({account, timeContract: Time.address, timestamp: timestamp.toString()});
}
main();
11 changes: 2 additions & 9 deletions contracts/scripts/skipDays.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import {loadEnvironment} from 'rocketh';
import {context} from '../deploy/_context';
import hre from 'hardhat';
import {EIP1193GenericRequestProvider} from 'eip-1193';
import SolidityKit from 'solidity-kit/generated/artifacts';
import 'rocketh-deploy';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as EIP1193GenericRequestProvider,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const args = process.argv.slice(2);
const valueStr = args[0];
Expand Down
11 changes: 2 additions & 9 deletions contracts/scripts/steal.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import {loadEnvironment} from 'rocketh';
import {context} from '../deploy/_context';
import {xyToBigIntID} from 'stratagems-common';
import hre from 'hardhat';
import 'rocketh-deploy';
import {formatEther, parseEther} from 'viem';
import {loadEnvironmentFromHardhat} from 'hardhat-rocketh/helpers';

async function main() {
const env = await loadEnvironment(
{
provider: hre.network.provider as any,
network: hre.network.name,
},
context,
);
const env = await loadEnvironmentFromHardhat({hre, context});

const {deployer, tokensBeneficiary} = env.accounts;

Expand Down
Loading

0 comments on commit 9f69970

Please sign in to comment.