@sentio/sdk 2.21.2 → 2.21.3-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 (93) hide show
  1. package/lib/aptos/aptos-chain-adapter.d.ts +0 -1
  2. package/lib/aptos/aptos-chain-adapter.d.ts.map +1 -1
  3. package/lib/aptos/aptos-chain-adapter.js +0 -4
  4. package/lib/aptos/aptos-chain-adapter.js.map +1 -1
  5. package/lib/aptos/aptos-plugin.d.ts.map +1 -1
  6. package/lib/aptos/aptos-plugin.js +2 -3
  7. package/lib/aptos/aptos-plugin.js.map +1 -1
  8. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  9. package/lib/aptos/aptos-processor.js +3 -3
  10. package/lib/aptos/aptos-processor.js.map +1 -1
  11. package/lib/aptos/ext/coin.js +3 -3
  12. package/lib/aptos/ext/coin.js.map +1 -1
  13. package/lib/aptos/utils.d.ts +1 -2
  14. package/lib/aptos/utils.d.ts.map +1 -1
  15. package/lib/aptos/utils.js +14 -12
  16. package/lib/aptos/utils.js.map +1 -1
  17. package/lib/eth/codegen/functions-handler.js +1 -1
  18. package/lib/eth/codegen/functions-handler.js.map +1 -1
  19. package/lib/eth/provider.js +7 -0
  20. package/lib/eth/provider.js.map +1 -1
  21. package/lib/move/abstract-codegen.d.ts +2 -3
  22. package/lib/move/abstract-codegen.d.ts.map +1 -1
  23. package/lib/move/abstract-codegen.js +45 -45
  24. package/lib/move/abstract-codegen.js.map +1 -1
  25. package/lib/move/abstract-move-coder.js +1 -1
  26. package/lib/move/abstract-move-coder.js.map +1 -1
  27. package/lib/move/chain-adapter.d.ts +1 -1
  28. package/lib/move/chain-adapter.d.ts.map +1 -1
  29. package/lib/move/chain-adapter.js +4 -0
  30. package/lib/move/chain-adapter.js.map +1 -1
  31. package/lib/move/types.d.ts.map +1 -1
  32. package/lib/move/types.js +6 -1
  33. package/lib/move/types.js.map +1 -1
  34. package/lib/move/utils.d.ts +4 -0
  35. package/lib/move/utils.d.ts.map +1 -1
  36. package/lib/move/utils.js +28 -2
  37. package/lib/move/utils.js.map +1 -1
  38. package/lib/move/utils.test.d.ts +2 -0
  39. package/lib/move/utils.test.d.ts.map +1 -0
  40. package/lib/move/utils.test.js.map +1 -0
  41. package/lib/sui/builtin/0x3.d.ts +4 -4
  42. package/lib/sui/builtin/0x3.js +2 -2
  43. package/lib/sui/codegen/codegen.js +2 -2
  44. package/lib/sui/codegen/codegen.js.map +1 -1
  45. package/lib/sui/ext/coin.js +3 -3
  46. package/lib/sui/ext/coin.js.map +1 -1
  47. package/lib/sui/index.d.ts +0 -1
  48. package/lib/sui/index.d.ts.map +1 -1
  49. package/lib/sui/index.js +1 -1
  50. package/lib/sui/index.js.map +1 -1
  51. package/lib/sui/sui-chain-adapter.d.ts +0 -1
  52. package/lib/sui/sui-chain-adapter.d.ts.map +1 -1
  53. package/lib/sui/sui-chain-adapter.js +0 -4
  54. package/lib/sui/sui-chain-adapter.js.map +1 -1
  55. package/lib/sui/sui-plugin.d.ts.map +1 -1
  56. package/lib/sui/sui-plugin.js +2 -3
  57. package/lib/sui/sui-plugin.js.map +1 -1
  58. package/lib/sui/sui-processor.d.ts.map +1 -1
  59. package/lib/sui/sui-processor.js +4 -14
  60. package/lib/sui/sui-processor.js.map +1 -1
  61. package/lib/sui/utils.d.ts +1 -3
  62. package/lib/sui/utils.d.ts.map +1 -1
  63. package/lib/sui/utils.js +24 -26
  64. package/lib/sui/utils.js.map +1 -1
  65. package/lib/testing/aptos-facet.d.ts.map +1 -1
  66. package/lib/testing/aptos-facet.js +4 -2
  67. package/lib/testing/aptos-facet.js.map +1 -1
  68. package/lib/testing/sui-facet.d.ts.map +1 -1
  69. package/lib/testing/sui-facet.js +5 -4
  70. package/lib/testing/sui-facet.js.map +1 -1
  71. package/package.json +4 -5
  72. package/src/aptos/aptos-chain-adapter.ts +3 -4
  73. package/src/aptos/aptos-plugin.ts +2 -3
  74. package/src/aptos/aptos-processor.ts +11 -3
  75. package/src/aptos/ext/coin.ts +3 -3
  76. package/src/aptos/utils.ts +13 -13
  77. package/src/eth/codegen/functions-handler.ts +1 -1
  78. package/src/eth/provider.ts +7 -0
  79. package/src/move/abstract-codegen.ts +47 -49
  80. package/src/move/abstract-move-coder.ts +1 -1
  81. package/src/move/chain-adapter.ts +5 -1
  82. package/src/move/types.ts +6 -1
  83. package/src/move/utils.ts +36 -2
  84. package/src/sui/builtin/0x3.ts +6 -6
  85. package/src/sui/codegen/codegen.ts +2 -2
  86. package/src/sui/ext/coin.ts +3 -3
  87. package/src/sui/index.ts +1 -1
  88. package/src/sui/sui-chain-adapter.ts +3 -4
  89. package/src/sui/sui-plugin.ts +2 -3
  90. package/src/sui/sui-processor.ts +7 -15
  91. package/src/sui/utils.ts +24 -32
  92. package/src/testing/aptos-facet.ts +6 -2
  93. package/src/testing/sui-facet.ts +7 -4
