@ledgerhq/coin-evm 17.0.0 → 17.1.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/logic/cip64Fees.d.ts +40 -9
- package/lib/logic/cip64Fees.d.ts.map +1 -1
- package/lib/logic/cip64Fees.js +86 -34
- package/lib/logic/cip64Fees.js.map +1 -1
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +48 -22
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +21 -3
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/tokenFeeOperations.d.ts +61 -0
- package/lib/logic/tokenFeeOperations.d.ts.map +1 -0
- package/lib/logic/tokenFeeOperations.js +128 -0
- package/lib/logic/tokenFeeOperations.js.map +1 -0
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +18 -0
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +2 -0
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js.map +1 -1
- package/lib/network/node/withNodeSources.d.ts.map +1 -1
- package/lib/network/node/withNodeSources.js +2 -0
- package/lib/network/node/withNodeSources.js.map +1 -1
- package/lib-es/logic/cip64Fees.d.ts +40 -9
- package/lib-es/logic/cip64Fees.d.ts.map +1 -1
- package/lib-es/logic/cip64Fees.js +85 -34
- package/lib-es/logic/cip64Fees.js.map +1 -1
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +48 -22
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +21 -3
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/tokenFeeOperations.d.ts +61 -0
- package/lib-es/logic/tokenFeeOperations.d.ts.map +1 -0
- package/lib-es/logic/tokenFeeOperations.js +122 -0
- package/lib-es/logic/tokenFeeOperations.js.map +1 -0
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +18 -0
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +2 -0
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/network/node/types.js.map +1 -1
- package/lib-es/network/node/withNodeSources.d.ts.map +1 -1
- package/lib-es/network/node/withNodeSources.js +2 -0
- package/lib-es/network/node/withNodeSources.js.map +1 -1
- package/package.json +1 -1
- package/src/api/tests/index.celo.integ.test.ts +143 -0
- package/src/logic/cip64Fees.ts +123 -38
- package/src/logic/getBlock.ts +74 -34
- package/src/logic/listOperations.ts +32 -2
- package/src/logic/tests/cip64Fees.test.ts +149 -14
- package/src/logic/tests/getBlock.test.ts +45 -5
- package/src/logic/tests/listOperations.test.ts +469 -1
- package/src/logic/tokenFeeOperations.ts +169 -0
- package/src/network/node/rpc.common.ts +19 -0
- package/src/network/node/types.ts +2 -0
- package/src/network/node/withNodeSources.ts +3 -0
- package/src/network/tests/node/rpc.test.ts +36 -0
- package/src/network/tests/node/withNodeSources.test.ts +17 -0
|
@@ -993,6 +993,24 @@ async function getFeeCurrencies(
|
|
|
993
993
|
return feeCurrencies
|
|
994
994
|
}
|
|
995
995
|
|
|
996
|
+
async function getFeeCurrency(api: JsonRpcProvider, txHash: string): Promise<string | null> {
|
|
997
|
+
const rawTx: unknown = await api.send('eth_getTransactionByHash', [txHash])
|
|
998
|
+
if (rawTx === null || rawTx === undefined) {
|
|
999
|
+
throw new NodeTransactionNotFound('Transaction not found', { txHash })
|
|
1000
|
+
}
|
|
1001
|
+
if (!isRecord(rawTx) || typeof rawTx.hash !== 'string')
|
|
1002
|
+
throw new MalformedNodeResponse('Invalid eth_getTransactionByHash response')
|
|
1003
|
+
if (rawTx.hash.toLowerCase() !== txHash.toLowerCase())
|
|
1004
|
+
throw new MalformedNodeResponse('eth_getTransactionByHash returned another transaction', {
|
|
1005
|
+
txHash,
|
|
1006
|
+
})
|
|
1007
|
+
// op-geth omits `feeCurrency` when the fee is paid in the native coin
|
|
1008
|
+
const feeCurrency = rawTx.feeCurrency ?? null
|
|
1009
|
+
if (feeCurrency !== null && typeof feeCurrency !== 'string')
|
|
1010
|
+
throw new MalformedNodeResponse('Malformed feeCurrency in eth_getTransactionByHash response')
|
|
1011
|
+
return feeCurrency
|
|
1012
|
+
}
|
|
1013
|
+
|
|
996
1014
|
async function traceBlockGeth(
|
|
997
1015
|
api: JsonRpcProvider,
|
|
998
1016
|
blockHeight: number
|
|
@@ -1210,6 +1228,7 @@ export function createNodeApi(
|
|
|
1210
1228
|
getBlockReceipts: (blockHeight) =>
|
|
1211
1229
|
withApi(evmConfig, (api) => getBlockReceipts(api, blockHeight, logger), nodeConfig),
|
|
1212
1230
|
getFeeCurrencies: make(getFeeCurrencies, evmConfig, nodeConfig),
|
|
1231
|
+
getFeeCurrency: make(getFeeCurrency, evmConfig, nodeConfig),
|
|
1213
1232
|
traceBlockErigon: make(traceBlockErigon, evmConfig, nodeConfig),
|
|
1214
1233
|
traceBlockGeth: make(traceBlockGeth, evmConfig, nodeConfig),
|
|
1215
1234
|
getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig, logger),
|
|
@@ -189,6 +189,8 @@ export type NodeApi = {
|
|
|
189
189
|
* Ethers drops the field, so this reads the raw block.
|
|
190
190
|
*/
|
|
191
191
|
getFeeCurrencies?: (blockHeight: number) => Promise<Map<string, string | null>>
|
|
192
|
+
/** The Celo CIP-64 `feeCurrency` of one transaction, as {@link getFeeCurrencies} gives it. */
|
|
193
|
+
getFeeCurrency?: (txHash: string) => Promise<string | null>
|
|
192
194
|
traceBlockErigon?: (blockHeight: number | 'latest') => Promise<TraceBlockItem[]>
|
|
193
195
|
traceBlockGeth?: (blockHeight: number) => Promise<TraceBlockItem[]>
|
|
194
196
|
getOptimismAdditionalFees: (transaction: string) => Promise<BigNumber>
|
|
@@ -59,6 +59,9 @@ export function createFailoverNodeApi(sources: NodeApi[], logger: Logger): NodeA
|
|
|
59
59
|
if (sources.some((api) => api.getFeeCurrencies))
|
|
60
60
|
base.getFeeCurrencies = (h): Promise<Map<string, string | null>> =>
|
|
61
61
|
tryInOrder('getFeeCurrencies', (api) => api.getFeeCurrencies?.(h))
|
|
62
|
+
if (sources.some((api) => api.getFeeCurrency))
|
|
63
|
+
base.getFeeCurrency = (h): Promise<string | null> =>
|
|
64
|
+
tryInOrder('getFeeCurrency', (api) => api.getFeeCurrency?.(h))
|
|
62
65
|
if (sources.some((api) => api.traceBlockErigon))
|
|
63
66
|
base.traceBlockErigon = (h): Promise<TraceBlockItem[]> =>
|
|
64
67
|
tryInOrder('traceBlockErigon', (api) => api.traceBlockErigon?.(h))
|
|
@@ -1941,6 +1941,42 @@ describe('EVM Family', () => {
|
|
|
1941
1941
|
})
|
|
1942
1942
|
})
|
|
1943
1943
|
|
|
1944
|
+
describe('getFeeCurrency', () => {
|
|
1945
|
+
it.each([
|
|
1946
|
+
['a fee currency', '0x0e2a3e05bc9a16f5292a6170456a710cb89c6f72'],
|
|
1947
|
+
['an omitted fee currency as native', undefined],
|
|
1948
|
+
['a null fee currency as native', null],
|
|
1949
|
+
])('reads %s from the raw transaction', async (_, feeCurrency) => {
|
|
1950
|
+
const send = mockRawRpc({
|
|
1951
|
+
eth_getTransactionByHash: { hash: '0xaa', type: '0x7b', feeCurrency },
|
|
1952
|
+
})
|
|
1953
|
+
|
|
1954
|
+
expect(await nodeApi.getFeeCurrency!('0xAA')).toBe(feeCurrency ?? null)
|
|
1955
|
+
expect(send).toHaveBeenCalledWith('eth_getTransactionByHash', ['0xAA'])
|
|
1956
|
+
})
|
|
1957
|
+
|
|
1958
|
+
it('rejects an unknown transaction', async () => {
|
|
1959
|
+
mockRawRpc({ eth_getTransactionByHash: null })
|
|
1960
|
+
|
|
1961
|
+
await expect(nodeApi.getFeeCurrency!('0xaa')).rejects.toMatchObject({
|
|
1962
|
+
name: 'NodeTransactionNotFound',
|
|
1963
|
+
})
|
|
1964
|
+
})
|
|
1965
|
+
|
|
1966
|
+
it.each([
|
|
1967
|
+
['a malformed transaction', 'tx'],
|
|
1968
|
+
['a transaction without hash', {}],
|
|
1969
|
+
['another transaction', { hash: '0xbb' }],
|
|
1970
|
+
['a malformed fee currency', { hash: '0xaa', feeCurrency: 1 }],
|
|
1971
|
+
])('rejects %s', async (_, response) => {
|
|
1972
|
+
mockRawRpc({ eth_getTransactionByHash: response })
|
|
1973
|
+
|
|
1974
|
+
await expect(nodeApi.getFeeCurrency!('0xaa')).rejects.toMatchObject({
|
|
1975
|
+
name: 'MalformedNodeResponse',
|
|
1976
|
+
})
|
|
1977
|
+
})
|
|
1978
|
+
})
|
|
1979
|
+
|
|
1944
1980
|
describe('traceBlockErigon', () => {
|
|
1945
1981
|
it('should return trace array when trace_block is supported', async () => {
|
|
1946
1982
|
const traceItem = {
|
|
@@ -71,6 +71,23 @@ describe('withNodeSources', () => {
|
|
|
71
71
|
expect(withNodeSources(api, config, testLogger).getFeeCurrencies).toBeUndefined()
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
+
it('reads the fee currency of a transaction from the node, which the explorer proxy cannot', async () => {
|
|
75
|
+
const config = createMockEvmConfigInfo({
|
|
76
|
+
chainId: 1,
|
|
77
|
+
node,
|
|
78
|
+
explorer: mkEtherscanExplorer(),
|
|
79
|
+
nodeSources: nodeSourcesFromList(['explorer-proxy', 'node']),
|
|
80
|
+
})
|
|
81
|
+
const withFeeCurrency = mockNodeApi({
|
|
82
|
+
getFeeCurrency: jest.fn().mockResolvedValueOnce('0xfee'),
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const wrapped = withNodeSources(withFeeCurrency, config, testLogger)
|
|
86
|
+
|
|
87
|
+
await expect(wrapped.getFeeCurrency?.('0xabc')).resolves.toBe('0xfee')
|
|
88
|
+
expect(withNodeSources(api, config, testLogger).getFeeCurrency).toBeUndefined()
|
|
89
|
+
})
|
|
90
|
+
|
|
74
91
|
describe('getBlockByHeight', () => {
|
|
75
92
|
it('forwards successful calls unchanged', async () => {
|
|
76
93
|
const config = createMockEvmConfigInfo({
|