@dripfi/drip-sdk 1.4.28-silo-sdk-2 → 1.4.28-silo-sdk-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -71,13 +71,13 @@ The SDK automatically determines the deposit type based on the provided paramete
71
71
 
72
72
  Access vault methods through `sdk.vault`:
73
73
 
74
- | Method | Description |
75
- | --- | --- |
76
- | `getAllowance(params: VaultOperationParams): Promise<boolean>` | Checks if the user's allowance is sufficient for the `depositAmount` |
77
- | `approveAllowance(params: VaultOperationParams): Promise<string>` | Approves the allowance for the `depositAmount` for the selected Vault |
78
- | `deposit(params: VaultOperationParams): Promise<string>` | Deposits the `depositAmount` into the selected `vault` |
79
- | `withdraw(params: VaultOperationParams): Promise<string>` | Withdraws the specified amount from the selected vault |
80
- | `getBalance(vaultAddress: string, tokenAddress?: string, onChainProjectId?: number): Promise<string>` | Gets the user's balance for the specified vault |
74
+ | Method | Description |
75
+ | ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
76
+ | `getAllowance(params: VaultOperationParams): Promise<boolean>` | Checks if the user's allowance is sufficient for the `depositAmount` |
77
+ | `approveAllowance(params: VaultOperationParams): Promise<string>` | Approves the allowance for the `depositAmount` for the selected Vault |
78
+ | `deposit(params: VaultOperationParams): Promise<string>` | Deposits the `depositAmount` into the selected `vault` |
79
+ | `withdraw(params: VaultOperationParams): Promise<string>` | Withdraws the specified amount from the selected vault |
80
+ | `getBalance(vaultAddress: string, tokenAddress?: string, onChainProjectId?: number): Promise<string>` | Gets the user's balance for the specified vault |
81
81
 
82
82
  ## Legacy Methods
83
83
 
@@ -426,11 +426,11 @@ enum ELoyaltyCardTier {
426
426
  Black = 'Black',
427
427
  }
428
428
 
