@sentio/cli 3.8.0 → 3.9.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.
- package/lib/index.js +68167 -43227
- package/package.json +12 -5
- package/src/abi.ts +135 -2
- package/templates/aptos/package.json +1 -1
- package/templates/aptos/tsconfig.json +2 -1
- package/templates/eth/package.json +1 -1
- package/templates/fuel/package.json +1 -1
- package/templates/iota/package.json +1 -1
- package/templates/iota/tsconfig.json +2 -1
- package/templates/raw/package.json +1 -1
- package/templates/solana/package.json +1 -1
- package/templates/sui/abis/sui/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.json +303 -227
- package/templates/sui/abis/sui/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.json +12844 -10000
- package/templates/sui/package.json +1 -1
- package/templates/sui/src/processor.ts +1 -1
- package/templates/sui/tsconfig.json +2 -1
- package/templates/aptos/src/processor.test.ts +0 -16
- package/templates/eth/src/processor.test.ts +0 -30
- package/templates/fuel/src/processor.test.ts +0 -16
- package/templates/iota/src/processor.test.ts +0 -16
- package/templates/raw/src/processor.test.ts +0 -16
- package/templates/solana/src/processor.test.ts +0 -16
- package/templates/sui/src/processor.test.ts +0 -16
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentio/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0-rc.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/sentioxyz/sentio-sdk.git",
|
|
8
|
+
"directory": "packages/cli"
|
|
9
|
+
},
|
|
5
10
|
"type": "module",
|
|
6
11
|
"exports": {
|
|
7
12
|
".": "./lib/index.js"
|
|
@@ -10,9 +15,11 @@
|
|
|
10
15
|
"sentio": "./lib/index.js"
|
|
11
16
|
},
|
|
12
17
|
"files": [
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
18
|
+
"lib",
|
|
19
|
+
"src",
|
|
20
|
+
"templates",
|
|
21
|
+
"!**/*.test.*",
|
|
22
|
+
"!lib/**/*.map"
|
|
16
23
|
],
|
|
17
24
|
"types": "module",
|
|
18
25
|
"dependencies": {
|
|
@@ -36,6 +43,6 @@
|
|
|
36
43
|
"bundle": "esbuild --platform=node --format=esm --bundle src/index.ts --outfile=lib/index.js --sourcemap --inject:src/cjs-shim.ts --external:@sentio/sdk",
|
|
37
44
|
"cli": "tsx src/index.ts",
|
|
38
45
|
"compile": "tsc",
|
|
39
|
-
"test": "
|
|
46
|
+
"test": "tsx --test 'src/**/*.test.ts'"
|
|
40
47
|
}
|
|
41
48
|
}
|
package/src/abi.ts
CHANGED
|
@@ -12,6 +12,140 @@ import { ReadKey } from './key.js'
|
|
|
12
12
|
import { Auth } from './commands/upload.js'
|
|
13
13
|
import { getApiUrl } from './utils.js'
|
|
14
14
|
|
|
15
|
+
// @typemove/sui v2 codegen consumes the gRPC ABI shape
|
|
16
|
+
// (`[{ address, module: { datatypes, functions } }]`). The JSON-RPC
|
|
17
|
+
// `getNormalizedMoveModulesByPackage` returns the legacy shape
|
|
18
|
+
// (`{ structs, exposedFunctions }`); convert it so downloaded Sui/Iota ABIs
|
|
19
|
+
// feed the codegen directly.
|
|
20
|
+
const MOVE_DATATYPE_KIND_STRUCT = 1
|
|
21
|
+
const MOVE_DATATYPE_KIND_ENUM = 2
|
|
22
|
+
const MOVE_VIS: Record<string, number> = { Private: 1, Public: 2, Friend: 3 }
|
|
23
|
+
const MOVE_TYPE = {
|
|
24
|
+
Address: 1,
|
|
25
|
+
Bool: 2,
|
|
26
|
+
U8: 3,
|
|
27
|
+
U16: 4,
|
|
28
|
+
U32: 5,
|
|
29
|
+
U64: 6,
|
|
30
|
+
U128: 7,
|
|
31
|
+
U256: 8,
|
|
32
|
+
Vector: 9,
|
|
33
|
+
Datatype: 10,
|
|
34
|
+
TypeParam: 11
|
|
35
|
+
}
|
|
36
|
+
const MOVE_ABILITY: Record<string, number> = { Copy: 1, Drop: 2, Store: 3, Key: 4 }
|
|
37
|
+
|
|
38
|
+
function normalizedTypeToBody(t: any): any {
|
|
39
|
+
if (typeof t === 'string') {
|
|
40
|
+
const m: Record<string, number> = {
|
|
41
|
+
Address: MOVE_TYPE.Address,
|
|
42
|
+
Bool: MOVE_TYPE.Bool,
|
|
43
|
+
U8: MOVE_TYPE.U8,
|
|
44
|
+
U16: MOVE_TYPE.U16,
|
|
45
|
+
U32: MOVE_TYPE.U32,
|
|
46
|
+
U64: MOVE_TYPE.U64,
|
|
47
|
+
U128: MOVE_TYPE.U128,
|
|
48
|
+
U256: MOVE_TYPE.U256
|
|
49
|
+
}
|
|
50
|
+
if (m[t]) return { type: m[t], typeParameterInstantiation: [] }
|
|
51
|
+
if (t.toLowerCase() === 'signer')
|
|
52
|
+
return { type: MOVE_TYPE.Datatype, typeName: '0x0::signer::Signer', typeParameterInstantiation: [] }
|
|
53
|
+
throw Error('unknown primitive type ' + t)
|
|
54
|
+
}
|
|
55
|
+
if ('Vector' in t) return { type: MOVE_TYPE.Vector, typeParameterInstantiation: [normalizedTypeToBody(t.Vector)] }
|
|
56
|
+
if ('Struct' in t) {
|
|
57
|
+
const s = t.Struct
|
|
58
|
+
return {
|
|
59
|
+
type: MOVE_TYPE.Datatype,
|
|
60
|
+
typeName: `${s.address}::${s.module}::${s.name}`,
|
|
61
|
+
typeParameterInstantiation: (s.typeArguments ?? []).map(normalizedTypeToBody)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if ('TypeParameter' in t)
|
|
65
|
+
return { type: MOVE_TYPE.TypeParam, typeParameter: t.TypeParameter, typeParameterInstantiation: [] }
|
|
66
|
+
if ('Reference' in t || 'MutableReference' in t) return normalizedTypeToBody(t.Reference ?? t.MutableReference)
|
|
67
|
+
throw Error('unknown type ' + JSON.stringify(t))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function normalizedParam(t: any): any {
|
|
71
|
+
if (t && typeof t === 'object' && 'Reference' in t) return { reference: 1, body: normalizedTypeToBody(t.Reference) }
|
|
72
|
+
if (t && typeof t === 'object' && 'MutableReference' in t)
|
|
73
|
+
return { reference: 2, body: normalizedTypeToBody(t.MutableReference) }
|
|
74
|
+
return { body: normalizedTypeToBody(t) }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function normalizedAbilities(s: any): number[] {
|
|
78
|
+
return (Array.isArray(s) ? s : (s?.abilities ?? [])).map((a: string) => MOVE_ABILITY[a])
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function normalizedTypeParameters(params: any[]): any[] {
|
|
82
|
+
return (params ?? []).map((p: any) => ({ constraints: normalizedAbilities(p.constraints ?? p.abilities ?? p) }))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function normalizedStruct(name: string, s: any): any {
|
|
86
|
+
return {
|
|
87
|
+
name,
|
|
88
|
+
kind: MOVE_DATATYPE_KIND_STRUCT,
|
|
89
|
+
abilities: normalizedAbilities(s.abilities),
|
|
90
|
+
typeParameters: normalizedTypeParameters(s.typeParameters),
|
|
91
|
+
fields: (s.fields ?? []).map((f: any, i: number) => ({
|
|
92
|
+
name: f.name,
|
|
93
|
+
position: i,
|
|
94
|
+
type: normalizedTypeToBody(f.type)
|
|
95
|
+
})),
|
|
96
|
+
variants: []
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function normalizedEnum(name: string, e: any): any {
|
|
101
|
+
return {
|
|
102
|
+
name,
|
|
103
|
+
kind: MOVE_DATATYPE_KIND_ENUM,
|
|
104
|
+
abilities: normalizedAbilities(e.abilities),
|
|
105
|
+
typeParameters: normalizedTypeParameters(e.typeParameters),
|
|
106
|
+
fields: [],
|
|
107
|
+
variants: Object.entries(e.variants ?? {}).map(([vn, fl]: [string, any], i) => ({
|
|
108
|
+
name: vn,
|
|
109
|
+
position: i,
|
|
110
|
+
fields: (fl as any[]).map((f, fi) => ({ name: f.name, position: fi, type: normalizedTypeToBody(f.type) }))
|
|
111
|
+
}))
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function normalizedFunction(name: string, f: any): any {
|
|
116
|
+
return {
|
|
117
|
+
name,
|
|
118
|
+
visibility: MOVE_VIS[f.visibility],
|
|
119
|
+
isEntry: f.isEntry ?? false,
|
|
120
|
+
typeParameters: (f.typeParameters ?? []).map((p: any) => ({
|
|
121
|
+
constraints: normalizedAbilities(p.abilities ?? p.constraints ?? p)
|
|
122
|
+
})),
|
|
123
|
+
parameters: (f.parameters ?? []).map(normalizedParam),
|
|
124
|
+
returns: (f.return ?? []).map(normalizedParam)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function normalizedModule(name: string, m: any): any {
|
|
129
|
+
return {
|
|
130
|
+
name: m.name ?? name,
|
|
131
|
+
datatypes: [
|
|
132
|
+
...Object.entries(m.structs ?? {}).map(([k, s]) => normalizedStruct(k, s)),
|
|
133
|
+
...Object.entries(m.enums ?? {}).map(([k, e]) => normalizedEnum(k, e))
|
|
134
|
+
],
|
|
135
|
+
functions: Object.entries(m.exposedFunctions ?? {}).map(([k, f]) => normalizedFunction(k, f))
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Convert the JSON-RPC normalized-modules shape (a `{ name: module }` map or an
|
|
140
|
+
// array of modules) into the gRPC ABI array consumed by the v2 codegen.
|
|
141
|
+
export function normalizedModulesToAbi(modules: any): Array<{ address: string; module: any }> {
|
|
142
|
+
const map = modules?.result ?? modules
|
|
143
|
+
const entries: Array<[string, any]> = Array.isArray(map)
|
|
144
|
+
? map.map((m: any) => [m.name, m])
|
|
145
|
+
: Object.entries(map ?? {})
|
|
146
|
+
return entries.map(([n, m]) => ({ address: m.address, module: normalizedModule(n, m) }))
|
|
147
|
+
}
|
|
148
|
+
|
|
15
149
|
export async function getABI(
|
|
16
150
|
chain: ChainId,
|
|
17
151
|
address: string,
|
|
@@ -37,7 +171,7 @@ export async function getABI(
|
|
|
37
171
|
if (suiClient) {
|
|
38
172
|
try {
|
|
39
173
|
return {
|
|
40
|
-
abi: await suiClient.getNormalizedMoveModulesByPackage({ package: address }),
|
|
174
|
+
abi: normalizedModulesToAbi(await suiClient.getNormalizedMoveModulesByPackage({ package: address })),
|
|
41
175
|
name
|
|
42
176
|
}
|
|
43
177
|
} catch (e) {
|
|
@@ -134,7 +268,6 @@ export async function getABI(
|
|
|
134
268
|
console.log('aptos module not loaded')
|
|
135
269
|
}
|
|
136
270
|
|
|
137
|
-
|
|
138
271
|
// ethereum
|
|
139
272
|
try {
|
|
140
273
|
const uploadAuth: Auth = {}
|