recon-crypto-mcp 0.1.0
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/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/abis/aave-pool.d.ts +174 -0
- package/dist/abis/aave-pool.js +101 -0
- package/dist/abis/aave-pool.js.map +1 -0
- package/dist/abis/aave-ui-pool-data-provider.d.ts +232 -0
- package/dist/abis/aave-ui-pool-data-provider.js +107 -0
- package/dist/abis/aave-ui-pool-data-provider.js.map +1 -0
- package/dist/abis/access-control.d.ts +94 -0
- package/dist/abis/access-control.js +51 -0
- package/dist/abis/access-control.js.map +1 -0
- package/dist/abis/compound-comet.d.ts +120 -0
- package/dist/abis/compound-comet.js +84 -0
- package/dist/abis/compound-comet.js.map +1 -0
- package/dist/abis/eigenlayer-delegation-manager.d.ts +23 -0
- package/dist/abis/eigenlayer-delegation-manager.js +18 -0
- package/dist/abis/eigenlayer-delegation-manager.js.map +1 -0
- package/dist/abis/eigenlayer-strategy-manager.d.ts +53 -0
- package/dist/abis/eigenlayer-strategy-manager.js +47 -0
- package/dist/abis/eigenlayer-strategy-manager.js.map +1 -0
- package/dist/abis/erc20.d.ts +78 -0
- package/dist/abis/erc20.js +10 -0
- package/dist/abis/erc20.js.map +1 -0
- package/dist/abis/lido.d.ts +80 -0
- package/dist/abis/lido.js +60 -0
- package/dist/abis/lido.js.map +1 -0
- package/dist/abis/morpho-blue.d.ts +321 -0
- package/dist/abis/morpho-blue.js +193 -0
- package/dist/abis/morpho-blue.js.map +1 -0
- package/dist/abis/uniswap-pool.d.ts +70 -0
- package/dist/abis/uniswap-pool.js +53 -0
- package/dist/abis/uniswap-pool.js.map +1 -0
- package/dist/abis/uniswap-position-manager.d.ts +71 -0
- package/dist/abis/uniswap-position-manager.js +41 -0
- package/dist/abis/uniswap-position-manager.js.map +1 -0
- package/dist/config/cache.d.ts +12 -0
- package/dist/config/cache.js +12 -0
- package/dist/config/cache.js.map +1 -0
- package/dist/config/chains.d.ts +24 -0
- package/dist/config/chains.js +158 -0
- package/dist/config/chains.js.map +1 -0
- package/dist/config/contracts.d.ts +107 -0
- package/dist/config/contracts.js +123 -0
- package/dist/config/contracts.js.map +1 -0
- package/dist/config/user-config.d.ts +15 -0
- package/dist/config/user-config.js +93 -0
- package/dist/config/user-config.js.map +1 -0
- package/dist/data/apis/etherscan.d.ts +30 -0
- package/dist/data/apis/etherscan.js +109 -0
- package/dist/data/apis/etherscan.js.map +1 -0
- package/dist/data/cache.d.ts +18 -0
- package/dist/data/cache.js +47 -0
- package/dist/data/cache.js.map +1 -0
- package/dist/data/format.d.ts +6 -0
- package/dist/data/format.js +44 -0
- package/dist/data/format.js.map +1 -0
- package/dist/data/prices.d.ts +12 -0
- package/dist/data/prices.js +81 -0
- package/dist/data/prices.js.map +1 -0
- package/dist/data/rpc.d.ts +17 -0
- package/dist/data/rpc.js +68 -0
- package/dist/data/rpc.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +344 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/balances/index.d.ts +20 -0
- package/dist/modules/balances/index.js +49 -0
- package/dist/modules/balances/index.js.map +1 -0
- package/dist/modules/balances/schemas.d.ts +32 -0
- package/dist/modules/balances/schemas.js +21 -0
- package/dist/modules/balances/schemas.js.map +1 -0
- package/dist/modules/bitcoin/index.d.ts +26 -0
- package/dist/modules/bitcoin/index.js +128 -0
- package/dist/modules/bitcoin/index.js.map +1 -0
- package/dist/modules/bitcoin/schemas.d.ts +49 -0
- package/dist/modules/bitcoin/schemas.js +51 -0
- package/dist/modules/bitcoin/schemas.js.map +1 -0
- package/dist/modules/bitcoin/send.d.ts +52 -0
- package/dist/modules/bitcoin/send.js +158 -0
- package/dist/modules/bitcoin/send.js.map +1 -0
- package/dist/modules/bitcoin/utxo.d.ts +99 -0
- package/dist/modules/bitcoin/utxo.js +116 -0
- package/dist/modules/bitcoin/utxo.js.map +1 -0
- package/dist/modules/compound/actions.d.ts +8 -0
- package/dist/modules/compound/actions.js +154 -0
- package/dist/modules/compound/actions.js.map +1 -0
- package/dist/modules/compound/index.d.ts +26 -0
- package/dist/modules/compound/index.js +141 -0
- package/dist/modules/compound/index.js.map +1 -0
- package/dist/modules/compound/schemas.d.ts +95 -0
- package/dist/modules/compound/schemas.js +37 -0
- package/dist/modules/compound/schemas.js.map +1 -0
- package/dist/modules/execution/index.d.ts +51 -0
- package/dist/modules/execution/index.js +271 -0
- package/dist/modules/execution/index.js.map +1 -0
- package/dist/modules/execution/schemas.d.ts +183 -0
- package/dist/modules/execution/schemas.js +88 -0
- package/dist/modules/execution/schemas.js.map +1 -0
- package/dist/modules/feedback/index.d.ts +28 -0
- package/dist/modules/feedback/index.js +161 -0
- package/dist/modules/feedback/index.js.map +1 -0
- package/dist/modules/feedback/rate-limit.d.ts +15 -0
- package/dist/modules/feedback/rate-limit.js +110 -0
- package/dist/modules/feedback/rate-limit.js.map +1 -0
- package/dist/modules/feedback/schemas.d.ts +41 -0
- package/dist/modules/feedback/schemas.js +40 -0
- package/dist/modules/feedback/schemas.js.map +1 -0
- package/dist/modules/morpho/actions.d.ts +8 -0
- package/dist/modules/morpho/actions.js +265 -0
- package/dist/modules/morpho/actions.js.map +1 -0
- package/dist/modules/morpho/index.d.ts +26 -0
- package/dist/modules/morpho/index.js +94 -0
- package/dist/modules/morpho/index.js.map +1 -0
- package/dist/modules/morpho/schemas.d.ts +130 -0
- package/dist/modules/morpho/schemas.js +34 -0
- package/dist/modules/morpho/schemas.js.map +1 -0
- package/dist/modules/portfolio/index.d.ts +3 -0
- package/dist/modules/portfolio/index.js +197 -0
- package/dist/modules/portfolio/index.js.map +1 -0
- package/dist/modules/portfolio/schemas.d.ts +20 -0
- package/dist/modules/portfolio/schemas.js +15 -0
- package/dist/modules/portfolio/schemas.js.map +1 -0
- package/dist/modules/positions/aave.d.ts +22 -0
- package/dist/modules/positions/aave.js +197 -0
- package/dist/modules/positions/aave.js.map +1 -0
- package/dist/modules/positions/actions.d.ts +18 -0
- package/dist/modules/positions/actions.js +205 -0
- package/dist/modules/positions/actions.js.map +1 -0
- package/dist/modules/positions/index.d.ts +37 -0
- package/dist/modules/positions/index.js +59 -0
- package/dist/modules/positions/index.js.map +1 -0
- package/dist/modules/positions/schemas.d.ts +55 -0
- package/dist/modules/positions/schemas.js +25 -0
- package/dist/modules/positions/schemas.js.map +1 -0
- package/dist/modules/positions/uniswap.d.ts +4 -0
- package/dist/modules/positions/uniswap.js +181 -0
- package/dist/modules/positions/uniswap.js.map +1 -0
- package/dist/modules/prices/index.d.ts +19 -0
- package/dist/modules/prices/index.js +22 -0
- package/dist/modules/prices/index.js.map +1 -0
- package/dist/modules/security/index.d.ts +26 -0
- package/dist/modules/security/index.js +13 -0
- package/dist/modules/security/index.js.map +1 -0
- package/dist/modules/security/permissions.d.ts +8 -0
- package/dist/modules/security/permissions.js +96 -0
- package/dist/modules/security/permissions.js.map +1 -0
- package/dist/modules/security/risk-score.d.ts +18 -0
- package/dist/modules/security/risk-score.js +116 -0
- package/dist/modules/security/risk-score.js.map +1 -0
- package/dist/modules/security/schemas.d.ts +31 -0
- package/dist/modules/security/schemas.js +16 -0
- package/dist/modules/security/schemas.js.map +1 -0
- package/dist/modules/security/verification.d.ts +4 -0
- package/dist/modules/security/verification.js +82 -0
- package/dist/modules/security/verification.js.map +1 -0
- package/dist/modules/shared/approval.d.ts +71 -0
- package/dist/modules/shared/approval.js +130 -0
- package/dist/modules/shared/approval.js.map +1 -0
- package/dist/modules/staking/actions.d.ts +22 -0
- package/dist/modules/staking/actions.js +100 -0
- package/dist/modules/staking/actions.js.map +1 -0
- package/dist/modules/staking/eigenlayer.d.ts +14 -0
- package/dist/modules/staking/eigenlayer.js +105 -0
- package/dist/modules/staking/eigenlayer.js.map +1 -0
- package/dist/modules/staking/index.d.ts +24 -0
- package/dist/modules/staking/index.js +59 -0
- package/dist/modules/staking/index.js.map +1 -0
- package/dist/modules/staking/lido.d.ts +14 -0
- package/dist/modules/staking/lido.js +113 -0
- package/dist/modules/staking/lido.js.map +1 -0
- package/dist/modules/staking/schemas.d.ts +34 -0
- package/dist/modules/staking/schemas.js +20 -0
- package/dist/modules/staking/schemas.js.map +1 -0
- package/dist/modules/swap/index.d.ts +47 -0
- package/dist/modules/swap/index.js +376 -0
- package/dist/modules/swap/index.js.map +1 -0
- package/dist/modules/swap/lifi.d.ts +17 -0
- package/dist/modules/swap/lifi.js +44 -0
- package/dist/modules/swap/lifi.js.map +1 -0
- package/dist/modules/swap/oneinch.d.ts +26 -0
- package/dist/modules/swap/oneinch.js +33 -0
- package/dist/modules/swap/oneinch.js.map +1 -0
- package/dist/modules/swap/schemas.d.ts +65 -0
- package/dist/modules/swap/schemas.js +46 -0
- package/dist/modules/swap/schemas.js.map +1 -0
- package/dist/setup.d.ts +2 -0
- package/dist/setup.js +257 -0
- package/dist/setup.js.map +1 -0
- package/dist/signing/pre-sign-check.d.ts +8 -0
- package/dist/signing/pre-sign-check.js +231 -0
- package/dist/signing/pre-sign-check.js.map +1 -0
- package/dist/signing/session.d.ts +28 -0
- package/dist/signing/session.js +26 -0
- package/dist/signing/session.js.map +1 -0
- package/dist/signing/tx-store.d.ts +29 -0
- package/dist/signing/tx-store.js +85 -0
- package/dist/signing/tx-store.js.map +1 -0
- package/dist/signing/walletconnect.d.ts +33 -0
- package/dist/signing/walletconnect.js +226 -0
- package/dist/signing/walletconnect.js.map +1 -0
- package/dist/types/index.d.ts +222 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +134 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { getAddress, keccak256, encodePacked } from "viem";
|
|
2
|
+
import { getClient } from "../../data/rpc.js";
|
|
3
|
+
import { CONTRACTS } from "../../config/contracts.js";
|
|
4
|
+
import { uniswapPositionManagerAbi } from "../../abis/uniswap-position-manager.js";
|
|
5
|
+
import { uniswapPoolAbi } from "../../abis/uniswap-pool.js";
|
|
6
|
+
import { erc20Abi } from "../../abis/erc20.js";
|
|
7
|
+
import { getTokenPrices } from "../../data/prices.js";
|
|
8
|
+
import { round, makeTokenAmount } from "../../data/format.js";
|
|
9
|
+
const POOL_INIT_CODE_HASH = "0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54";
|
|
10
|
+
/** Deterministically compute the Uniswap V3 pool address from (factory, token0, token1, fee). */
|
|
11
|
+
export function computePoolAddress(factory, tokenA, tokenB, fee) {
|
|
12
|
+
const [token0, token1] = tokenA.toLowerCase() < tokenB.toLowerCase() ? [tokenA, tokenB] : [tokenB, tokenA];
|
|
13
|
+
const salt = keccak256(encodePacked(["address", "address", "uint24"], [token0, token1, fee]));
|
|
14
|
+
// CREATE2: address = keccak256(0xff ++ factory ++ salt ++ keccak256(init_code))[12:]
|
|
15
|
+
const packed = `0xff${factory.slice(2)}${salt.slice(2)}${POOL_INIT_CODE_HASH.slice(2)}`;
|
|
16
|
+
const hash = keccak256(packed);
|
|
17
|
+
return getAddress(`0x${hash.slice(26)}`);
|
|
18
|
+
}
|
|
19
|
+
/** 1.0001^tick — price of token1 per token0 in raw (not decimal-adjusted) terms. */
|
|
20
|
+
function tickToPrice(tick) {
|
|
21
|
+
return Math.pow(1.0001, tick);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compute amounts of token0 / token1 held in a concentrated-liquidity position
|
|
25
|
+
* given current sqrtPrice (Q96) and the tick bounds.
|
|
26
|
+
*
|
|
27
|
+
* Reference: https://blog.uniswap.org/uniswap-v3-math-primer
|
|
28
|
+
*/
|
|
29
|
+
function computeAmountsFromLiquidity(liquidity, sqrtPriceX96, tickLower, tickUpper, currentTick) {
|
|
30
|
+
const Q96 = 2n ** 96n;
|
|
31
|
+
const sqrtLower = BigInt(Math.floor(Math.sqrt(tickToPrice(tickLower)) * Number(Q96)));
|
|
32
|
+
const sqrtUpper = BigInt(Math.floor(Math.sqrt(tickToPrice(tickUpper)) * Number(Q96)));
|
|
33
|
+
const sqrtP = sqrtPriceX96;
|
|
34
|
+
let amount0 = 0n;
|
|
35
|
+
let amount1 = 0n;
|
|
36
|
+
if (currentTick < tickLower) {
|
|
37
|
+
amount0 = (liquidity * (sqrtUpper - sqrtLower) * Q96) / (sqrtUpper * sqrtLower);
|
|
38
|
+
}
|
|
39
|
+
else if (currentTick >= tickUpper) {
|
|
40
|
+
amount1 = (liquidity * (sqrtUpper - sqrtLower)) / Q96;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
amount0 = (liquidity * (sqrtUpper - sqrtP) * Q96) / (sqrtUpper * sqrtP);
|
|
44
|
+
amount1 = (liquidity * (sqrtP - sqrtLower)) / Q96;
|
|
45
|
+
}
|
|
46
|
+
return { amount0, amount1 };
|
|
47
|
+
}
|
|
48
|
+
export async function getUniswapPositions(wallet, chain) {
|
|
49
|
+
try {
|
|
50
|
+
return await readUniswapPositions(wallet, chain);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Degrade to empty — same reasoning as Aave reader. LP breakdown is decorative; it
|
|
54
|
+
// shouldn't be able to sink the whole portfolio call on a transient RPC miss.
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function readUniswapPositions(wallet, chain) {
|
|
59
|
+
const client = getClient(chain);
|
|
60
|
+
const npm = CONTRACTS[chain].uniswap.positionManager;
|
|
61
|
+
const factory = CONTRACTS[chain].uniswap.factory;
|
|
62
|
+
const balance = (await client.readContract({
|
|
63
|
+
address: npm,
|
|
64
|
+
abi: uniswapPositionManagerAbi,
|
|
65
|
+
functionName: "balanceOf",
|
|
66
|
+
args: [wallet],
|
|
67
|
+
}));
|
|
68
|
+
const count = Number(balance);
|
|
69
|
+
if (count === 0)
|
|
70
|
+
return [];
|
|
71
|
+
// 1) Batch fetch all tokenIds
|
|
72
|
+
const idCalls = Array.from({ length: count }, (_, i) => ({
|
|
73
|
+
address: npm,
|
|
74
|
+
abi: uniswapPositionManagerAbi,
|
|
75
|
+
functionName: "tokenOfOwnerByIndex",
|
|
76
|
+
args: [wallet, BigInt(i)],
|
|
77
|
+
}));
|
|
78
|
+
const idResults = await client.multicall({ contracts: idCalls, allowFailure: true });
|
|
79
|
+
const tokenIds = idResults
|
|
80
|
+
.map((r) => (r.status === "success" ? r.result : null))
|
|
81
|
+
.filter((x) => x !== null);
|
|
82
|
+
// 2) Batch fetch position details
|
|
83
|
+
const posCalls = tokenIds.map((id) => ({
|
|
84
|
+
address: npm,
|
|
85
|
+
abi: uniswapPositionManagerAbi,
|
|
86
|
+
functionName: "positions",
|
|
87
|
+
args: [id],
|
|
88
|
+
}));
|
|
89
|
+
const posResults = await client.multicall({ contracts: posCalls, allowFailure: true });
|
|
90
|
+
const raw = [];
|
|
91
|
+
for (let i = 0; i < posResults.length; i++) {
|
|
92
|
+
const r = posResults[i];
|
|
93
|
+
if (r.status !== "success")
|
|
94
|
+
continue;
|
|
95
|
+
const tuple = r.result;
|
|
96
|
+
// positions() returns: nonce, operator, token0, token1, fee, tickLower, tickUpper, liquidity, fgi0, fgi1, owed0, owed1
|
|
97
|
+
const [, , token0, token1, fee, tickLower, tickUpper, liquidity, , , owed0, owed1] = tuple;
|
|
98
|
+
// Skip empty positions (closed / burned)
|
|
99
|
+
if (liquidity === 0n && owed0 === 0n && owed1 === 0n)
|
|
100
|
+
continue;
|
|
101
|
+
raw.push({
|
|
102
|
+
tokenId: tokenIds[i],
|
|
103
|
+
token0,
|
|
104
|
+
token1,
|
|
105
|
+
fee: Number(fee),
|
|
106
|
+
tickLower: Number(tickLower),
|
|
107
|
+
tickUpper: Number(tickUpper),
|
|
108
|
+
liquidity,
|
|
109
|
+
tokensOwed0: owed0,
|
|
110
|
+
tokensOwed1: owed1,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (raw.length === 0)
|
|
114
|
+
return [];
|
|
115
|
+
// 3) For each position, resolve pool address and fetch slot0 + token metadata
|
|
116
|
+
const poolAddrs = raw.map((p) => computePoolAddress(factory, p.token0, p.token1, p.fee));
|
|
117
|
+
const slot0Calls = poolAddrs.map((p) => ({
|
|
118
|
+
address: p,
|
|
119
|
+
abi: uniswapPoolAbi,
|
|
120
|
+
functionName: "slot0",
|
|
121
|
+
}));
|
|
122
|
+
// We also want decimals + symbol for both tokens.
|
|
123
|
+
const tokenMetaCalls = raw.flatMap((p) => [
|
|
124
|
+
{ address: p.token0, abi: erc20Abi, functionName: "decimals" },
|
|
125
|
+
{ address: p.token0, abi: erc20Abi, functionName: "symbol" },
|
|
126
|
+
{ address: p.token1, abi: erc20Abi, functionName: "decimals" },
|
|
127
|
+
{ address: p.token1, abi: erc20Abi, functionName: "symbol" },
|
|
128
|
+
]);
|
|
129
|
+
const [slot0Results, metaResults] = await Promise.all([
|
|
130
|
+
client.multicall({ contracts: slot0Calls, allowFailure: true }),
|
|
131
|
+
client.multicall({ contracts: tokenMetaCalls, allowFailure: true }),
|
|
132
|
+
]);
|
|
133
|
+
// 4) Batch price fetch for every token involved
|
|
134
|
+
const uniqueTokens = new Set();
|
|
135
|
+
raw.forEach((p) => {
|
|
136
|
+
uniqueTokens.add(p.token0.toLowerCase());
|
|
137
|
+
uniqueTokens.add(p.token1.toLowerCase());
|
|
138
|
+
});
|
|
139
|
+
const prices = await getTokenPrices([...uniqueTokens].map((addr) => ({ chain, address: addr })));
|
|
140
|
+
const positions = [];
|
|
141
|
+
for (let i = 0; i < raw.length; i++) {
|
|
142
|
+
const p = raw[i];
|
|
143
|
+
const slotRes = slot0Results[i];
|
|
144
|
+
if (slotRes.status !== "success")
|
|
145
|
+
continue;
|
|
146
|
+
const slot0 = slotRes.result;
|
|
147
|
+
const sqrtPriceX96 = slot0[0];
|
|
148
|
+
const currentTick = Number(slot0[1]);
|
|
149
|
+
const dec0 = Number(metaResults[i * 4]?.status === "success" ? metaResults[i * 4].result : 18);
|
|
150
|
+
const sym0 = metaResults[i * 4 + 1]?.status === "success" ? metaResults[i * 4 + 1].result : "?";
|
|
151
|
+
const dec1 = Number(metaResults[i * 4 + 2]?.status === "success" ? metaResults[i * 4 + 2].result : 18);
|
|
152
|
+
const sym1 = metaResults[i * 4 + 3]?.status === "success" ? metaResults[i * 4 + 3].result : "?";
|
|
153
|
+
const { amount0, amount1 } = computeAmountsFromLiquidity(p.liquidity, sqrtPriceX96, p.tickLower, p.tickUpper, currentTick);
|
|
154
|
+
const price0 = prices.get(`${chain}:${p.token0.toLowerCase()}`);
|
|
155
|
+
const price1 = prices.get(`${chain}:${p.token1.toLowerCase()}`);
|
|
156
|
+
const token0 = makeTokenAmount(chain, p.token0, amount0, dec0, sym0, price0);
|
|
157
|
+
const token1 = makeTokenAmount(chain, p.token1, amount1, dec1, sym1, price1);
|
|
158
|
+
const totalValueUsd = round((token0.valueUsd ?? 0) + (token1.valueUsd ?? 0), 2);
|
|
159
|
+
const fees0 = makeTokenAmount(chain, p.token0, p.tokensOwed0, dec0, sym0, price0);
|
|
160
|
+
const fees1 = makeTokenAmount(chain, p.token1, p.tokensOwed1, dec1, sym1, price1);
|
|
161
|
+
positions.push({
|
|
162
|
+
protocol: "uniswap-v3",
|
|
163
|
+
chain,
|
|
164
|
+
tokenId: p.tokenId.toString(),
|
|
165
|
+
token0,
|
|
166
|
+
token1,
|
|
167
|
+
feeTier: p.fee,
|
|
168
|
+
tickLower: p.tickLower,
|
|
169
|
+
tickUpper: p.tickUpper,
|
|
170
|
+
currentTick,
|
|
171
|
+
inRange: p.tickLower <= currentTick && currentTick < p.tickUpper,
|
|
172
|
+
liquidity: p.liquidity.toString(),
|
|
173
|
+
tokensOwedCached0: fees0,
|
|
174
|
+
tokensOwedCached1: fees1,
|
|
175
|
+
totalValueUsd,
|
|
176
|
+
valueUsdIsApproximate: true,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return positions;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=uniswap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniswap.js","sourceRoot":"","sources":["../../../src/modules/positions/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AS,IAAI,WAAW,IAAI,WAAW,GAAG,CAAC,CAAC,SAAS;YAChE,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE;YACjC,iBAAiB,EAAE,KAAK;YACxB,iBAAiB,EAAE,KAAK;YACxB,aAAa;YACb,qBAAqB,EAAE,IAAI;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type SupportedChain } from "../../types/index.js";
|
|
3
|
+
export declare const getTokenPriceInput: z.ZodObject<{
|
|
4
|
+
chain: z.ZodEnum<[string, ...string[]]>;
|
|
5
|
+
token: z.ZodUnion<[z.ZodLiteral<"native">, z.ZodString]>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
chain: string;
|
|
8
|
+
token: string;
|
|
9
|
+
}, {
|
|
10
|
+
chain: string;
|
|
11
|
+
token: string;
|
|
12
|
+
}>;
|
|
13
|
+
export type GetTokenPriceArgs = z.infer<typeof getTokenPriceInput>;
|
|
14
|
+
export declare function getTokenPriceTool(args: GetTokenPriceArgs): Promise<{
|
|
15
|
+
chain: SupportedChain;
|
|
16
|
+
token: `0x${string}` | "native";
|
|
17
|
+
priceUsd: number;
|
|
18
|
+
source: "defillama";
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { getTokenPrice } from "../../data/prices.js";
|
|
3
|
+
import { SUPPORTED_CHAINS } from "../../types/index.js";
|
|
4
|
+
const chainEnum = z.enum(SUPPORTED_CHAINS);
|
|
5
|
+
const tokenSchema = z.union([
|
|
6
|
+
z.literal("native"),
|
|
7
|
+
z.string().regex(/^0x[a-fA-F0-9]{40}$/),
|
|
8
|
+
]);
|
|
9
|
+
export const getTokenPriceInput = z.object({
|
|
10
|
+
chain: chainEnum,
|
|
11
|
+
token: tokenSchema,
|
|
12
|
+
});
|
|
13
|
+
export async function getTokenPriceTool(args) {
|
|
14
|
+
const chain = args.chain;
|
|
15
|
+
const token = args.token;
|
|
16
|
+
const priceUsd = await getTokenPrice(chain, token);
|
|
17
|
+
if (priceUsd === undefined) {
|
|
18
|
+
throw new Error(`No DefiLlama price found for ${token} on ${chain}. The token may be unlisted, illiquid, or the address may be wrong.`);
|
|
19
|
+
}
|
|
20
|
+
return { chain, token, priceUsd, source: "defillama" };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/prices/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAuB,MAAM,sBAAsB,CAAC;AAE7E,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,gBAAoD,CAAC,CAAC;AAC/E,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC;IAC1B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnB,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,WAAW;CACnB,CAAC,CAAC;AAIH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAuB;IAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAuB,CAAC;IAC3C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAiC,CAAC;IACrD,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,gCAAgC,KAAK,OAAO,KAAK,qEAAqE,CACvH,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAoB,EAAE,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CheckContractSecurityArgs, CheckPermissionRisksArgs, GetProtocolRiskScoreArgs } from "./schemas.js";
|
|
2
|
+
import type { SupportedChain } from "../../types/index.js";
|
|
3
|
+
export declare function checkContractSecurityHandler(args: CheckContractSecurityArgs): Promise<import("../../types/index.js").SecurityReport>;
|
|
4
|
+
export declare function checkPermissionRisksHandler(args: CheckPermissionRisksArgs): Promise<{
|
|
5
|
+
address: `0x${string}`;
|
|
6
|
+
chain: SupportedChain;
|
|
7
|
+
roles: import("../../types/index.js").PrivilegedRole[];
|
|
8
|
+
notes: string[];
|
|
9
|
+
}>;
|
|
10
|
+
export declare function getProtocolRiskScoreHandler(args: GetProtocolRiskScoreArgs): Promise<{
|
|
11
|
+
protocol: string;
|
|
12
|
+
score?: number;
|
|
13
|
+
breakdown: Record<string, {
|
|
14
|
+
value: number;
|
|
15
|
+
weight: number;
|
|
16
|
+
note: string;
|
|
17
|
+
}>;
|
|
18
|
+
raw: {
|
|
19
|
+
tvlUsd?: number;
|
|
20
|
+
tvlTrend30d?: number;
|
|
21
|
+
contractAgeDays?: number;
|
|
22
|
+
hasBugBounty: boolean;
|
|
23
|
+
bountyMaxUsd?: number;
|
|
24
|
+
auditsReported?: number;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { checkContractSecurity } from "./verification.js";
|
|
2
|
+
import { checkPermissionRisks } from "./permissions.js";
|
|
3
|
+
import { getProtocolRiskScore } from "./risk-score.js";
|
|
4
|
+
export async function checkContractSecurityHandler(args) {
|
|
5
|
+
return checkContractSecurity(args.address, args.chain);
|
|
6
|
+
}
|
|
7
|
+
export async function checkPermissionRisksHandler(args) {
|
|
8
|
+
return checkPermissionRisks(args.address, args.chain);
|
|
9
|
+
}
|
|
10
|
+
export async function getProtocolRiskScoreHandler(args) {
|
|
11
|
+
return getProtocolRiskScore(args.protocol);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/security/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAQvD,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,IAA+B;IAChF,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAwB,EAAE,IAAI,CAAC,KAAuB,CAAC,CAAC;AAC5F,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,IAA8B;IAC9E,OAAO,oBAAoB,CAAC,IAAI,CAAC,OAAwB,EAAE,IAAI,CAAC,KAAuB,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,IAA8B;IAC9E,OAAO,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PrivilegedRole, SupportedChain } from "../../types/index.js";
|
|
2
|
+
/** Enumerate privileged roles on a contract (best-effort given public ABIs). */
|
|
3
|
+
export declare function checkPermissionRisks(address: `0x${string}`, chain: SupportedChain): Promise<{
|
|
4
|
+
address: `0x${string}`;
|
|
5
|
+
chain: SupportedChain;
|
|
6
|
+
roles: PrivilegedRole[];
|
|
7
|
+
notes: string[];
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { getAddress, zeroAddress } from "viem";
|
|
2
|
+
import { getClient } from "../../data/rpc.js";
|
|
3
|
+
import { getContractInfo } from "../../data/apis/etherscan.js";
|
|
4
|
+
import { ownableAbi, gnosisSafeAbi, timelockAbi } from "../../abis/access-control.js";
|
|
5
|
+
/**
|
|
6
|
+
* Detect whether `address` is a contract.
|
|
7
|
+
* For contracts, try to detect Gnosis Safe (isMultisig) and OZ TimelockController (hasTimelock).
|
|
8
|
+
*/
|
|
9
|
+
async function classifyHolder(chain, holder) {
|
|
10
|
+
const client = getClient(chain);
|
|
11
|
+
const code = await client.getCode({ address: holder });
|
|
12
|
+
const isContract = !!code && code !== "0x";
|
|
13
|
+
if (!isContract) {
|
|
14
|
+
return { isContract: false, isMultisig: false, hasTimelock: false };
|
|
15
|
+
}
|
|
16
|
+
// Gnosis Safe detection
|
|
17
|
+
let isMultisig = false;
|
|
18
|
+
try {
|
|
19
|
+
const threshold = (await client.readContract({
|
|
20
|
+
address: holder,
|
|
21
|
+
abi: gnosisSafeAbi,
|
|
22
|
+
functionName: "getThreshold",
|
|
23
|
+
}));
|
|
24
|
+
isMultisig = threshold > 0n;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// Not a Safe
|
|
28
|
+
}
|
|
29
|
+
// Timelock detection — try both getMinDelay() (OZ 4.x) and delay() (older).
|
|
30
|
+
let hasTimelock = false;
|
|
31
|
+
let timelockDelaySeconds;
|
|
32
|
+
try {
|
|
33
|
+
const delay = (await client.readContract({
|
|
34
|
+
address: holder,
|
|
35
|
+
abi: timelockAbi,
|
|
36
|
+
functionName: "getMinDelay",
|
|
37
|
+
}));
|
|
38
|
+
hasTimelock = true;
|
|
39
|
+
timelockDelaySeconds = Number(delay);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
try {
|
|
43
|
+
const delay = (await client.readContract({
|
|
44
|
+
address: holder,
|
|
45
|
+
abi: timelockAbi,
|
|
46
|
+
functionName: "delay",
|
|
47
|
+
}));
|
|
48
|
+
hasTimelock = true;
|
|
49
|
+
timelockDelaySeconds = Number(delay);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Not a timelock
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { isContract, isMultisig, hasTimelock, timelockDelaySeconds };
|
|
56
|
+
}
|
|
57
|
+
/** Enumerate privileged roles on a contract (best-effort given public ABIs). */
|
|
58
|
+
export async function checkPermissionRisks(address, chain) {
|
|
59
|
+
const client = getClient(chain);
|
|
60
|
+
const info = await getContractInfo(address, chain);
|
|
61
|
+
const roles = [];
|
|
62
|
+
const notes = [];
|
|
63
|
+
if (!info.isVerified) {
|
|
64
|
+
notes.push("Contract is not verified on Etherscan — limited permission visibility.");
|
|
65
|
+
}
|
|
66
|
+
// 1) Ownable.owner()
|
|
67
|
+
try {
|
|
68
|
+
const owner = (await client.readContract({
|
|
69
|
+
address,
|
|
70
|
+
abi: ownableAbi,
|
|
71
|
+
functionName: "owner",
|
|
72
|
+
}));
|
|
73
|
+
if (owner && owner !== zeroAddress) {
|
|
74
|
+
const cls = await classifyHolder(chain, owner);
|
|
75
|
+
roles.push({ role: "owner", holder: getAddress(owner), ...cls });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// Not Ownable.
|
|
80
|
+
}
|
|
81
|
+
// 2) AccessControl — detect via ABI scan for hasRole function. If present, we can at least note it.
|
|
82
|
+
if (info.abi && Array.isArray(info.abi)) {
|
|
83
|
+
const hasRoleFn = info.abi.some((item) => typeof item === "object" && item !== null &&
|
|
84
|
+
item.type === "function" &&
|
|
85
|
+
item.name === "hasRole");
|
|
86
|
+
if (hasRoleFn) {
|
|
87
|
+
notes.push("Contract uses OpenZeppelin AccessControl. Role holders can only be enumerated with specific role hashes " +
|
|
88
|
+
"(e.g. DEFAULT_ADMIN_ROLE = 0x000...). Further enumeration not implemented in MVP.");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (roles.length === 0 && notes.length === 0) {
|
|
92
|
+
notes.push("No standard Ownable or AccessControl pattern detected.");
|
|
93
|
+
}
|
|
94
|
+
return { address: getAddress(address), chain, roles, notes };
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../src/modules/security/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAGtF;;;GAGG;AACH,KAAK,UAAU,cAAc,CAC3B,KAAqB,EACrB,MAAqB;IAErB,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC;IAC3C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IACtE,CAAC;IAED,wBAAwB;IACxB,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,CAAC,MAAM,MAAM,CAAC,YAAY,CAAC;YAC3C,OAAO,EAAE,MAAM;YACf,GAAG,EAAE,aAAa;YAClB,YAAY,EAAE,cAAc;SAC7B,CAAC,CAAW,CAAC;QACd,UAAU,GAAG,SAAS,GAAG,EAAE,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QAC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undefined if we have no data. */
|
|
2
|
+
export declare function getProtocolRiskScore(protocol: string): Promise<{
|
|
3
|
+
protocol: string;
|
|
4
|
+
score?: number;
|
|
5
|
+
breakdown: Record<string, {
|
|
6
|
+
value: number;
|
|
7
|
+
weight: number;
|
|
8
|
+
note: string;
|
|
9
|
+
}>;
|
|
10
|
+
raw: {
|
|
11
|
+
tvlUsd?: number;
|
|
12
|
+
tvlTrend30d?: number;
|
|
13
|
+
contractAgeDays?: number;
|
|
14
|
+
hasBugBounty: boolean;
|
|
15
|
+
bountyMaxUsd?: number;
|
|
16
|
+
auditsReported?: number;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { cache } from "../../data/cache.js";
|
|
2
|
+
import { CACHE_TTL } from "../../config/cache.js";
|
|
3
|
+
import { round } from "../../data/format.js";
|
|
4
|
+
// Hardcoded Immunefi bounty data for MVP-covered protocols.
|
|
5
|
+
// Source: Immunefi program pages (https://immunefi.com/explore/).
|
|
6
|
+
const IMMUNEFI_BOUNTIES = {
|
|
7
|
+
aave: { program: "Aave", maxBountyUsd: 1_000_000 },
|
|
8
|
+
uniswap: { program: "Uniswap", maxBountyUsd: 15_500_000 }, // Uniswap has a leading program
|
|
9
|
+
lido: { program: "Lido", maxBountyUsd: 2_000_000 },
|
|
10
|
+
eigenlayer: { program: "EigenLayer", maxBountyUsd: 2_000_000 },
|
|
11
|
+
};
|
|
12
|
+
async function fetchLlamaProtocol(slug) {
|
|
13
|
+
const key = `risk:llama:${slug.toLowerCase()}`;
|
|
14
|
+
return cache.remember(key, CACHE_TTL.PROTOCOL_RISK, async () => {
|
|
15
|
+
try {
|
|
16
|
+
const res = await fetch(`https://api.llama.fi/protocol/${encodeURIComponent(slug)}`);
|
|
17
|
+
if (!res.ok)
|
|
18
|
+
return null;
|
|
19
|
+
return (await res.json());
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Compute a 0-100 risk score. Higher = safer. Returns undefined if we have no data. */
|
|
27
|
+
export async function getProtocolRiskScore(protocol) {
|
|
28
|
+
const slug = protocol.toLowerCase();
|
|
29
|
+
const data = await fetchLlamaProtocol(slug);
|
|
30
|
+
const raw = { hasBugBounty: false };
|
|
31
|
+
if (data) {
|
|
32
|
+
raw.tvlUsd = data.tvl ?? undefined;
|
|
33
|
+
if (data.tvlHistory && data.tvlHistory.length > 30) {
|
|
34
|
+
const now = data.tvlHistory[data.tvlHistory.length - 1]?.[1];
|
|
35
|
+
const then = data.tvlHistory[data.tvlHistory.length - 31]?.[1];
|
|
36
|
+
if (now && then)
|
|
37
|
+
raw.tvlTrend30d = round((now - then) / then, 4);
|
|
38
|
+
}
|
|
39
|
+
if (data.listedAt) {
|
|
40
|
+
raw.contractAgeDays = Math.floor((Date.now() / 1000 - data.listedAt) / 86400);
|
|
41
|
+
}
|
|
42
|
+
if (data.audit_links)
|
|
43
|
+
raw.auditsReported = data.audit_links.length;
|
|
44
|
+
}
|
|
45
|
+
const bounty = IMMUNEFI_BOUNTIES[slug];
|
|
46
|
+
if (bounty) {
|
|
47
|
+
raw.hasBugBounty = true;
|
|
48
|
+
raw.bountyMaxUsd = bounty.maxBountyUsd;
|
|
49
|
+
}
|
|
50
|
+
// Scoring:
|
|
51
|
+
// TVL size : up to 30 points (log scale, 30 @ $10B+)
|
|
52
|
+
// TVL trend : 10 points (positive or stable), penalty if -30%+
|
|
53
|
+
// Contract age : 20 points (10 @ 1 year, 20 @ 3 years)
|
|
54
|
+
// Bug bounty : 20 points if active
|
|
55
|
+
// Audits : 20 points (2 @ each, cap 20)
|
|
56
|
+
const breakdown = {};
|
|
57
|
+
let tvlPoints = 0;
|
|
58
|
+
if (raw.tvlUsd) {
|
|
59
|
+
tvlPoints = Math.min(30, Math.max(0, Math.log10(raw.tvlUsd / 1e6) * 10));
|
|
60
|
+
}
|
|
61
|
+
breakdown.tvl = {
|
|
62
|
+
value: round(tvlPoints, 2),
|
|
63
|
+
weight: 30,
|
|
64
|
+
note: raw.tvlUsd ? `TVL $${(raw.tvlUsd / 1e6).toFixed(1)}M` : "no TVL data",
|
|
65
|
+
};
|
|
66
|
+
let trendPoints = 0;
|
|
67
|
+
if (raw.tvlTrend30d !== undefined) {
|
|
68
|
+
if (raw.tvlTrend30d >= 0)
|
|
69
|
+
trendPoints = 10;
|
|
70
|
+
else if (raw.tvlTrend30d >= -0.3)
|
|
71
|
+
trendPoints = 5;
|
|
72
|
+
else
|
|
73
|
+
trendPoints = 0;
|
|
74
|
+
}
|
|
75
|
+
breakdown.tvlTrend = {
|
|
76
|
+
value: trendPoints,
|
|
77
|
+
weight: 10,
|
|
78
|
+
note: raw.tvlTrend30d !== undefined ? `30d change ${(raw.tvlTrend30d * 100).toFixed(1)}%` : "no trend data",
|
|
79
|
+
};
|
|
80
|
+
let agePoints = 0;
|
|
81
|
+
if (raw.contractAgeDays !== undefined) {
|
|
82
|
+
if (raw.contractAgeDays >= 1095)
|
|
83
|
+
agePoints = 20;
|
|
84
|
+
else if (raw.contractAgeDays >= 365)
|
|
85
|
+
agePoints = 10;
|
|
86
|
+
else
|
|
87
|
+
agePoints = 5;
|
|
88
|
+
}
|
|
89
|
+
breakdown.age = {
|
|
90
|
+
value: agePoints,
|
|
91
|
+
weight: 20,
|
|
92
|
+
note: raw.contractAgeDays !== undefined ? `listed ${raw.contractAgeDays}d ago` : "no listing date",
|
|
93
|
+
};
|
|
94
|
+
breakdown.bounty = {
|
|
95
|
+
value: raw.hasBugBounty ? 20 : 0,
|
|
96
|
+
weight: 20,
|
|
97
|
+
note: raw.hasBugBounty ? `Immunefi bounty up to $${(raw.bountyMaxUsd ?? 0).toLocaleString()}` : "no Immunefi bounty registered",
|
|
98
|
+
};
|
|
99
|
+
let auditPoints = 0;
|
|
100
|
+
if (raw.auditsReported !== undefined)
|
|
101
|
+
auditPoints = Math.min(20, raw.auditsReported * 2);
|
|
102
|
+
breakdown.audits = {
|
|
103
|
+
value: auditPoints,
|
|
104
|
+
weight: 20,
|
|
105
|
+
note: raw.auditsReported !== undefined ? `${raw.auditsReported} audits linked on DefiLlama` : "no audit links",
|
|
106
|
+
};
|
|
107
|
+
const haveAnyData = data !== null || bounty !== undefined;
|
|
108
|
+
const total = tvlPoints + trendPoints + agePoints + breakdown.bounty.value + auditPoints;
|
|
109
|
+
return {
|
|
110
|
+
protocol,
|
|
111
|
+
score: haveAnyData ? Math.round(total) : undefined,
|
|
112
|
+
breakdown,
|
|
113
|
+
raw,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=risk-score.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"risk-score.js","sourceRoot":"","sources":["../../../src/modules/security/risk-score.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAa7C,4DAA4D;AAC5D,kEAAkE;AAClE,MAAM,iBAAiB,GAA8D;IACnF,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE;IAClD,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,gCAAgC;IAC3F,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE;IAClD,UAAU,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE;CAC/D,CAAC;AAEF,KAAK,UAAU,kBAAkB,CAAC,IAAY;IAC5C,MAAM,GAAG,GAAG,cAAc,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;IAC/C,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,aAAa,EAAE,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BAA+B;KAChI,CAAC;IAEF,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,GAAG,CAAC,cAAc,KAAK,SAAS;QAAE,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;IACzF,SAAS,CAAC,MAAM,GAAG;QACjB,KAAK,EAAE,WAAW;QAClB,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,GAAG,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,cAAc,6BAA6B,CAAC,CAAC,CAAC,gBAAgB;KAC/G,CAAC;IAEF,MAAM,WAAW,GAAG,IAAI,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,CAAC;IAC1D,MAAM,KAAK,GACT,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,GAAG,WAAW,CAAC;IAE7E,OAAO;QACL,QAAQ;QACR,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;QAClD,SAAS;QACT,GAAG;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const checkContractSecurityInput: z.ZodObject<{
|
|
3
|
+
address: z.ZodString;
|
|
4
|
+
chain: z.ZodEnum<[string, ...string[]]>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
address: string;
|
|
7
|
+
chain: string;
|
|
8
|
+
}, {
|
|
9
|
+
address: string;
|
|
10
|
+
chain: string;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const checkPermissionRisksInput: z.ZodObject<{
|
|
13
|
+
address: z.ZodString;
|
|
14
|
+
chain: z.ZodEnum<[string, ...string[]]>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
address: string;
|
|
17
|
+
chain: string;
|
|
18
|
+
}, {
|
|
19
|
+
address: string;
|
|
20
|
+
chain: string;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const getProtocolRiskScoreInput: z.ZodObject<{
|
|
23
|
+
protocol: z.ZodString;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
protocol: string;
|
|
26
|
+
}, {
|
|
27
|
+
protocol: string;
|
|
28
|
+
}>;
|
|
29
|
+
export type CheckContractSecurityArgs = z.infer<typeof checkContractSecurityInput>;
|
|
30
|
+
export type CheckPermissionRisksArgs = z.infer<typeof checkPermissionRisksInput>;
|
|
31
|
+
export type GetProtocolRiskScoreArgs = z.infer<typeof getProtocolRiskScoreInput>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { SUPPORTED_CHAINS } from "../../types/index.js";
|
|
3
|
+
const chainEnum = z.enum(SUPPORTED_CHAINS);
|
|
4
|
+
const addressSchema = z.string().regex(/^0x[a-fA-F0-9]{40}$/);
|
|
5
|
+
export const checkContractSecurityInput = z.object({
|
|
6
|
+
address: addressSchema,
|
|
7
|
+
chain: chainEnum,
|
|
8
|
+
});
|
|
9
|
+
export const checkPermissionRisksInput = z.object({
|
|
10
|
+
address: addressSchema,
|
|
11
|
+
chain: chainEnum,
|
|
12
|
+
});
|
|
13
|
+
export const getProtocolRiskScoreInput = z.object({
|
|
14
|
+
protocol: z.string().min(1),
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../src/modules/security/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,CAAC,gBAAoD,CAAC,CAAC;AAC/E,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;AAE9D,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,OAAO,EAAE,aAAa;IACtB,KAAK,EAAE,SAAS;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,OAAO,EAAE,aAAa;IACtB,KAAK,EAAE,SAAS;CACjB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC5B,CAAC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SecurityReport, SupportedChain } from "../../types/index.js";
|
|
2
|
+
/** Scan an ABI for dangerous function signatures. */
|
|
3
|
+
export declare function scanAbiForDangerousFunctions(abi: unknown[] | undefined): string[];
|
|
4
|
+
export declare function checkContractSecurity(address: `0x${string}`, chain: SupportedChain): Promise<SecurityReport>;
|