@xyo-network/evm-token-interface-diviner 2.99.5 → 2.99.6
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/index.cjs +10 -18
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.mjs +20 -21
- package/dist/browser/index.mjs.map +1 -1
- package/dist/neutral/index.cjs +10 -18
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.mjs +20 -21
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/index.cjs +23 -35
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +33 -38
- package/dist/node/index.mjs.map +1 -1
- package/package.json +28 -28
package/dist/browser/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,12 +42,9 @@ var isEvmTokenInterfaceImplemented = (0, import_payload_model.isPayloadOfSchemaT
|
|
|
43
42
|
// src/Diviner.ts
|
|
44
43
|
var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
|
|
45
44
|
var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiviner extends import_diviner_abstract.AbstractDiviner {
|
|
46
|
-
static {
|
|
47
|
-
__name(this, "EvmTokenInterfaceImplementedDiviner");
|
|
48
|
-
}
|
|
49
45
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
* The list of supported token interfaces
|
|
47
|
+
*/
|
|
52
48
|
static SupportedTokenInterfaces = {
|
|
53
49
|
ERC1155: import_open_zeppelin_typechain.ERC1155__factory.abi,
|
|
54
50
|
ERC1155Metadata_URI: import_open_zeppelin_typechain.IERC1155MetadataURI__factory.abi,
|
|
@@ -59,23 +55,19 @@ var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiv
|
|
|
59
55
|
ERC721Metadata: import_open_zeppelin_typechain.IERC721Metadata__factory.abi,
|
|
60
56
|
ERC721TokenReceiver: import_open_zeppelin_typechain.IERC721Receiver__factory.abi
|
|
61
57
|
};
|
|
62
|
-
static configSchemas = [
|
|
63
|
-
...super.configSchemas,
|
|
64
|
-
EvmTokenInterfaceImplementedDivinerConfigSchema
|
|
65
|
-
];
|
|
58
|
+
static configSchemas = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema];
|
|
66
59
|
static defaultConfigSchema = EvmTokenInterfaceImplementedDivinerConfigSchema;
|
|
67
60
|
_tokenInterfaces;
|
|
68
61
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
* The list of token interfaces to check against the contract
|
|
63
|
+
*/
|
|
71
64
|
get tokenInterfaces() {
|
|
72
65
|
if (!this._tokenInterfaces) {
|
|
73
|
-
this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
|
|
74
|
-
|
|
75
|
-
tokenInterface,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
66
|
+
this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
|
|
67
|
+
this.config?.tokenInterfaces.map((tokenInterface) => {
|
|
68
|
+
return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
|
|
69
|
+
})
|
|
70
|
+
) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
79
71
|
}
|
|
80
72
|
return this._tokenInterfaces;
|
|
81
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner.ts'\nexport * from './Payload.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner.ts'\nexport * from './Payload.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,8BAAgC;AAEhC,kCAA2C;AAE3C,qCASO;AAEP,oBAAwC;;;AChBxC,2BAA+C;AAyBxC,IAAM,qCAAqC;AAkC3C,IAAM,qCAAiC,4CAAoD,kCAAkC;;;ADvC7H,IAAM,kDAAkD,GAAG,kCAAkC;AAgB7F,IAAM,sCAAN,MAAM,6CAEH,wCAAoE;AAAA;AAAA;AAAA;AAAA,EAI5E,OAAgB,2BAAsF;AAAA,IACpG,SAAS,gDAAiB;AAAA,IAC1B,qBAAqB,4DAA6B;AAAA,IAClD,sBAAsB,yDAA0B;AAAA,IAChD,OAAO,8CAAe;AAAA,IACtB,QAAQ,+CAAgB;AAAA,IACxB,kBAAkB,0DAA2B;AAAA,IAC7C,gBAAgB,wDAAyB;AAAA,IACzC,qBAAqB,wDAAyB;AAAA,EAChD;AAAA,EAEA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+CAA+C;AAAA,EAC3H,OAAyB,sBAA8B;AAAA,EAE/C;AAAA;AAAA;AAAA;AAAA,EAKR,IAAI,kBAAkB;AACpB,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,mBACD,KAAK,QAAQ,kBACT,OAAO;AAAA,QACP,KAAK,QAAQ,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG,CAAC;AAAA,MACH,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC5C;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,aAA4B,CAAC,GAA4C;AAC9G,UAAM,KAAK,QAAQ,OAAO;AAC1B,QAAI;AACF,YAAM,aAAa,MAAM,QAAQ;AAAA;AAAA,QAE/B,WAAW,OAAO,yCAAa,EAAE,IAAI,CAAC,EAAE,SAAS,MAAM,QAAQ,MAAM;AAEnE,gBAAM,eAAW,wBAAS,MAAM,MAAM,cAAc;AACpD,gBAAM,UAA0C,CAAC;AAEjD,qBAAW,CAAC,gBAAgB,GAAG,KAAK,OAAO,QAAQ,KAAK,eAAe,GAAG;AAExE,kBAAM,oBAAoB,IAAI,wBAAU,GAAG;AAC3C,kBAAM,kBAA6B,CAAC;AACpC,8BAAkB,gBAAgB,CAAC,EAAE,SAAS,MAAM;AAClD,8BAAgB,KAAK,SAAS,SAAS,OAAO,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;AAAA,YACvE,CAAC;AACD,kBAAM,cAAc,gBAAgB,MAAM,OAAO;AACjD,kBAAM,SAAuC;AAAA,cAC3C;AAAA,cACA;AAAA,cACA;AAAA,cACA,QAAQ;AAAA,cACR;AAAA,YACF;AACA,oBAAQ,KAAK,MAAM;AAAA,UACrB;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO,WAAW,KAAK;AAAA,IACzB,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.mjs
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/Diviner.ts
|
|
5
2
|
import { assertEx } from "@xylabs/assert";
|
|
6
3
|
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
7
4
|
import { isEvmContract } from "@xyo-network/evm-contract-witness";
|
|
8
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ERC20__factory,
|
|
7
|
+
ERC721__factory,
|
|
8
|
+
ERC1155__factory,
|
|
9
|
+
IERC721Enumerable__factory,
|
|
10
|
+
IERC721Metadata__factory,
|
|
11
|
+
IERC721Receiver__factory,
|
|
12
|
+
IERC1155MetadataURI__factory,
|
|
13
|
+
IERC1155Receiver__factory
|
|
14
|
+
} from "@xyo-network/open-zeppelin-typechain";
|
|
9
15
|
import { Interface } from "ethers";
|
|
10
16
|
|
|
11
17
|
// src/Payload.ts
|
|
@@ -16,12 +22,9 @@ var isEvmTokenInterfaceImplemented = isPayloadOfSchemaType(EvmTokenInterfaceImpl
|
|
|
16
22
|
// src/Diviner.ts
|
|
17
23
|
var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
|
|
18
24
|
var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiviner extends AbstractDiviner {
|
|
19
|
-
static {
|
|
20
|
-
__name(this, "EvmTokenInterfaceImplementedDiviner");
|
|
21
|
-
}
|
|
22
25
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
* The list of supported token interfaces
|
|
27
|
+
*/
|
|
25
28
|
static SupportedTokenInterfaces = {
|
|
26
29
|
ERC1155: ERC1155__factory.abi,
|
|
27
30
|
ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,
|
|
@@ -32,23 +35,19 @@ var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiv
|
|
|
32
35
|
ERC721Metadata: IERC721Metadata__factory.abi,
|
|
33
36
|
ERC721TokenReceiver: IERC721Receiver__factory.abi
|
|
34
37
|
};
|
|
35
|
-
static configSchemas = [
|
|
36
|
-
...super.configSchemas,
|
|
37
|
-
EvmTokenInterfaceImplementedDivinerConfigSchema
|
|
38
|
-
];
|
|
38
|
+
static configSchemas = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema];
|
|
39
39
|
static defaultConfigSchema = EvmTokenInterfaceImplementedDivinerConfigSchema;
|
|
40
40
|
_tokenInterfaces;
|
|
41
41
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
* The list of token interfaces to check against the contract
|
|
43
|
+
*/
|
|
44
44
|
get tokenInterfaces() {
|
|
45
45
|
if (!this._tokenInterfaces) {
|
|
46
|
-
this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
|
|
47
|
-
|
|
48
|
-
tokenInterface,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
46
|
+
this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
|
|
47
|
+
this.config?.tokenInterfaces.map((tokenInterface) => {
|
|
48
|
+
return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
|
|
49
|
+
})
|
|
50
|
+
) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
52
51
|
}
|
|
53
52
|
return this._tokenInterfaces;
|
|
54
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAEhC,SAAsB,qBAAqB;AAE3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,iBAA+B;;;AChBxC,SAAS,6BAAsC;AAyBxC,IAAM,qCAAqC;AAkC3C,IAAM,iCAAiC,sBAAoD,kCAAkC;;;ADvC7H,IAAM,kDAAkD,GAAG,kCAAkC;AAgB7F,IAAM,sCAAN,MAAM,6CAEH,gBAAoE;AAAA;AAAA;AAAA;AAAA,EAI5E,OAAgB,2BAAsF;AAAA,IACpG,SAAS,iBAAiB;AAAA,IAC1B,qBAAqB,6BAA6B;AAAA,IAClD,sBAAsB,0BAA0B;AAAA,IAChD,OAAO,eAAe;AAAA,IACtB,QAAQ,gBAAgB;AAAA,IACxB,kBAAkB,2BAA2B;AAAA,IAC7C,gBAAgB,yBAAyB;AAAA,IACzC,qBAAqB,yBAAyB;AAAA,EAChD;AAAA,EAEA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+CAA+C;AAAA,EAC3H,OAAyB,sBAA8B;AAAA,EAE/C;AAAA;AAAA;AAAA;AAAA,EAKR,IAAI,kBAAkB;AACpB,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,mBACD,KAAK,QAAQ,kBACT,OAAO;AAAA,QACP,KAAK,QAAQ,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG,CAAC;AAAA,MACH,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC5C;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,aAA4B,CAAC,GAA4C;AAC9G,UAAM,KAAK,QAAQ,OAAO;AAC1B,QAAI;AACF,YAAM,aAAa,MAAM,QAAQ;AAAA;AAAA,QAE/B,WAAW,OAAO,aAAa,EAAE,IAAI,CAAC,EAAE,SAAS,MAAM,QAAQ,MAAM;AAEnE,gBAAM,WAAW,SAAS,MAAM,MAAM,cAAc;AACpD,gBAAM,UAA0C,CAAC;AAEjD,qBAAW,CAAC,gBAAgB,GAAG,KAAK,OAAO,QAAQ,KAAK,eAAe,GAAG;AAExE,kBAAM,oBAAoB,IAAI,UAAU,GAAG;AAC3C,kBAAM,kBAA6B,CAAC;AACpC,8BAAkB,gBAAgB,CAAC,EAAE,SAAS,MAAM;AAClD,8BAAgB,KAAK,SAAS,SAAS,OAAO,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;AAAA,YACvE,CAAC;AACD,kBAAM,cAAc,gBAAgB,MAAM,OAAO;AACjD,kBAAM,SAAuC;AAAA,cAC3C;AAAA,cACA;AAAA,cACA;AAAA,cACA,QAAQ;AAAA,cACR;AAAA,YACF;AACA,oBAAQ,KAAK,MAAM;AAAA,UACrB;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO,WAAW,KAAK;AAAA,IACzB,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/neutral/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,12 +42,9 @@ var isEvmTokenInterfaceImplemented = (0, import_payload_model.isPayloadOfSchemaT
|
|
|
43
42
|
// src/Diviner.ts
|
|
44
43
|
var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
|
|
45
44
|
var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiviner extends import_diviner_abstract.AbstractDiviner {
|
|
46
|
-
static {
|
|
47
|
-
__name(this, "EvmTokenInterfaceImplementedDiviner");
|
|
48
|
-
}
|
|
49
45
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
* The list of supported token interfaces
|
|
47
|
+
*/
|
|
52
48
|
static SupportedTokenInterfaces = {
|
|
53
49
|
ERC1155: import_open_zeppelin_typechain.ERC1155__factory.abi,
|
|
54
50
|
ERC1155Metadata_URI: import_open_zeppelin_typechain.IERC1155MetadataURI__factory.abi,
|
|
@@ -59,23 +55,19 @@ var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiv
|
|
|
59
55
|
ERC721Metadata: import_open_zeppelin_typechain.IERC721Metadata__factory.abi,
|
|
60
56
|
ERC721TokenReceiver: import_open_zeppelin_typechain.IERC721Receiver__factory.abi
|
|
61
57
|
};
|
|
62
|
-
static configSchemas = [
|
|
63
|
-
...super.configSchemas,
|
|
64
|
-
EvmTokenInterfaceImplementedDivinerConfigSchema
|
|
65
|
-
];
|
|
58
|
+
static configSchemas = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema];
|
|
66
59
|
static defaultConfigSchema = EvmTokenInterfaceImplementedDivinerConfigSchema;
|
|
67
60
|
_tokenInterfaces;
|
|
68
61
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
* The list of token interfaces to check against the contract
|
|
63
|
+
*/
|
|
71
64
|
get tokenInterfaces() {
|
|
72
65
|
if (!this._tokenInterfaces) {
|
|
73
|
-
this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
|
|
74
|
-
|
|
75
|
-
tokenInterface,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
66
|
+
this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
|
|
67
|
+
this.config?.tokenInterfaces.map((tokenInterface) => {
|
|
68
|
+
return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
|
|
69
|
+
})
|
|
70
|
+
) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
79
71
|
}
|
|
80
72
|
return this._tokenInterfaces;
|
|
81
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner.ts'\nexport * from './Payload.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner.ts'\nexport * from './Payload.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,8BAAgC;AAEhC,kCAA2C;AAE3C,qCASO;AAEP,oBAAwC;;;AChBxC,2BAA+C;AAyBxC,IAAM,qCAAqC;AAkC3C,IAAM,qCAAiC,4CAAoD,kCAAkC;;;ADvC7H,IAAM,kDAAkD,GAAG,kCAAkC;AAgB7F,IAAM,sCAAN,MAAM,6CAEH,wCAAoE;AAAA;AAAA;AAAA;AAAA,EAI5E,OAAgB,2BAAsF;AAAA,IACpG,SAAS,gDAAiB;AAAA,IAC1B,qBAAqB,4DAA6B;AAAA,IAClD,sBAAsB,yDAA0B;AAAA,IAChD,OAAO,8CAAe;AAAA,IACtB,QAAQ,+CAAgB;AAAA,IACxB,kBAAkB,0DAA2B;AAAA,IAC7C,gBAAgB,wDAAyB;AAAA,IACzC,qBAAqB,wDAAyB;AAAA,EAChD;AAAA,EAEA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+CAA+C;AAAA,EAC3H,OAAyB,sBAA8B;AAAA,EAE/C;AAAA;AAAA;AAAA;AAAA,EAKR,IAAI,kBAAkB;AACpB,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,mBACD,KAAK,QAAQ,kBACT,OAAO;AAAA,QACP,KAAK,QAAQ,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG,CAAC;AAAA,MACH,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC5C;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,aAA4B,CAAC,GAA4C;AAC9G,UAAM,KAAK,QAAQ,OAAO;AAC1B,QAAI;AACF,YAAM,aAAa,MAAM,QAAQ;AAAA;AAAA,QAE/B,WAAW,OAAO,yCAAa,EAAE,IAAI,CAAC,EAAE,SAAS,MAAM,QAAQ,MAAM;AAEnE,gBAAM,eAAW,wBAAS,MAAM,MAAM,cAAc;AACpD,gBAAM,UAA0C,CAAC;AAEjD,qBAAW,CAAC,gBAAgB,GAAG,KAAK,OAAO,QAAQ,KAAK,eAAe,GAAG;AAExE,kBAAM,oBAAoB,IAAI,wBAAU,GAAG;AAC3C,kBAAM,kBAA6B,CAAC;AACpC,8BAAkB,gBAAgB,CAAC,EAAE,SAAS,MAAM;AAClD,8BAAgB,KAAK,SAAS,SAAS,OAAO,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;AAAA,YACvE,CAAC;AACD,kBAAM,cAAc,gBAAgB,MAAM,OAAO;AACjD,kBAAM,SAAuC;AAAA,cAC3C;AAAA,cACA;AAAA,cACA;AAAA,cACA,QAAQ;AAAA,cACR;AAAA,YACF;AACA,oBAAQ,KAAK,MAAM;AAAA,UACrB;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO,WAAW,KAAK;AAAA,IACzB,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/neutral/index.mjs
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/Diviner.ts
|
|
5
2
|
import { assertEx } from "@xylabs/assert";
|
|
6
3
|
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
7
4
|
import { isEvmContract } from "@xyo-network/evm-contract-witness";
|
|
8
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ERC20__factory,
|
|
7
|
+
ERC721__factory,
|
|
8
|
+
ERC1155__factory,
|
|
9
|
+
IERC721Enumerable__factory,
|
|
10
|
+
IERC721Metadata__factory,
|
|
11
|
+
IERC721Receiver__factory,
|
|
12
|
+
IERC1155MetadataURI__factory,
|
|
13
|
+
IERC1155Receiver__factory
|
|
14
|
+
} from "@xyo-network/open-zeppelin-typechain";
|
|
9
15
|
import { Interface } from "ethers";
|
|
10
16
|
|
|
11
17
|
// src/Payload.ts
|
|
@@ -16,12 +22,9 @@ var isEvmTokenInterfaceImplemented = isPayloadOfSchemaType(EvmTokenInterfaceImpl
|
|
|
16
22
|
// src/Diviner.ts
|
|
17
23
|
var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
|
|
18
24
|
var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiviner extends AbstractDiviner {
|
|
19
|
-
static {
|
|
20
|
-
__name(this, "EvmTokenInterfaceImplementedDiviner");
|
|
21
|
-
}
|
|
22
25
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
* The list of supported token interfaces
|
|
27
|
+
*/
|
|
25
28
|
static SupportedTokenInterfaces = {
|
|
26
29
|
ERC1155: ERC1155__factory.abi,
|
|
27
30
|
ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,
|
|
@@ -32,23 +35,19 @@ var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiv
|
|
|
32
35
|
ERC721Metadata: IERC721Metadata__factory.abi,
|
|
33
36
|
ERC721TokenReceiver: IERC721Receiver__factory.abi
|
|
34
37
|
};
|
|
35
|
-
static configSchemas = [
|
|
36
|
-
...super.configSchemas,
|
|
37
|
-
EvmTokenInterfaceImplementedDivinerConfigSchema
|
|
38
|
-
];
|
|
38
|
+
static configSchemas = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema];
|
|
39
39
|
static defaultConfigSchema = EvmTokenInterfaceImplementedDivinerConfigSchema;
|
|
40
40
|
_tokenInterfaces;
|
|
41
41
|
/**
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
* The list of token interfaces to check against the contract
|
|
43
|
+
*/
|
|
44
44
|
get tokenInterfaces() {
|
|
45
45
|
if (!this._tokenInterfaces) {
|
|
46
|
-
this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
|
|
47
|
-
|
|
48
|
-
tokenInterface,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
})) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
46
|
+
this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
|
|
47
|
+
this.config?.tokenInterfaces.map((tokenInterface) => {
|
|
48
|
+
return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
|
|
49
|
+
})
|
|
50
|
+
) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
52
51
|
}
|
|
53
52
|
return this._tokenInterfaces;
|
|
54
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAEhC,SAAsB,qBAAqB;AAE3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,iBAA+B;;;AChBxC,SAAS,6BAAsC;AAyBxC,IAAM,qCAAqC;AAkC3C,IAAM,iCAAiC,sBAAoD,kCAAkC;;;ADvC7H,IAAM,kDAAkD,GAAG,kCAAkC;AAgB7F,IAAM,sCAAN,MAAM,6CAEH,gBAAoE;AAAA;AAAA;AAAA;AAAA,EAI5E,OAAgB,2BAAsF;AAAA,IACpG,SAAS,iBAAiB;AAAA,IAC1B,qBAAqB,6BAA6B;AAAA,IAClD,sBAAsB,0BAA0B;AAAA,IAChD,OAAO,eAAe;AAAA,IACtB,QAAQ,gBAAgB;AAAA,IACxB,kBAAkB,2BAA2B;AAAA,IAC7C,gBAAgB,yBAAyB;AAAA,IACzC,qBAAqB,yBAAyB;AAAA,EAChD;AAAA,EAEA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+CAA+C;AAAA,EAC3H,OAAyB,sBAA8B;AAAA,EAE/C;AAAA;AAAA;AAAA;AAAA,EAKR,IAAI,kBAAkB;AACpB,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,mBACD,KAAK,QAAQ,kBACT,OAAO;AAAA,QACP,KAAK,QAAQ,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG,CAAC;AAAA,MACH,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC5C;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,aAA4B,CAAC,GAA4C;AAC9G,UAAM,KAAK,QAAQ,OAAO;AAC1B,QAAI;AACF,YAAM,aAAa,MAAM,QAAQ;AAAA;AAAA,QAE/B,WAAW,OAAO,aAAa,EAAE,IAAI,CAAC,EAAE,SAAS,MAAM,QAAQ,MAAM;AAEnE,gBAAM,WAAW,SAAS,MAAM,MAAM,cAAc;AACpD,gBAAM,UAA0C,CAAC;AAEjD,qBAAW,CAAC,gBAAgB,GAAG,KAAK,OAAO,QAAQ,KAAK,eAAe,GAAG;AAExE,kBAAM,oBAAoB,IAAI,UAAU,GAAG;AAC3C,kBAAM,kBAA6B,CAAC;AACpC,8BAAkB,gBAAgB,CAAC,EAAE,SAAS,MAAM;AAClD,8BAAgB,KAAK,SAAS,SAAS,OAAO,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;AAAA,YACvE,CAAC;AACD,kBAAM,cAAc,gBAAgB,MAAM,OAAO;AACjD,kBAAM,SAAuC;AAAA,cAC3C;AAAA,cACA;AAAA,cACA;AAAA,cACA,QAAQ;AAAA,cACR;AAAA,YACF;AACA,oBAAQ,KAAK,MAAM;AAAA,UACrB;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO,WAAW,KAAK;AAAA,IACzB,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.cjs
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __reflectGet = Reflect.get;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
10
6
|
var __export = (target, all) => {
|
|
11
7
|
for (var name in all)
|
|
12
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -20,8 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
20
16
|
return to;
|
|
21
17
|
};
|
|
22
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
-
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
25
19
|
|
|
26
20
|
// src/index.ts
|
|
27
21
|
var src_exports = {};
|
|
@@ -47,20 +41,34 @@ var isEvmTokenInterfaceImplemented = (0, import_payload_model.isPayloadOfSchemaT
|
|
|
47
41
|
|
|
48
42
|
// src/Diviner.ts
|
|
49
43
|
var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
|
|
50
|
-
var
|
|
44
|
+
var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiviner extends import_diviner_abstract.AbstractDiviner {
|
|
45
|
+
/**
|
|
46
|
+
* The list of supported token interfaces
|
|
47
|
+
*/
|
|
48
|
+
static SupportedTokenInterfaces = {
|
|
49
|
+
ERC1155: import_open_zeppelin_typechain.ERC1155__factory.abi,
|
|
50
|
+
ERC1155Metadata_URI: import_open_zeppelin_typechain.IERC1155MetadataURI__factory.abi,
|
|
51
|
+
ERC1155TokenReceiver: import_open_zeppelin_typechain.IERC1155Receiver__factory.abi,
|
|
52
|
+
ERC20: import_open_zeppelin_typechain.ERC20__factory.abi,
|
|
53
|
+
ERC721: import_open_zeppelin_typechain.ERC721__factory.abi,
|
|
54
|
+
ERC721Enumerable: import_open_zeppelin_typechain.IERC721Enumerable__factory.abi,
|
|
55
|
+
ERC721Metadata: import_open_zeppelin_typechain.IERC721Metadata__factory.abi,
|
|
56
|
+
ERC721TokenReceiver: import_open_zeppelin_typechain.IERC721Receiver__factory.abi
|
|
57
|
+
};
|
|
58
|
+
static configSchemas = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema];
|
|
59
|
+
static defaultConfigSchema = EvmTokenInterfaceImplementedDivinerConfigSchema;
|
|
51
60
|
_tokenInterfaces;
|
|
52
61
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
* The list of token interfaces to check against the contract
|
|
63
|
+
*/
|
|
55
64
|
get tokenInterfaces() {
|
|
56
65
|
var _a, _b;
|
|
57
66
|
if (!this._tokenInterfaces) {
|
|
58
|
-
this._tokenInterfaces = ((_a = this.config) == null ? void 0 : _a.tokenInterfaces) ? Object.fromEntries(
|
|
59
|
-
|
|
60
|
-
tokenInterface,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
})) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
67
|
+
this._tokenInterfaces = ((_a = this.config) == null ? void 0 : _a.tokenInterfaces) ? Object.fromEntries(
|
|
68
|
+
(_b = this.config) == null ? void 0 : _b.tokenInterfaces.map((tokenInterface) => {
|
|
69
|
+
return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
|
|
70
|
+
})
|
|
71
|
+
) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
64
72
|
}
|
|
65
73
|
return this._tokenInterfaces;
|
|
66
74
|
}
|
|
@@ -99,26 +107,6 @@ var _EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDi
|
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
};
|
|
102
|
-
__name(_EvmTokenInterfaceImplementedDiviner, "EvmTokenInterfaceImplementedDiviner");
|
|
103
|
-
/**
|
|
104
|
-
* The list of supported token interfaces
|
|
105
|
-
*/
|
|
106
|
-
__publicField(_EvmTokenInterfaceImplementedDiviner, "SupportedTokenInterfaces", {
|
|
107
|
-
ERC1155: import_open_zeppelin_typechain.ERC1155__factory.abi,
|
|
108
|
-
ERC1155Metadata_URI: import_open_zeppelin_typechain.IERC1155MetadataURI__factory.abi,
|
|
109
|
-
ERC1155TokenReceiver: import_open_zeppelin_typechain.IERC1155Receiver__factory.abi,
|
|
110
|
-
ERC20: import_open_zeppelin_typechain.ERC20__factory.abi,
|
|
111
|
-
ERC721: import_open_zeppelin_typechain.ERC721__factory.abi,
|
|
112
|
-
ERC721Enumerable: import_open_zeppelin_typechain.IERC721Enumerable__factory.abi,
|
|
113
|
-
ERC721Metadata: import_open_zeppelin_typechain.IERC721Metadata__factory.abi,
|
|
114
|
-
ERC721TokenReceiver: import_open_zeppelin_typechain.IERC721Receiver__factory.abi
|
|
115
|
-
});
|
|
116
|
-
__publicField(_EvmTokenInterfaceImplementedDiviner, "configSchemas", [
|
|
117
|
-
...__superGet(_EvmTokenInterfaceImplementedDiviner, _EvmTokenInterfaceImplementedDiviner, "configSchemas"),
|
|
118
|
-
EvmTokenInterfaceImplementedDivinerConfigSchema
|
|
119
|
-
]);
|
|
120
|
-
__publicField(_EvmTokenInterfaceImplementedDiviner, "defaultConfigSchema", EvmTokenInterfaceImplementedDivinerConfigSchema);
|
|
121
|
-
var EvmTokenInterfaceImplementedDiviner = _EvmTokenInterfaceImplementedDiviner;
|
|
122
110
|
// Annotate the CommonJS export names for ESM import in node:
|
|
123
111
|
0 && (module.exports = {
|
|
124
112
|
EvmTokenInterfaceImplementedDiviner,
|
package/dist/node/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner.ts'\nexport * from './Payload.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner.ts'\nexport * from './Payload.ts'\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyB;AACzB,8BAAgC;AAEhC,kCAA2C;AAE3C,qCASO;AAEP,oBAAwC;;;AChBxC,2BAA+C;AAyBxC,IAAM,qCAAqC;AAkC3C,IAAM,qCAAiC,4CAAoD,kCAAkC;;;ADvC7H,IAAM,kDAAkD,GAAG,kCAAkC;AAgB7F,IAAM,sCAAN,MAAM,6CAEH,wCAAoE;AAAA;AAAA;AAAA;AAAA,EAI5E,OAAgB,2BAAsF;AAAA,IACpG,SAAS,gDAAiB;AAAA,IAC1B,qBAAqB,4DAA6B;AAAA,IAClD,sBAAsB,yDAA0B;AAAA,IAChD,OAAO,8CAAe;AAAA,IACtB,QAAQ,+CAAgB;AAAA,IACxB,kBAAkB,0DAA2B;AAAA,IAC7C,gBAAgB,wDAAyB;AAAA,IACzC,qBAAqB,wDAAyB;AAAA,EAChD;AAAA,EAEA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+CAA+C;AAAA,EAC3H,OAAyB,sBAA8B;AAAA,EAE/C;AAAA;AAAA;AAAA;AAAA,EAKR,IAAI,kBAAkB;AA7DxB;AA8DI,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,qBACD,UAAK,WAAL,mBAAa,mBACT,OAAO;AAAA,SACP,UAAK,WAAL,mBAAa,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG;AAAA,MACF,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC5C;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,aAA4B,CAAC,GAA4C;AAC9G,UAAM,KAAK,QAAQ,OAAO;AAC1B,QAAI;AACF,YAAM,aAAa,MAAM,QAAQ;AAAA;AAAA,QAE/B,WAAW,OAAO,yCAAa,EAAE,IAAI,CAAC,EAAE,SAAS,MAAM,QAAQ,MAAM;AAEnE,gBAAM,eAAW,wBAAS,MAAM,MAAM,cAAc;AACpD,gBAAM,UAA0C,CAAC;AAEjD,qBAAW,CAAC,gBAAgB,GAAG,KAAK,OAAO,QAAQ,KAAK,eAAe,GAAG;AAExE,kBAAM,oBAAoB,IAAI,wBAAU,GAAG;AAC3C,kBAAM,kBAA6B,CAAC;AACpC,8BAAkB,gBAAgB,CAAC,EAAE,SAAS,MAAM;AAClD,8BAAgB,KAAK,SAAS,SAAS,OAAO,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;AAAA,YACvE,CAAC;AACD,kBAAM,cAAc,gBAAgB,MAAM,OAAO;AACjD,kBAAM,SAAuC;AAAA,cAC3C;AAAA,cACA;AAAA,cACA;AAAA,cACA,QAAQ;AAAA,cACR;AAAA,YACF;AACA,oBAAQ,KAAK,MAAM;AAAA,UACrB;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO,WAAW,KAAK;AAAA,IACzB,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.mjs
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
-
var __reflectGet = Reflect.get;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
|
|
8
|
-
|
|
9
1
|
// src/Diviner.ts
|
|
10
2
|
import { assertEx } from "@xylabs/assert";
|
|
11
3
|
import { AbstractDiviner } from "@xyo-network/diviner-abstract";
|
|
12
4
|
import { isEvmContract } from "@xyo-network/evm-contract-witness";
|
|
13
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ERC20__factory,
|
|
7
|
+
ERC721__factory,
|
|
8
|
+
ERC1155__factory,
|
|
9
|
+
IERC721Enumerable__factory,
|
|
10
|
+
IERC721Metadata__factory,
|
|
11
|
+
IERC721Receiver__factory,
|
|
12
|
+
IERC1155MetadataURI__factory,
|
|
13
|
+
IERC1155Receiver__factory
|
|
14
|
+
} from "@xyo-network/open-zeppelin-typechain";
|
|
14
15
|
import { Interface } from "ethers";
|
|
15
16
|
|
|
16
17
|
// src/Payload.ts
|
|
@@ -20,20 +21,34 @@ var isEvmTokenInterfaceImplemented = isPayloadOfSchemaType(EvmTokenInterfaceImpl
|
|
|
20
21
|
|
|
21
22
|
// src/Diviner.ts
|
|
22
23
|
var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
|
|
23
|
-
var
|
|
24
|
+
var EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDiviner extends AbstractDiviner {
|
|
25
|
+
/**
|
|
26
|
+
* The list of supported token interfaces
|
|
27
|
+
*/
|
|
28
|
+
static SupportedTokenInterfaces = {
|
|
29
|
+
ERC1155: ERC1155__factory.abi,
|
|
30
|
+
ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,
|
|
31
|
+
ERC1155TokenReceiver: IERC1155Receiver__factory.abi,
|
|
32
|
+
ERC20: ERC20__factory.abi,
|
|
33
|
+
ERC721: ERC721__factory.abi,
|
|
34
|
+
ERC721Enumerable: IERC721Enumerable__factory.abi,
|
|
35
|
+
ERC721Metadata: IERC721Metadata__factory.abi,
|
|
36
|
+
ERC721TokenReceiver: IERC721Receiver__factory.abi
|
|
37
|
+
};
|
|
38
|
+
static configSchemas = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema];
|
|
39
|
+
static defaultConfigSchema = EvmTokenInterfaceImplementedDivinerConfigSchema;
|
|
24
40
|
_tokenInterfaces;
|
|
25
41
|
/**
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
* The list of token interfaces to check against the contract
|
|
43
|
+
*/
|
|
28
44
|
get tokenInterfaces() {
|
|
29
45
|
var _a, _b;
|
|
30
46
|
if (!this._tokenInterfaces) {
|
|
31
|
-
this._tokenInterfaces = ((_a = this.config) == null ? void 0 : _a.tokenInterfaces) ? Object.fromEntries(
|
|
32
|
-
|
|
33
|
-
tokenInterface,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
47
|
+
this._tokenInterfaces = ((_a = this.config) == null ? void 0 : _a.tokenInterfaces) ? Object.fromEntries(
|
|
48
|
+
(_b = this.config) == null ? void 0 : _b.tokenInterfaces.map((tokenInterface) => {
|
|
49
|
+
return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
|
|
50
|
+
})
|
|
51
|
+
) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
|
|
37
52
|
}
|
|
38
53
|
return this._tokenInterfaces;
|
|
39
54
|
}
|
|
@@ -72,26 +87,6 @@ var _EvmTokenInterfaceImplementedDiviner = class _EvmTokenInterfaceImplementedDi
|
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
89
|
};
|
|
75
|
-
__name(_EvmTokenInterfaceImplementedDiviner, "EvmTokenInterfaceImplementedDiviner");
|
|
76
|
-
/**
|
|
77
|
-
* The list of supported token interfaces
|
|
78
|
-
*/
|
|
79
|
-
__publicField(_EvmTokenInterfaceImplementedDiviner, "SupportedTokenInterfaces", {
|
|
80
|
-
ERC1155: ERC1155__factory.abi,
|
|
81
|
-
ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,
|
|
82
|
-
ERC1155TokenReceiver: IERC1155Receiver__factory.abi,
|
|
83
|
-
ERC20: ERC20__factory.abi,
|
|
84
|
-
ERC721: ERC721__factory.abi,
|
|
85
|
-
ERC721Enumerable: IERC721Enumerable__factory.abi,
|
|
86
|
-
ERC721Metadata: IERC721Metadata__factory.abi,
|
|
87
|
-
ERC721TokenReceiver: IERC721Receiver__factory.abi
|
|
88
|
-
});
|
|
89
|
-
__publicField(_EvmTokenInterfaceImplementedDiviner, "configSchemas", [
|
|
90
|
-
...__superGet(_EvmTokenInterfaceImplementedDiviner, _EvmTokenInterfaceImplementedDiviner, "configSchemas"),
|
|
91
|
-
EvmTokenInterfaceImplementedDivinerConfigSchema
|
|
92
|
-
]);
|
|
93
|
-
__publicField(_EvmTokenInterfaceImplementedDiviner, "defaultConfigSchema", EvmTokenInterfaceImplementedDivinerConfigSchema);
|
|
94
|
-
var EvmTokenInterfaceImplementedDiviner = _EvmTokenInterfaceImplementedDiviner;
|
|
95
90
|
export {
|
|
96
91
|
EvmTokenInterfaceImplementedDiviner,
|
|
97
92
|
EvmTokenInterfaceImplementedDivinerConfigSchema,
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["import { assertEx } from '@xylabs/assert'\nimport { AbstractDiviner } from '@xyo-network/diviner-abstract'\nimport { DivinerConfig, DivinerParams } from '@xyo-network/diviner-model'\nimport { EvmContract, isEvmContract } from '@xyo-network/evm-contract-witness'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport {\n ERC20__factory,\n ERC721__factory,\n ERC1155__factory,\n IERC721Enumerable__factory,\n IERC721Metadata__factory,\n IERC721Receiver__factory,\n IERC1155MetadataURI__factory,\n IERC1155Receiver__factory,\n} from '@xyo-network/open-zeppelin-typechain'\nimport { Schema } from '@xyo-network/payload-model'\nimport { Interface, JsonFragment } from 'ethers'\n\nimport { EvmTokenInterfaceImplemented, EvmTokenInterfaceImplementedSchema, TokenInterface } from './Payload.ts'\n\nexport const EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`\nexport type EvmTokenInterfaceImplementedDivinerConfigSchema = typeof EvmTokenInterfaceImplementedDivinerConfigSchema\n\nexport type EvmTokenInterfaceImplementedDivinerConfig = DivinerConfig<{\n schema: EvmTokenInterfaceImplementedDivinerConfigSchema\n tokenInterfaces?: TokenInterface[]\n}>\n\nexport type EvmTokenInterfaceImplementedDivinerParams = DivinerParams<AnyConfigSchema<EvmTokenInterfaceImplementedDivinerConfig>>\n\ntype DistributiveMappedType<T> = T extends string ? { [K in T]: readonly JsonFragment[] } : never\ntype TokenInterfaceDictionary = DistributiveMappedType<TokenInterface>\n\n/**\n * A diviner that checks if a contract implements a token interface\n */\nexport class EvmTokenInterfaceImplementedDiviner<\n TParams extends EvmTokenInterfaceImplementedDivinerParams = EvmTokenInterfaceImplementedDivinerParams,\n> extends AbstractDiviner<TParams, EvmContract, EvmTokenInterfaceImplemented> {\n /**\n * The list of supported token interfaces\n */\n static readonly SupportedTokenInterfaces: Readonly<Record<TokenInterface, readonly JsonFragment[]>> = {\n ERC1155: ERC1155__factory.abi,\n ERC1155Metadata_URI: IERC1155MetadataURI__factory.abi,\n ERC1155TokenReceiver: IERC1155Receiver__factory.abi,\n ERC20: ERC20__factory.abi,\n ERC721: ERC721__factory.abi,\n ERC721Enumerable: IERC721Enumerable__factory.abi,\n ERC721Metadata: IERC721Metadata__factory.abi,\n ERC721TokenReceiver: IERC721Receiver__factory.abi,\n }\n\n static override readonly configSchemas: Schema[] = [...super.configSchemas, EvmTokenInterfaceImplementedDivinerConfigSchema]\n static override readonly defaultConfigSchema: Schema = EvmTokenInterfaceImplementedDivinerConfigSchema\n\n private _tokenInterfaces?: TokenInterfaceDictionary\n\n /**\n * The list of token interfaces to check against the contract\n */\n get tokenInterfaces() {\n if (!this._tokenInterfaces) {\n this._tokenInterfaces\n = this.config?.tokenInterfaces\n ? ((Object.fromEntries(\n this.config?.tokenInterfaces.map((tokenInterface) => {\n return [tokenInterface, EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]] as const\n }),\n ) as TokenInterfaceDictionary) ?? {})\n : EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces\n }\n return this._tokenInterfaces\n }\n\n protected override async divineHandler(inPayloads: EvmContract[] = []): Promise<EvmTokenInterfaceImplemented[]> {\n await this.started('throw')\n try {\n const allResults = await Promise.all(\n // Iterate over each contract passed in\n inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {\n // Ensure we have the contract code\n const byteCode = assertEx(code, () => 'Missing code')\n const results: EvmTokenInterfaceImplemented[] = []\n // Iterate over each token interface\n for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {\n // Check if the contract implements the interface abi\n const contractInterface = new Interface(abi)\n const implementations: boolean[] = []\n contractInterface.forEachFunction(({ selector }) => {\n implementations.push(byteCode.includes(BigInt(selector).toString(16)))\n })\n const implemented = implementations.every(Boolean)\n const result: EvmTokenInterfaceImplemented = {\n address,\n chainId,\n implemented,\n schema: EvmTokenInterfaceImplementedSchema,\n tokenInterface: tokenInterface as TokenInterface,\n }\n results.push(result)\n }\n\n return results\n }),\n )\n return allResults.flat()\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","import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\n\n/**\n * ERC20 Token Interfaces\n */\nexport type ERC20TokenInterfaces = 'ERC20'\n\n/**\n * ERC721 Token Interfaces\n */\nexport type ERC721TokenInterfaces = 'ERC721' | 'ERC721TokenReceiver' | 'ERC721Metadata' | 'ERC721Enumerable'\n\n/**\n * ERC1155 Token Interfaces\n */\nexport type ERC1155TokenInterfaces = 'ERC1155' | 'ERC1155TokenReceiver' | 'ERC1155Metadata_URI'\n\n/**\n * All Token Interfaces\n */\nexport type TokenInterface = ERC20TokenInterfaces | ERC721TokenInterfaces | ERC1155TokenInterfaces\n\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport const EvmTokenInterfaceImplementedSchema = 'network.xyo.evm.token.interface.implemented'\n/**\n * The schema for the EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplementedSchema = typeof EvmTokenInterfaceImplementedSchema\n\n/**\n * The EVM Token Interface Implemented payload\n */\nexport type EvmTokenInterfaceImplemented = Payload<\n {\n /**\n * The contract address\n */\n address: string\n /**\n * The chain id\n */\n chainId: number\n /**\n * True if the contract implements the interface\n */\n implemented: boolean\n /**\n * The specific token interface\n */\n tokenInterface: TokenInterface\n },\n EvmTokenInterfaceImplementedSchema\n>\n\n/**\n * Identity function for EvmTokenInterfaceImplemented payload\n */\nexport const isEvmTokenInterfaceImplemented = isPayloadOfSchemaType<EvmTokenInterfaceImplemented>(EvmTokenInterfaceImplementedSchema)\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAEhC,SAAsB,qBAAqB;AAE3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,iBAA+B;;;AChBxC,SAAS,6BAAsC;AAyBxC,IAAM,qCAAqC;AAkC3C,IAAM,iCAAiC,sBAAoD,kCAAkC;;;ADvC7H,IAAM,kDAAkD,GAAG,kCAAkC;AAgB7F,IAAM,sCAAN,MAAM,6CAEH,gBAAoE;AAAA;AAAA;AAAA;AAAA,EAI5E,OAAgB,2BAAsF;AAAA,IACpG,SAAS,iBAAiB;AAAA,IAC1B,qBAAqB,6BAA6B;AAAA,IAClD,sBAAsB,0BAA0B;AAAA,IAChD,OAAO,eAAe;AAAA,IACtB,QAAQ,gBAAgB;AAAA,IACxB,kBAAkB,2BAA2B;AAAA,IAC7C,gBAAgB,yBAAyB;AAAA,IACzC,qBAAqB,yBAAyB;AAAA,EAChD;AAAA,EAEA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+CAA+C;AAAA,EAC3H,OAAyB,sBAA8B;AAAA,EAE/C;AAAA;AAAA;AAAA;AAAA,EAKR,IAAI,kBAAkB;AA7DxB;AA8DI,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,qBACD,UAAK,WAAL,mBAAa,mBACT,OAAO;AAAA,SACP,UAAK,WAAL,mBAAa,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG;AAAA,MACF,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC5C;AACA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAyB,cAAc,aAA4B,CAAC,GAA4C;AAC9G,UAAM,KAAK,QAAQ,OAAO;AAC1B,QAAI;AACF,YAAM,aAAa,MAAM,QAAQ;AAAA;AAAA,QAE/B,WAAW,OAAO,aAAa,EAAE,IAAI,CAAC,EAAE,SAAS,MAAM,QAAQ,MAAM;AAEnE,gBAAM,WAAW,SAAS,MAAM,MAAM,cAAc;AACpD,gBAAM,UAA0C,CAAC;AAEjD,qBAAW,CAAC,gBAAgB,GAAG,KAAK,OAAO,QAAQ,KAAK,eAAe,GAAG;AAExE,kBAAM,oBAAoB,IAAI,UAAU,GAAG;AAC3C,kBAAM,kBAA6B,CAAC;AACpC,8BAAkB,gBAAgB,CAAC,EAAE,SAAS,MAAM;AAClD,8BAAgB,KAAK,SAAS,SAAS,OAAO,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;AAAA,YACvE,CAAC;AACD,kBAAM,cAAc,gBAAgB,MAAM,OAAO;AACjD,kBAAM,SAAuC;AAAA,cAC3C;AAAA,cACA;AAAA,cACA;AAAA,cACA,QAAQ;AAAA,cACR;AAAA,YACF;AACA,oBAAQ,KAAK,MAAM;AAAA,UACrB;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AACA,aAAO,WAAW,KAAK;AAAA,IACzB,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,36 +10,36 @@
|
|
|
10
10
|
"url": "https://github.com/XYOracleNetwork/plugins/issues"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@xylabs/assert": "^3.6.
|
|
14
|
-
"@xyo-network/diviner-abstract": "^2.111.
|
|
15
|
-
"@xyo-network/diviner-model": "^2.111.
|
|
16
|
-
"@xyo-network/evm-contract-witness": "^2.99.
|
|
17
|
-
"@xyo-network/module-model": "^2.111.
|
|
18
|
-
"@xyo-network/open-zeppelin-typechain": "^3.0
|
|
19
|
-
"@xyo-network/payload-model": "^2.111.
|
|
13
|
+
"@xylabs/assert": "^3.6.12",
|
|
14
|
+
"@xyo-network/diviner-abstract": "^2.111.3",
|
|
15
|
+
"@xyo-network/diviner-model": "^2.111.3",
|
|
16
|
+
"@xyo-network/evm-contract-witness": "^2.99.6",
|
|
17
|
+
"@xyo-network/module-model": "^2.111.3",
|
|
18
|
+
"@xyo-network/open-zeppelin-typechain": "^3.1.0",
|
|
19
|
+
"@xyo-network/payload-model": "^2.111.3",
|
|
20
20
|
"ethers": "^6.13.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@xylabs/delay": "^3.6.
|
|
24
|
-
"@xylabs/jest-helpers": "^3.6.
|
|
25
|
-
"@xylabs/ts-scripts-yarn3": "^3.15.
|
|
26
|
-
"@xylabs/tsconfig": "^3.15.
|
|
27
|
-
"@xyo-network/account": "^2.111.
|
|
28
|
-
"@xyo-network/archivist-memory": "^2.111.
|
|
29
|
-
"@xyo-network/boundwitness-model": "^2.111.
|
|
30
|
-
"@xyo-network/diviner-boundwitness-memory": "^2.111.
|
|
31
|
-
"@xyo-network/diviner-jsonpatch": "^2.111.
|
|
32
|
-
"@xyo-network/diviner-payload-memory": "^2.111.
|
|
33
|
-
"@xyo-network/diviner-payload-model": "^2.111.
|
|
34
|
-
"@xyo-network/diviner-stateful": "^2.111.
|
|
35
|
-
"@xyo-network/diviner-temporal-indexing": "^2.111.
|
|
36
|
-
"@xyo-network/manifest": "^2.111.
|
|
37
|
-
"@xyo-network/module-factory-locator": "^2.111.
|
|
38
|
-
"@xyo-network/node-memory": "^2.111.
|
|
39
|
-
"@xyo-network/open-zeppelin-typechain": "^3.0
|
|
40
|
-
"@xyo-network/sentinel-model": "^2.111.
|
|
41
|
-
"@xyo-network/witness-evm-abstract": "^2.111.
|
|
42
|
-
"@xyo-network/witness-timestamp": "^2.111.
|
|
23
|
+
"@xylabs/delay": "^3.6.12",
|
|
24
|
+
"@xylabs/jest-helpers": "^3.6.12",
|
|
25
|
+
"@xylabs/ts-scripts-yarn3": "^3.15.14",
|
|
26
|
+
"@xylabs/tsconfig": "^3.15.14",
|
|
27
|
+
"@xyo-network/account": "^2.111.3",
|
|
28
|
+
"@xyo-network/archivist-memory": "^2.111.3",
|
|
29
|
+
"@xyo-network/boundwitness-model": "^2.111.3",
|
|
30
|
+
"@xyo-network/diviner-boundwitness-memory": "^2.111.3",
|
|
31
|
+
"@xyo-network/diviner-jsonpatch": "^2.111.3",
|
|
32
|
+
"@xyo-network/diviner-payload-memory": "^2.111.3",
|
|
33
|
+
"@xyo-network/diviner-payload-model": "^2.111.3",
|
|
34
|
+
"@xyo-network/diviner-stateful": "^2.111.3",
|
|
35
|
+
"@xyo-network/diviner-temporal-indexing": "^2.111.3",
|
|
36
|
+
"@xyo-network/manifest": "^2.111.3",
|
|
37
|
+
"@xyo-network/module-factory-locator": "^2.111.3",
|
|
38
|
+
"@xyo-network/node-memory": "^2.111.3",
|
|
39
|
+
"@xyo-network/open-zeppelin-typechain": "^3.1.0",
|
|
40
|
+
"@xyo-network/sentinel-model": "^2.111.3",
|
|
41
|
+
"@xyo-network/witness-evm-abstract": "^2.111.3",
|
|
42
|
+
"@xyo-network/witness-timestamp": "^2.111.3",
|
|
43
43
|
"jest": "^29.7.0",
|
|
44
44
|
"typescript": "^5.5.4"
|
|
45
45
|
},
|
|
@@ -82,6 +82,6 @@
|
|
|
82
82
|
"url": "https://github.com/XYOracleNetwork/plugins.git"
|
|
83
83
|
},
|
|
84
84
|
"sideEffects": false,
|
|
85
|
-
"version": "2.99.
|
|
85
|
+
"version": "2.99.6",
|
|
86
86
|
"type": "module"
|
|
87
87
|
}
|