429
- interface IVaultOperations {
429
+ interface VaultOperations {
430
430
  getAllowance(params: VaultOperationParams): Promise<boolean>;
431
431
  approveAllowance(params: VaultOperationParams): Promise<string>;
432
432
  deposit(params: VaultOperationParams): Promise<string>;
433
- withdraw(params: VaultOperationParams): Promise<string>;
433
+ withdraw(params: WithdrawParams): Promise<string>;
434
434
  getBalance(vaultAddress: string, tokenAddress?: string, onChainProjectId?: number): Promise<string>;
435
435
  }
436
436
 
@@ -649,6 +649,15 @@ type VaultStats = {
649
649
 
650
650
  type VaultType = 'launch' | 'earn' | 'airdrop';
651
651
 
652
+ interface WithdrawParams {
653
+ amount: string;
654
+ sdkType: SdkType;
655
+ tokenAddress: string;
656
+ vaultAddress: string;
657
+ // Optional parameters that may be needed for specific SDK implementations
658
+ onChainProjectId?: number; // needed for yelay SDK
659
+ }
660
+
652
661
  interface VaultOperationParams {
653
662
  sourceTokenAddress: string;
654
663
  vaultTokenAddress: string;
@@ -760,6 +769,7 @@ type OverallStats = {
760
769
  totalUsers: number;
761
770
  };
762
771
 
772
+
763
773
  ```
764
774
 
765
775
  ## Abis
@@ -1,16 +1,16 @@
1
1
  import PerqSdk from '../PerqSdk';
2
2
  import { VaultOperationParams } from '../types/VaultOperationParams';
3
- import { IVaultOperations } from './VaultHandlerPackage';
3
+ import { VaultOperations, WithdrawParams } from './VaultHandlerPackage';
4
4
  /**
5
5
  * Silo SDK vault operations implementation
6
6
  */
7
- export declare class SiloVaultOperations implements IVaultOperations {
7
+ export declare class SiloVaultOperations implements VaultOperations {
8
8
  private perqSdk;
9
9
  constructor(perqSdk: PerqSdk);
10
10
  getAllowance(params: VaultOperationParams): Promise<boolean>;
11
11
  approveAllowance(params: VaultOperationParams): Promise<string>;
12
12
  deposit(params: VaultOperationParams): Promise<string>;
13
- withdraw(params: VaultOperationParams): Promise<string>;
13
+ withdraw(params: WithdrawParams): Promise<string>;
14
14
  getBalance(vaultAddress: string, tokenAddress: string): Promise<string>;
15
15
  /**
16
16
  * Handles Silo withdraw with automatic full/partial withdraw detection
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.SiloVaultOperations = void 0;
7
4
  const ethers_1 = require("ethers");
8
- const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
9
5
  /**
10
6
  * Silo SDK vault operations implementation
11
7
  */
@@ -24,11 +20,9 @@ class SiloVaultOperations {
24
20
  // For Silo, we use the standard ERC20 allowance
25
21
  const allowance = await this.perqSdk.tokenUtils.getERC20TokenAllowance(vaultAddress, sourceTokenAddress);
26
22
  console.log('🚀 ~ allowance:', allowance);
27
- // Get token decimals for proper amount comparison
28
- const tokenContract = new ERC20TokenContract_1.default(sourceTokenAddress, this.perqSdk.signer);
29
- const decimals = await tokenContract.getPrecission();
30
- const requiredAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
31
- console.log('🚀 ~ requiredAmount:', requiredAmount);
23
+ // Get required amount with correct decimals
24
+ const requiredAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
25
+ console.log('🚀 ~ requiredAmount:', requiredAmount.toString());
32
26
  return allowance.gte(requiredAmount);
33
27
  }
34
28
  catch (error) {
@@ -42,35 +36,40 @@ class SiloVaultOperations {
42
36
  if (!this.perqSdk.siloPackage) {
43
37
  throw new Error('Silo package not initialized. Please provide a signer.');
44
38
  }
39
+ const amountToApprove = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
40
+ console.log('🚀 ~ amountToApprove:', amountToApprove.toString());
45
41
  // For Silo, we use the standard ERC20 approval
46
- return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, amount, vaultAddress);
42
+ return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, amountToApprove.toString(), vaultAddress);
47
43
  }
48
44
  async deposit(params) {
49
- const { amount, vaultAddress } = params;
45
+ const { amount, vaultAddress, sourceTokenAddress } = params;
50
46
  console.log(`🚀 ~ silo deposit called with these params:`, { amount, vaultAddress });
51
47
  if (!this.perqSdk.siloPackage) {
52
48
  throw new Error('Silo package not initialized. Please provide a signer.');
53
49
  }
54
- const tx = await this.perqSdk.siloPackage.deposit(amount, vaultAddress);
50
+ const parsedAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
51
+ console.log('🚀 ~ parsedAmount:', parsedAmount.toString());
52
+ const tx = await this.perqSdk.siloPackage.deposit(parsedAmount.toString(), vaultAddress);
55
53
  return this.extractTransactionHash(tx);
56
54
  }
57
55
  async withdraw(params) {
58
- const { sourceTokenAddress, vaultAddress, amount } = params;
59
- console.log(`🚀 ~ silo withdraw called with these params:`, { sourceTokenAddress, vaultAddress, amount });
56
+ const { amount, vaultAddress, tokenAddress } = params;
57
+ console.log(`🚀 ~ silo withdraw called with these params:`, { amount, vaultAddress, tokenAddress });
60
58
  if (!this.perqSdk.siloPackage) {
61
59
  throw new Error('Silo package not initialized. Please provide a signer.');
62
60
  }
63
- return await this.handleSiloWithdraw(sourceTokenAddress, vaultAddress, amount);
61
+ const parsedAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, tokenAddress);
62
+ console.log('🚀 ~ parsedAmount:', parsedAmount.toString());
63
+ return await this.handleSiloWithdraw(tokenAddress, vaultAddress, parsedAmount.toString());
64
64
  }
65
65
  async getBalance(vaultAddress, tokenAddress) {
66
66
  if (!this.perqSdk.signer) {
67
67
  throw new Error('Signer not initialized');
68
68
  }
69
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
70
- const decimals = await tokenContract.getPrecission();
71
69
  const balance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
72
- const formattedBalance = ethers_1.ethers.utils.formatUnits(balance, decimals);
73
- return formattedBalance;
70
+ const formattedBalance = await this.perqSdk.tokenUtils.parseAmountWithDecimals(balance.toString(), tokenAddress);
71
+ console.log('🚀 ~ formattedBalance:', formattedBalance.toString());
72
+ return formattedBalance.toString();
74
73
  }
75
74
  /**
76
75
  * Handles Silo withdraw with automatic full/partial withdraw detection
@@ -80,13 +79,14 @@ class SiloVaultOperations {
80
79
  let userBalance = ethers_1.BigNumber.from(0);
81
80
  try {
82
81
  userBalance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
82
+ console.log('🚀 ~ userBalance:', userBalance.toString());
83
83
  }
84
84
  catch (error) {
85
85
  console.error('Error getting user balance for silo withdraw: ', error);
86
86
  }
87
- const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
88
- const decimals = await tokenContract.getPrecission();
89
- const parsedWithdrawAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
87
+ // Parse withdraw amount with correct decimals
88
+ const parsedWithdrawAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, tokenAddress);
89
+ console.log('🚀 ~ parsedWithdrawAmount:', parsedWithdrawAmount.toString());
90
90
  try {
91
91
  if (parsedWithdrawAmount.gte(userBalance)) {
92
92
  return await this.handleSiloFullWithdraw(vaultAddress);
@@ -3,6 +3,13 @@ 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>;
6
13
  getTokenPrice(tokenName: string): Promise<number>;
7
14
  getAllowance(tokenAddress: string, spender: string): Promise<string>;
8
15
  approveAllowance(tokenAddress: string, amount: string, spenderAddress: string): Promise<string>;
@@ -11,6 +11,20 @@ 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
+ }
14
28
  async getTokenPrice(tokenName) {
15
29
  return this.perqSdk.perqApi.fetchTokenPrice(tokenName);
16
30
  }
@@ -27,8 +41,7 @@ class TokenUtilsPackage {
27
41
  throw Error('No signer provided');
28
42
  }
29
43
  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);
44
+ const parsedAmount = await this.parseAmountWithDecimals(amount, tokenAddress);
32
45
  return await tokenContract.approveToken(spenderAddress, parsedAmount.toString());
33
46
  }
34
47
  async transferErc20Token(tokenAddress, amount, receiver) {
@@ -36,8 +49,8 @@ class TokenUtilsPackage {
36
49
  throw Error('No signer provided');
37
50
  }
38
51
  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());
52
+ const parsedAmount = await this.parseAmountWithDecimals(amount, tokenAddress);
53
+ const txHash = await tokenContract.transfer(receiver, parsedAmount.toString());
41
54
  return txHash;
42
55
  }
43
56
  async wrapEther(amount, tokenAddress) {
@@ -1,10 +1,18 @@
1
1
  import PerqSdk from '../PerqSdk';
2
+ import SdkType from '../types/SdkType';
2
3
  import { VaultOperationParams } from '../types/VaultOperationParams';
3
- export interface IVaultOperations {
4
+ export interface WithdrawParams {
5
+ amount: string;
6
+ sdkType: SdkType;
7
+ tokenAddress: string;
8
+ vaultAddress: string;
9
+ onChainProjectId?: number;
10
+ }
11
+ export interface VaultOperations {
4
12
  getAllowance(params: VaultOperationParams): Promise<boolean>;
5
13
  approveAllowance(params: VaultOperationParams): Promise<string>;
6
14
  deposit(params: VaultOperationParams): Promise<string>;
7
- withdraw(params: VaultOperationParams): Promise<string>;
15
+ withdraw(params: WithdrawParams): Promise<string>;
8
16
  getBalance(vaultAddress: string, tokenAddress?: string, onChainProjectId?: number): Promise<string>;
9
17
  }
10
18
  export default class VaultHandler {
@@ -28,7 +36,7 @@ export default class VaultHandler {
28
36
  /**
29
37
  * Withdraw from vault
30
38
  */
31
- withdraw(params: VaultOperationParams): Promise<string>;
39
+ withdraw(params: WithdrawParams): Promise<string>;
32
40
  /**
33
41
  * Get the balance of the vault
34
42
  */
@@ -1,13 +1,13 @@
1
1
  import PerqSdk from '../PerqSdk';
2
2
  import { VaultOperationParams } from '../types/VaultOperationParams';
3
- import { IVaultOperations } from './VaultHandlerPackage';
4
- export declare class YelayVaultOperations implements IVaultOperations {
3
+ import { VaultOperations, WithdrawParams } from './VaultHandlerPackage';
4
+ export declare class YelayVaultOperations implements VaultOperations {
5
5
  private perqSdk;
6
6
  constructor(perqSdk: PerqSdk);
7
7
  getAllowance(params: VaultOperationParams): Promise<boolean>;
8
8
  approveAllowance(params: VaultOperationParams): Promise<string>;
9
9
  deposit(params: VaultOperationParams): Promise<string>;
10
- withdraw(params: VaultOperationParams): Promise<string>;
11
- getBalance(vaultAddress: string, tokenAddress: string, onChainProjectId: number): Promise<string>;
10
+ withdraw(params: WithdrawParams): Promise<string>;
11
+ getBalance(vaultAddress: string, _: string, onChainProjectId: number): Promise<string>;
12
12
  private determineDepositType;
13
13
  }
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.YelayVaultOperations = void 0;
7
4
  const ethers_1 = require("ethers");
8
- const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
9
5
  class YelayVaultOperations {
10
6
  perqSdk;
11
7
  constructor(perqSdk) {
@@ -44,10 +40,8 @@ class YelayVaultOperations {
44
40
  default:
45
41
  throw new Error(`Unsupported deposit type: ${depositType}`);
46
42
  }
47
- // Get token decimals for proper amount comparison
48
- const tokenContract = new ERC20TokenContract_1.default(sourceTokenAddress, this.perqSdk.signer);
49
- const decimals = await tokenContract.getPrecission();
50
- const requiredAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
43
+ // Get required amount with correct decimals
44
+ const requiredAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
51
45
  return allowance.gte(requiredAmount);
52
46
  }
53
47
  catch (error) {
@@ -67,13 +61,15 @@ class YelayVaultOperations {
67
61
  throw new Error('OnChainProjectId is required for Yelay vaults');
68
62
  }
69
63
  const depositType = this.determineDepositType(params);
64
+ const parsedAmount = await this.perqSdk.tokenUtils.parseAmountWithDecimals(amount, sourceTokenAddress);
65
+ console.log('🚀 ~ parsedAmount:', parsedAmount.toString());
70
66
  switch (depositType) {
71
67
  case 'direct':
72
- return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, amount, vaultAddress);
68
+ return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, parsedAmount.toString(), vaultAddress);
73
69
  case 'wrap':
74
70
  throw new Error("Can't approve a native token");
75
71
  case 'swap':
76
- return await this.perqSdk.lite.approveSwapAndDeposit(sourceTokenAddress, amount);
72
+ return await this.perqSdk.lite.approveSwapAndDeposit(sourceTokenAddress, parsedAmount.toString());
77
73
  default:
78
74
  throw new Error(`Unsupported deposit type: ${depositType}`);
79
75
  }
@@ -121,26 +117,32 @@ class YelayVaultOperations {
121
117
  }
122
118
  }
123
119
  async withdraw(params) {
124
- const { sourceTokenAddress, vaultAddress, amount, onChainProjectId } = params;
125
- console.log(`🚀 ~ yelay withdraw called with these params: `, {
126
- sourceTokenAddress,
127
- vaultAddress,
120
+ const { amount, tokenAddress, vaultAddress, onChainProjectId } = params;
121
+ console.log(`🚀 ~ yelay withdraw called with these params:`, {
128
122
  amount,
123
+ tokenAddress,
124
+ vaultAddress,
129
125
  onChainProjectId,
130
126
  });
131
127
  if (!onChainProjectId || onChainProjectId === -1) {
132
128
  throw new Error('OnChainProjectId is required for Yelay vaults');
133
129
  }
134
130
  console.log('🚀 ~ this.perqSdk.lite.withdraw called', {
135
- sourceTokenAddress,
131
+ tokenAddress,
136
132
  vaultAddress,
137
133
  onChainProjectId,
138
134
  amount,
139
135
  });
140
- return await this.perqSdk.lite.withdraw(sourceTokenAddress, vaultAddress, onChainProjectId, amount);
136
+ return await this.perqSdk.lite.withdraw(tokenAddress, vaultAddress, onChainProjectId, amount);
141
137
  }
142
- async getBalance(vaultAddress, tokenAddress, onChainProjectId) {
143
- return await this.perqSdk.pools.getUserPoolBalance(vaultAddress, onChainProjectId);
138
+ async getBalance(vaultAddress, _, onChainProjectId) {
139
+ console.log('🚀 ~ this.perqSdk.pools.getUserPoolBalance called with: ', {
140
+ vaultAddress,
141
+ onChainProjectId,
142
+ });
143
+ const balance = await this.perqSdk.pools.getUserPoolBalance(vaultAddress, onChainProjectId);
144
+ console.log('🚀 ~ balance: ', balance);
145
+ return balance;
144
146
  }
145
147
  determineDepositType(params) {
146
148
  const { sourceTokenSymbol, vaultTokenSymbol } = params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dripfi/drip-sdk",
3
- "version": "1.4.28-silo-sdk-2",
3
+ "version": "1.4.28-silo-sdk-4",
4
4
  "description": "Drip SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",