@hypurrquant/defi-cli 0.2.0 → 0.2.2
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 +224 -19
- package/dist/main.js.map +1 -1
- package/dist/mcp-server.js +23 -15
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp-server.js
CHANGED
|
@@ -5346,27 +5346,36 @@ server.tool(
|
|
|
5346
5346
|
try {
|
|
5347
5347
|
const oracle = createOracleFromLending2(p, rpcUrl);
|
|
5348
5348
|
const price = await oracle.getPrice(assetAddr);
|
|
5349
|
-
if (price > 0) prices.push({ source: p.slug, source_type: "oracle", price });
|
|
5349
|
+
if (price.price_f64 > 0) prices.push({ source: p.slug, source_type: "oracle", price: price.price_f64 });
|
|
5350
5350
|
} catch {
|
|
5351
5351
|
}
|
|
5352
5352
|
}));
|
|
5353
5353
|
}
|
|
5354
5354
|
if (srcMode === "all" || srcMode === "dex") {
|
|
5355
5355
|
const { DexSpotPrice: DexSpotPrice2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports2));
|
|
5356
|
-
const WHYPE2 = "0x5555555555555555555555555555555555555555";
|
|
5357
5356
|
const USDC_SYMBOL = "USDC";
|
|
5358
5357
|
let usdcAddr;
|
|
5358
|
+
let usdcDecimals = 6;
|
|
5359
5359
|
try {
|
|
5360
|
-
|
|
5360
|
+
const usdcToken = registry.resolveToken(chainName, USDC_SYMBOL);
|
|
5361
|
+
usdcAddr = usdcToken.address;
|
|
5362
|
+
usdcDecimals = usdcToken.decimals;
|
|
5361
5363
|
} catch {
|
|
5362
5364
|
}
|
|
5365
|
+
let assetDecimals = 18;
|
|
5366
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(asset)) {
|
|
5367
|
+
try {
|
|
5368
|
+
assetDecimals = registry.resolveToken(chainName, asset).decimals;
|
|
5369
|
+
} catch {
|
|
5370
|
+
}
|
|
5371
|
+
}
|
|
5363
5372
|
if (usdcAddr && assetAddr.toLowerCase() !== usdcAddr.toLowerCase()) {
|
|
5364
5373
|
const dexProtos = registry.getProtocolsForChain(chainName).filter((p) => p.category === ProtocolCategory2.Dex);
|
|
5365
5374
|
await Promise.all(dexProtos.map(async (p) => {
|
|
5366
5375
|
try {
|
|
5367
|
-
const dex =
|
|
5368
|
-
const
|
|
5369
|
-
if (
|
|
5376
|
+
const dex = createDex(p, rpcUrl);
|
|
5377
|
+
const priceData = await DexSpotPrice2.getPrice(dex, assetAddr, assetDecimals, usdcAddr, usdcDecimals);
|
|
5378
|
+
if (priceData.price_f64 > 0) prices.push({ source: p.slug, source_type: "dex", price: priceData.price_f64 });
|
|
5370
5379
|
} catch {
|
|
5371
5380
|
}
|
|
5372
5381
|
}));
|
|
@@ -5409,10 +5418,9 @@ server.tool(
|
|
|
5409
5418
|
const rpcUrl = chainConfig.effectiveRpcUrl();
|
|
5410
5419
|
const { ProtocolCategory: ProtocolCategory2 } = await Promise.resolve().then(() => (init_dist2(), dist_exports));
|
|
5411
5420
|
const { createOracleFromLending: createOracleFromLending2, DexSpotPrice: DexSpotPrice2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports2));
|
|
5412
|
-
const tokens = registry.
|
|
5421
|
+
const tokens = registry.tokens.get(chainName) ?? [];
|
|
5413
5422
|
const lendingProtos = registry.getProtocolsForChain(chainName).filter((p) => p.category === ProtocolCategory2.Lending);
|
|
5414
5423
|
const dexProtos = registry.getProtocolsForChain(chainName).filter((p) => p.category === ProtocolCategory2.Dex);
|
|
5415
|
-
const WHYPE2 = "0x5555555555555555555555555555555555555555";
|
|
5416
5424
|
let usdcAddr;
|
|
5417
5425
|
try {
|
|
5418
5426
|
usdcAddr = registry.resolveToken(chainName, "USDC").address;
|
|
@@ -5427,9 +5435,9 @@ server.tool(
|
|
|
5427
5435
|
for (const p of lendingProtos) {
|
|
5428
5436
|
try {
|
|
5429
5437
|
const oracle = createOracleFromLending2(p, rpcUrl);
|
|
5430
|
-
const
|
|
5431
|
-
if (
|
|
5432
|
-
oraclePrice =
|
|
5438
|
+
const priceData = await oracle.getPrice(addr);
|
|
5439
|
+
if (priceData.price_f64 > 0) {
|
|
5440
|
+
oraclePrice = priceData.price_f64;
|
|
5433
5441
|
break;
|
|
5434
5442
|
}
|
|
5435
5443
|
} catch {
|
|
@@ -5437,10 +5445,10 @@ server.tool(
|
|
|
5437
5445
|
}
|
|
5438
5446
|
for (const p of dexProtos) {
|
|
5439
5447
|
try {
|
|
5440
|
-
const dex =
|
|
5441
|
-
const
|
|
5442
|
-
if (
|
|
5443
|
-
dexPrice =
|
|
5448
|
+
const dex = createDex(p, rpcUrl);
|
|
5449
|
+
const priceData = await DexSpotPrice2.getPrice(dex, addr, token.decimals, usdcAddr, 6);
|
|
5450
|
+
if (priceData.price_f64 > 0) {
|
|
5451
|
+
dexPrice = priceData.price_f64;
|
|
5444
5452
|
break;
|
|
5445
5453
|
}
|
|
5446
5454
|
} catch {
|