Skip to content

Commit

Permalink
SDK vault methods (#84)
Browse files Browse the repository at this point in the history
* [sdk vault methods] update transactions

* [sdk vault methods] update check access

* [sdk vault methods] update methods

* [sdk vault methods] add operate multicall

* [sdk vault methods] update sdk multicall

* [sdk vault methods] update sdk multicall

* [sdk vault methods] update readme

* [sdk vault methods] update sdk

* [sdk vault methods] update sdk

* [sdk vault methods] fix types

* [sdk vault methods] update readme

* [sdk vault methods] update deps

* [sdk vault methods] update validation

* [sdk vault methods] update operate contract

* [sdk vault methods] update v3 sdk

* [sdk vault methods] update v3 sdk

* [sdk vault methods] update v3 sdk
  • Loading branch information
mike-diamond committed Apr 24, 2024
1 parent 9599079 commit d04cab9
Show file tree
Hide file tree
Showing 67 changed files with 875 additions and 547 deletions.
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 @@ -118,7 +118,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
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
25 changes: 0 additions & 25 deletions src/methods/vault/transactions/claimExitQueue/claimExitQueue.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { getMulticallEncode } from '../../utils'
import { commonLogic } from './common'
import { ClaimExitQueueInput } from './types'
import { vaultMulticall } from '../../../../contracts'
import type { ClaimExitQueueInput } from './types'


const claimExitQueueEncode = async (values: ClaimExitQueueInput): Promise<StakeWise.TransactionData> => {
const { params, multicallArgs } = await commonLogic(values)
const claimExitQueueEncode = (values: ClaimExitQueueInput) => {
const multicallArgs = commonLogic(values)

const rx = await vaultMulticall<{ data: string, to: string }>({
...multicallArgs,
request: {
params,
transactionData: true,
},
})

return {
data: rx.data,
to: rx.to,
}
return getMulticallEncode(multicallArgs)
}


Expand Down
Loading

0 comments on commit d04cab9

Please sign in to comment.