@tonappchain/sdk 0.7.2-scaled-ui-support-1 → 0.7.2-scaled-ui-support-2

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.
@@ -14,8 +14,10 @@ export declare class FT implements Asset {
14
14
  private _decimals;
15
15
  private _transferAmount;
16
16
  private _evmAddress?;
17
- private _displayMultiplierNumerator?;
18
- private _displayMultiplierDenominator?;
17
+ private _displayMultiplierNumerator;
18
+ private _displayMultiplierDenominator;
19
+ private _displayMultiplierFetchedAt;
20
+ private _displayMultiplierCacheDuration;
19
21
  get address(): string;
20
22
  static getJettonData(configuration: IConfiguration, address: TVMAddress): Promise<JettonMinterData>;
21
23
  getJettonData(): Promise<JettonMinterData>;
@@ -32,15 +34,13 @@ export declare class FT implements Asset {
32
34
  withRawAmount(rawAmount: bigint): FT;
33
35
  addAmount(amount: number): FT;
34
36
  addRawAmount(rawAmount: bigint): FT;
35
- withDisplayAmount(displayAmount: bigint): Promise<FT>;
36
- addDisplayAmount(displayAmount: bigint): Promise<FT>;
37
37
  getDecimals(): Promise<number>;
38
- getDisplayMultiplier(): Promise<{
39
- numerator: bigint;
40
- denominator: bigint;
41
- }>;
42
- toDisplayAmount(onchainAmount: bigint): Promise<bigint>;
43
- fromDisplayAmount(displayAmount: bigint): Promise<bigint>;
38
+ private refreshDisplayMultiplierInternal;
39
+ private ensureFreshDisplayMultiplier;
40
+ refreshDisplayMultiplier(): Promise<void>;
41
+ setDisplayMultiplierCacheDuration(durationMs: number): void;
42
+ toDisplayAmount(onchainAmount: bigint): bigint;
43
+ fromDisplayAmount(displayAmount: bigint): bigint;
44
44
  getEVMAddress(): Promise<string>;
45
45
  getTVMAddress(): Promise<string>;
46
46
  generatePayload(params: {
@@ -85,6 +85,10 @@ class FT {
85
85
  }
86
86
  constructor(address, origin, configuration, decimals) {
87
87
  this.type = Struct_1.AssetType.FT;
88
+ this._displayMultiplierNumerator = 1n;
89
+ this._displayMultiplierDenominator = 1n;
90
+ this._displayMultiplierFetchedAt = 0;
91
+ this._displayMultiplierCacheDuration = Consts_1.FIVE_MINUTES;
88
92
  this._tvmAddress = ton_1.Address.parse(address);
89
93
  this._configuration = configuration;
90
94
  this._jettonMinter = this._configuration.TONParams.contractOpener.open(configuration.artifacts.ton.wrappers.JettonMinter.createFromAddress(this._tvmAddress));
@@ -137,6 +141,8 @@ class FT {
137
141
  if (finalEvmAddress || (0, ethers_1.isAddress)(address)) {
138
142
  token._evmAddress = finalEvmAddress || address;
139
143
  }
144
+ // Fetch and cache display multiplier for TEP-526 support
145
+ await token.refreshDisplayMultiplierInternal();
140
146
  return token;
141
147
  }
142
148
  get rawAmount() {
@@ -148,15 +154,19 @@ class FT {
148
154
  ft._evmAddress = this._evmAddress;
149
155
  ft._displayMultiplierNumerator = this._displayMultiplierNumerator;
150
156
  ft._displayMultiplierDenominator = this._displayMultiplierDenominator;
157
+ ft._displayMultiplierFetchedAt = this._displayMultiplierFetchedAt;
158
+ ft._displayMultiplierCacheDuration = this._displayMultiplierCacheDuration;
151
159
  return ft;
152
160
  }
153
161
  withAmount(amount) {
162
+ const rawAmount = (0, Utils_1.calculateRawAmount)(amount, this._decimals);
163
+ const onchainAmount = this.fromDisplayAmount(rawAmount);
154
164
  if (this._transferAmount > 0n) {
155
165
  const newToken = this.clone;
156
- newToken._transferAmount = (0, Utils_1.calculateRawAmount)(amount, this._decimals);
166
+ newToken._transferAmount = onchainAmount;
157
167
  return newToken;
158
168
  }
159
- this._transferAmount = (0, Utils_1.calculateRawAmount)(amount, this._decimals);
169
+ this._transferAmount = onchainAmount;
160
170
  return this;
161
171
  }
162
172
  withRawAmount(rawAmount) {
@@ -169,60 +179,48 @@ class FT {
169
179
  return this;
170
180
  }
171
181
  addAmount(amount) {
172
- this._transferAmount = this._transferAmount + (0, Utils_1.calculateRawAmount)(amount, this._decimals);
182
+ const rawAmount = (0, Utils_1.calculateRawAmount)(amount, this._decimals);
183
+ const onchainAmount = this.fromDisplayAmount(rawAmount);
184
+ this._transferAmount = this._transferAmount + onchainAmount;
173
185
  return this;
174
186
  }
175
187
  addRawAmount(rawAmount) {
176
188
  this._transferAmount = this._transferAmount + rawAmount;
177
189
  return this;
178
190
  }
179
- async withDisplayAmount(displayAmount) {
180
- const onchainAmount = await this.fromDisplayAmount(displayAmount);
181
- if (this._transferAmount > 0n) {
182
- const newToken = this.clone;
183
- newToken._transferAmount = onchainAmount;
184
- return newToken;
185
- }
186
- this._transferAmount = onchainAmount;
187
- return this;
188
- }
189
- async addDisplayAmount(displayAmount) {
190
- const onchainAmount = await this.fromDisplayAmount(displayAmount);
191
- this._transferAmount = this._transferAmount + onchainAmount;
192
- return this;
193
- }
194
191
  async getDecimals() {
195
192
  return this._decimals;
196
193
  }
197
- async getDisplayMultiplier() {
198
- // Return cached values if available
199
- if (this._displayMultiplierNumerator !== undefined && this._displayMultiplierDenominator !== undefined) {
200
- return {
201
- numerator: this._displayMultiplierNumerator,
202
- denominator: this._displayMultiplierDenominator,
203
- };
204
- }
205
- // Fetch and cache the multiplier
194
+ async refreshDisplayMultiplierInternal() {
206
195
  try {
207
196
  const multiplier = await this._jettonMinter.getDisplayMultiplier();
208
197
  this._displayMultiplierNumerator = multiplier.numerator;
209
198
  this._displayMultiplierDenominator = multiplier.denominator;
210
- return multiplier;
199
+ this._displayMultiplierFetchedAt = Date.now();
211
200
  }
212
201
  catch {
213
- // If the method doesn't exist or fails, assume no scaling (1:1)
214
202
  this._displayMultiplierNumerator = 1n;
215
203
  this._displayMultiplierDenominator = 1n;
216
- return { numerator: 1n, denominator: 1n };
204
+ this._displayMultiplierFetchedAt = Date.now();
217
205
  }
218
206
  }
219
- async toDisplayAmount(onchainAmount) {
220
- const { numerator, denominator } = await this.getDisplayMultiplier();
221
- return (0, Utils_1.muldivr)(onchainAmount, numerator, denominator);
207
+ async ensureFreshDisplayMultiplier() {
208
+ const age = Date.now() - this._displayMultiplierFetchedAt;
209
+ if (age > this._displayMultiplierCacheDuration) {
210
+ await this.refreshDisplayMultiplierInternal();
211
+ }
212
+ }
213
+ async refreshDisplayMultiplier() {
214
+ await this.refreshDisplayMultiplierInternal();
215
+ }
216
+ setDisplayMultiplierCacheDuration(durationMs) {
217
+ this._displayMultiplierCacheDuration = durationMs;
218
+ }
219
+ toDisplayAmount(onchainAmount) {
220
+ return (0, Utils_1.muldivr)(onchainAmount, this._displayMultiplierNumerator, this._displayMultiplierDenominator);
222
221
  }
223
- async fromDisplayAmount(displayAmount) {
224
- const { numerator, denominator } = await this.getDisplayMultiplier();
225
- return (0, Utils_1.muldivr)(displayAmount, denominator, numerator);
222
+ fromDisplayAmount(displayAmount) {
223
+ return (0, Utils_1.muldivr)(displayAmount, this._displayMultiplierDenominator, this._displayMultiplierNumerator);
226
224
  }
227
225
  async getEVMAddress() {
228
226
  if (this._evmAddress) {
@@ -269,10 +267,12 @@ class FT {
269
267
  return (await this._jettonMinter.getWalletAddress(ton_1.Address.parse(userAddress))).toString({ bounceable: true });
270
268
  }
271
269
  async getUserBalance(userAddress) {
270
+ await this.ensureFreshDisplayMultiplier();
272
271
  const wallet = await this.getWallet(userAddress);
273
272
  return BigInt(await wallet.getJettonBalance());
274
273
  }
275
274
  async getUserBalanceExtended(userAddress) {
275
+ await this.ensureFreshDisplayMultiplier();
276
276
  const masterState = await this._configuration.TONParams.contractOpener.getContractState(this._tvmAddress);
277
277
  if (masterState.state !== 'active') {
278
278
  return { exists: false };
@@ -283,7 +283,7 @@ class FT {
283
283
  return {
284
284
  rawAmount,
285
285
  decimals,
286
- amount: (0, Utils_1.calculateAmount)(rawAmount, decimals),
286
+ amount: (0, Utils_1.calculateAmount)(this.toDisplayAmount(rawAmount), decimals),
287
287
  exists: true,
288
288
  };
289
289
  }
@@ -8,6 +8,7 @@ export interface Asset {
8
8
  /**
9
9
  * Returns a new asset instance with the specified transfer amount in human-readable units.
10
10
  * Does not mutate the current asset instance.
11
+ * For FT assets, this applies TEP-526 scaling automatically if supported by the token.
11
12
  * @param amount Amount in human units (e.g., 1.5 TON). Decimals are resolved during asset creation.
12
13
  * @returns A new Asset reflecting the requested amount.
13
14
  */
@@ -15,6 +16,7 @@ export interface Asset {
15
16
  /**
16
17
  * Returns a new asset instance with the specified transfer amount in raw base units.
17
18
  * Does not mutate the current asset instance.
19
+ * No TEP-526 scaling is applied - sets the raw onchain amount directly.
18
20
  * @param rawAmount Amount in raw base units (bigint).
19
21
  * @returns A new Asset reflecting the requested raw amount.
20
22
  */
@@ -22,6 +24,7 @@ export interface Asset {
22
24
  /**
23
25
  * Increases the transfer amount by the specified value (human-readable units) and returns a new asset instance.
24
26
  * Does not mutate the current asset instance.
27
+ * For FT assets, this applies TEP-526 scaling automatically if supported by the token.
25
28
  * @param amount Amount in human units (e.g., 1.5 TON). Decimals are resolved during asset creation.
26
29
  * @returns A new Asset with the increased amount.
27
30
  */
@@ -29,6 +32,7 @@ export interface Asset {
29
32
  /**
30
33
  * Increases the transfer amount by the specified raw base units and returns a new asset instance.
31
34
  * Does not mutate the current asset instance.
35
+ * No TEP-526 scaling is applied - adds to the raw onchain amount directly.
32
36
  * @param rawAmount Amount in raw base units (bigint).
33
37
  * @returns A new Asset with the increased amount in raw units.
34
38
  */
@@ -13,3 +13,4 @@ export declare const TAC_SYMBOL = "TAC";
13
13
  export declare const FIFTEEN_MINUTES: number;
14
14
  export declare const TON_DECIMALS = 9;
15
15
  export declare const TAC_DECIMALS = 18;
16
+ export declare const FIVE_MINUTES: number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TAC_DECIMALS = exports.TON_DECIMALS = exports.FIFTEEN_MINUTES = exports.TAC_SYMBOL = exports.TON_SYMBOL = exports.MAX_MSG_DEPTH = exports.MAX_HIGHLOAD_GROUP_MSG_NUM = exports.MAX_EXT_MSG_SIZE = exports.SOLIDITY_METHOD_NAME_REGEX = exports.SOLIDITY_SIGNATURE_REGEX = exports.DEFAULT_DELAY = exports.MAX_ITERATION_COUNT = exports.NFT_TRANSFER_FORWARD_TON_AMOUNT = exports.JETTON_TRANSFER_FORWARD_TON_AMOUNT = exports.TRANSACTION_TON_AMOUNT = void 0;
3
+ exports.FIVE_MINUTES = exports.TAC_DECIMALS = exports.TON_DECIMALS = exports.FIFTEEN_MINUTES = exports.TAC_SYMBOL = exports.TON_SYMBOL = exports.MAX_MSG_DEPTH = exports.MAX_HIGHLOAD_GROUP_MSG_NUM = exports.MAX_EXT_MSG_SIZE = exports.SOLIDITY_METHOD_NAME_REGEX = exports.SOLIDITY_SIGNATURE_REGEX = exports.DEFAULT_DELAY = exports.MAX_ITERATION_COUNT = exports.NFT_TRANSFER_FORWARD_TON_AMOUNT = exports.JETTON_TRANSFER_FORWARD_TON_AMOUNT = exports.TRANSACTION_TON_AMOUNT = void 0;
4
4
  const ton_1 = require("@ton/ton");
5
5
  exports.TRANSACTION_TON_AMOUNT = (0, ton_1.toNano)(0.55);
6
6
  exports.JETTON_TRANSFER_FORWARD_TON_AMOUNT = (0, ton_1.toNano)(0.2);
@@ -17,3 +17,4 @@ exports.TAC_SYMBOL = 'TAC';
17
17
  exports.FIFTEEN_MINUTES = 15 * 60 * 1000;
18
18
  exports.TON_DECIMALS = 9;
19
19
  exports.TAC_DECIMALS = 18;
20
+ exports.FIVE_MINUTES = 5 * 60 * 1000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonappchain/sdk",
3
- "version": "0.7.2-scaled-ui-support-1",
3
+ "version": "0.7.2-scaled-ui-support-2",
4
4
  "repository": "https://github.com/TacBuild/tac-sdk.git",
5
5
  "author": "TAC. <developers@tac>",
6
6
  "license": "MIT",