@atomiqlabs/chain-evm 2.1.11 → 2.1.14

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 (151) hide show
  1. package/README.md +75 -0
  2. package/dist/chains/EVMOptions.d.ts +66 -0
  3. package/dist/chains/EVMOptions.js +2 -0
  4. package/dist/chains/alpen/AlpenInitializer.d.ts +3 -30
  5. package/dist/chains/alpen/AlpenInitializer.js +3 -3
  6. package/dist/chains/botanix/BotanixInitializer.d.ts +3 -30
  7. package/dist/chains/botanix/BotanixInitializer.js +3 -3
  8. package/dist/chains/citrea/CitreaBtcRelay.d.ts +5 -0
  9. package/dist/chains/citrea/CitreaBtcRelay.js +7 -2
  10. package/dist/chains/citrea/CitreaFees.d.ts +3 -5
  11. package/dist/chains/citrea/CitreaFees.js +3 -5
  12. package/dist/chains/citrea/CitreaInitializer.d.ts +3 -29
  13. package/dist/chains/citrea/CitreaInitializer.js +3 -3
  14. package/dist/chains/citrea/CitreaSpvVaultContract.d.ts +5 -0
  15. package/dist/chains/citrea/CitreaSpvVaultContract.js +7 -2
  16. package/dist/chains/citrea/CitreaSwapContract.d.ts +7 -2
  17. package/dist/chains/citrea/CitreaSwapContract.js +10 -5
  18. package/dist/chains/citrea/CitreaTokens.d.ts +5 -0
  19. package/dist/chains/citrea/CitreaTokens.js +5 -0
  20. package/dist/chains/goat/GoatInitializer.d.ts +3 -30
  21. package/dist/chains/goat/GoatInitializer.js +3 -3
  22. package/dist/evm/btcrelay/EVMBtcRelay.d.ts +41 -10
  23. package/dist/evm/btcrelay/EVMBtcRelay.js +50 -18
  24. package/dist/evm/btcrelay/headers/EVMBtcHeader.d.ts +53 -7
  25. package/dist/evm/btcrelay/headers/EVMBtcHeader.js +43 -5
  26. package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.d.ts +53 -8
  27. package/dist/evm/btcrelay/headers/EVMBtcStoredHeader.js +41 -1
  28. package/dist/evm/chain/EVMChainInterface.d.ts +57 -2
  29. package/dist/evm/chain/EVMChainInterface.js +7 -7
  30. package/dist/evm/chain/EVMModule.d.ts +5 -0
  31. package/dist/evm/chain/EVMModule.js +6 -1
  32. package/dist/evm/chain/modules/EVMBlocks.d.ts +7 -0
  33. package/dist/evm/chain/modules/EVMBlocks.js +2 -0
  34. package/dist/evm/chain/modules/EVMEvents.js +19 -19
  35. package/dist/evm/chain/modules/EVMFees.d.ts +41 -5
  36. package/dist/evm/chain/modules/EVMFees.js +24 -5
  37. package/dist/evm/chain/modules/EVMTokens.d.ts +1 -1
  38. package/dist/evm/chain/modules/EVMTokens.js +1 -1
  39. package/dist/evm/chain/modules/EVMTransactions.d.ts +20 -2
  40. package/dist/evm/chain/modules/EVMTransactions.js +11 -8
  41. package/dist/evm/contract/EVMContractBase.d.ts +28 -10
  42. package/dist/evm/contract/EVMContractBase.js +9 -18
  43. package/dist/evm/contract/EVMContractModule.d.ts +5 -0
  44. package/dist/evm/contract/EVMContractModule.js +5 -0
  45. package/dist/evm/contract/modules/EVMContractEvents.d.ts +7 -1
  46. package/dist/evm/contract/modules/EVMContractEvents.js +23 -3
  47. package/dist/evm/events/EVMChainEvents.d.ts +8 -0
  48. package/dist/evm/events/EVMChainEvents.js +8 -0
  49. package/dist/evm/events/EVMChainEventsBrowser.d.ts +87 -19
  50. package/dist/evm/events/EVMChainEventsBrowser.js +53 -18
  51. package/dist/evm/providers/JsonRpcProviderWithRetries.d.ts +9 -0
  52. package/dist/evm/providers/JsonRpcProviderWithRetries.js +9 -0
  53. package/dist/evm/providers/ReconnectingWebSocketProvider.d.ts +5 -0
  54. package/dist/evm/providers/ReconnectingWebSocketProvider.js +5 -0
  55. package/dist/evm/providers/WebSocketProviderWithRetries.d.ts +9 -0
  56. package/dist/evm/providers/WebSocketProviderWithRetries.js +9 -0
  57. package/dist/evm/spv_swap/EVMSpvVaultContract.d.ts +46 -21
  58. package/dist/evm/spv_swap/EVMSpvVaultContract.js +62 -22
  59. package/dist/evm/spv_swap/EVMSpvVaultData.d.ts +57 -2
  60. package/dist/evm/spv_swap/EVMSpvVaultData.js +57 -2
  61. package/dist/evm/spv_swap/EVMSpvWithdrawalData.d.ts +12 -0
  62. package/dist/evm/spv_swap/EVMSpvWithdrawalData.js +12 -0
  63. package/dist/evm/swaps/EVMSwapContract.d.ts +58 -13
  64. package/dist/evm/swaps/EVMSwapContract.js +81 -54
  65. package/dist/evm/swaps/EVMSwapData.d.ts +27 -6
  66. package/dist/evm/swaps/EVMSwapData.js +26 -0
  67. package/dist/evm/swaps/EVMSwapModule.d.ts +5 -0
  68. package/dist/evm/swaps/EVMSwapModule.js +5 -0
  69. package/dist/evm/swaps/handlers/IHandler.d.ts +5 -0
  70. package/dist/evm/swaps/handlers/claim/ClaimHandlers.d.ts +15 -0
  71. package/dist/evm/swaps/handlers/claim/ClaimHandlers.js +5 -0
  72. package/dist/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.d.ts +5 -0
  73. package/dist/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.d.ts +10 -0
  74. package/dist/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.d.ts +5 -0
  75. package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.d.ts +15 -0
  76. package/dist/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.js +7 -2
  77. package/dist/evm/swaps/modules/EVMLpVault.d.ts +5 -0
  78. package/dist/evm/swaps/modules/EVMLpVault.js +9 -4
  79. package/dist/evm/swaps/modules/EVMSwapClaim.d.ts +7 -2
  80. package/dist/evm/swaps/modules/EVMSwapClaim.js +11 -6
  81. package/dist/evm/swaps/modules/EVMSwapInit.d.ts +10 -0
  82. package/dist/evm/swaps/modules/EVMSwapInit.js +11 -6
  83. package/dist/evm/swaps/modules/EVMSwapRefund.d.ts +5 -0
  84. package/dist/evm/swaps/modules/EVMSwapRefund.js +9 -4
  85. package/dist/evm/wallet/EVMBrowserSigner.d.ts +22 -2
  86. package/dist/evm/wallet/EVMBrowserSigner.js +40 -2
  87. package/dist/evm/wallet/EVMPersistentSigner.d.ts +13 -2
  88. package/dist/evm/wallet/EVMPersistentSigner.js +13 -1
  89. package/dist/evm/wallet/EVMSigner.d.ts +30 -1
  90. package/dist/evm/wallet/EVMSigner.js +34 -1
  91. package/dist/index.d.ts +71 -0
  92. package/dist/index.js +70 -0
  93. package/dist/node/index.d.ts +10 -0
  94. package/dist/node/index.js +15 -0
  95. package/dist/utils/Utils.d.ts +50 -0
  96. package/dist/utils/Utils.js +45 -0
  97. package/node/index.d.ts +1 -0
  98. package/node/index.js +3 -0
  99. package/package.json +4 -3
  100. package/src/chains/EVMOptions.ts +70 -0
  101. package/src/chains/alpen/AlpenInitializer.ts +5 -27
  102. package/src/chains/botanix/BotanixChainType.ts +5 -5
  103. package/src/chains/botanix/BotanixInitializer.ts +5 -27
  104. package/src/chains/citrea/CitreaBtcRelay.ts +8 -3
  105. package/src/chains/citrea/CitreaFees.ts +3 -6
  106. package/src/chains/citrea/CitreaInitializer.ts +5 -27
  107. package/src/chains/citrea/CitreaSpvVaultContract.ts +7 -2
  108. package/src/chains/citrea/CitreaSwapContract.ts +11 -6
  109. package/src/chains/citrea/CitreaTokens.ts +6 -1
  110. package/src/chains/goat/GoatChainType.ts +5 -5
  111. package/src/chains/goat/GoatInitializer.ts +3 -25
  112. package/src/evm/btcrelay/EVMBtcRelay.ts +54 -22
  113. package/src/evm/btcrelay/headers/EVMBtcHeader.ts +60 -13
  114. package/src/evm/btcrelay/headers/EVMBtcStoredHeader.ts +55 -10
  115. package/src/evm/chain/EVMChainInterface.ts +66 -14
  116. package/src/evm/chain/EVMModule.ts +6 -1
  117. package/src/evm/chain/modules/EVMBlocks.ts +7 -0
  118. package/src/evm/chain/modules/EVMEvents.ts +19 -19
  119. package/src/evm/chain/modules/EVMFees.ts +41 -5
  120. package/src/evm/chain/modules/EVMTokens.ts +1 -1
  121. package/src/evm/chain/modules/EVMTransactions.ts +27 -8
  122. package/src/evm/contract/EVMContractBase.ts +29 -24
  123. package/src/evm/contract/EVMContractModule.ts +5 -0
  124. package/src/evm/contract/modules/EVMContractEvents.ts +27 -8
  125. package/src/evm/events/EVMChainEvents.ts +8 -0
  126. package/src/evm/events/EVMChainEventsBrowser.ts +103 -29
  127. package/src/evm/providers/JsonRpcProviderWithRetries.ts +10 -1
  128. package/src/evm/providers/ReconnectingWebSocketProvider.ts +6 -1
  129. package/src/evm/providers/WebSocketProviderWithRetries.ts +10 -1
  130. package/src/evm/spv_swap/EVMSpvVaultContract.ts +73 -31
  131. package/src/evm/spv_swap/EVMSpvVaultData.ts +57 -2
  132. package/src/evm/spv_swap/EVMSpvWithdrawalData.ts +12 -0
  133. package/src/evm/swaps/EVMSwapContract.ts +108 -63
  134. package/src/evm/swaps/EVMSwapData.ts +27 -1
  135. package/src/evm/swaps/EVMSwapModule.ts +5 -0
  136. package/src/evm/swaps/handlers/IHandler.ts +5 -0
  137. package/src/evm/swaps/handlers/claim/ClaimHandlers.ts +15 -0
  138. package/src/evm/swaps/handlers/claim/btc/BitcoinNoncedOutputClaimHandler.ts +5 -0
  139. package/src/evm/swaps/handlers/claim/btc/BitcoinOutputClaimHandler.ts +10 -0
  140. package/src/evm/swaps/handlers/claim/btc/BitcoinTxIdClaimHandler.ts +5 -0
  141. package/src/evm/swaps/handlers/claim/btc/IBitcoinClaimHandler.ts +17 -2
  142. package/src/evm/swaps/modules/EVMLpVault.ts +10 -5
  143. package/src/evm/swaps/modules/EVMSwapClaim.ts +12 -7
  144. package/src/evm/swaps/modules/EVMSwapInit.ts +17 -7
  145. package/src/evm/swaps/modules/EVMSwapRefund.ts +9 -4
  146. package/src/evm/wallet/EVMBrowserSigner.ts +44 -5
  147. package/src/evm/wallet/EVMPersistentSigner.ts +14 -2
  148. package/src/evm/wallet/EVMSigner.ts +37 -1
  149. package/src/index.ts +72 -0
  150. package/src/node/index.ts +10 -0
  151. package/src/utils/Utils.ts +50 -1
