@dripfi/drip-sdk 1.4.28-silo-sdk-4 → 1.4.28-silo-sdk-6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/subpackages/SiloVaultOperations.js +8 -11
- package/dist/subpackages/TokenUtilsPackage.d.ts +7 -0
- package/dist/subpackages/TokenUtilsPackage.js +14 -0
- package/dist/subpackages/VaultHandlerPackage.d.ts +7 -1
- package/dist/subpackages/VaultHandlerPackage.js +1 -1
- package/dist/subpackages/YelayVaultOperations.js +2 -4
- package/package.json +1 -1
|
@@ -36,10 +36,8 @@ class SiloVaultOperations {
|
|
|
36
36
|
if (!this.perqSdk.siloPackage) {
|
|
37
37
|
throw new Error('Silo package not initialized. Please provide a signer.');
|
|
38
38
|
}
|
|
39
|
-
const amountToApprove = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
|
|
40
|
-
console.log('🚀 ~ amountToApprove:', amountToApprove.toString());
|
|
41
39
|
// For Silo, we use the standard ERC20 approval
|
|
42
|
-
return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress,
|
|
40
|
+
return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, amount, vaultAddress);
|
|
43
41
|
}
|
|
44
42
|
async deposit(params) {
|
|
45
43
|
const { amount, vaultAddress, sourceTokenAddress } = params;
|
|
@@ -67,9 +65,10 @@ class SiloVaultOperations {
|
|
|
67
65
|
throw new Error('Signer not initialized');
|
|
68
66
|
}
|
|
69
67
|
const balance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
console.log('🚀 ~ balance:', balance);
|
|
69
|
+
const formattedBalance = await this.perqSdk.tokenUtils.formatAmountWithDecimals(balance, tokenAddress);
|
|
70
|
+
console.log('🚀 ~ formattedBalance:', formattedBalance);
|
|
71
|
+
return formattedBalance;
|
|
73
72
|
}
|
|
74
73
|
/**
|
|
75
74
|
* Handles Silo withdraw with automatic full/partial withdraw detection
|
|
@@ -84,15 +83,13 @@ class SiloVaultOperations {
|
|
|
84
83
|
catch (error) {
|
|
85
84
|
console.error('Error getting user balance for silo withdraw: ', error);
|
|
86
85
|
}
|
|
87
|
-
|
|
88
|
-
const parsedWithdrawAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, tokenAddress);
|
|
89
|
-
console.log('🚀 ~ parsedWithdrawAmount:', parsedWithdrawAmount.toString());
|
|
86
|
+
const withdrawAmount = ethers_1.BigNumber.from(amount);
|
|
90
87
|
try {
|
|
91
|
-
if (
|
|
88
|
+
if (withdrawAmount.gte(userBalance)) {
|
|
92
89
|
return await this.handleSiloFullWithdraw(vaultAddress);
|
|
93
90
|
}
|
|
94
91
|
else {
|
|
95
|
-
return await this.handleSiloPartialWithdraw(vaultAddress,
|
|
92
|
+
return await this.handleSiloPartialWithdraw(vaultAddress, withdrawAmount);
|
|
96
93
|
}
|
|
97
94
|
}
|
|
98
95
|
catch (error) {
|
|
@@ -10,6 +10,13 @@ export default class TokenUtilsPackage {
|
|
|
10
10
|
* @returns Promise<BigNumber> - The parsed amount with correct decimals
|
|
11
11
|
*/
|
|
12
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>;
|
|
13
20
|
getTokenPrice(tokenName: string): Promise<number>;
|
|
14
21
|
getAllowance(tokenAddress: string, spender: string): Promise<string>;
|
|
15
22
|
approveAllowance(tokenAddress: string, amount: string, spenderAddress: string): Promise<string>;
|
|
@@ -25,6 +25,20 @@ class TokenUtilsPackage {
|
|
|
25
25
|
const decimals = await tokenContract.getPrecission();
|
|
26
26
|
return ethers_1.ethers.utils.parseUnits(amount, decimals);
|
|
27
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
|
+
}
|
|
28
42
|
async getTokenPrice(tokenName) {
|
|
29
43
|
return this.perqSdk.perqApi.fetchTokenPrice(tokenName);
|
|
30
44
|
}
|
|
@@ -8,6 +8,12 @@ export interface WithdrawParams {
|
|
|
8
8
|
vaultAddress: string;
|
|
9
9
|
onChainProjectId?: number;
|
|
10
10
|
}
|
|
11
|
+
export interface GetBalanceParams {
|
|
12
|
+
sdkType: SdkType;
|
|
13
|
+
tokenAddress: string;
|
|
14
|
+
vaultAddress: string;
|
|
15
|
+
onChainProjectId?: number;
|
|
16
|
+
}
|
|
11
17
|
export interface VaultOperations {
|
|
12
18
|
getAllowance(params: VaultOperationParams): Promise<boolean>;
|
|
13
19
|
approveAllowance(params: VaultOperationParams): Promise<string>;
|
|
@@ -40,7 +46,7 @@ export default class VaultHandler {
|
|
|
40
46
|
/**
|
|
41
47
|
* Get the balance of the vault
|
|
42
48
|
*/
|
|
43
|
-
getBalance(params:
|
|
49
|
+
getBalance(params: GetBalanceParams): Promise<string>;
|
|
44
50
|
/**
|
|
45
51
|
* Get the appropriate SDK handler based on SDK type
|
|
46
52
|
*/
|
|
@@ -83,7 +83,7 @@ class VaultHandler {
|
|
|
83
83
|
}
|
|
84
84
|
try {
|
|
85
85
|
const sdkHandler = this.getSdkHandler(params.sdkType);
|
|
86
|
-
return await sdkHandler.getBalance(params.vaultAddress, params.
|
|
86
|
+
return await sdkHandler.getBalance(params.vaultAddress, params.tokenAddress, params.onChainProjectId);
|
|
87
87
|
}
|
|
88
88
|
catch (error) {
|
|
89
89
|
console.error('Error withdrawing from vault:', error);
|
|
@@ -61,15 +61,13 @@ class YelayVaultOperations {
|
|
|
61
61
|
throw new Error('OnChainProjectId is required for Yelay vaults');
|
|
62
62
|
}
|
|
63
63
|
const depositType = this.determineDepositType(params);
|
|
64
|
-
const parsedAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
|
|
65
|
-
console.log('🚀 ~ parsedAmount:', parsedAmount.toString());
|
|
66
64
|
switch (depositType) {
|
|
67
65
|
case 'direct':
|
|
68
|
-
return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress,
|
|
66
|
+
return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, amount, vaultAddress);
|
|
69
67
|
case 'wrap':
|
|
70
68
|
throw new Error("Can't approve a native token");
|
|
71
69
|
case 'swap':
|
|
72
|
-
return await this.perqSdk.lite.approveSwapAndDeposit(sourceTokenAddress,
|
|
70
|
+
return await this.perqSdk.lite.approveSwapAndDeposit(sourceTokenAddress, amount);
|
|
73
71
|
default:
|
|
74
72
|
throw new Error(`Unsupported deposit type: ${depositType}`);
|
|
75
73
|
}
|