@carrot-protocol/boost-http-client 0.3.0-feat-get-account-endpoint-dev-6a0523c → 0.3.0-feat-get-account-endpoint-dev-1ff332b

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 { GetBankResponse, GetUserResponse, GetGroupResponse, GetGroupsResponse, GetAccountResponse } from "./types";
2
+ import { GetBankResponse, GetUserResponse, GetGroupResponse, GetGroupsResponse, GetAccountResponse, GetAccountRequest } from "./types";
3
3
  export * from "./types";
4
4
  export * from "./utils";
5
5
  export * as Common from "@carrot-protocol/clend-common";
@@ -25,7 +25,7 @@ export declare class Client {
25
25
  /**
26
26
  * Fetch and parse a single clend account by pubkey
27
27
  */
28
- getAccount(account: web3.PublicKey, getClendAccountSummary: boolean): Promise<GetAccountResponse>;
28
+ getAccount(account: GetAccountRequest["account"], getClendAccountSummary: GetAccountRequest["getClendAccountSummary"]): Promise<GetAccountResponse>;
29
29
  /**
30
30
  * Helper to parse a clend account summary array from API response
31
31
  */
@@ -50,6 +50,8 @@ export declare class Client {
50
50
  * @returns Bank details
51
51
  */
52
52
  getBank(bankAddress: web3.PublicKey): Promise<GetBankResponse>;
53
+ deposit(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, uiAmount: number): Promise<string>;
54
+ withdraw(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, uiAmount: number, withdrawAll: boolean): Promise<string>;
53
55
  /**
54
56
  * Deposit collateral and create a leveraged position
55
57
  * @param request Deposit leverage request parameters
package/dist/index.js CHANGED
@@ -298,6 +298,31 @@ class Client {
298
298
  };
299
299
  return response;
300
300
  }
301
+ async deposit(clendGroup, clendAccount, inputTokenMint, uiAmount) {
302
+ const req = {
303
+ owner: this.address(),
304
+ clendGroup,
305
+ clendAccount,
306
+ inputTokenMint,
307
+ depositAmountUi: uiAmount,
308
+ };
309
+ const body = await handleApiCall(() => this.http.post("deposit", JSON.stringify(req)));
310
+ const depositResponse = JSON.parse(body);
311
+ const txSig = await this.send(depositResponse.unsignedBase64Tx, depositResponse.userRequestId);
312
+ return txSig;
313
+ }
314
+ async withdraw(clendAccount, outputTokenMint, uiAmount, withdrawAll) {
315
+ const req = {
316
+ clendAccount,
317
+ outputTokenMint,
318
+ withdrawAmountUi: uiAmount,
319
+ withdrawAll,
320
+ };
321
+ const body = await handleApiCall(() => this.http.post("withdraw", JSON.stringify(req)));
322
+ const withdrawResponse = JSON.parse(body);
323
+ const txSig = await this.send(withdrawResponse.unsignedBase64Tx, withdrawResponse.userRequestId);
324
+ return txSig;
325
+ }
301
326
  /**
302
327
  * Deposit collateral and create a leveraged position
303
328
  * @param request Deposit leverage request parameters
package/dist/types.d.ts CHANGED
@@ -3,6 +3,33 @@ export interface SendRequest {
3
3
  userRequestId: string;
4
4
  txns: string[];
5
5
  }
6
+ /**
7
+ * Request to deposit collateral
8
+ */
9
+ export interface DepositRequest {
10
+ owner: web3.PublicKey;
11
+ clendGroup: web3.PublicKey;
12
+ clendAccount: web3.PublicKey | null;
13
+ inputTokenMint: web3.PublicKey;
14
+ depositAmountUi: number;
15
+ }
16
+ export interface DepositResponse {
17
+ userRequestId: string;
18
+ unsignedBase64Tx: string;
19
+ }
20
+ /**
21
+ * Request to withdraw collateral
22
+ */
23
+ export interface WithdrawRequest {
24
+ clendAccount: web3.PublicKey;
25
+ outputTokenMint: web3.PublicKey;
26
+ withdrawAmountUi: number;
27
+ withdrawAll: boolean;
28
+ }
29
+ export interface WithdrawResponse {
30
+ userRequestId: string;
31
+ unsignedBase64Tx: string;
32
+ }
6
33
  /**
7
34
  * Request to deposit collateral and create a leveraged position
8
35
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/boost-http-client",
3
- "version": "0.3.0-feat-get-account-endpoint-dev-6a0523c",
3
+ "version": "0.3.0-feat-get-account-endpoint-dev-1ff332b",
4
4
  "description": "HTTP client for Carrot Boost",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -27,7 +27,12 @@ import {
27
27
  BankEmissionsMode,
28
28
  WithdrawEmissionsRequest,
29
29
  WithdrawEmissionsResponse,
30
+ DepositRequest,
31
+ DepositResponse,
32
+ WithdrawRequest,
33
+ WithdrawResponse,
30
34
  GetAccountResponse,
35
+ GetAccountRequest,
31
36
  } from "./types";
32
37
  import encode from "bs58";
33
38
 
@@ -111,8 +116,8 @@ export class Client {
111
116
  * Fetch and parse a single clend account by pubkey
112
117
  */
113
118
  async getAccount(
114
- account: web3.PublicKey,
115
- getClendAccountSummary: boolean,
119
+ account: GetAccountRequest["account"],
120
+ getClendAccountSummary: GetAccountRequest["getClendAccountSummary"],
116
121
  ): Promise<GetAccountResponse> {
117
122
  const body = await handleApiCall(() =>
118
123
  this.http.get(
@@ -377,6 +382,61 @@ export class Client {
377
382
  return response;
378
383
  }
379
384
 
385
+ async deposit(
386
+ clendGroup: web3.PublicKey,
387
+ clendAccount: web3.PublicKey | null,
388
+ inputTokenMint: web3.PublicKey,
389
+ uiAmount: number,
390
+ ): Promise<string> {
391
+ const req: DepositRequest = {
392
+ owner: this.address(),
393
+ clendGroup,
394
+ clendAccount,
395
+ inputTokenMint,
396
+ depositAmountUi: uiAmount,
397
+ };
398
+
399
+ const body = await handleApiCall(() =>
400
+ this.http.post("deposit", JSON.stringify(req)),
401
+ );
402
+
403
+ const depositResponse: DepositResponse = JSON.parse(body);
404
+
405
+ const txSig = await this.send(
406
+ depositResponse.unsignedBase64Tx,
407
+ depositResponse.userRequestId,
408
+ );
409
+
410
+ return txSig;
411
+ }
412
+
413
+ async withdraw(
414
+ clendAccount: web3.PublicKey,
415
+ outputTokenMint: web3.PublicKey,
416
+ uiAmount: number,
417
+ withdrawAll: boolean,
418
+ ): Promise<string> {
419
+ const req: WithdrawRequest = {
420
+ clendAccount,
421
+ outputTokenMint,
422
+ withdrawAmountUi: uiAmount,
423
+ withdrawAll,
424
+ };
425
+
426
+ const body = await handleApiCall(() =>
427
+ this.http.post("withdraw", JSON.stringify(req)),
428
+ );
429
+
430
+ const withdrawResponse: WithdrawResponse = JSON.parse(body);
431
+
432
+ const txSig = await this.send(
433
+ withdrawResponse.unsignedBase64Tx,
434
+ withdrawResponse.userRequestId,
435
+ );
436
+
437
+ return txSig;
438
+ }
439
+
380
440
  /**
381
441
  * Deposit collateral and create a leveraged position
382
442
  * @param request Deposit leverage request parameters
package/src/types.ts CHANGED
@@ -6,6 +6,37 @@ export interface SendRequest {
6
6
  txns: string[];
7
7
  }
8
8
 
9
+ /**
10
+ * Request to deposit collateral
11
+ */
12
+ export interface DepositRequest {
13
+ owner: web3.PublicKey;
14
+ clendGroup: web3.PublicKey;
15
+ clendAccount: web3.PublicKey | null;
16
+ inputTokenMint: web3.PublicKey;
17
+ depositAmountUi: number;
18
+ }
19
+
20
+ export interface DepositResponse {
21
+ userRequestId: string;
22
+ unsignedBase64Tx: string;
23
+ }
24
+
25
+ /**
26
+ * Request to withdraw collateral
27
+ */
28
+ export interface WithdrawRequest {
29
+ clendAccount: web3.PublicKey;
30
+ outputTokenMint: web3.PublicKey;
31
+ withdrawAmountUi: number;
32
+ withdrawAll: boolean;
33
+ }
34
+
35
+ export interface WithdrawResponse {
36
+ userRequestId: string;
37
+ unsignedBase64Tx: string;
38
+ }
39
+
9
40
  /**
10
41
  * Request to deposit collateral and create a leveraged position
11
42
  */