UNPKG

@prism-hq/prism-ag

Version:

Prism Aggregator

102 lines (101 loc) 6.32 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadLiquidityProviders = exports.getCacheData = void 0; const axios_1 = __importDefault(require("axios")); const orca_1 = require("./orca"); // import { getPhoenixCacheData, getPhoenixMarkets } from "./phoenix"; const raydium_1 = require("./raydium"); const raydiumCLMM_1 = require("./raydiumCLMM"); const saber_1 = require("./saber"); // import { getSymmetryFunds } from "./symmetry"; // import { getSymmetryCacheData, getSymmetryFunds } from "./symmetry"; const whirlpools_1 = require("./whirlpools"); function getCacheData(connection) { return __awaiter(this, void 0, void 0, function* () { let cacheData1 = {}; let cacheData2 = {}; let cacheData3 = {}; yield Promise.all([ // getCropperCacheData(connection).then(res => cacheData1.cropper = res), // getMercurialCacheData(connection).then(res => cacheData1.mercurial = res), // getPenguinCacheData(connection).then(res => cacheData1.penguin = res), (0, raydium_1.getRaydiumCacheData)(connection).then(res => { cacheData1.raydium = res.cache1; cacheData2.raydium = res.cache2; cacheData3.raydium = res.cache3; }), (0, saber_1.getSaberCacheData)(connection).then(res => cacheData1.saber = res), // getSarosCacheData(connection).then(res => cacheData1.saros = res), // getSenchaCacheData(connection).then(res => cacheData1.sencha = res), // getStepCacheData(connection).then(res => cacheData1.step = res), // getSymmetryCacheData(connection).then(res =>cacheData1.symmetry = res), // getAldrinCacheData(connection).then(res => cacheData1.aldrin = res), // getOpenbookCacheData(connection).then(res => cacheData2.openbook = res), // getBalansolCacheData(connection).then(res => cacheData1.balansol = res), (0, whirlpools_1.getWhirlpoolsCacheData)(connection).then(res => cacheData3.whirlpools = res), (0, raydiumCLMM_1.getRaydiumClmmCacheData)(connection).then(res => cacheData3.raydiumClmm = res), // getMarcopoloCacheData(connection).then(res => cacheData1.marcopolo = res), ]); return [JSON.stringify(cacheData1), JSON.stringify(cacheData2), JSON.stringify(cacheData3)]; }); } exports.getCacheData = getCacheData; function loadLiquidityProviders(connection, liqProviders) { return __awaiter(this, void 0, void 0, function* () { let time = Date.now(); console.log("liqProviders Start Time: ", time); let [data1, data2, data3] = yield Promise.all([ axios_1.default.get("https://cache.prism.ag/init-cache-1.json"), axios_1.default.get("https://cache.prism.ag/init-cache-2.json"), axios_1.default.get("https://cache.prism.ag/init-cache-3.json"), ]); // let phoenixData = await getPhoenixCaceData(connection); let cacheData1 = data1.data, cacheData2 = data2.data, cacheData3 = data3.data; let results = yield Promise.all([ // liqProviders.cropper ? getCropperPools(cacheData1.cropper) : {}, // liqProviders.mercurial ? getMercurialPools(data.mercurial) : {}, // liqProviders.penguin ? getPenguinPools(cacheData1.penguin) : {}, liqProviders.raydium ? (0, raydium_1.getRaydiumAmms)(cacheData1.raydium, cacheData2.raydium, cacheData3.raydium) : {}, liqProviders.saber ? (0, saber_1.getSaberPools)(cacheData1.saber) : {}, // liqProviders.saros ? getSarosPools(cacheData1.saros) : {}, // liqProviders.sencha ? getSenchaPools(cacheData1.sencha) : {}, // liqProviders.step ? getStepPools(cacheData1.step) : {}, // liqProviders.symmetry ? getSymmetryFunds(cacheData1.symmetry) : {}, // liqProviders.aldrin ? getAldrinPools(connection, cacheData1.aldrin) : {}, // liqProviders.openbook ? getOpenbookMarkets(cacheData2.openbook) : {}, // liqProviders.balansol ? getBalansolPools(cacheData1.balansol) : {}, liqProviders.orca ? (0, orca_1.getOrcaPools)(connection) : {}, // liqProviders.lifinity ? getLifinityPools() : {}, // liqProviders.lifinityV2 ? getLifinityV2Pools() : {}, // liqProviders.stepn ? getStepnPools() : {}, // liqProviders.marinade ? getMarinadePools() : {}, liqProviders.whirlpools ? (0, whirlpools_1.getWhirlpools)(cacheData3.whirlpools) : {}, liqProviders.raydiumClmm ? (0, raydiumCLMM_1.getRaydiumClmmPools)(cacheData3.raydiumClmm) : {}, // liqProviders.marcopolo ? getMarcopoloPools(connection, cacheData1.marcopolo) : {}, // liqProviders.phoenix ? getPhoenixMarkets(phoenixData) : {}, ]); let combinedOptions = { all: {} }; for (let i = 0; i < results.length; i++) for (let [mint, info] of Object.entries(results[i])) { if (mint == "all") { combinedOptions.all = info; continue; } //@ts-ignore for (let j = 0; j < info.length; j++) //@ts-ignore (combinedOptions[mint] || (combinedOptions[mint] = [])).push(info[j]); } console.log("LiqProviders Ended: ", Date.now() - time); return combinedOptions; }); } exports.loadLiquidityProviders = loadLiquidityProviders;