@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.
- package/CHANGELOG.md +133 -0
- package/LICENSE +9 -0
- package/README.md +78 -0
- package/dist/client/TonClient.d.ts +231 -0
- package/dist/client/TonClient.js +392 -0
- package/dist/client/TonClient.spec.d.ts +1 -0
- package/dist/client/TonClient.spec.js +37 -0
- package/dist/client/TonClient4.d.ts +289 -0
- package/dist/client/TonClient4.js +514 -0
- package/dist/client/TonClient4.spec.d.ts +1 -0
- package/dist/client/TonClient4.spec.js +36 -0
- package/dist/client/api/HttpApi.d.ts +632 -0
- package/dist/client/api/HttpApi.js +297 -0
- package/dist/client/api/TonCache.d.ts +16 -0
- package/dist/client/api/TonCache.js +33 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +68 -0
- package/dist/jetton/JettonMaster.d.ts +21 -0
- package/dist/jetton/JettonMaster.js +39 -0
- package/dist/jetton/JettonMaster.spec.d.ts +8 -0
- package/dist/jetton/JettonMaster.spec.js +27 -0
- package/dist/jetton/JettonWallet.d.ts +14 -0
- package/dist/jetton/JettonWallet.js +27 -0
- package/dist/multisig/MultisigOrder.d.ts +17 -0
- package/dist/multisig/MultisigOrder.js +73 -0
- package/dist/multisig/MultisigOrder.spec.d.ts +1 -0
- package/dist/multisig/MultisigOrder.spec.js +139 -0
- package/dist/multisig/MultisigOrderBuilder.d.ts +13 -0
- package/dist/multisig/MultisigOrderBuilder.js +37 -0
- package/dist/multisig/MultisigWallet.d.ts +26 -0
- package/dist/multisig/MultisigWallet.js +120 -0
- package/dist/multisig/MultisigWallet.spec.d.ts +1 -0
- package/dist/multisig/MultisigWallet.spec.js +230 -0
- package/dist/utils/createTestClient.d.ts +9 -0
- package/dist/utils/createTestClient.js +18 -0
- package/dist/utils/createTestClient4.d.ts +9 -0
- package/dist/utils/createTestClient4.js +15 -0
- package/dist/utils/maybe.d.ts +8 -0
- package/dist/utils/maybe.js +9 -0
- package/dist/utils/randomTestKey.d.ts +8 -0
- package/dist/utils/randomTestKey.js +24 -0
- package/dist/utils/time.d.ts +15 -0
- package/dist/utils/time.js +63 -0
- package/dist/utils/toUrlSafe.d.ts +8 -0
- package/dist/utils/toUrlSafe.js +23 -0
- package/dist/wallets/WalletContractV1R1.d.ts +58 -0
- package/dist/wallets/WalletContractV1R1.js +100 -0
- package/dist/wallets/WalletContractV1R1.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV1R1.spec.js +44 -0
- package/dist/wallets/WalletContractV1R2.d.ts +58 -0
- package/dist/wallets/WalletContractV1R2.js +101 -0
- package/dist/wallets/WalletContractV1R2.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV1R2.spec.js +44 -0
- package/dist/wallets/WalletContractV1R3.d.ts +58 -0
- package/dist/wallets/WalletContractV1R3.js +101 -0
- package/dist/wallets/WalletContractV1R3.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV1R3.spec.js +44 -0
- package/dist/wallets/WalletContractV2R1.d.ts +60 -0
- package/dist/wallets/WalletContractV2R1.js +102 -0
- package/dist/wallets/WalletContractV2R1.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV2R1.spec.js +44 -0
- package/dist/wallets/WalletContractV2R2.d.ts +60 -0
- package/dist/wallets/WalletContractV2R2.js +102 -0
- package/dist/wallets/WalletContractV2R2.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV2R2.spec.js +44 -0
- package/dist/wallets/WalletContractV3R1.d.ts +62 -0
- package/dist/wallets/WalletContractV3R1.js +111 -0
- package/dist/wallets/WalletContractV3R1.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV3R1.spec.js +44 -0
- package/dist/wallets/WalletContractV3R2.d.ts +62 -0
- package/dist/wallets/WalletContractV3R2.js +111 -0
- package/dist/wallets/WalletContractV3R2.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV3R2.spec.js +44 -0
- package/dist/wallets/WalletContractV4.d.ts +62 -0
- package/dist/wallets/WalletContractV4.js +112 -0
- package/dist/wallets/WalletContractV4.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV4.spec.js +48 -0
- package/dist/wallets/signing/createWalletTransfer.d.ts +39 -0
- package/dist/wallets/signing/createWalletTransfer.js +122 -0
- package/package.json +68 -0
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.randomTestKey = void 0;
|
|
14
|
+
const prando_1 = __importDefault(require("prando"));
|
|
15
|
+
const crypto_1 = require("@ton/crypto");
|
|
16
|
+
function randomTestKey(seed) {
|
|
17
|
+
let random = new prando_1.default(seed);
|
|
18
|
+
let res = Buffer.alloc(32);
|
|
19
|
+
for (let i = 0; i < res.length; i++) {
|
|
20
|
+
res[i] = random.nextInt(0, 256);
|
|
21
|
+
}
|
|
22
|
+
return (0, crypto_1.keyPairFromSeed)(res);
|
|
23
|
+
}
|
|
24
|
+
exports.randomTestKey = randomTestKey;
|
|
@@ -0,0 +1,15 @@
|
|
|
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 declare function exponentialBackoffDelay(currentFailureCount: number, minDelay: number, maxDelay: number, maxFailureCount: number): number;
|
|
9
|
+
export declare function delay(ms: number): Promise<unknown>;
|
|
10
|
+
export declare function delayBreakable(ms: number): {
|
|
11
|
+
promise: Promise<unknown>;
|
|
12
|
+
resolver: () => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function forever(): Promise<unknown>;
|
|
15
|
+
export declare function backoff<T>(callback: () => Promise<T>, log: boolean): Promise<T>;
|
|
@@ -0,0 +1,63 @@
|
|
|
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.backoff = exports.forever = exports.delayBreakable = exports.delay = exports.exponentialBackoffDelay = void 0;
|
|
11
|
+
function exponentialBackoffDelay(currentFailureCount, minDelay, maxDelay, maxFailureCount) {
|
|
12
|
+
let maxDelayRet = minDelay + ((maxDelay - minDelay) / maxFailureCount) * Math.max(currentFailureCount, maxFailureCount);
|
|
13
|
+
return Math.round(Math.random() * maxDelayRet);
|
|
14
|
+
}
|
|
15
|
+
exports.exponentialBackoffDelay = exponentialBackoffDelay;
|
|
16
|
+
async function delay(ms) {
|
|
17
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
18
|
+
}
|
|
19
|
+
exports.delay = delay;
|
|
20
|
+
function delayBreakable(ms) {
|
|
21
|
+
// We can cancel delay from outer code
|
|
22
|
+
let promiseResolver = null;
|
|
23
|
+
let resolver = () => {
|
|
24
|
+
if (promiseResolver) {
|
|
25
|
+
promiseResolver();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
let promise = new Promise(resolve => {
|
|
29
|
+
promiseResolver = resolve;
|
|
30
|
+
setTimeout(resolve, ms);
|
|
31
|
+
});
|
|
32
|
+
return { promise, resolver };
|
|
33
|
+
}
|
|
34
|
+
exports.delayBreakable = delayBreakable;
|
|
35
|
+
const promise = new Promise(() => { });
|
|
36
|
+
function forever() {
|
|
37
|
+
return promise;
|
|
38
|
+
}
|
|
39
|
+
exports.forever = forever;
|
|
40
|
+
async function backoff(callback, log) {
|
|
41
|
+
let currentFailureCount = 0;
|
|
42
|
+
const minDelay = 500;
|
|
43
|
+
const maxDelay = 15000;
|
|
44
|
+
const maxFailureCount = 50;
|
|
45
|
+
while (true) {
|
|
46
|
+
try {
|
|
47
|
+
return await callback();
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (currentFailureCount > 3) {
|
|
51
|
+
if (log) {
|
|
52
|
+
console.warn(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (currentFailureCount < maxFailureCount) {
|
|
56
|
+
currentFailureCount++;
|
|
57
|
+
}
|
|
58
|
+
let waitForRequest = exponentialBackoffDelay(currentFailureCount, minDelay, maxDelay, maxFailureCount);
|
|
59
|
+
await delay(waitForRequest);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.backoff = backoff;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.toUrlSafe = void 0;
|
|
11
|
+
function toUrlSafe(src) {
|
|
12
|
+
while (src.indexOf('/') >= 0) {
|
|
13
|
+
src = src.replace('/', '_');
|
|
14
|
+
}
|
|
15
|
+
while (src.indexOf('+') >= 0) {
|
|
16
|
+
src = src.replace('+', '-');
|
|
17
|
+
}
|
|
18
|
+
while (src.indexOf('=') >= 0) {
|
|
19
|
+
src = src.replace('=', '');
|
|
20
|
+
}
|
|
21
|
+
return src;
|
|
22
|
+
}
|
|
23
|
+
exports.toUrlSafe = toUrlSafe;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 WalletContractV1R1 implements Contract {
|
|
12
|
+
static create(args: {
|
|
13
|
+
workchain: number;
|
|
14
|
+
publicKey: Buffer;
|
|
15
|
+
}): WalletContractV1R1;
|
|
16
|
+
readonly workchain: number;
|
|
17
|
+
readonly publicKey: Buffer;
|
|
18
|
+
readonly address: Address;
|
|
19
|
+
readonly init: {
|
|
20
|
+
data: Cell;
|
|
21
|
+
code: Cell;
|
|
22
|
+
};
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Get Wallet Balance
|
|
26
|
+
*/
|
|
27
|
+
getBalance(provider: ContractProvider): Promise<bigint>;
|
|
28
|
+
/**
|
|
29
|
+
* Get Wallet Seqno
|
|
30
|
+
*/
|
|
31
|
+
getSeqno(provider: ContractProvider): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Send signed transfer
|
|
34
|
+
*/
|
|
35
|
+
send(provider: ContractProvider, message: Cell): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Sign and send transfer
|
|
38
|
+
*/
|
|
39
|
+
sendTransfer(provider: ContractProvider, args: {
|
|
40
|
+
seqno: number;
|
|
41
|
+
secretKey: Buffer;
|
|
42
|
+
message?: Maybe<MessageRelaxed>;
|
|
43
|
+
sendMode?: Maybe<SendMode>;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Create signed transfer
|
|
47
|
+
*/
|
|
48
|
+
createTransfer(args: {
|
|
49
|
+
seqno: number;
|
|
50
|
+
secretKey: Buffer;
|
|
51
|
+
message?: Maybe<MessageRelaxed>;
|
|
52
|
+
sendMode?: Maybe<SendMode>;
|
|
53
|
+
}): Cell;
|
|
54
|
+
/**
|
|
55
|
+
* Create sender
|
|
56
|
+
*/
|
|
57
|
+
sender(provider: ContractProvider, secretKey: Buffer): Sender;
|
|
58
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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.WalletContractV1R1 = void 0;
|
|
11
|
+
const core_1 = require("@ton/core");
|
|
12
|
+
const createWalletTransfer_1 = require("./signing/createWalletTransfer");
|
|
13
|
+
class WalletContractV1R1 {
|
|
14
|
+
constructor(workchain, publicKey) {
|
|
15
|
+
this.workchain = workchain;
|
|
16
|
+
this.publicKey = publicKey;
|
|
17
|
+
// Build initial code and data
|
|
18
|
+
let code = core_1.Cell.fromBoc(Buffer.from('te6cckEBAQEARAAAhP8AIN2k8mCBAgDXGCDXCx/tRNDTH9P/0VESuvKhIvkBVBBE+RDyovgAAdMfMSDXSpbTB9QC+wDe0aTIyx/L/8ntVEH98Ik=', 'base64'))[0];
|
|
19
|
+
let data = (0, core_1.beginCell)()
|
|
20
|
+
.storeUint(0, 32) // Seqno
|
|
21
|
+
.storeBuffer(publicKey)
|
|
22
|
+
.endCell();
|
|
23
|
+
this.init = { code, data };
|
|
24
|
+
this.address = (0, core_1.contractAddress)(workchain, { code, data });
|
|
25
|
+
}
|
|
26
|
+
static create(args) {
|
|
27
|
+
return new WalletContractV1R1(args.workchain, args.publicKey);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get Wallet Balance
|
|
31
|
+
*/
|
|
32
|
+
async getBalance(provider) {
|
|
33
|
+
let state = await provider.getState();
|
|
34
|
+
return state.balance;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get Wallet Seqno
|
|
38
|
+
*/
|
|
39
|
+
async getSeqno(provider) {
|
|
40
|
+
let state = await provider.getState();
|
|
41
|
+
if (state.state.type === 'active') {
|
|
42
|
+
return core_1.Cell.fromBoc(state.state.data)[0].beginParse().loadUint(32);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Send signed transfer
|
|
50
|
+
*/
|
|
51
|
+
async send(provider, message) {
|
|
52
|
+
await provider.external(message);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Sign and send transfer
|
|
56
|
+
*/
|
|
57
|
+
async sendTransfer(provider, args) {
|
|
58
|
+
let transfer = this.createTransfer(args);
|
|
59
|
+
await this.send(provider, transfer);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create signed transfer
|
|
63
|
+
*/
|
|
64
|
+
createTransfer(args) {
|
|
65
|
+
let sendMode = core_1.SendMode.PAY_GAS_SEPARATELY;
|
|
66
|
+
if (args.sendMode !== null && args.sendMode !== undefined) {
|
|
67
|
+
sendMode = args.sendMode;
|
|
68
|
+
}
|
|
69
|
+
return (0, createWalletTransfer_1.createWalletTransferV1)({
|
|
70
|
+
seqno: args.seqno,
|
|
71
|
+
sendMode,
|
|
72
|
+
secretKey: args.secretKey,
|
|
73
|
+
message: args.message
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create sender
|
|
78
|
+
*/
|
|
79
|
+
sender(provider, secretKey) {
|
|
80
|
+
return {
|
|
81
|
+
send: async (args) => {
|
|
82
|
+
let seqno = await this.getSeqno(provider);
|
|
83
|
+
let transfer = this.createTransfer({
|
|
84
|
+
seqno,
|
|
85
|
+
secretKey,
|
|
86
|
+
sendMode: args.sendMode,
|
|
87
|
+
message: (0, core_1.internal)({
|
|
88
|
+
to: args.to,
|
|
89
|
+
value: args.value,
|
|
90
|
+
init: args.init,
|
|
91
|
+
body: args.body,
|
|
92
|
+
bounce: args.bounce
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
await this.send(provider, transfer);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.WalletContractV1R1 = WalletContractV1R1;
|
|
@@ -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 WalletContractV1R1_1 = require("./WalletContractV1R1");
|
|
14
|
+
describe('WalletContractV1R1', () => {
|
|
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(WalletContractV1R1_1.WalletContractV1R1.create({ workchain: 0, publicKey: key.publicKey }));
|
|
20
|
+
let balance = await contract.getBalance();
|
|
21
|
+
// Check parameters
|
|
22
|
+
expect(contract.address.equals(core_1.Address.parse('EQCtW_zzk6n82ebaVQFq8P_04wOemYhtwqMd3NuArmPODRvD'))).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(WalletContractV1R1_1.WalletContractV1R1.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
|
+
message: (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,58 @@
|
|
|
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 WalletContractV1R2 implements Contract {
|
|
12
|
+
static create(args: {
|
|
13
|
+
workchain: number;
|
|
14
|
+
publicKey: Buffer;
|
|
15
|
+
}): WalletContractV1R2;
|
|
16
|
+
readonly workchain: number;
|
|
17
|
+
readonly publicKey: Buffer;
|
|
18
|
+
readonly address: Address;
|
|
19
|
+
readonly init: {
|
|
20
|
+
data: Cell;
|
|
21
|
+
code: Cell;
|
|
22
|
+
};
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Get Wallet Balance
|
|
26
|
+
*/
|
|
27
|
+
getBalance(provider: ContractProvider): Promise<bigint>;
|
|
28
|
+
/**
|
|
29
|
+
* Get Wallet Seqno
|
|
30
|
+
*/
|
|
31
|
+
getSeqno(provider: ContractProvider): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Send signed transfer
|
|
34
|
+
*/
|
|
35
|
+
send(provider: ContractProvider, message: Cell): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Sign and send transfer
|
|
38
|
+
*/
|
|
39
|
+
sendTransfer(provider: ContractProvider, args: {
|
|
40
|
+
seqno: number;
|
|
41
|
+
secretKey: Buffer;
|
|
42
|
+
message?: Maybe<MessageRelaxed>;
|
|
43
|
+
sendMode?: Maybe<SendMode>;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Create signed transfer
|
|
47
|
+
*/
|
|
48
|
+
createTransfer(args: {
|
|
49
|
+
seqno: number;
|
|
50
|
+
secretKey: Buffer;
|
|
51
|
+
message?: Maybe<MessageRelaxed>;
|
|
52
|
+
sendMode?: Maybe<SendMode>;
|
|
53
|
+
}): Cell;
|
|
54
|
+
/**
|
|
55
|
+
* Create sender
|
|
56
|
+
*/
|
|
57
|
+
sender(provider: ContractProvider, secretKey: Buffer): Sender;
|
|
58
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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.WalletContractV1R2 = void 0;
|
|
11
|
+
const core_1 = require("@ton/core");
|
|
12
|
+
const createWalletTransfer_1 = require("./signing/createWalletTransfer");
|
|
13
|
+
class WalletContractV1R2 {
|
|
14
|
+
constructor(workchain, publicKey) {
|
|
15
|
+
this.workchain = workchain;
|
|
16
|
+
this.publicKey = publicKey;
|
|
17
|
+
// Build initial code and data
|
|
18
|
+
let code = core_1.Cell.fromBoc(Buffer.from('te6cckEBAQEAUwAAov8AIN0gggFMl7qXMO1E0NcLH+Ck8mCBAgDXGCDXCx/tRNDTH9P/0VESuvKhIvkBVBBE+RDyovgAAdMfMSDXSpbTB9QC+wDe0aTIyx/L/8ntVNDieG8=', 'base64'))[0];
|
|
19
|
+
let data = (0, core_1.beginCell)()
|
|
20
|
+
.storeUint(0, 32) // Seqno
|
|
21
|
+
.storeBuffer(publicKey)
|
|
22
|
+
.endCell();
|
|
23
|
+
this.init = { code, data };
|
|
24
|
+
this.address = (0, core_1.contractAddress)(workchain, { code, data });
|
|
25
|
+
}
|
|
26
|
+
static create(args) {
|
|
27
|
+
return new WalletContractV1R2(args.workchain, args.publicKey);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get Wallet Balance
|
|
31
|
+
*/
|
|
32
|
+
async getBalance(provider) {
|
|
33
|
+
let state = await provider.getState();
|
|
34
|
+
return state.balance;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get Wallet Seqno
|
|
38
|
+
*/
|
|
39
|
+
async getSeqno(provider) {
|
|
40
|
+
let state = await provider.getState();
|
|
41
|
+
if (state.state.type === 'active') {
|
|
42
|
+
let res = await provider.get('seqno', []);
|
|
43
|
+
return res.stack.readNumber();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Send signed transfer
|
|
51
|
+
*/
|
|
52
|
+
async send(provider, message) {
|
|
53
|
+
await provider.external(message);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sign and send transfer
|
|
57
|
+
*/
|
|
58
|
+
async sendTransfer(provider, args) {
|
|
59
|
+
let transfer = this.createTransfer(args);
|
|
60
|
+
await this.send(provider, transfer);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create signed transfer
|
|
64
|
+
*/
|
|
65
|
+
createTransfer(args) {
|
|
66
|
+
let sendMode = core_1.SendMode.PAY_GAS_SEPARATELY;
|
|
67
|
+
if (args.sendMode !== null && args.sendMode !== undefined) {
|
|
68
|
+
sendMode = args.sendMode;
|
|
69
|
+
}
|
|
70
|
+
return (0, createWalletTransfer_1.createWalletTransferV1)({
|
|
71
|
+
seqno: args.seqno,
|
|
72
|
+
sendMode,
|
|
73
|
+
secretKey: args.secretKey,
|
|
74
|
+
message: args.message
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create sender
|
|
79
|
+
*/
|
|
80
|
+
sender(provider, secretKey) {
|
|
81
|
+
return {
|
|
82
|
+
send: async (args) => {
|
|
83
|
+
let seqno = await this.getSeqno(provider);
|
|
84
|
+
let transfer = this.createTransfer({
|
|
85
|
+
seqno,
|
|
86
|
+
secretKey,
|
|
87
|
+
sendMode: args.sendMode,
|
|
88
|
+
message: (0, core_1.internal)({
|
|
89
|
+
to: args.to,
|
|
90
|
+
value: args.value,
|
|
91
|
+
init: args.init,
|
|
92
|
+
body: args.body,
|
|
93
|
+
bounce: args.bounce
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
await this.send(provider, transfer);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.WalletContractV1R2 = WalletContractV1R2;
|
|
@@ -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 WalletContractV1R2_1 = require("./WalletContractV1R2");
|
|
14
|
+
describe('WalletContractV1R2', () => {
|
|
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(WalletContractV1R2_1.WalletContractV1R2.create({ workchain: 0, publicKey: key.publicKey }));
|
|
20
|
+
let balance = await contract.getBalance();
|
|
21
|
+
// Check parameters
|
|
22
|
+
expect(contract.address.equals(core_1.Address.parse('EQATDkvcCA2fFWbSTHMpGCrjkNGqgEywES15ZS11HHY3UuxK'))).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(WalletContractV1R2_1.WalletContractV1R2.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
|
+
message: (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,58 @@
|
|
|
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 WalletContractV1R3 implements Contract {
|
|
12
|
+
static create(args: {
|
|
13
|
+
workchain: number;
|
|
14
|
+
publicKey: Buffer;
|
|
15
|
+
}): WalletContractV1R3;
|
|
16
|
+
readonly workchain: number;
|
|
17
|
+
readonly publicKey: Buffer;
|
|
18
|
+
readonly address: Address;
|
|
19
|
+
readonly init: {
|
|
20
|
+
data: Cell;
|
|
21
|
+
code: Cell;
|
|
22
|
+
};
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Get Wallet Balance
|
|
26
|
+
*/
|
|
27
|
+
getBalance(provider: ContractProvider): Promise<bigint>;
|
|
28
|
+
/**
|
|
29
|
+
* Get Wallet Seqno
|
|
30
|
+
*/
|
|
31
|
+
getSeqno(provider: ContractProvider): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Send signed transfer
|
|
34
|
+
*/
|
|
35
|
+
send(executor: ContractProvider, message: Cell): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Sign and send transfer
|
|
38
|
+
*/
|
|
39
|
+
sendTransfer(provider: ContractProvider, args: {
|
|
40
|
+
seqno: number;
|
|
41
|
+
secretKey: Buffer;
|
|
42
|
+
message?: Maybe<MessageRelaxed>;
|
|
43
|
+
sendMode?: Maybe<SendMode>;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Create signed transfer
|
|
47
|
+
*/
|
|
48
|
+
createTransfer(args: {
|
|
49
|
+
seqno: number;
|
|
50
|
+
secretKey: Buffer;
|
|
51
|
+
message?: Maybe<MessageRelaxed>;
|
|
52
|
+
sendMode?: Maybe<SendMode>;
|
|
53
|
+
}): Cell;
|
|
54
|
+
/**
|
|
55
|
+
* Create sender
|
|
56
|
+
*/
|
|
57
|
+
sender(provider: ContractProvider, secretKey: Buffer): Sender;
|
|
58
|
+
}
|