@sentio/sdk 2.23.0 → 2.24.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/aptos/aptos-processor.d.ts +1 -2
- package/lib/aptos/aptos-processor.d.ts.map +1 -1
- package/lib/aptos/aptos-processor.js +11 -11
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.d.ts +1 -1
- package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.js +6 -6
- package/lib/aptos/builtin/0x1.d.ts +850 -339
- package/lib/aptos/builtin/0x1.d.ts.map +1 -1
- package/lib/aptos/builtin/0x1.js +652 -189
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +73 -54
- package/lib/aptos/builtin/0x3.d.ts.map +1 -1
- package/lib/aptos/builtin/0x3.js +25 -66
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.d.ts.map +1 -1
- package/lib/aptos/codegen/codegen.js +40 -10
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/context.d.ts +1 -2
- package/lib/aptos/context.d.ts.map +1 -1
- package/lib/aptos/context.js +2 -2
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/ext/coin-event.js +1 -1
- package/lib/aptos/ext/coin.js +193 -193
- package/lib/aptos/ext/coin.js.map +1 -1
- package/lib/aptos/index.d.ts +4 -4
- package/lib/aptos/index.d.ts.map +1 -1
- package/lib/aptos/index.js +3 -4
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +2 -2
- package/lib/aptos/models.d.ts.map +1 -1
- package/lib/aptos/move-coder.d.ts +1 -13
- package/lib/aptos/move-coder.d.ts.map +1 -1
- package/lib/aptos/move-coder.js +4 -55
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/aptos/network.d.ts +1 -0
- package/lib/aptos/network.d.ts.map +1 -1
- package/lib/aptos/network.js +8 -1
- package/lib/aptos/network.js.map +1 -1
- package/lib/eth/codegen/codegen.d.ts.map +1 -1
- package/lib/eth/codegen/codegen.js +4 -3
- package/lib/eth/codegen/codegen.js.map +1 -1
- package/lib/move/ext/move-dex.d.ts +1 -1
- package/lib/move/ext/move-dex.d.ts.map +1 -1
- package/lib/move/ext/move-dex.js +4 -4
- package/lib/move/index.d.ts +1 -4
- package/lib/move/index.d.ts.map +1 -1
- package/lib/move/index.js +1 -4
- package/lib/move/index.js.map +1 -1
- package/lib/move/move-context.d.ts +3 -3
- package/lib/move/move-context.d.ts.map +1 -1
- package/lib/move/move-context.js.map +1 -1
- package/lib/move/shared-network-codegen.d.ts +14 -0
- package/lib/move/shared-network-codegen.d.ts.map +1 -0
- package/lib/move/shared-network-codegen.js +116 -0
- package/lib/move/shared-network-codegen.js.map +1 -0
- package/lib/sui/builtin/0x1.d.ts +4 -2
- package/lib/sui/builtin/0x1.d.ts.map +1 -1
- package/lib/sui/builtin/0x1.js +7 -14
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +52 -168
- package/lib/sui/builtin/0x2.d.ts.map +1 -1
- package/lib/sui/builtin/0x2.js +24 -65
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +113 -331
- package/lib/sui/builtin/0x3.d.ts.map +1 -1
- package/lib/sui/builtin/0x3.js +13 -32
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/codegen/codegen.d.ts.map +1 -1
- package/lib/sui/codegen/codegen.js +72 -51
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/context.d.ts +4 -4
- package/lib/sui/context.d.ts.map +1 -1
- package/lib/sui/context.js +2 -2
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/ext/coin.js +74 -74
- package/lib/sui/ext/move-dex.d.ts +2 -3
- package/lib/sui/ext/move-dex.d.ts.map +1 -1
- package/lib/sui/index.d.ts +4 -4
- package/lib/sui/index.d.ts.map +1 -1
- package/lib/sui/index.js +4 -4
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/models.d.ts +2 -2
- package/lib/sui/models.d.ts.map +1 -1
- package/lib/sui/move-coder.d.ts +1 -16
- package/lib/sui/move-coder.d.ts.map +1 -1
- package/lib/sui/move-coder.js +4 -93
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/network.d.ts +3 -2
- package/lib/sui/network.d.ts.map +1 -1
- package/lib/sui/network.js +10 -3
- package/lib/sui/network.js.map +1 -1
- package/lib/sui/sui-object-processor-template.d.ts +1 -1
- package/lib/sui/sui-object-processor-template.d.ts.map +1 -1
- package/lib/sui/sui-object-processor-template.js +7 -7
- package/lib/sui/sui-object-processor-template.js.map +1 -1
- package/lib/sui/sui-object-processor.d.ts +1 -1
- package/lib/sui/sui-object-processor.d.ts.map +1 -1
- package/lib/sui/sui-object-processor.js +5 -5
- package/lib/sui/sui-processor.d.ts +2 -2
- package/lib/sui/sui-processor.d.ts.map +1 -1
- package/lib/sui/sui-processor.js +10 -10
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/sui/utils.d.ts +2 -2
- package/lib/sui/utils.d.ts.map +1 -1
- package/lib/sui/utils.js +3 -4
- package/lib/sui/utils.js.map +1 -1
- package/lib/testing/aptos-facet.d.ts.map +1 -1
- package/lib/testing/aptos-facet.js +8 -9
- package/lib/testing/aptos-facet.js.map +1 -1
- package/lib/testing/sui-facet.d.ts +1 -1
- package/lib/testing/sui-facet.d.ts.map +1 -1
- package/lib/testing/sui-facet.js +8 -9
- package/lib/testing/sui-facet.js.map +1 -1
- package/package.json +10 -7
- package/src/aptos/abis/0x1.json +4533 -710
- package/src/aptos/abis/0x3.json +147 -2
- package/src/aptos/aptos-processor.ts +13 -12
- package/src/aptos/aptos-resource-processor-template.ts +7 -7
- package/src/aptos/builtin/0x1.ts +2243 -1187
- package/src/aptos/builtin/0x3.ts +205 -249
- package/src/aptos/codegen/codegen.ts +50 -11
- package/src/aptos/context.ts +4 -4
- package/src/aptos/ext/coin-event.ts +2 -2
- package/src/aptos/ext/coin.ts +193 -193
- package/src/aptos/index.ts +15 -4
- package/src/aptos/models.ts +2 -2
- package/src/aptos/move-coder.ts +4 -73
- package/src/aptos/network.ts +9 -1
- package/src/eth/codegen/codegen.ts +5 -4
- package/src/move/ext/move-dex.ts +5 -5
- package/src/move/index.ts +2 -4
- package/src/move/move-context.ts +3 -3
- package/src/move/shared-network-codegen.ts +160 -0
- package/src/sui/builtin/0x1.ts +17 -41
- package/src/sui/builtin/0x2.ts +196 -410
- package/src/sui/builtin/0x3.ts +271 -479
- package/src/sui/codegen/codegen.ts +80 -54
- package/src/sui/context.ts +8 -7
- package/src/sui/ext/coin.ts +75 -75
- package/src/sui/ext/move-dex.ts +3 -3
- package/src/sui/index.ts +5 -5
- package/src/sui/models.ts +2 -2
- package/src/sui/move-coder.ts +4 -108
- package/src/sui/network.ts +12 -4
- package/src/sui/sui-object-processor-template.ts +8 -8
- package/src/sui/sui-object-processor.ts +6 -6
- package/src/sui/sui-processor.ts +12 -16
- package/src/sui/utils.ts +6 -7
- package/src/testing/aptos-facet.ts +8 -9
- package/src/testing/sui-facet.ts +9 -10
- package/lib/aptos/aptos-chain-adapter.d.ts +0 -15
- package/lib/aptos/aptos-chain-adapter.d.ts.map +0 -1
- package/lib/aptos/aptos-chain-adapter.js +0 -72
- package/lib/aptos/aptos-chain-adapter.js.map +0 -1
- package/lib/aptos/module-client.d.ts +0 -7
- package/lib/aptos/module-client.d.ts.map +0 -1
- package/lib/aptos/module-client.js +0 -25
- package/lib/aptos/module-client.js.map +0 -1
- package/lib/aptos/module-client.test.d.ts +0 -2
- package/lib/aptos/module-client.test.d.ts.map +0 -1
- package/lib/aptos/module-client.test.js.map +0 -1
- package/lib/aptos/move-types.d.ts +0 -17
- package/lib/aptos/move-types.d.ts.map +0 -1
- package/lib/aptos/move-types.js +0 -53
- package/lib/aptos/move-types.js.map +0 -1
- package/lib/aptos/utils.d.ts +0 -2
- package/lib/aptos/utils.d.ts.map +0 -1
- package/lib/aptos/utils.js +0 -16
- package/lib/aptos/utils.js.map +0 -1
- package/lib/move/abstract-codegen.d.ts +0 -50
- package/lib/move/abstract-codegen.d.ts.map +0 -1
- package/lib/move/abstract-codegen.js +0 -489
- package/lib/move/abstract-codegen.js.map +0 -1
- package/lib/move/abstract-move-coder.d.ts +0 -29
- package/lib/move/abstract-move-coder.d.ts.map +0 -1
- package/lib/move/abstract-move-coder.js +0 -301
- package/lib/move/abstract-move-coder.js.map +0 -1
- package/lib/move/account.d.ts +0 -16
- package/lib/move/account.d.ts.map +0 -1
- package/lib/move/account.js +0 -71
- package/lib/move/account.js.map +0 -1
- package/lib/move/chain-adapter.d.ts +0 -13
- package/lib/move/chain-adapter.d.ts.map +0 -1
- package/lib/move/chain-adapter.js +0 -7
- package/lib/move/chain-adapter.js.map +0 -1
- package/lib/move/internal-models.d.ts +0 -35
- package/lib/move/internal-models.d.ts.map +0 -1
- package/lib/move/internal-models.js +0 -7
- package/lib/move/internal-models.js.map +0 -1
- package/lib/move/ts-type.test.d.ts +0 -2
- package/lib/move/ts-type.test.d.ts.map +0 -1
- package/lib/move/ts-type.test.js.map +0 -1
- package/lib/move/types.d.ts +0 -42
- package/lib/move/types.d.ts.map +0 -1
- package/lib/move/types.js +0 -205
- package/lib/move/types.js.map +0 -1
- package/lib/move/utils.d.ts +0 -16
- package/lib/move/utils.d.ts.map +0 -1
- package/lib/move/utils.js +0 -53
- package/lib/move/utils.js.map +0 -1
- package/lib/move/utils.test.d.ts +0 -2
- package/lib/move/utils.test.d.ts.map +0 -1
- package/lib/move/utils.test.js.map +0 -1
- package/lib/sui/module-client.d.ts +0 -4
- package/lib/sui/module-client.d.ts.map +0 -1
- package/lib/sui/module-client.js +0 -7
- package/lib/sui/module-client.js.map +0 -1
- package/lib/sui/move-types.d.ts +0 -9
- package/lib/sui/move-types.d.ts.map +0 -1
- package/lib/sui/move-types.js +0 -82
- package/lib/sui/move-types.js.map +0 -1
- package/lib/sui/sui-chain-adapter.d.ts +0 -15
- package/lib/sui/sui-chain-adapter.d.ts.map +0 -1
- package/lib/sui/sui-chain-adapter.js +0 -71
- package/lib/sui/sui-chain-adapter.js.map +0 -1
- package/src/aptos/aptos-chain-adapter.ts +0 -86
- package/src/aptos/module-client.ts +0 -30
- package/src/aptos/move-types.ts +0 -73
- package/src/aptos/utils.ts +0 -15
- package/src/move/abstract-codegen.ts +0 -596
- package/src/move/abstract-move-coder.ts +0 -337
- package/src/move/account.ts +0 -81
- package/src/move/chain-adapter.ts +0 -24
- package/src/move/internal-models.ts +0 -40
- package/src/move/types.ts +0 -241
- package/src/move/utils.ts +0 -69
- package/src/sui/module-client.ts +0 -7
- package/src/sui/move-types.ts +0 -108
- package/src/sui/sui-chain-adapter.ts +0 -93
package/src/aptos/move-types.ts
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
import { Types } from 'aptos-sdk'
|
2
|
-
import {
|
3
|
-
InternalMoveFunction,
|
4
|
-
InternalMoveFunctionVisibility,
|
5
|
-
InternalMoveModule,
|
6
|
-
InternalMoveStruct,
|
7
|
-
InternalMoveStructField,
|
8
|
-
} from '../move/internal-models.js'
|
9
|
-
import { parseMoveType } from '../move/index.js'
|
10
|
-
|
11
|
-
export type Address = Types.Address
|
12
|
-
export type Event = Types.Event
|
13
|
-
export type MoveFunction = Types.MoveFunction
|
14
|
-
export type MoveModule = Types.MoveModule
|
15
|
-
export type MoveResource = Types.MoveResource
|
16
|
-
export type MoveStruct = Types.MoveStruct
|
17
|
-
export type MoveStructField = Types.MoveStructField
|
18
|
-
export type MoveModuleBytecode = Types.MoveModuleBytecode
|
19
|
-
export type TransactionPayload_EntryFunctionPayload = Types.TransactionPayload_EntryFunctionPayload
|
20
|
-
export type Transaction_UserTransaction = Types.Transaction_UserTransaction
|
21
|
-
|
22
|
-
export function toInternalModule(module: MoveModuleBytecode): InternalMoveModule {
|
23
|
-
if (!module.abi) {
|
24
|
-
throw Error('module with no ABI found')
|
25
|
-
}
|
26
|
-
const abi = module.abi
|
27
|
-
return {
|
28
|
-
address: abi.address,
|
29
|
-
exposedFunctions: abi.exposed_functions.map(toInternalFunction),
|
30
|
-
name: abi.name,
|
31
|
-
structs: abi.structs.map(toInternalStruct),
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
export function toInternalFunction(func: MoveFunction): InternalMoveFunction {
|
36
|
-
let visibility
|
37
|
-
switch (func.visibility) {
|
38
|
-
case Types.MoveFunctionVisibility.PRIVATE:
|
39
|
-
visibility = InternalMoveFunctionVisibility.PRIVATE
|
40
|
-
break
|
41
|
-
case Types.MoveFunctionVisibility.PUBLIC:
|
42
|
-
visibility = InternalMoveFunctionVisibility.PUBLIC
|
43
|
-
break
|
44
|
-
case Types.MoveFunctionVisibility.FRIEND:
|
45
|
-
visibility = InternalMoveFunctionVisibility.FRIEND
|
46
|
-
break
|
47
|
-
}
|
48
|
-
return {
|
49
|
-
typeParams: func.generic_type_params,
|
50
|
-
isEntry: func.is_entry,
|
51
|
-
name: func.name,
|
52
|
-
params: func.params.map(parseMoveType),
|
53
|
-
return: func.return.map(parseMoveType),
|
54
|
-
visibility: visibility,
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
export function toInternalStruct(struct: MoveStruct): InternalMoveStruct {
|
59
|
-
return {
|
60
|
-
abilities: struct.abilities,
|
61
|
-
fields: struct.fields.map(toInternalField),
|
62
|
-
typeParams: struct.generic_type_params,
|
63
|
-
isNative: struct.is_native,
|
64
|
-
name: struct.name,
|
65
|
-
}
|
66
|
-
}
|
67
|
-
|
68
|
-
export function toInternalField(module: MoveStructField): InternalMoveStructField {
|
69
|
-
return {
|
70
|
-
name: module.name,
|
71
|
-
type: parseMoveType(module.type),
|
72
|
-
}
|
73
|
-
}
|
package/src/aptos/utils.ts
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
// import { HexString, TxnBuilderTypes } from 'aptos-sdk'
|
2
|
-
// import { isFrameworkAccount } from '../move/index.js'
|
3
|
-
|
4
|
-
// export function isValidAptosAddress(value: string): boolean {
|
5
|
-
// return TxnBuilderTypes.AccountAddress.isValid(value)
|
6
|
-
// }
|
7
|
-
//
|
8
|
-
// export function validateAndNormalizeAddress(address: string): string {
|
9
|
-
// const hex = TxnBuilderTypes.AccountAddress.fromHex(address).toHexString()
|
10
|
-
// // if (isFrameworkAccount(address)) {
|
11
|
-
// // return HexString.ensure(hex).toShortString()
|
12
|
-
// // }
|
13
|
-
// // return hex.toString()
|
14
|
-
// return HexString.ensure(hex).toShortString()
|
15
|
-
// }
|
@@ -1,596 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
InternalMoveFunction,
|
3
|
-
// InternalMoveFunctionVisibility,
|
4
|
-
InternalMoveModule,
|
5
|
-
InternalMoveStruct,
|
6
|
-
} from './internal-models.js'
|
7
|
-
import path from 'path'
|
8
|
-
import fs from 'fs'
|
9
|
-
import { AccountModulesImportInfo, AccountRegister } from './account.js'
|
10
|
-
import chalk from 'chalk'
|
11
|
-
import { format } from 'prettier'
|
12
|
-
import { isFrameworkAccount, moduleQname, normalizeToJSName, SPLITTER, upperFirst, VECTOR_STR } from './utils.js'
|
13
|
-
import { camel } from 'radash'
|
14
|
-
import { TypeDescriptor } from './types.js'
|
15
|
-
import { ChainAdapter } from './chain-adapter.js'
|
16
|
-
|
17
|
-
interface OutputFile {
|
18
|
-
fileName: string
|
19
|
-
fileContent: string
|
20
|
-
}
|
21
|
-
|
22
|
-
interface Config<NetworkType> {
|
23
|
-
fileName: string
|
24
|
-
outputDir: string
|
25
|
-
network: NetworkType
|
26
|
-
}
|
27
|
-
|
28
|
-
export abstract class AbstractCodegen<NetworkType, ModuleTypes, StructType> {
|
29
|
-
TEST_NET: NetworkType
|
30
|
-
MAIN_NET: NetworkType
|
31
|
-
ADDRESS_TYPE: string = 'string'
|
32
|
-
PREFIX: string
|
33
|
-
STRUCT_FIELD_NAME: string = 'data'
|
34
|
-
GENERATE_CLIENT = false
|
35
|
-
GENERATE_ON_ENTRY = true
|
36
|
-
PAYLOAD_OPTIONAL = false
|
37
|
-
SYSTEM_MODULES = new Set(['0x1', '0x2', '0x3'])
|
38
|
-
|
39
|
-
chainAdapter: ChainAdapter<NetworkType, ModuleTypes, StructType>
|
40
|
-
|
41
|
-
protected constructor(chainAdapter: ChainAdapter<NetworkType, ModuleTypes, StructType>) {
|
42
|
-
this.chainAdapter = chainAdapter
|
43
|
-
}
|
44
|
-
|
45
|
-
readModulesFile(fullPath: string) {
|
46
|
-
return JSON.parse(fs.readFileSync(fullPath, 'utf-8'))
|
47
|
-
}
|
48
|
-
|
49
|
-
async generate(srcDir: string, outputDir: string, builtin = false): Promise<number> {
|
50
|
-
const num1 = await this.generateForNetwork(srcDir, outputDir, this.MAIN_NET, builtin)
|
51
|
-
const num2 = await this.generateForNetwork(
|
52
|
-
path.join(srcDir, 'testnet'),
|
53
|
-
path.join(outputDir, 'testnet'),
|
54
|
-
this.TEST_NET,
|
55
|
-
builtin
|
56
|
-
)
|
57
|
-
return num1 + num2
|
58
|
-
}
|
59
|
-
|
60
|
-
async generateForNetwork(srcDir: string, outputDir: string, network: NetworkType, builtin = false) {
|
61
|
-
if (!fs.existsSync(srcDir)) {
|
62
|
-
return 0
|
63
|
-
}
|
64
|
-
|
65
|
-
const files = fs.readdirSync(srcDir)
|
66
|
-
outputDir = path.resolve(outputDir)
|
67
|
-
const outputs: OutputFile[] = []
|
68
|
-
|
69
|
-
fs.mkdirSync(outputDir, { recursive: true })
|
70
|
-
|
71
|
-
const loader = new AccountRegister()
|
72
|
-
|
73
|
-
// when generating user code, don't need to generate framework account
|
74
|
-
for (const sysModule of this.SYSTEM_MODULES) {
|
75
|
-
loader.accountImports.set(sysModule, new AccountModulesImportInfo(sysModule, sysModule))
|
76
|
-
}
|
77
|
-
// const client = getRpcClient(network)
|
78
|
-
|
79
|
-
for (const file of files) {
|
80
|
-
if (!file.endsWith('.json')) {
|
81
|
-
continue
|
82
|
-
}
|
83
|
-
const fullPath = path.resolve(srcDir, file)
|
84
|
-
const abi = this.readModulesFile(fullPath)
|
85
|
-
const modules = this.chainAdapter.toInternalModules(abi)
|
86
|
-
|
87
|
-
for (const module of modules) {
|
88
|
-
loader.register(module, path.basename(file, '.json'))
|
89
|
-
}
|
90
|
-
const codeGen = new AccountCodegen(this, loader, abi, modules, {
|
91
|
-
fileName: path.basename(file, '.json'),
|
92
|
-
outputDir: outputDir,
|
93
|
-
network,
|
94
|
-
})
|
95
|
-
|
96
|
-
outputs.push(...codeGen.generate())
|
97
|
-
}
|
98
|
-
|
99
|
-
while (loader.pendingAccounts.size > 0) {
|
100
|
-
for (const account of loader.pendingAccounts) {
|
101
|
-
console.log(`download dependent module for account ${account} at ${network}`)
|
102
|
-
|
103
|
-
try {
|
104
|
-
const rawModules = await this.chainAdapter.fetchModules(account, network)
|
105
|
-
const modules = this.chainAdapter.toInternalModules(rawModules)
|
106
|
-
|
107
|
-
fs.writeFileSync(path.resolve(srcDir, account + '.json'), JSON.stringify(rawModules, null, '\t'))
|
108
|
-
for (const module of modules) {
|
109
|
-
loader.register(module, account)
|
110
|
-
}
|
111
|
-
const codeGen = new AccountCodegen(this, loader, rawModules, modules, {
|
112
|
-
fileName: account,
|
113
|
-
outputDir: outputDir,
|
114
|
-
network,
|
115
|
-
})
|
116
|
-
|
117
|
-
outputs.push(...codeGen.generate())
|
118
|
-
} catch (e) {
|
119
|
-
console.error(
|
120
|
-
chalk.red(
|
121
|
-
'Error downloading account module, check if you choose the right network,or download account modules manually into your director'
|
122
|
-
)
|
123
|
-
)
|
124
|
-
console.error(e)
|
125
|
-
process.exit(1)
|
126
|
-
}
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
for (const output of outputs) {
|
131
|
-
// const content = output.fileContent
|
132
|
-
const content = format(output.fileContent, { parser: 'typescript' })
|
133
|
-
fs.writeFileSync(path.join(outputDir, output.fileName), content)
|
134
|
-
}
|
135
|
-
|
136
|
-
const rootFile = path.join(outputDir, 'index.ts')
|
137
|
-
let rootFileContent = `/* Autogenerated file. Do not edit manually. */
|
138
|
-
/* tslint:disable */
|
139
|
-
/* eslint-disable */
|
140
|
-
`
|
141
|
-
for (const output of outputs) {
|
142
|
-
const parsed = path.parse(output.fileName)
|
143
|
-
rootFileContent += `export * as _${parsed.name.replaceAll('-', '_')} from './${parsed.name}.js'\n`
|
144
|
-
}
|
145
|
-
// if (builtin) {
|
146
|
-
// rootFileContent += `export { BUILTIN_TYPES } from '@sentio/sdk/move'`
|
147
|
-
// }
|
148
|
-
fs.writeFileSync(rootFile, rootFileContent)
|
149
|
-
|
150
|
-
return outputs.length + 1
|
151
|
-
}
|
152
|
-
|
153
|
-
generateNetworkOption(network: NetworkType) {
|
154
|
-
switch (network) {
|
155
|
-
case this.TEST_NET:
|
156
|
-
return 'TEST_NET'
|
157
|
-
}
|
158
|
-
return 'MAIN_NET'
|
159
|
-
}
|
160
|
-
|
161
|
-
generateModule(module: InternalMoveModule, allEventStructs: Map<string, InternalMoveStruct>, network: NetworkType) {
|
162
|
-
const qname = moduleQname(module)
|
163
|
-
const functions = this.GENERATE_ON_ENTRY
|
164
|
-
? module.exposedFunctions.map((f) => this.generateForEntryFunctions(module, f)).filter((s) => s !== '')
|
165
|
-
: []
|
166
|
-
// const clientFunctions = this.GENERATE_CLIENT
|
167
|
-
// ? module.exposedFunctions.map((f) => this.generateClientFunctions(module, f)).filter((s) => s !== '')
|
168
|
-
// : []
|
169
|
-
const eventStructs = new Map<string, InternalMoveStruct>()
|
170
|
-
for (const [type, struct] of allEventStructs.entries()) {
|
171
|
-
if (type.startsWith(qname + SPLITTER)) {
|
172
|
-
eventStructs.set(type, struct)
|
173
|
-
}
|
174
|
-
}
|
175
|
-
|
176
|
-
const eventTypes = new Set(eventStructs.keys())
|
177
|
-
const events = Array.from(eventStructs.values())
|
178
|
-
.map((e) => this.generateForEvents(module, e))
|
179
|
-
.filter((s) => s !== '')
|
180
|
-
const structs = module.structs.map((s) => this.generateStructs(module, s, eventTypes))
|
181
|
-
const callArgs = module.exposedFunctions.map((f) => this.generateCallArgsStructs(module, f))
|
182
|
-
|
183
|
-
const moduleName = normalizeToJSName(module.name)
|
184
|
-
let processor = ''
|
185
|
-
// let client = ''
|
186
|
-
// if (clientFunctions.length > 0) {
|
187
|
-
// client = `
|
188
|
-
// export class ${moduleName}_client extends ModuleClient {
|
189
|
-
// ${clientFunctions.join('\n')}
|
190
|
-
// }
|
191
|
-
// `
|
192
|
-
// }
|
193
|
-
|
194
|
-
if (functions.length > 0 || events.length > 0) {
|
195
|
-
processor = `export class ${moduleName} extends ${this.PREFIX}BaseProcessor {
|
196
|
-
|
197
|
-
constructor(options: ${this.PREFIX}BindOptions) {
|
198
|
-
super("${module.name}", options)
|
199
|
-
}
|
200
|
-
static DEFAULT_OPTIONS: ${this.PREFIX}BindOptions = {
|
201
|
-
address: "${module.address}",
|
202
|
-
network: ${this.PREFIX}Network.${this.generateNetworkOption(network)}
|
203
|
-
}
|
204
|
-
|
205
|
-
static bind(options: Partial<${this.PREFIX}BindOptions> = {}): ${moduleName} {
|
206
|
-
return new ${moduleName}({ ...${moduleName}.DEFAULT_OPTIONS, ...options })
|
207
|
-
}
|
208
|
-
|
209
|
-
${functions.join('\n')}
|
210
|
-
|
211
|
-
${events.join('\n')}
|
212
|
-
}
|
213
|
-
`
|
214
|
-
}
|
215
|
-
|
216
|
-
return `
|
217
|
-
|
218
|
-
${processor}
|
219
|
-
|
220
|
-
export namespace ${moduleName} {
|
221
|
-
${structs.join('\n')}
|
222
|
-
|
223
|
-
${callArgs.join('\n')}
|
224
|
-
}
|
225
|
-
`
|
226
|
-
}
|
227
|
-
|
228
|
-
generateStructs(module: InternalMoveModule, struct: InternalMoveStruct, events: Set<string>, typeOnly = false) {
|
229
|
-
const typeParams = struct.typeParams || []
|
230
|
-
const genericString = this.generateStructTypeParameters(struct)
|
231
|
-
const genericStringAny = this.generateStructTypeParameters(struct, true)
|
232
|
-
|
233
|
-
const structName = normalizeToJSName(struct.name)
|
234
|
-
|
235
|
-
const fields = struct.fields.map((field) => {
|
236
|
-
const type = this.generateTypeForDescriptor(field.type, module.address)
|
237
|
-
return `${field.name}: ${type}`
|
238
|
-
})
|
239
|
-
|
240
|
-
const typeParamApplyArg = typeParams
|
241
|
-
.map((v, idx) => {
|
242
|
-
return `arg${idx}: TypeDescriptor<T${idx}> = ANY_TYPE`
|
243
|
-
})
|
244
|
-
.join(',')
|
245
|
-
const typeParamApply = typeParams
|
246
|
-
.map((v, idx) => {
|
247
|
-
return `arg${idx}`
|
248
|
-
})
|
249
|
-
.join(',')
|
250
|
-
|
251
|
-
const typeDescriptor = `
|
252
|
-
export namespace ${structName}{
|
253
|
-
export const TYPE_QNAME = '${module.address}::${module.name}::${struct.name}'
|
254
|
-
|
255
|
-
const TYPE = new TypeDescriptor<${structName}${genericStringAny}>(${structName}.TYPE_QNAME)
|
256
|
-
|
257
|
-
export function type${genericString}(${typeParamApplyArg}): TypeDescriptor<${structName}${genericString}> {
|
258
|
-
return TYPE.apply(${typeParamApply})
|
259
|
-
}
|
260
|
-
}
|
261
|
-
`
|
262
|
-
if (typeOnly) {
|
263
|
-
return typeDescriptor
|
264
|
-
}
|
265
|
-
|
266
|
-
let eventPayload = ''
|
267
|
-
if (events.has(moduleQname(module) + SPLITTER + struct.name)) {
|
268
|
-
eventPayload = `
|
269
|
-
export interface ${structName}Instance extends
|
270
|
-
TypedEventInstance<${structName}${genericStringAny}> {
|
271
|
-
${this.STRUCT_FIELD_NAME}_decoded: ${structName}${genericStringAny}
|
272
|
-
type_arguments: [${struct.typeParams.map((_) => 'string').join(', ')}]
|
273
|
-
}
|
274
|
-
`
|
275
|
-
}
|
276
|
-
|
277
|
-
return `
|
278
|
-
export interface ${structName}${genericString} {
|
279
|
-
${fields.join('\n')}
|
280
|
-
}
|
281
|
-
|
282
|
-
${typeDescriptor}
|
283
|
-
|
284
|
-
${eventPayload}
|
285
|
-
`
|
286
|
-
}
|
287
|
-
|
288
|
-
generateFunctionTypeParameters(func: InternalMoveFunction) {
|
289
|
-
let genericString = ''
|
290
|
-
if (func.typeParams && func.typeParams.length > 0) {
|
291
|
-
const params = func.typeParams
|
292
|
-
.map((v, idx) => {
|
293
|
-
return `T${idx}=any`
|
294
|
-
})
|
295
|
-
.join(',')
|
296
|
-
genericString = `<${params}>`
|
297
|
-
}
|
298
|
-
return genericString
|
299
|
-
}
|
300
|
-
|
301
|
-
generateStructTypeParameters(struct: InternalMoveStruct, useAny = false) {
|
302
|
-
let genericString = ''
|
303
|
-
|
304
|
-
if (struct.typeParams && struct.typeParams.length > 0) {
|
305
|
-
const params = struct.typeParams
|
306
|
-
.map((v, idx) => {
|
307
|
-
return useAny ? 'any' : 'T' + idx
|
308
|
-
})
|
309
|
-
.join(',')
|
310
|
-
genericString = `<${params}>`
|
311
|
-
}
|
312
|
-
return genericString
|
313
|
-
}
|
314
|
-
|
315
|
-
generateCallArgsStructs(module: InternalMoveModule, func: InternalMoveFunction) {
|
316
|
-
if (!func.isEntry) {
|
317
|
-
return
|
318
|
-
}
|
319
|
-
|
320
|
-
const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
|
321
|
-
return this.generateTypeForDescriptor(param, module.address) + (this.PAYLOAD_OPTIONAL ? ' | undefined' : '')
|
322
|
-
})
|
323
|
-
|
324
|
-
const camelFuncName = upperFirst(camel(func.name))
|
325
|
-
|
326
|
-
const genericString = this.generateFunctionTypeParameters(func)
|
327
|
-
return `
|
328
|
-
export interface ${camelFuncName}Payload${genericString}
|
329
|
-
extends TypedFunctionPayload<[${fields.join(',')}]> {
|
330
|
-
arguments_decoded: [${fields.join(',')}],
|
331
|
-
type_arguments: [${func.typeParams.map((_) => 'string').join(', ')}]
|
332
|
-
}
|
333
|
-
`
|
334
|
-
}
|
335
|
-
|
336
|
-
// generateClientFunctions(module: InternalMoveModule, func: InternalMoveFunction) {
|
337
|
-
// if (func.visibility === InternalMoveFunctionVisibility.PRIVATE) {
|
338
|
-
// return ''
|
339
|
-
// }
|
340
|
-
// if (func.isEntry) {
|
341
|
-
// return ''
|
342
|
-
// }
|
343
|
-
// // const moduleName = normalizeToJSName(module.name)
|
344
|
-
// const funcName = camel(func.name)
|
345
|
-
// const fields = this.chainAdapter.getMeaningfulFunctionParams(func.params).map((param) => {
|
346
|
-
// return this.generateTypeForDescriptor(param, module.address)
|
347
|
-
// })
|
348
|
-
// const genericString = this.generateFunctionTypeParameters(func)
|
349
|
-
//
|
350
|
-
// const returns = func.return.map((param) => {
|
351
|
-
// return this.generateTypeForDescriptor(param, module.address)
|
352
|
-
// })
|
353
|
-
//
|
354
|
-
// const source = `
|
355
|
-
// ${funcName}${genericString}(type_arguments: [${func.typeParams
|
356
|
-
// .map((_) => 'string')
|
357
|
-
// .join(', ')}], args: [${fields.join(',')}], version?: bigint): Promise<[${returns.join(',')}]> {
|
358
|
-
// return this.viewDecoded('${module.address}::${module.name}::${func.name}', type_arguments, args, version) as any
|
359
|
-
// }`
|
360
|
-
// return source
|
361
|
-
// }
|
362
|
-
|
363
|
-
generateForEntryFunctions(module: InternalMoveModule, func: InternalMoveFunction) {
|
364
|
-
if (!func.isEntry) {
|
365
|
-
return ''
|
366
|
-
}
|
367
|
-
|
368
|
-
// const genericString = generateFunctionTypeParameters(func)
|
369
|
-
const moduleName = normalizeToJSName(module.name)
|
370
|
-
|
371
|
-
const camelFuncName = upperFirst(camel(func.name))
|
372
|
-
const source = `
|
373
|
-
onEntry${camelFuncName}(func: (call: ${moduleName}.${camelFuncName}Payload, ctx: ${this.PREFIX}Context) => void, filter?: CallFilter, fetchConfig?: Partial<MoveFetchConfig>): ${moduleName} {
|
374
|
-
this.onEntryFunctionCall(func, {
|
375
|
-
...filter,
|
376
|
-
function: '${module.name}::${func.name}'
|
377
|
-
},
|
378
|
-
fetchConfig)
|
379
|
-
return this
|
380
|
-
}`
|
381
|
-
|
382
|
-
return source
|
383
|
-
}
|
384
|
-
|
385
|
-
generateForEvents(module: InternalMoveModule, struct: InternalMoveStruct): string {
|
386
|
-
// for struct that has drop + store
|
387
|
-
// if (!isEvent(struct, module)) {
|
388
|
-
// return ''
|
389
|
-
// }
|
390
|
-
|
391
|
-
// const genericString = generateStructTypeParameters(struct)
|
392
|
-
|
393
|
-
const moduleName = normalizeToJSName(module.name)
|
394
|
-
const source = `
|
395
|
-
onEvent${struct.name}(func: (event: ${moduleName}.${normalizeToJSName(struct.name)}Instance, ctx: ${
|
396
|
-
this.PREFIX
|
397
|
-
}Context) => void, fetchConfig?: Partial<MoveFetchConfig>): ${moduleName} {
|
398
|
-
this.onMoveEvent(func, {
|
399
|
-
type: '${module.name}::${struct.name}'
|
400
|
-
},
|
401
|
-
fetchConfig)
|
402
|
-
return this
|
403
|
-
}
|
404
|
-
`
|
405
|
-
return source
|
406
|
-
}
|
407
|
-
|
408
|
-
generateTypeForDescriptor(type: TypeDescriptor, currentAddress: string): string {
|
409
|
-
if (type.reference) {
|
410
|
-
return this.ADDRESS_TYPE
|
411
|
-
}
|
412
|
-
|
413
|
-
switch (type.qname) {
|
414
|
-
case 'signer': // TODO check this
|
415
|
-
case 'address':
|
416
|
-
case 'Address':
|
417
|
-
return this.ADDRESS_TYPE
|
418
|
-
case '0x1::string::String':
|
419
|
-
return 'string'
|
420
|
-
case 'bool':
|
421
|
-
case 'Bool':
|
422
|
-
return 'Boolean'
|
423
|
-
case 'u8':
|
424
|
-
case 'U8':
|
425
|
-
case 'u16':
|
426
|
-
case 'U16':
|
427
|
-
case 'u32':
|
428
|
-
case 'U32':
|
429
|
-
return 'number'
|
430
|
-
case 'u64':
|
431
|
-
case 'U64':
|
432
|
-
case 'u128':
|
433
|
-
case 'U128':
|
434
|
-
case 'u256':
|
435
|
-
case 'U256':
|
436
|
-
return 'bigint'
|
437
|
-
}
|
438
|
-
|
439
|
-
if (type.qname.toLowerCase() === VECTOR_STR) {
|
440
|
-
// vector<u8> as hex string
|
441
|
-
const elementTypeQname = type.typeArgs[0].qname
|
442
|
-
if (elementTypeQname === 'u8') {
|
443
|
-
// only for aptos
|
444
|
-
return 'string'
|
445
|
-
}
|
446
|
-
if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {
|
447
|
-
return `${elementTypeQname}[] | string`
|
448
|
-
}
|
449
|
-
return this.generateTypeForDescriptor(type.typeArgs[0], currentAddress) + '[]'
|
450
|
-
}
|
451
|
-
|
452
|
-
const simpleName = this.generateSimpleType(type.qname, currentAddress)
|
453
|
-
if (simpleName.length === 0) {
|
454
|
-
console.error('unexpected error')
|
455
|
-
}
|
456
|
-
if (simpleName.toLowerCase() === VECTOR_STR || simpleName.toLowerCase().startsWith(VECTOR_STR + SPLITTER)) {
|
457
|
-
console.error('unexpected vector type error')
|
458
|
-
}
|
459
|
-
if (type.typeArgs.length > 0) {
|
460
|
-
// return simpleName
|
461
|
-
return (
|
462
|
-
simpleName + '<' + type.typeArgs.map((t) => this.generateTypeForDescriptor(t, currentAddress)).join(',') + '>'
|
463
|
-
)
|
464
|
-
}
|
465
|
-
return simpleName
|
466
|
-
}
|
467
|
-
|
468
|
-
generateSimpleType(type: string, currentAddress: string): string {
|
469
|
-
const parts = type.split(SPLITTER)
|
470
|
-
|
471
|
-
for (let i = 0; i < parts.length; i++) {
|
472
|
-
parts[i] = normalizeToJSName(parts[i])
|
473
|
-
}
|
474
|
-
|
475
|
-
if (parts.length < 2) {
|
476
|
-
return parts[0]
|
477
|
-
}
|
478
|
-
if (parts[0] === currentAddress) {
|
479
|
-
return parts.slice(1).join('.')
|
480
|
-
}
|
481
|
-
return '_' + parts.join('.')
|
482
|
-
}
|
483
|
-
}
|
484
|
-
|
485
|
-
export class AccountCodegen<NetworkType, ModuleType, StructType> {
|
486
|
-
modules: InternalMoveModule[]
|
487
|
-
config: Config<NetworkType>
|
488
|
-
abi: ModuleType[]
|
489
|
-
loader: AccountRegister
|
490
|
-
moduleGen: AbstractCodegen<NetworkType, ModuleType, StructType>
|
491
|
-
|
492
|
-
constructor(
|
493
|
-
moduleGen: AbstractCodegen<NetworkType, ModuleType, StructType>,
|
494
|
-
loader: AccountRegister,
|
495
|
-
abi: ModuleType[],
|
496
|
-
modules: InternalMoveModule[],
|
497
|
-
config: Config<NetworkType>
|
498
|
-
) {
|
499
|
-
// const json = fs.readFileSync(config.srcFile, 'utf-8')
|
500
|
-
this.moduleGen = moduleGen
|
501
|
-
this.abi = abi
|
502
|
-
this.modules = modules
|
503
|
-
this.config = config
|
504
|
-
this.loader = loader
|
505
|
-
}
|
506
|
-
|
507
|
-
generate(): OutputFile[] {
|
508
|
-
if (!this.modules) {
|
509
|
-
return []
|
510
|
-
}
|
511
|
-
// const baseName = path.basename(this.config.fileName, '.json')
|
512
|
-
|
513
|
-
let address: string | undefined
|
514
|
-
for (const module of this.modules) {
|
515
|
-
address = module.address
|
516
|
-
}
|
517
|
-
if (!address) {
|
518
|
-
return []
|
519
|
-
}
|
520
|
-
|
521
|
-
const imports = `
|
522
|
-
import { CallFilter, TypeDescriptor, ANY_TYPE, MoveFetchConfig } from "@sentio/sdk/move"
|
523
|
-
import {
|
524
|
-
MoveCoder, defaultMoveCoder, ${this.moduleGen.PREFIX}BindOptions, ${this.moduleGen.PREFIX}BaseProcessor,
|
525
|
-
TypedEventInstance, ${this.moduleGen.PREFIX}Network, TypedFunctionPayload,
|
526
|
-
${this.moduleGen.PREFIX}Context } from "@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}"
|
527
|
-
import { ModuleClient } from "@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}"
|
528
|
-
`
|
529
|
-
|
530
|
-
const dependedAccounts: string[] = []
|
531
|
-
|
532
|
-
const moduleImports: string[] = []
|
533
|
-
|
534
|
-
const info = this.loader.accountImports.get(address)
|
535
|
-
|
536
|
-
if (info) {
|
537
|
-
for (const [account] of info.imports.entries()) {
|
538
|
-
// Remap to user's filename if possible, TODO codepath not well tested
|
539
|
-
const tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)
|
540
|
-
if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {
|
541
|
-
// Decide where to find runtime library
|
542
|
-
moduleImports.push(`import { _${account} } from "@sentio/sdk/${this.moduleGen.PREFIX.toLowerCase()}/builtin"`)
|
543
|
-
} else {
|
544
|
-
moduleImports.push(`import * as _${account} from "${tsAccountModule}.js"`)
|
545
|
-
}
|
546
|
-
|
547
|
-
dependedAccounts.push(account)
|
548
|
-
}
|
549
|
-
}
|
550
|
-
|
551
|
-
let loadAllTypes = `loadAllTypes(defaultMoveCoder(${
|
552
|
-
this.moduleGen.PREFIX
|
553
|
-
}Network.${this.moduleGen.generateNetworkOption(this.config.network)}))`
|
554
|
-
|
555
|
-
if (this.moduleGen.SYSTEM_MODULES.has(address)) {
|
556
|
-
loadAllTypes = `
|
557
|
-
loadAllTypes(defaultMoveCoder(${this.moduleGen.PREFIX}Network.MAIN_NET))
|
558
|
-
loadAllTypes(defaultMoveCoder(${this.moduleGen.PREFIX}Network.TEST_NET))
|
559
|
-
`
|
560
|
-
}
|
561
|
-
|
562
|
-
const eventsMap: Map<string, InternalMoveStruct> = this.moduleGen.chainAdapter.getAllEventStructs(this.modules)
|
563
|
-
|
564
|
-
const source = `
|
565
|
-
/* Autogenerated file. Do not edit manually. */
|
566
|
-
/* tslint:disable */
|
567
|
-
/* eslint-disable */
|
568
|
-
|
569
|
-
/* Generated modules for account ${address} */
|
570
|
-
|
571
|
-
${imports}
|
572
|
-
|
573
|
-
${moduleImports.join('\n')}
|
574
|
-
|
575
|
-
${this.modules.map((m) => this.moduleGen.generateModule(m, eventsMap, this.config.network)).join('\n')}
|
576
|
-
|
577
|
-
const MODULES = JSON.parse('${JSON.stringify(this.abi)}')
|
578
|
-
|
579
|
-
export function loadAllTypes(coder: MoveCoder) {
|
580
|
-
${dependedAccounts.map((a) => `_${a}.loadAllTypes(coder)`).join('\n')}
|
581
|
-
for (const m of Object.values(MODULES)) {
|
582
|
-
coder.load(m as any)
|
583
|
-
}
|
584
|
-
}
|
585
|
-
|
586
|
-
${loadAllTypes}
|
587
|
-
` // source
|
588
|
-
|
589
|
-
return [
|
590
|
-
{
|
591
|
-
fileName: this.config.fileName + '.ts',
|
592
|
-
fileContent: source,
|
593
|
-
},
|
594
|
-
]
|
595
|
-
}
|
596
|
-
}
|