@xyo-network/evm-token-interface-diviner 2.97.0 → 2.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,109 @@
1
- "use strict";var c=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var _=(n,t)=>{for(var r in t)c(n,r,{get:t[r],enumerable:!0})},D=(n,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of b(t))!x.call(n,a)&&a!==r&&c(n,a,{get:()=>t[a],enumerable:!(o=S(t,a))||o.enumerable});return n};var P=n=>D(c({},"__esModule",{value:!0}),n);var w={};_(w,{EvmTokenInterfaceImplementedDiviner:()=>f,EvmTokenInterfaceImplementedDivinerConfigSchema:()=>i,EvmTokenInterfaceImplementedSchema:()=>m,isEvmTokenInterfaceImplemented:()=>M});module.exports=P(w);var d=require("@xylabs/assert"),E=require("@xyo-network/diviner-abstract"),l=require("@xyo-network/evm-contract-witness"),e=require("@xyo-network/open-zeppelin-typechain"),k=require("ethers");var p=require("@xyo-network/payload-model"),m="network.xyo.evm.token.interface.implemented",M=(0,p.isPayloadOfSchemaType)(m);var i=`${m}.diviner.config`,f=class n extends E.AbstractDiviner{static SupportedTokenInterfaces={ERC1155:e.ERC1155__factory.abi,ERC1155Metadata_URI:e.IERC1155MetadataURI__factory.abi,ERC1155TokenReceiver:e.IERC1155Receiver__factory.abi,ERC20:e.ERC20__factory.abi,ERC721:e.ERC721__factory.abi,ERC721Enumerable:e.IERC721Enumerable__factory.abi,ERC721Metadata:e.IERC721Metadata__factory.abi,ERC721TokenReceiver:e.IERC721Receiver__factory.abi};static configSchemas=[...super.configSchemas,i];static defaultConfigSchema=i;_tokenInterfaces;get tokenInterfaces(){return this._tokenInterfaces||(this._tokenInterfaces=this.config?.tokenInterfaces?Object.fromEntries(this.config?.tokenInterfaces.map(t=>[t,n.SupportedTokenInterfaces[t]]))??{}:n.SupportedTokenInterfaces),this._tokenInterfaces}async divineHandler(t=[]){await this.started("throw");try{return(await Promise.all(t.filter(l.isEvmContract).map(({address:o,code:a,chainId:v})=>{let T=(0,d.assertEx)(a,()=>"Missing code"),s=[];for(let[C,y]of Object.entries(this.tokenInterfaces)){let R=new k.Interface(y),I=[];R.forEachFunction(({selector:u})=>{I.push(T.includes(BigInt(u).toString(16)))});let h=I.every(Boolean),g={address:o,chainId:v,implemented:h,schema:m,tokenInterface:C};s.push(g)}return s}))).flat()}catch(r){let o=r;throw console.log(`Error [${this.config.name}]: ${o.message}`),o}}};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ EvmTokenInterfaceImplementedDiviner: () => EvmTokenInterfaceImplementedDiviner,
24
+ EvmTokenInterfaceImplementedDivinerConfigSchema: () => EvmTokenInterfaceImplementedDivinerConfigSchema,
25
+ EvmTokenInterfaceImplementedSchema: () => EvmTokenInterfaceImplementedSchema,
26
+ isEvmTokenInterfaceImplemented: () => isEvmTokenInterfaceImplemented
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/Diviner.ts
31
+ var import_assert = require("@xylabs/assert");
32
+ var import_diviner_abstract = require("@xyo-network/diviner-abstract");
33
+ var import_evm_contract_witness = require("@xyo-network/evm-contract-witness");
34
+ var import_open_zeppelin_typechain = require("@xyo-network/open-zeppelin-typechain");
35
+ var import_ethers = require("ethers");
36
+
37
+ // src/Payload.ts
38
+ var import_payload_model = require("@xyo-network/payload-model");
39
+ var EvmTokenInterfaceImplementedSchema = "network.xyo.evm.token.interface.implemented";
40
+ var isEvmTokenInterfaceImplemented = (0, import_payload_model.isPayloadOfSchemaType)(EvmTokenInterfaceImplementedSchema);
41
+
42
+ // src/Diviner.ts
43
+ var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
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;
60
+ _tokenInterfaces;
61
+ /**
62
+ * The list of token interfaces to check against the contract
63
+ */
64
+ get tokenInterfaces() {
65
+ if (!this._tokenInterfaces) {
66
+ this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
67
+ this.config?.tokenInterfaces.map((tokenInterface) => {
68
+ return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
69
+ })
70
+ ) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
71
+ }
72
+ return this._tokenInterfaces;
73
+ }
74
+ async divineHandler(inPayloads = []) {
75
+ await this.started("throw");
76
+ try {
77
+ const allResults = await Promise.all(
78
+ // Iterate over each contract passed in
79
+ inPayloads.filter(import_evm_contract_witness.isEvmContract).map(({ address, code, chainId }) => {
80
+ const byteCode = (0, import_assert.assertEx)(code, () => "Missing code");
81
+ const results = [];
82
+ for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {
83
+ const contractInterface = new import_ethers.Interface(abi);
84
+ const implementations = [];
85
+ contractInterface.forEachFunction(({ selector }) => {
86
+ implementations.push(byteCode.includes(BigInt(selector).toString(16)));
87
+ });
88
+ const implemented = implementations.every(Boolean);
89
+ const result = {
90
+ address,
91
+ chainId,
92
+ implemented,
93
+ schema: EvmTokenInterfaceImplementedSchema,
94
+ tokenInterface
95
+ };
96
+ results.push(result);
97
+ }
98
+ return results;
99
+ })
100
+ );
101
+ return allResults.flat();
102
+ } catch (ex) {
103
+ const error = ex;
104
+ console.log(`Error [${this.config.name}]: ${error.message}`);
105
+ throw error;
106
+ }
107
+ }
108
+ };
2
109
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './Payload'\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'\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 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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yCAAAE,EAAA,oDAAAC,EAAA,uCAAAC,EAAA,mCAAAC,IAAA,eAAAC,EAAAN,GCAA,IAAAO,EAAyB,0BACzBC,EAAgC,yCAEhCC,EAA2C,6CAE3CC,EASO,gDAEPC,EAAwC,kBChBxC,IAAAC,EAA+C,sCAyBlCC,EAAqC,8CAkCrCC,KAAiC,yBAAoDD,CAAkC,EDvC7H,IAAME,EAAkD,GAAGC,CAAkC,kBAgBvFC,EAAN,MAAMC,UAEH,iBAAoE,CAI5E,OAAgB,yBAAsF,CACpG,QAAS,mBAAiB,IAC1B,oBAAqB,+BAA6B,IAClD,qBAAsB,4BAA0B,IAChD,MAAO,iBAAe,IACtB,OAAQ,kBAAgB,IACxB,iBAAkB,6BAA2B,IAC7C,eAAgB,2BAAyB,IACzC,oBAAqB,2BAAyB,GAChD,EACA,OAAyB,cAA0B,CAAC,GAAG,MAAM,cAAeH,CAA+C,EAC3H,OAAyB,oBAA8BA,EAE/C,iBAKR,IAAI,iBAAkB,CACpB,OAAK,KAAK,mBACR,KAAK,iBACH,KAAK,QAAQ,gBACV,OAAO,YACN,KAAK,QAAQ,gBAAgB,IAAKI,GACzB,CAACA,EAAgBD,EAAoC,yBAAyBC,CAAc,CAAC,CACrG,CACH,GAAkC,CAAC,EACnCD,EAAoC,0BAEnC,KAAK,gBACd,CAEA,MAAyB,cAAcE,EAA4B,CAAC,EAA4C,CAC9G,MAAM,KAAK,QAAQ,OAAO,EAC1B,GAAI,CA6BF,OA5BmB,MAAM,QAAQ,IAE/BA,EAAW,OAAO,eAAa,EAAE,IAAI,CAAC,CAAE,QAAAC,EAAS,KAAAC,EAAM,QAAAC,CAAQ,IAAM,CAEnE,IAAMC,KAAW,YAASF,EAAM,IAAM,cAAc,EAC9CG,EAA0C,CAAC,EAEjD,OAAW,CAACN,EAAgBO,CAAG,IAAK,OAAO,QAAQ,KAAK,eAAe,EAAG,CAExE,IAAMC,EAAoB,IAAI,YAAUD,CAAG,EACrCE,EAA6B,CAAC,EACpCD,EAAkB,gBAAgB,CAAC,CAAE,SAAAE,CAAS,IAAM,CAClDD,EAAgB,KAAKJ,EAAS,SAAS,OAAOK,CAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CACvE,CAAC,EACD,IAAMC,EAAcF,EAAgB,MAAM,OAAO,EAC3CG,EAAuC,CAC3C,QAAAV,EACA,QAAAE,EACA,YAAAO,EACA,OAAQd,EACR,eAAgBG,CAClB,EACAM,EAAQ,KAAKM,CAAM,CACrB,CAEA,OAAON,CACT,CAAC,CACH,GACkB,KAAK,CACzB,OAASO,EAAI,CACX,IAAMC,EAAQD,EACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAMC,EAAM,OAAO,EAAE,EACrDA,CACR,CACF,CACF","names":["src_exports","__export","EvmTokenInterfaceImplementedDiviner","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","__toCommonJS","import_assert","import_diviner_abstract","import_evm_contract_witness","import_open_zeppelin_typechain","import_ethers","import_payload_model","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","EvmTokenInterfaceImplementedDiviner","_EvmTokenInterfaceImplementedDiviner","tokenInterface","inPayloads","address","code","chainId","byteCode","results","abi","contractInterface","implementations","selector","implemented","result","ex","error"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './Payload'\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'\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 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,EACA,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,mBACH,KAAK,QAAQ,kBACV,OAAO;AAAA,QACN,KAAK,QAAQ,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG,CAAC;AAAA,MACH,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC1C;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":[]}
@@ -1,2 +1,95 @@
1
- import{assertEx as C}from"@xylabs/assert";import{AbstractDiviner as y}from"@xyo-network/diviner-abstract";import{isEvmContract as R}from"@xyo-network/evm-contract-witness";import{ERC20__factory as h,ERC721__factory as g,ERC1155__factory as u,IERC721Enumerable__factory as S,IERC721Metadata__factory as b,IERC721Receiver__factory as x,IERC1155MetadataURI__factory as _,IERC1155Receiver__factory as D}from"@xyo-network/open-zeppelin-typechain";import{Interface as P}from"ethers";import{isPayloadOfSchemaType as T}from"@xyo-network/payload-model";var n="network.xyo.evm.token.interface.implemented",F=T(n);var c=`${n}.diviner.config`,i=class r extends y{static SupportedTokenInterfaces={ERC1155:u.abi,ERC1155Metadata_URI:_.abi,ERC1155TokenReceiver:D.abi,ERC20:h.abi,ERC721:g.abi,ERC721Enumerable:S.abi,ERC721Metadata:b.abi,ERC721TokenReceiver:x.abi};static configSchemas=[...super.configSchemas,c];static defaultConfigSchema=c;_tokenInterfaces;get tokenInterfaces(){return this._tokenInterfaces||(this._tokenInterfaces=this.config?.tokenInterfaces?Object.fromEntries(this.config?.tokenInterfaces.map(e=>[e,r.SupportedTokenInterfaces[e]]))??{}:r.SupportedTokenInterfaces),this._tokenInterfaces}async divineHandler(e=[]){await this.started("throw");try{return(await Promise.all(e.filter(R).map(({address:t,code:f,chainId:s})=>{let I=C(f,()=>"Missing code"),a=[];for(let[p,d]of Object.entries(this.tokenInterfaces)){let E=new P(d),m=[];E.forEachFunction(({selector:v})=>{m.push(I.includes(BigInt(v).toString(16)))});let l=m.every(Boolean),k={address:t,chainId:s,implemented:l,schema:n,tokenInterface:p};a.push(k)}return a}))).flat()}catch(o){let t=o;throw console.log(`Error [${this.config.name}]: ${t.message}`),t}}};export{i as EvmTokenInterfaceImplementedDiviner,c as EvmTokenInterfaceImplementedDivinerConfigSchema,n as EvmTokenInterfaceImplementedSchema,F as isEvmTokenInterfaceImplemented};
1
+ // src/Diviner.ts
2
+ import { assertEx } from "@xylabs/assert";
3
+ import { AbstractDiviner } from "@xyo-network/diviner-abstract";
4
+ import { isEvmContract } from "@xyo-network/evm-contract-witness";
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";
15
+ import { Interface } from "ethers";
16
+
17
+ // src/Payload.ts
18
+ import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
19
+ var EvmTokenInterfaceImplementedSchema = "network.xyo.evm.token.interface.implemented";
20
+ var isEvmTokenInterfaceImplemented = isPayloadOfSchemaType(EvmTokenInterfaceImplementedSchema);
21
+
22
+ // src/Diviner.ts
23
+ var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
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;
40
+ _tokenInterfaces;
41
+ /**
42
+ * The list of token interfaces to check against the contract
43
+ */
44
+ get tokenInterfaces() {
45
+ if (!this._tokenInterfaces) {
46
+ this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
47
+ this.config?.tokenInterfaces.map((tokenInterface) => {
48
+ return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
49
+ })
50
+ ) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
51
+ }
52
+ return this._tokenInterfaces;
53
+ }
54
+ async divineHandler(inPayloads = []) {
55
+ await this.started("throw");
56
+ try {
57
+ const allResults = await Promise.all(
58
+ // Iterate over each contract passed in
59
+ inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {
60
+ const byteCode = assertEx(code, () => "Missing code");
61
+ const results = [];
62
+ for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {
63
+ const contractInterface = new Interface(abi);
64
+ const implementations = [];
65
+ contractInterface.forEachFunction(({ selector }) => {
66
+ implementations.push(byteCode.includes(BigInt(selector).toString(16)));
67
+ });
68
+ const implemented = implementations.every(Boolean);
69
+ const result = {
70
+ address,
71
+ chainId,
72
+ implemented,
73
+ schema: EvmTokenInterfaceImplementedSchema,
74
+ tokenInterface
75
+ };
76
+ results.push(result);
77
+ }
78
+ return results;
79
+ })
80
+ );
81
+ return allResults.flat();
82
+ } catch (ex) {
83
+ const error = ex;
84
+ console.log(`Error [${this.config.name}]: ${error.message}`);
85
+ throw error;
86
+ }
87
+ }
88
+ };
89
+ export {
90
+ EvmTokenInterfaceImplementedDiviner,
91
+ EvmTokenInterfaceImplementedDivinerConfigSchema,
92
+ EvmTokenInterfaceImplementedSchema,
93
+ isEvmTokenInterfaceImplemented
94
+ };
2
95
  //# sourceMappingURL=index.js.map
