UNPKG

@parifi/sdk

Version:

Parifi SDK with common utility functions

597 lines (596 loc) 14.6 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/subgraph/positions/subgraphQueries.ts var subgraphQueries_exports = {}; __export(subgraphQueries_exports, { fetchAllOpenPositionsWithTime: () => fetchAllOpenPositionsWithTime, fetchAllPositionHistoryWithTime: () => fetchAllPositionHistoryWithTime, fetchCrossMarginPositionsBySnxAccount: () => fetchCrossMarginPositionsBySnxAccount, fetchLiquidatedPositionsBySnxAccount: () => fetchLiquidatedPositionsBySnxAccount, fetchOpenPositionsByUser: () => fetchOpenPositionsByUser, fetchPositionByIdQuery: () => fetchPositionByIdQuery, fetchPositionsByUserQuery: () => fetchPositionsByUserQuery, fetchPositionsByUserQueryAndStatus: () => fetchPositionsByUserQueryAndStatus, fetchPositionsToLiquidateQuery: () => fetchPositionsToLiquidateQuery, fetchUserOpenPositionsWithTime: () => fetchUserOpenPositionsWithTime, fetchUserPositionHistory: () => fetchUserPositionHistory, fetchUserPositionHistoryWithTime: () => fetchUserPositionHistoryWithTime }); module.exports = __toCommonJS(subgraphQueries_exports); var import_graphql_request = require("graphql-request"); var fetchPositionsByUserQuery = (userAddress, count = 20, skip = 0) => import_graphql_request.gql` { snxAccounts( first: ${count} skip: ${skip} where: { owner: "${userAddress}", type: PERP }) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions(where: {status_in: [OPEN, CLOSED, LIQUIDATED]}) { id market { id marketName marketSymbol feedId } positionSize avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; var fetchPositionsByUserQueryAndStatus = (userAddress, status, count = 20, skip = 0) => import_graphql_request.gql` { snxAccounts( first: ${count} skip: ${skip} where: { owner: "${userAddress}", type: PERP } ) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions(where: {status: ${status} }) { id market { id marketName marketSymbol feedId } positionSize avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; var fetchOpenPositionsByUser = (userAddress, count = 20, skip = 0) => import_graphql_request.gql` { snxAccounts( first: ${count} skip: ${skip} where: { owner: "${userAddress}", type: PERP, openPositionCount_gt: 0 } ) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions(where: {status: OPEN }) { id market { id marketName marketSymbol feedId } positionSize avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; var fetchUserPositionHistory = (userAddress, count = 20, skip = 0) => import_graphql_request.gql` { snxAccounts( first: ${count} skip: ${skip} where: { owner: "${userAddress}", type: PERP } ) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions(where: {status_in: [CLOSED, LIQUIDATED]}) { id market { id marketName marketSymbol feedId } positionSize avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; var fetchPositionByIdQuery = (positionId) => import_graphql_request.gql` { position( id: "${positionId}" ) { id market { id, marketName, marketSymbol, feedId } snxAccount{ id accountId } isLong positionSize avgPrice avgPriceDec status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } }`; var fetchPositionsToLiquidateQuery = (count) => import_graphql_request.gql` { positions(where: { status: OPEN, canBeLiquidated: true }, first: ${count}, orderBy: positionSize, orderDirection: desc) { id } } `; var fetchUserPositionHistoryWithTime = (userAddress, startTimestamp, endTimestamp, count = 20, skip = 0) => import_graphql_request.gql` { snxAccounts( first: ${count} skip: ${skip} where: { owner: "${userAddress}", type: PERP } ) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions( where: { status_in: [CLOSED, LIQUIDATED], createdTimestamp_gte: ${startTimestamp} createdTimestamp_lte: ${endTimestamp} }) { id market { id marketName marketSymbol feedId } positionSize positionCollateral avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; var fetchUserOpenPositionsWithTime = (userAddress, startTimestamp, endTimestamp, count = 20, skip = 0) => import_graphql_request.gql` { snxAccounts( first: ${count} skip: ${skip} where: { owner: "${userAddress}", type: PERP, positions_: { status: OPEN, createdTimestamp_gte: ${startTimestamp} createdTimestamp_lte: ${endTimestamp} } } ) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions { id market { id marketName marketSymbol feedId } positionSize avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; var fetchLiquidatedPositionsBySnxAccount = (snxAccountId, lastRefresh) => import_graphql_request.gql` { snxAccount(id: "${snxAccountId}" ) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions(where: { status: LIQUIDATED, lastRefresh_gt: ${lastRefresh} }) { id market { id marketName marketSymbol feedId } positionSize avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; var fetchCrossMarginPositionsBySnxAccount = (snxAccountId, lastRefresh) => import_graphql_request.gql` { snxAccount(id: "${snxAccountId}") { accountId collateralDeposits { totalAmountLiquidated } positions(where: { status: LIQUIDATED, lastRefresh_gt: ${lastRefresh} }) { lastRefresh } } } `; var fetchAllOpenPositionsWithTime = (startTimestamp, endTimestamp, count = 20, skip = 0) => import_graphql_request.gql` { snxAccounts( first: ${count} skip: ${skip} where: { type: PERP openPositionCount_gt:0 } ) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions(where: { status: OPEN, createdTimestamp_gte: ${startTimestamp} createdTimestamp_lte: ${endTimestamp} }) { id market { id marketName marketSymbol feedId } positionSize avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; var fetchAllPositionHistoryWithTime = (startTimestamp, endTimestamp, count = 20, skip = 0) => import_graphql_request.gql` { snxAccounts( first: ${count} skip: ${skip} where: { type: PERP totalPositionsCount_gt :0 } ) { id accountId owner { id } collateralDeposits { id collateralName collateralSymbol collateralDecimals collateralAddress currentDepositedAmount totalAmountDeposited totalAmountWithdrawn totalAmountLiquidated } positions(where: { status_in: [CLOSED, LIQUIDATED], createdTimestamp_gte: ${startTimestamp} createdTimestamp_lte: ${endTimestamp} }) { id market { id marketName marketSymbol feedId } positionSize avgPrice avgPriceDec isLong createdTimestamp status txHash liquidationTxHash closingPrice realizedPositionPnl realizedPnlAfterFees totalFeesPaid createdTimestamp lastRefresh lastRefreshISO canBeLiquidated snapshotCollateralValueUsd } } }`; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { fetchAllOpenPositionsWithTime, fetchAllPositionHistoryWithTime, fetchCrossMarginPositionsBySnxAccount, fetchLiquidatedPositionsBySnxAccount, fetchOpenPositionsByUser, fetchPositionByIdQuery, fetchPositionsByUserQuery, fetchPositionsByUserQueryAndStatus, fetchPositionsToLiquidateQuery, fetchUserOpenPositionsWithTime, fetchUserPositionHistory, fetchUserPositionHistoryWithTime }); //# sourceMappingURL=subgraphQueries.js.map