@hypurrquant/defi-cli 1.0.3 → 1.0.5

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/main.js CHANGED
@@ -227,7 +227,7 @@ var init_dist = __esm({
227
227
  aggregators;
228
228
  effectiveRpcUrl() {
229
229
  const chainEnv = this.name.toUpperCase().replace(/ /g, "_") + "_RPC_URL";
230
- return process.env[chainEnv] ?? process.env["HYPEREVM_RPC_URL"] ?? this.rpc_url;
230
+ return process.env[chainEnv] ?? this.rpc_url;
231
231
  }
232
232
  };
233
233
  ProtocolCategory = /* @__PURE__ */ ((ProtocolCategory2) => {
@@ -5617,6 +5617,9 @@ var init_dist2 = __esm({
5617
5617
  "function borrowRatePerBlock() external view returns (uint256)",
5618
5618
  "function totalSupply() external view returns (uint256)",
5619
5619
  "function totalBorrows() external view returns (uint256)",
5620
+ "function balanceOf(address account) external view returns (uint256)",
5621
+ "function exchangeRateStored() external view returns (uint256)",
5622
+ "function borrowBalanceStored(address account) external view returns (uint256)",
5620
5623
  "function mint(uint256 mintAmount) external returns (uint256)",
5621
5624
  "function redeem(uint256 redeemTokens) external returns (uint256)",
5622
5625
  "function borrow(uint256 borrowAmount) external returns (uint256)",
@@ -5759,10 +5762,41 @@ var init_dist2 = __esm({
5759
5762
  total_borrow: totalBorrows
5760
5763
  };
5761
5764
  }
5762
- async getUserPosition(_user) {
5763
- throw DefiError.unsupported(
5764
- `[${this.protocolName}] User position requires querying individual vToken balances`
5765
- );
5765
+ async getUserPosition(user) {
5766
+ if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
5767
+ const client = createPublicClient13({ transport: http13(this.rpcUrl) });
5768
+ const ERC20_ABI42 = parseAbi17([
5769
+ "function symbol() external view returns (string)"
5770
+ ]);
5771
+ const supplies = [];
5772
+ const borrows = [];
5773
+ await Promise.all(this.vTokenCandidates.map(async (vtoken) => {
5774
+ try {
5775
+ const [vtokenBal, rate, borrowed, underlying] = await Promise.all([
5776
+ client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "balanceOf", args: [user] }),
5777
+ client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "exchangeRateStored" }),
5778
+ client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "borrowBalanceStored", args: [user] }),
5779
+ client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "underlying" }).catch(() => null)
5780
+ ]);
5781
+ if (vtokenBal === 0n && borrowed === 0n) return;
5782
+ const assetAddr = underlying ?? vtoken;
5783
+ const symbol = await client.readContract({
5784
+ address: assetAddr,
5785
+ abi: ERC20_ABI42,
5786
+ functionName: "symbol"
5787
+ }).catch(() => "?");
5788
+ const supplyUnderlying = vtokenBal * rate / 10n ** 18n;
5789
+ if (supplyUnderlying > 0n) supplies.push({ asset: assetAddr, symbol, amount: supplyUnderlying });
5790
+ if (borrowed > 0n) borrows.push({ asset: assetAddr, symbol, amount: borrowed });
5791
+ } catch {
5792
+ }
5793
+ }));
5794
+ return {
5795
+ protocol: this.protocolName,
5796
+ user,
5797
+ supplies,
5798
+ borrows
5799
+ };
5766
5800
  }
5767
5801
  };
