@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.
- package/_cjs/analyzer/json/components/targetAsset.js +3 -1
- package/_cjs/analyzer/json/components/targetAsset.js.map +1 -1
- package/_cjs/analyzer/json/schemas/generator.js +1 -0
- package/_cjs/analyzer/json/schemas/generator.js.map +1 -1
- package/_cjs/decoder/decode.js +1 -1
- package/_cjs/decoder/decode.js.map +1 -1
- package/_cjs/decoder/parseErc1155TransferSingleLogs.js +1 -1
- package/_cjs/decoder/parseErc1155TransferSingleLogs.js.map +1 -1
- package/_cjs/decoder/parseErc721TransferLogs.js +1 -1
- package/_cjs/decoder/parseErc721TransferLogs.js.map +1 -1
- package/_cjs/index.js +5 -2
- package/_cjs/index.js.map +1 -1
- package/_cjs/utils/create.js +9 -3
- package/_cjs/utils/create.js.map +1 -1
- package/_cjs/utils/index.js +5 -2
- package/_cjs/utils/index.js.map +1 -1
- package/_esm/analyzer/json/components/targetAsset.js +4 -2
- package/_esm/analyzer/json/components/targetAsset.js.map +1 -1
- package/_esm/analyzer/json/schemas/generator.js +1 -0
- package/_esm/analyzer/json/schemas/generator.js.map +1 -1
- package/_esm/decoder/decode.js +2 -2
- package/_esm/decoder/decode.js.map +1 -1
- package/_esm/decoder/parseErc1155TransferSingleLogs.js +2 -2
- package/_esm/decoder/parseErc1155TransferSingleLogs.js.map +1 -1
- package/_esm/decoder/parseErc721TransferLogs.js +2 -2
- package/_esm/decoder/parseErc721TransferLogs.js.map +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/utils/create.js +4 -1
- package/_esm/utils/create.js.map +1 -1
- package/_esm/utils/index.js +1 -1
- package/_esm/utils/index.js.map +1 -1
- package/_types/analyzer/json/components/targetAsset.d.ts.map +1 -1
- package/_types/analyzer/json/schemas/generator.d.ts +3 -0
- package/_types/analyzer/json/schemas/generator.d.ts.map +1 -1
- package/_types/index.d.ts +2 -2
- package/_types/index.d.ts.map +1 -1
- package/_types/types/erc1155.d.ts +1 -0
- package/_types/types/erc1155.d.ts.map +1 -1
- package/_types/types/erc721.d.ts +1 -0
- package/_types/types/erc721.d.ts.map +1 -1
- package/_types/types/index.d.ts +2 -2
- package/_types/types/index.d.ts.map +1 -1
- package/_types/utils/create.d.ts +10 -3
- package/_types/utils/create.d.ts.map +1 -1
- package/_types/utils/index.d.ts +1 -1
- package/_types/utils/index.d.ts.map +1 -1
- package/analyzer/json/components/targetAsset.ts +5 -2
- package/analyzer/json/schemas/generator.ts +1 -0
- package/decoder/decode.ts +3 -2
- package/decoder/parseErc1155TransferSingleLogs.ts +2 -2
- package/decoder/parseErc721TransferLogs.ts +2 -2
- package/index.ts +6 -9
- package/package.json +2 -2
- package/types/erc1155.ts +2 -0
- package/types/erc721.ts +2 -0
- package/types/index.ts +2 -2
- package/utils/create.ts +19 -4
- package/utils/index.ts +4 -1
- package/getAccountsTransactionFulls/getAccountsTransactionFulls.ts +0 -46
- package/getAccountsTransactionFulls/getAccountsTransactionFullsCustom.ts +0 -106
- package/getAccountsTransactionFulls/getDecodedTransactionsPrices.ts +0 -97
- package/getAccountsTransactionFulls/getHashesAndInternalTxs.ts +0 -65
- package/getAccountsTransactionFulls/getTransactionDetails.ts +0 -41
- package/getAccountsTransactionFulls/getTransactionsApps.ts +0 -42
- package/getAccountsTransactionFulls/index.ts +0 -2
- package/getAccountsTransactionFulls/types.ts +0 -122
- package/getAccountsTransactionFulls/withD.ts +0 -80
- package/getAccountsTransactionFulls/withDA.ts +0 -112
- package/getAccountsTransactionFulls/withP.ts +0 -120
- package/getAccountsTransactionFulls/withPD.ts +0 -141
- package/getAccountsTransactionFulls/withPDA.ts +0 -167
- package/getAccountsTransactionFulls/withUndefined.ts +0 -88
- package/getTransactionFull/getTransactionFull.ts +0 -30
- package/getTransactionFull/getTransactionFullCustom.ts +0 -91
- package/getTransactionFull/index.ts +0 -2
- package/getTransactionFull/types.ts +0 -98
- package/getTransactionFull/withD.ts +0 -57
- package/getTransactionFull/withDA.ts +0 -78
- package/getTransactionFull/withP.ts +0 -69
- package/getTransactionFull/withPD.ts +0 -119
- package/getTransactionFull/withPDA.ts +0 -147
- package/getTransactionFull/withUndefined.ts +0 -39
|
@@ -1,167 +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
|
-
GetAccountsTransactionFullsCustomParametersPDA,
|
|
10
|
-
GetAccountsTransactionFullsCustomReturnType,
|
|
11
|
-
} from './types'
|
|
12
|
-
|
|
13
|
-
export const getAccountsTransactionFullsCustomWithPDA = async (
|
|
14
|
-
{
|
|
15
|
-
chain,
|
|
16
|
-
addresses,
|
|
17
|
-
fromBlock,
|
|
18
|
-
toBlock,
|
|
19
|
-
appDataSource,
|
|
20
|
-
priceDataSource,
|
|
21
|
-
fiat,
|
|
22
|
-
decoder,
|
|
23
|
-
analyzer,
|
|
24
|
-
onFetchHashes,
|
|
25
|
-
onFetchTransaction,
|
|
26
|
-
}: GetAccountsTransactionFullsCustomParametersPDA,
|
|
27
|
-
config?: Config,
|
|
28
|
-
): Promise<
|
|
29
|
-
GetAccountsTransactionFullsCustomReturnType<GetAccountsTransactionFullsCustomParametersPDA>
|
|
30
|
-
> => {
|
|
31
|
-
const timeoutTimestamp =
|
|
32
|
-
Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
|
|
33
|
-
|
|
34
|
-
// get transaction hash & internal transaction by explorer
|
|
35
|
-
const { hashes, internalTransactions } = await getHashesAndInternalTxs(
|
|
36
|
-
chain,
|
|
37
|
-
addresses,
|
|
38
|
-
fromBlock,
|
|
39
|
-
toBlock,
|
|
40
|
-
config,
|
|
41
|
-
)
|
|
42
|
-
if (hashes.length === 0) {
|
|
43
|
-
return []
|
|
44
|
-
}
|
|
45
|
-
if (onFetchHashes !== undefined) {
|
|
46
|
-
onFetchHashes(hashes.map((hash) => toLowerHex(hash)))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// get transaction detail of hashes
|
|
50
|
-
const timeoutForGetTransactionDetail = timeoutTimestamp - Date.now()
|
|
51
|
-
const transactionDetails = await getTransactionDetails(
|
|
52
|
-
chain,
|
|
53
|
-
hashes,
|
|
54
|
-
internalTransactions,
|
|
55
|
-
onFetchTransaction,
|
|
56
|
-
{
|
|
57
|
-
timeout: timeoutForGetTransactionDetail,
|
|
58
|
-
logger: config?.logger,
|
|
59
|
-
},
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
// decode
|
|
63
|
-
const { transactions: transactionsDecoded } = await decoder.decode(
|
|
64
|
-
{
|
|
65
|
-
chain,
|
|
66
|
-
transactions: transactionDetails,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
timeout: timeoutTimestamp - Date.now(),
|
|
70
|
-
logger: config?.logger,
|
|
71
|
-
},
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
const timeoutForDataSources = timeoutTimestamp - Date.now()
|
|
75
|
-
const [apps, prices] = await Promise.all([
|
|
76
|
-
// get apps
|
|
77
|
-
getTransactionsApps(appDataSource, transactionDetails, {
|
|
78
|
-
timeout: timeoutForDataSources,
|
|
79
|
-
logger: config?.logger,
|
|
80
|
-
}),
|
|
81
|
-
// get prices
|
|
82
|
-
getDecodedTransactionsPrices(
|
|
83
|
-
chain,
|
|
84
|
-
priceDataSource,
|
|
85
|
-
fiat,
|
|
86
|
-
transactionsDecoded,
|
|
87
|
-
{
|
|
88
|
-
timeout: timeoutForDataSources,
|
|
89
|
-
logger: config?.logger,
|
|
90
|
-
},
|
|
91
|
-
),
|
|
92
|
-
])
|
|
93
|
-
|
|
94
|
-
const transactionsForAnalyzer = transactionsDecoded.map((transaction) => {
|
|
95
|
-
const lowerTo =
|
|
96
|
-
transaction.to === null ? undefined : toLowerHex(transaction.to)
|
|
97
|
-
const app = apps.find(({ address }) => address === lowerTo)?.app
|
|
98
|
-
const timestampMs = Number(transaction.block.timestamp) * 1000
|
|
99
|
-
const nativeTokenPrice = prices
|
|
100
|
-
.filter(
|
|
101
|
-
({ cryptoCurrencyId }) =>
|
|
102
|
-
cryptoCurrencyId === chain.nativeToken.currency.id,
|
|
103
|
-
)
|
|
104
|
-
.reduce(
|
|
105
|
-
(closestPrice: CryptoCurrencyPrice | undefined, price) =>
|
|
106
|
-
closestPrice === undefined ||
|
|
107
|
-
Math.abs(price.timestamp - timestampMs) <
|
|
108
|
-
Math.abs(closestPrice.timestamp - timestampMs)
|
|
109
|
-
? price
|
|
110
|
-
: closestPrice,
|
|
111
|
-
undefined,
|
|
112
|
-
)
|
|
113
|
-
return {
|
|
114
|
-
...transaction,
|
|
115
|
-
app,
|
|
116
|
-
nativeTokenPrice,
|
|
117
|
-
internalTransactions: transaction.internalTransactions.map(
|
|
118
|
-
(internalTransaction) => ({
|
|
119
|
-
...internalTransaction,
|
|
120
|
-
price: nativeTokenPrice,
|
|
121
|
-
}),
|
|
122
|
-
),
|
|
123
|
-
erc20Transfers: transaction.erc20Transfers.map((transfer) => ({
|
|
124
|
-
...transfer,
|
|
125
|
-
price: prices
|
|
126
|
-
.filter(
|
|
127
|
-
({ cryptoCurrencyId }) =>
|
|
128
|
-
cryptoCurrencyId === transfer.token.currency.id,
|
|
129
|
-
)
|
|
130
|
-
.reduce(
|
|
131
|
-
(closestPrice: CryptoCurrencyPrice | undefined, price) =>
|
|
132
|
-
closestPrice === undefined ||
|
|
133
|
-
Math.abs(price.timestamp - timestampMs) <
|
|
134
|
-
Math.abs(closestPrice.timestamp - timestampMs)
|
|
135
|
-
? price
|
|
136
|
-
: closestPrice,
|
|
137
|
-
undefined,
|
|
138
|
-
),
|
|
139
|
-
})),
|
|
140
|
-
}
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
// analyze
|
|
144
|
-
const timeoutForAnalyzer = timeoutTimestamp - Date.now()
|
|
145
|
-
const analyzedDatas = await Promise.all(
|
|
146
|
-
transactionsForAnalyzer.map((transactionForAnalyzer) =>
|
|
147
|
-
analyzer.analyze(
|
|
148
|
-
{
|
|
149
|
-
chain,
|
|
150
|
-
transaction: transactionForAnalyzer,
|
|
151
|
-
accountAddresses: addresses,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
timeout: timeoutForAnalyzer,
|
|
155
|
-
logger: config?.logger,
|
|
156
|
-
},
|
|
157
|
-
),
|
|
158
|
-
),
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
return transactionsForAnalyzer.map((transactionForAnalyzer, index) => ({
|
|
162
|
-
...transactionForAnalyzer,
|
|
163
|
-
accountAddresses: addresses,
|
|
164
|
-
actions: analyzedDatas[index].actions,
|
|
165
|
-
accountActions: analyzedDatas[index].accountActions,
|
|
166
|
-
}))
|
|
167
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { Config } from '@0xtorch/core'
|
|
2
|
-
import type { LowerHex } from '../types'
|
|
3
|
-
import { toLowerHex } from '../types'
|
|
4
|
-
import { getHashesAndInternalTxs } from './getHashesAndInternalTxs'
|
|
5
|
-
import { getTransactionDetails } from './getTransactionDetails'
|
|
6
|
-
import type {
|
|
7
|
-
GetAccountsTransactionFullsCustomParametersAllUndefined,
|
|
8
|
-
GetAccountsTransactionFullsCustomReturnType,
|
|
9
|
-
} from './types'
|
|
10
|
-
|
|
11
|
-
export const getAccountsTransactionFullsCustomWithAllUndefined = async (
|
|
12
|
-
{
|
|
13
|
-
chain,
|
|
14
|
-
addresses,
|
|
15
|
-
fromBlock,
|
|
16
|
-
toBlock,
|
|
17
|
-
appDataSource,
|
|
18
|
-
onFetchHashes,
|
|
19
|
-
onFetchTransaction,
|
|
20
|
-
}: GetAccountsTransactionFullsCustomParametersAllUndefined,
|
|
21
|
-
config?: Config,
|
|
22
|
-
): Promise<
|
|
23
|
-
GetAccountsTransactionFullsCustomReturnType<GetAccountsTransactionFullsCustomParametersAllUndefined>
|
|
24
|
-
> => {
|
|
25
|
-
const timeoutTimestamp =
|
|
26
|
-
Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
|
|
27
|
-
|
|
28
|
-
// get transaction hash & internal transaction by explorer
|
|
29
|
-
const { hashes, internalTransactions } = await getHashesAndInternalTxs(
|
|
30
|
-
chain,
|
|
31
|
-
addresses,
|
|
32
|
-
fromBlock,
|
|
33
|
-
toBlock,
|
|
34
|
-
config,
|
|
35
|
-
)
|
|
36
|
-
if (hashes.length === 0) {
|
|
37
|
-
return []
|
|
38
|
-
}
|
|
39
|
-
if (onFetchHashes !== undefined) {
|
|
40
|
-
onFetchHashes(hashes.map((hash) => toLowerHex(hash)))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// get transaction detail of hashes
|
|
44
|
-
const timeoutForGetTransactionDetail = timeoutTimestamp - Date.now()
|
|
45
|
-
const transactionDetails = await getTransactionDetails(
|
|
46
|
-
chain,
|
|
47
|
-
hashes,
|
|
48
|
-
internalTransactions,
|
|
49
|
-
onFetchTransaction,
|
|
50
|
-
{
|
|
51
|
-
timeout: timeoutForGetTransactionDetail,
|
|
52
|
-
logger: config?.logger,
|
|
53
|
-
},
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
// get app of to address
|
|
57
|
-
const toAddresses = [
|
|
58
|
-
...new Set(
|
|
59
|
-
transactionDetails
|
|
60
|
-
.map(({ to }) => (to === null ? undefined : toLowerHex(to)))
|
|
61
|
-
.filter((toAddress): toAddress is LowerHex => toAddress !== undefined),
|
|
62
|
-
),
|
|
63
|
-
]
|
|
64
|
-
const timeoutForGetApps = timeoutTimestamp - Date.now()
|
|
65
|
-
const apps = await Promise.all(
|
|
66
|
-
toAddresses.map((toAddress) =>
|
|
67
|
-
appDataSource === undefined
|
|
68
|
-
? undefined
|
|
69
|
-
: appDataSource.getApp(chain.id, toAddress, {
|
|
70
|
-
timeout: timeoutForGetApps,
|
|
71
|
-
logger: config?.logger,
|
|
72
|
-
}),
|
|
73
|
-
),
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
return transactionDetails.map((transactionDetail) => {
|
|
77
|
-
const appIndex =
|
|
78
|
-
transactionDetail.to === null
|
|
79
|
-
? -1
|
|
80
|
-
: toAddresses.indexOf(toLowerHex(transactionDetail.to))
|
|
81
|
-
const app = appIndex < 0 ? undefined : apps[appIndex]
|
|
82
|
-
return {
|
|
83
|
-
...transactionDetail,
|
|
84
|
-
app,
|
|
85
|
-
nativeTokenPrice: undefined,
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Config, FiatCurrency } from '@0xtorch/core'
|
|
2
|
-
import { coingeckoCryptoCurrencyDataSource, usd } from '@0xtorch/core'
|
|
3
|
-
import { analyzer } from '../analyzer'
|
|
4
|
-
import type { Chain } from '../chains'
|
|
5
|
-
import { decoder } from '../decoder'
|
|
6
|
-
import type { Hex } from '../types'
|
|
7
|
-
import { getTransactionFullCustom } from './getTransactionFullCustom'
|
|
8
|
-
|
|
9
|
-
type GetTransactionFullParameters = {
|
|
10
|
-
readonly chain: Chain
|
|
11
|
-
readonly hash: Hex
|
|
12
|
-
readonly fiat?: FiatCurrency
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const getTransactionFull = async (
|
|
16
|
-
{ chain, hash, fiat = usd }: GetTransactionFullParameters,
|
|
17
|
-
config?: Config,
|
|
18
|
-
) =>
|
|
19
|
-
await getTransactionFullCustom(
|
|
20
|
-
{
|
|
21
|
-
chain,
|
|
22
|
-
hash,
|
|
23
|
-
appDataSource: undefined,
|
|
24
|
-
priceDataSource: coingeckoCryptoCurrencyDataSource,
|
|
25
|
-
fiat,
|
|
26
|
-
decoder,
|
|
27
|
-
analyzer,
|
|
28
|
-
},
|
|
29
|
-
config,
|
|
30
|
-
)
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { Config } from '@0xtorch/core'
|
|
2
|
-
import type {
|
|
3
|
-
GetTransactionFullCustomParameters,
|
|
4
|
-
GetTransactionFullCustomParametersAllUndefined,
|
|
5
|
-
GetTransactionFullCustomParametersD,
|
|
6
|
-
GetTransactionFullCustomParametersDA,
|
|
7
|
-
GetTransactionFullCustomParametersP,
|
|
8
|
-
GetTransactionFullCustomParametersPD,
|
|
9
|
-
GetTransactionFullCustomParametersPDA,
|
|
10
|
-
GetTransactionFullCustomReturnType,
|
|
11
|
-
} from './types'
|
|
12
|
-
import { getTransactionFullCustomWithD } from './withD'
|
|
13
|
-
import { getTransactionFullCustomWithDA } from './withDA'
|
|
14
|
-
import { getTransactionFullCustomWithP } from './withP'
|
|
15
|
-
import { getTransactionFullCustomWithPD } from './withPD'
|
|
16
|
-
import { getTransactionFullCustomWithPDA } from './withPDA'
|
|
17
|
-
import { getTransactionFullCustomWithAllUndefined } from './withUndefined'
|
|
18
|
-
|
|
19
|
-
export const getTransactionFullCustom = async <
|
|
20
|
-
T extends GetTransactionFullCustomParameters,
|
|
21
|
-
>(
|
|
22
|
-
parameters: T,
|
|
23
|
-
config?: Config,
|
|
24
|
-
): Promise<GetTransactionFullCustomReturnType<T>> => {
|
|
25
|
-
if (isParametersAllUndefined(parameters)) {
|
|
26
|
-
const data = await getTransactionFullCustomWithAllUndefined(
|
|
27
|
-
parameters,
|
|
28
|
-
config,
|
|
29
|
-
)
|
|
30
|
-
return data as GetTransactionFullCustomReturnType<T>
|
|
31
|
-
}
|
|
32
|
-
if (isParametersP(parameters)) {
|
|
33
|
-
const data = await getTransactionFullCustomWithP(parameters, config)
|
|
34
|
-
return data as GetTransactionFullCustomReturnType<T>
|
|
35
|
-
}
|
|
36
|
-
if (isParametersPD(parameters)) {
|
|
37
|
-
const data = await getTransactionFullCustomWithPD(parameters, config)
|
|
38
|
-
return data as GetTransactionFullCustomReturnType<T>
|
|
39
|
-
}
|
|
40
|
-
if (isParametersPDA(parameters)) {
|
|
41
|
-
const data = await getTransactionFullCustomWithPDA(parameters, config)
|
|
42
|
-
return data as GetTransactionFullCustomReturnType<T>
|
|
43
|
-
}
|
|
44
|
-
if (isParametersD(parameters)) {
|
|
45
|
-
const data = await getTransactionFullCustomWithD(parameters, config)
|
|
46
|
-
return data as GetTransactionFullCustomReturnType<T>
|
|
47
|
-
}
|
|
48
|
-
if (isParametersDA(parameters)) {
|
|
49
|
-
const data = await getTransactionFullCustomWithDA(parameters, config)
|
|
50
|
-
return data as GetTransactionFullCustomReturnType<T>
|
|
51
|
-
}
|
|
52
|
-
throw new Error('not implemented')
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const isParametersAllUndefined = (
|
|
56
|
-
parameters: GetTransactionFullCustomParameters,
|
|
57
|
-
): parameters is GetTransactionFullCustomParametersAllUndefined =>
|
|
58
|
-
parameters.priceDataSource === undefined && parameters.decoder === undefined
|
|
59
|
-
|
|
60
|
-
const isParametersP = (
|
|
61
|
-
parameters: GetTransactionFullCustomParameters,
|
|
62
|
-
): parameters is GetTransactionFullCustomParametersP =>
|
|
63
|
-
parameters.priceDataSource !== undefined && parameters.decoder === undefined
|
|
64
|
-
|
|
65
|
-
const isParametersPD = (
|
|
66
|
-
parameters: GetTransactionFullCustomParameters,
|
|
67
|
-
): parameters is GetTransactionFullCustomParametersPD =>
|
|
68
|
-
parameters.priceDataSource !== undefined &&
|
|
69
|
-
parameters.decoder !== undefined &&
|
|
70
|
-
parameters.analyzer === undefined
|
|
71
|
-
|
|
72
|
-
const isParametersPDA = (
|
|
73
|
-
parameters: GetTransactionFullCustomParameters,
|
|
74
|
-
): parameters is GetTransactionFullCustomParametersPDA =>
|
|
75
|
-
parameters.priceDataSource !== undefined &&
|
|
76
|
-
parameters.decoder !== undefined &&
|
|
77
|
-
parameters.analyzer !== undefined
|
|
78
|
-
|
|
79
|
-
const isParametersD = (
|
|
80
|
-
parameters: GetTransactionFullCustomParameters,
|
|
81
|
-
): parameters is GetTransactionFullCustomParametersD =>
|
|
82
|
-
parameters.priceDataSource === undefined &&
|
|
83
|
-
parameters.decoder !== undefined &&
|
|
84
|
-
parameters.analyzer === undefined
|
|
85
|
-
|
|
86
|
-
const isParametersDA = (
|
|
87
|
-
parameters: GetTransactionFullCustomParameters,
|
|
88
|
-
): parameters is GetTransactionFullCustomParametersDA =>
|
|
89
|
-
parameters.priceDataSource === undefined &&
|
|
90
|
-
parameters.decoder !== undefined &&
|
|
91
|
-
parameters.analyzer !== undefined
|
|
@@ -1,98 +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 { Hex, TransactionFull } from '../types'
|
|
11
|
-
|
|
12
|
-
export type GetTransactionFullCustomParameters =
|
|
13
|
-
| GetTransactionFullCustomParametersAllUndefined
|
|
14
|
-
| GetTransactionFullCustomParametersP
|
|
15
|
-
| GetTransactionFullCustomParametersPD
|
|
16
|
-
| GetTransactionFullCustomParametersPDA
|
|
17
|
-
| GetTransactionFullCustomParametersD
|
|
18
|
-
| GetTransactionFullCustomParametersDA
|
|
19
|
-
|
|
20
|
-
export type GetTransactionFullCustomParametersAllUndefined = {
|
|
21
|
-
readonly chain: Chain
|
|
22
|
-
readonly hash: Hex
|
|
23
|
-
readonly appDataSource: AppDataSource | undefined
|
|
24
|
-
readonly priceDataSource: undefined
|
|
25
|
-
readonly fiat: undefined
|
|
26
|
-
readonly decoder: undefined
|
|
27
|
-
readonly analyzer: undefined
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type GetTransactionFullCustomParametersP = {
|
|
31
|
-
readonly chain: Chain
|
|
32
|
-
readonly hash: Hex
|
|
33
|
-
readonly appDataSource: AppDataSource | undefined
|
|
34
|
-
readonly priceDataSource: CryptoCurrencyDataSource
|
|
35
|
-
readonly fiat: FiatCurrency
|
|
36
|
-
readonly decoder: undefined
|
|
37
|
-
readonly analyzer: undefined
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type GetTransactionFullCustomParametersPD = {
|
|
41
|
-
readonly chain: Chain
|
|
42
|
-
readonly hash: Hex
|
|
43
|
-
readonly appDataSource: AppDataSource | undefined
|
|
44
|
-
readonly priceDataSource: CryptoCurrencyDataSource
|
|
45
|
-
readonly fiat: FiatCurrency
|
|
46
|
-
readonly decoder: Decoder
|
|
47
|
-
readonly analyzer: undefined
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type GetTransactionFullCustomParametersPDA = {
|
|
51
|
-
readonly chain: Chain
|
|
52
|
-
readonly hash: Hex
|
|
53
|
-
readonly appDataSource: AppDataSource | undefined
|
|
54
|
-
readonly priceDataSource: CryptoCurrencyDataSource
|
|
55
|
-
readonly fiat: FiatCurrency
|
|
56
|
-
readonly decoder: Decoder
|
|
57
|
-
readonly analyzer: Analyzer<CryptoCurrencyPrice | undefined>
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export type GetTransactionFullCustomParametersD = {
|
|
61
|
-
readonly chain: Chain
|
|
62
|
-
readonly hash: Hex
|
|
63
|
-
readonly appDataSource: AppDataSource | undefined
|
|
64
|
-
readonly priceDataSource: undefined
|
|
65
|
-
readonly fiat: undefined
|
|
66
|
-
readonly decoder: Decoder
|
|
67
|
-
readonly analyzer: undefined
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type GetTransactionFullCustomParametersDA = {
|
|
71
|
-
readonly chain: Chain
|
|
72
|
-
readonly hash: Hex
|
|
73
|
-
readonly appDataSource: AppDataSource | undefined
|
|
74
|
-
readonly priceDataSource: undefined
|
|
75
|
-
readonly fiat: undefined
|
|
76
|
-
readonly decoder: Decoder
|
|
77
|
-
readonly analyzer: Analyzer<undefined>
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export type GetTransactionFullCustomReturnType<
|
|
81
|
-
T extends GetTransactionFullCustomParameters,
|
|
82
|
-
> = T extends GetTransactionFullCustomParametersAllUndefined
|
|
83
|
-
? TransactionFull<undefined, false, false> | undefined
|
|
84
|
-
: T extends GetTransactionFullCustomParametersP
|
|
85
|
-
? TransactionFull<CryptoCurrencyPrice | undefined, false, false> | undefined
|
|
86
|
-
: T extends GetTransactionFullCustomParametersPD
|
|
87
|
-
?
|
|
88
|
-
| TransactionFull<CryptoCurrencyPrice | undefined, true, false>
|
|
89
|
-
| undefined
|
|
90
|
-
: T extends GetTransactionFullCustomParametersPDA
|
|
91
|
-
?
|
|
92
|
-
| TransactionFull<CryptoCurrencyPrice | undefined, true, true>
|
|
93
|
-
| undefined
|
|
94
|
-
: T extends GetTransactionFullCustomParametersD
|
|
95
|
-
? TransactionFull<undefined, true, false> | undefined
|
|
96
|
-
: T extends GetTransactionFullCustomParametersDA
|
|
97
|
-
? TransactionFull<undefined, true, true> | undefined
|
|
98
|
-
: never
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { Config } from '@0xtorch/core'
|
|
2
|
-
import { getTransactionDetail } from '../getTransactionDetail'
|
|
3
|
-
import { toLowerHex } from '../types'
|
|
4
|
-
import type {
|
|
5
|
-
GetTransactionFullCustomParametersD,
|
|
6
|
-
GetTransactionFullCustomReturnType,
|
|
7
|
-
} from './types'
|
|
8
|
-
|
|
9
|
-
export const getTransactionFullCustomWithD = async (
|
|
10
|
-
parameters: GetTransactionFullCustomParametersD,
|
|
11
|
-
config?: Config,
|
|
12
|
-
): Promise<
|
|
13
|
-
GetTransactionFullCustomReturnType<GetTransactionFullCustomParametersD>
|
|
14
|
-
> => {
|
|
15
|
-
const timeoutTimestamp =
|
|
16
|
-
Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
|
|
17
|
-
|
|
18
|
-
const { chain, hash, appDataSource, decoder } = parameters
|
|
19
|
-
|
|
20
|
-
// get transaction detail
|
|
21
|
-
const transactionDetail = await getTransactionDetail({ chain, hash }, config)
|
|
22
|
-
if (transactionDetail === undefined) {
|
|
23
|
-
return undefined
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// decode
|
|
27
|
-
const decodedData = await decoder.decode(
|
|
28
|
-
{
|
|
29
|
-
chain,
|
|
30
|
-
transactions: [transactionDetail],
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
timeout: timeoutTimestamp - Date.now(),
|
|
34
|
-
logger: config?.logger,
|
|
35
|
-
},
|
|
36
|
-
)
|
|
37
|
-
const transactionDecoded = decodedData.transactions[0]
|
|
38
|
-
|
|
39
|
-
// get app from data source
|
|
40
|
-
const app =
|
|
41
|
-
appDataSource === undefined || transactionDecoded.to === null
|
|
42
|
-
? undefined
|
|
43
|
-
: await appDataSource.getApp(
|
|
44
|
-
chain.id,
|
|
45
|
-
toLowerHex(transactionDecoded.to),
|
|
46
|
-
{
|
|
47
|
-
timeout: timeoutTimestamp - Date.now(),
|
|
48
|
-
logger: config?.logger,
|
|
49
|
-
},
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
...transactionDecoded,
|
|
54
|
-
app,
|
|
55
|
-
nativeTokenPrice: undefined,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/filename-case */
|
|
2
|
-
import type { Config } from '@0xtorch/core'
|
|
3
|
-
import { getTransactionDetail } from '../getTransactionDetail'
|
|
4
|
-
import { toLowerHex } from '../types'
|
|
5
|
-
import type {
|
|
6
|
-
GetTransactionFullCustomParametersDA,
|
|
7
|
-
GetTransactionFullCustomReturnType,
|
|
8
|
-
} from './types'
|
|
9
|
-
|
|
10
|
-
export const getTransactionFullCustomWithDA = async (
|
|
11
|
-
parameters: GetTransactionFullCustomParametersDA,
|
|
12
|
-
config?: Config,
|
|
13
|
-
): Promise<
|
|
14
|
-
GetTransactionFullCustomReturnType<GetTransactionFullCustomParametersDA>
|
|
15
|
-
> => {
|
|
16
|
-
const timeoutTimestamp =
|
|
17
|
-
Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
|
|
18
|
-
|
|
19
|
-
const { chain, hash, appDataSource, decoder, analyzer } = parameters
|
|
20
|
-
|
|
21
|
-
// get transaction detail
|
|
22
|
-
const transactionDetail = await getTransactionDetail({ chain, hash }, config)
|
|
23
|
-
if (transactionDetail === undefined) {
|
|
24
|
-
return undefined
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// decode
|
|
28
|
-
const decodedData = await decoder.decode(
|
|
29
|
-
{
|
|
30
|
-
chain,
|
|
31
|
-
transactions: [transactionDetail],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
timeout: timeoutTimestamp - Date.now(),
|
|
35
|
-
logger: config?.logger,
|
|
36
|
-
},
|
|
37
|
-
)
|
|
38
|
-
const transactionDecoded = decodedData.transactions[0]
|
|
39
|
-
|
|
40
|
-
// get app from data sourc
|
|
41
|
-
const app =
|
|
42
|
-
appDataSource === undefined || transactionDecoded.to === null
|
|
43
|
-
? undefined
|
|
44
|
-
: await appDataSource.getApp(
|
|
45
|
-
chain.id,
|
|
46
|
-
toLowerHex(transactionDecoded.to),
|
|
47
|
-
{
|
|
48
|
-
timeout: timeoutTimestamp - Date.now(),
|
|
49
|
-
logger: config?.logger,
|
|
50
|
-
},
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
const transactionForAnalyzer = {
|
|
54
|
-
...transactionDecoded,
|
|
55
|
-
app,
|
|
56
|
-
nativeTokenPrice: undefined,
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// analyze
|
|
60
|
-
const { actions, accountActions } = await analyzer.analyze(
|
|
61
|
-
{
|
|
62
|
-
chain,
|
|
63
|
-
transaction: transactionForAnalyzer,
|
|
64
|
-
accountAddresses: [],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
timeout: timeoutTimestamp - Date.now(),
|
|
68
|
-
logger: config?.logger,
|
|
69
|
-
},
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
...transactionForAnalyzer,
|
|
74
|
-
accountAddresses: [],
|
|
75
|
-
actions,
|
|
76
|
-
accountActions,
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { Config, CryptoCurrencyPrice } from '@0xtorch/core'
|
|
2
|
-
import { getTransactionDetail } from '../getTransactionDetail'
|
|
3
|
-
import { toLowerHex } from '../types'
|
|
4
|
-
import type {
|
|
5
|
-
GetTransactionFullCustomParametersP,
|
|
6
|
-
GetTransactionFullCustomReturnType,
|
|
7
|
-
} from './types'
|
|
8
|
-
|
|
9
|
-
export const getTransactionFullCustomWithP = async (
|
|
10
|
-
parameters: GetTransactionFullCustomParametersP,
|
|
11
|
-
config?: Config,
|
|
12
|
-
): Promise<
|
|
13
|
-
GetTransactionFullCustomReturnType<GetTransactionFullCustomParametersP>
|
|
14
|
-
> => {
|
|
15
|
-
const timeoutTimestamp =
|
|
16
|
-
Date.now() + (config?.timeout === undefined ? 60_000 : config.timeout)
|
|
17
|
-
|
|
18
|
-
const { chain, hash, appDataSource, priceDataSource, fiat } = parameters
|
|
19
|
-
|
|
20
|
-
// get transaction detail
|
|
21
|
-
const transactionDetail = await getTransactionDetail({ chain, hash }, config)
|
|
22
|
-
if (transactionDetail === undefined) {
|
|
23
|
-
return undefined
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const timestampMs = Number(transactionDetail.block.timestamp) * 1000
|
|
27
|
-
const from = timestampMs - 1000 * 60 * 60
|
|
28
|
-
const to = timestampMs + 1000 * 60 * 60
|
|
29
|
-
|
|
30
|
-
const timeoutForDataSources = timeoutTimestamp - Date.now()
|
|
31
|
-
const [app, prices] = await Promise.all([
|
|
32
|
-
// get app
|
|
33
|
-
appDataSource === undefined || transactionDetail.to === null
|
|
34
|
-
? undefined
|
|
35
|
-
: appDataSource.getApp(chain.id, toLowerHex(transactionDetail.to), {
|
|
36
|
-
timeout: timeoutForDataSources,
|
|
37
|
-
logger: config?.logger,
|
|
38
|
-
}),
|
|
39
|
-
// get native token prices
|
|
40
|
-
priceDataSource.getHistoricalPrices(
|
|
41
|
-
{
|
|
42
|
-
targetCurrencies: [chain.nativeToken.currency],
|
|
43
|
-
vsCurrency: fiat,
|
|
44
|
-
from,
|
|
45
|
-
to,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
timeout: timeoutForDataSources,
|
|
49
|
-
logger: config?.logger,
|
|
50
|
-
},
|
|
51
|
-
),
|
|
52
|
-
])
|
|
53
|
-
|
|
54
|
-
const closestPrice = prices.reduce(
|
|
55
|
-
(closestPrice: CryptoCurrencyPrice | undefined, price) =>
|
|
56
|
-
closestPrice === undefined ||
|
|
57
|
-
Math.abs(price.timestamp - timestampMs) <
|
|
58
|
-
Math.abs(closestPrice.timestamp - timestampMs)
|
|
59
|
-
? price
|
|
60
|
-
: closestPrice,
|
|
61
|
-
undefined,
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
...transactionDetail,
|
|
66
|
-
app,
|
|
67
|
-
nativeTokenPrice: closestPrice,
|
|
68
|
-
}
|
|
69
|
-
}
|