@carrot-protocol/boost-http-client 0.1.7 → 0.2.0-mrgn-fork1-dev-e3a1df6

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AnchorProvider, web3 } from "@coral-xyz/anchor";
2
- import { DepositLeverageRequest, GetMarketResponse, GetUserResponse, ModifyLeverageRequest, WithdrawLeverageRequest } from "./types";
2
+ import { DepositLeverageRequest, GetBankResponse, GetUserResponse, ModifyLeverageRequest, WithdrawLeverageRequest } from "./types";
3
3
  export * from "./types";
4
4
  /**
5
5
  * HTTP Client for Carrot Boost API
@@ -27,15 +27,11 @@ export declare class Client {
27
27
  */
28
28
  getUser(user?: web3.PublicKey): Promise<GetUserResponse>;
29
29
  /**
30
- * Get market details for the carrot boost market
31
- * @returns Market details
30
+ * Get bank details
31
+ * @param mint token mint of the bank public key
32
+ * @returns Bank details
32
33
  */
33
- getMarket(): Promise<GetMarketResponse>;
34
- /**
35
- * Create an obligation for the client
36
- * @returns Transaction signature
37
- */
38
- createObligation(): Promise<string>;
34
+ getBank(mint: web3.PublicKey): Promise<GetBankResponse>;
39
35
  /**
40
36
  * Deposit collateral and create a leveraged position
41
37
  * @param request Deposit 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, ...signedBase64Txns) {
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, ...signedBase64Txns],
84
+ txns: [encodedAndSignedTx],
85
85
  };
86
86
  // send to api
87
87
  await handleApiCall(() => this.http.post(`send`, sendRequest));
@@ -106,28 +106,20 @@ 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
  }
112
113
  /**
113
- * Get market details for the carrot boost market
114
- * @returns Market details
114
+ * Get bank details
115
+ * @param mint token mint of the bank public key
116
+ * @returns Bank details
115
117
  */
