@dbotx/fast-swap-mcp-server
Version:
Fast Swap MCP Server - Supports quickly initiating token buy/sell tasks, querying transaction results, and managing take-profit/stop-loss tasks.
184 lines • 10.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateLimitOrdersRequestSchema = exports.LimitOrderSettingSchema = exports.TriggerDirectionSchema = exports.CreateFastSwapsRequestSchema = exports.CreateFastSwapRequestSchema = exports.PnlCustomConfigSchema = exports.PnlGroupSchema = exports.TradeTypeSchema = exports.ChainSchema = void 0;
exports.getEnvDefault = getEnvDefault;
exports.getWalletIdByChain = getWalletIdByChain;
exports.validateWalletIdConfig = validateWalletIdConfig;
const zod_1 = require("zod");
// Helper function to get default values from environment variables
function getEnvDefault(envKey, defaultValue, transform) {
const envValue = process.env[envKey];
if (envValue === undefined) {
return defaultValue;
}
if (transform) {
try {
return transform(envValue);
}
catch (e) {
console.warn(`Warning: Invalid value for ${envKey}, using default value`);
return defaultValue;
}
}
return envValue;
}
// Base type definitions
exports.ChainSchema = zod_1.z.enum(['solana', 'ethereum', 'base', 'bsc', 'tron']);
exports.TradeTypeSchema = zod_1.z.enum(['buy', 'sell']);
// Take-profit/Stop-loss groups
exports.PnlGroupSchema = zod_1.z.object({
pricePercent: zod_1.z.number().min(0).max(10), // Price change percentage
amountPercent: zod_1.z.number().min(0).max(1), // Sell ratio
});
// Custom take-profit/stop-loss configuration
exports.PnlCustomConfigSchema = zod_1.z.object({
customFeeAndTip: zod_1.z.boolean().default(getEnvDefault('DBOT_CUSTOM_FEE_AND_TIP', false, (v) => v === 'true')),
priorityFee: zod_1.z.string().default(getEnvDefault('DBOT_PRIORITY_FEE', '0.0001')),
gasFeeDelta: zod_1.z.number().int().min(0).default(getEnvDefault('DBOT_GAS_FEE_DELTA', 5, Number)),
maxFeePerGas: zod_1.z.number().int().min(0).default(getEnvDefault('DBOT_MAX_FEE_PER_GAS', 100, Number)),
jitoEnabled: zod_1.z.boolean().default(getEnvDefault('DBOT_JITO_ENABLED', true, (v) => v === 'true')),
jitoTip: zod_1.z.number().min(0).default(getEnvDefault('DBOT_JITO_TIP', 0.001, Number)),
maxSlippage: zod_1.z.number().min(0).max(1).default(getEnvDefault('DBOT_MAX_SLIPPAGE', 0.1, Number)),
concurrentNodes: zod_1.z.number().int().min(1).max(3).default(getEnvDefault('DBOT_CONCURRENT_NODES', 2, Number)),
retries: zod_1.z.number().int().min(0).max(10).default(getEnvDefault('DBOT_RETRIES', 1, Number)),
});
// Fast swap request
exports.CreateFastSwapRequestSchema = zod_1.z.object({
chain: exports.ChainSchema.default(getEnvDefault('DBOT_CHAIN', 'solana')),
pair: zod_1.z.string().min(1),
walletId: zod_1.z.string().min(1),
type: exports.TradeTypeSchema,
customFeeAndTip: zod_1.z.boolean().default(getEnvDefault('DBOT_CUSTOM_FEE_AND_TIP', false, (v) => v === 'true')),
priorityFee: zod_1.z.string().default(getEnvDefault('DBOT_PRIORITY_FEE', '0.0001')),
gasFeeDelta: zod_1.z.number().int().min(0).default(getEnvDefault('DBOT_GAS_FEE_DELTA', 5, Number)),
maxFeePerGas: zod_1.z.number().int().min(0).default(getEnvDefault('DBOT_MAX_FEE_PER_GAS', 100, Number)),
jitoEnabled: zod_1.z.boolean().default(getEnvDefault('DBOT_JITO_ENABLED', true, (v) => v === 'true')),
jitoTip: zod_1.z.number().min(0).default(getEnvDefault('DBOT_JITO_TIP', 0.001, Number)),
maxSlippage: zod_1.z.number().min(0).max(1).default(getEnvDefault('DBOT_MAX_SLIPPAGE', 0.1, Number)),
concurrentNodes: zod_1.z.number().int().min(1).max(3).default(getEnvDefault('DBOT_CONCURRENT_NODES', 2, Number)),
retries: zod_1.z.number().int().min(0).max(10).default(getEnvDefault('DBOT_RETRIES', 1, Number)),
amountOrPercent: zod_1.z.number().min(0).default(getEnvDefault('DBOT_AMOUNT_OR_PERCENT', 0.001, Number)),
migrateSellPercent: zod_1.z.number().min(0).max(1).default(getEnvDefault('DBOT_MIGRATE_SELL_PERCENT', 1.0, Number)),
minDevSellPercent: zod_1.z.number().min(0).max(1).default(getEnvDefault('DBOT_MIN_DEV_SELL_PERCENT', 0.5, Number)),
devSellPercent: zod_1.z.number().min(0).max(1).default(getEnvDefault('DBOT_DEV_SELL_PERCENT', 1.0, Number)),
stopEarnPercent: zod_1.z.number().min(0).optional(),
stopLossPercent: zod_1.z.number().min(0).max(1).optional(),
stopEarnGroup: zod_1.z.array(exports.PnlGroupSchema).max(6).optional(),
stopLossGroup: zod_1.z.array(exports.PnlGroupSchema).max(6).optional(),
trailingStopGroup: zod_1.z.array(exports.PnlGroupSchema).max(1).optional(),
pnlOrderExpireDelta: zod_1.z.number().int().min(0).max(432000000).default(getEnvDefault('DBOT_PNL_ORDER_EXPIRE_DELTA', 43200000, Number)),
pnlOrderExpireExecute: zod_1.z.boolean().default(getEnvDefault('DBOT_PNL_ORDER_EXPIRE_EXECUTE', false, (v) => v === 'true')),
pnlOrderUseMidPrice: zod_1.z.boolean().default(getEnvDefault('DBOT_PNL_ORDER_USE_MID_PRICE', false, (v) => v === 'true')),
pnlCustomConfigEnabled: zod_1.z.boolean().default(getEnvDefault('DBOT_PNL_CUSTOM_CONFIG_ENABLED', true, (v) => v === 'true')),
pnlCustomConfig: exports.PnlCustomConfigSchema.optional(),
});
// Batch fast swap request
exports.CreateFastSwapsRequestSchema = zod_1.z.object({
chain: exports.ChainSchema.default('solana'),
pair: zod_1.z.string().min(1),
walletIdList: zod_1.z.array(zod_1.z.string()).max(5).min(1),
type: exports.TradeTypeSchema,
customFeeAndTip: zod_1.z.boolean().default(false),
priorityFee: zod_1.z.string().default(''),
gasFeeDelta: zod_1.z.number().int().min(0).default(5),
maxFeePerGas: zod_1.z.number().int().min(0).default(100),
jitoEnabled: zod_1.z.boolean().default(false),
jitoTip: zod_1.z.number().min(0).default(0.001),
maxSlippage: zod_1.z.number().min(0).max(1).default(0.1),
concurrentNodes: zod_1.z.number().int().min(1).max(3).default(2),
retries: zod_1.z.number().int().min(0).max(10).default(1),
minAmount: zod_1.z.number().min(0).optional(),
maxAmount: zod_1.z.number().min(0).optional(),
sellPercent: zod_1.z.number().min(0).max(1).default(1.0),
stopEarnPercent: zod_1.z.number().min(0).optional(),
stopLossPercent: zod_1.z.number().min(0).max(1).optional(),
stopEarnGroup: zod_1.z.array(exports.PnlGroupSchema).max(6).optional(),
stopLossGroup: zod_1.z.array(exports.PnlGroupSchema).max(6).optional(),
trailingStopGroup: zod_1.z.array(exports.PnlGroupSchema).max(1).optional(),
pnlOrderExpireDelta: zod_1.z.number().int().min(0).max(432000000).default(43200000),
pnlOrderExpireExecute: zod_1.z.boolean().default(false),
pnlOrderUseMidPrice: zod_1.z.boolean().default(false),
pnlCustomConfigEnabled: zod_1.z.boolean().default(true),
pnlCustomConfig: exports.PnlCustomConfigSchema.optional(),
});
// --- Limit Order Types ---
exports.TriggerDirectionSchema = zod_1.z.enum(['up', 'down']);
// Schema definition for limit order settings
exports.LimitOrderSettingSchema = zod_1.z.object({
enabled: zod_1.z.boolean().default(true),
tradeType: exports.TradeTypeSchema,
triggerPriceUsd: zod_1.z.string(),
triggerDirection: exports.TriggerDirectionSchema,
currencyAmountUI: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]),
customFeeAndTip: zod_1.z.boolean().default(getEnvDefault('DBOT_CUSTOM_FEE_AND_TIP', false, (v) => v === 'true')),
priorityFee: zod_1.z.string().default(getEnvDefault('DBOT_PRIORITY_FEE', '0.0001')),
gasFeeDelta: zod_1.z.number().int().min(0).default(getEnvDefault('DBOT_GAS_FEE_DELTA', 5, Number)),
maxFeePerGas: zod_1.z.number().int().min(0).default(getEnvDefault('DBOT_MAX_FEE_PER_GAS', 100, Number)),
jitoEnabled: zod_1.z.boolean().default(getEnvDefault('DBOT_JITO_ENABLED', true, (v) => v === 'true')),
jitoTip: zod_1.z.number().min(0).default(getEnvDefault('DBOT_JITO_TIP', 0.001, Number)),
expireDelta: zod_1.z.number().int().min(0).max(432000000).default(getEnvDefault('DBOT_PNL_ORDER_EXPIRE_DELTA', 360000000, Number)),
expireExecute: zod_1.z.boolean().default(getEnvDefault('DBOT_PNL_ORDER_EXPIRE_EXECUTE', false, (v) => v === 'true')),
useMidPrice: zod_1.z.boolean().default(getEnvDefault('DBOT_PNL_ORDER_USE_MID_PRICE', false, (v) => v === 'true')),
maxSlippage: zod_1.z.number().min(0).max(1).default(getEnvDefault('DBOT_MAX_SLIPPAGE', 0.1, Number)),
concurrentNodes: zod_1.z.number().int().min(1).max(3).default(getEnvDefault('DBOT_CONCURRENT_NODES', 2, Number)),
retries: zod_1.z.number().int().min(0).max(10).default(getEnvDefault('DBOT_RETRIES', 1, Number))
});
// Schema definition for create limit order request
exports.CreateLimitOrdersRequestSchema = zod_1.z.object({
chain: exports.ChainSchema.default(getEnvDefault('DBOT_CHAIN', 'solana')),
pair: zod_1.z.string().min(1),
walletId: zod_1.z.string().min(1).optional(),
groupId: zod_1.z.string(),
settings: zod_1.z.array(exports.LimitOrderSettingSchema)
});
/**
* Get wallet ID based on chain
*/
function getWalletIdByChain(chain) {
const chainUpperCase = chain.toUpperCase();
// Check specific chain first
const specificWalletId = process.env[`DBOT_WALLET_ID_${chainUpperCase}`];
if (specificWalletId) {
return specificWalletId;
}
// Fall back to generic chain type
let fallbackKey = '';
switch (chain) {
case 'solana':
fallbackKey = 'DBOT_WALLET_ID_SOLANA';
break;
case 'ethereum':
case 'base':
case 'bsc':
fallbackKey = 'DBOT_WALLET_ID_EVM';
break;
case 'tron':
fallbackKey = 'DBOT_WALLET_ID_TRON';
break;
default:
fallbackKey = 'DBOT_WALLET_ID_EVM';
}
const fallbackWalletId = process.env[fallbackKey];
if (fallbackWalletId) {
return fallbackWalletId;
}
throw new Error(`No wallet ID configured for chain ${chain}. Please configure at least one of the following environment variables: DBOT_WALLET_ID_SOLANA, DBOT_WALLET_ID_EVM, DBOT_WALLET_ID_TRON, DBOT_WALLET_ID_BASE, DBOT_WALLET_ID_ARBITRUM, DBOT_WALLET_ID_BSC`);
}
/**
* Check if at least one wallet ID is configured
*/
function validateWalletIdConfig() {
const requiredEnvVars = [
'DBOT_WALLET_ID_SOLANA',
'DBOT_WALLET_ID_EVM',
'DBOT_WALLET_ID_TRON',
'DBOT_WALLET_ID_BASE',
'DBOT_WALLET_ID_ARBITRUM',
'DBOT_WALLET_ID_BSC'
];
const hasAtLeastOne = requiredEnvVars.some(envVar => process.env[envVar]);
if (!hasAtLeastOne) {
throw new Error(`At least one wallet ID must be configured. Please set one of the following environment variables: ${requiredEnvVars.join(', ')}`);
}
}
//# sourceMappingURL=types.js.map