viem 2.57.4 → 2.57.5

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 (223) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/_cjs/actions/public/waitForTransactionReceipt.js +5 -2
  3. package/_cjs/actions/public/waitForTransactionReceipt.js.map +1 -1
  4. package/_cjs/actions/wallet/waitForCallsStatus.js +25 -2
  5. package/_cjs/actions/wallet/waitForCallsStatus.js.map +1 -1
  6. package/_cjs/chains/definitions/arcTestnet.js +11 -8
  7. package/_cjs/chains/definitions/arcTestnet.js.map +1 -1
  8. package/_cjs/chains/definitions/qmsTestnet.js +30 -0
  9. package/_cjs/chains/definitions/qmsTestnet.js.map +1 -0
  10. package/_cjs/chains/definitions/tempo.js +1 -1
  11. package/_cjs/chains/definitions/tempoModerato.js +2 -2
  12. package/_cjs/chains/index.js +7 -5
  13. package/_cjs/chains/index.js.map +1 -1
  14. package/_cjs/clients/transports/ipc.js +19 -10
  15. package/_cjs/clients/transports/ipc.js.map +1 -1
  16. package/_cjs/clients/transports/webSocket.js +19 -10
  17. package/_cjs/clients/transports/webSocket.js.map +1 -1
  18. package/_cjs/errors/version.js +1 -1
  19. package/_cjs/tempo/Account.js +40 -40
  20. package/_cjs/tempo/Account.js.map +1 -1
  21. package/_cjs/tempo/Decorator.js +9 -8
  22. package/_cjs/tempo/Decorator.js.map +1 -1
  23. package/_cjs/tempo/ExecutionError.js +1 -1
  24. package/_cjs/tempo/ExecutionError.js.map +1 -1
  25. package/_cjs/tempo/Formatters.js +8 -7
  26. package/_cjs/tempo/Formatters.js.map +1 -1
  27. package/_cjs/tempo/KeyAuthorizationManager.js +25 -16
  28. package/_cjs/tempo/KeyAuthorizationManager.js.map +1 -1
  29. package/_cjs/tempo/Relay.js +9 -4
  30. package/_cjs/tempo/Relay.js.map +1 -1
  31. package/_cjs/tempo/Transaction.js +9 -9
  32. package/_cjs/tempo/Transaction.js.map +1 -1
  33. package/_cjs/tempo/Transport.js +21 -11
  34. package/_cjs/tempo/Transport.js.map +1 -1
  35. package/_cjs/tempo/{multisig → accounts}/Config.js +8 -8
  36. package/_cjs/tempo/{multisig → accounts}/Config.js.map +1 -1
  37. package/_cjs/tempo/{multisig → accounts}/Operation.js +10 -10
  38. package/_cjs/tempo/{multisig → accounts}/Operation.js.map +1 -1
  39. package/_cjs/tempo/{multisig → accounts}/Signature.js +2 -2
  40. package/_cjs/tempo/accounts/Signature.js.map +1 -0
  41. package/_cjs/tempo/actions/accessKey.js +60 -37
  42. package/_cjs/tempo/actions/accessKey.js.map +1 -1
  43. package/_cjs/tempo/actions/{multisig.js → accounts.js} +13 -18
  44. package/_cjs/tempo/actions/accounts.js.map +1 -0
  45. package/_cjs/tempo/actions/index.js +2 -2
  46. package/_cjs/tempo/actions/index.js.map +1 -1
  47. package/_cjs/tempo/chainConfig.js +37 -37
  48. package/_cjs/tempo/chainConfig.js.map +1 -1
  49. package/_cjs/tempo/index.js +3 -3
  50. package/_cjs/tempo/index.js.map +1 -1
  51. package/_cjs/tempo/internal/relay/{multisig.js → accounts.js} +90 -93
  52. package/_cjs/tempo/internal/relay/accounts.js.map +1 -0
  53. package/_cjs/tempo/internal/relay/keyAuthorization.js +296 -0
  54. package/_cjs/tempo/internal/relay/keyAuthorization.js.map +1 -0
  55. package/_cjs/tempo/internal/relay/plugin.js +17 -7
  56. package/_cjs/tempo/internal/relay/plugin.js.map +1 -1
  57. package/_cjs/utils/hash/normalizeSignature.js +1 -1
  58. package/_cjs/utils/hash/normalizeSignature.js.map +1 -1
  59. package/_cjs/utils/rpc/http.js +66 -31
  60. package/_cjs/utils/rpc/http.js.map +1 -1
  61. package/_cjs/utils/rpc/socket.js +1 -1
  62. package/_cjs/utils/rpc/socket.js.map +1 -1
  63. package/_esm/actions/public/waitForTransactionReceipt.js +5 -2
  64. package/_esm/actions/public/waitForTransactionReceipt.js.map +1 -1
  65. package/_esm/actions/wallet/waitForCallsStatus.js +39 -2
  66. package/_esm/actions/wallet/waitForCallsStatus.js.map +1 -1
  67. package/_esm/chains/definitions/arcTestnet.js +11 -8
  68. package/_esm/chains/definitions/arcTestnet.js.map +1 -1
  69. package/_esm/chains/definitions/qmsTestnet.js +27 -0
  70. package/_esm/chains/definitions/qmsTestnet.js.map +1 -0
  71. package/_esm/chains/definitions/tempo.js +1 -1
  72. package/_esm/chains/definitions/tempoModerato.js +2 -2
  73. package/_esm/chains/index.js +1 -0
  74. package/_esm/chains/index.js.map +1 -1
  75. package/_esm/clients/transports/ipc.js +21 -10
  76. package/_esm/clients/transports/ipc.js.map +1 -1
  77. package/_esm/clients/transports/webSocket.js +21 -10
  78. package/_esm/clients/transports/webSocket.js.map +1 -1
  79. package/_esm/errors/version.js +1 -1
  80. package/_esm/tempo/Account.js +42 -42
  81. package/_esm/tempo/Account.js.map +1 -1
  82. package/_esm/tempo/Client.js +3 -3
  83. package/_esm/tempo/Decorator.js +9 -8
  84. package/_esm/tempo/Decorator.js.map +1 -1
  85. package/_esm/tempo/ExecutionError.js +1 -1
  86. package/_esm/tempo/ExecutionError.js.map +1 -1
  87. package/_esm/tempo/Formatters.js +11 -10
  88. package/_esm/tempo/Formatters.js.map +1 -1
  89. package/_esm/tempo/KeyAuthorizationManager.js +58 -16
  90. package/_esm/tempo/KeyAuthorizationManager.js.map +1 -1
  91. package/_esm/tempo/Relay.js +49 -8
  92. package/_esm/tempo/Relay.js.map +1 -1
  93. package/_esm/tempo/Transaction.js +11 -11
  94. package/_esm/tempo/Transaction.js.map +1 -1
  95. package/_esm/tempo/Transport.js +22 -12
  96. package/_esm/tempo/Transport.js.map +1 -1
  97. package/_esm/tempo/{multisig → accounts}/Config.js +14 -14
  98. package/_esm/tempo/{multisig → accounts}/Config.js.map +1 -1
  99. package/_esm/tempo/{multisig → accounts}/Operation.js +17 -17
  100. package/_esm/tempo/{multisig → accounts}/Operation.js.map +1 -1
  101. package/_esm/tempo/accounts/Signature.js +9 -0
  102. package/_esm/tempo/accounts/Signature.js.map +1 -0
  103. package/_esm/tempo/actions/accessKey.js +93 -38
  104. package/_esm/tempo/actions/accessKey.js.map +1 -1
  105. package/_esm/tempo/actions/{multisig.js → accounts.js} +31 -36
  106. package/_esm/tempo/actions/accounts.js.map +1 -0
  107. package/_esm/tempo/actions/index.js +1 -1
  108. package/_esm/tempo/actions/index.js.map +1 -1
  109. package/_esm/tempo/chainConfig.js +38 -38
  110. package/_esm/tempo/chainConfig.js.map +1 -1
  111. package/_esm/tempo/index.js +2 -1
  112. package/_esm/tempo/index.js.map +1 -1
  113. package/_esm/tempo/internal/relay/{multisig.js → accounts.js} +93 -98
  114. package/_esm/tempo/internal/relay/accounts.js.map +1 -0
  115. package/_esm/tempo/internal/relay/feePayer.js +1 -1
  116. package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
  117. package/_esm/tempo/internal/relay/keyAuthorization.js +334 -0
  118. package/_esm/tempo/internal/relay/keyAuthorization.js.map +1 -0
  119. package/_esm/tempo/internal/relay/plugin.js +15 -6
  120. package/_esm/tempo/internal/relay/plugin.js.map +1 -1
  121. package/_esm/utils/hash/normalizeSignature.js +3 -2
  122. package/_esm/utils/hash/normalizeSignature.js.map +1 -1
  123. package/_esm/utils/rpc/http.js +74 -31
  124. package/_esm/utils/rpc/http.js.map +1 -1
  125. package/_esm/utils/rpc/socket.js +3 -1
  126. package/_esm/utils/rpc/socket.js.map +1 -1
  127. package/_types/actions/public/waitForTransactionReceipt.d.ts.map +1 -1
  128. package/_types/actions/wallet/waitForCallsStatus.d.ts.map +1 -1
  129. package/_types/chains/definitions/arcTestnet.d.ts +5 -5
  130. package/_types/chains/definitions/arcTestnet.d.ts.map +1 -1
  131. package/_types/chains/definitions/qmsTestnet.d.ts +50 -0
  132. package/_types/chains/definitions/qmsTestnet.d.ts.map +1 -0
  133. package/_types/chains/definitions/tempo.d.ts +2 -2
  134. package/_types/chains/definitions/tempoModerato.d.ts +4 -4
  135. package/_types/chains/index.d.ts +1 -0
  136. package/_types/chains/index.d.ts.map +1 -1
  137. package/_types/clients/transports/ipc.d.ts.map +1 -1
  138. package/_types/clients/transports/webSocket.d.ts.map +1 -1
  139. package/_types/errors/version.d.ts +1 -1
  140. package/_types/tempo/Account.d.ts +28 -28
  141. package/_types/tempo/Account.d.ts.map +1 -1
  142. package/_types/tempo/Client.d.ts +3 -3
  143. package/_types/tempo/Decorator.d.ts +63 -37
  144. package/_types/tempo/Decorator.d.ts.map +1 -1
  145. package/_types/tempo/Formatters.d.ts.map +1 -1
  146. package/_types/tempo/KeyAuthorizationManager.d.ts +45 -2
  147. package/_types/tempo/KeyAuthorizationManager.d.ts.map +1 -1
  148. package/_types/tempo/Relay.d.ts +62 -12
  149. package/_types/tempo/Relay.d.ts.map +1 -1
  150. package/_types/tempo/Transaction.d.ts +14 -11
  151. package/_types/tempo/Transaction.d.ts.map +1 -1
  152. package/_types/tempo/Transport.d.ts +20 -7
  153. package/_types/tempo/Transport.d.ts.map +1 -1
  154. package/_types/tempo/{multisig → accounts}/Config.d.ts +7 -7
  155. package/_types/tempo/accounts/Config.d.ts.map +1 -0
  156. package/_types/tempo/{multisig → accounts}/Operation.d.ts +7 -7
  157. package/_types/tempo/accounts/Operation.d.ts.map +1 -0
  158. package/_types/tempo/{multisig → accounts}/Signature.d.ts +1 -1
  159. package/_types/tempo/accounts/Signature.d.ts.map +1 -0
  160. package/_types/tempo/actions/accessKey.d.ts +59 -17
  161. package/_types/tempo/actions/accessKey.d.ts.map +1 -1
  162. package/_types/tempo/actions/{multisig.d.ts → accounts.d.ts} +28 -28
  163. package/_types/tempo/actions/{multisig.d.ts.map → accounts.d.ts.map} +1 -1
  164. package/_types/tempo/actions/index.d.ts +1 -1
  165. package/_types/tempo/actions/index.d.ts.map +1 -1
  166. package/_types/tempo/index.d.ts +3 -2
  167. package/_types/tempo/index.d.ts.map +1 -1
  168. package/_types/tempo/internal/relay/accounts.d.ts +15 -0
  169. package/_types/tempo/internal/relay/accounts.d.ts.map +1 -0
  170. package/_types/tempo/internal/relay/keyAuthorization.d.ts +25 -0
  171. package/_types/tempo/internal/relay/keyAuthorization.d.ts.map +1 -0
  172. package/_types/tempo/internal/relay/plugin.d.ts +6 -3
  173. package/_types/tempo/internal/relay/plugin.d.ts.map +1 -1
  174. package/_types/utils/hash/normalizeSignature.d.ts.map +1 -1
  175. package/_types/utils/rpc/http.d.ts.map +1 -1
  176. package/_types/utils/rpc/socket.d.ts.map +1 -1
  177. package/actions/public/waitForTransactionReceipt.ts +8 -2
  178. package/actions/wallet/waitForCallsStatus.ts +41 -2
  179. package/chains/definitions/arcTestnet.ts +11 -8
  180. package/chains/definitions/qmsTestnet.ts +27 -0
  181. package/chains/definitions/tempo.ts +1 -1
  182. package/chains/definitions/tempoModerato.ts +2 -2
  183. package/chains/index.ts +1 -0
  184. package/clients/transports/ipc.ts +38 -29
  185. package/clients/transports/webSocket.ts +42 -33
  186. package/errors/version.ts +1 -1
  187. package/package.json +2 -2
  188. package/tempo/Account.ts +95 -84
  189. package/tempo/Client.ts +3 -3
  190. package/tempo/Decorator.ts +86 -57
  191. package/tempo/ExecutionError.ts +1 -1
  192. package/tempo/Formatters.ts +14 -13
  193. package/tempo/KeyAuthorizationManager.ts +71 -19
  194. package/tempo/Relay.ts +70 -14
  195. package/tempo/Transaction.ts +31 -23
  196. package/tempo/Transport.ts +49 -21
  197. package/tempo/{multisig → accounts}/Config.ts +21 -21
  198. package/tempo/{multisig → accounts}/Operation.ts +26 -26
  199. package/tempo/{multisig → accounts}/Signature.ts +5 -3
  200. package/tempo/actions/accessKey.ts +179 -79
  201. package/tempo/actions/{multisig.ts → accounts.ts} +47 -56
  202. package/tempo/actions/index.ts +1 -1
  203. package/tempo/chainConfig.ts +52 -52
  204. package/tempo/index.ts +5 -4
  205. package/tempo/internal/relay/{multisig.ts → accounts.ts} +118 -118
  206. package/tempo/internal/relay/feePayer.ts +1 -1
  207. package/tempo/internal/relay/keyAuthorization.ts +415 -0
  208. package/tempo/internal/relay/plugin.ts +20 -7
  209. package/utils/hash/normalizeSignature.ts +3 -2
  210. package/utils/rpc/http.ts +76 -30
  211. package/utils/rpc/socket.ts +3 -1
  212. package/_cjs/tempo/actions/multisig.js.map +0 -1
  213. package/_cjs/tempo/internal/relay/multisig.js.map +0 -1
  214. package/_cjs/tempo/multisig/Signature.js.map +0 -1
  215. package/_esm/tempo/actions/multisig.js.map +0 -1
  216. package/_esm/tempo/internal/relay/multisig.js.map +0 -1
  217. package/_esm/tempo/multisig/Signature.js +0 -9
  218. package/_esm/tempo/multisig/Signature.js.map +0 -1
  219. package/_types/tempo/internal/relay/multisig.d.ts +0 -4
  220. package/_types/tempo/internal/relay/multisig.d.ts.map +0 -1
  221. package/_types/tempo/multisig/Config.d.ts.map +0 -1
  222. package/_types/tempo/multisig/Operation.d.ts.map +0 -1
  223. package/_types/tempo/multisig/Signature.d.ts.map +0 -1
