@tonappchain/sdk 0.5.6 → 0.6.1-v3.0.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 (49) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +189 -1276
  3. package/package.json +67 -67
  4. package/dist/adapters/contractOpener.d.ts +0 -19
  5. package/dist/adapters/contractOpener.js +0 -94
  6. package/dist/errors/errors.d.ts +0 -34
  7. package/dist/errors/errors.js +0 -80
  8. package/dist/errors/index.d.ts +0 -2
  9. package/dist/errors/index.js +0 -30
  10. package/dist/errors/instances.d.ts +0 -16
  11. package/dist/errors/instances.js +0 -28
  12. package/dist/index.d.ts +0 -10
  13. package/dist/index.js +0 -35
  14. package/dist/sdk/Consts.d.ts +0 -6
  15. package/dist/sdk/Consts.js +0 -10
  16. package/dist/sdk/OperationTracker.d.ts +0 -14
  17. package/dist/sdk/OperationTracker.js +0 -151
  18. package/dist/sdk/StartTracking.d.ts +0 -8
  19. package/dist/sdk/StartTracking.js +0 -126
  20. package/dist/sdk/TacSdk.d.ts +0 -36
  21. package/dist/sdk/TacSdk.js +0 -364
  22. package/dist/sdk/Utils.d.ts +0 -18
  23. package/dist/sdk/Utils.js +0 -126
  24. package/dist/sender/RawSender.d.ts +0 -13
  25. package/dist/sender/RawSender.js +0 -37
  26. package/dist/sender/SenderAbstraction.d.ts +0 -19
  27. package/dist/sender/SenderAbstraction.js +0 -5
  28. package/dist/sender/SenderFactory.d.ts +0 -33
  29. package/dist/sender/SenderFactory.js +0 -55
  30. package/dist/sender/TonConnectSender.d.ts +0 -11
  31. package/dist/sender/TonConnectSender.js +0 -33
  32. package/dist/sender/index.d.ts +0 -2
  33. package/dist/sender/index.js +0 -18
  34. package/dist/structs/InternalStruct.d.ts +0 -54
  35. package/dist/structs/InternalStruct.js +0 -8
  36. package/dist/structs/Struct.d.ts +0 -227
  37. package/dist/structs/Struct.js +0 -38
  38. package/dist/wrappers/ContentUtils.d.ts +0 -25
  39. package/dist/wrappers/ContentUtils.js +0 -160
  40. package/dist/wrappers/HighloadQueryId.d.ts +0 -17
  41. package/dist/wrappers/HighloadQueryId.js +0 -72
  42. package/dist/wrappers/HighloadWalletV3.d.ts +0 -61
  43. package/dist/wrappers/HighloadWalletV3.js +0 -161
  44. package/dist/wrappers/JettonMaster.d.ts +0 -24
  45. package/dist/wrappers/JettonMaster.js +0 -53
  46. package/dist/wrappers/JettonWallet.d.ts +0 -46
  47. package/dist/wrappers/JettonWallet.js +0 -103
  48. package/dist/wrappers/Settings.d.ts +0 -10
  49. package/dist/wrappers/Settings.js +0 -38
