@sentio/sdk 2.15.6-rc.1 → 2.15.6-rc.3

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.
Files changed (43) hide show
  1. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +3 -3
  2. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +81 -114
  3. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  4. package/lib/eth/builtin/internal/erc1155-processor.d.ts +3 -3
  5. package/lib/eth/builtin/internal/erc1155-processor.js +29 -36
  6. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  7. package/lib/eth/builtin/internal/erc20-processor.d.ts +3 -3
  8. package/lib/eth/builtin/internal/erc20-processor.js +41 -54
  9. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  10. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +3 -3
  11. package/lib/eth/builtin/internal/erc20bytes-processor.js +33 -42
  12. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  13. package/lib/eth/builtin/internal/erc721-processor.d.ts +3 -3
  14. package/lib/eth/builtin/internal/erc721-processor.js +45 -60
  15. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  16. package/lib/eth/builtin/internal/weth9-processor.d.ts +3 -3
  17. package/lib/eth/builtin/internal/weth9-processor.js +33 -42
  18. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  19. package/lib/eth/codegen/file.js +12 -9
  20. package/lib/eth/codegen/file.js.map +1 -1
  21. package/lib/eth/codegen/view-function.js +4 -6
  22. package/lib/eth/codegen/view-function.js.map +1 -1
  23. package/lib/eth/index.d.ts +1 -1
  24. package/lib/eth/index.js +1 -1
  25. package/lib/eth/index.js.map +1 -1
  26. package/lib/eth/provider.d.ts +0 -2
  27. package/lib/eth/provider.js +9 -10
  28. package/lib/eth/provider.js.map +1 -1
  29. package/lib/eth/provider.test.js.map +1 -1
  30. package/lib/utils/token.js +9 -2
  31. package/lib/utils/token.js.map +1 -1
  32. package/package.json +3 -3
  33. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +86 -115
  34. package/src/eth/builtin/internal/erc1155-processor.ts +34 -37
  35. package/src/eth/builtin/internal/erc20-processor.ts +46 -55
  36. package/src/eth/builtin/internal/erc20bytes-processor.ts +38 -43
  37. package/src/eth/builtin/internal/erc721-processor.ts +50 -61
  38. package/src/eth/builtin/internal/weth9-processor.ts +38 -43
  39. package/src/eth/codegen/file.ts +12 -11
  40. package/src/eth/codegen/view-function.ts +4 -6
  41. package/src/eth/index.ts +1 -1
  42. package/src/eth/provider.ts +9 -11
  43. package/src/utils/token.ts +9 -2
