@dripfi/drip-sdk 1.0.11 → 1.0.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 +5 -0
- package/dist/DripApi.d.ts +2 -0
- package/dist/DripApi.js +11 -0
- package/dist/DripSdk.d.ts +2 -0
- package/dist/DripSdk.js +25 -36
- package/dist/types/UserRewards.d.ts +5 -0
- package/dist/types/UserRewards.js +2 -0
- package/package.json +2 -1
package/README.md
CHANGED
@@ -54,6 +54,7 @@ const dripSdk = new DripSdk(dripConfig, signer);
|
|
54
54
|
| `withdraw(vault: Vault, amountToWithdraw?: string): Promise<string>` | YES | Withdraws tokens from a vault. After withdrawing, you must wait for the withdrawal to be processed by the 'DoHardWork' function, and then you can claim those tokens using claimWithdraws(). Returns txHash. |
|
55
55
|
| `claimWithdraws(vaultAddress: string): Promise<string>` | YES | After the withdrawal has been processed by the 'DoHardWork' function, the 'claimWithdraws' function transfers the withdrawn tokens to their personal account. Returns txHash. |
|
56
56
|
| `fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<string>` | YES | For users who prefer not to wait for withdrawals to be processed, there is a Fast Withdrawal method. While this approach is more gas-intensive, as users bear the cost of executing the withdrawal process themselves, it allows for instant access to the withdrawn tokens. When utilizing Fast Withdrawal, users immediately receive the tokens, eliminating the need to initiate the 'claimWithdrawal' process separately. Returns txHash. |
|
57
|
+
| `getRewards(): Promise<UserRewards>` | YES | Fetches the current user's rewards points for each vault. |
|
57
58
|
|
58
59
|
|
59
60
|
> [!IMPORTANT]
|
@@ -289,4 +290,8 @@ type UserBalance = {
|
|
289
290
|
withdrawableBalance: string
|
290
291
|
};
|
291
292
|
|
293
|
+
type UserRewards = {
|
294
|
+
[key: string]: { [key: string]: number }
|
295
|
+
};
|
296
|
+
|
292
297
|
```
|
package/dist/DripApi.d.ts
CHANGED
@@ -2,6 +2,7 @@ import { BigNumber } from 'ethers';
|
|
2
2
|
import { Vault } from './types/Vault';
|
3
3
|
import { SwapInfo } from './types/SwapInfo';
|
4
4
|
import { QLFastRedeem } from './types/QLFastRedeem';
|
5
|
+
import { UserRewards } from './types/UserRewards';
|
5
6
|
export default class DripApi {
|
6
7
|
route: string;
|
7
8
|
constructor(route: string);
|
@@ -17,4 +18,5 @@ export default class DripApi {
|
|
17
18
|
fetchAllUserDNFTForVault(vaultAddress: string, walletAddress: string, token: string): Promise<any[]>;
|
18
19
|
fetchAssetPerSvtAtBlock(vaultAddress: string, blocknumber: number, token: string): Promise<BigNumber>;
|
19
20
|
fetchFastWithdrawNFTs(vaultAddress: string, walletAddress: string, token: string): Promise<QLFastRedeem[]>;
|
21
|
+
fetchUserRewards(walletAddress: string, token: string): Promise<UserRewards>;
|
20
22
|
}
|
package/dist/DripApi.js
CHANGED
@@ -144,5 +144,16 @@ class DripApi {
|
|
144
144
|
return data;
|
145
145
|
});
|
146
146
|
}
|
147
|
+
fetchUserRewards(walletAddress, token) {
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
149
|
+
const headers = new Headers();
|
150
|
+
headers.append('Authorization', token);
|
151
|
+
const res = yield fetch(`/api-be/api/user/rewards/${walletAddress}`, {
|
152
|
+
headers,
|
153
|
+
});
|
154
|
+
const data = yield res.json();
|
155
|
+
return data;
|
156
|
+
});
|
157
|
+
}
|
147
158
|
}
|
148
159
|
exports.default = DripApi;
|
package/dist/DripSdk.d.ts
CHANGED
@@ -3,6 +3,7 @@ import { Signer } from 'ethers';
|
|
3
3
|
import { DripConfig } from './DripConfig';
|
4
4
|
import { UserBalance } from './types/UserBalance';
|
5
5
|
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
6
|
+
import { UserRewards } from './types/UserRewards';
|
6
7
|
export default class DripSdk {
|
7
8
|
private dripApi;
|
8
9
|
private spoolSdk?;
|
@@ -14,6 +15,7 @@ export default class DripSdk {
|
|
14
15
|
authenticate(): Promise<boolean>;
|
15
16
|
isUserAuthenticated(): Promise<AuthenticationStatus>;
|
16
17
|
updateSigner(newSigner: Signer): void;
|
18
|
+
getRewards(): Promise<UserRewards>;
|
17
19
|
getUserBalance(vault: Vault): Promise<UserBalance>;
|
18
20
|
fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<string>;
|
19
21
|
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
package/dist/DripSdk.js
CHANGED
@@ -88,6 +88,16 @@ class DripSdk {
|
|
88
88
|
this.signer = newSigner;
|
89
89
|
this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(this.dripConfig.internalConfig, newSigner);
|
90
90
|
}
|
91
|
+
getRewards() {
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
93
|
+
const authData = yield this.isUserAuthenticated();
|
94
|
+
if (!authData.isAuthenticated) {
|
95
|
+
throw Error(`User not authenticated: ${authData.message}`);
|
96
|
+
}
|
97
|
+
const userRewards = this.dripApi.fetchUserRewards(authData.address, authData.token);
|
98
|
+
return userRewards;
|
99
|
+
});
|
100
|
+
}
|
91
101
|
getUserBalance(vault) {
|
92
102
|
return __awaiter(this, void 0, void 0, function* () {
|
93
103
|
const authData = yield this.isUserAuthenticated();
|
@@ -143,18 +153,14 @@ class DripSdk {
|
|
143
153
|
if (!this.signer) {
|
144
154
|
throw Error('No signer provided');
|
145
155
|
}
|
146
|
-
const
|
147
|
-
|
148
|
-
|
149
|
-
}
|
150
|
-
const redeemBagStruct = this.shouldUseNewWithdrawLogic(signerAddress, vault)
|
151
|
-
? yield this.generateNewRedeemBagStruct(authData.token, vault, signerAddress, amountToWithdraw)
|
152
|
-
: yield this.generateOldRedeemBagStruct(authData.token, vault, signerAddress, amountToWithdraw);
|
156
|
+
const redeemBagStruct = this.shouldUseNewWithdrawLogic(authData.address, vault)
|
157
|
+
? yield this.generateNewRedeemBagStruct(authData.token, vault, authData.address, amountToWithdraw)
|
158
|
+
: yield this.generateOldRedeemBagStruct(authData.token, vault, authData.address, amountToWithdraw);
|
153
159
|
const currentBlockNumber = yield ((_a = this.signer.provider) === null || _a === void 0 ? void 0 : _a.getBlockNumber());
|
154
160
|
if (!currentBlockNumber) {
|
155
161
|
throw Error('Error fetching block number');
|
156
162
|
}
|
157
|
-
const redeemTx = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.redeemFast(redeemBagStruct,
|
163
|
+
const redeemTx = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.redeemFast(redeemBagStruct, authData.address, currentBlockNumber));
|
158
164
|
const txReceipt = yield redeemTx.wait();
|
159
165
|
return txReceipt.transactionHash;
|
160
166
|
});
|
@@ -200,20 +206,19 @@ class DripSdk {
|
|
200
206
|
const decimals = yield this.getERC20Precission(fromTokenAddress);
|
201
207
|
const amountToWithdrawFixedDecimals = parseFloat(fromTokenAmount).toFixed(decimals);
|
202
208
|
const fromToken = ethers_1.ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals);
|
203
|
-
const signerAddress = yield this.signer.getAddress();
|
204
209
|
if (fromToken.gt(ethers_1.BigNumber.from(0))) {
|
205
|
-
const currentTokenAllowance = yield this.getTokenAllowanceForSwapAndDepositContractAddress(fromTokenAddress);
|
210
|
+
const currentTokenAllowance = yield this.getTokenAllowanceForSwapAndDepositContractAddress(fromTokenAddress, authData.address);
|
206
211
|
if (fromToken.gt(currentTokenAllowance)) {
|
207
212
|
yield this.approveTokenForSwapAndDepositContract(fromTokenAddress, fromToken.sub(currentTokenAllowance));
|
208
213
|
}
|
209
214
|
}
|
210
|
-
const swapInfo = yield this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken,
|
215
|
+
const swapInfo = yield this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken, authData.address);
|
211
216
|
const swapDepositBagStruct = {
|
212
217
|
inTokens: [fromTokenAddress],
|
213
218
|
inAmounts: [fromToken],
|
214
219
|
smartVault: vaultAddress,
|
215
220
|
swapInfo,
|
216
|
-
receiver:
|
221
|
+
receiver: authData.address,
|
217
222
|
referral: ethers_1.ethers.constants.AddressZero,
|
218
223
|
doFlush: false,
|
219
224
|
};
|
@@ -233,14 +238,10 @@ class DripSdk {
|
|
233
238
|
if (!this.signer) {
|
234
239
|
throw Error('No signer provided');
|
235
240
|
}
|
236
|
-
const
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
const redeemBagStruct = this.shouldUseNewWithdrawLogic(signerAddress, vault)
|
241
|
-
? yield this.generateNewRedeemBagStruct(authData.token, vault, signerAddress, amountToWithdraw)
|
242
|
-
: yield this.generateOldRedeemBagStruct(authData.token, vault, signerAddress, amountToWithdraw);
|
243
|
-
const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct, signerAddress.toLowerCase(), false);
|
241
|
+
const redeemBagStruct = this.shouldUseNewWithdrawLogic(authData.address, vault)
|
242
|
+
? yield this.generateNewRedeemBagStruct(authData.token, vault, authData.address, amountToWithdraw)
|
243
|
+
: yield this.generateOldRedeemBagStruct(authData.token, vault, authData.address, amountToWithdraw);
|
244
|
+
const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct, authData.address, false);
|
244
245
|
const redeemTxReceipt = yield redeemTx.wait();
|
245
246
|
return redeemTxReceipt.transactionHash;
|
246
247
|
});
|
@@ -254,11 +255,7 @@ class DripSdk {
|
|
254
255
|
if (!this.signer) {
|
255
256
|
throw Error('No signer provided');
|
256
257
|
}
|
257
|
-
const
|
258
|
-
if (!signerAddress) {
|
259
|
-
throw Error('Error fetching address');
|
260
|
-
}
|
261
|
-
const wnfts = yield this.dripApi.fetchEnrichedUserWNFTForVault(vaultAddress, signerAddress, authData.token);
|
258
|
+
const wnfts = yield this.dripApi.fetchEnrichedUserWNFTForVault(vaultAddress, authData.address, authData.token);
|
262
259
|
//! Shares come as Strings instead of BigNumber from our Backend
|
263
260
|
const nftIds = wnfts
|
264
261
|
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
@@ -266,7 +263,7 @@ class DripSdk {
|
|
266
263
|
const nftAmounts = wnfts
|
267
264
|
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
268
265
|
.map((item) => item.shares.toString());
|
269
|
-
const claimWithdrawTx = yield this.spoolSdk.claimWithdrawal(vaultAddress, nftIds, nftAmounts,
|
266
|
+
const claimWithdrawTx = yield this.spoolSdk.claimWithdrawal(vaultAddress, nftIds, nftAmounts, authData.address);
|
270
267
|
const txReceipt = yield claimWithdrawTx.wait();
|
271
268
|
return txReceipt.transactionHash;
|
272
269
|
});
|
@@ -368,10 +365,6 @@ class DripSdk {
|
|
368
365
|
if (!this.signer) {
|
369
366
|
throw Error('No signer provided');
|
370
367
|
}
|
371
|
-
const signerAddress = yield this.signer.getAddress();
|
372
|
-
if (!signerAddress) {
|
373
|
-
throw Error('Error fetching address');
|
374
|
-
}
|
375
368
|
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
376
369
|
const decimals = yield erc20Instance.decimals();
|
377
370
|
return decimals;
|
@@ -487,18 +480,14 @@ class DripSdk {
|
|
487
480
|
return [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance, estimatedWithdrawals];
|
488
481
|
});
|
489
482
|
}
|
490
|
-
getTokenAllowanceForSwapAndDepositContractAddress(tokenAddress) {
|
483
|
+
getTokenAllowanceForSwapAndDepositContractAddress(tokenAddress, userAddress) {
|
491
484
|
return __awaiter(this, void 0, void 0, function* () {
|
492
485
|
if (!this.signer) {
|
493
486
|
throw Error('No signer provided');
|
494
487
|
}
|
495
|
-
const signerAddress = yield this.signer.getAddress();
|
496
|
-
if (!signerAddress) {
|
497
|
-
throw Error('Error fetching address');
|
498
|
-
}
|
499
488
|
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
500
489
|
const swapAndDepositAddress = yield this.dripConfig.getSwapAndDepositContractAddress(this.signer);
|
501
|
-
const allowance = yield erc20Instance.allowance(
|
490
|
+
const allowance = yield erc20Instance.allowance(userAddress, swapAndDepositAddress);
|
502
491
|
return allowance;
|
503
492
|
});
|
504
493
|
}
|
package/package.json
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dripfi/drip-sdk",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.12",
|
4
4
|
"description": "Drip SDK",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
7
7
|
"scripts": {
|
8
8
|
"prepublish": "npm run build",
|
9
9
|
"build": "tsc",
|
10
|
+
"publish": "npm publish --access public",
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
11
12
|
},
|
12
13
|
"dependencies": {
|