@lifi/perps-sdk 0.0.0-preview-9f07ebf → 0.0.0-preview-ba2d335
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 +0 -1
- package/dist/cjs/client/PerpsClient.d.ts.map +1 -1
- package/dist/cjs/client/PerpsClient.js +0 -35
- package/dist/cjs/client/PerpsClient.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/storage/encryptedStorage.d.ts +3 -0
- package/dist/cjs/storage/encryptedStorage.d.ts.map +1 -0
- package/dist/cjs/storage/encryptedStorage.js +124 -0
- package/dist/cjs/storage/encryptedStorage.js.map +1 -0
- package/dist/cjs/storage/storage.d.ts +0 -1
- package/dist/cjs/storage/storage.d.ts.map +1 -1
- package/dist/cjs/storage/storage.js +0 -27
- package/dist/cjs/storage/storage.js.map +1 -1
- package/dist/cjs/types/provider.d.ts +1 -2
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/utils/depositChain.d.ts +1 -1
- package/dist/cjs/utils/depositChain.d.ts.map +1 -1
- package/dist/cjs/utils/depositChain.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 +0 -8
- package/dist/esm/client/PerpsClient.d.ts.map +1 -1
- package/dist/esm/client/PerpsClient.js +1 -45
- package/dist/esm/client/PerpsClient.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/storage/encryptedStorage.d.ts +22 -0
- package/dist/esm/storage/encryptedStorage.d.ts.map +1 -0
- package/dist/esm/storage/encryptedStorage.js +149 -0
- package/dist/esm/storage/encryptedStorage.js.map +1 -0
- package/dist/esm/storage/storage.d.ts +0 -7
- package/dist/esm/storage/storage.d.ts.map +1 -1
- package/dist/esm/storage/storage.js +0 -34
- package/dist/esm/storage/storage.js.map +1 -1
- package/dist/esm/types/provider.d.ts +1 -12
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/utils/depositChain.d.ts +2 -4
- package/dist/esm/utils/depositChain.d.ts.map +1 -1
- package/dist/esm/utils/depositChain.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 +0 -8
- package/dist/types/client/PerpsClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/storage/encryptedStorage.d.ts +22 -0
- package/dist/types/storage/encryptedStorage.d.ts.map +1 -0
- package/dist/types/storage/storage.d.ts +0 -7
- package/dist/types/storage/storage.d.ts.map +1 -1
- package/dist/types/types/provider.d.ts +1 -12
- package/dist/types/types/provider.d.ts.map +1 -1
- package/dist/types/utils/depositChain.d.ts +2 -4
- package/dist/types/utils/depositChain.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/client/PerpsClient.ts +1 -74
- package/src/index.ts +2 -1
- package/src/storage/encryptedStorage.ts +171 -0
- package/src/storage/storage.ts +0 -34
- package/src/types/provider.ts +0 -18
- package/src/utils/depositChain.ts +4 -5
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,UAAU,EACV,UAAU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AM,CAAC,CAAA"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { AccountConfig } from '@lifi/perps-types';
|
|
2
2
|
import { ChainId } from '@lifi/types';
|
|
3
3
|
/**
|
|
4
|
-
* Perps provider keys that
|
|
5
|
-
* from the map means the provider is not funded via a LI.FI swap (e.g. ondo's
|
|
6
|
-
* custodial provisioned-address deposits).
|
|
4
|
+
* Perps provider keys that have a declared LI.FI deposit-target chain.
|
|
7
5
|
*
|
|
8
6
|
* @public
|
|
9
7
|
*/
|
|
@@ -15,7 +13,7 @@ export type DepositProviderKey = AccountConfig['provider'];
|
|
|
15
13
|
*
|
|
16
14
|
* @public
|
|
17
15
|
*/
|
|
18
|
-
export declare const LIFI_DEPOSIT_CHAIN_BY_PROVIDER:
|
|
16
|
+
export declare const LIFI_DEPOSIT_CHAIN_BY_PROVIDER: Record<DepositProviderKey, ChainId>;
|
|
19
17
|
/**
|
|
20
18
|
* Resolve the LI.FI deposit-target chain for a perps provider key.
|
|
21
19
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depositChain.d.ts","sourceRoot":"","sources":["../../../src/utils/depositChain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC
|
|
1
|
+
{"version":3,"file":"depositChain.d.ts","sourceRoot":"","sources":["../../../src/utils/depositChain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAAC,UAAU,CAAC,CAAA;AAE1D;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAM,CACjD,kBAAkB,EAClB,OAAO,CAIR,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,GAClB,OAAO,GAAG,SAAS,CAErB"}
|
package/dist/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/perps-sdk",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-ba2d335",
|
|
4
4
|
"description": "LI.FI Perps SDK for perpetuals trading",
|
|
5
5
|
"homepage": "https://github.com/lifinance/perps-sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@lifi/types": "17.82.1",
|
|
45
45
|
"partysocket": "^1.1.19",
|
|
46
46
|
"viem": "^2.48.8",
|
|
47
|
-
"@lifi/perps-types": "^
|
|
47
|
+
"@lifi/perps-types": "^1.14.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
@@ -9,10 +9,9 @@ import type {
|
|
|
9
9
|
Position,
|
|
10
10
|
Provider,
|
|
11
11
|
ProviderAction,
|
|
12
|
-
RestCallSignedActionStep,
|
|
13
12
|
SignedActionStep,
|
|
14
13
|
} from '@lifi/perps-types'
|
|
15
|
-
import { ActionType, PerpsErrorCode
|
|
14
|
+
import { ActionType, PerpsErrorCode } from '@lifi/perps-types'
|
|
16
15
|
import type { Address } from 'viem'
|
|
17
16
|
import { PerpsError } from '../errors/PerpsError.js'
|
|
18
17
|
import { createAction } from '../services/createAction.js'
|
|
@@ -759,16 +758,6 @@ export class PerpsClient {
|
|
|
759
758
|
actions
|
|
760
759
|
)
|
|
761
760
|
|
|
762
|
-
if (descriptor.signingMethod === SigningMethod.AUTH_TOKEN) {
|
|
763
|
-
return this.executeAuthTokenActions(
|
|
764
|
-
provider,
|
|
765
|
-
address,
|
|
766
|
-
signerAddress ?? address,
|
|
767
|
-
action,
|
|
768
|
-
signedActions
|
|
769
|
-
)
|
|
770
|
-
}
|
|
771
|
-
|
|
772
761
|
// A plugin may execute an action entirely client-side (e.g. Lighter's
|
|
773
762
|
// token-authenticated venue mutations), leaving no backend-bound step. With
|
|
774
763
|
// nothing to submit, skip the `/executeAction` hop.
|
|
@@ -786,66 +775,4 @@ export class PerpsClient {
|
|
|
786
775
|
actions: signedActions,
|
|
787
776
|
})
|
|
788
777
|
}
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* The `AUTH_TOKEN` arm of {@link execute}: the venue call runs client-side
|
|
792
|
-
* via the plugin's `executeRestCallActions` because the credential headers
|
|
793
|
-
* must never transit the LI.FI backend. The venue's results are what the
|
|
794
|
-
* caller gets; the backend `executeAction` submission that follows is
|
|
795
|
-
* bookkeeping only, sent with `headers` stripped.
|
|
796
|
-
*/
|
|
797
|
-
private async executeAuthTokenActions(
|
|
798
|
-
provider: string,
|
|
799
|
-
address: Address,
|
|
800
|
-
signerAddress: Address,
|
|
801
|
-
action: ActionType,
|
|
802
|
-
signedActions: SignedActionStep[]
|
|
803
|
-
): Promise<ExecuteActionResponse> {
|
|
804
|
-
const plugin = this.requireProvider(provider)
|
|
805
|
-
if (typeof plugin.executeRestCallActions !== 'function') {
|
|
806
|
-
throw new PerpsError(
|
|
807
|
-
PerpsErrorCode.SDKError,
|
|
808
|
-
`Provider '${provider}' does not implement executeRestCallActions ` +
|
|
809
|
-
`for signingMethod 'authToken'.`
|
|
810
|
-
)
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
const restCallSteps = signedActions.map(
|
|
814
|
-
(step): RestCallSignedActionStep => {
|
|
815
|
-
if (!('request' in step) || !('headers' in step)) {
|
|
816
|
-
throw new PerpsError(
|
|
817
|
-
PerpsErrorCode.SDKError,
|
|
818
|
-
`Provider '${provider}' signed action '${step.action}' with a ` +
|
|
819
|
-
`non-rest-call step for signingMethod 'authToken'.`
|
|
820
|
-
)
|
|
821
|
-
}
|
|
822
|
-
return step
|
|
823
|
-
}
|
|
824
|
-
)
|
|
825
|
-
|
|
826
|
-
const results = await plugin.executeRestCallActions(restCallSteps, address)
|
|
827
|
-
|
|
828
|
-
try {
|
|
829
|
-
await executeAction(this.sdkClient, {
|
|
830
|
-
provider,
|
|
831
|
-
address,
|
|
832
|
-
signerAddress,
|
|
833
|
-
action,
|
|
834
|
-
actions: restCallSteps.map((step) => ({
|
|
835
|
-
action: step.action,
|
|
836
|
-
request: step.request,
|
|
837
|
-
headers: {},
|
|
838
|
-
})),
|
|
839
|
-
})
|
|
840
|
-
} catch (error) {
|
|
841
|
-
// The venue call already succeeded above — a failed bookkeeping
|
|
842
|
-
// submission must not mask a landed order, so it is logged, not thrown.
|
|
843
|
-
console.error(
|
|
844
|
-
`[${provider}] backend bookkeeping submission failed after venue execution`,
|
|
845
|
-
error
|
|
846
|
-
)
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
return { results }
|
|
850
|
-
}
|
|
851
778
|
}
|
package/src/index.ts
CHANGED
|
@@ -64,11 +64,12 @@ export {
|
|
|
64
64
|
QUOTE_THROTTLE_MS,
|
|
65
65
|
resolveSubscribeQuote,
|
|
66
66
|
} from './services/resolveSubscribeQuote.js'
|
|
67
|
+
export { localStorageAdapter } from './storage/encryptedStorage.js'
|
|
67
68
|
export {
|
|
68
69
|
parseStoredRecord,
|
|
69
70
|
readValidatedRecord,
|
|
70
71
|
} from './storage/parseStoredRecord.js'
|
|
71
|
-
export { createMemoryStorage
|
|
72
|
+
export { createMemoryStorage } from './storage/storage.js'
|
|
72
73
|
export type { StorageAdapter } from './storage/types.js'
|
|
73
74
|
export type { FetchWithRetryOptions } from './transport/fetchWithRetry.js'
|
|
74
75
|
export { fetchWithRetry } from './transport/fetchWithRetry.js'
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import type { StorageAdapter } from './types.js'
|
|
2
|
+
|
|
3
|
+
const DB_NAME = 'lifi-perps-sdk'
|
|
4
|
+
const OBJECT_STORE = 'keys'
|
|
5
|
+
const MASTER_KEY_ID = 'storage-master-key'
|
|
6
|
+
const IV_BYTE_LENGTH = 12
|
|
7
|
+
const AES_KEY_PARAMS = { name: 'AES-GCM', length: 256 } as const
|
|
8
|
+
|
|
9
|
+
let masterKeyPromise: Promise<CryptoKey | null> | undefined
|
|
10
|
+
|
|
11
|
+
function openDb(): Promise<IDBDatabase> {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const request = indexedDB.open(DB_NAME, 1)
|
|
14
|
+
request.onupgradeneeded = () => {
|
|
15
|
+
request.result.createObjectStore(OBJECT_STORE)
|
|
16
|
+
}
|
|
17
|
+
request.onsuccess = () => resolve(request.result)
|
|
18
|
+
request.onerror = () => reject(request.error)
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function requestToPromise<T>(request: IDBRequest<T>): Promise<T> {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
request.onsuccess = () => resolve(request.result)
|
|
25
|
+
request.onerror = () => reject(request.error)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the AES-GCM master key, generating and persisting one on first use.
|
|
31
|
+
* The key is non-extractable and lives as a structured-cloned handle in
|
|
32
|
+
* IndexedDB — the raw bytes never leave the browser's crypto layer. Resolves
|
|
33
|
+
* `null` when IndexedDB or WebCrypto is unavailable so callers degrade to
|
|
34
|
+
* no-op writes / null reads rather than persisting plaintext.
|
|
35
|
+
*/
|
|
36
|
+
async function loadMasterKey(): Promise<CryptoKey | null> {
|
|
37
|
+
if (
|
|
38
|
+
typeof indexedDB === 'undefined' ||
|
|
39
|
+
typeof crypto === 'undefined' ||
|
|
40
|
+
!crypto.subtle
|
|
41
|
+
) {
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const db = await openDb()
|
|
46
|
+
try {
|
|
47
|
+
const existing = await requestToPromise(
|
|
48
|
+
db
|
|
49
|
+
.transaction(OBJECT_STORE, 'readonly')
|
|
50
|
+
.objectStore(OBJECT_STORE)
|
|
51
|
+
.get(MASTER_KEY_ID)
|
|
52
|
+
)
|
|
53
|
+
if (existing instanceof CryptoKey) {
|
|
54
|
+
return existing
|
|
55
|
+
}
|
|
56
|
+
const key = await crypto.subtle.generateKey(AES_KEY_PARAMS, false, [
|
|
57
|
+
'encrypt',
|
|
58
|
+
'decrypt',
|
|
59
|
+
])
|
|
60
|
+
await requestToPromise(
|
|
61
|
+
db
|
|
62
|
+
.transaction(OBJECT_STORE, 'readwrite')
|
|
63
|
+
.objectStore(OBJECT_STORE)
|
|
64
|
+
.put(key, MASTER_KEY_ID)
|
|
65
|
+
)
|
|
66
|
+
return key
|
|
67
|
+
} finally {
|
|
68
|
+
db.close()
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
return null
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getMasterKey(): Promise<CryptoKey | null> {
|
|
76
|
+
masterKeyPromise ??= loadMasterKey()
|
|
77
|
+
return masterKeyPromise
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function bytesToBase64(bytes: Uint8Array): string {
|
|
81
|
+
let binary = ''
|
|
82
|
+
for (const byte of bytes) {
|
|
83
|
+
binary += String.fromCharCode(byte)
|
|
84
|
+
}
|
|
85
|
+
return btoa(binary)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function base64ToBytes(value: string): Uint8Array {
|
|
89
|
+
const binary = atob(value)
|
|
90
|
+
const bytes = new Uint8Array(binary.length)
|
|
91
|
+
for (let i = 0; i < binary.length; i += 1) {
|
|
92
|
+
bytes[i] = binary.charCodeAt(i)
|
|
93
|
+
}
|
|
94
|
+
return bytes
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Default storage adapter: persists AES-GCM-256 ciphertext to browser
|
|
99
|
+
* `localStorage`, keyed by a non-extractable master {@link CryptoKey} held in
|
|
100
|
+
* IndexedDB. Each `set` uses a fresh 12-byte IV and
|
|
101
|
+
* stores `base64(iv ‖ ciphertext)`. Falls back to a no-op / `null` when
|
|
102
|
+
* `localStorage`, `indexedDB`, or `crypto.subtle` is unavailable (e.g. SSR) —
|
|
103
|
+
* never writing plaintext.
|
|
104
|
+
*
|
|
105
|
+
* `get` resolves `null` on any failure (missing master key, tampered or
|
|
106
|
+
* truncated ciphertext, malformed value), matching the poisoned-record
|
|
107
|
+
* eviction philosophy so callers treat undecryptable data as absent.
|
|
108
|
+
*
|
|
109
|
+
* @security Encryption at rest defeats generic browser-storage/disk scanning
|
|
110
|
+
* and raw key exfiltration, not malware targeting this SDK or a fully
|
|
111
|
+
* compromised page — a same-origin script can still drive this adapter to
|
|
112
|
+
* decrypt.
|
|
113
|
+
*
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
export const localStorageAdapter: StorageAdapter = {
|
|
117
|
+
async get(key: string): Promise<string | null> {
|
|
118
|
+
try {
|
|
119
|
+
const raw = localStorage.getItem(key)
|
|
120
|
+
if (raw === null) {
|
|
121
|
+
return null
|
|
122
|
+
}
|
|
123
|
+
const masterKey = await getMasterKey()
|
|
124
|
+
if (!masterKey) {
|
|
125
|
+
return null
|
|
126
|
+
}
|
|
127
|
+
const combined = base64ToBytes(raw)
|
|
128
|
+
const iv = combined.slice(0, IV_BYTE_LENGTH)
|
|
129
|
+
const ciphertext = combined.slice(IV_BYTE_LENGTH)
|
|
130
|
+
const plaintext = await crypto.subtle.decrypt(
|
|
131
|
+
{ name: 'AES-GCM', iv },
|
|
132
|
+
masterKey,
|
|
133
|
+
ciphertext
|
|
134
|
+
)
|
|
135
|
+
return new TextDecoder().decode(plaintext)
|
|
136
|
+
} catch {
|
|
137
|
+
return null
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
async set(key: string, value: string): Promise<void> {
|
|
142
|
+
try {
|
|
143
|
+
const masterKey = await getMasterKey()
|
|
144
|
+
if (!masterKey) {
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
const iv = crypto.getRandomValues(new Uint8Array(IV_BYTE_LENGTH))
|
|
148
|
+
const ciphertext = new Uint8Array(
|
|
149
|
+
await crypto.subtle.encrypt(
|
|
150
|
+
{ name: 'AES-GCM', iv },
|
|
151
|
+
masterKey,
|
|
152
|
+
new TextEncoder().encode(value)
|
|
153
|
+
)
|
|
154
|
+
)
|
|
155
|
+
const combined = new Uint8Array(iv.length + ciphertext.length)
|
|
156
|
+
combined.set(iv, 0)
|
|
157
|
+
combined.set(ciphertext, iv.length)
|
|
158
|
+
localStorage.setItem(key, bytesToBase64(combined))
|
|
159
|
+
} catch {
|
|
160
|
+
// localStorage/crypto unavailable or encryption failed — never persist plaintext
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
async remove(key: string): Promise<void> {
|
|
165
|
+
try {
|
|
166
|
+
localStorage.removeItem(key)
|
|
167
|
+
} catch {
|
|
168
|
+
// localStorage not available
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
}
|
package/src/storage/storage.ts
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
1
|
import type { StorageAdapter } from './types.js'
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* localStorage adapter for browser environments. Falls back to a no-op when
|
|
5
|
-
* `localStorage` is unavailable (e.g. SSR).
|
|
6
|
-
*
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export const localStorageAdapter: StorageAdapter = {
|
|
10
|
-
get: (key: string): Promise<string | null> => {
|
|
11
|
-
try {
|
|
12
|
-
return Promise.resolve(localStorage.getItem(key))
|
|
13
|
-
} catch {
|
|
14
|
-
return Promise.resolve(null)
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
set: (key: string, value: string): Promise<void> => {
|
|
19
|
-
try {
|
|
20
|
-
localStorage.setItem(key, value)
|
|
21
|
-
} catch {
|
|
22
|
-
// localStorage not available
|
|
23
|
-
}
|
|
24
|
-
return Promise.resolve()
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
remove: (key: string): Promise<void> => {
|
|
28
|
-
try {
|
|
29
|
-
localStorage.removeItem(key)
|
|
30
|
-
} catch {
|
|
31
|
-
// localStorage not available
|
|
32
|
-
}
|
|
33
|
-
return Promise.resolve()
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
|
|
37
3
|
/**
|
|
38
4
|
* In-memory storage adapter for testing or server-side use.
|
|
39
5
|
*
|
package/src/types/provider.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type {
|
|
|
3
3
|
AccountConfigSetting,
|
|
4
4
|
AccountResponse,
|
|
5
5
|
AccountSummary,
|
|
6
|
-
ActionResult,
|
|
7
6
|
ActionStep,
|
|
8
7
|
ActionType,
|
|
9
8
|
ActivitiesResponse,
|
|
@@ -19,7 +18,6 @@ import type {
|
|
|
19
18
|
ProviderAction,
|
|
20
19
|
Quote,
|
|
21
20
|
QuoteSide,
|
|
22
|
-
RestCallSignedActionStep,
|
|
23
21
|
SignedActionStep,
|
|
24
22
|
SigningMethod,
|
|
25
23
|
TradeType,
|
|
@@ -448,22 +446,6 @@ export interface PerpsProviderPlugin {
|
|
|
448
446
|
address: Address,
|
|
449
447
|
ctx?: SignActionsContext
|
|
450
448
|
): Promise<SignedActionStep[]>
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Execute credential-bearing rest-call steps directly against the venue.
|
|
454
|
-
* Required for providers whose descriptors declare
|
|
455
|
-
* `SigningMethod.AUTH_TOKEN`: the client-held credential (attached by
|
|
456
|
-
* `signActions` as `headers`) must never transit the LI.FI backend, so the
|
|
457
|
-
* venue call happens SDK-side. The provider owns base-URL resolution and
|
|
458
|
-
* mapping the venue response onto {@link ActionResult}s — these results are
|
|
459
|
-
* authoritative for the caller; `PerpsClient.execute` submits the steps to
|
|
460
|
-
* the backend afterwards for bookkeeping only, with `headers` stripped.
|
|
461
|
-
*/
|
|
462
|
-
executeRestCallActions?(
|
|
463
|
-
steps: RestCallSignedActionStep[],
|
|
464
|
-
address: Address,
|
|
465
|
-
options?: SDKRequestOptions
|
|
466
|
-
): Promise<ActionResult[]>
|
|
467
449
|
}
|
|
468
450
|
|
|
469
451
|
/**
|
|
@@ -2,9 +2,7 @@ import type { AccountConfig } from '@lifi/perps-types'
|
|
|
2
2
|
import { ChainId } from '@lifi/types'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Perps provider keys that
|
|
6
|
-
* from the map means the provider is not funded via a LI.FI swap (e.g. ondo's
|
|
7
|
-
* custodial provisioned-address deposits).
|
|
5
|
+
* Perps provider keys that have a declared LI.FI deposit-target chain.
|
|
8
6
|
*
|
|
9
7
|
* @public
|
|
10
8
|
*/
|
|
@@ -17,8 +15,9 @@ export type DepositProviderKey = AccountConfig['provider']
|
|
|
17
15
|
*
|
|
18
16
|
* @public
|
|
19
17
|
*/
|
|
20
|
-
export const LIFI_DEPOSIT_CHAIN_BY_PROVIDER:
|
|
21
|
-
|
|
18
|
+
export const LIFI_DEPOSIT_CHAIN_BY_PROVIDER: Record<
|
|
19
|
+
DepositProviderKey,
|
|
20
|
+
ChainId
|
|
22
21
|
> = {
|
|
23
22
|
hyperliquid: ChainId.HPL,
|
|
24
23
|
lighter: ChainId.LTR,
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/perps-sdk'
|
|
2
|
-
export const version = '0.0.0-preview-
|
|
2
|
+
export const version = '0.0.0-preview-ba2d335'
|