@dripfi/drip-sdk 1.1.16 → 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/DripConfig.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ContractAddresses, SDKConfig } from '@spool.fi/spool-v2-sdk';
|
2
2
|
import { Signer } from 'ethers';
|
3
|
+
export declare const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
|
3
4
|
export declare class DripConfig {
|
4
5
|
internalConfig: SDKConfig;
|
5
6
|
dripRoute: string;
|
package/dist/DripConfig.js
CHANGED
@@ -9,15 +9,15 @@ 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 = void 0;
|
12
|
+
exports.DripConfig = 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
15
|
class DripConfig {
|
16
16
|
constructor(subgraphUrl, priceFeedApiUrl, rewardsUrl, fastRedeemApi, contracts, dripRoute, dripTokenAddress, dripTokenRecyclerAddress) {
|
17
17
|
this.internalConfig = new spool_v2_sdk_1.SDKConfig(subgraphUrl, priceFeedApiUrl, rewardsUrl, fastRedeemApi, contracts);
|
18
18
|
this.dripRoute = dripRoute;
|
19
|
-
this.dripTokenAddress = dripTokenAddress ? dripTokenAddress : NULL_ADDRESS;
|
20
|
-
this.dripTokenRecyclerAddress = dripTokenRecyclerAddress ? dripTokenRecyclerAddress : NULL_ADDRESS;
|
19
|
+
this.dripTokenAddress = dripTokenAddress ? dripTokenAddress : exports.NULL_ADDRESS;
|
20
|
+
this.dripTokenRecyclerAddress = dripTokenRecyclerAddress ? dripTokenRecyclerAddress : exports.NULL_ADDRESS;
|
21
21
|
}
|
22
22
|
getSwapAndDepositContractAddress(signer) {
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
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,19 +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
|
-
|
50
|
-
|
49
|
+
approveTokenForRecycler(tokenAddress: string, amount: string): Promise<string>;
|
50
|
+
approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<string>;
|
51
|
+
approveTokenForDeposit(tokenAddress: string, amount: string): Promise<string>;
|
51
52
|
private generateRedeemBagStruct;
|
52
53
|
private getAllSvts;
|
53
54
|
private getERC20Precission;
|
54
|
-
private calculateFastWithdrawBalancesOld;
|
55
|
-
private calculatePendingDepositsOld;
|
56
|
-
private calculateDepositsOld;
|
57
55
|
private calculatePendingDeposits;
|
58
56
|
private calculateAllDeposits;
|
59
57
|
private calculateBalanceForDNFT;
|
@@ -62,4 +60,5 @@ export default class DripSdk {
|
|
62
60
|
private getTokenAllowanceForDeposit;
|
63
61
|
private getTokenAllowanceForSwapAndDeposit;
|
64
62
|
private getERC20TokenAllowance;
|
63
|
+
private approveToken;
|
65
64
|
}
|
package/dist/DripSdk.js
CHANGED
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
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
|
-
const
|
18
|
+
const DripConfig_1 = require("./DripConfig");
|
19
19
|
const DripApi_1 = __importDefault(require("./DripApi"));
|
20
20
|
const js_cookie_1 = __importDefault(require("js-cookie"));
|
21
21
|
const DripTokenContract_1 = __importDefault(require("./contracts/DripTokenContract"));
|
@@ -345,15 +345,14 @@ class DripSdk {
|
|
345
345
|
if (!authData.isAuthenticated) {
|
346
346
|
throw Error(`User not authenticated: ${authData.message}`);
|
347
347
|
}
|
348
|
-
|
349
|
-
|
350
|
-
if (amount.gt(allowance)) {
|
351
|
-
const approveTx = yield this.dripTokenContract.approve(recyclerContractAddress, amount);
|
352
|
-
yield approveTx.wait();
|
348
|
+
if (this.dripConfig.dripTokenRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
|
349
|
+
throw Error('Recycler contract address not defined');
|
353
350
|
}
|
354
|
-
const
|
355
|
-
|
356
|
-
|
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());
|
354
|
+
const receipt = yield recycleTx.wait();
|
355
|
+
return receipt.transactionHash;
|
357
356
|
});
|
358
357
|
}
|
359
358
|
upgradeLoyaltyCard() {
|
@@ -392,17 +391,24 @@ class DripSdk {
|
|
392
391
|
return this.dripApi.fetchAllLoyaltyCards(authData.token, headers);
|
393
392
|
});
|
394
393
|
}
|
394
|
+
approveTokenForRecycler(tokenAddress, amount) {
|
395
|
+
return __awaiter(this, void 0, void 0, function* () {
|
396
|
+
if (!this.signer) {
|
397
|
+
throw Error('No signer provided');
|
398
|
+
}
|
399
|
+
if (this.dripConfig.dripTokenRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
|
400
|
+
throw Error('Recycler contract address not defined');
|
401
|
+
}
|
402
|
+
return yield this.approveToken(tokenAddress, amount.toString(), this.dripConfig.dripTokenRecyclerAddress);
|
403
|
+
});
|
404
|
+
}
|
395
405
|
approveTokenForSwapAndDeposit(tokenAddress, amount) {
|
396
406
|
return __awaiter(this, void 0, void 0, function* () {
|
397
407
|
if (!this.signer) {
|
398
408
|
throw Error('No signer provided');
|
399
409
|
}
|
400
|
-
const decimals = yield this.getERC20Precission(tokenAddress);
|
401
|
-
const amountToApprove = ethers_1.ethers.utils.parseUnits(amount.toString(), decimals);
|
402
410
|
const swapAndDepositContractAddress = yield this.dripConfig.getSwapAndDepositContractAddress(this.signer);
|
403
|
-
|
404
|
-
const approveTx = yield erc20Instance.approve(swapAndDepositContractAddress, amountToApprove);
|
405
|
-
yield approveTx.wait();
|
411
|
+
return yield this.approveToken(tokenAddress, amount, swapAndDepositContractAddress);
|
406
412
|
});
|
407
413
|
}
|
408
414
|
approveTokenForDeposit(tokenAddress, amount) {
|
@@ -410,12 +416,8 @@ class DripSdk {
|
|
410
416
|
if (!this.signer) {
|
411
417
|
throw Error('No signer provided');
|
412
418
|
}
|
413
|
-
const decimals = yield this.getERC20Precission(tokenAddress);
|
414
|
-
const amountToApprove = ethers_1.ethers.utils.parseUnits(amount.toString(), decimals);
|
415
419
|
const smartVaultManagerAddress = yield this.dripConfig.getSmartVaultManagerAddress(this.signer);
|
416
|
-
|
417
|
-
const approveTx = yield erc20Instance.approve(smartVaultManagerAddress, amountToApprove);
|
418
|
-
yield approveTx.wait();
|
420
|
+
return yield this.approveToken(tokenAddress, amount, smartVaultManagerAddress);
|
419
421
|
});
|
420
422
|
}
|
421
423
|
generateRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
|
@@ -486,39 +488,6 @@ class DripSdk {
|
|
486
488
|
return decimals;
|
487
489
|
});
|
488
490
|
}
|
489
|
-
calculateFastWithdrawBalancesOld(token, vaultAddress, userAddress, decimals, headers) {
|
490
|
-
return __awaiter(this, void 0, void 0, function* () {
|
491
|
-
const fastWithdrawNFTs = yield this.dripApi.fetchFastWithdrawNFTs(vaultAddress, userAddress, token, headers);
|
492
|
-
let fastWithdrawBalance = 0;
|
493
|
-
for (const wnft of fastWithdrawNFTs) {
|
494
|
-
if (wnft.assetsWithdrawn[0].asset && wnft.assetsWithdrawn[0].claimed) {
|
495
|
-
const value = +(0, utils_1.insertDot)(wnft.assetsWithdrawn[0].claimed, decimals);
|
496
|
-
fastWithdrawBalance += value;
|
497
|
-
}
|
498
|
-
}
|
499
|
-
return ethers_1.ethers.utils.parseUnits(fastWithdrawBalance.toFixed(decimals), decimals);
|
500
|
-
});
|
501
|
-
}
|
502
|
-
calculatePendingDepositsOld(dnfts, decimals) {
|
503
|
-
let pendingDeposits = 0;
|
504
|
-
for (const nft of dnfts) {
|
505
|
-
if (nft['assets'] && nft['assets'][0] && !nft.isDHWFinished) {
|
506
|
-
pendingDeposits += nft['assets'][0];
|
507
|
-
}
|
508
|
-
}
|
509
|
-
pendingDeposits = +pendingDeposits.toFixed(decimals);
|
510
|
-
return ethers_1.ethers.utils.parseUnits(pendingDeposits.toString(), decimals);
|
511
|
-
}
|
512
|
-
calculateDepositsOld(dnfts, decimals) {
|
513
|
-
let deposits = 0;
|
514
|
-
for (const nft of dnfts) {
|
515
|
-
if (nft['assets'] && nft['assets'][0] && nft.isDHWFinished) {
|
516
|
-
deposits += nft['assets'][0];
|
517
|
-
}
|
518
|
-
}
|
519
|
-
deposits = +deposits.toFixed(decimals);
|
520
|
-
return ethers_1.ethers.utils.parseUnits(deposits.toString(), decimals);
|
521
|
-
}
|
522
491
|
calculatePendingDeposits(dnfts, decimals) {
|
523
492
|
let pendingDeposits = ethers_1.BigNumber.from(0);
|
524
493
|
for (const nft of dnfts) {
|
@@ -616,5 +585,17 @@ class DripSdk {
|
|
616
585
|
return allowance;
|
617
586
|
});
|
618
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
|
+
}
|
619
600
|
}
|
620
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
|
}
|