@dripfi/drip-sdk 1.0.14 → 1.0.15
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 +49 -23
- package/dist/DripApi.d.ts +8 -0
- package/dist/DripApi.js +77 -1
- package/dist/DripSdk.d.ts +16 -8
- package/dist/DripSdk.js +105 -56
- package/dist/index.d.ts +11 -1
- package/dist/types/NFTBoost.d.ts +9 -0
- package/dist/types/NFTBoost.js +2 -0
- package/dist/types/Strategy.d.ts +5 -0
- package/dist/types/Strategy.js +2 -0
- package/dist/types/StretchGoal.d.ts +7 -0
- package/dist/types/StretchGoal.js +2 -0
- package/dist/types/UserBalance.d.ts +16 -5
- package/dist/types/UserVaultBalance.d.ts +7 -0
- package/dist/types/UserVaultBalance.js +2 -0
- package/dist/types/Vault.d.ts +7 -46
- package/dist/types/VaultDepositToken.d.ts +7 -0
- package/dist/types/VaultDepositToken.js +2 -0
- package/dist/types/VaultReward.d.ts +12 -0
- package/dist/types/VaultReward.js +2 -0
- package/dist/types/VaultStats.d.ts +5 -0
- package/dist/types/VaultStats.js +2 -0
- package/dist/types/VaultType.d.ts +1 -0
- package/dist/types/VaultType.js +2 -0
- package/dist/utils.js +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -43,18 +43,24 @@ const dripSdk = new DripSdk(dripConfig, signer);
|
|
43
43
|
|
44
44
|
| Name | Requires authentication | Description |
|
45
45
|
| ------ | ------ | ----------- |
|
46
|
-
| `getAllVaults(): Promise<Vault[]>`|
|
46
|
+
| `getAllVaults(): Promise<Vault[]>`| NO | Fetches details of all Drip Vaults. |
|
47
47
|
| `getVaultDetails(vaultAddress: string): Promise<Vault>` | NO | Fetches details of a specific Drip Vault identified by its address. |
|
48
|
-
| `
|
49
|
-
| `
|
48
|
+
| `getVaultStats(): Promise<VaultStats>`| NO | Returns some overall drip stats |
|
49
|
+
| `getTokenPrice(tokenName: string): Promise<number>`| NO | Returns the price for the given token (only works for weth at the moment) |
|
50
50
|
| `updateSigner(newSigner: Signer): Promise<void>`| NO | Updates the signer for the SDK instance. |
|
51
|
-
| `
|
51
|
+
| `isUserAuthenticated(): Promise<AuthenticationStatus>` | NO | Checks if the user is authenticated and returns authentication status along with relevant information. |
|
52
|
+
| `authenticate(): Promise<boolean>` | NO | Initiates the user authentication process and returns a boolean indicating success. |
|
52
53
|
| `deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>` | NO | The deposit function allows you to deposit tokens into a specific vault. Returns txHash. |
|
54
|
+
| `getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>`| YES | Returns the expected amount of tokens to get from a swap |
|
55
|
+
| `getUserBalance(): Promise<UserBalance>` | YES | Returns overall user balance information |
|
56
|
+
| `getUserBoostedNfts(vaultAddress: string): Promise<string[]>` | YES | Returns an array of boosted nfts addresses owned by the user |
|
57
|
+
| `getRewardsPerHour(vaultAddress: string): Promise<string[]>` | YES | Returns an estimated amount of tokens the user will receive in 1 hour as reward. It considers boost nfts the user owns for the estimation. |
|
58
|
+
| `getRewards(): Promise<UserRewards>` | YES | Fetches the current user's rewards points for each vault. |
|
59
|
+
| `getUserVaultBalance(): Promise<UserVaultBalance>` | YES | Fetches the user's balance for a specific Drip Vault. |
|
60
|
+
| `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. |
|
53
61
|
| `swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>` | YES | The swapAndDeposit function allows you to deposit a different token or ether and it will take care of swapping to the correct token before making the deposit. Returns txHash. |
|
54
62
|
| `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
63
|
| `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
|
-
| `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. |
|
58
64
|
|
59
65
|
|
60
66
|
> [!IMPORTANT]
|
@@ -190,6 +196,7 @@ type Vault = {
|
|
190
196
|
depositToken: VaultDepositToken
|
191
197
|
type: VaultType
|
192
198
|
rewards: VaultReward[]
|
199
|
+
rewardType: 'points' | 'token' | 'pnode shards'
|
193
200
|
liveUntil: string
|
194
201
|
liveUntilFormatted: string
|
195
202
|
hasPoolEnded: boolean
|
@@ -199,8 +206,7 @@ type Vault = {
|
|
199
206
|
newWithdraw: boolean
|
200
207
|
tgePrice?: number
|
201
208
|
maxAmountOfTokens?: number
|
202
|
-
|
203
|
-
}
|
209
|
+
};
|
204
210
|
|
205
211
|
type VaultType = 'launch' | 'earn' | 'airdrop'
|
206
212
|
|
@@ -213,13 +219,17 @@ type VaultDepositToken = {
|
|
213
219
|
}
|
214
220
|
|
215
221
|
type VaultReward = {
|
216
|
-
type: 'token' | 'points'
|
217
|
-
name: string
|
218
|
-
symbol: string
|
219
|
-
decimals: number
|
220
|
-
tokenAddress: string
|
221
|
-
monthlyEmissionRate
|
222
|
-
|
222
|
+
type: 'token' | 'points';
|
223
|
+
name: string;
|
224
|
+
symbol: string;
|
225
|
+
decimals: number;
|
226
|
+
tokenAddress: string;
|
227
|
+
monthlyEmissionRate: number;
|
228
|
+
blockNumber: number;
|
229
|
+
rewardrate: number;
|
230
|
+
timestamp: number;
|
231
|
+
endTime: number;
|
232
|
+
};
|
223
233
|
|
224
234
|
type NFTBoost = {
|
225
235
|
url: string
|
@@ -239,14 +249,6 @@ interface StretchGoal {
|
|
239
249
|
amountOfTokens: number
|
240
250
|
}
|
241
251
|
|
242
|
-
type RewardsInformation = {
|
243
|
-
[tokenAddress: string]: {
|
244
|
-
blockNumber: string;
|
245
|
-
rewardrate: string;
|
246
|
-
timestamp: string;
|
247
|
-
endTime: string }
|
248
|
-
}
|
249
|
-
|
250
252
|
type Strategy = {
|
251
253
|
address: string
|
252
254
|
lastDoHardWorkTime: number | null
|
@@ -283,6 +285,22 @@ type SwapInfo = {
|
|
283
285
|
}
|
284
286
|
|
285
287
|
type UserBalance = {
|
288
|
+
assets: {
|
289
|
+
asset: string,
|
290
|
+
dripping: string,
|
291
|
+
deposits: number,
|
292
|
+
depositsUSD: number,
|
293
|
+
tvr: number,
|
294
|
+
apy: number,
|
295
|
+
decimals: number,
|
296
|
+
reward: number
|
297
|
+
}[],
|
298
|
+
available: { [symbol: string] : number},
|
299
|
+
claimed: { [symbol: string] : number},
|
300
|
+
};
|
301
|
+
|
302
|
+
|
303
|
+
type UserVaultBalance = {
|
286
304
|
hasWithdrawsToClaim: boolean
|
287
305
|
userBalance: string
|
288
306
|
pendingUserBalance: string
|
@@ -290,8 +308,16 @@ type UserBalance = {
|
|
290
308
|
withdrawableBalance: string
|
291
309
|
};
|
292
310
|
|
311
|
+
|
293
312
|
type UserRewards = {
|
294
313
|
[vaultAddress: string]: { [rewardPointsName: string]: number }
|
295
314
|
};
|
296
315
|
|
316
|
+
type VaultStats = {
|
317
|
+
totalTVL: number
|
318
|
+
totalUsers: number
|
319
|
+
activeVaults: number
|
320
|
+
};
|
321
|
+
|
322
|
+
|
297
323
|
```
|
package/dist/DripApi.d.ts
CHANGED
@@ -3,11 +3,19 @@ import { Vault } from './types/Vault';
|
|
3
3
|
import { SwapInfo } from './types/SwapInfo';
|
4
4
|
import { QLFastRedeem } from './types/QLFastRedeem';
|
5
5
|
import { UserRewards } from './types/UserRewards';
|
6
|
+
import { VaultStats } from './types/VaultStats';
|
7
|
+
import { UserBalance } from './types/UserBalance';
|
6
8
|
export default class DripApi {
|
7
9
|
route: string;
|
8
10
|
constructor(route: string);
|
9
11
|
fetchAllVaults(): Promise<Vault[]>;
|
12
|
+
fetchTokenPrice(tokenName: string): Promise<number>;
|
13
|
+
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number, token: string): Promise<string>;
|
14
|
+
getUserBalance(walletAddress: string, token: string): Promise<UserBalance>;
|
15
|
+
getUserBoostedNfts(walletAddress: string, vaultAddress: string, token: string): Promise<string[]>;
|
16
|
+
fetchVaultStats(): Promise<VaultStats>;
|
10
17
|
fetchVaultDetails(vaultAddress: string): Promise<Vault>;
|
18
|
+
fetchRewardsPerHour(vaultAddress: string, token: string): Promise<number>;
|
11
19
|
getSwapInfo(fromTokenAddress: string, toTokenAddress: string, amount: BigNumber, fromAddress: string): Promise<SwapInfo[]>;
|
12
20
|
fetchUserSVTBalance(vaultAddress: string, walletAddress: string, token: string): Promise<BigNumber>;
|
13
21
|
fetchUserBalance(vaultAddress: string, walletAddress: string, token: string): Promise<Record<string, string>>;
|
package/dist/DripApi.js
CHANGED
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
const ethers_1 = require("ethers");
|
12
13
|
const WETH_TOKEN_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
13
14
|
class DripApi {
|
14
15
|
constructor(route) {
|
@@ -21,6 +22,67 @@ class DripApi {
|
|
21
22
|
return data;
|
22
23
|
});
|
23
24
|
}
|
25
|
+
fetchTokenPrice(tokenName) {
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
27
|
+
const res = yield fetch(`${this.route}/api-be/api/tokenPrice/?tokenName=${tokenName}`);
|
28
|
+
if (!res.ok) {
|
29
|
+
throw Error(yield res.text());
|
30
|
+
}
|
31
|
+
const data = yield res.json();
|
32
|
+
return data.usdPricePerToken;
|
33
|
+
});
|
34
|
+
}
|
35
|
+
getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, token) {
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
37
|
+
const headers = new Headers();
|
38
|
+
headers.append('Authorization', token);
|
39
|
+
const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
|
40
|
+
const queryParams = new URLSearchParams({
|
41
|
+
from: fromTokenAddress,
|
42
|
+
to: toTokenAddress,
|
43
|
+
amount: parsedAmount.toString(),
|
44
|
+
});
|
45
|
+
const res = yield fetch(`${this.route}/api-be/api/1inch/swap?${queryParams}`, {
|
46
|
+
headers,
|
47
|
+
});
|
48
|
+
const data = yield res.json();
|
49
|
+
if (res.ok) {
|
50
|
+
return data;
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
throw new Error(`HTTP error! status: ${res.status}`);
|
54
|
+
}
|
55
|
+
});
|
56
|
+
}
|
57
|
+
getUserBalance(walletAddress, token) {
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
59
|
+
const headers = new Headers();
|
60
|
+
headers.append('Authorization', token);
|
61
|
+
const res = yield fetch(`${this.route}/api-be/api/user/deposits/${walletAddress}`, {
|
62
|
+
headers,
|
63
|
+
});
|
64
|
+
const data = yield res.json();
|
65
|
+
return data;
|
66
|
+
});
|
67
|
+
}
|
68
|
+
getUserBoostedNfts(walletAddress, vaultAddress, token) {
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
70
|
+
const headers = new Headers();
|
71
|
+
headers.append('Authorization', token);
|
72
|
+
const res = yield fetch(`${this.route}/api-be/api/user/nftBoost/${walletAddress}/${vaultAddress}`, {
|
73
|
+
headers,
|
74
|
+
});
|
75
|
+
const data = yield res.json();
|
76
|
+
return data;
|
77
|
+
});
|
78
|
+
}
|
79
|
+
fetchVaultStats() {
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
81
|
+
const res = yield fetch(`${this.route}/api-be/api/vaultStats`);
|
82
|
+
const data = yield res.json();
|
83
|
+
return data;
|
84
|
+
});
|
85
|
+
}
|
24
86
|
fetchVaultDetails(vaultAddress) {
|
25
87
|
return __awaiter(this, void 0, void 0, function* () {
|
26
88
|
const res = yield fetch(`${this.route}/api-be/api/vault/${vaultAddress}`);
|
@@ -28,6 +90,20 @@ class DripApi {
|
|
28
90
|
return data;
|
29
91
|
});
|
30
92
|
}
|
93
|
+
fetchRewardsPerHour(vaultAddress, token) {
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
95
|
+
const headers = new Headers();
|
96
|
+
headers.append('Authorization', token);
|
97
|
+
const res = yield fetch(`${this.route}/api-be/api/user/rewardsPerHour/${vaultAddress}`, {
|
98
|
+
headers,
|
99
|
+
});
|
100
|
+
if (!res.ok) {
|
101
|
+
throw Error(yield res.text());
|
102
|
+
}
|
103
|
+
const data = yield res.json();
|
104
|
+
return data.rewardsPerHour;
|
105
|
+
});
|
106
|
+
}
|
31
107
|
getSwapInfo(fromTokenAddress, toTokenAddress, amount, fromAddress) {
|
32
108
|
return __awaiter(this, void 0, void 0, function* () {
|
33
109
|
if (fromTokenAddress === toTokenAddress && fromTokenAddress === WETH_TOKEN_ADDRESS) {
|
@@ -82,7 +158,7 @@ class DripApi {
|
|
82
158
|
return __awaiter(this, void 0, void 0, function* () {
|
83
159
|
const headers = new Headers();
|
84
160
|
headers.append('Authorization', token);
|
85
|
-
const res = yield fetch(
|
161
|
+
const res = yield fetch(`${this.route}/api-be/api/spool/user/wNft/${walletAddress}/${vaultAddress}`, {
|
86
162
|
headers,
|
87
163
|
});
|
88
164
|
const data = yield res.json();
|
package/dist/DripSdk.d.ts
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
import { Vault } from './types/Vault';
|
2
1
|
import { Signer } from 'ethers';
|
3
2
|
import { DripConfig } from './DripConfig';
|
4
|
-
import { UserBalance } from './types/UserBalance';
|
5
3
|
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
6
4
|
import { UserRewards } from './types/UserRewards';
|
5
|
+
import { VaultStats } from './types/VaultStats';
|
6
|
+
import { UserBalance } from './types/UserBalance';
|
7
|
+
import { UserVaultBalance } from './types/UserVaultBalance';
|
8
|
+
import { Vault } from './types/Vault';
|
7
9
|
export default class DripSdk {
|
8
10
|
private dripApi;
|
9
11
|
private spoolSdk?;
|
@@ -12,15 +14,21 @@ export default class DripSdk {
|
|
12
14
|
constructor(dripConfig: DripConfig, signer?: Signer);
|
13
15
|
getAllVaults(): Promise<Vault[]>;
|
14
16
|
getVaultDetails(vaultAddress: string): Promise<Vault>;
|
15
|
-
|
16
|
-
|
17
|
+
getVaultStats(): Promise<VaultStats>;
|
18
|
+
getTokenPrice(tokenName: string): Promise<number>;
|
17
19
|
updateSigner(newSigner: Signer): void;
|
18
|
-
|
19
|
-
|
20
|
-
fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<string>;
|
20
|
+
isUserAuthenticated(): Promise<AuthenticationStatus>;
|
21
|
+
authenticate(): Promise<boolean>;
|
21
22
|
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
23
|
+
getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>;
|
24
|
+
getUserBalance(): Promise<UserBalance>;
|
25
|
+
getUserBoostedNfts(vaultAddress: string): Promise<string[]>;
|
26
|
+
getRewardsPerHour(vaultAddress: string): Promise<number>;
|
27
|
+
getRewards(): Promise<UserRewards>;
|
28
|
+
getUserVaultBalance(vaultAddress: string): Promise<UserVaultBalance>;
|
29
|
+
fastWithdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
|
22
30
|
swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
|
23
|
-
withdraw(
|
31
|
+
withdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
|
24
32
|
claimWithdraws(vaultAddress: string): Promise<string>;
|
25
33
|
private generateOldRedeemBagStruct;
|
26
34
|
private generateNewRedeemBagStruct;
|
package/dist/DripSdk.js
CHANGED
@@ -38,27 +38,20 @@ class DripSdk {
|
|
38
38
|
return this.dripApi.fetchVaultDetails(vaultAddress);
|
39
39
|
});
|
40
40
|
}
|
41
|
-
|
41
|
+
getVaultStats() {
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
43
|
-
|
44
|
-
if (!this.signer) {
|
45
|
-
throw Error('No signer provided');
|
46
|
-
}
|
47
|
-
const address = yield this.signer.getAddress();
|
48
|
-
const cookieName = `auth_${address.toLowerCase()}`;
|
49
|
-
const token = yield web3_token_1.default.sign((msg) => __awaiter(this, void 0, void 0, function* () { return yield this.signer.signMessage(msg); }), {
|
50
|
-
statement: 'Please sign this message to authenticate.',
|
51
|
-
expires_in: '30d',
|
52
|
-
});
|
53
|
-
js_cookie_1.default.set(cookieName, token, { expires: 30 });
|
54
|
-
return true;
|
55
|
-
}
|
56
|
-
catch (error) {
|
57
|
-
console.error('Error obtaining token:', error);
|
58
|
-
}
|
59
|
-
return false;
|
43
|
+
return this.dripApi.fetchVaultStats();
|
60
44
|
});
|
61
45
|
}
|
46
|
+
getTokenPrice(tokenName) {
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
48
|
+
return this.dripApi.fetchTokenPrice(tokenName);
|
49
|
+
});
|
50
|
+
}
|
51
|
+
updateSigner(newSigner) {
|
52
|
+
this.signer = newSigner;
|
53
|
+
this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(this.dripConfig.internalConfig, newSigner);
|
54
|
+
}
|
62
55
|
isUserAuthenticated() {
|
63
56
|
return __awaiter(this, void 0, void 0, function* () {
|
64
57
|
try {
|
@@ -84,9 +77,91 @@ class DripSdk {
|
|
84
77
|
return { isAuthenticated: false };
|
85
78
|
});
|
86
79
|
}
|
87
|
-
|
88
|
-
this
|
89
|
-
|
80
|
+
authenticate() {
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
82
|
+
try {
|
83
|
+
if (!this.signer) {
|
84
|
+
throw Error('No signer provided');
|
85
|
+
}
|
86
|
+
const address = yield this.signer.getAddress();
|
87
|
+
const cookieName = `auth_${address.toLowerCase()}`;
|
88
|
+
const token = yield web3_token_1.default.sign((msg) => __awaiter(this, void 0, void 0, function* () { return yield this.signer.signMessage(msg); }), {
|
89
|
+
statement: 'Please sign this message to authenticate.',
|
90
|
+
expires_in: '30d',
|
91
|
+
});
|
92
|
+
js_cookie_1.default.set(cookieName, token, { expires: 30 });
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
catch (error) {
|
96
|
+
console.error('Error obtaining token:', error);
|
97
|
+
}
|
98
|
+
return false;
|
99
|
+
});
|
100
|
+
}
|
101
|
+
deposit(tokenAddress, vaultAddress, amount) {
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
103
|
+
if (!this.signer) {
|
104
|
+
throw Error('No signer provided');
|
105
|
+
}
|
106
|
+
const currentTokenAllowance = yield this.getTokenAllowanceForDeposit(tokenAddress);
|
107
|
+
const decimals = yield this.getERC20Precission(tokenAddress);
|
108
|
+
const amountToWithdrawFixedDecimals = parseFloat(amount).toFixed(decimals);
|
109
|
+
const amountToDeposit = ethers_1.ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals);
|
110
|
+
if (amountToDeposit.gt(currentTokenAllowance)) {
|
111
|
+
const requiredTokenAllowance = amountToDeposit.sub(currentTokenAllowance);
|
112
|
+
yield this.approveTokenForDeposit(tokenAddress, requiredTokenAllowance);
|
113
|
+
}
|
114
|
+
const signerAddress = yield this.signer.getAddress();
|
115
|
+
if (!signerAddress) {
|
116
|
+
throw Error('Error fetching address');
|
117
|
+
}
|
118
|
+
const depositBagStruct = {
|
119
|
+
smartVault: vaultAddress,
|
120
|
+
assets: [amountToDeposit],
|
121
|
+
receiver: signerAddress,
|
122
|
+
referral: ethers_1.ethers.constants.AddressZero,
|
123
|
+
doFlush: false,
|
124
|
+
};
|
125
|
+
const depositTx = yield this.spoolSdk.deposit(depositBagStruct);
|
126
|
+
const txReceipt = yield depositTx.wait();
|
127
|
+
return txReceipt.transactionHash;
|
128
|
+
});
|
129
|
+
}
|
130
|
+
getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals) {
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
132
|
+
const authData = yield this.isUserAuthenticated();
|
133
|
+
if (!authData.isAuthenticated) {
|
134
|
+
throw Error(`User not authenticated: ${authData.message}`);
|
135
|
+
}
|
136
|
+
return this.dripApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, authData.token);
|
137
|
+
});
|
138
|
+
}
|
139
|
+
getUserBalance() {
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
141
|
+
const authData = yield this.isUserAuthenticated();
|
142
|
+
if (!authData.isAuthenticated) {
|
143
|
+
throw Error(`User not authenticated: ${authData.message}`);
|
144
|
+
}
|
145
|
+
return this.dripApi.getUserBalance(authData.address, authData.token);
|
146
|
+
});
|
147
|
+
}
|
148
|
+
getUserBoostedNfts(vaultAddress) {
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
150
|
+
const authData = yield this.isUserAuthenticated();
|
151
|
+
if (!authData.isAuthenticated) {
|
152
|
+
throw Error(`User not authenticated: ${authData.message}`);
|
153
|
+
}
|
154
|
+
return this.dripApi.getUserBoostedNfts(authData.address, vaultAddress, authData.token);
|
155
|
+
});
|
156
|
+
}
|
157
|
+
getRewardsPerHour(vaultAddress) {
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
159
|
+
const authData = yield this.isUserAuthenticated();
|
160
|
+
if (!authData.isAuthenticated) {
|
161
|
+
throw Error(`User not authenticated: ${authData.message}`);
|
162
|
+
}
|
163
|
+
return this.dripApi.fetchRewardsPerHour(vaultAddress, authData.token);
|
164
|
+
});
|
90
165
|
}
|
91
166
|
getRewards() {
|
92
167
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -98,19 +173,20 @@ class DripSdk {
|
|
98
173
|
return userRewards;
|
99
174
|
});
|
100
175
|
}
|
101
|
-
|
176
|
+
getUserVaultBalance(vaultAddress) {
|
102
177
|
return __awaiter(this, void 0, void 0, function* () {
|
103
178
|
const authData = yield this.isUserAuthenticated();
|
104
179
|
if (!authData.isAuthenticated) {
|
105
180
|
throw Error(`User not authenticated: ${authData.message}`);
|
106
181
|
}
|
182
|
+
const vault = yield this.getVaultDetails(vaultAddress);
|
107
183
|
const userAddress = authData.address;
|
108
184
|
const token = authData.token;
|
109
|
-
const dnfts = yield this.dripApi.fetchAllUserDNFTForVault(
|
110
|
-
const wnfts = yield this.dripApi.fetchAllUserWNFTForVault(
|
185
|
+
const dnfts = yield this.dripApi.fetchAllUserDNFTForVault(vaultAddress, userAddress, token);
|
186
|
+
const wnfts = yield this.dripApi.fetchAllUserWNFTForVault(vaultAddress, userAddress, token);
|
111
187
|
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress);
|
112
188
|
if (this.shouldUseNewWithdrawLogic(userAddress, vault)) {
|
113
|
-
const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance] = yield this.calculateAllWithdrawalBalances(wnfts,
|
189
|
+
const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance] = yield this.calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals, token);
|
114
190
|
const hasWithdrawsToClaim = this.checkIfUserHasWithdrawsToClaim(wnfts);
|
115
191
|
const pendingDeposits = this.calculatePendingDeposits(dnfts, decimals);
|
116
192
|
const userBalance = this.calculateAllDeposits(dnfts, decimals).sub(pendingDeposits);
|
@@ -143,7 +219,7 @@ class DripSdk {
|
|
143
219
|
}
|
144
220
|
});
|
145
221
|
}
|
146
|
-
fastWithdraw(
|
222
|
+
fastWithdraw(vaultAddress, amountToWithdraw) {
|
147
223
|
return __awaiter(this, void 0, void 0, function* () {
|
148
224
|
var _a, _b;
|
149
225
|
const authData = yield this.isUserAuthenticated();
|
@@ -153,6 +229,7 @@ class DripSdk {
|
|
153
229
|
if (!this.signer) {
|
154
230
|
throw Error('No signer provided');
|
155
231
|
}
|
232
|
+
const vault = yield this.getVaultDetails(vaultAddress);
|
156
233
|
const redeemBagStruct = this.shouldUseNewWithdrawLogic(authData.address, vault)
|
157
234
|
? yield this.generateNewRedeemBagStruct(authData.token, vault, authData.address, amountToWithdraw)
|
158
235
|
: yield this.generateOldRedeemBagStruct(authData.token, vault, authData.address, amountToWithdraw);
|
@@ -165,35 +242,6 @@ class DripSdk {
|
|
165
242
|
return txReceipt.transactionHash;
|
166
243
|
});
|
167
244
|
}
|
168
|
-
deposit(tokenAddress, vaultAddress, amount) {
|
169
|
-
return __awaiter(this, void 0, void 0, function* () {
|
170
|
-
if (!this.signer) {
|
171
|
-
throw Error('No signer provided');
|
172
|
-
}
|
173
|
-
const currentTokenAllowance = yield this.getTokenAllowanceForDeposit(tokenAddress);
|
174
|
-
const decimals = yield this.getERC20Precission(tokenAddress);
|
175
|
-
const amountToWithdrawFixedDecimals = parseFloat(amount).toFixed(decimals);
|
176
|
-
const amountToDeposit = ethers_1.ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals);
|
177
|
-
if (amountToDeposit.gt(currentTokenAllowance)) {
|
178
|
-
const requiredTokenAllowance = amountToDeposit.sub(currentTokenAllowance);
|
179
|
-
yield this.approveTokenForDeposit(tokenAddress, requiredTokenAllowance);
|
180
|
-
}
|
181
|
-
const signerAddress = yield this.signer.getAddress();
|
182
|
-
if (!signerAddress) {
|
183
|
-
throw Error('Error fetching address');
|
184
|
-
}
|
185
|
-
const depositBagStruct = {
|
186
|
-
smartVault: vaultAddress,
|
187
|
-
assets: [amountToDeposit],
|
188
|
-
receiver: signerAddress,
|
189
|
-
referral: ethers_1.ethers.constants.AddressZero,
|
190
|
-
doFlush: false,
|
191
|
-
};
|
192
|
-
const depositTx = yield this.spoolSdk.deposit(depositBagStruct);
|
193
|
-
const txReceipt = yield depositTx.wait();
|
194
|
-
return txReceipt.transactionHash;
|
195
|
-
});
|
196
|
-
}
|
197
245
|
swapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
|
198
246
|
return __awaiter(this, void 0, void 0, function* () {
|
199
247
|
const authData = yield this.isUserAuthenticated();
|
@@ -229,7 +277,7 @@ class DripSdk {
|
|
229
277
|
return txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.transactionHash;
|
230
278
|
});
|
231
279
|
}
|
232
|
-
withdraw(
|
280
|
+
withdraw(vaultAddress, amountToWithdraw) {
|
233
281
|
return __awaiter(this, void 0, void 0, function* () {
|
234
282
|
const authData = yield this.isUserAuthenticated();
|
235
283
|
if (!authData.isAuthenticated) {
|
@@ -238,6 +286,7 @@ class DripSdk {
|
|
238
286
|
if (!this.signer) {
|
239
287
|
throw Error('No signer provided');
|
240
288
|
}
|
289
|
+
const vault = yield this.getVaultDetails(vaultAddress);
|
241
290
|
const redeemBagStruct = this.shouldUseNewWithdrawLogic(authData.address, vault)
|
242
291
|
? yield this.generateNewRedeemBagStruct(authData.token, vault, authData.address, amountToWithdraw)
|
243
292
|
: yield this.generateOldRedeemBagStruct(authData.token, vault, authData.address, amountToWithdraw);
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
import DripSdk from './DripSdk';
|
2
2
|
import { Vault } from './types/Vault';
|
3
|
+
import { VaultReward } from './types/VaultReward';
|
4
|
+
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
5
|
+
import { NFTBoost } from './types/NFTBoost';
|
6
|
+
import { Strategy } from './types/Strategy';
|
7
|
+
import { StretchGoal } from './types/StretchGoal';
|
8
|
+
import { SwapInfo } from './types/SwapInfo';
|
9
|
+
import { VaultDepositToken } from './types/VaultDepositToken';
|
10
|
+
import { VaultType } from './types/VaultType';
|
11
|
+
import { UserVaultBalance } from './types/UserVaultBalance';
|
3
12
|
import { UserBalance } from './types/UserBalance';
|
13
|
+
import { VaultStats } from './types/VaultStats';
|
4
14
|
import { DripConfig } from './DripConfig';
|
5
|
-
export { Vault, DripSdk, DripConfig, UserBalance };
|
15
|
+
export { Vault, VaultReward, DripSdk, DripConfig, UserVaultBalance, UserBalance, VaultStats, AuthenticationStatus, NFTBoost, Strategy, StretchGoal, SwapInfo, VaultDepositToken, VaultType };
|
@@ -1,7 +1,18 @@
|
|
1
1
|
export type UserBalance = {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
assets: {
|
3
|
+
asset: string;
|
4
|
+
dripping: string;
|
5
|
+
deposits: number;
|
6
|
+
depositsUSD: number;
|
7
|
+
tvr: number;
|
8
|
+
apy: number;
|
9
|
+
decimals: number;
|
10
|
+
reward: number;
|
11
|
+
}[];
|
12
|
+
available: {
|
13
|
+
[symbol: string]: number;
|
14
|
+
};
|
15
|
+
claimed: {
|
16
|
+
[symbol: string]: number;
|
17
|
+
};
|
7
18
|
};
|
package/dist/types/Vault.d.ts
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
import { NFTBoost } from './NFTBoost';
|
2
|
+
import { Strategy } from './Strategy';
|
3
|
+
import { StretchGoal } from './StretchGoal';
|
4
|
+
import { VaultDepositToken } from './VaultDepositToken';
|
5
|
+
import { VaultReward } from './VaultReward';
|
6
|
+
import { VaultType } from './VaultType';
|
1
7
|
export type Vault = {
|
2
8
|
vaultName: string;
|
3
9
|
vaultAddress: string;
|
@@ -8,6 +14,7 @@ export type Vault = {
|
|
8
14
|
depositToken: VaultDepositToken;
|
9
15
|
type: VaultType;
|
10
16
|
rewards: VaultReward[];
|
17
|
+
rewardType: 'points' | 'token' | 'pnode shards';
|
11
18
|
liveUntil: string;
|
12
19
|
liveUntilFormatted: string;
|
13
20
|
hasPoolEnded: boolean;
|
@@ -17,50 +24,4 @@ export type Vault = {
|
|
17
24
|
newWithdraw: boolean;
|
18
25
|
tgePrice?: number;
|
19
26
|
maxAmountOfTokens?: number;
|
20
|
-
rewardsInformation: RewardsInformation;
|
21
|
-
};
|
22
|
-
export type VaultType = 'launch' | 'earn' | 'airdrop';
|
23
|
-
export type VaultDepositToken = {
|
24
|
-
name: string;
|
25
|
-
symbol: string;
|
26
|
-
roundingDecimals: number;
|
27
|
-
precisionDecimals: number;
|
28
|
-
tokenAddress: string;
|
29
|
-
};
|
30
|
-
export type VaultReward = {
|
31
|
-
type: 'token' | 'points';
|
32
|
-
name: string;
|
33
|
-
symbol: string;
|
34
|
-
decimals: number;
|
35
|
-
tokenAddress: string;
|
36
|
-
monthlyEmissionRate?: number;
|
37
|
-
};
|
38
|
-
export type NFTBoost = {
|
39
|
-
url: string;
|
40
|
-
tokenAddress: string;
|
41
|
-
multiplier: number;
|
42
|
-
nftAddress: string;
|
43
|
-
network: string;
|
44
|
-
initialBlock: number;
|
45
|
-
imagePath: string;
|
46
|
-
};
|
47
|
-
export interface StretchGoal {
|
48
|
-
threshhold: number;
|
49
|
-
threshholdDescription: string;
|
50
|
-
rewardTooltip: string;
|
51
|
-
rewardDescription: string;
|
52
|
-
amountOfTokens: number;
|
53
|
-
}
|
54
|
-
export type RewardsInformation = {
|
55
|
-
[tokenAddress: string]: {
|
56
|
-
blockNumber: string;
|
57
|
-
rewardrate: string;
|
58
|
-
timestamp: string;
|
59
|
-
endTime: string;
|
60
|
-
};
|
61
|
-
};
|
62
|
-
export type Strategy = {
|
63
|
-
address: string;
|
64
|
-
lastDoHardWorkTime: number | null;
|
65
|
-
lastDoHardWorkBlock: number | null;
|
66
27
|
};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
export type VaultReward = {
|
2
|
+
type: 'token' | 'points';
|
3
|
+
name: string;
|
4
|
+
symbol: string;
|
5
|
+
decimals: number;
|
6
|
+
tokenAddress: string;
|
7
|
+
monthlyEmissionRate: number;
|
8
|
+
blockNumber: number;
|
9
|
+
rewardrate: number;
|
10
|
+
timestamp: number;
|
11
|
+
endTime: number;
|
12
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export type VaultType = 'launch' | 'earn' | 'airdrop';
|
package/dist/utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.insertDot =
|
3
|
+
exports.insertDot = insertDot;
|
4
4
|
function insertDot(numberString, decimals) {
|
5
5
|
if (numberString.length < decimals + 1) {
|
6
6
|
numberString = '0'.repeat(decimals + 1 - numberString.length) + numberString;
|
@@ -11,4 +11,3 @@ function insertDot(numberString, decimals) {
|
|
11
11
|
const afterDecimal = numberString.slice(indexToInsertDot);
|
12
12
|
return `${beforeDecimal}.${afterDecimal}`;
|
13
13
|
}
|
14
|
-
exports.insertDot = insertDot;
|