@dripfi/drip-sdk 1.0.10 → 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/.eslintrc.json +38 -0
- package/.vscode/settings.json +17 -0
- package/README.md +155 -28
- package/dist/DripApi.d.ts +2 -0
- package/dist/DripApi.js +11 -0
- package/dist/DripConfig.js +4 -2
- package/dist/DripSdk.d.ts +7 -5
- package/dist/DripSdk.js +85 -85
- package/dist/types/UserRewards.d.ts +5 -0
- package/dist/types/UserRewards.js +2 -0
- package/package.json +8 -7
- package/.prettierignore +0 -2
- package/.prettierrc +0 -11
- package/dist/test.d.ts +0 -2
- package/dist/test.js +0 -24
package/.eslintrc.json
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
{
|
2
|
+
"env": {
|
3
|
+
"browser": true,
|
4
|
+
"es2021": true
|
5
|
+
},
|
6
|
+
"extends": [
|
7
|
+
"eslint:recommended",
|
8
|
+
"plugin:@typescript-eslint/recommended"
|
9
|
+
],
|
10
|
+
"parser": "@typescript-eslint/parser",
|
11
|
+
"parserOptions": {
|
12
|
+
"ecmaVersion": "latest",
|
13
|
+
"sourceType": "module"
|
14
|
+
},
|
15
|
+
"plugins": [
|
16
|
+
"@typescript-eslint"
|
17
|
+
],
|
18
|
+
"rules": {
|
19
|
+
"quotes": [
|
20
|
+
"error",
|
21
|
+
"single"
|
22
|
+
],
|
23
|
+
"semi": "off",
|
24
|
+
"@typescript-eslint/semi": "error",
|
25
|
+
"@typescript-eslint/no-explicit-any": "off",
|
26
|
+
"curly": "error"
|
27
|
+
},
|
28
|
+
"overrides": [
|
29
|
+
{
|
30
|
+
"files": [
|
31
|
+
"tests/**/*"
|
32
|
+
],
|
33
|
+
"env": {
|
34
|
+
"jest": true
|
35
|
+
}
|
36
|
+
}
|
37
|
+
]
|
38
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
3
|
+
"editor.codeActionsOnSave": {
|
4
|
+
"source.fixAll.eslint": "explicit"
|
5
|
+
},
|
6
|
+
"editor.formatOnSave": true,
|
7
|
+
"[javascript]": {
|
8
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
9
|
+
},
|
10
|
+
"[typescript]": {
|
11
|
+
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
12
|
+
},
|
13
|
+
"eslint.workingDirectories": [
|
14
|
+
{"directory": "./src", "changeProcessCWD": true},
|
15
|
+
]
|
16
|
+
}
|
17
|
+
|
package/README.md
CHANGED
@@ -4,7 +4,14 @@
|
|
4
4
|
|
5
5
|
The Drip SDK is a TypeScript library designed to interact with the Drip protocol. It provides methods to retrieve information about Drip Vaults, manage user authentication, and fetch user balances.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Table of Contents
|
8
|
+
- [Installation](#installation)
|
9
|
+
- [Usage](#usage)
|
10
|
+
- [Methods](#methods)
|
11
|
+
- [Examples](#examples)
|
12
|
+
- [Types](#types)
|
13
|
+
|
14
|
+
# Installation
|
8
15
|
|
9
16
|
To use the Drip SDK in your project, you can install it via npm or yarn:
|
10
17
|
|
@@ -12,7 +19,7 @@ To use the Drip SDK in your project, you can install it via npm or yarn:
|
|
12
19
|
npm i @dripfi/drip-sdk
|
13
20
|
```
|
14
21
|
|
15
|
-
|
22
|
+
# Usage
|
16
23
|
|
17
24
|
```typescript
|
18
25
|
import DripSdk from '@drip/sdk'
|
@@ -32,44 +39,147 @@ const signer: ethers.Signer = /* your Signer instance */;
|
|
32
39
|
const dripSdk = new DripSdk(dripConfig, signer);
|
33
40
|
```
|
34
41
|
|
35
|
-
|
42
|
+
# Methods
|
43
|
+
|
44
|
+
| Name | Requires authentication | Description |
|
45
|
+
| ------ | ------ | ----------- |
|
46
|
+
| `getAllVaults(): Promise<Vault[]>`| No | Fetches details of all Drip Vaults. |
|
47
|
+
| `getVaultDetails(vaultAddress: string): Promise<Vault>` | NO | Fetches details of a specific Drip Vault identified by its address. |
|
48
|
+
| `authenticate(): Promise<boolean>` | NO | Initiates the user authentication process and returns a boolean indicating success. |
|
49
|
+
| `isUserAuthenticated(): Promise<AuthenticationStatus>` | NO | Checks if the user is authenticated and returns authentication status along with relevant information. |
|
50
|
+
| `updateSigner(newSigner: Signer): Promise<void>`| NO | Updates the signer for the SDK instance. |
|
51
|
+
| `getUserBalance(vault: Vault): Promise<UserBalance>` | YES | Fetches the user's balance for a specific Drip Vault. |
|
52
|
+
| `deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>` | NO | The deposit function allows you to deposit tokens into a specific vault. Returns txHash. |
|
53
|
+
| `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
|
+
| `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
|
+
| `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
|
+
|
59
|
+
|
60
|
+
> [!IMPORTANT]
|
61
|
+
> **You must authenticate once for every wallet you want to use**
|
62
|
+
|
63
|
+
---
|
64
|
+
|
65
|
+
# Examples
|
66
|
+
|
67
|
+
### `deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>`
|
68
|
+
|
69
|
+
I want to deposit 100 USDC in a USDC vault:
|
70
|
+
```typescript
|
71
|
+
USDC_TOKEN_ADDRESS = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" --> USDC contract address in tenderly environment
|
72
|
+
```
|
73
|
+
you can get vault token address from the vault.depositToken.tokenAddress
|
74
|
+
|
75
|
+
```typescript
|
76
|
+
VAULT_ADDRESS = "0x...c167" --> Check vaults returned by getAllVaults() and get vault address like: vault.vaultAddress
|
77
|
+
|
78
|
+
const txHash = await deposit(USDC_TOKEN_ADDRESS, VAULT_ADDRESS, '100')
|
79
|
+
```
|
80
|
+
|
81
|
+
> [!NOTE]
|
82
|
+
> User will be prompted with 2 tx:
|
83
|
+
> 1st to approve token usage
|
84
|
+
> 2nd to deposit the funds in the vault
|
85
|
+
|
86
|
+
> [!NOTE]
|
87
|
+
> Allowance is calculated by the deposit method, based on the current allowance and the required
|
88
|
+
|
89
|
+
> [!IMPORTANT]
|
90
|
+
> Amount should be formatted, not parsed. In the example we want to deposit 100 USDC so we just input that value instead of adding 6 decimals (100000000)
|
91
|
+
|
92
|
+
---
|
93
|
+
|
94
|
+
### `swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>`
|
95
|
+
|
96
|
+
I want to deposit 1.5ETH in a WETH vault:
|
97
|
+
|
98
|
+
```typescript
|
99
|
+
WETH_TOKEN_ADDRESS = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" --> WETH contract address in tenderly environment
|
100
|
+
|
101
|
+
const txHash = await swapAndDeposit(WETH_TOKEN_ADDRESS, WETH_TOKEN_ADDRESS, '0', vaultAddress, '1.5')
|
102
|
+
```
|
103
|
+
you can get vault token address from the vault.depositToken.tokenAddress
|
104
|
+
|
105
|
+
> [!IMPORTANT]
|
106
|
+
> ethAmount and fromTokenAmount should be formatted, not parsed. In the example we want to deposit 1.5 WETH so we just input that value instead of adding 18 decimals (1500000000000000000)
|
107
|
+
|
108
|
+
---
|
109
|
+
|
110
|
+
### `withdraw(vault: Vault, amountToWithdraw?: string): Promise<string>`
|
111
|
+
|
112
|
+
```typescript
|
113
|
+
const userBalanceObject = await getUserBalance()
|
114
|
+
const balance = userBalanceObject.userbalance
|
115
|
+
```
|
116
|
+
> [!NOTE]
|
117
|
+
> If i check balance, that is the max amount I can withdraw
|
118
|
+
|
119
|
+
I want to withdraw 100 USDC from the 1st vault fetched. ---> Let's assume the first vault is a USDC vault for simplicity
|
120
|
+
Fetch vaults returned by getAllVault() and pass the vault you want to withdraw from, and the amount to withdraw (100 in this example)
|
36
121
|
|
37
|
-
|
38
|
-
|
122
|
+
```typescript
|
123
|
+
const vaults = await getAllVaults()
|
124
|
+
const vaultToWithdrawFrom = vaults[0]
|
39
125
|
|
40
|
-
|
41
|
-
|
126
|
+
const txHash = await withdraw(vaultToWithdrawFrom, '100')
|
127
|
+
```
|
42
128
|
|
43
|
-
|
44
|
-
Initiates the user authentication process and returns a boolean indicating success.
|
129
|
+
if you want to withdraw all funds in the vault, don't specify the amountToWithdraw:
|
45
130
|
|
46
|
-
|
47
|
-
|
131
|
+
```typescript
|
132
|
+
const txHash = await withdraw(vaultToWithdrawFrom)
|
133
|
+
```
|
134
|
+
> [!IMPORTANT]
|
135
|
+
> you will have to claim your withdraws after DHW is processed to transfer the withdrawn funds to your wallet
|
48
136
|
|
49
|
-
|
50
|
-
Updates the signer for the SDK instance.
|
137
|
+
---
|
51
138
|
|
52
|
-
|
53
|
-
Fetches the user's balance for a specific Drip Vault.
|
139
|
+
### `claimWithdraws(vaultAddress: string): Promise<string>`
|
54
140
|
|
55
|
-
|
56
|
-
|
141
|
+
```typescript
|
142
|
+
const userBalanceObject = await getUserBalance()
|
143
|
+
const hasWithdrawsToClaim = userBalanceObject.hasWithdrawsToClaim
|
144
|
+
```
|
145
|
+
if hasWithdrawsToClaim is true you have available funds to transfer to your address
|
57
146
|
|
58
|
-
|
59
|
-
|
147
|
+
```typescript
|
148
|
+
const txHash = await claimWithdraws()
|
149
|
+
```
|
150
|
+
It will transfer all available funds withdrawn with withdraw() function, to your address
|
60
151
|
|
61
|
-
|
62
|
-
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()
|
152
|
+
---
|
63
153
|
|
64
|
-
|
65
|
-
After the withdrawal has been processed by the 'DoHardWork' function, the 'claimWithdraws' function transfers the withdrawn tokens to their personal account.
|
154
|
+
### `fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<string>`
|
66
155
|
|
67
|
-
|
68
|
-
|
156
|
+
```typescript
|
157
|
+
const userBalanceObject = await getUserBalance()
|
158
|
+
const balance = userBalanceObject.userbalance
|
159
|
+
```
|
69
160
|
|
70
|
-
|
161
|
+
> [!NOTE]
|
162
|
+
> If i check balance, that is the max amount I can withdraw
|
71
163
|
|
164
|
+
I want to withdraw 3.55 WETH from the 1st vault fetched. ---> Let's assume the first vault is a WETH vault for simplicity
|
165
|
+
Fetch vaults returned by getAllVault() and pass the vault you want to withdraw from, and the amount to withdraw (3.55 in this example)
|
166
|
+
|
167
|
+
```typescript
|
168
|
+
const vaults = await getAllVaults()
|
169
|
+
const vaultToWithdrawFrom = vaults[0]
|
170
|
+
|
171
|
+
const txHash = await fastWithdraw(vaultToWithdrawFrom, '3.55')
|
172
|
+
```
|
173
|
+
|
174
|
+
if you want to withdraw all funds in the vault, don't specify the amountToWithdraw, like:
|
175
|
+
|
176
|
+
```typescript
|
177
|
+
const txHash = await fastWithdraw(vaultToWithdrawFrom)
|
72
178
|
```
|
179
|
+
|
180
|
+
# Types
|
181
|
+
|
182
|
+
```typescript
|
73
183
|
type Vault = {
|
74
184
|
vaultName: string
|
75
185
|
vaultAddress: string
|
@@ -117,7 +227,7 @@ type NFTBoost = {
|
|
117
227
|
multiplier: number
|
118
228
|
nftAddress: string
|
119
229
|
network: string
|
120
|
-
initialBlock: number
|
230
|
+
initialBlock: number
|
121
231
|
imagePath: string
|
122
232
|
}
|
123
233
|
|
@@ -130,7 +240,11 @@ interface StretchGoal {
|
|
130
240
|
}
|
131
241
|
|
132
242
|
type RewardsInformation = {
|
133
|
-
[tokenAddress: string]: {
|
243
|
+
[tokenAddress: string]: {
|
244
|
+
blockNumber: string;
|
245
|
+
rewardrate: string;
|
246
|
+
timestamp: string;
|
247
|
+
endTime: string }
|
134
248
|
}
|
135
249
|
|
136
250
|
type Strategy = {
|
@@ -167,4 +281,17 @@ type SwapInfo = {
|
|
167
281
|
token: string
|
168
282
|
swapCallData: any
|
169
283
|
}
|
284
|
+
|
285
|
+
type UserBalance = {
|
286
|
+
hasWithdrawsToClaim: boolean
|
287
|
+
userBalance: string
|
288
|
+
pendingUserBalance: string
|
289
|
+
pendingWithdrawalBalance: string
|
290
|
+
withdrawableBalance: string
|
291
|
+
};
|
292
|
+
|
293
|
+
type UserRewards = {
|
294
|
+
[key: string]: { [key: string]: number }
|
295
|
+
};
|
296
|
+
|
170
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/DripConfig.js
CHANGED
@@ -18,8 +18,9 @@ class DripConfig {
|
|
18
18
|
}
|
19
19
|
getSwapAndDepositContractAddress(signer) {
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
21
|
-
if (!signer)
|
21
|
+
if (!signer) {
|
22
22
|
throw Error('No signer provided');
|
23
|
+
}
|
23
24
|
if (!this.swapAndDepositContractAddress) {
|
24
25
|
const contract = yield this.internalConfig.getChainAddresses(signer);
|
25
26
|
this.swapAndDepositContractAddress = contract.IDepositSwap;
|
@@ -29,8 +30,9 @@ class DripConfig {
|
|
29
30
|
}
|
30
31
|
getSmartVaultManagerAddress(signer) {
|
31
32
|
return __awaiter(this, void 0, void 0, function* () {
|
32
|
-
if (!signer)
|
33
|
+
if (!signer) {
|
33
34
|
throw Error('No signer provided');
|
35
|
+
}
|
34
36
|
if (!this.smartVaultManagerAddress) {
|
35
37
|
const contract = yield this.internalConfig.getChainAddresses(signer);
|
36
38
|
this.smartVaultManagerAddress = contract.ISmartVaultManager;
|
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,12 +15,13 @@ 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
|
-
fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<
|
19
|
-
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<
|
20
|
-
swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<
|
21
|
-
withdraw(vault: Vault, amountToWithdraw?: string): Promise<
|
22
|
-
claimWithdraws(vaultAddress: string): Promise<
|
20
|
+
fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<string>;
|
21
|
+
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
|
22
|
+
swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
|
23
|
+
withdraw(vault: Vault, amountToWithdraw?: string): Promise<string>;
|
24
|
+
claimWithdraws(vaultAddress: string): Promise<string>;
|
23
25
|
private generateOldRedeemBagStruct;
|
24
26
|
private generateNewRedeemBagStruct;
|
25
27
|
private getAllSvts;
|
package/dist/DripSdk.js
CHANGED
@@ -41,8 +41,9 @@ class DripSdk {
|
|
41
41
|
authenticate() {
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
43
43
|
try {
|
44
|
-
if (!this.signer)
|
44
|
+
if (!this.signer) {
|
45
45
|
throw Error('No signer provided');
|
46
|
+
}
|
46
47
|
const address = yield this.signer.getAddress();
|
47
48
|
const cookieName = `auth_${address.toLowerCase()}`;
|
48
49
|
const token = yield web3_token_1.default.sign((msg) => __awaiter(this, void 0, void 0, function* () { return yield this.signer.signMessage(msg); }), {
|
@@ -87,11 +88,22 @@ class DripSdk {
|
|
87
88
|
this.signer = newSigner;
|
88
89
|
this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(this.dripConfig.internalConfig, newSigner);
|
89
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
|
+
}
|
90
101
|
getUserBalance(vault) {
|
91
102
|
return __awaiter(this, void 0, void 0, function* () {
|
92
103
|
const authData = yield this.isUserAuthenticated();
|
93
|
-
if (!authData.isAuthenticated)
|
104
|
+
if (!authData.isAuthenticated) {
|
94
105
|
throw Error(`User not authenticated: ${authData.message}`);
|
106
|
+
}
|
95
107
|
const userAddress = authData.address;
|
96
108
|
const token = authData.token;
|
97
109
|
const dnfts = yield this.dripApi.fetchAllUserDNFTForVault(vault.vaultAddress, userAddress, token);
|
@@ -116,7 +128,7 @@ class DripSdk {
|
|
116
128
|
const [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance, estimatedWithdrawals] = yield this.calculateAllWithdrawalBalances(wnfts, vault.vaultAddress, decimals, token);
|
117
129
|
const fastWithdrawBalance = yield this.calculateFastWithdrawBalancesOld(authData.token, vault.vaultAddress, userAddress, decimals);
|
118
130
|
const hasWithdrawsToClaim = this.checkIfUserHasWithdrawsToClaim(wnfts);
|
119
|
-
|
131
|
+
const balance = allDeposits
|
120
132
|
.sub(estimatedWithdrawals)
|
121
133
|
.sub(estimatedWithdrawableBalance)
|
122
134
|
.sub(estimatedPendingWithdrawalBalance)
|
@@ -135,46 +147,41 @@ class DripSdk {
|
|
135
147
|
return __awaiter(this, void 0, void 0, function* () {
|
136
148
|
var _a, _b;
|
137
149
|
const authData = yield this.isUserAuthenticated();
|
138
|
-
if (!authData.isAuthenticated)
|
150
|
+
if (!authData.isAuthenticated) {
|
139
151
|
throw Error(`User not authenticated: ${authData.message}`);
|
140
|
-
|
152
|
+
}
|
153
|
+
if (!this.signer) {
|
141
154
|
throw Error('No signer provided');
|
142
|
-
try {
|
143
|
-
const signerAddress = yield this.signer.getAddress();
|
144
|
-
if (!signerAddress)
|
145
|
-
throw Error('Error fetching address');
|
146
|
-
const redeemBagStruct = this.shouldUseNewWithdrawLogic(signerAddress, vault)
|
147
|
-
? yield this.generateNewRedeemBagStruct(authData.token, vault, signerAddress, amountToWithdraw)
|
148
|
-
: yield this.generateOldRedeemBagStruct(authData.token, vault, signerAddress, amountToWithdraw);
|
149
|
-
const currentBlockNumber = yield ((_a = this.signer.provider) === null || _a === void 0 ? void 0 : _a.getBlockNumber());
|
150
|
-
if (!currentBlockNumber)
|
151
|
-
throw Error('Error fetching block number');
|
152
|
-
const redeemTx = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.redeemFast(redeemBagStruct, signerAddress.toLowerCase(), currentBlockNumber));
|
153
|
-
const redeemTxReceipt = yield redeemTx.wait();
|
154
155
|
}
|
155
|
-
|
156
|
-
|
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);
|
159
|
+
const currentBlockNumber = yield ((_a = this.signer.provider) === null || _a === void 0 ? void 0 : _a.getBlockNumber());
|
160
|
+
if (!currentBlockNumber) {
|
161
|
+
throw Error('Error fetching block number');
|
157
162
|
}
|
163
|
+
const redeemTx = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.redeemFast(redeemBagStruct, authData.address, currentBlockNumber));
|
164
|
+
const txReceipt = yield redeemTx.wait();
|
165
|
+
return txReceipt.transactionHash;
|
158
166
|
});
|
159
167
|
}
|
160
168
|
deposit(tokenAddress, vaultAddress, amount) {
|
161
169
|
return __awaiter(this, void 0, void 0, function* () {
|
162
|
-
|
163
|
-
if (!authData.isAuthenticated)
|
164
|
-
throw Error(`User not authenticated: ${authData.message}`);
|
165
|
-
if (!this.signer)
|
170
|
+
if (!this.signer) {
|
166
171
|
throw Error('No signer provided');
|
172
|
+
}
|
167
173
|
const currentTokenAllowance = yield this.getTokenAllowanceForDeposit(tokenAddress);
|
168
174
|
const decimals = yield this.getERC20Precission(tokenAddress);
|
169
|
-
|
175
|
+
const amountToWithdrawFixedDecimals = parseFloat(amount).toFixed(decimals);
|
170
176
|
const amountToDeposit = ethers_1.ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals);
|
171
177
|
if (amountToDeposit.gt(currentTokenAllowance)) {
|
172
178
|
const requiredTokenAllowance = amountToDeposit.sub(currentTokenAllowance);
|
173
179
|
yield this.approveTokenForDeposit(tokenAddress, requiredTokenAllowance);
|
174
180
|
}
|
175
181
|
const signerAddress = yield this.signer.getAddress();
|
176
|
-
if (!signerAddress)
|
182
|
+
if (!signerAddress) {
|
177
183
|
throw Error('Error fetching address');
|
184
|
+
}
|
178
185
|
const depositBagStruct = {
|
179
186
|
smartVault: vaultAddress,
|
180
187
|
assets: [amountToDeposit],
|
@@ -183,81 +190,72 @@ class DripSdk {
|
|
183
190
|
doFlush: false,
|
184
191
|
};
|
185
192
|
const depositTx = yield this.spoolSdk.deposit(depositBagStruct);
|
186
|
-
yield depositTx.wait();
|
193
|
+
const txReceipt = yield depositTx.wait();
|
194
|
+
return txReceipt.transactionHash;
|
187
195
|
});
|
188
196
|
}
|
189
197
|
swapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
|
190
198
|
return __awaiter(this, void 0, void 0, function* () {
|
191
|
-
var _a, _b;
|
192
199
|
const authData = yield this.isUserAuthenticated();
|
193
|
-
if (!authData.isAuthenticated)
|
200
|
+
if (!authData.isAuthenticated) {
|
194
201
|
throw Error(`User not authenticated: ${authData.message}`);
|
195
|
-
|
202
|
+
}
|
203
|
+
if (!this.signer) {
|
196
204
|
throw Error('No signer provided');
|
205
|
+
}
|
197
206
|
const decimals = yield this.getERC20Precission(fromTokenAddress);
|
198
207
|
const amountToWithdrawFixedDecimals = parseFloat(fromTokenAmount).toFixed(decimals);
|
199
208
|
const fromToken = ethers_1.ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals);
|
200
|
-
const signerAddress = yield this.signer.getAddress();
|
201
209
|
if (fromToken.gt(ethers_1.BigNumber.from(0))) {
|
202
|
-
const currentTokenAllowance = yield this.getTokenAllowanceForSwapAndDepositContractAddress(fromTokenAddress);
|
210
|
+
const currentTokenAllowance = yield this.getTokenAllowanceForSwapAndDepositContractAddress(fromTokenAddress, authData.address);
|
203
211
|
if (fromToken.gt(currentTokenAllowance)) {
|
204
212
|
yield this.approveTokenForSwapAndDepositContract(fromTokenAddress, fromToken.sub(currentTokenAllowance));
|
205
213
|
}
|
206
214
|
}
|
207
|
-
const swapInfo = yield this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken,
|
215
|
+
const swapInfo = yield this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken, authData.address);
|
208
216
|
const swapDepositBagStruct = {
|
209
217
|
inTokens: [fromTokenAddress],
|
210
218
|
inAmounts: [fromToken],
|
211
219
|
smartVault: vaultAddress,
|
212
220
|
swapInfo,
|
213
|
-
receiver:
|
221
|
+
receiver: authData.address,
|
214
222
|
referral: ethers_1.ethers.constants.AddressZero,
|
215
223
|
doFlush: false,
|
216
224
|
};
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
else {
|
223
|
-
swapAndDepositRequest = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.swapAndDeposit(swapDepositBagStruct));
|
224
|
-
}
|
225
|
-
yield (swapAndDepositRequest === null || swapAndDepositRequest === void 0 ? void 0 : swapAndDepositRequest.wait());
|
225
|
+
const swapAndDepositRequest = ethAmount
|
226
|
+
? yield this.spoolSdk.swapAndDeposit(swapDepositBagStruct, { value: ethers_1.ethers.utils.parseEther(ethAmount) })
|
227
|
+
: yield this.spoolSdk.swapAndDeposit(swapDepositBagStruct);
|
228
|
+
const txReceipt = yield swapAndDepositRequest.wait();
|
229
|
+
return txReceipt === null || txReceipt === void 0 ? void 0 : txReceipt.transactionHash;
|
226
230
|
});
|
227
231
|
}
|
228
232
|
withdraw(vault, amountToWithdraw) {
|
229
233
|
return __awaiter(this, void 0, void 0, function* () {
|
230
234
|
const authData = yield this.isUserAuthenticated();
|
231
|
-
if (!authData.isAuthenticated)
|
235
|
+
if (!authData.isAuthenticated) {
|
232
236
|
throw Error(`User not authenticated: ${authData.message}`);
|
233
|
-
if (!this.signer)
|
234
|
-
throw Error('No signer provided');
|
235
|
-
try {
|
236
|
-
const signerAddress = yield this.signer.getAddress();
|
237
|
-
if (!signerAddress)
|
238
|
-
throw Error('Error fetching address');
|
239
|
-
const redeemBagStruct = this.shouldUseNewWithdrawLogic(signerAddress, vault)
|
240
|
-
? yield this.generateNewRedeemBagStruct(authData.token, vault, signerAddress, amountToWithdraw)
|
241
|
-
: yield this.generateOldRedeemBagStruct(authData.token, vault, signerAddress, amountToWithdraw);
|
242
|
-
const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct, signerAddress.toLowerCase(), false);
|
243
|
-
const redeemTxReceipt = yield redeemTx.wait();
|
244
237
|
}
|
245
|
-
|
246
|
-
|
238
|
+
if (!this.signer) {
|
239
|
+
throw Error('No signer provided');
|
247
240
|
}
|
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);
|
245
|
+
const redeemTxReceipt = yield redeemTx.wait();
|
246
|
+
return redeemTxReceipt.transactionHash;
|
248
247
|
});
|
249
248
|
}
|
250
249
|
claimWithdraws(vaultAddress) {
|
251
250
|
return __awaiter(this, void 0, void 0, function* () {
|
252
251
|
const authData = yield this.isUserAuthenticated();
|
253
|
-
if (!authData.isAuthenticated)
|
252
|
+
if (!authData.isAuthenticated) {
|
254
253
|
throw Error(`User not authenticated: ${authData.message}`);
|
255
|
-
|
254
|
+
}
|
255
|
+
if (!this.signer) {
|
256
256
|
throw Error('No signer provided');
|
257
|
-
|
258
|
-
|
259
|
-
throw Error('Error fetching address');
|
260
|
-
const wnfts = yield this.dripApi.fetchEnrichedUserWNFTForVault(vaultAddress, signerAddress, authData.token);
|
257
|
+
}
|
258
|
+
const wnfts = yield this.dripApi.fetchEnrichedUserWNFTForVault(vaultAddress, authData.address, authData.token);
|
261
259
|
//! Shares come as Strings instead of BigNumber from our Backend
|
262
260
|
const nftIds = wnfts
|
263
261
|
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
@@ -265,8 +263,9 @@ class DripSdk {
|
|
265
263
|
const nftAmounts = wnfts
|
266
264
|
.filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
|
267
265
|
.map((item) => item.shares.toString());
|
268
|
-
const claimWithdrawTx = yield this.spoolSdk.claimWithdrawal(vaultAddress, nftIds, nftAmounts,
|
269
|
-
yield claimWithdrawTx.wait();
|
266
|
+
const claimWithdrawTx = yield this.spoolSdk.claimWithdrawal(vaultAddress, nftIds, nftAmounts, authData.address);
|
267
|
+
const txReceipt = yield claimWithdrawTx.wait();
|
268
|
+
return txReceipt.transactionHash;
|
270
269
|
});
|
271
270
|
}
|
272
271
|
generateOldRedeemBagStruct(token, vault, signerAddress, amountToWithdraw) {
|
@@ -283,7 +282,7 @@ class DripSdk {
|
|
283
282
|
}
|
284
283
|
else {
|
285
284
|
//! Not a MAX Withdraw (calculate the shares to withdraw)
|
286
|
-
|
285
|
+
const amountToWithdrawFixedDecimals = parseFloat(amountToWithdraw).toFixed(decimals);
|
287
286
|
sharesToWithdraw = ethers_1.ethers.utils
|
288
287
|
.parseUnits(amountToWithdrawFixedDecimals, decimals)
|
289
288
|
.mul(totalShares)
|
@@ -315,22 +314,23 @@ class DripSdk {
|
|
315
314
|
let dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress.toLowerCase(), signerAddress, token);
|
316
315
|
dnfts = yield this.getAllSvts(vault.vaultAddress.toLowerCase(), signerAddress, dnfts, token);
|
317
316
|
let shares = ethers_1.BigNumber.from(0);
|
318
|
-
|
319
|
-
|
317
|
+
const nftIds = [];
|
318
|
+
const nftAmounts = [];
|
320
319
|
let index = 0;
|
321
320
|
while (dnfts[index] && (totalAmountToWithdraw.gt(0) || withdrawAll)) {
|
322
321
|
const dnft = dnfts[index];
|
323
322
|
const userBalance = this.calculateBalanceForDNFT(dnft, decimals);
|
324
323
|
if (userBalance.gt(0)) {
|
325
|
-
|
324
|
+
const amountToWithdraw = totalAmountToWithdraw;
|
326
325
|
const userSvts = dnft.svts;
|
327
326
|
let svtsToWithdraw = ethers_1.BigNumber.from(0);
|
328
327
|
let nftAmount = ethers_1.BigNumber.from(0);
|
329
328
|
if (amountToWithdraw.gte(userBalance) || withdrawAll) {
|
330
329
|
nftAmount = dnft.shares;
|
331
330
|
svtsToWithdraw = userSvts;
|
332
|
-
if (!withdrawAll)
|
331
|
+
if (!withdrawAll) {
|
333
332
|
totalAmountToWithdraw = totalAmountToWithdraw.sub(userBalance);
|
333
|
+
}
|
334
334
|
}
|
335
335
|
else {
|
336
336
|
nftAmount = amountToWithdraw.mul(dnft.shares).div(userBalance);
|
@@ -362,11 +362,9 @@ class DripSdk {
|
|
362
362
|
}
|
363
363
|
getERC20Precission(tokenAddress) {
|
364
364
|
return __awaiter(this, void 0, void 0, function* () {
|
365
|
-
if (!this.signer)
|
365
|
+
if (!this.signer) {
|
366
366
|
throw Error('No signer provided');
|
367
|
-
|
368
|
-
if (!signerAddress)
|
369
|
-
throw Error('Error fetching address');
|
367
|
+
}
|
370
368
|
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
371
369
|
const decimals = yield erc20Instance.decimals();
|
372
370
|
return decimals;
|
@@ -452,9 +450,9 @@ class DripSdk {
|
|
452
450
|
}
|
453
451
|
calculateAllWithdrawalBalances(wnfts, vaultAddress, decimals, token) {
|
454
452
|
return __awaiter(this, void 0, void 0, function* () {
|
455
|
-
if (!this.signer)
|
453
|
+
if (!this.signer) {
|
456
454
|
throw Error('No signer provided');
|
457
|
-
|
455
|
+
}
|
458
456
|
let estimatedPendingWithdrawalBalance = ethers_1.BigNumber.from(0);
|
459
457
|
let estimatedWithdrawableBalance = ethers_1.BigNumber.from(0);
|
460
458
|
let withdrawals = 0;
|
@@ -482,23 +480,22 @@ class DripSdk {
|
|
482
480
|
return [estimatedPendingWithdrawalBalance, estimatedWithdrawableBalance, estimatedWithdrawals];
|
483
481
|
});
|
484
482
|
}
|
485
|
-
getTokenAllowanceForSwapAndDepositContractAddress(tokenAddress) {
|
483
|
+
getTokenAllowanceForSwapAndDepositContractAddress(tokenAddress, userAddress) {
|
486
484
|
return __awaiter(this, void 0, void 0, function* () {
|
487
|
-
if (!this.signer)
|
485
|
+
if (!this.signer) {
|
488
486
|
throw Error('No signer provided');
|
489
|
-
|
490
|
-
if (!signerAddress)
|
491
|
-
throw Error('Error fetching address');
|
487
|
+
}
|
492
488
|
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
493
489
|
const swapAndDepositAddress = yield this.dripConfig.getSwapAndDepositContractAddress(this.signer);
|
494
|
-
const allowance = yield erc20Instance.allowance(
|
490
|
+
const allowance = yield erc20Instance.allowance(userAddress, swapAndDepositAddress);
|
495
491
|
return allowance;
|
496
492
|
});
|
497
493
|
}
|
498
494
|
approveTokenForSwapAndDepositContract(tokenAddress, amount) {
|
499
495
|
return __awaiter(this, void 0, void 0, function* () {
|
500
|
-
if (!this.signer)
|
496
|
+
if (!this.signer) {
|
501
497
|
throw Error('No signer provided');
|
498
|
+
}
|
502
499
|
const swapAndDepositContractAddress = yield this.dripConfig.getSwapAndDepositContractAddress(this.signer);
|
503
500
|
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
504
501
|
const approveTx = yield erc20Instance.approve(swapAndDepositContractAddress, amount);
|
@@ -507,11 +504,13 @@ class DripSdk {
|
|
507
504
|
}
|
508
505
|
getTokenAllowanceForDeposit(tokenAddress) {
|
509
506
|
return __awaiter(this, void 0, void 0, function* () {
|
510
|
-
if (!this.signer)
|
507
|
+
if (!this.signer) {
|
511
508
|
throw Error('No signer provided');
|
509
|
+
}
|
512
510
|
const signerAddress = yield this.signer.getAddress();
|
513
|
-
if (!signerAddress)
|
511
|
+
if (!signerAddress) {
|
514
512
|
throw Error('Error fetching address');
|
513
|
+
}
|
515
514
|
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
516
515
|
const smartVaultManagerAddress = yield this.dripConfig.getSmartVaultManagerAddress(this.signer);
|
517
516
|
const allowance = yield erc20Instance.allowance(signerAddress, smartVaultManagerAddress);
|
@@ -520,8 +519,9 @@ class DripSdk {
|
|
520
519
|
}
|
521
520
|
approveTokenForDeposit(tokenAddress, amount) {
|
522
521
|
return __awaiter(this, void 0, void 0, function* () {
|
523
|
-
if (!this.signer)
|
522
|
+
if (!this.signer) {
|
524
523
|
throw Error('No signer provided');
|
524
|
+
}
|
525
525
|
const smartVaultManagerAddress = yield this.dripConfig.getSmartVaultManagerAddress(this.signer);
|
526
526
|
const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
|
527
527
|
const approveTx = yield erc20Instance.approve(smartVaultManagerAddress, amount);
|
package/package.json
CHANGED
@@ -1,27 +1,28 @@
|
|
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
|
-
"
|
10
|
+
"publish": "npm publish --access public",
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
12
12
|
},
|
13
13
|
"dependencies": {
|
14
14
|
"@spool.fi/spool-v2-sdk": "1.0.14",
|
15
15
|
"ethers": "^5.7.2",
|
16
|
-
"
|
17
|
-
"
|
16
|
+
"js-cookie": "^3.0.5",
|
17
|
+
"web3-token": "^1.0.6"
|
18
18
|
},
|
19
19
|
"author": "",
|
20
20
|
"license": "ISC",
|
21
21
|
"devDependencies": {
|
22
|
-
"typescript": "^5.4.5",
|
23
22
|
"@types/js-cookie": "^3.0.6",
|
24
|
-
"
|
25
|
-
"
|
23
|
+
"@typescript-eslint/eslint-plugin": "^7.12.0",
|
24
|
+
"@typescript-eslint/parser": "^7.12.0",
|
25
|
+
"eslint": "^8.57.0",
|
26
|
+
"typescript": "^5.4.5"
|
26
27
|
}
|
27
28
|
}
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
package/dist/test.d.ts
DELETED
package/dist/test.js
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.signer = void 0;
|
4
|
-
const ethers_1 = require("ethers");
|
5
|
-
const _1 = require(".");
|
6
|
-
const dripProdConfig = new _1.DripConfig('https://subgraph.satsuma-prod.com/49eb322da234/solidant/spool-v2/api', 'https://pricefeed.v2.spool.fi/', 'https://rewards.v2.spool.fi/', 'https://fastwithdraw.v2.spool.fi/', {
|
7
|
-
1: {
|
8
|
-
ISmartVaultManager: '0x23Daf34e2b9Af02A74dC19cB52Af727B19403874',
|
9
|
-
IDepositSwap: '0xd8534197Bd587F8226d12E0C864ef2CaE6f82f5C',
|
10
|
-
ISmartVaultFactory: '0x8049Fc710D4a1Deea6a6bCeF772C166CEd7A82F5',
|
11
|
-
IDepositManager: '0x823Ba38992825FF37E72B6c3D669a09173B8F7bf',
|
12
|
-
IRewardManager: '0xd8d2C1C3C7982272e3e12dEC5aF681433fdcf003',
|
13
|
-
IStrategyRegistry: '0x554c6bCB54656390aca0a0af38CA954dbE653F15',
|
14
|
-
ISpoolLens: '0x8aa6174333F75421903b2B5c70DdF8DA5D84f74F',
|
15
|
-
},
|
16
|
-
}, 'http://localhost:7070');
|
17
|
-
const provider = new ethers_1.ethers.providers.StaticJsonRpcProvider('https://mainnet.infura.io/v3/fa1bf2cea12147559c9634e80be76d61', 1);
|
18
|
-
exports.signer = new ethers_1.ethers.Wallet('6ffc226f7b7769e27124317372c9dbb579a324e67e97bf07131bf2f59ec0f4fe', provider);
|
19
|
-
const dripSdk = new _1.DripSdk(dripProdConfig, exports.signer);
|
20
|
-
// dripSdk.isUserAuthenticated().then((result) => {
|
21
|
-
// console.log(result)
|
22
|
-
// }).catch((error) => {
|
23
|
-
// console.log(error)
|
24
|
-
// })
|