Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[list requests] add requests #69

Merged
merged 5 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .graphqlconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"extensions": {
"endpoints": {
"Subgraph GraphQL": {
"url": "https://graph-testnet.stakewise.io/subgraphs/name/stakewise/stakewise",
"url": "https://holesky-graph.stakewise.io/subgraphs/name/stakewise/stakewise/graphql",
Cast0001 marked this conversation as resolved.
Show resolved Hide resolved
"headers": {
"user-agent": "JS GraphQL"
},
Expand Down
170 changes: 126 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ const sdk = new StakeWiseSDK({ network: Network.Mainnet })
## Quick Links

##### Request table:
| **Vault** | **osToken** | **Utils** |
|------|-------------|------|
| [sdk.vault.getStakerActions](#sdkvaultgetstakeractions) | [sdk.osToken.getBurnAmount](#sdkostokengetburnamount) | [sdk.utils.getSwiseUsdPrice](#sdkutilsgetswiseusdprice) |
| [sdk.vault.getSnapshots](#sdkvaultgetsnapshots) | [sdk.osToken.getHealthFactor](#sdkostokengethealthfactor) | [sdk.utils.getTransactions](#sdkutilsgettransactions) |
| **Vault** | **osToken** | **Utils** |
|-------------------------------------------------------------------|-------------|------|
| [sdk.vault.getStakerActions](#sdkvaultgetstakeractions) | [sdk.osToken.getBurnAmount](#sdkostokengetburnamount) | [sdk.utils.getSwiseUsdPrice](#sdkutilsgetswiseusdprice) |
| [sdk.vault.getSnapshots](#sdkvaultgetsnapshots) | [sdk.osToken.getHealthFactor](#sdkostokengethealthfactor) | [sdk.utils.getTransactions](#sdkutilsgettransactions) |
| [sdk.vault.getExitQueuePositions](#sdkvaultgetexitqueuepositions) | [sdk.osToken.getAPY](#sdkostokengetapy) |
| [sdk.vault.getValidators](#sdkvaultgetvalidators) | [sdk.osToken.getPosition](#sdkostokengetposition) |
| [sdk.vault.getVault](#sdkvaultgetvault) | [sdk.osToken.getMaxMint](#sdkostokengetmaxmint) |
| [sdk.vault.getMaxWithdraw](#sdkvaultgetmaxwithdraw) | [sdk.osToken.getBaseData](#sdkostokengetbasedata) |
| [sdk.vault.getHarvestParams](#sdkvaultgetharvestparams) | [sdk.osToken.getSharesFromAssets](#sdkostokengetsharesfromassets) |
| [sdk.vault.getStakeBalance](#sdkvaultgetstakebalance) | [sdk.osToken.getAssetsFromShares](#sdkostokengetassetsfromshares) |
|[sdk.vault.getUserRewards](#sdkvaultgetuserrewards) | [sdk.vault.getScorePercentiles](#sdkvaultgetscorepercentiles)
| [sdk.vault.getValidators](#sdkvaultgetvalidators) | [sdk.osToken.getPosition](#sdkostokengetposition) |
| [sdk.vault.getVault](#sdkvaultgetvault) | [sdk.osToken.getMaxMint](#sdkostokengetmaxmint) |
| [sdk.vault.getMaxWithdraw](#sdkvaultgetmaxwithdraw) | [sdk.osToken.getBaseData](#sdkostokengetbasedata) |
| [sdk.vault.getHarvestParams](#sdkvaultgetharvestparams) | [sdk.osToken.getSharesFromAssets](#sdkostokengetsharesfromassets) |
| [sdk.vault.getStakeBalance](#sdkvaultgetstakebalance) | [sdk.osToken.getAssetsFromShares](#sdkostokengetassetsfromshares) |
| [sdk.vault.getUserRewards](#sdkvaultgetuserrewards) | [sdk.vault.getScorePercentiles](#sdkvaultgetscorepercentiles)
| [sdk.vault.getWhitelist](#sdkvaultgetwhitelist)
| [sdk.vault.getBlocklist](#sdkvaultgetblocklist)

##### Table of transactions:
| **Vault** | **osToken** |
Expand Down Expand Up @@ -283,6 +285,90 @@ await sdk.vault.getUserRewards({
})
```
---
### `sdk.vault.getWhitelist`

#### Description:

Fetch the whitelist for private vaults. Only addresses included in this list are eligible to stake in the private vault. The number of addresses in this list is indicated by the vault whitelistCount field.


#### Arguments:

| Name | Type | Type | Description |
|------|-------------------|-------------|---|
| vaultAddress | `string` | **Require** | - |
| orderDirection | `'asc' \| 'desc'` | **Optional** | Sort, by default `desc` (descending order) |
| search | `string` | **Optional** | Filters results by the address field |
| limit | `number` | **Optional** | Limit the number of addresses, default is 100 |
| skip | `number` | **Optional** | Skip the number of addresses, default is 0 |

#### Returns:

```ts
type List = {
createdAt: number
address: string
}

type Output = {
whitelist: List[]
}
```

| Name | Description |
|------|-------------|
| `whitelist` | An array of objects representing the result of the query based on your parameters |

#### Example:

```ts
await sdk.vault.getWhitelist({
vaultAddress: '0x...',
})
```
---
### `sdk.vault.getBlocklist`

#### Description:

Fetch the blocklist for blocklisted vaults. Addresses included in this list are not eligible to stake in the blocklisted vault. The number of addresses in this list is indicated by the vault blocklistCount field.


#### Arguments:

| Name | Type | Type | Description |
|------|---------------|-------------|---|
| vaultAddress | `string` | **Require** | - |
| orderDirection | `'asc' \| 'desc'` | **Optional** | Sort, by default `desc` (descending order) |
| search | `string` | **Optional** | Filters results by the address field |
| limit | `number` | **Optional** | Limit the number of addresses, default is 100 |
| skip | `number` | **Optional** | Skip the number of addresses, default is 0 |

#### Returns:

```ts
type List = {
createdAt: number
address: string
}

type Output = {
blocklist: List[]
}
```

| Name | Description |
|------|-------------|
| `blocklist` | An array of objects representing the result of the query based on your parameters |

#### Example:

```ts
await sdk.vault.getBlocklist({
vaultAddress: '0x...',
})
```
---
### `sdk.vault.getExitQueuePositions`

#### Description:
Expand Down Expand Up @@ -399,6 +485,8 @@ type Output = {
whitelister: string
vaultAddress: string
mevRecipient: string
whitelistCount: number
blocklistCount: number
imageUrl: string | null
blocklistManager: string
vaultKeysManager: string
Expand All @@ -407,44 +495,38 @@ type Output = {
tokenSymbol: string | null
displayName: string | null
description: string | null
whitelist: Array<{
createdAt: number
address: string
}> | null
blocklist: Array<{
createdAt: number
address: string
}> | null
performance: number
}
```

| Name | Description |
|--------------------|-----------------------------------------|
| `apy` | Current vault apy |
| `isErc20` | Does the vault have its own ERC20 token |
| `capacity` | Maximum TVL of Vault |
| `createdAt` | Date of Creation |
| `feePercent` | Commission rate |
| `isPrivate` | Whether the storage is private |
| `isBlocklist` | Whether the storage has blocklist |
| `vaultAdmin` | Vault administrator address |
| `totalAssets` | TVL of Vault |
| `feeRecipient` | Vault fee address |
| `whitelister` | Whitelist manager |
| `vaultAddress` | Address of vault |
| `mevRecipient` | Validator fee recipient |
| `imageUrl` | Link for vault logo |
| `blocklistManager` | Blocklist manager |
| `vaultKeysManager` | Keys manager address |
| `isSmoothingPool` | Smoothing poll or Vault escrow |
| `tokenName` | ERC20 token name |
| `tokenSymbol` | ERC20 token symbol |
| `displayName` | Name of vault |
| `description` | Description of vault |
| `whitelist` | List of authorized users for deposits |
| `blocklist` | List of blocked users for deposits |
| `performance` | Vault performance indicator (percent) |
| Name | Description |
|--------------------|---------------------------------------------------------------|
| `apy` | Current vault apy |
| `isErc20` | Does the vault have its own ERC20 token |
| `capacity` | Maximum TVL of Vault |
| `createdAt` | Date of Creation |
| `feePercent` | Commission rate |
| `isPrivate` | Whether the storage is private |
| `isBlocklist` | Whether the storage has blocklist |
| `vaultAdmin` | Vault administrator address |
| `totalAssets` | TVL of Vault |
| `feeRecipient` | Vault fee address |
| `whitelister` | Whitelist manager |
| `vaultAddress` | Address of vault |
| `mevRecipient` | Validator fee recipient |
| `whitelistCount` | Number of addresses in the [whitelist](#sdkvaultgetwhitelist) |
| `blocklistCount` | Number of addresses in the [blocklist](#sdkvaultgetblocklist) |
| `imageUrl` | Link for vault logo |
| `blocklistManager` | Blocklist manager |
| `vaultKeysManager` | Keys manager address |
| `isSmoothingPool` | Smoothing poll or Vault escrow |
| `tokenName` | ERC20 token name |
| `tokenSymbol` | ERC20 token symbol |
| `displayName` | Name of vault |
| `description` | Description of vault |
| `whitelist` | List of authorized users for deposits |
| `blocklist` | List of blocked users for deposits |
| `performance` | Vault performance indicator (percent) |

#### Example:

Expand Down
6 changes: 6 additions & 0 deletions src/graphql/subgraph/vault/blocklistAccountsQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query BlocklistAccounts($where: VaultBlockedAccount_filter, $limit: Int, $skip: Int, $orderDirection: OrderDirection) {
vaultBlockedAccounts(where: $where, first: $limit, skip: $skip, orderDirection: $orderDirection, orderBy: createdAt) {
createdAt
address
}
}
6 changes: 6 additions & 0 deletions src/graphql/subgraph/vault/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ export type { VaultQueryPayload, VaultQueryVariables } from './vaultQuery.graphq

export { fetchHarvestParamsQuery } from './harvestParamsQuery.graphql'
export type { HarvestParamsQueryPayload, HarvestParamsQueryVariables } from './harvestParamsQuery.graphql'

export { fetchWhitelistAccountsQuery } from './whitelistAccountsQuery.graphql'
export type { WhitelistAccountsQueryPayload, WhitelistAccountsQueryVariables } from './whitelistAccountsQuery.graphql'

export { fetchBlocklistAccountsQuery } from './blocklistAccountsQuery.graphql'
export type { BlocklistAccountsQueryPayload, BlocklistAccountsQueryVariables } from './blocklistAccountsQuery.graphql'
10 changes: 2 additions & 8 deletions src/graphql/subgraph/vault/vaultQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ query Vault($address: ID!) {
validatorsRoot
blocklistManager
weeklyApy
}
privateVaultAccounts(where: { vault: $address }, first: 1000) {
createdAt
address
}
vaultBlockedAccounts(where: { vault: $address }, first: 1000) {
createdAt
address
blocklistCount
whitelistCount
}
}
6 changes: 6 additions & 0 deletions src/graphql/subgraph/vault/whitelistAccountsQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query WhitelistAccounts($where: PrivateVaultAccount_filter, $limit: Int, $skip: Int, $orderDirection: OrderDirection) {
privateVaultAccounts(where: $where, first: $limit, skip: $skip, orderDirection: $orderDirection, orderBy: createdAt) {
createdAt
address
}
}
4 changes: 4 additions & 0 deletions src/methods/vault/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Requests
import getVault from './requests/getVault'
import getSnapshots from './requests/getSnapshots'
import getWhitelist from './requests/getWhitelist'
import getBlocklist from './requests/getBlocklist'
import getValidators from './requests/getValidators'
import getUserRewards from './requests/getUserRewards'
import getMaxWithdraw from './requests/getMaxWithdraw'
Expand All @@ -27,6 +29,8 @@ export default {
getMaxWithdraw,
getValidators,
getSnapshots,
getWhitelist,
getBlocklist,
getVault,
},
transactions: {
Expand Down
66 changes: 66 additions & 0 deletions src/methods/vault/requests/getBlocklist/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type { BlocklistAccountsQueryVariables, BlocklistAccountsQueryPayload } from '../../../../graphql/subgraph/vault'
import { apiUrls, validateArgs } from '../../../../utils'
import graphql from '../../../../graphql'
import { ModifiedBlocklist } from './types'
import modifyBlocklist from './modifyBlocklist'


type GetBlocklistInput = {
vaultAddress: string
orderDirection?: BlocklistAccountsQueryVariables['orderDirection']
search?: string
limit?: number
skip?: number
options: StakeWise.Options
}

type GetBlocklistOutput = {
blocklist: {
createdAt: number
address: string
}[]
}

const getBlocklist = async (input: GetBlocklistInput): Promise<GetBlocklistOutput> => {
const { vaultAddress, orderDirection, search, limit, skip, options } = input

validateArgs.address({ vaultAddress })

if (typeof skip !== 'undefined') {
validateArgs.number({ skip })
}

if (typeof limit !== 'undefined') {
validateArgs.number({ limit })
}

if (typeof search !== 'undefined') {
validateArgs.string({ search })
}

if (typeof orderDirection !== 'undefined') {
if (![ 'asc', 'desc' ].includes(orderDirection)) {
throw new Error(`The "orderDirection" argument must be "asc" or "desc"`)
}
}

const vault = vaultAddress.toLowerCase()

const where = search
? { vault, address_contains: search.toLowerCase() } as BlocklistAccountsQueryVariables['where']
: { vault } as BlocklistAccountsQueryVariables['where']

return graphql.subgraph.vault.fetchBlocklistAccountsQuery<ModifiedBlocklist>({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
where,
skip: skip || 0,
limit: limit || 100,
orderDirection: orderDirection || 'desc',
},
modifyResult: (data: BlocklistAccountsQueryPayload) => modifyBlocklist({ data }),
})
}


export default getBlocklist
43 changes: 43 additions & 0 deletions src/methods/vault/requests/getBlocklist/modifyBlocklist.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import modifyBlocklist from './modifyBlocklist'
import type { BlocklistAccountsQueryPayload } from '../../../../graphql/subgraph/vault'


describe('modifyBlocklist', () => {
const mockBlocklistQueryPayload: BlocklistAccountsQueryPayload = {
vaultBlockedAccounts: [
{ createdAt: '1693395816', address: '0xeefffd4c23d2e8c845870e273861e7d60df49663' },
{ createdAt: '1693395816', address: '0xeefffd4c23d2e8c845870e273861e7d60df49663' },
],
}

it('should correctly transform the whitelist data', () => {
const expectedModifiedVault = [
{
createdAt: 1693395816000,
address: '0xeEFFFD4C23D2E8c845870e273861e7d60Df49663',
},
{
createdAt: 1693395816000,
address: '0xeEFFFD4C23D2E8c845870e273861e7d60Df49663',
},
]

const result = modifyBlocklist({
data: mockBlocklistQueryPayload,
})

expect(result).toEqual(expectedModifiedVault)
})

it('should handle empty privateVaultAccounts correctly', () => {
const mockDataWithoutBlockedAccounts: BlocklistAccountsQueryPayload = {
vaultBlockedAccounts: [],
}

const result = modifyBlocklist({
data: mockDataWithoutBlockedAccounts,
})

expect(result).toEqual([])
})
})
Loading
Loading