@0xtorch/evm 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/_cjs/analyzer/json/components/targetAsset.js +3 -1
  2. package/_cjs/analyzer/json/components/targetAsset.js.map +1 -1
  3. package/_cjs/analyzer/json/schemas/generator.js +1 -0
  4. package/_cjs/analyzer/json/schemas/generator.js.map +1 -1
  5. package/_cjs/decoder/decode.js +1 -1
  6. package/_cjs/decoder/decode.js.map +1 -1
  7. package/_cjs/decoder/parseErc1155TransferSingleLogs.js +1 -1
  8. package/_cjs/decoder/parseErc1155TransferSingleLogs.js.map +1 -1
  9. package/_cjs/decoder/parseErc721TransferLogs.js +1 -1
  10. package/_cjs/decoder/parseErc721TransferLogs.js.map +1 -1
  11. package/_cjs/index.js +5 -2
  12. package/_cjs/index.js.map +1 -1
  13. package/_cjs/utils/create.js +9 -3
  14. package/_cjs/utils/create.js.map +1 -1
  15. package/_cjs/utils/index.js +5 -2
  16. package/_cjs/utils/index.js.map +1 -1
  17. package/_esm/analyzer/json/components/targetAsset.js +4 -2
  18. package/_esm/analyzer/json/components/targetAsset.js.map +1 -1
  19. package/_esm/analyzer/json/schemas/generator.js +1 -0
  20. package/_esm/analyzer/json/schemas/generator.js.map +1 -1
  21. package/_esm/decoder/decode.js +2 -2
  22. package/_esm/decoder/decode.js.map +1 -1
  23. package/_esm/decoder/parseErc1155TransferSingleLogs.js +2 -2
  24. package/_esm/decoder/parseErc1155TransferSingleLogs.js.map +1 -1
  25. package/_esm/decoder/parseErc721TransferLogs.js +2 -2
  26. package/_esm/decoder/parseErc721TransferLogs.js.map +1 -1
  27. package/_esm/index.js +1 -1
  28. package/_esm/index.js.map +1 -1
  29. package/_esm/utils/create.js +4 -1
  30. package/_esm/utils/create.js.map +1 -1
  31. package/_esm/utils/index.js +1 -1
  32. package/_esm/utils/index.js.map +1 -1
  33. package/_types/analyzer/json/components/targetAsset.d.ts.map +1 -1
  34. package/_types/analyzer/json/schemas/generator.d.ts +3 -0
  35. package/_types/analyzer/json/schemas/generator.d.ts.map +1 -1
  36. package/_types/index.d.ts +2 -2
  37. package/_types/index.d.ts.map +1 -1
  38. package/_types/types/erc1155.d.ts +1 -0
  39. package/_types/types/erc1155.d.ts.map +1 -1
  40. package/_types/types/erc721.d.ts +1 -0
  41. package/_types/types/erc721.d.ts.map +1 -1
  42. package/_types/types/index.d.ts +2 -2
  43. package/_types/types/index.d.ts.map +1 -1
  44. package/_types/utils/create.d.ts +10 -3
  45. package/_types/utils/create.d.ts.map +1 -1
  46. package/_types/utils/index.d.ts +1 -1
  47. package/_types/utils/index.d.ts.map +1 -1
  48. package/analyzer/json/components/targetAsset.ts +5 -2
  49. package/analyzer/json/schemas/generator.ts +1 -0
  50. package/decoder/decode.ts +3 -2
  51. package/decoder/parseErc1155TransferSingleLogs.ts +2 -2
  52. package/decoder/parseErc721TransferLogs.ts +2 -2
  53. package/index.ts +6 -9
  54. package/package.json +2 -2
  55. package/types/erc1155.ts +2 -0
  56. package/types/erc721.ts +2 -0
  57. package/types/index.ts +2 -2
  58. package/utils/create.ts +19 -4
  59. package/utils/index.ts +4 -1
  60. package/getAccountsTransactionFulls/getAccountsTransactionFulls.ts +0 -46
  61. package/getAccountsTransactionFulls/getAccountsTransactionFullsCustom.ts +0 -106
  62. package/getAccountsTransactionFulls/getDecodedTransactionsPrices.ts +0 -97
  63. package/getAccountsTransactionFulls/getHashesAndInternalTxs.ts +0 -65
  64. package/getAccountsTransactionFulls/getTransactionDetails.ts +0 -41
  65. package/getAccountsTransactionFulls/getTransactionsApps.ts +0 -42
  66. package/getAccountsTransactionFulls/index.ts +0 -2
  67. package/getAccountsTransactionFulls/types.ts +0 -122
  68. package/getAccountsTransactionFulls/withD.ts +0 -80
  69. package/getAccountsTransactionFulls/withDA.ts +0 -112
  70. package/getAccountsTransactionFulls/withP.ts +0 -120
  71. package/getAccountsTransactionFulls/withPD.ts +0 -141
  72. package/getAccountsTransactionFulls/withPDA.ts +0 -167
  73. package/getAccountsTransactionFulls/withUndefined.ts +0 -88
  74. package/getTransactionFull/getTransactionFull.ts +0 -30
  75. package/getTransactionFull/getTransactionFullCustom.ts +0 -91
  76. package/getTransactionFull/index.ts +0 -2
  77. package/getTransactionFull/types.ts +0 -98
  78. package/getTransactionFull/withD.ts +0 -57
  79. package/getTransactionFull/withDA.ts +0 -78
  80. package/getTransactionFull/withP.ts +0 -69
  81. package/getTransactionFull/withPD.ts +0 -119
  82. package/getTransactionFull/withPDA.ts +0 -147
  83. package/getTransactionFull/withUndefined.ts +0 -39
