@ledgerhq/coin-evm 16.5.4 → 16.8.0
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 +22 -0
- package/lib/api/index.d.ts +5 -2
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +2 -1
- package/lib/api/index.js.map +1 -1
- package/lib/errors.d.ts +17 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +26 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/cip64Fees.d.ts +43 -0
- package/lib/logic/cip64Fees.d.ts.map +1 -0
- package/lib/logic/cip64Fees.js +139 -0
- package/lib/logic/cip64Fees.js.map +1 -0
- package/lib/logic/feeCollectorOperations.d.ts +2 -2
- package/lib/logic/feeCollectorOperations.js +2 -2
- package/lib/logic/getBlock.d.ts +2 -2
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +99 -19
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +20 -0
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +6 -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/staking/contracts.d.ts.map +1 -1
- package/lib/staking/contracts.js +7 -0
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/validators/index.d.ts.map +1 -1
- package/lib/staking/validators/index.js +36 -1
- package/lib/staking/validators/index.js.map +1 -1
- package/lib/staking/validators/monad.d.ts +1 -0
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js +103 -6
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/sei.d.ts.map +1 -1
- package/lib/staking/validators/sei.js +46 -14
- package/lib/staking/validators/sei.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js +31 -2
- package/lib/staking/validators/somnia.js.map +1 -1
- package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib/staking/validators/zero_gravity.js +14 -2
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib/types/staking.d.ts +10 -0
- package/lib/types/staking.d.ts.map +1 -1
- package/lib-es/api/index.d.ts +5 -2
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/errors.d.ts +17 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +21 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/cip64Fees.d.ts +43 -0
- package/lib-es/logic/cip64Fees.d.ts.map +1 -0
- package/lib-es/logic/cip64Fees.js +134 -0
- package/lib-es/logic/cip64Fees.js.map +1 -0
- package/lib-es/logic/feeCollectorOperations.d.ts +2 -2
- package/lib-es/logic/feeCollectorOperations.js +2 -2
- package/lib-es/logic/getBlock.d.ts +2 -2
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +99 -19
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +20 -0
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +6 -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/lib-es/staking/contracts.d.ts.map +1 -1
- package/lib-es/staking/contracts.js +7 -0
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/validators/index.d.ts.map +1 -1
- package/lib-es/staking/validators/index.js +3 -1
- package/lib-es/staking/validators/index.js.map +1 -1
- package/lib-es/staking/validators/monad.d.ts +1 -0
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js +101 -5
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/sei.d.ts.map +1 -1
- package/lib-es/staking/validators/sei.js +46 -14
- package/lib-es/staking/validators/sei.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js +31 -2
- package/lib-es/staking/validators/somnia.js.map +1 -1
- package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
- package/lib-es/staking/validators/zero_gravity.js +14 -2
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/types/staking.d.ts +10 -0
- package/lib-es/types/staking.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/api/index.ts +4 -1
- package/src/api/tests/index.celo.integ.test.ts +93 -0
- package/src/api/tests/index.flare.integ.test.ts +2 -1
- package/src/api/tests/index.test.ts +9 -0
- package/src/errors.ts +24 -0
- package/src/logic/cip64Fees.ts +193 -0
- package/src/logic/feeCollectorOperations.ts +2 -2
- package/src/logic/getBlock.ts +170 -30
- package/src/logic/tests/cip64Fees.test.ts +277 -0
- package/src/logic/tests/getBlock.test.ts +249 -2
- package/src/network/node/rpc.common.ts +29 -0
- package/src/network/node/types.ts +6 -0
- package/src/network/node/withNodeSources.ts +3 -0
- package/src/network/tests/node/rpc.test.ts +39 -0
- package/src/network/tests/node/withNodeSources.test.ts +18 -0
- package/src/staking/contracts.ts +7 -0
- package/src/staking/validators/index.ts +4 -1
- package/src/staking/validators/monad.test.ts +175 -44
- package/src/staking/validators/monad.ts +156 -4
- package/src/staking/validators/sei.test.ts +93 -0
- package/src/staking/validators/sei.ts +56 -14
- package/src/staking/validators/somnia.test.ts +44 -2
- package/src/staking/validators/somnia.ts +32 -2
- package/src/staking/validators/zero_gravity.test.ts +25 -0
- package/src/staking/validators/zero_gravity.ts +17 -2
- package/src/staking/validators.integ.test.ts +35 -4
- package/src/staking/validators.test.ts +34 -22
- package/src/types/staking.ts +10 -0
|
@@ -15,7 +15,7 @@ import type { EtherscanInternalTransaction } from '../../types'
|
|
|
15
15
|
import type { BlockOperation } from '@ledgerhq/coin-module-framework/api/index'
|
|
16
16
|
import { ethers } from 'ethers'
|
|
17
17
|
import { CHAIN_ID, evmDefaults, internalTxSourcesFromList } from '../../config'
|
|
18
|
-
import { UnsupportedRpcMethodError } from '../../errors'
|
|
18
|
+
import { UnsupportedFeeCurrencyError, UnsupportedRpcMethodError } from '../../errors'
|
|
19
19
|
import {
|
|
20
20
|
createMockEvmConfigInfo,
|
|
21
21
|
createMockEvmContext,
|
|
@@ -1096,7 +1096,8 @@ describe('getBlock', () => {
|
|
|
1096
1096
|
}
|
|
1097
1097
|
|
|
1098
1098
|
function mockBulkBlock(
|
|
1099
|
-
network: Pick<EvmConfigInfo, 'chainId' | 'feeCollectorContracts'
|
|
1099
|
+
network: Pick<EvmConfigInfo, 'chainId' | 'feeCollectorContracts' | 'feeCollectorTokens'>,
|
|
1100
|
+
otherTransfers: ERC20Transfer[] = []
|
|
1100
1101
|
): EvmContext {
|
|
1101
1102
|
const context = createMockEvmContext(
|
|
1102
1103
|
createMockEvmConfigInfo({
|
|
@@ -1131,6 +1132,7 @@ describe('getBlock', () => {
|
|
|
1131
1132
|
to: USER,
|
|
1132
1133
|
value: REFUND.toString(),
|
|
1133
1134
|
}),
|
|
1135
|
+
...otherTransfers,
|
|
1134
1136
|
],
|
|
1135
1137
|
}),
|
|
1136
1138
|
]),
|
|
@@ -1333,6 +1335,109 @@ describe('getBlock', () => {
|
|
|
1333
1335
|
expect(bootloaderNativeOps(tx.operations)).toHaveLength(2)
|
|
1334
1336
|
expect(userNativeDelta(tx.operations)).toBe(-PREPAYMENT)
|
|
1335
1337
|
})
|
|
1338
|
+
|
|
1339
|
+
it('drops the base-token fee legs too when the caller asks for the fee asset', async () => {
|
|
1340
|
+
const otherTransfer = makeNodeErc20Transfer({
|
|
1341
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1342
|
+
from: USER,
|
|
1343
|
+
to: address2,
|
|
1344
|
+
value: '1000',
|
|
1345
|
+
})
|
|
1346
|
+
const context = mockBulkBlock(
|
|
1347
|
+
{
|
|
1348
|
+
chainId: CHAIN_ID.ZKSYNC,
|
|
1349
|
+
feeCollectorContracts: [BOOTLOADER],
|
|
1350
|
+
feeCollectorTokens: [L2_BASE_TOKEN],
|
|
1351
|
+
},
|
|
1352
|
+
[otherTransfer]
|
|
1353
|
+
)
|
|
1354
|
+
jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
|
|
1355
|
+
makeExplorerInternalTransaction({
|
|
1356
|
+
from: USER,
|
|
1357
|
+
to: BOOTLOADER,
|
|
1358
|
+
value: PREPAYMENT.toString(),
|
|
1359
|
+
}),
|
|
1360
|
+
])
|
|
1361
|
+
|
|
1362
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
1363
|
+
|
|
1364
|
+
expect(tx.operations).toEqual([
|
|
1365
|
+
{
|
|
1366
|
+
type: 'transfer',
|
|
1367
|
+
address: USER,
|
|
1368
|
+
peer: address2,
|
|
1369
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1370
|
+
amount: -1000n,
|
|
1371
|
+
},
|
|
1372
|
+
{
|
|
1373
|
+
type: 'transfer',
|
|
1374
|
+
address: address2,
|
|
1375
|
+
peer: USER,
|
|
1376
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1377
|
+
amount: 1000n,
|
|
1378
|
+
},
|
|
1379
|
+
])
|
|
1380
|
+
expect(tx.fees).toBe(FEE)
|
|
1381
|
+
expect(tx.feesPayer).toBe(USER)
|
|
1382
|
+
expect(tx).not.toHaveProperty('feesAsset')
|
|
1383
|
+
})
|
|
1384
|
+
|
|
1385
|
+
it.each([
|
|
1386
|
+
['no internal transfer', false],
|
|
1387
|
+
['only its internal refund', true],
|
|
1388
|
+
])('reads a paymaster from its base-token prepayment, with %s', async (_, withRefund) => {
|
|
1389
|
+
const PAYMASTER = '0xA2Aac7bC9725c36ad9B12D2407dF8de6B2B68359'
|
|
1390
|
+
if (withRefund) {
|
|
1391
|
+
jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
|
|
1392
|
+
makeExplorerInternalTransaction({
|
|
1393
|
+
from: BOOTLOADER,
|
|
1394
|
+
to: PAYMASTER,
|
|
1395
|
+
value: '42357348500000',
|
|
1396
|
+
}),
|
|
1397
|
+
])
|
|
1398
|
+
}
|
|
1399
|
+
const context = createMockEvmContext(
|
|
1400
|
+
createMockEvmConfigInfo({
|
|
1401
|
+
chainId: CHAIN_ID.ZKSYNC,
|
|
1402
|
+
feeCollectorContracts: [BOOTLOADER],
|
|
1403
|
+
feeCollectorTokens: [L2_BASE_TOKEN],
|
|
1404
|
+
node: mkExternalNode(),
|
|
1405
|
+
explorer: mkEtherscanExplorer(),
|
|
1406
|
+
})
|
|
1407
|
+
)
|
|
1408
|
+
mockGetBlockNodeApi(
|
|
1409
|
+
mockNodeApi({
|
|
1410
|
+
getBlockByHeight: jest.fn().mockResolvedValueOnce(
|
|
1411
|
+
makeNodeBlock({
|
|
1412
|
+
transactions: [makeNodeBlockTx({ from: USER, to: address2, value: '0' })],
|
|
1413
|
+
})
|
|
1414
|
+
),
|
|
1415
|
+
getBlockReceipts: jest.fn().mockResolvedValueOnce([
|
|
1416
|
+
makeNodeBlockReceipt({
|
|
1417
|
+
erc20Transfers: [
|
|
1418
|
+
makeNodeErc20Transfer({
|
|
1419
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1420
|
+
from: PAYMASTER,
|
|
1421
|
+
to: BOOTLOADER,
|
|
1422
|
+
value: '49775000000000',
|
|
1423
|
+
}),
|
|
1424
|
+
makeNodeErc20Transfer({
|
|
1425
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1426
|
+
from: BOOTLOADER,
|
|
1427
|
+
to: PAYMASTER,
|
|
1428
|
+
value: '42357348500000',
|
|
1429
|
+
}),
|
|
1430
|
+
],
|
|
1431
|
+
}),
|
|
1432
|
+
]),
|
|
1433
|
+
})
|
|
1434
|
+
)
|
|
1435
|
+
|
|
1436
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
1437
|
+
|
|
1438
|
+
expect(tx.feesPayer).toBe(PAYMASTER)
|
|
1439
|
+
expect(tx.operations).toEqual([])
|
|
1440
|
+
})
|
|
1336
1441
|
})
|
|
1337
1442
|
|
|
1338
1443
|
it('when explorer is not etherscan like, falls back to node.traceBlockErigon', async () => {
|
|
@@ -2195,6 +2300,148 @@ describe('getBlock', () => {
|
|
|
2195
2300
|
])
|
|
2196
2301
|
})
|
|
2197
2302
|
})
|
|
2303
|
+
|
|
2304
|
+
describe('Celo CIP-64 fee currencies', () => {
|
|
2305
|
+
// Fee logs of tx 0x45e41cf20fca9b079f8b23510bb9637d14df647cb6d25d85157924cd27df09d7 (block
|
|
2306
|
+
// 80494727), which pays its fee in USD₮ through the USD₮ adapter
|
|
2307
|
+
const PAYER = '0x5362C723476b46a1e65D54E667C00e46b46F6f12'
|
|
2308
|
+
const USDT = '0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e'
|
|
2309
|
+
const USDT_ADAPTER = '0x0E2A3e05bc9A16F5292A6170456A710cb89C6f72'
|
|
2310
|
+
const HOLDER = '0x000000000000000000000000000000000Ce106A5'
|
|
2311
|
+
const FEE_HANDLER = '0xcD437749E43A154C07F3553504c68fBfD56B8778'
|
|
2312
|
+
const SEQUENCER_VAULT = '0x4200000000000000000000000000000000000011'
|
|
2313
|
+
const GAS_USED = '100000'
|
|
2314
|
+
const GAS_PRICE = '31763731729'
|
|
2315
|
+
const NATIVE_FEES = 3176373172900000n
|
|
2316
|
+
|
|
2317
|
+
const usdt = (from: string, to: string, value: string): ERC20Transfer =>
|
|
2318
|
+
makeNodeErc20Transfer({ asset: { type: 'erc20', assetReference: USDT }, from, to, value })
|
|
2319
|
+
const userTransfer = usdt(address2, PAYER, '5800')
|
|
2320
|
+
const transfers = [
|
|
2321
|
+
usdt(PAYER, HOLDER, '4252'),
|
|
2322
|
+
userTransfer,
|
|
2323
|
+
usdt(HOLDER, SEQUENCER_VAULT, '0'),
|
|
2324
|
+
usdt(HOLDER, FEE_HANDLER, '3176'),
|
|
2325
|
+
usdt(HOLDER, PAYER, '1076'),
|
|
2326
|
+
]
|
|
2327
|
+
const userOperations: BlockOperation[] = [
|
|
2328
|
+
{
|
|
2329
|
+
type: 'transfer',
|
|
2330
|
+
address: address2,
|
|
2331
|
+
peer: PAYER,
|
|
2332
|
+
asset: { type: 'erc20', assetReference: USDT },
|
|
2333
|
+
amount: -5800n,
|
|
2334
|
+
},
|
|
2335
|
+
{
|
|
2336
|
+
type: 'transfer',
|
|
2337
|
+
address: PAYER,
|
|
2338
|
+
peer: address2,
|
|
2339
|
+
asset: { type: 'erc20', assetReference: USDT },
|
|
2340
|
+
amount: 5800n,
|
|
2341
|
+
},
|
|
2342
|
+
]
|
|
2343
|
+
|
|
2344
|
+
function mockCeloBlock({
|
|
2345
|
+
chainId = CHAIN_ID.CELO,
|
|
2346
|
+
feeCurrency = USDT_ADAPTER,
|
|
2347
|
+
prefetched = true,
|
|
2348
|
+
receiptType = 0x7b,
|
|
2349
|
+
}: {
|
|
2350
|
+
chainId?: ChainId
|
|
2351
|
+
feeCurrency?: string | null
|
|
2352
|
+
prefetched?: boolean
|
|
2353
|
+
receiptType?: number | null
|
|
2354
|
+
} = {}): { context: EvmContext; nodeApi: ReturnType<typeof mockNodeApi> } {
|
|
2355
|
+
const context = createMockEvmContext(
|
|
2356
|
+
createMockEvmConfigInfo({
|
|
2357
|
+
chainId,
|
|
2358
|
+
node: mkExternalNode(),
|
|
2359
|
+
explorer: mkEtherscanExplorer(),
|
|
2360
|
+
})
|
|
2361
|
+
)
|
|
2362
|
+
const receipt = {
|
|
2363
|
+
hash: '0xtx1',
|
|
2364
|
+
gasUsed: GAS_USED,
|
|
2365
|
+
gasPrice: GAS_PRICE,
|
|
2366
|
+
...(receiptType !== null ? { type: receiptType } : {}),
|
|
2367
|
+
erc20Transfers: transfers,
|
|
2368
|
+
}
|
|
2369
|
+
const nodeApi = mockNodeApi({
|
|
2370
|
+
getBlockByHeight: jest.fn().mockResolvedValueOnce(
|
|
2371
|
+
prefetched
|
|
2372
|
+
? makeNodeBlock({
|
|
2373
|
+
transactions: [makeNodeBlockTx({ from: PAYER, value: '0', gasPrice: GAS_PRICE })],
|
|
2374
|
+
})
|
|
2375
|
+
: makeNodeBlock({ transactionHashes: ['0xtx1'] })
|
|
2376
|
+
),
|
|
2377
|
+
getBlockReceipts: jest.fn().mockResolvedValueOnce([makeNodeBlockReceipt(receipt)]),
|
|
2378
|
+
getTransaction: jest
|
|
2379
|
+
.fn()
|
|
2380
|
+
.mockResolvedValueOnce(makeNodeTxInfo({ ...receipt, from: PAYER, value: '0' })),
|
|
2381
|
+
getFeeCurrencies: jest.fn().mockResolvedValue(new Map([['0xtx1', feeCurrency]])),
|
|
2382
|
+
})
|
|
2383
|
+
mockGetBlockNodeApi(nodeApi)
|
|
2384
|
+
return { context, nodeApi }
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
it.each([
|
|
2388
|
+
['prefetched with block receipts', true, 0x7b],
|
|
2389
|
+
['fetched one by one', false, 0x7b],
|
|
2390
|
+
['whose block receipt has no type', true, null],
|
|
2391
|
+
])(
|
|
2392
|
+
'reports the token fee and drops the fee logs, on a transaction %s',
|
|
2393
|
+
async (_, prefetched, receiptType) => {
|
|
2394
|
+
const { context, nodeApi } = mockCeloBlock({ prefetched, receiptType })
|
|
2395
|
+
|
|
2396
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
2397
|
+
|
|
2398
|
+
expect(tx.fees).toBe(3176n)
|
|
2399
|
+
expect(tx.feesAsset).toEqual({ type: 'erc20', assetReference: USDT })
|
|
2400
|
+
expect(tx.feesPayer).toBe(PAYER)
|
|
2401
|
+
expect(tx.operations).toEqual(userOperations)
|
|
2402
|
+
expect(nodeApi.getFeeCurrencies).toHaveBeenCalledWith(12345)
|
|
2403
|
+
}
|
|
2404
|
+
)
|
|
2405
|
+
|
|
2406
|
+
it('keeps the native fee and the fee logs when the caller does not ask for the fee asset', async () => {
|
|
2407
|
+
const { context, nodeApi } = mockCeloBlock()
|
|
2408
|
+
|
|
2409
|
+
const [tx] = (await getBlock(context, 12345)).transactions
|
|
2410
|
+
|
|
2411
|
+
expect(tx.fees).toBe(NATIVE_FEES)
|
|
2412
|
+
expect(tx).not.toHaveProperty('feesAsset')
|
|
2413
|
+
expect(tx.operations).toHaveLength(transfers.length * 2)
|
|
2414
|
+
expect(nodeApi.getFeeCurrencies).not.toHaveBeenCalled()
|
|
2415
|
+
})
|
|
2416
|
+
|
|
2417
|
+
it('keeps the native fee of a CIP-64 transaction that pays in the native coin', async () => {
|
|
2418
|
+
const { context } = mockCeloBlock({ feeCurrency: null })
|
|
2419
|
+
|
|
2420
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
2421
|
+
|
|
2422
|
+
expect(tx.fees).toBe(NATIVE_FEES)
|
|
2423
|
+
expect(tx).not.toHaveProperty('feesAsset')
|
|
2424
|
+
expect(tx.operations).toHaveLength(transfers.length * 2)
|
|
2425
|
+
})
|
|
2426
|
+
|
|
2427
|
+
it('does not read fee currencies on another chain', async () => {
|
|
2428
|
+
const { context, nodeApi } = mockCeloBlock({ chainId: CHAIN_ID.ETHEREUM })
|
|
2429
|
+
|
|
2430
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
2431
|
+
|
|
2432
|
+
expect(tx.fees).toBe(NATIVE_FEES)
|
|
2433
|
+
expect(tx).not.toHaveProperty('feesAsset')
|
|
2434
|
+
expect(nodeApi.getFeeCurrencies).not.toHaveBeenCalled()
|
|
2435
|
+
})
|
|
2436
|
+
|
|
2437
|
+
it('rejects a block with a transaction paid in an unsupported fee currency', async () => {
|
|
2438
|
+
const { context } = mockCeloBlock({ feeCurrency: address2 })
|
|
2439
|
+
|
|
2440
|
+
await expect(getBlock(context, 12345, { feesAsset: true })).rejects.toThrow(
|
|
2441
|
+
UnsupportedFeeCurrencyError
|
|
2442
|
+
)
|
|
2443
|
+
})
|
|
2444
|
+
})
|
|
2198
2445
|
})
|
|
2199
2446
|
|
|
2200
2447
|
describe('dropRootTraceDuplicates', () => {
|
|
@@ -965,6 +965,34 @@ async function getBlockReceipts(
|
|
|
965
965
|
})
|
|
966
966
|
}
|
|
967
967
|
|
|
968
|
+
async function getFeeCurrencies(
|
|
969
|
+
api: JsonRpcProvider,
|
|
970
|
+
blockHeight: number
|
|
971
|
+
): Promise<Map<string, string | null>> {
|
|
972
|
+
const rawBlock: unknown = await api.send('eth_getBlockByNumber', [
|
|
973
|
+
ethers.toQuantity(blockHeight),
|
|
974
|
+
true,
|
|
975
|
+
])
|
|
976
|
+
if (!isRecord(rawBlock) || !Array.isArray(rawBlock.transactions))
|
|
977
|
+
throw new MalformedNodeResponse('Invalid eth_getBlockByNumber response')
|
|
978
|
+
|
|
979
|
+
const feeCurrencies = new Map<string, string | null>()
|
|
980
|
+
for (const [index, tx] of rawBlock.transactions.entries()) {
|
|
981
|
+
if (!isRecord(tx) || typeof tx.hash !== 'string')
|
|
982
|
+
throw new MalformedNodeResponse(
|
|
983
|
+
`Malformed block transaction at index ${index} in eth_getBlockByNumber response`
|
|
984
|
+
)
|
|
985
|
+
// op-geth omits `feeCurrency` when the fee is paid in the native coin
|
|
986
|
+
const feeCurrency = tx.feeCurrency ?? null
|
|
987
|
+
if (feeCurrency !== null && typeof feeCurrency !== 'string')
|
|
988
|
+
throw new MalformedNodeResponse(
|
|
989
|
+
`Malformed feeCurrency at index ${index} in eth_getBlockByNumber response`
|
|
990
|
+
)
|
|
991
|
+
feeCurrencies.set(tx.hash.toLowerCase(), feeCurrency)
|
|
992
|
+
}
|
|
993
|
+
return feeCurrencies
|
|
994
|
+
}
|
|
995
|
+
|
|
968
996
|
async function traceBlockGeth(
|
|
969
997
|
api: JsonRpcProvider,
|
|
970
998
|
blockHeight: number
|
|
@@ -1181,6 +1209,7 @@ export function createNodeApi(
|
|
|
1181
1209
|
withApi(evmConfig, (api) => getTransaction(api, txHash, logger), nodeConfig),
|
|
1182
1210
|
getBlockReceipts: (blockHeight) =>
|
|
1183
1211
|
withApi(evmConfig, (api) => getBlockReceipts(api, blockHeight, logger), nodeConfig),
|
|
1212
|
+
getFeeCurrencies: make(getFeeCurrencies, evmConfig, nodeConfig),
|
|
1184
1213
|
traceBlockErigon: make(traceBlockErigon, evmConfig, nodeConfig),
|
|
1185
1214
|
traceBlockGeth: make(traceBlockGeth, evmConfig, nodeConfig),
|
|
1186
1215
|
getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig, logger),
|
|
@@ -183,6 +183,12 @@ export type NodeApi = {
|
|
|
183
183
|
// timestamp is in milliseconds
|
|
184
184
|
) => Promise<BlockByHeightResult>
|
|
185
185
|
getBlockReceipts?: (blockHeight: number | 'latest') => Promise<BlockReceiptInfo[]>
|
|
186
|
+
/**
|
|
187
|
+
* The Celo CIP-64 `feeCurrency` of each transaction of a block, by lower-case hash: `null` when
|
|
188
|
+
* the transaction pays its fee in the native coin, which the node shows by omitting the field.
|
|
189
|
+
* Ethers drops the field, so this reads the raw block.
|
|
190
|
+
*/
|
|
191
|
+
getFeeCurrencies?: (blockHeight: number) => Promise<Map<string, string | null>>
|
|
186
192
|
traceBlockErigon?: (blockHeight: number | 'latest') => Promise<TraceBlockItem[]>
|
|
187
193
|
traceBlockGeth?: (blockHeight: number) => Promise<TraceBlockItem[]>
|
|
188
194
|
getOptimismAdditionalFees: (transaction: string) => Promise<BigNumber>
|
|
@@ -56,6 +56,9 @@ export function createFailoverNodeApi(sources: NodeApi[], logger: Logger): NodeA
|
|
|
56
56
|
if (sources.some((api) => api.getBlockReceipts))
|
|
57
57
|
base.getBlockReceipts = (h): Promise<BlockReceiptInfo[]> =>
|
|
58
58
|
tryInOrder('getBlockReceipts', (api) => api.getBlockReceipts?.(h))
|
|
59
|
+
if (sources.some((api) => api.getFeeCurrencies))
|
|
60
|
+
base.getFeeCurrencies = (h): Promise<Map<string, string | null>> =>
|
|
61
|
+
tryInOrder('getFeeCurrencies', (api) => api.getFeeCurrencies?.(h))
|
|
59
62
|
if (sources.some((api) => api.traceBlockErigon))
|
|
60
63
|
base.traceBlockErigon = (h): Promise<TraceBlockItem[]> =>
|
|
61
64
|
tryInOrder('traceBlockErigon', (api) => api.traceBlockErigon?.(h))
|
|
@@ -1902,6 +1902,45 @@ describe('EVM Family', () => {
|
|
|
1902
1902
|
})
|
|
1903
1903
|
})
|
|
1904
1904
|
|
|
1905
|
+
describe('getFeeCurrencies', () => {
|
|
1906
|
+
it('reads the fee currency of each transaction from the raw block, an omitted one as native', async () => {
|
|
1907
|
+
const send = mockRawRpc({
|
|
1908
|
+
eth_getBlockByNumber: {
|
|
1909
|
+
transactions: [
|
|
1910
|
+
{
|
|
1911
|
+
hash: '0xAA',
|
|
1912
|
+
type: '0x7b',
|
|
1913
|
+
feeCurrency: '0x0e2a3e05bc9a16f5292a6170456a710cb89c6f72',
|
|
1914
|
+
},
|
|
1915
|
+
{ hash: '0xbb', type: '0x7b', feeCurrency: null },
|
|
1916
|
+
{ hash: '0xcc', type: '0x7b' },
|
|
1917
|
+
],
|
|
1918
|
+
},
|
|
1919
|
+
})
|
|
1920
|
+
|
|
1921
|
+
expect(await nodeApi.getFeeCurrencies!(80494727)).toEqual(
|
|
1922
|
+
new Map([
|
|
1923
|
+
['0xaa', '0x0e2a3e05bc9a16f5292a6170456a710cb89c6f72'],
|
|
1924
|
+
['0xbb', null],
|
|
1925
|
+
['0xcc', null],
|
|
1926
|
+
])
|
|
1927
|
+
)
|
|
1928
|
+
expect(send).toHaveBeenCalledWith('eth_getBlockByNumber', ['0x4cc4087', true])
|
|
1929
|
+
})
|
|
1930
|
+
|
|
1931
|
+
it.each([
|
|
1932
|
+
['a block without transactions', undefined],
|
|
1933
|
+
['a transaction without hash', [{ feeCurrency: null }]],
|
|
1934
|
+
['a malformed fee currency', [{ hash: '0xaa', feeCurrency: 1 }]],
|
|
1935
|
+
])('rejects %s', async (_, transactions) => {
|
|
1936
|
+
mockRawRpc({ eth_getBlockByNumber: { transactions } })
|
|
1937
|
+
|
|
1938
|
+
await expect(nodeApi.getFeeCurrencies!(1)).rejects.toMatchObject({
|
|
1939
|
+
name: 'MalformedNodeResponse',
|
|
1940
|
+
})
|
|
1941
|
+
})
|
|
1942
|
+
})
|
|
1943
|
+
|
|
1905
1944
|
describe('traceBlockErigon', () => {
|
|
1906
1945
|
it('should return trace array when trace_block is supported', async () => {
|
|
1907
1946
|
const traceItem = {
|
|
@@ -53,6 +53,24 @@ describe('withNodeSources', () => {
|
|
|
53
53
|
expect(withNodeSources(api, config, testLogger)).not.toBe(api)
|
|
54
54
|
})
|
|
55
55
|
|
|
56
|
+
it('reads fee currencies from the node, which the explorer proxy cannot', async () => {
|
|
57
|
+
const config = createMockEvmConfigInfo({
|
|
58
|
+
chainId: 1,
|
|
59
|
+
node,
|
|
60
|
+
explorer: mkEtherscanExplorer(),
|
|
61
|
+
nodeSources: nodeSourcesFromList(['explorer-proxy', 'node']),
|
|
62
|
+
})
|
|
63
|
+
const feeCurrencies = new Map([['0xabc', null]])
|
|
64
|
+
const withFeeCurrencies = mockNodeApi({
|
|
65
|
+
getFeeCurrencies: jest.fn().mockResolvedValueOnce(feeCurrencies),
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const wrapped = withNodeSources(withFeeCurrencies, config, testLogger)
|
|
69
|
+
|
|
70
|
+
await expect(wrapped.getFeeCurrencies?.(100)).resolves.toBe(feeCurrencies)
|
|
71
|
+
expect(withNodeSources(api, config, testLogger).getFeeCurrencies).toBeUndefined()
|
|
72
|
+
})
|
|
73
|
+
|
|
56
74
|
describe('getBlockByHeight', () => {
|
|
57
75
|
it('forwards successful calls unchanged', async () => {
|
|
58
76
|
const config = createMockEvmConfigInfo({
|
package/src/staking/contracts.ts
CHANGED
|
@@ -49,6 +49,8 @@ export const STAKING_CONTRACTS: Partial<Record<ChainId, StakingContractConfig>>
|
|
|
49
49
|
baseUrl: 'https://rest.sei-apis.com/',
|
|
50
50
|
validatorsEndpoint:
|
|
51
51
|
'/cosmos/staking/v1beta1/validators?status=BOND_STATUS_BONDED&pagination.limit=200',
|
|
52
|
+
mintEndpoint: '/seichain/mint/v1beta1/minter',
|
|
53
|
+
poolEndpoint: '/cosmos/staking/v1beta1/pool',
|
|
52
54
|
// Source: https://docs.sei.io/evm/precompiles/cosmwasm-precompiles/addr
|
|
53
55
|
precompileAddress: {
|
|
54
56
|
address: '0x0000000000000000000000000000000000001004',
|
|
@@ -292,6 +294,11 @@ export const STAKING_CONTRACTS: Partial<Record<ChainId, StakingContractConfig>>
|
|
|
292
294
|
validatorNameSource: {
|
|
293
295
|
baseUrl: 'https://staking.somnia.network/api/validator-names',
|
|
294
296
|
},
|
|
297
|
+
// Network staking rate (mean fees paid to the staking contract over the last 100 epochs,
|
|
298
|
+
// per year, over the total staked), as shown on the official dashboard.
|
|
299
|
+
stakingRateSource: {
|
|
300
|
+
baseUrl: 'https://staking.somnia.network/api/apr-calculation',
|
|
301
|
+
},
|
|
295
302
|
value: ({ mode, amount }) => (mode === 'delegate' ? amount : 0n),
|
|
296
303
|
delegationMaxAmountReserve: 10n ** 17n,
|
|
297
304
|
// Somnia dashboard indexes delegations off-chain; new delegations can take up to 5 minutes to appear on the delegation board.
|
|
@@ -8,7 +8,7 @@ import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
|
8
8
|
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
9
9
|
import { CHAIN_ID } from '../../config'
|
|
10
10
|
import { STAKING_CONTRACTS } from '../contracts'
|
|
11
|
-
import monadValidatorApi from './monad'
|
|
11
|
+
import monadValidatorApi, { clearRewardRateCache } from './monad'
|
|
12
12
|
import seiValidatorApi from './sei'
|
|
13
13
|
import somniaValidatorApi from './somnia'
|
|
14
14
|
import zeroGravityValidatorApi from './zero_gravity'
|
|
@@ -64,6 +64,9 @@ const validatorsCache = makeLRUCache(
|
|
|
64
64
|
const issuedKeys = new Set<string>()
|
|
65
65
|
|
|
66
66
|
export const clearValidatorsCache = (chainId?: ChainId): void => {
|
|
67
|
+
// Monad pages reuse the validators fetched for the reward rate: they must not outlive the pages.
|
|
68
|
+
clearRewardRateCache(chainId)
|
|
69
|
+
|
|
67
70
|
if (chainId === undefined) {
|
|
68
71
|
validatorsCache.reset()
|
|
69
72
|
issuedKeys.clear()
|