UNPKG

client-aftermath-ts-sdk

Version:
155 lines (154 loc) 6.63 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LeveragedStaking = void 0; const caller_1 = require("../../general/utils/caller"); /** * Represents the Leveraged Staking module. */ class LeveragedStaking extends caller_1.Caller { // ========================================================================= // Constants // ========================================================================= // public static readonly constants = {}; // ========================================================================= // Constructor // ========================================================================= /** * Creates an instance of the LeveragedStaking class. * @param network The network to connect to. */ constructor(config) { super(config, "leveraged-staking"); } // ========================================================================= // Objects // ========================================================================= /** * Retrieves the leveraged stake position. * @param inputs The input parameters for the API request. * @returns A Promise that resolves to the API response. */ getLeveragedStakePosition(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.fetchApi("leveraged-stake-position", inputs); }); } /** * Retrieves the Leveraged AfSui state. * @returns A Promise that resolves to the LeveragedAfSuiState object. */ getLeveragedAfSuiState() { return __awaiter(this, void 0, void 0, function* () { return this.fetchApi("leveraged-afsui-state"); }); } /** * Retrieves the SUI market pool. * @returns A promise that resolves to a ScallopMarketPool object. */ getSuiMarketPool() { return __awaiter(this, void 0, void 0, function* () { // ScallopMarketPool return this.fetchApi("sui-market-pool"); }); } /** * Retrieves the AfSui market collateral. * @returns A promise that resolves to a `ScallopMarketCollateral` object. */ getAfSuiMarketCollateral() { return __awaiter(this, void 0, void 0, function* () { // ScallopMarketCollateral return this.fetchApi("afsui-market-collateral"); }); } // ========================================================================= // Events // ========================================================================= /** * Retrieves events for a specific user. * @param inputs The input parameters for the API request. * @returns A promise that resolves to the fetched events. */ getEventsForUser(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.fetchApiEvents("events", inputs); }); } // ========================================================================= // Transactions // ========================================================================= // public async getStakeTransaction(inputs: ApiStakeBody) { // return this.fetchApiTransaction<ApiStakeBody>( // "transactions/leveraged-stake", // inputs // ); // } // ========================================================================= // Graph Data // ========================================================================= /** * Retrieves the performance data for leveraged staking. * @param inputs - The input parameters for fetching performance data. * @returns A promise that resolves to an array of LeveragedStakingPerformanceDataPoint objects. */ getPerformanceData(inputs) { return __awaiter(this, void 0, void 0, function* () { return this.fetchApi(`performance-data/${inputs.timeframe}/${inputs.borrowRate}/${inputs.maxLeverage}`); }); } } exports.LeveragedStaking = LeveragedStaking; // ========================================================================= // Public Static Methods // ========================================================================= // ========================================================================= // Calculations // ========================================================================= /** * Calculates the leverage based on the provided inputs. * @param inputs - The inputs required for leverage calculation. * @returns The calculated leverage. */ LeveragedStaking.calcLeverage = (inputs) => { return LeveragedStaking.calcLeverageNormalized({ normalizedTotalSuiDebt: inputs.totalSuiDebt, normalizedTotalAfSuiCollateral: BigInt(Math.floor(Number(inputs.totalAfSuiCollateral) / inputs.afSuiToSuiExchangeRate)), }); }; /** * Calculates the total SUI debt based on the provided inputs. * * @param inputs - The inputs required for the calculation. * @returns The total SUI debt as a Balance. */ LeveragedStaking.calcTotalSuiDebt = (inputs) => { return BigInt(Math.floor(Number(inputs.totalAfSuiCollateral) * inputs.afSuiToSuiExchangeRate * (1 - (inputs.leverage ? 1 / inputs.leverage : 0)))); }; // ========================================================================= // Private Static Methods // ========================================================================= // ========================================================================= // Calculations // ========================================================================= LeveragedStaking.calcLeverageNormalized = (inputs) => { const normalizedTotalAfSuiCollateralNum = Number(inputs.normalizedTotalAfSuiCollateral); if (!normalizedTotalAfSuiCollateralNum) return 1; return (1 / (1 - Number(inputs.normalizedTotalSuiDebt) / normalizedTotalAfSuiCollateralNum)); };