-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [list requests] add requests * [list actions] move list actions to sdk * [list actions] Update readme * [list actions] Update readme
- Loading branch information
1 parent
c19bf14
commit c8cd54b
Showing
15 changed files
with
477 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { UpdateBlocklistInput } from './types' | ||
import { validateArgs } from '../../../../utils' | ||
import { vaultMulticall } from '../../../../contracts' | ||
|
||
|
||
const validateList = (blocklist: UpdateBlocklistInput['blocklist']) => { | ||
const isValid = blocklist.every((blocklistItem) => ( | ||
blocklistItem | ||
&& typeof blocklistItem === 'object' | ||
&& typeof blocklistItem.address === 'string' | ||
&& typeof blocklistItem.isNew === 'boolean' | ||
)) | ||
|
||
if (!isValid) { | ||
throw new Error('The "blocklist" argument must be an array of objects with "address" and "isNew" properties') | ||
} | ||
} | ||
|
||
export const commonLogic = (values: UpdateBlocklistInput) => { | ||
const { options, contracts, userAddress, vaultAddress, blocklist } = values | ||
|
||
validateArgs.array({ blocklist }) | ||
validateArgs.address({ vaultAddress, userAddress }) | ||
validateList(blocklist) | ||
|
||
const multicallCommonArgs: Omit<Parameters<typeof vaultMulticall>[0], 'request'> = { | ||
vaultContract: contracts.helpers.createBlocklistVault(vaultAddress), | ||
keeperContract: contracts.base.keeper, | ||
vaultAddress, | ||
userAddress, | ||
options, | ||
} | ||
|
||
const params: Parameters<typeof vaultMulticall>[0]['request']['params'] = blocklist.map(({ address, isNew }) => ({ | ||
method: 'updateBlocklist', | ||
args: [ address, isNew ], | ||
})) | ||
|
||
return { | ||
params, | ||
multicallCommonArgs, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as updateBlocklist } from './updateBlocklist' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import updateBlocklistGas from './updateBlocklistGas' | ||
import updateBlocklistEncode from './updateBlocklistEncode' | ||
|
||
|
||
export type UpdateBlocklistInput = { | ||
blocklist: Array<{ | ||
address: string | ||
isNew: boolean | ||
}> | ||
userAddress: string | ||
vaultAddress: string | ||
options: StakeWise.Options | ||
provider: StakeWise.Provider | ||
contracts: StakeWise.Contracts | ||
} | ||
|
||
export interface UpdateBlocklist { | ||
(values: UpdateBlocklistInput): Promise<StakeWise.TransactionHash> | ||
estimateGas: typeof updateBlocklistGas | ||
encode: typeof updateBlocklistEncode | ||
} |
25 changes: 25 additions & 0 deletions
25
src/methods/vault/transactions/updateBlocklist/updateBlocklist.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { UpdateBlocklist } from './types' | ||
import { commonLogic } from './common' | ||
import updateBlocklistGas from './updateBlocklistGas' | ||
import updateBlocklistEncode from './updateBlocklistEncode' | ||
import { vaultMulticall } from '../../../../contracts' | ||
|
||
|
||
const updateBlocklist: UpdateBlocklist = async (values) => { | ||
const { params, multicallCommonArgs } = commonLogic(values) | ||
|
||
const result = await vaultMulticall<{ hash: string }>({ | ||
...multicallCommonArgs, | ||
request: { | ||
params, | ||
}, | ||
}) | ||
|
||
return result.hash | ||
} | ||
|
||
updateBlocklist.encode = updateBlocklistEncode | ||
updateBlocklist.estimateGas = updateBlocklistGas | ||
|
||
|
||
export default updateBlocklist |
24 changes: 24 additions & 0 deletions
24
src/methods/vault/transactions/updateBlocklist/updateBlocklistEncode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { commonLogic } from './common' | ||
import { UpdateBlocklistInput } from './types' | ||
import { vaultMulticall } from '../../../../contracts' | ||
|
||
|
||
const updateBlocklistEncode = async (values: UpdateBlocklistInput): Promise<StakeWise.TransactionData> => { | ||
const { params, multicallCommonArgs } = commonLogic(values) | ||
|
||
const rx = await vaultMulticall<{ data: string, to: string }>({ | ||
...multicallCommonArgs, | ||
request: { | ||
params, | ||
transactionData: true, | ||
}, | ||
}) | ||
|
||
return { | ||
data: rx.data, | ||
to: rx.to, | ||
} | ||
} | ||
|
||
|
||
export default updateBlocklistEncode |
24 changes: 24 additions & 0 deletions
24
src/methods/vault/transactions/updateBlocklist/updateBlocklistGas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { commonLogic } from './common' | ||
import { UpdateBlocklistInput } from './types' | ||
import { getGas } from '../../../../utils' | ||
import { vaultMulticall } from '../../../../contracts' | ||
|
||
|
||
const updateBlocklistGas = async (values: UpdateBlocklistInput) => { | ||
const { params, multicallCommonArgs } = commonLogic(values) | ||
|
||
const estimatedGas = await vaultMulticall<bigint>({ | ||
...multicallCommonArgs, | ||
request: { | ||
estimateGas: true, | ||
params, | ||
}, | ||
}) | ||
|
||
const gas = await getGas({ estimatedGas, provider: values.provider }) | ||
|
||
return gas | ||
} | ||
|
||
|
||
export default updateBlocklistGas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { UpdateWhitelistInput } from './types' | ||
import { validateArgs } from '../../../../utils' | ||
import { vaultMulticall } from '../../../../contracts' | ||
|
||
|
||
const validateList = (whitelist: UpdateWhitelistInput['whitelist']) => { | ||
const isValid = whitelist.every((whitelistItem) => ( | ||
whitelistItem | ||
&& typeof whitelistItem === 'object' | ||
&& typeof whitelistItem.address === 'string' | ||
&& typeof whitelistItem.isNew === 'boolean' | ||
)) | ||
|
||
if (!isValid) { | ||
throw new Error('The "whitelist" argument must be an array of objects with "address" and "isNew" properties') | ||
} | ||
} | ||
|
||
export const commonLogic = (values: UpdateWhitelistInput) => { | ||
const { options, contracts, userAddress, vaultAddress, whitelist } = values | ||
|
||
validateArgs.array({ whitelist }) | ||
validateArgs.address({ vaultAddress, userAddress }) | ||
validateList(whitelist) | ||
|
||
const multicallCommonArgs: Omit<Parameters<typeof vaultMulticall>[0], 'request'> = { | ||
vaultContract: contracts.helpers.createPrivateVault(vaultAddress), | ||
keeperContract: contracts.base.keeper, | ||
vaultAddress, | ||
userAddress, | ||
options, | ||
} | ||
|
||
const params: Parameters<typeof vaultMulticall>[0]['request']['params'] = whitelist.map(({ address, isNew }) => ({ | ||
method: 'updateWhitelist', | ||
args: [ address, isNew ], | ||
})) | ||
|
||
return { | ||
params, | ||
multicallCommonArgs, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as updateWhitelist } from './updateWhitelist' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import updateWhitelistGas from './updateWhitelistGas' | ||
import updateWhitelistEncode from './updateWhitelistEncode' | ||
|
||
|
||
export type UpdateWhitelistInput = { | ||
whitelist: Array<{ | ||
address: string | ||
isNew: boolean | ||
}> | ||
userAddress: string | ||
vaultAddress: string | ||
options: StakeWise.Options | ||
provider: StakeWise.Provider | ||
contracts: StakeWise.Contracts | ||
} | ||
|
||
export interface UpdateWhitelist { | ||
(values: UpdateWhitelistInput): Promise<StakeWise.TransactionHash> | ||
estimateGas: typeof updateWhitelistGas | ||
encode: typeof updateWhitelistEncode | ||
} |
25 changes: 25 additions & 0 deletions
25
src/methods/vault/transactions/updateWhitelist/updateWhitelist.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { UpdateWhitelist } from './types' | ||
import { commonLogic } from './common' | ||
import updateWhitelistGas from './updateWhitelistGas' | ||
import updateWhitelistEncode from './updateWhitelistEncode' | ||
import { vaultMulticall } from '../../../../contracts' | ||
|
||
|
||
const updateWhitelist: UpdateWhitelist = async (values) => { | ||
const { params, multicallCommonArgs } = commonLogic(values) | ||
|
||
const result = await vaultMulticall<{ hash: string }>({ | ||
...multicallCommonArgs, | ||
request: { | ||
params, | ||
}, | ||
}) | ||
|
||
return result.hash | ||
} | ||
|
||
updateWhitelist.encode = updateWhitelistEncode | ||
updateWhitelist.estimateGas = updateWhitelistGas | ||
|
||
|
||
export default updateWhitelist |
24 changes: 24 additions & 0 deletions
24
src/methods/vault/transactions/updateWhitelist/updateWhitelistEncode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { commonLogic } from './common' | ||
import { UpdateWhitelistInput } from './types' | ||
import { vaultMulticall } from '../../../../contracts' | ||
|
||
|
||
const updateWhitelistEncode = async (values: UpdateWhitelistInput): Promise<StakeWise.TransactionData> => { | ||
const { params, multicallCommonArgs } = commonLogic(values) | ||
|
||
const rx = await vaultMulticall<{ data: string, to: string }>({ | ||
...multicallCommonArgs, | ||
request: { | ||
params, | ||
transactionData: true, | ||
}, | ||
}) | ||
|
||
return { | ||
data: rx.data, | ||
to: rx.to, | ||
} | ||
} | ||
|
||
|
||
export default updateWhitelistEncode |
24 changes: 24 additions & 0 deletions
24
src/methods/vault/transactions/updateWhitelist/updateWhitelistGas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { commonLogic } from './common' | ||
import { UpdateWhitelistInput } from './types' | ||
import { getGas } from '../../../../utils' | ||
import { vaultMulticall } from '../../../../contracts' | ||
|
||
|
||
const updateWhitelistGas = async (values: UpdateWhitelistInput) => { | ||
const { params, multicallCommonArgs } = commonLogic(values) | ||
|
||
const estimatedGas = await vaultMulticall<bigint>({ | ||
...multicallCommonArgs, | ||
request: { | ||
estimateGas: true, | ||
params, | ||
}, | ||
}) | ||
|
||
const gas = await getGas({ estimatedGas, provider: values.provider }) | ||
|
||
return gas | ||
} | ||
|
||
|
||
export default updateWhitelistGas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters