@dripfi/drip-sdk 2.0.0 → 2.0.1
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 +73 -24
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ The Drip SDK is a TypeScript library designed to interact with the Perq protocol
|
|
|
8
8
|
|
|
9
9
|
- [Installation](#installation)
|
|
10
10
|
- [Usage](#usage)
|
|
11
|
+
- [Initialization](#initialization)
|
|
11
12
|
- [Modules](#modules)
|
|
12
13
|
- [Core SDK](#core-sdk)
|
|
13
14
|
- [Lite Vaults](#lite-vaults)
|
|
@@ -17,6 +18,7 @@ The Drip SDK is a TypeScript library designed to interact with the Perq protocol
|
|
|
17
18
|
- [Sign Handler](#sign-handler)
|
|
18
19
|
- [Silo](#silo)
|
|
19
20
|
- [Vault Handler](#vault-handler)
|
|
21
|
+
- [Token Utils](#token-utils)
|
|
20
22
|
- [Examples](#examples)
|
|
21
23
|
- [Types](#types)
|
|
22
24
|
- [Abis](#abis)
|
|
@@ -32,26 +34,39 @@ npm i @dripfi/drip-sdk
|
|
|
32
34
|
## Usage
|
|
33
35
|
|
|
34
36
|
```typescript
|
|
35
|
-
import PerqSdk from '@drip
|
|
36
|
-
import {
|
|
37
|
+
import { PerqSdk, PRODUCTION, DEVELOPMENT } from '@dripfi/drip-sdk';
|
|
38
|
+
import { ethers } from 'ethers';
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
## Initialization
|
|
42
|
+
|
|
43
|
+
The SDK now requires a two-step initialization process:
|
|
40
44
|
|
|
41
45
|
```typescript
|
|
42
|
-
|
|
46
|
+
// Step 1: Create the SDK instance with configuration
|
|
47
|
+
const perqConfig = PRODUCTION; // Use DEVELOPMENT for testnet
|
|
48
|
+
|
|
49
|
+
const perqSdk = new PerqSdk(perqConfig);
|
|
43
50
|
|
|
44
|
-
|
|
51
|
+
// Step 2: Initialize with a provider (required before making blockchain calls)
|
|
52
|
+
const provider = new ethers.providers.JsonRpcProvider('YOUR_RPC_URL');
|
|
53
|
+
// Or if using Web3Provider from browser wallet:
|
|
54
|
+
// const provider = new ethers.providers.Web3Provider(window.ethereum);
|
|
45
55
|
|
|
46
|
-
|
|
56
|
+
await perqSdk.init(provider);
|
|
57
|
+
```
|
|
47
58
|
|
|
48
|
-
|
|
59
|
+
### Updating the Provider
|
|
49
60
|
|
|
50
|
-
|
|
61
|
+
When the user switches networks or wallets, update the SDK:
|
|
51
62
|
|
|
52
|
-
|
|
63
|
+
```typescript
|
|
64
|
+
await perqSdk.updateDripSdk(newProvider);
|
|
53
65
|
```
|
|
54
66
|
|
|
67
|
+
> [!IMPORTANT]
|
|
68
|
+
> The `init()` method must be called before using any blockchain operations.
|
|
69
|
+
|
|
55
70
|
## Modules
|
|
56
71
|
|
|
57
72
|
### Automatic Deposit Type Detection
|
|
@@ -87,25 +102,27 @@ For backward compatibility, the original methods are still available:
|
|
|
87
102
|
|
|
88
103
|
Core methods available directly on the SDK instance:
|
|
89
104
|
|
|
90
|
-
| Method
|
|
91
|
-
|
|
|
92
|
-
| `
|
|
105
|
+
| Method | Description |
|
|
106
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------------------------ |
|
|
107
|
+
| `init(provider: ethers.providers.JsonRpcProvider): Promise<void>` | Initializes the SDK with a provider. Required before making blockchain calls. |
|
|
108
|
+
| `updateDripSdk(provider?: ethers.providers.JsonRpcProvider): Promise<void>` | Updates the SDK with a new provider when user switches networks or wallets. |
|
|
93
109
|
|
|
94
110
|
### Lite Vaults
|
|
95
111
|
|
|
96
112
|
Access Lite vault methods through `sdk.lite`:
|
|
97
113
|
|
|
98
|
-
| Method | Description
|
|
99
|
-
| -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
114
|
+
| Method | Description |
|
|
115
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
116
|
+
| `deposit(tokenAddress: string, vaultAddress: string, onChainProjectId: number, amount: string): Promise<string>` | Deposits into Lite vault. |
|
|
117
|
+
| `withdraw(tokenAddress: string, vaultAddress: string, onChainProjectId: number, amount: string): Promise<string>` | Withdraws from Lite vault. |
|
|
118
|
+
| `swapAndDeposit(fromTokenAddress: string, toTokenAddress: string, amount: string, vaultAddress: string, onChainProjectId: number): Promise<string>` | Swaps and deposits into Lite vault. *(Currently disabled pending 1inch KYC)* |
|
|
119
|
+
| `wrapAndDepositEth(vaultAddress: string, onChainProjectId: number, amount: string): Promise<string>` | Wraps native token (ETH/S) and deposits. |
|
|
120
|
+
| `getSwapAndDepositAllowance(tokenAddress: string): Promise<string>` | Fetches the allowance for swap and deposit operations. |
|
|
121
|
+
| `approveSwapAndDeposit(tokenAddress: string, amount: string): Promise<string>` | Approves a token for swap and deposit operations. |
|
|
122
|
+
| `getExpectedSwapResult(fromTokenAddress: string, toTokenAddress: string, amount: string, decimals: number, chainId: PerqSupportedChainId): Promise<string>` | Calculates the expected result of a swap operation on a specific chain. |
|
|
123
|
+
| `getMigrationOptions(vaultAddress: string, onChainProjectId: number): Promise<MigrationOption[]>` | Fetches available migration options for a vault position. |
|
|
124
|
+
| `migrateDepositToOtherProject(tokenAddress: string, vaultAddress: string, fromProjectId: number, toProjectId: number, amount: string): Promise<string>` | Migrates a deposit from one project to another. |
|
|
125
|
+
| `getHistoricalTvl(projectName: string): Promise<ProjectHistoricalTvl>` | Fetches historical TVL data for a project. |
|
|
109
126
|
|
|
110
127
|
### Loyalty Cards
|
|
111
128
|
|
|
@@ -195,6 +212,8 @@ Access token utils methods through `sdk.tokenUtils`:
|
|
|
195
212
|
| `wrapEther(amount: string, tokenAddress: string): Promise<string>` | Wraps a specified amount of Ether into a WETH token. |
|
|
196
213
|
| `getERC20TokenAllowance(spender: string, tokenAddress: string): Promise<BigNumber>` | Retrieves the allowance for a specific ERC20 token. |
|
|
197
214
|
| `getPerqTokenContractAddress(): string` | Returns the contract address of the Perq token. |
|
|
215
|
+
| `parseAmountWithDecimals(amount: string, tokenAddress: string): Promise<BigNumber>` | Parses a human-readable amount to BigNumber with correct token decimals. |
|
|
216
|
+
| `formatAmountWithDecimals(amount: BigNumber, tokenAddress: string): Promise<string>` | Formats a BigNumber amount to human-readable string with correct decimals. |
|
|
198
217
|
|
|
199
218
|
### Sign Handler
|
|
200
219
|
|
|
@@ -220,6 +239,25 @@ Access silo methods through `sdk.silo`:
|
|
|
220
239
|
|
|
221
240
|
## Examples
|
|
222
241
|
|
|
242
|
+
### SDK Initialization
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
import { PerqSdk, PRODUCTION } from '@dripfi/drip-sdk';
|
|
246
|
+
import { ethers } from 'ethers';
|
|
247
|
+
|
|
248
|
+
// Create SDK instance
|
|
249
|
+
const perqSdk = new PerqSdk(PRODUCTION);
|
|
250
|
+
|
|
251
|
+
// Initialize with Web3Provider (browser wallet)
|
|
252
|
+
const provider = new ethers.providers.Web3Provider(window.ethereum);
|
|
253
|
+
await perqSdk.init(provider);
|
|
254
|
+
|
|
255
|
+
// Now you can use all SDK methods
|
|
256
|
+
const pools = await perqSdk.pools.getAllPools();
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
223
261
|
### `deposit(tokenAddress: string, vaultAddress: string, amount: string): Promise<string>`
|
|
224
262
|
|
|
225
263
|
I want to deposit 100 USDC in a USDC vault:
|
|
@@ -525,10 +563,11 @@ type PerqConfig = {
|
|
|
525
563
|
perqTokenAddress: string;
|
|
526
564
|
perqTokenRecyclerAddress: string;
|
|
527
565
|
perqSwapAndRecyclerAddress: string;
|
|
566
|
+
slotBurnTokenAddress: string;
|
|
528
567
|
perqVestingAddress: string;
|
|
529
568
|
swapAndDepositContractAddress: string;
|
|
530
569
|
ethereumSwapperAddress: string;
|
|
531
|
-
smartVaultManagerContractAddress: string
|
|
570
|
+
smartVaultManagerContractAddress: string;
|
|
532
571
|
bridgeMainnetPerqToSonicAddress: string;
|
|
533
572
|
bridgeSonicPerqToMainnetAddress: string;
|
|
534
573
|
};
|
|
@@ -713,6 +752,16 @@ type VestingInfo = {
|
|
|
713
752
|
|
|
714
753
|
type YelayVersion = 'v2' | 'lite';
|
|
715
754
|
|
|
755
|
+
type MigrationOption = {
|
|
756
|
+
projectName: string;
|
|
757
|
+
projectLogo: string;
|
|
758
|
+
onChainProjectId: number;
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
type ProjectHistoricalTvl = {
|
|
762
|
+
[timestamp: number]: number;
|
|
763
|
+
};
|
|
764
|
+
|
|
716
765
|
// Additional Types:
|
|
717
766
|
|
|
718
767
|
type ReducedProjectData = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dripfi/drip-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Drip SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@dripfi/silo-sdk": "0.0.1",
|
|
15
15
|
"@gud/drift-ethers-v5": "1.0.2",
|
|
16
16
|
"@gud/drift": "1.0.2",
|
|
17
|
-
"@yelay-lite/sdk": "2.1.
|
|
17
|
+
"@yelay-lite/sdk": "2.1.2",
|
|
18
18
|
"ethers": "5.8.0"
|
|
19
19
|
},
|
|
20
20
|
"author": "",
|