@pear-protocol/core-sdk 2.0.0 → 2.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/auth/index.d.ts +4 -4
- package/dist/core/index.d.ts +76 -1
- package/dist/core/index.js +29 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.js +10 -3
- package/dist/types.d.ts +11 -0
- package/package.json +2 -2
package/dist/auth/index.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ declare class Auth {
|
|
|
47
47
|
refreshToken: string;
|
|
48
48
|
user: {
|
|
49
49
|
id: string;
|
|
50
|
-
role: "basic" | "pro";
|
|
50
|
+
role: "basic" | "pro" | "vault";
|
|
51
51
|
providerId: string | null;
|
|
52
52
|
loginMethod: "email" | "evm_wallet" | "oauth" | "x";
|
|
53
53
|
};
|
|
@@ -77,7 +77,7 @@ declare class Auth {
|
|
|
77
77
|
refreshToken: string;
|
|
78
78
|
user: {
|
|
79
79
|
id: string;
|
|
80
|
-
role: "basic" | "pro";
|
|
80
|
+
role: "basic" | "pro" | "vault";
|
|
81
81
|
providerId: string | null;
|
|
82
82
|
loginMethod: "email" | "evm_wallet" | "oauth" | "x";
|
|
83
83
|
};
|
|
@@ -91,7 +91,7 @@ declare class Auth {
|
|
|
91
91
|
logout(headers?: ClientHeaders): Promise<void>;
|
|
92
92
|
me(headers?: ClientHeaders): Promise<{
|
|
93
93
|
id: string;
|
|
94
|
-
role: "basic" | "pro";
|
|
94
|
+
role: "basic" | "pro" | "vault";
|
|
95
95
|
providerId: string | null;
|
|
96
96
|
loginMethod: "email" | "evm_wallet" | "oauth" | "x";
|
|
97
97
|
identities: {
|
|
@@ -102,7 +102,7 @@ declare class Auth {
|
|
|
102
102
|
}>;
|
|
103
103
|
apiKeyMe(headers?: ClientHeaders): Promise<{
|
|
104
104
|
id: string;
|
|
105
|
-
role: "basic" | "pro";
|
|
105
|
+
role: "basic" | "pro" | "vault";
|
|
106
106
|
scope: "read" | "read_write";
|
|
107
107
|
authMethod: "api_key";
|
|
108
108
|
}>;
|
package/dist/core/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare class Core {
|
|
|
14
14
|
id: string;
|
|
15
15
|
alias: string;
|
|
16
16
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
17
|
+
kind: "vault" | "eoa";
|
|
17
18
|
exchangeIdentifier: string;
|
|
18
19
|
createdAt: string;
|
|
19
20
|
updatedAt: string;
|
|
@@ -32,6 +33,7 @@ declare class Core {
|
|
|
32
33
|
id: string;
|
|
33
34
|
alias: string;
|
|
34
35
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
36
|
+
kind: "vault" | "eoa";
|
|
35
37
|
exchangeIdentifier: string;
|
|
36
38
|
createdAt: string;
|
|
37
39
|
updatedAt: string;
|
|
@@ -50,6 +52,7 @@ declare class Core {
|
|
|
50
52
|
id: string;
|
|
51
53
|
alias: string;
|
|
52
54
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
55
|
+
kind: "vault" | "eoa";
|
|
53
56
|
exchangeIdentifier: string;
|
|
54
57
|
createdAt: string;
|
|
55
58
|
updatedAt: string;
|
|
@@ -70,6 +73,7 @@ declare class Core {
|
|
|
70
73
|
id: string;
|
|
71
74
|
alias: string;
|
|
72
75
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
76
|
+
kind: "vault" | "eoa";
|
|
73
77
|
exchangeIdentifier: string;
|
|
74
78
|
createdAt: string;
|
|
75
79
|
updatedAt: string;
|
|
@@ -91,6 +95,7 @@ declare class Core {
|
|
|
91
95
|
id: string;
|
|
92
96
|
alias: string;
|
|
93
97
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
98
|
+
kind: "vault" | "eoa";
|
|
94
99
|
exchangeIdentifier: string;
|
|
95
100
|
createdAt: string;
|
|
96
101
|
updatedAt: string;
|
|
@@ -119,6 +124,7 @@ declare class Core {
|
|
|
119
124
|
id: string;
|
|
120
125
|
alias: string;
|
|
121
126
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
127
|
+
kind: "vault" | "eoa";
|
|
122
128
|
exchangeIdentifier: string;
|
|
123
129
|
createdAt: string;
|
|
124
130
|
updatedAt: string;
|
|
@@ -141,6 +147,7 @@ declare class Core {
|
|
|
141
147
|
id: string;
|
|
142
148
|
alias: string;
|
|
143
149
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
150
|
+
kind: "vault" | "eoa";
|
|
144
151
|
exchangeIdentifier: string;
|
|
145
152
|
createdAt: string;
|
|
146
153
|
updatedAt: string;
|
|
@@ -164,6 +171,7 @@ declare class Core {
|
|
|
164
171
|
id: string;
|
|
165
172
|
alias: string;
|
|
166
173
|
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
174
|
+
kind: "vault" | "eoa";
|
|
167
175
|
exchangeIdentifier: string;
|
|
168
176
|
createdAt: string;
|
|
169
177
|
updatedAt: string;
|
|
@@ -182,6 +190,69 @@ declare class Core {
|
|
|
182
190
|
};
|
|
183
191
|
}>;
|
|
184
192
|
restore: (id: string, headers?: ClientHeaders) => Promise<void>;
|
|
193
|
+
createVault: (body: HttpTypes.CreateVaultTradeAccountInput, headers?: ClientHeaders) => Promise<{
|
|
194
|
+
account: {
|
|
195
|
+
id: string;
|
|
196
|
+
alias: string;
|
|
197
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
198
|
+
kind: "vault" | "eoa";
|
|
199
|
+
exchangeIdentifier: string;
|
|
200
|
+
createdAt: string;
|
|
201
|
+
updatedAt: string;
|
|
202
|
+
metadata?: {
|
|
203
|
+
agentWalletAddress: string;
|
|
204
|
+
isSubaccount: boolean;
|
|
205
|
+
mainAccountAddress: string;
|
|
206
|
+
} | {
|
|
207
|
+
l1_address: string;
|
|
208
|
+
} | undefined;
|
|
209
|
+
deletedAt?: string | undefined;
|
|
210
|
+
};
|
|
211
|
+
}>;
|
|
212
|
+
getVaultStatus: (vaultAddress: string, headers?: ClientHeaders) => Promise<{
|
|
213
|
+
status: {
|
|
214
|
+
exists: false;
|
|
215
|
+
} | {
|
|
216
|
+
exists: true;
|
|
217
|
+
tradeAccountId: string;
|
|
218
|
+
account: {
|
|
219
|
+
id: string;
|
|
220
|
+
alias: string;
|
|
221
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
222
|
+
kind: "vault" | "eoa";
|
|
223
|
+
exchangeIdentifier: string;
|
|
224
|
+
createdAt: string;
|
|
225
|
+
updatedAt: string;
|
|
226
|
+
metadata?: {
|
|
227
|
+
agentWalletAddress: string;
|
|
228
|
+
isSubaccount: boolean;
|
|
229
|
+
mainAccountAddress: string;
|
|
230
|
+
} | {
|
|
231
|
+
l1_address: string;
|
|
232
|
+
} | undefined;
|
|
233
|
+
deletedAt?: string | undefined;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
}>;
|
|
237
|
+
refreshVault: (vaultAddress: string, headers?: ClientHeaders) => Promise<{
|
|
238
|
+
account: {
|
|
239
|
+
id: string;
|
|
240
|
+
alias: string;
|
|
241
|
+
connector: "hyperliquid" | "binance" | "bybit" | "okx" | "lighter";
|
|
242
|
+
kind: "vault" | "eoa";
|
|
243
|
+
exchangeIdentifier: string;
|
|
244
|
+
createdAt: string;
|
|
245
|
+
updatedAt: string;
|
|
246
|
+
metadata?: {
|
|
247
|
+
agentWalletAddress: string;
|
|
248
|
+
isSubaccount: boolean;
|
|
249
|
+
mainAccountAddress: string;
|
|
250
|
+
} | {
|
|
251
|
+
l1_address: string;
|
|
252
|
+
} | undefined;
|
|
253
|
+
deletedAt?: string | undefined;
|
|
254
|
+
};
|
|
255
|
+
}>;
|
|
185
256
|
};
|
|
186
257
|
fee: {
|
|
187
258
|
get: (query?: HttpTypes.QuoteFeeParamsInput, headers?: ClientHeaders) => Promise<{
|
|
@@ -5110,6 +5181,10 @@ declare class Core {
|
|
|
5110
5181
|
})[];
|
|
5111
5182
|
}>;
|
|
5112
5183
|
setLeverage: (body: HttpTypes.SetLeverage, headers?: ClientHeaders) => Promise<Record<string, never>>;
|
|
5184
|
+
/** Add or remove margin from an isolated position without changing its size. */
|
|
5185
|
+
adjustIsolatedMargin: (body: HttpTypes.AdjustIsolatedMargin, headers?: ClientHeaders) => Promise<{
|
|
5186
|
+
adjustmentId: string;
|
|
5187
|
+
}>;
|
|
5113
5188
|
};
|
|
5114
5189
|
triggers: {
|
|
5115
5190
|
list: (query: HttpTypes.TriggerListParamsInput, headers?: ClientHeaders) => Promise<{
|
|
@@ -7388,7 +7463,7 @@ declare class Core {
|
|
|
7388
7463
|
profile: {
|
|
7389
7464
|
id: string;
|
|
7390
7465
|
displayName: string;
|
|
7391
|
-
role: "basic" | "pro";
|
|
7466
|
+
role: "basic" | "pro" | "vault";
|
|
7392
7467
|
address: string | null;
|
|
7393
7468
|
email: string | null;
|
|
7394
7469
|
emailVerified: boolean;
|
package/dist/core/index.js
CHANGED
|
@@ -61,7 +61,26 @@ class Core {
|
|
|
61
61
|
method: "POST",
|
|
62
62
|
headers
|
|
63
63
|
});
|
|
64
|
-
}, "restore")
|
|
64
|
+
}, "restore"),
|
|
65
|
+
createVault: /* @__PURE__ */ __name(async (body, headers) => {
|
|
66
|
+
return await this.client.fetch(`/trade-accounts/vault`, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers,
|
|
69
|
+
body
|
|
70
|
+
});
|
|
71
|
+
}, "createVault"),
|
|
72
|
+
getVaultStatus: /* @__PURE__ */ __name(async (vaultAddress, headers) => {
|
|
73
|
+
return await this.client.fetch(`/trade-accounts/vault/${vaultAddress}`, {
|
|
74
|
+
method: "GET",
|
|
75
|
+
headers
|
|
76
|
+
});
|
|
77
|
+
}, "getVaultStatus"),
|
|
78
|
+
refreshVault: /* @__PURE__ */ __name(async (vaultAddress, headers) => {
|
|
79
|
+
return await this.client.fetch(`/trade-accounts/vault/${vaultAddress}/refresh`, {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers
|
|
82
|
+
});
|
|
83
|
+
}, "refreshVault")
|
|
65
84
|
};
|
|
66
85
|
fee = {
|
|
67
86
|
// Resolves the trading fee and connector fee recipient for the caller's selected trade account.
|
|
@@ -631,7 +650,15 @@ class Core {
|
|
|
631
650
|
headers,
|
|
632
651
|
body
|
|
633
652
|
});
|
|
634
|
-
}, "setLeverage")
|
|
653
|
+
}, "setLeverage"),
|
|
654
|
+
/** Add or remove margin from an isolated position without changing its size. */
|
|
655
|
+
adjustIsolatedMargin: /* @__PURE__ */ __name(async (body, headers) => {
|
|
656
|
+
return await this.client.fetch(`/margin`, {
|
|
657
|
+
method: "POST",
|
|
658
|
+
headers,
|
|
659
|
+
body
|
|
660
|
+
});
|
|
661
|
+
}, "adjustIsolatedMargin")
|
|
635
662
|
};
|
|
636
663
|
triggers = {
|
|
637
664
|
list: /* @__PURE__ */ __name(async (query, headers) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export * from '@pear-protocol/utils';
|
|
|
8
8
|
export { FetchError } from './utils.js';
|
|
9
9
|
import './http.js';
|
|
10
10
|
|
|
11
|
+
/** Header that makes a request act as a Pear vault (see `SDKConfig.getVaultAddress`). */
|
|
12
|
+
declare const VAULT_ADDRESS_HEADER = "pear-vault-address";
|
|
11
13
|
declare class PearSDK {
|
|
12
14
|
auth: Auth;
|
|
13
15
|
core: Core;
|
|
@@ -15,4 +17,4 @@ declare class PearSDK {
|
|
|
15
17
|
constructor(config: SDKConfig);
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
export { External, PearSDK as default };
|
|
20
|
+
export { External, VAULT_ADDRESS_HEADER, PearSDK as default };
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { FetchError } from './utils';
|
|
|
10
10
|
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
12
12
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
const VAULT_ADDRESS_HEADER = "pear-vault-address";
|
|
13
14
|
class PearSDK {
|
|
14
15
|
static {
|
|
15
16
|
__name(this, "PearSDK");
|
|
@@ -161,10 +162,16 @@ class PearSDK {
|
|
|
161
162
|
client.useResponse(apiKeyAuthMiddleware);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
|
-
if (config.getTradeAccountId) {
|
|
165
|
+
if (config.getTradeAccountId || config.getVaultAddress) {
|
|
165
166
|
const getTradeAccountId = config.getTradeAccountId;
|
|
167
|
+
const getVaultAddress = config.getVaultAddress;
|
|
166
168
|
client.useRequest(async (request, next) => {
|
|
167
|
-
const
|
|
169
|
+
const vaultAddress = getVaultAddress?.();
|
|
170
|
+
if (vaultAddress) {
|
|
171
|
+
request.headers.set(VAULT_ADDRESS_HEADER, vaultAddress);
|
|
172
|
+
return next();
|
|
173
|
+
}
|
|
174
|
+
const tradeAccountId = getTradeAccountId?.();
|
|
168
175
|
if (tradeAccountId) {
|
|
169
176
|
request.headers.set("x-trade-account-id", tradeAccountId);
|
|
170
177
|
}
|
|
@@ -192,4 +199,4 @@ function readBearerCredential(request) {
|
|
|
192
199
|
}
|
|
193
200
|
__name(readBearerCredential, "readBearerCredential");
|
|
194
201
|
|
|
195
|
-
export { PearSDK as default };
|
|
202
|
+
export { VAULT_ADDRESS_HEADER, PearSDK as default };
|
package/dist/types.d.ts
CHANGED
|
@@ -62,6 +62,17 @@ type SDKConfig = {
|
|
|
62
62
|
* Example: () => localStorage.getState().activeTradeAccountId
|
|
63
63
|
*/
|
|
64
64
|
getTradeAccountId?: () => string | null;
|
|
65
|
+
/**
|
|
66
|
+
* Pear vault address getter (used in both modes). When it returns an address the
|
|
67
|
+
* request carries the `pear-vault-address` header and acts as that vault: the
|
|
68
|
+
* backend authorizes the caller as the vault's owner/trader and resolves the
|
|
69
|
+
* vault's own trade account, so the trade-account header is not sent. For a
|
|
70
|
+
* one-off call without this hook, pass `{ [VAULT_ADDRESS_HEADER]: address }` as
|
|
71
|
+
* the call's headers.
|
|
72
|
+
*
|
|
73
|
+
* Example: () => useSessionStore.getState().activeVault?.address ?? null
|
|
74
|
+
*/
|
|
75
|
+
getVaultAddress?: () => string | null;
|
|
65
76
|
/**
|
|
66
77
|
* Default attribution client code (client_ids.code). When set, it is
|
|
67
78
|
* auto-added to the body of trade / trigger / schedule / rebalance requests
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pear-protocol/core-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Pear Protocol Core SDK",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"typecheck": "tsc --noEmit"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@pear-protocol/types": "^2.
|
|
29
|
+
"@pear-protocol/types": "^2.1.0",
|
|
30
30
|
"@pear-protocol/utils": "^1.0.0",
|
|
31
31
|
"qs": "^6.14.0"
|
|
32
32
|
},
|