UNPKG

@drift-labs/sdk

Version:
54 lines (53 loc) 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOracleClient = void 0; const types_1 = require("../types"); const pythClient_1 = require("../oracles/pythClient"); const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient"); const anchor_1 = require("../isomorphic/anchor"); const prelaunchOracleClient_1 = require("../oracles/prelaunchOracleClient"); const pythLazerClient_1 = require("../oracles/pythLazerClient"); function getOracleClient(oracleSource, connection, program) { if ((0, types_1.isVariant)(oracleSource, 'pyth')) { return new pythClient_1.PythClient(connection); } if ((0, types_1.isVariant)(oracleSource, 'pyth1K')) { return new pythClient_1.PythClient(connection, new anchor_1.BN(1000)); } if ((0, types_1.isVariant)(oracleSource, 'pyth1M')) { return new pythClient_1.PythClient(connection, new anchor_1.BN(1000000)); } if ((0, types_1.isVariant)(oracleSource, 'pythStableCoin')) { return new pythClient_1.PythClient(connection, undefined, true); } if ((0, types_1.isVariant)(oracleSource, 'prelaunch')) { return new prelaunchOracleClient_1.PrelaunchOracleClient(connection, program); } if ((0, types_1.isVariant)(oracleSource, 'quoteAsset')) { return new quoteAssetOracleClient_1.QuoteAssetOracleClient(); } if ((0, types_1.isVariant)(oracleSource, 'pythPull') || (0, types_1.isVariant)(oracleSource, 'pyth1KPull') || (0, types_1.isVariant)(oracleSource, 'pyth1MPull') || (0, types_1.isVariant)(oracleSource, 'pythStableCoinPull')) { throw new Error('Pyth pull oracle support has been removed from the SDK'); } if ((0, types_1.isVariant)(oracleSource, 'switchboard') || (0, types_1.isVariant)(oracleSource, 'switchboardOnDemand')) { throw new Error('Switchboard oracle support has been removed from the SDK'); } if ((0, types_1.isVariant)(oracleSource, 'pythLazer')) { return new pythLazerClient_1.PythLazerClient(connection); } if ((0, types_1.isVariant)(oracleSource, 'pythLazer1K')) { return new pythLazerClient_1.PythLazerClient(connection, new anchor_1.BN(1000)); } if ((0, types_1.isVariant)(oracleSource, 'pythLazer1M')) { return new pythLazerClient_1.PythLazerClient(connection, new anchor_1.BN(1000000)); } if ((0, types_1.isVariant)(oracleSource, 'pythLazerStableCoin')) { return new pythLazerClient_1.PythLazerClient(connection, undefined, true); } throw new Error(`Unknown oracle source ${oracleSource}`); } exports.getOracleClient = getOracleClient;