@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.
Files changed (201) hide show
  1. package/.oxlintrc.json +2 -6
  2. package/CHANGELOG.md +12 -0
  3. package/lib/abis/index.d.ts +8 -0
  4. package/lib/abis/index.d.ts.map +1 -1
  5. package/lib/abis/index.js +30 -0
  6. package/lib/abis/index.js.map +1 -1
  7. package/lib/adapters/blockOperations.js +2 -2
  8. package/lib/adapters/blockOperations.js.map +1 -1
  9. package/lib/api/index.d.ts.map +1 -1
  10. package/lib/api/index.js +2 -1
  11. package/lib/api/index.js.map +1 -1
  12. package/lib/internalTxSources.d.ts.map +1 -1
  13. package/lib/internalTxSources.js +21 -3
  14. package/lib/internalTxSources.js.map +1 -1
  15. package/lib/logic/common.d.ts.map +1 -1
  16. package/lib/logic/common.js +11 -3
  17. package/lib/logic/common.js.map +1 -1
  18. package/lib/logic/craftTransaction.d.ts.map +1 -1
  19. package/lib/logic/craftTransaction.js +4 -1
  20. package/lib/logic/craftTransaction.js.map +1 -1
  21. package/lib/logic/estimateFees.d.ts.map +1 -1
  22. package/lib/logic/estimateFees.js +4 -1
  23. package/lib/logic/estimateFees.js.map +1 -1
  24. package/lib/logic/internalTransactionsFetcher.js +1 -1
  25. package/lib/logic/internalTransactionsFetcher.js.map +1 -1
  26. package/lib/logic/predicates.d.ts +17 -0
  27. package/lib/logic/predicates.d.ts.map +1 -0
  28. package/lib/logic/predicates.js +126 -0
  29. package/lib/logic/predicates.js.map +1 -0
  30. package/lib/network/explorer/types.d.ts.map +1 -1
  31. package/lib/network/explorer/types.js +11 -1
  32. package/lib/network/explorer/types.js.map +1 -1
  33. package/lib/network/gasTracker/ledger.d.ts.map +1 -1
  34. package/lib/network/gasTracker/ledger.js +1 -3
  35. package/lib/network/gasTracker/ledger.js.map +1 -1
  36. package/lib/network/node/explorerProxy.d.ts.map +1 -1
  37. package/lib/network/node/explorerProxy.js +10 -5
  38. package/lib/network/node/explorerProxy.js.map +1 -1
  39. package/lib/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
  40. package/lib/network/node/gethCallTracerToTraceBlockItems.js +10 -12
  41. package/lib/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
  42. package/lib/network/node/ledger.d.ts.map +1 -1
  43. package/lib/network/node/ledger.js +10 -5
  44. package/lib/network/node/ledger.js.map +1 -1
  45. package/lib/network/node/rpc.common.d.ts.map +1 -1
  46. package/lib/network/node/rpc.common.js +60 -70
  47. package/lib/network/node/rpc.common.js.map +1 -1
  48. package/lib/network/node/types.d.ts +6 -7
  49. package/lib/network/node/types.d.ts.map +1 -1
  50. package/lib/network/node/types.js +0 -27
  51. package/lib/network/node/types.js.map +1 -1
  52. package/lib/nodeSources.d.ts.map +1 -1
  53. package/lib/nodeSources.js +11 -3
  54. package/lib/nodeSources.js.map +1 -1
  55. package/lib/staking/contracts.d.ts.map +1 -1
  56. package/lib/staking/contracts.js +1 -3
  57. package/lib/staking/contracts.js.map +1 -1
  58. package/lib/staking/detectOperationType.d.ts +0 -3
  59. package/lib/staking/detectOperationType.d.ts.map +1 -1
  60. package/lib/staking/detectOperationType.js +15 -14
  61. package/lib/staking/detectOperationType.js.map +1 -1
  62. package/lib/staking/operations/index.d.ts.map +1 -1
  63. package/lib/staking/operations/index.js +18 -1
  64. package/lib/staking/operations/index.js.map +1 -1
  65. package/lib/staking/prepareIntents.d.ts.map +1 -1
  66. package/lib/staking/prepareIntents.js +4 -3
  67. package/lib/staking/prepareIntents.js.map +1 -1
  68. package/lib/staking/redelegations.d.ts.map +1 -1
  69. package/lib/staking/redelegations.js +4 -7
  70. package/lib/staking/redelegations.js.map +1 -1
  71. package/lib/staking/utils.d.ts.map +1 -1
  72. package/lib/staking/utils.js +22 -27
  73. package/lib/staking/utils.js.map +1 -1
  74. package/lib/staking/validators/monad.d.ts.map +1 -1
  75. package/lib/staking/validators/monad.js +15 -6
  76. package/lib/staking/validators/monad.js.map +1 -1
  77. package/lib/staking/validators/monadResolver.d.ts.map +1 -1
  78. package/lib/staking/validators/monadResolver.js +4 -3
  79. package/lib/staking/validators/monadResolver.js.map +1 -1
  80. package/lib/staking/validators/somnia.d.ts.map +1 -1
  81. package/lib/staking/validators/somnia.js +4 -3
  82. package/lib/staking/validators/somnia.js.map +1 -1
  83. package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
  84. package/lib/staking/validators/zero_gravity.js +4 -3
  85. package/lib/staking/validators/zero_gravity.js.map +1 -1
  86. package/lib-es/abis/index.d.ts +8 -0
  87. package/lib-es/abis/index.d.ts.map +1 -1
  88. package/lib-es/abis/index.js +29 -0
  89. package/lib-es/abis/index.js.map +1 -1
  90. package/lib-es/adapters/blockOperations.js +1 -1
  91. package/lib-es/adapters/blockOperations.js.map +1 -1
  92. package/lib-es/api/index.d.ts.map +1 -1
  93. package/lib-es/api/index.js +2 -1
  94. package/lib-es/api/index.js.map +1 -1
  95. package/lib-es/internalTxSources.d.ts.map +1 -1
  96. package/lib-es/internalTxSources.js +21 -3
  97. package/lib-es/internalTxSources.js.map +1 -1
  98. package/lib-es/logic/common.d.ts.map +1 -1
  99. package/lib-es/logic/common.js +11 -3
  100. package/lib-es/logic/common.js.map +1 -1
  101. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  102. package/lib-es/logic/craftTransaction.js +4 -1
  103. package/lib-es/logic/craftTransaction.js.map +1 -1
  104. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  105. package/lib-es/logic/estimateFees.js +4 -1
  106. package/lib-es/logic/estimateFees.js.map +1 -1
  107. package/lib-es/logic/internalTransactionsFetcher.js +1 -1
  108. package/lib-es/logic/internalTransactionsFetcher.js.map +1 -1
  109. package/lib-es/logic/predicates.d.ts +17 -0
  110. package/lib-es/logic/predicates.d.ts.map +1 -0
  111. package/lib-es/logic/predicates.js +114 -0
  112. package/lib-es/logic/predicates.js.map +1 -0
  113. package/lib-es/network/explorer/types.d.ts.map +1 -1
  114. package/lib-es/network/explorer/types.js +11 -1
  115. package/lib-es/network/explorer/types.js.map +1 -1
  116. package/lib-es/network/gasTracker/ledger.d.ts.map +1 -1
  117. package/lib-es/network/gasTracker/ledger.js +1 -3
  118. package/lib-es/network/gasTracker/ledger.js.map +1 -1
  119. package/lib-es/network/node/explorerProxy.d.ts.map +1 -1
  120. package/lib-es/network/node/explorerProxy.js +10 -5
  121. package/lib-es/network/node/explorerProxy.js.map +1 -1
  122. package/lib-es/network/node/gethCallTracerToTraceBlockItems.d.ts.map +1 -1
  123. package/lib-es/network/node/gethCallTracerToTraceBlockItems.js +4 -6
  124. package/lib-es/network/node/gethCallTracerToTraceBlockItems.js.map +1 -1
  125. package/lib-es/network/node/ledger.d.ts.map +1 -1
  126. package/lib-es/network/node/ledger.js +10 -5
  127. package/lib-es/network/node/ledger.js.map +1 -1
  128. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  129. package/lib-es/network/node/rpc.common.js +58 -68
  130. package/lib-es/network/node/rpc.common.js.map +1 -1
  131. package/lib-es/network/node/types.d.ts +6 -7
  132. package/lib-es/network/node/types.d.ts.map +1 -1
  133. package/lib-es/network/node/types.js +0 -25
  134. package/lib-es/network/node/types.js.map +1 -1
  135. package/lib-es/nodeSources.d.ts.map +1 -1
  136. package/lib-es/nodeSources.js +11 -3
  137. package/lib-es/nodeSources.js.map +1 -1
  138. package/lib-es/staking/contracts.d.ts.map +1 -1
  139. package/lib-es/staking/contracts.js +1 -3
  140. package/lib-es/staking/contracts.js.map +1 -1
  141. package/lib-es/staking/detectOperationType.d.ts +0 -3
  142. package/lib-es/staking/detectOperationType.d.ts.map +1 -1
  143. package/lib-es/staking/detectOperationType.js +15 -14
  144. package/lib-es/staking/detectOperationType.js.map +1 -1
  145. package/lib-es/staking/operations/index.d.ts.map +1 -1
  146. package/lib-es/staking/operations/index.js +18 -1
  147. package/lib-es/staking/operations/index.js.map +1 -1
  148. package/lib-es/staking/prepareIntents.d.ts.map +1 -1
  149. package/lib-es/staking/prepareIntents.js +2 -1
  150. package/lib-es/staking/prepareIntents.js.map +1 -1
  151. package/lib-es/staking/redelegations.d.ts.map +1 -1
  152. package/lib-es/staking/redelegations.js +1 -4
  153. package/lib-es/staking/redelegations.js.map +1 -1
  154. package/lib-es/staking/utils.d.ts.map +1 -1
  155. package/lib-es/staking/utils.js +20 -25
  156. package/lib-es/staking/utils.js.map +1 -1
  157. package/lib-es/staking/validators/monad.d.ts.map +1 -1
  158. package/lib-es/staking/validators/monad.js +12 -3
  159. package/lib-es/staking/validators/monad.js.map +1 -1
  160. package/lib-es/staking/validators/monadResolver.d.ts.map +1 -1
  161. package/lib-es/staking/validators/monadResolver.js +2 -1
  162. package/lib-es/staking/validators/monadResolver.js.map +1 -1
  163. package/lib-es/staking/validators/somnia.d.ts.map +1 -1
  164. package/lib-es/staking/validators/somnia.js +2 -1
  165. package/lib-es/staking/validators/somnia.js.map +1 -1
  166. package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
  167. package/lib-es/staking/validators/zero_gravity.js +2 -1
  168. package/lib-es/staking/validators/zero_gravity.js.map +1 -1
  169. package/package.json +2 -2
  170. package/src/abis/index.test.ts +36 -0
  171. package/src/abis/index.ts +30 -0
  172. package/src/adapters/blockOperations.ts +1 -1
  173. package/src/api/index.ts +3 -2
  174. package/src/internalTxSources.ts +20 -3
  175. package/src/logic/common.ts +13 -3
  176. package/src/logic/craftTransaction.ts +4 -2
  177. package/src/logic/estimateFees.ts +4 -2
  178. package/src/logic/internalTransactionsFetcher.ts +1 -1
  179. package/src/logic/predicates.ts +124 -0
  180. package/src/logic/tests/validateIntent.test.ts +4 -1
  181. package/src/network/explorer/ledger.test.ts +21 -15
  182. package/src/network/explorer/types.ts +12 -3
  183. package/src/network/gasTracker/ledger.ts +1 -4
  184. package/src/network/node/explorerProxy.ts +11 -8
  185. package/src/network/node/gethCallTracerToTraceBlockItems.test.ts +1 -1
  186. package/src/network/node/gethCallTracerToTraceBlockItems.ts +6 -9
  187. package/src/network/node/ledger.ts +14 -10
  188. package/src/network/node/rpc.common.ts +92 -88
  189. package/src/network/node/rpc.test.ts +119 -0
  190. package/src/network/node/types.ts +6 -35
  191. package/src/nodeSources.ts +11 -3
  192. package/src/staking/contracts.ts +1 -3
  193. package/src/staking/detectOperationType.ts +15 -14
  194. package/src/staking/operations/index.ts +26 -7
  195. package/src/staking/prepareIntents.ts +2 -1
  196. package/src/staking/redelegations.ts +1 -5
  197. package/src/staking/utils.ts +19 -26
  198. package/src/staking/validators/monad.ts +11 -3
  199. package/src/staking/validators/monadResolver.ts +2 -1
  200. package/src/staking/validators/somnia.ts +4 -3
  201. 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
