Skip to content

Commit

Permalink
refactor: separate wallet and normal services
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Jan 21, 2024
1 parent 5542ec6 commit 96d2e07
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 44 deletions.
19 changes: 1 addition & 18 deletions layer/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
23 changes: 23 additions & 0 deletions layer/WalletService.ts
Original file line number Diff line number Diff line change
@@ -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
})
24 changes: 24 additions & 0 deletions layer/wallet/alchemy.ts
Original file line number Diff line number Diff line change
@@ -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<EthereumChainId, string> => {
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}`
28 changes: 2 additions & 26 deletions layer/wallet/wallet-strategy.ts
Original file line number Diff line number Diff line change
@@ -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<EthereumChainId, string> => {
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()

Expand Down

0 comments on commit 96d2e07

Please sign in to comment.