@t2000/sdk 0.56.0 → 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.js
CHANGED
|
@@ -6,7 +6,7 @@ import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';
|
|
|
6
6
|
import { normalizeSuiAddress, isValidSuiAddress, normalizeStructTag } from '@mysten/sui/utils';
|
|
7
7
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
8
8
|
import { decodeSuiPrivateKey } from '@mysten/sui/cryptography';
|
|
9
|
-
import {
|
|
9
|
+
import { randomBytes, createCipheriv, createDecipheriv, scryptSync } from 'crypto';
|
|
10
10
|
import { access, mkdir, writeFile, readFile } from 'fs/promises';
|
|
11
11
|
import { join as join$1, dirname, resolve } from 'path';
|
|
12
12
|
import { homedir } from 'os';
|
|
@@ -809,9 +809,6 @@ var MIST_PER_SUI = 1000000000n;
|
|
|
809
809
|
var SUI_DECIMALS = 9;
|
|
810
810
|
var USDC_DECIMALS = 6;
|
|
811
811
|
var BPS_DENOMINATOR = 10000n;
|
|
812
|
-
var AUTO_TOPUP_THRESHOLD = 50000000n;
|
|
813
|
-
var GAS_RESERVE_TARGET = 150000000n;
|
|
814
|
-
var AUTO_TOPUP_MIN_USDC = 2000000n;
|
|
815
812
|
var SAVE_FEE_BPS = 10n;
|
|
816
813
|
var BORROW_FEE_BPS = 5n;
|
|
817
814
|
var CLOCK_ID = "0x6";
|
|
@@ -5122,8 +5119,6 @@ async function refreshOracle(tx, client, address, options) {
|
|
|
5122
5119
|
const oracleOpts = {
|
|
5123
5120
|
...sdkOptions(client),
|
|
5124
5121
|
throws: false,
|
|
5125
|
-
// Pyth update uses tx.splitCoins(tx.gas, ...) which is incompatible
|
|
5126
|
-
// with sponsored transactions where tx.gas belongs to the sponsor.
|
|
5127
5122
|
updatePythPriceFeeds: !options?.skipPythUpdate
|
|
5128
5123
|
};
|
|
5129
5124
|
await mt(tx, address, pools, oracleOpts);
|
|
@@ -5314,7 +5309,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
5314
5309
|
}
|
|
5315
5310
|
const tx = new Transaction();
|
|
5316
5311
|
tx.setSender(address);
|
|
5317
|
-
await refreshOracle(tx, client, address
|
|
5312
|
+
await refreshOracle(tx, client, address);
|
|
5318
5313
|
try {
|
|
5319
5314
|
const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5320
5315
|
tx.transferObjects([coin], address);
|
|
@@ -5326,7 +5321,6 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
5326
5321
|
}
|
|
5327
5322
|
async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
5328
5323
|
const asset = options.asset ?? "USDC";
|
|
5329
|
-
const sponsored = options.sponsored ?? true;
|
|
5330
5324
|
const assetInfo = resolveAssetInfo(asset);
|
|
5331
5325
|
const posResult = await getPositions(client, address);
|
|
5332
5326
|
const supply = posResult.positions.find(
|
|
@@ -5344,7 +5338,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
5344
5338
|
});
|
|
5345
5339
|
return { coin, effectiveAmount: 0 };
|
|
5346
5340
|
}
|
|
5347
|
-
await refreshOracle(tx, client, address
|
|
5341
|
+
await refreshOracle(tx, client, address);
|
|
5348
5342
|
try {
|
|
5349
5343
|
const coin = await Qe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5350
5344
|
return { coin, effectiveAmount };
|
|
@@ -5368,9 +5362,8 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
|
5368
5362
|
}
|
|
5369
5363
|
async function addRepayToTx(tx, client, address, coin, options = {}) {
|
|
5370
5364
|
const asset = options.asset ?? "USDC";
|
|
5371
|
-
const sponsored = options.sponsored ?? true;
|
|
5372
5365
|
const assetInfo = resolveAssetInfo(asset);
|
|
5373
|
-
await refreshOracle(tx, client, address
|
|
5366
|
+
await refreshOracle(tx, client, address);
|
|
5374
5367
|
try {
|
|
5375
5368
|
await xe(tx, assetInfo.type, coin, { env: "prod" });
|
|
5376
5369
|
} catch (err) {
|
|
@@ -5387,7 +5380,7 @@ async function buildBorrowTx(client, address, amount, options = {}) {
|
|
|
5387
5380
|
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
5388
5381
|
const tx = new Transaction();
|
|
5389
5382
|
tx.setSender(address);
|
|
5390
|
-
await refreshOracle(tx, client, address
|
|
5383
|
+
await refreshOracle(tx, client, address);
|
|
5391
5384
|
try {
|
|
5392
5385
|
const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
5393
5386
|
if (options.collectFee) {
|
|
@@ -5418,10 +5411,7 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
5418
5411
|
const coinObj = mergeCoins(tx, coins);
|
|
5419
5412
|
const rawAmount = Math.min(rawRequested, Number(totalBalance));
|
|
5420
5413
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
5421
|
-
await refreshOracle(tx, client, address, {
|
|
5422
|
-
skipPythUpdate: options.sponsored,
|
|
5423
|
-
skipOracle: options.skipOracle
|
|
5424
|
-
});
|
|
5414
|
+
await refreshOracle(tx, client, address, { skipOracle: options.skipOracle });
|
|
5425
5415
|
try {
|
|
5426
5416
|
await xe(tx, assetInfo.type, repayCoin, {
|
|
5427
5417
|
...sdkOptions(client),
|
|
@@ -5732,9 +5722,9 @@ var NaviAdapter = class {
|
|
|
5732
5722
|
const tx = await buildSaveTx(this.client, address, amount, { ...options, asset: normalized });
|
|
5733
5723
|
return { tx };
|
|
5734
5724
|
}
|
|
5735
|
-
async buildWithdrawTx(address, amount, asset
|
|
5725
|
+
async buildWithdrawTx(address, amount, asset) {
|
|
5736
5726
|
const normalized = normalizeAsset(asset);
|
|
5737
|
-
const result = await buildWithdrawTx(this.client, address, amount, { asset: normalized
|
|
5727
|
+
const result = await buildWithdrawTx(this.client, address, amount, { asset: normalized });
|
|
5738
5728
|
return { tx: result.tx, effectiveAmount: result.effectiveAmount };
|
|
5739
5729
|
}
|
|
5740
5730
|
async buildBorrowTx(address, amount, asset, options) {
|
|
@@ -5746,7 +5736,6 @@ var NaviAdapter = class {
|
|
|
5746
5736
|
const normalized = normalizeAsset(asset);
|
|
5747
5737
|
const tx = await buildRepayTx(this.client, address, amount, {
|
|
5748
5738
|
asset: normalized,
|
|
5749
|
-
sponsored: options?.sponsored,
|
|
5750
5739
|
skipOracle: options?.skipOracle
|
|
5751
5740
|
});
|
|
5752
5741
|
return { tx };
|
|
@@ -5776,339 +5765,6 @@ var NaviAdapter = class {
|
|
|
5776
5765
|
return addClaimRewardsToTx(tx, this.client, address);
|
|
5777
5766
|
}
|
|
5778
5767
|
};
|
|
5779
|
-
function hasLeadingZeroBits(hash, bits) {
|
|
5780
|
-
const fullBytes = Math.floor(bits / 8);
|
|
5781
|
-
const remainingBits = bits % 8;
|
|
5782
|
-
for (let i = 0; i < fullBytes; i++) {
|
|
5783
|
-
if (hash[i] !== 0) return false;
|
|
5784
|
-
}
|
|
5785
|
-
if (remainingBits > 0) {
|
|
5786
|
-
const mask = 255 << 8 - remainingBits;
|
|
5787
|
-
if ((hash[fullBytes] & mask) !== 0) return false;
|
|
5788
|
-
}
|
|
5789
|
-
return true;
|
|
5790
|
-
}
|
|
5791
|
-
function solveHashcash(challenge) {
|
|
5792
|
-
const bits = parseInt(challenge.split(":")[1], 10);
|
|
5793
|
-
let counter = 0;
|
|
5794
|
-
while (true) {
|
|
5795
|
-
const stamp = `${challenge}${counter.toString(16)}`;
|
|
5796
|
-
const hash = createHash("sha256").update(stamp).digest();
|
|
5797
|
-
if (hasLeadingZeroBits(hash, bits)) return stamp;
|
|
5798
|
-
counter++;
|
|
5799
|
-
}
|
|
5800
|
-
}
|
|
5801
|
-
|
|
5802
|
-
// src/gas/manager.ts
|
|
5803
|
-
init_errors();
|
|
5804
|
-
|
|
5805
|
-
// src/gas/autoTopUp.ts
|
|
5806
|
-
async function shouldAutoTopUp(client, address) {
|
|
5807
|
-
const [suiBalance, usdcBalance] = await Promise.all([
|
|
5808
|
-
client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS.SUI.type }),
|
|
5809
|
-
client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS.USDC.type })
|
|
5810
|
-
]);
|
|
5811
|
-
const suiRaw = BigInt(suiBalance.totalBalance);
|
|
5812
|
-
const usdcRaw = BigInt(usdcBalance.totalBalance);
|
|
5813
|
-
if (suiRaw < GAS_RESERVE_TARGET && usdcRaw >= AUTO_TOPUP_MIN_USDC) {
|
|
5814
|
-
return false;
|
|
5815
|
-
}
|
|
5816
|
-
return false;
|
|
5817
|
-
}
|
|
5818
|
-
async function executeAutoTopUp(_client, _signer) {
|
|
5819
|
-
return { success: false, tx: "", usdcSpent: 0, suiReceived: 0 };
|
|
5820
|
-
}
|
|
5821
|
-
|
|
5822
|
-
// src/gas/gasStation.ts
|
|
5823
|
-
init_errors();
|
|
5824
|
-
|
|
5825
|
-
// src/utils/base64.ts
|
|
5826
|
-
function toBase642(bytes) {
|
|
5827
|
-
let binary = "";
|
|
5828
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
5829
|
-
return btoa(binary);
|
|
5830
|
-
}
|
|
5831
|
-
function fromBase642(b64) {
|
|
5832
|
-
const binary = atob(b64);
|
|
5833
|
-
const bytes = new Uint8Array(binary.length);
|
|
5834
|
-
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
5835
|
-
return bytes;
|
|
5836
|
-
}
|
|
5837
|
-
|
|
5838
|
-
// src/gas/gasStation.ts
|
|
5839
|
-
async function requestGasSponsorship(txJson, sender, type, txBcsBytes) {
|
|
5840
|
-
const payload = { sender, type };
|
|
5841
|
-
if (txBcsBytes) {
|
|
5842
|
-
payload.txBcsBytes = txBcsBytes;
|
|
5843
|
-
} else {
|
|
5844
|
-
payload.txJson = txJson;
|
|
5845
|
-
payload.txBytes = toBase642(new TextEncoder().encode(txJson));
|
|
5846
|
-
}
|
|
5847
|
-
const res = await fetch(`${API_BASE_URL}/api/gas`, {
|
|
5848
|
-
method: "POST",
|
|
5849
|
-
headers: { "Content-Type": "application/json" },
|
|
5850
|
-
body: JSON.stringify(payload)
|
|
5851
|
-
});
|
|
5852
|
-
const data = await res.json();
|
|
5853
|
-
if (!res.ok) {
|
|
5854
|
-
const errorCode = data.error;
|
|
5855
|
-
if (errorCode === "CIRCUIT_BREAKER" || errorCode === "POOL_DEPLETED" || errorCode === "PRICE_STALE") {
|
|
5856
|
-
throw new T2000Error(
|
|
5857
|
-
"GAS_STATION_UNAVAILABLE",
|
|
5858
|
-
data.message ?? "Gas station temporarily unavailable",
|
|
5859
|
-
{ retryAfter: data.retryAfter, reason: errorCode },
|
|
5860
|
-
true
|
|
5861
|
-
);
|
|
5862
|
-
}
|
|
5863
|
-
if (errorCode === "GAS_FEE_EXCEEDED") {
|
|
5864
|
-
throw new T2000Error(
|
|
5865
|
-
"GAS_FEE_EXCEEDED",
|
|
5866
|
-
data.message ?? "Gas fee exceeds ceiling",
|
|
5867
|
-
{ retryAfter: data.retryAfter },
|
|
5868
|
-
true
|
|
5869
|
-
);
|
|
5870
|
-
}
|
|
5871
|
-
throw new T2000Error(
|
|
5872
|
-
"GAS_STATION_UNAVAILABLE",
|
|
5873
|
-
data.message ?? "Gas sponsorship request failed",
|
|
5874
|
-
{ reason: errorCode },
|
|
5875
|
-
true
|
|
5876
|
-
);
|
|
5877
|
-
}
|
|
5878
|
-
return data;
|
|
5879
|
-
}
|
|
5880
|
-
async function reportGasUsage(sender, txDigest, gasCostSui, usdcCharged, type) {
|
|
5881
|
-
try {
|
|
5882
|
-
await fetch(`${API_BASE_URL}/api/gas/report`, {
|
|
5883
|
-
method: "POST",
|
|
5884
|
-
headers: { "Content-Type": "application/json" },
|
|
5885
|
-
body: JSON.stringify({ sender, txDigest, gasCostSui, usdcCharged, type })
|
|
5886
|
-
});
|
|
5887
|
-
} catch {
|
|
5888
|
-
}
|
|
5889
|
-
}
|
|
5890
|
-
async function getGasStatus(address) {
|
|
5891
|
-
const url = new URL(`${API_BASE_URL}/api/gas/status`);
|
|
5892
|
-
if (address) url.searchParams.set("address", address);
|
|
5893
|
-
const res = await fetch(url.toString());
|
|
5894
|
-
if (!res.ok) {
|
|
5895
|
-
throw new T2000Error("GAS_STATION_UNAVAILABLE", "Failed to fetch gas status", void 0, true);
|
|
5896
|
-
}
|
|
5897
|
-
return await res.json();
|
|
5898
|
-
}
|
|
5899
|
-
|
|
5900
|
-
// src/gas/manager.ts
|
|
5901
|
-
function extractGasCost(effects) {
|
|
5902
|
-
if (!effects?.gasUsed) return 0;
|
|
5903
|
-
return (Number(effects.gasUsed.computationCost) + Number(effects.gasUsed.storageCost) - Number(effects.gasUsed.storageRebate)) / 1e9;
|
|
5904
|
-
}
|
|
5905
|
-
async function getSuiBalance(client, address) {
|
|
5906
|
-
const bal = await client.getBalance({ owner: address, coinType: SUPPORTED_ASSETS.SUI.type });
|
|
5907
|
-
return BigInt(bal.totalBalance);
|
|
5908
|
-
}
|
|
5909
|
-
async function assertTxSuccess(effects, digest) {
|
|
5910
|
-
const eff = effects;
|
|
5911
|
-
if (eff?.status?.status === "failure") {
|
|
5912
|
-
const errMsg = eff.status.error ?? "unknown on-chain error";
|
|
5913
|
-
if (isMoveAbort(errMsg)) {
|
|
5914
|
-
throw new T2000Error("TRANSACTION_FAILED", parseMoveAbortMessage(errMsg));
|
|
5915
|
-
}
|
|
5916
|
-
throw new T2000Error("TRANSACTION_FAILED", `Transaction ${digest} failed on-chain: ${errMsg}`);
|
|
5917
|
-
}
|
|
5918
|
-
}
|
|
5919
|
-
async function trySelfFunded(client, signer, tx) {
|
|
5920
|
-
const address = signer.getAddress();
|
|
5921
|
-
const suiBalance = await getSuiBalance(client, address);
|
|
5922
|
-
if (suiBalance < AUTO_TOPUP_THRESHOLD) return null;
|
|
5923
|
-
tx.setSender(address);
|
|
5924
|
-
const builtBytes = await tx.build({ client });
|
|
5925
|
-
const { signature } = await signer.signTransaction(builtBytes);
|
|
5926
|
-
const result = await client.executeTransactionBlock({
|
|
5927
|
-
transactionBlock: toBase642(builtBytes),
|
|
5928
|
-
signature: [signature],
|
|
5929
|
-
options: { showEffects: true, showBalanceChanges: true }
|
|
5930
|
-
});
|
|
5931
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
5932
|
-
await assertTxSuccess(result.effects, result.digest);
|
|
5933
|
-
return {
|
|
5934
|
-
digest: result.digest,
|
|
5935
|
-
effects: result.effects,
|
|
5936
|
-
balanceChanges: result.balanceChanges,
|
|
5937
|
-
gasMethod: "self-funded",
|
|
5938
|
-
gasCostSui: extractGasCost(result.effects),
|
|
5939
|
-
preTxSuiMist: suiBalance
|
|
5940
|
-
};
|
|
5941
|
-
}
|
|
5942
|
-
async function tryAutoTopUpThenSelfFund(client, signer, buildTx) {
|
|
5943
|
-
const address = signer.getAddress();
|
|
5944
|
-
const canTopUp = await shouldAutoTopUp(client, address);
|
|
5945
|
-
if (!canTopUp) return null;
|
|
5946
|
-
await executeAutoTopUp();
|
|
5947
|
-
const tx = await buildTx();
|
|
5948
|
-
tx.setSender(address);
|
|
5949
|
-
const suiAfterTopUp = await getSuiBalance(client, address);
|
|
5950
|
-
const builtBytes = await tx.build({ client });
|
|
5951
|
-
const { signature } = await signer.signTransaction(builtBytes);
|
|
5952
|
-
const result = await client.executeTransactionBlock({
|
|
5953
|
-
transactionBlock: toBase642(builtBytes),
|
|
5954
|
-
signature: [signature],
|
|
5955
|
-
options: { showEffects: true, showBalanceChanges: true }
|
|
5956
|
-
});
|
|
5957
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
5958
|
-
await assertTxSuccess(result.effects, result.digest);
|
|
5959
|
-
return {
|
|
5960
|
-
digest: result.digest,
|
|
5961
|
-
effects: result.effects,
|
|
5962
|
-
balanceChanges: result.balanceChanges,
|
|
5963
|
-
gasMethod: "auto-topup",
|
|
5964
|
-
gasCostSui: extractGasCost(result.effects),
|
|
5965
|
-
preTxSuiMist: suiAfterTopUp
|
|
5966
|
-
};
|
|
5967
|
-
}
|
|
5968
|
-
async function trySponsored(client, signer, tx) {
|
|
5969
|
-
const address = signer.getAddress();
|
|
5970
|
-
const suiBalance = await getSuiBalance(client, address);
|
|
5971
|
-
tx.setSender(address);
|
|
5972
|
-
let txJson;
|
|
5973
|
-
let txBcsBase64;
|
|
5974
|
-
try {
|
|
5975
|
-
txJson = tx.serialize();
|
|
5976
|
-
} catch {
|
|
5977
|
-
const bcsBytes = await tx.build({ client });
|
|
5978
|
-
txBcsBase64 = toBase642(bcsBytes);
|
|
5979
|
-
}
|
|
5980
|
-
const sponsoredResult = await requestGasSponsorship(txJson ?? "", address, void 0, txBcsBase64);
|
|
5981
|
-
const sponsoredTxBytes = fromBase642(sponsoredResult.txBytes);
|
|
5982
|
-
const { signature: agentSig } = await signer.signTransaction(sponsoredTxBytes);
|
|
5983
|
-
const result = await client.executeTransactionBlock({
|
|
5984
|
-
transactionBlock: sponsoredResult.txBytes,
|
|
5985
|
-
signature: [agentSig, sponsoredResult.sponsorSignature],
|
|
5986
|
-
options: { showEffects: true, showBalanceChanges: true }
|
|
5987
|
-
});
|
|
5988
|
-
await client.waitForTransaction({ digest: result.digest });
|
|
5989
|
-
await assertTxSuccess(result.effects, result.digest);
|
|
5990
|
-
const gasCost = extractGasCost(result.effects);
|
|
5991
|
-
reportGasUsage(address, result.digest, gasCost, 0, sponsoredResult.type);
|
|
5992
|
-
return {
|
|
5993
|
-
digest: result.digest,
|
|
5994
|
-
effects: result.effects,
|
|
5995
|
-
balanceChanges: result.balanceChanges,
|
|
5996
|
-
gasMethod: "sponsored",
|
|
5997
|
-
gasCostSui: gasCost,
|
|
5998
|
-
preTxSuiMist: suiBalance
|
|
5999
|
-
};
|
|
6000
|
-
}
|
|
6001
|
-
async function waitForIndexer(client, digest) {
|
|
6002
|
-
for (let i = 0; i < 3; i++) {
|
|
6003
|
-
try {
|
|
6004
|
-
await client.getTransactionBlock({ digest, options: { showObjectChanges: true } });
|
|
6005
|
-
return;
|
|
6006
|
-
} catch {
|
|
6007
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
6008
|
-
}
|
|
6009
|
-
}
|
|
6010
|
-
}
|
|
6011
|
-
async function executeWithGas(client, signer, buildTx, options) {
|
|
6012
|
-
if (options?.enforcer && options?.metadata) {
|
|
6013
|
-
options.enforcer.check(options.metadata);
|
|
6014
|
-
}
|
|
6015
|
-
const result = await resolveGas(client, signer, buildTx);
|
|
6016
|
-
try {
|
|
6017
|
-
if (result.preTxSuiMist !== void 0) {
|
|
6018
|
-
const gasCostMist = result.gasMethod === "sponsored" ? 0n : BigInt(Math.round(result.gasCostSui * 1e9));
|
|
6019
|
-
const estimatedRemaining = result.preTxSuiMist - gasCostMist;
|
|
6020
|
-
if (estimatedRemaining < GAS_RESERVE_TARGET) {
|
|
6021
|
-
const address = signer.getAddress();
|
|
6022
|
-
const usdcBal = await client.getBalance({
|
|
6023
|
-
owner: address,
|
|
6024
|
-
coinType: SUPPORTED_ASSETS.USDC.type
|
|
6025
|
-
});
|
|
6026
|
-
if (BigInt(usdcBal.totalBalance) >= AUTO_TOPUP_MIN_USDC) {
|
|
6027
|
-
await executeAutoTopUp(client, signer);
|
|
6028
|
-
}
|
|
6029
|
-
}
|
|
6030
|
-
}
|
|
6031
|
-
} catch {
|
|
6032
|
-
}
|
|
6033
|
-
return result;
|
|
6034
|
-
}
|
|
6035
|
-
var GAS_RESOLUTION_CODES = /* @__PURE__ */ new Set([
|
|
6036
|
-
"INSUFFICIENT_GAS",
|
|
6037
|
-
"GAS_STATION_UNAVAILABLE",
|
|
6038
|
-
"GAS_FEE_EXCEEDED",
|
|
6039
|
-
"AUTO_TOPUP_FAILED",
|
|
6040
|
-
"SPONSOR_UNAVAILABLE"
|
|
6041
|
-
]);
|
|
6042
|
-
function isBuildError(err) {
|
|
6043
|
-
return err instanceof T2000Error && !GAS_RESOLUTION_CODES.has(err.code);
|
|
6044
|
-
}
|
|
6045
|
-
async function resolveGas(client, signer, buildTx) {
|
|
6046
|
-
const errors = [];
|
|
6047
|
-
let lastBuildError;
|
|
6048
|
-
try {
|
|
6049
|
-
const tx = await buildTx();
|
|
6050
|
-
const result = await trySelfFunded(client, signer, tx);
|
|
6051
|
-
if (result) {
|
|
6052
|
-
await waitForIndexer(client, result.digest);
|
|
6053
|
-
return result;
|
|
6054
|
-
}
|
|
6055
|
-
errors.push("self-funded: SUI below threshold");
|
|
6056
|
-
} catch (err) {
|
|
6057
|
-
if (err instanceof T2000Error && err.code === "TRANSACTION_FAILED") throw err;
|
|
6058
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
6059
|
-
if (isMoveAbort(msg)) {
|
|
6060
|
-
throw new T2000Error("TRANSACTION_FAILED", parseMoveAbortMessage(msg));
|
|
6061
|
-
}
|
|
6062
|
-
if (isBuildError(err)) lastBuildError = err;
|
|
6063
|
-
errors.push(`self-funded: ${msg}`);
|
|
6064
|
-
}
|
|
6065
|
-
try {
|
|
6066
|
-
const result = await tryAutoTopUpThenSelfFund(client, signer, buildTx);
|
|
6067
|
-
if (result) {
|
|
6068
|
-
await waitForIndexer(client, result.digest);
|
|
6069
|
-
return result;
|
|
6070
|
-
}
|
|
6071
|
-
errors.push("auto-topup: not eligible (low USDC or sufficient SUI)");
|
|
6072
|
-
} catch (err) {
|
|
6073
|
-
if (err instanceof T2000Error && err.code === "TRANSACTION_FAILED") throw err;
|
|
6074
|
-
errors.push(`auto-topup: ${err instanceof Error ? err.message : String(err)}`);
|
|
6075
|
-
}
|
|
6076
|
-
try {
|
|
6077
|
-
const tx = await buildTx();
|
|
6078
|
-
const result = await trySelfFunded(client, signer, tx);
|
|
6079
|
-
if (result) {
|
|
6080
|
-
await waitForIndexer(client, result.digest);
|
|
6081
|
-
return result;
|
|
6082
|
-
}
|
|
6083
|
-
} catch (err) {
|
|
6084
|
-
if (err instanceof T2000Error && err.code === "TRANSACTION_FAILED") throw err;
|
|
6085
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
6086
|
-
if (isMoveAbort(msg)) {
|
|
6087
|
-
throw new T2000Error("TRANSACTION_FAILED", parseMoveAbortMessage(msg));
|
|
6088
|
-
}
|
|
6089
|
-
if (isBuildError(err)) lastBuildError = err;
|
|
6090
|
-
errors.push(`self-funded-retry: ${msg}`);
|
|
6091
|
-
}
|
|
6092
|
-
try {
|
|
6093
|
-
const tx = await buildTx();
|
|
6094
|
-
const result = await trySponsored(client, signer, tx);
|
|
6095
|
-
if (result) {
|
|
6096
|
-
await waitForIndexer(client, result.digest);
|
|
6097
|
-
return result;
|
|
6098
|
-
}
|
|
6099
|
-
errors.push("sponsored: returned null");
|
|
6100
|
-
} catch (err) {
|
|
6101
|
-
if (err instanceof T2000Error && err.code === "TRANSACTION_FAILED") throw err;
|
|
6102
|
-
if (isBuildError(err)) lastBuildError = err;
|
|
6103
|
-
errors.push(`sponsored: ${err instanceof Error ? err.message : String(err)}`);
|
|
6104
|
-
}
|
|
6105
|
-
if (lastBuildError) throw lastBuildError;
|
|
6106
|
-
throw new T2000Error(
|
|
6107
|
-
"INSUFFICIENT_GAS",
|
|
6108
|
-
`No SUI for gas and sponsorship unavailable. Fund your wallet with SUI or USDC. [${errors.join(" | ")}]`,
|
|
6109
|
-
{ reason: "all_gas_methods_exhausted", errors }
|
|
6110
|
-
);
|
|
6111
|
-
}
|
|
6112
5768
|
|
|
6113
5769
|
// src/t2000.ts
|
|
6114
5770
|
init_errors();
|
|
@@ -6353,6 +6009,25 @@ var ContactManager = class {
|
|
|
6353
6009
|
}
|
|
6354
6010
|
};
|
|
6355
6011
|
var DEFAULT_CONFIG_DIR = join$1(homedir(), ".t2000");
|
|
6012
|
+
async function executeTx(client, signer, buildTx) {
|
|
6013
|
+
const tx = await buildTx();
|
|
6014
|
+
tx.setSender(signer.getAddress());
|
|
6015
|
+
const txBytes = await tx.build({ client });
|
|
6016
|
+
const { signature } = await signer.signTransaction(txBytes);
|
|
6017
|
+
const result = await client.executeTransactionBlock({
|
|
6018
|
+
transactionBlock: txBytes,
|
|
6019
|
+
signature,
|
|
6020
|
+
options: { showEffects: true }
|
|
6021
|
+
});
|
|
6022
|
+
await client.waitForTransaction({ digest: result.digest });
|
|
6023
|
+
const gasUsed = result.effects?.gasUsed;
|
|
6024
|
+
let gasCostSui = 0;
|
|
6025
|
+
if (gasUsed) {
|
|
6026
|
+
const total = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
|
|
6027
|
+
gasCostSui = Number(total) / 1e9;
|
|
6028
|
+
}
|
|
6029
|
+
return { digest: result.digest, gasCostSui, effects: result.effects ?? void 0 };
|
|
6030
|
+
}
|
|
6356
6031
|
var T2000 = class _T2000 extends EventEmitter {
|
|
6357
6032
|
_signer;
|
|
6358
6033
|
_keypair;
|
|
@@ -6387,16 +6062,9 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6387
6062
|
return registry;
|
|
6388
6063
|
}
|
|
6389
6064
|
static async create(options = {}) {
|
|
6390
|
-
const { keyPath, pin, passphrase,
|
|
6065
|
+
const { keyPath, pin, passphrase, rpcUrl } = options;
|
|
6391
6066
|
const secret = pin ?? passphrase;
|
|
6392
6067
|
const client = getSuiClient(rpcUrl);
|
|
6393
|
-
if (sponsored) {
|
|
6394
|
-
const keypair2 = generateKeypair();
|
|
6395
|
-
if (secret) {
|
|
6396
|
-
await saveKey(keypair2, secret, keyPath);
|
|
6397
|
-
}
|
|
6398
|
-
return new _T2000(keypair2, client, void 0, DEFAULT_CONFIG_DIR);
|
|
6399
|
-
}
|
|
6400
6068
|
const exists = await walletExists(keyPath);
|
|
6401
6069
|
if (!exists) {
|
|
6402
6070
|
throw new T2000Error(
|
|
@@ -6422,15 +6090,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6422
6090
|
const client = getSuiClient();
|
|
6423
6091
|
const agent = new _T2000(keypair, client, void 0, DEFAULT_CONFIG_DIR);
|
|
6424
6092
|
const address = agent.address();
|
|
6425
|
-
|
|
6426
|
-
if (options.sponsored !== false) {
|
|
6427
|
-
try {
|
|
6428
|
-
await callSponsorApi(address, options.name);
|
|
6429
|
-
sponsored = true;
|
|
6430
|
-
} catch {
|
|
6431
|
-
}
|
|
6432
|
-
}
|
|
6433
|
-
return { agent, address, sponsored };
|
|
6093
|
+
return { agent, address };
|
|
6434
6094
|
}
|
|
6435
6095
|
// -- Gas --
|
|
6436
6096
|
/** SuiJsonRpcClient used by this agent — exposed for integrations. */
|
|
@@ -6463,7 +6123,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6463
6123
|
client,
|
|
6464
6124
|
signer: { toSuiAddress: () => signerAddress },
|
|
6465
6125
|
execute: async (tx) => {
|
|
6466
|
-
const result = await
|
|
6126
|
+
const result = await executeTx(client, signer, () => tx);
|
|
6467
6127
|
return { digest: result.digest, effects: result.effects };
|
|
6468
6128
|
}
|
|
6469
6129
|
})]
|
|
@@ -6501,7 +6161,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6501
6161
|
const { buildStakeVSuiTx: buildStakeVSuiTx2, getVoloStats: getVoloStats2 } = await Promise.resolve().then(() => (init_volo(), volo_exports));
|
|
6502
6162
|
const amountMist = BigInt(Math.floor(params.amount * Number(MIST_PER_SUI)));
|
|
6503
6163
|
const stats = await getVoloStats2();
|
|
6504
|
-
const gasResult = await
|
|
6164
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6505
6165
|
return buildStakeVSuiTx2(this.client, this._address, amountMist);
|
|
6506
6166
|
});
|
|
6507
6167
|
const vSuiReceived = params.amount / stats.exchangeRate;
|
|
@@ -6511,8 +6171,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6511
6171
|
amountSui: params.amount,
|
|
6512
6172
|
vSuiReceived,
|
|
6513
6173
|
apy: stats.apy,
|
|
6514
|
-
gasCost: gasResult.gasCostSui
|
|
6515
|
-
gasMethod: gasResult.gasMethod
|
|
6174
|
+
gasCost: gasResult.gasCostSui
|
|
6516
6175
|
};
|
|
6517
6176
|
}
|
|
6518
6177
|
async unstakeVSui(params) {
|
|
@@ -6529,7 +6188,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6529
6188
|
vSuiAmount = params.amount;
|
|
6530
6189
|
}
|
|
6531
6190
|
const stats = await getVoloStats2();
|
|
6532
|
-
const gasResult = await
|
|
6191
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6533
6192
|
return buildUnstakeVSuiTx2(this.client, this._address, amountMist);
|
|
6534
6193
|
});
|
|
6535
6194
|
const suiReceived = vSuiAmount * stats.exchangeRate;
|
|
@@ -6538,8 +6197,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6538
6197
|
tx: gasResult.digest,
|
|
6539
6198
|
vSuiAmount,
|
|
6540
6199
|
suiReceived,
|
|
6541
|
-
gasCost: gasResult.gasCostSui
|
|
6542
|
-
gasMethod: gasResult.gasMethod
|
|
6200
|
+
gasCost: gasResult.gasCostSui
|
|
6543
6201
|
};
|
|
6544
6202
|
}
|
|
6545
6203
|
// -- Swap --
|
|
@@ -6573,7 +6231,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6573
6231
|
preBalRaw = BigInt(preBal.totalBalance);
|
|
6574
6232
|
} catch {
|
|
6575
6233
|
}
|
|
6576
|
-
const gasResult = await
|
|
6234
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6577
6235
|
const tx = new Transaction();
|
|
6578
6236
|
tx.setSender(this._address);
|
|
6579
6237
|
let inputCoin;
|
|
@@ -6642,8 +6300,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6642
6300
|
toAmount,
|
|
6643
6301
|
priceImpact: route.priceImpact,
|
|
6644
6302
|
route: routeDesc,
|
|
6645
|
-
gasCost: gasResult.gasCostSui
|
|
6646
|
-
gasMethod: gasResult.gasMethod
|
|
6303
|
+
gasCost: gasResult.gasCostSui
|
|
6647
6304
|
};
|
|
6648
6305
|
}
|
|
6649
6306
|
async swapQuote(params) {
|
|
@@ -6690,11 +6347,10 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6690
6347
|
const resolved = this.contacts.resolve(params.to);
|
|
6691
6348
|
const sendAmount = params.amount;
|
|
6692
6349
|
const sendTo = resolved.address;
|
|
6693
|
-
const gasResult = await
|
|
6350
|
+
const gasResult = await executeTx(
|
|
6694
6351
|
this.client,
|
|
6695
6352
|
this._signer,
|
|
6696
|
-
() => buildSendTx({ client: this.client, address: this._address, to: sendTo, amount: sendAmount, asset })
|
|
6697
|
-
{ metadata: { operation: "send", amount: sendAmount }, enforcer: this.enforcer }
|
|
6353
|
+
() => buildSendTx({ client: this.client, address: this._address, to: sendTo, amount: sendAmount, asset })
|
|
6698
6354
|
);
|
|
6699
6355
|
this.enforcer.recordUsage(sendAmount);
|
|
6700
6356
|
const balance = await this.balance();
|
|
@@ -6707,7 +6363,6 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6707
6363
|
contactName: resolved.contactName,
|
|
6708
6364
|
gasCost: gasResult.gasCostSui,
|
|
6709
6365
|
gasCostUnit: "SUI",
|
|
6710
|
-
gasMethod: gasResult.gasMethod,
|
|
6711
6366
|
balance
|
|
6712
6367
|
};
|
|
6713
6368
|
}
|
|
@@ -6840,7 +6495,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6840
6495
|
const saveAmount = amount;
|
|
6841
6496
|
const adapter = await this.resolveLending(params.protocol, asset, "save");
|
|
6842
6497
|
const canPTB = !!adapter.addSaveToTx;
|
|
6843
|
-
const gasResult = await
|
|
6498
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6844
6499
|
if (canPTB) {
|
|
6845
6500
|
const tx2 = new Transaction();
|
|
6846
6501
|
tx2.setSender(this._address);
|
|
@@ -6878,7 +6533,6 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6878
6533
|
apy: rates.saveApy,
|
|
6879
6534
|
fee: fee.amount,
|
|
6880
6535
|
gasCost: gasResult.gasCostSui,
|
|
6881
|
-
gasMethod: gasResult.gasMethod,
|
|
6882
6536
|
savingsBalance
|
|
6883
6537
|
};
|
|
6884
6538
|
}
|
|
@@ -6937,7 +6591,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6937
6591
|
}
|
|
6938
6592
|
const withdrawAmount = amount;
|
|
6939
6593
|
let finalAmount = withdrawAmount;
|
|
6940
|
-
const gasResult = await
|
|
6594
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6941
6595
|
if (adapter.addWithdrawToTx) {
|
|
6942
6596
|
const tx = new Transaction();
|
|
6943
6597
|
tx.setSender(this._address);
|
|
@@ -6956,8 +6610,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6956
6610
|
tx: gasResult.digest,
|
|
6957
6611
|
amount: finalAmount,
|
|
6958
6612
|
asset: target.asset,
|
|
6959
|
-
gasCost: gasResult.gasCostSui
|
|
6960
|
-
gasMethod: gasResult.gasMethod
|
|
6613
|
+
gasCost: gasResult.gasCostSui
|
|
6961
6614
|
};
|
|
6962
6615
|
}
|
|
6963
6616
|
async withdrawAllProtocols() {
|
|
@@ -6994,7 +6647,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
6994
6647
|
}
|
|
6995
6648
|
let totalReceived = 0;
|
|
6996
6649
|
const canPTB = entries.every((e) => e.adapter.addWithdrawToTx);
|
|
6997
|
-
const gasResult = await
|
|
6650
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
6998
6651
|
if (canPTB) {
|
|
6999
6652
|
const tx = new Transaction();
|
|
7000
6653
|
tx.setSender(this._address);
|
|
@@ -7025,8 +6678,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7025
6678
|
success: true,
|
|
7026
6679
|
tx: gasResult.digest,
|
|
7027
6680
|
amount: totalReceived,
|
|
7028
|
-
gasCost: gasResult.gasCostSui
|
|
7029
|
-
gasMethod: gasResult.gasMethod
|
|
6681
|
+
gasCost: gasResult.gasCostSui
|
|
7030
6682
|
};
|
|
7031
6683
|
}
|
|
7032
6684
|
/**
|
|
@@ -7144,7 +6796,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7144
6796
|
}
|
|
7145
6797
|
const fee = calculateFee("borrow", params.amount);
|
|
7146
6798
|
const borrowAmount = params.amount;
|
|
7147
|
-
const gasResult = await
|
|
6799
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7148
6800
|
const { tx } = await adapter.buildBorrowTx(this._address, borrowAmount, asset, { collectFee: true });
|
|
7149
6801
|
return tx;
|
|
7150
6802
|
});
|
|
@@ -7158,8 +6810,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7158
6810
|
asset,
|
|
7159
6811
|
fee: fee.amount,
|
|
7160
6812
|
healthFactor: hf.healthFactor,
|
|
7161
|
-
gasCost: gasResult.gasCostSui
|
|
7162
|
-
gasMethod: gasResult.gasMethod
|
|
6813
|
+
gasCost: gasResult.gasCostSui
|
|
7163
6814
|
};
|
|
7164
6815
|
}
|
|
7165
6816
|
async repay(params) {
|
|
@@ -7188,7 +6839,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7188
6839
|
if (!adapter) throw new T2000Error("PROTOCOL_UNAVAILABLE", `Protocol ${target.protocolId} not found`);
|
|
7189
6840
|
const repayAmount = Math.min(params.amount, target.amount);
|
|
7190
6841
|
const targetAssetInfo = SUPPORTED_ASSETS[target.asset] ?? SUPPORTED_ASSETS.USDC;
|
|
7191
|
-
const gasResult = await
|
|
6842
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7192
6843
|
if (adapter.addRepayToTx) {
|
|
7193
6844
|
const tx2 = new Transaction();
|
|
7194
6845
|
tx2.setSender(this._address);
|
|
@@ -7211,8 +6862,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7211
6862
|
amount: repayAmount,
|
|
7212
6863
|
asset: target.asset,
|
|
7213
6864
|
remainingDebt: hf.borrowed,
|
|
7214
|
-
gasCost: gasResult.gasCostSui
|
|
7215
|
-
gasMethod: gasResult.gasMethod
|
|
6865
|
+
gasCost: gasResult.gasCostSui
|
|
7216
6866
|
};
|
|
7217
6867
|
}
|
|
7218
6868
|
async _repayAllBorrows(borrows) {
|
|
@@ -7224,7 +6874,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7224
6874
|
}
|
|
7225
6875
|
const canPTB = entries.every((e) => e.adapter.addRepayToTx);
|
|
7226
6876
|
let totalRepaid = 0;
|
|
7227
|
-
const gasResult = await
|
|
6877
|
+
const gasResult = await executeTx(this.client, this._signer, async () => {
|
|
7228
6878
|
if (canPTB) {
|
|
7229
6879
|
const tx = new Transaction();
|
|
7230
6880
|
tx.setSender(this._address);
|
|
@@ -7265,8 +6915,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7265
6915
|
amount: totalRepaid,
|
|
7266
6916
|
asset: dominantAsset,
|
|
7267
6917
|
remainingDebt: hf.borrowed,
|
|
7268
|
-
gasCost: gasResult.gasCostSui
|
|
7269
|
-
gasMethod: gasResult.gasMethod
|
|
6918
|
+
gasCost: gasResult.gasCostSui
|
|
7270
6919
|
};
|
|
7271
6920
|
}
|
|
7272
6921
|
async maxBorrow() {
|
|
@@ -7299,7 +6948,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7299
6948
|
this.enforcer.assertNotLocked();
|
|
7300
6949
|
const adapters = this.registry.listLending().filter((a) => a.addClaimRewardsToTx);
|
|
7301
6950
|
if (adapters.length === 0) {
|
|
7302
|
-
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0
|
|
6951
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
|
|
7303
6952
|
}
|
|
7304
6953
|
const tx = new Transaction();
|
|
7305
6954
|
tx.setSender(this._address);
|
|
@@ -7312,9 +6961,9 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7312
6961
|
}
|
|
7313
6962
|
}
|
|
7314
6963
|
if (allRewards.length === 0) {
|
|
7315
|
-
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0
|
|
6964
|
+
return { success: true, tx: "", rewards: [], totalValueUsd: 0, gasCost: 0 };
|
|
7316
6965
|
}
|
|
7317
|
-
const claimResult = await
|
|
6966
|
+
const claimResult = await executeTx(this.client, this._signer, async () => tx);
|
|
7318
6967
|
await this.client.waitForTransaction({ digest: claimResult.digest });
|
|
7319
6968
|
const totalValueUsd = allRewards.reduce((s, r) => s + r.estimatedValueUsd, 0);
|
|
7320
6969
|
return {
|
|
@@ -7322,8 +6971,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7322
6971
|
tx: claimResult.digest,
|
|
7323
6972
|
rewards: allRewards,
|
|
7324
6973
|
totalValueUsd,
|
|
7325
|
-
gasCost: claimResult.gasCostSui
|
|
7326
|
-
gasMethod: claimResult.gasMethod
|
|
6974
|
+
gasCost: claimResult.gasCostSui
|
|
7327
6975
|
};
|
|
7328
6976
|
}
|
|
7329
6977
|
/**
|
|
@@ -7395,7 +7043,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7395
7043
|
byAmountIn: true
|
|
7396
7044
|
});
|
|
7397
7045
|
if (!route || route.insufficientLiquidity) continue;
|
|
7398
|
-
const swapResult = await
|
|
7046
|
+
const swapResult = await executeTx(this.client, this._signer, async () => {
|
|
7399
7047
|
const tx = new Transaction();
|
|
7400
7048
|
tx.setSender(this._address);
|
|
7401
7049
|
const freshCoins = await this._fetchCoins(reward.coinType);
|
|
@@ -7426,7 +7074,7 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7426
7074
|
if (gainedRaw > 0n) {
|
|
7427
7075
|
try {
|
|
7428
7076
|
const adapter = await this.resolveLending(void 0, "USDC", "save");
|
|
7429
|
-
const depositResult = await
|
|
7077
|
+
const depositResult = await executeTx(this.client, this._signer, async () => {
|
|
7430
7078
|
const tx = new Transaction();
|
|
7431
7079
|
tx.setSender(this._address);
|
|
7432
7080
|
const coins = await this._fetchCoins(USDC_TYPE2);
|
|
@@ -7557,29 +7205,6 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
7557
7205
|
this.emit("balanceChange", { asset, previous: 0, current: 0, cause, tx });
|
|
7558
7206
|
}
|
|
7559
7207
|
};
|
|
7560
|
-
async function callSponsorApi(address, name) {
|
|
7561
|
-
const res = await fetch(`${API_BASE_URL}/api/sponsor`, {
|
|
7562
|
-
method: "POST",
|
|
7563
|
-
headers: { "Content-Type": "application/json" },
|
|
7564
|
-
body: JSON.stringify({ address, name })
|
|
7565
|
-
});
|
|
7566
|
-
if (res.status === 429) {
|
|
7567
|
-
const data = await res.json();
|
|
7568
|
-
if (data.challenge) {
|
|
7569
|
-
const proof = solveHashcash(data.challenge);
|
|
7570
|
-
const retry = await fetch(`${API_BASE_URL}/api/sponsor`, {
|
|
7571
|
-
method: "POST",
|
|
7572
|
-
headers: { "Content-Type": "application/json" },
|
|
7573
|
-
body: JSON.stringify({ address, name, proof })
|
|
7574
|
-
});
|
|
7575
|
-
if (!retry.ok) throw new T2000Error("SPONSOR_RATE_LIMITED", "Sponsor rate limited");
|
|
7576
|
-
return;
|
|
7577
|
-
}
|
|
7578
|
-
}
|
|
7579
|
-
if (!res.ok) {
|
|
7580
|
-
throw new T2000Error("SPONSOR_FAILED", "Sponsor API unavailable");
|
|
7581
|
-
}
|
|
7582
|
-
}
|
|
7583
7208
|
|
|
7584
7209
|
// src/index.ts
|
|
7585
7210
|
init_errors();
|
|
@@ -7766,6 +7391,6 @@ init_volo();
|
|
|
7766
7391
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7767
7392
|
*/
|
|
7768
7393
|
|
|
7769
|
-
export { ALL_NAVI_ASSETS, BORROW_FEE_BPS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, OVERLAY_FEE_RATE, ProtocolRegistry, SAVE_FEE_BPS, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, addCollectFeeToTx, allDescriptors, assertAllowedAsset, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, classifyAction, classifyLabel, classifyTransaction,
|
|
7394
|
+
export { ALL_NAVI_ASSETS, BORROW_FEE_BPS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, OVERLAY_FEE_RATE, ProtocolRegistry, SAVE_FEE_BPS, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, addCollectFeeToTx, allDescriptors, assertAllowedAsset, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, classifyAction, classifyLabel, classifyTransaction, exportPrivateKey, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getFinancialSummary, getPendingRewards, getRates, getSwapQuote, getTier, getVoloStats, isAllowedAsset, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, normalizeCoinType, parseSuiRpcTx, queryHistory, queryTransaction, rawToStable, rawToUsdc, refineLendingLabel, resolveSymbol, resolveTokenType, saveKey, simulateTransaction, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
7770
7395
|
//# sourceMappingURL=index.js.map
|
|
7771
7396
|
//# sourceMappingURL=index.js.map
|