init
This commit is contained in:
commit
ff04c88444
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 12,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"@typescript-eslint/no-non-null-assertion": 0,
|
||||
"@typescript-eslint/ban-ts-comment": 0,
|
||||
"@typescript-eslint/no-explicit-any": 0,
|
||||
"@typescript-eslint/explicit-function-return-type": "warn"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"prettier"
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 12,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"@typescript-eslint/no-non-null-assertion": 0,
|
||||
"@typescript-eslint/ban-ts-comment": 0,
|
||||
"@typescript-eslint/no-explicit-any": 0,
|
||||
"@typescript-eslint/explicit-function-return-type": "warn"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
.serverless/
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
.env
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# TradingView
|
||||
public/charting_library
|
||||
public/datafeeds
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# local env files
|
||||
.env*.local
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
tsconfig.tsbuildinfo
|
||||
|
||||
# Sentry Auth Token
|
||||
.sentryclirc
|
|
@ -0,0 +1 @@
|
|||
ts/client/src/mango_v4.ts
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
transform: {
|
||||
"^.+\\.(t|j)s$": "ts-jest",
|
||||
},
|
||||
moduleFileExtensions: ["ts", "js", "json", "node"],
|
||||
};
|
|
@ -0,0 +1,161 @@
|
|||
declare const PREMIUM_LISTING: {
|
||||
maxStalenessSlots: number | null;
|
||||
oracleConfFilter: number;
|
||||
adjustmentFactor: number;
|
||||
util0: number;
|
||||
rate0: number;
|
||||
util1: number;
|
||||
rate1: number;
|
||||
maxRate: number;
|
||||
loanFeeRate: number;
|
||||
loanOriginationFeeRate: number;
|
||||
maintAssetWeight: number;
|
||||
initAssetWeight: number;
|
||||
maintLiabWeight: number;
|
||||
initLiabWeight: number;
|
||||
liquidationFee: number;
|
||||
minVaultToDepositsRatio: number;
|
||||
netBorrowLimitWindowSizeTs: number;
|
||||
netBorrowLimitPerWindowQuote: number;
|
||||
insuranceFound: boolean;
|
||||
borrowWeightScale: number;
|
||||
depositWeightScale: number;
|
||||
preset_key: string;
|
||||
preset_name: string;
|
||||
preset_target_amount: number;
|
||||
};
|
||||
export type ListingPreset = typeof PREMIUM_LISTING;
|
||||
export type LISTING_PRESETS_KEYS = "PREMIUM" | "MID" | "MEME" | "SHIT" | "UNTRUSTED";
|
||||
export declare const LISTING_PRESETS: {
|
||||
[key in LISTING_PRESETS_KEYS]: ListingPreset | Record<string, never>;
|
||||
};
|
||||
export declare const LISTING_PRESETS_PYTH: {
|
||||
PREMIUM: {
|
||||
maxStalenessSlots: number;
|
||||
oracleConfFilter: number;
|
||||
adjustmentFactor: number;
|
||||
util0: number;
|
||||
rate0: number;
|
||||
util1: number;
|
||||
rate1: number;
|
||||
maxRate: number;
|
||||
loanFeeRate: number;
|
||||
loanOriginationFeeRate: number;
|
||||
maintAssetWeight: number;
|
||||
initAssetWeight: number;
|
||||
maintLiabWeight: number;
|
||||
initLiabWeight: number;
|
||||
liquidationFee: number;
|
||||
minVaultToDepositsRatio: number;
|
||||
netBorrowLimitWindowSizeTs: number;
|
||||
netBorrowLimitPerWindowQuote: number;
|
||||
insuranceFound: boolean;
|
||||
borrowWeightScale: number;
|
||||
depositWeightScale: number;
|
||||
preset_key: string;
|
||||
preset_name: string;
|
||||
preset_target_amount: number;
|
||||
} | {
|
||||
maxStalenessSlots: number;
|
||||
};
|
||||
MID: {
|
||||
maxStalenessSlots: number;
|
||||
oracleConfFilter: number;
|
||||
adjustmentFactor: number;
|
||||
util0: number;
|
||||
rate0: number;
|
||||
util1: number;
|
||||
rate1: number;
|
||||
maxRate: number;
|
||||
loanFeeRate: number;
|
||||
loanOriginationFeeRate: number;
|
||||
maintAssetWeight: number;
|
||||
initAssetWeight: number;
|
||||
maintLiabWeight: number;
|
||||
initLiabWeight: number;
|
||||
liquidationFee: number;
|
||||
minVaultToDepositsRatio: number;
|
||||
netBorrowLimitWindowSizeTs: number;
|
||||
netBorrowLimitPerWindowQuote: number;
|
||||
insuranceFound: boolean;
|
||||
borrowWeightScale: number;
|
||||
depositWeightScale: number;
|
||||
preset_key: string;
|
||||
preset_name: string;
|
||||
preset_target_amount: number;
|
||||
} | {
|
||||
maxStalenessSlots: number;
|
||||
};
|
||||
MEME: {
|
||||
maxStalenessSlots: number;
|
||||
oracleConfFilter: number;
|
||||
adjustmentFactor: number;
|
||||
util0: number;
|
||||
rate0: number;
|
||||
util1: number;
|
||||
rate1: number;
|
||||
maxRate: number;
|
||||
loanFeeRate: number;
|
||||
loanOriginationFeeRate: number;
|
||||
maintAssetWeight: number;
|
||||
initAssetWeight: number;
|
||||
maintLiabWeight: number;
|
||||
initLiabWeight: number;
|
||||
liquidationFee: number;
|
||||
minVaultToDepositsRatio: number;
|
||||
netBorrowLimitWindowSizeTs: number;
|
||||
netBorrowLimitPerWindowQuote: number;
|
||||
insuranceFound: boolean;
|
||||
borrowWeightScale: number;
|
||||
depositWeightScale: number;
|
||||
preset_key: string;
|
||||
preset_name: string;
|
||||
preset_target_amount: number;
|
||||
} | {
|
||||
maxStalenessSlots: number;
|
||||
};
|
||||
SHIT: {
|
||||
maxStalenessSlots: number;
|
||||
oracleConfFilter: number;
|
||||
adjustmentFactor: number;
|
||||
util0: number;
|
||||
rate0: number;
|
||||
util1: number;
|
||||
rate1: number;
|
||||
maxRate: number;
|
||||
loanFeeRate: number;
|
||||
loanOriginationFeeRate: number;
|
||||
maintAssetWeight: number;
|
||||
initAssetWeight: number;
|
||||
maintLiabWeight: number;
|
||||
initLiabWeight: number;
|
||||
liquidationFee: number;
|
||||
minVaultToDepositsRatio: number;
|
||||
netBorrowLimitWindowSizeTs: number;
|
||||
netBorrowLimitPerWindowQuote: number;
|
||||
insuranceFound: boolean;
|
||||
borrowWeightScale: number;
|
||||
depositWeightScale: number;
|
||||
preset_key: string;
|
||||
preset_name: string;
|
||||
preset_target_amount: number;
|
||||
} | {
|
||||
maxStalenessSlots: number;
|
||||
};
|
||||
UNTRUSTED: {};
|
||||
};
|
||||
export type MarketTradingParams = {
|
||||
baseLots: number;
|
||||
quoteLots: number;
|
||||
minOrderValue: number;
|
||||
baseLotExponent: number;
|
||||
quoteLotExponent: number;
|
||||
minOrderSize: number;
|
||||
priceIncrement: number;
|
||||
priceIncrementRelative: number;
|
||||
};
|
||||
export declare const calculateMarketTradingParams: (basePrice: number, quotePrice: number, baseDecimals: number, quoteDecimals: number) => MarketTradingParams;
|
||||
export declare const coinTiersToNames: {
|
||||
[key in LISTING_PRESETS_KEYS]: string;
|
||||
};
|
||||
export {};
|
|
@ -0,0 +1,133 @@
|
|||
"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",
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
/// <reference types="node" />
|
||||
import crypto from 'node:crypto';
|
||||
export declare class Uuid {
|
||||
v4(options?: crypto.RandomUUIDOptions | undefined): string;
|
||||
}
|
||||
declare const _default: Uuid;
|
||||
export default _default;
|
|
@ -0,0 +1,14 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Uuid = void 0;
|
||||
const node_crypto_1 = __importDefault(require("node:crypto"));
|
||||
class Uuid {
|
||||
v4(options) {
|
||||
return node_crypto_1.default.randomUUID(options);
|
||||
}
|
||||
}
|
||||
exports.Uuid = Uuid;
|
||||
exports.default = new Uuid();
|
|
@ -0,0 +1,2 @@
|
|||
import * as listingTools from "./helpers/listingTools";
|
||||
export default listingTools;
|
|
@ -0,0 +1,27 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const listingTools = __importStar(require("./helpers/listingTools"));
|
||||
exports.default = listingTools;
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"name": "@blockworks-foundation/mango-v4-settings",
|
||||
"version": "0.2.5",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "prettier --write \"src/**/*.(js|ts)\"",
|
||||
"lint": "eslint src --ext .js,.ts",
|
||||
"lint:fix": "eslint src --fix --ext .js,.ts",
|
||||
"test": "jest --config jest.config.js",
|
||||
"prepare": "npm run build",
|
||||
"prepublishOnly": "npm run lint",
|
||||
"preversion": "npm run lint",
|
||||
"version": "npm run format && git add -A src",
|
||||
"postversion": "git push && git push --tags"
|
||||
},
|
||||
"keywords": [
|
||||
"boilerplate",
|
||||
"typescript"
|
||||
],
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/bn.js": "^5.1.1",
|
||||
"@types/jest": "29.4.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.54.0",
|
||||
"@typescript-eslint/parser": "5.52.0",
|
||||
"eslint": "8.35.0",
|
||||
"eslint-plugin-jest": "27.2.1",
|
||||
"jest": "29.4.3",
|
||||
"prettier": "^3.0.1",
|
||||
"ts-jest": "29.0.5",
|
||||
"typescript": "4.9.5"
|
||||
},
|
||||
"files": [
|
||||
"lib/**/*"
|
||||
],
|
||||
"dependencies": {
|
||||
"bn.js": "^5.2.1",
|
||||
"eslint-config-prettier": "^9.0.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,239 @@
|
|||
import BN from "bn.js";
|
||||
|
||||
const PREMIUM_LISTING = {
|
||||
maxStalenessSlots: 10000 as number | null,
|
||||
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,
|
||||
};
|
||||
|
||||
export type ListingPreset = typeof PREMIUM_LISTING;
|
||||
|
||||
export type LISTING_PRESETS_KEYS =
|
||||
| "PREMIUM"
|
||||
| "MID"
|
||||
| "MEME"
|
||||
| "SHIT"
|
||||
| "UNTRUSTED";
|
||||
|
||||
export const LISTING_PRESETS: {
|
||||
[key in LISTING_PRESETS_KEYS]: ListingPreset | Record<string, never>;
|
||||
} = {
|
||||
//Price impact on $100,000 swap lower then 1%
|
||||
PREMIUM: {
|
||||
...PREMIUM_LISTING,
|
||||
},
|
||||
//Price impact on $20,000 swap lower then 1%
|
||||
MID: {
|
||||
...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: {
|
||||
...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: {
|
||||
...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: {},
|
||||
};
|
||||
|
||||
export const LISTING_PRESETS_PYTH = {
|
||||
PREMIUM: {
|
||||
...LISTING_PRESETS.PREMIUM,
|
||||
maxStalenessSlots: 250,
|
||||
},
|
||||
MID: {
|
||||
...LISTING_PRESETS.MID,
|
||||
maxStalenessSlots: 250,
|
||||
},
|
||||
MEME: {
|
||||
...LISTING_PRESETS.MEME,
|
||||
maxStalenessSlots: 250,
|
||||
},
|
||||
SHIT: {
|
||||
...LISTING_PRESETS.SHIT,
|
||||
maxStalenessSlots: 250,
|
||||
},
|
||||
UNTRUSTED: {},
|
||||
};
|
||||
|
||||
export type MarketTradingParams = {
|
||||
baseLots: number;
|
||||
quoteLots: number;
|
||||
minOrderValue: number;
|
||||
baseLotExponent: number;
|
||||
quoteLotExponent: number;
|
||||
minOrderSize: number;
|
||||
priceIncrement: number;
|
||||
priceIncrementRelative: number;
|
||||
};
|
||||
|
||||
// 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;
|
||||
export const calculateMarketTradingParams = (
|
||||
basePrice: number,
|
||||
quotePrice: number,
|
||||
baseDecimals: number,
|
||||
quoteDecimals: number
|
||||
): MarketTradingParams => {
|
||||
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,
|
||||
};
|
||||
};
|
||||
|
||||
function toNative(uiAmount: number, decimals: number): BN {
|
||||
return new BN((uiAmount * Math.pow(10, decimals)).toFixed(0));
|
||||
}
|
||||
|
||||
export const coinTiersToNames: {
|
||||
[key in LISTING_PRESETS_KEYS]: string;
|
||||
} = {
|
||||
PREMIUM: "Blue Chip",
|
||||
MID: "Mid-wit",
|
||||
MEME: "Meme",
|
||||
SHIT: "Shit Coin",
|
||||
UNTRUSTED: "Untrusted",
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
import * as listingTools from "./helpers/listingTools";
|
||||
|
||||
export default listingTools;
|
|
@ -0,0 +1,71 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
"declaration": true /* Generates corresponding '.d.ts' file. */,
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./lib" /* Redirect output structure to the directory. */,
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true /* Skip type checking of declaration files. */,
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "**/__tests__/*"]
|
||||
}
|
Loading…
Reference in New Issue