@dreamcash-org/mcp 0.1.0 → 0.1.1

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.
@@ -21082,6 +21082,514 @@ var StdioServerTransport = class {
21082
21082
  }
21083
21083
  };
21084
21084
 
21085
+ // ../constants/src/appStores.ts
21086
+ var DREAMCASH_APP_STORE_URL = "https://apps.apple.com/app/id6748916424";
21087
+ var DREAMCASH_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=xyz.dreamcash.app";
21088
+ // ../constants/src/chains.ts
21089
+ var ARBITRUM_ONE = {
21090
+ id: 42161,
21091
+ name: "Arbitrum One",
21092
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
21093
+ blockTimeMs: 250,
21094
+ rpcUrls: [
21095
+ "https://arb1.arbitrum.io/rpc",
21096
+ "https://arb-mainnet.g.alchemy.com/v2/51PmJ8CQYIfaS57viRzGZ",
21097
+ "https://arbitrum-one.publicnode.com",
21098
+ "https://1rpc.io/arb"
21099
+ ],
21100
+ explorer: {
21101
+ name: "Arbiscan",
21102
+ url: "https://arbiscan.io",
21103
+ apiUrl: "https://api.arbiscan.io/api"
21104
+ },
21105
+ multicall3: {
21106
+ address: "0xca11bde05977b3631167028862be2a173976ca11",
21107
+ blockCreated: 7654707
21108
+ }
21109
+ };
21110
+ var HYPERLIQUID_SIGNING_CHAIN_ID = ARBITRUM_ONE.id;
21111
+ // ../constants/src/evmChains.ts
21112
+ var MULTICALL3 = "0xcA11bde05977b3631167028862bE2a173976CA11";
21113
+ var ETHER = { name: "Ether", symbol: "ETH", decimals: 18 };
21114
+ var RELAY_SELL_CONTRACTS = {
21115
+ depository: "0x4cd00e387622c35bddb9b4c962c136462338bc31",
21116
+ approvalProxy: "0x5567954cd026cebfe486062cb75848e0f1c12e58"
21117
+ };
21118
+ var ETHER_COIN = {
21119
+ coingeckoCoinId: "ethereum",
21120
+ imageUrl: "https://coin-images.coingecko.com/coins/images/279/large/ethereum.png?1696501628"
21121
+ };
21122
+ var RELAY_NATIVE_SELL_ROUTER = "0x0729e2a4716d9f7dd17858d5d504426d228697f7";
21123
+ var CHAINS = {
21124
+ 1: {
21125
+ vm: "evm",
21126
+ name: "Ethereum",
21127
+ nativeCurrency: ETHER,
21128
+ rpcUrl: "https://ethereum-rpc.publicnode.com",
21129
+ explorer: { name: "Etherscan", url: "https://etherscan.io" },
21130
+ multicall3: MULTICALL3,
21131
+ alchemyNetwork: "eth-mainnet",
21132
+ coingeckoNetwork: "eth",
21133
+ dexscreenerChain: "ethereum",
21134
+ blockTimeMs: 12000,
21135
+ v4PoolManager: "0x000000000004444c5dc75cb358380d2e3de08a90",
21136
+ securitiesSource: { kind: "coingecko", platform: "ethereum" },
21137
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21138
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21139
+ nativeCoin: ETHER_COIN
21140
+ },
21141
+ 10: {
21142
+ vm: "evm",
21143
+ name: "Optimism",
21144
+ nativeCurrency: ETHER,
21145
+ rpcUrl: "https://mainnet.optimism.io",
21146
+ explorer: {
21147
+ name: "Optimistic Etherscan",
21148
+ url: "https://optimistic.etherscan.io"
21149
+ },
21150
+ multicall3: MULTICALL3,
21151
+ alchemyNetwork: "opt-mainnet",
21152
+ coingeckoNetwork: "optimism",
21153
+ dexscreenerChain: "optimism",
21154
+ blockTimeMs: 2000,
21155
+ v4PoolManager: "0x9a13f98cb987694c9f086b1f5eb990eea8264ec3",
21156
+ securitiesSource: { kind: "coingecko", platform: "optimistic-ethereum" },
21157
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21158
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21159
+ nativeCoin: ETHER_COIN
21160
+ },
21161
+ 56: {
21162
+ vm: "evm",
21163
+ name: "BNB Chain",
21164
+ nativeCurrency: { name: "BNB", symbol: "BNB", decimals: 18 },
21165
+ rpcUrl: "https://bsc-dataseed.bnbchain.org",
21166
+ explorer: { name: "BscScan", url: "https://bscscan.com" },
21167
+ multicall3: MULTICALL3,
21168
+ alchemyNetwork: "bnb-mainnet",
21169
+ coingeckoNetwork: "bsc",
21170
+ dexscreenerChain: "bsc",
21171
+ blockTimeMs: 450,
21172
+ v4PoolManager: "0x28e2ea090877bf75740558f6bfb36a5ffee9e9df",
21173
+ securitiesSource: { kind: "coingecko", platform: "binance-smart-chain" },
21174
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21175
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21176
+ nativeCoin: {
21177
+ coingeckoCoinId: "binancecoin",
21178
+ imageUrl: "https://coin-images.coingecko.com/coins/images/825/large/bnb-icon2_2x.png?1696501970"
21179
+ }
21180
+ },
21181
+ 130: {
21182
+ vm: "evm",
21183
+ name: "Unichain",
21184
+ nativeCurrency: ETHER,
21185
+ rpcUrl: "https://mainnet.unichain.org",
21186
+ explorer: { name: "Uniscan", url: "https://uniscan.xyz" },
21187
+ multicall3: MULTICALL3,
21188
+ alchemyNetwork: "unichain-mainnet",
21189
+ coingeckoNetwork: "unichain",
21190
+ dexscreenerChain: "unichain",
21191
+ blockTimeMs: 1000,
21192
+ v4PoolManager: "0x1f98400000000000000000000000000000000004",
21193
+ securitiesSource: { kind: "coingecko", platform: "unichain" },
21194
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21195
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21196
+ nativeCoin: ETHER_COIN
21197
+ },
21198
+ 480: {
21199
+ vm: "evm",
21200
+ name: "World Chain",
21201
+ nativeCurrency: ETHER,
21202
+ rpcUrl: "https://worldchain-mainnet.g.alchemy.com/public",
21203
+ explorer: { name: "Worldscan", url: "https://worldscan.org" },
21204
+ multicall3: MULTICALL3,
21205
+ alchemyNetwork: "worldchain-mainnet",
21206
+ coingeckoNetwork: "world-chain",
21207
+ dexscreenerChain: "worldchain",
21208
+ blockTimeMs: 2000,
21209
+ v4PoolManager: "0xb1860d529182ac3bc1f51fa2abd56662b7d13f33",
21210
+ securitiesSource: { kind: "coingecko", platform: "world-chain" },
21211
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21212
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21213
+ nativeCoin: ETHER_COIN
21214
+ },
21215
+ 4663: {
21216
+ vm: "evm",
21217
+ name: "Robinhood Chain",
21218
+ nativeCurrency: ETHER,
21219
+ rpcUrl: "https://rpc.mainnet.chain.robinhood.com",
21220
+ explorer: {
21221
+ name: "Blockscout",
21222
+ url: "https://robinhoodchain.blockscout.com"
21223
+ },
21224
+ multicall3: MULTICALL3,
21225
+ alchemyNetwork: "robinhood-mainnet",
21226
+ coingeckoNetwork: "robinhood",
21227
+ dexscreenerChain: "robinhood",
21228
+ blockTimeMs: 100,
21229
+ v4PoolManager: "0x8366a39cc670b4001a1121b8f6a443a643e40951",
21230
+ securitiesSource: {
21231
+ kind: "registry",
21232
+ url: "https://api.robinhood.com/rhj/assets/"
21233
+ },
21234
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21235
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21236
+ nativeCoin: ETHER_COIN
21237
+ },
21238
+ 8453: {
21239
+ vm: "evm",
21240
+ name: "Base",
21241
+ nativeCurrency: ETHER,
21242
+ rpcUrl: "https://mainnet.base.org",
21243
+ explorer: { name: "Basescan", url: "https://basescan.org" },
21244
+ multicall3: MULTICALL3,
21245
+ alchemyNetwork: "base-mainnet",
21246
+ coingeckoNetwork: "base",
21247
+ dexscreenerChain: "base",
21248
+ blockTimeMs: 2000,
21249
+ v4PoolManager: "0x498581ff718922c3f8e6a244956af099b2652b2b",
21250
+ securitiesSource: { kind: "coingecko", platform: "base" },
21251
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21252
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21253
+ nativeCoin: ETHER_COIN
21254
+ },
21255
+ 42161: {
21256
+ vm: "evm",
21257
+ name: "Arbitrum",
21258
+ nativeCurrency: ETHER,
21259
+ rpcUrl: "https://arb1.arbitrum.io/rpc",
21260
+ explorer: { name: "Arbiscan", url: "https://arbiscan.io" },
21261
+ multicall3: MULTICALL3,
21262
+ alchemyNetwork: "arb-mainnet",
21263
+ coingeckoNetwork: "arbitrum",
21264
+ dexscreenerChain: "arbitrum",
21265
+ blockTimeMs: 250,
21266
+ v4PoolManager: "0x360e68faccca8ca495c1b759fd9eee466db9fb32",
21267
+ securitiesSource: { kind: "coingecko", platform: "arbitrum-one" },
21268
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21269
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21270
+ nativeCoin: ETHER_COIN
21271
+ },
21272
+ 99901: {
21273
+ vm: "evm",
21274
+ name: "Elysium",
21275
+ nativeCurrency: { name: "HYPE", symbol: "HYPE", decimals: 18 },
21276
+ rpcUrl: "https://rpc.elysium.kinetiq.xyz",
21277
+ explorer: {
21278
+ name: "Elysium Explorer",
21279
+ url: "https://elysium.kinetiq.xyz/explorer"
21280
+ },
21281
+ multicall3: MULTICALL3,
21282
+ alchemyNetwork: "elysium-mainnet",
21283
+ coingeckoNetwork: "elysium",
21284
+ dexscreenerChain: "elysium",
21285
+ blockTimeMs: 100,
21286
+ v4PoolManager: "0xe2e105d3f7209a9da11f83ccf3e7398a753823f1",
21287
+ securitiesSource: { kind: "coingecko", platform: "elysium-kinetiq" },
21288
+ relaySellContracts: RELAY_SELL_CONTRACTS,
21289
+ relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
21290
+ nativeCoin: {
21291
+ coingeckoCoinId: "hyperliquid",
21292
+ imageUrl: "https://coin-images.coingecko.com/coins/images/50882/large/hyperliquid.jpg?1729431300"
21293
+ }
21294
+ },
21295
+ 792703809: {
21296
+ vm: "svm",
21297
+ name: "Solana",
21298
+ nativeCurrency: { name: "Solana", symbol: "SOL", decimals: 9 },
21299
+ rpcUrl: "https://api.mainnet-beta.solana.com",
21300
+ explorer: { name: "Solscan", url: "https://solscan.io" },
21301
+ alchemyNetwork: "solana-mainnet",
21302
+ coingeckoNetwork: "solana",
21303
+ dexscreenerChain: "solana",
21304
+ blockTimeMs: 400,
21305
+ securitiesSource: { kind: "coingecko", platform: "solana" },
21306
+ relaySellPrograms: {
21307
+ depositoryProgram: "DPArtTLbEqa6EuXHfL5UFLBZhFjiEXWRudhvXDrjwXUr",
21308
+ depository: "99vQwtBwYtrqqD9YSXbdum3KBdxPAVxYTaQ3cfnJSrN2",
21309
+ jupiter: "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
21310
+ }
21311
+ }
21312
+ };
21313
+ var CHAIN_IDS = Object.keys(CHAINS).map(Number);
21314
+ var isChainId = (chainId) => (chainId in CHAINS);
21315
+ var EVM_CHAINS = Object.fromEntries(Object.entries(CHAINS).filter(([, chain]) => chain.vm === "evm"));
21316
+ var isEvmChainId = (chainId) => isChainId(chainId) && CHAINS[chainId].vm === "evm";
21317
+ var EVM_CHAIN_IDS = CHAIN_IDS.filter(isEvmChainId);
21318
+ // ../constants/src/evmContracts.ts
21319
+ var CALIBUR_ADDRESS = "0x000000009B1D0aF20D8C6d0A44e162d11F9b8f00";
21320
+ var CALIBUR_EXECUTE_ABI = [
21321
+ {
21322
+ name: "execute",
21323
+ type: "function",
21324
+ stateMutability: "payable",
21325
+ inputs: [
21326
+ {
21327
+ name: "signedBatchedCall",
21328
+ type: "tuple",
21329
+ components: [
21330
+ {
21331
+ name: "batchedCall",
21332
+ type: "tuple",
21333
+ components: [
21334
+ {
21335
+ name: "calls",
21336
+ type: "tuple[]",
21337
+ components: [
21338
+ { name: "to", type: "address" },
21339
+ { name: "value", type: "uint256" },
21340
+ { name: "data", type: "bytes" }
21341
+ ]
21342
+ },
21343
+ { name: "revertOnFailure", type: "bool" }
21344
+ ]
21345
+ },
21346
+ { name: "nonce", type: "uint256" },
21347
+ { name: "keyHash", type: "bytes32" },
21348
+ { name: "executor", type: "address" },
21349
+ { name: "deadline", type: "uint256" }
21350
+ ]
21351
+ },
21352
+ { name: "wrappedSignature", type: "bytes" }
21353
+ ],
21354
+ outputs: []
21355
+ }
21356
+ ];
21357
+ var CALIBUR_ABI = [
21358
+ ...CALIBUR_EXECUTE_ABI,
21359
+ {
21360
+ name: "getSeq",
21361
+ type: "function",
21362
+ stateMutability: "view",
21363
+ inputs: [{ name: "key", type: "uint256" }],
21364
+ outputs: [{ name: "", type: "uint256" }]
21365
+ }
21366
+ ];
21367
+ var CALIBUR_EIP712_DOMAIN = {
21368
+ name: "Calibur",
21369
+ version: "1.0.0",
21370
+ salt: `0x${CALIBUR_ADDRESS.slice(2).padStart(64, "0")}`
21371
+ };
21372
+ // ../constants/src/hyperliquid/aiAgent.ts
21373
+ var AI_CLIENT_NAME_MAX_LENGTH = 60;
21374
+ var TRADE_REQUEST_TTL_MS = 15 * 60 * 1000;
21375
+ var AI_AGENT_SIGNATURE_HEADER = "x-dreamcash-agent-signature";
21376
+ var AI_AGENT_TIMESTAMP_HEADER = "x-dreamcash-agent-timestamp";
21377
+ var aiAgentRequestMessage = ({
21378
+ method,
21379
+ path,
21380
+ timestampMs,
21381
+ bodySha256
21382
+ }) => `Dreamcash agent ${method.toUpperCase()} ${path} ${timestampMs} ${bodySha256}`;
21383
+ var DREAMCASH_MCP_VERSION_HEADER = "x-dreamcash-mcp-version";
21384
+ // ../constants/src/hyperliquid/assetIndex.ts
21385
+ var SPOT_ASSET_INDEX_OFFSET = 1e4;
21386
+ var HIP3_ASSET_INDEX_OFFSET = 1e5;
21387
+ var DEX_INDEX_MULTIPLIER = 1e4;
21388
+ var HIP4_ASSET_INDEX_OFFSET = 1e8;
21389
+ var hip3DexIdOfAssetIndex = (assetIndex) => Math.floor((assetIndex - HIP3_ASSET_INDEX_OFFSET) / DEX_INDEX_MULTIPLIER);
21390
+ var isHip3Coin = (coin) => coin.includes(":");
21391
+ var getDexFromCoin = (coin) => isHip3Coin(coin) ? coin.split(":")[0] : undefined;
21392
+ // ../constants/src/hyperliquid/dexes.ts
21393
+ var HIP3_DEXES = [
21394
+ { id: 1, dex: "xyz", collateral: "USDC", listed: true },
21395
+ { id: 2, dex: "flx", collateral: "USDH", listed: true },
21396
+ { id: 3, dex: "vntl", collateral: "USDH", listed: false },
21397
+ { id: 4, dex: "hyna", collateral: "USDE", listed: true },
21398
+ { id: 5, dex: "km", collateral: "USDH", listed: false },
21399
+ { id: 6, dex: "abcd", collateral: "USDE", listed: false },
21400
+ { id: 7, dex: "cash", collateral: "USDT0", listed: true }
21401
+ ];
21402
+ var LISTED_DEXES = HIP3_DEXES.filter((dex) => dex.listed);
21403
+ var COLLATERAL_COINS = Array.from(new Set([
21404
+ "USDC",
21405
+ ...LISTED_DEXES.map((dex) => dex.collateral)
21406
+ ]));
21407
+ // ../constants/src/hyperliquid/fees.ts
21408
+ var BUILDER_FEE_APPROVAL_TENTH_OF_BASIS_POINTS = 50;
21409
+ var BUILDER_FEE = `${BUILDER_FEE_APPROVAL_TENTH_OF_BASIS_POINTS / 1000}%`;
21410
+ // ../constants/src/hyperliquid/tokens.ts
21411
+ var USDC_TOKEN_ADDRESS = "0x6d1e7cde53ba9467b783cb7c530ce054";
21412
+ var STABLE_TOKENS = {
21413
+ USDC: {
21414
+ coin: "USDC",
21415
+ symbol: "USDC",
21416
+ tokenIndex: 0,
21417
+ pairIndex: null,
21418
+ weiDecimals: 8,
21419
+ tokenId: USDC_TOKEN_ADDRESS,
21420
+ evmAddress: "0xb88339CB7199b77E23DB6E890353E22632Ba630f"
21421
+ },
21422
+ USDH: {
21423
+ coin: "USDH",
21424
+ symbol: "USDH",
21425
+ tokenIndex: 360,
21426
+ pairIndex: 10230,
21427
+ weiDecimals: 8
21428
+ },
21429
+ USDT0: {
21430
+ coin: "USDT0",
21431
+ symbol: "USDT",
21432
+ tokenIndex: 268,
21433
+ pairIndex: 10166,
21434
+ weiDecimals: 8
21435
+ },
21436
+ USDE: {
21437
+ coin: "USDE",
21438
+ symbol: "USDE",
21439
+ tokenIndex: 235,
21440
+ pairIndex: 10150,
21441
+ weiDecimals: 8
21442
+ }
21443
+ };
21444
+ var STABLECOIN_COINS = Object.keys(STABLE_TOKENS);
21445
+ // ../constants/src/onchain.ts
21446
+ var ONCHAIN_QUOTE_TTL_MS = 2 * 60 * 1000;
21447
+ var ONCHAIN_QUOTE_PREVIEW_MIN_REMAINING_MS = 30 * 1000;
21448
+ // ../constants/src/predictions.ts
21449
+ var COMBINING_MARKS = new RegExp("\\p{M}+", "gu");
21450
+ // ../constants/src/vault.ts
21451
+ var AGENT_VAULT_ADDRESSES = [
21452
+ "0xdfc24b077bc1425ad1dea75bcb6f8158e10df303"
21453
+ ];
21454
+ // src/signedFetch.ts
21455
+ import { createHash } from "node:crypto";
21456
+ // package.json
21457
+ var package_default = {
21458
+ name: "@dreamcash-org/mcp",
21459
+ version: "0.1.1",
21460
+ description: "Connect your own AI agent to your Dreamcash account: it reads your account and trades, each trade confirmed by you or on its own within your limits.",
21461
+ license: "MIT",
21462
+ keywords: [
21463
+ "mcp",
21464
+ "mcp-server",
21465
+ "model-context-protocol",
21466
+ "hyperliquid",
21467
+ "dreamcash",
21468
+ "ai-agent",
21469
+ "trading"
21470
+ ],
21471
+ homepage: "https://dreamcash.xyz",
21472
+ repository: {
21473
+ type: "git",
21474
+ url: "git+https://github.com/dreamcash-org/mono.git",
21475
+ directory: "packages/dreamcash-mcp"
21476
+ },
21477
+ type: "module",
21478
+ bin: {
21479
+ "dreamcash-mcp": "dist/dreamcash-mcp.js"
21480
+ },
21481
+ files: [
21482
+ "dist",
21483
+ "README.md"
21484
+ ],
21485
+ engines: {
21486
+ node: ">=20"
21487
+ },
21488
+ publishConfig: {
21489
+ access: "public"
21490
+ },
21491
+ scripts: {
21492
+ build: "bun build.ts",
21493
+ prepack: "bun run build",
21494
+ start: "bun src/main.ts",
21495
+ test: "bun test",
21496
+ "test:testnet": "HL_NETWORK=testnet bun test --timeout 180000 src/agentFlow.hl.test.ts",
21497
+ "test:types": "tsc --noEmit"
21498
+ },
21499
+ devDependencies: {
21500
+ "@dreamcash/constants": "workspace:*",
21501
+ "@dreamcash/hyperliquid-orders": "workspace:*",
21502
+ "@dreamcash/tsconfig": "workspace:*",
21503
+ "@dreamcash/utils": "workspace:*",
21504
+ "@modelcontextprotocol/client": "2.4.0",
21505
+ "@modelcontextprotocol/server": "2.4.0",
21506
+ "@nktkas/hyperliquid": "0.32.2",
21507
+ "@types/bun": "1.3.13",
21508
+ "@types/node": "^20",
21509
+ "@types/react": "^19",
21510
+ typescript: "^5",
21511
+ viem: "^2.40.3",
21512
+ zod: "^4.6.7"
21513
+ }
21514
+ };
21515
+
21516
+ // src/version.ts
21517
+ var DREAMCASH_MCP_VERSION = package_default.version;
21518
+
21519
+ // src/signedFetch.ts
21520
+ var signedFetch = (account) => async (input, init = {}) => {
21521
+ const request = input instanceof Request ? input : undefined;
21522
+ const url2 = new URL(request?.url ?? String(input));
21523
+ const method = (init.method ?? request?.method ?? "GET").toUpperCase();
21524
+ if (init.body != null && typeof init.body !== "string") {
21525
+ throw new Error("Dreamcash calls send their body as text");
21526
+ }
21527
+ const body = init.body ?? "";
21528
+ const at = Date.now();
21529
+ const signature = await account.signMessage({
21530
+ message: aiAgentRequestMessage({
21531
+ method,
21532
+ path: url2.pathname,
21533
+ timestampMs: at,
21534
+ bodySha256: createHash("sha256").update(body).digest("hex")
21535
+ })
21536
+ });
21537
+ const headers = new Headers(init.headers ?? request?.headers);
21538
+ headers.set(AI_AGENT_TIMESTAMP_HEADER, String(at));
21539
+ headers.set(AI_AGENT_SIGNATURE_HEADER, signature);
21540
+ headers.set(DREAMCASH_MCP_VERSION_HEADER, DREAMCASH_MCP_VERSION);
21541
+ return fetch(url2, { ...init, method, headers });
21542
+ };
21543
+
21544
+ // src/agentApi.ts
21545
+ class AgentApiError extends Error {
21546
+ status;
21547
+ code;
21548
+ guidance;
21549
+ constructor(message, status, code, guidance) {
21550
+ super(message);
21551
+ this.status = status;
21552
+ this.code = code;
21553
+ this.guidance = guidance;
21554
+ }
21555
+ }
21556
+ var THIS_MACHINE = new Set(["localhost", "127.0.0.1", "[::1]"]);
21557
+ var checkedApiUrl = (value) => {
21558
+ const url2 = new URL(value);
21559
+ const onThisMachine = url2.protocol === "http:" && THIS_MACHINE.has(url2.hostname);
21560
+ if (url2.protocol !== "https:" && !onThisMachine) {
21561
+ throw new Error(`DREAMCASH_API_URL must be an https URL (plain http only for localhost), not ${value}`);
21562
+ }
21563
+ return url2.href;
21564
+ };
21565
+ var agentApi = (baseUrl, account) => {
21566
+ const send = signedFetch(account);
21567
+ const call = async (method, path, body) => {
21568
+ const response = await send(new URL(path, baseUrl), {
21569
+ method,
21570
+ headers: body ? { "content-type": "application/json" } : {},
21571
+ body: body ? JSON.stringify(body) : undefined
21572
+ });
21573
+ const answer = await response.json().catch(() => ({}));
21574
+ if (!response.ok) {
21575
+ throw new AgentApiError(answer.message ?? `Dreamcash answered ${response.status}`, response.status, answer.code, answer.error);
21576
+ }
21577
+ return answer;
21578
+ };
21579
+ const tradeRequest = (id, action = "") => `/api/ai-connections/agent/trade-requests/${encodeURIComponent(id)}${action}`;
21580
+ const link = (code = "") => `/api/ai-agent/links${code ? `/${encodeURIComponent(code)}` : ""}`;
21581
+ return {
21582
+ get: (id) => call("GET", tradeRequest(id)),
21583
+ claim: (id) => call("POST", tradeRequest(id, "/claim"), {}),
21584
+ sent: (id) => call("POST", tradeRequest(id, "/sent"), {}),
21585
+ notSent: (id, reason) => call("POST", tradeRequest(id, "/not-sent"), { reason: reason.slice(0, 200) }),
21586
+ createPairing: (clientName) => call("POST", link(), {
21587
+ clientName: clientName.slice(0, AI_CLIENT_NAME_MAX_LENGTH)
21588
+ }),
21589
+ pairingStatus: (code) => call("GET", link(code))
21590
+ };
21591
+ };
21592
+
21085
21593
  // src/agentKey.ts
