Skip to content

Commit f03b3b4

Browse files
mike-diamondCast0001dfkadyrdfkadyr-stakewise
authored
[remove duplicates] update white/block list requests (#233)
* [for-new-stake] add contract for genesis * [for-new-stake] improve vaultMulticall * [for-new-stake] add stake calculator * [for-new-stake] improve stake calculator * [for-new-stake] improve abis * [for-new-stake] new stakecalculator * [for-new-stake] change address * New createVault method (#169) * [improve-abi-diff] new createVault method * [improve-abi-diff] gitignor * [improve-abi-diff] fix * New subgraph (#171) * [new subgraph] update schema * [codegen ci] add fallback subgraph codegen check (#168) * [codegen ci] add fallback subgraph codegen check (#168) * [new subgraph] Update codegen * [new subgraph] Update codegen * [new subgraph] Update types * [new subgraph] Update graphql * Subgraph tvl apy (#172) * [subgraph-tvl-ap] add getStakewiseStats * [subgraph-tvl-ap] change urls * [subgraph-tvl-apy] rename validatorsRoot and keysManager * [get config] update get config (#177) * [get config] update get config * [get config] update get config * [get config] update get config * [get config] update get config * [get config] update get config * Add new methods getUserStats & getVaultStats (#176) * Improve chart view logic in V3, add getUserStats, getVaultStats. * add deprecated to README * update docs * fixed import * improves, rename methods * new addresses * [new-stake-calculator] set new addresses (#178) * Add new methods getFiatRates & getUserExchangeRewards (#179) * add new methods getFiatRates & getUserExchangeRewards * remove unused * update text in docs * remove usdToDaiRate * remove unused methods, update docs * update docs * improve date in milliseconds * Replace depositDataRoot & depositDataManager (#182) * replace (depositDataRoot & depositDataManager) V1 logic from vault.operate, to (vault.setDepositDataRoot & vault.setDepositDataManager) instead * add version * rename to input * PR improves * Boost apy (#187) * [boost-apy] set apy logic * [boost-apy] change codegen * [boost-apy] change user stats * [boost-apy] improve ltv percent logic * [boost-apy] fix config * [boost-apy] fix readme * [boost-apy] remove import * Boost methods (#192) * remove duplicates (#186) * refactor checkRestakeOperatorsManagerAccess * update subgraphUrl logic * [boost ui] add boost multicall to sdk * [boost ui] add boost to sdk * [boost ui] add boost to sdk * [boost ui] update types * [boost ui] add boost methods * [boost ui] add boost methods * [boost ui] add boost methods * [boost ui] add boost methods * [boost ui] update type * [boost ui] update type * [boost ui] update permit signature --------- Co-authored-by: Kadyr Dzhemaledinov <[email protected]> * Boost part 3 (#195) * Boost apy (#187) * [boost-apy] set apy logic * [boost-apy] change codegen * [boost-apy] change user stats * [boost-apy] improve ltv percent logic * [boost-apy] fix config * [boost-apy] fix readme * [boost-apy] remove import * [boost-part-2] remove boost percent (#189) * [boost ui] update boost data (#188) * remove duplicates (#186) (#191) * refactor checkRestakeOperatorsManagerAccess * update subgraphUrl logic * Boost methods (#192) * remove duplicates (#186) * refactor checkRestakeOperatorsManagerAccess * update subgraphUrl logic * [boost ui] add boost multicall to sdk * [boost ui] add boost to sdk * [boost ui] add boost to sdk * [boost ui] update types * [boost ui] add boost methods * [boost ui] add boost methods * [boost ui] add boost methods * [boost ui] add boost methods * [boost ui] update type * [boost ui] update type * [boost ui] update permit signature --------- Co-authored-by: Kadyr Dzhemaledinov <[email protected]> * [boost-part-3] add boost method * [boost-part-3] fixes --------- Co-authored-by: Mike Diamond <[email protected]> Co-authored-by: Kadyr Dzhemaledinov <[email protected]> * Unboost (#197) * [unboost ui] update addresses * [unboost ui] update boost action * [unboost ui] update boost action * Boost updates (#198) * [boost-updates] set addresses * [boost-updates] update getBoost * [boost-updates] change readme * fix getBoost * Fix user stats (#201) * [fix-user-stats] fixed * [fix-user-stats] improve * Unboost (#199) * [unboost ui] update apy calculation * [unboost ui] add unboost method * [unboost ui] update unboost ui * [unboost ui] update unboost ui * [unboost ui] update unboost ui * [unboost ui] update unboost ui * [unboost ui] update unboost ui * [unboost ui] update unboost ui * [unboost ui] fix boost * [unboost vault] remove getBoostApy * Unboost queue (#204) * [unboost-queue] create getQueuePosition * [unboost-queue] create claimQueue * [unboost-queue] boost refactoring * [unboost-queue] improve * Add isDepositWithMint option (#206) * add isDepositWithMint logic * add genesis * improve isDepositWithMint in vaultMulticall * Rewards data (#207) * [rewards-data] add merge rewards & fiat helper * [rewards-data] change reqests * [rewards-data] create calculateUserStats * [rewards-data] readme * [rewards-data] readme * [rewards-data] fix * Add documentation website (#210) * update methods, add .md files * add new website * update dev command * app packages * update commands * test build * test build * update README * update README * update docs * Migration and Search (#211) * add migration page * add search * [rewards-fix] fixed (#214) * [new-schema] changes (#215) * fix * Update links, rename thresholdPercent to liqThresholdPercent (#219) * update jsdoc links * rename thresholdPercent to liqThresholdPercent * Fiat rates and APY (#220) * [fiat-rates] new logic * [fiat-rates] getUserApy method * [fiat-rates] change getOsTokenAPY * remove apy in leverageStrategyPositionStats_collection (#223) * [update stats] update stats requests (#225) * [update stats] update stats requests * [update stats] ui fixes * Currencies (#227) * [skeleton] add currencies * [currencies] update queries * [currencies] update graphql * [requests improve] update requests (#229) * [requests improve] update requests * [requests improve] update requests * [requests improve] update requests * [requests improve] update gnosis rates * [requests improve] update gnosis rates * [updates-for-apy] update fields (#231) * [remove duplicates] update white/block list requests * [remove duplicates] update local storage * [remove duplicates] move abortRequest to sdk * [remove duplicates] rebase --------- Co-authored-by: Andrey Kopylov <[email protected]> Co-authored-by: Kadyr Dzhemaledinov <[email protected]> Co-authored-by: Kadyr Dzhemaledinov <[email protected]>
1 parent d34dad5 commit f03b3b4

17 files changed

+551
-126
lines changed

jest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config: Config = {
66
maxWorkers: 1, // Fixed https://github.com/jestjs/jest/issues/11617#issuecomment-1028651059
77
rootDir: './src',
88
preset: 'ts-jest',
9-
resetMocks: true,
9+
resetMocks: false,
1010
testEnvironment: 'node',
1111
testMatch: [ '**/*.spec.ts' ],
1212
collectCoverageFrom: [ 'src/**/*.ts' ],

src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { constants } from './utils'
55
export * from './utils/enums'
66
export { createContract } from './contracts'
77
export { default as StakeWiseSDK } from './StakeWiseSDK'
8-
export { wrapAbortPromise, AbortPromise } from './modules/gql-module'
8+
export { default as localStorage } from './modules/local-storage'
9+
export { wrapAbortPromise, AbortPromise, AbortRequest } from './modules/gql-module'
910

1011
export {
1112
configs,

src/methods/utils/getListVariables.ts

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { isAddress } from 'ethers'
2+
import { validateArgs } from '../../utils'
3+
import { StakeWiseSubgraphGraph } from '../../types/graphql/subgraph'
4+
5+
6+
export type GetListVariablesInput = {
7+
vaultAddress: string
8+
orderDirection?: StakeWiseSubgraphGraph.OrderDirection
9+
search?: string
10+
limit?: number
11+
skip?: number
12+
addressIn?: string[]
13+
}
14+
15+
const validateList = (addressIn: string[]) => {
16+
const isValid = addressIn.every((address) => isAddress(address))
17+
18+
if (!isValid) {
19+
throw new Error('The "addressIn" argument must be an array of valid addresses')
20+
}
21+
}
22+
23+
const getListVariables = <T>(input: GetListVariablesInput): T => {
24+
const { vaultAddress, orderDirection, search, limit, skip, addressIn } = input
25+
26+
validateArgs.address({ vaultAddress })
27+
28+
if (typeof skip !== 'undefined') {
29+
validateArgs.number({ skip })
30+
}
31+
32+
if (typeof limit !== 'undefined') {
33+
validateArgs.number({ limit })
34+
}
35+
36+
if (typeof search !== 'undefined') {
37+
validateArgs.string({ search })
38+
}
39+
40+
if (typeof orderDirection !== 'undefined') {
41+
if (![ 'asc', 'desc' ].includes(orderDirection)) {
42+
throw new Error(`The "orderDirection" argument must be "asc" or "desc"`)
43+
}
44+
}
45+
46+
if (typeof addressIn !== 'undefined') {
47+
validateArgs.array({ addressIn })
48+
validateList(addressIn as string[])
49+
}
50+
51+
const vault = vaultAddress.toLowerCase()
52+
53+
const where = search
54+
? { vault, address_in: addressIn, address_contains: search.toLowerCase() }
55+
: { vault, address_in: addressIn }
56+
57+
return {
58+
where,
59+
skip: skip || 0,
60+
limit: limit || 100,
61+
orderDirection: orderDirection || 'desc',
62+
} as T
63+
}
64+
65+
66+
export default getListVariables

src/methods/utils/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export type { BaseInput } from './types'
22
export { default as getFiatRates } from './getFiatRates'
33
export { default as getTransactions } from './getTransactions'
4+
export type { GetListVariablesInput } from './getListVariables'
5+
export { default as getListVariables } from './getListVariables'
46
export { default as getFiatRatesByDay } from './getFiatRatesByDay'
57
export { default as getStakewiseStats } from './getStakewiseStats'
68
export { default as getPermitSignature } from './getPermitSignature'

src/methods/vault/requests/getBlocklist/index.ts

+6-54
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,23 @@
1-
import { isAddress } from 'ethers'
21
import type { BlocklistAccountsQueryVariables, BlocklistAccountsQueryPayload } from '../../../../graphql/subgraph/vault'
3-
import { apiUrls, validateArgs } from '../../../../utils'
2+
import { apiUrls } from '../../../../utils'
43
import graphql from '../../../../graphql'
54
import { ModifiedBlocklist } from './types'
65
import modifyBlocklist from './modifyBlocklist'
6+
import { getListVariables, GetListVariablesInput } from '../../../utils'
77

88

9-
type GetBlocklistInput = {
10-
vaultAddress: string
11-
orderDirection?: BlocklistAccountsQueryVariables['orderDirection']
12-
search?: string
13-
limit?: number
14-
skip?: number
15-
addressIn?: BlocklistAccountsQueryVariables['where']['address_in']
9+
type GetBlocklistInput = GetListVariablesInput & {
1610
options: StakeWise.Options
1711
}
1812

19-
const validateList = (addressIn: string[]) => {
20-
const isValid = addressIn.every((address) => isAddress(address))
21-
22-
if (!isValid) {
23-
throw new Error('The "addressIn" argument must be an array of valid addresses')
24-
}
25-
}
26-
2713
const getBlocklist = (input: GetBlocklistInput) => {
28-
const { vaultAddress, orderDirection, search, limit, skip, addressIn, options } = input
29-
30-
validateArgs.address({ vaultAddress })
31-
32-
if (typeof skip !== 'undefined') {
33-
validateArgs.number({ skip })
34-
}
35-
36-
if (typeof limit !== 'undefined') {
37-
validateArgs.number({ limit })
38-
}
39-
40-
if (typeof search !== 'undefined') {
41-
validateArgs.string({ search })
42-
}
43-
44-
if (typeof orderDirection !== 'undefined') {
45-
if (![ 'asc', 'desc' ].includes(orderDirection)) {
46-
throw new Error(`The "orderDirection" argument must be "asc" or "desc"`)
47-
}
48-
}
49-
50-
if (typeof addressIn !== 'undefined') {
51-
validateArgs.array({ addressIn })
52-
validateList(addressIn as string[])
53-
}
54-
55-
const vault = vaultAddress.toLowerCase()
14+
const { options, ...rest } = input
5615

57-
const where = search
58-
? { vault, address_in: addressIn, address_contains: search.toLowerCase() } as BlocklistAccountsQueryVariables['where']
59-
: { vault, address_in: addressIn } as BlocklistAccountsQueryVariables['where']
16+
const variables = getListVariables<BlocklistAccountsQueryVariables>(rest)
6017

6118
return graphql.subgraph.vault.fetchBlocklistAccountsQuery<ModifiedBlocklist>({
6219
url: apiUrls.getSubgraphqlUrl(options),
63-
variables: {
64-
where,
65-
skip: skip || 0,
66-
limit: limit || 100,
67-
orderDirection: orderDirection || 'desc',
68-
},
20+
variables,
6921
modifyResult: (data: BlocklistAccountsQueryPayload) => modifyBlocklist({ data }),
7022
})
7123
}

src/methods/vault/requests/getWhitelist/index.ts

+6-54
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,23 @@
1-
import { isAddress } from 'ethers'
21
import type { WhitelistAccountsQueryVariables, WhitelistAccountsQueryPayload } from '../../../../graphql/subgraph/vault'
3-
import { apiUrls, validateArgs } from '../../../../utils'
2+
import { apiUrls } from '../../../../utils'
43
import graphql from '../../../../graphql'
54
import { ModifiedWhitelist } from './types'
65
import modifyWhitelist from './modifyWhitelist'
6+
import { getListVariables, GetListVariablesInput } from '../../../utils'
77

88

9-
type GetWhitelistInput = {
10-
vaultAddress: string
11-
orderDirection?: WhitelistAccountsQueryVariables['orderDirection']
12-
search?: string
13-
limit?: number
14-
skip?: number
15-
addressIn?: WhitelistAccountsQueryVariables['where']['address_in']
9+
type GetWhitelistInput = GetListVariablesInput & {
1610
options: StakeWise.Options
1711
}
1812

19-
const validateList = (addressIn: string[]) => {
20-
const isValid = addressIn.every((address) => isAddress(address))
21-
22-
if (!isValid) {
23-
throw new Error('The "addressIn" argument must be an array of valid addresses')
24-
}
25-
}
26-
2713
const getWhitelist = (input: GetWhitelistInput) => {
28-
const { vaultAddress, orderDirection, search, limit, skip, addressIn, options } = input
29-
30-
validateArgs.address({ vaultAddress })
31-
32-
if (typeof skip !== 'undefined') {
33-
validateArgs.number({ skip })
34-
}
35-
36-
if (typeof limit !== 'undefined') {
37-
validateArgs.number({ limit })
38-
}
39-
40-
if (typeof search !== 'undefined') {
41-
validateArgs.string({ search })
42-
}
43-
44-
if (typeof orderDirection !== 'undefined') {
45-
if (![ 'asc', 'desc' ].includes(orderDirection)) {
46-
throw new Error(`The "orderDirection" argument must be "asc" or "desc"`)
47-
}
48-
}
49-
50-
if (typeof addressIn !== 'undefined') {
51-
validateArgs.array({ addressIn })
52-
validateList(addressIn as string[])
53-
}
54-
55-
const vault = vaultAddress.toLowerCase()
14+
const { options, ...rest } = input
5615

57-
const where = search
58-
? { vault, address_in: addressIn, address_contains: search.toLowerCase() } as WhitelistAccountsQueryVariables['where']
59-
: { vault, address_in: addressIn } as WhitelistAccountsQueryVariables['where']
16+
const variables = getListVariables<WhitelistAccountsQueryVariables>(rest)
6017

6118
return graphql.subgraph.vault.fetchWhitelistAccountsQuery<ModifiedWhitelist>({
6219
url: apiUrls.getSubgraphqlUrl(options),
63-
variables: {
64-
where,
65-
skip: skip || 0,
66-
limit: limit || 100,
67-
orderDirection: orderDirection || 'desc',
68-
},
20+
variables,
6921
modifyResult: (data: WhitelistAccountsQueryPayload) => modifyWhitelist({ data }),
7022
})
7123
}

src/modules/gql-module/abortCallback.ts

-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class AbortCallback {
1414

1515
then(onSuccess: (data: any) => any, onError?: (error: any) => any) {
1616
if (this.isAborted) {
17-
const dummyPromise = new Promise(() => {})
18-
1917
return new AbortCallback(dummyPromise, this.onAbort)
2018
}
2119

0 commit comments

Comments
 (0)