@ton/sandbox 0.18.0 → 0.20.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.
@@ -2,6 +2,9 @@ import { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, Send
2
2
  export type Treasury = Sender & {
3
3
  address: Address;
4
4
  };
5
+ /**
6
+ * @class TreasuryContract is Wallet v4 alternative. For additional information see {@link Blockchain.treasury}
7
+ */
5
8
  export declare class TreasuryContract implements Contract {
6
9
  static readonly code: Cell;
7
10
  static create(workchain: number, subwalletId: bigint): TreasuryContract;
@@ -9,10 +12,27 @@ export declare class TreasuryContract implements Contract {
9
12
  readonly init: StateInit;
10
13
  readonly subwalletId: bigint;
11
14
  constructor(workchain: number, subwalletId: bigint);
15
+ /**
16
+ * Send bulk messages using one external message.
17
+ * @param messages Messages to send
18
+ * @param sendMode Send mode of every message
19
+ */
12
20
  sendMessages(provider: ContractProvider, messages: MessageRelaxed[], sendMode?: SendMode): Promise<void>;
21
+ /**
22
+ * Sends message by arguments specified.
23
+ */
13
24
  send(provider: ContractProvider, args: SenderArguments): Promise<void>;
25
+ /**
26
+ * @returns Sender
27
+ */
14
28
  getSender(provider: ContractProvider): Treasury;
29
+ /**
30
+ * @returns wallet balance in nanoTONs
31
+ */
15
32
  getBalance(provider: ContractProvider): Promise<bigint>;
33
+ /**
34
+ * Creates transfer cell for {@link sendMessages}.
35
+ */
16
36
  createTransfer(args: {
17
37
  messages: MessageRelaxed[];
18
38
  sendMode?: SendMode;
@@ -22,6 +22,9 @@ function senderArgsToMessageRelaxed(args) {
22
22
  bounce: args.bounce
23
23
  });
24
24
  }
25
+ /**
26
+ * @class TreasuryContract is Wallet v4 alternative. For additional information see {@link Blockchain.treasury}
27
+ */
25
28
  class TreasuryContract {
26
29
  static create(workchain, subwalletId) {
27
30
  return new TreasuryContract(workchain, subwalletId);
@@ -34,6 +37,11 @@ class TreasuryContract {
34
37
  this.address = (0, core_1.contractAddress)(workchain, this.init);
35
38
  this.subwalletId = subwalletId;
36
39
  }
40
+ /**
41
+ * Send bulk messages using one external message.
42
+ * @param messages Messages to send
43
+ * @param sendMode Send mode of every message
44
+ */
37
45
  async sendMessages(provider, messages, sendMode) {
38
46
  let transfer = this.createTransfer({
39
47
  sendMode: sendMode,
@@ -41,9 +49,15 @@ class TreasuryContract {
41
49
  });
42
50
  await provider.external(transfer);
43
51
  }
52
+ /**
53
+ * Sends message by arguments specified.
54
+ */
44
55
  async send(provider, args) {
45
56
  await this.sendMessages(provider, [senderArgsToMessageRelaxed(args)], args.sendMode ?? undefined);
46
57
  }
58
+ /**
59
+ * @returns Sender
60
+ */
47
61
  getSender(provider) {
48
62
  return {
49
63
  address: this.address,
@@ -56,9 +70,15 @@ class TreasuryContract {
56
70
  }
57
71
  };
58
72
  }
73
+ /**
74
+ * @returns wallet balance in nanoTONs
75
+ */
59
76
  async getBalance(provider) {
60
77
  return (await provider.getState()).balance;
61
78
  }
79
+ /**
80
+ * Creates transfer cell for {@link sendMessages}.
81
+ */
62
82
  createTransfer(args) {
63
83
  let sendMode = core_1.SendMode.PAY_GAS_SEPARATELY;
64
84
  if (args.sendMode !== null && args.sendMode !== undefined) {
@@ -1,4 +1,7 @@
1
1
  import { Address, Cell, Message, StateInit } from "@ton/core";
2
+ /**
3
+ * Creates {@link Message} from params.
4
+ */
2
5
  export declare function internal(params: {
3
6
  from: Address;
4
7
  to: Address;
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.internal = void 0;
4
4
  const core_1 = require("@ton/core");
5
+ /**
6
+ * Creates {@link Message} from params.
7
+ */
5
8
  function internal(params) {
6
9
  return {
7
10
  info: {
@@ -1,3 +1,16 @@
1
1
  import { Transaction } from "@ton/core";
2
+ /**
3
+ * @param tx Transaction to create log string
4
+ * @returns Transaction log string
5
+ */
2
6
  export declare function prettyLogTransaction(tx: Transaction): string;
7
+ /**
8
+ * Log transaction using `console.log`. Logs base on result of {@link prettyLogTransaction}.
9
+ * Example output:
10
+ * ```
11
+ * null ➡️ EQBGhqLAZseEqRXz4ByFPTGV7SVMlI4hrbs-Sps_Xzx01x8G
12
+ * ➡️ 0.05 💎 EQC2VluVfpj2FoHNMAiDMpcMzwvjLZxxTG8ecq477RE3NvVt
13
+ * ```
14
+ * @param txs Transactions to log
15
+ */
3
16
  export declare function prettyLogTransactions(txs: Transaction[]): void;
@@ -2,6 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.prettyLogTransactions = exports.prettyLogTransaction = void 0;
4
4
  const core_1 = require("@ton/core");
5
+ /**
6
+ * @param tx Transaction to create log string
7
+ * @returns Transaction log string
8
+ */
5
9
  function prettyLogTransaction(tx) {
6
10
  let res = `${tx.inMessage?.info.src} ➡️ ${tx.inMessage?.info.dest}\n`;
7
11
  for (let message of tx.outMessages.values()) {
@@ -15,6 +19,15 @@ function prettyLogTransaction(tx) {
15
19
  return res;
16
20
  }
17
21
  exports.prettyLogTransaction = prettyLogTransaction;
22
+ /**
23
+ * Log transaction using `console.log`. Logs base on result of {@link prettyLogTransaction}.
24
+ * Example output:
25
+ * ```
26
+ * null ➡️ EQBGhqLAZseEqRXz4ByFPTGV7SVMlI4hrbs-Sps_Xzx01x8G
27
+ * ➡️ 0.05 💎 EQC2VluVfpj2FoHNMAiDMpcMzwvjLZxxTG8ecq477RE3NvVt
28
+ * ```
29
+ * @param txs Transactions to log
30
+ */
18
31
  function prettyLogTransactions(txs) {
19
32
  let out = '';
20
33
  for (let tx of txs) {
@@ -1,3 +1,16 @@
1
1
  import { Transaction } from "@ton/core";
2
2
  export declare function formatCoinsPure(value: bigint, precision?: number): string;
3
+ /**
4
+ * Prints transaction fees.
5
+ * Example output:
6
+ * ```
7
+ * ┌─────────┬─────────────┬────────────────┬────────────────┬────────────────┬────────────────┬───────────────┬────────────┬────────────────┬──────────┬────────────┐
8
+ * │ (index) │ op │ valueIn │ valueOut │ totalFees │ inForwardFee │ outForwardFee │ outActions │ computeFee │ exitCode │ actionCode │
9
+ * ├─────────┼─────────────┼────────────────┼────────────────┼────────────────┼────────────────┼───────────────┼────────────┼────────────────┼──────────┼────────────┤
10
+ * │ 0 │ 'N/A' │ 'N/A' │ '1000 TON' │ '0.004007 TON' │ 'N/A' │ '0.001 TON' │ 1 │ '0.001937 TON' │ 0 │ 0 │
11
+ * │ 1 │ '0x45ab564' │ '1000 TON' │ '998.8485 TON' │ '1.051473 TON' │ '0.000667 TON' │ '0.255 TON' │ 255 │ '0.966474 TON' │ 0 │ 0 │
12
+ * │ 2 │ '0x0' │ '3.917053 TON' │ '0 TON' │ '0.00031 TON' │ '0.000667 TON' │ 'N/A' │ 0 │ '0.000309 TON' │ 0 │ 0 │
13
+ * ```
14
+ * @param transactions List of transaction to print fees
15
+ */
3
16
  export declare function printTransactionFees(transactions: Transaction[]): void;
@@ -30,6 +30,19 @@ function formatCoins(value, precision = 6) {
30
30
  return 'N/A';
31
31
  return formatCoinsPure(value, precision) + ' TON';
32
32
  }
33
+ /**
34
+ * Prints transaction fees.
35
+ * Example output:
36
+ * ```
37
+ * ┌─────────┬─────────────┬────────────────┬────────────────┬────────────────┬────────────────┬───────────────┬────────────┬────────────────┬──────────┬────────────┐
38
+ * │ (index) │ op │ valueIn │ valueOut │ totalFees │ inForwardFee │ outForwardFee │ outActions │ computeFee │ exitCode │ actionCode │
39
+ * ├─────────┼─────────────┼────────────────┼────────────────┼────────────────┼────────────────┼───────────────┼────────────┼────────────────┼──────────┼────────────┤
40
+ * │ 0 │ 'N/A' │ 'N/A' │ '1000 TON' │ '0.004007 TON' │ 'N/A' │ '0.001 TON' │ 1 │ '0.001937 TON' │ 0 │ 0 │
41
+ * │ 1 │ '0x45ab564' │ '1000 TON' │ '998.8485 TON' │ '1.051473 TON' │ '0.000667 TON' │ '0.255 TON' │ 255 │ '0.966474 TON' │ 0 │ 0 │
42
+ * │ 2 │ '0x0' │ '3.917053 TON' │ '0 TON' │ '0.00031 TON' │ '0.000667 TON' │ 'N/A' │ 0 │ '0.000309 TON' │ 0 │ 0 │
43
+ * ```
44
+ * @param transactions List of transaction to print fees
45
+ */
33
46
  function printTransactionFees(transactions) {
34
47
  console.table(transactions
35
48
  .map((tx) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ton/sandbox",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "TON transaction emulator",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",