@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 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
- private fastWithdraw;
23
- private deposit;
24
- private swapAndDeposit;
25
- private withdraw;
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
- var _a, _b;
137
- if (!this.signer)
138
- throw Error('No signer provided');
139
- try {
140
- const signerAddress = yield this.signer.getAddress();
141
- if (!signerAddress)
142
- throw Error('Error fetching address');
143
- const redeemBagStruct = this.shouldUseNewWithdrawLogic(signerAddress, vault)
144
- ? yield this.generateNewRedeemBagStruct(vault, signerAddress, amountToWithdraw)
145
- : yield this.generateOldRedeemBagStruct(vault, signerAddress, amountToWithdraw);
146
- const currentBlockNumber = yield ((_a = this.signer.provider) === null || _a === void 0 ? void 0 : _a.getBlockNumber());
147
- if (!currentBlockNumber)
148
- throw Error('Error fetching block number');
149
- const redeemTx = yield ((_b = this.spoolSdk) === null || _b === void 0 ? void 0 : _b.redeemFast(redeemBagStruct, signerAddress.toLowerCase(), currentBlockNumber));
150
- const redeemTxReceipt = yield redeemTx.wait();
151
- }
152
- catch (error) {
153
- console.log(error);
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
- throw Error('No signer provided');
161
- const currentTokenAllowance = yield this.getTokenAllowanceForDeposit(tokenAddress);
162
- const decimals = yield this.getERC20Precission(tokenAddress);
163
- let amountToWithdrawFixedDecimals = parseFloat(amount).toFixed(decimals);
164
- const amountToDeposit = ethers_1.ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals);
165
- if (amountToDeposit.gt(currentTokenAllowance)) {
166
- const requiredTokenAllowance = amountToDeposit.sub(currentTokenAllowance);
167
- yield this.approveTokenForDeposit(tokenAddress, requiredTokenAllowance);
168
- }
169
- const signerAddress = yield this.signer.getAddress();
170
- if (!signerAddress)
171
- throw Error('Error fetching address');
172
- const depositBagStruct = {
173
- smartVault: vaultAddress,
174
- assets: [amountToDeposit],
175
- receiver: signerAddress,
176
- referral: ethers_1.ethers.constants.AddressZero,
177
- doFlush: false,
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
- var _a, _b;
186
- if (!this.signer)
187
- throw Error('No signer provided');
188
- const decimals = yield this.getERC20Precission(fromTokenAddress);
189
- const amountToWithdrawFixedDecimals = parseFloat(fromTokenAmount).toFixed(decimals);
190
- const fromToken = ethers_1.ethers.utils.parseUnits(amountToWithdrawFixedDecimals, decimals);
191
- const signerAddress = yield this.signer.getAddress();
192
- if (fromToken.gt(ethers_1.BigNumber.from(0))) {
193
- const currentTokenAllowance = yield this.getTokenAllowanceForSwapAndDepositContractAddress(fromTokenAddress);
194
- if (fromToken.gt(currentTokenAllowance)) {
195
- yield this.approveTokenForSwapAndDepositContract(fromTokenAddress, fromToken.sub(currentTokenAllowance));
196
- }
197
- }
198
- const swapInfo = yield this.dripApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken, signerAddress);
199
- const swapDepositBagStruct = {
200
- inTokens: [fromTokenAddress],
201
- inAmounts: [fromToken],
202
- smartVault: vaultAddress,
203
- swapInfo,
204
- receiver: signerAddress,
205
- referral: ethers_1.ethers.constants.AddressZero,
206
- doFlush: false,
207
- };
208
- let swapAndDepositRequest;
209
- if (ethAmount) {
210
- const eth = ethers_1.ethers.utils.parseEther(ethAmount);
211
- swapAndDepositRequest = yield ((_a = this.spoolSdk) === null || _a === void 0 ? void 0 : _a.swapAndDeposit(swapDepositBagStruct, { value: eth }));
212
- }
213
- else {
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
- throw Error('No signer provided');
223
- try {
224
- const signerAddress = yield this.signer.getAddress();
225
- if (!signerAddress)
226
- throw Error('Error fetching address');
227
- const redeemBagStruct = this.shouldUseNewWithdrawLogic(signerAddress, vault)
228
- ? yield this.generateNewRedeemBagStruct(vault, signerAddress, amountToWithdraw)
229
- : yield this.generateOldRedeemBagStruct(vault, signerAddress, amountToWithdraw);
230
- const redeemTx = yield this.spoolSdk.redeem(redeemBagStruct, signerAddress.toLowerCase(), false);
231
- const redeemTxReceipt = yield redeemTx.wait();
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dripfi/drip-sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Drip SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",