@lifi/perps-sdk 10.0.1 → 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.
- package/dist/cjs/client/PerpsClient.d.ts +6 -2
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +60 -0
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +7 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/services/getReferralActivity.d.ts +11 -0
- package/dist/cjs/services/getReferralActivity.d.ts.map +1 -0
- package/dist/cjs/services/getReferralActivity.js +13 -0
- package/dist/cjs/services/getReferralActivity.js.map +1 -0
- package/dist/cjs/services/getReferralStatus.d.ts +10 -0
- package/dist/cjs/services/getReferralStatus.d.ts.map +1 -0
- package/dist/cjs/services/getReferralStatus.js +12 -0
- package/dist/cjs/services/getReferralStatus.js.map +1 -0
- package/dist/cjs/types/api.d.ts +12 -1
- package/dist/cjs/types/api.d.ts.map +1 -1
- package/dist/cjs/utils/switchChain.d.ts +1 -0
- package/dist/cjs/utils/switchChain.d.ts.map +1 -1
- package/dist/cjs/utils/switchChain.js +9 -5
- package/dist/cjs/utils/switchChain.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/client/PerpsClient.d.ts +49 -2
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +105 -2
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/services/getReferralActivity.d.ts +38 -0
- package/dist/esm/services/getReferralActivity.d.ts.map +1 -0
- package/dist/esm/services/getReferralActivity.js +30 -0
- package/dist/esm/services/getReferralActivity.js.map +1 -0
- package/dist/esm/services/getReferralStatus.d.ts +45 -0
- package/dist/esm/services/getReferralStatus.d.ts.map +1 -0
- package/dist/esm/services/getReferralStatus.js +34 -0
- package/dist/esm/services/getReferralStatus.js.map +1 -0
- package/dist/esm/types/api.d.ts +27 -1
- package/dist/esm/types/api.d.ts.map +1 -1
- package/dist/esm/utils/switchChain.d.ts +7 -2
- package/dist/esm/utils/switchChain.d.ts.map +1 -1
- package/dist/esm/utils/switchChain.js +16 -9
- package/dist/esm/utils/switchChain.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/client/PerpsClient.d.ts +49 -2
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/services/getReferralActivity.d.ts +38 -0
- package/dist/types/services/getReferralActivity.d.ts.map +1 -0
- package/dist/types/services/getReferralStatus.d.ts +45 -0
- package/dist/types/services/getReferralStatus.d.ts.map +1 -0
- package/dist/types/types/api.d.ts +27 -1
- package/dist/types/types/api.d.ts.map +1 -1
- package/dist/types/utils/switchChain.d.ts +7 -2
- package/dist/types/utils/switchChain.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +139 -0
- package/src/index.ts +7 -0
- package/src/services/getReferralActivity.ts +51 -0
- package/src/services/getReferralStatus.ts +57 -0
- package/src/types/api.ts +34 -0
- package/src/utils/switchChain.ts +17 -9
- 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
|
+
}
|
package/src/utils/switchChain.ts
CHANGED
|
@@ -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).
|
|
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
|
-
|
|
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