@carrot-protocol/boost-http-client 0.4.4-handoff-dev-06f2933 → 0.4.4-handoff-dev-9a1c50a
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/index.d.ts +5 -6
- package/dist/index.js +38 -25
- package/dist/types.d.ts +9 -1
- package/package.json +1 -1
- package/src/index.ts +45 -17
- package/src/types.ts +9 -1
package/dist/index.d.ts
CHANGED
|
@@ -54,32 +54,31 @@ export declare class Client extends ApiClient {
|
|
|
54
54
|
* @returns Bank details
|
|
55
55
|
*/
|
|
56
56
|
getBank(bankAddress: web3.PublicKey): Promise<GetBankResponse>;
|
|
57
|
-
deposit(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, uiAmount: number): Promise<string>;
|
|
58
|
-
withdraw(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, uiAmount: number, withdrawAll: boolean): Promise<string>;
|
|
57
|
+
deposit(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, uiAmount: number, useJito: boolean): Promise<string>;
|
|
58
|
+
withdraw(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, uiAmount: number, withdrawAll: boolean, useJito: boolean): Promise<string>;
|
|
59
59
|
/**
|
|
60
60
|
* Deposit collateral and create a leveraged position
|
|
61
61
|
* @param request Deposit leverage request parameters
|
|
62
62
|
* @returns Deposit leverage operation result
|
|
63
63
|
*/
|
|
64
|
-
depositLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, leverage: number, slippageBps: number): Promise<string>;
|
|
64
|
+
depositLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, leverage: number, slippageBps: number, useJito: boolean, isHandoff: boolean): Promise<string>;
|
|
65
65
|
/**
|
|
66
66
|
* Adjust the leverage of an existing position
|
|
67
67
|
* @param request Adjust leverage request parameters
|
|
68
68
|
* @returns Adjust leverage operation result
|
|
69
69
|
*/
|
|
70
|
-
adjustLeverage(clendAccount: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, leverage: number, slippageBps: number): Promise<string>;
|
|
70
|
+
adjustLeverage(clendAccount: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, leverage: number, slippageBps: number, useJito: boolean): Promise<string>;
|
|
71
71
|
/**
|
|
72
72
|
* Withdraw from or close a leveraged position
|
|
73
73
|
* @param request Withdraw leverage request parameters
|
|
74
74
|
* @returns Withdraw leverage operation result
|
|
75
75
|
*/
|
|
76
|
-
withdrawLeverage(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<string>;
|
|
76
|
+
withdrawLeverage(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean, useJito: boolean): Promise<string>;
|
|
77
77
|
/**
|
|
78
78
|
* Withdraw emissions from a bank
|
|
79
79
|
* @returns Withdraw emissions operation result
|
|
80
80
|
*/
|
|
81
81
|
withdrawEmissions(clendAccount: web3.PublicKey): Promise<string>;
|
|
82
|
-
handoffDepositLeverage(): Promise<string>;
|
|
83
82
|
getPerformanceChartingExtension(clendAccount: web3.PublicKey): Promise<PositionChartingExtension>;
|
|
84
83
|
getGroupChartingExtension(group: web3.PublicKey): Promise<GroupChartingExtension>;
|
|
85
84
|
getWalletChartingExtension(address?: web3.PublicKey): Promise<WalletChartingExtension>;
|
package/dist/index.js
CHANGED
|
@@ -72,29 +72,32 @@ class Client extends api_1.ApiClient {
|
|
|
72
72
|
return this.provider.wallet.publicKey;
|
|
73
73
|
}
|
|
74
74
|
// sign and send tx to api for sending to network
|
|
75
|
-
async send(unsignedBase64Tx, userRequestId) {
|
|
75
|
+
async send(unsignedBase64Tx, userRequestId, useJito, handoffTxns = []) {
|
|
76
76
|
if (this.dryRun) {
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
console.log("unsignedBase64Tx", unsignedBase64Tx);
|
|
78
|
+
if (handoffTxns.length > 0)
|
|
79
|
+
console.log("handoffTxns", handoffTxns);
|
|
79
80
|
console.log("dry run enabled, exiting before sending tx");
|
|
80
81
|
return "";
|
|
81
82
|
}
|
|
82
|
-
//
|
|
83
|
+
// 1. Sign the primary transaction (User Transaction)
|
|
83
84
|
const txBytes = Buffer.from(unsignedBase64Tx, "base64");
|
|
84
85
|
const tx = anchor_1.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
85
|
-
// sign tx
|
|
86
86
|
const signedTx = await this.provider.wallet.signTransaction(tx);
|
|
87
|
+
// Grab signature for return value
|
|
87
88
|
const txSig = signedTx.signatures[0];
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
//
|
|
89
|
+
const encodedSignedUserTx = Buffer.from(signedTx.serialize()).toString("base64");
|
|
90
|
+
// 2. Construct the bundle
|
|
91
|
+
// The bundle consists of [UserSignedTx, ...PreSignedHandoffTxs]
|
|
92
|
+
const allTxns = [encodedSignedUserTx, ...handoffTxns];
|
|
93
|
+
// 3. Send to API
|
|
91
94
|
const sendRequest = {
|
|
92
95
|
userRequestId,
|
|
93
|
-
txns:
|
|
96
|
+
txns: allTxns,
|
|
97
|
+
useJito,
|
|
94
98
|
};
|
|
95
|
-
// send to api
|
|
96
99
|
await this.handleApiCall(() => this.http.post(`send`, sendRequest));
|
|
97
|
-
//
|
|
100
|
+
// Return signature of the user's transaction
|
|
98
101
|
return bs58_1.default.encode(txSig);
|
|
99
102
|
}
|
|
100
103
|
/**
|
|
@@ -326,29 +329,31 @@ class Client extends api_1.ApiClient {
|
|
|
326
329
|
};
|
|
327
330
|
return response;
|
|
328
331
|
}
|
|
329
|
-
async deposit(clendGroup, clendAccount, inputTokenMint, uiAmount) {
|
|
332
|
+
async deposit(clendGroup, clendAccount, inputTokenMint, uiAmount, useJito) {
|
|
330
333
|
const req = {
|
|
331
334
|
owner: this.address(),
|
|
332
335
|
clendGroup,
|
|
333
336
|
clendAccount,
|
|
334
337
|
inputTokenMint,
|
|
335
338
|
depositAmountUi: uiAmount,
|
|
339
|
+
useJito,
|
|
336
340
|
};
|
|
337
341
|
const body = await this.handleApiCall(() => this.http.post("deposit", JSON.stringify(req)));
|
|
338
342
|
const depositResponse = JSON.parse(body);
|
|
339
|
-
const txSig = await this.send(depositResponse.unsignedBase64Tx, depositResponse.userRequestId);
|
|
343
|
+
const txSig = await this.send(depositResponse.unsignedBase64Tx, depositResponse.userRequestId, false);
|
|
340
344
|
return txSig;
|
|
341
345
|
}
|
|
342
|
-
async withdraw(clendAccount, outputTokenMint, uiAmount, withdrawAll) {
|
|
346
|
+
async withdraw(clendAccount, outputTokenMint, uiAmount, withdrawAll, useJito) {
|
|
343
347
|
const req = {
|
|
344
348
|
clendAccount,
|
|
345
349
|
outputTokenMint,
|
|
346
350
|
withdrawAmountUi: uiAmount,
|
|
347
351
|
withdrawAll,
|
|
352
|
+
useJito,
|
|
348
353
|
};
|
|
349
354
|
const body = await this.handleApiCall(() => this.http.post("withdraw", JSON.stringify(req)));
|
|
350
355
|
const withdrawResponse = JSON.parse(body);
|
|
351
|
-
const txSig = await this.send(withdrawResponse.unsignedBase64Tx, withdrawResponse.userRequestId);
|
|
356
|
+
const txSig = await this.send(withdrawResponse.unsignedBase64Tx, withdrawResponse.userRequestId, false);
|
|
352
357
|
return txSig;
|
|
353
358
|
}
|
|
354
359
|
/**
|
|
@@ -356,7 +361,7 @@ class Client extends api_1.ApiClient {
|
|
|
356
361
|
* @param request Deposit leverage request parameters
|
|
357
362
|
* @returns Deposit leverage operation result
|
|
358
363
|
*/
|
|
359
|
-
async depositLeverage(clendGroup, clendAccount, inputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, leverage, slippageBps) {
|
|
364
|
+
async depositLeverage(clendGroup, clendAccount, inputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, leverage, slippageBps, useJito, isHandoff) {
|
|
360
365
|
const req = {
|
|
361
366
|
owner: this.address(),
|
|
362
367
|
clendGroup,
|
|
@@ -367,10 +372,18 @@ class Client extends api_1.ApiClient {
|
|
|
367
372
|
depositAmountUi: uiAmount,
|
|
368
373
|
leverage,
|
|
369
374
|
slippageBps,
|
|
375
|
+
useJito,
|
|
376
|
+
isHandoff,
|
|
370
377
|
};
|
|
371
378
|
const body = await this.handleApiCall(() => this.http.post("leverage/deposit", JSON.stringify(req)));
|
|
372
379
|
const depositLeverageResponse = JSON.parse(body);
|
|
373
|
-
|
|
380
|
+
let handoffTxns = [];
|
|
381
|
+
if (depositLeverageResponse.txns.length > 1) {
|
|
382
|
+
handoffTxns = depositLeverageResponse.txns.slice(1);
|
|
383
|
+
}
|
|
384
|
+
const userTx = depositLeverageResponse.txns[0];
|
|
385
|
+
const txSig = await this.send(userTx, depositLeverageResponse.userRequestId, req.useJito, handoffTxns);
|
|
386
|
+
return txSig;
|
|
374
387
|
return txSig;
|
|
375
388
|
}
|
|
376
389
|
/**
|
|
@@ -378,17 +391,18 @@ class Client extends api_1.ApiClient {
|
|
|
378
391
|
* @param request Adjust leverage request parameters
|
|
379
392
|
* @returns Adjust leverage operation result
|
|
380
393
|
*/
|
|
381
|
-
async adjustLeverage(clendAccount, assetTokenMint, liabilityTokenMint, leverage, slippageBps) {
|
|
394
|
+
async adjustLeverage(clendAccount, assetTokenMint, liabilityTokenMint, leverage, slippageBps, useJito) {
|
|
382
395
|
const req = {
|
|
383
396
|
clendAccount,
|
|
384
397
|
assetTokenMint,
|
|
385
398
|
liabilityTokenMint,
|
|
386
399
|
leverage,
|
|
387
400
|
slippageBps,
|
|
401
|
+
useJito,
|
|
388
402
|
};
|
|
389
403
|
const body = await this.handleApiCall(() => this.http.post("leverage/adjust", JSON.stringify(req)));
|
|
390
404
|
const adjustLeverageResponse = JSON.parse(body);
|
|
391
|
-
const txSig = await this.send(adjustLeverageResponse.unsignedBase64Tx, adjustLeverageResponse.userRequestId);
|
|
405
|
+
const txSig = await this.send(adjustLeverageResponse.unsignedBase64Tx, adjustLeverageResponse.userRequestId, false);
|
|
392
406
|
return txSig;
|
|
393
407
|
}
|
|
394
408
|
/**
|
|
@@ -396,7 +410,7 @@ class Client extends api_1.ApiClient {
|
|
|
396
410
|
* @param request Withdraw leverage request parameters
|
|
397
411
|
* @returns Withdraw leverage operation result
|
|
398
412
|
*/
|
|
399
|
-
async withdrawLeverage(clendAccount, outputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, slippageBps, withdrawAll) {
|
|
413
|
+
async withdrawLeverage(clendAccount, outputTokenMint, assetTokenMint, liabilityTokenMint, uiAmount, slippageBps, withdrawAll, useJito) {
|
|
400
414
|
const req = {
|
|
401
415
|
clendAccount,
|
|
402
416
|
outputTokenMint,
|
|
@@ -405,10 +419,11 @@ class Client extends api_1.ApiClient {
|
|
|
405
419
|
withdrawAmountUi: uiAmount,
|
|
406
420
|
slippageBps,
|
|
407
421
|
withdrawAll,
|
|
422
|
+
useJito,
|
|
408
423
|
};
|
|
409
424
|
const body = await this.handleApiCall(() => this.http.post("leverage/withdraw", JSON.stringify(req)));
|
|
410
425
|
const withdrawLeverageResponse = JSON.parse(body);
|
|
411
|
-
const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx, withdrawLeverageResponse.userRequestId);
|
|
426
|
+
const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx, withdrawLeverageResponse.userRequestId, true);
|
|
412
427
|
return txSig;
|
|
413
428
|
}
|
|
414
429
|
/**
|
|
@@ -418,15 +433,13 @@ class Client extends api_1.ApiClient {
|
|
|
418
433
|
async withdrawEmissions(clendAccount) {
|
|
419
434
|
const req = {
|
|
420
435
|
clendAccount,
|
|
436
|
+
useJito: false,
|
|
421
437
|
};
|
|
422
438
|
const body = await this.handleApiCall(() => this.http.post("emissions/withdraw", JSON.stringify(req)));
|
|
423
439
|
const withdrawEmissionsResponse = JSON.parse(body);
|
|
424
|
-
const txSig = await this.send(withdrawEmissionsResponse.unsignedBase64Tx, withdrawEmissionsResponse.userRequestId);
|
|
440
|
+
const txSig = await this.send(withdrawEmissionsResponse.unsignedBase64Tx, withdrawEmissionsResponse.userRequestId, false);
|
|
425
441
|
return txSig;
|
|
426
442
|
}
|
|
427
|
-
async handoffDepositLeverage() {
|
|
428
|
-
return "";
|
|
429
|
-
}
|
|
430
443
|
async getPerformanceChartingExtension(clendAccount) {
|
|
431
444
|
return new position_1.PositionChartingExtension(this.baseUrl, clendAccount);
|
|
432
445
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { GroupChartingExtension } from "./charting/group";
|
|
|
6
6
|
export interface SendRequest {
|
|
7
7
|
userRequestId: string;
|
|
8
8
|
txns: string[];
|
|
9
|
+
useJito: boolean;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Request to deposit collateral
|
|
@@ -16,6 +17,7 @@ export interface DepositRequest {
|
|
|
16
17
|
clendAccount: web3.PublicKey | null;
|
|
17
18
|
inputTokenMint: web3.PublicKey;
|
|
18
19
|
depositAmountUi: number;
|
|
20
|
+
useJito: boolean;
|
|
19
21
|
}
|
|
20
22
|
export interface DepositResponse {
|
|
21
23
|
userRequestId: string;
|
|
@@ -29,6 +31,7 @@ export interface WithdrawRequest {
|
|
|
29
31
|
outputTokenMint: web3.PublicKey;
|
|
30
32
|
withdrawAmountUi: number;
|
|
31
33
|
withdrawAll: boolean;
|
|
34
|
+
useJito: boolean;
|
|
32
35
|
}
|
|
33
36
|
export interface WithdrawResponse {
|
|
34
37
|
userRequestId: string;
|
|
@@ -47,13 +50,15 @@ export interface DepositLeverageRequest {
|
|
|
47
50
|
depositAmountUi: number;
|
|
48
51
|
leverage: number;
|
|
49
52
|
slippageBps: number;
|
|
53
|
+
useJito: boolean;
|
|
54
|
+
isHandoff: boolean;
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
52
57
|
* Response for deposit leverage operation
|
|
53
58
|
*/
|
|
54
59
|
export interface DepositLeverageResponse {
|
|
55
60
|
userRequestId: string;
|
|
56
|
-
|
|
61
|
+
txns: string[];
|
|
57
62
|
}
|
|
58
63
|
/**
|
|
59
64
|
* Request to adjust the leverage of an existing position
|
|
@@ -64,6 +69,7 @@ export interface AdjustLeverageRequest {
|
|
|
64
69
|
liabilityTokenMint: web3.PublicKey;
|
|
65
70
|
leverage: number;
|
|
66
71
|
slippageBps: number;
|
|
72
|
+
useJito: boolean;
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
69
75
|
* Response for adjust leverage operation
|
|
@@ -83,6 +89,7 @@ export interface WithdrawLeverageRequest {
|
|
|
83
89
|
withdrawAmountUi: number;
|
|
84
90
|
slippageBps: number;
|
|
85
91
|
withdrawAll: boolean;
|
|
92
|
+
useJito: boolean;
|
|
86
93
|
}
|
|
87
94
|
/**
|
|
88
95
|
* Response for withdraw leverage operation
|
|
@@ -96,6 +103,7 @@ export interface WithdrawLeverageResponse {
|
|
|
96
103
|
*/
|
|
97
104
|
export interface WithdrawEmissionsRequest {
|
|
98
105
|
clendAccount: web3.PublicKey;
|
|
106
|
+
useJito: boolean;
|
|
99
107
|
}
|
|
100
108
|
/**
|
|
101
109
|
* Response for withdraw emissions operation
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -75,37 +75,41 @@ export class Client extends ApiClient {
|
|
|
75
75
|
private async send(
|
|
76
76
|
unsignedBase64Tx: string,
|
|
77
77
|
userRequestId: string,
|
|
78
|
+
useJito: boolean,
|
|
79
|
+
handoffTxns: string[] = [], // Optional extra signed txs
|
|
78
80
|
): Promise<string> {
|
|
79
81
|
if (this.dryRun) {
|
|
80
|
-
|
|
81
|
-
console.log("
|
|
82
|
+
console.log("unsignedBase64Tx", unsignedBase64Tx);
|
|
83
|
+
if (handoffTxns.length > 0) console.log("handoffTxns", handoffTxns);
|
|
82
84
|
console.log("dry run enabled, exiting before sending tx");
|
|
83
85
|
return "";
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
//
|
|
88
|
+
// 1. Sign the primary transaction (User Transaction)
|
|
87
89
|
const txBytes = Buffer.from(unsignedBase64Tx, "base64");
|
|
88
90
|
const tx = web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
89
|
-
|
|
90
|
-
// sign tx
|
|
91
91
|
const signedTx = await this.provider!.wallet.signTransaction(tx);
|
|
92
|
-
const txSig = signedTx.signatures[0];
|
|
93
92
|
|
|
94
|
-
//
|
|
95
|
-
const
|
|
93
|
+
// Grab signature for return value
|
|
94
|
+
const txSig = signedTx.signatures[0];
|
|
95
|
+
const encodedSignedUserTx = Buffer.from(signedTx.serialize()).toString(
|
|
96
96
|
"base64",
|
|
97
97
|
);
|
|
98
98
|
|
|
99
|
-
//
|
|
99
|
+
// 2. Construct the bundle
|
|
100
|
+
// The bundle consists of [UserSignedTx, ...PreSignedHandoffTxs]
|
|
101
|
+
const allTxns = [encodedSignedUserTx, ...handoffTxns];
|
|
102
|
+
|
|
103
|
+
// 3. Send to API
|
|
100
104
|
const sendRequest: SendRequest = {
|
|
101
105
|
userRequestId,
|
|
102
|
-
txns:
|
|
106
|
+
txns: allTxns,
|
|
107
|
+
useJito,
|
|
103
108
|
};
|
|
104
109
|
|
|
105
|
-
// send to api
|
|
106
110
|
await this.handleApiCall(() => this.http.post(`send`, sendRequest));
|
|
107
111
|
|
|
108
|
-
//
|
|
112
|
+
// Return signature of the user's transaction
|
|
109
113
|
return encode.encode(txSig);
|
|
110
114
|
}
|
|
111
115
|
|
|
@@ -411,6 +415,7 @@ export class Client extends ApiClient {
|
|
|
411
415
|
clendAccount: web3.PublicKey | null,
|
|
412
416
|
inputTokenMint: web3.PublicKey,
|
|
413
417
|
uiAmount: number,
|
|
418
|
+
useJito: boolean,
|
|
414
419
|
): Promise<string> {
|
|
415
420
|
const req: DepositRequest = {
|
|
416
421
|
owner: this.address(),
|
|
@@ -418,6 +423,7 @@ export class Client extends ApiClient {
|
|
|
418
423
|
clendAccount,
|
|
419
424
|
inputTokenMint,
|
|
420
425
|
depositAmountUi: uiAmount,
|
|
426
|
+
useJito,
|
|
421
427
|
};
|
|
422
428
|
|
|
423
429
|
const body = await this.handleApiCall(() =>
|
|
@@ -429,6 +435,7 @@ export class Client extends ApiClient {
|
|
|
429
435
|
const txSig = await this.send(
|
|
430
436
|
depositResponse.unsignedBase64Tx,
|
|
431
437
|
depositResponse.userRequestId,
|
|
438
|
+
false,
|
|
432
439
|
);
|
|
433
440
|
|
|
434
441
|
return txSig;
|
|
@@ -439,12 +446,14 @@ export class Client extends ApiClient {
|
|
|
439
446
|
outputTokenMint: web3.PublicKey,
|
|
440
447
|
uiAmount: number,
|
|
441
448
|
withdrawAll: boolean,
|
|
449
|
+
useJito: boolean,
|
|
442
450
|
): Promise<string> {
|
|
443
451
|
const req: WithdrawRequest = {
|
|
444
452
|
clendAccount,
|
|
445
453
|
outputTokenMint,
|
|
446
454
|
withdrawAmountUi: uiAmount,
|
|
447
455
|
withdrawAll,
|
|
456
|
+
useJito,
|
|
448
457
|
};
|
|
449
458
|
|
|
450
459
|
const body = await this.handleApiCall(() =>
|
|
@@ -456,6 +465,7 @@ export class Client extends ApiClient {
|
|
|
456
465
|
const txSig = await this.send(
|
|
457
466
|
withdrawResponse.unsignedBase64Tx,
|
|
458
467
|
withdrawResponse.userRequestId,
|
|
468
|
+
false,
|
|
459
469
|
);
|
|
460
470
|
|
|
461
471
|
return txSig;
|
|
@@ -475,6 +485,8 @@ export class Client extends ApiClient {
|
|
|
475
485
|
uiAmount: number,
|
|
476
486
|
leverage: number,
|
|
477
487
|
slippageBps: number,
|
|
488
|
+
useJito: boolean,
|
|
489
|
+
isHandoff: boolean,
|
|
478
490
|
): Promise<string> {
|
|
479
491
|
const req: DepositLeverageRequest = {
|
|
480
492
|
owner: this.address(),
|
|
@@ -486,6 +498,8 @@ export class Client extends ApiClient {
|
|
|
486
498
|
depositAmountUi: uiAmount,
|
|
487
499
|
leverage,
|
|
488
500
|
slippageBps,
|
|
501
|
+
useJito,
|
|
502
|
+
isHandoff,
|
|
489
503
|
};
|
|
490
504
|
const body = await this.handleApiCall(() =>
|
|
491
505
|
this.http.post("leverage/deposit", JSON.stringify(req)),
|
|
@@ -493,12 +507,22 @@ export class Client extends ApiClient {
|
|
|
493
507
|
|
|
494
508
|
const depositLeverageResponse: DepositLeverageResponse = JSON.parse(body);
|
|
495
509
|
|
|
510
|
+
let handoffTxns: string[] = [];
|
|
511
|
+
if (depositLeverageResponse.txns.length > 1) {
|
|
512
|
+
handoffTxns = depositLeverageResponse.txns.slice(1);
|
|
513
|
+
}
|
|
514
|
+
const userTx = depositLeverageResponse.txns[0];
|
|
515
|
+
|
|
496
516
|
const txSig = await this.send(
|
|
497
|
-
|
|
517
|
+
userTx,
|
|
498
518
|
depositLeverageResponse.userRequestId,
|
|
519
|
+
req.useJito,
|
|
520
|
+
handoffTxns,
|
|
499
521
|
);
|
|
500
522
|
|
|
501
523
|
return txSig;
|
|
524
|
+
|
|
525
|
+
return txSig;
|
|
502
526
|
}
|
|
503
527
|
|
|
504
528
|
/**
|
|
@@ -512,6 +536,7 @@ export class Client extends ApiClient {
|
|
|
512
536
|
liabilityTokenMint: web3.PublicKey,
|
|
513
537
|
leverage: number,
|
|
514
538
|
slippageBps: number,
|
|
539
|
+
useJito: boolean,
|
|
515
540
|
): Promise<string> {
|
|
516
541
|
const req: AdjustLeverageRequest = {
|
|
517
542
|
clendAccount,
|
|
@@ -519,6 +544,7 @@ export class Client extends ApiClient {
|
|
|
519
544
|
liabilityTokenMint,
|
|
520
545
|
leverage,
|
|
521
546
|
slippageBps,
|
|
547
|
+
useJito,
|
|
522
548
|
};
|
|
523
549
|
const body = await this.handleApiCall(() =>
|
|
524
550
|
this.http.post("leverage/adjust", JSON.stringify(req)),
|
|
@@ -529,6 +555,7 @@ export class Client extends ApiClient {
|
|
|
529
555
|
const txSig = await this.send(
|
|
530
556
|
adjustLeverageResponse.unsignedBase64Tx,
|
|
531
557
|
adjustLeverageResponse.userRequestId,
|
|
558
|
+
false,
|
|
532
559
|
);
|
|
533
560
|
|
|
534
561
|
return txSig;
|
|
@@ -547,6 +574,7 @@ export class Client extends ApiClient {
|
|
|
547
574
|
uiAmount: number,
|
|
548
575
|
slippageBps: number,
|
|
549
576
|
withdrawAll: boolean,
|
|
577
|
+
useJito: boolean,
|
|
550
578
|
): Promise<string> {
|
|
551
579
|
const req: WithdrawLeverageRequest = {
|
|
552
580
|
clendAccount,
|
|
@@ -556,6 +584,7 @@ export class Client extends ApiClient {
|
|
|
556
584
|
withdrawAmountUi: uiAmount,
|
|
557
585
|
slippageBps,
|
|
558
586
|
withdrawAll,
|
|
587
|
+
useJito,
|
|
559
588
|
};
|
|
560
589
|
const body = await this.handleApiCall(() =>
|
|
561
590
|
this.http.post("leverage/withdraw", JSON.stringify(req)),
|
|
@@ -566,6 +595,7 @@ export class Client extends ApiClient {
|
|
|
566
595
|
const txSig = await this.send(
|
|
567
596
|
withdrawLeverageResponse.unsignedBase64Tx,
|
|
568
597
|
withdrawLeverageResponse.userRequestId,
|
|
598
|
+
true,
|
|
569
599
|
);
|
|
570
600
|
|
|
571
601
|
return txSig;
|
|
@@ -578,6 +608,7 @@ export class Client extends ApiClient {
|
|
|
578
608
|
async withdrawEmissions(clendAccount: web3.PublicKey): Promise<string> {
|
|
579
609
|
const req: WithdrawEmissionsRequest = {
|
|
580
610
|
clendAccount,
|
|
611
|
+
useJito: false,
|
|
581
612
|
};
|
|
582
613
|
|
|
583
614
|
const body = await this.handleApiCall(() =>
|
|
@@ -590,15 +621,12 @@ export class Client extends ApiClient {
|
|
|
590
621
|
const txSig = await this.send(
|
|
591
622
|
withdrawEmissionsResponse.unsignedBase64Tx,
|
|
592
623
|
withdrawEmissionsResponse.userRequestId,
|
|
624
|
+
false,
|
|
593
625
|
);
|
|
594
626
|
|
|
595
627
|
return txSig;
|
|
596
628
|
}
|
|
597
629
|
|
|
598
|
-
async handoffDepositLeverage(): Promise<string> {
|
|
599
|
-
return "";
|
|
600
|
-
}
|
|
601
|
-
|
|
602
630
|
public async getPerformanceChartingExtension(
|
|
603
631
|
clendAccount: web3.PublicKey,
|
|
604
632
|
): Promise<PositionChartingExtension> {
|
package/src/types.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { GroupChartingExtension } from "./charting/group";
|
|
|
8
8
|
export interface SendRequest {
|
|
9
9
|
userRequestId: string;
|
|
10
10
|
txns: string[];
|
|
11
|
+
useJito: boolean;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -19,6 +20,7 @@ export interface DepositRequest {
|
|
|
19
20
|
clendAccount: web3.PublicKey | null;
|
|
20
21
|
inputTokenMint: web3.PublicKey;
|
|
21
22
|
depositAmountUi: number;
|
|
23
|
+
useJito: boolean;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export interface DepositResponse {
|
|
@@ -34,6 +36,7 @@ export interface WithdrawRequest {
|
|
|
34
36
|
outputTokenMint: web3.PublicKey;
|
|
35
37
|
withdrawAmountUi: number;
|
|
36
38
|
withdrawAll: boolean;
|
|
39
|
+
useJito: boolean;
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
export interface WithdrawResponse {
|
|
@@ -54,6 +57,8 @@ export interface DepositLeverageRequest {
|
|
|
54
57
|
depositAmountUi: number;
|
|
55
58
|
leverage: number;
|
|
56
59
|
slippageBps: number;
|
|
60
|
+
useJito: boolean;
|
|
61
|
+
isHandoff: boolean;
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
/**
|
|
@@ -61,7 +66,7 @@ export interface DepositLeverageRequest {
|
|
|
61
66
|
*/
|
|
62
67
|
export interface DepositLeverageResponse {
|
|
63
68
|
userRequestId: string;
|
|
64
|
-
|
|
69
|
+
txns: string[];
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
/**
|
|
@@ -73,6 +78,7 @@ export interface AdjustLeverageRequest {
|
|
|
73
78
|
liabilityTokenMint: web3.PublicKey;
|
|
74
79
|
leverage: number;
|
|
75
80
|
slippageBps: number;
|
|
81
|
+
useJito: boolean;
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
/**
|
|
@@ -94,6 +100,7 @@ export interface WithdrawLeverageRequest {
|
|
|
94
100
|
withdrawAmountUi: number;
|
|
95
101
|
slippageBps: number;
|
|
96
102
|
withdrawAll: boolean;
|
|
103
|
+
useJito: boolean;
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
/**
|
|
@@ -109,6 +116,7 @@ export interface WithdrawLeverageResponse {
|
|
|
109
116
|
*/
|
|
110
117
|
export interface WithdrawEmissionsRequest {
|
|
111
118
|
clendAccount: web3.PublicKey;
|
|
119
|
+
useJito: boolean;
|
|
112
120
|
}
|
|
113
121
|
|
|
114
122
|
/**
|