@t2000/sdk 0.56.2 → 1.0.1
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 +22 -17
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +12 -9
- package/dist/adapters/index.d.ts +12 -9
- package/dist/adapters/index.js +22 -17
- 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-CDVXo3BM.d.cts} +9 -6
- package/dist/{descriptors-DkKhitk_.d.ts → descriptors-CDVXo3BM.d.ts} +9 -6
- package/dist/index.cjs +69 -436
- 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 +71 -433
- 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, { skipPythUpdate: options.
|
|
5314
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
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, { skipPythUpdate:
|
|
5343
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
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, { skipPythUpdate:
|
|
5368
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
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, { skipPythUpdate: options.
|
|
5385
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: options.skipPythUpdate });
|
|
5393
5386
|
try {
|
|
5394
5387
|
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5395
5388
|
if (options.collectFee) {
|
|
@@ -5421,8 +5414,8 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
5421
5414
|
const rawAmount = Math.min(rawRequested, Number(totalBalance));
|
|
5422
5415
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
5423
5416
|
await refreshOracle(tx, client, address, {
|
|
5424
|
-
|
|
5425
|
-
|
|
5417
|
+
skipOracle: options.skipOracle,
|
|
5418
|
+
skipPythUpdate: options.skipPythUpdate
|
|
5426
5419
|
});
|
|
5427
5420
|
try {
|
|
5428
5421
|
await xe(tx, assetInfo.type, repayCoin, {
|
|
@@ -5736,7 +5729,10 @@ var NaviAdapter = class {
|
|
|
5736
5729
|
}
|
|
5737
5730
|
async buildWithdrawTx(address, amount, asset, options) {
|
|
5738
5731
|
const normalized = normalizeAsset(asset);
|
|
5739
|
-
const result = await buildWithdrawTx(this.client, address, amount, {
|
|
5732
|
+
const result = await buildWithdrawTx(this.client, address, amount, {
|
|
5733
|
+
asset: normalized,
|
|
5734
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
5735
|
+
});
|
|
5740
5736
|
return { tx: result.tx, effectiveAmount: result.effectiveAmount };
|
|
5741
5737
|
}
|
|
5742
5738
|
async buildBorrowTx(address, amount, asset, options) {
|
|
@@ -5748,8 +5744,8 @@ var NaviAdapter = class {
|
|
|
5748
5744
|
const normalized = normalizeAsset(asset);
|
|
5749
5745
|
const tx = await buildRepayTx(this.client, address, amount, {
|
|
5750
5746
|
asset: normalized,
|
|
5751
|
-
|
|
5752
|
-
|
|
5747
|
+
skipOracle: options?.skipOracle,
|
|
5748
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
5753
5749
|
});
|
|
5754
5750
|
return { tx };
|
|
5755
5751
|
}
|
|
@@ -5759,17 +5755,23 @@ var NaviAdapter = class {
|
|
|
5759
5755
|
async maxBorrow(address, _asset) {
|
|
5760
5756
|
return maxBorrowAmount(this.client, address);
|
|
5761
5757
|
}
|
|
5762
|
-
async addWithdrawToTx(tx, address, amount, asset) {
|
|
5758
|
+
async addWithdrawToTx(tx, address, amount, asset, options) {
|
|
5763
5759
|
const normalized = normalizeAsset(asset);
|
|
5764
|
-
return addWithdrawToTx(tx, this.client, address, amount, {
|
|
5760
|
+
return addWithdrawToTx(tx, this.client, address, amount, {
|
|
5761
|
+
asset: normalized,
|
|
5762
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
5763
|
+
});
|
|
5765
5764
|
}
|
|
5766
5765
|
async addSaveToTx(tx, address, coin, asset, options) {
|
|
5767
5766
|
const normalized = normalizeAsset(asset);
|
|
5768
5767
|
return addSaveToTx(tx, this.client, address, coin, { ...options, asset: normalized });
|
|
5769
5768
|
}
|
|
5770
|
-
async addRepayToTx(tx, address, coin, asset) {
|
|
5769
|
+
async addRepayToTx(tx, address, coin, asset, options) {
|
|
5771
5770
|
const normalized = normalizeAsset(asset);
|
|
5772
|
-
return addRepayToTx(tx, this.client, address, coin, {
|
|
5771
|
+
return addRepayToTx(tx, this.client, address, coin, {
|
|
5772
|
+
asset: normalized,
|
|
5773
|
+
skipPythUpdate: options?.skipPythUpdate
|
|
5774
|
+
});
|
|
5773
5775
|
}
|
|
5774
5776
|
async getPendingRewards(address) {
|
|
5775
5777
|
return getPendingRewards(this.client, address);
|
|
@@ -5778,339 +5780,6 @@ var NaviAdapter = class {
|
|
|
5778
5780
|
return addClaimRewardsToTx(tx, this.client, address);
|
|
5779
5781
|
}
|
|
5780
5782
|
};
|
|
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
5783
|
|
|
6115
5784
|
// src/t2000.ts
|
|
6116
5785
|
init_errors();
|
|
@@ -6355,6 +6024,25 @@ var ContactManager = class {
|
|
|
6355
6024
|
}
|
|
6356
6025
|
};
|
|
6357
6026
|
var DEFAULT_CONFIG_DIR = path.join(os.homedir(), ".t2000");
|
|
6027
|
+
async function executeTx(client, signer, buildTx) {
|
|
6028
|
+
const tx = await buildTx();
|
|
6029
|
+
tx.setSender(signer.getAddress());
|
|
6030
|
+
const txBytes = await tx.build({ client });
|
|
6031
|
+
const { signature } = await signer.signTransaction(txBytes);
|
|
6032
|
+
const result = await client.executeTransactionBlock({
|
|
6033
|
+
transactionBlock: txBytes,
|
|
6034
|
+
signature,
|
|
6035
|
+
options: { showEffects: true }
|
|
6036
|
+
});
|
|
6037
|
+
await client.waitForTransaction({ digest: result.digest });
|
|
6038
|
+
const gasUsed = result.effects?.gasUsed;
|
|
6039
|
+
let gasCostSui = 0;
|
|
6040
|
+
if (gasUsed) {
|
|
6041
|
+
const total = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
|
|
6042
|
+
gasCostSui = Number(total) / 1e9;
|
|
6043
|
+
}
|
|
6044
|
+
return { digest: result.digest, gasCostSui, effects: result.effects ?? void 0 };
|
|
6045
|
+
}
|
|
6358
6046
|
var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
6359
6047
|
_signer;
|
|
6360
6048
|
_keypair;
|
|
@@ -6389,16 +6077,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6389
6077
|
return registry;
|
|
6390
6078
|
}
|
|
6391
6079
|
static async create(options = {}) {
|
|
6392
|
-
const { keyPath, pin, passphrase,
|
|
6080
|
+
const { keyPath, pin, passphrase, rpcUrl } = options;
|
|
6393
6081
|
const secret = pin ?? passphrase;
|
|
6394
6082
|
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
6083
|
const exists = await walletExists(keyPath);
|
|
6403
6084
|
if (!exists) {
|
|
6404
6085
|
throw new exports.T2000Error(
|
|
@@ -6424,15 +6105,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6424
6105
|
const client = getSuiClient();
|
|
6425
6106
|
const agent = new _T2000(keypair, client, void 0, DEFAULT_CONFIG_DIR);
|
|
6426
6107
|
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 };
|
|
6108
|
+
return { agent, address };
|
|
6436
6109
|
}
|
|
6437
6110
|
// -- Gas --
|
|
6438
6111
|
/** SuiJsonRpcClient used by this agent — exposed for integrations. */
|
|
@@ -6465,7 +6138,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6465
6138
|
client,
|
|
6466
6139
|
signer: { toSuiAddress: () => signerAddress },
|
|
6467
6140
|
execute: async (tx) => {
|
|
6468
|
-
const result = await
|
|
6141
|
+
const result = await executeTx(client, signer, () => tx);
|
|
6469
6142
|
return { digest: result.digest, effects: result.effects };
|
|
6470
6143
|
}
|
|
6471
6144
|
})]
|
|
@@ -6503,7 +6176,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6503
6176
|
const { buildStakeVSuiTx: buildStakeVSuiTx2, getVoloStats: getVoloStats2 } = await Promise.resolve().then(() => (init_volo(), volo_exports));
|
|
6504
6177
|
const amountMist = BigInt(Math.floor(params.amount * Number(MIST_PER_SUI)));
|
|
6505
6178
|
const stats = await getVoloStats2();
|
|
6506
|
-
const gasResult = await
|
|
6179
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6507
6180
|
return buildStakeVSuiTx2(this.client, this._address, amountMist);
|
|
6508
6181
|
});
|
|
6509
6182
|
const vSuiReceived = params.amount / stats.exchangeRate;
|
|
@@ -6513,8 +6186,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6513
6186
|
amountSui: params.amount,
|
|
6514
6187
|
vSuiReceived,
|
|
6515
6188
|
apy: stats.apy,
|
|
6516
|
-
gasCost: gasResult.gasCostSui
|
|
6517
|
-
gasMethod: gasResult.gasMethod
|
|
6189
|
+
gasCost: gasResult.gasCostSui
|
|
6518
6190
|
};
|
|
6519
6191
|
}
|
|
6520
6192
|
async unstakeVSui(params) {
|
|
@@ -6531,7 +6203,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6531
6203
|
vSuiAmount = params.amount;
|
|
6532
6204
|
}
|
|
6533
6205
|
const stats = await getVoloStats2();
|
|
6534
|
-
const gasResult = await
|
|
6206
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6535
6207
|
return buildUnstakeVSuiTx2(this.client, this._address, amountMist);
|
|
6536
6208
|
});
|
|
6537
6209
|
const suiReceived = vSuiAmount * stats.exchangeRate;
|
|
@@ -6540,8 +6212,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6540
6212
|
tx: gasResult.digest,
|
|
6541
6213
|
vSuiAmount,
|
|
6542
6214
|
suiReceived,
|
|
6543
|
-
gasCost: gasResult.gasCostSui
|
|
6544
|
-
gasMethod: gasResult.gasMethod
|
|
6215
|
+
gasCost: gasResult.gasCostSui
|
|
6545
6216
|
};
|
|
6546
6217
|
}
|
|
6547
6218
|
// -- Swap --
|
|
@@ -6575,7 +6246,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6575
6246
|
preBalRaw = BigInt(preBal.totalBalance);
|
|
6576
6247
|
} catch {
|
|
6577
6248
|
}
|
|
6578
|
-
const gasResult = await
|
|
6249
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6579
6250
|
const tx = new transactions.Transaction();
|
|
6580
6251
|
tx.setSender(this._address);
|
|
6581
6252
|
let inputCoin;
|
|
@@ -6644,8 +6315,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6644
6315
|
toAmount,
|
|
6645
6316
|
priceImpact: route.priceImpact,
|
|
6646
6317
|
route: routeDesc,
|
|
6647
|
-
gasCost: gasResult.gasCostSui
|
|
6648
|
-
gasMethod: gasResult.gasMethod
|
|
6318
|
+
gasCost: gasResult.gasCostSui
|
|
6649
6319
|
};
|
|
6650
6320
|
}
|
|
6651
6321
|
async swapQuote(params) {
|
|
@@ -6692,11 +6362,10 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6692
6362
|
const resolved = this.contacts.resolve(params.to);
|
|
6693
6363
|
const sendAmount = params.amount;
|
|
6694
6364
|
const sendTo = resolved.address;
|
|
6695
|
-
const gasResult = await
|
|
6365
|
+
const gasResult = await executeTx(
|
|
6696
6366
|
this.client,
|
|
6697
6367
|
this._signer,
|
|
6698
|
-
() => buildSendTx({ client: this.client, address: this._address, to: sendTo, amount: sendAmount, asset })
|
|
6699
|
-
{ metadata: { operation: "send", amount: sendAmount }, enforcer: this.enforcer }
|
|
6368
|
+
() => buildSendTx({ client: this.client, address: this._address, to: sendTo, amount: sendAmount, asset })
|
|
6700
6369
|
);
|
|
6701
6370
|
this.enforcer.recordUsage(sendAmount);
|
|
6702
6371
|
const balance = await this.balance();
|
|
@@ -6709,7 +6378,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6709
6378
|
contactName: resolved.contactName,
|
|
6710
6379
|
gasCost: gasResult.gasCostSui,
|
|
6711
6380
|
gasCostUnit: "SUI",
|
|
6712
|
-
gasMethod: gasResult.gasMethod,
|
|
6713
6381
|
balance
|
|
6714
6382
|
};
|
|
6715
6383
|
}
|
|
@@ -6842,7 +6510,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6842
6510
|
const saveAmount = amount;
|
|
6843
6511
|
const adapter = await this.resolveLending(params.protocol, asset, "save");
|
|
6844
6512
|
const canPTB = !!adapter.addSaveToTx;
|
|
6845
|
-
const gasResult = await
|
|
6513
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6846
6514
|
if (canPTB) {
|
|
6847
6515
|
const tx2 = new transactions.Transaction();
|
|
6848
6516
|
tx2.setSender(this._address);
|
|
@@ -6880,7 +6548,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6880
6548
|
apy: rates.saveApy,
|
|
6881
6549
|
fee: fee.amount,
|
|
6882
6550
|
gasCost: gasResult.gasCostSui,
|
|
6883
|
-
gasMethod: gasResult.gasMethod,
|
|
6884
6551
|
savingsBalance
|
|
6885
6552
|
};
|
|
6886
6553
|
}
|
|
@@ -6939,7 +6606,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6939
6606
|
}
|
|
6940
6607
|
const withdrawAmount = amount;
|
|
6941
6608
|
let finalAmount = withdrawAmount;
|
|
6942
|
-
const gasResult = await
|
|
6609
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6943
6610
|
if (adapter.addWithdrawToTx) {
|
|
6944
6611
|
const tx = new transactions.Transaction();
|
|
6945
6612
|
tx.setSender(this._address);
|
|
@@ -6958,8 +6625,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6958
6625
|
tx: gasResult.digest,
|
|
6959
6626
|
amount: finalAmount,
|
|
6960
6627
|
asset: target.asset,
|
|
6961
|
-
gasCost: gasResult.gasCostSui
|
|
6962
|
-
gasMethod: gasResult.gasMethod
|
|
6628
|
+
gasCost: gasResult.gasCostSui
|
|
6963
6629
|
};
|
|
6964
6630
|
}
|
|
6965
6631
|
async withdrawAllProtocols() {
|
|
@@ -6996,7 +6662,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
6996
6662
|
}
|
|
6997
6663
|
let totalReceived = 0;
|
|
6998
6664
|
const canPTB = entries.every((e) => e.adapter.addWithdrawToTx);
|
|
6999
|
-
const gasResult = await
|
|
6665
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7000
6666
|
if (canPTB) {
|
|
7001
6667
|
const tx = new transactions.Transaction();
|
|
7002
6668
|
tx.setSender(this._address);
|
|
@@ -7027,8 +6693,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7027
6693
|
success: true,
|
|
7028
6694
|
tx: gasResult.digest,
|
|
7029
6695
|
amount: totalReceived,
|
|
7030
|
-
gasCost: gasResult.gasCostSui
|
|
7031
|
-
gasMethod: gasResult.gasMethod
|
|
6696
|
+
gasCost: gasResult.gasCostSui
|
|
7032
6697
|
};
|
|
7033
6698
|
}
|
|
7034
6699
|
/**
|
|
@@ -7146,7 +6811,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7146
6811
|
}
|
|
7147
6812
|
const fee = calculateFee("borrow", params.amount);
|
|
7148
6813
|
const borrowAmount = params.amount;
|
|
7149
|
-
const gasResult = await
|
|
6814
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7150
6815
|
const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset, { collectFee: true });
|
|
7151
6816
|
return tx;
|
|
7152
6817
|
});
|
|
@@ -7160,8 +6825,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7160
6825
|
asset,
|
|
7161
6826
|
fee: fee.amount,
|
|
7162
6827
|
healthFactor: hf.healthFactor,
|
|
7163
|
-
gasCost: gasResult.gasCostSui
|
|
7164
|
-
gasMethod: gasResult.gasMethod
|
|
6828
|
+
gasCost: gasResult.gasCostSui
|
|
7165
6829
|
};
|
|
7166
6830
|
}
|
|
7167
6831
|
async repay(params) {
|
|
@@ -7190,7 +6854,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7190
6854
|
if (!adapter) throw new exports.T2000Error("PROTOCOL_UNAVAILABLE", `Protocol ${target.protocolId} not found`);
|
|
7191
6855
|
const repayAmount = Math.min(params.amount, target.amount);
|
|
7192
6856
|
const targetAssetInfo = SUPPORTED_ASSETS[target.asset] ?? SUPPORTED_ASSETS.USDC;
|
|
7193
|
-
const gasResult = await
|
|
6857
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7194
6858
|
if (adapter.addRepayToTx) {
|
|
7195
6859
|
const tx2 = new transactions.Transaction();
|
|
7196
6860
|
tx2.setSender(this._address);
|
|
@@ -7213,8 +6877,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7213
6877
|
amount: repayAmount,
|
|
7214
6878
|
asset: target.asset,
|
|
7215
6879
|
remainingDebt: hf.borrowed,
|
|
7216
|
-
gasCost: gasResult.gasCostSui
|
|
7217
|
-
gasMethod: gasResult.gasMethod
|
|
6880
|
+
gasCost: gasResult.gasCostSui
|
|
7218
6881
|
};
|
|
7219
6882
|
}
|
|
7220
6883
|
async _repayAllBorrows(borrows) {
|
|
@@ -7226,7 +6889,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7226
6889
|
}
|
|
7227
6890
|
const canPTB = entries.every((e) => e.adapter.addRepayToTx);
|
|
7228
6891
|
let totalRepaid = 0;
|
|
7229
|
-
const gasResult = await
|
|
6892
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7230
6893
|
if (canPTB) {
|
|
7231
6894
|
const tx = new transactions.Transaction();
|
|
7232
6895
|
tx.setSender(this._address);
|
|
@@ -7267,8 +6930,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7267
6930
|
amount: totalRepaid,
|
|
7268
6931
|
asset: dominantAsset,
|
|
7269
6932
|
remainingDebt: hf.borrowed,
|
|
7270
|
-
gasCost: gasResult.gasCostSui
|
|
7271
|
-
gasMethod: gasResult.gasMethod
|
|
6933
|
+
gasCost: gasResult.gasCostSui
|
|
7272
6934
|
};
|
|
7273
6935
|
}
|
|
7274
6936
|
async maxBorrow() {
|
|
@@ -7301,7 +6963,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7301
6963
|
this.enforcer.assertNotLocked();
|
|
7302
6964
|
const adapters = this.registry.listLending().filter((a) => a.addClaimRewardsToTx);
|
|
7303
6965
|
if (adapters.length === 0) {
|
|
7304
|
-
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0
|
|
6966
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
|
|
7305
6967
|
}
|
|
7306
6968
|
const tx = new transactions.Transaction();
|
|
7307
6969
|
tx.setSender(this._address);
|
|
@@ -7314,9 +6976,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7314
6976
|
}
|
|
7315
6977
|
}
|
|
7316
6978
|
if (allRewards.length === 0) {
|
|
7317
|
-
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0
|
|
6979
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
|
|
7318
6980
|
}
|
|
7319
|
-
const claimResult = await
|
|
6981
|
+
const claimResult = await executeTx(this.client, this._signer, async () => tx);
|
|
7320
6982
|
await this.client.waitForTransaction({ digest: claimResult.digest });
|
|
7321
6983
|
const totalValueUsd = allRewards.reduce((s, r) => s + r.estimatedValueUsd, 0);
|
|
7322
6984
|
return {
|
|
@@ -7324,8 +6986,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7324
6986
|
tx: claimResult.digest,
|
|
7325
6987
|
rewards: allRewards,
|
|
7326
6988
|
totalValueUsd,
|
|
7327
|
-
gasCost: claimResult.gasCostSui
|
|
7328
|
-
gasMethod: claimResult.gasMethod
|
|
6989
|
+
gasCost: claimResult.gasCostSui
|
|
7329
6990
|
};
|
|
7330
6991
|
}
|
|
7331
6992
|
/**
|
|
@@ -7397,7 +7058,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7397
7058
|
byAmountIn: true
|
|
7398
7059
|
});
|
|
7399
7060
|
if (!route || route.insufficientLiquidity) continue;
|
|
7400
|
-
const swapResult = await
|
|
7061
|
+
const swapResult = await executeTx(this.client, this._signer, async () => {
|
|
7401
7062
|
const tx = new transactions.Transaction();
|
|
7402
7063
|
tx.setSender(this._address);
|
|
7403
7064
|
const freshCoins = await this._fetchCoins(reward.coinType);
|
|
@@ -7428,7 +7089,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7428
7089
|
if (gainedRaw > 0n) {
|
|
7429
7090
|
try {
|
|
7430
7091
|
const adapter = await this.resolveLending(void 0, "USDC", "save");
|
|
7431
|
-
const depositResult = await
|
|
7092
|
+
const depositResult = await executeTx(this.client, this._signer, async () => {
|
|
7432
7093
|
const tx = new transactions.Transaction();
|
|
7433
7094
|
tx.setSender(this._address);
|
|
7434
7095
|
const coins = await this._fetchCoins(USDC_TYPE2);
|
|
@@ -7559,29 +7220,6 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
7559
7220
|
this.emit("balanceChange", { asset, previous: 0, current: 0, cause, tx });
|
|
7560
7221
|
}
|
|
7561
7222
|
};
|
|
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
7223
|
|
|
7586
7224
|
// src/index.ts
|
|
7587
7225
|
init_errors();
|
|
@@ -7806,8 +7444,6 @@ exports.calculateFee = calculateFee;
|
|
|
7806
7444
|
exports.classifyAction = classifyAction;
|
|
7807
7445
|
exports.classifyLabel = classifyLabel;
|
|
7808
7446
|
exports.classifyTransaction = classifyTransaction;
|
|
7809
|
-
exports.executeAutoTopUp = executeAutoTopUp;
|
|
7810
|
-
exports.executeWithGas = executeWithGas;
|
|
7811
7447
|
exports.exportPrivateKey = exportPrivateKey;
|
|
7812
7448
|
exports.extractTransferDetails = extractTransferDetails;
|
|
7813
7449
|
exports.extractTxCommands = extractTxCommands;
|
|
@@ -7822,7 +7458,6 @@ exports.getAddress = getAddress;
|
|
|
7822
7458
|
exports.getDecimals = getDecimals;
|
|
7823
7459
|
exports.getDecimalsForCoinType = getDecimalsForCoinType;
|
|
7824
7460
|
exports.getFinancialSummary = getFinancialSummary;
|
|
7825
|
-
exports.getGasStatus = getGasStatus;
|
|
7826
7461
|
exports.getPendingRewards = getPendingRewards;
|
|
7827
7462
|
exports.getRates = getRates;
|
|
7828
7463
|
exports.getSwapQuote = getSwapQuote;
|
|
@@ -7848,9 +7483,7 @@ exports.refineLendingLabel = refineLendingLabel;
|
|
|
7848
7483
|
exports.resolveSymbol = resolveSymbol;
|
|
7849
7484
|
exports.resolveTokenType = resolveTokenType;
|
|
7850
7485
|
exports.saveKey = saveKey;
|
|
7851
|
-
exports.shouldAutoTopUp = shouldAutoTopUp;
|
|
7852
7486
|
exports.simulateTransaction = simulateTransaction;
|
|
7853
|
-
exports.solveHashcash = solveHashcash;
|
|
7854
7487
|
exports.stableToRaw = stableToRaw;
|
|
7855
7488
|
exports.suiToMist = suiToMist;
|
|
7856
7489
|
exports.throwIfSimulationFailed = throwIfSimulationFailed;
|