@layerzerolabs/ton-sdk-tools 3.0.76 → 3.0.78
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/CHANGELOG.md +13 -0
- package/dist/index.cjs +71 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.mjs +71 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -124,9 +124,12 @@ declare abstract class BaseWrapper implements Contract {
|
|
|
124
124
|
beginMessage(opcode: number | bigint, queryId?: number | bigint): Builder;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
interface SharedGeneratorOptions {
|
|
128
|
+
relativeSrcPath?: string;
|
|
129
|
+
}
|
|
130
|
+
declare function generateCommonTestUtils(directory: string, filename: string, optionsInput?: SharedGeneratorOptions): void;
|
|
131
|
+
declare function generateSmlTestUtils(directory: string, filename: string, optionsInput?: SharedGeneratorOptions): void;
|
|
132
|
+
declare function generateUlnTestUtils(directory: string, filename: string, optionsInput?: SharedGeneratorOptions): void;
|
|
130
133
|
|
|
131
134
|
declare abstract class MultiSigOpCodes {
|
|
132
135
|
static readonly multisig: {
|
package/dist/index.d.ts
CHANGED
|
@@ -124,9 +124,12 @@ declare abstract class BaseWrapper implements Contract {
|
|
|
124
124
|
beginMessage(opcode: number | bigint, queryId?: number | bigint): Builder;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
interface SharedGeneratorOptions {
|
|
128
|
+
relativeSrcPath?: string;
|
|
129
|
+
}
|
|
130
|
+
declare function generateCommonTestUtils(directory: string, filename: string, optionsInput?: SharedGeneratorOptions): void;
|
|
131
|
+
declare function generateSmlTestUtils(directory: string, filename: string, optionsInput?: SharedGeneratorOptions): void;
|
|
132
|
+
declare function generateUlnTestUtils(directory: string, filename: string, optionsInput?: SharedGeneratorOptions): void;
|
|
130
133
|
|
|
131
134
|
declare abstract class MultiSigOpCodes {
|
|
132
135
|
static readonly multisig: {
|
package/dist/index.mjs
CHANGED
|
@@ -1225,16 +1225,16 @@ function generateAllViewFunctions(rootDir, nameWhitelist, blacklist) {
|
|
|
1225
1225
|
});
|
|
1226
1226
|
}
|
|
1227
1227
|
findContractDirs(rootDir);
|
|
1228
|
-
|
|
1228
|
+
for (const dir of contractDirs) {
|
|
1229
1229
|
const files = fs.readdirSync(dir).filter((file) => file.endsWith(".fc") || file.endsWith(".func"));
|
|
1230
|
-
|
|
1230
|
+
for (const file of files) {
|
|
1231
1231
|
const filePath = path.join(dir, file);
|
|
1232
1232
|
const contractName = snakeToCamelCase(path.basename(path.dirname(dir)) + "_" + path.basename(dir));
|
|
1233
1233
|
const content = fs.readFileSync(filePath, "utf-8");
|
|
1234
|
-
const functionRegex = /(
|
|
1234
|
+
const functionRegex = /(^\((?:[^()]+,\s*)*[^()]+\)|[\w:]+)\s+(\w+(?:::\w+)*)\s*\(([\w\s,$·]*)\)\s*·?\s*(impure)?\s*(inline\s*)?method_id\s*\{/gm;
|
|
1235
1235
|
let match;
|
|
1236
1236
|
while ((match = functionRegex.exec(content)) !== null) {
|
|
1237
|
-
const [, returnType, name, argsString
|
|
1237
|
+
const [, returnType, name, argsString] = match;
|
|
1238
1238
|
if (name.includes("::New")) {
|
|
1239
1239
|
continue;
|
|
1240
1240
|
}
|
|
@@ -1253,48 +1253,63 @@ function generateAllViewFunctions(rootDir, nameWhitelist, blacklist) {
|
|
|
1253
1253
|
if (!(contractName in viewFunctions)) {
|
|
1254
1254
|
viewFunctions[contractName] = [];
|
|
1255
1255
|
}
|
|
1256
|
+
const functionArgs = [
|
|
1257
|
+
"contract: ExtendedContract<TonContractWrapper>",
|
|
1258
|
+
...Object.entries(tsArgs).map(function([argName, argType]) {
|
|
1259
|
+
return `${argName}: ${argType}`;
|
|
1260
|
+
})
|
|
1261
|
+
];
|
|
1256
1262
|
const fnName = snakeToCamelCase("get_" + name);
|
|
1257
|
-
const code =
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
(
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1263
|
+
const code = [
|
|
1264
|
+
`static async ${fnName}(`,
|
|
1265
|
+
indent(functionArgs.join(",\n")),
|
|
1266
|
+
`): Promise<[${tsReturnTypes.join(", ")}]> {`
|
|
1267
|
+
];
|
|
1268
|
+
const hasArgs = Object.keys(tonArgs).length > 0;
|
|
1269
|
+
if (hasArgs) {
|
|
1270
|
+
code.push(indent(`const args: TupleItem[] = [`));
|
|
1271
|
+
const innerArgs = Object.entries(tonArgs).map(function([argName, argType]) {
|
|
1272
|
+
return `{ type: '${tonTypeToTupleType(argType)}', ${tonTypeToTupleValueName(argType)}: ${tonTypeToTupleValue(argName, argType)} }`;
|
|
1273
|
+
});
|
|
1274
|
+
code.push(indent(innerArgs.join(",\n"), 2));
|
|
1275
|
+
code.push(indent(`]`));
|
|
1276
|
+
}
|
|
1277
|
+
code.push(indent(`const stack = await contract.getViewFunction('${name}', ${hasArgs ? "args" : "[]"})`));
|
|
1278
|
+
const returnCalls = tonReturnTypes.map(function(_, index) {
|
|
1279
|
+
return `stack.${tonTypeToReadTupleFunction(tonReturnTypes[index])}`;
|
|
1280
|
+
});
|
|
1281
|
+
code.push(indent(`return [ ${returnCalls.join(", ")} ]`));
|
|
1282
|
+
code.push("}");
|
|
1273
1283
|
viewFunctions[contractName].push({
|
|
1274
1284
|
name: fnName,
|
|
1275
1285
|
args: tonArgs,
|
|
1276
1286
|
returnType: tonReturnTypes,
|
|
1277
|
-
code
|
|
1287
|
+
code: code.join("\n")
|
|
1278
1288
|
});
|
|
1279
1289
|
}
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1282
1292
|
return viewFunctions;
|
|
1283
1293
|
}
|
|
1294
|
+
function indent(input, count = 1) {
|
|
1295
|
+
return input.split("\n").map(function(line) {
|
|
1296
|
+
return `${" ".repeat(count)}${line}`;
|
|
1297
|
+
}).join("\n");
|
|
1298
|
+
}
|
|
1284
1299
|
function saveViewFunctions(viewFunctions, directory, filename) {
|
|
1285
|
-
const
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
fs.writeFileSync(path.join(directory, filename),
|
|
1300
|
+
const generated = [
|
|
1301
|
+
file_signature_header,
|
|
1302
|
+
`import { Address, Cell, Tuple, TupleItem, beginCell } from '@ton/core'`,
|
|
1303
|
+
`import { ExtendedContract, TonContractWrapper } from '../wrappers'`,
|
|
1304
|
+
""
|
|
1305
|
+
];
|
|
1306
|
+
for (const [contractName, functions] of Object.entries(viewFunctions)) {
|
|
1307
|
+
generated.push(`export class ${contractName} {`);
|
|
1308
|
+
generated.push(functions.map((fn) => indent(fn.code)).join("\n\n"));
|
|
1309
|
+
generated.push(`}`);
|
|
1310
|
+
generated.push("");
|
|
1311
|
+
}
|
|
1312
|
+
fs.writeFileSync(path.join(directory, filename), generated.join("\n"));
|
|
1298
1313
|
}
|
|
1299
1314
|
var BaseWrapper = class {
|
|
1300
1315
|
constructor(address, init) {
|
|
@@ -1335,7 +1350,18 @@ var BaseWrapper = class {
|
|
|
1335
1350
|
return beginCell().storeUint(opcode, 32).storeUint(queryId ?? randomQueryId, 64);
|
|
1336
1351
|
}
|
|
1337
1352
|
};
|
|
1338
|
-
function
|
|
1353
|
+
function getSharedOptions(input) {
|
|
1354
|
+
const ret = {
|
|
1355
|
+
relativeSrcPath: "../../src",
|
|
1356
|
+
...input
|
|
1357
|
+
};
|
|
1358
|
+
if (ret.relativeSrcPath.endsWith("/")) {
|
|
1359
|
+
throw new Error("relativeSrcPath should not end with a /");
|
|
1360
|
+
}
|
|
1361
|
+
return ret;
|
|
1362
|
+
}
|
|
1363
|
+
function generateCommonTestUtils(directory, filename, optionsInput) {
|
|
1364
|
+
const options = getSharedOptions(optionsInput);
|
|
1339
1365
|
const savedCode = `import fs from 'fs'
|
|
1340
1366
|
|
|
1341
1367
|
import {
|
|
@@ -1394,7 +1420,7 @@ import {
|
|
|
1394
1420
|
TonObjectUnwrapper,
|
|
1395
1421
|
deconstructorMap,
|
|
1396
1422
|
keyMap,
|
|
1397
|
-
} from '
|
|
1423
|
+
} from '${options.relativeSrcPath}'
|
|
1398
1424
|
|
|
1399
1425
|
const RECURSIVE_DECODE = false
|
|
1400
1426
|
|
|
@@ -2879,7 +2905,7 @@ export async function txDecoder(
|
|
|
2879
2905
|
}
|
|
2880
2906
|
|
|
2881
2907
|
export async function runtimeDecoder(contract: SandboxContract<TonContractWrapper>, obj: Cell): Promise<void> {
|
|
2882
|
-
const { tonObjects } = require('
|
|
2908
|
+
const { tonObjects } = require('${options.relativeSrcPath}/offchain-helpers/allObjects') as { [key: string]: { [key: string]: any } }
|
|
2883
2909
|
|
|
2884
2910
|
const typeName = await TonObjectUnwrapper.getTypeOf(contract, obj)
|
|
2885
2911
|
|
|
@@ -2940,7 +2966,8 @@ export async function runtimeDecoder(contract: SandboxContract<TonContractWrappe
|
|
|
2940
2966
|
`;
|
|
2941
2967
|
fs__default.writeFileSync(path__default.join(directory, filename), savedCode);
|
|
2942
2968
|
}
|
|
2943
|
-
function generateSmlTestUtils(directory, filename) {
|
|
2969
|
+
function generateSmlTestUtils(directory, filename, optionsInput) {
|
|
2970
|
+
const options = getSharedOptions(optionsInput);
|
|
2944
2971
|
const savedCode = `import { Cell, toNano } from '@ton/core'
|
|
2945
2972
|
import { Blockchain, SandboxContract, SendMessageResult, TreasuryContract } from '@ton/sandbox'
|
|
2946
2973
|
import '@ton/test-utils'
|
|
@@ -2961,7 +2988,7 @@ import {
|
|
|
2961
2988
|
setDefaultEndpointConfig,
|
|
2962
2989
|
wireChannels,
|
|
2963
2990
|
} from './auto-utils-common'
|
|
2964
|
-
import { LzEventHandler, OPCODES, TonContractWrapper } from '
|
|
2991
|
+
import { LzEventHandler, OPCODES, TonContractWrapper } from '${options.relativeSrcPath}'
|
|
2965
2992
|
|
|
2966
2993
|
const SML_MANAGER_DEFAULT_VERSION = BigInt(1)
|
|
2967
2994
|
const SML_MANAGER_CUSTOM_VERSION = BigInt(2)
|
|
@@ -3302,7 +3329,8 @@ export async function wireFixturesTogetherWithSML(
|
|
|
3302
3329
|
`;
|
|
3303
3330
|
fs__default.writeFileSync(path__default.join(directory, filename), savedCode);
|
|
3304
3331
|
}
|
|
3305
|
-
function generateUlnTestUtils(directory, filename) {
|
|
3332
|
+
function generateUlnTestUtils(directory, filename, optionsInput) {
|
|
3333
|
+
const options = getSharedOptions(optionsInput);
|
|
3306
3334
|
const savedCode = `import { Address, Cell, TupleItemCell, beginCell, toNano } from '@ton/core'
|
|
3307
3335
|
import { Blockchain, SandboxContract, SendMessageResult, TreasuryContract } from '@ton/sandbox'
|
|
3308
3336
|
import { FlatTransactionComparable } from '@ton/test-utils'
|
|
@@ -3349,7 +3377,7 @@ import {
|
|
|
3349
3377
|
OPCODES,
|
|
3350
3378
|
TonContractWrapper,
|
|
3351
3379
|
TonObjectUnwrapper,
|
|
3352
|
-
} from '
|
|
3380
|
+
} from '${options.relativeSrcPath}'
|
|
3353
3381
|
|
|
3354
3382
|
const ULN_MANAGER_DEFAULT_VERSION = BigInt(1)
|
|
3355
3383
|
|