@carrot-protocol/http-client 0.2.27-refs1-dev-fdc2f8a → 0.2.27
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 +19 -3
- package/dist/index.js +13 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +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<
|
|
16
|
-
claimReferralCode(wallet: anchor.web3.PublicKey, code: string): Promise<
|
|
17
|
-
getReferralCodes(wallet: anchor.web3.PublicKey): Promise<
|
|
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>;
|
|
18
18
|
private send;
|
|
19
19
|
}
|
|
20
20
|
export interface SendRequest {
|
|
@@ -58,6 +58,22 @@ export interface VaultApy {
|
|
|
58
58
|
time: number;
|
|
59
59
|
apy: number;
|
|
60
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
|
+
}
|
|
61
77
|
declare const allowedIntervals: readonly ["HOUR", "DAY", "WEEK"];
|
|
62
78
|
export type VaultHistoricalApyInterval = (typeof allowedIntervals)[number];
|
|
63
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,24 @@ class Client {
|
|
|
193
194
|
});
|
|
194
195
|
checkResponse(response);
|
|
195
196
|
const responseBody = await response.json();
|
|
196
|
-
const
|
|
197
|
-
return
|
|
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
|
|
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(
|
|
209
|
+
body: JSON.stringify(reqBody),
|
|
209
210
|
});
|
|
210
211
|
checkResponse(response);
|
|
212
|
+
const responseBody = await response.json();
|
|
213
|
+
const body = JSON.parse(JSON.stringify(responseBody));
|
|
214
|
+
return body;
|
|
211
215
|
}
|
|
212
216
|
async getReferralCodes(wallet) {
|
|
213
217
|
const url = new URL(`${this.baseUrl}/referralCodes?wallet=${wallet.toString()}`);
|
|
@@ -217,8 +221,8 @@ class Client {
|
|
|
217
221
|
});
|
|
218
222
|
checkResponse(response);
|
|
219
223
|
const responseBody = await response.json();
|
|
220
|
-
const
|
|
221
|
-
return
|
|
224
|
+
const body = JSON.parse(JSON.stringify(responseBody));
|
|
225
|
+
return body;
|
|
222
226
|
}
|
|
223
227
|
async send(base64Tx) {
|
|
224
228
|
// error if provider is undefined
|
|
@@ -245,6 +249,9 @@ class Client {
|
|
|
245
249
|
}
|
|
246
250
|
}
|
|
247
251
|
exports.Client = Client;
|
|
252
|
+
function isWalletAllowed(response) {
|
|
253
|
+
return response.isWhitelisted || response.claimedReferralCode;
|
|
254
|
+
}
|
|
248
255
|
const allowedIntervals = ["HOUR", "DAY", "WEEK"];
|
|
249
256
|
function isValidVaultHistoricalApyInterval(interval) {
|
|
250
257
|
return allowedIntervals.includes(interval);
|