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

SDK vault methods #84

Merged
merged 18 commits into from
Mar 29, 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
136 changes: 66 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,12 @@ promise.abort()
```

##### Table of transactions:
| **Vault** | **osToken** |
|-------------------------------------------------------|------|
| [sdk.vault.deposit](#sdkvaultdeposit) | [sdk.osToken.mint](#sdkostokenmint) |
| [sdk.vault.withdraw](#sdkvaultwithdraw) | [sdk.osToken.burn](#sdkostokenburn) |
| [sdk.vault.claimExitQueue](#sdkvaultclaimexitqueue) |
| [sdk.vault.updateWhitelist](#sdkvaultupdatewhitelist) |
| [sdk.vault.updateBlocklist](#sdkvaultupdateblocklist) |
| **Vault** | **osToken** |
|-----------------------------------------------------------------------------|------|
| [sdk.vault.deposit](#sdkvaultdeposit) | [sdk.osToken.mint](#sdkostokenmint) |
| [sdk.vault.withdraw](#sdkvaultwithdraw) | [sdk.osToken.burn](#sdkostokenburn) |
| [sdk.claimExitQueue](#sdkvaultclaimexitqueue) |
| [sdk.vault.operate](#sdkvaultoperate) |

## API-Vault

Expand Down Expand Up @@ -1099,95 +1098,92 @@ const { data, to } = await sdk.vault.claimExitQueue.encode(params)
const gas = await sdk.vault.claimExitQueue.estimateGas(params)
```
---
### `sdk.vault.updateWhitelist`
### `sdk.vault.operate`

#### Description:

Update the whitelist of addresses for a private vault.
The whitelist contains addresses allowed to stake or mint within
the private vault. This method can only be called by the vault
access manager.
Updates the vault by authorized personnel such as the vault admin, whitelister, blocklist manager, or keys manager.


#### Arguments:

| Name | Type | Required | Description |
|------|----------------------------------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------|
| whitelist | `Array<{ address: string, isNew: boolean }>` | **Yes** | List of addresses to update the whitelist. Use `isNew: true` to add a new address, `isNew: false` to remove an existing one |
| userAddress | `string` | **Yes** | The address of the user making the update (access manager) |
| vaultAddress | `string` | **Yes** | The address of the private vault |
| Name | Type | Required | Access | Description |
|--------------|----------------------------------------------|----------|-------------------|-----------------------------------------------------------------------------------------------------------------------------|
| whitelist | `Array<{ address: string, isNew: boolean }>` | **No** | Whitelister | List of addresses to update the whitelist. Use `isNew: true` to add a new address, `isNew: false` to remove an existing one |
| blocklist | `Array<{ address: string, isNew: boolean }>` | **No** | Blocklist manager | List of addresses to update the blocklist. Use `isNew: true` to add a new address, `isNew: false` to remove an existing one |
| keysManager | `string` | **No** | Admin | Address of the vault keys manager |
| whitelister | `string` | **No** | Admin | Address of the vault whitelister |
| feeRecipient | `string` | **No** | Admin | Address of the vault fee recipient |
| validatorsRoot | `string` | **No** | Keys manager | The vault validators merkle tree root |
| blocklistManager | `string` | **No** | Admin | The blocklisted vault blocklist manager |
| metadataIpfsHash | `string` | **No** | Admin | The vault metadata IPFS hash |
| userAddress | `string` | **Yes** | - | The address of the user making the update (admin, whitelister, blocklist manager or keys manager) |
| vaultAddress | `string` | **Yes** | - | The address of the vault |

#### Example:

```ts
const whitelist = [
{
address: '0x...',
isNew: true,
},
{
address: '0x...',
isNew: false,
},
]

// Data to update the vault by admin.
const params = {
whitelist,
keysManager: '0x...',
whitelister: '0x...',
feeRecipient: '0x...',
validatorsRoot: '0x...',
blocklistManager: '0x...',
metadataIpfsHash: '...',
vaultAddress: '0x...',
userAddress: '0x...',
}

// Send transaction
const hash = await sdk.vault.updateWhitelist(params)
// When you sign transactions on the backend (for custodians)
const { data, to } = await sdk.vault.updateWhitelist.encode(params)
// Get an approximate gas per transaction
const gas = await sdk.vault.updateWhitelist.estimateGas(params)
```
---
### `sdk.vault.updateBlocklist`

#### Description:

Update the blocklist of addresses for a blocklisted vault.
The blocklist contains addresses disallowed to stake or mint within
the blocklisted vault. This method can only be called by the vault
access manager.

#### Arguments:

| Name | Type | Required | Description |
|--------------|----------------------------------------------|-------------|------------------------------------------------------------------------------------------------------------------------------|
| blocklist | `Array<{ address: string, isNew: boolean }>` | **Yes** | List of addresses to update the blocklist. Use `isNew: true` to add a new address, `isNew: false` to remove an existing one |
| userAddress | `string` | **Yes** | The address of the user making the update (access manager) |
| vaultAddress | `string` | **Yes** | The address of the blocklisted vault |

#### Example:
// Data to update the vault by vault keys manager.
const params = {
validatorsRoot: '...',
vaultAddress: '0x...',
userAddress: '0x...',
}

