@ledgerhq/coin-evm 10.0.0 → 10.1.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/.oxlintrc.json +2 -6
- package/CHANGELOG.md +12 -0
- package/lib/abis/index.d.ts +8 -0
- package/lib/abis/index.d.ts.map +1 -1
- package/lib/abis/index.js +30 -0
- package/lib/abis/index.js.map +1 -1
- package/lib/adapters/blockOperations.js +2 -2
- package/lib/adapters/blockOperations.js.map +1 -1
- 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/internalTxSources.d.ts.map +1 -1
- package/lib/internalTxSources.js +21 -3
- package/lib/internalTxSources.js.map +1 -1
- package/lib/logic/common.d.ts.map +1 -1
- package/lib/logic/common.js +11 -3
- package/lib/logic/common.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +4 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +4 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/internalTransactionsFetcher.js +1 -1
- package/lib/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib/logic/predicates.d.ts +17 -0
- package/lib/logic/predicates.d.ts.map +1 -0
- package/lib/logic/predicates.js +126 -0
- package/lib/logic/predicates.js.map +1 -0
- package/lib/network/explorer/types.d.ts.map +1 -1
- package/lib/network/explorer/types.js +11 -1
- package/lib/network/explorer/types.js.map +1 -1
- package/lib/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib/network/gasTracker/ledger.js +1 -3
- package/lib/network/gasTracker/ledger.js.map +1 -1
- package/lib/network/node/explorerProxy.d.ts.map +1 -1
- package/lib/network/node/explorerProxy.js +10 -5
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
- package/lib/network/node/gethCallTracerToTraceBlockItems.js +10 -12
- package/lib/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +10 -5
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +60 -70
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +6 -7
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js +0 -27
- package/lib/network/node/types.js.map +1 -1
- package/lib/nodeSources.d.ts.map +1 -1
- package/lib/nodeSources.js +11 -3
- package/lib/nodeSources.js.map +1 -1
- package/lib/staking/contracts.d.ts.map +1 -1
- package/lib/staking/contracts.js +1 -3
- package/lib/staking/contracts.js.map +1 -1
- package/lib/staking/detectOperationType.d.ts +0 -3
- package/lib/staking/detectOperationType.d.ts.map +1 -1
- package/lib/staking/detectOperationType.js +15 -14
- package/lib/staking/detectOperationType.js.map +1 -1
- package/lib/staking/operations/index.d.ts.map +1 -1
- package/lib/staking/operations/index.js +18 -1
- package/lib/staking/operations/index.js.map +1 -1
- package/lib/staking/prepareIntents.d.ts.map +1 -1
- package/lib/staking/prepareIntents.js +4 -3
- package/lib/staking/prepareIntents.js.map +1 -1
- package/lib/staking/redelegations.d.ts.map +1 -1
- package/lib/staking/redelegations.js +4 -7
- package/lib/staking/redelegations.js.map +1 -1
- package/lib/staking/utils.d.ts.map +1 -1
- package/lib/staking/utils.js +22 -27
- package/lib/staking/utils.js.map +1 -1
- package/lib/staking/validators/monad.d.ts.map +1 -1
- package/lib/staking/validators/monad.js +15 -6
- package/lib/staking/validators/monad.js.map +1 -1
- package/lib/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib/staking/validators/monadResolver.js +4 -3
- package/lib/staking/validators/monadResolver.js.map +1 -1
- package/lib/staking/validators/somnia.d.ts.map +1 -1
- package/lib/staking/validators/somnia.js +4 -3
- 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 +4 -3
- package/lib/staking/validators/zero_gravity.js.map +1 -1
- package/lib-es/abis/index.d.ts +8 -0
- package/lib-es/abis/index.d.ts.map +1 -1
- package/lib-es/abis/index.js +29 -0
- package/lib-es/abis/index.js.map +1 -1
- package/lib-es/adapters/blockOperations.js +1 -1
- package/lib-es/adapters/blockOperations.js.map +1 -1
- 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/internalTxSources.d.ts.map +1 -1
- package/lib-es/internalTxSources.js +21 -3
- package/lib-es/internalTxSources.js.map +1 -1
- package/lib-es/logic/common.d.ts.map +1 -1
- package/lib-es/logic/common.js +11 -3
- package/lib-es/logic/common.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +4 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +4 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js +1 -1
- package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
- package/lib-es/logic/predicates.d.ts +17 -0
- package/lib-es/logic/predicates.d.ts.map +1 -0
- package/lib-es/logic/predicates.js +114 -0
- package/lib-es/logic/predicates.js.map +1 -0
- package/lib-es/network/explorer/types.d.ts.map +1 -1
- package/lib-es/network/explorer/types.js +11 -1
- package/lib-es/network/explorer/types.js.map +1 -1
- package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
- package/lib-es/network/gasTracker/ledger.js +1 -3
- package/lib-es/network/gasTracker/ledger.js.map +1 -1
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -1
- package/lib-es/network/node/explorerProxy.js +10 -5
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.js +4 -6
- package/lib-es/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +10 -5
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +58 -68
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +6 -7
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/network/node/types.js +0 -25
- package/lib-es/network/node/types.js.map +1 -1
- package/lib-es/nodeSources.d.ts.map +1 -1
- package/lib-es/nodeSources.js +11 -3
- package/lib-es/nodeSources.js.map +1 -1
- package/lib-es/staking/contracts.d.ts.map +1 -1
- package/lib-es/staking/contracts.js +1 -3
- package/lib-es/staking/contracts.js.map +1 -1
- package/lib-es/staking/detectOperationType.d.ts +0 -3
- package/lib-es/staking/detectOperationType.d.ts.map +1 -1
- package/lib-es/staking/detectOperationType.js +15 -14
- package/lib-es/staking/detectOperationType.js.map +1 -1
- package/lib-es/staking/operations/index.d.ts.map +1 -1
- package/lib-es/staking/operations/index.js +18 -1
- package/lib-es/staking/operations/index.js.map +1 -1
- package/lib-es/staking/prepareIntents.d.ts.map +1 -1
- package/lib-es/staking/prepareIntents.js +2 -1
- package/lib-es/staking/prepareIntents.js.map +1 -1
- package/lib-es/staking/redelegations.d.ts.map +1 -1
- package/lib-es/staking/redelegations.js +1 -4
- package/lib-es/staking/redelegations.js.map +1 -1
- package/lib-es/staking/utils.d.ts.map +1 -1
- package/lib-es/staking/utils.js +20 -25
- package/lib-es/staking/utils.js.map +1 -1
- package/lib-es/staking/validators/monad.d.ts.map +1 -1
- package/lib-es/staking/validators/monad.js +12 -3
- package/lib-es/staking/validators/monad.js.map +1 -1
- package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
- package/lib-es/staking/validators/monadResolver.js +2 -1
- package/lib-es/staking/validators/monadResolver.js.map +1 -1
- package/lib-es/staking/validators/somnia.d.ts.map +1 -1
- package/lib-es/staking/validators/somnia.js +2 -1
- 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 +2 -1
- package/lib-es/staking/validators/zero_gravity.js.map +1 -1
- package/package.json +2 -2
- package/src/abis/index.test.ts +36 -0
- package/src/abis/index.ts +30 -0
- package/src/adapters/blockOperations.ts +1 -1
- package/src/api/index.ts +3 -2
- package/src/internalTxSources.ts +20 -3
- package/src/logic/common.ts +13 -3
- package/src/logic/craftTransaction.ts +4 -2
- package/src/logic/estimateFees.ts +4 -2
- package/src/logic/internalTransactionsFetcher.ts +1 -1
- package/src/logic/predicates.ts +124 -0
- package/src/logic/tests/validateIntent.test.ts +4 -1
- package/src/network/explorer/ledger.test.ts +21 -15
- package/src/network/explorer/types.ts +12 -3
- package/src/network/gasTracker/ledger.ts +1 -4
- package/src/network/node/explorerProxy.ts +11 -8
- package/src/network/node/gethCallTracerToTraceBlockItems.test.ts +1 -1
- package/src/network/node/gethCallTracerToTraceBlockItems.ts +6 -9
- package/src/network/node/ledger.ts +14 -10
- package/src/network/node/rpc.common.ts +92 -88
- package/src/network/node/rpc.test.ts +119 -0
- package/src/network/node/types.ts +6 -35
- package/src/nodeSources.ts +11 -3
- package/src/staking/contracts.ts +1 -3
- package/src/staking/detectOperationType.ts +15 -14
- package/src/staking/operations/index.ts +26 -7
- package/src/staking/prepareIntents.ts +2 -1
- package/src/staking/redelegations.ts +1 -5
- package/src/staking/utils.ts +19 -26
- package/src/staking/validators/monad.ts +11 -3
- package/src/staking/validators/monadResolver.ts +2 -1
- package/src/staking/validators/somnia.ts +4 -3
- package/src/staking/validators/zero_gravity.ts +2 -1
|
@@ -46,17 +46,6 @@ export type TraceBlockCallAction = {
|
|
|
46
46
|
value: string
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export function isTraceBlockCallAction(
|
|
50
|
-
action: Record<string, unknown>
|
|
51
|
-
): action is TraceBlockCallAction {
|
|
52
|
-
return (
|
|
53
|
-
typeof action.from === 'string' &&
|
|
54
|
-
typeof action.to === 'string' &&
|
|
55
|
-
typeof action.callType === 'string' &&
|
|
56
|
-
typeof action.value === 'string'
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
49
|
/**
|
|
61
50
|
* Other action types (e.g. reward, or other trace_block action shapes).
|
|
62
51
|
* No specific fields are prescribed.
|
|
@@ -92,36 +81,18 @@ export type TraceBlockItem = {
|
|
|
92
81
|
type: string
|
|
93
82
|
}
|
|
94
83
|
|
|
95
|
-
/** Type guard for {@link TraceBlockItem} (Erigon `trace_block` and Geth adapter output). */
|
|
96
|
-
export function isTraceBlockItem(value: unknown): value is TraceBlockItem {
|
|
97
|
-
if (typeof value !== 'object' || value === null) return false
|
|
98
|
-
const o = value as Record<string, unknown>
|
|
99
|
-
if (!o.action || typeof o.action !== 'object' || o.action === null) return false
|
|
100
|
-
const action = o.action as Record<string, unknown>
|
|
101
|
-
if (o.error !== undefined && typeof o.error !== 'string') return false
|
|
102
|
-
|
|
103
|
-
const result = o.result
|
|
104
|
-
const resultOk =
|
|
105
|
-
result === undefined ||
|
|
106
|
-
result === null ||
|
|
107
|
-
(typeof result === 'object' &&
|
|
108
|
-
((result as Record<string, unknown>).error === undefined ||
|
|
109
|
-
typeof (result as Record<string, unknown>).error === 'string'))
|
|
110
|
-
const validCall = typeof o.transactionHash === 'string' && resultOk
|
|
111
|
-
|
|
112
|
-
return !isTraceBlockCallAction(action) || validCall
|
|
113
|
-
}
|
|
114
|
-
|
|
115
84
|
/** A transaction receipt as returned by a RPC node. */
|
|
116
85
|
export type TransactionReceipt = {
|
|
117
86
|
transactionHash: string
|
|
118
87
|
gasUsed: string
|
|
119
|
-
|
|
120
|
-
|
|
88
|
+
/** Absent, or JSON `null`, when the node does not report this field. */
|
|
89
|
+
effectiveGasPrice?: string | null
|
|
90
|
+
/** Absent, or JSON `null`, when the node does not report this field. */
|
|
91
|
+
gasPrice?: string | null
|
|
121
92
|
status: string | number | null
|
|
122
93
|
logs: LogWithAddress[]
|
|
123
|
-
/** Tx envelope type per EIP-2718, hex-prefixed (e.g. "0x2" EIP-1559). */
|
|
124
|
-
type?: string
|
|
94
|
+
/** Tx envelope type per EIP-2718, hex-prefixed (e.g. "0x2" EIP-1559). `null` when the node omits it. */
|
|
95
|
+
type?: string | null
|
|
125
96
|
}
|
|
126
97
|
|
|
127
98
|
/**
|
package/src/nodeSources.ts
CHANGED
|
@@ -24,14 +24,22 @@ export function nodeSourcesFromList(sources: readonly string[]): NodeSourceList
|
|
|
24
24
|
throw new Error('nodeSources: at least one source is required')
|
|
25
25
|
}
|
|
26
26
|
const seen = new Set<string>()
|
|
27
|
-
|
|
27
|
+
const validated: NodeSource[] = []
|
|
28
|
+
for (const source of sources) {
|
|
28
29
|
if (!isNodeSource(source)) {
|
|
29
30
|
throw new Error(`nodeSources: invalid source "${source}"`)
|
|
30
31
|
}
|
|
31
32
|
if (seen.has(source)) throw new Error(`nodeSources: duplicate source "${source}"`)
|
|
32
33
|
seen.add(source)
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
validated.push(source)
|
|
35
|
+
}
|
|
36
|
+
const frozen = Object.freeze(validated)
|
|
37
|
+
if (isNodeSourceList(frozen)) return frozen
|
|
38
|
+
throw new Error('nodeSources: invalid list')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isNodeSourceList(sources: readonly NodeSource[]): sources is NodeSourceList {
|
|
42
|
+
return sources.length > 0 && new Set(sources).size === sources.length
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
/** Default: direct RPC node only. */
|
package/src/staking/contracts.ts
CHANGED
|
@@ -274,9 +274,7 @@ export const STAKING_CONTRACTS: Record<string, StakingContractConfig> = {
|
|
|
274
274
|
return typeof shares !== 'bigint' || shares >= 10n ** 9n
|
|
275
275
|
},
|
|
276
276
|
gasMultiplier: ({ mode }) => {
|
|
277
|
-
return
|
|
278
|
-
? new BigNumber(1.2)
|
|
279
|
-
: new BigNumber(1)
|
|
277
|
+
return mode === 'delegate' || mode === 'undelegate' ? new BigNumber(1.2) : new BigNumber(1)
|
|
280
278
|
},
|
|
281
279
|
},
|
|
282
280
|
somnia: {
|
|
@@ -19,18 +19,19 @@ const OP_MAP: Partial<Record<StakingOperation, EvmStakingOperationType>> = {
|
|
|
19
19
|
/**
|
|
20
20
|
* Checks if a string is a valid staking operation
|
|
21
21
|
*/
|
|
22
|
+
const STAKING_OPERATIONS = new Set<string>([
|
|
23
|
+
'delegate',
|
|
24
|
+
'undelegate',
|
|
25
|
+
'redelegate',
|
|
26
|
+
'withdraw',
|
|
27
|
+
'getStakedBalance',
|
|
28
|
+
'getUnstakedBalance',
|
|
29
|
+
'claimReward',
|
|
30
|
+
'compoundReward',
|
|
31
|
+
])
|
|
32
|
+
|
|
22
33
|
export function isStakingOperation(value: string): value is StakingOperation {
|
|
23
|
-
|
|
24
|
-
'delegate',
|
|
25
|
-
'undelegate',
|
|
26
|
-
'redelegate',
|
|
27
|
-
'withdraw',
|
|
28
|
-
'getStakedBalance',
|
|
29
|
-
'getUnstakedBalance',
|
|
30
|
-
'claimReward',
|
|
31
|
-
'compoundReward',
|
|
32
|
-
]
|
|
33
|
-
return stakingOperations.includes(value as StakingOperation)
|
|
34
|
+
return STAKING_OPERATIONS.has(value)
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
type SelectorEntry = {
|
|
@@ -67,8 +68,8 @@ const getStakingEntries = (currencyId: string): Map<string, SelectorEntry> | und
|
|
|
67
68
|
selectorsCache.set(currencyId, entries)
|
|
68
69
|
|
|
69
70
|
for (const [op, fn] of Object.entries(config.functions)) {
|
|
70
|
-
|
|
71
|
-
const mapped = OP_MAP[
|
|
71
|
+
if (!isStakingOperation(op)) continue
|
|
72
|
+
const mapped = OP_MAP[op]
|
|
72
73
|
if (!mapped || !fn) continue
|
|
73
74
|
|
|
74
75
|
try {
|
|
@@ -80,7 +81,7 @@ const getStakingEntries = (currencyId: string): Map<string, SelectorEntry> | und
|
|
|
80
81
|
const signature = `${fn}(${paramTypes})`
|
|
81
82
|
const selector = ethers.id(signature).slice(0, 10).toLowerCase()
|
|
82
83
|
entries.set(selector, {
|
|
83
|
-
resolveAddress: (to) => config.contractAddress({ mode:
|
|
84
|
+
resolveAddress: (to) => config.contractAddress({ mode: op, valAddress: to }),
|
|
84
85
|
opType: mapped,
|
|
85
86
|
})
|
|
86
87
|
} catch {
|
|
@@ -9,12 +9,31 @@ import seiProtocol from './sei'
|
|
|
9
9
|
import somniaProtocol from './somnia'
|
|
10
10
|
import zeroGravityProtocol from './zero_gravity'
|
|
11
11
|
|
|
12
|
-
const STAKING_PROTOCOLS
|
|
13
|
-
sei_evm: seiProtocol
|
|
14
|
-
celo: celoProtocol
|
|
15
|
-
monad: monadProtocol
|
|
16
|
-
zero_gravity: zeroGravityProtocol
|
|
17
|
-
somnia: somniaProtocol
|
|
12
|
+
const STAKING_PROTOCOLS = {
|
|
13
|
+
sei_evm: seiProtocol,
|
|
14
|
+
celo: celoProtocol,
|
|
15
|
+
monad: monadProtocol,
|
|
16
|
+
zero_gravity: zeroGravityProtocol,
|
|
17
|
+
somnia: somniaProtocol,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isStakingProtocol(value: object): value is StakingProtocol {
|
|
21
|
+
return Object.values(value).every((entry) => typeof entry === 'function')
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function stakingProtocolFor(currencyId: string): StakingProtocol | undefined {
|
|
25
|
+
switch (currencyId) {
|
|
26
|
+
case 'sei_evm':
|
|
27
|
+
case 'celo':
|
|
28
|
+
case 'monad':
|
|
29
|
+
case 'zero_gravity':
|
|
30
|
+
case 'somnia': {
|
|
31
|
+
const protocol = STAKING_PROTOCOLS[currencyId]
|
|
32
|
+
return isStakingProtocol(protocol) ? protocol : undefined
|
|
33
|
+
}
|
|
34
|
+
default:
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
18
37
|
}
|
|
19
38
|
|
|
20
39
|
const REQUIRES_VAL_ADDRESS = new Set(['celo', 'sei_evm', 'somnia'])
|
|
@@ -24,7 +43,7 @@ export const buildTransactionParams = (
|
|
|
24
43
|
transactionType: StakingOperation,
|
|
25
44
|
params: OperationParams
|
|
26
45
|
): Array<string | bigint> => {
|
|
27
|
-
const protocol =
|
|
46
|
+
const protocol = stakingProtocolFor(currencyId)
|
|
28
47
|
if (!protocol) {
|
|
29
48
|
throw new Error(`Unsupported staking currency: ${currencyId}`)
|
|
30
49
|
}
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
} from '@ledgerhq/coin-module-framework/api/index'
|
|
10
10
|
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
11
11
|
import { ethers } from 'ethers'
|
|
12
|
+
import { toInterfaceAbi } from '../abis'
|
|
12
13
|
import { isStakingIntent } from '../logic-public'
|
|
13
14
|
import { withApi } from '../network/node/rpc.common'
|
|
14
15
|
import { isExternalNodeConfig } from '../network/node/types'
|
|
@@ -84,7 +85,7 @@ const prepareZeroGravityIntent: IntentPreparer = async (config, currencyId, inte
|
|
|
84
85
|
const node = config.node
|
|
85
86
|
if (!isExternalNodeConfig(node)) return intent
|
|
86
87
|
|
|
87
|
-
const iface = new ethers.Interface(abi
|
|
88
|
+
const iface = new ethers.Interface(toInterfaceAbi(abi))
|
|
88
89
|
const valAddress = intent.valAddress
|
|
89
90
|
const delegator = intent.sender
|
|
90
91
|
|
|
@@ -7,6 +7,7 @@ import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
|
7
7
|
import network from '@ledgerhq/live-network'
|
|
8
8
|
import { BigNumber } from 'bignumber.js'
|
|
9
9
|
import { ethers } from 'ethers'
|
|
10
|
+
import { isRecord } from '../logic/predicates'
|
|
10
11
|
import { withApi } from '../network/node/rpc.common'
|
|
11
12
|
import { isExternalNodeConfig } from '../network/node/types'
|
|
12
13
|
import { getStakingABI } from './abis'
|
|
@@ -197,11 +198,6 @@ export async function fetchRedelegations(
|
|
|
197
198
|
|
|
198
199
|
// ─── Operation-derived redelegations ──────────────────────────────────────────
|
|
199
200
|
|
|
200
|
-
/** Type predicate: narrows `unknown` to a plain object record without a cast. */
|
|
201
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
202
|
-
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
201
|
/**
|
|
206
202
|
* Fetch raw EVM transaction calldata for a given tx hash directly via the
|
|
207
203
|
* chain's external RPC node. Returns `undefined` when the node is not
|
package/src/staking/utils.ts
CHANGED
|
@@ -3,27 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
import type { SeiDelegation } from '../types/staking'
|
|
5
5
|
import { safeBigInt } from '../logic-public'
|
|
6
|
-
|
|
7
|
-
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
8
|
-
value !== null && typeof value === 'object'
|
|
6
|
+
import { isBigInt, isRecord, isString } from '../logic/predicates'
|
|
9
7
|
|
|
10
8
|
export const isSeiDelegation = (candidate: unknown): candidate is SeiDelegation => {
|
|
11
9
|
// Plain object format: { balance: { amount, denom }, delegation: { delegator_address, validator_address, ... } }
|
|
12
|
-
if (isRecord(candidate)
|
|
10
|
+
if (isRecord(candidate)) {
|
|
13
11
|
const balance = candidate.balance
|
|
14
12
|
const delegation = candidate.delegation
|
|
15
13
|
return (
|
|
16
14
|
isRecord(balance) &&
|
|
17
|
-
!Array.isArray(balance) &&
|
|
18
15
|
'amount' in balance &&
|
|
19
16
|
'denom' in balance &&
|
|
20
|
-
|
|
17
|
+
isString(balance.denom) &&
|
|
21
18
|
isRecord(delegation) &&
|
|
22
|
-
!Array.isArray(delegation) &&
|
|
23
19
|
'delegator_address' in delegation &&
|
|
24
20
|
'validator_address' in delegation &&
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
isString(delegation.delegator_address) &&
|
|
22
|
+
isString(delegation.validator_address)
|
|
27
23
|
)
|
|
28
24
|
}
|
|
29
25
|
|
|
@@ -35,14 +31,14 @@ export const isSeiDelegation = (candidate: unknown): candidate is SeiDelegation
|
|
|
35
31
|
return (
|
|
36
32
|
Array.isArray(balance) &&
|
|
37
33
|
balance.length === 2 &&
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
isBigInt(balance[0]) && // amount
|
|
35
|
+
isString(balance[1]) && // denom
|
|
40
36
|
Array.isArray(delegation) &&
|
|
41
37
|
delegation.length === 4 &&
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
isString(delegation[0]) && // delegator_address
|
|
39
|
+
isBigInt(delegation[1]) && // shares
|
|
40
|
+
isBigInt(delegation[2]) && // decimals
|
|
41
|
+
isString(delegation[3]) // validator_address
|
|
46
42
|
)
|
|
47
43
|
}
|
|
48
44
|
|
|
@@ -93,26 +89,23 @@ export function parseDecimalIntegerPart(amount: string): bigint {
|
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
function normalizeSeiDelegation(outer: unknown): SeiDelegation | undefined {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const balanceTuple = Array.isArray(outer) ? outer[0] : outer.balance
|
|
99
|
-
if (!isRecord(balanceTuple)) return undefined
|
|
92
|
+
// ethers.Result is array-like: named fields are not visible through `in`, so index into it.
|
|
93
|
+
const balanceTuple = Array.isArray(outer) ? outer[0] : isRecord(outer) ? outer.balance : undefined
|
|
100
94
|
|
|
101
95
|
let amount: unknown
|
|
102
96
|
let denom: unknown
|
|
103
|
-
|
|
104
|
-
if ('amount' in balanceTuple && 'denom' in balanceTuple) {
|
|
105
|
-
amount = balanceTuple.amount
|
|
106
|
-
denom = balanceTuple.denom
|
|
107
|
-
} else if (Array.isArray(balanceTuple) && balanceTuple.length >= 2) {
|
|
97
|
+
if (Array.isArray(balanceTuple) && balanceTuple.length >= 2) {
|
|
108
98
|
amount = balanceTuple[0]
|
|
109
99
|
denom = balanceTuple[1]
|
|
100
|
+
} else if (isRecord(balanceTuple) && 'amount' in balanceTuple && 'denom' in balanceTuple) {
|
|
101
|
+
amount = balanceTuple.amount
|
|
102
|
+
denom = balanceTuple.denom
|
|
110
103
|
} else {
|
|
111
104
|
return undefined
|
|
112
105
|
}
|
|
113
106
|
|
|
114
|
-
if (
|
|
115
|
-
if (
|
|
107
|
+
if (!isString(denom)) return undefined
|
|
108
|
+
if (!isString(amount) && typeof amount !== 'number' && !isBigInt(amount)) {
|
|
116
109
|
return undefined
|
|
117
110
|
}
|
|
118
111
|
|
|
@@ -18,6 +18,7 @@ import type { JsonRpcProvider } from 'ethers'
|
|
|
18
18
|
import network from '@ledgerhq/live-network'
|
|
19
19
|
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
20
20
|
import { ethers } from 'ethers'
|
|
21
|
+
import { toInterfaceAbi } from '../../abis'
|
|
21
22
|
import { withApi } from '../../network/node/rpc.common'
|
|
22
23
|
import { isExternalNodeConfig } from '../../network/node/types'
|
|
23
24
|
import { getStakingABI } from '../abis'
|
|
@@ -54,6 +55,13 @@ type ValidatorInfo = { name: string }
|
|
|
54
55
|
* The resolved promise is cached, so a miss is not re-requested; only transient/non-404
|
|
55
56
|
* errors are rethrown so the cache evicts and a later call retries.
|
|
56
57
|
*/
|
|
58
|
+
function responseStatus(error: unknown): number | undefined {
|
|
59
|
+
if (typeof error !== 'object' || error === null || !('response' in error)) return undefined
|
|
60
|
+
const response = error.response
|
|
61
|
+
if (typeof response !== 'object' || response === null || !('status' in response)) return undefined
|
|
62
|
+
return typeof response.status === 'number' ? response.status : undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
const fetchValidatorName = async (
|
|
58
66
|
currencyId: string,
|
|
59
67
|
secp: string,
|
|
@@ -68,7 +76,7 @@ const fetchValidatorName = async (
|
|
|
68
76
|
typeof res?.data?.name === 'string' && res.data.name.trim().length > 0 ? res.data.name : null
|
|
69
77
|
return name
|
|
70
78
|
} catch (error) {
|
|
71
|
-
const status = (error
|
|
79
|
+
const status = responseStatus(error)
|
|
72
80
|
// A 404 just means this validator hasn't published info — cache the miss.
|
|
73
81
|
if (status === 404) return null
|
|
74
82
|
// Anything else is transient: log and rethrow so the cache doesn't pin a miss.
|
|
@@ -144,7 +152,7 @@ const resolveContext = (
|
|
|
144
152
|
|
|
145
153
|
try {
|
|
146
154
|
return {
|
|
147
|
-
abi: abi
|
|
155
|
+
abi: toInterfaceAbi(abi),
|
|
148
156
|
node,
|
|
149
157
|
contractAddress: config.contractAddress(),
|
|
150
158
|
}
|
|
@@ -402,7 +410,7 @@ export const extractMonadKnownValIds = (
|
|
|
402
410
|
const abi = getStakingABI(currencyId)
|
|
403
411
|
if (!abi) return []
|
|
404
412
|
|
|
405
|
-
const iface = new ethers.Interface(abi
|
|
413
|
+
const iface = new ethers.Interface(toInterfaceAbi(abi))
|
|
406
414
|
const valIds = new Set<string>()
|
|
407
415
|
|
|
408
416
|
for (const op of ops) {
|
|
@@ -5,6 +5,7 @@ import type { EvmConfigInfo } from '../../config'
|
|
|
5
5
|
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
6
6
|
import type { JsonRpcProvider } from 'ethers'
|
|
7
7
|
import { ethers } from 'ethers'
|
|
8
|
+
import { toInterfaceAbi } from '../../abis'
|
|
8
9
|
import { withApi } from '../../network/node/rpc.common'
|
|
9
10
|
import { isExternalNodeConfig } from '../../network/node/types'
|
|
10
11
|
import { getStakingABI } from '../abis'
|
|
@@ -68,7 +69,7 @@ export const getValidatorAddressById = async (
|
|
|
68
69
|
config,
|
|
69
70
|
currencyId,
|
|
70
71
|
async (provider) => {
|
|
71
|
-
const iface = new ethers.Interface(abi
|
|
72
|
+
const iface = new ethers.Interface(toInterfaceAbi(abi))
|
|
72
73
|
const decoded = await callGetValidator(provider, iface, MONAD_PRECOMPILE, valId)
|
|
73
74
|
if (!decoded) return null
|
|
74
75
|
const [, , , , , , , , , , secpPubkey] = decoded
|
|
@@ -11,6 +11,7 @@ import type { JsonRpcProvider } from 'ethers'
|
|
|
11
11
|
import network from '@ledgerhq/live-network'
|
|
12
12
|
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
13
13
|
import { ethers } from 'ethers'
|
|
14
|
+
import { toInterfaceAbi } from '../../abis'
|
|
14
15
|
import { withApi } from '../../network/node/rpc.common'
|
|
15
16
|
import { isExternalNodeConfig } from '../../network/node/types'
|
|
16
17
|
import { getStakingABI } from '../abis'
|
|
@@ -79,7 +80,7 @@ const resolveContext = (
|
|
|
79
80
|
|
|
80
81
|
try {
|
|
81
82
|
return {
|
|
82
|
-
abi: abi
|
|
83
|
+
abi: toInterfaceAbi(abi),
|
|
83
84
|
node,
|
|
84
85
|
contractAddress: config.contractAddress(),
|
|
85
86
|
}
|
|
@@ -145,7 +146,7 @@ const fetchValidatorDetails = async (
|
|
|
145
146
|
addresses: string[],
|
|
146
147
|
logger: Logger
|
|
147
148
|
): Promise<Validator[]> => {
|
|
148
|
-
const names = await validatorNamesCache(currencyId, logger).catch(() => ({})
|
|
149
|
+
const names = await validatorNamesCache(currencyId, logger).catch((): ValidatorNamesMap => ({}))
|
|
149
150
|
|
|
150
151
|
const items: Validator[] = []
|
|
151
152
|
|
|
@@ -327,7 +328,7 @@ export const fetchSomniaStakes = async (
|
|
|
327
328
|
// Display-name overlay, keyed by lowercased operator address. Best-effort: on failure
|
|
328
329
|
// the delegation still shows, falling back to the raw address as its name.
|
|
329
330
|
const names = await validatorNamesCache(currencyId, logger).catch(
|
|
330
|
-
() => ({})
|
|
331
|
+
(): ValidatorNamesMap => ({})
|
|
331
332
|
)
|
|
332
333
|
|
|
333
334
|
const asset: AssetInfo = {
|
|
@@ -10,6 +10,7 @@ import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
|
10
10
|
import type { JsonRpcProvider } from 'ethers'
|
|
11
11
|
import network from '@ledgerhq/live-network'
|
|
12
12
|
import { ethers } from 'ethers'
|
|
13
|
+
import { toInterfaceAbi } from '../../abis'
|
|
13
14
|
import { withApi } from '../../network/node/rpc.common'
|
|
14
15
|
import { isExternalNodeConfig } from '../../network/node/types'
|
|
15
16
|
import { getStakingABI } from '../abis'
|
|
@@ -241,7 +242,7 @@ export const fetchZeroGravityStakes = async (
|
|
|
241
242
|
evmConfig,
|
|
242
243
|
currencyId,
|
|
243
244
|
async (provider) => {
|
|
244
|
-
const iface = new ethers.Interface(abi
|
|
245
|
+
const iface = new ethers.Interface(toInterfaceAbi(abi))
|
|
245
246
|
const stakes: Stake[] = []
|
|
246
247
|
const currentBlock = BigInt(await provider.getBlockNumber())
|
|
247
248
|
|