@lifi/perps-sdk 0.0.0-preview-13dcf3c7 → 0.0.0-preview-e0a0e165
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/README.md +28 -1
- package/dist/cjs/client/PerpsClient.d.ts +1 -0
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +17 -8
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/services/getMeta.d.ts.map +1 -1
- package/dist/cjs/services/getMeta.js.map +1 -1
- package/dist/cjs/types/provider.d.ts +1 -1
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/types/withdrawal.d.ts.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 +11 -3
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +28 -12
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/services/getMeta.d.ts +5 -2
- package/dist/esm/services/getMeta.d.ts.map +1 -1
- package/dist/esm/services/getMeta.js +5 -2
- package/dist/esm/services/getMeta.js.map +1 -1
- package/dist/esm/types/provider.d.ts +4 -2
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/types/withdrawal.d.ts +14 -2
- package/dist/esm/types/withdrawal.d.ts.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 +11 -3
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/services/getMeta.d.ts +5 -2
- package/dist/types/services/getMeta.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +4 -2
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/types/withdrawal.d.ts +14 -2
- package/dist/types/types/withdrawal.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +5 -3
- package/src/client/PerpsClient.ts +44 -13
- package/src/services/getMeta.ts +5 -2
- package/src/types/provider.ts +7 -2
- package/src/types/withdrawal.ts +14 -2
- package/src/version.ts +1 -1
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
PerpsErrorCode,
|
|
31
31
|
PerpsSigner,
|
|
32
32
|
SigningMethod,
|
|
33
|
+
UserActionStatus,
|
|
33
34
|
} from '@lifi/perps-types'
|
|
34
35
|
import type { Address } from 'viem'
|
|
35
36
|
import { isDecimalStringGreaterThan } from '../decimal/compare.js'
|
|
@@ -494,7 +495,8 @@ export class PerpsClient {
|
|
|
494
495
|
* Submit `signed` to `/executeAction` when every step the plugin executed
|
|
495
496
|
* while signing was acknowledged, then resolve explorer links and notify the
|
|
496
497
|
* plugin. Resolves to the full report: `executed`, then the `/executeAction`
|
|
497
|
-
* results
|
|
498
|
+
* results, with `retry` set when the plugin asked for one more attempt. An
|
|
499
|
+
* empty report means nothing executed.
|
|
498
500
|
*
|
|
499
501
|
* @throws {PerpsExecutionError} When the submission or the plugin callback
|
|
500
502
|
* throws after a result is known.
|
|
@@ -505,7 +507,7 @@ export class PerpsClient {
|
|
|
505
507
|
action: ActionType,
|
|
506
508
|
signerAddress: Address | undefined,
|
|
507
509
|
{ signed, executed }: SignActionsResult
|
|
508
|
-
): Promise<ActionResult[]> {
|
|
510
|
+
): Promise<{ results: ActionResult[]; retry: boolean }> {
|
|
509
511
|
let results = executed
|
|
510
512
|
if (signed.length > 0 && executed.every(isSubmittedOrAccepted)) {
|
|
511
513
|
try {
|
|
@@ -524,31 +526,34 @@ export class PerpsClient {
|
|
|
524
526
|
}
|
|
525
527
|
}
|
|
526
528
|
if (results.length === 0) {
|
|
527
|
-
return results
|
|
529
|
+
return { results, retry: false }
|
|
528
530
|
}
|
|
529
531
|
|
|
532
|
+
let retry = false
|
|
530
533
|
try {
|
|
531
534
|
results = this.resolveExplorerLinks(provider, results)
|
|
532
|
-
await this.notifyExecuteResults(provider, address, results)
|
|
535
|
+
retry = await this.notifyExecuteResults(provider, address, results)
|
|
533
536
|
} catch (error) {
|
|
534
537
|
rethrowWithKnownResults(results, error)
|
|
535
538
|
}
|
|
536
|
-
return results
|
|
539
|
+
return { results, retry }
|
|
537
540
|
}
|
|
538
541
|
|
|
539
542
|
/**
|
|
540
543
|
* Let the plugin observe an execution report before the core returns it —
|
|
541
|
-
* e.g. to evict a locally stored credential the venue refused.
|
|
544
|
+
* e.g. to evict a locally stored credential the venue refused. Resolves
|
|
545
|
+
* `true` when the plugin asks for one more attempt.
|
|
542
546
|
*/
|
|
543
547
|
private async notifyExecuteResults(
|
|
544
548
|
provider: string,
|
|
545
549
|
address: Address,
|
|
546
550
|
results: ActionResult[]
|
|
547
|
-
): Promise<
|
|
551
|
+
): Promise<boolean> {
|
|
548
552
|
const plugin = this.requireProvider(provider)
|
|
549
|
-
if (typeof plugin.onExecuteResults
|
|
550
|
-
|
|
553
|
+
if (typeof plugin.onExecuteResults !== 'function') {
|
|
554
|
+
return false
|
|
551
555
|
}
|
|
556
|
+
return (await plugin.onExecuteResults(address, results)) === 'retry'
|
|
552
557
|
}
|
|
553
558
|
|
|
554
559
|
/**
|
|
@@ -692,13 +697,14 @@ export class PerpsClient {
|
|
|
692
697
|
} catch (error) {
|
|
693
698
|
rethrowWithKnownResults(signResult.executed, error)
|
|
694
699
|
}
|
|
695
|
-
|
|
700
|
+
const { results } = await this.submitSignedActions(
|
|
696
701
|
provider,
|
|
697
702
|
address,
|
|
698
703
|
step.action,
|
|
699
704
|
signerAddress,
|
|
700
705
|
signResult
|
|
701
706
|
)
|
|
707
|
+
return results
|
|
702
708
|
}
|
|
703
709
|
|
|
704
710
|
/**
|
|
@@ -1629,7 +1635,11 @@ export class PerpsClient {
|
|
|
1629
1635
|
return { results }
|
|
1630
1636
|
}
|
|
1631
1637
|
|
|
1632
|
-
/**
|
|
1638
|
+
/**
|
|
1639
|
+
* {@link execute}, also returning the steps `createAction` staged. Runs the
|
|
1640
|
+
* action once more when the plugin asks for it and nothing took effect; the
|
|
1641
|
+
* second attempt's report is the answer.
|
|
1642
|
+
*/
|
|
1633
1643
|
private async runAction<T extends ActionType>(params: {
|
|
1634
1644
|
provider: string
|
|
1635
1645
|
address: Address
|
|
@@ -1637,6 +1647,27 @@ export class PerpsClient {
|
|
|
1637
1647
|
params: ActionParamsMap[T]
|
|
1638
1648
|
onProgress?: (progress: SignActionProgress) => void
|
|
1639
1649
|
}): Promise<{ staged: ActionStep[]; results: ActionResult[] }> {
|
|
1650
|
+
const first = await this.attemptAction(params)
|
|
1651
|
+
const nothingApplied = first.results.every(
|
|
1652
|
+
(result) => result.status === UserActionStatus.Failed
|
|
1653
|
+
)
|
|
1654
|
+
const { staged, results } =
|
|
1655
|
+
first.retry && nothingApplied ? await this.attemptAction(params) : first
|
|
1656
|
+
return { staged, results }
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
/** Create, sign and submit `action` once. */
|
|
1660
|
+
private async attemptAction<T extends ActionType>(params: {
|
|
1661
|
+
provider: string
|
|
1662
|
+
address: Address
|
|
1663
|
+
action: T
|
|
1664
|
+
params: ActionParamsMap[T]
|
|
1665
|
+
onProgress?: (progress: SignActionProgress) => void
|
|
1666
|
+
}): Promise<{
|
|
1667
|
+
staged: ActionStep[]
|
|
1668
|
+
results: ActionResult[]
|
|
1669
|
+
retry: boolean
|
|
1670
|
+
}> {
|
|
1640
1671
|
const { provider, address, action, onProgress } = params
|
|
1641
1672
|
const metadata = await this.getProviderMetadata(provider)
|
|
1642
1673
|
const descriptor = findActionDescriptor(metadata, action)
|
|
@@ -1663,14 +1694,14 @@ export class PerpsClient {
|
|
|
1663
1694
|
onProgress
|
|
1664
1695
|
)
|
|
1665
1696
|
|
|
1666
|
-
const results = await this.submitSignedActions(
|
|
1697
|
+
const { results, retry } = await this.submitSignedActions(
|
|
1667
1698
|
provider,
|
|
1668
1699
|
address,
|
|
1669
1700
|
action,
|
|
1670
1701
|
signerAddress,
|
|
1671
1702
|
signResult
|
|
1672
1703
|
)
|
|
1673
|
-
return { staged: actions, results }
|
|
1704
|
+
return { staged: actions, results, retry }
|
|
1674
1705
|
}
|
|
1675
1706
|
|
|
1676
1707
|
/**
|
package/src/services/getMeta.ts
CHANGED
|
@@ -4,9 +4,12 @@ import type { SDKRequestOptions } from '../types/config.js'
|
|
|
4
4
|
import type { PerpsSDKClient } from '../types/provider.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Get platform metadata: the API version and
|
|
7
|
+
* Get platform metadata: the API version and the notices the backend serves.
|
|
8
|
+
* A notice without `providerKeys` is global; a notice with `providerKeys` is
|
|
9
|
+
* scoped to those providers. The SDK returns notices as served and does not
|
|
10
|
+
* filter them by `validFrom` / `validTo`.
|
|
8
11
|
*
|
|
9
|
-
* @returns Platform version and the
|
|
12
|
+
* @returns Platform version and the global and provider-scoped notices
|
|
10
13
|
* @throws {PerpsError} On API error responses
|
|
11
14
|
* @throws {PerpsError} On network or parsing errors
|
|
12
15
|
*
|
package/src/types/provider.ts
CHANGED
|
@@ -758,9 +758,14 @@ export interface PerpsProviderPlugin {
|
|
|
758
758
|
* Observe the execution report of each `execute` call: the results of the
|
|
759
759
|
* steps the plugin executed while signing, then the `/executeAction`
|
|
760
760
|
* results. Lets a provider react to structured statuses — e.g. evicting a
|
|
761
|
-
* locally stored credential the venue refused.
|
|
761
|
+
* locally stored credential the venue refused. Resolve to `'retry'` to have
|
|
762
|
+
* core create, sign and execute the action once more; core retries at most
|
|
763
|
+
* once per `execute`, and only when every result is `Failed`.
|
|
762
764
|
*/
|
|
763
|
-
onExecuteResults?(
|
|
765
|
+
onExecuteResults?(
|
|
766
|
+
address: Address,
|
|
767
|
+
results: ActionResult[]
|
|
768
|
+
): Promise<'retry' | void>
|
|
764
769
|
|
|
765
770
|
/**
|
|
766
771
|
* Resolve a venue transaction hash to a block-explorer URL. Core calls it for
|
package/src/types/withdrawal.ts
CHANGED
|
@@ -16,7 +16,13 @@ import type { Address } from 'viem'
|
|
|
16
16
|
export interface ProviderWithdrawableBalance {
|
|
17
17
|
/** Provider-native `Asset.id`; never a display symbol. */
|
|
18
18
|
assetId: string
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* The withdrawal route: the provider category that a withdrawal from this row
|
|
21
|
+
* names. On a pooled account, a row can name a category that has no `Balance`
|
|
22
|
+
* row of the same asset. For example, a pooled collateral asset is one `spot`
|
|
23
|
+
* `Balance` row, but its withdrawable row names a `perps` or `hyperliquid`
|
|
24
|
+
* route. Do not join a withdrawable row to a `Balance` row by this value.
|
|
25
|
+
*/
|
|
20
26
|
categoryId: string
|
|
21
27
|
/** Withdrawable amount in the asset's own units. Always greater than zero. */
|
|
22
28
|
available: DecimalString
|
|
@@ -49,7 +55,13 @@ export interface ProviderWithdrawableBalance {
|
|
|
49
55
|
*/
|
|
50
56
|
export interface WithdrawableBalance {
|
|
51
57
|
asset: Asset
|
|
52
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* The withdrawal route: the provider category that a withdrawal from this row
|
|
60
|
+
* names. On a pooled account, a row can name a category that has no `Balance`
|
|
61
|
+
* row of the same asset. For example, a pooled collateral asset is one `spot`
|
|
62
|
+
* `Balance` row, but its withdrawable row names a `perps` or `hyperliquid`
|
|
63
|
+
* route. Do not join a withdrawable row to a `Balance` row by this value.
|
|
64
|
+
*/
|
|
53
65
|
categoryId: string
|
|
54
66
|
/** Withdrawable amount in the asset's own units. */
|
|
55
67
|
available: DecimalString
|
package/src/version.ts
CHANGED