@dripfi/drip-sdk 1.2.18 → 1.2.20
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/README.md +6 -19
- package/dist/DripApi.d.ts +20 -43
- package/dist/DripApi.js +70 -235
- package/dist/DripConfig.d.ts +1 -1
- package/dist/DripConfig.js +2 -2
- package/dist/DripSdk.d.ts +12 -15
- package/dist/DripSdk.js +52 -150
- package/dist/index.d.ts +1 -2
- package/dist/test.js +1 -3
- package/dist/types/SignedPayload.d.ts +5 -0
- package/dist/types/SignedPayload.js +2 -0
- package/dist/types/UpgradeLoyaltyCardPayload.d.ts +3 -0
- package/dist/types/UpgradeLoyaltyCardPayload.js +2 -0
- package/package.json +2 -5
- package/dist/types/AuthenticationStatus.d.ts +0 -18
- package/dist/types/AuthenticationStatus.js +0 -19
package/README.md
CHANGED
@@ -48,12 +48,9 @@ const dripSdk = new DripSdk(chain, signer);
|
|
48
48
|
| `getVaultStats(): Promise<VaultStats>`| NO | Returns some overall drip stats |
|
49
49
|
| `getTokenPrice(tokenName: string): Promise<number>`| NO | Returns the price for the given token (only works for weth at the moment) |
|
50
50
|
| `updateSigner(newSigner: Signer): Promise<void>`| NO | Updates the signer for the SDK instance. |
|
51
|
-
| `isUserAuthenticated(): Promise<AuthenticationStatus>` | NO | Checks if the user is authenticated and returns authentication status along with relevant information. |
|
52
|
-
| `authenticate(): Promise<boolean>` | NO | Initiates the user authentication process and returns a boolean indicating success. |
|
53
51
|
| `deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>` | NO | The deposit function allows you to deposit tokens into a specific vault. Returns txHash. |
|
54
52
|
| `getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>`| NO | Returns the expected amount of tokens to get from a swap |
|
55
53
|
| `getUserBalance(): Promise<UserBalance>` | YES | Returns overall user balance information |
|
56
|
-
| `getUserBoostedNfts(vaultAddress: string): Promise<string[]>` | YES | Returns an array of boosted nfts addresses owned by the user |
|
57
54
|
| `getRewardsPerHour(vaultAddress: string): Promise<string[]>` | YES | Returns an estimated amount of tokens the user will receive in 1 hour as reward. It considers boost nfts the user owns for the estimation. |
|
58
55
|
| `getRewards(): Promise<UserRewards>` | YES | Fetches the current user's rewards points for each vault. |
|
59
56
|
| `getUserVaultBalance(): Promise<UserVaultBalance>` | YES | Fetches the user's balance for a specific Drip Vault. |
|
@@ -64,7 +61,7 @@ const dripSdk = new DripSdk(chain, signer);
|
|
64
61
|
| `getTokenAllowanceForCurrency(tokenAddress: string): Promise<string>` | NO | This function retrieves the token allowance for a specific currency. |
|
65
62
|
| `getTokenAllowanceForRecycler(tokenAddress: string): Promise<BigNumber>` | NO | This function retrieves the token allowance for the recycler contract. |
|
66
63
|
| `getTokenAllowanceForSwapAndRecycler(tokenAddress: string): Promise<BigNumber>` | NO | This function retrieves the token allowance for the swap and recycler contract. |
|
67
|
-
| `getUserBoostedNfts(vaultAddress: string
|
64
|
+
| `getUserBoostedNfts(vaultAddress: string): Promise<string[]>` | YES | This function retrieves an array of boosted NFT addresses owned by the user. |
|
68
65
|
| `getRewardsPerHour(vaultAddress: string): Promise<number> ` | YES | This function returns an estimated amount of tokens the user will receive in one hour as a reward for the given vault |
|
69
66
|
| `newDeposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>` | YES | This function allows for a new deposit without checking for allowance.
|
70
67
|
| `newSwapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string> ` | YES | This function allows for a new swap and deposit without checking for allowance. |
|
@@ -72,15 +69,12 @@ const dripSdk = new DripSdk(chain, signer);
|
|
72
69
|
| `getVestingStart(): Promise<string>` | YES | This function retrieves the start time of the vesting period. |
|
73
70
|
| `getVestingEnd(): Promise<string>` | YES | This function retrieves the end time of the vesting period.
|
74
71
|
| `getBeansHistory(): Promise<BeanEntry[]> ` | YES | This function retrieves the user's beans history of tx
|
75
|
-
| `getBeansBalance(
|
76
|
-
| `getMyPerqBalance(
|
77
|
-
| `getVaultsClaimableData(
|
78
|
-
| `upgradeLoyaltyCard(): Promise<LoyaltyCard>` | YES | This function upgrades the user's loyalty card.
|
79
|
-
| `
|
80
|
-
| `getOwnedLoyaltyCards(headers?: Headers): Promise<LoyaltyCard>` | YES | This function fetches the next loyalty card for the authenticated user based on the currently owned one
|
72
|
+
| `getBeansBalance(): Promise<BeansBalance> ` | YES | This function retrieves the user's beans balance.
|
73
|
+
| `getMyPerqBalance(): Promise<MyPerqData>` | YES | This function retrieves the user's Perq balance data.
|
74
|
+
| `getVaultsClaimableData(): Promise<VaultClaimData> ` | YES | This function fetches claimable data for the user's vaults.
|
75
|
+
| `upgradeLoyaltyCard(index: number): Promise<LoyaltyCard>` | YES | This function upgrades the user's loyalty card.
|
76
|
+
| `getOwnedLoyaltyCard(): Promise<LoyaltyCard>` | YES | This function fetches the next loyalty card for the authenticated user based on the currently owned one
|
81
77
|
| `getAllLoyaltyCards(): Promise<LoyaltyCard[]>` | YES | This function fetches all available loyalty cards.
|
82
|
-
| `getLoyaltyCardBoost(rewardId: string, headers?: Headers): Promise<number>` | YES | This function retrieves the boost value for a specific loyalty card.
|
83
|
-
|
84
78
|
|
85
79
|
|
86
80
|
> [!IMPORTANT]
|
@@ -281,13 +275,6 @@ type Strategy = {
|
|
281
275
|
lastDoHardWorkBlock: number | null
|
282
276
|
}
|
283
277
|
|
284
|
-
type AuthenticationStatus = {
|
285
|
-
isAuthenticated: boolean
|
286
|
-
address?: string
|
287
|
-
token?: string
|
288
|
-
message?: string
|
289
|
-
}
|
290
|
-
|
291
278
|
interface QLFastRedeem {
|
292
279
|
assetsWithdrawn: {
|
293
280
|
asset: {
|
package/dist/DripApi.d.ts
CHANGED
@@ -11,57 +11,34 @@ import { LoyaltyCard } from './types/LoyaltyCard';
|
|
11
11
|
import { BeansBalance } from './types/BeansBalance';
|
12
12
|
import { PerqToBeansSwapInfo } from './types/PerqToBeansSwapInfo';
|
13
13
|
import BeanEntry from './types/BeanEntry';
|
14
|
-
import {
|
15
|
-
|
14
|
+
import { SignedPayload } from './types/SignedPayload';
|
15
|
+
import { UpgradeLoyaltyCardPayload } from './types/UpgradeLoyaltyCardPayload';
|
16
16
|
export default class DripApi {
|
17
17
|
route: string;
|
18
18
|
constructor(route: string);
|
19
19
|
fetchAllVaults(): Promise<Vault[]>;
|
20
20
|
fetchTokenPrice(tokenName: string): Promise<number>;
|
21
|
-
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number
|
22
|
-
getUserBalance(walletAddress: string
|
23
|
-
getUserBoostedNfts(walletAddress: string, vaultAddress: string
|
21
|
+
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>;
|
22
|
+
getUserBalance(walletAddress: string): Promise<UserBalance>;
|
23
|
+
getUserBoostedNfts(walletAddress: string, vaultAddress: string): Promise<string[]>;
|
24
24
|
fetchVaultStats(): Promise<VaultStats>;
|
25
25
|
fetchVaultDetails(vaultAddress: string): Promise<Vault>;
|
26
|
-
fetchRewardsPerHour(
|
26
|
+
fetchRewardsPerHour(walletAddress: string, vaultAddress: string): Promise<number>;
|
27
27
|
getSwapInfo(fromTokenAddress: string, toTokenAddress: string, amount: BigNumber, fromAddress: string): Promise<SwapInfo[]>;
|
28
|
-
fetchUserSVTBalance(vaultAddress: string, walletAddress: string
|
29
|
-
fetchUserBalance(vaultAddress: string, walletAddress: string
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
fetchUserRewards(walletAddress: string, token: string, headers?: Headers): Promise<UserRewards>;
|
38
|
-
fetchVaultsClaimableData(walletAddress: string, token: string, headers?: Headers): Promise<VaultClaimData>;
|
28
|
+
fetchUserSVTBalance(vaultAddress: string, walletAddress: string): Promise<BigNumber>;
|
29
|
+
fetchUserBalance(vaultAddress: string, walletAddress: string): Promise<Record<string, string>>;
|
30
|
+
fetchEnrichedUserWNFTForVault(vaultAddress: string, walletAddress: string): Promise<any[]>;
|
31
|
+
fetchAllUserWNFTForVault(vaultAddress: string, walletAddress: string): Promise<any[]>;
|
32
|
+
fetchAllUserDNFTForVault(vaultAddress: string, walletAddress: string): Promise<any[]>;
|
33
|
+
fetchAssetPerSvtAtBlock(vaultAddress: string, blocknumber: number): Promise<BigNumber>;
|
34
|
+
fetchFastWithdrawNFTs(vaultAddress: string, walletAddress: string): Promise<QLFastRedeem[]>;
|
35
|
+
fetchUserRewards(walletAddress: string): Promise<UserRewards>;
|
36
|
+
fetchVaultsClaimableData(walletAddress: string): Promise<VaultClaimData>;
|
39
37
|
fetchAllLoyaltyCards(): Promise<LoyaltyCard[]>;
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
cost: number;
|
45
|
-
boost: any;
|
46
|
-
}>;
|
47
|
-
fetchNextLoyaltyCard(token: string, headers?: Headers): Promise<{
|
48
|
-
id: any;
|
49
|
-
tier: any;
|
50
|
-
level: any;
|
51
|
-
cost: number;
|
52
|
-
boost: any;
|
53
|
-
}>;
|
54
|
-
fetchBeansBalance(token: string, headers?: Headers): Promise<BeansBalance>;
|
55
|
-
upgradeLoyaltyCard(token: string, headers?: Headers): Promise<{
|
56
|
-
id: any;
|
57
|
-
tier: any;
|
58
|
-
level: any;
|
59
|
-
cost: number;
|
60
|
-
boost: any;
|
61
|
-
}>;
|
62
|
-
fetchMyPerqData(userAddress: string, token: string, headers?: Headers): Promise<MyPerqData>;
|
63
|
-
getLoyaltyCardBoost(rewardId: string, token: string, headers?: Headers): Promise<number>;
|
38
|
+
fetchOwnedLoyaltyCard(walletAddress: string): Promise<LoyaltyCard>;
|
39
|
+
fetchBeansBalance(walletAddress: string): Promise<BeansBalance>;
|
40
|
+
upgradeLoyaltyCard(signedPayload: SignedPayload<UpgradeLoyaltyCardPayload>): Promise<LoyaltyCard>;
|
41
|
+
fetchMyPerqData(userAddress: string): Promise<MyPerqData>;
|
64
42
|
getSwapPerqForBeansInfo(): Promise<PerqToBeansSwapInfo>;
|
65
|
-
fetchBeansHistory(walletAddress: string
|
66
|
-
checkTokenStatus(token: string): Promise<AuthenticationStatus>;
|
43
|
+
fetchBeansHistory(walletAddress: string): Promise<BeanEntry[]>;
|
67
44
|
}
|
package/dist/DripApi.js
CHANGED
@@ -9,13 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.IMPERSONATOR_HEADER = void 0;
|
13
12
|
const ethers_1 = require("ethers");
|
14
13
|
const DripConfig_1 = require("./DripConfig");
|
15
|
-
const AuthenticationStatus_1 = require("./types/AuthenticationStatus");
|
16
14
|
const WETH_TOKEN_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
17
|
-
exports.IMPERSONATOR_HEADER = 'impersonatorAddress';
|
18
|
-
const AUTHORIZATION_HEADER = 'Authorization';
|
19
15
|
class DripApi {
|
20
16
|
constructor(route) {
|
21
17
|
this.route = route;
|
@@ -44,19 +40,15 @@ class DripApi {
|
|
44
40
|
}
|
45
41
|
});
|
46
42
|
}
|
47
|
-
getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals
|
43
|
+
getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals) {
|
48
44
|
return __awaiter(this, void 0, void 0, function* () {
|
49
|
-
const headers = new Headers();
|
50
|
-
headers.append(AUTHORIZATION_HEADER, token);
|
51
45
|
const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
|
52
46
|
const queryParams = new URLSearchParams({
|
53
47
|
from: fromTokenAddress,
|
54
48
|
to: toTokenAddress,
|
55
49
|
amount: parsedAmount.toString(),
|
56
50
|
});
|
57
|
-
const res = yield fetch(`${this.route}/api-be/api/1inch/swap?${queryParams}
|
58
|
-
headers,
|
59
|
-
});
|
51
|
+
const res = yield fetch(`${this.route}/api-be/api/1inch/swap?${queryParams}`);
|
60
52
|
if (res.ok) {
|
61
53
|
const data = yield res.json();
|
62
54
|
return data;
|
@@ -66,16 +58,9 @@ class DripApi {
|
|
66
58
|
}
|
67
59
|
});
|
68
60
|
}
|
69
|
-
getUserBalance(walletAddress
|
61
|
+
getUserBalance(walletAddress) {
|
70
62
|
return __awaiter(this, void 0, void 0, function* () {
|
71
|
-
const
|
72
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
73
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
74
|
-
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
75
|
-
}
|
76
|
-
const res = yield fetch(`${this.route}/api-be/api/user/deposits/${walletAddress}`, {
|
77
|
-
headers: reqHeaders,
|
78
|
-
});
|
63
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${walletAddress}/deposits`);
|
79
64
|
if (res.ok) {
|
80
65
|
const data = yield res.json();
|
81
66
|
return data;
|
@@ -85,16 +70,9 @@ class DripApi {
|
|
85
70
|
}
|
86
71
|
});
|
87
72
|
}
|
88
|
-
getUserBoostedNfts(walletAddress, vaultAddress
|
73
|
+
getUserBoostedNfts(walletAddress, vaultAddress) {
|
89
74
|
return __awaiter(this, void 0, void 0, function* () {
|
90
|
-
const
|
91
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
92
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
93
|
-
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
94
|
-
}
|
95
|
-
const res = yield fetch(`${this.route}/api-be/api/user/nftBoost/${walletAddress}/${vaultAddress}`, {
|
96
|
-
headers: reqHeaders,
|
97
|
-
});
|
75
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${walletAddress}/nftBoost/${vaultAddress}`);
|
98
76
|
if (res.ok) {
|
99
77
|
const data = yield res.json();
|
100
78
|
return data;
|
@@ -128,13 +106,9 @@ class DripApi {
|
|
128
106
|
}
|
129
107
|
});
|
130
108
|
}
|
131
|
-
fetchRewardsPerHour(
|
109
|
+
fetchRewardsPerHour(walletAddress, vaultAddress) {
|
132
110
|
return __awaiter(this, void 0, void 0, function* () {
|
133
|
-
const
|
134
|
-
headers.append(AUTHORIZATION_HEADER, token);
|
135
|
-
const res = yield fetch(`${this.route}/api-be/api/user/rewardsPerHour/${vaultAddress}`, {
|
136
|
-
headers,
|
137
|
-
});
|
111
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${walletAddress}/rewardsPerHour/${vaultAddress}`);
|
138
112
|
if (res.ok) {
|
139
113
|
const data = yield res.json();
|
140
114
|
return data.rewardsPerHour;
|
@@ -166,13 +140,9 @@ class DripApi {
|
|
166
140
|
}
|
167
141
|
});
|
168
142
|
}
|
169
|
-
fetchUserSVTBalance(vaultAddress, walletAddress
|
143
|
+
fetchUserSVTBalance(vaultAddress, walletAddress) {
|
170
144
|
return __awaiter(this, void 0, void 0, function* () {
|
171
|
-
const
|
172
|
-
headers.append(AUTHORIZATION_HEADER, token);
|
173
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/user/svtBalance/${walletAddress}/${vaultAddress}`, {
|
174
|
-
headers,
|
175
|
-
});
|
145
|
+
const res = yield fetch(`${this.route}/api-be/api/spool/user/${walletAddress}/svtBalance/${vaultAddress}`);
|
176
146
|
if (res.ok) {
|
177
147
|
const data = (yield res.json());
|
178
148
|
return data;
|
@@ -182,13 +152,9 @@ class DripApi {
|
|
182
152
|
}
|
183
153
|
});
|
184
154
|
}
|
185
|
-
fetchUserBalance(vaultAddress, walletAddress
|
155
|
+
fetchUserBalance(vaultAddress, walletAddress) {
|
186
156
|
return __awaiter(this, void 0, void 0, function* () {
|
187
|
-
const
|
188
|
-
headers.append(AUTHORIZATION_HEADER, token);
|
189
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/userBalance/${walletAddress}/${vaultAddress}`, {
|
190
|
-
headers,
|
191
|
-
});
|
157
|
+
const res = yield fetch(`${this.route}/api-be/api/spool/user/${walletAddress}/balance/${vaultAddress}`);
|
192
158
|
if (res.ok) {
|
193
159
|
const data = (yield res.json());
|
194
160
|
return data;
|
@@ -198,29 +164,9 @@ class DripApi {
|
|
198
164
|
}
|
199
165
|
});
|
200
166
|
}
|
201
|
-
|
202
|
-
return __awaiter(this, void 0, void 0, function* () {
|
203
|
-
const headers = new Headers();
|
204
|
-
headers.append(AUTHORIZATION_HEADER, token);
|
205
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/user/dNft/${walletAddress}/${vaultAddress}`, {
|
206
|
-
headers,
|
207
|
-
});
|
208
|
-
if (res.ok) {
|
209
|
-
const data = yield res.json();
|
210
|
-
return data;
|
211
|
-
}
|
212
|
-
else {
|
213
|
-
throw Error(`${yield res.text()}`);
|
214
|
-
}
|
215
|
-
});
|
216
|
-
}
|
217
|
-
fetchEnrichedUserWNFTForVault(vaultAddress, walletAddress, token) {
|
167
|
+
fetchEnrichedUserWNFTForVault(vaultAddress, walletAddress) {
|
218
168
|
return __awaiter(this, void 0, void 0, function* () {
|
219
|
-
const
|
220
|
-
headers.append(AUTHORIZATION_HEADER, token);
|
221
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/user/wNft/${walletAddress}/${vaultAddress}`, {
|
222
|
-
headers,
|
223
|
-
});
|
169
|
+
const res = yield fetch(`${this.route}/api-be/api/spool/user/${walletAddress}/wNft/${vaultAddress}`);
|
224
170
|
if (res.ok) {
|
225
171
|
const data = yield res.json();
|
226
172
|
return data;
|
@@ -230,13 +176,9 @@ class DripApi {
|
|
230
176
|
}
|
231
177
|
});
|
232
178
|
}
|
233
|
-
|
179
|
+
fetchAllUserWNFTForVault(vaultAddress, walletAddress) {
|
234
180
|
return __awaiter(this, void 0, void 0, function* () {
|
235
|
-
const
|
236
|
-
headers.append(AUTHORIZATION_HEADER, token);
|
237
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/user/svtFromNft/${userAddress}/${vaultAddress}?dnfts=${dnfts.join(',')}`, {
|
238
|
-
headers,
|
239
|
-
});
|
181
|
+
const res = yield fetch(`${this.route}/api-be/api/spool/user/${walletAddress}/allWnft/${vaultAddress}`);
|
240
182
|
if (res.ok) {
|
241
183
|
const data = (yield res.json());
|
242
184
|
return data;
|
@@ -246,16 +188,9 @@ class DripApi {
|
|
246
188
|
}
|
247
189
|
});
|
248
190
|
}
|
249
|
-
|
191
|
+
fetchAllUserDNFTForVault(vaultAddress, walletAddress) {
|
250
192
|
return __awaiter(this, void 0, void 0, function* () {
|
251
|
-
const
|
252
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
253
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
254
|
-
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
255
|
-
}
|
256
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/user/allWnft/${walletAddress}/${vaultAddress}`, {
|
257
|
-
headers: reqHeaders,
|
258
|
-
});
|
193
|
+
const res = yield fetch(`${this.route}/api-be/api/spool/user/${walletAddress}/allDnft/${vaultAddress}`);
|
259
194
|
if (res.ok) {
|
260
195
|
const data = (yield res.json());
|
261
196
|
return data;
|
@@ -265,16 +200,9 @@ class DripApi {
|
|
265
200
|
}
|
266
201
|
});
|
267
202
|
}
|
268
|
-
|
203
|
+
fetchAssetPerSvtAtBlock(vaultAddress, blocknumber) {
|
269
204
|
return __awaiter(this, void 0, void 0, function* () {
|
270
|
-
const
|
271
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
272
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
273
|
-
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
274
|
-
}
|
275
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/user/allDnft/${walletAddress}/${vaultAddress}`, {
|
276
|
-
headers: reqHeaders,
|
277
|
-
});
|
205
|
+
const res = yield fetch(`${this.route}/api-be/api/spool/assetBalance/${blocknumber}/${vaultAddress}`);
|
278
206
|
if (res.ok) {
|
279
207
|
const data = (yield res.json());
|
280
208
|
return data;
|
@@ -284,13 +212,9 @@ class DripApi {
|
|
284
212
|
}
|
285
213
|
});
|
286
214
|
}
|
287
|
-
|
215
|
+
fetchFastWithdrawNFTs(vaultAddress, walletAddress) {
|
288
216
|
return __awaiter(this, void 0, void 0, function* () {
|
289
|
-
const
|
290
|
-
headers.append(AUTHORIZATION_HEADER, token);
|
291
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/user/assetBalance/${blocknumber}/${vaultAddress}`, {
|
292
|
-
headers,
|
293
|
-
});
|
217
|
+
const res = yield fetch(`${this.route}/api-be/api/spool/user/${walletAddress}/fastWithdrawNft/${vaultAddress}`);
|
294
218
|
if (res.ok) {
|
295
219
|
const data = (yield res.json());
|
296
220
|
return data;
|
@@ -300,18 +224,11 @@ class DripApi {
|
|
300
224
|
}
|
301
225
|
});
|
302
226
|
}
|
303
|
-
|
227
|
+
fetchUserRewards(walletAddress) {
|
304
228
|
return __awaiter(this, void 0, void 0, function* () {
|
305
|
-
const
|
306
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
307
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
308
|
-
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
309
|
-
}
|
310
|
-
const res = yield fetch(`${this.route}/api-be/api/spool/user/fastWithdrawNft/${walletAddress}/${vaultAddress}`, {
|
311
|
-
headers: reqHeaders,
|
312
|
-
});
|
229
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${walletAddress}/rewards`);
|
313
230
|
if (res.ok) {
|
314
|
-
const data =
|
231
|
+
const data = yield res.json();
|
315
232
|
return data;
|
316
233
|
}
|
317
234
|
else {
|
@@ -319,16 +236,9 @@ class DripApi {
|
|
319
236
|
}
|
320
237
|
});
|
321
238
|
}
|
322
|
-
|
239
|
+
fetchVaultsClaimableData(walletAddress) {
|
323
240
|
return __awaiter(this, void 0, void 0, function* () {
|
324
|
-
const
|
325
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
326
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
327
|
-
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
328
|
-
}
|
329
|
-
const res = yield fetch(`${this.route}/api-be/api/user/rewards/${walletAddress}`, {
|
330
|
-
headers: reqHeaders,
|
331
|
-
});
|
241
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${walletAddress}/claimableVaults`);
|
332
242
|
if (res.ok) {
|
333
243
|
const data = yield res.json();
|
334
244
|
return data;
|
@@ -338,45 +248,27 @@ class DripApi {
|
|
338
248
|
}
|
339
249
|
});
|
340
250
|
}
|
341
|
-
|
251
|
+
fetchAllLoyaltyCards() {
|
342
252
|
return __awaiter(this, void 0, void 0, function* () {
|
343
|
-
const
|
344
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
345
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
346
|
-
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
347
|
-
}
|
348
|
-
const res = yield fetch(`${this.route}/api-be/api/user/claimableVaults/${walletAddress}`, {
|
349
|
-
headers: reqHeaders,
|
350
|
-
});
|
253
|
+
const res = yield fetch(`${this.route}/api-be/api/loyaltyCards/all`);
|
351
254
|
if (res.ok) {
|
352
255
|
const data = yield res.json();
|
353
|
-
return data
|
256
|
+
return data.map((card) => ({
|
257
|
+
id: card.id,
|
258
|
+
tier: card.tier,
|
259
|
+
level: card.level,
|
260
|
+
cost: parseFloat(ethers_1.ethers.utils.formatUnits(card.cost.toString(), DripConfig_1.PERQ_TOKEN_DECIMALS)),
|
261
|
+
boost: card.boost
|
262
|
+
}));
|
354
263
|
}
|
355
264
|
else {
|
356
265
|
throw Error(`${yield res.text()}`);
|
357
266
|
}
|
358
267
|
});
|
359
268
|
}
|
360
|
-
|
361
|
-
return __awaiter(this, void 0, void 0, function* () {
|
362
|
-
const res = yield fetch(`${this.route}/api-be/api/loyaltyCards/all`);
|
363
|
-
const data = yield res.json();
|
364
|
-
return data.map((card) => ({
|
365
|
-
id: card.id,
|
366
|
-
tier: card.tier,
|
367
|
-
level: card.level,
|
368
|
-
cost: parseFloat(ethers_1.ethers.utils.formatUnits(card.cost.toString(), DripConfig_1.DRIP_TOKEN_DECIMALS)),
|
369
|
-
boost: card.boost
|
370
|
-
}));
|
371
|
-
});
|
372
|
-
}
|
373
|
-
fetchOwnedLoyaltyCards(token, headers) {
|
269
|
+
fetchOwnedLoyaltyCard(walletAddress) {
|
374
270
|
return __awaiter(this, void 0, void 0, function* () {
|
375
|
-
const
|
376
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
377
|
-
const res = yield fetch(`${this.route}/api-be/api/loyaltyCards/owned`, {
|
378
|
-
headers: reqHeaders,
|
379
|
-
});
|
271
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${walletAddress}/loyaltyCards/owned`);
|
380
272
|
if (res.status === 204) {
|
381
273
|
return {};
|
382
274
|
}
|
@@ -386,7 +278,7 @@ class DripApi {
|
|
386
278
|
id: data.id,
|
387
279
|
tier: data.tier,
|
388
280
|
level: data.level,
|
389
|
-
cost: parseFloat(ethers_1.ethers.utils.formatUnits(data.cost.toString(), DripConfig_1.
|
281
|
+
cost: parseFloat(ethers_1.ethers.utils.formatUnits(data.cost.toString(), DripConfig_1.PERQ_TOKEN_DECIMALS)),
|
390
282
|
boost: data.boost
|
391
283
|
};
|
392
284
|
}
|
@@ -395,81 +287,50 @@ class DripApi {
|
|
395
287
|
}
|
396
288
|
});
|
397
289
|
}
|
398
|
-
|
290
|
+
fetchBeansBalance(walletAddress) {
|
399
291
|
return __awaiter(this, void 0, void 0, function* () {
|
400
|
-
const
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
};
|
413
|
-
});
|
414
|
-
}
|
415
|
-
fetchBeansBalance(token, headers) {
|
416
|
-
return __awaiter(this, void 0, void 0, function* () {
|
417
|
-
const reqHeaders = headers ? headers : new Headers();
|
418
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
419
|
-
const res = yield fetch(`${this.route}/api-be/api/beans/balance`, {
|
420
|
-
headers: reqHeaders,
|
421
|
-
});
|
422
|
-
const data = yield res.json();
|
423
|
-
return {
|
424
|
-
balance: ethers_1.ethers.utils.formatUnits(data.balance, DripConfig_1.DRIP_TOKEN_DECIMALS),
|
425
|
-
bonusesClaimed: data.bonusesClaimed
|
426
|
-
};
|
292
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${walletAddress}/beans/balance`);
|
293
|
+
if (res.ok) {
|
294
|
+
const data = yield res.json();
|
295
|
+
const beansBalance = {
|
296
|
+
balance: ethers_1.ethers.utils.formatUnits(data.balance, DripConfig_1.PERQ_TOKEN_DECIMALS),
|
297
|
+
bonusesClaimed: data.bonusesClaimed
|
298
|
+
};
|
299
|
+
return beansBalance;
|
300
|
+
}
|
301
|
+
else {
|
302
|
+
throw Error(`${yield res.text()}`);
|
303
|
+
}
|
427
304
|
});
|
428
305
|
}
|
429
|
-
upgradeLoyaltyCard(
|
306
|
+
upgradeLoyaltyCard(signedPayload) {
|
430
307
|
return __awaiter(this, void 0, void 0, function* () {
|
431
|
-
const
|
432
|
-
|
433
|
-
const res = yield fetch(`${this.route}/api-be/api/loyaltyCards/upgrade`, {
|
308
|
+
const { signerAddress } = signedPayload;
|
309
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${signerAddress}/loyaltyCards/upgrade`, {
|
434
310
|
method: 'POST',
|
435
|
-
headers:
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
id: data.id,
|
440
|
-
tier: data.tier,
|
441
|
-
level: data.level,
|
442
|
-
cost: parseFloat(ethers_1.ethers.utils.formatUnits(data.cost.toString(), DripConfig_1.DRIP_TOKEN_DECIMALS)),
|
443
|
-
boost: data.boost
|
444
|
-
};
|
445
|
-
});
|
446
|
-
}
|
447
|
-
fetchMyPerqData(userAddress, token, headers) {
|
448
|
-
return __awaiter(this, void 0, void 0, function* () {
|
449
|
-
const reqHeaders = headers ? headers : new Headers();
|
450
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
451
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
452
|
-
userAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
453
|
-
}
|
454
|
-
const res = yield fetch(`${this.route}/api-be/api/myperq/${userAddress}`, {
|
455
|
-
headers: reqHeaders,
|
311
|
+
headers: {
|
312
|
+
'Content-Type': 'application/json'
|
313
|
+
},
|
314
|
+
body: JSON.stringify(signedPayload)
|
456
315
|
});
|
457
316
|
if (res.ok) {
|
458
317
|
const data = yield res.json();
|
459
|
-
return
|
318
|
+
return {
|
319
|
+
id: data.id,
|
320
|
+
tier: data.tier,
|
321
|
+
level: data.level,
|
322
|
+
cost: parseFloat(ethers_1.ethers.utils.formatUnits(data.cost.toString(), DripConfig_1.PERQ_TOKEN_DECIMALS)),
|
323
|
+
boost: data.boost
|
324
|
+
};
|
460
325
|
}
|
461
326
|
else {
|
462
327
|
throw Error(`${yield res.text()}`);
|
463
328
|
}
|
464
329
|
});
|
465
330
|
}
|
466
|
-
|
331
|
+
fetchMyPerqData(userAddress) {
|
467
332
|
return __awaiter(this, void 0, void 0, function* () {
|
468
|
-
const
|
469
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
470
|
-
const res = yield fetch(`${this.route}api/loyaltyCards/boost/${rewardId}`, {
|
471
|
-
headers: reqHeaders,
|
472
|
-
});
|
333
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${userAddress}/myperq`);
|
473
334
|
if (res.ok) {
|
474
335
|
const data = yield res.json();
|
475
336
|
return data;
|
@@ -491,17 +352,9 @@ class DripApi {
|
|
491
352
|
}
|
492
353
|
});
|
493
354
|
}
|
494
|
-
fetchBeansHistory(walletAddress
|
355
|
+
fetchBeansHistory(walletAddress) {
|
495
356
|
return __awaiter(this, void 0, void 0, function* () {
|
496
|
-
const
|
497
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
498
|
-
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
499
|
-
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
500
|
-
}
|
501
|
-
const res = yield fetch(`${this.route}/api-be/api/beans/history/${walletAddress}`, {
|
502
|
-
method: 'GET',
|
503
|
-
headers: reqHeaders,
|
504
|
-
});
|
357
|
+
const res = yield fetch(`${this.route}/api-be/api/user/${walletAddress}/beans/history`);
|
505
358
|
if (res.ok) {
|
506
359
|
const data = yield res.json();
|
507
360
|
const result = data.map((element) => {
|
@@ -525,23 +378,5 @@ class DripApi {
|
|
525
378
|
}
|
526
379
|
});
|
527
380
|
}
|
528
|
-
checkTokenStatus(token) {
|
529
|
-
return __awaiter(this, void 0, void 0, function* () {
|
530
|
-
try {
|
531
|
-
const reqHeaders = new Headers();
|
532
|
-
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
533
|
-
const res = yield fetch(`${this.route}/api-be/auth/validateToken`, {
|
534
|
-
method: 'GET',
|
535
|
-
headers: reqHeaders,
|
536
|
-
});
|
537
|
-
const data = yield res.json();
|
538
|
-
return res.ok ? new AuthenticationStatus_1.ValidStatus(data.address, token) : new AuthenticationStatus_1.ErrorStatus(data.error);
|
539
|
-
}
|
540
|
-
catch (error) {
|
541
|
-
console.log(error);
|
542
|
-
return new AuthenticationStatus_1.ErrorStatus(error === null || error === void 0 ? void 0 : error.message);
|
543
|
-
}
|
544
|
-
});
|
545
|
-
}
|
546
381
|
}
|
547
382
|
exports.default = DripApi;
|
package/dist/DripConfig.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { SDKConfig } from '@spool.fi/spool-v2-sdk';
|
2
2
|
import { Signer } from 'ethers';
|
3
3
|
export declare const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
|
4
|
-
export declare const
|
4
|
+
export declare const PERQ_TOKEN_DECIMALS = 18;
|
5
5
|
export declare enum Chain {
|
6
6
|
MAINNET = "mainnet",
|
7
7
|
SEPOLIA = "sepolia"
|
package/dist/DripConfig.js
CHANGED
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.DripConfig = exports.Chain = exports.
|
12
|
+
exports.DripConfig = exports.Chain = exports.PERQ_TOKEN_DECIMALS = exports.NULL_ADDRESS = void 0;
|
13
13
|
const spool_v2_sdk_1 = require("@spool.fi/spool-v2-sdk");
|
14
14
|
exports.NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
|
15
|
-
exports.
|
15
|
+
exports.PERQ_TOKEN_DECIMALS = 18;
|
16
16
|
var Chain;
|
17
17
|
(function (Chain) {
|
18
18
|
Chain["MAINNET"] = "mainnet";
|
package/dist/DripSdk.d.ts
CHANGED
@@ -12,7 +12,7 @@ import { BeansBalance } from './types/BeansBalance';
|
|
12
12
|
import { PerqToBeansSwapInfo } from './types/PerqToBeansSwapInfo';
|
13
13
|
import BeanEntry from './types/BeanEntry';
|
14
14
|
import { VestingInfo } from './types/VestingInfo';
|
15
|
-
import {
|
15
|
+
import { SignedPayload } from './types/SignedPayload';
|
16
16
|
export default class DripSdk {
|
17
17
|
private dripApi;
|
18
18
|
private dripTokenContract;
|
@@ -28,8 +28,6 @@ export default class DripSdk {
|
|
28
28
|
getVaultStats(): Promise<VaultStats>;
|
29
29
|
getTokenPrice(tokenName: string): Promise<number>;
|
30
30
|
updateSigner(newSigner: Signer): void;
|
31
|
-
isUserAuthenticated(): Promise<AuthenticationStatus>;
|
32
|
-
authenticate(): Promise<boolean>;
|
33
31
|
newDeposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
34
32
|
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
35
33
|
private doDeposit;
|
@@ -37,29 +35,27 @@ export default class DripSdk {
|
|
37
35
|
getTokenAllowanceForRecycler(tokenAddress: string): Promise<BigNumber>;
|
38
36
|
getTokenAllowanceForSwapAndRecycler(tokenAddress: string): Promise<BigNumber>;
|
39
37
|
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>;
|
40
|
-
getUserBalance(
|
41
|
-
getUserBoostedNfts(vaultAddress: string
|
38
|
+
getUserBalance(): Promise<UserBalance>;
|
39
|
+
getUserBoostedNfts(vaultAddress: string): Promise<string[]>;
|
42
40
|
getRewardsPerHour(vaultAddress: string): Promise<number>;
|
43
|
-
getRewards(
|
44
|
-
getMyPerqBalance(
|
45
|
-
getUserVaultBalance(vaultAddress: string
|
41
|
+
getRewards(): Promise<UserRewards>;
|
42
|
+
getMyPerqBalance(): Promise<MyPerqData>;
|
43
|
+
getUserVaultBalance(vaultAddress: string): Promise<UserVaultBalance>;
|
46
44
|
fastWithdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
|
47
45
|
swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
|
48
46
|
newSwapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
|
49
47
|
private doSwapAndDeposit;
|
50
48
|
withdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
|
51
49
|
claimWithdraws(vaultAddress: string): Promise<string>;
|
52
|
-
getVaultsClaimableData(
|
53
|
-
getBeansBalance(
|
54
|
-
getBeansHistory(
|
50
|
+
getVaultsClaimableData(): Promise<VaultClaimData>;
|
51
|
+
getBeansBalance(): Promise<BeansBalance>;
|
52
|
+
getBeansHistory(): Promise<BeanEntry[]>;
|
55
53
|
recycleTokens(tokenAddress: string | undefined, amountToRecycle: string, beneficiary: string | undefined, price: string, deadline: string, signature: string): Promise<string>;
|
56
54
|
swapAndRecycleETH(beneficiary: string, path: string[], minAmountOutWithDecimals: string, amountOfEth: string, price: string, deadline: string, signature: string): Promise<string>;
|
57
55
|
swapAndRecycleERC20(beneficiary: string, path: string[], minAmountOutWithDecimals: string, amountInWithDecimals: string, price: string, deadline: string, signature: string): Promise<string>;
|
58
|
-
upgradeLoyaltyCard(): Promise<LoyaltyCard>;
|
59
|
-
|
60
|
-
getOwnedLoyaltyCards(headers?: Headers): Promise<LoyaltyCard>;
|
56
|
+
upgradeLoyaltyCard(index: number): Promise<LoyaltyCard>;
|
57
|
+
getOwnedLoyaltyCard(): Promise<LoyaltyCard>;
|
61
58
|
getAllLoyaltyCards(): Promise<LoyaltyCard[]>;
|
62
|
-
getLoyaltyCardBoost(rewardId: string, headers?: Headers): Promise<number>;
|
63
59
|
approveTokenForRecycler(tokenAddress: string, amount: string): Promise<string>;
|
64
60
|
approveTokenForSwapAndRecycler(tokenAddress: string, amount: string): Promise<string>;
|
65
61
|
approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<string>;
|
@@ -76,6 +72,7 @@ export default class DripSdk {
|
|
76
72
|
getAllVestingInfo(beneficiaryAddress: string): Promise<VestingInfo>;
|
77
73
|
claimVestedPerq(amount: string): Promise<string>;
|
78
74
|
burnVestedPerq(amount: string, price: string, deadline: string, signature: string): Promise<string>;
|
75
|
+
signPayload<T extends Record<string, unknown>>(payload: T): Promise<SignedPayload<T>>;
|
79
76
|
private generateRedeemBagStruct;
|
80
77
|
private getERC20Precission;
|
81
78
|
private calculatePendingDeposits;
|
package/dist/DripSdk.js
CHANGED
@@ -12,18 +12,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const web3_token_1 = __importDefault(require("web3-token"));
|
16
15
|
const spool_v2_sdk_1 = require("@spool.fi/spool-v2-sdk");
|
17
16
|
const ethers_1 = require("ethers");
|
18
17
|
const DripConfig_1 = require("./DripConfig");
|
19
18
|
const DripApi_1 = __importDefault(require("./DripApi"));
|
20
|
-
const js_cookie_1 = __importDefault(require("js-cookie"));
|
21
19
|
const DripTokenContract_1 = __importDefault(require("./contracts/DripTokenContract"));
|
22
20
|
const DripTokenRecyclerContract_1 = __importDefault(require("./contracts/DripTokenRecyclerContract"));
|
23
21
|
const DripSwapAndRecyclerContract_1 = __importDefault(require("./contracts/DripSwapAndRecyclerContract"));
|
24
22
|
const PerqVestingContract_1 = __importDefault(require("./contracts/PerqVestingContract"));
|
25
23
|
const utils_1 = require("ethers/lib/utils");
|
26
|
-
const AuthenticationStatus_1 = require("./types/AuthenticationStatus");
|
27
24
|
const WethTokenAbi_json_1 = __importDefault(require("./contracts/abi/WethTokenAbi.json"));
|
28
25
|
class DripSdk {
|
29
26
|
constructor(chain, signer, dripRoute) {
|
@@ -64,52 +61,6 @@ class DripSdk {
|
|
64
61
|
this.dripTokenContract.updateSigner(newSigner);
|
65
62
|
this.dripTokenRecyclerContract.updateSigner(newSigner);
|
66
63
|
}
|
67
|
-
isUserAuthenticated() {
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
69
|
-
if (!this.signer) {
|
70
|
-
return { isAuthenticated: false, message: 'Signer not provided' };
|
71
|
-
}
|
72
|
-
const userAddress = yield this.signer.getAddress();
|
73
|
-
const cookieName = `auth_${userAddress.toLowerCase()}`;
|
74
|
-
const authToken = js_cookie_1.default.get(cookieName);
|
75
|
-
return !authToken ? new AuthenticationStatus_1.ErrorStatus('Auth token not found') : yield this.dripApi.checkTokenStatus(authToken);
|
76
|
-
});
|
77
|
-
}
|
78
|
-
authenticate() {
|
79
|
-
return __awaiter(this, void 0, void 0, function* () {
|
80
|
-
try {
|
81
|
-
if (!this.signer) {
|
82
|
-
throw Error('No signer provided');
|
83
|
-
}
|
84
|
-
const address = yield this.signer.getAddress();
|
85
|
-
const cookieName = `auth_${address.toLowerCase()}`;
|
86
|
-
const token = yield web3_token_1.default.sign((message) => __awaiter(this, void 0, void 0, function* () { return yield this.signer.signMessage(message); }), {
|
87
|
-
statement: JSON.stringify({ address, message: 'Please sign in into Perq' }),
|
88
|
-
expires_in: '30d',
|
89
|
-
});
|
90
|
-
const response = yield fetch(`${this.dripConfig.dripRoute}/api-be/auth/verify`, {
|
91
|
-
method: 'POST',
|
92
|
-
headers: {
|
93
|
-
'Content-Type': 'application/json',
|
94
|
-
},
|
95
|
-
body: JSON.stringify({ token }),
|
96
|
-
});
|
97
|
-
const result = yield response.json();
|
98
|
-
if (result.success) {
|
99
|
-
js_cookie_1.default.set(cookieName, result.auth, { expires: 30 });
|
100
|
-
}
|
101
|
-
else {
|
102
|
-
js_cookie_1.default.remove(cookieName);
|
103
|
-
return false;
|
104
|
-
}
|
105
|
-
return true;
|
106
|
-
}
|
107
|
-
catch (error) {
|
108
|
-
console.error('Error obtaining token:', error);
|
109
|
-
}
|
110
|
-
return false;
|
111
|
-
});
|
112
|
-
}
|
113
64
|
newDeposit(tokenAddress, vaultAddress, amount) {
|
114
65
|
return __awaiter(this, void 0, void 0, function* () {
|
115
66
|
return this.doDeposit(tokenAddress, vaultAddress, amount, false);
|
@@ -179,63 +130,49 @@ class DripSdk {
|
|
179
130
|
}
|
180
131
|
getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals) {
|
181
132
|
return __awaiter(this, void 0, void 0, function* () {
|
182
|
-
|
183
|
-
yield this.isUserAuthenticated();
|
184
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
185
|
-
return this.dripApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, userAddress);
|
133
|
+
return this.dripApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals);
|
186
134
|
});
|
187
135
|
}
|
188
|
-
getUserBalance(
|
136
|
+
getUserBalance() {
|
189
137
|
return __awaiter(this, void 0, void 0, function* () {
|
190
138
|
const userAddress = yield this.signer.getAddress();
|
191
|
-
|
192
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
193
|
-
return this.dripApi.getUserBalance(userAddress, authData.token, headers);
|
139
|
+
return this.dripApi.getUserBalance(userAddress);
|
194
140
|
});
|
195
141
|
}
|
196
|
-
getUserBoostedNfts(vaultAddress
|
142
|
+
getUserBoostedNfts(vaultAddress) {
|
197
143
|
return __awaiter(this, void 0, void 0, function* () {
|
198
144
|
const userAddress = yield this.signer.getAddress();
|
199
|
-
|
200
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
201
|
-
return this.dripApi.getUserBoostedNfts(userAddress, vaultAddress, authData.token, headers);
|
145
|
+
return this.dripApi.getUserBoostedNfts(userAddress, vaultAddress);
|
202
146
|
});
|
203
147
|
}
|
204
148
|
getRewardsPerHour(vaultAddress) {
|
205
149
|
return __awaiter(this, void 0, void 0, function* () {
|
206
|
-
const
|
207
|
-
|
208
|
-
return this.dripApi.fetchRewardsPerHour(vaultAddress, authData.token);
|
150
|
+
const userAddress = yield this.signer.getAddress();
|
151
|
+
return this.dripApi.fetchRewardsPerHour(userAddress, vaultAddress);
|
209
152
|
});
|
210
153
|
}
|
211
|
-
getRewards(
|
154
|
+
getRewards() {
|
212
155
|
return __awaiter(this, void 0, void 0, function* () {
|
213
156
|
const userAddress = yield this.signer.getAddress();
|
214
|
-
const
|
215
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
216
|
-
const userRewards = this.dripApi.fetchUserRewards(userAddress, authData.token, headers);
|
157
|
+
const userRewards = this.dripApi.fetchUserRewards(userAddress);
|
217
158
|
return userRewards;
|
218
159
|
});
|
219
160
|
}
|
220
|
-
getMyPerqBalance(
|
161
|
+
getMyPerqBalance() {
|
221
162
|
return __awaiter(this, void 0, void 0, function* () {
|
222
163
|
const userAddress = yield this.signer.getAddress();
|
223
|
-
const
|
224
|
-
const myPerqBalance = this.dripApi.fetchMyPerqData(userAddress, authData.token, headers);
|
164
|
+
const myPerqBalance = this.dripApi.fetchMyPerqData(userAddress);
|
225
165
|
return myPerqBalance;
|
226
166
|
});
|
227
167
|
}
|
228
|
-
getUserVaultBalance(vaultAddress
|
168
|
+
getUserVaultBalance(vaultAddress) {
|
229
169
|
return __awaiter(this, void 0, void 0, function* () {
|
230
170
|
const userAddress = yield this.signer.getAddress();
|
231
|
-
const authData = yield this.isUserAuthenticated();
|
232
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
233
171
|
const vault = yield this.getVaultDetails(vaultAddress);
|
234
|
-
const
|
235
|
-
const
|
236
|
-
const wnfts = yield this.dripApi.fetchAllUserWNFTForVault(vaultAddress, userAddress, token, headers);
|
172
|
+
const dnfts = yield this.dripApi.fetchAllUserDNFTForVault(vaultAddress, userAddress);
|
173
|
+
const wnfts = yield this.dripApi.fetchAllUserWNFTForVault(vaultAddress, userAddress);
|
237
174
|
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
|
238
|
-
const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance] = yield this.calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals
|
175
|
+
const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance] = yield this.calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals);
|
239
176
|
const hasWithdrawsToClaim = this.checkIfUserHasWithdrawsToClaim(wnfts);
|
240
177
|
const pendingDeposits = this.calculatePendingDeposits(dnfts, decimals);
|
241
178
|
const userBalance = this.calculateAllDeposits(dnfts, decimals).sub(pendingDeposits);
|
@@ -255,8 +192,6 @@ class DripSdk {
|
|
255
192
|
throw Error('No signer provided');
|
256
193
|
}
|
257
194
|
const userAddress = yield this.signer.getAddress();
|
258
|
-
// const authData = await this.isUserAuthenticated();
|
259
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
260
195
|
if (!this.signer) {
|
261
196
|
throw Error('No signer provided');
|
262
197
|
}
|
@@ -284,8 +219,6 @@ class DripSdk {
|
|
284
219
|
doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, checkAllowance, ethAmount) {
|
285
220
|
return __awaiter(this, void 0, void 0, function* () {
|
286
221
|
const userAddress = yield this.signer.getAddress();
|
287
|
-
yield this.isUserAuthenticated();
|
288
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
289
222
|
if (!this.signer) {
|
290
223
|
throw Error('No signer provided');
|
291
224
|
}
|
@@ -321,8 +254,6 @@ class DripSdk {
|
|
321
254
|
throw Error('No signer provided');
|
322
255
|
}
|
323
256
|
const userAddress = yield this.signer.getAddress();
|
324
|
-
// const authData = await this.isUserAuthenticated();
|
325
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
326
257
|
if (!this.signer) {
|
327
258
|
throw Error('No signer provided');
|
328
259
|
}
|
@@ -336,12 +267,10 @@ class DripSdk {
|
|
336
267
|
claimWithdraws(vaultAddress) {
|
337
268
|
return __awaiter(this, void 0, void 0, function* () {
|
338
269
|
const userAddress = yield this.signer.getAddress();
|
339
|
-
const authData = yield this.isUserAuthenticated();
|
340
|
-
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
341
270
|
if (!this.signer) {
|
342
271
|
throw Error('No signer provided');
|
343
272
|
}
|
344
|
-
const wnfts = yield this.dripApi.fetchEnrichedUserWNFTForVault(vaultAddress, userAddress
|
273
|
+
const wnfts = yield this.dripApi.fetchEnrichedUserWNFTForVault(vaultAddress, userAddress);
|
345
274
|
//! Shares come as Strings instead of BigNumber from our Backend
|
346
275
|
const nftIds = wnfts
|
347
276
|
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
@@ -354,42 +283,29 @@ class DripSdk {
|
|
354
283
|
return txReceipt.transactionHash;
|
355
284
|
});
|
356
285
|
}
|
357
|
-
getVaultsClaimableData(
|
286
|
+
getVaultsClaimableData() {
|
358
287
|
return __awaiter(this, void 0, void 0, function* () {
|
359
|
-
const authData = yield this.isUserAuthenticated();
|
360
|
-
if (!authData.isAuthenticated) {
|
361
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
362
|
-
}
|
363
288
|
if (!this.signer) {
|
364
289
|
throw Error('No signer provided');
|
365
290
|
}
|
366
|
-
|
291
|
+
const userAddress = yield this.signer.getAddress();
|
292
|
+
return yield this.dripApi.fetchVaultsClaimableData(userAddress);
|
367
293
|
});
|
368
294
|
}
|
369
|
-
getBeansBalance(
|
295
|
+
getBeansBalance() {
|
370
296
|
return __awaiter(this, void 0, void 0, function* () {
|
371
|
-
const
|
372
|
-
|
373
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
374
|
-
}
|
375
|
-
return this.dripApi.fetchBeansBalance(authData.token, headers);
|
297
|
+
const userAddress = yield this.signer.getAddress();
|
298
|
+
return this.dripApi.fetchBeansBalance(userAddress);
|
376
299
|
});
|
377
300
|
}
|
378
|
-
getBeansHistory(
|
301
|
+
getBeansHistory() {
|
379
302
|
return __awaiter(this, void 0, void 0, function* () {
|
380
|
-
const
|
381
|
-
|
382
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
383
|
-
}
|
384
|
-
return this.dripApi.fetchBeansHistory(authData.address, authData.token, headers);
|
303
|
+
const userAddress = yield this.signer.getAddress();
|
304
|
+
return this.dripApi.fetchBeansHistory(userAddress);
|
385
305
|
});
|
386
306
|
}
|
387
307
|
recycleTokens() {
|
388
308
|
return __awaiter(this, arguments, void 0, function* (tokenAddress = this.dripConfig.dripTokenAddress, amountToRecycle, beneficiary = DripConfig_1.NULL_ADDRESS, price, deadline, signature) {
|
389
|
-
const authData = yield this.isUserAuthenticated();
|
390
|
-
if (!authData.isAuthenticated) {
|
391
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
392
|
-
}
|
393
309
|
if (this.dripConfig.dripTokenRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
|
394
310
|
throw Error('Recycler contract address not defined');
|
395
311
|
}
|
@@ -402,10 +318,6 @@ class DripSdk {
|
|
402
318
|
}
|
403
319
|
swapAndRecycleETH(beneficiary, path, minAmountOutWithDecimals, amountOfEth, price, deadline, signature) {
|
404
320
|
return __awaiter(this, void 0, void 0, function* () {
|
405
|
-
const authData = yield this.isUserAuthenticated();
|
406
|
-
if (!authData.isAuthenticated) {
|
407
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
408
|
-
}
|
409
321
|
if (this.dripConfig.dripSwapAndRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
|
410
322
|
throw Error('Recycler contract address not defined');
|
411
323
|
}
|
@@ -416,10 +328,6 @@ class DripSdk {
|
|
416
328
|
}
|
417
329
|
swapAndRecycleERC20(beneficiary, path, minAmountOutWithDecimals, amountInWithDecimals, price, deadline, signature) {
|
418
330
|
return __awaiter(this, void 0, void 0, function* () {
|
419
|
-
const authData = yield this.isUserAuthenticated();
|
420
|
-
if (!authData.isAuthenticated) {
|
421
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
422
|
-
}
|
423
331
|
if (this.dripConfig.dripSwapAndRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
|
424
332
|
throw Error('Recycler contract address not defined');
|
425
333
|
}
|
@@ -437,31 +345,17 @@ class DripSdk {
|
|
437
345
|
return receipt.transactionHash;
|
438
346
|
});
|
439
347
|
}
|
440
|
-
upgradeLoyaltyCard() {
|
348
|
+
upgradeLoyaltyCard(index) {
|
441
349
|
return __awaiter(this, void 0, void 0, function* () {
|
442
|
-
const
|
443
|
-
|
444
|
-
|
445
|
-
}
|
446
|
-
return this.dripApi.upgradeLoyaltyCard(authData.token);
|
350
|
+
const payload = { index };
|
351
|
+
const signedPayload = yield this.signPayload(payload);
|
352
|
+
return this.dripApi.upgradeLoyaltyCard(signedPayload);
|
447
353
|
});
|
448
354
|
}
|
449
|
-
|
355
|
+
getOwnedLoyaltyCard() {
|
450
356
|
return __awaiter(this, void 0, void 0, function* () {
|
451
|
-
const
|
452
|
-
|
453
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
454
|
-
}
|
455
|
-
return this.dripApi.fetchNextLoyaltyCard(authData.token, headers);
|
456
|
-
});
|
457
|
-
}
|
458
|
-
getOwnedLoyaltyCards(headers) {
|
459
|
-
return __awaiter(this, void 0, void 0, function* () {
|
460
|
-
const authData = yield this.isUserAuthenticated();
|
461
|
-
if (!authData.isAuthenticated) {
|
462
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
463
|
-
}
|
464
|
-
return this.dripApi.fetchOwnedLoyaltyCards(authData.token, headers);
|
357
|
+
const signerAddress = yield this.signer.getAddress();
|
358
|
+
return this.dripApi.fetchOwnedLoyaltyCard(signerAddress);
|
465
359
|
});
|
466
360
|
}
|
467
361
|
getAllLoyaltyCards() {
|
@@ -469,15 +363,6 @@ class DripSdk {
|
|
469
363
|
return this.dripApi.fetchAllLoyaltyCards();
|
470
364
|
});
|
471
365
|
}
|
472
|
-
getLoyaltyCardBoost(rewardId, headers) {
|
473
|
-
return __awaiter(this, void 0, void 0, function* () {
|
474
|
-
const authData = yield this.isUserAuthenticated();
|
475
|
-
if (!authData.isAuthenticated) {
|
476
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
477
|
-
}
|
478
|
-
return this.dripApi.getLoyaltyCardBoost(rewardId, authData.token, headers);
|
479
|
-
});
|
480
|
-
}
|
481
366
|
approveTokenForRecycler(tokenAddress, amount) {
|
482
367
|
return __awaiter(this, void 0, void 0, function* () {
|
483
368
|
if (!this.signer) {
|
@@ -669,6 +554,23 @@ class DripSdk {
|
|
669
554
|
}
|
670
555
|
});
|
671
556
|
}
|
557
|
+
signPayload(payload) {
|
558
|
+
return __awaiter(this, void 0, void 0, function* () {
|
559
|
+
if (!this.signer) {
|
560
|
+
throw Error('No signer provided');
|
561
|
+
}
|
562
|
+
const signerAddress = yield this.signer.getAddress();
|
563
|
+
// Create message to sign
|
564
|
+
const message = JSON.stringify(payload);
|
565
|
+
// Sign the message
|
566
|
+
const signature = yield this.signer.signMessage(message);
|
567
|
+
return {
|
568
|
+
signature,
|
569
|
+
signerAddress,
|
570
|
+
payload,
|
571
|
+
};
|
572
|
+
});
|
573
|
+
}
|
672
574
|
generateRedeemBagStruct(vault, signerAddress, amountToWithdraw) {
|
673
575
|
return __awaiter(this, void 0, void 0, function* () {
|
674
576
|
if (!this.spoolSdk) {
|
@@ -734,7 +636,7 @@ class DripSdk {
|
|
734
636
|
.map((item) => item.shares.toString());
|
735
637
|
return nftIds.length !== 0 || nftAmounts.length !== 0;
|
736
638
|
}
|
737
|
-
calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals
|
639
|
+
calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals) {
|
738
640
|
return __awaiter(this, void 0, void 0, function* () {
|
739
641
|
if (!this.signer) {
|
740
642
|
throw Error('No signer provided');
|
@@ -749,8 +651,8 @@ class DripSdk {
|
|
749
651
|
continue;
|
750
652
|
}
|
751
653
|
const currentBlockNumber = wnft.blockNumber - 1;
|
752
|
-
const assetsPerSvtAtBlock = yield this.dripApi.fetchAssetPerSvtAtBlock(vaultAddress.toLowerCase(), currentBlockNumber
|
753
|
-
const estimatedValueOfNFT = ethers_1.BigNumber.from(
|
654
|
+
const assetsPerSvtAtBlock = yield this.dripApi.fetchAssetPerSvtAtBlock(vaultAddress.toLowerCase(), currentBlockNumber);
|
655
|
+
const estimatedValueOfNFT = ethers_1.BigNumber.from(ethers_1.ethers.utils.formatUnits(ethers_1.BigNumber.from(wnft.svtWithdrawn).mul(assetsPerSvtAtBlock), 36).split('.')[0].toString());
|
754
656
|
if (wnft.isDHWFinished) {
|
755
657
|
// Processed and Withdrawable
|
756
658
|
estimatedWithdrawableBalance = estimatedWithdrawableBalance.add(estimatedValueOfNFT);
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import DripSdk from './DripSdk';
|
2
2
|
import { Vault } from './types/Vault';
|
3
3
|
import { VaultReward } from './types/VaultReward';
|
4
|
-
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
5
4
|
import { NFTBoost } from './types/NFTBoost';
|
6
5
|
import { Strategy } from './types/Strategy';
|
7
6
|
import { StretchGoal } from './types/StretchGoal';
|
@@ -15,4 +14,4 @@ import { Chain } from './DripConfig';
|
|
15
14
|
import MyPerqData from './types/MyPerqData';
|
16
15
|
import ELoyaltyCardTier from './types/ELoyaltyCardTier';
|
17
16
|
import BeanEntry from './types/BeanEntry';
|
18
|
-
export { Vault, VaultReward, DripSdk, UserVaultBalance, UserBalance, VaultStats,
|
17
|
+
export { Vault, VaultReward, DripSdk, UserVaultBalance, UserBalance, VaultStats, NFTBoost, Strategy, StretchGoal, SwapInfo, VaultDepositToken, VaultType, MyPerqData, Chain, ELoyaltyCardTier, BeanEntry };
|
package/dist/test.js
CHANGED
@@ -78,10 +78,8 @@ function main() {
|
|
78
78
|
try {
|
79
79
|
// const res = await dripSdk.deposit(usdcTokenAddress,usdcVaultPerq, '1000');
|
80
80
|
// const res = await dripSdk.withdraw(usdcVaultPerq, '1');
|
81
|
-
// await dripSdk.authenticate()
|
82
81
|
// const res = await dripSdk.getDripTokenBalance(account2)
|
83
|
-
// const res = await dripSdk.
|
84
|
-
// const res = await dripSdk.getOwnedLoyaltyCards()
|
82
|
+
// const res = await dripSdk.getOwnedLoyaltyCard()
|
85
83
|
// const res = await dripSdk.getBeansBalance()
|
86
84
|
// const res = await dripSdk.recycleTokens()
|
87
85
|
// const res = await dripSdk.upgradeLoyaltyCard()
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dripfi/drip-sdk",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.20",
|
4
4
|
"description": "Drip SDK",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -12,14 +12,11 @@
|
|
12
12
|
},
|
13
13
|
"dependencies": {
|
14
14
|
"@spool.fi/spool-v2-sdk": "2.0.31",
|
15
|
-
"ethers": "^5.7.2"
|
16
|
-
"js-cookie": "^3.0.5",
|
17
|
-
"web3-token": "^1.0.6"
|
15
|
+
"ethers": "^5.7.2"
|
18
16
|
},
|
19
17
|
"author": "",
|
20
18
|
"license": "ISC",
|
21
19
|
"devDependencies": {
|
22
|
-
"@types/js-cookie": "^3.0.6",
|
23
20
|
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
24
21
|
"@typescript-eslint/parser": "^7.12.0",
|
25
22
|
"eslint": "^8.57.0",
|
@@ -1,18 +0,0 @@
|
|
1
|
-
export interface AuthenticationStatus {
|
2
|
-
message: string;
|
3
|
-
isAuthenticated: boolean;
|
4
|
-
address?: string;
|
5
|
-
token?: string;
|
6
|
-
}
|
7
|
-
export declare class ValidStatus implements AuthenticationStatus {
|
8
|
-
message: string;
|
9
|
-
isAuthenticated: boolean;
|
10
|
-
address: string;
|
11
|
-
token: string;
|
12
|
-
constructor(address: string, token: string);
|
13
|
-
}
|
14
|
-
export declare class ErrorStatus implements AuthenticationStatus {
|
15
|
-
message: string;
|
16
|
-
isAuthenticated: boolean;
|
17
|
-
constructor(message: string);
|
18
|
-
}
|
@@ -1,19 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ErrorStatus = exports.ValidStatus = void 0;
|
4
|
-
class ValidStatus {
|
5
|
-
constructor(address, token) {
|
6
|
-
this.message = 'Valid Token';
|
7
|
-
this.isAuthenticated = true;
|
8
|
-
this.address = address;
|
9
|
-
this.token = token;
|
10
|
-
}
|
11
|
-
}
|
12
|
-
exports.ValidStatus = ValidStatus;
|
13
|
-
class ErrorStatus {
|
14
|
-
constructor(message) {
|
15
|
-
this.isAuthenticated = false;
|
16
|
-
this.message = message;
|
17
|
-
}
|
18
|
-
}
|
19
|
-
exports.ErrorStatus = ErrorStatus;
|