@dripfi/drip-sdk 1.1.10 → 1.1.12

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/README.md CHANGED
@@ -202,7 +202,6 @@ type Vault = {
202
202
  hasPoolEnded: boolean
203
203
  boosters: NFTBoost[]
204
204
  strategies: Strategy[]
205
- newWithdraw: boolean
206
205
  tgePrice?: number
207
206
  maxAmountOfTokens?: number
208
207
  project: DeployedProject
package/dist/DripApi.js CHANGED
@@ -21,18 +21,25 @@ class DripApi {
21
21
  fetchAllVaults() {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  const res = yield fetch(`${this.route}/api-be/api/vault`);
24
- const data = (yield res.json());
25
- return data;
24
+ if (res.ok) {
25
+ const data = (yield res.json());
26
+ return data;
27
+ }
28
+ else {
29
+ throw Error(`${yield res.text()}`);
30
+ }
26
31
  });
27
32
  }
28
33
  fetchTokenPrice(tokenName) {
29
34
  return __awaiter(this, void 0, void 0, function* () {
30
35
  const res = yield fetch(`${this.route}/api-be/api/tokenPrice?tokenName=${tokenName}`);
31
- if (!res.ok) {
32
- throw Error(yield res.text());
36
+ if (res.ok) {
37
+ const data = yield res.json();
38
+ return data.usdPricePerToken;
39
+ }
40
+ else {
41
+ throw Error(`${yield res.text()}`);
33
42
  }
34
- const data = yield res.json();
35
- return data.usdPricePerToken;
36
43
  });
37
44
  }
38
45
  getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, token) {
@@ -48,12 +55,12 @@ class DripApi {
48
55
  const res = yield fetch(`${this.route}/api-be/api/1inch/swap?${queryParams}`, {
49
56
  headers,
50
57
  });
51
- const data = yield res.json();
52
58
  if (res.ok) {
59
+ const data = yield res.json();
53
60
  return data;
54
61
  }
55
62
  else {
56
- throw new Error(`HTTP error! status: ${res.status}`);
63
+ throw Error(`${yield res.text()}`);
57
64
  }
58
65
  });
59
66
  }
@@ -67,8 +74,13 @@ class DripApi {
67
74
  const res = yield fetch(`${this.route}/api-be/api/user/deposits/${walletAddress}`, {
68
75
  headers: reqHeaders,
69
76
  });
70
- const data = yield res.json();
71
- return data;
77
+ if (res.ok) {
78
+ const data = yield res.json();
79
+ return data;
80
+ }
81
+ else {
82
+ throw Error(`${yield res.text()}`);
83
+ }
72
84
  });
73
85
  }
74
86
  getUserBoostedNfts(walletAddress, vaultAddress, token, headers) {
@@ -81,22 +93,37 @@ class DripApi {
81
93
  const res = yield fetch(`${this.route}/api-be/api/user/nftBoost/${walletAddress}/${vaultAddress}`, {
82
94
  headers: reqHeaders,
83
95
  });
84
- const data = yield res.json();
85
- return data;
96
+ if (res.ok) {
97
+ const data = yield res.json();
98
+ return data;
99
+ }
100
+ else {
101
+ throw Error(`${yield res.text()}`);
102
+ }
86
103
  });
87
104
  }
88
105
  fetchVaultStats() {
89
106
  return __awaiter(this, void 0, void 0, function* () {
90
107
  const res = yield fetch(`${this.route}/api-be/api/vaultStats`);
91
- const data = yield res.json();
92
- return data;
108
+ if (res.ok) {
109
+ const data = yield res.json();
110
+ return data;
111
+ }
112
+ else {
113
+ throw Error(`${yield res.text()}`);
114
+ }
93
115
  });
94
116
  }
95
117
  fetchVaultDetails(vaultAddress) {
96
118
  return __awaiter(this, void 0, void 0, function* () {
97
119
  const res = yield fetch(`${this.route}/api-be/api/vault/${vaultAddress}`);
98
- const data = (yield res.json());
99
- return data;
120
+ if (res.ok) {
121
+ const data = (yield res.json());
122
+ return data;
123
+ }
124
+ else {
125
+ throw Error(`${yield res.text()}`);
126
+ }
100
127
  });
101
128
  }
