@sentio/sdk 2.5.0-rc.3 → 2.5.1-rc.1

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 (51) hide show
  1. package/lib/aptos/codegen/codegen.js +3 -3
  2. package/lib/aptos/codegen/codegen.js.map +1 -1
  3. package/lib/aptos/move-coder.js +2 -2
  4. package/lib/aptos/move-coder.js.map +1 -1
  5. package/lib/aptos/move-types.d.ts +5 -5
  6. package/lib/aptos/move-types.js +15 -15
  7. package/lib/aptos/move-types.js.map +1 -1
  8. package/lib/move/abstract-codegen.d.ts +12 -12
  9. package/lib/move/abstract-codegen.js +27 -27
  10. package/lib/move/abstract-codegen.js.map +1 -1
  11. package/lib/move/abstract-move-coder.d.ts +4 -4
  12. package/lib/move/abstract-move-coder.js +3 -3
  13. package/lib/move/abstract-move-coder.js.map +1 -1
  14. package/lib/move/account.d.ts +4 -7
  15. package/lib/move/account.js +2 -14
  16. package/lib/move/account.js.map +1 -1
  17. package/lib/move/internal-models.d.ts +34 -0
  18. package/lib/move/internal-models.js +7 -0
  19. package/lib/move/internal-models.js.map +1 -0
  20. package/lib/move/ts-type.js +1 -3
  21. package/lib/move/ts-type.js.map +1 -1
  22. package/lib/move/types.d.ts +1 -0
  23. package/lib/move/types.js +13 -25
  24. package/lib/move/types.js.map +1 -1
  25. package/lib/sui/codegen/codegen.js +5 -5
  26. package/lib/sui/codegen/codegen.js.map +1 -1
  27. package/lib/sui/move-coder.js +2 -2
  28. package/lib/sui/move-coder.js.map +1 -1
  29. package/lib/sui/move-types.d.ts +7 -7
  30. package/lib/sui/move-types.js +26 -25
  31. package/lib/sui/move-types.js.map +1 -1
  32. package/lib/sui/utils.d.ts +2 -2
  33. package/lib/sui/utils.js.map +1 -1
  34. package/package.json +9 -9
  35. package/src/aptos/codegen/codegen.ts +7 -7
  36. package/src/aptos/move-coder.ts +2 -3
  37. package/src/aptos/move-types.ts +20 -20
  38. package/src/move/abstract-codegen.ts +42 -40
  39. package/src/move/abstract-move-coder.ts +9 -9
  40. package/src/move/account.ts +6 -21
  41. package/src/move/internal-models.ts +40 -0
  42. package/src/move/ts-type.ts +1 -3
  43. package/src/move/types.ts +13 -33
  44. package/src/sui/codegen/codegen.ts +8 -8
  45. package/src/sui/move-coder.ts +2 -2
  46. package/src/sui/move-types.ts +32 -31
  47. package/src/sui/utils.ts +2 -2
  48. package/lib/move/neutral-models.d.ts +0 -34
  49. package/lib/move/neutral-models.js +0 -7
  50. package/lib/move/neutral-models.js.map +0 -1
  51. package/src/move/neutral-models.ts +0 -45
package/src/move/types.ts CHANGED
@@ -1,20 +1,15 @@
1
1
  import { SPLITTER, VECTOR_STR } from './utils.js'
2
2
 