@@ -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'\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 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,OAAS,YAAAA,MAAgB,iBACzB,OAAS,mBAAAC,MAAuB,gCAEhC,OAAsB,iBAAAC,MAAqB,oCAE3C,OACE,kBAAAC,EACA,mBAAAC,EACA,oBAAAC,EACA,8BAAAC,EACA,4BAAAC,EACA,4BAAAC,EACA,gCAAAC,EACA,6BAAAC,MACK,uCAEP,OAAS,aAAAC,MAA+B,SChBxC,OAAS,yBAAAC,MAAsC,6BAyBxC,IAAMC,EAAqC,8CAkCrCC,EAAiCF,EAAoDC,CAAkC,EDvC7H,IAAME,EAAkD,GAAGC,CAAkC,kBAgBvFC,EAAN,MAAMC,UAEHC,CAAoE,CAI5E,OAAgB,yBAAsF,CACpG,QAASC,EAAiB,IAC1B,oBAAqBC,EAA6B,IAClD,qBAAsBC,EAA0B,IAChD,MAAOC,EAAe,IACtB,OAAQC,EAAgB,IACxB,iBAAkBC,EAA2B,IAC7C,eAAgBC,EAAyB,IACzC,oBAAqBC,EAAyB,GAChD,EACA,OAAyB,cAA0B,CAAC,GAAG,MAAM,cAAeZ,CAA+C,EAC3H,OAAyB,oBAA8BA,EAE/C,iBAKR,IAAI,iBAAkB,CACpB,OAAK,KAAK,mBACR,KAAK,iBACH,KAAK,QAAQ,gBACV,OAAO,YACN,KAAK,QAAQ,gBAAgB,IAAKa,GACzB,CAACA,EAAgBV,EAAoC,yBAAyBU,CAAc,CAAC,CACrG,CACH,GAAkC,CAAC,EACnCV,EAAoC,0BAEnC,KAAK,gBACd,CAEA,MAAyB,cAAcW,EAA4B,CAAC,EAA4C,CAC9G,MAAM,KAAK,QAAQ,OAAO,EAC1B,GAAI,CA6BF,OA5BmB,MAAM,QAAQ,IAE/BA,EAAW,OAAOC,CAAa,EAAE,IAAI,CAAC,CAAE,QAAAC,EAAS,KAAAC,EAAM,QAAAC,CAAQ,IAAM,CAEnE,IAAMC,EAAWC,EAASH,EAAM,IAAM,cAAc,EAC9CI,EAA0C,CAAC,EAEjD,OAAW,CAACR,EAAgBS,CAAG,IAAK,OAAO,QAAQ,KAAK,eAAe,EAAG,CAExE,IAAMC,EAAoB,IAAIC,EAAUF,CAAG,EACrCG,EAA6B,CAAC,EACpCF,EAAkB,gBAAgB,CAAC,CAAE,SAAAG,CAAS,IAAM,CAClDD,EAAgB,KAAKN,EAAS,SAAS,OAAOO,CAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CACvE,CAAC,EACD,IAAMC,EAAcF,EAAgB,MAAM,OAAO,EAC3CG,EAAuC,CAC3C,QAAAZ,EACA,QAAAE,EACA,YAAAS,EACA,OAAQ1B,EACR,eAAgBY,CAClB,EACAQ,EAAQ,KAAKO,CAAM,CACrB,CAEA,OAAOP,CACT,CAAC,CACH,GACkB,KAAK,CACzB,OAASQ,EAAI,CACX,IAAMC,EAAQD,EACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAMC,EAAM,OAAO,EAAE,EACrDA,CACR,CACF,CACF","names":["assertEx","AbstractDiviner","isEvmContract","ERC20__factory","ERC721__factory","ERC1155__factory","IERC721Enumerable__factory","IERC721Metadata__factory","IERC721Receiver__factory","IERC1155MetadataURI__factory","IERC1155Receiver__factory","Interface","isPayloadOfSchemaType","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","EvmTokenInterfaceImplementedDiviner","_EvmTokenInterfaceImplementedDiviner","AbstractDiviner","ERC1155__factory","IERC1155MetadataURI__factory","IERC1155Receiver__factory","ERC20__factory","ERC721__factory","IERC721Enumerable__factory","IERC721Metadata__factory","IERC721Receiver__factory","tokenInterface","inPayloads","isEvmContract","address","code","chainId","byteCode","assertEx","results","abi","contractInterface","Interface","implementations","selector","implemented","result","ex","error"]}
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'\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 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,EACA,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,mBACH,KAAK,QAAQ,kBACV,OAAO;AAAA,QACN,KAAK,QAAQ,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG,CAAC;AAAA,MACH,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC1C;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":[]}
@@ -1,2 +1,109 @@
1
- "use strict";var c=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var _=(n,t)=>{for(var r in t)c(n,r,{get:t[r],enumerable:!0})},D=(n,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of b(t))!x.call(n,a)&&a!==r&&c(n,a,{get:()=>t[a],enumerable:!(o=S(t,a))||o.enumerable});return n};var P=n=>D(c({},"__esModule",{value:!0}),n);var w={};_(w,{EvmTokenInterfaceImplementedDiviner:()=>f,EvmTokenInterfaceImplementedDivinerConfigSchema:()=>i,EvmTokenInterfaceImplementedSchema:()=>m,isEvmTokenInterfaceImplemented:()=>M});module.exports=P(w);var d=require("@xylabs/assert"),E=require("@xyo-network/diviner-abstract"),l=require("@xyo-network/evm-contract-witness"),e=require("@xyo-network/open-zeppelin-typechain"),k=require("ethers");var p=require("@xyo-network/payload-model"),m="network.xyo.evm.token.interface.implemented",M=(0,p.isPayloadOfSchemaType)(m);var i=`${m}.diviner.config`,f=class n extends E.AbstractDiviner{static SupportedTokenInterfaces={ERC1155:e.ERC1155__factory.abi,ERC1155Metadata_URI:e.IERC1155MetadataURI__factory.abi,ERC1155TokenReceiver:e.IERC1155Receiver__factory.abi,ERC20:e.ERC20__factory.abi,ERC721:e.ERC721__factory.abi,ERC721Enumerable:e.IERC721Enumerable__factory.abi,ERC721Metadata:e.IERC721Metadata__factory.abi,ERC721TokenReceiver:e.IERC721Receiver__factory.abi};static configSchemas=[...super.configSchemas,i];static defaultConfigSchema=i;_tokenInterfaces;get tokenInterfaces(){return this._tokenInterfaces||(this._tokenInterfaces=this.config?.tokenInterfaces?Object.fromEntries(this.config?.tokenInterfaces.map(t=>[t,n.SupportedTokenInterfaces[t]]))??{}:n.SupportedTokenInterfaces),this._tokenInterfaces}async divineHandler(t=[]){await this.started("throw");try{return(await Promise.all(t.filter(l.isEvmContract).map(({address:o,code:a,chainId:v})=>{let T=(0,d.assertEx)(a,()=>"Missing code"),s=[];for(let[C,y]of Object.entries(this.tokenInterfaces)){let R=new k.Interface(y),I=[];R.forEachFunction(({selector:u})=>{I.push(T.includes(BigInt(u).toString(16)))});let h=I.every(Boolean),g={address:o,chainId:v,implemented:h,schema:m,tokenInterface:C};s.push(g)}return s}))).flat()}catch(r){let o=r;throw console.log(`Error [${this.config.name}]: ${o.message}`),o}}};
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ EvmTokenInterfaceImplementedDiviner: () => EvmTokenInterfaceImplementedDiviner,
24
+ EvmTokenInterfaceImplementedDivinerConfigSchema: () => EvmTokenInterfaceImplementedDivinerConfigSchema,
25
+ EvmTokenInterfaceImplementedSchema: () => EvmTokenInterfaceImplementedSchema,
26
+ isEvmTokenInterfaceImplemented: () => isEvmTokenInterfaceImplemented
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/Diviner.ts
31
+ var import_assert = require("@xylabs/assert");
32
+ var import_diviner_abstract = require("@xyo-network/diviner-abstract");
33
+ var import_evm_contract_witness = require("@xyo-network/evm-contract-witness");
34
+ var import_open_zeppelin_typechain = require("@xyo-network/open-zeppelin-typechain");
35
+ var import_ethers = require("ethers");
36
+
37
+ // src/Payload.ts
38
+ var import_payload_model = require("@xyo-network/payload-model");
39
+ var EvmTokenInterfaceImplementedSchema = "network.xyo.evm.token.interface.implemented";
40
+ var isEvmTokenInterfaceImplemented = (0, import_payload_model.isPayloadOfSchemaType)(EvmTokenInterfaceImplementedSchema);
41
+
42
+ // src/Diviner.ts
43
+ var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
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;
60
+ _tokenInterfaces;
61
+ /**
62
+ * The list of token interfaces to check against the contract
63
+ */
64
+ get tokenInterfaces() {
65
+ if (!this._tokenInterfaces) {
66
+ this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
67
+ this.config?.tokenInterfaces.map((tokenInterface) => {
68
+ return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
69
+ })
70
+ ) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
71
+ }
72
+ return this._tokenInterfaces;
73
+ }
74
+ async divineHandler(inPayloads = []) {
75
+ await this.started("throw");
76
+ try {
77
+ const allResults = await Promise.all(
78
+ // Iterate over each contract passed in
79
+ inPayloads.filter(import_evm_contract_witness.isEvmContract).map(({ address, code, chainId }) => {
80
+ const byteCode = (0, import_assert.assertEx)(code, () => "Missing code");
81
+ const results = [];
82
+ for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {
83
+ const contractInterface = new import_ethers.Interface(abi);
84
+ const implementations = [];
85
+ contractInterface.forEachFunction(({ selector }) => {
86
+ implementations.push(byteCode.includes(BigInt(selector).toString(16)));
87
+ });
88
+ const implemented = implementations.every(Boolean);
89
+ const result = {
90
+ address,
91
+ chainId,
92
+ implemented,
93
+ schema: EvmTokenInterfaceImplementedSchema,
94
+ tokenInterface
95
+ };
96
+ results.push(result);
97
+ }
98
+ return results;
99
+ })
100
+ );
101
+ return allResults.flat();
102
+ } catch (ex) {
103
+ const error = ex;
104
+ console.log(`Error [${this.config.name}]: ${error.message}`);
105
+ throw error;
106
+ }
107
+ }
108
+ };
2
109
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './Payload'\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'\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 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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yCAAAE,EAAA,oDAAAC,EAAA,uCAAAC,EAAA,mCAAAC,IAAA,eAAAC,EAAAN,GCAA,IAAAO,EAAyB,0BACzBC,EAAgC,yCAEhCC,EAA2C,6CAE3CC,EASO,gDAEPC,EAAwC,kBChBxC,IAAAC,EAA+C,sCAyBlCC,EAAqC,8CAkCrCC,KAAiC,yBAAoDD,CAAkC,EDvC7H,IAAME,EAAkD,GAAGC,CAAkC,kBAgBvFC,EAAN,MAAMC,UAEH,iBAAoE,CAI5E,OAAgB,yBAAsF,CACpG,QAAS,mBAAiB,IAC1B,oBAAqB,+BAA6B,IAClD,qBAAsB,4BAA0B,IAChD,MAAO,iBAAe,IACtB,OAAQ,kBAAgB,IACxB,iBAAkB,6BAA2B,IAC7C,eAAgB,2BAAyB,IACzC,oBAAqB,2BAAyB,GAChD,EACA,OAAyB,cAA0B,CAAC,GAAG,MAAM,cAAeH,CAA+C,EAC3H,OAAyB,oBAA8BA,EAE/C,iBAKR,IAAI,iBAAkB,CACpB,OAAK,KAAK,mBACR,KAAK,iBACH,KAAK,QAAQ,gBACV,OAAO,YACN,KAAK,QAAQ,gBAAgB,IAAKI,GACzB,CAACA,EAAgBD,EAAoC,yBAAyBC,CAAc,CAAC,CACrG,CACH,GAAkC,CAAC,EACnCD,EAAoC,0BAEnC,KAAK,gBACd,CAEA,MAAyB,cAAcE,EAA4B,CAAC,EAA4C,CAC9G,MAAM,KAAK,QAAQ,OAAO,EAC1B,GAAI,CA6BF,OA5BmB,MAAM,QAAQ,IAE/BA,EAAW,OAAO,eAAa,EAAE,IAAI,CAAC,CAAE,QAAAC,EAAS,KAAAC,EAAM,QAAAC,CAAQ,IAAM,CAEnE,IAAMC,KAAW,YAASF,EAAM,IAAM,cAAc,EAC9CG,EAA0C,CAAC,EAEjD,OAAW,CAACN,EAAgBO,CAAG,IAAK,OAAO,QAAQ,KAAK,eAAe,EAAG,CAExE,IAAMC,EAAoB,IAAI,YAAUD,CAAG,EACrCE,EAA6B,CAAC,EACpCD,EAAkB,gBAAgB,CAAC,CAAE,SAAAE,CAAS,IAAM,CAClDD,EAAgB,KAAKJ,EAAS,SAAS,OAAOK,CAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CACvE,CAAC,EACD,IAAMC,EAAcF,EAAgB,MAAM,OAAO,EAC3CG,EAAuC,CAC3C,QAAAV,EACA,QAAAE,EACA,YAAAO,EACA,OAAQd,EACR,eAAgBG,CAClB,EACAM,EAAQ,KAAKM,CAAM,CACrB,CAEA,OAAON,CACT,CAAC,CACH,GACkB,KAAK,CACzB,OAASO,EAAI,CACX,IAAMC,EAAQD,EACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAMC,EAAM,OAAO,EAAE,EACrDA,CACR,CACF,CACF","names":["src_exports","__export","EvmTokenInterfaceImplementedDiviner","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","__toCommonJS","import_assert","import_diviner_abstract","import_evm_contract_witness","import_open_zeppelin_typechain","import_ethers","import_payload_model","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","EvmTokenInterfaceImplementedDiviner","_EvmTokenInterfaceImplementedDiviner","tokenInterface","inPayloads","address","code","chainId","byteCode","results","abi","contractInterface","implementations","selector","implemented","result","ex","error"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './Payload'\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'\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 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,EACA,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,mBACH,KAAK,QAAQ,kBACV,OAAO;AAAA,QACN,KAAK,QAAQ,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG,CAAC;AAAA,MACH,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC1C;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":[]}
@@ -1,2 +1,95 @@
1
- import{assertEx as C}from"@xylabs/assert";import{AbstractDiviner as y}from"@xyo-network/diviner-abstract";import{isEvmContract as R}from"@xyo-network/evm-contract-witness";import{ERC20__factory as h,ERC721__factory as g,ERC1155__factory as u,IERC721Enumerable__factory as S,IERC721Metadata__factory as b,IERC721Receiver__factory as x,IERC1155MetadataURI__factory as _,IERC1155Receiver__factory as D}from"@xyo-network/open-zeppelin-typechain";import{Interface as P}from"ethers";import{isPayloadOfSchemaType as T}from"@xyo-network/payload-model";var n="network.xyo.evm.token.interface.implemented",F=T(n);var c=`${n}.diviner.config`,i=class r extends y{static SupportedTokenInterfaces={ERC1155:u.abi,ERC1155Metadata_URI:_.abi,ERC1155TokenReceiver:D.abi,ERC20:h.abi,ERC721:g.abi,ERC721Enumerable:S.abi,ERC721Metadata:b.abi,ERC721TokenReceiver:x.abi};static configSchemas=[...super.configSchemas,c];static defaultConfigSchema=c;_tokenInterfaces;get tokenInterfaces(){return this._tokenInterfaces||(this._tokenInterfaces=this.config?.tokenInterfaces?Object.fromEntries(this.config?.tokenInterfaces.map(e=>[e,r.SupportedTokenInterfaces[e]]))??{}:r.SupportedTokenInterfaces),this._tokenInterfaces}async divineHandler(e=[]){await this.started("throw");try{return(await Promise.all(e.filter(R).map(({address:t,code:f,chainId:s})=>{let I=C(f,()=>"Missing code"),a=[];for(let[p,d]of Object.entries(this.tokenInterfaces)){let E=new P(d),m=[];E.forEachFunction(({selector:v})=>{m.push(I.includes(BigInt(v).toString(16)))});let l=m.every(Boolean),k={address:t,chainId:s,implemented:l,schema:n,tokenInterface:p};a.push(k)}return a}))).flat()}catch(o){let t=o;throw console.log(`Error [${this.config.name}]: ${t.message}`),t}}};export{i as EvmTokenInterfaceImplementedDiviner,c as EvmTokenInterfaceImplementedDivinerConfigSchema,n as EvmTokenInterfaceImplementedSchema,F as isEvmTokenInterfaceImplemented};
1
+ // src/Diviner.ts
2
+ import { assertEx } from "@xylabs/assert";
3
+ import { AbstractDiviner } from "@xyo-network/diviner-abstract";
4
+ import { isEvmContract } from "@xyo-network/evm-contract-witness";
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";
15
+ import { Interface } from "ethers";
16
+
17
+ // src/Payload.ts
18
+ import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
19
+ var EvmTokenInterfaceImplementedSchema = "network.xyo.evm.token.interface.implemented";
20
+ var isEvmTokenInterfaceImplemented = isPayloadOfSchemaType(EvmTokenInterfaceImplementedSchema);
21
+
22
+ // src/Diviner.ts
23
+ var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
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;
40
+ _tokenInterfaces;
41
+ /**
42
+ * The list of token interfaces to check against the contract
43
+ */
44
+ get tokenInterfaces() {
45
+ if (!this._tokenInterfaces) {
46
+ this._tokenInterfaces = this.config?.tokenInterfaces ? Object.fromEntries(
47
+ this.config?.tokenInterfaces.map((tokenInterface) => {
48
+ return [tokenInterface, _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces[tokenInterface]];
49
+ })
50
+ ) ?? {} : _EvmTokenInterfaceImplementedDiviner.SupportedTokenInterfaces;
51
+ }
52
+ return this._tokenInterfaces;
53
+ }
54
+ async divineHandler(inPayloads = []) {
55
+ await this.started("throw");
56
+ try {
57
+ const allResults = await Promise.all(
58
+ // Iterate over each contract passed in
59
+ inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {
60
+ const byteCode = assertEx(code, () => "Missing code");
61
+ const results = [];
62
+ for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {
63
+ const contractInterface = new Interface(abi);
64
+ const implementations = [];
65
+ contractInterface.forEachFunction(({ selector }) => {
66
+ implementations.push(byteCode.includes(BigInt(selector).toString(16)));
67
+ });
68
+ const implemented = implementations.every(Boolean);
69
+ const result = {
70
+ address,
71
+ chainId,
72
+ implemented,
73
+ schema: EvmTokenInterfaceImplementedSchema,
74
+ tokenInterface
75
+ };
76
+ results.push(result);
77
+ }
78
+ return results;
79
+ })
80
+ );
81
+ return allResults.flat();
82
+ } catch (ex) {
83
+ const error = ex;
84
+ console.log(`Error [${this.config.name}]: ${error.message}`);
85
+ throw error;
86
+ }
87
+ }
88
+ };
89
+ export {
90
+ EvmTokenInterfaceImplementedDiviner,
91
+ EvmTokenInterfaceImplementedDivinerConfigSchema,
92
+ EvmTokenInterfaceImplementedSchema,
93
+ isEvmTokenInterfaceImplemented
94
+ };
2
95
  //# sourceMappingURL=index.js.map
