@t2000/sdk 0.18.35 → 0.18.37

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/dist/index.d.cts CHANGED
@@ -614,6 +614,8 @@ interface GasExecutionResult {
614
614
  effects: unknown;
615
615
  gasMethod: GasMethod;
616
616
  gasCostSui: number;
617
+ /** Pre-TX SUI balance in MIST — used internally for proactive gas maintenance. */
618
+ preTxSuiMist?: bigint;
617
619
  }
618
620
  /**
619
621
  * Gas resolution chain:
package/dist/index.d.ts CHANGED
@@ -614,6 +614,8 @@ interface GasExecutionResult {
614
614
  effects: unknown;
615
615
  gasMethod: GasMethod;
616
616
  gasCostSui: number;
617
+ /** Pre-TX SUI balance in MIST — used internally for proactive gas maintenance. */
618
+ preTxSuiMist?: bigint;
617
619
  }
618
620
  /**
619
621
  * Gas resolution chain:
package/dist/index.js CHANGED
@@ -56158,7 +56158,8 @@ async function trySelfFunded(client, keypair, tx) {
56158
56158
  digest: result.digest,
56159
56159
  effects: result.effects,
56160
56160
  gasMethod: "self-funded",
56161
- gasCostSui: extractGasCost(result.effects)
56161
+ gasCostSui: extractGasCost(result.effects),
56162
+ preTxSuiMist: suiBalance
56162
56163
  };
56163
56164
  }
56164
56165
  async function tryAutoTopUpThenSelfFund(client, keypair, buildTx) {
@@ -56168,6 +56169,7 @@ async function tryAutoTopUpThenSelfFund(client, keypair, buildTx) {
56168
56169
  await executeAutoTopUp(client, keypair);
56169
56170
  const tx = await buildTx();
56170
56171
  tx.setSender(address);
56172
+ const suiAfterTopUp = await getSuiBalance(client, address);
56171
56173
  const result = await client.signAndExecuteTransaction({
56172
56174
  signer: keypair,
56173
56175
  transaction: tx,
@@ -56179,11 +56181,13 @@ async function tryAutoTopUpThenSelfFund(client, keypair, buildTx) {
56179
56181
  digest: result.digest,
56180
56182
  effects: result.effects,
56181
56183
  gasMethod: "auto-topup",
56182
- gasCostSui: extractGasCost(result.effects)
56184
+ gasCostSui: extractGasCost(result.effects),
56185
+ preTxSuiMist: suiAfterTopUp
56183
56186
  };
56184
56187
  }
56185
56188
  async function trySponsored(client, keypair, tx) {
56186
56189
  const address = keypair.getPublicKey().toSuiAddress();
56190
+ const suiBalance = await getSuiBalance(client, address);
56187
56191
  tx.setSender(address);
56188
56192
  let txJson;
56189
56193
  let txBcsBase64;
@@ -56209,7 +56213,8 @@ async function trySponsored(client, keypair, tx) {
56209
56213
  digest: result.digest,
56210
56214
  effects: result.effects,
56211
56215
  gasMethod: "sponsored",
56212
- gasCostSui: gasCost
56216
+ gasCostSui: gasCost,
56217
+ preTxSuiMist: suiBalance
56213
56218
  };
56214
56219
  }
56215
56220
  async function waitForIndexer(client, digest) {
@@ -56228,9 +56233,19 @@ async function executeWithGas(client, keypair, buildTx, options) {
56228
56233
  }
56229
56234
  const result = await resolveGas(client, keypair, buildTx);
56230
56235
  try {
56231
- const address = keypair.getPublicKey().toSuiAddress();
56232
- if (await shouldAutoTopUp(client, address)) {
56233
- await executeAutoTopUp(client, keypair);
56236
+ if (result.preTxSuiMist !== void 0) {
56237
+ const gasCostMist = result.gasMethod === "sponsored" ? 0n : BigInt(Math.round(result.gasCostSui * 1e9));
56238
+ const estimatedRemaining = result.preTxSuiMist - gasCostMist;
56239
+ if (estimatedRemaining < AUTO_TOPUP_THRESHOLD) {
56240
+ const address = keypair.getPublicKey().toSuiAddress();
56241
+ const usdcBal = await client.getBalance({
56242
+ owner: address,
56243
+ coinType: SUPPORTED_ASSETS.USDC.type
56244
+ });
56245
+ if (BigInt(usdcBal.totalBalance) >= AUTO_TOPUP_MIN_USDC) {
56246
+ await executeAutoTopUp(client, keypair);
56247
+ }
56248
+ }
56234
56249
  }
56235
56250
  } catch {
56236
56251
  }
@@ -57988,6 +58003,13 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
57988
58003
  throw new T2000Error("ASSET_NOT_SUPPORTED", `${params.asset} is not available for investment`);
57989
58004
  }
57990
58005
  const bal = await queryBalance(this.client, this._address);
58006
+ const totalFunds = bal.available + bal.savings;
58007
+ if (params.usdAmount > totalFunds * 1.05) {
58008
+ throw new T2000Error(
58009
+ "INSUFFICIENT_BALANCE",
58010
+ `Insufficient funds. You have $${totalFunds.toFixed(2)} total (checking: $${bal.available.toFixed(2)}, savings: $${bal.savings.toFixed(2)}) but need $${params.usdAmount.toFixed(2)}.`
58011
+ );
58012
+ }
57991
58013
  if (bal.available < params.usdAmount) {
57992
58014
  await this._autoFundFromSavings(params.usdAmount - bal.available);
57993
58015
  }
@@ -58433,6 +58455,13 @@ To sell investment: t2000 invest sell ${params.amount} ${fromAsset}`,
58433
58455
  }
58434
58456
  this.enforcer.check({ operation: "invest", amount: params.usdAmount });
58435
58457
  const bal = await queryBalance(this.client, this._address);
58458
+ const totalFunds = bal.available + bal.savings;
58459
+ if (params.usdAmount > totalFunds * 1.05) {
58460
+ throw new T2000Error(
58461
+ "INSUFFICIENT_BALANCE",
58462
+ `Insufficient funds. You have $${totalFunds.toFixed(2)} total (checking: $${bal.available.toFixed(2)}, savings: $${bal.savings.toFixed(2)}) but need $${params.usdAmount.toFixed(2)}.`
58463
+ );
58464
+ }
58436
58465
  if (bal.available < params.usdAmount && !params.dryRun) {
58437
58466
  await this._autoFundFromSavings(params.usdAmount - bal.available);
58438
58467
  }