102
129
  fetchRewardsPerHour(vaultAddress, token) {
@@ -106,11 +133,13 @@ class DripApi {
106
133
  const res = yield fetch(`${this.route}/api-be/api/user/rewardsPerHour/${vaultAddress}`, {
107
134
  headers,
108
135
  });
109
- if (!res.ok) {
110
- throw Error(yield res.text());
136
+ if (res.ok) {
137
+ const data = yield res.json();
138
+ return data.rewardsPerHour;
139
+ }
140
+ else {
141
+ throw Error(`${yield res.text()}`);
111
142
  }
112
- const data = yield res.json();
113
- return data.rewardsPerHour;
114
143
  });
115
144
  }
116
145
  getSwapInfo(fromTokenAddress, toTokenAddress, amount, fromAddress) {
@@ -120,14 +149,19 @@ class DripApi {
120
149
  }
121
150
  const url = `${this.route}/oneinch?getRequest=/swap/v5.2/1/swap?fromTokenAddress=${fromTokenAddress}%26toTokenAddress=${toTokenAddress}%26amount=${amount.toString()}%26fromAddress=${fromAddress}%26slippage=0.1%26disableEstimate=true%26allowPartialFill=false%26includeTokensInfo=true`;
122
151
  const res = yield fetch(url);
123
- const data = (yield res.json());
124
- return [
125
- {
126
- swapTarget: data.tx.to,
127
- token: data.fromToken.address,
128
- swapCallData: data.tx.data,
129
- },
130
- ];
152
+ if (res.ok) {
153
+ const data = (yield res.json());
154
+ return [
155
+ {
156
+ swapTarget: data.tx.to,
157
+ token: data.fromToken.address,
158
+ swapCallData: data.tx.data,
159
+ },
160
+ ];
161
+ }
162
+ else {
163
+ throw Error(`${yield res.text()}`);
164
+ }
131
165
  });
132
166
  }
133
167
  fetchUserSVTBalance(vaultAddress, walletAddress, token) {
@@ -137,8 +171,13 @@ class DripApi {
137
171
  const res = yield fetch(`${this.route}/api-be/api/spool/user/svtBalance/${walletAddress}/${vaultAddress}`, {
138
172
  headers,
139
173
  });
140
- const data = (yield res.json());
141
- return data;
174
+ if (res.ok) {
175
+ const data = (yield res.json());
176
+ return data;
177
+ }
178
+ else {
179
+ throw Error(`${yield res.text()}`);
180
+ }
142
181
  });
143
182
  }
144
183
  fetchUserBalance(vaultAddress, walletAddress, token) {
@@ -148,8 +187,13 @@ class DripApi {
148
187
  const res = yield fetch(`${this.route}/api-be/api/spool/userBalance/${walletAddress}/${vaultAddress}`, {
149
188
  headers,
150
189
  });
151
- const data = (yield res.json());
152
- return data;
190
+ if (res.ok) {
191
+ const data = (yield res.json());
192
+ return data;
193
+ }
194
+ else {
195
+ throw Error(`${yield res.text()}`);
196
+ }
153
197
  });
154
198
  }
155
199
  fetchEnrichedUserDNFTForVault(vaultAddress, walletAddress, token) {
@@ -159,8 +203,13 @@ class DripApi {
159
203
  const res = yield fetch(`${this.route}/api-be/api/spool/user/dNft/${walletAddress}/${vaultAddress}`, {
160
204
  headers,
161
205
  });
162
- const data = yield res.json();
163
- return data;
206
+ if (res.ok) {
207
+ const data = yield res.json();
208
+ return data;
209
+ }
210
+ else {
211
+ throw Error(`${yield res.text()}`);
212
+ }
164
213
  });
165
214
  }
