@carrot-protocol/boost-http-client 0.2.15-group-refactor1-dev-57b10ba → 0.2.15-group-refactor1-dev-69572ae
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 +10 -4
- package/dist/index.js +14 -8
- package/dist/types.d.ts +13 -0
- package/package.json +1 -1
- package/src/index.ts +30 -12
- package/src/types.ts +15 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnchorProvider, web3 } from "@coral-xyz/anchor";
|
|
2
|
-
import { GetBankResponse, GetGroupResponse, GetGroupsResponse } from "./types";
|
|
2
|
+
import { GetBankResponse, GetUserResponse, GetGroupResponse, GetGroupsResponse } from "./types";
|
|
3
3
|
export * from "./types";
|
|
4
4
|
export * from "./utils";
|
|
5
5
|
export * as Common from "@carrot-protocol/clend-common";
|
|
@@ -22,7 +22,7 @@ export declare class Client {
|
|
|
22
22
|
* @returns Index details
|
|
23
23
|
*/
|
|
24
24
|
index(): Promise<any>;
|
|
25
|
-
getUser(user: web3.PublicKey, groups: web3.PublicKey[], getClendAccountSummary: boolean): Promise<
|
|
25
|
+
getUser(user: web3.PublicKey, groups: web3.PublicKey[], getClendAccountSummary: boolean): Promise<GetUserResponse>;
|
|
26
26
|
/**
|
|
27
27
|
* Get all groups
|
|
28
28
|
* @param includeBankData Whether to include bank data in the response, if not strictly necessary keep false
|
|
@@ -52,11 +52,17 @@ export declare class Client {
|
|
|
52
52
|
* @param request Adjust leverage request parameters
|
|
53
53
|
* @returns Adjust leverage operation result
|
|
54
54
|
*/
|
|
55
|
-
adjustLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, leverage: number, slippageBps: number): Promise<
|
|
55
|
+
adjustLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, leverage: number, slippageBps: number): Promise<string>;
|
|
56
56
|
/**
|
|
57
57
|
* Withdraw from or close a leveraged position
|
|
58
58
|
* @param request Withdraw leverage request parameters
|
|
59
59
|
* @returns Withdraw leverage operation result
|
|
60
60
|
*/
|
|
61
|
-
withdrawLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<
|
|
61
|
+
withdrawLeverage(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, assetTokenMint: web3.PublicKey, liabilityTokenMint: web3.PublicKey, uiAmount: number, slippageBps: number, withdrawAll: boolean): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Withdraw emissions from a bank
|
|
64
|
+
* @param banks Banks to withdraw emissions, if empty, will withdraw from all banks
|
|
65
|
+
* @returns Withdraw emissions operation result
|
|
66
|
+
*/
|
|
67
|
+
withdrawEmissions(): Promise<string>;
|
|
62
68
|
}
|
package/dist/index.js
CHANGED
|
@@ -354,16 +354,22 @@ class Client {
|
|
|
354
354
|
const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx, withdrawLeverageResponse.userRequestId);
|
|
355
355
|
return txSig;
|
|
356
356
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
357
|
+
/**
|
|
358
|
+
* Withdraw emissions from a bank
|
|
359
|
+
* @param banks Banks to withdraw emissions, if empty, will withdraw from all banks
|
|
360
|
+
* @returns Withdraw emissions operation result
|
|
361
|
+
*/
|
|
362
|
+
async withdrawEmissions() {
|
|
363
|
+
const req = {
|
|
364
|
+
owner: this.address(),
|
|
365
|
+
};
|
|
366
|
+
const body = await handleApiCall(() => this.http.post("emissions/withdraw", JSON.stringify(req)));
|
|
367
|
+
const withdrawEmissionsResponse = JSON.parse(body);
|
|
368
|
+
const txSig = await this.send(withdrawEmissionsResponse.unsignedBase64Tx, withdrawEmissionsResponse.userRequestId);
|
|
369
|
+
return txSig;
|
|
365
370
|
}
|
|
366
371
|
}
|
|
372
|
+
exports.Client = Client;
|
|
367
373
|
// Helper function to handle API calls
|
|
368
374
|
async function handleApiCall(call) {
|
|
369
375
|
try {
|
package/dist/types.d.ts
CHANGED
|
@@ -64,6 +64,19 @@ export interface WithdrawLeverageResponse {
|
|
|
64
64
|
userRequestId: string;
|
|
65
65
|
unsignedBase64Tx: string;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Request to withdraw emissions from a bank
|
|
69
|
+
*/
|
|
70
|
+
export interface WithdrawEmissionsRequest {
|
|
71
|
+
owner: web3.PublicKey;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Response for withdraw emissions operation
|
|
75
|
+
*/
|
|
76
|
+
export interface WithdrawEmissionsResponse {
|
|
77
|
+
userRequestId: string;
|
|
78
|
+
unsignedBase64Tx: string;
|
|
79
|
+
}
|
|
67
80
|
export interface GetGroupsResponse {
|
|
68
81
|
groups: GroupAndBanks[];
|
|
69
82
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -25,6 +25,8 @@ import {
|
|
|
25
25
|
GroupAndBanks,
|
|
26
26
|
BankEmissions,
|
|
27
27
|
BankEmissionsMode,
|
|
28
|
+
WithdrawEmissionsRequest,
|
|
29
|
+
WithdrawEmissionsResponse,
|
|
28
30
|
} from "./types";
|
|
29
31
|
import encode from "bs58";
|
|
30
32
|
|
|
@@ -108,7 +110,7 @@ export class Client {
|
|
|
108
110
|
user: web3.PublicKey,
|
|
109
111
|
groups: web3.PublicKey[],
|
|
110
112
|
getClendAccountSummary: boolean,
|
|
111
|
-
): Promise<
|
|
113
|
+
): Promise<GetUserResponse> {
|
|
112
114
|
// Make the API call to fetch the raw user data as a string.
|
|
113
115
|
const body = await handleApiCall(() =>
|
|
114
116
|
this.http.get(
|
|
@@ -406,7 +408,7 @@ export class Client {
|
|
|
406
408
|
liabilityTokenMint: web3.PublicKey,
|
|
407
409
|
leverage: number,
|
|
408
410
|
slippageBps: number,
|
|
409
|
-
): Promise<
|
|
411
|
+
): Promise<string> {
|
|
410
412
|
const req: AdjustLeverageRequest = {
|
|
411
413
|
owner: this.address(),
|
|
412
414
|
clendGroup,
|
|
@@ -444,7 +446,7 @@ export class Client {
|
|
|
444
446
|
uiAmount: number,
|
|
445
447
|
slippageBps: number,
|
|
446
448
|
withdrawAll: boolean,
|
|
447
|
-
): Promise<
|
|
449
|
+
): Promise<string> {
|
|
448
450
|
const req: WithdrawLeverageRequest = {
|
|
449
451
|
owner: this.address(),
|
|
450
452
|
clendGroup,
|
|
@@ -469,6 +471,31 @@ export class Client {
|
|
|
469
471
|
|
|
470
472
|
return txSig;
|
|
471
473
|
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Withdraw emissions from a bank
|
|
477
|
+
* @param banks Banks to withdraw emissions, if empty, will withdraw from all banks
|
|
478
|
+
* @returns Withdraw emissions operation result
|
|
479
|
+
*/
|
|
480
|
+
async withdrawEmissions(): Promise<string> {
|
|
481
|
+
const req: WithdrawEmissionsRequest = {
|
|
482
|
+
owner: this.address(),
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
const body = await handleApiCall(() =>
|
|
486
|
+
this.http.post("emissions/withdraw", JSON.stringify(req)),
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
const withdrawEmissionsResponse: WithdrawEmissionsResponse =
|
|
490
|
+
JSON.parse(body);
|
|
491
|
+
|
|
492
|
+
const txSig = await this.send(
|
|
493
|
+
withdrawEmissionsResponse.unsignedBase64Tx,
|
|
494
|
+
withdrawEmissionsResponse.userRequestId,
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
return txSig;
|
|
498
|
+
}
|
|
472
499
|
}
|
|
473
500
|
|
|
474
501
|
type ApiErrorPayload = {
|
|
@@ -478,15 +505,6 @@ type ApiErrorPayload = {
|
|
|
478
505
|
timestamp: string;
|
|
479
506
|
};
|
|
480
507
|
|
|
481
|
-
function handleStatusCode(statusCode: number): void {
|
|
482
|
-
switch (statusCode) {
|
|
483
|
-
case 200:
|
|
484
|
-
break;
|
|
485
|
-
default:
|
|
486
|
-
throw new Error(`unexpected status code: ${statusCode}`);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
508
|
// Helper function to handle API calls
|
|
491
509
|
async function handleApiCall<T>(
|
|
492
510
|
call: () => Promise<AxiosResponse<T>>,
|
package/src/types.ts
CHANGED
|
@@ -73,6 +73,21 @@ export interface WithdrawLeverageResponse {
|
|
|
73
73
|
unsignedBase64Tx: string;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Request to withdraw emissions from a bank
|
|
78
|
+
*/
|
|
79
|
+
export interface WithdrawEmissionsRequest {
|
|
80
|
+
owner: web3.PublicKey;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Response for withdraw emissions operation
|
|
85
|
+
*/
|
|
86
|
+
export interface WithdrawEmissionsResponse {
|
|
87
|
+
userRequestId: string;
|
|
88
|
+
unsignedBase64Tx: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
76
91
|
export interface GetGroupsResponse {
|
|
77
92
|
groups: GroupAndBanks[];
|
|
78
93
|
}
|