@dripfi/drip-sdk 1.4.3-yelay-lite-3 → 1.4.3-yelay-lite-4

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.
Files changed (42) hide show
  1. package/README.md +220 -44
  2. package/dist/PerqApi.d.ts +10 -9
  3. package/dist/PerqApi.js +36 -36
  4. package/dist/PerqSdk.d.ts +32 -83
  5. package/dist/PerqSdk.js +47 -581
  6. package/dist/abi/ERC20.json +222 -0
  7. package/dist/contracts/ERC20TokenContract.d.ts +10 -0
  8. package/dist/contracts/ERC20TokenContract.js +34 -0
  9. package/dist/contracts/PerqSwapAndRecyclerContract.d.ts +3 -2
  10. package/dist/contracts/PerqSwapAndRecyclerContract.js +2 -2
  11. package/dist/contracts/PerqTokenRecyclerContract.d.ts +3 -2
  12. package/dist/contracts/PerqTokenRecyclerContract.js +2 -2
  13. package/dist/contracts/PerqVestingContract.d.ts +3 -2
  14. package/dist/contracts/PerqVestingContract.js +2 -2
  15. package/dist/subpackages/LitePackage.d.ts +13 -0
  16. package/dist/subpackages/LitePackage.js +88 -0
  17. package/dist/subpackages/LoyaltyCardsPackage.d.ts +12 -0
  18. package/dist/subpackages/LoyaltyCardsPackage.js +34 -0
  19. package/dist/subpackages/PoolsPackage.d.ts +16 -0
  20. package/dist/subpackages/PoolsPackage.js +52 -0
  21. package/dist/subpackages/RecyclerPackage.d.ts +13 -0
  22. package/dist/subpackages/RecyclerPackage.js +87 -0
  23. package/dist/subpackages/SignHandlerPackage.d.ts +8 -0
  24. package/dist/subpackages/SignHandlerPackage.js +33 -0
  25. package/dist/subpackages/TokenUtilsPackage.d.ts +13 -0
  26. package/dist/subpackages/TokenUtilsPackage.js +66 -0
  27. package/dist/subpackages/UserPackage.d.ts +7 -0
  28. package/dist/subpackages/UserPackage.js +23 -0
  29. package/dist/subpackages/V2Package.d.ts +24 -0
  30. package/dist/subpackages/V2Package.js +207 -0
  31. package/dist/subpackages/VestingPackage.d.ts +14 -0
  32. package/dist/subpackages/VestingPackage.js +112 -0
  33. package/dist/types/ChainId.d.ts +5 -0
  34. package/dist/types/ChainId.js +7 -0
  35. package/dist/types/DetailedProjectData.d.ts +8 -7
  36. package/dist/types/VaultData.d.ts +2 -0
  37. package/dist/types/index.d.ts +1 -2
  38. package/dist/utils/chains.d.ts +1 -0
  39. package/dist/utils/chains.js +2 -1
  40. package/package.json +2 -2
  41. package/dist/types/YelayLiteVault.d.ts +0 -11
  42. package/dist/types/YelayLiteVault.js +0 -2
package/dist/PerqSdk.js CHANGED
@@ -3,601 +3,67 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ethers_1 = require("ethers");
7
- const utils_1 = require("ethers/lib/utils");
8
- const spool_v2_sdk_1 = require("@spool.fi/spool-v2-sdk");
9
6
  const PerqApi_1 = __importDefault(require("./PerqApi"));
10
7
  const contracts_1 = require("./contracts");
11
- const WethTokenAbi_json_1 = __importDefault(require("./abi/WethTokenAbi.json"));
8
+ const VestingPackage_1 = __importDefault(require("./subpackages/VestingPackage"));
9
+ const LitePackage_1 = __importDefault(require("./subpackages/LitePackage"));
10
+ const V2Package_1 = __importDefault(require("./subpackages/V2Package"));
11
+ const RecyclerPackage_1 = __importDefault(require("./subpackages/RecyclerPackage"));
12
+ const LoyaltyCardsPackage_1 = __importDefault(require("./subpackages/LoyaltyCardsPackage"));
12
13
  const sdk_1 = require("@yelay-lite/sdk");
