@carrot-protocol/http-client 0.2.9-http-get-vault-dev-551e417 → 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) {
@@ -30,33 +53,33 @@ class Client {
30
53
  const rawBody = await response.json();
31
54
  console.log("GET_VAULT_RAW:", rawBody);
32
55
  let body = JSON.parse(JSON.stringify(rawBody));
33
- body.address = new anchor_1.web3.PublicKey(body.address);
34
- body.authority = new anchor_1.web3.PublicKey(body.authority);
35
- body.shares = new anchor_1.web3.PublicKey(body.shares);
36
- body.sharesSupply = new anchor_1.BN(body.sharesSupply, "hex");
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");
37
60
  body.assets = body.assets.map((asset) => ({
38
61
  ...asset,
39
62
  assetId: Number(asset.assetId),
40
63
  balanceUsd: Number(asset.balanceUsd),
41
- mint: new anchor_1.web3.PublicKey(asset.mint),
42
- ata: new anchor_1.web3.PublicKey(asset.ata),
43
- oracle: new anchor_1.web3.PublicKey(asset.oracle),
44
- 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"),
45
68
  }));
46
69
  body.strategies = body.strategies.map((strategy) => ({
47
- address: new anchor_1.web3.PublicKey(strategy.address),
70
+ address: new anchor.web3.PublicKey(strategy.address),
48
71
  record: {
49
72
  strategyId: Number(strategy.record.strategyId),
50
73
  assetId: Number(strategy.record.assetId),
51
- balance: new anchor_1.BN(strategy.record.balance, "hex"),
74
+ balance: new anchor.BN(strategy.record.balance, "hex"),
52
75
  balanceUsd: Number(strategy.record.balanceUsd),
53
- netEarnings: new anchor_1.BN(strategy.record.netEarnings, "hex"),
76
+ netEarnings: new anchor.BN(strategy.record.netEarnings, "hex"),
54
77
  },
55
78
  metadata: {
56
79
  ...strategy.metadata,
57
80
  strategyId: Number(strategy.metadata.strategyId),
58
- assetMint: new anchor_1.web3.PublicKey(strategy.metadata.assetMint),
59
- 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),
60
83
  },
61
84
  strategyType: strategy.strategyType,
62
85
  }));
@@ -75,9 +98,9 @@ class Client {
75
98
  for (let strats of body.strategyAPY) {
76
99
  strats.apy = Number(strats.apy);
77
100
  strats.balanceUsd = Number(strats.balanceUsd);
78
- strats.strategy = new anchor_1.web3.PublicKey(strats.strategy);
101
+ strats.strategy = new anchor.web3.PublicKey(strats.strategy);
79
102
  strats.vaultWeight = Number(strats.vaultWeight);
80
- strats.assetMint = new anchor_1.web3.PublicKey(strats.assetMint);
103
+ strats.assetMint = new anchor.web3.PublicKey(strats.assetMint);
81
104
  }
82
105
  return body;
83
106
  }
@@ -89,12 +112,12 @@ class Client {
89
112
  });
90
113
  checkResponse(response);
91
114
  const body = JSON.parse(JSON.stringify(await response.json()));
92
- body.solAmount = new anchor_1.BN(body.solAmount, "hex");
93
- 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");
94
117
  body.assets = body.assets.map((asset) => ({
95
118
  ...asset,
96
- mint: new anchor_1.web3.PublicKey(asset.mint),
97
- amount: new anchor_1.BN(asset.amount, "hex"),
119
+ mint: new anchor.web3.PublicKey(asset.mint),
120
+ amount: new anchor.BN(asset.amount, "hex"),
98
121
  }));
99
122
  return body;
100
123
  }
@@ -138,7 +161,7 @@ class Client {
138
161
  }
139
162
  async send(base64Tx) {
140
163
  const txBytes = Buffer.from(base64Tx, "base64");
141
- const tx = anchor_1.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
164
+ const tx = anchor.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
142
165
  const signedTx = await this.provider.wallet.signTransaction(tx);
143
166
  const txSig = signedTx.signatures[0];
144
167
  const encodedAndSignedTx = Buffer.from(signedTx.serialize()).toString("base64");
@@ -168,12 +191,12 @@ async function prepareUnsignedTx(connection, payer, ixns, lutAddr, additionalSig
168
191
  const recentBh = await connection.getLatestBlockhash({
169
192
  commitment: "confirmed",
170
193
  });
171
- const msg = new anchor_1.web3.TransactionMessage({
194
+ const msg = new anchor.web3.TransactionMessage({
172
195
  payerKey: payer,
173
196
  recentBlockhash: recentBh.blockhash,
174
197
  instructions: ixns,
175
198
  }).compileToV0Message(lutAccounts);
176
- const tx = new anchor_1.web3.VersionedTransaction(msg);
199
+ const tx = new anchor.web3.VersionedTransaction(msg);
177
200
  let base64Tx = Buffer.from(tx.serialize()).toString("base64");
178
201
  if (additionalSigner) {
179
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.9-http-get-vault-dev-551e417",
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",