@lifi/perps-sdk 10.0.2 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/cjs/client/PerpsClient.d.ts +6 -2
  2. package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
  3. package/dist/cjs/client/PerpsClient.js +60 -0
  4. package/dist/cjs/client/PerpsClient.js.map +1 -1
  5. package/dist/cjs/index.d.ts +5 -1
  6. package/dist/cjs/index.d.ts.map +1 -1
  7. package/dist/cjs/index.js +7 -3
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/services/getReferralActivity.d.ts +11 -0
  10. package/dist/cjs/services/getReferralActivity.d.ts.map +1 -0
  11. package/dist/cjs/services/getReferralActivity.js +13 -0
  12. package/dist/cjs/services/getReferralActivity.js.map +1 -0
  13. package/dist/cjs/services/getReferralStatus.d.ts +10 -0
  14. package/dist/cjs/services/getReferralStatus.d.ts.map +1 -0
  15. package/dist/cjs/services/getReferralStatus.js +12 -0
  16. package/dist/cjs/services/getReferralStatus.js.map +1 -0
  17. package/dist/cjs/types/api.d.ts +12 -1
  18. package/dist/cjs/types/api.d.ts.map +1 -1
  19. package/dist/cjs/utils/switchChain.d.ts +1 -0
  20. package/dist/cjs/utils/switchChain.d.ts.map +1 -1
  21. package/dist/cjs/utils/switchChain.js +9 -5
  22. package/dist/cjs/utils/switchChain.js.map +1 -1
  23. package/dist/cjs/version.d.ts +1 -1
  24. package/dist/cjs/version.js +1 -1
  25. package/dist/esm/client/PerpsClient.d.ts +49 -2
  26. package/dist/esm/client/PerpsClient.d.ts.map +1 -1
  27. package/dist/esm/client/PerpsClient.js +105 -2
  28. package/dist/esm/client/PerpsClient.js.map +1 -1
  29. package/dist/esm/index.d.ts +5 -1
  30. package/dist/esm/index.d.ts.map +1 -1
  31. package/dist/esm/index.js +2 -0
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/services/getReferralActivity.d.ts +38 -0
  34. package/dist/esm/services/getReferralActivity.d.ts.map +1 -0
  35. package/dist/esm/services/getReferralActivity.js +30 -0
  36. package/dist/esm/services/getReferralActivity.js.map +1 -0
  37. package/dist/esm/services/getReferralStatus.d.ts +45 -0
  38. package/dist/esm/services/getReferralStatus.d.ts.map +1 -0
  39. package/dist/esm/services/getReferralStatus.js +34 -0
  40. package/dist/esm/services/getReferralStatus.js.map +1 -0
  41. package/dist/esm/types/api.d.ts +27 -1
  42. package/dist/esm/types/api.d.ts.map +1 -1
  43. package/dist/esm/utils/switchChain.d.ts +7 -2
  44. package/dist/esm/utils/switchChain.d.ts.map +1 -1
  45. package/dist/esm/utils/switchChain.js +16 -9
  46. package/dist/esm/utils/switchChain.js.map +1 -1
  47. package/dist/esm/version.d.ts +1 -1
  48. package/dist/esm/version.js +1 -1
  49. package/dist/types/client/PerpsClient.d.ts +49 -2
  50. package/dist/types/client/PerpsClient.d.ts.map +1 -1
  51. package/dist/types/index.d.ts +5 -1
  52. package/dist/types/index.d.ts.map +1 -1
  53. package/dist/types/services/getReferralActivity.d.ts +38 -0
  54. package/dist/types/services/getReferralActivity.d.ts.map +1 -0
  55. package/dist/types/services/getReferralStatus.d.ts +45 -0
  56. package/dist/types/services/getReferralStatus.d.ts.map +1 -0
  57. package/dist/types/types/api.d.ts +27 -1
  58. package/dist/types/types/api.d.ts.map +1 -1
  59. package/dist/types/utils/switchChain.d.ts +7 -2
  60. package/dist/types/utils/switchChain.d.ts.map +1 -1
  61. package/dist/types/version.d.ts +1 -1
  62. package/package.json +2 -2
  63. package/src/client/PerpsClient.ts +139 -0
  64. package/src/index.ts +7 -0
  65. package/src/services/getReferralActivity.ts +51 -0
  66. package/src/services/getReferralStatus.ts +57 -0
  67. package/src/types/api.ts +34 -0
  68. package/src/utils/switchChain.ts +17 -9
  69. package/src/version.ts +1 -1
