@xyo-network/erc1967-witness 5.3.2 → 5.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ import { type Payload } from '@xyo-network/payload-model';
2
+ import type { Erc1967SlotStatus } from './lib/index.ts';
3
+ export declare const Erc1967StatusSchema: "network.xyo.erc1967.status" & {
4
+ readonly __schema: true;
5
+ };
6
+ export type Erc1967StatusSchema = typeof Erc1967StatusSchema;
7
+ export type Erc1967Status = Payload<{
8
+ address: string;
9
+ beacon?: Erc1967SlotStatus['beacon'];
10
+ block: number;
11
+ chainId: number;
12
+ implementation?: Erc1967SlotStatus['implementation'];
13
+ slots?: Erc1967SlotStatus['slots'];
14
+ }, Erc1967StatusSchema>;
15
+ //# sourceMappingURL=Payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvD,eAAO,MAAM,mBAAmB;;CAA+C,CAAA;AAC/E,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D,MAAM,MAAM,aAAa,GAAG,OAAO,CACjC;IACE,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAA;IACpC,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAA;IACpD,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAA;CACnC,EACD,mBAAmB,CACpB,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { Schema } from '@xyo-network/payload-model';
2
+ import type { EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
3
+ import { AbstractEvmWitness } from '@xyo-network/witness-evm-abstract';
4
+ import type { Erc1967Status } from './Payload.ts';
5
+ export declare const Erc1967WitnessConfigSchema: "network.xyo.erc1967.witness.config" & {
6
+ readonly __schema: true;
7
+ };
8
+ export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema;
9
+ export type Erc1967WitnessConfig = EvmWitnessConfig<{
10
+ address?: string;
11
+ }, Erc1967WitnessConfigSchema>;
12
+ export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
13
+ export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
14
+ static readonly configSchemas: Schema[];
15
+ static readonly defaultConfigSchema: Schema;
16
+ protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
17
+ }
18
+ //# sourceMappingURL=Witness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAExD,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAAE,gBAAgB,EACnC,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,kBAAkB,EAAoB,MAAM,mCAAmC,CAAA;AAGxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAGjD,eAAO,MAAM,0BAA0B;;CAAuD,CAAA;AAC9F,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAA;AAE1E,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,0BAA0B,CAAC,CAAA;AAErG,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,oBAAoB,CAAC,CAAA;AAEzE,qBAAa,cAAc,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,kBAAkB,CACjH,OAAO,EACP,UAAU,EACV,aAAa,CACd;IACC,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAuD;IACvG,gBAAyB,mBAAmB,EAAE,MAAM,CAA6B;cAExD,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAoCjG"}
@@ -0,0 +1,4 @@
1
+ export * from './lib/index.ts';
2
+ export * from './Payload.ts';
3
+ export * from './Witness.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}
@@ -0,0 +1,109 @@
1
+ // src/lib/getErc1967SlotStatus.ts
2
+ import {
3
+ asEthAddress,
4
+ hexFromHexString,
5
+ isHexZero
6
+ } from "@xylabs/sdk-js";
7
+ import { UpgradeableBeacon__factory } from "@xyo-network/open-zeppelin-typechain";
8
+ var ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
9
+ var ERC1967_PROXY_BEACON_STORAGE_SLOT = "0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50";
10
+ var ERC1967_PROXY_ADMIN_STORAGE_SLOT = "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
11
+ var ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = "0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143";
12
+ var readAddressFromSlot = async (provider, address, slot, block) => {
13
+ try {
14
+ const slotValue = await provider.getStorage(address, slot, block);
15
+ return asEthAddress(hexFromHexString(slotValue, { prefix: true }));
16
+ } catch {
17
+ return;
18
+ }
19
+ };
20
+ var getErc1967SlotStatus = async (provider, address, block) => {
21
+ const status = {
22
+ address,
23
+ implementation: address,
24
+ slots: {
25
+ admin: await readAddressFromSlot(provider, address, ERC1967_PROXY_ADMIN_STORAGE_SLOT, block),
26
+ beacon: await readAddressFromSlot(provider, address, ERC1967_PROXY_BEACON_STORAGE_SLOT, block),
27
+ implementation: await readAddressFromSlot(provider, address, ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT, block),
28
+ rollback: await readAddressFromSlot(provider, address, ERC1967_PROXY_ROLLBACK_STORAGE_SLOT, block)
29
+ }
30
+ };
31
+ if (status.slots.implementation && !isHexZero(status.slots.implementation)) {
32
+ status.implementation = `0x${BigInt(status.slots.implementation).toString(16).padStart(40, "0")}`;
33
+ } else {
34
+ if (status.slots.beacon && !isHexZero(status.slots.beacon)) {
35
+ const beacon = UpgradeableBeacon__factory.connect(status.slots.beacon, { provider });
36
+ try {
37
+ const implementation = await beacon.implementation(block ? { blockTag: block } : {});
38
+ if (implementation) {
39
+ status.beacon = { implementation };
40
+ if (!isHexZero(implementation)) {
41
+ status.implementation = implementation;
42
+ }
43
+ }
44
+ } catch (ex) {
45
+ const error = ex;
46
+ console.log(error.message);
47
+ }
48
+ }
49
+ }
50
+ return status;
51
+ };
52
+
53
+ // src/Payload.ts
54
+ import { asSchema } from "@xyo-network/payload-model";
55
+ var Erc1967StatusSchema = asSchema("network.xyo.erc1967.status", true);
56
+
57
+ // src/Witness.ts
58
+ import { assertEx } from "@xylabs/sdk-js";
59
+ import { asSchema as asSchema2, isPayloadOfSchemaType } from "@xyo-network/payload-model";
60
+ import { AbstractEvmWitness, EvmAddressSchema } from "@xyo-network/witness-evm-abstract";
61
+ var Erc1967WitnessConfigSchema = asSchema2("network.xyo.erc1967.witness.config", true);
62
+ var Erc1967Witness = class extends AbstractEvmWitness {
63
+ static configSchemas = [...super.configSchemas, Erc1967WitnessConfigSchema];
64
+ static defaultConfigSchema = Erc1967WitnessConfigSchema;
65
+ async observeHandler(inPayloads = []) {
66
+ await this.started("throw");
67
+ await this.getProviders();
68
+ try {
69
+ const observations = await Promise.all(
70
+ inPayloads.filter(isPayloadOfSchemaType(EvmAddressSchema)).map(async ({ address }) => {
71
+ const validatedAddress = assertEx(address ?? this.config.address, () => "Missing address").toLowerCase();
72
+ const provider = await this.getProvider(true, true);
73
+ const block = await provider.getBlockNumber();
74
+ const {
75
+ beacon,
76
+ implementation,
77
+ slots
78
+ } = await getErc1967SlotStatus(provider, validatedAddress, block);
79
+ const observation = {
80
+ address: validatedAddress,
81
+ beacon,
82
+ block,
83
+ chainId: Number((await provider.getNetwork()).chainId),
84
+ implementation,
85
+ schema: Erc1967StatusSchema,
86
+ slots
87
+ };
88
+ return observation;
89
+ })
90
+ );
91
+ return observations;
92
+ } catch (ex) {
93
+ const error = ex;
94
+ console.log(`Error [${this.config.name}]: ${error.message}`);
95
+ throw error;
96
+ }
97
+ }
98
+ };
99
+ export {
100
+ ERC1967_PROXY_ADMIN_STORAGE_SLOT,
101
+ ERC1967_PROXY_BEACON_STORAGE_SLOT,
102
+ ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT,
103
+ ERC1967_PROXY_ROLLBACK_STORAGE_SLOT,
104
+ Erc1967StatusSchema,
105
+ Erc1967Witness,
106
+ Erc1967WitnessConfigSchema,
107
+ getErc1967SlotStatus
108
+ };
109
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["import type { Address, EthAddress } from '@xylabs/sdk-js'\nimport {\n asEthAddress, hexFromHexString, isHexZero,\n} from '@xylabs/sdk-js'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport type { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' as EthAddress\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50' as EthAddress\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103' as EthAddress\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143' as EthAddress\n\nexport interface Erc1967DataSlots {\n admin?: EthAddress\n beacon?: EthAddress\n implementation?: EthAddress\n rollback?: EthAddress\n}\n\nexport interface Erc1967SlotStatus {\n address: string\n beacon?: {\n implementation?: Address\n }\n implementation: string\n slots: Erc1967DataSlots\n}\n\nconst readAddressFromSlot = async (provider: Provider, address: string, slot: string, block?: number) => {\n try {\n const slotValue = await provider.getStorage(address, slot, block)\n return asEthAddress(hexFromHexString(slotValue, { prefix: true }))\n } catch {\n return\n }\n}\n\nexport const getErc1967SlotStatus = async (provider: Provider, address: string, block?: number): Promise<Erc1967SlotStatus> => {\n const status: Erc1967SlotStatus = {\n address,\n implementation: address,\n slots: {\n admin: await readAddressFromSlot(provider, address, ERC1967_PROXY_ADMIN_STORAGE_SLOT, block),\n beacon: await readAddressFromSlot(provider, address, ERC1967_PROXY_BEACON_STORAGE_SLOT, block),\n implementation: await readAddressFromSlot(provider, address, ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT, block),\n rollback: await readAddressFromSlot(provider, address, ERC1967_PROXY_ROLLBACK_STORAGE_SLOT, block),\n },\n }\n\n if (status.slots.implementation && !isHexZero(status.slots.implementation)) {\n status.implementation = `0x${BigInt(status.slots.implementation as string)\n .toString(16)\n .padStart(40, '0')}` as Address\n } else {\n if (status.slots.beacon && !isHexZero(status.slots.beacon)) {\n const beacon = UpgradeableBeacon__factory.connect(status.slots.beacon as string, { provider })\n try {\n const implementation = (await beacon.implementation(block ? { blockTag: block } : {})) as Address\n if (implementation) {\n status.beacon = { implementation }\n if (!isHexZero(implementation)) {\n status.implementation = implementation\n }\n }\n } catch (ex) {\n const error = ex as Error\n console.log(error.message)\n }\n }\n }\n\n return status\n}\n","import { asSchema, type Payload } from '@xyo-network/payload-model'\n\nimport type { Erc1967SlotStatus } from './lib/index.ts'\n\nexport const Erc1967StatusSchema = asSchema('network.xyo.erc1967.status', true)\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: string\n beacon?: Erc1967SlotStatus['beacon']\n block: number\n chainId: number\n implementation?: Erc1967SlotStatus['implementation']\n slots?: Erc1967SlotStatus['slots']\n },\n Erc1967StatusSchema\n>\n","import { assertEx } from '@xylabs/sdk-js'\nimport type { Schema } from '@xyo-network/payload-model'\nimport { asSchema, isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport type {\n EvmAddress,\n EvmWitnessConfig, EvmWitnessParams,\n} from '@xyo-network/witness-evm-abstract'\nimport { AbstractEvmWitness, EvmAddressSchema } from '@xyo-network/witness-evm-abstract'\n\nimport { getErc1967SlotStatus } from './lib/index.ts'\nimport type { Erc1967Status } from './Payload.ts'\nimport { Erc1967StatusSchema } from './Payload.ts'\n\nexport const Erc1967WitnessConfigSchema = asSchema('network.xyo.erc1967.witness.config', true)\nexport type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema\n\nexport type Erc1967WitnessConfig = EvmWitnessConfig<{ address?: string }, Erc1967WitnessConfigSchema>\n\nexport type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>\n\nexport class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<\n TParams,\n EvmAddress,\n Erc1967Status\n> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, Erc1967WitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = Erc1967WitnessConfigSchema\n\n protected override async observeHandler(inPayloads: EvmAddress[] = []): Promise<Erc1967Status[]> {\n await this.started('throw')\n // calling it here to make sure we rests the cache\n await this.getProviders()\n try {\n const observations = await Promise.all(\n inPayloads.filter(isPayloadOfSchemaType<EvmAddress>(EvmAddressSchema)).map(async ({ address }) => {\n const validatedAddress = assertEx(address ?? this.config.address, () => 'Missing address').toLowerCase()\n\n const provider = await this.getProvider(true, true)\n\n const block = await provider.getBlockNumber()\n\n const {\n beacon, implementation, slots,\n } = await getErc1967SlotStatus(provider, validatedAddress, block)\n\n const observation: Erc1967Status = {\n address: validatedAddress,\n beacon,\n block,\n chainId: Number((await provider.getNetwork()).chainId),\n implementation,\n schema: Erc1967StatusSchema,\n slots,\n }\n return observation\n }),\n )\n return observations\n } catch (ex) {\n const error = ex as Error\n console.log(`Error [${this.config.name}]: ${error.message}`)\n throw error\n }\n }\n}\n"],"mappings":"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","names":["asSchema","asSchema"]}
@@ -0,0 +1,22 @@
1
+ import type { Address, EthAddress } from '@xylabs/sdk-js';
2
+ import type { Provider } from 'ethers';
3
+ export declare const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT: EthAddress;
4
+ export declare const ERC1967_PROXY_BEACON_STORAGE_SLOT: EthAddress;
5
+ export declare const ERC1967_PROXY_ADMIN_STORAGE_SLOT: EthAddress;
6
+ export declare const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT: EthAddress;
7
+ export interface Erc1967DataSlots {
8
+ admin?: EthAddress;
9
+ beacon?: EthAddress;
10
+ implementation?: EthAddress;
11
+ rollback?: EthAddress;
12
+ }
13
+ export interface Erc1967SlotStatus {
14
+ address: string;
15
+ beacon?: {
16
+ implementation?: Address;
17
+ };
18
+ implementation: string;
19
+ slots: Erc1967DataSlots;
20
+ }
21
+ export declare const getErc1967SlotStatus: (provider: Provider, address: string, block?: number) => Promise<Erc1967SlotStatus>;
22
+ //# sourceMappingURL=getErc1967SlotStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getErc1967SlotStatus.d.ts","sourceRoot":"","sources":["../../../src/lib/getErc1967SlotStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAKzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEtC,eAAO,MAAM,yCAAyC,EAA2E,UAAU,CAAA;AAC3I,eAAO,MAAM,iCAAiC,EAA2E,UAAU,CAAA;AACnI,eAAO,MAAM,gCAAgC,EAA2E,UAAU,CAAA;AAClI,eAAO,MAAM,mCAAmC,EAA2E,UAAU,CAAA;AAErI,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,cAAc,CAAC,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,EAAE,UAAU,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE;QACP,cAAc,CAAC,EAAE,OAAO,CAAA;KACzB,CAAA;IACD,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,gBAAgB,CAAA;CACxB;AAWD,eAAO,MAAM,oBAAoB,GAAU,UAAU,QAAQ,EAAE,SAAS,MAAM,EAAE,QAAQ,MAAM,KAAG,OAAO,CAAC,iBAAiB,CAmCzH,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './getErc1967SlotStatus.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/erc1967-witness",
3
- "version": "5.3.2",
3
+ "version": "5.3.3",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -30,13 +30,11 @@
30
30
  "types": "dist/neutral/index.d.ts",
