@xyo-network/erc1822-witness 2.84.1
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/LICENSE +165 -0
- package/README.md +13 -0
- package/dist/browser/Payload.d.cts +13 -0
- package/dist/browser/Payload.d.cts.map +1 -0
- package/dist/browser/Payload.d.mts +13 -0
- package/dist/browser/Payload.d.mts.map +1 -0
- package/dist/browser/Payload.d.ts +13 -0
- package/dist/browser/Payload.d.ts.map +1 -0
- package/dist/browser/Witness.d.cts +13 -0
- package/dist/browser/Witness.d.cts.map +1 -0
- package/dist/browser/Witness.d.mts +13 -0
- package/dist/browser/Witness.d.mts.map +1 -0
- package/dist/browser/Witness.d.ts +13 -0
- package/dist/browser/Witness.d.ts.map +1 -0
- package/dist/browser/index.cjs +95 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +4 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.d.mts +4 -0
- package/dist/browser/index.d.mts.map +1 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +75 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/lib/getErc1822SlotStatus.d.cts +13 -0
- package/dist/browser/lib/getErc1822SlotStatus.d.cts.map +1 -0
- package/dist/browser/lib/getErc1822SlotStatus.d.mts +13 -0
- package/dist/browser/lib/getErc1822SlotStatus.d.mts.map +1 -0
- package/dist/browser/lib/getErc1822SlotStatus.d.ts +13 -0
- package/dist/browser/lib/getErc1822SlotStatus.d.ts.map +1 -0
- package/dist/browser/lib/index.d.cts +2 -0
- package/dist/browser/lib/index.d.cts.map +1 -0
- package/dist/browser/lib/index.d.mts +2 -0
- package/dist/browser/lib/index.d.mts.map +1 -0
- package/dist/browser/lib/index.d.ts +2 -0
- package/dist/browser/lib/index.d.ts.map +1 -0
- package/dist/node/Payload.d.cts +13 -0
- package/dist/node/Payload.d.cts.map +1 -0
- package/dist/node/Payload.d.mts +13 -0
- package/dist/node/Payload.d.mts.map +1 -0
- package/dist/node/Payload.d.ts +13 -0
- package/dist/node/Payload.d.ts.map +1 -0
- package/dist/node/Witness.d.cts +13 -0
- package/dist/node/Witness.d.cts.map +1 -0
- package/dist/node/Witness.d.mts +13 -0
- package/dist/node/Witness.d.mts.map +1 -0
- package/dist/node/Witness.d.ts +13 -0
- package/dist/node/Witness.d.ts.map +1 -0
- package/dist/node/index.cjs +103 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +4 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.mts +4 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +75 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/lib/getErc1822SlotStatus.d.cts +13 -0
- package/dist/node/lib/getErc1822SlotStatus.d.cts.map +1 -0
- package/dist/node/lib/getErc1822SlotStatus.d.mts +13 -0
- package/dist/node/lib/getErc1822SlotStatus.d.mts.map +1 -0
- package/dist/node/lib/getErc1822SlotStatus.d.ts +13 -0
- package/dist/node/lib/getErc1822SlotStatus.d.ts.map +1 -0
- package/dist/node/lib/index.d.cts +2 -0
- package/dist/node/lib/index.d.cts.map +1 -0
- package/dist/node/lib/index.d.mts +2 -0
- package/dist/node/lib/index.d.mts.map +1 -0
- package/dist/node/lib/index.d.ts +2 -0
- package/dist/node/lib/index.d.ts.map +1 -0
- package/package.json +67 -0
- package/src/Payload.ts +18 -0
- package/src/Witness.ts +61 -0
- package/src/index.ts +3 -0
- package/src/lib/getErc1822SlotStatus.ts +39 -0
- package/src/lib/index.ts +1 -0
- package/typedoc.json +5 -0
- package/xy.config.ts +14 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAEzC,eAAO,MAAM,mBAAmB,+BAA+B,CAAA;AAC/D,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D,MAAM,MAAM,aAAa,GAAG,OAAO,CACjC;IACE,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAA;IACpD,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAA;CACnC,EACD,mBAAmB,CACpB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Address } from '@xylabs/hex';
|
|
2
|
+
import { Payload } from '@xyo-network/payload-model';
|
|
3
|
+
import { Erc1822SlotStatus } from './lib';
|
|
4
|
+
export declare const Erc1822StatusSchema = "network.xyo.erc1822.status";
|
|
5
|
+
export type Erc1822StatusSchema = typeof Erc1822StatusSchema;
|
|
6
|
+
export type Erc1822Status = Payload<{
|
|
7
|
+
address: Address;
|
|
8
|
+
block: number;
|
|
9
|
+
chainId: number;
|
|
10
|
+
implementation?: Erc1822SlotStatus['implementation'];
|
|
11
|
+
slots?: Erc1822SlotStatus['slots'];
|
|
12
|
+
}, Erc1822StatusSchema>;
|
|
13
|
+
//# sourceMappingURL=Payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Payload.d.ts","sourceRoot":"","sources":["../../src/Payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAEzC,eAAO,MAAM,mBAAmB,+BAA+B,CAAA;AAC/D,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D,MAAM,MAAM,aAAa,GAAG,OAAO,CACjC;IACE,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAA;IACpD,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAA;CACnC,EACD,mBAAmB,CACpB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractBlockchainWitness, BlockchainAddress, BlockchainWitnessConfig, BlockchainWitnessParams } from '@xyo-network/witness-blockchain-abstract';
|
|
2
|
+
import { Erc1822Status } from './Payload';
|
|
3
|
+
export declare const Erc1822WitnessConfigSchema = "network.xyo.blockchain.Erc1822.witness.config";
|
|
4
|
+
export type Erc1822WitnessConfigSchema = typeof Erc1822WitnessConfigSchema;
|
|
5
|
+
export type Erc1822WitnessConfig = BlockchainWitnessConfig<{
|
|
6
|
+
address?: string;
|
|
7
|
+
}, Erc1822WitnessConfigSchema>;
|
|
8
|
+
export type Erc1822WitnessParams = BlockchainWitnessParams<Erc1822WitnessConfig>;
|
|
9
|
+
export declare class Erc1822Witness<TParams extends Erc1822WitnessParams = Erc1822WitnessParams> extends AbstractBlockchainWitness<TParams, BlockchainAddress, Erc1822Status> {
|
|
10
|
+
static configSchemas: string[];
|
|
11
|
+
protected observeHandler(inPayloads?: BlockchainAddress[]): Promise<Erc1822Status[]>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EAEjB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,0CAA0C,CAAA;AAGjD,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,kDAAkD,CAAA;AACzF,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAA;AAE1E,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,0BAA0B,CAAC,CAAA;AAE5G,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC,oBAAoB,CAAC,CAAA;AAEhF,qBAAa,cAAc,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,yBAAyB,CACxH,OAAO,EACP,iBAAiB,EACjB,aAAa,CACd;IACC,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,iBAAiB,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAiCxG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractBlockchainWitness, BlockchainAddress, BlockchainWitnessConfig, BlockchainWitnessParams } from '@xyo-network/witness-blockchain-abstract';
|
|
2
|
+
import { Erc1822Status } from './Payload';
|
|
3
|
+
export declare const Erc1822WitnessConfigSchema = "network.xyo.blockchain.Erc1822.witness.config";
|
|
4
|
+
export type Erc1822WitnessConfigSchema = typeof Erc1822WitnessConfigSchema;
|
|
5
|
+
export type Erc1822WitnessConfig = BlockchainWitnessConfig<{
|
|
6
|
+
address?: string;
|
|
7
|
+
}, Erc1822WitnessConfigSchema>;
|
|
8
|
+
export type Erc1822WitnessParams = BlockchainWitnessParams<Erc1822WitnessConfig>;
|
|
9
|
+
export declare class Erc1822Witness<TParams extends Erc1822WitnessParams = Erc1822WitnessParams> extends AbstractBlockchainWitness<TParams, BlockchainAddress, Erc1822Status> {
|
|
10
|
+
static configSchemas: string[];
|
|
11
|
+
protected observeHandler(inPayloads?: BlockchainAddress[]): Promise<Erc1822Status[]>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EAEjB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,0CAA0C,CAAA;AAGjD,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,kDAAkD,CAAA;AACzF,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAA;AAE1E,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,0BAA0B,CAAC,CAAA;AAE5G,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC,oBAAoB,CAAC,CAAA;AAEhF,qBAAa,cAAc,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,yBAAyB,CACxH,OAAO,EACP,iBAAiB,EACjB,aAAa,CACd;IACC,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,iBAAiB,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAiCxG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AbstractBlockchainWitness, BlockchainAddress, BlockchainWitnessConfig, BlockchainWitnessParams } from '@xyo-network/witness-blockchain-abstract';
|
|
2
|
+
import { Erc1822Status } from './Payload';
|
|
3
|
+
export declare const Erc1822WitnessConfigSchema = "network.xyo.blockchain.Erc1822.witness.config";
|
|
4
|
+
export type Erc1822WitnessConfigSchema = typeof Erc1822WitnessConfigSchema;
|
|
5
|
+
export type Erc1822WitnessConfig = BlockchainWitnessConfig<{
|
|
6
|
+
address?: string;
|
|
7
|
+
}, Erc1822WitnessConfigSchema>;
|
|
8
|
+
export type Erc1822WitnessParams = BlockchainWitnessParams<Erc1822WitnessConfig>;
|
|
9
|
+
export declare class Erc1822Witness<TParams extends Erc1822WitnessParams = Erc1822WitnessParams> extends AbstractBlockchainWitness<TParams, BlockchainAddress, Erc1822Status> {
|
|
10
|
+
static configSchemas: string[];
|
|
11
|
+
protected observeHandler(inPayloads?: BlockchainAddress[]): Promise<Erc1822Status[]>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EAEjB,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,0CAA0C,CAAA;AAGjD,OAAO,EAAE,aAAa,EAAuB,MAAM,WAAW,CAAA;AAE9D,eAAO,MAAM,0BAA0B,kDAAkD,CAAA;AACzF,MAAM,MAAM,0BAA0B,GAAG,OAAO,0BAA0B,CAAA;AAE1E,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,0BAA0B,CAAC,CAAA;AAE5G,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC,oBAAoB,CAAC,CAAA;AAEhF,qBAAa,cAAc,CAAC,OAAO,SAAS,oBAAoB,GAAG,oBAAoB,CAAE,SAAQ,yBAAyB,CACxH,OAAO,EACP,iBAAiB,EACjB,aAAa,CACd;IACC,OAAgB,aAAa,WAA+B;cAEnC,cAAc,CAAC,UAAU,GAAE,iBAAiB,EAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAiCxG"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
ERC1822_PROXY_LOGIC_SLOT: () => ERC1822_PROXY_LOGIC_SLOT,
|
|
24
|
+
Erc1822StatusSchema: () => Erc1822StatusSchema,
|
|
25
|
+
Erc1822Witness: () => Erc1822Witness,
|
|
26
|
+
Erc1822WitnessConfigSchema: () => Erc1822WitnessConfigSchema,
|
|
27
|
+
getErc1822SlotStatus: () => getErc1822SlotStatus
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(src_exports);
|
|
30
|
+
|
|
31
|
+
// src/lib/getErc1822SlotStatus.ts
|
|
32
|
+
var import_hex = require("@xylabs/hex");
|
|
33
|
+
var ERC1822_PROXY_LOGIC_SLOT = "0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7";
|
|
34
|
+
var readAddressFromSlot = async (provider, address, slot, block) => {
|
|
35
|
+
try {
|
|
36
|
+
const slotValue = await provider.getStorage(address, slot, block);
|
|
37
|
+
return (0, import_hex.hexFromHexString)(slotValue, { prefix: true });
|
|
38
|
+
} catch (ex) {
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var getErc1822SlotStatus = async (provider, address, block) => {
|
|
43
|
+
const status = {
|
|
44
|
+
address,
|
|
45
|
+
implementation: address,
|
|
46
|
+
slots: {
|
|
47
|
+
implementation: await readAddressFromSlot(provider, address, ERC1822_PROXY_LOGIC_SLOT, block)
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
if (status.slots.implementation && !(0, import_hex.isHexZero)(status.slots.implementation)) {
|
|
51
|
+
status.implementation = status.slots.implementation;
|
|
52
|
+
}
|
|
53
|
+
return status;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/Payload.ts
|
|
57
|
+
var Erc1822StatusSchema = "network.xyo.erc1822.status";
|
|
58
|
+
|
|
59
|
+
// src/Witness.ts
|
|
60
|
+
var import_assert = require("@xylabs/assert");
|
|
61
|
+
var import_payload_model = require("@xyo-network/payload-model");
|
|
62
|
+
var import_witness_blockchain_abstract = require("@xyo-network/witness-blockchain-abstract");
|
|
63
|
+
var Erc1822WitnessConfigSchema = "network.xyo.blockchain.Erc1822.witness.config";
|
|
64
|
+
var Erc1822Witness = class extends import_witness_blockchain_abstract.AbstractBlockchainWitness {
|
|
65
|
+
static configSchemas = [Erc1822WitnessConfigSchema];
|
|
66
|
+
async observeHandler(inPayloads = []) {
|
|
67
|
+
await this.started("throw");
|
|
68
|
+
await this.getProviders();
|
|
69
|
+
try {
|
|
70
|
+
const observations = await Promise.all(
|
|
71
|
+
inPayloads.filter((0, import_payload_model.isPayloadOfSchemaType)(import_witness_blockchain_abstract.BlockchainAddressSchema)).map(async ({ address }) => {
|
|
72
|
+
const validatedAddress = (0, import_assert.assertEx)(address ?? this.config.address, "Missing address");
|
|
73
|
+
const provider = await this.getProvider(true, true);
|
|
74
|
+
const block = await provider.getBlockNumber();
|
|
75
|
+
const { implementation, slots } = await getErc1822SlotStatus(provider, validatedAddress, block);
|
|
76
|
+
const observation = {
|
|
77
|
+
address: validatedAddress,
|
|
78
|
+
block,
|
|
79
|
+
chainId: Number((await provider.getNetwork()).chainId),
|
|
80
|
+
implementation,
|
|
81
|
+
schema: Erc1822StatusSchema,
|
|
82
|
+
slots
|
|
83
|
+
};
|
|
84
|
+
return observation;
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
return observations;
|
|
88
|
+
} catch (ex) {
|
|
89
|
+
const error = ex;
|
|
90
|
+
console.log(`Error [${this.config.name}]: ${error.message}`);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
ERC1822_PROXY_LOGIC_SLOT,
|
|
98
|
+
Erc1822StatusSchema,
|
|
99
|
+
Erc1822Witness,
|
|
100
|
+
Erc1822WitnessConfigSchema,
|
|
101
|
+
getErc1822SlotStatus
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/lib/getErc1822SlotStatus.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 { Provider } from 'ethers'\n\nexport const ERC1822_PROXY_LOGIC_SLOT = '0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7'\n\nexport interface Erc1822DataSlots {\n implementation?: Address\n}\n\nexport interface Erc1822SlotStatus {\n address: Address\n implementation: Address\n slots: Erc1822DataSlots\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 getErc1822SlotStatus = async (provider: Provider, address: string, block?: number): Promise<Erc1822SlotStatus> => {\n const status: Erc1822SlotStatus = {\n address,\n implementation: address,\n slots: {\n implementation: await readAddressFromSlot(provider, address, ERC1822_PROXY_LOGIC_SLOT, block),\n },\n }\n\n if (status.slots.implementation && !isHexZero(status.slots.implementation)) {\n status.implementation = status.slots.implementation as string\n }\n\n return status\n}\n","import { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1822SlotStatus } from './lib'\n\nexport const Erc1822StatusSchema = 'network.xyo.erc1822.status'\nexport type Erc1822StatusSchema = typeof Erc1822StatusSchema\n\nexport type Erc1822Status = Payload<\n {\n address: Address\n block: number\n chainId: number\n implementation?: Erc1822SlotStatus['implementation']\n slots?: Erc1822SlotStatus['slots']\n },\n Erc1822StatusSchema\n>\n","import { assertEx } from '@xylabs/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport {\n AbstractBlockchainWitness,\n BlockchainAddress,\n BlockchainAddressSchema,\n BlockchainWitnessConfig,\n BlockchainWitnessParams,\n} from '@xyo-network/witness-blockchain-abstract'\n\nimport { getErc1822SlotStatus } from './lib'\nimport { Erc1822Status, Erc1822StatusSchema } from './Payload'\n\nexport const Erc1822WitnessConfigSchema = 'network.xyo.blockchain.Erc1822.witness.config'\nexport type Erc1822WitnessConfigSchema = typeof Erc1822WitnessConfigSchema\n\nexport type Erc1822WitnessConfig = BlockchainWitnessConfig<{ address?: string }, Erc1822WitnessConfigSchema>\n\nexport type Erc1822WitnessParams = BlockchainWitnessParams<Erc1822WitnessConfig>\n\nexport class Erc1822Witness<TParams extends Erc1822WitnessParams = Erc1822WitnessParams> extends AbstractBlockchainWitness<\n TParams,\n BlockchainAddress,\n Erc1822Status\n> {\n static override configSchemas = [Erc1822WitnessConfigSchema]\n\n protected override async observeHandler(inPayloads: BlockchainAddress[] = []): Promise<Erc1822Status[]> {\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(BlockchainAddressSchema)).map(async ({ address }) => {\n const validatedAddress = assertEx(address ?? this.config.address, 'Missing address')\n\n const provider = await this.getProvider(true, true)\n\n const block = await provider.getBlockNumber()\n\n const { implementation, slots } = await getErc1822SlotStatus(provider, validatedAddress, block)\n\n const observation: Erc1822Status = {\n address: validatedAddress,\n block,\n chainId: Number((await provider.getNetwork()).chainId),\n implementation,\n schema: Erc1822StatusSchema,\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;;;ACAA,iBAAqD;AAG9C,IAAM,2BAA2B;AAYxC,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,gBAAgB,MAAM,oBAAoB,UAAU,SAAS,0BAA0B,KAAK;AAAA,IAC9F;AAAA,EACF;AAEA,MAAI,OAAO,MAAM,kBAAkB,KAAC,sBAAU,OAAO,MAAM,cAAc,GAAG;AAC1E,WAAO,iBAAiB,OAAO,MAAM;AAAA,EACvC;AAEA,SAAO;AACT;;;ACjCO,IAAM,sBAAsB;;;ACLnC,oBAAyB;AACzB,2BAAsC;AACtC,yCAMO;AAKA,IAAM,6BAA6B;AAOnC,IAAM,iBAAN,cAA0F,6DAI/F;AAAA,EACA,OAAgB,gBAAgB,CAAC,0BAA0B;AAAA,EAE3D,MAAyB,eAAe,aAAkC,CAAC,GAA6B;AACtG,UAAM,KAAK,QAAQ,OAAO;AAE1B,UAAM,KAAK,aAAa;AACxB,QAAI;AACF,YAAM,eAAe,MAAM,QAAQ;AAAA,QACjC,WAAW,WAAO,4CAAsB,0DAAuB,CAAC,EAAE,IAAI,OAAO,EAAE,QAAQ,MAAM;AAC3F,gBAAM,uBAAmB,wBAAS,WAAW,KAAK,OAAO,SAAS,iBAAiB;AAEnF,gBAAM,WAAW,MAAM,KAAK,YAAY,MAAM,IAAI;AAElD,gBAAM,QAAQ,MAAM,SAAS,eAAe;AAE5C,gBAAM,EAAE,gBAAgB,MAAM,IAAI,MAAM,qBAAqB,UAAU,kBAAkB,KAAK;AAE9F,gBAAM,cAA6B;AAAA,YACjC,SAAS;AAAA,YACT;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":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/lib/getErc1822SlotStatus.ts
|
|
2
|
+
import { hexFromHexString, isHexZero } from "@xylabs/hex";
|
|
3
|
+
var ERC1822_PROXY_LOGIC_SLOT = "0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7";
|
|
4
|
+
var readAddressFromSlot = async (provider, address, slot, block) => {
|
|
5
|
+
try {
|
|
6
|
+
const slotValue = await provider.getStorage(address, slot, block);
|
|
7
|
+
return hexFromHexString(slotValue, { prefix: true });
|
|
8
|
+
} catch (ex) {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var getErc1822SlotStatus = async (provider, address, block) => {
|
|
13
|
+
const status = {
|
|
14
|
+
address,
|
|
15
|
+
implementation: address,
|
|
16
|
+
slots: {
|
|
17
|
+
implementation: await readAddressFromSlot(provider, address, ERC1822_PROXY_LOGIC_SLOT, block)
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
if (status.slots.implementation && !isHexZero(status.slots.implementation)) {
|
|
21
|
+
status.implementation = status.slots.implementation;
|
|
22
|
+
}
|
|
23
|
+
return status;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/Payload.ts
|
|
27
|
+
var Erc1822StatusSchema = "network.xyo.erc1822.status";
|
|
28
|
+
|
|
29
|
+
// src/Witness.ts
|
|
30
|
+
import { assertEx } from "@xylabs/assert";
|
|
31
|
+
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
32
|
+
import {
|
|
33
|
+
AbstractBlockchainWitness,
|
|
34
|
+
BlockchainAddressSchema
|
|
35
|
+
} from "@xyo-network/witness-blockchain-abstract";
|
|
36
|
+
var Erc1822WitnessConfigSchema = "network.xyo.blockchain.Erc1822.witness.config";
|
|
37
|
+
var Erc1822Witness = class extends AbstractBlockchainWitness {
|
|
38
|
+
static configSchemas = [Erc1822WitnessConfigSchema];
|
|
39
|
+
async observeHandler(inPayloads = []) {
|
|
40
|
+
await this.started("throw");
|
|
41
|
+
await this.getProviders();
|
|
42
|
+
try {
|
|
43
|
+
const observations = await Promise.all(
|
|
44
|
+
inPayloads.filter(isPayloadOfSchemaType(BlockchainAddressSchema)).map(async ({ address }) => {
|
|
45
|
+
const validatedAddress = assertEx(address ?? this.config.address, "Missing address");
|
|
46
|
+
const provider = await this.getProvider(true, true);
|
|
47
|
+
const block = await provider.getBlockNumber();
|
|
48
|
+
const { implementation, slots } = await getErc1822SlotStatus(provider, validatedAddress, block);
|
|
49
|
+
const observation = {
|
|
50
|
+
address: validatedAddress,
|
|
51
|
+
block,
|
|
52
|
+
chainId: Number((await provider.getNetwork()).chainId),
|
|
53
|
+
implementation,
|
|
54
|
+
schema: Erc1822StatusSchema,
|
|
55
|
+
slots
|
|
56
|
+
};
|
|
57
|
+
return observation;
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
return observations;
|
|
61
|
+
} catch (ex) {
|
|
62
|
+
const error = ex;
|
|
63
|
+
console.log(`Error [${this.config.name}]: ${error.message}`);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export {
|
|
69
|
+
ERC1822_PROXY_LOGIC_SLOT,
|
|
70
|
+
Erc1822StatusSchema,
|
|
71
|
+
Erc1822Witness,
|
|
72
|
+
Erc1822WitnessConfigSchema,
|
|
73
|
+
getErc1822SlotStatus
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/getErc1822SlotStatus.ts","../../src/Payload.ts","../../src/Witness.ts"],"sourcesContent":["import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'\nimport { Provider } from 'ethers'\n\nexport const ERC1822_PROXY_LOGIC_SLOT = '0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7'\n\nexport interface Erc1822DataSlots {\n implementation?: Address\n}\n\nexport interface Erc1822SlotStatus {\n address: Address\n implementation: Address\n slots: Erc1822DataSlots\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 getErc1822SlotStatus = async (provider: Provider, address: string, block?: number): Promise<Erc1822SlotStatus> => {\n const status: Erc1822SlotStatus = {\n address,\n implementation: address,\n slots: {\n implementation: await readAddressFromSlot(provider, address, ERC1822_PROXY_LOGIC_SLOT, block),\n },\n }\n\n if (status.slots.implementation && !isHexZero(status.slots.implementation)) {\n status.implementation = status.slots.implementation as string\n }\n\n return status\n}\n","import { Address } from '@xylabs/hex'\nimport { Payload } from '@xyo-network/payload-model'\n\nimport { Erc1822SlotStatus } from './lib'\n\nexport const Erc1822StatusSchema = 'network.xyo.erc1822.status'\nexport type Erc1822StatusSchema = typeof Erc1822StatusSchema\n\nexport type Erc1822Status = Payload<\n {\n address: Address\n block: number\n chainId: number\n implementation?: Erc1822SlotStatus['implementation']\n slots?: Erc1822SlotStatus['slots']\n },\n Erc1822StatusSchema\n>\n","import { assertEx } from '@xylabs/assert'\nimport { isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport {\n AbstractBlockchainWitness,\n BlockchainAddress,\n BlockchainAddressSchema,\n BlockchainWitnessConfig,\n BlockchainWitnessParams,\n} from '@xyo-network/witness-blockchain-abstract'\n\nimport { getErc1822SlotStatus } from './lib'\nimport { Erc1822Status, Erc1822StatusSchema } from './Payload'\n\nexport const Erc1822WitnessConfigSchema = 'network.xyo.blockchain.Erc1822.witness.config'\nexport type Erc1822WitnessConfigSchema = typeof Erc1822WitnessConfigSchema\n\nexport type Erc1822WitnessConfig = BlockchainWitnessConfig<{ address?: string }, Erc1822WitnessConfigSchema>\n\nexport type Erc1822WitnessParams = BlockchainWitnessParams<Erc1822WitnessConfig>\n\nexport class Erc1822Witness<TParams extends Erc1822WitnessParams = Erc1822WitnessParams> extends AbstractBlockchainWitness<\n TParams,\n BlockchainAddress,\n Erc1822Status\n> {\n static override configSchemas = [Erc1822WitnessConfigSchema]\n\n protected override async observeHandler(inPayloads: BlockchainAddress[] = []): Promise<Erc1822Status[]> {\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(BlockchainAddressSchema)).map(async ({ address }) => {\n const validatedAddress = assertEx(address ?? this.config.address, 'Missing address')\n\n const provider = await this.getProvider(true, true)\n\n const block = await provider.getBlockNumber()\n\n const { implementation, slots } = await getErc1822SlotStatus(provider, validatedAddress, block)\n\n const observation: Erc1822Status = {\n address: validatedAddress,\n block,\n chainId: Number((await provider.getNetwork()).chainId),\n implementation,\n schema: Erc1822StatusSchema,\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;AAG9C,IAAM,2BAA2B;AAYxC,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,gBAAgB,MAAM,oBAAoB,UAAU,SAAS,0BAA0B,KAAK;AAAA,IAC9F;AAAA,EACF;AAEA,MAAI,OAAO,MAAM,kBAAkB,CAAC,UAAU,OAAO,MAAM,cAAc,GAAG;AAC1E,WAAO,iBAAiB,OAAO,MAAM;AAAA,EACvC;AAEA,SAAO;AACT;;;ACjCO,IAAM,sBAAsB;;;ACLnC,SAAS,gBAAgB;AACzB,SAAS,6BAA6B;AACtC;AAAA,EACE;AAAA,EAEA;AAAA,OAGK;AAKA,IAAM,6BAA6B;AAOnC,IAAM,iBAAN,cAA0F,0BAI/F;AAAA,EACA,OAAgB,gBAAgB,CAAC,0BAA0B;AAAA,EAE3D,MAAyB,eAAe,aAAkC,CAAC,GAA6B;AACtG,UAAM,KAAK,QAAQ,OAAO;AAE1B,UAAM,KAAK,aAAa;AACxB,QAAI;AACF,YAAM,eAAe,MAAM,QAAQ;AAAA,QACjC,WAAW,OAAO,sBAAsB,uBAAuB,CAAC,EAAE,IAAI,OAAO,EAAE,QAAQ,MAAM;AAC3F,gBAAM,mBAAmB,SAAS,WAAW,KAAK,OAAO,SAAS,iBAAiB;AAEnF,gBAAM,WAAW,MAAM,KAAK,YAAY,MAAM,IAAI;AAElD,gBAAM,QAAQ,MAAM,SAAS,eAAe;AAE5C,gBAAM,EAAE,gBAAgB,MAAM,IAAI,MAAM,qBAAqB,UAAU,kBAAkB,KAAK;AAE9F,gBAAM,cAA6B;AAAA,YACjC,SAAS;AAAA,YACT;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":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Address } from '@xylabs/hex';
|
|
2
|
+
import { Provider } from 'ethers';
|
|
3
|
+
export declare const ERC1822_PROXY_LOGIC_SLOT = "0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7";
|
|
4
|
+
export interface Erc1822DataSlots {
|
|
5
|
+
implementation?: Address;
|
|
6
|
+
}
|
|
7
|
+
export interface Erc1822SlotStatus {
|
|
8
|
+
address: Address;
|
|
9
|
+
implementation: Address;
|
|
10
|
+
slots: Erc1822DataSlots;
|
|
11
|
+
}
|
|
12
|
+
export declare const getErc1822SlotStatus: (provider: Provider, address: string, block?: number) => Promise<Erc1822SlotStatus>;
|
|
13
|
+
//# sourceMappingURL=getErc1822SlotStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErc1822SlotStatus.d.ts","sourceRoot":"","sources":["../../../src/lib/getErc1822SlotStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA+B,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,eAAO,MAAM,wBAAwB,uEAAuE,CAAA;AAE5G,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;IACvB,KAAK,EAAE,gBAAgB,CAAA;CACxB;AAWD,eAAO,MAAM,oBAAoB,aAAoB,QAAQ,WAAW,MAAM,UAAU,MAAM,KAAG,QAAQ,iBAAiB,CAczH,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Address } from '@xylabs/hex';
|
|
2
|
+
import { Provider } from 'ethers';
|
|
3
|
+
export declare const ERC1822_PROXY_LOGIC_SLOT = "0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7";
|
|
4
|
+
export interface Erc1822DataSlots {
|
|
5
|
+
implementation?: Address;
|
|
6
|
+
}
|
|
7
|
+
export interface Erc1822SlotStatus {
|
|
8
|
+
address: Address;
|
|
9
|
+
implementation: Address;
|
|
10
|
+
slots: Erc1822DataSlots;
|
|
11
|
+
}
|
|
12
|
+
export declare const getErc1822SlotStatus: (provider: Provider, address: string, block?: number) => Promise<Erc1822SlotStatus>;
|
|
13
|
+
//# sourceMappingURL=getErc1822SlotStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErc1822SlotStatus.d.ts","sourceRoot":"","sources":["../../../src/lib/getErc1822SlotStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA+B,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,eAAO,MAAM,wBAAwB,uEAAuE,CAAA;AAE5G,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;IACvB,KAAK,EAAE,gBAAgB,CAAA;CACxB;AAWD,eAAO,MAAM,oBAAoB,aAAoB,QAAQ,WAAW,MAAM,UAAU,MAAM,KAAG,QAAQ,iBAAiB,CAczH,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Address } from '@xylabs/hex';
|
|
2
|
+
import { Provider } from 'ethers';
|
|
3
|
+
export declare const ERC1822_PROXY_LOGIC_SLOT = "0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7";
|
|
4
|
+
export interface Erc1822DataSlots {
|
|
5
|
+
implementation?: Address;
|
|
6
|
+
}
|
|
7
|
+
export interface Erc1822SlotStatus {
|
|
8
|
+
address: Address;
|
|
9
|
+
implementation: Address;
|
|
10
|
+
slots: Erc1822DataSlots;
|
|
11
|
+
}
|
|
12
|
+
export declare const getErc1822SlotStatus: (provider: Provider, address: string, block?: number) => Promise<Erc1822SlotStatus>;
|
|
13
|
+
//# sourceMappingURL=getErc1822SlotStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getErc1822SlotStatus.d.ts","sourceRoot":"","sources":["../../../src/lib/getErc1822SlotStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA+B,MAAM,aAAa,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,eAAO,MAAM,wBAAwB,uEAAuE,CAAA;AAE5G,MAAM,WAAW,gBAAgB;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,cAAc,EAAE,OAAO,CAAA;IACvB,KAAK,EAAE,gBAAgB,CAAA;CACxB;AAWD,eAAO,MAAM,oBAAoB,aAAoB,QAAQ,WAAW,MAAM,UAAU,MAAM,KAAG,QAAQ,iBAAiB,CAczH,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyo-network/erc1822-witness",
|
|
3
|
+
"author": {
|
|
4
|
+
"email": "support@xyo.network",
|
|
5
|
+
"name": "XYO Development Team",
|
|
6
|
+
"url": "https://xyo.network"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"email": "support@xyo.network",
|
|
10
|
+
"url": "https://github.com/XYOracleNetwork/plugins/issues"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xylabs/assert": "^2.13.20",
|
|
14
|
+
"@xylabs/hex": "^2.13.20",
|
|
15
|
+
"@xyo-network/payload-model": "^2.84.3",
|
|
16
|
+
"@xyo-network/witness-blockchain-abstract": "^2.84.3"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@xylabs/jest-helpers": "^2.13.20",
|
|
20
|
+
"@xylabs/ts-scripts-yarn3": "^3.2.19",
|
|
21
|
+
"@xylabs/tsconfig": "^3.2.19",
|
|
22
|
+
"ethers": "^6.9.0",
|
|
23
|
+
"jest": "^29.7.0",
|
|
24
|
+
"typescript": "^5.3.3"
|
|
25
|
+
},
|
|
26
|
+
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
27
|
+
"types": "dist/node/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"browser": {
|
|
31
|
+
"require": {
|
|
32
|
+
"types": "./dist/browser/index.d.cts",
|
|
33
|
+
"default": "./dist/browser/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/browser/index.d.mts",
|
|
37
|
+
"default": "./dist/browser/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"node": {
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/node/index.d.cts",
|
|
43
|
+
"default": "./dist/node/index.cjs"
|
|
44
|
+
},
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/node/index.d.mts",
|
|
47
|
+
"default": "./dist/node/index.js"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./package.json": "./package.json"
|
|
52
|
+
},
|
|
53
|
+
"main": "dist/node/index.cjs",
|
|
54
|
+
"module": "dist/node/index.js",
|
|
55
|
+
"homepage": "https://xyo.network",
|
|
56
|
+
"license": "LGPL-3.0-only",
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
},
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
63
|
+
},
|
|
64
|
+
"sideEffects": false,
|
|
65
|
+
"version": "2.84.1",
|
|
66
|
+
"type": "module"
|
|
67
|
+
}
|
package/src/Payload.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Address } from '@xylabs/hex'
|
|
2
|
+
import { Payload } from '@xyo-network/payload-model'
|
|
3
|
+
|
|
4
|
+
import { Erc1822SlotStatus } from './lib'
|
|
5
|
+
|
|
6
|
+
export const Erc1822StatusSchema = 'network.xyo.erc1822.status'
|
|
7
|
+
export type Erc1822StatusSchema = typeof Erc1822StatusSchema
|
|
8
|
+
|
|
9
|
+
export type Erc1822Status = Payload<
|
|
10
|
+
{
|
|
11
|
+
address: Address
|
|
12
|
+
block: number
|
|
13
|
+
chainId: number
|
|
14
|
+
implementation?: Erc1822SlotStatus['implementation']
|
|
15
|
+
slots?: Erc1822SlotStatus['slots']
|
|
16
|
+
},
|
|
17
|
+
Erc1822StatusSchema
|
|
18
|
+
>
|
package/src/Witness.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
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'
|
|
10
|
+
|
|
11
|
+
import { getErc1822SlotStatus } from './lib'
|
|
12
|
+
import { Erc1822Status, Erc1822StatusSchema } from './Payload'
|
|
13
|
+
|
|
14
|
+
export const Erc1822WitnessConfigSchema = 'network.xyo.blockchain.Erc1822.witness.config'
|
|
15
|
+
export type Erc1822WitnessConfigSchema = typeof Erc1822WitnessConfigSchema
|
|
16
|
+
|
|
17
|
+
export type Erc1822WitnessConfig = BlockchainWitnessConfig<{ address?: string }, Erc1822WitnessConfigSchema>
|
|
18
|
+
|
|
19
|
+
export type Erc1822WitnessParams = BlockchainWitnessParams<Erc1822WitnessConfig>
|
|
20
|
+
|
|
21
|
+
export class Erc1822Witness<TParams extends Erc1822WitnessParams = Erc1822WitnessParams> extends AbstractBlockchainWitness<
|
|
22
|
+
TParams,
|
|
23
|
+
BlockchainAddress,
|
|
24
|
+
Erc1822Status
|
|
25
|
+
> {
|
|
26
|
+
static override configSchemas = [Erc1822WitnessConfigSchema]
|
|
27
|
+
|
|
28
|
+
protected override async observeHandler(inPayloads: BlockchainAddress[] = []): Promise<Erc1822Status[]> {
|
|
29
|
+
await this.started('throw')
|
|
30
|
+
//calling it here to make sure we rests the cache
|
|
31
|
+
await this.getProviders()
|
|
32
|
+
try {
|
|
33
|
+
const observations = await Promise.all(
|
|
34
|
+
inPayloads.filter(isPayloadOfSchemaType(BlockchainAddressSchema)).map(async ({ address }) => {
|
|
35
|
+
const validatedAddress = assertEx(address ?? this.config.address, 'Missing address')
|
|
36
|
+
|
|
37
|
+
const provider = await this.getProvider(true, true)
|
|
38
|
+
|
|
39
|
+
const block = await provider.getBlockNumber()
|
|
40
|
+
|
|
41
|
+
const { implementation, slots } = await getErc1822SlotStatus(provider, validatedAddress, block)
|
|
42
|
+
|
|
43
|
+
const observation: Erc1822Status = {
|
|
44
|
+
address: validatedAddress,
|
|
45
|
+
block,
|
|
46
|
+
chainId: Number((await provider.getNetwork()).chainId),
|
|
47
|
+
implementation,
|
|
48
|
+
schema: Erc1822StatusSchema,
|
|
49
|
+
slots,
|
|
50
|
+
}
|
|
51
|
+
return observation
|
|
52
|
+
}),
|
|
53
|
+
)
|
|
54
|
+
return observations
|
|
55
|
+
} catch (ex) {
|
|
56
|
+
const error = ex as Error
|
|
57
|
+
console.log(`Error [${this.config.name}]: ${error.message}`)
|
|
58
|
+
throw error
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Address, hexFromHexString, isHexZero } from '@xylabs/hex'
|
|
2
|
+
import { Provider } from 'ethers'
|
|
3
|
+
|
|
4
|
+
export const ERC1822_PROXY_LOGIC_SLOT = '0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7'
|
|
5
|
+
|
|
6
|
+
export interface Erc1822DataSlots {
|
|
7
|
+
implementation?: Address
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface Erc1822SlotStatus {
|
|
11
|
+
address: Address
|
|
12
|
+
implementation: Address
|
|
13
|
+
slots: Erc1822DataSlots
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const readAddressFromSlot = async (provider: Provider, address: string, slot: string, block?: number) => {
|
|
17
|
+
try {
|
|
18
|
+
const slotValue = await provider.getStorage(address, slot, block)
|
|
19
|
+
return hexFromHexString(slotValue, { prefix: true })
|
|
20
|
+
} catch (ex) {
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const getErc1822SlotStatus = async (provider: Provider, address: string, block?: number): Promise<Erc1822SlotStatus> => {
|
|
26
|
+
const status: Erc1822SlotStatus = {
|
|
27
|
+
address,
|
|
28
|
+
implementation: address,
|
|
29
|
+
slots: {
|
|
30
|
+
implementation: await readAddressFromSlot(provider, address, ERC1822_PROXY_LOGIC_SLOT, block),
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (status.slots.implementation && !isHexZero(status.slots.implementation)) {
|
|
35
|
+
status.implementation = status.slots.implementation as string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return status
|
|
39
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getErc1822SlotStatus'
|
package/typedoc.json
ADDED
package/xy.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
|
|
2
|
+
const config: XyTsupConfig = {
|
|
3
|
+
compile: {
|
|
4
|
+
browser: {
|
|
5
|
+
src: true,
|
|
6
|
+
},
|
|
7
|
+
node: {
|
|
8
|
+
src: true,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line import/no-default-export
|
|
14
|
+
export default config
|