@lifi/perps-types 11.3.0 → 11.4.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 (50) hide show
  1. package/dist/cjs/action.d.ts +3 -0
  2. package/dist/cjs/action.d.ts.map +1 -1
  3. package/dist/cjs/enums.d.ts +2 -0
  4. package/dist/cjs/enums.d.ts.map +1 -1
  5. package/dist/cjs/enums.js +2 -0
  6. package/dist/cjs/enums.js.map +1 -1
  7. package/dist/cjs/index.d.ts +1 -0
  8. package/dist/cjs/index.d.ts.map +1 -1
  9. package/dist/cjs/index.js +1 -0
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/cjs/metaProvider.d.ts +2 -0
  12. package/dist/cjs/metaProvider.d.ts.map +1 -1
  13. package/dist/cjs/metaProvider.js.map +1 -1
  14. package/dist/cjs/referral.d.ts +93 -0
  15. package/dist/cjs/referral.d.ts.map +1 -0
  16. package/dist/cjs/referral.js +28 -0
  17. package/dist/cjs/referral.js.map +1 -0
  18. package/dist/esm/action.d.ts +3 -0
  19. package/dist/esm/action.d.ts.map +1 -1
  20. package/dist/esm/enums.d.ts +4 -0
  21. package/dist/esm/enums.d.ts.map +1 -1
  22. package/dist/esm/enums.js +4 -0
  23. package/dist/esm/enums.js.map +1 -1
  24. package/dist/esm/index.d.ts +1 -0
  25. package/dist/esm/index.d.ts.map +1 -1
  26. package/dist/esm/index.js +1 -0
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/metaProvider.d.ts +8 -0
  29. package/dist/esm/metaProvider.d.ts.map +1 -1
  30. package/dist/esm/metaProvider.js.map +1 -1
  31. package/dist/esm/referral.d.ts +237 -0
  32. package/dist/esm/referral.d.ts.map +1 -0
  33. package/dist/esm/referral.js +46 -0
  34. package/dist/esm/referral.js.map +1 -0
  35. package/dist/types/action.d.ts +3 -0
  36. package/dist/types/action.d.ts.map +1 -1
  37. package/dist/types/enums.d.ts +4 -0
  38. package/dist/types/enums.d.ts.map +1 -1
  39. package/dist/types/index.d.ts +1 -0
  40. package/dist/types/index.d.ts.map +1 -1
  41. package/dist/types/metaProvider.d.ts +8 -0
  42. package/dist/types/metaProvider.d.ts.map +1 -1
  43. package/dist/types/referral.d.ts +237 -0
  44. package/dist/types/referral.d.ts.map +1 -0
  45. package/package.json +1 -1
  46. package/src/action.ts +3 -0
  47. package/src/enums.ts +4 -0
  48. package/src/index.ts +1 -0
  49. package/src/metaProvider.ts +13 -0
  50. package/src/referral.ts +266 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referral.d.ts","sourceRoot":"","sources":["../../src/referral.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExE;;;;GAIG;AACH,oBAAY,qBAAqB;IAC/B,6DAA6D;IAC7D,SAAS,cAAc;IACvB,uDAAuD;IACvD,SAAS,cAAc;IACvB,uDAAuD;IACvD,QAAQ,aAAa;IACrB,uDAAuD;IACvD,aAAa,kBAAkB;IAC/B,2EAA2E;IAC3E,gBAAgB,qBAAqB;IACrC,2EAA2E;IAC3E,YAAY,iBAAiB;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,OAAO,CAAA;IACd,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,qBAAqB,CAAA;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,2DAA2D;IAC3D,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAA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c,CAAC,OAAO,CAAC,CAAA;IAC3B,OAAO,EAAE,yBAAyB,CAAA;CACnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/perps-types",
3
- "version": "11.3.0",
3
+ "version": "11.4.0",
4
4
  "description": "Shared types for the LI.FI perps stack",
