@t2000/sdk 0.56.2 → 1.0.0
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/README.md +8 -25
- package/dist/adapters/descriptors.d.cts +1 -1
- package/dist/adapters/descriptors.d.ts +1 -1
- package/dist/adapters/index.cjs +7 -15
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +4 -9
- package/dist/adapters/index.d.ts +4 -9
- package/dist/adapters/index.js +7 -15
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.cjs +14 -335
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +15 -332
- package/dist/browser.js.map +1 -1
- package/dist/{descriptors-DkKhitk_.d.cts → descriptors-3YmGYl63.d.cts} +1 -6
- package/dist/{descriptors-DkKhitk_.d.ts → descriptors-3YmGYl63.d.ts} +1 -6
- package/dist/index.cjs +54 -434
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -20
- package/dist/index.d.ts +24 -20
- package/dist/index.js +56 -431
- package/dist/index.js.map +1 -1
- package/dist/{token-registry-BortlMRr.d.ts → token-registry-CoTPqCbS.d.ts} +19 -84
- package/dist/{token-registry-DWRdYf6m.d.cts → token-registry-DAHghHh2.d.cts} +19 -84
- package/dist/{types-DVVns7_w.d.cts → types-jAD-e7Pq.d.cts} +1 -14
- package/dist/{types-DVVns7_w.d.ts → types-jAD-e7Pq.d.ts} +1 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -811,9 +811,6 @@ var MIST_PER_SUI = 1000000000n;
|
|
|
811
811
|
var SUI_DECIMALS = 9;
|
|
812
812
|
var USDC_DECIMALS = 6;
|
|
813
813
|
var BPS_DENOMINATOR = 10000n;
|
|
814
|
-
var AUTO_TOPUP_THRESHOLD = 50000000n;
|
|
815
|
-
var GAS_RESERVE_TARGET = 150000000n;
|
|
816
|
-
var AUTO_TOPUP_MIN_USDC = 2000000n;
|
|
817
814
|
var SAVE_FEE_BPS = 10n;
|
|
818
815
|
var BORROW_FEE_BPS = 5n;
|
|
819
816
|
var CLOCK_ID = "0x6";
|
|
@@ -5124,8 +5121,6 @@ async function refreshOracle(tx, client, address, options) {
|
|
|
5124
5121
|
const oracleOpts = {
|
|
5125
5122
|
...sdkOptions(client),
|
|
5126
5123
|
throws: false,
|
|
5127
|
-
// Pyth update uses tx.splitCoins(tx.gas, ...) which is incompatible
|
|
5128
|
-
// with sponsored transactions where tx.gas belongs to the sponsor.
|
|
5129
5124
|
updatePythPriceFeeds: !options?.skipPythUpdate
|
|
5130
5125
|
};
|
|
5131
5126
|
await mt(tx, address, pools, oracleOpts);
|
|
@@ -5316,7 +5311,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
5316
5311
|
}
|
|
5317
5312
|
const tx = new transactions.Transaction();
|
|
5318
5313
|
tx.setSender(address);
|
|
5319
|
-
await refreshOracle(tx, client, address
|
|
5314
|
+
await refreshOracle(tx, client, address);
|
|
5320
5315
|
try {
|
|
5321
5316
|
const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5322
5317
|
tx.transferObjects([coin], address);
|
|
@@ -5328,7 +5323,6 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
5328
5323
|
}
|
|
5329
5324
|
async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
5330
5325
|
const asset = options.asset ?? "USDC";
|
|
5331
|
-
const sponsored = options.sponsored ?? true;
|
|
5332
5326
|
const assetInfo = resolveAssetInfo(asset);
|
|
5333
5327
|
const posResult = await getPositions(client, address);
|
|
5334
5328
|
const supply = posResult.positions.find(
|
|
@@ -5346,7 +5340,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
5346
5340
|
});
|
|
5347
5341
|
return { coin, effectiveAmount: 0 };
|
|
5348
5342
|
}
|
|
5349
|
-
await refreshOracle(tx, client, address
|
|
5343
|
+
await refreshOracle(tx, client, address);
|
|
5350
5344
|
try {
|
|
5351
5345
|
const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5352
5346
|
return { coin, effectiveAmount };
|
|
@@ -5370,9 +5364,8 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
|
5370
5364
|
}
|
|
5371
5365
|
async function addRepayToTx(tx, client, address, coin, options = {}) {
|
|
5372
5366
|
const asset = options.asset ?? "USDC";
|
|
5373
|
-
const sponsored = options.sponsored ?? true;
|
|
5374
5367
|
const assetInfo = resolveAssetInfo(asset);
|
|
5375
|
-
await refreshOracle(tx, client, address
|
|
5368
|
+
await refreshOracle(tx, client, address);
|
|
5376
5369
|
try {
|
|
5377
5370
|
await xe(tx, assetInfo.type, coin, { env: "prod" });
|
|
5378
5371
|
} catch (err) {
|
|
@@ -5389,7 +5382,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
5389
5382
|
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
5390
5383
|
const tx = new transactions.Transaction();
|
|
5391
5384
|
tx.setSender(address);
|
|
5392
|
-
await refreshOracle(tx, client, address
|
|
5385
|
+
await refreshOracle(tx, client, address);
|
|
5393
5386
|
try {
|
|
5394
5387
|
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5395
5388
|
if (options.collectFee) {
|
|
@@ -5420,10 +5413,7 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
5420
5413
|
const coinObj = mergeCoins(tx, coins);
|
|
5421
5414
|
const rawAmount = Math.min(rawRequested, Number(totalBalance));
|
|
5422
5415
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
5423
|
-
await refreshOracle(tx, client, address, {
|
|
5424
|
-
skipPythUpdate: options.sponsored,
|
|
5425
|
-
skipOracle: options.skipOracle
|
|
5426
|
-
});
|
|
5416
|
+
await refreshOracle(tx, client, address, { skipOracle: options.skipOracle });
|
|
5427
5417
|
try {
|
|
5428
5418
|
await xe(tx, assetInfo.type, repayCoin, {
|
|
5429
5419
|
...sdkOptions(client),
|
|
@@ -5734,9 +5724,9 @@ var NaviAdapter = class {
|
|
|
5734
5724
|
const tx = await buildSaveTx(this.client, address, amount, { ...options, asset: normalized });
|
|
5735
5725
|
return { tx };
|
|
5736
5726
|
}
|
|
5737
|
-
async buildWithdrawTx(address, amount, asset
|
|
5727
|
+
async buildWithdrawTx(address, amount, asset) {
|
|
5738
5728
|
const normalized = normalizeAsset(asset);
|
|
5739
|
-
const result = await buildWithdrawTx(this.client, address, amount, { asset: normalized
|
|
5729
|
+
const result = await buildWithdrawTx(this.client, address, amount, { asset: normalized });
|
|
5740
5730
|
return { tx: result.tx, effectiveAmount: result.effectiveAmount };
|
|
5741
5731
|
}
|
|
5742
5732
|
async buildBorrowTx(address, amount, asset, options) {
|
|
@@ -5748,7 +5738,6 @@ var NaviAdapter = class {
|
|
|
5748
5738
|
const normalized = normalizeAsset(asset);
|
|
5749
5739
|
const tx = await buildRepayTx(this.client, address, amount, {
|
|
5750
5740
|
asset: normalized,
|
|
5751
|
-
sponsored: options?.sponsored,
|
|
5752
5741
|
skipOracle: options?.skipOracle
|
|
5753
5742
|
});
|
|
5754
5743
|
return { tx };
|
|
@@ -5778,339 +5767,6 @@ var NaviAdapter = class {
|
|
|
5778
5767
|
return addClaimRewardsToTx(tx, this.client, address);
|
|
5779
5768
|
}
|
|
5780
5769
|
};
|
|
5781
|
-
function hasLeadingZeroBits(hash, bits) {
|
|
5782
|
-
const fullBytes = Math.floor(bits / 8);
|
|
5783
|
-
const remainingBits = bits % 8;
|
|
5784
|
-
for (let i = 0; i < fullBytes; i++) {
|
|
5785
|
-
if (hash[i] !== 0) return false;
|
|
5786
|
-
}
|
|
5787
|
-
if (remainingBits > 0) {
|
|
5788
|
-
const mask = 255 << 8 - remainingBits;
|
|
5789
|
-
if ((hash[fullBytes] & mask) !== 0) return false;
|
|
5790
|
-
}
|
|
5791
|
-
return true;
|
|
5792
|
-
}
|
|
5793
|
-
function solveHashcash(challenge) {
|
|
5794
|
-
const bits = parseInt(challenge.split(":")[1], 10);
|
|
5795
|
-
let counter = 0;
|
|
5796
|
-
while (true) {
|
|
5797
|
-
const stamp = `${challenge}${counter.toString(16)}`;
|
|
5798
|
-
const hash = crypto$1.createHash("sha256").update(stamp).digest();
|
|
5799
|
-
if (hasLeadingZeroBits(hash, bits)) return stamp;
|
|
5800
|
-
counter++;
|
|
5801
|
-
}
|
|
5802
|
-
}
|
|
5803
|
-
|
|
5804
|
-
// src/gas/manager.ts
|
|
5805
|
-
init_errors();
|
|
5806
|
-
|
|
5807
|
-
// src/gas/autoTopUp.ts
|
|
5808
|
-
async function shouldAutoTopUp(client, address) {
|
|
5809
|
-
const [suiBalance, usdcBalance] = await Promise.all([
|
|
5810
|
-
client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS.SUI.type }),
|
|
5811
|
-
client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS.USDC.type })
|
|
5812
|
-
]);
|
|
5813
|
-
const suiRaw = BigInt(suiBalance.totalBalance);
|
|
5814
|
-
const usdcRaw = BigInt(usdcBalance.totalBalance);
|
|
5815
|
-
if (suiRaw < GAS_RESERVE_TARGET && usdcRaw >= AUTO_TOPUP_MIN_USDC) {
|
|
5816
|
-
return false;
|
|
5817
|
-
}
|
|
5818
|
-
return false;
|
|
5819
|
-
}
|
|
5820
|
-
async function executeAutoTopUp(_client, _signer) {
|
|
5821
|
-
return { success: false, tx: "", usdcSpent: 0, suiReceived: 0 };
|
|
5822
|
-
}
|
|
5823
|
-
|
|
5824
|
-
// src/gas/gasStation.ts
|
|
5825
|
-
init_errors();
|
|
5826
|
-
|
|
5827
|
-
// src/utils/base64.ts
|
|
5828
|
-
function toBase642(bytes) {
|
|
5829
|
-
let binary = "";
|
|
5830
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
5831
|
-
return btoa(binary);
|
|
5832
|
-
}
|
|
5833
|
-
function fromBase642(b64) {
|
|
5834
|
-
const binary = atob(b64);
|
|
5835
|
-
const bytes = new Uint8Array(binary.length);
|
|
5836
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
5837
|
-
return bytes;
|
|
5838
|
-
}
|
|
5839
|
-
|
|
5840
|
-
// src/gas/gasStation.ts
|
|
5841
|
-
async function requestGasSponsorship(txJson, sender, type, txBcsBytes) {
|
|
5842
|
-
const payload = { sender, type };
|
|
5843
|
-
if (txBcsBytes) {
|
|
5844
|
-
payload.txBcsBytes = txBcsBytes;
|
|
5845
|
-
} else {
|
|
5846
|
-
payload.txJson = txJson;
|
|
5847
|
-
payload.txBytes = toBase642(new TextEncoder().encode(txJson));
|
|
5848
|
-
}
|
|
5849
|
-
const res = await fetch(`${API_BASE_URL}/api/gas`, {
|
|
5850
|
-
method: "POST",
|
|
5851
|
-
headers: { "Content-Type": "application/json" },
|
|
5852
|
-
body: JSON.stringify(payload)
|
|
5853
|
-
});
|
|
5854
|
-
const data = await res.json();
|
|
5855
|
-
if (!res.ok) {
|
|
5856
|
-
const errorCode = data.error;
|
|
5857
|
-
if (errorCode === "CIRCUIT_BREAKER" || errorCode === "POOL_DEPLETED" || errorCode === "PRICE_STALE") {
|
|
5858
|
-
throw new exports.T2000Error(
|
|
5859
|
-
"GAS_STATION_UNAVAILABLE",
|
|
5860
|
-
data.message ?? "Gas station temporarily unavailable",
|
|
5861
|
-
{ retryAfter: data.retryAfter, reason: errorCode },
|
|
5862
|
-
true
|
|
5863
|
-
);
|
|
5864
|
-
}
|
|
5865
|
-
if (errorCode === "GAS_FEE_EXCEEDED") {
|
|
5866
|
-
throw new exports.T2000Error(
|
|
5867
|
-
"GAS_FEE_EXCEEDED",
|
|
5868
|
-
data.message ?? "Gas fee exceeds ceiling",
|
|
5869
|
-
{ retryAfter: data.retryAfter },
|
|
5870
|
-
true
|
|
5871
|
-
);
|
|
5872
|
-
}
|
|
5873
|
-
throw new exports.T2000Error(
|
|
5874
|
-
"GAS_STATION_UNAVAILABLE",
|
|
5875
|
-
data.message ?? "Gas sponsorship request failed",
|
|
5876
|
-
{ reason: errorCode },
|
|
5877
|
-
true
|
|
5878
|
-
);
|
|
5879
|
-
}
|
|
5880
|
-
return data;
|
|
5881
|
-
}
|
|
5882
|
-
async function reportGasUsage(sender, txDigest, gasCostSui, usdcCharged, type) {
|
|
5883
|
-
try {
|
|
5884
|
-
await fetch(`${API_BASE_URL}/api/gas/report`, {
|
|
5885
|
-
method: "POST",
|
|
5886
|
-
headers: { "Content-Type": "application/json" },
|
|
5887
|
-
body: JSON.stringify({ sender, txDigest, gasCostSui, usdcCharged, type })
|
|
5888
|
-
});
|
|
5889
|
-
} catch {
|
|
5890
|
-
}
|
|
5891
|
-
}
|
|
5892
|
-
async function getGasStatus(address) {
|
|
5893
|
-
const url = new URL(`${API_BASE_URL}/api/gas/status`);
|
|
5894
|
-
if (address) url.searchParams.set("address", address);
|
|
5895
|
-
const res = await fetch(url.toString());
|
|
5896
|
-
if (!res.ok) {
|
|
5897
|
-
throw new exports.T2000Error("GAS_STATION_UNAVAILABLE", "Failed to fetch gas status", void 0, true);
|
|
5898
|
-
}
|
|
5899
|
-
return await res.json();
|
|
5900
|
-
}
|
|
5901
|
-
|
|
5902
|
-
// src/gas/manager.ts
|
|
5903
|
-
function extractGasCost(effects) {
|
|
5904
|
-
if (!effects?.gasUsed) return 0;
|
|
5905
|
-
return (Number(effects.gasUsed.computationCost) + Number(effects.gasUsed.storageCost) - Number(effects.gasUsed.storageRebate)) / 1e9;
|
|
5906
|
-
}
|
|
5907
|
-
async function getSuiBalance(client, address) {
|
|
5908
|
-
const bal = await client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS.SUI.type });
|
|
5909
|
-
return BigInt(bal.totalBalance);
|
|
5910
|
-
}
|
|
5911
|
-
async function assertTxSuccess(effects, digest) {
|
|
5912
|
-
const eff = effects;
|
|
5913
|
-
if (eff?.status?.status === "failure") {
|
|
5914
|
-
const errMsg = eff.status.error ?? "unknown on-chain error";
|
|
5915
|
-
if (isMoveAbort(errMsg)) {
|
|
5916
|
-
throw new exports.T2000Error("TRANSACTION_FAILED", parseMoveAbortMessage(errMsg));
|
|
5917
|
-
}
|
|
5918
|
-
throw new exports.T2000Error("TRANSACTION_FAILED", `Transaction ${digest} failed on-chain: ${errMsg}`);
|
|
5919
|
-
}
|
|
5920
|
-
}
|
|
5921
|
-
async function trySelfFunded(client, signer, tx) {
|
|
5922
|
-
const address = signer.getAddress();
|
|
5923
|
-
const suiBalance = await getSuiBalance(client, address);
|
|
5924
|
-
if (suiBalance < AUTO_TOPUP_THRESHOLD) return null;
|
|
5925
|
-
tx.setSender(address);
|
|
5926
|
-
const builtBytes = await tx.build({ client });
|
|
5927
|
-
const { signature } = await signer.signTransaction(builtBytes);
|
|
5928
|
-
const result = await client.executeTransactionBlock({
|
|
5929
|
-
transactionBlock: toBase642(builtBytes),
|
|
5930
|
-
signature: [signature],
|
|
5931
|
-
options: { showEffects: true, showBalanceChanges: true }
|
|
5932
|
-
});
|
|
5933
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
5934
|
-
await assertTxSuccess(result.effects, result.digest);
|
|
5935
|
-
return {
|
|
5936
|
-
digest: result.digest,
|
|
5937
|
-
effects: result.effects,
|
|
5938
|
-
balanceChanges: result.balanceChanges,
|
|
5939
|
-
gasMethod: "self-funded",
|
|
5940
|
-
gasCostSui: extractGasCost(result.effects),
|
|
5941
|
-
preTxSuiMist: suiBalance
|
|
5942
|
-
};
|
|
5943
|
-
}
|
|
5944
|
-
async function tryAutoTopUpThenSelfFund(client, signer, buildTx) {
|
|
5945
|
-
const address = signer.getAddress();
|
|
5946
|
-
const canTopUp = await shouldAutoTopUp(client, address);
|
|
5947
|
-
if (!canTopUp) return null;
|
|
5948
|
-
await executeAutoTopUp();
|
|
5949
|
-
const tx = await buildTx();
|
|
5950
|
-
tx.setSender(address);
|
|
5951
|
-
const suiAfterTopUp = await getSuiBalance(client, address);
|
|
5952
|
-
const builtBytes = await tx.build({ client });
|
|
5953
|
-
const { signature } = await signer.signTransaction(builtBytes);
|
|
5954
|
-
const result = await client.executeTransactionBlock({
|
|
5955
|
-
transactionBlock: toBase642(builtBytes),
|
|
5956
|
-
signature: [signature],
|
|
5957
|
-
options: { showEffects: true, showBalanceChanges: true }
|
|
5958
|
-
});
|
|
5959
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
5960
|
-
await assertTxSuccess(result.effects, result.digest);
|
|
5961
|
-
return {
|
|
5962
|
-
digest: result.digest,
|
|
5963
|
-
effects: result.effects,
|
|
5964
|
-
balanceChanges: result.balanceChanges,
|
|
5965
|
-
gasMethod: "auto-topup",
|
|
5966
|
-
gasCostSui: extractGasCost(result.effects),
|
|
5967
|
-
preTxSuiMist: suiAfterTopUp
|
|
5968
|
-
};
|
|
5969
|
-
}
|
|
5970
|
-
async function trySponsored(client, signer, tx) {
|
|
5971
|
-
const address = signer.getAddress();
|
|
5972
|
-
const suiBalance = await getSuiBalance(client, address);
|
|
5973
|
-
tx.setSender(address);
|
|
5974
|
-
let txJson;
|
|
5975
|
-
let txBcsBase64;
|
|
5976
|
-
try {
|
|
5977
|
-
txJson = tx.serialize();
|
|
5978
|
-
} catch {
|
|
5979
|
-
const bcsBytes = await tx.build({ client });
|
|
5980
|
-
txBcsBase64 = toBase642(bcsBytes);
|
|
5981
|
-
}
|
|
5982
|
-
const sponsoredResult = await requestGasSponsorship(txJson ?? "", address, void 0, txBcsBase64);
|
|
5983
|
-
const sponsoredTxBytes = fromBase642(sponsoredResult.txBytes);
|
|
5984
|
-
const { signature: agentSig } = await signer.signTransaction(sponsoredTxBytes);
|
|
5985
|
-
const result = await client.executeTransactionBlock({
|
|
5986
|
-
transactionBlock: sponsoredResult.txBytes,
|
|
5987
|
-
signature: [agentSig, sponsoredResult.sponsorSignature],
|
|
5988
|
-
options: { showEffects: true, showBalanceChanges: true }
|
|
5989
|
-
});
|
|
5990
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
5991
|
-
await assertTxSuccess(result.effects, result.digest);
|
|
5992
|
-
const gasCost = extractGasCost(result.effects);
|
|
5993
|
-
reportGasUsage(address, result.digest, gasCost, 0, sponsoredResult.type);
|
|
5994
|
-
return {
|
|
5995
|
-
digest: result.digest,
|
|
5996
|
-
effects: result.effects,
|
|
5997
|
-
balanceChanges: result.balanceChanges,
|
|
5998
|
-
gasMethod: "sponsored",
|
|
5999
|
-
gasCostSui: gasCost,
|
|
6000
|
-
preTxSuiMist: suiBalance
|
|
6001
|
-
};
|
|
6002
|
-
}
|
|
6003
|
-
async function waitForIndexer(client, digest) {
|
|
6004
|
-
for (let i = 0; i < 3; i++) {
|
|
6005
|
-
try {
|
|
6006
|
-
await client.getTransactionBlock({ digest, options: { showObjectChanges: true } });
|
|
6007
|
-
return;
|
|
6008
|
-
} catch {
|
|
6009
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
6010
|
-
}
|
|
6011
|
-
}
|
|
6012
|
-
}
|
|
6013
|
-
async function executeWithGas(client, signer, buildTx, options) {
|
|
6014
|
-
if (options?.enforcer && options?.metadata) {
|
|
6015
|
-
options.enforcer.check(options.metadata);
|
|
6016
|
-
}
|
|
6017
|
-
const result = await resolveGas(client, signer, buildTx);
|
|
6018
|
-
try {
|
|
6019
|
-
if (result.preTxSuiMist !== void 0) {
|
|
6020
|
-
const gasCostMist = result.gasMethod === "sponsored" ? 0n : BigInt(Math.round(result.gasCostSui * 1e9));
|
|
6021
|
-
const estimatedRemaining = result.preTxSuiMist - gasCostMist;
|
|
6022
|
-
if (estimatedRemaining < GAS_RESERVE_TARGET) {
|
|
6023
|
-
const address = signer.getAddress();
|
|
6024
|
-
const usdcBal = await client.getBalance({
|
|
6025
|
-
owner: address,
|
|
6026
|
-
coinType: SUPPORTED_ASSETS.USDC.type
|
|
6027
|
-
});
|
|
6028
|
-
if (BigInt(usdcBal.totalBalance) >= AUTO_TOPUP_MIN_USDC) {
|
|
6029
|
-
await executeAutoTopUp(client, signer);
|
|
6030
|
-
}
|
|
6031
|
-
}
|
|
6032
|
-
}
|
|
6033
|
-
} catch {
|
|
6034
|
-
}
|
|
6035
|
-
return result;
|
|
6036
|
-
}
|
|
6037
|
-
var GAS_RESOLUTION_CODES = /* @__PURE__ */ new Set([
|
|
6038
|
-
"INSUFFICIENT_GAS",
|
|
6039
|
-
"GAS_STATION_UNAVAILABLE",
|
|
6040
|
-
"GAS_FEE_EXCEEDED",
|
|
6041
|
-
"AUTO_TOPUP_FAILED",
|
|
6042
|
-
"SPONSOR_UNAVAILABLE"
|
|
6043
|
-
]);
|
|
6044
|
-
function isBuildError(err) {
|
|
6045
|
-
return err instanceof exports.T2000Error && !GAS_RESOLUTION_CODES.has(err.code);
|
|
6046
|
-
}
|
|
6047
|
-
async function resolveGas(client, signer, buildTx) {
|
|
6048
|
-
const errors = [];
|
|
6049
|
-
let lastBuildError;
|
|
6050
|
-
try {
|
|
6051
|
-
const tx = await buildTx();
|
|
6052
|
-
const result = await trySelfFunded(client, signer, tx);
|
|
6053
|
-
if (result) {
|
|
6054
|
-
await waitForIndexer(client, result.digest);
|
|
6055
|
-
return result;
|
|
6056
|
-
}
|
|
6057
|
-
errors.push("self-funded: SUI below threshold");
|
|
6058
|
-
} catch (err) {
|
|
6059
|
-
if (err instanceof exports.T2000Error && err.code === "TRANSACTION_FAILED") throw err;
|
|
6060
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
6061
|
-
if (isMoveAbort(msg)) {
|
|
6062
|
-
throw new exports.T2000Error("TRANSACTION_FAILED", parseMoveAbortMessage(msg));
|
|
6063
|
-
}
|
|
6064
|
-
if (isBuildError(err)) lastBuildError = err;
|
|
6065
|
-
errors.push(`self-funded: ${msg}`);
|
|
6066
|
-
}
|
|
6067
|
-
try {
|
|
6068
|
-
const result = await tryAutoTopUpThenSelfFund(client, signer, buildTx);
|
|
6069
|
-
if (result) {
|
|
6070
|
-
await waitForIndexer(client, result.digest);
|
|
6071
|
-
return result;
|
|
6072
|
-
}
|
|
6073
|
-
errors.push("auto-topup: not eligible (low USDC or sufficient SUI)");
|
|
6074
|
-
} catch (err) {
|
|
6075
|
-
if (err instanceof exports.T2000Error && err.code === "TRANSACTION_FAILED") throw err;
|
|
6076
|
-
errors.push(`auto-topup: ${err instanceof Error ? err.message : String(err)}`);
|
|
6077
|
-
}
|
|
6078
|
-
try {
|
|
6079
|
-
const tx = await buildTx();
|
|
6080
|
-
const result = await trySelfFunded(client, signer, tx);
|
|
6081
|
-
if (result) {
|
|
6082
|
-
await waitForIndexer(client, result.digest);
|
|
6083
|
-
return result;
|
|
6084
|
-
}
|
|
6085
|
-
} catch (err) {
|
|
6086
|
-
if (err instanceof exports.T2000Error && err.code === "TRANSACTION_FAILED") throw err;
|
|
6087
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
6088
|
-
if (isMoveAbort(msg)) {
|
|
6089
|
-
throw new exports.T2000Error("TRANSACTION_FAILED", parseMoveAbortMessage(msg));
|
|
6090
|
-
}
|
|
6091
|
-
if (isBuildError(err)) lastBuildError = err;
|
|
6092
|
-
errors.push(`self-funded-retry: ${msg}`);
|
|
6093
|
-
}
|
|
6094
|
-
try {
|
|
6095
|
-
const tx = await buildTx();
|
|
6096
|
-
const result = await trySponsored(client, signer, tx);
|
|
6097
|
-
if (result) {
|
|
6098
|
-
await waitForIndexer(client, result.digest);
|
|
6099
|
-
return result;
|
|
6100
|
-
}
|
|
6101
|
-
errors.push("sponsored: returned null");
|
|
6102
|
-
} catch (err) {
|
|
6103
|
-
if (err instanceof exports.T2000Error && err.code === "TRANSACTION_FAILED") throw err;
|
|
6104
|
-
if (isBuildError(err)) lastBuildError = err;
|
|
6105
|
-
errors.push(`sponsored: ${err instanceof Error ? err.message : String(err)}`);
|
|
6106
|
-
}
|
|
6107
|
-
if (lastBuildError) throw lastBuildError;
|
|
6108
|
-
throw new exports.T2000Error(
|
|
6109
|
-
"INSUFFICIENT_GAS",
|
|
6110
|
-
`No SUI for gas and sponsorship unavailable. Fund your wallet with SUI or USDC. [${errors.join(" | ")}]`,
|
|
6111
|
-
{ reason: "all_gas_methods_exhausted", errors }
|
|
6112
|
-
);
|
|
6113
|
-
}
|
|
6114
5770
|
|
|
6115
5771
|
// src/t2000.ts
|
|
6116
5772
|
init_errors();
|
|
@@ -6355,6 +6011,25 @@ var ContactManager = class {
|
|
|
6355
6011
|
}
|
|
6356
6012
|
};
|
|
6357
6013
|
var DEFAULT_CONFIG_DIR = path.join(os.homedir(), ".t2000");
|
|
6014
|
+
async function executeTx(client, signer, buildTx) {
|
|
6015
|
+
const tx = await buildTx();
|
|
6016
|
+
tx.setSender(signer.getAddress());
|
|
6017
|
+
const txBytes = await tx.build({ client });
|
|
6018
|
+
const { signature } = await signer.signTransaction(txBytes);
|
|
6019
|
+
const result = await client.executeTransactionBlock({
|
|
6020
|
+
transactionBlock: txBytes,
|
|
6021
|
+
signature,
|
|
6022
|
+
options: { showEffects: true }
|
|
6023
|
+
});
|
|
6024
|
+
await client.waitForTransaction({ digest: result.digest });
|
|
6025
|
+
const gasUsed = result.effects?.gasUsed;
|
|
6026
|
+
let gasCostSui = 0;
|
|
6027
|
+
if (gasUsed) {
|
|
6028
|
+
const total = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
|
|
6029
|
+
gasCostSui = Number(total) / 1e9;
|
|
6030
|
+
}
|
|
6031
|
+
return { digest: result.digest, gasCostSui, effects: result.effects ?? void 0 };
|
|
6032
|
+
}
|
|
6358
6033
|
var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
6359
6034
|
_signer;
|
|
6360
6035
|
_keypair;
|
|
@@ -6389,16 +6064,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6389
6064
|
return registry;
|
|
6390
6065
|
}
|
|
6391
6066
|
static async create(options = {}) {
|
|
6392
|
-
const { keyPath, pin, passphrase,
|
|
6067
|
+
const { keyPath, pin, passphrase, rpcUrl } = options;
|
|
6393
6068
|
const secret = pin ?? passphrase;
|
|
6394
6069
|
const client = getSuiClient(rpcUrl);
|
|
6395
|
-
if (sponsored) {
|
|
6396
|
-
const keypair2 = generateKeypair();
|
|
6397
|
-
if (secret) {
|
|
6398
|
-
await saveKey(keypair2, secret, keyPath);
|
|
6399
|
-
}
|
|
6400
|
-
return new _T2000(keypair2, client, void 0, DEFAULT_CONFIG_DIR);
|
|
6401
|
-
}
|
|
6402
6070
|
const exists = await walletExists(keyPath);
|
|
6403
6071
|
if (!exists) {
|
|
6404
6072
|
throw new exports.T2000Error(
|
|
@@ -6424,15 +6092,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6424
6092
|
const client = getSuiClient();
|
|
6425
6093
|
const agent = new _T2000(keypair, client, void 0, DEFAULT_CONFIG_DIR);
|
|
6426
6094
|
const address = agent.address();
|
|
6427
|
-
|
|
6428
|
-
if (options.sponsored !== false) {
|
|
6429
|
-
try {
|
|
6430
|
-
await callSponsorApi(address, options.name);
|
|
6431
|
-
sponsored = true;
|
|
6432
|
-
} catch {
|
|
6433
|
-
}
|
|
6434
|
-
}
|
|
6435
|
-
return { agent, address, sponsored };
|
|
6095
|
+
return { agent, address };
|
|
6436
6096
|
}
|
|
6437
6097
|
// -- Gas --
|
|
6438
6098
|
/** SuiJsonRpcClient used by this agent — exposed for integrations. */
|
|
@@ -6465,7 +6125,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6465
6125
|
client,
|
|
6466
6126
|
signer: { toSuiAddress: () => signerAddress },
|
|
6467
6127
|
execute: async (tx) => {
|
|
6468
|
-
const result = await
|
|
6128
|
+
const result = await executeTx(client, signer, () => tx);
|
|
6469
6129
|
return { digest: result.digest, effects: result.effects };
|
|
6470
6130
|
}
|
|
6471
6131
|
})]
|
|
@@ -6503,7 +6163,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6503
6163
|
const { buildStakeVSuiTx: buildStakeVSuiTx2, getVoloStats: getVoloStats2 } = await Promise.resolve().then(() => (init_volo(), volo_exports));
|
|
6504
6164
|
const amountMist = BigInt(Math.floor(params.amount * Number(MIST_PER_SUI)));
|
|
6505
6165
|
const stats = await getVoloStats2();
|
|
6506
|
-
const gasResult = await
|
|
6166
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6507
6167
|
return buildStakeVSuiTx2(this.client, this._address, amountMist);
|
|
6508
6168
|
});
|
|
6509
6169
|
const vSuiReceived = params.amount / stats.exchangeRate;
|
|
@@ -6513,8 +6173,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6513
6173
|
amountSui: params.amount,
|
|
6514
6174
|
vSuiReceived,
|
|
6515
6175
|
apy: stats.apy,
|
|
6516
|
-
gasCost: gasResult.gasCostSui
|
|
6517
|
-
gasMethod: gasResult.gasMethod
|
|
6176
|
+
gasCost: gasResult.gasCostSui
|
|
6518
6177
|
};
|
|
6519
6178
|
}
|
|
6520
6179
|
async unstakeVSui(params) {
|
|
@@ -6531,7 +6190,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6531
6190
|
vSuiAmount = params.amount;
|
|
6532
6191
|
}
|
|
6533
6192
|
const stats = await getVoloStats2();
|
|
6534
|
-
const gasResult = await
|
|
6193
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6535
6194
|
return buildUnstakeVSuiTx2(this.client, this._address, amountMist);
|
|
6536
6195
|
});
|
|
6537
6196
|
const suiReceived = vSuiAmount * stats.exchangeRate;
|
|
@@ -6540,8 +6199,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6540
6199
|
tx: gasResult.digest,
|
|
6541
6200
|
vSuiAmount,
|
|
6542
6201
|
suiReceived,
|
|
6543
|
-
gasCost: gasResult.gasCostSui
|
|
6544
|
-
gasMethod: gasResult.gasMethod
|
|
6202
|
+
gasCost: gasResult.gasCostSui
|
|
6545
6203
|
};
|
|
6546
6204
|
}
|
|
6547
6205
|
// -- Swap --
|
|
@@ -6575,7 +6233,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6575
6233
|
preBalRaw = BigInt(preBal.totalBalance);
|
|
6576
6234
|
} catch {
|
|
6577
6235
|
}
|
|
6578
|
-
const gasResult = await
|
|
6236
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6579
6237
|
const tx = new transactions.Transaction();
|
|
6580
6238
|
tx.setSender(this._address);
|
|
6581
6239
|
let inputCoin;
|
|
@@ -6644,8 +6302,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6644
6302
|
toAmount,
|
|
6645
6303
|
priceImpact: route.priceImpact,
|
|
6646
6304
|
route: routeDesc,
|
|
6647
|
-
gasCost: gasResult.gasCostSui
|
|
6648
|
-
gasMethod: gasResult.gasMethod
|
|
6305
|
+
gasCost: gasResult.gasCostSui
|
|
6649
6306
|
};
|
|
6650
6307
|
}
|
|
6651
6308
|
async swapQuote(params) {
|
|
@@ -6692,11 +6349,10 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6692
6349
|
const resolved = this.contacts.resolve(params.to);
|
|
6693
6350
|
const sendAmount = params.amount;
|
|
6694
6351
|
const sendTo = resolved.address;
|
|
6695
|
-
const gasResult = await
|
|
6352
|
+
const gasResult = await executeTx(
|
|
6696
6353
|
this.client,
|
|
6697
6354
|
this._signer,
|
|
6698
|
-
() => buildSendTx({ client: this.client, address: this._address, to: sendTo, amount: sendAmount, asset })
|
|
6699
|
-
{ metadata: { operation: "send", amount: sendAmount }, enforcer: this.enforcer }
|
|
6355
|
+
() => buildSendTx({ client: this.client, address: this._address, to: sendTo, amount: sendAmount, asset })
|
|
6700
6356
|
);
|
|
6701
6357
|
this.enforcer.recordUsage(sendAmount);
|
|
6702
6358
|
const balance = await this.balance();
|
|
@@ -6709,7 +6365,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6709
6365
|
contactName: resolved.contactName,
|
|
6710
6366
|
gasCost: gasResult.gasCostSui,
|
|
6711
6367
|
gasCostUnit: "SUI",
|
|
6712
|
-
gasMethod: gasResult.gasMethod,
|
|
6713
6368
|
balance
|
|
6714
6369
|
};
|
|
6715
6370
|
}
|
|
@@ -6842,7 +6497,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6842
6497
|
const saveAmount = amount;
|
|
6843
6498
|
const adapter = await this.resolveLending(params.protocol, asset, "save");
|
|
6844
6499
|
const canPTB = !!adapter.addSaveToTx;
|
|
6845
|
-
const gasResult = await
|
|
6500
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6846
6501
|
if (canPTB) {
|
|
6847
6502
|
const tx2 = new transactions.Transaction();
|
|
6848
6503
|
tx2.setSender(this._address);
|
|
@@ -6880,7 +6535,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6880
6535
|
apy: rates.saveApy,
|
|
6881
6536
|
fee: fee.amount,
|
|
6882
6537
|
gasCost: gasResult.gasCostSui,
|
|
6883
|
-
gasMethod: gasResult.gasMethod,
|
|
6884
6538
|
savingsBalance
|
|
6885
6539
|
};
|
|
6886
6540
|
}
|
|
@@ -6939,7 +6593,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6939
6593
|
}
|
|
6940
6594
|
const withdrawAmount = amount;
|
|
6941
6595
|
let finalAmount = withdrawAmount;
|
|
6942
|
-
const gasResult = await
|
|
6596
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6943
6597
|
if (adapter.addWithdrawToTx) {
|
|
6944
6598
|
const tx = new transactions.Transaction();
|
|
6945
6599
|
tx.setSender(this._address);
|
|
@@ -6958,8 +6612,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6958
6612
|
tx: gasResult.digest,
|
|
6959
6613
|
amount: finalAmount,
|
|
6960
6614
|
asset: target.asset,
|
|
6961
|
-
gasCost: gasResult.gasCostSui
|
|
6962
|
-
gasMethod: gasResult.gasMethod
|
|
6615
|
+
gasCost: gasResult.gasCostSui
|
|
6963
6616
|
};
|
|
6964
6617
|
}
|
|
6965
6618
|
async withdrawAllProtocols() {
|
|
@@ -6996,7 +6649,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6996
6649
|
}
|
|
6997
6650
|
let totalReceived = 0;
|
|
6998
6651
|
const canPTB = entries.every((e) => e.adapter.addWithdrawToTx);
|
|
6999
|
-
const gasResult = await
|
|
6652
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7000
6653
|
if (canPTB) {
|
|
7001
6654
|
const tx = new transactions.Transaction();
|
|
7002
6655
|
tx.setSender(this._address);
|
|
@@ -7027,8 +6680,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7027
6680
|
success: true,
|
|
7028
6681
|
tx: gasResult.digest,
|
|
7029
6682
|
amount: totalReceived,
|
|
7030
|
-
gasCost: gasResult.gasCostSui
|
|
7031
|
-
gasMethod: gasResult.gasMethod
|
|
6683
|
+
gasCost: gasResult.gasCostSui
|
|
7032
6684
|
};
|
|
7033
6685
|
}
|
|
7034
6686
|
/**
|
|
@@ -7146,7 +6798,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7146
6798
|
}
|
|
7147
6799
|
const fee = calculateFee("borrow", params.amount);
|
|
7148
6800
|
const borrowAmount = params.amount;
|
|
7149
|
-
const gasResult = await
|
|
6801
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7150
6802
|
const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset, { collectFee: true });
|
|
7151
6803
|
return tx;
|
|
7152
6804
|
});
|
|
@@ -7160,8 +6812,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7160
6812
|
asset,
|
|
7161
6813
|
fee: fee.amount,
|
|
7162
6814
|
healthFactor: hf.healthFactor,
|
|
7163
|
-
gasCost: gasResult.gasCostSui
|
|
7164
|
-
gasMethod: gasResult.gasMethod
|
|
6815
|
+
gasCost: gasResult.gasCostSui
|
|
7165
6816
|
};
|
|
7166
6817
|
}
|
|
7167
6818
|
async repay(params) {
|
|
@@ -7190,7 +6841,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7190
6841
|
if (!adapter) throw new exports.T2000Error("PROTOCOL_UNAVAILABLE", `Protocol ${target.protocolId} not found`);
|
|
7191
6842
|
const repayAmount = Math.min(params.amount, target.amount);
|
|
7192
6843
|
const targetAssetInfo = SUPPORTED_ASSETS[target.asset] ?? SUPPORTED_ASSETS.USDC;
|
|
7193
|
-
const gasResult = await
|
|
6844
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7194
6845
|
if (adapter.addRepayToTx) {
|
|
7195
6846
|
const tx2 = new transactions.Transaction();
|
|
7196
6847
|
tx2.setSender(this._address);
|
|
@@ -7213,8 +6864,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7213
6864
|
amount: repayAmount,
|
|
7214
6865
|
asset: target.asset,
|
|
7215
6866
|
remainingDebt: hf.borrowed,
|
|
7216
|
-
gasCost: gasResult.gasCostSui
|
|
7217
|
-
gasMethod: gasResult.gasMethod
|
|
6867
|
+
gasCost: gasResult.gasCostSui
|
|
7218
6868
|
};
|
|
7219
6869
|
}
|
|
7220
6870
|
async _repayAllBorrows(borrows) {
|
|
@@ -7226,7 +6876,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7226
6876
|
}
|
|
7227
6877
|
const canPTB = entries.every((e) => e.adapter.addRepayToTx);
|
|
7228
6878
|
let totalRepaid = 0;
|
|
7229
|
-
const gasResult = await
|
|
6879
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7230
6880
|
if (canPTB) {
|
|
7231
6881
|
const tx = new transactions.Transaction();
|
|
7232
6882
|
tx.setSender(this._address);
|
|
@@ -7267,8 +6917,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7267
6917
|
amount: totalRepaid,
|
|
7268
6918
|
asset: dominantAsset,
|
|
7269
6919
|
remainingDebt: hf.borrowed,
|
|
7270
|
-
gasCost: gasResult.gasCostSui
|
|
7271
|
-
gasMethod: gasResult.gasMethod
|
|
6920
|
+
gasCost: gasResult.gasCostSui
|
|
7272
6921
|
};
|
|
7273
6922
|
}
|
|
7274
6923
|
async maxBorrow() {
|
|
@@ -7301,7 +6950,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7301
6950
|
this.enforcer.assertNotLocked();
|
|
7302
6951
|
const adapters = this.registry.listLending().filter((a) => a.addClaimRewardsToTx);
|
|
7303
6952
|
if (adapters.length === 0) {
|
|
7304
|
-
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0
|
|
6953
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
|
|
7305
6954
|
}
|
|
7306
6955
|
const tx = new transactions.Transaction();
|
|
7307
6956
|
tx.setSender(this._address);
|
|
@@ -7314,9 +6963,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7314
6963
|
}
|
|
7315
6964
|
}
|
|
7316
6965
|
if (allRewards.length === 0) {
|
|
7317
|
-
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0
|
|
6966
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
|
|
7318
6967
|
}
|
|
7319
|
-
const claimResult = await
|
|
6968
|
+
const claimResult = await executeTx(this.client, this._signer, async () => tx);
|
|
7320
6969
|
await this.client.waitForTransaction({ digest: claimResult.digest });
|
|
7321
6970
|
const totalValueUsd = allRewards.reduce((s, r) => s + r.estimatedValueUsd, 0);
|
|
7322
6971
|
return {
|
|
@@ -7324,8 +6973,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7324
6973
|
tx: claimResult.digest,
|
|
7325
6974
|
rewards: allRewards,
|
|
7326
6975
|
totalValueUsd,
|
|
7327
|
-
gasCost: claimResult.gasCostSui
|
|
7328
|
-
gasMethod: claimResult.gasMethod
|
|
6976
|
+
gasCost: claimResult.gasCostSui
|
|
7329
6977
|
};
|
|
7330
6978
|
}
|
|
7331
6979
|
/**
|
|
@@ -7397,7 +7045,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7397
7045
|
byAmountIn: true
|
|
7398
7046
|
});
|
|
7399
7047
|
if (!route || route.insufficientLiquidity) continue;
|
|
7400
|
-
const swapResult = await
|
|
7048
|
+
const swapResult = await executeTx(this.client, this._signer, async () => {
|
|
7401
7049
|
const tx = new transactions.Transaction();
|
|
7402
7050
|
tx.setSender(this._address);
|
|
7403
7051
|
const freshCoins = await this._fetchCoins(reward.coinType);
|
|
@@ -7428,7 +7076,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7428
7076
|
if (gainedRaw > 0n) {
|
|
7429
7077
|
try {
|
|
7430
7078
|
const adapter = await this.resolveLending(void 0, "USDC", "save");
|
|
7431
|
-
const depositResult = await
|
|
7079
|
+
const depositResult = await executeTx(this.client, this._signer, async () => {
|
|
7432
7080
|
const tx = new transactions.Transaction();
|
|
7433
7081
|
tx.setSender(this._address);
|
|
7434
7082
|
const coins = await this._fetchCoins(USDC_TYPE2);
|
|
@@ -7559,29 +7207,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7559
7207
|
this.emit("balanceChange", { asset, previous: 0, current: 0, cause, tx });
|
|
7560
7208
|
}
|
|
7561
7209
|
};
|
|
7562
|
-
async function callSponsorApi(address, name) {
|
|
7563
|
-
const res = await fetch(`${API_BASE_URL}/api/sponsor`, {
|
|
7564
|
-
method: "POST",
|
|
7565
|
-
headers: { "Content-Type": "application/json" },
|
|
7566
|
-
body: JSON.stringify({ address, name })
|
|
7567
|
-
});
|
|
7568
|
-
if (res.status === 429) {
|
|
7569
|
-
const data = await res.json();
|
|
7570
|
-
if (data.challenge) {
|
|
7571
|
-
const proof = solveHashcash(data.challenge);
|
|
7572
|
-
const retry = await fetch(`${API_BASE_URL}/api/sponsor`, {
|
|
7573
|
-
method: "POST",
|
|
7574
|
-
headers: { "Content-Type": "application/json" },
|
|
7575
|
-
body: JSON.stringify({ address, name, proof })
|
|
7576
|
-
});
|
|
7577
|
-
if (!retry.ok) throw new exports.T2000Error("SPONSOR_RATE_LIMITED", "Sponsor rate limited");
|
|
7578
|
-
return;
|
|
7579
|
-
}
|
|
7580
|
-
}
|
|
7581
|
-
if (!res.ok) {
|
|
7582
|
-
throw new exports.T2000Error("SPONSOR_FAILED", "Sponsor API unavailable");
|
|
7583
|
-
}
|
|
7584
|
-
}
|
|
7585
7210
|
|
|
7586
7211
|
// src/index.ts
|
|
7587
7212
|
init_errors();
|
|
@@ -7806,8 +7431,6 @@ exports.calculateFee = calculateFee;
|
|
|
7806
7431
|
exports.classifyAction = classifyAction;
|
|
7807
7432
|
exports.classifyLabel = classifyLabel;
|
|
7808
7433
|
exports.classifyTransaction = classifyTransaction;
|
|
7809
|
-
exports.executeAutoTopUp = executeAutoTopUp;
|
|
7810
|
-
exports.executeWithGas = executeWithGas;
|
|
7811
7434
|
exports.exportPrivateKey = exportPrivateKey;
|
|
7812
7435
|
exports.extractTransferDetails = extractTransferDetails;
|
|
7813
7436
|
exports.extractTxCommands = extractTxCommands;
|
|
@@ -7822,7 +7445,6 @@ exports.getAddress = getAddress;
|
|
|
7822
7445
|
exports.getDecimals = getDecimals;
|
|
7823
7446
|
exports.getDecimalsForCoinType = getDecimalsForCoinType;
|
|
7824
7447
|
exports.getFinancialSummary = getFinancialSummary;
|
|
7825
|
-
exports.getGasStatus = getGasStatus;
|
|
7826
7448
|
exports.getPendingRewards = getPendingRewards;
|
|
7827
7449
|
exports.getRates = getRates;
|
|
7828
7450
|
exports.getSwapQuote = getSwapQuote;
|
|
@@ -7848,9 +7470,7 @@ exports.refineLendingLabel = refineLendingLabel;
|
|
|
7848
7470
|
exports.resolveSymbol = resolveSymbol;
|
|
7849
7471
|
exports.resolveTokenType = resolveTokenType;
|
|
7850
7472
|
exports.saveKey = saveKey;
|
|
7851
|
-
exports.shouldAutoTopUp = shouldAutoTopUp;
|
|
7852
7473
|
exports.simulateTransaction = simulateTransaction;
|
|
7853
|
-
exports.solveHashcash = solveHashcash;
|
|
7854
7474
|
exports.stableToRaw = stableToRaw;
|
|
7855
7475
|
exports.suiToMist = suiToMist;
|
|
7856
7476
|
exports.throwIfSimulationFailed = throwIfSimulationFailed;
|