-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-base.ts
79 lines (62 loc) · 2.19 KB
/
example-base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Foundry } from '@adraffy/blocksmith';
import { namehash, toBeHex, Contract, Wallet } from 'ethers';
import { 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,
exampleContractAddress: string
) => {
const foundry = await Foundry.launch({
fork: chainLink,
procLog : true,
infoLog : true,
});
const verifierArgsToUse = typeof verifierArgs === 'function' ? await verifierArgs(foundry) : verifierArgs;
const vmPath = `@unruggable/contracts/GatewayVM.sol`;
const GatewayVM = await foundry.deploy({
import: vmPath,
args: [],
});
const verifierLibs = {GatewayVM};
const verifier = await foundry.deploy({
import: verifierPath,
args: verifierArgsToUse,
libs: verifierLibs,
});
const ENS = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
const NODE = namehash(NAME_TO_TEST);
const SLOT = solidityFollowSlot(0, NODE) + 1n;
const resolver = await foundry.deploy({
file: 'ExampleResolver',
args: [verifier.target, exampleContractAddress],
});
console.log('Resolver deployment:', resolver.target);
await foundry.provider.send('anvil_setStorageAt', [
ENS,
toBeHex(SLOT, 32),
toBeHex(resolver.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();
}