@@ -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'\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 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,OAAS,YAAAA,MAAgB,iBACzB,OAAS,mBAAAC,MAAuB,gCAEhC,OAAsB,iBAAAC,MAAqB,oCAE3C,OACE,kBAAAC,EACA,mBAAAC,EACA,oBAAAC,EACA,8BAAAC,EACA,4BAAAC,EACA,4BAAAC,EACA,gCAAAC,EACA,6BAAAC,MACK,uCAEP,OAAS,aAAAC,MAA+B,SChBxC,OAAS,yBAAAC,MAAsC,6BAyBxC,IAAMC,EAAqC,8CAkCrCC,EAAiCF,EAAoDC,CAAkC,EDvC7H,IAAME,EAAkD,GAAGC,CAAkC,kBAgBvFC,EAAN,MAAMC,UAEHC,CAAoE,CAI5E,OAAgB,yBAAsF,CACpG,QAASC,EAAiB,IAC1B,oBAAqBC,EAA6B,IAClD,qBAAsBC,EAA0B,IAChD,MAAOC,EAAe,IACtB,OAAQC,EAAgB,IACxB,iBAAkBC,EAA2B,IAC7C,eAAgBC,EAAyB,IACzC,oBAAqBC,EAAyB,GAChD,EACA,OAAyB,cAA0B,CAAC,GAAG,MAAM,cAAeZ,CAA+C,EAC3H,OAAyB,oBAA8BA,EAE/C,iBAKR,IAAI,iBAAkB,CACpB,OAAK,KAAK,mBACR,KAAK,iBACH,KAAK,QAAQ,gBACV,OAAO,YACN,KAAK,QAAQ,gBAAgB,IAAKa,GACzB,CAACA,EAAgBV,EAAoC,yBAAyBU,CAAc,CAAC,CACrG,CACH,GAAkC,CAAC,EACnCV,EAAoC,0BAEnC,KAAK,gBACd,CAEA,MAAyB,cAAcW,EAA4B,CAAC,EAA4C,CAC9G,MAAM,KAAK,QAAQ,OAAO,EAC1B,GAAI,CA6BF,OA5BmB,MAAM,QAAQ,IAE/BA,EAAW,OAAOC,CAAa,EAAE,IAAI,CAAC,CAAE,QAAAC,EAAS,KAAAC,EAAM,QAAAC,CAAQ,IAAM,CAEnE,IAAMC,EAAWC,EAASH,EAAM,IAAM,cAAc,EAC9CI,EAA0C,CAAC,EAEjD,OAAW,CAACR,EAAgBS,CAAG,IAAK,OAAO,QAAQ,KAAK,eAAe,EAAG,CAExE,IAAMC,EAAoB,IAAIC,EAAUF,CAAG,EACrCG,EAA6B,CAAC,EACpCF,EAAkB,gBAAgB,CAAC,CAAE,SAAAG,CAAS,IAAM,CAClDD,EAAgB,KAAKN,EAAS,SAAS,OAAOO,CAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CACvE,CAAC,EACD,IAAMC,EAAcF,EAAgB,MAAM,OAAO,EAC3CG,EAAuC,CAC3C,QAAAZ,EACA,QAAAE,EACA,YAAAS,EACA,OAAQ1B,EACR,eAAgBY,CAClB,EACAQ,EAAQ,KAAKO,CAAM,CACrB,CAEA,OAAOP,CACT,CAAC,CACH,GACkB,KAAK,CACzB,OAASQ,EAAI,CACX,IAAMC,EAAQD,EACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAMC,EAAM,OAAO,EAAE,EACrDA,CACR,CACF,CACF","names":["assertEx","AbstractDiviner","isEvmContract","ERC20__factory","ERC721__factory","ERC1155__factory","IERC721Enumerable__factory","IERC721Metadata__factory","IERC721Receiver__factory","IERC1155MetadataURI__factory","IERC1155Receiver__factory","Interface","isPayloadOfSchemaType","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","EvmTokenInterfaceImplementedDiviner","_EvmTokenInterfaceImplementedDiviner","AbstractDiviner","ERC1155__factory","IERC1155MetadataURI__factory","IERC1155Receiver__factory","ERC20__factory","ERC721__factory","IERC721Enumerable__factory","IERC721Metadata__factory","IERC721Receiver__factory","tokenInterface","inPayloads","isEvmContract","address","code","chainId","byteCode","assertEx","results","abi","contractInterface","Interface","implementations","selector","implemented","result","ex","error"]}
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'\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 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,EACA,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,mBACH,KAAK,QAAQ,kBACV,OAAO;AAAA,QACN,KAAK,QAAQ,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG,CAAC;AAAA,MACH,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC1C;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":[]}
@@ -1,2 +1,117 @@
1
- "use strict";var c=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var _=(n,t)=>{for(var r in t)c(n,r,{get:t[r],enumerable:!0})},D=(n,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of b(t))!x.call(n,a)&&a!==r&&c(n,a,{get:()=>t[a],enumerable:!(o=S(t,a))||o.enumerable});return n};var P=n=>D(c({},"__esModule",{value:!0}),n);var w={};_(w,{EvmTokenInterfaceImplementedDiviner:()=>f,EvmTokenInterfaceImplementedDivinerConfigSchema:()=>i,EvmTokenInterfaceImplementedSchema:()=>m,isEvmTokenInterfaceImplemented:()=>M});module.exports=P(w);var d=require("@xylabs/assert"),E=require("@xyo-network/diviner-abstract"),l=require("@xyo-network/evm-contract-witness"),e=require("@xyo-network/open-zeppelin-typechain"),k=require("ethers");var p=require("@xyo-network/payload-model"),m="network.xyo.evm.token.interface.implemented",M=(0,p.isPayloadOfSchemaType)(m);var i=`${m}.diviner.config`,f=class n extends E.AbstractDiviner{static SupportedTokenInterfaces={ERC1155:e.ERC1155__factory.abi,ERC1155Metadata_URI:e.IERC1155MetadataURI__factory.abi,ERC1155TokenReceiver:e.IERC1155Receiver__factory.abi,ERC20:e.ERC20__factory.abi,ERC721:e.ERC721__factory.abi,ERC721Enumerable:e.IERC721Enumerable__factory.abi,ERC721Metadata:e.IERC721Metadata__factory.abi,ERC721TokenReceiver:e.IERC721Receiver__factory.abi};static configSchemas=[...super.configSchemas,i];static defaultConfigSchema=i;_tokenInterfaces;get tokenInterfaces(){var t,r;return this._tokenInterfaces||(this._tokenInterfaces=(t=this.config)!=null&&t.tokenInterfaces?Object.fromEntries((r=this.config)==null?void 0:r.tokenInterfaces.map(o=>[o,n.SupportedTokenInterfaces[o]]))??{}:n.SupportedTokenInterfaces),this._tokenInterfaces}async divineHandler(t=[]){await this.started("throw");try{return(await Promise.all(t.filter(l.isEvmContract).map(({address:o,code:a,chainId:v})=>{let T=(0,d.assertEx)(a,()=>"Missing code"),s=[];for(let[C,y]of Object.entries(this.tokenInterfaces)){let R=new k.Interface(y),I=[];R.forEachFunction(({selector:u})=>{I.push(T.includes(BigInt(u).toString(16)))});let h=I.every(Boolean),g={address:o,chainId:v,implemented:h,schema:m,tokenInterface:C};s.push(g)}return s}))).flat()}catch(r){let o=r;throw console.log(`Error [${this.config.name}]: ${o.message}`),o}}};0&&(module.exports={EvmTokenInterfaceImplementedDiviner,EvmTokenInterfaceImplementedDivinerConfigSchema,EvmTokenInterfaceImplementedSchema,isEvmTokenInterfaceImplemented});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ EvmTokenInterfaceImplementedDiviner: () => EvmTokenInterfaceImplementedDiviner,
24
+ EvmTokenInterfaceImplementedDivinerConfigSchema: () => EvmTokenInterfaceImplementedDivinerConfigSchema,
25
+ EvmTokenInterfaceImplementedSchema: () => EvmTokenInterfaceImplementedSchema,
26
+ isEvmTokenInterfaceImplemented: () => isEvmTokenInterfaceImplemented
27
+ });
28
+ module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/Diviner.ts
31
+ var import_assert = require("@xylabs/assert");
32
+ var import_diviner_abstract = require("@xyo-network/diviner-abstract");
33
+ var import_evm_contract_witness = require("@xyo-network/evm-contract-witness");
34
+ var import_open_zeppelin_typechain = require("@xyo-network/open-zeppelin-typechain");
35
+ var import_ethers = require("ethers");
36
+
37
+ // src/Payload.ts
38
+ var import_payload_model = require("@xyo-network/payload-model");
39
+ var EvmTokenInterfaceImplementedSchema = "network.xyo.evm.token.interface.implemented";
40
+ var isEvmTokenInterfaceImplemented = (0, import_payload_model.isPayloadOfSchemaType)(EvmTokenInterfaceImplementedSchema);
41
+
42
+ // src/Diviner.ts
43
+ var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
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;
60
+ _tokenInterfaces;
61
+ /**
62
+ * The list of token interfaces to check against the contract
63
+ */
64
+ get tokenInterfaces() {
65
+ var _a, _b;
66
+ if (!this._tokenInterfaces) {
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;
72
+ }
73
+ return this._tokenInterfaces;
74
+ }
75
+ async divineHandler(inPayloads = []) {
76
+ await this.started("throw");
77
+ try {
78
+ const allResults = await Promise.all(
79
+ // Iterate over each contract passed in
80
+ inPayloads.filter(import_evm_contract_witness.isEvmContract).map(({ address, code, chainId }) => {
81
+ const byteCode = (0, import_assert.assertEx)(code, () => "Missing code");
82
+ const results = [];
83
+ for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {
84
+ const contractInterface = new import_ethers.Interface(abi);
85
+ const implementations = [];
86
+ contractInterface.forEachFunction(({ selector }) => {
87
+ implementations.push(byteCode.includes(BigInt(selector).toString(16)));
88
+ });
89
+ const implemented = implementations.every(Boolean);
90
+ const result = {
91
+ address,
92
+ chainId,
93
+ implemented,
94
+ schema: EvmTokenInterfaceImplementedSchema,
95
+ tokenInterface
96
+ };
97
+ results.push(result);
98
+ }
99
+ return results;
100
+ })
101
+ );
102
+ return allResults.flat();
103
+ } catch (ex) {
104
+ const error = ex;
105
+ console.log(`Error [${this.config.name}]: ${error.message}`);
106
+ throw error;
107
+ }
108
+ }
109
+ };
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ EvmTokenInterfaceImplementedDiviner,
113
+ EvmTokenInterfaceImplementedDivinerConfigSchema,
114
+ EvmTokenInterfaceImplementedSchema,
115
+ isEvmTokenInterfaceImplemented
116
+ });
2
117
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './Payload'\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'\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 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":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yCAAAE,EAAA,oDAAAC,EAAA,uCAAAC,EAAA,mCAAAC,IAAA,eAAAC,EAAAN,GCAA,IAAAO,EAAyB,0BACzBC,EAAgC,yCAEhCC,EAA2C,6CAE3CC,EASO,gDAEPC,EAAwC,kBChBxC,IAAAC,EAA+C,sCAyBlCC,EAAqC,8CAkCrCC,KAAiC,yBAAoDD,CAAkC,EDvC7H,IAAME,EAAkD,GAAGC,CAAkC,kBAgBvFC,EAAN,MAAMC,UAEH,iBAAoE,CAI5E,OAAgB,yBAAsF,CACpG,QAAS,mBAAiB,IAC1B,oBAAqB,+BAA6B,IAClD,qBAAsB,4BAA0B,IAChD,MAAO,iBAAe,IACtB,OAAQ,kBAAgB,IACxB,iBAAkB,6BAA2B,IAC7C,eAAgB,2BAAyB,IACzC,oBAAqB,2BAAyB,GAChD,EACA,OAAyB,cAA0B,CAAC,GAAG,MAAM,cAAeH,CAA+C,EAC3H,OAAyB,oBAA8BA,EAE/C,iBAKR,IAAI,iBAAkB,CA5DxB,IAAAI,EAAAC,EA6DI,OAAK,KAAK,mBACR,KAAK,kBACHD,EAAA,KAAK,SAAL,MAAAA,EAAa,gBACV,OAAO,aACNC,EAAA,KAAK,SAAL,YAAAA,EAAa,gBAAgB,IAAKC,GACzB,CAACA,EAAgBH,EAAoC,yBAAyBG,CAAc,CAAC,EAExG,GAAkC,CAAC,EACnCH,EAAoC,0BAEnC,KAAK,gBACd,CAEA,MAAyB,cAAcI,EAA4B,CAAC,EAA4C,CAC9G,MAAM,KAAK,QAAQ,OAAO,EAC1B,GAAI,CA6BF,OA5BmB,MAAM,QAAQ,IAE/BA,EAAW,OAAO,eAAa,EAAE,IAAI,CAAC,CAAE,QAAAC,EAAS,KAAAC,EAAM,QAAAC,CAAQ,IAAM,CAEnE,IAAMC,KAAW,YAASF,EAAM,IAAM,cAAc,EAC9CG,EAA0C,CAAC,EAEjD,OAAW,CAACN,EAAgBO,CAAG,IAAK,OAAO,QAAQ,KAAK,eAAe,EAAG,CAExE,IAAMC,EAAoB,IAAI,YAAUD,CAAG,EACrCE,EAA6B,CAAC,EACpCD,EAAkB,gBAAgB,CAAC,CAAE,SAAAE,CAAS,IAAM,CAClDD,EAAgB,KAAKJ,EAAS,SAAS,OAAOK,CAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CACvE,CAAC,EACD,IAAMC,EAAcF,EAAgB,MAAM,OAAO,EAC3CG,EAAuC,CAC3C,QAAAV,EACA,QAAAE,EACA,YAAAO,EACA,OAAQhB,EACR,eAAgBK,CAClB,EACAM,EAAQ,KAAKM,CAAM,CACrB,CAEA,OAAON,CACT,CAAC,CACH,GACkB,KAAK,CACzB,OAASO,EAAI,CACX,IAAMC,EAAQD,EACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAMC,EAAM,OAAO,EAAE,EACrDA,CACR,CACF,CACF","names":["src_exports","__export","EvmTokenInterfaceImplementedDiviner","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","__toCommonJS","import_assert","import_diviner_abstract","import_evm_contract_witness","import_open_zeppelin_typechain","import_ethers","import_payload_model","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","EvmTokenInterfaceImplementedDiviner","_EvmTokenInterfaceImplementedDiviner","_a","_b","tokenInterface","inPayloads","address","code","chainId","byteCode","results","abi","contractInterface","implementations","selector","implemented","result","ex","error"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/Diviner.ts","../../src/Payload.ts"],"sourcesContent":["export * from './Diviner'\nexport * from './Payload'\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'\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 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,EACA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+CAA+C;AAAA,EAC3H,OAAyB,sBAA8B;AAAA,EAE/C;AAAA;AAAA;AAAA;AAAA,EAKR,IAAI,kBAAkB;AA5DxB;AA6DI,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,qBACH,UAAK,WAAL,mBAAa,mBACV,OAAO;AAAA,SACN,UAAK,WAAL,mBAAa,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG;AAAA,MACF,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC1C;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":[]}
@@ -1,2 +1,96 @@
1
- import{assertEx as C}from"@xylabs/assert";import{AbstractDiviner as y}from"@xyo-network/diviner-abstract";import{isEvmContract as R}from"@xyo-network/evm-contract-witness";import{ERC20__factory as h,ERC721__factory as g,ERC1155__factory as u,IERC721Enumerable__factory as S,IERC721Metadata__factory as b,IERC721Receiver__factory as x,IERC1155MetadataURI__factory as _,IERC1155Receiver__factory as D}from"@xyo-network/open-zeppelin-typechain";import{Interface as P}from"ethers";import{isPayloadOfSchemaType as T}from"@xyo-network/payload-model";var r="network.xyo.evm.token.interface.implemented",F=T(r);var c=`${r}.diviner.config`,i=class o extends y{static SupportedTokenInterfaces={ERC1155:u.abi,ERC1155Metadata_URI:_.abi,ERC1155TokenReceiver:D.abi,ERC20:h.abi,ERC721:g.abi,ERC721Enumerable:S.abi,ERC721Metadata:b.abi,ERC721TokenReceiver:x.abi};static configSchemas=[...super.configSchemas,c];static defaultConfigSchema=c;_tokenInterfaces;get tokenInterfaces(){var n,t;return this._tokenInterfaces||(this._tokenInterfaces=(n=this.config)!=null&&n.tokenInterfaces?Object.fromEntries((t=this.config)==null?void 0:t.tokenInterfaces.map(e=>[e,o.SupportedTokenInterfaces[e]]))??{}:o.SupportedTokenInterfaces),this._tokenInterfaces}async divineHandler(n=[]){await this.started("throw");try{return(await Promise.all(n.filter(R).map(({address:e,code:f,chainId:s})=>{let I=C(f,()=>"Missing code"),a=[];for(let[p,d]of Object.entries(this.tokenInterfaces)){let E=new P(d),m=[];E.forEachFunction(({selector:v})=>{m.push(I.includes(BigInt(v).toString(16)))});let l=m.every(Boolean),k={address:e,chainId:s,implemented:l,schema:r,tokenInterface:p};a.push(k)}return a}))).flat()}catch(t){let e=t;throw console.log(`Error [${this.config.name}]: ${e.message}`),e}}};export{i as EvmTokenInterfaceImplementedDiviner,c as EvmTokenInterfaceImplementedDivinerConfigSchema,r as EvmTokenInterfaceImplementedSchema,F as isEvmTokenInterfaceImplemented};
1
+ // src/Diviner.ts
2
+ import { assertEx } from "@xylabs/assert";
3
+ import { AbstractDiviner } from "@xyo-network/diviner-abstract";
4
+ import { isEvmContract } from "@xyo-network/evm-contract-witness";
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";
15
+ import { Interface } from "ethers";
16
+
17
+ // src/Payload.ts
18
+ import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
19
+ var EvmTokenInterfaceImplementedSchema = "network.xyo.evm.token.interface.implemented";
20
+ var isEvmTokenInterfaceImplemented = isPayloadOfSchemaType(EvmTokenInterfaceImplementedSchema);
21
+
22
+ // src/Diviner.ts
23
+ var EvmTokenInterfaceImplementedDivinerConfigSchema = `${EvmTokenInterfaceImplementedSchema}.diviner.config`;
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;
40
+ _tokenInterfaces;
41
+ /**
42
+ * The list of token interfaces to check against the contract
43
+ */
44
+ get tokenInterfaces() {
45
+ var _a, _b;
46
+ if (!this._tokenInterfaces) {
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;
52
+ }
53
+ return this._tokenInterfaces;
54
+ }
55
+ async divineHandler(inPayloads = []) {
56
+ await this.started("throw");
57
+ try {
58
+ const allResults = await Promise.all(
59
+ // Iterate over each contract passed in
60
+ inPayloads.filter(isEvmContract).map(({ address, code, chainId }) => {
61
+ const byteCode = assertEx(code, () => "Missing code");
62
+ const results = [];
63
+ for (const [tokenInterface, abi] of Object.entries(this.tokenInterfaces)) {
64
+ const contractInterface = new Interface(abi);
65
+ const implementations = [];
66
+ contractInterface.forEachFunction(({ selector }) => {
67
+ implementations.push(byteCode.includes(BigInt(selector).toString(16)));
68
+ });
69
+ const implemented = implementations.every(Boolean);
70
+ const result = {
71
+ address,
72
+ chainId,
73
+ implemented,
74
+ schema: EvmTokenInterfaceImplementedSchema,
75
+ tokenInterface
76
+ };
77
+ results.push(result);
78
+ }
79
+ return results;
80
+ })
81
+ );
82
+ return allResults.flat();
83
+ } catch (ex) {
84
+ const error = ex;
85
+ console.log(`Error [${this.config.name}]: ${error.message}`);
86
+ throw error;
87
+ }
88
+ }
89
+ };
90
+ export {
91
+ EvmTokenInterfaceImplementedDiviner,
92
+ EvmTokenInterfaceImplementedDivinerConfigSchema,
93
+ EvmTokenInterfaceImplementedSchema,
94
+ isEvmTokenInterfaceImplemented
95
+ };
2
96
  //# sourceMappingURL=index.js.map
