@metamask-previews/transaction-controller 25.1.0-preview-da8ff5ef → 25.1.0-preview-a3500873

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 (38) hide show
  1. package/dist/TransactionController.js +5 -5
  2. package/dist/TransactionController.mjs +4 -4
  3. package/dist/{chunk-2MUK5JWA.js → chunk-JCGCPGGI.js} +3 -3
  4. package/dist/{chunk-DX4NUE4H.mjs → chunk-JRQKQEJG.mjs} +4 -3
  5. package/dist/chunk-JRQKQEJG.mjs.map +1 -0
  6. package/dist/{chunk-6FF5JJVB.mjs → chunk-OXRUL7JF.mjs} +4 -3
  7. package/dist/chunk-OXRUL7JF.mjs.map +1 -0
  8. package/dist/{chunk-CBKVKDFC.js → chunk-S222HWGT.js} +4 -3
  9. package/dist/chunk-S222HWGT.js.map +1 -0
  10. package/dist/{chunk-WCJ7I43R.mjs → chunk-WBE2B3XJ.mjs} +2 -2
  11. package/dist/{chunk-SBZB2FLU.mjs → chunk-WIVEC2DS.mjs} +27 -4
  12. package/dist/chunk-WIVEC2DS.mjs.map +1 -0
  13. package/dist/{chunk-EXFVMWXE.js → chunk-WUTU5BUB.js} +31 -8
  14. package/dist/chunk-WUTU5BUB.js.map +1 -0
  15. package/dist/{chunk-GKCF2RYY.js → chunk-XRHCFQ3K.js} +5 -4
  16. package/dist/chunk-XRHCFQ3K.js.map +1 -0
  17. package/dist/gas-flows/OptimismLayer1GasFeeFlow.js +3 -3
  18. package/dist/gas-flows/OptimismLayer1GasFeeFlow.mjs +2 -2
  19. package/dist/helpers/GasFeePoller.js +3 -3
  20. package/dist/helpers/GasFeePoller.mjs +2 -2
  21. package/dist/index.js +5 -5
  22. package/dist/index.mjs +4 -4
  23. package/dist/tsconfig.build.tsbuildinfo +1 -1
  24. package/dist/types/TransactionController.d.ts +8 -0
  25. package/dist/types/TransactionController.d.ts.map +1 -1
  26. package/dist/types/utils/layer1-gas-fee-flow.d.ts +9 -0
  27. package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +1 -1
  28. package/dist/utils/layer1-gas-fee-flow.js +4 -2
  29. package/dist/utils/layer1-gas-fee-flow.mjs +3 -1
  30. package/package.json +1 -1
  31. package/dist/chunk-6FF5JJVB.mjs.map +0 -1
  32. package/dist/chunk-CBKVKDFC.js.map +0 -1
  33. package/dist/chunk-DX4NUE4H.mjs.map +0 -1
  34. package/dist/chunk-EXFVMWXE.js.map +0 -1
  35. package/dist/chunk-GKCF2RYY.js.map +0 -1
  36. package/dist/chunk-SBZB2FLU.mjs.map +0 -1
  37. /package/dist/{chunk-2MUK5JWA.js.map → chunk-JCGCPGGI.js.map} +0 -0
  38. /package/dist/{chunk-WCJ7I43R.mjs.map → chunk-WBE2B3XJ.mjs.map} +0 -0
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkEXFVMWXEjs = require('./chunk-EXFVMWXE.js');
7
+ var _chunkWUTU5BUBjs = require('./chunk-WUTU5BUB.js');
8
8
  require('./chunk-HS277C77.js');
9
9
  require('./chunk-VH47Q6TS.js');
10
10
  require('./chunk-RQKICZYP.js');
@@ -12,7 +12,7 @@ require('./chunk-QP75SWIQ.js');
12
12
  require('./chunk-ZNZEJDOE.js');
13
13
  require('./chunk-WXQZIUNW.js');
14
14
  require('./chunk-4S25HUCL.js');
15
- require('./chunk-2MUK5JWA.js');
15
+ require('./chunk-JCGCPGGI.js');
16
16
  require('./chunk-DTDTOMTB.js');
17
17
  require('./chunk-7C6ERJJC.js');
