@metamask-previews/perps-controller 6.0.1-preview-e5cef32c6 → 6.1.0-preview-6d2aeda
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 +10 -1
- package/dist/providers/HyperLiquidProvider.cjs +24 -18
- package/dist/providers/HyperLiquidProvider.cjs.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.cts.map +1 -1
- package/dist/providers/HyperLiquidProvider.d.mts.map +1 -1
- package/dist/providers/HyperLiquidProvider.mjs +25 -19
- package/dist/providers/HyperLiquidProvider.mjs.map +1 -1
- package/dist/services/HyperLiquidWalletService.cjs +4 -1
- package/dist/services/HyperLiquidWalletService.cjs.map +1 -1
- package/dist/services/HyperLiquidWalletService.d.cts +1 -1
- package/dist/services/HyperLiquidWalletService.d.cts.map +1 -1
- package/dist/services/HyperLiquidWalletService.d.mts +1 -1
- package/dist/services/HyperLiquidWalletService.d.mts.map +1 -1
- package/dist/services/HyperLiquidWalletService.mjs +4 -1
- package/dist/services/HyperLiquidWalletService.mjs.map +1 -1
- package/dist/services/RewardsIntegrationService.cjs +11 -2
- package/dist/services/RewardsIntegrationService.cjs.map +1 -1
- package/dist/services/RewardsIntegrationService.d.cts.map +1 -1
- package/dist/services/RewardsIntegrationService.d.mts.map +1 -1
- package/dist/services/RewardsIntegrationService.mjs +11 -2
- package/dist/services/RewardsIntegrationService.mjs.map +1 -1
- package/dist/services/TradingReadinessCache.cjs +2 -1
- package/dist/services/TradingReadinessCache.cjs.map +1 -1
- package/dist/services/TradingReadinessCache.d.cts +2 -1
- package/dist/services/TradingReadinessCache.d.cts.map +1 -1
- package/dist/services/TradingReadinessCache.d.mts +2 -1
- package/dist/services/TradingReadinessCache.d.mts.map +1 -1
- package/dist/services/TradingReadinessCache.mjs +2 -1
- package/dist/services/TradingReadinessCache.mjs.map +1 -1
- package/dist/services/TradingService.cjs +41 -0
- package/dist/services/TradingService.cjs.map +1 -1
- package/dist/services/TradingService.d.cts.map +1 -1
- package/dist/services/TradingService.d.mts.map +1 -1
- package/dist/services/TradingService.mjs +41 -0
- package/dist/services/TradingService.mjs.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +7 -2
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.mts +7 -2
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/errorUtils.cjs +24 -3
- package/dist/utils/errorUtils.cjs.map +1 -1
- package/dist/utils/errorUtils.d.cts +8 -0
- package/dist/utils/errorUtils.d.cts.map +1 -1
- package/dist/utils/errorUtils.d.mts +8 -0
- package/dist/utils/errorUtils.d.mts.map +1 -1
- package/dist/utils/errorUtils.mjs +22 -2
- package/dist/utils/errorUtils.mjs.map +1 -1
- package/dist/utils/hyperLiquidAbstraction.cjs +23 -0
- package/dist/utils/hyperLiquidAbstraction.cjs.map +1 -0
- package/dist/utils/hyperLiquidAbstraction.d.cts +11 -0
- package/dist/utils/hyperLiquidAbstraction.d.cts.map +1 -0
- package/dist/utils/hyperLiquidAbstraction.d.mts +11 -0
- package/dist/utils/hyperLiquidAbstraction.d.mts.map +1 -0
- package/dist/utils/hyperLiquidAbstraction.mjs +19 -0
- package/dist/utils/hyperLiquidAbstraction.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -21,6 +21,9 @@ const accountUtils_1 = require("../utils/accountUtils.cjs");
|
|
|
21
21
|
// service portable between mobile and the core monorepo.
|
|
22
22
|
const HARDWARE_KEYRING_TYPES = new Set([
|
|
23
23
|
'Ledger Hardware',
|
|
24
|
+
'Trezor Hardware',
|
|
25
|
+
'OneKey Hardware',
|
|
26
|
+
'Lattice Hardware',
|
|
24
27
|
'QR Hardware Wallet Device',
|
|
25
28
|
]);
|
|
26
29
|
/**
|
|
@@ -49,7 +52,7 @@ class HyperLiquidWalletService {
|
|
|
49
52
|
/**
|
|
50
53
|
* Check whether the selected EVM account is backed by hardware.
|
|
51
54
|
*
|
|
52
|
-
* @returns True for
|
|
55
|
+
* @returns True for MetaMask hardware keyrings; false for software accounts.
|
|
53
56
|
*/
|
|
54
57
|
isSelectedHardwareWallet() {
|
|
55
58
|
const selectedEvmAccount = (0, accountUtils_1.findEvmAccount)(__classPrivateFieldGet(this, _HyperLiquidWalletService_messenger, "f").call('AccountTreeController:getAccountsFromSelectedAccountGroup'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidWalletService.cjs","sourceRoot":"","sources":["../../src/services/HyperLiquidWalletService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAIyB;AAGzB,0EAA4D;AAC5D,4DAAuD;AAMvD,4DAA8E;AAE9E,+EAA+E;AAC/E,yDAAyD;AACzD,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAS;IAC7C,iBAAiB;IACjB,2BAA2B;CAC5B,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAa,wBAAwB;IAQnC,YACE,IAA+B,EAC/B,SAAuC,EACvC,UAAmC,EAAE;;QAVvC,sDAAoB;QAEpB,0CAA0C;QACjC,iDAAiC;QAEjC,sDAAyC;QAOhD,uBAAA,IAAI,kCAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,uCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,uCAAc,OAAO,CAAC,SAAS,IAAI,KAAK,MAAA,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACI,iBAAiB;QACtB,OAAO,uBAAA,IAAI,2CAAW,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC,UAAU,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACI,wBAAwB;QAC7B,MAAM,kBAAkB,GAAG,IAAA,6BAAc,EACvC,uBAAA,IAAI,2CAAW,CAAC,IAAI,CAClB,2DAA2D,CAC5D,CACF,CAAC;QACF,IAAI,CAAC,kBAAkB,IAAI,CAAC,IAAA,mBAAW,EAAC,kBAAkB,EAAE,UAAU,CAAC,EA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AC,CAAC;QAC5D,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,yBAAyB,CACpC,SAAyB;QAEzB,MAAM,EAAE,GAAG,SAAS,IAAI,CAAC,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,SAAkB;QACtC,uBAAA,IAAI,uCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACI,aAAa;QAClB,OAAO,uBAAA,IAAI,2CAAW,CAAC;IACzB,CAAC;CACF;AA3OD,4DA2OC;;AAzLC;;;;;GAKG;AACH,KAAK,qDAAmB,SAAkC;IACxD,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,mCAAiB,CAAC,cAAc,CAAC,CAAC;IACpD,CAAC;IACD,uEAAuE;IACvE,gFAAgF;IAChF,OAAO,uBAAA,IAAI,2CAAW,CAAC,IAAI,CACzB,oCAAoC;IACpC,8DAA8D;IAC9D,SAAgB;IAChB,8DAA8D;IAC9D,IAAW,CACZ,CAAC;AACJ,CAAC","sourcesContent":["import {\n hasProperty,\n isValidHexAddress,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\n\nimport { getChainId } from '../constants/hyperLiquidConfig';\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes';\nimport type {\n PerpsPlatformDependencies,\n PerpsTypedMessageParams,\n} from '../types';\nimport type { PerpsControllerMessengerBase } from '../types/messenger';\nimport { findEvmAccount, getSelectedEvmAccount } from '../utils/accountUtils';\n\n// Mirrors KeyringTypes from @metamask/keyring-controller. Inlined to keep this\n// service portable between mobile and the core monorepo.\nconst HARDWARE_KEYRING_TYPES = new Set<string>([\n 'Ledger Hardware',\n 'QR Hardware Wallet Device',\n]);\n\n/**\n * Service for MetaMask wallet integration with HyperLiquid SDK\n * Provides wallet adapter that implements AbstractWindowEthereum interface\n */\nexport class HyperLiquidWalletService {\n #isTestnet: boolean;\n\n // Platform dependencies for observability\n readonly #deps: PerpsPlatformDependencies;\n\n readonly #messenger: PerpsControllerMessengerBase;\n\n constructor(\n deps: PerpsPlatformDependencies,\n messenger: PerpsControllerMessengerBase,\n options: { isTestnet?: boolean } = {},\n ) {\n this.#deps = deps;\n this.#messenger = messenger;\n this.#isTestnet = options.isTestnet ?? false;\n }\n\n /**\n * Check if the keyring is currently unlocked\n *\n * @returns True if the keyring is unlocked and available for signing.\n */\n public isKeyringUnlocked(): boolean {\n return this.#messenger.call('KeyringController:getState').isUnlocked;\n }\n\n /**\n * Check whether the selected EVM account is backed by hardware.\n *\n * @returns True for Ledger / QR hardware keyrings; false for software accounts.\n */\n public isSelectedHardwareWallet(): boolean {\n const selectedEvmAccount = findEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n if (!selectedEvmAccount || !hasProperty(selectedEvmAccount, 'metadata')) {\n return false;\n }\n\n const metadata = selectedEvmAccount.metadata as\n | { keyring?: { type?: string } }\n | undefined;\n const keyringType = metadata?.keyring?.type;\n\n return Boolean(keyringType && HARDWARE_KEYRING_TYPES.has(keyringType));\n }\n\n /**\n * Sign typed data via DI keyring controller\n *\n * @param msgParams - The typed message parameters including data and sender address.\n * @returns The signature string.\n */\n async #signTypedMessage(msgParams: PerpsTypedMessageParams): Promise<string> {\n if (!this.isKeyringUnlocked()) {\n throw new Error(PERPS_ERROR_CODES.KEYRING_LOCKED);\n }\n // Cast needed: PerpsTypedMessageParams uses loose `data: unknown` type\n // while KeyringController uses strict TypedMessageParams / SignTypedDataVersion\n return this.#messenger.call(\n 'KeyringController:signTypedMessage',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n msgParams as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n 'V4' as any,\n );\n }\n\n /**\n * Create wallet adapter that implements AbstractViemJsonRpcAccount interface\n * Required by @nktkas/hyperliquid SDK for signing transactions\n *\n * @returns The wallet adapter with address, signTypedData, and getChainId methods.\n */\n public createWalletAdapter(): {\n address: Hex;\n signTypedData: (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }) => Promise<Hex>;\n getChainId?: () => Promise<number>;\n } {\n // Get current EVM account via DI accountTree\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const address = evmAccount.address as Hex;\n\n return {\n address,\n signTypedData: async (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<Hex> => {\n // Get FRESH account on every sign to handle account switches\n // This prevents race conditions where wallet adapter was created with old account\n const currentEvmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!currentEvmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const currentAddress = currentEvmAccount.address as Hex;\n\n // Construct EIP-712 typed data\n const typedData = {\n domain: params.domain,\n types: params.types,\n primaryType: params.primaryType,\n message: params.message,\n };\n\n this.#deps.debugLogger.log(\n 'HyperLiquidWalletService: Signing typed data',\n {\n address: currentAddress,\n primaryType: params.primaryType,\n domain: params.domain,\n },\n );\n\n // Use messenger to sign typed data\n const signature = await this.#signTypedMessage({\n from: currentAddress,\n data: typedData,\n });\n\n return signature as Hex;\n },\n getChainId: async (): Promise<number> =>\n parseInt(getChainId(this.#isTestnet), 10),\n };\n }\n\n /**\n * Get current account ID using messenger\n *\n * @returns The CAIP account ID for the current EVM account.\n */\n public async getCurrentAccountId(): Promise<CaipAccountId> {\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const chainId = getChainId(this.#isTestnet);\n const caipAccountId: CaipAccountId = `eip155:${chainId}:${evmAccount.address}`;\n\n return caipAccountId;\n }\n\n /**\n * Get validated user address as Hex from account ID\n *\n * @param accountId - The CAIP account ID to extract the address from.\n * @returns The validated hex address.\n */\n public getUserAddress(accountId: CaipAccountId): Hex {\n const parsed = parseCaipAccountId(accountId);\n const address = parsed.address as Hex;\n\n if (!isValidHexAddress(address)) {\n throw new Error(PERPS_ERROR_CODES.INVALID_ADDRESS_FORMAT);\n }\n\n return address;\n }\n\n /**\n * Get user address with default fallback to current account\n *\n * @param accountId - Optional CAIP account ID; defaults to current account if omitted.\n * @returns The validated hex address.\n */\n public async getUserAddressWithDefault(\n accountId?: CaipAccountId,\n ): Promise<Hex> {\n const id = accountId ?? (await this.getCurrentAccountId());\n return this.getUserAddress(id);\n }\n\n /**\n * Update testnet mode\n *\n * @param isTestnet - Whether to enable testnet mode.\n */\n public setTestnetMode(isTestnet: boolean): void {\n this.#isTestnet = isTestnet;\n }\n\n /**\n * Check if running on testnet\n *\n * @returns True if the service is in testnet mode.\n */\n public isTestnetMode(): boolean {\n return this.#isTestnet;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"HyperLiquidWalletService.cjs","sourceRoot":"","sources":["../../src/services/HyperLiquidWalletService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAIyB;AAGzB,0EAA4D;AAC5D,4DAAuD;AAMvD,4DAA8E;AAE9E,+EAA+E;AAC/E,yDAAyD;AACzD,MAAM,sBAAsB,GAAG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,4DA2OC;;AAzLC;;;;;GAKG;AACH,KAAK,qDAAmB,SAAkC;IACxD,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,mCAAiB,CAAC,cAAc,CAAC,CAAC;IACpD,CAAC;IACD,uEAAuE;IACvE,gFAAgF;IAChF,OAAO,uBAAA,IAAI,2CAAW,CAAC,IAAI,CACzB,oCAAoC;IACpC,8DAA8D;IAC9D,SAAgB;IAChB,8DAA8D;IAC9D,IAAW,CACZ,CAAC;AACJ,CAAC","sourcesContent":["import {\n hasProperty,\n isValidHexAddress,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\n\nimport { getChainId } from '../constants/hyperLiquidConfig';\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes';\nimport type {\n PerpsPlatformDependencies,\n PerpsTypedMessageParams,\n} from '../types';\nimport type { PerpsControllerMessengerBase } from '../types/messenger';\nimport { findEvmAccount, getSelectedEvmAccount } from '../utils/accountUtils';\n\n// Mirrors KeyringTypes from @metamask/keyring-controller. Inlined to keep this\n// service portable between mobile and the core monorepo.\nconst HARDWARE_KEYRING_TYPES = new Set<string>([\n 'Ledger Hardware',\n 'Trezor Hardware',\n 'OneKey Hardware',\n 'Lattice Hardware',\n 'QR Hardware Wallet Device',\n]);\n\n/**\n * Service for MetaMask wallet integration with HyperLiquid SDK\n * Provides wallet adapter that implements AbstractWindowEthereum interface\n */\nexport class HyperLiquidWalletService {\n #isTestnet: boolean;\n\n // Platform dependencies for observability\n readonly #deps: PerpsPlatformDependencies;\n\n readonly #messenger: PerpsControllerMessengerBase;\n\n constructor(\n deps: PerpsPlatformDependencies,\n messenger: PerpsControllerMessengerBase,\n options: { isTestnet?: boolean } = {},\n ) {\n this.#deps = deps;\n this.#messenger = messenger;\n this.#isTestnet = options.isTestnet ?? false;\n }\n\n /**\n * Check if the keyring is currently unlocked\n *\n * @returns True if the keyring is unlocked and available for signing.\n */\n public isKeyringUnlocked(): boolean {\n return this.#messenger.call('KeyringController:getState').isUnlocked;\n }\n\n /**\n * Check whether the selected EVM account is backed by hardware.\n *\n * @returns True for MetaMask hardware keyrings; false for software accounts.\n */\n public isSelectedHardwareWallet(): boolean {\n const selectedEvmAccount = findEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n if (!selectedEvmAccount || !hasProperty(selectedEvmAccount, 'metadata')) {\n return false;\n }\n\n const metadata = selectedEvmAccount.metadata as\n | { keyring?: { type?: string } }\n | undefined;\n const keyringType = metadata?.keyring?.type;\n\n return Boolean(keyringType && HARDWARE_KEYRING_TYPES.has(keyringType));\n }\n\n /**\n * Sign typed data via DI keyring controller\n *\n * @param msgParams - The typed message parameters including data and sender address.\n * @returns The signature string.\n */\n async #signTypedMessage(msgParams: PerpsTypedMessageParams): Promise<string> {\n if (!this.isKeyringUnlocked()) {\n throw new Error(PERPS_ERROR_CODES.KEYRING_LOCKED);\n }\n // Cast needed: PerpsTypedMessageParams uses loose `data: unknown` type\n // while KeyringController uses strict TypedMessageParams / SignTypedDataVersion\n return this.#messenger.call(\n 'KeyringController:signTypedMessage',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n msgParams as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n 'V4' as any,\n );\n }\n\n /**\n * Create wallet adapter that implements AbstractViemJsonRpcAccount interface\n * Required by @nktkas/hyperliquid SDK for signing transactions\n *\n * @returns The wallet adapter with address, signTypedData, and getChainId methods.\n */\n public createWalletAdapter(): {\n address: Hex;\n signTypedData: (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }) => Promise<Hex>;\n getChainId?: () => Promise<number>;\n } {\n // Get current EVM account via DI accountTree\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const address = evmAccount.address as Hex;\n\n return {\n address,\n signTypedData: async (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<Hex> => {\n // Get FRESH account on every sign to handle account switches\n // This prevents race conditions where wallet adapter was created with old account\n const currentEvmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!currentEvmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const currentAddress = currentEvmAccount.address as Hex;\n\n // Construct EIP-712 typed data\n const typedData = {\n domain: params.domain,\n types: params.types,\n primaryType: params.primaryType,\n message: params.message,\n };\n\n this.#deps.debugLogger.log(\n 'HyperLiquidWalletService: Signing typed data',\n {\n address: currentAddress,\n primaryType: params.primaryType,\n domain: params.domain,\n },\n );\n\n // Use messenger to sign typed data\n const signature = await this.#signTypedMessage({\n from: currentAddress,\n data: typedData,\n });\n\n return signature as Hex;\n },\n getChainId: async (): Promise<number> =>\n parseInt(getChainId(this.#isTestnet), 10),\n };\n }\n\n /**\n * Get current account ID using messenger\n *\n * @returns The CAIP account ID for the current EVM account.\n */\n public async getCurrentAccountId(): Promise<CaipAccountId> {\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const chainId = getChainId(this.#isTestnet);\n const caipAccountId: CaipAccountId = `eip155:${chainId}:${evmAccount.address}`;\n\n return caipAccountId;\n }\n\n /**\n * Get validated user address as Hex from account ID\n *\n * @param accountId - The CAIP account ID to extract the address from.\n * @returns The validated hex address.\n */\n public getUserAddress(accountId: CaipAccountId): Hex {\n const parsed = parseCaipAccountId(accountId);\n const address = parsed.address as Hex;\n\n if (!isValidHexAddress(address)) {\n throw new Error(PERPS_ERROR_CODES.INVALID_ADDRESS_FORMAT);\n }\n\n return address;\n }\n\n /**\n * Get user address with default fallback to current account\n *\n * @param accountId - Optional CAIP account ID; defaults to current account if omitted.\n * @returns The validated hex address.\n */\n public async getUserAddressWithDefault(\n accountId?: CaipAccountId,\n ): Promise<Hex> {\n const id = accountId ?? (await this.getCurrentAccountId());\n return this.getUserAddress(id);\n }\n\n /**\n * Update testnet mode\n *\n * @param isTestnet - Whether to enable testnet mode.\n */\n public setTestnetMode(isTestnet: boolean): void {\n this.#isTestnet = isTestnet;\n }\n\n /**\n * Check if running on testnet\n *\n * @returns True if the service is in testnet mode.\n */\n public isTestnetMode(): boolean {\n return this.#isTestnet;\n }\n}\n"]}
|
|
@@ -19,7 +19,7 @@ export declare class HyperLiquidWalletService {
|
|
|
19
19
|
/**
|
|
20
20
|
* Check whether the selected EVM account is backed by hardware.
|
|
21
21
|
*
|
|
22
|
-
* @returns True for
|
|
22
|
+
* @returns True for MetaMask hardware keyrings; false for software accounts.
|
|
23
23
|
*/
|
|
24
24
|
isSelectedHardwareWallet(): boolean;
|
|
25
25
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidWalletService.d.cts","sourceRoot":"","sources":["../../src/services/HyperLiquidWalletService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAI1D,OAAO,KAAK,EACV,yBAAyB,EAE1B,2BAAiB;AAClB,OAAO,KAAK,EAAE,4BAA4B,EAAE,+BAA2B;
|
|
1
|
+
{"version":3,"file":"HyperLiquidWalletService.d.cts","sourceRoot":"","sources":["../../src/services/HyperLiquidWalletService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,E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OAAO,GAAG,IAAI;IAI/C;;;;OAIG;IACI,aAAa,IAAI,OAAO;CAGhC"}
|
|
@@ -19,7 +19,7 @@ export declare class HyperLiquidWalletService {
|
|
|
19
19
|
/**
|
|
20
20
|
* Check whether the selected EVM account is backed by hardware.
|
|
21
21
|
*
|
|
22
|
-
* @returns True for
|
|
22
|
+
* @returns True for MetaMask hardware keyrings; false for software accounts.
|
|
23
23
|
*/
|
|
24
24
|
isSelectedHardwareWallet(): boolean;
|
|
25
25
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidWalletService.d.mts","sourceRoot":"","sources":["../../src/services/HyperLiquidWalletService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAI1D,OAAO,KAAK,EACV,yBAAyB,EAE1B,2BAAiB;AAClB,OAAO,KAAK,EAAE,4BAA4B,EAAE,+BAA2B;
|
|
1
|
+
{"version":3,"file":"HyperLiquidWalletService.d.mts","sourceRoot":"","sources":["../../src/services/HyperLiquidWalletService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,EAAE,wBAAwB;AAI1D,OAAO,KAAK,EACV,yBAAyB,EAE1B,2BAAiB;AAClB,OAAO,KAAK,EAAE,4BAA4B,EAAE,+BAA2B;AAavE;;;GAGG;AACH,qBAAa,wBAAwB;;gBASjC,IAAI,EAAE,yBAAyB,EAC/B,SAAS,EAAE,4BAA4B,EACvC,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO;IAOvC;;;;OAIG;IACI,iBAAiB,IAAI,OAAO;IAInC;;;;OAIG;IACI,wBAAwB,IAAI,OAAO;IAuC1C;;;;;OAKG;IACI,mBAAmB,IAAI;QAC5B,OAAO,EAAE,GAAG,CAAC;QACb,aAAa,EAAE,CAAC,MAAM,EAAE;YACtB,MAAM,EAAE;gBACN,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,CAAC;gBAChB,OAAO,EAAE,MAAM,CAAC;gBAChB,iBAAiB,EAAE,GAAG,CAAC;aACxB,CAAC;YACF,KAAK,EAAE;gBACL,CAAC,GAAG,EAAE,MAAM,GAAG;oBAAE,IAAI,EAAE,MAAM,CAAC;oBAAC,IAAI,EAAE,MAAM,CAAA;iBAAE,EAAE,CAAC;aACjD,CAAC;YACF,WAAW,EAAE,MAAM,CAAC;YACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SAClC,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;KACpC;IAyED;;;;OAIG;IACU,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC;IAiB1D;;;;;OAKG;IACI,cAAc,CAAC,SAAS,EAAE,aAAa,GAAG,GAAG;IAWpD;;;;;OAKG;IACU,yBAAyB,CACpC,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,GAAG,CAAC;IAKf;;;;OAIG;IACI,cAAc,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI;IAI/C;;;;OAIG;IACI,aAAa,IAAI,OAAO;CAGhC"}
|
|
@@ -18,6 +18,9 @@ import { findEvmAccount, getSelectedEvmAccount } from "../utils/accountUtils.mjs
|
|
|
18
18
|
// service portable between mobile and the core monorepo.
|
|
19
19
|
const HARDWARE_KEYRING_TYPES = new Set([
|
|
20
20
|
'Ledger Hardware',
|
|
21
|
+
'Trezor Hardware',
|
|
22
|
+
'OneKey Hardware',
|
|
23
|
+
'Lattice Hardware',
|
|
21
24
|
'QR Hardware Wallet Device',
|
|
22
25
|
]);
|
|
23
26
|
/**
|
|
@@ -46,7 +49,7 @@ export class HyperLiquidWalletService {
|
|
|
46
49
|
/**
|
|
47
50
|
* Check whether the selected EVM account is backed by hardware.
|
|
48
51
|
*
|
|
49
|
-
* @returns True for
|
|
52
|
+
* @returns True for MetaMask hardware keyrings; false for software accounts.
|
|
50
53
|
*/
|
|
51
54
|
isSelectedHardwareWallet() {
|
|
52
55
|
const selectedEvmAccount = findEvmAccount(__classPrivateFieldGet(this, _HyperLiquidWalletService_messenger, "f").call('AccountTreeController:getAccountsFromSelectedAccountGroup'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperLiquidWalletService.mjs","sourceRoot":"","sources":["../../src/services/HyperLiquidWalletService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EAAE,UAAU,EAAE,2CAAuC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,+BAA2B;AAMvD,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,kCAA8B;AAE9E,+EAA+E;AAC/E,yDAAyD;AACzD,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAS;IAC7C,iBAAiB;IACjB,2BAA2B;CAC5B,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,OAAO,wBAAwB;IAQnC,YACE,IAA+B,EAC/B,SAAuC,EACvC,UAAmC,EAAE;;QAVvC,sDAAoB;QAEpB,0CAA0C;QACjC,iDAAiC;QAEjC,sDAAyC;QAOhD,uBAAA,IAAI,kCAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,uCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,uCAAc,OAAO,CAAC,SAAS,IAAI,KAAK,MAAA,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACI,iBAAiB;QACtB,OAAO,uBAAA,IAAI,2CAAW,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC,UAAU,CAAC;IACvE,CAAC;IAED;;;;OAIG;IACI,wBAAwB;QAC7B,MAAM,kBAAkB,GAAG,cAAc,CACvC,uBAAA,IAAI,2CAAW,CAAC,IAAI,CAClB,2DAA2D,CAC5D,CACF,CAAC;QACF,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AC,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,yBAAyB,CACpC,SAAyB;QAEzB,MAAM,EAAE,GAAG,SAAS,IAAI,CAAC,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,cAAc,CAAC,SAAkB;QACtC,uBAAA,IAAI,uCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACI,aAAa;QAClB,OAAO,uBAAA,IAAI,2CAAW,CAAC;IACzB,CAAC;CACF;;AAzLC;;;;;GAKG;AACH,KAAK,qDAAmB,SAAkC;IACxD,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;IACpD,CAAC;IACD,uEAAuE;IACvE,gFAAgF;IAChF,OAAO,uBAAA,IAAI,2CAAW,CAAC,IAAI,CACzB,oCAAoC;IACpC,8DAA8D;IAC9D,SAAgB;IAChB,8DAA8D;IAC9D,IAAW,CACZ,CAAC;AACJ,CAAC","sourcesContent":["import {\n hasProperty,\n isValidHexAddress,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\n\nimport { getChainId } from '../constants/hyperLiquidConfig';\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes';\nimport type {\n PerpsPlatformDependencies,\n PerpsTypedMessageParams,\n} from '../types';\nimport type { PerpsControllerMessengerBase } from '../types/messenger';\nimport { findEvmAccount, getSelectedEvmAccount } from '../utils/accountUtils';\n\n// Mirrors KeyringTypes from @metamask/keyring-controller. Inlined to keep this\n// service portable between mobile and the core monorepo.\nconst HARDWARE_KEYRING_TYPES = new Set<string>([\n 'Ledger Hardware',\n 'QR Hardware Wallet Device',\n]);\n\n/**\n * Service for MetaMask wallet integration with HyperLiquid SDK\n * Provides wallet adapter that implements AbstractWindowEthereum interface\n */\nexport class HyperLiquidWalletService {\n #isTestnet: boolean;\n\n // Platform dependencies for observability\n readonly #deps: PerpsPlatformDependencies;\n\n readonly #messenger: PerpsControllerMessengerBase;\n\n constructor(\n deps: PerpsPlatformDependencies,\n messenger: PerpsControllerMessengerBase,\n options: { isTestnet?: boolean } = {},\n ) {\n this.#deps = deps;\n this.#messenger = messenger;\n this.#isTestnet = options.isTestnet ?? false;\n }\n\n /**\n * Check if the keyring is currently unlocked\n *\n * @returns True if the keyring is unlocked and available for signing.\n */\n public isKeyringUnlocked(): boolean {\n return this.#messenger.call('KeyringController:getState').isUnlocked;\n }\n\n /**\n * Check whether the selected EVM account is backed by hardware.\n *\n * @returns True for Ledger / QR hardware keyrings; false for software accounts.\n */\n public isSelectedHardwareWallet(): boolean {\n const selectedEvmAccount = findEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n if (!selectedEvmAccount || !hasProperty(selectedEvmAccount, 'metadata')) {\n return false;\n }\n\n const metadata = selectedEvmAccount.metadata as\n | { keyring?: { type?: string } }\n | undefined;\n const keyringType = metadata?.keyring?.type;\n\n return Boolean(keyringType && HARDWARE_KEYRING_TYPES.has(keyringType));\n }\n\n /**\n * Sign typed data via DI keyring controller\n *\n * @param msgParams - The typed message parameters including data and sender address.\n * @returns The signature string.\n */\n async #signTypedMessage(msgParams: PerpsTypedMessageParams): Promise<string> {\n if (!this.isKeyringUnlocked()) {\n throw new Error(PERPS_ERROR_CODES.KEYRING_LOCKED);\n }\n // Cast needed: PerpsTypedMessageParams uses loose `data: unknown` type\n // while KeyringController uses strict TypedMessageParams / SignTypedDataVersion\n return this.#messenger.call(\n 'KeyringController:signTypedMessage',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n msgParams as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n 'V4' as any,\n );\n }\n\n /**\n * Create wallet adapter that implements AbstractViemJsonRpcAccount interface\n * Required by @nktkas/hyperliquid SDK for signing transactions\n *\n * @returns The wallet adapter with address, signTypedData, and getChainId methods.\n */\n public createWalletAdapter(): {\n address: Hex;\n signTypedData: (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }) => Promise<Hex>;\n getChainId?: () => Promise<number>;\n } {\n // Get current EVM account via DI accountTree\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const address = evmAccount.address as Hex;\n\n return {\n address,\n signTypedData: async (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<Hex> => {\n // Get FRESH account on every sign to handle account switches\n // This prevents race conditions where wallet adapter was created with old account\n const currentEvmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!currentEvmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const currentAddress = currentEvmAccount.address as Hex;\n\n // Construct EIP-712 typed data\n const typedData = {\n domain: params.domain,\n types: params.types,\n primaryType: params.primaryType,\n message: params.message,\n };\n\n this.#deps.debugLogger.log(\n 'HyperLiquidWalletService: Signing typed data',\n {\n address: currentAddress,\n primaryType: params.primaryType,\n domain: params.domain,\n },\n );\n\n // Use messenger to sign typed data\n const signature = await this.#signTypedMessage({\n from: currentAddress,\n data: typedData,\n });\n\n return signature as Hex;\n },\n getChainId: async (): Promise<number> =>\n parseInt(getChainId(this.#isTestnet), 10),\n };\n }\n\n /**\n * Get current account ID using messenger\n *\n * @returns The CAIP account ID for the current EVM account.\n */\n public async getCurrentAccountId(): Promise<CaipAccountId> {\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const chainId = getChainId(this.#isTestnet);\n const caipAccountId: CaipAccountId = `eip155:${chainId}:${evmAccount.address}`;\n\n return caipAccountId;\n }\n\n /**\n * Get validated user address as Hex from account ID\n *\n * @param accountId - The CAIP account ID to extract the address from.\n * @returns The validated hex address.\n */\n public getUserAddress(accountId: CaipAccountId): Hex {\n const parsed = parseCaipAccountId(accountId);\n const address = parsed.address as Hex;\n\n if (!isValidHexAddress(address)) {\n throw new Error(PERPS_ERROR_CODES.INVALID_ADDRESS_FORMAT);\n }\n\n return address;\n }\n\n /**\n * Get user address with default fallback to current account\n *\n * @param accountId - Optional CAIP account ID; defaults to current account if omitted.\n * @returns The validated hex address.\n */\n public async getUserAddressWithDefault(\n accountId?: CaipAccountId,\n ): Promise<Hex> {\n const id = accountId ?? (await this.getCurrentAccountId());\n return this.getUserAddress(id);\n }\n\n /**\n * Update testnet mode\n *\n * @param isTestnet - Whether to enable testnet mode.\n */\n public setTestnetMode(isTestnet: boolean): void {\n this.#isTestnet = isTestnet;\n }\n\n /**\n * Check if running on testnet\n *\n * @returns True if the service is in testnet mode.\n */\n public isTestnetMode(): boolean {\n return this.#isTestnet;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"HyperLiquidWalletService.mjs","sourceRoot":"","sources":["../../src/services/HyperLiquidWalletService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EACnB,wBAAwB;AAGzB,OAAO,EAAE,UAAU,EAAE,2CAAuC;AAC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9B,CAAC;IAED;;;;OAIG;IACI,aAAa;QAClB,OAAO,uBAAA,IAAI,2CAAW,CAAC;IACzB,CAAC;CACF;;AAzLC;;;;;GAKG;AACH,KAAK,qDAAmB,SAAkC;IACxD,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;IACpD,CAAC;IACD,uEAAuE;IACvE,gFAAgF;IAChF,OAAO,uBAAA,IAAI,2CAAW,CAAC,IAAI,CACzB,oCAAoC;IACpC,8DAA8D;IAC9D,SAAgB;IAChB,8DAA8D;IAC9D,IAAW,CACZ,CAAC;AACJ,CAAC","sourcesContent":["import {\n hasProperty,\n isValidHexAddress,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\n\nimport { getChainId } from '../constants/hyperLiquidConfig';\nimport { PERPS_ERROR_CODES } from '../perpsErrorCodes';\nimport type {\n PerpsPlatformDependencies,\n PerpsTypedMessageParams,\n} from '../types';\nimport type { PerpsControllerMessengerBase } from '../types/messenger';\nimport { findEvmAccount, getSelectedEvmAccount } from '../utils/accountUtils';\n\n// Mirrors KeyringTypes from @metamask/keyring-controller. Inlined to keep this\n// service portable between mobile and the core monorepo.\nconst HARDWARE_KEYRING_TYPES = new Set<string>([\n 'Ledger Hardware',\n 'Trezor Hardware',\n 'OneKey Hardware',\n 'Lattice Hardware',\n 'QR Hardware Wallet Device',\n]);\n\n/**\n * Service for MetaMask wallet integration with HyperLiquid SDK\n * Provides wallet adapter that implements AbstractWindowEthereum interface\n */\nexport class HyperLiquidWalletService {\n #isTestnet: boolean;\n\n // Platform dependencies for observability\n readonly #deps: PerpsPlatformDependencies;\n\n readonly #messenger: PerpsControllerMessengerBase;\n\n constructor(\n deps: PerpsPlatformDependencies,\n messenger: PerpsControllerMessengerBase,\n options: { isTestnet?: boolean } = {},\n ) {\n this.#deps = deps;\n this.#messenger = messenger;\n this.#isTestnet = options.isTestnet ?? false;\n }\n\n /**\n * Check if the keyring is currently unlocked\n *\n * @returns True if the keyring is unlocked and available for signing.\n */\n public isKeyringUnlocked(): boolean {\n return this.#messenger.call('KeyringController:getState').isUnlocked;\n }\n\n /**\n * Check whether the selected EVM account is backed by hardware.\n *\n * @returns True for MetaMask hardware keyrings; false for software accounts.\n */\n public isSelectedHardwareWallet(): boolean {\n const selectedEvmAccount = findEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n if (!selectedEvmAccount || !hasProperty(selectedEvmAccount, 'metadata')) {\n return false;\n }\n\n const metadata = selectedEvmAccount.metadata as\n | { keyring?: { type?: string } }\n | undefined;\n const keyringType = metadata?.keyring?.type;\n\n return Boolean(keyringType && HARDWARE_KEYRING_TYPES.has(keyringType));\n }\n\n /**\n * Sign typed data via DI keyring controller\n *\n * @param msgParams - The typed message parameters including data and sender address.\n * @returns The signature string.\n */\n async #signTypedMessage(msgParams: PerpsTypedMessageParams): Promise<string> {\n if (!this.isKeyringUnlocked()) {\n throw new Error(PERPS_ERROR_CODES.KEYRING_LOCKED);\n }\n // Cast needed: PerpsTypedMessageParams uses loose `data: unknown` type\n // while KeyringController uses strict TypedMessageParams / SignTypedDataVersion\n return this.#messenger.call(\n 'KeyringController:signTypedMessage',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n msgParams as any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n 'V4' as any,\n );\n }\n\n /**\n * Create wallet adapter that implements AbstractViemJsonRpcAccount interface\n * Required by @nktkas/hyperliquid SDK for signing transactions\n *\n * @returns The wallet adapter with address, signTypedData, and getChainId methods.\n */\n public createWalletAdapter(): {\n address: Hex;\n signTypedData: (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }) => Promise<Hex>;\n getChainId?: () => Promise<number>;\n } {\n // Get current EVM account via DI accountTree\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const address = evmAccount.address as Hex;\n\n return {\n address,\n signTypedData: async (params: {\n domain: {\n name: string;\n version: string;\n chainId: number;\n verifyingContract: Hex;\n };\n types: {\n [key: string]: { name: string; type: string }[];\n };\n primaryType: string;\n message: Record<string, unknown>;\n }): Promise<Hex> => {\n // Get FRESH account on every sign to handle account switches\n // This prevents race conditions where wallet adapter was created with old account\n const currentEvmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!currentEvmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const currentAddress = currentEvmAccount.address as Hex;\n\n // Construct EIP-712 typed data\n const typedData = {\n domain: params.domain,\n types: params.types,\n primaryType: params.primaryType,\n message: params.message,\n };\n\n this.#deps.debugLogger.log(\n 'HyperLiquidWalletService: Signing typed data',\n {\n address: currentAddress,\n primaryType: params.primaryType,\n domain: params.domain,\n },\n );\n\n // Use messenger to sign typed data\n const signature = await this.#signTypedMessage({\n from: currentAddress,\n data: typedData,\n });\n\n return signature as Hex;\n },\n getChainId: async (): Promise<number> =>\n parseInt(getChainId(this.#isTestnet), 10),\n };\n }\n\n /**\n * Get current account ID using messenger\n *\n * @returns The CAIP account ID for the current EVM account.\n */\n public async getCurrentAccountId(): Promise<CaipAccountId> {\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount?.address) {\n throw new Error(PERPS_ERROR_CODES.NO_ACCOUNT_SELECTED);\n }\n\n const chainId = getChainId(this.#isTestnet);\n const caipAccountId: CaipAccountId = `eip155:${chainId}:${evmAccount.address}`;\n\n return caipAccountId;\n }\n\n /**\n * Get validated user address as Hex from account ID\n *\n * @param accountId - The CAIP account ID to extract the address from.\n * @returns The validated hex address.\n */\n public getUserAddress(accountId: CaipAccountId): Hex {\n const parsed = parseCaipAccountId(accountId);\n const address = parsed.address as Hex;\n\n if (!isValidHexAddress(address)) {\n throw new Error(PERPS_ERROR_CODES.INVALID_ADDRESS_FORMAT);\n }\n\n return address;\n }\n\n /**\n * Get user address with default fallback to current account\n *\n * @param accountId - Optional CAIP account ID; defaults to current account if omitted.\n * @returns The validated hex address.\n */\n public async getUserAddressWithDefault(\n accountId?: CaipAccountId,\n ): Promise<Hex> {\n const id = accountId ?? (await this.getCurrentAccountId());\n return this.getUserAddress(id);\n }\n\n /**\n * Update testnet mode\n *\n * @param isTestnet - Whether to enable testnet mode.\n */\n public setTestnetMode(isTestnet: boolean): void {\n this.#isTestnet = isTestnet;\n }\n\n /**\n * Check if running on testnet\n *\n * @returns True if the service is in testnet mode.\n */\n public isTestnetMode(): boolean {\n return this.#isTestnet;\n }\n}\n"]}
|
|
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _RewardsIntegrationService_instances, _RewardsIntegrationService_deps, _RewardsIntegrationService_messenger, _RewardsIntegrationService_getChainIdForNetwork;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.RewardsIntegrationService = void 0;
|
|
16
|
+
const hyperLiquidConfig_1 = require("../constants/hyperLiquidConfig.cjs");
|
|
16
17
|
const perpsConfig_1 = require("../constants/perpsConfig.cjs");
|
|
17
18
|
const accountUtils_1 = require("../utils/accountUtils.cjs");
|
|
18
19
|
const errorUtils_1 = require("../utils/errorUtils.cjs");
|
|
@@ -84,8 +85,16 @@ class RewardsIntegrationService {
|
|
|
84
85
|
});
|
|
85
86
|
return undefined;
|
|
86
87
|
}
|
|
87
|
-
// Use rewards via DI (no RewardsController in Core yet)
|
|
88
|
-
|
|
88
|
+
// Use rewards via DI (no RewardsController in Core yet).
|
|
89
|
+
// The rewards controller needs the perps MetaMask builder base fee in
|
|
90
|
+
// bips to convert an absolute VIP fee into a discount fraction.
|
|
91
|
+
const discountBips = await __classPrivateFieldGet(this, _RewardsIntegrationService_deps, "f").rewards.getPerpsDiscountForAccount(caipAccountId, hyperLiquidConfig_1.BUILDER_FEE_CONFIG.MaxFeeDecimal * hyperLiquidConfig_1.BASIS_POINTS_DIVISOR);
|
|
92
|
+
// null = subscription state not hydrated yet; surface as undefined so
|
|
93
|
+
// callers don't treat it as a definitive "no discount" answer.
|
|
94
|
+
if (discountBips === null) {
|
|
95
|
+
__classPrivateFieldGet(this, _RewardsIntegrationService_deps, "f").debugLogger.log('RewardsIntegrationService: Fee discount unavailable (subscription state not hydrated)', { address: evmAccount.address, caipAccountId });
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
89
98
|
__classPrivateFieldGet(this, _RewardsIntegrationService_deps, "f").debugLogger.log('RewardsIntegrationService: Fee discount calculated', {
|
|
90
99
|
address: evmAccount.address,
|
|
91
100
|
caipAccountId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RewardsIntegrationService.cjs","sourceRoot":"","sources":["../../src/services/RewardsIntegrationService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8DAA2D;AAG3D,4DAA8D;AAC9D,wDAAkD;AAClD,4DAAqE;AAErE;;;;;;;GAOG;AACH,MAAa,yBAAyB;IAKpC;;;;;OAKG;IACH,YACE,IAA+B,EAC/B,SAAuC;;QAZhC,kDAAiC;QAEjC,uDAAyC;QAYhD,uBAAA,IAAI,mCAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,wCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAqBD;;;;;OAKG;IACH,KAAK,CAAC,wBAAwB;QAC5B,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,IAAA,oCAAqB,EACtC,uB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C3B,OAAO;4BACP,uBAAuB;yBACxB;qBACF;iBACF,CACF,CAAC;gBACF,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,
|
|
1
|
+
{"version":3,"file":"RewardsIntegrationService.cjs","sourceRoot":"","sources":["../../src/services/RewardsIntegrationService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0EAGwC;AACxC,8DAA2D;AAG3D,4DAA8D;AAC9D,wDAAkD;AAClD,4DAAqE;AAErE;;;;;;;GAOG;AACH,MAAa,yBAAyB;IAKpC;;;;;OAKG;IACH,YACE,IAA+B,EAC/B,SAAuC;;QAZhC,kDAAiC;QAEjC,uDAAyC;QAYhD,uBAAA,IAAI,mCAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,wCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAqBD;;;;;OAKG;IACH,KAAK,CAAC,wBAAwB;QAC5B,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,IAAA,oCAAqB,EACtC,uBAAA,IAAI,4CAAW,CAAC,IAAI,CAClB,2DAA2D,CAC5D,CACF,CAAC;YAEF,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,uBAAA,IAAI,uCAAM,CAAC,WAAW,CAAC,GAAG,CACxB,kEAAkE,CACnE,CAAC;gBACF,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,6CAA6C;YAC7C,MAAM,YAAY,GAAG,uBAAA,IAAI,4CAAW,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;YACxE,MAAM,EAAE,uBAAuB,EAAE,GAAG,YAAY,CAAC;YACjD,MAAM,OAAO,GAAG,uBAAA,IAAI,6FAAsB,MAA1B,IAAI,EAAuB,uBAAuB,CAAC,CAAC;YAEpE,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,uBAAA,IAAI,uCAAM,CAAC,MAAM,CAAC,KAAK,CACrB,IAAI,KAAK,CAAC,iDAAiD,CAAC,EAC5D;oBACE,IAAI,EAAE,EAAE,OAAO,EAA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U,CAAC,OAAO;gBAC3B,aAAa;gBACb,YAAY;gBACZ,kBAAkB,EAAE,YAAY,GAAG,GAAG;aACvC,CACF,CAAC;YAEF,OAAO,YAAY,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uBAAA,IAAI,uCAAM,CAAC,MAAM,CAAC,KAAK,CACrB,IAAA,wBAAW,EACT,KAAK,EACL,oDAAoD,CACrD,EACD;gBACE,IAAI,EAAE,EAAE,OAAO,EAAE,6BAAe,CAAC,WAAW,EAAE;gBAC9C,OAAO,EAAE;oBACP,IAAI,EAAE,oDAAoD;oBAC1D,IAAI,EAAE,EAAE;iBACT;aACF,CACF,CAAC;YACF,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF;AAvJD,8DAuJC;wQA9HuB,eAAuB;IAC3C,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,uBAAA,IAAI,4CAAW,CAAC,IAAI,CACxC,wCAAwC,EACxC,eAAe,CAChB,CAAC;QACF,OAAO,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,+BAA+B;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import {\n BASIS_POINTS_DIVISOR,\n BUILDER_FEE_CONFIG,\n} from '../constants/hyperLiquidConfig';\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport type { PerpsPlatformDependencies } from '../types';\nimport type { PerpsControllerMessengerBase } from '../types/messenger';\nimport { getSelectedEvmAccount } from '../utils/accountUtils';\nimport { ensureError } from '../utils/errorUtils';\nimport { formatAccountToCaipAccountId } from '../utils/rewardsUtils';\n\n/**\n * RewardsIntegrationService\n *\n * Handles rewards-related operations and fee discount calculations.\n * Stateless service that coordinates with RewardsController and NetworkController.\n *\n * Instance-based service with constructor injection of platform dependencies.\n */\nexport class RewardsIntegrationService {\n readonly #deps: PerpsPlatformDependencies;\n\n readonly #messenger: PerpsControllerMessengerBase;\n\n /**\n * Create a new RewardsIntegrationService instance\n *\n * @param deps - Platform dependencies for logging, metrics, etc.\n * @param messenger - Controller messenger for cross-controller communication.\n */\n constructor(\n deps: PerpsPlatformDependencies,\n messenger: PerpsControllerMessengerBase,\n ) {\n this.#deps = deps;\n this.#messenger = messenger;\n }\n\n /**\n * Get chain ID for a network client via DI network controller\n *\n * @param networkClientId - The network client identifier to look up.\n * @returns The chain ID string, or undefined if the network client is not found.\n */\n #getChainIdForNetwork(networkClientId: string): string | undefined {\n try {\n const networkClient = this.#messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return networkClient.configuration.chainId;\n } catch {\n // Network client may not exist\n return undefined;\n }\n }\n\n /**\n * Calculate user fee discount from rewards\n * Returns discount in basis points (e.g., 6500 = 65% discount)\n *\n * @returns The fee discount in basis points, or undefined if unavailable.\n */\n async calculateUserFeeDiscount(): Promise<number | undefined> {\n try {\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount) {\n this.#deps.debugLogger.log(\n 'RewardsIntegrationService: No EVM account found for fee discount',\n );\n return undefined;\n }\n\n // Get the chain ID via DI network controller\n const networkState = this.#messenger.call('NetworkController:getState');\n const { selectedNetworkClientId } = networkState;\n const chainId = this.#getChainIdForNetwork(selectedNetworkClientId);\n\n if (!chainId) {\n this.#deps.logger.error(\n new Error('Chain ID not found for fee discount calculation'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'RewardsIntegrationService.calculateUserFeeDiscount',\n data: {\n selectedNetworkClientId,\n },\n },\n },\n );\n return undefined;\n }\n\n // Use pure utility function for CAIP formatting (pass logger for error reporting)\n const caipAccountId = formatAccountToCaipAccountId(\n evmAccount.address,\n chainId,\n this.#deps.logger,\n );\n\n if (!caipAccountId) {\n this.#deps.logger.error(\n new Error('Failed to format CAIP account ID for fee discount'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'RewardsIntegrationService.calculateUserFeeDiscount',\n data: {\n address: evmAccount.address,\n chainId,\n selectedNetworkClientId,\n },\n },\n },\n );\n return undefined;\n }\n\n // Use rewards via DI (no RewardsController in Core yet).\n // The rewards controller needs the perps MetaMask builder base fee in\n // bips to convert an absolute VIP fee into a discount fraction.\n const discountBips = await this.#deps.rewards.getPerpsDiscountForAccount(\n caipAccountId,\n BUILDER_FEE_CONFIG.MaxFeeDecimal * BASIS_POINTS_DIVISOR,\n );\n\n // null = subscription state not hydrated yet; surface as undefined so\n // callers don't treat it as a definitive \"no discount\" answer.\n if (discountBips === null) {\n this.#deps.debugLogger.log(\n 'RewardsIntegrationService: Fee discount unavailable (subscription state not hydrated)',\n { address: evmAccount.address, caipAccountId },\n );\n return undefined;\n }\n\n this.#deps.debugLogger.log(\n 'RewardsIntegrationService: Fee discount calculated',\n {\n address: evmAccount.address,\n caipAccountId,\n discountBips,\n discountPercentage: discountBips / 100,\n },\n );\n\n return discountBips;\n } catch (error) {\n this.#deps.logger.error(\n ensureError(\n error,\n 'RewardsIntegrationService.calculateUserFeeDiscount',\n ),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'RewardsIntegrationService.calculateUserFeeDiscount',\n data: {},\n },\n },\n );\n return undefined;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RewardsIntegrationService.d.cts","sourceRoot":"","sources":["../../src/services/RewardsIntegrationService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RewardsIntegrationService.d.cts","sourceRoot":"","sources":["../../src/services/RewardsIntegrationService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,2BAAiB;AAC1D,OAAO,KAAK,EAAE,4BAA4B,EAAE,+BAA2B;AAKvE;;;;;;;GAOG;AACH,qBAAa,yBAAyB;;IAKpC;;;;;OAKG;gBAED,IAAI,EAAE,yBAAyB,EAC/B,SAAS,EAAE,4BAA4B;IAyBzC;;;;;OAKG;IACG,wBAAwB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CA2G9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RewardsIntegrationService.d.mts","sourceRoot":"","sources":["../../src/services/RewardsIntegrationService.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RewardsIntegrationService.d.mts","sourceRoot":"","sources":["../../src/services/RewardsIntegrationService.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,2BAAiB;AAC1D,OAAO,KAAK,EAAE,4BAA4B,EAAE,+BAA2B;AAKvE;;;;;;;GAOG;AACH,qBAAa,yBAAyB;;IAKpC;;;;;OAKG;gBAED,IAAI,EAAE,yBAAyB,EAC/B,SAAS,EAAE,4BAA4B;IAyBzC;;;;;OAKG;IACG,wBAAwB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;CA2G9D"}
|
|
@@ -10,6 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _RewardsIntegrationService_instances, _RewardsIntegrationService_deps, _RewardsIntegrationService_messenger, _RewardsIntegrationService_getChainIdForNetwork;
|
|
13
|
+
import { BASIS_POINTS_DIVISOR, BUILDER_FEE_CONFIG } from "../constants/hyperLiquidConfig.mjs";
|
|
13
14
|
import { PERPS_CONSTANTS } from "../constants/perpsConfig.mjs";
|
|
14
15
|
import { getSelectedEvmAccount } from "../utils/accountUtils.mjs";
|
|
15
16
|
import { ensureError } from "../utils/errorUtils.mjs";
|
|
@@ -81,8 +82,16 @@ export class RewardsIntegrationService {
|
|
|
81
82
|
});
|
|
82
83
|
return undefined;
|
|
83
84
|
}
|
|
84
|
-
// Use rewards via DI (no RewardsController in Core yet)
|
|
85
|
-
|
|
85
|
+
// Use rewards via DI (no RewardsController in Core yet).
|
|
86
|
+
// The rewards controller needs the perps MetaMask builder base fee in
|
|
87
|
+
// bips to convert an absolute VIP fee into a discount fraction.
|
|
88
|
+
const discountBips = await __classPrivateFieldGet(this, _RewardsIntegrationService_deps, "f").rewards.getPerpsDiscountForAccount(caipAccountId, BUILDER_FEE_CONFIG.MaxFeeDecimal * BASIS_POINTS_DIVISOR);
|
|
89
|
+
// null = subscription state not hydrated yet; surface as undefined so
|
|
90
|
+
// callers don't treat it as a definitive "no discount" answer.
|
|
91
|
+
if (discountBips === null) {
|
|
92
|
+
__classPrivateFieldGet(this, _RewardsIntegrationService_deps, "f").debugLogger.log('RewardsIntegrationService: Fee discount unavailable (subscription state not hydrated)', { address: evmAccount.address, caipAccountId });
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
86
95
|
__classPrivateFieldGet(this, _RewardsIntegrationService_deps, "f").debugLogger.log('RewardsIntegrationService: Fee discount calculated', {
|
|
87
96
|
address: evmAccount.address,
|
|
88
97
|
caipAccountId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RewardsIntegrationService.mjs","sourceRoot":"","sources":["../../src/services/RewardsIntegrationService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,qCAAiC;AAG3D,OAAO,EAAE,qBAAqB,EAAE,kCAA8B;AAC9D,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAClD,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAErE;;;;;;;GAOG;AACH,MAAM,OAAO,yBAAyB;IAKpC;;;;;OAKG;IACH,YACE,IAA+B,EAC/B,SAAuC;;QAZhC,kDAAiC;QAEjC,uDAAyC;QAYhD,uBAAA,IAAI,mCAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,wCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAqBD;;;;;OAKG;IACH,KAAK,CAAC,wBAAwB;QAC5B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AE;4BACJ,OAAO,EAAE,UAAU,CAAC,OAAO;4BAC3B,OAAO;4BACP,uBAAuB;yBACxB;qBACF;iBACF,CACF,CAAC;gBACF,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,
|
|
1
|
+
{"version":3,"file":"RewardsIntegrationService.mjs","sourceRoot":"","sources":["../../src/services/RewardsIntegrationService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EACnB,2CAAuC;AACxC,OAAO,EAAE,eAAe,EAAE,qCAAiC;AAG3D,OAAO,EAAE,qBAAqB,EAAE,kCAA8B;AAC9D,OAAO,EAAE,WAAW,EAAE,gCAA4B;AAClD,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAErE;;;;;;;GAOG;AACH,MAAM,OAAO,yBAAyB;IAKpC;;;;;OAKG;IACH,YACE,IAA+B,EAC/B,SAAuC;;QAZhC,kDAAiC;QAEjC,uDAAyC;QAYhD,uBAAA,IAAI,mCAAS,IAAI,MAAA,CAAC;QAClB,uBAAA,IAAI,wCAAc,SAAS,MAAA,CAAC;IAC9B,CAAC;IAqBD;;;;;OAKG;IACH,KAAK,CAAC,wBAAwB;QAC5B,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,qBAAqB,CACtC,uBAAA,IAAI,4CAAW,CAAC,IAAI,CAClB,2DAA2D,CAC5D,CACF,CAAC;YAEF,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,uBAAA,IAAI,uCAAM,CAAC,WAAW,CAAC,GAAG,CACxB,kEAAkE,CACnE,CAAC;gBACF,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,6CAA6C;YAC7C,MAAM,YAAY,GAAG,uBAAA,IAAI,4CAAW,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;YACxE,MAAM,EAAE,uBAAuB,EAAE,GAAG,YAAY,CAAC;YACjD,MAAM,OAAO,GAAG,uBAAA,IAAI,6FAAsB,MAA1B,IAAI,EAAuB,uBAAu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U,CAAC,OAAO,EAAE,aAAa,EAAE,CAC/C,CAAC;gBACF,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,uBAAA,IAAI,uCAAM,CAAC,WAAW,CAAC,GAAG,CACxB,oDAAoD,EACpD;gBACE,OAAO,EAAE,UAAU,CAAC,OAAO;gBAC3B,aAAa;gBACb,YAAY;gBACZ,kBAAkB,EAAE,YAAY,GAAG,GAAG;aACvC,CACF,CAAC;YAEF,OAAO,YAAY,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,uBAAA,IAAI,uCAAM,CAAC,MAAM,CAAC,KAAK,CACrB,WAAW,CACT,KAAK,EACL,oDAAoD,CACrD,EACD;gBACE,IAAI,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,WAAW,EAAE;gBAC9C,OAAO,EAAE;oBACP,IAAI,EAAE,oDAAoD;oBAC1D,IAAI,EAAE,EAAE;iBACT;aACF,CACF,CAAC;YACF,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;CACF;wQA9HuB,eAAuB;IAC3C,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,uBAAA,IAAI,4CAAW,CAAC,IAAI,CACxC,wCAAwC,EACxC,eAAe,CAChB,CAAC;QACF,OAAO,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,+BAA+B;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import {\n BASIS_POINTS_DIVISOR,\n BUILDER_FEE_CONFIG,\n} from '../constants/hyperLiquidConfig';\nimport { PERPS_CONSTANTS } from '../constants/perpsConfig';\nimport type { PerpsPlatformDependencies } from '../types';\nimport type { PerpsControllerMessengerBase } from '../types/messenger';\nimport { getSelectedEvmAccount } from '../utils/accountUtils';\nimport { ensureError } from '../utils/errorUtils';\nimport { formatAccountToCaipAccountId } from '../utils/rewardsUtils';\n\n/**\n * RewardsIntegrationService\n *\n * Handles rewards-related operations and fee discount calculations.\n * Stateless service that coordinates with RewardsController and NetworkController.\n *\n * Instance-based service with constructor injection of platform dependencies.\n */\nexport class RewardsIntegrationService {\n readonly #deps: PerpsPlatformDependencies;\n\n readonly #messenger: PerpsControllerMessengerBase;\n\n /**\n * Create a new RewardsIntegrationService instance\n *\n * @param deps - Platform dependencies for logging, metrics, etc.\n * @param messenger - Controller messenger for cross-controller communication.\n */\n constructor(\n deps: PerpsPlatformDependencies,\n messenger: PerpsControllerMessengerBase,\n ) {\n this.#deps = deps;\n this.#messenger = messenger;\n }\n\n /**\n * Get chain ID for a network client via DI network controller\n *\n * @param networkClientId - The network client identifier to look up.\n * @returns The chain ID string, or undefined if the network client is not found.\n */\n #getChainIdForNetwork(networkClientId: string): string | undefined {\n try {\n const networkClient = this.#messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return networkClient.configuration.chainId;\n } catch {\n // Network client may not exist\n return undefined;\n }\n }\n\n /**\n * Calculate user fee discount from rewards\n * Returns discount in basis points (e.g., 6500 = 65% discount)\n *\n * @returns The fee discount in basis points, or undefined if unavailable.\n */\n async calculateUserFeeDiscount(): Promise<number | undefined> {\n try {\n const evmAccount = getSelectedEvmAccount(\n this.#messenger.call(\n 'AccountTreeController:getAccountsFromSelectedAccountGroup',\n ),\n );\n\n if (!evmAccount) {\n this.#deps.debugLogger.log(\n 'RewardsIntegrationService: No EVM account found for fee discount',\n );\n return undefined;\n }\n\n // Get the chain ID via DI network controller\n const networkState = this.#messenger.call('NetworkController:getState');\n const { selectedNetworkClientId } = networkState;\n const chainId = this.#getChainIdForNetwork(selectedNetworkClientId);\n\n if (!chainId) {\n this.#deps.logger.error(\n new Error('Chain ID not found for fee discount calculation'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'RewardsIntegrationService.calculateUserFeeDiscount',\n data: {\n selectedNetworkClientId,\n },\n },\n },\n );\n return undefined;\n }\n\n // Use pure utility function for CAIP formatting (pass logger for error reporting)\n const caipAccountId = formatAccountToCaipAccountId(\n evmAccount.address,\n chainId,\n this.#deps.logger,\n );\n\n if (!caipAccountId) {\n this.#deps.logger.error(\n new Error('Failed to format CAIP account ID for fee discount'),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'RewardsIntegrationService.calculateUserFeeDiscount',\n data: {\n address: evmAccount.address,\n chainId,\n selectedNetworkClientId,\n },\n },\n },\n );\n return undefined;\n }\n\n // Use rewards via DI (no RewardsController in Core yet).\n // The rewards controller needs the perps MetaMask builder base fee in\n // bips to convert an absolute VIP fee into a discount fraction.\n const discountBips = await this.#deps.rewards.getPerpsDiscountForAccount(\n caipAccountId,\n BUILDER_FEE_CONFIG.MaxFeeDecimal * BASIS_POINTS_DIVISOR,\n );\n\n // null = subscription state not hydrated yet; surface as undefined so\n // callers don't treat it as a definitive \"no discount\" answer.\n if (discountBips === null) {\n this.#deps.debugLogger.log(\n 'RewardsIntegrationService: Fee discount unavailable (subscription state not hydrated)',\n { address: evmAccount.address, caipAccountId },\n );\n return undefined;\n }\n\n this.#deps.debugLogger.log(\n 'RewardsIntegrationService: Fee discount calculated',\n {\n address: evmAccount.address,\n caipAccountId,\n discountBips,\n discountPercentage: discountBips / 100,\n },\n );\n\n return discountBips;\n } catch (error) {\n this.#deps.logger.error(\n ensureError(\n error,\n 'RewardsIntegrationService.calculateUserFeeDiscount',\n ),\n {\n tags: { feature: PERPS_CONSTANTS.FeatureName },\n context: {\n name: 'RewardsIntegrationService.calculateUserFeeDiscount',\n data: {},\n },\n },\n );\n return undefined;\n }\n }\n}\n"]}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Global singleton cache for Perps signing operations
|
|
4
4
|
*
|
|
5
5
|
* This cache persists across provider reconnections to prevent repeated
|
|
6
|
-
* signing requests for hardware wallets. Critical for preventing
|
|
6
|
+
* signing requests for hardware wallets. Critical for preventing repeated
|
|
7
|
+
* hardware wallet signing prompts.
|
|
7
8
|
*
|
|
8
9
|
* Cache is intentionally kept separate from provider instances because providers
|
|
9
10
|
* are recreated on account/network changes, which would reset instance-level caches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TradingReadinessCache.cjs","sourceRoot":"","sources":["../../src/services/TradingReadinessCache.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;;;AAqBH,MAAM,wBAAwB;IAS5B,8CAA8C;IAC9C;;QAPS,0CAA8C,IAAI,GAAG,EAAE,EAAC;QAEjE,iFAAiF;QACjF,gGAAgG;QACvF,uDAAkD,IAAI,GAAG,EAAE,EAAC;QAInE,sCAAsC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW;;QACvB,+GAAuC,IAAI,EAAwB,EAAE,0CAAA,CAAC;QACtE,OAAO,uBAAA,EAAwB,8CAAU,CAAC;IAC5C,CAAC;IAED,qCAAqC;IAErC;;;;;;;OAOG;IACI,UAAU,CACf,aAA2D,EAC3D,OAA8B,EAC9B,WAAmB;QAEnB,MAAM,GAAG,GAAG,GAAG,aAAa,IAAI,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;QACvE,OAAO,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;OAQG;IACI,WAAW,CAChB,aAA2D,EAC3D,OAA8B,EAC9B,WAAmB;QAEnB,MAAM,GAAG,GAAG,GAAG,aAAa,IAAI,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;QACvE,IAAI,cAA0B,CAAC;QAC/B,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAC5C,cAAc,GAAG,OAAO,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,uBAAA,IAAI,oDAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC3C,OAAO,GAAG,EAAE;YACV,uBAAA,IAAI,oDAAo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,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YAChD,QAAQ,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YAC9C,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;QACF,uBAAA,IAAI,uCAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAnFM,sDAAS,CAA2B;AA0T7C,0DAA0D;AAC7C,QAAA,qBAAqB,GAAG,wBAAwB,CAAC,WAAW,EAAE,CAAC;AAE5E,mCAAmC;AACtB,QAAA,iBAAiB,GAAG,wBAAwB,CAAC,WAAW,EAAE,CAAC","sourcesContent":["/**\n * Global singleton cache for Perps signing operations\n *\n * This cache persists across provider reconnections to prevent repeated\n * signing requests for hardware wallets. Critical for preventing QR popup spam.\n *\n * Cache is intentionally kept separate from provider instances because providers\n * are recreated on account/network changes, which would reset instance-level caches.\n *\n * Tracks three signing operations:\n * 1. Unified Account enablement (one-time, replaces deprecated DEX abstraction)\n * 2. Builder Fee approval (required for trading)\n * 3. Referral code setup (one-time per account)\n *\n * Cache Structure:\n * - Key: `network:userAddress` (e.g., \"mainnet:0x123...\")\n * - Value: { unifiedAccount, builderFee, referral, timestamp }\n *\n * Lifecycle:\n * - Cache persists throughout app session\n * - Individual entries can be cleared per user/network\n * - Full cache can be cleared on app restart or explicit user action\n */\n\ntype SigningOperationState = {\n attempted: boolean; // Whether we've attempted this operation\n success: boolean; // Whether it succeeded (only valid if attempted=true)\n};\n\ntype PerpsSigningCacheEntry = {\n unifiedAccount: SigningOperationState;\n builderFee: SigningOperationState;\n referral: SigningOperationState;\n timestamp: number; // When this entry was last updated\n};\n\n// Legacy interface for backward compatibility\ntype TradingReadinessCacheEntry = {\n attempted: boolean;\n enabled: boolean;\n timestamp: number;\n};\n\nclass PerpsSigningCacheManager {\n static #instance: PerpsSigningCacheManager;\n\n readonly #cache: Map<string, PerpsSigningCacheEntry> = new Map();\n\n // Global in-flight locks to prevent concurrent signing attempts across providers\n // Key: operationType:network:userAddress, Value: Promise that resolves when operation completes\n readonly #inFlightOperations: Map<string, Promise<void>> = new Map();\n\n // Singleton: use getInstance() instead of new\n protected constructor() {\n // Protected constructor for singleton\n }\n\n public static getInstance(): PerpsSigningCacheManager {\n PerpsSigningCacheManager.#instance ??= new PerpsSigningCacheManager();\n return PerpsSigningCacheManager.#instance;\n }\n\n // ===== In-Flight Lock Methods =====\n\n /**\n * Check if an operation is currently in-flight for this user/network\n *\n * @param operationType - The type of operation being performed.\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public isInFlight(\n operationType: 'unifiedAccount' | 'builderFee' | 'referral',\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): Promise<void> | undefined {\n const key = `${operationType}:${network}:${userAddress.toLowerCase()}`;\n return this.#inFlightOperations.get(key);\n }\n\n /**\n * Set an operation as in-flight\n * Returns a function to call when operation completes\n *\n * @param operationType - The type of operation being performed.\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public setInFlight(\n operationType: 'unifiedAccount' | 'builderFee' | 'referral',\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): () => void {\n const key = `${operationType}:${network}:${userAddress.toLowerCase()}`;\n let resolvePromise: () => void;\n const promise = new Promise<void>((resolve) => {\n resolvePromise = resolve;\n });\n this.#inFlightOperations.set(key, promise);\n return () => {\n this.#inFlightOperations.delete(key);\n resolvePromise();\n };\n }\n\n #getCacheKey(network: 'mainnet' | 'testnet', userAddress: string): string {\n return `${network}:${userAddress.toLowerCase()}`;\n }\n\n #getOrCreateEntry(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): PerpsSigningCacheEntry {\n const key = this.#getCacheKey(network, userAddress);\n let entry = this.#cache.get(key);\n if (!entry) {\n entry = {\n unifiedAccount: { attempted: false, success: false },\n builderFee: { attempted: false, success: false },\n referral: { attempted: false, success: false },\n timestamp: Date.now(),\n };\n this.#cache.set(key, entry);\n }\n return entry;\n }\n\n // ===== Unified Account Methods =====\n\n /**\n * Get unified account cache entry (legacy compatibility)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public get(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): TradingReadinessCacheEntry | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (!entry) {\n return undefined;\n }\n return {\n attempted: entry.unifiedAccount.attempted,\n enabled: entry.unifiedAccount.success,\n timestamp: entry.timestamp,\n };\n }\n\n /**\n * Set unified account cache entry (legacy compatibility)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param data - The transaction data payload.\n * @param data.attempted - Whether the operation was attempted.\n * @param data.enabled - Whether the feature is enabled.\n */\n public set(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n data: { attempted: boolean; enabled: boolean },\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.unifiedAccount = { attempted: data.attempted, success: data.enabled };\n entry.timestamp = Date.now();\n }\n\n // ===== Builder Fee Methods =====\n\n /**\n * Check if builder fee approval was attempted\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public getBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): SigningOperationState | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n return entry?.builderFee;\n }\n\n /**\n * Set builder fee approval state\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param state - The current state.\n */\n public setBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n state: SigningOperationState,\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.builderFee = state;\n entry.timestamp = Date.now();\n }\n\n // ===== Referral Methods =====\n\n /**\n * Check if referral setup was attempted\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public getReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): SigningOperationState | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n return entry?.referral;\n }\n\n /**\n * Set referral setup state\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param state - The current state.\n */\n public setReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n state: SigningOperationState,\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.referral = state;\n entry.timestamp = Date.now();\n }\n\n // ===== General Methods =====\n\n /**\n * Clear only unified account state for a specific network and user address\n * This preserves builder fee and referral states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearUnifiedAccount(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.unifiedAccount = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear only builder fee state for a specific network and user address\n * This preserves unified account and referral states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.builderFee = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear only referral state for a specific network and user address\n * This preserves unified account and builder fee states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.referral = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear entire cache entry for a specific network and user address\n * WARNING: This clears ALL signing operation states (unifiedAccount, builderFee, referral)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clear(network: 'mainnet' | 'testnet', userAddress: string): void {\n const key = this.#getCacheKey(network, userAddress);\n this.#cache.delete(key);\n }\n\n /**\n * Clear all cache entries\n * WARNING: This clears ALL signing operation states for ALL users\n */\n public clearAll(): void {\n this.#cache.clear();\n }\n\n /**\n * Get all cache entries (for debugging)\n *\n * @returns The result of the operation.\n */\n public getAll(): Map<string, PerpsSigningCacheEntry> {\n return new Map(this.#cache);\n }\n\n /**\n * Get cache size (for debugging)\n *\n * @returns The resulting numeric value.\n */\n public size(): number {\n return this.#cache.size;\n }\n\n /**\n * Get full cache state for debugging\n *\n * @returns The resulting string value.\n */\n public debugState(): string {\n const entries: string[] = [];\n this.#cache.forEach((entry, key) => {\n entries.push(\n `${key}: unified=${entry.unifiedAccount.attempted}/${entry.unifiedAccount.success}, ` +\n `builder=${entry.builderFee.attempted}/${entry.builderFee.success}, ` +\n `referral=${entry.referral.attempted}/${entry.referral.success}`,\n );\n });\n return entries.join('\\n') || '(empty)';\n }\n}\n\n// Export singleton instance with backward-compatible name\nexport const TradingReadinessCache = PerpsSigningCacheManager.getInstance();\n\n// Export with new name for clarity\nexport const PerpsSigningCache = PerpsSigningCacheManager.getInstance();\n"]}
|
|
1
|
+
{"version":3,"file":"TradingReadinessCache.cjs","sourceRoot":"","sources":["../../src/services/TradingReadinessCache.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;;;;;;;;;;;;;AAqBH,MAAM,wBAAwB;IAS5B,8CAA8C;IAC9C;;QAPS,0CAA8C,IAAI,GAAG,EAAE,EAAC;QAEjE,iFAAiF;QACjF,gGAAgG;QACvF,uDAAkD,IAAI,GAAG,EAAE,EAAC;QAInE,sCAAsC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW;;QACvB,+GAAuC,IAAI,EAAwB,EAAE,0CAAA,CAAC;QACtE,OAAO,uBAAA,EAAwB,8CAAU,CAAC;IAC5C,CAAC;IAED,qCAA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U,CAAC,OAAO,IAAI;gBACrE,YAAY,KAAK,CAAC,QAAQ,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CACnE,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC;IACzC,CAAC;CACF;0RAzPc,OAA8B,EAAE,WAAmB;IAC9D,OAAO,GAAG,OAAO,IAAI,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;AACnD,CAAC,mGAGC,OAA8B,EAC9B,WAAmB;IAEnB,MAAM,GAAG,GAAG,uBAAA,IAAI,kFAAa,MAAjB,IAAI,EAAc,OAAO,EAAE,WAAW,CAAC,CAAC;IACpD,IAAI,KAAK,GAAG,uBAAA,IAAI,uCAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG;YACN,cAAc,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YACpD,UAAU,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YAChD,QAAQ,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE;YAC9C,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;QACF,uBAAA,IAAI,uCAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAnFM,sDAAS,CAA2B;AA0T7C,0DAA0D;AAC7C,QAAA,qBAAqB,GAAG,wBAAwB,CAAC,WAAW,EAAE,CAAC;AAE5E,mCAAmC;AACtB,QAAA,iBAAiB,GAAG,wBAAwB,CAAC,WAAW,EAAE,CAAC","sourcesContent":["/**\n * Global singleton cache for Perps signing operations\n *\n * This cache persists across provider reconnections to prevent repeated\n * signing requests for hardware wallets. Critical for preventing repeated\n * hardware wallet signing prompts.\n *\n * Cache is intentionally kept separate from provider instances because providers\n * are recreated on account/network changes, which would reset instance-level caches.\n *\n * Tracks three signing operations:\n * 1. Unified Account enablement (one-time, replaces deprecated DEX abstraction)\n * 2. Builder Fee approval (required for trading)\n * 3. Referral code setup (one-time per account)\n *\n * Cache Structure:\n * - Key: `network:userAddress` (e.g., \"mainnet:0x123...\")\n * - Value: { unifiedAccount, builderFee, referral, timestamp }\n *\n * Lifecycle:\n * - Cache persists throughout app session\n * - Individual entries can be cleared per user/network\n * - Full cache can be cleared on app restart or explicit user action\n */\n\ntype SigningOperationState = {\n attempted: boolean; // Whether we've attempted this operation\n success: boolean; // Whether it succeeded (only valid if attempted=true)\n};\n\ntype PerpsSigningCacheEntry = {\n unifiedAccount: SigningOperationState;\n builderFee: SigningOperationState;\n referral: SigningOperationState;\n timestamp: number; // When this entry was last updated\n};\n\n// Legacy interface for backward compatibility\ntype TradingReadinessCacheEntry = {\n attempted: boolean;\n enabled: boolean;\n timestamp: number;\n};\n\nclass PerpsSigningCacheManager {\n static #instance: PerpsSigningCacheManager;\n\n readonly #cache: Map<string, PerpsSigningCacheEntry> = new Map();\n\n // Global in-flight locks to prevent concurrent signing attempts across providers\n // Key: operationType:network:userAddress, Value: Promise that resolves when operation completes\n readonly #inFlightOperations: Map<string, Promise<void>> = new Map();\n\n // Singleton: use getInstance() instead of new\n protected constructor() {\n // Protected constructor for singleton\n }\n\n public static getInstance(): PerpsSigningCacheManager {\n PerpsSigningCacheManager.#instance ??= new PerpsSigningCacheManager();\n return PerpsSigningCacheManager.#instance;\n }\n\n // ===== In-Flight Lock Methods =====\n\n /**\n * Check if an operation is currently in-flight for this user/network\n *\n * @param operationType - The type of operation being performed.\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public isInFlight(\n operationType: 'unifiedAccount' | 'builderFee' | 'referral',\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): Promise<void> | undefined {\n const key = `${operationType}:${network}:${userAddress.toLowerCase()}`;\n return this.#inFlightOperations.get(key);\n }\n\n /**\n * Set an operation as in-flight\n * Returns a function to call when operation completes\n *\n * @param operationType - The type of operation being performed.\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public setInFlight(\n operationType: 'unifiedAccount' | 'builderFee' | 'referral',\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): () => void {\n const key = `${operationType}:${network}:${userAddress.toLowerCase()}`;\n let resolvePromise: () => void;\n const promise = new Promise<void>((resolve) => {\n resolvePromise = resolve;\n });\n this.#inFlightOperations.set(key, promise);\n return () => {\n this.#inFlightOperations.delete(key);\n resolvePromise();\n };\n }\n\n #getCacheKey(network: 'mainnet' | 'testnet', userAddress: string): string {\n return `${network}:${userAddress.toLowerCase()}`;\n }\n\n #getOrCreateEntry(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): PerpsSigningCacheEntry {\n const key = this.#getCacheKey(network, userAddress);\n let entry = this.#cache.get(key);\n if (!entry) {\n entry = {\n unifiedAccount: { attempted: false, success: false },\n builderFee: { attempted: false, success: false },\n referral: { attempted: false, success: false },\n timestamp: Date.now(),\n };\n this.#cache.set(key, entry);\n }\n return entry;\n }\n\n // ===== Unified Account Methods =====\n\n /**\n * Get unified account cache entry (legacy compatibility)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public get(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): TradingReadinessCacheEntry | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (!entry) {\n return undefined;\n }\n return {\n attempted: entry.unifiedAccount.attempted,\n enabled: entry.unifiedAccount.success,\n timestamp: entry.timestamp,\n };\n }\n\n /**\n * Set unified account cache entry (legacy compatibility)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param data - The transaction data payload.\n * @param data.attempted - Whether the operation was attempted.\n * @param data.enabled - Whether the feature is enabled.\n */\n public set(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n data: { attempted: boolean; enabled: boolean },\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.unifiedAccount = { attempted: data.attempted, success: data.enabled };\n entry.timestamp = Date.now();\n }\n\n // ===== Builder Fee Methods =====\n\n /**\n * Check if builder fee approval was attempted\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public getBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): SigningOperationState | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n return entry?.builderFee;\n }\n\n /**\n * Set builder fee approval state\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param state - The current state.\n */\n public setBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n state: SigningOperationState,\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.builderFee = state;\n entry.timestamp = Date.now();\n }\n\n // ===== Referral Methods =====\n\n /**\n * Check if referral setup was attempted\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @returns The resulting string value.\n */\n public getReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): SigningOperationState | undefined {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n return entry?.referral;\n }\n\n /**\n * Set referral setup state\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n * @param state - The current state.\n */\n public setReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n state: SigningOperationState,\n ): void {\n const entry = this.#getOrCreateEntry(network, userAddress);\n entry.referral = state;\n entry.timestamp = Date.now();\n }\n\n // ===== General Methods =====\n\n /**\n * Clear only unified account state for a specific network and user address\n * This preserves builder fee and referral states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearUnifiedAccount(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.unifiedAccount = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear only builder fee state for a specific network and user address\n * This preserves unified account and referral states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearBuilderFee(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.builderFee = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear only referral state for a specific network and user address\n * This preserves unified account and builder fee states\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clearReferral(\n network: 'mainnet' | 'testnet',\n userAddress: string,\n ): void {\n const key = this.#getCacheKey(network, userAddress);\n const entry = this.#cache.get(key);\n if (entry) {\n entry.referral = { attempted: false, success: false };\n entry.timestamp = Date.now();\n }\n }\n\n /**\n * Clear entire cache entry for a specific network and user address\n * WARNING: This clears ALL signing operation states (unifiedAccount, builderFee, referral)\n *\n * @param network - The network environment.\n * @param userAddress - The user's wallet address.\n */\n public clear(network: 'mainnet' | 'testnet', userAddress: string): void {\n const key = this.#getCacheKey(network, userAddress);\n this.#cache.delete(key);\n }\n\n /**\n * Clear all cache entries\n * WARNING: This clears ALL signing operation states for ALL users\n */\n public clearAll(): void {\n this.#cache.clear();\n }\n\n /**\n * Get all cache entries (for debugging)\n *\n * @returns The result of the operation.\n */\n public getAll(): Map<string, PerpsSigningCacheEntry> {\n return new Map(this.#cache);\n }\n\n /**\n * Get cache size (for debugging)\n *\n * @returns The resulting numeric value.\n */\n public size(): number {\n return this.#cache.size;\n }\n\n /**\n * Get full cache state for debugging\n *\n * @returns The resulting string value.\n */\n public debugState(): string {\n const entries: string[] = [];\n this.#cache.forEach((entry, key) => {\n entries.push(\n `${key}: unified=${entry.unifiedAccount.attempted}/${entry.unifiedAccount.success}, ` +\n `builder=${entry.builderFee.attempted}/${entry.builderFee.success}, ` +\n `referral=${entry.referral.attempted}/${entry.referral.success}`,\n );\n });\n return entries.join('\\n') || '(empty)';\n }\n}\n\n// Export singleton instance with backward-compatible name\nexport const TradingReadinessCache = PerpsSigningCacheManager.getInstance();\n\n// Export with new name for clarity\nexport const PerpsSigningCache = PerpsSigningCacheManager.getInstance();\n"]}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Global singleton cache for Perps signing operations
|
|
3
3
|
*
|
|
4
4
|
* This cache persists across provider reconnections to prevent repeated
|
|
5
|
-
* signing requests for hardware wallets. Critical for preventing
|
|
5
|
+
* signing requests for hardware wallets. Critical for preventing repeated
|
|
6
|
+
* hardware wallet signing prompts.
|
|
6
7
|
*
|
|
7
8
|
* Cache is intentionally kept separate from provider instances because providers
|
|
8
9
|
* are recreated on account/network changes, which would reset instance-level caches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TradingReadinessCache.d.cts","sourceRoot":"","sources":["../../src/services/TradingReadinessCache.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"TradingReadinessCache.d.cts","sourceRoot":"","sources":["../../src/services/TradingReadinessCache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,cAAc,EAAE,qBAAqB,CAAC;IACtC,UAAU,EAAE,qBAAqB,CAAC;IAClC,QAAQ,EAAE,qBAAqB,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAGF,KAAK,0BAA0B,GAAG;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,cAAM,wBAAwB;;IAU5B,SA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AS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,GAClB,IAAI;IASP;;;;;;OAMG;IACI,eAAe,CACpB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,GAClB,IAAI;IASP;;;;;;OAMG;IACI,aAAa,CAClB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,GAClB,IAAI;IASP;;;;;;OAMG;IACI,KAAK,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAKvE;;;OAGG;IACI,QAAQ,IAAI,IAAI;IAIvB;;;;OAIG;IACI,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC;IAIpD;;;;OAIG;IACI,IAAI,IAAI,MAAM;IAIrB;;;;OAIG;IACI,UAAU,IAAI,MAAM;CAW5B;AAGD,eAAO,MAAM,qBAAqB,0BAAyC,CAAC;AAG5E,eAAO,MAAM,iBAAiB,0BAAyC,CAAC"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Global singleton cache for Perps signing operations
|
|
3
3
|
*
|
|
4
4
|
* This cache persists across provider reconnections to prevent repeated
|
|
5
|
-
* signing requests for hardware wallets. Critical for preventing
|
|
5
|
+
* signing requests for hardware wallets. Critical for preventing repeated
|
|
6
|
+
* hardware wallet signing prompts.
|
|
6
7
|
*
|
|
7
8
|
* Cache is intentionally kept separate from provider instances because providers
|
|
8
9
|
* are recreated on account/network changes, which would reset instance-level caches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TradingReadinessCache.d.mts","sourceRoot":"","sources":["../../src/services/TradingReadinessCache.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"TradingReadinessCache.d.mts","sourceRoot":"","sources":["../../src/services/TradingReadinessCache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,KAAK,qBAAqB,GAA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Aa,CAClB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,qBAAqB,GAC3B,IAAI;IAQP;;;;;;OAMG;IACI,WAAW,CAChB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,GAClB,qBAAqB,GAAG,SAAS;IAMpC;;;;;;OAMG;IACI,WAAW,CAChB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,qBAAqB,GAC3B,IAAI;IAQP;;;;;;OAMG;IACI,mBAAmB,CACxB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,GAClB,IAAI;IASP;;;;;;OAMG;IACI,eAAe,CACpB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,GAClB,IAAI;IASP;;;;;;OAMG;IACI,aAAa,CAClB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,GAClB,IAAI;IASP;;;;;;OAMG;IACI,KAAK,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAKvE;;;OAGG;IACI,QAAQ,IAAI,IAAI;IAIvB;;;;OAIG;IACI,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC;IAIpD;;;;OAIG;IACI,IAAI,IAAI,MAAM;IAIrB;;;;OAIG;IACI,UAAU,IAAI,MAAM;CAW5B;AAGD,eAAO,MAAM,qBAAqB,0BAAyC,CAAC;AAG5E,eAAO,MAAM,iBAAiB,0BAAyC,CAAC"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Global singleton cache for Perps signing operations
|
|
3
3
|
*
|
|
4
4
|
* This cache persists across provider reconnections to prevent repeated
|
|
5
|
-
* signing requests for hardware wallets. Critical for preventing
|
|
5
|
+
* signing requests for hardware wallets. Critical for preventing repeated
|
|
6
|
+
* hardware wallet signing prompts.
|
|
6
7
|
*
|
|
7
8
|
* Cache is intentionally kept separate from provider instances because providers
|
|
8
9
|
* are recreated on account/network changes, which would reset instance-level caches.
|