21086
21594
  import {
21087
21595
  chmod,
@@ -25552,480 +26060,115 @@ function findTypeDependencies({ primaryType: primaryType_, types }, results = ne
25552
26060
  function encodeField({ types, name, type, value }) {
25553
26061
  if (types[type] !== undefined) {
25554
26062
  return [
25555
- { type: "bytes32" },
25556
- keccak2562(encodeData({ data: value, primaryType: type, types }))
25557
- ];
25558
- }
25559
- if (type === "bytes")
25560
- return [{ type: "bytes32" }, keccak2562(value)];
25561
- if (type === "string")
25562
- return [{ type: "bytes32" }, keccak2562(toHex(value))];
25563
- if (type.lastIndexOf("]") === type.length - 1) {
25564
- const parsedType2 = type.slice(0, type.lastIndexOf("["));
25565
- const typeValuePairs = value.map((item) => encodeField({
25566
- name,
25567
- type: parsedType2,
25568
- types,
25569
- value: item
25570
- }));
25571
- return [
25572
- { type: "bytes32" },
25573
- keccak2562(encodeAbiParameters2(typeValuePairs.map(([t]) => t), typeValuePairs.map(([, v]) => v)))
25574
- ];
25575
- }
25576
- return [{ type }, value];
25577
- }
25578
-
25579
- // ../../node_modules/.bun/viem@2.52.2+336253948d369456/node_modules/viem/_esm/accounts/utils/signTypedData.js
25580
- async function signTypedData(parameters) {
25581
- const { privateKey, ...typedData } = parameters;
25582
- return await sign({
25583
- hash: hashTypedData2(typedData),
25584
- privateKey,
25585
- to: "hex"
25586
- });
25587
- }
25588
-
25589
- // ../../node_modules/.bun/viem@2.52.2+336253948d369456/node_modules/viem/_esm/accounts/privateKeyToAccount.js
25590
- function privateKeyToAccount(privateKey, options = {}) {
25591
- const { nonceManager: nonceManager2 } = options;
25592
- const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false));
25593
- const address = publicKeyToAddress(publicKey);
25594
- const account = toAccount({
25595
- address,
25596
- nonceManager: nonceManager2,
25597
- async sign({ hash }) {
25598
- return sign({ hash, privateKey, to: "hex" });
25599
- },
25600
- async signAuthorization(authorization) {
25601
- return signAuthorization({ ...authorization, privateKey });
25602
- },
25603
- async signMessage({ message }) {
25604
- return signMessage({ message, privateKey });
25605
- },
25606
- async signTransaction(transaction, { serializer } = {}) {
25607
- return signTransaction({ privateKey, transaction, serializer });
25608
- },
25609
- async signTypedData(typedData) {
25610
- return signTypedData({ ...typedData, privateKey });
25611
- }
25612
- });
25613
- return {
25614
- ...account,
25615
- publicKey,
25616
- source: "privateKey"
25617
- };
25618
- }
25619
- // src/agentKey.ts
25620
- var defaultKeyFile = () => process.env.DREAMCASH_AGENT_KEY_FILE ?? join(homedir(), ".dreamcash", "agent-key.json");
25621
- var pendingKeyFile = (file) => `${file}.pending`;
25622
-
25623
- class KeyUnreadable extends Error {
25624
- file;
25625
- constructor(file, cause) {
25626
- super(`the agent key at ${file} couldn't be read`, { cause });
25627
- this.file = file;
25628
- }
25629
- }
25630
- var storedAgentAccount = async (file = defaultKeyFile()) => {
25631
- try {
25632
- const stored = JSON.parse(await readFile(file, "utf8"));
25633
- if (!isHex(stored.privateKey))
25634
- throw new Error("it holds no private key");
25635
- return privateKeyToAccount(stored.privateKey);
25636
- } catch (error2) {
25637
- const { code } = error2;
25638
- if (code === "ENOENT" || code === "ENOTDIR")
25639
- return;
25640
- throw new KeyUnreadable(file, error2);
25641
- }
25642
- };
25643
- var newAgentAccount = async (file = defaultKeyFile()) => {
25644
- const privateKey = generatePrivateKey();
25645
- const account = privateKeyToAccount(privateKey);
25646
- await mkdir(dirname(file), { recursive: true, mode: 448 });
25647
- const stored = {
25648
- address: account.address,
25649
- privateKey,
25650
- createdAt: new Date().toISOString()
25651
- };
25652
- const written = `${file}.tmp`;
25653
- await writeFile(written, JSON.stringify(stored, null, 2), { mode: 384 });
25654
- await chmod(written, 384);
25655
- await rename(written, file);
25656
- return account;
25657
- };
25658
- var adoptPendingKey = (file) => rename(pendingKeyFile(file), file);
25659
- var dropPendingKey = (file) => rm(pendingKeyFile(file), { force: true });
25660
-
25661
- // ../constants/src/appStores.ts
25662
- var DREAMCASH_APP_STORE_URL = "https://apps.apple.com/app/id6748916424";
25663
- var DREAMCASH_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=xyz.dreamcash.app";
25664
- // ../constants/src/chains.ts
25665
- var ARBITRUM_ONE = {
25666
- id: 42161,
25667
- name: "Arbitrum One",
25668
- nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
25669
- blockTimeMs: 250,
25670
- rpcUrls: [
25671
- "https://arb1.arbitrum.io/rpc",
25672
- "https://arb-mainnet.g.alchemy.com/v2/51PmJ8CQYIfaS57viRzGZ",
25673
- "https://arbitrum-one.publicnode.com",
25674
- "https://1rpc.io/arb"
25675
- ],
25676
- explorer: {
25677
- name: "Arbiscan",
25678
- url: "https://arbiscan.io",
25679
- apiUrl: "https://api.arbiscan.io/api"
25680
- },
25681
- multicall3: {
25682
- address: "0xca11bde05977b3631167028862be2a173976ca11",
25683
- blockCreated: 7654707
25684
- }
25685
- };
25686
- var HYPERLIQUID_SIGNING_CHAIN_ID = ARBITRUM_ONE.id;
25687
- // ../constants/src/evmChains.ts
25688
- var MULTICALL3 = "0xcA11bde05977b3631167028862bE2a173976CA11";
25689
- var ETHER = { name: "Ether", symbol: "ETH", decimals: 18 };
25690
- var RELAY_SELL_CONTRACTS = {
25691
- depository: "0x4cd00e387622c35bddb9b4c962c136462338bc31",
25692
- approvalProxy: "0x5567954cd026cebfe486062cb75848e0f1c12e58"
25693
- };
25694
- var ETHER_COIN = {
25695
- coingeckoCoinId: "ethereum",
25696
- imageUrl: "https://coin-images.coingecko.com/coins/images/279/large/ethereum.png?1696501628"
25697
- };
25698
- var RELAY_NATIVE_SELL_ROUTER = "0x0729e2a4716d9f7dd17858d5d504426d228697f7";
25699
- var CHAINS = {
25700
- 1: {
25701
- vm: "evm",
25702
- name: "Ethereum",
25703
- nativeCurrency: ETHER,
25704
- rpcUrl: "https://ethereum-rpc.publicnode.com",
25705
- explorer: { name: "Etherscan", url: "https://etherscan.io" },
25706
- multicall3: MULTICALL3,
25707
- alchemyNetwork: "eth-mainnet",
25708
- coingeckoNetwork: "eth",
25709
- dexscreenerChain: "ethereum",
25710
- blockTimeMs: 12000,
25711
- v4PoolManager: "0x000000000004444c5dc75cb358380d2e3de08a90",
25712
- securitiesSource: { kind: "coingecko", platform: "ethereum" },
25713
- relaySellContracts: RELAY_SELL_CONTRACTS,
25714
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25715
- nativeCoin: ETHER_COIN
25716
- },
25717
- 10: {
25718
- vm: "evm",
25719
- name: "Optimism",
25720
- nativeCurrency: ETHER,
25721
- rpcUrl: "https://mainnet.optimism.io",
25722
- explorer: {
25723
- name: "Optimistic Etherscan",
25724
- url: "https://optimistic.etherscan.io"
26063
+ { type: "bytes32" },
26064
+ keccak2562(encodeData({ data: value, primaryType: type, types }))
26065
+ ];
26066
+ }
26067
+ if (type === "bytes")
26068
+ return [{ type: "bytes32" }, keccak2562(value)];
26069
+ if (type === "string")
26070
+ return [{ type: "bytes32" }, keccak2562(toHex(value))];
26071
+ if (type.lastIndexOf("]") === type.length - 1) {
26072
+ const parsedType2 = type.slice(0, type.lastIndexOf("["));
26073
+ const typeValuePairs = value.map((item) => encodeField({
26074
+ name,
26075
+ type: parsedType2,
26076
+ types,
26077
+ value: item
26078
+ }));
26079
+ return [
26080
+ { type: "bytes32" },
26081
+ keccak2562(encodeAbiParameters2(typeValuePairs.map(([t]) => t), typeValuePairs.map(([, v]) => v)))
26082
+ ];
26083
+ }
26084
+ return [{ type }, value];
26085
+ }
26086
+
26087
+ // ../../node_modules/.bun/viem@2.52.2+336253948d369456/node_modules/viem/_esm/accounts/utils/signTypedData.js
26088
+ async function signTypedData(parameters) {
26089
+ const { privateKey, ...typedData } = parameters;
26090
+ return await sign({
26091
+ hash: hashTypedData2(typedData),
26092
+ privateKey,
26093
+ to: "hex"
26094
+ });
26095
+ }
26096
+
26097
+ // ../../node_modules/.bun/viem@2.52.2+336253948d369456/node_modules/viem/_esm/accounts/privateKeyToAccount.js
26098
+ function privateKeyToAccount(privateKey, options = {}) {
26099
+ const { nonceManager: nonceManager2 } = options;
26100
+ const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false));
26101
+ const address = publicKeyToAddress(publicKey);
26102
+ const account = toAccount({
26103
+ address,
26104
+ nonceManager: nonceManager2,
26105
+ async sign({ hash }) {
26106
+ return sign({ hash, privateKey, to: "hex" });
25725
26107
  },
25726
- multicall3: MULTICALL3,
25727
- alchemyNetwork: "opt-mainnet",
25728
- coingeckoNetwork: "optimism",
25729
- dexscreenerChain: "optimism",
25730
- blockTimeMs: 2000,
25731
- v4PoolManager: "0x9a13f98cb987694c9f086b1f5eb990eea8264ec3",
25732
- securitiesSource: { kind: "coingecko", platform: "optimistic-ethereum" },
25733
- relaySellContracts: RELAY_SELL_CONTRACTS,
25734
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25735
- nativeCoin: ETHER_COIN
25736
- },
25737
- 56: {
25738
- vm: "evm",
25739
- name: "BNB Chain",
25740
- nativeCurrency: { name: "BNB", symbol: "BNB", decimals: 18 },
25741
- rpcUrl: "https://bsc-dataseed.bnbchain.org",
25742
- explorer: { name: "BscScan", url: "https://bscscan.com" },
25743
- multicall3: MULTICALL3,
25744
- alchemyNetwork: "bnb-mainnet",
25745
- coingeckoNetwork: "bsc",
25746
- dexscreenerChain: "bsc",
25747
- blockTimeMs: 450,
25748
- v4PoolManager: "0x28e2ea090877bf75740558f6bfb36a5ffee9e9df",
25749
- securitiesSource: { kind: "coingecko", platform: "binance-smart-chain" },
25750
- relaySellContracts: RELAY_SELL_CONTRACTS,
25751
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25752
- nativeCoin: {
25753
- coingeckoCoinId: "binancecoin",
25754
- imageUrl: "https://coin-images.coingecko.com/coins/images/825/large/bnb-icon2_2x.png?1696501970"
25755
- }
25756
- },
25757
- 130: {
25758
- vm: "evm",
25759
- name: "Unichain",
25760
- nativeCurrency: ETHER,
25761
- rpcUrl: "https://mainnet.unichain.org",
25762
- explorer: { name: "Uniscan", url: "https://uniscan.xyz" },
25763
- multicall3: MULTICALL3,
25764
- alchemyNetwork: "unichain-mainnet",
25765
- coingeckoNetwork: "unichain",
25766
- dexscreenerChain: "unichain",
25767
- blockTimeMs: 1000,
25768
- v4PoolManager: "0x1f98400000000000000000000000000000000004",
25769
- securitiesSource: { kind: "coingecko", platform: "unichain" },
25770
- relaySellContracts: RELAY_SELL_CONTRACTS,
25771
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25772
- nativeCoin: ETHER_COIN
25773
- },
25774
- 480: {
25775
- vm: "evm",
25776
- name: "World Chain",
25777
- nativeCurrency: ETHER,
25778
- rpcUrl: "https://worldchain-mainnet.g.alchemy.com/public",
25779
- explorer: { name: "Worldscan", url: "https://worldscan.org" },
25780
- multicall3: MULTICALL3,
25781
- alchemyNetwork: "worldchain-mainnet",
25782
- coingeckoNetwork: "world-chain",
25783
- dexscreenerChain: "worldchain",
25784
- blockTimeMs: 2000,
25785
- v4PoolManager: "0xb1860d529182ac3bc1f51fa2abd56662b7d13f33",
25786
- securitiesSource: { kind: "coingecko", platform: "world-chain" },
25787
- relaySellContracts: RELAY_SELL_CONTRACTS,
25788
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25789
- nativeCoin: ETHER_COIN
25790
- },
25791
- 4663: {
25792
- vm: "evm",
25793
- name: "Robinhood Chain",
25794
- nativeCurrency: ETHER,
25795
- rpcUrl: "https://rpc.mainnet.chain.robinhood.com",
25796
- explorer: {
25797
- name: "Blockscout",
25798
- url: "https://robinhoodchain.blockscout.com"
26108
+ async signAuthorization(authorization) {
26109
+ return signAuthorization({ ...authorization, privateKey });
25799
26110
  },
25800
- multicall3: MULTICALL3,
25801
- alchemyNetwork: "robinhood-mainnet",
25802
- coingeckoNetwork: "robinhood",
25803
- dexscreenerChain: "robinhood",
25804
- blockTimeMs: 100,
25805
- v4PoolManager: "0x8366a39cc670b4001a1121b8f6a443a643e40951",
25806
- securitiesSource: {
25807
- kind: "registry",
25808
- url: "https://api.robinhood.com/rhj/assets/"
26111
+ async signMessage({ message }) {
26112
+ return signMessage({ message, privateKey });
25809
26113
  },
25810
- relaySellContracts: RELAY_SELL_CONTRACTS,
25811
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25812
- nativeCoin: ETHER_COIN
25813
- },
25814
- 8453: {
25815
- vm: "evm",
25816
- name: "Base",
25817
- nativeCurrency: ETHER,
25818
- rpcUrl: "https://mainnet.base.org",
25819
- explorer: { name: "Basescan", url: "https://basescan.org" },
25820
- multicall3: MULTICALL3,
25821
- alchemyNetwork: "base-mainnet",
25822
- coingeckoNetwork: "base",
25823
- dexscreenerChain: "base",
25824
- blockTimeMs: 2000,
25825
- v4PoolManager: "0x498581ff718922c3f8e6a244956af099b2652b2b",
25826
- securitiesSource: { kind: "coingecko", platform: "base" },
25827
- relaySellContracts: RELAY_SELL_CONTRACTS,
25828
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25829
- nativeCoin: ETHER_COIN
25830
- },
25831
- 42161: {
25832
- vm: "evm",
25833
- name: "Arbitrum",
25834
- nativeCurrency: ETHER,
25835
- rpcUrl: "https://arb1.arbitrum.io/rpc",
25836
- explorer: { name: "Arbiscan", url: "https://arbiscan.io" },
25837
- multicall3: MULTICALL3,
25838
- alchemyNetwork: "arb-mainnet",
25839
- coingeckoNetwork: "arbitrum",
25840
- dexscreenerChain: "arbitrum",
25841
- blockTimeMs: 250,
25842
- v4PoolManager: "0x360e68faccca8ca495c1b759fd9eee466db9fb32",
25843
- securitiesSource: { kind: "coingecko", platform: "arbitrum-one" },
25844
- relaySellContracts: RELAY_SELL_CONTRACTS,
25845
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25846
- nativeCoin: ETHER_COIN
25847
- },
25848
- 99901: {
25849
- vm: "evm",
25850
- name: "Elysium",
25851
- nativeCurrency: { name: "HYPE", symbol: "HYPE", decimals: 18 },
25852
- rpcUrl: "https://rpc.elysium.kinetiq.xyz",
25853
- explorer: {
25854
- name: "Elysium Explorer",
25855
- url: "https://elysium.kinetiq.xyz/explorer"
26114
+ async signTransaction(transaction, { serializer } = {}) {
26115
+ return signTransaction({ privateKey, transaction, serializer });
25856
26116
  },
25857
- multicall3: MULTICALL3,
25858
- alchemyNetwork: "elysium-mainnet",
25859
- coingeckoNetwork: "elysium",
25860
- dexscreenerChain: "elysium",
25861
- blockTimeMs: 100,
25862
- v4PoolManager: "0xe2e105d3f7209a9da11f83ccf3e7398a753823f1",
25863
- securitiesSource: { kind: "coingecko", platform: "elysium-kinetiq" },
25864
- relaySellContracts: RELAY_SELL_CONTRACTS,
25865
- relayNativeSellRouter: RELAY_NATIVE_SELL_ROUTER,
25866
- nativeCoin: {
25867
- coingeckoCoinId: "hyperliquid",
25868
- imageUrl: "https://coin-images.coingecko.com/coins/images/50882/large/hyperliquid.jpg?1729431300"
25869
- }
25870
- },
25871
- 792703809: {
25872
- vm: "svm",
25873
- name: "Solana",
25874
- nativeCurrency: { name: "Solana", symbol: "SOL", decimals: 9 },
25875
- rpcUrl: "https://api.mainnet-beta.solana.com",
25876
- explorer: { name: "Solscan", url: "https://solscan.io" },
25877
- alchemyNetwork: "solana-mainnet",
25878
- coingeckoNetwork: "solana",
25879
- dexscreenerChain: "solana",
25880
- blockTimeMs: 400,
25881
- securitiesSource: { kind: "coingecko", platform: "solana" },
25882
- relaySellPrograms: {
25883
- depositoryProgram: "DPArtTLbEqa6EuXHfL5UFLBZhFjiEXWRudhvXDrjwXUr",
25884
- depository: "99vQwtBwYtrqqD9YSXbdum3KBdxPAVxYTaQ3cfnJSrN2",
25885
- jupiter: "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
26117
+ async signTypedData(typedData) {
26118
+ return signTypedData({ ...typedData, privateKey });
25886
26119
  }
26120
+ });
26121
+ return {
26122
+ ...account,
26123
+ publicKey,
26124
+ source: "privateKey"
26125
+ };
26126
+ }
26127
+ // src/agentKey.ts
26128
+ var defaultKeyFile = () => process.env.DREAMCASH_AGENT_KEY_FILE ?? join(homedir(), ".dreamcash", "agent-key.json");
26129
+ var pendingKeyFile = (file) => `${file}.pending`;
26130
+
26131
+ class KeyUnreadable extends Error {
26132
+ file;
26133
+ constructor(file, cause) {
26134
+ super(`the agent key at ${file} couldn't be read`, { cause });
26135
+ this.file = file;
25887
26136
  }
25888
- };
25889
- var CHAIN_IDS = Object.keys(CHAINS).map(Number);
25890
- var isChainId = (chainId) => (chainId in CHAINS);
25891
- var EVM_CHAINS = Object.fromEntries(Object.entries(CHAINS).filter(([, chain]) => chain.vm === "evm"));
25892
- var isEvmChainId = (chainId) => isChainId(chainId) && CHAINS[chainId].vm === "evm";
25893
- var EVM_CHAIN_IDS = CHAIN_IDS.filter(isEvmChainId);
25894
- // ../constants/src/evmContracts.ts
25895
- var CALIBUR_ADDRESS = "0x000000009B1D0aF20D8C6d0A44e162d11F9b8f00";
25896
- var CALIBUR_EXECUTE_ABI = [
25897
- {
25898
- name: "execute",
25899
- type: "function",
25900
- stateMutability: "payable",
25901
- inputs: [
25902
- {
25903
- name: "signedBatchedCall",
25904
- type: "tuple",
25905
- components: [
25906
- {
25907
- name: "batchedCall",
25908
- type: "tuple",
25909
- components: [
25910
- {
25911
- name: "calls",
25912
- type: "tuple[]",
25913
- components: [
25914
- { name: "to", type: "address" },
25915
- { name: "value", type: "uint256" },
25916
- { name: "data", type: "bytes" }
25917
- ]
25918
- },
25919
- { name: "revertOnFailure", type: "bool" }
25920
- ]
25921
- },
25922
- { name: "nonce", type: "uint256" },
25923
- { name: "keyHash", type: "bytes32" },
25924
- { name: "executor", type: "address" },
25925
- { name: "deadline", type: "uint256" }
25926
- ]
25927
- },
25928
- { name: "wrappedSignature", type: "bytes" }
25929
- ],
25930
- outputs: []
25931
- }
25932
- ];
25933
- var CALIBUR_ABI = [
25934
- ...CALIBUR_EXECUTE_ABI,
25935
- {
25936
- name: "getSeq",
25937
- type: "function",
25938
- stateMutability: "view",
25939
- inputs: [{ name: "key", type: "uint256" }],
25940
- outputs: [{ name: "", type: "uint256" }]
26137
+ }
26138
+ var storedAgentAccount = async (file = defaultKeyFile()) => {
26139
+ try {
26140
+ const stored = JSON.parse(await readFile(file, "utf8"));
26141
+ if (!isHex(stored.privateKey))
26142
+ throw new Error("it holds no private key");
26143
+ return privateKeyToAccount(stored.privateKey);
26144
+ } catch (error2) {
26145
+ const { code } = error2;
26146
+ if (code === "ENOENT" || code === "ENOTDIR")
26147
+ return;
26148
+ throw new KeyUnreadable(file, error2);
25941
26149
  }
25942
- ];
25943
- var CALIBUR_EIP712_DOMAIN = {
25944
- name: "Calibur",
25945
- version: "1.0.0",
25946
- salt: `0x${CALIBUR_ADDRESS.slice(2).padStart(64, "0")}`
25947
26150
  };
25948
- // ../constants/src/hyperliquid/aiAgent.ts
25949
- var TRADE_REQUEST_TTL_MS = 15 * 60 * 1000;
25950
- var AI_AGENT_SIGNATURE_HEADER = "x-dreamcash-agent-signature";
25951
- var AI_AGENT_TIMESTAMP_HEADER = "x-dreamcash-agent-timestamp";
25952
- var aiAgentRequestMessage = ({
25953
- method,
25954
- path,
25955
- timestampMs,
25956
- bodySha256
25957
- }) => `Dreamcash agent ${method.toUpperCase()} ${path} ${timestampMs} ${bodySha256}`;
25958
- var DREAMCASH_MCP_VERSION_HEADER = "x-dreamcash-mcp-version";
25959
- // ../constants/src/hyperliquid/assetIndex.ts
25960
- var SPOT_ASSET_INDEX_OFFSET = 1e4;
25961
- var HIP3_ASSET_INDEX_OFFSET = 1e5;
25962
- var DEX_INDEX_MULTIPLIER = 1e4;
25963
- var HIP4_ASSET_INDEX_OFFSET = 1e8;
25964
- var hip3DexIdOfAssetIndex = (assetIndex) => Math.floor((assetIndex - HIP3_ASSET_INDEX_OFFSET) / DEX_INDEX_MULTIPLIER);
25965
- var isHip3Coin = (coin) => coin.includes(":");
25966
- var getDexFromCoin = (coin) => isHip3Coin(coin) ? coin.split(":")[0] : undefined;
25967
- // ../constants/src/hyperliquid/dexes.ts
25968
- var HIP3_DEXES = [
25969
- { id: 1, dex: "xyz", collateral: "USDC", listed: true },
25970
- { id: 2, dex: "flx", collateral: "USDH", listed: true },
25971
- { id: 3, dex: "vntl", collateral: "USDH", listed: false },
25972
- { id: 4, dex: "hyna", collateral: "USDE", listed: true },
25973
- { id: 5, dex: "km", collateral: "USDH", listed: false },
25974
- { id: 6, dex: "abcd", collateral: "USDE", listed: false },
25975
- { id: 7, dex: "cash", collateral: "USDT0", listed: true }
25976
- ];
25977
- var LISTED_DEXES = HIP3_DEXES.filter((dex) => dex.listed);
25978
- var COLLATERAL_COINS = Array.from(new Set([
25979
- "USDC",
25980
- ...LISTED_DEXES.map((dex) => dex.collateral)
25981
- ]));
25982
- // ../constants/src/hyperliquid/fees.ts
25983
- var BUILDER_FEE_APPROVAL_TENTH_OF_BASIS_POINTS = 50;
25984
- var BUILDER_FEE = `${BUILDER_FEE_APPROVAL_TENTH_OF_BASIS_POINTS / 1000}%`;
25985
- // ../constants/src/hyperliquid/tokens.ts
25986
- var USDC_TOKEN_ADDRESS = "0x6d1e7cde53ba9467b783cb7c530ce054";
25987
- var STABLE_TOKENS = {
25988
- USDC: {
25989
- coin: "USDC",
25990
- symbol: "USDC",
25991
- tokenIndex: 0,
25992
- pairIndex: null,
25993
- weiDecimals: 8,
25994
- tokenId: USDC_TOKEN_ADDRESS,
25995
- evmAddress: "0xb88339CB7199b77E23DB6E890353E22632Ba630f"
25996
- },
25997
- USDH: {
25998
- coin: "USDH",
25999
- symbol: "USDH",
26000
- tokenIndex: 360,
26001
- pairIndex: 10230,
26002
- weiDecimals: 8
26003
- },
26004
- USDT0: {
26005
- coin: "USDT0",
26006
- symbol: "USDT",
26007
- tokenIndex: 268,
26008
- pairIndex: 10166,
26009
- weiDecimals: 8
26010
- },
26011
- USDE: {
26012
- coin: "USDE",
26013
- symbol: "USDE",
26014
- tokenIndex: 235,
26015
- pairIndex: 10150,
26016
- weiDecimals: 8
26017
- }
26151
+ var newAgentAccount = async (file = defaultKeyFile()) => {
26152
+ const privateKey = generatePrivateKey();
26153
+ const account = privateKeyToAccount(privateKey);
26154
+ await mkdir(dirname(file), { recursive: true, mode: 448 });
26155
+ const stored = {
26156
+ address: account.address,
26157
+ privateKey,
26158
+ createdAt: new Date().toISOString()
26159
+ };
26160
+ const written = `${file}.tmp`;
26161
+ await rm(written, { force: true });
26162
+ await writeFile(written, JSON.stringify(stored, null, 2), {
26163
+ mode: 384,
26164
+ flag: "wx"
26165
+ });
26166
+ await chmod(written, 384);
26167
+ await rename(written, file);
26168
+ return account;
26018
26169
  };
26019
- var STABLECOIN_COINS = Object.keys(STABLE_TOKENS);
26020
- // ../constants/src/onchain.ts
26021
- var ONCHAIN_QUOTE_TTL_MS = 2 * 60 * 1000;
26022
- var ONCHAIN_QUOTE_PREVIEW_MIN_REMAINING_MS = 30 * 1000;
26023
- // ../constants/src/predictions.ts
26024
- var COMBINING_MARKS = new RegExp("\\p{M}+", "gu");
26025
- // ../constants/src/vault.ts
26026
- var AGENT_VAULT_ADDRESSES = [
26027
- "0xdfc24b077bc1425ad1dea75bcb6f8158e10df303"
26028
- ];
26170
+ var adoptPendingKey = (file) => rename(pendingKeyFile(file), file);
26171
+ var dropPendingKey = (file) => rm(pendingKeyFile(file), { force: true });
26029
26172
  // ../hyperliquid-orders/src/trade.ts
26030
26173
  var OUTCOME_PRICE_DECIMALS = 5;
26031
26174
  // ../hyperliquid-orders/src/plan.ts
@@ -47976,127 +48119,6 @@ var StreamableHTTPClientTransport = class {
47976
48119
  // ../../node_modules/.bun/@modelcontextprotocol+server@2.4.0/node_modules/@modelcontextprotocol/server/dist/index.mjs
47977
48120
  var DEFAULT_MAX_REQUEST_BODY_SIZE = 4 * 1024 * 1024;
47978
48121
 
47979
- // src/signedFetch.ts
47980
- import { createHash } from "node:crypto";
47981
- // package.json
47982
- var package_default = {
47983
- name: "@dreamcash-org/mcp",
47984
- version: "0.1.0",
47985
- description: "Connect your own AI agent to your Dreamcash account: it reads your account and asks for trades you confirm.",
47986
- license: "MIT",
47987
- keywords: [
47988
- "mcp",
47989
- "hyperliquid",
47990
- "dreamcash",
47991
- "ai-agent",
47992
- "trading"
47993
- ],
47994
- homepage: "https://dreamcash.xyz",
47995
- type: "module",
47996
- bin: {
47997
- "dreamcash-mcp": "dist/dreamcash-mcp.js"
47998
- },
47999
- files: [
48000
- "dist",
48001
- "README.md"
48002
- ],
48003
- engines: {
48004
- node: ">=20"
48005
- },
48006
- publishConfig: {
48007
- access: "public"
48008
- },
48009
- scripts: {
48010
- build: "bun build.ts",
48011
- prepack: "bun run build",
48012
- start: "bun src/main.ts",
48013
- test: "bun test",
48014
- "test:testnet": "HL_NETWORK=testnet bun test --timeout 180000 src/agentFlow.hl.test.ts",
48015
- "test:types": "tsc --noEmit"
48016
- },
48017
- devDependencies: {
48018
- "@dreamcash/constants": "workspace:*",
48019
- "@dreamcash/hyperliquid-orders": "workspace:*",
48020
- "@dreamcash/tsconfig": "workspace:*",
48021
- "@dreamcash/utils": "workspace:*",
48022
- "@modelcontextprotocol/client": "2.4.0",
48023
- "@modelcontextprotocol/server": "2.4.0",
48024
- "@nktkas/hyperliquid": "0.32.2",
48025
- "@types/bun": "1.3.13",
48026
- "@types/node": "^20",
48027
- "@types/react": "^19",
48028
- typescript: "^5",
48029
- viem: "^2.40.3",
48030
- zod: "^4.6.7"
48031
- }
48032
- };
48033
-
48034
- // src/version.ts
48035
- var DREAMCASH_MCP_VERSION = package_default.version;
48036
-
48037
- // src/signedFetch.ts
48038
- var signedFetch = (account) => async (input, init = {}) => {
48039
- const request = input instanceof Request ? input : undefined;
48040
- const url2 = new URL(request?.url ?? String(input));
48041
- const method = (init.method ?? request?.method ?? "GET").toUpperCase();
48042
- if (init.body != null && typeof init.body !== "string") {
48043
- throw new Error("Dreamcash calls send their body as text");
48044
- }
48045
- const body = init.body ?? "";
48046
- const at = Date.now();
48047
- const signature = await account.signMessage({
48048
- message: aiAgentRequestMessage({
48049
- method,
48050
- path: url2.pathname,
48051
- timestampMs: at,
48052
- bodySha256: createHash("sha256").update(body).digest("hex")
48053
- })
48054
- });
48055
- const headers = new Headers(init.headers ?? request?.headers);
48056
- headers.set(AI_AGENT_TIMESTAMP_HEADER, String(at));
48057
- headers.set(AI_AGENT_SIGNATURE_HEADER, signature);
48058
- headers.set(DREAMCASH_MCP_VERSION_HEADER, DREAMCASH_MCP_VERSION);
48059
- return fetch(url2, { ...init, method, headers });
48060
- };
48061
-
48062
- // src/agentApi.ts
48063
- class AgentApiError extends Error {
48064
- status;
48065
- code;
48066
- guidance;
48067
- constructor(message, status, code, guidance) {
48068
- super(message);
48069
- this.status = status;
48070
- this.code = code;
48071
- this.guidance = guidance;
48072
- }
48073
- }
48074
- var agentApi = (baseUrl, account) => {
48075
- const send = signedFetch(account);
48076
- const call = async (method, path, body) => {
48077
- const response = await send(new URL(path, baseUrl), {
48078
- method,
48079
- headers: body ? { "content-type": "application/json" } : {},
48080
- body: body ? JSON.stringify(body) : undefined
48081
- });
48082
- const answer = await response.json().catch(() => ({}));
48083
- if (!response.ok) {
48084
- throw new AgentApiError(answer.message ?? `Dreamcash answered ${response.status}`, response.status, answer.code, answer.error);
48085
- }
48086
- return answer;
48087
- };
48088
- const tradeRequest = (id, action = "") => `/api/ai-connections/agent/trade-requests/${encodeURIComponent(id)}${action}`;
48089
- const link = (code = "") => `/api/ai-agent/links${code ? `/${encodeURIComponent(code)}` : ""}`;
48090
- return {
48091
- get: (id) => call("GET", tradeRequest(id)),
48092
- claim: (id) => call("POST", tradeRequest(id, "/claim"), {}),
48093
- sent: (id) => call("POST", tradeRequest(id, "/sent"), {}),
48094
- notSent: (id, reason) => call("POST", tradeRequest(id, "/not-sent"), { reason: reason.slice(0, 200) }),
48095
- createPairing: (clientName) => call("POST", link(), { clientName }),
48096
- pairingStatus: (code) => call("GET", link(code))
48097
- };
48098
- };
48099
-
48100
48122
  // src/agentSafety.ts
48101
48123
  var MAX_PRICE_DEVIATION = 0.1;
48102
48124
  var MAX_NOTIONAL_OVER_ASKED = 1.05;
@@ -48685,7 +48707,7 @@ var executeTradeRequest = async ({
48685
48707
  // src/dreamcashServer.ts
48686
48708
  var PAIRING_WAIT_MS = 25000;
48687
48709
  var PAIRING_POLL_MS = 2000;
48688
- var INSTRUCTIONS = `Dreamcash is a Hyperliquid trading app. This server connects you to the user's Dreamcash account. Until you're connected, connect_dreamcash is your only tool: call it and write the code and link it gives you out in full in your reply (the user may not see tool results), then call it again until it says connected. You then get tools to read their account (balances, positions, orders, history, PnL, XP, vaults) and Hyperliquid markets, and, if the user allowed it, to ask for trades. Once connected, call how_to_use_dreamcash first: it explains every tool, what you may do and how to behave.
48710
+ var INSTRUCTIONS = `Dreamcash is a Hyperliquid trading app. This server connects you to the user's Dreamcash account. Until you're connected, connect_dreamcash is your only tool: call it and write the code and link it gives you out in full in your reply (the user may not see tool results), then call it again until it says connected. You then get tools to read their account (balances, positions, orders, history, PnL, XP, vaults) and Hyperliquid markets, and to ask for trades, or, if the user lets you, to trade on your own with your own key, kept on this machine (Dreamcash never sees it). Once connected, call how_to_use_dreamcash first: it explains every tool, what you may do and how to behave.
48689
48711
 
48690
48712
  Anything that fails answers {"error": {code, what_happened, what_to_do, tell_the_user, can_retry}}: do what_to_do, and pass tell_the_user on to the user. Amounts are USD unless stated. What you suggest is your own analysis, not advice from Dreamcash.`;
48691
48713
  var CONNECT_TOOL = {
@@ -48811,7 +48833,19 @@ var createDreamcashServer = ({
48811
48833
  apiUrl,
48812
48834
  keyFile
48813
48835
  }) => {
48814
- const server = new Server({ name: "dreamcash", title: "Dreamcash", version: DREAMCASH_MCP_VERSION }, {
48836
+ const server = new Server({
48837
+ name: "dreamcash",
48838
+ title: "Dreamcash",
48839
+ version: DREAMCASH_MCP_VERSION,
48840
+ websiteUrl: "https://dreamcash.xyz",
48841
+ icons: [
48842
+ {
48843
+ src: new URL("/dreamcash-icon.png", apiUrl).href,
48844
+ mimeType: "image/png",
48845
+ sizes: ["256x256"]
48846
+ }
48847
+ ]
48848
+ }, {
48815
48849
  capabilities: { tools: { listChanged: true } },
48816
48850
  instructions: INSTRUCTIONS
48817
48851
  });
@@ -49008,7 +49042,7 @@ var createDreamcashServer = ({
49008
49042
 
49009
49043
  // src/main.ts
49010
49044
  var server = createDreamcashServer({
49011
- apiUrl: process.env.DREAMCASH_API_URL ?? "https://api.dreamcash.xyz",
49045
+ apiUrl: checkedApiUrl(process.env.DREAMCASH_API_URL ?? "https://api.dreamcash.xyz"),
49012
49046
  keyFile: defaultKeyFile()
49013
49047
  });
49014
49048
  await server.connect(new StdioServerTransport);