18
18
  require('./chunk-F3CMU2DM.js');
@@ -26,8 +26,8 @@ require('./chunk-5OQ373JS.js');
26
26
  require('./chunk-UGFBA4GV.js');
27
27
  require('./chunk-2MMWLJXS.js');
28
28
  require('./chunk-TUW3M44L.js');
29
- require('./chunk-GKCF2RYY.js');
30
- require('./chunk-CBKVKDFC.js');
29
+ require('./chunk-XRHCFQ3K.js');
30
+ require('./chunk-S222HWGT.js');
31
31
  require('./chunk-ITDY6AIZ.js');
32
32
  require('./chunk-S6VGOPUY.js');
33
33
  require('./chunk-Z4BLTVTB.js');
@@ -37,5 +37,5 @@ require('./chunk-Z4BLTVTB.js');
37
37
 
38
38
 
39
39
 
40
- exports.ApprovalState = _chunkEXFVMWXEjs.ApprovalState; exports.CANCEL_RATE = _chunkEXFVMWXEjs.CANCEL_RATE; exports.HARDFORK = _chunkEXFVMWXEjs.HARDFORK; exports.SPEED_UP_RATE = _chunkEXFVMWXEjs.SPEED_UP_RATE; exports.TransactionController = _chunkEXFVMWXEjs.TransactionController;
40
+ exports.ApprovalState = _chunkWUTU5BUBjs.ApprovalState; exports.CANCEL_RATE = _chunkWUTU5BUBjs.CANCEL_RATE; exports.HARDFORK = _chunkWUTU5BUBjs.HARDFORK; exports.SPEED_UP_RATE = _chunkWUTU5BUBjs.SPEED_UP_RATE; exports.TransactionController = _chunkWUTU5BUBjs.TransactionController;
41
41
  //# sourceMappingURL=TransactionController.js.map
@@ -4,7 +4,7 @@ import {
4
4
  HARDFORK,
5
5
  SPEED_UP_RATE,
6
6
  TransactionController
7
- } from "./chunk-SBZB2FLU.mjs";
7
+ } from "./chunk-WIVEC2DS.mjs";
8
8
  import "./chunk-JRBREX22.mjs";
9
9
  import "./chunk-NM6OYEPP.mjs";
10
10
  import "./chunk-XKNFL657.mjs";
@@ -12,7 +12,7 @@ import "./chunk-XGRAHX6T.mjs";
12
12
  import "./chunk-NHRBO3LU.mjs";
13
13
  import "./chunk-QSBIXUMB.mjs";
14
14
  import "./chunk-7XPI7KU5.mjs";
15
- import "./chunk-WCJ7I43R.mjs";
15
+ import "./chunk-WBE2B3XJ.mjs";
16
16
  import "./chunk-Y7ENNK7L.mjs";
17
17
  import "./chunk-Z6HYOGNR.mjs";
18
18
  import "./chunk-IZI7FQIN.mjs";
@@ -26,8 +26,8 @@ import "./chunk-3D3SA6PY.mjs";
26
26
  import "./chunk-J56A7UCK.mjs";
27
27
  import "./chunk-6KYPLIXG.mjs";
28
28
  import "./chunk-XOIPXDGX.mjs";
29
- import "./chunk-DX4NUE4H.mjs";
30
- import "./chunk-6FF5JJVB.mjs";
29
+ import "./chunk-JRQKQEJG.mjs";
30
+ import "./chunk-OXRUL7JF.mjs";
31
31
  import "./chunk-Z3HHSD5I.mjs";
32
32
  import "./chunk-UQQWZT6C.mjs";
33
33
  import "./chunk-XUI43LEZ.mjs";
@@ -3,7 +3,7 @@
3
3
  var _chunk2MMWLJXSjs = require('./chunk-2MMWLJXS.js');
4
4
 
5
5
 
6
- var _chunkCBKVKDFCjs = require('./chunk-CBKVKDFC.js');
6
+ var _chunkS222HWGTjs = require('./chunk-S222HWGT.js');
7
7
 
8
8
 
9
9
  var _chunkS6VGOPUYjs = require('./chunk-S6VGOPUY.js');
