UNPKG

@drift-labs/common

Version:

Common functions for Drift

68 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getHeliusPriorityFeeEstimate = exports.getPriorityFeeLevelFromPercentile = void 0; const FEE_ENDPOINT = 'https://dlob.drift.trade/batchPriorityFees'; const getPriorityFeeLevelFromPercentile = (percentile) => { if (percentile < 0 || percentile > 100) { throw new Error('Percentile must be between 0 and 100'); } if (percentile === 0) { return 'min'; } if (percentile <= 25) { return 'low'; } if (percentile <= 50) { return 'medium'; } if (percentile <= 75) { return 'high'; } if (percentile <= 95) { return 'veryHigh'; } return 'unsafeMax'; }; exports.getPriorityFeeLevelFromPercentile = getPriorityFeeLevelFromPercentile; /** * Helius fee buckets are as follows: * * none: 0th percentile * low: 25th percentile * medium: 50th percentile * high: 75th percentile * veryHigh: 95th percentile * unsafeMax: 100th percentile * default: 50th percentile */ const getHeliusPriorityFeeEstimate = async (marketIds, priorityFeeLevel = 'high') => { try { if (!(marketIds === null || marketIds === void 0 ? void 0 : marketIds.length)) { return []; } const queryParamsMap = { marketType: marketIds.map((market) => market.marketTypeStr).join(','), marketIndex: marketIds.map((market) => market.marketIndex).join(','), }; const queryParams = Object.entries(queryParamsMap) .filter(([_key, param]) => param !== undefined) .map(([key, param]) => { return `${key}=${param}`; }); const queryParamsString = `${queryParams.join('&')}`; const response = await fetch(`${FEE_ENDPOINT}?${queryParamsString}`, { headers: { 'Content-Type': 'application/json' }, }); const result = (await response.json()); if (!response.ok) { return undefined; } const feeLevelValues = result.map((result) => result === null || result === void 0 ? void 0 : result[priorityFeeLevel]); return feeLevelValues; } catch (e) { return undefined; } }; exports.getHeliusPriorityFeeEstimate = getHeliusPriorityFeeEstimate; //# sourceMappingURL=priorityFees.js.map