@hypurrquant/defi-cli 1.0.4 → 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/index.js +88 -23
- package/dist/index.js.map +1 -1
- package/dist/main.js +88 -23
- package/dist/main.js.map +1 -1
- package/dist/mcp-server.js +65 -9
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/skills/defi-cli/package.json +1 -1
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] ??
|
|
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(
|
|
5763
|
-
throw DefiError.
|
|
5764
|
-
|
|
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(
|
|
5906
|
-
throw DefiError.
|
|
5907
|
-
|
|
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([
|
|
@@ -11514,15 +11570,19 @@ function registerSetup(program2) {
|
|
|
11514
11570
|
}
|
|
11515
11571
|
}
|
|
11516
11572
|
console.log(pc2.cyan(pc2.bold("\n RPC URLs")) + pc2.gray(" (press Enter to use public defaults)"));
|
|
11517
|
-
const
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
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
|
+
}
|
|
11526
11586
|
}
|
|
11527
11587
|
const finalEnv = { ...existing, ...newEnv };
|
|
11528
11588
|
writeEnvFile(finalEnv);
|
|
@@ -11534,11 +11594,16 @@ function registerSetup(program2) {
|
|
|
11534
11594
|
if (finalEnv.DEFI_PRIVATE_KEY) {
|
|
11535
11595
|
console.log(` Key: ${pc2.green("configured")}`);
|
|
11536
11596
|
}
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
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)}`);
|
|
11542
11607
|
}
|
|
11543
11608
|
console.log(pc2.bold(pc2.white("\n Next steps:")));
|
|
11544
11609
|
console.log(` ${pc2.green("defi portfolio")} view balances & positions`);
|