Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 __mocks__/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ethersMock = {
...ethers,
providers: {
JsonRpcProvider: vi.fn(),
JsonRpcBatchProvider: vi.fn(),
StaticJsonRpcProvider: vi.fn(),
},
Contract: vi.fn().mockImplementation(address => ({
decimals: () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/caip/src/adapters/yearn/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { toChainId } from '../../chainId/chainId'
import { CHAIN_NAMESPACE, CHAIN_REFERENCE } from '../../constants'

const network = 1 // 1 for mainnet
const provider = new ethers.providers.JsonRpcBatchProvider(process.env.REACT_APP_ETHEREUM_NODE_URL)
const provider = new ethers.providers.StaticJsonRpcProvider(process.env.REACT_APP_ETHEREUM_NODE_URL)
const yearnSdk = new Yearn(network, { provider })

export const writeFiles = async (data: Record<string, Record<string, string>>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export interface TxMetadata extends BaseTxMetadata {

interface ParserArgs {
chainId: ChainId
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider
}

export class Parser<T extends Tx> implements SubParser<T> {
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider

readonly chainId: ChainId
readonly abiInterface = new ethers.utils.Interface(bep20)
Expand Down
4 changes: 2 additions & 2 deletions packages/unchained-client/src/evm/ethereum/parser/uniV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export interface TxMetadata extends BaseTxMetadata {

export interface ParserArgs {
chainId: ChainId
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider
}

export class Parser implements SubParser<Tx> {
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider
readonly chainId: ChainId
readonly wethContract: string
readonly abiInterface = new ethers.utils.Interface(UNIV2_ABI)
Expand Down
4 changes: 2 additions & 2 deletions packages/unchained-client/src/evm/ethereum/parser/weth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export interface TxMetadata extends BaseTxMetadata {

export interface ParserArgs {
chainId: ChainId
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider
}

export class Parser implements SubParser<Tx> {
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider
readonly chainId: ChainId
readonly wethContract: string
readonly abiInterface = new ethers.utils.Interface(WETH_ABI)
Expand Down
4 changes: 2 additions & 2 deletions packages/unchained-client/src/evm/parser/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export interface TxMetadata extends BaseTxMetadata {

interface ParserArgs {
chainId: ChainId
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider
}

export class Parser<T extends Tx> implements SubParser<T> {
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider

readonly chainId: ChainId
readonly abiInterface = new ethers.utils.Interface(ERC20_ABI)
Expand Down
4 changes: 2 additions & 2 deletions packages/unchained-client/src/evm/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export class BaseTransactionParser<T extends Tx> {
assetId: AssetId

protected readonly api: Api
protected readonly provider: ethers.providers.JsonRpcBatchProvider
protected readonly provider: ethers.providers.StaticJsonRpcProvider

private parsers: SubParser<T>[] = []

constructor(args: BaseTransactionParserArgs) {
this.chainId = args.chainId
this.assetId = args.assetId
this.api = args.api
this.provider = new ethers.providers.JsonRpcBatchProvider(args.rpcUrl)
this.provider = new ethers.providers.StaticJsonRpcProvider(args.rpcUrl)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/unchained-client/src/evm/parser/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export interface TxMetadata extends BaseTxMetadata {
interface ParserArgs {
chainId: ChainId
api: Api
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider
}

const supportedTokenTypes = ['ERC721', 'ERC1155', 'BEP721', 'BEP1155']

export class Parser<T extends Tx> implements SubParser<T> {
provider: ethers.providers.JsonRpcBatchProvider
provider: ethers.providers.StaticJsonRpcProvider

readonly chainId: ChainId
readonly api: Api
Expand Down
2 changes: 1 addition & 1 deletion scripts/generateAssetData/ethereum/yearnVaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ethereum } from '../baseAssets'
import { colorMap } from '../colorMap'

const network = 1 // 1 for mainnet
const provider = new ethers.providers.JsonRpcBatchProvider(process.env.ETHEREUM_NODE_URL)
const provider = new ethers.providers.StaticJsonRpcProvider(process.env.ETHEREUM_NODE_URL)
export const yearnSdk = new Yearn(network, { provider })

const explorerData = {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ethersProviderSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export const rpcUrlByChainId = (chainId: EvmChainId): string => {
}
}

const ethersProviders: Map<ChainId, providers.JsonRpcBatchProvider> = new Map()
const ethersProviders: Map<ChainId, providers.StaticJsonRpcProvider> = new Map()

export const getEthersProvider = (
chainId: EvmChainId = KnownChainIds.EthereumMainnet,
): providers.JsonRpcBatchProvider => {
): providers.StaticJsonRpcProvider => {
if (!ethersProviders.has(chainId)) {
const provider = new providers.JsonRpcBatchProvider(rpcUrlByChainId(chainId))
const provider = new providers.StaticJsonRpcProvider(rpcUrlByChainId(chainId))
ethersProviders.set(chainId, provider)
return provider
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/lib/investor/investor-foxy/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type EthereumChainReference =
export type ConstructorArgs = {
adapter: EvmBaseAdapter<KnownChainIds.EthereumMainnet>
providerUrl: string
provider: ethers.providers.StaticJsonRpcProvider
foxyAddresses: FoxyAddressesType
chainReference?: EthereumChainReference
}
Expand All @@ -83,9 +84,8 @@ const TOKE_IPFS_URL = 'https://ipfs.tokemaklabs.xyz/ipfs'

export class FoxyApi {
public adapter: EvmBaseAdapter<KnownChainIds.EthereumMainnet>
public provider: ethers.providers.JsonRpcBatchProvider
public provider: ethers.providers.StaticJsonRpcProvider
private providerUrl: string
public jsonRpcProvider: ethers.providers.JsonRpcBatchProvider
private foxyStakingContracts: ethers.Contract[]
private liquidityReserveContracts: ethers.Contract[]
private readonly ethereumChainReference: ChainReference
Expand All @@ -96,10 +96,10 @@ export class FoxyApi {
providerUrl,
foxyAddresses,
chainReference = CHAIN_REFERENCE.EthereumMainnet,
provider,
}: ConstructorArgs) {
this.adapter = adapter
this.provider = new ethers.providers.JsonRpcBatchProvider(providerUrl)
this.jsonRpcProvider = new ethers.providers.JsonRpcBatchProvider(providerUrl)
this.provider = provider
this.foxyStakingContracts = foxyAddresses.map(
addresses => new ethers.Contract(addresses.staking, foxyStakingAbi, this.provider),
)
Expand Down
4 changes: 4 additions & 0 deletions src/lib/investor/investor-foxy/foxycli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NativeHDWallet } from '@shapeshiftoss/hdwallet-native'
import { WithdrawType } from '@shapeshiftoss/types'
import * as unchained from '@shapeshiftoss/unchained-client'
import dotenv from 'dotenv'
import { ethers } from 'ethers'
import readline from 'readline-sync'
import { bnOrZero } from 'lib/bignumber/bignumber'

Expand Down Expand Up @@ -54,6 +55,9 @@ const main = async (): Promise<void> => {
adapter: ethChainAdapter,
providerUrl: process.env.ARCHIVE_NODE || 'http://127.0.0.1:8545/',
foxyAddresses,
provider: new ethers.providers.StaticJsonRpcProvider(
process.env.ARCHIVE_NODE || 'http://127.0.0.1:8545/',
),
})

const accountNumber = 0
Expand Down
2 changes: 2 additions & 0 deletions src/lib/market-service/foxy/foxy.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { HistoryTimeframe } from '@shapeshiftoss/types'
import type { AxiosInstance } from 'axios'
import { ethers } from 'ethers'
import { beforeAll, describe, expect, it, vi } from 'vitest'
import { bn } from 'lib/bignumber/bignumber'

import { FOXY_ASSET_ID, FoxyMarketService } from './foxy'
import { fox, mockFoxyMarketData } from './foxyMockData'

const foxyMarketService = new FoxyMarketService({
provider: new ethers.providers.StaticJsonRpcProvider(''),
providerUrls: {
jsonRpcProviderUrl: 'dummy',
unchainedEthereumHttpUrl: '',
Expand Down
14 changes: 12 additions & 2 deletions src/lib/market-service/foxy/foxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
PriceHistoryArgs,
} from '@shapeshiftoss/types'
import * as unchained from '@shapeshiftoss/unchained-client'
import type { ethers } from 'ethers'
import { foxyAddresses, FoxyApi } from 'lib/investor/investor-foxy'

import type { MarketService } from '../api'
Expand All @@ -19,11 +20,19 @@ const FOXY_ASSET_PRECISION = '18'

export class FoxyMarketService extends CoinGeckoMarketService implements MarketService {
providerUrls: ProviderUrls

constructor({ providerUrls }: { providerUrls: ProviderUrls }) {
provider: ethers.providers.StaticJsonRpcProvider

constructor({
providerUrls,
provider,
}: {
providerUrls: ProviderUrls
provider: ethers.providers.StaticJsonRpcProvider
}) {
super()

this.providerUrls = providerUrls
this.provider = provider
}

async findAll() {
Expand Down Expand Up @@ -71,6 +80,7 @@ export class FoxyMarketService extends CoinGeckoMarketService implements MarketS
adapter: ethChainAdapter,
providerUrl: this.providerUrls.jsonRpcProviderUrl,
foxyAddresses,
provider: this.provider,
})

const tokenContractAddress = foxyAddresses[0].foxy
Expand Down
6 changes: 4 additions & 2 deletions src/lib/market-service/market-service-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
MarketDataArgs,
PriceHistoryArgs,
} from '@shapeshiftoss/types'
import type { ethers } from 'ethers'
import { AssetService } from 'lib/asset-service'

// import { Yearn } from '@yfi/sdk'
Expand All @@ -25,14 +26,15 @@ export type ProviderUrls = {
export type MarketServiceManagerArgs = {
yearnChainReference: 1 | 250 | 1337 | 42161 // from @yfi/sdk
providerUrls: ProviderUrls
provider: ethers.providers.StaticJsonRpcProvider
}

export class MarketServiceManager {
marketProviders: MarketService[]
assetService: AssetService

constructor(args: MarketServiceManagerArgs) {
const { providerUrls } = args
const { providerUrls, provider } = args

// TODO(0xdef1cafe): after chain agnosticism, we need to dependency inject a chainReference here
// YearnVaultMarketCapService deps
Expand All @@ -48,7 +50,7 @@ export class MarketServiceManager {
// Yearn is currently borked upstream
// new YearnVaultMarketCapService({ yearnSdk }),
// new YearnTokenMarketCapService({ yearnSdk }),
new FoxyMarketService({ providerUrls }),
new FoxyMarketService({ providerUrls, provider }),
]

this.assetService = new AssetService()
Expand Down
2 changes: 2 additions & 0 deletions src/lib/market-service/market-service.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HistoryTimeframe } from '@shapeshiftoss/types'
import { ethers } from 'ethers'
import { describe, expect, it, vi } from 'vitest'

import { CoinGeckoMarketService } from './coingecko/coingecko'
Expand Down Expand Up @@ -99,6 +100,7 @@ describe('market service', () => {
const marketServiceManagerArgs = {
coinGeckoAPIKey: 'dummyCoingeckoApiKey',
yearnChainReference: 1 as const,
provider: new ethers.providers.StaticJsonRpcProvider(''),
providerUrls: {
jsonRpcProviderUrl: '',
unchainedEthereumWsUrl: '',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/walletConnectToDapps/hooks/useGetAbi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useGetAbi = (

const { to: contractAddress, data } = transactionParams
const provider = useMemo(
() => new ethers.providers.JsonRpcBatchProvider(getConfig().REACT_APP_ETHEREUM_NODE_URL),
() => new ethers.providers.StaticJsonRpcProvider(getConfig().REACT_APP_ETHEREUM_NODE_URL),
[],
)

Expand Down
2 changes: 2 additions & 0 deletions src/state/apis/foxy/foxyApiSingleton.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { EvmBaseAdapter } from '@shapeshiftoss/chain-adapters'
import { KnownChainIds } from '@shapeshiftoss/types'
import { getConfig } from 'config'
import { getEthersProvider } from 'lib/ethersProviderSingleton'
import { foxyAddresses, FoxyApi } from 'lib/investor/investor-foxy'
import { assertGetEvmChainAdapter } from 'lib/utils/evm'

Expand All @@ -19,6 +20,7 @@ export const getFoxyApi = (): FoxyApi => {
) as EvmBaseAdapter<KnownChainIds.EthereumMainnet>,
providerUrl: getConfig()[RPC_PROVIDER_ENV],
foxyAddresses,
provider: getEthersProvider(KnownChainIds.EthereumMainnet),
})

_foxyApi = foxyApi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// do not directly use or export, singleton
import { KnownChainIds } from '@shapeshiftoss/types'
import { getConfig } from 'config'
import { getEthersProvider } from 'lib/ethersProviderSingleton'
import { MarketServiceManager } from 'lib/market-service'

let _marketServiceManager: MarketServiceManager | undefined
Expand All @@ -11,6 +13,7 @@ export const getMarketServiceManager: GetMarketServiceManager = () => {
if (!_marketServiceManager) {
_marketServiceManager = new MarketServiceManager({
yearnChainReference: 1, // CHAIN_REFERENCE.EthereumMainnet is '1', yearn requires strict number union
provider: getEthersProvider(KnownChainIds.EthereumMainnet),
providerUrls: {
jsonRpcProviderUrl: config.REACT_APP_ETHEREUM_NODE_URL,
unchainedEthereumHttpUrl: config.REACT_APP_UNCHAINED_ETHEREUM_HTTP_URL,
Expand Down