@dripfi/drip-sdk 1.1.9 → 1.1.10
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 +9 -3
- package/dist/DripSdk.js +79 -40
- package/package.json +1 -1
package/dist/DripSdk.d.ts
CHANGED
@@ -20,7 +20,10 @@ export default class DripSdk {
|
|
20
20
|
updateSigner(newSigner: Signer): void;
|
21
21
|
isUserAuthenticated(): Promise<AuthenticationStatus>;
|
22
22
|
authenticate(): Promise<boolean>;
|
23
|
+
newDeposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
23
24
|
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
25
|
+
private doDeposit;
|
26
|
+
getTokenAllowanceForCurrency(tokenAddress: string): Promise<string>;
|
24
27
|
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>;
|
25
28
|
getUserBalance(headers?: Headers): Promise<UserBalance>;
|
26
29
|
getUserBoostedNfts(vaultAddress: string, headers?: Headers): Promise<string[]>;
|
@@ -29,10 +32,14 @@ export default class DripSdk {
|
|
29
32
|
getUserVaultBalance(vaultAddress: string, headers?: Headers): Promise<UserVaultBalance>;
|
30
33
|
fastWithdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
|
31
34
|
swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
|
35
|
+
newSwapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
|
36
|
+
private doSwapAndDeposit;
|
32
37
|
withdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
|
33
38
|
claimWithdraws(vaultAddress: string): Promise<string>;
|
34
39
|
getVaultsClaimableData(headers?: Headers): Promise<VaultClaimData>;
|
35
40
|
private generateOldRedeemBagStruct;
|
41
|
+
approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<void>;
|
42
|
+
approveTokenForDeposit(tokenAddress: string, amount: string): Promise<void>;
|
36
43
|
private generateNewRedeemBagStruct;
|
37
44
|
private getAllSvts;
|
38
45
|
private getERC20Precission;
|
@@ -45,8 +52,7 @@ export default class DripSdk {
|
|
45
52
|
private checkIfUserHasWithdrawsToClaim;
|
46
53
|
private shouldUseNewWithdrawLogic;
|
47
54
|
private calculateAllWithdrawalBalances;
|
48
|
-
private getTokenAllowanceForSwapAndDepositContractAddress;
|
49
|
-
private approveTokenForSwapAndDepositContract;
|
50
55
|
private getTokenAllowanceForDeposit;
|
51
|
-
private
|
56
|
+
private getTokenAllowanceForSwapAndDeposit;
|
57
|
+
private getERC20TokenAllowance;
|
52
58
|
}
|
package/dist/DripSdk.js
CHANGED
@@ -124,19 +124,30 @@ class DripSdk {
|
|
124
124
|
return false;
|
125
125
|
});
|
126
126
|
}
|
127
|
+
newDeposit(tokenAddress, vaultAddress, amount) {
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
129
|
+
return this.doDeposit(tokenAddress, vaultAddress, amount, false);
|
130
|
+
});
|
131
|
+
}
|
127
132
|
deposit(tokenAddress, vaultAddress, amount) {
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
134
|
+
return this.doDeposit(tokenAddress, vaultAddress, amount, true);
|
135
|
+
});
|
136
|
+
}
|
137
|
+
doDeposit(tokenAddress, vaultAddress, amount, checkAllowance) {
|
128
138
|
return __awaiter(this, void 0, void 0, function* () {
|
129
139
|
if (!this.signer) {
|
130
140
|
throw Error('No signer provided');
|
131
141
|
}
|
132
|
-
const currentTokenAllowance = yield this.getTokenAllowanceForDeposit(tokenAddress);
|
133
142
|
const decimals = yield this.getERC20Precission(tokenAddress);
|
134
|
-
const
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
143
|
+
const amountWithDecimals = parseFloat(parseFloat(amount).toFixed(decimals));
|
144
|
+
if (checkAllowance) {
|
145
|
+
const currentTokenAllowance = parseFloat(ethers_1.ethers.utils.formatUnits(yield this.getTokenAllowanceForDeposit(tokenAddress), decimals));
|
146
|
+
if (amountWithDecimals > currentTokenAllowance) {
|
147
|
+
yield this.approveTokenForDeposit(tokenAddress, amountWithDecimals.toString());
|
148
|
+
}
|
139
149
|
}
|
150
|
+
const amountToDeposit = ethers_1.ethers.utils.parseUnits(amountWithDecimals.toString(), decimals);
|
140
151
|
const signerAddress = yield this.signer.getAddress();
|
141
152
|
if (!signerAddress) {
|
142
153
|
throw Error('Error fetching address');
|
@@ -153,10 +164,19 @@ class DripSdk {
|
|
153
164
|
return txReceipt.transactionHash;
|
154
165
|
});
|
155
166
|
}
|
167
|
+
getTokenAllowanceForCurrency(tokenAddress) {
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
169
|
+
if (!this.signer) {
|
170
|
+
throw Error('No signer provided');
|
171
|
+
}
|
172
|
+
const currentTokenAllowance = yield this.getTokenAllowanceForDeposit(tokenAddress);
|
173
|
+
return currentTokenAllowance.toString();
|
174
|
+
});
|
175
|
+
}
|
156
176
|
getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals) {
|
157
177
|
return __awaiter(this, void 0, void 0, function* () {
|
158
178
|
const userAddress = yield this.signer.getAddress();
|
159
|
-
|
179
|
+
yield this.isUserAuthenticated();
|
160
180
|
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
161
181
|
return this.dripApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, userAddress);
|
162
182
|
});
|
@@ -260,22 +280,32 @@ class DripSdk {
|
|
260
280
|
});
|
261
281
|
}
|
262
282
|
swapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
284
|
+
return this.doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, true, ethAmount);
|
285
|
+
});
|
286
|
+
}
|
287
|
+
newSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
|
288
|
+
return __awaiter(this, void 0, void 0, function* () {
|
289
|
+
return this.doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, false, ethAmount);
|
290
|
+
});
|
291
|
+
}
|
292
|
+
doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, checkAllowance, ethAmount) {
|
263
293
|
return __awaiter(this, void 0, void 0, function* () {
|
264
294
|
const userAddress = yield this.signer.getAddress();
|
265
|
-
|
295
|
+
yield this.isUserAuthenticated();
|
266
296
|
// if (!authData.isAuthenticated) {throw Error(`User not authenticated: ${authData.message}`);}
|
267
297
|
if (!this.signer) {
|
268
298
|
throw Error('No signer provided');
|
269
299
|
}
|
270
300
|
const decimals = yield this.getERC20Precission(fromTokenAddress);
|
271
|
-
const
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
yield this.approveTokenForSwapAndDepositContract(fromTokenAddress, fromToken.sub(currentTokenAllowance));
|
301
|
+
const amountWithDecimals = parseFloat(parseFloat(fromTokenAmount).toFixed(decimals));
|
302
|
+
if (amountWithDecimals > 0 && checkAllowance) {
|
303
|
+
const currentTokenAllowance = parseFloat(ethers_1.ethers.utils.formatUnits(yield this.getTokenAllowanceForSwapAndDeposit(fromTokenAddress), decimals));
|
304
|
+
if (amountWithDecimals > currentTokenAllowance) {
|
305
|
+
yield this.approveTokenForSwapAndDeposit(fromTokenAddress, amountWithDecimals.toString());
|
277
306
|
}
|
278
307
|
}
|
308
|
+
const fromToken = ethers_1.ethers.utils.parseUnits(amountWithDecimals.toString(), decimals);
|
279
309
|
const swapInfo = yield this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken, userAddress);
|
280
310
|
const swapDepositBagStruct = {
|
281
311
|
inTokens: [fromTokenAddress],
|
@@ -380,6 +410,32 @@ class DripSdk {
|
|
380
410
|
};
|
381
411
|
});
|
382
412
|
}
|
413
|
+
approveTokenForSwapAndDeposit(tokenAddress, amount) {
|
414
|
+
return __awaiter(this, void 0, void 0, function* () {
|
415
|
+
if (!this.signer) {
|
416
|
+
throw Error('No signer provided');
|
417
|
+
}
|
418
|
+
const decimals = yield this.getERC20Precission(tokenAddress);
|
419
|
+
const amountToApprove = ethers_1.ethers.utils.parseUnits(amount.toString(), decimals);
|
420
|
+
const swapAndDepositContractAddress = yield this.dripConfig.getSwapAndDepositContractAddress(this.signer);
|
421
|
+
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
422
|
+
const approveTx = yield erc20Instance.approve(swapAndDepositContractAddress, amountToApprove);
|
423
|
+
yield approveTx.wait();
|
424
|
+
});
|
425
|
+
}
|
426
|
+
approveTokenForDeposit(tokenAddress, amount) {
|
427
|
+
return __awaiter(this, void 0, void 0, function* () {
|
428
|
+
if (!this.signer) {
|
429
|
+
throw Error('No signer provided');
|
430
|
+
}
|
431
|
+
const decimals = yield this.getERC20Precission(tokenAddress);
|
432
|
+
const amountToApprove = ethers_1.ethers.utils.parseUnits(amount.toString(), decimals);
|
433
|
+
const smartVaultManagerAddress = yield this.dripConfig.getSmartVaultManagerAddress(this.signer);
|
434
|
+
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
435
|
+
const approveTx = yield erc20Instance.approve(smartVaultManagerAddress, amountToApprove);
|
436
|
+
yield approveTx.wait();
|
437
|
+
});
|
438
|
+
}
|
383
439
|
generateNewRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
|
384
440
|
return __awaiter(this, void 0, void 0, function* () {
|
385
441
|
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress.toLowerCase());
|
@@ -555,53 +611,36 @@ class DripSdk {
|
|
555
611
|
return [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance, estimatedWithdrawals];
|
556
612
|
});
|
557
613
|
}
|
558
|
-
|
614
|
+
getTokenAllowanceForDeposit(tokenAddress) {
|
559
615
|
return __awaiter(this, void 0, void 0, function* () {
|
560
616
|
if (!this.signer) {
|
561
617
|
throw Error('No signer provided');
|
562
618
|
}
|
563
|
-
const
|
564
|
-
const
|
565
|
-
const allowance = yield erc20Instance.allowance(userAddress, swapAndDepositAddress);
|
619
|
+
const smartVaultManagerAddress = yield this.dripConfig.getSmartVaultManagerAddress(this.signer);
|
620
|
+
const allowance = yield this.getERC20TokenAllowance(smartVaultManagerAddress, tokenAddress);
|
566
621
|
return allowance;
|
567
622
|
});
|
568
623
|
}
|
569
|
-
|
624
|
+
getTokenAllowanceForSwapAndDeposit(tokenAddress) {
|
570
625
|
return __awaiter(this, void 0, void 0, function* () {
|
571
626
|
if (!this.signer) {
|
572
627
|
throw Error('No signer provided');
|
573
628
|
}
|
574
|
-
const
|
575
|
-
const
|
576
|
-
|
577
|
-
yield approveTx.wait();
|
629
|
+
const swapAndDepositAddress = yield this.dripConfig.getSwapAndDepositContractAddress(this.signer);
|
630
|
+
const allowance = yield this.getERC20TokenAllowance(swapAndDepositAddress, tokenAddress);
|
631
|
+
return allowance;
|
578
632
|
});
|
579
633
|
}
|
580
|
-
|
634
|
+
getERC20TokenAllowance(spender, tokenAddress) {
|
581
635
|
return __awaiter(this, void 0, void 0, function* () {
|
582
636
|
if (!this.signer) {
|
583
637
|
throw Error('No signer provided');
|
584
638
|
}
|
585
639
|
const signerAddress = yield this.signer.getAddress();
|
586
|
-
if (!signerAddress) {
|
587
|
-
throw Error('Error fetching address');
|
588
|
-
}
|
589
640
|
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
590
|
-
const
|
591
|
-
const allowance = yield erc20Instance.allowance(signerAddress, smartVaultManagerAddress);
|
641
|
+
const allowance = yield erc20Instance.allowance(signerAddress, spender);
|
592
642
|
return allowance;
|
593
643
|
});
|
594
644
|
}
|
595
|
-
approveTokenForDeposit(tokenAddress, amount) {
|
596
|
-
return __awaiter(this, void 0, void 0, function* () {
|
597
|
-
if (!this.signer) {
|
598
|
-
throw Error('No signer provided');
|
599
|
-
}
|
600
|
-
const smartVaultManagerAddress = yield this.dripConfig.getSmartVaultManagerAddress(this.signer);
|
601
|
-
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
602
|
-
const approveTx = yield erc20Instance.approve(smartVaultManagerAddress, amount);
|
603
|
-
yield approveTx.wait();
|
604
|
-
});
|
605
|
-
}
|
606
645
|
}
|
607
646
|
exports.default = DripSdk;
|