"use strict";
/**
 * MYX Protocol Configuration Constants
 *
 * Stage 1 configuration for market display and price fetching.
 * Based on MYX SDK patterns but simplified for read-only operations.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.MYX_MAX_RETRIES = exports.MYX_HTTP_TIMEOUT_MS = exports.MYX_PRICE_POLLING_INTERVAL_MS = exports.fromMYXCollateral = exports.toMYXSize = exports.fromMYXSize = exports.toMYXPrice = exports.fromMYXPrice = exports.MYX_ASSET_CONFIGS = exports.USDT_BNB_MAINNET = exports.USDT_BNB_TESTNET = exports.MYX_COLLATERAL_DECIMALS = exports.MYX_SIZE_DECIMALS = exports.MYX_PRICE_DECIMALS = exports.getMYXHttpEndpoint = exports.MYX_ENDPOINTS = exports.getMYXChainId = exports.BNB_TESTNET_CAIP_CHAIN_ID = exports.BNB_MAINNET_CAIP_CHAIN_ID = exports.BNB_TESTNET_CHAIN_ID = exports.BNB_MAINNET_CHAIN_ID = void 0;
const bignumber_js_1 = require("bignumber.js");
// ============================================================================
// Network Constants
// ============================================================================
/**
 * BNB Chain IDs - MYX's primary network
 */
exports.BNB_MAINNET_CHAIN_ID = '56';
exports.BNB_TESTNET_CHAIN_ID = '97';
exports.BNB_MAINNET_CAIP_CHAIN_ID = `eip155:${exports.BNB_MAINNET_CHAIN_ID}`;
exports.BNB_TESTNET_CAIP_CHAIN_ID = `eip155:${exports.BNB_TESTNET_CHAIN_ID}`;
/**
 * Get numeric chain ID for MYX network
 *
 * @param network - The MYX network environment (mainnet or testnet).
 * @returns The numeric chain ID for the specified network.
 */
function getMYXChainId(network) {
    return network === 'testnet'
        ? parseInt(exports.BNB_TESTNET_CHAIN_ID, 10)
        : parseInt(exports.BNB_MAINNET_CHAIN_ID, 10);
}
exports.getMYXChainId = getMYXChainId;
// ============================================================================
// API Endpoints
// ============================================================================
/**
 * MYX REST and WebSocket endpoints
 */
exports.MYX_ENDPOINTS = {
    mainnet: {
        http: 'https://api.myx.finance',
        ws: 'wss://ws.myx.finance',
    },
    testnet: {
        http: 'https://api-beta.myx.finance',
        ws: 'wss://ws-beta.myx.finance',
    },
};
/**
 * Get HTTP endpoint for network
 *
 * @param network - The MYX network environment (mainnet or testnet).
 * @returns The HTTP API endpoint URL for the specified network.
 */
function getMYXHttpEndpoint(network) {
    return exports.MYX_ENDPOINTS[network].http;
}
exports.getMYXHttpEndpoint = getMYXHttpEndpoint;
// ============================================================================
// Decimal Constants
// ============================================================================
/**
 * MYX uses 30 decimals for price representation
 * This is consistent with the SDK's internal format
 */
exports.MYX_PRICE_DECIMALS = 30;
/**
 * MYX uses 18 decimals for position sizes
 */
exports.MYX_SIZE_DECIMALS = 18;
/**
 * MYX uses 18 decimals for collateral amounts (USDT on BNB)
 */
exports.MYX_COLLATERAL_DECIMALS = 18;
// ============================================================================
// Token Addresses
// ============================================================================
/**
 * USDT token address on BNB testnet
 */
exports.USDT_BNB_TESTNET = '0x337610d27c682e347c9cd60bd4b3b107c9d34ddd';
/**
 * USDT token address on BNB mainnet
 */
exports.USDT_BNB_MAINNET = '0x55d398326f99059ff775485246999027b3197955';
/**
 * USDT configuration by network
 */
