@atomiqlabs/chain-evm 2.1.12 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +61 -2
  29. package/dist/evm/chain/EVMChainInterface.js +14 -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 +22 -5
  40. package/dist/evm/chain/modules/EVMTransactions.js +31 -22
  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 +61 -23
  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 +5 -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 +74 -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 +40 -17
  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 +72 -32
  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
@@ -1,22 +1,40 @@
1
- import { BaseContract, Log, TransactionDescription } from "ethers";
1
+ import { BaseContract, TransactionDescription } from "ethers";
2
2
  import { EVMChainInterface } from "../chain/EVMChainInterface";
3
3
  import { EVMContractEvents } from "./modules/EVMContractEvents";
4
- import { TypedContractMethod, TypedEventLog } from "../typechain/common";
4
+ import { TypedContractMethod } from "../typechain/common";
5
5
  type __TypechainOutputObject<T> = T extends TypedContractMethod<infer V> ? V : never;
6
+ /**
7
+ * Typed transaction call decoded from calldata for a specific contract method.
8
+ *
9
+ * @category Internal/Contracts
10
+ */
6
11
  export interface TypedFunctionCall<TCMethod extends TypedContractMethod> extends Omit<TransactionDescription, "args"> {
7
12
  args: __TypechainOutputObject<TCMethod>;
8
13
  }
9
14
  /**
10
- * Base class providing program specific utilities
15
+ * Base contract wrapper providing typed event and calldata parsing helpers.
16
+ *
17
+ * @category Internal/Contracts
11
18
  */
12
19
  export declare class EVMContractBase<T extends BaseContract> {
13
- contract: T;
14
- readonly Events: EVMContractEvents<T>;
15
- readonly Chain: EVMChainInterface<any>;
16
- readonly contractAddress: string;
17
- readonly contractDeploymentHeight?: number;
20
+ readonly contract: T;
21
+ /**
22
+ * @internal
23
+ */
24
+ readonly _Events: EVMContractEvents<T>;
25
+ protected readonly Chain: EVMChainInterface<any>;
26
+ /**
27
+ * @internal
28
+ */
29
+ readonly _contractAddress: string;
30
+ /**
31
+ * @internal
32
+ */
33
+ readonly _contractDeploymentHeight?: number;
18
34
  constructor(chainInterface: EVMChainInterface<any>, contractAddress: string, contractAbi: any, contractDeploymentHeight?: number);
19
- toTypedEvent<TEventName extends keyof T["filters"] = keyof T["filters"]>(log: Log): TypedEventLog<T["filters"][TEventName]> | null;
20
- parseCalldata<TMethod extends TypedContractMethod>(calldata: string): TypedFunctionCall<TMethod>;
35
+ /**
36
+ * @internal
37
+ */
38
+ protected parseCalldata<TMethod extends TypedContractMethod>(calldata: string): TypedFunctionCall<TMethod>;
21
39
  }
22
40
  export {};
@@ -4,30 +4,21 @@ exports.EVMContractBase = void 0;
4
4
  const ethers_1 = require("ethers");
5
5
  const EVMContractEvents_1 = require("./modules/EVMContractEvents");
6
6
  /**
7
- * Base class providing program specific utilities
7
+ * Base contract wrapper providing typed event and calldata parsing helpers.
8
+ *
9
+ * @category Internal/Contracts
8
10
  */
