@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
@@ -13,8 +13,17 @@ import { EVMSigner } from "../wallet/EVMSigner";
13
13
  * @category Chain Interface
14
14
  */
15
15
  export type EVMRetryPolicy = {
16
+ /**
17
+ * Maximum retries to be attempted
18
+ */
16
19
  maxRetries?: number;
20
+ /**
21
+ * Default delay between retries
22
+ */
17
23
  delay?: number;
24
+ /**
25
+ * Whether the delays should scale exponentially, i.e. 1 second, 2 seconds, 4 seconds, 8 seconds
26
+ */
18
27
  exponential?: boolean;
19
28
  };
20
29
  /**
@@ -22,16 +31,53 @@ export type EVMRetryPolicy = {
22
31
  * @category Chain Interface
23
32
  */
24
33
  export type EVMConfiguration = {
34
+ /**
35
+ * EVM Block tag to be considered safe for financial application, i.e. sending assets on different blockchains
36
+ */
25
37
  safeBlockTag: EVMBlockTag;
38
+ /**
39
+ * EVM Block tag to be considered finalized, i.e. the state definitely cannot revert after the blocks gets
40
+ * this level of finality
41
+ */
26
42
  finalizedBlockTag: EVMBlockTag;
43
+ /**
44
+ * Maximum range of blocks to query when querying `ethereum_getLogs` RPC endpoint.
45
+ */
27
46
  maxLogsBlockRange: number;
47
+ /**
48
+ * Maximum number of `ethereum_getLogs` RPC calls to be executed in parallel
49
+ */
28
50
  maxParallelLogRequests: number;
51
+ /**
52
+ * Maximum number of parallel contract calls to execute in batch functions
53
+ */
29
54
  maxParallelCalls: number;
55
+ /**
56
+ * Maximum number of topics specified in the `ethereum_getLogs` RPC call
57
+ */
30
58
  maxLogTopics: number;
59
+ /**
60
+ * Whether to use EIP-2930 access lists for transactions, if set to `true` the transaction is simulated before
61
+ * sending and the access list is populated for the transaction
62
+ */
31
63
  useAccessLists?: boolean;
64
+ /**
65
+ * Default EIP-2930 addresses to add when simulating the transaction initially
66
+ */
32
67
  defaultAccessListAddresses?: string[];
68
+ /**
69
+ * Strategy for checking finality of transactions or events
70
+ */
33
71
  finalityCheckStrategy?: {
72
+ /**
73
+ * Type of the finality checking strategy:
74
+ * - `"timer"` - periodically checks for the finality status, set the interval period `delayMs`
75
+ * - `"blocks"` - check for the finality when new block is created
76
+ */
34
77
  type: "timer" | "blocks";
78
+ /**
79
+ * Interval in milliseconds to use for the `"timer"` type of finality checking strategy
80
+ */
35
81
  delayMs?: number;
36
82
  };
37
83
  };
