@sentio/sdk 1.20.1 → 1.21.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/aptos/aptos-processor.d.ts +17 -12
- package/lib/aptos/aptos-processor.js +65 -13
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/bind-options.d.ts +0 -6
- package/lib/aptos/bind-options.js +1 -8
- package/lib/aptos/bind-options.js.map +1 -1
- package/lib/aptos/context.d.ts +5 -4
- package/lib/aptos/context.js +9 -6
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/index.d.ts +3 -2
- package/lib/aptos/index.js +1 -2
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/runtime.d.ts +2 -0
- package/lib/aptos/runtime.js +16 -0
- package/lib/aptos/runtime.js.map +1 -0
- package/lib/aptos/types.d.ts +28 -0
- package/lib/aptos/types.js +159 -0
- package/lib/aptos/types.js.map +1 -0
- package/lib/aptos/utils.d.ts +6 -0
- package/lib/aptos/utils.js +19 -0
- package/lib/aptos/utils.js.map +1 -0
- package/lib/aptos-codegen/codegen.d.ts +5 -2
- package/lib/aptos-codegen/codegen.js +195 -18
- package/lib/aptos-codegen/codegen.js.map +1 -1
- package/lib/aptos-codegen/typegen.d.ts +18 -0
- package/lib/aptos-codegen/typegen.js +196 -0
- package/lib/aptos-codegen/typegen.js.map +1 -0
- package/lib/binds.d.ts +2 -3
- package/lib/binds.js +6 -33
- package/lib/binds.js.map +1 -1
- package/lib/builtin/aptos/0x1.d.ts +1624 -0
- package/lib/builtin/aptos/0x1.js +2502 -0
- package/lib/builtin/aptos/0x1.js.map +1 -0
- package/lib/builtin/aptos/0x3.d.ts +414 -0
- package/lib/builtin/aptos/0x3.js +461 -0
- package/lib/builtin/aptos/0x3.js.map +1 -0
- package/lib/builtin/internal/eacaggregatorproxy_processor.d.ts +2 -2
- package/lib/builtin/internal/eacaggregatorproxy_processor.js +12 -11
- package/lib/builtin/internal/eacaggregatorproxy_processor.js.map +1 -1
- package/lib/builtin/internal/erc20_processor.d.ts +2 -2
- package/lib/builtin/internal/erc20_processor.js +12 -11
- package/lib/builtin/internal/erc20_processor.js.map +1 -1
- package/lib/builtin/internal/erc20bytes_processor.d.ts +2 -2
- package/lib/builtin/internal/erc20bytes_processor.js +12 -11
- package/lib/builtin/internal/erc20bytes_processor.js.map +1 -1
- package/lib/builtin/internal/weth9_processor.d.ts +2 -2
- package/lib/builtin/internal/weth9_processor.js +12 -11
- package/lib/builtin/internal/weth9_processor.js.map +1 -1
- package/lib/builtin/solana/types.d.ts +5 -5
- package/lib/builtin/solana/wormhole-processor.d.ts +6 -6
- package/lib/builtin/solana/wormhole-processor.js +15 -12
- package/lib/builtin/solana/wormhole-processor.js.map +1 -1
- package/lib/cli/build.js +17 -16
- package/lib/cli/build.js.map +1 -1
- package/lib/core/base-processor-template.d.ts +7 -7
- package/lib/core/base-processor-template.js.map +1 -1
- package/lib/core/base-processor.d.ts +5 -6
- package/lib/core/base-processor.js +6 -4
- package/lib/core/base-processor.js.map +1 -1
- package/lib/core/big-decimal.d.ts +1 -0
- package/lib/core/big-decimal.js +6 -0
- package/lib/core/big-decimal.js.map +1 -0
- package/lib/core/bind-options.d.ts +0 -2
- package/lib/core/bind-options.js +4 -4
- package/lib/core/bind-options.js.map +1 -1
- package/lib/core/context.d.ts +14 -11
- package/lib/core/context.js +28 -19
- package/lib/core/context.js.map +1 -1
- package/lib/core/generic-processor.js +5 -5
- package/lib/core/generic-processor.js.map +1 -1
- package/lib/core/index.d.ts +5 -5
- package/lib/core/index.js +6 -6
- package/lib/core/index.js.map +1 -1
- package/lib/core/logger.d.ts +2 -3
- package/lib/core/logger.js +6 -6
- package/lib/core/logger.js.map +1 -1
- package/lib/core/metadata.d.ts +7 -4
- package/lib/core/metadata.js +13 -10
- package/lib/core/metadata.js.map +1 -1
- package/lib/core/meter.d.ts +4 -7
- package/lib/core/meter.js +12 -13
- package/lib/core/meter.js.map +1 -1
- package/lib/core/solana-processor.d.ts +7 -4
- package/lib/core/solana-processor.js +14 -20
- package/lib/core/solana-processor.js.map +1 -1
- package/lib/core/sui-processor.d.ts +5 -4
- package/lib/core/sui-processor.js +10 -17
- package/lib/core/sui-processor.js.map +1 -1
- package/lib/error.d.ts +2 -2
- package/lib/error.js.map +1 -1
- package/lib/gen/processor/protos/processor.d.ts +23 -12
- package/lib/gen/processor/protos/processor.js +129 -57
- package/lib/gen/processor/protos/processor.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.js +1 -4
- package/lib/index.js.map +1 -1
- package/lib/processor-state.d.ts +1 -1
- package/lib/processor-state.js.map +1 -1
- package/lib/service.js +13 -12
- package/lib/service.js.map +1 -1
- package/lib/target-ethers-sentio/codegen.js +14 -15
- package/lib/target-ethers-sentio/codegen.js.map +1 -1
- package/lib/test-abi-code-gen.js.map +1 -1
- package/lib/testing/metric-utils.js +2 -2
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/tests/aptos.test.js +95 -2
- package/lib/tests/aptos.test.js.map +1 -1
- package/lib/tests/erc20.js +1 -1
- package/lib/tests/erc20.js.map +1 -1
- package/lib/tests/erc20.test.js +3 -4
- package/lib/tests/erc20.test.js.map +1 -1
- package/lib/tests/solana.test.js +5 -1
- package/lib/tests/solana.test.js.map +1 -1
- package/lib/tests/souffl3.js +17 -4
- package/lib/tests/souffl3.js.map +1 -1
- package/lib/tests/sui.test.js +1 -4
- package/lib/tests/sui.test.js.map +1 -1
- package/lib/tests/types/aptos/souffle.d.ts +311 -22
- package/lib/tests/types/aptos/souffle.js +142 -6
- package/lib/tests/types/aptos/souffle.js.map +1 -1
- package/lib/tests/types/solana/basic_1_processor.d.ts +2 -2
- package/lib/tests/types/solana/basic_1_processor.js +4 -4
- package/lib/tests/types/solana/basic_1_processor.js.map +1 -1
- package/lib/tests/wormhole-token-bridge.js +2 -1
- package/lib/tests/wormhole-token-bridge.js.map +1 -1
- package/lib/utils/chain.d.ts +1 -0
- package/lib/utils/chain.js +15 -1
- package/lib/utils/chain.js.map +1 -1
- package/lib/utils/conversion.d.ts +1 -1
- package/lib/utils/conversion.js.map +1 -1
- package/package.json +3 -2
- package/src/abis/aptos/0x1.json +9205 -0
- package/src/abis/aptos/0x3.json +1515 -0
- package/src/aptos/aptos-processor.ts +88 -20
- package/src/aptos/bind-options.ts +0 -7
- package/src/aptos/context.ts +11 -8
- package/src/aptos/index.ts +3 -2
- package/src/aptos/runtime.ts +13 -0
- package/src/aptos/types.ts +203 -0
- package/src/aptos/utils.ts +18 -0
- package/src/aptos-codegen/codegen.ts +222 -19
- package/src/aptos-codegen/typegen.test.ts +29 -0
- package/src/aptos-codegen/typegen.ts +216 -0
- package/src/binds.ts +5 -39
- package/src/builtin/aptos/0x1.ts +3760 -0
- package/src/builtin/aptos/0x3.ts +798 -0
- package/src/builtin/internal/eacaggregatorproxy_processor.ts +14 -31
- package/src/builtin/internal/erc20_processor.ts +14 -25
- package/src/builtin/internal/erc20bytes_processor.ts +14 -25
- package/src/builtin/internal/weth9_processor.ts +14 -25
- package/src/builtin/solana/wormhole-processor.ts +21 -18
- package/src/cli/build.ts +19 -17
- package/src/core/base-processor-template.ts +7 -7
- package/src/core/base-processor.ts +30 -9
- package/src/core/big-decimal.ts +1 -0
- package/src/core/bind-options.ts +3 -2
- package/src/core/context.ts +40 -24
- package/src/core/generic-processor.ts +6 -7
- package/src/core/index.ts +5 -5
- package/src/core/logger.ts +7 -7
- package/src/core/metadata.ts +14 -12
- package/src/core/meter.ts +12 -14
- package/src/core/solana-processor.ts +24 -21
- package/src/core/sui-processor.ts +10 -21
- package/src/error.ts +2 -2
- package/src/gen/processor/protos/processor.ts +158 -68
- package/src/index.ts +1 -2
- package/src/processor-state.ts +1 -1
- package/src/service.ts +22 -15
- package/src/target-ethers-sentio/codegen.ts +14 -15
- package/src/test-abi-code-gen.ts +1 -0
- package/src/testing/metric-utils.ts +2 -2
- package/src/tests/aptos.test.ts +102 -3
- package/src/tests/erc20.test.ts +3 -4
- package/src/tests/erc20.ts +1 -1
- package/src/tests/solana.test.ts +5 -1
- package/src/tests/souffl3.ts +21 -6
- package/src/tests/sui.test.ts +1 -4
- package/src/tests/types/aptos/souffle.ts +424 -42
- package/src/tests/types/solana/basic_1_processor.ts +6 -6
- package/src/tests/wormhole-token-bridge.ts +2 -1
- package/src/types/global.d.ts +1 -1
- package/src/utils/chain.ts +14 -0
- package/src/utils/conversion.ts +1 -1
- package/lib/contract-namer.d.ts +0 -6
- package/lib/contract-namer.js +0 -20
- package/lib/contract-namer.js.map +0 -1
- package/src/aptos-codegen/codgen.test.ts +0 -11
- package/src/contract-namer.ts +0 -17
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/aptos/utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,QAAQ,GAAG,IAAI,CAAA;AAEf,QAAA,UAAU,GAAG,QAAQ,CAAA;AAElC,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,KAAK,CAAA;AACpE,CAAC;AAFD,gDAEC;AAED,SAAgB,WAAW,CAAC,MAAkB;IAC5C,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,gBAAQ,GAAG,MAAM,CAAC,IAAI,CAAA;AAC9D,CAAC;AAFD,kCAEC;AAED,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7B,CAAC;AAHD,gDAGC","sourcesContent":["import { MoveModule } from 'aptos/src/generated'\n\nexport const SPLITTER = '::'\n\nexport const VECTOR_STR = 'vector'\n\nexport function isFrameworkAccount(account: string) {\n return account === '0x1' || account === '0x2' || account === '0x3'\n}\n\nexport function moduleQname(module: MoveModule): string {\n return module.address.toLowerCase() + SPLITTER + module.name\n}\n\nexport function moduleQnameForType(type: string): [string, string] {\n const parts = type.split(SPLITTER).slice(0, 2)\n return [parts[0], parts[1]]\n}\n"]}
|
@@ -1,12 +1,15 @@
|
|
1
1
|
import { MoveModuleBytecode } from 'aptos/src/generated';
|
2
|
+
import { AccountRegister } from './typegen';
|
3
|
+
export declare function generate(srcDir: string, outputDir: string): void;
|
2
4
|
interface Config {
|
3
5
|
srcFile: string;
|
4
6
|
outputDir: string;
|
5
7
|
}
|
6
|
-
export declare class
|
8
|
+
export declare class AccountCodegen {
|
7
9
|
modules: MoveModuleBytecode[];
|
8
10
|
config: Config;
|
9
|
-
|
11
|
+
loader: AccountRegister;
|
12
|
+
constructor(loader: AccountRegister, config: Config);
|
10
13
|
generate(): void;
|
11
14
|
}
|
12
15
|
export {};
|
@@ -3,22 +3,67 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.
|
6
|
+
exports.AccountCodegen = exports.generate = void 0;
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
8
8
|
const path_1 = __importDefault(require("path"));
|
9
9
|
const prettier_1 = __importDefault(require("prettier"));
|
10
|
-
|
10
|
+
const typegen_1 = require("./typegen");
|
11
|
+
const utils_1 = require("../aptos/utils");
|
12
|
+
function generate(srcDir, outputDir) {
|
13
|
+
const files = fs_1.default.readdirSync(srcDir);
|
14
|
+
outputDir = path_1.default.resolve(outputDir);
|
15
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
16
|
+
const loader = new typegen_1.AccountRegister();
|
17
|
+
// The first path, identify import relation and module name (filename) of those imports
|
18
|
+
for (const file of files) {
|
19
|
+
if (!file.endsWith('.json')) {
|
20
|
+
continue;
|
21
|
+
}
|
22
|
+
// Reading file is duplicated, but since they are small files probably file
|
23
|
+
// TODO add file manager class
|
24
|
+
const json = fs_1.default.readFileSync(path_1.default.join(srcDir, file), 'utf-8');
|
25
|
+
const modules = JSON.parse(json);
|
26
|
+
for (const module of modules) {
|
27
|
+
if (module.abi) {
|
28
|
+
loader.register(module.abi, path_1.default.basename(file, '.json'));
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
for (const file of files) {
|
33
|
+
if (!file.endsWith('.json')) {
|
34
|
+
continue;
|
35
|
+
}
|
36
|
+
const codeGen = new AccountCodegen(loader, {
|
37
|
+
srcFile: path_1.default.join(srcDir, file),
|
38
|
+
outputDir: outputDir,
|
39
|
+
});
|
40
|
+
codeGen.generate();
|
41
|
+
}
|
42
|
+
// when generating user code, don't need to generate framework account
|
43
|
+
loader.pendingAccounts.delete('0x1');
|
44
|
+
loader.pendingAccounts.delete('0x2');
|
45
|
+
loader.pendingAccounts.delete('0x3');
|
46
|
+
if (loader.pendingAccounts.size > 0) {
|
47
|
+
// TODO automatic download dependencies
|
48
|
+
console.error('Missing ABIs from the following accounts', loader.pendingAccounts);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
exports.generate = generate;
|
52
|
+
class AccountCodegen {
|
11
53
|
modules;
|
12
54
|
config;
|
13
|
-
|
55
|
+
loader;
|
56
|
+
constructor(loader, config) {
|
14
57
|
const json = fs_1.default.readFileSync(config.srcFile, 'utf-8');
|
15
58
|
this.modules = JSON.parse(json);
|
16
59
|
this.config = config;
|
60
|
+
this.loader = loader;
|
17
61
|
}
|
18
62
|
generate() {
|
19
63
|
if (!this.modules) {
|
20
64
|
return;
|
21
65
|
}
|
66
|
+
const baseName = path_1.default.basename(this.config.srcFile, '.json');
|
22
67
|
let address;
|
23
68
|
for (const module of this.modules) {
|
24
69
|
if (module.abi && module.abi.address) {
|
@@ -28,7 +73,32 @@ class AptosCodegen {
|
|
28
73
|
if (!address) {
|
29
74
|
return;
|
30
75
|
}
|
31
|
-
const imports = `
|
76
|
+
const imports = `
|
77
|
+
import { aptos } from "@sentio/sdk"
|
78
|
+
import { Address, MoveModule } from "aptos/src/generated"
|
79
|
+
`;
|
80
|
+
const dependedAccounts = [];
|
81
|
+
const moduleImports = [];
|
82
|
+
const info = this.loader.accountImports.get(address);
|
83
|
+
if (info) {
|
84
|
+
for (const [account, moduleImported] of info.imports.entries()) {
|
85
|
+
// Remap to user's filename if possible, TODO codepath not well tested
|
86
|
+
let tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account);
|
87
|
+
if ((0, utils_1.isFrameworkAccount)(account) && !(0, utils_1.isFrameworkAccount)(address)) {
|
88
|
+
// Decide where to find runtime library
|
89
|
+
let srcRoot = 'lib';
|
90
|
+
if (__dirname.includes('sdk/src/aptos-codegen')) {
|
91
|
+
srcRoot = 'src';
|
92
|
+
}
|
93
|
+
tsAccountModule = `@sentio/sdk/${srcRoot}/builtin/aptos/${account}`;
|
94
|
+
}
|
95
|
+
const items = Array.from(moduleImported);
|
96
|
+
moduleImports.push(`import { ${items.join(',')} } from "${tsAccountModule}"`);
|
97
|
+
// Ideally we should use per module's load types, but it doesn't matter since we are loading the entire
|
98
|
+
// account modules anyway
|
99
|
+
items.forEach((m) => dependedAccounts.push(m));
|
100
|
+
}
|
101
|
+
}
|
32
102
|
let source = `
|
33
103
|
/* Autogenerated file. Do not edit manually. */
|
34
104
|
/* tslint:disable */
|
@@ -38,43 +108,147 @@ class AptosCodegen {
|
|
38
108
|
|
39
109
|
${imports}
|
40
110
|
|
41
|
-
${
|
111
|
+
${moduleImports.join('\n')}
|
112
|
+
|
113
|
+
${this.modules.map((m) => generateModule(m, dependedAccounts)).join('\n')}
|
114
|
+
|
115
|
+
function loadAllTypes(registry: aptos.TypeRegistry) {
|
116
|
+
${dependedAccounts.map((m) => `${m}.loadTypes(registry)`).join('\n')}
|
117
|
+
|
118
|
+
${this.modules
|
119
|
+
.map((m) => {
|
120
|
+
return `registry.load(${m.abi?.name}.ABI)`;
|
121
|
+
})
|
122
|
+
.join('\n')}
|
123
|
+
}
|
42
124
|
`; // source
|
43
|
-
const baseName = path_1.default.basename(this.config.srcFile, '.json');
|
44
125
|
source = prettier_1.default.format(source, { parser: 'typescript' });
|
45
126
|
fs_1.default.writeFileSync(path_1.default.join(this.config.outputDir, baseName + '.ts'), source);
|
46
127
|
}
|
47
128
|
}
|
48
|
-
exports.
|
49
|
-
function generateModule(moduleByteCode) {
|
129
|
+
exports.AccountCodegen = AccountCodegen;
|
130
|
+
function generateModule(moduleByteCode, dependedModules) {
|
50
131
|
if (!moduleByteCode.abi) {
|
51
132
|
return '';
|
52
133
|
}
|
53
134
|
const module = moduleByteCode.abi;
|
54
135
|
const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '');
|
55
136
|
const events = module.structs.map((e) => generateOnEvents(module, e)).filter((s) => s !== '');
|
56
|
-
|
57
|
-
|
58
|
-
|
137
|
+
const structs = module.structs.map((s) => generateStructs(module, s));
|
138
|
+
const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f));
|
139
|
+
let processor = '';
|
140
|
+
if (functions.length > 0 || events.length > 0) {
|
141
|
+
processor = `export class ${module.name} extends aptos.AptosBaseProcessor {
|
142
|
+
|
143
|
+
constructor(options: aptos.AptosBindOptions) {
|
144
|
+
super("${module.name}", options)
|
145
|
+
}
|
146
|
+
static DEFAULT_OPTIONS: aptos.AptosBindOptions = {
|
59
147
|
address: "${module.address}",
|
60
148
|
network: aptos.AptosNetwork.TEST_NET
|
61
149
|
}
|
62
|
-
|
63
|
-
|
150
|
+
|
151
|
+
static bind(options: Partial<aptos.AptosBindOptions> = {}): ${module.name} {
|
152
|
+
return new ${module.name}({ ...${module.name}.DEFAULT_OPTIONS, ...options })
|
64
153
|
}
|
65
154
|
|
66
155
|
${functions.join('\n')}
|
67
156
|
|
68
157
|
${events.join('\n')}
|
69
|
-
|
158
|
+
|
159
|
+
loadTypesInternal(registry: aptos.TypeRegistry) {
|
160
|
+
loadAllTypes(registry)
|
161
|
+
}
|
162
|
+
}
|
163
|
+
`;
|
164
|
+
}
|
165
|
+
return `
|
166
|
+
${processor}
|
167
|
+
|
168
|
+
export namespace ${module.name} {
|
169
|
+
${structs.join('\n')}
|
170
|
+
|
171
|
+
${callArgs.join('\n')}
|
172
|
+
|
173
|
+
export function loadTypes(registry: aptos.TypeRegistry) {
|
174
|
+
loadAllTypes(registry)
|
175
|
+
}
|
176
|
+
export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')
|
177
|
+
}
|
178
|
+
`;
|
179
|
+
}
|
180
|
+
function generateStructs(module, struct) {
|
181
|
+
const genericString = generateStructTypeParameters(struct);
|
182
|
+
const fields = struct.fields.map((field) => {
|
183
|
+
return `${field.name}: ${(0, typegen_1.generateType)(field.type)}`;
|
184
|
+
});
|
185
|
+
let eventPayload = '';
|
186
|
+
if (isEvent(struct)) {
|
187
|
+
eventPayload = `
|
188
|
+
export interface ${struct.name}Instance${genericString} extends
|
189
|
+
aptos.TypedEventInstance<${struct.name}${genericString}> {
|
190
|
+
data_typed: ${struct.name}${genericString}
|
191
|
+
}
|
192
|
+
`;
|
193
|
+
}
|
194
|
+
return `
|
195
|
+
export class ${struct.name}${genericString} {
|
196
|
+
${fields.join('\n')}
|
197
|
+
}
|
198
|
+
|
199
|
+
${eventPayload}
|
200
|
+
`;
|
201
|
+
}
|
202
|
+
function generateFunctionTypeParameters(func) {
|
203
|
+
let genericString = '';
|
204
|
+
if (func.generic_type_params && func.generic_type_params.length > 0) {
|
205
|
+
const params = func.generic_type_params
|
206
|
+
.map((v, idx) => {
|
207
|
+
return 'T' + idx;
|
208
|
+
})
|
209
|
+
.join(',');
|
210
|
+
genericString = `<${params}>`;
|
211
|
+
}
|
212
|
+
return genericString;
|
213
|
+
}
|
214
|
+
function generateStructTypeParameters(struct) {
|
215
|
+
let genericString = '';
|
216
|
+
if (struct.generic_type_params && struct.generic_type_params.length > 0) {
|
217
|
+
const params = struct.generic_type_params
|
218
|
+
.map((v, idx) => {
|
219
|
+
return 'T' + idx;
|
220
|
+
})
|
221
|
+
.join(',');
|
222
|
+
genericString = `<${params}>`;
|
223
|
+
}
|
224
|
+
return genericString;
|
225
|
+
}
|
226
|
+
function generateCallArgsStructs(module, func) {
|
227
|
+
if (!func.is_entry) {
|
228
|
+
return;
|
229
|
+
}
|
230
|
+
// the first param is always signer so ignore
|
231
|
+
// TODO check if there is any edge case
|
232
|
+
const fields = func.params.slice(1).map((param) => {
|
233
|
+
return `${(0, typegen_1.generateType)(param)}`;
|
234
|
+
});
|
235
|
+
const camelFuncName = capitalizeFirstChar(camelize(func.name));
|
236
|
+
const genericString = generateFunctionTypeParameters(func);
|
237
|
+
return `
|
238
|
+
export interface ${camelFuncName}Payload${genericString}
|
239
|
+
extends aptos.TypedEntryFunctionPayload<[${fields.join(',')}]> {
|
240
|
+
arguments_typed: [${fields.join(',')}]
|
241
|
+
}
|
242
|
+
`;
|
70
243
|
}
|
71
244
|
function generateOnEntryFunctions(module, func) {
|
72
245
|
if (!func.is_entry) {
|
73
246
|
return '';
|
74
247
|
}
|
248
|
+
const genericString = generateFunctionTypeParameters(func);
|
75
249
|
const camelFuncName = capitalizeFirstChar(camelize(func.name));
|
76
250
|
const source = `
|
77
|
-
onEntry${camelFuncName}(func: (call:
|
251
|
+
onEntry${camelFuncName}${genericString}(func: (call: ${module.name}.${camelFuncName}Payload${genericString}, ctx: aptos.AptosContext) => void): ${module.name} {
|
78
252
|
this.onEntryFunctionCall(func, {
|
79
253
|
function: '${module.name}::${func.name}'
|
80
254
|
})
|
@@ -82,15 +256,18 @@ function generateOnEntryFunctions(module, func) {
|
|
82
256
|
}`;
|
83
257
|
return source;
|
84
258
|
}
|
259
|
+
function isEvent(struct) {
|
260
|
+
return struct.abilities.includes('drop') && struct.abilities.includes('store') && struct.name.endsWith('Event');
|
261
|
+
}
|
85
262
|
function generateOnEvents(module, struct) {
|
86
263
|
// for struct that has drop + store
|
87
|
-
if (!
|
264
|
+
if (!isEvent(struct)) {
|
88
265
|
return '';
|
89
266
|
}
|
90
267
|
const source = `
|
91
|
-
onEvent${struct.name}(func: (event:
|
268
|
+
onEvent${struct.name}(func: (event: ${module.name}.${struct.name}Instance, ctx: aptos.AptosContext) => void): ${module.name} {
|
92
269
|
this.onEvent(func, {
|
93
|
-
type: '${module.
|
270
|
+
type: '${module.name}::${struct.name}'
|
94
271
|
})
|
95
272
|
return this
|
96
273
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/codegen.ts"],"names":[],"mappings":";;;;;;AACA,4CAAmB;AACnB,gDAAuB;AAGvB,wDAA+B;AAO/B,MAAa,YAAY;IACvB,OAAO,CAAsB;IAC7B,MAAM,CAAQ;IAEd,YAAY,MAAc;QACxB,MAAM,IAAI,GAAG,YAAE,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACrD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,OAAM;SACP;QACD,IAAI,OAA2B,CAAA;QAC/B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE;YACjC,IAAI,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE;gBACpC,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAA;aAC7B;SACF;QACD,IAAI,CAAC,OAAO,EAAE;YACZ,OAAM;SACP;QAED,MAAM,OAAO,GAAG,qCAAqC,CAAA;QAErD,IAAI,MAAM,GAAG;;;;;uCAKsB,OAAO;;MAExC,OAAO;;MAEP,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;KAC5C,CAAA,CAAC,SAAS;QAEX,MAAM,QAAQ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A;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAK,CAAA;KACb;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import { MoveModuleBytecode } from 'aptos/src/generated'\nimport fs from 'fs'\nimport path from 'path'\nimport { MoveFunction, MoveModule } from 'aptos/src/generated'\nimport { MoveStruct } from 'aptos/src/generated/models/MoveStruct'\nimport prettier from 'prettier'\n\ninterface Config {\n srcFile: string\n outputDir: string\n}\n\nexport class AptosCodegen {\n modules: MoveModuleBytecode[]\n config: Config\n\n constructor(config: Config) {\n const json = fs.readFileSync(config.srcFile, 'utf-8')\n this.modules = JSON.parse(json)\n this.config = config\n }\n\n generate() {\n if (!this.modules) {\n return\n }\n let address: string | undefined\n for (const module of this.modules) {\n if (module.abi && module.abi.address) {\n address = module.abi.address\n }\n }\n if (!address) {\n return\n }\n\n const imports = `import { aptos } from \"@sentio/sdk\"`\n\n let source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n \n /* Generated modules for account ${address} */\n \n ${imports}\n \n ${this.modules.map(generateModule).join('\\n')}\n ` // source\n\n const baseName = path.basename(this.config.srcFile, '.json')\n source = prettier.format(source, { parser: 'typescript' })\n fs.writeFileSync(path.join(this.config.outputDir, baseName + '.ts'), source)\n }\n}\n\nfunction generateModule(moduleByteCode: MoveModuleBytecode) {\n if (!moduleByteCode.abi) {\n return ''\n }\n const module = moduleByteCode.abi\n\n const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')\n const events = module.structs.map((e) => generateOnEvents(module, e)).filter((s) => s !== '')\n\n return `\n export class ${module.name} extends aptos.AptosBaseProcessor {\n static DEFAULT_OPTIONS: aptos.NamedAptosBindOptions = {\n address: \"${module.address}\",\n network: aptos.AptosNetwork.TEST_NET \n }\n static bind(options = ${module.name}.DEFAULT_OPTIONS): ${module.name} {\n return new ${module.name}({ ...options, name: \"${module.name}\" })\n }\n \n ${functions.join('\\n')}\n \n ${events.join('\\n')}\n }`\n}\n\nfunction generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return ''\n }\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n const source = `\n onEntry${camelFuncName}(func: (call: aptos.TransactionPayload_EntryFunctionPayload, ctx: aptos.AptosContext) => void): ${module.name} {\n this.onEntryFunctionCall(func, {\n function: '${module.name}::${func.name}'\n })\n return this\n }`\n\n return source\n}\n\nfunction generateOnEvents(module: MoveModule, struct: MoveStruct): string {\n // for struct that has drop + store\n if (!struct.abilities.includes('drop') || !struct.abilities.includes('store') || !struct.name.endsWith('Event')) {\n return ''\n }\n const source = `\n onEvent${struct.name}(func: (event: aptos.Event, ctx: aptos.AptosContext) => void): ${module.name} {\n this.onEvent(func, {\n type: '${module.address}::${module.name}::${struct.name}'\n })\n return this\n }\n `\n return source\n}\n\nfunction camelize(input: string): string {\n return input\n .split('_')\n .reduce(\n (res, word, i) =>\n i === 0 ? word.toLowerCase() : `${res}${word.charAt(0).toUpperCase()}${word.substr(1).toLowerCase()}`,\n ''\n )\n}\n\nfunction capitalizeFirstChar(input: string): string {\n if (!input) {\n return input\n }\n return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')\n}\n"]}
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/codegen.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,wDAA+B;AAE/B,uCAAyD;AACzD,0CAAmD;AAEnD,SAAgB,QAAQ,CAAC,MAAc,EAAE,SAAiB;IACxD,MAAM,KAAK,GAAG,YAAE,CAAC,WA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C;AAED,SAAS,gBAAgB,CAAC,MAAkB,EAAE,MAAkB;IAC9D,mCAAmC;IACnC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACpB,OAAO,EAAE,CAAA;KACV;IACD,MAAM,MAAM,GAAG;WACN,MAAM,CAAC,IAAI,kBAAkB,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,gDAAgD,MAAM,CAAC,IAAI;;eAE9G,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI;;;;GAIvC,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa;IAC7B,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CACL,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,CACf,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,EAAE,EACvG,EAAE,CACH,CAAA;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAK,CAAA;KACb;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport prettier from 'prettier'\nimport { MoveFunction, MoveModule, MoveStruct, MoveModuleBytecode } from 'aptos/src/generated'\nimport { generateType, AccountRegister } from './typegen'\nimport { isFrameworkAccount } from '../aptos/utils'\n\nexport function generate(srcDir: string, outputDir: string) {\n const files = fs.readdirSync(srcDir)\n outputDir = path.resolve(outputDir)\n\n fs.mkdirSync(outputDir, { recursive: true })\n\n const loader = new AccountRegister()\n\n // The first path, identify import relation and module name (filename) of those imports\n for (const file of files) {\n if (!file.endsWith('.json')) {\n continue\n }\n // Reading file is duplicated, but since they are small files probably file\n // TODO add file manager class\n const json = fs.readFileSync(path.join(srcDir, file), 'utf-8')\n const modules = JSON.parse(json)\n\n for (const module of modules) {\n if (module.abi) {\n loader.register(module.abi, path.basename(file, '.json'))\n }\n }\n }\n\n for (const file of files) {\n if (!file.endsWith('.json')) {\n continue\n }\n const codeGen = new AccountCodegen(loader, {\n srcFile: path.join(srcDir, file),\n outputDir: outputDir,\n })\n\n codeGen.generate()\n }\n\n // when generating user code, don't need to generate framework account\n loader.pendingAccounts.delete('0x1')\n loader.pendingAccounts.delete('0x2')\n loader.pendingAccounts.delete('0x3')\n\n if (loader.pendingAccounts.size > 0) {\n // TODO automatic download dependencies\n console.error('Missing ABIs from the following accounts', loader.pendingAccounts)\n }\n}\n\ninterface Config {\n srcFile: string\n outputDir: string\n}\n\nexport class AccountCodegen {\n modules: MoveModuleBytecode[]\n config: Config\n loader: AccountRegister\n\n constructor(loader: AccountRegister, config: Config) {\n const json = fs.readFileSync(config.srcFile, 'utf-8')\n this.modules = JSON.parse(json)\n this.config = config\n this.loader = loader\n }\n\n generate() {\n if (!this.modules) {\n return\n }\n const baseName = path.basename(this.config.srcFile, '.json')\n\n let address: string | undefined\n for (const module of this.modules) {\n if (module.abi && module.abi.address) {\n address = module.abi.address\n }\n }\n if (!address) {\n return\n }\n\n const imports = `\n import { aptos } from \"@sentio/sdk\"\n import { Address, MoveModule } from \"aptos/src/generated\"\n `\n\n const dependedAccounts: string[] = []\n\n const moduleImports: string[] = []\n\n const info = this.loader.accountImports.get(address)\n\n if (info) {\n for (const [account, moduleImported] of info.imports.entries()) {\n // Remap to user's filename if possible, TODO codepath not well tested\n let tsAccountModule = './' + (this.loader.accountImports.get(account)?.moduleName || account)\n if (isFrameworkAccount(account) && !isFrameworkAccount(address)) {\n // Decide where to find runtime library\n let srcRoot = 'lib'\n if (__dirname.includes('sdk/src/aptos-codegen')) {\n srcRoot = 'src'\n }\n tsAccountModule = `@sentio/sdk/${srcRoot}/builtin/aptos/${account}`\n }\n const items = Array.from(moduleImported)\n moduleImports.push(`import { ${items.join(',')} } from \"${tsAccountModule}\"`)\n\n // Ideally we should use per module's load types, but it doesn't matter since we are loading the entire\n // account modules anyway\n items.forEach((m) => dependedAccounts.push(m))\n }\n }\n\n let source = `\n /* Autogenerated file. Do not edit manually. */\n /* tslint:disable */\n /* eslint-disable */\n \n /* Generated modules for account ${address} */\n \n ${imports}\n \n ${moduleImports.join('\\n')}\n \n ${this.modules.map((m) => generateModule(m, dependedAccounts)).join('\\n')}\n \n function loadAllTypes(registry: aptos.TypeRegistry) {\n ${dependedAccounts.map((m) => `${m}.loadTypes(registry)`).join('\\n')}\n\n ${this.modules\n .map((m) => {\n return `registry.load(${m.abi?.name}.ABI)`\n })\n .join('\\n')}\n }\n ` // source\n\n source = prettier.format(source, { parser: 'typescript' })\n fs.writeFileSync(path.join(this.config.outputDir, baseName + '.ts'), source)\n }\n}\n\nfunction generateModule(moduleByteCode: MoveModuleBytecode, dependedModules: string[]) {\n if (!moduleByteCode.abi) {\n return ''\n }\n const module = moduleByteCode.abi\n\n const functions = module.exposed_functions.map((f) => generateOnEntryFunctions(module, f)).filter((s) => s !== '')\n const events = module.structs.map((e) => generateOnEvents(module, e)).filter((s) => s !== '')\n const structs = module.structs.map((s) => generateStructs(module, s))\n const callArgs = module.exposed_functions.map((f) => generateCallArgsStructs(module, f))\n\n let processor = ''\n if (functions.length > 0 || events.length > 0) {\n processor = `export class ${module.name} extends aptos.AptosBaseProcessor {\n\n constructor(options: aptos.AptosBindOptions) {\n super(\"${module.name}\", options)\n }\n static DEFAULT_OPTIONS: aptos.AptosBindOptions = {\n address: \"${module.address}\",\n network: aptos.AptosNetwork.TEST_NET \n }\n\n static bind(options: Partial<aptos.AptosBindOptions> = {}): ${module.name} {\n return new ${module.name}({ ...${module.name}.DEFAULT_OPTIONS, ...options })\n }\n \n ${functions.join('\\n')}\n \n ${events.join('\\n')}\n \n loadTypesInternal(registry: aptos.TypeRegistry) {\n loadAllTypes(registry)\n }\n }\n `\n }\n\n return `\n ${processor}\n\n export namespace ${module.name} {\n ${structs.join('\\n')}\n \n ${callArgs.join('\\n')}\n \n export function loadTypes(registry: aptos.TypeRegistry) {\n loadAllTypes(registry)\n }\n export const ABI: MoveModule = JSON.parse('${JSON.stringify(module)}')\n }\n `\n}\n\nfunction generateStructs(module: MoveModule, struct: MoveStruct) {\n const genericString = generateStructTypeParameters(struct)\n\n const fields = struct.fields.map((field) => {\n return `${field.name}: ${generateType(field.type)}`\n })\n\n let eventPayload = ''\n if (isEvent(struct)) {\n eventPayload = `\n export interface ${struct.name}Instance${genericString} extends \n aptos.TypedEventInstance<${struct.name}${genericString}> {\n data_typed: ${struct.name}${genericString}\n }\n `\n }\n\n return `\n export class ${struct.name}${genericString} {\n ${fields.join('\\n')} \n }\n \n ${eventPayload}\n `\n}\n\nfunction generateFunctionTypeParameters(func: MoveFunction) {\n let genericString = ''\n if (func.generic_type_params && func.generic_type_params.length > 0) {\n const params = func.generic_type_params\n .map((v, idx) => {\n return 'T' + idx\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n}\n\nfunction generateStructTypeParameters(struct: MoveStruct) {\n let genericString = ''\n\n if (struct.generic_type_params && struct.generic_type_params.length > 0) {\n const params = struct.generic_type_params\n .map((v, idx) => {\n return 'T' + idx\n })\n .join(',')\n genericString = `<${params}>`\n }\n return genericString\n}\n\nfunction generateCallArgsStructs(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return\n }\n\n // the first param is always signer so ignore\n // TODO check if there is any edge case\n const fields = func.params.slice(1).map((param) => {\n return `${generateType(param)}`\n })\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n\n const genericString = generateFunctionTypeParameters(func)\n return `\n export interface ${camelFuncName}Payload${genericString} \n extends aptos.TypedEntryFunctionPayload<[${fields.join(',')}]> {\n arguments_typed: [${fields.join(',')}]\n }\n `\n}\n\nfunction generateOnEntryFunctions(module: MoveModule, func: MoveFunction) {\n if (!func.is_entry) {\n return ''\n }\n\n const genericString = generateFunctionTypeParameters(func)\n\n const camelFuncName = capitalizeFirstChar(camelize(func.name))\n const source = `\n onEntry${camelFuncName}${genericString}(func: (call: ${module.name}.${camelFuncName}Payload${genericString}, ctx: aptos.AptosContext) => void): ${module.name} {\n this.onEntryFunctionCall(func, {\n function: '${module.name}::${func.name}'\n })\n return this\n }`\n\n return source\n}\n\nfunction isEvent(struct: MoveStruct) {\n return struct.abilities.includes('drop') && struct.abilities.includes('store') && struct.name.endsWith('Event')\n}\n\nfunction generateOnEvents(module: MoveModule, struct: MoveStruct): string {\n // for struct that has drop + store\n if (!isEvent(struct)) {\n return ''\n }\n const source = `\n onEvent${struct.name}(func: (event: ${module.name}.${struct.name}Instance, ctx: aptos.AptosContext) => void): ${module.name} {\n this.onEvent(func, {\n type: '${module.name}::${struct.name}'\n })\n return this\n }\n `\n return source\n}\n\nfunction camelize(input: string): string {\n return input\n .split('_')\n .reduce(\n (res, word, i) =>\n i === 0 ? word.toLowerCase() : `${res}${word.charAt(0).toUpperCase()}${word.substr(1).toLowerCase()}`,\n ''\n )\n}\n\nfunction capitalizeFirstChar(input: string): string {\n if (!input) {\n return input\n }\n return input[0].toUpperCase() + (input.length > 1 ? input.substring(1) : '')\n}\n"]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { MoveModule } from 'aptos/src/generated';
|
2
|
+
import { TypeDescriptor } from '../aptos/types';
|
3
|
+
export declare function parseMoveType(type: string): TypeDescriptor;
|
4
|
+
export declare function generateType(type: string, ctx?: any): string;
|
5
|
+
export declare class AccountModulesImportInfo {
|
6
|
+
imports: Map<string, Set<string>>;
|
7
|
+
account: string;
|
8
|
+
moduleName: string;
|
9
|
+
constructor(account: string, tsModuleName: string);
|
10
|
+
addImport(account: string, module: string): void;
|
11
|
+
}
|
12
|
+
export declare class AccountRegister {
|
13
|
+
accountImports: Map<string, AccountModulesImportInfo>;
|
14
|
+
pendingAccounts: Set<string>;
|
15
|
+
typeRegistry: Map<string, TypeDescriptor>;
|
16
|
+
private loadTypeDescriptor;
|
17
|
+
register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo;
|
18
|
+
}
|
@@ -0,0 +1,196 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.AccountRegister = exports.AccountModulesImportInfo = exports.generateType = exports.parseMoveType = void 0;
|
4
|
+
const types_1 = require("../aptos/types");
|
5
|
+
const utils_1 = require("../aptos/utils");
|
6
|
+
function generateTypeForDescriptor(type) {
|
7
|
+
// TODO &signer is defintely an address, but what if &OTHER_TYPE?
|
8
|
+
if (type.qname.startsWith('&')) {
|
9
|
+
return 'Address';
|
10
|
+
}
|
11
|
+
switch (type.qname) {
|
12
|
+
case 'signer': // TODO check this
|
13
|
+
case 'address':
|
14
|
+
return 'Address';
|
15
|
+
case '0x1::string::String':
|
16
|
+
return 'string';
|
17
|
+
case 'bool':
|
18
|
+
return 'Boolean';
|
19
|
+
case 'u8':
|
20
|
+
case 'u16':
|
21
|
+
case 'u32':
|
22
|
+
return 'number';
|
23
|
+
case 'u64':
|
24
|
+
case 'u128':
|
25
|
+
return 'bigint';
|
26
|
+
}
|
27
|
+
if (type.qname === utils_1.VECTOR_STR) {
|
28
|
+
// vector<u8> as hex string
|
29
|
+
const elementTypeQname = type.typeArgs[0].qname;
|
30
|
+
if (elementTypeQname === 'u8') {
|
31
|
+
return 'string';
|
32
|
+
}
|
33
|
+
if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(utils_1.SPLITTER)) {
|
34
|
+
return `${elementTypeQname}[] | string`;
|
35
|
+
}
|
36
|
+
return generateTypeForDescriptor(type.typeArgs[0]) + '[]';
|
37
|
+
}
|
38
|
+
const simpleName = generateSimpleType(type.qname);
|
39
|
+
if (simpleName.length === 0) {
|
40
|
+
console.error('unexpected error');
|
41
|
+
}
|
42
|
+
if (simpleName.includes('vector')) {
|
43
|
+
console.error('unexpected error');
|
44
|
+
}
|
45
|
+
if (type.typeArgs.length > 0) {
|
46
|
+
// return simpleName
|
47
|
+
return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t)).join(',') + '>';
|
48
|
+
}
|
49
|
+
return simpleName;
|
50
|
+
}
|
51
|
+
function generateSimpleType(type) {
|
52
|
+
const parts = type.split(utils_1.SPLITTER);
|
53
|
+
if (parts.length < 2) {
|
54
|
+
return parts[0];
|
55
|
+
}
|
56
|
+
return parts.slice(1).join('.');
|
57
|
+
}
|
58
|
+
function parseMoveType(type) {
|
59
|
+
// type = type.replace('&', '')
|
60
|
+
type = type.replace('&mut ', '&');
|
61
|
+
// TODO replace ' ' is not exactly safe, need to double check this
|
62
|
+
type = type.replace(' ', '');
|
63
|
+
const stack = [new types_1.TypeDescriptor('')];
|
64
|
+
let buffer = [];
|
65
|
+
// xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
|
66
|
+
for (let i = 0; i < type.length; i++) {
|
67
|
+
const ch = type[i];
|
68
|
+
if (ch === '<') {
|
69
|
+
// const symbol = type.slice(symbolStart, i)
|
70
|
+
// symbolStart =
|
71
|
+
const symbol = buffer.join('');
|
72
|
+
buffer = [];
|
73
|
+
stack[stack.length - 1].qname = symbol;
|
74
|
+
stack.push(new types_1.TypeDescriptor(''));
|
75
|
+
continue;
|
76
|
+
}
|
77
|
+
if (ch === '>') {
|
78
|
+
const typeParam = stack.pop();
|
79
|
+
if (!typeParam) {
|
80
|
+
throw Error('Uxpectecd stack size');
|
81
|
+
}
|
82
|
+
if (buffer.length > 0) {
|
83
|
+
typeParam.qname = buffer.join('');
|
84
|
+
buffer = [];
|
85
|
+
}
|
86
|
+
stack[stack.length - 1].typeArgs.push(typeParam);
|
87
|
+
continue;
|
88
|
+
}
|
89
|
+
if (ch === ',') {
|
90
|
+
const typeParam = stack.pop();
|
91
|
+
if (!typeParam) {
|
92
|
+
throw Error('Uxpectecd stack size');
|
93
|
+
}
|
94
|
+
if (buffer.length > 0) {
|
95
|
+
typeParam.qname = buffer.join('');
|
96
|
+
buffer = [];
|
97
|
+
}
|
98
|
+
stack[stack.length - 1].typeArgs.push(typeParam);
|
99
|
+
// continue parse next param
|
100
|
+
stack.push(new types_1.TypeDescriptor(''));
|
101
|
+
continue;
|
102
|
+
}
|
103
|
+
buffer.push(ch);
|
104
|
+
}
|
105
|
+
if (buffer.length > 0) {
|
106
|
+
stack[stack.length - 1].qname = buffer.join('');
|
107
|
+
}
|
108
|
+
const res = stack.pop();
|
109
|
+
if (!res || stack.length > 0) {
|
110
|
+
throw Error('Uxpectecd stack size');
|
111
|
+
}
|
112
|
+
return res;
|
113
|
+
}
|
114
|
+
exports.parseMoveType = parseMoveType;
|
115
|
+
// TODO ctx need to have type parameters
|
116
|
+
function generateType(type, ctx) {
|
117
|
+
return generateTypeForDescriptor(parseMoveType(type));
|
118
|
+
}
|
119
|
+
exports.generateType = generateType;
|
120
|
+
class AccountModulesImportInfo {
|
121
|
+
// account to module
|
122
|
+
imports;
|
123
|
+
account;
|
124
|
+
moduleName;
|
125
|
+
constructor(account, tsModuleName) {
|
126
|
+
this.account = account;
|
127
|
+
this.moduleName = tsModuleName;
|
128
|
+
this.imports = new Map();
|
129
|
+
}
|
130
|
+
addImport(account, module) {
|
131
|
+
if (account === this.account) {
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
let accountModules = this.imports.get(account);
|
135
|
+
if (!accountModules) {
|
136
|
+
accountModules = new Set();
|
137
|
+
this.imports.set(account, accountModules);
|
138
|
+
}
|
139
|
+
accountModules.add(module);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
exports.AccountModulesImportInfo = AccountModulesImportInfo;
|
143
|
+
class AccountRegister {
|
144
|
+
accountImports = new Map();
|
145
|
+
pendingAccounts = new Set();
|
146
|
+
// loadedAccount = new Set<string>()
|
147
|
+
typeRegistry = new Map();
|
148
|
+
loadTypeDescriptor(type) {
|
149
|
+
let descriptor = this.typeRegistry.get(type);
|
150
|
+
// const descriptparseMoveType(type)
|
151
|
+
if (!descriptor) {
|
152
|
+
descriptor = parseMoveType(type);
|
153
|
+
this.typeRegistry.set(type, descriptor);
|
154
|
+
}
|
155
|
+
return descriptor;
|
156
|
+
}
|
157
|
+
register(module, tsModuleName) {
|
158
|
+
const currentModuleFqn = (0, utils_1.moduleQname)(module);
|
159
|
+
let accountModuleImports = this.accountImports.get(module.address);
|
160
|
+
if (!accountModuleImports) {
|
161
|
+
accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName);
|
162
|
+
this.accountImports.set(module.address, accountModuleImports);
|
163
|
+
// the account has already be processed, delete pending task
|
164
|
+
this.pendingAccounts.delete(module.address);
|
165
|
+
}
|
166
|
+
for (const struct of module.structs) {
|
167
|
+
for (const field of struct.fields) {
|
168
|
+
for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {
|
169
|
+
const [account, module] = (0, utils_1.moduleQnameForType)(type);
|
170
|
+
accountModuleImports.addImport(account, module);
|
171
|
+
if (!this.accountImports.has(account)) {
|
172
|
+
this.pendingAccounts.add(account);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
for (const func of module.exposed_functions) {
|
178
|
+
if (!func.is_entry) {
|
179
|
+
continue;
|
180
|
+
}
|
181
|
+
for (const param of func.params) {
|
182
|
+
for (const type of this.loadTypeDescriptor(param).dependedTypes()) {
|
183
|
+
const [account, module] = (0, utils_1.moduleQnameForType)(type);
|
184
|
+
accountModuleImports.addImport(account, module);
|
185
|
+
if (!this.accountImports.has(account)) {
|
186
|
+
this.pendingAccounts.add(account);
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
}
|
191
|
+
this.accountImports.set(currentModuleFqn, accountModuleImports);
|
192
|
+
return accountModuleImports;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
exports.AccountRegister = AccountRegister;
|
196
|
+
//# sourceMappingURL=typegen.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"typegen.js","sourceRoot":"","sources":["../../src/aptos-codegen/typegen.ts"],"names":[],"mappings":";;;AACA,0CAA+C;AAC/C,0CAAsF;AAEtF,SAAS,yBAAyB,CAAC,IAAoB;IACrD,iEAAiE;IACjE,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC9B,OAAO,SAAS,CAAA;KACjB;IAED,QAAQ,IAAI,CAAC,KAAK,EAAE;QAClB,KAAK,QAAQ,CAAC,CAAC,kBAAkB;QACjC,KAAK,SAAS;YACZ,OAAO,SAAS,CAAA;QAClB,KAAK,qBAAqB;YACxB,OAAO,QAAQ,CAAA;QACjB,KAAK,MAAM;YACT,OAAO,SAAS,CAAA;QAClB,KAAK,IAAI,CAAC;QACV,KAAK,KAAK,CAAC;QACX,KAAK,KAAK;YACR,OAAO,QAAQ,CAAA;QACjB,KAAK,KAAK,CAAC;QACX,KAAK,MAAM;YACT,OAAO,QAAQ,CAAA;KAClB;IAED,IAAI,IAAI,CAAC,KAAK,KAAK,kBAAU,EAAE;QAC7B,2BAA2B;QAC3B,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QAC/C,IAAI,gBAAgB,KAAK,IAAI,EAAE;YAC7B,OAAO,QAAQ,CAAA;SAChB;QACD,IAAI,gBAAgB,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,gBAAQ,CAAC,EAAE;YAC5E,OAAO,GAAG,gBAAgB,aAAa,CAAA;SACxC;QACD,OAAO,yBAAyB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;KAC1D;IAED,MAAM,UAA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MoveModule } from 'aptos/src/generated'\nimport { TypeDescriptor } from '../aptos/types'\nimport { moduleQname, moduleQnameForType, SPLITTER, VECTOR_STR } from '../aptos/utils'\n\nfunction generateTypeForDescriptor(type: TypeDescriptor): string {\n // TODO &signer is defintely an address, but what if &OTHER_TYPE?\n if (type.qname.startsWith('&')) {\n return 'Address'\n }\n\n switch (type.qname) {\n case 'signer': // TODO check this\n case 'address':\n return 'Address'\n case '0x1::string::String':\n return 'string'\n case 'bool':\n return 'Boolean'\n case 'u8':\n case 'u16':\n case 'u32':\n return 'number'\n case 'u64':\n case 'u128':\n return 'bigint'\n }\n\n if (type.qname === VECTOR_STR) {\n // vector<u8> as hex string\n const elementTypeQname = type.typeArgs[0].qname\n if (elementTypeQname === 'u8') {\n return 'string'\n }\n if (elementTypeQname.startsWith('T') && !elementTypeQname.includes(SPLITTER)) {\n return `${elementTypeQname}[] | string`\n }\n return generateTypeForDescriptor(type.typeArgs[0]) + '[]'\n }\n\n const simpleName = generateSimpleType(type.qname)\n if (simpleName.length === 0) {\n console.error('unexpected error')\n }\n if (simpleName.includes('vector')) {\n console.error('unexpected error')\n }\n if (type.typeArgs.length > 0) {\n // return simpleName\n return simpleName + '<' + type.typeArgs.map((t) => generateTypeForDescriptor(t)).join(',') + '>'\n }\n return simpleName\n}\n\nfunction generateSimpleType(type: string): string {\n const parts = type.split(SPLITTER)\n if (parts.length < 2) {\n return parts[0]\n }\n\n return parts.slice(1).join('.')\n}\n\nexport function parseMoveType(type: string) {\n // type = type.replace('&', '')\n\n type = type.replace('&mut ', '&')\n\n // TODO replace ' ' is not exactly safe, need to double check this\n type = type.replace(' ', '')\n\n const stack: TypeDescriptor[] = [new TypeDescriptor('')]\n let buffer = []\n\n // xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>\n for (let i = 0; i < type.length; i++) {\n const ch = type[i]\n if (ch === '<') {\n // const symbol = type.slice(symbolStart, i)\n // symbolStart =\n const symbol = buffer.join('')\n buffer = []\n stack[stack.length - 1].qname = symbol\n stack.push(new TypeDescriptor(''))\n continue\n }\n if (ch === '>') {\n const typeParam = stack.pop()\n if (!typeParam) {\n throw Error('Uxpectecd stack size')\n }\n if (buffer.length > 0) {\n typeParam.qname = buffer.join('')\n buffer = []\n }\n stack[stack.length - 1].typeArgs.push(typeParam)\n continue\n }\n if (ch === ',') {\n const typeParam = stack.pop()\n if (!typeParam) {\n throw Error('Uxpectecd stack size')\n }\n if (buffer.length > 0) {\n typeParam.qname = buffer.join('')\n buffer = []\n }\n\n stack[stack.length - 1].typeArgs.push(typeParam)\n // continue parse next param\n stack.push(new TypeDescriptor(''))\n continue\n }\n\n buffer.push(ch)\n }\n\n if (buffer.length > 0) {\n stack[stack.length - 1].qname = buffer.join('')\n }\n\n const res = stack.pop()\n if (!res || stack.length > 0) {\n throw Error('Uxpectecd stack size')\n }\n return res\n}\n\n// TODO ctx need to have type parameters\nexport function generateType(type: string, ctx?: any): string {\n return generateTypeForDescriptor(parseMoveType(type))\n}\n\nexport class AccountModulesImportInfo {\n // account to module\n imports: Map<string, Set<string>>\n account: string\n moduleName: string\n\n constructor(account: string, tsModuleName: string) {\n this.account = account\n this.moduleName = tsModuleName\n this.imports = new Map<string, Set<string>>()\n }\n\n addImport(account: string, module: string) {\n if (account === this.account) {\n return\n }\n let accountModules = this.imports.get(account)\n if (!accountModules) {\n accountModules = new Set<string>()\n this.imports.set(account, accountModules)\n }\n accountModules.add(module)\n }\n}\n\nexport class AccountRegister {\n accountImports = new Map<string, AccountModulesImportInfo>()\n pendingAccounts = new Set<string>()\n\n // loadedAccount = new Set<string>()\n typeRegistry = new Map<string, TypeDescriptor>()\n\n private loadTypeDescriptor(type: string) {\n let descriptor = this.typeRegistry.get(type)\n\n // const descriptparseMoveType(type)\n if (!descriptor) {\n descriptor = parseMoveType(type)\n this.typeRegistry.set(type, descriptor)\n }\n return descriptor\n }\n\n register(module: MoveModule, tsModuleName: string): AccountModulesImportInfo {\n const currentModuleFqn = moduleQname(module)\n\n let accountModuleImports = this.accountImports.get(module.address)\n if (!accountModuleImports) {\n accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName)\n this.accountImports.set(module.address, accountModuleImports)\n // the account has already be processed, delete pending task\n this.pendingAccounts.delete(module.address)\n }\n\n for (const struct of module.structs) {\n for (const field of struct.fields) {\n for (const type of this.loadTypeDescriptor(field.type).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n\n for (const func of module.exposed_functions) {\n if (!func.is_entry) {\n continue\n }\n for (const param of func.params) {\n for (const type of this.loadTypeDescriptor(param).dependedTypes()) {\n const [account, module] = moduleQnameForType(type)\n accountModuleImports.addImport(account, module)\n if (!this.accountImports.has(account)) {\n this.pendingAccounts.add(account)\n }\n }\n }\n }\n this.accountImports.set(currentModuleFqn, accountModuleImports)\n return accountModuleImports\n }\n}\n"]}
|
package/lib/binds.d.ts
CHANGED
@@ -2,8 +2,7 @@ import { BindOptions } from './core/bind-options';
|
|
2
2
|
import { BaseProcessor, ContractView } from './core';
|
3
3
|
import { Networkish } from '@ethersproject/networks';
|
4
4
|
import { BaseContract } from 'ethers';
|
5
|
-
export declare function
|
6
|
-
export declare function
|
7
|
-
export declare function addProcessor(abiName: string, opts: BindOptions, processor: BaseProcessor<any, any>): void;
|
5
|
+
export declare function getProcessor(opts: BindOptions): BaseProcessor<any, any> | undefined;
|
6
|
+
export declare function addProcessor(opts: BindOptions, processor: BaseProcessor<any, any>): void;
|
8
7
|
export declare function getContractByABI(abiName: string, address: string, network: Networkish): ContractView<BaseContract> | undefined;
|
9
8
|
export declare function addContractByABI(abiName: string, address: string, network: Networkish, contract: ContractView<BaseContract>): Map<string, ContractView<BaseContract>>;
|