@@ -0,0 +1,57 @@
1
+ import type { ReferralStatus } from '@lifi/perps-types'
2
+ import type { Address } from 'viem'
3
+ import { buildUrl, request } from '../transport/request.js'
4
+ import type { SDKRequestOptions } from '../types/config.js'
5
+ import type { PerpsSDKClient } from '../types/provider.js'
6
+
7
+ /**
8
+ * Parameters for {@link getReferralStatus}.
9
+ *
10
+ * @public
11
+ */
12
+ export interface GetReferralStatusParams {
13
+ address: Address
14
+ /**
15
+ * Candidate internal referral code to validate in the same read. The
16
+ * response carries the backend's verdict on `candidate`, and reflects the
17
+ * candidate in `onboarding.referralCode` when it is attachable.
18
+ */
19
+ code?: string
20
+ }
21
+
22
+ /**
23
+ * Get an address's onboarding and internal-referral state: terms acceptance,
24
+ * the code attached to it, the code it owns, whether it may create one, the
25
+ * verdict on a candidate code, and the one onboarding step it must sign next.
26
+ * Provider-independent — reads from the platform `meta` surface, not a venue
27
+ * plugin.
28
+ *
29
+ * An address the backend holds no record for resolves to a well-formed
30
+ * payload with `termsAccepted: false` and the optional state fields absent.
31
+ *
32
+ * @throws {PerpsError} On backend error responses, network, or parsing errors.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const client = createPerpsClient({ apiKey: 'your-api-key' })
37
+ * const status = await getReferralStatus(client, {
38
+ * address: '0x1234...',
39
+ * code: 'ABC123',
40
+ * })
41
+ * if (status.onboarding) {
42
+ * // one signature is outstanding; submit it via PerpsClient.submitOnboarding
43
+ * }
44
+ * ```
45
+ * @public
46
+ */
47
+ export async function getReferralStatus(
48
+ client: PerpsSDKClient,
49
+ params: GetReferralStatusParams,
50
+ options?: SDKRequestOptions
51
+ ): Promise<ReferralStatus> {
52
+ const url = buildUrl(`${client.config.apiUrl}/meta/referral`, {
53
+ address: params.address,
54
+ code: params.code,
55
+ })
56
+ return request<ReferralStatus>(client.config, url, {}, options)
57
+ }
package/src/types/api.ts CHANGED
@@ -2,12 +2,16 @@ import type {
2
2
  AccountConfigSetting,
3
3
  AccountResponse,
4
4
  CancelTwapOrderParams as ActionCancelTwapOrderParams,
5
+ CreateReferralCodeParams as ActionCreateReferralCodeParams,
6
+ ActionParamsMap,
5
7
  PlaceTwapOrderParams as ActionPlaceTwapOrderParams,
6
8
  ActionStep,
7
9
  ExecuteActionResponse,
8
10
  MarginMode,
9
11
  MarketRef,
12
+ MetaActionType,
10
13
  ModifyOrderInput,
14
+ OnboardParams,
11
15
  OrderSide,
12
16
  OrderType,
13
17
  SignedActionStep,
@@ -344,3 +348,33 @@ export interface GetAccountResult extends AccountResponse {
344
348
  /** SDK-projected current state of every setup + options descriptor. */
345
349
  settings: AccountConfigSetting[]
346
350
  }
351
+
352
+ /**
353
+ * Parameters for {@link PerpsClient.submitOnboarding}.
354
+ *
355
+ * @public
356
+ */
357
+ export interface SubmitOnboardingParams extends OnboardParams {
358
+ address: Address
359
+ }
360
+
361
+ /**
362
+ * Parameters for {@link PerpsClient.createReferralCode}.
363
+ *
364
+ * @public
365
+ */
366
+ export interface CreateReferralCodeActionParams
367
+ extends ActionCreateReferralCodeParams {
368
+ address: Address
369
+ }
370
+
371
+ /**
372
+ * Parameters for {@link PerpsClient.executeMetaAction}.
373
+ *
374
+ * @public
375
+ */
376
+ export interface ExecuteMetaActionParams<T extends MetaActionType> {
377
+ address: Address
378
+ action: T
379
+ params: ActionParamsMap[T]
380
+ }
@@ -8,12 +8,26 @@ import { getChainId } from 'viem/actions'
8
8
  import { PerpsError } from '../errors/PerpsError.js'
9
9
  import type { PerpsClientSigner, SwitchChainHook } from '../types/config.js'
10
10
 
11
+ /**
12
+ * The chain `actions` are signed on: the first numeric
13
+ * `typedData.domain.chainId` across the batch, or `undefined` when no step
14
+ * carries one.
15
+ */
16
+ export function eip712DomainChainId(actions: ActionStep[]): number | undefined {
17
+ for (const step of actions) {
18
+ const chainId = (step as Eip712ActionStep).typedData?.domain?.chainId
19
+ if (typeof chainId === 'number') {
20
+ return chainId
21
+ }
22
+ }
23
+ return undefined
24
+ }
25
+
11
26
  /**
12
27
  * The chain a batch of `actions` must be signed on, or `undefined` when no
13
28
  * wallet chain switch applies. Only USER-signed EIP-712 batches carry a target
14
29
  * (agent-signed batches sign with a chain-bound keypair; other schemes are not
15
- * EIP-712). Reads the first numeric `typedData.domain.chainId`; a batch whose
16
- * steps omit `chainId` yields `undefined`.
30
+ * EIP-712).
17
31
  */
18
32
  export function userEip712TargetChainId(
19
33
  descriptor: ProviderAction,
@@ -25,13 +39,7 @@ export function userEip712TargetChainId(
25
39
  ) {
26
40
  return undefined
27
41
  }
28
- for (const step of actions) {
29
- const chainId = (step as Eip712ActionStep).typedData?.domain?.chainId
30
- if (typeof chainId === 'number') {
31
- return chainId
32
- }
33
- }
34
- return undefined
42
+ return eip712DomainChainId(actions)
35
43
  }
36
44
 
37
45
  /**
package/src/version.ts CHANGED
@@ -10,4 +10,4 @@ export const name = '@lifi/perps-sdk'
10
10
  *
11
11
  * @public
12
12
  */
13
- export const version = '10.0.2'
13
+ export const version = '10.1.0'