5
5
  "keywords": [
6
6
  "lifi",
package/src/action.ts CHANGED
@@ -12,6 +12,7 @@ import type {
12
12
  } from './enums.js'
13
13
  import type { MarketDisplay, MarketRef } from './market.js'
14
14
  import type { Address, Hex } from './primitives.js'
15
+ import type { CreateReferralCodeParams, OnboardParams } from './referral.js'
15
16
  import type { PerpsTypedData } from './typedData.js'
16
17
 
17
18
  /**
@@ -630,6 +631,8 @@ export interface ActionParamsMap {
630
631
  [ActionType.ACCEPT_PROVIDER_TERMS]: Record<string, never>
631
632
  [ActionType.DEPOSIT]: DepositParams
632
633
  [ActionType.META_ACCEPT_TERMS]: AcceptTermsParams
634
+ [ActionType.META_ONBOARD]: OnboardParams
635
+ [ActionType.META_CREATE_REFERRAL_CODE]: CreateReferralCodeParams
633
636
  [ActionType.SYNC_FEE_ATTRIBUTION]: Record<string, never>
634
637
  }
635
638
 
package/src/enums.ts CHANGED
@@ -175,6 +175,10 @@ export enum ActionType {
175
175
  DEPOSIT = 'deposit',
176
176
  /** Provider-independent: sent with the `META_PROVIDER` sentinel, not a real provider key. */
177
177
  META_ACCEPT_TERMS = 'metaAcceptTerms',
178
+ /** Provider-independent composite onboarding consent: the current app-wide terms plus an optional internal referral code, in one signature. */
179
+ META_ONBOARD = 'metaOnboard',
180
+ /** Provider-independent: reserves the shareable internal referral code an address owns. */
181
+ META_CREATE_REFERRAL_CODE = 'metaCreateReferralCode',
178
182
  /** Never projected on `Provider.setup` or `Provider.options`, and never offered as a user-facing trading action. */
179
183
  SYNC_FEE_ATTRIBUTION = 'syncFeeAttribution',
180
184
  }
package/src/index.ts CHANGED
@@ -20,5 +20,6 @@ export * from './positionMargin.js'
20
20
  export * from './primitives.js'
21
21
  export * from './providers.js'
22
22
  export * from './quote.js'
23
+ export * from './referral.js'
23
24
  export * from './subscriptions.js'
24
25
  export * from './typedData.js'
@@ -1,3 +1,5 @@
1
+ import type { ActionType } from './enums.js'
2
+
1
3
  /**
2
4
  * Sentinel sent in the `provider` field for provider-independent actions
3
5
  * (e.g. {@link "./enums.js".ActionType.META_ACCEPT_TERMS}). The backend
@@ -8,3 +10,14 @@ export const META_PROVIDER = 'meta'
8
10
 
9
11
  /** Type alias for the {@link META_PROVIDER} provider-independent sentinel. @public */
10
12
  export type MetaProvider = typeof META_PROVIDER
