@carrot-protocol/http-client 0.2.8 → 0.2.9-http-get-vault-dev-af83b64

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,32 +1,32 @@
1
- import { web3, BN, AnchorProvider } from "@coral-xyz/anchor";
1
+ import * as anchor from "@coral-xyz/anchor";
2
2
  import { Vault, VaultPerformance } from "@carrot-protocol/common";
3
3
  export declare class Client {
4
4
  readonly baseUrl: string;
5
- readonly provider: AnchorProvider;
5
+ readonly provider: anchor.AnchorProvider;
6
6
  private headers;
7
- constructor(baseUrl: string, provider: AnchorProvider);
7
+ constructor(baseUrl: string, provider: anchor.AnchorProvider);
8
8
  index(): Promise<void>;
9
- getVault(vault: web3.PublicKey): Promise<Vault>;
10
- getVaultPerformance(vault: web3.PublicKey): Promise<VaultPerformance>;
11
- getUser(vault: web3.PublicKey): Promise<UserResponse>;
12
- issue(vault: web3.PublicKey, assetMint: web3.PublicKey, amount: BN): Promise<string>;
13
- redeem(vault: web3.PublicKey, assetMint: web3.PublicKey, amount: BN): Promise<string>;
9
+ getVault(vault: anchor.web3.PublicKey): Promise<Vault>;
10
+ getVaultPerformance(vault: anchor.web3.PublicKey): Promise<VaultPerformance>;
11
+ getUser(vault: anchor.web3.PublicKey): Promise<UserResponse>;
12
+ issue(vault: anchor.web3.PublicKey, assetMint: anchor.web3.PublicKey, amount: anchor.BN): Promise<string>;
13
+ redeem(vault: anchor.web3.PublicKey, assetMint: anchor.web3.PublicKey, amount: anchor.BN): Promise<string>;
14
14
  private send;
15
15
  }
16
16
  export interface SendRequest {
17
17
  tx: string;
18
18
  }
19
19
  export interface RedeemRequest {
20
- vault: web3.PublicKey;
21
- assetMint: web3.PublicKey;
22
- amount: BN;
23
- user: web3.PublicKey;
20
+ vault: anchor.web3.PublicKey;
21
+ assetMint: anchor.web3.PublicKey;
22
+ amount: anchor.BN;
23
+ user: anchor.web3.PublicKey;
24
24
  }
25
25
  export interface IssueRequest {
26
- vault: web3.PublicKey;
27
- assetMint: web3.PublicKey;
28
- amount: BN;
29
- user: web3.PublicKey;
26
+ vault: anchor.web3.PublicKey;
27
+ assetMint: anchor.web3.PublicKey;
28
+ amount: anchor.BN;
29
+ user: anchor.web3.PublicKey;
30
30
  }
