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