@dripfi/drip-sdk 1.4.28-slot-machine-4 → 1.4.29

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 (48) hide show
  1. package/README.md +88 -10
  2. package/dist/PerqSdk.d.ts +5 -1
  3. package/dist/PerqSdk.js +8 -1
  4. package/dist/abi/index.js +6 -6
  5. package/dist/constants.js +2 -2
  6. package/dist/contracts/{BasePerqContract.d.ts → BaseContract.d.ts} +1 -1
  7. package/dist/contracts/{BasePerqContract.js → BaseContract.js} +2 -2
  8. package/dist/contracts/BridgeMainnetPerqToSonicContract.d.ts +2 -2
  9. package/dist/contracts/BridgeMainnetPerqToSonicContract.js +3 -3
  10. package/dist/contracts/BridgeSonicPerqToMainnetContract.d.ts +2 -2
  11. package/dist/contracts/BridgeSonicPerqToMainnetContract.js +3 -3
  12. package/dist/contracts/SlotBurnTokenContract.d.ts +2 -2
  13. package/dist/contracts/SlotBurnTokenContract.js +2 -2
  14. package/dist/contracts/index.d.ts +6 -6
  15. package/dist/contracts/index.js +9 -9
  16. package/dist/contracts/{PerqSwapAndRecyclerContract.d.ts → perq/PerqSwapAndRecyclerContract.d.ts} +3 -3
  17. package/dist/contracts/{PerqSwapAndRecyclerContract.js → perq/PerqSwapAndRecyclerContract.js} +3 -3
  18. package/dist/contracts/{PerqTokenContract.d.ts → perq/PerqTokenContract.d.ts} +2 -2
  19. package/dist/contracts/{PerqTokenContract.js → perq/PerqTokenContract.js} +3 -3
  20. package/dist/contracts/{PerqTokenRecyclerContract.d.ts → perq/PerqTokenRecyclerContract.d.ts} +3 -3
  21. package/dist/contracts/{PerqTokenRecyclerContract.js → perq/PerqTokenRecyclerContract.js} +3 -3
  22. package/dist/contracts/{PerqVestingContract.d.ts → perq/PerqVestingContract.d.ts} +3 -3
  23. package/dist/contracts/{PerqVestingContract.js → perq/PerqVestingContract.js} +3 -3
  24. package/dist/subpackages/LoyaltyCardsPackage.js +4 -2
  25. package/dist/subpackages/SiloPackage.d.ts +18 -0
  26. package/dist/subpackages/SiloPackage.js +112 -0
  27. package/dist/subpackages/SiloVaultOperations.d.ts +31 -0
  28. package/dist/subpackages/SiloVaultOperations.js +138 -0
  29. package/dist/subpackages/TokenUtilsPackage.d.ts +14 -0
  30. package/dist/subpackages/TokenUtilsPackage.js +31 -4
  31. package/dist/subpackages/VaultHandlerPackage.d.ts +54 -0
  32. package/dist/subpackages/VaultHandlerPackage.js +107 -0
  33. package/dist/subpackages/YelayVaultOperations.d.ts +13 -0
  34. package/dist/subpackages/YelayVaultOperations.js +164 -0
  35. package/dist/types/DeployedProject.d.ts +1 -0
  36. package/dist/types/SdkType.d.ts +2 -0
  37. package/dist/types/SdkType.js +2 -0
  38. package/dist/types/VaultData.d.ts +2 -0
  39. package/dist/types/VaultOperationParams.d.ts +12 -0
  40. package/dist/types/VaultOperationParams.js +2 -0
  41. package/dist/types/index.d.ts +2 -1
  42. package/package.json +2 -1
  43. /package/dist/abi/{BridgeMainnetPerqToSonicAbi.json → perq/BridgeMainnetPerqToSonicAbi.json} +0 -0
  44. /package/dist/abi/{BridgeSonicPerqToMainnetAbi.json → perq/BridgeSonicPerqToMainnetAbi.json} +0 -0
  45. /package/dist/abi/{PerqSwapAndRecyclerAbi.json → perq/PerqSwapAndRecyclerAbi.json} +0 -0
  46. /package/dist/abi/{PerqTokenAbi.json → perq/PerqTokenAbi.json} +0 -0
  47. /package/dist/abi/{PerqVestingAbi.json → perq/PerqVestingAbi.json} +0 -0
  48. /package/dist/abi/{TokenRecyclerAbi.json → perq/TokenRecyclerAbi.json} +0 -0
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const silo_sdk_1 = require("@dripfi/silo-sdk");
4
+ class SiloPackage {
5
+ siloSdk;
6
+ constructor(signer) {
7
+ this.siloSdk = new silo_sdk_1.SiloSdk(signer);
8
+ }
9
+ async deposit(assetAmount, vaultAddress) {
10
+ try {
11
+ const tx = await this.siloSdk.contracts.deposit(assetAmount, vaultAddress);
12
+ return tx;
13
+ }
14
+ catch (error) {
15
+ console.error('Error depositing:', error);
16
+ throw error;
17
+ }
18
+ }
19
+ async withdraw(assetAmount, vaultAddress) {
20
+ try {
21
+ const tx = await this.siloSdk.contracts.withdraw(assetAmount, vaultAddress);
22
+ return tx;
23
+ }
24
+ catch (error) {
25
+ console.error('Error depositing:', error);
26
+ throw error;
27
+ }
28
+ }
29
+ async redeem(sharesAmount, vaultAddress) {
30
+ try {
31
+ const tx = await this.siloSdk.contracts.redeem(sharesAmount, vaultAddress);
32
+ return tx;
33
+ }
34
+ catch (error) {
35
+ console.error('Error depositing:', error);
36
+ throw error;
37
+ }
38
+ }
39
+ async getHistoricalTvl() {
40
+ console.log('getHistoricalTvl to be implemented');
41
+ return await this.siloSdk.getHistoricalTvl();
42
+ }
43
+ async getApy() {
44
+ console.log('getApy to be implemented');
45
+ return await this.siloSdk.getApy();
46
+ }
47
+ async getEarnedRewards() {
48
+ console.log('getEarnedRewards to be implemented');
49
+ return await this.siloSdk.getEarnedRewards();
50
+ }
51
+ async getBalanceInShares(vaultAddress) {
52
+ try {
53
+ const balance = await this.siloSdk.contracts.getBalance(vaultAddress);
54
+ return balance;
55
+ }
56
+ catch (error) {
57
+ console.error('Error getting balance:', error);
58
+ throw error;
59
+ }
60
+ }
61
+ async getBalanceInAssets(vaultAddress) {
62
+ try {
63
+ const balance = await this.siloSdk.contracts.getBalanceInAssets(vaultAddress);
64
+ return balance;
65
+ }
66
+ catch (error) {
67
+ console.error('Error getting balance:', error);
68
+ throw error;
69
+ }
70
+ }
71
+ async getTotalSupply(vaultAddress) {
72
+ try {
73
+ const totalSupply = await this.siloSdk.contracts.getTotalSupply(vaultAddress);
74
+ return totalSupply;
75
+ }
76
+ catch (error) {
77
+ console.error('Error getting totalSupply:', error);
78
+ throw error;
79
+ }
80
+ }
81
+ async getTotalAssets(vaultAddress) {
82
+ try {
83
+ const totalAssets = await this.siloSdk.contracts.getTotalAssets(vaultAddress);
84
+ return totalAssets;
85
+ }
86
+ catch (error) {
87
+ console.error('Error getting totalAssets:', error);
88
+ throw error;
89
+ }
90
+ }
91
+ async convertToShares(assetsAmount, vaultAddress) {
92
+ try {
93
+ const shares = await this.siloSdk.contracts.convertToShares(assetsAmount, vaultAddress);
94
+ return shares;
95
+ }
96
+ catch (error) {
97
+ console.error('Error converting to shares:', error);
98
+ throw error;
99
+ }
100
+ }
101
+ async convertToAssets(sharesAmount, vaultAddress) {
102
+ try {
103
+ const assets = await this.siloSdk.contracts.convertToAssets(sharesAmount, vaultAddress);
104
+ return assets;
105
+ }
106
+ catch (error) {
107
+ console.error('Error converting to assets:', error);
108
+ throw error;
109
+ }
110
+ }
111
+ }
112
+ exports.default = SiloPackage;
@@ -0,0 +1,31 @@
1
+ import PerqSdk from '../PerqSdk';
2
+ import { VaultOperationParams } from '../types/VaultOperationParams';
3
+ import { VaultOperations, WithdrawParams } from './VaultHandlerPackage';
4
+ /**
5
+ * Silo SDK vault operations implementation
6
+ */
7
+ export declare class SiloVaultOperations implements VaultOperations {
8
+ private perqSdk;
9
+ constructor(perqSdk: PerqSdk);
10
+ getAllowance(params: VaultOperationParams): Promise<boolean>;
11
+ approveAllowance(params: VaultOperationParams): Promise<string>;
12
+ deposit(params: VaultOperationParams): Promise<string>;
13
+ withdraw(params: WithdrawParams): Promise<string>;
14
+ getBalance(vaultAddress: string, tokenAddress: string): Promise<string>;
15
+ /**
16
+ * Handles Silo withdraw with automatic full/partial withdraw detection
17
+ */
18
+ private handleSiloWithdraw;
19
+ /**
20
+ * Handles a full withdraw from a Silo vault
21
+ */
22
+ private handleSiloFullWithdraw;
23
+ /**
24
+ * Handles a partial withdraw from a Silo vault
25
+ */
26
+ private handleSiloPartialWithdraw;
27
+ /**
28
+ * Extracts transaction hash from various transaction response formats
29
+ */
30
+ private extractTransactionHash;
31
+ }
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SiloVaultOperations = void 0;
4
+ const ethers_1 = require("ethers");
5
+ /**
6
+ * Silo SDK vault operations implementation
7
+ */
8
+ class SiloVaultOperations {
9
+ perqSdk;
10
+ constructor(perqSdk) {
11
+ this.perqSdk = perqSdk;
12
+ }
13
+ async getAllowance(params) {
14
+ const { sourceTokenAddress, vaultAddress, amount } = params;
15
+ console.log(`🚀 ~ silo getAllowance called with these params:`, { sourceTokenAddress, vaultAddress, amount });
16
+ if (!this.perqSdk.siloPackage) {
17
+ throw new Error('Silo package not initialized. Please provide a signer.');
18
+ }
19
+ try {
20
+ // For Silo, we use the standard ERC20 allowance
21
+ const allowance = await this.perqSdk.tokenUtils.getERC20TokenAllowance(vaultAddress, sourceTokenAddress);
22
+ console.log('🚀 ~ allowance:', allowance);
23
+ // Get required amount with correct decimals
24
+ const requiredAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
25
+ console.log('🚀 ~ requiredAmount:', requiredAmount.toString());
26
+ return allowance.gte(requiredAmount);
27
+ }
28
+ catch (error) {
29
+ console.error('Error checking allowance:', error);
30
+ return false;
31
+ }
32
+ }
33
+ async approveAllowance(params) {
34
+ const { sourceTokenAddress, vaultAddress, amount } = params;
35
+ console.log(`🚀 ~ silo approveAllowance called with these params:`, { sourceTokenAddress, vaultAddress, amount });
36
+ if (!this.perqSdk.siloPackage) {
37
+ throw new Error('Silo package not initialized. Please provide a signer.');
38
+ }
39
+ // For Silo, we use the standard ERC20 approval
40
+ return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, amount, vaultAddress);
41
+ }
42
+ async deposit(params) {
43
+ const { amount, vaultAddress, sourceTokenAddress } = params;
44
+ console.log(`🚀 ~ silo deposit called with these params:`, { amount, vaultAddress });
45
+ if (!this.perqSdk.siloPackage) {
46
+ throw new Error('Silo package not initialized. Please provide a signer.');
47
+ }
48
+ const parsedAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
49
+ console.log('🚀 ~ parsedAmount:', parsedAmount.toString());
50
+ const tx = await this.perqSdk.siloPackage.deposit(parsedAmount.toString(), vaultAddress);
51
+ return this.extractTransactionHash(tx);
52
+ }
53
+ async withdraw(params) {
54
+ const { amount, vaultAddress, tokenAddress } = params;
55
+ console.log(`🚀 ~ silo withdraw called with these params:`, { amount, vaultAddress, tokenAddress });
56
+ if (!this.perqSdk.siloPackage) {
57
+ throw new Error('Silo package not initialized. Please provide a signer.');
58
+ }
59
+ const parsedAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, tokenAddress);
60
+ console.log('🚀 ~ parsedAmount:', parsedAmount.toString());
61
+ return await this.handleSiloWithdraw(tokenAddress, vaultAddress, parsedAmount.toString());
62
+ }
63
+ async getBalance(vaultAddress, tokenAddress) {
64
+ if (!this.perqSdk.signer) {
65
+ throw new Error('Signer not initialized');
66
+ }
67
+ const balance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
68
+ console.log('🚀 ~ balance:', balance);
69
+ const formattedBalance = await this.perqSdk.tokenUtils.formatAmountWithDecimals(balance, tokenAddress);
70
+ console.log('🚀 ~ formattedBalance:', formattedBalance);
71
+ return formattedBalance;
72
+ }
73
+ /**
74
+ * Handles Silo withdraw with automatic full/partial withdraw detection
75
+ */
76
+ async handleSiloWithdraw(tokenAddress, vaultAddress, amount) {
77
+ console.log(`🚀 ~ silo handleSiloWithdraw called with these params:`, { tokenAddress, vaultAddress, amount });
78
+ let userBalance = ethers_1.BigNumber.from(0);
79
+ try {
80
+ userBalance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
81
+ console.log('🚀 ~ userBalance:', userBalance.toString());
82
+ }
83
+ catch (error) {
84
+ console.error('Error getting user balance for silo withdraw: ', error);
85
+ }
86
+ const withdrawAmount = ethers_1.BigNumber.from(amount);
87
+ try {
88
+ if (withdrawAmount.gte(userBalance)) {
89
+ return await this.handleSiloFullWithdraw(vaultAddress);
90
+ }
91
+ else {
92
+ return await this.handleSiloPartialWithdraw(vaultAddress, withdrawAmount);
93
+ }
94
+ }
95
+ catch (error) {
96
+ console.error('Error handling silo withdraw: ', error);
97
+ throw error;
98
+ }
99
+ }
100
+ /**
101
+ * Handles a full withdraw from a Silo vault
102
+ */
103
+ async handleSiloFullWithdraw(vaultAddress) {
104
+ const balanceInShares = await this.perqSdk.siloPackage.getBalanceInShares(vaultAddress);
105
+ console.log('🚀 ~ balanceInShares:', balanceInShares);
106
+ console.log('🚀 ~ perqSdk.siloPackage!.redeem:', { balanceInShares: balanceInShares.toString(), vaultAddress });
107
+ const tx = await this.perqSdk.siloPackage.redeem(balanceInShares.toString(), vaultAddress);
108
+ return this.extractTransactionHash(tx);
109
+ }
110
+ /**
111
+ * Handles a partial withdraw from a Silo vault
112
+ */
113
+ async handleSiloPartialWithdraw(vaultAddress, parsedWithdrawAmount) {
114
+ console.log('🚀 ~ perqSdk.siloPackage!.withdraw:', {
115
+ parsedWithdrawAmount: parsedWithdrawAmount.toString(),
116
+ vaultAddress,
117
+ });
118
+ const tx = await this.perqSdk.siloPackage.withdraw(parsedWithdrawAmount.toString(), vaultAddress);
119
+ return this.extractTransactionHash(tx);
120
+ }
121
+ /**
122
+ * Extracts transaction hash from various transaction response formats
123
+ */
124
+ extractTransactionHash(tx) {
125
+ console.log('🚀 ~ extractTransactionHash called with tx:', tx);
126
+ if (typeof tx === 'string') {
127
+ return tx;
128
+ }
129
+ if (tx?.hash) {
130
+ return tx.hash;
131
+ }
132
+ if (tx?.transactionHash) {
133
+ return tx.transactionHash;
134
+ }
135
+ throw new Error('Unable to extract transaction hash from response');
136
+ }
137
+ }
138
+ exports.SiloVaultOperations = SiloVaultOperations;
@@ -3,6 +3,20 @@ import PerqSdk from '../PerqSdk';
3
3
  export default class TokenUtilsPackage {
4
4
  private perqSdk;
5
5
  constructor(perqSdk: PerqSdk);
6
+ /**
7
+ * Helper method to parse amount with correct token decimals
8
+ * @param amount - The amount as a string
9
+ * @param tokenAddress - The token contract address
10
+ * @returns Promise<BigNumber> - The parsed amount with correct decimals
11
+ */
12
+ parseAmountWithDecimals(amount: string, tokenAddress: string): Promise<BigNumber>;
13
+ /**
14
+ * Helper method to format amount from token decimals to human-readable string
15
+ * @param amount - The amount as BigNumber with token decimals
16
+ * @param tokenAddress - The token contract address
17
+ * @returns Promise<string> - The formatted amount as human-readable string
18
+ */
19
+ formatAmountWithDecimals(amount: BigNumber, tokenAddress: string): Promise<string>;
6
20
  getTokenPrice(tokenName: string): Promise<number>;
7
21
  getAllowance(tokenAddress: string, spender: string): Promise<string>;
8
22
  approveAllowance(tokenAddress: string, amount: string, spenderAddress: string): Promise<string>;
@@ -11,6 +11,34 @@ class TokenUtilsPackage {
11
11
  constructor(perqSdk) {
12
12
  this.perqSdk = perqSdk;
13
13
  }
14
+ /**
15
+ * Helper method to parse amount with correct token decimals
16
+ * @param amount - The amount as a string
17
+ * @param tokenAddress - The token contract address
18
+ * @returns Promise<BigNumber> - The parsed amount with correct decimals
19
+ */
20
+ async parseAmountWithDecimals(amount, tokenAddress) {
21
+ if (!this.perqSdk.signer) {
22
+ throw new Error('No signer provided');
23
+ }
24
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
25
+ const decimals = await tokenContract.getPrecission();
26
+ return ethers_1.ethers.utils.parseUnits(amount, decimals);
27
+ }
28
+ /**
29
+ * Helper method to format amount from token decimals to human-readable string
30
+ * @param amount - The amount as BigNumber with token decimals
31
+ * @param tokenAddress - The token contract address
32
+ * @returns Promise<string> - The formatted amount as human-readable string
33
+ */
34
+ async formatAmountWithDecimals(amount, tokenAddress) {
35
+ if (!this.perqSdk.signer) {
36
+ throw new Error('No signer provided');
37
+ }
38
+ const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
39
+ const decimals = await tokenContract.getPrecission();
40
+ return ethers_1.ethers.utils.formatUnits(amount, decimals);
41
+ }
14
42
  async getTokenPrice(tokenName) {
15
43
  return this.perqSdk.perqApi.fetchTokenPrice(tokenName);
16
44
  }
@@ -27,8 +55,7 @@ class TokenUtilsPackage {
27
55
  throw Error('No signer provided');
28
56
  }
29
57
  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);
58
+ const parsedAmount = await this.parseAmountWithDecimals(amount, tokenAddress);
32
59
  return await tokenContract.approveToken(spenderAddress, parsedAmount.toString());
33
60
  }
