@parifi/sdk
Version:
Parifi SDK with common utility functions
76 lines (73 loc) • 4.95 kB
text/typescript
import { RpcConfig, SubgraphConfig, PythConfig } from '../interfaces/classConfigs.mjs';
import { PriceObject } from '../interfaces/subgraphTypes.mjs';
import { LeaderboardUserData, SnxAccount, Order, Position, Market, ProtocolStats } from '../interfaces/sdkTypes.mjs';
import { depositedCollateralAccountIdResponse } from './accounts/index.mjs';
import { Chain } from '@parifi/references';
import { GraphQLClient } from 'graphql-request';
import { Pyth } from '../pyth/index.mjs';
import Decimal__default from 'decimal.js';
export { getPublicSubgraphEndpoint, publicSubgraphEndpoints } from './common/index.mjs';
export { getAllMarketsFromSubgraph, getMarketById } from './markets/index.mjs';
export { getAllOrdersByUserAddress, getOrderById, getSettledOrdersCountBasedOnTimeStampByUserAddress } from './orders/index.mjs';
export { getAllOpenPositionsWithTime, getAllPositionHistoryWithTime, getAllPositionsByUserAddress, getClosedPositionsByUserAddress, getLiquidatedPositionsByUserAddress, getOpenPositionsByUserAddress, getPositionById, getUserLiquidatedPositionsBySnxAccount, getUserOpenPositionsWithTime, getUserPositionHistoryWithTime, getUserPositionsHistory } from './positions/index.mjs';
import 'axios';
declare class Subgraph {
private rpcConfig;
private subgraphConfig;
graphQLClient: GraphQLClient;
pyth: Pyth;
constructor(rpcConfig: RpcConfig, subgraphConfig: SubgraphConfig, pythConfig: PythConfig);
init(): Promise<void>;
getSubgraphEndpoint(chainId: Chain): string;
executeSubgraphQuery(query: string): Promise<any>;
getRealizedPnlForUser(userAddress: string): Promise<{
totalRealizedPnlPositions: Decimal__default;
totalRealizedPnlVaults: Decimal__default;
}>;
getPortfolioStats(userAddress: string, priceData: {
id: string;
price: number;
}[]): Promise<{
collateralValueInUsd: Decimal__default;
unrealizedPnl: Decimal__default;
realizedPnl: Decimal__default;
}>;
getLeaderboardUserData(userAddresses: string[]): Promise<LeaderboardUserData[]>;
getFeesByAddress(userAddresses: string[]): Promise<Map<string, number>>;
checkIfExistingUser(userAddress: string): Promise<boolean>;
depositedCollateralForSnxAccounts(accountIds: string[]): Promise<depositedCollateralAccountIdResponse[]>;
transformPriceArray(priceArray: PriceObject[]): {
id: string;
price: number;
}[];
getAllOrdersByUserAddress(userAddress: string, count: number, skip: number): Promise<SnxAccount[]>;
getOrderById(orderId: string): Promise<Order>;
getUserByAddress(userAddress: string): Promise<any>;
getSettledOrdersCountBasedOnTimeStampByUserAddress(userAddress: string, count: number, skip: number, startTime: number, endTime: number): Promise<number>;
getAllPositionsByUserAddress(userAddress: string, count?: number, skip?: number): Promise<SnxAccount[]>;
getOpenPositionsByUserAddress(userAddress: string, count?: number, skip?: number): Promise<SnxAccount[]>;
getClosedPositionsByUserAddress(userAddress: string, count?: number, skip?: number): Promise<SnxAccount[]>;
getLiquidatedPositionsByUserAddress(userAddress: string, count?: number, skip?: number): Promise<SnxAccount[]>;
getPositionById(positionId: string): Promise<Position>;
getUserPositionsHistory(userAddress: string, count?: number, skip?: number): Promise<SnxAccount[]>;
getUserPositionHistoryWithTime(userAddress: string, startTime: number, endTime: number, count?: number, skip?: number): Promise<SnxAccount[]>;
getUserOpenPositionsWithTime(userAddress: string, startTime: number, endTime: number, count?: number, skip?: number): Promise<SnxAccount[]>;
getUserLiquidatedPositionsBySnxAccount(snxAccountId: string, lastRefresh: number): Promise<SnxAccount | undefined>;
getAllPositionHistoryWithTime(startTime: number, endTime: number, count?: number, skip?: number): Promise<SnxAccount[]>;
getAllOpenPositionsWithTime(startTime: number, endTime: number, count?: number, skip?: number): Promise<SnxAccount[]>;
getAllMarketsFromSubgraph(): Promise<Market[]>;
getMarketById(marketId: string): Promise<Market>;
getProtocolStats(): Promise<ProtocolStats>;
/**
* Estimates the rewards a user would receive based on their share of integrator fees
* generated during a specified time period.
*
* @param userAddress - The address of the user to calculate rewards for
* @param totalRewardsForPeriod - The total rewards to be distributed for the period
* @param startTimestamp - The starting Unix timestamp of the period
* @param endTimestamp - The ending Unix timestamp of the period
* @returns A Promise resolving to the estimated reward amount for the user
*/
getEstimatedRewardsForUser(userAddress: string, totalRewardsForPeriod: number, startTimestamp: number, endTimestamp: number): Promise<number>;
}
export { Subgraph };