Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
krzkaczor committed Jul 23, 2024
1 parent 628a95e commit 489b1f6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 50 deletions.
38 changes: 19 additions & 19 deletions scripts/spell-caster/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import type { Address } from "viem";
import { gnosis, mainnet } from "viem/chains";
import { getRequiredEnv } from "./env";
import type { Address } from 'viem'
import { gnosis, mainnet } from 'viem/chains'
import { getRequiredEnv } from './env'

export interface Config {
tenderly: TenderlyConfig;
networks: Record<string, NetworkConfig>;
tenderly: TenderlyConfig
networks: Record<string, NetworkConfig>
}

export interface NetworkConfig {
name: string;
chainId: number;
sparkSpellExecutor: Address;
name: string
chainId: number
sparkSpellExecutor: Address
}

export interface TenderlyConfig {
account: string;
project: string;
apiKey: string;
account: string
project: string
apiKey: string
}

export function getConfig(): Config {
return {
tenderly: {
account: getRequiredEnv("TENDERLY_ACCOUNT"),
project: getRequiredEnv("TENDERLY_PROJECT"),
apiKey: getRequiredEnv("TENDERLY_API_KEY"),
account: getRequiredEnv('TENDERLY_ACCOUNT'),
project: getRequiredEnv('TENDERLY_PROJECT'),
apiKey: getRequiredEnv('TENDERLY_API_KEY'),
},
networks: {
[mainnet.id]: {
name: "mainnet",
name: 'mainnet',
chainId: mainnet.id,
sparkSpellExecutor: "0x3300f198988e4C9C63F75dF86De36421f06af8c4",
sparkSpellExecutor: '0x3300f198988e4C9C63F75dF86De36421f06af8c4',
},
[gnosis.id]: {
name: "gnosis",
name: 'gnosis',
chainId: gnosis.id,
sparkSpellExecutor: "0xc4218C1127cB24a0D6c1e7D25dc34e10f2625f5A",
sparkSpellExecutor: '0xc4218C1127cB24a0D6c1e7D25dc34e10f2625f5A',
},
},
};
}
}
4 changes: 4 additions & 0 deletions scripts/spell-caster/src/executeSpell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe(executeSpell.name, () => {
test('replaces the code of the executor with a code of a spell', async () => {
const spellAddress = randomAddress('spell')
const network: NetworkConfig = {
name: 'mainnet',
chainId: 1,
sparkSpellExecutor: randomAddress('executor'),
}
Expand All @@ -26,6 +27,7 @@ describe(executeSpell.name, () => {
test('restores the code of the executor when done', async () => {
const spellAddress = randomAddress('spell')
const network: NetworkConfig = {
name: 'mainnet',
chainId: 1,
sparkSpellExecutor: randomAddress('executor'),
}
Expand All @@ -45,6 +47,7 @@ describe(executeSpell.name, () => {
test('executes a spell', async () => {
const spellAddress = randomAddress('spell')
const network: NetworkConfig = {
name: 'mainnet',
chainId: 1,
sparkSpellExecutor: randomAddress('executor'),
}
Expand All @@ -62,6 +65,7 @@ describe(executeSpell.name, () => {
test('throws if spell not deployed', async () => {
const spellAddress = randomAddress('spell')
const network: NetworkConfig = {
name: 'mainnet',
chainId: 1,
sparkSpellExecutor: randomAddress('executor'),
}
Expand Down
57 changes: 26 additions & 31 deletions scripts/spell-caster/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
import assert from "node:assert";
import { zeroAddress } from "viem";
import { getConfig } from "./config";
import { executeSpell } from "./executeSpell";
import { EthereumClient } from "./periphery/ethereum";
import { buildAppUrl } from "./periphery/spark-app";
import { createTenderlyVNet, getRandomChainId } from "./periphery/tenderly";
import { deployContract } from "./utils/forge";
import { getChainIdFromSpellName } from "./utils/getChainIdFromSpellName";

const deployer = zeroAddress;
import assert from 'node:assert'
import { zeroAddress } from 'viem'
import { getConfig } from './config'
import { executeSpell } from './executeSpell'
import { EthereumClient } from './periphery/ethereum'
import { buildAppUrl } from './periphery/spark-app'
import { createTenderlyVNet, getRandomChainId } from './periphery/tenderly'
import { deployContract } from './utils/forge'
import { getChainIdFromSpellName } from './utils/getChainIdFromSpellName'

const deployer = zeroAddress

async function main(spellName?: string) {
assert(
spellName,
"Pass spell name as an argument ex. SparkEthereum_20240627"
);
assert(spellName, 'Pass spell name as an argument ex. SparkEthereum_20240627')

const config = getConfig();
const originChainId = getChainIdFromSpellName(spellName);
const chain = config.networks[originChainId];
assert(chain, `Chain not found for chainId: ${originChainId}`);
const forkChainId = getRandomChainId();
const config = getConfig()
const originChainId = getChainIdFromSpellName(spellName)
const chain = config.networks[originChainId]
assert(chain, `Chain not found for chainId: ${originChainId}`)
const forkChainId = getRandomChainId()

console.log(
`Executing spell ${spellName} on ${chain.name} (chainId=${originChainId})`
);
console.log(`Executing spell ${spellName} on ${chain.name} (chainId=${originChainId})`)

const rpc = await createTenderlyVNet({
account: config.tenderly.account,
apiKey: config.tenderly.apiKey,
project: config.tenderly.project,
originChainId: originChainId,
forkChainId,
});
const ethereumClient = new EthereumClient(rpc, forkChainId, deployer);
})
const ethereumClient = new EthereumClient(rpc, forkChainId, deployer)

const spellAddress = await deployContract(spellName, rpc, deployer);
const spellAddress = await deployContract(spellName, rpc, deployer)

await executeSpell({ spellAddress, network: chain, ethereumClient });
await executeSpell({ spellAddress, network: chain, ethereumClient })

console.log(`Fork Network RPC: ${rpc}`);
console.log(`Spark App URL: ${buildAppUrl({ rpc, originChainId })}`);
console.log(`Fork Network RPC: ${rpc}`)
console.log(`Spark App URL: ${buildAppUrl({ rpc, originChainId })}`)
}

const arg1 = process.argv[2];
const arg1 = process.argv[2]

await main(arg1);
await main(arg1)

0 comments on commit 489b1f6

Please sign in to comment.