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

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 +2 -1
  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 +2 -1
  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 +2 -1
  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 +2 -1
  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 +2 -1
  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 +2 -1
  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 +10 -7
  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 +84 -114
  34. package/src/eth/builtin/internal/erc1155-processor.ts +32 -36
  35. package/src/eth/builtin/internal/erc20-processor.ts +44 -54
  36. package/src/eth/builtin/internal/erc20bytes-processor.ts +36 -42
  37. package/src/eth/builtin/internal/erc721-processor.ts +48 -60
  38. package/src/eth/builtin/internal/weth9-processor.ts +36 -42
  39. package/src/eth/codegen/file.ts +10 -9
  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,7 +18,6 @@ import {
18
18
  DummyProvider,
19
19
  EthChainId,
20
20
  TypedCallTrace,
21
- getEthChainId,
22
21
  EthContext,
23
22
  EthFetchConfig,
24
23
  } from "@sentio/sdk/eth";
@@ -175,48 +174,38 @@ export class WETH9BoundContractView extends BoundContractView<
175
174
  WETH9ContractView
176
175
  > {
177
176
  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 || {});
177
+ return await this.view.name({
178
+ blockTag: this.context.blockNumber,
179
+ ...overrides,
180
+ });
184
181
  }
185
182
 
186
183
  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 || {});
184
+ return await this.view.totalSupply({
185
+ blockTag: this.context.blockNumber,
186
+ ...overrides,
187
+ });
193
188
  }
194
189
 
195
190
  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 || {});
191
+ return await this.view.decimals({
192
+ blockTag: this.context.blockNumber,
193
+ ...overrides,
194
+ });
202
195
  }
203
196
 
204
197
  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 || {});
198
+ return await this.view.balanceOf(arg0, {
199
+ blockTag: this.context.blockNumber,
200
+ ...overrides,
201
+ });
211
202
  }
212
203
 
213
204
  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 || {});
205
+ return await this.view.symbol({
206
+ blockTag: this.context.blockNumber,
207
+ ...overrides,
208
+ });
220
209
  }
221
210
 
222
211
  async allowance(
@@ -224,12 +213,10 @@ export class WETH9BoundContractView extends BoundContractView<
224
213
  arg1: string,
225
214
  overrides?: Overrides
226
215
  ): 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 || {});
216
+ return await this.view.allowance(arg0, arg1, {
217
+ blockTag: this.context.blockNumber,
218
+ ...overrides,
219
+ });
233
220
  }
234
221
  }
235
222
 
@@ -485,19 +472,26 @@ export class WETH9ProcessorTemplate extends BaseProcessorTemplate<
485
472
  }
486
473
 
487
474
  export function getWETH9Contract(
488
- contextOrNetwork: EthContext | EthChainId,
475
+ chainId: EthChainId,
489
476
  address: string
490
477
  ): WETH9ContractView {
491
- const network = getEthChainId(contextOrNetwork);
492
478
  let contract = getContractByABI(
493
479
  "WETH9",
494
480
  address,
495
- network
481
+ chainId
496
482
  ) as WETH9ContractView;
497
483
  if (!contract) {
498
- const rawContract = WETH9__factory.connect(address, getProvider(network));
484
+ const rawContract = WETH9__factory.connect(address, getProvider(chainId));
499
485
  contract = new WETH9ContractView(rawContract);
500
- addContractByABI("WETH9", address, network, contract);
486
+ addContractByABI("WETH9", address, chainId, contract);
501
487
  }
502
488
  return contract;
503
489
  }
490
+
491
+ export function getWETH9ContractOnContext(
492
+ context: EthContext,
493
+ address: string
494
+ ): WETH9BoundContractView {
495
+ const view = getWETH9Contract(context.getChainId(), address);
496
+ return new WETH9BoundContractView(address, view);
497
+ }
@@ -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,8 +169,6 @@ 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
  ],
@@ -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) {