- effectiveGasPrice?: string
120
- gasPrice?: string
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
  /**
@@ -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
- sources.forEach((source) => {
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
- return Object.freeze([...sources]) as unknown as NodeSourceList
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. */
@@ -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 (['delegate', 'undelegate'] as const).includes(mode as 'delegate' | 'undelegate')
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
- const stakingOperations: ReadonlyArray<StakingOperation> = [
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
- const operation = op as StakingOperation
71
- const mapped = OP_MAP[operation]
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: operation, valAddress: to }),
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: Record<string, StakingProtocol> = {
13
- sei_evm: seiProtocol as StakingProtocol,
14
- celo: celoProtocol as StakingProtocol,
15
- monad: monadProtocol as StakingProtocol,
16
- zero_gravity: zeroGravityProtocol as StakingProtocol,
17
- somnia: somniaProtocol as StakingProtocol,
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 = STAKING_PROTOCOLS[currencyId]
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 as ethers.InterfaceAbi)
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
@@ -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) && !Array.isArray(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
- typeof balance.denom === 'string' &&
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
- typeof delegation.delegator_address === 'string' &&
26
- typeof delegation.validator_address === 'string'
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
- typeof balance[0] === 'bigint' && // amount
39
- typeof balance[1] === 'string' && // denom
34
+ isBigInt(balance[0]) && // amount
35
+ isString(balance[1]) && // denom
40
36
  Array.isArray(delegation) &&
41
37
  delegation.length === 4 &&
42
- typeof delegation[0] === 'string' && // delegator_address
43
- typeof delegation[1] === 'bigint' && // shares
44
- typeof delegation[2] === 'bigint' && // decimals
45
- typeof delegation[3] === 'string' // validator_address
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
- if (!isRecord(outer)) return undefined
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 (typeof denom !== 'string') return undefined
115
- if (typeof amount !== 'string' && typeof amount !== 'number' && typeof amount !== 'bigint') {
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 as { response?: { status?: number } })?.response?.status
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 as ethers.InterfaceAbi,
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 as ethers.InterfaceAbi)
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 as ethers.InterfaceAbi)
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 as ethers.InterfaceAbi,
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(() => ({}) as ValidatorNamesMap)
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
- () => ({}) as ValidatorNamesMap
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 as ethers.InterfaceAbi)
245
+ const iface = new ethers.Interface(toInterfaceAbi(abi))
245
246
  const stakes: Stake[] = []
246
247
  const currentBlock = BigInt(await provider.getBlockNumber())
247
248