Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[remove duplicates] update white/block list requests #233

Merged
merged 44 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7b96107
[for-new-stake] add contract for genesis
Cast0001 Jul 16, 2024
aea23f9
[for-new-stake] improve vaultMulticall
Cast0001 Jul 17, 2024
6689ebd
[for-new-stake] add stake calculator
Cast0001 Jul 22, 2024
0dacf5f
[for-new-stake] improve stake calculator
Cast0001 Jul 25, 2024
64f9e9e
[for-new-stake] improve abis
Cast0001 Jul 26, 2024
94fcded
[for-new-stake] new stakecalculator
Cast0001 Jul 29, 2024
7bd6385
[for-new-stake] change address
Cast0001 Aug 6, 2024
2f27efb
New createVault method (#169)
Cast0001 Sep 20, 2024
1df6f87
New subgraph (#171)
mike-diamond Sep 24, 2024
159b1b5
Subgraph tvl apy (#172)
Cast0001 Sep 24, 2024
e1af472
[get config] update get config (#177)
mike-diamond Sep 27, 2024
12f0b6d
Add new methods getUserStats & getVaultStats (#176)
dfkadyr Sep 27, 2024
903aabd
new addresses
Cast0001 Sep 27, 2024
493a367
[new-stake-calculator] set new addresses (#178)
Cast0001 Sep 30, 2024
ce0ed21
Add new methods getFiatRates & getUserExchangeRewards (#179)
dfkadyr Oct 3, 2024
aaec048
Replace depositDataRoot & depositDataManager (#182)
dfkadyr Oct 7, 2024
a7058cc
Boost apy (#187)
Cast0001 Oct 17, 2024
f6be2a0
Boost methods (#192)
mike-diamond Oct 23, 2024
57614d4
Boost part 3 (#195)
Cast0001 Oct 25, 2024
32fc377
Unboost (#197)
mike-diamond Oct 28, 2024
8e37be5
Boost updates (#198)
Cast0001 Oct 28, 2024
b8627d9
fix getBoost
Cast0001 Oct 29, 2024
1b07d39
Fix user stats (#201)
Cast0001 Oct 31, 2024
fb5aac7
Unboost (#199)
mike-diamond Nov 4, 2024
3fba130
[unboost vault] remove getBoostApy
mike-diamond Nov 5, 2024
ecd491e
Unboost queue (#204)
Cast0001 Nov 5, 2024
8e37635
Add isDepositWithMint option (#206)
dfkadyr-stakewise Nov 8, 2024
4a749d2
Rewards data (#207)
Cast0001 Nov 14, 2024
c3bcc8c
Add documentation website (#210)
dfkadyr-stakewise Nov 25, 2024
d389c4d
Migration and Search (#211)
dfkadyr-stakewise Nov 26, 2024
9827925
[rewards-fix] fixed (#214)
Cast0001 Nov 29, 2024
248c6ab
[new-schema] changes (#215)
Cast0001 Dec 2, 2024
97d738b
fix
Cast0001 Dec 2, 2024
0c16297
Update links, rename thresholdPercent to liqThresholdPercent (#219)
dfkadyr-stakewise Dec 6, 2024
2adb797
Fiat rates and APY (#220)
Cast0001 Dec 9, 2024
1795d1a
remove apy in leverageStrategyPositionStats_collection (#223)
dfkadyr-stakewise Dec 11, 2024
9409deb
[update stats] update stats requests (#225)
mike-diamond Dec 19, 2024
ca6e44c
Currencies (#227)
mike-diamond Dec 24, 2024
be58b6d
[requests improve] update requests (#229)
mike-diamond Jan 6, 2025
6cda626
[updates-for-apy] update fields (#231)
Cast0001 Jan 14, 2025
2dbc16a
[remove duplicates] update white/block list requests
mike-diamond Jan 15, 2025
7389447
[remove duplicates] update local storage
mike-diamond Jan 16, 2025
726659e
[remove duplicates] move abortRequest to sdk
mike-diamond Jan 17, 2025
9ba8220
[remove duplicates] rebase
mike-diamond Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading