@dripfi/drip-sdk 1.1.10 → 1.1.11
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/DripApi.js +139 -50
- package/dist/DripSdk.js +6 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.js +55 -0
- package/package.json +1 -1
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
|
-
|
25
|
-
|
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 (
|
32
|
-
|
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
|
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
|
-
|
71
|
-
|
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
|
-
|
85
|
-
|
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
|
-
|
92
|
-
|
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
|
-
|
99
|
-
|
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 (
|
110
|
-
|
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
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
|
141
|
-
|
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
|
-
|
152
|
-
|
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
|
-
|
163
|
-
|
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
|
-
|
174
|
-
|
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
|
-
|
185
|
-
|
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
|
-
|
199
|
-
|
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
|
-
|
213
|
-
|
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
|
-
|
224
|
-
|
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
|
-
|
238
|
-
|
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
|
-
|
252
|
-
|
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
|
-
|
266
|
-
|
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.js
CHANGED
@@ -376,6 +376,9 @@ class DripSdk {
|
|
376
376
|
generateOldRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
|
377
377
|
return __awaiter(this, void 0, void 0, function* () {
|
378
378
|
const dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress, signerAddress, token);
|
379
|
+
if (dnfts.length === 0) {
|
380
|
+
throw Error('User has no deposits');
|
381
|
+
}
|
379
382
|
const userBalance = yield this.dripApi.fetchUserBalance(vault.vaultAddress, signerAddress, token);
|
380
383
|
const totalTokenBalance = ethers_1.BigNumber.from(userBalance[vault.depositToken.tokenAddress]);
|
381
384
|
const totalSharesFetched = yield this.dripApi.fetchUserSVTBalance(vault.vaultAddress, signerAddress, token);
|
@@ -443,6 +446,9 @@ class DripSdk {
|
|
443
446
|
const initialAmountToWithdraw = ethers_1.ethers.utils.parseUnits(amountToWithdraw || '0', decimals);
|
444
447
|
let totalAmountToWithdraw = initialAmountToWithdraw;
|
445
448
|
let dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress.toLowerCase(), signerAddress, token);
|
449
|
+
if (dnfts.length === 0) {
|
450
|
+
throw Error('User has no deposits');
|
451
|
+
}
|
446
452
|
dnfts = yield this.getAllSvts(vault.vaultAddress.toLowerCase(), signerAddress, dnfts, token);
|
447
453
|
let shares = ethers_1.BigNumber.from(0);
|
448
454
|
const nftIds = [];
|
package/dist/test.d.ts
ADDED
package/dist/test.js
ADDED
@@ -0,0 +1,55 @@
|
|
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 = 'b0236d5a72786eb1d256713482103d49ba0fecafaf18da8df45eac8a66bcf1af';
|
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 dripSdk = new DripSdk_1.default(new DripConfig_1.DripConfig(configParams.subgraphUrl, configParams.priceFeedApiUrl, configParams.rewardsUrl, configParams.fastRedeemApi, configParams.contracts, 'http://localhost:3000'), exports.signer);
|
43
|
+
function main() {
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
45
|
+
try {
|
46
|
+
// const res = await dripSdk.deposit('0xa6b92FCD4Ee124353C8A6AcF1Edb574F46F3f8DF',vaultAddress, '1500');
|
47
|
+
const res = yield dripSdk.withdraw(vaultAddress, '150');
|
48
|
+
console.log(res);
|
49
|
+
}
|
50
|
+
catch (error) {
|
51
|
+
console.log(`Main error: ${error}`);
|
52
|
+
}
|
53
|
+
});
|
54
|
+
}
|
55
|
+
main();
|