@strkfarm/sdk 2.0.0-dev.26 → 2.0.0-dev.28
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/cli.js +190 -36
- package/dist/cli.mjs +188 -34
- package/dist/index.browser.global.js +79130 -49354
- package/dist/index.browser.mjs +18039 -11431
- package/dist/index.d.ts +2869 -898
- package/dist/index.js +19036 -12207
- package/dist/index.mjs +18942 -12158
- package/package.json +1 -1
- package/src/data/avnu.abi.json +840 -0
- package/src/data/ekubo-price-fethcer.abi.json +265 -0
- package/src/dataTypes/_bignumber.ts +13 -4
- package/src/dataTypes/index.ts +3 -2
- package/src/dataTypes/mynumber.ts +141 -0
- package/src/global.ts +76 -41
- package/src/index.browser.ts +2 -1
- package/src/interfaces/common.tsx +167 -2
- package/src/modules/ExtendedWrapperSDk/types.ts +26 -4
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +110 -67
- package/src/modules/apollo-client-config.ts +28 -0
- package/src/modules/avnu.ts +4 -4
- package/src/modules/ekubo-pricer.ts +79 -0
- package/src/modules/ekubo-quoter.ts +46 -30
- package/src/modules/erc20.ts +17 -0
- package/src/modules/harvests.ts +43 -29
- package/src/modules/pragma.ts +23 -8
- package/src/modules/pricer-from-api.ts +156 -15
- package/src/modules/pricer-lst.ts +1 -1
- package/src/modules/pricer.ts +40 -4
- package/src/modules/pricerBase.ts +2 -1
- package/src/node/deployer.ts +36 -1
- package/src/node/pricer-redis.ts +2 -1
- package/src/strategies/base-strategy.ts +78 -10
- package/src/strategies/ekubo-cl-vault.tsx +906 -347
- package/src/strategies/factory.ts +159 -0
- package/src/strategies/index.ts +6 -1
- package/src/strategies/registry.ts +239 -0
- package/src/strategies/sensei.ts +335 -7
- package/src/strategies/svk-strategy.ts +97 -27
- package/src/strategies/types.ts +4 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +2 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +177 -268
- package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
- package/src/strategies/universal-adapters/common-adapter.ts +206 -203
- package/src/strategies/universal-adapters/extended-adapter.ts +155 -336
- package/src/strategies/universal-adapters/index.ts +9 -8
- package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
- package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +200 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +110 -75
- package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +476 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +762 -844
- package/src/strategies/universal-adapters/vesu-position-common.ts +251 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
- package/src/strategies/universal-lst-muliplier-strategy.tsx +396 -204
- package/src/strategies/universal-strategy.tsx +1426 -1178
- package/src/strategies/vesu-extended-strategy/services/executionService.ts +2251 -0
- package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +2941 -0
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +12 -1
- package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +52 -0
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +1 -0
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +3 -1
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +158 -124
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +377 -1781
- package/src/strategies/vesu-rebalance.tsx +255 -152
- package/src/utils/health-factor-math.ts +4 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/logger.browser.ts +22 -4
- package/src/utils/logger.node.ts +259 -24
- package/src/utils/starknet-call-parser.ts +1036 -0
- package/src/utils/strategy-utils.ts +61 -0
- package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
|
@@ -55,6 +55,68 @@ export interface IProtocol {
|
|
|
55
55
|
logo: string;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
export enum StrategyTag {
|
|
59
|
+
META_VAULT = "Meta Vaults",
|
|
60
|
+
LEVERED = "Maxx",
|
|
61
|
+
AUTOMATED_LP = "Ekubo",
|
|
62
|
+
BTC = "BTC"
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export enum VaultType {
|
|
66
|
+
LOOPING = "Looping",
|
|
67
|
+
META_VAULT = "Meta Vault",
|
|
68
|
+
DELTA_NEUTRAL = "Delta Neutral",
|
|
69
|
+
AUTOMATED_LP = "Automated LP",
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Security metadata enums
|
|
73
|
+
export enum AuditStatus {
|
|
74
|
+
AUDITED = "Audited",
|
|
75
|
+
NOT_AUDITED = "Not Audited",
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export enum SourceCodeType {
|
|
79
|
+
OPEN_SOURCE = "Open Source",
|
|
80
|
+
CLOSED_SOURCE = "Closed Source",
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export enum AccessControlType {
|
|
84
|
+
MULTISIG_ACCOUNT = "Multisig Account",
|
|
85
|
+
STANDARD_ACCOUNT = "Standard Account",
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export enum InstantWithdrawalVault {
|
|
89
|
+
YES = "Yes",
|
|
90
|
+
NO = "No",
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Security metadata interfaces
|
|
94
|
+
export interface SourceCodeInfo {
|
|
95
|
+
type: SourceCodeType;
|
|
96
|
+
contractLink: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface AccessControlInfo {
|
|
100
|
+
type: AccessControlType;
|
|
101
|
+
addresses: ContractAddr[];
|
|
102
|
+
timeLock: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface SecurityMetadata {
|
|
106
|
+
auditStatus: AuditStatus;
|
|
107
|
+
sourceCode: SourceCodeInfo;
|
|
108
|
+
accessControl: AccessControlInfo;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface RedemptionInfo {
|
|
112
|
+
instantWithdrawalVault: InstantWithdrawalVault;
|
|
113
|
+
redemptionsInfo: {
|
|
114
|
+
title: string; // e.g. Upto $1M
|
|
115
|
+
description: string; // e.g. "1-2 hours"
|
|
116
|
+
}[],
|
|
117
|
+
alerts: StrategyAlert[];
|
|
118
|
+
}
|
|
119
|
+
|
|
58
120
|
export enum FlowChartColors {
|
|
59
121
|
Green = "purple",
|
|
60
122
|
Blue = "#35484f",
|
|
@@ -66,26 +128,65 @@ export interface FAQ {
|
|
|
66
128
|
answer: string | React.ReactNode;
|
|
67
129
|
}
|
|
68
130
|
|
|
131
|
+
export enum StrategyLiveStatus {
|
|
132
|
+
ACTIVE = "Active",
|
|
133
|
+
NEW = "New",
|
|
134
|
+
COMING_SOON = "Coming Soon",
|
|
135
|
+
DEPRECATED = "Deprecated", // active but not recommended
|
|
136
|
+
RETIRED = "Retired", // not active anymore
|
|
137
|
+
HOT = "Hot & New 🔥"
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface StrategyAlert {
|
|
141
|
+
type: "warning" | "info";
|
|
142
|
+
text: string | React.ReactNode;
|
|
143
|
+
tab: "all" | "deposit" | "withdraw";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface StrategySettings {
|
|
147
|
+
maxTVL?: Web3Number;
|
|
148
|
+
liveStatus?: StrategyLiveStatus;
|
|
149
|
+
isPaused?: boolean;
|
|
150
|
+
isInMaintenance?: boolean;
|
|
151
|
+
isAudited: boolean;
|
|
152
|
+
isInstantWithdrawal?: boolean;
|
|
153
|
+
hideHarvestInfo?: boolean;
|
|
154
|
+
is_promoted?: boolean;
|
|
155
|
+
isTransactionHistDisabled?: boolean;
|
|
156
|
+
quoteToken: TokenInfo;
|
|
157
|
+
hideNetEarnings?: boolean;
|
|
158
|
+
showWithdrawalWarningModal?: boolean;
|
|
159
|
+
alerts?: StrategyAlert[];
|
|
160
|
+
tags?: StrategyTag[];
|
|
161
|
+
}
|
|
162
|
+
|
|
69
163
|
/**
|
|
70
164
|
* @property risk.riskFactor.factor - The risk factors that are considered for the strategy.
|
|
71
165
|
* @property risk.riskFactor.factor - The value of the risk factor from 0 to 10, 0 being the lowest and 10 being the highest.
|
|
166
|
+
* @property security - Security-related metadata including audit status, source code information, and access control details.
|
|
167
|
+
* @property redemptionInfo - Redemption information including instant withdrawal availability and expected redemption times.
|
|
72
168
|
*/
|
|
73
169
|
export interface IStrategyMetadata<T> {
|
|
170
|
+
id: string;
|
|
74
171
|
name: string;
|
|
75
172
|
description: string | React.ReactNode;
|
|
76
173
|
address: ContractAddr;
|
|
77
174
|
launchBlock: number;
|
|
78
175
|
type: "ERC4626" | "ERC721" | "Other";
|
|
176
|
+
vaultType: {
|
|
177
|
+
type: VaultType;
|
|
178
|
+
description: string;
|
|
179
|
+
};
|
|
79
180
|
depositTokens: TokenInfo[];
|
|
80
181
|
protocols: IProtocol[];
|
|
81
182
|
auditUrl?: string;
|
|
82
|
-
maxTVL: Web3Number;
|
|
83
183
|
risk: {
|
|
84
184
|
riskFactor: RiskFactor[];
|
|
85
185
|
netRisk: number;
|
|
86
186
|
notARisks: RiskType[];
|
|
87
187
|
};
|
|
88
188
|
apyMethodology?: string;
|
|
189
|
+
realizedAPYMethodology?: string;
|
|
89
190
|
additionalInfo: T;
|
|
90
191
|
contractDetails: {
|
|
91
192
|
address: ContractAddr;
|
|
@@ -97,7 +198,30 @@ export interface IStrategyMetadata<T> {
|
|
|
97
198
|
docs?: string;
|
|
98
199
|
investmentSteps: string[];
|
|
99
200
|
curator?: { name: string, logo: string },
|
|
100
|
-
isPreview?: boolean
|
|
201
|
+
isPreview?: boolean;
|
|
202
|
+
tags?: StrategyTag[];
|
|
203
|
+
security: SecurityMetadata;
|
|
204
|
+
redemptionInfo: RedemptionInfo;
|
|
205
|
+
usualTimeToEarnings: null | string; // e.g. "2 weeks" // some strats grow like step functions
|
|
206
|
+
usualTimeToEarningsDescription: null | string; // e.g. "LSTs price on DEX goes up roughly every 2 weeks"
|
|
207
|
+
discontinuationInfo?: {
|
|
208
|
+
date?: Date;
|
|
209
|
+
reason?: React.ReactNode | string;
|
|
210
|
+
info?: React.ReactNode | string;
|
|
211
|
+
};
|
|
212
|
+
settings?: StrategySettings;
|
|
213
|
+
// Legacy field for multi-step strategies (deprecated, use investmentFlows instead)
|
|
214
|
+
actions?: Array<{
|
|
215
|
+
name?: string;
|
|
216
|
+
pool?: {
|
|
217
|
+
protocol?: { name: string; logo: string };
|
|
218
|
+
pool?: { name: string; logos?: string[] };
|
|
219
|
+
apr?: number;
|
|
220
|
+
borrow?: { apr?: number };
|
|
221
|
+
};
|
|
222
|
+
amount?: string | number;
|
|
223
|
+
isDeposit?: boolean;
|
|
224
|
+
}>;
|
|
101
225
|
}
|
|
102
226
|
|
|
103
227
|
export interface IInvestmentFlow {
|
|
@@ -124,6 +248,23 @@ export function getMainnetConfig(
|
|
|
124
248
|
};
|
|
125
249
|
}
|
|
126
250
|
|
|
251
|
+
export const getStrategyTagDesciption = (tag: StrategyTag): string => {
|
|
252
|
+
switch (tag) {
|
|
253
|
+
case StrategyTag.META_VAULT:
|
|
254
|
+
return "A meta vault is a vault that auto allocates funds to multiple vaults based on optimal yield opportunities";
|
|
255
|
+
case StrategyTag.LEVERED:
|
|
256
|
+
return "Looping vaults on Endur LSTs with leveraged borrowing of STRK or BTC to increase yield (2-4x higher yield than simply staking)";
|
|
257
|
+
case StrategyTag.AUTOMATED_LP:
|
|
258
|
+
return "Automated LP vaults on Ekubo that rebalance position automatically, ensuring you earn fees efficiently";
|
|
259
|
+
case StrategyTag.BTC:
|
|
260
|
+
return "BTC linked vaults";
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export const getAllStrategyTags = (): StrategyTag[] => {
|
|
265
|
+
return Object.values(StrategyTag);
|
|
266
|
+
}
|
|
267
|
+
|
|
127
268
|
export const getRiskExplaination = (riskType: RiskType) => {
|
|
128
269
|
switch (riskType) {
|
|
129
270
|
case RiskType.MARKET_RISK:
|
|
@@ -215,6 +356,30 @@ export interface VaultPosition {
|
|
|
215
356
|
protocol: IProtocol
|
|
216
357
|
}
|
|
217
358
|
|
|
359
|
+
export interface AmountInfo {
|
|
360
|
+
amount: Web3Number;
|
|
361
|
+
usdValue: number;
|
|
362
|
+
tokenInfo: TokenInfo;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export interface AmountsInfo {
|
|
366
|
+
usdValue: number;
|
|
367
|
+
amounts: AmountInfo[];
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Strategy capabilities interface
|
|
372
|
+
* Describes what optional methods a strategy instance supports
|
|
373
|
+
*/
|
|
374
|
+
export interface StrategyCapabilities {
|
|
375
|
+
hasMatchInputAmounts: boolean;
|
|
376
|
+
hasNetAPY: boolean;
|
|
377
|
+
hasGetInvestmentFlows: boolean;
|
|
378
|
+
hasGetPendingRewards: boolean;
|
|
379
|
+
hasHarvest: boolean;
|
|
380
|
+
hasRebalance: boolean;
|
|
381
|
+
}
|
|
382
|
+
|
|
218
383
|
const VesuProtocol: IProtocol = {
|
|
219
384
|
name: "Vesu",
|
|
220
385
|
logo: "https://static-assets-8zct.onrender.com/integrations/vesu/logo.png"
|
|
@@ -79,9 +79,10 @@ export enum AssetOperationType {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export enum AssetOperationStatus {
|
|
82
|
-
|
|
82
|
+
CREATED = "CREATED",
|
|
83
|
+
IN_PROGRESS = "IN_PROGRESS",
|
|
83
84
|
COMPLETED = "COMPLETED",
|
|
84
|
-
|
|
85
|
+
REJECTED = "REJECTED",
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
// Base types
|
|
@@ -293,7 +294,8 @@ export interface ExtendedApiResponse<T> {
|
|
|
293
294
|
|
|
294
295
|
// Configuration types
|
|
295
296
|
export interface ExtendedWrapperConfig {
|
|
296
|
-
|
|
297
|
+
readUrl: string;
|
|
298
|
+
writeUrl: string;
|
|
297
299
|
apiKey?: string;
|
|
298
300
|
timeout?: number;
|
|
299
301
|
retries?: number;
|
|
@@ -308,4 +310,24 @@ export interface FundingRate {
|
|
|
308
310
|
m: string;
|
|
309
311
|
f:string;
|
|
310
312
|
t:number;
|
|
311
|
-
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export interface FundingPayment {
|
|
316
|
+
id: number;
|
|
317
|
+
accountId?: number;
|
|
318
|
+
account_id?: number;
|
|
319
|
+
market: string;
|
|
320
|
+
positionId?: number;
|
|
321
|
+
position_id?: number;
|
|
322
|
+
side: PositionSide;
|
|
323
|
+
size: string;
|
|
324
|
+
value: string;
|
|
325
|
+
markPrice?: string;
|
|
326
|
+
mark_price?: string;
|
|
327
|
+
fundingFee?: string;
|
|
328
|
+
funding_fee?: string;
|
|
329
|
+
fundingRate?: string;
|
|
330
|
+
funding_rate?: string;
|
|
331
|
+
paidTime?: number;
|
|
332
|
+
paid_time?: number;
|
|
333
|
+
}
|
|
@@ -22,20 +22,23 @@ import {
|
|
|
22
22
|
AssetOperationType,
|
|
23
23
|
AssetOperationStatus,
|
|
24
24
|
FundingRate,
|
|
25
|
+
FundingPayment,
|
|
25
26
|
UpdateLeverageRequest,
|
|
26
27
|
} from "./types";
|
|
27
28
|
|
|
28
29
|
export class ExtendedWrapper {
|
|
29
|
-
private
|
|
30
|
+
private readUrl: string;
|
|
31
|
+
private writeUrl: string;
|
|
30
32
|
private apiKey?: string;
|
|
31
33
|
private timeout: number;
|
|
32
34
|
private retries: number;
|
|
33
35
|
|
|
34
36
|
constructor(config: ExtendedWrapperConfig) {
|
|
35
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, ""); // Remove trailing slash
|
|
36
37
|
this.apiKey = config.apiKey;
|
|
37
38
|
this.timeout = config.timeout || 30000; // 30 seconds default
|
|
38
39
|
this.retries = config.retries || 3;
|
|
40
|
+
this.readUrl = config.readUrl.replace(/\/$/, "");
|
|
41
|
+
this.writeUrl = config.writeUrl.replace(/\/$/, "");
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
@@ -43,15 +46,14 @@ export class ExtendedWrapper {
|
|
|
43
46
|
*/
|
|
44
47
|
private async makeRequest<T>(
|
|
45
48
|
endpoint: string,
|
|
46
|
-
|
|
49
|
+
isRead: boolean,
|
|
50
|
+
options: RequestInit = {},
|
|
47
51
|
): Promise<ExtendedApiResponse<T>> {
|
|
48
|
-
const url = `${this.
|
|
49
|
-
|
|
52
|
+
const url = `${isRead ? this.readUrl : this.writeUrl}${endpoint}`;
|
|
50
53
|
const headers: Record<string, any> = {
|
|
51
54
|
"Content-Type": "application/json",
|
|
52
55
|
...options.headers,
|
|
53
56
|
};
|
|
54
|
-
|
|
55
57
|
if (this.apiKey) {
|
|
56
58
|
headers["X-API-Key"] = this.apiKey;
|
|
57
59
|
}
|
|
@@ -73,36 +75,42 @@ export class ExtendedWrapper {
|
|
|
73
75
|
throw new Error(
|
|
74
76
|
`HTTP ${response.status}: ${
|
|
75
77
|
errorData.detail || response.statusText
|
|
76
|
-
}
|
|
78
|
+
}`,
|
|
77
79
|
);
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
|
|
80
82
|
const text = await response.text();
|
|
81
83
|
|
|
82
84
|
// Replace large integers (greater than MAX_SAFE_INTEGER) with quoted strings
|
|
83
85
|
// This regex finds numbers that are likely to be large integers in the "data" field
|
|
84
|
-
const MAX_SAFE_INTEGER_STR =
|
|
86
|
+
const MAX_SAFE_INTEGER_STR = "9007199254740991";
|
|
85
87
|
const largeIntegerRegex = /"data"\s*:\s*(\d{16,})/g;
|
|
86
|
-
|
|
87
|
-
const modifiedText = text.replace(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
|
|
89
|
+
const modifiedText = text.replace(
|
|
90
|
+
largeIntegerRegex,
|
|
91
|
+
(match, largeInt) => {
|
|
92
|
+
// Compare as strings to avoid precision loss
|
|
93
|
+
if (
|
|
94
|
+
largeInt.length > MAX_SAFE_INTEGER_STR.length ||
|
|
95
|
+
(largeInt.length === MAX_SAFE_INTEGER_STR.length &&
|
|
96
|
+
largeInt > MAX_SAFE_INTEGER_STR)
|
|
97
|
+
) {
|
|
98
|
+
// Replace the number with a quoted string to preserve precision
|
|
99
|
+
return `"data":"${largeInt}"`;
|
|
100
|
+
}
|
|
101
|
+
return match; // Keep original if it's a safe integer
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
|
|
97
105
|
const data = JSON.parse(modifiedText);
|
|
98
|
-
|
|
99
|
-
if (data && typeof data.data ===
|
|
106
|
+
|
|
107
|
+
if (data && typeof data.data === "string" && /^\d+$/.test(data.data)) {
|
|
100
108
|
const numValue = Number(data.data);
|
|
101
109
|
if (Number.isSafeInteger(numValue)) {
|
|
102
110
|
data.data = numValue;
|
|
103
111
|
}
|
|
104
112
|
}
|
|
105
|
-
|
|
113
|
+
|
|
106
114
|
return data;
|
|
107
115
|
} catch (error) {
|
|
108
116
|
lastError = error as Error;
|
|
@@ -122,9 +130,9 @@ export class ExtendedWrapper {
|
|
|
122
130
|
* Create a new order on Extended Exchange
|
|
123
131
|
*/
|
|
124
132
|
async createOrder(
|
|
125
|
-
request: CreateOrderRequest
|
|
133
|
+
request: CreateOrderRequest,
|
|
126
134
|
): Promise<ExtendedApiResponse<PlacedOrder>> {
|
|
127
|
-
return this.makeRequest<PlacedOrder>("/api/v1/orders", {
|
|
135
|
+
return this.makeRequest<PlacedOrder>("/api/v1/orders", false, {
|
|
128
136
|
method: "POST",
|
|
129
137
|
body: JSON.stringify(request),
|
|
130
138
|
});
|
|
@@ -134,32 +142,35 @@ export class ExtendedWrapper {
|
|
|
134
142
|
* Get all markets
|
|
135
143
|
*/
|
|
136
144
|
async getMarkets(
|
|
137
|
-
marketNames?: string
|
|
145
|
+
marketNames?: string,
|
|
138
146
|
): Promise<ExtendedApiResponse<Market[]>> {
|
|
139
147
|
const params = marketNames
|
|
140
148
|
? `?market_names=${encodeURIComponent(marketNames)}`
|
|
141
149
|
: "";
|
|
142
|
-
return this.makeRequest<Market[]>(`/api/v1/markets${params}
|
|
150
|
+
return this.makeRequest<Market[]>(`/api/v1/markets${params}`, false);
|
|
143
151
|
}
|
|
144
152
|
|
|
145
|
-
|
|
146
|
-
*
|
|
153
|
+
/**
|
|
154
|
+
*
|
|
147
155
|
* @param orderId - The ID of the order to get
|
|
148
156
|
* @returns The order
|
|
149
157
|
*/
|
|
150
|
-
|
|
158
|
+
async getOrderByOrderId(
|
|
159
|
+
orderId: string,
|
|
160
|
+
): Promise<ExtendedApiResponse<OpenOrder>> {
|
|
151
161
|
const orderIdInt = parseInt(orderId);
|
|
152
|
-
return this.makeRequest<OpenOrder>(`/api/v1/orderId/${orderIdInt}
|
|
162
|
+
return this.makeRequest<OpenOrder>(`/api/v1/orderId/${orderIdInt}`, false);
|
|
153
163
|
}
|
|
154
164
|
|
|
155
165
|
/**
|
|
156
166
|
* Get market statistics for a specific market
|
|
157
167
|
*/
|
|
158
168
|
async getMarketStatistics(
|
|
159
|
-
marketName: string
|
|
169
|
+
marketName: string,
|
|
160
170
|
): Promise<ExtendedApiResponse<MarketStats>> {
|
|
161
171
|
return this.makeRequest<MarketStats>(
|
|
162
|
-
`/api/v1/markets/statistics?market_name=${encodeURIComponent(marketName)}
|
|
172
|
+
`/api/v1/markets/statistics?market_name=${encodeURIComponent(marketName)}`,
|
|
173
|
+
false,
|
|
163
174
|
);
|
|
164
175
|
}
|
|
165
176
|
|
|
@@ -167,19 +178,20 @@ export class ExtendedWrapper {
|
|
|
167
178
|
* Get current trading positions
|
|
168
179
|
*/
|
|
169
180
|
async getPositions(
|
|
170
|
-
marketNames?: string
|
|
181
|
+
marketNames?: string,
|
|
171
182
|
): Promise<ExtendedApiResponse<Position[]>> {
|
|
172
183
|
const params = marketNames
|
|
173
184
|
? `?market_names=${encodeURIComponent(marketNames)}`
|
|
174
185
|
: "";
|
|
175
|
-
|
|
186
|
+
const response = await this.makeRequest<Position[]>(`/api/v1/positions${params}`, true);
|
|
187
|
+
return response;
|
|
176
188
|
}
|
|
177
189
|
|
|
178
190
|
/**
|
|
179
191
|
* Get account balance and holdings
|
|
180
192
|
*/
|
|
181
193
|
async getHoldings(): Promise<ExtendedApiResponse<Balance>> {
|
|
182
|
-
return this.makeRequest<Balance>("/api/v1/holdings");
|
|
194
|
+
return this.makeRequest<Balance>("/api/v1/holdings", true);
|
|
183
195
|
}
|
|
184
196
|
|
|
185
197
|
/**
|
|
@@ -187,9 +199,9 @@ export class ExtendedWrapper {
|
|
|
187
199
|
* Returns data as number | string to preserve precision for large integers
|
|
188
200
|
*/
|
|
189
201
|
async withdraw(
|
|
190
|
-
request: WithdrawRequest
|
|
202
|
+
request: WithdrawRequest,
|
|
191
203
|
): Promise<ExtendedApiResponse<number | string>> {
|
|
192
|
-
return this.makeRequest<number | string>("/api/v1/withdraw", {
|
|
204
|
+
return this.makeRequest<number | string>("/api/v1/withdraw", false, {
|
|
193
205
|
method: "POST",
|
|
194
206
|
body: JSON.stringify(request),
|
|
195
207
|
});
|
|
@@ -207,7 +219,7 @@ export class ExtendedWrapper {
|
|
|
207
219
|
};
|
|
208
220
|
}>
|
|
209
221
|
> {
|
|
210
|
-
return this.makeRequest("/api/v1/withdraw/sign", {
|
|
222
|
+
return this.makeRequest("/api/v1/withdraw/sign", false, {
|
|
211
223
|
method: "POST",
|
|
212
224
|
body: JSON.stringify(request),
|
|
213
225
|
});
|
|
@@ -217,25 +229,24 @@ export class ExtendedWrapper {
|
|
|
217
229
|
* Cancel an existing order
|
|
218
230
|
*/
|
|
219
231
|
async cancelOrder(
|
|
220
|
-
request: CancelOrderRequest
|
|
232
|
+
request: CancelOrderRequest,
|
|
221
233
|
): Promise<ExtendedApiResponse<{}>> {
|
|
222
|
-
return this.makeRequest<{}>("/api/v1/orders/cancel", {
|
|
234
|
+
return this.makeRequest<{}>("/api/v1/orders/cancel", false, {
|
|
223
235
|
method: "POST",
|
|
224
236
|
body: JSON.stringify(request),
|
|
225
237
|
});
|
|
226
238
|
}
|
|
227
239
|
|
|
228
|
-
|
|
229
240
|
/**
|
|
230
241
|
* Get all open orders
|
|
231
242
|
*/
|
|
232
243
|
async getOpenOrders(
|
|
233
|
-
marketName?: string
|
|
244
|
+
marketName?: string,
|
|
234
245
|
): Promise<ExtendedApiResponse<OpenOrder[]>> {
|
|
235
246
|
const endpoint = marketName
|
|
236
247
|
? `/api/v1/marketOrders/${marketName}`
|
|
237
248
|
: "/api/v1/marketOrders";
|
|
238
|
-
return this.makeRequest<OpenOrder[]>(endpoint,{
|
|
249
|
+
return this.makeRequest<OpenOrder[]>(endpoint, false, {
|
|
239
250
|
method: "GET",
|
|
240
251
|
headers: {
|
|
241
252
|
"Content-Type": "application/json",
|
|
@@ -249,9 +260,9 @@ export class ExtendedWrapper {
|
|
|
249
260
|
* @returns
|
|
250
261
|
*/
|
|
251
262
|
async updateLeverage(
|
|
252
|
-
request: UpdateLeverageRequest
|
|
263
|
+
request: UpdateLeverageRequest,
|
|
253
264
|
): Promise<ExtendedApiResponse<{}>> {
|
|
254
|
-
return this.makeRequest<{}>("/api/v1/leverage", {
|
|
265
|
+
return this.makeRequest<{}>("/api/v1/leverage", false, {
|
|
255
266
|
method: "POST",
|
|
256
267
|
body: JSON.stringify(request),
|
|
257
268
|
});
|
|
@@ -269,7 +280,7 @@ export class ExtendedWrapper {
|
|
|
269
280
|
endTime?: number;
|
|
270
281
|
cursor?: number;
|
|
271
282
|
limit?: number;
|
|
272
|
-
} = {}
|
|
283
|
+
} = {},
|
|
273
284
|
): Promise<ExtendedApiResponse<AssetOperation[]>> {
|
|
274
285
|
const params = new URLSearchParams();
|
|
275
286
|
|
|
@@ -294,14 +305,14 @@ export class ExtendedWrapper {
|
|
|
294
305
|
queryString ? `?${queryString}` : ""
|
|
295
306
|
}`;
|
|
296
307
|
|
|
297
|
-
return this.makeRequest<AssetOperation[]>(endpoint);
|
|
308
|
+
return this.makeRequest<AssetOperation[]>(endpoint, false);
|
|
298
309
|
}
|
|
299
310
|
|
|
300
311
|
/**
|
|
301
312
|
* Health check endpoint
|
|
302
313
|
*/
|
|
303
314
|
async healthCheck(): Promise<ExtendedApiResponse<MarketStats>> {
|
|
304
|
-
return this.makeRequest<MarketStats>("/api/v1/health");
|
|
315
|
+
return this.makeRequest<MarketStats>("/api/v1/health", false);
|
|
305
316
|
}
|
|
306
317
|
|
|
307
318
|
/**
|
|
@@ -313,10 +324,11 @@ export class ExtendedWrapper {
|
|
|
313
324
|
price: string,
|
|
314
325
|
options: {
|
|
315
326
|
postOnly?: boolean;
|
|
327
|
+
reduceOnly?: boolean;
|
|
316
328
|
previousOrderId?: number;
|
|
317
329
|
externalId?: string;
|
|
318
330
|
timeInForce?: TimeInForce;
|
|
319
|
-
} = {}
|
|
331
|
+
} = {},
|
|
320
332
|
): Promise<ExtendedApiResponse<PlacedOrder>> {
|
|
321
333
|
return this.createOrder({
|
|
322
334
|
market_name: marketName,
|
|
@@ -327,13 +339,13 @@ export class ExtendedWrapper {
|
|
|
327
339
|
});
|
|
328
340
|
}
|
|
329
341
|
|
|
330
|
-
|
|
342
|
+
/**
|
|
331
343
|
* Get order by ID
|
|
332
344
|
* @param orderId - The ID of the order to get
|
|
333
345
|
* @returns The order
|
|
334
346
|
*/
|
|
335
|
-
|
|
336
|
-
return this.makeRequest<OpenOrder>(`/api/v1/orderId/${orderId}
|
|
347
|
+
async getOrderById(orderId: number): Promise<ExtendedApiResponse<OpenOrder>> {
|
|
348
|
+
return this.makeRequest<OpenOrder>(`/api/v1/orderId/${orderId}`, false);
|
|
337
349
|
}
|
|
338
350
|
|
|
339
351
|
/**
|
|
@@ -345,10 +357,11 @@ export class ExtendedWrapper {
|
|
|
345
357
|
price: string,
|
|
346
358
|
options: {
|
|
347
359
|
postOnly?: boolean;
|
|
360
|
+
reduceOnly?: boolean;
|
|
348
361
|
previousOrderId?: number;
|
|
349
362
|
externalId?: string;
|
|
350
363
|
timeInForce?: TimeInForce;
|
|
351
|
-
} = {}
|
|
364
|
+
} = {},
|
|
352
365
|
): Promise<ExtendedApiResponse<PlacedOrder>> {
|
|
353
366
|
return this.createOrder({
|
|
354
367
|
market_name: marketName,
|
|
@@ -363,7 +376,7 @@ export class ExtendedWrapper {
|
|
|
363
376
|
* Get positions for a specific market
|
|
364
377
|
*/
|
|
365
378
|
async getPositionsForMarket(
|
|
366
|
-
marketName: string
|
|
379
|
+
marketName: string,
|
|
367
380
|
): Promise<ExtendedApiResponse<Position[]>> {
|
|
368
381
|
return this.getPositions(marketName);
|
|
369
382
|
}
|
|
@@ -372,7 +385,7 @@ export class ExtendedWrapper {
|
|
|
372
385
|
* Get open orders for a specific market
|
|
373
386
|
*/
|
|
374
387
|
async getOpenOrdersForMarket(
|
|
375
|
-
marketName: string
|
|
388
|
+
marketName: string,
|
|
376
389
|
): Promise<ExtendedApiResponse<OpenOrder[]>> {
|
|
377
390
|
return this.getOpenOrders(marketName);
|
|
378
391
|
}
|
|
@@ -383,21 +396,25 @@ export class ExtendedWrapper {
|
|
|
383
396
|
async cancelOrderById(orderId: number): Promise<ExtendedApiResponse<{}>> {
|
|
384
397
|
return this.cancelOrder({ order_id: orderId });
|
|
385
398
|
}
|
|
386
|
-
|
|
399
|
+
|
|
387
400
|
/**
|
|
388
401
|
* Get order history for a specific market
|
|
389
402
|
* @param marketName - The name of the market to get order history for
|
|
390
403
|
* @returns The order history for the specified market
|
|
391
404
|
*/
|
|
392
|
-
async getOrderHistory(
|
|
393
|
-
|
|
405
|
+
async getOrderHistory(
|
|
406
|
+
marketName: string,
|
|
407
|
+
): Promise<ExtendedApiResponse<OpenOrder[]>> {
|
|
408
|
+
return this.makeRequest<OpenOrder[]>(`/api/v1/marketOrders/${marketName}`, false);
|
|
394
409
|
}
|
|
395
410
|
|
|
396
411
|
/**
|
|
397
412
|
* Withdraw USDC (convenience method)
|
|
398
413
|
* Returns data as number | string to preserve precision for large integers
|
|
399
414
|
*/
|
|
400
|
-
async withdrawUSDC(
|
|
415
|
+
async withdrawUSDC(
|
|
416
|
+
amount: string,
|
|
417
|
+
): Promise<ExtendedApiResponse<number | string>> {
|
|
401
418
|
return this.withdraw({ amount, asset: "USDC" });
|
|
402
419
|
}
|
|
403
420
|
|
|
@@ -409,16 +426,42 @@ export class ExtendedWrapper {
|
|
|
409
426
|
async getFundingRates(
|
|
410
427
|
marketName: string,
|
|
411
428
|
side: string,
|
|
412
|
-
startTime
|
|
429
|
+
startTime?: number,
|
|
413
430
|
endTime?: number,
|
|
414
|
-
|
|
431
|
+
// in epoch milliseconds
|
|
415
432
|
): Promise<ExtendedApiResponse<FundingRate[]>> {
|
|
416
|
-
const endTimeParam = endTime !== undefined ? `&end_time=${endTime}` :
|
|
417
|
-
const startTimeParam =
|
|
418
|
-
|
|
433
|
+
const endTimeParam = endTime !== undefined ? `&end_time=${endTime}` : "";
|
|
434
|
+
const startTimeParam =
|
|
435
|
+
startTime !== undefined ? `&start_time=${startTime}` : "";
|
|
436
|
+
const response = await this.makeRequest<FundingRate[]>(
|
|
419
437
|
`/api/v1/markets/funding-rates?market_name=${encodeURIComponent(
|
|
420
|
-
marketName
|
|
421
|
-
)}&side=${encodeURIComponent(side)}${startTimeParam}${endTimeParam}
|
|
438
|
+
marketName,
|
|
439
|
+
)}&side=${encodeURIComponent(side)}${startTimeParam}${endTimeParam}`,
|
|
440
|
+
true
|
|
441
|
+
);
|
|
442
|
+
return response;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Get funding payments for a specific market.
|
|
447
|
+
*/
|
|
448
|
+
async getUserFundingPayments(
|
|
449
|
+
marketName: string,
|
|
450
|
+
side: string,
|
|
451
|
+
startTime: number,
|
|
452
|
+
limit?: number,
|
|
453
|
+
cursor?: number,
|
|
454
|
+
): Promise<ExtendedApiResponse<FundingPayment[]>> {
|
|
455
|
+
const params = new URLSearchParams();
|
|
456
|
+
params.append("start_time", String(startTime));
|
|
457
|
+
params.append("market_names", marketName);
|
|
458
|
+
params.append("side", side);
|
|
459
|
+
if (limit !== undefined) params.append("limit", String(limit));
|
|
460
|
+
if (cursor !== undefined) params.append("cursor", String(cursor));
|
|
461
|
+
|
|
462
|
+
return this.makeRequest<FundingPayment[]>(
|
|
463
|
+
`/api/v1/account/funding-payments?${params.toString()}`,
|
|
464
|
+
true,
|
|
422
465
|
);
|
|
423
466
|
}
|
|
424
467
|
}
|