diff --git a/layer/Service.ts b/layer/Service.ts index 27d00df9..6e9a92f2 100644 --- a/layer/Service.ts +++ b/layer/Service.ts @@ -30,20 +30,18 @@ import { IndexerRestDerivativesChronosApi, } from '@injectivelabs/sdk-ts' import { TokenMetaUtilsFactory } from '@injectivelabs/token-metadata' -import { MsgBroadcaster, Web3Broadcaster } from '@injectivelabs/wallet-ts' import { SpotCacheApi } from './providers/cacheApi/spot' import { TokenCacheApi } from './providers/cacheApi/token' import { StakingCacheApi } from './providers/cacheApi/staking' import { DerivativeCacheApi } from './providers/cacheApi/derivative' -import { walletStrategy, alchemyRpcEndpoint } from './wallet/wallet-strategy' import { NETWORK, CHAIN_ID, ENDPOINTS, COINGECKO_KEY, ETHEREUM_CHAIN_ID, - FEE_PAYER_PUB_KEY } from './utils/constant' +import { alchemyRpcEndpoint } from './wallet/alchemy' // Services export const bankApi = new ChainGrpcBankApi(ENDPOINTS.grpc) @@ -118,19 +116,4 @@ export const web3Composer = new Web3Composer({ ethereumChainId: ETHEREUM_CHAIN_ID }) -// Transaction broadcaster -export const msgBroadcaster = new MsgBroadcaster({ - walletStrategy, - network: NETWORK, - networkEndpoints: ENDPOINTS, - feePayerPubKey: FEE_PAYER_PUB_KEY, - simulateTx: true -}) - -export const web3Broadcaster = new Web3Broadcaster({ - walletStrategy, - network: NETWORK, - ethereumChainId: ETHEREUM_CHAIN_ID -}) - export const tokenMetaUtils = TokenMetaUtilsFactory.make(NETWORK) diff --git a/layer/WalletService.ts b/layer/WalletService.ts new file mode 100644 index 00000000..5b69185d --- /dev/null +++ b/layer/WalletService.ts @@ -0,0 +1,23 @@ +import { MsgBroadcaster, Web3Broadcaster } from '@injectivelabs/wallet-ts' +import { walletStrategy } from './wallet/wallet-strategy' +import { + NETWORK, + ENDPOINTS, + ETHEREUM_CHAIN_ID, + FEE_PAYER_PUB_KEY +} from './utils/constant' + +// Transaction broadcaster +export const msgBroadcaster = new MsgBroadcaster({ + walletStrategy, + network: NETWORK, + endpoints: ENDPOINTS, + feePayerPubKey: FEE_PAYER_PUB_KEY, + simulateTx: true +}) + +export const web3Broadcaster = new Web3Broadcaster({ + walletStrategy, + network: NETWORK, + ethereumChainId: ETHEREUM_CHAIN_ID +}) diff --git a/layer/wallet/alchemy.ts b/layer/wallet/alchemy.ts new file mode 100644 index 00000000..21d06a9e --- /dev/null +++ b/layer/wallet/alchemy.ts @@ -0,0 +1,24 @@ +import { EthereumChainId } from '@injectivelabs/ts-types' +import { + IS_TESTNET, + ALCHEMY_KEY, + ALCHEMY_KOVAN_KEY, + ALCHEMY_GOERLI_KEY +} from './../utils/constant' + +export const getRpcUrlsForChainIds = (): Record => { + return { + [EthereumChainId.Ganache]: 'http://localhost:8545', + [EthereumChainId.HardHat]: 'http://localhost:8545', + [EthereumChainId.Goerli]: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_GOERLI_KEY}`, + [EthereumChainId.Kovan]: `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_KOVAN_KEY}`, + [EthereumChainId.Mainnet]: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}`, + [EthereumChainId.Injective]: '', + [EthereumChainId.Rinkeby]: '', + [EthereumChainId.Ropsten]: '' + } +} + +export const alchemyRpcEndpoint = IS_TESTNET + ? `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_GOERLI_KEY}` + : `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}` diff --git a/layer/wallet/wallet-strategy.ts b/layer/wallet/wallet-strategy.ts index d6a53ed7..f7aa601e 100644 --- a/layer/wallet/wallet-strategy.ts +++ b/layer/wallet/wallet-strategy.ts @@ -1,30 +1,6 @@ -import { EthereumChainId } from '@injectivelabs/ts-types' import { WalletStrategy } from '@injectivelabs/wallet-ts' -import { - CHAIN_ID, - IS_TESTNET, - ALCHEMY_KEY, - ETHEREUM_CHAIN_ID, - ALCHEMY_KOVAN_KEY, - ALCHEMY_GOERLI_KEY -} from './../utils/constant' - -export const getRpcUrlsForChainIds = (): Record => { - return { - [EthereumChainId.Ganache]: 'http://localhost:8545', - [EthereumChainId.HardHat]: 'http://localhost:8545', - [EthereumChainId.Goerli]: `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_GOERLI_KEY}`, - [EthereumChainId.Kovan]: `https://eth-kovan.alchemyapi.io/v2/${ALCHEMY_KOVAN_KEY}`, - [EthereumChainId.Mainnet]: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}`, - [EthereumChainId.Injective]: '', - [EthereumChainId.Rinkeby]: '', - [EthereumChainId.Ropsten]: '' - } -} - -export const alchemyRpcEndpoint = IS_TESTNET - ? `https://eth-goerli.alchemyapi.io/v2/${ALCHEMY_GOERLI_KEY}` - : `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_KEY}` +import { CHAIN_ID, ETHEREUM_CHAIN_ID } from './../utils/constant' +import { getRpcUrlsForChainIds } from './alchemy' const rpcUrls = getRpcUrlsForChainIds()