@xyo-network/erc1967-witness 2.92.1 → 2.93.0
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 +3 -1
- package/dist/browser/Witness.d.cts.map +1 -1
- package/dist/browser/Witness.d.mts +3 -1
- package/dist/browser/Witness.d.mts.map +1 -1
- package/dist/browser/Witness.d.ts +3 -1
- package/dist/browser/Witness.d.ts.map +1 -1
- package/dist/browser/index.cjs +2 -1
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +2 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/node/Witness.d.cts +3 -1
- package/dist/node/Witness.d.cts.map +1 -1
- package/dist/node/Witness.d.mts +3 -1
- package/dist/node/Witness.d.mts.map +1 -1
- package/dist/node/Witness.d.ts +3 -1
- package/dist/node/Witness.d.ts.map +1 -1
- package/dist/node/index.cjs +2 -1
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +2 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +8 -8
- package/src/Witness.ts +3 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Schema } from '@xyo-network/payload-model';
|
|
1
2
|
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
3
|
import { Erc1967Status } from './Payload';
|
|
3
4
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
@@ -7,7 +8,8 @@ export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
|
7
8
|
}, Erc1967WitnessConfigSchema>;
|
|
8
9
|
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
10
|
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
|
-
static configSchemas:
|
|
11
|
+
static configSchemas: Schema[];
|
|
12
|
+
static defaultConfigSchema: Schema;
|
|
11
13
|
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAC1E,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,EAAE,MAAM,EAAE,CAAuD;IAC9F,OAAgB,mBAAmB,EAAE,MAAM,CAA6B;cAE/C,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Schema } from '@xyo-network/payload-model';
|
|
1
2
|
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
3
|
import { Erc1967Status } from './Payload';
|
|
3
4
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
@@ -7,7 +8,8 @@ export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
|
7
8
|
}, Erc1967WitnessConfigSchema>;
|
|
8
9
|
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
10
|
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
|
-
static configSchemas:
|
|
11
|
+
static configSchemas: Schema[];
|
|
12
|
+
static defaultConfigSchema: Schema;
|
|
11
13
|
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAC1E,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,EAAE,MAAM,EAAE,CAAuD;IAC9F,OAAgB,mBAAmB,EAAE,MAAM,CAA6B;cAE/C,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Schema } from '@xyo-network/payload-model';
|
|
1
2
|
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
3
|
import { Erc1967Status } from './Payload';
|
|
3
4
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
@@ -7,7 +8,8 @@ export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
|
7
8
|
}, Erc1967WitnessConfigSchema>;
|
|
8
9
|
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
10
|
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
|
-
static configSchemas:
|
|
11
|
+
static configSchemas: Schema[];
|
|
12
|
+
static defaultConfigSchema: Schema;
|
|
11
13
|
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAC1E,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,EAAE,MAAM,EAAE,CAAuD;IAC9F,OAAgB,mBAAmB,EAAE,MAAM,CAA6B;cAE/C,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -88,7 +88,8 @@ var import_payload_model = require("@xyo-network/payload-model");
|
|
|
88
88
|
var import_witness_evm_abstract = require("@xyo-network/witness-evm-abstract");
|
|
89
89
|
var Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
90
90
|
var Erc1967Witness = class extends import_witness_evm_abstract.AbstractEvmWitness {
|
|
91
|
-
static configSchemas = [Erc1967WitnessConfigSchema];
|
|
91
|
+
static configSchemas = [...super.configSchemas, Erc1967WitnessConfigSchema];
|
|
92
|
+
static defaultConfigSchema = Erc1967WitnessConfigSchema;
|
|
92
93
|
async observeHandler(inPayloads = []) {
|
|
93
94
|
await this.started("throw");
|
|
94
95
|
await this.getProviders();
|
|
@@ -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 type { 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: 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 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 { 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: 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/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,QAAQ;AACN;AAAA,EACF;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,KAAC,sBAAU,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,KAAC,sBAAU,OAAO,MAAM,MAAM,GAAG;AAC1D,YAAM,SAAS,0DAA2B,QAAQ,OAAO,MAAM,QAAkB,EAAE,SAAS,CAAC;AAC7F,UAAI;AACF,cAAM,iBAAkB,MAAM,OAAO,eAAe,QAAQ,EAAE,UAAU,MAAM,IAAI,CAAC,CAAC;AACpF,YAAI,gBAAgB;AAClB,iBAAO,SAAS,EAAE,eAAe;AACjC,cAAI,KAAC,sBAAU,cAAc,GAAG;AAC9B,mBAAO,iBAAiB;AAAA,UAC1B;AAAA,QACF;AAAA,MACF,SAAS,IAAI;AACX,cAAM,QAAQ;AACd,gBAAQ,IAAI,MAAM,OAAO;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;;;ACjEO,IAAM,sBAAsB;;;ACJnC,oBAAyB;AACzB,
|
|
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 type { 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: 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 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 { 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: 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/assert'\nimport { isPayloadOfSchemaType, Schema } 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: Schema[] = [...super.configSchemas, Erc1967WitnessConfigSchema]\n static override 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 { 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,QAAQ;AACN;AAAA,EACF;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,KAAC,sBAAU,OAAO,MAAM,cAAc,GAAG;AAC1E,WAAO,iBAAiB,KAAK,OAAO,OAAO,MAAM,cAAwB,EACtE,SAAS,EAAE,EACX,SAAS,IAAI,GAAG,CAAC;AAAA,E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ACjC,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
|
@@ -55,7 +55,8 @@ import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
|
55
55
|
import { AbstractEvmWitness, EvmAddressSchema } from "@xyo-network/witness-evm-abstract";
|
|
56
56
|
var Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
57
57
|
var Erc1967Witness = class extends AbstractEvmWitness {
|
|
58
|
-
static configSchemas = [Erc1967WitnessConfigSchema];
|
|
58
|
+
static configSchemas = [...super.configSchemas, Erc1967WitnessConfigSchema];
|
|
59
|
+
static defaultConfigSchema = Erc1967WitnessConfigSchema;
|
|
59
60
|
async observeHandler(inPayloads = []) {
|
|
60
61
|
await this.started("throw");
|
|
61
62
|
await this.getProviders();
|
|
@@ -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 type { 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: 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 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 { 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: 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/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,QAAQ;AACN;AAAA,EACF;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,OAAO,MAAM,MAAM,GAAG;AAC1D,YAAM,SAAS,2BAA2B,QAAQ,OAAO,MAAM,QAAkB,EAAE,SAAS,CAAC;AAC7F,UAAI;AACF,cAAM,iBAAkB,MAAM,OAAO,eAAe,QAAQ,EAAE,UAAU,MAAM,IAAI,CAAC,CAAC;AACpF,YAAI,gBAAgB;AAClB,iBAAO,SAAS,EAAE,eAAe;AACjC,cAAI,CAAC,UAAU,cAAc,GAAG;AAC9B,mBAAO,iBAAiB;AAAA,UAC1B;AAAA,QACF;AAAA,MACF,SAAS,IAAI;AACX,cAAM,QAAQ;AACd,gBAAQ,IAAI,MAAM,OAAO;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;;;ACjEO,IAAM,sBAAsB;;;ACJnC,SAAS,gBAAgB;AACzB,SAAS,
|
|
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 type { 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: 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 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 { 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: 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/assert'\nimport { isPayloadOfSchemaType, Schema } 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: Schema[] = [...super.configSchemas, Erc1967WitnessConfigSchema]\n static override 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 { 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;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oBAAgC,wBAA4D;AAK9F,IAAM,6BAA6B;AAOnC,IAAM,iBAAN,cAA0F,mBAI/F;AAAA,EACA,OAAgB,gBAA0B,CAAC,GAAG,MAAM,eAAe,0BAA0B;AAAA,EAC7F,OAAgB,sBAA8B;AAAA,EAE9C,MAAyB,eAAe,aAA2B,CAAC,GAA6B;AAC/F,UAAM,KAAK,QAAQ,OAAO;AAE1B,UAAM,KAAK,aAAa;AACxB,QAAI;AACF,YAAM,eAAe,MAAM,QAAQ;AAAA,QACjC,WAAW,OAAO,sBAAkC,gBAAgB,CAAC,EAAE,IAAI,OAAO,EAAE,QAAQ,MAAM;AAChG,gBAAM,mBAAmB,SAAS,WAAW,KAAK,OAAO,SAAS,MAAM,iBAAiB,EAAE,YAAY;AAEvG,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/node/Witness.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Schema } from '@xyo-network/payload-model';
|
|
1
2
|
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
3
|
import { Erc1967Status } from './Payload';
|
|
3
4
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
@@ -7,7 +8,8 @@ export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
|
7
8
|
}, Erc1967WitnessConfigSchema>;
|
|
8
9
|
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
10
|
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
|
-
static configSchemas:
|
|
11
|
+
static configSchemas: Schema[];
|
|
12
|
+
static defaultConfigSchema: Schema;
|
|
11
13
|
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAC1E,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,EAAE,MAAM,EAAE,CAAuD;IAC9F,OAAgB,mBAAmB,EAAE,MAAM,CAA6B;cAE/C,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
package/dist/node/Witness.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Schema } from '@xyo-network/payload-model';
|
|
1
2
|
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
3
|
import { Erc1967Status } from './Payload';
|
|
3
4
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
@@ -7,7 +8,8 @@ export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
|
7
8
|
}, Erc1967WitnessConfigSchema>;
|
|
8
9
|
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
10
|
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
|
-
static configSchemas:
|
|
11
|
+
static configSchemas: Schema[];
|
|
12
|
+
static defaultConfigSchema: Schema;
|
|
11
13
|
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAC1E,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,EAAE,MAAM,EAAE,CAAuD;IAC9F,OAAgB,mBAAmB,EAAE,MAAM,CAA6B;cAE/C,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
package/dist/node/Witness.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Schema } from '@xyo-network/payload-model';
|
|
1
2
|
import { AbstractEvmWitness, EvmAddress, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract';
|
|
2
3
|
import { Erc1967Status } from './Payload';
|
|
3
4
|
export declare const Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
@@ -7,7 +8,8 @@ export type Erc1967WitnessConfig = EvmWitnessConfig<{
|
|
|
7
8
|
}, Erc1967WitnessConfigSchema>;
|
|
8
9
|
export type Erc1967WitnessParams = EvmWitnessParams<Erc1967WitnessConfig>;
|
|
9
10
|
export declare class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967WitnessParams> extends AbstractEvmWitness<TParams, EvmAddress, Erc1967Status> {
|
|
10
|
-
static configSchemas:
|
|
11
|
+
static configSchemas: Schema[];
|
|
12
|
+
static defaultConfigSchema: Schema;
|
|
11
13
|
protected observeHandler(inPayloads?: EvmAddress[]): Promise<Erc1967Status[]>;
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAC1E,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,EAAE,MAAM,EAAE,CAAuD;IAC9F,OAAgB,mBAAmB,EAAE,MAAM,CAA6B;cAE/C,cAAc,CAAC,UAAU,GAAE,UAAU,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAkCjG"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -88,7 +88,8 @@ var import_payload_model = require("@xyo-network/payload-model");
|
|
|
88
88
|
var import_witness_evm_abstract = require("@xyo-network/witness-evm-abstract");
|
|
89
89
|
var Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
90
90
|
var Erc1967Witness = class extends import_witness_evm_abstract.AbstractEvmWitness {
|
|
91
|
-
static configSchemas = [Erc1967WitnessConfigSchema];
|
|
91
|
+
static configSchemas = [...super.configSchemas, Erc1967WitnessConfigSchema];
|
|
92
|
+
static defaultConfigSchema = Erc1967WitnessConfigSchema;
|
|
92
93
|
async observeHandler(inPayloads = []) {
|
|
93
94
|
await this.started("throw");
|
|
94
95
|
await this.getProviders();
|
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 type { 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: 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 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 { 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: 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/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,UAA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IAAM,sBAAsB;;;ACJnC,oBAAyB;AACzB,
|
|
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 type { 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: 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 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 { 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: 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/assert'\nimport { isPayloadOfSchemaType, Schema } 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: Schema[] = [...super.configSchemas, Erc1967WitnessConfigSchema]\n static override 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 { 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,QAAQ;AACN;AAAA,EACF;AACF;AAEO,IAAM,uBAAuB,OAAO,UAAoB,SAAiB,UAA+C;AAC7H,QAAM,SAA4B;AAAA,IAChC;AAAA,IACA,gBAAgB;AAAA,IAChB,OAAO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AQ,OAAO;AAE1B,UAAM,KAAK,aAAa;AACxB,QAAI;AACF,YAAM,eAAe,MAAM,QAAQ;AAAA,QACjC,WAAW,WAAO,4CAAkC,4CAAgB,CAAC,EAAE,IAAI,OAAO,EAAE,QAAQ,MAAM;AAChG,gBAAM,uBAAmB,wBAAS,WAAW,KAAK,OAAO,SAAS,MAAM,iBAAiB,EAAE,YAAY;AAEvG,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/node/index.js
CHANGED
|
@@ -55,7 +55,8 @@ import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
|
55
55
|
import { AbstractEvmWitness, EvmAddressSchema } from "@xyo-network/witness-evm-abstract";
|
|
56
56
|
var Erc1967WitnessConfigSchema = "network.xyo.erc1967.witness.config";
|
|
57
57
|
var Erc1967Witness = class extends AbstractEvmWitness {
|
|
58
|
-
static configSchemas = [Erc1967WitnessConfigSchema];
|
|
58
|
+
static configSchemas = [...super.configSchemas, Erc1967WitnessConfigSchema];
|
|
59
|
+
static defaultConfigSchema = Erc1967WitnessConfigSchema;
|
|
59
60
|
async observeHandler(inPayloads = []) {
|
|
60
61
|
await this.started("throw");
|
|
61
62
|
await this.getProviders();
|
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 type { 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: 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 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 { 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: 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/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,QAAQ;AACN;AAAA,EACF;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,OAAO,MAAM,MAAM,GAAG;AAC1D,YAAM,SAAS,2BAA2B,QAAQ,OAAO,MAAM,QAAkB,EAAE,SAAS,CAAC;AAC7F,UAAI;AACF,cAAM,iBAAkB,MAAM,OAAO,eAAe,QAAQ,EAAE,UAAU,MAAM,IAAI,CAAC,CAAC;AACpF,YAAI,gBAAgB;AAClB,iBAAO,SAAS,EAAE,eAAe;AACjC,cAAI,CAAC,UAAU,cAAc,GAAG;AAC9B,mBAAO,iBAAiB;AAAA,UAC1B;AAAA,QACF;AAAA,MACF,SAAS,IAAI;AACX,cAAM,QAAQ;AACd,gBAAQ,IAAI,MAAM,OAAO;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;;;ACjEO,IAAM,sBAAsB;;;ACJnC,SAAS,gBAAgB;AACzB,SAAS,
|
|
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 type { 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: 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 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 { 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: 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/assert'\nimport { isPayloadOfSchemaType, Schema } 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: Schema[] = [...super.configSchemas, Erc1967WitnessConfigSchema]\n static override 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 { 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,QAAQ;AACN;AAAA,EACF;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,OAAO,MAAM,MAAM,GAAG;AAC1D,YAAM,SAAS,2BAA2B,QAAQ,OAAO,M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rD;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
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/plugins/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/assert": "^3.1.
|
|
14
|
-
"@xylabs/hex": "^3.1.
|
|
13
|
+
"@xylabs/assert": "^3.1.8",
|
|
14
|
+
"@xylabs/hex": "^3.1.8",
|
|
15
15
|
"@xyo-network/open-zeppelin-typechain": "^3.0.5",
|
|
16
|
-
"@xyo-network/payload-model": "^2.
|
|
17
|
-
"@xyo-network/witness-evm-abstract": "^2.
|
|
16
|
+
"@xyo-network/payload-model": "^2.97.0",
|
|
17
|
+
"@xyo-network/witness-evm-abstract": "^2.97.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@xylabs/jest-helpers": "^3.1.
|
|
21
|
-
"@xylabs/ts-scripts-yarn3": "^3.9.
|
|
22
|
-
"@xylabs/tsconfig": "^3.9.
|
|
20
|
+
"@xylabs/jest-helpers": "^3.1.8",
|
|
21
|
+
"@xylabs/ts-scripts-yarn3": "^3.9.1",
|
|
22
|
+
"@xylabs/tsconfig": "^3.9.1",
|
|
23
23
|
"ethers": "^6.12.0",
|
|
24
24
|
"jest": "^29.7.0",
|
|
25
25
|
"typescript": "^5.4.5"
|
|
@@ -63,6 +63,6 @@
|
|
|
63
63
|
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
64
64
|
},
|
|
65
65
|
"sideEffects": false,
|
|
66
|
-
"version": "2.
|
|
66
|
+
"version": "2.93.0",
|
|
67
67
|
"type": "module"
|
|
68
68
|
}
|
package/src/Witness.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertEx } from '@xylabs/assert'
|
|
2
|
-
import { isPayloadOfSchemaType } from '@xyo-network/payload-model'
|
|
2
|
+
import { isPayloadOfSchemaType, Schema } from '@xyo-network/payload-model'
|
|
3
3
|
import { AbstractEvmWitness, EvmAddress, EvmAddressSchema, EvmWitnessConfig, EvmWitnessParams } from '@xyo-network/witness-evm-abstract'
|
|
4
4
|
|
|
5
5
|
import { getErc1967SlotStatus } from './lib'
|
|
@@ -17,7 +17,8 @@ export class Erc1967Witness<TParams extends Erc1967WitnessParams = Erc1967Witnes
|
|
|
17
17
|
EvmAddress,
|
|
18
18
|
Erc1967Status
|
|
19
19
|
> {
|
|
20
|
-
static override configSchemas = [Erc1967WitnessConfigSchema]
|
|
20
|
+
static override configSchemas: Schema[] = [...super.configSchemas, Erc1967WitnessConfigSchema]
|
|
21
|
+
static override defaultConfigSchema: Schema = Erc1967WitnessConfigSchema
|
|
21
22
|
|
|
22
23
|
protected override async observeHandler(inPayloads: EvmAddress[] = []): Promise<Erc1967Status[]> {
|
|
23
24
|
await this.started('throw')
|