166
215
  fetchEnrichedUserWNFTForVault(vaultAddress, walletAddress, token) {
@@ -170,8 +219,13 @@ class DripApi {
170
219
  const res = yield fetch(`${this.route}/api-be/api/spool/user/wNft/${walletAddress}/${vaultAddress}`, {
171
220
  headers,
172
221
  });
173
- const data = yield res.json();
174
- return data;
222
+ if (res.ok) {
223
+ const data = yield res.json();
224
+ return data;
225
+ }
226
+ else {
227
+ throw Error(`${yield res.text()}`);
228
+ }
175
229
  });
176
230
  }
177
231
  fetchUserSVTFromNfts(vaultAddress, userAddress, dnfts, token) {
@@ -181,8 +235,13 @@ class DripApi {
181
235
  const res = yield fetch(`${this.route}/api-be/api/spool/user/svtFromNft/${userAddress}/${vaultAddress}?dnfts=${dnfts.join(',')}`, {
182
236
  headers,
183
237
  });
184
- const data = (yield res.json());
185
- return data;
238
+ if (res.ok) {
239
+ const data = (yield res.json());
240
+ return data;
241
+ }
242
+ else {
243
+ throw Error(`${yield res.text()}`);
244
+ }
186
245
  });
187
246
  }
188
247
  fetchAllUserWNFTForVault(vaultAddress, walletAddress, token, headers) {
@@ -195,8 +254,13 @@ class DripApi {
195
254
  const res = yield fetch(`${this.route}/api-be/api/spool/user/allWnft/${walletAddress}/${vaultAddress}`, {
196
255
  headers: reqHeaders,
197
256
  });
198
- const data = (yield res.json());
199
- return data;
257
+ if (res.ok) {
258
+ const data = (yield res.json());
259
+ return data;
260
+ }
261
+ else {
262
+ throw Error(`${yield res.text()}`);
263
+ }
200
264
  });
201
265
  }
202
266
  fetchAllUserDNFTForVault(vaultAddress, walletAddress, token, headers) {
@@ -209,8 +273,13 @@ class DripApi {
209
273
  const res = yield fetch(`${this.route}/api-be/api/spool/user/allDnft/${walletAddress}/${vaultAddress}`, {
210
274
  headers: reqHeaders,
211
275
  });
212
- const data = (yield res.json());
213
- return data;
276
+ if (res.ok) {
277
+ const data = (yield res.json());
278
+ return data;
279
+ }
280
+ else {
281
+ throw Error(`${yield res.text()}`);
282
+ }
214
283
  });
215
284
  }
216
285
  fetchAssetPerSvtAtBlock(vaultAddress, blocknumber, token) {
@@ -220,8 +289,13 @@ class DripApi {
220
289
  const res = yield fetch(`${this.route}/api-be/api/spool/user/assetBalance/${blocknumber}/${vaultAddress}`, {
221
290
  headers,
222
291
  });
223
- const data = (yield res.json());
224
- return data;
292
+ if (res.ok) {
293
+ const data = (yield res.json());
294
+ return data;
295
+ }
296
+ else {
297
+ throw Error(`${yield res.text()}`);
298
+ }
225
299
  });
226
300
  }
227
301
  fetchFastWithdrawNFTs(vaultAddress, walletAddress, token, headers) {
@@ -234,8 +308,13 @@ class DripApi {
234
308
  const res = yield fetch(`${this.route}/api-be/api/spool/user/fastWithdrawNft/${walletAddress}/${vaultAddress}`, {
235
309
  headers: reqHeaders,
236
310
  });
237
- const data = (yield res.json());
238
- return data;
311
+ if (res.ok) {
312
+ const data = (yield res.json());
313
+ return data;
314
+ }
315
+ else {
316
+ throw Error(`${yield res.text()}`);
317
+ }
239
318
  });
240
319
  }
241
320
  fetchUserRewards(walletAddress, token, headers) {
@@ -248,8 +327,13 @@ class DripApi {
248
327
  const res = yield fetch(`${this.route}/api-be/api/user/rewards/${walletAddress}`, {
249
328
  headers: reqHeaders,
250
329
  });
251
- const data = yield res.json();
252
- return data;
330
+ if (res.ok) {
331
+ const data = yield res.json();
332
+ return data;
333
+ }
334
+ else {
335
+ throw Error(`${yield res.text()}`);
336
+ }
253
337
  });