@@ -18,7 +18,15 @@ import {
18
18
  Data_AptCall,
19
19
  } from '@sentio/protos'
20
20
  import { ServerError, Status } from 'nice-grpc'
21
- import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'
21
+ import {
22
+ accountAddressString,
23
+ accountTypeString,
24
+ CallHandler,
25
+ EventFilter,
26
+ EventHandler,
27
+ FunctionNameAndCallFilter,
28
+ parseMoveType,
29
+ } from '../move/index.js'
22
30
  import { Labels, PromiseOrVoid } from '../core/index.js'
23
31
 
24
32
  const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
@@ -77,7 +85,7 @@ export class AptosBaseProcessor {
77
85
  // const moduleName = this.moduleName
78
86
 
79
87
  const processor = this
80
- const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))
88
+ const allEventType = new Set(_filters.map((f) => accountTypeString(processor.config.address) + '::' + f.type))
81
89
 
82
90
  this.eventHandlers.push({
83
91
  handler: async function (data) {
@@ -315,7 +323,7 @@ function configure(options: AptosBindOptions): IndexConfigure {
315
323
 
316
324
  return {
317
325
  startVersion: startVersion,
318
- address: options.address,
326
+ address: options.address === '*' ? '*' : accountAddressString(options.address),
319
327
  network: options.network || AptosNetwork.MAIN_NET,
320
328
  baseLabels: options.baseLabels,
321
329
  }
@@ -1,7 +1,7 @@
1
1
  import { getPriceByType } from '@sentio/sdk/utils'
2
2
  import fetch from 'node-fetch'
3
- import { validateAndNormalizeAddress } from '../utils.js'
4
- import { SPLITTER } from '../../move/index.js'
3
+ // import { validateAndNormalizeAddress } from '../utils.js'
4
+ import { accountTypeString, SPLITTER } from '../../move/index.js'
5
5
  import { AptosChainId } from '@sentio/chain'
6
6
  import { SimpleCoinInfo } from '../../move/ext/move-dex.js'
7
7
 
@@ -43,7 +43,7 @@ export function whitelistCoins() {
43
43
 
44
44
  export function whiteListed(coin: string): boolean {
45
45
  const [addr, module, type] = coin.split(SPLITTER)
46
- const normalized = [validateAndNormalizeAddress(addr), module, type].join(SPLITTER)
46
+ const normalized = [accountTypeString(addr), module, type].join(SPLITTER)
47
47
  return WHITELISTED_COINS.has(normalized)
48
48
  }
49
49
 
@@ -1,15 +1,15 @@
1
- import { HexString, TxnBuilderTypes } from 'aptos-sdk'
1
+ // import { HexString, TxnBuilderTypes } from 'aptos-sdk'
2
2
  // import { isFrameworkAccount } from '../move/index.js'
3
3
 
4
- export function isValidAptosAddress(value: string): boolean {
5
- return TxnBuilderTypes.AccountAddress.isValid(value)
6
- }
7
-
8
- export function validateAndNormalizeAddress(address: string): string {
9
- const hex = TxnBuilderTypes.AccountAddress.fromHex(address).toHexString()
10
- // if (isFrameworkAccount(address)) {
11
- // return HexString.ensure(hex).toShortString()
12
- // }
13
- // return hex.toString()
14
- return HexString.ensure(hex).toShortString()
15
- }
4
+ // export function isValidAptosAddress(value: string): boolean {
5
+ // return TxnBuilderTypes.AccountAddress.isValid(value)
6
+ // }
7
+ //
8
+ // export function validateAndNormalizeAddress(address: string): string {
9
+ // const hex = TxnBuilderTypes.AccountAddress.fromHex(address).toHexString()
10
+ // // if (isFrameworkAccount(address)) {
11
+ // // return HexString.ensure(hex).toShortString()
12
+ // // }
13
+ // // return hex.toString()
14
+ // return HexString.ensure(hex).toShortString()
15
+ // }
@@ -5,7 +5,7 @@ import {
5
5
  import sha3 from 'js-sha3'
6
6
  import { FunctionDeclaration, getSignatureForFn } from 'typechain'
7
7
  import { getFullSignatureAsSymbolForFunction } from './types.js'
8
- import { upperFirst } from 'lodash-es'
8
+ import { upperFirst } from '../../move/index.js'
9
9
 
10
10
  export function generateCallHandlers(fns: FunctionDeclaration[], contractName: string): string {
11
11
  if (fns.length === 1) {
@@ -104,6 +104,13 @@ class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
104
104
  }
105
105
  }, 1000)
106
106
  }
107
+ if (e.code === 'CALL_EXCEPTION' && !e.data) {
108
+ setTimeout(() => {
109
+ if (this.#performCache.get(tag) === perform) {
110
+ this.#performCache.delete(tag)
111
+ }
112
+ }, 1000)
113
+ }
107
114
  })
108
115
  this.#performCache.set(tag, perform)
109
116
  // For non latest block call, we cache permanently, otherwise we cache for one minute
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InternalMoveFunction,
3
- InternalMoveFunctionVisibility,
3
+ // InternalMoveFunctionVisibility,
4
4
  InternalMoveModule,
5
5
  InternalMoveStruct,
6
6
  } from './internal-models.js'
@@ -9,8 +9,8 @@ import fs from 'fs'
9
9
  import { AccountModulesImportInfo, AccountRegister } from './account.js'
10
10
  import chalk from 'chalk'
11
11
  import { format } from 'prettier'
12
- import { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER, VECTOR_STR } from './utils.js'
13
- import { camelCase, upperFirst } from 'lodash-es'
12
+ import { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER, upperFirst, VECTOR_STR } from './utils.js'
13
+ import { camel } from 'radash'
14
14
  import { TypeDescriptor } from './types.js'
15
15
  import { ChainAdapter } from './chain-adapter.js'
16
16
 
@@ -161,11 +161,11 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
161
161
  generateModule(module: InternalMoveModule, allEventStructs: Map<string, InternalMoveStruct>, network: NetworkType) {
162
162
  const qname = moduleQname(module)
163
163
  const functions = this.GENERATE_ON_ENTRY
164
- ? module.exposedFunctions.map((f) => this.generateOnEntryFunctions(module, f)).filter((s) => s !== '')
165
- : []
166
- const clientFunctions = this.GENERATE_CLIENT
167
- ? module.exposedFunctions.map((f) => this.generateClientFunctions(module, f)).filter((s) => s !== '')
164
+ ? module.exposedFunctions.map((f) => this.generateForEntryFunctions(module, f)).filter((s) => s !== '')
168
165
  : []
166
+ // const clientFunctions = this.GENERATE_CLIENT
167
+ // ? module.exposedFunctions.map((f) => this.generateClientFunctions(module, f)).filter((s) => s !== '')
168
+ // : []
169
169
  const eventStructs = new Map<string, InternalMoveStruct>()
170
170
  for (const [type, struct] of allEventStructs.entries()) {
171
171
  if (type.startsWith(qname + SPLITTER)) {
@@ -175,22 +175,21 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
175
175
 
176
176
  const eventTypes = new Set(eventStructs.keys())
177
177
  const events = Array.from(eventStructs.values())
178
- .map((e) => this.generateOnEvents(module, e))
178
+ .map((e) => this.generateForEvents(module, e))
179
179
  .filter((s) => s !== '')
180
180
  const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes))
181
181
  const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f))
