@hypurrquant/defi-cli 1.0.4 → 1.0.6
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 +95 -28
- package/dist/index.js.map +1 -1
- package/dist/main.js +95 -28
- package/dist/main.js.map +1 -1
- package/dist/mcp-server.js +72 -14
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/skills/defi-cli/package.json +1 -1
package/dist/index.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] ??
|
|
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)",
|
|
@@ -5732,7 +5735,7 @@ var init_dist2 = __esm({
|
|
|
5732
5735
|
total_borrow: 0n
|
|
5733
5736
|
};
|
|
5734
5737
|
}
|
|
5735
|
-
const [supplyRate, borrowRate,
|
|
5738
|
+
const [supplyRate, borrowRate, totalSupplyVtoken, totalBorrows, exchangeRate] = await Promise.all([
|
|
5736
5739
|
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "supplyRatePerBlock" }).catch((e) => {
|
|
5737
5740
|
throw DefiError.rpcError(`[${this.protocolName}] supplyRatePerBlock failed: ${e}`);
|
|
5738
5741
|
}),
|
|
@@ -5740,29 +5743,62 @@ var init_dist2 = __esm({
|
|
|
5740
5743
|
throw DefiError.rpcError(`[${this.protocolName}] borrowRatePerBlock failed: ${e}`);
|
|
5741
5744
|
}),
|
|
5742
5745
|
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "totalSupply" }).catch(() => 0n),
|
|
5743
|
-
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "totalBorrows" }).catch(() => 0n)
|
|
5746
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "totalBorrows" }).catch(() => 0n),
|
|
5747
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "exchangeRateStored" }).catch(() => 0n)
|
|
5744
5748
|
]);
|
|
5745
5749
|
const supplyPerBlock = Number(supplyRate) / 1e18;
|
|
5746
5750
|
const borrowPerBlock = Number(borrowRate) / 1e18;
|
|
5747
5751
|
const supplyApy = supplyPerBlock * BSC_BLOCKS_PER_YEAR * 100;
|
|
5748
5752
|
const borrowApy = borrowPerBlock * BSC_BLOCKS_PER_YEAR * 100;
|
|
5749
|
-
const
|
|
5753
|
+
const totalSupplyUnderlying = exchangeRate > 0n ? totalSupplyVtoken * exchangeRate / 10n ** 18n : totalSupplyVtoken;
|
|
5754
|
+
const supplyF = Number(totalSupplyUnderlying);
|
|
5750
5755
|
const borrowF = Number(totalBorrows);
|
|
5751
|
-
const utilization = supplyF > 0 ? borrowF / supplyF * 100 : 0;
|
|
5756
|
+
const utilization = supplyF > 0 ? Math.round(borrowF / supplyF * 1e4) / 100 : 0;
|
|
5752
5757
|
return {
|
|
5753
5758
|
protocol: this.protocolName,
|
|
5754
5759
|
asset,
|
|
5755
5760
|
supply_apy: supplyApy,
|
|
5756
5761
|
borrow_variable_apy: borrowApy,
|
|
5757
5762
|
utilization,
|
|
5758
|
-
total_supply:
|
|
5763
|
+
total_supply: totalSupplyUnderlying,
|
|
5759
5764
|
total_borrow: totalBorrows
|
|
5760
5765
|
};
|
|
5761
5766
|
}
|
|
5762
|
-
async getUserPosition(
|
|
5763
|
-
throw DefiError.
|
|
5764
|
-
|
|
5765
|
-
|
|
5767
|
+
async getUserPosition(user) {
|
|
5768
|
+
if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
|
|
5769
|
+
const client = createPublicClient13({ transport: http13(this.rpcUrl) });
|
|
5770
|
+
const ERC20_ABI42 = parseAbi17([
|
|
5771
|
+
"function symbol() external view returns (string)"
|
|
5772
|
+
]);
|
|
5773
|
+
const supplies = [];
|
|
5774
|
+
const borrows = [];
|
|
5775
|
+
await Promise.all(this.vTokenCandidates.map(async (vtoken) => {
|
|
5776
|
+
try {
|
|
5777
|
+
const [vtokenBal, rate, borrowed, underlying] = await Promise.all([
|
|
5778
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "balanceOf", args: [user] }),
|
|
5779
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "exchangeRateStored" }),
|
|
5780
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "borrowBalanceStored", args: [user] }),
|
|
5781
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "underlying" }).catch(() => null)
|
|
5782
|
+
]);
|
|
5783
|
+
if (vtokenBal === 0n && borrowed === 0n) return;
|
|
5784
|
+
const assetAddr = underlying ?? vtoken;
|
|
5785
|
+
const symbol = await client.readContract({
|
|
5786
|
+
address: assetAddr,
|
|
5787
|
+
abi: ERC20_ABI42,
|
|
5788
|
+
functionName: "symbol"
|
|
5789
|
+
}).catch(() => "?");
|
|
5790
|
+
const supplyUnderlying = vtokenBal * rate / 10n ** 18n;
|
|
5791
|
+
if (supplyUnderlying > 0n) supplies.push({ asset: assetAddr, symbol, amount: supplyUnderlying });
|
|
5792
|
+
if (borrowed > 0n) borrows.push({ asset: assetAddr, symbol, amount: borrowed });
|
|
5793
|
+
} catch {
|
|
5794
|
+
}
|
|
5795
|
+
}));
|
|
5796
|
+
return {
|
|
5797
|
+
protocol: this.protocolName,
|
|
5798
|
+
user,
|
|
5799
|
+
supplies,
|
|
5800
|
+
borrows
|
|
5801
|
+
};
|
|
5766
5802
|
}
|
|
5767
5803
|
};
|
|
5768
5804
|
COMET_ABI = parseAbi18([
|
|
@@ -5772,6 +5808,8 @@ var init_dist2 = __esm({
|
|
|
5772
5808
|
"function getBorrowRate(uint256 utilization) external view returns (uint64)",
|
|
5773
5809
|
"function totalSupply() external view returns (uint256)",
|
|
5774
5810
|
"function totalBorrow() external view returns (uint256)",
|
|
5811
|
+
"function balanceOf(address account) external view returns (uint256)",
|
|
5812
|
+
"function borrowBalanceOf(address account) external view returns (uint256)",
|
|
5775
5813
|
"function supply(address asset, uint256 amount) external",
|
|
5776
5814
|
"function withdraw(address asset, uint256 amount) external"
|
|
5777
5815
|
]);
|
|
@@ -5902,10 +5940,30 @@ var init_dist2 = __esm({
|
|
|
5902
5940
|
total_borrow: totalBorrow
|
|
5903
5941
|
};
|
|
5904
5942
|
}
|
|
5905
|
-
async getUserPosition(
|
|
5906
|
-
throw DefiError.
|
|
5907
|
-
|
|
5908
|
-
|
|
5943
|
+
async getUserPosition(user) {
|
|
5944
|
+
if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
|
|
5945
|
+
const client = createPublicClient14({ transport: http14(this.rpcUrl) });
|
|
5946
|
+
const ERC20_ABI42 = parseAbi18([
|
|
5947
|
+
"function symbol() external view returns (string)"
|
|
5948
|
+
]);
|
|
5949
|
+
const [supplyBal, borrowBal, baseToken] = await Promise.all([
|
|
5950
|
+
client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "balanceOf", args: [user] }).catch(() => 0n),
|
|
5951
|
+
client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "borrowBalanceOf", args: [user] }).catch(() => 0n),
|
|
5952
|
+
client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "baseToken" })
|
|
5953
|
+
]);
|
|
5954
|
+
const baseSymbol = await client.readContract({
|
|
5955
|
+
address: baseToken,
|
|
5956
|
+
abi: ERC20_ABI42,
|
|
5957
|
+
functionName: "symbol"
|
|
5958
|
+
}).catch(() => "?");
|
|
5959
|
+
const supplies = supplyBal > 0n ? [{ asset: baseToken, symbol: baseSymbol, amount: supplyBal }] : [];
|
|
5960
|
+
const borrows = borrowBal > 0n ? [{ asset: baseToken, symbol: baseSymbol, amount: borrowBal }] : [];
|
|
5961
|
+
return {
|
|
5962
|
+
protocol: this.protocolName,
|
|
5963
|
+
user,
|
|
5964
|
+
supplies,
|
|
5965
|
+
borrows
|
|
5966
|
+
};
|
|
5909
5967
|
}
|
|
5910
5968
|
};
|
|
5911
5969
|
EULER_VAULT_ABI = parseAbi19([
|
|
@@ -11510,15 +11568,19 @@ function registerSetup(program2) {
|
|
|
11510
11568
|
}
|
|
11511
11569
|
}
|
|
11512
11570
|
console.log(pc2.cyan(pc2.bold("\n RPC URLs")) + pc2.gray(" (press Enter to use public defaults)"));
|
|
11513
|
-
const
|
|
11514
|
-
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11571
|
+
const rpcPrompts = [
|
|
11572
|
+
{ env: "HYPEREVM_RPC_URL", label: "HyperEVM" },
|
|
11573
|
+
{ env: "MANTLE_RPC_URL", label: "Mantle" },
|
|
11574
|
+
{ env: "BASE_RPC_URL", label: "Base" },
|
|
11575
|
+
{ env: "BNB_RPC_URL", label: "BNB" },
|
|
11576
|
+
{ env: "MONAD_RPC_URL", label: "Monad" }
|
|
11577
|
+
];
|
|
11578
|
+
for (const { env, label } of rpcPrompts) {
|
|
11579
|
+
const value = await ask(rl, ` ${label} RPC URL: `);
|
|
11580
|
+
if (value) {
|
|
11581
|
+
newEnv[env] = value;
|
|
11582
|
+
console.log(` ${pc2.green("OK")} ${label} RPC set`);
|
|
11583
|
+
}
|
|
11522
11584
|
}
|
|
11523
11585
|
const finalEnv = { ...existing, ...newEnv };
|
|
11524
11586
|
writeEnvFile(finalEnv);
|
|
@@ -11530,11 +11592,16 @@ function registerSetup(program2) {
|
|
|
11530
11592
|
if (finalEnv.DEFI_PRIVATE_KEY) {
|
|
11531
11593
|
console.log(` Key: ${pc2.green("configured")}`);
|
|
11532
11594
|
}
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11595
|
+
const rpcSummary = [
|
|
11596
|
+
["HYPEREVM_RPC_URL", "HyperEVM RPC"],
|
|
11597
|
+
["MANTLE_RPC_URL", "Mantle RPC "],
|
|
11598
|
+
["BASE_RPC_URL", "Base RPC "],
|
|
11599
|
+
["BNB_RPC_URL", "BNB RPC "],
|
|
11600
|
+
["MONAD_RPC_URL", "Monad RPC "]
|
|
11601
|
+
];
|
|
11602
|
+
for (const [k, label] of rpcSummary) {
|
|
11603
|
+
const v = finalEnv[k];
|
|
11604
|
+
if (v) console.log(` ${label}: ${pc2.gray(v)}`);
|
|
11538
11605
|
}
|
|
11539
11606
|
console.log(pc2.bold(pc2.white("\n Next steps:")));
|
|
11540
11607
|
console.log(` ${pc2.green("defi portfolio")} view balances & positions`);
|