254
338
  }
255
339
  fetchVaultsClaimableData(walletAddress, token, headers) {
@@ -262,8 +346,13 @@ class DripApi {
262
346
  const res = yield fetch(`${this.route}/api-be/api/user/claimableVaults/${walletAddress}`, {
263
347
  headers: reqHeaders,
264
348
  });
265
- const data = yield res.json();
266
- return data;
349
+ if (res.ok) {
350
+ const data = yield res.json();
351
+ return data;
352
+ }
353
+ else {
354
+ throw Error(`${yield res.text()}`);
355
+ }
267
356
  });
268
357
  }
269
358
  }
package/dist/DripSdk.d.ts CHANGED
@@ -37,10 +37,9 @@ export default class DripSdk {
37
37
  withdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
38
38
  claimWithdraws(vaultAddress: string): Promise<string>;
39
39
  getVaultsClaimableData(headers?: Headers): Promise<VaultClaimData>;
40
- private generateOldRedeemBagStruct;
41
40
  approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<void>;
42
41
  approveTokenForDeposit(tokenAddress: string, amount: string): Promise<void>;
43
- private generateNewRedeemBagStruct;
42
+ private generateRedeemBagStruct;
44
43
  private getAllSvts;
45
44
  private getERC20Precission;
46
45
  private calculateFastWithdrawBalancesOld;
@@ -50,7 +49,6 @@ export default class DripSdk {
50
49
  private calculateAllDeposits;
51
50
  private calculateBalanceForDNFT;
52
51
  private checkIfUserHasWithdrawsToClaim;
53
- private shouldUseNewWithdrawLogic;
54
52
  private calculateAllWithdrawalBalances;
55
53
  private getTokenAllowanceForDeposit;
56
54
  private getTokenAllowanceForSwapAndDeposit;
package/dist/DripSdk.js CHANGED
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -39,9 +16,8 @@ const web3_token_1 = __importDefault(require("web3-token"));
39
16
  const spool_v2_sdk_1 = require("@spool.fi/spool-v2-sdk");
40
17
  const ethers_1 = require("ethers");
41
18
  const utils_1 = require("./utils");
42
- const DripApi_1 = __importStar(require("./DripApi"));
19
+ const DripApi_1 = __importDefault(require("./DripApi"));
43
20
  const js_cookie_1 = __importDefault(require("js-cookie"));
44
- const KASU_USDC_VAULT_ADDRESS = '0xd8aa8099a53eddebe6a49c98ca12746ff19aa502';
45
21
  class DripSdk {
46
22
  constructor(dripConfig, signer) {
47
23
  this.signer = signer;
@@ -223,38 +199,17 @@ class DripSdk {
223
199
  const dnfts = yield this.dripApi.fetchAllUserDNFTForVault(vaultAddress, userAddress, token, headers);
224
200
  const wnfts = yield this.dripApi.fetchAllUserWNFTForVault(vaultAddress, userAddress, token, headers);
225
201
  const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
226
- if (this.shouldUseNewWithdrawLogic(headers && headers.has(DripApi_1.IMPERSONATOR_HEADER) ? headers.get(DripApi_1.IMPERSONATOR_HEADER) : userAddress, vault)) {
227
- const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance] = yield this.calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals, token);
228
- const hasWithdrawsToClaim = this.checkIfUserHasWithdrawsToClaim(wnfts);
229
- const pendingDeposits = this.calculatePendingDeposits(dnfts, decimals);
230
- const userBalance = this.calculateAllDeposits(dnfts, decimals).sub(pendingDeposits);
231
- return {
232
- hasWithdrawsToClaim,
233
- userBalance: ethers_1.ethers.utils.formatUnits(userBalance, decimals),
234
- pendingUserBalance: ethers_1.ethers.utils.formatUnits(pendingDeposits, decimals),
235
- pendingWithdrawalBalance: ethers_1.ethers.utils.formatUnits(estimatedPendingWithdrawalBalance, decimals),
236
- withdrawableBalance: ethers_1.ethers.utils.formatUnits(estimatedWithdrawableBalance, decimals),
237
- };
238
- }
239
- else {
240
- const allDeposits = this.calculateDepositsOld(dnfts, decimals);
241
- const pendingDeposits = this.calculatePendingDepositsOld(dnfts, decimals);
242
- const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance, estimatedWithdrawals] = yield this.calculateAllWithdrawalBalances(wnfts, vault.vaultAddress, decimals, token);
243
- const fastWithdrawBalance = yield this.calculateFastWithdrawBalancesOld(authData.token, vault.vaultAddress, userAddress, decimals, headers);
244
- const hasWithdrawsToClaim = this.checkIfUserHasWithdrawsToClaim(wnfts);
245
- const balance = allDeposits
246
- .sub(estimatedWithdrawals)
247
- .sub(estimatedWithdrawableBalance)
248
- .sub(estimatedPendingWithdrawalBalance)
249
- .sub(fastWithdrawBalance);
250
- return {
251
- hasWithdrawsToClaim,
252
- userBalance: ethers_1.ethers.utils.formatUnits(balance, decimals),
253
- pendingUserBalance: ethers_1.ethers.utils.formatUnits(pendingDeposits, decimals),
254
- pendingWithdrawalBalance: ethers_1.ethers.utils.formatUnits(estimatedPendingWithdrawalBalance, decimals),
255
- withdrawableBalance: ethers_1.ethers.utils.formatUnits(estimatedWithdrawableBalance, decimals),
256
- };
257
- }
202
+ const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance] = yield this.calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals, token);
203
+ const hasWithdrawsToClaim = this.checkIfUserHasWithdrawsToClaim(wnfts);
204
+ const pendingDeposits = this.calculatePendingDeposits(dnfts, decimals);
205
+ const userBalance = this.calculateAllDeposits(dnfts, decimals).sub(pendingDeposits);
206
+ return {
207
+ hasWithdrawsToClaim,
208
+ userBalance: ethers_1.ethers.utils.formatUnits(userBalance, decimals),
209
+ pendingUserBalance: ethers_1.ethers.utils.formatUnits(pendingDeposits, decimals),
210
+ pendingWithdrawalBalance: ethers_1.ethers.utils.formatUnits(estimatedPendingWithdrawalBalance, decimals),
211
+ withdrawableBalance: ethers_1.ethers.utils.formatUnits(estimatedWithdrawableBalance, decimals),
212
+ };
258
213
  });
