Skip to content

Commit 3320f40

Browse files
committed
Merge branch 'main' into for-new-stake
2 parents 2a9b7a1 + a690bba commit 3320f40

File tree

34 files changed

+567
-491
lines changed

34 files changed

+567
-491
lines changed

README.md

+209-225
Large diffs are not rendered by default.

changelog/next-release.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
- Breaking change: Removed `sdk.osToken.getConfig`. Use `sdk.vault.getVault` instead to get osToken config data `{ osTokenConfig: { ltvPercent, thresholdPercent } }`.
2+
- Added canHarvest: boolean to `sdk.vault.getHarvestParams` response.
3+
4+
# Updates
5+
### 1. `sdk.vault.getVault`
6+
7+
#### New output field:
8+
9+
```ts
10+
type AddedOutput = {
11+
osTokenConfig: {
12+
ltvPercent: string
13+
thresholdPercent: string
14+
}
15+
}
16+
```
17+
18+
| Name | Description |
19+
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
20+
| `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 |
21+
22+
---
23+
### 2. `sdk.vault.getHarvestParams`
24+
25+
#### New output field:
26+
27+
```ts
28+
type AddedOutput = {
29+
canHarvest: boolean
30+
}
31+
```
32+
33+
---
34+
35+
### 3. Removed method
36+
### `sdk.vault.getVault`

package-lock.json

+228-177
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.0.2",
2+
"version": "2.1.0",
33
"sideEffects": false,
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
@@ -11,7 +11,7 @@
1111
"homepage": "https://github.com/stakewise/v3-sdk",
1212
"scripts": {
1313
"test": "jest --clearCache && jest --onlyChanged",
14-
"prepare": "npm run typechain && npm run graphql && husky install && npm run beforePublish",
14+
"prepare": "npm run typechain && npm run graphql && npm run beforePublish",
1515
"build": "npm run test && npm run prepare && rm -rf ./dist && npm run rollup",
1616
"typechain": "typechain --target ethers-v6 --out-dir src/contracts/types 'src/contracts/abis/*.json'",
1717
"graphql": "graphql-codegen && ts-node -O '{\"module\": \"commonjs\"}' ./scripts/generateGraphqlExports",
@@ -65,7 +65,6 @@
6565
"eslint-plugin-import": "2.29.1",
6666
"hardhat": "2.22.8",
6767
"hardhat-jest-plugin": "0.0.6",
68-
"husky": "9.1.4",
6968
"jest": "29.7.0",
7069
"jest-fetch-mock": "3.0.3",
7170
"regenerator-runtime": "0.14.1",

src/StakeWiseSDK.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class StakeWiseSDK {
3232
constructor(options: StakeWise.Options) {
3333
const config = configs[options.network]
3434

35+
if (!options.provider && !options.endpoints?.web3) {
36+
throw new Error('Provider or endpoints.web3 should be provided')
37+
}
38+
3539
const provider = options.provider || createProvider(options)
3640

3741
const contracts = createContracts({ provider, config })
@@ -59,7 +63,6 @@ class StakeWiseSDK {
5963
})
6064

6165
return vaultMulticall<T>({
62-
keeperContract: this.contracts.base.keeper,
6366
options: this.options,
6467
vaultContract,
6568
vaultAddress,
@@ -82,7 +85,6 @@ class StakeWiseSDK {
8285

8386
return rewardSplitterMulticall<T>({
8487
rewardSplitterContract: this.contracts.helpers.createRewardSplitter(rewardSplitterAddress),
85-
keeperContract: this.contracts.base.keeper,
8688
options: this.options,
8789
vaultAddress,
8890
userAddress,

src/contracts/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export { default as createContract } from './createContract'
22
export { default as createContracts } from './createContracts'
33
export { default as multicall } from './multicall/commonMulticall'
4-
export { default as vaultMulticall } from './multicall/vaultMulticall'
54
export { default as eigenPodOwnerMulticall } from './multicall/eigenPodOwnerMulticall'
6-
export { default as rewardSplitterMulticall } from './multicall/rewardSplitterMulticall'
5+
6+
export { vaultMulticall, rewardSplitterMulticall } from './multicall'
7+
export type { VaultMulticallBaseInput, RewardSplitterMulticallBaseInput } from './multicall'

src/contracts/multicall/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export { default as vaultMulticall } from './vaultMulticall'
21
export { default as commonMulticall } from './commonMulticall'
3-
export { default as rewardSplitterMulticall } from './rewardSplitterMulticall'
42

3+
export { default as vaultMulticall } from './vaultMulticall'
4+
export type { VaultMulticallBaseInput } from './vaultMulticall'
5+
6+
export { default as rewardSplitterMulticall } from './rewardSplitterMulticall'
7+
export type { RewardSplitterMulticallBaseInput } from './rewardSplitterMulticall'

src/contracts/multicall/rewardSplitterMulticall.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@ import {
77
handleTransactionData,
88
} from './util'
99

10-
import type { KeeperAbi, RewardSplitterAbi } from '../types'
10+
import type { RewardSplitterAbi } from '../types'
1111
import type { MulticallRequestInput } from './types'
1212

1313

14-
type RewardSplittersMulticallInput = {
14+
export type RewardSplitterMulticallBaseInput = {
1515
userAddress: string
1616
vaultAddress: string
1717
options: StakeWise.Options
18-
request: MulticallRequestInput
19-
keeperContract: KeeperAbi
2018
rewardSplitterContract: RewardSplitterAbi
2119
}
2220

23-
const rewardSplittersMulticall = async <T extends unknown>(values: RewardSplittersMulticallInput): Promise<T> => {
24-
const { request, options, userAddress, vaultAddress, keeperContract, rewardSplitterContract } = values
21+
type RewardSplitterMulticallInput = RewardSplitterMulticallBaseInput & {
22+
request: MulticallRequestInput
23+
}
24+
25+
const rewardSplitterMulticall = async <T extends unknown>(values: RewardSplitterMulticallInput): Promise<T> => {
26+
const { request, options, userAddress, vaultAddress, rewardSplitterContract } = values
2527
const { params, callStatic, estimateGas, transactionData } = request
2628

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

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

7273

73-
export default rewardSplittersMulticall
74+
export default rewardSplitterMulticall

src/contracts/multicall/util/getHarvestArgs.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import getHarvestParams from '../../../methods/vault/requests/getHarvestParams'
2-
import type { KeeperAbi } from '../../types'
32
import type { HarvestParamsQueryPayload } from '../../../graphql/subgraph/vault'
43

54

65
type Input<T> = {
76
options: StakeWise.Options
87
vaultAddress: string
9-
keeperContract: KeeperAbi
108
}
119

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

15-
const [ harvestParams, canHarvest ] = await Promise.all([
16-
getHarvestParams({ options, vaultAddress }),
17-
keeperContract.canHarvest(vaultAddress),
18-
])
13+
const harvestParams = await getHarvestParams({
14+
options,
15+
vaultAddress,
16+
})
1917

20-
if (canHarvest) {
18+
if (harvestParams?.canHarvest) {
2119
return harvestParams
2220
}
2321

src/contracts/multicall/util/handleCallStatic.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,27 @@ type Input = {
1212
const deleteResultFromMethods = [
1313
'updateState',
1414
'swapXdaiToGno',
15+
'updateVaultState',
1516
]
1617

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

21-
const idexesToDeleteResult: number[] = []
22+
const indexesToDeleteResult: number[] = []
2223

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

2627
if (deleteResultFromMethods.includes(method)) {
27-
idexesToDeleteResult.push(index)
28+
indexesToDeleteResult.push(index)
2829
}
2930

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

34-
return formattedResult.filter((_, index) => !idexesToDeleteResult.includes(index))
35+
return formattedResult.filter((_, index) => !indexesToDeleteResult.includes(index))
3536
}
3637

3738

src/contracts/multicall/vaultMulticall.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ import {
99
} from './util'
1010

1111
import type { MulticallRequestInput } from './types'
12-
import type { KeeperAbi, OtherTokenVaultAbi, VaultAbi } from '../types'
12+
import type { OtherTokenVaultAbi, VaultAbi } from '../types'
1313
import { Network } from '../../utils'
1414

1515

1616
type VaultContractAbi = VaultAbi | OtherTokenVaultAbi
1717

18-
type VaultMulticallInput = {
18+
export type VaultMulticallBaseInput = {
1919
userAddress: string
2020
vaultAddress: string
21-
keeperContract: KeeperAbi
2221
options: StakeWise.Options
23-
request: MulticallRequestInput
2422
vaultContract: VaultContractAbi
2523
}
2624

25+
type VaultMulticallInput = VaultMulticallBaseInput & {
26+
request: MulticallRequestInput
27+
}
28+
2729
// Methods with _checkHarvested() call
2830
const harvestCheckMethods = [
2931
'deposit',
@@ -43,7 +45,7 @@ const harvestCheckMethods = [
4345
* This method will also add swapXdaiToGno execution if needed.
4446
*/
4547
const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): Promise<T> => {
46-
const { options, vaultAddress, userAddress, request, vaultContract, keeperContract } = values
48+
const { options, vaultAddress, userAddress, request, vaultContract } = values
4749
const { params, callStatic, estimateGas, transactionData } = request
4850

4951
const contract = await getSignedContract({
@@ -61,7 +63,6 @@ const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): P
6163
const harvestArgs = await getHarvestArgs<VaultContractAbi>({
6264
options,
6365
vaultAddress,
64-
keeperContract,
6566
})
6667

6768
if (harvestArgs) {

src/graphql/subgraph/vault/harvestParamsQuery.graphql

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
query HarvestParams($address: ID!) {
22
harvestParams: vault(id: $address) {
33
proof
4+
canHarvest
45
rewardsRoot
56
reward: proofReward
67
unlockedMevReward: proofUnlockedMevReward

src/graphql/subgraph/vault/vaultQuery.graphql

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ query Vault($address: ID!) {
22
vault(id: $address) {
33
address: id
44
performance: score
5+
osTokenConfig {
6+
ltvPercent
7+
liqThresholdPercent
8+
}
59
apy
610
admin
711
version
@@ -26,6 +30,7 @@ query Vault($address: ID!) {
2630
validatorsRoot
2731
blocklistCount
2832
whitelistCount
33+
isCollateralized
2934
blocklistManager
3035
validatorsManager
3136
depositDataManager

src/methods/osToken/transactions/mint/common.ts

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const commonLogic = (values: MintInput) => {
1313

1414
const multicallArgs: Omit<Parameters<typeof vaultMulticall>[0], 'request'> = {
1515
vaultContract: contracts.helpers.createVault(vaultAddress),
16-
keeperContract: contracts.base.keeper,
1716
vaultAddress,
1817
userAddress,
1918
options,

src/methods/rewardSplitter/requests/getClaimAmount/getAssetsFromShares.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const getAssetsFromShares = async (input: GetAssetsFromSharesInput) => {
2424
options,
2525
userAddress,
2626
vaultAddress,
27-
keeperContract: contracts.base.keeper,
2827
vaultContract: contracts.helpers.createVault(vaultAddress),
2928
})
3029

src/methods/rewardSplitter/requests/getClaimAmount/getShares.ts

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const getShares = async (input: GetSharesInput) => {
2525
options,
2626
userAddress,
2727
vaultAddress,
28-
keeperContract: contracts.base.keeper,
2928
rewardSplitterContract: contracts.helpers.createRewardSplitter(rewardSplitterAddress),
3029
})
3130

src/methods/rewardSplitter/transactions/claimRewards/common.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { validateArgs } from '../../../../utils'
22
import { rewardSplitterMulticall } from '../../../../contracts'
3+
import type { RewardSplitterMulticallBaseInput } from '../../../../contracts'
34
import type { ClaimRewardsInput } from './types'
45

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

17-
const baseMulticall = {
18+
const baseMulticall: RewardSplitterMulticallBaseInput = {
1819
rewardSplitterContract: contracts.helpers.createRewardSplitter(rewardSplitterAddress),
19-
keeperContract: contracts.base.keeper,
2020
vaultAddress,
2121
userAddress,
2222
options,

src/methods/rewardSplitter/transactions/claimRewards/getSharesFromAssets.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const getSharesFromAssets = async (input: GetSharesFromAssetsInput) => {
2424
options,
2525
userAddress,
2626
vaultAddress,
27-
keeperContract: contracts.base.keeper,
2827
vaultContract: contracts.helpers.createVault(vaultAddress),
2928
})
3029

src/methods/rewardSplitter/transactions/updateFeeRecipients/common.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isAddress } from 'ethers'
33
import vault from '../../../vault'
44
import { validateArgs } from '../../../../utils'
55
import { rewardSplitterMulticall } from '../../../../contracts'
6+
import type { RewardSplitterMulticallBaseInput } from '../../../../contracts'
67
import { checkAdminAccess } from '../../../vault/transactions/util'
78
import type { FeeRecipient, UpdateFeeRecipientsInput } from './types'
89

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

4243
await checkAdminAccess(values)
4344

44-
const baseMulticall = {
45+
const baseMulticall: RewardSplitterMulticallBaseInput = {
4546
rewardSplitterContract: contracts.helpers.createRewardSplitter(rewardSplitterAddress),
46-
keeperContract: contracts.base.keeper,
4747
vaultAddress,
4848
userAddress,
4949
options,

src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('parseExitRequests function', () => {
2020
const network = Network.Holesky
2121
const config = configs[network]
2222

23-
const provider = new JsonRpcProvider(config.network.url)
23+
const provider = new JsonRpcProvider('')
2424
const contracts = createContracts({ provider, config })
2525

2626
const input: ParseExitRequestsInput = {
@@ -137,7 +137,7 @@ describe('parseExitRequests function', () => {
137137

138138
expect(result).toEqual({
139139
total: 100n,
140-
duration: 0,
140+
duration: 1718536919,
141141
positions: [],
142142
withdrawable: 0n,
143143
pending: [
@@ -171,9 +171,9 @@ describe('parseExitRequests function', () => {
171171

172172
expect(result).toEqual({
173173
total: 50n,
174-
duration: 0,
175174
positions: [],
176175
withdrawable: 0n,
176+
duration: 1718536919,
177177
pending: [
178178
{
179179
positionTicket: 'positionTicket-1',

0 commit comments

Comments
 (0)