5768
5802
  COMET_ABI = parseAbi18([
@@ -5772,6 +5806,8 @@ var init_dist2 = __esm({
5772
5806
  "function getBorrowRate(uint256 utilization) external view returns (uint64)",
5773
5807
  "function totalSupply() external view returns (uint256)",
5774
5808
  "function totalBorrow() external view returns (uint256)",
5809
+ "function balanceOf(address account) external view returns (uint256)",
5810
+ "function borrowBalanceOf(address account) external view returns (uint256)",
5775
5811
  "function supply(address asset, uint256 amount) external",
5776
5812
  "function withdraw(address asset, uint256 amount) external"
5777
5813
  ]);
@@ -5902,10 +5938,30 @@ var init_dist2 = __esm({
5902
5938
  total_borrow: totalBorrow
5903
5939
  };
5904
5940
  }
5905
- async getUserPosition(_user) {
5906
- throw DefiError.unsupported(
5907
- `[${this.protocolName}] User position requires querying Comet balanceOf + borrowBalanceOf`
5908
- );
5941
+ async getUserPosition(user) {
5942
+ if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
5943
+ const client = createPublicClient14({ transport: http14(this.rpcUrl) });
5944
+ const ERC20_ABI42 = parseAbi18([
5945
+ "function symbol() external view returns (string)"
5946
+ ]);
5947
+ const [supplyBal, borrowBal, baseToken] = await Promise.all([
5948
+ client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "balanceOf", args: [user] }).catch(() => 0n),
5949
+ client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "borrowBalanceOf", args: [user] }).catch(() => 0n),
5950
+ client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "baseToken" })
5951
+ ]);
5952
+ const baseSymbol = await client.readContract({
5953
+ address: baseToken,
5954
+ abi: ERC20_ABI42,
5955
+ functionName: "symbol"
5956
+ }).catch(() => "?");
5957
+ const supplies = supplyBal > 0n ? [{ asset: baseToken, symbol: baseSymbol, amount: supplyBal }] : [];
5958
+ const borrows = borrowBal > 0n ? [{ asset: baseToken, symbol: baseSymbol, amount: borrowBal }] : [];
5959
+ return {
5960
+ protocol: this.protocolName,
5961
+ user,
5962
+ supplies,
5963
+ borrows
5964
+ };
5909
5965
  }
5910
5966
  };
