@dripfi/drip-sdk 1.1.17 → 1.1.18
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
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Signer } from 'ethers';
|
2
2
|
import { DripConfig } from './DripConfig';
|
3
3
|
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
4
4
|
import { UserRewards } from './types/UserRewards';
|
@@ -41,20 +41,17 @@ export default class DripSdk {
|
|
41
41
|
claimWithdraws(vaultAddress: string): Promise<string>;
|
42
42
|
getVaultsClaimableData(headers?: Headers): Promise<VaultClaimData>;
|
43
43
|
getBeansBalance(walletAddress: string, headers?: Headers): Promise<any>;
|
44
|
-
recycleTokens(amount:
|
44
|
+
recycleTokens(amount: string): Promise<string>;
|
45
45
|
upgradeLoyaltyCard(): Promise<LoyaltyCard>;
|
46
46
|
getNextLoyaltyCard(headers?: Headers): Promise<LoyaltyCard>;
|
47
47
|
getOwnedLoyaltyCards(headers?: Headers): Promise<LoyaltyCard>;
|
48
48
|
getAllLoyaltyCards(headers?: Headers): Promise<LoyaltyCard[]>;
|
49
|
-
approveTokenForRecycler(tokenAddress: string, amount: string): Promise<
|
50
|
-
approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<
|
51
|
-
approveTokenForDeposit(tokenAddress: string, amount: string): Promise<
|
49
|
+
approveTokenForRecycler(tokenAddress: string, amount: string): Promise<string>;
|
50
|
+
approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<string>;
|
51
|
+
approveTokenForDeposit(tokenAddress: string, amount: string): Promise<string>;
|
52
52
|
private generateRedeemBagStruct;
|
53
53
|
private getAllSvts;
|
54
54
|
private getERC20Precission;
|
55
|
-
private calculateFastWithdrawBalancesOld;
|
56
|
-
private calculatePendingDepositsOld;
|
57
|
-
private calculateDepositsOld;
|
58
55
|
private calculatePendingDeposits;
|
59
56
|
private calculateAllDeposits;
|
60
57
|
private calculateBalanceForDNFT;
|
@@ -63,4 +60,5 @@ export default class DripSdk {
|
|
63
60
|
private getTokenAllowanceForDeposit;
|
64
61
|
private getTokenAllowanceForSwapAndDeposit;
|
65
62
|
private getERC20TokenAllowance;
|
63
|
+
private approveToken;
|
66
64
|
}
|
package/dist/DripSdk.js
CHANGED
@@ -16,7 +16,6 @@ const web3_token_1 = __importDefault(require("web3-token"));
|
|
16
16
|
const spool_v2_sdk_1 = require("@spool.fi/spool-v2-sdk");
|
17
17
|
const ethers_1 = require("ethers");
|
18
18
|
const DripConfig_1 = require("./DripConfig");
|
19
|
-
const utils_1 = require("./utils");
|
20
19
|
const DripApi_1 = __importDefault(require("./DripApi"));
|
21
20
|
const js_cookie_1 = __importDefault(require("js-cookie"));
|
22
21
|
const DripTokenContract_1 = __importDefault(require("./contracts/DripTokenContract"));
|
@@ -349,7 +348,9 @@ class DripSdk {
|
|
349
348
|
if (this.dripConfig.dripTokenRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
|
350
349
|
throw Error('Recycler contract address not defined');
|
351
350
|
}
|
352
|
-
const
|
351
|
+
const decimals = yield this.getERC20Precission(this.dripConfig.dripTokenAddress);
|
352
|
+
const amountWithDecimals = parseFloat(parseFloat(amount).toFixed(decimals));
|
353
|
+
const recycleTx = yield this.dripTokenRecyclerContract.recycle(amountWithDecimals.toString());
|
353
354
|
const receipt = yield recycleTx.wait();
|
354
355
|
return receipt.transactionHash;
|
355
356
|
});
|
@@ -398,11 +399,7 @@ class DripSdk {
|
|
398
399
|
if (this.dripConfig.dripTokenRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
|
399
400
|
throw Error('Recycler contract address not defined');
|
400
401
|
}
|
401
|
-
|
402
|
-
const amountToApprove = ethers_1.ethers.utils.parseUnits(amount.toString(), decimals);
|
403
|
-
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
404
|
-
const approveTx = yield erc20Instance.approve(this.dripConfig.dripTokenRecyclerAddress, amountToApprove);
|
405
|
-
yield approveTx.wait();
|
402
|
+
return yield this.approveToken(tokenAddress, amount.toString(), this.dripConfig.dripTokenRecyclerAddress);
|
406
403
|
});
|
407
404
|
}
|
408
405
|
approveTokenForSwapAndDeposit(tokenAddress, amount) {
|
@@ -410,12 +407,8 @@ class DripSdk {
|
|
410
407
|
if (!this.signer) {
|
411
408
|
throw Error('No signer provided');
|
412
409
|
}
|
413
|
-
const decimals = yield this.getERC20Precission(tokenAddress);
|
414
|
-
const amountToApprove = ethers_1.ethers.utils.parseUnits(amount.toString(), decimals);
|
415
410
|
const swapAndDepositContractAddress = yield this.dripConfig.getSwapAndDepositContractAddress(this.signer);
|
416
|
-
|
417
|
-
const approveTx = yield erc20Instance.approve(swapAndDepositContractAddress, amountToApprove);
|
418
|
-
yield approveTx.wait();
|
411
|
+
return yield this.approveToken(tokenAddress, amount, swapAndDepositContractAddress);
|
419
412
|
});
|
420
413
|
}
|
421
414
|
approveTokenForDeposit(tokenAddress, amount) {
|
@@ -423,12 +416,8 @@ class DripSdk {
|
|
423
416
|
if (!this.signer) {
|
424
417
|
throw Error('No signer provided');
|
425
418
|
}
|
426
|
-
const decimals = yield this.getERC20Precission(tokenAddress);
|
427
|
-
const amountToApprove = ethers_1.ethers.utils.parseUnits(amount.toString(), decimals);
|
428
419
|
const smartVaultManagerAddress = yield this.dripConfig.getSmartVaultManagerAddress(this.signer);
|
429
|
-
|
430
|
-
const approveTx = yield erc20Instance.approve(smartVaultManagerAddress, amountToApprove);
|
431
|
-
yield approveTx.wait();
|
420
|
+
return yield this.approveToken(tokenAddress, amount, smartVaultManagerAddress);
|
432
421
|
});
|
433
422
|
}
|
434
423
|
generateRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
|
@@ -499,39 +488,6 @@ class DripSdk {
|
|
499
488
|
return decimals;
|
500
489
|
});
|
501
490
|
}
|
502
|
-
calculateFastWithdrawBalancesOld(token, vaultAddress, userAddress, decimals, headers) {
|
503
|
-
return __awaiter(this, void 0, void 0, function* () {
|
504
|
-
const fastWithdrawNFTs = yield this.dripApi.fetchFastWithdrawNFTs(vaultAddress, userAddress, token, headers);
|
505
|
-
let fastWithdrawBalance = 0;
|
506
|
-
for (const wnft of fastWithdrawNFTs) {
|
507
|
-
if (wnft.assetsWithdrawn[0].asset && wnft.assetsWithdrawn[0].claimed) {
|
508
|
-
const value = +(0, utils_1.insertDot)(wnft.assetsWithdrawn[0].claimed, decimals);
|
509
|
-
fastWithdrawBalance += value;
|
510
|
-
}
|
511
|
-
}
|
512
|
-
return ethers_1.ethers.utils.parseUnits(fastWithdrawBalance.toFixed(decimals), decimals);
|
513
|
-
});
|
514
|
-
}
|
515
|
-
calculatePendingDepositsOld(dnfts, decimals) {
|
516
|
-
let pendingDeposits = 0;
|
517
|
-
for (const nft of dnfts) {
|
518
|
-
if (nft['assets'] && nft['assets'][0] && !nft.isDHWFinished) {
|
519
|
-
pendingDeposits += nft['assets'][0];
|
520
|
-
}
|
521
|
-
}
|
522
|
-
pendingDeposits = +pendingDeposits.toFixed(decimals);
|
523
|
-
return ethers_1.ethers.utils.parseUnits(pendingDeposits.toString(), decimals);
|
524
|
-
}
|
525
|
-
calculateDepositsOld(dnfts, decimals) {
|
526
|
-
let deposits = 0;
|
527
|
-
for (const nft of dnfts) {
|
528
|
-
if (nft['assets'] && nft['assets'][0] && nft.isDHWFinished) {
|
529
|
-
deposits += nft['assets'][0];
|
530
|
-
}
|
531
|
-
}
|
532
|
-
deposits = +deposits.toFixed(decimals);
|
533
|
-
return ethers_1.ethers.utils.parseUnits(deposits.toString(), decimals);
|
534
|
-
}
|
535
491
|
calculatePendingDeposits(dnfts, decimals) {
|
536
492
|
let pendingDeposits = ethers_1.BigNumber.from(0);
|
537
493
|
for (const nft of dnfts) {
|
@@ -629,5 +585,17 @@ class DripSdk {
|
|
629
585
|
return allowance;
|
630
586
|
});
|
631
587
|
}
|
588
|
+
approveToken(tokenAddress, amount, spender) {
|
589
|
+
return __awaiter(this, void 0, void 0, function* () {
|
590
|
+
if (!this.signer) {
|
591
|
+
throw Error('No signer provided');
|
592
|
+
}
|
593
|
+
const decimals = yield this.getERC20Precission(tokenAddress);
|
594
|
+
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
595
|
+
const approveTx = yield erc20Instance.approve(spender, ethers_1.ethers.utils.parseUnits(amount, decimals));
|
596
|
+
const receipt = yield approveTx.wait();
|
597
|
+
return receipt.transactionHash;
|
598
|
+
});
|
599
|
+
}
|
632
600
|
}
|
633
601
|
exports.default = DripSdk;
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { ContractTransaction, ethers } from 'ethers';
|
2
2
|
import BaseDripContract from './BaseDripContract';
|
3
3
|
export default class DripTokenRecyclerContract extends BaseDripContract {
|
4
4
|
constructor(address: string, signer?: ethers.Signer);
|
5
|
-
recycle(amount:
|
5
|
+
recycle(amount: string): Promise<ContractTransaction>;
|
6
6
|
}
|
@@ -24,7 +24,7 @@ class DripTokenRecyclerContract extends BaseDripContract_1.default {
|
|
24
24
|
if (!this.contract.signer) {
|
25
25
|
throw Error('No signer provided');
|
26
26
|
}
|
27
|
-
return yield this.contract.recycle(amount
|
27
|
+
return yield this.contract.recycle(amount);
|
28
28
|
});
|
29
29
|
}
|
30
30
|
}
|