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

Subgraph update #163

Merged
merged 2 commits into from
Sep 5, 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://holesky-graph.stakewise.io/subgraphs/name/stakewise/stakewise/graphql",
"url": "https://mainnet-graph-stage.stakewise.io/subgraphs/name/stakewise/stakewise/graphql",
"headers": {
"user-agent": "JS GraphQL"
},
Expand Down
183 changes: 81 additions & 102 deletions README.md

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions changelog/next-release.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- Breaking change: Removed `sdk.osToken.getConfig`. Use `sdk.vault.getVault` instead to get osToken config data `{ osTokenConfig: { ltvPercent, thresholdPercent } }`.
- Added canHarvest: boolean to `sdk.vault.getHarvestParams` response.

# Updates
### 1. `sdk.vault.getVault`

#### New output field:

```ts
type AddedOutput = {
osTokenConfig: {
ltvPercent: string
thresholdPercent: string
}
}
```

| Name | Description |
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `osTokenConfig` | contains the `ltvPercent`, which is the percentage used to calculate how much a user can mint in OsToken shares, and `thresholdPercent`, which is the liquidation threshold percentage used to calculate the health factor for the OsToken position |

---
### 2. `sdk.vault.getHarvestParams`

#### New output field:

```ts
type AddedOutput = {
canHarvest: boolean
}
```

---

