@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
@@ -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 { WETH9, WETH9__factory } from "./index.js";
25
+ import { WETH9__factory } from "./index.js";
27
26
  import {
27
+ WETH9,
28
28
  ApprovalEvent,
29
29
  ApprovalEventFilter,
30
30
  TransferEvent,
@@ -175,48 +175,38 @@ export class WETH9BoundContractView extends BoundContractView<
175
175
  WETH9ContractView
176
176
  > {
177
177
  async name(overrides?: Overrides): Promise<string> {
178
- if (!overrides && this.context) {
179
- overrides = {
180
- blockTag: this.context.blockNumber,
181
- };
182
- }
183
- return await this.view.name(overrides || {});
178
+ return await this.view.name({
179
+ blockTag: this.context.blockNumber,
180
+ ...overrides,
181
+ });
184
182
  }
185
183
 
186
184
  async totalSupply(overrides?: Overrides): Promise<bigint> {
187
- if (!overrides && this.context) {
188
- overrides = {
189
- blockTag: this.context.blockNumber,
190
- };
191
- }
192
- return await this.view.totalSupply(overrides || {});
185
+ return await this.view.totalSupply({
186
+ blockTag: this.context.blockNumber,
187
+ ...overrides,
188
+ });
193
189
  }
194
190
 
195
191
  async decimals(overrides?: Overrides): Promise<bigint> {
196
- if (!overrides && this.context) {
197
- overrides = {
198
- blockTag: this.context.blockNumber,
199
- };
200
- }
201
- return await this.view.decimals(overrides || {});
192
+ return await this.view.decimals({
193
+ blockTag: this.context.blockNumber,
194
+ ...overrides,
195
+ });
202
196
  }
203
197
 
204
198
  async balanceOf(arg0: string, overrides?: Overrides): Promise<bigint> {
205
- if (!overrides && this.context) {
206
- overrides = {
207
- blockTag: this.context.blockNumber,
208
- };
209
- }
210
- return await this.view.balanceOf(arg0, overrides || {});
199
+ return await this.view.balanceOf(arg0, {
200
+ blockTag: this.context.blockNumber,
201
+ ...overrides,
202
+ });
211
203
  }
212
204
 
213
205
  async symbol(overrides?: Overrides): Promise<string> {
214
- if (!overrides && this.context) {
215
- overrides = {
216
- blockTag: this.context.blockNumber,
217
- };
218
- }
219
- return await this.view.symbol(overrides || {});
206
+ return await this.view.symbol({
207
+ blockTag: this.context.blockNumber,
208
+ ...overrides,
209
+ });
220
210
  }
221
211
 
222
212
  async allowance(
@@ -224,12 +214,10 @@ export class WETH9BoundContractView extends BoundContractView<
224
214
  arg1: string,
225
215
  overrides?: Overrides
226
216
  ): Promise<bigint> {
227
- if (!overrides && this.context) {
228
- overrides = {
229
- blockTag: this.context.blockNumber,
230
- };
231
- }
232
- return await this.view.allowance(arg0, arg1, overrides || {});
217
+ return await this.view.allowance(arg0, arg1, {
218
+ blockTag: this.context.blockNumber,
219
+ ...overrides,
220
+ });
233
221
  }
234
222
  }
235
223
 
@@ -485,19 +473,26 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
485
473
  }
486
474
 
487
475
  export function getWETH9Contract(
488
- contextOrNetwork: EthContext | EthChainId,
476
+ chainId: EthChainId,
489
477
  address: string
490
478
  ): WETH9ContractView {
491
- const network = getEthChainId(contextOrNetwork);
492
479
  let contract = getContractByABI(
493
480
  "WETH9",
494
481
  address,
495
- network
482
+ chainId
496
483
  ) as WETH9ContractView;
497
484
  if (!contract) {
498
- const rawContract = WETH9__factory.connect(address, getProvider(network));
485
+ const rawContract = WETH9__factory.connect(address, getProvider(chainId));
499
486
  contract = new WETH9ContractView(rawContract);
500
- addContractByABI("WETH9", address, network, contract);
487
+ addContractByABI("WETH9", address, chainId, contract);
501
488
  }
502
489
  return contract;
503
490
  }
491
+
492
+ export function getWETH9ContractOnContext(
493
+ context: EthContext,
494
+ address: string
495
+ ): WETH9BoundContractView {
496
+ const view = getWETH9Contract(context.getChainId(), address);
497
+ return new WETH9BoundContractView(address, view);
498
+ }
@@ -106,18 +106,21 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
106
106
  .join('\n')}
107
107
  }
108
108
 
