@dripfi/drip-sdk 1.0.5 → 1.0.7
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/.prettierignore +2 -0
- package/.prettierrc +11 -0
- package/README.md +125 -5
- package/dist/DripApi.d.ts +4 -4
- package/dist/DripApi.js +18 -18
- package/dist/DripConfig.d.ts +2 -2
- package/dist/DripSdk.d.ts +11 -14
- package/dist/DripSdk.js +94 -97
- package/dist/test.d.ts +1 -1
- package/dist/types/AuthenticationStatus.d.ts +6 -0
- package/dist/types/AuthenticationStatus.js +2 -0
- package/package.json +5 -2
package/.prettierignore
ADDED
package/.prettierrc
ADDED
package/README.md
CHANGED
@@ -15,15 +15,120 @@ npm i @dripfi/drip-sdk
|
|
15
15
|
## Usage
|
16
16
|
|
17
17
|
```typescript
|
18
|
-
import DripSdk from '@drip/sdk'
|
18
|
+
import DripSdk from '@drip/sdk'
|
19
19
|
```
|
20
20
|
|
21
21
|
Initialize the SDK with your Drip configuration and an optional signer:
|
22
22
|
|
23
23
|
```typescript
|
24
|
-
const dripConfig = new DripConfig(
|
25
|
-
|
24
|
+
const dripConfig = new DripConfig(
|
25
|
+
subgraphUrl: string,
|
26
|
+
priceFeedApiUrl: string,
|
27
|
+
rewardsUrl: string,
|
28
|
+
fastRedeemApi: string,
|
29
|
+
contracts: Record<number, ContractAddresses>,
|
30
|
+
dripRoute: string);
|
31
|
+
const signer: ethers.Signer = /* your Signer instance */;
|
26
32
|
const dripSdk = new DripSdk(dripConfig, signer);
|
33
|
+
|
34
|
+
type Vault = {
|
35
|
+
vaultName: string
|
36
|
+
vaultAddress: string
|
37
|
+
apy: number
|
38
|
+
tvr: number
|
39
|
+
protocols: string[]
|
40
|
+
projectName: string
|
41
|
+
depositToken: VaultDepositToken
|
42
|
+
type: VaultType
|
43
|
+
rewards: VaultReward[]
|
44
|
+
liveUntil: string
|
45
|
+
liveUntilFormatted: string
|
46
|
+
hasPoolEnded: boolean
|
47
|
+
boosters: NFTBoost[]
|
48
|
+
stretchGoals: StretchGoal[]
|
49
|
+
strategies: Strategy[]
|
50
|
+
newWithdraw: boolean
|
51
|
+
tgePrice?: number
|
52
|
+
maxAmountOfTokens?: number
|
53
|
+
rewardsInformation: RewardsInformation
|
54
|
+
}
|
55
|
+
|
56
|
+
type VaultType = 'launch' | 'earn' | 'airdrop'
|
57
|
+
|
58
|
+
type VaultDepositToken = {
|
59
|
+
name: string
|
60
|
+
symbol: string
|
61
|
+
roundingDecimals: number
|
62
|
+
precisionDecimals: number
|
63
|
+
tokenAddress: string
|
64
|
+
}
|
65
|
+
|
66
|
+
type VaultReward = {
|
67
|
+
type: 'token' | 'points'
|
68
|
+
name: string
|
69
|
+
symbol: string
|
70
|
+
decimals: number
|
71
|
+
tokenAddress: string
|
72
|
+
monthlyEmissionRate?: number
|
73
|
+
}
|
74
|
+
|
75
|
+
type NFTBoost = {
|
76
|
+
url: string
|
77
|
+
tokenAddress: string
|
78
|
+
multiplier: number
|
79
|
+
nftAddress: string
|
80
|
+
network: string
|
81
|
+
initialBlock: number // needs to be the block when rewards was deployed
|
82
|
+
imagePath: string
|
83
|
+
}
|
84
|
+
|
85
|
+
interface StretchGoal {
|
86
|
+
threshhold: number
|
87
|
+
threshholdDescription: string
|
88
|
+
rewardTooltip: string
|
89
|
+
rewardDescription: string
|
90
|
+
amountOfTokens: number
|
91
|
+
}
|
92
|
+
|
93
|
+
type RewardsInformation = {
|
94
|
+
[tokenAddress: string]: { blockNumber: string; rewardrate: string; timestamp: string; endTime: string }
|
95
|
+
}
|
96
|
+
|
97
|
+
type Strategy = {
|
98
|
+
address: string
|
99
|
+
lastDoHardWorkTime: number | null
|
100
|
+
lastDoHardWorkBlock: number | null
|
101
|
+
}
|
102
|
+
|
103
|
+
type AuthenticationStatus = {
|
104
|
+
isAuthenticated: boolean
|
105
|
+
address?: string
|
106
|
+
token?: string
|
107
|
+
message?: string
|
108
|
+
}
|
109
|
+
|
110
|
+
interface QLFastRedeem {
|
111
|
+
assetsWithdrawn: {
|
112
|
+
asset: {
|
113
|
+
decimals: number
|
114
|
+
id: string
|
115
|
+
name: string
|
116
|
+
symbol: string
|
117
|
+
}
|
118
|
+
claimed: string
|
119
|
+
id: string
|
120
|
+
}[]
|
121
|
+
blockNumber: number
|
122
|
+
id: string
|
123
|
+
svtWithdrawn: string
|
124
|
+
}
|
125
|
+
|
126
|
+
type SwapInfo = {
|
127
|
+
swapTarget: any
|
128
|
+
token: string
|
129
|
+
swapCallData: any
|
130
|
+
}
|
131
|
+
|
27
132
|
```
|
28
133
|
|
29
134
|
## Methods
|
@@ -37,11 +142,26 @@ const dripSdk = new DripSdk(dripConfig, signer);
|
|
37
142
|
- **authenticate(): Promise<boolean>**
|
38
143
|
Initiates the user authentication process and returns a boolean indicating success.
|
39
144
|
|
40
|
-
- **isUserAuthenticated(): Promise<
|
145
|
+
- **isUserAuthenticated(): Promise<AuthenticationStatus>**
|
41
146
|
Checks if the user is authenticated and returns authentication status along with relevant information.
|
42
147
|
|
43
|
-
- **updateSigner(newSigner: Signer)
|
148
|
+
- **updateSigner(newSigner: Signer): Promise<void>**
|
44
149
|
Updates the signer for the SDK instance.
|
45
150
|
|
46
151
|
- **getUserBalance(vault: Vault): Promise<UserBalance>**
|
47
152
|
Fetches the user's balance for a specific Drip Vault.
|
153
|
+
|
154
|
+
- **deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<void>**
|
155
|
+
The deposit function allows you to deposit tokens into a specific vault.
|
156
|
+
|
157
|
+
- **swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<void>**
|
158
|
+
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
|
159
|
+
|
160
|
+
- **withdraw(vault: Vault, amountToWithdraw?: string): Promise<void>**
|
161
|
+
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()
|
162
|
+
|
163
|
+
- **claimWithdraws(vaultAddress: string): Promise<void>**
|
164
|
+
After the withdrawal has been processed by the 'DoHardWork' function, the 'claimWithdraws' function transfers the withdrawn tokens to their personal account.
|
165
|
+
|
166
|
+
- **fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<void>**
|
167
|
+
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.
|
package/dist/DripApi.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import { BigNumber } from
|
2
|
-
import { Vault } from
|
3
|
-
import { SwapInfo } from
|
4
|
-
import { QLFastRedeem } from
|
1
|
+
import { BigNumber } from 'ethers';
|
2
|
+
import { Vault } from './types/Vault';
|
3
|
+
import { SwapInfo } from './types/SwapInfo';
|
4
|
+
import { QLFastRedeem } from './types/QLFastRedeem';
|
5
5
|
export default class DripApi {
|
6
6
|
route: string;
|
7
7
|
constructor(route: string);
|
package/dist/DripApi.js
CHANGED
@@ -17,14 +17,14 @@ class DripApi {
|
|
17
17
|
fetchAllVaults() {
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
19
19
|
const res = yield fetch(`${this.route}/api-be/api/vault`);
|
20
|
-
const data = yield res.json();
|
20
|
+
const data = (yield res.json());
|
21
21
|
return data;
|
22
22
|
});
|
23
23
|
}
|
24
24
|
fetchVaultDetails(vaultAddress) {
|
25
25
|
return __awaiter(this, void 0, void 0, function* () {
|
26
26
|
const res = yield fetch(`${this.route}/api-be/api/vault/${vaultAddress}`);
|
27
|
-
const data = yield res.json();
|
27
|
+
const data = (yield res.json());
|
28
28
|
return data;
|
29
29
|
});
|
30
30
|
}
|
@@ -35,13 +35,13 @@ class DripApi {
|
|
35
35
|
}
|
36
36
|
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`;
|
37
37
|
const res = yield fetch(url);
|
38
|
-
const data = yield res.json();
|
38
|
+
const data = (yield res.json());
|
39
39
|
return [
|
40
40
|
{
|
41
41
|
swapTarget: data.tx.to,
|
42
42
|
token: data.fromToken.address,
|
43
43
|
swapCallData: data.tx.data,
|
44
|
-
}
|
44
|
+
},
|
45
45
|
];
|
46
46
|
});
|
47
47
|
}
|
@@ -52,7 +52,7 @@ class DripApi {
|
|
52
52
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/svtBalance/${walletAddress}/${vaultAddress}`, {
|
53
53
|
headers,
|
54
54
|
});
|
55
|
-
const data = yield res.json();
|
55
|
+
const data = (yield res.json());
|
56
56
|
return data;
|
57
57
|
});
|
58
58
|
}
|
@@ -61,9 +61,9 @@ class DripApi {
|
|
61
61
|
const headers = new Headers();
|
62
62
|
headers.append('Authorization', token);
|
63
63
|
const res = yield fetch(`${this.route}/api-be/api/spool/userBalance/${walletAddress}/${vaultAddress}`, {
|
64
|
-
headers
|
64
|
+
headers,
|
65
65
|
});
|
66
|
-
const data = yield res.json();
|
66
|
+
const data = (yield res.json());
|
67
67
|
return data;
|
68
68
|
});
|
69
69
|
}
|
@@ -72,7 +72,7 @@ class DripApi {
|
|
72
72
|
const headers = new Headers();
|
73
73
|
headers.append('Authorization', token);
|
74
74
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/dNft/${walletAddress}/${vaultAddress}`, {
|
75
|
-
headers
|
75
|
+
headers,
|
76
76
|
});
|
77
77
|
const data = yield res.json();
|
78
78
|
return data;
|
@@ -83,9 +83,9 @@ class DripApi {
|
|
83
83
|
const headers = new Headers();
|
84
84
|
headers.append('Authorization', token);
|
85
85
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/svtFromNft/${userAddress}/${vaultAddress}?dnfts=${dnfts.join(',')}`, {
|
86
|
-
headers
|
86
|
+
headers,
|
87
87
|
});
|
88
|
-
const data = yield res.json();
|
88
|
+
const data = (yield res.json());
|
89
89
|
return data;
|
90
90
|
});
|
91
91
|
}
|
@@ -94,9 +94,9 @@ class DripApi {
|
|
94
94
|
const headers = new Headers();
|
95
95
|
headers.append('Authorization', token);
|
96
96
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/allWnft/${walletAddress}/${vaultAddress}`, {
|
97
|
-
headers
|
97
|
+
headers,
|
98
98
|
});
|
99
|
-
const data = yield res.json();
|
99
|
+
const data = (yield res.json());
|
100
100
|
return data;
|
101
101
|
});
|
102
102
|
}
|
@@ -105,9 +105,9 @@ class DripApi {
|
|
105
105
|
const headers = new Headers();
|
106
106
|
headers.append('Authorization', token);
|
107
107
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/allDnft/${walletAddress}/${vaultAddress}`, {
|
108
|
-
headers
|
108
|
+
headers,
|
109
109
|
});
|
110
|
-
const data = yield res.json();
|
110
|
+
const data = (yield res.json());
|
111
111
|
return data;
|
112
112
|
});
|
113
113
|
}
|
@@ -116,9 +116,9 @@ class DripApi {
|
|
116
116
|
const headers = new Headers();
|
117
117
|
headers.append('Authorization', token);
|
118
118
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/assetBalance/${blocknumber}/${vaultAddress}`, {
|
119
|
-
headers
|
119
|
+
headers,
|
120
120
|
});
|
121
|
-
const data = yield res.json();
|
121
|
+
const data = (yield res.json());
|
122
122
|
return data;
|
123
123
|
});
|
124
124
|
}
|
@@ -127,9 +127,9 @@ class DripApi {
|
|
127
127
|
const headers = new Headers();
|
128
128
|
headers.append('Authorization', token);
|
129
129
|
const res = yield fetch(`${this.route}/api-be/api/spool/user/fastWithdrawNft/${walletAddress}/${vaultAddress}`, {
|
130
|
-
headers
|
130
|
+
headers,
|
131
131
|
});
|
132
|
-
const data = yield res.json();
|
132
|
+
const data = (yield res.json());
|
133
133
|
return data;
|
134
134
|
});
|
135
135
|
}
|
package/dist/DripConfig.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { ContractAddresses, SDKConfig } from
|
2
|
-
import { Signer } from
|
1
|
+
import { ContractAddresses, SDKConfig } from '@spool.fi/spool-v2-sdk';
|
2
|
+
import { Signer } from 'ethers';
|
3
3
|
export declare class DripConfig {
|
4
4
|
internalConfig: SDKConfig;
|
5
5
|
dripRoute: string;
|
package/dist/DripSdk.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
import { Vault } from
|
2
|
-
import { Signer } from
|
3
|
-
import { DripConfig } from
|
4
|
-
import { UserBalance } from
|
1
|
+
import { Vault } from './types/Vault';
|
2
|
+
import { Signer } from 'ethers';
|
3
|
+
import { DripConfig } from './DripConfig';
|
4
|
+
import { UserBalance } from './types/UserBalance';
|
5
|
+
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
5
6
|
export default class DripSdk {
|
6
7
|
private dripApi;
|
7
8
|
private spoolSdk?;
|
@@ -11,18 +12,14 @@ export default class DripSdk {
|
|
11
12
|
getAllVaults(): Promise<Vault[]>;
|
12
13
|
getVaultDetails(vaultAddress: string): Promise<Vault>;
|
13
14
|
authenticate(): Promise<boolean>;
|
14
|
-
isUserAuthenticated(): Promise<
|
15
|
-
isAuthenticated: boolean;
|
16
|
-
address?: string;
|
17
|
-
token?: string;
|
18
|
-
message?: string;
|
19
|
-
}>;
|
15
|
+
isUserAuthenticated(): Promise<AuthenticationStatus>;
|
20
16
|
updateSigner(newSigner: Signer): void;
|
21
17
|
getUserBalance(vault: Vault): Promise<UserBalance>;
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<void>;
|
19
|
+
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<void>;
|
20
|
+
swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<void>;
|
21
|
+
withdraw(vault: Vault, amountToWithdraw?: string): Promise<void>;
|
22
|
+
claimWithdraws(vaultAddress: string): Promise<void>;
|
26
23
|
private generateOldRedeemBagStruct;
|
27
24
|
private generateNewRedeemBagStruct;
|
28
25
|
private getAllSvts;
|
package/dist/DripSdk.js
CHANGED
@@ -18,7 +18,7 @@ const ethers_1 = require("ethers");
|
|
18
18
|
const utils_1 = require("./utils");
|
19
19
|
const DripApi_1 = __importDefault(require("./DripApi"));
|
20
20
|
const js_cookie_1 = __importDefault(require("js-cookie"));
|
21
|
-
const KASU_USDC_VAULT_ADDRESS =
|
21
|
+
const KASU_USDC_VAULT_ADDRESS = '0xd8aa8099a53eddebe6a49c98ca12746ff19aa502';
|
22
22
|
class DripSdk {
|
23
23
|
constructor(dripConfig, signer) {
|
24
24
|
this.signer = signer;
|
@@ -62,18 +62,18 @@ class DripSdk {
|
|
62
62
|
return __awaiter(this, void 0, void 0, function* () {
|
63
63
|
try {
|
64
64
|
if (!this.signer) {
|
65
|
-
return { isAuthenticated: false, message:
|
65
|
+
return { isAuthenticated: false, message: 'Signer not provided' };
|
66
66
|
}
|
67
67
|
const userAddress = yield this.signer.getAddress();
|
68
68
|
const cookieName = `auth_${userAddress.toLowerCase()}`;
|
69
69
|
const authToken = js_cookie_1.default.get(cookieName);
|
70
70
|
if (!authToken) {
|
71
|
-
return { isAuthenticated: false, message:
|
71
|
+
return { isAuthenticated: false, message: 'Auth token not found' };
|
72
72
|
}
|
73
73
|
const { address } = web3_token_1.default.verify(authToken);
|
74
74
|
if (address.toLowerCase() !== userAddress.toLowerCase()) {
|
75
75
|
js_cookie_1.default.remove(cookieName);
|
76
|
-
return { isAuthenticated: false, message:
|
76
|
+
return { isAuthenticated: false, message: 'Invalid token' };
|
77
77
|
}
|
78
78
|
return { isAuthenticated: true, address: address.toLowerCase(), token: authToken };
|
79
79
|
}
|
@@ -133,108 +133,102 @@ class DripSdk {
|
|
133
133
|
}
|
134
134
|
fastWithdraw(vault, amountToWithdraw) {
|
135
135
|
return __awaiter(this, void 0, void 0, function* () {
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
|
154
|
-
}
|
136
|
+
// if (!this.signer) throw Error('No signer provided')
|
137
|
+
// try {
|
138
|
+
// const signerAddress = await this.signer.getAddress()
|
139
|
+
// if (!signerAddress) throw Error('Error fetching address')
|
140
|
+
// const redeemBagStruct: RedeemBagStruct = this.shouldUseNewWithdrawLogic(signerAddress, vault)
|
141
|
+
// ? await this.generateNewRedeemBagStruct(vault, signerAddress, amountToWithdraw)
|
142
|
+
// : await this.generateOldRedeemBagStruct(vault, signerAddress, amountToWithdraw)
|
143
|
+
// const currentBlockNumber = await this.signer.provider?.getBlockNumber()
|
144
|
+
// if (!currentBlockNumber) throw Error('Error fetching block number')
|
145
|
+
// const redeemTx = await this.spoolSdk?.redeemFast(
|
146
|
+
// redeemBagStruct,
|
147
|
+
// signerAddress.toLowerCase(),
|
148
|
+
// currentBlockNumber,
|
149
|
+
// )
|
150
|
+
// const redeemTxReceipt = await redeemTx!.wait()
|
151
|
+
// } catch (error) {
|
152
|
+
// console.log(error)
|
153
|
+
// }
|
155
154
|
});
|
156
155
|
}
|
157
156
|
deposit(tokenAddress, vaultAddress, amount) {
|
158
157
|
return __awaiter(this, void 0, void 0, function* () {
|
159
|
-
if (!this.signer)
|
160
|
-
|
161
|
-
const
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
const depositTx = yield this.spoolSdk.deposit(depositBagStruct);
|
180
|
-
yield depositTx.wait();
|
158
|
+
// if (!this.signer) throw Error('No signer provided')
|
159
|
+
// const currentTokenAllowance = await this.getTokenAllowanceForDeposit(tokenAddress)
|
160
|
+
// const decimals = await this.getERC20Precission(tokenAddress)
|
161
|
+
// let amountToWithdrawFixedDecimals = parseFloat(amount).toFixed(decimals)
|
162
|
+
// const amountToDeposit = ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals)
|
163
|
+
// if (amountToDeposit.gt(currentTokenAllowance)) {
|
164
|
+
// const requiredTokenAllowance = amountToDeposit.sub(currentTokenAllowance)
|
165
|
+
// await this.approveTokenForDeposit(tokenAddress, requiredTokenAllowance)
|
166
|
+
// }
|
167
|
+
// const signerAddress = await this.signer.getAddress()
|
168
|
+
// if (!signerAddress) throw Error('Error fetching address')
|
169
|
+
// const depositBagStruct: DepositBagStruct = {
|
170
|
+
// smartVault: vaultAddress,
|
171
|
+
// assets: [amountToDeposit],
|
172
|
+
// receiver: signerAddress,
|
173
|
+
// referral: ethers.constants.AddressZero,
|
174
|
+
// doFlush: false,
|
175
|
+
// }
|
176
|
+
// const depositTx = await this.spoolSdk!.deposit(depositBagStruct)
|
177
|
+
// await depositTx.wait()
|
181
178
|
});
|
182
179
|
}
|
183
180
|
swapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
|
184
181
|
return __awaiter(this, void 0, void 0, function* () {
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
const
|
189
|
-
const
|
190
|
-
|
191
|
-
const
|
192
|
-
if (fromToken.gt(
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
}
|
213
|
-
|
214
|
-
swapAndDepositRequest = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.swapAndDeposit(swapDepositBagStruct));
|
215
|
-
}
|
216
|
-
yield (swapAndDepositRequest === null || swapAndDepositRequest === void 0 ? void 0 : swapAndDepositRequest.wait());
|
182
|
+
// if (!this.signer) throw Error('No signer provided')
|
183
|
+
// const decimals = await this.getERC20Precission(fromTokenAddress)
|
184
|
+
// const amountToWithdrawFixedDecimals = parseFloat(fromTokenAmount).toFixed(decimals)
|
185
|
+
// const fromToken = ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals)
|
186
|
+
// const signerAddress = await this.signer.getAddress()
|
187
|
+
// if (fromToken.gt(BigNumber.from(0))) {
|
188
|
+
// const currentTokenAllowance = await this.getTokenAllowanceForSwapAndDepositContractAddress(fromTokenAddress)
|
189
|
+
// if (fromToken.gt(currentTokenAllowance)) {
|
190
|
+
// await this.approveTokenForSwapAndDepositContract(fromTokenAddress, fromToken.sub(currentTokenAllowance))
|
191
|
+
// }
|
192
|
+
// }
|
193
|
+
// const swapInfo = await this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken, signerAddress)
|
194
|
+
// const swapDepositBagStruct = {
|
195
|
+
// inTokens: [fromTokenAddress],
|
196
|
+
// inAmounts: [fromToken],
|
197
|
+
// smartVault: vaultAddress,
|
198
|
+
// swapInfo,
|
199
|
+
// receiver: signerAddress,
|
200
|
+
// referral: ethers.constants.AddressZero,
|
201
|
+
// doFlush: false,
|
202
|
+
// }
|
203
|
+
// let swapAndDepositRequest: ethers.ContractTransaction | undefined
|
204
|
+
// if (ethAmount) {
|
205
|
+
// const eth = ethers.utils.parseEther(ethAmount)
|
206
|
+
// swapAndDepositRequest = await this.spoolSdk?.swapAndDeposit(swapDepositBagStruct, { value: eth })
|
207
|
+
// } else {
|
208
|
+
// swapAndDepositRequest = await this.spoolSdk?.swapAndDeposit(swapDepositBagStruct)
|
209
|
+
// }
|
210
|
+
// await swapAndDepositRequest?.wait()
|
217
211
|
});
|
218
212
|
}
|
219
213
|
withdraw(vault, amountToWithdraw) {
|
220
214
|
return __awaiter(this, void 0, void 0, function* () {
|
221
|
-
if (!this.signer)
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
}
|
233
|
-
catch (error) {
|
234
|
-
console.log(error);
|
235
|
-
}
|
215
|
+
// if (!this.signer) throw Error('No signer provided')
|
216
|
+
// try {
|
217
|
+
// const signerAddress = await this.signer.getAddress()
|
218
|
+
// if (!signerAddress) throw Error('Error fetching address')
|
219
|
+
// const redeemBagStruct: RedeemBagStruct = this.shouldUseNewWithdrawLogic(signerAddress, vault)
|
220
|
+
// ? await this.generateNewRedeemBagStruct(vault, signerAddress, amountToWithdraw)
|
221
|
+
// : await this.generateOldRedeemBagStruct(vault, signerAddress, amountToWithdraw)
|
222
|
+
// const redeemTx = await this.spoolSdk!.redeem(redeemBagStruct, signerAddress.toLowerCase(), false)
|
223
|
+
// const redeemTxReceipt = await redeemTx.wait()
|
224
|
+
// } catch (error) {
|
225
|
+
// console.log(error)
|
226
|
+
// }
|
236
227
|
});
|
237
228
|
}
|
229
|
+
claimWithdraws(vaultAddress) {
|
230
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
231
|
+
}
|
238
232
|
generateOldRedeemBagStruct(vault, signerAddress, amountToWithdraw) {
|
239
233
|
return __awaiter(this, void 0, void 0, function* () {
|
240
234
|
const token = yield this.generateToken();
|
@@ -277,7 +271,7 @@ class DripSdk {
|
|
277
271
|
return __awaiter(this, void 0, void 0, function* () {
|
278
272
|
const token = yield this.generateToken();
|
279
273
|
const decimals = yield this.getERC20Precission(vault.depositToken.tokenAddress.toLowerCase());
|
280
|
-
const withdrawAll =
|
274
|
+
const withdrawAll = !amountToWithdraw;
|
281
275
|
const initialAmountToWithdraw = ethers_1.ethers.utils.parseUnits(amountToWithdraw || '0', decimals);
|
282
276
|
let totalAmountToWithdraw = initialAmountToWithdraw;
|
283
277
|
let dnfts = yield this.dripApi.fetchEnrichedUserDNFTForVault(vault.vaultAddress.toLowerCase(), signerAddress, token);
|
@@ -315,7 +309,7 @@ class DripSdk {
|
|
315
309
|
smartVault: vault.vaultAddress.toLowerCase(),
|
316
310
|
shares: shares,
|
317
311
|
nftIds,
|
318
|
-
nftAmounts
|
312
|
+
nftAmounts,
|
319
313
|
};
|
320
314
|
});
|
321
315
|
}
|
@@ -323,7 +317,9 @@ class DripSdk {
|
|
323
317
|
return __awaiter(this, void 0, void 0, function* () {
|
324
318
|
const token = yield this.generateToken();
|
325
319
|
const svts = yield this.dripApi.fetchUserSVTFromNfts(vaultAddress, userAddress, dnfts.map((element) => parseInt(element.nftId)), token);
|
326
|
-
const result = dnfts.map((element, index) => {
|
320
|
+
const result = dnfts.map((element, index) => {
|
321
|
+
return { nftId: element.nftId, assets: element.assets, shares: element.shares, svts: svts[index] };
|
322
|
+
});
|
327
323
|
return result;
|
328
324
|
});
|
329
325
|
}
|
@@ -410,9 +406,10 @@ class DripSdk {
|
|
410
406
|
shouldUseNewWithdrawLogic(userAddress, vault) {
|
411
407
|
// Users that already withdrew using the old approach should keep using the same
|
412
408
|
const usersWhoAlreadyWithdraw = {
|
413
|
-
'0x5ae62d2bc40e9119aee9cd4ed50e3d9378c9a191': KASU_USDC_VAULT_ADDRESS
|
409
|
+
'0x5ae62d2bc40e9119aee9cd4ed50e3d9378c9a191': KASU_USDC_VAULT_ADDRESS,
|
414
410
|
};
|
415
|
-
if (usersWhoAlreadyWithdraw[userAddress.toLowerCase()] &&
|
411
|
+
if (usersWhoAlreadyWithdraw[userAddress.toLowerCase()] &&
|
412
|
+
usersWhoAlreadyWithdraw[userAddress.toLowerCase()] === vault.vaultAddress.toLowerCase()) {
|
416
413
|
return false;
|
417
414
|
}
|
418
415
|
return vault.newWithdraw;
|
package/dist/test.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import { ethers } from
|
1
|
+
import { ethers } from 'ethers';
|
2
2
|
export declare const signer: ethers.Wallet;
|
package/package.json
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dripfi/drip-sdk",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.7",
|
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
|
+
"format": "prettier --write .",
|
10
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
11
12
|
},
|
12
13
|
"dependencies": {
|
@@ -19,6 +20,8 @@
|
|
19
20
|
"license": "ISC",
|
20
21
|
"devDependencies": {
|
21
22
|
"typescript": "^5.4.5",
|
22
|
-
"@types/js-cookie": "^3.0.6"
|
23
|
+
"@types/js-cookie": "^3.0.6",
|
24
|
+
"prettier": "3.2.5",
|
25
|
+
"prettier-plugin-tailwindcss": "^0.5.12"
|
23
26
|
}
|
24
27
|
}
|