@metamask-previews/bridge-controller 80.1.0-preview-3866c0ff1 → 80.1.0-preview-e3275932a
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 +0 -1
- package/dist/bridge-controller-method-action-types.cjs +7 -0
- package/dist/bridge-controller-method-action-types.cjs.map +1 -0
- package/dist/{bridge-controller-method-action-types.d.ts → bridge-controller-method-action-types.d.cts} +2 -2
- package/dist/bridge-controller-method-action-types.d.cts.map +1 -0
- package/dist/bridge-controller-method-action-types.d.mts +50 -0
- package/dist/bridge-controller-method-action-types.d.mts.map +1 -0
- package/dist/{bridge-controller-method-action-types.js → bridge-controller-method-action-types.mjs} +1 -1
- package/dist/bridge-controller-method-action-types.mjs.map +1 -0
- package/dist/bridge-controller.cjs +1044 -0
- package/dist/bridge-controller.cjs.map +1 -0
- package/dist/{bridge-controller.d.ts → bridge-controller.d.cts} +21 -21
- package/dist/bridge-controller.d.cts.map +1 -0
- package/dist/bridge-controller.d.mts +127 -0
- package/dist/bridge-controller.d.mts.map +1 -0
- package/dist/bridge-controller.mjs +1040 -0
- package/dist/bridge-controller.mjs.map +1 -0
- package/dist/coercers/quote-response-v1-to-v2.cjs +139 -0
- package/dist/coercers/quote-response-v1-to-v2.cjs.map +1 -0
- package/dist/coercers/{quote-response-v1-to-v2.d.ts → quote-response-v1-to-v2.d.cts} +4 -4
- package/dist/coercers/quote-response-v1-to-v2.d.cts.map +1 -0
- package/dist/coercers/quote-response-v1-to-v2.d.mts +13 -0
- package/dist/coercers/quote-response-v1-to-v2.d.mts.map +1 -0
- package/dist/coercers/{quote-response-v1-to-v2.js → quote-response-v1-to-v2.mjs} +11 -11
- package/dist/coercers/quote-response-v1-to-v2.mjs.map +1 -0
- package/dist/coercers/quote-response-v2-to-v1.cjs +162 -0
- package/dist/coercers/quote-response-v2-to-v1.cjs.map +1 -0
- package/dist/coercers/{quote-response-v2-to-v1.d.ts → quote-response-v2-to-v1.d.cts} +4 -4
- package/dist/coercers/quote-response-v2-to-v1.d.cts.map +1 -0
- package/dist/coercers/quote-response-v2-to-v1.d.mts +13 -0
- package/dist/coercers/quote-response-v2-to-v1.d.mts.map +1 -0
- package/dist/coercers/{quote-response-v2-to-v1.js → quote-response-v2-to-v1.mjs} +10 -10
- package/dist/coercers/quote-response-v2-to-v1.mjs.map +1 -0
- package/dist/constants/bridge.cjs +98 -0
- package/dist/constants/bridge.cjs.map +1 -0
- package/dist/constants/{bridge.d.ts → bridge.d.cts} +38 -38
- package/dist/constants/bridge.d.cts.map +1 -0
- package/dist/constants/bridge.d.mts +77 -0
- package/dist/constants/bridge.d.mts.map +1 -0
- package/dist/constants/{bridge.js → bridge.mjs} +4 -4
- package/dist/constants/bridge.mjs.map +1 -0
- package/dist/constants/chains.cjs +174 -0
- package/dist/constants/chains.cjs.map +1 -0
- package/dist/constants/{chains.d.ts → chains.d.cts} +84 -84
- package/dist/constants/chains.d.cts.map +1 -0
- package/dist/constants/chains.d.mts +171 -0
- package/dist/constants/chains.d.mts.map +1 -0
- package/dist/constants/{chains.js → chains.mjs} +1 -1
- package/dist/constants/chains.mjs.map +1 -0
- package/dist/constants/swaps.cjs +98 -0
- package/dist/constants/swaps.cjs.map +1 -0
- package/dist/constants/{swaps.d.ts → swaps.d.cts} +2 -2
- package/dist/constants/swaps.d.cts.map +1 -0
- package/dist/constants/swaps.d.mts +6 -0
- package/dist/constants/swaps.d.mts.map +1 -0
- package/dist/constants/{swaps.js → swaps.mjs} +2 -2
- package/dist/constants/swaps.mjs.map +1 -0
- package/dist/constants/tokens.cjs +212 -0
- package/dist/constants/tokens.cjs.map +1 -0
- package/dist/constants/{tokens.d.ts → tokens.d.cts} +34 -34
- package/dist/constants/tokens.d.cts.map +1 -0
- package/dist/constants/tokens.d.mts +195 -0
- package/dist/constants/tokens.d.mts.map +1 -0
- package/dist/constants/{tokens.js → tokens.mjs} +3 -3
- package/dist/constants/tokens.mjs.map +1 -0
- package/dist/constants/traces.cjs +11 -0
- package/dist/constants/traces.cjs.map +1 -0
- package/dist/constants/{traces.d.ts → traces.d.cts} +1 -1
- package/dist/constants/traces.d.cts.map +1 -0
- package/dist/constants/traces.d.mts +7 -0
- package/dist/constants/traces.d.mts.map +1 -0
- package/dist/constants/{traces.js → traces.mjs} +1 -1
- package/dist/constants/traces.mjs.map +1 -0
- package/dist/index.cjs +166 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +52 -52
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +60 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +47 -0
- package/dist/index.mjs.map +1 -0
- package/dist/selectors.cjs +449 -0
- package/dist/selectors.cjs.map +1 -0
- package/dist/{selectors.d.ts → selectors.d.cts} +5782 -5782
- package/dist/selectors.d.cts.map +1 -0
- package/dist/selectors.d.mts +13877 -0
- package/dist/selectors.d.mts.map +1 -0
- package/dist/{selectors.js → selectors.mjs} +19 -18
- package/dist/selectors.mjs.map +1 -0
- package/dist/types.cjs +66 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +27 -27
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +283 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/dist/utils/assets.cjs +43 -0
- package/dist/utils/assets.cjs.map +1 -0
- package/dist/utils/{assets.d.ts → assets.d.cts} +4 -4
- package/dist/utils/assets.d.cts.map +1 -0
- package/dist/utils/assets.d.mts +10 -0
- package/dist/utils/assets.d.mts.map +1 -0
- package/dist/utils/{assets.js → assets.mjs} +4 -4
- package/dist/utils/assets.mjs.map +1 -0
- package/dist/utils/balance.cjs +34 -0
- package/dist/utils/balance.cjs.map +1 -0
- package/dist/utils/{balance.d.ts → balance.d.cts} +4 -4
- package/dist/utils/balance.d.cts.map +1 -0
- package/dist/utils/balance.d.mts +7 -0
- package/dist/utils/balance.d.mts.map +1 -0
- package/dist/utils/{balance.js → balance.mjs} +6 -6
- package/dist/utils/balance.mjs.map +1 -0
- package/dist/utils/bridge.cjs +204 -0
- package/dist/utils/bridge.cjs.map +1 -0
- package/dist/utils/{bridge.d.ts → bridge.d.cts} +23 -8
- package/dist/utils/bridge.d.cts.map +1 -0
- package/dist/utils/bridge.d.mts +97 -0
- package/dist/utils/bridge.d.mts.map +1 -0
- package/dist/utils/{bridge.js → bridge.mjs} +12 -12
- package/dist/utils/bridge.mjs.map +1 -0
- package/dist/utils/caip-formatters.cjs +157 -0
- package/dist/utils/caip-formatters.cjs.map +1 -0
- package/dist/utils/{caip-formatters.d.ts → caip-formatters.d.cts} +3 -3
- package/dist/utils/caip-formatters.d.cts.map +1 -0
- package/dist/utils/caip-formatters.d.mts +40 -0
- package/dist/utils/caip-formatters.d.mts.map +1 -0
- package/dist/utils/{caip-formatters.js → caip-formatters.mjs} +9 -9
- package/dist/utils/caip-formatters.mjs.map +1 -0
- package/dist/utils/feature-flags.cjs +77 -0
- package/dist/utils/feature-flags.cjs.map +1 -0
- package/dist/utils/{feature-flags.d.ts → feature-flags.d.cts} +9 -9
- package/dist/utils/feature-flags.d.cts.map +1 -0
- package/dist/utils/feature-flags.d.mts +52 -0
- package/dist/utils/feature-flags.d.mts.map +1 -0
- package/dist/utils/{feature-flags.js → feature-flags.mjs} +4 -4
- package/dist/utils/feature-flags.mjs.map +1 -0
- package/dist/utils/fetch-server-events.cjs +70 -0
- package/dist/utils/fetch-server-events.cjs.map +1 -0
- package/dist/utils/{fetch-server-events.d.ts → fetch-server-events.d.cts} +3 -3
- package/dist/utils/fetch-server-events.d.cts.map +1 -0
- package/dist/utils/fetch-server-events.d.mts +17 -0
- package/dist/utils/fetch-server-events.d.mts.map +1 -0
- package/dist/utils/{fetch-server-events.js → fetch-server-events.mjs} +1 -1
- package/dist/utils/fetch-server-events.mjs.map +1 -0
- package/dist/utils/fetch.cjs +426 -0
- package/dist/utils/fetch.cjs.map +1 -0
- package/dist/utils/{fetch.d.ts → fetch.d.cts} +15 -15
- package/dist/utils/fetch.d.cts.map +1 -0
- package/dist/utils/fetch.d.mts +114 -0
- package/dist/utils/fetch.d.mts.map +1 -0
- package/dist/utils/{fetch.js → fetch.mjs} +15 -15
- package/dist/utils/fetch.mjs.map +1 -0
- package/dist/utils/metrics/constants.cjs +103 -0
- package/dist/utils/metrics/constants.cjs.map +1 -0
- package/dist/utils/metrics/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/utils/metrics/constants.d.cts.map +1 -0
- package/dist/utils/metrics/constants.d.mts +91 -0
- package/dist/utils/metrics/constants.d.mts.map +1 -0
- package/dist/utils/metrics/{constants.js → constants.mjs} +1 -1
- package/dist/utils/metrics/constants.mjs.map +1 -0
- package/dist/utils/metrics/properties.cjs +140 -0
- package/dist/utils/metrics/properties.cjs.map +1 -0
- package/dist/utils/metrics/{properties.d.ts → properties.d.cts} +14 -14
- package/dist/utils/metrics/properties.d.cts.map +1 -0
- package/dist/utils/metrics/properties.d.mts +66 -0
- package/dist/utils/metrics/properties.d.mts.map +1 -0
- package/dist/utils/metrics/{properties.js → properties.mjs} +7 -7
- package/dist/utils/metrics/properties.mjs.map +1 -0
- package/dist/utils/metrics/types.cjs +3 -0
- package/dist/utils/metrics/types.cjs.map +1 -0
- package/dist/utils/metrics/{types.d.ts → types.d.cts} +5 -5
- package/dist/utils/metrics/types.d.cts.map +1 -0
- package/dist/utils/metrics/types.d.mts +311 -0
- package/dist/utils/metrics/types.d.mts.map +1 -0
- package/dist/utils/metrics/types.mjs +2 -0
- package/dist/utils/metrics/types.mjs.map +1 -0
- package/dist/utils/number-formatters.cjs +107 -0
- package/dist/utils/number-formatters.cjs.map +1 -0
- package/dist/utils/{number-formatters.d.ts → number-formatters.d.cts} +4 -4
- package/dist/utils/number-formatters.d.cts.map +1 -0
- package/dist/utils/number-formatters.d.mts +34 -0
- package/dist/utils/number-formatters.d.mts.map +1 -0
- package/dist/utils/{number-formatters.js → number-formatters.mjs} +3 -3
- package/dist/utils/number-formatters.mjs.map +1 -0
- package/dist/utils/quote-fees.cjs +144 -0
- package/dist/utils/quote-fees.cjs.map +1 -0
- package/dist/utils/quote-fees.d.cts +21 -0
- package/dist/utils/quote-fees.d.cts.map +1 -0
- package/dist/utils/quote-fees.d.mts +21 -0
- package/dist/utils/quote-fees.d.mts.map +1 -0
- package/dist/utils/{quote-fees.js → quote-fees.mjs} +7 -7
- package/dist/utils/quote-fees.mjs.map +1 -0
- package/dist/utils/quote-metadata/calculators.cjs +345 -0
- package/dist/utils/quote-metadata/calculators.cjs.map +1 -0
- package/dist/utils/quote-metadata/{calculators.d.ts → calculators.d.cts} +12 -12
- package/dist/utils/quote-metadata/calculators.d.cts.map +1 -0
- package/dist/utils/quote-metadata/calculators.d.mts +121 -0
- package/dist/utils/quote-metadata/calculators.d.mts.map +1 -0
- package/dist/utils/quote-metadata/{calculators.js → calculators.mjs} +11 -11
- package/dist/utils/quote-metadata/calculators.mjs.map +1 -0
- package/dist/utils/quote-metadata/include-if-truthy.cjs +21 -0
- package/dist/utils/quote-metadata/include-if-truthy.cjs.map +1 -0
- package/dist/utils/quote-metadata/{include-if-truthy.d.ts → include-if-truthy.d.cts} +1 -1
- package/dist/utils/quote-metadata/include-if-truthy.d.cts.map +1 -0
- package/dist/utils/quote-metadata/include-if-truthy.d.mts +9 -0
- package/dist/utils/quote-metadata/include-if-truthy.d.mts.map +1 -0
- package/dist/utils/quote-metadata/{include-if-truthy.js → include-if-truthy.mjs} +1 -1
- package/dist/utils/quote-metadata/include-if-truthy.mjs.map +1 -0
- package/dist/utils/quote-metadata/merge.cjs +60 -0
- package/dist/utils/quote-metadata/merge.cjs.map +1 -0
- package/dist/utils/quote-metadata/{merge.d.ts → merge.d.cts} +5 -5
- package/dist/utils/quote-metadata/merge.d.cts.map +1 -0
- package/dist/utils/quote-metadata/merge.d.mts +15 -0
- package/dist/utils/quote-metadata/merge.d.mts.map +1 -0
- package/dist/utils/quote-metadata/{merge.js → merge.mjs} +7 -6
- package/dist/utils/quote-metadata/merge.mjs.map +1 -0
- package/dist/utils/quote-metadata/to-currency-values.cjs +62 -0
- package/dist/utils/quote-metadata/to-currency-values.cjs.map +1 -0
- package/dist/utils/quote-metadata/{to-currency-values.d.ts → to-currency-values.d.cts} +4 -4
- package/dist/utils/quote-metadata/to-currency-values.d.cts.map +1 -0
- package/dist/utils/quote-metadata/to-currency-values.d.mts +12 -0
- package/dist/utils/quote-metadata/to-currency-values.d.mts.map +1 -0
- package/dist/utils/quote-metadata/{to-currency-values.js → to-currency-values.mjs} +3 -2
- package/dist/utils/quote-metadata/to-currency-values.mjs.map +1 -0
- package/dist/utils/quote-metadata/to-normalized-amounts.cjs +38 -0
- package/dist/utils/quote-metadata/to-normalized-amounts.cjs.map +1 -0
- package/dist/utils/quote-metadata/{to-normalized-amounts.d.ts → to-normalized-amounts.d.cts} +3 -3
- package/dist/utils/quote-metadata/to-normalized-amounts.d.cts.map +1 -0
- package/dist/utils/quote-metadata/to-normalized-amounts.d.mts +10 -0
- package/dist/utils/quote-metadata/to-normalized-amounts.d.mts.map +1 -0
- package/dist/utils/quote-metadata/{to-normalized-amounts.js → to-normalized-amounts.mjs} +3 -3
- package/dist/utils/quote-metadata/to-normalized-amounts.mjs.map +1 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v1.cjs +94 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v1.cjs.map +1 -0
- package/dist/utils/quote-metadata/{to-quote-metadata-v1.d.ts → to-quote-metadata-v1.d.cts} +6 -6
- package/dist/utils/quote-metadata/to-quote-metadata-v1.d.cts.map +1 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v1.d.mts +15 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v1.d.mts.map +1 -0
- package/dist/utils/quote-metadata/{to-quote-metadata-v1.js → to-quote-metadata-v1.mjs} +7 -6
- package/dist/utils/quote-metadata/to-quote-metadata-v1.mjs.map +1 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v2.cjs +84 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v2.cjs.map +1 -0
- package/dist/utils/quote-metadata/{to-quote-metadata-v2.d.ts → to-quote-metadata-v2.d.cts} +4 -4
- package/dist/utils/quote-metadata/to-quote-metadata-v2.d.cts.map +1 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v2.d.mts +12 -0
- package/dist/utils/quote-metadata/to-quote-metadata-v2.d.mts.map +1 -0
- package/dist/utils/quote-metadata/{to-quote-metadata-v2.js → to-quote-metadata-v2.mjs} +6 -6
- package/dist/utils/quote-metadata/to-quote-metadata-v2.mjs.map +1 -0
- package/dist/utils/quote-metadata/types.cjs +19 -0
- package/dist/utils/quote-metadata/types.cjs.map +1 -0
- package/dist/utils/quote-metadata/{types.d.ts → types.d.cts} +5 -5
- package/dist/utils/quote-metadata/types.d.cts.map +1 -0
- package/dist/utils/quote-metadata/types.d.mts +108 -0
- package/dist/utils/quote-metadata/types.d.mts.map +1 -0
- package/dist/utils/quote-metadata/{types.js → types.mjs} +1 -1
- package/dist/utils/quote-metadata/types.mjs.map +1 -0
- package/dist/utils/slippage.cjs +49 -0
- package/dist/utils/slippage.cjs.map +1 -0
- package/dist/utils/{slippage.d.ts → slippage.d.cts} +2 -2
- package/dist/utils/slippage.d.cts.map +1 -0
- package/dist/utils/slippage.d.mts +23 -0
- package/dist/utils/slippage.d.mts.map +1 -0
- package/dist/utils/{slippage.js → slippage.mjs} +2 -2
- package/dist/utils/slippage.mjs.map +1 -0
- package/dist/utils/snaps.cjs +76 -0
- package/dist/utils/snaps.cjs.map +1 -0
- package/dist/utils/{snaps.d.ts → snaps.d.cts} +5 -5
- package/dist/utils/snaps.d.cts.map +1 -0
- package/dist/utils/snaps.d.mts +59 -0
- package/dist/utils/snaps.d.mts.map +1 -0
- package/dist/utils/{snaps.js → snaps.mjs} +4 -4
- package/dist/utils/snaps.mjs.map +1 -0
- package/dist/utils/sort-quotes.cjs +16 -0
- package/dist/utils/sort-quotes.cjs.map +1 -0
- package/dist/utils/sort-quotes.d.cts +4 -0
- package/dist/utils/sort-quotes.d.cts.map +1 -0
- package/dist/utils/sort-quotes.d.mts +4 -0
- package/dist/utils/sort-quotes.d.mts.map +1 -0
- package/dist/utils/{sort-quotes.js → sort-quotes.mjs} +2 -2
- package/dist/utils/sort-quotes.mjs.map +1 -0
- package/dist/utils/struct-error.cjs +16 -0
- package/dist/utils/struct-error.cjs.map +1 -0
- package/dist/utils/{struct-error.d.ts → struct-error.d.cts} +2 -2
- package/dist/utils/struct-error.d.cts.map +1 -0
- package/dist/utils/struct-error.d.mts +11 -0
- package/dist/utils/struct-error.d.mts.map +1 -0
- package/dist/utils/{struct-error.js → struct-error.mjs} +1 -1
- package/dist/utils/struct-error.mjs.map +1 -0
- package/dist/utils/swaps.cjs +73 -0
- package/dist/utils/swaps.cjs.map +1 -0
- package/dist/utils/{swaps.d.ts → swaps.d.cts} +3 -3
- package/dist/utils/swaps.d.cts.map +1 -0
- package/dist/utils/swaps.d.mts +37 -0
- package/dist/utils/swaps.d.mts.map +1 -0
- package/dist/utils/{swaps.js → swaps.mjs} +5 -5
- package/dist/utils/swaps.mjs.map +1 -0
- package/dist/utils/trade-utils.cjs +39 -0
- package/dist/utils/trade-utils.cjs.map +1 -0
- package/dist/utils/{trade-utils.d.ts → trade-utils.d.cts} +2 -2
- package/dist/utils/trade-utils.d.cts.map +1 -0
- package/dist/utils/trade-utils.d.mts +9 -0
- package/dist/utils/trade-utils.d.mts.map +1 -0
- package/dist/utils/{trade-utils.js → trade-utils.mjs} +2 -2
- package/dist/utils/trade-utils.mjs.map +1 -0
- package/dist/validators/amount-and-asset.cjs +27 -0
- package/dist/validators/amount-and-asset.cjs.map +1 -0
- package/dist/validators/{amount-and-asset.d.ts → amount-and-asset.d.cts} +8 -8
- package/dist/validators/amount-and-asset.d.cts.map +1 -0
- package/dist/validators/amount-and-asset.d.mts +62 -0
- package/dist/validators/amount-and-asset.d.mts.map +1 -0
- package/dist/validators/{amount-and-asset.js → amount-and-asset.mjs} +4 -4
- package/dist/validators/amount-and-asset.mjs.map +1 -0
- package/dist/validators/batch-sell.cjs +39 -0
- package/dist/validators/batch-sell.cjs.map +1 -0
- package/dist/validators/{batch-sell.d.ts → batch-sell.d.cts} +39 -8
- package/dist/validators/batch-sell.d.cts.map +1 -0
- package/dist/validators/batch-sell.d.mts +79 -0
- package/dist/validators/batch-sell.d.mts.map +1 -0
- package/dist/validators/{batch-sell.js → batch-sell.mjs} +7 -7
- package/dist/validators/batch-sell.mjs.map +1 -0
- package/dist/validators/bridge-asset.cjs +106 -0
- package/dist/validators/bridge-asset.cjs.map +1 -0
- package/dist/validators/{bridge-asset.d.ts → bridge-asset.d.cts} +42 -10
- package/dist/validators/bridge-asset.d.cts.map +1 -0
- package/dist/validators/bridge-asset.d.mts +146 -0
- package/dist/validators/bridge-asset.d.mts.map +1 -0
- package/dist/validators/{bridge-asset.js → bridge-asset.mjs} +3 -3
- package/dist/validators/bridge-asset.mjs.map +1 -0
- package/dist/validators/feature-flags.cjs +110 -0
- package/dist/validators/feature-flags.cjs.map +1 -0
- package/dist/validators/{feature-flags.d.ts → feature-flags.d.cts} +60 -16
- package/dist/validators/feature-flags.d.cts.map +1 -0
- package/dist/validators/feature-flags.d.mts +264 -0
- package/dist/validators/feature-flags.d.mts.map +1 -0
- package/dist/validators/{feature-flags.js → feature-flags.mjs} +3 -3
- package/dist/validators/feature-flags.mjs.map +1 -0
- package/dist/validators/intent.cjs +122 -0
- package/dist/validators/intent.cjs.map +1 -0
- package/dist/validators/{intent.d.ts → intent.d.cts} +12 -12
- package/dist/validators/intent.d.cts.map +1 -0
- package/dist/validators/intent.d.mts +231 -0
- package/dist/validators/intent.d.mts.map +1 -0
- package/dist/validators/{intent.js → intent.mjs} +4 -4
- package/dist/validators/intent.mjs.map +1 -0
- package/dist/validators/number.cjs +8 -0
- package/dist/validators/number.cjs.map +1 -0
- package/dist/validators/{number.d.ts → number.d.cts} +1 -1
- package/dist/validators/number.d.cts.map +1 -0
- package/dist/validators/number.d.mts +4 -0
- package/dist/validators/number.d.mts.map +1 -0
- package/dist/validators/{number.js → number.mjs} +2 -2
- package/dist/validators/number.mjs.map +1 -0
- package/dist/validators/quote-request.cjs +57 -0
- package/dist/validators/quote-request.cjs.map +1 -0
- package/dist/validators/{quote-request.d.ts → quote-request.d.cts} +2 -2
- package/dist/validators/quote-request.d.cts.map +1 -0
- package/dist/validators/quote-request.d.mts +4 -0
- package/dist/validators/quote-request.d.mts.map +1 -0
- package/dist/validators/{quote-request.js → quote-request.mjs} +2 -2
- package/dist/validators/quote-request.mjs.map +1 -0
- package/dist/validators/quote-response-v1.cjs +31 -0
- package/dist/validators/quote-response-v1.cjs.map +1 -0
- package/dist/validators/{quote-response-v1.d.ts → quote-response-v1.d.cts} +335 -128
- package/dist/validators/quote-response-v1.d.cts.map +1 -0
- package/dist/validators/quote-response-v1.d.mts +661 -0
- package/dist/validators/quote-response-v1.d.mts.map +1 -0
- package/dist/validators/{quote-response-v1.js → quote-response-v1.mjs} +7 -7
- package/dist/validators/quote-response-v1.mjs.map +1 -0
- package/dist/validators/quote-response.cjs +129 -0
- package/dist/validators/quote-response.cjs.map +1 -0
- package/dist/validators/{quote-response.d.ts → quote-response.d.cts} +414 -414
- package/dist/validators/{quote-response.d.ts.map → quote-response.d.cts.map} +1 -1
- package/dist/validators/quote-response.d.mts +1973 -0
- package/dist/validators/quote-response.d.mts.map +1 -0
- package/dist/validators/{quote-response.js → quote-response.mjs} +7 -7
- package/dist/validators/quote-response.mjs.map +1 -0
- package/dist/validators/quote-stream-complete.cjs +29 -0
- package/dist/validators/quote-stream-complete.cjs.map +1 -0
- package/dist/validators/{quote-stream-complete.d.ts → quote-stream-complete.d.cts} +11 -7
- package/dist/validators/quote-stream-complete.d.cts.map +1 -0
- package/dist/validators/quote-stream-complete.d.mts +39 -0
- package/dist/validators/quote-stream-complete.d.mts.map +1 -0
- package/dist/validators/{quote-stream-complete.js → quote-stream-complete.mjs} +2 -2
- package/dist/validators/quote-stream-complete.mjs.map +1 -0
- package/dist/validators/quote.cjs +164 -0
- package/dist/validators/quote.cjs.map +1 -0
- package/dist/validators/{quote.d.ts → quote.d.cts} +132 -132
- package/dist/validators/quote.d.cts.map +1 -0
- package/dist/validators/quote.d.mts +588 -0
- package/dist/validators/quote.d.mts.map +1 -0
- package/dist/validators/{quote.js → quote.mjs} +7 -7
- package/dist/validators/quote.mjs.map +1 -0
- package/dist/validators/step.cjs +26 -0
- package/dist/validators/step.cjs.map +1 -0
- package/dist/validators/{step.d.ts → step.d.cts} +56 -56
- package/dist/validators/step.d.cts.map +1 -0
- package/dist/validators/step.d.mts +319 -0
- package/dist/validators/step.d.mts.map +1 -0
- package/dist/validators/{step.js → step.mjs} +4 -4
- package/dist/validators/step.mjs.map +1 -0
- package/dist/validators/token-feature.cjs +22 -0
- package/dist/validators/token-feature.cjs.map +1 -0
- package/dist/validators/{token-feature.d.ts → token-feature.d.cts} +9 -6
- package/dist/validators/token-feature.d.cts.map +1 -0
- package/dist/validators/token-feature.d.mts +26 -0
- package/dist/validators/token-feature.d.mts.map +1 -0
- package/dist/validators/{token-feature.js → token-feature.mjs} +2 -2
- package/dist/validators/token-feature.mjs.map +1 -0
- package/dist/validators/trade.cjs +94 -0
- package/dist/validators/trade.cjs.map +1 -0
- package/dist/validators/{trade.d.ts → trade.d.cts} +31 -7
- package/dist/validators/trade.d.cts.map +1 -0
- package/dist/validators/trade.d.mts +121 -0
- package/dist/validators/trade.d.mts.map +1 -0
- package/dist/validators/{trade.js → trade.mjs} +2 -2
- package/dist/validators/trade.mjs.map +1 -0
- package/package.json +17 -13
- package/dist/bridge-controller-method-action-types.d.ts.map +0 -1
- package/dist/bridge-controller-method-action-types.js.map +0 -1
- package/dist/bridge-controller.d.ts.map +0 -1
- package/dist/bridge-controller.js +0 -1029
- package/dist/bridge-controller.js.map +0 -1
- package/dist/coercers/quote-response-v1-to-v2.d.ts.map +0 -1
- package/dist/coercers/quote-response-v1-to-v2.js.map +0 -1
- package/dist/coercers/quote-response-v2-to-v1.d.ts.map +0 -1
- package/dist/coercers/quote-response-v2-to-v1.js.map +0 -1
- package/dist/constants/bridge.d.ts.map +0 -1
- package/dist/constants/bridge.js.map +0 -1
- package/dist/constants/chains.d.ts.map +0 -1
- package/dist/constants/chains.js.map +0 -1
- package/dist/constants/swaps.d.ts.map +0 -1
- package/dist/constants/swaps.js.map +0 -1
- package/dist/constants/tokens.d.ts.map +0 -1
- package/dist/constants/tokens.js.map +0 -1
- package/dist/constants/traces.d.ts.map +0 -1
- package/dist/constants/traces.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -47
- package/dist/index.js.map +0 -1
- package/dist/selectors.d.ts.map +0 -1
- package/dist/selectors.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/assets.d.ts.map +0 -1
- package/dist/utils/assets.js.map +0 -1
- package/dist/utils/balance.d.ts.map +0 -1
- package/dist/utils/balance.js.map +0 -1
- package/dist/utils/bridge.d.ts.map +0 -1
- package/dist/utils/bridge.js.map +0 -1
- package/dist/utils/caip-formatters.d.ts.map +0 -1
- package/dist/utils/caip-formatters.js.map +0 -1
- package/dist/utils/feature-flags.d.ts.map +0 -1
- package/dist/utils/feature-flags.js.map +0 -1
- package/dist/utils/fetch-server-events.d.ts.map +0 -1
- package/dist/utils/fetch-server-events.js.map +0 -1
- package/dist/utils/fetch.d.ts.map +0 -1
- package/dist/utils/fetch.js.map +0 -1
- package/dist/utils/metrics/constants.d.ts.map +0 -1
- package/dist/utils/metrics/constants.js.map +0 -1
- package/dist/utils/metrics/properties.d.ts.map +0 -1
- package/dist/utils/metrics/properties.js.map +0 -1
- package/dist/utils/metrics/types.d.ts.map +0 -1
- package/dist/utils/metrics/types.js +0 -2
- package/dist/utils/metrics/types.js.map +0 -1
- package/dist/utils/number-formatters.d.ts.map +0 -1
- package/dist/utils/number-formatters.js.map +0 -1
- package/dist/utils/quote-fees.d.ts +0 -17
- package/dist/utils/quote-fees.d.ts.map +0 -1
- package/dist/utils/quote-fees.js.map +0 -1
- package/dist/utils/quote-metadata/calculators.d.ts.map +0 -1
- package/dist/utils/quote-metadata/calculators.js.map +0 -1
- package/dist/utils/quote-metadata/include-if-truthy.d.ts.map +0 -1
- package/dist/utils/quote-metadata/include-if-truthy.js.map +0 -1
- package/dist/utils/quote-metadata/merge.d.ts.map +0 -1
- package/dist/utils/quote-metadata/merge.js.map +0 -1
- package/dist/utils/quote-metadata/to-currency-values.d.ts.map +0 -1
- package/dist/utils/quote-metadata/to-currency-values.js.map +0 -1
- package/dist/utils/quote-metadata/to-normalized-amounts.d.ts.map +0 -1
- package/dist/utils/quote-metadata/to-normalized-amounts.js.map +0 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v1.d.ts.map +0 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v1.js.map +0 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v2.d.ts.map +0 -1
- package/dist/utils/quote-metadata/to-quote-metadata-v2.js.map +0 -1
- package/dist/utils/quote-metadata/types.d.ts.map +0 -1
- package/dist/utils/quote-metadata/types.js.map +0 -1
- package/dist/utils/slippage.d.ts.map +0 -1
- package/dist/utils/slippage.js.map +0 -1
- package/dist/utils/snaps.d.ts.map +0 -1
- package/dist/utils/snaps.js.map +0 -1
- package/dist/utils/sort-quotes.d.ts +0 -4
- package/dist/utils/sort-quotes.d.ts.map +0 -1
- package/dist/utils/sort-quotes.js.map +0 -1
- package/dist/utils/struct-error.d.ts.map +0 -1
- package/dist/utils/struct-error.js.map +0 -1
- package/dist/utils/swaps.d.ts.map +0 -1
- package/dist/utils/swaps.js.map +0 -1
- package/dist/utils/trade-utils.d.ts.map +0 -1
- package/dist/utils/trade-utils.js.map +0 -1
- package/dist/validators/amount-and-asset.d.ts.map +0 -1
- package/dist/validators/amount-and-asset.js.map +0 -1
- package/dist/validators/batch-sell.d.ts.map +0 -1
- package/dist/validators/batch-sell.js.map +0 -1
- package/dist/validators/bridge-asset.d.ts.map +0 -1
- package/dist/validators/bridge-asset.js.map +0 -1
- package/dist/validators/feature-flags.d.ts.map +0 -1
- package/dist/validators/feature-flags.js.map +0 -1
- package/dist/validators/intent.d.ts.map +0 -1
- package/dist/validators/intent.js.map +0 -1
- package/dist/validators/number.d.ts.map +0 -1
- package/dist/validators/number.js.map +0 -1
- package/dist/validators/quote-request.d.ts.map +0 -1
- package/dist/validators/quote-request.js.map +0 -1
- package/dist/validators/quote-response-v1.d.ts.map +0 -1
- package/dist/validators/quote-response-v1.js.map +0 -1
- package/dist/validators/quote-response.js.map +0 -1
- package/dist/validators/quote-stream-complete.d.ts.map +0 -1
- package/dist/validators/quote-stream-complete.js.map +0 -1
- package/dist/validators/quote.d.ts.map +0 -1
- package/dist/validators/quote.js.map +0 -1
- package/dist/validators/step.d.ts.map +0 -1
- package/dist/validators/step.js.map +0 -1
- package/dist/validators/token-feature.d.ts.map +0 -1
- package/dist/validators/token-feature.js.map +0 -1
- package/dist/validators/trade.d.ts.map +0 -1
- package/dist/validators/trade.js.map +0 -1
|
@@ -0,0 +1,1044 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _BridgeController_instances, _BridgeController_abortController, _BridgeController_batchSellTradesAbortController, _BridgeController_quotesFirstFetched, _BridgeController_location, _BridgeController_clientId, _BridgeController_clientVersion, _BridgeController_getLayer1GasFee, _BridgeController_fetchFn, _BridgeController_trackMetaMetricsFn, _BridgeController_trace, _BridgeController_config, _BridgeController_getUseAssetsControllerForRates, _BridgeController_trackQuoteValidationFailures, _BridgeController_fetchAssetExchangeRates, _BridgeController_hasInsufficientBalance, _BridgeController_appendInsufficientBalAndResetApproval, _BridgeController_shouldResetApproval, _BridgeController_fetchBridgeQuotes, _BridgeController_handleQuoteStreaming, _BridgeController_setMinimumBalanceForRentExemptionInLamports, _BridgeController_getMultichainSelectedAccount, _BridgeController_getNetworkClientByChainId, _BridgeController_getJwt, _BridgeController_getRequestMetadata, _BridgeController_getQuoteFetchData, _BridgeController_getEventProperties, _BridgeController_trackInputChangedEvents, _BridgeController_getUSDTMainnetAllowance;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BridgeController = void 0;
|
|
16
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
17
|
+
const bignumber_1 = require("@ethersproject/bignumber");
|
|
18
|
+
const contracts_1 = require("@ethersproject/contracts");
|
|
19
|
+
const providers_1 = require("@ethersproject/providers");
|
|
20
|
+
const metamask_eth_abis_1 = require("@metamask/metamask-eth-abis");
|
|
21
|
+
const polling_controller_1 = require("@metamask/polling-controller");
|
|
22
|
+
const uuid_1 = require("uuid");
|
|
23
|
+
const quote_response_v1_to_v2_js_1 = require("./coercers/quote-response-v1-to-v2.cjs");
|
|
24
|
+
const bridge_js_1 = require("./constants/bridge.cjs");
|
|
25
|
+
const chains_js_1 = require("./constants/chains.cjs");
|
|
26
|
+
const swaps_js_1 = require("./constants/swaps.cjs");
|
|
27
|
+
const traces_js_1 = require("./constants/traces.cjs");
|
|
28
|
+
const types_js_1 = require("./types.cjs");
|
|
29
|
+
const assets_js_1 = require("./utils/assets.cjs");
|
|
30
|
+
const balance_js_1 = require("./utils/balance.cjs");
|
|
31
|
+
const bridge_js_2 = require("./utils/bridge.cjs");
|
|
32
|
+
const caip_formatters_js_1 = require("./utils/caip-formatters.cjs");
|
|
33
|
+
const feature_flags_js_1 = require("./utils/feature-flags.cjs");
|
|
34
|
+
const fetch_js_1 = require("./utils/fetch.cjs");
|
|
35
|
+
const constants_js_1 = require("./utils/metrics/constants.cjs");
|
|
36
|
+
const properties_js_1 = require("./utils/metrics/properties.cjs");
|
|
37
|
+
const quote_fees_js_1 = require("./utils/quote-fees.cjs");
|
|
38
|
+
const snaps_js_1 = require("./utils/snaps.cjs");
|
|
39
|
+
const sort_quotes_js_1 = require("./utils/sort-quotes.cjs");
|
|
40
|
+
const quote_request_js_1 = require("./validators/quote-request.cjs");
|
|
41
|
+
const metadata = {
|
|
42
|
+
quoteRequest: {
|
|
43
|
+
includeInStateLogs: true,
|
|
44
|
+
persist: false,
|
|
45
|
+
includeInDebugSnapshot: false,
|
|
46
|
+
usedInUi: true,
|
|
47
|
+
},
|
|
48
|
+
quotes: {
|
|
49
|
+
includeInStateLogs: true,
|
|
50
|
+
persist: false,
|
|
51
|
+
includeInDebugSnapshot: false,
|
|
52
|
+
usedInUi: true,
|
|
53
|
+
},
|
|
54
|
+
quotesInitialLoadTime: {
|
|
55
|
+
includeInStateLogs: true,
|
|
56
|
+
persist: false,
|
|
57
|
+
includeInDebugSnapshot: false,
|
|
58
|
+
usedInUi: true,
|
|
59
|
+
},
|
|
60
|
+
quotesLastFetched: {
|
|
61
|
+
includeInStateLogs: true,
|
|
62
|
+
persist: false,
|
|
63
|
+
includeInDebugSnapshot: false,
|
|
64
|
+
usedInUi: true,
|
|
65
|
+
},
|
|
66
|
+
quotesLoadingStatus: {
|
|
67
|
+
includeInStateLogs: true,
|
|
68
|
+
persist: false,
|
|
69
|
+
includeInDebugSnapshot: false,
|
|
70
|
+
usedInUi: true,
|
|
71
|
+
},
|
|
72
|
+
quoteFetchError: {
|
|
73
|
+
includeInStateLogs: true,
|
|
74
|
+
persist: false,
|
|
75
|
+
includeInDebugSnapshot: false,
|
|
76
|
+
usedInUi: true,
|
|
77
|
+
},
|
|
78
|
+
quotesRefreshCount: {
|
|
79
|
+
includeInStateLogs: true,
|
|
80
|
+
persist: false,
|
|
81
|
+
includeInDebugSnapshot: false,
|
|
82
|
+
usedInUi: true,
|
|
83
|
+
},
|
|
84
|
+
assetExchangeRates: {
|
|
85
|
+
includeInStateLogs: true,
|
|
86
|
+
persist: false,
|
|
87
|
+
includeInDebugSnapshot: false,
|
|
88
|
+
usedInUi: true,
|
|
89
|
+
},
|
|
90
|
+
minimumBalanceForRentExemptionInLamports: {
|
|
91
|
+
includeInStateLogs: true,
|
|
92
|
+
persist: false,
|
|
93
|
+
includeInDebugSnapshot: false,
|
|
94
|
+
usedInUi: true,
|
|
95
|
+
},
|
|
96
|
+
tokenWarnings: {
|
|
97
|
+
includeInStateLogs: true,
|
|
98
|
+
persist: false,
|
|
99
|
+
includeInDebugSnapshot: false,
|
|
100
|
+
usedInUi: true,
|
|
101
|
+
},
|
|
102
|
+
tokenSecurityTypeDestination: {
|
|
103
|
+
includeInStateLogs: true,
|
|
104
|
+
persist: false,
|
|
105
|
+
includeInDebugSnapshot: false,
|
|
106
|
+
usedInUi: true,
|
|
107
|
+
},
|
|
108
|
+
inputPrimaryDenomination: {
|
|
109
|
+
includeInStateLogs: true,
|
|
110
|
+
persist: true,
|
|
111
|
+
includeInDebugSnapshot: false,
|
|
112
|
+
usedInUi: true,
|
|
113
|
+
},
|
|
114
|
+
quoteStreamComplete: {
|
|
115
|
+
includeInStateLogs: true,
|
|
116
|
+
persist: false,
|
|
117
|
+
includeInDebugSnapshot: false,
|
|
118
|
+
usedInUi: true,
|
|
119
|
+
},
|
|
120
|
+
batchSellTrades: {
|
|
121
|
+
includeInStateLogs: true,
|
|
122
|
+
persist: false,
|
|
123
|
+
includeInDebugSnapshot: false,
|
|
124
|
+
usedInUi: true,
|
|
125
|
+
},
|
|
126
|
+
batchSellTradesLoadingStatus: {
|
|
127
|
+
includeInStateLogs: true,
|
|
128
|
+
persist: false,
|
|
129
|
+
includeInDebugSnapshot: false,
|
|
130
|
+
usedInUi: true,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const QUOTE_ABORT_REASONS = new Set(Object.values(constants_js_1.AbortReason));
|
|
134
|
+
const isExpectedQuoteAbort = (error, signal) => {
|
|
135
|
+
if (signal?.aborted) {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
if (QUOTE_ABORT_REASONS.has(String(error))) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
const errorText = error instanceof Error ? `${error.name} ${error.message}` : String(error);
|
|
142
|
+
return (errorText.includes('AbortError') ||
|
|
143
|
+
errorText.includes('FetchRequestCanceledException'));
|
|
144
|
+
};
|
|
145
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
146
|
+
'updateBridgeQuoteRequestParams',
|
|
147
|
+
'fetchQuotes',
|
|
148
|
+
'updateBatchSellTrades',
|
|
149
|
+
'stopPollingForQuotes',
|
|
150
|
+
'setLocation',
|
|
151
|
+
'getLocation',
|
|
152
|
+
'setInputPrimaryDenomination',
|
|
153
|
+
'resetState',
|
|
154
|
+
'setChainIntervalLength',
|
|
155
|
+
'trackUnifiedSwapBridgeEvent',
|
|
156
|
+
];
|
|
157
|
+
class BridgeController extends (0, polling_controller_1.StaticIntervalPollingController)() {
|
|
158
|
+
constructor({ messenger, state, clientId, clientVersion, getLayer1GasFee, fetchFn, config, trackMetaMetricsFn, traceFn, getUseAssetsControllerForRates, }) {
|
|
159
|
+
super({
|
|
160
|
+
name: bridge_js_1.BRIDGE_CONTROLLER_NAME,
|
|
161
|
+
metadata,
|
|
162
|
+
messenger,
|
|
163
|
+
state: {
|
|
164
|
+
...(0, bridge_js_2.getDefaultBridgeControllerState)(),
|
|
165
|
+
...state,
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
_BridgeController_instances.add(this);
|
|
169
|
+
_BridgeController_abortController.set(this, void 0);
|
|
170
|
+
_BridgeController_batchSellTradesAbortController.set(this, void 0);
|
|
171
|
+
_BridgeController_quotesFirstFetched.set(this, void 0);
|
|
172
|
+
/**
|
|
173
|
+
* Stores the location/entry point from which the user initiated the swap or bridge flow.
|
|
174
|
+
* Set via setLocation() before navigating to the swap/bridge flow.
|
|
175
|
+
* Used as default for all subsequent internal events.
|
|
176
|
+
*/
|
|
177
|
+
_BridgeController_location.set(this, constants_js_1.MetaMetricsSwapsEventSource.Unknown);
|
|
178
|
+
_BridgeController_clientId.set(this, void 0);
|
|
179
|
+
_BridgeController_clientVersion.set(this, void 0);
|
|
180
|
+
_BridgeController_getLayer1GasFee.set(this, void 0);
|
|
181
|
+
_BridgeController_fetchFn.set(this, void 0);
|
|
182
|
+
_BridgeController_trackMetaMetricsFn.set(this, void 0);
|
|
183
|
+
_BridgeController_trace.set(this, void 0);
|
|
184
|
+
_BridgeController_config.set(this, void 0);
|
|
185
|
+
/**
|
|
186
|
+
* Returns whether to use AssetsController for exchange rates.
|
|
187
|
+
* Set via constructor option getUseAssetsControllerForRates; defaults to false.
|
|
188
|
+
*
|
|
189
|
+
* @returns True when exchange rates should be read from AssetsController:getExchangeRatesForBridge.
|
|
190
|
+
*/
|
|
191
|
+
_BridgeController_getUseAssetsControllerForRates.set(this, void 0);
|
|
192
|
+
this._executePoll = async (pollingInput) => {
|
|
193
|
+
await __classPrivateFieldGet(this, _BridgeController_fetchBridgeQuotes, "f").call(this, pollingInput);
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Updates the quote request at the specified index with the given parameters, then starts
|
|
197
|
+
* polling for quotes.
|
|
198
|
+
*
|
|
199
|
+
* @param paramsToUpdate - The parameters to update in the quote request at the specified index
|
|
200
|
+
* @param context - metrics context
|
|
201
|
+
* @param quoteRequestIndex - The index of the quote request to update
|
|
202
|
+
* @param quoteRequestCount - The number of quote requests in the UI
|
|
203
|
+
*/
|
|
204
|
+
this.updateBridgeQuoteRequestParams = async (paramsToUpdate, context, quoteRequestIndex = 0, quoteRequestCount = 1) => {
|
|
205
|
+
// Guard against updating a quote request that doesn't exist
|
|
206
|
+
if (quoteRequestIndex >= quoteRequestCount) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
__classPrivateFieldGet(this, _BridgeController_trackInputChangedEvents, "f").call(this, paramsToUpdate, context.feature_id, quoteRequestIndex);
|
|
210
|
+
this.resetState(constants_js_1.AbortReason.QuoteRequestUpdated, quoteRequestIndex);
|
|
211
|
+
this.update((state) => {
|
|
212
|
+
// Update only the specified quote request and keep the rest of the quote requests unchanged
|
|
213
|
+
state.quoteRequest = state.quoteRequest
|
|
214
|
+
.slice(0, quoteRequestIndex)
|
|
215
|
+
.concat({
|
|
216
|
+
...bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest[0],
|
|
217
|
+
...paramsToUpdate,
|
|
218
|
+
})
|
|
219
|
+
.concat(state.quoteRequest.slice(quoteRequestIndex + 1, quoteRequestCount));
|
|
220
|
+
state.tokenSecurityTypeDestination =
|
|
221
|
+
context.token_security_type_destination ?? null;
|
|
222
|
+
});
|
|
223
|
+
// BatchSell and Unified swaps both use the same polling logic so both validations should pass
|
|
224
|
+
if ((0, quote_request_js_1.isValidQuoteRequest)(paramsToUpdate) &&
|
|
225
|
+
(0, quote_request_js_1.isValidBatchSellQuoteRequest)(this.state.quoteRequest)) {
|
|
226
|
+
__classPrivateFieldSet(this, _BridgeController_quotesFirstFetched, Date.now(), "f");
|
|
227
|
+
// Update the insufficientBal and resetApproval params for the quote request
|
|
228
|
+
const quoteWithInsufficientBalAndResetApproval = await __classPrivateFieldGet(this, _BridgeController_appendInsufficientBalAndResetApproval, "f").call(this, paramsToUpdate);
|
|
229
|
+
this.update((state) => {
|
|
230
|
+
state.quoteRequest[quoteRequestIndex] =
|
|
231
|
+
quoteWithInsufficientBalAndResetApproval;
|
|
232
|
+
});
|
|
233
|
+
// Set refresh rate based on the source chain before starting polling
|
|
234
|
+
this.setChainIntervalLength();
|
|
235
|
+
this.startPolling({
|
|
236
|
+
quoteRequests: this.state.quoteRequest,
|
|
237
|
+
context,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Fetches quotes for specified request without updating the controller state
|
|
243
|
+
* This method does not start polling for quotes and does not emit UnifiedSwapBridge events
|
|
244
|
+
*
|
|
245
|
+
* @param quoteRequest - The parameters for quote requests to fetch
|
|
246
|
+
* @param featureId - The feature ID that maps to quoteParam overrides from LD
|
|
247
|
+
* @param abortSignal - The abort signal to cancel all the requests
|
|
248
|
+
* @returns A list of validated quotes
|
|
249
|
+
*/
|
|
250
|
+
this.fetchQuotes = async (quoteRequest, featureId, abortSignal = null) => {
|
|
251
|
+
const bridgeFeatureFlags = (0, feature_flags_js_1.getBridgeFeatureFlags)(this.messenger);
|
|
252
|
+
const jwt = await __classPrivateFieldGet(this, _BridgeController_getJwt, "f").call(this);
|
|
253
|
+
// If featureId is specified, retrieve the quoteRequestOverrides for that featureId
|
|
254
|
+
const quoteRequestOverrides = featureId
|
|
255
|
+
? bridgeFeatureFlags.quoteRequestOverrides?.[featureId]
|
|
256
|
+
: undefined;
|
|
257
|
+
const resetApproval = await __classPrivateFieldGet(this, _BridgeController_shouldResetApproval, "f").call(this, quoteRequest);
|
|
258
|
+
// If quoteRequestOverrides is specified, merge it with the quoteRequest
|
|
259
|
+
const { quotes: baseQuotes, validationFailures } = await (0, fetch_js_1.fetchBridgeQuotes)(quoteRequestOverrides
|
|
260
|
+
? { ...quoteRequest, ...quoteRequestOverrides, resetApproval }
|
|
261
|
+
: { ...quoteRequest, resetApproval }, abortSignal, __classPrivateFieldGet(this, _BridgeController_clientId, "f"), jwt, __classPrivateFieldGet(this, _BridgeController_fetchFn, "f"), __classPrivateFieldGet(this, _BridgeController_config, "f").customBridgeApiBaseUrl ?? bridge_js_1.BRIDGE_PROD_API_BASE_URL, featureId, __classPrivateFieldGet(this, _BridgeController_clientVersion, "f"));
|
|
262
|
+
__classPrivateFieldGet(this, _BridgeController_trackQuoteValidationFailures, "f").call(this, validationFailures, featureId);
|
|
263
|
+
const srcChainIds = Array.from(new Set(baseQuotes.map((quote) => quote.quote.srcChainId))).filter(Boolean);
|
|
264
|
+
const quotesWithFees = srcChainIds.length > 1 || srcChainIds.length === 0
|
|
265
|
+
? // Don't append fees if there are multiple srcChainIds
|
|
266
|
+
baseQuotes
|
|
267
|
+
: await (0, quote_fees_js_1.appendFeesToQuotes)((0, caip_formatters_js_1.formatChainIdToCaip)(srcChainIds[0]), baseQuotes, this.messenger, __classPrivateFieldGet(this, _BridgeController_getLayer1GasFee, "f"), __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this, quoteRequest.walletAddress));
|
|
268
|
+
return (0, sort_quotes_js_1.sortQuotes)(quotesWithFees, featureId);
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Fetches gasless transaction data and fees for BatchSell quotes.
|
|
272
|
+
* To use this in the clients, add a listener for the recommendedQuotes and call
|
|
273
|
+
* this handler whenever they change.
|
|
274
|
+
*
|
|
275
|
+
* @param quotes - The quotes to fetch the gasless transaction data and fees for
|
|
276
|
+
* @param stxEnabled - Flag to estimate gas cost more precisely for the batch sell feature.
|
|
277
|
+
*/
|
|
278
|
+
this.updateBatchSellTrades = async (quotes, stxEnabled) => {
|
|
279
|
+
__classPrivateFieldGet(this, _BridgeController_batchSellTradesAbortController, "f")?.abort(constants_js_1.AbortReason.GaslessTxBatchFetched);
|
|
280
|
+
__classPrivateFieldSet(this, _BridgeController_batchSellTradesAbortController, new AbortController(), "f");
|
|
281
|
+
this.update((state) => {
|
|
282
|
+
// Set loading status again if recommended quotes are re-ordered
|
|
283
|
+
state.batchSellTradesLoadingStatus = types_js_1.RequestStatus.LOADING;
|
|
284
|
+
});
|
|
285
|
+
try {
|
|
286
|
+
const batchSellTradesResponse = await (0, fetch_js_1.fetchBatchSellTrades)(quotes, stxEnabled, __classPrivateFieldGet(this, _BridgeController_batchSellTradesAbortController, "f").signal, __classPrivateFieldGet(this, _BridgeController_clientId, "f"), await __classPrivateFieldGet(this, _BridgeController_getJwt, "f").call(this), __classPrivateFieldGet(this, _BridgeController_fetchFn, "f"), __classPrivateFieldGet(this, _BridgeController_config, "f").customBridgeApiBaseUrl ?? bridge_js_1.BRIDGE_PROD_API_BASE_URL, __classPrivateFieldGet(this, _BridgeController_clientVersion, "f"));
|
|
287
|
+
this.update((state) => {
|
|
288
|
+
state.batchSellTrades = batchSellTradesResponse;
|
|
289
|
+
state.batchSellTradesLoadingStatus = types_js_1.RequestStatus.FETCHED;
|
|
290
|
+
});
|
|
291
|
+
// TODO if fee.asset.assetId is not in exchange rates, fetch the exchange rate and update the state
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
// Ignore abort errors
|
|
295
|
+
if (error.toString().includes('AbortError') ||
|
|
296
|
+
error.toString().includes('FetchRequestCanceledException') ||
|
|
297
|
+
[
|
|
298
|
+
constants_js_1.AbortReason.ResetState,
|
|
299
|
+
constants_js_1.AbortReason.NewQuoteRequest,
|
|
300
|
+
constants_js_1.AbortReason.QuoteRequestUpdated,
|
|
301
|
+
constants_js_1.AbortReason.TransactionSubmitted,
|
|
302
|
+
constants_js_1.AbortReason.GaslessTxBatchFetched,
|
|
303
|
+
].includes(error)) {
|
|
304
|
+
// Exit the function early to prevent other state updates
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
this.update((state) => {
|
|
308
|
+
// Reset the batch sell trades if the fetch fails to avoid showing stale data
|
|
309
|
+
state.batchSellTrades = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.batchSellTrades;
|
|
310
|
+
// Update loading status
|
|
311
|
+
state.batchSellTradesLoadingStatus = types_js_1.RequestStatus.ERROR;
|
|
312
|
+
});
|
|
313
|
+
console.log(`Failed to fetch batch sell trades`, error);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
_BridgeController_trackQuoteValidationFailures.set(this, (validationFailures, featureId) => {
|
|
317
|
+
if (validationFailures.length === 0) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
this.trackUnifiedSwapBridgeEvent(constants_js_1.UnifiedSwapBridgeEventName.QuotesValidationFailed, {
|
|
321
|
+
feature_id: featureId,
|
|
322
|
+
failures: validationFailures,
|
|
323
|
+
location: __classPrivateFieldGet(this, _BridgeController_location, "f"),
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
/**
|
|
327
|
+
* Fetches the exchange rates for the assets in the quote request if they are not already in the state
|
|
328
|
+
* In addition to the selected tokens, this also fetches the native asset for the source and destination chains
|
|
329
|
+
*
|
|
330
|
+
* @param quoteRequests - The quote requests to fetch the exchange rates for
|
|
331
|
+
*/
|
|
332
|
+
_BridgeController_fetchAssetExchangeRates.set(this, async (quoteRequests) => {
|
|
333
|
+
// Get unique assetIds for all quote requests
|
|
334
|
+
const assetIds = new Set(quoteRequests.flatMap((quoteRequest) => [
|
|
335
|
+
(0, assets_js_1.getAssetIdsForToken)(quoteRequest.srcTokenAddress, quoteRequest.srcChainId),
|
|
336
|
+
(0, assets_js_1.getAssetIdsForToken)(quoteRequest.destTokenAddress, quoteRequest.destChainId),
|
|
337
|
+
].flat()));
|
|
338
|
+
const currency = __classPrivateFieldGet(this, _BridgeController_getUseAssetsControllerForRates, "f").call(this)
|
|
339
|
+
? this.messenger.call('AssetsController:getExchangeRatesForBridge')
|
|
340
|
+
.currentCurrency
|
|
341
|
+
: this.messenger.call('CurrencyRateController:getState').currentCurrency;
|
|
342
|
+
if (assetIds.size === 0) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const pricesByAssetId = await (0, fetch_js_1.fetchAssetPrices)({
|
|
346
|
+
assetIds,
|
|
347
|
+
currencies: new Set([currency, 'usd']),
|
|
348
|
+
clientId: __classPrivateFieldGet(this, _BridgeController_clientId, "f"),
|
|
349
|
+
clientVersion: __classPrivateFieldGet(this, _BridgeController_clientVersion, "f"),
|
|
350
|
+
fetchFn: __classPrivateFieldGet(this, _BridgeController_fetchFn, "f"),
|
|
351
|
+
signal: __classPrivateFieldGet(this, _BridgeController_abortController, "f")?.signal,
|
|
352
|
+
});
|
|
353
|
+
const exchangeRates = (0, assets_js_1.toExchangeRates)(currency, pricesByAssetId);
|
|
354
|
+
this.update((state) => {
|
|
355
|
+
state.assetExchangeRates = {
|
|
356
|
+
...state.assetExchangeRates,
|
|
357
|
+
...exchangeRates,
|
|
358
|
+
};
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
_BridgeController_hasInsufficientBalance.set(this, async (quoteRequest) => {
|
|
362
|
+
try {
|
|
363
|
+
const srcChainIdInHex = (0, caip_formatters_js_1.formatChainIdToHex)(quoteRequest.srcChainId);
|
|
364
|
+
const provider = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getNetworkClientByChainId).call(this, srcChainIdInHex)?.provider;
|
|
365
|
+
const normalizedSrcTokenAddress = (0, caip_formatters_js_1.formatAddressToCaipReference)(quoteRequest.srcTokenAddress);
|
|
366
|
+
return !(provider &&
|
|
367
|
+
normalizedSrcTokenAddress &&
|
|
368
|
+
quoteRequest.srcTokenAmount &&
|
|
369
|
+
srcChainIdInHex &&
|
|
370
|
+
(await (0, balance_js_1.hasSufficientBalance)(provider, quoteRequest.walletAddress, normalizedSrcTokenAddress, quoteRequest.srcTokenAmount, srcChainIdInHex)));
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
console.warn('Failed to set insufficientBal', error);
|
|
374
|
+
// Fall back to true so the backend returns quotes
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
_BridgeController_appendInsufficientBalAndResetApproval.set(this, async (quoteRequest) => {
|
|
379
|
+
const isSrcChainNonEVM = (0, bridge_js_2.isNonEvmChainId)(quoteRequest.srcChainId);
|
|
380
|
+
const providerConfig = isSrcChainNonEVM
|
|
381
|
+
? undefined
|
|
382
|
+
: __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getNetworkClientByChainId).call(this, (0, caip_formatters_js_1.formatChainIdToHex)(quoteRequest.srcChainId))?.configuration;
|
|
383
|
+
let insufficientBal;
|
|
384
|
+
let resetApproval = Boolean(quoteRequest.resetApproval);
|
|
385
|
+
if (isSrcChainNonEVM) {
|
|
386
|
+
// If the source chain is not an EVM network, use value from params
|
|
387
|
+
insufficientBal = quoteRequest.insufficientBal;
|
|
388
|
+
}
|
|
389
|
+
else if (providerConfig?.rpcUrl?.includes('tenderly')) {
|
|
390
|
+
// If the rpcUrl is a tenderly fork (e2e tests), set insufficientBal=true
|
|
391
|
+
// The bridge-api filters out quotes if the balance on mainnet is insufficient so this override allows quotes to always be returned
|
|
392
|
+
insufficientBal = true;
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
// Set loading status if RPC calls are made before the quotes are fetched
|
|
396
|
+
this.update((state) => {
|
|
397
|
+
state.quotesLoadingStatus = types_js_1.RequestStatus.LOADING;
|
|
398
|
+
});
|
|
399
|
+
resetApproval = await __classPrivateFieldGet(this, _BridgeController_shouldResetApproval, "f").call(this, quoteRequest);
|
|
400
|
+
// Otherwise query the src token balance from the RPC provider
|
|
401
|
+
insufficientBal =
|
|
402
|
+
quoteRequest.insufficientBal ??
|
|
403
|
+
(await __classPrivateFieldGet(this, _BridgeController_hasInsufficientBalance, "f").call(this, quoteRequest));
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
...quoteRequest,
|
|
407
|
+
insufficientBal,
|
|
408
|
+
resetApproval,
|
|
409
|
+
};
|
|
410
|
+
});
|
|
411
|
+
_BridgeController_shouldResetApproval.set(this, async (quoteRequest) => {
|
|
412
|
+
if ((0, bridge_js_2.isNonEvmChainId)(quoteRequest.srcChainId)) {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
try {
|
|
416
|
+
const normalizedSrcTokenAddress = (0, caip_formatters_js_1.formatAddressToCaipReference)(quoteRequest.srcTokenAddress);
|
|
417
|
+
if ((0, bridge_js_2.isEthUsdt)(quoteRequest.srcChainId, normalizedSrcTokenAddress)) {
|
|
418
|
+
const allowance = bignumber_1.BigNumber.from(await __classPrivateFieldGet(this, _BridgeController_getUSDTMainnetAllowance, "f").call(this, quoteRequest.walletAddress, normalizedSrcTokenAddress, quoteRequest.destChainId));
|
|
419
|
+
return allowance.lt(quoteRequest.srcTokenAmount) && allowance.gt(0);
|
|
420
|
+
}
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
console.warn('Failed to set resetApproval', error);
|
|
425
|
+
// Fall back to true so the backend returns quotes
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
this.stopPollingForQuotes = (reason, context) => {
|
|
430
|
+
this.stopAllPolling();
|
|
431
|
+
// If polling is stopped before quotes finish loading, track QuotesReceived
|
|
432
|
+
if (this.state.quotesLoadingStatus === types_js_1.RequestStatus.LOADING && context) {
|
|
433
|
+
this.trackUnifiedSwapBridgeEvent(constants_js_1.UnifiedSwapBridgeEventName.QuotesReceived, context);
|
|
434
|
+
}
|
|
435
|
+
// Clears quotes list in state
|
|
436
|
+
__classPrivateFieldGet(this, _BridgeController_abortController, "f")?.abort(reason);
|
|
437
|
+
__classPrivateFieldGet(this, _BridgeController_batchSellTradesAbortController, "f")?.abort(reason);
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* Sets the location/entry point for the current swap or bridge flow.
|
|
441
|
+
* Call this when the user enters the flow so that all internally-fired
|
|
442
|
+
* events (InputChanged, QuotesRequested, etc.) carry the correct location.
|
|
443
|
+
*
|
|
444
|
+
* @param location - The entry point from which the user initiated the flow
|
|
445
|
+
*/
|
|
446
|
+
this.setLocation = (location) => {
|
|
447
|
+
__classPrivateFieldSet(this, _BridgeController_location, location, "f");
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Returns the location/entry point for the current swap or bridge flow.
|
|
451
|
+
*
|
|
452
|
+
* @returns The entry point from which the user initiated the flow
|
|
453
|
+
*/
|
|
454
|
+
this.getLocation = () => {
|
|
455
|
+
return __classPrivateFieldGet(this, _BridgeController_location, "f");
|
|
456
|
+
};
|
|
457
|
+
this.setInputPrimaryDenomination = (inputPrimaryDenomination) => {
|
|
458
|
+
this.update((state) => {
|
|
459
|
+
state.inputPrimaryDenomination = inputPrimaryDenomination;
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
this.resetState = (reason = constants_js_1.AbortReason.ResetState, quoteRequestIndex = null, context) => {
|
|
463
|
+
this.stopPollingForQuotes(reason, context);
|
|
464
|
+
this.update((state) => {
|
|
465
|
+
// Cannot do direct assignment to state, i.e. state = {... }, need to manually assign each field
|
|
466
|
+
if (quoteRequestIndex === null) {
|
|
467
|
+
// Clear all requests if index is null
|
|
468
|
+
state.quoteRequest = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
// Otherwise only clear the specified request
|
|
472
|
+
state.quoteRequest = state.quoteRequest
|
|
473
|
+
.slice(0, quoteRequestIndex)
|
|
474
|
+
.concat(bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteRequest[0])
|
|
475
|
+
.concat(state.quoteRequest.slice(quoteRequestIndex + 1));
|
|
476
|
+
}
|
|
477
|
+
state.quotesInitialLoadTime =
|
|
478
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotesInitialLoadTime;
|
|
479
|
+
state.quotes = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;
|
|
480
|
+
state.quotesLastFetched =
|
|
481
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLastFetched;
|
|
482
|
+
state.quotesLoadingStatus =
|
|
483
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotesLoadingStatus;
|
|
484
|
+
state.quoteFetchError = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;
|
|
485
|
+
state.quotesRefreshCount =
|
|
486
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotesRefreshCount;
|
|
487
|
+
state.assetExchangeRates =
|
|
488
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.assetExchangeRates;
|
|
489
|
+
state.minimumBalanceForRentExemptionInLamports =
|
|
490
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.minimumBalanceForRentExemptionInLamports;
|
|
491
|
+
state.tokenWarnings = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.tokenWarnings;
|
|
492
|
+
state.tokenSecurityTypeDestination =
|
|
493
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.tokenSecurityTypeDestination;
|
|
494
|
+
state.quoteStreamComplete =
|
|
495
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteStreamComplete;
|
|
496
|
+
state.batchSellTrades = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.batchSellTrades;
|
|
497
|
+
state.batchSellTradesLoadingStatus =
|
|
498
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.batchSellTradesLoadingStatus;
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Sets the interval length based on the source chain
|
|
503
|
+
*/
|
|
504
|
+
this.setChainIntervalLength = () => {
|
|
505
|
+
const { state } = this;
|
|
506
|
+
// Assume that BatchSell quote requests all have the same source chain
|
|
507
|
+
// Use the first one to determine refresh rate
|
|
508
|
+
const { srcChainId } = state.quoteRequest[0];
|
|
509
|
+
const bridgeFeatureFlags = (0, feature_flags_js_1.getBridgeFeatureFlags)(this.messenger);
|
|
510
|
+
const refreshRateOverride = srcChainId
|
|
511
|
+
? bridgeFeatureFlags.chains[(0, caip_formatters_js_1.formatChainIdToCaip)(srcChainId)]?.refreshRate
|
|
512
|
+
: undefined;
|
|
513
|
+
const defaultRefreshRate = bridgeFeatureFlags.refreshRate;
|
|
514
|
+
this.setIntervalLength(refreshRateOverride ?? defaultRefreshRate);
|
|
515
|
+
};
|
|
516
|
+
_BridgeController_fetchBridgeQuotes.set(this, async ({ quoteRequests, context, }) => {
|
|
517
|
+
__classPrivateFieldGet(this, _BridgeController_abortController, "f")?.abort(constants_js_1.AbortReason.NewQuoteRequest);
|
|
518
|
+
__classPrivateFieldGet(this, _BridgeController_batchSellTradesAbortController, "f")?.abort(constants_js_1.AbortReason.NewQuoteRequest);
|
|
519
|
+
__classPrivateFieldSet(this, _BridgeController_abortController, new AbortController(), "f");
|
|
520
|
+
const quoteTraceStartTime = Date.now();
|
|
521
|
+
const quoteTraceRequestId = (0, uuid_1.v4)();
|
|
522
|
+
const quoteAbortSignal = __classPrivateFieldGet(this, _BridgeController_abortController, "f").signal;
|
|
523
|
+
__classPrivateFieldGet(this, _BridgeController_fetchAssetExchangeRates, "f").call(this, quoteRequests).catch((error) => console.warn('Failed to fetch asset exchange rates', error));
|
|
524
|
+
this.trackUnifiedSwapBridgeEvent(constants_js_1.UnifiedSwapBridgeEventName.QuotesRequested, context);
|
|
525
|
+
const { sse, maxRefreshCount } = (0, feature_flags_js_1.getBridgeFeatureFlags)(this.messenger);
|
|
526
|
+
const shouldStream = sse?.enabled &&
|
|
527
|
+
(0, feature_flags_js_1.hasMinimumRequiredVersion)(__classPrivateFieldGet(this, _BridgeController_clientVersion, "f"), sse.minimumVersion);
|
|
528
|
+
const isBatchSellRequest = quoteRequests.length > 1;
|
|
529
|
+
this.update((state) => {
|
|
530
|
+
state.quoteFetchError = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteFetchError;
|
|
531
|
+
state.tokenWarnings = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.tokenWarnings;
|
|
532
|
+
state.quoteStreamComplete =
|
|
533
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quoteStreamComplete;
|
|
534
|
+
state.quotesLastFetched = Date.now();
|
|
535
|
+
state.quotesLoadingStatus = types_js_1.RequestStatus.LOADING;
|
|
536
|
+
// Prevent clients from displaying stale batch sell fees
|
|
537
|
+
if (quoteRequests.length > 1) {
|
|
538
|
+
state.batchSellTradesLoadingStatus = types_js_1.RequestStatus.LOADING;
|
|
539
|
+
state.batchSellTrades = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.batchSellTrades;
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
const jwt = await __classPrivateFieldGet(this, _BridgeController_getJwt, "f").call(this);
|
|
543
|
+
const [firstQuoteRequest] = quoteRequests;
|
|
544
|
+
let traceResult = 'error';
|
|
545
|
+
let traceName = traces_js_1.TraceName.BatchSellQuotesFetched;
|
|
546
|
+
if (!isBatchSellRequest) {
|
|
547
|
+
traceName = (0, bridge_js_2.isCrossChain)(firstQuoteRequest.srcChainId, firstQuoteRequest.destChainId)
|
|
548
|
+
? traces_js_1.TraceName.BridgeQuotesFetched
|
|
549
|
+
: traces_js_1.TraceName.SwapQuotesFetched;
|
|
550
|
+
}
|
|
551
|
+
const tracedProviders = new Set();
|
|
552
|
+
const traceWithoutImpact = async (request) => {
|
|
553
|
+
try {
|
|
554
|
+
await __classPrivateFieldGet(this, _BridgeController_trace, "f").call(this, request, () => undefined);
|
|
555
|
+
}
|
|
556
|
+
catch {
|
|
557
|
+
// Telemetry failures must not affect quote fetching or state updates.
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
const traceProviderFirstResult = (providerData) => {
|
|
561
|
+
const provider = (0, properties_js_1.formatProviderLabel)(providerData);
|
|
562
|
+
if (isBatchSellRequest || tracedProviders.has(provider)) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
tracedProviders.add(provider);
|
|
566
|
+
// Provider telemetry must not delay quote processing.
|
|
567
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
568
|
+
traceWithoutImpact({
|
|
569
|
+
name: traces_js_1.TraceName.QuoteProviderFirstResult,
|
|
570
|
+
startTime: quoteTraceStartTime,
|
|
571
|
+
data: {
|
|
572
|
+
provider,
|
|
573
|
+
feature_id: context.feature_id,
|
|
574
|
+
request_id: quoteTraceRequestId,
|
|
575
|
+
swap_type: (0, properties_js_1.getSwapType)(firstQuoteRequest.srcChainId, firstQuoteRequest.destChainId),
|
|
576
|
+
srcChainId: (0, caip_formatters_js_1.formatChainIdToCaip)(firstQuoteRequest.srcChainId),
|
|
577
|
+
destChainId: (0, caip_formatters_js_1.formatChainIdToCaip)(firstQuoteRequest.destChainId),
|
|
578
|
+
result: 'success',
|
|
579
|
+
},
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
try {
|
|
583
|
+
const selectedAccount = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this, firstQuoteRequest.walletAddress);
|
|
584
|
+
// This call is not awaited to prevent blocking quote fetching if the snap takes too long to respond
|
|
585
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
586
|
+
__classPrivateFieldGet(this, _BridgeController_setMinimumBalanceForRentExemptionInLamports, "f").call(this, firstQuoteRequest.srcChainId, selectedAccount?.metadata?.snap?.id);
|
|
587
|
+
// Use SSE if enabled and return early
|
|
588
|
+
if (shouldStream || isBatchSellRequest) {
|
|
589
|
+
const quoteCount = await __classPrivateFieldGet(this, _BridgeController_handleQuoteStreaming, "f").call(this, {
|
|
590
|
+
quoteRequests,
|
|
591
|
+
featureId: context.feature_id,
|
|
592
|
+
jwt,
|
|
593
|
+
selectedAccount,
|
|
594
|
+
signal: quoteAbortSignal,
|
|
595
|
+
traceProviderFirstResult,
|
|
596
|
+
});
|
|
597
|
+
if (quoteAbortSignal.aborted) {
|
|
598
|
+
traceResult = 'cancelled';
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
traceResult = quoteCount > 0 ? 'success' : 'no_quotes';
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
// Otherwise use regular fetch
|
|
605
|
+
const quotes = await this.fetchQuotes(firstQuoteRequest, context.feature_id, quoteAbortSignal);
|
|
606
|
+
for (const quote of quotes) {
|
|
607
|
+
traceProviderFirstResult(quote.quote);
|
|
608
|
+
}
|
|
609
|
+
this.update((state) => {
|
|
610
|
+
// Set the initial load time if this is the first fetch
|
|
611
|
+
if (state.quotesRefreshCount ===
|
|
612
|
+
bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotesRefreshCount &&
|
|
613
|
+
__classPrivateFieldGet(this, _BridgeController_quotesFirstFetched, "f")) {
|
|
614
|
+
state.quotesInitialLoadTime = Date.now() - __classPrivateFieldGet(this, _BridgeController_quotesFirstFetched, "f");
|
|
615
|
+
}
|
|
616
|
+
state.quotes = quotes.map(quote_response_v1_to_v2_js_1.toQuoteResponseV2);
|
|
617
|
+
state.quotesLoadingStatus = types_js_1.RequestStatus.FETCHED;
|
|
618
|
+
});
|
|
619
|
+
traceResult = quotes.length > 0 ? 'success' : 'no_quotes';
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
catch (error) {
|
|
623
|
+
// Reset the quotes list if the fetch fails to avoid showing stale quotes
|
|
624
|
+
this.update((state) => {
|
|
625
|
+
state.quotes = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;
|
|
626
|
+
});
|
|
627
|
+
// Ignore abort errors
|
|
628
|
+
if (isExpectedQuoteAbort(error, quoteAbortSignal)) {
|
|
629
|
+
traceResult = 'cancelled';
|
|
630
|
+
// Exit the function early to prevent other state updates
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
// Update loading status and error message
|
|
634
|
+
this.update((state) => {
|
|
635
|
+
// The error object reference is not guaranteed to exist on mobile so reading
|
|
636
|
+
// the message directly could cause an error.
|
|
637
|
+
let errorMessage;
|
|
638
|
+
try {
|
|
639
|
+
errorMessage =
|
|
640
|
+
error?.message ?? error.toString();
|
|
641
|
+
}
|
|
642
|
+
catch {
|
|
643
|
+
// Intentionally empty
|
|
644
|
+
}
|
|
645
|
+
finally {
|
|
646
|
+
state.quoteFetchError = errorMessage ?? 'Unknown error';
|
|
647
|
+
}
|
|
648
|
+
state.quotesLoadingStatus = types_js_1.RequestStatus.ERROR;
|
|
649
|
+
});
|
|
650
|
+
// Track event and log error
|
|
651
|
+
this.trackUnifiedSwapBridgeEvent(constants_js_1.UnifiedSwapBridgeEventName.QuotesError, context);
|
|
652
|
+
console.log(`Failed to ${shouldStream ? 'stream' : 'fetch'} bridge quotes`, error);
|
|
653
|
+
}
|
|
654
|
+
finally {
|
|
655
|
+
await traceWithoutImpact({
|
|
656
|
+
name: traceName,
|
|
657
|
+
startTime: quoteTraceStartTime,
|
|
658
|
+
data: {
|
|
659
|
+
srcChainId: (0, caip_formatters_js_1.formatChainIdToCaip)(firstQuoteRequest.srcChainId),
|
|
660
|
+
destChainId: (0, caip_formatters_js_1.formatChainIdToCaip)(firstQuoteRequest.destChainId),
|
|
661
|
+
...(!isBatchSellRequest && {
|
|
662
|
+
request_id: quoteTraceRequestId,
|
|
663
|
+
feature_id: context.feature_id,
|
|
664
|
+
result: traceResult,
|
|
665
|
+
}),
|
|
666
|
+
},
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
// Update refresh count after fetching, validation and fee calculation have completed
|
|
670
|
+
this.update((state) => {
|
|
671
|
+
state.quotesRefreshCount += 1;
|
|
672
|
+
});
|
|
673
|
+
const hasNoFundedQuoteRequests = quoteRequests.every(({ insufficientBal }) => Boolean(insufficientBal));
|
|
674
|
+
if (hasNoFundedQuoteRequests
|
|
675
|
+
? // If all quote requests are insufficiently funded, stop polling
|
|
676
|
+
// So if a BatchSell has at least 1 sufficiently funded quote request, polling continues
|
|
677
|
+
true
|
|
678
|
+
: // Otherwise continue polling until the maximum number of refreshes has been reached
|
|
679
|
+
this.state.quotesRefreshCount >= maxRefreshCount) {
|
|
680
|
+
this.stopAllPolling();
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
_BridgeController_handleQuoteStreaming.set(this, async ({ quoteRequests, featureId, jwt, selectedAccount, signal, traceProviderFirstResult, }) => {
|
|
684
|
+
/**
|
|
685
|
+
* Tracks the number of valid quotes received from the current stream, which is used
|
|
686
|
+
* to determine when to clear the quotes list and set the initial load time
|
|
687
|
+
*/
|
|
688
|
+
let validQuotesCounter = 0;
|
|
689
|
+
/**
|
|
690
|
+
* Tracks all pending promises from appendFeesToQuotes calls to ensure they complete
|
|
691
|
+
* before setting quotesLoadingStatus to FETCHED
|
|
692
|
+
*/
|
|
693
|
+
const pendingFeeAppendPromises = new Set();
|
|
694
|
+
await (0, fetch_js_1.fetchBridgeQuoteStream)(__classPrivateFieldGet(this, _BridgeController_fetchFn, "f"), quoteRequests, signal, featureId, __classPrivateFieldGet(this, _BridgeController_clientId, "f"), jwt, __classPrivateFieldGet(this, _BridgeController_config, "f").customBridgeApiBaseUrl ?? bridge_js_1.BRIDGE_PROD_API_BASE_URL, {
|
|
695
|
+
onQuoteValidationFailure: (validationFailures) => __classPrivateFieldGet(this, _BridgeController_trackQuoteValidationFailures, "f").call(this, validationFailures, featureId),
|
|
696
|
+
onValidQuoteReceived: async (quote) => {
|
|
697
|
+
const feeAppendPromise = (async () => {
|
|
698
|
+
const quotesWithFees = await (0, quote_fees_js_1.appendFeesToQuotes)(quote.chainId, [quote], this.messenger, __classPrivateFieldGet(this, _BridgeController_getLayer1GasFee, "f"), selectedAccount);
|
|
699
|
+
if (quotesWithFees.length > 0) {
|
|
700
|
+
validQuotesCounter += 1;
|
|
701
|
+
traceProviderFirstResult(quote.quote);
|
|
702
|
+
}
|
|
703
|
+
this.update((state) => {
|
|
704
|
+
// Clear previous quotes and quotes load time when first quote in the current
|
|
705
|
+
// polling loop is received
|
|
706
|
+
// This enables clients to continue showing the previous quotes while new
|
|
707
|
+
// quotes are loading
|
|
708
|
+
// Note: If there are no valid quotes until the 2nd fetch, quotesInitialLoadTime will be > refreshRate
|
|
709
|
+
if (validQuotesCounter === 1) {
|
|
710
|
+
state.quotes = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;
|
|
711
|
+
if (!state.quotesInitialLoadTime && __classPrivateFieldGet(this, _BridgeController_quotesFirstFetched, "f")) {
|
|
712
|
+
// Set the initial load time after the first quote is received
|
|
713
|
+
state.quotesInitialLoadTime =
|
|
714
|
+
Date.now() - __classPrivateFieldGet(this, _BridgeController_quotesFirstFetched, "f");
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
state.quotes = [...state.quotes, ...quotesWithFees];
|
|
718
|
+
});
|
|
719
|
+
})();
|
|
720
|
+
pendingFeeAppendPromises.add(feeAppendPromise);
|
|
721
|
+
feeAppendPromise
|
|
722
|
+
.catch((error) => {
|
|
723
|
+
// Catch errors to prevent them from breaking stream processing
|
|
724
|
+
// If appendFeesToQuotes throws, the state update never happens, so no invalid entry is added
|
|
725
|
+
console.error('Error appending fees to quote', error);
|
|
726
|
+
})
|
|
727
|
+
.finally(() => {
|
|
728
|
+
pendingFeeAppendPromises.delete(feeAppendPromise);
|
|
729
|
+
});
|
|
730
|
+
// Await the promise to ensure errors are caught and handled before continuing
|
|
731
|
+
// The promise is also tracked in pendingFeeAppendPromises for onClose to wait for
|
|
732
|
+
await feeAppendPromise;
|
|
733
|
+
},
|
|
734
|
+
onTokenWarning: (warning) => {
|
|
735
|
+
this.update((state) => {
|
|
736
|
+
const isDuplicate = state.tokenWarnings.some((existing) => existing.feature_id === warning.feature_id);
|
|
737
|
+
if (!isDuplicate) {
|
|
738
|
+
state.tokenWarnings = [...state.tokenWarnings, warning];
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
},
|
|
742
|
+
onComplete: (data) => {
|
|
743
|
+
this.update((state) => {
|
|
744
|
+
state.quoteStreamComplete = data;
|
|
745
|
+
});
|
|
746
|
+
},
|
|
747
|
+
onClose: async () => {
|
|
748
|
+
// Wait for all pending appendFeesToQuotes operations to complete
|
|
749
|
+
// before setting quotesLoadingStatus to FETCHED
|
|
750
|
+
await Promise.allSettled(Array.from(pendingFeeAppendPromises));
|
|
751
|
+
this.update((state) => {
|
|
752
|
+
// If there are no valid quotes in the current stream, clear the quotes list
|
|
753
|
+
// to remove quotes from the previous stream
|
|
754
|
+
if (validQuotesCounter === 0) {
|
|
755
|
+
state.quotes = bridge_js_1.DEFAULT_BRIDGE_CONTROLLER_STATE.quotes;
|
|
756
|
+
}
|
|
757
|
+
state.quotesLoadingStatus = types_js_1.RequestStatus.FETCHED;
|
|
758
|
+
});
|
|
759
|
+
},
|
|
760
|
+
}, __classPrivateFieldGet(this, _BridgeController_clientVersion, "f"));
|
|
761
|
+
return validQuotesCounter;
|
|
762
|
+
});
|
|
763
|
+
_BridgeController_setMinimumBalanceForRentExemptionInLamports.set(this, async (srcChainId, snapId) => {
|
|
764
|
+
if (!(0, bridge_js_2.isSolanaChainId)(srcChainId) || !snapId) {
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
const minimumBalanceForRentExemptionInLamports = await (0, snaps_js_1.getMinimumBalanceForRentExemptionInLamports)(snapId, this.messenger);
|
|
768
|
+
this.update((state) => {
|
|
769
|
+
state.minimumBalanceForRentExemptionInLamports =
|
|
770
|
+
minimumBalanceForRentExemptionInLamports;
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
_BridgeController_getJwt.set(this, async () => {
|
|
774
|
+
try {
|
|
775
|
+
const token = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
776
|
+
return token;
|
|
777
|
+
}
|
|
778
|
+
catch (error) {
|
|
779
|
+
console.error('Error getting JWT token for bridge-api request', error);
|
|
780
|
+
return undefined;
|
|
781
|
+
}
|
|
782
|
+
});
|
|
783
|
+
_BridgeController_getRequestMetadata.set(this, (quoteRequestIndex = 0) => {
|
|
784
|
+
const quoteRequest = this.state.quoteRequest[quoteRequestIndex];
|
|
785
|
+
const { walletAddress } = quoteRequest;
|
|
786
|
+
const accountHardwareType = (0, properties_js_1.getAccountHardwareType)(walletAddress
|
|
787
|
+
? __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getMultichainSelectedAccount).call(this, walletAddress)
|
|
788
|
+
: undefined);
|
|
789
|
+
return {
|
|
790
|
+
slippage_limit: quoteRequest.slippage ?? 0,
|
|
791
|
+
swap_type: (0, properties_js_1.getSwapTypeFromQuote)(quoteRequest),
|
|
792
|
+
custom_slippage: (0, properties_js_1.isCustomSlippage)(quoteRequest.slippage),
|
|
793
|
+
account_hardware_type: accountHardwareType,
|
|
794
|
+
is_hardware_wallet: accountHardwareType !== null,
|
|
795
|
+
};
|
|
796
|
+
});
|
|
797
|
+
_BridgeController_getQuoteFetchData.set(this, () => {
|
|
798
|
+
return {
|
|
799
|
+
quotes_count: this.state.quotes.length,
|
|
800
|
+
quotes_list: this.state.quotes.map(({ quote }) => (0, properties_js_1.formatProviderLabel)(quote)),
|
|
801
|
+
initial_load_time_all_quotes: this.state.quotesInitialLoadTime ?? 0,
|
|
802
|
+
has_gas_included_quote: this.state.quotes.some(({ quote }) => quote.gasIncluded),
|
|
803
|
+
};
|
|
804
|
+
});
|
|
805
|
+
_BridgeController_getEventProperties.set(this, (eventName, propertiesFromClient, quoteRequestIndex = 0) => {
|
|
806
|
+
const clientProps = propertiesFromClient;
|
|
807
|
+
const baseProperties = {
|
|
808
|
+
...propertiesFromClient,
|
|
809
|
+
location: clientProps?.location ?? __classPrivateFieldGet(this, _BridgeController_location, "f"),
|
|
810
|
+
action_type: constants_js_1.MetricsActionType.SWAPBRIDGE_V1,
|
|
811
|
+
};
|
|
812
|
+
const inputPrimaryDenominationProperties = {
|
|
813
|
+
input_primary_denomination: this.state.inputPrimaryDenomination,
|
|
814
|
+
};
|
|
815
|
+
const batchSellClientChainProperties = propertiesFromClient;
|
|
816
|
+
const batchSellBaseProperties = {
|
|
817
|
+
chain_id_source: batchSellClientChainProperties.chain_id_source,
|
|
818
|
+
chain_id_destination: batchSellClientChainProperties.chain_id_destination,
|
|
819
|
+
location: clientProps?.location ?? __classPrivateFieldGet(this, _BridgeController_location, "f"),
|
|
820
|
+
};
|
|
821
|
+
const quoteRequest = this.state.quoteRequest[quoteRequestIndex];
|
|
822
|
+
switch (eventName) {
|
|
823
|
+
case constants_js_1.UnifiedSwapBridgeEventName.ButtonClicked:
|
|
824
|
+
return {
|
|
825
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
826
|
+
...baseProperties,
|
|
827
|
+
};
|
|
828
|
+
case constants_js_1.UnifiedSwapBridgeEventName.PageViewed:
|
|
829
|
+
return {
|
|
830
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
831
|
+
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
832
|
+
...inputPrimaryDenominationProperties,
|
|
833
|
+
...baseProperties,
|
|
834
|
+
};
|
|
835
|
+
case constants_js_1.BatchSellMetricsEventName.BatchSellTokenPageViewed:
|
|
836
|
+
return batchSellBaseProperties;
|
|
837
|
+
case constants_js_1.BatchSellMetricsEventName.BatchSellTokenPageContinueClicked: {
|
|
838
|
+
const propsFromClient = propertiesFromClient;
|
|
839
|
+
return {
|
|
840
|
+
...batchSellBaseProperties,
|
|
841
|
+
source_token_count: propsFromClient.source_token_addresses.length,
|
|
842
|
+
source_token_symbols: propsFromClient.source_token_symbols,
|
|
843
|
+
source_token_addresses: propsFromClient.source_token_addresses,
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
case constants_js_1.BatchSellMetricsEventName.BatchSellQuotePageViewed:
|
|
847
|
+
case constants_js_1.BatchSellMetricsEventName.BatchSellQuotePageReviewClicked: {
|
|
848
|
+
const propsFromClient = propertiesFromClient;
|
|
849
|
+
return {
|
|
850
|
+
...batchSellBaseProperties,
|
|
851
|
+
source_token_count: propsFromClient.source_token_addresses.length,
|
|
852
|
+
source_token_symbols: propsFromClient.source_token_symbols,
|
|
853
|
+
source_token_addresses: propsFromClient.source_token_addresses,
|
|
854
|
+
destination_token_symbol: propsFromClient.destination_token_symbol,
|
|
855
|
+
destination_token_address: propsFromClient.destination_token_address,
|
|
856
|
+
usd_amount_source_tokens: propsFromClient.usd_amount_source_tokens,
|
|
857
|
+
usd_amount_source_total: propsFromClient.usd_amount_source_total,
|
|
858
|
+
source_token_slippages: propsFromClient.source_token_slippages,
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
case constants_js_1.BatchSellMetricsEventName.BatchSellReviewModalSubmitted: {
|
|
862
|
+
const reviewModalProperties = propertiesFromClient;
|
|
863
|
+
return {
|
|
864
|
+
...batchSellBaseProperties,
|
|
865
|
+
source_token_count: reviewModalProperties.source_token_addresses.length,
|
|
866
|
+
source_token_symbols: reviewModalProperties.source_token_symbols,
|
|
867
|
+
source_token_addresses: reviewModalProperties.source_token_addresses,
|
|
868
|
+
destination_token_symbol: reviewModalProperties.destination_token_symbol,
|
|
869
|
+
destination_token_address: reviewModalProperties.destination_token_address,
|
|
870
|
+
usd_amount_source_tokens: reviewModalProperties.usd_amount_source_tokens,
|
|
871
|
+
usd_amount_source_total: reviewModalProperties.usd_amount_source_total,
|
|
872
|
+
source_token_slippages: reviewModalProperties.source_token_slippages,
|
|
873
|
+
usd_quoted_gas: reviewModalProperties.usd_quoted_gas,
|
|
874
|
+
usd_quoted_return: reviewModalProperties.usd_quoted_return,
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
case constants_js_1.UnifiedSwapBridgeEventName.FiatCryptoToggleClicked:
|
|
878
|
+
return {
|
|
879
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
880
|
+
swap_type: (0, properties_js_1.getSwapTypeFromQuote)(quoteRequest),
|
|
881
|
+
...baseProperties,
|
|
882
|
+
};
|
|
883
|
+
case constants_js_1.UnifiedSwapBridgeEventName.QuotesValidationFailed:
|
|
884
|
+
return {
|
|
885
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
886
|
+
refresh_count: this.state.quotesRefreshCount,
|
|
887
|
+
...baseProperties,
|
|
888
|
+
};
|
|
889
|
+
case constants_js_1.UnifiedSwapBridgeEventName.QuotesReceived:
|
|
890
|
+
return {
|
|
891
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
892
|
+
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
893
|
+
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
894
|
+
refresh_count: this.state.quotesRefreshCount,
|
|
895
|
+
has_sufficient_funds: !quoteRequest.insufficientBal,
|
|
896
|
+
...inputPrimaryDenominationProperties,
|
|
897
|
+
...baseProperties,
|
|
898
|
+
};
|
|
899
|
+
case constants_js_1.UnifiedSwapBridgeEventName.QuotesRequested:
|
|
900
|
+
return {
|
|
901
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
902
|
+
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
903
|
+
has_sufficient_funds: !quoteRequest.insufficientBal,
|
|
904
|
+
...inputPrimaryDenominationProperties,
|
|
905
|
+
...baseProperties,
|
|
906
|
+
};
|
|
907
|
+
case constants_js_1.UnifiedSwapBridgeEventName.QuotesError:
|
|
908
|
+
return {
|
|
909
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
910
|
+
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
911
|
+
error_message: this.state.quoteFetchError,
|
|
912
|
+
has_sufficient_funds: !quoteRequest.insufficientBal,
|
|
913
|
+
...baseProperties,
|
|
914
|
+
};
|
|
915
|
+
case constants_js_1.UnifiedSwapBridgeEventName.AllQuotesOpened:
|
|
916
|
+
case constants_js_1.UnifiedSwapBridgeEventName.AllQuotesSorted:
|
|
917
|
+
case constants_js_1.UnifiedSwapBridgeEventName.QuoteSelected:
|
|
918
|
+
return {
|
|
919
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
920
|
+
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
921
|
+
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
922
|
+
...baseProperties,
|
|
923
|
+
};
|
|
924
|
+
case constants_js_1.UnifiedSwapBridgeEventName.Failed: {
|
|
925
|
+
// Populate the properties that the error occurred before the tx was submitted
|
|
926
|
+
return {
|
|
927
|
+
...baseProperties,
|
|
928
|
+
...(0, properties_js_1.getRequestParams)(quoteRequest, this.state.tokenSecurityTypeDestination),
|
|
929
|
+
...__classPrivateFieldGet(this, _BridgeController_getRequestMetadata, "f").call(this),
|
|
930
|
+
...__classPrivateFieldGet(this, _BridgeController_getQuoteFetchData, "f").call(this),
|
|
931
|
+
...propertiesFromClient,
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
case constants_js_1.UnifiedSwapBridgeEventName.AssetDetailTooltipClicked:
|
|
935
|
+
case constants_js_1.UnifiedSwapBridgeEventName.AssetPickerOpened:
|
|
936
|
+
return baseProperties;
|
|
937
|
+
// Inject `token_security_type_destination` from controller state so the
|
|
938
|
+
// field is always present on this event. `baseProperties` (which spreads
|
|
939
|
+
// `propertiesFromClient`) wins if the client supplies a value explicitly.
|
|
940
|
+
case constants_js_1.UnifiedSwapBridgeEventName.InputSourceDestinationSwitched:
|
|
941
|
+
return {
|
|
942
|
+
token_security_type_destination: this.state.tokenSecurityTypeDestination,
|
|
943
|
+
...baseProperties,
|
|
944
|
+
};
|
|
945
|
+
// These events may be published after the bridge-controller state is reset
|
|
946
|
+
// So the BridgeStatusController populates all the properties
|
|
947
|
+
case constants_js_1.UnifiedSwapBridgeEventName.Submitted:
|
|
948
|
+
case constants_js_1.UnifiedSwapBridgeEventName.Completed:
|
|
949
|
+
return propertiesFromClient;
|
|
950
|
+
case constants_js_1.UnifiedSwapBridgeEventName.InputChanged:
|
|
951
|
+
default:
|
|
952
|
+
return baseProperties;
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
_BridgeController_trackInputChangedEvents.set(this, (paramsToUpdate, featureId, quoteRequestIndex = 0) => {
|
|
956
|
+
Object.entries(paramsToUpdate).forEach(([key, value]) => {
|
|
957
|
+
const inputKey = properties_js_1.toInputChangedPropertyKey[key];
|
|
958
|
+
const inputValue = properties_js_1.toInputChangedPropertyValue[key]?.(paramsToUpdate);
|
|
959
|
+
if (inputKey &&
|
|
960
|
+
inputValue !== undefined &&
|
|
961
|
+
this.state.quoteRequest[quoteRequestIndex] &&
|
|
962
|
+
value !==
|
|
963
|
+
this.state.quoteRequest[quoteRequestIndex][key]) {
|
|
964
|
+
this.trackUnifiedSwapBridgeEvent(constants_js_1.UnifiedSwapBridgeEventName.InputChanged, {
|
|
965
|
+
input: inputKey,
|
|
966
|
+
input_value: inputValue,
|
|
967
|
+
location: __classPrivateFieldGet(this, _BridgeController_location, "f"),
|
|
968
|
+
feature_id: featureId,
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
});
|
|
973
|
+
/**
|
|
974
|
+
* This method tracks cross-chain swaps events
|
|
975
|
+
*
|
|
976
|
+
* @param eventName - The name of the event to track
|
|
977
|
+
* @param propertiesFromClient - Properties that can't be calculated from the event name and need to be provided by the client
|
|
978
|
+
* @param quoteRequestIndex - The index of the quote request to track the event for
|
|
979
|
+
* @example
|
|
980
|
+
* this.trackUnifiedSwapBridgeEvent(UnifiedSwapBridgeEventName.ActionOpened, {
|
|
981
|
+
* location: MetaMetricsSwapsEventSource.MainView,
|
|
982
|
+
* });
|
|
983
|
+
*/
|
|
984
|
+
this.trackUnifiedSwapBridgeEvent = (eventName, propertiesFromClient, quoteRequestIndex = 0) => {
|
|
985
|
+
try {
|
|
986
|
+
const combinedPropertiesForEvent = __classPrivateFieldGet(this, _BridgeController_getEventProperties, "f").call(this, eventName, propertiesFromClient, quoteRequestIndex);
|
|
987
|
+
__classPrivateFieldGet(this, _BridgeController_trackMetaMetricsFn, "f").call(this, eventName, combinedPropertiesForEvent);
|
|
988
|
+
}
|
|
989
|
+
catch (error) {
|
|
990
|
+
console.error(`Error tracking cross-chain swaps MetaMetrics event ${eventName}`, error);
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
/**
|
|
994
|
+
*
|
|
995
|
+
* @param walletAddress - The address of the account to get the allowance for
|
|
996
|
+
* @param contractAddress - The address of the ERC20 token contract on mainnet
|
|
997
|
+
* @param destinationChainId - The chain ID of the destination network
|
|
998
|
+
* @returns The atomic allowance of the ERC20 token contract
|
|
999
|
+
*/
|
|
1000
|
+
_BridgeController_getUSDTMainnetAllowance.set(this, async (walletAddress, contractAddress, destinationChainId) => {
|
|
1001
|
+
const networkClient = __classPrivateFieldGet(this, _BridgeController_instances, "m", _BridgeController_getNetworkClientByChainId).call(this, chains_js_1.CHAIN_IDS.MAINNET);
|
|
1002
|
+
const provider = networkClient?.provider;
|
|
1003
|
+
if (!provider) {
|
|
1004
|
+
throw new Error('No provider found');
|
|
1005
|
+
}
|
|
1006
|
+
const ethersProvider = new providers_1.Web3Provider(provider);
|
|
1007
|
+
const contract = new contracts_1.Contract(contractAddress, metamask_eth_abis_1.abiERC20, ethersProvider);
|
|
1008
|
+
const spenderAddress = (0, bridge_js_2.isCrossChain)(chains_js_1.CHAIN_IDS.MAINNET, destinationChainId)
|
|
1009
|
+
? bridge_js_1.METABRIDGE_ETHEREUM_ADDRESS
|
|
1010
|
+
: swaps_js_1.SWAPS_CONTRACT_ADDRESSES[chains_js_1.CHAIN_IDS.MAINNET];
|
|
1011
|
+
const allowance = await contract.allowance(walletAddress, spenderAddress);
|
|
1012
|
+
return allowance.toString();
|
|
1013
|
+
});
|
|
1014
|
+
this.setIntervalLength(bridge_js_1.REFRESH_INTERVAL_MS);
|
|
1015
|
+
__classPrivateFieldSet(this, _BridgeController_abortController, new AbortController(), "f");
|
|
1016
|
+
__classPrivateFieldSet(this, _BridgeController_getLayer1GasFee, getLayer1GasFee, "f");
|
|
1017
|
+
__classPrivateFieldSet(this, _BridgeController_clientId, clientId, "f");
|
|
1018
|
+
__classPrivateFieldSet(this, _BridgeController_clientVersion, clientVersion, "f");
|
|
1019
|
+
__classPrivateFieldSet(this, _BridgeController_fetchFn, fetchFn, "f");
|
|
1020
|
+
__classPrivateFieldSet(this, _BridgeController_trackMetaMetricsFn, trackMetaMetricsFn, "f");
|
|
1021
|
+
__classPrivateFieldSet(this, _BridgeController_config, config ?? {}, "f");
|
|
1022
|
+
__classPrivateFieldSet(this, _BridgeController_trace, traceFn ?? ((_request, fn) => fn?.()), "f");
|
|
1023
|
+
__classPrivateFieldSet(this, _BridgeController_getUseAssetsControllerForRates, getUseAssetsControllerForRates ?? (() => false), "f");
|
|
1024
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
exports.BridgeController = BridgeController;
|
|
1028
|
+
_BridgeController_abortController = new WeakMap(), _BridgeController_batchSellTradesAbortController = new WeakMap(), _BridgeController_quotesFirstFetched = new WeakMap(), _BridgeController_location = new WeakMap(), _BridgeController_clientId = new WeakMap(), _BridgeController_clientVersion = new WeakMap(), _BridgeController_getLayer1GasFee = new WeakMap(), _BridgeController_fetchFn = new WeakMap(), _BridgeController_trackMetaMetricsFn = new WeakMap(), _BridgeController_trace = new WeakMap(), _BridgeController_config = new WeakMap(), _BridgeController_getUseAssetsControllerForRates = new WeakMap(), _BridgeController_trackQuoteValidationFailures = new WeakMap(), _BridgeController_fetchAssetExchangeRates = new WeakMap(), _BridgeController_hasInsufficientBalance = new WeakMap(), _BridgeController_appendInsufficientBalAndResetApproval = new WeakMap(), _BridgeController_shouldResetApproval = new WeakMap(), _BridgeController_fetchBridgeQuotes = new WeakMap(), _BridgeController_handleQuoteStreaming = new WeakMap(), _BridgeController_setMinimumBalanceForRentExemptionInLamports = new WeakMap(), _BridgeController_getJwt = new WeakMap(), _BridgeController_getRequestMetadata = new WeakMap(), _BridgeController_getQuoteFetchData = new WeakMap(), _BridgeController_getEventProperties = new WeakMap(), _BridgeController_trackInputChangedEvents = new WeakMap(), _BridgeController_getUSDTMainnetAllowance = new WeakMap(), _BridgeController_instances = new WeakSet(), _BridgeController_getMultichainSelectedAccount = function _BridgeController_getMultichainSelectedAccount(walletAddress) {
|
|
1029
|
+
// Assume that all quotes in a batch are for the same account
|
|
1030
|
+
const addressToUse = walletAddress ?? this.state.quoteRequest[0].walletAddress;
|
|
1031
|
+
if (!addressToUse) {
|
|
1032
|
+
throw new Error('Account address is required');
|
|
1033
|
+
}
|
|
1034
|
+
const selectedAccount = this.messenger.call('AccountsController:getAccountByAddress', addressToUse);
|
|
1035
|
+
return selectedAccount;
|
|
1036
|
+
}, _BridgeController_getNetworkClientByChainId = function _BridgeController_getNetworkClientByChainId(chainId) {
|
|
1037
|
+
const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', chainId);
|
|
1038
|
+
if (!networkClientId) {
|
|
1039
|
+
throw new Error(`No network client found for chainId: ${chainId}`);
|
|
1040
|
+
}
|
|
1041
|
+
const networkClient = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
|
|
1042
|
+
return networkClient;
|
|
1043
|
+
};
|
|
1044
|
+
//# sourceMappingURL=bridge-controller.cjs.map
|