@metamask-previews/perps-controller 17.3.0-preview-d3f9964be → 17.4.0-preview-aecbce4ff

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +72 -1
  2. package/dist/PerpsController-method-action-types.d.ts +10 -3
  3. package/dist/PerpsController-method-action-types.d.ts.map +1 -1
  4. package/dist/PerpsController-method-action-types.js.map +1 -1
  5. package/dist/PerpsController.d.ts +10 -3
  6. package/dist/PerpsController.d.ts.map +1 -1
  7. package/dist/PerpsController.js +62 -8
  8. package/dist/PerpsController.js.map +1 -1
  9. package/dist/constants/perpsConfig.d.ts +55 -0
  10. package/dist/constants/perpsConfig.d.ts.map +1 -1
  11. package/dist/constants/perpsConfig.js +55 -0
  12. package/dist/constants/perpsConfig.js.map +1 -1
  13. package/dist/providers/AggregatedPerpsProvider.d.ts +19 -0
  14. package/dist/providers/AggregatedPerpsProvider.d.ts.map +1 -1
  15. package/dist/providers/AggregatedPerpsProvider.js +21 -0
  16. package/dist/providers/AggregatedPerpsProvider.js.map +1 -1
  17. package/dist/providers/HyperLiquidProvider.d.ts +7 -0
  18. package/dist/providers/HyperLiquidProvider.d.ts.map +1 -1
  19. package/dist/providers/HyperLiquidProvider.js +133 -34
  20. package/dist/providers/HyperLiquidProvider.js.map +1 -1
  21. package/dist/providers/LighterProvider.d.ts.map +1 -1
  22. package/dist/providers/LighterProvider.js +2 -0
  23. package/dist/providers/LighterProvider.js.map +1 -1
  24. package/dist/services/MarketDataService.d.ts.map +1 -1
  25. package/dist/services/MarketDataService.js +16 -4
  26. package/dist/services/MarketDataService.js.map +1 -1
  27. package/dist/services/RewardsIntegrationService.d.ts +47 -2
  28. package/dist/services/RewardsIntegrationService.d.ts.map +1 -1
  29. package/dist/services/RewardsIntegrationService.js +400 -19
  30. package/dist/services/RewardsIntegrationService.js.map +1 -1
  31. package/dist/services/ServiceContext.d.ts +9 -1
  32. package/dist/services/ServiceContext.d.ts.map +1 -1
  33. package/dist/services/ServiceContext.js.map +1 -1
  34. package/dist/services/TerminalMarketService.d.ts +1 -1
  35. package/dist/services/TerminalMarketService.d.ts.map +1 -1
  36. package/dist/services/TerminalMarketService.js +11 -2
  37. package/dist/services/TerminalMarketService.js.map +1 -1
  38. package/dist/services/TradingService.d.ts.map +1 -1
  39. package/dist/services/TradingService.js +291 -18
  40. package/dist/services/TradingService.js.map +1 -1
  41. package/dist/types/index.d.ts +65 -4
  42. package/dist/types/index.d.ts.map +1 -1
  43. package/dist/types/index.js.map +1 -1
  44. package/dist/types/messenger.d.ts +17 -1
  45. package/dist/types/messenger.d.ts.map +1 -1
  46. package/dist/types/messenger.js.map +1 -1
  47. package/dist/utils/hyperLiquidAdapter.d.ts +7 -0
  48. package/dist/utils/hyperLiquidAdapter.d.ts.map +1 -1
  49. package/dist/utils/hyperLiquidAdapter.js +1 -1
  50. package/dist/utils/hyperLiquidAdapter.js.map +1 -1
  51. package/dist/utils/index.d.ts +1 -0
  52. package/dist/utils/index.d.ts.map +1 -1
  53. package/dist/utils/index.js +1 -0
  54. package/dist/utils/index.js.map +1 -1
  55. package/dist/utils/subscriptionFeeWaiver.d.ts +201 -0
  56. package/dist/utils/subscriptionFeeWaiver.d.ts.map +1 -0
  57. package/dist/utils/subscriptionFeeWaiver.js +334 -0
  58. package/dist/utils/subscriptionFeeWaiver.js.map +1 -0
  59. package/package.json +11 -6