182
182
 
183
183
  const moduleName = normalizeToJSName(module.name)
184
184
  let processor = ''
185
- let client = ''
186
-
187
- if (clientFunctions.length > 0) {
188
- client = `
189
- export class ${moduleName}_client extends ModuleClient {
190
- ${clientFunctions.join('\n')}
191
- }
192
- `
193
- }
185
+ // let client = ''
186
+ // if (clientFunctions.length > 0) {
187
+ // client = `
188
+ // export class ${moduleName}_client extends ModuleClient {
189
+ // ${clientFunctions.join('\n')}
190
+ // }
191
+ // `
192
+ // }
194
193
 
195
194
  if (functions.length > 0 || events.length > 0) {
196
195
  processor = `export class ${moduleName} extends ${this.PREFIX}BaseProcessor {
@@ -215,7 +214,6 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
215
214
  }
216
215
 
217
216
  return `
218
- ${client}
219
217
 
220
218
  ${processor}
221
219
 
@@ -323,7 +321,7 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
323
321
  return this.generateTypeForDescriptor(param, module.address) + (this.PAYLOAD_OPTIONAL ? ' | undefined' : '')
324
322
  })
325
323
 
326
- const camelFuncName = upperFirst(camelCase(func.name))
324
+ const camelFuncName = upperFirst(camel(func.name))
327
325
 
