@ton/ton 13.5.1

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 (80) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/LICENSE +9 -0
  3. package/README.md +78 -0
  4. package/dist/client/TonClient.d.ts +231 -0
  5. package/dist/client/TonClient.js +392 -0
  6. package/dist/client/TonClient.spec.d.ts +1 -0
  7. package/dist/client/TonClient.spec.js +37 -0
  8. package/dist/client/TonClient4.d.ts +289 -0
  9. package/dist/client/TonClient4.js +514 -0
  10. package/dist/client/TonClient4.spec.d.ts +1 -0
  11. package/dist/client/TonClient4.spec.js +36 -0
  12. package/dist/client/api/HttpApi.d.ts +632 -0
  13. package/dist/client/api/HttpApi.js +297 -0
  14. package/dist/client/api/TonCache.d.ts +16 -0
  15. package/dist/client/api/TonCache.js +33 -0
  16. package/dist/index.d.ts +24 -0
  17. package/dist/index.js +68 -0
  18. package/dist/jetton/JettonMaster.d.ts +21 -0
  19. package/dist/jetton/JettonMaster.js +39 -0
  20. package/dist/jetton/JettonMaster.spec.d.ts +8 -0
  21. package/dist/jetton/JettonMaster.spec.js +27 -0
  22. package/dist/jetton/JettonWallet.d.ts +14 -0
  23. package/dist/jetton/JettonWallet.js +27 -0
  24. package/dist/multisig/MultisigOrder.d.ts +17 -0
  25. package/dist/multisig/MultisigOrder.js +73 -0
  26. package/dist/multisig/MultisigOrder.spec.d.ts +1 -0
  27. package/dist/multisig/MultisigOrder.spec.js +139 -0
  28. package/dist/multisig/MultisigOrderBuilder.d.ts +13 -0
  29. package/dist/multisig/MultisigOrderBuilder.js +37 -0
  30. package/dist/multisig/MultisigWallet.d.ts +26 -0
  31. package/dist/multisig/MultisigWallet.js +120 -0
  32. package/dist/multisig/MultisigWallet.spec.d.ts +1 -0
  33. package/dist/multisig/MultisigWallet.spec.js +230 -0
  34. package/dist/utils/createTestClient.d.ts +9 -0
  35. package/dist/utils/createTestClient.js +18 -0
  36. package/dist/utils/createTestClient4.d.ts +9 -0
  37. package/dist/utils/createTestClient4.js +15 -0
  38. package/dist/utils/maybe.d.ts +8 -0
  39. package/dist/utils/maybe.js +9 -0
  40. package/dist/utils/randomTestKey.d.ts +8 -0
  41. package/dist/utils/randomTestKey.js +24 -0
  42. package/dist/utils/time.d.ts +15 -0
  43. package/dist/utils/time.js +63 -0
  44. package/dist/utils/toUrlSafe.d.ts +8 -0
  45. package/dist/utils/toUrlSafe.js +23 -0
  46. package/dist/wallets/WalletContractV1R1.d.ts +58 -0
  47. package/dist/wallets/WalletContractV1R1.js +100 -0
  48. package/dist/wallets/WalletContractV1R1.spec.d.ts +8 -0
  49. package/dist/wallets/WalletContractV1R1.spec.js +44 -0
  50. package/dist/wallets/WalletContractV1R2.d.ts +58 -0
  51. package/dist/wallets/WalletContractV1R2.js +101 -0
  52. package/dist/wallets/WalletContractV1R2.spec.d.ts +8 -0
  53. package/dist/wallets/WalletContractV1R2.spec.js +44 -0
  54. package/dist/wallets/WalletContractV1R3.d.ts +58 -0
  55. package/dist/wallets/WalletContractV1R3.js +101 -0
  56. package/dist/wallets/WalletContractV1R3.spec.d.ts +8 -0
  57. package/dist/wallets/WalletContractV1R3.spec.js +44 -0
  58. package/dist/wallets/WalletContractV2R1.d.ts +60 -0
  59. package/dist/wallets/WalletContractV2R1.js +102 -0
  60. package/dist/wallets/WalletContractV2R1.spec.d.ts +8 -0
  61. package/dist/wallets/WalletContractV2R1.spec.js +44 -0
  62. package/dist/wallets/WalletContractV2R2.d.ts +60 -0
  63. package/dist/wallets/WalletContractV2R2.js +102 -0
  64. package/dist/wallets/WalletContractV2R2.spec.d.ts +8 -0
  65. package/dist/wallets/WalletContractV2R2.spec.js +44 -0
  66. package/dist/wallets/WalletContractV3R1.d.ts +62 -0
  67. package/dist/wallets/WalletContractV3R1.js +111 -0
  68. package/dist/wallets/WalletContractV3R1.spec.d.ts +8 -0
  69. package/dist/wallets/WalletContractV3R1.spec.js +44 -0
  70. package/dist/wallets/WalletContractV3R2.d.ts +62 -0
  71. package/dist/wallets/WalletContractV3R2.js +111 -0
  72. package/dist/wallets/WalletContractV3R2.spec.d.ts +8 -0
  73. package/dist/wallets/WalletContractV3R2.spec.js +44 -0
  74. package/dist/wallets/WalletContractV4.d.ts +62 -0
  75. package/dist/wallets/WalletContractV4.js +112 -0
  76. package/dist/wallets/WalletContractV4.spec.d.ts +8 -0
  77. package/dist/wallets/WalletContractV4.spec.js +48 -0
  78. package/dist/wallets/signing/createWalletTransfer.d.ts +39 -0
  79. package/dist/wallets/signing/createWalletTransfer.js +122 -0
  80. package/package.json +68 -0
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Whales Corp.
4
+ * All Rights Reserved.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.WalletContractV3R1 = void 0;
11
+ const core_1 = require("@ton/core");
12
+ const createWalletTransfer_1 = require("./signing/createWalletTransfer");
13
+ class WalletContractV3R1 {
14
+ constructor(workchain, publicKey, walletId) {
15
+ // Resolve parameters
16
+ this.workchain = workchain;
17
+ this.publicKey = publicKey;
18
+ if (walletId !== null && walletId !== undefined) {
19
+ this.walletId = walletId;
20
+ }
21
+ else {
22
+ this.walletId = 698983191 + workchain;
23
+ }
24
+ // Build initial code and data
25
+ let code = core_1.Cell.fromBoc(Buffer.from('te6cckEBAQEAYgAAwP8AIN0gggFMl7qXMO1E0NcLH+Ck8mCDCNcYINMf0x/TH/gjE7vyY+1E0NMf0x/T/9FRMrryoVFEuvKiBPkBVBBV+RDyo/gAkyDXSpbTB9QC+wDo0QGkyMsfyx/L/8ntVD++buA=', 'base64'))[0];
26
+ let data = (0, core_1.beginCell)()
27
+ .storeUint(0, 32) // Seqno
28
+ .storeUint(this.walletId, 32)
29
+ .storeBuffer(publicKey)
30
+ .endCell();
31
+ this.init = { code, data };
32
+ this.address = (0, core_1.contractAddress)(workchain, { code, data });
33
+ }
34
+ static create(args) {
35
+ return new WalletContractV3R1(args.workchain, args.publicKey, args.walletId);
36
+ }
37
+ /**
38
+ * Get wallet balance
39
+ */
40
+ async getBalance(provider) {
41
+ let state = await provider.getState();
42
+ return state.balance;
43
+ }
44
+ /**
45
+ * Get Wallet Seqno
46
+ */
47
+ async getSeqno(provider) {
48
+ let state = await provider.getState();
49
+ if (state.state.type === 'active') {
50
+ let res = await provider.get('seqno', []);
51
+ return res.stack.readNumber();
52
+ }
53
+ else {
54
+ return 0;
55
+ }
56
+ }
57
+ /**
58
+ * Send signed transfer
59
+ */
60
+ async send(provider, message) {
61
+ await provider.external(message);
62
+ }
63
+ /**
64
+ * Sign and send transfer
65
+ */
66
+ async sendTransfer(provider, args) {
67
+ let transfer = this.createTransfer(args);
68
+ await this.send(provider, transfer);
69
+ }
70
+ /**
71
+ * Create transfer
72
+ */
73
+ createTransfer(args) {
74
+ let sendMode = core_1.SendMode.PAY_GAS_SEPARATELY;
75
+ if (args.sendMode !== null && args.sendMode !== undefined) {
76
+ sendMode = args.sendMode;
77
+ }
78
+ return (0, createWalletTransfer_1.createWalletTransferV3)({
79
+ seqno: args.seqno,
80
+ sendMode,
81
+ secretKey: args.secretKey,
82
+ messages: args.messages,
83
+ timeout: args.timeout,
84
+ walletId: this.walletId
85
+ });
86
+ }
87
+ /**
88
+ * Create sender
89
+ */
90
+ sender(provider, secretKey) {
91
+ return {
92
+ send: async (args) => {
93
+ let seqno = await this.getSeqno(provider);
94
+ let transfer = this.createTransfer({
95
+ seqno,
96
+ secretKey,
97
+ sendMode: args.sendMode,
98
+ messages: [(0, core_1.internal)({
99
+ to: args.to,
100
+ value: args.value,
101
+ init: args.init,
102
+ body: args.body,
103
+ bounce: args.bounce
104
+ })]
105
+ });
106
+ await this.send(provider, transfer);
107
+ }
108
+ };
109
+ }
110
+ }
111
+ exports.WalletContractV3R1 = WalletContractV3R1;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Whales Corp.
3
+ * All Rights Reserved.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Whales Corp.
4
+ * All Rights Reserved.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const randomTestKey_1 = require("../utils/randomTestKey");
11
+ const createTestClient4_1 = require("../utils/createTestClient4");
12
+ const core_1 = require("@ton/core");
13
+ const WalletContractV3R1_1 = require("./WalletContractV3R1");
14
+ describe('WalletContractV3R1', () => {
15
+ it('should has balance and correct address', async () => {
16
+ // Create contract
17
+ let client = (0, createTestClient4_1.createTestClient4)();
18
+ let key = (0, randomTestKey_1.randomTestKey)('v4-treasure');
19
+ let contract = client.open(WalletContractV3R1_1.WalletContractV3R1.create({ workchain: 0, publicKey: key.publicKey }));
20
+ let balance = await contract.getBalance();
21
+ // Check parameters
22
+ expect(contract.address.equals(core_1.Address.parse('EQBJp7j5N40GXJbAqFSnfTV1Af4ZTyHIMpRbKcudNhWJbbNO'))).toBe(true);
23
+ expect(balance > 0n).toBe(true);
24
+ });
25
+ it('should perform transfer', async () => {
26
+ // Create contract
27
+ let client = (0, createTestClient4_1.createTestClient4)();
28
+ let key = (0, randomTestKey_1.randomTestKey)('v4-treasure');
29
+ let contract = client.open(WalletContractV3R1_1.WalletContractV3R1.create({ workchain: 0, publicKey: key.publicKey }));
30
+ // Prepare transfer
31
+ let seqno = await contract.getSeqno();
32
+ let transfer = contract.createTransfer({
33
+ seqno,
34
+ secretKey: key.secretKey,
35
+ messages: [(0, core_1.internal)({
36
+ to: 'kQD6oPnzaaAMRW24R8F0_nlSsJQni0cGHntR027eT9_sgtwt',
37
+ value: '0.1',
38
+ body: 'Hello, world!'
39
+ })]
40
+ });
41
+ // Perform transfer
42
+ await contract.send(transfer);
43
+ });
44
+ });
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Copyright (c) Whales Corp.
3
+ * All Rights Reserved.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /// <reference types="node" />
9
+ import { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, SendMode } from "@ton/core";
10
+ import { Maybe } from "../utils/maybe";
11
+ export declare class WalletContractV3R2 implements Contract {
12
+ static create(args: {
13
+ workchain: number;
14
+ publicKey: Buffer;
15
+ walletId?: Maybe<number>;
16
+ }): WalletContractV3R2;
17
+ readonly workchain: number;
18
+ readonly publicKey: Buffer;
19
+ readonly address: Address;
20
+ readonly walletId: number;
21
+ readonly init: {
22
+ data: Cell;
23
+ code: Cell;
24
+ };
25
+ private constructor();
26
+ /**
27
+ * Get wallet balance
28
+ */
29
+ getBalance(provider: ContractProvider): Promise<bigint>;
30
+ /**
31
+ * Get Wallet Seqno
32
+ */
33
+ getSeqno(provider: ContractProvider): Promise<number>;
34
+ /**
35
+ * Send signed transfer
36
+ */
37
+ send(provider: ContractProvider, message: Cell): Promise<void>;
38
+ /**
39
+ * Sign and send transfer
40
+ */
41
+ sendTransfer(provider: ContractProvider, args: {
42
+ seqno: number;
43
+ secretKey: Buffer;
44
+ messages: MessageRelaxed[];
45
+ sendMode?: Maybe<SendMode>;
46
+ timeout?: Maybe<number>;
47
+ }): Promise<void>;
48
+ /**
49
+ * Create transfer
50
+ */
51
+ createTransfer(args: {
52
+ seqno: number;
53
+ sendMode?: Maybe<SendMode>;
54
+ secretKey: Buffer;
55
+ messages: MessageRelaxed[];
56
+ timeout?: Maybe<number>;
57
+ }): Cell;
58
+ /**
59
+ * Create sender
60
+ */
61
+ sender(provider: ContractProvider, secretKey: Buffer): Sender;
62
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Whales Corp.
4
+ * All Rights Reserved.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.WalletContractV3R2 = void 0;
11
+ const core_1 = require("@ton/core");
12
+ const createWalletTransfer_1 = require("./signing/createWalletTransfer");
13
+ class WalletContractV3R2 {
14
+ constructor(workchain, publicKey, walletId) {
15
+ // Resolve parameters
16
+ this.workchain = workchain;
17
+ this.publicKey = publicKey;
18
+ if (walletId !== null && walletId !== undefined) {
19
+ this.walletId = walletId;
20
+ }
21
+ else {
22
+ this.walletId = 698983191 + workchain;
23
+ }
24
+ // Build initial code and data
25
+ let code = core_1.Cell.fromBoc(Buffer.from('te6cckEBAQEAcQAA3v8AIN0gggFMl7ohggEznLqxn3Gw7UTQ0x/THzHXC//jBOCk8mCDCNcYINMf0x/TH/gjE7vyY+1E0NMf0x/T/9FRMrryoVFEuvKiBPkBVBBV+RDyo/gAkyDXSpbTB9QC+wDo0QGkyMsfyx/L/8ntVBC9ba0=', 'base64'))[0];
26
+ let data = (0, core_1.beginCell)()
27
+ .storeUint(0, 32) // Seqno
28
+ .storeUint(this.walletId, 32)
29
+ .storeBuffer(publicKey)
30
+ .endCell();
31
+ this.init = { code, data };
32
+ this.address = (0, core_1.contractAddress)(workchain, { code, data });
33
+ }
34
+ static create(args) {
35
+ return new WalletContractV3R2(args.workchain, args.publicKey, args.walletId);
36
+ }
37
+ /**
38
+ * Get wallet balance
39
+ */
40
+ async getBalance(provider) {
41
+ let state = await provider.getState();
42
+ return state.balance;
43
+ }
44
+ /**
45
+ * Get Wallet Seqno
46
+ */
47
+ async getSeqno(provider) {
48
+ let state = await provider.getState();
49
+ if (state.state.type === 'active') {
50
+ let res = await provider.get('seqno', []);
51
+ return res.stack.readNumber();
52
+ }
53
+ else {
54
+ return 0;
55
+ }
56
+ }
57
+ /**
58
+ * Send signed transfer
59
+ */
60
+ async send(provider, message) {
61
+ await provider.external(message);
62
+ }
63
+ /**
64
+ * Sign and send transfer
65
+ */
66
+ async sendTransfer(provider, args) {
67
+ let transfer = this.createTransfer(args);
68
+ await this.send(provider, transfer);
69
+ }
70
+ /**
71
+ * Create transfer
72
+ */
73
+ createTransfer(args) {
74
+ let sendMode = core_1.SendMode.PAY_GAS_SEPARATELY;
75
+ if (args.sendMode !== null && args.sendMode !== undefined) {
76
+ sendMode = args.sendMode;
77
+ }
78
+ return (0, createWalletTransfer_1.createWalletTransferV3)({
79
+ seqno: args.seqno,
80
+ sendMode,
81
+ secretKey: args.secretKey,
82
+ messages: args.messages,
83
+ timeout: args.timeout,
84
+ walletId: this.walletId
85
+ });
86
+ }
87
+ /**
88
+ * Create sender
89
+ */
90
+ sender(provider, secretKey) {
91
+ return {
92
+ send: async (args) => {
93
+ let seqno = await this.getSeqno(provider);
94
+ let transfer = this.createTransfer({
95
+ seqno,
96
+ secretKey,
97
+ sendMode: args.sendMode,
98
+ messages: [(0, core_1.internal)({
99
+ to: args.to,
100
+ value: args.value,
101
+ init: args.init,
102
+ body: args.body,
103
+ bounce: args.bounce
104
+ })]
105
+ });
106
+ await this.send(provider, transfer);
107
+ }
108
+ };
109
+ }
110
+ }
111
+ exports.WalletContractV3R2 = WalletContractV3R2;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Whales Corp.
3
+ * All Rights Reserved.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export {};
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Whales Corp.
4
+ * All Rights Reserved.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const randomTestKey_1 = require("../utils/randomTestKey");
11
+ const createTestClient4_1 = require("../utils/createTestClient4");
12
+ const core_1 = require("@ton/core");
13
+ const WalletContractV3R2_1 = require("./WalletContractV3R2");
14
+ describe('WalletContractV3R1', () => {
15
+ it('should has balance and correct address', async () => {
16
+ // Create contract
17
+ let client = (0, createTestClient4_1.createTestClient4)();
18
+ let key = (0, randomTestKey_1.randomTestKey)('v4-treasure');
19
+ let contract = client.open(WalletContractV3R2_1.WalletContractV3R2.create({ workchain: 0, publicKey: key.publicKey }));
20
+ let balance = await contract.getBalance();
21
+ // Check parameters
22
+ expect(contract.address.equals(core_1.Address.parse('EQA0D_5WdusaCB-SpnoE6l5TzdBmgOkzTcXrdh0px6g3zJSk'))).toBe(true);
23
+ expect(balance > 0n).toBe(true);
24
+ });
25
+ it('should perform transfer', async () => {
26
+ // Create contract
27
+ let client = (0, createTestClient4_1.createTestClient4)();
28
+ let key = (0, randomTestKey_1.randomTestKey)('v4-treasure');
29
+ let contract = client.open(WalletContractV3R2_1.WalletContractV3R2.create({ workchain: 0, publicKey: key.publicKey }));
30
+ // Prepare transfer
31
+ let seqno = await contract.getSeqno();
32
+ let transfer = contract.createTransfer({
33
+ seqno,
34
+ secretKey: key.secretKey,
35
+ messages: [(0, core_1.internal)({
36
+ to: 'kQD6oPnzaaAMRW24R8F0_nlSsJQni0cGHntR027eT9_sgtwt',
37
+ value: '0.1',
38
+ body: 'Hello, world!'
39
+ })]
40
+ });
41
+ // Perform transfer
42
+ await contract.send(transfer);
43
+ });
44
+ });
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Copyright (c) Whales Corp.
3
+ * All Rights Reserved.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /// <reference types="node" />
9
+ import { Address, Cell, Contract, ContractProvider, MessageRelaxed, Sender, SendMode } from "@ton/core";
10
+ import { Maybe } from "../utils/maybe";
11
+ export declare class WalletContractV4 implements Contract {
12
+ static create(args: {
13
+ workchain: number;
14
+ publicKey: Buffer;
15
+ walletId?: Maybe<number>;
16
+ }): WalletContractV4;
17
+ readonly workchain: number;
18
+ readonly publicKey: Buffer;
19
+ readonly address: Address;
20
+ readonly walletId: number;
21
+ readonly init: {
22
+ data: Cell;
23
+ code: Cell;
24
+ };
25
+ private constructor();
26
+ /**
27
+ * Get Wallet Balance
28
+ */
29
+ getBalance(provider: ContractProvider): Promise<bigint>;
30
+ /**
31
+ * Get Wallet Seqno
32
+ */
33
+ getSeqno(provider: ContractProvider): Promise<number>;
34
+ /**
35
+ * Send signed transfer
36
+ */
37
+ send(provider: ContractProvider, message: Cell): Promise<void>;
38
+ /**
39
+ * Sign and send transfer
40
+ */
41
+ sendTransfer(provider: ContractProvider, args: {
42
+ seqno: number;
43
+ secretKey: Buffer;
44
+ messages: MessageRelaxed[];
45
+ sendMode?: Maybe<SendMode>;
46
+ timeout?: Maybe<number>;
47
+ }): Promise<void>;
48
+ /**
49
+ * Create signed transfer
50
+ */
51
+ createTransfer(args: {
52
+ seqno: number;
53
+ secretKey: Buffer;
54
+ messages: MessageRelaxed[];
55
+ sendMode?: Maybe<SendMode>;
56
+ timeout?: Maybe<number>;
57
+ }): Cell;
58
+ /**
59
+ * Create sender
60
+ */
61
+ sender(provider: ContractProvider, secretKey: Buffer): Sender;
62
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Whales Corp.
4
+ * All Rights Reserved.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.WalletContractV4 = void 0;
11
+ const core_1 = require("@ton/core");
12
+ const createWalletTransfer_1 = require("./signing/createWalletTransfer");
13
+ class WalletContractV4 {
14
+ constructor(workchain, publicKey, walletId) {
15
+ // Resolve parameters
16
+ this.workchain = workchain;
17
+ this.publicKey = publicKey;
18
+ if (walletId !== null && walletId !== undefined) {
19
+ this.walletId = walletId;
20
+ }
21
+ else {
22
+ this.walletId = 698983191 + workchain;
23
+ }
24
+ // Build initial code and data
25
+ let code = core_1.Cell.fromBoc(Buffer.from('te6ccgECFAEAAtQAART/APSkE/S88sgLAQIBIAIDAgFIBAUE+PKDCNcYINMf0x/THwL4I7vyZO1E0NMf0x/T//QE0VFDuvKhUVG68qIF+QFUEGT5EPKj+AAkpMjLH1JAyx9SMMv/UhD0AMntVPgPAdMHIcAAn2xRkyDXSpbTB9QC+wDoMOAhwAHjACHAAuMAAcADkTDjDQOkyMsfEssfy/8QERITAubQAdDTAyFxsJJfBOAi10nBIJJfBOAC0x8hghBwbHVnvSKCEGRzdHK9sJJfBeAD+kAwIPpEAcjKB8v/ydDtRNCBAUDXIfQEMFyBAQj0Cm+hMbOSXwfgBdM/yCWCEHBsdWe6kjgw4w0DghBkc3RyupJfBuMNBgcCASAICQB4AfoA9AQw+CdvIjBQCqEhvvLgUIIQcGx1Z4MesXCAGFAEywUmzxZY+gIZ9ADLaRfLH1Jgyz8gyYBA+wAGAIpQBIEBCPRZMO1E0IEBQNcgyAHPFvQAye1UAXKwjiOCEGRzdHKDHrFwgBhQBcsFUAPPFiP6AhPLassfyz/JgED7AJJfA+ICASAKCwBZvSQrb2omhAgKBrkPoCGEcNQICEekk30pkQzmkD6f+YN4EoAbeBAUiYcVnzGEAgFYDA0AEbjJftRNDXCx+AA9sp37UTQgQFA1yH0BDACyMoHy//J0AGBAQj0Cm+hMYAIBIA4PABmtznaiaEAga5Drhf/AABmvHfaiaEAQa5DrhY/AAG7SB/oA1NQi+QAFyMoHFcv/ydB3dIAYyMsFywIizxZQBfoCFMtrEszMyXP7AMhAFIEBCPRR8qcCAHCBAQjXGPoA0z/IVCBHgQEI9FHyp4IQbm90ZXB0gBjIywXLAlAGzxZQBPoCFMtqEssfyz/Jc/sAAgBsgQEI1xj6ANM/MFIkgQEI9Fnyp4IQZHN0cnB0gBjIywXLAlAFzxZQA/oCE8tqyx8Syz/Jc/sAAAr0AMntVA==', 'base64'))[0];
26
+ let data = (0, core_1.beginCell)()
27
+ .storeUint(0, 32) // Seqno
28
+ .storeUint(this.walletId, 32)
29
+ .storeBuffer(this.publicKey)
30
+ .storeBit(0) // Empty plugins dict
31
+ .endCell();
32
+ this.init = { code, data };
33
+ this.address = (0, core_1.contractAddress)(workchain, { code, data });
34
+ }
35
+ static create(args) {
36
+ return new WalletContractV4(args.workchain, args.publicKey, args.walletId);
37
+ }
38
+ /**
39
+ * Get Wallet Balance
40
+ */
41
+ async getBalance(provider) {
42
+ let state = await provider.getState();
43
+ return state.balance;
44
+ }
45
+ /**
46
+ * Get Wallet Seqno
47
+ */
48
+ async getSeqno(provider) {
49
+ let state = await provider.getState();
50
+ if (state.state.type === 'active') {
51
+ let res = await provider.get('seqno', []);
52
+ return res.stack.readNumber();
53
+ }
54
+ else {
55
+ return 0;
56
+ }
57
+ }
58
+ /**
59
+ * Send signed transfer
60
+ */
61
+ async send(provider, message) {
62
+ await provider.external(message);
63
+ }
64
+ /**
65
+ * Sign and send transfer
66
+ */
67
+ async sendTransfer(provider, args) {
68
+ let transfer = this.createTransfer(args);
69
+ await this.send(provider, transfer);
70
+ }
71
+ /**
72
+ * Create signed transfer
73
+ */
74
+ createTransfer(args) {
75
+ let sendMode = core_1.SendMode.PAY_GAS_SEPARATELY;
76
+ if (args.sendMode !== null && args.sendMode !== undefined) {
77
+ sendMode = args.sendMode;
78
+ }
79
+ return (0, createWalletTransfer_1.createWalletTransferV4)({
80
+ seqno: args.seqno,
81
+ sendMode,
82
+ secretKey: args.secretKey,
83
+ messages: args.messages,
84
+ timeout: args.timeout,
85
+ walletId: this.walletId
86
+ });
87
+ }
88
+ /**
89
+ * Create sender
90
+ */
91
+ sender(provider, secretKey) {
92
+ return {
93
+ send: async (args) => {
94
+ let seqno = await this.getSeqno(provider);
95
+ let transfer = this.createTransfer({
96
+ seqno,
97
+ secretKey,
98
+ sendMode: args.sendMode,
99
+ messages: [(0, core_1.internal)({
100
+ to: args.to,
101
+ value: args.value,
102
+ init: args.init,
103
+ body: args.body,
104
+ bounce: args.bounce
105
+ })]
106
+ });
107
+ await this.send(provider, transfer);
108
+ }
109
+ };
110
+ }
111
+ }
112
+ exports.WalletContractV4 = WalletContractV4;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Whales Corp.
3
+ * All Rights Reserved.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Whales Corp.
4
+ * All Rights Reserved.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const randomTestKey_1 = require("../utils/randomTestKey");
11
+ const WalletContractV4_1 = require("./WalletContractV4");
12
+ const createTestClient4_1 = require("../utils/createTestClient4");
13
+ const core_1 = require("@ton/core");
14
+ describe('WalletContractV4', () => {
15
+ it('should has balance and correct address', async () => {
16
+ // Create contract
17
+ let client = (0, createTestClient4_1.createTestClient4)();
18
+ let key = (0, randomTestKey_1.randomTestKey)('v4-treasure');
19
+ let contract = client.open(WalletContractV4_1.WalletContractV4.create({ workchain: 0, publicKey: key.publicKey }));
20
+ let balance = await contract.getBalance();
21
+ // Check parameters
22
+ expect(contract.address.equals(core_1.Address.parse('EQDnBF4JTFKHTYjulEJyNd4dstLGH1m51UrLdu01_tw4z2Au'))).toBe(true);
23
+ expect(balance > 0n).toBe(true);
24
+ });
25
+ it('should perform transfer', async () => {
26
+ // Create contract
27
+ let client = (0, createTestClient4_1.createTestClient4)();
28
+ let key = (0, randomTestKey_1.randomTestKey)('v4-treasure');
29
+ let contract = client.open(WalletContractV4_1.WalletContractV4.create({ workchain: 0, publicKey: key.publicKey }));
30
+ // Prepare transfer
31
+ let seqno = await contract.getSeqno();
32
+ let transfer = contract.createTransfer({
33
+ seqno,
34
+ secretKey: key.secretKey,
35
+ messages: [(0, core_1.internal)({
36
+ to: 'kQD6oPnzaaAMRW24R8F0_nlSsJQni0cGHntR027eT9_sgtwt',
37
+ value: '0.1',
38
+ body: 'Hello world: 1'
39
+ }), (0, core_1.internal)({
40
+ to: 'kQD6oPnzaaAMRW24R8F0_nlSsJQni0cGHntR027eT9_sgtwt',
41
+ value: '0.1',
42
+ body: 'Hello world: 2'
43
+ })]
44
+ });
45
+ // Perform transfer
46
+ await contract.send(transfer);
47
+ });
48
+ });
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright (c) Whales Corp.
3
+ * All Rights Reserved.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /// <reference types="node" />
9
+ import { MessageRelaxed } from "@ton/core";
10
+ import { Maybe } from "../../utils/maybe";
11
+ export declare function createWalletTransferV1(args: {
12
+ seqno: number;
13
+ sendMode: number;
14
+ message: Maybe<MessageRelaxed>;
15
+ secretKey: Buffer;
16
+ }): import("@ton/core").Cell;
17
+ export declare function createWalletTransferV2(args: {
18
+ seqno: number;
19
+ sendMode: number;
20
+ messages: MessageRelaxed[];
21
+ secretKey: Buffer;
22
+ timeout?: Maybe<number>;
23
+ }): import("@ton/core").Cell;
24
+ export declare function createWalletTransferV3(args: {
25
+ seqno: number;
26
+ sendMode: number;
27
+ walletId: number;
28
+ messages: MessageRelaxed[];
29
+ secretKey: Buffer;
30
+ timeout?: Maybe<number>;
31
+ }): import("@ton/core").Cell;
32
+ export declare function createWalletTransferV4(args: {
33
+ seqno: number;
34
+ sendMode: number;
35
+ walletId: number;
36
+ messages: MessageRelaxed[];
37
+ secretKey: Buffer;
38
+ timeout?: Maybe<number>;
39
+ }): import("@ton/core").Cell;