@xyo-network/erc1967-witness 2.84.3 → 2.84.4
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.
- package/dist/browser/Witness.d.cts +5 -5
- package/dist/browser/Witness.d.cts.map +1 -1
- package/dist/browser/Witness.d.mts +5 -5
- package/dist/browser/Witness.d.mts.map +1 -1
- package/dist/browser/Witness.d.ts +5 -5
- package/dist/browser/Witness.d.ts.map +1 -1
- package/dist/browser/index.cjs +3 -3
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +3 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Witness.d.cts +5 -5
- package/dist/node/Witness.d.cts.map +1 -1
- package/dist/node/Witness.d.mts +5 -5
- package/dist/node/Witness.d.mts.map +1 -1
- package/dist/node/Witness.d.ts +5 -5
- package/dist/node/Witness.d.ts.map +1 -1
- package/dist/node/index.cjs +3 -3
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +3 -6
- package/dist/node/index.js.map +1 -1
- package/package.json +6 -6
- package/src/Witness.ts +7 -13
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
2
|
import { Erc1967Status } from './Payload';
|
|
3
3
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
4
4
|
export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema;
|
|
5
|
-
export type Erc1967WitnessConfig =
|
|
5
|
+
export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
6
6
|
address?: string;
|
|
7
7
|
}, Erc1967WitnessConfigSchema>;
|
|
8
|
-
export type Erc1967WitnessParams =
|
|
9
|
-
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends
|
|
8
|
+
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
|
+
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
10
|
static configSchemas: string[];
|
|
11
|
-
protected observeHandler(inPayloads?:
|
|
11
|
+
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAoB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAGxI,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,uCAAuC,CAAA;AAC9E,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,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
2
|
import { Erc1967Status } from './Payload';
|
|
3
3
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
4
4
|
export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema;
|
|
5
|
-
export type Erc1967WitnessConfig =
|
|
5
|
+
export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
6
6
|
address?: string;
|
|
7
7
|
}, Erc1967WitnessConfigSchema>;
|
|
8
|
-
export type Erc1967WitnessParams =
|
|
9
|
-
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends
|
|
8
|
+
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
|
+
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
10
|
static configSchemas: string[];
|
|
11
|
-
protected observeHandler(inPayloads?:
|
|
11
|
+
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAoB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAGxI,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,uCAAuC,CAAA;AAC9E,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,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
2
|
import { Erc1967Status } from './Payload';
|
|
3
3
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
4
4
|
export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema;
|
|
5
|
-
export type Erc1967WitnessConfig =
|
|
5
|
+
export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
6
6
|
address?: string;
|
|
7
7
|
}, Erc1967WitnessConfigSchema>;
|
|
8
|
-
export type Erc1967WitnessParams =
|
|
9
|
-
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends
|
|
8
|
+
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
|
+
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
10
|
static configSchemas: string[];
|
|
11
|
-
protected observeHandler(inPayloads?:
|
|
11
|
+
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAoB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAGxI,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,uCAAuC,CAAA;AAC9E,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,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -85,16 +85,16 @@ var Erc1967StatusSchema = "network.xyo.erc1967.status";
|
|
|
85
85
|
// src/Witness.ts
|
|
86
86
|
var import_assert = require("@xylabs/assert");
|
|
87
87
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
88
|
-
var
|
|
88
|
+
var import_witness_evm_abstract = require("@xyo-network/witness-evm-abstract");
|
|
89
89
|
var Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
90
|
-
var Erc1967Witness = class extends
|
|
90
|
+
var Erc1967Witness = class extends import_witness_evm_abstract.AbstractEvmWitness {
|
|
91
91
|
static configSchemas = [Erc1967WitnessConfigSchema];
|
|
92
92
|
async observeHandler(inPayloads = []) {
|
|
93
93
|
await this.started("throw");
|
|
94
94
|
await this.getProviders();
|
|
95
95
|
try {
|
|
96
96
|
const observations = await Promise.all(
|
|
97
|
-
inPayloads.filter((0, import_payload_model.isPayloadOfSchemaType)(
|
|
97
|
+
inPayloads.filter((0, import_payload_model.isPayloadOfSchemaType)(import_witness_evm_abstract.EvmAddressSchema)).map(async ({ address }) => {
|
|
98
98
|
const validatedAddress = (0, import_assert.assertEx)(address ?? this.config.address, "Missing address").toLowerCase();
|
|
99
99
|
const provider = await this.getProvider(true, true);
|
|
100
100
|
const block = await provider.getBlockNumber();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["export * from './lib'\nexport * from './Payload'\nexport * from './Witness'\n","import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50'\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143'\n\nexport interface Erc1967DataSlots {\n admin?: Address\n beacon?: Address\n implementation?: Address\n rollback?: Address\n}\n\nexport interface Erc1967SlotStatus {\n address: Address\n beacon?: {\n implementation?: Address\n }\n implementation: Address\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 hexFromHexString(slotValue, { prefix: true })\n } catch (ex) {\n return undefined\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')}`\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 } : {})\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 { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1967SlotStatus } from './lib'\n\nexport const Erc1967StatusSchema = 'network.xyo.erc1967.status'\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: Address\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/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["export * from './lib'\nexport * from './Payload'\nexport * from './Witness'\n","import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50'\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143'\n\nexport interface Erc1967DataSlots {\n admin?: Address\n beacon?: Address\n implementation?: Address\n rollback?: Address\n}\n\nexport interface Erc1967SlotStatus {\n address: Address\n beacon?: {\n implementation?: Address\n }\n implementation: Address\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 hexFromHexString(slotValue, { prefix: true })\n } catch (ex) {\n return undefined\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')}`\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 } : {})\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 { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1967SlotStatus } from './lib'\n\nexport const Erc1967StatusSchema = 'network.xyo.erc1967.status'\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: Address\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/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { AbstractEvmWitness, EvmAddress, EvmAddressSchema, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract'\n\nimport { getErc1967SlotStatus } from './lib'\nimport { Erc1967Status, Erc1967StatusSchema } from './Payload'\n\nexport const Erc1967WitnessConfigSchema = 'network.xyo.erc1967.witness.config'\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 configSchemas = [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 { beacon, implementation, slots } = 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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAqD;AACrD,qCAA2C;AAGpC,IAAM,4CAA4C;AAClD,IAAM,oCAAoC;AAC1C,IAAM,mCAAmC;AACzC,IAAM,sCAAsC;AAkBnD,IAAM,sBAAsB,OAAO,UAAoB,SAAiB,MAAc,UAAmB;AACvG,MAAI;AACF,UAAM,YAAY,MAAM,SAAS,WAAW,SAAS,MAAM,KAAK;AAChE,eAAO,6BAAiB,WAAW,EAAE,QAAQ,KAAK,CAAC;AAAA,EACrD,SAAS,IAAI;AACX,WAAO;AAAA,EACT;AACF;AAEO,IAAM,uBAAuB,OAAO,UAAoB,SAAiB,UAA+C;AAC7H,QAAM,SAA4B;AAAA,IAChC;AAAA,IACA,gBAAgB;AAAA,IAChB,OAAO;AAAA,MACL,OAAO,MAAM,oBAAoB,UAAU,SAAS,kCAAkC,KAAK;AAAA,MA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B,CAAC,EAAE,IAAI,OAAO,EAAE,QAAQ,MAAM;AAChG,gBAAM,uBAAmB,wBAAS,WAAW,KAAK,OAAO,SAAS,iBAAiB,EAAE,YAAY;AAEjG,gBAAM,WAAW,MAAM,KAAK,YAAY,MAAM,IAAI;AAElD,gBAAM,QAAQ,MAAM,SAAS,eAAe;AAE5C,gBAAM,EAAE,QAAQ,gBAAgB,MAAM,IAAI,MAAM,qBAAqB,UAAU,kBAAkB,KAAK;AAEtG,gBAAM,cAA6B;AAAA,YACjC,SAAS;AAAA,YACT;AAAA,YACA;AAAA,YACA,SAAS,QAAQ,MAAM,SAAS,WAAW,GAAG,OAAO;AAAA,YACrD;AAAA,YACA,QAAQ;AAAA,YACR;AAAA,UACF;AACA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT,SAAS,IAAI;AACX,YAAM,QAAQ;AACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAM,MAAM,OAAO,EAAE;AAC3D,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
package/dist/browser/index.js
CHANGED
|
@@ -52,19 +52,16 @@ var Erc1967StatusSchema = "network.xyo.erc1967.status";
|
|
|
52
52
|
// src/Witness.ts
|
|
53
53
|
import { assertEx } from "@xylabs/assert";
|
|
54
54
|
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
55
|
-
import {
|
|
56
|
-
AbstractBlockchainWitness,
|
|
57
|
-
BlockchainAddressSchema
|
|
58
|
-
} from "@xyo-network/witness-blockchain-abstract";
|
|
55
|
+
import { AbstractEvmWitness, EvmAddressSchema } from "@xyo-network/witness-evm-abstract";
|
|
59
56
|
var Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
60
|
-
var Erc1967Witness = class extends
|
|
57
|
+
var Erc1967Witness = class extends AbstractEvmWitness {
|
|
61
58
|
static configSchemas = [Erc1967WitnessConfigSchema];
|
|
62
59
|
async observeHandler(inPayloads = []) {
|
|
63
60
|
await this.started("throw");
|
|
64
61
|
await this.getProviders();
|
|
65
62
|
try {
|
|
66
63
|
const observations = await Promise.all(
|
|
67
|
-
inPayloads.filter(isPayloadOfSchemaType(
|
|
64
|
+
inPayloads.filter(isPayloadOfSchemaType(EvmAddressSchema)).map(async ({ address }) => {
|
|
68
65
|
const validatedAddress = assertEx(address ?? this.config.address, "Missing address").toLowerCase();
|
|
69
66
|
const provider = await this.getProvider(true, true);
|
|
70
67
|
const block = await provider.getBlockNumber();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50'\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143'\n\nexport interface Erc1967DataSlots {\n admin?: Address\n beacon?: Address\n implementation?: Address\n rollback?: Address\n}\n\nexport interface Erc1967SlotStatus {\n address: Address\n beacon?: {\n implementation?: Address\n }\n implementation: Address\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 hexFromHexString(slotValue, { prefix: true })\n } catch (ex) {\n return undefined\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')}`\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 } : {})\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 { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1967SlotStatus } from './lib'\n\nexport const Erc1967StatusSchema = 'network.xyo.erc1967.status'\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: Address\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/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50'\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143'\n\nexport interface Erc1967DataSlots {\n admin?: Address\n beacon?: Address\n implementation?: Address\n rollback?: Address\n}\n\nexport interface Erc1967SlotStatus {\n address: Address\n beacon?: {\n implementation?: Address\n }\n implementation: Address\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 hexFromHexString(slotValue, { prefix: true })\n } catch (ex) {\n return undefined\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')}`\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 } : {})\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 { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1967SlotStatus } from './lib'\n\nexport const Erc1967StatusSchema = 'network.xyo.erc1967.status'\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: Address\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/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { AbstractEvmWitness, EvmAddress, EvmAddressSchema, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract'\n\nimport { getErc1967SlotStatus } from './lib'\nimport { Erc1967Status, Erc1967StatusSchema } from './Payload'\n\nexport const Erc1967WitnessConfigSchema = 'network.xyo.erc1967.witness.config'\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 configSchemas = [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 { beacon, implementation, slots } = 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":";AAAA,SAAkB,kBAAkB,iBAAiB;AACrD,SAAS,kCAAkC;AAGpC,IAAM,4CAA4C;AAClD,IAAM,oCAAoC;AAC1C,IAAM,mCAAmC;AACzC,IAAM,sCAAsC;AAkBnD,IAAM,sBAAsB,OAAO,UAAoB,SAAiB,MAAc,UAAmB;AACvG,MAAI;AACF,UAAM,YAAY,MAAM,SAAS,WAAW,SAAS,MAAM,KAAK;AAChE,WAAO,iBAAiB,WAAW,EAAE,QAAQ,KAAK,CAAC;AAAA,EACrD,SAAS,IAAI;AACX,WAAO;AAAA,EACT;AACF;AAEO,IAAM,uBAAuB,OAAO,UAAoB,SAAiB,UAA+C;AAC7H,QAAM,SAA4B;AAAA,IAChC;AAAA,IACA,gBAAgB;AAAA,IAChB,OAAO;AAAA,MACL,OAAO,MAAM,oBAAoB,UAAU,SAAS,kCAAkC,KAAK;AAAA,MAC3F,QAAQ,MAAM,oBAAoB,UAAU,SAAS,mCAAmC,KAAK;AAAA,MAC7F,gBAAgB,MAAM,oBAAoB,UAAU,SAAS,2CAA2C,KAAK;AAAA,MAC7G,UAAU,MAAM,oBAAoB,UAAU,SAAS,qCAAqC,KAAK;AAAA,IACnG;AAAA,EACF;AAEA,MAAI,OAAO,MAAM,kBAAkB,CAAC,UAAU,OAAO,MAAM,cAAc,GAAG;AAC1E,WAAO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AAM,qBAAqB,UAAU,kBAAkB,KAAK;AAEtG,gBAAM,cAA6B;AAAA,YACjC,SAAS;AAAA,YACT;AAAA,YACA;AAAA,YACA,SAAS,QAAQ,MAAM,SAAS,WAAW,GAAG,OAAO;AAAA,YACrD;AAAA,YACA,QAAQ;AAAA,YACR;AAAA,UACF;AACA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT,SAAS,IAAI;AACX,YAAM,QAAQ;AACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAM,MAAM,OAAO,EAAE;AAC3D,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
package/dist/node/Witness.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
2
|
import { Erc1967Status } from './Payload';
|
|
3
3
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
4
4
|
export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema;
|
|
5
|
-
export type Erc1967WitnessConfig =
|
|
5
|
+
export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
6
6
|
address?: string;
|
|
7
7
|
}, Erc1967WitnessConfigSchema>;
|
|
8
|
-
export type Erc1967WitnessParams =
|
|
9
|
-
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends
|
|
8
|
+
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
|
+
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
10
|
static configSchemas: string[];
|
|
11
|
-
protected observeHandler(inPayloads?:
|
|
11
|
+
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAoB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAGxI,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,uCAAuC,CAAA;AAC9E,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,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
package/dist/node/Witness.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
2
|
import { Erc1967Status } from './Payload';
|
|
3
3
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
4
4
|
export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema;
|
|
5
|
-
export type Erc1967WitnessConfig =
|
|
5
|
+
export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
6
6
|
address?: string;
|
|
7
7
|
}, Erc1967WitnessConfigSchema>;
|
|
8
|
-
export type Erc1967WitnessParams =
|
|
9
|
-
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends
|
|
8
|
+
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
|
+
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
10
|
static configSchemas: string[];
|
|
11
|
-
protected observeHandler(inPayloads?:
|
|
11
|
+
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAoB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAGxI,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,uCAAuC,CAAA;AAC9E,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,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
package/dist/node/Witness.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
2
|
import { Erc1967Status } from './Payload';
|
|
3
3
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
4
4
|
export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema;
|
|
5
|
-
export type Erc1967WitnessConfig =
|
|
5
|
+
export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
6
6
|
address?: string;
|
|
7
7
|
}, Erc1967WitnessConfigSchema>;
|
|
8
|
-
export type Erc1967WitnessParams =
|
|
9
|
-
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends
|
|
8
|
+
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
|
+
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
10
|
static configSchemas: string[];
|
|
11
|
-
protected observeHandler(inPayloads?:
|
|
11
|
+
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAoB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAA;AAGxI,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,uCAAuC,CAAA;AAC9E,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,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -85,16 +85,16 @@ var Erc1967StatusSchema = "network.xyo.erc1967.status";
|
|
|
85
85
|
// src/Witness.ts
|
|
86
86
|
var import_assert = require("@xylabs/assert");
|
|
87
87
|
var import_payload_model = require("@xyo-network/payload-model");
|
|
88
|
-
var
|
|
88
|
+
var import_witness_evm_abstract = require("@xyo-network/witness-evm-abstract");
|
|
89
89
|
var Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
90
|
-
var Erc1967Witness = class extends
|
|
90
|
+
var Erc1967Witness = class extends import_witness_evm_abstract.AbstractEvmWitness {
|
|
91
91
|
static configSchemas = [Erc1967WitnessConfigSchema];
|
|
92
92
|
async observeHandler(inPayloads = []) {
|
|
93
93
|
await this.started("throw");
|
|
94
94
|
await this.getProviders();
|
|
95
95
|
try {
|
|
96
96
|
const observations = await Promise.all(
|
|
97
|
-
inPayloads.filter((0, import_payload_model.isPayloadOfSchemaType)(
|
|
97
|
+
inPayloads.filter((0, import_payload_model.isPayloadOfSchemaType)(import_witness_evm_abstract.EvmAddressSchema)).map(async ({ address }) => {
|
|
98
98
|
const validatedAddress = (0, import_assert.assertEx)(address ?? this.config.address, "Missing address").toLowerCase();
|
|
99
99
|
const provider = await this.getProvider(true, true);
|
|
100
100
|
const block = await provider.getBlockNumber();
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["export * from './lib'\nexport * from './Payload'\nexport * from './Witness'\n","import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50'\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143'\n\nexport interface Erc1967DataSlots {\n admin?: Address\n beacon?: Address\n implementation?: Address\n rollback?: Address\n}\n\nexport interface Erc1967SlotStatus {\n address: Address\n beacon?: {\n implementation?: Address\n }\n implementation: Address\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 hexFromHexString(slotValue, { prefix: true })\n } catch (ex) {\n return undefined\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')}`\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 } : {})\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 { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1967SlotStatus } from './lib'\n\nexport const Erc1967StatusSchema = 'network.xyo.erc1967.status'\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: Address\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/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["export * from './lib'\nexport * from './Payload'\nexport * from './Witness'\n","import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50'\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143'\n\nexport interface Erc1967DataSlots {\n admin?: Address\n beacon?: Address\n implementation?: Address\n rollback?: Address\n}\n\nexport interface Erc1967SlotStatus {\n address: Address\n beacon?: {\n implementation?: Address\n }\n implementation: Address\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 hexFromHexString(slotValue, { prefix: true })\n } catch (ex) {\n return undefined\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')}`\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 } : {})\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 { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1967SlotStatus } from './lib'\n\nexport const Erc1967StatusSchema = 'network.xyo.erc1967.status'\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: Address\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/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { AbstractEvmWitness, EvmAddress, EvmAddressSchema, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract'\n\nimport { getErc1967SlotStatus } from './lib'\nimport { Erc1967Status, Erc1967StatusSchema } from './Payload'\n\nexport const Erc1967WitnessConfigSchema = 'network.xyo.erc1967.witness.config'\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 configSchemas = [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 { beacon, implementation, slots } = 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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAqD;AACrD,qCAA2C;AAGpC,IAAM,4CAA4C;AAClD,IAAM,oCAAoC;AAC1C,IAAM,mCAAmC;AACzC,IAAM,sCAAsC;AAkBnD,IAAM,sBAAsB,OAAO,UAAoB,SAAiB,MAAc,UAAmB;AACvG,MAAI;AACF,UAAM,YAAY,MAAM,SAAS,WAAW,SAAS,MAAM,KAAK;AAChE,eAAO,6BAAiB,WAAW,EAAE,QAAQ,KAAK,CAAC;AAAA,EACrD,SAAS,IAAI;AACX,WAAO;AAAA,EACT;AACF;AAEO,IAAM,uBAAuB,OAAO,UAAoB,SAAiB,UAA+C;AAC7H,QAAM,SAA4B;AAAA,IAChC;AAAA,IACA,gBAAgB;AAAA,IAChB,OAAO;AAAA,MACL,OAAO,MAAM,oBAAoB,UAAU,SAAS,kCAAkC,KAAK;AAAA,MAC3F,QAAQ,MAAM,oBAAoB,UAAU,SAAS,mCAAmC,KAAK;AAAA,MAC7F,gBAAgB,MAAM,oBAAoB,UAAU,SAAS,2CAA2C,KAAK;AAAA,MAC7G,UAAU,MAAM,oBAAoB,UAAU,SAAS,qCAAq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I;AAElD,gBAAM,QAAQ,MAAM,SAAS,eAAe;AAE5C,gBAAM,EAAE,QAAQ,gBAAgB,MAAM,IAAI,MAAM,qBAAqB,UAAU,kBAAkB,KAAK;AAEtG,gBAAM,cAA6B;AAAA,YACjC,SAAS;AAAA,YACT;AAAA,YACA;AAAA,YACA,SAAS,QAAQ,MAAM,SAAS,WAAW,GAAG,OAAO;AAAA,YACrD;AAAA,YACA,QAAQ;AAAA,YACR;AAAA,UACF;AACA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT,SAAS,IAAI;AACX,YAAM,QAAQ;AACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAM,MAAM,OAAO,EAAE;AAC3D,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
package/dist/node/index.js
CHANGED
|
@@ -52,19 +52,16 @@ var Erc1967StatusSchema = "network.xyo.erc1967.status";
|
|
|
52
52
|
// src/Witness.ts
|
|
53
53
|
import { assertEx } from "@xylabs/assert";
|
|
54
54
|
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
55
|
-
import {
|
|
56
|
-
AbstractBlockchainWitness,
|
|
57
|
-
BlockchainAddressSchema
|
|
58
|
-
} from "@xyo-network/witness-blockchain-abstract";
|
|
55
|
+
import { AbstractEvmWitness, EvmAddressSchema } from "@xyo-network/witness-evm-abstract";
|
|
59
56
|
var Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
60
|
-
var Erc1967Witness = class extends
|
|
57
|
+
var Erc1967Witness = class extends AbstractEvmWitness {
|
|
61
58
|
static configSchemas = [Erc1967WitnessConfigSchema];
|
|
62
59
|
async observeHandler(inPayloads = []) {
|
|
63
60
|
await this.started("throw");
|
|
64
61
|
await this.getProviders();
|
|
65
62
|
try {
|
|
66
63
|
const observations = await Promise.all(
|
|
67
|
-
inPayloads.filter(isPayloadOfSchemaType(
|
|
64
|
+
inPayloads.filter(isPayloadOfSchemaType(EvmAddressSchema)).map(async ({ address }) => {
|
|
68
65
|
const validatedAddress = assertEx(address ?? this.config.address, "Missing address").toLowerCase();
|
|
69
66
|
const provider = await this.getProvider(true, true);
|
|
70
67
|
const block = await provider.getBlockNumber();
|
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50'\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143'\n\nexport interface Erc1967DataSlots {\n admin?: Address\n beacon?: Address\n implementation?: Address\n rollback?: Address\n}\n\nexport interface Erc1967SlotStatus {\n address: Address\n beacon?: {\n implementation?: Address\n }\n implementation: Address\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 hexFromHexString(slotValue, { prefix: true })\n } catch (ex) {\n return undefined\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')}`\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 } : {})\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 { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1967SlotStatus } from './lib'\n\nexport const Erc1967StatusSchema = 'network.xyo.erc1967.status'\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: Address\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/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/lib/getErc1967SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { UpgradeableBeacon__factory } from '@xyo-network/open-zeppelin-typechain'\nimport { Provider } from 'ethers'\n\nexport const ERC1967_PROXY_IMPLEMENTATION_STORAGE_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'\nexport const ERC1967_PROXY_BEACON_STORAGE_SLOT = '0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50'\nexport const ERC1967_PROXY_ADMIN_STORAGE_SLOT = '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'\nexport const ERC1967_PROXY_ROLLBACK_STORAGE_SLOT = '0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143'\n\nexport interface Erc1967DataSlots {\n admin?: Address\n beacon?: Address\n implementation?: Address\n rollback?: Address\n}\n\nexport interface Erc1967SlotStatus {\n address: Address\n beacon?: {\n implementation?: Address\n }\n implementation: Address\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 hexFromHexString(slotValue, { prefix: true })\n } catch (ex) {\n return undefined\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')}`\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 } : {})\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 { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1967SlotStatus } from './lib'\n\nexport const Erc1967StatusSchema = 'network.xyo.erc1967.status'\nexport type Erc1967StatusSchema = typeof Erc1967StatusSchema\n\nexport type Erc1967Status = Payload<\n {\n address: Address\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/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport { AbstractEvmWitness, EvmAddress, EvmAddressSchema, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract'\n\nimport { getErc1967SlotStatus } from './lib'\nimport { Erc1967Status, Erc1967StatusSchema } from './Payload'\n\nexport const Erc1967WitnessConfigSchema = 'network.xyo.erc1967.witness.config'\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 configSchemas = [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 { beacon, implementation, slots } = 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":";AAAA,SAAkB,kBAAkB,iBAAiB;AACrD,SAAS,kCAAkC;AAGpC,IAAM,4CAA4C;AAClD,IAAM,oCAAoC;AAC1C,IAAM,mCAAmC;AACzC,IAAM,sCAAsC;AAkBnD,IAAM,sBAAsB,OAAO,UAAoB,SAAiB,MAAc,UAAmB;AACvG,MAAI;AACF,UAAM,YAAY,MAAM,SAAS,WAAW,SAAS,MAAM,KAAK;AAChE,WAAO,iBAAiB,WAAW,EAAE,QAAQ,KAAK,CAAC;AAAA,EACrD,SAAS,IAAI;AACX,WAAO;AAAA,EACT;AACF;AAEO,IAAM,uBAAuB,OAAO,UAAoB,SAAiB,UAA+C;AAC7H,QAAM,SAA4B;AAAA,IAChC;AAAA,IACA,gBAAgB;AAAA,IAChB,OAAO;AAAA,MACL,OAAO,MAAM,oBAAoB,UAAU,SAAS,kCAAkC,KAAK;AAAA,MAC3F,QAAQ,MAAM,oBAAoB,UAAU,SAAS,mCAAmC,KAAK;AAAA,MAC7F,gBAAgB,MAAM,oBAAoB,UAAU,SAAS,2CAA2C,KAAK;AAAA,MAC7G,UAAU,MAAM,oBAAoB,UAAU,SAAS,qCAAqC,KAAK;AAAA,IACnG;AAAA,EACF;AAEA,MAAI,OAAO,MAAM,kBAAkB,CAAC,UAAU,OAAO,MAAM,cAAc,GAAG;AAC1E,WAAO,iBAAiB,KAAK,OAAO,OAAO,MAAM,cAAwB,EACtE,SAAS,EAAE,EACX,SAAS,IAAI,GAAG,CAAC;AAAA,EACtB,OAAO;AACL,QAAI,OAAO,MAAM,UAAU,CAAC,UAAU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AO;AAAA,YACrD;AAAA,YACA,QAAQ;AAAA,YACR;AAAA,UACF;AACA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO;AAAA,IACT,SAAS,IAAI;AACX,YAAM,QAAQ;AACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAM,MAAM,OAAO,EAAE;AAC3D,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"@xylabs/assert": "^2.13.20",
|
|
14
14
|
"@xylabs/hex": "^2.13.20",
|
|
15
15
|
"@xyo-network/open-zeppelin-typechain": "^3.0.5",
|
|
16
|
-
"@xyo-network/payload-model": "^2.84.
|
|
17
|
-
"@xyo-network/witness-blockchain-abstract": "^2.84.
|
|
16
|
+
"@xyo-network/payload-model": "^2.84.13",
|
|
17
|
+
"@xyo-network/witness-blockchain-abstract": "^2.84.13"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@xylabs/jest-helpers": "^2.13.20",
|
|
21
|
-
"@xylabs/ts-scripts-yarn3": "^3.2.
|
|
22
|
-
"@xylabs/tsconfig": "^3.2.
|
|
23
|
-
"ethers": "^6.9.
|
|
21
|
+
"@xylabs/ts-scripts-yarn3": "^3.2.25",
|
|
22
|
+
"@xylabs/tsconfig": "^3.2.25",
|
|
23
|
+
"ethers": "^6.9.1",
|
|
24
24
|
"jest": "^29.7.0",
|
|
25
25
|
"typescript": "^5.3.3"
|
|
26
26
|
},
|
|
@@ -63,6 +63,6 @@
|
|
|
63
63
|
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
64
64
|
},
|
|
65
65
|
"sideEffects": false,
|
|
66
|
-
"version": "2.84.
|
|
66
|
+
"version": "2.84.4",
|
|
67
67
|
"type": "module"
|
|
68
68
|
}
|
package/src/Witness.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
2
|
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
3
|
-
import {
|
|
4
|
-
AbstractBlockchainWitness,
|
|
5
|
-
BlockchainAddress,
|
|
6
|
-
BlockchainAddressSchema,
|
|
7
|
-
BlockchainWitnessConfig,
|
|
8
|
-
BlockchainWitnessParams,
|
|
9
|
-
} from '@xyo-network/witness-blockchain-abstract'
|
|
3
|
+
import { AbstractEvmWitness, EvmAddress, EvmAddressSchema, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract'
|
|
10
4
|
|
|
11
5
|
import { getErc1967SlotStatus } from './lib'
|
|
12
6
|
import { Erc1967Status, Erc1967StatusSchema } from './Payload'
|
|
@@ -14,24 +8,24 @@ import { Erc1967Status, Erc1967StatusSchema } from './Payload'
|
|
|
14
8
|
export const Erc1967WitnessConfigSchema = 'network.xyo.erc1967.witness.config'
|
|
15
9
|
export type Erc1967WitnessConfigSchema = typeof Erc1967WitnessConfigSchema
|
|
16
10
|
|
|
17
|
-
export type Erc1967WitnessConfig =
|
|
11
|
+
export type Erc1967WitnessConfig = EvmWitnessConfig<{ address?: string }, Erc1967WitnessConfigSchema>
|
|
18
12
|
|
|
19
|
-
export type Erc1967WitnessParams =
|
|
13
|
+
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>
|
|
20
14
|
|
|
21
|
-
export class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends
|
|
15
|
+
export class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<
|
|
22
16
|
TParams,
|
|
23
|
-
|
|
17
|
+
EvmAddress,
|
|
24
18
|
Erc1967Status
|
|
25
19
|
> {
|
|
26
20
|
static override configSchemas = [Erc1967WitnessConfigSchema]
|
|
27
21
|
|
|
28
|
-
protected override async observeHandler(inPayloads:
|
|
22
|
+
protected override async observeHandler(inPayloads: EvmAddress[] = []): Promise<Erc1967Status[]> {
|
|
29
23
|
await this.started('throw')
|
|
30
24
|
//calling it here to make sure we rests the cache
|
|
31
25
|
await this.getProviders()
|
|
32
26
|
try {
|
|
33
27
|
const observations = await Promise.all(
|
|
34
|
-
inPayloads.filter(isPayloadOfSchemaType<
|
|
28
|
+
inPayloads.filter(isPayloadOfSchemaType<EvmAddress>(EvmAddressSchema)).map(async ({ address }) => {
|
|
35
29
|
const validatedAddress = assertEx(address ?? this.config.address, 'Missing address').toLowerCase()
|
|
36
30
|
|
|
37
31
|
const provider = await this.getProvider(true, true)
|