@ton/sandbox 0.11.0

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +221 -0
  2. package/LICENSE +21 -0
  3. package/README.md +214 -0
  4. package/dist/blockchain/Blockchain.d.ts +120 -0
  5. package/dist/blockchain/Blockchain.js +327 -0
  6. package/dist/blockchain/BlockchainContractProvider.d.ts +30 -0
  7. package/dist/blockchain/BlockchainContractProvider.js +90 -0
  8. package/dist/blockchain/BlockchainSender.d.ts +9 -0
  9. package/dist/blockchain/BlockchainSender.js +29 -0
  10. package/dist/blockchain/BlockchainStorage.d.ts +64 -0
  11. package/dist/blockchain/BlockchainStorage.js +105 -0
  12. package/dist/blockchain/SmartContract.d.ts +93 -0
  13. package/dist/blockchain/SmartContract.js +289 -0
  14. package/dist/config/defaultConfig.d.ts +2 -0
  15. package/dist/config/defaultConfig.js +5 -0
  16. package/dist/config/slimConfig.d.ts +2 -0
  17. package/dist/config/slimConfig.js +5 -0
  18. package/dist/event/Event.d.ts +19 -0
  19. package/dist/event/Event.js +46 -0
  20. package/dist/executor/Executor.d.ts +90 -0
  21. package/dist/executor/Executor.js +208 -0
  22. package/dist/executor/emulator-emscripten.js +21 -0
  23. package/dist/executor/emulator-emscripten.wasm.js +1 -0
  24. package/dist/index.d.ts +12 -0
  25. package/dist/index.js +31 -0
  26. package/dist/treasury/Treasury.d.ts +23 -0
  27. package/dist/treasury/Treasury.js +82 -0
  28. package/dist/utils/AsyncLock.d.ts +6 -0
  29. package/dist/utils/AsyncLock.js +48 -0
  30. package/dist/utils/base64.d.ts +1 -0
  31. package/dist/utils/base64.js +42 -0
  32. package/dist/utils/crc16.d.ts +2 -0
  33. package/dist/utils/crc16.js +49 -0
  34. package/dist/utils/message.d.ts +15 -0
  35. package/dist/utils/message.js +24 -0
  36. package/dist/utils/prettyLogTransaction.d.ts +3 -0
  37. package/dist/utils/prettyLogTransaction.js +25 -0
  38. package/dist/utils/printTransactionFees.d.ts +3 -0
  39. package/dist/utils/printTransactionFees.js +63 -0
  40. package/dist/utils/selector.d.ts +1 -0
  41. package/dist/utils/selector.js +19 -0
  42. package/dist/utils/testTreasurySubwalletId.d.ts +1 -0
  43. package/dist/utils/testTreasurySubwalletId.js +9 -0
  44. package/package.json +38 -0