```ts
const blocklist = [
{
address: '0x...',
isNew: true,
},
{
address: '0x...',
isNew: false,
},
]
// Data to update the private vault by whitelister.
// The whitelist contains addresses allowed to stake or mint within
// the vault.
const params = {
whitelist: [
{
address: '0x...',
isNew: true,
},
{
address: '0x...',
isNew: false,
},
],
vaultAddress: '0x...',
userAddress: '0x...',
}

// Data to update blocklisted vault by blocklist manager.
// The blocklist contains addresses disallowed to stake or mint within
// the vault.
const params = {
blocklist,
blocklist: [
{
address: '0x...',
isNew: true,
},
{
address: '0x...',
isNew: false,
},
],
vaultAddress: '0x...',
userAddress: '0x...',
}

// Send transaction
const hash = await sdk.vault.updateBlocklist(params)
const hash = await sdk.vault.operate(params)
// When you sign transactions on the backend (for custodians)
const { data, to } = await sdk.vault.updateBlocklist.encode(params)
const { data, to } = await sdk.vault.operate.encode(params)
// Get an approximate gas per transaction
const gas = await sdk.vault.updateBlockList.estimateGas(params)
const gas = await sdk.vault.operate.estimateGas(params)
```
---
### `sdk.osToken.mint`
Expand Down
13 changes: 13 additions & 0 deletions src/contracts/abis/BlocklistVaultDiffAbi.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[
{
"inputs": [],
"name": "blocklistManager",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
13 changes: 13 additions & 0 deletions src/contracts/abis/PrivateVaultDiffAbi.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[
{
"inputs": [],
"name": "whitelister",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
26 changes: 26 additions & 0 deletions src/contracts/abis/VaultAbi.json
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,32 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "admin",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "keysManager",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/createContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const createContracts = (input: CreateContractsInput) => {
createVault: (address: string) => createContract<StakeWise.ABI.Vault>(address, VaultAbi, provider),
createUniswapPool: (address: string) => createContract<StakeWise.ABI.UniswapPool>(address, UniswapPoolAbi, provider),
createPrivateVault: (address: string) => createContract<StakeWise.ABI.PrivateVault>(address, PrivateVaultAbi, provider),
createBlocklistVault: (address: string) => createContract<StakeWise.ABI.BlocklistVault>(address, BlocklistVaultAbi, provider),
createBlocklistedVault: (address: string) => createContract<StakeWise.ABI.BlocklistVault>(address, BlocklistVaultAbi, provider),
createRewardSplitter: (address: string) => createContract<StakeWise.ABI.RewardSplitter>(address, RewardSplitterAbi, provider),
createOtherTokenVault: (address: string) => createContract<StakeWise.ABI.OtherTokenVault>(address, OtherTokenVaultAbi, provider),
createVestingEscrowDirect: (address: string) => createContract<StakeWise.ABI.VestingEscrow>(address, VestingEscrowAbi, provider),
Expand Down
29 changes: 22 additions & 7 deletions src/contracts/vaultMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ type VaultMulticallInput = {
vaultContract: VaultAbi | OtherTokenVaultAbi
}

// Methods with _checkHarvested() call
const harvestCheckMethods = [
'deposit',
'mintOsToken',
'enterExitQueue',
'setFeeRecipient',
'claimExitedAssets',
]

const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): Promise<T> => {
const { options, vaultAddress, userAddress, request, vaultContract, keeperContract } = values
const { params, callStatic, estimateGas, transactionData } = request
Expand All @@ -44,15 +53,21 @@ const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): P
contract = vaultContract.connect(signer)
}

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

if (canHarvest) {
const fragment = contract.interface.encodeFunctionData('updateState', [ harvestParams ])
const needHarvest = params.some(({ method }) => harvestCheckMethods.includes(method))

calls.push(fragment)
if (needHarvest) {
const [ harvestParams ] = await Promise.all([
getHarvestParams({ options, vaultAddress }),
keeperContract.canHarvest(vaultAddress).then((value) => canHarvest = value),
])

if (canHarvest) {
const fragment = contract.interface.encodeFunctionData('updateState', [ harvestParams ])

calls.push(fragment)
}
}

params.forEach(({ method, args }) => {
Expand Down
12 changes: 5 additions & 7 deletions src/methods/vault/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import getScorePercentiles from './requests/getScorePercentiles'
import getExitQueuePositions from './requests/getExitQueuePositions'

// Transactions
import { deposit } from './transactions/deposit'
import { withdraw } from './transactions/withdraw'
import { claimExitQueue } from './transactions/claimExitQueue'
import { updateWhitelist } from './transactions/updateWhitelist'
import { updateBlocklist } from './transactions/updateBlocklist'
import { default as deposit } from './transactions/deposit'
import { default as operate } from './transactions/operate'
import { default as withdraw } from './transactions/withdraw'
import { default as claimExitQueue } from './transactions/claimExitQueue'


export default {
Expand All @@ -37,9 +36,8 @@ export default {
},
transactions: {
deposit,
operate,
withdraw,
claimExitQueue,
updateWhitelist,
updateBlocklist,
},
} as const
3 changes: 2 additions & 1 deletion src/methods/vault/requests/getExitQueuePositions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { validateArgs } from '../../../../utils'
import parseExitRequests from './parseExitRequests'
import fetchExitQueuePositions from './fetchExitQueuePositions'
import type { ParseExitRequestsOutput } from './parseExitRequests'
import type { FetchExitQueuePositionsInput } from './fetchExitQueuePositions'


Expand All @@ -16,7 +17,7 @@ const mock = {
withdrawable: 0n,
}

const getExitQueuePositions = async (input: GetExitQueuePositionsInput) => {
const getExitQueuePositions = async (input: GetExitQueuePositionsInput): Promise<ParseExitRequestsOutput> => {
const { options, contracts, provider, vaultAddress, userAddress } = input

validateArgs.address({ vaultAddress, userAddress })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Position = {
timestamp: string
}

type ParseExitRequestsOutput = {
export type ParseExitRequestsOutput = {
total: bigint
withdrawable: bigint
positions: Position[]
Expand Down
25 changes: 0 additions & 25 deletions src/methods/vault/transactions/claimExitQueue/claimExitQueue.ts

This file was deleted.

Loading