@@ -1,122 +0,0 @@
1
- import type {
2
- CryptoCurrencyDataSource,
3
- CryptoCurrencyPrice,
4
- FiatCurrency,
5
- } from '@0xtorch/core'
6
- import type { Analyzer } from '../analyzer'
7
- import type { AppDataSource } from '../apps'
8
- import type { Chain } from '../chains'
9
- import type { Decoder } from '../decoder'
10
- import type { LowerHex, TransactionFull } from '../types'
11
-
12
- export type GetAccountsTransactionFullsCustomParameters =
13
- | GetAccountsTransactionFullsCustomParametersAllUndefined
14
- | GetAccountsTransactionFullsCustomParametersP
15
- | GetAccountsTransactionFullsCustomParametersPD
16
- | GetAccountsTransactionFullsCustomParametersPDA
17
- | GetAccountsTransactionFullsCustomParametersD
18
- | GetAccountsTransactionFullsCustomParametersDA
19
-
20
- export type GetAccountsTransactionFullsCustomParametersAllUndefined = {
21
- readonly chain: Chain
22
- readonly addresses: readonly LowerHex[]
23
- readonly fromBlock: bigint
24
- readonly toBlock: bigint
25
- readonly appDataSource: AppDataSource | undefined
26
- readonly priceDataSource: undefined
27
- readonly fiat: undefined
28
- readonly decoder: undefined
29
- readonly analyzer: undefined
30
- readonly onFetchHashes?: (hashes: readonly LowerHex[]) => void
31
- readonly onFetchTransaction?: (hash: LowerHex) => void
32
- }
33
-
34
- export type GetAccountsTransactionFullsCustomParametersP = {
35
- readonly chain: Chain
36
- readonly addresses: readonly LowerHex[]
37
- readonly fromBlock: bigint
38
- readonly toBlock: bigint
39
- readonly appDataSource: AppDataSource | undefined
40
- readonly priceDataSource: CryptoCurrencyDataSource
41
- readonly fiat: FiatCurrency
42
- readonly decoder: undefined
43
- readonly analyzer: undefined
44
- readonly onFetchHashes?: (hashes: readonly LowerHex[]) => void
45
- readonly onFetchTransaction?: (hash: LowerHex) => void
46
- }
47
-
48
- export type GetAccountsTransactionFullsCustomParametersPD = {
49
- readonly chain: Chain
50
- readonly addresses: readonly LowerHex[]
51
- readonly fromBlock: bigint
52
- readonly toBlock: bigint
53
- readonly appDataSource: AppDataSource | undefined
54
- readonly priceDataSource: CryptoCurrencyDataSource
55
- readonly fiat: FiatCurrency
56
- readonly decoder: Decoder
57
- readonly analyzer: undefined
58
- readonly onFetchHashes?: (hashes: readonly LowerHex[]) => void
59
- readonly onFetchTransaction?: (hash: LowerHex) => void
60
- }
61
-
62
- export type GetAccountsTransactionFullsCustomParametersPDA = {
63
- readonly chain: Chain
64
- readonly addresses: readonly LowerHex[]
65
- readonly fromBlock: bigint
66
- readonly toBlock: bigint
67
- readonly appDataSource: AppDataSource | undefined
68
- readonly priceDataSource: CryptoCurrencyDataSource
69
- readonly fiat: FiatCurrency
70
- readonly decoder: Decoder
71
- readonly analyzer: Analyzer<CryptoCurrencyPrice | undefined>
72
- readonly onFetchHashes?: (hashes: readonly LowerHex[]) => void
73
- readonly onFetchTransaction?: (hash: LowerHex) => void
74
- }
75
-
76
- export type GetAccountsTransactionFullsCustomParametersD = {
77
- readonly chain: Chain
78
- readonly addresses: readonly LowerHex[]
79
- readonly fromBlock: bigint
80
- readonly toBlock: bigint
81
- readonly appDataSource: AppDataSource | undefined
82
- readonly priceDataSource: undefined
83
- readonly fiat: undefined
84
- readonly decoder: Decoder
85
- readonly analyzer: undefined
86
- readonly onFetchHashes?: (hashes: readonly LowerHex[]) => void
87
- readonly onFetchTransaction?: (hash: LowerHex) => void
88
- }
89
-
90
- export type GetAccountsTransactionFullsCustomParametersDA = {
91
- readonly chain: Chain
92
- readonly addresses: readonly LowerHex[]
93
- readonly fromBlock: bigint
94
- readonly toBlock: bigint
95
- readonly appDataSource: AppDataSource | undefined
96
- readonly priceDataSource: undefined
97
- readonly fiat: undefined
98
- readonly decoder: Decoder
99
- readonly analyzer: Analyzer<undefined>
100
- readonly onFetchHashes?: (hashes: readonly LowerHex[]) => void
101
- readonly onFetchTransaction?: (hash: LowerHex) => void
102
- }
103
-
104
- export type GetAccountsTransactionFullsCustomReturnType<
105
- T extends GetAccountsTransactionFullsCustomParameters,
106
- > = T extends GetAccountsTransactionFullsCustomParametersAllUndefined
107
- ? readonly TransactionFull<undefined, false, false>[]
108
- : T extends GetAccountsTransactionFullsCustomParametersP
109
- ? readonly TransactionFull<CryptoCurrencyPrice | undefined, false, false>[]
110
- : T extends GetAccountsTransactionFullsCustomParametersPD
111
- ? readonly TransactionFull<CryptoCurrencyPrice | undefined, true, false>[]
112
- : T extends GetAccountsTransactionFullsCustomParametersPDA
113
- ? readonly TransactionFull<
114
- CryptoCurrencyPrice | undefined,
115
- true,
116
- true
117
- >[]
118
- : T extends GetAccountsTransactionFullsCustomParametersD
119
- ? readonly TransactionFull<undefined, true, false>[]
120
- : T extends GetAccountsTransactionFullsCustomParametersDA
121
- ? readonly TransactionFull<undefined, true, true>[]
122
- : never
@@ -1,80 +0,0 @@
1
- import type { Config } from '@0xtorch/core'
2
- import { toLowerHex } from '../types'
3
- import { getHashesAndInternalTxs } from './getHashesAndInternalTxs'
4
- import { getTransactionDetails } from './getTransactionDetails'
5
- import { getTransactionsApps } from './getTransactionsApps'
6
- import type {
7
- GetAccountsTransactionFullsCustomParametersD,
8
- GetAccountsTransactionFullsCustomReturnType,
9
- } from './types'
10
-
11
- export const getAccountsTransactionFullsCustomWithD = async (
12
- {
13
- chain,
14
- addresses,
15
- fromBlock,
16
- toBlock,
17
- appDataSource,
18
- decoder,
19
- onFetchHashes,
20
- onFetchTransaction,
21
- }: GetAccountsTransactionFullsCustomParametersD,
22
- config?: Config,
23
- ): Promise<
24
- GetAccountsTransactionFullsCustomReturnType<GetAccountsTransactionFullsCustomParametersD>
25
- > => {
26
- const timeoutTimestamp =
27
- Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
28
-
29
- // get transaction hash & internal transaction by explorer
30
- const { hashes, internalTransactions } = await getHashesAndInternalTxs(
31
- chain,
32
- addresses,
33
- fromBlock,
34
- toBlock,
35
- config,
36
- )
37
- if (hashes.length === 0) {
38
- return []
39
- }
40
- if (onFetchHashes !== undefined) {
41
- onFetchHashes(hashes.map((hash) => toLowerHex(hash)))
42
- }
43
-
44
- // get transaction detail of hashes
45
- const timeoutForGetTransactionDetail = timeoutTimestamp - Date.now()
46
- const transactionDetails = await getTransactionDetails(
47
- chain,
48
- hashes,
49
- internalTransactions,
50
- onFetchTransaction,
51
- {
52
- timeout: timeoutForGetTransactionDetail,
53
- logger: config?.logger,
54
- },
55
- )
56
-
57
- // decode
58
- const { transactions: transactionsDecoded } = await decoder.decode({
59
- chain,
60
- transactions: transactionDetails,
61
- })
62
-
63
- // get apps
64
- const apps = await getTransactionsApps(appDataSource, transactionDetails, {
65
- timeout: timeoutTimestamp - Date.now(),
66
- logger: config?.logger,
67
- })
68
-
69
- return transactionsDecoded.map((transaction) => {
70
- const lowerTo =
71
- transaction.to === null ? undefined : toLowerHex(transaction.to)
72
- const app = apps.find(({ address }) => address === lowerTo)?.app
73
-
74
- return {
75
- ...transaction,
76
- app,
77
- nativeTokenPrice: undefined,
78
- }
79
- })
80
- }
@@ -1,112 +0,0 @@
1
- /* eslint-disable unicorn/filename-case */
2
- import type { Config } from '@0xtorch/core'
3
- import { toLowerHex } from '../types'
4
- import { getHashesAndInternalTxs } from './getHashesAndInternalTxs'
5
- import { getTransactionDetails } from './getTransactionDetails'
6
- import { getTransactionsApps } from './getTransactionsApps'
7
- import type {
8
- GetAccountsTransactionFullsCustomParametersDA,
9
- GetAccountsTransactionFullsCustomReturnType,
10
- } from './types'
11
-
12
- export const getAccountsTransactionFullsCustomWithDA = async (
13
- {
14
- chain,
15
- addresses,
16
- fromBlock,
17
- toBlock,
18
- appDataSource,
19
- decoder,
20
- analyzer,
21
- onFetchHashes,
22
- onFetchTransaction,
23
- }: GetAccountsTransactionFullsCustomParametersDA,
24
- config?: Config,
25
- ): Promise<
26
- GetAccountsTransactionFullsCustomReturnType<GetAccountsTransactionFullsCustomParametersDA>
27
- > => {
28
- const timeoutTimestamp =
29
- Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
30
-
31
- // get transaction hash & internal transaction by explorer
32
- const { hashes, internalTransactions } = await getHashesAndInternalTxs(
33
- chain,
34
- addresses,
35
- fromBlock,
36
- toBlock,
37
- config,
38
- )
39
- if (hashes.length === 0) {
40
- return []
41
- }
42
- if (onFetchHashes !== undefined) {
43
- onFetchHashes(hashes.map((hash) => toLowerHex(hash)))
44
- }
45
-
46
- // get transaction detail of hashes
47
- const timeoutForGetTransactionDetail = timeoutTimestamp - Date.now()
48
- const transactionDetails = await getTransactionDetails(
49
- chain,
50
- hashes,
51
- internalTransactions,
52
- onFetchTransaction,
53
- {
54
- timeout: timeoutForGetTransactionDetail,
55
- logger: config?.logger,
56
- },
57
- )
58
-
59
- // decode
60
- const { transactions: transactionsDecoded } = await decoder.decode(
61
- {
62
- chain,
63
- transactions: transactionDetails,
64
- },
65
- {
66
- timeout: timeoutTimestamp - Date.now(),
67
- logger: config?.logger,
68
- },
69
- )
70
-
71
- // get apps
72
- const apps = await getTransactionsApps(appDataSource, transactionDetails, {
73
- timeout: timeoutTimestamp - Date.now(),
74
- logger: config?.logger,
75
- })
76
-
77
- const transactionsForAnalyzer = transactionsDecoded.map((transaction) => {
78
- const lowerTo =
79
- transaction.to === null ? undefined : toLowerHex(transaction.to)
80
- const app = apps.find(({ address }) => address === lowerTo)?.app
81
- return {
82
- ...transaction,
83
- app,
84
- nativeTokenPrice: undefined,
85
- }
86
- })
87
-
88
- // analyze
89
- const timeoutForAnalyze = timeoutTimestamp - Date.now()
90
- const analyzedDatas = await Promise.all(
91
- transactionsForAnalyzer.map((transactionForAnalyzer) =>
92
- analyzer.analyze(
93
- {
94
- chain,
95
- transaction: transactionForAnalyzer,
96
- accountAddresses: addresses,
97
- },
98
- {
99
- timeout: timeoutForAnalyze,
100
- logger: config?.logger,
101
- },
102
- ),
103
- ),
104
- )
105
-
106
- return transactionsForAnalyzer.map((transactionForAnalyzer, index) => ({
107
- ...transactionForAnalyzer,
108
- accountAddresses: addresses,
109
- actions: analyzedDatas[index].actions,
110
- accountActions: analyzedDatas[index].accountActions,
111
- }))
112
- }
@@ -1,120 +0,0 @@
1
- import type { Config, CryptoCurrencyPrice } from '@0xtorch/core'
2
- import { toLowerHex } from '../types'
3
- import { getHashesAndInternalTxs } from './getHashesAndInternalTxs'
4
- import { getTransactionDetails } from './getTransactionDetails'
5
- import { getTransactionsApps } from './getTransactionsApps'
6
- import type {
7
- GetAccountsTransactionFullsCustomParametersP,
8
- GetAccountsTransactionFullsCustomReturnType,
9
- } from './types'
10
-
11
- export const getAccountsTransactionFullsCustomWithP = async (
12
- {
13
- chain,
14
- addresses,
15
- fromBlock,
16
- toBlock,
17
- appDataSource,
18
- priceDataSource,
19
- fiat,
20
- onFetchHashes,
21
- onFetchTransaction,
22
- }: GetAccountsTransactionFullsCustomParametersP,
23
- config?: Config,
24
- ): Promise<
25
- GetAccountsTransactionFullsCustomReturnType<GetAccountsTransactionFullsCustomParametersP>
26
- > => {
27
- const timeoutTimestamp =
28
- Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
29
-
30
- // get transaction hash & internal transaction by explorer
31
- const { hashes, internalTransactions } = await getHashesAndInternalTxs(
32
- chain,
33
- addresses,
34
- fromBlock,
35
- toBlock,
36
- config,
37
- )
38
- if (hashes.length === 0) {
39
- return []
40
- }
41
- if (onFetchHashes !== undefined) {
42
- onFetchHashes(hashes.map((hash) => toLowerHex(hash)))
43
- }
44
-
45
- // get transaction detail of hashes
46
- const timeoutForGetTransactionDetail = timeoutTimestamp - Date.now()
47
- const transactionDetails = await getTransactionDetails(
48
- chain,
49
- hashes,
50
- internalTransactions,
51
- onFetchTransaction,
52
- {
53
- timeout: timeoutForGetTransactionDetail,
54
- logger: config?.logger,
55
- },
56
- )
57
-
58
- // native token price timestamp range
59
- const minTimestamp = transactionDetails.reduce(
60
- (minTimestamp, { block }) =>
61
- Math.min(minTimestamp, Number(block.timestamp)),
62
- Number.MAX_SAFE_INTEGER,
63
- )
64
- const maxTimestamp = transactionDetails.reduce(
65
- (maxTimestamp, { block }) =>
66
- Math.max(maxTimestamp, Number(block.timestamp)),
67
- 0,
68
- )
69
- const from = minTimestamp * 1000 - 1000 * 60 * 60
70
- const to = maxTimestamp * 1000 + 1000 * 60 * 60
71
-
72
- const timeoutForDataSource = timeoutTimestamp - Date.now()
73
- const [apps, prices] = await Promise.all([
74
- // get apps
75
- getTransactionsApps(appDataSource, transactionDetails, {
76
- timeout: timeoutForDataSource,
77
- logger: config?.logger,
78
- }),
79
- // get native token prices
80
- priceDataSource.getHistoricalPrices(
81
- {
82
- targetCurrencies: [chain.nativeToken.currency],
83
- vsCurrency: fiat,
84
- from,
85
- to,
86
- },
87
- {
88
- timeout: timeoutForDataSource,
89
- logger: config?.logger,
90
- },
91
- ),
92
- ])
93
-
94
- return transactionDetails.map((transactionDetail) => {
95
- const lowerTo =
96
- transactionDetail.to === null
97
- ? undefined
98
- : toLowerHex(transactionDetail.to)
99
- const app = apps.find(({ address }) => address === lowerTo)?.app
100
- const price = prices.reduce(
101
- (closestPrice: CryptoCurrencyPrice | undefined, price) =>
102
- closestPrice === undefined ||
103
- Math.abs(
104
- price.timestamp - Number(transactionDetail.block.timestamp) * 1000,
105
- ) <
106
- Math.abs(
107
- closestPrice.timestamp -
108
- Number(transactionDetail.block.timestamp) * 1000,
109
- )
110
- ? price
111
- : closestPrice,
112
- undefined,
113
- )
114
- return {
115
- ...transactionDetail,
116
- app,
117
- nativeTokenPrice: price,
118
- }
119
- })
120
- }
@@ -1,141 +0,0 @@
1
- /* eslint-disable unicorn/filename-case */
2
- import type { Config, CryptoCurrencyPrice } from '@0xtorch/core'
3
- import { toLowerHex } from '../types'
4
- import { getDecodedTransactionsPrices } from './getDecodedTransactionsPrices'
5
- import { getHashesAndInternalTxs } from './getHashesAndInternalTxs'
6
- import { getTransactionDetails } from './getTransactionDetails'
7
- import { getTransactionsApps } from './getTransactionsApps'
8
- import type {
9
- GetAccountsTransactionFullsCustomParametersPD,
10
- GetAccountsTransactionFullsCustomReturnType,
11
- } from './types'
12
-
13
- export const getAccountsTransactionFullsCustomWithPD = async (
14
- {
15
- chain,
16
- addresses,
17
- fromBlock,
18
- toBlock,
19
- appDataSource,
20
- priceDataSource,
21
- fiat,
22
- decoder,
23
- onFetchHashes,
24
- onFetchTransaction,
25
- }: GetAccountsTransactionFullsCustomParametersPD,
26
- config?: Config,
27
- ): Promise<
28
- GetAccountsTransactionFullsCustomReturnType<GetAccountsTransactionFullsCustomParametersPD>
29
- > => {
30
- const timeoutTimestamp =
31
- Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
32
-
33
- // get transaction hash & internal transaction by explorer
34
- const { hashes, internalTransactions } = await getHashesAndInternalTxs(
35
- chain,
36
- addresses,
37
- fromBlock,
38
- toBlock,
39
- config,
40
- )
41
- if (hashes.length === 0) {
42
- return []
43
- }
44
- if (onFetchHashes !== undefined) {
45
- onFetchHashes(hashes.map((hash) => toLowerHex(hash)))
46
- }
47
-
48
- // get transaction detail of hashes
49
- const timeoutForGetTransactionDetail = timeoutTimestamp - Date.now()
50
- const transactionDetails = await getTransactionDetails(
51
- chain,
52
- hashes,
53
- internalTransactions,
54
- onFetchTransaction,
55
- {
56
- timeout: timeoutForGetTransactionDetail,
57
- logger: config?.logger,
58
- },
59
- )
60
-
61
- // decode
62
- const { transactions: transactionsDecoded } = await decoder.decode(
63
- {
64
- chain,
65
- transactions: transactionDetails,
66
- },
67
- {
68
- timeout: timeoutTimestamp - Date.now(),
69
- logger: config?.logger,
70
- },
71
- )
72
-
73
- const timeoutForDataSources = timeoutTimestamp - Date.now()
74
- const [apps, prices] = await Promise.all([
75
- // get apps
76
- getTransactionsApps(appDataSource, transactionDetails, {
77
- timeout: timeoutForDataSources,
78
- logger: config?.logger,
79
- }),
80
- // get prices
81
- getDecodedTransactionsPrices(
82
- chain,
83
- priceDataSource,
84
- fiat,
85
- transactionsDecoded,
86
- {
87
- timeout: timeoutForDataSources,
88
- logger: config?.logger,
89
- },
90
- ),
91
- ])
92
-
93
- return transactionsDecoded.map((transaction) => {
94
- const lowerTo =
95
- transaction.to === null ? undefined : toLowerHex(transaction.to)
96
- const app = apps.find(({ address }) => address === lowerTo)?.app
97
-
98
- const timestampMs = Number(transaction.block.timestamp) * 1000
99
-
100
- const nativeTokenPrice = prices
101
- .filter(
102
- ({ cryptoCurrencyId }) =>
103
- cryptoCurrencyId === chain.nativeToken.currency.id,
104
- )
105
- .reduce((closestPrice, price) =>
106
- Math.abs(price.timestamp - timestampMs) <
107
- Math.abs(closestPrice.timestamp - timestampMs)
108
- ? price
109
- : closestPrice,
110
- )
111
-
112
- return {
113
- ...transaction,
114
- app,
115
- nativeTokenPrice,
116
- internalTransactions: transaction.internalTransactions.map(
117
- (internalTransaction) => ({
118
- ...internalTransaction,
119
- price: nativeTokenPrice,
120
- }),
121
- ),
122
- erc20Transfers: transaction.erc20Transfers.map((transfer) => ({
123
- ...transfer,
124
- price: prices
125
- .filter(
126
- ({ cryptoCurrencyId }) =>
127
- cryptoCurrencyId === transfer.token.currency.id,
128
- )
129
- .reduce(
130
- (closestPrice: CryptoCurrencyPrice | undefined, price) =>
131
- closestPrice === undefined ||
132
- Math.abs(price.timestamp - timestampMs) <
133
- Math.abs(closestPrice.timestamp - timestampMs)
134
- ? price
135
- : closestPrice,
136
- undefined,
137
- ),
138
- })),
139
- }
140
- })
141
- }