@@ -0,0 +1,12 @@
1
+ export { defaultConfig, defaultConfigSeqno, } from './config/defaultConfig';
2
+ export { Blockchain, SendMessageResult, BlockchainTransaction, PendingMessage, SandboxContract, ExternalOut, ExternalOutInfo, BlockchainConfig, BlockchainSnapshot, } from './blockchain/Blockchain';
3
+ export { BlockchainContractProvider, SandboxContractProvider, } from './blockchain/BlockchainContractProvider';
4
+ export { BlockchainSender, } from './blockchain/BlockchainSender';
5
+ export { BlockchainStorage, LocalBlockchainStorage, RemoteBlockchainStorage, RemoteBlockchainStorageClient, wrapTonClient4ForRemote, } from './blockchain/BlockchainStorage';
6
+ export { Verbosity, LogsVerbosity, SmartContract, SmartContractTransaction, MessageParams, GetMethodParams, GetMethodResult, createEmptyShardAccount, createShardAccount, GetMethodError, TimeError, SmartContractSnapshot, } from './blockchain/SmartContract';
7
+ export { TickOrTock, } from './executor/Executor';
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';
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.internal = exports.printTransactionFees = exports.prettyLogTransactions = exports.prettyLogTransaction = exports.TreasuryContract = exports.TimeError = exports.GetMethodError = exports.createShardAccount = exports.createEmptyShardAccount = exports.SmartContract = exports.wrapTonClient4ForRemote = exports.RemoteBlockchainStorage = exports.LocalBlockchainStorage = exports.BlockchainSender = exports.BlockchainContractProvider = exports.Blockchain = exports.defaultConfigSeqno = exports.defaultConfig = void 0;
4
+ var defaultConfig_1 = require("./config/defaultConfig");
5
+ Object.defineProperty(exports, "defaultConfig", { enumerable: true, get: function () { return defaultConfig_1.defaultConfig; } });
6
+ Object.defineProperty(exports, "defaultConfigSeqno", { enumerable: true, get: function () { return defaultConfig_1.defaultConfigSeqno; } });
7
+ var Blockchain_1 = require("./blockchain/Blockchain");
8
+ Object.defineProperty(exports, "Blockchain", { enumerable: true, get: function () { return Blockchain_1.Blockchain; } });
9
+ var BlockchainContractProvider_1 = require("./blockchain/BlockchainContractProvider");
10
+ Object.defineProperty(exports, "BlockchainContractProvider", { enumerable: true, get: function () { return BlockchainContractProvider_1.BlockchainContractProvider; } });
11
+ var BlockchainSender_1 = require("./blockchain/BlockchainSender");
12
+ Object.defineProperty(exports, "BlockchainSender", { enumerable: true, get: function () { return BlockchainSender_1.BlockchainSender; } });
13
+ var BlockchainStorage_1 = require("./blockchain/BlockchainStorage");
14
+ Object.defineProperty(exports, "LocalBlockchainStorage", { enumerable: true, get: function () { return BlockchainStorage_1.LocalBlockchainStorage; } });
15
+ Object.defineProperty(exports, "RemoteBlockchainStorage", { enumerable: true, get: function () { return BlockchainStorage_1.RemoteBlockchainStorage; } });
16
+ Object.defineProperty(exports, "wrapTonClient4ForRemote", { enumerable: true, get: function () { return BlockchainStorage_1.wrapTonClient4ForRemote; } });
17
+ var SmartContract_1 = require("./blockchain/SmartContract");
18
+ Object.defineProperty(exports, "SmartContract", { enumerable: true, get: function () { return SmartContract_1.SmartContract; } });
19
+ Object.defineProperty(exports, "createEmptyShardAccount", { enumerable: true, get: function () { return SmartContract_1.createEmptyShardAccount; } });
20
+ Object.defineProperty(exports, "createShardAccount", { enumerable: true, get: function () { return SmartContract_1.createShardAccount; } });
21
+ Object.defineProperty(exports, "GetMethodError", { enumerable: true, get: function () { return SmartContract_1.GetMethodError; } });
22
+ Object.defineProperty(exports, "TimeError", { enumerable: true, get: function () { return SmartContract_1.TimeError; } });
23
+ var Treasury_1 = require("./treasury/Treasury");
24
+ Object.defineProperty(exports, "TreasuryContract", { enumerable: true, get: function () { return Treasury_1.TreasuryContract; } });
25
+ var prettyLogTransaction_1 = require("./utils/prettyLogTransaction");
26
+ Object.defineProperty(exports, "prettyLogTransaction", { enumerable: true, get: function () { return prettyLogTransaction_1.prettyLogTransaction; } });
27
+ Object.defineProperty(exports, "prettyLogTransactions", { enumerable: true, get: function () { return prettyLogTransaction_1.prettyLogTransactions; } });
28
+ var printTransactionFees_1 = require("./utils/printTransactionFees");
29
+ Object.defineProperty(exports, "printTransactionFees", { enumerable: true, get: function () { return printTransactionFees_1.printTransactionFees; } });
30
+ var message_1 = require("./utils/message");
31
+ Object.defineProperty(exports, "internal", { enumerable: true, get: function () { return message_1.internal; } });
@@ -0,0 +1,23 @@
1
+ import { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, SenderArguments, SendMode } from "ton-core";
2
+ export type Treasury = Sender & {
3
+ address: Address;
4
+ };
5
+ export declare class TreasuryContract implements Contract {
6
+ static readonly code: Cell;
7
+ static create(workchain: number, subwalletId: bigint): TreasuryContract;
8
+ readonly address: Address;
9
+ readonly init: {
10
+ code: Cell;
11
+ data: Cell;
12
+ };
13
+ readonly subwalletId: bigint;
14
+ constructor(workchain: number, subwalletId: bigint);
15
+ sendMessages(provider: ContractProvider, messages: MessageRelaxed[], sendMode?: SendMode): Promise<void>;
16
+ send(provider: ContractProvider, args: SenderArguments): Promise<void>;
17
+ getSender(provider: ContractProvider): Treasury;
18
+ getBalance(provider: ContractProvider): Promise<bigint>;
19
+ createTransfer(args: {
20
+ messages: MessageRelaxed[];
21
+ sendMode?: SendMode;
22
+ }): Cell;
23
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TreasuryContract = void 0;
4
+ const ton_core_1 = require("ton-core");
5
+ const DictionaryMessageValue = {
6
+ serialize(src, builder) {
7
+ builder.storeUint(src.sendMode, 8);
8
+ builder.storeRef((0, ton_core_1.beginCell)().store((0, ton_core_1.storeMessageRelaxed)(src.message)));
9
+ },
10
+ parse(src) {
11
+ let sendMode = src.loadUint(8);
12
+ let message = (0, ton_core_1.loadMessageRelaxed)(src.loadRef().beginParse());
13
+ return { sendMode, message };
14
+ },
15
+ };
16
+ function senderArgsToMessageRelaxed(args) {
17
+ return (0, ton_core_1.internal)({
18
+ to: args.to,
19
+ value: args.value,
20
+ init: args.init,
21
+ body: args.body,
22
+ bounce: args.bounce
23
+ });
24
+ }
25
+ class TreasuryContract {
26
+ static create(workchain, subwalletId) {
27
+ return new TreasuryContract(workchain, subwalletId);
28
+ }
29
+ constructor(workchain, subwalletId) {
30
+ const data = (0, ton_core_1.beginCell)()
31
+ .storeUint(subwalletId, 256)
32
+ .endCell();
33
+ this.init = { code: TreasuryContract.code, data };
34
+ this.address = (0, ton_core_1.contractAddress)(workchain, this.init);
35
+ this.subwalletId = subwalletId;
36
+ }
37
+ async sendMessages(provider, messages, sendMode) {
38
+ let transfer = this.createTransfer({
39
+ sendMode: sendMode,
40
+ messages: messages
41
+ });
42
+ await provider.external(transfer);
43
+ }
44
+ async send(provider, args) {
45
+ await this.sendMessages(provider, [senderArgsToMessageRelaxed(args)], args.sendMode ?? undefined);
46
+ }
47
+ getSender(provider) {
48
+ return {
49
+ address: this.address,
50
+ send: async (args) => {
51
+ let transfer = this.createTransfer({
52
+ sendMode: args.sendMode ?? undefined,
53
+ messages: [senderArgsToMessageRelaxed(args)]
54
+ });
55
+ await provider.external(transfer);
56
+ }
57
+ };
58
+ }
59
+ async getBalance(provider) {
60
+ return (await provider.getState()).balance;
61
+ }
62
+ createTransfer(args) {
63
+ let sendMode = ton_core_1.SendMode.PAY_GAS_SEPARATELY;
64
+ if (args.sendMode !== null && args.sendMode !== undefined) {
65
+ sendMode = args.sendMode;
66
+ }
67
+ if (args.messages.length > 255) {
68
+ throw new Error('Maximum number of messages is 255');
69
+ }
70
+ let messages = ton_core_1.Dictionary.empty(ton_core_1.Dictionary.Keys.Int(16), DictionaryMessageValue);
71
+ let index = 0;
72
+ for (let m of args.messages) {
73
+ messages.set(index++, { sendMode, message: m });
74
+ }
75
+ return (0, ton_core_1.beginCell)()
76
+ .storeUint(this.subwalletId, 256)
77
+ .storeDict(messages)
78
+ .endCell();
79
+ }
80
+ }
81
+ exports.TreasuryContract = TreasuryContract;
82
+ TreasuryContract.code = ton_core_1.Cell.fromBase64('te6cckEBBAEARQABFP8A9KQT9LzyyAsBAgEgAwIAWvLT/+1E0NP/0RK68qL0BNH4AH+OFiGAEPR4b6UgmALTB9QwAfsAkTLiAbPmWwAE0jD+omUe');
@@ -0,0 +1,6 @@
1
+ export declare class AsyncLock {
2
+ #private;
3
+ acquire(): Promise<void>;
4
+ release(): Promise<void>;
5
+ with<T>(fn: () => Promise<T>): Promise<T>;
6
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _AsyncLock_waiters;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AsyncLock = void 0;
10
+ function createWaiter() {
11
+ const w = { promise: undefined, resolve: undefined };
12
+ w.promise = new Promise((res) => {
13
+ w.resolve = res;
14
+ });
15
+ return w;
16
+ }
17
+ class AsyncLock {
18
+ constructor() {
19
+ _AsyncLock_waiters.set(this, []);
20
+ }
21
+ async acquire() {
22
+ const waiters = __classPrivateFieldGet(this, _AsyncLock_waiters, "f").map(w => w.promise);
23
+ __classPrivateFieldGet(this, _AsyncLock_waiters, "f").push(createWaiter());
24
+ if (waiters.length > 0) {
25
+ await Promise.all(waiters);
26
+ }
27
+ }
28
+ async release() {
29
+ const waiter = __classPrivateFieldGet(this, _AsyncLock_waiters, "f").shift();
30
+ if (waiter !== undefined) {
31
+ waiter.resolve();
32
+ }
33
+ else {
34
+ throw new Error('The lock is not locked');
35
+ }
36
+ }
37
+ async with(fn) {
38
+ await this.acquire();
39
+ try {
40
+ return await fn();
41
+ }
42
+ finally {
43
+ await this.release();
44
+ }
45
+ }
46
+ }
47
+ exports.AsyncLock = AsyncLock;
48
+ _AsyncLock_waiters = new WeakMap();
@@ -0,0 +1 @@
1
+ export declare function base64Decode(sBase64: string): Uint8Array;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ // Credits: https://developer.mozilla.org/en-US/docs/Glossary/Base64#solution_2_–_rewriting_atob_and_btoa_using_typedarrays_and_utf-8
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.base64Decode = void 0;
5
+ function b64ToUint6(nChr) {
6
+ return nChr > 64 && nChr < 91
7
+ ? nChr - 65
8
+ : nChr > 96 && nChr < 123
9
+ ? nChr - 71
10
+ : nChr > 47 && nChr < 58
11
+ ? nChr + 4
12
+ : nChr === 43
13
+ ? 62
14
+ : nChr === 47
15
+ ? 63
16
+ : 0;
17
+ }
18
+ function base64Decode(sBase64) {
19
+ const sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, "");
20
+ const nInLen = sB64Enc.length;
21
+ const nOutLen = (nInLen * 3 + 1) >> 2;
22
+ const taBytes = new Uint8Array(nOutLen);
23
+ let nMod3;
24
+ let nMod4;
25
+ let nUint24 = 0;
26
+ let nOutIdx = 0;
27
+ for (let nInIdx = 0; nInIdx < nInLen; nInIdx++) {
28
+ nMod4 = nInIdx & 3;
29
+ nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << (6 * (3 - nMod4));
30
+ if (nMod4 === 3 || nInLen - nInIdx === 1) {
31
+ nMod3 = 0;
32
+ while (nMod3 < 3 && nOutIdx < nOutLen) {
33
+ taBytes[nOutIdx] = (nUint24 >>> ((16 >>> nMod3) & 24)) & 255;
34
+ nMod3++;
35
+ nOutIdx++;
36
+ }
37
+ nUint24 = 0;
38
+ }
39
+ }
40
+ return taBytes;
41
+ }
42
+ exports.base64Decode = base64Decode;
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" />
2
+ export declare function crc16(data: string | Buffer): number;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.crc16 = void 0;
4
+ const TABLE = new Int16Array([
5
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
6
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
7
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
8
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
9
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
10
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
11
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
12
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
13
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
14
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
15
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
16
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
17
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
18
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
19
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
20
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
21
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
22
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
23
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
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
37
+ ]);
38
+ function crc16(data) {
39
+ if (!(data instanceof Buffer)) {
40
+ data = Buffer.from(data);
41
+ }
42
+ let crc = 0;
43
+ for (let index = 0; index < data.length; index++) {
44
+ const byte = data[index];
45
+ crc = (TABLE[((crc >> 8) ^ byte) & 0xff] ^ (crc << 8)) & 0xffff;
46
+ }
47
+ return crc;
48
+ }
49
+ exports.crc16 = crc16;
@@ -0,0 +1,15 @@
1
+ import { Address, Cell, Message, StateInit } from "ton-core";
2
+ export declare function internal(params: {
3
+ from: Address;
4
+ to: Address;
5
+ value: bigint;
6
+ body?: Cell;
7
+ stateInit?: StateInit;
8
+ bounce?: boolean;
9
+ bounced?: boolean;
10
+ ihrDisabled?: boolean;
11
+ ihrFee?: bigint;
12
+ forwardFee?: bigint;
13
+ createdAt?: number;
14
+ createdLt?: bigint;
15
+ }): Message;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.internal = void 0;
4
+ const ton_core_1 = require("ton-core");
5
+ function internal(params) {
6
+ return {
7
+ info: {
8
+ type: 'internal',
9
+ dest: params.to,
10
+ src: params.from,
11
+ value: { coins: params.value },
12
+ bounce: params.bounce ?? true,
13
+ ihrDisabled: params.ihrDisabled ?? true,
14
+ bounced: params.bounced ?? false,
15
+ ihrFee: params.ihrFee ?? 0n,
16
+ forwardFee: params.forwardFee ?? 0n,
17
+ createdAt: params.createdAt ?? 0,
18
+ createdLt: params.createdLt ?? 0n,
19
+ },
20
+ body: params.body ?? new ton_core_1.Cell(),
21
+ init: params.stateInit,
22
+ };
23
+ }
24
+ exports.internal = internal;
@@ -0,0 +1,3 @@
1
+ import { Transaction } from "ton-core";
2
+ export declare function prettyLogTransaction(tx: Transaction): string;
3
+ export declare function prettyLogTransactions(txs: Transaction[]): void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prettyLogTransactions = exports.prettyLogTransaction = void 0;
4
+ const ton_core_1 = require("ton-core");
5
+ function prettyLogTransaction(tx) {
6
+ let res = `${tx.inMessage?.info.src} ➡️ ${tx.inMessage?.info.dest}\n`;
7
+ for (let message of tx.outMessages.values()) {
8
+ if (message.info.type === 'internal') {
9
+ res += ` ➡️ ${(0, ton_core_1.fromNano)(message.info.value.coins)} 💎 ${message.info.dest}\n`;
10
+ }
11
+ else {
12
+ res += ` ➡️ ${message.info.dest}\n`;
13
+ }
14
+ }
15
+ return res;
16
+ }
17
+ exports.prettyLogTransaction = prettyLogTransaction;
18
+ function prettyLogTransactions(txs) {
19
+ let out = '';
20
+ for (let tx of txs) {
21
+ out += prettyLogTransaction(tx) + '\n\n';
22
+ }
23
+ console.log(out);
24
+ }
25
+ exports.prettyLogTransactions = prettyLogTransactions;
@@ -0,0 +1,3 @@
1
+ import { Transaction } from "ton-core";
2
+ export declare function formatCoinsPure(value: bigint, precision?: number): string;
3
+ export declare function printTransactionFees(transactions: Transaction[]): void;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printTransactionFees = exports.formatCoinsPure = void 0;
4
+ const decimalCount = 9;
5
+ const decimal = pow10(decimalCount);
6
+ function pow10(n) {
7
+ let v = 1n;
8
+ for (let i = 0; i < n; i++) {
9
+ v *= 10n;
10
+ }
11
+ return v;
12
+ }
13
+ function formatCoinsPure(value, precision = 6) {
14
+ let whole = value / decimal;
15
+ let frac = value % decimal;
16
+ const precisionDecimal = pow10(decimalCount - precision);
17
+ if (frac % precisionDecimal > 0n) { // round up
18
+ frac += precisionDecimal;
19
+ if (frac >= decimal) {
20
+ frac -= decimal;
21
+ whole += 1n;
22
+ }
23
+ }
24
+ frac /= precisionDecimal;
25
+ return `${whole.toString()}${frac !== 0n ? ('.' + frac.toString().padStart(precision, '0').replace(/0+$/, '')) : ''}`;
26
+ }
27
+ exports.formatCoinsPure = formatCoinsPure;
28
+ function formatCoins(value, precision = 6) {
29
+ if (value === undefined)
30
+ return 'N/A';
31
+ return formatCoinsPure(value, precision) + ' TON';
32
+ }
33
+ function printTransactionFees(transactions) {
34
+ console.table(transactions
35
+ .map((tx) => {
36
+ if (tx.description.type !== 'generic')
37
+ return undefined;
38
+ const body = tx.inMessage?.info.type === 'internal' ? tx.inMessage?.body.beginParse() : undefined;
39
+ const op = body === undefined ? 'N/A' : (body.remainingBits >= 32 ? body.preloadUint(32) : 'no body');
40
+ const totalFees = formatCoins(tx.totalFees.coins);
41
+ const computeFees = formatCoins(tx.description.computePhase.type === 'vm' ? tx.description.computePhase.gasFees : undefined);
42
+ const totalFwdFees = formatCoins(tx.description.actionPhase?.totalFwdFees ?? undefined);
43
+ const valueIn = formatCoins(tx.inMessage?.info.type === 'internal' ? tx.inMessage.info.value.coins : undefined);
44
+ const valueOut = formatCoins(tx.outMessages
45
+ .values()
46
+ .reduce((total, message) => total + (message.info.type === 'internal' ? message.info.value.coins : 0n), 0n));
47
+ const forwardIn = formatCoins(tx.inMessage?.info.type === 'internal' ? tx.inMessage.info.forwardFee : undefined);
48
+ return {
49
+ op: typeof op === 'number' ? ('0x' + op.toString(16)) : op,
50
+ valueIn,
51
+ valueOut,
52
+ totalFees: totalFees,
53
+ inForwardFee: forwardIn,
54
+ outForwardFee: totalFwdFees,
55
+ outActions: tx.description.actionPhase?.totalActions ?? 'N/A',
56
+ computeFee: computeFees,
57
+ exitCode: tx.description.computePhase.type === 'vm' ? tx.description.computePhase.exitCode : 'N/A',
58
+ actionCode: tx.description.actionPhase?.resultCode ?? 'N/A',
59
+ };
60
+ })
61
+ .filter((v) => v !== undefined));
62
+ }
63
+ exports.printTransactionFees = printTransactionFees;
@@ -0,0 +1 @@
1
+ export declare function getSelectorForMethod(methodName: string): number;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSelectorForMethod = void 0;
4
+ const crc16_1 = require("./crc16");
5
+ function getSelectorForMethod(methodName) {
6
+ if (methodName === 'main') {
7
+ return 0;
8
+ }
9
+ else if (methodName === 'recv_internal') {
10
+ return 0;
11
+ }
12
+ else if (methodName === 'recv_external') {
13
+ return -1;
14
+ }
15
+ else {
16
+ return ((0, crc16_1.crc16)(methodName) & 0xffff) | 0x10000;
17
+ }
18
+ }
19
+ exports.getSelectorForMethod = getSelectorForMethod;
@@ -0,0 +1 @@
1
+ export declare function testSubwalletId(seed: string): bigint;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.testSubwalletId = void 0;
4
+ const ton_crypto_1 = require("ton-crypto");
5
+ const prefix = 'TESTSEED';
6
+ function testSubwalletId(seed) {
7
+ return BigInt('0x' + (0, ton_crypto_1.sha256_sync)(prefix + seed).toString('hex'));
8
+ }
9
+ exports.testSubwalletId = testSubwalletId;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@ton/sandbox",
3
+ "version": "0.11.0",
4
+ "description": "TON transaction emulator",
5
+ "main": "dist/index.js",
6
+ "license": "MIT",
7
+ "author": "TonTech",
8
+ "files": [
9
+ "dist/**/*"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ton-org/sandbox"
14
+ },
15
+ "devDependencies": {
16
+ "@ton-community/test-utils": "^0.2.0",
17
+ "@types/jest": "^29.5.0",
18
+ "@types/node": "^18.15.11",
19
+ "jest": "^29.5.0",
20
+ "ton": "^13.4.1",
21
+ "ton-core": "^0.49.0",
22
+ "ton-crypto": "3.2.0",
23
+ "ts-jest": "^29.0.5",
24
+ "ts-node": "^10.9.1",
25
+ "typescript": "^4.9.5"
26
+ },
27
+ "peerDependencies": {
28
+ "ton-core": ">=0.48.0",
29
+ "ton-crypto": ">=3.2.0"
30
+ },
31
+ "scripts": {
32
+ "wasm:pack": "ts-node ./scripts/pack-wasm.ts",
33
+ "wasm:copy": "cp src/executor/emulator-emscripten.js src/executor/emulator-emscripten.wasm.js ./dist/executor",
34
+ "test": "yarn wasm:pack && yarn jest src",
35
+ "build": "rm -rf dist && yarn wasm:pack && yarn test && tsc && yarn wasm:copy",
36
+ "config:pack": "ts-node ./scripts/pack-config.ts"
37
+ }
38
+ }