31
31
  export interface RedeemResponse {
32
32
  tx: string;
@@ -35,15 +35,15 @@ export interface IssueResponse {
35
35
  tx: string;
36
36
  }
37
37
  export interface UserResponse {
38
- solAmount: BN;
38
+ solAmount: anchor.BN;
39
39
  solAmountUi: number;
40
- sharesAmount: BN;
40
+ sharesAmount: anchor.BN;
41
41
  sharesAmountUi: number;
42
42
  assets: UserAssetBalance[];
43
43
  }
44
44
  export interface UserAssetBalance {
45
- mint: web3.PublicKey;
46
- amount: BN;
45
+ mint: anchor.web3.PublicKey;
46
+ amount: anchor.BN;
47
47
  amountUi: number;
48
48
  }
49
- export declare function prepareUnsignedTx(connection: web3.Connection, payer: web3.PublicKey, ixns: web3.TransactionInstruction[], lutAddr?: web3.PublicKey, additionalSigner?: AnchorProvider): Promise<string>;
49
+ export declare function prepareUnsignedTx(connection: anchor.web3.Connection, payer: anchor.web3.PublicKey, ixns: anchor.web3.TransactionInstruction[], lutAddr?: anchor.web3.PublicKey, additionalSigner?: anchor.AnchorProvider): Promise<string>;
package/dist/index.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -6,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
29
  exports.Client = void 0;
7
30
  exports.prepareUnsignedTx = prepareUnsignedTx;
8
31
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
9
- const anchor_1 = require("@coral-xyz/anchor");
32
+ const anchor = __importStar(require("@coral-xyz/anchor"));
10
33
  const bs58_1 = require("bs58");
11
34
  class Client {
12
35
  constructor(baseUrl, provider) {
@@ -28,34 +51,35 @@ class Client {
28
51
  });
29
52
  checkResponse(response);
30
53
  const rawBody = await response.json();
54
+ console.log("GET_VAULT_RAW:", rawBody);
31
55
  let body = JSON.parse(JSON.stringify(rawBody));
32
- body.address = new anchor_1.web3.PublicKey(body.address);
33
- body.authority = new anchor_1.web3.PublicKey(body.authority);
34
- body.shares = new anchor_1.web3.PublicKey(body.shares);
35
- body.sharesSupply = new anchor_1.BN(body.sharesSupply);
56
+ body.address = new anchor.web3.PublicKey(body.address);
57
+ body.authority = new anchor.web3.PublicKey(body.authority);
58
+ body.shares = new anchor.web3.PublicKey(body.shares);
59
+ body.sharesSupply = new anchor.BN(body.sharesSupply, "hex");
36
60
  body.assets = body.assets.map((asset) => ({
37
61
  ...asset,
38
62
  assetId: Number(asset.assetId),
39
63
  balanceUsd: Number(asset.balanceUsd),
40
- mint: new anchor_1.web3.PublicKey(asset.mint),
41
- ata: new anchor_1.web3.PublicKey(asset.ata),
42
- oracle: new anchor_1.web3.PublicKey(asset.oracle),
43
- ataAmount: new anchor_1.BN(asset.ataAmount, "hex"),
64
+ mint: new anchor.web3.PublicKey(asset.mint),
65
+ ata: new anchor.web3.PublicKey(asset.ata),
66
+ oracle: new anchor.web3.PublicKey(asset.oracle),
67
+ ataAmount: new anchor.BN(asset.ataAmount, "hex"),
44
68
  }));
45
69
  body.strategies = body.strategies.map((strategy) => ({
46
- address: new anchor_1.web3.PublicKey(strategy.address),
70
+ address: new anchor.web3.PublicKey(strategy.address),
47
71
  record: {
48
72
  strategyId: Number(strategy.record.strategyId),
49
73
  assetId: Number(strategy.record.assetId),
50
- balance: new anchor_1.BN(strategy.record.balance, "hex"),
74
+ balance: new anchor.BN(strategy.record.balance, "hex"),
51
75
  balanceUsd: Number(strategy.record.balanceUsd),
52
- netEarnings: new anchor_1.BN(strategy.record.netEarnings, "hex"),
76
+ netEarnings: new anchor.BN(strategy.record.netEarnings, "hex"),
53
77
  },
54
78
  metadata: {
55
79
  ...strategy.metadata,
56
80
  strategyId: Number(strategy.metadata.strategyId),
57
- assetMint: new anchor_1.web3.PublicKey(strategy.metadata.assetMint),
58
- vault: new anchor_1.web3.PublicKey(strategy.metadata.vault),
81
+ assetMint: new anchor.web3.PublicKey(strategy.metadata.assetMint),
82
+ vault: new anchor.web3.PublicKey(strategy.metadata.vault),
59
83
  },
60
84
  strategyType: strategy.strategyType,
61
85
  }));
@@ -74,9 +98,9 @@ class Client {
74
98
  for (let strats of body.strategyAPY) {
75
99
  strats.apy = Number(strats.apy);
76
100
  strats.balanceUsd = Number(strats.balanceUsd);
77
- strats.strategy = new anchor_1.web3.PublicKey(strats.strategy);
101
+ strats.strategy = new anchor.web3.PublicKey(strats.strategy);
78
102
  strats.vaultWeight = Number(strats.vaultWeight);
79
- strats.assetMint = new anchor_1.web3.PublicKey(strats.assetMint);
103
+ strats.assetMint = new anchor.web3.PublicKey(strats.assetMint);
80
104
  }
81
105
  return body;
82
106
  }
@@ -88,12 +112,12 @@ class Client {
88
112
  });
89
113
  checkResponse(response);
90
114
  const body = JSON.parse(JSON.stringify(await response.json()));
91
- body.solAmount = new anchor_1.BN(body.solAmount, "hex");
92
- body.sharesAmount = new anchor_1.BN(body.sharesAmount, "hex");
115
+ body.solAmount = new anchor.BN(body.solAmount, "hex");
116
+ body.sharesAmount = new anchor.BN(body.sharesAmount, "hex");
93
117
  body.assets = body.assets.map((asset) => ({
94
118
  ...asset,
95
- mint: new anchor_1.web3.PublicKey(asset.mint),
96
- amount: new anchor_1.BN(asset.amount, "hex"),
119
+ mint: new anchor.web3.PublicKey(asset.mint),
120
+ amount: new anchor.BN(asset.amount, "hex"),
97
121
  }));
98
122
  return body;
99
123
  }
@@ -137,7 +161,7 @@ class Client {
137
161
  }
138
162
  async send(base64Tx) {
139
163
  const txBytes = Buffer.from(base64Tx, "base64");
140
- const tx = anchor_1.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
164
+ const tx = anchor.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
141
165
  const signedTx = await this.provider.wallet.signTransaction(tx);
142
166
  const txSig = signedTx.signatures[0];
143
167
  const encodedAndSignedTx = Buffer.from(signedTx.serialize()).toString("base64");
@@ -167,12 +191,12 @@ async function prepareUnsignedTx(connection, payer, ixns, lutAddr, additionalSig
167
191
  const recentBh = await connection.getLatestBlockhash({
168
192
  commitment: "confirmed",
169
193
  });
170
- const msg = new anchor_1.web3.TransactionMessage({
194
+ const msg = new anchor.web3.TransactionMessage({
171
195
  payerKey: payer,
172
196
  recentBlockhash: recentBh.blockhash,
173
197
  instructions: ixns,
174
198
  }).compileToV0Message(lutAccounts);
175
- const tx = new anchor_1.web3.VersionedTransaction(msg);
199
+ const tx = new anchor.web3.VersionedTransaction(msg);
176
200
  let base64Tx = Buffer.from(tx.serialize()).toString("base64");
177
201
  if (additionalSigner) {
178
202
  const signedTx = await additionalSigner.wallet.signTransaction(tx);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/http-client",
3
- "version": "0.2.8",
3
+ "version": "0.2.9-http-get-vault-dev-af83b64",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",