@metamask/transaction-controller 24.0.0 → 25.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -1
- package/dist/TransactionController.js +39 -1816
- package/dist/TransactionController.js.map +1 -1
- package/dist/TransactionController.mjs +40 -0
- package/dist/TransactionController.mjs.map +1 -0
- package/dist/chunk-2YXA3K67.mjs +62 -0
- package/dist/chunk-2YXA3K67.mjs.map +1 -0
- package/dist/chunk-3D3SA6PY.mjs +211 -0
- package/dist/chunk-3D3SA6PY.mjs.map +1 -0
- package/dist/chunk-4S25HUCL.js +46 -0
- package/dist/chunk-4S25HUCL.js.map +1 -0
- package/dist/chunk-5OQ373JS.js +211 -0
- package/dist/chunk-5OQ373JS.js.map +1 -0
- package/dist/chunk-5XBULBP2.js +399 -0
- package/dist/chunk-5XBULBP2.js.map +1 -0
- package/dist/chunk-72OTU5ZW.mjs +2332 -0
- package/dist/chunk-72OTU5ZW.mjs.map +1 -0
- package/dist/chunk-7LXE4KHV.js +40 -0
- package/dist/chunk-7LXE4KHV.js.map +1 -0
- package/dist/chunk-7XPI7KU5.mjs +46 -0
- package/dist/chunk-7XPI7KU5.mjs.map +1 -0
- package/dist/chunk-BILEZLAT.js +182 -0
- package/dist/chunk-BILEZLAT.js.map +1 -0
- package/dist/chunk-CQBXHAYR.js +121 -0
- package/dist/chunk-CQBXHAYR.js.map +1 -0
- package/dist/chunk-CXXGL43K.js +85 -0
- package/dist/chunk-CXXGL43K.js.map +1 -0
- package/dist/chunk-DTDTOMTB.js +238 -0
- package/dist/chunk-DTDTOMTB.js.map +1 -0
- package/dist/chunk-DTONMSFW.mjs +208 -0
- package/dist/chunk-DTONMSFW.mjs.map +1 -0
- package/dist/chunk-EEMJC7S7.mjs +182 -0
- package/dist/chunk-EEMJC7S7.mjs.map +1 -0
- package/dist/chunk-F3CMU2DM.js +170 -0
- package/dist/chunk-F3CMU2DM.js.map +1 -0
- package/dist/chunk-FRKQ3Z2L.mjs +40 -0
- package/dist/chunk-FRKQ3Z2L.mjs.map +1 -0
- package/dist/chunk-HS277C77.js +75 -0
- package/dist/chunk-HS277C77.js.map +1 -0
- package/dist/chunk-ITDY6AIZ.js +127 -0
- package/dist/chunk-ITDY6AIZ.js.map +1 -0
- package/dist/chunk-IZI7FQIN.mjs +170 -0
- package/dist/chunk-IZI7FQIN.mjs.map +1 -0
- package/dist/chunk-J56A7UCK.mjs +123 -0
- package/dist/chunk-J56A7UCK.mjs.map +1 -0
- package/dist/chunk-JRBREX22.mjs +75 -0
- package/dist/chunk-JRBREX22.mjs.map +1 -0
- package/dist/chunk-JRQHIBG5.mjs +399 -0
- package/dist/chunk-JRQHIBG5.mjs.map +1 -0
- package/dist/chunk-K26EBMGI.mjs +121 -0
- package/dist/chunk-K26EBMGI.mjs.map +1 -0
- package/dist/chunk-KFL2GGZC.mjs +48 -0
- package/dist/chunk-KFL2GGZC.mjs.map +1 -0
- package/dist/chunk-NHRBO3LU.mjs +50 -0
- package/dist/chunk-NHRBO3LU.mjs.map +1 -0
- package/dist/chunk-NM4LTWRU.mjs +76 -0
- package/dist/chunk-NM4LTWRU.mjs.map +1 -0
- package/dist/chunk-NM6OYEPP.mjs +182 -0
- package/dist/chunk-NM6OYEPP.mjs.map +1 -0
- package/dist/chunk-NRWEI43Q.js +320 -0
- package/dist/chunk-NRWEI43Q.js.map +1 -0
- package/dist/chunk-O7H2MC7R.js +62 -0
- package/dist/chunk-O7H2MC7R.js.map +1 -0
- package/dist/chunk-OF6NSLXF.mjs +90 -0
- package/dist/chunk-OF6NSLXF.mjs.map +1 -0
- package/dist/chunk-QDIYZX5V.js +2332 -0
- package/dist/chunk-QDIYZX5V.js.map +1 -0
- package/dist/chunk-QP75SWIQ.js +53 -0
- package/dist/chunk-QP75SWIQ.js.map +1 -0
- package/dist/chunk-QPNEFZB3.js +208 -0
- package/dist/chunk-QPNEFZB3.js.map +1 -0
- package/dist/chunk-QSBIXUMB.mjs +242 -0
- package/dist/chunk-QSBIXUMB.mjs.map +1 -0
- package/dist/chunk-R7NJVDWN.js +48 -0
- package/dist/chunk-R7NJVDWN.js.map +1 -0
- package/dist/chunk-RQKICZYP.js +137 -0
- package/dist/chunk-RQKICZYP.js.map +1 -0
- package/dist/chunk-S6VGOPUY.js +14 -0
- package/dist/chunk-S6VGOPUY.js.map +1 -0
- package/dist/chunk-TXVH44HM.js +90 -0
- package/dist/chunk-TXVH44HM.js.map +1 -0
- package/dist/chunk-UGFBA4GV.js +123 -0
- package/dist/chunk-UGFBA4GV.js.map +1 -0
- package/dist/chunk-UQQWZT6C.mjs +14 -0
- package/dist/chunk-UQQWZT6C.mjs.map +1 -0
- package/dist/chunk-VEREDMI2.mjs +85 -0
- package/dist/chunk-VEREDMI2.mjs.map +1 -0
- package/dist/chunk-VH47Q6TS.js +182 -0
- package/dist/chunk-VH47Q6TS.js.map +1 -0
- package/dist/chunk-W3GAOR7Y.js +76 -0
- package/dist/chunk-W3GAOR7Y.js.map +1 -0
- package/dist/chunk-WXQZIUNW.js +242 -0
- package/dist/chunk-WXQZIUNW.js.map +1 -0
- package/dist/chunk-XGRAHX6T.mjs +53 -0
- package/dist/chunk-XGRAHX6T.mjs.map +1 -0
- package/dist/chunk-XKNFL657.mjs +137 -0
- package/dist/chunk-XKNFL657.mjs.map +1 -0
- package/dist/chunk-XUI43LEZ.mjs +30 -0
- package/dist/chunk-XUI43LEZ.mjs.map +1 -0
- package/dist/chunk-Y7ENNK7L.mjs +238 -0
- package/dist/chunk-Y7ENNK7L.mjs.map +1 -0
- package/dist/chunk-Z3HHSD5I.mjs +127 -0
- package/dist/chunk-Z3HHSD5I.mjs.map +1 -0
- package/dist/chunk-Z4BLTVTB.js +30 -0
- package/dist/chunk-Z4BLTVTB.js.map +1 -0
- package/dist/chunk-ZNZEJDOE.js +50 -0
- package/dist/chunk-ZNZEJDOE.js.map +1 -0
- package/dist/chunk-ZQFMTLZJ.mjs +320 -0
- package/dist/chunk-ZQFMTLZJ.mjs.map +1 -0
- package/dist/constants.js +15 -110
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +16 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/gas-flows/DefaultGasFeeFlow.js +14 -77
- package/dist/gas-flows/DefaultGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/DefaultGasFeeFlow.mjs +15 -0
- package/dist/gas-flows/DefaultGasFeeFlow.mjs.map +1 -0
- package/dist/gas-flows/LineaGasFeeFlow.js +15 -110
- package/dist/gas-flows/LineaGasFeeFlow.js.map +1 -1
- package/dist/gas-flows/LineaGasFeeFlow.mjs +16 -0
- package/dist/gas-flows/LineaGasFeeFlow.mjs.map +1 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.js +11 -145
- package/dist/helpers/EtherscanRemoteTransactionSource.js.map +1 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs +12 -0
- package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -0
- package/dist/helpers/GasFeePoller.js +11 -143
- package/dist/helpers/GasFeePoller.js.map +1 -1
- package/dist/helpers/GasFeePoller.mjs +12 -0
- package/dist/helpers/GasFeePoller.mjs.map +1 -0
- package/dist/helpers/IncomingTransactionHelper.js +8 -205
- package/dist/helpers/IncomingTransactionHelper.js.map +1 -1
- package/dist/helpers/IncomingTransactionHelper.mjs +9 -0
- package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -0
- package/dist/helpers/MultichainTrackingHelper.js +12 -291
- package/dist/helpers/MultichainTrackingHelper.js.map +1 -1
- package/dist/helpers/MultichainTrackingHelper.mjs +13 -0
- package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -0
- package/dist/helpers/PendingTransactionTracker.js +9 -360
- package/dist/helpers/PendingTransactionTracker.js.map +1 -1
- package/dist/helpers/PendingTransactionTracker.mjs +10 -0
- package/dist/helpers/PendingTransactionTracker.mjs.map +1 -0
- package/dist/index.js +57 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.js +11 -8
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +12 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/{TransactionController.d.ts → types/TransactionController.d.ts} +236 -46
- package/dist/types/TransactionController.d.ts.map +1 -0
- package/dist/{constants.d.ts → types/constants.d.ts} +10 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/gas-flows/DefaultGasFeeFlow.d.ts.map +1 -0
- package/dist/types/gas-flows/LineaGasFeeFlow.d.ts.map +1 -0
- package/dist/types/helpers/EtherscanRemoteTransactionSource.d.ts.map +1 -0
- package/dist/{helpers → types/helpers}/GasFeePoller.d.ts +5 -3
- package/dist/types/helpers/GasFeePoller.d.ts.map +1 -0
- package/dist/types/helpers/IncomingTransactionHelper.d.ts.map +1 -0
- package/dist/types/helpers/MultichainTrackingHelper.d.ts.map +1 -0
- package/dist/types/helpers/PendingTransactionTracker.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/{types.d.ts → types/types.d.ts} +94 -65
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils/etherscan.d.ts.map +1 -0
- package/dist/types/utils/external-transactions.d.ts.map +1 -0
- package/dist/types/utils/gas-fees.d.ts.map +1 -0
- package/dist/types/utils/gas-flow.d.ts.map +1 -0
- package/dist/types/utils/gas.d.ts.map +1 -0
- package/dist/types/utils/history.d.ts +20 -0
- package/dist/types/utils/history.d.ts.map +1 -0
- package/dist/types/utils/layer1-gas-fee-flow.d.ts +16 -0
- package/dist/types/utils/layer1-gas-fee-flow.d.ts.map +1 -0
- package/dist/types/utils/nonce.d.ts.map +1 -0
- package/dist/types/utils/simulation-api.d.ts +99 -0
- package/dist/types/utils/simulation-api.d.ts.map +1 -0
- package/dist/types/utils/simulation.d.ts +21 -0
- package/dist/types/utils/simulation.d.ts.map +1 -0
- package/dist/{utils → types/utils}/swaps.d.ts +8 -5
- package/dist/types/utils/swaps.d.ts.map +1 -0
- package/dist/types/utils/transaction-type.d.ts.map +1 -0
- package/dist/types/utils/utils.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/dist/types.js +19 -170
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +20 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils/etherscan.js +13 -118
- package/dist/utils/etherscan.js.map +1 -1
- package/dist/utils/etherscan.mjs +14 -0
- package/dist/utils/etherscan.mjs.map +1 -0
- package/dist/utils/external-transactions.js +8 -35
- package/dist/utils/external-transactions.js.map +1 -1
- package/dist/utils/external-transactions.mjs +9 -0
- package/dist/utils/external-transactions.mjs.map +1 -0
- package/dist/utils/gas-fees.js +15 -200
- package/dist/utils/gas-fees.js.map +1 -1
- package/dist/utils/gas-fees.mjs +16 -0
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas-flow.js +10 -52
- package/dist/utils/gas-flow.js.map +1 -1
- package/dist/utils/gas-flow.mjs +11 -0
- package/dist/utils/gas-flow.mjs.map +1 -0
- package/dist/utils/gas.js +19 -133
- package/dist/utils/gas.js.map +1 -1
- package/dist/utils/gas.mjs +20 -0
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/history.js +9 -83
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/history.mjs +10 -0
- package/dist/utils/history.mjs.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.js +9 -0
- package/dist/utils/layer1-gas-fee-flow.js.map +1 -0
- package/dist/utils/layer1-gas-fee-flow.mjs +9 -0
- package/dist/utils/layer1-gas-fee-flow.mjs.map +1 -0
- package/dist/utils/nonce.js +10 -76
- package/dist/utils/nonce.js.map +1 -1
- package/dist/utils/nonce.mjs +11 -0
- package/dist/utils/nonce.mjs.map +1 -0
- package/dist/utils/simulation-api.js +10 -0
- package/dist/utils/simulation-api.js.map +1 -0
- package/dist/utils/simulation-api.mjs +10 -0
- package/dist/utils/simulation-api.mjs.map +1 -0
- package/dist/utils/simulation.js +12 -0
- package/dist/utils/simulation.js.map +1 -0
- package/dist/utils/simulation.mjs +12 -0
- package/dist/utils/simulation.mjs.map +1 -0
- package/dist/utils/swaps.js +23 -256
- package/dist/utils/swaps.js.map +1 -1
- package/dist/utils/swaps.mjs +24 -0
- package/dist/utils/swaps.mjs.map +1 -0
- package/dist/utils/transaction-type.js +10 -120
- package/dist/utils/transaction-type.js.map +1 -1
- package/dist/utils/transaction-type.mjs +11 -0
- package/dist/utils/transaction-type.mjs.map +1 -0
- package/dist/utils/utils.js +32 -160
- package/dist/utils/utils.js.map +1 -1
- package/dist/utils/utils.mjs +33 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/dist/utils/validation.js +11 -258
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/validation.mjs +12 -0
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +22 -10
- package/dist/TransactionController.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/gas-flows/DefaultGasFeeFlow.d.ts.map +0 -1
- package/dist/gas-flows/LineaGasFeeFlow.d.ts.map +0 -1
- package/dist/helpers/EtherscanRemoteTransactionSource.d.ts.map +0 -1
- package/dist/helpers/GasFeePoller.d.ts.map +0 -1
- package/dist/helpers/IncomingTransactionHelper.d.ts.map +0 -1
- package/dist/helpers/MultichainTrackingHelper.d.ts.map +0 -1
- package/dist/helpers/PendingTransactionTracker.d.ts.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/etherscan.d.ts.map +0 -1
- package/dist/utils/external-transactions.d.ts.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-flow.d.ts.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/history.d.ts +0 -15
- package/dist/utils/history.d.ts.map +0 -1
- package/dist/utils/nonce.d.ts.map +0 -1
- package/dist/utils/swaps.d.ts.map +0 -1
- package/dist/utils/transaction-type.d.ts.map +0 -1
- package/dist/utils/utils.d.ts.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- /package/dist/{gas-flows → types/gas-flows}/DefaultGasFeeFlow.d.ts +0 -0
- /package/dist/{gas-flows → types/gas-flows}/LineaGasFeeFlow.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/EtherscanRemoteTransactionSource.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/IncomingTransactionHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/MultichainTrackingHelper.d.ts +0 -0
- /package/dist/{helpers → types/helpers}/PendingTransactionTracker.d.ts +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{utils → types/utils}/etherscan.d.ts +0 -0
- /package/dist/{utils → types/utils}/external-transactions.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-fees.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas-flow.d.ts +0 -0
- /package/dist/{utils → types/utils}/gas.d.ts +0 -0
- /package/dist/{utils → types/utils}/nonce.d.ts +0 -0
- /package/dist/{utils → types/utils}/transaction-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/utils.d.ts +0 -0
- /package/dist/{utils → types/utils}/validation.d.ts +0 -0
package/dist/utils/swaps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swaps.js","sourceRoot":"","sources":["../../src/utils/swaps.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAmD;AAEnD,mCAAuC;AAEvC,4CAAyC;AACzC,sCAA8D;AAE9D,oCAA2C;AAC3C,mCAA0D;AAE1D,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,OAAO,CAAC,CAAC;AAEvD;;GAEG;AACU,QAAA,8BAA8B,GAAG,IAAI,CAAC;AAEnD;;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CAChC,CAAC;IAEF,gCAAgC;IAChC,8DAA8D;IAC9D,IAAI,uBAAuB,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAS,CAAC;IACjE,uBAAuB,GAAG,IAAA,eAAM,EAAC;QAC/B,IAAI;QACJ,iBAAiB;KAClB,CAA6B,CAAC;IAC/B,IAAA,cAAK,EAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,0BAA0B,CAAC,OAAe,EAAE,OAAe;;IAClE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CACL,OAAO;SACP,MAAA,uCAA+B,CAC7B,OAAuD,CACxD,0CAAE,OAAO,CAAA,CACX,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { query } from '@metamask/controller-utils';\nimport type EthQuery from '@metamask/eth-query';\nimport { merge, pickBy } from 'lodash';\n\nimport { CHAIN_IDS } from '../constants';\nimport { createModuleLogger, projectLogger } from '../logger';\nimport type { Events, TransactionMeta } from '../types';\nimport { TransactionType } from '../types';\nimport { validateIfTransactionUnapproved } from './utils';\n\nconst log = createModuleLogger(projectLogger, 'swaps');\n\n/**\n * Interval in milliseconds between checks of post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_TIMEOUT = 5000;\n\n/**\n * Retry attempts for checking post transaction balance\n */\nexport const UPDATE_POST_TX_BALANCE_ATTEMPTS = 6;\n\nconst SWAPS_TESTNET_CHAIN_ID = '0x539';\n\n/**\n * An address that the metaswap-api recognizes as the default token for the current network, in place of the token address that ERC-20 tokens have\n */\nexport const DEFAULT_TOKEN_ADDRESS =\n '0x0000000000000000000000000000000000000000';\n\n// Convert to a `type` in a future major version.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\ninterface SwapsTokenObject {\n /**\n * The name for the network\n */\n name: string;\n /**\n * An address that the metaswap-api recognizes as the default token\n */\n address: string;\n /**\n * Number of digits after decimal point\n */\n decimals: number;\n}\n\nconst ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n};\n\nconst BNB_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Binance Coin',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst MATIC_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Matic',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst AVAX_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Avalanche',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst TEST_ETH_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Test Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst GOERLI_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n name: 'Ether',\n address: DEFAULT_TOKEN_ADDRESS,\n decimals: 18,\n} as const;\n\nconst ARBITRUM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst OPTIMISM_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nconst ZKSYNC_ERA_SWAPS_TOKEN_OBJECT: SwapsTokenObject = {\n ...ETH_SWAPS_TOKEN_OBJECT,\n} as const;\n\nexport const SWAPS_CHAINID_DEFAULT_TOKEN_MAP = {\n [CHAIN_IDS.MAINNET]: ETH_SWAPS_TOKEN_OBJECT,\n [SWAPS_TESTNET_CHAIN_ID]: TEST_ETH_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.BSC]: BNB_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.POLYGON]: MATIC_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.GOERLI]: GOERLI_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.AVALANCHE]: AVAX_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.OPTIMISM]: OPTIMISM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ARBITRUM]: ARBITRUM_SWAPS_TOKEN_OBJECT,\n [CHAIN_IDS.ZKSYNC_ERA]: ZKSYNC_ERA_SWAPS_TOKEN_OBJECT,\n} as const;\n\nexport const SWAP_TRANSACTION_TYPES = [\n TransactionType.swap,\n TransactionType.swapApproval,\n];\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - The transaction meta object to update\n * @param transactionType - The type of the transaction\n * @param swaps - The swaps object\n * @param swaps.hasApproveTx - Whether the swap has an approval transaction\n * @param swaps.meta - The swap meta object\n * @param updateSwapsTransactionRequest - Dependency bag\n * @param updateSwapsTransactionRequest.isSwapsDisabled - Whether swaps are disabled\n * @param updateSwapsTransactionRequest.cancelTransaction - Function to cancel a transaction\n * @param updateSwapsTransactionRequest.controllerHubEmitter - Function to emit an event to the controller hub\n */\nexport async function updateSwapsTransaction(\n transactionMeta: TransactionMeta,\n transactionType: TransactionType,\n swaps: {\n hasApproveTx?: boolean;\n meta?: Partial<TransactionMeta>;\n },\n {\n isSwapsDisabled,\n cancelTransaction,\n controllerHubEmitter,\n }: {\n isSwapsDisabled: boolean;\n cancelTransaction: (transactionId: string) => void;\n controllerHubEmitter: <T extends keyof Events>(\n eventName: T,\n ...args: Events[T]\n ) => boolean;\n },\n) {\n if (isSwapsDisabled || !SWAP_TRANSACTION_TYPES.includes(transactionType)) {\n return;\n }\n // The simulationFails property is added if the estimateGas call fails. In cases\n // when no swaps approval tx is required, this indicates that the swap will likely\n // fail. There was an earlier estimateGas call made by the swaps controller,\n // but it is possible that external conditions have change since then, and\n // a previously succeeding estimate gas call could now fail. By checking for\n // the `simulationFails` property here, we can reduce the number of swap\n // transactions that get published to the blockchain only to fail and thereby\n // waste the user's funds on gas.\n if (\n transactionType === TransactionType.swap &&\n swaps?.hasApproveTx === false &&\n transactionMeta.simulationFails\n ) {\n await cancelTransaction(transactionMeta.id);\n throw new Error('Simulation failed');\n }\n\n const swapsMeta = swaps?.meta as Partial<TransactionMeta>;\n\n if (!swapsMeta) {\n return;\n }\n\n if (transactionType === TransactionType.swapApproval) {\n updateSwapApprovalTransaction(transactionMeta, swapsMeta);\n controllerHubEmitter('transaction-new-swap-approval', {\n transactionMeta,\n });\n }\n\n if (transactionType === TransactionType.swap) {\n updateSwapTransaction(transactionMeta, swapsMeta);\n controllerHubEmitter('transaction-new-swap', {\n transactionMeta,\n });\n }\n}\n\n/**\n * Attempts to update the post transaction balance of the provided transaction\n *\n * @param transactionMeta - Transaction meta object to update\n * @param updatePostTransactionBalanceRequest - Dependency bag\n * @param updatePostTransactionBalanceRequest.ethQuery - EthQuery object\n * @param updatePostTransactionBalanceRequest.getTransaction - Reading function for the latest transaction state\n * @param updatePostTransactionBalanceRequest.updateTransaction - Updating transaction function\n */\nexport async function updatePostTransactionBalance(\n transactionMeta: TransactionMeta,\n {\n ethQuery,\n getTransaction,\n updateTransaction,\n }: {\n ethQuery: EthQuery;\n getTransaction: (transactionId: string) => TransactionMeta | undefined;\n updateTransaction: (transactionMeta: TransactionMeta, note: string) => void;\n },\n): Promise<{\n updatedTransactionMeta: TransactionMeta;\n approvalTransactionMeta?: TransactionMeta;\n}> {\n log('Updating post transaction balance', transactionMeta.id);\n\n const transactionId = transactionMeta.id;\n let latestTransactionMeta, approvalTransactionMeta;\n\n for (let i = 0; i < UPDATE_POST_TX_BALANCE_ATTEMPTS; i++) {\n log('Querying balance', { attempt: i });\n\n const postTransactionBalance = await query(ethQuery, 'getBalance', [\n transactionMeta.txParams.from,\n ]);\n\n latestTransactionMeta = getTransaction(transactionId) as TransactionMeta;\n\n approvalTransactionMeta = latestTransactionMeta.approvalTxId\n ? getTransaction(latestTransactionMeta.approvalTxId)\n : undefined;\n\n latestTransactionMeta.postTxBalance = postTransactionBalance.toString(16);\n\n const isDefaultTokenAddress = isSwapsDefaultTokenAddress(\n transactionMeta.destinationTokenAddress as string,\n transactionMeta.chainId,\n );\n\n if (\n !isDefaultTokenAddress ||\n transactionMeta.preTxBalance !== latestTransactionMeta.postTxBalance\n ) {\n log('Finishing post balance update', {\n isDefaultTokenAddress,\n preTxBalance: transactionMeta.preTxBalance,\n postTxBalance: latestTransactionMeta.postTxBalance,\n });\n\n break;\n }\n\n log('Waiting for balance to update', {\n delay: UPDATE_POST_TX_BALANCE_TIMEOUT,\n });\n\n await sleep(UPDATE_POST_TX_BALANCE_TIMEOUT);\n }\n\n updateTransaction(\n latestTransactionMeta as TransactionMeta,\n 'TransactionController#updatePostTransactionBalance - Add post transaction balance',\n );\n\n log('Completed post balance update', latestTransactionMeta?.postTxBalance);\n\n return {\n updatedTransactionMeta: latestTransactionMeta as TransactionMeta,\n approvalTransactionMeta,\n };\n}\n\n/**\n * Updates the transaction meta object with the swap information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n * @param propsToUpdate.destinationTokenSymbol - Symbol of the token to be received\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.destinationTokenDecimals - Decimals of the token to be received\n * @param propsToUpdate.destinationTokenAddress - Address of the token to be received\n * @param propsToUpdate.swapMetaData - Metadata of the swap\n * @param propsToUpdate.swapTokenValue - Value of the token to be swapped\n * @param propsToUpdate.estimatedBaseFee - Estimated base fee of the transaction\n * @param propsToUpdate.approvalTxId - Transaction id of the approval transaction\n */\nfunction updateSwapTransaction(\n transactionMeta: TransactionMeta,\n {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n }: Partial<TransactionMeta>,\n) {\n validateIfTransactionUnapproved(transactionMeta, 'updateSwapTransaction');\n\n let swapTransaction = {\n sourceTokenSymbol,\n destinationTokenSymbol,\n type,\n destinationTokenDecimals,\n destinationTokenAddress,\n swapMetaData,\n swapTokenValue,\n estimatedBaseFee,\n approvalTxId,\n };\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n swapTransaction = pickBy(swapTransaction) as any;\n merge(transactionMeta, swapTransaction);\n}\n\n/**\n * Updates the transaction meta object with the swap approval information\n *\n * @param transactionMeta - Transaction meta object to update\n * @param propsToUpdate - Properties to update\n * @param propsToUpdate.type - Type of the transaction\n * @param propsToUpdate.sourceTokenSymbol - Symbol of the token to be swapped\n */\nfunction updateSwapApprovalTransaction(\n transactionMeta: TransactionMeta,\n { type, sourceTokenSymbol }: Partial<TransactionMeta>,\n) {\n validateIfTransactionUnapproved(\n transactionMeta,\n 'updateSwapApprovalTransaction',\n );\n\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let swapApprovalTransaction = { type, sourceTokenSymbol } as any;\n swapApprovalTransaction = pickBy({\n type,\n sourceTokenSymbol,\n }) as Partial<TransactionMeta>;\n merge(transactionMeta, swapApprovalTransaction);\n}\n\n/**\n * Checks whether the provided address is strictly equal to the address for\n * the default swaps token of the provided chain.\n *\n * @param address - The string to compare to the default token address\n * @param chainId - The hex encoded chain ID of the default swaps token to check\n * @returns Whether the address is the provided chain's default token address\n */\nfunction isSwapsDefaultTokenAddress(address: string, chainId: string) {\n if (!address || !chainId) {\n return false;\n }\n\n return (\n address ===\n SWAPS_CHAINID_DEFAULT_TOKEN_MAP[\n chainId as keyof typeof SWAPS_CHAINID_DEFAULT_TOKEN_MAP\n ]?.address\n );\n}\n\n/**\n * Sleeps for the provided number of milliseconds\n *\n * @param ms - Number of milliseconds to sleep\n * @returns Promise that resolves after the provided number of milliseconds\n */\nfunction sleep(ms: number) {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_TOKEN_ADDRESS,
|
|
3
|
+
SWAPS_CHAINID_DEFAULT_TOKEN_MAP,
|
|
4
|
+
SWAP_TRANSACTION_TYPES,
|
|
5
|
+
UPDATE_POST_TX_BALANCE_ATTEMPTS,
|
|
6
|
+
UPDATE_POST_TX_BALANCE_TIMEOUT,
|
|
7
|
+
updatePostTransactionBalance,
|
|
8
|
+
updateSwapsTransaction
|
|
9
|
+
} from "../chunk-3D3SA6PY.mjs";
|
|
10
|
+
import "../chunk-J56A7UCK.mjs";
|
|
11
|
+
import "../chunk-Z3HHSD5I.mjs";
|
|
12
|
+
import "../chunk-UQQWZT6C.mjs";
|
|
13
|
+
import "../chunk-NM4LTWRU.mjs";
|
|
14
|
+
import "../chunk-XUI43LEZ.mjs";
|
|
15
|
+
export {
|
|
16
|
+
DEFAULT_TOKEN_ADDRESS,
|
|
17
|
+
SWAPS_CHAINID_DEFAULT_TOKEN_MAP,
|
|
18
|
+
SWAP_TRANSACTION_TYPES,
|
|
19
|
+
UPDATE_POST_TX_BALANCE_ATTEMPTS,
|
|
20
|
+
UPDATE_POST_TX_BALANCE_TIMEOUT,
|
|
21
|
+
updatePostTransactionBalance,
|
|
22
|
+
updateSwapsTransaction
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=swaps.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,121 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.determineTransactionType = exports.ESTIMATE_GAS_ERROR = void 0;
|
|
13
|
-
const abi_1 = require("@ethersproject/abi");
|
|
14
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
15
|
-
const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
|
|
16
|
-
const types_1 = require("../types");
|
|
17
|
-
exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
|
|
18
|
-
const ERC20Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC20);
|
|
19
|
-
const ERC721Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC721);
|
|
20
|
-
const ERC1155Interface = new abi_1.Interface(metamask_eth_abis_1.abiERC1155);
|
|
21
|
-
/**
|
|
22
|
-
* Determines the type of the transaction by analyzing the txParams.
|
|
23
|
-
* It will never return TRANSACTION_TYPE_CANCEL or TRANSACTION_TYPE_RETRY as these
|
|
24
|
-
* represent specific events that we specify manually at transaction creation.
|
|
25
|
-
*
|
|
26
|
-
* @param txParams - Parameters for the transaction.
|
|
27
|
-
* @param ethQuery - EthQuery instance.
|
|
28
|
-
* @returns A object with the transaction type and the contract code response in Hex.
|
|
29
|
-
*/
|
|
30
|
-
function determineTransactionType(txParams, ethQuery) {
|
|
31
|
-
var _a, _b;
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const { data, to } = txParams;
|
|
34
|
-
if (data && !to) {
|
|
35
|
-
return { type: types_1.TransactionType.deployContract, getCodeResponse: undefined };
|
|
36
|
-
}
|
|
37
|
-
const { contractCode: getCodeResponse, isContractAddress } = yield readAddressAsContract(ethQuery, to);
|
|
38
|
-
if (!isContractAddress) {
|
|
39
|
-
return { type: types_1.TransactionType.simpleSend, getCodeResponse };
|
|
40
|
-
}
|
|
41
|
-
const hasValue = Number((_a = txParams.value) !== null && _a !== void 0 ? _a : '0') !== 0;
|
|
42
|
-
const contractInteractionResult = {
|
|
43
|
-
type: types_1.TransactionType.contractInteraction,
|
|
44
|
-
getCodeResponse,
|
|
45
|
-
};
|
|
46
|
-
if (!data || hasValue) {
|
|
47
|
-
return contractInteractionResult;
|
|
48
|
-
}
|
|
49
|
-
const name = (_b = parseStandardTokenTransactionData(data)) === null || _b === void 0 ? void 0 : _b.name;
|
|
50
|
-
if (!name) {
|
|
51
|
-
return contractInteractionResult;
|
|
52
|
-
}
|
|
53
|
-
const tokenMethodName = [
|
|
54
|
-
types_1.TransactionType.tokenMethodApprove,
|
|
55
|
-
types_1.TransactionType.tokenMethodSetApprovalForAll,
|
|
56
|
-
types_1.TransactionType.tokenMethodTransfer,
|
|
57
|
-
types_1.TransactionType.tokenMethodTransferFrom,
|
|
58
|
-
types_1.TransactionType.tokenMethodSafeTransferFrom,
|
|
59
|
-
].find((methodName) => methodName.toLowerCase() === name.toLowerCase());
|
|
60
|
-
if (tokenMethodName) {
|
|
61
|
-
return { type: tokenMethodName, getCodeResponse };
|
|
62
|
-
}
|
|
63
|
-
return contractInteractionResult;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
exports.determineTransactionType = determineTransactionType;
|
|
67
|
-
/**
|
|
68
|
-
* Attempts to decode transaction data using ABIs for three different token standards: ERC20, ERC721, ERC1155.
|
|
69
|
-
* The data will decode correctly if the transaction is an interaction with a contract that matches one of these
|
|
70
|
-
* contract standards
|
|
71
|
-
*
|
|
72
|
-
* @param data - Encoded transaction data.
|
|
73
|
-
* @returns A representation of an ethereum contract call.
|
|
74
|
-
*/
|
|
75
|
-
function parseStandardTokenTransactionData(data) {
|
|
76
|
-
if (!data) {
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
return ERC20Interface.parseTransaction({ data });
|
|
81
|
-
}
|
|
82
|
-
catch (_a) {
|
|
83
|
-
// ignore and next try to parse with erc721 ABI
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
return ERC721Interface.parseTransaction({ data });
|
|
87
|
-
}
|
|
88
|
-
catch (_b) {
|
|
89
|
-
// ignore and next try to parse with erc1155 ABI
|
|
90
|
-
}
|
|
91
|
-
try {
|
|
92
|
-
return ERC1155Interface.parseTransaction({ data });
|
|
93
|
-
}
|
|
94
|
-
catch (_c) {
|
|
95
|
-
// ignore and return undefined
|
|
96
|
-
}
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Reads an Ethereum address and determines if it is a contract address.
|
|
101
|
-
*
|
|
102
|
-
* @param ethQuery - The Ethereum query object used to interact with the Ethereum blockchain.
|
|
103
|
-
* @param address - The Ethereum address.
|
|
104
|
-
* @returns An object containing the contract code and a boolean indicating if it is a contract address.
|
|
105
|
-
*/
|
|
106
|
-
function readAddressAsContract(ethQuery, address) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
-
let contractCode;
|
|
109
|
-
try {
|
|
110
|
-
contractCode = yield (0, controller_utils_1.query)(ethQuery, 'getCode', [address]);
|
|
111
|
-
}
|
|
112
|
-
catch (e) {
|
|
113
|
-
contractCode = null;
|
|
114
|
-
}
|
|
115
|
-
const isContractAddress = contractCode
|
|
116
|
-
? contractCode !== '0x' && contractCode !== '0x0'
|
|
117
|
-
: false;
|
|
118
|
-
return { contractCode, isContractAddress };
|
|
119
|
-
});
|
|
120
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkHS277C77js = require('../chunk-HS277C77.js');
|
|
5
|
+
require('../chunk-W3GAOR7Y.js');
|
|
6
|
+
require('../chunk-Z4BLTVTB.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.ESTIMATE_GAS_ERROR = _chunkHS277C77js.ESTIMATE_GAS_ERROR; exports.determineTransactionType = _chunkHS277C77js.determineTransactionType;
|
|
121
11
|
//# sourceMappingURL=transaction-type.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ESTIMATE_GAS_ERROR,
|
|
3
|
+
determineTransactionType
|
|
4
|
+
} from "../chunk-JRBREX22.mjs";
|
|
5
|
+
import "../chunk-NM4LTWRU.mjs";
|
|
6
|
+
import "../chunk-XUI43LEZ.mjs";
|
|
7
|
+
export {
|
|
8
|
+
ESTIMATE_GAS_ERROR,
|
|
9
|
+
determineTransactionType
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=transaction-type.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,161 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (txParams[key]) {
|
|
34
|
-
normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (!normalizedTxParams.value) {
|
|
38
|
-
normalizedTxParams.value = '0x0';
|
|
39
|
-
}
|
|
40
|
-
return normalizedTxParams;
|
|
41
|
-
}
|
|
42
|
-
exports.normalizeTransactionParams = normalizeTransactionParams;
|
|
43
|
-
/**
|
|
44
|
-
* Checks if a transaction is EIP-1559 by checking for the existence of
|
|
45
|
-
* maxFeePerGas and maxPriorityFeePerGas within its parameters.
|
|
46
|
-
*
|
|
47
|
-
* @param txParams - Transaction params object to add.
|
|
48
|
-
* @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.
|
|
49
|
-
*/
|
|
50
|
-
function isEIP1559Transaction(txParams) {
|
|
51
|
-
const hasOwnProp = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
|
|
52
|
-
return (hasOwnProp(txParams, 'maxFeePerGas') &&
|
|
53
|
-
hasOwnProp(txParams, 'maxPriorityFeePerGas'));
|
|
54
|
-
}
|
|
55
|
-
exports.isEIP1559Transaction = isEIP1559Transaction;
|
|
56
|
-
const validateGasValues = (gasValues) => {
|
|
57
|
-
Object.keys(gasValues).forEach((key) => {
|
|
58
|
-
// TODO: Replace `any` with type
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
const value = gasValues[key];
|
|
61
|
-
if (typeof value !== 'string' || !(0, utils_1.isStrictHexString)(value)) {
|
|
62
|
-
throw new TypeError(`expected hex string for ${key} but received: ${value}`);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
exports.validateGasValues = validateGasValues;
|
|
67
|
-
const isFeeMarketEIP1559Values = (gasValues) => (gasValues === null || gasValues === void 0 ? void 0 : gasValues.maxFeePerGas) !== undefined ||
|
|
68
|
-
(gasValues === null || gasValues === void 0 ? void 0 : gasValues.maxPriorityFeePerGas) !== undefined;
|
|
69
|
-
exports.isFeeMarketEIP1559Values = isFeeMarketEIP1559Values;
|
|
70
|
-
const isGasPriceValue = (gasValues) => (gasValues === null || gasValues === void 0 ? void 0 : gasValues.gasPrice) !== undefined;
|
|
71
|
-
exports.isGasPriceValue = isGasPriceValue;
|
|
72
|
-
const getIncreasedPriceHex = (value, rate) => (0, utils_1.add0x)(`${parseInt(`${value * rate}`, 10).toString(16)}`);
|
|
73
|
-
exports.getIncreasedPriceHex = getIncreasedPriceHex;
|
|
74
|
-
const getIncreasedPriceFromExisting = (value, rate) => {
|
|
75
|
-
return (0, exports.getIncreasedPriceHex)((0, controller_utils_1.convertHexToDecimal)(value), rate);
|
|
76
|
-
};
|
|
77
|
-
exports.getIncreasedPriceFromExisting = getIncreasedPriceFromExisting;
|
|
78
|
-
/**
|
|
79
|
-
* Validates that the proposed value is greater than or equal to the minimum value.
|
|
80
|
-
*
|
|
81
|
-
* @param proposed - The proposed value.
|
|
82
|
-
* @param min - The minimum value.
|
|
83
|
-
* @returns The proposed value.
|
|
84
|
-
* @throws Will throw if the proposed value is too low.
|
|
85
|
-
*/
|
|
86
|
-
function validateMinimumIncrease(proposed, min) {
|
|
87
|
-
const proposedDecimal = (0, controller_utils_1.convertHexToDecimal)(proposed);
|
|
88
|
-
const minDecimal = (0, controller_utils_1.convertHexToDecimal)(min);
|
|
89
|
-
if (proposedDecimal >= minDecimal) {
|
|
90
|
-
return proposed;
|
|
91
|
-
}
|
|
92
|
-
const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;
|
|
93
|
-
throw new Error(errorMsg);
|
|
94
|
-
}
|
|
95
|
-
exports.validateMinimumIncrease = validateMinimumIncrease;
|
|
96
|
-
/**
|
|
97
|
-
* Validates that a transaction is unapproved.
|
|
98
|
-
* Throws if the transaction is not unapproved.
|
|
99
|
-
*
|
|
100
|
-
* @param transactionMeta - The transaction metadata to check.
|
|
101
|
-
* @param fnName - The name of the function calling this helper.
|
|
102
|
-
*/
|
|
103
|
-
function validateIfTransactionUnapproved(transactionMeta, fnName) {
|
|
104
|
-
if ((transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.status) !== types_1.TransactionStatus.unapproved) {
|
|
105
|
-
throw new Error(`TransactionsController: Can only call ${fnName} on an unapproved transaction.
|
|
106
|
-
Current tx status: ${transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.status}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
exports.validateIfTransactionUnapproved = validateIfTransactionUnapproved;
|
|
110
|
-
/**
|
|
111
|
-
* Normalizes properties on transaction params.
|
|
112
|
-
*
|
|
113
|
-
* @param error - The error to be normalize.
|
|
114
|
-
* @returns Normalized transaction error.
|
|
115
|
-
*/
|
|
116
|
-
function normalizeTxError(error) {
|
|
117
|
-
return {
|
|
118
|
-
name: error.name,
|
|
119
|
-
message: error.message,
|
|
120
|
-
stack: error.stack,
|
|
121
|
-
code: error === null || error === void 0 ? void 0 : error.code,
|
|
122
|
-
rpc: error === null || error === void 0 ? void 0 : error.value,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
exports.normalizeTxError = normalizeTxError;
|
|
126
|
-
/**
|
|
127
|
-
* Normalize an object containing gas fee values.
|
|
128
|
-
*
|
|
129
|
-
* @param gasFeeValues - An object containing gas fee values.
|
|
130
|
-
* @returns An object containing normalized gas fee values.
|
|
131
|
-
*/
|
|
132
|
-
function normalizeGasFeeValues(gasFeeValues) {
|
|
133
|
-
// TODO: Replace `any` with type
|
|
134
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
|
-
const normalize = (value) => typeof value === 'string' ? (0, utils_1.add0x)(value) : value;
|
|
136
|
-
if ('gasPrice' in gasFeeValues) {
|
|
137
|
-
return {
|
|
138
|
-
gasPrice: normalize(gasFeeValues.gasPrice),
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),
|
|
143
|
-
maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
exports.normalizeGasFeeValues = normalizeGasFeeValues;
|
|
147
|
-
/**
|
|
148
|
-
* Ensure a hex string is of even length by adding a leading 0 if necessary.
|
|
149
|
-
* Any existing `0x` prefix is preserved but is not added if missing.
|
|
150
|
-
*
|
|
151
|
-
* @param hex - The hex string to ensure is even.
|
|
152
|
-
* @returns The hex string with an even length.
|
|
153
|
-
*/
|
|
154
|
-
function padHexToEvenLength(hex) {
|
|
155
|
-
const prefix = hex.toLowerCase().startsWith('0x') ? hex.slice(0, 2) : '';
|
|
156
|
-
const data = prefix ? hex.slice(2) : hex;
|
|
157
|
-
const evenData = data.length % 2 === 0 ? data : `0${data}`;
|
|
158
|
-
return prefix + evenData;
|
|
159
|
-
}
|
|
160
|
-
exports.padHexToEvenLength = padHexToEvenLength;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkUGFBA4GVjs = require('../chunk-UGFBA4GV.js');
|
|
16
|
+
require('../chunk-W3GAOR7Y.js');
|
|
17
|
+
require('../chunk-Z4BLTVTB.js');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
exports.ESTIMATE_GAS_ERROR = _chunkUGFBA4GVjs.ESTIMATE_GAS_ERROR; exports.getIncreasedPriceFromExisting = _chunkUGFBA4GVjs.getIncreasedPriceFromExisting; exports.getIncreasedPriceHex = _chunkUGFBA4GVjs.getIncreasedPriceHex; exports.isEIP1559Transaction = _chunkUGFBA4GVjs.isEIP1559Transaction; exports.isFeeMarketEIP1559Values = _chunkUGFBA4GVjs.isFeeMarketEIP1559Values; exports.isGasPriceValue = _chunkUGFBA4GVjs.isGasPriceValue; exports.normalizeGasFeeValues = _chunkUGFBA4GVjs.normalizeGasFeeValues; exports.normalizeTransactionParams = _chunkUGFBA4GVjs.normalizeTransactionParams; exports.normalizeTxError = _chunkUGFBA4GVjs.normalizeTxError; exports.padHexToEvenLength = _chunkUGFBA4GVjs.padHexToEvenLength; exports.validateGasValues = _chunkUGFBA4GVjs.validateGasValues; exports.validateIfTransactionUnapproved = _chunkUGFBA4GVjs.validateIfTransactionUnapproved; exports.validateMinimumIncrease = _chunkUGFBA4GVjs.validateMinimumIncrease;
|
|
161
33
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":";;;AAAA,iEAAiE;AACjE,2CAIyB;AAMzB,oCAA6C;AAOhC,QAAA,kBAAkB,GAAG,kCAAkC,CAAC;AAErE,gCAAgC;AAChC,8DAA8D;AAC9D,MAAM,WAAW,GAAgD;IAC/D,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,IAAI,CAAC,CAAC,WAAW,EAAE;IACjD,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,GAAG,CAAC;IAChC,QAAQ,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,GAAG,CAAC;IACrC,QAAQ,EAAE,CAAC,QAAgB,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,QAAQ,CAAC;IAC/C,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,KAAK,CAAC;IACtC,EAAE,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,EAAE,CAAC,CAAC,WAAW,EAAE;IAC3C,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,KAAK,CAAC;IACtC,YAA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AAC,CAAC,KAAK,CAAC;IAEnD,IAAI,UAAU,IAAI,YAAY,EAAE;QAC9B,OAAO;YACL,QAAQ,EAAE,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC;SAC3C,CAAC;KACH;IAED,OAAO;QACL,YAAY,EAAE,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC;QAClD,oBAAoB,EAAE,SAAS,CAAC,YAAY,CAAC,oBAAoB,CAAC;KACnE,CAAC;AACJ,CAAC;AAlBD,sDAkBC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,GAAW;IAC5C,MAAM,MAAM,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzE,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;IAE3D,OAAO,MAAM,GAAG,QAAQ,CAAC;AAC3B,CAAC;AAND,gDAMC","sourcesContent":["import { convertHexToDecimal } from '@metamask/controller-utils';\nimport {\n add0x,\n getKnownPropertyNames,\n isStrictHexString,\n} from '@metamask/utils';\n\nimport type {\n GasPriceValue,\n FeeMarketEIP1559Values,\n} from '../TransactionController';\nimport { TransactionStatus } from '../types';\nimport type {\n TransactionParams,\n TransactionMeta,\n TransactionError,\n} from '../types';\n\nexport const ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';\n\n// TODO: Replace `any` with type\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst NORMALIZERS: { [param in keyof TransactionParams]: any } = {\n data: (data: string) => add0x(padHexToEvenLength(data)),\n from: (from: string) => add0x(from).toLowerCase(),\n gas: (gas: string) => add0x(gas),\n gasLimit: (gas: string) => add0x(gas),\n gasPrice: (gasPrice: string) => add0x(gasPrice),\n nonce: (nonce: string) => add0x(nonce),\n to: (to: string) => add0x(to).toLowerCase(),\n value: (value: string) => add0x(value),\n maxFeePerGas: (maxFeePerGas: string) => add0x(maxFeePerGas),\n maxPriorityFeePerGas: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n estimatedBaseFee: (maxPriorityFeePerGas: string) =>\n add0x(maxPriorityFeePerGas),\n type: (type: string) => add0x(type),\n};\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param txParams - The transaction params to normalize.\n * @returns Normalized transaction params.\n */\nexport function normalizeTransactionParams(txParams: TransactionParams) {\n const normalizedTxParams: TransactionParams = { from: '' };\n\n for (const key of getKnownPropertyNames(NORMALIZERS)) {\n if (txParams[key]) {\n normalizedTxParams[key] = NORMALIZERS[key](txParams[key]);\n }\n }\n\n if (!normalizedTxParams.value) {\n normalizedTxParams.value = '0x0';\n }\n\n return normalizedTxParams;\n}\n\n/**\n * Checks if a transaction is EIP-1559 by checking for the existence of\n * maxFeePerGas and maxPriorityFeePerGas within its parameters.\n *\n * @param txParams - Transaction params object to add.\n * @returns Boolean that is true if the transaction is EIP-1559 (has maxFeePerGas and maxPriorityFeePerGas), otherwise returns false.\n */\nexport function isEIP1559Transaction(txParams: TransactionParams): boolean {\n const hasOwnProp = (obj: TransactionParams, key: string) =>\n Object.prototype.hasOwnProperty.call(obj, key);\n return (\n hasOwnProp(txParams, 'maxFeePerGas') &&\n hasOwnProp(txParams, 'maxPriorityFeePerGas')\n );\n}\n\nexport const validateGasValues = (\n gasValues: GasPriceValue | FeeMarketEIP1559Values,\n) => {\n Object.keys(gasValues).forEach((key) => {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const value = (gasValues as any)[key];\n if (typeof value !== 'string' || !isStrictHexString(value)) {\n throw new TypeError(\n `expected hex string for ${key} but received: ${value}`,\n );\n }\n });\n};\n\nexport const isFeeMarketEIP1559Values = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is FeeMarketEIP1559Values =>\n (gasValues as FeeMarketEIP1559Values)?.maxFeePerGas !== undefined ||\n (gasValues as FeeMarketEIP1559Values)?.maxPriorityFeePerGas !== undefined;\n\nexport const isGasPriceValue = (\n gasValues?: GasPriceValue | FeeMarketEIP1559Values,\n): gasValues is GasPriceValue =>\n (gasValues as GasPriceValue)?.gasPrice !== undefined;\n\nexport const getIncreasedPriceHex = (value: number, rate: number): string =>\n add0x(`${parseInt(`${value * rate}`, 10).toString(16)}`);\n\nexport const getIncreasedPriceFromExisting = (\n value: string | undefined,\n rate: number,\n): string => {\n return getIncreasedPriceHex(convertHexToDecimal(value), rate);\n};\n\n/**\n * Validates that the proposed value is greater than or equal to the minimum value.\n *\n * @param proposed - The proposed value.\n * @param min - The minimum value.\n * @returns The proposed value.\n * @throws Will throw if the proposed value is too low.\n */\nexport function validateMinimumIncrease(proposed: string, min: string) {\n const proposedDecimal = convertHexToDecimal(proposed);\n const minDecimal = convertHexToDecimal(min);\n if (proposedDecimal >= minDecimal) {\n return proposed;\n }\n const errorMsg = `The proposed value: ${proposedDecimal} should meet or exceed the minimum value: ${minDecimal}`;\n throw new Error(errorMsg);\n}\n\n/**\n * Validates that a transaction is unapproved.\n * Throws if the transaction is not unapproved.\n *\n * @param transactionMeta - The transaction metadata to check.\n * @param fnName - The name of the function calling this helper.\n */\nexport function validateIfTransactionUnapproved(\n transactionMeta: TransactionMeta | undefined,\n fnName: string,\n) {\n if (transactionMeta?.status !== TransactionStatus.unapproved) {\n throw new Error(\n `TransactionsController: Can only call ${fnName} on an unapproved transaction.\n Current tx status: ${transactionMeta?.status}`,\n );\n }\n}\n\n/**\n * Normalizes properties on transaction params.\n *\n * @param error - The error to be normalize.\n * @returns Normalized transaction error.\n */\nexport function normalizeTxError(\n error: Error & { code?: string; value?: unknown },\n): TransactionError {\n return {\n name: error.name,\n message: error.message,\n stack: error.stack,\n code: error?.code,\n rpc: error?.value,\n };\n}\n\n/**\n * Normalize an object containing gas fee values.\n *\n * @param gasFeeValues - An object containing gas fee values.\n * @returns An object containing normalized gas fee values.\n */\nexport function normalizeGasFeeValues(\n gasFeeValues: GasPriceValue | FeeMarketEIP1559Values,\n): GasPriceValue | FeeMarketEIP1559Values {\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const normalize = (value: any) =>\n typeof value === 'string' ? add0x(value) : value;\n\n if ('gasPrice' in gasFeeValues) {\n return {\n gasPrice: normalize(gasFeeValues.gasPrice),\n };\n }\n\n return {\n maxFeePerGas: normalize(gasFeeValues.maxFeePerGas),\n maxPriorityFeePerGas: normalize(gasFeeValues.maxPriorityFeePerGas),\n };\n}\n\n/**\n * Ensure a hex string is of even length by adding a leading 0 if necessary.\n * Any existing `0x` prefix is preserved but is not added if missing.\n *\n * @param hex - The hex string to ensure is even.\n * @returns The hex string with an even length.\n */\nexport function padHexToEvenLength(hex: string) {\n const prefix = hex.toLowerCase().startsWith('0x') ? hex.slice(0, 2) : '';\n const data = prefix ? hex.slice(2) : hex;\n const evenData = data.length % 2 === 0 ? data : `0${data}`;\n\n return prefix + evenData;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ESTIMATE_GAS_ERROR,
|
|
3
|
+
getIncreasedPriceFromExisting,
|
|
4
|
+
getIncreasedPriceHex,
|
|
5
|
+
isEIP1559Transaction,
|
|
6
|
+
isFeeMarketEIP1559Values,
|
|
7
|
+
isGasPriceValue,
|
|
8
|
+
normalizeGasFeeValues,
|
|
9
|
+
normalizeTransactionParams,
|
|
10
|
+
normalizeTxError,
|
|
11
|
+
padHexToEvenLength,
|
|
12
|
+
validateGasValues,
|
|
13
|
+
validateIfTransactionUnapproved,
|
|
14
|
+
validateMinimumIncrease
|
|
15
|
+
} from "../chunk-J56A7UCK.mjs";
|
|
16
|
+
import "../chunk-NM4LTWRU.mjs";
|
|
17
|
+
import "../chunk-XUI43LEZ.mjs";
|
|
18
|
+
export {
|
|
19
|
+
ESTIMATE_GAS_ERROR,
|
|
20
|
+
getIncreasedPriceFromExisting,
|
|
21
|
+
getIncreasedPriceHex,
|
|
22
|
+
isEIP1559Transaction,
|
|
23
|
+
isFeeMarketEIP1559Values,
|
|
24
|
+
isGasPriceValue,
|
|
25
|
+
normalizeGasFeeValues,
|
|
26
|
+
normalizeTransactionParams,
|
|
27
|
+
normalizeTxError,
|
|
28
|
+
padHexToEvenLength,
|
|
29
|
+
validateGasValues,
|
|
30
|
+
validateIfTransactionUnapproved,
|
|
31
|
+
validateMinimumIncrease
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|