@@ -11,6 +11,7 @@ import type { ErrorType } from '../../errors/utils.js'
11
11
  import type { Chain } from '../../types/chain.js'
12
12
  import type { Hash } from '../../types/misc.js'
13
13
  import type { Transaction } from '../../types/transaction.js'
14
+ import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
14
15
  import { getAction } from '../../utils/getAction.js'
15
16
  import { type ObserveErrorType, observe } from '../../utils/observe.js'
16
17
  import { withResolvers } from '../../utils/promise/withResolvers.js'
@@ -329,7 +330,7 @@ export async function waitForTransactionReceipt<
329
330
  block.transactions as {} as Transaction[]
330
331
  ).find(
331
332
  ({ from, hash, nonce }) =>
332
- from === replacedTransaction!.from &&
333
+ isAddressEqual(from, replacedTransaction!.from) &&
333
334
  hash !== replacedTransaction!.hash &&
334
335
  nonce === replacedTransaction!.nonce,
335
336
  )
@@ -356,7 +357,12 @@ export async function waitForTransactionReceipt<
356
357
 
357
358
  let reason: ReplacementReason = 'replaced'
358
359
  if (
359
- replacementTransaction.to === replacedTransaction.to &&
360
+ (replacementTransaction.to && replacedTransaction.to
361
+ ? isAddressEqual(
362
+ replacementTransaction.to,
363
+ replacedTransaction.to,
364
+ )
365
+ : replacementTransaction.to === replacedTransaction.to) &&
360
366
  replacementTransaction.value === replacedTransaction.value &&
361
367
  replacementTransaction.input === replacedTransaction.input
362
368
  ) {
@@ -69,6 +69,17 @@ export type WaitForCallsStatusErrorType =
69
69
  | WaitForCallsStatusTimeoutError
70
70
  | ErrorType
71
71
 
72
+ const functionIds = /*#__PURE__*/ new WeakMap<object, number>()
73
+ let functionCount = 0
74
+ function getFunctionId(fn: object): number {
75
+ let fnId = functionIds.get(fn)
76
+ if (fnId === undefined) {
77
+ fnId = ++functionCount
78
+ functionIds.set(fn, fnId)
79
+ }
80
+ return fnId
81
+ }
82
+
72
83
  /**
73
84
  * Waits for the status & receipts of a call bundle that was sent via `sendCalls`.
74
85
  *
@@ -104,7 +115,31 @@ export async function waitForCallsStatus<chain extends Chain | undefined>(
104
115
  timeout = 60_000,
105
116
  throwOnFailure = false,
106
117
  } = parameters
107
- const observerId = stringify(['waitForCallsStatus', client.uid, id])
118
+ const observerId = stringify([
119
+ 'waitForCallsStatus',
120
+ client.uid,
121
+ id,
122
+ // Concurrent calls with different behavior-defining options must not
123
+ // share an observer: the first call's polling closure decides the
124
+ // status check, failure handling and retry behavior for everyone.
125
+ // `timeout` is enforced per caller below, so it is not included.
126
+ {
127
+ pollingInterval,
128
+ retryCount,
129
+ // Caller-provided functions are keyed by identity, not source text:
130
+ // two predicates built by the same factory have identical source
131
+ // but capture different values, so they must not share an observer.
132
+ // Keying on `parameters.*` (not the destructured defaults) keeps
133
+ // calls that use the defaults on one shared observer, since the
134
+ // default functions are recreated on every call.
135
+ retryDelay:
136
+ typeof parameters.retryDelay === 'function'
137
+ ? ['function', getFunctionId(parameters.retryDelay)]
138
+ : parameters.retryDelay,
139
+ status: parameters.status ? getFunctionId(parameters.status) : undefined,
140
+ throwOnFailure,
141
+ },
142
+ ])
108
143
 
109
144
  const { promise, resolve, reject } =
110
145
  withResolvers<WaitForCallsStatusReturnType>()
@@ -161,7 +196,11 @@ export async function waitForCallsStatus<chain extends Chain | undefined>(
161
196
  }, timeout)
162
197
  : undefined
163
198
 
164
- return await promise
199
+ // Remove this caller's listener once its promise settles. `done` only
200
+ // unobserves the caller that started the poll, so a listener from a
201
+ // concurrent caller would otherwise stay cached and block every later
202
+ // wait for the same id from polling.
203
+ return await promise.finally(() => unobserve())
165
204
  }
166
205
 
167
206
  export type WaitForCallsStatusTimeoutErrorType =
@@ -11,21 +11,24 @@ export const arcTestnet = /*#__PURE__*/ defineChain({
11
11
  rpcUrls: {
12
12
  default: {
13
13
  http: [
14
- 'https://rpc.testnet.arc.network',
15
- 'https://rpc.quicknode.testnet.arc.network',
16
- 'https://rpc.blockdaemon.testnet.arc.network',
14
+ 'https://rpc.testnet.arc.io',
15
+ 'https://rpc.blockdaemon.testnet.arc.io',
16
+ 'https://rpc.drpc.testnet.arc.io',
17
+ 'https://rpc.quicknode.testnet.arc.io',
17
18
  ],
18
19
  webSocket: [
19
- 'wss://rpc.testnet.arc.network',
20
- 'wss://rpc.quicknode.testnet.arc.network',
20
+ 'wss://rpc.testnet.arc.io',
21
+ 'wss://rpc.blockdaemon.testnet.arc.io:443/websocket',
22
+ 'wss://rpc.drpc.testnet.arc.io',
23
+ 'wss://rpc.quicknode.testnet.arc.io',
21
24
  ],
22
25
  },
23
26
  },
24
27
  blockExplorers: {
25
28
  default: {
26
- name: 'ArcScan',
27
- url: 'https://testnet.arcscan.app',
28
- apiUrl: 'https://testnet.arcscan.app/api',
29
+ name: 'Arc Explorer',
30
+ url: 'https://explorer.testnet.arc.io',
31
+ apiUrl: 'https://explorer.testnet.arc.io/api',
29
32
  },
30
33
  },
31
34
  contracts: {
@@ -0,0 +1,27 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const qmsTestnet = /*#__PURE__*/ defineChain({
4
+ id: 19480,
5
+ name: 'QMS Testnet',
6
+ nativeCurrency: { name: 'QMS', symbol: 'QMS', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://rpc.testnet.qms.finance'],
10
+ webSocket: ['wss://rpc.testnet.qms.finance'],
11
+ },
12
+ },
13
+ blockExplorers: {
14
+ default: {
15
+ name: 'QMS Testnet Explorer',
16
+ url: 'https://testnet.qmsscan.io',
17
+ apiUrl: 'https://testnet.qmsscan.io/api',
18
+ },
19
+ },
20
+ contracts: {
21
+ multicall3: {
22
+ address: '0xcA11bde05977b3631167028862bE2a173976CA11',
23
+ blockCreated: 0,
24
+ },
25
+ },
26
+ testnet: true,
27
+ })
@@ -12,7 +12,7 @@ export const tempo = /*#__PURE__*/ defineChain({
12
12
  },
13
13
  contracts: {
14
14
  earnFactory: {
15
- address: '0xb5889A96114014d4C032ebD76772c10bF3b97137',
15
+ address: '0x3085A8003f340CD51C72D9e1a1298CDafB171B02',
16
16
  },
17
17
  erc4626EngineFactory: {
18
18
  address: '0xd43D00981222a8db444A528E69f19E3cE5A7D2Ff',
@@ -13,10 +13,10 @@ export const tempoModerato = /*#__PURE__*/ defineChain({
13
13
  },
14
14
  contracts: {
15
15
  earnFactory: {
16
- address: '0xb5889A96114014d4C032ebD76772c10bF3b97137',
16
+ address: '0x1de6B233984583F4d936ae4265f3b60282b70cc6',
17
17
  },
18
18
  erc4626EngineFactory: {
19
- address: '0xd43D00981222a8db444A528E69f19E3cE5A7D2Ff',
19
+ address: '0x0d57c10249eb3a92b7d81bBA6221F80F2865448A',
20
20
  },
21
21
  },
22
22
  name: 'Tempo Testnet (Moderato)',
package/chains/index.ts CHANGED
@@ -519,6 +519,7 @@ export { pumpfiTestnet } from './definitions/pumpfiTestnet.js'
519
519
  export { pyrope } from './definitions/pyrope.js'
520
520
  export { ql1 } from './definitions/ql1.js'
521
521
  export { qMainnet } from './definitions/qMainnet.js'
522
+ export { qmsTestnet } from './definitions/qmsTestnet.js'
522
523
  export { qTestnet } from './definitions/qTestnet.js'
523
524
  export { quai } from './definitions/quai.js'
524
525
  export { quaiTestnet } from './definitions/quaiTestnet.js'
@@ -133,42 +133,51 @@ export function ipc(
133
133
  },
134
134
  async subscribe({ params, onData, onError }: any) {
135
135
  const rpcClient = await getIpcRpcClient(path)
136
- const { result: subscriptionId } = await new Promise<any>(
137
- (resolve, reject) =>
136
+ // Updated when the subscription is re-established after a reconnect.
137
+ let subscriptionId: Hash
138
+ let unsubscribed = false
139
+ function unsubscribe() {
140
+ unsubscribed = true
141
+ return new Promise<any>((resolve) =>
138
142
  rpcClient.request({
139
143
  body: {
140
- method: 'eth_subscribe',
141
- params,
142
- },
143
- onResponse(response) {
144
- if (response.error) {
145
- reject(response.error)
146
- onError?.(response.error)
147
- return
148
- }
149
-
150
- if (typeof response.id === 'number') {
151
- resolve(response)
152
- return
153
- }
154
- if (response.method !== 'eth_subscription') return
155
- onData(response.params)
144
+ method: 'eth_unsubscribe',
145
+ params: [subscriptionId],
156
146
  },
147
+ onResponse: resolve,
157
148
  }),
149
+ )
150
+ }
151
+ await new Promise<any>((resolve, reject) =>
152
+ rpcClient.request({
153
+ body: {
154
+ method: 'eth_subscribe',
155
+ params,
156
+ },
157
+ onResponse(response) {
158
+ if (response.error) {
159
+ reject(response.error)
160
+ onError?.(response.error)
161
+ return
162
+ }
163
+
164
+ if (typeof response.id === 'number') {
165
+ subscriptionId = response.result
166
+ // Re-subscribed while an unsubscribe was in flight.
167
+ if (unsubscribed) unsubscribe()
168
+ resolve(response)
169
+ return
170
+ }
171
+ if (response.method !== 'eth_subscription') return
172
+ onData(response.params)
173
+ },
174
+ }),
158
175
  )
159
176
  return {
160
- subscriptionId,
161
- async unsubscribe() {
162
- return new Promise<any>((resolve) =>
163
- rpcClient.request({
164
- body: {
165
- method: 'eth_unsubscribe',
166
- params: [subscriptionId],
167
- },
168
- onResponse: resolve,
169
- }),
170
- )
177
+ get subscriptionId() {
178
+ return subscriptionId
171
179
  },
180
+ unsubscribe,
172
181
  }
173
182
  },
174
183
  },
@@ -154,47 +154,56 @@ export function webSocket(
154
154
  },
155
155
  async subscribe({ params, onData, onError }: any) {
156
156
  const rpcClient = await getWebSocketRpcClient(url_, wsRpcClientOpts)
157
- const { result: subscriptionId } = await new Promise<any>(
158
- (resolve, reject) =>
157
+ // Updated when the subscription is re-established after a reconnect.
158
+ let subscriptionId: Hash
159
+ let unsubscribed = false
160
+ function unsubscribe() {
161
+ unsubscribed = true
162
+ return new Promise<any>((resolve) =>
159
163
  rpcClient.request({
160
164
  body: {
161
- method: 'eth_subscribe',
162
- params,
165
+ method: 'eth_unsubscribe',
166
+ params: [subscriptionId],
163
167
  },
164
- onError(error) {
165
- reject(error)
166
- onError?.(error)
168
+ onResponse: resolve,
169
+ }),
170
+ )
171
+ }
172
+ await new Promise<any>((resolve, reject) =>
173
+ rpcClient.request({
174
+ body: {
175
+ method: 'eth_subscribe',
176
+ params,
177
+ },
178
+ onError(error) {
179
+ reject(error)
180
+ onError?.(error)
181
+ return
182
+ },
183
+ onResponse(response) {
184
+ if (response.error) {
185
+ reject(response.error)
186
+ onError?.(response.error)
167
187
  return
168
- },
169
- onResponse(response) {
170
- if (response.error) {
171
- reject(response.error)
172
- onError?.(response.error)
173
- return
174
- }
188
+ }
175
189
 
176
- if (typeof response.id === 'number') {
177
- resolve(response)
178
- return
179
- }
180
- if (response.method !== 'eth_subscription') return
181
- onData(response.params)
182
- },
183
- }),
190
+ if (typeof response.id === 'number') {
191
+ subscriptionId = response.result
192
+ // Re-subscribed while an unsubscribe was in flight.
193
+ if (unsubscribed) unsubscribe()
194
+ resolve(response)
195
+ return
196
+ }
197
+ if (response.method !== 'eth_subscription') return
198
+ onData(response.params)
199
+ },
200
+ }),
184
201
  )
185
202
  return {
186
- subscriptionId,
187
- async unsubscribe() {
188
- return new Promise<any>((resolve) =>
189
- rpcClient.request({
190
- body: {
191
- method: 'eth_unsubscribe',
192
- params: [subscriptionId],
193
- },
194
- onResponse: resolve,
195
- }),
196
- )
203
+ get subscriptionId() {
204
+ return subscriptionId
197
205
  },
206
+ unsubscribe,
198
207
  }
199
208
  },
200
209
  },
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.57.4'
1
+ export const version = '2.57.5'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.57.4",
4
+ "version": "2.57.5",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -229,7 +229,7 @@
229
229
  "@scure/bip39": "1.6.0",
230
230
  "abitype": "1.2.3",
231
231
  "isows": "1.0.7",
232
- "ox": "0.14.54",
232
+ "ox": "0.14.56",
233
233
  "ws": "8.21.0"
234
234
  },
235
235
  "license": "MIT",