@zyfai/sdk 0.1.28 → 0.1.30
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 +26 -35
- package/dist/index.d.mts +49 -37
- package/dist/index.d.ts +49 -37
- package/dist/index.js +72 -97
- package/dist/index.mjs +72 -97
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,6 @@ import { ZyfaiSDK } from "@zyfai/sdk";
|
|
|
43
43
|
// Option 1: Full configuration object
|
|
44
44
|
const sdk = new ZyfaiSDK({
|
|
45
45
|
apiKey: "your-api-key",
|
|
46
|
-
environment: "production", // or 'staging' (default: 'production')
|
|
47
46
|
});
|
|
48
47
|
|
|
49
48
|
// Option 2: Simple string initialization (API key only)
|
|
@@ -52,10 +51,9 @@ const sdk = new ZyfaiSDK("your-api-key");
|
|
|
52
51
|
|
|
53
52
|
**Configuration Options:**
|
|
54
53
|
|
|
55
|
-
| Option
|
|
56
|
-
|
|
|
57
|
-
| `apiKey`
|
|
58
|
-
| `environment` | No | `"production"` or `"staging"` (default: `"production"`) |
|
|
54
|
+
| Option | Required | Description |
|
|
55
|
+
| -------- | -------- | ---------------------------------------------------------------------------------------------------- |
|
|
56
|
+
| `apiKey` | Yes | API key for both Execution API and Data API (Safe deployment, transactions, session keys, analytics) |
|
|
59
57
|
|
|
60
58
|
### Connect Account
|
|
61
59
|
|
|
@@ -114,9 +112,12 @@ const walletInfo = await sdk.getSmartWalletAddress(userAddress, 8453);
|
|
|
114
112
|
console.log("Safe Address:", walletInfo.address);
|
|
115
113
|
console.log("Is Deployed:", walletInfo.isDeployed);
|
|
116
114
|
|
|
117
|
-
// Deploy the Safe (automatically checks if already deployed)
|
|
115
|
+
// Deploy the Safe with default safe strategy (automatically checks if already deployed)
|
|
118
116
|
const result = await sdk.deploySafe(userAddress, 8453);
|
|
119
117
|
|
|
118
|
+
// Or deploy with degen strategy (yieldor)
|
|
119
|
+
const degenResult = await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
120
|
+
|
|
120
121
|
if (result.success) {
|
|
121
122
|
console.log("Safe Address:", result.safeAddress);
|
|
122
123
|
console.log("Status:", result.status); // 'deployed' | 'failed'
|
|
@@ -126,6 +127,11 @@ if (result.success) {
|
|
|
126
127
|
|
|
127
128
|
**Note:** The SDK proactively checks if the Safe is already deployed before attempting deployment. If it exists, it returns early without making any transactions.
|
|
128
129
|
|
|
130
|
+
**Strategy Options:**
|
|
131
|
+
|
|
132
|
+
- `"safe_strategy"` (default): Low-risk, stable yield strategy
|
|
133
|
+
- `"degen_strategy"`: High-risk, high-reward strategy (also known as "yieldor" on the frontend)
|
|
134
|
+
|
|
129
135
|
### 2. Multi-Chain Support
|
|
130
136
|
|
|
131
137
|
The SDK supports the following chains:
|
|
@@ -168,7 +174,6 @@ new ZyfaiSDK(config: SDKConfig | string)
|
|
|
168
174
|
- If a string is provided, it's treated as the `apiKey`
|
|
169
175
|
- If an object is provided:
|
|
170
176
|
- `apiKey` (string): Your Zyfai API key (required)
|
|
171
|
-
- `environment` ('production' | 'staging', optional): API environment (default: 'production')
|
|
172
177
|
- `rpcUrls` (object, optional): Custom RPC URLs per chain to avoid rate limiting (optional, only needed for local operations like `getSmartWalletAddress`)
|
|
173
178
|
- `8453` (string, optional): Base Mainnet RPC URL
|
|
174
179
|
- `42161` (string, optional): Arbitrum One RPC URL
|
|
@@ -183,13 +188,11 @@ const sdk = new ZyfaiSDK("your-api-key");
|
|
|
183
188
|
// Option 2: Object initialization (full configuration)
|
|
184
189
|
const sdk = new ZyfaiSDK({
|
|
185
190
|
apiKey: "your-api-key",
|
|
186
|
-
environment: "production",
|
|
187
191
|
});
|
|
188
192
|
|
|
189
193
|
// Option 3: With custom RPC URLs (recommended to avoid rate limiting)
|
|
190
194
|
const sdk = new ZyfaiSDK({
|
|
191
195
|
apiKey: "your-api-key",
|
|
192
|
-
environment: "production",
|
|
193
196
|
rpcUrls: {
|
|
194
197
|
8453: "https://base-mainnet.g.alchemy.com/v2/YOUR_API_KEY", // Base
|
|
195
198
|
42161: "https://arb-mainnet.g.alchemy.com/v2/YOUR_API_KEY", // Arbitrum
|
|
@@ -269,7 +272,7 @@ Get the Smart Wallet (Safe) address for a user.
|
|
|
269
272
|
}
|
|
270
273
|
```
|
|
271
274
|
|
|
272
|
-
##### `deploySafe(userAddress: string, chainId: SupportedChainId): Promise<DeploySafeResponse>`
|
|
275
|
+
##### `deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>`
|
|
273
276
|
|
|
274
277
|
Deploy a Safe smart wallet for a user. **Deployment is handled by the backend API**, which manages all RPC calls and bundler interactions. This avoids rate limiting issues.
|
|
275
278
|
|
|
@@ -277,6 +280,9 @@ Deploy a Safe smart wallet for a user. **Deployment is handled by the backend AP
|
|
|
277
280
|
|
|
278
281
|
- `userAddress`: User's EOA address
|
|
279
282
|
- `chainId`: Target chain ID
|
|
283
|
+
- `strategy`: Optional strategy selection (default: `"safe_strategy"`)
|
|
284
|
+
- `"safe_strategy"`: Low-risk, stable yield strategy (default)
|
|
285
|
+
- `"degen_strategy"`: High-risk, high-reward strategy (also known as "yieldor" on the frontend)
|
|
280
286
|
|
|
281
287
|
**Returns:**
|
|
282
288
|
|
|
@@ -590,25 +596,14 @@ degenStrats.data.forEach((s) => {
|
|
|
590
596
|
});
|
|
591
597
|
```
|
|
592
598
|
|
|
593
|
-
### 11.
|
|
599
|
+
### 11. APY Per Strategy
|
|
594
600
|
|
|
595
|
-
#### Get
|
|
601
|
+
#### Get APY Per Strategy
|
|
596
602
|
|
|
597
603
|
```typescript
|
|
598
604
|
// Get same-chain rebalances
|
|
599
|
-
const
|
|
600
|
-
console.log("
|
|
601
|
-
|
|
602
|
-
// Get cross-chain rebalances
|
|
603
|
-
const crossChain = await sdk.getRebalanceInfo(true);
|
|
604
|
-
```
|
|
605
|
-
|
|
606
|
-
#### Get Rebalance Frequency
|
|
607
|
-
|
|
608
|
-
```typescript
|
|
609
|
-
const frequency = await sdk.getRebalanceFrequency(walletAddress);
|
|
610
|
-
console.log("Tier:", frequency.tier);
|
|
611
|
-
console.log("Max rebalances/day:", frequency.frequency);
|
|
605
|
+
const apyPerStrategy = await sdk.getAPYPerStrategy(false, "7D", "safe");
|
|
606
|
+
console.log("APY per strategy:", apyPerStrategy.data);
|
|
612
607
|
```
|
|
613
608
|
|
|
614
609
|
### 12. SDK API Key Management
|
|
@@ -717,9 +712,12 @@ async function main() {
|
|
|
717
712
|
return;
|
|
718
713
|
}
|
|
719
714
|
|
|
720
|
-
// Deploy Safe
|
|
715
|
+
// Deploy Safe with default safe strategy
|
|
721
716
|
const result = await sdk.deploySafe(userAddress, 8453);
|
|
722
717
|
|
|
718
|
+
// Or deploy with degen strategy (yieldor)
|
|
719
|
+
// const result = await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
720
|
+
|
|
723
721
|
if (result.success) {
|
|
724
722
|
console.log("✅ Successfully deployed Safe");
|
|
725
723
|
console.log("Address:", result.safeAddress);
|
|
@@ -737,13 +735,7 @@ import { ZyfaiSDK } from "@zyfai/sdk";
|
|
|
737
735
|
import { useState } from "react";
|
|
738
736
|
|
|
739
737
|
function SafeDeployment() {
|
|
740
|
-
const [sdk] = useState(
|
|
741
|
-
() =>
|
|
742
|
-
new ZyfaiSDK({
|
|
743
|
-
apiKey: process.env.ZYFAI_API_KEY!,
|
|
744
|
-
bundlerApiKey: process.env.BUNDLER_API_KEY!,
|
|
745
|
-
})
|
|
746
|
-
);
|
|
738
|
+
const [sdk] = useState(() => new ZyfaiSDK(process.env.ZYFAI_API_KEY!));
|
|
747
739
|
|
|
748
740
|
const [userAddress, setUserAddress] = useState<string>("");
|
|
749
741
|
const [safeAddress, setSafeAddress] = useState<string>("");
|
|
@@ -885,8 +877,7 @@ The SDK automatically performs SIWE authentication when you call `connectAccount
|
|
|
885
877
|
If you encounter SIWE authentication failures in a browser, ensure:
|
|
886
878
|
|
|
887
879
|
1. Your frontend origin is allowed by the API's CORS configuration
|
|
888
|
-
2.
|
|
889
|
-
3. The user approves the SIWE signature request in their wallet
|
|
880
|
+
2. The user approves the SIWE signature request in their wallet
|
|
890
881
|
|
|
891
882
|
### Session Key Already Exists
|
|
892
883
|
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import { Chain, PublicClient } from 'viem';
|
|
|
5
5
|
*/
|
|
6
6
|
type Address = `0x${string}`;
|
|
7
7
|
type Hex = `0x${string}`;
|
|
8
|
-
type
|
|
8
|
+
type Strategy = "safe_strategy" | "degen_strategy";
|
|
9
9
|
interface RpcUrlsConfig {
|
|
10
10
|
8453?: string;
|
|
11
11
|
42161?: string;
|
|
@@ -13,7 +13,6 @@ interface RpcUrlsConfig {
|
|
|
13
13
|
}
|
|
14
14
|
interface SDKConfig {
|
|
15
15
|
apiKey: string;
|
|
16
|
-
environment?: Environment;
|
|
17
16
|
rpcUrls?: RpcUrlsConfig;
|
|
18
17
|
}
|
|
19
18
|
interface DeploySafeResponse {
|
|
@@ -158,6 +157,27 @@ interface TVLResponse {
|
|
|
158
157
|
byChain?: Record<number, number>;
|
|
159
158
|
breakdown?: TVLBreakdown[];
|
|
160
159
|
}
|
|
160
|
+
interface APYPerStrategy {
|
|
161
|
+
id: string;
|
|
162
|
+
timestamp: string;
|
|
163
|
+
amount: number;
|
|
164
|
+
fee_threshold: number;
|
|
165
|
+
days: number;
|
|
166
|
+
chain_id: number;
|
|
167
|
+
is_cross_chain: boolean;
|
|
168
|
+
average_apy: number;
|
|
169
|
+
average_apy_with_rzfi: number;
|
|
170
|
+
total_rebalances: number;
|
|
171
|
+
created_at: string;
|
|
172
|
+
strategy: string;
|
|
173
|
+
average_apy_without_fee: number;
|
|
174
|
+
average_apy_with_rzfi_without_fee: number;
|
|
175
|
+
}
|
|
176
|
+
interface APYPerStrategyResponse {
|
|
177
|
+
success: boolean;
|
|
178
|
+
count: number;
|
|
179
|
+
data: APYPerStrategy[];
|
|
180
|
+
}
|
|
161
181
|
interface VolumeResponse {
|
|
162
182
|
success: boolean;
|
|
163
183
|
volumeInUSD: string;
|
|
@@ -310,23 +330,6 @@ interface DailyApyHistoryResponse {
|
|
|
310
330
|
requestedDays?: number;
|
|
311
331
|
averageWeightedApy?: number;
|
|
312
332
|
}
|
|
313
|
-
interface RebalanceInfo {
|
|
314
|
-
id: string;
|
|
315
|
-
timestamp: string;
|
|
316
|
-
fromProtocol?: string;
|
|
317
|
-
toProtocol?: string;
|
|
318
|
-
fromPool?: string;
|
|
319
|
-
toPool?: string;
|
|
320
|
-
amount?: string;
|
|
321
|
-
isCrossChain: boolean;
|
|
322
|
-
fromChainId?: number;
|
|
323
|
-
toChainId?: number;
|
|
324
|
-
}
|
|
325
|
-
interface RebalanceInfoResponse {
|
|
326
|
-
success: boolean;
|
|
327
|
-
data: RebalanceInfo[];
|
|
328
|
-
count: number;
|
|
329
|
-
}
|
|
330
333
|
interface RebalanceFrequencyResponse {
|
|
331
334
|
success: boolean;
|
|
332
335
|
walletAddress: string;
|
|
@@ -413,7 +416,6 @@ declare class ZyfaiSDK {
|
|
|
413
416
|
private walletClient;
|
|
414
417
|
private authenticatedUserId;
|
|
415
418
|
private hasActiveSessionKey;
|
|
416
|
-
private environment;
|
|
417
419
|
private currentProvider;
|
|
418
420
|
private currentChainId;
|
|
419
421
|
private rpcUrls?;
|
|
@@ -511,9 +513,19 @@ declare class ZyfaiSDK {
|
|
|
511
513
|
*
|
|
512
514
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
513
515
|
* @param chainId - Target chain ID
|
|
516
|
+
* @param strategy - Optional strategy selection: "safe_strategy" (default) or "degen_strategy" (yieldor)
|
|
514
517
|
* @returns Deployment response with Safe address and transaction hash
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```typescript
|
|
521
|
+
* // Deploy with default safe strategy
|
|
522
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
523
|
+
*
|
|
524
|
+
* // Deploy with degen strategy (yieldor)
|
|
525
|
+
* await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
526
|
+
* ```
|
|
515
527
|
*/
|
|
516
|
-
deploySafe(userAddress: string, chainId: SupportedChainId): Promise<DeploySafeResponse>;
|
|
528
|
+
deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>;
|
|
517
529
|
/**
|
|
518
530
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
519
531
|
* This is the simplified method that automatically fetches session configuration
|
|
@@ -660,6 +672,21 @@ declare class ZyfaiSDK {
|
|
|
660
672
|
* ```
|
|
661
673
|
*/
|
|
662
674
|
getTVL(): Promise<TVLResponse>;
|
|
675
|
+
/**
|
|
676
|
+
* Get APY per strategy for a specific chain
|
|
677
|
+
*
|
|
678
|
+
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
679
|
+
* @param days - Time period: "7D", "14D", or "30D"
|
|
680
|
+
* @param strategyType - Strategy type: "safe" or "degen"
|
|
681
|
+
* @returns APY per strategy for a specific chain
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```typescript
|
|
685
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, "7D", "safe");
|
|
686
|
+
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
getAPYPerStrategy(crossChain?: boolean, days?: string, strategyType?: string): Promise<APYPerStrategyResponse>;
|
|
663
690
|
/**
|
|
664
691
|
* Get total volume across all Zyfai accounts
|
|
665
692
|
*
|
|
@@ -828,21 +855,6 @@ declare class ZyfaiSDK {
|
|
|
828
855
|
* ```
|
|
829
856
|
*/
|
|
830
857
|
getDailyApyHistory(walletAddress: string, days?: "7D" | "14D" | "30D"): Promise<DailyApyHistoryResponse>;
|
|
831
|
-
/**
|
|
832
|
-
* Get rebalance information
|
|
833
|
-
* Shows yield generated by rebalancing strategies
|
|
834
|
-
*
|
|
835
|
-
* @param isCrossChain - Filter by cross-chain or same-chain rebalances
|
|
836
|
-
* @returns List of rebalance events
|
|
837
|
-
*
|
|
838
|
-
* @example
|
|
839
|
-
* ```typescript
|
|
840
|
-
* // Get same-chain rebalance info
|
|
841
|
-
* const rebalances = await sdk.getRebalanceInfo(false);
|
|
842
|
-
* console.log("Rebalance count:", rebalances.count);
|
|
843
|
-
* ```
|
|
844
|
-
*/
|
|
845
|
-
getRebalanceInfo(isCrossChain?: boolean): Promise<RebalanceInfoResponse>;
|
|
846
858
|
/**
|
|
847
859
|
* Get rebalance frequency/tier for a wallet
|
|
848
860
|
* Determines how often the wallet can be rebalanced based on tier
|
|
@@ -860,4 +872,4 @@ declare class ZyfaiSDK {
|
|
|
860
872
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
861
873
|
}
|
|
862
874
|
|
|
863
|
-
export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type
|
|
875
|
+
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type SDKConfig, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Chain, PublicClient } from 'viem';
|
|
|
5
5
|
*/
|
|
6
6
|
type Address = `0x${string}`;
|
|
7
7
|
type Hex = `0x${string}`;
|
|
8
|
-
type
|
|
8
|
+
type Strategy = "safe_strategy" | "degen_strategy";
|
|
9
9
|
interface RpcUrlsConfig {
|
|
10
10
|
8453?: string;
|
|
11
11
|
42161?: string;
|
|
@@ -13,7 +13,6 @@ interface RpcUrlsConfig {
|
|
|
13
13
|
}
|
|
14
14
|
interface SDKConfig {
|
|
15
15
|
apiKey: string;
|
|
16
|
-
environment?: Environment;
|
|
17
16
|
rpcUrls?: RpcUrlsConfig;
|
|
18
17
|
}
|
|
19
18
|
interface DeploySafeResponse {
|
|
@@ -158,6 +157,27 @@ interface TVLResponse {
|
|
|
158
157
|
byChain?: Record<number, number>;
|
|
159
158
|
breakdown?: TVLBreakdown[];
|
|
160
159
|
}
|
|
160
|
+
interface APYPerStrategy {
|
|
161
|
+
id: string;
|
|
162
|
+
timestamp: string;
|
|
163
|
+
amount: number;
|
|
164
|
+
fee_threshold: number;
|
|
165
|
+
days: number;
|
|
166
|
+
chain_id: number;
|
|
167
|
+
is_cross_chain: boolean;
|
|
168
|
+
average_apy: number;
|
|
169
|
+
average_apy_with_rzfi: number;
|
|
170
|
+
total_rebalances: number;
|
|
171
|
+
created_at: string;
|
|
172
|
+
strategy: string;
|
|
173
|
+
average_apy_without_fee: number;
|
|
174
|
+
average_apy_with_rzfi_without_fee: number;
|
|
175
|
+
}
|
|
176
|
+
interface APYPerStrategyResponse {
|
|
177
|
+
success: boolean;
|
|
178
|
+
count: number;
|
|
179
|
+
data: APYPerStrategy[];
|
|
180
|
+
}
|
|
161
181
|
interface VolumeResponse {
|
|
162
182
|
success: boolean;
|
|
163
183
|
volumeInUSD: string;
|
|
@@ -310,23 +330,6 @@ interface DailyApyHistoryResponse {
|
|
|
310
330
|
requestedDays?: number;
|
|
311
331
|
averageWeightedApy?: number;
|
|
312
332
|
}
|
|
313
|
-
interface RebalanceInfo {
|
|
314
|
-
id: string;
|
|
315
|
-
timestamp: string;
|
|
316
|
-
fromProtocol?: string;
|
|
317
|
-
toProtocol?: string;
|
|
318
|
-
fromPool?: string;
|
|
319
|
-
toPool?: string;
|
|
320
|
-
amount?: string;
|
|
321
|
-
isCrossChain: boolean;
|
|
322
|
-
fromChainId?: number;
|
|
323
|
-
toChainId?: number;
|
|
324
|
-
}
|
|
325
|
-
interface RebalanceInfoResponse {
|
|
326
|
-
success: boolean;
|
|
327
|
-
data: RebalanceInfo[];
|
|
328
|
-
count: number;
|
|
329
|
-
}
|
|
330
333
|
interface RebalanceFrequencyResponse {
|
|
331
334
|
success: boolean;
|
|
332
335
|
walletAddress: string;
|
|
@@ -413,7 +416,6 @@ declare class ZyfaiSDK {
|
|
|
413
416
|
private walletClient;
|
|
414
417
|
private authenticatedUserId;
|
|
415
418
|
private hasActiveSessionKey;
|
|
416
|
-
private environment;
|
|
417
419
|
private currentProvider;
|
|
418
420
|
private currentChainId;
|
|
419
421
|
private rpcUrls?;
|
|
@@ -511,9 +513,19 @@ declare class ZyfaiSDK {
|
|
|
511
513
|
*
|
|
512
514
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
513
515
|
* @param chainId - Target chain ID
|
|
516
|
+
* @param strategy - Optional strategy selection: "safe_strategy" (default) or "degen_strategy" (yieldor)
|
|
514
517
|
* @returns Deployment response with Safe address and transaction hash
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```typescript
|
|
521
|
+
* // Deploy with default safe strategy
|
|
522
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
523
|
+
*
|
|
524
|
+
* // Deploy with degen strategy (yieldor)
|
|
525
|
+
* await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
526
|
+
* ```
|
|
515
527
|
*/
|
|
516
|
-
deploySafe(userAddress: string, chainId: SupportedChainId): Promise<DeploySafeResponse>;
|
|
528
|
+
deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>;
|
|
517
529
|
/**
|
|
518
530
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
519
531
|
* This is the simplified method that automatically fetches session configuration
|
|
@@ -660,6 +672,21 @@ declare class ZyfaiSDK {
|
|
|
660
672
|
* ```
|
|
661
673
|
*/
|
|
662
674
|
getTVL(): Promise<TVLResponse>;
|
|
675
|
+
/**
|
|
676
|
+
* Get APY per strategy for a specific chain
|
|
677
|
+
*
|
|
678
|
+
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
679
|
+
* @param days - Time period: "7D", "14D", or "30D"
|
|
680
|
+
* @param strategyType - Strategy type: "safe" or "degen"
|
|
681
|
+
* @returns APY per strategy for a specific chain
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```typescript
|
|
685
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, "7D", "safe");
|
|
686
|
+
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
getAPYPerStrategy(crossChain?: boolean, days?: string, strategyType?: string): Promise<APYPerStrategyResponse>;
|
|
663
690
|
/**
|
|
664
691
|
* Get total volume across all Zyfai accounts
|
|
665
692
|
*
|
|
@@ -828,21 +855,6 @@ declare class ZyfaiSDK {
|
|
|
828
855
|
* ```
|
|
829
856
|
*/
|
|
830
857
|
getDailyApyHistory(walletAddress: string, days?: "7D" | "14D" | "30D"): Promise<DailyApyHistoryResponse>;
|
|
831
|
-
/**
|
|
832
|
-
* Get rebalance information
|
|
833
|
-
* Shows yield generated by rebalancing strategies
|
|
834
|
-
*
|
|
835
|
-
* @param isCrossChain - Filter by cross-chain or same-chain rebalances
|
|
836
|
-
* @returns List of rebalance events
|
|
837
|
-
*
|
|
838
|
-
* @example
|
|
839
|
-
* ```typescript
|
|
840
|
-
* // Get same-chain rebalance info
|
|
841
|
-
* const rebalances = await sdk.getRebalanceInfo(false);
|
|
842
|
-
* console.log("Rebalance count:", rebalances.count);
|
|
843
|
-
* ```
|
|
844
|
-
*/
|
|
845
|
-
getRebalanceInfo(isCrossChain?: boolean): Promise<RebalanceInfoResponse>;
|
|
846
858
|
/**
|
|
847
859
|
* Get rebalance frequency/tier for a wallet
|
|
848
860
|
* Determines how often the wallet can be rebalanced based on tier
|
|
@@ -860,4 +872,4 @@ declare class ZyfaiSDK {
|
|
|
860
872
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
861
873
|
}
|
|
862
874
|
|
|
863
|
-
export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type
|
|
875
|
+
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type SDKConfig, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
package/dist/index.js
CHANGED
|
@@ -43,14 +43,8 @@ module.exports = __toCommonJS(index_exports);
|
|
|
43
43
|
var import_axios = __toESM(require("axios"));
|
|
44
44
|
|
|
45
45
|
// src/config/endpoints.ts
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
production: "https://api.zyf.ai"
|
|
49
|
-
};
|
|
50
|
-
var DATA_API_ENDPOINTS = {
|
|
51
|
-
staging: "https://staging-defiapi.zyf.ai",
|
|
52
|
-
production: "https://defiapi.zyf.ai"
|
|
53
|
-
};
|
|
46
|
+
var API_ENDPOINT = "https://api.zyf.ai";
|
|
47
|
+
var DATA_API_ENDPOINT = "https://defiapi.zyf.ai";
|
|
54
48
|
var API_VERSION = "/api/v1";
|
|
55
49
|
var DATA_API_VERSION = "/api/v2";
|
|
56
50
|
var ENDPOINTS = {
|
|
@@ -98,7 +92,9 @@ var DATA_ENDPOINTS = {
|
|
|
98
92
|
// APY History
|
|
99
93
|
DAILY_APY_HISTORY_WEIGHTED: (walletAddress, days) => `/daily-apy-history/weighted/${walletAddress}${days ? `?days=${days}` : ""}`,
|
|
100
94
|
// Rebalance
|
|
101
|
-
REBALANCE_INFO: (isCrossChain) => isCrossChain !== void 0 ? `/rebalance/rebalance-info?isCrossChain=${isCrossChain}` : "/rebalance/rebalance-info"
|
|
95
|
+
REBALANCE_INFO: (isCrossChain) => isCrossChain !== void 0 ? `/rebalance/rebalance-info?isCrossChain=${isCrossChain}` : "/rebalance/rebalance-info",
|
|
96
|
+
// APY Per Strategy
|
|
97
|
+
APY_PER_STRATEGY: (isCrossChain = false, days = "7D", strategyType = "safe") => `/rebalance/rebalance-info?isCrossChain=${isCrossChain}&days=${days}&strategyType=${strategyType}`
|
|
102
98
|
};
|
|
103
99
|
|
|
104
100
|
// src/utils/http-client.ts
|
|
@@ -107,27 +103,23 @@ var HttpClient = class {
|
|
|
107
103
|
* Create HTTP client for both Execution API and Data API
|
|
108
104
|
*
|
|
109
105
|
* @param apiKey - API key for both Execution API and Data API
|
|
110
|
-
* @param environment - 'staging' or 'production'
|
|
111
106
|
*/
|
|
112
|
-
constructor(apiKey
|
|
107
|
+
constructor(apiKey) {
|
|
113
108
|
this.authToken = null;
|
|
114
109
|
this.apiKey = apiKey;
|
|
115
|
-
|
|
116
|
-
const endpoint = API_ENDPOINTS[environment];
|
|
117
|
-
const parsedUrl = new URL(endpoint);
|
|
110
|
+
const parsedUrl = new URL(API_ENDPOINT);
|
|
118
111
|
this.origin = parsedUrl.origin;
|
|
119
112
|
this.host = parsedUrl.host;
|
|
120
113
|
this.client = import_axios.default.create({
|
|
121
|
-
baseURL: `${
|
|
114
|
+
baseURL: `${API_ENDPOINT}${API_VERSION}`,
|
|
122
115
|
headers: {
|
|
123
116
|
"Content-Type": "application/json",
|
|
124
117
|
"X-API-Key": this.apiKey
|
|
125
118
|
},
|
|
126
119
|
timeout: 3e4
|
|
127
120
|
});
|
|
128
|
-
const dataEndpoint = DATA_API_ENDPOINTS[environment];
|
|
129
121
|
this.dataClient = import_axios.default.create({
|
|
130
|
-
baseURL: `${
|
|
122
|
+
baseURL: `${DATA_API_ENDPOINT}${DATA_API_VERSION}`,
|
|
131
123
|
headers: {
|
|
132
124
|
"Content-Type": "application/json",
|
|
133
125
|
"X-API-Key": this.apiKey
|
|
@@ -226,7 +218,7 @@ var HttpClient = class {
|
|
|
226
218
|
* @param config - Additional axios config
|
|
227
219
|
*/
|
|
228
220
|
async dataPostCustom(path, data, config) {
|
|
229
|
-
const fullUrl = `${
|
|
221
|
+
const fullUrl = `${DATA_API_ENDPOINT}${path}`;
|
|
230
222
|
const headers = {
|
|
231
223
|
"Content-Type": "application/json",
|
|
232
224
|
"X-API-Key": this.apiKey,
|
|
@@ -443,18 +435,9 @@ var import_viem3 = require("viem");
|
|
|
443
435
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
444
436
|
var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
445
437
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
446
|
-
var
|
|
447
|
-
staging: "zyfai-staging",
|
|
448
|
-
production: "zyfai"
|
|
449
|
-
};
|
|
438
|
+
var ACCOUNT_SALT = "zyfai";
|
|
450
439
|
var getSafeAccount = async (config) => {
|
|
451
|
-
const {
|
|
452
|
-
owner,
|
|
453
|
-
safeOwnerAddress,
|
|
454
|
-
publicClient,
|
|
455
|
-
environment = "production"
|
|
456
|
-
} = config;
|
|
457
|
-
const effectiveSalt = ACCOUNT_SALTS[environment];
|
|
440
|
+
const { owner, safeOwnerAddress, publicClient } = config;
|
|
458
441
|
if (!owner || !owner.account) {
|
|
459
442
|
throw new Error("Wallet not connected. Please connect your wallet first.");
|
|
460
443
|
}
|
|
@@ -478,7 +461,7 @@ var getSafeAccount = async (config) => {
|
|
|
478
461
|
// Use formatted effective owner address for validator
|
|
479
462
|
threshold: 1
|
|
480
463
|
});
|
|
481
|
-
const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(
|
|
464
|
+
const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(ACCOUNT_SALT), "bigint");
|
|
482
465
|
const tempOwner = {
|
|
483
466
|
address: formattedEffectiveAddress,
|
|
484
467
|
type: "json-rpc"
|
|
@@ -557,14 +540,15 @@ var getAccountType = async (address, publicClient) => {
|
|
|
557
540
|
};
|
|
558
541
|
var deploySafeAccount = async (config) => {
|
|
559
542
|
try {
|
|
560
|
-
const { owner, httpClient, chainId } = config;
|
|
543
|
+
const { owner, httpClient, chainId, strategy = "safe_strategy" } = config;
|
|
561
544
|
if (!owner || !owner.account) {
|
|
562
545
|
throw new Error(
|
|
563
546
|
"Wallet not connected. Please connect your wallet first."
|
|
564
547
|
);
|
|
565
548
|
}
|
|
566
549
|
const prepareResponse = await httpClient.post(
|
|
567
|
-
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}
|
|
550
|
+
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
551
|
+
{ strategy }
|
|
568
552
|
);
|
|
569
553
|
if (!prepareResponse.userOpHashToSign) {
|
|
570
554
|
throw new Error(
|
|
@@ -578,7 +562,7 @@ var deploySafeAccount = async (config) => {
|
|
|
578
562
|
});
|
|
579
563
|
const deployResponse = await httpClient.post(
|
|
580
564
|
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
581
|
-
{ userOpSignature }
|
|
565
|
+
{ userOpSignature, strategy }
|
|
582
566
|
);
|
|
583
567
|
if (!deployResponse.success) {
|
|
584
568
|
throw new Error(
|
|
@@ -651,12 +635,11 @@ var ZyfaiSDK = class {
|
|
|
651
635
|
this.currentProvider = null;
|
|
652
636
|
this.currentChainId = null;
|
|
653
637
|
const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
|
|
654
|
-
const { apiKey,
|
|
638
|
+
const { apiKey, rpcUrls } = sdkConfig;
|
|
655
639
|
if (!apiKey) {
|
|
656
640
|
throw new Error("API key is required");
|
|
657
641
|
}
|
|
658
|
-
this.
|
|
659
|
-
this.httpClient = new HttpClient(apiKey, this.environment);
|
|
642
|
+
this.httpClient = new HttpClient(apiKey);
|
|
660
643
|
this.rpcUrls = rpcUrls;
|
|
661
644
|
}
|
|
662
645
|
/**
|
|
@@ -683,8 +666,8 @@ var ZyfaiSDK = class {
|
|
|
683
666
|
uri = globalWindow.location.origin;
|
|
684
667
|
domain = globalWindow.location.host;
|
|
685
668
|
} else {
|
|
686
|
-
uri =
|
|
687
|
-
domain =
|
|
669
|
+
uri = API_ENDPOINT;
|
|
670
|
+
domain = API_ENDPOINT.split("//")[1];
|
|
688
671
|
}
|
|
689
672
|
const messageObj = new import_siwe.SiweMessage({
|
|
690
673
|
address: userAddress,
|
|
@@ -1006,8 +989,7 @@ var ZyfaiSDK = class {
|
|
|
1006
989
|
owner: walletClient,
|
|
1007
990
|
safeOwnerAddress: userAddress,
|
|
1008
991
|
chain: chainConfig.chain,
|
|
1009
|
-
publicClient: chainConfig.publicClient
|
|
1010
|
-
environment: this.environment
|
|
992
|
+
publicClient: chainConfig.publicClient
|
|
1011
993
|
});
|
|
1012
994
|
const isDeployed = await isSafeDeployed(
|
|
1013
995
|
safeAddress,
|
|
@@ -1023,9 +1005,19 @@ var ZyfaiSDK = class {
|
|
|
1023
1005
|
*
|
|
1024
1006
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
1025
1007
|
* @param chainId - Target chain ID
|
|
1008
|
+
* @param strategy - Optional strategy selection: "safe_strategy" (default) or "degen_strategy" (yieldor)
|
|
1026
1009
|
* @returns Deployment response with Safe address and transaction hash
|
|
1010
|
+
*
|
|
1011
|
+
* @example
|
|
1012
|
+
* ```typescript
|
|
1013
|
+
* // Deploy with default safe strategy
|
|
1014
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
1015
|
+
*
|
|
1016
|
+
* // Deploy with degen strategy (yieldor)
|
|
1017
|
+
* await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
1018
|
+
* ```
|
|
1027
1019
|
*/
|
|
1028
|
-
async deploySafe(userAddress, chainId) {
|
|
1020
|
+
async deploySafe(userAddress, chainId, strategy) {
|
|
1029
1021
|
try {
|
|
1030
1022
|
if (!userAddress) {
|
|
1031
1023
|
throw new Error("User address is required");
|
|
@@ -1040,8 +1032,7 @@ var ZyfaiSDK = class {
|
|
|
1040
1032
|
owner: walletClient,
|
|
1041
1033
|
safeOwnerAddress: userAddress,
|
|
1042
1034
|
chain: chainConfig.chain,
|
|
1043
|
-
publicClient: chainConfig.publicClient
|
|
1044
|
-
environment: this.environment
|
|
1035
|
+
publicClient: chainConfig.publicClient
|
|
1045
1036
|
});
|
|
1046
1037
|
const alreadyDeployed = await isSafeDeployed(
|
|
1047
1038
|
safeAddress,
|
|
@@ -1071,9 +1062,9 @@ var ZyfaiSDK = class {
|
|
|
1071
1062
|
safeOwnerAddress: userAddress,
|
|
1072
1063
|
chain: chainConfig.chain,
|
|
1073
1064
|
publicClient: chainConfig.publicClient,
|
|
1074
|
-
environment: this.environment,
|
|
1075
1065
|
chainId,
|
|
1076
|
-
httpClient: this.httpClient
|
|
1066
|
+
httpClient: this.httpClient,
|
|
1067
|
+
strategy: strategy || "safe_strategy"
|
|
1077
1068
|
});
|
|
1078
1069
|
try {
|
|
1079
1070
|
await this.initializeUser(deploymentResult.safeAddress, chainId);
|
|
@@ -1216,8 +1207,7 @@ var ZyfaiSDK = class {
|
|
|
1216
1207
|
owner: walletClient,
|
|
1217
1208
|
safeOwnerAddress: userAddress,
|
|
1218
1209
|
chain: chainConfig.chain,
|
|
1219
|
-
publicClient: chainConfig.publicClient
|
|
1220
|
-
environment: this.environment
|
|
1210
|
+
publicClient: chainConfig.publicClient
|
|
1221
1211
|
},
|
|
1222
1212
|
sessions,
|
|
1223
1213
|
allPublicClients,
|
|
@@ -1227,8 +1217,7 @@ var ZyfaiSDK = class {
|
|
|
1227
1217
|
owner: walletClient,
|
|
1228
1218
|
safeOwnerAddress: userAddress,
|
|
1229
1219
|
chain: chainConfig.chain,
|
|
1230
|
-
publicClient: chainConfig.publicClient
|
|
1231
|
-
environment: this.environment
|
|
1220
|
+
publicClient: chainConfig.publicClient
|
|
1232
1221
|
});
|
|
1233
1222
|
return {
|
|
1234
1223
|
success: true,
|
|
@@ -1338,8 +1327,7 @@ var ZyfaiSDK = class {
|
|
|
1338
1327
|
owner: walletClient,
|
|
1339
1328
|
safeOwnerAddress: userAddress,
|
|
1340
1329
|
chain: chainConfig.chain,
|
|
1341
|
-
publicClient: chainConfig.publicClient
|
|
1342
|
-
environment: this.environment
|
|
1330
|
+
publicClient: chainConfig.publicClient
|
|
1343
1331
|
});
|
|
1344
1332
|
const isDeployed = await isSafeDeployed(
|
|
1345
1333
|
safeAddress,
|
|
@@ -1420,8 +1408,7 @@ var ZyfaiSDK = class {
|
|
|
1420
1408
|
owner: walletClient,
|
|
1421
1409
|
safeOwnerAddress: userAddress,
|
|
1422
1410
|
chain: chainConfig.chain,
|
|
1423
|
-
publicClient: chainConfig.publicClient
|
|
1424
|
-
environment: this.environment
|
|
1411
|
+
publicClient: chainConfig.publicClient
|
|
1425
1412
|
});
|
|
1426
1413
|
}
|
|
1427
1414
|
} catch {
|
|
@@ -1430,8 +1417,7 @@ var ZyfaiSDK = class {
|
|
|
1430
1417
|
owner: walletClient,
|
|
1431
1418
|
safeOwnerAddress: userAddress,
|
|
1432
1419
|
chain: chainConfig.chain,
|
|
1433
|
-
publicClient: chainConfig.publicClient
|
|
1434
|
-
environment: this.environment
|
|
1420
|
+
publicClient: chainConfig.publicClient
|
|
1435
1421
|
});
|
|
1436
1422
|
}
|
|
1437
1423
|
const isDeployed = await isSafeDeployed(
|
|
@@ -1628,6 +1614,37 @@ var ZyfaiSDK = class {
|
|
|
1628
1614
|
throw new Error(`Failed to get TVL: ${error.message}`);
|
|
1629
1615
|
}
|
|
1630
1616
|
}
|
|
1617
|
+
// ============================================================================
|
|
1618
|
+
// APY Per Strategy Methods
|
|
1619
|
+
// ============================================================================
|
|
1620
|
+
/**
|
|
1621
|
+
* Get APY per strategy for a specific chain
|
|
1622
|
+
*
|
|
1623
|
+
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
1624
|
+
* @param days - Time period: "7D", "14D", or "30D"
|
|
1625
|
+
* @param strategyType - Strategy type: "safe" or "degen"
|
|
1626
|
+
* @returns APY per strategy for a specific chain
|
|
1627
|
+
*
|
|
1628
|
+
* @example
|
|
1629
|
+
* ```typescript
|
|
1630
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, "7D", "safe");
|
|
1631
|
+
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
1632
|
+
* ```
|
|
1633
|
+
*/
|
|
1634
|
+
async getAPYPerStrategy(crossChain = false, days = "7D", strategyType = "safe") {
|
|
1635
|
+
try {
|
|
1636
|
+
const response = await this.httpClient.dataGet(DATA_ENDPOINTS.APY_PER_STRATEGY(crossChain, days, strategyType));
|
|
1637
|
+
return {
|
|
1638
|
+
success: true,
|
|
1639
|
+
count: response.count || 0,
|
|
1640
|
+
data: response.data || []
|
|
1641
|
+
};
|
|
1642
|
+
} catch (error) {
|
|
1643
|
+
throw new Error(
|
|
1644
|
+
`Failed to get APY per strategy: ${error.message}`
|
|
1645
|
+
);
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1631
1648
|
/**
|
|
1632
1649
|
* Get total volume across all Zyfai accounts
|
|
1633
1650
|
*
|
|
@@ -2086,48 +2103,6 @@ var ZyfaiSDK = class {
|
|
|
2086
2103
|
// ============================================================================
|
|
2087
2104
|
// Rebalance Methods
|
|
2088
2105
|
// ============================================================================
|
|
2089
|
-
/**
|
|
2090
|
-
* Get rebalance information
|
|
2091
|
-
* Shows yield generated by rebalancing strategies
|
|
2092
|
-
*
|
|
2093
|
-
* @param isCrossChain - Filter by cross-chain or same-chain rebalances
|
|
2094
|
-
* @returns List of rebalance events
|
|
2095
|
-
*
|
|
2096
|
-
* @example
|
|
2097
|
-
* ```typescript
|
|
2098
|
-
* // Get same-chain rebalance info
|
|
2099
|
-
* const rebalances = await sdk.getRebalanceInfo(false);
|
|
2100
|
-
* console.log("Rebalance count:", rebalances.count);
|
|
2101
|
-
* ```
|
|
2102
|
-
*/
|
|
2103
|
-
async getRebalanceInfo(isCrossChain) {
|
|
2104
|
-
try {
|
|
2105
|
-
const response = await this.httpClient.dataGet(
|
|
2106
|
-
DATA_ENDPOINTS.REBALANCE_INFO(isCrossChain)
|
|
2107
|
-
);
|
|
2108
|
-
const data = response.data || response || [];
|
|
2109
|
-
return {
|
|
2110
|
-
success: true,
|
|
2111
|
-
data: Array.isArray(data) ? data.map((r) => ({
|
|
2112
|
-
id: r.id,
|
|
2113
|
-
timestamp: r.timestamp || r.created_at,
|
|
2114
|
-
fromProtocol: r.from_protocol || r.fromProtocol,
|
|
2115
|
-
toProtocol: r.to_protocol || r.toProtocol,
|
|
2116
|
-
fromPool: r.from_pool || r.fromPool,
|
|
2117
|
-
toPool: r.to_pool || r.toPool,
|
|
2118
|
-
amount: r.amount,
|
|
2119
|
-
isCrossChain: r.is_cross_chain ?? r.isCrossChain ?? false,
|
|
2120
|
-
fromChainId: r.from_chain_id || r.fromChainId,
|
|
2121
|
-
toChainId: r.to_chain_id || r.toChainId
|
|
2122
|
-
})) : [],
|
|
2123
|
-
count: data.length
|
|
2124
|
-
};
|
|
2125
|
-
} catch (error) {
|
|
2126
|
-
throw new Error(
|
|
2127
|
-
`Failed to get rebalance info: ${error.message}`
|
|
2128
|
-
);
|
|
2129
|
-
}
|
|
2130
|
-
}
|
|
2131
2106
|
/**
|
|
2132
2107
|
* Get rebalance frequency/tier for a wallet
|
|
2133
2108
|
* Determines how often the wallet can be rebalanced based on tier
|
package/dist/index.mjs
CHANGED
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
|
|
4
4
|
// src/config/endpoints.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
production: "https://api.zyf.ai"
|
|
8
|
-
};
|
|
9
|
-
var DATA_API_ENDPOINTS = {
|
|
10
|
-
staging: "https://staging-defiapi.zyf.ai",
|
|
11
|
-
production: "https://defiapi.zyf.ai"
|
|
12
|
-
};
|
|
5
|
+
var API_ENDPOINT = "https://api.zyf.ai";
|
|
6
|
+
var DATA_API_ENDPOINT = "https://defiapi.zyf.ai";
|
|
13
7
|
var API_VERSION = "/api/v1";
|
|
14
8
|
var DATA_API_VERSION = "/api/v2";
|
|
15
9
|
var ENDPOINTS = {
|
|
@@ -57,7 +51,9 @@ var DATA_ENDPOINTS = {
|
|
|
57
51
|
// APY History
|
|
58
52
|
DAILY_APY_HISTORY_WEIGHTED: (walletAddress, days) => `/daily-apy-history/weighted/${walletAddress}${days ? `?days=${days}` : ""}`,
|
|
59
53
|
// Rebalance
|
|
60
|
-
REBALANCE_INFO: (isCrossChain) => isCrossChain !== void 0 ? `/rebalance/rebalance-info?isCrossChain=${isCrossChain}` : "/rebalance/rebalance-info"
|
|
54
|
+
REBALANCE_INFO: (isCrossChain) => isCrossChain !== void 0 ? `/rebalance/rebalance-info?isCrossChain=${isCrossChain}` : "/rebalance/rebalance-info",
|
|
55
|
+
// APY Per Strategy
|
|
56
|
+
APY_PER_STRATEGY: (isCrossChain = false, days = "7D", strategyType = "safe") => `/rebalance/rebalance-info?isCrossChain=${isCrossChain}&days=${days}&strategyType=${strategyType}`
|
|
61
57
|
};
|
|
62
58
|
|
|
63
59
|
// src/utils/http-client.ts
|
|
@@ -66,27 +62,23 @@ var HttpClient = class {
|
|
|
66
62
|
* Create HTTP client for both Execution API and Data API
|
|
67
63
|
*
|
|
68
64
|
* @param apiKey - API key for both Execution API and Data API
|
|
69
|
-
* @param environment - 'staging' or 'production'
|
|
70
65
|
*/
|
|
71
|
-
constructor(apiKey
|
|
66
|
+
constructor(apiKey) {
|
|
72
67
|
this.authToken = null;
|
|
73
68
|
this.apiKey = apiKey;
|
|
74
|
-
|
|
75
|
-
const endpoint = API_ENDPOINTS[environment];
|
|
76
|
-
const parsedUrl = new URL(endpoint);
|
|
69
|
+
const parsedUrl = new URL(API_ENDPOINT);
|
|
77
70
|
this.origin = parsedUrl.origin;
|
|
78
71
|
this.host = parsedUrl.host;
|
|
79
72
|
this.client = axios.create({
|
|
80
|
-
baseURL: `${
|
|
73
|
+
baseURL: `${API_ENDPOINT}${API_VERSION}`,
|
|
81
74
|
headers: {
|
|
82
75
|
"Content-Type": "application/json",
|
|
83
76
|
"X-API-Key": this.apiKey
|
|
84
77
|
},
|
|
85
78
|
timeout: 3e4
|
|
86
79
|
});
|
|
87
|
-
const dataEndpoint = DATA_API_ENDPOINTS[environment];
|
|
88
80
|
this.dataClient = axios.create({
|
|
89
|
-
baseURL: `${
|
|
81
|
+
baseURL: `${DATA_API_ENDPOINT}${DATA_API_VERSION}`,
|
|
90
82
|
headers: {
|
|
91
83
|
"Content-Type": "application/json",
|
|
92
84
|
"X-API-Key": this.apiKey
|
|
@@ -185,7 +177,7 @@ var HttpClient = class {
|
|
|
185
177
|
* @param config - Additional axios config
|
|
186
178
|
*/
|
|
187
179
|
async dataPostCustom(path, data, config) {
|
|
188
|
-
const fullUrl = `${
|
|
180
|
+
const fullUrl = `${DATA_API_ENDPOINT}${path}`;
|
|
189
181
|
const headers = {
|
|
190
182
|
"Content-Type": "application/json",
|
|
191
183
|
"X-API-Key": this.apiKey,
|
|
@@ -420,18 +412,9 @@ import {
|
|
|
420
412
|
} from "viem/account-abstraction";
|
|
421
413
|
var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
422
414
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
423
|
-
var
|
|
424
|
-
staging: "zyfai-staging",
|
|
425
|
-
production: "zyfai"
|
|
426
|
-
};
|
|
415
|
+
var ACCOUNT_SALT = "zyfai";
|
|
427
416
|
var getSafeAccount = async (config) => {
|
|
428
|
-
const {
|
|
429
|
-
owner,
|
|
430
|
-
safeOwnerAddress,
|
|
431
|
-
publicClient,
|
|
432
|
-
environment = "production"
|
|
433
|
-
} = config;
|
|
434
|
-
const effectiveSalt = ACCOUNT_SALTS[environment];
|
|
417
|
+
const { owner, safeOwnerAddress, publicClient } = config;
|
|
435
418
|
if (!owner || !owner.account) {
|
|
436
419
|
throw new Error("Wallet not connected. Please connect your wallet first.");
|
|
437
420
|
}
|
|
@@ -455,7 +438,7 @@ var getSafeAccount = async (config) => {
|
|
|
455
438
|
// Use formatted effective owner address for validator
|
|
456
439
|
threshold: 1
|
|
457
440
|
});
|
|
458
|
-
const saltHex = fromHex(toHex(
|
|
441
|
+
const saltHex = fromHex(toHex(ACCOUNT_SALT), "bigint");
|
|
459
442
|
const tempOwner = {
|
|
460
443
|
address: formattedEffectiveAddress,
|
|
461
444
|
type: "json-rpc"
|
|
@@ -534,14 +517,15 @@ var getAccountType = async (address, publicClient) => {
|
|
|
534
517
|
};
|
|
535
518
|
var deploySafeAccount = async (config) => {
|
|
536
519
|
try {
|
|
537
|
-
const { owner, httpClient, chainId } = config;
|
|
520
|
+
const { owner, httpClient, chainId, strategy = "safe_strategy" } = config;
|
|
538
521
|
if (!owner || !owner.account) {
|
|
539
522
|
throw new Error(
|
|
540
523
|
"Wallet not connected. Please connect your wallet first."
|
|
541
524
|
);
|
|
542
525
|
}
|
|
543
526
|
const prepareResponse = await httpClient.post(
|
|
544
|
-
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}
|
|
527
|
+
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
528
|
+
{ strategy }
|
|
545
529
|
);
|
|
546
530
|
if (!prepareResponse.userOpHashToSign) {
|
|
547
531
|
throw new Error(
|
|
@@ -555,7 +539,7 @@ var deploySafeAccount = async (config) => {
|
|
|
555
539
|
});
|
|
556
540
|
const deployResponse = await httpClient.post(
|
|
557
541
|
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
558
|
-
{ userOpSignature }
|
|
542
|
+
{ userOpSignature, strategy }
|
|
559
543
|
);
|
|
560
544
|
if (!deployResponse.success) {
|
|
561
545
|
throw new Error(
|
|
@@ -628,12 +612,11 @@ var ZyfaiSDK = class {
|
|
|
628
612
|
this.currentProvider = null;
|
|
629
613
|
this.currentChainId = null;
|
|
630
614
|
const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
|
|
631
|
-
const { apiKey,
|
|
615
|
+
const { apiKey, rpcUrls } = sdkConfig;
|
|
632
616
|
if (!apiKey) {
|
|
633
617
|
throw new Error("API key is required");
|
|
634
618
|
}
|
|
635
|
-
this.
|
|
636
|
-
this.httpClient = new HttpClient(apiKey, this.environment);
|
|
619
|
+
this.httpClient = new HttpClient(apiKey);
|
|
637
620
|
this.rpcUrls = rpcUrls;
|
|
638
621
|
}
|
|
639
622
|
/**
|
|
@@ -660,8 +643,8 @@ var ZyfaiSDK = class {
|
|
|
660
643
|
uri = globalWindow.location.origin;
|
|
661
644
|
domain = globalWindow.location.host;
|
|
662
645
|
} else {
|
|
663
|
-
uri =
|
|
664
|
-
domain =
|
|
646
|
+
uri = API_ENDPOINT;
|
|
647
|
+
domain = API_ENDPOINT.split("//")[1];
|
|
665
648
|
}
|
|
666
649
|
const messageObj = new SiweMessage({
|
|
667
650
|
address: userAddress,
|
|
@@ -983,8 +966,7 @@ var ZyfaiSDK = class {
|
|
|
983
966
|
owner: walletClient,
|
|
984
967
|
safeOwnerAddress: userAddress,
|
|
985
968
|
chain: chainConfig.chain,
|
|
986
|
-
publicClient: chainConfig.publicClient
|
|
987
|
-
environment: this.environment
|
|
969
|
+
publicClient: chainConfig.publicClient
|
|
988
970
|
});
|
|
989
971
|
const isDeployed = await isSafeDeployed(
|
|
990
972
|
safeAddress,
|
|
@@ -1000,9 +982,19 @@ var ZyfaiSDK = class {
|
|
|
1000
982
|
*
|
|
1001
983
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
1002
984
|
* @param chainId - Target chain ID
|
|
985
|
+
* @param strategy - Optional strategy selection: "safe_strategy" (default) or "degen_strategy" (yieldor)
|
|
1003
986
|
* @returns Deployment response with Safe address and transaction hash
|
|
987
|
+
*
|
|
988
|
+
* @example
|
|
989
|
+
* ```typescript
|
|
990
|
+
* // Deploy with default safe strategy
|
|
991
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
992
|
+
*
|
|
993
|
+
* // Deploy with degen strategy (yieldor)
|
|
994
|
+
* await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
995
|
+
* ```
|
|
1004
996
|
*/
|
|
1005
|
-
async deploySafe(userAddress, chainId) {
|
|
997
|
+
async deploySafe(userAddress, chainId, strategy) {
|
|
1006
998
|
try {
|
|
1007
999
|
if (!userAddress) {
|
|
1008
1000
|
throw new Error("User address is required");
|
|
@@ -1017,8 +1009,7 @@ var ZyfaiSDK = class {
|
|
|
1017
1009
|
owner: walletClient,
|
|
1018
1010
|
safeOwnerAddress: userAddress,
|
|
1019
1011
|
chain: chainConfig.chain,
|
|
1020
|
-
publicClient: chainConfig.publicClient
|
|
1021
|
-
environment: this.environment
|
|
1012
|
+
publicClient: chainConfig.publicClient
|
|
1022
1013
|
});
|
|
1023
1014
|
const alreadyDeployed = await isSafeDeployed(
|
|
1024
1015
|
safeAddress,
|
|
@@ -1048,9 +1039,9 @@ var ZyfaiSDK = class {
|
|
|
1048
1039
|
safeOwnerAddress: userAddress,
|
|
1049
1040
|
chain: chainConfig.chain,
|
|
1050
1041
|
publicClient: chainConfig.publicClient,
|
|
1051
|
-
environment: this.environment,
|
|
1052
1042
|
chainId,
|
|
1053
|
-
httpClient: this.httpClient
|
|
1043
|
+
httpClient: this.httpClient,
|
|
1044
|
+
strategy: strategy || "safe_strategy"
|
|
1054
1045
|
});
|
|
1055
1046
|
try {
|
|
1056
1047
|
await this.initializeUser(deploymentResult.safeAddress, chainId);
|
|
@@ -1193,8 +1184,7 @@ var ZyfaiSDK = class {
|
|
|
1193
1184
|
owner: walletClient,
|
|
1194
1185
|
safeOwnerAddress: userAddress,
|
|
1195
1186
|
chain: chainConfig.chain,
|
|
1196
|
-
publicClient: chainConfig.publicClient
|
|
1197
|
-
environment: this.environment
|
|
1187
|
+
publicClient: chainConfig.publicClient
|
|
1198
1188
|
},
|
|
1199
1189
|
sessions,
|
|
1200
1190
|
allPublicClients,
|
|
@@ -1204,8 +1194,7 @@ var ZyfaiSDK = class {
|
|
|
1204
1194
|
owner: walletClient,
|
|
1205
1195
|
safeOwnerAddress: userAddress,
|
|
1206
1196
|
chain: chainConfig.chain,
|
|
1207
|
-
publicClient: chainConfig.publicClient
|
|
1208
|
-
environment: this.environment
|
|
1197
|
+
publicClient: chainConfig.publicClient
|
|
1209
1198
|
});
|
|
1210
1199
|
return {
|
|
1211
1200
|
success: true,
|
|
@@ -1315,8 +1304,7 @@ var ZyfaiSDK = class {
|
|
|
1315
1304
|
owner: walletClient,
|
|
1316
1305
|
safeOwnerAddress: userAddress,
|
|
1317
1306
|
chain: chainConfig.chain,
|
|
1318
|
-
publicClient: chainConfig.publicClient
|
|
1319
|
-
environment: this.environment
|
|
1307
|
+
publicClient: chainConfig.publicClient
|
|
1320
1308
|
});
|
|
1321
1309
|
const isDeployed = await isSafeDeployed(
|
|
1322
1310
|
safeAddress,
|
|
@@ -1397,8 +1385,7 @@ var ZyfaiSDK = class {
|
|
|
1397
1385
|
owner: walletClient,
|
|
1398
1386
|
safeOwnerAddress: userAddress,
|
|
1399
1387
|
chain: chainConfig.chain,
|
|
1400
|
-
publicClient: chainConfig.publicClient
|
|
1401
|
-
environment: this.environment
|
|
1388
|
+
publicClient: chainConfig.publicClient
|
|
1402
1389
|
});
|
|
1403
1390
|
}
|
|
1404
1391
|
} catch {
|
|
@@ -1407,8 +1394,7 @@ var ZyfaiSDK = class {
|
|
|
1407
1394
|
owner: walletClient,
|
|
1408
1395
|
safeOwnerAddress: userAddress,
|
|
1409
1396
|
chain: chainConfig.chain,
|
|
1410
|
-
publicClient: chainConfig.publicClient
|
|
1411
|
-
environment: this.environment
|
|
1397
|
+
publicClient: chainConfig.publicClient
|
|
1412
1398
|
});
|
|
1413
1399
|
}
|
|
1414
1400
|
const isDeployed = await isSafeDeployed(
|
|
@@ -1605,6 +1591,37 @@ var ZyfaiSDK = class {
|
|
|
1605
1591
|
throw new Error(`Failed to get TVL: ${error.message}`);
|
|
1606
1592
|
}
|
|
1607
1593
|
}
|
|
1594
|
+
// ============================================================================
|
|
1595
|
+
// APY Per Strategy Methods
|
|
1596
|
+
// ============================================================================
|
|
1597
|
+
/**
|
|
1598
|
+
* Get APY per strategy for a specific chain
|
|
1599
|
+
*
|
|
1600
|
+
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
1601
|
+
* @param days - Time period: "7D", "14D", or "30D"
|
|
1602
|
+
* @param strategyType - Strategy type: "safe" or "degen"
|
|
1603
|
+
* @returns APY per strategy for a specific chain
|
|
1604
|
+
*
|
|
1605
|
+
* @example
|
|
1606
|
+
* ```typescript
|
|
1607
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, "7D", "safe");
|
|
1608
|
+
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
1609
|
+
* ```
|
|
1610
|
+
*/
|
|
1611
|
+
async getAPYPerStrategy(crossChain = false, days = "7D", strategyType = "safe") {
|
|
1612
|
+
try {
|
|
1613
|
+
const response = await this.httpClient.dataGet(DATA_ENDPOINTS.APY_PER_STRATEGY(crossChain, days, strategyType));
|
|
1614
|
+
return {
|
|
1615
|
+
success: true,
|
|
1616
|
+
count: response.count || 0,
|
|
1617
|
+
data: response.data || []
|
|
1618
|
+
};
|
|
1619
|
+
} catch (error) {
|
|
1620
|
+
throw new Error(
|
|
1621
|
+
`Failed to get APY per strategy: ${error.message}`
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1608
1625
|
/**
|
|
1609
1626
|
* Get total volume across all Zyfai accounts
|
|
1610
1627
|
*
|
|
@@ -2063,48 +2080,6 @@ var ZyfaiSDK = class {
|
|
|
2063
2080
|
// ============================================================================
|
|
2064
2081
|
// Rebalance Methods
|
|
2065
2082
|
// ============================================================================
|
|
2066
|
-
/**
|
|
2067
|
-
* Get rebalance information
|
|
2068
|
-
* Shows yield generated by rebalancing strategies
|
|
2069
|
-
*
|
|
2070
|
-
* @param isCrossChain - Filter by cross-chain or same-chain rebalances
|
|
2071
|
-
* @returns List of rebalance events
|
|
2072
|
-
*
|
|
2073
|
-
* @example
|
|
2074
|
-
* ```typescript
|
|
2075
|
-
* // Get same-chain rebalance info
|
|
2076
|
-
* const rebalances = await sdk.getRebalanceInfo(false);
|
|
2077
|
-
* console.log("Rebalance count:", rebalances.count);
|
|
2078
|
-
* ```
|
|
2079
|
-
*/
|
|
2080
|
-
async getRebalanceInfo(isCrossChain) {
|
|
2081
|
-
try {
|
|
2082
|
-
const response = await this.httpClient.dataGet(
|
|
2083
|
-
DATA_ENDPOINTS.REBALANCE_INFO(isCrossChain)
|
|
2084
|
-
);
|
|
2085
|
-
const data = response.data || response || [];
|
|
2086
|
-
return {
|
|
2087
|
-
success: true,
|
|
2088
|
-
data: Array.isArray(data) ? data.map((r) => ({
|
|
2089
|
-
id: r.id,
|
|
2090
|
-
timestamp: r.timestamp || r.created_at,
|
|
2091
|
-
fromProtocol: r.from_protocol || r.fromProtocol,
|
|
2092
|
-
toProtocol: r.to_protocol || r.toProtocol,
|
|
2093
|
-
fromPool: r.from_pool || r.fromPool,
|
|
2094
|
-
toPool: r.to_pool || r.toPool,
|
|
2095
|
-
amount: r.amount,
|
|
2096
|
-
isCrossChain: r.is_cross_chain ?? r.isCrossChain ?? false,
|
|
2097
|
-
fromChainId: r.from_chain_id || r.fromChainId,
|
|
2098
|
-
toChainId: r.to_chain_id || r.toChainId
|
|
2099
|
-
})) : [],
|
|
2100
|
-
count: data.length
|
|
2101
|
-
};
|
|
2102
|
-
} catch (error) {
|
|
2103
|
-
throw new Error(
|
|
2104
|
-
`Failed to get rebalance info: ${error.message}`
|
|
2105
|
-
);
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
2083
|
/**
|
|
2109
2084
|
* Get rebalance frequency/tier for a wallet
|
|
2110
2085
|
* Determines how often the wallet can be rebalanced based on tier
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"description": "TypeScript SDK for Zyfai Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|