@carrot-protocol/http-client 0.2.57-lib-docs-dev-77289ab → 0.2.57-lib-docs-dev-65a9672

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 +21 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -47,16 +47,19 @@ const bs58_1 = require("bs58");
47
47
  exports.Common = __importStar(require("@carrot-protocol/common"));
48
48
  class Client {
49
49
  constructor(baseUrl, provider) {
50
- this.headers = { "Content-Type": "application/json" };
50
+ this.headers = { "Content-Type": "application/json" }; // Default headers for HTTP requests
51
+ // Initializes the client with a base URL and optional provider
51
52
  this.baseUrl = baseUrl;
52
53
  this.provider = provider;
53
54
  }
55
+ // Fetches and logs the index data from the base URL
54
56
  async index() {
55
57
  const response = await (0, cross_fetch_1.default)(this.baseUrl);
56
58
  checkResponse(response);
57
59
  const body = await response.json();
58
60
  console.log(JSON.stringify(body, undefined, 2));
59
61
  }
62
+ // Retrieves details of a specific vault
60
63
  async getVault(vault, useCache) {
61
64
  const url = new URL(`${this.baseUrl}/vault?vault=${vault.toString()}&useCache=${useCache}`);
62
65
  const response = await (0, cross_fetch_1.default)(url, {
@@ -104,6 +107,7 @@ class Client {
104
107
  }));
105
108
  return body;
106
109
  }
110
+ // Fetches performance metrics for a specific vault
107
111
  async getVaultPerformance(vault, useCache) {
108
112
  const url = new URL(`${this.baseUrl}/performance?vault=${vault.toString()}&useCache=${useCache}`);
109
113
  const response = await (0, cross_fetch_1.default)(url, {
@@ -130,6 +134,7 @@ class Client {
130
134
  }
131
135
  return body;
132
136
  }
137
+ // Retrieves user-specific data for a given vault
133
138
  async getUser(vault) {
134
139
  // error if provider is undefined
135
140
  requireProvider(this.provider);
@@ -149,6 +154,7 @@ class Client {
149
154
  }));
150
155
  return body;
151
156
  }
157
+ // Gets historical APY data for a specific vault
152
158
  async getHistoricalVaultApy(vault, interval) {
153
159
  const url = new URL(`${this.baseUrl}/historicalVaultApy?vault=${vault.toString()}&interval=${interval}`);
154
160
  const response = await (0, cross_fetch_1.default)(url, {
@@ -163,6 +169,7 @@ class Client {
163
169
  };
164
170
  return historicalVaultApyResponse;
165
171
  }
172
+ // Fetches performance data for a user across multiple wallets
166
173
  async getUserPerformance(vault, wallets) {
167
174
  const walletsString = wallets.map((wallet) => wallet.toString()).join(",");
168
175
  const url = new URL(`${this.baseUrl}/userPerformance?vault=${vault.toString()}&wallets=${walletsString}`);
@@ -183,6 +190,7 @@ class Client {
183
190
  };
184
191
  return getUserPerformanceResponse;
185
192
  }
193
+ // Retrieves historical NAV data for a specific vault
186
194
  async getHistoricalVaultNav(vault, interval) {
187
195
  const url = new URL(`${this.baseUrl}/historicalVaultNav?vault=${vault.toString()}&interval=${interval}`);
188
196
  const response = await (0, cross_fetch_1.default)(url, {
@@ -197,6 +205,7 @@ class Client {
197
205
  };
198
206
  return historicalVaultNavResponse;
199
207
  }
208
+ // Issues new assets to a specified vault
200
209
  async issue(vault, assetMint, amount) {
201
210
  // error if provider is undefined
202
211
  requireProvider(this.provider);
@@ -218,6 +227,7 @@ class Client {
218
227
  const txSig = await this.send(issueResponse.tx);
219
228
  return txSig;
220
229
  }
230
+ // Redeems assets from a specified vault
221
231
  async redeem(vault, assetMint, amount) {
222
232
  // error if provider is undefined
223
233
  requireProvider(this.provider);
@@ -239,6 +249,7 @@ class Client {
239
249
  const txSig = await this.send(redeemResponse.tx);
240
250
  return txSig;
241
251
  }
252
+ // Checks the status of a specified wallet
242
253
  async checkWallet(wallet) {
243
254
  const url = new URL(`${this.baseUrl}/checkWallet?wallet=${wallet.toString()}`);
244
255
  const response = await (0, cross_fetch_1.default)(url, {
@@ -250,6 +261,7 @@ class Client {
250
261
  const body = JSON.parse(JSON.stringify(responseBody));
251
262
  return body;
252
263
  }
264
+ // Claims a referral code for a specified wallet
253
265
  async claimReferralCode(wallet, code) {
254
266
  const url = new URL(`${this.baseUrl}/claimReferralCode`);
255
267
  const reqBody = {
@@ -266,6 +278,7 @@ class Client {
266
278
  const body = JSON.parse(JSON.stringify(responseBody));
267
279
  return body;
268
280
  }
281
+ // Retrieves referral codes associated with a specified wallet
269
282
  async getReferralCodes(wallet) {
270
283
  const url = new URL(`${this.baseUrl}/referralCodes?wallet=${wallet.toString()}`);
271
284
  const response = await (0, cross_fetch_1.default)(url, {
@@ -277,6 +290,7 @@ class Client {
277
290
  const body = JSON.parse(JSON.stringify(responseBody));
278
291
  return body;
279
292
  }
293
+ // Sends a signed transaction to the network
280
294
  async send(base64Tx) {
281
295
  // error if provider is undefined
282
296
  requireProvider(this.provider);
@@ -302,13 +316,17 @@ class Client {
302
316
  }
303
317
  }
304
318
  exports.Client = Client;
319
+ // Checks if a wallet is allowed based on its status
305
320
  function isWalletAllowed(response) {
306
321
  return response.isWhitelisted || response.claimedReferralCode;
307
322
  }
323
+ // Allowed intervals for historical data
308
324
  const allowedIntervals = ["HOUR", "DAY", "WEEK"];
325
+ // Validates the provided historical interval
309
326
  function isValidVaultHistoricalInterval(interval) {
310
327
  return allowedIntervals.includes(interval);
311
328
  }
329
+ // Prepares an unsigned transaction for submission
312
330
  async function prepareUnsignedTx(connection, payer, ixns, lutAddr, additionalSigner) {
313
331
  const lutAccounts = [];
314
332
  if (lutAddr) {
@@ -331,11 +349,13 @@ async function prepareUnsignedTx(connection, payer, ixns, lutAddr, additionalSig
331
349
  }
332
350
  return base64Tx;
333
351
  }
352
+ // Checks the response status of an HTTP request
334
353
  function checkResponse(response) {
335
354
  if (response.status !== 200) {
336
355
  throw new Error(`unexpected http status of ${response.status}`);
337
356
  }
338
357
  }
358
+ // Ensures that a provider is defined
339
359
  function requireProvider(provider) {
340
360
  if (provider) {
341
361
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/http-client",
3
- "version": "0.2.57-lib-docs-dev-77289ab",
3
+ "version": "0.2.57-lib-docs-dev-65a9672",
4
4
  "description": "interact with carrot api",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",