@dripfi/drip-sdk 1.1.16 → 1.1.17

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.
@@ -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;
@@ -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
- const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
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 { BigNumber, Signer, ethers } from 'ethers';
1
+ import { BigNumber, Signer } from 'ethers';
2
2
  import { DripConfig } from './DripConfig';
3
3
  import { AuthenticationStatus } from './types/AuthenticationStatus';
4
4
  import { UserRewards } from './types/UserRewards';
@@ -41,11 +41,12 @@ 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: BigNumber): Promise<ethers.ContractTransaction>;
44
+ recycleTokens(amount: BigNumber): 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<void>;
49
50
  approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<void>;
50
51
  approveTokenForDeposit(tokenAddress: string, amount: string): Promise<void>;
51
52
  private generateRedeemBagStruct;
package/dist/DripSdk.js CHANGED
@@ -15,6 +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 DripConfig_1 = require("./DripConfig");
18
19
  const utils_1 = require("./utils");
19
20
  const DripApi_1 = __importDefault(require("./DripApi"));
20
21
  const js_cookie_1 = __importDefault(require("js-cookie"));
@@ -345,15 +346,12 @@ class DripSdk {
345
346
  if (!authData.isAuthenticated) {
346
347
  throw Error(`User not authenticated: ${authData.message}`);
347
348
  }
348
- const recyclerContractAddress = this.dripTokenRecyclerContract.getContractAddress();
349
- const allowance = yield this.dripTokenContract.getAllowance(recyclerContractAddress);
350
- if (amount.gt(allowance)) {
351
- const approveTx = yield this.dripTokenContract.approve(recyclerContractAddress, amount);
352
- yield approveTx.wait();
349
+ if (this.dripConfig.dripTokenRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
350
+ throw Error('Recycler contract address not defined');
353
351
  }
354
352
  const recycleTx = yield this.dripTokenRecyclerContract.recycle(amount);
355
- yield recycleTx.wait();
356
- return recycleTx;
353
+ const receipt = yield recycleTx.wait();
354
+ return receipt.transactionHash;
357
355
  });
358
356
  }
359
357
  upgradeLoyaltyCard() {
@@ -392,6 +390,21 @@ class DripSdk {
392
390
  return this.dripApi.fetchAllLoyaltyCards(authData.token, headers);
393
391
  });
394
392
  }
393
+ approveTokenForRecycler(tokenAddress, amount) {
394
+ return __awaiter(this, void 0, void 0, function* () {
395
+ if (!this.signer) {
396
+ throw Error('No signer provided');
397
+ }
398
+ if (this.dripConfig.dripTokenRecyclerAddress === DripConfig_1.NULL_ADDRESS) {
399
+ throw Error('Recycler contract address not defined');
400
+ }
401
+ const decimals = yield this.getERC20Precission(tokenAddress);
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();
406
+ });
407
+ }
395
408
  approveTokenForSwapAndDeposit(tokenAddress, amount) {
396
409
  return __awaiter(this, void 0, void 0, function* () {
397
410
  if (!this.signer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dripfi/drip-sdk",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "description": "Drip SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",