@@ -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'\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 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,OAAS,YAAAA,MAAgB,iBACzB,OAAS,mBAAAC,MAAuB,gCAEhC,OAAsB,iBAAAC,MAAqB,oCAE3C,OACE,kBAAAC,EACA,mBAAAC,EACA,oBAAAC,EACA,8BAAAC,EACA,4BAAAC,EACA,4BAAAC,EACA,gCAAAC,EACA,6BAAAC,MACK,uCAEP,OAAS,aAAAC,MAA+B,SChBxC,OAAS,yBAAAC,MAAsC,6BAyBxC,IAAMC,EAAqC,8CAkCrCC,EAAiCF,EAAoDC,CAAkC,EDvC7H,IAAME,EAAkD,GAAGC,CAAkC,kBAgBvFC,EAAN,MAAMC,UAEHC,CAAoE,CAI5E,OAAgB,yBAAsF,CACpG,QAASC,EAAiB,IAC1B,oBAAqBC,EAA6B,IAClD,qBAAsBC,EAA0B,IAChD,MAAOC,EAAe,IACtB,OAAQC,EAAgB,IACxB,iBAAkBC,EAA2B,IAC7C,eAAgBC,EAAyB,IACzC,oBAAqBC,EAAyB,GAChD,EACA,OAAyB,cAA0B,CAAC,GAAG,MAAM,cAAeZ,CAA+C,EAC3H,OAAyB,oBAA8BA,EAE/C,iBAKR,IAAI,iBAAkB,CA5DxB,IAAAa,EAAAC,EA6DI,OAAK,KAAK,mBACR,KAAK,kBACHD,EAAA,KAAK,SAAL,MAAAA,EAAa,gBACV,OAAO,aACNC,EAAA,KAAK,SAAL,YAAAA,EAAa,gBAAgB,IAAKC,GACzB,CAACA,EAAgBZ,EAAoC,yBAAyBY,CAAc,CAAC,EAExG,GAAkC,CAAC,EACnCZ,EAAoC,0BAEnC,KAAK,gBACd,CAEA,MAAyB,cAAca,EAA4B,CAAC,EAA4C,CAC9G,MAAM,KAAK,QAAQ,OAAO,EAC1B,GAAI,CA6BF,OA5BmB,MAAM,QAAQ,IAE/BA,EAAW,OAAOC,CAAa,EAAE,IAAI,CAAC,CAAE,QAAAC,EAAS,KAAAC,EAAM,QAAAC,CAAQ,IAAM,CAEnE,IAAMC,EAAWC,EAASH,EAAM,IAAM,cAAc,EAC9CI,EAA0C,CAAC,EAEjD,OAAW,CAACR,EAAgBS,CAAG,IAAK,OAAO,QAAQ,KAAK,eAAe,EAAG,CAExE,IAAMC,EAAoB,IAAIC,EAAUF,CAAG,EACrCG,EAA6B,CAAC,EACpCF,EAAkB,gBAAgB,CAAC,CAAE,SAAAG,CAAS,IAAM,CAClDD,EAAgB,KAAKN,EAAS,SAAS,OAAOO,CAAQ,EAAE,SAAS,EAAE,CAAC,CAAC,CACvE,CAAC,EACD,IAAMC,EAAcF,EAAgB,MAAM,OAAO,EAC3CG,EAAuC,CAC3C,QAAAZ,EACA,QAAAE,EACA,YAAAS,EACA,OAAQ5B,EACR,eAAgBc,CAClB,EACAQ,EAAQ,KAAKO,CAAM,CACrB,CAEA,OAAOP,CACT,CAAC,CACH,GACkB,KAAK,CACzB,OAASQ,EAAI,CACX,IAAMC,EAAQD,EACd,cAAQ,IAAI,UAAU,KAAK,OAAO,IAAI,MAAMC,EAAM,OAAO,EAAE,EACrDA,CACR,CACF,CACF","names":["assertEx","AbstractDiviner","isEvmContract","ERC20__factory","ERC721__factory","ERC1155__factory","IERC721Enumerable__factory","IERC721Metadata__factory","IERC721Receiver__factory","IERC1155MetadataURI__factory","IERC1155Receiver__factory","Interface","isPayloadOfSchemaType","EvmTokenInterfaceImplementedSchema","isEvmTokenInterfaceImplemented","EvmTokenInterfaceImplementedDivinerConfigSchema","EvmTokenInterfaceImplementedSchema","EvmTokenInterfaceImplementedDiviner","_EvmTokenInterfaceImplementedDiviner","AbstractDiviner","ERC1155__factory","IERC1155MetadataURI__factory","IERC1155Receiver__factory","ERC20__factory","ERC721__factory","IERC721Enumerable__factory","IERC721Metadata__factory","IERC721Receiver__factory","_a","_b","tokenInterface","inPayloads","isEvmContract","address","code","chainId","byteCode","assertEx","results","abi","contractInterface","Interface","implementations","selector","implemented","result","ex","error"]}
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'\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 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,EACA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,+CAA+C;AAAA,EAC3H,OAAyB,sBAA8B;AAAA,EAE/C;AAAA;AAAA;AAAA;AAAA,EAKR,IAAI,kBAAkB;AA5DxB;AA6DI,QAAI,CAAC,KAAK,kBAAkB;AAC1B,WAAK,qBACH,UAAK,WAAL,mBAAa,mBACV,OAAO;AAAA,SACN,UAAK,WAAL,mBAAa,gBAAgB,IAAI,CAAC,mBAAmB;AACnD,iBAAO,CAAC,gBAAgB,qCAAoC,yBAAyB,cAAc,CAAC;AAAA,QACtG;AAAA,MACF,KAAkC,CAAC,IACnC,qCAAoC;AAAA,IAC1C;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,38 +10,38 @@
10
10
  "url": "https://github.com/XYOracleNetwork/plugins/issues"