@@ -3,10 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EVMSigner = void 0;
4
4
  const ethers_1 = require("ethers");
5
5
  /**
6
- * EVM signer implementation wrapping an ethers Signer
6
+ * EVM signer implementation wrapping an ethers {@link Signer}, for browser-based wallet use
7
+ * {@link EVMBrowserSigner}.
8
+ *
7
9
  * @category Wallets
8
10
  */
9
11
  class EVMSigner {
12
+ /**
13
+ * Returns a static message, which should be signed by the EVM wallets to generate reproducible entropy. Works when
14
+ * wallets use signing with deterministic nonce, such that signature over the same message always yields the
15
+ * same signature (same entropy).
16
+ *
17
+ * @param appName Application name to differentiate reproducible entropy generated across different apps
18
+ */
19
+ static getReproducibleEntropyMessage(appName) {
20
+ return EVMSigner.EVM_REPRODUCIBLE_ENTROPY_MESSAGE.replace(new RegExp("%APPNAME%", 'g'), appName);
21
+ }
22
+ /**
23
+ * Constructs a signer wrapping an ethers {@link Signer}.
24
+ *
25
+ * @param account
26
+ * @param address
27
+ * @param isManagingNoncesInternally
28
+ */
10
29
  constructor(account, address, isManagingNoncesInternally = false) {
11
30
  this.type = "AtomiqAbstractSigner";
12
31
  this.account = account;
@@ -19,9 +38,15 @@ class EVMSigner {
19
38
  getAddress() {
20
39
  return (0, ethers_1.getAddress)(this.address);
21
40
  }
41
+ /**
42
+ * @inheritDoc
43
+ */
22
44
  async signTransaction(transaction) {
23
45
  return this.account.signTransaction(transaction);
24
46
  }
47
+ /**
48
+ * @inheritDoc
49
+ */
25
50
  async sendTransaction(transaction, onBeforePublish) {
26
51
  const txResponse = await this.account.sendTransaction(transaction);
27
52
  if (onBeforePublish != null)
@@ -33,3 +58,11 @@ class EVMSigner {
33
58
  }
34
59
  }
35
60
  exports.EVMSigner = EVMSigner;
61
+ /**
62
+ * A static message, which should be signed by the EVM wallets to generate reproducible entropy. Works when
63
+ * wallets use signing with deterministic nonce, such that signature over the same message always yields the
64
+ * same signature (same entropy).
65
+ */
66
+ EVMSigner.EVM_REPRODUCIBLE_ENTROPY_MESSAGE = "Signing this messages generates a reproducible secret to be used on %APPNAME%.\n\nPLEASE DOUBLE CHECK THAT YOU" +
67
+ " ARE ON THE %APPNAME% WEBSITE BEFORE SIGNING THE MESSAGE, SIGNING THIS MESSAGE ON ANY OTHER WEBSITE MIGHT LEAD TO" +
68
+ " LOSS OF FUNDS!";
package/dist/index.d.ts CHANGED
@@ -1,3 +1,73 @@
1
+ /**
2
+ * # @atomiqlabs/chain-evm
3
+ *
4
+ * `@atomiqlabs/chain-evm` is the EVM integration package for the Atomiq protocol.
5
+ *
6
+ * Within the Atomiq stack, this library provides the EVM-side building blocks used for Bitcoin-aware swaps and SPV-backed vault flows on supported EVM-compatible chains. It includes:
7
+ *
8
+ * - chain initializers for Atomiq-supported EVM networks
9
+ * - the `EVMChainInterface` used to talk to chain RPCs
10
+ * - BTC relay, escrow swap, and SPV vault contract wrappers
11
+ * - browser and server-side EVM signer helpers
12
+ * - event utilities for tracking swap and vault activity
13
+ *
14
+ * This package is intended for direct protocol integrations and for higher-level Atomiq SDK layers that need EVM chain support.
15
+ *
16
+ * ## Installation
17
+ *
18
+ * Install the package with its `ethers` peer dependency:
19
+ *
20
+ * ```bash
21
+ * npm install @atomiqlabs/chain-evm ethers
22
+ * ```
23
+ *
24
+ * ## Supported Chains
25
+ *
26
+ * The package currently exports chain initializers for:
27
+ *
28
+ * - Botanix via `BotanixInitializer`
29
+ * - Citrea via `CitreaInitializer`
30
+ * - Alpen via `AlpenInitializer`
31
+ * - GOAT Network via `GoatInitializer`
32
+ *
33
+ * Canonical deployments currently defined in this package:
34
+ *
35
+ * | Chain | Canonical deployments included |
36
+ * | --- | --- |
37
+ * | Botanix | `MAINNET`, `TESTNET` |
38
+ * | Citrea | `MAINNET`, `TESTNET4` |
39
+ * | Alpen | `TESTNET`, `TESTNET4` |
40
+ * | GOAT Network | `TESTNET`, `TESTNET4` |
41
+ *
42
+ * For Alpen and GOAT Network, `MAINNET` chain types exist in the API, but default mainnet contract addresses are not populated in this package yet. In those cases, pass explicit contract addresses if you want to use non-canonical deployments.
43
+ *
44
+ * ## SDK Example
45
+ *
46
+ * Initialize the atomiq SDK with Citrea network support:
47
+ *
48
+ * ```ts
49
+ * import {CitreaInitializer, CitreaInitializerType} from "@atomiqlabs/chain-evm";
50
+ * import {BitcoinNetwork, SwapperFactory, TypedSwapper} from "@atomiqlabs/sdk";
51
+ *
52
+ * //Define chains that you want to support here
53
+ * const chains = [CitreaInitializer] as const;
54
+ * type SupportedChains = typeof chains; //It's helpful that we also get the type of the chains array
55
+ *
56
+ * const Factory = new SwapperFactory<SupportedChains>(chains); //Create swapper factory
57
+ *
58
+ * const swapper: TypedSwapper<SupportedChains> = Factory.newSwapper({
59
+ * chains: {
60
+ * CITREA: {
61
+ * rpcUrl: citreaRpc, //You can also pass JsonApiProvider object here
62
+ * }
63
+ * },
64
+ * bitcoinNetwork: BitcoinNetwork.MAINNET //or BitcoinNetwork.TESTNET3, BitcoinNetwork.TESTNET4 - this also sets the deployment to use for EVM chains
65
+ * });
66
+ * ```
67
+ *
68
+ * @packageDocumentation
69
+ */
70
+ export * from "./chains/EVMOptions";
1
71
  export * from "./chains/citrea/CitreaInitializer";
2
72
  export * from "./chains/citrea/CitreaChainType";
3
73
  export * from "./chains/citrea/CitreaFees";
@@ -12,6 +82,7 @@ export { EVMBtcStoredHeader } from "./evm/btcrelay/headers/EVMBtcStoredHeader";
12
82
  export { EVMBtcRelay } from "./evm/btcrelay/EVMBtcRelay";
13
83
  export * from "./evm/chain/EVMChainInterface";
14
84
  export * from "./evm/chain/modules/EVMFees";
85
+ export { EVMTx, SignedEVMTx } from "./evm/chain/modules/EVMTransactions";
15
86
  export * from "./evm/events/EVMChainEventsBrowser";
16
87
  export * from "./evm/providers/JsonRpcProviderWithRetries";
17
88
  export * from "./evm/providers/WebSocketProviderWithRetries";
package/dist/index.js CHANGED
@@ -15,6 +15,76 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.EVMSpvVaultData = exports.EVMSpvWithdrawalData = exports.EVMSpvVaultContract = exports.EVMBtcRelay = exports.EVMBtcStoredHeader = exports.EVMBtcHeader = void 0;
18
+ /**
19
+ * # @atomiqlabs/chain-evm
20
+ *
21
+ * `@atomiqlabs/chain-evm` is the EVM integration package for the Atomiq protocol.
22
+ *
23
+ * Within the Atomiq stack, this library provides the EVM-side building blocks used for Bitcoin-aware swaps and SPV-backed vault flows on supported EVM-compatible chains. It includes:
24
+ *
25
+ * - chain initializers for Atomiq-supported EVM networks
26
+ * - the `EVMChainInterface` used to talk to chain RPCs
27
+ * - BTC relay, escrow swap, and SPV vault contract wrappers
28
+ * - browser and server-side EVM signer helpers
29
+ * - event utilities for tracking swap and vault activity
30
+ *
31
+ * This package is intended for direct protocol integrations and for higher-level Atomiq SDK layers that need EVM chain support.
32
+ *
33
+ * ## Installation
34
+ *
35
+ * Install the package with its `ethers` peer dependency:
36
+ *
37
+ * ```bash
38
+ * npm install @atomiqlabs/chain-evm ethers
39
+ * ```
40
+ *
41
+ * ## Supported Chains
42
+ *
43
+ * The package currently exports chain initializers for:
44
+ *
45
+ * - Botanix via `BotanixInitializer`
46
+ * - Citrea via `CitreaInitializer`
47
+ * - Alpen via `AlpenInitializer`
48
+ * - GOAT Network via `GoatInitializer`
49
+ *
50
+ * Canonical deployments currently defined in this package:
51
+ *
52
+ * | Chain | Canonical deployments included |
53
+ * | --- | --- |
54
+ * | Botanix | `MAINNET`, `TESTNET` |
55
+ * | Citrea | `MAINNET`, `TESTNET4` |
56
+ * | Alpen | `TESTNET`, `TESTNET4` |
57
+ * | GOAT Network | `TESTNET`, `TESTNET4` |
58
+ *
59
+ * For Alpen and GOAT Network, `MAINNET` chain types exist in the API, but default mainnet contract addresses are not populated in this package yet. In those cases, pass explicit contract addresses if you want to use non-canonical deployments.
60
+ *
61
+ * ## SDK Example
62
+ *
63
+ * Initialize the atomiq SDK with Citrea network support:
64
+ *
65
+ * ```ts
66
+ * import {CitreaInitializer, CitreaInitializerType} from "@atomiqlabs/chain-evm";
67
+ * import {BitcoinNetwork, SwapperFactory, TypedSwapper} from "@atomiqlabs/sdk";
68
+ *
69
+ * //Define chains that you want to support here
70
+ * const chains = [CitreaInitializer] as const;
71
+ * type SupportedChains = typeof chains; //It's helpful that we also get the type of the chains array
72
+ *
73
+ * const Factory = new SwapperFactory<SupportedChains>(chains); //Create swapper factory
74
+ *
75
+ * const swapper: TypedSwapper<SupportedChains> = Factory.newSwapper({
76
+ * chains: {
77
+ * CITREA: {
78
+ * rpcUrl: citreaRpc, //You can also pass JsonApiProvider object here
79
+ * }
80
+ * },
81
+ * bitcoinNetwork: BitcoinNetwork.MAINNET //or BitcoinNetwork.TESTNET3, BitcoinNetwork.TESTNET4 - this also sets the deployment to use for EVM chains
82
+ * });
83
+ * ```
84
+ *
85
+ * @packageDocumentation
86
+ */
87
+ __exportStar(require("./chains/EVMOptions"), exports);
18
88
  __exportStar(require("./chains/citrea/CitreaInitializer"), exports);
19
89
  __exportStar(require("./chains/citrea/CitreaChainType"), exports);
20
90
  __exportStar(require("./chains/citrea/CitreaFees"), exports);
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Node.js-only entrypoint for filesystem-backed EVM helpers.
3
+ *
4
+ * Import from `@atomiqlabs/chain-evm/node` when you need runtime features
5
+ * that depend on Node's `fs` module.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export { EVMChainEvents } from "../evm/events/EVMChainEvents";
10
+ export { EVMPersistentSigner } from "../evm/wallet/EVMPersistentSigner";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EVMPersistentSigner = exports.EVMChainEvents = void 0;
4
+ /**
5
+ * Node.js-only entrypoint for filesystem-backed EVM helpers.
6
+ *
7
+ * Import from `@atomiqlabs/chain-evm/node` when you need runtime features
8
+ * that depend on Node's `fs` module.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ var EVMChainEvents_1 = require("../evm/events/EVMChainEvents");
13
+ Object.defineProperty(exports, "EVMChainEvents", { enumerable: true, get: function () { return EVMChainEvents_1.EVMChainEvents; } });
14
+ var EVMPersistentSigner_1 = require("../evm/wallet/EVMPersistentSigner");
15
+ Object.defineProperty(exports, "EVMPersistentSigner", { enumerable: true, get: function () { return EVMPersistentSigner_1.EVMPersistentSigner; } });
@@ -1,19 +1,69 @@
1
+ /**
2
+ * Logger interface used across EVM modules.
3
+ *
4
+ * @category Internal/Utils
5
+ */
1
6
  export type LoggerType = {
2
7
  debug: (msg: string, ...args: any[]) => void;
3
8
  info: (msg: string, ...args: any[]) => void;
4
9
  warn: (msg: string, ...args: any[]) => void;
5
10
  error: (msg: string, ...args: any[]) => void;
6
11
  };
12
+ /**
13
+ * Returns a promise that resolves after `timeoutMillis` unless aborted first.
14
+ *
15
+ * @category Internal/Utils
16
+ */
7
17
  export declare function timeoutPromise(timeoutMillis: number, abortSignal?: AbortSignal): Promise<void>;
18
+ /**
19
+ * Wraps an async executor so it runs once at a time and reuses the same promise.
20
+ *
21
+ * @category Internal/Utils
22
+ */
8
23
  export declare function onceAsync<T>(executor: () => Promise<T>): () => Promise<T>;
24
+ /**
25
+ * Creates a prefixed logger that honors the global `atomiqLogLevel`.
26
+ *
27
+ * @category Internal/Utils
28
+ */
9
29
  export declare function getLogger(prefix: string): LoggerType;
30
+ /**
31
+ * Retries an async function using the provided retry policy.
32
+ *
33
+ * @category Internal/Utils
34
+ */
10
35
  export declare function tryWithRetries<T>(func: () => Promise<T>, retryPolicy?: {
11
36
  maxRetries?: number;
12
37
  delay?: number;
13
38
  exponential?: boolean;
14
39
  }, errorAllowed?: (e: any) => boolean, abortSignal?: AbortSignal): Promise<T>;
40
+ /**
41
+ * Reverses byte order of a 32-bit unsigned integer.
42
+ *
43
+ * @category Internal/Utils
44
+ */
15
45
  export declare function uint32ReverseEndianness(value: number): number;
46
+ /**
47
+ * Returns the greater of two bigint values.
48
+ *
49
+ * @category Internal/Utils
50
+ */
16
51
  export declare function bigIntMax(a: bigint, b: bigint): bigint;
52
+ /**
53
+ * Ethers.js error codes considered recoverable for retry logic.
54
+ *
55
+ * @category Internal/Utils
56
+ */
17
57
  export declare const allowedEthersErrorCodes: Set<string>;
58
+ /**
59
+ * JSON-RPC error numbers considered recoverable for retry logic.
60
+ *
61
+ * @category Internal/Utils
62
+ */
18
63
  export declare const allowedEthersErrorNumbers: Set<number>;
64
+ /**
65
+ * RPC error messages considered recoverable for retry logic.
66
+ *
67
+ * @category Internal/Utils
68
+ */
19
69
  export declare const allowedEthersErrorMessages: Set<string>;
@@ -1,6 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.allowedEthersErrorMessages = exports.allowedEthersErrorNumbers = exports.allowedEthersErrorCodes = exports.bigIntMax = exports.uint32ReverseEndianness = exports.tryWithRetries = exports.getLogger = exports.onceAsync = exports.timeoutPromise = void 0;
4
+ /**
5
+ * Returns a promise that resolves after `timeoutMillis` unless aborted first.
6
+ *
7
+ * @category Internal/Utils
8
+ */
4
9
  function timeoutPromise(timeoutMillis, abortSignal) {
5
10
  return new Promise((resolve, reject) => {
6
11
  const timeout = setTimeout(resolve, timeoutMillis);
@@ -12,6 +17,11 @@ function timeoutPromise(timeoutMillis, abortSignal) {
12
17
  });
13
18
  }
14
19
  exports.timeoutPromise = timeoutPromise;
20
+ /**
21
+ * Wraps an async executor so it runs once at a time and reuses the same promise.
22
+ *
23
+ * @category Internal/Utils
24
+ */
15
25
  function onceAsync(executor) {
16
26
  let promise;
17
27
  return () => {
@@ -25,6 +35,11 @@ function onceAsync(executor) {
25
35
  };
26
36
  }
27
37
  exports.onceAsync = onceAsync;
38
+ /**
39
+ * Creates a prefixed logger that honors the global `atomiqLogLevel`.
40
+ *
41
+ * @category Internal/Utils
42
+ */
28
43
  function getLogger(prefix) {
29
44
  return {
30
45
  debug: (msg, ...args) => global.atomiqLogLevel >= 3 && console.debug(prefix + msg, ...args),
@@ -35,6 +50,11 @@ function getLogger(prefix) {
35
50
  }
36
51
  exports.getLogger = getLogger;
37
52
  const logger = getLogger("Utils: ");
53
+ /**
54
+ * Retries an async function using the provided retry policy.
55
+ *
56
+ * @category Internal/Utils
57
+ */
38
58
  async function tryWithRetries(func, retryPolicy, errorAllowed, abortSignal) {
39
59
  retryPolicy = retryPolicy || {};
40
60
  retryPolicy.maxRetries = retryPolicy.maxRetries || 5;
@@ -61,6 +81,11 @@ async function tryWithRetries(func, retryPolicy, errorAllowed, abortSignal) {
61
81
  throw err;
62
82
  }
63
83
  exports.tryWithRetries = tryWithRetries;
84
+ /**
85
+ * Reverses byte order of a 32-bit unsigned integer.
86
+ *
87
+ * @category Internal/Utils
88
+ */
64
89
  function uint32ReverseEndianness(value) {
65
90
  const valueBN = BigInt(value);
66
91
  return Number(((valueBN & 0xffn) << 24n) |
@@ -69,16 +94,31 @@ function uint32ReverseEndianness(value) {
69
94
  ((valueBN >> 24n) & 0xffn));
70
95
  }
71
96
  exports.uint32ReverseEndianness = uint32ReverseEndianness;
97
+ /**
98
+ * Returns the greater of two bigint values.
99
+ *
100
+ * @category Internal/Utils
101
+ */
72
102
  function bigIntMax(a, b) {
73
103
  return a > b ? a : b;
74
104
  }
75
105
  exports.bigIntMax = bigIntMax;
106
+ /**
107
+ * Ethers.js error codes considered recoverable for retry logic.
108
+ *
109
+ * @category Internal/Utils
110
+ */
76
111
  exports.allowedEthersErrorCodes = new Set([
77
112
  "NOT_IMPLEMENTED", "UNSUPPORTED_OPERATION", "BAD_DATA",
78
113
  "NUMERIC_FAULT",
79
114
  "INVALID_ARGUMENT", "MISSING_ARGUMENT", "UNEXPECTED_ARGUMENT", "VALUE_MISMATCH",
80
115
  "CALL_EXCEPTION", "NONCE_EXPIRED", "REPLACEMENT_UNDERPRICED", "TRANSACTION_REPLACED", "UNCONFIGURED_NAME", "OFFCHAIN_FAULT", "ACTION_REJECTED"
81
116
  ]);
117
+ /**
118
+ * JSON-RPC error numbers considered recoverable for retry logic.
119
+ *
120
+ * @category Internal/Utils
121
+ */
82
122
  exports.allowedEthersErrorNumbers = new Set([
83
123
  3,
84
124
  -32700,
@@ -94,6 +134,11 @@ exports.allowedEthersErrorNumbers = new Set([
94
134
  // -32005, //Limit exceeded
95
135
  -32006 //JSON-RPC version not supported
96
136
  ]);
137
+ /**
138
+ * RPC error messages considered recoverable for retry logic.
139
+ *
140
+ * @category Internal/Utils
141
+ */
97
142
  exports.allowedEthersErrorMessages = new Set([
98
143
  "already known"
99
144
  ]);
@@ -0,0 +1 @@
1
+ export * from "../dist/node";
package/node/index.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+
3
+ module.exports = require("../dist/node");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-evm",
3
- "version": "2.1.11",
3
+ "version": "2.1.14",
4
4
  "description": "EVM specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -11,7 +11,8 @@
11
11
  },
12
12
  "files": [
13
13
  "/dist",
14
- "/src"
14
+ "/src",
15
+ "/node"
15
16
  ],
16
17
  "keywords": [
17
18
  "EVM",
@@ -25,7 +26,7 @@
25
26
  "author": "adambor",
26
27
  "license": "Apache-2.0",
27
28
  "dependencies": {
28
- "@atomiqlabs/base": "^13.1.9",
29
+ "@atomiqlabs/base": "^13.1.14",
29
30
  "@noble/hashes": "^1.8.0",
30
31
  "@scure/btc-signer": "^1.6.0",
31
32
  "buffer": "6.0.3",
@@ -0,0 +1,70 @@
1
+ import {JsonRpcApiProvider} from "ethers";
2
+ import {EVMConfiguration, EVMRetryPolicy} from "../evm/chain/EVMChainInterface";
3
+ import {ChainSwapType} from "@atomiqlabs/base";
4
+ import {EVMFees} from "../evm/chain/modules/EVMFees";
5
+
6
+ /**
7
+ * Generic options for an EVM chain
8
+ *
9
+ * @category Chain Interface
10
+ */
11
+ export type EVMOptions<C extends string, F extends EVMFees = EVMFees> = {
12
+ /**
13
+ * EVM RPC URL or {@link JsonRpcApiProvider} object to use for EVM network access
14
+ */
15
+ rpcUrl: string | JsonRpcApiProvider,
16
+ /**
17
+ * Retry policy for the RPC calls
18
+ */
19
+ retryPolicy?: EVMRetryPolicy,
20
+ /**
21
+ * Network type for the EVM chain
22
+ */
23
+ chainType?: C,
24
+
25
+ /**
26
+ * Contract address of the Escrow Manager contract, uses canonical deployment by default
27
+ */
28
+ swapContract?: string,
29
+ /**
30
+ * Optional Escrow Manager contract deployment height, which acts as genesis when querying events
31
+ */
32
+ swapContractDeploymentHeight?: number,
33
+ /**
34
+ * Contract address of the BTC Relay contract, uses canonical deployment by default
35
+ */
36
+ btcRelayContract?: string,
37
+ /**
38
+ * Optional BTC Relay contract deployment height, which acts as genesis when querying events
39
+ */
40
+ btcRelayDeploymentHeight?: number,
41
+ /**
42
+ * Contract address of the UTXO-controlled vault (SPV Vault manager) contract, uses canonical deployment by default
43
+ */
44
+ spvVaultContract?: string,
45
+ /**
46
+ * Optional UTXO-controlled vault (SPV Vault manager) contract deployment height, which acts as genesis when querying events
47
+ */
48
+ spvVaultDeploymentHeight?: number,
49
+ /**
50
+ * Contract addresses of the refund and claim handlers, uses canonical deployment by default
51
+ */
52
+ handlerContracts?: {
53
+ refund?: {
54
+ timelock?: string
55
+ },
56
+ claim?: {
57
+ [type in ChainSwapType]?: string
58
+ }
59
+ }
60
+
61
+ /**
62
+ * EVM network fee API
63
+ */
64
+ fees?: F,
65
+
66
+ /**
67
+ * EVM configuration
68
+ */
69
+ evmConfig?: Partial<Omit<EVMConfiguration, "safeBlockTag" | "finalizedBlockTag" | "finalityCheckStrategy">>
70
+ }
@@ -1,6 +1,6 @@
1
1
  import {BaseTokenType, BitcoinNetwork, BitcoinRpc, ChainData, ChainInitializer, ChainSwapType} from "@atomiqlabs/base";
2
- import {JsonRpcApiProvider, JsonRpcProvider, WebSocketProvider} from "ethers";
3
- import {EVMChainInterface, EVMConfiguration, EVMRetryPolicy} from "../../evm/chain/EVMChainInterface";
2
+ import {JsonRpcProvider, WebSocketProvider} from "ethers";
3
+ import {EVMChainInterface} from "../../evm/chain/EVMChainInterface";
4
4
  import {EVMFees} from "../../evm/chain/modules/EVMFees";
5
5
  import {EVMBtcRelay} from "../../evm/btcrelay/EVMBtcRelay";
6
6
  import {EVMSwapContract} from "../../evm/swaps/EVMSwapContract";
@@ -10,6 +10,7 @@ import {EVMSwapData} from "../../evm/swaps/EVMSwapData";
10
10
  import {EVMSpvVaultData} from "../../evm/spv_swap/EVMSpvVaultData";
11
11
  import {EVMSpvWithdrawalData} from "../../evm/spv_swap/EVMSpvWithdrawalData";
12
12
  import {AlpenChainType} from "./AlpenChainType";
13
+ import {EVMOptions} from "../EVMOptions";
13
14
 
14
15
  const AlpenChainIds = {
15
16
  MAINNET: -1,
@@ -96,7 +97,7 @@ export type AlpenAssetsType = BaseTokenType<"BTC">;
96
97
  * Default Alpen token assets configuration
97
98
  * @category Networks/Alpen
98
99
  */
99
- export const AlpenAssets: AlpenAssetsType = {
100
+ const AlpenAssets: AlpenAssetsType = {
100
101
  BTC: {
101
102
  address: "0x0000000000000000000000000000000000000000",
102
103
  decimals: 18,
@@ -108,30 +109,7 @@ export const AlpenAssets: AlpenAssetsType = {
108
109
  * Configuration options for initializing Alpen chain
109
110
  * @category Networks/Alpen
110
111
  */
111
- export type AlpenOptions = {
112
- rpcUrl: string | JsonRpcApiProvider,
113
- retryPolicy?: EVMRetryPolicy,
114
- chainType?: "MAINNET" | "TESTNET" | "TESTNET4",
115
-
116
- swapContract?: string,
117
- swapContractDeploymentHeight?: number,
118
- btcRelayContract?: string,
119
- btcRelayDeploymentHeight?: number,
120
- spvVaultContract?: string,
121
- spvVaultDeploymentHeight?: number,
122
- handlerContracts?: {
123
- refund?: {
124
- timelock?: string
125
- },
126
- claim?: {
127
- [type in ChainSwapType]?: string
128
- }
129
- }
130
-
131
- fees?: EVMFees,
132
-
133
- evmConfig?: Partial<Omit<EVMConfiguration, "safeBlockTag" | "finalizedBlockTag" | "finalityCheckStrategy">>
134
- }
112
+ export type AlpenOptions = EVMOptions<"MAINNET" | "TESTNET" | "TESTNET4">
135
113
 
136
114
  /**
137
115
  * Initialize Alpen chain integration
@@ -12,11 +12,11 @@ import {EVMBtcRelay} from "../../evm/btcrelay/EVMBtcRelay";
12
12
  import {EVMSpvVaultContract} from "../../evm/spv_swap/EVMSpvVaultContract";
13
13
  import {Signer} from "ethers";
14
14
 
15
- /**
16
- * Type definition for the Botanix chain implementation
17
- * @category Networks/Botanix
18
- */
19
- export type BotanixChainType = ChainType<
15
+ /**
16
+ * Type definition for the Botanix chain implementation
17
+ * @category Networks/Botanix
18
+ */
19
+ export type BotanixChainType = ChainType<
20
20
  "BOTANIX",
21
21
  never,
22
22
  EVMPreFetchVerification,
@@ -1,6 +1,6 @@
1
1
  import {BaseTokenType, BitcoinNetwork, BitcoinRpc, ChainData, ChainInitializer, ChainSwapType} from "@atomiqlabs/base";
2
- import {JsonRpcApiProvider, JsonRpcProvider, WebSocketProvider} from "ethers";
3
- import {EVMChainInterface, EVMConfiguration, EVMRetryPolicy} from "../../evm/chain/EVMChainInterface";
2
+ import {JsonRpcProvider, WebSocketProvider} from "ethers";
3
+ import {EVMChainInterface} from "../../evm/chain/EVMChainInterface";
4
4
  import {EVMFees} from "../../evm/chain/modules/EVMFees";
5
5
  import {EVMBtcRelay} from "../../evm/btcrelay/EVMBtcRelay";
6
6
  import {EVMSwapContract} from "../../evm/swaps/EVMSwapContract";
@@ -10,6 +10,7 @@ import {EVMSwapData} from "../../evm/swaps/EVMSwapData";
10
10
  import {EVMSpvVaultData} from "../../evm/spv_swap/EVMSpvVaultData";
11
11
  import {EVMSpvWithdrawalData} from "../../evm/spv_swap/EVMSpvWithdrawalData";
12
12
  import {BotanixChainType} from "./BotanixChainType";
13
+ import {EVMOptions} from "../EVMOptions";
13
14
 
14
15
  const BotanixChainIds = {
15
16
  MAINNET: 3637,
@@ -74,7 +75,7 @@ export type BotanixAssetsType = BaseTokenType<"BTC">;
74
75
  * Default Botanix token assets configuration
75
76
  * @category Networks/Botanix
76
77
  */
77
- export const BotanixAssets: BotanixAssetsType = {
78
+ const BotanixAssets: BotanixAssetsType = {
78
79
  BTC: {
79
80
  address: "0x0000000000000000000000000000000000000000",
80
81
  decimals: 18,
@@ -86,30 +87,7 @@ export const BotanixAssets: BotanixAssetsType = {
86
87
  * Configuration options for initializing Botanix chain
87
88
  * @category Networks/Botanix
88
89
  */
89
- export type BotanixOptions = {
90
- rpcUrl: string | JsonRpcApiProvider,
91
- retryPolicy?: EVMRetryPolicy,
92
- chainType?: "MAINNET" | "TESTNET",
93
-
94
- swapContract?: string,
95
- swapContractDeploymentHeight?: number,
96
- btcRelayContract?: string,
97
- btcRelayDeploymentHeight?: number,
98
- spvVaultContract?: string,
99
- spvVaultDeploymentHeight?: number,
100
- handlerContracts?: {
101
- refund?: {
102
- timelock?: string
103
- },
104
- claim?: {
105
- [type in ChainSwapType]?: string
106
- }
107
- }
108
-
109
- fees?: EVMFees,
110
-
111
- evmConfig?: Partial<Omit<EVMConfiguration, "safeBlockTag" | "finalizedBlockTag" | "finalityCheckStrategy">>
112
- }
90
+ export type BotanixOptions = EVMOptions<"MAINNET" | "TESTNET">;
113
91
 
114
92
  /**
115
93
  * Initialize Botanix chain integration