@@ -164,7 +164,7 @@ _updateTransactionLayer1GasFee = new WeakSet();
164
164
  updateTransactionLayer1GasFee_fn = async function(transactionMeta) {
165
165
  const { chainId, networkClientId } = transactionMeta;
166
166
  const provider = _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _getProvider).call(this, chainId, networkClientId);
167
- await _chunkCBKVKDFCjs.updateTransactionLayer1GasFee.call(void 0, {
167
+ await _chunkS222HWGTjs.updateTransactionLayer1GasFee.call(void 0, {
168
168
  provider,
169
169
  layer1GasFeeFlows: _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _layer1GasFeeFlows),
170
170
  transactionMeta
@@ -184,4 +184,4 @@ getUnapprovedTransactions_fn = function() {
184
184
 
185
185
 
186
186
  exports.GasFeePoller = GasFeePoller;
187
- //# sourceMappingURL=chunk-2MUK5JWA.js.map
187
+ //# sourceMappingURL=chunk-JCGCPGGI.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  buildUnserializedTransaction
3
- } from "./chunk-6FF5JJVB.mjs";
3
+ } from "./chunk-OXRUL7JF.mjs";
4
4
  import {
5
5
  CHAIN_IDS
6
6
  } from "./chunk-Z3HHSD5I.mjs";
@@ -14,6 +14,7 @@ import {
14
14
 
15
15
  // src/gas-flows/OptimismLayer1GasFeeFlow.ts
16
16
  import { Contract } from "@ethersproject/contracts";
17
+ import { Web3Provider } from "@ethersproject/providers";
17
18
  import { createModuleLogger } from "@metamask/utils";
18
19
  var OPTIMISIM_CHAIN_IDS = [
19
20
  CHAIN_IDS.OPTIMISM,
@@ -54,7 +55,7 @@ getOptimisimLayer1GasFee_fn = async function(request) {
54
55
  OPTIMISM_GAS_PRICE_ORACLE_ADDRESS,
55
56
  OPTIMISM_GAS_PRICE_ORACLE_ABI,
56
57
  // Network controller provider type is uncompatible with ethers provider
57
- provider
58
+ new Web3Provider(provider)
58
59
  );
59
60
  const serializedTransaction = buildUnserializedTransaction(transactionMeta).serialize();
60
61
  const result = await contract.getL1Fee(serializedTransaction);
@@ -66,4 +67,4 @@ getOptimisimLayer1GasFee_fn = async function(request) {
66
67
  export {
67
68
  OptimismLayer1GasFeeFlow
68
69
  };
69
- //# sourceMappingURL=chunk-DX4NUE4H.mjs.map
70
+ //# sourceMappingURL=chunk-JRQKQEJG.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/gas-flows/OptimismLayer1GasFeeFlow.ts"],"sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider, type ExternalProvider } from '@ethersproject/providers';\nimport { createModuleLogger, type Hex } from '@metamask/utils';\n\nimport { CHAIN_IDS } from '../constants';\nimport { projectLogger } from '../logger';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { buildUnserializedTransaction } from '../utils/layer1-gas-fee-flow';\n\nconst OPTIMISIM_CHAIN_IDS: Hex[] = [\n CHAIN_IDS.OPTIMISM,\n CHAIN_IDS.OPTIMISM_TESTNET,\n];\n\nconst log = createModuleLogger(projectLogger, 'optimisim-layer1-gas-fee-flow');\n\n// Snippet of the ABI that we need\n// Should we need more of it at some point, the full ABI can be found here:\n// https://github.com/ethereum-optimism/optimism/blob/develop/gas-oracle/abis/OVM_GasPriceOracle.json\nconst OPTIMISM_GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [{ internalType: 'bytes', name: '_data', type: 'bytes' }],\n name: 'getL1Fee',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// BlockExplorer link: https://optimistic.etherscan.io/address/0x420000000000000000000000000000000000000f#code\nconst OPTIMISM_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F';\n\n/**\n * Optimism layer 1 gas fee flow that obtains gas fee estimate using Optimisim oracle contract.\n */\nexport class OptimismLayer1GasFeeFlow implements Layer1GasFeeFlow {\n matchesTransaction(transactionMeta: TransactionMeta): boolean {\n return OPTIMISIM_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n async #getOptimisimLayer1GasFee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n const { provider, transactionMeta } = request;\n\n const contract = new Contract(\n OPTIMISM_GAS_PRICE_ORACLE_ADDRESS,\n OPTIMISM_GAS_PRICE_ORACLE_ABI,\n // Network controller provider type is uncompatible with ethers provider\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n\n const serializedTransaction =\n buildUnserializedTransaction(transactionMeta).serialize();\n const result = await contract.getL1Fee(serializedTransaction);\n\n return {\n layer1Fee: result?.toHexString(),\n };\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n return await this.#getOptimisimLayer1GasFee(request);\n } catch (error) {\n log('Failed to get Optimism layer 1 gas fee due to error', error);\n throw new Error(`Failed to get Optimism layer 1 gas fee`);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAA2C;AACpD,SAAS,0BAAoC;AAY7C,IAAM,sBAA6B;AAAA,EACjC,UAAU;AAAA,EACV,UAAU;AACZ;AAEA,IAAM,MAAM,mBAAmB,eAAe,+BAA+B;AAK7E,IAAM,gCAAgC;AAAA,EACpC;AAAA,IACE,QAAQ,CAAC,EAAE,cAAc,SAAS,MAAM,SAAS,MAAM,QAAQ,CAAC;AAAA,IAChE,MAAM;AAAA,IACN,SAAS,CAAC,EAAE,cAAc,WAAW,MAAM,IAAI,MAAM,UAAU,CAAC;AAAA,IAChE,iBAAiB;AAAA,IACjB,MAAM;AAAA,EACR;AACF;AAGA,IAAM,oCACJ;AApCF;AAyCO,IAAM,2BAAN,MAA2D;AAAA,EAA3D;AAKL,uBAAM;AAAA;AAAA,EAJN,mBAAmB,iBAA2C;AAC5D,WAAO,oBAAoB,SAAS,gBAAgB,OAAO;AAAA,EAC7D;AAAA,EAuBA,MAAM,aACJ,SACmC;AACnC,QAAI;AACF,aAAO,MAAM,sBAAK,wDAAL,WAA+B;AAAA,IAC9C,SAAS,OAAO;AACd,UAAI,uDAAuD,KAAK;AAChE,YAAM,IAAI,MAAM,wCAAwC;AAAA,IAC1D;AAAA,EACF;AACF;AA/BQ;AAAA,8BAAyB,eAC7B,SACmC;AACnC,QAAM,EAAE,UAAU,gBAAgB,IAAI;AAEtC,QAAM,WAAW,IAAI;AAAA,IACnB;AAAA,IACA;AAAA;AAAA,IAEA,IAAI,aAAa,QAAuC;AAAA,EAC1D;AAEA,QAAM,wBACJ,6BAA6B,eAAe,EAAE,UAAU;AAC1D,QAAM,SAAS,MAAM,SAAS,SAAS,qBAAqB;AAE5D,SAAO;AAAA,IACL,WAAW,QAAQ,YAAY;AAAA,EACjC;AACF;","names":[]}
@@ -5,7 +5,7 @@ import {
5
5
  // src/utils/layer1-gas-fee-flow.ts
6
6
  import { Common, Hardfork } from "@ethereumjs/common";
7
7
  import { TransactionFactory } from "@ethereumjs/tx";
8
- import { createModuleLogger } from "@metamask/utils";
8
+ import { createModuleLogger, remove0x } from "@metamask/utils";
9
9
  import BN from "bn.js";
10
10
  import { omit } from "lodash";
11
11
  var log = createModuleLogger(projectLogger, "layer-1-gas-fee-flow");
@@ -53,7 +53,7 @@ function buildTransactionParams(transactionMeta) {
53
53
  }
54
54
  function buildTransactionCommon(transactionMeta) {
55
55
  return Common.custom({
56
- chainId: new BN(transactionMeta.chainId, 16),
56
+ chainId: new BN(remove0x(transactionMeta.chainId), 16),
57
57
  // Optimism only supports type-0 transactions; it does not support any of
58
58
  // the newer EIPs since EIP-155. Source:
59
59
  // <https://github.com/ethereum-optimism/optimism/blob/develop/specs/l2geth/transaction-types.md>
@@ -68,6 +68,7 @@ function buildUnserializedTransaction(transactionMeta) {
68
68
 
69
69
  export {
70
70
  updateTransactionLayer1GasFee,
71
+ getTransactionLayer1GasFee,
71
72
  buildUnserializedTransaction
72
73
  };
73
- //# sourceMappingURL=chunk-6FF5JJVB.mjs.map
74
+ //# sourceMappingURL=chunk-OXRUL7JF.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/layer1-gas-fee-flow.ts"],"sourcesContent":["import { Common, Hardfork } from '@ethereumjs/common';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { Provider } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\nimport { omit } from 'lodash';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n provider: Provider;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (layer1GasFee) {\n const { transactionMeta } = request;\n transactionMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction and return the layer1Fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.provider - The provider to use to get the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n provider,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n if (!layer1GasFeeFlow) {\n log('Layer 1 gas fee flow not found', transactionMeta.id);\n return undefined;\n }\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n\n/**\n * Build transactionParams to be used in the unserialized transaction.\n *\n * @param transactionMeta - The transaction to build transactionParams.\n * @returns The transactionParams for the unserialized transaction.\n */\nfunction buildTransactionParams(\n transactionMeta: TransactionMeta,\n): TransactionMeta['txParams'] {\n return {\n ...omit(transactionMeta.txParams, 'gas'),\n gasLimit: transactionMeta.txParams.gas,\n };\n}\n\n/**\n * This produces a transaction whose information does not completely match an\n * Optimism transaction — for instance, DEFAULT_CHAIN is still 'mainnet' and\n * genesis points to the mainnet genesis, not the Optimism genesis — but\n * considering that all we want to do is serialize a transaction, this works\n * fine for our use case.\n *\n * @param transactionMeta - The transaction to build an unserialized transaction for.\n * @returns The unserialized transaction.\n */\nfunction buildTransactionCommon(transactionMeta: TransactionMeta) {\n return Common.custom({\n chainId: new BN(remove0x(transactionMeta.chainId), 16) as unknown as number,\n // Optimism only supports type-0 transactions; it does not support any of\n // the newer EIPs since EIP-155. Source:\n // <https://github.com/ethereum-optimism/optimism/blob/develop/specs/l2geth/transaction-types.md>\n defaultHardfork: Hardfork.London,\n });\n}\n\n/**\n * Build an unserialized transaction for a transaction.\n *\n * @param transactionMeta - The transaction to build an unserialized transaction for.\n * @returns The unserialized transaction.\n */\nexport function buildUnserializedTransaction(transactionMeta: TransactionMeta) {\n const txParams = buildTransactionParams(transactionMeta);\n const common = buildTransactionCommon(transactionMeta);\n return TransactionFactory.fromTxData(txParams, { common });\n}\n"],"mappings":";;;;;AAAA,SAAS,QAAQ,gBAAgB;AACjC,SAAS,0BAA0B;AAEnC,SAAS,oBAA8B,gBAAgB;AACvD,OAAO,QAAQ;AACf,SAAS,YAAY;AAKrB,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAepE,eAAsB,8BACpB,SACA;AACA,QAAM,eAAe,MAAM,2BAA2B,OAAO;AAE7D,MAAI,cAAc;AAChB,UAAM,EAAE,gBAAgB,IAAI;AAC5B,oBAAgB,eAAe;AAAA,EACjC;AACF;AAQA,SAAS,oBACP,iBACA,mBAC8B;AAC9B,SAAO,kBAAkB;AAAA,IAAK,CAAC,qBAC7B,iBAAiB,mBAAmB,eAAe;AAAA,EACrD;AACF;AASA,eAAsB,2BAA2B;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AACF,GAAwD;AACtD,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AACA,MAAI,CAAC,kBAAkB;AACrB,QAAI,kCAAkC,gBAAgB,EAAE;AACxD,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,EAAE,UAAU,IAAI,MAAM,iBAAiB,aAAa;AAAA,MACxD;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iCAAiC,gBAAgB,IAAI,KAAK;AAC9D,WAAO;AAAA,EACT;AACF;AAQA,SAAS,uBACP,iBAC6B;AAC7B,SAAO;AAAA,IACL,GAAG,KAAK,gBAAgB,UAAU,KAAK;AAAA,IACvC,UAAU,gBAAgB,SAAS;AAAA,EACrC;AACF;AAYA,SAAS,uBAAuB,iBAAkC;AAChE,SAAO,OAAO,OAAO;AAAA,IACnB,SAAS,IAAI,GAAG,SAAS,gBAAgB,OAAO,GAAG,EAAE;AAAA;AAAA;AAAA;AAAA,IAIrD,iBAAiB,SAAS;AAAA,EAC5B,CAAC;AACH;AAQO,SAAS,6BAA6B,iBAAkC;AAC7E,QAAM,WAAW,uBAAuB,eAAe;AACvD,QAAM,SAAS,uBAAuB,eAAe;AACrD,SAAO,mBAAmB,WAAW,UAAU,EAAE,OAAO,CAAC;AAC3D;","names":[]}
@@ -53,7 +53,7 @@ function buildTransactionParams(transactionMeta) {
53
53
  }
54
54
  function buildTransactionCommon(transactionMeta) {
55
55
  return _common.Common.custom({
56
- chainId: new (0, _bnjs2.default)(transactionMeta.chainId, 16),
56
+ chainId: new (0, _bnjs2.default)(_utils.remove0x.call(void 0, transactionMeta.chainId), 16),
57
57
  // Optimism only supports type-0 transactions; it does not support any of
58
58
  // the newer EIPs since EIP-155. Source:
59
59
  // <https://github.com/ethereum-optimism/optimism/blob/develop/specs/l2geth/transaction-types.md>
@@ -69,5 +69,6 @@ function buildUnserializedTransaction(transactionMeta) {
69
69
 
70
70
 
71
71
 
72
- exports.updateTransactionLayer1GasFee = updateTransactionLayer1GasFee; exports.buildUnserializedTransaction = buildUnserializedTransaction;
73
- //# sourceMappingURL=chunk-CBKVKDFC.js.map
72
+
73
+ exports.updateTransactionLayer1GasFee = updateTransactionLayer1GasFee; exports.getTransactionLayer1GasFee = getTransactionLayer1GasFee; exports.buildUnserializedTransaction = buildUnserializedTransaction;
74
+ //# sourceMappingURL=chunk-S222HWGT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/layer1-gas-fee-flow.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,QAAQ,gBAAgB;AACjC,SAAS,0BAA0B;AAEnC,SAAS,oBAA8B,gBAAgB;AACvD,OAAO,QAAQ;AACf,SAAS,YAAY;AAKrB,IAAM,MAAM,mBAAmB,eAAe,sBAAsB;AAepE,eAAsB,8BACpB,SACA;AACA,QAAM,eAAe,MAAM,2BAA2B,OAAO;AAE7D,MAAI,cAAc;AAChB,UAAM,EAAE,gBAAgB,IAAI;AAC5B,oBAAgB,eAAe;AAAA,EACjC;AACF;AAQA,SAAS,oBACP,iBACA,mBAC8B;AAC9B,SAAO,kBAAkB;AAAA,IAAK,CAAC,qBAC7B,iBAAiB,mBAAmB,eAAe;AAAA,EACrD;AACF;AASA,eAAsB,2BAA2B;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AACF,GAAwD;AACtD,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AACA,MAAI,CAAC,kBAAkB;AACrB,QAAI,kCAAkC,gBAAgB,EAAE;AACxD,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,EAAE,UAAU,IAAI,MAAM,iBAAiB,aAAa;AAAA,MACxD;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iCAAiC,gBAAgB,IAAI,KAAK;AAC9D,WAAO;AAAA,EACT;AACF;AAQA,SAAS,uBACP,iBAC6B;AAC7B,SAAO;AAAA,IACL,GAAG,KAAK,gBAAgB,UAAU,KAAK;AAAA,IACvC,UAAU,gBAAgB,SAAS;AAAA,EACrC;AACF;AAYA,SAAS,uBAAuB,iBAAkC;AAChE,SAAO,OAAO,OAAO;AAAA,IACnB,SAAS,IAAI,GAAG,SAAS,gBAAgB,OAAO,GAAG,EAAE;AAAA;AAAA;AAAA;AAAA,IAIrD,iBAAiB,SAAS;AAAA,EAC5B,CAAC;AACH;AAQO,SAAS,6BAA6B,iBAAkC;AAC7E,QAAM,WAAW,uBAAuB,eAAe;AACvD,QAAM,SAAS,uBAAuB,eAAe;AACrD,SAAO,mBAAmB,WAAW,UAAU,EAAE,OAAO,CAAC;AAC3D","sourcesContent":["import { Common, Hardfork } from '@ethereumjs/common';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { Provider } from '@metamask/network-controller';\nimport { createModuleLogger, type Hex, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\nimport { omit } from 'lodash';\n\nimport { projectLogger } from '../logger';\nimport type { Layer1GasFeeFlow, TransactionMeta } from '../types';\n\nconst log = createModuleLogger(projectLogger, 'layer-1-gas-fee-flow');\n\nexport type UpdateLayer1GasFeeRequest = {\n layer1GasFeeFlows: Layer1GasFeeFlow[];\n provider: Provider;\n transactionMeta: TransactionMeta;\n};\n\n/**\n * Updates the given transactionMeta with the layer 1 gas fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.provider - Provider used to create a new underlying EthQuery instance\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n */\nexport async function updateTransactionLayer1GasFee(\n request: UpdateLayer1GasFeeRequest,\n) {\n const layer1GasFee = await getTransactionLayer1GasFee(request);\n\n if (layer1GasFee) {\n const { transactionMeta } = request;\n transactionMeta.layer1GasFee = layer1GasFee;\n }\n}\n\n/**\n * Get the layer 1 gas fee flow for a transaction.\n * @param transactionMeta - The transaction to get the layer 1 gas fee flow for.\n * @param layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @returns The layer 1 gas fee flow for the transaction, or undefined if none match.\n */\nfunction getLayer1GasFeeFlow(\n transactionMeta: TransactionMeta,\n layer1GasFeeFlows: Layer1GasFeeFlow[],\n): Layer1GasFeeFlow | undefined {\n return layer1GasFeeFlows.find((layer1GasFeeFlow) =>\n layer1GasFeeFlow.matchesTransaction(transactionMeta),\n );\n}\n\n/**\n * Get the layer 1 gas fee for a transaction and return the layer1Fee.\n * @param request - The request to use when getting the layer 1 gas fee.\n * @param request.layer1GasFeeFlows - The layer 1 gas fee flows to search.\n * @param request.provider - The provider to use to get the layer 1 gas fee.\n * @param request.transactionMeta - The transaction to get the layer 1 gas fee for.\n */\nexport async function getTransactionLayer1GasFee({\n layer1GasFeeFlows,\n provider,\n transactionMeta,\n}: UpdateLayer1GasFeeRequest): Promise<Hex | undefined> {\n const layer1GasFeeFlow = getLayer1GasFeeFlow(\n transactionMeta,\n layer1GasFeeFlows,\n );\n if (!layer1GasFeeFlow) {\n log('Layer 1 gas fee flow not found', transactionMeta.id);\n return undefined;\n }\n\n try {\n const { layer1Fee } = await layer1GasFeeFlow.getLayer1Fee({\n provider,\n transactionMeta,\n });\n return layer1Fee;\n } catch (error) {\n log('Failed to get layer 1 gas fee', transactionMeta.id, error);\n return undefined;\n }\n}\n\n/**\n * Build transactionParams to be used in the unserialized transaction.\n *\n * @param transactionMeta - The transaction to build transactionParams.\n * @returns The transactionParams for the unserialized transaction.\n */\nfunction buildTransactionParams(\n transactionMeta: TransactionMeta,\n): TransactionMeta['txParams'] {\n return {\n ...omit(transactionMeta.txParams, 'gas'),\n gasLimit: transactionMeta.txParams.gas,\n };\n}\n\n/**\n * This produces a transaction whose information does not completely match an\n * Optimism transaction — for instance, DEFAULT_CHAIN is still 'mainnet' and\n * genesis points to the mainnet genesis, not the Optimism genesis — but\n * considering that all we want to do is serialize a transaction, this works\n * fine for our use case.\n *\n * @param transactionMeta - The transaction to build an unserialized transaction for.\n * @returns The unserialized transaction.\n */\nfunction buildTransactionCommon(transactionMeta: TransactionMeta) {\n return Common.custom({\n chainId: new BN(remove0x(transactionMeta.chainId), 16) as unknown as number,\n // Optimism only supports type-0 transactions; it does not support any of\n // the newer EIPs since EIP-155. Source:\n // <https://github.com/ethereum-optimism/optimism/blob/develop/specs/l2geth/transaction-types.md>\n defaultHardfork: Hardfork.London,\n });\n}\n\n/**\n * Build an unserialized transaction for a transaction.\n *\n * @param transactionMeta - The transaction to build an unserialized transaction for.\n * @returns The unserialized transaction.\n */\nexport function buildUnserializedTransaction(transactionMeta: TransactionMeta) {\n const txParams = buildTransactionParams(transactionMeta);\n const common = buildTransactionCommon(transactionMeta);\n return TransactionFactory.fromTxData(txParams, { common });\n}\n"]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-6KYPLIXG.mjs";
4
4
  import {
5
5
  updateTransactionLayer1GasFee
6
- } from "./chunk-6FF5JJVB.mjs";
6
+ } from "./chunk-OXRUL7JF.mjs";
7
7
  import {
8
8
  projectLogger
9
9
  } from "./chunk-UQQWZT6C.mjs";
@@ -184,4 +184,4 @@ getUnapprovedTransactions_fn = function() {
184
184
  export {
185
185
  GasFeePoller
186
186
  };
187
- //# sourceMappingURL=chunk-WCJ7I43R.mjs.map
187
+ //# sourceMappingURL=chunk-WBE2B3XJ.mjs.map
@@ -23,7 +23,7 @@ import {
23
23
  } from "./chunk-QSBIXUMB.mjs";
24
24
  import {
25
25
  GasFeePoller
26
- } from "./chunk-WCJ7I43R.mjs";
26
+ } from "./chunk-WBE2B3XJ.mjs";
27
27
  import {
28
28
  IncomingTransactionHelper
29
29
  } from "./chunk-Y7ENNK7L.mjs";
@@ -66,10 +66,11 @@ import {
66
66
  } from "./chunk-J56A7UCK.mjs";
67
67
  import {
68
68
  OptimismLayer1GasFeeFlow
69
- } from "./chunk-DX4NUE4H.mjs";
69
+ } from "./chunk-JRQKQEJG.mjs";
70
70
  import {
71
+ getTransactionLayer1GasFee,
71
72
  updateTransactionLayer1GasFee
72
- } from "./chunk-6FF5JJVB.mjs";
73
+ } from "./chunk-OXRUL7JF.mjs";
73
74
  import {
74
75
  projectLogger
75
76
  } from "./chunk-UQQWZT6C.mjs";
@@ -1363,6 +1364,28 @@ var TransactionController = class extends BaseController {
1363
1364
  }
1364
1365
  return filteredTransactions;
1365
1366
  }
1367
+ /**
1368
+ * Utility method to get the layer 1 gas fee for given transaction params.
1369
+ *
1370
+ * @param chainId - Estimated transaction chainId.
1371
+ * @param networkClientId - Estimated transaction networkClientId.
1372
+ * @param transactionParams - The transaction params to estimate layer 1 gas fee for.
1373
+ */
1374
+ async getLayer1GasFee(chainId, networkClientId, transactionParams) {
1375
+ const provider = __privateGet(this, _multichainTrackingHelper).getProvider({
1376
+ networkClientId,
1377
+ chainId
1378
+ });
1379
+ const layer1GasFee = await getTransactionLayer1GasFee({
1380
+ layer1GasFeeFlows: this.layer1GasFeeFlows,
1381
+ provider,
1382
+ transactionMeta: {
1383
+ txParams: transactionParams,
1384
+ chainId
1385
+ }
1386
+ });
1387
+ return layer1GasFee;
1388
+ }
1366
1389
  async signExternalTransaction(chainId, transactionParams) {
1367
1390
  if (!this.sign) {
1368
1391
  throw new Error("No sign method defined.");
@@ -2344,4 +2367,4 @@ export {
2344
2367
  ApprovalState,
2345
2368
  TransactionController
2346
2369
  };
2347
- //# sourceMappingURL=chunk-SBZB2FLU.mjs.map
2370
+ //# sourceMappingURL=chunk-WIVEC2DS.mjs.map