@dripfi/drip-sdk 1.4.28-silo-sdk → 1.4.28-silo-sdk-2
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 +52 -11
- package/dist/subpackages/SiloPackage.js +0 -3
- package/dist/subpackages/SiloVaultOperations.d.ts +31 -0
- package/dist/subpackages/SiloVaultOperations.js +141 -0
- package/dist/subpackages/VaultHandlerPackage.d.ts +23 -20
- package/dist/subpackages/VaultHandlerPackage.js +55 -102
- package/dist/subpackages/YelayVaultOperations.d.ts +13 -0
- package/dist/subpackages/YelayVaultOperations.js +164 -0
- package/dist/types/SdkType.d.ts +1 -1
- package/dist/types/VaultOperationParams.d.ts +12 -0
- package/dist/types/VaultOperationParams.js +2 -0
- package/dist/types/index.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,6 +54,35 @@ const perqSdk = new PerqSdk(perqConfig, perqSupportedChainId, provider?: ethers.
|
|
|
54
54
|
|
|
55
55
|
## Modules
|
|
56
56
|
|
|
57
|
+
### Automatic Deposit Type Detection
|
|
58
|
+
|
|
59
|
+
The SDK automatically determines the deposit type based on the provided parameters:
|
|
60
|
+
|
|
61
|
+
- **Direct Deposit**: When `sourceTokenSymbol` equals `vaultTokenSymbol`
|
|
62
|
+
- **Wrap Deposit**: When `sourceTokenSymbol` is "ETH" / "S" or any other native token
|
|
63
|
+
- **Swap Deposit**: When `sourceTokenSymbol` differs from `vaultTokenSymbol` only possible on certain `sdkType` vaults
|
|
64
|
+
|
|
65
|
+
### Supported SDK Types
|
|
66
|
+
|
|
67
|
+
- **Yelay**: Supports direct deposits, ETH deposits, and swap deposits
|
|
68
|
+
- **Silo**: Supports standard ERC20 deposits and withdrawals
|
|
69
|
+
|
|
70
|
+
### Vault Handler
|
|
71
|
+
|
|
72
|
+
Access vault methods through `sdk.vault`:
|
|
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 |
|
|
81
|
+
|
|
82
|
+
## Legacy Methods
|
|
83
|
+
|
|
84
|
+
For backward compatibility, the original methods are still available:
|
|
85
|
+
|
|
57
86
|
### Core SDK
|
|
58
87
|
|
|
59
88
|
Core methods available directly on the SDK instance:
|
|
@@ -188,15 +217,6 @@ Access silo methods through `sdk.silo`:
|
|
|
188
217
|
| `getTotalSupply(vaultAddress: string): Promise<BigNumber>` | Retrieves the total amounts of shares in the Vault. |
|
|
189
218
|
| `getTotalAssets(vaultAddress: string): string` | Returns the total balance in the vaults currency/asset. |
|
|
190
219
|
|
|
191
|
-
### Vault Handler
|
|
192
|
-
|
|
193
|
-
Access vault methods through `sdk.vault`:
|
|
194
|
-
|
|
195
|
-
| Method | Description |
|
|
196
|
-
| ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- |
|
|
197
|
-
| `deposit(tokenAddress: string, vaultAddress: string, amount: string, sdkType: SdkType, onChainProjectId?: number): Promise<string>` | Handles deposit into any Vault by determining which sdk to use. |
|
|
198
|
-
| `withdraw(tokenAddress: string, vaultAddress: string, amount: string, sdkType: SdkType, onChainProjectId?: number): Promise<string>` | Withdraws from any Vault. |
|
|
199
|
-
|
|
200
220
|
## Examples
|
|
201
221
|
|
|
202
222
|
### `deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>`
|
|
@@ -301,7 +321,7 @@ const vaultToWithdrawFrom = vaults[0];
|
|
|
301
321
|
const txHash = await lite.withdraw(
|
|
302
322
|
vaultToWithdrawFrom.depositToken.tokenAddress,
|
|
303
323
|
vaultToWithdrawFrom.vaultAddress,
|
|
304
|
-
|
|
324
|
+
vaultToWithdrawFrom.onChainProjectId,
|
|
305
325
|
'3.55',
|
|
306
326
|
);
|
|
307
327
|
```
|
|
@@ -394,6 +414,8 @@ type DepositToken = {
|
|
|
394
414
|
tokenAddress: string;
|
|
395
415
|
};
|
|
396
416
|
|
|
417
|
+
type DepositType = 'direct' | 'swap' | 'wrap';
|
|
418
|
+
|
|
397
419
|
enum ELoyaltyCardTier {
|
|
398
420
|
White = 'White',
|
|
399
421
|
Ivory = 'Ivory',
|
|
@@ -404,6 +426,14 @@ enum ELoyaltyCardTier {
|
|
|
404
426
|
Black = 'Black',
|
|
405
427
|
}
|
|
406
428
|
|
|
429
|
+
interface IVaultOperations {
|
|
430
|
+
getAllowance(params: VaultOperationParams): Promise<boolean>;
|
|
431
|
+
approveAllowance(params: VaultOperationParams): Promise<string>;
|
|
432
|
+
deposit(params: VaultOperationParams): Promise<string>;
|
|
433
|
+
withdraw(params: VaultOperationParams): Promise<string>;
|
|
434
|
+
getBalance(vaultAddress: string, tokenAddress?: string, onChainProjectId?: number): Promise<string>;
|
|
435
|
+
}
|
|
436
|
+
|
|
407
437
|
type LoyaltyCard = {
|
|
408
438
|
id: string;
|
|
409
439
|
tier: ELoyaltyCardTier;
|
|
@@ -499,7 +529,7 @@ type QLFastRedeem = {
|
|
|
499
529
|
svtWithdrawn: string;
|
|
500
530
|
};
|
|
501
531
|
|
|
502
|
-
type SdkType = '
|
|
532
|
+
type SdkType = 'yelay' | 'silo';
|
|
503
533
|
|
|
504
534
|
type SpecialEditionLoyaltyCard = {
|
|
505
535
|
id: string;
|
|
@@ -619,6 +649,17 @@ type VaultStats = {
|
|
|
619
649
|
|
|
620
650
|
type VaultType = 'launch' | 'earn' | 'airdrop';
|
|
621
651
|
|
|
652
|
+
interface VaultOperationParams {
|
|
653
|
+
sourceTokenAddress: string;
|
|
654
|
+
vaultTokenAddress: string;
|
|
655
|
+
vaultAddress: string;
|
|
656
|
+
amount: string;
|
|
657
|
+
sdkType: SdkType;
|
|
658
|
+
onChainProjectId?: number;
|
|
659
|
+
sourceTokenSymbol?: string;
|
|
660
|
+
vaultTokenSymbol?: string;
|
|
661
|
+
}
|
|
662
|
+
|
|
622
663
|
type VestingInfo = {
|
|
623
664
|
startTimestamp: string;
|
|
624
665
|
endTimestamp: string;
|
|
@@ -5,9 +5,6 @@ class SiloPackage {
|
|
|
5
5
|
siloSdk;
|
|
6
6
|
constructor(signer) {
|
|
7
7
|
this.siloSdk = new silo_sdk_1.SiloSdk(signer);
|
|
8
|
-
console.log('Silo sdk constructed');
|
|
9
|
-
console.log('siloSdk.subgraph ', this.siloSdk.subgraph);
|
|
10
|
-
console.log('siloSdk.contracts ', this.siloSdk.contracts);
|
|
11
8
|
}
|
|
12
9
|
async deposit(assetAmount, vaultAddress) {
|
|
13
10
|
try {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import PerqSdk from '../PerqSdk';
|
|
2
|
+
import { VaultOperationParams } from '../types/VaultOperationParams';
|
|
3
|
+
import { IVaultOperations } from './VaultHandlerPackage';
|
|
4
|
+
/**
|
|
5
|
+
* Silo SDK vault operations implementation
|
|
6
|
+
*/
|
|
7
|
+
export declare class SiloVaultOperations implements IVaultOperations {
|
|
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: VaultOperationParams): 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,141 @@
|
|
|
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
|
+
exports.SiloVaultOperations = void 0;
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
|
|
9
|
+
/**
|
|
10
|
+
* Silo SDK vault operations implementation
|
|
11
|
+
*/
|
|
12
|
+
class SiloVaultOperations {
|
|
13
|
+
perqSdk;
|
|
14
|
+
constructor(perqSdk) {
|
|
15
|
+
this.perqSdk = perqSdk;
|
|
16
|
+
}
|
|
17
|
+
async getAllowance(params) {
|
|
18
|
+
const { sourceTokenAddress, vaultAddress, amount } = params;
|
|
19
|
+
console.log(`🚀 ~ silo getAllowance called with these params:`, { sourceTokenAddress, vaultAddress, amount });
|
|
20
|
+
if (!this.perqSdk.siloPackage) {
|
|
21
|
+
throw new Error('Silo package not initialized. Please provide a signer.');
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
// For Silo, we use the standard ERC20 allowance
|
|
25
|
+
const allowance = await this.perqSdk.tokenUtils.getERC20TokenAllowance(vaultAddress, sourceTokenAddress);
|
|
26
|
+
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);
|
|
32
|
+
return allowance.gte(requiredAmount);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error('Error checking allowance:', error);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async approveAllowance(params) {
|
|
40
|
+
const { sourceTokenAddress, vaultAddress, amount } = params;
|
|
41
|
+
console.log(`🚀 ~ silo approveAllowance called with these params:`, { sourceTokenAddress, vaultAddress, amount });
|
|
42
|
+
if (!this.perqSdk.siloPackage) {
|
|
43
|
+
throw new Error('Silo package not initialized. Please provide a signer.');
|
|
44
|
+
}
|
|
45
|
+
// For Silo, we use the standard ERC20 approval
|
|
46
|
+
return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, amount, vaultAddress);
|
|
47
|
+
}
|
|
48
|
+
async deposit(params) {
|
|
49
|
+
const { amount, vaultAddress } = params;
|
|
50
|
+
console.log(`🚀 ~ silo deposit called with these params:`, { amount, vaultAddress });
|
|
51
|
+
if (!this.perqSdk.siloPackage) {
|
|
52
|
+
throw new Error('Silo package not initialized. Please provide a signer.');
|
|
53
|
+
}
|
|
54
|
+
const tx = await this.perqSdk.siloPackage.deposit(amount, vaultAddress);
|
|
55
|
+
return this.extractTransactionHash(tx);
|
|
56
|
+
}
|
|
57
|
+
async withdraw(params) {
|
|
58
|
+
const { sourceTokenAddress, vaultAddress, amount } = params;
|
|
59
|
+
console.log(`🚀 ~ silo withdraw called with these params:`, { sourceTokenAddress, vaultAddress, amount });
|
|
60
|
+
if (!this.perqSdk.siloPackage) {
|
|
61
|
+
throw new Error('Silo package not initialized. Please provide a signer.');
|
|
62
|
+
}
|
|
63
|
+
return await this.handleSiloWithdraw(sourceTokenAddress, vaultAddress, amount);
|
|
64
|
+
}
|
|
65
|
+
async getBalance(vaultAddress, tokenAddress) {
|
|
66
|
+
if (!this.perqSdk.signer) {
|
|
67
|
+
throw new Error('Signer not initialized');
|
|
68
|
+
}
|
|
69
|
+
const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
|
|
70
|
+
const decimals = await tokenContract.getPrecission();
|
|
71
|
+
const balance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
|
|
72
|
+
const formattedBalance = ethers_1.ethers.utils.formatUnits(balance, decimals);
|
|
73
|
+
return formattedBalance;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Handles Silo withdraw with automatic full/partial withdraw detection
|
|
77
|
+
*/
|
|
78
|
+
async handleSiloWithdraw(tokenAddress, vaultAddress, amount) {
|
|
79
|
+
console.log(`🚀 ~ silo handleSiloWithdraw called with these params:`, { tokenAddress, vaultAddress, amount });
|
|
80
|
+
let userBalance = ethers_1.BigNumber.from(0);
|
|
81
|
+
try {
|
|
82
|
+
userBalance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('Error getting user balance for silo withdraw: ', error);
|
|
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);
|
|
90
|
+
try {
|
|
91
|
+
if (parsedWithdrawAmount.gte(userBalance)) {
|
|
92
|
+
return await this.handleSiloFullWithdraw(vaultAddress);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return await this.handleSiloPartialWithdraw(vaultAddress, parsedWithdrawAmount);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.error('Error handling silo withdraw: ', error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Handles a full withdraw from a Silo vault
|
|
105
|
+
*/
|
|
106
|
+
async handleSiloFullWithdraw(vaultAddress) {
|
|
107
|
+
const balanceInShares = await this.perqSdk.siloPackage.getBalanceInShares(vaultAddress);
|
|
108
|
+
console.log('🚀 ~ balanceInShares:', balanceInShares);
|
|
109
|
+
console.log('🚀 ~ perqSdk.siloPackage!.redeem:', { balanceInShares: balanceInShares.toString(), vaultAddress });
|
|
110
|
+
const tx = await this.perqSdk.siloPackage.redeem(balanceInShares.toString(), vaultAddress);
|
|
111
|
+
return this.extractTransactionHash(tx);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Handles a partial withdraw from a Silo vault
|
|
115
|
+
*/
|
|
116
|
+
async handleSiloPartialWithdraw(vaultAddress, parsedWithdrawAmount) {
|
|
117
|
+
console.log('🚀 ~ perqSdk.siloPackage!.withdraw:', {
|
|
118
|
+
parsedWithdrawAmount: parsedWithdrawAmount.toString(),
|
|
119
|
+
vaultAddress,
|
|
120
|
+
});
|
|
121
|
+
const tx = await this.perqSdk.siloPackage.withdraw(parsedWithdrawAmount.toString(), vaultAddress);
|
|
122
|
+
return this.extractTransactionHash(tx);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Extracts transaction hash from various transaction response formats
|
|
126
|
+
*/
|
|
127
|
+
extractTransactionHash(tx) {
|
|
128
|
+
console.log('🚀 ~ extractTransactionHash called with tx:', tx);
|
|
129
|
+
if (typeof tx === 'string') {
|
|
130
|
+
return tx;
|
|
131
|
+
}
|
|
132
|
+
if (tx?.hash) {
|
|
133
|
+
return tx.hash;
|
|
134
|
+
}
|
|
135
|
+
if (tx?.transactionHash) {
|
|
136
|
+
return tx.transactionHash;
|
|
137
|
+
}
|
|
138
|
+
throw new Error('Unable to extract transaction hash from response');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.SiloVaultOperations = SiloVaultOperations;
|
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
import PerqSdk from '../PerqSdk';
|
|
2
|
-
import
|
|
2
|
+
import { VaultOperationParams } from '../types/VaultOperationParams';
|
|
3
|
+
export interface IVaultOperations {
|
|
4
|
+
getAllowance(params: VaultOperationParams): Promise<boolean>;
|
|
5
|
+
approveAllowance(params: VaultOperationParams): Promise<string>;
|
|
6
|
+
deposit(params: VaultOperationParams): Promise<string>;
|
|
7
|
+
withdraw(params: VaultOperationParams): Promise<string>;
|
|
8
|
+
getBalance(vaultAddress: string, tokenAddress?: string, onChainProjectId?: number): Promise<string>;
|
|
9
|
+
}
|
|
3
10
|
export default class VaultHandler {
|
|
4
11
|
private perqSdk;
|
|
5
12
|
constructor(perqSdk: PerqSdk);
|
|
6
|
-
deposit(tokenAddress: string, vaultAddress: string, amount: string, sdkType: SdkType, onChainProjectId?: number): Promise<string>;
|
|
7
|
-
withdraw(tokenAddress: string, vaultAddress: string, amount: string, sdkType: SdkType, onChainProjectId?: number): Promise<string>;
|
|
8
|
-
/**
|
|
9
|
-
* Centralized method to execute vault operations based on SDK type
|
|
10
|
-
* This makes it easy to add new SDK types in the future
|
|
11
|
-
*/
|
|
12
|
-
private executeVaultOperation;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Get allowance for vault operations
|
|
15
|
+
* Returns true if the user has approved sufficient allowance for the specified amount
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
getAllowance(params: VaultOperationParams): Promise<boolean>;
|
|
17
18
|
/**
|
|
18
|
-
*
|
|
19
|
+
* Approve allowance for vault operations
|
|
20
|
+
* Automatically determines the correct approval method based on deposit type
|
|
19
21
|
*/
|
|
20
|
-
|
|
22
|
+
approveAllowance(params: VaultOperationParams): Promise<string>;
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* Deposit to vault
|
|
25
|
+
* Automatically determines the correct deposit method based on deposit type
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
deposit(params: VaultOperationParams): Promise<string>;
|
|
25
28
|
/**
|
|
26
|
-
*
|
|
29
|
+
* Withdraw from vault
|
|
27
30
|
*/
|
|
28
|
-
|
|
31
|
+
withdraw(params: VaultOperationParams): Promise<string>;
|
|
29
32
|
/**
|
|
30
|
-
*
|
|
33
|
+
* Get the balance of the vault
|
|
31
34
|
*/
|
|
32
|
-
|
|
35
|
+
getBalance(params: VaultOperationParams): Promise<string>;
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
37
|
+
* Get the appropriate SDK handler based on SDK type
|
|
35
38
|
*/
|
|
36
|
-
private
|
|
39
|
+
private getSdkHandler;
|
|
37
40
|
}
|
|
@@ -1,154 +1,107 @@
|
|
|
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
|
-
const
|
|
7
|
-
const
|
|
3
|
+
const YelayVaultOperations_1 = require("./YelayVaultOperations");
|
|
4
|
+
const SiloVaultOperations_1 = require("./SiloVaultOperations");
|
|
8
5
|
class VaultHandler {
|
|
9
6
|
perqSdk;
|
|
10
7
|
constructor(perqSdk) {
|
|
11
8
|
this.perqSdk = perqSdk;
|
|
12
9
|
}
|
|
13
|
-
|
|
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) {
|
|
14
15
|
if (!this.perqSdk.signer) {
|
|
15
16
|
throw Error('No signer provided');
|
|
16
17
|
}
|
|
17
18
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
vaultAddress,
|
|
21
|
-
amount,
|
|
22
|
-
sdkType,
|
|
23
|
-
onChainProjectId,
|
|
24
|
-
});
|
|
19
|
+
const sdkHandler = this.getSdkHandler(params.sdkType);
|
|
20
|
+
return await sdkHandler.getAllowance(params);
|
|
25
21
|
}
|
|
26
22
|
catch (error) {
|
|
27
|
-
console.error('Error
|
|
23
|
+
console.error('Error getting allowance:', error);
|
|
28
24
|
throw error;
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Approve allowance for vault operations
|
|
29
|
+
* Automatically determines the correct approval method based on deposit type
|
|
30
|
+
*/
|
|
31
|
+
async approveAllowance(params) {
|
|
32
32
|
if (!this.perqSdk.signer) {
|
|
33
33
|
throw Error('No signer provided');
|
|
34
34
|
}
|
|
35
35
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
vaultAddress,
|
|
39
|
-
amount,
|
|
40
|
-
sdkType,
|
|
41
|
-
onChainProjectId,
|
|
42
|
-
});
|
|
36
|
+
const sdkHandler = this.getSdkHandler(params.sdkType);
|
|
37
|
+
return await sdkHandler.approveAllowance(params);
|
|
43
38
|
}
|
|
44
39
|
catch (error) {
|
|
45
|
-
console.error('Error
|
|
40
|
+
console.error('Error approving allowance:', error);
|
|
46
41
|
throw error;
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
44
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
45
|
+
* Deposit to vault
|
|
46
|
+
* Automatically determines the correct deposit method based on deposit type
|
|
52
47
|
*/
|
|
53
|
-
async
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
case 'lite':
|
|
57
|
-
return this.handleYelayLiteOperation(operation, tokenAddress, vaultAddress, amount, onChainProjectId);
|
|
58
|
-
case 'silo':
|
|
59
|
-
return this.handleSiloOperation(operation, tokenAddress, vaultAddress, amount);
|
|
60
|
-
default:
|
|
61
|
-
throw new Error(`Unsupported SDK type: ${sdkType}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Handles Yelay Lite vault operations
|
|
66
|
-
*/
|
|
67
|
-
async handleYelayLiteOperation(operation, tokenAddress, vaultAddress, amount, onChainProjectId) {
|
|
68
|
-
if (!onChainProjectId || onChainProjectId === -1) {
|
|
69
|
-
throw new Error('OnChainProjectId is required for Lite vaults');
|
|
48
|
+
async deposit(params) {
|
|
49
|
+
if (!this.perqSdk.signer) {
|
|
50
|
+
throw Error('No signer provided');
|
|
70
51
|
}
|
|
71
|
-
|
|
72
|
-
|
|
52
|
+
try {
|
|
53
|
+
const sdkHandler = this.getSdkHandler(params.sdkType);
|
|
54
|
+
return await sdkHandler.deposit(params);
|
|
73
55
|
}
|
|
74
|
-
|
|
75
|
-
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error('Error depositing to vault:', error);
|
|
58
|
+
throw error;
|
|
76
59
|
}
|
|
77
60
|
}
|
|
78
61
|
/**
|
|
79
|
-
*
|
|
62
|
+
* Withdraw from vault
|
|
80
63
|
*/
|
|
81
|
-
async
|
|
82
|
-
if (!this.perqSdk.
|
|
83
|
-
throw
|
|
64
|
+
async withdraw(params) {
|
|
65
|
+
if (!this.perqSdk.signer) {
|
|
66
|
+
throw Error('No signer provided');
|
|
84
67
|
}
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
return
|
|
68
|
+
try {
|
|
69
|
+
const sdkHandler = this.getSdkHandler(params.sdkType);
|
|
70
|
+
return await sdkHandler.withdraw(params);
|
|
88
71
|
}
|
|
89
|
-
|
|
90
|
-
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('Error withdrawing from vault:', error);
|
|
74
|
+
throw error;
|
|
91
75
|
}
|
|
92
76
|
}
|
|
93
77
|
/**
|
|
94
|
-
*
|
|
78
|
+
* Get the balance of the vault
|
|
95
79
|
*/
|
|
96
|
-
async
|
|
97
|
-
if (!this.perqSdk.
|
|
98
|
-
throw
|
|
99
|
-
}
|
|
100
|
-
let userBalance = ethers_1.BigNumber.from(0);
|
|
101
|
-
try {
|
|
102
|
-
userBalance = await this.perqSdk.siloPackage.getBalanceInAssets(vaultAddress);
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
console.error('Error getting user balance for silo withdraw: ', error);
|
|
80
|
+
async getBalance(params) {
|
|
81
|
+
if (!this.perqSdk.signer) {
|
|
82
|
+
throw Error('No signer provided');
|
|
106
83
|
}
|
|
107
|
-
const tokenContract = new ERC20TokenContract_1.default(tokenAddress, this.perqSdk.signer);
|
|
108
|
-
const decimals = await tokenContract.getPrecission();
|
|
109
|
-
const parsedWithdrawAmount = ethers_1.ethers.utils.parseUnits(amount, decimals);
|
|
110
84
|
try {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return await this.handleSiloPartialWithdraw(vaultAddress, parsedWithdrawAmount);
|
|
116
|
-
}
|
|
85
|
+
const sdkHandler = this.getSdkHandler(params.sdkType);
|
|
86
|
+
return await sdkHandler.getBalance(params.vaultAddress, params.vaultTokenAddress, params.onChainProjectId);
|
|
117
87
|
}
|
|
118
88
|
catch (error) {
|
|
119
|
-
console.error('Error
|
|
89
|
+
console.error('Error withdrawing from vault:', error);
|
|
120
90
|
throw error;
|
|
121
91
|
}
|
|
122
92
|
}
|
|
123
93
|
/**
|
|
124
|
-
*
|
|
125
|
-
*/
|
|
126
|
-
async handleSiloFullWithdraw(vaultAddress) {
|
|
127
|
-
const balanceInShares = await this.perqSdk.siloPackage.getBalanceInShares(vaultAddress);
|
|
128
|
-
const tx = await this.perqSdk.siloPackage.redeem(balanceInShares.toString(), vaultAddress);
|
|
129
|
-
return this.extractTransactionHash(tx);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Handles a partial withdraw from a Silo vault
|
|
133
|
-
*/
|
|
134
|
-
async handleSiloPartialWithdraw(vaultAddress, parsedWithdrawAmount) {
|
|
135
|
-
const tx = await this.perqSdk.siloPackage.withdraw(parsedWithdrawAmount.toString(), vaultAddress);
|
|
136
|
-
return this.extractTransactionHash(tx);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Extracts transaction hash from various transaction response formats
|
|
94
|
+
* Get the appropriate SDK handler based on SDK type
|
|
140
95
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return tx.transactionHash;
|
|
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}`);
|
|
150
104
|
}
|
|
151
|
-
throw new Error('Unable to extract transaction hash from response');
|
|
152
105
|
}
|
|
153
106
|
}
|
|
154
107
|
exports.default = VaultHandler;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import PerqSdk from '../PerqSdk';
|
|
2
|
+
import { VaultOperationParams } from '../types/VaultOperationParams';
|
|
3
|
+
import { IVaultOperations } from './VaultHandlerPackage';
|
|
4
|
+
export declare class YelayVaultOperations implements IVaultOperations {
|
|
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: VaultOperationParams): Promise<string>;
|
|
11
|
+
getBalance(vaultAddress: string, tokenAddress: string, onChainProjectId: number): Promise<string>;
|
|
12
|
+
private determineDepositType;
|
|
13
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
exports.YelayVaultOperations = void 0;
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
const ERC20TokenContract_1 = __importDefault(require("../contracts/ERC20TokenContract"));
|
|
9
|
+
class YelayVaultOperations {
|
|
10
|
+
perqSdk;
|
|
11
|
+
constructor(perqSdk) {
|
|
12
|
+
this.perqSdk = perqSdk;
|
|
13
|
+
}
|
|
14
|
+
async getAllowance(params) {
|
|
15
|
+
const { sourceTokenAddress, vaultAddress, onChainProjectId, amount } = params;
|
|
16
|
+
console.log(`🚀 ~ yelay getAllowance with these params: `, {
|
|
17
|
+
sourceTokenAddress,
|
|
18
|
+
vaultAddress,
|
|
19
|
+
onChainProjectId,
|
|
20
|
+
amount,
|
|
21
|
+
});
|
|
22
|
+
if (!onChainProjectId || onChainProjectId === -1) {
|
|
23
|
+
throw new Error('OnChainProjectId is required for Yelay vaults');
|
|
24
|
+
}
|
|
25
|
+
const depositType = this.determineDepositType(params);
|
|
26
|
+
console.log('🚀 ~ depositType: ', depositType);
|
|
27
|
+
try {
|
|
28
|
+
let allowance;
|
|
29
|
+
switch (depositType) {
|
|
30
|
+
case 'direct': {
|
|
31
|
+
allowance = await this.perqSdk.tokenUtils.getERC20TokenAllowance(vaultAddress, sourceTokenAddress);
|
|
32
|
+
console.log('🚀 ~ direct deposit allowance: ', allowance);
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'swap': {
|
|
36
|
+
const allowanceString = await this.perqSdk.lite.getSwapAndDepositAllowance(sourceTokenAddress);
|
|
37
|
+
allowance = ethers_1.BigNumber.from(allowanceString);
|
|
38
|
+
console.log('🚀 ~ swapAndDeposit allowance: ', allowance);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case 'wrap': {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
default:
|
|
45
|
+
throw new Error(`Unsupported deposit type: ${depositType}`);
|
|
46
|
+
}
|
|
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);
|
|
51
|
+
return allowance.gte(requiredAmount);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('Error checking allowance:', error);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async approveAllowance(params) {
|
|
59
|
+
const { sourceTokenAddress, vaultAddress, amount, onChainProjectId } = params;
|
|
60
|
+
console.log(`🚀 ~ yelay approveAllowance called with these params:`, {
|
|
61
|
+
sourceTokenAddress,
|
|
62
|
+
vaultAddress,
|
|
63
|
+
amount,
|
|
64
|
+
onChainProjectId,
|
|
65
|
+
});
|
|
66
|
+
if (!onChainProjectId || onChainProjectId === -1) {
|
|
67
|
+
throw new Error('OnChainProjectId is required for Yelay vaults');
|
|
68
|
+
}
|
|
69
|
+
const depositType = this.determineDepositType(params);
|
|
70
|
+
switch (depositType) {
|
|
71
|
+
case 'direct':
|
|
72
|
+
return await this.perqSdk.tokenUtils.approveAllowance(sourceTokenAddress, amount, vaultAddress);
|
|
73
|
+
case 'wrap':
|
|
74
|
+
throw new Error("Can't approve a native token");
|
|
75
|
+
case 'swap':
|
|
76
|
+
return await this.perqSdk.lite.approveSwapAndDeposit(sourceTokenAddress, amount);
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(`Unsupported deposit type: ${depositType}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async deposit(params) {
|
|
82
|
+
const { sourceTokenAddress, vaultTokenAddress, vaultAddress, amount, onChainProjectId } = params;
|
|
83
|
+
console.log(`🚀 ~ yelay deposit called with these params: `, {
|
|
84
|
+
sourceTokenAddress,
|
|
85
|
+
vaultTokenAddress,
|
|
86
|
+
vaultAddress,
|
|
87
|
+
amount,
|
|
88
|
+
onChainProjectId,
|
|
89
|
+
});
|
|
90
|
+
if (!onChainProjectId || onChainProjectId === -1) {
|
|
91
|
+
throw new Error('OnChainProjectId is required for Yelay vaults');
|
|
92
|
+
}
|
|
93
|
+
const depositType = this.determineDepositType(params);
|
|
94
|
+
switch (depositType) {
|
|
95
|
+
case 'direct':
|
|
96
|
+
console.log('🚀 ~ this.perqSdk.lite.deposit called', {
|
|
97
|
+
sourceTokenAddress,
|
|
98
|
+
vaultAddress,
|
|
99
|
+
onChainProjectId,
|
|
100
|
+
amount,
|
|
101
|
+
});
|
|
102
|
+
return await this.perqSdk.lite.deposit(sourceTokenAddress, vaultAddress, onChainProjectId, amount);
|
|
103
|
+
case 'wrap':
|
|
104
|
+
console.log('🚀 ~ this.perqSdk.lite.wrapAndDepositEth called', {
|
|
105
|
+
vaultAddress,
|
|
106
|
+
onChainProjectId,
|
|
107
|
+
amount,
|
|
108
|
+
});
|
|
109
|
+
return await this.perqSdk.lite.wrapAndDepositEth(vaultAddress, onChainProjectId, amount);
|
|
110
|
+
case 'swap':
|
|
111
|
+
console.log('🚀 ~ this.perqSdk.lite.swapAndDeposit called', {
|
|
112
|
+
sourceTokenAddress,
|
|
113
|
+
vaultTokenAddress,
|
|
114
|
+
amount,
|
|
115
|
+
vaultAddress,
|
|
116
|
+
onChainProjectId,
|
|
117
|
+
});
|
|
118
|
+
return await this.perqSdk.lite.swapAndDeposit(sourceTokenAddress, vaultTokenAddress, amount, vaultAddress, onChainProjectId);
|
|
119
|
+
default:
|
|
120
|
+
throw new Error(`Unsupported deposit type: ${depositType}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async withdraw(params) {
|
|
124
|
+
const { sourceTokenAddress, vaultAddress, amount, onChainProjectId } = params;
|
|
125
|
+
console.log(`🚀 ~ yelay withdraw called with these params: `, {
|
|
126
|
+
sourceTokenAddress,
|
|
127
|
+
vaultAddress,
|
|
128
|
+
amount,
|
|
129
|
+
onChainProjectId,
|
|
130
|
+
});
|
|
131
|
+
if (!onChainProjectId || onChainProjectId === -1) {
|
|
132
|
+
throw new Error('OnChainProjectId is required for Yelay vaults');
|
|
133
|
+
}
|
|
134
|
+
console.log('🚀 ~ this.perqSdk.lite.withdraw called', {
|
|
135
|
+
sourceTokenAddress,
|
|
136
|
+
vaultAddress,
|
|
137
|
+
onChainProjectId,
|
|
138
|
+
amount,
|
|
139
|
+
});
|
|
140
|
+
return await this.perqSdk.lite.withdraw(sourceTokenAddress, vaultAddress, onChainProjectId, amount);
|
|
141
|
+
}
|
|
142
|
+
async getBalance(vaultAddress, tokenAddress, onChainProjectId) {
|
|
143
|
+
return await this.perqSdk.pools.getUserPoolBalance(vaultAddress, onChainProjectId);
|
|
144
|
+
}
|
|
145
|
+
determineDepositType(params) {
|
|
146
|
+
const { sourceTokenSymbol, vaultTokenSymbol } = params;
|
|
147
|
+
if (!sourceTokenSymbol || !vaultTokenSymbol) {
|
|
148
|
+
return 'direct';
|
|
149
|
+
}
|
|
150
|
+
const lowerSourceToken = sourceTokenSymbol.toLowerCase();
|
|
151
|
+
const lowerVaultToken = vaultTokenSymbol.toLowerCase();
|
|
152
|
+
// Check if it's ETH wrap deposit
|
|
153
|
+
if (lowerSourceToken === 'eth' || lowerSourceToken === 's') {
|
|
154
|
+
return 'wrap';
|
|
155
|
+
}
|
|
156
|
+
// Check if it's a direct deposit (same token)
|
|
157
|
+
if (lowerSourceToken === lowerVaultToken) {
|
|
158
|
+
return 'direct';
|
|
159
|
+
}
|
|
160
|
+
// Otherwise it's a swap deposit
|
|
161
|
+
return 'swap';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.YelayVaultOperations = YelayVaultOperations;
|
package/dist/types/SdkType.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
type SdkType = '
|
|
1
|
+
type SdkType = 'yelay' | 'silo';
|
|
2
2
|
export default SdkType;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import SdkType from './SdkType';
|
|
2
|
+
export interface VaultOperationParams {
|
|
3
|
+
sourceTokenAddress: string;
|
|
4
|
+
vaultTokenAddress: string;
|
|
5
|
+
vaultAddress: string;
|
|
6
|
+
amount: string;
|
|
7
|
+
sdkType: SdkType;
|
|
8
|
+
onChainProjectId?: number;
|
|
9
|
+
sourceTokenSymbol?: string;
|
|
10
|
+
vaultTokenSymbol?: string;
|
|
11
|
+
}
|
|
12
|
+
export type DepositType = 'direct' | 'swap' | 'wrap';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -25,9 +25,10 @@ import VaultData from './VaultData';
|
|
|
25
25
|
import VaultReward, { RewardType } from './VaultReward';
|
|
26
26
|
import VaultStats from './VaultStats';
|
|
27
27
|
import VaultType from './VaultType';
|
|
28
|
+
import { VaultOperationParams, DepositType } from './VaultOperationParams';
|
|
28
29
|
import VestingInfo from './VestingInfo';
|
|
29
30
|
import YelayVersion from './YelayVersion';
|
|
30
31
|
import Earnings from './Earnings';
|
|
31
32
|
import LinkedPodWallets from './LinkedPodWallets';
|
|
32
33
|
import MigrationOption from './MigrationOption';
|
|
33
|
-
export { Asset, BasePayload, BeanEntry, BeansBalance, DeployedProject, DeployedVault, DepositToken, DetailedProjectData, ELoyaltyCardTier, NearWalletPayload, SuiWalletPayload, LinkedPodWallets, LoyaltyCard, MigrationOption, MyPerqData, NFTBoost, NonceEnrichedPayload, NonceEnrichedSignedPayload, PerqConfig, PerqToBeansSwapInfo, ProjectBacker, QLFastRedeem, ReducedProjectData, RewardType, SpecialEditionLoyaltyCard, Strategy, StretchGoal, SwapInfo, UpgradeLoyaltyCardPayload, UserRewards, VaultData, VaultReward, VaultStats, VaultType, VestingInfo, YelayVersion, Earnings, };
|
|
34
|
+
export { Asset, BasePayload, BeanEntry, BeansBalance, DeployedProject, DeployedVault, DepositToken, DetailedProjectData, ELoyaltyCardTier, NearWalletPayload, SuiWalletPayload, LinkedPodWallets, LoyaltyCard, MigrationOption, MyPerqData, NFTBoost, NonceEnrichedPayload, NonceEnrichedSignedPayload, PerqConfig, PerqToBeansSwapInfo, ProjectBacker, QLFastRedeem, ReducedProjectData, RewardType, SpecialEditionLoyaltyCard, Strategy, StretchGoal, SwapInfo, UpgradeLoyaltyCardPayload, UserRewards, VaultData, VaultReward, VaultStats, VaultType, VaultOperationParams, DepositType, VestingInfo, YelayVersion, Earnings, };
|