328
326
  const genericString = this.generateFunctionTypeParameters(func)
329
327
  return `
@@ -335,34 +333,34 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
335
333
  `
336
334
  }
337
335
 
338
- generateClientFunctions(module: InternalMoveModule, func: InternalMoveFunction) {
339
- if (func.visibility === InternalMoveFunctionVisibility.PRIVATE) {
340
- return ''
341
- }
342
- if (func.isEntry) {
343
- return ''
344
- }
345
- // const moduleName = normalizeToJSName(module.name)
346
- const funcName = camelCase(func.name)
347
- const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
348
- return this.generateTypeForDescriptor(param, module.address)
349
- })
350
- const genericString = this.generateFunctionTypeParameters(func)
351
-
352
- const returns = func.return.map((param) => {
353
- return this.generateTypeForDescriptor(param, module.address)
354
- })
355
-
356
- const source = `
357
- ${funcName}${genericString}(type_arguments: [${func.typeParams
358
- .map((_) => 'string')
359
- .join(', ')}], args: [${fields.join(',')}], version?: bigint): Promise<[${returns.join(',')}]> {
360
- return this.viewDecoded('${module.address}::${module.name}::${func.name}', type_arguments, args, version) as any
361
- }`
362
- return source
363
- }
364
-
365
- generateOnEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction) {
336
+ // generateClientFunctions(module: InternalMoveModule, func: InternalMoveFunction) {
337
+ // if (func.visibility === InternalMoveFunctionVisibility.PRIVATE) {
338
+ // return ''
339
+ // }
340
+ // if (func.isEntry) {
341
+ // return ''
342
+ // }
343
+ // // const moduleName = normalizeToJSName(module.name)
344
+ // const funcName = camel(func.name)
345
+ // const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
346
+ // return this.generateTypeForDescriptor(param, module.address)
347
+ // })
348
+ // const genericString = this.generateFunctionTypeParameters(func)
349
+ //
350
+ // const returns = func.return.map((param) => {
351
+ // return this.generateTypeForDescriptor(param, module.address)
352
+ // })
353
+ //
354
+ // const source = `
355
+ // ${funcName}${genericString}(type_arguments: [${func.typeParams
356
+ // .map((_) => 'string')
357
+ // .join(', ')}], args: [${fields.join(',')}], version?: bigint): Promise<[${returns.join(',')}]> {
358
+ // return this.viewDecoded('${module.address}::${module.name}::${func.name}', type_arguments, args, version) as any
359
+ // }`
360
+ // return source
361
+ // }
362
+
363
+ generateForEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction) {
366
364
  if (!func.isEntry) {
367
365
  return ''
368
366
  }
@@ -370,7 +368,7 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
370
368
  // const genericString = generateFunctionTypeParameters(func)
371
369
  const moduleName = normalizeToJSName(module.name)
372
370
 
373
- const camelFuncName = upperFirst(camelCase(func.name))
371
+ const camelFuncName = upperFirst(camel(func.name))
374
372
  const source = `
375
373
  onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, fetchConfig?: Partial<MoveFetchConfig>): ${moduleName} {
376
374
  this.onEntryFunctionCall(func, {
@@ -384,7 +382,7 @@ export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
384
382
  return source
385
383
  }
386
384
 
387
- generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
385
+ generateForEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
388
386
  // for struct that has drop + store
389
387
  // if (!isEvent(struct, module)) {
390
388
  // return ''
@@ -16,7 +16,7 @@ export abstract class AbstractMoveCoder<Network, ModuleType, StructType> {
16
16
  }
17
17
 
18
18
  contains(account: string, name: string) {
19
- return this.moduleMapping.has(account + '::' + name)
19
+ return this.moduleMapping.has(moduleQname({ address: account, name }))
20
20
  }
21
21
 
22
22
  abstract load(module: ModuleType): InternalMoveModule
@@ -1,5 +1,6 @@
1
1
  import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'
2
2
  import { TypeDescriptor } from './types.js'
3
+ import { accountAddressString } from './utils.js'
3
4
 
4
5
  export abstract class ChainAdapter<NetworkType, ModuleType, StructType> {
5
6
  abstract fetchModule(account: string, module: string, network: NetworkType): Promise<ModuleType>
@@ -16,5 +17,8 @@ export abstract class ChainAdapter<NetworkType, ModuleType, StructType> {
16
17
 
17
18
  abstract getType(base: StructType): string
18
19
  abstract getData<T>(base: StructType): any
19
- abstract validateAndNormalizeAddress(address: string): string
20
+
21
+ validateAndNormalizeAddress(address: string): string {
22
+ return accountAddressString(address)
23
+ }
20
24
  }
package/src/move/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SPLITTER, VECTOR_STR } from './utils.js'
1
+ import { accountTypeString, SPLITTER, VECTOR_STR } from './utils.js'
2
2
 
3
3
  export type DecodedStruct<B, T> = B & {
4
4
  /**
@@ -174,6 +174,11 @@ function adjustType(type: TypeDescriptor) {
174
174
  type.mutable = true
175
175
  type.qname = type.qname.slice(3)
176
176
  }
177
+ const parts = type.qname.split(SPLITTER)
178
+ if (parts.length > 1) {
179
+ const [account, module, name] = parts
180
+ type.qname = [accountTypeString(account), module, name].join(SPLITTER)
181
+ }
177
182
  }
178
183
 
179
184
  export const ANY_TYPE = new TypeDescriptor<any>('any')
package/src/move/utils.ts CHANGED
@@ -12,6 +12,36 @@ export function isFrameworkAccount(account: string) {
12
12
  return n >= 0 && n < 16
13
13
  }
14
14
 
15
+ // strip any lead 0
16
+ export function accountTypeString(account: string): string {
17
+ const withoutPrefix = account.toLowerCase().replace(/^(0x)/, '')
18
+ return '0x' + withoutPrefix.replace(/^0*/, '')
19
+ }
20
+
21
+ const MOVE_ADDRESS_LENGTH = 32
22
+
23
+ function isHex(value: string): boolean {
24
+ return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)
25
+ }
26
+
27
+ function getHexByteLength(value: string): number {
28
+ return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2
29
+ }
30
+
31
+ export function isValidMoveAddress(value: string): boolean {
32
+ return isHex(value) && getHexByteLength(value) <= MOVE_ADDRESS_LENGTH
33
+ }
34
+
35
+ // Get full address with 32 bytes
36
+ export function accountAddressString(account: string): string {
37
+ if (!isValidMoveAddress(account)) {
38
+ throw Error('Not valid move address')
39
+ }
40
+
41
+ const address = account.toLowerCase().replace(/^(0x)/, '')
42
+ return `0x${address.padStart(MOVE_ADDRESS_LENGTH * 2, '0')}`
43
+ }
44
+
15
45
  const KEYWORDS = new Set(['package', 'namespace', 'volatile', 'object', 'string', 'number', 'bigint', 'any'])
16
46
 
17
47
  export function normalizeToJSName(name: string) {
@@ -27,9 +57,13 @@ export function moduleQnameForType(type: string): [string, string] {
27
57
  }
28
58
 
29
59
  export function moduleQname(module: { address: string; name: string }): string {
30
- return module.address.toLowerCase() + SPLITTER + module.name
60
+ return accountTypeString(module.address) + SPLITTER + module.name
31
61
  }
32
62
 
33
63
  export function structQname(module: InternalMoveModule, struct: InternalMoveStruct): string {
34
- return [module.address, module.name, struct.name].join(SPLITTER)
64
+ return [accountTypeString(module.address), module.name, struct.name].join(SPLITTER)
65
+ }
66
+
67
+ export function upperFirst(str: string): string {
68
+ return str.charAt(0).toUpperCase() + str.slice(1)
35
69
  }
@@ -677,9 +677,9 @@ export class sui_system extends SuiBaseProcessor {
677
677
  return this;
678
678
  }
679
679
 
680
- onEntryUpdateCandidateValidatorP2PAddress(
680
+ onEntryUpdateCandidateValidatorP2pAddress(
681
681
  func: (
682
- call: sui_system.UpdateCandidateValidatorP2PAddressPayload,
682
+ call: sui_system.UpdateCandidateValidatorP2pAddressPayload,
683
683
  ctx: SuiContext
684
684
  ) => void,
685
685
  filter?: CallFilter,
@@ -867,9 +867,9 @@ export class sui_system extends SuiBaseProcessor {
867
867
  return this;
868
868
  }
869
869
 
870
- onEntryUpdateValidatorNextEpochP2PAddress(
870
+ onEntryUpdateValidatorNextEpochP2pAddress(
871
871
  func: (
872
- call: sui_system.UpdateValidatorNextEpochP2PAddressPayload,
872
+ call: sui_system.UpdateValidatorNextEpochP2pAddressPayload,
873
873
  ctx: SuiContext
874
874
  ) => void,
875
875
  filter?: CallFilter,
@@ -1222,7 +1222,7 @@ export namespace sui_system {
1222
1222
  type_arguments: [];
1223
1223
  }
1224
1224
 
1225
- export interface UpdateCandidateValidatorP2PAddressPayload
1225
+ export interface UpdateCandidateValidatorP2pAddressPayload
1226
1226
  extends TypedFunctionPayload<
1227
1227
  [SuiAddress | undefined, number[] | undefined, SuiAddress | undefined]
1228
1228
  > {
@@ -1348,7 +1348,7 @@ export namespace sui_system {
1348
1348
  type_arguments: [];
1349
1349
  }
1350
1350
 
1351
- export interface UpdateValidatorNextEpochP2PAddressPayload
1351
+ export interface UpdateValidatorNextEpochP2pAddressPayload
1352
1352
  extends TypedFunctionPayload<
1353
1353
  [SuiAddress | undefined, number[] | undefined, SuiAddress | undefined]
1354
1354
  > {
@@ -67,7 +67,7 @@ class SuiCodegen extends AbstractCodegen<SuiNetwork, SuiMoveNormalizedModule, Su
67
67
  return content + super.generateStructs(module, struct, events, content !== '')
68
68
  }
69
69
 
70
- generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
70
+ generateForEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
71
71
  switch (structQname(module, struct)) {
72
72
  case '0x1::ascii::Char':
73
73
  case '0x1::ascii::String':
@@ -77,6 +77,6 @@ class SuiCodegen extends AbstractCodegen<SuiNetwork, SuiMoveNormalizedModule, Su
77
77
  case '0x2::balance::Balance':
78
78
  return ''
79
79
  }
80
- return super.generateOnEvents(module, struct)
80
+ return super.generateForEvents(module, struct)
81
81
  }
82
82
  }
@@ -1,9 +1,9 @@
1
1
  import { SimpleCoinInfo } from '../../move/ext/index.js'
2
2
  import fetch from 'node-fetch'
3
- import { SPLITTER } from '../../move/index.js'
3
+ import { accountTypeString, SPLITTER } from '../../move/index.js'
4
4
  import { getPriceByType } from '../../utils/index.js'
5
5
  import { SuiChainId } from '@sentio/chain'
6
- import { validateAndNormalizeAddress } from '../utils.js'
6
+ // import { validateAndNormalizeAddress } from '../utils.js'
7
7
  import { getClient, SuiNetwork } from '../network.js'
8
8
  import { CoinMetadata } from '@mysten/sui.js'
9
9
 
@@ -65,7 +65,7 @@ export function whitelistCoins() {
65
65
 
66
66
  export function whiteListed(coin: string): boolean {
67
67
  const [addr, module, type] = coin.split(SPLITTER)
68
- const normalized = [validateAndNormalizeAddress(addr), module, type].join(SPLITTER)
68
+ const normalized = [accountTypeString(addr), module, type].join(SPLITTER)
69
69
  return WHITELISTED_COINS.has(normalized)
70
70
  }
71
71
 
package/src/sui/index.ts CHANGED
@@ -25,4 +25,4 @@ export { SuiPlugin } from './sui-plugin.js'
25
25
 
26
26
  export { ModuleClient } from './module-client.js'
27
27
 
28
- export { validateAndNormalizeAddress, isValidSuiAddress } from './utils.js'
28
+ // export { validateAndNormalizeAddress, isValidSuiAddress } from './utils.js'
@@ -10,7 +10,6 @@ import {
10
10
  SuiMoveObject,
11
11
  SuiParsedData,
12
12
  } from '@mysten/sui.js'
13
- import { validateAndNormalizeAddress } from './utils.js'
14
13
 
15
14
  export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
16
15
  static INSTANCE = new SuiChainAdapter()
@@ -76,9 +75,9 @@ export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedM
76
75
  }
77
76
  return val as any
78
77
  }
79
- validateAndNormalizeAddress(address: string) {
80
- return validateAndNormalizeAddress(address)
81
- }
78
+ // validateAndNormalizeAddress(address: string) {
79
+ // return validateAndNormalizeAddress(address)
80
+ // }
82
81
  }
83
82
 
84
83
  function getRpcEndpoint(network: SuiNetwork): string {
@@ -18,7 +18,6 @@ import { ServerError, Status } from 'nice-grpc'
18
18
 
19
19
  import { SuiProcessorState } from './sui-processor.js'
20
20
  import { SuiAccountProcessorState } from './sui-object-processor.js'
21
- import { validateAndNormalizeAddress } from './utils.js'
22
21
  import { initCoinList } from './ext/coin.js'
23
22
  import { SuiChainId } from '@sentio/chain'
24
23
  import {
@@ -77,7 +76,7 @@ export class SuiPlugin extends Plugin {
77
76
  contract: {
78
77
  name: suiProcessor.moduleName,
79
78
  chainId: suiProcessor.config.network,
80
- address: suiProcessor.config.address === '*' ? '*' : validateAndNormalizeAddress(suiProcessor.config.address),
79
+ address: suiProcessor.config.address,
81
80
  abi: '',
82
81
  },
83
82
  startBlock: suiProcessor.config.startCheckpoint,
@@ -118,7 +117,7 @@ export class SuiPlugin extends Plugin {
118
117
 
119
118
  for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {
120
119
  const accountConfig = AccountConfig.fromPartial({
121
- address: validateAndNormalizeAddress(processor.config.address),
120
+ address: processor.config.address,
122
121
  chainId: processor.getChainId(),
123
122
  startBlock: processor.config.startCheckpoint, // TODO maybe use another field
124
123
  })
@@ -11,6 +11,8 @@ import {
11
11
  SuiTransactionBlockResponse,
12
12
  } from '@mysten/sui.js'
13
13
  import {
14
+ accountAddressString,
15
+ accountTypeString,
14
16
  CallHandler,
15
17
  EventFilter,
16
18
  EventHandler,
@@ -32,21 +34,9 @@ const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
32
34
  export type IndexConfigure = Required<SuiBindOptions, 'startCheckpoint' | 'network'>
33
35
 
34
36
  export function configure(options: SuiBindOptions): IndexConfigure {
35
- let addressNoPrefix = options.address
36
-
37
- if (addressNoPrefix.startsWith('0x')) {
38
- addressNoPrefix = addressNoPrefix.slice(2)
39
- }
40
- for (let i = 0; i < addressNoPrefix.length; i++) {
41
- if (addressNoPrefix[i] !== '0') {
42
- addressNoPrefix = addressNoPrefix.slice(i)
43
- break
44
- }
45
- }
46
-
47
37
  return {
48
38
  startCheckpoint: options.startCheckpoint || 0n,
49
- address: addressNoPrefix === '*' ? '*' : '0x' + addressNoPrefix,
39
+ address: options.address === '*' ? '*' : accountAddressString(options.address),
50
40
  network: options.network || SuiNetwork.MAIN_NET,
51
41
  baseLabels: options.baseLabels,
52
42
  }
@@ -100,7 +90,7 @@ export class SuiBaseProcessor {
100
90
  // const moduleName = this.moduleName
101
91
 
102
92
  const processor = this
103
- const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))
93
+ const allEventType = new Set(_filters.map((f) => accountTypeString(processor.config.address) + '::' + f.type))
104
94
 
105
95
  this.eventHandlers.push({
106
96
  handler: async function (data) {
@@ -158,7 +148,9 @@ export class SuiBaseProcessor {
158
148
  }
159
149
 
160
150
  const processor = this
161
- const allFunctionType = new Set(_filters.map((f) => processor.config.address + '::' + f.function))
151
+ const allFunctionType = new Set(
152
+ _filters.map((f) => accountTypeString(processor.config.address) + '::' + f.function)
153
+ )
162
154
 
163
155
  this.callHandlers.push({
164
156
  handler: async function (data) {
package/src/sui/utils.ts CHANGED
@@ -5,11 +5,8 @@ import {
5
5
  getProgrammableTransaction,
6
6
  ProgrammableTransaction,
7
7
  SuiTransaction,
8
- normalizeSuiAddress,
9
- SUI_ADDRESS_LENGTH,
10
- SuiAddress,
11
8
  } from '@mysten/sui.js'
12
- import { isFrameworkAccount } from '../move/index.js'
9
+ import { accountTypeString } from '../move/index.js'
13
10
 
14
11
  export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
15
12
  const txKind = getTransactionKind(txBlock)
@@ -24,12 +21,7 @@ export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
24
21
  return programmableTx.transactions.flatMap((tx: SuiTransaction) => {
25
22
  if ('MoveCall' in tx) {
26
23
  const call = tx.MoveCall as MoveCallSuiTransaction
27
-
28
- let pkg: string = call.package
29
- if (call.package.startsWith('0x000000000000000000000000000000000000000000000000000000000000000')) {
30
- pkg = '0x' + pkg[pkg.length - 1]
31
- }
32
- call.package = pkg
24
+ call.package = accountTypeString(call.package)
33
25
 
34
26
  return [call]
35
27
  }
@@ -37,25 +29,25 @@ export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
37
29
  })
38
30
  }
39
31
 
40
- function isHex(value: string): boolean {
41
- return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)
42
- }
43
-
44
- function getHexByteLength(value: string): number {
45
- return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2
46
- }
47
-
48
- export function isValidSuiAddress(value: string): value is SuiAddress {
49
- return isHex(value) && getHexByteLength(value) <= SUI_ADDRESS_LENGTH
50
- }
51
-
52
- export function validateAndNormalizeAddress(address: string): string {
53
- if (isFrameworkAccount(address)) {
54
- const n = parseInt(address, 16)
55
- return `0x${n.toString(16)}`
56
- }
57
- if (!isValidSuiAddress(address)) {
58
- throw Error('Not valid Address')
59
- }
60
- return normalizeSuiAddress(address)
61
- }
32
+ // function isHex(value: string): boolean {
33
+ // return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)
34
+ // }
35
+ //
36
+ // function getHexByteLength(value: string): number {
37
+ // return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2
38
+ // }
39
+ //
40
+ // export function isValidSuiAddress(value: string): value is SuiAddress {
41
+ // return isHex(value) && getHexByteLength(value) <= SUI_ADDRESS_LENGTH
42
+ // }
43
+
44
+ // export function validateAndNormalizeAddress(address: string): string {
45
+ // // if (isFrameworkAccount(address)) {
46
+ // // const n = parseInt(address, 16)
47
+ // // return `0x${n.toString(16)}`
48
+ // // }
49
+ // if (!isValidSuiAddress(address)) {
50
+ // throw Error('Not valid Address')
51
+ // }
52
+ // return normalizeSuiAddress(address)
53
+ // }