@metamask/transaction-controller 65.4.0 → 66.0.1
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.
- package/CHANGELOG.md +30 -1
- package/dist/TransactionController.cjs +7 -5
- package/dist/TransactionController.cjs.map +1 -1
- package/dist/TransactionController.d.cts.map +1 -1
- package/dist/TransactionController.d.mts.map +1 -1
- package/dist/TransactionController.mjs +7 -5
- package/dist/TransactionController.mjs.map +1 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs +5 -0
- package/dist/gas-flows/MantleLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.cts +1 -0
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts +1 -0
- package/dist/gas-flows/MantleLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/MantleLayer1GasFeeFlow.mjs +5 -0
- package/dist/gas-flows/MantleLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs +15 -3
- package/dist/gas-flows/OracleLayer1GasFeeFlow.cjs.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts +10 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.cts.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts +10 -0
- package/dist/gas-flows/OracleLayer1GasFeeFlow.d.mts.map +1 -1
- package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs +15 -3
- package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
- package/dist/hooks/ExtraTransactionsPublishHook.cjs +1 -0
- package/dist/hooks/ExtraTransactionsPublishHook.cjs.map +1 -1
- package/dist/hooks/ExtraTransactionsPublishHook.d.cts.map +1 -1
- package/dist/hooks/ExtraTransactionsPublishHook.d.mts.map +1 -1
- package/dist/hooks/ExtraTransactionsPublishHook.mjs +1 -0
- package/dist/hooks/ExtraTransactionsPublishHook.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +8 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +8 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/batch.cjs +7 -3
- package/dist/utils/batch.cjs.map +1 -1
- package/dist/utils/batch.d.cts.map +1 -1
- package/dist/utils/batch.d.mts.map +1 -1
- package/dist/utils/batch.mjs +7 -3
- package/dist/utils/batch.mjs.map +1 -1
- package/dist/utils/gas-fee-tokens.cjs +13 -10
- package/dist/utils/gas-fee-tokens.cjs.map +1 -1
- package/dist/utils/gas-fee-tokens.d.cts.map +1 -1
- package/dist/utils/gas-fee-tokens.d.mts.map +1 -1
- package/dist/utils/gas-fee-tokens.mjs +13 -10
- package/dist/utils/gas-fee-tokens.mjs.map +1 -1
- package/dist/utils/gas-fees.cjs +2 -2
- package/dist/utils/gas-fees.cjs.map +1 -1
- package/dist/utils/gas-fees.d.cts.map +1 -1
- package/dist/utils/gas-fees.d.mts.map +1 -1
- package/dist/utils/gas-fees.mjs +3 -3
- package/dist/utils/gas-fees.mjs.map +1 -1
- package/dist/utils/validation.cjs +15 -14
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.cts +6 -2
- package/dist/utils/validation.d.cts.map +1 -1
- package/dist/utils/validation.d.mts +6 -2
- package/dist/utils/validation.d.mts.map +1 -1
- package/dist/utils/validation.mjs +16 -15
- package/dist/utils/validation.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -34,6 +34,11 @@ class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow_1.OracleLayer1GasFee
|
|
|
34
34
|
async matchesTransaction({ transactionMeta, }) {
|
|
35
35
|
return MANTLE_CHAIN_IDS.includes(transactionMeta.chainId);
|
|
36
36
|
}
|
|
37
|
+
getOperatorFeeGas(transactionMeta) {
|
|
38
|
+
return (transactionMeta.gasUsed ??
|
|
39
|
+
transactionMeta.txParams.gas ??
|
|
40
|
+
transactionMeta.txParams.gasLimit);
|
|
41
|
+
}
|
|
37
42
|
async transformOracleFee(oracleFee, request) {
|
|
38
43
|
const { provider, transactionMeta } = request;
|
|
39
44
|
const oracleAddress = this.getOracleAddressForChain(transactionMeta.chainId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MantleLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;AAAA,wDAAoD;AACpD,wDAAwD;AAKxD,gDAAyC;AAGzC,8CAAsC;AACtC,yEAAkE;AAElE,MAAM,gBAAgB,GAAU,CAAC,qBAAS,CAAC,MAAM,EAAE,qBAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,eAAe,GAAG;IACtB;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAa,sBAAuB,SAAQ,+CAAsB;IAChE,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAEkB,KAAK,CAAC,kBAAkB,CACzC,SAAa,EACb,OAAgC;QAEhC,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,aAAa,GAAG,IAAI,CAAC,wBAAwB,CACjD,eAAe,CAAC,OAAO,CACxB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAC3B,aAAa,EACb,eAAe,EACf,IAAI,wBAAY,CA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D,eAAe,CAAC,OAAO,CACxB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,oBAAQ,CAC3B,aAAa,EACb,eAAe,EACf,IAAI,wBAAY,CAAC,QAAuC,CAAC,CAC1D,CAAC;QAEF,MAAM,UAAU,GAAG,IAAA,YAAI,EAAC,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACrD,OAAO,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CACF;AAtCD,wDAsCC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { Layer1GasFeeFlowRequest, TransactionMeta } from '../types';\nimport { toBN } from '../utils/utils';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\n\nconst MANTLE_CHAIN_IDS: Hex[] = [CHAIN_IDS.MANTLE, CHAIN_IDS.MANTLE_SEPOLIA];\n\nconst TOKEN_RATIO_ABI = [\n {\n inputs: [],\n name: 'tokenRatio',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n/**\n * Mantle layer 1 gas fee flow.\n *\n * Mantle uses MNT as its native gas token, but the oracle's getL1Fee returns\n * values denominated in ETH. This subclass multiplies the L1 fee by the\n * tokenRatio (ETH/MNT exchange rate) from the oracle contract to convert\n * the fee to MNT.\n */\nexport class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return MANTLE_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n protected override getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return (\n transactionMeta.gasUsed ??\n transactionMeta.txParams.gas ??\n transactionMeta.txParams.gasLimit\n );\n }\n\n protected override async transformOracleFee(\n oracleFee: BN,\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const { provider, transactionMeta } = request;\n const oracleAddress = this.getOracleAddressForChain(\n transactionMeta.chainId,\n );\n\n const contract = new Contract(\n oracleAddress,\n TOKEN_RATIO_ABI,\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n\n const tokenRatio = toBN(await contract.tokenRatio());\n return oracleFee.mul(tokenRatio);\n }\n}\n"]}
|
|
@@ -15,6 +15,7 @@ export declare class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {
|
|
|
15
15
|
transactionMeta: TransactionMeta;
|
|
16
16
|
messenger: TransactionControllerMessenger;
|
|
17
17
|
}): Promise<boolean>;
|
|
18
|
+
protected getOperatorFeeGas(transactionMeta: TransactionMeta): string | undefined;
|
|
18
19
|
protected transformOracleFee(oracleFee: BN, request: Layer1GasFeeFlowRequest): Promise<BN>;
|
|
19
20
|
}
|
|
20
21
|
//# sourceMappingURL=MantleLayer1GasFeeFlow.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MantleLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc;AAG5B,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAiB;AAEzE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAoBlE;;;;;;;GAOG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAC1D,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MantleLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc;AAG5B,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAiB;AAEzE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAoBlE;;;;;;;GAOG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAC1D,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;cAID,iBAAiB,CAClC,eAAe,EAAE,eAAe,GAC/B,MAAM,GAAG,SAAS;cAQI,kBAAkB,CACzC,SAAS,EAAE,EAAE,EACb,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,EAAE,CAAC;CAef"}
|
|
@@ -15,6 +15,7 @@ export declare class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {
|
|
|
15
15
|
transactionMeta: TransactionMeta;
|
|
16
16
|
messenger: TransactionControllerMessenger;
|
|
17
17
|
}): Promise<boolean>;
|
|
18
|
+
protected getOperatorFeeGas(transactionMeta: TransactionMeta): string | undefined;
|
|
18
19
|
protected transformOracleFee(oracleFee: BN, request: Layer1GasFeeFlowRequest): Promise<BN>;
|
|
19
20
|
}
|
|
20
21
|
//# sourceMappingURL=MantleLayer1GasFeeFlow.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MantleLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc;AAG5B,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAiB;AAEzE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAoBlE;;;;;;;GAOG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAC1D,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MantleLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc;AAG5B,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,qBAAiB;AAEzE,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAoBlE;;;;;;;GAOG;AACH,qBAAa,sBAAuB,SAAQ,sBAAsB;IAC1D,kBAAkB,CAAC,EACvB,eAAe,GAChB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,SAAS,EAAE,8BAA8B,CAAC;KAC3C,GAAG,OAAO,CAAC,OAAO,CAAC;cAID,iBAAiB,CAClC,eAAe,EAAE,eAAe,GAC/B,MAAM,GAAG,SAAS;cAQI,kBAAkB,CACzC,SAAS,EAAE,EAAE,EACb,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,EAAE,CAAC;CAef"}
|
|
@@ -31,6 +31,11 @@ export class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {
|
|
|
31
31
|
async matchesTransaction({ transactionMeta, }) {
|
|
32
32
|
return MANTLE_CHAIN_IDS.includes(transactionMeta.chainId);
|
|
33
33
|
}
|
|
34
|
+
getOperatorFeeGas(transactionMeta) {
|
|
35
|
+
return (transactionMeta.gasUsed ??
|
|
36
|
+
transactionMeta.txParams.gas ??
|
|
37
|
+
transactionMeta.txParams.gasLimit);
|
|
38
|
+
}
|
|
34
39
|
async transformOracleFee(oracleFee, request) {
|
|
35
40
|
const { provider, transactionMeta } = request;
|
|
36
41
|
const oracleAddress = this.getOracleAddressForChain(transactionMeta.chainId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MantleLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AACpD,OAAO,EAAE,YAAY,EAAE,iCAAiC;AAKxD,OAAO,EAAE,SAAS,EAAE,yBAAqB;AAGzC,OAAO,EAAE,IAAI,EAAE,2BAAuB;AACtC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAElE,MAAM,gBAAgB,GAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,eAAe,GAAG;IACtB;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAChE,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAEkB,KAAK,CAAC,kBAAkB,CACzC,SAAa,EACb,OAAgC;QAEhC,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,aAAa,GAAG,IAAI,CAAC,wBAAwB,CACjD,eAAe,CAAC,OAAO,CACxB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAC3B,aAAa,EACb,eAAe,EACf,IAAI,YAAY,CAAC,QAAuC,CAAC,CAC1D,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACrD,OAAO,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { Layer1GasFeeFlowRequest, TransactionMeta } from '../types';\nimport { toBN } from '../utils/utils';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\n\nconst MANTLE_CHAIN_IDS: Hex[] = [CHAIN_IDS.MANTLE, CHAIN_IDS.MANTLE_SEPOLIA];\n\nconst TOKEN_RATIO_ABI = [\n {\n inputs: [],\n name: 'tokenRatio',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n/**\n * Mantle layer 1 gas fee flow.\n *\n * Mantle uses MNT as its native gas token, but the oracle's getL1Fee returns\n * values denominated in ETH. This subclass multiplies the L1 fee by the\n * tokenRatio (ETH/MNT exchange rate) from the oracle contract to convert\n * the fee to MNT.\n */\nexport class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return MANTLE_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n protected override async transformOracleFee(\n oracleFee: BN,\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const { provider, transactionMeta } = request;\n const oracleAddress = this.getOracleAddressForChain(\n transactionMeta.chainId,\n );\n\n const contract = new Contract(\n oracleAddress,\n TOKEN_RATIO_ABI,\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n\n const tokenRatio = toBN(await contract.tokenRatio());\n return oracleFee.mul(tokenRatio);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MantleLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/MantleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AACpD,OAAO,EAAE,YAAY,EAAE,iCAAiC;AAKxD,OAAO,EAAE,SAAS,EAAE,yBAAqB;AAGzC,OAAO,EAAE,IAAI,EAAE,2BAAuB;AACtC,OAAO,EAAE,sBAAsB,EAAE,qCAAiC;AAElE,MAAM,gBAAgB,GAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;AAE7E,MAAM,eAAe,GAAG;IACtB;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,sBAAuB,SAAQ,sBAAsB;IAChE,KAAK,CAAC,kBAAkB,CAAC,EACvB,eAAe,GAIhB;QACC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAEkB,iBAAiB,CAClC,eAAgC;QAEhC,OAAO,CACL,eAAe,CAAC,OAAO;YACvB,eAAe,CAAC,QAAQ,CAAC,GAAG;YAC5B,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAClC,CAAC;IACJ,CAAC;IAEkB,KAAK,CAAC,kBAAkB,CACzC,SAAa,EACb,OAAgC;QAEhC,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,aAAa,GAAG,IAAI,CAAC,wBAAwB,CACjD,eAAe,CAAC,OAAO,CACxB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAC3B,aAAa,EACb,eAAe,EACf,IAAI,YAAY,CAAC,QAAuC,CAAC,CAC1D,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;QACrD,OAAO,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CACF","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport type BN from 'bn.js';\n\nimport { CHAIN_IDS } from '../constants';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type { Layer1GasFeeFlowRequest, TransactionMeta } from '../types';\nimport { toBN } from '../utils/utils';\nimport { OracleLayer1GasFeeFlow } from './OracleLayer1GasFeeFlow';\n\nconst MANTLE_CHAIN_IDS: Hex[] = [CHAIN_IDS.MANTLE, CHAIN_IDS.MANTLE_SEPOLIA];\n\nconst TOKEN_RATIO_ABI = [\n {\n inputs: [],\n name: 'tokenRatio',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n/**\n * Mantle layer 1 gas fee flow.\n *\n * Mantle uses MNT as its native gas token, but the oracle's getL1Fee returns\n * values denominated in ETH. This subclass multiplies the L1 fee by the\n * tokenRatio (ETH/MNT exchange rate) from the oracle contract to convert\n * the fee to MNT.\n */\nexport class MantleLayer1GasFeeFlow extends OracleLayer1GasFeeFlow {\n async matchesTransaction({\n transactionMeta,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean> {\n return MANTLE_CHAIN_IDS.includes(transactionMeta.chainId);\n }\n\n protected override getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return (\n transactionMeta.gasUsed ??\n transactionMeta.txParams.gas ??\n transactionMeta.txParams.gasLimit\n );\n }\n\n protected override async transformOracleFee(\n oracleFee: BN,\n request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n const { provider, transactionMeta } = request;\n const oracleAddress = this.getOracleAddressForChain(\n transactionMeta.chainId,\n );\n\n const contract = new Contract(\n oracleAddress,\n TOKEN_RATIO_ABI,\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n\n const tokenRatio = toBN(await contract.tokenRatio());\n return oracleFee.mul(tokenRatio);\n }\n}\n"]}
|
|
@@ -123,6 +123,18 @@ class OracleLayer1GasFeeFlow {
|
|
|
123
123
|
throw new Error(`Failed to get oracle layer 1 gas fee`);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns the gas value to pass to the operator-fee oracle, or undefined
|
|
128
|
+
* to skip the operator-fee call entirely. Defaults to the simulated
|
|
129
|
+
* `gasUsed` on the transaction. Subclasses can override to supply a
|
|
130
|
+
* fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.
|
|
131
|
+
*
|
|
132
|
+
* @param transactionMeta - The transaction metadata.
|
|
133
|
+
* @returns The gas value, or undefined to skip the operator-fee call.
|
|
134
|
+
*/
|
|
135
|
+
getOperatorFeeGas(transactionMeta) {
|
|
136
|
+
return transactionMeta.gasUsed;
|
|
137
|
+
}
|
|
126
138
|
}
|
|
127
139
|
exports.OracleLayer1GasFeeFlow = OracleLayer1GasFeeFlow;
|
|
128
140
|
_OracleLayer1GasFeeFlow_instances = new WeakSet(), _OracleLayer1GasFeeFlow_getOracleLayer1GasFee = async function _OracleLayer1GasFeeFlow_getOracleLayer1GasFee(contract, transactionMeta) {
|
|
@@ -133,12 +145,12 @@ _OracleLayer1GasFeeFlow_instances = new WeakSet(), _OracleLayer1GasFeeFlow_getOr
|
|
|
133
145
|
}
|
|
134
146
|
return (0, utils_2.toBN)(result);
|
|
135
147
|
}, _OracleLayer1GasFeeFlow_getOperatorLayer1GasFee = async function _OracleLayer1GasFeeFlow_getOperatorLayer1GasFee(contract, transactionMeta) {
|
|
136
|
-
const
|
|
137
|
-
if (!
|
|
148
|
+
const gas = this.getOperatorFeeGas(transactionMeta);
|
|
149
|
+
if (!gas) {
|
|
138
150
|
return ZERO;
|
|
139
151
|
}
|
|
140
152
|
try {
|
|
141
|
-
const result = await contract.getOperatorFee(
|
|
153
|
+
const result = await contract.getOperatorFee(gas);
|
|
142
154
|
if (result === undefined) {
|
|
143
155
|
return ZERO;
|
|
144
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OracleLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wDAAoD;AACpD,wDAAwD;AAGxD,2CAA4D;AAC5D,kDAAuB;AAEvB,0CAA0C;AAQ1C,kDAAsD;AACtD,8CAA0D;AAE1D,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,4BAA4B,CAAC,CAAC;AAE5E,MAAM,IAAI,GAAG,IAAI,eAAE,CAAC,CAAC,CAAC,CAAC;AAEvB,MAAM,SAAS,GACb,kEAAkE,CAAC;AAErE,MAAM,oBAAoB,GAAG;IAC3B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,OAAO;gBACrB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;aACd;SACF;QACD,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD,8BA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d,CAAC;AACH,CAAC,uHAGC,eAAgC,EAChC,IAAa;IAEb,MAAM,QAAQ,GAAG,uBAAA,IAAI,yFAAwB,MAA5B,IAAI,EAAyB,eAAe,CAAC,CAAC;IAC/D,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;IAEpC,IAAI,uBAAuB,GAAG,IAAA,4BAAkB,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEpE,IAAI,IAAI,EAAE,CAAC;QACT,iDAAiD;QACjD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5C,uBAAuB,GAAG,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC,2GAGC,eAAgC;IAEhC,OAAO;QACL,GAAG,eAAe,CAAC,QAAQ;QAC3B,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG;KACvC,CAAC;AACJ,CAAC,iHAGC,QAA6C,EAC7C,OAAY;IAEZ,OAAO,IAAI,oBAAQ,CACjB,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,EACtC,oBAAoB;IACpB,wEAAwE;IACxE,IAAI,wBAAY,CAAC,QAAuC,CAAC,CAC1D,CAAC;AACJ,CAAC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { prepareTransaction } from '../utils/prepare';\nimport { padHexToEvenLength, toBN } from '../utils/utils';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst ZERO = new BN(0);\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [\n {\n internalType: 'bytes',\n name: '_data',\n type: 'bytes',\n },\n ],\n name: 'getL1Fee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n // only available post Isthmus\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_gasUsed',\n type: 'uint256',\n },\n ],\n name: 'getOperatorFee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// Default OP Stack gas price oracle address used across supported networks\nconst DEFAULT_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F' as Hex;\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n /**\n * Resolves the oracle address for the given chain. Subclasses can override\n * this method to provide chain-specific oracle addresses. By default, this\n * returns the standard OP Stack gas price oracle address.\n *\n * @param _chainId - The chain ID to resolve the oracle address for.\n * @returns The oracle address for the given chain.\n */\n protected getOracleAddressForChain(_chainId: Hex): Hex {\n return DEFAULT_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n /**\n * Whether to sign the transaction with a dummy key prior to calling the\n * oracle contract. Some oracle contracts require a signed payload even for\n * read-only methods.\n *\n * Subclasses can override to enable signing when needed. Defaults to false.\n *\n * @returns Whether the transaction should be signed prior to the oracle call.\n */\n protected shouldSignTransaction(): boolean {\n return false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean>;\n\n /**\n * Transforms the raw oracle L1 fee before it is combined with the operator\n * fee. Subclasses can override this to apply chain-specific conversions\n * (e.g. currency conversion via an on-chain exchange rate).\n *\n * Defaults to returning the fee unchanged.\n *\n * @param oracleFee - The raw L1 fee returned by the oracle contract.\n * @param _request - The original fee flow request (provider + transaction).\n * @returns The transformed fee.\n */\n protected async transformOracleFee(\n oracleFee: BN,\n _request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n return oracleFee;\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n const { provider, transactionMeta } = request;\n\n const contract = this.#getGasPriceOracleContract(\n provider,\n transactionMeta.chainId,\n );\n\n const oracleFee = await this.#getOracleLayer1GasFee(\n contract,\n transactionMeta,\n );\n const transformedFee = await this.transformOracleFee(oracleFee, request);\n const operatorFee = await this.#getOperatorLayer1GasFee(\n contract,\n transactionMeta,\n );\n\n return {\n layer1Fee: add0x(\n padHexToEvenLength(transformedFee.add(operatorFee).toString(16)),\n ),\n };\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(\n contract: Contract,\n transactionMeta: TransactionMeta,\n ): Promise<BN> {\n const serializedTransaction = this.#buildUnserializedTransaction(\n transactionMeta,\n this.shouldSignTransaction(),\n ).serialize();\n\n const result = await contract.getL1Fee(serializedTransaction);\n\n if (result === undefined) {\n throw new Error('No value returned from oracle contract');\n }\n\n return toBN(result);\n }\n\n async #getOperatorLayer1GasFee(\n contract: Contract,\n transactionMeta: TransactionMeta,\n ): Promise<BN> {\n const { gasUsed } = transactionMeta;\n\n if (!gasUsed) {\n return ZERO;\n }\n\n try {\n const result = await contract.getOperatorFee(gasUsed);\n\n if (result === undefined) {\n return ZERO;\n }\n\n return toBN(result);\n } catch (error) {\n log('Failed to get operator layer 1 gas fee', error);\n return ZERO;\n }\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ): ReturnType<typeof prepareTransaction> {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n // eslint-disable-next-line no-restricted-globals\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n const keyBytes = Uint8Array.from(keyBuffer);\n unserializedTransaction = unserializedTransaction.sign(keyBytes);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n\n #getGasPriceOracleContract(\n provider: Layer1GasFeeFlowRequest['provider'],\n chainId: Hex,\n ): Contract {\n return new Contract(\n this.getOracleAddressForChain(chainId),\n GAS_PRICE_ORACLE_ABI,\n // Network controller provider type is incompatible with ethers provider\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OracleLayer1GasFeeFlow.cjs","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wDAAoD;AACpD,wDAAwD;AAGxD,2CAA4D;AAC5D,kDAAuB;AAEvB,0CAA0C;AAQ1C,kDAAsD;AACtD,8CAA0D;AAE1D,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,4BAA4B,CAAC,CAAC;AAE5E,MAAM,IAAI,GAAG,IAAI,eAAE,CAAC,CAAC,CAAC,CAAC;AAEvB,MAAM,SAAS,GACb,kEAAkE,CAAC;AAErE,MAAM,oBAAoB,GAAG;IAC3B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,OAAO;gBACrB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;aACd;SACF;QACD,IAAI,EAAE,UAAU;QAChB,OAAO,E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import type { ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { prepareTransaction } from '../utils/prepare';\nimport { padHexToEvenLength, toBN } from '../utils/utils';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst ZERO = new BN(0);\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [\n {\n internalType: 'bytes',\n name: '_data',\n type: 'bytes',\n },\n ],\n name: 'getL1Fee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n // only available post Isthmus\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_gasUsed',\n type: 'uint256',\n },\n ],\n name: 'getOperatorFee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// Default OP Stack gas price oracle address used across supported networks\nconst DEFAULT_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F' as Hex;\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n /**\n * Resolves the oracle address for the given chain. Subclasses can override\n * this method to provide chain-specific oracle addresses. By default, this\n * returns the standard OP Stack gas price oracle address.\n *\n * @param _chainId - The chain ID to resolve the oracle address for.\n * @returns The oracle address for the given chain.\n */\n protected getOracleAddressForChain(_chainId: Hex): Hex {\n return DEFAULT_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n /**\n * Whether to sign the transaction with a dummy key prior to calling the\n * oracle contract. Some oracle contracts require a signed payload even for\n * read-only methods.\n *\n * Subclasses can override to enable signing when needed. Defaults to false.\n *\n * @returns Whether the transaction should be signed prior to the oracle call.\n */\n protected shouldSignTransaction(): boolean {\n return false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean>;\n\n /**\n * Transforms the raw oracle L1 fee before it is combined with the operator\n * fee. Subclasses can override this to apply chain-specific conversions\n * (e.g. currency conversion via an on-chain exchange rate).\n *\n * Defaults to returning the fee unchanged.\n *\n * @param oracleFee - The raw L1 fee returned by the oracle contract.\n * @param _request - The original fee flow request (provider + transaction).\n * @returns The transformed fee.\n */\n protected async transformOracleFee(\n oracleFee: BN,\n _request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n return oracleFee;\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n const { provider, transactionMeta } = request;\n\n const contract = this.#getGasPriceOracleContract(\n provider,\n transactionMeta.chainId,\n );\n\n const oracleFee = await this.#getOracleLayer1GasFee(\n contract,\n transactionMeta,\n );\n const transformedFee = await this.transformOracleFee(oracleFee, request);\n const operatorFee = await this.#getOperatorLayer1GasFee(\n contract,\n transactionMeta,\n );\n\n return {\n layer1Fee: add0x(\n padHexToEvenLength(transformedFee.add(operatorFee).toString(16)),\n ),\n };\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(\n contract: Contract,\n transactionMeta: TransactionMeta,\n ): Promise<BN> {\n const serializedTransaction = this.#buildUnserializedTransaction(\n transactionMeta,\n this.shouldSignTransaction(),\n ).serialize();\n\n const result = await contract.getL1Fee(serializedTransaction);\n\n if (result === undefined) {\n throw new Error('No value returned from oracle contract');\n }\n\n return toBN(result);\n }\n\n /**\n * Returns the gas value to pass to the operator-fee oracle, or undefined\n * to skip the operator-fee call entirely. Defaults to the simulated\n * `gasUsed` on the transaction. Subclasses can override to supply a\n * fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.\n *\n * @param transactionMeta - The transaction metadata.\n * @returns The gas value, or undefined to skip the operator-fee call.\n */\n protected getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return transactionMeta.gasUsed;\n }\n\n async #getOperatorLayer1GasFee(\n contract: Contract,\n transactionMeta: TransactionMeta,\n ): Promise<BN> {\n const gas = this.getOperatorFeeGas(transactionMeta);\n\n if (!gas) {\n return ZERO;\n }\n\n try {\n const result = await contract.getOperatorFee(gas);\n\n if (result === undefined) {\n return ZERO;\n }\n\n return toBN(result);\n } catch (error) {\n log('Failed to get operator layer 1 gas fee', error);\n return ZERO;\n }\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ): ReturnType<typeof prepareTransaction> {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n // eslint-disable-next-line no-restricted-globals\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n const keyBytes = Uint8Array.from(keyBuffer);\n unserializedTransaction = unserializedTransaction.sign(keyBytes);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n\n #getGasPriceOracleContract(\n provider: Layer1GasFeeFlowRequest['provider'],\n chainId: Hex,\n ): Contract {\n return new Contract(\n this.getOracleAddressForChain(chainId),\n GAS_PRICE_ORACLE_ABI,\n // Network controller provider type is incompatible with ethers provider\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n }\n}\n"]}
|
|
@@ -43,5 +43,15 @@ export declare abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow
|
|
|
43
43
|
*/
|
|
44
44
|
protected transformOracleFee(oracleFee: BN, _request: Layer1GasFeeFlowRequest): Promise<BN>;
|
|
45
45
|
getLayer1Fee(request: Layer1GasFeeFlowRequest): Promise<Layer1GasFeeFlowResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the gas value to pass to the operator-fee oracle, or undefined
|
|
48
|
+
* to skip the operator-fee call entirely. Defaults to the simulated
|
|
49
|
+
* `gasUsed` on the transaction. Subclasses can override to supply a
|
|
50
|
+
* fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.
|
|
51
|
+
*
|
|
52
|
+
* @param transactionMeta - The transaction metadata.
|
|
53
|
+
* @returns The gas value, or undefined to skip the operator-fee call.
|
|
54
|
+
*/
|
|
55
|
+
protected getOperatorFeeGas(transactionMeta: TransactionMeta): string | undefined;
|
|
46
56
|
}
|
|
47
57
|
//# sourceMappingURL=OracleLayer1GasFeeFlow.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OracleLayer1GasFeeFlow.d.cts","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAAE,cAAc;AAGvB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,EAChB,qBAAiB;AAyDlB;;GAEG;AACH,8BAAsB,sBAAuB,YAAW,gBAAgB;;IACtE;;;;;;;OAOG;IACH,SAAS,CAAC,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;IAItD;;;;;;;;OAQG;IACH,SAAS,CAAC,qBAAqB,IAAI,OAAO;IAI1C,QAAQ,CAAC,kBAAkB,CAAC,EAC1B,eAAe,EACf,SAAS,GACV,EAAE;QACD,e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B,MAAM,GAAG,SAAS;CAmEtB"}
|
|
@@ -43,5 +43,15 @@ export declare abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow
|
|
|
43
43
|
*/
|
|
44
44
|
protected transformOracleFee(oracleFee: BN, _request: Layer1GasFeeFlowRequest): Promise<BN>;
|
|
45
45
|
getLayer1Fee(request: Layer1GasFeeFlowRequest): Promise<Layer1GasFeeFlowResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the gas value to pass to the operator-fee oracle, or undefined
|
|
48
|
+
* to skip the operator-fee call entirely. Defaults to the simulated
|
|
49
|
+
* `gasUsed` on the transaction. Subclasses can override to supply a
|
|
50
|
+
* fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.
|
|
51
|
+
*
|
|
52
|
+
* @param transactionMeta - The transaction metadata.
|
|
53
|
+
* @returns The gas value, or undefined to skip the operator-fee call.
|
|
54
|
+
*/
|
|
55
|
+
protected getOperatorFeeGas(transactionMeta: TransactionMeta): string | undefined;
|
|
46
56
|
}
|
|
47
57
|
//# sourceMappingURL=OracleLayer1GasFeeFlow.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OracleLayer1GasFeeFlow.d.mts","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,EAAE,cAAc;AAGvB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,eAAe,EAChB,qBAAiB;AAyDlB;;GAEG;AACH,8BAAsB,sBAAuB,YAAW,gBAAgB;;IACtE;;;;;;;OAOG;IACH,SAAS,CAAC,wBAAwB,CAAC,QAAQ,EAAE,GAAG,GAAG,GAAG;IAItD;;;;;;;;OAQG;IACH,SAAS,CAAC,qBAAqB,IAAI,OAAO;IAI1C,QAAQ,C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OAQG;IACH,SAAS,CAAC,iBAAiB,CACzB,eAAe,EAAE,eAAe,GAC/B,MAAM,GAAG,SAAS;CAmEtB"}
|
|
@@ -124,6 +124,18 @@ export class OracleLayer1GasFeeFlow {
|
|
|
124
124
|
throw new Error(`Failed to get oracle layer 1 gas fee`);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns the gas value to pass to the operator-fee oracle, or undefined
|
|
129
|
+
* to skip the operator-fee call entirely. Defaults to the simulated
|
|
130
|
+
* `gasUsed` on the transaction. Subclasses can override to supply a
|
|
131
|
+
* fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.
|
|
132
|
+
*
|
|
133
|
+
* @param transactionMeta - The transaction metadata.
|
|
134
|
+
* @returns The gas value, or undefined to skip the operator-fee call.
|
|
135
|
+
*/
|
|
136
|
+
getOperatorFeeGas(transactionMeta) {
|
|
137
|
+
return transactionMeta.gasUsed;
|
|
138
|
+
}
|
|
127
139
|
}
|
|
128
140
|
_OracleLayer1GasFeeFlow_instances = new WeakSet(), _OracleLayer1GasFeeFlow_getOracleLayer1GasFee = async function _OracleLayer1GasFeeFlow_getOracleLayer1GasFee(contract, transactionMeta) {
|
|
129
141
|
const serializedTransaction = __classPrivateFieldGet(this, _OracleLayer1GasFeeFlow_instances, "m", _OracleLayer1GasFeeFlow_buildUnserializedTransaction).call(this, transactionMeta, this.shouldSignTransaction()).serialize();
|
|
@@ -133,12 +145,12 @@ _OracleLayer1GasFeeFlow_instances = new WeakSet(), _OracleLayer1GasFeeFlow_getOr
|
|
|
133
145
|
}
|
|
134
146
|
return toBN(result);
|
|
135
147
|
}, _OracleLayer1GasFeeFlow_getOperatorLayer1GasFee = async function _OracleLayer1GasFeeFlow_getOperatorLayer1GasFee(contract, transactionMeta) {
|
|
136
|
-
const
|
|
137
|
-
if (!
|
|
148
|
+
const gas = this.getOperatorFeeGas(transactionMeta);
|
|
149
|
+
if (!gas) {
|
|
138
150
|
return ZERO;
|
|
139
151
|
}
|
|
140
152
|
try {
|
|
141
|
-
const result = await contract.getOperatorFee(
|
|
153
|
+
const result = await contract.getOperatorFee(gas);
|
|
142
154
|
if (result === undefined) {
|
|
143
155
|
return ZERO;
|
|
144
156
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OracleLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AACpD,OAAO,EAAE,YAAY,EAAE,iCAAiC;AAGxD,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAC5D,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAQ1C,OAAO,EAAE,kBAAkB,EAAE,6BAAyB;AACtD,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,2BAAuB;AAE1D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,4BAA4B,CAAC,CAAC;AAE5E,MAAM,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAEvB,MAAM,SAAS,GACb,kEAAkE,CAAC;AAErE,MAAM,oBAAoB,GAAG;IAC3B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,OAAO;gBACrB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;aACd;SACF;QACD,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE;YACP;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,SAAS;aAChB;SACF;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;IACD,8BAA8B;IAC9B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,SAAS;gBACvB,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,SAAS;aAChB;SACF;QACD,IAAI,EAAE,g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AAe,CAAC;IAEpC,IAAI,uBAAuB,GAAG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEpE,IAAI,IAAI,EAAE,CAAC;QACT,iDAAiD;QACjD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5C,uBAAuB,GAAG,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC,2GAGC,eAAgC;IAEhC,OAAO;QACL,GAAG,eAAe,CAAC,QAAQ;QAC3B,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG;KACvC,CAAC;AACJ,CAAC,iHAGC,QAA6C,EAC7C,OAAY;IAEZ,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,EACtC,oBAAoB;IACpB,wEAAwE;IACxE,IAAI,YAAY,CAAC,QAAuC,CAAC,CAC1D,CAAC;AACJ,CAAC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { prepareTransaction } from '../utils/prepare';\nimport { padHexToEvenLength, toBN } from '../utils/utils';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst ZERO = new BN(0);\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [\n {\n internalType: 'bytes',\n name: '_data',\n type: 'bytes',\n },\n ],\n name: 'getL1Fee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n // only available post Isthmus\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_gasUsed',\n type: 'uint256',\n },\n ],\n name: 'getOperatorFee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// Default OP Stack gas price oracle address used across supported networks\nconst DEFAULT_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F' as Hex;\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n /**\n * Resolves the oracle address for the given chain. Subclasses can override\n * this method to provide chain-specific oracle addresses. By default, this\n * returns the standard OP Stack gas price oracle address.\n *\n * @param _chainId - The chain ID to resolve the oracle address for.\n * @returns The oracle address for the given chain.\n */\n protected getOracleAddressForChain(_chainId: Hex): Hex {\n return DEFAULT_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n /**\n * Whether to sign the transaction with a dummy key prior to calling the\n * oracle contract. Some oracle contracts require a signed payload even for\n * read-only methods.\n *\n * Subclasses can override to enable signing when needed. Defaults to false.\n *\n * @returns Whether the transaction should be signed prior to the oracle call.\n */\n protected shouldSignTransaction(): boolean {\n return false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean>;\n\n /**\n * Transforms the raw oracle L1 fee before it is combined with the operator\n * fee. Subclasses can override this to apply chain-specific conversions\n * (e.g. currency conversion via an on-chain exchange rate).\n *\n * Defaults to returning the fee unchanged.\n *\n * @param oracleFee - The raw L1 fee returned by the oracle contract.\n * @param _request - The original fee flow request (provider + transaction).\n * @returns The transformed fee.\n */\n protected async transformOracleFee(\n oracleFee: BN,\n _request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n return oracleFee;\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n const { provider, transactionMeta } = request;\n\n const contract = this.#getGasPriceOracleContract(\n provider,\n transactionMeta.chainId,\n );\n\n const oracleFee = await this.#getOracleLayer1GasFee(\n contract,\n transactionMeta,\n );\n const transformedFee = await this.transformOracleFee(oracleFee, request);\n const operatorFee = await this.#getOperatorLayer1GasFee(\n contract,\n transactionMeta,\n );\n\n return {\n layer1Fee: add0x(\n padHexToEvenLength(transformedFee.add(operatorFee).toString(16)),\n ),\n };\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(\n contract: Contract,\n transactionMeta: TransactionMeta,\n ): Promise<BN> {\n const serializedTransaction = this.#buildUnserializedTransaction(\n transactionMeta,\n this.shouldSignTransaction(),\n ).serialize();\n\n const result = await contract.getL1Fee(serializedTransaction);\n\n if (result === undefined) {\n throw new Error('No value returned from oracle contract');\n }\n\n return toBN(result);\n }\n\n async #getOperatorLayer1GasFee(\n contract: Contract,\n transactionMeta: TransactionMeta,\n ): Promise<BN> {\n const { gasUsed } = transactionMeta;\n\n if (!gasUsed) {\n return ZERO;\n }\n\n try {\n const result = await contract.getOperatorFee(gasUsed);\n\n if (result === undefined) {\n return ZERO;\n }\n\n return toBN(result);\n } catch (error) {\n log('Failed to get operator layer 1 gas fee', error);\n return ZERO;\n }\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ): ReturnType<typeof prepareTransaction> {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n // eslint-disable-next-line no-restricted-globals\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n const keyBytes = Uint8Array.from(keyBuffer);\n unserializedTransaction = unserializedTransaction.sign(keyBytes);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n\n #getGasPriceOracleContract(\n provider: Layer1GasFeeFlowRequest['provider'],\n chainId: Hex,\n ): Contract {\n return new Contract(\n this.getOracleAddressForChain(chainId),\n GAS_PRICE_ORACLE_ABI,\n // Network controller provider type is incompatible with ethers provider\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OracleLayer1GasFeeFlow.mjs","sourceRoot":"","sources":["../../src/gas-flows/OracleLayer1GasFeeFlow.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,iCAAiC;AACpD,OAAO,EAAE,YAAY,EAAE,iCAAiC;AAGxD,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,wBAAwB;AAC5D,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAQ1C,OAAO,EAAE,kBAAkB,EAAE,6BAAyB;AACtD,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,2BAAuB;AAE1D,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,4BAA4B,CAAC,CAAC;AAE5E,MAAM,IAAI,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAEvB,MAAM,SAAS,GACb,kEAAkE,CAAC;AAErE,MAAM,oBAAoB,GAAG;IAC3B;QACE,MAAM,EAAE;YACN;gBACE,YAAY,EAAE,OAAO;gBACrB,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;aACd;SACF;QACD,IAAI,EAAE,UAAU;QAChB,OAAO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AC,CAAC;QAElD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,uHAGC,eAAgC,EAChC,IAAa;IAEb,MAAM,QAAQ,GAAG,uBAAA,IAAI,yFAAwB,MAA5B,IAAI,EAAyB,eAAe,CAAC,CAAC;IAC/D,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;IAEpC,IAAI,uBAAuB,GAAG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEpE,IAAI,IAAI,EAAE,CAAC;QACT,iDAAiD;QACjD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5C,uBAAuB,GAAG,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,uBAAuB,CAAC;AACjC,CAAC,2GAGC,eAAgC;IAEhC,OAAO;QACL,GAAG,eAAe,CAAC,QAAQ;QAC3B,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG;KACvC,CAAC;AACJ,CAAC,iHAGC,QAA6C,EAC7C,OAAY;IAEZ,OAAO,IAAI,QAAQ,CACjB,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,EACtC,oBAAoB;IACpB,wEAAwE;IACxE,IAAI,YAAY,CAAC,QAAuC,CAAC,CAC1D,CAAC;AACJ,CAAC","sourcesContent":["import { Contract } from '@ethersproject/contracts';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { ExternalProvider } from '@ethersproject/providers';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, createModuleLogger } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { projectLogger } from '../logger';\nimport type { TransactionControllerMessenger } from '../TransactionController';\nimport type {\n Layer1GasFeeFlow,\n Layer1GasFeeFlowRequest,\n Layer1GasFeeFlowResponse,\n TransactionMeta,\n} from '../types';\nimport { prepareTransaction } from '../utils/prepare';\nimport { padHexToEvenLength, toBN } from '../utils/utils';\n\nconst log = createModuleLogger(projectLogger, 'oracle-layer1-gas-fee-flow');\n\nconst ZERO = new BN(0);\n\nconst DUMMY_KEY =\n 'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789';\n\nconst GAS_PRICE_ORACLE_ABI = [\n {\n inputs: [\n {\n internalType: 'bytes',\n name: '_data',\n type: 'bytes',\n },\n ],\n name: 'getL1Fee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n // only available post Isthmus\n {\n inputs: [\n {\n internalType: 'uint256',\n name: '_gasUsed',\n type: 'uint256',\n },\n ],\n name: 'getOperatorFee',\n outputs: [\n {\n internalType: 'uint256',\n name: '',\n type: 'uint256',\n },\n ],\n stateMutability: 'view',\n type: 'function',\n },\n];\n\n// Default OP Stack gas price oracle address used across supported networks\nconst DEFAULT_GAS_PRICE_ORACLE_ADDRESS =\n '0x420000000000000000000000000000000000000F' as Hex;\n\n/**\n * Layer 1 gas fee flow that obtains gas fee estimate using an oracle smart contract.\n */\nexport abstract class OracleLayer1GasFeeFlow implements Layer1GasFeeFlow {\n /**\n * Resolves the oracle address for the given chain. Subclasses can override\n * this method to provide chain-specific oracle addresses. By default, this\n * returns the standard OP Stack gas price oracle address.\n *\n * @param _chainId - The chain ID to resolve the oracle address for.\n * @returns The oracle address for the given chain.\n */\n protected getOracleAddressForChain(_chainId: Hex): Hex {\n return DEFAULT_GAS_PRICE_ORACLE_ADDRESS;\n }\n\n /**\n * Whether to sign the transaction with a dummy key prior to calling the\n * oracle contract. Some oracle contracts require a signed payload even for\n * read-only methods.\n *\n * Subclasses can override to enable signing when needed. Defaults to false.\n *\n * @returns Whether the transaction should be signed prior to the oracle call.\n */\n protected shouldSignTransaction(): boolean {\n return false;\n }\n\n abstract matchesTransaction({\n transactionMeta,\n messenger,\n }: {\n transactionMeta: TransactionMeta;\n messenger: TransactionControllerMessenger;\n }): Promise<boolean>;\n\n /**\n * Transforms the raw oracle L1 fee before it is combined with the operator\n * fee. Subclasses can override this to apply chain-specific conversions\n * (e.g. currency conversion via an on-chain exchange rate).\n *\n * Defaults to returning the fee unchanged.\n *\n * @param oracleFee - The raw L1 fee returned by the oracle contract.\n * @param _request - The original fee flow request (provider + transaction).\n * @returns The transformed fee.\n */\n protected async transformOracleFee(\n oracleFee: BN,\n _request: Layer1GasFeeFlowRequest,\n ): Promise<BN> {\n return oracleFee;\n }\n\n async getLayer1Fee(\n request: Layer1GasFeeFlowRequest,\n ): Promise<Layer1GasFeeFlowResponse> {\n try {\n const { provider, transactionMeta } = request;\n\n const contract = this.#getGasPriceOracleContract(\n provider,\n transactionMeta.chainId,\n );\n\n const oracleFee = await this.#getOracleLayer1GasFee(\n contract,\n transactionMeta,\n );\n const transformedFee = await this.transformOracleFee(oracleFee, request);\n const operatorFee = await this.#getOperatorLayer1GasFee(\n contract,\n transactionMeta,\n );\n\n return {\n layer1Fee: add0x(\n padHexToEvenLength(transformedFee.add(operatorFee).toString(16)),\n ),\n };\n } catch (error) {\n log('Failed to get oracle layer 1 gas fee', error);\n throw new Error(`Failed to get oracle layer 1 gas fee`);\n }\n }\n\n async #getOracleLayer1GasFee(\n contract: Contract,\n transactionMeta: TransactionMeta,\n ): Promise<BN> {\n const serializedTransaction = this.#buildUnserializedTransaction(\n transactionMeta,\n this.shouldSignTransaction(),\n ).serialize();\n\n const result = await contract.getL1Fee(serializedTransaction);\n\n if (result === undefined) {\n throw new Error('No value returned from oracle contract');\n }\n\n return toBN(result);\n }\n\n /**\n * Returns the gas value to pass to the operator-fee oracle, or undefined\n * to skip the operator-fee call entirely. Defaults to the simulated\n * `gasUsed` on the transaction. Subclasses can override to supply a\n * fallback (e.g. estimated gas limit) when `gasUsed` is unavailable.\n *\n * @param transactionMeta - The transaction metadata.\n * @returns The gas value, or undefined to skip the operator-fee call.\n */\n protected getOperatorFeeGas(\n transactionMeta: TransactionMeta,\n ): string | undefined {\n return transactionMeta.gasUsed;\n }\n\n async #getOperatorLayer1GasFee(\n contract: Contract,\n transactionMeta: TransactionMeta,\n ): Promise<BN> {\n const gas = this.getOperatorFeeGas(transactionMeta);\n\n if (!gas) {\n return ZERO;\n }\n\n try {\n const result = await contract.getOperatorFee(gas);\n\n if (result === undefined) {\n return ZERO;\n }\n\n return toBN(result);\n } catch (error) {\n log('Failed to get operator layer 1 gas fee', error);\n return ZERO;\n }\n }\n\n #buildUnserializedTransaction(\n transactionMeta: TransactionMeta,\n sign: boolean,\n ): ReturnType<typeof prepareTransaction> {\n const txParams = this.#buildTransactionParams(transactionMeta);\n const { chainId } = transactionMeta;\n\n let unserializedTransaction = prepareTransaction(chainId, txParams);\n\n if (sign) {\n // eslint-disable-next-line no-restricted-globals\n const keyBuffer = Buffer.from(DUMMY_KEY, 'hex');\n const keyBytes = Uint8Array.from(keyBuffer);\n unserializedTransaction = unserializedTransaction.sign(keyBytes);\n }\n\n return unserializedTransaction;\n }\n\n #buildTransactionParams(\n transactionMeta: TransactionMeta,\n ): TransactionMeta['txParams'] {\n return {\n ...transactionMeta.txParams,\n gasLimit: transactionMeta.txParams.gas,\n };\n }\n\n #getGasPriceOracleContract(\n provider: Layer1GasFeeFlowRequest['provider'],\n chainId: Hex,\n ): Contract {\n return new Contract(\n this.getOracleAddressForChain(chainId),\n GAS_PRICE_ORACLE_ABI,\n // Network controller provider type is incompatible with ethers provider\n new Web3Provider(provider as unknown as ExternalProvider),\n );\n }\n}\n"]}
|
|
@@ -115,6 +115,7 @@ _ExtraTransactionsPublishHook_addTransactionBatch = new WeakMap(), _ExtraTransac
|
|
|
115
115
|
};
|
|
116
116
|
await __classPrivateFieldGet(this, _ExtraTransactionsPublishHook_addTransactionBatch, "f").call(this, {
|
|
117
117
|
from,
|
|
118
|
+
isInternal: true,
|
|
118
119
|
networkClientId,
|
|
119
120
|
requireApproval: false,
|
|
120
121
|
transactions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtraTransactionsPublishHook.cjs","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4E;AAI5E,0CAA0C;AAS1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAC5B,sBAAa,EACb,iCAAiC,CAClC,CAAC;AAEF;;;GAGG;AACH,MAAa,4BAA4B;IAOvC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GAKpB;;QAdQ,oEAAmE;QAEnE,+DAA4D;QAE5D,oEAAkC;QAWzC,uBAAA,IAAI,qDAAwB,mBAAmB,MAAA,CAAC;QAChD,uBAAA,IAAI,gDAAmB,cAAc,MAAA,CAAC;QACtC,uBAAA,IAAI,qDAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,uBAAA,IAAI,mFAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"ExtraTransactionsPublishHook.cjs","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4E;AAI5E,0CAA0C;AAS1C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAC5B,sBAAa,EACb,iCAAiC,CAClC,CAAC;AAEF;;;GAGG;AACH,MAAa,4BAA4B;IAOvC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GAKpB;;QAdQ,oEAAmE;QAEnE,+DAA4D;QAE5D,oEAAkC;QAWzC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EAAE,EAAE,CAAC,CAAC;QAC9B,GAAG,IAAI;KACR,CAAC,CAAC,CAAC;IAEN,MAAM,YAAY,GAAoC;QACpD,GAAG,kBAAkB;QACrB,eAAe;QACf,GAAG,iBAAiB;KACrB,CAAC;IAEF,GAAG,CAAC,0BAA0B,EAAE;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,wBAAwB,IAAI;QAC1C,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,KAAK;QAClB,iBAAiB,EAAE,IAAI;KACxB,CAAC;IAEF,MAAM,uBAAA,IAAI,yDAAqB,MAAzB,IAAI,EAAsB;QAC9B,IAAI;QACJ,UAAU,EAAE,IAAI;QAChB,eAAe;QACf,eAAe,EAAE,KAAK;QACtB,YAAY;QACZ,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,OAAO,CAAC;AAC/B,CAAC","sourcesContent":["import { createDeferredPromise, createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { TransactionController } from '..';\nimport { projectLogger } from '../logger';\nimport type {\n BatchTransactionParams,\n PublishHook,\n PublishHookResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n} from '../types';\n\nconst log = createModuleLogger(\n projectLogger,\n 'extra-transactions-publish-hook',\n);\n\n/**\n * Custom publish logic that also publishes additional transactions in an batch.\n * Requires the batch to be successful to resolve.\n */\nexport class ExtraTransactionsPublishHook {\n readonly #addTransactionBatch: TransactionController['addTransactionBatch'];\n\n readonly #getTransaction: (transactionId: string) => TransactionMeta;\n\n readonly #originalPublishHook: PublishHook;\n\n constructor({\n addTransactionBatch,\n getTransaction,\n originalPublishHook,\n }: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n getTransaction: (transactionId: string) => TransactionMeta;\n originalPublishHook: PublishHook;\n }) {\n this.#addTransactionBatch = addTransactionBatch;\n this.#getTransaction = getTransaction;\n this.#originalPublishHook = originalPublishHook;\n }\n\n /**\n * @returns The publish hook function.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n async #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n log('Publishing transaction as batch', { transactionMeta, signedTx });\n\n const {\n batchTransactions,\n batchTransactionsOptions,\n id: transactionId,\n networkClientId,\n txParams,\n } = transactionMeta;\n\n const from = txParams.from as Hex;\n const to = txParams.to as Hex | undefined;\n const data = txParams.data as Hex | undefined;\n const value = txParams.value as Hex | undefined;\n const gas = txParams.gas as Hex | undefined;\n const maxFeePerGas = txParams.maxFeePerGas as Hex | undefined;\n\n const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas as\n | Hex\n | undefined;\n\n const signedTransaction = signedTx as Hex;\n const resultPromise = createDeferredPromise<PublishHookResult>();\n\n const onPublish = ({\n newSignature,\n transactionHash,\n }: {\n newSignature?: Hex;\n transactionHash?: string;\n }): void => {\n if (newSignature) {\n const latestTransactionMeta = this.#getTransaction(transactionId);\n\n log('Calling original publish hook with new signature', {\n latestTransactionMeta,\n newSignature,\n });\n\n this.#originalPublishHook(latestTransactionMeta, newSignature)\n .then(resultPromise.resolve)\n .catch(resultPromise.reject);\n\n return;\n }\n\n resultPromise.resolve({ transactionHash });\n };\n\n const firstParams: BatchTransactionParams = {\n data,\n gas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n const mainTransaction: TransactionBatchSingleRequest = {\n existingTransaction: {\n id: transactionId,\n onPublish,\n signedTransaction,\n },\n params: firstParams,\n };\n\n const extraTransactions = (batchTransactions ?? []).map((transaction) => {\n const { isAfter, type, ...rest } = transaction;\n return {\n isAfter,\n params: rest,\n type,\n };\n });\n\n const beforeTransactions: TransactionBatchSingleRequest[] =\n extraTransactions\n .filter((transaction) => transaction.isAfter === false)\n .map(({ isAfter, ...rest }) => ({\n ...rest,\n }));\n\n const afterTransactions: TransactionBatchSingleRequest[] = extraTransactions\n .filter(\n (transaction) =>\n transaction.isAfter === undefined || transaction.isAfter,\n )\n .map(({ isAfter, ...rest }) => ({\n ...rest,\n }));\n\n const transactions: TransactionBatchSingleRequest[] = [\n ...beforeTransactions,\n mainTransaction,\n ...afterTransactions,\n ];\n\n log('Adding transaction batch', {\n from,\n networkClientId,\n transactions,\n });\n\n const options = batchTransactionsOptions ?? {\n disable7702: true,\n disableHook: false,\n disableSequential: true,\n };\n\n await this.#addTransactionBatch({\n from,\n isInternal: true,\n networkClientId,\n requireApproval: false,\n transactions,\n ...options,\n });\n\n return resultPromise.promise;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtraTransactionsPublishHook.d.cts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EAEV,WAAW,EAGX,eAAe,EAChB,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAO3B,EACV,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GACpB,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,cAAc,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,eAAe,CAAC;QAC3D,mBAAmB,EAAE,WAAW,CAAC;KAClC;IAMD;;OAEG;IACH,OAAO,IAAI,WAAW;
|
|
1
|
+
{"version":3,"file":"ExtraTransactionsPublishHook.d.cts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EAEV,WAAW,EAGX,eAAe,EAChB,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAO3B,EACV,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GACpB,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,cAAc,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,eAAe,CAAC;QAC3D,mBAAmB,EAAE,WAAW,CAAC;KAClC;IAMD;;OAEG;IACH,OAAO,IAAI,WAAW;CAiIvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtraTransactionsPublishHook.d.mts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EAEV,WAAW,EAGX,eAAe,EAChB,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAO3B,EACV,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GACpB,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,cAAc,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,eAAe,CAAC;QAC3D,mBAAmB,EAAE,WAAW,CAAC;KAClC;IAMD;;OAEG;IACH,OAAO,IAAI,WAAW;
|
|
1
|
+
{"version":3,"file":"ExtraTransactionsPublishHook.d.mts","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAW;AAEhD,OAAO,KAAK,EAEV,WAAW,EAGX,eAAe,EAChB,qBAAiB;AAOlB;;;GAGG;AACH,qBAAa,4BAA4B;;gBAO3B,EACV,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GACpB,EAAE;QACD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;QAClE,cAAc,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,eAAe,CAAC;QAC3D,mBAAmB,EAAE,WAAW,CAAC;KAClC;IAMD;;OAEG;IACH,OAAO,IAAI,WAAW;CAiIvB"}
|
|
@@ -111,6 +111,7 @@ _ExtraTransactionsPublishHook_addTransactionBatch = new WeakMap(), _ExtraTransac
|
|
|
111
111
|
};
|
|
112
112
|
await __classPrivateFieldGet(this, _ExtraTransactionsPublishHook_addTransactionBatch, "f").call(this, {
|
|
113
113
|
from,
|
|
114
|
+
isInternal: true,
|
|
114
115
|
networkClientId,
|
|
115
116
|
requireApproval: false,
|
|
116
117
|
transactions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtraTransactionsPublishHook.mjs","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAwB;AAI5E,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAS1C,MAAM,GAAG,GAAG,kBAAkB,CAC5B,aAAa,EACb,iCAAiC,CAClC,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,4BAA4B;IAOvC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,mBAAmB,GAKpB;;QAdQ,oEAAmE;QAEnE,+DAA4D;QAE5D,oEAAkC;QAWzC,uBAAA,IAAI,qDAAwB,mBAAmB,MAAA,CAAC;QAChD,uBAAA,IAAI,gDAAmB,cAAc,MAAA,CAAC;QACtC,uBAAA,IAAI,qDAAwB,mBAAmB,MAAA,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,OAAO;QACL,OAAO,uBAAA,IAAI,mFAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"ExtraTransactionsPublishHook.mjs","sourceRoot":"","sources":["../../src/hooks/ExtraTransactionsPublishHook.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,wBAAwB;AAI5E,OAAO,EAAE,aAAa,EAAE,sBAAkB;AAS1C,MAAM,GAAG,GAAG,kBAAkB,CAC5B,aAAa,EACb,iCAAiC,CAClC,CAAC;AAEF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,CACd,WAAW,CAAC,OAAO,KAAK,SAAS,IAAI,WAAW,CAAC,OAAO,CAC3D;SACA,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9B,GAAG,IAAI;KACR,CAAC,CAAC,CAAC;IAEN,MAAM,YAAY,GAAoC;QACpD,GAAG,kBAAkB;QACrB,eAAe;QACf,GAAG,iBAAiB;KACrB,CAAC;IAEF,GAAG,CAAC,0BAA0B,EAAE;QAC9B,IAAI;QACJ,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,wBAAwB,IAAI;QAC1C,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,KAAK;QAClB,iBAAiB,EAAE,IAAI;KACxB,CAAC;IAEF,MAAM,uBAAA,IAAI,yDAAqB,MAAzB,IAAI,EAAsB;QAC9B,IAAI;QACJ,UAAU,EAAE,IAAI;QAChB,eAAe;QACf,eAAe,EAAE,KAAK;QACtB,YAAY;QACZ,GAAG,OAAO;KACX,CAAC,CAAC;IAEH,OAAO,aAAa,CAAC,OAAO,CAAC;AAC/B,CAAC","sourcesContent":["import { createDeferredPromise, createModuleLogger } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { TransactionController } from '..';\nimport { projectLogger } from '../logger';\nimport type {\n BatchTransactionParams,\n PublishHook,\n PublishHookResult,\n TransactionBatchSingleRequest,\n TransactionMeta,\n} from '../types';\n\nconst log = createModuleLogger(\n projectLogger,\n 'extra-transactions-publish-hook',\n);\n\n/**\n * Custom publish logic that also publishes additional transactions in an batch.\n * Requires the batch to be successful to resolve.\n */\nexport class ExtraTransactionsPublishHook {\n readonly #addTransactionBatch: TransactionController['addTransactionBatch'];\n\n readonly #getTransaction: (transactionId: string) => TransactionMeta;\n\n readonly #originalPublishHook: PublishHook;\n\n constructor({\n addTransactionBatch,\n getTransaction,\n originalPublishHook,\n }: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n getTransaction: (transactionId: string) => TransactionMeta;\n originalPublishHook: PublishHook;\n }) {\n this.#addTransactionBatch = addTransactionBatch;\n this.#getTransaction = getTransaction;\n this.#originalPublishHook = originalPublishHook;\n }\n\n /**\n * @returns The publish hook function.\n */\n getHook(): PublishHook {\n return this.#hook.bind(this);\n }\n\n async #hook(\n transactionMeta: TransactionMeta,\n signedTx: string,\n ): Promise<PublishHookResult> {\n log('Publishing transaction as batch', { transactionMeta, signedTx });\n\n const {\n batchTransactions,\n batchTransactionsOptions,\n id: transactionId,\n networkClientId,\n txParams,\n } = transactionMeta;\n\n const from = txParams.from as Hex;\n const to = txParams.to as Hex | undefined;\n const data = txParams.data as Hex | undefined;\n const value = txParams.value as Hex | undefined;\n const gas = txParams.gas as Hex | undefined;\n const maxFeePerGas = txParams.maxFeePerGas as Hex | undefined;\n\n const maxPriorityFeePerGas = txParams.maxPriorityFeePerGas as\n | Hex\n | undefined;\n\n const signedTransaction = signedTx as Hex;\n const resultPromise = createDeferredPromise<PublishHookResult>();\n\n const onPublish = ({\n newSignature,\n transactionHash,\n }: {\n newSignature?: Hex;\n transactionHash?: string;\n }): void => {\n if (newSignature) {\n const latestTransactionMeta = this.#getTransaction(transactionId);\n\n log('Calling original publish hook with new signature', {\n latestTransactionMeta,\n newSignature,\n });\n\n this.#originalPublishHook(latestTransactionMeta, newSignature)\n .then(resultPromise.resolve)\n .catch(resultPromise.reject);\n\n return;\n }\n\n resultPromise.resolve({ transactionHash });\n };\n\n const firstParams: BatchTransactionParams = {\n data,\n gas,\n maxFeePerGas,\n maxPriorityFeePerGas,\n to,\n value,\n };\n\n const mainTransaction: TransactionBatchSingleRequest = {\n existingTransaction: {\n id: transactionId,\n onPublish,\n signedTransaction,\n },\n params: firstParams,\n };\n\n const extraTransactions = (batchTransactions ?? []).map((transaction) => {\n const { isAfter, type, ...rest } = transaction;\n return {\n isAfter,\n params: rest,\n type,\n };\n });\n\n const beforeTransactions: TransactionBatchSingleRequest[] =\n extraTransactions\n .filter((transaction) => transaction.isAfter === false)\n .map(({ isAfter, ...rest }) => ({\n ...rest,\n }));\n\n const afterTransactions: TransactionBatchSingleRequest[] = extraTransactions\n .filter(\n (transaction) =>\n transaction.isAfter === undefined || transaction.isAfter,\n )\n .map(({ isAfter, ...rest }) => ({\n ...rest,\n }));\n\n const transactions: TransactionBatchSingleRequest[] = [\n ...beforeTransactions,\n mainTransaction,\n ...afterTransactions,\n ];\n\n log('Adding transaction batch', {\n from,\n networkClientId,\n transactions,\n });\n\n const options = batchTransactionsOptions ?? {\n disable7702: true,\n disableHook: false,\n disableSequential: true,\n };\n\n await this.#addTransactionBatch({\n from,\n isInternal: true,\n networkClientId,\n requireApproval: false,\n transactions,\n ...options,\n });\n\n return resultPromise.promise;\n }\n}\n"]}
|