Skip to content

Commit

Permalink
Merge branch 'main' into for-new-stake
Browse files Browse the repository at this point in the history
  • Loading branch information
Cast0001 committed Sep 9, 2024
2 parents 2a9b7a1 + a690bba commit 3320f40
Show file tree
Hide file tree
Showing 34 changed files with 567 additions and 491 deletions.
434 changes: 209 additions & 225 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`
405 changes: 228 additions & 177 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.2",
"version": "2.1.0",
"sideEffects": false,
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -11,7 +11,7 @@
"homepage": "https://github.com/stakewise/v3-sdk",
"scripts": {
"test": "jest --clearCache && jest --onlyChanged",
"prepare": "npm run typechain && npm run graphql && husky install && npm run beforePublish",
"prepare": "npm run typechain && npm run graphql && npm run beforePublish",
"build": "npm run test && npm run prepare && rm -rf ./dist && npm run rollup",
"typechain": "typechain --target ethers-v6 --out-dir src/contracts/types 'src/contracts/abis/*.json'",
"graphql": "graphql-codegen && ts-node -O '{\"module\": \"commonjs\"}' ./scripts/generateGraphqlExports",
Expand Down Expand Up @@ -65,7 +65,6 @@
"eslint-plugin-import": "2.29.1",
"hardhat": "2.22.8",
"hardhat-jest-plugin": "0.0.6",
"husky": "9.1.4",
"jest": "29.7.0",
"jest-fetch-mock": "3.0.3",
"regenerator-runtime": "0.14.1",
Expand Down
6 changes: 4 additions & 2 deletions src/StakeWiseSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class StakeWiseSDK {
constructor(options: StakeWise.Options) {
const config = configs[options.network]

if (!options.provider && !options.endpoints?.web3) {
throw new Error('Provider or endpoints.web3 should be provided')
}

const provider = options.provider || createProvider(options)

const contracts = createContracts({ provider, config })
Expand Down Expand Up @@ -59,7 +63,6 @@ class StakeWiseSDK {
})

return vaultMulticall<T>({
keeperContract: this.contracts.base.keeper,
options: this.options,
vaultContract,
vaultAddress,
Expand All @@ -82,7 +85,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 createContract } from './createContract'
export { default as createContracts } from './createContracts'
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
7 changes: 4 additions & 3 deletions src/contracts/multicall/util/handleCallStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,27 @@ type Input = {
const deleteResultFromMethods = [
'updateState',
'swapXdaiToGno',
'updateVaultState',
]

const handleCallStatic = async ({ contract, multicallParams, userAddress }: Input) => {
const calls = getMulticallCalls({ multicallParams, contract })
const result = await contract.multicall.staticCall(calls, { from: userAddress })

const idexesToDeleteResult: number[] = []
const indexesToDeleteResult: number[] = []

const formattedResult = result.map((data: any, index: number) => {
const { method } = multicallParams[index]

if (deleteResultFromMethods.includes(method)) {
idexesToDeleteResult.push(index)
indexesToDeleteResult.push(index)
}

// @ts-ignore: TS has limitations when dealing with overloads
return contract.interface.decodeFunctionResult(method, data)
})

return formattedResult.filter((_, index) => !idexesToDeleteResult.includes(index))
return formattedResult.filter((_, index) => !indexesToDeleteResult.includes(index))
}


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 Expand Up @@ -137,7 +137,7 @@ describe('parseExitRequests function', () => {

expect(result).toEqual({
total: 100n,
duration: 0,
duration: 1718536919,
positions: [],
withdrawable: 0n,
pending: [
Expand Down Expand Up @@ -171,9 +171,9 @@ describe('parseExitRequests function', () => {

expect(result).toEqual({
total: 50n,
duration: 0,
positions: [],
withdrawable: 0n,
duration: 1718536919,
pending: [
{
positionTicket: 'positionTicket-1',
Expand Down
Loading

0 comments on commit 3320f40

Please sign in to comment.