9
11
  class EVMContractBase {
10
12
  constructor(chainInterface, contractAddress, contractAbi, contractDeploymentHeight) {
11
13
  this.Chain = chainInterface;
12
14
  this.contract = new ethers_1.Contract(contractAddress, contractAbi, chainInterface.provider);
13
- this.Events = new EVMContractEvents_1.EVMContractEvents(chainInterface, this);
14
- this.contractAddress = contractAddress;
15
- this.contractDeploymentHeight = contractDeploymentHeight;
16
- }
17
- toTypedEvent(log) {
18
- let foundFragment = null;
19
- try {
20
- foundFragment = this.contract.interface.getEvent(log.topics[0]);
21
- }
22
- catch (error) { }
23
- if (!foundFragment)
24
- return null;
25
- try {
26
- return new ethers_1.EventLog(log, this.contract.interface, foundFragment);
27
- }
28
- catch (error) { }
29
- return null;
15
+ this._Events = new EVMContractEvents_1.EVMContractEvents(chainInterface, this);
16
+ this._contractAddress = contractAddress;
17
+ this._contractDeploymentHeight = contractDeploymentHeight;
30
18
  }
19
+ /**
20
+ * @internal
21
+ */
31
22
  parseCalldata(calldata) {
32
23
  return this.contract.interface.parseTransaction({ data: calldata });
33
24
  }
@@ -2,6 +2,11 @@ import { BaseContract } from "ethers";
2
2
  import { EVMModule } from "../chain/EVMModule";
3
3
  import { EVMChainInterface } from "../chain/EVMChainInterface";
4
4
  import { EVMContractBase } from "./EVMContractBase";
5
+ /**
6
+ * Base module class for EVM components tied to a specific contract wrapper.
7
+ *
8
+ * @category Internal/Contracts
9
+ */
5
10
  export declare class EVMContractModule<T extends BaseContract, C extends EVMContractBase<T> = EVMContractBase<T>> extends EVMModule<any> {
6
11
  readonly contract: C;
7
12
  constructor(chainInterface: EVMChainInterface<any>, contract: C);
@@ -2,6 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EVMContractModule = void 0;
4
4
  const EVMModule_1 = require("../chain/EVMModule");
5
+ /**
6
+ * Base module class for EVM components tied to a specific contract wrapper.
7
+ *
8
+ * @category Internal/Contracts
9
+ */
5
10
  class EVMContractModule extends EVMModule_1.EVMModule {
6
11
  constructor(chainInterface, contract) {
7
12
  super(chainInterface);
@@ -3,10 +3,16 @@ import { EVMEvents } from "../../chain/modules/EVMEvents";
3
3
  import { EVMContractBase } from "../EVMContractBase";
4
4
  import { EVMChainInterface } from "../../chain/EVMChainInterface";
5
5
  import { TypedEventLog } from "../../typechain/common";
6
+ /**
7
+ * Typed contract event utilities built on top of generic EVM log querying helpers.
8
+ *
9
+ * @category Internal/Contracts
10
+ */
6
11
  export declare class EVMContractEvents<T extends BaseContract> extends EVMEvents {
7
- readonly contract: EVMContractBase<T>;
12
+ private readonly contract;
8
13
  readonly baseContract: T;
9
14
  constructor(chainInterface: EVMChainInterface<any>, contract: EVMContractBase<T>);
15
+ private toTypedEvent;
10
16
  toTypedEvents<TEventName extends keyof T["filters"]>(blockEvents: Log[]): (TypedEventLog<T["filters"][TEventName]> | null)[];
11
17
  private toFilter;
12
18
  /**
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EVMContractEvents = void 0;
4
+ const ethers_1 = require("ethers");
4
5
  const EVMEvents_1 = require("../../chain/modules/EVMEvents");
5
6
  function normalizeTopic(topic) {
6
7
  if (topic.length !== 66) {
@@ -8,14 +9,33 @@ function normalizeTopic(topic) {
8
9
  }
9
10
  return topic;
10
11
  }
12
+ /**
13
+ * Typed contract event utilities built on top of generic EVM log querying helpers.
14
+ *
15
+ * @category Internal/Contracts
16
+ */
11
17
  class EVMContractEvents extends EVMEvents_1.EVMEvents {
12
18
  constructor(chainInterface, contract) {
13
19
  super(chainInterface);
14
20
  this.contract = contract;
15
21
  this.baseContract = contract.contract;
16
22
  }
23
+ toTypedEvent(log) {
24
+ let foundFragment = null;
25
+ try {
26
+ foundFragment = this.baseContract.interface.getEvent(log.topics[0]);
27
+ }
28
+ catch (error) { }
29
+ if (!foundFragment)
30
+ return null;
31
+ try {
32
+ return new ethers_1.EventLog(log, this.baseContract.interface, foundFragment);
33
+ }
34
+ catch (error) { }
35
+ return null;
36
+ }
17
37
  toTypedEvents(blockEvents) {
18
- return blockEvents.map(log => this.contract.toTypedEvent(log));
38
+ return blockEvents.map(log => this.toTypedEvent(log));
19
39
  }
20
40
  toFilter(events, keys) {
21
41
  const filterArray = [];
@@ -61,7 +81,7 @@ class EVMContractEvents extends EVMEvents_1.EVMEvents {
61
81
  return result;
62
82
  }
63
83
  return null;
64
- }, abortSignal, this.contract.contractDeploymentHeight);
84
+ }, abortSignal, this.contract._contractDeploymentHeight);
65
85
  }
66
86
  /**
67
87
  * Runs a search forwards in time, processing the events for a specific topic
@@ -84,7 +104,7 @@ class EVMContractEvents extends EVMEvents_1.EVMEvents {
84
104
  return result;
85
105
  }
86
106
  return null;
87
- }, abortSignal, Math.max(this.contract.contractDeploymentHeight ?? 0, startHeight ?? 0));
107
+ }, abortSignal, Math.max(this.contract._contractDeploymentHeight ?? 0, startHeight ?? 0));
88
108
  }
89
109
  }
90
110
  exports.EVMContractEvents = EVMContractEvents;
@@ -2,6 +2,11 @@ import { EVMChainEventsBrowser } from "./EVMChainEventsBrowser";
2
2
  import { EVMChainInterface } from "../chain/EVMChainInterface";
3
3
  import { EVMSwapContract } from "../swaps/EVMSwapContract";
4
4
  import { EVMSpvVaultContract } from "../spv_swap/EVMSpvVaultContract";
5
+ /**
6
+ * Backend event listener with persisted polling cursor stored on filesystem.
7
+ *
8
+ * @category Events
9
+ */
5
10
  export declare class EVMChainEvents extends EVMChainEventsBrowser {
6
11
  private readonly directory;
7
12
  private readonly BLOCKHEIGHT_FILENAME;
@@ -18,5 +23,8 @@ export declare class EVMChainEvents extends EVMChainEventsBrowser {
18
23
  * @private
19
24
  */
20
25
  private saveLastEventData;
26
+ /**
27
+ * @inheritDoc
28
+ */
21
29
  init(noAutomaticPoll?: boolean): Promise<void>;
22
30
  }
@@ -4,6 +4,11 @@ exports.EVMChainEvents = void 0;
4
4
  //@ts-ignore
5
5
  const fs = require("fs/promises");
6
6
  const EVMChainEventsBrowser_1 = require("./EVMChainEventsBrowser");
7
+ /**
8
+ * Backend event listener with persisted polling cursor stored on filesystem.
9
+ *
10
+ * @category Events
11
+ */
7
12
  class EVMChainEvents extends EVMChainEventsBrowser_1.EVMChainEventsBrowser {
8
13
  constructor(directory, chainInterface, evmSwapContract, evmSpvVaultContract, pollIntervalSeconds) {
9
14
  super(chainInterface, evmSwapContract, evmSpvVaultContract, pollIntervalSeconds);
@@ -70,6 +75,9 @@ class EVMChainEvents extends EVMChainEventsBrowser_1.EVMChainEventsBrowser {
70
75
  }
71
76
  }).join(";"));
72
77
  }
78
+ /**
79
+ * @inheritDoc
80
+ */
73
81
  async init(noAutomaticPoll) {
74
82
  if (noAutomaticPoll)
75
83
  return Promise.resolve();
@@ -1,4 +1,4 @@
1
- import { ChainEvents, ClaimEvent, EventListener, InitializeEvent, RefundEvent, SpvVaultClaimEvent, SpvVaultCloseEvent, SpvVaultDepositEvent, SpvVaultFrontEvent, SpvVaultOpenEvent } from "@atomiqlabs/base";
1
+ import { ChainEvents, EventListener } from "@atomiqlabs/base";
2
2
  import { EVMSwapData } from "../swaps/EVMSwapData";
3
3
  import { Block, JsonRpcApiProvider, EventFilter, Log } from "ethers";
4
4
  import { EVMSwapContract } from "../swaps/EVMSwapContract";
@@ -7,6 +7,12 @@ import { EVMChainInterface } from "../chain/EVMChainInterface";
7
7
  import { TypedEventLog } from "../typechain/common";
8
8
  import { EscrowManager } from "../swaps/EscrowManagerTypechain";
9
9
  import { SpvVaultManager } from "../spv_swap/SpvVaultContractTypechain";
10
+ /**
11
+ * Current state of the EVM event listener, containing the last processed block number
12
+ * and event position.
13
+ *
14
+ * @category Events
15
+ */
10
16
  export type EVMEventListenerState = {
11
17
  lastBlockNumber: number;
12
18
  lastEvent?: {
@@ -19,23 +25,61 @@ type AtomiqTypedEvent = (TypedEventLog<EscrowManager["filters"]["Initialize" | "
19
25
  * EVM on-chain event handler for front-end systems without access to fs, uses WS or long-polling to subscribe, might lose
20
26
  * out on some events if the network is unreliable, front-end systems should take this into consideration and not
21
27
  * rely purely on events
28
+ *
29
+ * @category Events
22
30
  */
23
31
  export declare class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, EVMEventListenerState[]> {
24
32
  private eventsProcessing;
25
33
  private processedEvents;
26
34
  private processedEventsIndex;
35
+ /**
36
+ * @internal
37
+ */
27
38
  protected readonly listeners: EventListener<EVMSwapData>[];
39
+ /**
40
+ * @internal
41
+ */
28
42
  protected readonly provider: JsonRpcApiProvider;
43
+ /**
44
+ * @internal
45
+ */
29
46
  protected readonly chainInterface: EVMChainInterface;
47
+ /**
48
+ * @internal
49
+ */
30
50
  protected readonly evmSwapContract: EVMSwapContract;
51
+ /**
52
+ * @internal
53
+ */
31
54
  protected readonly evmSpvVaultContract: EVMSpvVaultContract<any>;
55
+ /**
56
+ * @internal
57
+ */
32
58
  protected readonly logger: import("../../utils/Utils").LoggerType;
59
+ /**
60
+ * @internal
61
+ */
33
62
  protected stopped: boolean;
63
+ /**
64
+ * @internal
65
+ */
34
66
  protected pollIntervalSeconds: number;
35
67
  private timeout?;
68
+ /**
69
+ * @internal
70
+ */
36
71
  protected readonly spvVaultContractLogFilter: EventFilter;
72
+ /**
73
+ * @internal
74
+ */
37
75
  protected readonly swapContractLogFilter: EventFilter;
76
+ /**
77
+ * @internal
78
+ */
38
79
  protected unconfirmedEventQueue: AtomiqTypedEvent[];
80
+ /**
81
+ * @internal
82
+ */
39
83
  protected confirmedEventQueue: {
40
84
  event: AtomiqTypedEvent;
41
85
  block: Block;
@@ -52,14 +96,14 @@ export declare class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, E
52
96
  * @returns {() => Promise<EVMSwapData | null>} getter to be passed to InitializeEvent constructor
53
97
  */
54
98
  private getSwapDataGetter;
55
- protected parseInitializeEvent(event: TypedEventLog<EscrowManager["filters"]["Initialize"]>): InitializeEvent<EVMSwapData> | null;
56
- protected parseRefundEvent(event: TypedEventLog<EscrowManager["filters"]["Refund"]>): RefundEvent<EVMSwapData>;
57
- protected parseClaimEvent(event: TypedEventLog<EscrowManager["filters"]["Claim"]>): ClaimEvent<EVMSwapData> | null;
58
- protected parseSpvOpenEvent(event: TypedEventLog<SpvVaultManager["filters"]["Opened"]>): SpvVaultOpenEvent;
59
- protected parseSpvDepositEvent(event: TypedEventLog<SpvVaultManager["filters"]["Deposited"]>): SpvVaultDepositEvent;
60
- protected parseSpvFrontEvent(event: TypedEventLog<SpvVaultManager["filters"]["Fronted"]>): SpvVaultFrontEvent;
61
- protected parseSpvClaimEvent(event: TypedEventLog<SpvVaultManager["filters"]["Claimed"]>): SpvVaultClaimEvent;
62
- protected parseSpvCloseEvent(event: TypedEventLog<SpvVaultManager["filters"]["Closed"]>): SpvVaultCloseEvent;
99
+ private parseInitializeEvent;
100
+ private parseRefundEvent;
101
+ private parseClaimEvent;
102
+ private parseSpvOpenEvent;
103
+ private parseSpvDepositEvent;
104
+ private parseSpvFrontEvent;
105
+ private parseSpvClaimEvent;
106
+ private parseSpvCloseEvent;
63
107
  /**
64
108
  * Processes event as received from the chain, parses it & calls event listeners
65
109
  *
@@ -67,15 +111,9 @@ export declare class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, E
67
111
  * @param currentBlock
68
112
  * @protected
69
113
  */
70
- protected processEvents(events: (TypedEventLog<EscrowManager["filters"]["Initialize" | "Refund" | "Claim"]> | TypedEventLog<SpvVaultManager["filters"]["Opened" | "Deposited" | "Fronted" | "Claimed" | "Closed"]>)[], currentBlock?: Block): Promise<void>;
71
- protected checkEventsEcrowManager(currentBlock: Block, lastEvent?: {
72
- blockHash: string;
73
- logIndex: number;
74
- }, lastBlockNumber?: number): Promise<EVMEventListenerState>;
75
- protected checkEventsSpvVaults(currentBlock: Block, lastEvent?: {
76
- blockHash: string;
77
- logIndex: number;
78
- }, lastBlockNumber?: number): Promise<EVMEventListenerState>;
114
+ private processEvents;
115
+ private checkEventsEcrowManager;
116
+ private checkEventsSpvVaults;
79
117
  /**
80
118
  * @inheritDoc
81
119
  */
@@ -83,18 +121,48 @@ export declare class EVMChainEventsBrowser implements ChainEvents<EVMSwapData, E
83
121
  /**
84
122
  * Sets up event handlers listening for swap events over websocket
85
123
  *
86
- * @protected
124
+ * @internal
87
125
  */
88
126
  protected setupPoll(lastState?: EVMEventListenerState[], saveLatestProcessedBlockNumber?: (newState: EVMEventListenerState[]) => Promise<void>): Promise<void>;
127
+ /**
128
+ * @internal
129
+ */
89
130
  protected handleWsEvent(event: AtomiqTypedEvent): Promise<void>;
131
+ /**
132
+ * @internal
133
+ */
90
134
  protected spvVaultContractListener?: (log: Log) => void;
135
+ /**
136
+ * @internal
137
+ */
91
138
  protected swapContractListener?: (log: Log) => void;
139
+ /**
140
+ * @internal
141
+ */
92
142
  protected blockListener?: (blockNumber: number) => Promise<void>;
143
+ /**
144
+ * @internal
145
+ */
93
146
  protected finalityCheckTimer: any;
147
+ /**
148
+ * @internal
149
+ */
94
150
  protected wsStarted: boolean;
151
+ /**
152
+ * @internal
153
+ */
95
154
  protected checkUnconfirmedEventsFinality(): Promise<void>;
155
+ /**
156
+ * @internal
157
+ */
96
158
  protected addOrRemoveBlockListener(): Promise<void>;
159
+ /**
160
+ * @internal
161
+ */
97
162
  protected startFinalityCheckTimer(): Promise<void>;
163
+ /**
164
+ * @internal
165
+ */
98
166
  protected setupWebsocket(): Promise<void>;
99
167
  /**
100
168
  * @inheritDoc
@@ -10,17 +10,37 @@ const PROCESSED_EVENTS_BACKLOG = 1000;
10
10
  * EVM on-chain event handler for front-end systems without access to fs, uses WS or long-polling to subscribe, might lose
11
11
  * out on some events if the network is unreliable, front-end systems should take this into consideration and not
12
12
  * rely purely on events
13
+ *
14
+ * @category Events
13
15
  */
14
16
  class EVMChainEventsBrowser {
15
17
  constructor(chainInterface, evmSwapContract, evmSpvVaultContract, pollIntervalSeconds = 5) {
16
18
  this.eventsProcessing = {};
17
19
  this.processedEvents = [];
18
20
  this.processedEventsIndex = 0;
21
+ /**
22
+ * @internal
23
+ */
19
24
  this.listeners = [];
25
+ /**
26
+ * @internal
27
+ */
20
28
  this.logger = (0, Utils_1.getLogger)("EVMChainEventsBrowser: ");
29
+ /**
30
+ * @internal
31
+ */
21
32
  this.stopped = true;
33
+ /**
34
+ * @internal
35
+ */
22
36
  this.unconfirmedEventQueue = [];
37
+ /**
38
+ * @internal
39
+ */
23
40
  this.confirmedEventQueue = [];
41
+ /**
42
+ * @internal
43
+ */
24
44
  this.wsStarted = false;
25
45
  this.chainInterface = chainInterface;
26
46
  this.provider = chainInterface.provider;
@@ -28,10 +48,10 @@ class EVMChainEventsBrowser {
28
48
  this.evmSpvVaultContract = evmSpvVaultContract;
29
49
  this.pollIntervalSeconds = pollIntervalSeconds;
30
50
  this.spvVaultContractLogFilter = {
31
- address: this.evmSpvVaultContract.contractAddress
51
+ address: this.evmSpvVaultContract._contractAddress
32
52
  };
33
53
  this.swapContractLogFilter = {
34
- address: this.evmSwapContract.contractAddress
54
+ address: this.evmSwapContract._contractAddress
35
55
  };
36
56
  }
37
57
  addProcessedEvent(event) {
@@ -62,7 +82,7 @@ class EVMChainEventsBrowser {
62
82
  parseInitializeEvent(event) {
63
83
  const escrowHash = event.args.escrowHash.substring(2);
64
84
  const claimHandlerHex = event.args.claimHandler;
65
- const claimHandler = this.evmSwapContract.claimHandlersByAddress[claimHandlerHex.toLowerCase()];
85
+ const claimHandler = this.evmSwapContract._claimHandlersByAddress[claimHandlerHex.toLowerCase()];
66
86
  if (claimHandler == null) {
67
87
  this.logger.warn("parseInitializeEvent(" + escrowHash + "): Unknown claim handler with claim: " + claimHandlerHex);
68
88
  return null;
@@ -79,7 +99,7 @@ class EVMChainEventsBrowser {
79
99
  parseClaimEvent(event) {
80
100
  const escrowHash = event.args.escrowHash.substring(2);
81
101
  const claimHandlerHex = event.args.claimHandler;
82
- const claimHandler = this.evmSwapContract.claimHandlersByAddress[claimHandlerHex.toLowerCase()];
102
+ const claimHandler = this.evmSwapContract._claimHandlersByAddress[claimHandlerHex.toLowerCase()];
83
103
  if (claimHandler == null) {
84
104
  this.logger.warn("parseClaimEvent(" + escrowHash + "): Unknown claim handler with claim: " + claimHandlerHex);
85
105
  return null;
@@ -210,7 +230,7 @@ class EVMChainEventsBrowser {
210
230
  return { lastEvent, lastBlockNumber };
211
231
  }
212
232
  // this.logger.debug(`checkEvents(EscrowManager): Requesting logs: ${lastBlockNumber}...${currentBlock.number}`);
213
- let events = await this.evmSwapContract.Events.getContractBlockEvents(["Initialize", "Claim", "Refund"], [], lastBlockNumber, currentBlock.number);
233
+ let events = await this.evmSwapContract._Events.getContractBlockEvents(["Initialize", "Claim", "Refund"], [], lastBlockNumber, currentBlock.number);
214
234
  if (lastEvent != null) {
215
235
  const latestProcessedEventIndex = events.findIndex(val => val.blockHash === lastEvent.blockHash && val.index === lastEvent.logIndex);
216
236
  if (latestProcessedEventIndex !== -1) {
@@ -241,7 +261,7 @@ class EVMChainEventsBrowser {
241
261
  return { lastEvent, lastBlockNumber };
242
262
  }
243
263
  // this.logger.debug(`checkEvents(SpvVaults): Requesting logs: ${lastBlockNumber}...${currentBlock.number}`);
244
- let events = await this.evmSpvVaultContract.Events.getContractBlockEvents(["Opened", "Deposited", "Closed", "Fronted", "Claimed"], [], lastBlockNumber, currentBlock.number);
264
+ let events = await this.evmSpvVaultContract._Events.getContractBlockEvents(["Opened", "Deposited", "Closed", "Fronted", "Claimed"], [], lastBlockNumber, currentBlock.number);
245
265
  if (lastEvent != null) {
246
266
  const latestProcessedEventIndex = events.findIndex(val => val.blockHash === lastEvent.blockHash && val.index === lastEvent.logIndex);
247
267
  if (latestProcessedEventIndex !== -1) {
@@ -270,9 +290,9 @@ class EVMChainEventsBrowser {
270
290
  */
271
291
  async poll(lastState) {
272
292
  lastState ?? (lastState = []);
273
- const currentBlock = await this.provider.getBlock(this.chainInterface.config.safeBlockTag, false);
293
+ const currentBlock = await this.provider.getBlock(this.chainInterface._config.safeBlockTag, false);
274
294
  if (currentBlock == null)
275
- throw new Error(`Cannot fetch '${this.chainInterface.config.safeBlockTag}' block!`);
295
+ throw new Error(`Cannot fetch '${this.chainInterface._config.safeBlockTag}' block!`);
276
296
  const resultEscrow = await this.checkEventsEcrowManager(currentBlock, lastState?.[0]?.lastEvent, lastState?.[0]?.lastBlockNumber);
277
297
  const resultSpvVault = await this.checkEventsSpvVaults(currentBlock, lastState?.[1]?.lastEvent, lastState?.[1]?.lastBlockNumber);
278
298
  lastState = [
@@ -284,7 +304,7 @@ class EVMChainEventsBrowser {
284
304
  /**
285
305
  * Sets up event handlers listening for swap events over websocket
286
306
  *
287
- * @protected
307
+ * @internal
288
308
  */
289
309
  async setupPoll(lastState, saveLatestProcessedBlockNumber) {
290
310
  this.stopped = false;
@@ -304,18 +324,24 @@ class EVMChainEventsBrowser {
304
324
  await func();
305
325
  }
306
326
  //Websocket
327
+ /**
328
+ * @internal
329
+ */
307
330
  handleWsEvent(event) {
308
- if (this.chainInterface.config.safeBlockTag === "latest" || this.chainInterface.config.safeBlockTag === "pending") {
331
+ if (this.chainInterface._config.safeBlockTag === "latest" || this.chainInterface._config.safeBlockTag === "pending") {
309
332
  return this.processEvents([event]);
310
333
  }
311
334
  this.unconfirmedEventQueue.push(event);
312
335
  return this.addOrRemoveBlockListener();
313
336
  }
337
+ /**
338
+ * @internal
339
+ */
314
340
  async checkUnconfirmedEventsFinality() {
315
341
  if (this.unconfirmedEventQueue.length > 0) {
316
- const latestSafeBlock = await this.provider.getBlock(this.chainInterface.config.safeBlockTag);
342
+ const latestSafeBlock = await this.provider.getBlock(this.chainInterface._config.safeBlockTag);
317
343
  if (latestSafeBlock == null)
318
- throw new Error(`Failed to fetch '${this.chainInterface.config.safeBlockTag}' block!`);
344
+ throw new Error(`Failed to fetch '${this.chainInterface._config.safeBlockTag}' block!`);
319
345
  const events = this.unconfirmedEventQueue.filter(event => {
320
346
  return event.blockNumber <= latestSafeBlock.number;
321
347
  });
@@ -340,8 +366,11 @@ class EVMChainEventsBrowser {
340
366
  this.confirmedEventQueue.splice(index, 1);
341
367
  }
342
368
  }
369
+ /**
370
+ * @internal
371
+ */
343
372
  async addOrRemoveBlockListener() {
344
- if (this.chainInterface.config.finalityCheckStrategy?.type !== "blocks")
373
+ if (this.chainInterface._config.finalityCheckStrategy?.type !== "blocks")
345
374
  return;
346
375
  if (this.unconfirmedEventQueue.length > 0 || this.confirmedEventQueue.length > 0) {
347
376
  this.logger.debug(`addOrRemoveBlockListener(): Adding block listener, unconfirmed/confirmed event count: ${this.unconfirmedEventQueue.length + this.confirmedEventQueue.length}`);
@@ -352,6 +381,9 @@ class EVMChainEventsBrowser {
352
381
  await this.provider.off("block", this.blockListener);
353
382
  }
354
383
  }
384
+ /**
385
+ * @internal
386
+ */
355
387
  async startFinalityCheckTimer() {
356
388
  let check;
357
389
  check = async () => {
@@ -367,10 +399,13 @@ class EVMChainEventsBrowser {
367
399
  }
368
400
  if (!this.wsStarted)
369
401
  return;
370
- this.finalityCheckTimer = setTimeout(check, this.chainInterface.config.finalityCheckStrategy?.delayMs ?? 5 * 1000);
402
+ this.finalityCheckTimer = setTimeout(check, this.chainInterface._config.finalityCheckStrategy?.delayMs ?? 5 * 1000);
371
403
  };
372
404
  await check();
373
405
  }
406
+ /**
407
+ * @internal
408
+ */
374
409
  async setupWebsocket() {
375
410
  this.wsStarted = true;
376
411
  let processing = false;
@@ -389,18 +424,18 @@ class EVMChainEventsBrowser {
389
424
  processing = false;
390
425
  await this.addOrRemoveBlockListener();
391
426
  };
392
- if (this.chainInterface.config.safeBlockTag === "safe" || this.chainInterface.config.safeBlockTag === "finalized") {
393
- if (this.chainInterface.config.finalityCheckStrategy?.type === "timer")
427
+ if (this.chainInterface._config.safeBlockTag === "safe" || this.chainInterface._config.safeBlockTag === "finalized") {
428
+ if (this.chainInterface._config.finalityCheckStrategy?.type === "timer")
394
429
  this.startFinalityCheckTimer();
395
430
  }
396
431
  await this.provider.on(this.spvVaultContractLogFilter, this.spvVaultContractListener = (log) => {
397
- let [event] = this.evmSpvVaultContract.Events.toTypedEvents([log]);
432
+ let [event] = this.evmSpvVaultContract._Events.toTypedEvents([log]);
398
433
  if (event == null || event.removed)
399
434
  return;
400
435
  this.handleWsEvent(event);
401
436
  });
402
437
  await this.provider.on(this.swapContractLogFilter, this.swapContractListener = (log) => {
403
- let [event] = this.evmSwapContract.Events.toTypedEvents([log]);
438
+ let [event] = this.evmSwapContract._Events.toTypedEvents([log]);
404
439
  if (event == null || event.removed)
405
440
  return;
406
441
  if (event.eventName !== "Initialize" && event.eventName !== "Refund" && event.eventName !== "Claim")
@@ -1,6 +1,8 @@
1
1
  import { JsonRpcProvider, JsonRpcApiProviderOptions } from "ethers";
2
2
  import { Networkish, FetchRequest } from "ethers";
3
3
  /**
4
+ * JSON-RPC provider with built-in retry functionality for transient RPC failures.
5
+ *
4
6
  * @category Providers
5
7
  */
6
8
  export declare class JsonRpcProviderWithRetries extends JsonRpcProvider {
@@ -9,6 +11,13 @@ export declare class JsonRpcProviderWithRetries extends JsonRpcProvider {
9
11
  delay?: number;
10
12
  exponential?: boolean;
11
13
  };
14
+ /**
15
+ * Creates a new JSON-RPC provider which retries RPC calls based on the provided policy.
16
+ *
17
+ * @param url
18
+ * @param network
19
+ * @param options
20
+ */
12
21
  constructor(url: string | FetchRequest, network?: Networkish, options?: JsonRpcApiProviderOptions & {
13
22
  maxRetries?: number;
14
23
  delay?: number;
@@ -5,9 +5,18 @@ const ethers_1 = require("ethers");
5
5
  const ethers_2 = require("ethers");
6
6
  const Utils_1 = require("../../utils/Utils");
7
7
  /**
8
+ * JSON-RPC provider with built-in retry functionality for transient RPC failures.
9
+ *
8
10
  * @category Providers
9
11
  */
10
12
  class JsonRpcProviderWithRetries extends ethers_1.JsonRpcProvider {
13
+ /**
14
+ * Creates a new JSON-RPC provider which retries RPC calls based on the provided policy.
15
+ *
16
+ * @param url
17
+ * @param network
18
+ * @param options
19
+ */
11
20
  constructor(url, network, options) {
12
21
  if (typeof (url) === "string")
13
22
  url = new ethers_2.FetchRequest(url);
@@ -1,6 +1,11 @@
1
1
  import { JsonRpcApiProviderOptions } from "ethers";
2
2
  import type { Networkish, WebSocketLike } from "ethers";
3
3
  import { SocketProvider } from "./SocketProvider";
4
+ /**
5
+ * WebSocket RPC provider with automatic reconnect, heartbeat ping and connection timeout handling.
6
+ *
7
+ * @category Providers
8
+ */
4
9
  export declare class ReconnectingWebSocketProvider extends SocketProvider {
5
10
  requestTimeoutSeconds: number;
6
11
  reconnectSeconds: number;