@t2000/cli 0.22.15 → 0.22.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +56 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -9
package/dist/index.js
CHANGED
|
@@ -8371,18 +8371,68 @@ function registerSwap(program3) {
|
|
|
8371
8371
|
if (isNaN(parsedAmount) || parsedAmount <= 0) {
|
|
8372
8372
|
throw new Error("Amount must be a positive number");
|
|
8373
8373
|
}
|
|
8374
|
-
|
|
8374
|
+
const resolved = resolveAssetName2(asset);
|
|
8375
|
+
if (resolved in INVESTMENT_ASSETS) {
|
|
8376
|
+
const pin = await resolvePin();
|
|
8377
|
+
const agent = await T2000.create({ pin, keyPath: opts.key });
|
|
8378
|
+
const result = await agent.investBuy({
|
|
8379
|
+
asset: resolved,
|
|
8380
|
+
usdAmount: parsedAmount,
|
|
8381
|
+
maxSlippage: parseFloat(opts.slippage ?? "3") / 100
|
|
8382
|
+
});
|
|
8383
|
+
if (isJsonMode()) {
|
|
8384
|
+
printJson(result);
|
|
8385
|
+
return;
|
|
8386
|
+
}
|
|
8387
|
+
const display = SUPPORTED_ASSETS[resolved]?.displayName ?? resolved;
|
|
8388
|
+
printBlank();
|
|
8389
|
+
printSuccess(`Bought ${fmtTokenAmount(result.amount, resolved)} ${display} for ${formatUsd(parsedAmount)}`);
|
|
8390
|
+
printKeyValue("Tx", explorerUrl(result.tx));
|
|
8391
|
+
printBlank();
|
|
8392
|
+
} else {
|
|
8393
|
+
await executeSwap("USDC", asset, parsedAmount, opts, "Bought");
|
|
8394
|
+
}
|
|
8375
8395
|
} catch (error) {
|
|
8376
8396
|
handleError(error);
|
|
8377
8397
|
}
|
|
8378
8398
|
});
|
|
8379
|
-
program3.command("sell <amount> <asset>").description("Sell an asset for USDC (e.g. sell 0.001 BTC)").option("--key <path>", "Key file path").option("--slippage <pct>", "Max slippage percentage (default: 3)", "3").action(async (amount, asset, opts) => {
|
|
8399
|
+
program3.command("sell <amount> <asset>").description("Sell an asset for USDC (e.g. sell 0.001 BTC, sell all SUI)").option("--key <path>", "Key file path").option("--slippage <pct>", "Max slippage percentage (default: 3)", "3").action(async (amount, asset, opts) => {
|
|
8380
8400
|
try {
|
|
8381
|
-
const
|
|
8382
|
-
|
|
8383
|
-
|
|
8401
|
+
const resolved = resolveAssetName2(asset);
|
|
8402
|
+
const isAll = amount.toLowerCase() === "all";
|
|
8403
|
+
if (resolved in INVESTMENT_ASSETS) {
|
|
8404
|
+
const pin = await resolvePin();
|
|
8405
|
+
const agent = await T2000.create({ pin, keyPath: opts.key });
|
|
8406
|
+
const usdAmount = isAll ? "all" : parseFloat(amount);
|
|
8407
|
+
if (usdAmount !== "all" && (isNaN(usdAmount) || usdAmount <= 0)) {
|
|
8408
|
+
throw new Error('Amount must be a positive number or "all"');
|
|
8409
|
+
}
|
|
8410
|
+
const result = await agent.investSell({
|
|
8411
|
+
asset: resolved,
|
|
8412
|
+
usdAmount,
|
|
8413
|
+
maxSlippage: parseFloat(opts.slippage ?? "3") / 100
|
|
8414
|
+
});
|
|
8415
|
+
if (isJsonMode()) {
|
|
8416
|
+
printJson(result);
|
|
8417
|
+
return;
|
|
8418
|
+
}
|
|
8419
|
+
const display = SUPPORTED_ASSETS[resolved]?.displayName ?? resolved;
|
|
8420
|
+
printBlank();
|
|
8421
|
+
printSuccess(`Sold ${fmtTokenAmount(result.amount, resolved)} ${display} at ${formatUsd(result.price)}`);
|
|
8422
|
+
printKeyValue("Proceeds", formatUsd(result.usdValue));
|
|
8423
|
+
if (result.realizedPnL !== void 0) {
|
|
8424
|
+
const pnlSign = result.realizedPnL >= 0 ? "+" : "";
|
|
8425
|
+
printKeyValue("Realized P&L", `${pnlSign}${formatUsd(result.realizedPnL)}`);
|
|
8426
|
+
}
|
|
8427
|
+
printKeyValue("Tx", explorerUrl(result.tx));
|
|
8428
|
+
printBlank();
|
|
8429
|
+
} else {
|
|
8430
|
+
const parsedAmount = parseFloat(amount);
|
|
8431
|
+
if (isNaN(parsedAmount) || parsedAmount <= 0) {
|
|
8432
|
+
throw new Error("Amount must be a positive number");
|
|
8433
|
+
}
|
|
8434
|
+
await executeSwap(asset, "USDC", parsedAmount, opts, "Sold");
|
|
8384
8435
|
}
|
|
8385
|
-
await executeSwap(asset, "USDC", parsedAmount, opts, "Sold");
|
|
8386
8436
|
} catch (error) {
|
|
8387
8437
|
handleError(error);
|
|
8388
8438
|
}
|