/**
* DataAI API Configuration and Constants
* Contains all endpoint definitions, API configuration, and supported chains
*/
// Simple environment loading - server must run anyway
function getOptionalEnvVar(name: string, defaultValue: string): string {
return process.env[name] || defaultValue;
}
function getOptionalIntEnvVar(name: string, defaultValue: number): number {
const value = process.env[name];
if (value === undefined) return defaultValue;
const parsed = parseInt(value, 10);
return isNaN(parsed) ? defaultValue : parsed;
}
function getOptionalBooleanEnvVar(name: string, defaultValue: boolean): boolean {
const value = process.env[name];
if (value === undefined) return defaultValue;
return value.toLowerCase() === 'true';
}
// API Configuration
export const API_CONFIG = {
BASE_URL: 'https://api-v1.mymerlin.io',
API_KEY: process.env.DATAI_API_KEY, // No fallback - tools will handle missing key gracefully
TIMEOUT: 180000, // 3 minutes as tested
USER_AGENT: 'DataAI-FastMCP/1.0.0',
LIMIT: getOptionalIntEnvVar('DATAI_LIMIT', 1),
DEBUG_TRUNCATE: getOptionalBooleanEnvVar('DATAI_DEBUG_TRUNCATE', false)
} as const;
// Server Configuration - Simple version without complex validation
export const SERVER_CONFIG = {
PORT: parseInt(process.env.PORT || "3099"),
DEBUG: process.env.DEBUG === "true",
NODE_ENV: process.env.NODE_ENV || "production",
LOG_LEVEL: process.env.LOG_LEVEL || "info"
} as const;
// Test Wallet Addresses (Verified Working)
export const TEST_WALLETS = {
WALLET1: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
WALLET2: '0x09CF915e195aF33FA7B932C253352Ae9FBdB0106',
WALLET3: '0xbdfa4f4492dd7b7cf211209c4791af8d52bf5c50'
} as const;
// Supported Blockchain Networks
export const SUPPORTED_CHAINS = [
'eth', // Ethereum
'arb', // Arbitrum
'matic', // Polygon
'avax', // Avalanche
'bsc', // Binance Smart Chain
'base', // Base
'op' // Optimism
] as const;
export type SupportedChain = typeof SUPPORTED_CHAINS[number];
// API Endpoints - DeFi Position Tools (4 endpoints)
export const DEFI_ENDPOINTS = {
// Tool 1: Get All User DeFi Positions
GET_ALL_USER_DEFI_POSITIONS: '/api/merlin/public/userDeFiPositions/all/{wallet}',
// Tool 2: Get User DeFi Positions by Chain
GET_USER_DEFI_POSITIONS_BY_CHAIN: '/api/merlin/public/userDeFiPositions/{wallet}',
// Tool 3: Get User DeFi Positions by Multiple Chains
GET_USER_DEFI_POSITIONS_BY_MULTIPLE_CHAINS: '/api/merlin/public/userDeFiPositionsByChains/{wallet}',
// Tool 4: Get User DeFi Positions by Protocol
GET_USER_DEFI_POSITIONS_BY_PROTOCOL: '/api/merlin/public/userDeFiPositions/{wallet}'
} as const;
// API Endpoints - Balance Tools (4 endpoints)
export const BALANCE_ENDPOINTS = {
// Tool 5: Get User DeFi Protocol Balances by Chain
GET_USER_DEFI_PROTOCOL_BALANCES_BY_CHAIN: '/api/merlin/public/balances/defi/{wallet}',
// Tool 6: Get User Overall Balance All Chains
GET_USER_OVERALL_BALANCE_ALL_CHAINS: '/api/merlin/public/balances/all/{wallet}',
// Tool 7: Get User Overall Balance by Chain
GET_USER_OVERALL_BALANCE_BY_CHAIN: '/api/merlin/public/balances/overall/{wallet}',
// Tool 8: Get Wallet Balances by Chain
GET_WALLET_BALANCES_BY_CHAIN: '/api/merlin/public/balances/token/{wallet}'
} as const;
// All Endpoints Combined
export const ALL_ENDPOINTS = {
...DEFI_ENDPOINTS,
...BALANCE_ENDPOINTS
} as const;
// Working Test Curl Commands for Reference
export const TEST_COMMANDS = {
DEFI: {
ALL_POSITIONS: `curl -H "Authorization: ${API_CONFIG.API_KEY}" "${API_CONFIG.BASE_URL}${DEFI_ENDPOINTS.GET_ALL_USER_DEFI_POSITIONS.replace('{wallet}', TEST_WALLETS.WALLET1)}"`,
BY_CHAIN: `curl -H "Authorization: ${API_CONFIG.API_KEY}" "${API_CONFIG.BASE_URL}${DEFI_ENDPOINTS.GET_USER_DEFI_POSITIONS_BY_CHAIN.replace('{wallet}', TEST_WALLETS.WALLET2)}?chain=arb"`,
MULTIPLE_CHAINS: `curl -H "Authorization: ${API_CONFIG.API_KEY}" "${API_CONFIG.BASE_URL}${DEFI_ENDPOINTS.GET_USER_DEFI_POSITIONS_BY_MULTIPLE_CHAINS.replace('{wallet}', TEST_WALLETS.WALLET3)}?chains=avax,arb"`,
BY_PROTOCOL: `curl -H "Authorization: ${API_CONFIG.API_KEY}" "${API_CONFIG.BASE_URL}${DEFI_ENDPOINTS.GET_USER_DEFI_POSITIONS_BY_PROTOCOL.replace('{wallet}', TEST_WALLETS.WALLET2)}?protocol=uniswap"`
},
BALANCE: {
DEFI_BY_CHAIN: `curl -H "Authorization: ${API_CONFIG.API_KEY}" "${API_CONFIG.BASE_URL}${BALANCE_ENDPOINTS.GET_USER_DEFI_PROTOCOL_BALANCES_BY_CHAIN.replace('{wallet}', TEST_WALLETS.WALLET2)}?chain=arb"`,
ALL_CHAINS: `curl -H "Authorization: ${API_CONFIG.API_KEY}" "${API_CONFIG.BASE_URL}${BALANCE_ENDPOINTS.GET_USER_OVERALL_BALANCE_ALL_CHAINS.replace('{wallet}', TEST_WALLETS.WALLET2)}"`,
BY_CHAIN: `curl -H "Authorization: ${API_CONFIG.API_KEY}" "${API_CONFIG.BASE_URL}${BALANCE_ENDPOINTS.GET_USER_OVERALL_BALANCE_BY_CHAIN.replace('{wallet}', TEST_WALLETS.WALLET1)}?chain=eth"`,
TOKEN_BY_CHAIN: `curl -H "Authorization: ${API_CONFIG.API_KEY}" "${API_CONFIG.BASE_URL}${BALANCE_ENDPOINTS.GET_WALLET_BALANCES_BY_CHAIN.replace('{wallet}', TEST_WALLETS.WALLET1)}?chain=base"`
}
} as const;
// Common DeFi Protocols (for validation)
export const COMMON_PROTOCOLS = [
'uniswap',
'aave',
'compound',
'curve',
'balancer',
'sushiswap',
'yearn',
'convex',
'frax',
'liquity'
] as const;
export type CommonProtocol = typeof COMMON_PROTOCOLS[number];