@sentio/sdk 2.7.4-rc.2 → 2.8.0-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 (81) hide show
  1. package/lib/aptos/context.d.ts +2 -0
  2. package/lib/aptos/context.js +8 -2
  3. package/lib/aptos/context.js.map +1 -1
  4. package/lib/aptos/ext/aptos-dex.js +2 -0
  5. package/lib/aptos/ext/aptos-dex.js.map +1 -1
  6. package/lib/core/base-context.d.ts +1 -0
  7. package/lib/core/base-context.js.map +1 -1
  8. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts +2 -1
  9. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +3 -2
  10. package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
  11. package/lib/eth/builtin/internal/eacaggregatorproxy-test-utils.js +4 -4
  12. package/lib/eth/builtin/internal/eacaggregatorproxy-test-utils.js.map +1 -1
  13. package/lib/eth/builtin/internal/erc1155-processor.d.ts +2 -1
  14. package/lib/eth/builtin/internal/erc1155-processor.js +3 -2
  15. package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
  16. package/lib/eth/builtin/internal/erc1155-test-utils.js +4 -4
  17. package/lib/eth/builtin/internal/erc1155-test-utils.js.map +1 -1
  18. package/lib/eth/builtin/internal/erc20-processor.d.ts +2 -1
  19. package/lib/eth/builtin/internal/erc20-processor.js +3 -2
  20. package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
  21. package/lib/eth/builtin/internal/erc20-test-utils.js +3 -3
  22. package/lib/eth/builtin/internal/erc20-test-utils.js.map +1 -1
  23. package/lib/eth/builtin/internal/erc20bytes-processor.d.ts +2 -1
  24. package/lib/eth/builtin/internal/erc20bytes-processor.js +3 -2
  25. package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
  26. package/lib/eth/builtin/internal/erc20bytes-test-utils.js +2 -2
  27. package/lib/eth/builtin/internal/erc20bytes-test-utils.js.map +1 -1
  28. package/lib/eth/builtin/internal/erc721-processor.d.ts +2 -1
  29. package/lib/eth/builtin/internal/erc721-processor.js +3 -2
  30. package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
  31. package/lib/eth/builtin/internal/erc721-test-utils.js +3 -3
  32. package/lib/eth/builtin/internal/erc721-test-utils.js.map +1 -1
  33. package/lib/eth/builtin/internal/weth9-processor.d.ts +2 -1
  34. package/lib/eth/builtin/internal/weth9-processor.js +3 -2
  35. package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
  36. package/lib/eth/builtin/internal/weth9-test-utils.js +4 -4
  37. package/lib/eth/builtin/internal/weth9-test-utils.js.map +1 -1
  38. package/lib/eth/codegen/file.js +5 -3
  39. package/lib/eth/codegen/file.js.map +1 -1
  40. package/lib/eth/context.d.ts +1 -0
  41. package/lib/eth/context.js +3 -0
  42. package/lib/eth/context.js.map +1 -1
  43. package/lib/eth/index.d.ts +1 -1
  44. package/lib/eth/index.js +1 -1
  45. package/lib/eth/index.js.map +1 -1
  46. package/lib/eth/provider.d.ts +3 -1
  47. package/lib/eth/provider.js +9 -2
  48. package/lib/eth/provider.js.map +1 -1
  49. package/lib/solana/solana-context.d.ts +1 -0
  50. package/lib/solana/solana-context.js +4 -1
  51. package/lib/solana/solana-context.js.map +1 -1
  52. package/lib/sui/context.d.ts +1 -0
  53. package/lib/sui/context.js +4 -1
  54. package/lib/sui/context.js.map +1 -1
  55. package/lib/utils/erc20.test.js.map +1 -1
  56. package/lib/utils/token.d.ts +4 -2
  57. package/lib/utils/token.js +5 -3
  58. package/lib/utils/token.js.map +1 -1
  59. package/package.json +4 -4
  60. package/src/aptos/context.ts +10 -2
  61. package/src/aptos/ext/aptos-dex.ts +2 -0
  62. package/src/core/base-context.ts +2 -0
  63. package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +4 -1
  64. package/src/eth/builtin/internal/eacaggregatorproxy-test-utils.ts +4 -4
  65. package/src/eth/builtin/internal/erc1155-processor.ts +4 -1
  66. package/src/eth/builtin/internal/erc1155-test-utils.ts +4 -4
  67. package/src/eth/builtin/internal/erc20-processor.ts +4 -1
  68. package/src/eth/builtin/internal/erc20-test-utils.ts +3 -3
  69. package/src/eth/builtin/internal/erc20bytes-processor.ts +4 -1
  70. package/src/eth/builtin/internal/erc20bytes-test-utils.ts +2 -2
  71. package/src/eth/builtin/internal/erc721-processor.ts +4 -1
  72. package/src/eth/builtin/internal/erc721-test-utils.ts +3 -3
  73. package/src/eth/builtin/internal/weth9-processor.ts +4 -1
  74. package/src/eth/builtin/internal/weth9-test-utils.ts +4 -4
  75. package/src/eth/codegen/file.ts +7 -3
  76. package/src/eth/context.ts +4 -0
  77. package/src/eth/index.ts +1 -1
  78. package/src/eth/provider.ts +10 -2
  79. package/src/solana/solana-context.ts +5 -1
  80. package/src/sui/context.ts +5 -1
  81. package/src/utils/token.ts +10 -4
