@carrot-protocol/boost-http-client 0.2.0-mrgn-fork1-dev-be6fd99 → 0.2.0-mrgn-fork1-dev-37e1e0b
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 -5
- package/dist/index.js +10 -9
- package/dist/types.d.ts +11 -19
- package/package.json +1 -1
- package/src/index.ts +12 -14
- package/src/types.ts +11 -18
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnchorProvider, web3 } from "@coral-xyz/anchor";
|
|
2
|
-
import { DepositLeverageRequest, GetBankResponse, GetUserResponse,
|
|
2
|
+
import { DepositLeverageRequest, GetBankResponse, GetUserResponse, AdjustLeverageRequest, WithdrawLeverageRequest } from "./types";
|
|
3
3
|
export * from "./types";
|
|
4
4
|
/**
|
|
5
5
|
* HTTP Client for Carrot Boost API
|
|
@@ -39,11 +39,11 @@ export declare class Client {
|
|
|
39
39
|
*/
|
|
40
40
|
depositLeverage(params: DepositLeverageRequest): Promise<string>;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
* @param request
|
|
44
|
-
* @returns
|
|
42
|
+
* Adjust the leverage of an existing position
|
|
43
|
+
* @param request Adjust leverage request parameters
|
|
44
|
+
* @returns Adjust leverage operation result
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
adjustLeverage(params: AdjustLeverageRequest): Promise<any>;
|
|
47
47
|
/**
|
|
48
48
|
* Withdraw from or close a leveraged position
|
|
49
49
|
* @param request Withdraw leverage request parameters
|
package/dist/index.js
CHANGED
|
@@ -70,7 +70,7 @@ class Client {
|
|
|
70
70
|
return this.provider.wallet.publicKey;
|
|
71
71
|
}
|
|
72
72
|
// sign and send tx to api for sending to network
|
|
73
|
-
async send(unsignedBase64Tx
|
|
73
|
+
async send(unsignedBase64Tx) {
|
|
74
74
|
// deserialize into tx obj
|
|
75
75
|
const txBytes = Buffer.from(unsignedBase64Tx, "base64");
|
|
76
76
|
const tx = anchor_1.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
@@ -81,7 +81,7 @@ class Client {
|
|
|
81
81
|
const encodedAndSignedTx = Buffer.from(signedTx.serialize()).toString("base64");
|
|
82
82
|
// create request obj
|
|
83
83
|
const sendRequest = {
|
|
84
|
-
txns: [encodedAndSignedTx
|
|
84
|
+
txns: [encodedAndSignedTx],
|
|
85
85
|
};
|
|
86
86
|
// send to api
|
|
87
87
|
await handleApiCall(() => this.http.post(`send`, sendRequest));
|
|
@@ -106,6 +106,7 @@ class Client {
|
|
|
106
106
|
user = this.address();
|
|
107
107
|
}
|
|
108
108
|
const body = await handleApiCall(() => this.http.get(`/user?user=${user.toString()}`));
|
|
109
|
+
console.log(JSON.stringify(body));
|
|
109
110
|
const response = JSON.parse(body);
|
|
110
111
|
return response;
|
|
111
112
|
}
|
|
@@ -131,14 +132,14 @@ class Client {
|
|
|
131
132
|
return txSig;
|
|
132
133
|
}
|
|
133
134
|
/**
|
|
134
|
-
*
|
|
135
|
-
* @param request
|
|
136
|
-
* @returns
|
|
135
|
+
* Adjust the leverage of an existing position
|
|
136
|
+
* @param request Adjust leverage request parameters
|
|
137
|
+
* @returns Adjust leverage operation result
|
|
137
138
|
*/
|
|
138
|
-
async
|
|
139
|
-
const body = await handleApiCall(() => this.http.post("leverage/
|
|
140
|
-
const
|
|
141
|
-
const txSig = await this.send(
|
|
139
|
+
async adjustLeverage(params) {
|
|
140
|
+
const body = await handleApiCall(() => this.http.post("leverage/adjust", JSON.stringify(params)));
|
|
141
|
+
const adjustLeverageResponse = JSON.parse(body);
|
|
142
|
+
const txSig = await this.send(adjustLeverageResponse.unsignedBase64Tx);
|
|
142
143
|
return txSig;
|
|
143
144
|
}
|
|
144
145
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BN, web3 } from "@coral-xyz/anchor";
|
|
2
|
-
import Decimal from "decimal.js";
|
|
3
2
|
export interface SendRequest {
|
|
4
3
|
txns: string[];
|
|
5
4
|
}
|
|
@@ -15,9 +14,9 @@ export interface CreateObligationResponse {
|
|
|
15
14
|
export interface DepositLeverageRequest {
|
|
16
15
|
owner: web3.PublicKey;
|
|
17
16
|
selectedTokenMint: web3.PublicKey;
|
|
18
|
-
depositAmount:
|
|
17
|
+
depositAmount: BN;
|
|
19
18
|
leverage: number;
|
|
20
|
-
|
|
19
|
+
slippageBps: number;
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
22
|
* Response for deposit leverage operation
|
|
@@ -26,17 +25,17 @@ export interface DepositLeverageResponse {
|
|
|
26
25
|
unsignedBase64Tx: string;
|
|
27
26
|
}
|
|
28
27
|
/**
|
|
29
|
-
* Request to
|
|
28
|
+
* Request to adjust the leverage of an existing position
|
|
30
29
|
*/
|
|
31
|
-
export interface
|
|
30
|
+
export interface AdjustLeverageRequest {
|
|
32
31
|
owner: web3.PublicKey;
|
|
33
32
|
leverage: number;
|
|
34
|
-
|
|
33
|
+
slippageBps: number;
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
37
|
-
* Response for
|
|
36
|
+
* Response for adjust leverage operation
|
|
38
37
|
*/
|
|
39
|
-
export interface
|
|
38
|
+
export interface AdjustLeverageResponse {
|
|
40
39
|
unsignedBase64Tx: string;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
@@ -45,9 +44,9 @@ export interface ModifyLeverageResponse {
|
|
|
45
44
|
export interface WithdrawLeverageRequest {
|
|
46
45
|
owner: web3.PublicKey;
|
|
47
46
|
selectedTokenMint: web3.PublicKey;
|
|
48
|
-
withdrawAmount:
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
withdrawAmount: BN;
|
|
48
|
+
slippageBps: number;
|
|
49
|
+
withdrawAll: boolean;
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
53
52
|
* Response for withdraw leverage operation
|
|
@@ -56,20 +55,13 @@ export interface WithdrawLeverageResponse {
|
|
|
56
55
|
unsignedBase64Tx: string;
|
|
57
56
|
}
|
|
58
57
|
export interface GetUserResponse {
|
|
59
|
-
netValue: number;
|
|
60
|
-
pnl: number;
|
|
61
|
-
netAPY: number;
|
|
62
|
-
leverage: number;
|
|
63
|
-
totalCollateral: number;
|
|
64
|
-
totalDebt: number;
|
|
65
|
-
ltv: number;
|
|
66
|
-
liquidationLtv: number;
|
|
67
58
|
usdcBalance: BN;
|
|
68
59
|
usdcBalanceUi: number;
|
|
69
60
|
jlpBalance: BN;
|
|
70
61
|
jlpBalanceUi: number;
|
|
71
62
|
solBalance: BN;
|
|
72
63
|
solBalanceUi: number;
|
|
64
|
+
clendAccount: any | undefined;
|
|
73
65
|
}
|
|
74
66
|
export interface GetBankResponse {
|
|
75
67
|
totalBorrowTVL: number;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
DepositLeverageResponse,
|
|
6
6
|
GetBankResponse,
|
|
7
7
|
GetUserResponse,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
AdjustLeverageRequest,
|
|
9
|
+
AdjustLeverageResponse,
|
|
10
10
|
SendRequest,
|
|
11
11
|
WithdrawLeverageRequest,
|
|
12
12
|
WithdrawLeverageResponse,
|
|
@@ -47,10 +47,7 @@ export class Client {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// sign and send tx to api for sending to network
|
|
50
|
-
private async send(
|
|
51
|
-
unsignedBase64Tx: string,
|
|
52
|
-
...signedBase64Txns: string[]
|
|
53
|
-
): Promise<string> {
|
|
50
|
+
private async send(unsignedBase64Tx: string): Promise<string> {
|
|
54
51
|
// deserialize into tx obj
|
|
55
52
|
const txBytes = Buffer.from(unsignedBase64Tx, "base64");
|
|
56
53
|
const tx = web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
|
|
@@ -66,7 +63,7 @@ export class Client {
|
|
|
66
63
|
|
|
67
64
|
// create request obj
|
|
68
65
|
const sendRequest: SendRequest = {
|
|
69
|
-
txns: [encodedAndSignedTx
|
|
66
|
+
txns: [encodedAndSignedTx],
|
|
70
67
|
};
|
|
71
68
|
|
|
72
69
|
// send to api
|
|
@@ -98,6 +95,7 @@ export class Client {
|
|
|
98
95
|
const body = await handleApiCall(() =>
|
|
99
96
|
this.http.get(`/user?user=${user.toString()}`),
|
|
100
97
|
);
|
|
98
|
+
console.log(JSON.stringify(body));
|
|
101
99
|
|
|
102
100
|
const response: GetUserResponse = JSON.parse(body);
|
|
103
101
|
|
|
@@ -137,18 +135,18 @@ export class Client {
|
|
|
137
135
|
}
|
|
138
136
|
|
|
139
137
|
/**
|
|
140
|
-
*
|
|
141
|
-
* @param request
|
|
142
|
-
* @returns
|
|
138
|
+
* Adjust the leverage of an existing position
|
|
139
|
+
* @param request Adjust leverage request parameters
|
|
140
|
+
* @returns Adjust leverage operation result
|
|
143
141
|
*/
|
|
144
|
-
async
|
|
142
|
+
async adjustLeverage(params: AdjustLeverageRequest): Promise<any> {
|
|
145
143
|
const body = await handleApiCall(() =>
|
|
146
|
-
this.http.post("leverage/
|
|
144
|
+
this.http.post("leverage/adjust", JSON.stringify(params)),
|
|
147
145
|
);
|
|
148
146
|
|
|
149
|
-
const
|
|
147
|
+
const adjustLeverageResponse: AdjustLeverageResponse = JSON.parse(body);
|
|
150
148
|
|
|
151
|
-
const txSig = await this.send(
|
|
149
|
+
const txSig = await this.send(adjustLeverageResponse.unsignedBase64Tx);
|
|
152
150
|
|
|
153
151
|
return txSig;
|
|
154
152
|
}
|
package/src/types.ts
CHANGED
|
@@ -20,9 +20,9 @@ export interface CreateObligationResponse {
|
|
|
20
20
|
export interface DepositLeverageRequest {
|
|
21
21
|
owner: web3.PublicKey;
|
|
22
22
|
selectedTokenMint: web3.PublicKey;
|
|
23
|
-
depositAmount:
|
|
23
|
+
depositAmount: BN;
|
|
24
24
|
leverage: number;
|
|
25
|
-
|
|
25
|
+
slippageBps: number;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
@@ -33,18 +33,18 @@ export interface DepositLeverageResponse {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Request to
|
|
36
|
+
* Request to adjust the leverage of an existing position
|
|
37
37
|
*/
|
|
38
|
-
export interface
|
|
38
|
+
export interface AdjustLeverageRequest {
|
|
39
39
|
owner: web3.PublicKey;
|
|
40
40
|
leverage: number;
|
|
41
|
-
|
|
41
|
+
slippageBps: number;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Response for
|
|
45
|
+
* Response for adjust leverage operation
|
|
46
46
|
*/
|
|
47
|
-
export interface
|
|
47
|
+
export interface AdjustLeverageResponse {
|
|
48
48
|
unsignedBase64Tx: string;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -54,9 +54,9 @@ export interface ModifyLeverageResponse {
|
|
|
54
54
|
export interface WithdrawLeverageRequest {
|
|
55
55
|
owner: web3.PublicKey;
|
|
56
56
|
selectedTokenMint: web3.PublicKey;
|
|
57
|
-
withdrawAmount:
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
withdrawAmount: BN;
|
|
58
|
+
slippageBps: number;
|
|
59
|
+
withdrawAll: boolean;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
@@ -67,20 +67,13 @@ export interface WithdrawLeverageResponse {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
export interface GetUserResponse {
|
|
70
|
-
netValue: number;
|
|
71
|
-
pnl: number;
|
|
72
|
-
netAPY: number;
|
|
73
|
-
leverage: number;
|
|
74
|
-
totalCollateral: number;
|
|
75
|
-
totalDebt: number;
|
|
76
|
-
ltv: number;
|
|
77
|
-
liquidationLtv: number;
|
|
78
70
|
usdcBalance: BN;
|
|
79
71
|
usdcBalanceUi: number;
|
|
80
72
|
jlpBalance: BN;
|
|
81
73
|
jlpBalanceUi: number;
|
|
82
74
|
solBalance: BN;
|
|
83
75
|
solBalanceUi: number;
|
|
76
|
+
clendAccount: any | undefined;
|
|
84
77
|
}
|
|
85
78
|
|
|
86
79
|
export interface GetBankResponse {
|