5911
5967
  EULER_VAULT_ABI = parseAbi19([
@@ -7964,7 +8020,7 @@ function handleSchema(params) {
7964
8020
  from: { type: "string", required: true, description: "Input token symbol or address" },
7965
8021
  to: { type: "string", required: true, description: "Output token symbol or address" },
7966
8022
  amount: { type: "string", required: true, description: "Amount in wei" },
7967
- provider: { type: "string", required: false, default: "kyber", description: "Aggregator: kyber, openocean, liquid" },
8023
+ provider: { type: "string", required: false, default: "kyber", description: "Aggregator: kyber, openocean, liquid, lifi, relay" },
7968
8024
  slippage: { type: "string", required: false, default: "50", description: "Slippage in bps" }
7969
8025
  },
7970
8026
  cli: "defi --chain hyperevm swap --from USDC --to WHYPE --amount 1000000"
@@ -9822,11 +9878,12 @@ function registerYield(parent, getOpts, makeExecutor2) {
9822
9878
  if (opts.targetChain) {
9823
9879
  targetChainName = opts.targetChain.toLowerCase();
9824
9880
  } else {
9825
- process.stderr.write(`Scanning all chains for best ${asset} yield...
9881
+ const quiet = getOpts().json;
9882
+ if (!quiet) process.stderr.write(`Scanning all chains for best ${asset} yield...
9826
9883
  `);
9827
9884
  const t0 = Date.now();
9828
9885
  const allRates = await scanRatesForExecute(registry, asset);
9829
- process.stderr.write(`Scan done in ${Date.now() - t0}ms \u2014 ${allRates.length} rates found
9886
+ if (!quiet) process.stderr.write(`Scan done in ${Date.now() - t0}ms \u2014 ${allRates.length} rates found
9830
9887
  `);
9831
9888
  if (allRates.length === 0) {
9832
9889
  printOutput({ error: `No yield opportunities found for ${asset}` }, getOpts());
@@ -11513,15 +11570,19 @@ function registerSetup(program2) {
11513
11570
  }
11514
11571
  }
11515
11572
  console.log(pc2.cyan(pc2.bold("\n RPC URLs")) + pc2.gray(" (press Enter to use public defaults)"));
11516
- const hyperevmRpc = await ask(rl, " HyperEVM RPC URL: ");
11517
- if (hyperevmRpc) {
11518
- newEnv.HYPEREVM_RPC_URL = hyperevmRpc;
11519
- console.log(` ${pc2.green("OK")} HyperEVM RPC set`);
11520
- }
11521
- const mantleRpc = await ask(rl, " Mantle RPC URL: ");
11522
- if (mantleRpc) {
11523
- newEnv.MANTLE_RPC_URL = mantleRpc;
11524
- console.log(` ${pc2.green("OK")} Mantle RPC set`);
11573
+ const rpcPrompts = [
11574
+ { env: "HYPEREVM_RPC_URL", label: "HyperEVM" },
11575
+ { env: "MANTLE_RPC_URL", label: "Mantle" },
11576
+ { env: "BASE_RPC_URL", label: "Base" },
11577
+ { env: "BNB_RPC_URL", label: "BNB" },
11578
+ { env: "MONAD_RPC_URL", label: "Monad" }
11579
+ ];
11580
+ for (const { env, label } of rpcPrompts) {
11581
+ const value = await ask(rl, ` ${label} RPC URL: `);
11582
+ if (value) {
11583
+ newEnv[env] = value;
11584
+ console.log(` ${pc2.green("OK")} ${label} RPC set`);
11585
+ }
11525
11586
  }
11526
11587
  const finalEnv = { ...existing, ...newEnv };
11527
11588
  writeEnvFile(finalEnv);
@@ -11533,11 +11594,16 @@ function registerSetup(program2) {
11533
11594
  if (finalEnv.DEFI_PRIVATE_KEY) {
11534
11595
  console.log(` Key: ${pc2.green("configured")}`);
11535
11596
  }
11536
- if (finalEnv.HYPEREVM_RPC_URL) {
11537
- console.log(` HyperEVM RPC: ${pc2.gray(finalEnv.HYPEREVM_RPC_URL)}`);
11538
- }
11539
- if (finalEnv.MANTLE_RPC_URL) {
11540
- console.log(` Mantle RPC: ${pc2.gray(finalEnv.MANTLE_RPC_URL)}`);
11597
+ const rpcSummary = [
11598
+ ["HYPEREVM_RPC_URL", "HyperEVM RPC"],
11599
+ ["MANTLE_RPC_URL", "Mantle RPC "],
11600
+ ["BASE_RPC_URL", "Base RPC "],
11601
+ ["BNB_RPC_URL", "BNB RPC "],
11602
+ ["MONAD_RPC_URL", "Monad RPC "]
11603
+ ];
11604
+ for (const [k, label] of rpcSummary) {
11605
+ const v = finalEnv[k];
11606
+ if (v) console.log(` ${label}: ${pc2.gray(v)}`);
11541
11607
  }
11542
11608
  console.log(pc2.bold(pc2.white("\n Next steps:")));
11543
11609
  console.log(` ${pc2.green("defi portfolio")} view balances & positions`);
@@ -11750,7 +11816,9 @@ function buildBanner() {
11750
11816
  try {
11751
11817
  const reg = Registry.loadEmbedded();
11752
11818
  chainCount = reg.chains.size;
11753
- protocolCount = reg.protocols.length;
11819
+ protocolCount = reg.protocols.filter(
11820
+ (p) => p.verified !== false && p.is_active !== false
11821
+ ).length;
11754
11822
  } catch {
11755
11823
  }
11756
11824
  const stats = chainCount && protocolCount ? `${chainCount} chains \xB7 ${protocolCount} protocols \xB7 by HypurrQuant` : `by HypurrQuant`;