@@ -105,8 +105,10 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
105
105
  .join('\n')}
106
106
  }
107
107
 
108
-
109
- export function get${contract.name}Contract(address: string, network: Networkish = 1): ${contract.name}ContractView {
108
+ export function get${contract.name}Contract(address: string, contextOrNetwork: BaseContext | Networkish): ${
109
+ contract.name
110
+ }ContractView {
111
+ const network = getNetworkFromCtxOrNetworkish(contextOrNetwork)
110
112
  let contract = getContractByABI("${contract.name}", address, network) as ${contract.name}ContractView
111
113
  if (!contract) {
112
114
  const rawContract = ${contract.name}__factory.connect(address, getProvider(network))
@@ -162,8 +164,10 @@ export class ${contract.name}ProcessorTemplate extends BaseProcessorTemplate<${c
162
164
  'ContractView',
163
165
  'DummyProvider',
164
166
  'TypedCallTrace',
167
+ 'getNetworkFromCtxOrNetworkish',
165
168
  // 'toBlockTag',
166
169
  ],
170
+ '@sentio/sdk': ['BaseContext'],
167
171
  '@sentio/protos': ['EthFetchConfig'],
168
172
  './common.js': ['PromiseOrValue'],
169
173
  './index.js': [`${contract.name}`, `${contract.name}__factory`],
@@ -226,7 +230,7 @@ function generateMockEventLogFunction(event: EventDeclaration, contractName: str
226
230
 
227
231
  return `
228
232
  export function mock${eventName}Log(contractAddress: string, event: ${eventName}EventObject): LogParams {
229
- const contract = get${contractName}Contract(contractAddress)
233
+ const contract = get${contractName}Contract(contractAddress, 1)
230
234
  const encodedLog = contract.rawContract.interface.encodeEventLog(
231
235
  '${getFullSignatureForEvent(event)}',
232
236
  [${eventArgs.join(', ')}]
@@ -50,6 +50,10 @@ export abstract class EthContext extends BaseContext {
50
50
 
51
51
  protected abstract getContractName(): string
52
52
 
53
+ getChainId(): string {
54
+ return this.chainId.toString()
55
+ }
56
+
53
57
  getMetaData(name: string, labels: Labels): RecordMetaData {
54
58
  if (this.log) {
55
59
  return {
package/src/eth/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { BaseProcessor } from './base-processor.js'
2
2
  export { GenericProcessor } from './generic-processor.js'
3
3
  export { BaseProcessorTemplate } from './base-processor-template.js'
4
- export { getProvider, DummyProvider } from './provider.js'
4
+ export { getProvider, DummyProvider, getNetworkFromCtxOrNetworkish } from './provider.js'
5
5
  export type { TypedCallTrace, Trace } from './trace.js'
6
6
  export * from './eth.js'
7
7
  export { BindOptions, AccountBindOptions } from './bind-options.js'
@@ -3,22 +3,30 @@ import { Networkish } from 'ethers/providers'
3
3
 
4
4
  import PQueue from 'p-queue'
5
5
  import { Endpoints } from '@sentio/runtime'
6
+ import { BaseContext } from '../core/index.js'
6
7
 
7
8
  export const DummyProvider = new JsonRpcProvider('', Network.from(1))
8
9
 
9
10
  const providers = new Map<string, JsonRpcProvider>()
10
11
 
11
- export function getProvider(networkish?: Networkish): Provider {
12
+ export function getNetworkFromCtxOrNetworkish(networkish?: BaseContext | Networkish) {
12
13
  if (!networkish) {
13
14
  networkish = 1
14
15
  }
16
+ if (networkish instanceof BaseContext) {
17
+ networkish = networkish.getChainId()
18
+ }
15
19
  if (typeof networkish === 'string') {
16
20
  const id = parseInt(networkish)
17
21
  if (!isNaN(id)) {
18
22
  networkish = 1
19
23
  }
20
24
  }
21
- const network = Network.from(networkish)
25
+ return Network.from(networkish)
26
+ }
27
+
28
+ export function getProvider(networkish?: Networkish): Provider {
29
+ const network = getNetworkFromCtxOrNetworkish(networkish)
22
30
  // TODO check if other key needed
23
31
 
24
32
  const address = Endpoints.INSTANCE.chainServer.get(network.chainId.toString())
@@ -14,6 +14,10 @@ export class SolanaContext extends BaseContext {
14
14
  this.blockNumber = slot
15
15
  }
16
16
 
17
+ getChainId(): string {
18
+ return this.network
19
+ }
20
+
17
21
  getMetaData(name: string, labels: Labels): RecordMetaData {
18
22
  return {
19
23
  address: this.address,
@@ -22,7 +26,7 @@ export class SolanaContext extends BaseContext {
22
26
  transactionIndex: 0,
23
27
  transactionHash: '', // TODO add
24
28
  logIndex: 0,
25
- chainId: this.network,
29
+ chainId: this.getChainId(),
26
30
  name: name,
27
31
  labels: normalizeLabels(labels),
28
32
  }
@@ -30,6 +30,10 @@ export class SuiContext extends BaseContext {
30
30
  }
31
31
  }
32
32
 
33
+ getChainId(): string {
34
+ return getChainId(this.network)
35
+ }
36
+
33
37
  getMetaData(name: string, labels: Labels): RecordMetaData {
34
38
  return {
35
39
  address: this.address,
@@ -38,7 +42,7 @@ export class SuiContext extends BaseContext {
38
42
  transactionIndex: 0,
39
43
  transactionHash: this.transaction?.certificate.transactionDigest || '', // TODO
40
44
  logIndex: 0,
41
- chainId: getChainId(this.network),
45
+ chainId: this.getChainId(),
42
46
  name: name,
43
47
  labels: normalizeLabels(labels),
44
48
  }
@@ -2,7 +2,9 @@ import { getERC20Contract } from '../eth/builtin/erc20.js'
2
2
  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
- import { decodeBytes32String } from 'ethers'
5
+ import { decodeBytes32String, Networkish } from 'ethers'
6
+ import { BaseContext } from '../core/index.js'
7
+ import { getNetworkFromCtxOrNetworkish } from '../eth/index.js'
6
8
 
7
9
  export interface TokenInfo {
8
10
  symbol: string
@@ -30,7 +32,11 @@ async function getTokenInfoPromise(
30
32
  }
31
33
  }
32
34
 
33
- export async function getERC20TokenInfo(tokenAddress: string, chainId = 1): Promise<TokenInfo> {
35
+ export async function getERC20TokenInfo(
36
+ tokenAddress: string,
37
+ contextOrNetworkish: BaseContext | Networkish
38
+ ): Promise<TokenInfo> {
39
+ const chainId = getNetworkFromCtxOrNetworkish(contextOrNetworkish).chainId.toString()
34
40
  const key = chainId + tokenAddress
35
41
  const res = TOKEN_INFOS.get(key)
36
42
  if (res) {
@@ -63,8 +69,8 @@ export async function getERC20TokenInfo(tokenAddress: string, chainId = 1): Prom
63
69
  export async function getER20NormalizedAmount(
64
70
  tokenAddress: string,
65
71
  amount: bigint,
66
- chainId: number
72
+ contextOrNetworkish: BaseContext | Networkish
67
73
  ): Promise<BigDecimal> {
68
- const tokenInfo = await getERC20TokenInfo(tokenAddress, chainId)
74
+ const tokenInfo = await getERC20TokenInfo(tokenAddress, contextOrNetworkish)
69
75
  return scaleDown(amount, tokenInfo.decimal)
70
76
  }