Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
clowestab committed Sep 20, 2024
1 parent f2782d1 commit efba224
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 228 deletions.
39 changes: 39 additions & 0 deletions arbitrum-one.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { NitroRollup } from '@unruggable/gateways';
import { createProviderPair, providerURL } from './providers';
import { runExample } from './example-base';
import { type ConfigItem } from './utils';

const config = NitroRollup.arb1MainnetConfig;

// Make sure you've created a .env and added node provider API keys
console.log(providerURL(config.chain1));
console.log(providerURL(config.chain2));

const provider = providerURL(config.chain1);
const rollup = await new NitroRollup(
createProviderPair(config),
config
);
const verifierPath = `@unruggable/contracts/nitro/NitroVerifier.sol`;
const verifierArgs: any[] = [];
const GATEWAY_URL = 'https://arbitrum-one.gateway.unruggable.com';
//This is the address of the SlotDataContract deployed on the L2 (that we fork)
const EXAMPLE_CONTRACT_ADDRESS = '0xCC344B12fcc8512cc5639CeD6556064a8907c8a1'; //Arb
const configurationToSet: ConfigItem[] = [
{
getter: 'getWindow',
setter: 'setWindow',
value: rollup.defaultWindow,
},
{
getter: 'gatewayURLs',
setter: 'setGatewayURLs',
value: [GATEWAY_URL],
},
{
setter: 'setRollup',
value: rollup.L2Rollup.target,
},
];

runExample(provider, verifierPath, verifierArgs, configurationToSet, EXAMPLE_CONTRACT_ADDRESS);
113 changes: 0 additions & 113 deletions arbitrum.ts

This file was deleted.

Binary file modified bun.lockb
Binary file not shown.
92 changes: 92 additions & 0 deletions example-base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Foundry } from '@adraffy/blocksmith';
import { namehash, toBeHex, Contract } from 'ethers';
import { type ConfigItem, type VerifierArgsType } from './utils';
import { solidityFollowSlot } from '@unruggable/gateways';

const NAME_TO_TEST = "unruggable.eth";

export const runExample = async (
chainLink: string,
verifierPath: string,
verifierArgs: VerifierArgsType,
configurationToSet: ConfigItem[],
exampleContractAddress: string
) => {

const foundry = await Foundry.launch({
fork: chainLink,
procLog : true,
infoLog : true,
});

const deployerWallet = foundry.wallets.admin;

const verifierArgsToUse = typeof verifierArgs === 'function' ? await verifierArgs(foundry) : verifierArgs;

//Deploy verifier
const verifier = await foundry.deploy({
import: verifierPath,
args: verifierArgsToUse,
});

//Deploy proxy
const proxy = await foundry.deploy({
import: `@unruggable/lib/openzeppelin-contracts/contracts/proxy/transparent/TransparentUpgradeableProxy.sol`,
args: [verifier.target, deployerWallet.address, '0x'],
});

// Instantiate the proxy using the underlying verifier interface
const proxyUsingInterface = new Contract(
proxy.target,
verifier.interface,
deployerWallet
);

// Configure the verifier
for (const config of configurationToSet) {
await foundry.confirm(proxyUsingInterface[config.setter](config.value));
console.log(`Set ${config.setter} to ${config.value}`);
}

const ENS = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
const NODE = namehash(NAME_TO_TEST);
const SLOT = solidityFollowSlot(0, NODE) + 1n;

const arbitrumOneResolver = await foundry.deploy({
file: 'ExampleResolver',
args: [proxy.target, exampleContractAddress],
});

console.log('Arbitrum One Resolver deployment:', arbitrumOneResolver.target);

await foundry.provider.send('anvil_setStorageAt', [
ENS,
toBeHex(SLOT, 32),
toBeHex(arbitrumOneResolver.target, 32),
]);
const ens = new Contract(
ENS,
['function resolver(bytes32 node) view returns (address)'],
foundry.provider
);
console.log('Hijacked:', await ens.resolver(NODE));

async function resolve(name: string, keys = ['avatar'], coinType = 60) {
const resolver = await foundry.provider.getResolver(name);

console.log("Resolver", resolver);

if (!resolver) throw new Error('bug');
const [address] = await Promise.all([
resolver.getAddress(coinType)
]);
console.log({
name,
address,
});
}

await resolve(NAME_TO_TEST);

await foundry.shutdown();
}
Loading

0 comments on commit efba224

Please sign in to comment.