31
31
  "files": [
32
32
  "dist",
33
- "src",
34
- "!**/*.bench.*",
35
- "!**/*.spec.*",
36
- "!**/*.test.*"
33
+ "README.md"
37
34
  ],
38
35
  "devDependencies": {
39
36
  "@xylabs/sdk-js": "^5.0.90",
37
+ "@xylabs/ts-scripts-common": "~7.5.10",
40
38
  "@xylabs/ts-scripts-yarn3": "~7.5.10",
41
39
  "@xylabs/tsconfig": "~7.5.10",
42
40
  "@xylabs/vitest-extended": "~5.0.90",
@@ -50,6 +48,9 @@
50
48
  },
51
49
  "peerDependencies": {
52
50
  "@xylabs/sdk-js": "^5",
51
+ "@xyo-network/open-zeppelin-typechain": "^4",
52
+ "@xyo-network/payload-model": "^5",
53
+ "@xyo-network/witness-evm-abstract": "^5",
53
54
  "ethers": "^6",
54
55
  "zod": "^4"
55
56
  },
package/src/Payload.ts DELETED
@@ -1,18 +0,0 @@
1
- import { asSchema, type Payload } from '@xyo-network/payload-model'
2
-
3
- import type { Erc1967SlotStatus } from './lib/index.ts'
4
-
5
- export const Erc1967StatusSchema = asSchema('network.xyo.erc1967.status', true)
6
- export type Erc1967StatusSchema = typeof Erc1967StatusSchema
7
-
8
- export type Erc1967Status = Payload<
9
- {
10
- address: string
11
- beacon?: Erc1967SlotStatus['beacon']
12
- block: number
13
- chainId: number
14
- implementation?: Erc1967SlotStatus['implementation']
15
- slots?: Erc1967SlotStatus['slots']
16
- },
17
- Erc1967StatusSchema
18
- >
package/src/Witness.ts DELETED
@@ -1,65 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import type { Schema } from '@xyo-network/payload-model'
3
- import { asSchema, isPayloadOfSchemaType } from '@xyo-network/payload-model'
4
- import type {
5
- EvmAddress,
6
- EvmWitnessConfig, EvmWitnessParams,
7
- } from '@xyo-network/witness-evm-abstract'
8
- import { AbstractEvmWitness, EvmAddressSchema } from '@xyo-network/witness-evm-abstract'
9
-
10
- import { getErc1967SlotStatus } from './lib/index.ts'
11
- import type { Erc1967Status } from './Payload.ts'
12
- import { Erc1967StatusSchema } from './Payload.ts'
13
-
14
- export const Erc1967WitnessConfigSchema = asSchema('network.xyo.erc1967.witness.config', true)
15
- export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema
16
-
17
- export type Erc1967WitnessConfig = EvmWitnessConfig<{ address?: string }, Erc1967WitnessConfigSchema>
18
-
19
- export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>
20
-
21
- export class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<
22
- TParams,
23
- EvmAddress,
24
- Erc1967Status
25
- > {
26
- static override readonly configSchemas: Schema[] = [...super.configSchemas, Erc1967WitnessConfigSchema]
27
- static override readonly defaultConfigSchema: Schema = Erc1967WitnessConfigSchema
28
-
29
- protected override async observeHandler(inPayloads: EvmAddress[] = []): Promise<Erc1967Status[]> {
30
- await this.started('throw')
31
- // calling it here to make sure we rests the cache
32
- await this.getProviders()
33
- try {
34
- const observations = await Promise.all(
35
- inPayloads.filter(isPayloadOfSchemaType<EvmAddress>(EvmAddressSchema)).map(async ({ address }) => {
36
- const validatedAddress = assertEx(address ?? this.config.address, () => 'Missing address').toLowerCase()
37
-
38
- const provider = await this.getProvider(true, true)
39
-
40
- const block = await provider.getBlockNumber()
41
-
42
- const {
43
- beacon, implementation, slots,
44
- } = await getErc1967SlotStatus(provider, validatedAddress, block)
45
-
46
- const observation: Erc1967Status = {
47
- address: validatedAddress,
48
- beacon,
49
- block,
50
- chainId: Number((await provider.getNetwork()).chainId),
51
- implementation,
52
- schema: Erc1967StatusSchema,
53
- slots,
54
- }
55
- return observation
56
- }),
57
- )
58
- return observations
59
- } catch (ex) {
60
- const error = ex as Error
61
- console.log(`Error [${this.config.name}]: ${error.message}`)
62
- throw error
63
- }
64
- }
65
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './lib/index.ts'
2
- export * from './Payload.ts'
3
- export * from './Witness.ts'
@@ -1,73 +0,0 @@
1
- import type { Address, EthAddress } from '@xylabs/sdk-js'
2
- import {
3
- asEthAddress, hexFromHexString, isHexZero,
4
- } from '@xylabs/sdk-js'
5
- import { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'
6
- import type { Provider } from 'ethers'
7
-
8
- export const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' as EthAddress
9
- export const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50' as EthAddress
10
- export const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103' as EthAddress
11
- export const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143' as EthAddress
12
-
13
- export interface Erc1967DataSlots {
14
- admin?: EthAddress
15
- beacon?: EthAddress
16
- implementation?: EthAddress
17
- rollback?: EthAddress
18
- }
19
-
20
- export interface Erc1967SlotStatus {
21
- address: string
22
- beacon?: {
23
- implementation?: Address
24
- }
25
- implementation: string
26
- slots: Erc1967DataSlots
27
- }
28
-
29
- const readAddressFromSlot = async (provider: Provider, address: string, slot: string, block?: number) => {
30
- try {
31
- const slotValue = await provider.getStorage(address, slot, block)
32
- return asEthAddress(hexFromHexString(slotValue, { prefix: true }))
33
- } catch {
34
- return
35
- }
36
- }
37
-
38
- export const getErc1967SlotStatus = async (provider: Provider, address: string, block?: number): Promise<Erc1967SlotStatus> => {
39
- const status: Erc1967SlotStatus = {
40
- address,
41
- implementation: address,
42
- slots: {
43
- admin: await readAddressFromSlot(provider, address, ERC1967_PROXY_ADMIN_STORAGE_SLOT, block),
44
- beacon: await readAddressFromSlot(provider, address, ERC1967_PROXY_BEACON_STORAGE_SLOT, block),
45
- implementation: await readAddressFromSlot(provider, address, ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT, block),
46
- rollback: await readAddressFromSlot(provider, address, ERC1967_PROXY_ROLLBACK_STORAGE_SLOT, block),
47
- },
48
- }
49
-
50
- if (status.slots.implementation && !isHexZero(status.slots.implementation)) {
51
- status.implementation = `0x${BigInt(status.slots.implementation as string)
52
- .toString(16)
53
- .padStart(40, '0')}` as Address
54
- } else {
55
- if (status.slots.beacon && !isHexZero(status.slots.beacon)) {
56
- const beacon = UpgradeableBeacon__factory.connect(status.slots.beacon as string, { provider })
57
- try {
58
- const implementation = (await beacon.implementation(block ? { blockTag: block } : {})) as Address
59
- if (implementation) {
60
- status.beacon = { implementation }
61
- if (!isHexZero(implementation)) {
62
- status.implementation = implementation
63
- }
64
- }
65
- } catch (ex) {
66
- const error = ex as Error
67
- console.log(error.message)
68
- }
69
- }
70
- }
71
-
72
- return status
73
- }
package/src/lib/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from './getErc1967SlotStatus.ts'