@dripfi/drip-sdk 1.1.11 → 1.1.13
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 +0 -1
- package/dist/DripSdk.d.ts +1 -3
- package/dist/DripSdk.js +16 -116
- package/dist/test.js +8 -4
- package/dist/types/DeployedVault.d.ts +0 -1
- package/dist/types/Vault.d.ts +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
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
|
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 =
|
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;
|
@@ -98,7 +74,7 @@ class DripSdk {
|
|
98
74
|
const address = yield this.signer.getAddress();
|
99
75
|
const cookieName = `auth_${address.toLowerCase()}`;
|
100
76
|
const token = yield web3_token_1.default.sign((message) => __awaiter(this, void 0, void 0, function* () { return yield this.signer.signMessage(message); }), {
|
101
|
-
statement: JSON.stringify({ address, message: 'Please sign in into
|
77
|
+
statement: JSON.stringify({ address, message: 'Please sign in into Perq' }),
|
102
78
|
expires_in: '30d',
|
103
79
|
});
|
104
80
|
const response = yield fetch(`${this.dripConfig.dripRoute}/api-be/auth/verify`, {
|
@@ -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
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
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.
|
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.
|
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,46 +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
|
-
if (dnfts.length === 0) {
|
380
|
-
throw Error('User has no deposits');
|
381
|
-
}
|
382
|
-
const userBalance = yield this.dripApi.fetchUserBalance(vault.vaultAddress, signerAddress, token);
|
383
|
-
const totalTokenBalance = ethers_1.BigNumber.from(userBalance[vault.depositToken.tokenAddress]);
|
384
|
-
const totalSharesFetched = yield this.dripApi.fetchUserSVTBalance(vault.vaultAddress, signerAddress, token);
|
385
|
-
const totalShares = ethers_1.BigNumber.from(totalSharesFetched);
|
386
|
-
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
|
387
|
-
let sharesToWithdraw = ethers_1.BigNumber.from(0);
|
388
|
-
if (!amountToWithdraw) {
|
389
|
-
sharesToWithdraw = totalShares;
|
390
|
-
}
|
391
|
-
else {
|
392
|
-
//! Not a MAX Withdraw (calculate the shares to withdraw)
|
393
|
-
const amountToWithdrawFixedDecimals = parseFloat(amountToWithdraw).toFixed(decimals);
|
394
|
-
sharesToWithdraw = ethers_1.ethers.utils
|
395
|
-
.parseUnits(amountToWithdrawFixedDecimals, decimals)
|
396
|
-
.mul(totalShares)
|
397
|
-
.div(totalTokenBalance);
|
398
|
-
if (sharesToWithdraw.gt(totalShares)) {
|
399
|
-
sharesToWithdraw = totalShares;
|
400
|
-
}
|
401
|
-
}
|
402
|
-
const nftIds = dnfts
|
403
|
-
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
404
|
-
.map((item) => item.nftId.toString());
|
405
|
-
const nftAmounts = dnfts
|
406
|
-
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
407
|
-
.map((item) => item.shares.toString());
|
408
|
-
return {
|
409
|
-
smartVault: vault.vaultAddress,
|
410
|
-
shares: sharesToWithdraw,
|
411
|
-
nftIds,
|
412
|
-
nftAmounts,
|
413
|
-
};
|
414
|
-
});
|
415
|
-
}
|
416
327
|
approveTokenForSwapAndDeposit(tokenAddress, amount) {
|
417
328
|
return __awaiter(this, void 0, void 0, function* () {
|
418
329
|
if (!this.signer) {
|
@@ -439,7 +350,7 @@ class DripSdk {
|
|
439
350
|
yield approveTx.wait();
|
440
351
|
});
|
441
352
|
}
|
442
|
-
|
353
|
+
generateRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
|
443
354
|
return __awaiter(this, void 0, void 0, function* () {
|
444
355
|
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress.toLowerCase());
|
445
356
|
const withdrawAll = !amountToWithdraw;
|
@@ -574,17 +485,6 @@ class DripSdk {
|
|
574
485
|
.map((item) => item.shares.toString());
|
575
486
|
return nftIds.length !== 0 || nftAmounts.length !== 0;
|
576
487
|
}
|
577
|
-
shouldUseNewWithdrawLogic(userAddress, vault) {
|
578
|
-
// Users that already withdrew using the old approach should keep using the same
|
579
|
-
const usersWhoAlreadyWithdraw = {
|
580
|
-
'0x5ae62d2bc40e9119aee9cd4ed50e3d9378c9a191': KASU_USDC_VAULT_ADDRESS,
|
581
|
-
};
|
582
|
-
if (usersWhoAlreadyWithdraw[userAddress.toLowerCase()] &&
|
583
|
-
usersWhoAlreadyWithdraw[userAddress.toLowerCase()] === vault.vaultAddress.toLowerCase()) {
|
584
|
-
return false;
|
585
|
-
}
|
586
|
-
return vault.newWithdraw;
|
587
|
-
}
|
588
488
|
calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals, token) {
|
589
489
|
return __awaiter(this, void 0, void 0, function* () {
|
590
490
|
if (!this.signer) {
|
package/dist/test.js
CHANGED
@@ -17,7 +17,7 @@ const ethers_1 = require("ethers");
|
|
17
17
|
const DripConfig_1 = require("./DripConfig");
|
18
18
|
const DripSdk_1 = __importDefault(require("./DripSdk"));
|
19
19
|
// This is script to test locally the drip sdk methods
|
20
|
-
const privKey = '
|
20
|
+
const privKey = '6ffc226f7b7769e27124317372c9dbb579a324e67e97bf07131bf2f59ec0f4fe';
|
21
21
|
const configParams = {
|
22
22
|
subgraphUrl: 'https://subgraph.satsuma-prod.com/49eb322da234/solidant/spool-v2-sepolia/api',
|
23
23
|
priceFeedApiUrl: 'https://pricefeed.dev.spool.fi/',
|
@@ -39,12 +39,16 @@ const provider = new ethers_1.ethers.providers.StaticJsonRpcProvider('https://rp
|
|
39
39
|
exports.signer = new ethers_1.ethers.Wallet(privKey, provider);
|
40
40
|
// const random_address = '0x25dFcFB061956c6f33B1ee032cc33837d0b83257';
|
41
41
|
const vaultAddress = '0x457d29df2449439a86521a1cea1561d24cc67a93'; // USDC AUKI
|
42
|
-
const
|
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);
|
43
47
|
function main() {
|
44
48
|
return __awaiter(this, void 0, void 0, function* () {
|
45
49
|
try {
|
46
|
-
// const res = await dripSdk.deposit(
|
47
|
-
const res = yield dripSdk.withdraw(
|
50
|
+
// const res = await dripSdk.deposit(usdcTokenAddress,usdcVaultPerq, '1000');
|
51
|
+
const res = yield dripSdk.withdraw(usdcVaultPerq, '1');
|
48
52
|
console.log(res);
|
49
53
|
}
|
50
54
|
catch (error) {
|
package/dist/types/Vault.d.ts
CHANGED