@ledgerhq/coin-evm 16.4.2 → 16.5.1
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/CHANGELOG.md +12 -0
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +4 -1
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/config.d.ts +9 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +4 -0
- package/lib/config.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +76 -7
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.d.ts +20 -0
- package/lib/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +57 -0
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +4 -1
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/config.d.ts +9 -0
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +77 -8
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.d.ts +20 -0
- package/lib-es/logic/internalTransactionsFetcher.d.ts.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +55 -0
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/etherscan.test.ts +16 -0
- package/src/adapters/etherscan.ts +4 -1
- package/src/config.ts +11 -0
- package/src/logic/getBlock.ts +117 -7
- package/src/logic/internalTransactionsFetcher.ts +72 -0
- package/src/logic/tests/getBlock.test.ts +418 -2
- package/src/logic/tests/internalTransactionsFetcher.test.ts +141 -1
|
@@ -7,5 +7,25 @@ export type InternalTxsByHash = Map<string, BlockOperation[]>;
|
|
|
7
7
|
export type SourceFetcher = (height: number) => Promise<InternalTxsByHash>;
|
|
8
8
|
export declare function composeInternalTxsFetcher(sources: readonly InternalTxSource[], fetchers: Record<InternalTxSource, SourceFetcher>): SourceFetcher;
|
|
9
9
|
export declare function makeSourceFetchers(config: EvmConfigInfo, nodeApi: NodeApi, logger: Logger): Record<InternalTxSource, SourceFetcher>;
|
|
10
|
+
/**
|
|
11
|
+
* Drops the internal native transfers between a fee collector contract (see
|
|
12
|
+
* `feeCollectorContracts`) and the fee payer of their transaction. They move the fee that the
|
|
13
|
+
* transaction `fees` already holds: keeping them would debit the fee payer twice. A transfer
|
|
14
|
+
* between a fee collector and another account is kept: `fees` does not hold it.
|
|
15
|
+
*
|
|
16
|
+
* @param feesPayers fee payer of each transaction, by hash
|
|
17
|
+
*/
|
|
18
|
+
export declare function dropFeeCollectorTransfers(internalTxs: InternalTxsByHash, feeCollectorContracts: readonly string[], feesPayers: ReadonlyMap<string, string | undefined>): InternalTxsByHash;
|
|
19
|
+
/**
|
|
20
|
+
* Finds the account that paid the fee of a transaction to a fee collector contract (see
|
|
21
|
+
* `feeCollectorContracts`), when it is not the sender: a zkSync paymaster prepays the fee to the
|
|
22
|
+
* bootloader for the sender, and gets the unused gas back.
|
|
23
|
+
*
|
|
24
|
+
* @param operations internal operations of the transaction
|
|
25
|
+
* @param sender sender of the transaction
|
|
26
|
+
* @returns the account that sent native coins to a fee collector, if it is a single account
|
|
27
|
+
* other than the sender
|
|
28
|
+
*/
|
|
29
|
+
export declare function findFeeCollectorPayer(operations: readonly BlockOperation[], feeCollectorContracts: readonly string[], sender: string | undefined): string | undefined;
|
|
10
30
|
export declare function createInternalTransactionsFetcher(config: EvmConfigInfo, nodeApi: NodeApi, sources: readonly InternalTxSource[], logger: Logger): SourceFetcher;
|
|
11
31
|
//# sourceMappingURL=internalTransactionsFetcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internalTransactionsFetcher.d.ts","sourceRoot":"","sources":["../../src/logic/internalTransactionsFetcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2CAA2C,CAAA;AAC/E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAA;AAWpE,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,CAAA;AAE7D,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAA;AA2F1E,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,QAAQ,EAAE,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,GAChD,aAAa,CAEf;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAwDzC;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,MAAM,EAAE,MAAM,GACb,aAAa,CAEf"}
|
|
1
|
+
{"version":3,"file":"internalTransactionsFetcher.d.ts","sourceRoot":"","sources":["../../src/logic/internalTransactionsFetcher.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uB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
|
129
|
+
/**
|
|
130
|
+
* Drops the internal native transfers between a fee collector contract (see
|
|
131
|
+
* `feeCollectorContracts`) and the fee payer of their transaction. They move the fee that the
|
|
132
|
+
* transaction `fees` already holds: keeping them would debit the fee payer twice. A transfer
|
|
133
|
+
* between a fee collector and another account is kept: `fees` does not hold it.
|
|
134
|
+
*
|
|
135
|
+
* @param feesPayers fee payer of each transaction, by hash
|
|
136
|
+
*/
|
|
137
|
+
export function dropFeeCollectorTransfers(internalTxs, feeCollectorContracts, feesPayers) {
|
|
138
|
+
const collectors = new Set(feeCollectorContracts.map((address) => address.toLowerCase()));
|
|
139
|
+
const isFeeTransfer = (operation, feesPayer) => {
|
|
140
|
+
if (operation.type !== 'transfer' || operation.asset.type !== 'native')
|
|
141
|
+
return false;
|
|
142
|
+
if (operation.peer === undefined)
|
|
143
|
+
return false;
|
|
144
|
+
const address = operation.address.toLowerCase();
|
|
145
|
+
const peer = operation.peer.toLowerCase();
|
|
146
|
+
return ((collectors.has(address) && peer === feesPayer) ||
|
|
147
|
+
(collectors.has(peer) && address === feesPayer));
|
|
148
|
+
};
|
|
149
|
+
return new Map([...internalTxs].map(([hash, operations]) => {
|
|
150
|
+
const feesPayer = feesPayers.get(hash)?.toLowerCase();
|
|
151
|
+
return [
|
|
152
|
+
hash,
|
|
153
|
+
feesPayer === undefined
|
|
154
|
+
? operations
|
|
155
|
+
: operations.filter((operation) => !isFeeTransfer(operation, feesPayer)),
|
|
156
|
+
];
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Finds the account that paid the fee of a transaction to a fee collector contract (see
|
|
161
|
+
* `feeCollectorContracts`), when it is not the sender: a zkSync paymaster prepays the fee to the
|
|
162
|
+
* bootloader for the sender, and gets the unused gas back.
|
|
163
|
+
*
|
|
164
|
+
* @param operations internal operations of the transaction
|
|
165
|
+
* @param sender sender of the transaction
|
|
166
|
+
* @returns the account that sent native coins to a fee collector, if it is a single account
|
|
167
|
+
* other than the sender
|
|
168
|
+
*/
|
|
169
|
+
export function findFeeCollectorPayer(operations, feeCollectorContracts, sender) {
|
|
170
|
+
const collectors = new Set(feeCollectorContracts.map((address) => address.toLowerCase()));
|
|
171
|
+
const payers = new Set(operations.flatMap((operation) => operation.type === 'transfer' &&
|
|
172
|
+
operation.asset.type === 'native' &&
|
|
173
|
+
operation.amount < 0n &&
|
|
174
|
+
operation.peer !== undefined &&
|
|
175
|
+
collectors.has(operation.peer.toLowerCase()) &&
|
|
176
|
+
!collectors.has(operation.address.toLowerCase())
|
|
177
|
+
? [operation.address.toLowerCase()]
|
|
178
|
+
: []));
|
|
179
|
+
if (payers.size !== 1 || (sender !== undefined && payers.has(sender.toLowerCase()))) {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
return [...payers][0];
|
|
183
|
+
}
|
|
129
184
|
export function createInternalTransactionsFetcher(config, nodeApi, sources, logger) {
|
|
130
185
|
return composeInternalTxsFetcher(sources, makeSourceFetchers(config, nodeApi, logger));
|
|
131
186
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internalTransactionsFetcher.js","sourceRoot":"","sources":["../../src/logic/internalTransactionsFetcher.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,sCAAsC;AAOtC,OAAO,EAAE,iCAAiC,EAAE,MAAM,6BAA6B,CAAA;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAA;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,8BAA8B,IAAI,0CAA0C,EAAE,MAAM,yBAAyB,CAAA;AACtH,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAA;AAC9E,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,2BAA2B,CAAA;AAQlC,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,MAA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EAAE,CAAC;QACpF,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,MAAqB,EACrB,OAAgB,EAChB,OAAoC,EACpC,MAAc;IAEd,OAAO,yBAAyB,CAAC,OAAO,EAAE,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAA;AACxF,CAAC"}
|
package/package.json
CHANGED
|
@@ -2134,6 +2134,22 @@ describe('EVM Family', () => {
|
|
|
2134
2134
|
expect(byHash.size).toBe(0)
|
|
2135
2135
|
})
|
|
2136
2136
|
|
|
2137
|
+
it.each(['0x', '0x0'])(
|
|
2138
|
+
'leaves the credit of an internal tx from placeholder sender %s with no peer',
|
|
2139
|
+
(from) => {
|
|
2140
|
+
const internalTxs = [{ ...baseInternalTx, hash: '0xtx1', from, value: '1000' }]
|
|
2141
|
+
const ops = internalTxsToOperationsByHash(internalTxs, testLogger).get('0xtx1')!
|
|
2142
|
+
expect(ops).toEqual([
|
|
2143
|
+
{
|
|
2144
|
+
type: 'transfer',
|
|
2145
|
+
address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619',
|
|
2146
|
+
asset: { type: 'native' },
|
|
2147
|
+
amount: 1000n,
|
|
2148
|
+
},
|
|
2149
|
+
])
|
|
2150
|
+
}
|
|
2151
|
+
)
|
|
2152
|
+
|
|
2137
2153
|
it('returns empty map for empty internal txs array', () => {
|
|
2138
2154
|
const byHash = internalTxsToOperationsByHash([], testLogger)
|
|
2139
2155
|
expect(byHash.size).toBe(0)
|
|
@@ -421,10 +421,13 @@ export function internalTxsToOperationsByHash(
|
|
|
421
421
|
asset: NATIVE_ASSET,
|
|
422
422
|
amount: -amount,
|
|
423
423
|
}
|
|
424
|
+
// Built on its own, not from `fromOp`: a placeholder sender ('0x', '0x0') encodes to '' and
|
|
425
|
+
// must leave the credit with no peer, not with the recipient inherited from `fromOp`.
|
|
424
426
|
const toOp: TransferBlockOperation = {
|
|
425
|
-
|
|
427
|
+
type: 'transfer',
|
|
426
428
|
address: encodedTo,
|
|
427
429
|
...(encodedFrom ? { peer: encodedFrom } : {}),
|
|
430
|
+
asset: NATIVE_ASSET,
|
|
428
431
|
amount: amount,
|
|
429
432
|
}
|
|
430
433
|
if (encodedFrom) {
|
package/src/config.ts
CHANGED
|
@@ -125,6 +125,13 @@ export type EvmConfig = {
|
|
|
125
125
|
* Addresses are matched case-insensitively.
|
|
126
126
|
*/
|
|
127
127
|
nativeContracts?: string[]
|
|
128
|
+
/**
|
|
129
|
+
* System contracts that collect the transaction fee (e.g. the zkSync bootloader, which takes
|
|
130
|
+
* the fee prepayment and refunds the unused gas). An internal native transfer to or from one of
|
|
131
|
+
* them moves the fee that the transaction `fees` already holds, so `getBlock` drops it.
|
|
132
|
+
* Addresses are matched case-insensitively.
|
|
133
|
+
*/
|
|
134
|
+
feeCollectorContracts?: string[]
|
|
128
135
|
/**
|
|
129
136
|
* Minimum effective price per gas (in wei, decimal string) accepted by this chain's
|
|
130
137
|
* mempool. Applied as a floor to both the legacy `gasPrice` and the EIP-1559
|
|
@@ -955,6 +962,8 @@ export const evmDefaults = {
|
|
|
955
962
|
unit: { name: 'ETH', code: 'ETH', magnitude: 18 },
|
|
956
963
|
node: { type: 'external', uri: 'https://zksync.coin.ledger.com' },
|
|
957
964
|
explorer: { type: 'blockscout', uri: 'https://proxyblockscout.api.live.ledger.com/324/api' },
|
|
965
|
+
// bootloader
|
|
966
|
+
feeCollectorContracts: ['0x0000000000000000000000000000000000008001'],
|
|
958
967
|
},
|
|
959
968
|
zksync_sepolia: {
|
|
960
969
|
status: {
|
|
@@ -966,6 +975,8 @@ export const evmDefaults = {
|
|
|
966
975
|
unit: { name: 'ETH', code: 'ETH', magnitude: 18 },
|
|
967
976
|
node: { type: 'external', uri: 'https://zksync-sepolia.coin.ledger.com' },
|
|
968
977
|
explorer: { type: 'blockscout', uri: 'https://zksync-sepolia.blockscout.com/api' },
|
|
978
|
+
// bootloader
|
|
979
|
+
feeCollectorContracts: ['0x0000000000000000000000000000000000008001'],
|
|
969
980
|
},
|
|
970
981
|
monad: {
|
|
971
982
|
status: {
|
package/src/logic/getBlock.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { ChainId, EvmContext } from '../config'
|
|
5
5
|
import type { BlockReceiptInfo, PrefetchedBlockTransaction } from '../network/node/types'
|
|
6
|
+
import type { EvmStakingOperationType } from '../types/staking'
|
|
6
7
|
import type { InternalTxsByHash } from './internalTransactionsFetcher'
|
|
7
8
|
import type {
|
|
8
9
|
Block,
|
|
@@ -18,7 +19,12 @@ import { CHAIN_ID, DEFAULT_INTERNAL_TX_SOURCES } from '../config'
|
|
|
18
19
|
import { UnsupportedRpcMethodError } from '../errors'
|
|
19
20
|
import { buildSmartContractDetails, safeEncodeEIP55 } from '../logic-public'
|
|
20
21
|
import { getNodeApi } from '../network/node'
|
|
21
|
-
import {
|
|
22
|
+
import { detectEvmStakingOperationType } from '../staking/detectOperationType'
|
|
23
|
+
import {
|
|
24
|
+
createInternalTransactionsFetcher,
|
|
25
|
+
dropFeeCollectorTransfers,
|
|
26
|
+
findFeeCollectorPayer,
|
|
27
|
+
} from './internalTransactionsFetcher'
|
|
22
28
|
import { dropRootTraceDuplicates } from './rootTraceDedup'
|
|
23
29
|
|
|
24
30
|
export async function getBlock(context: EvmContext, height: number): Promise<Block> {
|
|
@@ -89,7 +95,14 @@ export async function getBlock(context: EvmContext, height: number): Promise<Blo
|
|
|
89
95
|
const transactions = transactionsResult.value
|
|
90
96
|
const internalTxs = internalTxsResult.value
|
|
91
97
|
|
|
92
|
-
const mergedTransactions = mergeInternalTransactions(
|
|
98
|
+
const mergedTransactions = mergeInternalTransactions(
|
|
99
|
+
...attributeFeeCollectorTransfers(
|
|
100
|
+
transactions,
|
|
101
|
+
internalTxs,
|
|
102
|
+
config.feeCollectorContracts ?? [],
|
|
103
|
+
context.logger
|
|
104
|
+
)
|
|
105
|
+
)
|
|
93
106
|
|
|
94
107
|
return {
|
|
95
108
|
info,
|
|
@@ -101,6 +114,37 @@ function describeReason(reason: unknown): string {
|
|
|
101
114
|
return reason instanceof Error ? reason.message : String(reason)
|
|
102
115
|
}
|
|
103
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Gives each transaction the account that paid its fee to the network's `feeCollectorContracts`
|
|
119
|
+
* (see {@link findFeeCollectorPayer}), then drops the internal native transfers between the fee
|
|
120
|
+
* collectors and that payer (see `dropFeeCollectorTransfers`): the transaction `fees` already holds
|
|
121
|
+
* them. On zkSync, a paymaster prepays the fee to the bootloader for the sender, so the paymaster,
|
|
122
|
+
* not the sender, pays the fee.
|
|
123
|
+
*/
|
|
124
|
+
function attributeFeeCollectorTransfers(
|
|
125
|
+
transactions: BlockTransaction[],
|
|
126
|
+
internalTxs: InternalTxsByHash,
|
|
127
|
+
feeCollectorContracts: readonly string[],
|
|
128
|
+
logger: Logger
|
|
129
|
+
): [BlockTransaction[], InternalTxsByHash] {
|
|
130
|
+
if (feeCollectorContracts.length === 0) return [transactions, internalTxs]
|
|
131
|
+
|
|
132
|
+
const paidTransactions = transactions.map((tx) => {
|
|
133
|
+
const payer = findFeeCollectorPayer(
|
|
134
|
+
internalTxs.get(tx.hash) ?? [],
|
|
135
|
+
feeCollectorContracts,
|
|
136
|
+
tx.feesPayer
|
|
137
|
+
)
|
|
138
|
+
return payer === undefined ? tx : { ...tx, feesPayer: safeEncodeEIP55(payer, logger) }
|
|
139
|
+
})
|
|
140
|
+
const feesPayers = new Map(paidTransactions.map((tx) => [tx.hash, tx.feesPayer]))
|
|
141
|
+
|
|
142
|
+
return [
|
|
143
|
+
paidTransactions,
|
|
144
|
+
dropFeeCollectorTransfers(internalTxs, feeCollectorContracts, feesPayers),
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
|
|
104
148
|
/**
|
|
105
149
|
* Merges internal transaction operations into block transactions by matching tx hash.
|
|
106
150
|
*
|
|
@@ -109,11 +153,13 @@ function describeReason(reason: unknown): string {
|
|
|
109
153
|
* is dropped, because it represents the same value transfer reported twice. ERC20/721/1155
|
|
110
154
|
* ops come from receipt logs, so they are never touched here.
|
|
111
155
|
*
|
|
112
|
-
* This complements the semantic filters applied upstream
|
|
156
|
+
* This complements the semantic filters applied upstream:
|
|
113
157
|
* - `traceBlockItemsToOperationsByHash` skips items with `traceAddress.length === 0` and
|
|
114
158
|
* items whose `callType` is `delegatecall`/`staticcall`/`callcode`.
|
|
115
159
|
* - `internalTxsToOperationsByHash` skips items whose `callType` (Blockscout) or `type`
|
|
116
160
|
* (Etherscan) matches the same non-value-transferring call types.
|
|
161
|
+
* - `attributeFeeCollectorTransfers` drops the native transfers between the network's
|
|
162
|
+
* `feeCollectorContracts` and the transaction fee payer, whatever the source.
|
|
117
163
|
*
|
|
118
164
|
* The structural dedup here is the last line of defence: if a provider surfaces the root call
|
|
119
165
|
* in a shape the adapter didn't anticipate (e.g. a future explorer variant), it still gets
|
|
@@ -130,13 +176,55 @@ function mergeInternalTransactions(
|
|
|
130
176
|
if (!extraOps || extraOps.length === 0) return tx
|
|
131
177
|
const dedupedExtraOps = dropRootTraceDuplicates(tx.operations, extraOps)
|
|
132
178
|
if (dedupedExtraOps.length === 0) return tx
|
|
179
|
+
const internalTransfers = toInternalTransfers(dedupedExtraOps)
|
|
133
180
|
return {
|
|
134
181
|
...tx,
|
|
135
182
|
operations: [...tx.operations, ...dedupedExtraOps],
|
|
183
|
+
...(internalTransfers.length > 0 ? { details: { ...tx.details, internalTransfers } } : {}),
|
|
136
184
|
}
|
|
137
185
|
})
|
|
138
186
|
}
|
|
139
187
|
|
|
188
|
+
/**
|
|
189
|
+
* An internal transfer appended to the operations of a block transaction, as listed in the
|
|
190
|
+
* `internalTransfers` detail. `value` is in wei, as a decimal string.
|
|
191
|
+
*/
|
|
192
|
+
type InternalTransferDetail = {
|
|
193
|
+
from?: string
|
|
194
|
+
to?: string
|
|
195
|
+
value: string
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Describes the internal transfers that {@link mergeInternalTransactions} appends to a block
|
|
200
|
+
* transaction, so that consumers can tell them apart from the top-level transfers.
|
|
201
|
+
*
|
|
202
|
+
* The adapters turn each internal transfer into a debit op (`address = from`, `peer = to`,
|
|
203
|
+
* negative amount) followed by a credit op (`address = to`, `peer = from`, positive amount),
|
|
204
|
+
* leaving out the side whose address is unknown. The root-trace dedup drops both ops of a pair
|
|
205
|
+
* or none. So a debit op stands for one transfer, and a credit op stands for one only when it
|
|
206
|
+
* has no peer (no debit op was emitted for it).
|
|
207
|
+
*/
|
|
208
|
+
function toInternalTransfers(internalOps: readonly BlockOperation[]): InternalTransferDetail[] {
|
|
209
|
+
const transfers: InternalTransferDetail[] = []
|
|
210
|
+
for (const op of internalOps) {
|
|
211
|
+
if (op.type !== 'transfer' || op.asset.type !== 'native') continue
|
|
212
|
+
if (op.amount < 0n) {
|
|
213
|
+
transfers.push({
|
|
214
|
+
from: op.address,
|
|
215
|
+
...(op.peer !== undefined ? { to: op.peer } : {}),
|
|
216
|
+
value: (-op.amount).toString(),
|
|
217
|
+
})
|
|
218
|
+
} else if (op.peer === undefined) {
|
|
219
|
+
transfers.push({
|
|
220
|
+
to: op.address,
|
|
221
|
+
value: op.amount.toString(),
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return transfers
|
|
226
|
+
}
|
|
227
|
+
|
|
140
228
|
async function getTransactionsFromNode(
|
|
141
229
|
chainId: ChainId,
|
|
142
230
|
chainName: string,
|
|
@@ -194,7 +282,7 @@ async function getTransactionsFromPrefetchedData(
|
|
|
194
282
|
for (const tx of prefetchedTransactions) {
|
|
195
283
|
const receipt = receiptsByHash.get(tx.hash)
|
|
196
284
|
if (!receipt) return null
|
|
197
|
-
const blockTx = prefetchedTransactionToBlockTransaction(tx, receipt, logger)
|
|
285
|
+
const blockTx = prefetchedTransactionToBlockTransaction(chainId, tx, receipt, logger)
|
|
198
286
|
transactions.push({
|
|
199
287
|
...blockTx,
|
|
200
288
|
operations: applyChainSpecificCorrections(
|
|
@@ -221,6 +309,7 @@ async function getTransactionsFromPrefetchedData(
|
|
|
221
309
|
}
|
|
222
310
|
|
|
223
311
|
function prefetchedTransactionToBlockTransaction(
|
|
312
|
+
chainId: ChainId,
|
|
224
313
|
tx: PrefetchedBlockTransaction,
|
|
225
314
|
receipt: BlockReceiptInfo,
|
|
226
315
|
logger: Logger
|
|
@@ -246,7 +335,8 @@ function prefetchedTransactionToBlockTransaction(
|
|
|
246
335
|
gasPrice,
|
|
247
336
|
tx.gasLimit,
|
|
248
337
|
tx.nonce,
|
|
249
|
-
buildSmartContractDetails(tx.to, tx.input, logger, receipt.contractAddress)
|
|
338
|
+
buildSmartContractDetails(tx.to, tx.input, logger, receipt.contractAddress),
|
|
339
|
+
detectStakingOperationType(chainId, tx.to, tx.input)
|
|
250
340
|
)
|
|
251
341
|
|
|
252
342
|
return {
|
|
@@ -278,7 +368,8 @@ async function getTransactionFromHash(
|
|
|
278
368
|
BigInt(txInfo.gasPrice),
|
|
279
369
|
txInfo.gasLimit,
|
|
280
370
|
txInfo.nonce,
|
|
281
|
-
buildSmartContractDetails(txInfo.to, txInfo.input, logger, txInfo.contractAddress)
|
|
371
|
+
buildSmartContractDetails(txInfo.to, txInfo.input, logger, txInfo.contractAddress),
|
|
372
|
+
detectStakingOperationType(chainId, txInfo.to, txInfo.input)
|
|
282
373
|
)
|
|
283
374
|
|
|
284
375
|
return {
|
|
@@ -299,21 +390,40 @@ async function getTransactionFromHash(
|
|
|
299
390
|
* @param gasLimit gas limit set by the sender (decimal), when known
|
|
300
391
|
* @param nonce nonce of the transaction, when known
|
|
301
392
|
* @param smartContractDetails details of the contract interaction or deployment, if any
|
|
393
|
+
* @param stakingOperationType staking operation type of the transaction, if it is a staking call
|
|
302
394
|
*/
|
|
303
395
|
function buildTransactionDetails(
|
|
304
396
|
gasPrice: bigint,
|
|
305
397
|
gasLimit: string | undefined,
|
|
306
398
|
nonce: number | undefined,
|
|
307
|
-
smartContractDetails: Record<string, unknown> | undefined
|
|
399
|
+
smartContractDetails: Record<string, unknown> | undefined,
|
|
400
|
+
stakingOperationType: EvmStakingOperationType | undefined
|
|
308
401
|
): Record<string, unknown> {
|
|
309
402
|
return {
|
|
310
403
|
gasPrice: gasPrice.toString(),
|
|
311
404
|
...(gasLimit !== undefined ? { gasLimit } : {}),
|
|
312
405
|
...(nonce !== undefined ? { sequence: nonce } : {}),
|
|
313
406
|
...(smartContractDetails ?? {}),
|
|
407
|
+
...(stakingOperationType !== undefined ? { ledgerOpType: stakingOperationType } : {}),
|
|
314
408
|
}
|
|
315
409
|
}
|
|
316
410
|
|
|
411
|
+
/**
|
|
412
|
+
* Detects a staking call (delegate, undelegate, redelegate, withdraw, reward) from the
|
|
413
|
+
* recipient and the function selector of the transaction, like {@link listOperations} does.
|
|
414
|
+
*
|
|
415
|
+
* @param chainId chain of the transaction
|
|
416
|
+
* @param to recipient of the transaction, undefined on a contract deployment
|
|
417
|
+
* @param input call data of the transaction, if any
|
|
418
|
+
*/
|
|
419
|
+
function detectStakingOperationType(
|
|
420
|
+
chainId: ChainId,
|
|
421
|
+
to: string | undefined,
|
|
422
|
+
input: string | undefined
|
|
423
|
+
): EvmStakingOperationType | undefined {
|
|
424
|
+
return detectEvmStakingOperationType(chainId, to, input?.slice(0, 10))
|
|
425
|
+
}
|
|
426
|
+
|
|
317
427
|
function applyChainSpecificCorrections(
|
|
318
428
|
chainId: ChainId,
|
|
319
429
|
operations: BlockOperation[],
|
|
@@ -178,6 +178,78 @@ export function makeSourceFetchers(
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Drops the internal native transfers between a fee collector contract (see
|
|
183
|
+
* `feeCollectorContracts`) and the fee payer of their transaction. They move the fee that the
|
|
184
|
+
* transaction `fees` already holds: keeping them would debit the fee payer twice. A transfer
|
|
185
|
+
* between a fee collector and another account is kept: `fees` does not hold it.
|
|
186
|
+
*
|
|
187
|
+
* @param feesPayers fee payer of each transaction, by hash
|
|
188
|
+
*/
|
|
189
|
+
export function dropFeeCollectorTransfers(
|
|
190
|
+
internalTxs: InternalTxsByHash,
|
|
191
|
+
feeCollectorContracts: readonly string[],
|
|
192
|
+
feesPayers: ReadonlyMap<string, string | undefined>
|
|
193
|
+
): InternalTxsByHash {
|
|
194
|
+
const collectors = new Set(feeCollectorContracts.map((address) => address.toLowerCase()))
|
|
195
|
+
const isFeeTransfer = (operation: BlockOperation, feesPayer: string): boolean => {
|
|
196
|
+
if (operation.type !== 'transfer' || operation.asset.type !== 'native') return false
|
|
197
|
+
if (operation.peer === undefined) return false
|
|
198
|
+
const address = operation.address.toLowerCase()
|
|
199
|
+
const peer = operation.peer.toLowerCase()
|
|
200
|
+
return (
|
|
201
|
+
(collectors.has(address) && peer === feesPayer) ||
|
|
202
|
+
(collectors.has(peer) && address === feesPayer)
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return new Map(
|
|
207
|
+
[...internalTxs].map(([hash, operations]) => {
|
|
208
|
+
const feesPayer = feesPayers.get(hash)?.toLowerCase()
|
|
209
|
+
return [
|
|
210
|
+
hash,
|
|
211
|
+
feesPayer === undefined
|
|
212
|
+
? operations
|
|
213
|
+
: operations.filter((operation) => !isFeeTransfer(operation, feesPayer)),
|
|
214
|
+
]
|
|
215
|
+
})
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Finds the account that paid the fee of a transaction to a fee collector contract (see
|
|
221
|
+
* `feeCollectorContracts`), when it is not the sender: a zkSync paymaster prepays the fee to the
|
|
222
|
+
* bootloader for the sender, and gets the unused gas back.
|
|
223
|
+
*
|
|
224
|
+
* @param operations internal operations of the transaction
|
|
225
|
+
* @param sender sender of the transaction
|
|
226
|
+
* @returns the account that sent native coins to a fee collector, if it is a single account
|
|
227
|
+
* other than the sender
|
|
228
|
+
*/
|
|
229
|
+
export function findFeeCollectorPayer(
|
|
230
|
+
operations: readonly BlockOperation[],
|
|
231
|
+
feeCollectorContracts: readonly string[],
|
|
232
|
+
sender: string | undefined
|
|
233
|
+
): string | undefined {
|
|
234
|
+
const collectors = new Set(feeCollectorContracts.map((address) => address.toLowerCase()))
|
|
235
|
+
const payers = new Set(
|
|
236
|
+
operations.flatMap((operation) =>
|
|
237
|
+
operation.type === 'transfer' &&
|
|
238
|
+
operation.asset.type === 'native' &&
|
|
239
|
+
operation.amount < 0n &&
|
|
240
|
+
operation.peer !== undefined &&
|
|
241
|
+
collectors.has(operation.peer.toLowerCase()) &&
|
|
242
|
+
!collectors.has(operation.address.toLowerCase())
|
|
243
|
+
? [operation.address.toLowerCase()]
|
|
244
|
+
: []
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
if (payers.size !== 1 || (sender !== undefined && payers.has(sender.toLowerCase()))) {
|
|
248
|
+
return undefined
|
|
249
|
+
}
|
|
250
|
+
return [...payers][0]
|
|
251
|
+
}
|
|
252
|
+
|
|
181
253
|
export function createInternalTransactionsFetcher(
|
|
182
254
|
config: EvmConfigInfo,
|
|
183
255
|
nodeApi: NodeApi,
|