@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/index.js +95 -27
- package/dist/index.js.map +1 -1
- package/dist/main.js +95 -27
- 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/mcp-server.js
CHANGED
|
@@ -339,7 +339,7 @@ var init_dist = __esm({
|
|
|
339
339
|
aggregators;
|
|
340
340
|
effectiveRpcUrl() {
|
|
341
341
|
const chainEnv = this.name.toUpperCase().replace(/ /g, "_") + "_RPC_URL";
|
|
342
|
-
return process.env[chainEnv] ??
|
|
342
|
+
return process.env[chainEnv] ?? this.rpc_url;
|
|
343
343
|
}
|
|
344
344
|
};
|
|
345
345
|
ProtocolCategory = /* @__PURE__ */ ((ProtocolCategory2) => {
|
|
@@ -5729,6 +5729,9 @@ var init_dist2 = __esm({
|
|
|
5729
5729
|
"function borrowRatePerBlock() external view returns (uint256)",
|
|
5730
5730
|
"function totalSupply() external view returns (uint256)",
|
|
5731
5731
|
"function totalBorrows() external view returns (uint256)",
|
|
5732
|
+
"function balanceOf(address account) external view returns (uint256)",
|
|
5733
|
+
"function exchangeRateStored() external view returns (uint256)",
|
|
5734
|
+
"function borrowBalanceStored(address account) external view returns (uint256)",
|
|
5732
5735
|
"function mint(uint256 mintAmount) external returns (uint256)",
|
|
5733
5736
|
"function redeem(uint256 redeemTokens) external returns (uint256)",
|
|
5734
5737
|
"function borrow(uint256 borrowAmount) external returns (uint256)",
|
|
@@ -5871,10 +5874,41 @@ var init_dist2 = __esm({
|
|
|
5871
5874
|
total_borrow: totalBorrows
|
|
5872
5875
|
};
|
|
5873
5876
|
}
|
|
5874
|
-
async getUserPosition(
|
|
5875
|
-
throw DefiError.
|
|
5876
|
-
|
|
5877
|
-
|
|
5877
|
+
async getUserPosition(user) {
|
|
5878
|
+
if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
|
|
5879
|
+
const client = createPublicClient13({ transport: http13(this.rpcUrl) });
|
|
5880
|
+
const ERC20_ABI42 = parseAbi17([
|
|
5881
|
+
"function symbol() external view returns (string)"
|
|
5882
|
+
]);
|
|
5883
|
+
const supplies = [];
|
|
5884
|
+
const borrows = [];
|
|
5885
|
+
await Promise.all(this.vTokenCandidates.map(async (vtoken) => {
|
|
5886
|
+
try {
|
|
5887
|
+
const [vtokenBal, rate, borrowed, underlying] = await Promise.all([
|
|
5888
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "balanceOf", args: [user] }),
|
|
5889
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "exchangeRateStored" }),
|
|
5890
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "borrowBalanceStored", args: [user] }),
|
|
5891
|
+
client.readContract({ address: vtoken, abi: CTOKEN_ABI, functionName: "underlying" }).catch(() => null)
|
|
5892
|
+
]);
|
|
5893
|
+
if (vtokenBal === 0n && borrowed === 0n) return;
|
|
5894
|
+
const assetAddr = underlying ?? vtoken;
|
|
5895
|
+
const symbol = await client.readContract({
|
|
5896
|
+
address: assetAddr,
|
|
5897
|
+
abi: ERC20_ABI42,
|
|
5898
|
+
functionName: "symbol"
|
|
5899
|
+
}).catch(() => "?");
|
|
5900
|
+
const supplyUnderlying = vtokenBal * rate / 10n ** 18n;
|
|
5901
|
+
if (supplyUnderlying > 0n) supplies.push({ asset: assetAddr, symbol, amount: supplyUnderlying });
|
|
5902
|
+
if (borrowed > 0n) borrows.push({ asset: assetAddr, symbol, amount: borrowed });
|
|
5903
|
+
} catch {
|
|
5904
|
+
}
|
|
5905
|
+
}));
|
|
5906
|
+
return {
|
|
5907
|
+
protocol: this.protocolName,
|
|
5908
|
+
user,
|
|
5909
|
+
supplies,
|
|
5910
|
+
borrows
|
|
5911
|
+
};
|
|
5878
5912
|
}
|
|
5879
5913
|
};
|
|
5880
5914
|
COMET_ABI = parseAbi18([
|
|
@@ -5884,6 +5918,8 @@ var init_dist2 = __esm({
|
|
|
5884
5918
|
"function getBorrowRate(uint256 utilization) external view returns (uint64)",
|
|
5885
5919
|
"function totalSupply() external view returns (uint256)",
|
|
5886
5920
|
"function totalBorrow() external view returns (uint256)",
|
|
5921
|
+
"function balanceOf(address account) external view returns (uint256)",
|
|
5922
|
+
"function borrowBalanceOf(address account) external view returns (uint256)",
|
|
5887
5923
|
"function supply(address asset, uint256 amount) external",
|
|
5888
5924
|
"function withdraw(address asset, uint256 amount) external"
|
|
5889
5925
|
]);
|
|
@@ -6014,10 +6050,30 @@ var init_dist2 = __esm({
|
|
|
6014
6050
|
total_borrow: totalBorrow
|
|
6015
6051
|
};
|
|
6016
6052
|
}
|
|
6017
|
-
async getUserPosition(
|
|
6018
|
-
throw DefiError.
|
|
6019
|
-
|
|
6020
|
-
|
|
6053
|
+
async getUserPosition(user) {
|
|
6054
|
+
if (!this.rpcUrl) throw DefiError.rpcError("No RPC URL configured");
|
|
6055
|
+
const client = createPublicClient14({ transport: http14(this.rpcUrl) });
|
|
6056
|
+
const ERC20_ABI42 = parseAbi18([
|
|
6057
|
+
"function symbol() external view returns (string)"
|
|
6058
|
+
]);
|
|
6059
|
+
const [supplyBal, borrowBal, baseToken] = await Promise.all([
|
|
6060
|
+
client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "balanceOf", args: [user] }).catch(() => 0n),
|
|
6061
|
+
client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "borrowBalanceOf", args: [user] }).catch(() => 0n),
|
|
6062
|
+
client.readContract({ address: this.comet, abi: COMET_ABI, functionName: "baseToken" })
|
|
6063
|
+
]);
|
|
6064
|
+
const baseSymbol = await client.readContract({
|
|
6065
|
+
address: baseToken,
|
|
6066
|
+
abi: ERC20_ABI42,
|
|
6067
|
+
functionName: "symbol"
|
|
6068
|
+
}).catch(() => "?");
|
|
6069
|
+
const supplies = supplyBal > 0n ? [{ asset: baseToken, symbol: baseSymbol, amount: supplyBal }] : [];
|
|
6070
|
+
const borrows = borrowBal > 0n ? [{ asset: baseToken, symbol: baseSymbol, amount: borrowBal }] : [];
|
|
6071
|
+
return {
|
|
6072
|
+
protocol: this.protocolName,
|
|
6073
|
+
user,
|
|
6074
|
+
supplies,
|
|
6075
|
+
borrows
|
|
6076
|
+
};
|
|
6021
6077
|
}
|
|
6022
6078
|
};
|
|
6023
6079
|
EULER_VAULT_ABI = parseAbi19([
|