@dripfi/drip-sdk 1.1.27 → 1.1.28
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/DripSdk.d.ts +0 -1
- package/dist/DripSdk.js +28 -59
- package/package.json +2 -2
package/dist/DripSdk.d.ts
CHANGED
@@ -54,7 +54,6 @@ export default class DripSdk {
|
|
54
54
|
approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<string>;
|
55
55
|
approveTokenForDeposit(tokenAddress: string, amount: string): Promise<string>;
|
56
56
|
private generateRedeemBagStruct;
|
57
|
-
private getAllSvts;
|
58
57
|
private getERC20Precission;
|
59
58
|
private calculatePendingDeposits;
|
60
59
|
private calculateAllDeposits;
|
package/dist/DripSdk.js
CHANGED
@@ -229,14 +229,17 @@ class DripSdk {
|
|
229
229
|
fastWithdraw(vaultAddress, amountToWithdraw) {
|
230
230
|
return __awaiter(this, void 0, void 0, function* () {
|
231
231
|
var _a, _b;
|
232
|
+
if (!this.signer) {
|
233
|
+
throw Error('No signer provided');
|
234
|
+
}
|
232
235
|
const userAddress = yield this.signer.getAddress();
|
233
|
-
const authData =
|
236
|
+
// const authData = await this.isUserAuthenticated();
|
234
237
|
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
235
238
|
if (!this.signer) {
|
236
239
|
throw Error('No signer provided');
|
237
240
|
}
|
238
241
|
const vault = yield this.getVaultDetails(vaultAddress);
|
239
|
-
const redeemBagStruct = yield this.generateRedeemBagStruct(
|
242
|
+
const redeemBagStruct = yield this.generateRedeemBagStruct(vault, userAddress, amountToWithdraw);
|
240
243
|
const currentBlockNumber = yield ((_a = this.signer.provider) === null || _a === void 0 ? void 0 : _a.getBlockNumber());
|
241
244
|
if (!currentBlockNumber) {
|
242
245
|
throw Error('Error fetching block number');
|
@@ -292,14 +295,17 @@ class DripSdk {
|
|
292
295
|
}
|
293
296
|
withdraw(vaultAddress, amountToWithdraw) {
|
294
297
|
return __awaiter(this, void 0, void 0, function* () {
|
298
|
+
if (!this.signer) {
|
299
|
+
throw Error('No signer provided');
|
300
|
+
}
|
295
301
|
const userAddress = yield this.signer.getAddress();
|
296
|
-
const authData =
|
302
|
+
// const authData = await this.isUserAuthenticated();
|
297
303
|
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
298
304
|
if (!this.signer) {
|
299
305
|
throw Error('No signer provided');
|
300
306
|
}
|
301
307
|
const vault = yield this.getVaultDetails(vaultAddress);
|
302
|
-
const redeemBagStruct = yield this.generateRedeemBagStruct(
|
308
|
+
const redeemBagStruct = yield this.generateRedeemBagStruct(vault, userAddress, amountToWithdraw);
|
303
309
|
const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct, userAddress, false);
|
304
310
|
const redeemTxReceipt = yield redeemTx.wait();
|
305
311
|
return redeemTxReceipt.transactionHash;
|
@@ -428,62 +434,25 @@ class DripSdk {
|
|
428
434
|
return yield this.approveToken(tokenAddress, amount, smartVaultManagerAddress);
|
429
435
|
});
|
430
436
|
}
|
431
|
-
generateRedeemBagStruct(
|
432
|
-
return __awaiter(this, void 0, void 0, function* () {
|
433
|
-
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress.toLowerCase());
|
434
|
-
const withdrawAll = !amountToWithdraw;
|
435
|
-
const initialAmountToWithdraw = ethers_1.ethers.utils.parseUnits(amountToWithdraw || '0', decimals);
|
436
|
-
let totalAmountToWithdraw = initialAmountToWithdraw;
|
437
|
-
let dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress.toLowerCase(), signerAddress, token);
|
438
|
-
if (dnfts.length === 0) {
|
439
|
-
throw Error('User has no deposits');
|
440
|
-
}
|
441
|
-
dnfts = yield this.getAllSvts(vault.vaultAddress.toLowerCase(), signerAddress, dnfts, token);
|
442
|
-
let shares = ethers_1.BigNumber.from(0);
|
443
|
-
const nftIds = [];
|
444
|
-
const nftAmounts = [];
|
445
|
-
let index = 0;
|
446
|
-
while (dnfts[index] && (totalAmountToWithdraw.gt(0) || withdrawAll)) {
|
447
|
-
const dnft = dnfts[index];
|
448
|
-
const userBalance = this.calculateBalanceForDNFT(dnft, decimals);
|
449
|
-
if (userBalance.gt(0)) {
|
450
|
-
const amountToWithdraw = totalAmountToWithdraw;
|
451
|
-
const userSvts = dnft.svts;
|
452
|
-
let svtsToWithdraw = ethers_1.BigNumber.from(0);
|
453
|
-
let nftAmount = ethers_1.BigNumber.from(0);
|
454
|
-
if (amountToWithdraw.gte(userBalance) || withdrawAll) {
|
455
|
-
nftAmount = dnft.shares;
|
456
|
-
svtsToWithdraw = userSvts;
|
457
|
-
if (!withdrawAll) {
|
458
|
-
totalAmountToWithdraw = totalAmountToWithdraw.sub(userBalance);
|
459
|
-
}
|
460
|
-
}
|
461
|
-
else {
|
462
|
-
nftAmount = amountToWithdraw.mul(dnft.shares).div(userBalance);
|
463
|
-
svtsToWithdraw = nftAmount.mul(userSvts).div(dnft.shares);
|
464
|
-
totalAmountToWithdraw = totalAmountToWithdraw.sub(amountToWithdraw);
|
465
|
-
}
|
466
|
-
shares = shares.add(svtsToWithdraw);
|
467
|
-
nftIds.push(dnft.nftId);
|
468
|
-
nftAmounts.push(nftAmount);
|
469
|
-
}
|
470
|
-
index++;
|
471
|
-
}
|
472
|
-
return {
|
473
|
-
smartVault: vault.vaultAddress.toLowerCase(),
|
474
|
-
shares: shares,
|
475
|
-
nftIds,
|
476
|
-
nftAmounts,
|
477
|
-
};
|
478
|
-
});
|
479
|
-
}
|
480
|
-
getAllSvts(vaultAddress, userAddress, dnfts, token) {
|
437
|
+
generateRedeemBagStruct(vault, signerAddress, amountToWithdraw) {
|
481
438
|
return __awaiter(this, void 0, void 0, function* () {
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
439
|
+
if (!this.spoolSdk) {
|
440
|
+
throw Error('No spool sdk provided');
|
441
|
+
}
|
442
|
+
const isFullWithdraw = !amountToWithdraw;
|
443
|
+
if (isFullWithdraw) {
|
444
|
+
return this.spoolSdk.views.userInfo.getMaxRedeemBag({
|
445
|
+
userAddress: signerAddress.toLowerCase(),
|
446
|
+
vaultAddress: vault.vaultAddress,
|
447
|
+
});
|
448
|
+
}
|
449
|
+
else {
|
450
|
+
return this.spoolSdk.views.userInfo.getMinimumBurnRedeemBag({
|
451
|
+
userAddress: signerAddress.toLowerCase(),
|
452
|
+
vaultAddress: vault.vaultAddress,
|
453
|
+
assetsToWithdraw: [Number(amountToWithdraw)]
|
454
|
+
});
|
455
|
+
}
|
487
456
|
});
|
488
457
|
}
|
489
458
|
getERC20Precission(tokenAddress) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dripfi/drip-sdk",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.28",
|
4
4
|
"description": "Drip SDK",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -11,7 +11,7 @@
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
12
12
|
},
|
13
13
|
"dependencies": {
|
14
|
-
"@spool.fi/spool-v2-sdk": "1.0.
|
14
|
+
"@spool.fi/spool-v2-sdk": "1.0.27",
|
15
15
|
"ethers": "^5.7.2",
|
16
16
|
"js-cookie": "^3.0.5",
|
17
17
|
"web3-token": "^1.0.6"
|