@t2000/cli 0.50.3 → 0.51.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/dist/{chunk-Q52KM4VI.js → chunk-6QF7QYS4.js} +38 -14
- package/dist/{chunk-Q52KM4VI.js.map → chunk-6QF7QYS4.js.map} +1 -1
- package/dist/{dist-4KFY6MX6.js → dist-53IAVMW6.js} +2 -2
- package/dist/{dist-UTSUSZ5R.js → dist-LBQE6JNT.js} +39 -15
- package/dist/{dist-UTSUSZ5R.js.map → dist-LBQE6JNT.js.map} +1 -1
- package/dist/index.js +3 -3
- package/package.json +3 -3
- /package/dist/{dist-4KFY6MX6.js.map → dist-53IAVMW6.js.map} +0 -0
|
@@ -60662,8 +60662,8 @@ var SUPPORTED_ASSETS = {
|
|
|
60662
60662
|
var STABLE_ASSETS = ["USDC"];
|
|
60663
60663
|
var ALL_NAVI_ASSETS = Object.keys(SUPPORTED_ASSETS);
|
|
60664
60664
|
var OPERATION_ASSETS = {
|
|
60665
|
-
save: ["USDC"],
|
|
60666
|
-
borrow: ["USDC"],
|
|
60665
|
+
save: ["USDC", "USDsui"],
|
|
60666
|
+
borrow: ["USDC", "USDsui"],
|
|
60667
60667
|
withdraw: "*",
|
|
60668
60668
|
repay: "*",
|
|
60669
60669
|
send: "*",
|
|
@@ -60672,7 +60672,8 @@ var OPERATION_ASSETS = {
|
|
|
60672
60672
|
function isAllowedAsset(op, asset) {
|
|
60673
60673
|
const allowed = OPERATION_ASSETS[op];
|
|
60674
60674
|
if (allowed === "*") return true;
|
|
60675
|
-
|
|
60675
|
+
const target = asset.toLowerCase();
|
|
60676
|
+
return allowed.some((a) => a.toLowerCase() === target);
|
|
60676
60677
|
}
|
|
60677
60678
|
function assertAllowedAsset(op, asset) {
|
|
60678
60679
|
if (!asset) return;
|
|
@@ -60681,7 +60682,7 @@ function assertAllowedAsset(op, asset) {
|
|
|
60681
60682
|
const list = Array.isArray(allowed) ? allowed.join(", ") : "any";
|
|
60682
60683
|
throw new T2000Error(
|
|
60683
60684
|
"INVALID_ASSET",
|
|
60684
|
-
`${op} only supports ${list}. Cannot use ${asset}.${op === "save" ? " Swap to USDC first." : ""}`
|
|
60685
|
+
`${op} only supports ${list}. Cannot use ${asset}.${op === "save" ? " Swap to USDC or USDsui first." : ""}`
|
|
60685
60686
|
);
|
|
60686
60687
|
}
|
|
60687
60688
|
}
|
|
@@ -66523,23 +66524,26 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66523
66524
|
async save(params) {
|
|
66524
66525
|
this.enforcer.assertNotLocked();
|
|
66525
66526
|
assertAllowedAsset("save", params.asset);
|
|
66526
|
-
const asset = "USDC";
|
|
66527
|
+
const asset = params.asset ?? "USDC";
|
|
66527
66528
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
66528
66529
|
let amount;
|
|
66529
66530
|
if (params.amount === "all") {
|
|
66530
|
-
const
|
|
66531
|
-
amount =
|
|
66531
|
+
const assetBalance = await this._queryAssetBalance(assetInfo.type, assetInfo.decimals);
|
|
66532
|
+
amount = assetBalance - 1;
|
|
66532
66533
|
if (amount <= 0) {
|
|
66533
|
-
throw new T2000Error("INSUFFICIENT_BALANCE", `No
|
|
66534
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} available to save`, {
|
|
66534
66535
|
reason: "insufficient_balance",
|
|
66535
66536
|
asset
|
|
66536
66537
|
});
|
|
66537
66538
|
}
|
|
66538
66539
|
} else {
|
|
66539
66540
|
amount = params.amount;
|
|
66540
|
-
const
|
|
66541
|
-
if (amount >
|
|
66542
|
-
throw new T2000Error(
|
|
66541
|
+
const assetBalance = await this._queryAssetBalance(assetInfo.type, assetInfo.decimals);
|
|
66542
|
+
if (amount > assetBalance) {
|
|
66543
|
+
throw new T2000Error(
|
|
66544
|
+
"INSUFFICIENT_BALANCE",
|
|
66545
|
+
`Insufficient ${assetInfo.displayName} balance. Available: ${assetBalance.toFixed(assetInfo.decimals === 6 ? 2 : 4)}, requested: ${amount.toFixed(assetInfo.decimals === 6 ? 2 : 4)}`
|
|
66546
|
+
);
|
|
66543
66547
|
}
|
|
66544
66548
|
}
|
|
66545
66549
|
const fee = calculateFee("save", amount);
|
|
@@ -66551,7 +66555,7 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66551
66555
|
const tx2 = new Transaction();
|
|
66552
66556
|
tx2.setSender(this._address);
|
|
66553
66557
|
const coins = await this._fetchCoins(assetInfo.type);
|
|
66554
|
-
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE",
|
|
66558
|
+
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins found`);
|
|
66555
66559
|
const merged = this._mergeCoinsInTx(tx2, coins);
|
|
66556
66560
|
const rawAmount = BigInt(Math.floor(saveAmount * 10 ** assetInfo.decimals));
|
|
66557
66561
|
const [inputCoin] = tx2.splitCoins(merged, [rawAmount]);
|
|
@@ -66735,6 +66739,24 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66735
66739
|
gasMethod: gasResult.gasMethod
|
|
66736
66740
|
};
|
|
66737
66741
|
}
|
|
66742
|
+
/**
|
|
66743
|
+
* [v0.51.0] Per-asset wallet balance lookup.
|
|
66744
|
+
*
|
|
66745
|
+
* `queryBalance.available` rolls up only `STABLE_ASSETS` (USDC), so it cannot
|
|
66746
|
+
* answer "do they have enough USDsui to save 10?". This helper hits
|
|
66747
|
+
* `getBalance` for the specific coin type — same mechanism `queryBalance`
|
|
66748
|
+
* uses internally — and converts to a human-readable amount using the asset's
|
|
66749
|
+
* decimals. Returns 0 (not a throw) when the address holds none of the asset,
|
|
66750
|
+
* matching the caller's existing "insufficient balance" error path.
|
|
66751
|
+
*/
|
|
66752
|
+
async _queryAssetBalance(coinType, decimals) {
|
|
66753
|
+
try {
|
|
66754
|
+
const bal = await this.client.getBalance({ owner: this._address, coinType });
|
|
66755
|
+
return Number(bal.totalBalance) / 10 ** decimals;
|
|
66756
|
+
} catch {
|
|
66757
|
+
return 0;
|
|
66758
|
+
}
|
|
66759
|
+
}
|
|
66738
66760
|
async _fetchCoins(coinType) {
|
|
66739
66761
|
const all3 = [];
|
|
66740
66762
|
let cursor;
|
|
@@ -66817,7 +66839,8 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66817
66839
|
// -- Borrowing --
|
|
66818
66840
|
async borrow(params) {
|
|
66819
66841
|
this.enforcer.assertNotLocked();
|
|
66820
|
-
|
|
66842
|
+
assertAllowedAsset("borrow", params.asset);
|
|
66843
|
+
const asset = params.asset ?? "USDC";
|
|
66821
66844
|
const adapter2 = await this.resolveLending(params.protocol, asset, "borrow");
|
|
66822
66845
|
const maxResult = await adapter2.maxBorrow(this._address, asset);
|
|
66823
66846
|
if (maxResult.maxAmount <= 0) {
|
|
@@ -66842,6 +66865,7 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66842
66865
|
success: true,
|
|
66843
66866
|
tx: gasResult.digest,
|
|
66844
66867
|
amount: borrowAmount,
|
|
66868
|
+
asset,
|
|
66845
66869
|
fee: fee.amount,
|
|
66846
66870
|
healthFactor: hf.healthFactor,
|
|
66847
66871
|
gasCost: gasResult.gasCostSui,
|
|
@@ -67588,4 +67612,4 @@ axios/dist/node/axios.cjs:
|
|
|
67588
67612
|
@scure/bip39/index.js:
|
|
67589
67613
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
67590
67614
|
*/
|
|
67591
|
-
//# sourceMappingURL=chunk-
|
|
67615
|
+
//# sourceMappingURL=chunk-6QF7QYS4.js.map
|