UNPKG

@parifi/sdk

Version:

Parifi SDK with common utility functions

561 lines 12.4 kB
// src/subgraph/positions/subgraphQueries.ts import { gql } from "graphql-request"; var fetchPositionsByUserQuery = (userAddress, count = 20, skip = 0) => 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) => 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) => 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) => 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) => 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) => gql` { positions(where: { status: OPEN, canBeLiquidated: true }, first: ${count}, orderBy: positionSize, orderDirection: desc) { id } } `; var fetchUserPositionHistoryWithTime = (userAddress, startTimestamp, endTimestamp, count = 20, skip = 0) => 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) => 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) => 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) => gql` { snxAccount(id: "${snxAccountId}") { accountId collateralDeposits { totalAmountLiquidated } positions(where: { status: LIQUIDATED, lastRefresh_gt: ${lastRefresh} }) { lastRefresh } } } `; var fetchAllOpenPositionsWithTime = (startTimestamp, endTimestamp, count = 20, skip = 0) => 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) => 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 } } }`; export { fetchAllOpenPositionsWithTime, fetchAllPositionHistoryWithTime, fetchCrossMarginPositionsBySnxAccount, fetchLiquidatedPositionsBySnxAccount, fetchOpenPositionsByUser, fetchPositionByIdQuery, fetchPositionsByUserQuery, fetchPositionsByUserQueryAndStatus, fetchPositionsToLiquidateQuery, fetchUserOpenPositionsWithTime, fetchUserPositionHistory, fetchUserPositionHistoryWithTime }; //# sourceMappingURL=subgraphQueries.mjs.map