3
3
  export class TypeDescriptor {
4
- // type: string
5
-
6
- // TODO add reference flag
7
-
8
- // qualified name without type parameters
9
4
  qname: string
10
5
  reference: boolean
11
- // account?: string
12
- // module?: string
13
-
6
+ mutable: boolean
14
7
  typeArgs: TypeDescriptor[]
15
8
 
16
9
  constructor(symbol: string, typeParams?: TypeDescriptor[]) {
17
10
  this.qname = symbol
11
+ this.reference = false
12
+ this.mutable = false
18
13
  this.typeArgs = typeParams || []
19
14
  }
20
15
 
@@ -97,20 +92,15 @@ export class TypeDescriptor {
97
92
  }
98
93
 
99
94
  export function parseMoveType(type: string): TypeDescriptor {
100
- // type = type.replace('&', '')
101
-
102
- type = type.replaceAll('&mut ', '&')
103
- type = type.replaceAll('mut ', '')
104
-
105
- // TODO replace ' ' is not exactly safe, need to double check this
106
- type = type.replaceAll(' ', '')
107
-
108
95
  const stack: TypeDescriptor[] = [new TypeDescriptor('')]
109
96
  let buffer = []
110
97
 
111
98
  // xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
112
99
  for (let i = 0; i < type.length; i++) {
113
100
  const ch = type[i]
101
+ if (ch === ' ') {
102
+ continue
103
+ }
114
104
  if (ch === '<') {
115
105
  // const symbol = type.slice(symbolStart, i)
116
106
  // symbolStart =
@@ -121,7 +111,7 @@ export function parseMoveType(type: string): TypeDescriptor {
121
111
  stack.push(new TypeDescriptor(''))
122
112
  continue
123
113
  }
124
- if (ch === '>') {
114
+ if (ch === '>' || ch === ',') {
125
115
  const typeParam = stack.pop()
126
116
  if (!typeParam) {
127
117
  throw Error('Unexpected stack size')
@@ -132,25 +122,11 @@ export function parseMoveType(type: string): TypeDescriptor {
132
122
  }
133
123
  adjustType(typeParam)
134
124
  stack[stack.length - 1].typeArgs.push(typeParam)
135
- continue
136
- }
137
- if (ch === ',') {
138
- const typeParam = stack.pop()
139
- if (!typeParam) {
140
- throw Error('Unexpected stack size')
141
- }
142
- if (buffer.length > 0) {
143
- typeParam.qname = buffer.join('')
144
- buffer = []
125
+ if (ch === ',') {
126
+ stack.push(new TypeDescriptor(''))
145
127
  }
146
- adjustType(typeParam)
147
-
148
- stack[stack.length - 1].typeArgs.push(typeParam)
149
- // continue parse next param
150
- stack.push(new TypeDescriptor(''))
151
128
  continue
152
129
  }
153
-
154
130
  buffer.push(ch)
155
131
  }
156
132
 
@@ -171,4 +147,8 @@ function adjustType(type: TypeDescriptor) {
171
147
  type.reference = true
172
148
  type.qname = type.qname.slice(1)
173
149
  }
150
+ if (type.qname.startsWith('mut')) {
151
+ type.mutable = true
152
+ type.qname = type.qname.slice(3)
153
+ }
174
154
  }
@@ -1,10 +1,10 @@
1
1
  import { SuiNetwork } from '../network.js'
2
2
  import * as fs from 'fs'
3
3
  import chalk from 'chalk'
4
- import { NeutralMoveModule, NeutralMoveStruct } from '../../move/neutral-models.js'
4
+ import { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'
5
5
  import { AbstractCodegen } from '../../move/abstract-codegen.js'
6
6
  import { JsonRpcProvider, SuiMoveNormalizedModules } from '@mysten/sui.js'
7
- import { toNeutralModule } from '../move-types.js'
7
+ import { toInternalModule } from '../move-types.js'
8
8
  import { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'
9
9
 
10
10
  export async function codegen(abisDir: string, outDir = 'src/types/sui') {
@@ -12,7 +12,7 @@ export async function codegen(abisDir: string, outDir = 'src/types/sui') {
12
12
  return
13
13
  }
14
14
  console.log(chalk.green('Generated Types for Sui'))
15
- const gen = new SuiCodeGen()
15
+ const gen = new SuiCodegen()
16
16
  await gen.generate(abisDir, outDir)
17
17
  }
18
18
 
@@ -28,7 +28,7 @@ function getRpcClient(network: SuiNetwork): JsonRpcProvider {
28
28
  return new JsonRpcProvider(getRpcEndpoint(network))
29
29
  }
30
30
 
31
- class SuiCodeGen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
31
+ class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
32
32
  ADDRESS_TYPE = 'SuiAddress'
33
33
  MAIN_NET = SuiNetwork.MAIN_NET
34
34
  TEST_NET = SuiNetwork.TEST_NET
@@ -44,13 +44,13 @@ class SuiCodeGen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
44
44
  return params.slice(0, params.length - 1)
45
45
  }
46
46
 
47
- toNeutral(modules: SuiMoveNormalizedModules): NeutralMoveModule[] {
48
- return Object.values(modules).map(toNeutralModule)
47
+ toInternalModules(modules: SuiMoveNormalizedModules): InternalMoveModule[] {
48
+ return Object.values(modules).map(toInternalModule)
49
49
  }
50
50
 
51
- getEventStructs(module: NeutralMoveModule) {
51
+ getEventStructs(module: InternalMoveModule) {
52
52
  const qname = moduleQname(module)
53
- const eventMap = new Map<string, NeutralMoveStruct>()
53
+ const eventMap = new Map<string, InternalMoveStruct>()
54
54
 
55
55
  for (const struct of module.structs) {
56
56
  const abilities = new Set(struct.abilities)
@@ -1,7 +1,7 @@
1
1
  import { TypedEventInstance, TypedEntryFunctionPayload } from './models.js'
2
2
  import { AbstractMoveCoder } from '../move/abstract-move-coder.js'
3
3
  import { MoveCall, MoveEvent, SuiMoveNormalizedModule } from '@mysten/sui.js'
4
- import { toNeutralModule } from './move-types.js'
4
+ import { toInternalModule } from './move-types.js'
5
5
  import { SPLITTER } from '../move/index.js'
6
6
 
7
7
  export class MoveCoder extends AbstractMoveCoder<MoveEvent> {
@@ -9,7 +9,7 @@ export class MoveCoder extends AbstractMoveCoder<MoveEvent> {
9
9
  if (this.contains(module.address, module.name)) {
10
10
  return
11
11
  }
12
- this.loadNeutral(toNeutralModule(module))
12
+ this.loadInternal(toInternalModule(module))
13
13
  }
14
14
 
15
15
  decodeEvent<T>(event: MoveEvent): TypedEventInstance<T> | undefined {
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  SuiMoveNormalizedField,
3
3
  SuiMoveNormalizedFunction,
4
4
  SuiMoveNormalizedModule,
@@ -6,102 +6,103 @@ import {
6
6
  SuiMoveNormalizedType,
7
7
  } from '@mysten/sui.js'
8
8
  import {
9
- NeutralMoveFunction,
10
- NeutralMoveFunctionVisibility,
11
- NeutralMoveModule,
12
- NeutralMoveStruct,
13
- NeutralMoveStructField,
14
- } from '../move/neutral-models.js'
9
+ InternalMoveFunction,
10
+ InternalMoveFunctionVisibility,
11
+ InternalMoveModule,
12
+ InternalMoveStruct,
13
+ InternalMoveStructField,
14
+ } from '../move/internal-models.js'
15
15
  import { SPLITTER, TypeDescriptor } from '../move/index.js'
16
16
 
17
17
  export type { SuiAddress } from '@mysten/sui.js'
18
18
 
19
- export function toNeutralModule(module: SuiMoveNormalizedModule): NeutralMoveModule {
19
+ export function toInternalModule(module: SuiMoveNormalizedModule): InternalMoveModule {
20
20
  return {
21
21
  address: module.address,
22
- exposed_functions: Object.entries(module.exposed_functions).map(([n, f]) => toNeutralFunction(n, f)),
22
+ exposedFunctions: Object.entries(module.exposed_functions).map(([n, f]) => toInternalFunction(n, f)),
23
23
  name: module.name,
24
- structs: Object.entries(module.structs).map(([n, s]) => toNeutralStruct(n, s)),
24
+ structs: Object.entries(module.structs).map(([n, s]) => toInternalStruct(n, s)),
25
25
  }
26
26
  }
27
27
 
28
- export function toNeutralFunction(name: string, func: SuiMoveNormalizedFunction): NeutralMoveFunction {
28
+ export function toInternalFunction(name: string, func: SuiMoveNormalizedFunction): InternalMoveFunction {
29
29
  let visibility
30
30
  switch (func.visibility) {
31
31
  case 'Private':
32
- visibility = NeutralMoveFunctionVisibility.PRIVATE
32
+ visibility = InternalMoveFunctionVisibility.PRIVATE
33
33
  break
34
34
  case 'Public':
35
- visibility = NeutralMoveFunctionVisibility.PUBLIC
35
+ visibility = InternalMoveFunctionVisibility.PUBLIC
36
36
  break
37
37
  case 'Friend':
38
- visibility = NeutralMoveFunctionVisibility.FRIEND
38
+ visibility = InternalMoveFunctionVisibility.FRIEND
39
39
  break
40
+ default:
41
+ throw Error('No visibility for function' + name)
40
42
  }
41
43
  return {
42
- generic_type_params: func.type_parameters.map((p) => {
44
+ typeParams: func.type_parameters.map((p: any) => {
43
45
  return { constraints: p.abilities }
44
46
  }),
45
- is_entry: func.is_entry,
47
+ isEntry: func.is_entry,
46
48
  name: name,
47
- params: func.parameters.map(convertToTypeDescriptor),
48
- return: func.return_.map(convertToTypeDescriptor),
49
+ params: func.parameters.map(toTypeDescriptor),
50
+ return: func.return_.map(toTypeDescriptor),
49
51
  visibility: visibility,
50
52
  }
51
53
  }
52
54
 
53
- export function toNeutralStruct(name: string, struct: SuiMoveNormalizedStruct): NeutralMoveStruct {
55
+ export function toInternalStruct(name: string, struct: SuiMoveNormalizedStruct): InternalMoveStruct {
54
56
  return {
55
57
  abilities: struct.abilities.abilities,
56
- fields: struct.fields.map(toNeutralField),
57
- generic_type_params: struct.type_parameters.map((p) => {
58
+ fields: struct.fields.map(toInternalField),
59
+ typeParams: struct.type_parameters.map((p: any) => {
58
60
  return { constraints: p.constraints.abilities }
59
61
  }),
60
- is_native: false,
62
+ isNative: false,
61
63
  name: name,
62
64
  }
63
65
  }
64
66
 
65
- export function toNeutralField(module: SuiMoveNormalizedField): NeutralMoveStructField {
67
+ export function toInternalField(module: SuiMoveNormalizedField): InternalMoveStructField {
66
68
  return {
67
69
  name: module.name,
68
- type: convertToTypeDescriptor(module.type_),
70
+ type: toTypeDescriptor(module.type_),
69
71
  }
70
72
  }
71
73
 
72
- export function convertToTypeDescriptor(normalizedType: SuiMoveNormalizedType): TypeDescriptor {
74
+ export function toTypeDescriptor(normalizedType: SuiMoveNormalizedType): TypeDescriptor {
73
75
  if (typeof normalizedType === 'string') {
74
76
  return new TypeDescriptor(normalizedType)
75
77
  }
76
78
 
77
79
  if ('Struct' in normalizedType) {
78
- // normalizedType.Struct.
79
- // return normalizedType;
80
80
  const qname = [normalizedType.Struct.address, normalizedType.Struct.module, normalizedType.Struct.name].join(
81
81
  SPLITTER
82
82
  )
83
83
 
84
- const args = normalizedType.Struct.type_arguments.map(convertToTypeDescriptor)
84
+ const args = normalizedType.Struct.type_arguments.map(toTypeDescriptor)
85
85
 
86
86
  return new TypeDescriptor(qname, args)
87
87
  }
88
88
 
89
89
  if ('Vector' in normalizedType) {
90
- return new TypeDescriptor('vector', [convertToTypeDescriptor(normalizedType.Vector)])
90
+ return new TypeDescriptor('vector', [toTypeDescriptor(normalizedType.Vector)])
91
91
  }
92
92
  if ('TypeParameter' in normalizedType) {
93
93
  return new TypeDescriptor('T' + normalizedType.TypeParameter)
94
94
  }
95
95
 
96
96
  if ('Reference' in normalizedType) {
97
- const res = convertToTypeDescriptor(normalizedType.Reference)
97
+ const res = toTypeDescriptor(normalizedType.Reference)
98
98
  res.reference = true
99
99
  return res
100
100
  }
101
101
 
102
102
  if ('MutableReference' in normalizedType) {
103
- const res = convertToTypeDescriptor(normalizedType.MutableReference)
103
+ const res = toTypeDescriptor(normalizedType.MutableReference)
104
104
  res.reference = true
105
+ res.mutable = true
105
106
  return res
106
107
  }
107
108
 
package/src/sui/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { SuiTransactionResponse, getMoveCallTransaction, MoveCall } from '@mysten/sui.js'
1
+ import { SuiTransactionResponse, getMoveCallTransaction, SuiTransactionKind } from '@mysten/sui.js'
2
2
 
3
3
  export function getMoveCalls(tx: SuiTransactionResponse) {
4
- return tx.certificate.data.transactions.flatMap((tx) => {
4
+ return tx.certificate.data.transactions.flatMap((tx: SuiTransactionKind) => {
5
5
  const call = getMoveCallTransaction(tx)
6
6
  if (call) {
7
7
  return [call]
@@ -1,34 +0,0 @@
1
- import { TypeDescriptor } from './types.js';
2
- export interface NeutralMoveModule {
3
- address: string;
4
- name: string;
5
- exposed_functions: Array<NeutralMoveFunction>;
6
- structs: Array<NeutralMoveStruct>;
7
- }
8
- export interface NeutralMoveFunction {
9
- name: string;
10
- visibility: NeutralMoveFunctionVisibility;
11
- is_entry: boolean;
12
- generic_type_params: Array<NeutralMoveGenericTypeParam>;
13
- params: Array<TypeDescriptor>;
14
- return: Array<TypeDescriptor>;
15
- }
16
- export interface NeutralMoveStruct {
17
- name: string;
18
- is_native: boolean;
19
- abilities: Array<string>;
20
- generic_type_params: Array<NeutralMoveGenericTypeParam>;
21
- fields: Array<NeutralMoveStructField>;
22
- }
23
- export interface NeutralMoveStructField {
24
- name: string;
25
- type: TypeDescriptor;
26
- }
27
- export declare enum NeutralMoveFunctionVisibility {
28
- PRIVATE = "private",
29
- PUBLIC = "public",
30
- FRIEND = "friend"
31
- }
32
- export type NeutralMoveGenericTypeParam = {
33
- constraints: Array<string>;
34
- };
@@ -1,7 +0,0 @@
1
- export var NeutralMoveFunctionVisibility;
2
- (function (NeutralMoveFunctionVisibility) {
3
- NeutralMoveFunctionVisibility["PRIVATE"] = "private";
4
- NeutralMoveFunctionVisibility["PUBLIC"] = "public";
5
- NeutralMoveFunctionVisibility["FRIEND"] = "friend";
6
- })(NeutralMoveFunctionVisibility || (NeutralMoveFunctionVisibility = {}));
7
- //# sourceMappingURL=neutral-models.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"neutral-models.js","sourceRoot":"","sources":["../../src/move/neutral-models.ts"],"names":[],"mappings":"AAoCA,MAAM,CAAN,IAAY,6BAIX;AAJD,WAAY,6BAA6B;IACvC,oDAAmB,CAAA;IACnB,kDAAiB,CAAA;IACjB,kDAAiB,CAAA;AACnB,CAAC,EAJW,6BAA6B,KAA7B,6BAA6B,QAIxC","sourcesContent":["import { TypeDescriptor } from './types.js'\n\nexport interface NeutralMoveModule {\n address: string\n name: string\n\n exposed_functions: Array<NeutralMoveFunction>\n structs: Array<NeutralMoveStruct>\n}\n\nexport interface NeutralMoveFunction {\n name: string\n visibility: NeutralMoveFunctionVisibility\n is_entry: boolean\n generic_type_params: Array<NeutralMoveGenericTypeParam>\n params: Array<TypeDescriptor>\n return: Array<TypeDescriptor>\n}\n\nexport interface NeutralMoveStruct {\n name: string\n\n is_native: boolean\n\n abilities: Array<string>\n\n generic_type_params: Array<NeutralMoveGenericTypeParam>\n\n fields: Array<NeutralMoveStructField>\n}\n\nexport interface NeutralMoveStructField {\n name: string\n type: TypeDescriptor\n}\n\nexport enum NeutralMoveFunctionVisibility {\n PRIVATE = 'private',\n PUBLIC = 'public',\n FRIEND = 'friend',\n}\n\nexport type NeutralMoveGenericTypeParam = {\n constraints: Array<string>\n}\n"]}
@@ -1,45 +0,0 @@
1
- import { TypeDescriptor } from './types.js'
2
-
3
- export interface NeutralMoveModule {
4
- address: string
5
- name: string
6
-
7
- exposed_functions: Array<NeutralMoveFunction>
8
- structs: Array<NeutralMoveStruct>
9
- }
10
-
11
- export interface NeutralMoveFunction {
12
- name: string
13
- visibility: NeutralMoveFunctionVisibility
14
- is_entry: boolean
15
- generic_type_params: Array<NeutralMoveGenericTypeParam>
16
- params: Array<TypeDescriptor>
17
- return: Array<TypeDescriptor>
18
- }
19
-
20
- export interface NeutralMoveStruct {
21
- name: string
22
-
23
- is_native: boolean
24
-
25
- abilities: Array<string>
26
-
27
- generic_type_params: Array<NeutralMoveGenericTypeParam>
28
-
29
- fields: Array<NeutralMoveStructField>
30
- }
31
-
32
- export interface NeutralMoveStructField {
33
- name: string
34
- type: TypeDescriptor
35
- }
36
-
37
- export enum NeutralMoveFunctionVisibility {
38
- PRIVATE = 'private',
39
- PUBLIC = 'public',
40
- FRIEND = 'friend',
41
- }
42
-
43
- export type NeutralMoveGenericTypeParam = {
44
- constraints: Array<string>
45
- }