@carrot-protocol/http-client 0.2.27-refs1-dev-1802f0b → 0.2.27-refs1-dev-0c99d82

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
@@ -12,8 +12,9 @@ export declare class Client {
12
12
  getHistoricalVaultApy(vault: anchor.web3.PublicKey, interval: VaultHistoricalApyInterval): Promise<HistoricalVaultApyResponse>;
13
13
  issue(vault: anchor.web3.PublicKey, assetMint: anchor.web3.PublicKey, amount: anchor.BN): Promise<string>;
14
14
  redeem(vault: anchor.web3.PublicKey, assetMint: anchor.web3.PublicKey, amount: anchor.BN): Promise<string>;
15
- checkWallet(wallet: anchor.web3.PublicKey): Promise<boolean>;
16
- claimReferralCode(wallet: anchor.web3.PublicKey, code: string): Promise<void>;
15
+ checkWallet(wallet: anchor.web3.PublicKey): Promise<CheckWalletResponse>;
16
+ claimReferralCode(wallet: anchor.web3.PublicKey, code: string): Promise<ClaimReferralCodeResponse>;
17
+ getReferralCodes(wallet: anchor.web3.PublicKey): Promise<GetReferralCodesResponse>;
17
18
  private send;
18
19
  }
19
20
  export interface SendRequest {
@@ -57,6 +58,22 @@ export interface VaultApy {
57
58
  time: number;
58
59
  apy: number;
59
60
  }
61
+ export interface CheckWalletResponse {
62
+ isWhitelisted: boolean;
63
+ claimedReferralCode: boolean;
64
+ }
65
+ export declare function isWalletAllowed(response: CheckWalletResponse): boolean;
66
+ export interface ClaimReferralCodeResponse {
67
+ success: boolean;
68
+ }
69
+ export interface GetReferralCodesResponse {
70
+ codes: ReferralCode[];
71
+ }
72
+ export interface ReferralCode {
73
+ code: string;
74
+ maxUses: number;
75
+ remainingUses: number;
76
+ }
60
77
  declare const allowedIntervals: readonly ["HOUR", "DAY", "WEEK"];
61
78
  export type VaultHistoricalApyInterval = (typeof allowedIntervals)[number];
62
79
  export declare function isValidVaultHistoricalApyInterval(interval: string): interval is VaultHistoricalApyInterval;
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.Client = void 0;
30
+ exports.isWalletAllowed = isWalletAllowed;
30
31
  exports.isValidVaultHistoricalApyInterval = isValidVaultHistoricalApyInterval;
31
32
  exports.prepareUnsignedTx = prepareUnsignedTx;
32
33
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
@@ -193,21 +194,35 @@ class Client {
193
194
  });
194
195
  checkResponse(response);
195
196
  const responseBody = await response.json();
196
- const isWalletValid = JSON.parse(JSON.stringify(responseBody));
197
- return isWalletValid;
197
+ const body = JSON.parse(JSON.stringify(responseBody));
198
+ return body;
198
199
  }
199
200
  async claimReferralCode(wallet, code) {
200
201
  const url = new URL(`${this.baseUrl}/claimReferralCode`);
201
- const body = {
202
+ const reqBody = {
202
203
  wallet: wallet.toString(),
203
204
  code,
204
205
  };
205
206
  const response = await (0, cross_fetch_1.default)(url, {
206
207
  method: "POST",
207
208
  headers: this.headers,
208
- body: JSON.stringify(body),
209
+ body: JSON.stringify(reqBody),
210
+ });
211
+ checkResponse(response);
212
+ const responseBody = await response.json();
213
+ const body = JSON.parse(JSON.stringify(responseBody));
214
+ return body;
215
+ }
216
+ async getReferralCodes(wallet) {
217
+ const url = new URL(`${this.baseUrl}/referralCodes?wallet=${wallet.toString()}`);
218
+ const response = await (0, cross_fetch_1.default)(url, {
219
+ method: "GET",
220
+ headers: this.headers,
209
221
  });
210
222
  checkResponse(response);
223
+ const responseBody = await response.json();
224
+ const body = JSON.parse(JSON.stringify(responseBody));
225
+ return body;
211
226
  }
212
227
  async send(base64Tx) {
213
228
  // error if provider is undefined
@@ -234,6 +249,9 @@ class Client {
234
249
  }
235
250
  }
236
251
  exports.Client = Client;
252
+ function isWalletAllowed(response) {
253
+ return response.isWhitelisted || response.claimedReferralCode;
254
+ }
237
255
  const allowedIntervals = ["HOUR", "DAY", "WEEK"];
238
256
  function isValidVaultHistoricalApyInterval(interval) {
239
257
  return allowedIntervals.includes(interval);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrot-protocol/http-client",
3
- "version": "0.2.27-refs1-dev-1802f0b",
3
+ "version": "0.2.27-refs1-dev-0c99d82",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",