@@ -685,6 +685,30 @@ export class PerpsController extends BaseController {
685
685
  // geo-blocking and HIP-3 flag propagation must remain active across
686
686
  // disconnect → reconnect cycles and must never be torn down.
687
687
  this.messenger.subscribe('RemoteFeatureFlagController:stateChange', this.refreshEligibilityOnFeatureFlagChange.bind(this));
688
+ // Also subscribed for the controller lifetime: the subscription profile
689
+ // must learn the new trading address after every account switch, and the
690
+ // preload-scoped account handler is torn down on disconnect, so it cannot
691
+ // carry this.
692
+ const forgetRegisteredTradingAddresses = () => {
693
+ this.#rewardsIntegrationService.resetRegisteredTradingAddresses();
694
+ // Clearing alone only guarantees the *next preview* re-registers. An
695
+ // order submitted straight after a switch, with no preview in between,
696
+ // would otherwise be attributed to nothing, so the new address announces
697
+ // itself here. Fire-and-forget: attribution plumbing must not block or
698
+ // fail an account switch.
699
+ const switchedAccount = getSelectedEvmAccountFromMessenger(this.messenger);
700
+ if (switchedAccount) {
701
+ this.#rewardsIntegrationService
702
+ .registerTradingAddress(switchedAccount.address, {
703
+ isTestnet: this.state.isTestnet,
704
+ })
705
+ .catch(() => {
706
+ /* never blocks an account switch */
707
+ });
708
+ }
709
+ };
710
+ this.messenger.subscribe('AccountsController:selectedAccountChange', forgetRegisteredTradingAddresses);
711
+ this.messenger.subscribe('AccountTreeController:selectedAccountGroupChange', forgetRegisteredTradingAddresses);
688
712
  this.providers = new Map();
689
713
  // Migrate old persisted data without accountAddress
690
714
  this.#migrateRequestsIfNeeded();
@@ -4322,24 +4346,54 @@ export class PerpsController extends BaseController {
4322
4346
  // cache read and can therefore never start a benefits request while an
4323
4347
  // order is being signed.
4324
4348
  await this.#rewardsIntegrationService.refreshSubscriptionBenefits();
4325
- const waiverStatus = this.#rewardsIntegrationService.getSubscriptionFeeWaiverStatus();
4349
+ // ADR 0064: preview is also where the trading address is announced, so a
4350
+ // fill decoded off the HL fan-out can be attributed back to a profile.
4351
+ // Fire-and-forget — attribution plumbing must not delay or fail a quote.
4352
+ const selectedAccount = getSelectedEvmAccountFromMessenger(this.messenger);
4353
+ if (selectedAccount) {
4354
+ this.#rewardsIntegrationService
4355
+ .registerTradingAddress(selectedAccount.address, {
4356
+ isTestnet: this.state.isTestnet,
4357
+ })
4358
+ .catch(() => {
4359
+ /* never blocks a fee preview */
4360
+ });
4361
+ }
4362
+ // The preview quotes the same blended rate the submit path charges, which
4363
+ // is only possible once the order notional reaches the resolver. `amount`
4364
+ // is the order notional in USD for the quote being previewed.
4365
+ const orderNotionalUsd = params.amount
4366
+ ? Number.parseFloat(params.amount)
4367
+ : undefined;
4368
+ const feeResolution = await this.#rewardsIntegrationService.resolveFee(orderNotionalUsd);
4369
+ // Taken from the resolution rather than read separately: a second read can
4370
+ // observe a different snapshot if the cache is invalidated or the feature
4371
+ // flag flips between the two, which would surface metadata describing a
4372
+ // waiver the quoted rates do not reflect.
4373
+ const waiverStatus = feeResolution.subscription;
4326
4374
  const context = this.#createServiceContext('calculateFees', {
4327
4375
  subscriptionFeeWaiver: waiverStatus.reason === 'no-source' ? undefined : waiverStatus,
4376
+ feeResolution,
4328
4377
  });
4329
4378
  return this.#marketDataService.calculateFees({ provider, params, context });
4330
4379
  }
4331
4380
  /**
4332
4381
  * Approve the dedicated subscription builder outside order submission.
4333
- * Until this succeeds, subscription waivers fall back to the ordinary
4334
- * builder at the standard fee.
4335
4382
  *
4336
- * @returns Whether the subscription builder is approved.
4383
+ * @deprecated ADR 0064 replaced the dedicated subscription builder with cloid
4384
+ * marking on the standard builder, so there is nothing left to approve. Kept
4385
+ * as a no-op so clients still calling it keep building while they migrate;
4386
+ * remove it once cloid marking is verified in shadow mode.
4387
+ *
4388
+ * Resolves `true`, not `false`. The method answers "is the subscription
4389
+ * builder ready?", and the honest answer is now "nothing needs approving" —
4390
+ * a `false` would read as a setup failure to a caller that branches on it and
4391
+ * could block a waiver that is already fully in effect.
4392
+ * @returns Always `true`; no approval is required.
4337
4393
  */
4338
4394
  async approveSubscriptionBuilderFee() {
4339
- const provider = this.getActiveProvider();
4340
- return provider.approveSubscriptionBuilderFee
4341
- ? provider.approveSubscriptionBuilderFee()
4342
- : false;
4395
+ this.#debugLog('PerpsController: approveSubscriptionBuilderFee is a no-op; subscription attribution now rides on the order cloid');
4396
+ return true;
4343
4397
  }
4344
4398
  /**
4345
4399
  * Drop the cached subscription benefits snapshot.