@sentio/sdk 2.58.7 → 2.59.0-rc.10

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 (102) hide show
  1. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  2. package/lib/aptos/aptos-plugin.js +11 -5
  3. package/lib/aptos/aptos-plugin.js.map +1 -1
  4. package/lib/aptos/aptos-processor.d.ts +1 -0
  5. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  6. package/lib/aptos/aptos-processor.js +1 -0
  7. package/lib/aptos/aptos-processor.js.map +1 -1
  8. package/lib/aptos/builtin/0x1.d.ts +485 -0
  9. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  10. package/lib/aptos/builtin/0x1.js +825 -1
  11. package/lib/aptos/builtin/0x1.js.map +1 -1
  12. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  13. package/lib/aptos/builtin/0x3.js +2 -1
  14. package/lib/aptos/builtin/0x3.js.map +1 -1
  15. package/lib/aptos/builtin/0x4.d.ts.map +1 -1
  16. package/lib/aptos/builtin/0x4.js +2 -1
  17. package/lib/aptos/builtin/0x4.js.map +1 -1
  18. package/lib/aptos/codegen/codegen.js +27 -5
  19. package/lib/aptos/codegen/codegen.js.map +1 -1
  20. package/lib/aptos/move-coder.js +1 -1
  21. package/lib/aptos/move-coder.js.map +1 -1
  22. package/lib/aptos/network.d.ts +2 -0
  23. package/lib/aptos/network.d.ts.map +1 -1
  24. package/lib/aptos/network.js +5 -1
  25. package/lib/aptos/network.js.map +1 -1
  26. package/lib/eth/base-processor.d.ts +3 -3
  27. package/lib/eth/base-processor.d.ts.map +1 -1
  28. package/lib/eth/base-processor.js +22 -8
  29. package/lib/eth/base-processor.js.map +1 -1
  30. package/lib/eth/bind-options.d.ts +6 -0
  31. package/lib/eth/bind-options.d.ts.map +1 -1
  32. package/lib/eth/bind-options.js +2 -0
  33. package/lib/eth/bind-options.js.map +1 -1
  34. package/lib/eth/eth-plugin.d.ts.map +1 -1
  35. package/lib/eth/eth-plugin.js +12 -5
  36. package/lib/eth/eth-plugin.js.map +1 -1
  37. package/lib/store/codegen.d.ts.map +1 -1
  38. package/lib/store/codegen.js +17 -0
  39. package/lib/store/codegen.js.map +1 -1
  40. package/lib/store/schema.d.ts.map +1 -1
  41. package/lib/store/schema.js +3 -1
  42. package/lib/store/schema.js.map +1 -1
  43. package/lib/store/types.d.ts +1 -1
  44. package/lib/store/types.d.ts.map +1 -1
  45. package/lib/sui/builtin/0x1.d.ts +4 -0
  46. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  47. package/lib/sui/builtin/0x1.js +1 -1
  48. package/lib/sui/builtin/0x1.js.map +1 -1
  49. package/lib/sui/builtin/0x2.d.ts +63 -0
  50. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  51. package/lib/sui/builtin/0x2.js +279 -1
  52. package/lib/sui/builtin/0x2.js.map +1 -1
  53. package/lib/sui/builtin/0x3.d.ts +41 -14
  54. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  55. package/lib/sui/builtin/0x3.js +128 -10
  56. package/lib/sui/builtin/0x3.js.map +1 -1
  57. package/lib/sui/sui-object-processor-template.js +1 -1
  58. package/lib/sui/sui-object-processor-template.js.map +1 -1
  59. package/lib/sui/sui-object-processor.d.ts +2 -0
  60. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  61. package/lib/sui/sui-object-processor.js +4 -0
  62. package/lib/sui/sui-object-processor.js.map +1 -1
  63. package/lib/sui/sui-plugin.d.ts.map +1 -1
  64. package/lib/sui/sui-plugin.js +9 -4
  65. package/lib/sui/sui-plugin.js.map +1 -1
  66. package/lib/sui/sui-processor.d.ts +1 -0
  67. package/lib/sui/sui-processor.d.ts.map +1 -1
  68. package/lib/sui/sui-processor.js +1 -0
  69. package/lib/sui/sui-processor.js.map +1 -1
  70. package/lib/utils/block.d.ts +2 -0
  71. package/lib/utils/block.d.ts.map +1 -1
  72. package/lib/utils/block.js +13 -0
  73. package/lib/utils/block.js.map +1 -1
  74. package/package.json +10 -9
  75. package/src/aptos/abis/0x1.json +9650 -5284
  76. package/src/aptos/abis/0x3.json +13 -13
  77. package/src/aptos/abis/0x4.json +42 -42
  78. package/src/aptos/aptos-plugin.ts +11 -5
  79. package/src/aptos/aptos-processor.ts +2 -0
  80. package/src/aptos/builtin/0x1.ts +1567 -67
  81. package/src/aptos/builtin/0x3.ts +3 -1
  82. package/src/aptos/builtin/0x4.ts +3 -1
  83. package/src/aptos/codegen/codegen.ts +33 -5
  84. package/src/aptos/move-coder.ts +1 -1
  85. package/src/aptos/network.ts +5 -1
  86. package/src/eth/base-processor.ts +23 -9
  87. package/src/eth/bind-options.ts +7 -0
  88. package/src/eth/eth-plugin.ts +22 -5
  89. package/src/store/codegen.ts +22 -0
  90. package/src/store/schema.ts +3 -1
  91. package/src/store/types.ts +1 -1
  92. package/src/sui/abis/0x1.json +8 -0
  93. package/src/sui/abis/0x2.json +437 -0
  94. package/src/sui/abis/0x3.json +116 -5
  95. package/src/sui/builtin/0x1.ts +6 -1
  96. package/src/sui/builtin/0x2.ts +413 -1
  97. package/src/sui/builtin/0x3.ts +211 -22
  98. package/src/sui/sui-object-processor-template.ts +1 -1
  99. package/src/sui/sui-object-processor.ts +6 -0
  100. package/src/sui/sui-plugin.ts +9 -4
  101. package/src/sui/sui-processor.ts +2 -0
  102. package/src/utils/block.ts +15 -0
