@dripfi/drip-sdk 1.3.2 → 1.3.3

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
@@ -10,6 +10,7 @@ The Drip SDK is a TypeScript library designed to interact with the Drip protocol
10
10
  - [Methods](#methods)
11
11
  - [Examples](#examples)
12
12
  - [Types](#types)
13
+ - [Abis](#abis)
13
14
 
14
15
  # Installation
15
16
 
@@ -73,13 +74,9 @@ const dripSdk = new DripSdk(chain, signer);
73
74
  | `getMyPerqBalance(): Promise<MyPerqData>` | YES | This function retrieves the user's Perq balance data.
74
75
  | `getVaultsClaimableData(): Promise<VaultClaimData> ` | YES | This function fetches claimable data for the user's vaults.
75
76
  | `upgradeLoyaltyCard(index: number): Promise<LoyaltyCard>` | YES | This function upgrades the user's loyalty card.
76
- | `getOwnedLoyaltyCard(): Promise<LoyaltyCard>` | YES | This function fetches the next loyalty card for the authenticated user based on the currently owned one
77
+ | `getOwnedLoyaltyCard(): Promise<LoyaltyCard>` | YES | This function fetches the currently owned loyalty card of the connected wallet.
77
78
  | `getAllLoyaltyCards(): Promise<LoyaltyCard[]>` | YES | This function fetches all available loyalty cards.
78
79
 
79
-
80
- > [!IMPORTANT]
81
- > **You must authenticate once for every wallet you want to use**
82
-
83
80
  ---
84
81
 
85
82
  # Examples
@@ -209,7 +206,7 @@ type Vault = {
209
206
  depositToken: VaultDepositToken
210
207
  type: VaultType
211
208
  rewards: VaultReward[]
212
- rewardType: RewardType
209
+ rewardType: RewardType
213
210
  liveUntil: string
214
211
  liveFrom: string
215
212
  liveUntilFormatted: string
@@ -223,9 +220,15 @@ type Vault = {
223
220
  coingeckoId?: string
224
221
  depositTokenId: string
225
222
  expectedTge?: string
226
- tokenPrice: number,
227
- change24h: number,
228
- volume24h: number,
223
+ tokenPrice: number
224
+ change24h: number
225
+ volume24h: number
226
+ projectFeatured: boolean
227
+ avgTvl: string
228
+ peakTvl: string
229
+ amountOfDepositors: number
230
+ boostedTvl: number
231
+ projectVAPY?: number
229
232
  };
230
233
 
231
234
  type VaultType = 'launch' | 'earn' | 'airdrop'
@@ -366,38 +369,49 @@ enum ELoyaltyCardTier {
366
369
 
367
370
  export type MyPerqData = {
368
371
  [key: string]: {
369
- vaultAddress: string,
370
- projectName: string,
371
- projectType: string,
372
- projectFeatured: boolean,
373
- liveUntil: string,
374
- coingeckoId?: string,
375
- depositTokenId: 'WETH' | 'USDC' | 'DAI',
376
- type: 'earn' | 'launch' | 'airdrop',
377
- rewardType: 'points' | 'token' | 'pnode shards',
378
- amountOfTokens?: number
379
- vaultName: string,
380
- protocols: string[],
381
- apy: number,
382
- tvr: number,
383
- tokenPrice: number,
384
- change24h: number,
385
- volume24h: number,
386
- rewards: CacheVaultRewards[]
387
- strategies: Strategy[],
388
- boosters: NFTBoost[],
389
- depositToken: DepositToken
390
- avgTvl: string
391
- peakTvl: string
392
- pendingDeposits: number;
393
- currentlyDeposited: number;
394
- pendingWithdraws: number;
395
- claimable: number;
396
- ethPrice: number;
397
- tokenRewards: {[token_address: string]: Asset & { amount: number, rewardsPerHour: number }};
372
+ vaultAddress: string,
373
+ projectName: string,
374
+ projectType: string,
375
+ projectFeatured: boolean,
376
+ liveUntil: string,
377
+ coingeckoId?: string,
378
+ depositTokenId: 'WETH' | 'USDC' | 'DAI',
379
+ type: 'earn' | 'launch' | 'airdrop',
380
+ rewardType: 'points' | 'token' | 'pnode shards',
381
+ amountOfTokens?: number
382
+ vaultName: string,
383
+ protocols: string[],
384
+ apy: number,
385
+ tvr: number,
386
+ tokenPrice: number,
387
+ change24h: number,
388
+ volume24h: number,
389
+ rewards: CacheVaultRewards[]
390
+ strategies: Strategy[],
391
+ boosters: NFTBoost[],
392
+ depositToken: DepositToken
393
+ avgTvl: string
394
+ peakTvl: string
395
+ pendingDeposits: number;
396
+ currentlyDeposited: number;
397
+ pendingWithdraws: number;
398
+ claimable: number;
399
+ ethPrice: number;
400
+ tokenRewards: {[token_address: string]: Asset & { amount: number, rewardsPerHour: number }};
398
401
  }
399
402
  };
403
+ ```
400
404
 
405
+ # Abis
406
+
407
+ - DRIP_SWAP_AND_RECYCLER_ABI
408
+
409
+ - WETH_TOKEN_ABI
410
+
411
+ - DRIP_TOKEN_ABI
412
+
413
+ - TOKEN_RECYCLER_ABI
414
+
415
+ - PERQ_VESTING_ABI
401
416
 
402
417
 
403
- ```
package/dist/DripSdk.js CHANGED
@@ -167,21 +167,57 @@ class DripSdk {
167
167
  }
168
168
  getUserVaultBalance(vaultAddress) {
169
169
  return __awaiter(this, void 0, void 0, function* () {
170
+ if (!this.signer) {
171
+ throw Error('No signer provided');
172
+ }
170
173
  const userAddress = yield this.signer.getAddress();
171
- const vault = yield this.getVaultDetails(vaultAddress);
172
- const dnfts = yield this.dripApi.fetchAllUserDNFTForVault(vaultAddress, userAddress);
173
- const wnfts = yield this.dripApi.fetchAllUserWNFTForVault(vaultAddress, userAddress);
174
+ // Parallel fetch of vault, user dnfts and user wnfts
175
+ const [vault, userDnftsForVault, userWnftsForVault] = yield Promise.all([
176
+ this.getVaultDetails(vaultAddress),
177
+ this.dripApi.fetchAllUserDNFTForVault(vaultAddress, userAddress),
178
+ this.dripApi.fetchAllUserWNFTForVault(vaultAddress, userAddress),
179
+ ]);
174
180
  const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
175
- const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance] = yield this.calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals);
176
- const hasWithdrawsToClaim = this.checkIfUserHasWithdrawsToClaim(wnfts);
177
- const pendingDeposits = this.calculatePendingDeposits(dnfts, decimals);
178
- const userBalance = this.calculateAllDeposits(dnfts, decimals).sub(pendingDeposits);
181
+ // Calculate deposits
182
+ let pendingDeposits = ethers_1.BigNumber.from(0);
183
+ let currentlyDeposited = ethers_1.BigNumber.from(0);
184
+ for (const dnft of userDnftsForVault) {
185
+ if (dnft.assets && dnft.assets[0]) {
186
+ const amount = ethers_1.ethers.utils.parseUnits(dnft.assets[0].toString(), decimals);
187
+ if (!dnft.isDHWFinished) {
188
+ // Pending deposits (not yet processed)
189
+ pendingDeposits = pendingDeposits.add(amount);
190
+ }
191
+ else {
192
+ // Processed deposits
193
+ currentlyDeposited = currentlyDeposited.add(amount);
194
+ }
195
+ }
196
+ }
197
+ // Calculate withdrawals
198
+ let pendingWithdraws = ethers_1.BigNumber.from(0);
199
+ let claimable = ethers_1.BigNumber.from(0);
200
+ for (const wnft of userWnftsForVault) {
201
+ if (!wnft.isBurned && wnft.svtWithdrawn) {
202
+ const currentBlockNumber = wnft.blockNumber - 1;
203
+ const assetsPerSvtAtBlock = yield this.dripApi.fetchAssetPerSvtAtBlock(vaultAddress, currentBlockNumber);
204
+ const estimatedValueOfNFT = ethers_1.BigNumber.from(ethers_1.ethers.utils.formatUnits(ethers_1.BigNumber.from(wnft.svtWithdrawn).mul(assetsPerSvtAtBlock), 36).split('.')[0]);
205
+ if (wnft.isDHWFinished) {
206
+ // Processed and claimable
207
+ claimable = claimable.add(estimatedValueOfNFT);
208
+ }
209
+ else {
210
+ // Not processed, pending withdrawal
211
+ pendingWithdraws = pendingWithdraws.add(estimatedValueOfNFT);
212
+ }
213
+ }
214
+ }
179
215
  return {
180
- hasWithdrawsToClaim,
181
- userBalance: ethers_1.ethers.utils.formatUnits(userBalance, decimals),
216
+ hasWithdrawsToClaim: claimable.gt(0),
217
+ userBalance: ethers_1.ethers.utils.formatUnits(currentlyDeposited, decimals),
182
218
  pendingUserBalance: ethers_1.ethers.utils.formatUnits(pendingDeposits, decimals),
183
- pendingWithdrawalBalance: ethers_1.ethers.utils.formatUnits(estimatedPendingWithdrawalBalance, decimals),
184
- withdrawableBalance: ethers_1.ethers.utils.formatUnits(estimatedWithdrawableBalance, decimals),
219
+ pendingWithdrawalBalance: ethers_1.ethers.utils.formatUnits(pendingWithdraws, decimals),
220
+ withdrawableBalance: ethers_1.ethers.utils.formatUnits(claimable, decimals),
185
221
  };
186
222
  });
187
223
  }
@@ -1,368 +1,4 @@
1
1
  [
2
- {
3
- "inputs": [
4
- {
5
- "internalType": "contract IUniswapV2Router02",
6
- "name": "swapRouter_",
7
- "type": "address"
8
- },
9
- {
10
- "internalType": "contract ITokenRecycler",
11
- "name": "tokenRecycler_",
12
- "type": "address"
13
- },
14
- {
15
- "internalType": "address",
16
- "name": "admin_",
17
- "type": "address"
18
- }
19
- ],
20
- "stateMutability": "nonpayable",
21
- "type": "constructor"
22
- },
23
- {
24
- "inputs": [],
25
- "name": "AccessControlBadConfirmation",
26
- "type": "error"
27
- },
28
- {
29
- "inputs": [
30
- {
31
- "internalType": "address",
32
- "name": "account",
33
- "type": "address"
34
- },
35
- {
36
- "internalType": "bytes32",
37
- "name": "neededRole",
38
- "type": "bytes32"
39
- }
40
- ],
41
- "name": "AccessControlUnauthorizedAccount",
42
- "type": "error"
43
- },
44
- {
45
- "inputs": [
46
- {
47
- "internalType": "address",
48
- "name": "target",
49
- "type": "address"
50
- }
51
- ],
52
- "name": "AddressEmptyCode",
53
- "type": "error"
54
- },
55
- {
56
- "inputs": [
57
- {
58
- "internalType": "address",
59
- "name": "account",
60
- "type": "address"
61
- }
62
- ],
63
- "name": "AddressInsufficientBalance",
64
- "type": "error"
65
- },
66
- {
67
- "inputs": [],
68
- "name": "FailedInnerCall",
69
- "type": "error"
70
- },
71
- {
72
- "inputs": [],
73
- "name": "ReentrancyGuardReentrantCall",
74
- "type": "error"
75
- },
76
- {
77
- "inputs": [
78
- {
79
- "internalType": "address",
80
- "name": "token",
81
- "type": "address"
82
- }
83
- ],
84
- "name": "SafeERC20FailedOperation",
85
- "type": "error"
86
- },
87
- {
88
- "anonymous": false,
89
- "inputs": [
90
- {
91
- "indexed": true,
92
- "internalType": "bytes32",
93
- "name": "role",
94
- "type": "bytes32"
95
- },
96
- {
97
- "indexed": true,
98
- "internalType": "bytes32",
99
- "name": "previousAdminRole",
100
- "type": "bytes32"
101
- },
102
- {
103
- "indexed": true,
104
- "internalType": "bytes32",
105
- "name": "newAdminRole",
106
- "type": "bytes32"
107
- }
108
- ],
109
- "name": "RoleAdminChanged",
110
- "type": "event"
111
- },
112
- {
113
- "anonymous": false,
114
- "inputs": [
115
- {
116
- "indexed": true,
117
- "internalType": "bytes32",
118
- "name": "role",
119
- "type": "bytes32"
120
- },
121
- {
122
- "indexed": true,
123
- "internalType": "address",
124
- "name": "account",
125
- "type": "address"
126
- },
127
- {
128
- "indexed": true,
129
- "internalType": "address",
130
- "name": "sender",
131
- "type": "address"
132
- }
133
- ],
134
- "name": "RoleGranted",
135
- "type": "event"
136
- },
137
- {
138
- "anonymous": false,
139
- "inputs": [
140
- {
141
- "indexed": true,
142
- "internalType": "bytes32",
143
- "name": "role",
144
- "type": "bytes32"
145
- },
146
- {
147
- "indexed": true,
148
- "internalType": "address",
149
- "name": "account",
150
- "type": "address"
151
- },
152
- {
153
- "indexed": true,
154
- "internalType": "address",
155
- "name": "sender",
156
- "type": "address"
157
- }
158
- ],
159
- "name": "RoleRevoked",
160
- "type": "event"
161
- },
162
- {
163
- "anonymous": false,
164
- "inputs": [
165
- {
166
- "indexed": true,
167
- "internalType": "address",
168
- "name": "sender",
169
- "type": "address"
170
- },
171
- {
172
- "indexed": true,
173
- "internalType": "address",
174
- "name": "rewardBeneficiary",
175
- "type": "address"
176
- },
177
- {
178
- "indexed": false,
179
- "internalType": "address[]",
180
- "name": "path",
181
- "type": "address[]"
182
- },
183
- {
184
- "indexed": false,
185
- "internalType": "uint256[]",
186
- "name": "swapAmounts",
187
- "type": "uint256[]"
188
- },
189
- {
190
- "indexed": false,
191
- "internalType": "uint256",
192
- "name": "minAmountOut",
193
- "type": "uint256"
194
- },
195
- {
196
- "indexed": false,
197
- "internalType": "uint256",
198
- "name": "deadline",
199
- "type": "uint256"
200
- },
201
- {
202
- "indexed": false,
203
- "internalType": "uint256",
204
- "name": "rewardAmount",
205
- "type": "uint256"
206
- }
207
- ],
208
- "name": "SwappedAndRecycled",
209
- "type": "event"
210
- },
211
- {
212
- "inputs": [],
213
- "name": "ADMIN_ROLE",
214
- "outputs": [
215
- {
216
- "internalType": "bytes32",
217
- "name": "",
218
- "type": "bytes32"
219
- }
220
- ],
221
- "stateMutability": "view",
222
- "type": "function"
223
- },
224
- {
225
- "inputs": [],
226
- "name": "DEFAULT_ADMIN_ROLE",
227
- "outputs": [
228
- {
229
- "internalType": "bytes32",
230
- "name": "",
231
- "type": "bytes32"
232
- }
233
- ],
234
- "stateMutability": "view",
235
- "type": "function"
236
- },
237
- {
238
- "inputs": [
239
- {
240
- "internalType": "bytes32",
241
- "name": "role",
242
- "type": "bytes32"
243
- }
244
- ],
245
- "name": "getRoleAdmin",
246
- "outputs": [
247
- {
248
- "internalType": "bytes32",
249
- "name": "",
250
- "type": "bytes32"
251
- }
252
- ],
253
- "stateMutability": "view",
254
- "type": "function"
255
- },
256
- {
257
- "inputs": [
258
- {
259
- "internalType": "bytes32",
260
- "name": "role",
261
- "type": "bytes32"
262
- },
263
- {
264
- "internalType": "address",
265
- "name": "account",
266
- "type": "address"
267
- }
268
- ],
269
- "name": "grantRole",
270
- "outputs": [],
271
- "stateMutability": "nonpayable",
272
- "type": "function"
273
- },
274
- {
275
- "inputs": [
276
- {
277
- "internalType": "bytes32",
278
- "name": "role",
279
- "type": "bytes32"
280
- },
281
- {
282
- "internalType": "address",
283
- "name": "account",
284
- "type": "address"
285
- }
286
- ],
287
- "name": "hasRole",
288
- "outputs": [
289
- {
290
- "internalType": "bool",
291
- "name": "",
292
- "type": "bool"
293
- }
294
- ],
295
- "stateMutability": "view",
296
- "type": "function"
297
- },
298
- {
299
- "inputs": [],
300
- "name": "recycledToken",
301
- "outputs": [
302
- {
303
- "internalType": "contract IERC20",
304
- "name": "",
305
- "type": "address"
306
- }
307
- ],
308
- "stateMutability": "view",
309
- "type": "function"
310
- },
311
- {
312
- "inputs": [
313
- {
314
- "internalType": "bytes32",
315
- "name": "role",
316
- "type": "bytes32"
317
- },
318
- {
319
- "internalType": "address",
320
- "name": "callerConfirmation",
321
- "type": "address"
322
- }
323
- ],
324
- "name": "renounceRole",
325
- "outputs": [],
326
- "stateMutability": "nonpayable",
327
- "type": "function"
328
- },
329
- {
330
- "inputs": [
331
- {
332
- "internalType": "bytes32",
333
- "name": "role",
334
- "type": "bytes32"
335
- },
336
- {
337
- "internalType": "address",
338
- "name": "account",
339
- "type": "address"
340
- }
341
- ],
342
- "name": "revokeRole",
343
- "outputs": [],
344
- "stateMutability": "nonpayable",
345
- "type": "function"
346
- },
347
- {
348
- "inputs": [
349
- {
350
- "internalType": "bytes4",
351
- "name": "interfaceId",
352
- "type": "bytes4"
353
- }
354
- ],
355
- "name": "supportsInterface",
356
- "outputs": [
357
- {
358
- "internalType": "bool",
359
- "name": "",
360
- "type": "bool"
361
- }
362
- ],
363
- "stateMutability": "view",
364
- "type": "function"
365
- },
366
2
  {
367
3
  "inputs": [
368
4
  {
@@ -455,62 +91,5 @@
455
91
  ],
456
92
  "stateMutability": "payable",
457
93
  "type": "function"
458
- },
459
- {
460
- "inputs": [],
461
- "name": "swapRouter",
462
- "outputs": [
463
- {
464
- "internalType": "contract IUniswapV2Router02",
465
- "name": "",
466
- "type": "address"
467
- }
468
- ],
469
- "stateMutability": "view",
470
- "type": "function"
471
- },
472
- {
473
- "inputs": [],
474
- "name": "tokenRecycler",
475
- "outputs": [
476
- {
477
- "internalType": "contract ITokenRecycler",
478
- "name": "",
479
- "type": "address"
480
- }
481
- ],
482
- "stateMutability": "view",
483
- "type": "function"
484
- },
485
- {
486
- "inputs": [
487
- {
488
- "internalType": "uint256",
489
- "name": "amount_",
490
- "type": "uint256"
491
- }
492
- ],
493
- "name": "withdrawETH",
494
- "outputs": [],
495
- "stateMutability": "nonpayable",
496
- "type": "function"
497
- },
498
- {
499
- "inputs": [
500
- {
501
- "internalType": "contract IERC20",
502
- "name": "token_",
503
- "type": "address"
504
- },
505
- {
506
- "internalType": "uint256",
507
- "name": "amount_",
508
- "type": "uint256"
509
- }
510
- ],
511
- "name": "withdrawToken",
512
- "outputs": [],
513
- "stateMutability": "nonpayable",
514
- "type": "function"
515
94
  }
516
95
  ]