@t2000/sdk 0.18.36 → 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.cjs +21 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +21 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
56232
|
-
|
|
56233
|
-
|
|
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
|
}
|