@typemove/sui 1.0.0-rc.8 → 1.0.0
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/Readme.md +128 -0
- package/builtin/package.json +5 -0
- package/codegen/package.json +5 -0
- package/dist/cjs/builtin/0x1.d.ts +495 -0
- package/dist/cjs/builtin/0x1.d.ts.map +1 -0
- package/dist/cjs/builtin/0x1.js +2083 -0
- package/dist/cjs/builtin/0x1.js.map +1 -0
- package/dist/cjs/builtin/0x2.d.ts +2929 -0
- package/dist/cjs/builtin/0x2.d.ts.map +1 -0
- package/dist/cjs/builtin/0x2.js +9641 -0
- package/dist/cjs/builtin/0x2.js.map +1 -0
- package/dist/cjs/builtin/0x3.d.ts +1207 -0
- package/dist/cjs/builtin/0x3.d.ts.map +1 -0
- package/dist/cjs/builtin/0x3.js +2625 -0
- package/dist/cjs/builtin/0x3.js.map +1 -0
- package/dist/cjs/builtin/index.d.ts +4 -0
- package/dist/cjs/builtin/index.d.ts.map +1 -0
- package/dist/cjs/builtin/index.js +11 -0
- package/dist/cjs/builtin/index.js.map +1 -0
- package/dist/cjs/codegen/codegen.d.ts +19 -0
- package/dist/cjs/codegen/codegen.d.ts.map +1 -0
- package/dist/cjs/codegen/codegen.js +177 -0
- package/dist/cjs/codegen/codegen.js.map +1 -0
- package/dist/cjs/codegen/index.d.ts +2 -0
- package/dist/cjs/codegen/index.d.ts.map +1 -0
- package/dist/cjs/codegen/index.js +5 -0
- package/dist/cjs/codegen/index.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +10 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/models.d.ts +12 -0
- package/dist/cjs/models.d.ts.map +1 -0
- package/dist/cjs/models.js +8 -0
- package/dist/cjs/models.js.map +1 -0
- package/dist/cjs/move-coder.d.ts +16 -0
- package/dist/cjs/move-coder.d.ts.map +1 -0
- package/dist/cjs/move-coder.js +104 -0
- package/dist/cjs/move-coder.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/sui-chain-adapter.d.ts +12 -0
- package/dist/cjs/sui-chain-adapter.d.ts.map +1 -0
- package/dist/cjs/sui-chain-adapter.js +86 -0
- package/dist/cjs/sui-chain-adapter.js.map +1 -0
- package/dist/cjs/to-internal.d.ts +4 -0
- package/dist/cjs/to-internal.d.ts.map +1 -0
- package/dist/cjs/to-internal.js +85 -0
- package/dist/cjs/to-internal.js.map +1 -0
- package/dist/cjs/utils.d.ts +15 -0
- package/dist/cjs/utils.d.ts.map +1 -0
- package/dist/cjs/utils.js +49 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/builtin/0x1.d.ts +495 -0
- package/dist/esm/builtin/0x1.d.ts.map +1 -0
- package/dist/esm/builtin/0x1.js +2079 -0
- package/dist/esm/builtin/0x1.js.map +1 -0
- package/dist/esm/builtin/0x2.d.ts +2929 -0
- package/dist/esm/builtin/0x2.d.ts.map +1 -0
- package/dist/esm/builtin/0x2.js +9636 -0
- package/dist/esm/builtin/0x2.js.map +1 -0
- package/dist/esm/builtin/0x3.d.ts +1207 -0
- package/dist/esm/builtin/0x3.d.ts.map +1 -0
- package/dist/esm/builtin/0x3.js +2620 -0
- package/dist/esm/builtin/0x3.js.map +1 -0
- package/dist/esm/builtin/index.d.ts +4 -0
- package/dist/esm/builtin/index.d.ts.map +1 -0
- package/dist/esm/builtin/index.js +7 -0
- package/dist/esm/builtin/index.js.map +1 -0
- package/dist/esm/codegen/codegen.d.ts +19 -0
- package/dist/esm/codegen/codegen.d.ts.map +1 -0
- package/dist/esm/codegen/codegen.js +171 -0
- package/dist/esm/codegen/codegen.js.map +1 -0
- package/dist/esm/codegen/index.d.ts +2 -0
- package/dist/esm/codegen/index.d.ts.map +1 -0
- package/dist/esm/codegen/index.js +2 -0
- package/dist/esm/codegen/index.js.map +1 -0
- package/dist/esm/codegen/run.d.ts +2 -0
- package/dist/esm/codegen/run.d.ts.map +1 -0
- package/dist/esm/codegen/run.js +19 -0
- package/dist/esm/codegen/run.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/{index.js → esm/index.js} +0 -1
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/models.d.ts +12 -0
- package/dist/esm/models.d.ts.map +1 -0
- package/dist/esm/models.js +5 -0
- package/dist/esm/models.js.map +1 -0
- package/dist/esm/move-coder.d.ts +16 -0
- package/dist/esm/move-coder.d.ts.map +1 -0
- package/dist/esm/move-coder.js +99 -0
- package/dist/esm/move-coder.js.map +1 -0
- package/dist/esm/sui-chain-adapter.d.ts +12 -0
- package/dist/esm/sui-chain-adapter.d.ts.map +1 -0
- package/dist/esm/sui-chain-adapter.js +82 -0
- package/dist/esm/sui-chain-adapter.js.map +1 -0
- package/dist/esm/to-internal.d.ts +4 -0
- package/dist/esm/to-internal.d.ts.map +1 -0
- package/dist/esm/to-internal.js +81 -0
- package/dist/esm/to-internal.js.map +1 -0
- package/dist/esm/utils.d.ts +15 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +45 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +26 -10
- package/src/builtin/0x1.ts +1359 -231
- package/src/builtin/0x2.ts +6364 -1302
- package/src/builtin/0x3.ts +1909 -495
- package/src/codegen/codegen.ts +63 -49
- package/src/index.ts +0 -2
- package/src/models.ts +9 -12
- package/src/move-coder.ts +6 -20
- package/src/sui-chain-adapter.ts +13 -15
- package/src/tests/types/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.ts +98 -30
- package/src/tests/types/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.ts +1084 -282
- package/src/tests/types/testnet/0xdee9.ts +1112 -308
- package/src/tests/types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.ts +3973 -1201
- package/src/to-internal.ts +12 -32
- package/src/module-client.ts +0 -23
package/src/codegen/codegen.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SuiMoveNormalizedModule,
|
|
3
|
-
SuiEvent,
|
|
4
|
-
SuiMoveObject,
|
|
5
|
-
} from '@mysten/sui.js'
|
|
1
|
+
import { SuiMoveNormalizedModule, SuiEvent, SuiMoveObject } from '@mysten/sui.js/client'
|
|
6
2
|
|
|
7
3
|
import * as fs from 'fs'
|
|
8
4
|
import chalk from 'chalk'
|
|
@@ -34,13 +30,13 @@ export async function codegen(
|
|
|
34
30
|
console.log(chalk.green(`Generated ${numFiles} for Sui`))
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
class SuiCodegen extends AbstractCodegen<
|
|
33
|
+
export class SuiCodegen extends AbstractCodegen<
|
|
38
34
|
// SuiNetwork,
|
|
39
35
|
SuiMoveNormalizedModule,
|
|
40
36
|
SuiEvent | SuiMoveObject
|
|
41
37
|
> {
|
|
42
|
-
ADDRESS_TYPE = '
|
|
43
|
-
|
|
38
|
+
ADDRESS_TYPE = 'string'
|
|
39
|
+
SYSTEM_PACKAGE = '@typemove/sui'
|
|
44
40
|
// ADDRESS_TYPE = 'string'
|
|
45
41
|
// MAIN_NET = SuiNetwork.MAIN_NET
|
|
46
42
|
// TEST_NET = SuiNetwork.TEST_NET
|
|
@@ -61,11 +57,7 @@ class SuiCodegen extends AbstractCodegen<
|
|
|
61
57
|
return res
|
|
62
58
|
}
|
|
63
59
|
|
|
64
|
-
generateStructs(
|
|
65
|
-
module: InternalMoveModule,
|
|
66
|
-
struct: InternalMoveStruct,
|
|
67
|
-
events: Set<string>
|
|
68
|
-
): string {
|
|
60
|
+
generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>): string {
|
|
69
61
|
let content = ''
|
|
70
62
|
switch (structQname(module, struct)) {
|
|
71
63
|
// TODO they should still have module code generated
|
|
@@ -84,15 +76,10 @@ class SuiCodegen extends AbstractCodegen<
|
|
|
84
76
|
content += `export type Option<T> = T | undefined`
|
|
85
77
|
break
|
|
86
78
|
}
|
|
87
|
-
return (
|
|
88
|
-
content + super.generateStructs(module, struct, events, content !== '')
|
|
89
|
-
)
|
|
79
|
+
return content + super.generateStructs(module, struct, events, content !== '')
|
|
90
80
|
}
|
|
91
81
|
|
|
92
|
-
generateForEvents(
|
|
93
|
-
module: InternalMoveModule,
|
|
94
|
-
struct: InternalMoveStruct
|
|
95
|
-
): string {
|
|
82
|
+
generateForEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
|
|
96
83
|
switch (structQname(module, struct)) {
|
|
97
84
|
case '0x1::ascii::Char':
|
|
98
85
|
case '0x1::ascii::String':
|
|
@@ -105,51 +92,81 @@ class SuiCodegen extends AbstractCodegen<
|
|
|
105
92
|
return super.generateForEvents(module, struct)
|
|
106
93
|
}
|
|
107
94
|
|
|
108
|
-
protected
|
|
109
|
-
const funcs = module.exposedFunctions.map((f) =>
|
|
110
|
-
|
|
111
|
-
)
|
|
95
|
+
protected generateExtra(module: InternalMoveModule): string {
|
|
96
|
+
const funcs = module.exposedFunctions.map((f) => this.generateBuilderForFunction(module, f))
|
|
97
|
+
|
|
98
|
+
const viewFuncs = module.exposedFunctions.map((f) => this.generateViewFunction(module, f))
|
|
112
99
|
|
|
113
100
|
return `
|
|
114
101
|
export namespace builder {
|
|
115
102
|
${funcs.join('\n')}
|
|
116
103
|
}
|
|
104
|
+
export namespace view {
|
|
105
|
+
${viewFuncs.join('\n')}
|
|
106
|
+
}
|
|
117
107
|
`
|
|
118
108
|
}
|
|
119
109
|
|
|
120
|
-
|
|
121
|
-
module: InternalMoveModule,
|
|
122
|
-
func: InternalMoveFunction
|
|
123
|
-
): string {
|
|
124
|
-
if (func.visibility !== InternalMoveFunctionVisibility.PUBLIC) {
|
|
125
|
-
return ''
|
|
126
|
-
}
|
|
127
|
-
|
|
110
|
+
private generateArgs(module: InternalMoveModule, func: InternalMoveFunction) {
|
|
128
111
|
const args = []
|
|
129
112
|
for (const [idx, arg] of func.params.entries()) {
|
|
130
113
|
if (arg.reference) {
|
|
131
114
|
args.push({
|
|
132
|
-
paramType:
|
|
115
|
+
paramType: `${this.ADDRESS_TYPE} | ObjectCallArg | TransactionArgument`,
|
|
133
116
|
callValue: `_args.push(TransactionArgument.is(args[${idx}]) ? args[${idx}] : tx.object(args[${idx}]))`,
|
|
134
117
|
})
|
|
135
118
|
} else if (arg.isVector()) {
|
|
136
119
|
args.push({
|
|
137
|
-
paramType:
|
|
120
|
+
paramType: `(${this.ADDRESS_TYPE} | ObjectCallArg)[] | TransactionArgument`,
|
|
138
121
|
callValue: `_args.push(TransactionArgument.is(args[${idx}]) ? args[${idx}] : tx.makeMoveVec({
|
|
139
|
-
objects: args[${idx}].map(a => tx.object(a))
|
|
122
|
+
objects: args[${idx}].map((a: any) => tx.object(a))
|
|
140
123
|
// type: TODO
|
|
141
124
|
}))`,
|
|
142
125
|
})
|
|
143
126
|
} else {
|
|
144
127
|
args.push({
|
|
145
|
-
paramType: `${this.generateTypeForDescriptor(
|
|
146
|
-
arg,
|
|
147
|
-
module.address
|
|
148
|
-
)} | TransactionArgument`,
|
|
128
|
+
paramType: `${this.generateTypeForDescriptor(arg, module.address)} | TransactionArgument`,
|
|
149
129
|
callValue: `_args.push(TransactionArgument.is(args[${idx}]) ? args[${idx}] : tx.pure(args[${idx}]))`,
|
|
150
130
|
})
|
|
151
131
|
}
|
|
152
132
|
}
|
|
133
|
+
return args
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected generateViewFunction(module: InternalMoveModule, func: InternalMoveFunction): string {
|
|
137
|
+
if (func.visibility !== InternalMoveFunctionVisibility.PUBLIC) {
|
|
138
|
+
return ''
|
|
139
|
+
}
|
|
140
|
+
const genericString = this.generateFunctionTypeParameters(func)
|
|
141
|
+
|
|
142
|
+
const typeParamArg = func.typeParams
|
|
143
|
+
.map((v, idx) => {
|
|
144
|
+
return `TypeDescriptor<T${idx}> | string`
|
|
145
|
+
})
|
|
146
|
+
.join(',')
|
|
147
|
+
|
|
148
|
+
const args = this.generateArgs(module, func)
|
|
149
|
+
|
|
150
|
+
return `export async function ${camel(normalizeToJSName(func.name))}${genericString}(
|
|
151
|
+
client: SuiClient,
|
|
152
|
+
args: [${args.map((a) => a.paramType).join(',')}],
|
|
153
|
+
${typeParamArg.length > 0 ? `typeArguments: [${typeParamArg}]` : ``} ) {
|
|
154
|
+
const tx = new TransactionBlock()
|
|
155
|
+
builder.${camel(normalizeToJSName(func.name))}(tx, args ${typeParamArg.length > 0 ? `, typeArguments` : ''})
|
|
156
|
+
const res = await client.devInspectTransactionBlock({
|
|
157
|
+
transactionBlock: tx,
|
|
158
|
+
sender: ZERO_ADDRESS
|
|
159
|
+
})
|
|
160
|
+
return res
|
|
161
|
+
}`
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
protected generateBuilderForFunction(module: InternalMoveModule, func: InternalMoveFunction): string {
|
|
165
|
+
if (func.visibility !== InternalMoveFunctionVisibility.PUBLIC) {
|
|
166
|
+
return ''
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const args = this.generateArgs(module, func)
|
|
153
170
|
|
|
154
171
|
const genericString = this.generateFunctionTypeParameters(func)
|
|
155
172
|
|
|
@@ -164,14 +181,10 @@ class SuiCodegen extends AbstractCodegen<
|
|
|
164
181
|
})
|
|
165
182
|
.join(',')
|
|
166
183
|
|
|
167
|
-
return `export function ${camel(
|
|
168
|
-
normalizeToJSName(func.name)
|
|
169
|
-
)}${genericString}(tx: TransactionBlock,
|
|
184
|
+
return `export function ${camel(normalizeToJSName(func.name))}${genericString}(tx: TransactionBlock,
|
|
170
185
|
args: [${args.map((a) => a.paramType).join(',')}],
|
|
171
186
|
${typeParamArg.length > 0 ? `typeArguments: [${typeParamArg}]` : ``} ):
|
|
172
|
-
TransactionArgument & [ ${'TransactionArgument,'.repeat(
|
|
173
|
-
func.params.length
|
|
174
|
-
)} ] {
|
|
187
|
+
TransactionArgument & [ ${'TransactionArgument,'.repeat(func.params.length)} ] {
|
|
175
188
|
const _args: any[] = []
|
|
176
189
|
${args.map((a) => a.callValue).join('\n')}
|
|
177
190
|
|
|
@@ -179,9 +192,7 @@ class SuiCodegen extends AbstractCodegen<
|
|
|
179
192
|
return tx.moveCall({
|
|
180
193
|
target: "${module.address}::${module.name}::${func.name}",
|
|
181
194
|
arguments: _args,
|
|
182
|
-
${
|
|
183
|
-
typeParamArg.length > 0 ? `typeArguments: [${typeParamToString}]` : ``
|
|
184
|
-
}
|
|
195
|
+
${typeParamArg.length > 0 ? `typeArguments: [${typeParamToString}]` : ``}
|
|
185
196
|
})
|
|
186
197
|
}`
|
|
187
198
|
}
|
|
@@ -189,7 +200,10 @@ class SuiCodegen extends AbstractCodegen<
|
|
|
189
200
|
generateImports(): string {
|
|
190
201
|
return `
|
|
191
202
|
${super.generateImports()}
|
|
192
|
-
import {
|
|
203
|
+
import { ZERO_ADDRESS } from '@typemove/sui'
|
|
204
|
+
import { TransactionBlock } from '@mysten/sui.js/transactions'
|
|
205
|
+
import { ObjectCallArg, TransactionArgument } from '@mysten/sui.js'
|
|
206
|
+
import { SuiClient } from '@mysten/sui.js/client'
|
|
193
207
|
`
|
|
194
208
|
}
|
|
195
209
|
}
|
package/src/index.ts
CHANGED
package/src/models.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
SuiEvent,
|
|
3
|
-
MoveCallSuiTransaction,
|
|
4
|
-
SuiMoveObject,
|
|
5
|
-
} from '@mysten/sui.js'
|
|
1
|
+
import type { SuiEvent, MoveCallSuiTransaction, SuiMoveObject } from '@mysten/sui.js/client'
|
|
6
2
|
import { DecodedStruct } from '@typemove/move'
|
|
7
3
|
|
|
4
|
+
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000000000000000000000000000'
|
|
5
|
+
|
|
8
6
|
export type TypedEventInstance<T> = DecodedStruct<SuiEvent, T>
|
|
9
7
|
export type TypedSuiMoveObject<T> = DecodedStruct<SuiMoveObject, T>
|
|
10
8
|
|
|
11
|
-
export type TypedFunctionPayload<T extends Array<any>> =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
9
|
+
export type TypedFunctionPayload<T extends Array<any>> = MoveCallSuiTransaction & {
|
|
10
|
+
/**
|
|
11
|
+
* decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
|
12
|
+
*/
|
|
13
|
+
arguments_decoded: T
|
|
14
|
+
}
|
|
18
15
|
|
|
19
16
|
// export interface TypedExecutionResultType<T> extends ExecutionResultType {
|
|
20
17
|
//
|
package/src/move-coder.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
SuiEvent,
|
|
15
15
|
SuiMoveNormalizedModule,
|
|
16
16
|
SuiMoveObject,
|
|
17
|
-
} from '@mysten/sui.js'
|
|
17
|
+
} from '@mysten/sui.js/client'
|
|
18
18
|
import { toInternalModule } from './to-internal.js'
|
|
19
19
|
import { SuiChainAdapter } from './sui-chain-adapter.js'
|
|
20
20
|
import { dynamic_field } from './builtin/0x2.js'
|
|
@@ -60,10 +60,7 @@ export class MoveCoder extends AbstractMoveCoder<
|
|
|
60
60
|
decodeEvent<T>(event: SuiEvent): Promise<TypedEventInstance<T> | undefined> {
|
|
61
61
|
return this.decodedStruct(event)
|
|
62
62
|
}
|
|
63
|
-
filterAndDecodeEvents<T>(
|
|
64
|
-
type: TypeDescriptor<T> | string,
|
|
65
|
-
resources: SuiEvent[]
|
|
66
|
-
): Promise<TypedEventInstance<T>[]> {
|
|
63
|
+
filterAndDecodeEvents<T>(type: TypeDescriptor<T> | string, resources: SuiEvent[]): Promise<TypedEventInstance<T>[]> {
|
|
67
64
|
if (typeof type === 'string') {
|
|
68
65
|
type = parseMoveType(type)
|
|
69
66
|
}
|
|
@@ -77,9 +74,7 @@ export class MoveCoder extends AbstractMoveCoder<
|
|
|
77
74
|
): Promise<dynamic_field.Field<T1, T2>[]> {
|
|
78
75
|
// const type = dynamic_field.Field.TYPE
|
|
79
76
|
// Not using the code above to avoid cycle initialize failed
|
|
80
|
-
const type = new TypeDescriptor<dynamic_field.Field<T1, T2>>(
|
|
81
|
-
'0x2::dynamic_field::Field'
|
|
82
|
-
)
|
|
77
|
+
const type = new TypeDescriptor<dynamic_field.Field<T1, T2>>('0x2::dynamic_field::Field')
|
|
83
78
|
type.typeArgs = [keyType, valueType]
|
|
84
79
|
const res = await this.filterAndDecodeObjects(type, objects)
|
|
85
80
|
return res.map((o) => o.data_decoded)
|
|
@@ -92,15 +87,8 @@ export class MoveCoder extends AbstractMoveCoder<
|
|
|
92
87
|
return this.filterAndDecodeStruct(type, objects)
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
async decodeFunctionPayload(
|
|
96
|
-
payload
|
|
97
|
-
inputs: SuiCallArg[]
|
|
98
|
-
): Promise<MoveCallSuiTransaction> {
|
|
99
|
-
const functionType = [
|
|
100
|
-
payload.package,
|
|
101
|
-
payload.module,
|
|
102
|
-
payload.function,
|
|
103
|
-
].join(SPLITTER)
|
|
90
|
+
async decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): Promise<MoveCallSuiTransaction> {
|
|
91
|
+
const functionType = [payload.package, payload.module, payload.function].join(SPLITTER)
|
|
104
92
|
const func = await this.getMoveFunction(functionType)
|
|
105
93
|
const params = this.adapter.getMeaningfulFunctionParams(func.params)
|
|
106
94
|
const args = []
|
|
@@ -135,9 +123,7 @@ export class MoveCoder extends AbstractMoveCoder<
|
|
|
135
123
|
const DEFAULT_ENDPOINT = 'https://fullnode.mainnet.sui.io/'
|
|
136
124
|
const CODER_MAP = new Map<string, MoveCoder>()
|
|
137
125
|
|
|
138
|
-
export function defaultMoveCoder(
|
|
139
|
-
endpoint: string = DEFAULT_ENDPOINT
|
|
140
|
-
): MoveCoder {
|
|
126
|
+
export function defaultMoveCoder(endpoint: string = DEFAULT_ENDPOINT): MoveCoder {
|
|
141
127
|
let coder = CODER_MAP.get(endpoint)
|
|
142
128
|
if (!coder) {
|
|
143
129
|
coder = new MoveCoder(DEFAULT_ENDPOINT)
|
package/src/sui-chain-adapter.ts
CHANGED
|
@@ -7,14 +7,8 @@ import {
|
|
|
7
7
|
SPLITTER,
|
|
8
8
|
TypeDescriptor,
|
|
9
9
|
} from '@typemove/move'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
JsonRpcProvider,
|
|
13
|
-
SuiMoveNormalizedModule,
|
|
14
|
-
SuiEvent,
|
|
15
|
-
SuiMoveObject,
|
|
16
|
-
SuiParsedData,
|
|
17
|
-
} from '@mysten/sui.js'
|
|
10
|
+
|
|
11
|
+
import { SuiMoveNormalizedModule, SuiEvent, SuiMoveObject, SuiClient } from '@mysten/sui.js/client'
|
|
18
12
|
|
|
19
13
|
export class SuiChainAdapter extends ChainAdapter<
|
|
20
14
|
// SuiNetwork,
|
|
@@ -55,9 +49,7 @@ export class SuiChainAdapter extends ChainAdapter<
|
|
|
55
49
|
return Object.values(modules).map(toInternalModule)
|
|
56
50
|
}
|
|
57
51
|
|
|
58
|
-
getAllEventStructs(
|
|
59
|
-
modules: InternalMoveModule[]
|
|
60
|
-
): Map<string, InternalMoveStruct> {
|
|
52
|
+
getAllEventStructs(modules: InternalMoveModule[]): Map<string, InternalMoveStruct> {
|
|
61
53
|
const eventMap = new Map<string, InternalMoveStruct>()
|
|
62
54
|
|
|
63
55
|
for (const module of modules) {
|
|
@@ -78,10 +70,16 @@ export class SuiChainAdapter extends ChainAdapter<
|
|
|
78
70
|
}
|
|
79
71
|
|
|
80
72
|
getData(val: SuiEvent | SuiMoveObject) {
|
|
81
|
-
if (
|
|
73
|
+
// if (val.parsedJson) {
|
|
74
|
+
// return val.parsedJson as any
|
|
75
|
+
// }
|
|
76
|
+
if ('parsedJson' in val) {
|
|
82
77
|
return val.parsedJson as any
|
|
83
78
|
}
|
|
84
|
-
if (SuiParsedData.is(val)) {
|
|
79
|
+
// if (SuiParsedData.is(val)) {
|
|
80
|
+
// return val.fields as any
|
|
81
|
+
// }
|
|
82
|
+
if (val.dataType === 'moveObject') {
|
|
85
83
|
return val.fields as any
|
|
86
84
|
}
|
|
87
85
|
// if (SuiMoveObject.is(val)) {
|
|
@@ -108,6 +106,6 @@ export class SuiChainAdapter extends ChainAdapter<
|
|
|
108
106
|
// return 'https://fullnode.mainnet.sui.io/'
|
|
109
107
|
// }
|
|
110
108
|
|
|
111
|
-
function getRpcClient(endpoint: string):
|
|
112
|
-
return new
|
|
109
|
+
function getRpcClient(endpoint: string): SuiClient {
|
|
110
|
+
return new SuiClient({ url: endpoint })
|
|
113
111
|
}
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
/* Generated modules for account 0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5 */
|
|
6
6
|
|
|
7
7
|
import { TypeDescriptor, ANY_TYPE } from "@typemove/move";
|
|
8
|
-
import { MoveCoder,
|
|
9
|
-
import { SuiAddress, ObjectId, ModuleClient } from "@typemove/sui";
|
|
8
|
+
import { MoveCoder, TypedEventInstance } from "@typemove/sui";
|
|
10
9
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "@mysten/sui.js";
|
|
10
|
+
import { defaultMoveCoder } from "@typemove/sui";
|
|
11
|
+
|
|
12
|
+
import { ZERO_ADDRESS } from "@typemove/sui";
|
|
13
|
+
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
14
|
+
import { ObjectCallArg, TransactionArgument } from "@mysten/sui.js";
|
|
15
|
+
import { SuiClient } from "@mysten/sui.js/client";
|
|
16
16
|
|
|
17
17
|
import { _0x2 } from "@typemove/sui/builtin";
|
|
18
18
|
import { _0x1 } from "@typemove/sui/builtin";
|
|
@@ -30,7 +30,7 @@ export namespace oracle {
|
|
|
30
30
|
const TYPE = new TypeDescriptor<Key<any>>(Key.TYPE_QNAME);
|
|
31
31
|
|
|
32
32
|
export function type<T0>(
|
|
33
|
-
arg0: TypeDescriptor<T0> = ANY_TYPE
|
|
33
|
+
arg0: TypeDescriptor<T0> = ANY_TYPE,
|
|
34
34
|
): TypeDescriptor<Key<T0>> {
|
|
35
35
|
return TYPE.apply(arg0);
|
|
36
36
|
}
|
|
@@ -52,7 +52,7 @@ export namespace oracle {
|
|
|
52
52
|
const TYPE = new TypeDescriptor<Oracle<any>>(Oracle.TYPE_QNAME);
|
|
53
53
|
|
|
54
54
|
export function type<T0>(
|
|
55
|
-
arg0: TypeDescriptor<T0> = ANY_TYPE
|
|
55
|
+
arg0: TypeDescriptor<T0> = ANY_TYPE,
|
|
56
56
|
): TypeDescriptor<Oracle<T0>> {
|
|
57
57
|
return TYPE.apply(arg0);
|
|
58
58
|
}
|
|
@@ -85,20 +85,20 @@ export namespace oracle {
|
|
|
85
85
|
export function copyKey<T0 = any>(
|
|
86
86
|
tx: TransactionBlock,
|
|
87
87
|
args: [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
string | ObjectCallArg | TransactionArgument,
|
|
89
|
+
string | TransactionArgument,
|
|
90
|
+
string | ObjectCallArg | TransactionArgument,
|
|
91
91
|
],
|
|
92
|
-
typeArguments: [TypeDescriptor<T0> | string]
|
|
92
|
+
typeArguments: [TypeDescriptor<T0> | string],
|
|
93
93
|
): TransactionArgument &
|
|
94
94
|
[TransactionArgument, TransactionArgument, TransactionArgument] {
|
|
95
95
|
const _args: any[] = [];
|
|
96
96
|
_args.push(
|
|
97
|
-
TransactionArgument.is(args[0]) ? args[0] : tx.object(args[0])
|
|
97
|
+
TransactionArgument.is(args[0]) ? args[0] : tx.object(args[0]),
|
|
98
98
|
);
|
|
99
99
|
_args.push(TransactionArgument.is(args[1]) ? args[1] : tx.pure(args[1]));
|
|
100
100
|
_args.push(
|
|
101
|
-
TransactionArgument.is(args[2]) ? args[2] : tx.object(args[2])
|
|
101
|
+
TransactionArgument.is(args[2]) ? args[2] : tx.object(args[2]),
|
|
102
102
|
);
|
|
103
103
|
|
|
104
104
|
// @ts-ignore
|
|
@@ -115,12 +115,12 @@ export namespace oracle {
|
|
|
115
115
|
}
|
|
116
116
|
export function getOracle<T0 = any>(
|
|
117
117
|
tx: TransactionBlock,
|
|
118
|
-
args: [
|
|
119
|
-
typeArguments: [TypeDescriptor<T0> | string]
|
|
118
|
+
args: [string | ObjectCallArg | TransactionArgument],
|
|
119
|
+
typeArguments: [TypeDescriptor<T0> | string],
|
|
120
120
|
): TransactionArgument & [TransactionArgument] {
|
|
121
121
|
const _args: any[] = [];
|
|
122
122
|
_args.push(
|
|
123
|
-
TransactionArgument.is(args[0]) ? args[0] : tx.object(args[0])
|
|
123
|
+
TransactionArgument.is(args[0]) ? args[0] : tx.object(args[0]),
|
|
124
124
|
);
|
|
125
125
|
|
|
126
126
|
// @ts-ignore
|
|
@@ -139,14 +139,14 @@ export namespace oracle {
|
|
|
139
139
|
tx: TransactionBlock,
|
|
140
140
|
args: [
|
|
141
141
|
bigint | TransactionArgument,
|
|
142
|
-
|
|
142
|
+
string | ObjectCallArg | TransactionArgument,
|
|
143
143
|
],
|
|
144
|
-
typeArguments: [TypeDescriptor<T0> | string]
|
|
144
|
+
typeArguments: [TypeDescriptor<T0> | string],
|
|
145
145
|
): TransactionArgument & [TransactionArgument, TransactionArgument] {
|
|
146
146
|
const _args: any[] = [];
|
|
147
147
|
_args.push(TransactionArgument.is(args[0]) ? args[0] : tx.pure(args[0]));
|
|
148
148
|
_args.push(
|
|
149
|
-
TransactionArgument.is(args[1]) ? args[1] : tx.object(args[1])
|
|
149
|
+
TransactionArgument.is(args[1]) ? args[1] : tx.object(args[1]),
|
|
150
150
|
);
|
|
151
151
|
|
|
152
152
|
// @ts-ignore
|
|
@@ -164,14 +164,14 @@ export namespace oracle {
|
|
|
164
164
|
export function update<T0 = any>(
|
|
165
165
|
tx: TransactionBlock,
|
|
166
166
|
args: [
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
string | ObjectCallArg | TransactionArgument,
|
|
168
|
+
string | ObjectCallArg | TransactionArgument,
|
|
169
169
|
bigint | TransactionArgument,
|
|
170
170
|
bigint | TransactionArgument,
|
|
171
171
|
bigint | TransactionArgument,
|
|
172
|
-
|
|
172
|
+
string | ObjectCallArg | TransactionArgument,
|
|
173
173
|
],
|
|
174
|
-
typeArguments: [TypeDescriptor<T0> | string]
|
|
174
|
+
typeArguments: [TypeDescriptor<T0> | string],
|
|
175
175
|
): TransactionArgument &
|
|
176
176
|
[
|
|
177
177
|
TransactionArgument,
|
|
@@ -179,20 +179,20 @@ export namespace oracle {
|
|
|
179
179
|
TransactionArgument,
|
|
180
180
|
TransactionArgument,
|
|
181
181
|
TransactionArgument,
|
|
182
|
-
TransactionArgument
|
|
182
|
+
TransactionArgument,
|
|
183
183
|
] {
|
|
184
184
|
const _args: any[] = [];
|
|
185
185
|
_args.push(
|
|
186
|
-
TransactionArgument.is(args[0]) ? args[0] : tx.object(args[0])
|
|
186
|
+
TransactionArgument.is(args[0]) ? args[0] : tx.object(args[0]),
|
|
187
187
|
);
|
|
188
188
|
_args.push(
|
|
189
|
-
TransactionArgument.is(args[1]) ? args[1] : tx.object(args[1])
|
|
189
|
+
TransactionArgument.is(args[1]) ? args[1] : tx.object(args[1]),
|
|
190
190
|
);
|
|
191
191
|
_args.push(TransactionArgument.is(args[2]) ? args[2] : tx.pure(args[2]));
|
|
192
192
|
_args.push(TransactionArgument.is(args[3]) ? args[3] : tx.pure(args[3]));
|
|
193
193
|
_args.push(TransactionArgument.is(args[4]) ? args[4] : tx.pure(args[4]));
|
|
194
194
|
_args.push(
|
|
195
|
-
TransactionArgument.is(args[5]) ? args[5] : tx.object(args[5])
|
|
195
|
+
TransactionArgument.is(args[5]) ? args[5] : tx.object(args[5]),
|
|
196
196
|
);
|
|
197
197
|
|
|
198
198
|
// @ts-ignore
|
|
@@ -208,10 +208,78 @@ export namespace oracle {
|
|
|
208
208
|
});
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
+
export namespace view {
|
|
212
|
+
export async function copyKey<T0 = any>(
|
|
213
|
+
client: SuiClient,
|
|
214
|
+
args: [
|
|
215
|
+
string | ObjectCallArg | TransactionArgument,
|
|
216
|
+
string | TransactionArgument,
|
|
217
|
+
string | ObjectCallArg | TransactionArgument,
|
|
218
|
+
],
|
|
219
|
+
typeArguments: [TypeDescriptor<T0> | string],
|
|
220
|
+
) {
|
|
221
|
+
const tx = new TransactionBlock();
|
|
222
|
+
builder.copyKey(tx, args, typeArguments);
|
|
223
|
+
const res = await client.devInspectTransactionBlock({
|
|
224
|
+
transactionBlock: tx,
|
|
225
|
+
sender: ZERO_ADDRESS,
|
|
226
|
+
});
|
|
227
|
+
return res;
|
|
228
|
+
}
|
|
229
|
+
export async function getOracle<T0 = any>(
|
|
230
|
+
client: SuiClient,
|
|
231
|
+
args: [string | ObjectCallArg | TransactionArgument],
|
|
232
|
+
typeArguments: [TypeDescriptor<T0> | string],
|
|
233
|
+
) {
|
|
234
|
+
const tx = new TransactionBlock();
|
|
235
|
+
builder.getOracle(tx, args, typeArguments);
|
|
236
|
+
const res = await client.devInspectTransactionBlock({
|
|
237
|
+
transactionBlock: tx,
|
|
238
|
+
sender: ZERO_ADDRESS,
|
|
239
|
+
});
|
|
240
|
+
return res;
|
|
241
|
+
}
|
|
242
|
+
export async function newOracle<T0 = any>(
|
|
243
|
+
client: SuiClient,
|
|
244
|
+
args: [
|
|
245
|
+
bigint | TransactionArgument,
|
|
246
|
+
string | ObjectCallArg | TransactionArgument,
|
|
247
|
+
],
|
|
248
|
+
typeArguments: [TypeDescriptor<T0> | string],
|
|
249
|
+
) {
|
|
250
|
+
const tx = new TransactionBlock();
|
|
251
|
+
builder.newOracle(tx, args, typeArguments);
|
|
252
|
+
const res = await client.devInspectTransactionBlock({
|
|
253
|
+
transactionBlock: tx,
|
|
254
|
+
sender: ZERO_ADDRESS,
|
|
255
|
+
});
|
|
256
|
+
return res;
|
|
257
|
+
}
|
|
258
|
+
export async function update<T0 = any>(
|
|
259
|
+
client: SuiClient,
|
|
260
|
+
args: [
|
|
261
|
+
string | ObjectCallArg | TransactionArgument,
|
|
262
|
+
string | ObjectCallArg | TransactionArgument,
|
|
263
|
+
bigint | TransactionArgument,
|
|
264
|
+
bigint | TransactionArgument,
|
|
265
|
+
bigint | TransactionArgument,
|
|
266
|
+
string | ObjectCallArg | TransactionArgument,
|
|
267
|
+
],
|
|
268
|
+
typeArguments: [TypeDescriptor<T0> | string],
|
|
269
|
+
) {
|
|
270
|
+
const tx = new TransactionBlock();
|
|
271
|
+
builder.update(tx, args, typeArguments);
|
|
272
|
+
const res = await client.devInspectTransactionBlock({
|
|
273
|
+
transactionBlock: tx,
|
|
274
|
+
sender: ZERO_ADDRESS,
|
|
275
|
+
});
|
|
276
|
+
return res;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
211
279
|
}
|
|
212
280
|
|
|
213
281
|
const MODULES = JSON.parse(
|
|
214
|
-
'[{"fileFormatVersion":6,"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","name":"oracle","friends":[],"structs":{"Key":{"abilities":{"abilities":["Key"]},"typeParameters":[{"constraints":{"abilities":[]},"isPhantom":true}],"fields":[{"name":"id","type":{"Struct":{"address":"0x2","module":"object","name":"UID","typeArguments":[]}}},{"name":"for","type":{"Struct":{"address":"0x2","module":"object","name":"ID","typeArguments":[]}}}]},"Oracle":{"abilities":{"abilities":["Key"]},"typeParameters":[{"constraints":{"abilities":[]},"isPhantom":true}],"fields":[{"name":"id","type":{"Struct":{"address":"0x2","module":"object","name":"UID","typeArguments":[]}}},{"name":"decimal","type":"U64"},{"name":"price","type":"U64"},{"name":"twap_price_1h","type":"U64"},{"name":"ts_ms","type":"U64"},{"name":"epoch","type":"U64"}]},"PriceEvent":{"abilities":{"abilities":["Copy","Drop"]},"typeParameters":[],"fields":[{"name":"token","type":{"Struct":{"address":"0x1","module":"ascii","name":"String","typeArguments":[]}}},{"name":"price","type":"U64"},{"name":"ts_ms","type":"U64"},{"name":"epoch","type":"U64"}]}},"exposedFunctions":{"copy_key":{"visibility":"Public","isEntry":true,"typeParameters":[{"abilities":[]}],"parameters":[{"Reference":{"Struct":{"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","module":"oracle","name":"Key","typeArguments":[{"TypeParameter":0}]}}},"Address",{"MutableReference":{"Struct":{"address":"0x2","module":"tx_context","name":"TxContext","typeArguments":[]}}}],"return":[]},"get_oracle":{"visibility":"Public","isEntry":false,"typeParameters":[{"abilities":[]}],"parameters":[{"Reference":{"Struct":{"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","module":"oracle","name":"Oracle","typeArguments":[{"TypeParameter":0}]}}}],"return":["U64","U64","U64","U64"]},"new_oracle":{"visibility":"Public","isEntry":true,"typeParameters":[{"abilities":[]}],"parameters":["U64",{"MutableReference":{"Struct":{"address":"0x2","module":"tx_context","name":"TxContext","typeArguments":[]}}}],"return":[]},"update":{"visibility":"Public","isEntry":true,"typeParameters":[{"abilities":[]}],"parameters":[{"MutableReference":{"Struct":{"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","module":"oracle","name":"Oracle","typeArguments":[{"TypeParameter":0}]}}},{"Reference":{"Struct":{"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","module":"oracle","name":"Key","typeArguments":[{"TypeParameter":0}]}}},"U64","U64","U64",{"MutableReference":{"Struct":{"address":"0x2","module":"tx_context","name":"TxContext","typeArguments":[]}}}],"return":[]}}}]'
|
|
282
|
+
'[{"fileFormatVersion":6,"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","name":"oracle","friends":[],"structs":{"Key":{"abilities":{"abilities":["Key"]},"typeParameters":[{"constraints":{"abilities":[]},"isPhantom":true}],"fields":[{"name":"id","type":{"Struct":{"address":"0x2","module":"object","name":"UID","typeArguments":[]}}},{"name":"for","type":{"Struct":{"address":"0x2","module":"object","name":"ID","typeArguments":[]}}}]},"Oracle":{"abilities":{"abilities":["Key"]},"typeParameters":[{"constraints":{"abilities":[]},"isPhantom":true}],"fields":[{"name":"id","type":{"Struct":{"address":"0x2","module":"object","name":"UID","typeArguments":[]}}},{"name":"decimal","type":"U64"},{"name":"price","type":"U64"},{"name":"twap_price_1h","type":"U64"},{"name":"ts_ms","type":"U64"},{"name":"epoch","type":"U64"}]},"PriceEvent":{"abilities":{"abilities":["Copy","Drop"]},"typeParameters":[],"fields":[{"name":"token","type":{"Struct":{"address":"0x1","module":"ascii","name":"String","typeArguments":[]}}},{"name":"price","type":"U64"},{"name":"ts_ms","type":"U64"},{"name":"epoch","type":"U64"}]}},"exposedFunctions":{"copy_key":{"visibility":"Public","isEntry":true,"typeParameters":[{"abilities":[]}],"parameters":[{"Reference":{"Struct":{"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","module":"oracle","name":"Key","typeArguments":[{"TypeParameter":0}]}}},"Address",{"MutableReference":{"Struct":{"address":"0x2","module":"tx_context","name":"TxContext","typeArguments":[]}}}],"return":[]},"get_oracle":{"visibility":"Public","isEntry":false,"typeParameters":[{"abilities":[]}],"parameters":[{"Reference":{"Struct":{"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","module":"oracle","name":"Oracle","typeArguments":[{"TypeParameter":0}]}}}],"return":["U64","U64","U64","U64"]},"new_oracle":{"visibility":"Public","isEntry":true,"typeParameters":[{"abilities":[]}],"parameters":["U64",{"MutableReference":{"Struct":{"address":"0x2","module":"tx_context","name":"TxContext","typeArguments":[]}}}],"return":[]},"update":{"visibility":"Public","isEntry":true,"typeParameters":[{"abilities":[]}],"parameters":[{"MutableReference":{"Struct":{"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","module":"oracle","name":"Oracle","typeArguments":[{"TypeParameter":0}]}}},{"Reference":{"Struct":{"address":"0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5","module":"oracle","name":"Key","typeArguments":[{"TypeParameter":0}]}}},"U64","U64","U64",{"MutableReference":{"Struct":{"address":"0x2","module":"tx_context","name":"TxContext","typeArguments":[]}}}],"return":[]}}}]',
|
|
215
283
|
);
|
|
216
284
|
|
|
217
285
|
export function loadAllTypes(coder: MoveCoder) {
|