@ton/sandbox 0.32.2 → 0.33.0-dev.20250610093937.e3733e4
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 +6 -0
- package/dist/blockchain/Blockchain.d.ts +14 -14
- package/dist/blockchain/Blockchain.js +28 -18
- package/dist/blockchain/BlockchainContractProvider.d.ts +4 -4
- package/dist/blockchain/BlockchainContractProvider.js +9 -8
- package/dist/blockchain/BlockchainSender.d.ts +1 -1
- package/dist/blockchain/BlockchainSender.js +5 -2
- package/dist/blockchain/BlockchainStorage.d.ts +6 -6
- package/dist/blockchain/BlockchainStorage.js +15 -7
- package/dist/blockchain/SmartContract.d.ts +4 -4
- package/dist/blockchain/SmartContract.js +24 -15
- package/dist/event/Event.d.ts +1 -1
- package/dist/event/Event.js +15 -13
- package/dist/executor/Executor.d.ts +2 -2
- package/dist/executor/Executor.js +52 -33
- package/dist/index.d.ts +10 -9
- package/dist/index.js +4 -1
- package/dist/jest/BenchmarkCommand.js +1 -1
- package/dist/jest/BenchmarkReporter.js +1 -1
- package/dist/meta/ContractsMeta.d.ts +1 -1
- package/dist/metric/collectMetric.js +6 -1
- package/dist/metric/deltaResult.js +2 -0
- package/dist/treasury/Treasury.d.ts +1 -1
- package/dist/treasury/Treasury.js +6 -11
- package/dist/utils/AsyncLock.js +5 -5
- package/dist/utils/base64.js +1 -1
- package/dist/utils/config.d.ts +3 -0
- package/dist/utils/config.js +78 -0
- package/dist/utils/crc16.js +19 -32
- package/dist/utils/ec.d.ts +1 -1
- package/dist/utils/message.d.ts +2 -2
- package/dist/utils/prettyLogTransaction.d.ts +1 -1
- package/dist/utils/prettyLogTransaction.js +1 -0
- package/dist/utils/printTransactionFees.d.ts +1 -1
- package/dist/utils/printTransactionFees.js +6 -4
- package/jest-environment.js +1 -1
- package/jest-reporter.js +1 -1
- package/package.json +9 -4
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Executor = void 0;
|
|
4
4
|
const core_1 = require("@ton/core");
|
|
5
5
|
const base64_1 = require("../utils/base64");
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
6
7
|
const EmulatorModule = require('./emulator-emscripten.js');
|
|
7
8
|
function blockIdToTuple(blockId) {
|
|
8
9
|
return [
|
|
@@ -15,11 +16,17 @@ function blockIdToTuple(blockId) {
|
|
|
15
16
|
}
|
|
16
17
|
function prevBlocksInfoToTuple(prevBlocksInfo) {
|
|
17
18
|
const r = [
|
|
18
|
-
{
|
|
19
|
+
{
|
|
20
|
+
type: 'tuple',
|
|
21
|
+
items: prevBlocksInfo.lastMcBlocks.map((bid) => ({ type: 'tuple', items: blockIdToTuple(bid) })),
|
|
22
|
+
},
|
|
19
23
|
{ type: 'tuple', items: blockIdToTuple(prevBlocksInfo.prevKeyBlock) },
|
|
20
24
|
];
|
|
21
25
|
if (prevBlocksInfo.lastMcBlocks100) {
|
|
22
|
-
r.push({
|
|
26
|
+
r.push({
|
|
27
|
+
type: 'tuple',
|
|
28
|
+
items: prevBlocksInfo.lastMcBlocks100.map((bid) => ({ type: 'tuple', items: blockIdToTuple(bid) })),
|
|
29
|
+
});
|
|
23
30
|
}
|
|
24
31
|
return r;
|
|
25
32
|
}
|
|
@@ -31,12 +38,12 @@ function serializeTupleAsStackEntry(tuple) {
|
|
|
31
38
|
return s.asCell();
|
|
32
39
|
}
|
|
33
40
|
const verbosityToNum = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
short: 0,
|
|
42
|
+
full: 1,
|
|
43
|
+
full_location: 2,
|
|
44
|
+
full_location_gas: 3,
|
|
45
|
+
full_location_stack: 4,
|
|
46
|
+
full_location_stack_verbose: 5,
|
|
40
47
|
};
|
|
41
48
|
function runCommonArgsToInternalParams(args) {
|
|
42
49
|
const p = {
|
|
@@ -47,7 +54,9 @@ function runCommonArgsToInternalParams(args) {
|
|
|
47
54
|
debug_enabled: args.debugEnabled,
|
|
48
55
|
};
|
|
49
56
|
if (args.prevBlocksInfo !== undefined) {
|
|
50
|
-
p.prev_blocks_info = serializeTupleAsStackEntry(prevBlocksInfoToTuple(args.prevBlocksInfo))
|
|
57
|
+
p.prev_blocks_info = serializeTupleAsStackEntry(prevBlocksInfoToTuple(args.prevBlocksInfo))
|
|
58
|
+
.toBoc()
|
|
59
|
+
.toString('base64');
|
|
51
60
|
}
|
|
52
61
|
return p;
|
|
53
62
|
}
|
|
@@ -65,6 +74,7 @@ class Pointer {
|
|
|
65
74
|
}
|
|
66
75
|
}
|
|
67
76
|
class Heap {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
78
|
constructor(module) {
|
|
69
79
|
this.pointers = [];
|
|
70
80
|
this.maxPtrs = 0;
|
|
@@ -73,16 +83,19 @@ class Heap {
|
|
|
73
83
|
getPointersForStrings(strs) {
|
|
74
84
|
this.maxPtrs = Math.max(this.maxPtrs, strs.length);
|
|
75
85
|
const sorted = strs.map((str, i) => ({ str, i })).sort((a, b) => b.str.length - a.str.length);
|
|
76
|
-
const ptrs = sorted
|
|
86
|
+
const ptrs = sorted
|
|
87
|
+
.map((e) => ({ i: e.i, ptr: this.getCStringPointer(e.str) }))
|
|
88
|
+
.sort((a, b) => a.i - b.i)
|
|
89
|
+
.map((e) => e.ptr.rawPointer);
|
|
77
90
|
this.pointers.sort((a, b) => b.length - a.length);
|
|
78
|
-
this.pointers.slice(this.maxPtrs).forEach(ptr => this.module._free(ptr.rawPointer));
|
|
91
|
+
this.pointers.slice(this.maxPtrs).forEach((ptr) => this.module._free(ptr.rawPointer));
|
|
79
92
|
this.pointers = this.pointers.slice(0, this.maxPtrs);
|
|
80
|
-
this.pointers.forEach(p => p.free());
|
|
93
|
+
this.pointers.forEach((p) => p.free());
|
|
81
94
|
return ptrs;
|
|
82
95
|
}
|
|
83
96
|
getCStringPointer(data) {
|
|
84
97
|
let length = this.module.lengthBytesUTF8(data) + 1;
|
|
85
|
-
let existing = this.pointers.find(p => p.length >= length && !p.inUse);
|
|
98
|
+
let existing = this.pointers.find((p) => p.length >= length && !p.inUse);
|
|
86
99
|
if (existing) {
|
|
87
100
|
this.module.stringToUTF8(data, existing.rawPointer, length);
|
|
88
101
|
existing.alloc();
|
|
@@ -97,6 +110,7 @@ class Heap {
|
|
|
97
110
|
}
|
|
98
111
|
}
|
|
99
112
|
class Executor {
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
114
|
constructor(module) {
|
|
101
115
|
this.debugLogs = [];
|
|
102
116
|
this.module = module;
|
|
@@ -104,6 +118,7 @@ class Executor {
|
|
|
104
118
|
}
|
|
105
119
|
static async create() {
|
|
106
120
|
const ex = new Executor(await EmulatorModule({
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
107
122
|
wasmBinary: (0, base64_1.base64Decode)(require('./emulator-emscripten.wasm.js').EmulatorEmscriptenWasm),
|
|
108
123
|
printErr: (text) => ex.debugLogs.push(text),
|
|
109
124
|
}));
|
|
@@ -130,17 +145,16 @@ class Executor {
|
|
|
130
145
|
}
|
|
131
146
|
}
|
|
132
147
|
if (args.prevBlocksInfo !== undefined) {
|
|
133
|
-
params.prev_blocks_info = serializeTupleAsStackEntry(prevBlocksInfoToTuple(args.prevBlocksInfo))
|
|
148
|
+
params.prev_blocks_info = serializeTupleAsStackEntry(prevBlocksInfoToTuple(args.prevBlocksInfo))
|
|
149
|
+
.toBoc()
|
|
150
|
+
.toString('base64');
|
|
134
151
|
}
|
|
135
152
|
let stack = (0, core_1.serializeTuple)(args.stack);
|
|
136
153
|
this.debugLogs = [];
|
|
137
|
-
const resp = JSON.parse(this.extractString(this.invoke('_run_get_method', [
|
|
138
|
-
JSON.stringify(params),
|
|
139
|
-
stack.toBoc().toString('base64'),
|
|
140
|
-
args.config,
|
|
141
|
-
])));
|
|
154
|
+
const resp = JSON.parse(this.extractString(this.invoke('_run_get_method', [JSON.stringify(params), stack.toBoc().toString('base64'), args.config])));
|
|
142
155
|
const debugLogs = this.debugLogs.join('\n');
|
|
143
156
|
if (resp.fail) {
|
|
157
|
+
// eslint-disable-next-line no-console
|
|
144
158
|
console.error(resp);
|
|
145
159
|
throw new Error('Unknown emulation error');
|
|
146
160
|
}
|
|
@@ -155,26 +169,31 @@ class Executor {
|
|
|
155
169
|
const resp = JSON.parse(this.extractString(this.invoke('_emulate_with_emulator', args)));
|
|
156
170
|
const debugLogs = this.debugLogs.join('\n');
|
|
157
171
|
if (resp.fail) {
|
|
172
|
+
// eslint-disable-next-line no-console
|
|
158
173
|
console.error(resp);
|
|
159
174
|
throw new Error('Unknown emulation error');
|
|
160
175
|
}
|
|
161
176
|
const logs = resp.logs;
|
|
162
177
|
const result = resp.output;
|
|
163
178
|
return {
|
|
164
|
-
result: result.success
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
actions: result.actions,
|
|
170
|
-
} : {
|
|
171
|
-
success: false,
|
|
172
|
-
error: result.error,
|
|
173
|
-
vmResults: 'vm_log' in result ? {
|
|
179
|
+
result: result.success
|
|
180
|
+
? {
|
|
181
|
+
success: true,
|
|
182
|
+
transaction: result.transaction,
|
|
183
|
+
shardAccount: result.shard_account,
|
|
174
184
|
vmLog: result.vm_log,
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
185
|
+
actions: result.actions,
|
|
186
|
+
}
|
|
187
|
+
: {
|
|
188
|
+
success: false,
|
|
189
|
+
error: result.error,
|
|
190
|
+
vmResults: 'vm_log' in result
|
|
191
|
+
? {
|
|
192
|
+
vmLog: result.vm_log,
|
|
193
|
+
vmExitCode: result.vm_exit_code,
|
|
194
|
+
}
|
|
195
|
+
: undefined,
|
|
196
|
+
},
|
|
178
197
|
logs,
|
|
179
198
|
debugLogs,
|
|
180
199
|
};
|
|
@@ -232,7 +251,7 @@ class Executor {
|
|
|
232
251
|
invocationArgs[i] = arg;
|
|
233
252
|
}
|
|
234
253
|
}
|
|
235
|
-
const strPtrs = this.heap.getPointersForStrings(strArgs.map(e => e.str));
|
|
254
|
+
const strPtrs = this.heap.getPointersForStrings(strArgs.map((e) => e.str));
|
|
236
255
|
for (let i = 0; i < strPtrs.length; i++) {
|
|
237
256
|
invocationArgs[strArgs[i].i] = strPtrs[i];
|
|
238
257
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
export { defaultConfig, defaultConfigSeqno
|
|
1
|
+
export { defaultConfig, defaultConfigSeqno } from './config/defaultConfig';
|
|
2
2
|
export { Blockchain, toSandboxContract, SendMessageResult, BlockchainTransaction, PendingMessage, SandboxContract, ExternalOut, ExternalOutInfo, BlockchainConfig, BlockchainSnapshot, } from './blockchain/Blockchain';
|
|
3
|
-
export { BlockchainContractProvider, SandboxContractProvider
|
|
4
|
-
export { BlockchainSender
|
|
3
|
+
export { BlockchainContractProvider, SandboxContractProvider } from './blockchain/BlockchainContractProvider';
|
|
4
|
+
export { BlockchainSender } from './blockchain/BlockchainSender';
|
|
5
5
|
export { BlockchainStorage, LocalBlockchainStorage, RemoteBlockchainStorage, RemoteBlockchainStorageClient, wrapTonClient4ForRemote, } from './blockchain/BlockchainStorage';
|
|
6
6
|
export { Verbosity, LogsVerbosity, SmartContract, SmartContractTransaction, MessageParams, GetMethodParams, GetMethodResult, createEmptyShardAccount, createShardAccount, GetMethodError, TimeError, SmartContractSnapshot, EmulationError, } from './blockchain/SmartContract';
|
|
7
7
|
export { TickOrTock, IExecutor, Executor, GetMethodArgs as ExecutorGetMethodArgs, GetMethodResult as ExecutorGetMethodResult, RunTickTockArgs as ExecutorRunTickTockArgs, EmulationResult as ExecutorEmulationResult, RunTransactionArgs as ExecutorRunTransactionArgs, ExecutorVerbosity, BlockId, PrevBlocksInfo, } from './executor/Executor';
|
|
8
|
-
export { Event, EventAccountCreated, EventAccountDestroyed, EventMessageSent
|
|
9
|
-
export { Treasury, TreasuryContract
|
|
10
|
-
export { prettyLogTransaction, prettyLogTransactions
|
|
11
|
-
export { printTransactionFees
|
|
12
|
-
export { internal
|
|
13
|
-
export {
|
|
8
|
+
export { Event, EventAccountCreated, EventAccountDestroyed, EventMessageSent } from './event/Event';
|
|
9
|
+
export { Treasury, TreasuryContract } from './treasury/Treasury';
|
|
10
|
+
export { prettyLogTransaction, prettyLogTransactions } from './utils/prettyLogTransaction';
|
|
11
|
+
export { printTransactionFees } from './utils/printTransactionFees';
|
|
12
|
+
export { internal } from './utils/message';
|
|
13
|
+
export { fetchConfig, setGlobalVersion } from './utils/config';
|
|
14
|
+
export { ExtraCurrency } from './utils/ec';
|
|
14
15
|
export * from './metric';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.internal = exports.printTransactionFees = exports.prettyLogTransactions = exports.prettyLogTransaction = exports.TreasuryContract = exports.Executor = exports.EmulationError = exports.TimeError = exports.GetMethodError = exports.createShardAccount = exports.createEmptyShardAccount = exports.SmartContract = exports.wrapTonClient4ForRemote = exports.RemoteBlockchainStorage = exports.LocalBlockchainStorage = exports.BlockchainSender = exports.BlockchainContractProvider = exports.toSandboxContract = exports.Blockchain = exports.defaultConfigSeqno = exports.defaultConfig = void 0;
|
|
17
|
+
exports.setGlobalVersion = exports.fetchConfig = exports.internal = exports.printTransactionFees = exports.prettyLogTransactions = exports.prettyLogTransaction = exports.TreasuryContract = exports.Executor = exports.EmulationError = exports.TimeError = exports.GetMethodError = exports.createShardAccount = exports.createEmptyShardAccount = exports.SmartContract = exports.wrapTonClient4ForRemote = exports.RemoteBlockchainStorage = exports.LocalBlockchainStorage = exports.BlockchainSender = exports.BlockchainContractProvider = exports.toSandboxContract = exports.Blockchain = exports.defaultConfigSeqno = exports.defaultConfig = void 0;
|
|
18
18
|
var defaultConfig_1 = require("./config/defaultConfig");
|
|
19
19
|
Object.defineProperty(exports, "defaultConfig", { enumerable: true, get: function () { return defaultConfig_1.defaultConfig; } });
|
|
20
20
|
Object.defineProperty(exports, "defaultConfigSeqno", { enumerable: true, get: function () { return defaultConfig_1.defaultConfigSeqno; } });
|
|
@@ -47,4 +47,7 @@ var printTransactionFees_1 = require("./utils/printTransactionFees");
|
|
|
47
47
|
Object.defineProperty(exports, "printTransactionFees", { enumerable: true, get: function () { return printTransactionFees_1.printTransactionFees; } });
|
|
48
48
|
var message_1 = require("./utils/message");
|
|
49
49
|
Object.defineProperty(exports, "internal", { enumerable: true, get: function () { return message_1.internal; } });
|
|
50
|
+
var config_1 = require("./utils/config");
|
|
51
|
+
Object.defineProperty(exports, "fetchConfig", { enumerable: true, get: function () { return config_1.fetchConfig; } });
|
|
52
|
+
Object.defineProperty(exports, "setGlobalVersion", { enumerable: true, get: function () { return config_1.setGlobalVersion; } });
|
|
50
53
|
__exportStar(require("./metric"), exports);
|
|
@@ -5,7 +5,7 @@ class BenchmarkCommand {
|
|
|
5
5
|
constructor(option) {
|
|
6
6
|
option = option || {};
|
|
7
7
|
this.label = option?.label ?? process.env?.BENCH_NEW;
|
|
8
|
-
this.doDiff = option?.doDiff ?? process.env?.BENCH_DIFF === 'true'
|
|
8
|
+
this.doDiff = option?.doDiff ?? process.env?.BENCH_DIFF === 'true';
|
|
9
9
|
}
|
|
10
10
|
get doBenchmark() {
|
|
11
11
|
return this.doDiff || typeof this.label !== 'undefined';
|
|
@@ -112,7 +112,7 @@ class BenchmarkReporter extends reporters_1.BaseReporter {
|
|
|
112
112
|
data = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(this.rootDirPath, filePath), 'utf-8'));
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
-
catch (
|
|
115
|
+
catch (_) {
|
|
116
116
|
throw new Error(`Could not parse contract database: ${filePath}`);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -53,10 +53,12 @@ function makeSnapshotMetric(store, config = {}) {
|
|
|
53
53
|
return snapshot;
|
|
54
54
|
}
|
|
55
55
|
exports.makeSnapshotMetric = makeSnapshotMetric;
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
57
|
function getMetricStore(context = globalThis) {
|
|
57
58
|
return context[STORE_METRIC];
|
|
58
59
|
}
|
|
59
60
|
exports.getMetricStore = getMetricStore;
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
62
|
function createMetricStore(context = globalThis) {
|
|
61
63
|
if (!Array.isArray(context[STORE_METRIC])) {
|
|
62
64
|
context[STORE_METRIC] = new Array();
|
|
@@ -64,6 +66,7 @@ function createMetricStore(context = globalThis) {
|
|
|
64
66
|
return context[STORE_METRIC];
|
|
65
67
|
}
|
|
66
68
|
exports.createMetricStore = createMetricStore;
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
70
|
function resetMetricStore(context = globalThis) {
|
|
68
71
|
const store = getMetricStore(context);
|
|
69
72
|
if (store)
|
|
@@ -152,7 +155,9 @@ async function collectMetric(blockchain, ctx, result) {
|
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
let testName;
|
|
158
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
159
|
if (globalThis['expect']) {
|
|
160
|
+
// eslint-disable-next-line no-undef
|
|
156
161
|
testName = expect.getState().currentTestName;
|
|
157
162
|
}
|
|
158
163
|
let contractName = ctx.contract.constructor.name;
|
|
@@ -170,7 +175,7 @@ async function collectMetric(blockchain, ctx, result) {
|
|
|
170
175
|
methodName = OpCodeReserved[Number(opCode)];
|
|
171
176
|
}
|
|
172
177
|
const address = core_1.Address.parseRaw(`0:${tx.address.toString(16).padStart(64, '0')}`);
|
|
173
|
-
const { computePhase, actionPhase
|
|
178
|
+
const { computePhase, actionPhase } = tx.description;
|
|
174
179
|
const action = actionPhase
|
|
175
180
|
? {
|
|
176
181
|
success: actionPhase.success,
|
|
@@ -91,7 +91,9 @@ function aggregatedCompareMetric(before, after, basePath = []) {
|
|
|
91
91
|
keys.forEach((key) => {
|
|
92
92
|
if (!deltaTarget.includes(key))
|
|
93
93
|
return;
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
95
|
const prev = before[key];
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
97
|
const next = after[key];
|
|
96
98
|
const path = [...basePath, key];
|
|
97
99
|
if (prev === undefined || next === undefined)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, SenderArguments, SendMode, StateInit } from
|
|
1
|
+
import { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, SenderArguments, SendMode, StateInit } from '@ton/core';
|
|
2
2
|
export type Treasury = Sender & {
|
|
3
3
|
address: Address;
|
|
4
4
|
};
|
|
@@ -20,7 +20,7 @@ function senderArgsToMessageRelaxed(args) {
|
|
|
20
20
|
extracurrency: args.extracurrency,
|
|
21
21
|
init: args.init,
|
|
22
22
|
body: args.body,
|
|
23
|
-
bounce: args.bounce
|
|
23
|
+
bounce: args.bounce,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
@@ -31,9 +31,7 @@ class TreasuryContract {
|
|
|
31
31
|
return new TreasuryContract(workchain, subwalletId);
|
|
32
32
|
}
|
|
33
33
|
constructor(workchain, subwalletId) {
|
|
34
|
-
const data = (0, core_1.beginCell)()
|
|
35
|
-
.storeUint(subwalletId, 256)
|
|
36
|
-
.endCell();
|
|
34
|
+
const data = (0, core_1.beginCell)().storeUint(subwalletId, 256).endCell();
|
|
37
35
|
this.init = { code: TreasuryContract.code, data };
|
|
38
36
|
this.address = (0, core_1.contractAddress)(workchain, this.init);
|
|
39
37
|
this.subwalletId = subwalletId;
|
|
@@ -46,7 +44,7 @@ class TreasuryContract {
|
|
|
46
44
|
async sendMessages(provider, messages, sendMode) {
|
|
47
45
|
let transfer = this.createTransfer({
|
|
48
46
|
sendMode: sendMode,
|
|
49
|
-
messages: messages
|
|
47
|
+
messages: messages,
|
|
50
48
|
});
|
|
51
49
|
await provider.external(transfer);
|
|
52
50
|
}
|
|
@@ -65,10 +63,10 @@ class TreasuryContract {
|
|
|
65
63
|
send: async (args) => {
|
|
66
64
|
let transfer = this.createTransfer({
|
|
67
65
|
sendMode: args.sendMode ?? undefined,
|
|
68
|
-
messages: [senderArgsToMessageRelaxed(args)]
|
|
66
|
+
messages: [senderArgsToMessageRelaxed(args)],
|
|
69
67
|
});
|
|
70
68
|
await provider.external(transfer);
|
|
71
|
-
}
|
|
69
|
+
},
|
|
72
70
|
};
|
|
73
71
|
}
|
|
74
72
|
/**
|
|
@@ -93,10 +91,7 @@ class TreasuryContract {
|
|
|
93
91
|
for (let m of args.messages) {
|
|
94
92
|
messages.set(index++, { sendMode, message: m });
|
|
95
93
|
}
|
|
96
|
-
return (0, core_1.beginCell)()
|
|
97
|
-
.storeUint(this.subwalletId, 256)
|
|
98
|
-
.storeDict(messages)
|
|
99
|
-
.endCell();
|
|
94
|
+
return (0, core_1.beginCell)().storeUint(this.subwalletId, 256).storeDict(messages).endCell();
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
exports.TreasuryContract = TreasuryContract;
|
package/dist/utils/AsyncLock.js
CHANGED
|
@@ -8,18 +8,18 @@ var _AsyncLock_waiters;
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AsyncLock = void 0;
|
|
10
10
|
function createWaiter() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
let resolveFn;
|
|
12
|
+
const promise = new Promise((res) => {
|
|
13
|
+
resolveFn = res;
|
|
14
14
|
});
|
|
15
|
-
return
|
|
15
|
+
return { promise, resolve: resolveFn };
|
|
16
16
|
}
|
|
17
17
|
class AsyncLock {
|
|
18
18
|
constructor() {
|
|
19
19
|
_AsyncLock_waiters.set(this, []);
|
|
20
20
|
}
|
|
21
21
|
async acquire() {
|
|
22
|
-
const waiters = __classPrivateFieldGet(this, _AsyncLock_waiters, "f").map(w => w.promise);
|
|
22
|
+
const waiters = __classPrivateFieldGet(this, _AsyncLock_waiters, "f").map((w) => w.promise);
|
|
23
23
|
__classPrivateFieldGet(this, _AsyncLock_waiters, "f").push(createWaiter());
|
|
24
24
|
if (waiters.length > 0) {
|
|
25
25
|
await Promise.all(waiters);
|
package/dist/utils/base64.js
CHANGED
|
@@ -16,7 +16,7 @@ function b64ToUint6(nChr) {
|
|
|
16
16
|
: 0;
|
|
17
17
|
}
|
|
18
18
|
function base64Decode(sBase64) {
|
|
19
|
-
const sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g,
|
|
19
|
+
const sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, '');
|
|
20
20
|
const nInLen = sB64Enc.length;
|
|
21
21
|
const nOutLen = (nInLen * 3 + 1) >> 2;
|
|
22
22
|
const taBytes = new Uint8Array(nOutLen);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setGlobalVersion = exports.fetchConfig = void 0;
|
|
4
|
+
const core_1 = require("@ton/core");
|
|
5
|
+
async function fetchConfig(network, maxRetries = 5) {
|
|
6
|
+
let apiDomain;
|
|
7
|
+
let retryLeft = maxRetries;
|
|
8
|
+
if (network == 'testnet') {
|
|
9
|
+
apiDomain = 'testnet.toncenter.com';
|
|
10
|
+
}
|
|
11
|
+
else if (network == 'mainnet') {
|
|
12
|
+
apiDomain = 'toncenter.com';
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
throw new RangeError(`Unknown network: ${network}`);
|
|
16
|
+
}
|
|
17
|
+
const sleep = (timeout) => new Promise((resolve) => {
|
|
18
|
+
setTimeout(resolve, timeout);
|
|
19
|
+
});
|
|
20
|
+
const headers = new Headers();
|
|
21
|
+
headers.append('Accept', 'application/json');
|
|
22
|
+
do {
|
|
23
|
+
try {
|
|
24
|
+
const resp = await fetch(`https://${apiDomain}/api/v2/getConfigAll`, {
|
|
25
|
+
method: 'GET',
|
|
26
|
+
headers,
|
|
27
|
+
});
|
|
28
|
+
const jsonResp = await resp.json();
|
|
29
|
+
if (jsonResp.ok) {
|
|
30
|
+
return core_1.Cell.fromBase64(jsonResp.result.config.bytes);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw new Error(JSON.stringify(jsonResp));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
retryLeft--;
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
39
|
+
console.error(`Error fetching config:${e.toString()}`);
|
|
40
|
+
await sleep(1000);
|
|
41
|
+
}
|
|
42
|
+
} while (retryLeft > 0);
|
|
43
|
+
throw new Error(`Failed to fetch config after ${maxRetries} attempts`);
|
|
44
|
+
}
|
|
45
|
+
exports.fetchConfig = fetchConfig;
|
|
46
|
+
function setGlobalVersion(config, version, capabilites) {
|
|
47
|
+
const parsedConfig = core_1.Dictionary.loadDirect(core_1.Dictionary.Keys.Int(32), core_1.Dictionary.Values.Cell(), config);
|
|
48
|
+
let changed = false;
|
|
49
|
+
const param8 = parsedConfig.get(8);
|
|
50
|
+
if (!param8) {
|
|
51
|
+
throw new Error('[setGlobalVersion] parameter 8 is not found!');
|
|
52
|
+
}
|
|
53
|
+
const ds = param8.beginParse();
|
|
54
|
+
const tag = ds.loadUint(8);
|
|
55
|
+
const curVersion = ds.loadUint(32);
|
|
56
|
+
const newValue = (0, core_1.beginCell)().storeUint(tag, 8);
|
|
57
|
+
if (curVersion != version) {
|
|
58
|
+
changed = true;
|
|
59
|
+
}
|
|
60
|
+
newValue.storeUint(version, 32);
|
|
61
|
+
if (capabilites) {
|
|
62
|
+
const curCapabilities = ds.loadUintBig(64);
|
|
63
|
+
if (capabilites != curCapabilities) {
|
|
64
|
+
changed = true;
|
|
65
|
+
}
|
|
66
|
+
newValue.storeUint(capabilites, 64);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
newValue.storeSlice(ds);
|
|
70
|
+
}
|
|
71
|
+
// If any changes, serialize
|
|
72
|
+
if (changed) {
|
|
73
|
+
parsedConfig.set(8, newValue.endCell());
|
|
74
|
+
return (0, core_1.beginCell)().storeDictDirect(parsedConfig).endCell();
|
|
75
|
+
}
|
|
76
|
+
return config;
|
|
77
|
+
}
|
|
78
|
+
exports.setGlobalVersion = setGlobalVersion;
|
package/dist/utils/crc16.js
CHANGED
|
@@ -2,38 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.crc16 = void 0;
|
|
4
4
|
const TABLE = new Int16Array([
|
|
5
|
-
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
|
25
|
-
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
|
26
|
-
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
|
27
|
-
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
|
28
|
-
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
|
29
|
-
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
|
30
|
-
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
|
31
|
-
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
|
32
|
-
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
|
33
|
-
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
|
34
|
-
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
|
35
|
-
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
|
36
|
-
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
|
|
5
|
+
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad,
|
|
6
|
+
0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a,
|
|
7
|
+
0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b,
|
|
8
|
+
0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
|
9
|
+
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861,
|
|
10
|
+
0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96,
|
|
11
|
+
0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 0x6ca6, 0x7c87,
|
|
12
|
+
0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
|
13
|
+
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a,
|
|
14
|
+
0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3,
|
|
15
|
+
0x5004, 0x4025, 0x7046, 0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290,
|
|
16
|
+
0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
|
17
|
+
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e,
|
|
18
|
+
0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e, 0xe92f,
|
|
19
|
+
0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d, 0xdb5c,
|
|
20
|
+
0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
|
21
|
+
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83,
|
|
22
|
+
0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74,
|
|
23
|
+
0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
|
|
37
24
|
]);
|
|
38
25
|
function crc16(data) {
|
|
39
26
|
if (!(data instanceof Buffer)) {
|
package/dist/utils/ec.d.ts
CHANGED
package/dist/utils/message.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Address, Cell, Dictionary, Message, StateInit } from
|
|
2
|
-
import { ExtraCurrency } from
|
|
1
|
+
import { Address, Cell, Dictionary, Message, StateInit } from '@ton/core';
|
|
2
|
+
import { ExtraCurrency } from './ec';
|
|
3
3
|
/**
|
|
4
4
|
* Creates {@link Message} from params.
|
|
5
5
|
*/
|
|
@@ -14,7 +14,8 @@ function formatCoinsPure(value, precision = 6) {
|
|
|
14
14
|
let whole = value / decimal;
|
|
15
15
|
let frac = value % decimal;
|
|
16
16
|
const precisionDecimal = pow10(decimalCount - precision);
|
|
17
|
-
if (frac % precisionDecimal > 0n) {
|
|
17
|
+
if (frac % precisionDecimal > 0n) {
|
|
18
|
+
// round up
|
|
18
19
|
frac += precisionDecimal;
|
|
19
20
|
if (frac >= decimal) {
|
|
20
21
|
frac -= decimal;
|
|
@@ -22,7 +23,7 @@ function formatCoinsPure(value, precision = 6) {
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
frac /= precisionDecimal;
|
|
25
|
-
return `${whole.toString()}${frac !== 0n ?
|
|
26
|
+
return `${whole.toString()}${frac !== 0n ? '.' + frac.toString().padStart(precision, '0').replace(/0+$/, '') : ''}`;
|
|
26
27
|
}
|
|
27
28
|
exports.formatCoinsPure = formatCoinsPure;
|
|
28
29
|
function formatCoins(value, precision = 6) {
|
|
@@ -44,12 +45,13 @@ function formatCoins(value, precision = 6) {
|
|
|
44
45
|
* @param transactions List of transaction to print fees
|
|
45
46
|
*/
|
|
46
47
|
function printTransactionFees(transactions) {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
47
49
|
console.table(transactions
|
|
48
50
|
.map((tx) => {
|
|
49
51
|
if (tx.description.type !== 'generic')
|
|
50
52
|
return undefined;
|
|
51
53
|
const body = tx.inMessage?.info.type === 'internal' ? tx.inMessage?.body.beginParse() : undefined;
|
|
52
|
-
const op = body === undefined ? 'N/A' :
|
|
54
|
+
const op = body === undefined ? 'N/A' : body.remainingBits >= 32 ? body.preloadUint(32) : 'no body';
|
|
53
55
|
const totalFees = formatCoins(tx.totalFees.coins);
|
|
54
56
|
const computeFees = formatCoins(tx.description.computePhase.type === 'vm' ? tx.description.computePhase.gasFees : undefined);
|
|
55
57
|
const totalFwdFees = formatCoins(tx.description.actionPhase?.totalFwdFees ?? undefined);
|
|
@@ -59,7 +61,7 @@ function printTransactionFees(transactions) {
|
|
|
59
61
|
.reduce((total, message) => total + (message.info.type === 'internal' ? message.info.value.coins : 0n), 0n));
|
|
60
62
|
const forwardIn = formatCoins(tx.inMessage?.info.type === 'internal' ? tx.inMessage.info.forwardFee : undefined);
|
|
61
63
|
return {
|
|
62
|
-
op: typeof op === 'number' ?
|
|
64
|
+
op: typeof op === 'number' ? '0x' + op.toString(16) : op,
|
|
63
65
|
valueIn,
|
|
64
66
|
valueOut,
|
|
65
67
|
totalFees: totalFees,
|
package/jest-environment.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require(
|
|
1
|
+
module.exports = require('./dist/jest/BenchmarkEnvironment').default;
|
package/jest-reporter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require(
|
|
1
|
+
module.exports = require('./dist/jest/BenchmarkReporter').default;
|