109
- export function get${contract.name}Contract(contextOrNetwork: EthContext | EthChainId, address: string): ${
110
- contract.name
111
- }ContractView {
112
- const network = getEthChainId(contextOrNetwork)
113
- let contract = getContractByABI("${contract.name}", address, network) as ${contract.name}ContractView
109
+ export function get${contract.name}Contract(chainId: EthChainId, address: string): ${contract.name}ContractView {
110
+ let contract = getContractByABI("${contract.name}", address, chainId) as ${contract.name}ContractView
114
111
  if (!contract) {
115
- const rawContract = ${contract.name}__factory.connect(address, getProvider(network))
112
+ const rawContract = ${contract.name}__factory.connect(address, getProvider(chainId))
116
113
  contract = new ${contract.name}ContractView(rawContract)
117
- addContractByABI("${contract.name}", address, network, contract)
114
+ addContractByABI("${contract.name}", address, chainId, contract)
118
115
  }
119
116
  return contract
120
117
  }
118
+
119
+ export function get${contract.name}ContractOnContext(context: EthContext, address: string):
120
+ ${contract.name}BoundContractView {
121
+ const view = get${contract.name}Contract(context.getChainId(), address)
122
+ return new ${contract.name}BoundContractView(address, view)
123
+ }
121
124
  `
122
125
  const eventsImports = Object.values(contract.events).flatMap((events) => {
123
126
  if (events.length === 1) {
@@ -166,16 +169,14 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
166
169
  'DummyProvider',
167
170
  'EthChainId',
168
171
  'TypedCallTrace',
169
- 'getEthChainId',
170
- // 'toBlockTag',
171
172
  'EthContext',
172
173
  'EthFetchConfig',
173
174
  ],
174
175
  // '@sentio/sdk/eth': ['BaseContext'],
175
176
  // '@sentio/protos': ['EthFetchConfig'],
176
177
  './common.js': ['PromiseOrValue'],
177
- './index.js': [`${contract.name}`, `${contract.name}__factory`],
178
- [`./${contract.name}.js`]: eventsImports.concat(uniqueStructImports),
178
+ './index.js': [`${contract.name}__factory`],
179
+ [`./${contract.name}.js`]: [`${contract.name}`, ...eventsImports, ...uniqueStructImports],
179
180
  },
180
181
  source
181
182
  )
@@ -60,14 +60,12 @@ export function generateBoundViewFunction(fn: FunctionDeclaration, includeArgTyp
60
60
  async ${declName ?? fn.name}(${generateInputTypes(fn.inputs, {
61
61
  useStructs: true,
62
62
  })}overrides?: Overrides): ${generateReturnTypes(fn)} {
63
- if (!overrides && this.context) {
64
- overrides = {
65
- blockTag: this.context.blockNumber,
66
- }
67
- }
68
63
  return await this.view.${declName}(${
69
64
  fn.inputs.length > 0 ? fn.inputs.map((input, index) => input.name || `arg${index}`).join(',') + ',' : ''
70
- } overrides || {})
65
+ } {
66
+ blockTag: this.context.blockNumber,
67
+ ...overrides
68
+ })
71
69
  }
72
70
  `
73
71
  }
package/src/eth/index.ts 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'
@@ -2,23 +2,21 @@ import { JsonRpcProvider, Network, Provider } from 'ethers'
2
2
 
3
3
  import PQueue from 'p-queue'
4
4
  import { Endpoints } from '@sentio/runtime'
5
- import { BaseContext } from '../core/index.js'
6
5
  import { EthChainId } from '../core/chain.js'
7
- import { EthContext } from './context.js'
8
6
 
9
7
  export const DummyProvider = new JsonRpcProvider('', Network.from(1))
10
8
 
11
9
  const providers = new Map<string, JsonRpcProvider>()
12
10
 
13
- export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {
14
- if (!networkish) {
15
- networkish = EthChainId.ETHEREUM
16
- }
17
- if (networkish instanceof BaseContext) {
18
- networkish = networkish.getChainId()
19
- }
20
- return networkish
21
- }
11
+ // export function getEthChainId(networkish?: EthContext | EthChainId): EthChainId {
12
+ // if (!networkish) {
13
+ // networkish = EthChainId.ETHEREUM
14
+ // }
15
+ // if (networkish instanceof BaseContext) {
16
+ // networkish = networkish.getChainId()
17
+ // }
18
+ // return networkish
19
+ // }
22
20
 
23
21
  export function getProvider(chainId?: EthChainId): Provider {
24
22
  // const network = getNetworkFromCtxOrNetworkish(networkish)
@@ -3,7 +3,8 @@ import { getERC20BytesContract } from '../eth/builtin/erc20bytes.js'
3
3
  import { BigDecimal, scaleDown } from '../core/big-decimal.js'
4
4
  import { PromiseOrValue } from '../eth/builtin/internal/common.js'
5
5
  import { decodeBytes32String } from 'ethers'
6
- import { EthChainId, EthContext, getEthChainId } from '../eth/index.js'
6
+ import { EthChainId, EthContext } from '../eth/index.js'
7
+ import { BaseContext } from '../core/index.js'
7
8
 
8
9
  export interface TokenInfo {
9
10
  symbol: string
@@ -35,7 +36,13 @@ export async function getERC20TokenInfo(
35
36
  contextOrNetworkish: EthContext | EthChainId,
36
37
  tokenAddress: string
37
38
  ): Promise<TokenInfo> {
38
- const chainId = getEthChainId(contextOrNetworkish)
39
+ let chainId: EthChainId
40
+ if (contextOrNetworkish instanceof BaseContext) {
41
+ chainId = contextOrNetworkish.getChainId()
42
+ } else {
43
+ chainId = contextOrNetworkish || EthChainId.ETHEREUM
44
+ }
45
+
39
46
  const key = chainId + tokenAddress
40
47
  const res = TOKEN_INFOS.get(key)
41
48
  if (res) {