mango-v4-settings/lib/helpers/listingTools.js

134 lines
6.6 KiB
JavaScript
Raw Normal View History

2023-08-10 09:07:36 -07:00
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.coinTiersToNames = exports.calculateMarketTradingParams = exports.LISTING_PRESETS_PYTH = exports.LISTING_PRESETS = void 0;
const bn_js_1 = __importDefault(require("bn.js"));
const PREMIUM_LISTING = {
maxStalenessSlots: 10000,
oracleConfFilter: 0.1,
adjustmentFactor: 0.004,
util0: 0.5,
rate0: 0.052,
util1: 0.8,
rate1: 0.1446,
maxRate: 1.4456,
loanFeeRate: 0.005,
loanOriginationFeeRate: 0.001,
maintAssetWeight: 0.9,
initAssetWeight: 0.8,
maintLiabWeight: 1.1,
initLiabWeight: 1.2,
liquidationFee: 0.05,
minVaultToDepositsRatio: 0.2,
netBorrowLimitWindowSizeTs: 24 * 60 * 60,
netBorrowLimitPerWindowQuote: toNative(50000, 6).toNumber(),
insuranceFound: true,
borrowWeightScale: toNative(250000, 6).toNumber(),
depositWeightScale: toNative(250000, 6).toNumber(),
preset_key: "PREMIUM",
preset_name: "Blue chip",
preset_target_amount: 100000,
};
exports.LISTING_PRESETS = {
//Price impact on $100,000 swap lower then 1%
PREMIUM: Object.assign({}, PREMIUM_LISTING),
//Price impact on $20,000 swap lower then 1%
MID: Object.assign(Object.assign({}, PREMIUM_LISTING), { maintAssetWeight: 0.75, initAssetWeight: 0.5, maintLiabWeight: 1.2, initLiabWeight: 1.4, liquidationFee: 0.1, netBorrowLimitPerWindowQuote: toNative(20000, 6).toNumber(), borrowWeightScale: toNative(50000, 6).toNumber(), depositWeightScale: toNative(50000, 6).toNumber(), insuranceFound: false, preset_name: "Midwit", preset_key: "MID", preset_target_amount: 20000 }),
//Price impact on $5,000 swap lower then 1%
MEME: Object.assign(Object.assign({}, PREMIUM_LISTING), { maxStalenessSlots: 800, loanOriginationFeeRate: 0.002, maintAssetWeight: 0, initAssetWeight: 0, maintLiabWeight: 1.25, initLiabWeight: 1.5, liquidationFee: 0.125, netBorrowLimitPerWindowQuote: toNative(5000, 6).toNumber(), borrowWeightScale: toNative(20000, 6).toNumber(), depositWeightScale: toNative(20000, 6).toNumber(), insuranceFound: false, preset_name: "Meme Coin", preset_key: "MEME", preset_target_amount: 5000 }),
//Price impact on $1,000 swap lower then 1%
SHIT: Object.assign(Object.assign({}, PREMIUM_LISTING), { maxStalenessSlots: 800, loanOriginationFeeRate: 0.002, maintAssetWeight: 0, initAssetWeight: 0, maintLiabWeight: 1.4, initLiabWeight: 1.8, liquidationFee: 0.2, netBorrowLimitPerWindowQuote: toNative(1000, 6).toNumber(), borrowWeightScale: toNative(5000, 6).toNumber(), depositWeightScale: toNative(5000, 6).toNumber(), insuranceFound: false, preset_name: "Shit Coin", preset_key: "SHIT", preset_target_amount: 1000 }),
//should run untrusted instruction
UNTRUSTED: {},
};
exports.LISTING_PRESETS_PYTH = {
PREMIUM: Object.assign(Object.assign({}, exports.LISTING_PRESETS.PREMIUM), { maxStalenessSlots: 250 }),
MID: Object.assign(Object.assign({}, exports.LISTING_PRESETS.MID), { maxStalenessSlots: 250 }),
MEME: Object.assign(Object.assign({}, exports.LISTING_PRESETS.MEME), { maxStalenessSlots: 250 }),
SHIT: Object.assign(Object.assign({}, exports.LISTING_PRESETS.SHIT), { maxStalenessSlots: 250 }),
UNTRUSTED: {},
};
// definitions:
// baseLots = 10 ^ baseLotExponent
// quoteLots = 10 ^ quoteLotExponent
// minOrderSize = 10^(baseLotExponent - baseDecimals)
// minOrderValue = basePrice * minOrderSize
// priceIncrement = 10^(quoteLotExponent + baseDecimals - baseLotExponent - quoteDecimals)
// priceIncrementRelative = priceIncrement * quotePrice / basePrice
// derive: baseLotExponent <= min[ basePrice * minOrderSize > 0.05]
// baseLotExponent = 10
// While (baseLotExponent < 10):
// minOrderSize = 10^(baseLotExponent - baseDecimals)
// minOrderValue = basePrice * minOrderSize
// if minOrderValue > 0.05:
// break;
// Derive: quoteLotExponent <= min[ priceIncrement * quotePrice / basePrice > 0.000025 ]
// quoteLotExponent = 0
// While (quoteLotExponent < 10):
// priceIncrement = 10^(quoteLotExponent + baseDecimals - baseLotExponent - quoteDecimals)
// priceIncrementRelative = priceIncrement * quotePrice / basePrice
// if priceIncrementRelative > 0.000025:
// break;
const calculateMarketTradingParams = (basePrice, quotePrice, baseDecimals, quoteDecimals) => {
const MAX_MIN_ORDER_VALUE = 0.05;
const MIN_PRICE_INCREMENT_RELATIVE = 0.000025;
const EXPONENT_THRESHOLD = 10;
let minOrderSize = 0;
let priceIncrement = 0;
let baseLotExponent = 0;
let quoteLotExponent = 0;
let minOrderValue = 0;
let priceIncrementRelative = 0;
// Calculate minimum order size
do {
minOrderSize = Math.pow(10, baseLotExponent - baseDecimals);
minOrderValue = basePrice * minOrderSize;
if (minOrderValue > MAX_MIN_ORDER_VALUE) {
break;
}
baseLotExponent++;
} while (baseLotExponent < EXPONENT_THRESHOLD);
// Calculate price increment
do {
priceIncrement = Math.pow(10, quoteLotExponent + baseDecimals - baseLotExponent - quoteDecimals);
priceIncrementRelative = (priceIncrement * quotePrice) / basePrice;
if (priceIncrementRelative > MIN_PRICE_INCREMENT_RELATIVE) {
break;
}
quoteLotExponent++;
} while (quoteLotExponent < EXPONENT_THRESHOLD);
//exception override values in that case example eth/btc market
if (quoteLotExponent === 0 &&
priceIncrementRelative > 0.001 &&
minOrderSize < 1) {
baseLotExponent = baseLotExponent + 1;
minOrderSize = Math.pow(10, baseLotExponent - baseDecimals);
minOrderValue = basePrice * minOrderSize;
priceIncrement = Math.pow(10, quoteLotExponent + baseDecimals - baseLotExponent - quoteDecimals);
priceIncrementRelative = (priceIncrement * quotePrice) / basePrice;
}
return {
baseLots: Math.pow(10, baseLotExponent),
quoteLots: Math.pow(10, quoteLotExponent),
minOrderValue: minOrderValue,
baseLotExponent: baseLotExponent,
quoteLotExponent: quoteLotExponent,
minOrderSize: minOrderSize,
priceIncrement: priceIncrement,
priceIncrementRelative: priceIncrementRelative,
};
};
exports.calculateMarketTradingParams = calculateMarketTradingParams;
function toNative(uiAmount, decimals) {
return new bn_js_1.default((uiAmount * Math.pow(10, decimals)).toFixed(0));
}
exports.coinTiersToNames = {
PREMIUM: "Blue Chip",
MID: "Mid-wit",
MEME: "Meme",
SHIT: "Shit Coin",
UNTRUSTED: "Untrusted",
};