@sentio/sdk 2.5.5 → 2.6.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/eth/eth.js +3 -1
- package/lib/eth/eth.js.map +1 -1
- package/lib/eth/provider.js +9 -5
- package/lib/eth/provider.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +2 -0
- package/lib/move/abstract-codegen.js +71 -6
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.js +0 -2
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/index.d.ts +0 -1
- package/lib/move/index.js +0 -1
- package/lib/move/index.js.map +1 -1
- package/lib/move/utils.d.ts +2 -0
- package/lib/move/utils.js +3 -0
- package/lib/move/utils.js.map +1 -1
- package/lib/sui/builtin/0x1.d.ts +1 -14
- package/lib/sui/builtin/0x1.js +0 -25
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +26 -43
- package/lib/sui/builtin/0x2.js +1 -29
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/codegen/codegen.js +21 -1
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/move-coder.d.ts +1 -0
- package/lib/sui/move-coder.js +11 -0
- package/lib/sui/move-coder.js.map +1 -1
- package/package.json +4 -4
- package/src/eth/eth.ts +5 -1
- package/src/eth/provider.ts +9 -6
- package/src/move/abstract-codegen.ts +80 -6
- package/src/move/abstract-move-coder.ts +0 -2
- package/src/move/index.ts +0 -1
- package/src/move/utils.ts +6 -0
- package/src/sui/builtin/0x1.ts +1 -37
- package/src/sui/builtin/0x2.ts +27 -66
- package/src/sui/codegen/codegen.ts +23 -1
- package/src/sui/move-coder.ts +12 -0
- package/lib/move/ts-type.d.ts +0 -2
- package/lib/move/ts-type.js +0 -77
- package/lib/move/ts-type.js.map +0 -1
- package/src/move/ts-type.ts +0 -86
@@ -4,7 +4,7 @@ import chalk from 'chalk';
|
|
4
4
|
import { AbstractCodegen } from '../../move/abstract-codegen.js';
|
5
5
|
import { JsonRpcProvider } from '@mysten/sui.js';
|
6
6
|
import { toInternalModule } from '../move-types.js';
|
7
|
-
import { moduleQname, SPLITTER } from '../../move/index.js';
|
7
|
+
import { moduleQname, SPLITTER, structQname } from '../../move/index.js';
|
8
8
|
import { getMeaningfulFunctionParams } from '../utils.js';
|
9
9
|
export async function codegen(abisDir, outDir = 'src/types/sui') {
|
10
10
|
if (!fs.existsSync(abisDir)) {
|
@@ -58,5 +58,25 @@ class SuiCodegen extends AbstractCodegen {
|
|
58
58
|
}
|
59
59
|
return res;
|
60
60
|
}
|
61
|
+
generateStructs(module, struct, events) {
|
62
|
+
switch (structQname(module, struct)) {
|
63
|
+
case '0x2::object::ID':
|
64
|
+
return `export type ${struct.name} = string`;
|
65
|
+
case '0x2::coin::Coin':
|
66
|
+
return `export type ${struct.name}<T> = string`;
|
67
|
+
case '0x1::option::Option':
|
68
|
+
return `export type Option<T> = T | undefined`;
|
69
|
+
}
|
70
|
+
return super.generateStructs(module, struct, events);
|
71
|
+
}
|
72
|
+
generateOnEvents(module, struct) {
|
73
|
+
switch (structQname(module, struct)) {
|
74
|
+
case '0x2::object::ID':
|
75
|
+
case '0x2::coin::Coin':
|
76
|
+
case '0x1::option::Option':
|
77
|
+
return '';
|
78
|
+
}
|
79
|
+
return super.generateOnEvents(module, struct);
|
80
|
+
}
|
61
81
|
}
|
62
82
|
//# sourceMappingURL=codegen.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/sui/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,EAAE,eAAe,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AA;QAC3C,IAAI,GAAG,CAAC,MAAM,EAAE;YACd,OAAO,GAAG,CAAC,MAAM,CAAA;SAClB;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;IAED,eAAe,CAAC,MAA0B,EAAE,MAA0B,EAAE,MAAmB;QACzF,QAAQ,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;YACnC,KAAK,iBAAiB;gBACpB,OAAO,eAAe,MAAM,CAAC,IAAI,WAAW,CAAA;YAC9C,KAAK,iBAAiB;gBACpB,OAAO,eAAe,MAAM,CAAC,IAAI,cAAc,CAAA;YACjD,KAAK,qBAAqB;gBACxB,OAAO,uCAAuC,CAAA;SACjD;QACD,OAAO,KAAK,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IACtD,CAAC;IAED,gBAAgB,CAAC,MAA0B,EAAE,MAA0B;QACrE,QAAQ,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;YACnC,KAAK,iBAAiB,CAAC;YACvB,KAAK,iBAAiB,CAAC;YACvB,KAAK,qBAAqB;gBACxB,OAAO,EAAE,CAAA;SACZ;QACD,OAAO,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/C,CAAC;CACF","sourcesContent":["import { SuiNetwork } from '../network.js'\nimport * as fs from 'fs'\nimport chalk from 'chalk'\nimport { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'\nimport { AbstractCodegen } from '../../move/abstract-codegen.js'\nimport { JsonRpcProvider, SuiMoveNormalizedModules } from '@mysten/sui.js'\nimport { toInternalModule } from '../move-types.js'\nimport { moduleQname, SPLITTER, structQname, TypeDescriptor } from '../../move/index.js'\nimport { getMeaningfulFunctionParams } from '../utils.js'\n\nexport async function codegen(abisDir: string, outDir = 'src/types/sui') {\n if (!fs.existsSync(abisDir)) {\n return\n }\n console.log(chalk.green('Generated Types for Sui'))\n const gen = new SuiCodegen()\n await gen.generate(abisDir, outDir)\n}\n\nfunction getRpcEndpoint(network: SuiNetwork): string {\n switch (network) {\n case SuiNetwork.TEST_NET:\n return 'https://fullnode.testnet.sui.io/'\n }\n return 'https://fullnode.mainnet.sui.io/'\n}\n\nfunction getRpcClient(network: SuiNetwork): JsonRpcProvider {\n return new JsonRpcProvider(getRpcEndpoint(network))\n}\n\nclass SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {\n ADDRESS_TYPE = 'SuiAddress'\n MAIN_NET = SuiNetwork.MAIN_NET\n TEST_NET = SuiNetwork.TEST_NET\n PREFIX = 'Sui'\n STRUCT_FIELD_NAME = 'fields'\n\n async fetchModules(account: string, network: SuiNetwork): Promise<SuiMoveNormalizedModules> {\n const client = getRpcClient(network)\n return await client.getNormalizedMoveModulesByPackage(account)\n }\n\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return getMeaningfulFunctionParams(params)\n }\n\n toInternalModules(modules: SuiMoveNormalizedModules): InternalMoveModule[] {\n return Object.values(modules).map(toInternalModule)\n }\n\n getEventStructs(module: InternalMoveModule) {\n const qname = moduleQname(module)\n const eventMap = new Map<string, InternalMoveStruct>()\n\n for (const struct of module.structs) {\n const abilities = new Set(struct.abilities)\n if (abilities.has('Drop') && abilities.has('Copy')) {\n eventMap.set(qname + SPLITTER + struct.name, struct)\n }\n }\n return eventMap\n }\n\n readModulesFile(fullPath: string) {\n const res = super.readModulesFile(fullPath)\n if (res.result) {\n return res.result\n }\n return res\n }\n\n generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>): string {\n switch (structQname(module, struct)) {\n case '0x2::object::ID':\n return `export type ${struct.name} = string`\n case '0x2::coin::Coin':\n return `export type ${struct.name}<T> = string`\n case '0x1::option::Option':\n return `export type Option<T> = T | undefined`\n }\n return super.generateStructs(module, struct, events)\n }\n\n generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {\n switch (structQname(module, struct)) {\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n case '0x1::option::Option':\n return ''\n }\n return super.generateOnEvents(module, struct)\n }\n}\n"]}
|
package/lib/sui/move-coder.d.ts
CHANGED
@@ -4,6 +4,7 @@ import { MoveCall, MoveEvent, SuiMoveNormalizedModule } from '@mysten/sui.js';
|
|
4
4
|
import { TypeDescriptor } from '../move/index.js';
|
5
5
|
export declare class MoveCoder extends AbstractMoveCoder<MoveEvent> {
|
6
6
|
load(module: SuiMoveNormalizedModule): void;
|
7
|
+
decode(data: any, type: TypeDescriptor): any;
|
7
8
|
decodeEvent<T>(event: MoveEvent): TypedEventInstance<T> | undefined;
|
8
9
|
filterAndDecodeEvents<T>(typeQname: string, resources: MoveEvent[]): TypedEventInstance<T>[];
|
9
10
|
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[];
|
package/lib/sui/move-coder.js
CHANGED
@@ -9,6 +9,17 @@ export class MoveCoder extends AbstractMoveCoder {
|
|
9
9
|
}
|
10
10
|
this.loadInternal(toInternalModule(module));
|
11
11
|
}
|
12
|
+
decode(data, type) {
|
13
|
+
switch (type.qname) {
|
14
|
+
case '0x2::object::ID':
|
15
|
+
case '0x2::coin::Coin':
|
16
|
+
return data;
|
17
|
+
case '0x1::option::Option':
|
18
|
+
return this.decode(data, type.typeArgs[0]);
|
19
|
+
default:
|
20
|
+
return super.decode(data, type);
|
21
|
+
}
|
22
|
+
}
|
12
23
|
decodeEvent(event) {
|
13
24
|
const res = this.decodedInternal({ ...event, data: event.fields });
|
14
25
|
return { ...event, fields_decoded: res?.data_decoded, type_arguments: res?.type_arguments || [] };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/sui/move-coder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AAC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MAAM,CAAC,CAAA;IAC5C,CAAC;IAED,qBAAqB,CAAC,OAAiB;QACrC,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAChG,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAA;QAC/C,MAAM,MAAM,GAAG,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACvD,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,EAAE,MAAM,CAAC,CAAA;QACxE,OAAO;YACL,GAAG,OAAO;YACV,iBAAiB,EAAE,cAAc;SACL,CAAA;IAChC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAA;AAEzC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import { TypedEventInstance, TypedFunctionPayload } from './models.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\nimport { MoveCall, MoveEvent, SuiMoveNormalizedModule } from '@mysten/sui.js'\nimport { toInternalModule } from './move-types.js'\nimport { SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { getMeaningfulFunctionParams } from './utils.js'\n\nexport class MoveCoder extends AbstractMoveCoder<MoveEvent> {\n load(module: SuiMoveNormalizedModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.loadInternal(toInternalModule(module))\n }\n\n decodeEvent<T>(event: MoveEvent): TypedEventInstance<T> | undefined {\n const res = this.decodedInternal<T>({ ...event, data: event.fields })\n return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: MoveEvent[]): TypedEventInstance<T>[] {\n const resp = this.filterAndDecodeInternal(\n typeQname,\n resources.map((event) => {\n return { ...event, data: event.fields, type: event.type }\n })\n )\n return resp.map((res) => {\n delete res.data_decoded\n const event = res as MoveEvent\n return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }\n })\n }\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return getMeaningfulFunctionParams(params)\n }\n\n decodeFunctionPayload(payload: MoveCall): MoveCall {\n const functionType = [payload.package.objectId, payload.module, payload.function].join(SPLITTER)\n const func = this.getMoveFunction(functionType)\n const params = getMeaningfulFunctionParams(func.params)\n const argumentsTyped = this.decodeArray(payload.arguments || [], params)\n return {\n ...payload,\n arguments_decoded: argumentsTyped,\n } as TypedFunctionPayload<any>\n }\n}\n\nexport const MOVE_CODER = new MoveCoder()\n\nexport function defaultMoveCoder(): MoveCoder {\n return MOVE_CODER\n}\n"]}
|
1
|
+
{"version":3,"file":"move-coder.js","sourceRoot":"","sources":["../../src/sui/move-coder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAkB,MAAM,kBAAkB,CAAA;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAExD,MAAM,OAAO,SAAU,SAAQ,iBAA4B;IACzD,IAAI,CAAC,MAA+B;QAClC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE;YAC9C,OAAM;SACP;QACD,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAA;IAC7C,CAAC;IAED,MAAM,CAAC,IAAS,EAAE,IAAoB;QACpC,QAAQ,IAAI,CAAC,KAAK,EAAE;YAClB,KAAK,iBAAiB,CAAC;YACvB,KAAK,iBAAiB;gBACpB,OAAO,IAAI,CAAA;YACb,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OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAChG,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,CAAA;QAC/C,MAAM,MAAM,GAAG,2BAA2B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACvD,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,IAAI,EAAE,EAAE,MAAM,CAAC,CAAA;QACxE,OAAO;YACL,GAAG,OAAO;YACV,iBAAiB,EAAE,cAAc;SACL,CAAA;IAChC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,SAAS,EAAE,CAAA;AAEzC,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import { TypedEventInstance, TypedFunctionPayload } from './models.js'\nimport { AbstractMoveCoder } from '../move/abstract-move-coder.js'\nimport { MoveCall, MoveEvent, SuiMoveNormalizedModule } from '@mysten/sui.js'\nimport { toInternalModule } from './move-types.js'\nimport { SPLITTER, TypeDescriptor } from '../move/index.js'\nimport { getMeaningfulFunctionParams } from './utils.js'\n\nexport class MoveCoder extends AbstractMoveCoder<MoveEvent> {\n load(module: SuiMoveNormalizedModule) {\n if (this.contains(module.address, module.name)) {\n return\n }\n this.loadInternal(toInternalModule(module))\n }\n\n decode(data: any, type: TypeDescriptor): any {\n switch (type.qname) {\n case '0x2::object::ID':\n case '0x2::coin::Coin':\n return data\n case '0x1::option::Option':\n return this.decode(data, type.typeArgs[0])\n default:\n return super.decode(data, type)\n }\n }\n\n decodeEvent<T>(event: MoveEvent): TypedEventInstance<T> | undefined {\n const res = this.decodedInternal<T>({ ...event, data: event.fields })\n return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }\n }\n filterAndDecodeEvents<T>(typeQname: string, resources: MoveEvent[]): TypedEventInstance<T>[] {\n const resp = this.filterAndDecodeInternal(\n typeQname,\n resources.map((event) => {\n return { ...event, data: event.fields, type: event.type }\n })\n )\n return resp.map((res) => {\n delete res.data_decoded\n const event = res as MoveEvent\n return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }\n })\n }\n getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {\n return getMeaningfulFunctionParams(params)\n }\n\n decodeFunctionPayload(payload: MoveCall): MoveCall {\n const functionType = [payload.package.objectId, payload.module, payload.function].join(SPLITTER)\n const func = this.getMoveFunction(functionType)\n const params = getMeaningfulFunctionParams(func.params)\n const argumentsTyped = this.decodeArray(payload.arguments || [], params)\n return {\n ...payload,\n arguments_decoded: argumentsTyped,\n } as TypedFunctionPayload<any>\n }\n}\n\nexport const MOVE_CODER = new MoveCoder()\n\nexport function defaultMoveCoder(): MoveCoder {\n return MOVE_CODER\n}\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
3
|
"license": "Apache-2.0",
|
4
|
-
"version": "2.
|
4
|
+
"version": "2.6.0-rc.2",
|
5
5
|
"type": "module",
|
6
6
|
"scripts": {
|
7
7
|
"compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
|
@@ -23,8 +23,8 @@
|
|
23
23
|
"@project-serum/anchor": "^0.26.0",
|
24
24
|
"@sentio/bigdecimal": "^9.1.1-patch.3",
|
25
25
|
"@sentio/ethers-v6": "^1.0.25",
|
26
|
-
"@sentio/protos": "^2.
|
27
|
-
"@sentio/runtime": "^2.
|
26
|
+
"@sentio/protos": "^2.6.0-rc.2",
|
27
|
+
"@sentio/runtime": "^2.6.0-rc.2",
|
28
28
|
"@solana/web3.js": "^1.73.2",
|
29
29
|
"@types/prettier": "^2.7.2",
|
30
30
|
"aptos-sdk": "npm:@sentio/aptos@^1.6.0",
|
@@ -78,5 +78,5 @@
|
|
78
78
|
"engines": {
|
79
79
|
"node": ">=16"
|
80
80
|
},
|
81
|
-
"gitHead": "
|
81
|
+
"gitHead": "80a22e106432ebcd65371bda09d36d0c3b11f2e4"
|
82
82
|
}
|
package/src/eth/eth.ts
CHANGED
@@ -51,6 +51,9 @@ export function transformEtherError(e: Error, ctx: ContractContext<any, any> | u
|
|
51
51
|
return e
|
52
52
|
}
|
53
53
|
|
54
|
+
const checkPage =
|
55
|
+
'Check here for possible cause and fix: https://docs.sentio.xyz/best-practices/handling-errors#ethers-error'
|
56
|
+
|
54
57
|
let msg = ''
|
55
58
|
const err = e as CallExceptionError
|
56
59
|
if (err.code === 'CALL_EXCEPTION') {
|
@@ -64,11 +67,12 @@ export function transformEtherError(e: Error, ctx: ContractContext<any, any> | u
|
|
64
67
|
} else {
|
65
68
|
msg = "jsonrpc eth_call return '0x' (likely contract not existed): " + JSON.stringify(err)
|
66
69
|
}
|
70
|
+
msg += '\n' + checkPage
|
67
71
|
return new SimpleEthersError(msg, err)
|
68
72
|
}
|
69
73
|
}
|
70
74
|
|
71
|
-
msg = 'ethers call error\n' + JSON.stringify(e) + '\n' + e.stack?.toString()
|
75
|
+
msg = 'ethers call error\n' + JSON.stringify(e) + '\n' + e.stack?.toString() + '\n' + checkPage
|
72
76
|
return new Error(msg)
|
73
77
|
}
|
74
78
|
|
package/src/eth/provider.ts
CHANGED
@@ -84,16 +84,19 @@ class QueuedStaticJsonRpcProvider extends JsonRpcProvider {
|
|
84
84
|
|
85
85
|
async send(method: string, params: Array<any>): Promise<any> {
|
86
86
|
const tag = getTag(method, params)
|
87
|
+
const block = params[params.length - 1]
|
87
88
|
let perform = this.#performCache.get(tag)
|
88
89
|
if (!perform) {
|
89
90
|
perform = this.executor.add(() => super.send(method, params))
|
90
91
|
this.#performCache.set(tag, perform)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
this.#performCache.
|
95
|
-
|
96
|
-
|
92
|
+
// For non latest block call, we cache permanently, otherwise we cache for one minute
|
93
|
+
if (block === 'latest') {
|
94
|
+
setTimeout(() => {
|
95
|
+
if (this.#performCache.get(tag) === perform) {
|
96
|
+
this.#performCache.delete(tag)
|
97
|
+
}
|
98
|
+
}, 60 * 1000)
|
99
|
+
}
|
97
100
|
}
|
98
101
|
|
99
102
|
const result = await perform
|
@@ -9,8 +9,7 @@ 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 } from './utils.js'
|
13
|
-
import { generateTypeForDescriptor } from './ts-type.js'
|
12
|
+
import { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER, VECTOR_STR } from './utils.js'
|
14
13
|
import { camelCase, upperFirst } from 'lodash-es'
|
15
14
|
import { TypeDescriptor } from './types.js'
|
16
15
|
|
@@ -219,7 +218,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
219
218
|
const structName = normalizeToJSName(struct.name)
|
220
219
|
|
221
220
|
const fields = struct.fields.map((field) => {
|
222
|
-
const type = generateTypeForDescriptor(field.type, module.address
|
221
|
+
const type = this.generateTypeForDescriptor(field.type, module.address)
|
223
222
|
return `${field.name}: ${type}`
|
224
223
|
})
|
225
224
|
|
@@ -277,7 +276,7 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
277
276
|
}
|
278
277
|
|
279
278
|
const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {
|
280
|
-
return generateTypeForDescriptor(param, module.address
|
279
|
+
return this.generateTypeForDescriptor(param, module.address)
|
281
280
|
})
|
282
281
|
|
283
282
|
const camelFuncName = upperFirst(camelCase(func.name))
|
@@ -302,12 +301,12 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
302
301
|
// const moduleName = normalizeToJSName(module.name)
|
303
302
|
const funcName = camelCase(func.name)
|
304
303
|
const fields = this.getMeaningfulFunctionParams(func.params).map((param) => {
|
305
|
-
return generateTypeForDescriptor(param, module.address
|
304
|
+
return this.generateTypeForDescriptor(param, module.address)
|
306
305
|
})
|
307
306
|
const genericString = this.generateFunctionTypeParameters(func)
|
308
307
|
|
309
308
|
const returns = func.return.map((param) => {
|
310
|
-
return generateTypeForDescriptor(param, module.address
|
309
|
+
return this.generateTypeForDescriptor(param, module.address)
|
311
310
|
})
|
312
311
|
|
313
312
|
const source = `
|
@@ -363,6 +362,81 @@ export abstract class AbstractCodegen<ModuleTypes, NetworkType> {
|
|
363
362
|
`
|
364
363
|
return source
|
365
364
|
}
|
365
|
+
|
366
|
+
generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string {
|
367
|
+
if (type.reference) {
|
368
|
+
return this.ADDRESS_TYPE
|
369
|
+
}
|
370
|
+
|
371
|
+
switch (type.qname) {
|
372
|
+
case 'signer': // TODO check this
|
373
|
+
case 'address':
|
374
|
+
case 'Address':
|
375
|
+
return this.ADDRESS_TYPE
|
376
|
+
case '0x1::string::String':
|
377
|
+
return 'string'
|
378
|
+
case 'bool':
|
379
|
+
case 'Bool':
|
380
|
+
return 'Boolean'
|
381
|
+
case 'u8':
|
382
|
+
case 'U8':
|
383
|
+
case 'u16':
|
384
|
+
case 'U16':
|
385
|
+
case 'u32':
|
386
|
+
case 'U32':
|
387
|
+
return 'number'
|
388
|
+
case 'u64':
|
389
|
+
case 'U64':
|
390
|
+
case 'u128':
|
391
|
+
case 'U128':
|
392
|
+
case 'u256':
|
393
|
+
case 'U256':
|
394
|
+
return 'bigint'
|
395
|
+
}
|
396
|
+
|
397
|
+
if (type.qname.toLowerCase() === VECTOR_STR) {
|
398
|
+
// vector<u8> as hex string
|
399
|
+
const elementTypeQname = type.typeArgs[0].qname
|
400
|
+
if (elementTypeQname === 'u8' || elementTypeQname === 'U8') {
|
401
|
+
return 'string'
|
402
|
+
}
|
403
|
+
if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {
|
404
|
+
return `${elementTypeQname}[] | string`
|
405
|
+
}
|
406
|
+
return this.generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]'
|
407
|
+
}
|
408
|
+
|
409
|
+
const simpleName = this.generateSimpleType(type.qname, currentAddress)
|
410
|
+
if (simpleName.length === 0) {
|
411
|
+
console.error('unexpected error')
|
412
|
+
}
|
413
|
+
if (simpleName.toLowerCase() === VECTOR_STR || simpleName.toLowerCase().startsWith(VECTOR_STR + SPLITTER)) {
|
414
|
+
console.error('unexpected vector type error')
|
415
|
+
}
|
416
|
+
if (type.typeArgs.length > 0) {
|
417
|
+
// return simpleName
|
418
|
+
return (
|
419
|
+
simpleName + '<' + type.typeArgs.map((t) => this.generateTypeForDescriptor(t, currentAddress)).join(',') + '>'
|
420
|
+
)
|
421
|
+
}
|
422
|
+
return simpleName
|
423
|
+
}
|
424
|
+
|
425
|
+
generateSimpleType(type: string, currentAddress: string): string {
|
426
|
+
const parts = type.split(SPLITTER)
|
427
|
+
|
428
|
+
for (let i = 0; i < parts.length; i++) {
|
429
|
+
parts[i] = normalizeToJSName(parts[i])
|
430
|
+
}
|
431
|
+
|
432
|
+
if (parts.length < 2) {
|
433
|
+
return parts[0]
|
434
|
+
}
|
435
|
+
if (parts[0] === currentAddress) {
|
436
|
+
return parts.slice(1).join('.')
|
437
|
+
}
|
438
|
+
return '_' + parts.join('.')
|
439
|
+
}
|
366
440
|
}
|
367
441
|
|
368
442
|
export class AccountCodegen<ModuleType, NetworkType> {
|
package/src/move/index.ts
CHANGED
package/src/move/utils.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'
|
2
|
+
|
1
3
|
export const SPLITTER = '::'
|
2
4
|
|
3
5
|
export const VECTOR_STR = 'vector'
|
@@ -23,3 +25,7 @@ export function moduleQnameForType(type: string): [string, string] {
|
|
23
25
|
export function moduleQname(module: { address: string; name: string }): string {
|
24
26
|
return module.address.toLowerCase() + SPLITTER + module.name
|
25
27
|
}
|
28
|
+
|
29
|
+
export function structQname(module: InternalMoveModule, struct: InternalMoveStruct): string {
|
30
|
+
return [module.address, module.name, struct.name].join(SPLITTER)
|
31
|
+
}
|
package/src/sui/builtin/0x1.ts
CHANGED
@@ -172,44 +172,8 @@ export namespace fixed_point32 {
|
|
172
172
|
|
173
173
|
export namespace hash {}
|
174
174
|
|
175
|
-
export class option extends SuiBaseProcessor {
|
176
|
-
constructor(options: SuiBindOptions) {
|
177
|
-
super("option", options);
|
178
|
-
}
|
179
|
-
static DEFAULT_OPTIONS: SuiBindOptions = {
|
180
|
-
address: "0x1",
|
181
|
-
network: SuiNetwork.MAIN_NET,
|
182
|
-
};
|
183
|
-
|
184
|
-
static bind(options: Partial<SuiBindOptions> = {}): option {
|
185
|
-
return new option({ ...option.DEFAULT_OPTIONS, ...options });
|
186
|
-
}
|
187
|
-
|
188
|
-
onEventOption(
|
189
|
-
func: (event: option.OptionInstance, ctx: SuiContext) => void,
|
190
|
-
fetchConfig?: MoveFetchConfig
|
191
|
-
): option {
|
192
|
-
this.onMoveEvent(
|
193
|
-
func,
|
194
|
-
{
|
195
|
-
type: "option::Option",
|
196
|
-
},
|
197
|
-
fetchConfig
|
198
|
-
);
|
199
|
-
return this;
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
175
|
export namespace option {
|
204
|
-
export
|
205
|
-
static TYPE_QNAME = "0x1::option::Option";
|
206
|
-
vec: T0[] | string;
|
207
|
-
}
|
208
|
-
|
209
|
-
export interface OptionInstance extends TypedEventInstance<Option<any>> {
|
210
|
-
fields_decoded: Option<any>;
|
211
|
-
type_arguments: [string];
|
212
|
-
}
|
176
|
+
export type Option<T> = T | undefined;
|
213
177
|
}
|
214
178
|
|
215
179
|
export class string_ extends SuiBaseProcessor {
|
package/src/sui/builtin/0x2.ts
CHANGED
@@ -227,11 +227,7 @@ export class coin extends SuiBaseProcessor {
|
|
227
227
|
}
|
228
228
|
|
229
229
|
export namespace coin {
|
230
|
-
export
|
231
|
-
static TYPE_QNAME = "0x2::coin::Coin";
|
232
|
-
id: object_.UID;
|
233
|
-
balance: balance.Balance<T0>;
|
234
|
-
}
|
230
|
+
export type Coin<T> = string;
|
235
231
|
|
236
232
|
export class CoinMetadata<T0> {
|
237
233
|
static TYPE_QNAME = "0x2::coin::CoinMetadata";
|
@@ -390,7 +386,7 @@ export namespace devnet_nft {
|
|
390
386
|
|
391
387
|
export class MintNFTEvent {
|
392
388
|
static TYPE_QNAME = "0x2::devnet_nft::MintNFTEvent";
|
393
|
-
object_id:
|
389
|
+
object_id: object_.ID;
|
394
390
|
creator: SuiAddress;
|
395
391
|
name: string;
|
396
392
|
}
|
@@ -838,8 +834,8 @@ export namespace locked_coin {
|
|
838
834
|
}
|
839
835
|
|
840
836
|
export interface LockCoinPayload<T0 = any>
|
841
|
-
extends TypedFunctionPayload<[
|
842
|
-
arguments_decoded: [
|
837
|
+
extends TypedFunctionPayload<[coin.Coin<T0>, SuiAddress, bigint]> {
|
838
|
+
arguments_decoded: [coin.Coin<T0>, SuiAddress, bigint];
|
843
839
|
type_arguments: [string];
|
844
840
|
}
|
845
841
|
|
@@ -852,48 +848,12 @@ export namespace locked_coin {
|
|
852
848
|
|
853
849
|
export namespace math {}
|
854
850
|
|
855
|
-
export class object_ extends SuiBaseProcessor {
|
856
|
-
constructor(options: SuiBindOptions) {
|
857
|
-
super("object", options);
|
858
|
-
}
|
859
|
-
static DEFAULT_OPTIONS: SuiBindOptions = {
|
860
|
-
address: "0x2",
|
861
|
-
network: SuiNetwork.MAIN_NET,
|
862
|
-
};
|
863
|
-
|
864
|
-
static bind(options: Partial<SuiBindOptions> = {}): object_ {
|
865
|
-
return new object_({ ...object_.DEFAULT_OPTIONS, ...options });
|
866
|
-
}
|
867
|
-
|
868
|
-
onEventID(
|
869
|
-
func: (event: object_.IDInstance, ctx: SuiContext) => void,
|
870
|
-
fetchConfig?: MoveFetchConfig
|
871
|
-
): object_ {
|
872
|
-
this.onMoveEvent(
|
873
|
-
func,
|
874
|
-
{
|
875
|
-
type: "object::ID",
|
876
|
-
},
|
877
|
-
fetchConfig
|
878
|
-
);
|
879
|
-
return this;
|
880
|
-
}
|
881
|
-
}
|
882
|
-
|
883
851
|
export namespace object_ {
|
884
|
-
export
|
885
|
-
static TYPE_QNAME = "0x2::object::ID";
|
886
|
-
bytes: SuiAddress;
|
887
|
-
}
|
888
|
-
|
889
|
-
export interface IDInstance extends TypedEventInstance<ID> {
|
890
|
-
fields_decoded: ID;
|
891
|
-
type_arguments: [];
|
892
|
-
}
|
852
|
+
export type ID = string;
|
893
853
|
|
894
854
|
export class UID {
|
895
855
|
static TYPE_QNAME = "0x2::object::UID";
|
896
|
-
id:
|
856
|
+
id: object_.ID;
|
897
857
|
}
|
898
858
|
}
|
899
859
|
|
@@ -1059,8 +1019,8 @@ export namespace pay {
|
|
1059
1019
|
}
|
1060
1020
|
|
1061
1021
|
export interface JoinVecAndTransferPayload<T0 = any>
|
1062
|
-
extends TypedFunctionPayload<[
|
1063
|
-
arguments_decoded: [
|
1022
|
+
extends TypedFunctionPayload<[coin.Coin<T0>[]]> {
|
1023
|
+
arguments_decoded: [coin.Coin<T0>[]];
|
1064
1024
|
type_arguments: [string];
|
1065
1025
|
}
|
1066
1026
|
|
@@ -1222,26 +1182,26 @@ export namespace safe {
|
|
1222
1182
|
export class OwnerCapability<T0> {
|
1223
1183
|
static TYPE_QNAME = "0x2::safe::OwnerCapability";
|
1224
1184
|
id: object_.UID;
|
1225
|
-
safe_id:
|
1185
|
+
safe_id: object_.ID;
|
1226
1186
|
}
|
1227
1187
|
|
1228
1188
|
export class Safe<T0> {
|
1229
1189
|
static TYPE_QNAME = "0x2::safe::Safe";
|
1230
1190
|
id: object_.UID;
|
1231
1191
|
balance: balance.Balance<T0>;
|
1232
|
-
allowed_safes: vec_set.VecSet<
|
1192
|
+
allowed_safes: vec_set.VecSet<object_.ID>;
|
1233
1193
|
}
|
1234
1194
|
|
1235
1195
|
export class TransferCapability<T0> {
|
1236
1196
|
static TYPE_QNAME = "0x2::safe::TransferCapability";
|
1237
1197
|
id: object_.UID;
|
1238
|
-
safe_id:
|
1198
|
+
safe_id: object_.ID;
|
1239
1199
|
amount: bigint;
|
1240
1200
|
}
|
1241
1201
|
|
1242
1202
|
export interface CreatePayload<T0 = any>
|
1243
|
-
extends TypedFunctionPayload<[
|
1244
|
-
arguments_decoded: [
|
1203
|
+
extends TypedFunctionPayload<[coin.Coin<T0>]> {
|
1204
|
+
arguments_decoded: [coin.Coin<T0>];
|
1245
1205
|
type_arguments: [string];
|
1246
1206
|
}
|
1247
1207
|
|
@@ -1421,7 +1381,7 @@ export namespace staking_pool {
|
|
1421
1381
|
export class Delegation {
|
1422
1382
|
static TYPE_QNAME = "0x2::staking_pool::Delegation";
|
1423
1383
|
id: object_.UID;
|
1424
|
-
staked_sui_id:
|
1384
|
+
staked_sui_id: object_.ID;
|
1425
1385
|
pool_tokens: balance.Balance<staking_pool.DelegationToken>;
|
1426
1386
|
principal_sui_amount: bigint;
|
1427
1387
|
}
|
@@ -1480,7 +1440,7 @@ export namespace staking_pool {
|
|
1480
1440
|
rewards_pool: balance.Balance<sui.SUI>;
|
1481
1441
|
delegation_token_supply: balance.Supply<staking_pool.DelegationToken>;
|
1482
1442
|
pending_delegations: linked_table.LinkedTable<
|
1483
|
-
|
1443
|
+
object_.ID,
|
1484
1444
|
staking_pool.PendingDelegationEntry
|
1485
1445
|
>;
|
1486
1446
|
pending_withdraws: table_vec.TableVec<staking_pool.PendingWithdrawEntry>;
|
@@ -1547,8 +1507,9 @@ export namespace sui {
|
|
1547
1507
|
dummy_field: Boolean;
|
1548
1508
|
}
|
1549
1509
|
|
1550
|
-
export interface TransferPayload
|
1551
|
-
|
1510
|
+
export interface TransferPayload
|
1511
|
+
extends TypedFunctionPayload<[coin.Coin<sui.SUI>]> {
|
1512
|
+
arguments_decoded: [coin.Coin<sui.SUI>];
|
1552
1513
|
type_arguments: [];
|
1553
1514
|
}
|
1554
1515
|
}
|
@@ -1991,18 +1952,18 @@ export namespace sui_system {
|
|
1991
1952
|
}
|
1992
1953
|
|
1993
1954
|
export interface RequestAddDelegationPayload
|
1994
|
-
extends TypedFunctionPayload<[SuiAddress,
|
1995
|
-
arguments_decoded: [SuiAddress,
|
1955
|
+
extends TypedFunctionPayload<[SuiAddress, coin.Coin<sui.SUI>, SuiAddress]> {
|
1956
|
+
arguments_decoded: [SuiAddress, coin.Coin<sui.SUI>, SuiAddress];
|
1996
1957
|
type_arguments: [];
|
1997
1958
|
}
|
1998
1959
|
|
1999
1960
|
export interface RequestAddDelegationMulCoinPayload
|
2000
1961
|
extends TypedFunctionPayload<
|
2001
|
-
[SuiAddress,
|
1962
|
+
[SuiAddress, coin.Coin<sui.SUI>[], _0x1.option.Option<bigint>, SuiAddress]
|
2002
1963
|
> {
|
2003
1964
|
arguments_decoded: [
|
2004
1965
|
SuiAddress,
|
2005
|
-
|
1966
|
+
coin.Coin<sui.SUI>[],
|
2006
1967
|
_0x1.option.Option<bigint>,
|
2007
1968
|
SuiAddress
|
2008
1969
|
];
|
@@ -2040,8 +2001,8 @@ export namespace sui_system {
|
|
2040
2001
|
}
|
2041
2002
|
|
2042
2003
|
export interface RequestAddStakePayload
|
2043
|
-
extends TypedFunctionPayload<[SuiAddress,
|
2044
|
-
arguments_decoded: [SuiAddress,
|
2004
|
+
extends TypedFunctionPayload<[SuiAddress, coin.Coin<sui.SUI>]> {
|
2005
|
+
arguments_decoded: [SuiAddress, coin.Coin<sui.SUI>];
|
2045
2006
|
type_arguments: [];
|
2046
2007
|
}
|
2047
2008
|
|
@@ -2068,7 +2029,7 @@ export namespace sui_system {
|
|
2068
2029
|
string,
|
2069
2030
|
string,
|
2070
2031
|
string,
|
2071
|
-
|
2032
|
+
coin.Coin<sui.SUI>,
|
2072
2033
|
bigint,
|
2073
2034
|
bigint
|
2074
2035
|
]
|
@@ -2086,7 +2047,7 @@ export namespace sui_system {
|
|
2086
2047
|
string,
|
2087
2048
|
string,
|
2088
2049
|
string,
|
2089
|
-
|
2050
|
+
coin.Coin<sui.SUI>,
|
2090
2051
|
bigint,
|
2091
2052
|
bigint
|
2092
2053
|
];
|
@@ -2207,7 +2168,7 @@ export class typed_id extends SuiBaseProcessor {
|
|
2207
2168
|
export namespace typed_id {
|
2208
2169
|
export class TypedID<T0> {
|
2209
2170
|
static TYPE_QNAME = "0x2::typed_id::TypedID";
|
2210
|
-
id:
|
2171
|
+
id: object_.ID;
|
2211
2172
|
}
|
2212
2173
|
|
2213
2174
|
export interface TypedIDInstance extends TypedEventInstance<TypedID<any>> {
|
@@ -5,7 +5,7 @@ import { InternalMoveModule, InternalMoveStruct } from '../../move/internal-mode
|
|
5
5
|
import { AbstractCodegen } from '../../move/abstract-codegen.js'
|
6
6
|
import { JsonRpcProvider, SuiMoveNormalizedModules } from '@mysten/sui.js'
|
7
7
|
import { toInternalModule } from '../move-types.js'
|
8
|
-
import { moduleQname, SPLITTER, TypeDescriptor } from '../../move/index.js'
|
8
|
+
import { moduleQname, SPLITTER, structQname, TypeDescriptor } from '../../move/index.js'
|
9
9
|
import { getMeaningfulFunctionParams } from '../utils.js'
|
10
10
|
|
11
11
|
export async function codegen(abisDir: string, outDir = 'src/types/sui') {
|
@@ -69,4 +69,26 @@ class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
|
|
69
69
|
}
|
70
70
|
return res
|
71
71
|
}
|
72
|
+
|
73
|
+
generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>): string {
|
74
|
+
switch (structQname(module, struct)) {
|
75
|
+
case '0x2::object::ID':
|
76
|
+
return `export type ${struct.name} = string`
|
77
|
+
case '0x2::coin::Coin':
|
78
|
+
return `export type ${struct.name}<T> = string`
|
79
|
+
case '0x1::option::Option':
|
80
|
+
return `export type Option<T> = T | undefined`
|
81
|
+
}
|
82
|
+
return super.generateStructs(module, struct, events)
|
83
|
+
}
|
84
|
+
|
85
|
+
generateOnEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
|
86
|
+
switch (structQname(module, struct)) {
|
87
|
+
case '0x2::object::ID':
|
88
|
+
case '0x2::coin::Coin':
|
89
|
+
case '0x1::option::Option':
|
90
|
+
return ''
|
91
|
+
}
|
92
|
+
return super.generateOnEvents(module, struct)
|
93
|
+
}
|
72
94
|
}
|
package/src/sui/move-coder.ts
CHANGED
@@ -13,6 +13,18 @@ export class MoveCoder extends AbstractMoveCoder<MoveEvent> {
|
|
13
13
|
this.loadInternal(toInternalModule(module))
|
14
14
|
}
|
15
15
|
|
16
|
+
decode(data: any, type: TypeDescriptor): any {
|
17
|
+
switch (type.qname) {
|
18
|
+
case '0x2::object::ID':
|
19
|
+
case '0x2::coin::Coin':
|
20
|
+
return data
|
21
|
+
case '0x1::option::Option':
|
22
|
+
return this.decode(data, type.typeArgs[0])
|
23
|
+
default:
|
24
|
+
return super.decode(data, type)
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
16
28
|
decodeEvent<T>(event: MoveEvent): TypedEventInstance<T> | undefined {
|
17
29
|
const res = this.decodedInternal<T>({ ...event, data: event.fields })
|
18
30
|
return { ...event, fields_decoded: res?.data_decoded as T, type_arguments: res?.type_arguments || [] }
|
package/lib/move/ts-type.d.ts
DELETED