Skip to content

Commit

Permalink
[sdk vault methods] update sdk multicall
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-diamond committed Mar 28, 2024
1 parent 5d4d664 commit 69cd1e8
Show file tree
Hide file tree
Showing 27 changed files with 169 additions and 176 deletions.
49 changes: 20 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +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.claimExitQueue](#sdkvaultclaimexitqueue) |
| [sdk.vault.operate.multicall](#sdkvaultoperatemulticall) |
| [sdk.vault.operate.setFeeRecipient](#sdkvaultoperatesetfeerecipient) |
| [sdk.vault.operate.setMetadata](#sdkvaultoperatesetmetadata) |
| [sdk.vault.operate.setWhitelister](#sdkvaultoperatesetwhitelister) |
| [sdk.vault.operate.setKeysManager](#sdkvaultoperatesetkeysmanager) |
| [sdk.vault.operate.updateWhitelist](#sdkvaultoperateupdatewhitelist) |
| [sdk.vault.operate.updateBlocklist](#sdkvaultoperateupdateblocklist) |
| [sdk.vault.operate.setValidatorsRoot](#sdkvaultoperatesetvalidatorsroot) |
| [sdk.vault.operate.setBlocklistManager](#sdkvaultoperatesetblocklistmanager) |
| **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 @@ -1137,28 +1129,27 @@ const { data, to } = await sdk.vault.claimExitQueue.encode(params)
const gas = await sdk.vault.claimExitQueue.estimateGas(params)
```
---
### `sdk.vault.operate.multicall`
### `sdk.vault.operate`

#### Description:

Calls any vault.operate methods within one transaction.
Saves gas when it is needed to make more than one call.
Updates vault by the vault admin, whitelister, blocklist manager or keys manager.


#### Arguments:

| Name | Type | Required | Description |
|--------------|----------------------------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------|
| whitelist | `Array<{ address: string, isNew: boolean }>` | **No** | 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** | 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** | Address of the vault keys manager |
| whitelister | `string` | **No** | Address of the vault whitelister |
| feeRecipient | `string` | **No** | Address of the vault fee recipient |
| validatorsRoot | `string` | **No** | The vault validators merkle tree root |
| blocklistManager | `string` | **No** | The blocklisted vault blocklist manager |
| metadataIpfsHash | `string` | **No** | The vault metadata IPFS hash |
| 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 (access manager) |
| vaultAddress | `string` | **Yes** | - | The address of the private vault |

#### Example:

Expand Down
2 changes: 0 additions & 2 deletions src/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type Methods = (
typeof utils

| typeof vault.requests
| typeof vault.operations
| typeof vault.transactions

| typeof osToken.requests
Expand Down Expand Up @@ -88,7 +87,6 @@ const methods = {
createVaultMethods: (params: CommonParams) => ({
...createMethods<typeof vault.requests>(vault.requests, params),
...createMethods<typeof vault.transactions>(vault.transactions, params),
operate: createMethods<typeof vault.operations>(vault.operations, params),
}),
createOsTokenMethods: (params: CommonParams) => ({
...createMethods<typeof osToken.requests>(osToken.requests, params),
Expand Down
24 changes: 2 additions & 22 deletions src/methods/vault/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,10 @@ import getExitQueuePositions from './requests/getExitQueuePositions'

// Transactions
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'

// Operations
import { default as multicall } from './operations/multicall'
import { default as setMetadata } from './operations/setMetadata'
import { default as setWhitelister } from './operations/setWhitelister'
import { default as setKeysManager } from './operations/setKeysManager'
import { default as updateWhitelist } from './operations/updateWhitelist'
import { default as updateBlocklist } from './operations/updateBlocklist'
import { default as setFeeRecipient } from './operations/setFeeRecipient'
import { default as setValidatorsRoot } from './operations/setValidatorsRoot'
import { default as setBlocklistManager } from './operations/setBlocklistManager'


export default {
requests: {
Expand All @@ -46,18 +36,8 @@ export default {
},
transactions: {
deposit,
operate,
withdraw,
claimExitQueue,
},
operations: {
multicall,
setMetadata,
setWhitelister,
setKeysManager,
setFeeRecipient,
updateWhitelist,
updateBlocklist,
setValidatorsRoot,
setBlocklistManager,
},
} as const
88 changes: 0 additions & 88 deletions src/methods/vault/operations/multicall/common.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/methods/vault/operations/util/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Action } from '../util'
import { checkAccessCommon } from '../util'
import type { Action } from './util'
import { checkAccessCommon } from './util'
import type { MulticallInput as Input } from './types'


Expand Down
88 changes: 88 additions & 0 deletions src/methods/vault/transactions/operate/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { validateArgs } from '../../../../utils'
import { vaultMulticall } from '../../../../contracts'
import type { MulticallInput } from './types'

import getMetadataParams from './util/params/getMetadataParams'
import getBlocklistParams from './util/params/getBlocklistParams'
import getWhitelistParams from './util/params/getWhitelistParams'
import getKeysManagerParams from './util/params/getKeysManagerParams'
import getWhitelisterParams from './util/params/getWhitelisterParams'
import getFeeRecipientParams from './util/params/getFeeRecipientParams'
import getValidatorsRootParams from './util/params/getValidatorsRootParams'
import getBlocklistManagerParams from './util/params/getBlocklistManagerParams'


export const commonLogic = (values: MulticallInput) => {
const {
options, contracts, userAddress, vaultAddress, provider,
blocklist, whitelist, keysManager, whitelister, feeRecipient, validatorsRoot, blocklistManager, metadataIpfsHash,
} = values

validateArgs.address({ vaultAddress, userAddress })

const baseMulticall = {
vaultContract: contracts.helpers.createBlocklistedVault(vaultAddress),
keeperContract: contracts.base.keeper,
vaultAddress,
userAddress,
options,
}

const baseInput = {
options,
provider,
contracts,
userAddress,
vaultAddress,
}

const params: Parameters<typeof vaultMulticall>[0]['request']['params'] = []

if (blocklist) {
const blocklistParams = getBlocklistParams({ ...baseInput, blocklist })

params.push(...blocklistParams)
}
if (whitelist) {
const whitelistParams = getWhitelistParams({ ...baseInput, whitelist })

params.push(...whitelistParams)
}
if (keysManager) {
const keysManagerParams = getKeysManagerParams({ ...baseInput, keysManager })

params.push(...keysManagerParams)
}
if (whitelister) {
const whitelisterParams = getWhitelisterParams({ ...baseInput, whitelister })

params.push(...whitelisterParams)
}
if (feeRecipient) {
const feeRecipientParams = getFeeRecipientParams({ ...baseInput, feeRecipient })

params.push(...feeRecipientParams)
}
if (validatorsRoot) {
const validatorsRootParams = getValidatorsRootParams({ ...baseInput, validatorsRoot })

params.push(...validatorsRootParams)
}
if (metadataIpfsHash) {
const metadataParams = getMetadataParams({ ...baseInput, metadataIpfsHash })

params.push(...metadataParams)
}
if (blocklistManager) {
const blocklistManagerParams = getBlocklistManagerParams({ ...baseInput, blocklistManager })

params.push(...blocklistManagerParams)
}

return {
...baseMulticall,
request: {
params,
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import type { Multicall } from './types'
import { vaultMulticall } from '../../../../contracts'


const multicall: Multicall = async (values) => {
const operate: Multicall = async (values) => {
const multicallCommonArgs = commonLogic(values)

const result = await vaultMulticall<{ hash: string }>(multicallCommonArgs)

return result.hash
}

multicall.encode = checkAccess<StakeWise.TransactionData>(multicallEncode)
multicall.estimateGas = checkAccess<bigint>(multicallGas)
operate.encode = checkAccess<StakeWise.TransactionData>(multicallEncode)
operate.estimateGas = checkAccess<bigint>(multicallGas)


export default checkAccess<string>(multicall)
export default checkAccess<string>(operate)
3 changes: 3 additions & 0 deletions src/methods/vault/transactions/operate/util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type { Action, CheckInput } from './check/types'
export { default as validateList } from './validateList'
export { default as checkAccessCommon } from './check/checkAccessCommon'
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { validateArgs } from '../../../../utils'
import { vaultMulticall } from '../../../../contracts'
import { validateArgs } from '../../../../../../utils'
import { vaultMulticall } from '../../../../../../contracts'


export type SetBlocklistManagerParams = {
blocklistManager: string
}

export const getParams = (values: SetBlocklistManagerParams) => {
const getParams = (values: SetBlocklistManagerParams) => {
const { blocklistManager } = values

validateArgs.address({ blocklistManager })
Expand All @@ -19,3 +19,6 @@ export const getParams = (values: SetBlocklistManagerParams) => {

return params
}


export default getParams
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { vaultMulticall } from '../../../../contracts'
import { validateArgs } from '../../../../utils'
import { validateList } from '../util'
import { validateList } from '../../util'
import { validateArgs } from '../../../../../../utils'
import { vaultMulticall } from '../../../../../../contracts'


export type UpdateBlocklistParams = {
Expand All @@ -18,7 +18,7 @@ const validateBlocklist = (blocklist: UpdateBlocklistParams['blocklist']) => {
}
}

export const getParams = (values: UpdateBlocklistParams) => {
const getParams = (values: UpdateBlocklistParams) => {
const { blocklist } = values

validateArgs.array({ blocklist })
Expand All @@ -31,3 +31,6 @@ export const getParams = (values: UpdateBlocklistParams) => {

return params
}


export default getParams
Loading

0 comments on commit 69cd1e8

Please sign in to comment.