11
11
  },
12
12
  "dependencies": {
13
- "@xylabs/assert": "^3.5.1",
14
- "@xyo-network/diviner-abstract": "^2.107.0",
15
- "@xyo-network/diviner-model": "^2.107.0",
16
- "@xyo-network/evm-contract-witness": "~2.97.0",
17
- "@xyo-network/module-model": "^2.107.0",
13
+ "@xylabs/assert": "^3.5.2",
14
+ "@xyo-network/diviner-abstract": "^2.108.0",
15
+ "@xyo-network/diviner-model": "^2.108.0",
16
+ "@xyo-network/evm-contract-witness": "^2.98.0",
17
+ "@xyo-network/module-model": "^2.108.0",
18
18
  "@xyo-network/open-zeppelin-typechain": "^3.0.5",
19
- "@xyo-network/payload-model": "^2.107.0",
19
+ "@xyo-network/payload-model": "^2.108.0",
20
20
  "ethers": "^6.13.1"
21
21
  },
22
22
  "devDependencies": {
23
- "@xylabs/delay": "^3.5.1",
24
- "@xylabs/jest-helpers": "^3.5.1",
25
- "@xylabs/ts-scripts-yarn3": "^3.11.8",
26
- "@xylabs/tsconfig": "^3.11.8",
27
- "@xyo-network/account": "^2.107.0",
28
- "@xyo-network/archivist-memory": "^2.107.0",
29
- "@xyo-network/boundwitness-model": "^2.107.0",
30
- "@xyo-network/diviner-boundwitness-memory": "^2.107.0",
31
- "@xyo-network/diviner-jsonpatch": "^2.107.0",
32
- "@xyo-network/diviner-payload-memory": "^2.107.0",
33
- "@xyo-network/diviner-payload-model": "^2.107.0",
34
- "@xyo-network/diviner-stateful": "^2.107.0",
35
- "@xyo-network/diviner-temporal-indexing": "^2.107.0",
36
- "@xyo-network/manifest": "^2.107.0",
37
- "@xyo-network/module-factory-locator": "^2.107.0",
38
- "@xyo-network/node-memory": "^2.107.0",
23
+ "@xylabs/delay": "^3.5.2",
24
+ "@xylabs/jest-helpers": "^3.5.2",
25
+ "@xylabs/ts-scripts-yarn3": "^3.11.12",
26
+ "@xylabs/tsconfig": "^3.11.12",
27
+ "@xyo-network/account": "^2.108.0",
28
+ "@xyo-network/archivist-memory": "^2.108.0",
29
+ "@xyo-network/boundwitness-model": "^2.108.0",
30
+ "@xyo-network/diviner-boundwitness-memory": "^2.108.0",
31
+ "@xyo-network/diviner-jsonpatch": "^2.108.0",
32
+ "@xyo-network/diviner-payload-memory": "^2.108.0",
33
+ "@xyo-network/diviner-payload-model": "^2.108.0",
34
+ "@xyo-network/diviner-stateful": "^2.108.0",
35
+ "@xyo-network/diviner-temporal-indexing": "^2.108.0",
36
+ "@xyo-network/manifest": "^2.108.0",
37
+ "@xyo-network/module-factory-locator": "^2.108.0",
38
+ "@xyo-network/node-memory": "^2.108.0",
39
39
  "@xyo-network/open-zeppelin-typechain": "^3.0.5",
40
- "@xyo-network/sentinel-model": "^2.107.0",
41
- "@xyo-network/witness-evm-abstract": "^2.107.0",
42
- "@xyo-network/witness-timestamp": "^2.107.0",
40
+ "@xyo-network/sentinel-model": "^2.108.0",
41
+ "@xyo-network/witness-evm-abstract": "^2.108.0",
42
+ "@xyo-network/witness-timestamp": "^2.108.0",
43
43
  "jest": "^29.7.0",
44
- "typescript": "^5.5.2"
44
+ "typescript": "^5.5.3"
45
45
  },
46
46
  "description": "Typescript/Javascript Plugins for XYO Platform",
47
47
  "types": "dist/node/index.d.ts",
@@ -82,6 +82,6 @@
82
82
  "url": "https://github.com/XYOracleNetwork/plugins.git"
83
83
  },
84
84
  "sideEffects": false,
85
- "version": "2.97.0",
85
+ "version": "2.98.0",
86
86
  "type": "module"
87
87
  }