@@ -1 +1 @@
1
- {"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/eth/codegen/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,+BAA+B,EAE/B,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAA;AACtF,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACpF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAEtF,MAAM,UAAU,YAAY,CAAC,QAAkB;IAC7C,OAAO;8BACqB,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE;8BAC3B,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE;8BAC3B,QAAQ,CAAC,IAAI;wCACH,QAAQ,CAAC,IAAI;GAClD,CAAA;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAkB;IAClD,MAAM,MAAM,GAAG;IACb,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,IAAI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,SAAS,uCAAuC,SAAS;4BACvD,YAAY;;WAE7B,wBAAwB,CAAC,KAAK,CAAC;WAC/B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;GAU5B,CAAA;AACH,CAAC","sourcesContent":["import {\n Contract,\n createImportsForUsedIdentifiers,\n EventDeclaration,\n getFullSignatureAsSymbolForEvent,\n getFullSignatureForEvent,\n} from 'typechain'\n\nimport { reservedKeywords } from '@sentio/ethers-v6/dist/codegen/reserved-keywords.js'\nimport { codegenCallTraceTypes, generateCallHandlers } from './functions-handler.js'\nimport { generateEventFilters, generateEventHandlers } from './event-handler.js'\nimport { generateBoundViewFunctions, generateViewFunctions } from './view-function.js'\n\nexport function codeGenIndex(contract: Contract): string {\n return ` \n export * from './internal/${contract.name.toLowerCase()}-processor.js'\n export * from './internal/${contract.name.toLowerCase()}-test-utils.js'\n export * from './internal/${contract.name}.js'\n export * from './internal/factories/${contract.name}__factory.js'\n `\n}\n\nexport function codeGenSentioFile(contract: Contract): string {\n const source = `\n ${Object.values(contract.functions).map(codegenCallTraceTypes).join('\\n')}\n\n const templateContract = ${contract.name}__factory.connect(\"0x0\", DummyProvider)\n\n export class ${contract.name}ContractView extends ContractView<${contract.name}> {\n constructor (contract: ${contract.name}) {\n super(contract);\n }\n\n ${Object.values(contract.functions)\n .filter((f) => !reservedKeywords.has(f[0].name))\n .map((fs) => generateViewFunctions(fs))\n .join('\\n')}\n }\n \n export class ${contract.name}BoundContractView extends BoundContractView<${contract.name}, \n ${contract.name}ContractView> {\n ${Object.values(contract.functions)\n .filter((f) => !reservedKeywords.has(f[0].name))\n .map((fs) => generateBoundViewFunctions(fs))\n .join('\\n')}\n }\n\n export type ${contract.name}Context = ContractContext<${contract.name}, ${contract.name}BoundContractView>\n\n export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {\n ${Object.values(contract.events)\n .map((events) => generateEventHandlers(events, contract.name))\n .join('\\n')}\n\n ${Object.values(contract.functions)\n .map((f) => generateCallHandlers(f, contract.name))\n .join('\\n')}\n\n public static filters = {\n ${Object.values(contract.events)\n .map((events) => generateEventFilters(events))\n .join(',')}\n }\n \n protected CreateBoundContractView(): ${contract.name}BoundContractView {\n const view = get${contract.name}Contract(this.config.network, this.config.address)\n return new ${contract.name}BoundContractView(this.config.address, view)\n }\n\n public static bind(options: BindOptions): ${contract.name}Processor {\n if (!options.name) {\n options.name = \"${contract.name}\"\n }\n let processor = getProcessor(options) as ${contract.name}Processor\n if (!processor) {\n processor = new ${contract.name}Processor(options)\n addProcessor(options, processor)\n }\n return processor\n }\n}\n\nexport class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${contract.name}, ${\n contract.name\n }BoundContractView> {\n bindInternal(options: BindOptions) {\n if (!options.name) {\n options.name = \"${contract.name}\"\n }\n let processor = getProcessor(options) as ${contract.name}Processor\n if (!processor) {\n processor = new ${contract.name}Processor(options)\n addProcessor(options, processor)\n }\n return processor\n }\n\n ${Object.values(contract.events)\n .map((events) => generateEventHandlers(events, contract.name))\n .join('\\n')}\n \n ${Object.values(contract.functions)\n .map((functions) => {\n generateCallHandlers(functions, contract.name)\n })\n .join('\\n')}\n }\n\n export function get${contract.name}Contract(contextOrNetwork: EthContext | EthChainId, address: string): ${\n contract.name\n }ContractView {\n const network = getEthChainId(contextOrNetwork) \n let contract = getContractByABI(\"${contract.name}\", address, network) as ${contract.name}ContractView\n if (!contract) {\n const rawContract = ${contract.name}__factory.connect(address, getProvider(network))\n contract = new ${contract.name}ContractView(rawContract)\n addContractByABI(\"${contract.name}\", address, network, contract)\n }\n return contract\n }\n `\n const eventsImports = Object.values(contract.events).flatMap((events) => {\n if (events.length === 1) {\n return [`${events[0].name}Event`, `${events[0].name}EventFilter`]\n } else {\n return events.flatMap((e) => [\n `${getFullSignatureAsSymbolForEvent(e)}_Event`,\n `${getFullSignatureAsSymbolForEvent(e)}_EventFilter`,\n ])\n }\n })\n\n const structImports = Object.values(contract.structs).flatMap((structs) => {\n return structs.flatMap((s) => {\n if (!s.structName) {\n return []\n }\n if (s.structName.namespace) {\n return [s.structName.namespace]\n } else {\n return [s.structName.identifier + 'StructOutput', s.structName.identifier + 'Struct']\n }\n })\n })\n // dedup namespace\n const uniqueStructImports = [...new Set(structImports)]\n\n const imports = createImportsForUsedIdentifiers(\n {\n ethers: ['BigNumberish', 'Overrides', 'BytesLike'],\n // 'ethers/providers': ['Networkish'],\n '@sentio/sdk/eth': [\n 'addContractByABI',\n 'getContractByABI',\n 'addProcessor',\n 'getProcessor',\n 'getProvider',\n 'transformEtherError',\n 'Trace',\n 'BindOptions',\n 'BaseProcessor',\n 'BaseProcessorTemplate',\n 'BoundContractView',\n 'ContractContext',\n 'ContractView',\n 'DummyProvider',\n 'EthChainId',\n 'TypedCallTrace',\n 'getEthChainId',\n // 'toBlockTag',\n 'EthContext',\n 'EthFetchConfig',\n ],\n // '@sentio/sdk/eth': ['BaseContext'],\n // '@sentio/protos': ['EthFetchConfig'],\n './common.js': ['PromiseOrValue'],\n './index.js': [`${contract.name}`, `${contract.name}__factory`],\n [`./${contract.name}.js`]: eventsImports.concat(uniqueStructImports),\n },\n source\n )\n\n return imports + source\n}\n\nexport function codeGenTestUtilsFile(contract: Contract): string {\n const source = `\n const mockField = {\n blockHash:\n \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n blockNumber: 0,\n logIndex: 0,\n removed: false,\n transactionHash:\n \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n transactionIndex: 0,\n }\n ${Object.values(contract.events)\n .map((events) => {\n if (events.length === 1) {\n return generateMockEventLogFunction(events[0], contract.name, false)\n } else {\n return events.map((e) => generateMockEventLogFunction(e, contract.name, true)).join('\\n')\n }\n })\n .join('\\n')}\n `\n\n const possibleImports = {\n 'ethers/providers': ['LogParams'],\n '@sentio/sdk/eth': ['EthChainId'],\n } as any\n possibleImports[`./${contract.name}.js`] = Object.values(contract.events).flatMap((events) => {\n if (events.length === 1) {\n return `${events[0].name}EventObject`\n } else {\n return events.flatMap((e) => `${getFullSignatureAsSymbolForEvent(e)}_EventObject`)\n }\n })\n\n possibleImports[`./${contract.name.toLowerCase()}-processor.js`] = [`get${contract.name}Contract`]\n\n const imports = createImportsForUsedIdentifiers(possibleImports, source)\n\n return imports + source\n}\n\nfunction generateMockEventLogFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {\n let eventName = event.name\n if (includeArgTypes) {\n eventName = getFullSignatureAsSymbolForEvent(event) + '_'\n }\n\n const eventArgs = event.inputs.map((input, i) => `event.${input.name ?? `arg${i.toString()}`}`)\n\n return `\n export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): LogParams {\n const contract = get${contractName}Contract(EthChainId.ETHEREUM, contractAddress)\n const encodedLog = contract.rawContract.interface.encodeEventLog(\n '${getFullSignatureForEvent(event)}',\n [${eventArgs.join(', ')}]\n )\n return {\n ...mockField,\n index: 0,\n address: contractAddress,\n data: encodedLog.data,\n topics: encodedLog.topics,\n }\n }\n `\n}\n"]}
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/eth/codegen/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,+BAA+B,EAE/B,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAA;AACtF,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACpF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAChF,OAAO,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAEtF,MAAM,UAAU,YAAY,CAAC,QAAkB;IAC7C,OAAO;8BACqB,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE;8BAC3B,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE;8BAC3B,QAAQ,CAAC,IAAI;wCACH,QAAQ,CAAC,IAAI;GAClD,CAAA;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AAG,gCAAgC,CAAC,KAAK,CAAC,GAAG,GAAG,CAAA;KAC1D;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAA;IAE/F,OAAO;0BACiB,SAAS,uCAAuC,SAAS;4BACvD,YAAY;;WAE7B,wBAAwB,CAAC,KAAK,CAAC;WAC/B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;;;;;;GAU5B,CAAA;AACH,CAAC","sourcesContent":["import {\n Contract,\n createImportsForUsedIdentifiers,\n EventDeclaration,\n getFullSignatureAsSymbolForEvent,\n getFullSignatureForEvent,\n} from 'typechain'\n\nimport { reservedKeywords } from '@sentio/ethers-v6/dist/codegen/reserved-keywords.js'\nimport { codegenCallTraceTypes, generateCallHandlers } from './functions-handler.js'\nimport { generateEventFilters, generateEventHandlers } from './event-handler.js'\nimport { generateBoundViewFunctions, generateViewFunctions } from './view-function.js'\n\nexport function codeGenIndex(contract: Contract): string {\n return ` \n export * from './internal/${contract.name.toLowerCase()}-processor.js'\n export * from './internal/${contract.name.toLowerCase()}-test-utils.js'\n export * from './internal/${contract.name}.js'\n export * from './internal/factories/${contract.name}__factory.js'\n `\n}\n\nexport function codeGenSentioFile(contract: Contract): string {\n const source = `\n ${Object.values(contract.functions).map(codegenCallTraceTypes).join('\\n')}\n\n const templateContract = ${contract.name}__factory.connect(\"0x0\", DummyProvider)\n\n export class ${contract.name}ContractView extends ContractView<${contract.name}> {\n constructor (contract: ${contract.name}) {\n super(contract);\n }\n\n ${Object.values(contract.functions)\n .filter((f) => !reservedKeywords.has(f[0].name))\n .map((fs) => generateViewFunctions(fs))\n .join('\\n')}\n }\n \n export class ${contract.name}BoundContractView extends BoundContractView<${contract.name}, \n ${contract.name}ContractView> {\n ${Object.values(contract.functions)\n .filter((f) => !reservedKeywords.has(f[0].name))\n .map((fs) => generateBoundViewFunctions(fs))\n .join('\\n')}\n }\n\n export type ${contract.name}Context = ContractContext<${contract.name}, ${contract.name}BoundContractView>\n\n export class ${contract.name}Processor extends BaseProcessor<${contract.name}, ${contract.name}BoundContractView> {\n ${Object.values(contract.events)\n .map((events) => generateEventHandlers(events, contract.name))\n .join('\\n')}\n\n ${Object.values(contract.functions)\n .map((f) => generateCallHandlers(f, contract.name))\n .join('\\n')}\n\n public static filters = {\n ${Object.values(contract.events)\n .map((events) => generateEventFilters(events))\n .join(',')}\n }\n \n protected CreateBoundContractView(): ${contract.name}BoundContractView {\n const view = get${contract.name}Contract(this.config.network, this.config.address)\n return new ${contract.name}BoundContractView(this.config.address, view)\n }\n\n public static bind(options: BindOptions): ${contract.name}Processor {\n if (!options.name) {\n options.name = \"${contract.name}\"\n }\n let processor = getProcessor(options) as ${contract.name}Processor\n if (!processor) {\n processor = new ${contract.name}Processor(options)\n addProcessor(options, processor)\n }\n return processor\n }\n}\n\nexport class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${contract.name}, ${\n contract.name\n }BoundContractView> {\n bindInternal(options: BindOptions) {\n if (!options.name) {\n options.name = \"${contract.name}\"\n }\n let processor = getProcessor(options) as ${contract.name}Processor\n if (!processor) {\n processor = new ${contract.name}Processor(options)\n addProcessor(options, processor)\n }\n return processor\n }\n\n ${Object.values(contract.events)\n .map((events) => generateEventHandlers(events, contract.name))\n .join('\\n')}\n \n ${Object.values(contract.functions)\n .map((functions) => {\n generateCallHandlers(functions, contract.name)\n })\n .join('\\n')}\n }\n\n export function get${contract.name}Contract(chainId: EthChainId, address: string): ${contract.name}ContractView {\n let contract = getContractByABI(\"${contract.name}\", address, chainId) as ${contract.name}ContractView\n if (!contract) {\n const rawContract = ${contract.name}__factory.connect(address, getProvider(chainId))\n contract = new ${contract.name}ContractView(rawContract)\n addContractByABI(\"${contract.name}\", address, chainId, contract)\n }\n return contract\n }\n \n export function get${contract.name}ContractOnContext(context: EthContext, address: string): \n ${contract.name}BoundContractView {\n const view = get${contract.name}Contract(context.getChainId(), address)\n return new ${contract.name}BoundContractView(address, view) \n }\n `\n const eventsImports = Object.values(contract.events).flatMap((events) => {\n if (events.length === 1) {\n return [`${events[0].name}Event`, `${events[0].name}EventFilter`]\n } else {\n return events.flatMap((e) => [\n `${getFullSignatureAsSymbolForEvent(e)}_Event`,\n `${getFullSignatureAsSymbolForEvent(e)}_EventFilter`,\n ])\n }\n })\n\n const structImports = Object.values(contract.structs).flatMap((structs) => {\n return structs.flatMap((s) => {\n if (!s.structName) {\n return []\n }\n if (s.structName.namespace) {\n return [s.structName.namespace]\n } else {\n return [s.structName.identifier + 'StructOutput', s.structName.identifier + 'Struct']\n }\n })\n })\n // dedup namespace\n const uniqueStructImports = [...new Set(structImports)]\n\n const imports = createImportsForUsedIdentifiers(\n {\n ethers: ['BigNumberish', 'Overrides', 'BytesLike'],\n // 'ethers/providers': ['Networkish'],\n '@sentio/sdk/eth': [\n 'addContractByABI',\n 'getContractByABI',\n 'addProcessor',\n 'getProcessor',\n 'getProvider',\n 'transformEtherError',\n 'Trace',\n 'BindOptions',\n 'BaseProcessor',\n 'BaseProcessorTemplate',\n 'BoundContractView',\n 'ContractContext',\n 'ContractView',\n 'DummyProvider',\n 'EthChainId',\n 'TypedCallTrace',\n 'EthContext',\n 'EthFetchConfig',\n ],\n // '@sentio/sdk/eth': ['BaseContext'],\n // '@sentio/protos': ['EthFetchConfig'],\n './common.js': ['PromiseOrValue'],\n './index.js': [`${contract.name}__factory`],\n [`./${contract.name}.js`]: [`${contract.name}`, ...eventsImports, ...uniqueStructImports],\n },\n source\n )\n\n return imports + source\n}\n\nexport function codeGenTestUtilsFile(contract: Contract): string {\n const source = `\n const mockField = {\n blockHash:\n \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n blockNumber: 0,\n logIndex: 0,\n removed: false,\n transactionHash:\n \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n transactionIndex: 0,\n }\n ${Object.values(contract.events)\n .map((events) => {\n if (events.length === 1) {\n return generateMockEventLogFunction(events[0], contract.name, false)\n } else {\n return events.map((e) => generateMockEventLogFunction(e, contract.name, true)).join('\\n')\n }\n })\n .join('\\n')}\n `\n\n const possibleImports = {\n 'ethers/providers': ['LogParams'],\n '@sentio/sdk/eth': ['EthChainId'],\n } as any\n possibleImports[`./${contract.name}.js`] = Object.values(contract.events).flatMap((events) => {\n if (events.length === 1) {\n return `${events[0].name}EventObject`\n } else {\n return events.flatMap((e) => `${getFullSignatureAsSymbolForEvent(e)}_EventObject`)\n }\n })\n\n possibleImports[`./${contract.name.toLowerCase()}-processor.js`] = [`get${contract.name}Contract`]\n\n const imports = createImportsForUsedIdentifiers(possibleImports, source)\n\n return imports + source\n}\n\nfunction generateMockEventLogFunction(event: EventDeclaration, contractName: string, includeArgTypes: boolean): string {\n let eventName = event.name\n if (includeArgTypes) {\n eventName = getFullSignatureAsSymbolForEvent(event) + '_'\n }\n\n const eventArgs = event.inputs.map((input, i) => `event.${input.name ?? `arg${i.toString()}`}`)\n\n return `\n export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): LogParams {\n const contract = get${contractName}Contract(EthChainId.ETHEREUM, contractAddress)\n const encodedLog = contract.rawContract.interface.encodeEventLog(\n '${getFullSignatureForEvent(event)}',\n [${eventArgs.join(', ')}]\n )\n return {\n ...mockField,\n index: 0,\n address: contractAddress,\n data: encodedLog.data,\n topics: encodedLog.topics,\n }\n }\n `\n}\n"]}
@@ -50,12 +50,10 @@ export function generateBoundViewFunction(fn, includeArgTypes) {
50
50
  async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
51
51
  useStructs: true,
52
52
  })}overrides?: Overrides): ${generateReturnTypes(fn)} {
53
- if (!overrides && this.context) {
54
- overrides = {
55
- blockTag: this.context.blockNumber,
56
- }
57
- }
58
- return await this.view.${declName}(${fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''} overrides || {})
53
+ return await this.view.${declName}(${fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''} {
54
+ blockTag: this.context.blockNumber,
55
+ ...overrides
56
+ })
59
57
  }
