diff --git a/README.md b/README.md index 897bf4e3..865f0852 100644 --- a/README.md +++ b/README.md @@ -68,18 +68,23 @@ Create SDK instance ```typescript import { StakeWiseSDK, Network } from '@stakewise/v3-sdk' -const sdk = new StakeWiseSDK({ network: Network.Mainnet }) +const sdk = new StakeWiseSDK({ + network: Network.Mainnet, + endpoints: { + web3: 'https://mainnet.infura.io/v3/...', + }, +}) ``` #### SDK Constructor Arguments: -| Name | Type | Required | Description | -|--------------------|--------------------------------------|----------|----------------| -| network | `Network` | **Yes** | Chain id | -| provider | `BrowserProvider or JsonRpcProvider` | **No** | You can provide your implementation of the provender for ethers | -| endpoints.web3 | `string OR string[]` | **No** | Your urls for connect to blockchain | -| endpoints.subgraph | `string` | **No** | stakewise subgraph url | -| endpoints.api | `string` | **No** | stakewise backend url | +| Name | Type | Required | Description | +|--------------------|------------------------------------------------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| network | `Network` | **Yes** | Chain id | +| provider | `BrowserProvider or JsonRpcProvider` | **No** | You can provide your implementation of the provender for ethers | +| endpoints.web3 | `string OR Array<(string \| { url: string, headers: Headers })>` | **No** | Your urls for connecting to blockchain. This parameter is required if `provider` is not provided. If more than one URL is provided, they will be used as fallbacks. | +| endpoints.subgraph | `string` | **No** | stakewise subgraph url | +| endpoints.api | `string` | **No** | stakewise backend url | ## Quick Links diff --git a/changelog/next-release.md b/changelog/next-release.md index e69de29b..cd2ad74b 100644 --- a/changelog/next-release.md +++ b/changelog/next-release.md @@ -0,0 +1 @@ +- Breaking change: Removed default rpc urls from the SDK. You must now provide the rpc urls or provider when creating a new SDK instance. diff --git a/package-lock.json b/package-lock.json index a73c5e9f..5189f0f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@stakewise/v3-sdk", - "version": "2.0.3", + "version": "2.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@stakewise/v3-sdk", - "version": "2.0.3", + "version": "2.1.0", "license": "AGPL-3.0-only", "dependencies": { "bignumber.js": "9.1.2" diff --git a/package.json b/package.json index fc26adbc..3c662932 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "2.0.3", + "version": "2.1.0", "sideEffects": false, "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/StakeWiseSDK.ts b/src/StakeWiseSDK.ts index 94f90da2..91d8bbe6 100644 --- a/src/StakeWiseSDK.ts +++ b/src/StakeWiseSDK.ts @@ -22,6 +22,10 @@ class StakeWiseSDK { constructor(options: StakeWise.Options) { const config = configs[options.network] + if (!options.provider && !options.endpoints?.web3) { + throw new Error('Provider or endpoints.web3 should be provided') + } + const provider = options.provider || createProvider(options) const contracts = createContracts({ provider, config }) diff --git a/src/utils/apiUrls.ts b/src/utils/apiUrls.ts index 68ce9c99..adcb5e6b 100644 --- a/src/utils/apiUrls.ts +++ b/src/utils/apiUrls.ts @@ -1,13 +1,11 @@ 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, } diff --git a/src/utils/constants/chains.ts b/src/utils/constants/chains.ts index 79a12be0..94656458 100644 --- a/src/utils/constants/chains.ts +++ b/src/utils/constants/chains.ts @@ -8,7 +8,6 @@ const mainnet = { chainId: Network.Mainnet, hexadecimalChainId: '0x1', blockExplorerUrl: 'https://etherscan.io', - url: 'https://mainnet.infura.io/v3/84842078b09946638c03157f83405213', nativeCurrency: { symbol: tokens.eth, name: 'Ethereum', @@ -22,7 +21,6 @@ const holesky = { name: 'Holesky Testnet', chainId: Network.Holesky, hexadecimalChainId: '0x4268', - url: 'https://ethereum-holesky.publicnode.com/', blockExplorerUrl: 'https://holesky.etherscan.io', nativeCurrency: { symbol: tokens.eth, @@ -37,7 +35,6 @@ const chiado = { name: 'Chiado Testnet', chainId: Network.Chiado, hexadecimalChainId: '0x27D8', - url: 'https://rpc.chiadochain.net', blockExplorerUrl: 'https://gnosis-chiado.blockscout.com', nativeCurrency: { symbol: tokens.xdai, @@ -52,7 +49,6 @@ const gnosis = { name: 'Gnosis Chain', chainId: Network.Gnosis, hexadecimalChainId: '0x64', - url: 'https://rpc.gnosischain.com', blockExplorerUrl: 'https://gnosisscan.io', nativeCurrency: { symbol: tokens.xdai, diff --git a/src/utils/createProvider.ts b/src/utils/createProvider.ts index 1ba32dab..6dcb11a6 100644 --- a/src/utils/createProvider.ts +++ b/src/utils/createProvider.ts @@ -44,7 +44,7 @@ const getFetchRequest = (_url: string | StakeWise.UrlWithHeaders) => { const createProvider = (options: StakeWise.Options) => { const { network } = options - const urls = apiUrls.getWeb3Url(options) + const urls = options.endpoints?.web3 as string | string[] const arrayUrls = typeof urls === 'string' ? [ urls ] : urls if (arrayUrls.length === 1) {