116
- async getMarket() {
117
- const body = await handleApiCall(() => this.http.get(`market`));
118
+ async getBank(mint) {
119
+ const body = await handleApiCall(() => this.http.get(`/bank?mint=${mint.toString()}`));
118
120
  const response = JSON.parse(body);
119
121
  return response;
120
122
  }
121
- /**
122
- * Create an obligation for the client
123
- * @returns Transaction signature
124
- */
125
- async createObligation() {
126
- const body = await handleApiCall(() => this.http.post("createObligation", JSON.stringify({ owner: this.address() })));
127
- const createObligationResponse = JSON.parse(body);
128
- const txSig = await this.send(createObligationResponse.unsignedBase64Tx);
129
- return txSig;
130
- }
131
123
  /**
132
124
  * Deposit collateral and create a leveraged position
133
125
  * @param request Deposit leverage request parameters
@@ -136,7 +128,7 @@ class Client {
136
128
  async depositLeverage(params) {
137
129
  const body = await handleApiCall(() => this.http.post("leverage/deposit", JSON.stringify(params)));
138
130
  const depositLeverageResponse = JSON.parse(body);
139
- const txSig = await this.send(depositLeverageResponse.unsignedBase64Tx, depositLeverageResponse.signedSetBorrowRateBase64Tx);
131
+ const txSig = await this.send(depositLeverageResponse.unsignedBase64Tx);
140
132
  return txSig;
141
133
  }
142
134
  /**
@@ -147,7 +139,7 @@ class Client {
147
139
  async modifyLeverage(params) {
148
140
  const body = await handleApiCall(() => this.http.post("leverage/modify", JSON.stringify(params)));
149
141
  const modifyLeverageResponse = JSON.parse(body);
150
- const txSig = await this.send(modifyLeverageResponse.unsignedBase64Tx, modifyLeverageResponse.signedSetBorrowRateBase64Tx);
142
+ const txSig = await this.send(modifyLeverageResponse.unsignedBase64Tx);
151
143
  return txSig;
152
144
  }
153
145
  /**
@@ -158,7 +150,7 @@ class Client {
158
150
  async withdrawLeverage(params) {
159
151
  const body = await handleApiCall(() => this.http.post("leverage/withdraw", JSON.stringify(params)));
160
152
  const withdrawLeverageResponse = JSON.parse(body);
161
- const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx, withdrawLeverageResponse.signedSetBorrowRateBase64Tx);
153
+ const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx);
162
154
  return txSig;
163
155
  }
164
156
  }
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,16 +14,15 @@ export interface CreateObligationResponse {
15
14
  export interface DepositLeverageRequest {
16
15
  owner: web3.PublicKey;
17
16
  selectedTokenMint: web3.PublicKey;
18
- depositAmount: Decimal;
17
+ depositAmount: BN;
19
18
  leverage: number;
20
- slippagePct: number;
19
+ slippageBps: number;
21
20
  }
22
21
  /**
23
22
  * Response for deposit leverage operation
24
23
  */
25
24
  export interface DepositLeverageResponse {
26
25
  unsignedBase64Tx: string;
27
- signedSetBorrowRateBase64Tx: string;
28
26
  }
29
27
  /**
30
28
  * Request to modify the leverage of an existing position
@@ -39,7 +37,6 @@ export interface ModifyLeverageRequest {
39
37
  */
40
38
  export interface ModifyLeverageResponse {
41
39
  unsignedBase64Tx: string;
42
- signedSetBorrowRateBase64Tx: string;
43
40
  }
44
41
  /**
45
42
  * Request to withdraw from a leveraged position
@@ -47,41 +44,31 @@ export interface ModifyLeverageResponse {
47
44
  export interface WithdrawLeverageRequest {
48
45
  owner: web3.PublicKey;
49
46
  selectedTokenMint: web3.PublicKey;
50
- withdrawAmount: Decimal;
51
- slippagePct: number;
52
- closePosition: boolean;
47
+ withdrawAmount: BN;
48
+ slippageBps: number;
49
+ withdrawAll: boolean;
53
50
  }
54
51
  /**
55
52
  * Response for withdraw leverage operation
56
53
  */
57
54
  export interface WithdrawLeverageResponse {
58
55
  unsignedBase64Tx: string;
59
- signedSetBorrowRateBase64Tx: string;
60
56
  }
61
57
  export interface GetUserResponse {
62
- netValue: number;
63
- pnl: number;
64
- netAPY: number;
65
- leverage: number;
66
- totalCollateral: number;
67
- totalDebt: number;
68
- ltv: number;
69
- liquidationLtv: number;
70
58
  usdcBalance: BN;
71
59
  usdcBalanceUi: number;
72
60
  jlpBalance: BN;
73
61
  jlpBalanceUi: number;
74
62
  solBalance: BN;
75
63
  solBalanceUi: number;
76
- obligationCreated: boolean;
64
+ clendAccount: any | undefined;
77
65
  }
78
- export interface GetMarketResponse {
66
+ export interface GetBankResponse {
79
67
  totalBorrowTVL: number;
80
68
  totalSupplyTVL: number;
81
- usdcSupplyApy: number;
82
- usdcBorrowApy: number;
83
- usdcSupplyAmount: number;
84
- usdcBorrowAmount: number;
85
- usdcPrice: number;
86
- jlpPrice: number;
69
+ supplyApy: number;
70
+ borrowApy: number;
71
+ supplyAmount: number;
72
+ borrowAmount: number;
73
+ price: number;
87
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/boost-http-client",
3
- "version": "0.1.7",
3
+ "version": "0.2.0-mrgn-fork1-dev-e3a1df6",
4
4
  "description": "HTTP client for Carrot Boost API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import axios, { AxiosInstance, AxiosError, AxiosResponse } from "axios";
2
2
  import { AnchorProvider, Wallet, web3 } from "@coral-xyz/anchor";
3
3
  import {
4
- CreateObligationResponse,
5
4
  DepositLeverageRequest,
6
5
  DepositLeverageResponse,
7
- GetMarketResponse,
6
+ GetBankResponse,
8
7
  GetUserResponse,
9
8
  ModifyLeverageRequest,
10
9
  ModifyLeverageResponse,
@@ -48,10 +47,7 @@ export class Client {
48
47
  }
49
48
 
50
49
  // sign and send tx to api for sending to network
51
- private async send(
52
- unsignedBase64Tx: string,
53
- ...signedBase64Txns: string[]
54
- ): Promise<string> {
50
+ private async send(unsignedBase64Tx: string): Promise<string> {
55
51
  // deserialize into tx obj
56
52
  const txBytes = Buffer.from(unsignedBase64Tx, "base64");
57
53
  const tx = web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
@@ -67,7 +63,7 @@ export class Client {
67
63
 
68
64
  // create request obj
69
65
  const sendRequest: SendRequest = {
70
- txns: [encodedAndSignedTx, ...signedBase64Txns],
66
+ txns: [encodedAndSignedTx],
71
67
  };
72
68
 
73
69
  // send to api
@@ -99,6 +95,7 @@ export class Client {
99
95
  const body = await handleApiCall(() =>
100
96
  this.http.get(`/user?user=${user.toString()}`),
101
97
  );
98
+ console.log(JSON.stringify(body));
102
99
 
103
100
  const response: GetUserResponse = JSON.parse(body);
104
101
 
@@ -106,34 +103,18 @@ export class Client {
106
103
  }
107
104
 
108
105
  /**
109
- * Get market details for the carrot boost market
110
- * @returns Market details
106
+ * Get bank details
107
+ * @param mint token mint of the bank public key
108
+ * @returns Bank details
111
109
  */
112
- async getMarket(): Promise<GetMarketResponse> {
113
- const body = await handleApiCall(() => this.http.get(`market`));
114
-
115
- const response: GetMarketResponse = JSON.parse(body);
116
-
117
- return response;
118
- }
119
-
120
- /**
121
- * Create an obligation for the client
122
- * @returns Transaction signature
123
- */
124
- async createObligation(): Promise<string> {
110
+ async getBank(mint: web3.PublicKey): Promise<GetBankResponse> {
125
111
  const body = await handleApiCall(() =>
126
- this.http.post(
127
- "createObligation",
128
- JSON.stringify({ owner: this.address() }),
129
- ),
112
+ this.http.get(`/bank?mint=${mint.toString()}`),
130
113
  );
131
114
 
132
- const createObligationResponse: CreateObligationResponse = JSON.parse(body);
115
+ const response: GetBankResponse = JSON.parse(body);
133
116
 
134
- const txSig = await this.send(createObligationResponse.unsignedBase64Tx);
135
-
136
- return txSig;
117
+ return response;
137
118
  }
138
119
 
139
120
  /**
@@ -148,10 +129,7 @@ export class Client {
148
129
 
149
130
  const depositLeverageResponse: DepositLeverageResponse = JSON.parse(body);
150
131
 
151
- const txSig = await this.send(
152
- depositLeverageResponse.unsignedBase64Tx,
153
- depositLeverageResponse.signedSetBorrowRateBase64Tx,
154
- );
132
+ const txSig = await this.send(depositLeverageResponse.unsignedBase64Tx);
155
133
 
156
134
  return txSig;
157
135
  }
@@ -168,10 +146,7 @@ export class Client {
168
146
 
169
147
  const modifyLeverageResponse: ModifyLeverageResponse = JSON.parse(body);
170
148
 
171
- const txSig = await this.send(
172
- modifyLeverageResponse.unsignedBase64Tx,
173
- modifyLeverageResponse.signedSetBorrowRateBase64Tx,
174
- );
149
+ const txSig = await this.send(modifyLeverageResponse.unsignedBase64Tx);
175
150
 
176
151
  return txSig;
177
152
  }
@@ -188,10 +163,7 @@ export class Client {
188
163
 
189
164
  const withdrawLeverageResponse: WithdrawLeverageResponse = JSON.parse(body);
190
165
 
191
- const txSig = await this.send(
192
- withdrawLeverageResponse.unsignedBase64Tx,
193
- withdrawLeverageResponse.signedSetBorrowRateBase64Tx,
194
- );
166
+ const txSig = await this.send(withdrawLeverageResponse.unsignedBase64Tx);
195
167
 
196
168
  return txSig;
197
169
  }
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: Decimal;
23
+ depositAmount: BN;
24
24
  leverage: number;
25
- slippagePct: number;
25
+ slippageBps: number;
26
26
  }
27
27
 
28
28
  /**
@@ -30,7 +30,6 @@ export interface DepositLeverageRequest {
30
30
  */
31
31
  export interface DepositLeverageResponse {
32
32
  unsignedBase64Tx: string;
33
- signedSetBorrowRateBase64Tx: string;
34
33
  }
35
34
 
36
35
  /**
@@ -47,7 +46,6 @@ export interface ModifyLeverageRequest {
47
46
  */
48
47
  export interface ModifyLeverageResponse {
49
48
  unsignedBase64Tx: string;
50
- signedSetBorrowRateBase64Tx: string;
51
49
  }
52
50
 
53
51
  /**
@@ -56,9 +54,9 @@ export interface ModifyLeverageResponse {
56
54
  export interface WithdrawLeverageRequest {
57
55
  owner: web3.PublicKey;
58
56
  selectedTokenMint: web3.PublicKey;
59
- withdrawAmount: Decimal;
60
- slippagePct: number;
61
- closePosition: boolean;
57
+ withdrawAmount: BN;
58
+ slippageBps: number;
59
+ withdrawAll: boolean;
62
60
  }
63
61
 
64
62
  /**
@@ -66,34 +64,24 @@ export interface WithdrawLeverageRequest {
66
64
  */
67
65
  export interface WithdrawLeverageResponse {
68
66
  unsignedBase64Tx: string;
69
- signedSetBorrowRateBase64Tx: string;
70
67
  }
71
68
 
72
69
  export interface GetUserResponse {
73
- netValue: number;
74
- pnl: number;
75
- netAPY: number;
76
- leverage: number;
77
- totalCollateral: number;
78
- totalDebt: number;
79
- ltv: number;
80
- liquidationLtv: number;
81
70
  usdcBalance: BN;
82
71
  usdcBalanceUi: number;
83
72
  jlpBalance: BN;
84
73
  jlpBalanceUi: number;
85
74
  solBalance: BN;
86
75
  solBalanceUi: number;
87
- obligationCreated: boolean;
76
+ clendAccount: any | undefined;
88
77
  }
89
78
 
90
- export interface GetMarketResponse {
79
+ export interface GetBankResponse {
91
80
  totalBorrowTVL: number;
92
81
  totalSupplyTVL: number;
93
- usdcSupplyApy: number;
94
- usdcBorrowApy: number;
95
- usdcSupplyAmount: number;
96
- usdcBorrowAmount: number;
97
- usdcPrice: number;
98
- jlpPrice: number;
82
+ supplyApy: number;
83
+ borrowApy: number;
84
+ supplyAmount: number;
85
+ borrowAmount: number;
86
+ price: number;
99
87
  }