@dripfi/drip-sdk 1.4.9 → 1.4.10

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 (53) hide show
  1. package/README.md +206 -45
  2. package/dist/PerqApi.d.ts +22 -20
  3. package/dist/PerqApi.js +127 -92
  4. package/dist/PerqSdk.d.ts +35 -70
  5. package/dist/PerqSdk.js +51 -534
  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 +16 -0
  16. package/dist/subpackages/LitePackage.js +102 -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 +10 -0
  28. package/dist/subpackages/UserPackage.js +36 -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/DeployedProject.d.ts +3 -0
  36. package/dist/types/DetailedProjectData.d.ts +34 -0
  37. package/dist/types/DetailedProjectData.js +2 -0
  38. package/dist/types/Earnings.d.ts +11 -0
  39. package/dist/types/Earnings.js +2 -0
  40. package/dist/types/LinkWalletPayload.d.ts +4 -2
  41. package/dist/types/LinkedPodWallets.d.ts +5 -0
  42. package/dist/types/LinkedPodWallets.js +2 -0
  43. package/dist/types/MigrationOption.d.ts +6 -0
  44. package/dist/types/MigrationOption.js +2 -0
  45. package/dist/types/MyPerqData.d.ts +10 -10
  46. package/dist/types/PerqConfig.d.ts +5 -3
  47. package/dist/types/PerqConfig.js +12 -10
  48. package/dist/types/ReducedProjectData.d.ts +21 -0
  49. package/dist/types/ReducedProjectData.js +2 -0
  50. package/dist/types/VaultData.d.ts +33 -0
  51. package/dist/types/VaultData.js +2 -0
  52. package/dist/types/index.d.ts +8 -2
  53. package/package.json +2 -2
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ethers_1 = require("ethers");
7
+ const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
8
+ class RecyclerPackage {
9
+ perqSdk;
10
+ constructor(perqSdk) {
11
+ this.perqSdk = perqSdk;
12
+ }
13
+ async getTokenAllowanceForRecycler(tokenAddress) {
14
+ if (!this.perqSdk.signer) {
15
+ throw Error('No signer provided');
16
+ }
17
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
18
+ const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), this.perqSdk.perqTokenRecyclerContract.getContractAddress());
19
+ return allowance;
20
+ }
21
+ async getTokenAllowanceForSwapAndRecycler(tokenAddress) {
22
+ if (!this.perqSdk.signer) {
23
+ throw Error('No signer provided');
24
+ }
25
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
26
+ const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), this.perqSdk.perqSwapAndRecyclerContract.getContractAddress());
27
+ return allowance;
28
+ }
29
+ async recycleTokens(tokenAddress = this.perqSdk.perqConfig.perqTokenAddress, amountToRecycle, beneficiary = ethers_1.ethers.constants.AddressZero, price, deadline, signature) {
30
+ if (this.perqSdk.perqConfig.perqTokenRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
31
+ throw Error('Recycler contract address not defined');
32
+ }
33
+ if (!this.perqSdk.signer) {
34
+ throw Error('No signer provided');
35
+ }
36
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
37
+ const decimals = await tokenContract.getPrecission();
38
+ const amountWithDecimals = ethers_1.ethers.utils.parseUnits(amountToRecycle, decimals).toString();
39
+ const recycleTx = await this.perqSdk.perqTokenRecyclerContract.recycle(amountWithDecimals, beneficiary, price, deadline, signature);
40
+ const receipt = await recycleTx.wait();
41
+ return receipt.transactionHash;
42
+ }
43
+ async swapAndRecycleETH(beneficiary, path, minAmountOutWithDecimals, amountOfEth, price, deadline, signature) {
44
+ if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
45
+ throw Error('Recycler contract address not defined');
46
+ }
47
+ const swapAndRecycleTx = await this.perqSdk.perqSwapAndRecyclerContract.swapETHAndRecycle(beneficiary, path, minAmountOutWithDecimals, amountOfEth, price, deadline, signature);
48
+ const receipt = await swapAndRecycleTx.wait();
49
+ return receipt.transactionHash;
50
+ }
51
+ async swapAndRecycleERC20(beneficiary, path, minAmountOutWithDecimals, amountInWithDecimals, price, deadline, signature) {
52
+ if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
53
+ throw Error('Recycler contract address not defined');
54
+ }
55
+ const swapAndRecycleTx = await this.perqSdk.perqSwapAndRecyclerContract.swapAndRecycle(beneficiary, path, amountInWithDecimals, minAmountOutWithDecimals, price, deadline, signature);
56
+ const receipt = await swapAndRecycleTx.wait();
57
+ return receipt.transactionHash;
58
+ }
59
+ async approveTokenForRecycler(tokenAddress, amount) {
60
+ if (!this.perqSdk.signer) {
61
+ throw Error('No signer provided');
62
+ }
63
+ if (this.perqSdk.perqConfig.perqTokenRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
64
+ throw Error('Recycler contract address not defined');
65
+ }
66
+ if (!this.perqSdk.signer) {
67
+ throw Error('No signer provided');
68
+ }
69
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
70
+ const decimals = await tokenContract.getPrecission();
71
+ const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
72
+ return await tokenContract.approveToken(this.perqSdk.perqConfig.perqTokenRecyclerAddress, parsedAmount);
73
+ }
74
+ async approveTokenForSwapAndRecycler(tokenAddress, amount) {
75
+ if (!this.perqSdk.signer) {
76
+ throw Error('No signer provided');
77
+ }
78
+ if (this.perqSdk.perqConfig.perqSwapAndRecyclerAddress === ethers_1.ethers.constants.AddressZero) {
79
+ throw Error('Recycler contract address not defined');
80
+ }
81
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
82
+ const decimals = await tokenContract.getPrecission();
83
+ const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
84
+ return await tokenContract.approveToken(this.perqSdk.perqConfig.perqSwapAndRecyclerAddress, parsedAmount);
85
+ }
86
+ }
87
+ exports.default = RecyclerPackage;
@@ -0,0 +1,8 @@
1
+ import PerqSdk from '../PerqSdk';
2
+ import { NonceEnrichedSignedPayload } from '../types';
3
+ export default class SignHandlerPackage {
4
+ private perqSdk;
5
+ constructor(perqSdk: PerqSdk);
6
+ private getEnrichedPayload;
7
+ signPayload<T>(payload: T): Promise<NonceEnrichedSignedPayload<T>>;
8
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class SignHandlerPackage {
4
+ perqSdk;
5
+ constructor(perqSdk) {
6
+ this.perqSdk = perqSdk;
7
+ }
8
+ async getEnrichedPayload(payload) {
9
+ return this.perqSdk.perqApi.getNonceEnrichedPayload(payload.payload);
10
+ }
11
+ async signPayload(payload) {
12
+ if (!this.perqSdk.signer) {
13
+ throw new Error('No signer provided');
14
+ }
15
+ // Wrap the payload in a Basepayload to enrich it later on
16
+ const basePayload = {
17
+ payload,
18
+ };
19
+ const signerAddress = await this.perqSdk.signer.getAddress();
20
+ // Get enriched payload with nonce before signing
21
+ const enrichedPayload = await this.getEnrichedPayload(basePayload);
22
+ // Create message to sign
23
+ const message = JSON.stringify(enrichedPayload);
24
+ // Sign the message
25
+ const signature = await this.perqSdk.signer.signMessage(message);
26
+ return {
27
+ signature,
28
+ signerAddress,
29
+ payload: enrichedPayload,
30
+ };
31
+ }
32
+ }
33
+ exports.default = SignHandlerPackage;
@@ -0,0 +1,13 @@
1
+ import { BigNumber } from 'ethers';
2
+ import PerqSdk from '../PerqSdk';
3
+ export default class TokenUtilsPackage {
4
+ private perqSdk;
5
+ constructor(perqSdk: PerqSdk);
6
+ getTokenPrice(tokenName: string): Promise<number>;
7
+ getAllowance(tokenAddress: string, spender: string): Promise<string>;
8
+ approveAllowance(tokenAddress: string, amount: string, spenderAddress: string): Promise<string>;
9
+ transferErc20Token(tokenAddress: string, amount: string, receiver: string): Promise<string>;
10
+ wrapEther(amount: string, tokenAddress: string): Promise<string>;
11
+ getERC20TokenAllowance(spender: string, tokenAddress: string): Promise<BigNumber>;
12
+ getPerqTokenContractAddress(): string;
13
+ }
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ethers_1 = require("ethers");
7
+ const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
8
+ const WethTokenAbi_json_1 = __importDefault(require("../abi/WethTokenAbi.json"));
9
+ class TokenUtilsPackage {
10
+ perqSdk;
11
+ constructor(perqSdk) {
12
+ this.perqSdk = perqSdk;
13
+ }
14
+ async getTokenPrice(tokenName) {
15
+ return this.perqSdk.perqApi.fetchTokenPrice(tokenName);
16
+ }
17
+ async getAllowance(tokenAddress, spender) {
18
+ if (!this.perqSdk.signer) {
19
+ throw Error('No signer provided');
20
+ }
21
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
22
+ const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), spender);
23
+ return allowance.toString();
24
+ }
25
+ async approveAllowance(tokenAddress, amount, spenderAddress) {
26
+ if (!this.perqSdk.signer) {
27
+ throw Error('No signer provided');
28
+ }
29
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
30
+ const decimals = await tokenContract.getPrecission();
31
+ const parsedAmount = ethers_1.ethers.utils.parseUnits(parseFloat(amount).toFixed(decimals), decimals);
32
+ return await tokenContract.approveToken(spenderAddress, parsedAmount.toString());
33
+ }
34
+ async transferErc20Token(tokenAddress, amount, receiver) {
35
+ if (!this.perqSdk.signer) {
36
+ throw Error('No signer provided');
37
+ }
38
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
39
+ const decimals = await tokenContract.getPrecission();
40
+ const txHash = await tokenContract.transfer(receiver, ethers_1.ethers.utils.parseUnits(amount, decimals).toString());
41
+ return txHash;
42
+ }
43
+ async wrapEther(amount, tokenAddress) {
44
+ if (!this.perqSdk.signer) {
45
+ throw Error('No signer provided');
46
+ }
47
+ const wethContract = new ethers_1.ethers.Contract(tokenAddress, WethTokenAbi_json_1.default, this.perqSdk.signer);
48
+ const decimals = await wethContract.decimals();
49
+ const amountWithDecimals = ethers_1.ethers.utils.parseUnits(amount, decimals);
50
+ const depositTx = await wethContract.deposit({ value: amountWithDecimals });
51
+ const receipt = await depositTx.wait();
52
+ return receipt.transactionHash;
53
+ }
54
+ async getERC20TokenAllowance(spender, tokenAddress) {
55
+ if (!this.perqSdk.signer) {
56
+ throw Error('No signer provided');
57
+ }
58
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
59
+ const allowance = tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), spender);
60
+ return allowance;
61
+ }
62
+ getPerqTokenContractAddress() {
63
+ return this.perqSdk.perqConfig.perqTokenAddress;
64
+ }
65
+ }
66
+ exports.default = TokenUtilsPackage;
@@ -0,0 +1,10 @@
1
+ import PerqSdk from '../PerqSdk';
2
+ import { Earnings, LinkedPodWallets } from '../types';
3
+ export default class UserPackage {
4
+ private perqSdk;
5
+ constructor(perqSdk: PerqSdk);
6
+ getEarnings(projectName: string): Promise<Earnings>;
7
+ linkSuiWalletWithEthWallet(suiWalletAddress: string): Promise<boolean>;
8
+ linkNearWalletWithEthWallet(nearWalletAddress: string): Promise<boolean>;
9
+ getLinkedPodWallets(): Promise<LinkedPodWallets>;
10
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class UserPackage {
4
+ perqSdk;
5
+ constructor(perqSdk) {
6
+ this.perqSdk = perqSdk;
7
+ }
8
+ async getEarnings(projectName) {
9
+ if (!this.perqSdk.signer) {
10
+ throw new Error('No signer provided');
11
+ }
12
+ return this.perqSdk.perqApi.fetchEarnings(await this.perqSdk.signer.getAddress(), projectName);
13
+ }
14
+ async linkSuiWalletWithEthWallet(suiWalletAddress) {
15
+ const payload = {
16
+ suiWalletAddr: suiWalletAddress,
17
+ };
18
+ const signedPayload = await this.perqSdk.signHandler.signPayload(payload);
19
+ return this.perqSdk.perqApi.linkSuiWalletWithEthWallet(signedPayload);
20
+ }
21
+ async linkNearWalletWithEthWallet(nearWalletAddress) {
22
+ const payload = {
23
+ nearWalletAddr: nearWalletAddress,
24
+ };
25
+ const signedPayload = await this.perqSdk.signHandler.signPayload(payload);
26
+ return this.perqSdk.perqApi.linkNearWalletWithEthWallet(signedPayload);
27
+ }
28
+ async getLinkedPodWallets() {
29
+ if (!this.perqSdk.signer) {
30
+ throw new Error('No signer provided');
31
+ }
32
+ const walletAddr = await this.perqSdk.signer.getAddress();
33
+ return this.perqSdk.perqApi.getPodWallets(walletAddr);
34
+ }
35
+ }
36
+ exports.default = UserPackage;
@@ -0,0 +1,24 @@
1
+ import { UserVaultBalance, VaultData } from '../types';
2
+ import PerqSdk from '../PerqSdk';
3
+ export default class V2Package {
4
+ perqSdk: PerqSdk;
5
+ constructor(perqSdk: PerqSdk);
6
+ getPoolDetails(vaultAddress: string): Promise<VaultData>;
7
+ newDeposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
8
+ deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>;
9
+ private doDeposit;
10
+ getSwapAndDepositTokenAllowanceForCurrency(tokenAddress: string): Promise<string>;
11
+ getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number): Promise<string>;
12
+ getUserPoolBalance(vaultAddress: string): Promise<UserVaultBalance>;
13
+ fastWithdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
14
+ swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
15
+ newSwapAndDeposit(fromTokenAddress: string, toTokenAddress: string, fromTokenAmount: string, vaultAddress: string, ethAmount?: string): Promise<string>;
16
+ private doSwapAndDeposit;
17
+ withdraw(vaultAddress: string, amountToWithdraw?: string): Promise<string>;
18
+ claimWithdraws(vaultAddress: string): Promise<string>;
19
+ approveTokenForSwapAndDeposit(tokenAddress: string, amount: string): Promise<string>;
20
+ approveTokenForDeposit(tokenAddress: string, amount: string): Promise<string>;
21
+ private generateRedeemBagStruct;
22
+ private getTokenAllowanceForDeposit;
23
+ getTokenAllowanceForCurrency(tokenAddress: string): Promise<string>;
24
+ }
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ethers_1 = require("ethers");
7
+ const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
8
+ const ChainId_1 = require("../types/ChainId");
9
+ class V2Package {
10
+ perqSdk;
11
+ constructor(perqSdk) {
12
+ this.perqSdk = perqSdk;
13
+ }
14
+ async getPoolDetails(vaultAddress) {
15
+ return this.perqSdk.perqApi.fetchPoolV2Details(vaultAddress);
16
+ }
17
+ async newDeposit(tokenAddress, vaultAddress, amount) {
18
+ return this.doDeposit(tokenAddress, vaultAddress, amount, false);
19
+ }
20
+ async deposit(tokenAddress, vaultAddress, amount) {
21
+ return this.doDeposit(tokenAddress, vaultAddress, amount, true);
22
+ }
23
+ async doDeposit(tokenAddress, vaultAddress, amount, checkAllowance) {
24
+ if (!this.perqSdk.signer) {
25
+ throw Error('No signer provided');
26
+ }
27
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
28
+ const decimals = await tokenContract.getPrecission();
29
+ const amountWithDecimals = parseFloat(parseFloat(amount).toFixed(decimals));
30
+ if (checkAllowance) {
31
+ const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), this.perqSdk.perqConfig.smartVaultManagerContractAddress);
32
+ const currentTokenAllowance = parseFloat(ethers_1.ethers.utils.formatUnits(allowance, decimals));
33
+ if (amountWithDecimals > currentTokenAllowance) {
34
+ await this.approveTokenForDeposit(tokenAddress, amountWithDecimals.toString());
35
+ }
36
+ }
37
+ const amountToDeposit = ethers_1.ethers.utils.parseUnits(amountWithDecimals.toString(), decimals);
38
+ const signerAddress = await this.perqSdk.signer.getAddress();
39
+ if (!signerAddress) {
40
+ throw Error('Error fetching address');
41
+ }
42
+ const depositBagStruct = {
43
+ smartVault: vaultAddress.toLowerCase(),
44
+ assets: [amountToDeposit],
45
+ receiver: signerAddress,
46
+ referral: ethers_1.ethers.constants.AddressZero,
47
+ doFlush: false,
48
+ };
49
+ const depositTx = await this.perqSdk.spoolSdk.deposit(depositBagStruct);
50
+ const txReceipt = await depositTx.wait();
51
+ return txReceipt.transactionHash;
52
+ }
53
+ async getSwapAndDepositTokenAllowanceForCurrency(tokenAddress) {
54
+ if (!this.perqSdk.signer) {
55
+ throw Error('No signer provided');
56
+ }
57
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
58
+ const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), this.perqSdk.perqConfig.swapAndDepositContractAddress);
59
+ return allowance.toString();
60
+ }
61
+ async getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals) {
62
+ return this.perqSdk.perqApi.getExpectedSwapResult(fromTokenAddress, toTokenAddress, amount, decimals, ChainId_1.ETHEREUM_CHAIN_ID.toString());
63
+ }
64
+ async getUserPoolBalance(vaultAddress) {
65
+ if (!this.perqSdk.signer) {
66
+ throw Error('No signer provided');
67
+ }
68
+ const userAddress = await this.perqSdk.signer.getAddress();
69
+ return await this.perqSdk.perqApi.fetchV2PoolUserBalance(userAddress.toLowerCase(), vaultAddress.toLowerCase());
70
+ }
71
+ async fastWithdraw(vaultAddress, amountToWithdraw) {
72
+ if (!this.perqSdk.signer) {
73
+ throw Error('No signer provided');
74
+ }
75
+ const userAddress = await this.perqSdk.signer.getAddress();
76
+ const vault = await this.getPoolDetails(vaultAddress);
77
+ const redeemBagStruct = await this.generateRedeemBagStruct(vault, userAddress, amountToWithdraw);
78
+ const currentBlockNumber = await this.perqSdk.signer.provider?.getBlockNumber();
79
+ if (!currentBlockNumber) {
80
+ throw Error('Error fetching block number');
81
+ }
82
+ const redeemTx = await this.perqSdk.spoolSdk?.redeemFast(redeemBagStruct, userAddress, currentBlockNumber);
83
+ const txReceipt = await redeemTx.wait();
84
+ return txReceipt.transactionHash;
85
+ }
86
+ async swapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
87
+ return this.doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, true, ethAmount);
88
+ }
89
+ async newSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, ethAmount) {
90
+ return this.doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, false, ethAmount);
91
+ }
92
+ async doSwapAndDeposit(fromTokenAddress, toTokenAddress, fromTokenAmount, vaultAddress, checkAllowance, ethAmount) {
93
+ if (!this.perqSdk.signer) {
94
+ throw Error('No signer provided');
95
+ }
96
+ const userAddress = await this.perqSdk.signer.getAddress();
97
+ const tokenContract = new ERC20TokenContract_1.default(fromTokenAddress, this.perqSdk.signer);
98
+ const decimals = await tokenContract.getPrecission();
99
+ const amountWithDecimals = parseFloat(parseFloat(fromTokenAmount).toFixed(decimals));
100
+ if (amountWithDecimals > 0 && checkAllowance) {
101
+ const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), this.perqSdk.perqConfig.swapAndDepositContractAddress);
102
+ const currentTokenAllowance = parseFloat(ethers_1.ethers.utils.formatUnits(allowance, decimals));
103
+ if (amountWithDecimals > currentTokenAllowance) {
104
+ await this.approveTokenForSwapAndDeposit(fromTokenAddress, amountWithDecimals.toString());
105
+ }
106
+ }
107
+ const fromToken = ethers_1.ethers.utils.parseUnits(amountWithDecimals.toString(), decimals);
108
+ const swapInfo = await this.perqSdk.perqApi.getSwapInfo(fromTokenAddress, toTokenAddress, fromToken, this.perqSdk.perqConfig.ethereumSwapperAddress, ChainId_1.ETHEREUM_CHAIN_ID);
109
+ const swapDepositBagStruct = {
110
+ inTokens: [fromTokenAddress],
111
+ inAmounts: [fromToken],
112
+ smartVault: vaultAddress.toLowerCase(),
113
+ swapInfo,
114
+ receiver: userAddress,
115
+ referral: ethers_1.ethers.constants.AddressZero,
116
+ doFlush: false,
117
+ };
118
+ const swapAndDepositRequest = ethAmount
119
+ ? await this.perqSdk.spoolSdk.swapAndDeposit(swapDepositBagStruct, {
120
+ value: ethers_1.ethers.utils.parseEther(ethAmount),
121
+ })
122
+ : await this.perqSdk.spoolSdk.swapAndDeposit(swapDepositBagStruct);
123
+ const txReceipt = await swapAndDepositRequest.wait();
124
+ return txReceipt?.transactionHash;
125
+ }
126
+ async withdraw(vaultAddress, amountToWithdraw) {
127
+ if (!this.perqSdk.signer) {
128
+ throw Error('No signer provided');
129
+ }
130
+ const userAddress = await this.perqSdk.signer.getAddress();
131
+ const vault = await this.getPoolDetails(vaultAddress);
132
+ const redeemBagStruct = await this.generateRedeemBagStruct(vault, userAddress, amountToWithdraw);
133
+ const redeemTx = await this.perqSdk.spoolSdk.redeem(redeemBagStruct, userAddress, false);
134
+ const redeemTxReceipt = await redeemTx.wait();
135
+ return redeemTxReceipt.transactionHash;
136
+ }
137
+ async claimWithdraws(vaultAddress) {
138
+ if (!this.perqSdk.signer) {
139
+ throw Error('No signer provided');
140
+ }
141
+ const userAddress = await this.perqSdk.signer.getAddress();
142
+ const wnfts = await this.perqSdk.perqApi.fetchEnrichedUserWNFTForPool(vaultAddress, userAddress);
143
+ //! Shares come as Strings instead of BigNumber from our Backend
144
+ const nftIds = wnfts
145
+ .filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
146
+ .map((item) => item.nftId.toString());
147
+ const nftAmounts = wnfts
148
+ .filter((item) => !item.isBurned && ethers_1.BigNumber.from(item.shares).gt(ethers_1.BigNumber.from('0')) && item.isDHWFinished)
149
+ .map((item) => item.shares.toString());
150
+ const claimWithdrawTx = await this.perqSdk.spoolSdk.claimWithdrawal(vaultAddress.toLowerCase(), nftIds, nftAmounts, userAddress);
151
+ const txReceipt = await claimWithdrawTx.wait();
152
+ return txReceipt.transactionHash;
153
+ }
154
+ async approveTokenForSwapAndDeposit(tokenAddress, amount) {
155
+ if (!this.perqSdk.signer) {
156
+ throw Error('No signer provided');
157
+ }
158
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
159
+ const decimals = await tokenContract.getPrecission();
160
+ const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
161
+ return await tokenContract.approveToken(this.perqSdk.perqConfig.swapAndDepositContractAddress, parsedAmount);
162
+ }
163
+ async approveTokenForDeposit(tokenAddress, amount) {
164
+ if (!this.perqSdk.signer) {
165
+ throw Error('No signer provided');
166
+ }
167
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
168
+ const decimals = await tokenContract.getPrecission();
169
+ const parsedAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
170
+ return await tokenContract.approveToken(this.perqSdk.perqConfig.smartVaultManagerContractAddress, parsedAmount);
171
+ }
172
+ async generateRedeemBagStruct(vault, signerAddress, amountToWithdraw) {
173
+ if (!this.perqSdk.spoolSdk) {
174
+ throw Error('No spool sdk provided');
175
+ }
176
+ const isFullWithdraw = !amountToWithdraw;
177
+ if (isFullWithdraw) {
178
+ return this.perqSdk.spoolSdk.views.userInfo.getMaxRedeemBag({
179
+ userAddress: signerAddress.toLowerCase(),
180
+ vaultAddress: vault.vaultAddress.toLowerCase(),
181
+ });
182
+ }
183
+ else {
184
+ return this.perqSdk.spoolSdk.views.userInfo.getMinimumBurnRedeemBag({
185
+ userAddress: signerAddress.toLowerCase(),
186
+ vaultAddress: vault.vaultAddress.toLowerCase(),
187
+ assetsToWithdraw: [Number(amountToWithdraw)],
188
+ });
189
+ }
190
+ }
191
+ async getTokenAllowanceForDeposit(tokenAddress) {
192
+ if (!this.perqSdk.signer) {
193
+ throw Error('No signer provided');
194
+ }
195
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
196
+ const allowance = await tokenContract.getAllowance(await this.perqSdk.signer.getAddress(), this.perqSdk.perqConfig.smartVaultManagerContractAddress);
197
+ return allowance;
198
+ }
199
+ async getTokenAllowanceForCurrency(tokenAddress) {
200
+ if (!this.perqSdk.signer) {
201
+ throw Error('No signer provided');
202
+ }
203
+ const currentTokenAllowance = await this.getTokenAllowanceForDeposit(tokenAddress);
204
+ return currentTokenAllowance.toString();
205
+ }
206
+ }
207
+ exports.default = V2Package;
@@ -0,0 +1,14 @@
1
+ import { VestingInfo } from '../types';
2
+ import PerqSdk from '../PerqSdk';
3
+ export default class VestingPackage {
4
+ perqSdk: PerqSdk;
5
+ constructor(perqSdk: PerqSdk);
6
+ getVestingStart(): Promise<string>;
7
+ getVestingEnd(): Promise<string>;
8
+ getVestedAmount(beneficiary: string): Promise<string>;
9
+ getReleasableAmount(beneficiary: string): Promise<string>;
10
+ getReleasableTotalAmount(beneficiary: string): Promise<string>;
11
+ claimVestedPerq(amount: string): Promise<string>;
12
+ burnVestedPerq(amount: string, price: string, deadline: string, signature: string): Promise<string>;
13
+ getAllVestingInfo(beneficiaryAddress: string): Promise<VestingInfo>;
14
+ }
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("ethers/lib/utils");
4
+ class VestingPackage {
5
+ perqSdk;
6
+ constructor(perqSdk) {
7
+ this.perqSdk = perqSdk;
8
+ }
9
+ async getVestingStart() {
10
+ try {
11
+ const startBigNumber = await this.perqSdk.perqVestingContract.start();
12
+ return startBigNumber.toString();
13
+ }
14
+ catch (error) {
15
+ if (error instanceof Error) {
16
+ throw new Error(`Failed to get vesting start time: ${error.message}`);
17
+ }
18
+ throw new Error('Failed to get vesting start time: Unknown error');
19
+ }
20
+ }
21
+ async getVestingEnd() {
22
+ try {
23
+ const endBigNumber = await this.perqSdk.perqVestingContract.end();
24
+ return endBigNumber.toString();
25
+ }
26
+ catch (error) {
27
+ if (error instanceof Error) {
28
+ throw new Error(`Failed to get vesting end time: ${error.message}`);
29
+ }
30
+ throw new Error('Failed to get vesting end time: Unknown error');
31
+ }
32
+ }
33
+ async getVestedAmount(beneficiary) {
34
+ try {
35
+ const vestedAmount = await this.perqSdk.perqVestingContract.vested(beneficiary);
36
+ return (0, utils_1.formatUnits)(vestedAmount, 18);
37
+ }
38
+ catch (error) {
39
+ if (error instanceof Error) {
40
+ throw new Error(`Failed to get vested amount: ${error.message}`);
41
+ }
42
+ throw new Error('Failed to get vested amount: Unknown error');
43
+ }
44
+ }
45
+ async getReleasableAmount(beneficiary) {
46
+ try {
47
+ const releasableAmount = await this.perqSdk.perqVestingContract.releasable(beneficiary);
48
+ return (0, utils_1.formatUnits)(releasableAmount, 18);
49
+ }
50
+ catch (error) {
51
+ if (error instanceof Error) {
52
+ throw new Error(`Failed to get releasable amount: ${error.message}`);
53
+ }
54
+ throw new Error('Failed to get releasable amount: Unknown error');
55
+ }
56
+ }
57
+ async getReleasableTotalAmount(beneficiary) {
58
+ try {
59
+ const releasableTotalAmount = await this.perqSdk.perqVestingContract.releasableTotal(beneficiary);
60
+ return (0, utils_1.formatUnits)(releasableTotalAmount, 18);
61
+ }
62
+ catch (error) {
63
+ if (error instanceof Error) {
64
+ throw new Error(`Failed to get total releasable amount: ${error.message}`);
65
+ }
66
+ throw new Error('Failed to get total releasable amount: Unknown error');
67
+ }
68
+ }
69
+ async claimVestedPerq(amount) {
70
+ try {
71
+ const claimTx = await this.perqSdk.perqVestingContract.claim(amount);
72
+ const txReceipt = await claimTx.wait();
73
+ return txReceipt.transactionHash;
74
+ }
75
+ catch (error) {
76
+ if (error instanceof Error) {
77
+ throw new Error(`Failed to get total releasable amount: ${error.message}`);
78
+ }
79
+ throw new Error('Failed to get total releasable amount: Unknown error');
80
+ }
81
+ }
82
+ async burnVestedPerq(amount, price, deadline, signature) {
83
+ try {
84
+ const burnTx = await this.perqSdk.perqVestingContract.burn(amount, price, deadline, signature);
85
+ const txReceipt = await burnTx.wait();
86
+ return txReceipt.transactionHash;
87
+ }
88
+ catch (error) {
89
+ if (error instanceof Error) {
90
+ throw new Error(`Failed to get total releasable amount: ${error.message}`);
91
+ }
92
+ throw new Error('Failed to get total releasable amount: Unknown error');
93
+ }
94
+ }
95
+ async getAllVestingInfo(beneficiaryAddress) {
96
+ const [startTimestamp, endTimestamp, vested, releasable, releasableTotal] = await Promise.all([
97
+ this.getVestingStart(),
98
+ this.getVestingEnd(),
99
+ this.getVestedAmount(beneficiaryAddress),
100
+ this.getReleasableAmount(beneficiaryAddress),
101
+ this.getReleasableTotalAmount(beneficiaryAddress),
102
+ ]);
103
+ return {
104
+ startTimestamp,
105
+ endTimestamp,
106
+ vested,
107
+ releasable,
108
+ releasableTotal,
109
+ };
110
+ }
111
+ }
112
+ exports.default = VestingPackage;
@@ -0,0 +1,5 @@
1
+ export declare const BASE_CHAIN_ID = 8453;
2
+ export declare const ETHEREUM_CHAIN_ID = 1;
3
+ export declare const ETHEREUM_SEPOLIA_CHAIN_ID = 11155111;
4
+ export declare const ARBITRUM_CHAIN_ID = 42161;
5
+ export type ChainId = typeof BASE_CHAIN_ID | typeof ETHEREUM_CHAIN_ID | typeof ETHEREUM_SEPOLIA_CHAIN_ID | typeof ARBITRUM_CHAIN_ID;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ARBITRUM_CHAIN_ID = exports.ETHEREUM_SEPOLIA_CHAIN_ID = exports.ETHEREUM_CHAIN_ID = exports.BASE_CHAIN_ID = void 0;
4
+ exports.BASE_CHAIN_ID = 8453;
5
+ exports.ETHEREUM_CHAIN_ID = 1;
6
+ exports.ETHEREUM_SEPOLIA_CHAIN_ID = 11155111;
7
+ exports.ARBITRUM_CHAIN_ID = 42161;
@@ -39,6 +39,9 @@ type DeployedProject = {
39
39
  bannerImage?: string;
40
40
  rewardImage?: string;
41
41
  rewardTooltipName?: string;
42
+ liveUntil: string;
43
+ liveFrom: string;
44
+ distributionType: string;
42
45
  };
43
46
  export default DeployedProject;
44
47
  export type ProjectBacker = {