### 3. Removed method
### `sdk.vault.getVault`
2 changes: 0 additions & 2 deletions src/StakeWiseSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class StakeWiseSDK {
vaultMulticall<T extends unknown>({ userAddress, vaultAddress, request }: VaultMulticallInput) {
return vaultMulticall<T>({
vaultContract: this.contracts.helpers.createVault(vaultAddress),
keeperContract: this.contracts.base.keeper,
options: this.options,
vaultAddress,
userAddress,
Expand All @@ -67,7 +66,6 @@ class StakeWiseSDK {

return rewardSplitterMulticall<T>({
rewardSplitterContract: this.contracts.helpers.createRewardSplitter(rewardSplitterAddress),
keeperContract: this.contracts.base.keeper,
options: this.options,
vaultAddress,
userAddress,
Expand Down
5 changes: 3 additions & 2 deletions src/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { default as createContracts } from './createContracts'
export { default as createContract } from './createContract'
export { default as multicall } from './multicall/commonMulticall'
export { default as vaultMulticall } from './multicall/vaultMulticall'
export { default as eigenPodOwnerMulticall } from './multicall/eigenPodOwnerMulticall'
export { default as rewardSplitterMulticall } from './multicall/rewardSplitterMulticall'

export { vaultMulticall, rewardSplitterMulticall } from './multicall'
export type { VaultMulticallBaseInput, RewardSplitterMulticallBaseInput } from './multicall'
7 changes: 5 additions & 2 deletions src/contracts/multicall/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export { default as vaultMulticall } from './vaultMulticall'
export { default as commonMulticall } from './commonMulticall'
export { default as rewardSplitterMulticall } from './rewardSplitterMulticall'

export { default as vaultMulticall } from './vaultMulticall'
export type { VaultMulticallBaseInput } from './vaultMulticall'

export { default as rewardSplitterMulticall } from './rewardSplitterMulticall'
export type { RewardSplitterMulticallBaseInput } from './rewardSplitterMulticall'
17 changes: 9 additions & 8 deletions src/contracts/multicall/rewardSplitterMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ import {
handleTransactionData,
} from './util'

import type { KeeperAbi, RewardSplitterAbi } from '../types'
import type { RewardSplitterAbi } from '../types'
import type { MulticallRequestInput } from './types'


type RewardSplittersMulticallInput = {
export type RewardSplitterMulticallBaseInput = {
userAddress: string
vaultAddress: string
options: StakeWise.Options
request: MulticallRequestInput
keeperContract: KeeperAbi
rewardSplitterContract: RewardSplitterAbi
}

const rewardSplittersMulticall = async <T extends unknown>(values: RewardSplittersMulticallInput): Promise<T> => {
const { request, options, userAddress, vaultAddress, keeperContract, rewardSplitterContract } = values
type RewardSplitterMulticallInput = RewardSplitterMulticallBaseInput & {
request: MulticallRequestInput
}

const rewardSplitterMulticall = async <T extends unknown>(values: RewardSplitterMulticallInput): Promise<T> => {
const { request, options, userAddress, vaultAddress, rewardSplitterContract } = values
const { params, callStatic, estimateGas, transactionData } = request

let multicallParams = [ ...params ]
Expand All @@ -36,7 +38,6 @@ const rewardSplittersMulticall = async <T extends unknown>(values: RewardSplitte
const harvestArgs = await getHarvestArgs<RewardSplitterAbi>({
options,
vaultAddress,
keeperContract,
})

if (harvestArgs) {
Expand Down Expand Up @@ -70,4 +71,4 @@ const rewardSplittersMulticall = async <T extends unknown>(values: RewardSplitte
}


export default rewardSplittersMulticall
export default rewardSplitterMulticall
14 changes: 6 additions & 8 deletions src/contracts/multicall/util/getHarvestArgs.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import getHarvestParams from '../../../methods/vault/requests/getHarvestParams'
import type { KeeperAbi } from '../../types'
import type { HarvestParamsQueryPayload } from '../../../graphql/subgraph/vault'


type Input<T> = {
options: StakeWise.Options
vaultAddress: string
keeperContract: KeeperAbi
}

const getHarvestArgs = async <T>(props: Input<T>): Promise<HarvestParamsQueryPayload['harvestParams'] | null> => {
const { options, vaultAddress, keeperContract } = props
const { options, vaultAddress } = props

const [ harvestParams, canHarvest ] = await Promise.all([
getHarvestParams({ options, vaultAddress }),
keeperContract.canHarvest(vaultAddress),
])
const harvestParams = await getHarvestParams({
options,
vaultAddress,
})

if (canHarvest) {
if (harvestParams?.canHarvest) {
return harvestParams
}

Expand Down
13 changes: 7 additions & 6 deletions src/contracts/multicall/vaultMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ import {
} from './util'

import type { MulticallRequestInput } from './types'
import type { KeeperAbi, OtherTokenVaultAbi, VaultAbi } from '../types'
import type { OtherTokenVaultAbi, VaultAbi } from '../types'
import { Network } from '../../utils'


type VaultContractAbi = VaultAbi | OtherTokenVaultAbi

type VaultMulticallInput = {
export type VaultMulticallBaseInput = {
userAddress: string
vaultAddress: string
keeperContract: KeeperAbi
options: StakeWise.Options
request: MulticallRequestInput
vaultContract: VaultContractAbi
}

type VaultMulticallInput = VaultMulticallBaseInput & {
request: MulticallRequestInput
}

// Methods with _checkHarvested() call
const harvestCheckMethods = [
'deposit',
Expand All @@ -43,7 +45,7 @@ const harvestCheckMethods = [
* This method will also add swapXdaiToGno execution if needed.
*/
const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): Promise<T> => {
const { options, vaultAddress, userAddress, request, vaultContract, keeperContract } = values
const { options, vaultAddress, userAddress, request, vaultContract } = values
const { params, callStatic, estimateGas, transactionData } = request

const contract = await getSignedContract({
Expand All @@ -61,7 +63,6 @@ const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): P
const harvestArgs = await getHarvestArgs<VaultContractAbi>({
options,
vaultAddress,
keeperContract,
})

if (harvestArgs) {
Expand Down
1 change: 1 addition & 0 deletions src/graphql/subgraph/vault/harvestParamsQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
query HarvestParams($address: ID!) {
harvestParams: vault(id: $address) {
proof
canHarvest
rewardsRoot
reward: proofReward
unlockedMevReward: proofUnlockedMevReward
Expand Down
5 changes: 5 additions & 0 deletions src/graphql/subgraph/vault/vaultQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ query Vault($address: ID!) {
vault(id: $address) {
address: id
performance: score
osTokenConfig {
ltvPercent
liqThresholdPercent
}
apy
admin
version
Expand All @@ -26,6 +30,7 @@ query Vault($address: ID!) {
validatorsRoot
blocklistCount
whitelistCount
isCollateralized
blocklistManager
validatorsManager
depositDataManager
Expand Down
1 change: 0 additions & 1 deletion src/methods/osToken/transactions/mint/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const commonLogic = (values: MintInput) => {

const multicallArgs: Omit<Parameters<typeof vaultMulticall>[0], 'request'> = {
vaultContract: contracts.helpers.createVault(vaultAddress),
keeperContract: contracts.base.keeper,
vaultAddress,
userAddress,
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const getAssetsFromShares = async (input: GetAssetsFromSharesInput) => {
options,
userAddress,
vaultAddress,
keeperContract: contracts.base.keeper,
vaultContract: contracts.helpers.createVault(vaultAddress),
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const getShares = async (input: GetSharesInput) => {
options,
userAddress,
vaultAddress,
keeperContract: contracts.base.keeper,
rewardSplitterContract: contracts.helpers.createRewardSplitter(rewardSplitterAddress),
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { validateArgs } from '../../../../utils'
import { rewardSplitterMulticall } from '../../../../contracts'
import type { RewardSplitterMulticallBaseInput } from '../../../../contracts'
import type { ClaimRewardsInput } from './types'

import getSharesFromAssets from './getSharesFromAssets'
Expand All @@ -14,9 +15,8 @@ export const commonLogic = async (values: ClaimRewardsInput) => {
validateArgs.address({ vaultAddress, userAddress, rewardSplitterAddress })
validateArgs.bigint({ assets })

const baseMulticall = {
const baseMulticall: RewardSplitterMulticallBaseInput = {
rewardSplitterContract: contracts.helpers.createRewardSplitter(rewardSplitterAddress),
keeperContract: contracts.base.keeper,
vaultAddress,
userAddress,
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const getSharesFromAssets = async (input: GetSharesFromAssetsInput) => {
options,
userAddress,
vaultAddress,
keeperContract: contracts.base.keeper,
vaultContract: contracts.helpers.createVault(vaultAddress),
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isAddress } from 'ethers'
import vault from '../../../vault'
import { validateArgs } from '../../../../utils'
import { rewardSplitterMulticall } from '../../../../contracts'
import type { RewardSplitterMulticallBaseInput } from '../../../../contracts'
import { checkAdminAccess } from '../../../vault/transactions/util'
import type { FeeRecipient, UpdateFeeRecipientsInput } from './types'

Expand Down Expand Up @@ -41,9 +42,8 @@ export const commonLogic = async (values: UpdateFeeRecipientsInput) => {

await checkAdminAccess(values)

const baseMulticall = {
const baseMulticall: RewardSplitterMulticallBaseInput = {
rewardSplitterContract: contracts.helpers.createRewardSplitter(rewardSplitterAddress),
keeperContract: contracts.base.keeper,
vaultAddress,
userAddress,
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('parseExitRequests function', () => {
const network = Network.Holesky
const config = configs[network]

const provider = new JsonRpcProvider(config.network.url)
const provider = new JsonRpcProvider('')
const contracts = createContracts({ provider, config })

const input: ParseExitRequestsInput = {
Expand Down
1 change: 0 additions & 1 deletion src/methods/vault/requests/getStakeBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const getStakeBalance = async (values: GetStakeBalanceInput) => {
userAddress,
vaultAddress,
vaultContract,
keeperContract: contracts.base.keeper,
request: {
callStatic: true,
params: [
Expand Down
32 changes: 9 additions & 23 deletions src/methods/vault/requests/getVault/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { VaultQueryVariables, VaultQueryPayload } from '../../../../graphql/subgraph/vault'
import { wrapAbortPromise } from '../../../../modules/gql-module'
import { apiUrls, validateArgs } from '../../../../utils'
import graphql from '../../../../graphql'
import { ModifiedVault } from './types'
Expand All @@ -8,35 +7,22 @@ import modifyVault from './modifyVault'

type GetVaultInput = {
options: StakeWise.Options
contracts: StakeWise.Contracts
vaultAddress: VaultQueryVariables['address']
}

type GetVaultOutput = ModifiedVault & {
isCollateralized: boolean
}

const getVault = async (input: GetVaultInput) => {
const { contracts, options, vaultAddress } = input
const { options, vaultAddress } = input

validateArgs.address({ vaultAddress })

const [ data, isCollateralized ] = await Promise.all([
graphql.subgraph.vault.fetchVaultQuery<ModifiedVault>({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
address: vaultAddress.toLowerCase(),
},
modifyResult: (data: VaultQueryPayload) => modifyVault({ data, network: options.network }),
}),
contracts.base.keeper.isCollateralized(vaultAddress),
])

return {
...data,
isCollateralized,
}
return graphql.subgraph.vault.fetchVaultQuery<ModifiedVault>({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
address: vaultAddress.toLowerCase(),
},
modifyResult: (data: VaultQueryPayload) => modifyVault({ data, network: options.network }),
})
}


export default wrapAbortPromise<GetVaultInput, GetVaultOutput>(getVault)
export default getVault
5 changes: 5 additions & 0 deletions src/methods/vault/requests/getVault/modifyVault.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('modifyVault', () => {
capacity: '1000000000000000',
validatorsRoot: 'mockValidators',
description: 'This is a mock vault',
isCollateralized: true,
admin: '0xeefffd4c23d2e8c845870e273861e7d60df49663',
address: '0xeefffd4c23d2e8c845870e273861e7d60df49663',
mevEscrow: '0xeefffd4c23d2e8c845870e273861e7d60df49663',
Expand All @@ -40,6 +41,10 @@ describe('modifyVault', () => {
depositDataManager: '0xeefffd4c23d2e8c845870e273861e7d60df49663',
restakeOperatorsManager: '0xeefffd4c23d2e8c845870e273861e7d60df49663',
restakeWithdrawalsManager: '0xeefffd4c23d2e8c845870e273861e7d60df49663',
osTokenConfig: {
ltvPercent: '0',
liqThresholdPercent: '0',
},
},
}

Expand Down
Loading
Loading