34
61
  async transferErc20Token(tokenAddress, amount, receiver) {
@@ -36,8 +63,8 @@ class TokenUtilsPackage {
36
63
  throw Error('No signer provided');
37
64
  }
38
65
  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());
66
+ const parsedAmount = await this.parseAmountWithDecimals(amount, tokenAddress);
67
+ const txHash = await tokenContract.transfer(receiver, parsedAmount.toString());
41
68
  return txHash;
42
69
  }
43
70
  async wrapEther(amount, tokenAddress) {
@@ -0,0 +1,54 @@
1
+ import PerqSdk from '../PerqSdk';
2
+ import SdkType from '../types/SdkType';
3
+ import { VaultOperationParams } from '../types/VaultOperationParams';
4
+ export interface WithdrawParams {
5
+ amount: string;
6
+ sdkType: SdkType;
7
+ tokenAddress: string;
8
+ vaultAddress: string;
9
+ onChainProjectId?: number;
10
+ }
11
+ export interface GetBalanceParams {
12
+ sdkType: SdkType;
13
+ tokenAddress: string;
14
+ vaultAddress: string;
15
+ onChainProjectId?: number;
16
+ }
17
+ export interface VaultOperations {
18
+ getAllowance(params: VaultOperationParams): Promise<boolean>;
19
+ approveAllowance(params: VaultOperationParams): Promise<string>;
20
+ deposit(params: VaultOperationParams): Promise<string>;
21
+ withdraw(params: WithdrawParams): Promise<string>;
22
+ getBalance(vaultAddress: string, tokenAddress?: string, onChainProjectId?: number): Promise<string>;
23
+ }
24
+ export default class VaultHandler {
25
+ private perqSdk;
26
+ constructor(perqSdk: PerqSdk);
27
+ /**
28
+ * Get allowance for vault operations
29
+ * Returns true if the user has approved sufficient allowance for the specified amount
30
+ */
31
+ getAllowance(params: VaultOperationParams): Promise<boolean>;
32
+ /**
33
+ * Approve allowance for vault operations
34
+ * Automatically determines the correct approval method based on deposit type
35
+ */
36
+ approveAllowance(params: VaultOperationParams): Promise<string>;
37
+ /**
38
+ * Deposit to vault
39
+ * Automatically determines the correct deposit method based on deposit type
40
+ */
41
+ deposit(params: VaultOperationParams): Promise<string>;
42
+ /**
43
+ * Withdraw from vault
44
+ */
45
+ withdraw(params: WithdrawParams): Promise<string>;
46
+ /**
47
+ * Get the balance of the vault
48
+ */
49
+ getBalance(params: GetBalanceParams): Promise<string>;
50
+ /**
51
+ * Get the appropriate SDK handler based on SDK type
52
+ */
53
+ private getSdkHandler;
54
+ }
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const YelayVaultOperations_1 = require("./YelayVaultOperations");
4
+ const SiloVaultOperations_1 = require("./SiloVaultOperations");
5
+ class VaultHandler {
6
+ perqSdk;
7
+ constructor(perqSdk) {
8
+ this.perqSdk = perqSdk;
9
+ }
10
+ /**
11
+ * Get allowance for vault operations
12
+ * Returns true if the user has approved sufficient allowance for the specified amount
13
+ */
14
+ async getAllowance(params) {
15
+ if (!this.perqSdk.signer) {
16
+ throw Error('No signer provided');
17
+ }
18
+ try {
19
+ const sdkHandler = this.getSdkHandler(params.sdkType);
20
+ return await sdkHandler.getAllowance(params);
21
+ }
22
+ catch (error) {
23
+ console.error('Error getting allowance:', error);
24
+ throw error;
25
+ }
26
+ }
27
+ /**
28
+ * Approve allowance for vault operations
29
+ * Automatically determines the correct approval method based on deposit type
30
+ */
31
+ async approveAllowance(params) {
32
+ if (!this.perqSdk.signer) {
33
+ throw Error('No signer provided');
34
+ }
35
+ try {
36
+ const sdkHandler = this.getSdkHandler(params.sdkType);
37
+ return await sdkHandler.approveAllowance(params);
38
+ }
39
+ catch (error) {
40
+ console.error('Error approving allowance:', error);
41
+ throw error;
42
+ }
43
+ }
44
+ /**
45
+ * Deposit to vault
46
+ * Automatically determines the correct deposit method based on deposit type
47
+ */
48
+ async deposit(params) {
49
+ if (!this.perqSdk.signer) {
50
+ throw Error('No signer provided');
51
+ }
52
+ try {
53
+ const sdkHandler = this.getSdkHandler(params.sdkType);
54
+ return await sdkHandler.deposit(params);
55
+ }
56
+ catch (error) {
57
+ console.error('Error depositing to vault:', error);
58
+ throw error;
59
+ }
60
+ }
61
+ /**
62
+ * Withdraw from vault
63
+ */
64
+ async withdraw(params) {
65
+ if (!this.perqSdk.signer) {
66
+ throw Error('No signer provided');
67
+ }
68
+ try {
69
+ const sdkHandler = this.getSdkHandler(params.sdkType);
70
+ return await sdkHandler.withdraw(params);
71
+ }
72
+ catch (error) {
73
+ console.error('Error withdrawing from vault:', error);
74
+ throw error;
75
+ }
76
+ }
77
+ /**
78
+ * Get the balance of the vault
79
+ */
80
+ async getBalance(params) {
81
+ if (!this.perqSdk.signer) {
82
+ throw Error('No signer provided');
83
+ }
84
+ try {
85
+ const sdkHandler = this.getSdkHandler(params.sdkType);
86
+ return await sdkHandler.getBalance(params.vaultAddress, params.tokenAddress, params.onChainProjectId);
87
+ }
88
+ catch (error) {
89
+ console.error('Error withdrawing from vault:', error);
90
+ throw error;
91
+ }
92
+ }
93
+ /**
94
+ * Get the appropriate SDK handler based on SDK type
95
+ */
96
+ getSdkHandler(sdkType) {
97
+ switch (sdkType) {
98
+ case 'yelay':
99
+ return new YelayVaultOperations_1.YelayVaultOperations(this.perqSdk);
100
+ case 'silo':
101
+ return new SiloVaultOperations_1.SiloVaultOperations(this.perqSdk);
102
+ default:
103
+ throw new Error(`Unsupported SDK type: ${sdkType}`);
104
+ }
105
+ }
106
+ }
107
+ exports.default = VaultHandler;
@@ -0,0 +1,13 @@
1
+ import PerqSdk from '../PerqSdk';
2
+ import { VaultOperationParams } from '../types/VaultOperationParams';
3
+ import { VaultOperations, WithdrawParams } from './VaultHandlerPackage';
4
+ export declare class YelayVaultOperations implements VaultOperations {
5
+ private perqSdk;
6
+ constructor(perqSdk: PerqSdk);
7
+ getAllowance(params: VaultOperationParams): Promise<boolean>;
8
+ approveAllowance(params: VaultOperationParams): Promise<string>;
9
+ deposit(params: VaultOperationParams): Promise<string>;
10
+ withdraw(params: WithdrawParams): Promise<string>;
11
+ getBalance(vaultAddress: string, _: string, onChainProjectId: number): Promise<string>;
12
+ private determineDepositType;
13
+ }