@@ -42,15 +88,24 @@ export type EVMConfiguration = {
42
88
  export declare class EVMChainInterface<ChainId extends string = string> implements ChainInterface<EVMTx, SignedEVMTx, EVMSigner, ChainId, Signer> {
43
89
  readonly chainId: ChainId;
44
90
  readonly provider: JsonRpcApiProvider;
45
- readonly retryPolicy?: EVMRetryPolicy;
46
91
  readonly evmChainId: number;
47
- readonly config: EVMConfiguration;
92
+ /**
93
+ * @internal
94
+ */
95
+ readonly _retryPolicy?: EVMRetryPolicy;
96
+ /**
97
+ * @internal
98
+ */
99
+ readonly _config: EVMConfiguration;
48
100
  Fees: EVMFees;
49
101
  Tokens: EVMTokens;
50
102
  Transactions: EVMTransactions;
51
103
  Signatures: EVMSignatures;
52
104
  Events: EVMEvents;
53
105
  Blocks: EVMBlocks;
106
+ /**
107
+ * @internal
108
+ */
54
109
  protected logger: LoggerType;
55
110
  constructor(chainId: ChainId, evmChainId: number, provider: JsonRpcApiProvider, config: EVMConfiguration, retryPolicy?: EVMRetryPolicy, evmFeeEstimator?: EVMFees);
56
111
  /**
@@ -105,6 +160,10 @@ export declare class EVMChainInterface<ChainId extends string = string> implemen
105
160
  * @inheritDoc
106
161
  */
107
162
  sendSignedAndConfirm(signedTxs: Transaction[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
163
+ /**
164
+ * @inheritDoc
165
+ */
166
+ prepareTxs(txs: EVMTx[]): Promise<EVMTx[]>;
108
167
  /**
109
168
  * @inheritDoc
110
169
  */
@@ -22,12 +22,12 @@ class EVMChainInterface {
22
22
  this.chainId = chainId;
23
23
  this.evmChainId = evmChainId;
24
24
  this.provider = provider;
25
- this.retryPolicy = retryPolicy;
26
- this.config = config;
27
- (_a = this.config).safeBlockTag ?? (_a.safeBlockTag = "safe");
28
- (_b = this.config).finalizedBlockTag ?? (_b.finalizedBlockTag = "finalized");
29
- (_c = this.config).finalityCheckStrategy ?? (_c.finalityCheckStrategy = { type: "timer" });
30
- (_d = this.config.finalityCheckStrategy).delayMs ?? (_d.delayMs = 1000);
25
+ this._retryPolicy = retryPolicy;
26
+ this._config = config;
27
+ (_a = this._config).safeBlockTag ?? (_a.safeBlockTag = "safe");
28
+ (_b = this._config).finalizedBlockTag ?? (_b.finalizedBlockTag = "finalized");
29
+ (_c = this._config).finalityCheckStrategy ?? (_c.finalityCheckStrategy = { type: "timer" });
30
+ (_d = this._config.finalityCheckStrategy).delayMs ?? (_d.delayMs = 1000);
31
31
  this.logger = (0, Utils_1.getLogger)("EVMChainInterface(" + this.evmChainId + "): ");
32
32
  this.Fees = evmFeeEstimator;
33
33
  this.Tokens = new EVMTokens_1.EVMTokens(this);
@@ -118,6 +118,13 @@ class EVMChainInterface {
118
118
  sendSignedAndConfirm(signedTxs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
119
119
  return this.Transactions.sendSignedAndConfirm(signedTxs, waitForConfirmation, abortSignal, parallel, onBeforePublish);
120
120
  }
121
+ /**
122
+ * @inheritDoc
123
+ */
124
+ async prepareTxs(txs) {
125
+ await this.Transactions.prepareTransactions(txs);
126
+ return txs;
127
+ }
121
128
  /**
122
129
  * @inheritDoc
123
130
  */
@@ -158,7 +165,7 @@ class EVMChainInterface {
158
165
  * @inheritDoc
159
166
  */
160
167
  async getFinalizedBlock() {
161
- const block = await this.Blocks.getBlock(this.config.finalizedBlockTag);
168
+ const block = await this.Blocks.getBlock(this._config.finalizedBlockTag);
162
169
  return {
163
170
  height: block.number,
164
171
  blockHash: block.hash
@@ -1,5 +1,10 @@
1
1
  import { JsonRpcApiProvider } from "ethers";
2
2
  import { EVMChainInterface, EVMRetryPolicy } from "./EVMChainInterface";
3
+ /**
4
+ * Base module class shared by EVM chain submodules.
5
+ *
6
+ * @category Internal/Chain
7
+ */
3
8
  export declare class EVMModule<ChainId extends string = string> {
4
9
  protected readonly provider: JsonRpcApiProvider;
5
10
  protected readonly retryPolicy?: EVMRetryPolicy;
@@ -2,11 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EVMModule = void 0;
4
4
  const Utils_1 = require("../../utils/Utils");
5
+ /**
6
+ * Base module class shared by EVM chain submodules.
7
+ *
8
+ * @category Internal/Chain
9
+ */
5
10
  class EVMModule {
6
11
  constructor(root) {
7
12
  this.logger = (0, Utils_1.getLogger)(this.constructor.name + ": ");
8
13
  this.provider = root.provider;
9
- this.retryPolicy = root.retryPolicy;
14
+ this.retryPolicy = root._retryPolicy;
10
15
  this.root = root;
11
16
  }
12
17
  }
@@ -1,7 +1,14 @@
1
1
  import { EVMModule } from "../EVMModule";
2
2
  import { Block } from "ethers";
3
+ /**
4
+ * Supported EVM block tags used for safety/finality aware reads.
5
+ *
6
+ * @category Chain Interface
7
+ */
3
8
  export type EVMBlockTag = "safe" | "pending" | "latest" | "finalized";
4
9
  /**
10
+ * Cached block lookup helper for block and timestamp access.
11
+ *
5
12
  * @category Internal/Chain
6
13
  */
7
14
  export declare class EVMBlocks extends EVMModule<any> {
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EVMBlocks = void 0;
4
4
  const EVMModule_1 = require("../EVMModule");
5
5
  /**
6
+ * Cached block lookup helper for block and timestamp access.
7
+ *
6
8
  * @category Internal/Chain
7
9
  */
8
10
  class EVMBlocks extends EVMModule_1.EVMModule {
@@ -58,17 +58,17 @@ class EVMEvents extends EVMModule_1.EVMModule {
58
58
  events = await this.root.provider.getLogs({
59
59
  address: contract,
60
60
  fromBlock: startBlock,
61
- toBlock: endBlock == null ? this.root.config.safeBlockTag : endBlock,
61
+ toBlock: endBlock == null ? this.root._config.safeBlockTag : endBlock,
62
62
  topics
63
63
  });
64
64
  }
65
65
  else if (endBlock == null) {
66
- const safeBlock = await this.root.provider.getBlock(this.root.config.safeBlockTag);
66
+ const safeBlock = await this.root.provider.getBlock(this.root._config.safeBlockTag);
67
67
  if (safeBlock == null)
68
- throw new Error(`Cannot retrieve '${this.root.config.safeBlockTag}' block`);
69
- if (safeBlock.number - startBlock > this.root.config.maxLogsBlockRange) {
70
- for (let i = startBlock + this.root.config.maxLogsBlockRange; i < safeBlock.number; i += this.root.config.maxLogsBlockRange) {
71
- events.push(...await this.getLogs(contract, topics, i - this.root.config.maxLogsBlockRange, i));
68
+ throw new Error(`Cannot retrieve '${this.root._config.safeBlockTag}' block`);
69
+ if (safeBlock.number - startBlock > this.root._config.maxLogsBlockRange) {
70
+ for (let i = startBlock + this.root._config.maxLogsBlockRange; i < safeBlock.number; i += this.root._config.maxLogsBlockRange) {
71
+ events.push(...await this.getLogs(contract, topics, i - this.root._config.maxLogsBlockRange, i));
72
72
  startBlock = i;
73
73
  }
74
74
  }
@@ -76,9 +76,9 @@ class EVMEvents extends EVMModule_1.EVMModule {
76
76
  }
77
77
  else {
78
78
  //Both numeric
79
- if (endBlock - startBlock > this.root.config.maxLogsBlockRange) {
80
- for (let i = startBlock + this.root.config.maxLogsBlockRange; i < endBlock; i += this.root.config.maxLogsBlockRange) {
81
- events.push(...await this.getLogs(contract, topics, i - this.root.config.maxLogsBlockRange, i));
79
+ if (endBlock - startBlock > this.root._config.maxLogsBlockRange) {
80
+ for (let i = startBlock + this.root._config.maxLogsBlockRange; i < endBlock; i += this.root._config.maxLogsBlockRange) {
81
+ events.push(...await this.getLogs(contract, topics, i - this.root._config.maxLogsBlockRange, i));
82
82
  startBlock = i;
83
83
  }
84
84
  }
@@ -97,13 +97,13 @@ class EVMEvents extends EVMModule_1.EVMModule {
97
97
  * @param genesisHeight Height when the contract was deployed
98
98
  */
99
99
  async findInEvents(contract, topics, processor, abortSignal, genesisHeight) {
100
- const latestBlock = await this.provider.getBlock(this.root.config.safeBlockTag);
100
+ const latestBlock = await this.provider.getBlock(this.root._config.safeBlockTag);
101
101
  if (latestBlock == null)
102
- throw new Error(`Cannot find block ${this.root.config.safeBlockTag}`);
102
+ throw new Error(`Cannot find block ${this.root._config.safeBlockTag}`);
103
103
  let promises = [];
104
- for (let blockNumber = latestBlock.number; blockNumber >= (genesisHeight ?? 0); blockNumber -= this.root.config.maxLogsBlockRange) {
105
- promises.push(this.getLogs(contract, topics, Math.max(blockNumber - this.root.config.maxLogsBlockRange, 0), blockNumber));
106
- if (promises.length >= this.root.config.maxParallelLogRequests) {
104
+ for (let blockNumber = latestBlock.number; blockNumber >= (genesisHeight ?? 0); blockNumber -= this.root._config.maxLogsBlockRange) {
105
+ promises.push(this.getLogs(contract, topics, Math.max(blockNumber - this.root._config.maxLogsBlockRange, 0), blockNumber));
106
+ if (promises.length >= this.root._config.maxParallelLogRequests) {
107
107
  const eventsResult = (await Promise.all(promises)).map(arr => arr.reverse() //Oldest events first
108
108
  ).flat();
109
109
  promises = [];
@@ -134,13 +134,13 @@ class EVMEvents extends EVMModule_1.EVMModule {
134
134
  * @param startHeight Blockheight at which to start
135
135
  */
136
136
  async findInEventsForward(contract, topics, processor, abortSignal, startHeight) {
137
- const latestBlock = await this.provider.getBlock(this.root.config.safeBlockTag);
137
+ const latestBlock = await this.provider.getBlock(this.root._config.safeBlockTag);
138
138
  if (latestBlock == null)
139
- throw new Error(`Cannot find block ${this.root.config.safeBlockTag}`);
139
+ throw new Error(`Cannot find block ${this.root._config.safeBlockTag}`);
140
140
  let promises = [];
141
- for (let blockNumber = startHeight ?? 0; blockNumber < latestBlock.number; blockNumber += this.root.config.maxLogsBlockRange) {
142
- promises.push(this.getLogs(contract, topics, blockNumber, Math.min(blockNumber + this.root.config.maxLogsBlockRange, latestBlock.number)));
143
- if (promises.length >= this.root.config.maxParallelLogRequests) {
141
+ for (let blockNumber = startHeight ?? 0; blockNumber < latestBlock.number; blockNumber += this.root._config.maxLogsBlockRange) {
142
+ promises.push(this.getLogs(contract, topics, blockNumber, Math.min(blockNumber + this.root._config.maxLogsBlockRange, latestBlock.number)));
143
+ if (promises.length >= this.root._config.maxParallelLogRequests) {
144
144
  const eventsResult = (await Promise.all(promises)).flat();
145
145
  promises = [];
146
146
  if (abortSignal != null)
@@ -1,19 +1,50 @@
1
1
  import { JsonRpcApiProvider, TransactionRequest } from "ethers";
2
+ /**
3
+ * Parsed EIP-1559 fee rate components.
4
+ *
5
+ * @category Chain Interface
6
+ */
2
7
  export type EVMFeeRate = {
3
8
  maxFeePerGas: bigint;
4
9
  maxPriorityFee: bigint;
5
10
  };
6
11
  /**
12
+ * Fee estimation service for EVM chains.
13
+ *
7
14
  * @category Chain Interface
8
15
  */
9
16
  export declare class EVMFees {
17
+ /**
18
+ * @internal
19
+ */
10
20
  protected MAX_FEE_AGE: number;
21
+ /**
22
+ * @internal
23
+ */
11
24
  protected readonly logger: import("../../../utils/Utils").LoggerType;
25
+ /**
26
+ * @internal
27
+ */
12
28
  protected readonly provider: JsonRpcApiProvider;
29
+ /**
30
+ * @internal
31
+ */
13
32
  protected readonly maxFeeRatePerGas: bigint;
33
+ /**
34
+ * @internal
35
+ */
14
36
  protected readonly priorityFee: bigint;
37
+ /**
38
+ * @internal
39
+ */
15
40
  protected readonly feeMultiplierPPM: bigint;
16
41
  private blockFeeCache?;
42
+ /**
43
+ * @param provider Underlying RPC provider providing read access to the EVM network
44
+ * @param maxFeeRatePerGas Maximum fee rate for a transaction, default to 500 GWei
45
+ * @param priorityFee Priority fee (or tip) to add to the transactions, default to 1 GWei
46
+ * @param feeMultiplier Fee multiplier to multiply the RPC-returned fee rate with
47
+ */
17
48
  constructor(provider: JsonRpcApiProvider, maxFeeRatePerGas?: bigint, priorityFee?: bigint, feeMultiplier?: number);
18
49
  /**
19
50
  * Gets evm fee rate
@@ -23,17 +54,22 @@ export declare class EVMFees {
23
54
  */
24
55
  private _getFeeRate;
25
56
  /**
26
- * Gets the gas price with caching, format: <base fee Wei>,<priority fee Wei>
27
- *
28
- * @private
57
+ * Gets the gas price with caching, format: `<base fee Wei>,<priority fee Wei>`
29
58
  */
30
59
  getFeeRate(): Promise<string>;
31
60
  /**
32
61
  * Calculates the total gas fee paid for a given gas limit at a given fee rate
33
62
  *
34
- * @param gas
35
- * @param feeRate
63
+ * @param gas Gas limit to add to the transaction
64
+ * @param feeRate Serialized fee rate to add to the transaction, in format: `<baseFee>,<priorityFee>`
36
65
  */
37
66
  static getGasFee(gas: number, feeRate: string): bigint;
67
+ /**
68
+ * Applies the gas limit and fee rate to a transaction
69
+ *
70
+ * @param tx EVM Transaction to apply the fee rate to
71
+ * @param gas Gas limit to add to the transaction
72
+ * @param feeRate Serialized fee rate to add to the transaction, in format: `<baseFee>,<priorityFee>`
73
+ */
38
74
  static applyFeeRate(tx: TransactionRequest, gas: number | null, feeRate: string): void;
39
75
  }
@@ -3,11 +3,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EVMFees = void 0;
4
4
  const Utils_1 = require("../../../utils/Utils");
5
5
  /**
6
+ * Fee estimation service for EVM chains.
7
+ *
6
8
  * @category Chain Interface
7
9
  */
8
10
  class EVMFees {
11
+ /**
12
+ * @param provider Underlying RPC provider providing read access to the EVM network
13
+ * @param maxFeeRatePerGas Maximum fee rate for a transaction, default to 500 GWei
14
+ * @param priorityFee Priority fee (or tip) to add to the transactions, default to 1 GWei
15
+ * @param feeMultiplier Fee multiplier to multiply the RPC-returned fee rate with
16
+ */
9
17
  constructor(provider, maxFeeRatePerGas = 500n * 1000000000n, priorityFee = 1n * 1000000000n, feeMultiplier = 1.25) {
18
+ /**
19
+ * @internal
20
+ */
10
21
  this.MAX_FEE_AGE = 5000;
22
+ /**
23
+ * @internal
24
+ */
11
25
  this.logger = (0, Utils_1.getLogger)("EVMFees: ");
12
26
  this.provider = provider;
13
27
  this.maxFeeRatePerGas = maxFeeRatePerGas;
@@ -31,9 +45,7 @@ class EVMFees {
31
45
  return baseFee;
32
46
  }
33
47
  /**
34
- * Gets the gas price with caching, format: <base fee Wei>,<priority fee Wei>
35
- *
36
- * @private
48
+ * Gets the gas price with caching, format: `<base fee Wei>,<priority fee Wei>`
37
49
  */
38
50
  async getFeeRate() {
39
51
  if (this.blockFeeCache == null || Date.now() - this.blockFeeCache.timestamp > this.MAX_FEE_AGE) {
@@ -57,8 +69,8 @@ class EVMFees {
57
69
  /**
58
70
  * Calculates the total gas fee paid for a given gas limit at a given fee rate
59
71
  *
60
- * @param gas
61
- * @param feeRate
72
+ * @param gas Gas limit to add to the transaction
73
+ * @param feeRate Serialized fee rate to add to the transaction, in format: `<baseFee>,<priorityFee>`
62
74
  */
63
75
  static getGasFee(gas, feeRate) {
64
76
  if (feeRate == null)
@@ -66,6 +78,13 @@ class EVMFees {
66
78
  const [baseFee, priorityFee] = feeRate.split(",");
67
79
  return BigInt(gas) * (BigInt(baseFee) + BigInt(priorityFee));
68
80
  }
81
+ /**
82
+ * Applies the gas limit and fee rate to a transaction
83
+ *
84
+ * @param tx EVM Transaction to apply the fee rate to
85
+ * @param gas Gas limit to add to the transaction
86
+ * @param feeRate Serialized fee rate to add to the transaction, in format: `<baseFee>,<priorityFee>`
87
+ */
69
88
  static applyFeeRate(tx, gas, feeRate) {
70
89
  if (feeRate == null)
71
90
  return;
@@ -11,7 +11,7 @@ export declare class EVMTokens extends EVMModule<any> {
11
11
  };
12
12
  private getContract;
13
13
  /**
14
- * Checks if the provided string is a valid starknet token
14
+ * Checks if the provided string is a valid EVM token address.
15
15
  *
16
16
  * @param token
17
17
  */
@@ -16,7 +16,7 @@ class EVMTokens extends EVMModule_1.EVMModule {
16
16
  ///////////////////
17
17
  //// Tokens
18
18
  /**
19
- * Checks if the provided string is a valid starknet token
19
+ * Checks if the provided string is a valid EVM token address.
20
20
  *
21
21
  * @param token
22
22
  */
@@ -1,8 +1,23 @@
1
1
  import { EVMModule } from "../EVMModule";
2
2
  import { Transaction, TransactionRequest } from "ethers";
3
3
  import { EVMSigner } from "../../wallet/EVMSigner";
4
+ /**
5
+ * Unsigned EVM transaction type used by chain modules.
6
+ *
7
+ * @category Chain Interface
8
+ */
4
9
  export type EVMTx = TransactionRequest;
10
+ /**
11
+ * Signed EVM transaction type as produced by ethers.
12
+ *
13
+ * @category Chain Interface
14
+ */
5
15
  export type SignedEVMTx = Transaction;
16
+ /**
17
+ * Simplified call-trace structure returned by `debug_traceTransaction` with `callTracer`.
18
+ *
19
+ * @category Internal/Chain
20
+ */
6
21
  export type EVMTxTrace = {
7
22
  from: string;
8
23
  gas: string;
@@ -16,6 +31,8 @@ export type EVMTxTrace = {
16
31
  type: "CREATE" | "CALL" | "STATICCALL";
17
32
  };
18
33
  /**
34
+ * Transaction service for preparing, signing, broadcasting and confirming EVM transactions.
35
+ *
19
36
  * @category Internal/Chain
20
37
  */
21
38
  export declare class EVMTransactions extends EVMModule<any> {
@@ -36,14 +53,14 @@ export declare class EVMTransactions extends EVMModule<any> {
36
53
  private confirmTransaction;
37
54
  private applyAccessList;
38
55
  /**
39
- * Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
56
+ * Prepares EVM transactions, assigns nonces when needed, and optionally applies access lists
57
+ * before signing.
40
58
  *
41
- * @param signer
42
59
  * @param txs
60
+ * @param signer
43
61
  * @param useAccessList Whether to use access lists for sending txns
44
- * @private
45
62
  */
46
- private prepareTransactions;
63
+ prepareTransactions(txs: TransactionRequest[], signer?: EVMSigner, useAccessList?: boolean): Promise<void>;
47
64
  /**
48
65
  * Sends out a signed transaction to the RPC
49
66
  *
@@ -93,7 +110,7 @@ export declare class EVMTransactions extends EVMModule<any> {
93
110
  */
94
111
  deserializeSignedTx(signedTxData: string): Transaction;
95
112
  /**
96
- * Gets the status of the raw starknet transaction
113
+ * Gets the status of a raw signed EVM transaction.
97
114
  *
98
115
  * @param tx
99
116
  */
@@ -7,6 +7,8 @@ const Utils_1 = require("../../../utils/Utils");
7
7
  const base_1 = require("@atomiqlabs/base");
8
8
  const MAX_UNCONFIRMED_TXNS = 10;
9
9
  /**
10
+ * Transaction service for preparing, signing, broadcasting and confirming EVM transactions.
11
+ *
10
12
  * @category Internal/Chain
11
13
  */
12
14
  class EVMTransactions extends EVMModule_1.EVMModule {
@@ -59,7 +61,7 @@ class EVMTransactions extends EVMModule_1.EVMModule {
59
61
  }
60
62
  this.logger.warn("confirmTransaction(): All transactions not found, fetching the latest account nonce...");
61
63
  const _latestConfirmedNonce = this.latestConfirmedNonces[tx.from];
62
- const currentLatestNonce = await this.provider.getTransactionCount(tx.from, this.root.config.safeBlockTag);
64
+ const currentLatestNonce = await this.provider.getTransactionCount(tx.from, this.root._config.safeBlockTag);
63
65
  if (_latestConfirmedNonce == null || _latestConfirmedNonce < currentLatestNonce) {
64
66
  this.latestConfirmedNonces[tx.from] = currentLatestNonce;
65
67
  }
@@ -97,9 +99,9 @@ class EVMTransactions extends EVMModule_1.EVMModule {
97
99
  value: (0, ethers_1.toBeHex)(tx.value ?? 0n),
98
100
  input: tx.data,
99
101
  data: tx.data,
100
- accessList: this.root.config.defaultAccessListAddresses == null
102
+ accessList: this.root._config.defaultAccessListAddresses == null
101
103
  ? undefined
102
- : this.root.config.defaultAccessListAddresses.map(val => ({ address: val, storageKeys: [] }))
104
+ : this.root._config.defaultAccessListAddresses.map(val => ({ address: val, storageKeys: [] }))
103
105
  }, "pending"]);
104
106
  }
105
107
  catch (e) {
@@ -112,21 +114,27 @@ class EVMTransactions extends EVMModule_1.EVMModule {
112
114
  tx.accessList = accessListResponse.accessList;
113
115
  }
114
116
  /**
115
- * Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
117
+ * Prepares EVM transactions, assigns nonces when needed, and optionally applies access lists
118
+ * before signing.
116
119
  *
117
- * @param signer
118
120
  * @param txs
121
+ * @param signer
119
122
  * @param useAccessList Whether to use access lists for sending txns
120
- * @private
121
123
  */
122
- async prepareTransactions(signer, txs, useAccessList) {
124
+ async prepareTransactions(txs, signer, useAccessList) {
125
+ if (txs.length === 0)
126
+ return;
127
+ const signerAddress = signer?.getAddress()
128
+ ?? (txs[0].from == null ? null : await (0, ethers_1.resolveAddress)(txs[0].from, this.provider));
129
+ if (signerAddress == null)
130
+ throw new Error("Cannot get tx sender address!");
123
131
  for (let tx of txs) {
124
132
  tx.chainId = this.root.evmChainId;
125
- tx.from = signer.getAddress();
133
+ tx.from = signerAddress;
126
134
  }
127
- if (!signer.isManagingNoncesInternally) {
128
- let nonce = await this.root.provider.getTransactionCount(signer.getAddress(), "pending");
129
- const latestKnownNonce = this.latestPendingNonces[signer.getAddress()];
135
+ if (signer == null || !signer.isManagingNoncesInternally) {
136
+ let nonce = await this.root.provider.getTransactionCount(signerAddress, "pending");
137
+ const latestKnownNonce = this.latestPendingNonces[signerAddress];
130
138
  if (latestKnownNonce != null && latestKnownNonce > nonce) {
131
139
  this.logger.debug("prepareTransactions(): Using nonce from local cache!");
132
140
  nonce = latestKnownNonce;
@@ -136,20 +144,21 @@ class EVMTransactions extends EVMModule_1.EVMModule {
136
144
  if (tx.nonce != null)
137
145
  nonce = tx.nonce; //Take the nonce from last tx
138
146
  if (nonce == null)
139
- nonce = await this.root.provider.getTransactionCount(signer.getAddress(), "pending"); //Fetch the nonce
147
+ nonce = await this.root.provider.getTransactionCount(signerAddress, "pending"); //Fetch the nonce
140
148
  if (tx.nonce == null)
141
149
  tx.nonce = nonce;
142
150
  this.logger.debug("sendAndConfirm(): transaction prepared (" + (i + 1) + "/" + txs.length + "), nonce: " + tx.nonce);
143
151
  nonce++;
144
152
  }
145
153
  }
146
- for (let tx of txs) {
147
- if (useAccessList)
148
- await this.applyAccessList(tx);
149
- for (let callback of this.cbksBeforeTxSigned) {
150
- await callback(tx);
154
+ if (signer != null)
155
+ for (let tx of txs) {
156
+ if (useAccessList)
157
+ await this.applyAccessList(tx);
158
+ for (let callback of this.cbksBeforeTxSigned) {
159
+ await callback(tx);
160
+ }
151
161
  }
152
- }
153
162
  }
154
163
  /**
155
164
  * Sends out a signed transaction to the RPC
@@ -188,7 +197,7 @@ class EVMTransactions extends EVMModule_1.EVMModule {
188
197
  * @param useAccessLists
189
198
  */
190
199
  async sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish, useAccessLists) {
191
- await this.prepareTransactions(signer, txs, useAccessLists ?? this.root.config.useAccessLists);
200
+ await this.prepareTransactions(txs, signer, useAccessLists ?? this.root._config.useAccessLists);
192
201
  const signedTxs = [];
193
202
  //Don't separate the signing process from the sending when using browser-based wallet
194
203
  if (signer.signTransaction != null)
@@ -361,7 +370,7 @@ class EVMTransactions extends EVMModule_1.EVMModule {
361
370
  return ethers_1.Transaction.from(signedTxData);
362
371
  }
363
372
  /**
364
- * Gets the status of the raw starknet transaction
373
+ * Gets the status of a raw signed EVM transaction.
365
374
  *
366
375
  * @param tx
367
376
  */
@@ -381,9 +390,9 @@ class EVMTransactions extends EVMModule_1.EVMModule {
381
390
  if (txResponse.blockHash == null)
382
391
  return "pending";
383
392
  const [safeBlockNumber, txReceipt] = await Promise.all([
384
- this.root.config.safeBlockTag === "latest"
393
+ this.root._config.safeBlockTag === "latest"
385
394
  ? Promise.resolve(null)
386
- : this.provider.getBlock(this.root.config.safeBlockTag).then(res => res?.number ?? 0),
395
+ : this.provider.getBlock(this.root._config.safeBlockTag).then(res => res?.number ?? 0),
387
396
  this.provider.getTransactionReceipt(txId)
388
397
  ]);
389
398
  if (txReceipt == null || (safeBlockNumber != null && txReceipt.blockNumber > safeBlockNumber))