@@ -26,9 +26,9 @@ class AptosNetworkCodegen extends BaseAptosCodegen {
26
26
  moduleGenerator: SharedNetworkCodegen<AptosNetwork, MoveModuleBytecode, Event | MoveResource>
27
27
  SYSTEM_PACKAGE = '@sentio/sdk/aptos'
28
28
 
29
- constructor(network: AptosNetwork) {
29
+ constructor(network: AptosNetwork, useViewJson = false) {
30
30
  const endpoint = getRpcEndpoint(network)
31
- super(endpoint)
31
+ super(endpoint, useViewJson)
32
32
  const generator = this
33
33
 
34
34
  this.moduleGenerator = new (class extends SharedNetworkCodegen<
@@ -54,6 +54,7 @@ class AptosNetworkCodegen extends BaseAptosCodegen {
54
54
  protected getGetDefaultCoder() {
55
55
  return `defaultMoveCoderForClient(client)`
56
56
  }
57
+
57
58
  generateModule(module: InternalMoveModule, allEventStructs: Map<string, InternalMoveStruct>) {
58
59
  return this.moduleGenerator.generateModule(module, allEventStructs)
59
60
  }
@@ -67,18 +68,44 @@ class AptosNetworkCodegen extends BaseAptosCodegen {
67
68
  MoveCoder, TypedEventInstance } from "@typemove/${this.PREFIX.toLowerCase()}"
68
69
 
69
70
  import { defaultMoveCoder, defaultMoveCoderForClient } from "${this.defaultCoderPackage()}"
70
- import { Aptos, Account as AptosAccount, MoveAddressType, PendingTransactionResponse, InputGenerateTransactionOptions, MoveStructId, InputViewFunctionData } from '@aptos-labs/ts-sdk'`
71
+ import { Aptos, Account as AptosAccount, MoveAddressType, PendingTransactionResponse, InputGenerateTransactionOptions, MoveStructId, InputViewFunctionData, InputViewFunctionJsonData } from '@aptos-labs/ts-sdk'`
71
72
  )
72
73
  }
74
+
73
75
  generateLoadAll(isSystem: boolean): string {
74
76
  return this.moduleGenerator.generateLoadAll(isSystem)
75
77
  }
76
78
  }
77
79
 
80
+ const ADDRESS_LENGTH = 64
81
+
82
+ class InitiaAptosNetworkCodegen extends AptosNetworkCodegen {
83
+ constructor(network: AptosNetwork) {
84
+ super(network, true)
85
+
86
+ const oldFetchModules = this.chainAdapter.fetchModules.bind(this.chainAdapter)
87
+ this.chainAdapter.fetchModules = async (address: string) => {
88
+ return oldFetchModules(this.padZero(address))
89
+ }
90
+ const oldFetchModule = this.chainAdapter.fetchModule.bind(this.chainAdapter)
91
+ this.chainAdapter.fetchModule = async (address: string, moduleName: string) => {
92
+ return oldFetchModule(this.padZero(address), moduleName)
93
+ }
94
+ }
95
+
96
+ private padZero(address: string): string {
97
+ if (address.startsWith('0x')) {
98
+ address = address.slice(2)
99
+ }
100
+ return '0x' + address.padStart(ADDRESS_LENGTH, '0')
101
+ }
102
+ }
103
+
78
104
  const MAINNET_CODEGEN = new AptosNetworkCodegen(AptosNetwork.MAIN_NET)
79
105
  const TESTNET_CODEGEN = new AptosNetworkCodegen(AptosNetwork.TEST_NET)
80
106
  const MOVEMENT_MAINNET_CODEGEN = new AptosNetworkCodegen(AptosNetwork.MOVEMENT_MAIN_NET)
81
107
  const MOVEMENT_TESTNET_CODEGEN = new AptosNetworkCodegen(AptosNetwork.MOVEMENT_TEST_NET)
108
+ const ECHELON_CODEGEN = new InitiaAptosNetworkCodegen(AptosNetwork.INITIA_ECHELON)
82
109
 
83
110
  class AptosCodegen {
84
111
  async generate(srcDir: string, outputDir: string, builtin = false): Promise<number> {
@@ -87,11 +114,12 @@ class AptosCodegen {
87
114
  ['', MAINNET_CODEGEN],
88
115
  ['testnet', TESTNET_CODEGEN],
89
116
  ['movement-mainnet', MOVEMENT_MAINNET_CODEGEN],
90
- ['movement-testnet', MOVEMENT_TESTNET_CODEGEN]
117
+ ['movement-testnet', MOVEMENT_TESTNET_CODEGEN],
118
+ ['initia-echelon', ECHELON_CODEGEN]
91
119
  ]
92
120
 
93
121
  for (const [network, gen] of generators) {
94
- const exclude = network ? [] : ['testnet', 'movement-mainnet', 'movement-testnet']
122
+ const exclude = network ? [] : ['testnet', 'movement-mainnet', 'movement-testnet', 'initia-echelon']
95
123
  numFiles += await recursiveCodegen(
96
124
  path.join(srcDir, network),
97
125
  path.join(outputDir, network),
@@ -9,7 +9,7 @@ export function defaultMoveCoder(network: AptosNetwork = AptosNetwork.MAIN_NET):
9
9
  let coder = CODERS.get(network)
10
10
  if (!coder) {
11
11
  const client = getClient(network)
12
- coder = new MoveCoder(getClient(network))
12
+ coder = new MoveCoder(getClient(network), network == AptosNetwork.INITIA_ECHELON)
13
13
  CODERS.set(network, coder)
14
14
  URL_CODERS.set(client.config.fullnode || '', coder)
15
15
  }
@@ -11,7 +11,8 @@ export const AptosNetwork = <const>{
11
11
  TEST_NET: AptosChainId.APTOS_TESTNET,
12
12
 
13
13
  MOVEMENT_MAIN_NET: AptosChainId.APTOS_MOVEMENT_MAINNET,
14
- MOVEMENT_TEST_NET: AptosChainId.APTOS_MOVEMENT_TESTNET
14
+ MOVEMENT_TEST_NET: AptosChainId.APTOS_MOVEMENT_TESTNET,
15
+ INITIA_ECHELON: AptosChainId.INITIA_ECHELON
15
16
  }
16
17
 
17
18
  export const MovementNetwork = <const>{
@@ -24,6 +25,7 @@ export class AptosBindOptions {
24
25
  network?: AptosNetwork = AptosNetwork.MAIN_NET
25
26
  client?: Aptos
26
27
  startVersion?: bigint | number
28
+ endVersion?: bigint | number
27
29
  baseLabels?: Labels
28
30
  }
29
31
 
@@ -37,6 +39,8 @@ export function getRpcEndpoint(network: AptosNetwork): string {
37
39
  return 'https://mainnet.movementnetwork.xyz/v1'
38
40
  case AptosNetwork.MOVEMENT_TEST_NET:
39
41
  return 'https://aptos.testnet.bardock.movementlabs.xyz/v1'
42
+ case AptosNetwork.INITIA_ECHELON:
43
+ return 'https://rpc.sentio.xyz/initia-aptos/v1'
40
44
  }
41
45
  }
42
46
 
@@ -13,7 +13,7 @@ import {
13
13
  PreprocessResult,
14
14
  ProcessResult
15
15
  } from '@sentio/protos'
16
- import { BindOptions } from './bind-options.js'
16
+ import { BindOptions, TimeOrBlock } from './bind-options.js'
17
17
  import { PromiseOrVoid } from '../core/promises.js'
18
18
  import { ServerError, Status } from 'nice-grpc'
19
19
  import {
@@ -75,8 +75,8 @@ class BindInternalOptions {
75
75
  address: string
76
76
  network: EthChainId
77
77
  name: string
78
- startBlock: bigint
79
- endBlock?: bigint
78
+ start: TimeOrBlock
79
+ end?: TimeOrBlock
80
80
  baseLabels?: { [key: string]: string }
81
81
  }
82
82
 
@@ -101,13 +101,20 @@ export class GlobalProcessor {
101
101
  address: ALL_ADDRESS,
102
102
  name: config.name || 'Global',
103
103
  network: config.network || EthChainId.ETHEREUM,
104
- startBlock: 0n
104
+ start: config.start || {
105
+ block: 0
106
+ },
107
+ end: config.end
105
108
  }
106
109
  if (config.startBlock) {
107
- this.config.startBlock = BigInt(config.startBlock)
110
+ this.config.start = {
111
+ block: config.startBlock
112
+ }
108
113
  }
109
114
  if (config.endBlock) {
110
- this.config.endBlock = BigInt(config.endBlock)
115
+ this.config.end = {
116
+ block: config.endBlock
117
+ }
111
118
  }
112
119
 
113
120
  return proxyProcessor(this)
@@ -390,14 +397,21 @@ export abstract class BaseProcessor<
390
397
  address: validateAndNormalizeAddress(config.address),
391
398
  name: config.name || '',
392
399
  network: config.network || EthChainId.ETHEREUM,
393
- startBlock: 0n,
400
+ start: config.start || {
401
+ block: 0
402
+ },
403
+ end: config.end,
394
404
  baseLabels: config.baseLabels
395
405
  }
396
406
  if (config.startBlock) {
397
- this.config.startBlock = BigInt(config.startBlock)
407
+ this.config.start = {
408
+ block: config.startBlock
409
+ }
398
410
  }
399
411
  if (config.endBlock) {
400
- this.config.endBlock = BigInt(config.endBlock)
412
+ this.config.end = {
413
+ block: config.endBlock
414
+ }
401
415
  }
402
416
 
403
417
  return proxyProcessor(this)
@@ -7,11 +7,18 @@ export class BindOptions {
7
7
  network?: EthChainId = EthChainId.ETHEREUM
8
8
  // Optional, override default contract name
9
9
  name?: string
10
+ start?: TimeOrBlock
11
+ end?: TimeOrBlock
10
12
  startBlock?: bigint | number
11
13
  endBlock?: bigint | number
12
14
  baseLabels?: { [key: string]: string }
13
15
  }
14
16
 
17
+ export interface TimeOrBlock {
18
+ block?: bigint | number
19
+ time?: Date
20
+ }
21
+
15
22
  export function getOptionsSignature(opts: BindOptions): string {
16
23
  const sig = [opts.address]
17
24
  if (opts.network) {
@@ -1,4 +1,12 @@
1
- import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR, GLOBAL_CONFIG } from '@sentio/runtime'
1
+ import {
2
+ errorString,
3
+ mergeProcessResults,
4
+ Plugin,
5
+ PluginManager,
6
+ USER_PROCESSOR,
7
+ GLOBAL_CONFIG,
8
+ getProvider
9
+ } from '@sentio/runtime'
2
10
  import {
3
11
  AccountConfig,
4
12
  ContractConfig,
@@ -26,6 +34,7 @@ import { validateAndNormalizeAddress } from './eth.js'
26
34
  import { EthChainId } from '@sentio/chain'
27
35
  import { EthContext } from './context.js'
28
36
  import { TemplateInstanceState } from '../core/template.js'
37
+ import { timeOrBlockToBlockNumber } from '@sentio/sdk/utils'
29
38
 
30
39
  interface Handlers {
31
40
  eventHandlers: ((event: Data_EthLog, preparedData?: PreparedData) => Promise<ProcessResult>)[]
@@ -79,6 +88,10 @@ export class EthPlugin extends Plugin {
79
88
  const chainId = processor.getChainId()
80
89
  // this.processorsByChainId.set(chainId, processor)
81
90
 
91
+ const provider = getProvider(chainId)
92
+ const startBlock = await timeOrBlockToBlockNumber(provider, processor.config.start)
93
+ const endBlock = processor.config.end ? await timeOrBlockToBlockNumber(provider, processor.config.end) : undefined
94
+
82
95
  const contractConfig = ContractConfig.fromPartial({
83
96
  processorType: USER_PROCESSOR,
84
97
  contract: {
@@ -87,8 +100,8 @@ export class EthPlugin extends Plugin {
87
100
  address: validateAndNormalizeAddress(processor.config.address),
88
101
  abi: ''
89
102
  },
90
- startBlock: processor.config.startBlock,
91
- endBlock: processor.config.endBlock
103
+ startBlock,
104
+ endBlock
92
105
  })
93
106
 
94
107
  // Step 1. Prepare all the block handlers
@@ -167,6 +180,10 @@ export class EthPlugin extends Plugin {
167
180
  for (const processor of GlobalProcessorState.INSTANCE.getValues()) {
168
181
  const chainId = processor.getChainId()
169
182
 
183
+ const provider = getProvider(chainId)
184
+ const startBlock = await timeOrBlockToBlockNumber(provider, processor.config.start)
185
+ const endBlock = processor.config.end ? await timeOrBlockToBlockNumber(provider, processor.config.end) : undefined
186
+
170
187
  const contractConfig = ContractConfig.fromPartial({
171
188
  processorType: USER_PROCESSOR,
172
189
  contract: {
@@ -175,8 +192,8 @@ export class EthPlugin extends Plugin {
175
192
  address: processor.config.address, // can only be *
176
193
  abi: ''
177
194
  },
178
- startBlock: processor.config.startBlock,
179
- endBlock: processor.config.endBlock
195
+ startBlock,
196
+ endBlock
180
197
  })
181
198
 
182
199
  for (const blockHandler of processor.blockHandlers) {
@@ -48,6 +48,7 @@ interface Class {
48
48
  annotations: string[]
49
49
  parent?: string
50
50
  interfaces: string[]
51
+ timeseries?: boolean
51
52
  }
52
53
 
53
54
  interface Interface {
@@ -154,6 +155,18 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
154
155
  }
155
156
 
156
157
  if (t instanceof GraphQLObjectType) {
158
+ if (isTimeseries(t)) {
159
+ // check id is int8
160
+ const idField = t.getFields()['id']
161
+ if (!idField || !isNonNullType(idField.type) || idField.type.toString() !== 'Int8!') {
162
+ throw new Error(`Timeseries entity ${t.name} must have an id field of type Int8!`)
163
+ }
164
+ // check if it has a timestamp field
165
+ const timestampField = t.getFields()['timestamp']
166
+ if (!timestampField || !isNonNullType(timestampField.type) || timestampField.type.toString() !== 'Timestamp!') {
167
+ throw new Error(`Timeseries entity ${t.name} must have a timestamp field of type Timestamp!`)
168
+ }
169
+ }
157
170
  if (isEntity(t)) {
158
171
  const fields: Field[] = []
159
172
  const methods: Method[] = []
@@ -228,6 +241,7 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
228
241
  }
229
242
  classes.push({
230
243
  name: t.name,
244
+ timeseries: isTimeseries(t),
231
245
  fields,
232
246
  methods,
233
247
  annotations: [`@Entity("${t.name}")`],
@@ -367,6 +381,14 @@ function isEntity(t: GraphQLObjectType) {
367
381
  return t.astNode?.directives?.some((d) => d.name.value == 'entity')
368
382
  }
369
383
 
384
+ function isTimeseries(t: GraphQLObjectType) {
385
+ return t.astNode?.directives?.some(
386
+ (d) =>
387
+ d.name.value == 'entity' &&
388
+ d.arguments?.some((a) => a.name.value == 'timeseries' && a.value.kind == 'BooleanValue' && a.value.value == true)
389
+ )
390
+ }
391
+
370
392
  function isDerived(f: GraphQLField<any, any>) {
371
393
  return f.astNode?.directives?.some((d) => d.name.value == 'derivedFrom')
372
394
  }
@@ -6,7 +6,7 @@ const customScalars = ['BigInt', 'BigDecimal', 'Timestamp', 'JSON', 'Bytes', 'ID
6
6
 
7
7
  const baseSchema = buildASTSchema(
8
8
  parse(`
9
- directive @entity(immutable: Boolean! = false, sparse: Boolean! = false) on OBJECT
9
+ directive @entity(immutable: Boolean! = false, sparse: Boolean! = false, timeseries: Boolean! = false) on OBJECT
10
10
  directive @query on INTERFACE
11
11
  directive @derivedFrom(field: String!) on FIELD_DEFINITION
12
12
  directive @unique on FIELD_DEFINITION
@@ -16,6 +16,8 @@ const baseSchema = buildASTSchema(
16
16
  directive @byteWeight(value: Float!) on FIELD_DEFINITION
17
17
  directive @variant on OBJECT # legacy
18
18
  directive @jsonField on OBJECT # legacy
19
+ directive @aggregation(intervals: [String!]! = ["hour"], source: String!) on OBJECT
20
+ directive @aggregate(fn: String!, arg: String, cumulative: Boolean = false) on FIELD_DEFINITION
19
21
  ${customScalars.map((name) => 'scalar ' + name).join('\n')}
20
22
  `)
21
23
  )
@@ -14,7 +14,7 @@ export type Bytes = Uint8Array
14
14
  export type BigInt = bigint
15
15
 
16
16
  export abstract class AbstractEntity {
17
- abstract id: ID
17
+ abstract id: ID | Int8
18
18
  private readonly _data: RichStruct
19
19
 
20
20
  toJSON() {
@@ -690,6 +690,14 @@
690
690
  }
691
691
  }
692
692
  },
693
+ "bool": {
694
+ "fileFormatVersion": 6,
695
+ "address": "0x1",
696
+ "name": "bool",
697
+ "friends": [],
698
+ "structs": {},
699
+ "exposedFunctions": {}
700
+ },
693
701
  "debug": {
694
702
  "fileFormatVersion": 6,
695
703
  "address": "0x1",