diff --git a/src/build.config.js b/src/build.config.js index 84ac731f5..5b498f751 100644 --- a/src/build.config.js +++ b/src/build.config.js @@ -33,6 +33,12 @@ export default { ] }, infuraApiKey: 'da99ebc8c0964bb8bb757b6f8cc40f1f', + pocketApiKey: { + 1: '61439bb937e52c00344102a5', + 3: '6143ee6737e52c00344170b5', + 56: '6143eefb37e52c00344175f9', + 137: '6143eebc37e52c0034417396' + }, exploraApis: { testnet: 'https://liquality.io/testnet/electrs', mainnet: 'https://api-mainnet-bitcoin-electrs.liquality.io' diff --git a/src/store/factory/client.js b/src/store/factory/client.js index efd4c21fd..3feca273b 100644 --- a/src/store/factory/client.js +++ b/src/store/factory/client.js @@ -42,6 +42,9 @@ import cryptoassets from '@/utils/cryptoassets' import buildConfig from '../../build.config' import { ChainNetworks } from '@/utils/networks' +// Only bsc mainnet, ropsten testnet, eth mainnet & polygon mainnet are supported +import { evmChainToRpcProviders } from '@utils/pocket-rpc' + function createBtcClient (network, mnemonic, accountType, derivationPath) { const isTestnet = network === 'testnet' const bitcoinNetwork = ChainNetworks.bitcoin[network] @@ -130,11 +133,11 @@ function createEthereumClient ( function createEthClient (asset, network, mnemonic, accountType, derivationPath) { const isTestnet = network === 'testnet' const ethereumNetwork = ChainNetworks.ethereum[network] - const infuraApi = isTestnet ? `https://ropsten.infura.io/v3/${buildConfig.infuraApiKey}` : `https://mainnet.infura.io/v3/${buildConfig.infuraApiKey}` + const pocketApi = isTestnet ? evmChainToRpcProviders[3] : evmChainToRpcProviders[1] const scraperApi = isTestnet ? 'https://liquality.io/eth-ropsten-api' : 'https://liquality.io/eth-mainnet-api' const feeProvider = isTestnet ? new EthereumRpcFeeProvider() : new EthereumGasNowFeeProvider() - return createEthereumClient(asset, network, ethereumNetwork, infuraApi, scraperApi, feeProvider, mnemonic, accountType, derivationPath) + return createEthereumClient(asset, network, ethereumNetwork, pocketApi, scraperApi, feeProvider, mnemonic, accountType, derivationPath) } function createNearClient (network, mnemonic, derivationPath) { @@ -184,7 +187,7 @@ function createRskClient (asset, network, mnemonic, accountType, derivationPath) function createBSCClient (asset, network, mnemonic, derivationPath) { const isTestnet = network === 'testnet' const bnbNetwork = ChainNetworks.bsc[network] - const rpcApi = isTestnet ? 'https://data-seed-prebsc-1-s1.binance.org:8545' : 'https://bsc-dataseed.binance.org' + const rpcApi = isTestnet ? 'https://data-seed-prebsc-1-s1.binance.org:8545' : evmChainToRpcProviders[56] const scraperApi = isTestnet ? 'https://liquality.io/bsc-testnet-api' : 'https://liquality.io/bsc-mainnet-api' const feeProvider = new EthereumRpcFeeProvider({ slowMultiplier: 1, averageMultiplier: 1, fastMultiplier: 1.25 }) @@ -194,7 +197,7 @@ function createBSCClient (asset, network, mnemonic, derivationPath) { function createPolygonClient (asset, network, mnemonic, derivationPath) { const isTestnet = network === 'testnet' const polygonNetwork = ChainNetworks.polygon[network] - const rpcApi = isTestnet ? 'https://rpc-mumbai.maticvigil.com' : 'https://rpc-mainnet.maticvigil.com' + const rpcApi = isTestnet ? 'https://rpc-mumbai.maticvigil.com' : evmChainToRpcProviders[137] const scraperApi = isTestnet ? 'https://liquality.io/polygon-testnet-api' : 'https://liquality.io/polygon-mainnet-api' const feeProvider = new EthereumRpcFeeProvider({ slowMultiplier: 1, averageMultiplier: 1, fastMultiplier: 1.25 }) diff --git a/src/swaps/oneinch/OneinchSwapProvider.js b/src/swaps/oneinch/OneinchSwapProvider.js index f36a0f99b..677fa5f78 100644 --- a/src/swaps/oneinch/OneinchSwapProvider.js +++ b/src/swaps/oneinch/OneinchSwapProvider.js @@ -9,16 +9,13 @@ import { prettyBalance } from '../../utils/coinFormatter' import { isEthereumChain, isERC20 } from '@/utils/asset' import cryptoassets from '@/utils/cryptoassets' import * as ethers from 'ethers' -import buildConfig from '../../build.config' import ERC20 from '@uniswap/v2-core/build/ERC20.json' +// Only bsc mainnet, ropsten testnet, eth mainnet & polygon mainnet are supported +import { evmChainToRpcProviders } from '@utils/pocket-rpc' + const nativeAssetAddress = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' const slippagePercentage = 0.5 -const chainToRpcProviders = { - 1: `https://mainnet.infura.io/v3/${buildConfig.infuraApiKey}`, - 56: 'https://bsc-dataseed.binance.org', - 137: 'https://rpc-mainnet.matic.network' -} class OneinchSwapProvider extends SwapProvider { async getSupportedPairs () { @@ -43,7 +40,7 @@ class OneinchSwapProvider extends SwapProvider { const fromAmountInUnit = BN(currencyToUnit(cryptoassets[from], BN(amount))) const chainIdFrom = ChainNetworks[cryptoassets[from].chain][network].chainId const chainIdTo = ChainNetworks[cryptoassets[to].chain][network].chainId - if (chainIdFrom !== chainIdTo || !chainToRpcProviders[chainIdFrom]) return null + if (chainIdFrom !== chainIdTo || !evmChainToRpcProviders[chainIdFrom]) return null const trade = await this._getQuote(chainIdFrom, from, to, fromAmountInUnit.toNumber()) const toAmountInUnit = BN(trade.data.toTokenAmount) @@ -60,9 +57,9 @@ class OneinchSwapProvider extends SwapProvider { const fromChain = cryptoassets[quote.from].chain const toChain = cryptoassets[quote.to].chain const chainId = ChainNetworks[fromChain][network].chainId - if (fromChain !== toChain || !chainToRpcProviders[chainId]) return null + if (fromChain !== toChain || !evmChainToRpcProviders[chainId]) return null - const api = new ethers.providers.StaticJsonRpcProvider(chainToRpcProviders[chainId]) + const api = new ethers.providers.StaticJsonRpcProvider(evmChainToRpcProviders[chainId]) const erc20 = new ethers.Contract(cryptoassets[quote.from].contractAddress, ERC20.abi, api) const fromAddressRaw = await this.getSwapAddress(network, walletId, quote.from, quote.toAccountId) const fromAddress = chains[fromChain].formatAddress(fromAddressRaw) @@ -95,7 +92,7 @@ class OneinchSwapProvider extends SwapProvider { const toChain = cryptoassets[quote.to].chain const fromChain = cryptoassets[quote.from].chain const chainId = ChainNetworks[toChain][network].chainId - if (toChain !== fromChain || !chainToRpcProviders[chainId]) return null + if (toChain !== fromChain || !evmChainToRpcProviders[chainId]) return null const account = this.getAccount(quote.fromAccountId) const client = this.getClient(network, walletId, quote.from, account?.type) diff --git a/src/swaps/thorchain/ThorchainSwapProvider.js b/src/swaps/thorchain/ThorchainSwapProvider.js index 5cf401066..5a914d9ef 100644 --- a/src/swaps/thorchain/ThorchainSwapProvider.js +++ b/src/swaps/thorchain/ThorchainSwapProvider.js @@ -4,7 +4,6 @@ import * as ethers from 'ethers' import { v4 as uuidv4 } from 'uuid' import ERC20 from '@uniswap/v2-core/build/ERC20.json' -import buildConfig from '../../build.config' import { chains, currencyToUnit, unitToCurrency } from '@liquality/cryptoassets' import cryptoassets from '@/utils/cryptoassets' import { isERC20 } from '../../utils/asset' @@ -17,6 +16,9 @@ import { SwapProvider } from '../SwapProvider' import { getTxFee } from '../../utils/fees' import { mapValues } from 'lodash-es' +// Only bsc mainnet, ropsten testnet, eth mainnet & polygon mainnet are supported +import { evmChainToRpcProviders } from '@utils/pocket-rpc' + // Pool balances are denominated with 8 decimals const THORCHAIN_DECIMAL = 8 @@ -130,7 +132,7 @@ class ThorchainSwapProvider extends SwapProvider { const fromChain = cryptoassets[quote.from].chain const chainId = ChainNetworks[fromChain][network].chainId - const api = new ethers.providers.InfuraProvider(chainId, buildConfig.infuraApiKey) + const api = new ethers.providers.StaticJsonRpcProvider(evmChainToRpcProviders[chainId]) const erc20 = new ethers.Contract(cryptoassets[quote.from].contractAddress, ERC20.abi, api) const inboundAddresses = await this._getInboundAddresses() @@ -184,7 +186,7 @@ class ThorchainSwapProvider extends SwapProvider { const routerAddress = inboundAddresses.find(inbound => inbound.chain === fromThorchainAsset.chain).router const chainId = ChainNetworks[cryptoassets[quote.from].chain][network].chainId - const api = new ethers.providers.InfuraProvider(chainId, buildConfig.infuraApiKey) + const api = new ethers.providers.StaticJsonRpcProvider(evmChainToRpcProviders[chainId]) const tokenAddress = isERC20(quote.from) ? cryptoassets[quote.from].contractAddress : '0x0000000000000000000000000000000000000000' const thorchainRouter = new ethers.Contract(routerAddress, ['function deposit(address payable vault, address asset, uint amount, string memory memo) external payable'], api) diff --git a/src/swaps/uniswap/UniswapSwapProvider.js b/src/swaps/uniswap/UniswapSwapProvider.js index 22c6ed81f..1ba9cb6c8 100644 --- a/src/swaps/uniswap/UniswapSwapProvider.js +++ b/src/swaps/uniswap/UniswapSwapProvider.js @@ -9,7 +9,6 @@ import UniswapV2Pair from '@uniswap/v2-core/build/IUniswapV2Pair.json' import UniswapV2Router from '@uniswap/v2-periphery/build/IUniswapV2Router02.json' import * as ethers from 'ethers' -import buildConfig from '../../build.config' import { chains, currencyToUnit, unitToCurrency } from '@liquality/cryptoassets' import cryptoassets from '@/utils/cryptoassets' import { isEthereumChain, isERC20 } from '../../utils/asset' @@ -18,6 +17,9 @@ import { ChainNetworks } from '@/utils/networks' import { withInterval, withLock } from '../../store/actions/performNextAction/utils' import { SwapProvider } from '../SwapProvider' +// Only bsc mainnet, ropsten testnet, eth mainnet & polygon mainnet are supported +import { evmChainToRpcProviders } from '@utils/pocket-rpc' + const SWAP_DEADLINE = 30 * 60 // 30 minutes class UniswapSwapProvider extends SwapProvider { @@ -36,7 +38,7 @@ class UniswapSwapProvider extends SwapProvider { if (chainId in this._apiCache) { return this._apiCache[chainId] } else { - const api = new ethers.providers.InfuraProvider(chainId, buildConfig.infuraApiKey) + const api = new ethers.providers.StaticJsonRpcProvider(evmChainToRpcProviders[chainId]) this._apiCache[chainId] = api return api } diff --git a/src/utils/asset.js b/src/utils/asset.js index 8b83cc1c6..bee3cf336 100644 --- a/src/utils/asset.js +++ b/src/utils/asset.js @@ -5,7 +5,9 @@ import { import cryptoassets from '@/utils/cryptoassets' import * as ethers from 'ethers' import tokenABI from './tokenABI.json' -import buildConfig from '../build.config' + +// Only bsc mainnet, ropsten testnet, eth mainnet & polygon mainnet are supported +import { evmChainToRpcProviders } from '@utils/pocket-rpc' const EXPLORERS = { ethereum: { @@ -165,12 +167,12 @@ export const getExplorerTransactionHash = (asset, hash) => { export const tokenDetailProviders = { ethereum: { async getDetails (contractAddress) { - return await fetchTokenDetails(contractAddress, `https://mainnet.infura.io/v3/${buildConfig.infuraApiKey}`) + return await fetchTokenDetails(contractAddress, evmChainToRpcProviders[1]) } }, polygon: { async getDetails (contractAddress) { - return await fetchTokenDetails(contractAddress, 'https://rpc-mainnet.matic.network/') + return await fetchTokenDetails(contractAddress, evmChainToRpcProviders[137]) } }, rsk: { @@ -180,7 +182,7 @@ export const tokenDetailProviders = { }, bsc: { async getDetails (contractAddress) { - return await fetchTokenDetails(contractAddress, 'https://bsc-dataseed.binance.org') + return await fetchTokenDetails(contractAddress, evmChainToRpcProviders[56]) } }, arbitrum: { diff --git a/src/utils/pocket-rpc.js b/src/utils/pocket-rpc.js new file mode 100644 index 000000000..fe0980905 --- /dev/null +++ b/src/utils/pocket-rpc.js @@ -0,0 +1,10 @@ +import buildConfig from '../../build.config' + +const evmChainToRpcProviders = { + 1: `https://eth-mainnet.gateway.pokt.network/v1/lb/${buildConfig.pocketApiKey[1]}`, + 3: `https://eth-ropsten.gateway.pokt.network/v1/lb/${buildConfig.pocketApiKey[3]}`, + 56: `https://bsc-mainnet.gateway.pokt.network/v1/lb/${buildConfig.pocketApiKey[56]}`, + 137: `https://poly-mainnet.gateway.pokt.network/v1/lb/${buildConfig.pocketApiKey[137]}` +} + +export { evmChainToRpcProviders }