60
58
  `;
61
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"view-function.js","sourceRoot":"","sources":["../../../src/eth/codegen/view-function.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AACjG,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7F,SAAS,mBAAmB,CAAC,EAAuB;IAClD,yFAAyF;IACzF,OAAO,WAAW,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA;AACvG,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,SAAgC;IACpE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QAC1B,OAAO,oBAAoB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;KACjD;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,oBAAoB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzE,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,EAAuB,EAAE,eAAwB;IACpF,IAAI,EAAE,CAAC,eAAe,KAAK,MAAM,IAAI,EAAE,CAAC,eAAe,KAAK,MAAM,EAAE;QAClE,OAAO,EAAE,CAAA;KACV;IACD,MAAM,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC,mCAAmC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAA;IACpF,MAAM,IAAI,GAAG,6BAA6B,GAAG,2BAA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,IAAI,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE;QAC3D,UAAU,EAAE,IAAI;KACjB,CAAC,2BAA2B,mBAAmB,CAAC,EAAE,CAAC;;;;;;6BAMzB,QAAQ,IACjC,EAAE,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EACxG;;GAEC,CAAA;AACH,CAAC","sourcesContent":["// https://github.com/dethcrypto/TypeChain/blob/015abb28bd22826611051f27e0ec96a00f9a0b61/packages/target-ethers-v5/src/codegen/functions.ts#L54\nimport { FunctionDeclaration } from 'typechain'\nimport { generateInputTypes, generateOutputTypes } from '@sentio/ethers-v6/dist/codegen/types.js'\nimport { getFullSignatureAsSymbolForFunction, getFullSignatureForFunction } from './types.js'\n\nfunction generateReturnTypes(fn: FunctionDeclaration) {\n // sounds like returnResultObject should be true but we need to set false to make it work\n return `Promise<${generateOutputTypes({ returnResultObject: false, useStructs: true }, fn.outputs)}>`\n}\n\nexport function generateViewFunctions(functions: FunctionDeclaration[]): string {\n if (functions.length === 1) {\n return generateViewFunction(functions[0], false)\n }\n return functions.map((fn) => generateViewFunction(fn, true)).join('\\n')\n}\n\nexport function generateViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string {\n if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {\n return ''\n }\n const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name\n const call = 'this.contract.getFunction(\"' + getFullSignatureForFunction(fn) + '\")'\n // if (overrides) {\n // return await ${call}(${\n // fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n // } overrides)\n // } else {\n // return await ${call}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})\n // }\n return `\n async ${declName}(${generateInputTypes(fn.inputs, {\n useStructs: true,\n })}overrides?: Overrides): ${generateReturnTypes(fn)} {\n try { \n return await ${call}(${\n fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n } overrides || {})\n } catch (e) {\n throw transformEtherError(e, undefined)\n }\n }\n `\n}\n\nexport function generateBoundViewFunctions(functions: FunctionDeclaration[]): string {\n if (functions.length === 1) {\n return generateBoundViewFunction(functions[0], false)\n }\n return functions.map((fn) => generateBoundViewFunction(fn, true)).join('\\n')\n}\n\nexport function generateBoundViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string {\n if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {\n return ''\n }\n const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name\n\n return `\n async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {\n useStructs: true,\n })}overrides?: Overrides): ${generateReturnTypes(fn)} {\n if (!overrides && this.context) {\n overrides = {\n blockTag: this.context.blockNumber,\n }\n }\n return await this.view.${declName}(${\n fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n } overrides || {})\n }\n `\n}\n"]}
1
+ {"version":3,"file":"view-function.js","sourceRoot":"","sources":["../../../src/eth/codegen/view-function.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAA;AACjG,OAAO,EAAE,mCAAmC,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAE7F,SAAS,mBAAmB,CAAC,EAAuB;IAClD,yFAAyF;IACzF,OAAO,WAAW,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA;AACvG,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC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C;IACzE,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;QAC1B,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;KACtD;IACD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,yBAAyB,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC9E,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,EAAuB,EAAE,eAAwB;IACzF,IAAI,EAAE,CAAC,eAAe,KAAK,MAAM,IAAI,EAAE,CAAC,eAAe,KAAK,MAAM,EAAE;QAClE,OAAO,EAAE,CAAA;KACV;IACD,MAAM,QAAQ,GAAG,eAAe,CAAC,CAAC,CAAC,mCAAmC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAA;IAEpF,OAAO;UACC,QAAQ,IAAI,EAAE,CAAC,IAAI,IAAI,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE;QAC3D,UAAU,EAAE,IAAI;KACjB,CAAC,2BAA2B,mBAAmB,CAAC,EAAE,CAAC;6BACzB,QAAQ,IACjC,EAAE,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,IAAI,MAAM,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EACxG;;;;;GAKC,CAAA;AACH,CAAC","sourcesContent":["// https://github.com/dethcrypto/TypeChain/blob/015abb28bd22826611051f27e0ec96a00f9a0b61/packages/target-ethers-v5/src/codegen/functions.ts#L54\nimport { FunctionDeclaration } from 'typechain'\nimport { generateInputTypes, generateOutputTypes } from '@sentio/ethers-v6/dist/codegen/types.js'\nimport { getFullSignatureAsSymbolForFunction, getFullSignatureForFunction } from './types.js'\n\nfunction generateReturnTypes(fn: FunctionDeclaration) {\n // sounds like returnResultObject should be true but we need to set false to make it work\n return `Promise<${generateOutputTypes({ returnResultObject: false, useStructs: true }, fn.outputs)}>`\n}\n\nexport function generateViewFunctions(functions: FunctionDeclaration[]): string {\n if (functions.length === 1) {\n return generateViewFunction(functions[0], false)\n }\n return functions.map((fn) => generateViewFunction(fn, true)).join('\\n')\n}\n\nexport function generateViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string {\n if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {\n return ''\n }\n const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name\n const call = 'this.contract.getFunction(\"' + getFullSignatureForFunction(fn) + '\")'\n // if (overrides) {\n // return await ${call}(${\n // fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n // } overrides)\n // } else {\n // return await ${call}(${fn.inputs.map((input, index) => input.name || `arg${index}`).join(',')})\n // }\n return `\n async ${declName}(${generateInputTypes(fn.inputs, {\n useStructs: true,\n })}overrides?: Overrides): ${generateReturnTypes(fn)} {\n try { \n return await ${call}(${\n fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n } overrides || {})\n } catch (e) {\n throw transformEtherError(e, undefined)\n }\n }\n `\n}\n\nexport function generateBoundViewFunctions(functions: FunctionDeclaration[]): string {\n if (functions.length === 1) {\n return generateBoundViewFunction(functions[0], false)\n }\n return functions.map((fn) => generateBoundViewFunction(fn, true)).join('\\n')\n}\n\nexport function generateBoundViewFunction(fn: FunctionDeclaration, includeArgTypes: boolean): string {\n if (fn.stateMutability !== 'view' && fn.stateMutability !== 'pure') {\n return ''\n }\n const declName = includeArgTypes ? getFullSignatureAsSymbolForFunction(fn) : fn.name\n\n return `\n async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {\n useStructs: true,\n })}overrides?: Overrides): ${generateReturnTypes(fn)} {\n return await this.view.${declName}(${\n fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''\n } {\n blockTag: this.context.blockNumber,\n ...overrides\n })\n }\n `\n}\n"]}
@@ -2,7 +2,7 @@ export { BaseProcessor, GlobalProcessor } from './base-processor.js';
2
2
  export { GenericProcessor } from './generic-processor.js';
3
3
  export { BaseProcessorTemplate } from './base-processor-template.js';
4
4
  export { AccountProcessor } from './account-processor.js';
5
- export { getProvider, DummyProvider, getEthChainId } from './provider.js';
5
+ export { getProvider, DummyProvider } from './provider.js';
6
6
  export { EthContext } from './context.js';
7
7
  export * from './eth.js';
8
8
  export { BindOptions, AccountBindOptions } from './bind-options.js';
package/lib/eth/index.js CHANGED
@@ -2,7 +2,7 @@ export { BaseProcessor, GlobalProcessor } from './base-processor.js';
2
2
  export { GenericProcessor } from './generic-processor.js';
3
3
  export { BaseProcessorTemplate } from './base-processor-template.js';
4
4
  export { AccountProcessor } from './account-processor.js';
5
- export { getProvider, DummyProvider, getEthChainId } from './provider.js';
5
+ export { getProvider, DummyProvider } from './provider.js';
6
6
  export { EthContext } from './context.js';
7
7
  export * from './eth.js';
8
8
  export { BindOptions, AccountBindOptions } from './bind-options.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC3F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAE9G,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA","sourcesContent":["export { BaseProcessor, GlobalProcessor } from './base-processor.js'\nexport { GenericProcessor } from './generic-processor.js'\nexport { BaseProcessorTemplate } from './base-processor-template.js'\nexport { AccountProcessor } from './account-processor.js'\nexport { getProvider, DummyProvider, getEthChainId } from './provider.js'\nexport { EthContext } from './context.js'\nexport * from './eth.js'\nexport { BindOptions, AccountBindOptions } from './bind-options.js'\nexport { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds.js'\nexport { AccountContext, ContractContext, GlobalContext, ContractView, BoundContractView } from './context.js'\n\nexport { EthPlugin } from './eth-plugin.js'\n\nexport { EthFetchConfig } from '@sentio/protos'\n\nexport { EthChainId } from '../core/chain.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACnE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC3F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAE9G,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA","sourcesContent":["export { BaseProcessor, GlobalProcessor } from './base-processor.js'\nexport { GenericProcessor } from './generic-processor.js'\nexport { BaseProcessorTemplate } from './base-processor-template.js'\nexport { AccountProcessor } from './account-processor.js'\nexport { getProvider, DummyProvider } from './provider.js'\nexport { EthContext } from './context.js'\nexport * from './eth.js'\nexport { BindOptions, AccountBindOptions } from './bind-options.js'\nexport { getProcessor, addProcessor, getContractByABI, addContractByABI } from './binds.js'\nexport { AccountContext, ContractContext, GlobalContext, ContractView, BoundContractView } from './context.js'\n\nexport { EthPlugin } from './eth-plugin.js'\n\nexport { EthFetchConfig } from '@sentio/protos'\n\nexport { EthChainId } from '../core/chain.js'\n"]}
@@ -1,6 +1,4 @@
1
1
  import { JsonRpcProvider, Provider } from 'ethers';
2
2
  import { EthChainId } from '../core/chain.js';
3
- import { EthContext } from './context.js';
4
3
  export declare const DummyProvider: JsonRpcProvider;
5
- export declare function getEthChainId(networkish?: EthContext | EthChainId): EthChainId;
6
4
  export declare function getProvider(chainId?: EthChainId): Provider;
@@ -1,19 +1,18 @@
1
1
  import { JsonRpcProvider, Network } from 'ethers';
2
2
  import PQueue from 'p-queue';
3
3
  import { Endpoints } from '@sentio/runtime';
4
- import { BaseContext } from '../core/index.js';
5
4
  import { EthChainId } from '../core/chain.js';
6
5
  export const DummyProvider = new JsonRpcProvider('', Network.from(1));
7
6
  const providers = new Map();
8
- export function getEthChainId(networkish) {
9
- if (!networkish) {
10
- networkish = EthChainId.ETHEREUM;
11
- }
12
- if (networkish instanceof BaseContext) {
13
- networkish = networkish.getChainId();
14
- }
15
- return networkish;
16
- }
7
+ // export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {
8
+ // if (!networkish) {
9
+ // networkish = EthChainId.ETHEREUM
10
+ // }
11
+ // if (networkish instanceof BaseContext) {
12
+ // networkish = networkish.getChainId()
13
+ // }
14
+ // return networkish
15
+ // }
17
16
  export function getProvider(chainId) {
18
17
  // const network = getNetworkFromCtxOrNetworkish(networkish)
19
18
  if (!chainId) {
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/eth/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAY,MAAM,QAAQ,CAAA;AAE3D,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG7C,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,eAAe,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAErE,MAAM,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAA;AAEpD,MAAM,UAAU,aAAa,CAAC,UAAoC;IAChE,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAA;KACjC;IACD,IAAI,UAAU,YAAY,WAAW,EAAE;QACrC,UAAU,GAAG,UAAU,CAAC,UAAU,EAAE,CAAA;KACrC;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAoB;IAC9C,4D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C,GAAG,CAAC,GAAG,CAAC,CAAA;QACzC,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;YAC7D,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;YACpC,qFAAqF;YACrF,IAAI,KAAK,KAAK,QAAQ,EAAE;gBACtB,UAAU,CAAC,GAAG,EAAE;oBACd,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,OAAO,EAAE;wBAC3C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;qBAC/B;gBACH,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,CAAA;aACd;SACF;QAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAA;QAC5B,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,KAAK,CAAC,0BAA0B,CAAC,CAAA;SACxC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;CACF","sourcesContent":["import { JsonRpcProvider, Network, Provider } from 'ethers'\n\nimport PQueue from 'p-queue'\nimport { Endpoints } from '@sentio/runtime'\nimport { BaseContext } from '../core/index.js'\nimport { EthChainId } from '../core/chain.js'\nimport { EthContext } from './context.js'\n\nexport const DummyProvider = new JsonRpcProvider('', Network.from(1))\n\nconst providers = new Map<string, JsonRpcProvider>()\n\nexport function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {\n if (!networkish) {\n networkish = EthChainId.ETHEREUM\n }\n if (networkish instanceof BaseContext) {\n networkish = networkish.getChainId()\n }\n return networkish\n}\n\nexport function getProvider(chainId?: EthChainId): Provider {\n // const network = getNetworkFromCtxOrNetworkish(networkish)\n if (!chainId) {\n chainId = EthChainId.ETHEREUM\n }\n const network = Network.from(parseInt(chainId))\n // TODO check if other key needed\n\n const address = Endpoints.INSTANCE.chainServer.get(chainId)\n const key = network.chainId.toString() + '-' + address\n let provider = providers.get(key)\n\n if (provider) {\n return provider\n }\n\n if (address === undefined) {\n throw Error(\n 'Provider not found for chain ' +\n network.chainId +\n ', configured chains: ' +\n [...Endpoints.INSTANCE.chainServer.keys()].join(' ')\n )\n }\n provider = new QueuedStaticJsonRpcProvider(address, network, Endpoints.INSTANCE.concurrency)\n providers.set(network.chainId.toString(), provider)\n return provider\n}\n\nfunction getTag(prefix: string, value: any): string {\n return (\n prefix +\n ':' +\n JSON.stringify(value, (k, v) => {\n if (v == null) {\n return 'null'\n }\n if (typeof v === 'bigint') {\n return `bigint:${v.toString()}`\n }\n if (typeof v === 'string') {\n return v.toLowerCase()\n }\n\n // Sort object keys\n if (typeof v === 'object' && !Array.isArray(v)) {\n const keys = Object.keys(v)\n keys.sort()\n return keys.reduce((accum, key) => {\n accum[key] = v[key]\n return accum\n }, <any>{})\n }\n\n return v\n })\n )\n}\n\nclass QueuedStaticJsonRpcProvider extends JsonRpcProvider {\n executor: PQueue\n #performCache = new Map<string, Promise<any>>()\n\n constructor(url: string, network: Network, concurrency: number) {\n // TODO re-enable match when possible\n super(url, network, { staticNetwork: network, batchMaxCount: 1 })\n this.executor = new PQueue({ concurrency: concurrency })\n }\n\n async send(method: string, params: Array<any>): Promise<any> {\n const tag = getTag(method, params)\n const block = params[params.length - 1]\n let perform = this.#performCache.get(tag)\n if (!perform) {\n perform = this.executor.add(() => super.send(method, params))\n this.#performCache.set(tag, perform)\n // For non latest block call, we cache permanently, otherwise we cache for one minute\n if (block === 'latest') {\n setTimeout(() => {\n if (this.#performCache.get(tag) === perform) {\n this.#performCache.delete(tag)\n }\n }, 60 * 1000)\n }\n }\n\n const result = await perform\n if (!result) {\n throw Error('Unexpected null response')\n }\n return result\n }\n}\n"]}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/eth/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE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cesContent":["import { JsonRpcProvider, Network, Provider } from 'ethers'\n\nimport PQueue from 'p-queue'\nimport { Endpoints } from '@sentio/runtime'\nimport { EthChainId } from '../core/chain.js'\n\nexport const DummyProvider = new JsonRpcProvider('', Network.from(1))\n\nconst providers = new Map<string, JsonRpcProvider>()\n\n// export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {\n// if (!networkish) {\n// networkish = EthChainId.ETHEREUM\n// }\n// if (networkish instanceof BaseContext) {\n// networkish = networkish.getChainId()\n// }\n// return networkish\n// }\n\nexport function getProvider(chainId?: EthChainId): Provider {\n // const network = getNetworkFromCtxOrNetworkish(networkish)\n if (!chainId) {\n chainId = EthChainId.ETHEREUM\n }\n const network = Network.from(parseInt(chainId))\n // TODO check if other key needed\n\n const address = Endpoints.INSTANCE.chainServer.get(chainId)\n const key = network.chainId.toString() + '-' + address\n let provider = providers.get(key)\n\n if (provider) {\n return provider\n }\n\n if (address === undefined) {\n throw Error(\n 'Provider not found for chain ' +\n network.chainId +\n ', configured chains: ' +\n [...Endpoints.INSTANCE.chainServer.keys()].join(' ')\n )\n }\n provider = new QueuedStaticJsonRpcProvider(address, network, Endpoints.INSTANCE.concurrency)\n providers.set(network.chainId.toString(), provider)\n return provider\n}\n\nfunction getTag(prefix: string, value: any): string {\n return (\n prefix +\n ':' +\n JSON.stringify(value, (k, v) => {\n if (v == null) {\n return 'null'\n }\n if (typeof v === 'bigint') {\n return `bigint:${v.toString()}`\n }\n if (typeof v === 'string') {\n return v.toLowerCase()\n }\n\n // Sort object keys\n if (typeof v === 'object' && !Array.isArray(v)) {\n const keys = Object.keys(v)\n keys.sort()\n return keys.reduce((accum, key) => {\n accum[key] = v[key]\n return accum\n }, <any>{})\n }\n\n return v\n })\n )\n}\n\nclass QueuedStaticJsonRpcProvider extends JsonRpcProvider {\n executor: PQueue\n #performCache = new Map<string, Promise<any>>()\n\n constructor(url: string, network: Network, concurrency: number) {\n // TODO re-enable match when possible\n super(url, network, { staticNetwork: network, batchMaxCount: 1 })\n this.executor = new PQueue({ concurrency: concurrency })\n }\n\n async send(method: string, params: Array<any>): Promise<any> {\n const tag = getTag(method, params)\n const block = params[params.length - 1]\n let perform = this.#performCache.get(tag)\n if (!perform) {\n perform = this.executor.add(() => super.send(method, params))\n this.#performCache.set(tag, perform)\n // For non latest block call, we cache permanently, otherwise we cache for one minute\n if (block === 'latest') {\n setTimeout(() => {\n if (this.#performCache.get(tag) === perform) {\n this.#performCache.delete(tag)\n }\n }, 60 * 1000)\n }\n }\n\n const result = await perform\n if (!result) {\n throw Error('Unexpected null response')\n }\n return result\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.test.js","sourceRoot":"","sources":["../../src/eth/provider.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,iDAAiD;IACjD,mCAAmC;IACnC,+BAA+B;IAC/B,KAAK;IAEL,6CAA6C;IAC7C,iCAAiC;IACjC,+BAA+B;IAC/B,KAAK;IAEL,IAAI,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACxD,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QAC5B,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { getEthChainId } from './provider.js'\nimport { expect } from 'chai'\nimport { AccountContext } from './context.js'\nimport { EthChainId } from '../core/chain.js'\n\ndescribe('provider test', () => {\n // test('network test with string', async () => {\n // const n = getEthChainId('321')\n // expect(n.chainId).eq(321n)\n // })\n\n // test('network test with id', async () => {\n // const n = getEthChainId(321)\n // expect(n.chainId).eq(321n)\n // })\n\n test('network test with context', async () => {\n const ctx = new AccountContext(EthChainId.KUCOIN, '0x1')\n const n = getEthChainId(ctx)\n expect(n).eq(EthChainId.KUCOIN)\n })\n})\n"]}
1
+ {"version":3,"file":"provider.test.js","sourceRoot":"","sources":["../../src/eth/provider.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,iDAAiD;IACjD,mCAAmC;IACnC,+BAA+B;IAC/B,KAAK;IAEL,6CAA6C;IAC7C,iCAAiC;IACjC,+BAA+B;IAC/B,KAAK;IAEL,IAAI,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;QAC3C,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACxD,MAAM,CAAC,GAAG,GAAG,CAAC,UAAU,EAAE,CAAA;QAC1B,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IACjC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { expect } from 'chai'\nimport { AccountContext } from './context.js'\nimport { EthChainId } from '../core/chain.js'\n\ndescribe('provider test', () => {\n // test('network test with string', async () => {\n // const n = getEthChainId('321')\n // expect(n.chainId).eq(321n)\n // })\n\n // test('network test with id', async () => {\n // const n = getEthChainId(321)\n // expect(n.chainId).eq(321n)\n // })\n\n test('network test with context', async () => {\n const ctx = new AccountContext(EthChainId.KUCOIN, '0x1')\n const n = ctx.getChainId()\n expect(n).eq(EthChainId.KUCOIN)\n })\n})\n"]}
@@ -2,7 +2,8 @@ import { getERC20Contract } from '../eth/builtin/erc20.js';
2
2
  import { getERC20BytesContract } from '../eth/builtin/erc20bytes.js';
3
3
  import { scaleDown } from '../core/big-decimal.js';
4
4
  import { decodeBytes32String } from 'ethers';
5
- import { getEthChainId } from '../eth/index.js';
5
+ import { EthChainId } from '../eth/index.js';
6
+ import { BaseContext } from '../core/index.js';
6
7
  export const NATIVE_ETH = {
7
8
  symbol: 'ETH',
8
9
  decimal: 18,
@@ -17,7 +18,13 @@ async function getTokenInfoPromise(symbol, name, decimal) {
17
18
  };
18
19
  }
19
20
  export async function getERC20TokenInfo(contextOrNetworkish, tokenAddress) {
20
- const chainId = getEthChainId(contextOrNetworkish);
21
+ let chainId;
22
+ if (contextOrNetworkish instanceof BaseContext) {
23
+ chainId = contextOrNetworkish.getChainId();
24
+ }
25
+ else {
26
+ chainId = contextOrNetworkish || EthChainId.ETHEREUM;
27
+ }
21
28
  const key = chainId + tokenAddress;
22
29
  const res = TOKEN_INFOS.get(key);
23
30
  if (res) {
@@ -1 +1 @@
1
- {"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAc,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAA0B,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAQvE,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,YAAY;CACnB,CAAA;AAED,MAAM,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAA;AAEzD,KAAK,UAAU,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,CAAC,CAAA;IAC1B,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,mBAA4C,EAC5C,YAAoB,EACpB,MAAc;IAEd,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAA;IAC5E,OAAO,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { getERC20Contract } from '../eth/builtin/erc20.js'\nimport { getERC20BytesContract } from '../eth/builtin/erc20bytes.js'\nimport { BigDecimal, scaleDown } from '../core/big-decimal.js'\nimport { PromiseOrValue } from '../eth/builtin/internal/common.js'\nimport { decodeBytes32String } from 'ethers'\nimport { EthChainId, EthContext, getEthChainId } from '../eth/index.js'\n\nexport interface TokenInfo {\n symbol: string\n name: string\n decimal: number\n}\n\nexport const NATIVE_ETH = {\n symbol: 'ETH',\n decimal: 18,\n name: 'Native ETH',\n}\n\nconst TOKEN_INFOS = new Map<string, Promise<TokenInfo>>()\n\nasync function getTokenInfoPromise(\n symbol: PromiseOrValue<string> | string,\n name: PromiseOrValue<string> | string,\n decimal: PromiseOrValue<bigint>\n): Promise<TokenInfo> {\n return {\n symbol: await symbol,\n name: await name,\n decimal: Number(await decimal),\n }\n}\n\nexport async function getERC20TokenInfo(\n contextOrNetworkish: EthContext | EthChainId,\n tokenAddress: string\n): Promise<TokenInfo> {\n const chainId = getEthChainId(contextOrNetworkish)\n const key = chainId + tokenAddress\n const res = TOKEN_INFOS.get(key)\n if (res) {\n return res\n }\n const contract = getERC20Contract(chainId, tokenAddress)\n const bytesContract = getERC20BytesContract(chainId, tokenAddress)\n\n let name = ''\n try {\n name = await contract.name()\n } catch (e) {\n name = decodeBytes32String(await bytesContract.name())\n }\n\n let symbol = ''\n try {\n symbol = await contract.symbol()\n } catch (e) {\n symbol = decodeBytes32String(await bytesContract.symbol())\n }\n\n const decimal = await contract.decimals()\n const info = getTokenInfoPromise(symbol, name, decimal)\n\n TOKEN_INFOS.set(key, info)\n return info\n}\n\nexport async function getER20NormalizedAmount(\n contextOrNetworkish: EthContext | EthChainId,\n tokenAddress: string,\n amount: bigint\n): Promise<BigDecimal> {\n const tokenInfo = await getERC20TokenInfo(contextOrNetworkish, tokenAddress)\n return scaleDown(amount, tokenInfo.decimal)\n}\n"]}
1
+ {"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAc,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAc,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAQ9C,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,YAAY;CACnB,CAAA;AAED,MAAM,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAA;AAEzD,KAAK,UAAU,mBAAmB,CAChC,MAAuC,EACvC,IAAqC,EACrC,OAA+B;IAE/B,OAAO;QACL,MAAM,EAAE,MAAM,MAAM;QACpB,IAAI,EAAE,MAAM,IAAI;QAChB,OAAO,EAAE,MAAM,CAAC,MAAM,OAAO,CAAC;KAC/B,CAAA;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,mBAA4C,EAC5C,YAAoB;IAEpB,IAAI,OAAmB,CAAA;IACvB,IAAI,mBAAmB,YAAY,WAAW,EAAE;QAC9C,OAAO,GAAG,mBAAmB,CAAC,UAAU,EAAE,CAAA;KAC3C;SAAM;QACL,OAAO,GAAG,mBAAmB,IAAI,UAAU,CAAC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{ getERC20Contract } from '../eth/builtin/erc20.js'\nimport { getERC20BytesContract } from '../eth/builtin/erc20bytes.js'\nimport { BigDecimal, scaleDown } from '../core/big-decimal.js'\nimport { PromiseOrValue } from '../eth/builtin/internal/common.js'\nimport { decodeBytes32String } from 'ethers'\nimport { EthChainId, EthContext } from '../eth/index.js'\nimport { BaseContext } from '../core/index.js'\n\nexport interface TokenInfo {\n symbol: string\n name: string\n decimal: number\n}\n\nexport const NATIVE_ETH = {\n symbol: 'ETH',\n decimal: 18,\n name: 'Native ETH',\n}\n\nconst TOKEN_INFOS = new Map<string, Promise<TokenInfo>>()\n\nasync function getTokenInfoPromise(\n symbol: PromiseOrValue<string> | string,\n name: PromiseOrValue<string> | string,\n decimal: PromiseOrValue<bigint>\n): Promise<TokenInfo> {\n return {\n symbol: await symbol,\n name: await name,\n decimal: Number(await decimal),\n }\n}\n\nexport async function getERC20TokenInfo(\n contextOrNetworkish: EthContext | EthChainId,\n tokenAddress: string\n): Promise<TokenInfo> {\n let chainId: EthChainId\n if (contextOrNetworkish instanceof BaseContext) {\n chainId = contextOrNetworkish.getChainId()\n } else {\n chainId = contextOrNetworkish || EthChainId.ETHEREUM\n }\n\n const key = chainId + tokenAddress\n const res = TOKEN_INFOS.get(key)\n if (res) {\n return res\n }\n const contract = getERC20Contract(chainId, tokenAddress)\n const bytesContract = getERC20BytesContract(chainId, tokenAddress)\n\n let name = ''\n try {\n name = await contract.name()\n } catch (e) {\n name = decodeBytes32String(await bytesContract.name())\n }\n\n let symbol = ''\n try {\n symbol = await contract.symbol()\n } catch (e) {\n symbol = decodeBytes32String(await bytesContract.symbol())\n }\n\n const decimal = await contract.decimals()\n const info = getTokenInfoPromise(symbol, name, decimal)\n\n TOKEN_INFOS.set(key, info)\n return info\n}\n\nexport async function getER20NormalizedAmount(\n contextOrNetworkish: EthContext | EthChainId,\n tokenAddress: string,\n amount: bigint\n): Promise<BigDecimal> {\n const tokenInfo = await getERC20TokenInfo(contextOrNetworkish, tokenAddress)\n return scaleDown(amount, tokenInfo.decimal)\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
- "version": "2.15.6-rc.1",
3
+ "version": "2.15.6-rc.3",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -70,8 +70,8 @@
70
70
  "typechain": "^8.0.0",
71
71
  "typedoc": "^0.24.1",
72
72
  "yaml": "^2.2.1",
73
- "@sentio/protos": "^2.15.6-rc.1",
74
- "@sentio/runtime": "^2.15.6-rc.1"
73
+ "@sentio/protos": "^2.15.6-rc.3",
74
+ "@sentio/runtime": "^2.15.6-rc.3"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "tsup": "npm:@sentio/tsup@^6.7.0"
@@ -18,13 +18,13 @@ import {
18
18
  DummyProvider,
19
19
  EthChainId,
20
20
  TypedCallTrace,
21
- getEthChainId,
22
21
  EthContext,
23
22
  EthFetchConfig,
24
23
  } from "@sentio/sdk/eth";
25
24
 
26
- import { EACAggregatorProxy, EACAggregatorProxy__factory } from "./index.js";
25
+ import { EACAggregatorProxy__factory } from "./index.js";
27
26
  import {
27
+ EACAggregatorProxy,
28
28
  AnswerUpdatedEvent,
29
29
  AnswerUpdatedEventFilter,
30
30
  NewRoundEvent,
@@ -421,51 +421,41 @@ export class EACAggregatorProxyBoundContractView extends BoundContractView<
421
421
  EACAggregatorProxyContractView
422
422
  > {
423
423
  async accessController(overrides?: Overrides): Promise<string> {
424
- if (!overrides && this.context) {
425
- overrides = {
426
- blockTag: this.context.blockNumber,
427
- };
428
- }
429
- return await this.view.accessController(overrides || {});
424
+ return await this.view.accessController({
425
+ blockTag: this.context.blockNumber,
426
+ ...overrides,
427
+ });
430
428
  }
431
429
 
432
430
  async aggregator(overrides?: Overrides): Promise<string> {
433
- if (!overrides && this.context) {
434
- overrides = {
435
- blockTag: this.context.blockNumber,
436
- };
437
- }
438
- return await this.view.aggregator(overrides || {});
431
+ return await this.view.aggregator({
432
+ blockTag: this.context.blockNumber,
433
+ ...overrides,
434
+ });
439
435
  }
440
436
 
441
437
  async decimals(overrides?: Overrides): Promise<bigint> {
442
- if (!overrides && this.context) {
443
- overrides = {
444
- blockTag: this.context.blockNumber,
445
- };
446
- }
447
- return await this.view.decimals(overrides || {});
438
+ return await this.view.decimals({
439
+ blockTag: this.context.blockNumber,
440
+ ...overrides,
441
+ });
448
442
  }
449
443
 
450
444
  async description(overrides?: Overrides): Promise<string> {
451
- if (!overrides && this.context) {
452
- overrides = {
453
- blockTag: this.context.blockNumber,
454
- };
455
- }
456
- return await this.view.description(overrides || {});
445
+ return await this.view.description({
446
+ blockTag: this.context.blockNumber,
447
+ ...overrides,
448
+ });
457
449
  }
458
450
 
459
451
  async getAnswer(
460
452
  _roundId: BigNumberish,
461
453
  overrides?: Overrides
462
454
  ): Promise<bigint> {
463
- if (!overrides && this.context) {
464
- overrides = {
465
- blockTag: this.context.blockNumber,
466
- };
467
- }
468
- return await this.view.getAnswer(_roundId, overrides || {});
455
+ return await this.view.getAnswer(_roundId, {
456
+ blockTag: this.context.blockNumber,
457
+ ...overrides,
458
+ });
469
459
  }
470
460
 
471
461
  async getRoundData(
@@ -480,42 +470,34 @@ export class EACAggregatorProxyBoundContractView extends BoundContractView<
480
470
  answeredInRound: bigint;
481
471
  }
482
472
  > {
483
- if (!overrides && this.context) {
484
- overrides = {
485
- blockTag: this.context.blockNumber,
486
- };
487
- }
488
- return await this.view.getRoundData(_roundId, overrides || {});
473
+ return await this.view.getRoundData(_roundId, {
474
+ blockTag: this.context.blockNumber,
475
+ ...overrides,
476
+ });
489
477
  }
490
478
 
491
479
  async getTimestamp(
492
480
  _roundId: BigNumberish,
493
481
  overrides?: Overrides
494
482
  ): Promise<bigint> {
495
- if (!overrides && this.context) {
496
- overrides = {
497
- blockTag: this.context.blockNumber,
498
- };
499
- }
500
- return await this.view.getTimestamp(_roundId, overrides || {});
483
+ return await this.view.getTimestamp(_roundId, {
484
+ blockTag: this.context.blockNumber,
485
+ ...overrides,
486
+ });
501
487
  }
502
488
 
503
489
  async latestAnswer(overrides?: Overrides): Promise<bigint> {
504
- if (!overrides && this.context) {
505
- overrides = {
506
- blockTag: this.context.blockNumber,
507
- };
508
- }
509
- return await this.view.latestAnswer(overrides || {});
490
+ return await this.view.latestAnswer({
491
+ blockTag: this.context.blockNumber,
492
+ ...overrides,
493
+ });
510
494
  }
511
495
 
512
496
  async latestRound(overrides?: Overrides): Promise<bigint> {
513
- if (!overrides && this.context) {
514
- overrides = {
515
- blockTag: this.context.blockNumber,
516
- };
517
- }
518
- return await this.view.latestRound(overrides || {});
497
+ return await this.view.latestRound({
498
+ blockTag: this.context.blockNumber,
499
+ ...overrides,
500
+ });
519
501
  }
520
502
 
521
503
  async latestRoundData(
@@ -529,60 +511,48 @@ export class EACAggregatorProxyBoundContractView extends BoundContractView<
529
511
  answeredInRound: bigint;
530
512
  }
531
513
  > {
532
- if (!overrides && this.context) {
533
- overrides = {
534
- blockTag: this.context.blockNumber,
535
- };
536
- }
537
- return await this.view.latestRoundData(overrides || {});
514
+ return await this.view.latestRoundData({
515
+ blockTag: this.context.blockNumber,
516
+ ...overrides,
517
+ });
538
518
  }
539
519
 
540
520
  async latestTimestamp(overrides?: Overrides): Promise<bigint> {
541
- if (!overrides && this.context) {
542
- overrides = {
543
- blockTag: this.context.blockNumber,
544
- };
545
- }
546
- return await this.view.latestTimestamp(overrides || {});
521
+ return await this.view.latestTimestamp({
522
+ blockTag: this.context.blockNumber,
523
+ ...overrides,
524
+ });
547
525
  }
548
526
 
549
527
  async owner(overrides?: Overrides): Promise<string> {
550
- if (!overrides && this.context) {
551
- overrides = {
552
- blockTag: this.context.blockNumber,
553
- };
554
- }
555
- return await this.view.owner(overrides || {});
528
+ return await this.view.owner({
529
+ blockTag: this.context.blockNumber,
530
+ ...overrides,
531
+ });
556
532
  }
557
533
 
558
534
  async phaseAggregators(
559
535
  arg0: BigNumberish,
560
536
  overrides?: Overrides
561
537
  ): Promise<string> {
562
- if (!overrides && this.context) {
563
- overrides = {
564
- blockTag: this.context.blockNumber,
565
- };
566
- }
567
- return await this.view.phaseAggregators(arg0, overrides || {});
538
+ return await this.view.phaseAggregators(arg0, {
539
+ blockTag: this.context.blockNumber,
540
+ ...overrides,
541
+ });
568
542
  }
569
543
 
570
544
  async phaseId(overrides?: Overrides): Promise<bigint> {
571
- if (!overrides && this.context) {
572
- overrides = {
573
- blockTag: this.context.blockNumber,
574
- };
575
- }
576
- return await this.view.phaseId(overrides || {});
545
+ return await this.view.phaseId({
546
+ blockTag: this.context.blockNumber,
547
+ ...overrides,
548
+ });
577
549
  }
578
550
 
579
551
  async proposedAggregator(overrides?: Overrides): Promise<string> {
580
- if (!overrides && this.context) {
581
- overrides = {
582
- blockTag: this.context.blockNumber,
583
- };
584
- }
585
- return await this.view.proposedAggregator(overrides || {});
552
+ return await this.view.proposedAggregator({
553
+ blockTag: this.context.blockNumber,
554
+ ...overrides,
555
+ });
586
556
  }
587
557
 
588
558
  async proposedGetRoundData(
@@ -597,12 +567,10 @@ export class EACAggregatorProxyBoundContractView extends BoundContractView<
597
567
  answeredInRound: bigint;
598
568
  }
599
569
  > {
600
- if (!overrides && this.context) {
601
- overrides = {
602
- blockTag: this.context.blockNumber,
603
- };
604
- }
605
- return await this.view.proposedGetRoundData(_roundId, overrides || {});
570
+ return await this.view.proposedGetRoundData(_roundId, {
571
+ blockTag: this.context.blockNumber,
572
+ ...overrides,
573
+ });
606
574
  }
607
575
 
608
576
  async proposedLatestRoundData(
@@ -616,21 +584,17 @@ export class EACAggregatorProxyBoundContractView extends BoundContractView<
616
584
  answeredInRound: bigint;
617
585
  }
618
586
  > {
619
- if (!overrides && this.context) {
620
- overrides = {
621
- blockTag: this.context.blockNumber,
622
- };
623
- }
624
- return await this.view.proposedLatestRoundData(overrides || {});
587
+ return await this.view.proposedLatestRoundData({
588
+ blockTag: this.context.blockNumber,
589
+ ...overrides,
590
+ });
625
591
  }
626
592
 
627
593
  async version(overrides?: Overrides): Promise<bigint> {
628
- if (!overrides && this.context) {
629
- overrides = {
630
- blockTag: this.context.blockNumber,
631
- };
632
- }
633
- return await this.view.version(overrides || {});
594
+ return await this.view.version({
595
+ blockTag: this.context.blockNumber,
596
+ ...overrides,
597
+ });
634
598
  }
635
599
  }
636
600
 
@@ -1067,22 +1031,29 @@ export class EACAggregatorProxyProcessorTemplate extends BaseProcessorTemplate<
1067
1031
  }
1068
1032
 
1069
1033
  export function getEACAggregatorProxyContract(
1070
- contextOrNetwork: EthContext | EthChainId,
1034
+ chainId: EthChainId,
1071
1035
  address: string
1072
1036
  ): EACAggregatorProxyContractView {
1073
- const network = getEthChainId(contextOrNetwork);
1074
1037
  let contract = getContractByABI(
1075
1038
  "EACAggregatorProxy",
1076
1039
  address,
1077
- network
1040
+ chainId
1078
1041
  ) as EACAggregatorProxyContractView;
1079
1042
  if (!contract) {
1080
1043
  const rawContract = EACAggregatorProxy__factory.connect(
1081
1044
  address,
1082
- getProvider(network)
1045
+ getProvider(chainId)
1083
1046
  );
1084
1047
  contract = new EACAggregatorProxyContractView(rawContract);
1085
- addContractByABI("EACAggregatorProxy", address, network, contract);
1048
+ addContractByABI("EACAggregatorProxy", address, chainId, contract);
1086
1049
  }
1087
1050
  return contract;
1088
1051
  }
1052
+
1053
+ export function getEACAggregatorProxyContractOnContext(
1054
+ context: EthContext,
1055
+ address: string
1056
+ ): EACAggregatorProxyBoundContractView {
1057
+ const view = getEACAggregatorProxyContract(context.getChainId(), address);
1058
+ return new EACAggregatorProxyBoundContractView(address, view);
1059
+ }