@zyfai/sdk 0.1.28 → 0.1.29
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 +22 -20
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +38 -54
- package/dist/index.mjs +38 -54
- 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
|
|
|
@@ -717,9 +723,12 @@ async function main() {
|
|
|
717
723
|
return;
|
|
718
724
|
}
|
|
719
725
|
|
|
720
|
-
// Deploy Safe
|
|
726
|
+
// Deploy Safe with default safe strategy
|
|
721
727
|
const result = await sdk.deploySafe(userAddress, 8453);
|
|
722
728
|
|
|
729
|
+
// Or deploy with degen strategy (yieldor)
|
|
730
|
+
// const result = await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
731
|
+
|
|
723
732
|
if (result.success) {
|
|
724
733
|
console.log("✅ Successfully deployed Safe");
|
|
725
734
|
console.log("Address:", result.safeAddress);
|
|
@@ -737,13 +746,7 @@ import { ZyfaiSDK } from "@zyfai/sdk";
|
|
|
737
746
|
import { useState } from "react";
|
|
738
747
|
|
|
739
748
|
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
|
-
);
|
|
749
|
+
const [sdk] = useState(() => new ZyfaiSDK(process.env.ZYFAI_API_KEY!));
|
|
747
750
|
|
|
748
751
|
const [userAddress, setUserAddress] = useState<string>("");
|
|
749
752
|
const [safeAddress, setSafeAddress] = useState<string>("");
|
|
@@ -885,8 +888,7 @@ The SDK automatically performs SIWE authentication when you call `connectAccount
|
|
|
885
888
|
If you encounter SIWE authentication failures in a browser, ensure:
|
|
886
889
|
|
|
887
890
|
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
|
|
891
|
+
2. The user approves the SIWE signature request in their wallet
|
|
890
892
|
|
|
891
893
|
### Session Key Already Exists
|
|
892
894
|
|
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 {
|
|
@@ -413,7 +412,6 @@ declare class ZyfaiSDK {
|
|
|
413
412
|
private walletClient;
|
|
414
413
|
private authenticatedUserId;
|
|
415
414
|
private hasActiveSessionKey;
|
|
416
|
-
private environment;
|
|
417
415
|
private currentProvider;
|
|
418
416
|
private currentChainId;
|
|
419
417
|
private rpcUrls?;
|
|
@@ -511,9 +509,19 @@ declare class ZyfaiSDK {
|
|
|
511
509
|
*
|
|
512
510
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
513
511
|
* @param chainId - Target chain ID
|
|
512
|
+
* @param strategy - Optional strategy selection: "safe_strategy" (default) or "degen_strategy" (yieldor)
|
|
514
513
|
* @returns Deployment response with Safe address and transaction hash
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```typescript
|
|
517
|
+
* // Deploy with default safe strategy
|
|
518
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
519
|
+
*
|
|
520
|
+
* // Deploy with degen strategy (yieldor)
|
|
521
|
+
* await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
522
|
+
* ```
|
|
515
523
|
*/
|
|
516
|
-
deploySafe(userAddress: string, chainId: SupportedChainId): Promise<DeploySafeResponse>;
|
|
524
|
+
deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>;
|
|
517
525
|
/**
|
|
518
526
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
519
527
|
* This is the simplified method that automatically fetches session configuration
|
|
@@ -860,4 +868,4 @@ declare class ZyfaiSDK {
|
|
|
860
868
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
861
869
|
}
|
|
862
870
|
|
|
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
|
|
871
|
+
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 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 RebalanceInfo, type RebalanceInfoResponse, 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 {
|
|
@@ -413,7 +412,6 @@ declare class ZyfaiSDK {
|
|
|
413
412
|
private walletClient;
|
|
414
413
|
private authenticatedUserId;
|
|
415
414
|
private hasActiveSessionKey;
|
|
416
|
-
private environment;
|
|
417
415
|
private currentProvider;
|
|
418
416
|
private currentChainId;
|
|
419
417
|
private rpcUrls?;
|
|
@@ -511,9 +509,19 @@ declare class ZyfaiSDK {
|
|
|
511
509
|
*
|
|
512
510
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
513
511
|
* @param chainId - Target chain ID
|
|
512
|
+
* @param strategy - Optional strategy selection: "safe_strategy" (default) or "degen_strategy" (yieldor)
|
|
514
513
|
* @returns Deployment response with Safe address and transaction hash
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```typescript
|
|
517
|
+
* // Deploy with default safe strategy
|
|
518
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
519
|
+
*
|
|
520
|
+
* // Deploy with degen strategy (yieldor)
|
|
521
|
+
* await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
522
|
+
* ```
|
|
515
523
|
*/
|
|
516
|
-
deploySafe(userAddress: string, chainId: SupportedChainId): Promise<DeploySafeResponse>;
|
|
524
|
+
deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>;
|
|
517
525
|
/**
|
|
518
526
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
519
527
|
* This is the simplified method that automatically fetches session configuration
|
|
@@ -860,4 +868,4 @@ declare class ZyfaiSDK {
|
|
|
860
868
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
861
869
|
}
|
|
862
870
|
|
|
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
|
|
871
|
+
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 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 RebalanceInfo, type RebalanceInfoResponse, 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 = {
|
|
@@ -107,27 +101,23 @@ var HttpClient = class {
|
|
|
107
101
|
* Create HTTP client for both Execution API and Data API
|
|
108
102
|
*
|
|
109
103
|
* @param apiKey - API key for both Execution API and Data API
|
|
110
|
-
* @param environment - 'staging' or 'production'
|
|
111
104
|
*/
|
|
112
|
-
constructor(apiKey
|
|
105
|
+
constructor(apiKey) {
|
|
113
106
|
this.authToken = null;
|
|
114
107
|
this.apiKey = apiKey;
|
|
115
|
-
|
|
116
|
-
const endpoint = API_ENDPOINTS[environment];
|
|
117
|
-
const parsedUrl = new URL(endpoint);
|
|
108
|
+
const parsedUrl = new URL(API_ENDPOINT);
|
|
118
109
|
this.origin = parsedUrl.origin;
|
|
119
110
|
this.host = parsedUrl.host;
|
|
120
111
|
this.client = import_axios.default.create({
|
|
121
|
-
baseURL: `${
|
|
112
|
+
baseURL: `${API_ENDPOINT}${API_VERSION}`,
|
|
122
113
|
headers: {
|
|
123
114
|
"Content-Type": "application/json",
|
|
124
115
|
"X-API-Key": this.apiKey
|
|
125
116
|
},
|
|
126
117
|
timeout: 3e4
|
|
127
118
|
});
|
|
128
|
-
const dataEndpoint = DATA_API_ENDPOINTS[environment];
|
|
129
119
|
this.dataClient = import_axios.default.create({
|
|
130
|
-
baseURL: `${
|
|
120
|
+
baseURL: `${DATA_API_ENDPOINT}${DATA_API_VERSION}`,
|
|
131
121
|
headers: {
|
|
132
122
|
"Content-Type": "application/json",
|
|
133
123
|
"X-API-Key": this.apiKey
|
|
@@ -226,7 +216,7 @@ var HttpClient = class {
|
|
|
226
216
|
* @param config - Additional axios config
|
|
227
217
|
*/
|
|
228
218
|
async dataPostCustom(path, data, config) {
|
|
229
|
-
const fullUrl = `${
|
|
219
|
+
const fullUrl = `${DATA_API_ENDPOINT}${path}`;
|
|
230
220
|
const headers = {
|
|
231
221
|
"Content-Type": "application/json",
|
|
232
222
|
"X-API-Key": this.apiKey,
|
|
@@ -443,18 +433,9 @@ var import_viem3 = require("viem");
|
|
|
443
433
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
444
434
|
var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
445
435
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
446
|
-
var
|
|
447
|
-
staging: "zyfai-staging",
|
|
448
|
-
production: "zyfai"
|
|
449
|
-
};
|
|
436
|
+
var ACCOUNT_SALT = "zyfai";
|
|
450
437
|
var getSafeAccount = async (config) => {
|
|
451
|
-
const {
|
|
452
|
-
owner,
|
|
453
|
-
safeOwnerAddress,
|
|
454
|
-
publicClient,
|
|
455
|
-
environment = "production"
|
|
456
|
-
} = config;
|
|
457
|
-
const effectiveSalt = ACCOUNT_SALTS[environment];
|
|
438
|
+
const { owner, safeOwnerAddress, publicClient } = config;
|
|
458
439
|
if (!owner || !owner.account) {
|
|
459
440
|
throw new Error("Wallet not connected. Please connect your wallet first.");
|
|
460
441
|
}
|
|
@@ -478,7 +459,7 @@ var getSafeAccount = async (config) => {
|
|
|
478
459
|
// Use formatted effective owner address for validator
|
|
479
460
|
threshold: 1
|
|
480
461
|
});
|
|
481
|
-
const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(
|
|
462
|
+
const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(ACCOUNT_SALT), "bigint");
|
|
482
463
|
const tempOwner = {
|
|
483
464
|
address: formattedEffectiveAddress,
|
|
484
465
|
type: "json-rpc"
|
|
@@ -557,14 +538,15 @@ var getAccountType = async (address, publicClient) => {
|
|
|
557
538
|
};
|
|
558
539
|
var deploySafeAccount = async (config) => {
|
|
559
540
|
try {
|
|
560
|
-
const { owner, httpClient, chainId } = config;
|
|
541
|
+
const { owner, httpClient, chainId, strategy = "safe_strategy" } = config;
|
|
561
542
|
if (!owner || !owner.account) {
|
|
562
543
|
throw new Error(
|
|
563
544
|
"Wallet not connected. Please connect your wallet first."
|
|
564
545
|
);
|
|
565
546
|
}
|
|
566
547
|
const prepareResponse = await httpClient.post(
|
|
567
|
-
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}
|
|
548
|
+
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
549
|
+
{ strategy }
|
|
568
550
|
);
|
|
569
551
|
if (!prepareResponse.userOpHashToSign) {
|
|
570
552
|
throw new Error(
|
|
@@ -578,7 +560,7 @@ var deploySafeAccount = async (config) => {
|
|
|
578
560
|
});
|
|
579
561
|
const deployResponse = await httpClient.post(
|
|
580
562
|
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
581
|
-
{ userOpSignature }
|
|
563
|
+
{ userOpSignature, strategy }
|
|
582
564
|
);
|
|
583
565
|
if (!deployResponse.success) {
|
|
584
566
|
throw new Error(
|
|
@@ -651,12 +633,11 @@ var ZyfaiSDK = class {
|
|
|
651
633
|
this.currentProvider = null;
|
|
652
634
|
this.currentChainId = null;
|
|
653
635
|
const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
|
|
654
|
-
const { apiKey,
|
|
636
|
+
const { apiKey, rpcUrls } = sdkConfig;
|
|
655
637
|
if (!apiKey) {
|
|
656
638
|
throw new Error("API key is required");
|
|
657
639
|
}
|
|
658
|
-
this.
|
|
659
|
-
this.httpClient = new HttpClient(apiKey, this.environment);
|
|
640
|
+
this.httpClient = new HttpClient(apiKey);
|
|
660
641
|
this.rpcUrls = rpcUrls;
|
|
661
642
|
}
|
|
662
643
|
/**
|
|
@@ -683,8 +664,8 @@ var ZyfaiSDK = class {
|
|
|
683
664
|
uri = globalWindow.location.origin;
|
|
684
665
|
domain = globalWindow.location.host;
|
|
685
666
|
} else {
|
|
686
|
-
uri =
|
|
687
|
-
domain =
|
|
667
|
+
uri = API_ENDPOINT;
|
|
668
|
+
domain = API_ENDPOINT.split("//")[1];
|
|
688
669
|
}
|
|
689
670
|
const messageObj = new import_siwe.SiweMessage({
|
|
690
671
|
address: userAddress,
|
|
@@ -1006,8 +987,7 @@ var ZyfaiSDK = class {
|
|
|
1006
987
|
owner: walletClient,
|
|
1007
988
|
safeOwnerAddress: userAddress,
|
|
1008
989
|
chain: chainConfig.chain,
|
|
1009
|
-
publicClient: chainConfig.publicClient
|
|
1010
|
-
environment: this.environment
|
|
990
|
+
publicClient: chainConfig.publicClient
|
|
1011
991
|
});
|
|
1012
992
|
const isDeployed = await isSafeDeployed(
|
|
1013
993
|
safeAddress,
|
|
@@ -1023,9 +1003,19 @@ var ZyfaiSDK = class {
|
|
|
1023
1003
|
*
|
|
1024
1004
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
1025
1005
|
* @param chainId - Target chain ID
|
|
1006
|
+
* @param strategy - Optional strategy selection: "safe_strategy" (default) or "degen_strategy" (yieldor)
|
|
1026
1007
|
* @returns Deployment response with Safe address and transaction hash
|
|
1008
|
+
*
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```typescript
|
|
1011
|
+
* // Deploy with default safe strategy
|
|
1012
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
1013
|
+
*
|
|
1014
|
+
* // Deploy with degen strategy (yieldor)
|
|
1015
|
+
* await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
1016
|
+
* ```
|
|
1027
1017
|
*/
|
|
1028
|
-
async deploySafe(userAddress, chainId) {
|
|
1018
|
+
async deploySafe(userAddress, chainId, strategy) {
|
|
1029
1019
|
try {
|
|
1030
1020
|
if (!userAddress) {
|
|
1031
1021
|
throw new Error("User address is required");
|
|
@@ -1040,8 +1030,7 @@ var ZyfaiSDK = class {
|
|
|
1040
1030
|
owner: walletClient,
|
|
1041
1031
|
safeOwnerAddress: userAddress,
|
|
1042
1032
|
chain: chainConfig.chain,
|
|
1043
|
-
publicClient: chainConfig.publicClient
|
|
1044
|
-
environment: this.environment
|
|
1033
|
+
publicClient: chainConfig.publicClient
|
|
1045
1034
|
});
|
|
1046
1035
|
const alreadyDeployed = await isSafeDeployed(
|
|
1047
1036
|
safeAddress,
|
|
@@ -1071,9 +1060,9 @@ var ZyfaiSDK = class {
|
|
|
1071
1060
|
safeOwnerAddress: userAddress,
|
|
1072
1061
|
chain: chainConfig.chain,
|
|
1073
1062
|
publicClient: chainConfig.publicClient,
|
|
1074
|
-
environment: this.environment,
|
|
1075
1063
|
chainId,
|
|
1076
|
-
httpClient: this.httpClient
|
|
1064
|
+
httpClient: this.httpClient,
|
|
1065
|
+
strategy: strategy || "safe_strategy"
|
|
1077
1066
|
});
|
|
1078
1067
|
try {
|
|
1079
1068
|
await this.initializeUser(deploymentResult.safeAddress, chainId);
|
|
@@ -1216,8 +1205,7 @@ var ZyfaiSDK = class {
|
|
|
1216
1205
|
owner: walletClient,
|
|
1217
1206
|
safeOwnerAddress: userAddress,
|
|
1218
1207
|
chain: chainConfig.chain,
|
|
1219
|
-
publicClient: chainConfig.publicClient
|
|
1220
|
-
environment: this.environment
|
|
1208
|
+
publicClient: chainConfig.publicClient
|
|
1221
1209
|
},
|
|
1222
1210
|
sessions,
|
|
1223
1211
|
allPublicClients,
|
|
@@ -1227,8 +1215,7 @@ var ZyfaiSDK = class {
|
|
|
1227
1215
|
owner: walletClient,
|
|
1228
1216
|
safeOwnerAddress: userAddress,
|
|
1229
1217
|
chain: chainConfig.chain,
|
|
1230
|
-
publicClient: chainConfig.publicClient
|
|
1231
|
-
environment: this.environment
|
|
1218
|
+
publicClient: chainConfig.publicClient
|
|
1232
1219
|
});
|
|
1233
1220
|
return {
|
|
1234
1221
|
success: true,
|
|
@@ -1338,8 +1325,7 @@ var ZyfaiSDK = class {
|
|
|
1338
1325
|
owner: walletClient,
|
|
1339
1326
|
safeOwnerAddress: userAddress,
|
|
1340
1327
|
chain: chainConfig.chain,
|
|
1341
|
-
publicClient: chainConfig.publicClient
|
|
1342
|
-
environment: this.environment
|
|
1328
|
+
publicClient: chainConfig.publicClient
|
|
1343
1329
|
});
|
|
1344
1330
|
const isDeployed = await isSafeDeployed(
|
|
1345
1331
|
safeAddress,
|
|
@@ -1420,8 +1406,7 @@ var ZyfaiSDK = class {
|
|
|
1420
1406
|
owner: walletClient,
|
|
1421
1407
|
safeOwnerAddress: userAddress,
|
|
1422
1408
|
chain: chainConfig.chain,
|
|
1423
|
-
publicClient: chainConfig.publicClient
|
|
1424
|
-
environment: this.environment
|
|
1409
|
+
publicClient: chainConfig.publicClient
|
|
1425
1410
|
});
|
|
1426
1411
|
}
|
|
1427
1412
|
} catch {
|
|
@@ -1430,8 +1415,7 @@ var ZyfaiSDK = class {
|
|
|
1430
1415
|
owner: walletClient,
|
|
1431
1416
|
safeOwnerAddress: userAddress,
|
|
1432
1417
|
chain: chainConfig.chain,
|
|
1433
|
-
publicClient: chainConfig.publicClient
|
|
1434
|
-
environment: this.environment
|
|
1418
|
+
publicClient: chainConfig.publicClient
|
|
1435
1419
|
});
|
|
1436
1420
|
}
|
|
1437
1421
|
const isDeployed = await isSafeDeployed(
|
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 = {
|
|
@@ -66,27 +60,23 @@ var HttpClient = class {
|
|
|
66
60
|
* Create HTTP client for both Execution API and Data API
|
|
67
61
|
*
|
|
68
62
|
* @param apiKey - API key for both Execution API and Data API
|
|
69
|
-
* @param environment - 'staging' or 'production'
|
|
70
63
|
*/
|
|
71
|
-
constructor(apiKey
|
|
64
|
+
constructor(apiKey) {
|
|
72
65
|
this.authToken = null;
|
|
73
66
|
this.apiKey = apiKey;
|
|
74
|
-
|
|
75
|
-
const endpoint = API_ENDPOINTS[environment];
|
|
76
|
-
const parsedUrl = new URL(endpoint);
|
|
67
|
+
const parsedUrl = new URL(API_ENDPOINT);
|
|
77
68
|
this.origin = parsedUrl.origin;
|
|
78
69
|
this.host = parsedUrl.host;
|
|
79
70
|
this.client = axios.create({
|
|
80
|
-
baseURL: `${
|
|
71
|
+
baseURL: `${API_ENDPOINT}${API_VERSION}`,
|
|
81
72
|
headers: {
|
|
82
73
|
"Content-Type": "application/json",
|
|
83
74
|
"X-API-Key": this.apiKey
|
|
84
75
|
},
|
|
85
76
|
timeout: 3e4
|
|
86
77
|
});
|
|
87
|
-
const dataEndpoint = DATA_API_ENDPOINTS[environment];
|
|
88
78
|
this.dataClient = axios.create({
|
|
89
|
-
baseURL: `${
|
|
79
|
+
baseURL: `${DATA_API_ENDPOINT}${DATA_API_VERSION}`,
|
|
90
80
|
headers: {
|
|
91
81
|
"Content-Type": "application/json",
|
|
92
82
|
"X-API-Key": this.apiKey
|
|
@@ -185,7 +175,7 @@ var HttpClient = class {
|
|
|
185
175
|
* @param config - Additional axios config
|
|
186
176
|
*/
|
|
187
177
|
async dataPostCustom(path, data, config) {
|
|
188
|
-
const fullUrl = `${
|
|
178
|
+
const fullUrl = `${DATA_API_ENDPOINT}${path}`;
|
|
189
179
|
const headers = {
|
|
190
180
|
"Content-Type": "application/json",
|
|
191
181
|
"X-API-Key": this.apiKey,
|
|
@@ -420,18 +410,9 @@ import {
|
|
|
420
410
|
} from "viem/account-abstraction";
|
|
421
411
|
var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
422
412
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
423
|
-
var
|
|
424
|
-
staging: "zyfai-staging",
|
|
425
|
-
production: "zyfai"
|
|
426
|
-
};
|
|
413
|
+
var ACCOUNT_SALT = "zyfai";
|
|
427
414
|
var getSafeAccount = async (config) => {
|
|
428
|
-
const {
|
|
429
|
-
owner,
|
|
430
|
-
safeOwnerAddress,
|
|
431
|
-
publicClient,
|
|
432
|
-
environment = "production"
|
|
433
|
-
} = config;
|
|
434
|
-
const effectiveSalt = ACCOUNT_SALTS[environment];
|
|
415
|
+
const { owner, safeOwnerAddress, publicClient } = config;
|
|
435
416
|
if (!owner || !owner.account) {
|
|
436
417
|
throw new Error("Wallet not connected. Please connect your wallet first.");
|
|
437
418
|
}
|
|
@@ -455,7 +436,7 @@ var getSafeAccount = async (config) => {
|
|
|
455
436
|
// Use formatted effective owner address for validator
|
|
456
437
|
threshold: 1
|
|
457
438
|
});
|
|
458
|
-
const saltHex = fromHex(toHex(
|
|
439
|
+
const saltHex = fromHex(toHex(ACCOUNT_SALT), "bigint");
|
|
459
440
|
const tempOwner = {
|
|
460
441
|
address: formattedEffectiveAddress,
|
|
461
442
|
type: "json-rpc"
|
|
@@ -534,14 +515,15 @@ var getAccountType = async (address, publicClient) => {
|
|
|
534
515
|
};
|
|
535
516
|
var deploySafeAccount = async (config) => {
|
|
536
517
|
try {
|
|
537
|
-
const { owner, httpClient, chainId } = config;
|
|
518
|
+
const { owner, httpClient, chainId, strategy = "safe_strategy" } = config;
|
|
538
519
|
if (!owner || !owner.account) {
|
|
539
520
|
throw new Error(
|
|
540
521
|
"Wallet not connected. Please connect your wallet first."
|
|
541
522
|
);
|
|
542
523
|
}
|
|
543
524
|
const prepareResponse = await httpClient.post(
|
|
544
|
-
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}
|
|
525
|
+
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
526
|
+
{ strategy }
|
|
545
527
|
);
|
|
546
528
|
if (!prepareResponse.userOpHashToSign) {
|
|
547
529
|
throw new Error(
|
|
@@ -555,7 +537,7 @@ var deploySafeAccount = async (config) => {
|
|
|
555
537
|
});
|
|
556
538
|
const deployResponse = await httpClient.post(
|
|
557
539
|
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
558
|
-
{ userOpSignature }
|
|
540
|
+
{ userOpSignature, strategy }
|
|
559
541
|
);
|
|
560
542
|
if (!deployResponse.success) {
|
|
561
543
|
throw new Error(
|
|
@@ -628,12 +610,11 @@ var ZyfaiSDK = class {
|
|
|
628
610
|
this.currentProvider = null;
|
|
629
611
|
this.currentChainId = null;
|
|
630
612
|
const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
|
|
631
|
-
const { apiKey,
|
|
613
|
+
const { apiKey, rpcUrls } = sdkConfig;
|
|
632
614
|
if (!apiKey) {
|
|
633
615
|
throw new Error("API key is required");
|
|
634
616
|
}
|
|
635
|
-
this.
|
|
636
|
-
this.httpClient = new HttpClient(apiKey, this.environment);
|
|
617
|
+
this.httpClient = new HttpClient(apiKey);
|
|
637
618
|
this.rpcUrls = rpcUrls;
|
|
638
619
|
}
|
|
639
620
|
/**
|
|
@@ -660,8 +641,8 @@ var ZyfaiSDK = class {
|
|
|
660
641
|
uri = globalWindow.location.origin;
|
|
661
642
|
domain = globalWindow.location.host;
|
|
662
643
|
} else {
|
|
663
|
-
uri =
|
|
664
|
-
domain =
|
|
644
|
+
uri = API_ENDPOINT;
|
|
645
|
+
domain = API_ENDPOINT.split("//")[1];
|
|
665
646
|
}
|
|
666
647
|
const messageObj = new SiweMessage({
|
|
667
648
|
address: userAddress,
|
|
@@ -983,8 +964,7 @@ var ZyfaiSDK = class {
|
|
|
983
964
|
owner: walletClient,
|
|
984
965
|
safeOwnerAddress: userAddress,
|
|
985
966
|
chain: chainConfig.chain,
|
|
986
|
-
publicClient: chainConfig.publicClient
|
|
987
|
-
environment: this.environment
|
|
967
|
+
publicClient: chainConfig.publicClient
|
|
988
968
|
});
|
|
989
969
|
const isDeployed = await isSafeDeployed(
|
|
990
970
|
safeAddress,
|
|
@@ -1000,9 +980,19 @@ var ZyfaiSDK = class {
|
|
|
1000
980
|
*
|
|
1001
981
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
1002
982
|
* @param chainId - Target chain ID
|
|
983
|
+
* @param strategy - Optional strategy selection: "safe_strategy" (default) or "degen_strategy" (yieldor)
|
|
1003
984
|
* @returns Deployment response with Safe address and transaction hash
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```typescript
|
|
988
|
+
* // Deploy with default safe strategy
|
|
989
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
990
|
+
*
|
|
991
|
+
* // Deploy with degen strategy (yieldor)
|
|
992
|
+
* await sdk.deploySafe(userAddress, 8453, "degen_strategy");
|
|
993
|
+
* ```
|
|
1004
994
|
*/
|
|
1005
|
-
async deploySafe(userAddress, chainId) {
|
|
995
|
+
async deploySafe(userAddress, chainId, strategy) {
|
|
1006
996
|
try {
|
|
1007
997
|
if (!userAddress) {
|
|
1008
998
|
throw new Error("User address is required");
|
|
@@ -1017,8 +1007,7 @@ var ZyfaiSDK = class {
|
|
|
1017
1007
|
owner: walletClient,
|
|
1018
1008
|
safeOwnerAddress: userAddress,
|
|
1019
1009
|
chain: chainConfig.chain,
|
|
1020
|
-
publicClient: chainConfig.publicClient
|
|
1021
|
-
environment: this.environment
|
|
1010
|
+
publicClient: chainConfig.publicClient
|
|
1022
1011
|
});
|
|
1023
1012
|
const alreadyDeployed = await isSafeDeployed(
|
|
1024
1013
|
safeAddress,
|
|
@@ -1048,9 +1037,9 @@ var ZyfaiSDK = class {
|
|
|
1048
1037
|
safeOwnerAddress: userAddress,
|
|
1049
1038
|
chain: chainConfig.chain,
|
|
1050
1039
|
publicClient: chainConfig.publicClient,
|
|
1051
|
-
environment: this.environment,
|
|
1052
1040
|
chainId,
|
|
1053
|
-
httpClient: this.httpClient
|
|
1041
|
+
httpClient: this.httpClient,
|
|
1042
|
+
strategy: strategy || "safe_strategy"
|
|
1054
1043
|
});
|
|
1055
1044
|
try {
|
|
1056
1045
|
await this.initializeUser(deploymentResult.safeAddress, chainId);
|
|
@@ -1193,8 +1182,7 @@ var ZyfaiSDK = class {
|
|
|
1193
1182
|
owner: walletClient,
|
|
1194
1183
|
safeOwnerAddress: userAddress,
|
|
1195
1184
|
chain: chainConfig.chain,
|
|
1196
|
-
publicClient: chainConfig.publicClient
|
|
1197
|
-
environment: this.environment
|
|
1185
|
+
publicClient: chainConfig.publicClient
|
|
1198
1186
|
},
|
|
1199
1187
|
sessions,
|
|
1200
1188
|
allPublicClients,
|
|
@@ -1204,8 +1192,7 @@ var ZyfaiSDK = class {
|
|
|
1204
1192
|
owner: walletClient,
|
|
1205
1193
|
safeOwnerAddress: userAddress,
|
|
1206
1194
|
chain: chainConfig.chain,
|
|
1207
|
-
publicClient: chainConfig.publicClient
|
|
1208
|
-
environment: this.environment
|
|
1195
|
+
publicClient: chainConfig.publicClient
|
|
1209
1196
|
});
|
|
1210
1197
|
return {
|
|
1211
1198
|
success: true,
|
|
@@ -1315,8 +1302,7 @@ var ZyfaiSDK = class {
|
|
|
1315
1302
|
owner: walletClient,
|
|
1316
1303
|
safeOwnerAddress: userAddress,
|
|
1317
1304
|
chain: chainConfig.chain,
|
|
1318
|
-
publicClient: chainConfig.publicClient
|
|
1319
|
-
environment: this.environment
|
|
1305
|
+
publicClient: chainConfig.publicClient
|
|
1320
1306
|
});
|
|
1321
1307
|
const isDeployed = await isSafeDeployed(
|
|
1322
1308
|
safeAddress,
|
|
@@ -1397,8 +1383,7 @@ var ZyfaiSDK = class {
|
|
|
1397
1383
|
owner: walletClient,
|
|
1398
1384
|
safeOwnerAddress: userAddress,
|
|
1399
1385
|
chain: chainConfig.chain,
|
|
1400
|
-
publicClient: chainConfig.publicClient
|
|
1401
|
-
environment: this.environment
|
|
1386
|
+
publicClient: chainConfig.publicClient
|
|
1402
1387
|
});
|
|
1403
1388
|
}
|
|
1404
1389
|
} catch {
|
|
@@ -1407,8 +1392,7 @@ var ZyfaiSDK = class {
|
|
|
1407
1392
|
owner: walletClient,
|
|
1408
1393
|
safeOwnerAddress: userAddress,
|
|
1409
1394
|
chain: chainConfig.chain,
|
|
1410
|
-
publicClient: chainConfig.publicClient
|
|
1411
|
-
environment: this.environment
|
|
1395
|
+
publicClient: chainConfig.publicClient
|
|
1412
1396
|
});
|
|
1413
1397
|
}
|
|
1414
1398
|
const isDeployed = await isSafeDeployed(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
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",
|