chain-insights 0.2.16
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 +165 -0
- package/bin/cli.js +10 -0
- package/bin/install.cjs +252 -0
- package/bin/mcp-proxy.cjs +10 -0
- package/dist/active-BSrxLKwn.mjs +50 -0
- package/dist/active-BSrxLKwn.mjs.map +1 -0
- package/dist/active-Dv7Tu-O4.cjs +68 -0
- package/dist/app-BjjuQM0B.mjs +155 -0
- package/dist/app-BjjuQM0B.mjs.map +1 -0
- package/dist/app-Dq1TdB6p.cjs +161 -0
- package/dist/artifact-server-DoxJ7fCx.cjs +47 -0
- package/dist/artifact-server-Dxz5YbuQ.mjs +48 -0
- package/dist/artifact-server-Dxz5YbuQ.mjs.map +1 -0
- package/dist/assets/bg-pattern.png +0 -0
- package/dist/assets/logo.png +0 -0
- package/dist/call-args-DQA2QcRA.cjs +27 -0
- package/dist/call-args-Lk_wOJxd.mjs +29 -0
- package/dist/call-args-Lk_wOJxd.mjs.map +1 -0
- package/dist/capabilities-CB97WMA5.cjs +83 -0
- package/dist/capabilities-DliMBim-.mjs +84 -0
- package/dist/capabilities-DliMBim-.mjs.map +1 -0
- package/dist/cases-By7INiOa.mjs +6 -0
- package/dist/cases-CDcNU91B.cjs +9 -0
- package/dist/chunk-CZWwpsFl.cjs +43 -0
- package/dist/cli.cjs +752 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +753 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/client-D4Bq0rp9.mjs +111 -0
- package/dist/client-D4Bq0rp9.mjs.map +1 -0
- package/dist/client-D4fZgIaO.cjs +132 -0
- package/dist/config-Bmdl5hdk.cjs +67 -0
- package/dist/config-BwrBYmiC.mjs +44 -0
- package/dist/config-BwrBYmiC.mjs.map +1 -0
- package/dist/data-extractor-BNGj7ECT.cjs +347 -0
- package/dist/data-extractor-DFzsa5CS.mjs +336 -0
- package/dist/data-extractor-DFzsa5CS.mjs.map +1 -0
- package/dist/dossier-BsroDgD3.mjs +76 -0
- package/dist/dossier-BsroDgD3.mjs.map +1 -0
- package/dist/dossier-DtxREpPm.cjs +76 -0
- package/dist/evidence-BGcdKxuV.cjs +200 -0
- package/dist/evidence-BhvFW-y_.mjs +195 -0
- package/dist/evidence-BhvFW-y_.mjs.map +1 -0
- package/dist/format-Ce1RObVl.mjs +22 -0
- package/dist/format-Ce1RObVl.mjs.map +1 -0
- package/dist/format-DOrPvXEr.cjs +20 -0
- package/dist/frontmatter-D8wWCeOa.mjs +26 -0
- package/dist/frontmatter-D8wWCeOa.mjs.map +1 -0
- package/dist/frontmatter-DgAuai7E.cjs +35 -0
- package/dist/graph-normalizer-Cv9yK9Pg.mjs +130 -0
- package/dist/graph-normalizer-Cv9yK9Pg.mjs.map +1 -0
- package/dist/graph-normalizer-DeIj6Ses.cjs +133 -0
- package/dist/graph-reports-C4TBjCkM.mjs +63 -0
- package/dist/graph-reports-C4TBjCkM.mjs.map +1 -0
- package/dist/graph-reports-DU05YCei.cjs +64 -0
- package/dist/html-generator-CAv81IWH.cjs +85 -0
- package/dist/html-generator-V6Bp0uRb.mjs +68 -0
- package/dist/html-generator-V6Bp0uRb.mjs.map +1 -0
- package/dist/index.cjs +31 -0
- package/dist/index.d.cts +187 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +187 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +9 -0
- package/dist/init-BjuFt54X.cjs +232 -0
- package/dist/init-CaOsHTIo.mjs +232 -0
- package/dist/init-CaOsHTIo.mjs.map +1 -0
- package/dist/mcp-proxy.cjs +1257 -0
- package/dist/mcp-proxy.d.cts +12 -0
- package/dist/mcp-proxy.d.cts.map +1 -0
- package/dist/mcp-proxy.d.mts +12 -0
- package/dist/mcp-proxy.d.mts.map +1 -0
- package/dist/mcp-proxy.mjs +1255 -0
- package/dist/mcp-proxy.mjs.map +1 -0
- package/dist/output-root-CFYms3ad.cjs +43 -0
- package/dist/output-root-CmWM7aV2.mjs +33 -0
- package/dist/output-root-CmWM7aV2.mjs.map +1 -0
- package/dist/parser-BUIWW1OH.cjs +182 -0
- package/dist/parser-DO0_SssG.mjs +182 -0
- package/dist/parser-DO0_SssG.mjs.map +1 -0
- package/dist/public-tools-D4UI-Zb0.mjs +2554 -0
- package/dist/public-tools-D4UI-Zb0.mjs.map +1 -0
- package/dist/public-tools-XSpkz2ky.cjs +2556 -0
- package/dist/resolver-C2ZS7oC8.mjs +201 -0
- package/dist/resolver-C2ZS7oC8.mjs.map +1 -0
- package/dist/resolver-zYbu4wDV.cjs +203 -0
- package/dist/rolldown-runtime-wcPFST8Q.mjs +13 -0
- package/dist/runner-1Eq55OYb.cjs +148 -0
- package/dist/runner-BhUHbiHG.mjs +149 -0
- package/dist/runner-BhUHbiHG.mjs.map +1 -0
- package/dist/schema-4XpzDFQM.cjs +55 -0
- package/dist/schema-8d0rVIdZ.mjs +37 -0
- package/dist/schema-8d0rVIdZ.mjs.map +1 -0
- package/dist/schema-cache-9CksD7tX.mjs +34 -0
- package/dist/schema-cache-9CksD7tX.mjs.map +1 -0
- package/dist/schema-cache-CgWRCN2N.cjs +36 -0
- package/dist/selector-CkFcTXzz.cjs +10 -0
- package/dist/selector-xjm6NTHI.mjs +12 -0
- package/dist/selector-xjm6NTHI.mjs.map +1 -0
- package/dist/server-BkM5xrXb.mjs +45 -0
- package/dist/server-BkM5xrXb.mjs.map +1 -0
- package/dist/server-DXowbpfi.cjs +54 -0
- package/dist/session-BpNylyuJ.cjs +115 -0
- package/dist/session-CcTgYxsj.mjs +115 -0
- package/dist/session-CcTgYxsj.mjs.map +1 -0
- package/dist/setup-DOpKPrlx.cjs +81 -0
- package/dist/setup-DyrWHuwQ.mjs +80 -0
- package/dist/setup-DyrWHuwQ.mjs.map +1 -0
- package/dist/store-BiUhQOIf.cjs +230 -0
- package/dist/store-BoWE-Gtl.mjs +225 -0
- package/dist/store-BoWE-Gtl.mjs.map +1 -0
- package/dist/templates/graph.html +1406 -0
- package/dist/tool-visibility-3Z_KvO9Q.mjs +28 -0
- package/dist/tool-visibility-3Z_KvO9Q.mjs.map +1 -0
- package/dist/tool-visibility-CwgY205r.cjs +36 -0
- package/dist/tools-Cp2jAAAb.mjs +100 -0
- package/dist/tools-Cp2jAAAb.mjs.map +1 -0
- package/dist/tools-f_vJUZAF.cjs +139 -0
- package/dist/topup-server-BZuQifvh.cjs +940 -0
- package/dist/topup-server-DUjyFftI.mjs +919 -0
- package/dist/topup-server-DUjyFftI.mjs.map +1 -0
- package/dist/version-1gP19Lhi.mjs +8 -0
- package/dist/version-1gP19Lhi.mjs.map +1 -0
- package/dist/version-BNGtdpmH.cjs +18 -0
- package/dist/viz-BlCJe6Tk.mjs +35 -0
- package/dist/viz-BlCJe6Tk.mjs.map +1 -0
- package/dist/viz-ClezVXrJ.cjs +44 -0
- package/dist/wallet-BMelXBYP.mjs +104 -0
- package/dist/wallet-BMelXBYP.mjs.map +1 -0
- package/dist/wallet-RnvvSpV2.cjs +146 -0
- package/docs/architecture.md +145 -0
- package/docs/contributing.md +68 -0
- package/docs/debugging.md +68 -0
- package/docs/development.md +44 -0
- package/docs/graph-tools.md +251 -0
- package/docs/images/graph-mcp-iframe.png +0 -0
- package/docs/images/graph-visualization.png +0 -0
- package/docs/images/topup-page.png +0 -0
- package/docs/investigation-workspaces.md +151 -0
- package/docs/mcp-proxy.md +180 -0
- package/package.json +59 -0
- package/skills/chain-insights-developer-experience/SKILL.md +101 -0
- package/skills/chain-insights-investigation/SKILL.md +285 -0
- package/skills/chain-insights-investigation/agents/openai.yaml +4 -0
- package/skills/chain-insights-investigation/scripts/run-target-uat.sh +197 -0
- package/skills/chain-insights-trace-funds/SKILL.md +249 -0
- package/skills/ci-case/SKILL.md +43 -0
- package/skills/ci-status/SKILL.md +45 -0
- package/skills/test-chain-insights-graphrag-mcp/SKILL.md +75 -0
- package/skills/test-chain-insights-graphrag-mcp/agents/openai.yaml +4 -0
- package/skills/test-chain-insights-graphrag-mcp/scripts/run-uat.sh +414 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-wcPFST8Q.mjs";
|
|
2
|
+
//#region src/mcp/tool-visibility.ts
|
|
3
|
+
var tool_visibility_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
HIDDEN_REMOTE_TOOL_NAMES: () => HIDDEN_REMOTE_TOOL_NAMES,
|
|
5
|
+
assertPublicMcpToolName: () => assertPublicMcpToolName,
|
|
6
|
+
isHiddenRemoteToolName: () => isHiddenRemoteToolName,
|
|
7
|
+
visibleRemoteTools: () => visibleRemoteTools
|
|
8
|
+
});
|
|
9
|
+
const HIDDEN_REMOTE_TOOL_NAMES = new Set([
|
|
10
|
+
"topup",
|
|
11
|
+
"trace_funds",
|
|
12
|
+
"money_flows_between_exchanges",
|
|
13
|
+
"address_connection_risk"
|
|
14
|
+
]);
|
|
15
|
+
function isHiddenRemoteToolName(name) {
|
|
16
|
+
return HIDDEN_REMOTE_TOOL_NAMES.has(name);
|
|
17
|
+
}
|
|
18
|
+
function visibleRemoteTools(tools) {
|
|
19
|
+
return tools.filter((tool) => !isHiddenRemoteToolName(tool.name));
|
|
20
|
+
}
|
|
21
|
+
function assertPublicMcpToolName(name) {
|
|
22
|
+
if (!isHiddenRemoteToolName(name)) return;
|
|
23
|
+
throw new Error(`MCP tool '${name}' is not exposed by Chain Insights.${name === "trace_funds" ? " Use track_funds instead." : ""}`);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { tool_visibility_exports as n, HIDDEN_REMOTE_TOOL_NAMES as t };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=tool-visibility-3Z_KvO9Q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-visibility-3Z_KvO9Q.mjs","names":[],"sources":["../src/mcp/tool-visibility.ts"],"sourcesContent":["export const HIDDEN_REMOTE_TOOL_NAMES = new Set([\n 'topup',\n 'trace_funds',\n 'money_flows_between_exchanges',\n 'address_connection_risk',\n])\n\nexport function isHiddenRemoteToolName(name: string): boolean {\n return HIDDEN_REMOTE_TOOL_NAMES.has(name)\n}\n\nexport function visibleRemoteTools<T extends { name: string }>(tools: T[]): T[] {\n return tools.filter((tool) => !isHiddenRemoteToolName(tool.name))\n}\n\nexport function assertPublicMcpToolName(name: string): void {\n if (!isHiddenRemoteToolName(name)) return\n const replacement = name === 'trace_funds'\n ? ' Use track_funds instead.'\n : ''\n throw new Error(`MCP tool '${name}' is not exposed by Chain Insights.${replacement}`)\n}\n"],"mappings":";;;;;;;;AAAA,MAAa,2BAA2B,IAAI,IAAI;CAC9C;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,uBAAuB,MAAuB;AAC5D,QAAO,yBAAyB,IAAI,KAAK;;AAG3C,SAAgB,mBAA+C,OAAiB;AAC9E,QAAO,MAAM,QAAQ,SAAS,CAAC,uBAAuB,KAAK,KAAK,CAAC;;AAGnE,SAAgB,wBAAwB,MAAoB;AAC1D,KAAI,CAAC,uBAAuB,KAAK,CAAE;AAInC,OAAM,IAAI,MAAM,aAAa,KAAK,qCAHd,SAAS,gBACzB,8BACA,KACiF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/mcp/tool-visibility.ts
|
|
2
|
+
var tool_visibility_exports = /* @__PURE__ */ require("./chunk-CZWwpsFl.cjs").__exportAll({
|
|
3
|
+
HIDDEN_REMOTE_TOOL_NAMES: () => HIDDEN_REMOTE_TOOL_NAMES,
|
|
4
|
+
assertPublicMcpToolName: () => assertPublicMcpToolName,
|
|
5
|
+
isHiddenRemoteToolName: () => isHiddenRemoteToolName,
|
|
6
|
+
visibleRemoteTools: () => visibleRemoteTools
|
|
7
|
+
});
|
|
8
|
+
const HIDDEN_REMOTE_TOOL_NAMES = new Set([
|
|
9
|
+
"topup",
|
|
10
|
+
"trace_funds",
|
|
11
|
+
"money_flows_between_exchanges",
|
|
12
|
+
"address_connection_risk"
|
|
13
|
+
]);
|
|
14
|
+
function isHiddenRemoteToolName(name) {
|
|
15
|
+
return HIDDEN_REMOTE_TOOL_NAMES.has(name);
|
|
16
|
+
}
|
|
17
|
+
function visibleRemoteTools(tools) {
|
|
18
|
+
return tools.filter((tool) => !isHiddenRemoteToolName(tool.name));
|
|
19
|
+
}
|
|
20
|
+
function assertPublicMcpToolName(name) {
|
|
21
|
+
if (!isHiddenRemoteToolName(name)) return;
|
|
22
|
+
throw new Error(`MCP tool '${name}' is not exposed by Chain Insights.${name === "trace_funds" ? " Use track_funds instead." : ""}`);
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
Object.defineProperty(exports, "HIDDEN_REMOTE_TOOL_NAMES", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function() {
|
|
28
|
+
return HIDDEN_REMOTE_TOOL_NAMES;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "tool_visibility_exports", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function() {
|
|
34
|
+
return tool_visibility_exports;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-wcPFST8Q.mjs";
|
|
2
|
+
import { i as normalizeWalletPrivateKey, t as decryptKey } from "./wallet-BMelXBYP.mjs";
|
|
3
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
4
|
+
import { createPublicClient, formatEther, formatUnits, http } from "viem";
|
|
5
|
+
import { base } from "viem/chains";
|
|
6
|
+
//#region src/wallet/tools.ts
|
|
7
|
+
var tools_exports = /* @__PURE__ */ __exportAll({
|
|
8
|
+
BASE_CHAIN_ID: () => BASE_CHAIN_ID,
|
|
9
|
+
DEFAULT_BASE_RPC_URL: () => DEFAULT_BASE_RPC_URL,
|
|
10
|
+
PUBLIC_BASE_RPC_URLS: () => PUBLIC_BASE_RPC_URLS,
|
|
11
|
+
USDC_ADDRESS: () => USDC_ADDRESS,
|
|
12
|
+
buildTopupInfo: () => buildTopupInfo,
|
|
13
|
+
formatWalletBalance: () => formatWalletBalance,
|
|
14
|
+
getBalanceEth: () => getBalanceEth,
|
|
15
|
+
getBalanceUsdc: () => getBalanceUsdc,
|
|
16
|
+
getWalletAccount: () => getWalletAccount,
|
|
17
|
+
getWalletBalanceText: () => getWalletBalanceText
|
|
18
|
+
});
|
|
19
|
+
const BASE_CHAIN_ID = 8453;
|
|
20
|
+
const USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
21
|
+
const DEFAULT_BASE_RPC_URL = "https://mainnet.base.org";
|
|
22
|
+
const PUBLIC_BASE_RPC_URLS = [
|
|
23
|
+
DEFAULT_BASE_RPC_URL,
|
|
24
|
+
"https://base-rpc.publicnode.com",
|
|
25
|
+
"https://base.drpc.org",
|
|
26
|
+
"https://1rpc.io/base"
|
|
27
|
+
];
|
|
28
|
+
const USDC_ABI = [{
|
|
29
|
+
type: "function",
|
|
30
|
+
name: "balanceOf",
|
|
31
|
+
stateMutability: "view",
|
|
32
|
+
inputs: [{
|
|
33
|
+
name: "account",
|
|
34
|
+
type: "address"
|
|
35
|
+
}],
|
|
36
|
+
outputs: [{
|
|
37
|
+
name: "",
|
|
38
|
+
type: "uint256"
|
|
39
|
+
}]
|
|
40
|
+
}];
|
|
41
|
+
async function getWalletAccount() {
|
|
42
|
+
const privateKey = normalizeWalletPrivateKey(await decryptKey());
|
|
43
|
+
return {
|
|
44
|
+
address: privateKeyToAccount(privateKey).address,
|
|
45
|
+
privateKey
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function getBalanceUsdc(address, rpcUrl = process.env["BASE_RPC_URL"]) {
|
|
49
|
+
const rpcUrls = [...rpcUrl ? [rpcUrl] : [], ...PUBLIC_BASE_RPC_URLS.filter((fallbackUrl) => fallbackUrl !== rpcUrl)];
|
|
50
|
+
for (const url of rpcUrls) try {
|
|
51
|
+
return formatUnits(await createPublicClient({
|
|
52
|
+
chain: base,
|
|
53
|
+
transport: http(url)
|
|
54
|
+
}).readContract({
|
|
55
|
+
address: USDC_ADDRESS,
|
|
56
|
+
abi: USDC_ABI,
|
|
57
|
+
functionName: "balanceOf",
|
|
58
|
+
args: [address]
|
|
59
|
+
}), 6);
|
|
60
|
+
} catch {}
|
|
61
|
+
return "unknown";
|
|
62
|
+
}
|
|
63
|
+
async function getBalanceEth(address, rpcUrl = process.env["BASE_RPC_URL"]) {
|
|
64
|
+
const rpcUrls = [...rpcUrl ? [rpcUrl] : [], ...PUBLIC_BASE_RPC_URLS.filter((fallbackUrl) => fallbackUrl !== rpcUrl)];
|
|
65
|
+
for (const url of rpcUrls) try {
|
|
66
|
+
return formatEther(await createPublicClient({
|
|
67
|
+
chain: base,
|
|
68
|
+
transport: http(url)
|
|
69
|
+
}).getBalance({ address }));
|
|
70
|
+
} catch {}
|
|
71
|
+
return "unknown";
|
|
72
|
+
}
|
|
73
|
+
function formatWalletBalance(address, balanceUsdc, balanceEth) {
|
|
74
|
+
return [
|
|
75
|
+
`Balance: ${balanceUsdc} USDC`,
|
|
76
|
+
balanceEth === void 0 ? void 0 : `Gas: ${balanceEth} ETH on Base`,
|
|
77
|
+
"Network: Base",
|
|
78
|
+
"Base ETH is required for one-time USDC Permit2 approval gas.",
|
|
79
|
+
`Address: ${address}`
|
|
80
|
+
].filter(Boolean).join("\n");
|
|
81
|
+
}
|
|
82
|
+
async function getWalletBalanceText(account) {
|
|
83
|
+
const wallet = account ?? await getWalletAccount();
|
|
84
|
+
const [balanceUsdc, balanceEth] = await Promise.all([getBalanceUsdc(wallet.address), getBalanceEth(wallet.address)]);
|
|
85
|
+
return formatWalletBalance(wallet.address, balanceUsdc, balanceEth);
|
|
86
|
+
}
|
|
87
|
+
function buildTopupInfo(address, topupUrl) {
|
|
88
|
+
return {
|
|
89
|
+
wallet_address: address,
|
|
90
|
+
network: "Base",
|
|
91
|
+
chain_id: BASE_CHAIN_ID,
|
|
92
|
+
token: "USDC",
|
|
93
|
+
token_contract: USDC_ADDRESS,
|
|
94
|
+
...topupUrl ? { topup_url: topupUrl } : {}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { getWalletAccount as a, getBalanceUsdc as i, formatWalletBalance as n, getWalletBalanceText as o, getBalanceEth as r, tools_exports as s, buildTopupInfo as t };
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=tools-Cp2jAAAb.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools-Cp2jAAAb.mjs","names":[],"sources":["../src/wallet/tools.ts"],"sourcesContent":["import { createPublicClient, formatEther, formatUnits, http, type Address, type Hex } from 'viem'\nimport { base } from 'viem/chains'\nimport { privateKeyToAccount } from 'viem/accounts'\nimport { decryptKey, normalizeWalletPrivateKey } from './index.js'\n\nexport const BASE_CHAIN_ID = 8453\nexport const USDC_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' as const\nexport const DEFAULT_BASE_RPC_URL = 'https://mainnet.base.org'\nexport const PUBLIC_BASE_RPC_URLS = [\n DEFAULT_BASE_RPC_URL,\n 'https://base-rpc.publicnode.com',\n 'https://base.drpc.org',\n 'https://1rpc.io/base',\n] as const\n\nconst USDC_ABI = [\n {\n type: 'function',\n name: 'balanceOf',\n stateMutability: 'view',\n inputs: [{ name: 'account', type: 'address' }],\n outputs: [{ name: '', type: 'uint256' }],\n },\n] as const\n\nexport interface PaymentWalletAccount {\n address: Address\n privateKey: Hex\n}\n\nexport interface TopupInfo {\n wallet_address: string\n network: 'Base'\n chain_id: typeof BASE_CHAIN_ID\n token: 'USDC'\n token_contract: typeof USDC_ADDRESS\n topup_url?: string\n}\n\nexport async function getWalletAccount(): Promise<PaymentWalletAccount> {\n const privateKey = normalizeWalletPrivateKey(await decryptKey()) as Hex\n const account = privateKeyToAccount(privateKey)\n return { address: account.address, privateKey }\n}\n\nexport async function getBalanceUsdc(\n address: Address | string,\n rpcUrl = process.env['BASE_RPC_URL'],\n): Promise<string> {\n const rpcUrls = [\n ...(rpcUrl ? [rpcUrl] : []),\n ...PUBLIC_BASE_RPC_URLS.filter((fallbackUrl) => fallbackUrl !== rpcUrl),\n ]\n\n for (const url of rpcUrls) {\n try {\n const client = createPublicClient({\n chain: base,\n transport: http(url),\n })\n const balance = await client.readContract({\n address: USDC_ADDRESS,\n abi: USDC_ABI,\n functionName: 'balanceOf',\n args: [address as Address],\n })\n return formatUnits(balance, 6)\n } catch {\n // Try the next public Base RPC endpoint.\n }\n }\n\n return 'unknown'\n}\n\nexport async function getBalanceEth(\n address: Address | string,\n rpcUrl = process.env['BASE_RPC_URL'],\n): Promise<string> {\n const rpcUrls = [\n ...(rpcUrl ? [rpcUrl] : []),\n ...PUBLIC_BASE_RPC_URLS.filter((fallbackUrl) => fallbackUrl !== rpcUrl),\n ]\n\n for (const url of rpcUrls) {\n try {\n const client = createPublicClient({\n chain: base,\n transport: http(url),\n })\n const balance = await client.getBalance({ address: address as Address })\n return formatEther(balance)\n } catch {\n // Try the next public Base RPC endpoint.\n }\n }\n\n return 'unknown'\n}\n\nexport function formatWalletBalance(address: string, balanceUsdc: string, balanceEth?: string): string {\n return [\n `Balance: ${balanceUsdc} USDC`,\n balanceEth === undefined ? undefined : `Gas: ${balanceEth} ETH on Base`,\n 'Network: Base',\n 'Base ETH is required for one-time USDC Permit2 approval gas.',\n `Address: ${address}`,\n ].filter(Boolean).join('\\n')\n}\n\nexport async function getWalletBalanceText(account?: PaymentWalletAccount): Promise<string> {\n const wallet = account ?? await getWalletAccount()\n const [balanceUsdc, balanceEth] = await Promise.all([\n getBalanceUsdc(wallet.address),\n getBalanceEth(wallet.address),\n ])\n return formatWalletBalance(wallet.address, balanceUsdc, balanceEth)\n}\n\nexport function buildTopupInfo(address: string, topupUrl?: string): TopupInfo {\n return {\n wallet_address: address,\n network: 'Base',\n chain_id: BASE_CHAIN_ID,\n token: 'USDC',\n token_contract: USDC_ADDRESS,\n ...(topupUrl ? { topup_url: topupUrl } : {}),\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAKA,MAAa,gBAAgB;AAC7B,MAAa,eAAe;AAC5B,MAAa,uBAAuB;AACpC,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACD;AAED,MAAM,WAAW,CACf;CACE,MAAM;CACN,MAAM;CACN,iBAAiB;CACjB,QAAQ,CAAC;EAAE,MAAM;EAAW,MAAM;EAAW,CAAC;CAC9C,SAAS,CAAC;EAAE,MAAM;EAAI,MAAM;EAAW,CAAC;CACzC,CACF;AAgBD,eAAsB,mBAAkD;CACtE,MAAM,aAAa,0BAA0B,MAAM,YAAY,CAAC;AAEhE,QAAO;EAAE,SADO,oBAAoB,WACX,CAAC;EAAS;EAAY;;AAGjD,eAAsB,eACpB,SACA,SAAS,QAAQ,IAAI,iBACJ;CACjB,MAAM,UAAU,CACd,GAAI,SAAS,CAAC,OAAO,GAAG,EAAE,EAC1B,GAAG,qBAAqB,QAAQ,gBAAgB,gBAAgB,OAAO,CACxE;AAED,MAAK,MAAM,OAAO,QAChB,KAAI;AAWF,SAAO,YAAY,MAVJ,mBAAmB;GAChC,OAAO;GACP,WAAW,KAAK,IAAI;GACrB,CAC2B,CAAC,aAAa;GACxC,SAAS;GACT,KAAK;GACL,cAAc;GACd,MAAM,CAAC,QAAmB;GAC3B,CAAC,EAC0B,EAAE;SACxB;AAKV,QAAO;;AAGT,eAAsB,cACpB,SACA,SAAS,QAAQ,IAAI,iBACJ;CACjB,MAAM,UAAU,CACd,GAAI,SAAS,CAAC,OAAO,GAAG,EAAE,EAC1B,GAAG,qBAAqB,QAAQ,gBAAgB,gBAAgB,OAAO,CACxE;AAED,MAAK,MAAM,OAAO,QAChB,KAAI;AAMF,SAAO,YAAY,MALJ,mBAAmB;GAChC,OAAO;GACP,WAAW,KAAK,IAAI;GACrB,CAC2B,CAAC,WAAW,EAAW,SAAoB,CAAC,CAC7C;SACrB;AAKV,QAAO;;AAGT,SAAgB,oBAAoB,SAAiB,aAAqB,YAA6B;AACrG,QAAO;EACL,YAAY,YAAY;EACxB,eAAe,KAAA,IAAY,KAAA,IAAY,QAAQ,WAAW;EAC1D;EACA;EACA,YAAY;EACb,CAAC,OAAO,QAAQ,CAAC,KAAK,KAAK;;AAG9B,eAAsB,qBAAqB,SAAiD;CAC1F,MAAM,SAAS,WAAW,MAAM,kBAAkB;CAClD,MAAM,CAAC,aAAa,cAAc,MAAM,QAAQ,IAAI,CAClD,eAAe,OAAO,QAAQ,EAC9B,cAAc,OAAO,QAAQ,CAC9B,CAAC;AACF,QAAO,oBAAoB,OAAO,SAAS,aAAa,WAAW;;AAGrE,SAAgB,eAAe,SAAiB,UAA8B;AAC5E,QAAO;EACL,gBAAgB;EAChB,SAAS;EACT,UAAU;EACV,OAAO;EACP,gBAAgB;EAChB,GAAI,WAAW,EAAE,WAAW,UAAU,GAAG,EAAE;EAC5C"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-CZWwpsFl.cjs");
|
|
2
|
+
const require_wallet = require("./wallet-RnvvSpV2.cjs");
|
|
3
|
+
let viem_accounts = require("viem/accounts");
|
|
4
|
+
let viem = require("viem");
|
|
5
|
+
let viem_chains = require("viem/chains");
|
|
6
|
+
//#region src/wallet/tools.ts
|
|
7
|
+
var tools_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
8
|
+
BASE_CHAIN_ID: () => BASE_CHAIN_ID,
|
|
9
|
+
DEFAULT_BASE_RPC_URL: () => DEFAULT_BASE_RPC_URL,
|
|
10
|
+
PUBLIC_BASE_RPC_URLS: () => PUBLIC_BASE_RPC_URLS,
|
|
11
|
+
USDC_ADDRESS: () => USDC_ADDRESS,
|
|
12
|
+
buildTopupInfo: () => buildTopupInfo,
|
|
13
|
+
formatWalletBalance: () => formatWalletBalance,
|
|
14
|
+
getBalanceEth: () => getBalanceEth,
|
|
15
|
+
getBalanceUsdc: () => getBalanceUsdc,
|
|
16
|
+
getWalletAccount: () => getWalletAccount,
|
|
17
|
+
getWalletBalanceText: () => getWalletBalanceText
|
|
18
|
+
});
|
|
19
|
+
const BASE_CHAIN_ID = 8453;
|
|
20
|
+
const USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
21
|
+
const DEFAULT_BASE_RPC_URL = "https://mainnet.base.org";
|
|
22
|
+
const PUBLIC_BASE_RPC_URLS = [
|
|
23
|
+
DEFAULT_BASE_RPC_URL,
|
|
24
|
+
"https://base-rpc.publicnode.com",
|
|
25
|
+
"https://base.drpc.org",
|
|
26
|
+
"https://1rpc.io/base"
|
|
27
|
+
];
|
|
28
|
+
const USDC_ABI = [{
|
|
29
|
+
type: "function",
|
|
30
|
+
name: "balanceOf",
|
|
31
|
+
stateMutability: "view",
|
|
32
|
+
inputs: [{
|
|
33
|
+
name: "account",
|
|
34
|
+
type: "address"
|
|
35
|
+
}],
|
|
36
|
+
outputs: [{
|
|
37
|
+
name: "",
|
|
38
|
+
type: "uint256"
|
|
39
|
+
}]
|
|
40
|
+
}];
|
|
41
|
+
async function getWalletAccount() {
|
|
42
|
+
const privateKey = require_wallet.normalizeWalletPrivateKey(await require_wallet.decryptKey());
|
|
43
|
+
return {
|
|
44
|
+
address: (0, viem_accounts.privateKeyToAccount)(privateKey).address,
|
|
45
|
+
privateKey
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
async function getBalanceUsdc(address, rpcUrl = process.env["BASE_RPC_URL"]) {
|
|
49
|
+
const rpcUrls = [...rpcUrl ? [rpcUrl] : [], ...PUBLIC_BASE_RPC_URLS.filter((fallbackUrl) => fallbackUrl !== rpcUrl)];
|
|
50
|
+
for (const url of rpcUrls) try {
|
|
51
|
+
return (0, viem.formatUnits)(await (0, viem.createPublicClient)({
|
|
52
|
+
chain: viem_chains.base,
|
|
53
|
+
transport: (0, viem.http)(url)
|
|
54
|
+
}).readContract({
|
|
55
|
+
address: USDC_ADDRESS,
|
|
56
|
+
abi: USDC_ABI,
|
|
57
|
+
functionName: "balanceOf",
|
|
58
|
+
args: [address]
|
|
59
|
+
}), 6);
|
|
60
|
+
} catch {}
|
|
61
|
+
return "unknown";
|
|
62
|
+
}
|
|
63
|
+
async function getBalanceEth(address, rpcUrl = process.env["BASE_RPC_URL"]) {
|
|
64
|
+
const rpcUrls = [...rpcUrl ? [rpcUrl] : [], ...PUBLIC_BASE_RPC_URLS.filter((fallbackUrl) => fallbackUrl !== rpcUrl)];
|
|
65
|
+
for (const url of rpcUrls) try {
|
|
66
|
+
return (0, viem.formatEther)(await (0, viem.createPublicClient)({
|
|
67
|
+
chain: viem_chains.base,
|
|
68
|
+
transport: (0, viem.http)(url)
|
|
69
|
+
}).getBalance({ address }));
|
|
70
|
+
} catch {}
|
|
71
|
+
return "unknown";
|
|
72
|
+
}
|
|
73
|
+
function formatWalletBalance(address, balanceUsdc, balanceEth) {
|
|
74
|
+
return [
|
|
75
|
+
`Balance: ${balanceUsdc} USDC`,
|
|
76
|
+
balanceEth === void 0 ? void 0 : `Gas: ${balanceEth} ETH on Base`,
|
|
77
|
+
"Network: Base",
|
|
78
|
+
"Base ETH is required for one-time USDC Permit2 approval gas.",
|
|
79
|
+
`Address: ${address}`
|
|
80
|
+
].filter(Boolean).join("\n");
|
|
81
|
+
}
|
|
82
|
+
async function getWalletBalanceText(account) {
|
|
83
|
+
const wallet = account ?? await getWalletAccount();
|
|
84
|
+
const [balanceUsdc, balanceEth] = await Promise.all([getBalanceUsdc(wallet.address), getBalanceEth(wallet.address)]);
|
|
85
|
+
return formatWalletBalance(wallet.address, balanceUsdc, balanceEth);
|
|
86
|
+
}
|
|
87
|
+
function buildTopupInfo(address, topupUrl) {
|
|
88
|
+
return {
|
|
89
|
+
wallet_address: address,
|
|
90
|
+
network: "Base",
|
|
91
|
+
chain_id: BASE_CHAIN_ID,
|
|
92
|
+
token: "USDC",
|
|
93
|
+
token_contract: USDC_ADDRESS,
|
|
94
|
+
...topupUrl ? { topup_url: topupUrl } : {}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
Object.defineProperty(exports, "buildTopupInfo", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return buildTopupInfo;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "formatWalletBalance", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function() {
|
|
107
|
+
return formatWalletBalance;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(exports, "getBalanceEth", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function() {
|
|
113
|
+
return getBalanceEth;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
Object.defineProperty(exports, "getBalanceUsdc", {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function() {
|
|
119
|
+
return getBalanceUsdc;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
Object.defineProperty(exports, "getWalletAccount", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function() {
|
|
125
|
+
return getWalletAccount;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, "getWalletBalanceText", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function() {
|
|
131
|
+
return getWalletBalanceText;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(exports, "tools_exports", {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function() {
|
|
137
|
+
return tools_exports;
|
|
138
|
+
}
|
|
139
|
+
});
|