@carrot-protocol/http-client 0.2.8-export-rpc-dev-f1388a1 → 0.2.8-export-rpc-dev-e0deb73

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -35
  2. package/package.json +3 -2
package/dist/index.js CHANGED
@@ -1,54 +1,61 @@
1
- import fetch from "cross-fetch";
2
- import { web3, BN } from "@coral-xyz/anchor";
3
- import { encode } from "bs58";
4
- export class Client {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Client = void 0;
7
+ exports.prepareUnsignedTx = prepareUnsignedTx;
8
+ const cross_fetch_1 = __importDefault(require("cross-fetch"));
9
+ const anchor_1 = require("@coral-xyz/anchor");
10
+ const bs58_1 = require("bs58");
11
+ class Client {
5
12
  constructor(baseUrl, provider) {
6
13
  this.headers = { "Content-Type": "application/json" };
7
14
  this.baseUrl = baseUrl;
8
15
  this.provider = provider;
9
16
  }
10
17
  async index() {
11
- const response = await fetch(this.baseUrl);
18
+ const response = await (0, cross_fetch_1.default)(this.baseUrl);
12
19
  checkResponse(response);
13
20
  const body = await response.json();
14
21
  console.log(JSON.stringify(body, undefined, 2));
15
22
  }
16
23
  async getVault(vault) {
17
24
  const url = new URL(`${this.baseUrl}/vault?vault=${vault.toString()}`);
18
- const response = await fetch(url, {
25
+ const response = await (0, cross_fetch_1.default)(url, {
19
26
  method: "GET",
20
27
  headers: this.headers,
21
28
  });
22
29
  checkResponse(response);
23
30
  const rawBody = await response.json();
24
31
  let body = JSON.parse(JSON.stringify(rawBody));
25
- body.address = new web3.PublicKey(body.address);
26
- body.authority = new web3.PublicKey(body.authority);
27
- body.shares = new web3.PublicKey(body.shares);
28
- body.sharesSupply = new BN(body.sharesSupply);
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);
29
36
  body.assets = body.assets.map((asset) => ({
30
37
  ...asset,
31
38
  assetId: Number(asset.assetId),
32
39
  balanceUsd: Number(asset.balanceUsd),
33
- mint: new web3.PublicKey(asset.mint),
34
- ata: new web3.PublicKey(asset.ata),
35
- oracle: new web3.PublicKey(asset.oracle),
36
- ataAmount: new BN(asset.ataAmount, "hex"),
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"),
37
44
  }));
38
45
  body.strategies = body.strategies.map((strategy) => ({
39
- address: new web3.PublicKey(strategy.address),
46
+ address: new anchor_1.web3.PublicKey(strategy.address),
40
47
  record: {
41
48
  strategyId: Number(strategy.record.strategyId),
42
49
  assetId: Number(strategy.record.assetId),
43
- balance: new BN(strategy.record.balance, "hex"),
50
+ balance: new anchor_1.BN(strategy.record.balance, "hex"),
44
51
  balanceUsd: Number(strategy.record.balanceUsd),
45
- netEarnings: new BN(strategy.record.netEarnings, "hex"),
52
+ netEarnings: new anchor_1.BN(strategy.record.netEarnings, "hex"),
46
53
  },
47
54
  metadata: {
48
55
  ...strategy.metadata,
49
56
  strategyId: Number(strategy.metadata.strategyId),
50
- assetMint: new web3.PublicKey(strategy.metadata.assetMint),
51
- vault: new web3.PublicKey(strategy.metadata.vault),
57
+ assetMint: new anchor_1.web3.PublicKey(strategy.metadata.assetMint),
58
+ vault: new anchor_1.web3.PublicKey(strategy.metadata.vault),
52
59
  },
53
60
  strategyType: strategy.strategyType,
54
61
  }));
@@ -56,7 +63,7 @@ export class Client {
56
63
  }
57
64
  async getVaultPerformance(vault) {
58
65
  const url = new URL(`${this.baseUrl}/performance?vault=${vault.toString()}`);
59
- const response = await fetch(url, {
66
+ const response = await (0, cross_fetch_1.default)(url, {
60
67
  method: "GET",
61
68
  headers: this.headers,
62
69
  });
@@ -67,26 +74,26 @@ export class Client {
67
74
  for (let strats of body.strategyAPY) {
68
75
  strats.apy = Number(strats.apy);
69
76
  strats.balanceUsd = Number(strats.balanceUsd);
70
- strats.strategy = new web3.PublicKey(strats.strategy);
77
+ strats.strategy = new anchor_1.web3.PublicKey(strats.strategy);
71
78
  strats.vaultWeight = Number(strats.vaultWeight);
72
- strats.assetMint = new web3.PublicKey(strats.assetMint);
79
+ strats.assetMint = new anchor_1.web3.PublicKey(strats.assetMint);
73
80
  }
74
81
  return body;
75
82
  }
76
83
  async getUser(vault) {
77
84
  const url = new URL(`${this.baseUrl}/user?vault=${vault.toString()}&user=${this.provider.publicKey.toString()}`);
78
- const response = await fetch(url, {
85
+ const response = await (0, cross_fetch_1.default)(url, {
79
86
  method: "GET",
80
87
  headers: this.headers,
81
88
  });
82
89
  checkResponse(response);
83
90
  const body = JSON.parse(JSON.stringify(await response.json()));
84
- body.solAmount = new BN(body.solAmount, "hex");
85
- body.sharesAmount = new BN(body.sharesAmount, "hex");
91
+ body.solAmount = new anchor_1.BN(body.solAmount, "hex");
92
+ body.sharesAmount = new anchor_1.BN(body.sharesAmount, "hex");
86
93
  body.assets = body.assets.map((asset) => ({
87
94
  ...asset,
88
- mint: new web3.PublicKey(asset.mint),
89
- amount: new BN(asset.amount, "hex"),
95
+ mint: new anchor_1.web3.PublicKey(asset.mint),
96
+ amount: new anchor_1.BN(asset.amount, "hex"),
90
97
  }));
91
98
  return body;
92
99
  }
@@ -98,7 +105,7 @@ export class Client {
98
105
  amount,
99
106
  assetMint,
100
107
  };
101
- const response = await fetch(url, {
108
+ const response = await (0, cross_fetch_1.default)(url, {
102
109
  method: "POST",
103
110
  headers: this.headers,
104
111
  body: JSON.stringify(body),
@@ -117,7 +124,7 @@ export class Client {
117
124
  amount,
118
125
  assetMint,
119
126
  };
120
- const response = await fetch(url, {
127
+ const response = await (0, cross_fetch_1.default)(url, {
121
128
  method: "POST",
122
129
  headers: this.headers,
123
130
  body: JSON.stringify(body),
@@ -130,7 +137,7 @@ export class Client {
130
137
  }
131
138
  async send(base64Tx) {
132
139
  const txBytes = Buffer.from(base64Tx, "base64");
133
- const tx = web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
140
+ const tx = anchor_1.web3.VersionedTransaction.deserialize(new Uint8Array(txBytes));
134
141
  const signedTx = await this.provider.wallet.signTransaction(tx);
135
142
  const txSig = signedTx.signatures[0];
136
143
  const encodedAndSignedTx = Buffer.from(signedTx.serialize()).toString("base64");
@@ -138,7 +145,7 @@ export class Client {
138
145
  tx: encodedAndSignedTx,
139
146
  };
140
147
  const url = new URL(`${this.baseUrl}/send`);
141
- const response = await fetch(url, {
148
+ const response = await (0, cross_fetch_1.default)(url, {
142
149
  method: "POST",
143
150
  headers: this.headers,
144
151
  body: JSON.stringify(sendRequest),
@@ -147,10 +154,11 @@ export class Client {
147
154
  if (response.status !== 200) {
148
155
  throw new Error(`unexpected http status of ${response.status}`);
149
156
  }
150
- return encode(txSig);
157
+ return (0, bs58_1.encode)(txSig);
151
158
  }
152
159
  }
153
- export async function prepareUnsignedTx(connection, payer, ixns, lutAddr, additionalSigner) {
160
+ exports.Client = Client;
161
+ async function prepareUnsignedTx(connection, payer, ixns, lutAddr, additionalSigner) {
154
162
  const lutAccounts = [];
155
163
  if (lutAddr) {
156
164
  const account = (await connection.getAddressLookupTable(lutAddr)).value;
@@ -159,12 +167,12 @@ export async function prepareUnsignedTx(connection, payer, ixns, lutAddr, additi
159
167
  const recentBh = await connection.getLatestBlockhash({
160
168
  commitment: "confirmed",
161
169
  });
162
- const msg = new web3.TransactionMessage({
170
+ const msg = new anchor_1.web3.TransactionMessage({
163
171
  payerKey: payer,
164
172
  recentBlockhash: recentBh.blockhash,
165
173
  instructions: ixns,
166
174
  }).compileToV0Message(lutAccounts);
167
- const tx = new web3.VersionedTransaction(msg);
175
+ const tx = new anchor_1.web3.VersionedTransaction(msg);
168
176
  let base64Tx = Buffer.from(tx.serialize()).toString("base64");
169
177
  if (additionalSigner) {
170
178
  const signedTx = await additionalSigner.wallet.signTransaction(tx);
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@carrot-protocol/http-client",
3
- "version": "0.2.8-export-rpc-dev-f1388a1",
3
+ "version": "0.2.8-export-rpc-dev-e0deb73",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
+ "type": "commonjs",
6
7
  "types": "dist/index.d.ts",
7
8
  "scripts": {
8
9
  "build": "rm -rf dist node_modules && npm i && tsc && npm pack",
@@ -17,7 +18,7 @@
17
18
  ],
18
19
  "dependencies": {
19
20
  "@coral-xyz/anchor": "^0.29.0",
20
- "@carrot-protocol/common": "0.2.7",
21
+ "@carrot-protocol/common": "0.2.8-export-rpc-dev-6269584",
21
22
  "bs58": "^5.0.0",
22
23
  "cross-fetch": "^4.0.0"
23
24
  },