@tonappchain/sdk 0.8.1-rc1 → 0.9.0-rc2

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 (40) hide show
  1. package/README.md +2 -0
  2. package/dist/artifacts/dev/tac/utils.d.ts +3 -1
  3. package/dist/artifacts/dev/tac/utils.js +11 -3
  4. package/dist/artifacts/mainnet/tac/utils.d.ts +3 -1
  5. package/dist/artifacts/mainnet/tac/utils.js +11 -3
  6. package/dist/artifacts/mainnet/ton/internal/wrappers/NFTCollection.d.ts +4 -4
  7. package/dist/artifacts/testnet/tac/utils.d.ts +3 -1
  8. package/dist/artifacts/testnet/tac/utils.js +11 -3
  9. package/dist/artifacts/testnet/ton/internal/wrappers/NFTCollection.d.ts +4 -4
  10. package/dist/esm/artifacts/index.d.mts +1 -0
  11. package/dist/esm/artifacts/index.mjs +10 -0
  12. package/dist/esm/artifacts/tacTypes.d.mts +1 -0
  13. package/dist/esm/artifacts/tacTypes.mjs +0 -0
  14. package/dist/esm/artifacts/tonTypes.d.mts +1 -0
  15. package/dist/esm/artifacts/tonTypes.mjs +0 -0
  16. package/dist/esm/chunk-6AEFUAMZ.mjs +13895 -0
  17. package/dist/esm/src/index.d.mts +1 -0
  18. package/dist/esm/src/index.mjs +7735 -0
  19. package/dist/src/agnosticSdk/DebugHelpers.js +5 -5
  20. package/dist/src/agnosticSdk/HooksHandler.js +6 -6
  21. package/dist/src/agnosticSdk/ReplacementHelper.js +2 -2
  22. package/dist/src/assets/FT.js +3 -3
  23. package/dist/src/assets/NFT.js +2 -2
  24. package/dist/src/assets/TON.js +1 -1
  25. package/dist/src/sdk/Configuration.js +11 -11
  26. package/dist/src/sdk/TACTransactionManager.js +4 -4
  27. package/dist/src/sdk/Utils.js +4 -4
  28. package/dist/src/sender/BatchSender.js +2 -1
  29. package/dist/src/structs/InternalStruct.d.ts +3 -3
  30. package/dist/src/wrappers/HighloadQueryId.d.ts +2 -0
  31. package/dist/src/wrappers/HighloadQueryId.js +7 -6
  32. package/dist/src/wrappers/HighloadWalletV3.d.ts +6 -0
  33. package/dist/src/wrappers/HighloadWalletV3.js +16 -2
  34. package/package.json +51 -21
  35. package/dist/artifacts/dev/tac/internal/scripts/utils/encoding.d.ts +0 -4
  36. package/dist/artifacts/dev/tac/internal/scripts/utils/encoding.js +0 -18
  37. package/dist/artifacts/mainnet/tac/internal/scripts/utils/encoding.d.ts +0 -4
  38. package/dist/artifacts/mainnet/tac/internal/scripts/utils/encoding.js +0 -18
  39. package/dist/artifacts/testnet/tac/internal/scripts/utils/encoding.d.ts +0 -4
  40. package/dist/artifacts/testnet/tac/internal/scripts/utils/encoding.js +0 -18
