@atomiqlabs/chain-evm 1.0.2 → 1.0.4

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.
@@ -20,6 +20,7 @@ export type EVMConfiguration = {
20
20
  maxParallelLogRequests: number;
21
21
  maxParallelCalls: number;
22
22
  maxLogTopics: number;
23
+ useAccessLists?: boolean;
23
24
  };
24
25
  export declare class EVMChainInterface<ChainId extends string = string> implements ChainInterface<EVMTx, EVMSigner, ChainId, Signer> {
25
26
  readonly chainId: ChainId;
@@ -30,11 +30,13 @@ export declare class EVMTransactions extends EVMModule<any> {
30
30
  * @private
31
31
  */
32
32
  private confirmTransaction;
33
+ private applyAccessList;
33
34
  /**
34
35
  * Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
35
36
  *
36
37
  * @param signer
37
38
  * @param txs
39
+ * @param useAccessList Whether to use access lists for sending txns
38
40
  * @private
39
41
  */
40
42
  private prepareTransactions;
@@ -58,8 +60,9 @@ export declare class EVMTransactions extends EVMModule<any> {
58
60
  * @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
59
61
  * are executed in order)
60
62
  * @param onBeforePublish a callback called before every transaction is published, NOTE: callback is not called when using browser-based wallet!
63
+ * @param useAccessLists
61
64
  */
62
- sendAndConfirm(signer: EVMSigner, txs: TransactionRequest[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]>;
65
+ sendAndConfirm(signer: EVMSigner, txs: TransactionRequest[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>, useAccessLists?: boolean): Promise<string[]>;
63
66
  /**
64
67
  * Serializes the signed EVM transaction
65
68
  *
@@ -72,14 +72,20 @@ class EVMTransactions extends EVMModule_1.EVMModule {
72
72
  throw new base_1.TransactionRevertedError("Transaction reverted!");
73
73
  return confirmedTxId;
74
74
  }
75
+ async applyAccessList(tx) {
76
+ const accessListResponse = await this.provider.send("eth_createAccessList", [tx, "pending"]);
77
+ const result = accessListResponse.result;
78
+ tx.accessList = result.accessList;
79
+ }
75
80
  /**
76
81
  * Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
77
82
  *
78
83
  * @param signer
79
84
  * @param txs
85
+ * @param useAccessList Whether to use access lists for sending txns
80
86
  * @private
81
87
  */
82
- async prepareTransactions(signer, txs) {
88
+ async prepareTransactions(signer, txs, useAccessList) {
83
89
  for (let tx of txs) {
84
90
  tx.chainId = this.root.evmChainId;
85
91
  tx.from = signer.getAddress();
@@ -104,6 +110,8 @@ class EVMTransactions extends EVMModule_1.EVMModule {
104
110
  }
105
111
  }
106
112
  for (let tx of txs) {
113
+ if (useAccessList)
114
+ await this.applyAccessList(tx);
107
115
  for (let callback of this.cbksBeforeTxSigned) {
108
116
  await callback(tx);
109
117
  }
@@ -143,9 +151,10 @@ class EVMTransactions extends EVMModule_1.EVMModule {
143
151
  * @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
144
152
  * are executed in order)
145
153
  * @param onBeforePublish a callback called before every transaction is published, NOTE: callback is not called when using browser-based wallet!
154
+ * @param useAccessLists
146
155
  */
147
- async sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish) {
148
- await this.prepareTransactions(signer, txs);
156
+ async sendAndConfirm(signer, txs, waitForConfirmation, abortSignal, parallel, onBeforePublish, useAccessLists) {
157
+ await this.prepareTransactions(signer, txs, useAccessLists ?? this.root.config.useAccessLists);
149
158
  const signedTxs = [];
150
159
  //Don't separate the signing process from the sending when using browser-based wallet
151
160
  if (signer.signTransaction != null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-evm",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "EVM specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -32,7 +32,9 @@ export type EVMConfiguration = {
32
32
  maxLogsBlockRange: number,
33
33
  maxParallelLogRequests: number,
34
34
  maxParallelCalls: number,
35
- maxLogTopics: number
35
+ maxLogTopics: number,
36
+
37
+ useAccessLists?: boolean
36
38
  };
37
39
 
38
40
  export class EVMChainInterface<ChainId extends string = string> implements ChainInterface<EVMTx, EVMSigner, ChainId, Signer> {
@@ -1,5 +1,5 @@
1
1
  import {EVMModule} from "../EVMModule";
2
- import {Transaction, TransactionRequest, TransactionResponse} from "ethers";
2
+ import {JsonRpcResult, makeError, Transaction, TransactionRequest, TransactionResponse} from "ethers";
3
3
  import {timeoutPromise} from "../../../utils/Utils";
4
4
  import {EVMSigner} from "../../wallet/EVMSigner";
5
5
  import {TransactionRevertedError} from "@atomiqlabs/base";
@@ -93,14 +93,23 @@ export class EVMTransactions extends EVMModule<any> {
93
93
  return confirmedTxId;
94
94
  }
95
95
 
96
+ private async applyAccessList(tx: TransactionRequest) {
97
+ const accessListResponse: JsonRpcResult = await this.provider.send("eth_createAccessList", [tx, "pending"]);
98
+ const result: {
99
+ accessList: {address: string, storageKeys: string[]}[]
100
+ } = accessListResponse.result;
101
+ tx.accessList = result.accessList;
102
+ }
103
+
96
104
  /**
97
105
  * Prepares starknet transactions, checks if the account is deployed, assigns nonces if needed & calls beforeTxSigned callback
98
106
  *
99
107
  * @param signer
100
108
  * @param txs
109
+ * @param useAccessList Whether to use access lists for sending txns
101
110
  * @private
102
111
  */
103
- private async prepareTransactions(signer: EVMSigner, txs: TransactionRequest[]): Promise<void> {
112
+ private async prepareTransactions(signer: EVMSigner, txs: TransactionRequest[], useAccessList?: boolean): Promise<void> {
104
113
  for(let tx of txs) {
105
114
  tx.chainId = this.root.evmChainId;
106
115
  tx.from = signer.getAddress();
@@ -127,6 +136,7 @@ export class EVMTransactions extends EVMModule<any> {
127
136
  }
128
137
 
129
138
  for(let tx of txs) {
139
+ if(useAccessList) await this.applyAccessList(tx);
130
140
  for(let callback of this.cbksBeforeTxSigned) {
131
141
  await callback(tx);
132
142
  }
@@ -172,9 +182,14 @@ export class EVMTransactions extends EVMModule<any> {
172
182
  * @param parallel whether the send all the transaction at once in parallel or sequentially (such that transactions
173
183
  * are executed in order)
174
184
  * @param onBeforePublish a callback called before every transaction is published, NOTE: callback is not called when using browser-based wallet!
185
+ * @param useAccessLists
175
186
  */
176
- public async sendAndConfirm(signer: EVMSigner, txs: TransactionRequest[], waitForConfirmation?: boolean, abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>): Promise<string[]> {
177
- await this.prepareTransactions(signer, txs);
187
+ public async sendAndConfirm(
188
+ signer: EVMSigner, txs: TransactionRequest[], waitForConfirmation?: boolean,
189
+ abortSignal?: AbortSignal, parallel?: boolean, onBeforePublish?: (txId: string, rawTx: string) => Promise<void>,
190
+ useAccessLists?: boolean
191
+ ): Promise<string[]> {
192
+ await this.prepareTransactions(signer, txs, useAccessLists ?? this.root.config.useAccessLists);
178
193
  const signedTxs: Transaction[] = [];
179
194
 
180
195
  //Don't separate the signing process from the sending when using browser-based wallet