Skip to content

Commit

Permalink
[handle-429-error] improves
Browse files Browse the repository at this point in the history
  • Loading branch information
Cast0001 committed Apr 25, 2024
1 parent c2ec2da commit 4cfc0fd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 21 deletions.
5 changes: 1 addition & 4 deletions src/StakeWiseSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ class StakeWiseSDK {
constructor(options: StakeWise.Options) {
const config = configs[options.network]

const provider = options.provider || createProvider({
urls: options.endpoints?.web3 || '',
network: options.network,
})
const provider = options.provider || createProvider(options)

const contracts = createContracts({ provider, config })

Expand Down
5 changes: 1 addition & 4 deletions src/contracts/vaultMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ const vaultMulticall = async <T extends unknown>(values: VaultMulticallInput): P
const withSigner = !callStatic && !transactionData

if (withSigner) {
const library = options.provider || createProvider({
urls: options.endpoints?.web3 || '',
network: options.network,
})
const library = options.provider || createProvider(options)

const signer = options.provider
? await options.provider.getSigner(userAddress)
Expand Down
2 changes: 2 additions & 0 deletions src/utils/apiUrls.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import configs from './configs'


const getWeb3Url = (options: StakeWise.Options) => options.endpoints?.web3 || configs[options.network].network.url
const getBackendUrl = (options: StakeWise.Options) => options.endpoints?.api || configs[options.network].api.backend
const getSubgraphqlUrl = (options: StakeWise.Options) => options.endpoints?.subgraph || configs[options.network].api.subgraph


export default {
getWeb3Url,
getBackendUrl,
getSubgraphqlUrl,
}
18 changes: 5 additions & 13 deletions src/utils/createProvider.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { JsonRpcProvider, FallbackProvider, FetchRequest, FetchResponse } from 'ethers'

import configs from './configs'
import { Network } from './enums'
import apiUrls from './apiUrls'


type Input = {
urls: string | string[]
network: Network
}

const createProvider = (values: Input) => {
const { urls, network } = values
const createProvider = (options: StakeWise.Options) => {
const { network } = options

if (!urls) {
return new JsonRpcProvider(configs[network].network.url)
}
const urls = apiUrls.getWeb3Url(options)

if (Array.isArray(urls)) {
if (urls.length === 1) {
Expand All @@ -29,7 +21,7 @@ const createProvider = (values: Input) => {
const fetchRequest = new FetchRequest(url)

fetchRequest.setThrottleParams({
slotInterval: 500,
slotInterval: 2 * 1000,
maxAttempts: 2,
})

Expand Down

0 comments on commit 4cfc0fd

Please sign in to comment.