@prb/effect-evm 1.0.0-beta.4 → 1.0.0-beta.6

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 (233) hide show
  1. package/DOCS.md +13 -0
  2. package/README.md +1 -0
  3. package/dist/constants/index.d.ts +0 -4
  4. package/dist/constants/index.d.ts.map +1 -1
  5. package/dist/constants/index.js +0 -4
  6. package/dist/constants/index.js.map +1 -1
  7. package/dist/contract/pipeline/internal/core.d.ts +2 -2
  8. package/dist/contract/pipeline/internal/core.d.ts.map +1 -1
  9. package/dist/contract/pipeline/internal/core.js.map +1 -1
  10. package/dist/contract/pipeline/internal/receipt.d.ts +2 -2
  11. package/dist/contract/pipeline/internal/receipt.d.ts.map +1 -1
  12. package/dist/contract/pipeline/internal/receipt.js +1 -1
  13. package/dist/contract/pipeline/internal/receipt.js.map +1 -1
  14. package/dist/contract/pipeline/service.d.ts +3 -3
  15. package/dist/contract/pipeline/service.d.ts.map +1 -1
  16. package/dist/contract/pipeline/service.js.map +1 -1
  17. package/dist/contract/pipeline/types.d.ts +2 -2
  18. package/dist/contract/pipeline/types.d.ts.map +1 -1
  19. package/dist/contract/pipeline/types.js.map +1 -1
  20. package/dist/contract/pipeline/write-and-track.js +1 -1
  21. package/dist/contract/pipeline/write-and-track.js.map +1 -1
  22. package/dist/contract/pipeline/write-and-wait.d.ts +1 -1
  23. package/dist/contract/pipeline/write-and-wait.d.ts.map +1 -1
  24. package/dist/core/errors/transaction.d.ts +7 -7
  25. package/dist/core/errors/transaction.d.ts.map +1 -1
  26. package/dist/core/errors/transaction.js +2 -2
  27. package/dist/core/errors/transaction.js.map +1 -1
  28. package/dist/core/errors/viem-mapper.d.ts +3 -3
  29. package/dist/core/errors/viem-mapper.d.ts.map +1 -1
  30. package/dist/core/errors/viem-mapper.js +3 -3
  31. package/dist/core/errors/viem-mapper.js.map +1 -1
  32. package/dist/deploy/service.d.ts +3 -3
  33. package/dist/deploy/service.d.ts.map +1 -1
  34. package/dist/deploy/service.js.map +1 -1
  35. package/dist/eip7702/errors.d.ts +3 -3
  36. package/dist/eip7702/errors.d.ts.map +1 -1
  37. package/dist/eip7702/errors.js +1 -1
  38. package/dist/eip7702/errors.js.map +1 -1
  39. package/dist/eip7702/service.d.ts +8 -8
  40. package/dist/eip7702/service.d.ts.map +1 -1
  41. package/dist/eip7702/service.js +2 -2
  42. package/dist/eip7702/service.js.map +1 -1
  43. package/dist/react-hooks/index.d.ts +0 -4
  44. package/dist/react-hooks/index.d.ts.map +1 -1
  45. package/dist/react-hooks/index.js +0 -4
  46. package/dist/react-hooks/index.js.map +1 -1
  47. package/dist/subscriptions/pending-tx.d.ts +1 -1
  48. package/dist/subscriptions/pending-tx.d.ts.map +1 -1
  49. package/dist/subscriptions/pending-tx.js +1 -1
  50. package/dist/subscriptions/pending-tx.js.map +1 -1
  51. package/dist/subscriptions/service.d.ts +2 -2
  52. package/dist/subscriptions/service.d.ts.map +1 -1
  53. package/dist/subscriptions/service.js +4 -4
  54. package/dist/subscriptions/service.js.map +1 -1
  55. package/dist/telemetry/tracer.d.ts +2 -2
  56. package/dist/telemetry/tracer.js +2 -2
  57. package/dist/telemetry/tracer.js.map +1 -1
  58. package/dist/testing-kit/mock-subscription-service.d.ts +2 -2
  59. package/dist/testing-kit/mock-subscription-service.d.ts.map +1 -1
  60. package/dist/testing-kit/mock-subscription-service.js +5 -5
  61. package/dist/testing-kit/mock-subscription-service.js.map +1 -1
  62. package/dist/testing-kit/mock-transfer-service.d.ts +3 -3
  63. package/dist/testing-kit/mock-transfer-service.d.ts.map +1 -1
  64. package/dist/testing-kit/mock-transfer-service.js.map +1 -1
  65. package/dist/transfer/service.d.ts +3 -3
  66. package/dist/transfer/service.d.ts.map +1 -1
  67. package/dist/transfer/service.js +3 -3
  68. package/dist/transfer/service.js.map +1 -1
  69. package/dist/tx/manager.d.ts +2 -2
  70. package/dist/tx/manager.d.ts.map +1 -1
  71. package/dist/tx/manager.js +5 -5
  72. package/dist/tx/manager.js.map +1 -1
  73. package/dist/tx/manager.test.integration.js +4 -4
  74. package/dist/tx/manager.test.integration.js.map +1 -1
  75. package/dist/tx/replacement.d.ts +3 -3
  76. package/dist/tx/replacement.d.ts.map +1 -1
  77. package/dist/tx/replacement.js +3 -3
  78. package/dist/tx/replacement.js.map +1 -1
  79. package/dist/tx/tracker.d.ts +6 -6
  80. package/dist/tx/tracker.d.ts.map +1 -1
  81. package/dist/tx/tracker.js +9 -9
  82. package/dist/tx/tracker.js.map +1 -1
  83. package/dist/types/params.d.ts +1 -1
  84. package/dist/types/params.d.ts.map +1 -1
  85. package/dist/types/params.js.map +1 -1
  86. package/dist/wallet/errors.d.ts +3 -3
  87. package/dist/wallet/errors.d.ts.map +1 -1
  88. package/dist/wallet/errors.js +1 -1
  89. package/dist/wallet/errors.js.map +1 -1
  90. package/dist/wallet/operations.d.ts +2 -2
  91. package/dist/wallet/operations.d.ts.map +1 -1
  92. package/dist/wallet/operations.js +2 -2
  93. package/dist/wallet/operations.js.map +1 -1
  94. package/dist/wallet/service.d.ts +2 -2
  95. package/dist/wallet/service.d.ts.map +1 -1
  96. package/dist/wallet/service.js.map +1 -1
  97. package/package.json +1 -6
  98. package/dist/react-hooks/safe-origins.d.ts +0 -8
  99. package/dist/react-hooks/safe-origins.d.ts.map +0 -1
  100. package/dist/react-hooks/safe-origins.js +0 -124
  101. package/dist/react-hooks/safe-origins.js.map +0 -1
  102. package/dist/react-hooks/use-is-host-safe-multisig.d.ts +0 -2
  103. package/dist/react-hooks/use-is-host-safe-multisig.d.ts.map +0 -1
  104. package/dist/react-hooks/use-is-host-safe-multisig.js +0 -16
  105. package/dist/react-hooks/use-is-host-safe-multisig.js.map +0 -1
  106. package/dist/react-hooks/use-is-wallet-safe-multisig.d.ts +0 -2
  107. package/dist/react-hooks/use-is-wallet-safe-multisig.d.ts.map +0 -1
  108. package/dist/react-hooks/use-is-wallet-safe-multisig.js +0 -24
  109. package/dist/react-hooks/use-is-wallet-safe-multisig.js.map +0 -1
  110. package/dist/react-hooks/use-safe-context.d.ts +0 -2
  111. package/dist/react-hooks/use-safe-context.d.ts.map +0 -1
  112. package/dist/react-hooks/use-safe-context.js +0 -41
  113. package/dist/react-hooks/use-safe-context.js.map +0 -1
  114. package/dist/safe/adapter.d.ts +0 -9
  115. package/dist/safe/adapter.d.ts.map +0 -1
  116. package/dist/safe/adapter.js +0 -13
  117. package/dist/safe/adapter.js.map +0 -1
  118. package/dist/safe/detection.d.ts +0 -26
  119. package/dist/safe/detection.d.ts.map +0 -1
  120. package/dist/safe/detection.js +0 -102
  121. package/dist/safe/detection.js.map +0 -1
  122. package/dist/safe/detection.test.integration.d.ts +0 -2
  123. package/dist/safe/detection.test.integration.d.ts.map +0 -1
  124. package/dist/safe/detection.test.integration.js +0 -92
  125. package/dist/safe/detection.test.integration.js.map +0 -1
  126. package/dist/safe/errors.d.ts +0 -79
  127. package/dist/safe/errors.d.ts.map +0 -1
  128. package/dist/safe/errors.js +0 -34
  129. package/dist/safe/errors.js.map +0 -1
  130. package/dist/safe/index.d.ts +0 -8
  131. package/dist/safe/index.d.ts.map +0 -1
  132. package/dist/safe/index.js +0 -6
  133. package/dist/safe/index.js.map +0 -1
  134. package/dist/safe/live.d.ts +0 -8
  135. package/dist/safe/live.d.ts.map +0 -1
  136. package/dist/safe/live.js +0 -250
  137. package/dist/safe/live.js.map +0 -1
  138. package/dist/safe/service.d.ts +0 -26
  139. package/dist/safe/service.d.ts.map +0 -1
  140. package/dist/safe/service.js +0 -4
  141. package/dist/safe/service.js.map +0 -1
  142. package/dist/safe/service.test.integration.d.ts +0 -2
  143. package/dist/safe/service.test.integration.d.ts.map +0 -1
  144. package/dist/safe/service.test.integration.js +0 -173
  145. package/dist/safe/service.test.integration.js.map +0 -1
  146. package/dist/safe/simulation/abis.d.ts +0 -73
  147. package/dist/safe/simulation/abis.d.ts.map +0 -1
  148. package/dist/safe/simulation/abis.js +0 -61
  149. package/dist/safe/simulation/abis.js.map +0 -1
  150. package/dist/safe/simulation/addresses.d.ts +0 -4
  151. package/dist/safe/simulation/addresses.d.ts.map +0 -1
  152. package/dist/safe/simulation/addresses.js +0 -54
  153. package/dist/safe/simulation/addresses.js.map +0 -1
  154. package/dist/safe/simulation/encoding.d.ts +0 -16
  155. package/dist/safe/simulation/encoding.d.ts.map +0 -1
  156. package/dist/safe/simulation/encoding.js +0 -36
  157. package/dist/safe/simulation/encoding.js.map +0 -1
  158. package/dist/safe/simulation/errors.d.ts +0 -56
  159. package/dist/safe/simulation/errors.d.ts.map +0 -1
  160. package/dist/safe/simulation/errors.js +0 -37
  161. package/dist/safe/simulation/errors.js.map +0 -1
  162. package/dist/safe/simulation/index.d.ts +0 -7
  163. package/dist/safe/simulation/index.d.ts.map +0 -1
  164. package/dist/safe/simulation/index.js +0 -6
  165. package/dist/safe/simulation/index.js.map +0 -1
  166. package/dist/safe/simulation/internal/calldata/calldata.d.ts +0 -5
  167. package/dist/safe/simulation/internal/calldata/calldata.d.ts.map +0 -1
  168. package/dist/safe/simulation/internal/calldata/calldata.js +0 -17
  169. package/dist/safe/simulation/internal/calldata/calldata.js.map +0 -1
  170. package/dist/safe/simulation/internal/calldata/index.d.ts +0 -2
  171. package/dist/safe/simulation/internal/calldata/index.d.ts.map +0 -1
  172. package/dist/safe/simulation/internal/calldata/index.js +0 -2
  173. package/dist/safe/simulation/internal/calldata/index.js.map +0 -1
  174. package/dist/safe/simulation/internal/contracts/contracts.d.ts +0 -5
  175. package/dist/safe/simulation/internal/contracts/contracts.d.ts.map +0 -1
  176. package/dist/safe/simulation/internal/contracts/contracts.js +0 -25
  177. package/dist/safe/simulation/internal/contracts/contracts.js.map +0 -1
  178. package/dist/safe/simulation/internal/contracts/index.d.ts +0 -2
  179. package/dist/safe/simulation/internal/contracts/index.d.ts.map +0 -1
  180. package/dist/safe/simulation/internal/contracts/index.js +0 -2
  181. package/dist/safe/simulation/internal/contracts/index.js.map +0 -1
  182. package/dist/safe/simulation/internal/evaluation/evaluation.d.ts +0 -6
  183. package/dist/safe/simulation/internal/evaluation/evaluation.d.ts.map +0 -1
  184. package/dist/safe/simulation/internal/evaluation/evaluation.js +0 -20
  185. package/dist/safe/simulation/internal/evaluation/evaluation.js.map +0 -1
  186. package/dist/safe/simulation/internal/evaluation/index.d.ts +0 -2
  187. package/dist/safe/simulation/internal/evaluation/index.d.ts.map +0 -1
  188. package/dist/safe/simulation/internal/evaluation/index.js +0 -2
  189. package/dist/safe/simulation/internal/evaluation/index.js.map +0 -1
  190. package/dist/safe/simulation/internal/execution/execution.d.ts +0 -9
  191. package/dist/safe/simulation/internal/execution/execution.d.ts.map +0 -1
  192. package/dist/safe/simulation/internal/execution/execution.js +0 -65
  193. package/dist/safe/simulation/internal/execution/execution.js.map +0 -1
  194. package/dist/safe/simulation/internal/execution/index.d.ts +0 -2
  195. package/dist/safe/simulation/internal/execution/index.d.ts.map +0 -1
  196. package/dist/safe/simulation/internal/execution/index.js +0 -2
  197. package/dist/safe/simulation/internal/execution/index.js.map +0 -1
  198. package/dist/safe/simulation/internal/limits/index.d.ts +0 -2
  199. package/dist/safe/simulation/internal/limits/index.d.ts.map +0 -1
  200. package/dist/safe/simulation/internal/limits/index.js +0 -2
  201. package/dist/safe/simulation/internal/limits/index.js.map +0 -1
  202. package/dist/safe/simulation/internal/limits/limits.d.ts +0 -5
  203. package/dist/safe/simulation/internal/limits/limits.d.ts.map +0 -1
  204. package/dist/safe/simulation/internal/limits/limits.js +0 -18
  205. package/dist/safe/simulation/internal/limits/limits.js.map +0 -1
  206. package/dist/safe/simulation/internal/types/index.d.ts +0 -2
  207. package/dist/safe/simulation/internal/types/index.d.ts.map +0 -1
  208. package/dist/safe/simulation/internal/types/index.js +0 -2
  209. package/dist/safe/simulation/internal/types/index.js.map +0 -1
  210. package/dist/safe/simulation/internal/types/types.d.ts +0 -11
  211. package/dist/safe/simulation/internal/types/types.d.ts.map +0 -1
  212. package/dist/safe/simulation/internal/types/types.js +0 -2
  213. package/dist/safe/simulation/internal/types/types.js.map +0 -1
  214. package/dist/safe/simulation/internal/validation/index.d.ts +0 -2
  215. package/dist/safe/simulation/internal/validation/index.d.ts.map +0 -1
  216. package/dist/safe/simulation/internal/validation/index.js +0 -2
  217. package/dist/safe/simulation/internal/validation/index.js.map +0 -1
  218. package/dist/safe/simulation/internal/validation/validation.d.ts +0 -5
  219. package/dist/safe/simulation/internal/validation/validation.d.ts.map +0 -1
  220. package/dist/safe/simulation/internal/validation/validation.js +0 -27
  221. package/dist/safe/simulation/internal/validation/validation.js.map +0 -1
  222. package/dist/safe/simulation/service.d.ts +0 -14
  223. package/dist/safe/simulation/service.d.ts.map +0 -1
  224. package/dist/safe/simulation/service.js +0 -25
  225. package/dist/safe/simulation/service.js.map +0 -1
  226. package/dist/safe/simulation/types.d.ts +0 -20
  227. package/dist/safe/simulation/types.d.ts.map +0 -1
  228. package/dist/safe/simulation/types.js +0 -2
  229. package/dist/safe/simulation/types.js.map +0 -1
  230. package/dist/safe/types.d.ts +0 -61
  231. package/dist/safe/types.d.ts.map +0 -1
  232. package/dist/safe/types.js +0 -2
  233. package/dist/safe/types.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { Effect, SubscriptionRef } from "effect";
