Skip to content

Commit

Permalink
[remove duplicates] update white/block list requests (#233)
Browse files Browse the repository at this point in the history
* [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]>
  • Loading branch information
4 people authored Jan 17, 2025
1 parent d34dad5 commit f03b3b4
Show file tree
Hide file tree
Showing 17 changed files with 551 additions and 126 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: Config = {
maxWorkers: 1, // Fixed https://github.com/jestjs/jest/issues/11617#issuecomment-1028651059
rootDir: './src',
preset: 'ts-jest',
resetMocks: true,
resetMocks: false,
testEnvironment: 'node',
testMatch: [ '**/*.spec.ts' ],
collectCoverageFrom: [ 'src/**/*.ts' ],
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { constants } from './utils'
export * from './utils/enums'
export { createContract } from './contracts'
export { default as StakeWiseSDK } from './StakeWiseSDK'
export { wrapAbortPromise, AbortPromise } from './modules/gql-module'
export { default as localStorage } from './modules/local-storage'
export { wrapAbortPromise, AbortPromise, AbortRequest } from './modules/gql-module'

export {
configs,
Expand Down
66 changes: 66 additions & 0 deletions src/methods/utils/getListVariables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { isAddress } from 'ethers'
import { validateArgs } from '../../utils'
import { StakeWiseSubgraphGraph } from '../../types/graphql/subgraph'


export type GetListVariablesInput = {
vaultAddress: string
orderDirection?: StakeWiseSubgraphGraph.OrderDirection
search?: string
limit?: number
skip?: number
addressIn?: string[]
}

const validateList = (addressIn: string[]) => {
const isValid = addressIn.every((address) => isAddress(address))

if (!isValid) {
throw new Error('The "addressIn" argument must be an array of valid addresses')
}
}

const getListVariables = <T>(input: GetListVariablesInput): T => {
const { vaultAddress, orderDirection, search, limit, skip, addressIn } = input

validateArgs.address({ vaultAddress })

if (typeof skip !== 'undefined') {
validateArgs.number({ skip })
}

if (typeof limit !== 'undefined') {
validateArgs.number({ limit })
}

if (typeof search !== 'undefined') {
validateArgs.string({ search })
}

if (typeof orderDirection !== 'undefined') {
if (![ 'asc', 'desc' ].includes(orderDirection)) {
throw new Error(`The "orderDirection" argument must be "asc" or "desc"`)
}
}

if (typeof addressIn !== 'undefined') {
validateArgs.array({ addressIn })
validateList(addressIn as string[])
}

const vault = vaultAddress.toLowerCase()

const where = search
? { vault, address_in: addressIn, address_contains: search.toLowerCase() }
: { vault, address_in: addressIn }

return {
where,
skip: skip || 0,
limit: limit || 100,
orderDirection: orderDirection || 'desc',
} as T
}


export default getListVariables
2 changes: 2 additions & 0 deletions src/methods/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export type { BaseInput } from './types'
export { default as getFiatRates } from './getFiatRates'
export { default as getTransactions } from './getTransactions'
export type { GetListVariablesInput } from './getListVariables'
export { default as getListVariables } from './getListVariables'
export { default as getFiatRatesByDay } from './getFiatRatesByDay'
export { default as getStakewiseStats } from './getStakewiseStats'
export { default as getPermitSignature } from './getPermitSignature'
Expand Down
60 changes: 6 additions & 54 deletions src/methods/vault/requests/getBlocklist/index.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,23 @@
import { isAddress } from 'ethers'
import type { BlocklistAccountsQueryVariables, BlocklistAccountsQueryPayload } from '../../../../graphql/subgraph/vault'
import { apiUrls, validateArgs } from '../../../../utils'
import { apiUrls } from '../../../../utils'
import graphql from '../../../../graphql'
import { ModifiedBlocklist } from './types'
import modifyBlocklist from './modifyBlocklist'
import { getListVariables, GetListVariablesInput } from '../../../utils'


type GetBlocklistInput = {
vaultAddress: string
orderDirection?: BlocklistAccountsQueryVariables['orderDirection']
search?: string
limit?: number
skip?: number
addressIn?: BlocklistAccountsQueryVariables['where']['address_in']
type GetBlocklistInput = GetListVariablesInput & {
options: StakeWise.Options
}

const validateList = (addressIn: string[]) => {
const isValid = addressIn.every((address) => isAddress(address))

if (!isValid) {
throw new Error('The "addressIn" argument must be an array of valid addresses')
}
}

const getBlocklist = (input: GetBlocklistInput) => {
const { vaultAddress, orderDirection, search, limit, skip, addressIn, options } = input

validateArgs.address({ vaultAddress })

if (typeof skip !== 'undefined') {
validateArgs.number({ skip })
}

if (typeof limit !== 'undefined') {
validateArgs.number({ limit })
}

if (typeof search !== 'undefined') {
validateArgs.string({ search })
}

if (typeof orderDirection !== 'undefined') {
if (![ 'asc', 'desc' ].includes(orderDirection)) {
throw new Error(`The "orderDirection" argument must be "asc" or "desc"`)
}
}

if (typeof addressIn !== 'undefined') {
validateArgs.array({ addressIn })
validateList(addressIn as string[])
}

const vault = vaultAddress.toLowerCase()
const { options, ...rest } = input

const where = search
? { vault, address_in: addressIn, address_contains: search.toLowerCase() } as BlocklistAccountsQueryVariables['where']
: { vault, address_in: addressIn } as BlocklistAccountsQueryVariables['where']
const variables = getListVariables<BlocklistAccountsQueryVariables>(rest)

return graphql.subgraph.vault.fetchBlocklistAccountsQuery<ModifiedBlocklist>({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
where,
skip: skip || 0,
limit: limit || 100,
orderDirection: orderDirection || 'desc',
},
variables,
modifyResult: (data: BlocklistAccountsQueryPayload) => modifyBlocklist({ data }),
})
}
Expand Down
60 changes: 6 additions & 54 deletions src/methods/vault/requests/getWhitelist/index.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,23 @@
import { isAddress } from 'ethers'
import type { WhitelistAccountsQueryVariables, WhitelistAccountsQueryPayload } from '../../../../graphql/subgraph/vault'
import { apiUrls, validateArgs } from '../../../../utils'
import { apiUrls } from '../../../../utils'
import graphql from '../../../../graphql'
import { ModifiedWhitelist } from './types'
import modifyWhitelist from './modifyWhitelist'
import { getListVariables, GetListVariablesInput } from '../../../utils'


type GetWhitelistInput = {
vaultAddress: string
orderDirection?: WhitelistAccountsQueryVariables['orderDirection']
search?: string
limit?: number
skip?: number
addressIn?: WhitelistAccountsQueryVariables['where']['address_in']
type GetWhitelistInput = GetListVariablesInput & {
options: StakeWise.Options
}

const validateList = (addressIn: string[]) => {
const isValid = addressIn.every((address) => isAddress(address))

if (!isValid) {
throw new Error('The "addressIn" argument must be an array of valid addresses')
}
}

const getWhitelist = (input: GetWhitelistInput) => {
const { vaultAddress, orderDirection, search, limit, skip, addressIn, options } = input

validateArgs.address({ vaultAddress })

if (typeof skip !== 'undefined') {
validateArgs.number({ skip })
}

if (typeof limit !== 'undefined') {
validateArgs.number({ limit })
}

if (typeof search !== 'undefined') {
validateArgs.string({ search })
}

if (typeof orderDirection !== 'undefined') {
if (![ 'asc', 'desc' ].includes(orderDirection)) {
throw new Error(`The "orderDirection" argument must be "asc" or "desc"`)
}
}

if (typeof addressIn !== 'undefined') {
validateArgs.array({ addressIn })
validateList(addressIn as string[])
}

const vault = vaultAddress.toLowerCase()
const { options, ...rest } = input

const where = search
? { vault, address_in: addressIn, address_contains: search.toLowerCase() } as WhitelistAccountsQueryVariables['where']
: { vault, address_in: addressIn } as WhitelistAccountsQueryVariables['where']
const variables = getListVariables<WhitelistAccountsQueryVariables>(rest)

return graphql.subgraph.vault.fetchWhitelistAccountsQuery<ModifiedWhitelist>({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
where,
skip: skip || 0,
limit: limit || 100,
orderDirection: orderDirection || 'desc',
},
variables,
modifyResult: (data: WhitelistAccountsQueryPayload) => modifyWhitelist({ data }),
})
}
Expand Down
2 changes: 0 additions & 2 deletions src/modules/gql-module/abortCallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class AbortCallback {

then(onSuccess: (data: any) => any, onError?: (error: any) => any) {
if (this.isAborted) {
const dummyPromise = new Promise(() => {})

return new AbortCallback(dummyPromise, this.onAbort)
}

Expand Down
Loading

0 comments on commit f03b3b4

Please sign in to comment.