@@ -1,72 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HighloadQueryId = void 0;
4
- const BIT_NUMBER_SIZE = 10n; // 10 bit
5
- const SHIFT_SIZE = 13n; // 13 bit
6
- const MAX_BIT_NUMBER = 1022n;
7
- const MAX_SHIFT = 8191n; // 2^13 = 8192
8
- class HighloadQueryId {
9
- constructor() {
10
- this.shift = 0n;
11
- this.bitnumber = 0n;
12
- }
13
- static fromShiftAndBitNumber(shift, bitnumber) {
14
- const q = new HighloadQueryId();
15
- q.shift = shift;
16
- if (q.shift < 0)
17
- throw new Error('invalid shift');
18
- if (q.shift > MAX_SHIFT)
19
- throw new Error('invalid shift');
20
- q.bitnumber = bitnumber;
21
- if (q.bitnumber < 0)
22
- throw new Error('invalid bitnumber');
23
- if (q.bitnumber > MAX_BIT_NUMBER)
24
- throw new Error('invalid bitnumber');
25
- return q;
26
- }
27
- getNext() {
28
- let newBitnumber = this.bitnumber + 1n;
29
- let newShift = this.shift;
30
- if (newShift === MAX_SHIFT && newBitnumber > MAX_BIT_NUMBER - 1n) {
31
- throw new Error('Overload'); // NOTE: we left one queryId for emergency withdraw
32
- }
33
- if (newBitnumber > MAX_BIT_NUMBER) {
34
- newBitnumber = 0n;
35
- newShift += 1n;
36
- if (newShift > MAX_SHIFT) {
37
- throw new Error('Overload');
38
- }
39
- }
40
- return HighloadQueryId.fromShiftAndBitNumber(newShift, newBitnumber);
41
- }
42
- hasNext() {
43
- const isEnd = this.bitnumber >= MAX_BIT_NUMBER - 1n && this.shift === MAX_SHIFT; // NOTE: we left one queryId for emergency withdraw;
44
- return !isEnd;
45
- }
46
- getShift() {
47
- return this.shift;
48
- }
49
- getBitNumber() {
50
- return this.bitnumber;
51
- }
52
- getQueryId() {
53
- return (this.shift << BIT_NUMBER_SIZE) + this.bitnumber;
54
- }
55
- static fromQueryId(queryId) {
56
- const shift = queryId >> BIT_NUMBER_SIZE;
57
- const bitnumber = queryId & 1023n;
58
- return this.fromShiftAndBitNumber(shift, bitnumber);
59
- }
60
- static fromSeqno(i) {
61
- const shift = i / 1023n;
62
- const bitnumber = i % 1023n;
63
- return this.fromShiftAndBitNumber(shift, bitnumber);
64
- }
65
- /**
66
- * @return {bigint} [0 .. 8380415]
67
- */
68
- toSeqno() {
69
- return this.bitnumber + this.shift * 1023n;
70
- }
71
- }
72
- exports.HighloadQueryId = HighloadQueryId;
@@ -1,61 +0,0 @@
1
- import { Address, Cell, ContractProvider, MessageRelaxed, OutAction, OutActionSendMsg, SendMode } from '@ton/ton';
2
- import { HighloadQueryId } from './HighloadQueryId';
3
- import { WalletInstance } from '../sender';
4
- export declare enum OP {
5
- InternalTransfer = 2923619748
6
- }
7
- export type HighloadWalletV3Config = {
8
- publicKey: Buffer;
9
- subwalletId?: number;
10
- timeout?: number;
11
- };
12
- export declare const DEFAULT_SUBWALLET_ID = 4269;
13
- export declare const DEFAULT_TIMEOUT: number;
14
- export declare const TIMESTAMP_SIZE = 64;
15
- export declare const TIMEOUT_SIZE = 22;
16
- export declare function highloadWalletV3ConfigToCell(config: HighloadWalletV3Config): Cell;
17
- export declare class HighloadWalletV3 implements WalletInstance {
18
- readonly address: Address;
19
- readonly init?: {
20
- code: Cell;
21
- data: Cell;
22
- } | undefined;
23
- constructor(address: Address, init?: {
24
- code: Cell;
25
- data: Cell;
26
- } | undefined);
27
- getSeqno(_: ContractProvider): Promise<number>;
28
- sendTransfer(provider: ContractProvider, args: {
29
- seqno?: number;
30
- secretKey: Buffer;
31
- messages: MessageRelaxed[];
32
- sendMode: SendMode;
33
- timeout?: number;
34
- subwalletId?: number;
35
- }): Promise<void>;
36
- static create(config: HighloadWalletV3Config, code?: Cell, workchain?: number): HighloadWalletV3;
37
- sendExternalMessage(provider: ContractProvider, secretKey: Buffer, opts: {
38
- message: MessageRelaxed | Cell;
39
- mode: number;
40
- queryId: bigint | HighloadQueryId;
41
- createdAt: number;
42
- subwalletId: number;
43
- timeout: number;
44
- }): Promise<void>;
45
- sendBatch(provider: ContractProvider, secretKey: Buffer, messages: OutActionSendMsg[], subwallet: number, queryId: HighloadQueryId, timeout: number, createdAt?: number, value?: bigint): Promise<void>;
46
- static createInternalTransferBody(opts: {
47
- actions: OutAction[] | Cell;
48
- queryId: HighloadQueryId;
49
- }): Cell;
50
- createInternalTransfer(opts: {
51
- actions: OutAction[] | Cell;
52
- queryId: HighloadQueryId;
53
- value: bigint;
54
- }): MessageRelaxed;
55
- packActions(messages: OutAction[], value: bigint | undefined, queryId: HighloadQueryId): MessageRelaxed;
56
- getPublicKey(provider: ContractProvider): Promise<Buffer>;
57
- getSubwalletId(provider: ContractProvider): Promise<number>;
58
- getTimeout(provider: ContractProvider): Promise<number>;
59
- getLastCleaned(provider: ContractProvider): Promise<number>;
60
- getProcessed(provider: ContractProvider, queryId: HighloadQueryId, needClean?: boolean): Promise<boolean>;
61
- }
@@ -1,161 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HighloadWalletV3 = exports.TIMEOUT_SIZE = exports.TIMESTAMP_SIZE = exports.DEFAULT_TIMEOUT = exports.DEFAULT_SUBWALLET_ID = exports.OP = void 0;
4
- exports.highloadWalletV3ConfigToCell = highloadWalletV3ConfigToCell;
5
- const ton_1 = require("@ton/ton");
6
- const ton_crypto_1 = require("ton-crypto");
7
- const HighloadQueryId_1 = require("./HighloadQueryId");
8
- var OP;
9
- (function (OP) {
10
- OP[OP["InternalTransfer"] = 2923619748] = "InternalTransfer";
11
- })(OP || (exports.OP = OP = {}));
12
- exports.DEFAULT_SUBWALLET_ID = 0x10ad;
13
- exports.DEFAULT_TIMEOUT = 60 * 60; // 1 hour
14
- const HIGHLOAD_V3_CODE = ton_1.Cell.fromBoc(Buffer.from('b5ee9c7241021001000228000114ff00f4a413f4bcf2c80b01020120020d02014803040078d020d74bc00101c060b0915be101d0d3030171b0915be0fa4030f828c705b39130e0d31f018210ae42e5a4ba9d8040d721d74cf82a01ed55fb04e030020120050a02027306070011adce76a2686b85ffc00201200809001aabb6ed44d0810122d721d70b3f0018aa3bed44d08307d721d70b1f0201200b0c001bb9a6eed44d0810162d721d70b15800e5b8bf2eda2edfb21ab09028409b0ed44d0810120d721f404f404d33fd315d1058e1bf82325a15210b99f326df82305aa0015a112b992306dde923033e2923033e25230800df40f6fa19ed021d721d70a00955f037fdb31e09130e259800df40f6fa19cd001d721d70a00937fdb31e0915be270801f6f2d48308d718d121f900ed44d0d3ffd31ff404f404d33fd315d1f82321a15220b98e12336df82324aa00a112b9926d32de58f82301de541675f910f2a106d0d31fd4d307d30cd309d33fd315d15168baf2a2515abaf2a6f8232aa15250bcf2a304f823bbf2a35304800df40f6fa199d024d721d70a00f2649130e20e01fe5309800df40f6fa18e13d05004d718d20001f264c858cf16cf8301cf168e1030c824cf40cf8384095005a1a514cf40e2f800c94039800df41704c8cbff13cb1ff40012f40012cb3f12cb15c9ed54f80f21d0d30001f265d3020171b0925f03e0fa4001d70b01c000f2a5fa4031fa0031f401fa0031fa00318060d721d300010f0020f265d2000193d431d19130e272b1fb00b585bf03', 'hex'))[0];
15
- exports.TIMESTAMP_SIZE = 64;
16
- exports.TIMEOUT_SIZE = 22;
17
- function highloadWalletV3ConfigToCell(config) {
18
- return (0, ton_1.beginCell)()
19
- .storeBuffer(config.publicKey)
20
- .storeUint(config.subwalletId ?? exports.DEFAULT_SUBWALLET_ID, 32)
21
- .storeUint(0, 1 + 1 + exports.TIMESTAMP_SIZE)
22
- .storeUint(config.timeout ?? exports.DEFAULT_TIMEOUT, exports.TIMEOUT_SIZE)
23
- .endCell();
24
- }
25
- class HighloadWalletV3 {
26
- constructor(address, init) {
27
- this.address = address;
28
- this.init = init;
29
- }
30
- async getSeqno(_) {
31
- return 0; // will not be used
32
- }
33
- async sendTransfer(provider, args) {
34
- if (!args.messages.length) {
35
- return;
36
- }
37
- const state = await provider.getState();
38
- const isActive = state.state.type === 'active';
39
- const subwalletId = isActive ? await this.getSubwalletId(provider) : exports.DEFAULT_SUBWALLET_ID;
40
- const timeout = isActive ? await this.getTimeout(provider) : exports.DEFAULT_TIMEOUT;
41
- const queryId = new HighloadQueryId_1.HighloadQueryId();
42
- const actions = args.messages.map((msg) => ({
43
- type: 'sendMsg',
44
- mode: args.sendMode,
45
- outMsg: msg,
46
- }));
47
- await this.sendBatch(provider, args.secretKey, actions, subwalletId, queryId, timeout);
48
- }
49
- static create(config, code = HIGHLOAD_V3_CODE, workchain = 0) {
50
- const data = highloadWalletV3ConfigToCell(config);
51
- const init = { code, data };
52
- return new HighloadWalletV3((0, ton_1.contractAddress)(workchain, init), init);
53
- }
54
- async sendExternalMessage(provider, secretKey, opts) {
55
- let messageCell;
56
- if (opts.message instanceof ton_1.Cell) {
57
- messageCell = opts.message;
58
- }
59
- else {
60
- const messageBuilder = (0, ton_1.beginCell)();
61
- messageBuilder.store((0, ton_1.storeMessageRelaxed)(opts.message));
62
- messageCell = messageBuilder.endCell();
63
- }
64
- const queryId = opts.queryId instanceof HighloadQueryId_1.HighloadQueryId ? opts.queryId.getQueryId() : opts.queryId;
65
- const messageInner = (0, ton_1.beginCell)()
66
- .storeUint(opts.subwalletId, 32)
67
- .storeRef(messageCell)
68
- .storeUint(opts.mode, 8)
69
- .storeUint(queryId, 23)
70
- .storeUint(opts.createdAt, exports.TIMESTAMP_SIZE)
71
- .storeUint(opts.timeout, exports.TIMEOUT_SIZE)
72
- .endCell();
73
- await provider.external((0, ton_1.beginCell)().storeBuffer((0, ton_crypto_1.sign)(messageInner.hash(), secretKey)).storeRef(messageInner).endCell());
74
- }
75
- async sendBatch(provider, secretKey, messages, subwallet, queryId, timeout, createdAt, value = 0n) {
76
- if (createdAt == undefined) {
77
- createdAt = Math.floor(Date.now() / 1000) - 20; // -20 is used to pass check created_at <= now() in smart contract for sure
78
- }
79
- return await this.sendExternalMessage(provider, secretKey, {
80
- message: this.packActions(messages, value, queryId),
81
- mode: value > 0n ? ton_1.SendMode.PAY_GAS_SEPARATELY : ton_1.SendMode.CARRY_ALL_REMAINING_BALANCE,
82
- queryId: queryId,
83
- createdAt: createdAt,
84
- subwalletId: subwallet,
85
- timeout: timeout,
86
- });
87
- }
88
- static createInternalTransferBody(opts) {
89
- let actionsCell;
90
- if (opts.actions instanceof ton_1.Cell) {
91
- actionsCell = opts.actions;
92
- }
93
- else {
94
- if (opts.actions.length > 254) {
95
- throw TypeError('Max allowed action count is 254. Use packActions instead.');
96
- }
97
- const actionsBuilder = (0, ton_1.beginCell)();
98
- (0, ton_1.storeOutList)(opts.actions)(actionsBuilder);
99
- actionsCell = actionsBuilder.endCell();
100
- }
101
- return (0, ton_1.beginCell)()
102
- .storeUint(OP.InternalTransfer, 32)
103
- .storeUint(opts.queryId.getQueryId(), 64)
104
- .storeRef(actionsCell)
105
- .endCell();
106
- }
107
- createInternalTransfer(opts) {
108
- return (0, ton_1.internal)({
109
- to: this.address,
110
- value: opts.value,
111
- body: HighloadWalletV3.createInternalTransferBody(opts),
112
- });
113
- }
114
- packActions(messages, value = (0, ton_1.toNano)('1'), queryId) {
115
- let batch;
116
- if (messages.length > 254) {
117
- batch = messages.slice(0, 253);
118
- batch.push({
119
- type: 'sendMsg',
120
- mode: value > 0n ? ton_1.SendMode.PAY_GAS_SEPARATELY : ton_1.SendMode.CARRY_ALL_REMAINING_BALANCE,
121
- outMsg: this.packActions(messages.slice(253), value, queryId),
122
- });
123
- }
124
- else {
125
- batch = messages;
126
- }
127
- return this.createInternalTransfer({
128
- actions: batch,
129
- queryId: queryId,
130
- value,
131
- });
132
- }
133
- async getPublicKey(provider) {
134
- const res = (await provider.get('get_public_key', [])).stack;
135
- const pubKeyU = res.readBigNumber();
136
- return Buffer.from(pubKeyU.toString(16).padStart(32 * 2, '0'), 'hex');
137
- }
138
- async getSubwalletId(provider) {
139
- const res = (await provider.get('get_subwallet_id', [])).stack;
140
- return res.readNumber();
141
- }
142
- async getTimeout(provider) {
143
- const res = (await provider.get('get_timeout', [])).stack;
144
- return res.readNumber();
145
- }
146
- async getLastCleaned(provider) {
147
- const res = (await provider.get('get_last_clean_time', [])).stack;
148
- return res.readNumber();
149
- }
150
- async getProcessed(provider, queryId, needClean = true) {
151
- const res = (await provider.get('processed?', [
152
- { type: 'int', value: queryId.getQueryId() },
153
- {
154
- type: 'int',
155
- value: needClean ? -1n : 0n,
156
- },
157
- ])).stack;
158
- return res.readBoolean();
159
- }
160
- }
161
- exports.HighloadWalletV3 = HighloadWalletV3;
@@ -1,24 +0,0 @@
1
- import { Address, Cell, Contract, ContractProvider } from '@ton/ton';
2
- import type { JettonExtendedMetadata } from './ContentUtils';
3
- export type JettonMasterInitData = {
4
- evmTokenAddress: string;
5
- crossChainLayerAddress: Address;
6
- code: Cell;
7
- walletCode: Cell;
8
- };
9
- export type JettonMasterData = {
10
- totalSupply: number;
11
- mintable: boolean;
12
- adminAddress: string;
13
- content: JettonExtendedMetadata;
14
- jettonWalletCode: Cell;
15
- };
16
- export declare class JettonMaster implements Contract {
17
- static createFromAddress(address: Address): JettonMaster;
18
- static createFromConfig(config: JettonMasterInitData, workchain?: number): JettonMaster;
19
- readonly address: Address;
20
- constructor(address: Address);
21
- getWalletAddress(provider: ContractProvider, owner: string): Promise<string>;
22
- getJettonData(provider: ContractProvider): Promise<JettonMasterData>;
23
- getL2Address(provider: ContractProvider): Promise<string>;
24
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JettonMaster = void 0;
4
- const ton_1 = require("@ton/ton");
5
- const ContentUtils_1 = require("./ContentUtils");
6
- class JettonMaster {
7
- static createFromAddress(address) {
8
- return new JettonMaster(address);
9
- }
10
- static createFromConfig(config, workchain = 0) {
11
- const data = (0, ton_1.beginCell)()
12
- .storeCoins(0)
13
- .storeAddress(config.crossChainLayerAddress)
14
- .storeAddress(null)
15
- .storeRef((0, ton_1.beginCell)().endCell())
16
- .storeRef(config.walletCode)
17
- .storeStringTail(config.evmTokenAddress)
18
- .endCell();
19
- return JettonMaster.createFromAddress((0, ton_1.contractAddress)(workchain, { data, code: config.code }));
20
- }
21
- constructor(address) {
22
- this.address = address;
23
- }
24
- async getWalletAddress(provider, owner) {
25
- const res = await provider.get('get_wallet_address', [
26
- {
27
- type: 'slice',
28
- cell: (0, ton_1.beginCell)().storeAddress(ton_1.Address.parse(owner)).endCell(),
29
- },
30
- ]);
31
- return res.stack.readAddress().toString();
32
- }
33
- async getJettonData(provider) {
34
- const result = await provider.get('get_jetton_data', []);
35
- const totalSupply = Number((0, ton_1.fromNano)(result.stack.readBigNumber()));
36
- const mintable = result.stack.readBoolean();
37
- const adminAddress = result.stack.readAddress().toString();
38
- const content = await (0, ContentUtils_1.readJettonMetadata)(result.stack.readCell());
39
- const jettonWalletCode = result.stack.readCell();
40
- return {
41
- totalSupply,
42
- mintable,
43
- adminAddress,
44
- content,
45
- jettonWalletCode,
46
- };
47
- }
48
- async getL2Address(provider) {
49
- const result = await provider.get('get_l2_token_address', []);
50
- return result.stack.readString();
51
- }
52
- }
53
- exports.JettonMaster = JettonMaster;
@@ -1,46 +0,0 @@
1
- import type { Contract, ContractProvider, Sender } from '@ton/ton';
2
- import { Address, Cell } from '@ton/ton';
3
- export type JettonWalletData = {
4
- balance: bigint;
5
- ownerAddress: string;
6
- jettonMasterAddress: string;
7
- jettonWalletCode: Cell;
8
- };
9
- export declare enum JettonWalletOpCodes {
10
- burn = 1499400124,
11
- transfer = 260734629
12
- }
13
- export declare function jettonWalletConfigToCell(config: JettonWalletData): Cell;
14
- export declare class JettonWallet implements Contract {
15
- readonly address: Address;
16
- readonly init?: {
17
- code: Cell;
18
- data: Cell;
19
- } | undefined;
20
- constructor(address: Address, init?: {
21
- code: Cell;
22
- data: Cell;
23
- } | undefined);
24
- static createFromAddress(address: Address): JettonWallet;
25
- static createFromConfig(config: JettonWalletData, code: Cell, workchain?: number): JettonWallet;
26
- static burnMessage(jettonAmount: bigint, receiverAddress?: string, crossChainTonAmount?: bigint, crossChainPayload?: Cell | null, queryId?: number): Cell;
27
- sendBurn(provider: ContractProvider, via: Sender, value: bigint, opts: {
28
- queryId?: number;
29
- jettonAmount: bigint;
30
- receiverAddress?: string;
31
- crossChainTonAmount?: bigint;
32
- crossChainPayload?: Cell | null;
33
- }): Promise<void>;
34
- static transferMessage(jettonAmount: bigint, to: string, responseAddress: string | null, forwardTonAmount?: bigint, crossChainTonAmount?: bigint, crossChainPayload?: Cell | null, queryId?: number): Cell;
35
- sendTransfer(provider: ContractProvider, via: Sender, value: bigint, opts: {
36
- queryId?: number;
37
- jettonAmount: bigint;
38
- toOwnerAddress: string;
39
- responseAddress?: string;
40
- customPayload?: Cell | null;
41
- forwardTonAmount?: bigint;
42
- forwardPayload?: Cell | null;
43
- }): Promise<void>;
44
- getWalletData(provider: ContractProvider): Promise<JettonWalletData>;
45
- getJettonBalance(provider: ContractProvider): Promise<bigint>;
46
- }
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JettonWallet = exports.JettonWalletOpCodes = void 0;
4
- exports.jettonWalletConfigToCell = jettonWalletConfigToCell;
5
- const ton_1 = require("@ton/ton");
6
- var JettonWalletOpCodes;
7
- (function (JettonWalletOpCodes) {
8
- JettonWalletOpCodes[JettonWalletOpCodes["burn"] = 1499400124] = "burn";
9
- JettonWalletOpCodes[JettonWalletOpCodes["transfer"] = 260734629] = "transfer";
10
- })(JettonWalletOpCodes || (exports.JettonWalletOpCodes = JettonWalletOpCodes = {}));
11
- function jettonWalletConfigToCell(config) {
12
- return (0, ton_1.beginCell)()
13
- .storeCoins(config.balance)
14
- .storeAddress(ton_1.Address.parse(config.ownerAddress))
15
- .storeAddress(ton_1.Address.parse(config.jettonMasterAddress))
16
- .endCell();
17
- }
18
- class JettonWallet {
19
- constructor(address, init) {
20
- this.address = address;
21
- this.init = init;
22
- }
23
- static createFromAddress(address) {
24
- return new JettonWallet(address);
25
- }
26
- static createFromConfig(config, code, workchain = 0) {
27
- const data = jettonWalletConfigToCell(config);
28
- const init = { code, data };
29
- return new JettonWallet((0, ton_1.contractAddress)(workchain, init), init);
30
- }
31
- static burnMessage(jettonAmount, receiverAddress, crossChainTonAmount, crossChainPayload, queryId) {
32
- const body = (0, ton_1.beginCell)()
33
- .storeUint(JettonWalletOpCodes.burn, 32)
34
- .storeUint(queryId || 0, 64)
35
- .storeCoins(jettonAmount)
36
- .storeAddress(receiverAddress ? ton_1.Address.parse(receiverAddress) : null);
37
- if (crossChainTonAmount || crossChainPayload) {
38
- body.storeMaybeRef((0, ton_1.beginCell)()
39
- .storeCoins(crossChainTonAmount ?? 0n)
40
- .storeMaybeRef(crossChainPayload)
41
- .endCell());
42
- }
43
- else {
44
- body.storeMaybeRef(null);
45
- }
46
- return body.endCell();
47
- }
48
- async sendBurn(provider, via, value, opts) {
49
- const body = JettonWallet.burnMessage(opts.jettonAmount, opts.receiverAddress, opts.crossChainTonAmount, opts.crossChainPayload, opts.queryId);
50
- await provider.internal(via, {
51
- value,
52
- sendMode: ton_1.SendMode.PAY_GAS_SEPARATELY,
53
- body: body,
54
- });
55
- }
56
- static transferMessage(jettonAmount, to, responseAddress, forwardTonAmount, crossChainTonAmount, crossChainPayload, queryId) {
57
- return (0, ton_1.beginCell)()
58
- .storeUint(JettonWalletOpCodes.transfer, 32)
59
- .storeUint(queryId ?? 0, 64)
60
- .storeCoins(jettonAmount)
61
- .storeAddress(ton_1.Address.parse(to))
62
- .storeAddress(responseAddress ? ton_1.Address.parse(responseAddress) : null)
63
- .storeMaybeRef(null)
64
- .storeCoins((forwardTonAmount || 0n) + (crossChainTonAmount || 0n))
65
- .storeCoins(crossChainTonAmount ?? 0n)
66
- .storeMaybeRef(crossChainPayload)
67
- .endCell();
68
- }
69
- async sendTransfer(provider, via, value, opts) {
70
- await provider.internal(via, {
71
- value,
72
- sendMode: ton_1.SendMode.PAY_GAS_SEPARATELY,
73
- body: (0, ton_1.beginCell)()
74
- .storeUint(JettonWalletOpCodes.transfer, 32)
75
- .storeUint(opts.queryId || 0, 64)
76
- .storeCoins(opts.jettonAmount)
77
- .storeAddress(ton_1.Address.parse(opts.toOwnerAddress))
78
- .storeAddress(opts.responseAddress ? ton_1.Address.parse(opts.responseAddress) : null)
79
- .storeMaybeRef(opts.customPayload)
80
- .storeCoins(opts.forwardTonAmount ?? 0n)
81
- .storeMaybeRef(opts.forwardPayload)
82
- .endCell(),
83
- });
84
- }
85
- async getWalletData(provider) {
86
- const result = await provider.get('get_wallet_data', []);
87
- return {
88
- balance: result.stack.readBigNumber(),
89
- ownerAddress: result.stack.readAddress().toString(),
90
- jettonMasterAddress: result.stack.readAddress().toString(),
91
- jettonWalletCode: result.stack.readCell(),
92
- };
93
- }
94
- async getJettonBalance(provider) {
95
- const state = await provider.getState();
96
- if (state.state.type !== 'active') {
97
- return 0n;
98
- }
99
- const result = await provider.get('get_wallet_data', []);
100
- return result.stack.readBigNumber();
101
- }
102
- }
103
- exports.JettonWallet = JettonWallet;
@@ -1,10 +0,0 @@
1
- import type { Cell, Contract, ContractProvider } from '@ton/ton';
2
- import { Address } from '@ton/ton';
3
- export declare class Settings implements Contract {
4
- static create(address: Address): Settings;
5
- readonly address: Address;
6
- constructor(address: Address);
7
- getKeyFromString(ContractName: string): bigint;
8
- getAddressSetting(provider: ContractProvider, ContractName: string): Promise<string>;
9
- getCellSetting(provider: ContractProvider, setting: string): Promise<Cell>;
10
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Settings = void 0;
4
- const ethers_1 = require("ethers");
5
- const errors_1 = require("../errors");
6
- class Settings {
7
- static create(address) {
8
- return new Settings(address);
9
- }
10
- constructor(address) {
11
- this.address = address;
12
- }
13
- getKeyFromString(ContractName) {
14
- const hash = ethers_1.ethers.sha256(ethers_1.ethers.toUtf8Bytes(ContractName));
15
- return ethers_1.ethers.toBigInt(hash);
16
- }
17
- async getAddressSetting(provider, ContractName) {
18
- const key = this.getKeyFromString(ContractName);
19
- const { stack } = await provider.get('get', [{ type: 'int', value: key }]);
20
- const cell = stack.readCellOpt();
21
- const found = stack.readBoolean();
22
- if (!found) {
23
- return '';
24
- }
25
- return cell ? cell.beginParse().loadAddress().toString() : '';
26
- }
27
- async getCellSetting(provider, setting) {
28
- const key = this.getKeyFromString(setting);
29
- const { stack } = await provider.get('get', [{ type: 'int', value: key }]);
30
- const cell = stack.readCellOpt();
31
- const found = stack.readBoolean();
32
- if (!found || cell == null) {
33
- throw (0, errors_1.emptySettingError)(setting);
34
- }
35
- return cell;
36
- }
37
- }
38
- exports.Settings = Settings;