@@ -30,11 +30,11 @@ class DebugHelpers {
30
30
  try {
31
31
  switch (hook.hookType) {
32
32
  case AgnosticStructs_1.HookType.Custom:
33
- return ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(['tuple(bool,address,uint256,bytes,bytes)'], hook.hookData)[0];
33
+ return ethers_1.AbiCoder.defaultAbiCoder().decode(['tuple(bool,address,uint256,bytes,bytes)'], hook.hookData)[0];
34
34
  case AgnosticStructs_1.HookType.FullBalanceApprove:
35
- return ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(['tuple(address,address,bool)'], hook.hookData)[0];
35
+ return ethers_1.AbiCoder.defaultAbiCoder().decode(['tuple(address,address,bool)'], hook.hookData)[0];
36
36
  case AgnosticStructs_1.HookType.FullBalanceTransfer:
37
- return ethers_1.ethers.AbiCoder.defaultAbiCoder().decode(['tuple(address,address,bool)'], hook.hookData)[0];
37
+ return ethers_1.AbiCoder.defaultAbiCoder().decode(['tuple(address,address,bool)'], hook.hookData)[0];
38
38
  default:
39
39
  throw new Error(`Unknown hook type: ${hook.hookType}`);
40
40
  }
@@ -168,7 +168,7 @@ class DebugHelpers {
168
168
  hasReplacements = true;
169
169
  }
170
170
  const perspective = isFromSA ? 'Smart Account' : 'Proxy Contract';
171
- const valueStr = value > 0n ? ` (sending ${ethers_1.ethers.formatEther(value)} ETH)` : '';
171
+ const valueStr = value > 0n ? ` (sending ${(0, ethers_1.formatEther)(value)} ETH)` : '';
172
172
  const replacementStr = hasReplacements ? ' 🔄 [with dynamic value replacement]' : '';
173
173
  return `📞 Custom call to ${this._formatAddress(contractAddress)} from ${perspective}${valueStr}
174
174
  Function: ${functionDescription}${replacementStr}`;
@@ -254,7 +254,7 @@ class DebugHelpers {
254
254
  * @returns The encoded zap call that can be used as calldata in tac sdk
255
255
  */
256
256
  encodeZapCall(zapCall) {
257
- return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode([
257
+ return ethers_1.AbiCoder.defaultAbiCoder().encode([
258
258
  'tuple(' +
259
259
  'tuple(uint8,bytes)[],' + // hooks: only hookType and hookData
260
260
  'tuple(address[],tuple(address,uint256,uint256)[],bool)' + // bridgeData
@@ -24,19 +24,19 @@ class HooksHandler {
24
24
  if (dynamicReplacements && dynamicReplacements.length > 0) {
25
25
  // For now, support single replacement (can be extended)
26
26
  const replacement = dynamicReplacements[0];
27
- const replacementData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['tuple(uint16,uint16,address,address)'], [[replacement.position, replacement.len, replacement.token, replacement.balanceAddress]]);
27
+ const replacementData = ethers_1.AbiCoder.defaultAbiCoder().encode(['tuple(uint16,uint16,address,address)'], [[replacement.position, replacement.len, replacement.token, replacement.balanceAddress]]);
28
28
  // Encode as ReplacementType.Amount with the replacement data
29
- improvedMissionInfo = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['uint8', 'bytes'], [AgnosticStructs_1.ReplacementType.Amount, replacementData]);
29
+ improvedMissionInfo = ethers_1.AbiCoder.defaultAbiCoder().encode(['uint8', 'bytes'], [AgnosticStructs_1.ReplacementType.Amount, replacementData]);
30
30
  }
31
31
  const customHookData = {
32
32
  isFromSAPerspective,
33
- contractAddress: ethers_1.ethers.getAddress(contractAddress.toLowerCase()), // Normalize address to checksum format
33
+ contractAddress: (0, ethers_1.getAddress)(contractAddress.toLowerCase()), // Normalize address to checksum format
34
34
  value,
35
35
  data,
36
36
  improvedMissionInfo,
37
37
  };
38
38
  // Encode only the CustomHookData
39
- const encodedHookData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['tuple(bool,address,uint256,bytes,bytes)'], [
39
+ const encodedHookData = ethers_1.AbiCoder.defaultAbiCoder().encode(['tuple(bool,address,uint256,bytes,bytes)'], [
40
40
  [
41
41
  customHookData.isFromSAPerspective,
42
42
  customHookData.contractAddress,
@@ -64,7 +64,7 @@ class HooksHandler {
64
64
  isFromSAPerspective,
65
65
  };
66
66
  // Encode only the ApproveHookData
67
- const encodedHookData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['tuple(address,address,bool)'], [[approveHookData.token, approveHookData.to, approveHookData.isFromSAPerspective]]);
67
+ const encodedHookData = ethers_1.AbiCoder.defaultAbiCoder().encode(['tuple(address,address,bool)'], [[approveHookData.token, approveHookData.to, approveHookData.isFromSAPerspective]]);
68
68
  return {
69
69
  hookType: AgnosticStructs_1.HookType.FullBalanceApprove,
70
70
  hookData: encodedHookData,
@@ -84,7 +84,7 @@ class HooksHandler {
84
84
  isFromSAPerspective,
85
85
  };
86
86
  // Encode only the TransferHookData
87
- const encodedHookData = ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['tuple(address,address,bool)'], [[transferHookData.token, transferHookData.to, transferHookData.isFromSAPerspective]]);
87
+ const encodedHookData = ethers_1.AbiCoder.defaultAbiCoder().encode(['tuple(address,address,bool)'], [[transferHookData.token, transferHookData.to, transferHookData.isFromSAPerspective]]);
88
88
  return {
89
89
  hookType: AgnosticStructs_1.HookType.FullBalanceTransfer,
90
90
  hookData: encodedHookData,
@@ -156,11 +156,11 @@ class ReplacementHelper {
156
156
  validation.warnings.push(`⚠️ Parameter '${param.name}' might not be intended for amount replacement`);
157
157
  }
158
158
  // Check token address
159
- if (!ethers_1.ethers.isAddress(token)) {
159
+ if (!(0, ethers_1.isAddress)(token)) {
160
160
  validation.isValid = false;
161
161
  validation.warnings.push(`Invalid token address: ${token}`);
162
162
  }
163
- if (!ethers_1.ethers.isAddress(balanceAddress)) {
163
+ if (!(0, ethers_1.isAddress)(balanceAddress)) {
164
164
  validation.isValid = false;
165
165
  validation.warnings.push(`Invalid balance address: ${balanceAddress}`);
166
166
  }
@@ -58,7 +58,7 @@ class FT {
58
58
  const fromTVM = await configuration.TACParams.tokenUtils['exists(address)'](address);
59
59
  if (fromTVM) {
60
60
  const cclErc20Abi = configuration.artifacts.tac.compilationArtifacts.ICrossChainLayerERC20.abi;
61
- const erc20Token = new ethers_1.ethers.Contract(address, cclErc20Abi, configuration.TACParams.provider);
61
+ const erc20Token = new ethers_1.Contract(address, cclErc20Abi, configuration.TACParams.provider);
62
62
  const info = await erc20Token.getInfo();
63
63
  return info.tvmAddress;
64
64
  }
@@ -118,7 +118,7 @@ class FT {
118
118
  }
119
119
  // For ERC20 contracts, get decimals from contract
120
120
  const erc20TokenAbi = configuration.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi;
121
- const erc20Token = new ethers_1.ethers.Contract(evmAddress, erc20TokenAbi, configuration.TACParams.provider);
121
+ const erc20Token = new ethers_1.Contract(evmAddress, erc20TokenAbi, configuration.TACParams.provider);
122
122
  return Number(await erc20Token.decimals());
123
123
  }
124
124
  static async fromAddress(configuration, address) {
@@ -322,7 +322,7 @@ class FT {
322
322
  if (evmAddress === nativeTACAddress) {
323
323
  return this._configuration.TACParams.provider.getBalance(userAddress);
324
324
  }
325
- const erc20Token = new ethers_1.ethers.Contract(evmAddress, this._configuration.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this._configuration.TACParams.provider);
325
+ const erc20Token = new ethers_1.Contract(evmAddress, this._configuration.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this._configuration.TACParams.provider);
326
326
  return erc20Token.balanceOf(userAddress);
327
327
  }
328
328
  getTransferPayload(rawAmount, notificationReceiverAddress, responseAddress, evmData, crossChainTonAmount, forwardFeeAmount, feeData) {
@@ -100,7 +100,7 @@ class NFT {
100
100
  const exists = await configuration.TACParams.tokenUtils['exists(address)'](collectionAddress);
101
101
  if (exists) {
102
102
  const cclErc721TokenAbi = configuration.artifacts.tac.compilationArtifacts.ICrossChainLayerERC721.abi;
103
- const cclErc721Token = new ethers_1.ethers.Contract(collectionAddress, cclErc721TokenAbi, configuration.TACParams.provider);
103
+ const cclErc721Token = new ethers_1.Contract(collectionAddress, cclErc721TokenAbi, configuration.TACParams.provider);
104
104
  const info = await cclErc721Token.getInfo();
105
105
  const NFTCollectionC = configuration.artifacts.ton.wrappers.NFTCollection;
106
106
  const nftCollection = configuration.TONParams.contractOpener.open(NFTCollectionC.createFromAddress((0, ton_1.address)(info.tvmAddress)));
@@ -222,7 +222,7 @@ class NFT {
222
222
  return (await this.isOwnedBy(userAddress)) ? 1n : 0n;
223
223
  }
224
224
  Validator_1.Validator.validateEVMAddress(userAddress);
225
- const nft = new ethers_1.ethers.Contract(await this.getEVMAddress(), this._configuration.artifacts.tac.compilationArtifacts.IERC721.abi, this._configuration.TACParams.provider);
225
+ const nft = new ethers_1.Contract(await this.getEVMAddress(), this._configuration.artifacts.tac.compilationArtifacts.IERC721.abi, this._configuration.TACParams.provider);
226
226
  return (await nft.ownerOf(this._addresses.index)).toLowerCase() === userAddress.toLowerCase() ? 1n : 0n;
227
227
  }
228
228
  getBurnPayload(crossChainLayerAddress, evmData, crossChainTonAmount, feeData) {
@@ -99,7 +99,7 @@ class TON {
99
99
  return this.getUserBalance(userAddress);
100
100
  }
101
101
  Validator_1.Validator.validateEVMAddress(userAddress);
102
- const token = new ethers_1.ethers.Contract(await this.getEVMAddress(), this._config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this._config.TACParams.provider);
102
+ const token = new ethers_1.Contract(await this.getEVMAddress(), this._config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this._config.TACParams.provider);
103
103
  return token.balanceOf(userAddress);
104
104
  }
105
105
  }
@@ -117,13 +117,13 @@ class Configuration {
117
117
  saFactoryAddress = TACParams.saFactoryAddress;
118
118
  }
119
119
  else {
120
- provider = TACParams?.provider ?? ethers_1.ethers.getDefaultProvider(artifacts.TAC_RPC_ENDPOINT);
120
+ provider = TACParams?.provider ?? (0, ethers_1.getDefaultProvider)(artifacts.TAC_RPC_ENDPOINT);
121
121
  settingsAddress = TACParams?.settingsAddress ?? artifacts.TAC_SETTINGS_ADDRESS;
122
122
  saFactoryAddress = TACParams?.saFactoryAddress ?? artifacts.TAC_SMART_ACCOUNT_FACTORY_ADDRESS;
123
123
  }
124
124
  Validator_1.Validator.validateEVMAddress(settingsAddress);
125
125
  const settingsAbi = artifacts.tac.compilationArtifacts.ISettings.abi;
126
- const settings = new ethers_1.ethers.Contract(settingsAddress, settingsAbi, provider);
126
+ const settings = new ethers_1.Contract(settingsAddress, settingsAbi, provider);
127
127
  const loaded = await this.loadTACSettingsViaMulticall(network, provider, settingsAddress);
128
128
  let crossChainLayerAddress;
129
129
  let tokenUtilsAddress;
@@ -142,11 +142,11 @@ class Configuration {
142
142
  trustedTONExecutors = await settings.getTrustedTVMExecutors();
143
143
  }
144
144
  const crossChainLayerAbi = artifacts.tac.compilationArtifacts.ICrossChainLayer.abi;
145
- const crossChainLayer = new ethers_1.ethers.Contract(crossChainLayerAddress, crossChainLayerAbi, provider);
145
+ const crossChainLayer = new ethers_1.Contract(crossChainLayerAddress, crossChainLayerAbi, provider);
146
146
  const tokenUtilsAbi = artifacts.tac.compilationArtifacts.ITokenUtils.abi;
147
- const tokenUtils = new ethers_1.ethers.Contract(tokenUtilsAddress, tokenUtilsAbi, provider);
147
+ const tokenUtils = new ethers_1.Contract(tokenUtilsAddress, tokenUtilsAbi, provider);
148
148
  const TacSAFactoryAbi = artifacts.tac.compilationArtifacts.ISAFactory.abi;
149
- const smartAccountFactory = new ethers_1.ethers.Contract(saFactoryAddress, TacSAFactoryAbi, provider);
149
+ const smartAccountFactory = new ethers_1.Contract(saFactoryAddress, TacSAFactoryAbi, provider);
150
150
  return {
151
151
  provider,
152
152
  settings,
@@ -155,7 +155,7 @@ class Configuration {
155
155
  crossChainLayer,
156
156
  trustedTACExecutors,
157
157
  trustedTONExecutors,
158
- abiCoder: new ethers_1.ethers.AbiCoder(),
158
+ abiCoder: new ethers_1.AbiCoder(),
159
159
  };
160
160
  }
161
161
  static async loadTACSettingsViaMulticall(network, provider, settingsAddress) {
@@ -168,11 +168,11 @@ class Configuration {
168
168
  const multicallAbi = artifacts.tac.multicall.MULTICALL_ABI_ETHERS;
169
169
  try {
170
170
  Validator_1.Validator.validateEVMAddress(multicallAddress);
171
- const multicall = new ethers_1.ethers.Contract(multicallAddress, multicallAbi, provider);
172
- const abiCoder = new ethers_1.ethers.AbiCoder();
173
- const selectorGetAddressSetting = ethers_1.ethers.id('getAddressSetting(bytes32)').slice(0, 10);
174
- const selectorGetTrustedEVMExecutors = ethers_1.ethers.id('getTrustedEVMExecutors()').slice(0, 10);
175
- const selectorGetTrustedTVMExecutors = ethers_1.ethers.id('getTrustedTVMExecutors()').slice(0, 10);
171
+ const multicall = new ethers_1.Contract(multicallAddress, multicallAbi, provider);
172
+ const abiCoder = new ethers_1.AbiCoder();
173
+ const selectorGetAddressSetting = (0, ethers_1.id)('getAddressSetting(bytes32)').slice(0, 10);
174
+ const selectorGetTrustedEVMExecutors = (0, ethers_1.id)('getTrustedEVMExecutors()').slice(0, 10);
175
+ const selectorGetTrustedTVMExecutors = (0, ethers_1.id)('getTrustedTVMExecutors()').slice(0, 10);
176
176
  const crossChainLayerKey = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)('CrossChainLayerAddress'));
177
177
  const tokenUtilsKey = (0, ethers_1.keccak256)((0, ethers_1.toUtf8Bytes)('TokenUtilsAddress'));
178
178
  const encodeGetAddressSetting = (key) => selectorGetAddressSetting + abiCoder.encode(['bytes32'], [key]).slice(2);
@@ -74,7 +74,7 @@ class TACTransactionManager {
74
74
  const hasTransactionParams = Object.keys(transactionParams).length > 0;
75
75
  if (asset.type === Struct_1.AssetType.FT) {
76
76
  this.logger.debug(`Approving FT ${evmAddress} for ${spenderAddress}`);
77
- const contract = new ethers_1.ethers.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this.config.TACParams.provider);
77
+ const contract = new ethers_1.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this.config.TACParams.provider);
78
78
  const tx = hasTransactionParams
79
79
  ? await contract.connect(signer).approve(spenderAddress, asset.rawAmount, transactionParams)
80
80
  : await contract.connect(signer).approve(spenderAddress, asset.rawAmount);
@@ -82,7 +82,7 @@ class TACTransactionManager {
82
82
  }
83
83
  else {
84
84
  this.logger.debug(`Approving NFT ${evmAddress} for ${spenderAddress}`);
85
- const contract = new ethers_1.ethers.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC721.abi, this.config.TACParams.provider);
85
+ const contract = new ethers_1.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC721.abi, this.config.TACParams.provider);
86
86
  const tx = hasTransactionParams
87
87
  ? await contract
88
88
  .connect(signer)
@@ -95,10 +95,10 @@ class TACTransactionManager {
95
95
  async estimateApprovalGas(asset, signer, spenderAddress, transactionParams = {}) {
96
96
  const evmAddress = await asset.getEVMAddress();
97
97
  if (asset.type === Struct_1.AssetType.FT) {
98
- const contract = new ethers_1.ethers.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this.config.TACParams.provider);
98
+ const contract = new ethers_1.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC20WithDecimals.abi, this.config.TACParams.provider);
99
99
  return contract.connect(signer).approve.estimateGas(spenderAddress, asset.rawAmount, transactionParams);
100
100
  }
101
- const contract = new ethers_1.ethers.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC721.abi, this.config.TACParams.provider);
101
+ const contract = new ethers_1.Contract(evmAddress, this.config.artifacts.tac.compilationArtifacts.IERC721.abi, this.config.TACParams.provider);
102
102
  return contract
103
103
  .connect(signer)
104
104
  .approve.estimateGas(spenderAddress, asset.addresses.index, transactionParams);
@@ -88,10 +88,10 @@ function generateTransactionLinker(caller, shardCount) {
88
88
  };
89
89
  }
90
90
  function calculateEVMTokenAddress(abiCoder, tokenUtilsAddress, crossChainLayerTokenBytecode, crossChainLayerAddress, tvmAddress) {
91
- const salt = ethers_1.ethers.keccak256(ethers_1.ethers.solidityPacked(['string'], [tvmAddress]));
92
- const initCode = ethers_1.ethers.solidityPacked(['bytes', 'bytes'], [crossChainLayerTokenBytecode, abiCoder.encode(['address'], [crossChainLayerAddress])]);
93
- const initCodeHash = ethers_1.ethers.keccak256(initCode);
94
- return ethers_1.ethers.getCreate2Address(tokenUtilsAddress, salt, initCodeHash);
91
+ const salt = (0, ethers_1.keccak256)((0, ethers_1.solidityPacked)(['string'], [tvmAddress]));
92
+ const initCode = (0, ethers_1.solidityPacked)(['bytes', 'bytes'], [crossChainLayerTokenBytecode, abiCoder.encode(['address'], [crossChainLayerAddress])]);
93
+ const initCodeHash = (0, ethers_1.keccak256)(initCode);
94
+ return (0, ethers_1.getCreate2Address)(tokenUtilsAddress, salt, initCodeHash);
95
95
  }
96
96
  const snakeToCamel = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
97
97
  const convertKeysToCamelCase = (data) => {
@@ -78,7 +78,7 @@ class BatchSender {
78
78
  let validGroupFound = false;
79
79
  while (groupSize > 0) {
80
80
  const group = messages.slice(left, left + groupSize);
81
- const createdAt = Math.floor(Date.now() / 1000) - 40;
81
+ const createdAt = HighloadWalletV3_1.HighloadWalletV3.generateCreatedAt();
82
82
  const queryId = this.wallet.getQueryIdFromCreatedAt(createdAt);
83
83
  const externalMsg = this.wallet.getExternalMessage(group, ton_1.SendMode.PAY_GAS_SEPARATELY, 0n, queryId);
84
84
  const isBocSizeValid = externalMsg.body.toBoc().length <= Consts_1.MAX_EXT_MSG_SIZE;
@@ -106,6 +106,7 @@ class BatchSender {
106
106
  if (createdAt <= this.lastCreatedAt) {
107
107
  createdAt = this.lastCreatedAt + 1; // to prevent error::already_executed on highload wallet
108
108
  }
109
+ createdAt = HighloadWalletV3_1.HighloadWalletV3.normalizeCreatedAt(createdAt);
109
110
  this.lastCreatedAt = createdAt;
110
111
  return walletContract.sendTransfer({
111
112
  secretKey: this.secretKey,
@@ -1,5 +1,5 @@
1
1
  import type { Address, Cell, Message } from '@ton/ton';
2
- import { AbstractProvider, ethers } from 'ethers';
2
+ import { AbiCoder, AbstractProvider, BytesLike } from 'ethers';
3
3
  import { ICrossChainLayer, ISAFactory, ISettings, ITokenUtils } from '../../artifacts/tacTypes';
4
4
  import { ContractOpener, IToncenterV3Indexer } from '../interfaces';
5
5
  import { CurrencyType, ExecutionStagesByOperationId, ExecutionStagesV2ByOperationId, Network, OperationIdsByShardsKey, OperationIdWithLogIndex, OperationType, OperationTypeV2Info, StatusInfosByOperationId, SuggestedTVMExecutorFee, TACSimulationResult, ToncenterV3IndexedTransaction, TransactionLinker } from './Struct';
@@ -22,7 +22,7 @@ export type PreparedCrossChainTransaction = {
22
22
  transactionLinker: TransactionLinker;
23
23
  };
24
24
  export type PreparedBridgeTokensToTON = {
25
- outMessagePayload: ethers.BytesLike;
25
+ outMessagePayload: BytesLike;
26
26
  totalValue: bigint;
27
27
  };
28
28
  export declare enum AssetOpType {
@@ -56,7 +56,7 @@ export type InternalTACParams = {
56
56
  smartAccountFactory: ISAFactory;
57
57
  trustedTACExecutors: string[];
58
58
  trustedTONExecutors: string[];
59
- abiCoder: ethers.AbiCoder;
59
+ abiCoder: AbiCoder;
60
60
  };
61
61
  export type ResponseBase<T> = {
62
62
  response: T;
@@ -1,3 +1,5 @@
1
+ export declare const HIGHLOAD_QUERY_ID_BIT_NUMBER_SIZE = 10n;
2
+ export declare const HIGHLOAD_QUERY_ID_INVALID_BIT_NUMBER: bigint;
1
3
  export declare class HighloadQueryId {
2
4
  private shift;
3
5
  private bitnumber;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HighloadQueryId = void 0;
4
- const BIT_NUMBER_SIZE = 10n; // 10 bit
5
- const MAX_BIT_NUMBER = 1022n;
3
+ exports.HighloadQueryId = exports.HIGHLOAD_QUERY_ID_INVALID_BIT_NUMBER = exports.HIGHLOAD_QUERY_ID_BIT_NUMBER_SIZE = void 0;
4
+ exports.HIGHLOAD_QUERY_ID_BIT_NUMBER_SIZE = 10n;
5
+ exports.HIGHLOAD_QUERY_ID_INVALID_BIT_NUMBER = (1n << exports.HIGHLOAD_QUERY_ID_BIT_NUMBER_SIZE) - 1n;
6
+ const MAX_BIT_NUMBER = exports.HIGHLOAD_QUERY_ID_INVALID_BIT_NUMBER - 1n;
6
7
  const MAX_SHIFT = 8191n; // 2^13 = 8192
7
8
  class HighloadQueryId {
8
9
  constructor() {
@@ -49,11 +50,11 @@ class HighloadQueryId {
49
50
  return this.bitnumber;
50
51
  }
51
52
  getQueryId() {
52
- return (this.shift << BIT_NUMBER_SIZE) + this.bitnumber;
53
+ return (this.shift << exports.HIGHLOAD_QUERY_ID_BIT_NUMBER_SIZE) + this.bitnumber;
53
54
  }
54
55
  static fromQueryId(queryId) {
55
- const shift = queryId >> BIT_NUMBER_SIZE;
56
- const bitnumber = queryId & 1023n;
56
+ const shift = queryId >> exports.HIGHLOAD_QUERY_ID_BIT_NUMBER_SIZE;
57
+ const bitnumber = queryId & exports.HIGHLOAD_QUERY_ID_INVALID_BIT_NUMBER;
57
58
  return this.fromShiftAndBitNumber(shift, bitnumber);
58
59
  }
59
60
  static fromSeqno(i) {
@@ -38,6 +38,12 @@ export declare class HighloadWalletV3 implements WalletInstanse {
38
38
  }): Promise<string>;
39
39
  static create(config: HighloadWalletV3Config, code?: Cell, workchain?: number): HighloadWalletV3;
40
40
  static generateCreatedAt(): number;
41
+ /**
42
+ * The Highload V3 contract accepts bitnumber values [0..1022]. Query IDs
43
+ * are derived from createdAt, so skip timestamps whose low 10 bits are the
44
+ * invalid value 1023.
45
+ */
46
+ static normalizeCreatedAt(createdAt: number): number;
41
47
  sendExternalMessage(provider: ContractProvider, secretKey: Buffer, opts: {
42
48
  message: MessageRelaxed | Cell;
43
49
  mode: number;
@@ -14,6 +14,7 @@ exports.DEFAULT_TIMEOUT = 60 * 60; // 1 hour
14
14
  const HIGHLOAD_V3_CODE = ton_1.Cell.fromBoc(Buffer.from('b5ee9c7241021001000228000114ff00f4a413f4bcf2c80b01020120020d02014803040078d020d74bc00101c060b0915be101d0d3030171b0915be0fa4030f828c705b39130e0d31f018210ae42e5a4ba9d8040d721d74cf82a01ed55fb04e030020120050a02027306070011adce76a2686b85ffc00201200809001aabb6ed44d0810122d721d70b3f0018aa3bed44d08307d721d70b1f0201200b0c001bb9a6eed44d0810162d721d70b15800e5b8bf2eda2edfb21ab09028409b0ed44d0810120d721f404f404d33fd315d1058e1bf82325a15210b99f326df82305aa0015a112b992306dde923033e2923033e25230800df40f6fa19ed021d721d70a00955f037fdb31e09130e259800df40f6fa19cd001d721d70a00937fdb31e0915be270801f6f2d48308d718d121f900ed44d0d3ffd31ff404f404d33fd315d1f82321a15220b98e12336df82324aa00a112b9926d32de58f82301de541675f910f2a106d0d31fd4d307d30cd309d33fd315d15168baf2a2515abaf2a6f8232aa15250bcf2a304f823bbf2a35304800df40f6fa199d024d721d70a00f2649130e20e01fe5309800df40f6fa18e13d05004d718d20001f264c858cf16cf8301cf168e1030c824cf40cf8384095005a1a514cf40e2f800c94039800df41704c8cbff13cb1ff40012f40012cb3f12cb15c9ed54f80f21d0d30001f265d3020171b0925f03e0fa4001d70b01c000f2a5fa4031fa0031f401fa0031fa00318060d721d300010f0020f265d2000193d431d19130e272b1fb00b585bf03', 'hex'))[0];
15
15
  exports.TIMESTAMP_SIZE = 64;
16
16
  exports.TIMEOUT_SIZE = 22;
17
+ const QUERY_ID_PERIOD = 8388608n; // 2^23
17
18
  function highloadWalletV3ConfigToCell(config) {
18
19
  return (0, ton_1.beginCell)()
19
20
  .storeBuffer(config.publicKey)
@@ -57,7 +58,19 @@ class HighloadWalletV3 {
57
58
  return new HighloadWalletV3((0, ton_1.contractAddress)(workchain, init), init);
58
59
  }
59
60
  static generateCreatedAt() {
60
- return Math.floor(Date.now() / 1000) - 40; // -40 is used to pass check created_at <= now() in smart contract for sure
61
+ // -40 is used to pass check created_at <= now() in smart contract for sure
62
+ return HighloadWalletV3.normalizeCreatedAt(Math.floor(Date.now() / 1000) - 40);
63
+ }
64
+ /**
65
+ * The Highload V3 contract accepts bitnumber values [0..1022]. Query IDs
66
+ * are derived from createdAt, so skip timestamps whose low 10 bits are the
67
+ * invalid value 1023.
68
+ */
69
+ static normalizeCreatedAt(createdAt) {
70
+ const queryId = BigInt(createdAt) % QUERY_ID_PERIOD;
71
+ return (queryId & HighloadQueryId_1.HIGHLOAD_QUERY_ID_INVALID_BIT_NUMBER) === HighloadQueryId_1.HIGHLOAD_QUERY_ID_INVALID_BIT_NUMBER
72
+ ? createdAt + 1
73
+ : createdAt;
61
74
  }
62
75
  async sendExternalMessage(provider, secretKey, opts) {
63
76
  let messageCell;
@@ -89,6 +102,7 @@ class HighloadWalletV3 {
89
102
  if (createdAt == undefined) {
90
103
  createdAt = HighloadWalletV3.generateCreatedAt();
91
104
  }
105
+ createdAt = HighloadWalletV3.normalizeCreatedAt(createdAt);
92
106
  const queryId = this.getQueryIdFromCreatedAt(createdAt);
93
107
  return await this.sendExternalMessage(provider, secretKey, {
94
108
  message: this.packActions(messages, value, queryId),
@@ -100,7 +114,7 @@ class HighloadWalletV3 {
100
114
  });
101
115
  }
102
116
  getQueryIdFromCreatedAt(createdAt) {
103
- return HighloadQueryId_1.HighloadQueryId.fromQueryId(BigInt(createdAt) % 8388608n);
117
+ return HighloadQueryId_1.HighloadQueryId.fromQueryId(BigInt(createdAt) % QUERY_ID_PERIOD);
104
118
  }
105
119
  getExternalMessage(messages, sendMode, value, queryId) {
106
120
  return this.packActions(messages.map((msg) => ({
package/package.json CHANGED
@@ -1,26 +1,38 @@
1
1
  {
2
2
  "name": "@tonappchain/sdk",
3
- "version": "0.8.1-rc1",
3
+ "version": "0.9.0-rc2",
4
4
  "repository": "https://github.com/TacBuild/tac-sdk.git",
5
5
  "author": "TAC. <developers@tac>",
6
6
  "license": "MIT",
7
7
  "main": "dist/src/index.js",
8
+ "module": "dist/esm/src/index.mjs",
8
9
  "types": "dist/src/index.d.ts",
9
10
  "exports": {
10
11
  ".": {
11
12
  "node": {
12
- "types": "./dist/src/index.d.ts",
13
- "require": "./dist/src/index.js",
14
- "import": "./dist/src/index.js"
13
+ "import": {
14
+ "types": "./dist/esm/src/index.d.mts",
15
+ "default": "./dist/esm/src/index.mjs"
16
+ },
17
+ "require": {
18
+ "types": "./dist/src/index.d.ts",
19
+ "default": "./dist/src/index.js"
20
+ }
15
21
  },
16
22
  "browser": {
17
- "types": "./dist/src/index.d.ts",
18
- "import": "./dist/src/index.js"
23
+ "import": {
24
+ "types": "./dist/esm/src/index.d.mts",
25
+ "default": "./dist/esm/src/index.mjs"
26
+ }
27
+ },
28
+ "import": {
29
+ "types": "./dist/esm/src/index.d.mts",
30
+ "default": "./dist/esm/src/index.mjs"
19
31
  },
20
- "types": "./dist/src/index.d.ts",
21
- "require": "./dist/src/index.js",
22
- "import": "./dist/src/index.js",
23
- "default": "./dist/src/index.js"
32
+ "require": {
33
+ "types": "./dist/src/index.d.ts",
34
+ "default": "./dist/src/index.js"
35
+ }
24
36
  },
25
37
  "./package.json": "./package.json",
26
38
  "./dist": null,
@@ -28,19 +40,34 @@
28
40
  "./src": null,
29
41
  "./src/*": null,
30
42
  "./artifacts": {
31
- "types": "./dist/artifacts/index.d.ts",
32
- "import": "./dist/artifacts/index.js",
33
- "require": "./dist/artifacts/index.js"
43
+ "import": {
44
+ "types": "./dist/esm/artifacts/index.d.mts",
45
+ "default": "./dist/esm/artifacts/index.mjs"
46
+ },
47
+ "require": {
48
+ "types": "./dist/artifacts/index.d.ts",
49
+ "default": "./dist/artifacts/index.js"
50
+ }
34
51
  },
35
52
  "./artifacts/types/ton": {
36
- "types": "./dist/artifacts/tonTypes.d.ts",
37
- "import": "./dist/artifacts/tonTypes.js",
38
- "require": "./dist/artifacts/tonTypes.js"
53
+ "import": {
54
+ "types": "./dist/esm/artifacts/tonTypes.d.mts",
55
+ "default": "./dist/esm/artifacts/tonTypes.mjs"
56
+ },
57
+ "require": {
58
+ "types": "./dist/artifacts/tonTypes.d.ts",
59
+ "default": "./dist/artifacts/tonTypes.js"
60
+ }
39
61
  },
40
62
  "./artifacts/types/tac": {
41
- "types": "./dist/artifacts/tacTypes.d.ts",
42
- "import": "./dist/artifacts/tacTypes.js",
43
- "require": "./dist/artifacts/tacTypes.js"
63
+ "import": {
64
+ "types": "./dist/esm/artifacts/tacTypes.d.mts",
65
+ "default": "./dist/esm/artifacts/tacTypes.mjs"
66
+ },
67
+ "require": {
68
+ "types": "./dist/artifacts/tacTypes.d.ts",
69
+ "default": "./dist/artifacts/tacTypes.js"
70
+ }
44
71
  },
45
72
  "./artifacts/*": null,
46
73
  "./*": null
@@ -49,8 +76,9 @@
49
76
  "dist"
50
77
  ],
51
78
  "scripts": {
52
- "litebuild": "rm -rf dist && tsc --declaration",
79
+ "litebuild": "rm -rf dist && tsc --declaration && npm run build:esm",
53
80
  "build": "bash build.sh",
81
+ "build:esm": "esbuild src/index.ts artifacts/index.ts artifacts/tonTypes.ts artifacts/tacTypes.ts --bundle --format=esm --platform=neutral --target=es2020 --packages=external --outdir=dist/esm --outbase=. --out-extension:.js=.mjs --splitting && cp -R esm-types/. dist/esm",
54
82
  "build:artifacts:tac:dev": "cd artifacts/dev/l2-evm && npm i && npx hardhat compile && rsync -avh --delete ./artifacts ./scripts ./typechain-types ../tac/internal/",
55
83
  "build:artifacts:ton:dev": "cd artifacts/dev/l1_tvm_ton && npm i && npm run compile:ts && npm run build:all && rsync -avh --delete ./build ./wrappers ../ton/internal/",
56
84
  "build:artifacts:tac:testnet": "cd artifacts/testnet/l2-evm && npm i && npx hardhat compile && rsync -avh --delete ./artifacts ./scripts ./typechain-types ../tac/internal/",
@@ -60,7 +88,8 @@
60
88
  "build:artifacts:ton:all": "npm run build:artifacts:ton:dev && npm run build:artifacts:ton:testnet && npm run build:artifacts:ton:mainnet",
61
89
  "build:artifacts:tac:all": "npm run build:artifacts:tac:dev && npm run build:artifacts:tac:testnet && npm run build:artifacts:tac:mainnet",
62
90
  "build:artifacts": "npm run build:artifacts:ton:all && npm run build:artifacts:tac:all",
63
- "test": "jest --verbose --runInBand",
91
+ "test": "npm run test:package && jest --verbose --runInBand",
92
+ "test:package": "npm run litebuild && node --test tests/package/modules.test.mjs && tsc -p tests/package/tsconfig.json && tsc -p tests/package/tsconfig.bundler.json",
64
93
  "test:ton-providers": "RUN_TON_PROVIDER_TESTS=1 jest --verbose --runInBand tests/ton_providers",
65
94
  "test:toncenter-v2-tree": "RUN_TON_PROVIDER_TESTS=1 jest --verbose --runInBand tests/ton_providers/contractOpeners/toncenterV2HistoricalTree.spec.ts",
66
95
  "release": "npm run build && npx release-it",
@@ -99,6 +128,7 @@
99
128
  "@tonconnect/ui": "^3.0.0",
100
129
  "@types/bn.js": "^5.1.6",
101
130
  "@types/jest": "^29.5.14",
131
+ "esbuild": "^0.28.1",
102
132
  "eslint": "^9.26.0",
103
133
  "eslint-config-prettier": "^10.0.2",
104
134
  "eslint-plugin-simple-import-sort": "^12.1.1",
@@ -1,4 +0,0 @@
1
- import { BytesLike } from "ethers";
2
- import { InMessageV1Struct, OutMessageV1Struct } from "../../typechain-types/contracts/core/Structs.sol/IStructsInterface";
3
- export declare function encodeInMessageV1(inMessage: InMessageV1Struct): BytesLike;
4
- export declare function encodeOutMessageV1(outMessage: OutMessageV1Struct): BytesLike;
@@ -1,18 +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.encodeInMessageV1 = encodeInMessageV1;
7
- exports.encodeOutMessageV1 = encodeOutMessageV1;
8
- const ethers_1 = require("ethers");
9
- const IStructsInterface_json_1 = __importDefault(require("../../artifacts/contracts/core/Structs.sol/IStructsInterface.json"));
10
- const structsInterface = new ethers_1.ethers.Interface(IStructsInterface_json_1.default.abi);
11
- function encodeInMessageV1(inMessage) {
12
- const encodedCall = ethers_1.ethers.getBytes(structsInterface.encodeFunctionData("__InMessageV1", [inMessage]));
13
- return ethers_1.ethers.hexlify(encodedCall.slice(4));
14
- }
15
- function encodeOutMessageV1(outMessage) {
16
- const encodedCall = ethers_1.ethers.getBytes(structsInterface.encodeFunctionData("__OutMessageV1", [outMessage]));
17
- return ethers_1.ethers.hexlify(encodedCall.slice(4));
18
- }
@@ -1,4 +0,0 @@
1
- import { BytesLike } from "ethers";
2
- import { InMessageV1Struct, OutMessageV1Struct } from "../../typechain-types/contracts/core/Structs.sol/IStructsInterface";
3
- export declare function encodeInMessageV1(inMessage: InMessageV1Struct): BytesLike;
4
- export declare function encodeOutMessageV1(outMessage: OutMessageV1Struct): BytesLike;
@@ -1,18 +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.encodeInMessageV1 = encodeInMessageV1;
7
- exports.encodeOutMessageV1 = encodeOutMessageV1;
8
- const ethers_1 = require("ethers");
9
- const IStructsInterface_json_1 = __importDefault(require("../../artifacts/contracts/core/Structs.sol/IStructsInterface.json"));
10
- const structsInterface = new ethers_1.ethers.Interface(IStructsInterface_json_1.default.abi);
11
- function encodeInMessageV1(inMessage) {
12
- const encodedCall = ethers_1.ethers.getBytes(structsInterface.encodeFunctionData("__InMessageV1", [inMessage]));
13
- return ethers_1.ethers.hexlify(encodedCall.slice(4));
14
- }
15
- function encodeOutMessageV1(outMessage) {
16
- const encodedCall = ethers_1.ethers.getBytes(structsInterface.encodeFunctionData("__OutMessageV1", [outMessage]));
17
- return ethers_1.ethers.hexlify(encodedCall.slice(4));
18
- }
@@ -1,4 +0,0 @@
1
- import { BytesLike } from "ethers";
2
- import { InMessageV1Struct, OutMessageV1Struct } from "../../typechain-types/contracts/core/Structs.sol/IStructsInterface";
3
- export declare function encodeInMessageV1(inMessage: InMessageV1Struct): BytesLike;
4
- export declare function encodeOutMessageV1(outMessage: OutMessageV1Struct): BytesLike;
@@ -1,18 +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.encodeInMessageV1 = encodeInMessageV1;
7
- exports.encodeOutMessageV1 = encodeOutMessageV1;
8
- const ethers_1 = require("ethers");
9
- const IStructsInterface_json_1 = __importDefault(require("../../artifacts/contracts/core/Structs.sol/IStructsInterface.json"));
10
- const structsInterface = new ethers_1.ethers.Interface(IStructsInterface_json_1.default.abi);
11
- function encodeInMessageV1(inMessage) {
12
- const encodedCall = ethers_1.ethers.getBytes(structsInterface.encodeFunctionData("__InMessageV1", [inMessage]));
13
- return ethers_1.ethers.hexlify(encodedCall.slice(4));
14
- }
15
- function encodeOutMessageV1(outMessage) {
16
- const encodedCall = ethers_1.ethers.getBytes(structsInterface.encodeFunctionData("__OutMessageV1", [outMessage]));
17
- return ethers_1.ethers.hexlify(encodedCall.slice(4));
18
- }