2
2
  import { MIN_TX_GAS } from "../constants/index.js";
3
- import { PublicClientService, TransactionFailedError, WalletClientService, } from "../core/index.js";
3
+ import { PublicClientService, TxFailedError, WalletClientService } from "../core/index.js";
4
4
  export const initialTxState = { status: "idle" };
5
5
  export const makeTxTracker = Effect.gen(function* () {
6
6
  const ref = yield* SubscriptionRef.make(initialTxState);
@@ -12,13 +12,13 @@ export const makeTxTracker = Effect.gen(function* () {
12
12
  update: (f) => SubscriptionRef.update(ref, f),
13
13
  };
14
14
  });
15
- export const speedupTransaction = (chainId, hash, newMaxFeePerGas, newMaxPriorityFeePerGas) => Effect.gen(function* () {
15
+ export const speedupTx = (chainId, hash, newMaxFeePerGas, newMaxPriorityFeePerGas) => Effect.gen(function* () {
16
16
  const walletClientService = yield* WalletClientService;
17
17
  const walletClient = yield* walletClientService.get(chainId);
18
18
  const publicClientService = yield* PublicClientService;
19
19
  const publicClient = yield* publicClientService.get(chainId);
20
20
  const tx = yield* Effect.tryPromise({
21
- catch: (cause) => new TransactionFailedError({
21
+ catch: (cause) => new TxFailedError({
22
22
  cause,
23
23
  hash,
24
24
  message: `Failed to get transaction ${hash}`,
@@ -26,14 +26,14 @@ export const speedupTransaction = (chainId, hash, newMaxFeePerGas, newMaxPriorit
26
26
  try: () => publicClient.getTransaction({ hash }),
27
27
  });
28
28
  if (!tx) {
29
- yield* Effect.fail(new TransactionFailedError({
29
+ yield* Effect.fail(new TxFailedError({
30
30
  hash,
31
31
  message: `Transaction ${hash} not found`,
32
32
  }));
33
33
  }
34
34
  const transaction = tx;
35
35
  const newHash = yield* Effect.tryPromise({
36
- catch: (cause) => new TransactionFailedError({
36
+ catch: (cause) => new TxFailedError({
37
37
  cause,
38
38
  hash,
39
39
  message: `Failed to speed up transaction ${hash}`,
@@ -52,13 +52,13 @@ export const speedupTransaction = (chainId, hash, newMaxFeePerGas, newMaxPriorit
52
52
  });
53
53
  return newHash;
54
54
  });
55
- export const cancelTransaction = (chainId, hash, newMaxFeePerGas, newMaxPriorityFeePerGas) => Effect.gen(function* () {
55
+ export const cancelTx = (chainId, hash, newMaxFeePerGas, newMaxPriorityFeePerGas) => Effect.gen(function* () {
56
56
  const walletClientService = yield* WalletClientService;
57
57
  const walletClient = yield* walletClientService.get(chainId);
58
58
  const publicClientService = yield* PublicClientService;
59
59
  const publicClient = yield* publicClientService.get(chainId);
60
60
  const tx = yield* Effect.tryPromise({
61
- catch: (cause) => new TransactionFailedError({
61
+ catch: (cause) => new TxFailedError({
62
62
  cause,
63
63
  hash,
64
64
  message: `Failed to get transaction ${hash}`,
@@ -66,14 +66,14 @@ export const cancelTransaction = (chainId, hash, newMaxFeePerGas, newMaxPriority
66
66
  try: () => publicClient.getTransaction({ hash }),
67
67
  });
68
68
  if (!tx) {
69
- yield* Effect.fail(new TransactionFailedError({
69
+ yield* Effect.fail(new TxFailedError({
70
70
  hash,
71
71
  message: `Transaction ${hash} not found`,
72
72
  }));
73
73
  }
74
74
  const transaction = tx;
75
75
  const newHash = yield* Effect.tryPromise({
76
- catch: (cause) => new TransactionFailedError({
76
+ catch: (cause) => new TxFailedError({
77
77
  cause,
78
78
  hash,
79
79
  message: `Failed to cancel transaction ${hash}`,
@@ -1 +1 @@
1
- {"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/tx/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAUjD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAOtD,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AA8C7B,MAAM,CAAC,MAAM,cAAc,GAAY,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAG1D,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC,IAAI,CAAU,cAAc,CAAC,CAAC;IAEjE,OAAO;QACL,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC;QAC7B,GAAG;QACH,GAAG,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;QACxD,MAAM,EAAE,CAAC,CAA0B,EAAE,EAAE,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;KACvE,CAAC;AACJ,CAAC,CAAC,CAAC;AAUH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,OAAe,EACf,IAAU,EACV,eAAuB,EACvB,uBAAgC,EAKhC,EAAE,CACF,MAAM,CAAC,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CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,EAAiB,CAAC;IAGtC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;QACvC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CACf,IAAI,sBAAsB,CAAC;YACzB,KAAK;YACL,IAAI;YACJ,OAAO,EAAE,gCAAgC,IAAI,EAAE;SAChD,CAAC;QACJ,GAAG,EAAE,GAAG,EAAE,CACP,YAA6B,CAAC,eAAe,CAAC;YAC7C,OAAO,EAAE,WAAW,CAAC,IAAI;YACzB,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,eAAe;YAC7B,oBAAoB,EAClB,uBAAuB,IAAI,WAAW,CAAC,oBAAoB,IAAI,SAAS;YAC1E,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,EAAE,EAAE,WAAW,CAAC,IAAI;YACpB,KAAK,EAAE,EAAE;SACV,CAAC;KACL,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC,CAAC","sourcesContent":["import { Effect, SubscriptionRef } from \"effect\";\nimport type {\n AccessList,\n Hash,\n PublicClient,\n Transaction,\n TransactionReceipt,\n TransactionType,\n WalletClient,\n} from \"viem\";\nimport { MIN_TX_GAS } from \"@/src/constants/index.js\";\nimport type {\n ClientNotFoundError,\n TransactionReplacementReason,\n WalletNotConnectedError,\n WrongNetworkError,\n} from \"@/src/core/index.js\";\nimport {\n PublicClientService,\n TransactionFailedError,\n WalletClientService,\n} from \"@/src/core/index.js\";\n\nexport type TxRequestMeta = {\n readonly accessList?: AccessList | undefined;\n readonly gas?: bigint | undefined;\n readonly gasPrice?: bigint | undefined;\n readonly maxFeePerGas?: bigint | undefined;\n readonly maxPriorityFeePerGas?: bigint | undefined;\n readonly nonce?: number | bigint | undefined;\n readonly type?: TransactionType | undefined;\n};\n\nexport type TxState =\n | ({ readonly tx?: TxRequestMeta | undefined } & { status: \"idle\" })\n | ({ readonly tx?: TxRequestMeta | undefined } & { status: \"simulating\" })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"estimated\";\n gas: bigint;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & { status: \"signing\" })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"submitted\";\n hash: Hash;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"pending\";\n hash: Hash;\n confirmations: number;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"mined\";\n hash: Hash;\n receipt: TransactionReceipt;\n effectiveGasPrice?: bigint | undefined;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"replaced\";\n oldHash: Hash;\n newHash: Hash;\n reason: TransactionReplacementReason;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"failed\";\n error: TransactionFailedError;\n });\n\nexport const initialTxState: TxState = { status: \"idle\" };\n\n/** Create a TxState tracker with subscription capabilities */\nexport const makeTxTracker = Effect.gen(function* () {\n const ref = yield* SubscriptionRef.make<TxState>(initialTxState);\n\n return {\n changes: ref.changes,\n get: SubscriptionRef.get(ref),\n ref,\n set: (state: TxState) => SubscriptionRef.set(ref, state),\n update: (f: (s: TxState) => TxState) => SubscriptionRef.update(ref, f),\n };\n});\n\n/**\n * Speed up a pending transaction by submitting a replacement with higher gas fees\n * @param chainId - Chain ID for the wallet client\n * @param hash - Original transaction hash\n * @param newMaxFeePerGas - New max fee per gas (must be higher than original)\n * @param newMaxPriorityFeePerGas - New max priority fee per gas (optional)\n * @returns Effect that resolves to the new transaction hash\n */\nexport const speedupTransaction = (\n chainId: number,\n hash: Hash,\n newMaxFeePerGas: bigint,\n newMaxPriorityFeePerGas?: bigint\n): Effect.Effect<\n Hash,\n TransactionFailedError | WalletNotConnectedError | WrongNetworkError | ClientNotFoundError,\n PublicClientService | WalletClientService\n> =>\n Effect.gen(function* () {\n const walletClientService = yield* WalletClientService;\n const walletClient = yield* walletClientService.get(chainId);\n const publicClientService = yield* PublicClientService;\n const publicClient = yield* publicClientService.get(chainId);\n\n // Get original transaction\n const tx = yield* Effect.tryPromise({\n catch: (cause) =>\n new TransactionFailedError({\n cause,\n hash,\n message: `Failed to get transaction ${hash}`,\n }),\n try: () => (publicClient as PublicClient).getTransaction({ hash }),\n });\n\n if (!tx) {\n yield* Effect.fail(\n new TransactionFailedError({\n hash,\n message: `Transaction ${hash} not found`,\n })\n );\n }\n\n const transaction = tx as Transaction;\n\n // Create replacement transaction with same nonce but higher fees\n const newHash = yield* Effect.tryPromise({\n catch: (cause) =>\n new TransactionFailedError({\n cause,\n hash,\n message: `Failed to speed up transaction ${hash}`,\n }),\n try: () =>\n (walletClient as WalletClient).sendTransaction({\n account: transaction.from,\n chain: null,\n data: transaction.input,\n gas: transaction.gas ?? undefined,\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas:\n newMaxPriorityFeePerGas ?? transaction.maxPriorityFeePerGas ?? undefined,\n nonce: transaction.nonce,\n to: transaction.to ?? undefined,\n value: transaction.value,\n }),\n });\n\n return newHash;\n });\n\n/**\n * Cancel a pending transaction by submitting a zero-value replacement to self\n * @param chainId - Chain ID for the wallet client\n * @param hash - Original transaction hash\n * @param newMaxFeePerGas - New max fee per gas (must be higher than original)\n * @returns Effect that resolves to the cancellation transaction hash\n */\nexport const cancelTransaction = (\n chainId: number,\n hash: Hash,\n newMaxFeePerGas: bigint,\n newMaxPriorityFeePerGas?: bigint\n): Effect.Effect<\n Hash,\n TransactionFailedError | WalletNotConnectedError | WrongNetworkError | ClientNotFoundError,\n PublicClientService | WalletClientService\n> =>\n Effect.gen(function* () {\n const walletClientService = yield* WalletClientService;\n const walletClient = yield* walletClientService.get(chainId);\n const publicClientService = yield* PublicClientService;\n const publicClient = yield* publicClientService.get(chainId);\n\n // Get original transaction\n const tx = yield* Effect.tryPromise({\n catch: (cause) =>\n new TransactionFailedError({\n cause,\n hash,\n message: `Failed to get transaction ${hash}`,\n }),\n try: () => (publicClient as PublicClient).getTransaction({ hash }),\n });\n\n if (!tx) {\n yield* Effect.fail(\n new TransactionFailedError({\n hash,\n message: `Transaction ${hash} not found`,\n })\n );\n }\n\n const transaction = tx as Transaction;\n\n // Create cancellation transaction: same nonce, zero value to self, higher fees\n const newHash = yield* Effect.tryPromise({\n catch: (cause) =>\n new TransactionFailedError({\n cause,\n hash,\n message: `Failed to cancel transaction ${hash}`,\n }),\n try: () =>\n (walletClient as WalletClient).sendTransaction({\n account: transaction.from,\n chain: null,\n data: \"0x\",\n gas: MIN_TX_GAS, // Standard transfer gas\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas:\n newMaxPriorityFeePerGas ?? transaction.maxPriorityFeePerGas ?? undefined,\n nonce: transaction.nonce,\n to: transaction.from, // Send to self\n value: 0n, // Zero value\n }),\n });\n\n return newHash;\n });\n"]}
1
+ {"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/tx/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAUjD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAOtD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AA8C9F,MAAM,CAAC,MAAM,cAAc,GAAY,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAG1D,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC,IAAI,CAAU,cAAc,CAAC,CAAC;IAEjE,OAAO;QACL,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC;QAC7B,GAAG;QACH,GAAG,EAAE,CAAC,KAAc,EAAE,EAAE,CA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B,IAAI,EAAE;SAC7C,CAAC;QACJ,GAAG,EAAE,GAAG,EAAE,CAAE,YAA6B,CAAC,cAAc,CAAC,EAAE,IAAI,EAAE,CAAC;KACnE,CAAC,CAAC;IAEH,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAChB,IAAI,aAAa,CAAC;YAChB,IAAI;YACJ,OAAO,EAAE,eAAe,IAAI,YAAY;SACzC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,MAAM,WAAW,GAAG,EAAiB,CAAC;IAGtC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;QACvC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CACf,IAAI,aAAa,CAAC;YAChB,KAAK;YACL,IAAI;YACJ,OAAO,EAAE,gCAAgC,IAAI,EAAE;SAChD,CAAC;QACJ,GAAG,EAAE,GAAG,EAAE,CACP,YAA6B,CAAC,eAAe,CAAC;YAC7C,OAAO,EAAE,WAAW,CAAC,IAAI;YACzB,KAAK,EAAE,IAAI;YACX,IAAI,EAAE,IAAI;YACV,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,eAAe;YAC7B,oBAAoB,EAClB,uBAAuB,IAAI,WAAW,CAAC,oBAAoB,IAAI,SAAS;YAC1E,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,EAAE,EAAE,WAAW,CAAC,IAAI;YACpB,KAAK,EAAE,EAAE;SACV,CAAC;KACL,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC,CAAC","sourcesContent":["import { Effect, SubscriptionRef } from \"effect\";\nimport type {\n AccessList,\n Hash,\n PublicClient,\n Transaction,\n TransactionReceipt,\n TransactionType,\n WalletClient,\n} from \"viem\";\nimport { MIN_TX_GAS } from \"@/src/constants/index.js\";\nimport type {\n ClientNotFoundError,\n TxReplacementReason,\n WalletNotConnectedError,\n WrongNetworkError,\n} from \"@/src/core/index.js\";\nimport { PublicClientService, TxFailedError, WalletClientService } from \"@/src/core/index.js\";\n\nexport type TxRequestMeta = {\n readonly accessList?: AccessList | undefined;\n readonly gas?: bigint | undefined;\n readonly gasPrice?: bigint | undefined;\n readonly maxFeePerGas?: bigint | undefined;\n readonly maxPriorityFeePerGas?: bigint | undefined;\n readonly nonce?: number | bigint | undefined;\n readonly type?: TransactionType | undefined;\n};\n\nexport type TxState =\n | ({ readonly tx?: TxRequestMeta | undefined } & { status: \"idle\" })\n | ({ readonly tx?: TxRequestMeta | undefined } & { status: \"simulating\" })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"estimated\";\n gas: bigint;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & { status: \"signing\" })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"submitted\";\n hash: Hash;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"pending\";\n hash: Hash;\n confirmations: number;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"mined\";\n hash: Hash;\n receipt: TransactionReceipt;\n effectiveGasPrice?: bigint | undefined;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"replaced\";\n oldHash: Hash;\n newHash: Hash;\n reason: TxReplacementReason;\n })\n | ({ readonly tx?: TxRequestMeta | undefined } & {\n status: \"failed\";\n error: TxFailedError;\n });\n\nexport const initialTxState: TxState = { status: \"idle\" };\n\n/** Create a TxState tracker with subscription capabilities */\nexport const makeTxTracker = Effect.gen(function* () {\n const ref = yield* SubscriptionRef.make<TxState>(initialTxState);\n\n return {\n changes: ref.changes,\n get: SubscriptionRef.get(ref),\n ref,\n set: (state: TxState) => SubscriptionRef.set(ref, state),\n update: (f: (s: TxState) => TxState) => SubscriptionRef.update(ref, f),\n };\n});\n\n/**\n * Speed up a pending transaction by submitting a replacement with higher gas fees\n * @param chainId - Chain ID for the wallet client\n * @param hash - Original transaction hash\n * @param newMaxFeePerGas - New max fee per gas (must be higher than original)\n * @param newMaxPriorityFeePerGas - New max priority fee per gas (optional)\n * @returns Effect that resolves to the new transaction hash\n */\nexport const speedupTx = (\n chainId: number,\n hash: Hash,\n newMaxFeePerGas: bigint,\n newMaxPriorityFeePerGas?: bigint\n): Effect.Effect<\n Hash,\n TxFailedError | WalletNotConnectedError | WrongNetworkError | ClientNotFoundError,\n PublicClientService | WalletClientService\n> =>\n Effect.gen(function* () {\n const walletClientService = yield* WalletClientService;\n const walletClient = yield* walletClientService.get(chainId);\n const publicClientService = yield* PublicClientService;\n const publicClient = yield* publicClientService.get(chainId);\n\n // Get original transaction\n const tx = yield* Effect.tryPromise({\n catch: (cause) =>\n new TxFailedError({\n cause,\n hash,\n message: `Failed to get transaction ${hash}`,\n }),\n try: () => (publicClient as PublicClient).getTransaction({ hash }),\n });\n\n if (!tx) {\n yield* Effect.fail(\n new TxFailedError({\n hash,\n message: `Transaction ${hash} not found`,\n })\n );\n }\n\n const transaction = tx as Transaction;\n\n // Create replacement transaction with same nonce but higher fees\n const newHash = yield* Effect.tryPromise({\n catch: (cause) =>\n new TxFailedError({\n cause,\n hash,\n message: `Failed to speed up transaction ${hash}`,\n }),\n try: () =>\n (walletClient as WalletClient).sendTransaction({\n account: transaction.from,\n chain: null,\n data: transaction.input,\n gas: transaction.gas ?? undefined,\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas:\n newMaxPriorityFeePerGas ?? transaction.maxPriorityFeePerGas ?? undefined,\n nonce: transaction.nonce,\n to: transaction.to ?? undefined,\n value: transaction.value,\n }),\n });\n\n return newHash;\n });\n\n/**\n * Cancel a pending transaction by submitting a zero-value replacement to self\n * @param chainId - Chain ID for the wallet client\n * @param hash - Original transaction hash\n * @param newMaxFeePerGas - New max fee per gas (must be higher than original)\n * @returns Effect that resolves to the cancellation transaction hash\n */\nexport const cancelTx = (\n chainId: number,\n hash: Hash,\n newMaxFeePerGas: bigint,\n newMaxPriorityFeePerGas?: bigint\n): Effect.Effect<\n Hash,\n TxFailedError | WalletNotConnectedError | WrongNetworkError | ClientNotFoundError,\n PublicClientService | WalletClientService\n> =>\n Effect.gen(function* () {\n const walletClientService = yield* WalletClientService;\n const walletClient = yield* walletClientService.get(chainId);\n const publicClientService = yield* PublicClientService;\n const publicClient = yield* publicClientService.get(chainId);\n\n // Get original transaction\n const tx = yield* Effect.tryPromise({\n catch: (cause) =>\n new TxFailedError({\n cause,\n hash,\n message: `Failed to get transaction ${hash}`,\n }),\n try: () => (publicClient as PublicClient).getTransaction({ hash }),\n });\n\n if (!tx) {\n yield* Effect.fail(\n new TxFailedError({\n hash,\n message: `Transaction ${hash} not found`,\n })\n );\n }\n\n const transaction = tx as Transaction;\n\n // Create cancellation transaction: same nonce, zero value to self, higher fees\n const newHash = yield* Effect.tryPromise({\n catch: (cause) =>\n new TxFailedError({\n cause,\n hash,\n message: `Failed to cancel transaction ${hash}`,\n }),\n try: () =>\n (walletClient as WalletClient).sendTransaction({\n account: transaction.from,\n chain: null,\n data: \"0x\",\n gas: MIN_TX_GAS, // Standard transfer gas\n maxFeePerGas: newMaxFeePerGas,\n maxPriorityFeePerGas:\n newMaxPriorityFeePerGas ?? transaction.maxPriorityFeePerGas ?? undefined,\n nonce: transaction.nonce,\n to: transaction.from, // Send to self\n value: 0n, // Zero value\n }),\n });\n\n return newHash;\n });\n"]}
@@ -48,7 +48,7 @@ export type MulticallResult<TResult = unknown> = {
48
48
  readonly status: "failure";
49
49
  readonly error: Error;
50
50
  };
51
- export type TransactionResult = {
51
+ export type TxResult = {
52
52
  readonly hash: Hash;
53
53
  readonly receipt: TransactionReceipt;
54
54
  };
@@ -1 +1 @@
1
- {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,GAAG,EACH,OAAO,EACP,QAAQ,EACR,oBAAoB,EACpB,oBAAoB,EACpB,QAAQ,EACR,IAAI,EACJ,kBAAkB,EACnB,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE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C,MAAM,MAAM,cAAc,CAAC,OAAO,GAAG,OAAO,IAAI;IAC9C,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAKF,MAAM,MAAM,aAAa,CACvB,IAAI,SAAS,GAAG,GAAG,GAAG,EACtB,aAAa,SAAS,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,oBAAoB,CACtF,IAAI,EACJ,MAAM,GAAG,MAAM,CAChB,IACC;IACF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;IACnB,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC;CACtC,GAAG,SAAS,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;AAK1E,MAAM,MAAM,eAAe,CAAC,OAAO,GAAG,OAAO,IACzC;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAK1D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;CACtC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Abi,\n Address,\n BlockTag,\n ContractFunctionArgs,\n ContractFunctionName,\n GetValue,\n Hash,\n TransactionReceipt,\n} from \"viem\";\nimport type { TxOverrides } from \"@/src/types/index.js\";\n\ntype ValueField<TAbi extends Abi, TFunctionName extends string> = Readonly<\n GetValue<TAbi, TFunctionName, bigint>\n>;\n\ntype ArgsField<TArgs> = {\n readonly args?: TArgs | undefined;\n} & (readonly [] extends TArgs ? unknown : { readonly args: TArgs });\n\ntype BlockRef =\n | {\n readonly blockNumber?: bigint | undefined;\n readonly blockTag?: never;\n }\n | {\n readonly blockNumber?: never;\n readonly blockTag?: BlockTag | undefined;\n }\n | {\n readonly blockNumber?: never;\n readonly blockTag?: never;\n };\n\n/**\n * Parameters for reading from a contract\n */\nexport type ReadParams<\n TAbi extends Abi,\n TFunctionName extends ContractFunctionName<TAbi, \"pure\" | \"view\">,\n> = {\n /** Optional call account (msg.sender) */\n readonly account?: Address | undefined;\n readonly chainId: number;\n readonly address: Address;\n readonly abi: TAbi;\n readonly functionName: TFunctionName;\n} & BlockRef &\n ArgsField<ContractFunctionArgs<TAbi, \"pure\" | \"view\", TFunctionName>>;\n\n/**\n * Parameters for writing to a contract\n */\nexport type WriteParams<\n TAbi extends Abi,\n TFunctionName extends ContractFunctionName<TAbi, \"nonpayable\" | \"payable\">,\n> = {\n readonly chainId: number;\n readonly address: Address;\n readonly abi: TAbi;\n readonly functionName: TFunctionName;\n readonly account: Address;\n /** Legacy escape hatch. Prefer `overrides.gas`. */\n readonly gas?: bigint | undefined;\n /** Safe transaction-level overrides (fees, nonce, access list, etc). */\n readonly overrides?: TxOverrides | undefined;\n} & ArgsField<ContractFunctionArgs<TAbi, \"nonpayable\" | \"payable\", TFunctionName>> &\n ValueField<TAbi, TFunctionName>;\n\n/**\n * Result from simulating a contract call\n */\nexport type SimulateResult<TResult = unknown> = {\n readonly result: TResult;\n readonly request: unknown;\n};\n\n/**\n * A single call in a multicall batch\n */\nexport type MulticallCall<\n TAbi extends Abi = Abi,\n TFunctionName extends ContractFunctionName<TAbi, \"pure\" | \"view\"> = ContractFunctionName<\n TAbi,\n \"pure\" | \"view\"\n >,\n> = {\n readonly address: Address;\n readonly abi: TAbi;\n readonly functionName: TFunctionName;\n} & ArgsField<ContractFunctionArgs<TAbi, \"pure\" | \"view\", TFunctionName>>;\n\n/**\n * Result from a multicall operation\n */\nexport type MulticallResult<TResult = unknown> =\n | { readonly status: \"success\"; readonly result: TResult }\n | { readonly status: \"failure\"; readonly error: Error };\n\n/**\n * Result from a transaction\n */\nexport type TransactionResult = {\n readonly hash: Hash;\n readonly receipt: TransactionReceipt;\n};\n"]}
1
+ {"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Abi,\n Address,\n BlockTag,\n ContractFunctionArgs,\n ContractFunctionName,\n GetValue,\n Hash,\n TransactionReceipt,\n} from \"viem\";\nimport type { TxOverrides } from \"@/src/types/index.js\";\n\ntype ValueField<TAbi extends Abi, TFunctionName extends string> = Readonly<\n GetValue<TAbi, TFunctionName, bigint>\n>;\n\ntype ArgsField<TArgs> = {\n readonly args?: TArgs | undefined;\n} & (readonly [] extends TArgs ? unknown : { readonly args: TArgs });\n\ntype BlockRef =\n | {\n readonly blockNumber?: bigint | undefined;\n readonly blockTag?: never;\n }\n | {\n readonly blockNumber?: never;\n readonly blockTag?: BlockTag | undefined;\n }\n | {\n readonly blockNumber?: never;\n readonly blockTag?: never;\n };\n\n/**\n * Parameters for reading from a contract\n */\nexport type ReadParams<\n TAbi extends Abi,\n TFunctionName extends ContractFunctionName<TAbi, \"pure\" | \"view\">,\n> = {\n /** Optional call account (msg.sender) */\n readonly account?: Address | undefined;\n readonly chainId: number;\n readonly address: Address;\n readonly abi: TAbi;\n readonly functionName: TFunctionName;\n} & BlockRef &\n ArgsField<ContractFunctionArgs<TAbi, \"pure\" | \"view\", TFunctionName>>;\n\n/**\n * Parameters for writing to a contract\n */\nexport type WriteParams<\n TAbi extends Abi,\n TFunctionName extends ContractFunctionName<TAbi, \"nonpayable\" | \"payable\">,\n> = {\n readonly chainId: number;\n readonly address: Address;\n readonly abi: TAbi;\n readonly functionName: TFunctionName;\n readonly account: Address;\n /** Legacy escape hatch. Prefer `overrides.gas`. */\n readonly gas?: bigint | undefined;\n /** Safe transaction-level overrides (fees, nonce, access list, etc). */\n readonly overrides?: TxOverrides | undefined;\n} & ArgsField<ContractFunctionArgs<TAbi, \"nonpayable\" | \"payable\", TFunctionName>> &\n ValueField<TAbi, TFunctionName>;\n\n/**\n * Result from simulating a contract call\n */\nexport type SimulateResult<TResult = unknown> = {\n readonly result: TResult;\n readonly request: unknown;\n};\n\n/**\n * A single call in a multicall batch\n */\nexport type MulticallCall<\n TAbi extends Abi = Abi,\n TFunctionName extends ContractFunctionName<TAbi, \"pure\" | \"view\"> = ContractFunctionName<\n TAbi,\n \"pure\" | \"view\"\n >,\n> = {\n readonly address: Address;\n readonly abi: TAbi;\n readonly functionName: TFunctionName;\n} & ArgsField<ContractFunctionArgs<TAbi, \"pure\" | \"view\", TFunctionName>>;\n\n/**\n * Result from a multicall operation\n */\nexport type MulticallResult<TResult = unknown> =\n | { readonly status: \"success\"; readonly result: TResult }\n | { readonly status: \"failure\"; readonly error: Error };\n\n/**\n * Result from a transaction\n */\nexport type TxResult = {\n readonly hash: Hash;\n readonly receipt: TransactionReceipt;\n};\n"]}
@@ -15,13 +15,13 @@ declare const SignTypedDataError_base: Schema.TaggedErrorClass<SignTypedDataErro
15
15
  }>;
16
16
  export declare class SignTypedDataError extends SignTypedDataError_base {
17
17
  }
18
- declare const SignTransactionError_base: Schema.TaggedErrorClass<SignTransactionError, "SignTransactionError", {
19
- readonly _tag: Schema.tag<"SignTransactionError">;
18
+ declare const SignTxError_base: Schema.TaggedErrorClass<SignTxError, "SignTxError", {
19
+ readonly _tag: Schema.tag<"SignTxError">;
20
20
  } & {
21
21
  cause: Schema.optional<typeof Schema.Unknown>;
22
22
  message: typeof Schema.String;
23
23
  }>;
24
- export declare class SignTransactionError extends SignTransactionError_base {
24
+ export declare class SignTxError extends SignTxError_base {
25
25
  }
26
26
  declare const WalletConnectionError_base: Schema.TaggedErrorClass<WalletConnectionError, "WalletConnectionError", {
27
27
  readonly _tag: Schema.tag<"WalletConnectionError">;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/wallet/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;;AAEhC,qBAAa,gBAAiB,SAAQ,qBAGpC;CAAG;;;;;;;AAEL,qBAAa,kBAAmB,SAAQ,uBAMvC;CAAG;;;;;;;AAEJ,qBAAa,oBAAqB,SAAQ,yBAMzC;CAAG;;;;;;;AAEJ,qBAAa,qBAAsB,SAAQ,0BAM1C;CAAG;;;;;;;;AAEJ,qBAAa,gBAAiB,SAAQ,qBAIpC;CAAG;;;;;;;;AAEL,qBAAa,aAAc,SAAQ,kBAIjC;CAAG;;;;;;AAEL,qBAAa,wBAAyB,SAAQ,6BAK7C;CAAG;;;;;;;AAEJ,qBAAa,eAAgB,SAAQ,oBAGnC;CAAG"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/wallet/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;;;;AAEhC,qBAAa,gBAAiB,SAAQ,qBAGpC;CAAG;;;;;;;AAEL,qBAAa,kBAAmB,SAAQ,uBAMvC;CAAG;;;;;;;AAEJ,qBAAa,WAAY,SAAQ,gBAG/B;CAAG;;;;;;;AAEL,qBAAa,qBAAsB,SAAQ,0BAM1C;CAAG;;;;;;;;AAEJ,qBAAa,gBAAiB,SAAQ,qBAIpC;CAAG;;;;;;;;AAEL,qBAAa,aAAc,SAAQ,kBAIjC;CAAG;;;;;;AAEL,qBAAa,wBAAyB,SAAQ,6BAK7C;CAAG;;;;;;;AAEJ,qBAAa,eAAgB,SAAQ,oBAGnC;CAAG"}
@@ -9,7 +9,7 @@ export class SignTypedDataError extends Schema.TaggedError()("SignTypedDataError
9
9
  message: Schema.String,
10
10
  }) {
11
11
  }
12
- export class SignTransactionError extends Schema.TaggedError()("SignTransactionError", {
12
+ export class SignTxError extends Schema.TaggedError()("SignTxError", {
13
13
  cause: Schema.optional(Schema.Unknown),
14
14
  message: Schema.String,
15
15
  }) {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/wallet/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,EAAoB,CAAC,kBAAkB,EAAE;IAC/F,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,OAAO,kBAAmB,SAAQ,MAAM,CAAC,WAAW,EAAsB,CAC9E,oBAAoB,EACpB;IACE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;CAAG;AAEJ,MAAM,OAAO,oBAAqB,SAAQ,MAAM,CAAC,WAAW,EAAwB,CAClF,sBAAsB,EACtB;IACE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;CAAG;AAEJ,MAAM,OAAO,qBAAsB,SAAQ,MAAM,CAAC,WAAW,EAAyB,CACpF,uBAAuB,EACvB;IACE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;CAAG;AAEJ,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,EAAoB,CAAC,kBAAkB,EAAE;IAC/F,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,WAAW,EAAiB,CAAC,eAAe,EAAE;IACtF,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,OAAO,wBAAyB,SAAQ,MAAM,CAAC,WAAW,EAA4B,CAC1F,0BAA0B,EAC1B;IACE,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;CAAG;AAEJ,MAAM,OAAO,eAAgB,SAAQ,MAAM,CAAC,WAAW,EAAmB,CAAC,iBAAiB,EAAE;IAC5F,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG","sourcesContent":["import { Schema } from \"effect\";\n\nexport class SignMessageError extends Schema.TaggedError<SignMessageError>()(\"SignMessageError\", {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n}) {}\n\nexport class SignTypedDataError extends Schema.TaggedError<SignTypedDataError>()(\n \"SignTypedDataError\",\n {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n }\n) {}\n\nexport class SignTransactionError extends Schema.TaggedError<SignTransactionError>()(\n \"SignTransactionError\",\n {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n }\n) {}\n\nexport class WalletConnectionError extends Schema.TaggedError<WalletConnectionError>()(\n \"WalletConnectionError\",\n {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n }\n) {}\n\nexport class ChainSwitchError extends Schema.TaggedError<ChainSwitchError>()(\"ChainSwitchError\", {\n cause: Schema.optional(Schema.Unknown),\n chainId: Schema.Number,\n message: Schema.String,\n}) {}\n\nexport class AddChainError extends Schema.TaggedError<AddChainError>()(\"AddChainError\", {\n cause: Schema.optional(Schema.Unknown),\n chainId: Schema.Number,\n message: Schema.String,\n}) {}\n\nexport class AccountNotConnectedError extends Schema.TaggedError<AccountNotConnectedError>()(\n \"AccountNotConnectedError\",\n {\n message: Schema.String,\n }\n) {}\n\nexport class WatchAssetError extends Schema.TaggedError<WatchAssetError>()(\"WatchAssetError\", {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n}) {}\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/wallet/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,EAAoB,CAAC,kBAAkB,EAAE;IAC/F,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,OAAO,kBAAmB,SAAQ,MAAM,CAAC,WAAW,EAAsB,CAC9E,oBAAoB,EACpB;IACE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;CAAG;AAEJ,MAAM,OAAO,WAAY,SAAQ,MAAM,CAAC,WAAW,EAAe,CAAC,aAAa,EAAE;IAChF,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,OAAO,qBAAsB,SAAQ,MAAM,CAAC,WAAW,EAAyB,CACpF,uBAAuB,EACvB;IACE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;CAAG;AAEJ,MAAM,OAAO,gBAAiB,SAAQ,MAAM,CAAC,WAAW,EAAoB,CAAC,kBAAkB,EAAE;IAC/F,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,OAAO,aAAc,SAAQ,MAAM,CAAC,WAAW,EAAiB,CAAC,eAAe,EAAE;IACtF,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG;AAEL,MAAM,OAAO,wBAAyB,SAAQ,MAAM,CAAC,WAAW,EAA4B,CAC1F,0BAA0B,EAC1B;IACE,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CACF;CAAG;AAEJ,MAAM,OAAO,eAAgB,SAAQ,MAAM,CAAC,WAAW,EAAmB,CAAC,iBAAiB,EAAE;IAC5F,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC;CAAG","sourcesContent":["import { Schema } from \"effect\";\n\nexport class SignMessageError extends Schema.TaggedError<SignMessageError>()(\"SignMessageError\", {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n}) {}\n\nexport class SignTypedDataError extends Schema.TaggedError<SignTypedDataError>()(\n \"SignTypedDataError\",\n {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n }\n) {}\n\nexport class SignTxError extends Schema.TaggedError<SignTxError>()(\"SignTxError\", {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n}) {}\n\nexport class WalletConnectionError extends Schema.TaggedError<WalletConnectionError>()(\n \"WalletConnectionError\",\n {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n }\n) {}\n\nexport class ChainSwitchError extends Schema.TaggedError<ChainSwitchError>()(\"ChainSwitchError\", {\n cause: Schema.optional(Schema.Unknown),\n chainId: Schema.Number,\n message: Schema.String,\n}) {}\n\nexport class AddChainError extends Schema.TaggedError<AddChainError>()(\"AddChainError\", {\n cause: Schema.optional(Schema.Unknown),\n chainId: Schema.Number,\n message: Schema.String,\n}) {}\n\nexport class AccountNotConnectedError extends Schema.TaggedError<AccountNotConnectedError>()(\n \"AccountNotConnectedError\",\n {\n message: Schema.String,\n }\n) {}\n\nexport class WatchAssetError extends Schema.TaggedError<WatchAssetError>()(\"WatchAssetError\", {\n cause: Schema.optional(Schema.Unknown),\n message: Schema.String,\n}) {}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { Effect } from "effect";
2
2
  import type { Hex, TypedData } from "viem";
3
3
  import type { SignMessageParams, SignTransactionParams, SignTypedDataParams, WalletProvider } from "../wallet/index.js";
4
- import { AccountNotConnectedError, SignMessageError, SignTransactionError, SignTypedDataError } from "../wallet/index.js";
4
+ import { AccountNotConnectedError, SignMessageError, SignTxError, SignTypedDataError } from "../wallet/index.js";
5
5
  export declare function signMessage(provider: WalletProvider, params: SignMessageParams): Effect.Effect<Hex, SignMessageError | AccountNotConnectedError>;
6
6
  export declare function signTypedData<const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain">(provider: WalletProvider, params: SignTypedDataParams<typedData, primaryType>): Effect.Effect<Hex, SignTypedDataError | AccountNotConnectedError>;
7
- export declare function signTransaction(provider: WalletProvider, params: SignTransactionParams): Effect.Effect<Hex, SignTransactionError | AccountNotConnectedError>;
7
+ export declare function signTransaction(provider: WalletProvider, params: SignTransactionParams): Effect.Effect<Hex, SignTxError | AccountNotConnectedError>;
8
8
  //# sourceMappingURL=operations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/wallet/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAW,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;AA+F/B,wBAAgB,WAAW,CACzB,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,iBAAiB,GACxB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,gBAAgB,GAAG,wBAAwB,CAAC,CAkEjE;AAKD,wBAAgB,aAAa,CAC3B,KAAK,CAAC,SAAS,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,WAAW,SAAS,MAAM,SAAS,GAAG,cAAc,EAEpD,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,mBAAmB,CAAC,SAAS,EAAE,WAAW,CAAC,GAClD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,kBAAkB,GAAG,wBAAwB,CAAC,CAiDnE;AAKD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,qBAAqB,GAC5B,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,GAAG,wBAAwB,CAAC,CAwC5D"}
@@ -1,7 +1,7 @@
1
1
  import { Effect } from "effect";
2
2
  import { isLikelyUserRejectedError, isUserRejectedError } from "../core/errors/index.js";
3
3
  import { SpanNames } from "../telemetry/index.js";
4
- import { AccountNotConnectedError, SignMessageError, SignTransactionError, SignTypedDataError, } from "../wallet/index.js";
4
+ import { AccountNotConnectedError, SignMessageError, SignTxError, SignTypedDataError, } from "../wallet/index.js";
5
5
  const isUserRejection = (error) => isUserRejectedError(error);
6
6
  const isLikelyUserRejection = (error) => isLikelyUserRejectedError(error);
7
7
  const errorCode = (error) => {
@@ -186,7 +186,7 @@ export function signTransaction(provider, params) {
186
186
  catch: (cause) => {
187
187
  const errorMessage = cause instanceof Error ? cause.message : "Failed to sign transaction";
188
188
  const isRejection = isLikelyUserRejection(cause);
189
- return new SignTransactionError({
189
+ return new SignTxError({
190
190
  cause,
191
191
  message: isRejection ? "User rejected the request" : errorMessage,
192
192
  });
@@ -1 +1 @@
1
- {"version":3,"file":"operations.js","sourceRoot":"","sources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M,KAAK,CAAC,EAAE,CAAC;wBAC1B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;oBACjD,CAAC;oBACD,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;gBACrB,CAAC;aACF,CAAC,CAAC,CAAC;QAGN,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;YAC9B,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,4BAA4B,CAAC;gBAC3F,MAAM,WAAW,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBACjD,OAAO,IAAI,oBAAoB,CAAC;oBAC9B,KAAK;oBACL,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,YAAY;iBAClE,CAAC,CAAC;YACL,CAAC;YACD,GAAG,EAAE,KAAK,IAAI,EAAE;gBACd,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC;oBACpC,MAAM,EAAE,qBAAqB;oBAC7B,MAAM,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iBACvC,CAAC,CAAC;gBACH,OAAO,MAAa,CAAC;YACvB,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Effect } from \"effect\";\nimport type { Address, Hex, TypedData } from \"viem\";\nimport { isLikelyUserRejectedError, isUserRejectedError } from \"@/src/core/errors/index.js\";\nimport { SpanNames } from \"@/src/telemetry/index.js\";\nimport type {\n SignMessageParams,\n SignTransactionParams,\n SignTypedDataParams,\n WalletProvider,\n} from \"@/src/wallet/index.js\";\nimport {\n AccountNotConnectedError,\n SignMessageError,\n SignTransactionError,\n SignTypedDataError,\n} from \"@/src/wallet/index.js\";\n\n/**\n * Detect if an error is a user rejection\n */\nconst isUserRejection = (error: unknown): boolean => isUserRejectedError(error);\nconst isLikelyUserRejection = (error: unknown): boolean => isLikelyUserRejectedError(error);\n\nconst errorCode = (error: unknown): number | undefined => {\n if (!error || typeof error !== \"object\") {\n return;\n }\n const code = (error as { code?: unknown }).code;\n return typeof code === \"number\" ? code : undefined;\n};\n\nconst messageOf = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message;\n }\n if (typeof error === \"string\") {\n return error;\n }\n return String(error);\n};\n\nconst isMethodNotFound = (error: unknown): boolean => {\n const code = errorCode(error);\n if (code === -32_601) {\n return true;\n }\n const msg = messageOf(error).toLowerCase();\n return msg.includes(\"method not found\") || msg.includes(\"does not exist\");\n};\n\nconst isInvalidParams = (error: unknown): boolean => {\n const code = errorCode(error);\n if (code === -32_602) {\n return true;\n }\n const msg = messageOf(error).toLowerCase();\n return msg.includes(\"invalid params\") || msg.includes(\"invalid parameter\");\n};\n\nconst requestHex = async (\n provider: WalletProvider,\n method: string,\n methodParams: unknown[]\n): Promise<Hex> => {\n const result = await provider.request({\n method,\n params: methodParams,\n });\n return result as Hex;\n};\n\nconst signTypedDataFallbacks = async (\n provider: WalletProvider,\n account: Address,\n typedDataPayload: unknown\n): Promise<Hex> => {\n const json = JSON.stringify(typedDataPayload);\n const attempts: ReadonlyArray<{\n method: string;\n params: readonly unknown[];\n }> = [\n { method: \"eth_signTypedData_v4\", params: [account, json] },\n { method: \"eth_signTypedData_v3\", params: [account, json] },\n { method: \"eth_signTypedData\", params: [account, typedDataPayload] },\n ];\n\n let lastError: unknown;\n for (const attempt of attempts) {\n try {\n return await requestHex(provider, attempt.method, [...attempt.params]);\n } catch (e) {\n if (isUserRejection(e)) {\n throw e;\n }\n lastError = e;\n\n const shouldTryNext = attempt.method !== \"eth_signTypedData\" && isMethodNotFound(e);\n\n if (!shouldTryNext) {\n throw e;\n }\n }\n }\n\n throw lastError;\n};\n\n/**\n * Sign a message using the wallet's personal_sign method\n */\nexport function signMessage(\n provider: WalletProvider,\n params: SignMessageParams\n): Effect.Effect<Hex, SignMessageError | AccountNotConnectedError> {\n return Effect.gen(function* () {\n // Get the current account if not provided\n const account =\n params.account ??\n (yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get wallet account\",\n }),\n try: async () => {\n const accounts = (await provider.request({\n method: \"eth_accounts\",\n })) as Address[];\n if (accounts.length === 0) {\n throw new Error(\"No wallet account connected\");\n }\n return accounts[0];\n },\n }));\n\n // Prepare the message\n const message = typeof params.message === \"string\" ? params.message : params.message.raw;\n\n // Sign the message\n return yield* Effect.tryPromise({\n catch: (cause) => {\n const errorMessage = messageOf(cause) || \"Failed to sign message\";\n const isRejection = isLikelyUserRejection(cause);\n return new SignMessageError({\n cause,\n message: isRejection ? \"User rejected the request\" : errorMessage,\n });\n },\n try: async () => {\n try {\n const result = await provider.request({\n method: \"personal_sign\",\n params: [message, account],\n });\n return result as Hex;\n } catch (e) {\n if (isUserRejection(e)) {\n throw e;\n }\n\n if (!isInvalidParams(e)) {\n throw e;\n }\n\n // Fallback for providers that expect reversed parameter order.\n const result = await provider.request({\n method: \"personal_sign\",\n params: [account, message],\n });\n return result as Hex;\n }\n },\n });\n }).pipe(\n Effect.withSpan(SpanNames.WALLET_SIGN_MESSAGE, {\n attributes: {\n account: params.account,\n },\n })\n );\n}\n\n/**\n * Sign typed data using the wallet's eth_signTypedData_v4 method\n */\nexport function signTypedData<\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\",\n>(\n provider: WalletProvider,\n params: SignTypedDataParams<typedData, primaryType>\n): Effect.Effect<Hex, SignTypedDataError | AccountNotConnectedError> {\n return Effect.gen(function* () {\n // Get the current account if not provided\n const account =\n params.account ??\n (yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get wallet account\",\n }),\n try: async () => {\n const accounts = (await provider.request({\n method: \"eth_accounts\",\n })) as Address[];\n if (accounts.length === 0) {\n throw new Error(\"No wallet account connected\");\n }\n return accounts[0];\n },\n }));\n\n // Prepare the typed data payload\n const typedDataPayload = {\n domain: params.domain,\n message: params.message,\n primaryType: params.primaryType,\n types: params.types,\n };\n\n // Sign the typed data\n return yield* Effect.tryPromise({\n catch: (cause) => {\n const errorMessage = messageOf(cause) || \"Failed to sign typed data\";\n const isRejection = isLikelyUserRejection(cause);\n return new SignTypedDataError({\n cause,\n message: isRejection ? \"User rejected the request\" : errorMessage,\n });\n },\n try: async () => await signTypedDataFallbacks(provider, account, typedDataPayload),\n });\n }).pipe(\n Effect.withSpan(SpanNames.WALLET_SIGN_TYPED_DATA, {\n attributes: {\n account: params.account,\n primaryType: params.primaryType,\n },\n })\n );\n}\n\n/**\n * Sign a transaction using the wallet's eth_signTransaction method\n */\nexport function signTransaction(\n provider: WalletProvider,\n params: SignTransactionParams\n): Effect.Effect<Hex, SignTransactionError | AccountNotConnectedError> {\n return Effect.gen(function* () {\n // Get the current account if not provided\n const account =\n params.from ??\n (yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get wallet account\",\n }),\n try: async () => {\n const accounts = (await provider.request({\n method: \"eth_accounts\",\n })) as Address[];\n if (accounts.length === 0) {\n throw new Error(\"No wallet account connected\");\n }\n return accounts[0];\n },\n }));\n\n // Sign the transaction\n return yield* Effect.tryPromise({\n catch: (cause) => {\n const errorMessage = cause instanceof Error ? cause.message : \"Failed to sign transaction\";\n const isRejection = isLikelyUserRejection(cause);\n return new SignTransactionError({\n cause,\n message: isRejection ? \"User rejected the request\" : errorMessage,\n });\n },\n try: async () => {\n const result = await provider.request({\n method: \"eth_signTransaction\",\n params: [{ ...params, from: account }],\n });\n return result as Hex;\n },\n });\n });\n}\n"]}
1
+ {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/wallet/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CA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jD,CAAC;oBACD,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;gBACrB,CAAC;aACF,CAAC,CAAC,CAAC;QAGN,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC;YAC9B,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,4BAA4B,CAAC;gBAC3F,MAAM,WAAW,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;gBACjD,OAAO,IAAI,WAAW,CAAC;oBACrB,KAAK;oBACL,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,YAAY;iBAClE,CAAC,CAAC;YACL,CAAC;YACD,GAAG,EAAE,KAAK,IAAI,EAAE;gBACd,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC;oBACpC,MAAM,EAAE,qBAAqB;oBAC7B,MAAM,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iBACvC,CAAC,CAAC;gBACH,OAAO,MAAa,CAAC;YACvB,CAAC;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Effect } from \"effect\";\nimport type { Address, Hex, TypedData } from \"viem\";\nimport { isLikelyUserRejectedError, isUserRejectedError } from \"@/src/core/errors/index.js\";\nimport { SpanNames } from \"@/src/telemetry/index.js\";\nimport type {\n SignMessageParams,\n SignTransactionParams,\n SignTypedDataParams,\n WalletProvider,\n} from \"@/src/wallet/index.js\";\nimport {\n AccountNotConnectedError,\n SignMessageError,\n SignTxError,\n SignTypedDataError,\n} from \"@/src/wallet/index.js\";\n\n/**\n * Detect if an error is a user rejection\n */\nconst isUserRejection = (error: unknown): boolean => isUserRejectedError(error);\nconst isLikelyUserRejection = (error: unknown): boolean => isLikelyUserRejectedError(error);\n\nconst errorCode = (error: unknown): number | undefined => {\n if (!error || typeof error !== \"object\") {\n return;\n }\n const code = (error as { code?: unknown }).code;\n return typeof code === \"number\" ? code : undefined;\n};\n\nconst messageOf = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message;\n }\n if (typeof error === \"string\") {\n return error;\n }\n return String(error);\n};\n\nconst isMethodNotFound = (error: unknown): boolean => {\n const code = errorCode(error);\n if (code === -32_601) {\n return true;\n }\n const msg = messageOf(error).toLowerCase();\n return msg.includes(\"method not found\") || msg.includes(\"does not exist\");\n};\n\nconst isInvalidParams = (error: unknown): boolean => {\n const code = errorCode(error);\n if (code === -32_602) {\n return true;\n }\n const msg = messageOf(error).toLowerCase();\n return msg.includes(\"invalid params\") || msg.includes(\"invalid parameter\");\n};\n\nconst requestHex = async (\n provider: WalletProvider,\n method: string,\n methodParams: unknown[]\n): Promise<Hex> => {\n const result = await provider.request({\n method,\n params: methodParams,\n });\n return result as Hex;\n};\n\nconst signTypedDataFallbacks = async (\n provider: WalletProvider,\n account: Address,\n typedDataPayload: unknown\n): Promise<Hex> => {\n const json = JSON.stringify(typedDataPayload);\n const attempts: ReadonlyArray<{\n method: string;\n params: readonly unknown[];\n }> = [\n { method: \"eth_signTypedData_v4\", params: [account, json] },\n { method: \"eth_signTypedData_v3\", params: [account, json] },\n { method: \"eth_signTypedData\", params: [account, typedDataPayload] },\n ];\n\n let lastError: unknown;\n for (const attempt of attempts) {\n try {\n return await requestHex(provider, attempt.method, [...attempt.params]);\n } catch (e) {\n if (isUserRejection(e)) {\n throw e;\n }\n lastError = e;\n\n const shouldTryNext = attempt.method !== \"eth_signTypedData\" && isMethodNotFound(e);\n\n if (!shouldTryNext) {\n throw e;\n }\n }\n }\n\n throw lastError;\n};\n\n/**\n * Sign a message using the wallet's personal_sign method\n */\nexport function signMessage(\n provider: WalletProvider,\n params: SignMessageParams\n): Effect.Effect<Hex, SignMessageError | AccountNotConnectedError> {\n return Effect.gen(function* () {\n // Get the current account if not provided\n const account =\n params.account ??\n (yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get wallet account\",\n }),\n try: async () => {\n const accounts = (await provider.request({\n method: \"eth_accounts\",\n })) as Address[];\n if (accounts.length === 0) {\n throw new Error(\"No wallet account connected\");\n }\n return accounts[0];\n },\n }));\n\n // Prepare the message\n const message = typeof params.message === \"string\" ? params.message : params.message.raw;\n\n // Sign the message\n return yield* Effect.tryPromise({\n catch: (cause) => {\n const errorMessage = messageOf(cause) || \"Failed to sign message\";\n const isRejection = isLikelyUserRejection(cause);\n return new SignMessageError({\n cause,\n message: isRejection ? \"User rejected the request\" : errorMessage,\n });\n },\n try: async () => {\n try {\n const result = await provider.request({\n method: \"personal_sign\",\n params: [message, account],\n });\n return result as Hex;\n } catch (e) {\n if (isUserRejection(e)) {\n throw e;\n }\n\n if (!isInvalidParams(e)) {\n throw e;\n }\n\n // Fallback for providers that expect reversed parameter order.\n const result = await provider.request({\n method: \"personal_sign\",\n params: [account, message],\n });\n return result as Hex;\n }\n },\n });\n }).pipe(\n Effect.withSpan(SpanNames.WALLET_SIGN_MESSAGE, {\n attributes: {\n account: params.account,\n },\n })\n );\n}\n\n/**\n * Sign typed data using the wallet's eth_signTypedData_v4 method\n */\nexport function signTypedData<\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\",\n>(\n provider: WalletProvider,\n params: SignTypedDataParams<typedData, primaryType>\n): Effect.Effect<Hex, SignTypedDataError | AccountNotConnectedError> {\n return Effect.gen(function* () {\n // Get the current account if not provided\n const account =\n params.account ??\n (yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get wallet account\",\n }),\n try: async () => {\n const accounts = (await provider.request({\n method: \"eth_accounts\",\n })) as Address[];\n if (accounts.length === 0) {\n throw new Error(\"No wallet account connected\");\n }\n return accounts[0];\n },\n }));\n\n // Prepare the typed data payload\n const typedDataPayload = {\n domain: params.domain,\n message: params.message,\n primaryType: params.primaryType,\n types: params.types,\n };\n\n // Sign the typed data\n return yield* Effect.tryPromise({\n catch: (cause) => {\n const errorMessage = messageOf(cause) || \"Failed to sign typed data\";\n const isRejection = isLikelyUserRejection(cause);\n return new SignTypedDataError({\n cause,\n message: isRejection ? \"User rejected the request\" : errorMessage,\n });\n },\n try: async () => await signTypedDataFallbacks(provider, account, typedDataPayload),\n });\n }).pipe(\n Effect.withSpan(SpanNames.WALLET_SIGN_TYPED_DATA, {\n attributes: {\n account: params.account,\n primaryType: params.primaryType,\n },\n })\n );\n}\n\n/**\n * Sign a transaction using the wallet's eth_signTransaction method\n */\nexport function signTransaction(\n provider: WalletProvider,\n params: SignTransactionParams\n): Effect.Effect<Hex, SignTxError | AccountNotConnectedError> {\n return Effect.gen(function* () {\n // Get the current account if not provided\n const account =\n params.from ??\n (yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get wallet account\",\n }),\n try: async () => {\n const accounts = (await provider.request({\n method: \"eth_accounts\",\n })) as Address[];\n if (accounts.length === 0) {\n throw new Error(\"No wallet account connected\");\n }\n return accounts[0];\n },\n }));\n\n // Sign the transaction\n return yield* Effect.tryPromise({\n catch: (cause) => {\n const errorMessage = cause instanceof Error ? cause.message : \"Failed to sign transaction\";\n const isRejection = isLikelyUserRejection(cause);\n return new SignTxError({\n cause,\n message: isRejection ? \"User rejected the request\" : errorMessage,\n });\n },\n try: async () => {\n const result = await provider.request({\n method: \"eth_signTransaction\",\n params: [{ ...params, from: account }],\n });\n return result as Hex;\n },\n });\n });\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { Context, Effect, Layer, Stream } from "effect";
2
2
  import type { Address, Hex, TypedData } from "viem";
3
- import type { SignMessageError, SignMessageParams, SignTransactionError, SignTransactionParams, SignTypedDataError, SignTypedDataParams, WalletProvider } from "../wallet/index.js";
3
+ import type { SignMessageError, SignMessageParams, SignTransactionParams, SignTxError, SignTypedDataError, SignTypedDataParams, WalletProvider } from "../wallet/index.js";
4
4
  import { AccountNotConnectedError, WalletProviderRef } from "../wallet/index.js";
5
5
  export declare const UNKNOWN_CHAIN_ID = 0;
6
6
  export type WalletServiceShape = {
@@ -10,7 +10,7 @@ export type WalletServiceShape = {
10
10
  readonly currentChainId: Effect.Effect<number, AccountNotConnectedError>;
11
11
  readonly signMessage: (params: SignMessageParams) => Effect.Effect<Hex, SignMessageError | AccountNotConnectedError>;
12
12
  readonly signTypedData: <const typedData extends TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain">(params: SignTypedDataParams<typedData, primaryType>) => Effect.Effect<Hex, SignTypedDataError | AccountNotConnectedError>;
13
- readonly signTransaction: (params: SignTransactionParams) => Effect.Effect<Hex, SignTransactionError | AccountNotConnectedError>;
13
+ readonly signTransaction: (params: SignTransactionParams) => Effect.Effect<Hex, SignTxError | AccountNotConnectedError>;
14
14
  };
15
15
  declare const WalletService_base: Context.TagClass<WalletService, "ew3/WalletService", WalletServiceShape>;
16
16
  export declare class WalletService extends WalletService_base {
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/wallet/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,wBAAwB,EAIxB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,eAAO,MAAM,gBAAgB,IAAI,CAAC;AA+ElC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CA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AKF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAC3C,aAAa,EACb,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;IAGf,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;AAC/F,CAAC,CAAC,CACH,CAAC","sourcesContent":["import { Context, Effect, Layer, Option, Stream } from \"effect\";\nimport type { Address, Hex, TypedData } from \"viem\";\nimport { parseHexInt } from \"@/src/internal/index.js\";\nimport type {\n SignMessageError,\n SignMessageParams,\n SignTransactionError,\n SignTransactionParams,\n SignTypedDataError,\n SignTypedDataParams,\n WalletProvider,\n} from \"@/src/wallet/index.js\";\nimport {\n AccountNotConnectedError,\n signMessage,\n signTransaction,\n signTypedData,\n WalletProviderRef,\n} from \"@/src/wallet/index.js\";\n\nexport const UNKNOWN_CHAIN_ID = 0;\n\nconst accountsStreamFromProvider = (provider: WalletProvider) =>\n Stream.async<Address[], never>((emit) => {\n provider\n .request({ method: \"eth_accounts\" })\n .then((result) => {\n const accounts = (result as Address[]) || [];\n emit.single(accounts);\n })\n .catch(() => {\n emit.single([]);\n });\n\n const handleAccountsChanged = (...args: unknown[]) => {\n const accounts = args[0] as Address[];\n emit.single(accounts);\n };\n\n if (\"on\" in provider && typeof provider.on === \"function\") {\n (\n provider as {\n on: (event: string, handler: (...args: unknown[]) => void) => void;\n }\n ).on(\"accountsChanged\", handleAccountsChanged);\n }\n\n return Effect.sync(() => {\n if (\"removeListener\" in provider && typeof provider.removeListener === \"function\") {\n (\n provider as {\n removeListener: (event: string, handler: (...args: unknown[]) => void) => void;\n }\n ).removeListener(\"accountsChanged\", handleAccountsChanged);\n }\n });\n });\n\nconst chainIdStreamFromProvider = (provider: WalletProvider) =>\n Stream.async<number, never>((emit) => {\n provider\n .request({ method: \"eth_chainId\" })\n .then((result) => {\n const chainIdHex = result as string;\n const parsed = Option.getOrElse(parseHexInt(chainIdHex), () => UNKNOWN_CHAIN_ID);\n emit.single(parsed);\n })\n .catch(() => {\n emit.single(UNKNOWN_CHAIN_ID);\n });\n\n const handleChainChanged = (...args: unknown[]) => {\n const chainIdHex = args[0] as string;\n const parsed = Option.getOrElse(parseHexInt(chainIdHex), () => UNKNOWN_CHAIN_ID);\n emit.single(parsed);\n };\n\n if (\"on\" in provider && typeof provider.on === \"function\") {\n (\n provider as {\n on: (event: string, handler: (...args: unknown[]) => void) => void;\n }\n ).on(\"chainChanged\", handleChainChanged);\n }\n\n return Effect.sync(() => {\n if (\"removeListener\" in provider && typeof provider.removeListener === \"function\") {\n (\n provider as {\n removeListener: (event: string, handler: (...args: unknown[]) => void) => void;\n }\n ).removeListener(\"chainChanged\", handleChainChanged);\n }\n });\n });\n\n/**\n * Service for wallet account management and signing operations\n */\nexport type WalletServiceShape = {\n readonly accounts: Effect.Effect<Stream.Stream<Address[], never>, never>;\n readonly currentAccount: Effect.Effect<Address, AccountNotConnectedError>;\n readonly chainId: Effect.Effect<Stream.Stream<number, never>, never>;\n readonly currentChainId: Effect.Effect<number, AccountNotConnectedError>;\n readonly signMessage: (\n params: SignMessageParams\n ) => Effect.Effect<Hex, SignMessageError | AccountNotConnectedError>;\n readonly signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\",\n >(\n params: SignTypedDataParams<typedData, primaryType>\n ) => Effect.Effect<Hex, SignTypedDataError | AccountNotConnectedError>;\n readonly signTransaction: (\n params: SignTransactionParams\n ) => Effect.Effect<Hex, SignTransactionError | AccountNotConnectedError>;\n};\n\nexport class WalletService extends Context.Tag(\"ew3/WalletService\")<\n WalletService,\n WalletServiceShape\n>() {}\n\n/**\n * Create a live implementation of WalletService\n */\nexport function makeWalletServiceLive(provider: WalletProvider): Layer.Layer<WalletService> {\n return Layer.succeed(WalletService, {\n accounts: Effect.succeed(accountsStreamFromProvider(provider)),\n\n chainId: Effect.succeed(chainIdStreamFromProvider(provider)),\n\n currentAccount: Effect.gen(function* () {\n const accounts = yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get accounts\",\n }),\n try: async () => {\n const result = await provider.request({\n method: \"eth_accounts\",\n });\n return result as Address[];\n },\n });\n\n if (accounts.length === 0) {\n return yield* Effect.fail(\n new AccountNotConnectedError({\n message: \"No wallet account connected\",\n })\n );\n }\n\n return accounts[0];\n }),\n\n currentChainId: Effect.gen(function* () {\n const chainIdHex = yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get chain ID\",\n }),\n try: async () => {\n const result = await provider.request({\n method: \"eth_chainId\",\n });\n return result as string;\n },\n });\n\n return Option.getOrElse(parseHexInt(chainIdHex), () => UNKNOWN_CHAIN_ID);\n }),\n\n signMessage: (params: SignMessageParams) => signMessage(provider, params),\n\n signTransaction: (params: SignTransactionParams) => signTransaction(provider, params),\n\n signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\",\n >(\n params: SignTypedDataParams<typedData, primaryType>\n ) => signTypedData(provider, params),\n });\n}\n\nexport const WalletServiceFromProviderRefLive = Layer.effect(\n WalletService,\n Effect.gen(function* () {\n const providerRef = yield* WalletProviderRef;\n\n const getProviderOrFail = Effect.gen(function* () {\n const current = yield* providerRef.get;\n if (Option.isNone(current)) {\n return yield* Effect.fail(\n new AccountNotConnectedError({\n message: \"No wallet provider set\",\n })\n );\n }\n return current.value;\n });\n\n const accountsStream = providerRef.ref.changes.pipe(\n Stream.flatMap(\n (current) =>\n Option.isNone(current)\n ? Stream.succeed([] as Address[])\n : accountsStreamFromProvider(current.value),\n { switch: true }\n )\n );\n\n const chainIdStream = providerRef.ref.changes.pipe(\n Stream.flatMap(\n (current) =>\n Option.isNone(current)\n ? Stream.succeed(UNKNOWN_CHAIN_ID)\n : chainIdStreamFromProvider(current.value),\n { switch: true }\n )\n );\n\n return WalletService.of({\n accounts: Effect.succeed(accountsStream),\n chainId: Effect.succeed(chainIdStream),\n\n currentAccount: Effect.gen(function* () {\n const provider = yield* getProviderOrFail;\n const accounts = yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get accounts\",\n }),\n try: async () => {\n const result = await provider.request({ method: \"eth_accounts\" });\n return result as Address[];\n },\n });\n\n if (accounts.length === 0) {\n return yield* Effect.fail(\n new AccountNotConnectedError({\n message: \"No wallet account connected\",\n })\n );\n }\n\n return accounts[0];\n }),\n\n currentChainId: Effect.gen(function* () {\n const provider = yield* getProviderOrFail;\n const chainIdHex = yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get chain ID\",\n }),\n try: async () => {\n const result = await provider.request({ method: \"eth_chainId\" });\n return result as string;\n },\n });\n\n return Option.getOrElse(parseHexInt(chainIdHex), () => UNKNOWN_CHAIN_ID);\n }),\n\n signMessage: (params) =>\n getProviderOrFail.pipe(Effect.flatMap((provider) => signMessage(provider, params))),\n\n signTransaction: (params) =>\n getProviderOrFail.pipe(Effect.flatMap((provider) => signTransaction(provider, params))),\n\n signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\",\n >(\n params: SignTypedDataParams<typedData, primaryType>\n ) => getProviderOrFail.pipe(Effect.flatMap((provider) => signTypedData(provider, params))),\n });\n })\n);\n\n/**\n * Default live layer that requires a WalletProvider to be provided separately\n */\nexport const WalletServiceLive = Layer.effect(\n WalletService,\n Effect.sync(() => {\n // This is a placeholder that will be replaced by makeWalletServiceLive\n // when a provider is available\n throw new Error(\"WalletServiceLive requires a provider. Use makeWalletServiceLive instead.\");\n })\n);\n"]}
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/wallet/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhE,OAAO,E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,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QAErF,eAAe,EAAE,CAAC,MAAM,EAAE,EAAE,CAC1B,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;QAEzF,aAAa,EAAE,CAIb,MAAmD,EACnD,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;KAC3F,CAAC,CAAC;AACL,CAAC,CAAC,CACH,CAAC;AAKF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAC3C,aAAa,EACb,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;IAGf,MAAM,IAAI,KAAK,CAAC,2EAA2E,CAAC,CAAC;AAC/F,CAAC,CAAC,CACH,CAAC","sourcesContent":["import { Context, Effect, Layer, Option, Stream } from \"effect\";\nimport type { Address, Hex, TypedData } from \"viem\";\nimport { parseHexInt } from \"@/src/internal/index.js\";\nimport type {\n SignMessageError,\n SignMessageParams,\n SignTransactionParams,\n SignTxError,\n SignTypedDataError,\n SignTypedDataParams,\n WalletProvider,\n} from \"@/src/wallet/index.js\";\nimport {\n AccountNotConnectedError,\n signMessage,\n signTransaction,\n signTypedData,\n WalletProviderRef,\n} from \"@/src/wallet/index.js\";\n\nexport const UNKNOWN_CHAIN_ID = 0;\n\nconst accountsStreamFromProvider = (provider: WalletProvider) =>\n Stream.async<Address[], never>((emit) => {\n provider\n .request({ method: \"eth_accounts\" })\n .then((result) => {\n const accounts = (result as Address[]) || [];\n emit.single(accounts);\n })\n .catch(() => {\n emit.single([]);\n });\n\n const handleAccountsChanged = (...args: unknown[]) => {\n const accounts = args[0] as Address[];\n emit.single(accounts);\n };\n\n if (\"on\" in provider && typeof provider.on === \"function\") {\n (\n provider as {\n on: (event: string, handler: (...args: unknown[]) => void) => void;\n }\n ).on(\"accountsChanged\", handleAccountsChanged);\n }\n\n return Effect.sync(() => {\n if (\"removeListener\" in provider && typeof provider.removeListener === \"function\") {\n (\n provider as {\n removeListener: (event: string, handler: (...args: unknown[]) => void) => void;\n }\n ).removeListener(\"accountsChanged\", handleAccountsChanged);\n }\n });\n });\n\nconst chainIdStreamFromProvider = (provider: WalletProvider) =>\n Stream.async<number, never>((emit) => {\n provider\n .request({ method: \"eth_chainId\" })\n .then((result) => {\n const chainIdHex = result as string;\n const parsed = Option.getOrElse(parseHexInt(chainIdHex), () => UNKNOWN_CHAIN_ID);\n emit.single(parsed);\n })\n .catch(() => {\n emit.single(UNKNOWN_CHAIN_ID);\n });\n\n const handleChainChanged = (...args: unknown[]) => {\n const chainIdHex = args[0] as string;\n const parsed = Option.getOrElse(parseHexInt(chainIdHex), () => UNKNOWN_CHAIN_ID);\n emit.single(parsed);\n };\n\n if (\"on\" in provider && typeof provider.on === \"function\") {\n (\n provider as {\n on: (event: string, handler: (...args: unknown[]) => void) => void;\n }\n ).on(\"chainChanged\", handleChainChanged);\n }\n\n return Effect.sync(() => {\n if (\"removeListener\" in provider && typeof provider.removeListener === \"function\") {\n (\n provider as {\n removeListener: (event: string, handler: (...args: unknown[]) => void) => void;\n }\n ).removeListener(\"chainChanged\", handleChainChanged);\n }\n });\n });\n\n/**\n * Service for wallet account management and signing operations\n */\nexport type WalletServiceShape = {\n readonly accounts: Effect.Effect<Stream.Stream<Address[], never>, never>;\n readonly currentAccount: Effect.Effect<Address, AccountNotConnectedError>;\n readonly chainId: Effect.Effect<Stream.Stream<number, never>, never>;\n readonly currentChainId: Effect.Effect<number, AccountNotConnectedError>;\n readonly signMessage: (\n params: SignMessageParams\n ) => Effect.Effect<Hex, SignMessageError | AccountNotConnectedError>;\n readonly signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\",\n >(\n params: SignTypedDataParams<typedData, primaryType>\n ) => Effect.Effect<Hex, SignTypedDataError | AccountNotConnectedError>;\n readonly signTransaction: (\n params: SignTransactionParams\n ) => Effect.Effect<Hex, SignTxError | AccountNotConnectedError>;\n};\n\nexport class WalletService extends Context.Tag(\"ew3/WalletService\")<\n WalletService,\n WalletServiceShape\n>() {}\n\n/**\n * Create a live implementation of WalletService\n */\nexport function makeWalletServiceLive(provider: WalletProvider): Layer.Layer<WalletService> {\n return Layer.succeed(WalletService, {\n accounts: Effect.succeed(accountsStreamFromProvider(provider)),\n\n chainId: Effect.succeed(chainIdStreamFromProvider(provider)),\n\n currentAccount: Effect.gen(function* () {\n const accounts = yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get accounts\",\n }),\n try: async () => {\n const result = await provider.request({\n method: \"eth_accounts\",\n });\n return result as Address[];\n },\n });\n\n if (accounts.length === 0) {\n return yield* Effect.fail(\n new AccountNotConnectedError({\n message: \"No wallet account connected\",\n })\n );\n }\n\n return accounts[0];\n }),\n\n currentChainId: Effect.gen(function* () {\n const chainIdHex = yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get chain ID\",\n }),\n try: async () => {\n const result = await provider.request({\n method: \"eth_chainId\",\n });\n return result as string;\n },\n });\n\n return Option.getOrElse(parseHexInt(chainIdHex), () => UNKNOWN_CHAIN_ID);\n }),\n\n signMessage: (params: SignMessageParams) => signMessage(provider, params),\n\n signTransaction: (params: SignTransactionParams) => signTransaction(provider, params),\n\n signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\",\n >(\n params: SignTypedDataParams<typedData, primaryType>\n ) => signTypedData(provider, params),\n });\n}\n\nexport const WalletServiceFromProviderRefLive = Layer.effect(\n WalletService,\n Effect.gen(function* () {\n const providerRef = yield* WalletProviderRef;\n\n const getProviderOrFail = Effect.gen(function* () {\n const current = yield* providerRef.get;\n if (Option.isNone(current)) {\n return yield* Effect.fail(\n new AccountNotConnectedError({\n message: \"No wallet provider set\",\n })\n );\n }\n return current.value;\n });\n\n const accountsStream = providerRef.ref.changes.pipe(\n Stream.flatMap(\n (current) =>\n Option.isNone(current)\n ? Stream.succeed([] as Address[])\n : accountsStreamFromProvider(current.value),\n { switch: true }\n )\n );\n\n const chainIdStream = providerRef.ref.changes.pipe(\n Stream.flatMap(\n (current) =>\n Option.isNone(current)\n ? Stream.succeed(UNKNOWN_CHAIN_ID)\n : chainIdStreamFromProvider(current.value),\n { switch: true }\n )\n );\n\n return WalletService.of({\n accounts: Effect.succeed(accountsStream),\n chainId: Effect.succeed(chainIdStream),\n\n currentAccount: Effect.gen(function* () {\n const provider = yield* getProviderOrFail;\n const accounts = yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get accounts\",\n }),\n try: async () => {\n const result = await provider.request({ method: \"eth_accounts\" });\n return result as Address[];\n },\n });\n\n if (accounts.length === 0) {\n return yield* Effect.fail(\n new AccountNotConnectedError({\n message: \"No wallet account connected\",\n })\n );\n }\n\n return accounts[0];\n }),\n\n currentChainId: Effect.gen(function* () {\n const provider = yield* getProviderOrFail;\n const chainIdHex = yield* Effect.tryPromise({\n catch: (error) =>\n new AccountNotConnectedError({\n message: error instanceof Error ? error.message : \"Failed to get chain ID\",\n }),\n try: async () => {\n const result = await provider.request({ method: \"eth_chainId\" });\n return result as string;\n },\n });\n\n return Option.getOrElse(parseHexInt(chainIdHex), () => UNKNOWN_CHAIN_ID);\n }),\n\n signMessage: (params) =>\n getProviderOrFail.pipe(Effect.flatMap((provider) => signMessage(provider, params))),\n\n signTransaction: (params) =>\n getProviderOrFail.pipe(Effect.flatMap((provider) => signTransaction(provider, params))),\n\n signTypedData: <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\",\n >(\n params: SignTypedDataParams<typedData, primaryType>\n ) => getProviderOrFail.pipe(Effect.flatMap((provider) => signTypedData(provider, params))),\n });\n })\n);\n\n/**\n * Default live layer that requires a WalletProvider to be provided separately\n */\nexport const WalletServiceLive = Layer.effect(\n WalletService,\n Effect.sync(() => {\n // This is a placeholder that will be replaced by makeWalletServiceLive\n // when a provider is available\n throw new Error(\"WalletServiceLive requires a provider. Use makeWalletServiceLive instead.\");\n })\n);\n"]}
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "sideEffects": false,
7
7
  "type": "module",
8
8
  "types": "./dist/index.d.ts",
9
- "version": "1.0.0-beta.4",
9
+ "version": "1.0.0-beta.6",
10
10
  "scripts": {
11
11
  "build": "just build",
12
12
  "prepack": "bun install --frozen-lockfile && just build"
@@ -29,7 +29,6 @@
29
29
  "@effect/platform": "catalog:effect",
30
30
  "@effect/vitest": "catalog:dev",
31
31
  "@sablier/devkit": "catalog:dev",
32
- "@safe-global/safe-apps-sdk": "9.1.0",
33
32
  "@types/node": "catalog:dev",
34
33
  "@types/react": "catalog:dev",
35
34
  "@types/react-dom": "catalog:dev",
@@ -76,7 +75,6 @@
76
75
  ],
77
76
  "peerDependencies": {
78
77
  "@effect/platform": "catalog:peers",
79
- "@safe-global/safe-apps-sdk": "catalog:peers",
80
78
  "@wagmi/core": "catalog:peers",
81
79
  "effect": "catalog:peers",
82
80
  "react": "catalog:peers",
@@ -84,9 +82,6 @@
84
82
  "viem": "catalog:peers"
85
83
  },
86
84
  "peerDependenciesMeta": {
87
- "@safe-global/safe-apps-sdk": {
88
- "optional": true
89
- },
90
85
  "@wagmi/core": {
91
86
  "optional": true
92
87
  },
@@ -1,8 +0,0 @@
1
- export declare const DEFAULT_SAFE_ORIGINS: readonly ["https://app.safe.global", "https://gnosis-safe.io", "https://safe.global", "https://safe.berachain.com", "https://safe.chiliz.com", "https://safe.lightlink.io", "https://safe.optimism.io"];
2
- export declare function setSafeOrigins(origins: readonly string[]): void;
3
- export declare function extendSafeOrigins(origins: readonly string[]): void;
4
- export declare function getSafeOrigins(): readonly string[];
5
- export declare function subscribeSafeOrigins(listener: () => void): () => void;
6
- export declare function isValidSafeOrigin(): boolean;
7
- export declare function isHostEmbedded(): boolean;
8
- //# sourceMappingURL=safe-origins.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"safe-origins.d.ts","sourceRoot":"","sources":["../../src/react-hooks/safe-origins.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,oBAAoB,yMAUvB,CAAC;AASX,wBAAgB,cAAc,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,QAExD;AAGD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,QAE3D;AAGD,wBAAgB,cAAc,IAAI,SAAS,MAAM,EAAE,CAElD;AAGD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAKrE;AAGD,wBAAgB,iBAAiB,IAAI,OAAO,CAM3C;AAGD,wBAAgB,cAAc,IAAI,OAAO,CAExC"}