259
214
  }
260
215
  fastWithdraw(vaultAddress, amountToWithdraw) {
@@ -267,9 +222,7 @@ class DripSdk {
267
222
  throw Error('No signer provided');
268
223
  }
269
224
  const vault = yield this.getVaultDetails(vaultAddress);
270
- const redeemBagStruct = this.shouldUseNewWithdrawLogic(userAddress, vault)
271
- ? yield this.generateNewRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw)
272
- : yield this.generateOldRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw);
225
+ const redeemBagStruct = yield this.generateRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw);
273
226
  const currentBlockNumber = yield ((_a = this.signer.provider) === null || _a === void 0 ? void 0 : _a.getBlockNumber());
274
227
  if (!currentBlockNumber) {
275
228
  throw Error('Error fetching block number');
@@ -332,9 +285,7 @@ class DripSdk {
332
285
  throw Error('No signer provided');
333
286
  }
334
287
  const vault = yield this.getVaultDetails(vaultAddress);
335
- const redeemBagStruct = this.shouldUseNewWithdrawLogic(userAddress, vault)
336
- ? yield this.generateNewRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw)
337
- : yield this.generateOldRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw);
288
+ const redeemBagStruct = yield this.generateRedeemBagStruct(authData.token, vault, userAddress, amountToWithdraw);
338
289
  const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct, userAddress, false);
339
290
  const redeemTxReceipt = yield redeemTx.wait();
340
291
  return redeemTxReceipt.transactionHash;
@@ -373,43 +324,6 @@ class DripSdk {
373
324
  return yield this.dripApi.fetchVaultsClaimableData(authData.address, authData.token, headers);
374
325
  });
375
326
  }