exports.MYX_ASSET_CONFIGS = {
    USDT: {
        mainnet: {
            chainId: exports.BNB_MAINNET_CAIP_CHAIN_ID,
            tokenAddress: exports.USDT_BNB_MAINNET,
        },
        testnet: {
            chainId: exports.BNB_TESTNET_CAIP_CHAIN_ID,
            tokenAddress: exports.USDT_BNB_TESTNET,
        },
    },
};
// ============================================================================
// Decimal Conversion Helpers
// ============================================================================
/**
 * Convert MYX SDK price (30 decimals) to standard number
 *
 * @param myxPrice - Price string in 30-decimal format from SDK
 * @returns Standard decimal number
 */
function fromMYXPrice(myxPrice) {
    if (!myxPrice || myxPrice === '0') {
        return 0;
    }
    try {
        const bn = new bignumber_js_1.BigNumber(myxPrice);
        if (bn.isNaN()) {
            return 0;
        }
        const divisor = new bignumber_js_1.BigNumber(10).pow(exports.MYX_PRICE_DECIMALS);
        return bn.dividedBy(divisor).toNumber();
    }
    catch {
        return 0;
    }
}
exports.fromMYXPrice = fromMYXPrice;
/**
 * Convert standard number to MYX SDK price format (30 decimals)
 *
 * @param price - Standard decimal number
 * @returns Price string in 30-decimal format for SDK
 */
function toMYXPrice(price) {
    try {
        const bn = new bignumber_js_1.BigNumber(price);
        if (bn.isNaN()) {
            return '0';
        }
        const multiplier = new bignumber_js_1.BigNumber(10).pow(exports.MYX_PRICE_DECIMALS);
        return bn.multipliedBy(multiplier).toFixed(0);
    }
    catch {
        return '0';
    }
}
exports.toMYXPrice = toMYXPrice;
/**
 * Convert MYX SDK size (18 decimals) to standard number
 *
 * @param myxSize - Size string in 18-decimal format from SDK
 * @returns Standard decimal number
 */
function fromMYXSize(myxSize) {
    if (!myxSize || myxSize === '0') {
        return 0;
    }
    try {
        const bn = new bignumber_js_1.BigNumber(myxSize);
        if (bn.isNaN()) {
            return 0;
        }
        const divisor = new bignumber_js_1.BigNumber(10).pow(exports.MYX_SIZE_DECIMALS);
        return bn.dividedBy(divisor).toNumber();
    }
    catch {
        return 0;
    }
}
exports.fromMYXSize = fromMYXSize;
/**
 * Convert standard number to MYX SDK size format (18 decimals)
 *
 * @param size - Standard decimal number
 * @returns Size string in 18-decimal format for SDK
 */
function toMYXSize(size) {
    try {
        const bn = new bignumber_js_1.BigNumber(size);
        if (bn.isNaN()) {
            return '0';
        }
        const multiplier = new bignumber_js_1.BigNumber(10).pow(exports.MYX_SIZE_DECIMALS);
        return bn.multipliedBy(multiplier).toFixed(0);
    }
    catch {
        return '0';
    }
}
exports.toMYXSize = toMYXSize;
/**
 * Convert MYX SDK collateral (18 decimals) to standard number
 *
 * @param myxCollateral - Collateral string in 18-decimal format from SDK
 * @returns Standard decimal number
 */
function fromMYXCollateral(myxCollateral) {
    if (!myxCollateral || myxCollateral === '0') {
        return 0;
    }
    try {
        const bn = new bignumber_js_1.BigNumber(myxCollateral);
        if (bn.isNaN()) {
            return 0;
        }
        const divisor = new bignumber_js_1.BigNumber(10).pow(exports.MYX_COLLATERAL_DECIMALS);
        return bn.dividedBy(divisor).toNumber();
    }
    catch {
        return 0;
    }
}
exports.fromMYXCollateral = fromMYXCollateral;
// ============================================================================
// REST API Configuration
// ============================================================================
/**
 * Price polling interval in milliseconds
 * Using 5 seconds as a fallback for unreliable WebSocket
 */
exports.MYX_PRICE_POLLING_INTERVAL_MS = 5000;
/**
 * HTTP request timeout in milliseconds
 */
exports.MYX_HTTP_TIMEOUT_MS = 10000;
/**
 * Maximum retries for failed API requests
 */
exports.MYX_MAX_RETRIES = 3;
//# sourceMappingURL=myxConfig.cjs.map