13
+
14
+ /**
15
+ * The provider-independent actions dispatched with the {@link META_PROVIDER}
16
+ * sentinel. They carry no venue plugin and no `ProviderAction` descriptor, so
17
+ * they are signed as EIP-712 typed data with the end-user's wallet.
18
+ * @public
19
+ */
20
+ export type MetaActionType =
21
+ | ActionType.META_ACCEPT_TERMS
22
+ | ActionType.META_ONBOARD
23
+ | ActionType.META_CREATE_REFERRAL_CODE
@@ -0,0 +1,266 @@
1
+ import type { Pagination } from './account.js'
2
+ import type { Address } from './primitives.js'
3
+ import type { PerpsTypedData, TypedDataParameter } from './typedData.js'
4
+
5
+ /**
6
+ * Reason the backend will not attach a candidate internal referral code to an
7
+ * address. The backend decides; the SDK relays the verdict.
8
+ * @public
9
+ */
10
+ export enum ReferralCodeRejection {
11
+ /** The candidate does not match the accepted code format. */
12
+ MALFORMED = 'MALFORMED',
13
+ /** No internal referral code matches the candidate. */
14
+ NOT_FOUND = 'NOT_FOUND',
15
+ /** The code exists but the backend has disabled it. */
16
+ INACTIVE = 'INACTIVE',
17
+ /** The candidate is the queried address's own code. */
18
+ SELF_REFERRAL = 'SELF_REFERRAL',
19
+ /** The address already has an attached code; attachment is first-touch. */
20
+ ALREADY_ATTACHED = 'ALREADY_ATTACHED',
21
+ /** The address no longer meets the backend's conditions for attachment. */
22
+ NOT_ELIGIBLE = 'NOT_ELIGIBLE',
23
+ }
24
+
25
+ /**
26
+ * Backend verdict for a candidate internal referral code.
27
+ * @public
28
+ */
29
+ export interface ReferralCodeValidation {
30
+ /** The candidate exactly as submitted. */
31
+ code: string
32
+ valid: boolean
33
+ /** Backend-normalized form of `code`; absent when `valid` is false. */
34
+ normalizedCode?: string
35
+ /** Present only when `valid` is false. */
36
+ rejection?: ReferralCodeRejection
37
+ }
38
+
39
+ /**
40
+ * The internal referral code attached to an address. Attachment is first-touch:
41
+ * once the backend records it, it does not change.
42
+ * @public
43
+ */
44
+ export interface AttachedReferralCode {
45
+ /** Normalized code this address is attached to. */
46
+ code: string
47
+ /** Unix epoch milliseconds the attachment was recorded. */
48
+ attachedAt: number
49
+ }
50
+
51
+ /**
52
+ * The shareable internal referral code an address owns.
53
+ * @public
54
+ */
55
+ export interface OwnedReferralCode {
56
+ code: string
57
+ /** Unix epoch milliseconds the code was created. */
58
+ createdAt: number
59
+ /** Number of addresses attached to this code. */
60
+ attachedCount: number
61
+ }
62
+
63
+ /**
64
+ * Whether an address may create an owned internal referral code. The backend
65
+ * owns both the threshold and the decision.
66
+ * @public
67
+ */
68
+ export interface OwnedReferralCodeEligibility {
69
+ eligible: boolean
70
+ /**
71
+ * Executed notional the address must reach, as a decimal string in the
72
+ * backend's reporting currency. Absent when the backend does not disclose it.
73
+ */
74
+ requiredNotional?: string
75
+ /** The address's executed notional so far, in the same units as `requiredNotional`. */
76
+ currentNotional?: string
77
+ }
78
+
79
+ /**
80
+ * What the one pending onboarding signature would commit for an address. A
81
+ * present field is carried by the step; an absent field is not part of it.
82
+ * @public
83
+ */
84
+ export interface OnboardingRequirement {
85
+ /** Terms version the step accepts; absent when the address already accepted the current version. */
86
+ termsVersion?: string
87
+ /** Normalized code the step attaches; absent when the step attaches none. */
88
+ referralCode?: string
89
+ }
90
+
91
+ /**
92
+ * Address-scoped onboarding and internal-referral state, served by
93
+ * `GET /v1/perps/meta/referral?address=`.
94
+ *
95
+ * An address the backend holds no record for still resolves to a well-formed
96
+ * payload: `termsAccepted` is `false` and every optional state field is absent.
97
+ * @public
98
+ */
99
+ export interface ReferralStatus {
100
+ address: Address
101
+ /** Backend-owned version identifier for the current terms. */
102
+ termsVersion: string
103
+ termsAccepted: boolean
104
+ attachedCode?: AttachedReferralCode
105
+ ownedCode?: OwnedReferralCode
106
+ ownedCodeEligibility: OwnedReferralCodeEligibility
107
+ /** Verdict for the request's candidate code; absent when the request passed none. */
108
+ candidate?: ReferralCodeValidation
109
+ /**
110
+ * The one onboarding step to sign next; absent when the backend requires no
111
+ * consent from this address.
112
+ */
113
+ onboarding?: OnboardingRequirement
114
+ }
115
+
116
+ /**
117
+ * One address attached to the queried address's owned internal referral code.
118
+ * @public
119
+ */
120
+ export interface ReferralActivityItem {
121
+ address: Address
122
+ /** Unix epoch milliseconds the attachment was recorded. */
123
+ attachedAt: number
124
+ /**
125
+ * Executed notional recorded against this attachment, as a decimal string in
126
+ * the backend's reporting currency.
127
+ */
128
+ notional: string
129
+ }
130
+
131
+ /**
132
+ * Paginated attachment records for an address's owned internal referral code,
133
+ * served by `GET /v1/perps/meta/referral/activity?address=`.
134
+ *
135
+ * An address that owns no code resolves to `items: []` with `hasMore: false`
136
+ * and no cursor.
137
+ * @public
138
+ */
139
+ export interface ReferralActivityResponse {
140
+ items: ReferralActivityItem[]
141
+ pagination: Pagination
142
+ }
143
+
144
+ /**
145
+ * Params for an {@link "./enums.js".ActionType.META_ONBOARD} action: the terms
146
+ * version to accept and the candidate internal referral code to attach.
147
+ *
148
+ * Both fields are requests, not commitments. The backend decides what the step
149
+ * it returns actually carries, and returns no step when it needs no consent.
150
+ *
151
+ * Provider-independent: sent with the {@link "./metaProvider.js".META_PROVIDER}
152
+ * sentinel in the transport `provider` field.
153
+ * @public
154
+ */
155
+ export interface OnboardParams {
156
+ /** Terms-of-Service version being accepted; backend-owned, relayed verbatim. */
157
+ termsVersion?: string
158
+ /** Candidate code as the client captured it; the backend normalizes it. */
159
+ referralCode?: string
160
+ }
161
+
162
+ /**
163
+ * EIP-712 message body for an `Onboard`. Field order matches
164
+ * {@link onboardTypeFields}.
165
+ *
166
+ * Every mutable field is bound into the digest, so a term the signature does
167
+ * not commit is carried as the empty string rather than dropped.
168
+ * @public
169
+ */
170
+ export interface OnboardMessage {
171
+ /** Human-readable action, e.g. `"Accept LI.FI Perps Terms of Service v3"`. */
172
+ action: string
173
+ account: Address
174
+ /** Terms version accepted, or `''` when the signature accepts no terms. */
175
+ termsVersion: string
176
+ /** Normalized code attached, or `''` when the signature attaches none. */
177
+ referralCode: string
178
+ /** Replay-protection nonce as a decimal string (uint256). */
179
+ nonce: string
180
+ /** Unix timestamp in milliseconds after which the signature is stale. */
181
+ deadline: number
182
+ }
183
+
184
+ /**
185
+ * EIP-712 type member list for the `Onboard` primary type. Field order is part
186
+ * of the signed digest and must match the backend's encoder.
187
+ * @public
188
+ */
189
+ export const onboardTypeFields: readonly TypedDataParameter[] = [
190
+ { name: 'action', type: 'string' },
191
+ { name: 'account', type: 'address' },
192
+ { name: 'termsVersion', type: 'string' },
193
+ { name: 'referralCode', type: 'string' },
194
+ { name: 'nonce', type: 'uint256' },
195
+ { name: 'deadline', type: 'uint256' },
196
+ ]
197
+
198
+ /**
199
+ * EIP-712 typed data for a composite onboarding consent, as returned by
200
+ * `createAction` and signed client-side. `primaryType` is always `'Onboard'`.
201
+ * @public
202
+ */
203
+ export interface OnboardTypedData extends PerpsTypedData {
204
+ primaryType: 'Onboard'
205
+ types: {
206
+ Onboard: readonly TypedDataParameter[]
207
+ } & PerpsTypedData['types']
208
+ message: OnboardMessage
209
+ }
210
+
211
+ /**
212
+ * Params for an
213
+ * {@link "./enums.js".ActionType.META_CREATE_REFERRAL_CODE} action.
214
+ *
215
+ * Provider-independent: sent with the {@link "./metaProvider.js".META_PROVIDER}
216
+ * sentinel in the transport `provider` field.
217
+ * @public
218
+ */
219
+ export interface CreateReferralCodeParams {
220
+ /** Desired code; omit to let the backend generate one. */
221
+ code?: string
222
+ }
223
+
224
+ /**
225
+ * EIP-712 message body for a `CreateReferralCode`. Field order matches
226
+ * {@link createReferralCodeTypeFields}.
227
+ * @public
228
+ */
229
+ export interface CreateReferralCodeMessage {
230
+ /** Human-readable action, e.g. `"Create LI.FI Perps referral code ABC123"`. */
231
+ action: string
232
+ account: Address
233
+ /** Normalized code the signature reserves. */
234
+ code: string
235
+ /** Replay-protection nonce as a decimal string (uint256). */
236
+ nonce: string
237
+ /** Unix timestamp in milliseconds after which the signature is stale. */
238
+ deadline: number
239
+ }
240
+
241
+ /**
242
+ * EIP-712 type member list for the `CreateReferralCode` primary type. Field
243
+ * order is part of the signed digest and must match the backend's encoder.
244
+ * @public
245
+ */
246
+ export const createReferralCodeTypeFields: readonly TypedDataParameter[] = [
247
+ { name: 'action', type: 'string' },
248
+ { name: 'account', type: 'address' },
249
+ { name: 'code', type: 'string' },
250
+ { name: 'nonce', type: 'uint256' },
251
+ { name: 'deadline', type: 'uint256' },
252
+ ]
253
+
254
+ /**
255
+ * EIP-712 typed data for reserving an owned internal referral code, as
256
+ * returned by `createAction` and signed client-side. `primaryType` is always
257
+ * `'CreateReferralCode'`.
258
+ * @public
259
+ */
260
+ export interface CreateReferralCodeTypedData extends PerpsTypedData {
261
+ primaryType: 'CreateReferralCode'
262
+ types: {
263
+ CreateReferralCode: readonly TypedDataParameter[]
264
+ } & PerpsTypedData['types']
265
+ message: CreateReferralCodeMessage
266
+ }