376
- generateOldRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
377
- return __awaiter(this, void 0, void 0, function* () {
378
- const dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress, signerAddress, token);
379
- const userBalance = yield this.dripApi.fetchUserBalance(vault.vaultAddress, signerAddress, token);
380
- const totalTokenBalance = ethers_1.BigNumber.from(userBalance[vault.depositToken.tokenAddress]);
381
- const totalSharesFetched = yield this.dripApi.fetchUserSVTBalance(vault.vaultAddress, signerAddress, token);
382
- const totalShares = ethers_1.BigNumber.from(totalSharesFetched);
383
- const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
384
- let sharesToWithdraw = ethers_1.BigNumber.from(0);
385
- if (!amountToWithdraw) {
386
- sharesToWithdraw = totalShares;
387
- }
388
- else {
389
- //! Not a MAX Withdraw (calculate the shares to withdraw)
390
- const amountToWithdrawFixedDecimals = parseFloat(amountToWithdraw).toFixed(decimals);
391
- sharesToWithdraw = ethers_1.ethers.utils
392
- .parseUnits(amountToWithdrawFixedDecimals, decimals)
393
- .mul(totalShares)
394
- .div(totalTokenBalance);
395
- if (sharesToWithdraw.gt(totalShares)) {
396
- sharesToWithdraw = totalShares;
397
- }
398
- }
399
- const nftIds = dnfts
400
- .filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
401
- .map((item) => item.nftId.toString());
402
- const nftAmounts = dnfts
403
- .filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
404
- .map((item) => item.shares.toString());
405
- return {
406
- smartVault: vault.vaultAddress,
407
- shares: sharesToWithdraw,
408
- nftIds,
409
- nftAmounts,
410
- };
411
- });
412
- }
413
327
  approveTokenForSwapAndDeposit(tokenAddress, amount) {
414
328
  return __awaiter(this, void 0, void 0, function* () {
415
329
  if (!this.signer) {
@@ -436,13 +350,16 @@ class DripSdk {
436
350
  yield approveTx.wait();
437
351
  });
438
352
  }
439
- generateNewRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
353
+ generateRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
440
354
  return __awaiter(this, void 0, void 0, function* () {
441
355
  const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress.toLowerCase());
442
356
  const withdrawAll = !amountToWithdraw;
443
357
  const initialAmountToWithdraw = ethers_1.ethers.utils.parseUnits(amountToWithdraw || '0', decimals);
444
358
  let totalAmountToWithdraw = initialAmountToWithdraw;
445
359
  let dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress.toLowerCase(), signerAddress, token);
360
+ if (dnfts.length === 0) {
361
+ throw Error('User has no deposits');
362
+ }
446
363
  dnfts = yield this.getAllSvts(vault.vaultAddress.toLowerCase(), signerAddress, dnfts, token);
447
364
  let shares = ethers_1.BigNumber.from(0);
448
365
  const nftIds = [];
@@ -568,17 +485,6 @@ class DripSdk {
568
485
  .map((item) => item.shares.toString());
569
486
  return nftIds.length !== 0 || nftAmounts.length !== 0;
570
487
  }
571
- shouldUseNewWithdrawLogic(userAddress, vault) {
572
- // Users that already withdrew using the old approach should keep using the same
573
- const usersWhoAlreadyWithdraw = {
574
- '0x5ae62d2bc40e9119aee9cd4ed50e3d9378c9a191': KASU_USDC_VAULT_ADDRESS,
575
- };
576
- if (usersWhoAlreadyWithdraw[userAddress.toLowerCase()] &&
577
- usersWhoAlreadyWithdraw[userAddress.toLowerCase()] === vault.vaultAddress.toLowerCase()) {
578
- return false;
579
- }
580
- return vault.newWithdraw;
581
- }
582
488
  calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals, token) {
583
489
  return __awaiter(this, void 0, void 0, function* () {
584
490
  if (!this.signer) {
package/dist/test.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { ethers } from 'ethers';
2
+ export declare const signer: ethers.Wallet;
package/dist/test.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.signer = void 0;
16
+ const ethers_1 = require("ethers");
17
+ const DripConfig_1 = require("./DripConfig");
18
+ const DripSdk_1 = __importDefault(require("./DripSdk"));
19
+ // This is script to test locally the drip sdk methods
20
+ const privKey = '6ffc226f7b7769e27124317372c9dbb579a324e67e97bf07131bf2f59ec0f4fe';
21
+ const configParams = {
22
+ subgraphUrl: 'https://subgraph.satsuma-prod.com/49eb322da234/solidant/spool-v2-sepolia/api',
23
+ priceFeedApiUrl: 'https://pricefeed.dev.spool.fi/',
24
+ rewardsUrl: 'https://rewards.dev.spool.fi/sepolia',
25
+ fastRedeemApi: 'https://fastwithdraw.dev.spool.fi/sepolia',
26
+ contracts: {
27
+ 11155111: {
28
+ ISmartVaultManager: '0x2638d6c0b4EF6Dee04050fA0B07CA62500435747',
29
+ IDepositSwap: '0x5FB08e00DE169f041711206A0995410884080177',
30
+ ISmartVaultFactory: '0x86BB0376929218ba1cb825cE2ebE801bFCcD8149',
31
+ IDepositManager: '0xfA37dd47F3596681C39D3a1b55474595BB591dc9',
32
+ IRewardManager: '0xcE7F66BD505a80129Ef25b06207Ac49620A55522',
33
+ IStrategyRegistry: '0xf978853Db777d00b1130Ea21d8d98E8710b0Bc56',
34
+ ISpoolLens: '0x33Df6cf08Fbb10047e318989fE687294CD45A7B4',
35
+ },
36
+ },
37
+ };
38
+ const provider = new ethers_1.ethers.providers.StaticJsonRpcProvider('https://rpc.ankr.com/eth_sepolia', 11155111);
39
+ exports.signer = new ethers_1.ethers.Wallet(privKey, provider);
40
+ // const random_address = '0x25dFcFB061956c6f33B1ee032cc33837d0b83257';
41
+ const vaultAddress = '0x457d29df2449439a86521a1cea1561d24cc67a93'; // USDC AUKI
42
+ const daiVaultPerq = '0x1977efe478ba17da8be6e93fdfadbd3055d30111'; // DAI PERQ SEPOLIA
43
+ const usdcVaultPerq = '0xf9795bfbf7c40981c372d0fb25a87e0b694c4fcd'; // USDC PERQ SEPOLIA
44
+ const daiTokenAddress = '0x2a3a3872c242c35093a8fc48dac838c4b2d24a03'; // DAI TOKEN
45
+ const usdcTokenAddress = '0xa6b92fcd4ee124353c8a6acf1edb574f46f3f8df'; // USDC TOKEN
46
+ const dripSdk = new DripSdk_1.default(new DripConfig_1.DripConfig(configParams.subgraphUrl, configParams.priceFeedApiUrl, configParams.rewardsUrl, configParams.fastRedeemApi, configParams.contracts, 'https://dev.dripfi.io'), exports.signer);
47
+ function main() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ try {
50
+ // const res = await dripSdk.deposit(usdcTokenAddress,usdcVaultPerq, '1000');
51
+ const res = yield dripSdk.withdraw(usdcVaultPerq, '1');
52
+ console.log(res);
53
+ }
54
+ catch (error) {
55
+ console.log(`Main error: ${error}`);
56
+ }
57
+ });
58
+ }
59
+ main();
@@ -8,7 +8,6 @@ export type DeployedVault = {
8
8
  liveFrom: string;
9
9
  type: VaultType;
10
10
  depositTokenId: string;
11
- newWithdraw: boolean;
12
11
  rewards: VaultReward[];
13
12
  project?: DeployedProject;
14
13
  coingeckoId?: string;
@@ -20,7 +20,6 @@ export type Vault = {
20
20
  hasPoolEnded: boolean;
21
21
  boosters: NFTBoost[];
22
22
  strategies: Strategy[];
23
- newWithdraw: boolean;
24
23
  tgePrice?: number;
25
24
  maxAmountOfTokens?: number;
26
25
  project: DeployedProject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dripfi/drip-sdk",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "Drip SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",