@dripfi/drip-sdk 1.1.5 → 1.1.7
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/DripApi.d.ts +2 -0
- package/dist/DripApi.js +14 -0
- package/dist/DripSdk.d.ts +2 -0
- package/dist/DripSdk.js +49 -49
- package/dist/types/VaultClaimData.d.ts +6 -0
- package/dist/types/VaultClaimData.js +2 -0
- package/package.json +1 -1
package/dist/DripApi.d.ts
CHANGED
@@ -5,6 +5,7 @@ import { QLFastRedeem } from './types/QLFastRedeem';
|
|
5
5
|
import { UserRewards } from './types/UserRewards';
|
6
6
|
import { VaultStats } from './types/VaultStats';
|
7
7
|
import { UserBalance } from './types/UserBalance';
|
8
|
+
import { VaultClaimData } from './types/VaultClaimData';
|
8
9
|
export declare const IMPERSONATOR_HEADER = "impersonatorAddress";
|
9
10
|
export default class DripApi {
|
10
11
|
route: string;
|
@@ -28,4 +29,5 @@ export default class DripApi {
|
|
28
29
|
fetchAssetPerSvtAtBlock(vaultAddress: string, blocknumber: number, token: string): Promise<BigNumber>;
|
29
30
|
fetchFastWithdrawNFTs(vaultAddress: string, walletAddress: string, token: string, headers?: Headers): Promise<QLFastRedeem[]>;
|
30
31
|
fetchUserRewards(walletAddress: string, token: string, headers?: Headers): Promise<UserRewards>;
|
32
|
+
fetchVaultsClaimableData(walletAddress: string, token: string, headers?: Headers): Promise<VaultClaimData>;
|
31
33
|
}
|
package/dist/DripApi.js
CHANGED
@@ -252,5 +252,19 @@ class DripApi {
|
|
252
252
|
return data;
|
253
253
|
});
|
254
254
|
}
|
255
|
+
fetchVaultsClaimableData(walletAddress, token, headers) {
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
257
|
+
const reqHeaders = headers ? headers : new Headers();
|
258
|
+
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
259
|
+
if (reqHeaders.has(exports.IMPERSONATOR_HEADER)) {
|
260
|
+
walletAddress = reqHeaders.get(exports.IMPERSONATOR_HEADER);
|
261
|
+
}
|
262
|
+
const res = yield fetch(`${this.route}/api-be/api/user/claimableVaults/${walletAddress}`, {
|
263
|
+
headers: reqHeaders,
|
264
|
+
});
|
265
|
+
const data = yield res.json();
|
266
|
+
return data;
|
267
|
+
});
|
268
|
+
}
|
255
269
|
}
|
256
270
|
exports.default = DripApi;
|
package/dist/DripSdk.d.ts
CHANGED
@@ -5,6 +5,7 @@ import { UserRewards } from './types/UserRewards';
|
|
5
5
|
import { VaultStats } from './types/VaultStats';
|
6
6
|
import { UserBalance } from './types/UserBalance';
|
7
7
|
import { UserVaultBalance } from './types/UserVaultBalance';
|
8
|
+
import { VaultClaimData } from './types/VaultClaimData';
|
8
9
|
import { Vault } from './types/Vault';
|
9
10
|
export default class DripSdk {
|
10
11
|
private dripApi;
|
@@ -30,6 +31,7 @@ export default class DripSdk {
|
|
30
31
|
swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
|
31
32
|
withdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
|
32
33
|
claimWithdraws(vaultAddress: string): Promise<string>;
|
34
|
+
getVaultsClaimableData(headers?: Headers): Promise<VaultClaimData>;
|
33
35
|
private generateOldRedeemBagStruct;
|
34
36
|
private generateNewRedeemBagStruct;
|
35
37
|
private getAllSvts;
|
package/dist/DripSdk.js
CHANGED
@@ -155,63 +155,55 @@ class DripSdk {
|
|
155
155
|
}
|
156
156
|
getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals) {
|
157
157
|
return __awaiter(this, void 0, void 0, function* () {
|
158
|
+
const userAddress = yield this.signer.getAddress();
|
158
159
|
const authData = yield this.isUserAuthenticated();
|
159
|
-
if (!authData.isAuthenticated) {
|
160
|
-
|
161
|
-
}
|
162
|
-
return this.dripApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, authData.token);
|
160
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
161
|
+
return this.dripApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, userAddress);
|
163
162
|
});
|
164
163
|
}
|
165
164
|
getUserBalance(headers) {
|
166
165
|
return __awaiter(this, void 0, void 0, function* () {
|
166
|
+
const userAddress = yield this.signer.getAddress();
|
167
167
|
const authData = yield this.isUserAuthenticated();
|
168
|
-
if (!authData.isAuthenticated) {
|
169
|
-
|
170
|
-
}
|
171
|
-
return this.dripApi.getUserBalance(authData.address, authData.token, headers);
|
168
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
169
|
+
return this.dripApi.getUserBalance(userAddress, authData.token, headers);
|
172
170
|
});
|
173
171
|
}
|
174
172
|
getUserBoostedNfts(vaultAddress, headers) {
|
175
173
|
return __awaiter(this, void 0, void 0, function* () {
|
174
|
+
const userAddress = yield this.signer.getAddress();
|
176
175
|
const authData = yield this.isUserAuthenticated();
|
177
|
-
if (!authData.isAuthenticated) {
|
178
|
-
|
179
|
-
}
|
180
|
-
return this.dripApi.getUserBoostedNfts(authData.address, vaultAddress, authData.token, headers);
|
176
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
177
|
+
return this.dripApi.getUserBoostedNfts(userAddress, vaultAddress, authData.token, headers);
|
181
178
|
});
|
182
179
|
}
|
183
180
|
getRewardsPerHour(vaultAddress) {
|
184
181
|
return __awaiter(this, void 0, void 0, function* () {
|
185
182
|
const authData = yield this.isUserAuthenticated();
|
186
|
-
if (!authData.isAuthenticated) {
|
187
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
188
|
-
}
|
183
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
189
184
|
return this.dripApi.fetchRewardsPerHour(vaultAddress, authData.token);
|
190
185
|
});
|
191
186
|
}
|
192
187
|
getRewards(headers) {
|
193
188
|
return __awaiter(this, void 0, void 0, function* () {
|
189
|
+
const userAddress = yield this.signer.getAddress();
|
194
190
|
const authData = yield this.isUserAuthenticated();
|
195
|
-
if (!authData.isAuthenticated) {
|
196
|
-
|
197
|
-
}
|
198
|
-
const userRewards = this.dripApi.fetchUserRewards(authData.address, authData.token, headers);
|
191
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
192
|
+
const userRewards = this.dripApi.fetchUserRewards(userAddress, authData.token, headers);
|
199
193
|
return userRewards;
|
200
194
|
});
|
201
195
|
}
|
202
196
|
getUserVaultBalance(vaultAddress, headers) {
|
203
197
|
return __awaiter(this, void 0, void 0, function* () {
|
198
|
+
const userAddress = yield this.signer.getAddress();
|
204
199
|
const authData = yield this.isUserAuthenticated();
|
205
|
-
if (!authData.isAuthenticated) {
|
206
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
207
|
-
}
|
200
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
208
201
|
const vault = yield this.getVaultDetails(vaultAddress);
|
209
|
-
const userAddress = authData.address;
|
210
202
|
const token = authData.token;
|
211
203
|
const dnfts = yield this.dripApi.fetchAllUserDNFTForVault(vaultAddress, userAddress, token, headers);
|
212
204
|
const wnfts = yield this.dripApi.fetchAllUserWNFTForVault(vaultAddress, userAddress, token, headers);
|
213
205
|
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
|
214
|
-
if (this.shouldUseNewWithdrawLogic(headers && headers.has(DripApi_1.IMPERSONATOR_HEADER) ? headers.get(DripApi_1.IMPERSONATOR_HEADER) :
|
206
|
+
if (this.shouldUseNewWithdrawLogic(headers && headers.has(DripApi_1.IMPERSONATOR_HEADER) ? headers.get(DripApi_1.IMPERSONATOR_HEADER) : userAddress, vault)) {
|
215
207
|
const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance] = yield this.calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals, token);
|
216
208
|
const hasWithdrawsToClaim = this.checkIfUserHasWithdrawsToClaim(wnfts);
|
217
209
|
const pendingDeposits = this.calculatePendingDeposits(dnfts, decimals);
|
@@ -248,32 +240,30 @@ class DripSdk {
|
|
248
240
|
fastWithdraw(vaultAddress, amountToWithdraw) {
|
249
241
|
return __awaiter(this, void 0, void 0, function* () {
|
250
242
|
var _a, _b;
|
243
|
+
const userAddress = yield this.signer.getAddress();
|
251
244
|
const authData = yield this.isUserAuthenticated();
|
252
|
-
if (!authData.isAuthenticated) {
|
253
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
254
|
-
}
|
245
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
255
246
|
if (!this.signer) {
|
256
247
|
throw Error('No signer provided');
|
257
248
|
}
|
258
249
|
const vault = yield this.getVaultDetails(vaultAddress);
|
259
|
-
const redeemBagStruct = this.shouldUseNewWithdrawLogic(
|
260
|
-
? yield this.generateNewRedeemBagStruct(authData.token, vault,
|
261
|
-
: yield this.generateOldRedeemBagStruct(authData.token, vault,
|
250
|
+
const redeemBagStruct = this.shouldUseNewWithdrawLogic(userAddress, vault)
|
251
|
+
? yield this.generateNewRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw)
|
252
|
+
: yield this.generateOldRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw);
|
262
253
|
const currentBlockNumber = yield ((_a = this.signer.provider) === null || _a === void 0 ? void 0 : _a.getBlockNumber());
|
263
254
|
if (!currentBlockNumber) {
|
264
255
|
throw Error('Error fetching block number');
|
265
256
|
}
|
266
|
-
const redeemTx = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.redeemFast(redeemBagStruct,
|
257
|
+
const redeemTx = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.redeemFast(redeemBagStruct, userAddress, currentBlockNumber));
|
267
258
|
const txReceipt = yield redeemTx.wait();
|
268
259
|
return txReceipt.transactionHash;
|
269
260
|
});
|
270
261
|
}
|
271
262
|
swapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
|
272
263
|
return __awaiter(this, void 0, void 0, function* () {
|
264
|
+
const userAddress = yield this.signer.getAddress();
|
273
265
|
const authData = yield this.isUserAuthenticated();
|
274
|
-
if (!authData.isAuthenticated) {
|
275
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
276
|
-
}
|
266
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
277
267
|
if (!this.signer) {
|
278
268
|
throw Error('No signer provided');
|
279
269
|
}
|
@@ -281,18 +271,18 @@ class DripSdk {
|
|
281
271
|
const amountToWithdrawFixedDecimals = parseFloat(fromTokenAmount).toFixed(decimals);
|
282
272
|
const fromToken = ethers_1.ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals);
|
283
273
|
if (fromToken.gt(ethers_1.BigNumber.from(0))) {
|
284
|
-
const currentTokenAllowance = yield this.getTokenAllowanceForSwapAndDepositContractAddress(fromTokenAddress,
|
274
|
+
const currentTokenAllowance = yield this.getTokenAllowanceForSwapAndDepositContractAddress(fromTokenAddress, userAddress);
|
285
275
|
if (fromToken.gt(currentTokenAllowance)) {
|
286
276
|
yield this.approveTokenForSwapAndDepositContract(fromTokenAddress, fromToken.sub(currentTokenAllowance));
|
287
277
|
}
|
288
278
|
}
|
289
|
-
const swapInfo = yield this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken,
|
279
|
+
const swapInfo = yield this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken, userAddress);
|
290
280
|
const swapDepositBagStruct = {
|
291
281
|
inTokens: [fromTokenAddress],
|
292
282
|
inAmounts: [fromToken],
|
293
283
|
smartVault: vaultAddress,
|
294
284
|
swapInfo,
|
295
|
-
receiver:
|
285
|
+
receiver: userAddress,
|
296
286
|
referral: ethers_1.ethers.constants.AddressZero,
|
297
287
|
doFlush: false,
|
298
288
|
};
|
@@ -305,32 +295,30 @@ class DripSdk {
|
|
305
295
|
}
|
306
296
|
withdraw(vaultAddress, amountToWithdraw) {
|
307
297
|
return __awaiter(this, void 0, void 0, function* () {
|
298
|
+
const userAddress = yield this.signer.getAddress();
|
308
299
|
const authData = yield this.isUserAuthenticated();
|
309
|
-
if (!authData.isAuthenticated) {
|
310
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
311
|
-
}
|
300
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
312
301
|
if (!this.signer) {
|
313
302
|
throw Error('No signer provided');
|
314
303
|
}
|
315
304
|
const vault = yield this.getVaultDetails(vaultAddress);
|
316
|
-
const redeemBagStruct = this.shouldUseNewWithdrawLogic(
|
317
|
-
? yield this.generateNewRedeemBagStruct(authData.token, vault,
|
318
|
-
: yield this.generateOldRedeemBagStruct(authData.token, vault,
|
319
|
-
const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct,
|
305
|
+
const redeemBagStruct = this.shouldUseNewWithdrawLogic(userAddress, vault)
|
306
|
+
? yield this.generateNewRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw)
|
307
|
+
: yield this.generateOldRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw);
|
308
|
+
const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct, userAddress, false);
|
320
309
|
const redeemTxReceipt = yield redeemTx.wait();
|
321
310
|
return redeemTxReceipt.transactionHash;
|
322
311
|
});
|
323
312
|
}
|
324
313
|
claimWithdraws(vaultAddress) {
|
325
314
|
return __awaiter(this, void 0, void 0, function* () {
|
315
|
+
const userAddress = yield this.signer.getAddress();
|
326
316
|
const authData = yield this.isUserAuthenticated();
|
327
|
-
if (!authData.isAuthenticated) {
|
328
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
329
|
-
}
|
317
|
+
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
330
318
|
if (!this.signer) {
|
331
319
|
throw Error('No signer provided');
|
332
320
|
}
|
333
|
-
const wnfts = yield this.dripApi.fetchEnrichedUserWNFTForVault(vaultAddress,
|
321
|
+
const wnfts = yield this.dripApi.fetchEnrichedUserWNFTForVault(vaultAddress, userAddress, authData.token);
|
334
322
|
//! Shares come as Strings instead of BigNumber from our Backend
|
335
323
|
const nftIds = wnfts
|
336
324
|
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
@@ -338,11 +326,23 @@ class DripSdk {
|
|
338
326
|
const nftAmounts = wnfts
|
339
327
|
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
340
328
|
.map((item) => item.shares.toString());
|
341
|
-
const claimWithdrawTx = yield this.spoolSdk.claimWithdrawal(vaultAddress, nftIds, nftAmounts,
|
329
|
+
const claimWithdrawTx = yield this.spoolSdk.claimWithdrawal(vaultAddress, nftIds, nftAmounts, userAddress);
|
342
330
|
const txReceipt = yield claimWithdrawTx.wait();
|
343
331
|
return txReceipt.transactionHash;
|
344
332
|
});
|
345
333
|
}
|
334
|
+
getVaultsClaimableData(headers) {
|
335
|
+
return __awaiter(this, void 0, void 0, function* () {
|
336
|
+
const authData = yield this.isUserAuthenticated();
|
337
|
+
if (!authData.isAuthenticated) {
|
338
|
+
throw Error(`User not authenticated: ${authData.message}`);
|
339
|
+
}
|
340
|
+
if (!this.signer) {
|
341
|
+
throw Error('No signer provided');
|
342
|
+
}
|
343
|
+
return yield this.dripApi.fetchVaultsClaimableData(authData.address, authData.token, headers);
|
344
|
+
});
|
345
|
+
}
|
346
346
|
generateOldRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
|
347
347
|
return __awaiter(this, void 0, void 0, function* () {
|
348
348
|
const dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress, signerAddress, token);
|