@carrot-protocol/boost-http-client 0.2.15 → 0.2.16-token22-dev-998073e

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
@@ -41,6 +41,8 @@ export declare class Client {
41
41
  * @returns Bank details
42
42
  */
43
43
  getBank(bankAddress: web3.PublicKey): Promise<GetBankResponse>;
44
+ deposit(clendGroup: web3.PublicKey, clendAccount: web3.PublicKey | null, inputTokenMint: web3.PublicKey, uiAmount: number): Promise<string>;
45
+ withdraw(clendAccount: web3.PublicKey, outputTokenMint: web3.PublicKey, uiAmount: number): Promise<string>;
44
46
  /**
45
47
  * Deposit collateral and create a leveraged position
46
48
  * @param request Deposit leverage request parameters
package/dist/index.js CHANGED
@@ -289,6 +289,30 @@ class Client {
289
289
  };
290
290
  return response;
291
291
  }
292
+ async deposit(clendGroup, clendAccount, inputTokenMint, uiAmount) {
293
+ const req = {
294
+ owner: this.address(),
295
+ clendGroup,
296
+ clendAccount,
297
+ inputTokenMint,
298
+ depositAmountUi: uiAmount,
299
+ };
300
+ const body = await handleApiCall(() => this.http.post("deposit", JSON.stringify(req)));
301
+ const depositResponse = JSON.parse(body);
302
+ const txSig = await this.send(depositResponse.unsignedBase64Tx, depositResponse.userRequestId);
303
+ return txSig;
304
+ }
305
+ async withdraw(clendAccount, outputTokenMint, uiAmount) {
306
+ const req = {
307
+ clendAccount,
308
+ outputTokenMint,
309
+ withdrawAmountUi: uiAmount,
310
+ };
311
+ const body = await handleApiCall(() => this.http.post("withdraw", JSON.stringify(req)));
312
+ const withdrawResponse = JSON.parse(body);
313
+ const txSig = await this.send(withdrawResponse.unsignedBase64Tx, withdrawResponse.userRequestId);
314
+ return txSig;
315
+ }
292
316
  /**
293
317
  * Deposit collateral and create a leveraged position
294
318
  * @param request Deposit leverage request parameters
package/dist/types.d.ts CHANGED
@@ -3,6 +3,32 @@ 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
+ }
28
+ export interface WithdrawResponse {
29
+ userRequestId: string;
30
+ unsignedBase64Tx: string;
31
+ }
6
32
  /**
7
33
  * Request to deposit collateral and create a leveraged position
8
34
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/boost-http-client",
3
- "version": "0.2.15",
3
+ "version": "0.2.16-token22-dev-998073e",
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,6 +27,10 @@ import {
27
27
  BankEmissionsMode,
28
28
  WithdrawEmissionsRequest,
29
29
  WithdrawEmissionsResponse,
30
+ DepositRequest,
31
+ DepositResponse,
32
+ WithdrawRequest,
33
+ WithdrawResponse,
30
34
  } from "./types";
31
35
  import encode from "bs58";
32
36
 
@@ -356,6 +360,59 @@ export class Client {
356
360
  return response;
357
361
  }
358
362
 
363
+ async deposit(
364
+ clendGroup: web3.PublicKey,
365
+ clendAccount: web3.PublicKey | null,
366
+ inputTokenMint: web3.PublicKey,
367
+ uiAmount: number,
368
+ ): Promise<string> {
369
+ const req: DepositRequest = {
370
+ owner: this.address(),
371
+ clendGroup,
372
+ clendAccount,
373
+ inputTokenMint,
374
+ depositAmountUi: uiAmount,
375
+ };
376
+
377
+ const body = await handleApiCall(() =>
378
+ this.http.post("deposit", JSON.stringify(req)),
379
+ );
380
+
381
+ const depositResponse: DepositResponse = JSON.parse(body);
382
+
383
+ const txSig = await this.send(
384
+ depositResponse.unsignedBase64Tx,
385
+ depositResponse.userRequestId,
386
+ );
387
+
388
+ return txSig;
389
+ }
390
+
391
+ async withdraw(
392
+ clendAccount: web3.PublicKey,
393
+ outputTokenMint: web3.PublicKey,
394
+ uiAmount: number,
395
+ ): Promise<string> {
396
+ const req: WithdrawRequest = {
397
+ clendAccount,
398
+ outputTokenMint,
399
+ withdrawAmountUi: uiAmount,
400
+ };
401
+
402
+ const body = await handleApiCall(() =>
403
+ this.http.post("withdraw", JSON.stringify(req)),
404
+ );
405
+
406
+ const withdrawResponse: WithdrawResponse = JSON.parse(body);
407
+
408
+ const txSig = await this.send(
409
+ withdrawResponse.unsignedBase64Tx,
410
+ withdrawResponse.userRequestId,
411
+ );
412
+
413
+ return txSig;
414
+ }
415
+
359
416
  /**
360
417
  * Deposit collateral and create a leveraged position
361
418
  * @param request Deposit leverage request parameters
package/src/types.ts CHANGED
@@ -6,6 +6,36 @@ 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
+ }
33
+
34
+ export interface WithdrawResponse {
35
+ userRequestId: string;
36
+ unsignedBase64Tx: string;
37
+ }
38
+
9
39
  /**
10
40
  * Request to deposit collateral and create a leveraged position
11
41
  */