@tonappchain/sdk 0.5.7 → 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.
- package/LICENSE +20 -20
- package/README.md +189 -1276
- package/package.json +67 -67
- package/dist/adapters/contractOpener.d.ts +0 -19
- package/dist/adapters/contractOpener.js +0 -94
- package/dist/errors/errors.d.ts +0 -34
- package/dist/errors/errors.js +0 -80
- package/dist/errors/index.d.ts +0 -2
- package/dist/errors/index.js +0 -30
- package/dist/errors/instances.d.ts +0 -16
- package/dist/errors/instances.js +0 -28
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -35
- package/dist/sdk/Consts.d.ts +0 -6
- package/dist/sdk/Consts.js +0 -10
- package/dist/sdk/OperationTracker.d.ts +0 -14
- package/dist/sdk/OperationTracker.js +0 -151
- package/dist/sdk/StartTracking.d.ts +0 -8
- package/dist/sdk/StartTracking.js +0 -126
- package/dist/sdk/TacSdk.d.ts +0 -36
- package/dist/sdk/TacSdk.js +0 -365
- package/dist/sdk/Utils.d.ts +0 -18
- package/dist/sdk/Utils.js +0 -126
- package/dist/sender/RawSender.d.ts +0 -13
- package/dist/sender/RawSender.js +0 -37
- package/dist/sender/SenderAbstraction.d.ts +0 -19
- package/dist/sender/SenderAbstraction.js +0 -5
- package/dist/sender/SenderFactory.d.ts +0 -33
- package/dist/sender/SenderFactory.js +0 -55
- package/dist/sender/TonConnectSender.d.ts +0 -11
- package/dist/sender/TonConnectSender.js +0 -33
- package/dist/sender/index.d.ts +0 -2
- package/dist/sender/index.js +0 -18
- package/dist/structs/InternalStruct.d.ts +0 -54
- package/dist/structs/InternalStruct.js +0 -8
- package/dist/structs/Struct.d.ts +0 -227
- package/dist/structs/Struct.js +0 -38
- package/dist/wrappers/ContentUtils.d.ts +0 -25
- package/dist/wrappers/ContentUtils.js +0 -160
- package/dist/wrappers/HighloadQueryId.d.ts +0 -17
- package/dist/wrappers/HighloadQueryId.js +0 -72
- package/dist/wrappers/HighloadWalletV3.d.ts +0 -61
- package/dist/wrappers/HighloadWalletV3.js +0 -161
- package/dist/wrappers/JettonMaster.d.ts +0 -24
- package/dist/wrappers/JettonMaster.js +0 -53
- package/dist/wrappers/JettonWallet.d.ts +0 -46
- package/dist/wrappers/JettonWallet.js +0 -103
- package/dist/wrappers/Settings.d.ts +0 -10
- package/dist/wrappers/Settings.js +0 -38
package/dist/sdk/TacSdk.js
DELETED
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TacSdk = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const ton_1 = require("@ton/ton");
|
|
9
|
-
const ethers_1 = require("ethers");
|
|
10
|
-
// import structs
|
|
11
|
-
const Struct_1 = require("../structs/Struct");
|
|
12
|
-
// import internal structs
|
|
13
|
-
const InternalStruct_1 = require("../structs/InternalStruct");
|
|
14
|
-
// jetton imports
|
|
15
|
-
const JettonMaster_1 = require("../wrappers/JettonMaster");
|
|
16
|
-
const JettonWallet_1 = require("../wrappers/JettonWallet");
|
|
17
|
-
// ton settings
|
|
18
|
-
const Settings_1 = require("../wrappers/Settings");
|
|
19
|
-
const Consts_1 = require("./Consts");
|
|
20
|
-
const Utils_1 = require("./Utils");
|
|
21
|
-
const artifacts_1 = require("@tonappchain/artifacts");
|
|
22
|
-
const errors_1 = require("../errors");
|
|
23
|
-
const contractOpener_1 = require("../adapters/contractOpener");
|
|
24
|
-
class TacSdk {
|
|
25
|
-
constructor(network, delay, artifacts, TONParams, TACParams, liteSequencerEndpoints) {
|
|
26
|
-
this.network = network;
|
|
27
|
-
this.delay = delay;
|
|
28
|
-
this.artifacts = artifacts;
|
|
29
|
-
this.TONParams = TONParams;
|
|
30
|
-
this.TACParams = TACParams;
|
|
31
|
-
this.liteSequencerEndpoints = liteSequencerEndpoints;
|
|
32
|
-
}
|
|
33
|
-
static async create(sdkParams) {
|
|
34
|
-
const network = sdkParams.network;
|
|
35
|
-
const delay = sdkParams.delay ?? Consts_1.DEFAULT_DELAY;
|
|
36
|
-
const artifacts = network === Struct_1.Network.TESTNET ? artifacts_1.testnet : artifacts_1.mainnet;
|
|
37
|
-
const TONParams = await this.prepareTONParams(network, delay, artifacts, sdkParams.TONParams);
|
|
38
|
-
const TACParams = await this.prepareTACParams(artifacts, sdkParams.TACParams);
|
|
39
|
-
const liteSequencerEndpoints = sdkParams.customLiteSequencerEndpoints ??
|
|
40
|
-
(network === Struct_1.Network.TESTNET
|
|
41
|
-
? artifacts_1.testnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS
|
|
42
|
-
: artifacts_1.mainnet.PUBLIC_LITE_SEQUENCER_ENDPOINTS);
|
|
43
|
-
return new TacSdk(network, delay, artifacts, TONParams, TACParams, liteSequencerEndpoints);
|
|
44
|
-
}
|
|
45
|
-
static async prepareTONParams(network, delay, artifacts, TONParams) {
|
|
46
|
-
const contractOpener = TONParams?.contractOpener ?? (await (0, contractOpener_1.orbsOpener4)(network));
|
|
47
|
-
const settingsAddress = TONParams?.settingsAddress ?? artifacts.ton.addresses.TON_SETTINGS_ADDRESS;
|
|
48
|
-
const settings = contractOpener.open(new Settings_1.Settings(ton_1.Address.parse(settingsAddress)));
|
|
49
|
-
const jettonProxyAddress = await settings.getAddressSetting('JettonProxyAddress');
|
|
50
|
-
await (0, Utils_1.sleep)(delay * 1000);
|
|
51
|
-
const crossChainLayerAddress = await settings.getAddressSetting('CrossChainLayerAddress');
|
|
52
|
-
await (0, Utils_1.sleep)(delay * 1000);
|
|
53
|
-
const jettonMinterCode = await settings.getCellSetting('JETTON_MINTER_CODE');
|
|
54
|
-
await (0, Utils_1.sleep)(delay * 1000);
|
|
55
|
-
const jettonWalletCode = await settings.getCellSetting('JETTON_WALLET_CODE');
|
|
56
|
-
await (0, Utils_1.sleep)(delay * 1000);
|
|
57
|
-
return {
|
|
58
|
-
contractOpener,
|
|
59
|
-
jettonProxyAddress,
|
|
60
|
-
crossChainLayerAddress,
|
|
61
|
-
jettonMinterCode,
|
|
62
|
-
jettonWalletCode,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
static async prepareTACParams(artifacts, TACParams) {
|
|
66
|
-
const provider = TACParams?.provider ?? ethers_1.ethers.getDefaultProvider(artifacts.TAC_RPC_ENDPOINT);
|
|
67
|
-
const settingsAddress = TACParams?.settingsAddress?.toString() ?? artifacts.tac.addresses.TAC_SETTINGS_ADDRESS;
|
|
68
|
-
const settings = new ethers_1.ethers.Contract(settingsAddress, TACParams?.settingsABI ?? artifacts.tac.compilationArtifacts.Settings.abi, provider);
|
|
69
|
-
const crossChainLayerABI = TACParams?.crossChainLayerABI ?? artifacts.tac.compilationArtifacts.CrossChainLayer.abi;
|
|
70
|
-
const crossChainLayerAddress = await settings.getAddressSetting((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)('CrossChainLayerAddress')));
|
|
71
|
-
const tokenUtilsAddress = await settings.getAddressSetting((0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)('TokenUtilsAddress')));
|
|
72
|
-
const crossChainLayerTokenABI = TACParams?.crossChainLayerTokenABI ?? artifacts.tac.compilationArtifacts.CrossChainLayerToken.abi;
|
|
73
|
-
const crossChainLayerTokenBytecode = TACParams?.crossChainLayerTokenBytecode ?? artifacts.tac.compilationArtifacts.CrossChainLayerToken.bytecode;
|
|
74
|
-
return {
|
|
75
|
-
provider,
|
|
76
|
-
settingsAddress,
|
|
77
|
-
tokenUtilsAddress,
|
|
78
|
-
abiCoder: new ethers_1.ethers.AbiCoder(),
|
|
79
|
-
crossChainLayerABI,
|
|
80
|
-
crossChainLayerAddress,
|
|
81
|
-
crossChainLayerTokenABI,
|
|
82
|
-
crossChainLayerTokenBytecode,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
closeConnections() {
|
|
86
|
-
return this.TONParams.contractOpener.closeConnections?.call(this);
|
|
87
|
-
}
|
|
88
|
-
get nativeTONAddress() {
|
|
89
|
-
return 'NONE';
|
|
90
|
-
}
|
|
91
|
-
get nativeTACAddress() {
|
|
92
|
-
const crossChainLayer = new ethers_1.ethers.Contract(this.TACParams.crossChainLayerAddress, this.TACParams.crossChainLayerABI, this.TACParams.provider);
|
|
93
|
-
return crossChainLayer.NATIVE_TOKEN_ADDRESS.staticCall();
|
|
94
|
-
}
|
|
95
|
-
async getUserJettonWalletAddress(userAddress, tokenAddress) {
|
|
96
|
-
const jettonMaster = this.TONParams.contractOpener.open(new JettonMaster_1.JettonMaster(ton_1.Address.parse(tokenAddress)));
|
|
97
|
-
return jettonMaster.getWalletAddress(userAddress);
|
|
98
|
-
}
|
|
99
|
-
async getUserJettonBalance(userAddress, tokenAddress) {
|
|
100
|
-
const jettonMaster = this.TONParams.contractOpener.open(new JettonMaster_1.JettonMaster(ton_1.Address.parse(tokenAddress)));
|
|
101
|
-
const userJettonWalletAddress = await jettonMaster.getWalletAddress(userAddress);
|
|
102
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
103
|
-
const userJettonWallet = this.TONParams.contractOpener.open(new JettonWallet_1.JettonWallet(ton_1.Address.parse(userJettonWalletAddress)));
|
|
104
|
-
return userJettonWallet.getJettonBalance();
|
|
105
|
-
}
|
|
106
|
-
async getUserJettonBalanceExtended(userAddress, tokenAddress) {
|
|
107
|
-
const masterAddress = ton_1.Address.parse(tokenAddress);
|
|
108
|
-
const masterState = await this.TONParams.contractOpener.getContractState(masterAddress);
|
|
109
|
-
if (masterState.state !== 'active') {
|
|
110
|
-
return { exists: false };
|
|
111
|
-
}
|
|
112
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
113
|
-
const jettonMaster = this.TONParams.contractOpener.open(new JettonMaster_1.JettonMaster(masterAddress));
|
|
114
|
-
const userJettonWalletAddress = await jettonMaster.getWalletAddress(userAddress);
|
|
115
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
116
|
-
const userJettonWallet = this.TONParams.contractOpener.open(new JettonWallet_1.JettonWallet(ton_1.Address.parse(userJettonWalletAddress)));
|
|
117
|
-
const rawAmount = await userJettonWallet.getJettonBalance();
|
|
118
|
-
const decimalsRaw = (await jettonMaster.getJettonData()).content.metadata.decimals;
|
|
119
|
-
const decimals = decimalsRaw ? Number(decimalsRaw) : 9;
|
|
120
|
-
return {
|
|
121
|
-
rawAmount,
|
|
122
|
-
decimals,
|
|
123
|
-
amount: (0, Utils_1.calculateAmount)(rawAmount, decimals),
|
|
124
|
-
exists: true,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
getJettonTransferPayload(jettonData, responseAddress, evmData, crossChainTonAmount) {
|
|
128
|
-
const queryId = (0, Utils_1.generateRandomNumberByTimestamp)().randomNumber;
|
|
129
|
-
return JettonWallet_1.JettonWallet.transferMessage(jettonData.rawAmount, this.TONParams.jettonProxyAddress, responseAddress, Consts_1.JETTON_TRANSFER_FORWARD_TON_AMOUNT, crossChainTonAmount, evmData, queryId);
|
|
130
|
-
}
|
|
131
|
-
getJettonBurnPayload(jettonData, evmData, crossChainTonAmount) {
|
|
132
|
-
const queryId = (0, Utils_1.generateRandomNumberByTimestamp)().randomNumber;
|
|
133
|
-
return JettonWallet_1.JettonWallet.burnMessage(jettonData.rawAmount, jettonData.notificationReceiverAddress, crossChainTonAmount, evmData, queryId);
|
|
134
|
-
}
|
|
135
|
-
getTonTransferPayload(responseAddress, evmData, crossChainTonAmount) {
|
|
136
|
-
const queryId = (0, Utils_1.generateRandomNumberByTimestamp)().randomNumber;
|
|
137
|
-
return (0, ton_1.beginCell)()
|
|
138
|
-
.storeUint(this.artifacts.ton.wrappers.CrossChainLayerOpCodes.anyone_l1MsgToL2, 32)
|
|
139
|
-
.storeUint(queryId, 64)
|
|
140
|
-
.storeUint(this.artifacts.ton.wrappers.OperationType.tonTransfer, 32)
|
|
141
|
-
.storeCoins(crossChainTonAmount)
|
|
142
|
-
.storeAddress(ton_1.Address.parse(responseAddress))
|
|
143
|
-
.storeMaybeRef(evmData)
|
|
144
|
-
.endCell();
|
|
145
|
-
}
|
|
146
|
-
async getJettonOpType(asset) {
|
|
147
|
-
const { code: givenMinterCodeBOC } = await this.TONParams.contractOpener.getContractState((0, ton_1.address)(asset.address));
|
|
148
|
-
if (!givenMinterCodeBOC) {
|
|
149
|
-
throw errors_1.emptyContractError;
|
|
150
|
-
}
|
|
151
|
-
const givenMinterCode = ton_1.Cell.fromBoc(givenMinterCodeBOC)[0];
|
|
152
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
153
|
-
if (!this.TONParams.jettonMinterCode.equals(givenMinterCode)) {
|
|
154
|
-
return InternalStruct_1.AssetOpType.JETTON_TRANSFER;
|
|
155
|
-
}
|
|
156
|
-
const givenMinter = this.TONParams.contractOpener.open(new JettonMaster_1.JettonMaster((0, ton_1.address)(asset.address)));
|
|
157
|
-
const l2Address = await givenMinter.getL2Address();
|
|
158
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
159
|
-
const expectedMinterAddress = await (0, Utils_1.calculateContractAddress)(this.TONParams.jettonMinterCode, (0, ton_1.beginCell)()
|
|
160
|
-
.storeCoins(0)
|
|
161
|
-
.storeAddress((0, ton_1.address)(this.TONParams.crossChainLayerAddress))
|
|
162
|
-
.storeAddress(null)
|
|
163
|
-
.storeRef((0, ton_1.beginCell)().endCell())
|
|
164
|
-
.storeRef(this.TONParams.jettonWalletCode)
|
|
165
|
-
.storeStringTail(l2Address)
|
|
166
|
-
.endCell());
|
|
167
|
-
if (!expectedMinterAddress.equals(givenMinter.address)) {
|
|
168
|
-
return InternalStruct_1.AssetOpType.JETTON_TRANSFER;
|
|
169
|
-
}
|
|
170
|
-
return InternalStruct_1.AssetOpType.JETTON_BURN;
|
|
171
|
-
}
|
|
172
|
-
async aggregateJettons(assets) {
|
|
173
|
-
const uniqueAssetsMap = new Map();
|
|
174
|
-
let crossChainTonAmount = 0n;
|
|
175
|
-
for await (const asset of assets ?? []) {
|
|
176
|
-
if (asset.rawAmount <= 0)
|
|
177
|
-
continue;
|
|
178
|
-
if (asset.address) {
|
|
179
|
-
(0, Utils_1.validateTVMAddress)(asset.address);
|
|
180
|
-
uniqueAssetsMap.set(asset.address, (uniqueAssetsMap.get(asset.address) || 0n) + BigInt(asset.rawAmount));
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
crossChainTonAmount += BigInt(asset.rawAmount);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const jettons = Array.from(uniqueAssetsMap.entries()).map(([address, rawAmount]) => ({
|
|
187
|
-
address,
|
|
188
|
-
rawAmount,
|
|
189
|
-
}));
|
|
190
|
-
return {
|
|
191
|
-
jettons,
|
|
192
|
-
crossChainTonAmount,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
async generatePayload(jetton, caller, evmData, crossChainTonAmount) {
|
|
196
|
-
const opType = await this.getJettonOpType(jetton);
|
|
197
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
198
|
-
console.log(`***** Jetton ${jetton.address} requires ${opType} operation`);
|
|
199
|
-
let payload;
|
|
200
|
-
switch (opType) {
|
|
201
|
-
case InternalStruct_1.AssetOpType.JETTON_BURN:
|
|
202
|
-
payload = this.getJettonBurnPayload({
|
|
203
|
-
notificationReceiverAddress: this.TONParams.crossChainLayerAddress,
|
|
204
|
-
...jetton,
|
|
205
|
-
}, evmData, crossChainTonAmount);
|
|
206
|
-
break;
|
|
207
|
-
case InternalStruct_1.AssetOpType.JETTON_TRANSFER:
|
|
208
|
-
payload = this.getJettonTransferPayload(jetton, caller, evmData, crossChainTonAmount);
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
return payload;
|
|
212
|
-
}
|
|
213
|
-
async generateCrossChainMessages(caller, evmData, aggregatedData) {
|
|
214
|
-
let crossChainTonAmount = aggregatedData.crossChainTonAmount;
|
|
215
|
-
if (aggregatedData.jettons.length == 0) {
|
|
216
|
-
return [
|
|
217
|
-
{
|
|
218
|
-
address: this.TONParams.crossChainLayerAddress,
|
|
219
|
-
value: crossChainTonAmount + Consts_1.TRANSACTION_TON_AMOUNT,
|
|
220
|
-
payload: this.getTonTransferPayload(caller, evmData, crossChainTonAmount),
|
|
221
|
-
},
|
|
222
|
-
];
|
|
223
|
-
}
|
|
224
|
-
const messages = [];
|
|
225
|
-
for (const jetton of aggregatedData.jettons) {
|
|
226
|
-
const payload = await this.generatePayload(jetton, caller, evmData, crossChainTonAmount);
|
|
227
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
228
|
-
const jettonWalletAddress = await this.getUserJettonWalletAddress(caller, jetton.address);
|
|
229
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
230
|
-
messages.push({
|
|
231
|
-
address: jettonWalletAddress,
|
|
232
|
-
value: crossChainTonAmount + Consts_1.TRANSACTION_TON_AMOUNT,
|
|
233
|
-
payload,
|
|
234
|
-
});
|
|
235
|
-
crossChainTonAmount = 0n;
|
|
236
|
-
}
|
|
237
|
-
return messages;
|
|
238
|
-
}
|
|
239
|
-
async getRawAmount(asset, precalculatedAddress) {
|
|
240
|
-
if ('rawAmount' in asset) {
|
|
241
|
-
// User specified raw format amount
|
|
242
|
-
return asset.rawAmount;
|
|
243
|
-
}
|
|
244
|
-
if (!precalculatedAddress) {
|
|
245
|
-
// User specified TON Coin
|
|
246
|
-
return (0, ton_1.toNano)(asset.amount);
|
|
247
|
-
}
|
|
248
|
-
if (typeof asset.decimals === 'number') {
|
|
249
|
-
// User manually set decimals
|
|
250
|
-
return (0, Utils_1.calculateRawAmount)(asset.amount, asset.decimals);
|
|
251
|
-
}
|
|
252
|
-
// Get decimals from chain
|
|
253
|
-
(0, Utils_1.validateTVMAddress)(precalculatedAddress);
|
|
254
|
-
const contract = this.TONParams.contractOpener.open(new JettonMaster_1.JettonMaster((0, ton_1.address)(precalculatedAddress)));
|
|
255
|
-
const { content } = await contract.getJettonData();
|
|
256
|
-
if (!content.metadata.decimals) {
|
|
257
|
-
// if decimals not specified use default value 9
|
|
258
|
-
return (0, ton_1.toNano)(asset.amount);
|
|
259
|
-
}
|
|
260
|
-
return (0, Utils_1.calculateRawAmount)(asset.amount, Number(content.metadata.decimals));
|
|
261
|
-
}
|
|
262
|
-
async convertAssetsToRawFormat(assets) {
|
|
263
|
-
return await Promise.all((assets ?? []).map(async (asset) => {
|
|
264
|
-
const address = (0, ethers_1.isAddress)(asset.address)
|
|
265
|
-
? await this.getTVMTokenAddress(asset.address)
|
|
266
|
-
: asset.address;
|
|
267
|
-
return {
|
|
268
|
-
address,
|
|
269
|
-
rawAmount: await this.getRawAmount(asset, address),
|
|
270
|
-
};
|
|
271
|
-
}));
|
|
272
|
-
}
|
|
273
|
-
async getGasLimit(evmProxyMsg, transactionLinker, rawAssets, forceSend = false) {
|
|
274
|
-
const tacSimulationBody = {
|
|
275
|
-
tacCallParams: {
|
|
276
|
-
arguments: evmProxyMsg.encodedParameters ?? '0x',
|
|
277
|
-
methodName: (0, Utils_1.formatSolidityMethodName)(evmProxyMsg.methodName),
|
|
278
|
-
target: evmProxyMsg.evmTargetAddress,
|
|
279
|
-
},
|
|
280
|
-
extraData: '0x',
|
|
281
|
-
feeAssetAddress: '',
|
|
282
|
-
shardsKey: transactionLinker.shardsKey,
|
|
283
|
-
tonAssets: rawAssets.map((asset) => ({
|
|
284
|
-
amount: asset.rawAmount.toString(),
|
|
285
|
-
tokenAddress: asset.address || '',
|
|
286
|
-
})),
|
|
287
|
-
tonCaller: transactionLinker.caller,
|
|
288
|
-
};
|
|
289
|
-
const tacSimulationResult = await this.simulateTACMessage(tacSimulationBody);
|
|
290
|
-
if (!tacSimulationResult.simulationStatus) {
|
|
291
|
-
if (forceSend) {
|
|
292
|
-
return 0n;
|
|
293
|
-
}
|
|
294
|
-
throw tacSimulationResult;
|
|
295
|
-
}
|
|
296
|
-
return (BigInt(tacSimulationResult.estimatedGas) * 120n) / 100n;
|
|
297
|
-
}
|
|
298
|
-
async sendCrossChainTransaction(evmProxyMsg, sender, assets, forceSend = false) {
|
|
299
|
-
const rawAssets = await this.convertAssetsToRawFormat(assets);
|
|
300
|
-
const aggregatedData = await this.aggregateJettons(rawAssets);
|
|
301
|
-
const transactionLinkerShardCount = aggregatedData.jettons.length == 0 ? 1 : aggregatedData.jettons.length;
|
|
302
|
-
const caller = sender.getSenderAddress();
|
|
303
|
-
const transactionLinker = (0, Utils_1.generateTransactionLinker)(caller, transactionLinkerShardCount);
|
|
304
|
-
const gasLimit = await this.getGasLimit(evmProxyMsg, transactionLinker, rawAssets, forceSend);
|
|
305
|
-
if (evmProxyMsg.gasLimit == 0n || evmProxyMsg.gasLimit == undefined) {
|
|
306
|
-
evmProxyMsg.gasLimit = gasLimit;
|
|
307
|
-
}
|
|
308
|
-
const evmData = (0, Utils_1.buildEvmDataCell)(transactionLinker, evmProxyMsg);
|
|
309
|
-
const messages = await this.generateCrossChainMessages(caller, evmData, aggregatedData);
|
|
310
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
311
|
-
const transaction = {
|
|
312
|
-
validUntil: +new Date() + 15 * 60 * 1000,
|
|
313
|
-
messages,
|
|
314
|
-
network: this.network,
|
|
315
|
-
};
|
|
316
|
-
console.log('*****Sending transaction: ', transaction);
|
|
317
|
-
const sendTransactionResult = await sender.sendShardTransaction(transaction, this.delay, this.network, this.TONParams.contractOpener);
|
|
318
|
-
return { sendTransactionResult, ...transactionLinker };
|
|
319
|
-
}
|
|
320
|
-
async getEVMTokenAddress(tvmTokenAddress) {
|
|
321
|
-
if (tvmTokenAddress !== this.nativeTONAddress) {
|
|
322
|
-
(0, Utils_1.validateTVMAddress)(tvmTokenAddress);
|
|
323
|
-
const { code: givenMinterCodeBOC } = await this.TONParams.contractOpener.getContractState((0, ton_1.address)(tvmTokenAddress));
|
|
324
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
325
|
-
if (givenMinterCodeBOC && this.TONParams.jettonMinterCode.equals(ton_1.Cell.fromBoc(givenMinterCodeBOC)[0])) {
|
|
326
|
-
const givenMinter = this.TONParams.contractOpener.open(new JettonMaster_1.JettonMaster((0, ton_1.address)(tvmTokenAddress)));
|
|
327
|
-
const l2Address = await givenMinter.getL2Address();
|
|
328
|
-
await (0, Utils_1.sleep)(this.delay * 1000);
|
|
329
|
-
return l2Address;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return (0, Utils_1.calculateEVMTokenAddress)(this.TACParams.abiCoder, this.TACParams.tokenUtilsAddress, this.TACParams.crossChainLayerTokenBytecode, this.TACParams.crossChainLayerAddress, tvmTokenAddress);
|
|
333
|
-
}
|
|
334
|
-
async getTVMTokenAddress(evmTokenAddress) {
|
|
335
|
-
(0, Utils_1.validateEVMAddress)(evmTokenAddress);
|
|
336
|
-
const bytecode = await this.TACParams.provider.getCode(evmTokenAddress);
|
|
337
|
-
if (bytecode.includes(ethers_1.ethers.id('getInfo()').slice(2, 10))) {
|
|
338
|
-
const contract = new ethers_1.ethers.Contract(evmTokenAddress, this.TACParams.crossChainLayerTokenABI, this.TACParams.provider);
|
|
339
|
-
const info = await contract.getInfo.staticCall();
|
|
340
|
-
return info.l1Address;
|
|
341
|
-
}
|
|
342
|
-
const jettonMaster = JettonMaster_1.JettonMaster.createFromConfig({
|
|
343
|
-
evmTokenAddress,
|
|
344
|
-
crossChainLayerAddress: (0, ton_1.address)(this.TONParams.crossChainLayerAddress),
|
|
345
|
-
code: this.TONParams.jettonMinterCode,
|
|
346
|
-
walletCode: this.TONParams.jettonWalletCode,
|
|
347
|
-
});
|
|
348
|
-
return jettonMaster.address.toString();
|
|
349
|
-
}
|
|
350
|
-
async simulateTACMessage(req) {
|
|
351
|
-
for (const endpoint of this.liteSequencerEndpoints) {
|
|
352
|
-
try {
|
|
353
|
-
const response = await axios_1.default.post(`${endpoint}/tac/simulator/simulate-message`, req, {
|
|
354
|
-
transformResponse: [Utils_1.toCamelCaseTransformer],
|
|
355
|
-
});
|
|
356
|
-
return response.data.response;
|
|
357
|
-
}
|
|
358
|
-
catch (error) {
|
|
359
|
-
console.error(`Error while simulating with ${endpoint}:`, error);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
throw errors_1.simulationError;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
exports.TacSdk = TacSdk;
|
package/dist/sdk/Utils.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Address, Cell } from '@ton/ton';
|
|
2
|
-
import { AbiCoder } from 'ethers';
|
|
3
|
-
import { EvmProxyMsg, TransactionLinker } from '../structs/Struct';
|
|
4
|
-
import { RandomNumberByTimestamp } from '../structs/InternalStruct';
|
|
5
|
-
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
6
|
-
export declare function generateRandomNumber(interval: number): number;
|
|
7
|
-
export declare function generateRandomNumberByTimestamp(): RandomNumberByTimestamp;
|
|
8
|
-
export declare function calculateContractAddress(code: Cell, data: Cell): Promise<Address>;
|
|
9
|
-
export declare function buildEvmDataCell(transactionLinker: TransactionLinker, evmProxyMsg: EvmProxyMsg): Cell;
|
|
10
|
-
export declare function formatSolidityMethodName(methodName?: string): string;
|
|
11
|
-
export declare function generateTransactionLinker(caller: string, shardCount: number): TransactionLinker;
|
|
12
|
-
export declare function validateTVMAddress(address: string): void;
|
|
13
|
-
export declare function validateEVMAddress(address: string): void;
|
|
14
|
-
export declare function calculateEVMTokenAddress(abiCoder: AbiCoder, tokenUtilsAddress: string, crossChainLayerTokenBytecode: string, crossChainLayerAddress: string, l1Address: string): string;
|
|
15
|
-
export declare const convertKeysToCamelCase: <T>(data: T) => T;
|
|
16
|
-
export declare const calculateRawAmount: (amount: number, decimals: number) => bigint;
|
|
17
|
-
export declare const calculateAmount: (rawAmount: bigint, decimals: number) => number;
|
|
18
|
-
export declare const toCamelCaseTransformer: (data: any) => any;
|
package/dist/sdk/Utils.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toCamelCaseTransformer = exports.calculateAmount = exports.calculateRawAmount = exports.convertKeysToCamelCase = exports.sleep = void 0;
|
|
4
|
-
exports.generateRandomNumber = generateRandomNumber;
|
|
5
|
-
exports.generateRandomNumberByTimestamp = generateRandomNumberByTimestamp;
|
|
6
|
-
exports.calculateContractAddress = calculateContractAddress;
|
|
7
|
-
exports.buildEvmDataCell = buildEvmDataCell;
|
|
8
|
-
exports.formatSolidityMethodName = formatSolidityMethodName;
|
|
9
|
-
exports.generateTransactionLinker = generateTransactionLinker;
|
|
10
|
-
exports.validateTVMAddress = validateTVMAddress;
|
|
11
|
-
exports.validateEVMAddress = validateEVMAddress;
|
|
12
|
-
exports.calculateEVMTokenAddress = calculateEVMTokenAddress;
|
|
13
|
-
const ton_1 = require("@ton/ton");
|
|
14
|
-
const ethers_1 = require("ethers");
|
|
15
|
-
const errors_1 = require("../errors");
|
|
16
|
-
const Consts_1 = require("./Consts");
|
|
17
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
18
|
-
exports.sleep = sleep;
|
|
19
|
-
function generateRandomNumber(interval) {
|
|
20
|
-
return Math.round(Math.random() * interval);
|
|
21
|
-
}
|
|
22
|
-
function generateRandomNumberByTimestamp() {
|
|
23
|
-
const timestamp = Math.floor(+new Date() / 1000);
|
|
24
|
-
return {
|
|
25
|
-
timestamp,
|
|
26
|
-
randomNumber: timestamp + generateRandomNumber(1000),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
async function calculateContractAddress(code, data) {
|
|
30
|
-
const stateInit = (0, ton_1.beginCell)().store((0, ton_1.storeStateInit)({ code, data })).endCell();
|
|
31
|
-
return new ton_1.Address(0, stateInit.hash());
|
|
32
|
-
}
|
|
33
|
-
function buildEvmDataCell(transactionLinker, evmProxyMsg) {
|
|
34
|
-
const evmArguments = evmProxyMsg.encodedParameters
|
|
35
|
-
? Buffer.from(evmProxyMsg.encodedParameters.split('0x')[1], 'hex').toString('base64')
|
|
36
|
-
: null;
|
|
37
|
-
const json = JSON.stringify({
|
|
38
|
-
evmCall: {
|
|
39
|
-
target: evmProxyMsg.evmTargetAddress,
|
|
40
|
-
methodName: formatSolidityMethodName(evmProxyMsg.methodName),
|
|
41
|
-
arguments: evmArguments,
|
|
42
|
-
gasLimit: Number(evmProxyMsg.gasLimit),
|
|
43
|
-
},
|
|
44
|
-
shardsKey: transactionLinker.shardsKey,
|
|
45
|
-
shardCount: transactionLinker.shardCount,
|
|
46
|
-
});
|
|
47
|
-
return (0, ton_1.beginCell)().storeStringTail(json).endCell();
|
|
48
|
-
}
|
|
49
|
-
function formatSolidityMethodName(methodName) {
|
|
50
|
-
if (!methodName)
|
|
51
|
-
return '';
|
|
52
|
-
if (!Consts_1.SOLIDITY_SIGNATURE_REGEX.test(methodName)) {
|
|
53
|
-
throw (0, errors_1.invalidMethodNameError)(methodName);
|
|
54
|
-
}
|
|
55
|
-
return Consts_1.SOLIDITY_METHOD_NAME_REGEX.test(methodName) ? `${methodName}(bytes,bytes)` : methodName;
|
|
56
|
-
}
|
|
57
|
-
function generateTransactionLinker(caller, shardCount) {
|
|
58
|
-
const random = generateRandomNumberByTimestamp();
|
|
59
|
-
return {
|
|
60
|
-
caller: ton_1.Address.normalize(caller),
|
|
61
|
-
shardCount,
|
|
62
|
-
shardsKey: String(random.randomNumber),
|
|
63
|
-
timestamp: random.timestamp,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
function validateTVMAddress(address) {
|
|
67
|
-
try {
|
|
68
|
-
ton_1.Address.parse(address); // will throw on error address
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
throw (0, errors_1.tvmAddressError)(address);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function validateEVMAddress(address) {
|
|
75
|
-
if (!(0, ethers_1.isAddress)(address)) {
|
|
76
|
-
throw (0, errors_1.evmAddressError)(address);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function calculateEVMTokenAddress(abiCoder, tokenUtilsAddress, crossChainLayerTokenBytecode, crossChainLayerAddress, l1Address) {
|
|
80
|
-
const salt = ethers_1.ethers.keccak256(ethers_1.ethers.solidityPacked(['string'], [l1Address]));
|
|
81
|
-
const initCode = ethers_1.ethers.solidityPacked(['bytes', 'bytes'], [crossChainLayerTokenBytecode, abiCoder.encode(['address'], [crossChainLayerAddress])]);
|
|
82
|
-
const initCodeHash = ethers_1.ethers.keccak256(initCode);
|
|
83
|
-
return ethers_1.ethers.getCreate2Address(tokenUtilsAddress, salt, initCodeHash);
|
|
84
|
-
}
|
|
85
|
-
const snakeToCamel = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
86
|
-
const convertKeysToCamelCase = (data) => {
|
|
87
|
-
if (Array.isArray(data)) {
|
|
88
|
-
return data.map(exports.convertKeysToCamelCase);
|
|
89
|
-
}
|
|
90
|
-
else if (data !== null && typeof data === 'object') {
|
|
91
|
-
return Object.keys(data).reduce((acc, key) => {
|
|
92
|
-
const camelKey = snakeToCamel(key);
|
|
93
|
-
acc[camelKey] = (0, exports.convertKeysToCamelCase)(data[key]);
|
|
94
|
-
return acc;
|
|
95
|
-
}, {});
|
|
96
|
-
}
|
|
97
|
-
return data;
|
|
98
|
-
};
|
|
99
|
-
exports.convertKeysToCamelCase = convertKeysToCamelCase;
|
|
100
|
-
const calculateRawAmount = (amount, decimals) => {
|
|
101
|
-
const [integerPart, fractionalPart = ''] = amount.toString().split('.');
|
|
102
|
-
// Ensure the fractional part has enough digits
|
|
103
|
-
const paddedFraction = fractionalPart.padEnd(decimals, '0').slice(0, decimals);
|
|
104
|
-
return BigInt(integerPart + paddedFraction);
|
|
105
|
-
};
|
|
106
|
-
exports.calculateRawAmount = calculateRawAmount;
|
|
107
|
-
const calculateAmount = (rawAmount, decimals) => {
|
|
108
|
-
const rawStr = rawAmount.toString();
|
|
109
|
-
if (rawStr.length <= decimals) {
|
|
110
|
-
return Number(`0.${rawStr.padStart(decimals, '0')}`);
|
|
111
|
-
}
|
|
112
|
-
const integerPart = rawStr.slice(0, -decimals);
|
|
113
|
-
const fractionalPart = rawStr.slice(-decimals).replace(/0+$/, '');
|
|
114
|
-
return Number(fractionalPart ? `${integerPart}.${fractionalPart}` : integerPart);
|
|
115
|
-
};
|
|
116
|
-
exports.calculateAmount = calculateAmount;
|
|
117
|
-
const toCamelCaseTransformer = (data) => {
|
|
118
|
-
try {
|
|
119
|
-
const parsedData = JSON.parse(data);
|
|
120
|
-
return (0, exports.convertKeysToCamelCase)(parsedData);
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
return data;
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
exports.toCamelCaseTransformer = toCamelCaseTransformer;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ContractOpener } from '../structs/Struct';
|
|
2
|
-
import type { ShardTransaction } from '../structs/InternalStruct';
|
|
3
|
-
import { Network } from '../structs/Struct';
|
|
4
|
-
import { SenderAbstraction, WalletInstance } from './SenderAbstraction';
|
|
5
|
-
export declare class RawSender implements SenderAbstraction {
|
|
6
|
-
private wallet;
|
|
7
|
-
private secretKey;
|
|
8
|
-
constructor(wallet: WalletInstance, secretKey: Buffer);
|
|
9
|
-
getSenderAddress(): string;
|
|
10
|
-
sendShardTransaction(shardTransaction: ShardTransaction, delay: number, _chain: Network, contractOpener: ContractOpener): Promise<void | (import("@ton/sandbox").SendMessageResult & {
|
|
11
|
-
result: void;
|
|
12
|
-
})>;
|
|
13
|
-
}
|
package/dist/sender/RawSender.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RawSender = void 0;
|
|
4
|
-
const ton_1 = require("@ton/ton");
|
|
5
|
-
const ton_2 = require("@ton/ton");
|
|
6
|
-
const SenderAbstraction_1 = require("./SenderAbstraction");
|
|
7
|
-
class RawSender {
|
|
8
|
-
constructor(wallet, secretKey) {
|
|
9
|
-
this.wallet = wallet;
|
|
10
|
-
this.secretKey = secretKey;
|
|
11
|
-
}
|
|
12
|
-
getSenderAddress() {
|
|
13
|
-
return this.wallet.address.toString();
|
|
14
|
-
}
|
|
15
|
-
async sendShardTransaction(shardTransaction, delay, _chain, contractOpener) {
|
|
16
|
-
const walletContract = contractOpener.open(this.wallet);
|
|
17
|
-
await (0, SenderAbstraction_1.sleep)(delay * 1000);
|
|
18
|
-
const seqno = await walletContract.getSeqno();
|
|
19
|
-
const messages = [];
|
|
20
|
-
for (const message of shardTransaction.messages) {
|
|
21
|
-
messages.push((0, ton_1.internal)({
|
|
22
|
-
to: message.address,
|
|
23
|
-
value: (0, ton_1.fromNano)(message.value),
|
|
24
|
-
bounce: true,
|
|
25
|
-
body: message.payload,
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
await (0, SenderAbstraction_1.sleep)(delay * 1000);
|
|
29
|
-
return walletContract.sendTransfer({
|
|
30
|
-
seqno,
|
|
31
|
-
secretKey: this.secretKey,
|
|
32
|
-
messages,
|
|
33
|
-
sendMode: ton_2.SendMode.PAY_GAS_SEPARATELY,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.RawSender = RawSender;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Contract, ContractProvider, MessageRelaxed, SendMode } from '@ton/ton';
|
|
2
|
-
import type { ContractOpener } from '../structs/Struct';
|
|
3
|
-
import type { ShardTransaction } from '../structs/InternalStruct';
|
|
4
|
-
import { Network } from '../structs/Struct';
|
|
5
|
-
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
6
|
-
export interface WalletInstance extends Contract {
|
|
7
|
-
getSeqno(provider: ContractProvider): Promise<number>;
|
|
8
|
-
sendTransfer(provider: ContractProvider, args: {
|
|
9
|
-
seqno: number;
|
|
10
|
-
secretKey: Buffer;
|
|
11
|
-
messages: MessageRelaxed[];
|
|
12
|
-
sendMode: SendMode;
|
|
13
|
-
timeout?: number;
|
|
14
|
-
}): Promise<void>;
|
|
15
|
-
}
|
|
16
|
-
export interface SenderAbstraction {
|
|
17
|
-
sendShardTransaction(shardTransaction: ShardTransaction, delay: number, chain?: Network, contractOpener?: ContractOpener): Promise<unknown>;
|
|
18
|
-
getSenderAddress(): string;
|
|
19
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { WalletContractV2R1, WalletContractV2R2, WalletContractV3R1, WalletContractV3R2, WalletContractV4, WalletContractV5R1 } from '@ton/ton';
|
|
2
|
-
import { TonConnectUI } from '@tonconnect/ui';
|
|
3
|
-
import { SenderAbstraction } from './SenderAbstraction';
|
|
4
|
-
import { Network } from '../structs/Struct';
|
|
5
|
-
import { HighloadWalletV3 } from '../wrappers/HighloadWalletV3';
|
|
6
|
-
export type WalletVersion = 'V2R1' | 'V2R2' | 'V3R1' | 'V3R2' | 'V4' | 'V5R1' | 'HIGHLOAD_V3';
|
|
7
|
-
export declare const wallets: {
|
|
8
|
-
V2R1: typeof WalletContractV2R1;
|
|
9
|
-
V2R2: typeof WalletContractV2R2;
|
|
10
|
-
V3R1: typeof WalletContractV3R1;
|
|
11
|
-
V3R2: typeof WalletContractV3R2;
|
|
12
|
-
V4: typeof WalletContractV4;
|
|
13
|
-
V5R1: typeof WalletContractV5R1;
|
|
14
|
-
HIGHLOAD_V3: typeof HighloadWalletV3;
|
|
15
|
-
};
|
|
16
|
-
export declare class SenderFactory {
|
|
17
|
-
static getSender(params: {
|
|
18
|
-
network: Network;
|
|
19
|
-
version: WalletVersion;
|
|
20
|
-
mnemonic: string;
|
|
21
|
-
options?: {
|
|
22
|
-
v5r1?: {
|
|
23
|
-
subwalletNumber?: number;
|
|
24
|
-
};
|
|
25
|
-
highloadV3?: {
|
|
26
|
-
subwalletId?: number;
|
|
27
|
-
timeout?: number;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
} | {
|
|
31
|
-
tonConnect: TonConnectUI;
|
|
32
|
-
}): Promise<SenderAbstraction>;
|
|
33
|
-
}
|