-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from Premian-Labs/fix/transaction-api
Add function to get optionPS transactions and fix transaction fragments
- Loading branch information
Showing
14 changed files
with
260 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BigNumberish } from 'ethers' | ||
|
||
import { Token } from './token' | ||
import { OptionPhysicallySettled } from './option' | ||
|
||
export enum OptionPSTransactionType { | ||
OPTION_PS_EXERCISE = 'OPTION_PS_EXERCISE', | ||
OPTION_PS_CANCEL_EXERCISE = 'OPTION_PS_CANCEL_EXERCISE', | ||
OPTION_PS_SETTLE_LONG = 'OPTION_PS_SETTLE_LONG', | ||
OPTION_PS_SETTLE_SHORT = 'OPTION_PS_SETTLE_SHORT', | ||
OPTION_PS_ANNIHILATE = 'OPTION_PS_ANNIHILATE', | ||
OPTION_REWARD_UNDERWRITE = 'OPTION_REWARD_UNDERWRITE', | ||
SHORT_OPTION_TRANSFER = 'SHORT_OPTION_TRANSFER', | ||
SHORT_OPTION_RECEIVE = 'SHORT_OPTION_RECEIVE', | ||
LONG_OPTION_PS_TRANSFER = 'LONG_OPTION_PS_TRANSFER', | ||
LONG_OPTION_PS_RECEIVE = 'LONG_OPTION_PS_RECEIVE', | ||
} | ||
|
||
export interface OptionPSTransaction { | ||
id: string | ||
option: OptionPhysicallySettled | ||
tokenSymbol: string | ||
token: Token | ||
origin: string | ||
gasUsed: BigNumberish | ||
gasPrice: BigNumberish | ||
timestamp: BigNumberish | ||
block: BigNumberish | ||
logIndex: BigNumberish | ||
|
||
type: OptionPSTransactionType | ||
action: string | ||
description: string | ||
size: BigNumberish | ||
sizeETH: BigNumberish | ||
sizeUSD: BigNumberish | ||
user: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/services/subgraph/graphql/fragments/optionPSTransaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { gql } from '@apollo/client/core' | ||
|
||
import { OptionPhysicallySettledFragment } from './option' | ||
import { TokenFragment } from './token' | ||
|
||
export const OptionPSTransactionFragment = gql` | ||
${OptionPhysicallySettledFragment} | ||
${TokenFragment} | ||
fragment OptionPSTransaction on OptionPSTransaction { | ||
id | ||
option { | ||
...OptionPhysicallySettled | ||
} | ||
tokenSymbol | ||
token { | ||
...Token | ||
} | ||
origin | ||
gasUsed | ||
gasPrice | ||
timestamp | ||
block | ||
logIndex | ||
type | ||
action | ||
description | ||
size | ||
sizeETH | ||
sizeUSD | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/services/subgraph/graphql/queries/optionPSTransaction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { DocumentNode, gql } from '@apollo/client/core' | ||
import { BigNumberish } from 'ethers' | ||
import { OptionPSTransactionFragment } from '../fragments' | ||
import { addFields } from '../../../../utils/subgraph' | ||
import PremiaSubgraph from '../../index' | ||
|
||
export class OptionPSTransactionQuery { | ||
static optionPSTransactionId(hash: string): string { | ||
return hash | ||
} | ||
|
||
@addFields | ||
static GetOptionPSTransaction( | ||
subgraph: PremiaSubgraph, | ||
hash: string | ||
): DocumentNode { | ||
return gql` | ||
${OptionPSTransactionFragment} | ||
{ | ||
optionPSTransaction(id: "${this.optionPSTransactionId(hash)}") { | ||
...OptionPSTransaction | ||
} | ||
} | ||
` | ||
} | ||
|
||
@addFields | ||
static GetOptionPSTransactions( | ||
subgraph: PremiaSubgraph, | ||
search: string, | ||
orderBy: string, | ||
order: string, | ||
first = 100, | ||
skip = 0, | ||
account?: string, | ||
startTime?: BigNumberish, | ||
endTime?: BigNumberish, | ||
searchInput?: string | ||
): DocumentNode { | ||
const startFilter = startTime ? `timestamp_gte: ${Number(startTime)},` : '' | ||
const endFilter = endTime ? `timestamp_lte: ${Number(endTime)},` : '' | ||
const searchFilter = searchInput | ||
? `description_contains: "${searchInput.toUpperCase()}",` | ||
: '' | ||
const accountFilter = account ? `user: "${account.toLowerCase()}",` : '' | ||
|
||
const containsName = 'tokenSymbol_contains' | ||
const containsFilter = `${containsName}: "${search}",` | ||
|
||
return gql` | ||
${OptionPSTransactionFragment} | ||
query OptionPSTransaction { | ||
optionPSTransactions( | ||
first: ${first} | ||
skip: ${skip} | ||
orderBy: "${orderBy}" | ||
orderDirection: "${order}" | ||
where: { | ||
sizeUSD_gt: 0, | ||
${startFilter} | ||
${endFilter} | ||
${searchFilter} | ||
${accountFilter} | ||
${containsFilter} | ||
} | ||
) { | ||
...OptionPSTransaction | ||
} | ||
} | ||
` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.