13
- const chains_1 = require("./utils/chains");
14
- const WETH_DECIMAL_PRECISION = 18;
14
+ const TokenUtilsPackage_1 = __importDefault(require("./subpackages/TokenUtilsPackage"));
15
+ const UserPackage_1 = __importDefault(require("./subpackages/UserPackage"));
16
+ const SignHandlerPackage_1 = __importDefault(require("./subpackages/SignHandlerPackage"));
17
+ const PoolsPackage_1 = __importDefault(require("./subpackages/PoolsPackage"));
18
+ const spool_v2_sdk_1 = require("@spool.fi/spool-v2-sdk");
15
19
  class PerqSdk {
16
20
  perqApi;
21
+ signer;
22
+ lite;
23
+ v2;
24
+ vesting;
25
+ recycler;
26
+ loyaltyCards;
27
+ tokenUtils;
28
+ user;
29
+ signHandler;
30
+ pools;
17
31
  perqConfig;
18
- perqTokenContract;
32
+ yelayLiteSdk;
33
+ spoolSdk;
34
+ perqVestingContract;
19
35
  perqTokenRecyclerContract;
20
36
  perqSwapAndRecyclerContract;
21
- perqVestingContract;
22
- spoolSdk;
23
- signer;
24
- yelayLiteSdk;
25
37
  constructor(perqConfig, provider) {
38
+ this.perqConfig = perqConfig;
26
39
  const newSigner = provider?.getSigner();
27
- if (provider && newSigner) {
40
+ if (newSigner) {
28
41
  this.signer = newSigner;
29
- this.yelayLiteSdk = new sdk_1.YelayLiteSdk(newSigner, perqConfig.yelayLiteSdkConfig);
30
- this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(perqConfig.spoolSdkConfig, newSigner);
31
- }
32
- this.perqConfig = perqConfig;
33
- this.perqApi = new PerqApi_1.default(perqConfig.route);
34
- this.perqTokenContract = new contracts_1.PerqTokenContract(perqConfig.perqTokenAddress, newSigner);
35
- this.perqTokenRecyclerContract = new contracts_1.PerqTokenRecyclerContract(perqConfig.perqTokenRecyclerAddress, newSigner);
36
- this.perqSwapAndRecyclerContract = new contracts_1.PerqSwapAndRecyclerContract(perqConfig.perqSwapAndRecyclerAddress, newSigner);
37
- this.perqVestingContract = new contracts_1.PerqVestingContract(perqConfig.perqVestingAddress, newSigner);
38
- }
39
- async getAllProjects() {
40
- return this.perqApi.fetchAllProjects();
41
- }
42
- async getProjectDetails(projectName) {
43
- return this.perqApi.fetchProjetctDetails(projectName);
44
- }
45
- async getAllVaults() {
46
- return this.perqApi.fetchAllVaults();
47
- }
48
- async getV2VaultDetails(vaultAddress) {
49
- return this.perqApi.fetchVaultV2Details(vaultAddress);
50
- }
51
- async getLiteVaultDetails(vaultAddress, onChainProjectId) {
52
- return this.perqApi.fetchVaultLiteDetails(vaultAddress, onChainProjectId);
53
- }
54
- async getVaultStats() {
55
- return this.perqApi.fetchVaultStats();
56
- }
57
- async getTokenPrice(tokenName) {
58
- return this.perqApi.fetchTokenPrice(tokenName);
42
+ this.yelayLiteSdk = new sdk_1.YelayLiteSdk(this.signer, perqConfig.yelayLiteSdkConfig);
43
+ this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(perqConfig.spoolSdkConfig, this.signer);
44
+ }
45
+ this.vesting = new VestingPackage_1.default(this);
46
+ this.lite = new LitePackage_1.default(this);
47
+ this.v2 = new V2Package_1.default(this);
48
+ this.recycler = new RecyclerPackage_1.default(this);
49
+ this.loyaltyCards = new LoyaltyCardsPackage_1.default(this);
50
+ this.tokenUtils = new TokenUtilsPackage_1.default(this);
51
+ this.tokenUtils = new TokenUtilsPackage_1.default(this);
52
+ this.user = new UserPackage_1.default(this);
53
+ this.signHandler = new SignHandlerPackage_1.default(this);
54
+ this.pools = new PoolsPackage_1.default(this);
55
+ this.perqApi = new PerqApi_1.default(this);
56
+ this.perqVestingContract = new contracts_1.PerqVestingContract(this);
57
+ this.perqTokenRecyclerContract = new contracts_1.PerqTokenRecyclerContract(this);
58
+ this.perqSwapAndRecyclerContract = new contracts_1.PerqSwapAndRecyclerContract(this);
59
59
  }
60
60
  async updateSigner(newSigner) {
61
61
  this.signer = newSigner;
62
- this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(this.perqConfig.spoolSdkConfig, newSigner);
63
- this.yelayLiteSdk = new sdk_1.YelayLiteSdk(newSigner, this.perqConfig.yelayLiteSdkConfig);
64
- this.perqTokenContract.updateSigner(newSigner);
65
- this.perqTokenRecyclerContract.updateSigner(newSigner);
66
- this.perqSwapAndRecyclerContract.updateSigner(newSigner);
67
- this.perqVestingContract.updateSigner(newSigner);
68
- }
69
- async yelayLiteDeposit(tokenAddress, vaultAddress, onChainProjectId, amount) {
70
- if (!this.signer) {
71
- throw Error('No signer provided');
72
- }
73
- const decimals = await this.getERC20Precission(tokenAddress);
74
- const parsedAmountToDeposit = ethers_1.ethers.utils.parseUnits(amount, decimals);
75
- const res = await this.yelayLiteSdk.vaults.deposit(vaultAddress, onChainProjectId, BigInt(parsedAmountToDeposit.toString()));
76
- return res.hash;
77
- }
78
- async newDeposit(tokenAddress, vaultAddress, amount) {
79
- return this.doDeposit(tokenAddress, vaultAddress, amount, false);
80
- }
81
- async deposit(tokenAddress, vaultAddress, amount) {
82
- return this.doDeposit(tokenAddress, vaultAddress, amount, true);
83
- }
84
- async doDeposit(tokenAddress, vaultAddress, amount, checkAllowance) {
85
- if (!this.signer) {
86
- throw Error('No signer provided');
87
- }
88
- const decimals = await this.getERC20Precission(tokenAddress);
89
- const amountWithDecimals = parseFloat(parseFloat(amount).toFixed(decimals));
90
- if (checkAllowance) {
91
- const currentTokenAllowance = parseFloat(ethers_1.ethers.utils.formatUnits(await this.getTokenAllowanceForDeposit(tokenAddress), decimals));
92
- if (amountWithDecimals > currentTokenAllowance) {
93
- await this.approveTokenForDeposit(tokenAddress, amountWithDecimals.toString());
94
- }
95
- }
96
- const amountToDeposit = ethers_1.ethers.utils.parseUnits(amountWithDecimals.toString(), decimals);
97
- const signerAddress = await this.signer.getAddress();
98
- if (!signerAddress) {
99
- throw Error('Error fetching address');
100
- }
101
- const depositBagStruct = {
102
- smartVault: vaultAddress.toLowerCase(),
103
- assets: [amountToDeposit],
104
- receiver: signerAddress,
105
- referral: ethers_1.ethers.constants.AddressZero,
106
- doFlush: false,
107
- };
108
- const depositTx = await this.spoolSdk.deposit(depositBagStruct);
109
- const txReceipt = await depositTx.wait();
110
- return txReceipt.transactionHash;
111
- }
112
- async getTokenAllowanceForCurrency(tokenAddress) {
113
- if (!this.signer) {
114
- throw Error('No signer provided');
115
- }
116
- const currentTokenAllowance = await this.getTokenAllowanceForDeposit(tokenAddress);
117
- return currentTokenAllowance.toString();
118
- }
119
- async getSwapAndDepositTokenAllowanceForCurrency(tokenAddress) {
120
- if (!this.signer) {
121
- throw Error('No signer provided');
122
- }
123
- const currentTokenAllowance = await this.getTokenAllowanceForSwapAndDeposit(tokenAddress);
124
- return currentTokenAllowance.toString();
125
- }
126
- async getTokenAllowanceForRecycler(tokenAddress) {
127
- if (!this.signer) {
128
- throw Error('No signer provided');
129
- }
130
- const allowance = await this.getERC20TokenAllowance(this.perqTokenRecyclerContract.getContractAddress(), tokenAddress);
131
- return allowance;
132
- }
133
- async getTokenAllowanceForSwapAndRecycler(tokenAddress) {
134
- if (!this.signer) {
135
- throw Error('No signer provided');
136
- }
137
- const allowance = await this.getERC20TokenAllowance(this.perqSwapAndRecyclerContract.getContractAddress(), tokenAddress);
138
- return allowance;
139
- }
140
- async getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals) {
141
- return this.perqApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, chains_1.ETHEREUM_CHAIN_ID.toString());
142
- }
143
- async getExpectedYelayLiteSwapResult(fromTokenAddress, toTokenAddress, amount, decimals) {
144
- return this.perqApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, chains_1.BASE_CHAIN_ID.toString());
145
- }
146
- async getUserBoostedNfts(vaultAddress) {
147
- const userAddress = await this.signer.getAddress();
148
- return this.perqApi.getUserBoostedNfts(userAddress, vaultAddress);
149
- }
150
- async getRewardsPerHour(vaultAddress) {
151
- const userAddress = await this.signer.getAddress();
152
- return this.perqApi.fetchRewardsPerHour(userAddress, vaultAddress);
153
- }
154
- async getRewards() {
155
- const userAddress = await this.signer.getAddress();
156
- const userRewards = this.perqApi.fetchUserRewards(userAddress);
157
- return userRewards;
158
- }
159
- async getMyPerqBalance() {
160
- const userAddress = await this.signer.getAddress();
161
- const myPerqBalance = this.perqApi.fetchMyPerqData(userAddress);
162
- return myPerqBalance;
163
- }
164
- async getYelayLiteUserVaultBalance(vaultAddress, onChainProjectId) {
165
- if (!this.signer) {
166
- throw Error('No signer provided');
167
- }
168
- const userAddress = await this.signer.getAddress();
169
- return await this.perqApi.fetchLiteVaultUserBalance(userAddress.toLowerCase(), vaultAddress.toLowerCase(), onChainProjectId);
170
- }
171
- async getUserVaultBalance(vaultAddress) {
172
- if (!this.signer) {
173
- throw Error('No signer provided');
174
- }
175
- const userAddress = await this.signer.getAddress();
176
- return await this.perqApi.fetchV2VaultUserBalance(userAddress.toLowerCase(), vaultAddress.toLowerCase());
177
- }
178
- async fastWithdraw(vaultAddress, amountToWithdraw) {
179
- if (!this.signer) {
180
- throw Error('No signer provided');
181
- }
182
- const userAddress = await this.signer.getAddress();
183
- if (!this.signer) {
184
- throw Error('No signer provided');
185
- }
186
- const vault = await this.getV2VaultDetails(vaultAddress);
187
- const redeemBagStruct = await this.generateRedeemBagStruct(vault, userAddress, amountToWithdraw);
188
- const currentBlockNumber = await this.signer.provider?.getBlockNumber();
189
- if (!currentBlockNumber) {
190
- throw Error('Error fetching block number');
191
- }
192
- const redeemTx = await this.spoolSdk?.redeemFast(redeemBagStruct, userAddress, currentBlockNumber);
193
- const txReceipt = await redeemTx.wait();
194
- return txReceipt.transactionHash;
195
- }
196
- async swapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
197
- return this.doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, true, ethAmount);
198
- }
199
- async newSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
200
- return this.doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, false, ethAmount);
201
- }
202
- async doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, checkAllowance, ethAmount) {
203
- const userAddress = await this.signer.getAddress();
204
- if (!this.signer) {
205
- throw Error('No signer provided');
206
- }
207
- const decimals = await this.getERC20Precission(fromTokenAddress);
208
- const amountWithDecimals = parseFloat(parseFloat(fromTokenAmount).toFixed(decimals));
209
- if (amountWithDecimals > 0 && checkAllowance) {
210
- const currentTokenAllowance = parseFloat(ethers_1.ethers.utils.formatUnits(await this.getTokenAllowanceForSwapAndDeposit(fromTokenAddress), decimals));
211
- if (amountWithDecimals > currentTokenAllowance) {
212
- await this.approveTokenForSwapAndDeposit(fromTokenAddress, amountWithDecimals.toString());
213
- }
214
- }
215
- const fromToken = ethers_1.ethers.utils.parseUnits(amountWithDecimals.toString(), decimals);
216
- const swapInfo = await this.perqApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken, this.perqConfig.ethereumSwapperAddress, chains_1.ETHEREUM_CHAIN_ID);
217
- const swapDepositBagStruct = {
218
- inTokens: [fromTokenAddress],
219
- inAmounts: [fromToken],
220
- smartVault: vaultAddress.toLowerCase(),
221
- swapInfo,
222
- receiver: userAddress,
223
- referral: ethers_1.ethers.constants.AddressZero,
224
- doFlush: false,
225
- };
226
- const swapAndDepositRequest = ethAmount
227
- ? await this.spoolSdk.swapAndDeposit(swapDepositBagStruct, { value: ethers_1.ethers.utils.parseEther(ethAmount) })
228
- : await this.spoolSdk.swapAndDeposit(swapDepositBagStruct);
229
- const txReceipt = await swapAndDepositRequest.wait();
230
- return txReceipt?.transactionHash;
231
- }
232
- async withdraw(vaultAddress, amountToWithdraw) {
233
- if (!this.signer) {
234
- throw Error('No signer provided');
235
- }
236
- const userAddress = await this.signer.getAddress();
237
- if (!this.signer) {
238
- throw Error('No signer provided');
239
- }
240
- const vault = await this.getV2VaultDetails(vaultAddress);
241
- const redeemBagStruct = await this.generateRedeemBagStruct(vault, userAddress, amountToWithdraw);
242
- const redeemTx = await this.spoolSdk.redeem(redeemBagStruct, userAddress, false);
243
- const redeemTxReceipt = await redeemTx.wait();
244
- return redeemTxReceipt.transactionHash;
245
- }
246
- async getYelayLiteSwapAndDepositAllowance(tokenAddress) {
247
- const res = await this.yelayLiteSdk.vaults.vaultWrapperAllowance(tokenAddress);
248
- return res.toString();
249
- }
250
- async approveYelayLiteSwapAndDeposit(tokenAddress, amount) {
251
- const decimals = await this.getERC20Precission(tokenAddress);
252
- const parsedAmountToApprove = ethers_1.ethers.utils.parseUnits(amount, decimals);
253
- const res = await this.yelayLiteSdk.vaults.approveVaultWrapper(tokenAddress, parsedAmountToApprove.toBigInt());
254
- return res.hash;
255
- }
256
- async yelayLiteSwapAndDeposit(fromTokenAddress, toTokenAddress, amount, vaultAddress, projectId) {
257
- const decimals = await this.getERC20Precission(fromTokenAddress);
258
- const parsedAmountToSwapAndDeposit = ethers_1.ethers.utils.parseUnits(amount, decimals);
259
- const swapInfo = await this.perqApi.getSwapInfo(fromTokenAddress, toTokenAddress, parsedAmountToSwapAndDeposit, this.perqConfig.baseSwapperAddress, chains_1.BASE_CHAIN_ID);
260
- const swapArgsStruct = {
261
- tokenIn: swapInfo[0].token,
262
- swapTarget: swapInfo[0].swapTarget,
263
- swapCallData: swapInfo[0].swapCallData,
264
- };
265
- const res = await this.yelayLiteSdk.vaults.swapAndDeposit(vaultAddress.toLowerCase(), projectId, parsedAmountToSwapAndDeposit.toBigInt(), swapArgsStruct);
266
- return res.hash;
267
- }
268
- async yelayLiteWithdraw(tokenAddress, vaultAddress, onChainProjectId, amount) {
269
- if (!this.signer) {
270
- throw Error('No signer provided');
271
- }
272
- const decimals = await this.getERC20Precission(tokenAddress);
273
- const parsedAmountToWithdraw = ethers_1.ethers.utils.parseUnits(amount, decimals);
274
- const res = await this.yelayLiteSdk.vaults.redeem(vaultAddress, onChainProjectId, BigInt(parsedAmountToWithdraw.toString()));
275
- return res.hash;
276
- }
277
- async claimWithdraws(vaultAddress) {
278
- const userAddress = await this.signer.getAddress();
279
- if (!this.signer) {
280
- throw Error('No signer provided');
281
- }
282
- const wnfts = await this.perqApi.fetchEnrichedUserWNFTForVault(vaultAddress, userAddress);
283
- //! Shares come as Strings instead of BigNumber from our Backend
284
- const nftIds = wnfts
285
- .filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
286
- .map((item) => item.nftId.toString());
287
- const nftAmounts = wnfts
288
- .filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
289
- .map((item) => item.shares.toString());
290
- const claimWithdrawTx = await this.spoolSdk.claimWithdrawal(vaultAddress.toLowerCase(), nftIds, nftAmounts, userAddress);
291
- const txReceipt = await claimWithdrawTx.wait();
292
- return txReceipt.transactionHash;
293
- }
294
- async getBeansBalance() {
295
- const userAddress = await this.signer.getAddress();
296
- return this.perqApi.fetchBeansBalance(userAddress);
297
- }
298
- async getBeansHistory() {
299
- const userAddress = await this.signer.getAddress();
300
- return this.perqApi.fetchBeansHistory(userAddress);
301
- }
302
- async recycleTokens(tokenAddress = this.perqConfig.perqTokenAddress, amountToRecycle, beneficiary = ethers_1.ethers.constants.AddressZero, price, deadline, signature) {
303
- if (this.perqConfig.perqTokenRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
304
- throw Error('Recycler contract address not defined');
305
- }
306
- const decimals = await this.getERC20Precission(tokenAddress);
307
- const amountWithDecimals = ethers_1.ethers.utils.parseUnits(amountToRecycle, decimals).toString();
308
- const recycleTx = await this.perqTokenRecyclerContract.recycle(amountWithDecimals, beneficiary, price, deadline, signature);
309
- const receipt = await recycleTx.wait();
310
- return receipt.transactionHash;
311
- }
312
- async swapAndRecycleETH(beneficiary, path, minAmountOutWithDecimals, amountOfEth, price, deadline, signature) {
313
- if (this.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
314
- throw Error('Recycler contract address not defined');
315
- }
316
- const swapAndRecycleTx = await this.perqSwapAndRecyclerContract.swapETHAndRecycle(beneficiary, path, minAmountOutWithDecimals, amountOfEth, price, deadline, signature);
317
- const receipt = await swapAndRecycleTx.wait();
318
- return receipt.transactionHash;
319
- }
320
- async swapAndRecycleERC20(beneficiary, path, minAmountOutWithDecimals, amountInWithDecimals, price, deadline, signature) {
321
- if (this.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
322
- throw Error('Recycler contract address not defined');
323
- }
324
- const swapAndRecycleTx = await this.perqSwapAndRecyclerContract.swapAndRecycle(beneficiary, path, amountInWithDecimals, minAmountOutWithDecimals, price, deadline, signature);
325
- const receipt = await swapAndRecycleTx.wait();
326
- return receipt.transactionHash;
327
- }
328
- async upgradeLoyaltyCard(index) {
329
- const payload = {
330
- index,
331
- };
332
- const signedPayload = await this.signPayload(payload);
333
- return this.perqApi.upgradeLoyaltyCard(signedPayload);
334
- }
335
- async getOwnedLoyaltyCard() {
336
- const signerAddress = await this.signer.getAddress();
337
- return this.perqApi.fetchOwnedLoyaltyCard(signerAddress);
338
- }
339
- async getAllLoyaltyCards() {
340
- return this.perqApi.fetchAllLoyaltyCards();
341
- }
342
- async approveTokenForRecycler(tokenAddress, amount) {
343
- if (!this.signer) {
344
- throw Error('No signer provided');
345
- }
346
- if (this.perqConfig.perqTokenRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
347
- throw Error('Recycler contract address not defined');
348
- }
349
- return await this.approveToken(tokenAddress, amount, this.perqConfig.perqTokenRecyclerAddress);
350
- }
351
- async approveTokenForSwapAndRecycler(tokenAddress, amount) {
352
- if (!this.signer) {
353
- throw Error('No signer provided');
354
- }
355
- if (this.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
356
- throw Error('Recycler contract address not defined');
357
- }
358
- return await this.approveToken(tokenAddress, amount, this.perqConfig.perqSwapAndRecyclerAddress);
359
- }
360
- async approveTokenForSwapAndDeposit(tokenAddress, amount) {
361
- return await this.approveToken(tokenAddress, amount, this.perqConfig.swapAndDepositContractAddress);
362
- }
363
- async approveTokenForDeposit(tokenAddress, amount) {
364
- return await this.approveToken(tokenAddress, amount, this.perqConfig.smartVaultManagerContractAddress);
365
- }
366
- getPerqTokenContractAddress() {
367
- return this.perqConfig.perqTokenAddress;
368
- }
369
- async getSwapPerqForBeansInfo() {
370
- return this.perqApi.getSwapPerqForBeansInfo();
371
- }
372
- async getAllowance(tokenAddress, spender) {
373
- const allowance = await this.getERC20TokenAllowance(spender, tokenAddress);
374
- return allowance.toString();
375
- }
376
- async approveAllowance(tokenAddress, amount, spenderAddress) {
377
- const decimals = await this.getERC20Precission(tokenAddress);
378
- const amountWithDecimals = parseFloat(parseFloat(amount).toFixed(decimals));
379
- return await this.approveToken(tokenAddress, amountWithDecimals.toString(), spenderAddress);
380
- }
381
- async transferErc20Token(tokenAddress, amount, receiver) {
382
- if (!this.signer) {
383
- throw Error('No signer provided');
384
- }
385
- const decimals = await this.getERC20Precission(tokenAddress);
386
- const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
387
- const approveTx = await erc20Instance.transfer(receiver, ethers_1.ethers.utils.parseUnits(amount, decimals));
388
- const receipt = await approveTx.wait();
389
- return receipt.transactionHash;
390
- }
391
- async wrapEther(amount, tokenAddress) {
392
- if (!this.signer) {
393
- throw Error('No signer provided');
394
- }
395
- const wethContract = new ethers_1.ethers.Contract(tokenAddress, WethTokenAbi_json_1.default, this.signer);
396
- const decimals = await wethContract.decimals();
397
- const amountWithDecimals = ethers_1.ethers.utils.parseUnits(amount, decimals);
398
- const depositTx = await wethContract.deposit({ value: amountWithDecimals });
399
- const receipt = await depositTx.wait();
400
- return receipt.transactionHash;
401
- }
402
- async getVestingStart() {
403
- try {
404
- const startBigNumber = await this.perqVestingContract.start();
405
- return startBigNumber.toString();
406
- }
407
- catch (error) {
408
- if (error instanceof Error) {
409
- throw new Error(`Failed to get vesting start time: ${error.message}`);
410
- }
411
- throw new Error('Failed to get vesting start time: Unknown error');
412
- }
413
- }
414
- async getVestingEnd() {
415
- try {
416
- const endBigNumber = await this.perqVestingContract.end();
417
- return endBigNumber.toString();
418
- }
419
- catch (error) {
420
- if (error instanceof Error) {
421
- throw new Error(`Failed to get vesting end time: ${error.message}`);
422
- }
423
- throw new Error('Failed to get vesting end time: Unknown error');
424
- }
425
- }
426
- async getVestedAmount(beneficiary) {
427
- try {
428
- const vestedAmount = await this.perqVestingContract.vested(beneficiary);
429
- return (0, utils_1.formatUnits)(vestedAmount, 18);
430
- }
431
- catch (error) {
432
- if (error instanceof Error) {
433
- throw new Error(`Failed to get vested amount: ${error.message}`);
434
- }
435
- throw new Error('Failed to get vested amount: Unknown error');
436
- }
437
- }
438
- async getReleasableAmount(beneficiary) {
439
- try {
440
- const releasableAmount = await this.perqVestingContract.releasable(beneficiary);
441
- return (0, utils_1.formatUnits)(releasableAmount, 18);
442
- }
443
- catch (error) {
444
- if (error instanceof Error) {
445
- throw new Error(`Failed to get releasable amount: ${error.message}`);
446
- }
447
- throw new Error('Failed to get releasable amount: Unknown error');
448
- }
449
- }
450
- async getReleasableTotalAmount(beneficiary) {
451
- try {
452
- const releasableTotalAmount = await this.perqVestingContract.releasableTotal(beneficiary);
453
- return (0, utils_1.formatUnits)(releasableTotalAmount, 18);
454
- }
455
- catch (error) {
456
- if (error instanceof Error) {
457
- throw new Error(`Failed to get total releasable amount: ${error.message}`);
458
- }
459
- throw new Error('Failed to get total releasable amount: Unknown error');
460
- }
461
- }
462
- async getAllVestingInfo(beneficiaryAddress) {
463
- const [startTimestamp, endTimestamp, vested, releasable, releasableTotal] = await Promise.all([
464
- this.getVestingStart(),
465
- this.getVestingEnd(),
466
- this.getVestedAmount(beneficiaryAddress),
467
- this.getReleasableAmount(beneficiaryAddress),
468
- this.getReleasableTotalAmount(beneficiaryAddress),
469
- ]);
470
- return {
471
- startTimestamp,
472
- endTimestamp,
473
- vested,
474
- releasable,
475
- releasableTotal,
476
- };
477
- }
478
- async claimVestedPerq(amount) {
479
- try {
480
- const claimTx = await this.perqVestingContract.claim(amount);
481
- const txReceipt = await claimTx.wait();
482
- return txReceipt.transactionHash;
483
- }
484
- catch (error) {
485
- if (error instanceof Error) {
486
- throw new Error(`Failed to get total releasable amount: ${error.message}`);
487
- }
488
- throw new Error('Failed to get total releasable amount: Unknown error');
489
- }
490
- }
491
- async burnVestedPerq(amount, price, deadline, signature) {
492
- try {
493
- const burnTx = await this.perqVestingContract.burn(amount, price, deadline, signature);
494
- const txReceipt = await burnTx.wait();
495
- return txReceipt.transactionHash;
496
- }
497
- catch (error) {
498
- if (error instanceof Error) {
499
- throw new Error(`Failed to get total releasable amount: ${error.message}`);
500
- }
501
- throw new Error('Failed to get total releasable amount: Unknown error');
502
- }
503
- }
504
- async linkSuiWalletWithEthWallet(suiWalletAddress) {
505
- const payload = {
506
- suiWalletAddr: suiWalletAddress,
507
- };
508
- const signedPayload = await this.signPayload(payload);
509
- return this.perqApi.linkSuiWalletWithEthWallet(signedPayload);
510
- }
511
- async getLinkedSuiWallet() {
512
- if (!this.signer) {
513
- throw new Error('No signer provided');
514
- }
515
- const walletAddr = await this.signer.getAddress();
516
- return this.perqApi.getLinkedSuiWallet(walletAddr);
517
- }
518
- async signPayload(payload) {
519
- if (!this.signer) {
520
- throw new Error('No signer provided');
521
- }
522
- // Wrap the payload in a Basepayload to enrich it later on
523
- const basePayload = {
524
- payload,
525
- };
526
- const signerAddress = await this.signer.getAddress();
527
- // Get enriched payload with nonce before signing
528
- const enrichedPayload = await this.getEnrichedPayload(basePayload);
529
- // Create message to sign
530
- const message = JSON.stringify(enrichedPayload);
531
- // Sign the message
532
- const signature = await this.signer.signMessage(message);
533
- return {
534
- signature,
535
- signerAddress,
536
- payload: enrichedPayload,
537
- };
538
- }
539
- async getEnrichedPayload(payload) {
540
- return this.perqApi.getNonceEnrichedPayload(payload.payload);
541
- }
542
- async generateRedeemBagStruct(vault, signerAddress, amountToWithdraw) {
543
- if (!this.spoolSdk) {
544
- throw Error('No spool sdk provided');
545
- }
546
- const isFullWithdraw = !amountToWithdraw;
547
- if (isFullWithdraw) {
548
- return this.spoolSdk.views.userInfo.getMaxRedeemBag({
549
- userAddress: signerAddress.toLowerCase(),
550
- vaultAddress: vault.vaultAddress.toLowerCase(),
551
- });
552
- }
553
- else {
554
- return this.spoolSdk.views.userInfo.getMinimumBurnRedeemBag({
555
- userAddress: signerAddress.toLowerCase(),
556
- vaultAddress: vault.vaultAddress.toLowerCase(),
557
- assetsToWithdraw: [Number(amountToWithdraw)],
558
- });
559
- }
560
- }
561
- async getERC20Precission(tokenAddress) {
562
- if (!this.signer) {
563
- throw Error('No signer provided');
564
- }
565
- const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
566
- const decimals = await erc20Instance.decimals();
567
- return decimals;
568
- }
569
- async getTokenAllowanceForDeposit(tokenAddress) {
570
- return await this.getERC20TokenAllowance(this.perqConfig.smartVaultManagerContractAddress, tokenAddress);
571
- }
572
- async getTokenAllowanceForSwapAndDeposit(tokenAddress) {
573
- return await this.getERC20TokenAllowance(this.perqConfig.swapAndDepositContractAddress, tokenAddress);
574
- }
575
- async getERC20TokenAllowance(spender, tokenAddress) {
576
- if (!this.signer) {
577
- throw Error('No signer provided');
578
- }
579
- const signerAddress = await this.signer.getAddress();
580
- const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
581
- const allowance = await erc20Instance.allowance(signerAddress, spender);
582
- return allowance;
583
- }
584
- async approveToken(tokenAddress, amount, spender) {
585
- if (!this.signer) {
586
- throw Error('No signer provided');
587
- }
588
- const decimals = await this.getERC20Precission(tokenAddress);
589
- const erc20Instance = spool_v2_sdk_1.ERC20__factory.connect(tokenAddress, this.signer);
590
- const approveTx = await erc20Instance.approve(spender, ethers_1.ethers.utils.parseUnits(amount, decimals));
591
- const receipt = await approveTx.wait();
592
- return receipt.transactionHash;
593
- }
594
- async yelayLiteWrapAndDepositEth(vaultAddress, onChainProjectId, amount) {
595
- if (!this.signer) {
596
- throw Error('No signer provided');
597
- }
598
- const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, WETH_DECIMAL_PRECISION);
599
- const res = await this.yelayLiteSdk.vaults.depositEth(vaultAddress, onChainProjectId, BigInt(parsedAmount.toString()));
600
- return res.hash;
62
+ this.yelayLiteSdk = new sdk_1.YelayLiteSdk(this.signer, this.perqConfig.yelayLiteSdkConfig);
63
+ this.spoolSdk = new spool_v2_sdk_1.SpoolSdk(this.perqConfig.spoolSdkConfig, this.signer);
64
+ this.perqVestingContract = new contracts_1.PerqVestingContract(this);
65
+ this.perqTokenRecyclerContract = new contracts_1.PerqTokenRecyclerContract(this);
66
+ this.perqSwapAndRecyclerContract = new contracts_1.PerqSwapAndRecyclerContract(this);
601
67
  }
602
68
  }
603
69
  exports.default = PerqSdk;