@dripfi/drip-sdk 1.0.5 → 1.0.6
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 +18 -0
- package/dist/DripSdk.d.ts +5 -4
- package/dist/DripSdk.js +82 -88
- package/package.json +1 -1
package/README.md
CHANGED
@@ -45,3 +45,21 @@ const dripSdk = new DripSdk(dripConfig, signer);
|
|
45
45
|
|
46
46
|
- **getUserBalance(vault: Vault): Promise<UserBalance>**
|
47
47
|
Fetches the user's balance for a specific Drip Vault.
|
48
|
+
|
49
|
+
- **deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise**
|
50
|
+
The deposit function allows you to deposit tokens into a specific vault.
|
51
|
+
|
52
|
+
- **swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise**
|
53
|
+
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
|
54
|
+
|
55
|
+
- **withdraw(vault: Vault, amountToWithdraw?: string): Promise**
|
56
|
+
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()
|
57
|
+
|
58
|
+
- **claimWithdraws(vaultAddress: string): Promise**
|
59
|
+
After the withdrawal has been processed by the 'DoHardWork' function, the 'claimWithdraws' function transfers the withdrawn tokens to their personal account.
|
60
|
+
|
61
|
+
- **fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise**
|
62
|
+
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.
|
63
|
+
|
64
|
+
|
65
|
+
|
package/dist/DripSdk.d.ts
CHANGED
@@ -19,10 +19,11 @@ export default class DripSdk {
|
|
19
19
|
}>;
|
20
20
|
updateSigner(newSigner: Signer): void;
|
21
21
|
getUserBalance(vault: Vault): Promise<UserBalance>;
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
fastWithdraw(vault: Vault, amountToWithdraw?: string): Promise<void>;
|
23
|
+
deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<void>;
|
24
|
+
swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<void>;
|
25
|
+
withdraw(vault: Vault, amountToWithdraw?: string): Promise<void>;
|
26
|
+
claimWithdraws(vaultAddress: string): Promise<void>;
|
26
27
|
private generateOldRedeemBagStruct;
|
27
28
|
private generateNewRedeemBagStruct;
|
28
29
|
private getAllSvts;
|
package/dist/DripSdk.js
CHANGED
@@ -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();
|