Skip to content

Commit

Permalink
feat: poll noves indexer data (#2868)
Browse files Browse the repository at this point in the history
* feat: poll noves indexer data

* feat: move network id to noves chain map to auxiliary and adds noves chain enum

* fix: change promise all to promise all settled

* fix: adds pagination to novesApi.getTransactionsFromAddress
  • Loading branch information
jeeanribeiro authored Oct 15, 2024
1 parent 6a76e38 commit 8f2e3ed
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,27 @@ export class NovesTranslateApi extends NovesBaseApi {
accountAddress: string,
chain: string,
options?: NovesTxsOptions
): Promise<NovesTxsResponse | undefined> {
): Promise<NovesTxResponse[]> {
const response = await this.get<NovesTxsResponse>({
path: `evm/${chain}/txs/${accountAddress}`,
queryParameters: options as QueryParameters,
})
return response

if (response) {
const responses = await this.recursiveRequest([response], response)

const items = responses.reduce((acc, response) => {
if (response.items.length > 0) {
return [...acc, ...response.items]
} else {
return acc
}
}, [] as NovesTxResponse[])

return items
}

return []
}

async getHistoryFromAddress(
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/lib/auxiliary/noves/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './supported-network-id-to-noves-chain.constant'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NetworkId } from '../../../core/network/types'
import { SupportedNetworkId } from '../../../core/network/constants/supported-network-id.constant'
import { SupportedNovesChain } from '../enums'

export const SUPPORTED_NETWORK_ID_TO_NOVES_CHAIN: Readonly<{ [key in NetworkId]?: string }> = {
[SupportedNetworkId.ShimmerEvm]: SupportedNovesChain.ShimmerEvm,
[SupportedNetworkId.Ethereum]: SupportedNovesChain.Ethereum,
[SupportedNetworkId.Sepolia]: SupportedNovesChain.Sepolia,
[SupportedNetworkId.Arbitrum]: SupportedNovesChain.Arbitrum,
[SupportedNetworkId.Base]: SupportedNovesChain.Base,
[SupportedNetworkId.Blast]: SupportedNovesChain.Blast,
[SupportedNetworkId.Optimism]: SupportedNovesChain.Optimism,
[SupportedNetworkId.Bnb]: SupportedNovesChain.Bnb,
}
1 change: 1 addition & 0 deletions packages/shared/src/lib/auxiliary/noves/enums/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './eth-rpc-method.enum'
export * from './supported-noves-chain.enum'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum SupportedNovesChain {
ShimmerEvm = 'shimmer-evm',
Ethereum = 'eth',
Sepolia = 'eth-sepolia',
Arbitrum = 'arbitrum',
Base = 'base',
Blast = 'blast',
Optimism = 'optimism',
Bnb = 'bsc',
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { NovesTokenBalancesResponse } from '../types'
import { NovesHistoryItem } from './noves-history-response.interface'
import { NovesTxDescriptionResponse } from './noves-tx-description-response.interface'
import { NovesTxResponse } from './noves-tx-response.interface'
import { NovesTxsResponse } from './noves-txs-response.interface'

export interface INovesTranslateApi {
getTransaction(txHash: string, chain: string, viewAsAccountAddress?: string): Promise<NovesTxResponse | undefined>
Expand All @@ -11,7 +10,7 @@ export interface INovesTranslateApi {
accountAddress: string,
chain: string,
options?: NovesTxsOptions
): Promise<NovesTxsResponse | undefined>
): Promise<NovesTxResponse[] | undefined>
getHistoryFromAddress(
accountAddress: string,
chain: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
import { NetworkId } from '../types'
import { SupportedNetworkId } from './supported-network-id.constant'
import { NOVES_TRANSLATE_API_URL } from './noves-translate-api-url.constant'
import { SupportedNovesChain } from '@auxiliary/noves/enums'

export const DEFAULT_NOVES_INDEXER_URLS: Readonly<{ [key in NetworkId]?: string }> = {
// IOTA
[SupportedNetworkId.IotaEvm]: '',
[SupportedNetworkId.IotaTestnetEvm]: '',

// Shimmer
[SupportedNetworkId.ShimmerEvm]: getEvmIndexerUrl('shimmer-evm'),
[SupportedNetworkId.ShimmerEvm]: getEvmIndexerUrl(SupportedNovesChain.ShimmerEvm),
[SupportedNetworkId.TestnetEvm]: '',

// Ethereum
[SupportedNetworkId.Ethereum]: getEvmIndexerUrl('eth'),
[SupportedNetworkId.Sepolia]: getEvmIndexerUrl('eth-sepolia'),
[SupportedNetworkId.Ethereum]: getEvmIndexerUrl(SupportedNovesChain.Ethereum),
[SupportedNetworkId.Sepolia]: getEvmIndexerUrl(SupportedNovesChain.Sepolia),

// Arbitrum
[SupportedNetworkId.Arbitrum]: getEvmIndexerUrl('arbitrum'),
[SupportedNetworkId.Arbitrum]: getEvmIndexerUrl(SupportedNovesChain.Arbitrum),
[SupportedNetworkId.ArbitrumSepoliaTestnet]: '',

// Base
[SupportedNetworkId.Base]: getEvmIndexerUrl('base'),
[SupportedNetworkId.Base]: getEvmIndexerUrl(SupportedNovesChain.Base),
[SupportedNetworkId.BaseSepoliaTestnet]: '',

// Blast
[SupportedNetworkId.Blast]: getEvmIndexerUrl('blast'),
[SupportedNetworkId.Blast]: getEvmIndexerUrl(SupportedNovesChain.Blast),
[SupportedNetworkId.BlastSepoliaTestnet]: '',

// Immutable
[SupportedNetworkId.Immutable]: '',
[SupportedNetworkId.ImmutableTestnet]: '',

// Optimism
[SupportedNetworkId.Optimism]: getEvmIndexerUrl('optimism'),
[SupportedNetworkId.Optimism]: getEvmIndexerUrl(SupportedNovesChain.Optimism),
[SupportedNetworkId.OptimismSepoliaTestnet]: '',

// BNB Smart Chain
[SupportedNetworkId.Bnb]: getEvmIndexerUrl('bsc'),
[SupportedNetworkId.Bnb]: getEvmIndexerUrl(SupportedNovesChain.Bnb),
[SupportedNetworkId.BnbTestnet]: '',
}

Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/lib/core/network/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from './network-status-poll-interval.constant'
export * from './noves-translate-api-url.constant'
export * from './seconds-per-milestone.constant'
export * from './supported-network-id.constant'
export * from '../../../auxiliary/noves/constants/supported-network-id-to-noves-chain.constant'
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
isBlockscoutTransactionPersisted,
} from '../stores'
import { BlockscoutApi } from '@auxiliary/blockscout/api'
import { EvmNetworkId, IEvmNetwork, getEvmNetworks } from '@core/network'
import { EvmNetworkId, IEvmNetwork, SUPPORTED_NETWORK_ID_TO_NOVES_CHAIN, getEvmNetworks } from '@core/network'
import { BlockscoutTokenTransfer } from '@auxiliary/blockscout/types'
import { generateEvmActivityFromPersistedTransaction } from '@core/activity/utils'
import { EvmActivity, addAccountActivities, allAccountActivities } from '@core/activity'
import { get } from 'svelte/store'
import { NovesApi, NovesTxResponse } from '@auxiliary/noves'

export async function fetchAndPersistTransactionsForAccounts(
profileId: string,
Expand All @@ -35,7 +36,16 @@ export async function fetchAndPersistTransactionsForNetwork(
): Promise<void> {
for (const account of accounts) {
try {
const blockscoutTransactions = await fetchBlockscoutTransactionsForAccount(profileId, account, network)
const [blockscoutTransactionsPromise, novesTransactionsPromise] = await Promise.allSettled([
fetchBlockscoutTransactionsForAccount(profileId, account, network),
fetchNovesTransactionsForAccount(account, network),
])

const blockscoutTransactions =
blockscoutTransactionsPromise.status === 'fulfilled' && blockscoutTransactionsPromise.value
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const novesTransactions = novesTransactionsPromise.status === 'fulfilled' && novesTransactionsPromise.value

blockscoutTransactions &&
addBlockscoutTransactionToPersistedTransactions(
profileId,
Expand Down Expand Up @@ -119,6 +129,21 @@ async function fetchBlockscoutTransactionsForAccount(
return transactions
}

async function fetchNovesTransactionsForAccount(
account: IAccountState,
network: IEvmNetwork
): Promise<NovesTxResponse[]> {
const address = getAddressFromAccountForNetwork(account, network.id)
const novesChain = SUPPORTED_NETWORK_ID_TO_NOVES_CHAIN[network.id]
if (!address || !novesChain) {
return []
}

const novesApi = new NovesApi()
const transactions = await novesApi.translate.getTransactionsFromAddress(address, novesChain)
return transactions
}

function getTokenTransferExitFunction(
items: BlockscoutTokenTransfer[],
profileId: string,
Expand Down

0 comments on commit 8f2e3ed

Please sign in to comment.