@zyfai/sdk 0.1.4 → 0.1.6
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 +77 -17
- package/dist/index.d.mts +22 -9
- package/dist/index.d.ts +22 -9
- package/dist/index.js +69 -44
- package/dist/index.mjs +69 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ const sdk = new ZyfaiSDK({
|
|
|
65
65
|
|
|
66
66
|
### Connect Account
|
|
67
67
|
|
|
68
|
-
The SDK accepts either a private key or a modern wallet provider
|
|
68
|
+
The SDK accepts either a private key or a modern wallet provider. **The SDK automatically authenticates the user via SIWE (Sign-In with Ethereum) when connecting.**
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
71
|
// Option 1: With private key (chainId required)
|
|
@@ -84,7 +84,25 @@ const userAddress = "0xUser...";
|
|
|
84
84
|
await sdk.deploySafe(userAddress, 42161);
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
**Note:**
|
|
87
|
+
**Note:**
|
|
88
|
+
- When using a wallet provider, the SDK automatically detects the chain from the provider. You can optionally specify `chainId` to override.
|
|
89
|
+
- The SDK automatically performs SIWE authentication when connecting, so you don't need to call any additional authentication methods.
|
|
90
|
+
|
|
91
|
+
### Disconnect Account
|
|
92
|
+
|
|
93
|
+
Disconnect the current account and clear all authentication state:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// Disconnect account and clear JWT token
|
|
97
|
+
await sdk.disconnectAccount();
|
|
98
|
+
console.log("Account disconnected and authentication cleared");
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
This method:
|
|
102
|
+
- Clears the wallet connection
|
|
103
|
+
- Resets authentication state
|
|
104
|
+
- Clears the JWT token
|
|
105
|
+
- Resets session key tracking
|
|
88
106
|
|
|
89
107
|
## Core Features
|
|
90
108
|
|
|
@@ -164,7 +182,7 @@ new ZyfaiSDK(config: SDKConfig | string)
|
|
|
164
182
|
|
|
165
183
|
##### `connectAccount(account: string | any, chainId?: SupportedChainId): Promise<Address>`
|
|
166
184
|
|
|
167
|
-
Connect account for signing transactions. Accepts either a private key string or a modern wallet provider.
|
|
185
|
+
Connect account for signing transactions and authenticate via SIWE. Accepts either a private key string or a modern wallet provider.
|
|
168
186
|
|
|
169
187
|
**Parameters:**
|
|
170
188
|
|
|
@@ -176,6 +194,11 @@ Connect account for signing transactions. Accepts either a private key string or
|
|
|
176
194
|
|
|
177
195
|
**Returns:** Connected wallet address
|
|
178
196
|
|
|
197
|
+
**Automatic Actions:**
|
|
198
|
+
- Connects the wallet
|
|
199
|
+
- Authenticates via SIWE (Sign-In with Ethereum)
|
|
200
|
+
- Stores JWT token for authenticated endpoints
|
|
201
|
+
|
|
179
202
|
**Examples:**
|
|
180
203
|
|
|
181
204
|
```typescript
|
|
@@ -187,6 +210,25 @@ const provider = await connector.getProvider();
|
|
|
187
210
|
await sdk.connectAccount(provider); // Uses provider's current chain
|
|
188
211
|
```
|
|
189
212
|
|
|
213
|
+
##### `disconnectAccount(): Promise<void>`
|
|
214
|
+
|
|
215
|
+
Disconnect account and clear all authentication state.
|
|
216
|
+
|
|
217
|
+
**Returns:** Promise that resolves when disconnection is complete
|
|
218
|
+
|
|
219
|
+
**Actions:**
|
|
220
|
+
- Clears wallet connection
|
|
221
|
+
- Resets authentication state
|
|
222
|
+
- Clears JWT token
|
|
223
|
+
- Resets session key tracking
|
|
224
|
+
|
|
225
|
+
**Example:**
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
await sdk.disconnectAccount();
|
|
229
|
+
console.log("Disconnected and cleared");
|
|
230
|
+
```
|
|
231
|
+
|
|
190
232
|
##### `getSmartWalletAddress(userAddress: string, chainId: SupportedChainId): Promise<SmartWalletResponse>`
|
|
191
233
|
|
|
192
234
|
Get the Smart Wallet (Safe) address for a user.
|
|
@@ -235,7 +277,7 @@ The SDK automatically fetches optimal session configuration from ZyFAI API:
|
|
|
235
277
|
|
|
236
278
|
```typescript
|
|
237
279
|
// SDK automatically:
|
|
238
|
-
// 1.
|
|
280
|
+
// 1. Uses existing SIWE authentication (from connectAccount)
|
|
239
281
|
// 2. Checks if user already has an active session key (returns early if so)
|
|
240
282
|
// 3. Calculates the deterministic Safe address
|
|
241
283
|
// 4. Retrieves personalized config via /session-keys/config
|
|
@@ -257,9 +299,9 @@ console.log("User ID:", result.userId);
|
|
|
257
299
|
|
|
258
300
|
**Important**:
|
|
259
301
|
|
|
260
|
-
-
|
|
261
|
-
- The SDK proactively checks if the user already has an active session key
|
|
262
|
-
- The user record must have `smartWallet` and `chainId` set (automatically handled after calling `deploySafe`
|
|
302
|
+
- User must be authenticated (automatically done via `connectAccount()`)
|
|
303
|
+
- The SDK proactively checks if the user already has an active session key and returns early without requiring any signature if one exists
|
|
304
|
+
- The user record must have `smartWallet` and `chainId` set (automatically handled after calling `deploySafe`)
|
|
263
305
|
- When `alreadyActive` is `true`, `sessionKeyAddress` and `signature` are not available in the response
|
|
264
306
|
|
|
265
307
|
### 4. Deposit Funds
|
|
@@ -286,7 +328,7 @@ The SDK automatically authenticates via SIWE before logging the deposit with ZyF
|
|
|
286
328
|
|
|
287
329
|
### 5. Withdraw Funds
|
|
288
330
|
|
|
289
|
-
|
|
331
|
+
Initiate a withdrawal from your Safe. **Note: Withdrawals are processed asynchronously by the backend.**
|
|
290
332
|
|
|
291
333
|
```typescript
|
|
292
334
|
// Full withdrawal
|
|
@@ -301,13 +343,22 @@ const result = await sdk.withdrawFunds(
|
|
|
301
343
|
);
|
|
302
344
|
|
|
303
345
|
if (result.success) {
|
|
304
|
-
console.log("Withdrawal
|
|
305
|
-
console.log("
|
|
346
|
+
console.log("Withdrawal initiated!");
|
|
347
|
+
console.log("Message:", result.message); // e.g., "Withdrawal request sent"
|
|
348
|
+
if (result.txHash) {
|
|
349
|
+
console.log("Transaction Hash:", result.txHash);
|
|
350
|
+
} else {
|
|
351
|
+
console.log("Transaction will be processed asynchronously");
|
|
352
|
+
}
|
|
306
353
|
}
|
|
307
354
|
```
|
|
308
355
|
|
|
309
|
-
**
|
|
310
|
-
|
|
356
|
+
**Important Notes:**
|
|
357
|
+
- Amount must be in least decimal units. For USDC (6 decimals): 1 USDC = 1000000
|
|
358
|
+
- The SDK authenticates via SIWE before calling the withdrawal endpoints
|
|
359
|
+
- Withdrawals are processed asynchronously - the `txHash` may not be immediately available
|
|
360
|
+
- Check the `message` field for the withdrawal status
|
|
361
|
+
- Use `getHistory()` to track the withdrawal transaction once it's processed
|
|
311
362
|
|
|
312
363
|
### 6. Get Available Protocols
|
|
313
364
|
|
|
@@ -377,7 +428,7 @@ console.log("Active wallet count:", wallets.count);
|
|
|
377
428
|
#### Get Smart Wallets by EOA
|
|
378
429
|
|
|
379
430
|
```typescript
|
|
380
|
-
const result = await sdk.
|
|
431
|
+
const result = await sdk.getSmartWalletByEOA("0xYourEOA...");
|
|
381
432
|
console.log("Smart wallets:", result.smartWallets);
|
|
382
433
|
```
|
|
383
434
|
|
|
@@ -549,7 +600,7 @@ async function main() {
|
|
|
549
600
|
bundlerApiKey: process.env.BUNDLER_API_KEY!,
|
|
550
601
|
});
|
|
551
602
|
|
|
552
|
-
// Connect account (
|
|
603
|
+
// Connect account (automatically authenticates via SIWE)
|
|
553
604
|
await sdk.connectAccount(process.env.PRIVATE_KEY!, 42161);
|
|
554
605
|
|
|
555
606
|
const userAddress = "0xUser..."; // User's EOA address
|
|
@@ -598,9 +649,10 @@ function SafeDeployment() {
|
|
|
598
649
|
try {
|
|
599
650
|
// Client passes the wallet provider from their frontend
|
|
600
651
|
// e.g., from wagmi: const provider = await connector.getProvider();
|
|
652
|
+
// connectAccount automatically authenticates via SIWE
|
|
601
653
|
const address = await sdk.connectAccount(walletProvider); // chainId auto-detected
|
|
602
654
|
setUserAddress(address);
|
|
603
|
-
console.log("Connected:", address);
|
|
655
|
+
console.log("Connected and authenticated:", address);
|
|
604
656
|
|
|
605
657
|
// Get Safe address for this user
|
|
606
658
|
const walletInfo = await sdk.getSmartWalletAddress(address, 42161);
|
|
@@ -720,7 +772,7 @@ CHAIN_ID=8453
|
|
|
720
772
|
|
|
721
773
|
### "No account connected" Error
|
|
722
774
|
|
|
723
|
-
Make sure to call `connectAccount()` before calling other methods that require signing.
|
|
775
|
+
Make sure to call `connectAccount()` before calling other methods that require signing. Note that `connectAccount()` automatically authenticates the user via SIWE.
|
|
724
776
|
|
|
725
777
|
### "Unsupported chain" Error
|
|
726
778
|
|
|
@@ -728,18 +780,26 @@ Check that the chain ID is in the supported chains list: Arbitrum (42161), Base
|
|
|
728
780
|
|
|
729
781
|
### SIWE Authentication Issues in Browser
|
|
730
782
|
|
|
731
|
-
The SDK automatically detects browser vs Node.js environments
|
|
783
|
+
The SDK automatically performs SIWE authentication when you call `connectAccount()`. The SDK automatically detects browser vs Node.js environments:
|
|
732
784
|
- **Browser**: Uses `window.location.origin` for the SIWE message domain/uri to match the browser's automatic `Origin` header
|
|
733
785
|
- **Node.js**: Uses the API endpoint URL
|
|
734
786
|
|
|
735
787
|
If you encounter SIWE authentication failures in a browser, ensure:
|
|
736
788
|
1. Your frontend origin is allowed by the API's CORS configuration
|
|
737
789
|
2. You're using the correct `environment` setting (`staging` or `production`)
|
|
790
|
+
3. The user approves the SIWE signature request in their wallet
|
|
738
791
|
|
|
739
792
|
### Session Key Already Exists
|
|
740
793
|
|
|
741
794
|
If `createSessionKey` returns `{ alreadyActive: true }`, the user already has an active session key. This is not an error - the SDK proactively checks before attempting to create a new one.
|
|
742
795
|
|
|
796
|
+
### Withdrawal Transaction Hash Not Available
|
|
797
|
+
|
|
798
|
+
If `withdrawFunds` returns without a `txHash`, the withdrawal is being processed asynchronously by the backend. You can:
|
|
799
|
+
1. Check the `message` field for status information
|
|
800
|
+
2. Use `getHistory()` to track when the withdrawal transaction is processed
|
|
801
|
+
3. The transaction will appear in the history once it's been executed
|
|
802
|
+
|
|
743
803
|
### Data API CORS Errors
|
|
744
804
|
|
|
745
805
|
Some Data API endpoints may require server-side CORS configuration. If you see CORS errors for endpoints like `onchain-earnings`, `calculate-onchain-earnings`, or `opportunities`, contact ZyFAI support to ensure your origin is whitelisted.
|
package/dist/index.d.mts
CHANGED
|
@@ -177,11 +177,10 @@ interface ActiveWalletsResponse {
|
|
|
177
177
|
wallets: ActiveWallet[];
|
|
178
178
|
count: number;
|
|
179
179
|
}
|
|
180
|
-
interface
|
|
180
|
+
interface SmartWalletByEOAResponse {
|
|
181
181
|
success: boolean;
|
|
182
182
|
eoa: string;
|
|
183
|
-
smartWallet:
|
|
184
|
-
smartWallets: string[];
|
|
183
|
+
smartWallet: Address | null;
|
|
185
184
|
chains: number[];
|
|
186
185
|
}
|
|
187
186
|
interface FirstTopupResponse {
|
|
@@ -348,7 +347,8 @@ interface DepositResponse {
|
|
|
348
347
|
}
|
|
349
348
|
interface WithdrawResponse {
|
|
350
349
|
success: boolean;
|
|
351
|
-
|
|
350
|
+
message: string;
|
|
351
|
+
txHash?: string;
|
|
352
352
|
type: "full" | "partial";
|
|
353
353
|
amount: string;
|
|
354
354
|
receiver: string;
|
|
@@ -457,6 +457,17 @@ declare class ZyfaiSDK {
|
|
|
457
457
|
* await sdk.connectAccount(provider);
|
|
458
458
|
*/
|
|
459
459
|
connectAccount(account: string | any, chainId?: SupportedChainId): Promise<Address>;
|
|
460
|
+
/**
|
|
461
|
+
* Disconnect account and clear authentication state
|
|
462
|
+
* Resets wallet connection, JWT token, and all authentication-related state
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* await sdk.disconnectAccount();
|
|
467
|
+
* console.log("Account disconnected");
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
disconnectAccount(): Promise<void>;
|
|
460
471
|
/**
|
|
461
472
|
* Get wallet client (throws if not connected)
|
|
462
473
|
* @private
|
|
@@ -532,18 +543,20 @@ declare class ZyfaiSDK {
|
|
|
532
543
|
depositFunds(userAddress: string, chainId: SupportedChainId, tokenAddress: string, amount: string): Promise<DepositResponse>;
|
|
533
544
|
/**
|
|
534
545
|
* Withdraw funds from Safe smart wallet
|
|
535
|
-
*
|
|
546
|
+
* Initiates a withdrawal request to the ZyFAI API
|
|
547
|
+
* Note: The withdrawal is processed asynchronously, so txHash may not be immediately available
|
|
536
548
|
*
|
|
537
549
|
* @param userAddress - User's address (owner of the Safe)
|
|
538
550
|
* @param chainId - Target chain ID
|
|
539
551
|
* @param amount - Optional: Amount in least decimal units to withdraw (partial withdrawal). If not specified, withdraws all funds
|
|
540
552
|
* @param receiver - Optional: Receiver address. If not specified, sends to Safe owner
|
|
541
|
-
* @returns Withdraw response with transaction hash
|
|
553
|
+
* @returns Withdraw response with message and optional transaction hash (available once processed)
|
|
542
554
|
*
|
|
543
555
|
* @example
|
|
544
556
|
* ```typescript
|
|
545
557
|
* // Full withdrawal
|
|
546
558
|
* const result = await sdk.withdrawFunds("0xUser...", 42161);
|
|
559
|
+
* console.log(result.message); // "Withdrawal request sent"
|
|
547
560
|
*
|
|
548
561
|
* // Partial withdrawal of 50 USDC (6 decimals)
|
|
549
562
|
* const result = await sdk.withdrawFunds(
|
|
@@ -647,11 +660,11 @@ declare class ZyfaiSDK {
|
|
|
647
660
|
*
|
|
648
661
|
* @example
|
|
649
662
|
* ```typescript
|
|
650
|
-
* const result = await sdk.
|
|
663
|
+
* const result = await sdk.getSmartWalletByEOA("0x...");
|
|
651
664
|
* console.log("Smart wallets:", result.smartWallets);
|
|
652
665
|
* ```
|
|
653
666
|
*/
|
|
654
|
-
|
|
667
|
+
getSmartWalletByEOA(eoaAddress: string): Promise<SmartWalletByEOAResponse>;
|
|
655
668
|
/**
|
|
656
669
|
* Get the first topup (deposit) information for a wallet
|
|
657
670
|
*
|
|
@@ -814,4 +827,4 @@ declare class ZyfaiSDK {
|
|
|
814
827
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
815
828
|
}
|
|
816
829
|
|
|
817
|
-
export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type Address, type ChainConfig, type ChainPortfolio, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type Environment, 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
|
|
830
|
+
export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type Address, type ChainConfig, type ChainPortfolio, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type Environment, 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 SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getSupportedChainIds, isSupportedChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -177,11 +177,10 @@ interface ActiveWalletsResponse {
|
|
|
177
177
|
wallets: ActiveWallet[];
|
|
178
178
|
count: number;
|
|
179
179
|
}
|
|
180
|
-
interface
|
|
180
|
+
interface SmartWalletByEOAResponse {
|
|
181
181
|
success: boolean;
|
|
182
182
|
eoa: string;
|
|
183
|
-
smartWallet:
|
|
184
|
-
smartWallets: string[];
|
|
183
|
+
smartWallet: Address | null;
|
|
185
184
|
chains: number[];
|
|
186
185
|
}
|
|
187
186
|
interface FirstTopupResponse {
|
|
@@ -348,7 +347,8 @@ interface DepositResponse {
|
|
|
348
347
|
}
|
|
349
348
|
interface WithdrawResponse {
|
|
350
349
|
success: boolean;
|
|
351
|
-
|
|
350
|
+
message: string;
|
|
351
|
+
txHash?: string;
|
|
352
352
|
type: "full" | "partial";
|
|
353
353
|
amount: string;
|
|
354
354
|
receiver: string;
|
|
@@ -457,6 +457,17 @@ declare class ZyfaiSDK {
|
|
|
457
457
|
* await sdk.connectAccount(provider);
|
|
458
458
|
*/
|
|
459
459
|
connectAccount(account: string | any, chainId?: SupportedChainId): Promise<Address>;
|
|
460
|
+
/**
|
|
461
|
+
* Disconnect account and clear authentication state
|
|
462
|
+
* Resets wallet connection, JWT token, and all authentication-related state
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```typescript
|
|
466
|
+
* await sdk.disconnectAccount();
|
|
467
|
+
* console.log("Account disconnected");
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
disconnectAccount(): Promise<void>;
|
|
460
471
|
/**
|
|
461
472
|
* Get wallet client (throws if not connected)
|
|
462
473
|
* @private
|
|
@@ -532,18 +543,20 @@ declare class ZyfaiSDK {
|
|
|
532
543
|
depositFunds(userAddress: string, chainId: SupportedChainId, tokenAddress: string, amount: string): Promise<DepositResponse>;
|
|
533
544
|
/**
|
|
534
545
|
* Withdraw funds from Safe smart wallet
|
|
535
|
-
*
|
|
546
|
+
* Initiates a withdrawal request to the ZyFAI API
|
|
547
|
+
* Note: The withdrawal is processed asynchronously, so txHash may not be immediately available
|
|
536
548
|
*
|
|
537
549
|
* @param userAddress - User's address (owner of the Safe)
|
|
538
550
|
* @param chainId - Target chain ID
|
|
539
551
|
* @param amount - Optional: Amount in least decimal units to withdraw (partial withdrawal). If not specified, withdraws all funds
|
|
540
552
|
* @param receiver - Optional: Receiver address. If not specified, sends to Safe owner
|
|
541
|
-
* @returns Withdraw response with transaction hash
|
|
553
|
+
* @returns Withdraw response with message and optional transaction hash (available once processed)
|
|
542
554
|
*
|
|
543
555
|
* @example
|
|
544
556
|
* ```typescript
|
|
545
557
|
* // Full withdrawal
|
|
546
558
|
* const result = await sdk.withdrawFunds("0xUser...", 42161);
|
|
559
|
+
* console.log(result.message); // "Withdrawal request sent"
|
|
547
560
|
*
|
|
548
561
|
* // Partial withdrawal of 50 USDC (6 decimals)
|
|
549
562
|
* const result = await sdk.withdrawFunds(
|
|
@@ -647,11 +660,11 @@ declare class ZyfaiSDK {
|
|
|
647
660
|
*
|
|
648
661
|
* @example
|
|
649
662
|
* ```typescript
|
|
650
|
-
* const result = await sdk.
|
|
663
|
+
* const result = await sdk.getSmartWalletByEOA("0x...");
|
|
651
664
|
* console.log("Smart wallets:", result.smartWallets);
|
|
652
665
|
* ```
|
|
653
666
|
*/
|
|
654
|
-
|
|
667
|
+
getSmartWalletByEOA(eoaAddress: string): Promise<SmartWalletByEOAResponse>;
|
|
655
668
|
/**
|
|
656
669
|
* Get the first topup (deposit) information for a wallet
|
|
657
670
|
*
|
|
@@ -814,4 +827,4 @@ declare class ZyfaiSDK {
|
|
|
814
827
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
815
828
|
}
|
|
816
829
|
|
|
817
|
-
export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type Address, type ChainConfig, type ChainPortfolio, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type Environment, 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
|
|
830
|
+
export { type ActionData, type ActiveWallet, type ActiveWalletsResponse, type Address, type ChainConfig, type ChainPortfolio, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type Environment, 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 SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getSupportedChainIds, isSupportedChain };
|
package/dist/index.js
CHANGED
|
@@ -414,7 +414,7 @@ var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
|
414
414
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
415
415
|
var ACCOUNT_SALTS = {
|
|
416
416
|
staging: "zyfai-staging",
|
|
417
|
-
production: "zyfai
|
|
417
|
+
production: "zyfai"
|
|
418
418
|
};
|
|
419
419
|
var getSafeAccount = async (config) => {
|
|
420
420
|
const {
|
|
@@ -440,8 +440,8 @@ var getSafeAccount = async (config) => {
|
|
|
440
440
|
const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(effectiveSalt), "bigint");
|
|
441
441
|
const safeAccount = await (0, import_accounts.toSafeSmartAccount)({
|
|
442
442
|
client: publicClient,
|
|
443
|
-
owners: [owner
|
|
444
|
-
// Pass the
|
|
443
|
+
owners: [owner],
|
|
444
|
+
// Pass the owner object with address and signMessage capability
|
|
445
445
|
version: "1.4.1",
|
|
446
446
|
entryPoint: {
|
|
447
447
|
address: import_account_abstraction.entryPoint07Address,
|
|
@@ -512,7 +512,7 @@ var getAccountType = async (address, publicClient) => {
|
|
|
512
512
|
}
|
|
513
513
|
};
|
|
514
514
|
var getSmartAccountClient = async (config) => {
|
|
515
|
-
const {
|
|
515
|
+
const { chain, bundlerUrl } = config;
|
|
516
516
|
const safeAccount = await getSafeAccount(config);
|
|
517
517
|
const bundlerClient = (0, import_pimlico.createPimlicoClient)({
|
|
518
518
|
transport: (0, import_viem3.http)(bundlerUrl),
|
|
@@ -757,6 +757,7 @@ var ZyfaiSDK = class {
|
|
|
757
757
|
this.isAuthenticated = false;
|
|
758
758
|
this.httpClient.clearAuthToken();
|
|
759
759
|
const chainConfig = getChainConfig(chainId);
|
|
760
|
+
let connectedAddress;
|
|
760
761
|
if (typeof account === "string") {
|
|
761
762
|
let privateKey = account;
|
|
762
763
|
if (!privateKey.startsWith("0x")) {
|
|
@@ -768,39 +769,60 @@ var ZyfaiSDK = class {
|
|
|
768
769
|
chain: chainConfig.chain,
|
|
769
770
|
transport: (0, import_viem4.http)(chainConfig.rpcUrl)
|
|
770
771
|
});
|
|
771
|
-
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
772
|
+
connectedAddress = this.signer.address;
|
|
773
|
+
} else {
|
|
774
|
+
const provider = account;
|
|
775
|
+
if (!provider) {
|
|
776
|
+
throw new Error(
|
|
777
|
+
"Invalid account parameter. Expected private key string or wallet provider."
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
if (provider.request) {
|
|
781
|
+
const accounts = await provider.request({
|
|
782
|
+
method: "eth_requestAccounts"
|
|
783
|
+
});
|
|
784
|
+
if (!accounts || accounts.length === 0) {
|
|
785
|
+
throw new Error("No accounts found in wallet provider");
|
|
786
|
+
}
|
|
787
|
+
this.walletClient = (0, import_viem4.createWalletClient)({
|
|
788
|
+
account: accounts[0],
|
|
789
|
+
chain: chainConfig.chain,
|
|
790
|
+
transport: (0, import_viem4.custom)(provider)
|
|
791
|
+
});
|
|
792
|
+
connectedAddress = accounts[0];
|
|
793
|
+
} else if (provider.account && provider.transport) {
|
|
794
|
+
this.walletClient = (0, import_viem4.createWalletClient)({
|
|
795
|
+
account: provider.account,
|
|
796
|
+
chain: chainConfig.chain,
|
|
797
|
+
transport: provider.transport
|
|
798
|
+
});
|
|
799
|
+
connectedAddress = provider.account.address;
|
|
800
|
+
} else {
|
|
801
|
+
throw new Error(
|
|
802
|
+
"Invalid wallet provider. Expected EIP-1193 provider or viem WalletClient."
|
|
803
|
+
);
|
|
785
804
|
}
|
|
786
|
-
this.walletClient = (0, import_viem4.createWalletClient)({
|
|
787
|
-
account: accounts[0],
|
|
788
|
-
chain: chainConfig.chain,
|
|
789
|
-
transport: (0, import_viem4.custom)(provider)
|
|
790
|
-
});
|
|
791
|
-
return accounts[0];
|
|
792
|
-
}
|
|
793
|
-
if (provider.account && provider.transport) {
|
|
794
|
-
this.walletClient = (0, import_viem4.createWalletClient)({
|
|
795
|
-
account: provider.account,
|
|
796
|
-
chain: chainConfig.chain,
|
|
797
|
-
transport: provider.transport
|
|
798
|
-
});
|
|
799
|
-
return provider.account.address;
|
|
800
805
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
806
|
+
await this.authenticateUser();
|
|
807
|
+
return connectedAddress;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Disconnect account and clear authentication state
|
|
811
|
+
* Resets wallet connection, JWT token, and all authentication-related state
|
|
812
|
+
*
|
|
813
|
+
* @example
|
|
814
|
+
* ```typescript
|
|
815
|
+
* await sdk.disconnectAccount();
|
|
816
|
+
* console.log("Account disconnected");
|
|
817
|
+
* ```
|
|
818
|
+
*/
|
|
819
|
+
async disconnectAccount() {
|
|
820
|
+
this.signer = null;
|
|
821
|
+
this.walletClient = null;
|
|
822
|
+
this.isAuthenticated = false;
|
|
823
|
+
this.authenticatedUserId = null;
|
|
824
|
+
this.hasActiveSessionKey = false;
|
|
825
|
+
this.httpClient.clearAuthToken();
|
|
804
826
|
}
|
|
805
827
|
/**
|
|
806
828
|
* Get wallet client (throws if not connected)
|
|
@@ -1172,18 +1194,20 @@ var ZyfaiSDK = class {
|
|
|
1172
1194
|
}
|
|
1173
1195
|
/**
|
|
1174
1196
|
* Withdraw funds from Safe smart wallet
|
|
1175
|
-
*
|
|
1197
|
+
* Initiates a withdrawal request to the ZyFAI API
|
|
1198
|
+
* Note: The withdrawal is processed asynchronously, so txHash may not be immediately available
|
|
1176
1199
|
*
|
|
1177
1200
|
* @param userAddress - User's address (owner of the Safe)
|
|
1178
1201
|
* @param chainId - Target chain ID
|
|
1179
1202
|
* @param amount - Optional: Amount in least decimal units to withdraw (partial withdrawal). If not specified, withdraws all funds
|
|
1180
1203
|
* @param receiver - Optional: Receiver address. If not specified, sends to Safe owner
|
|
1181
|
-
* @returns Withdraw response with transaction hash
|
|
1204
|
+
* @returns Withdraw response with message and optional transaction hash (available once processed)
|
|
1182
1205
|
*
|
|
1183
1206
|
* @example
|
|
1184
1207
|
* ```typescript
|
|
1185
1208
|
* // Full withdrawal
|
|
1186
1209
|
* const result = await sdk.withdrawFunds("0xUser...", 42161);
|
|
1210
|
+
* console.log(result.message); // "Withdrawal request sent"
|
|
1187
1211
|
*
|
|
1188
1212
|
* // Partial withdrawal of 50 USDC (6 decimals)
|
|
1189
1213
|
* const result = await sdk.withdrawFunds(
|
|
@@ -1234,9 +1258,12 @@ var ZyfaiSDK = class {
|
|
|
1234
1258
|
});
|
|
1235
1259
|
}
|
|
1236
1260
|
const success = response?.success ?? true;
|
|
1261
|
+
const message = response?.message || "Withdrawal request sent";
|
|
1262
|
+
const txHash = response?.txHash || response?.transactionHash;
|
|
1237
1263
|
return {
|
|
1238
1264
|
success,
|
|
1239
|
-
|
|
1265
|
+
message,
|
|
1266
|
+
txHash,
|
|
1240
1267
|
type: amount ? "partial" : "full",
|
|
1241
1268
|
amount: amount || "all",
|
|
1242
1269
|
receiver: receiver || userAddress,
|
|
@@ -1476,11 +1503,11 @@ var ZyfaiSDK = class {
|
|
|
1476
1503
|
*
|
|
1477
1504
|
* @example
|
|
1478
1505
|
* ```typescript
|
|
1479
|
-
* const result = await sdk.
|
|
1506
|
+
* const result = await sdk.getSmartWalletByEOA("0x...");
|
|
1480
1507
|
* console.log("Smart wallets:", result.smartWallets);
|
|
1481
1508
|
* ```
|
|
1482
1509
|
*/
|
|
1483
|
-
async
|
|
1510
|
+
async getSmartWalletByEOA(eoaAddress) {
|
|
1484
1511
|
try {
|
|
1485
1512
|
if (!eoaAddress) {
|
|
1486
1513
|
throw new Error("EOA address is required");
|
|
@@ -1488,14 +1515,12 @@ var ZyfaiSDK = class {
|
|
|
1488
1515
|
const response = await this.httpClient.get(
|
|
1489
1516
|
ENDPOINTS.DATA_BY_EOA(eoaAddress)
|
|
1490
1517
|
);
|
|
1491
|
-
const smartWallet = response.agent ||
|
|
1492
|
-
const smartWallets = smartWallet ? [smartWallet] : [];
|
|
1518
|
+
const smartWallet = response.agent || null;
|
|
1493
1519
|
const chains = response.chains || [];
|
|
1494
1520
|
return {
|
|
1495
1521
|
success: true,
|
|
1496
1522
|
eoa: eoaAddress,
|
|
1497
|
-
smartWallet
|
|
1498
|
-
smartWallets,
|
|
1523
|
+
smartWallet,
|
|
1499
1524
|
chains
|
|
1500
1525
|
};
|
|
1501
1526
|
} catch (error) {
|
package/dist/index.mjs
CHANGED
|
@@ -393,7 +393,7 @@ var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
|
393
393
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
394
394
|
var ACCOUNT_SALTS = {
|
|
395
395
|
staging: "zyfai-staging",
|
|
396
|
-
production: "zyfai
|
|
396
|
+
production: "zyfai"
|
|
397
397
|
};
|
|
398
398
|
var getSafeAccount = async (config) => {
|
|
399
399
|
const {
|
|
@@ -419,8 +419,8 @@ var getSafeAccount = async (config) => {
|
|
|
419
419
|
const saltHex = fromHex(toHex(effectiveSalt), "bigint");
|
|
420
420
|
const safeAccount = await toSafeSmartAccount({
|
|
421
421
|
client: publicClient,
|
|
422
|
-
owners: [owner
|
|
423
|
-
// Pass the
|
|
422
|
+
owners: [owner],
|
|
423
|
+
// Pass the owner object with address and signMessage capability
|
|
424
424
|
version: "1.4.1",
|
|
425
425
|
entryPoint: {
|
|
426
426
|
address: entryPoint07Address,
|
|
@@ -491,7 +491,7 @@ var getAccountType = async (address, publicClient) => {
|
|
|
491
491
|
}
|
|
492
492
|
};
|
|
493
493
|
var getSmartAccountClient = async (config) => {
|
|
494
|
-
const {
|
|
494
|
+
const { chain, bundlerUrl } = config;
|
|
495
495
|
const safeAccount = await getSafeAccount(config);
|
|
496
496
|
const bundlerClient = createPimlicoClient({
|
|
497
497
|
transport: http2(bundlerUrl),
|
|
@@ -736,6 +736,7 @@ var ZyfaiSDK = class {
|
|
|
736
736
|
this.isAuthenticated = false;
|
|
737
737
|
this.httpClient.clearAuthToken();
|
|
738
738
|
const chainConfig = getChainConfig(chainId);
|
|
739
|
+
let connectedAddress;
|
|
739
740
|
if (typeof account === "string") {
|
|
740
741
|
let privateKey = account;
|
|
741
742
|
if (!privateKey.startsWith("0x")) {
|
|
@@ -747,39 +748,60 @@ var ZyfaiSDK = class {
|
|
|
747
748
|
chain: chainConfig.chain,
|
|
748
749
|
transport: http3(chainConfig.rpcUrl)
|
|
749
750
|
});
|
|
750
|
-
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
751
|
+
connectedAddress = this.signer.address;
|
|
752
|
+
} else {
|
|
753
|
+
const provider = account;
|
|
754
|
+
if (!provider) {
|
|
755
|
+
throw new Error(
|
|
756
|
+
"Invalid account parameter. Expected private key string or wallet provider."
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
if (provider.request) {
|
|
760
|
+
const accounts = await provider.request({
|
|
761
|
+
method: "eth_requestAccounts"
|
|
762
|
+
});
|
|
763
|
+
if (!accounts || accounts.length === 0) {
|
|
764
|
+
throw new Error("No accounts found in wallet provider");
|
|
765
|
+
}
|
|
766
|
+
this.walletClient = createWalletClient({
|
|
767
|
+
account: accounts[0],
|
|
768
|
+
chain: chainConfig.chain,
|
|
769
|
+
transport: custom(provider)
|
|
770
|
+
});
|
|
771
|
+
connectedAddress = accounts[0];
|
|
772
|
+
} else if (provider.account && provider.transport) {
|
|
773
|
+
this.walletClient = createWalletClient({
|
|
774
|
+
account: provider.account,
|
|
775
|
+
chain: chainConfig.chain,
|
|
776
|
+
transport: provider.transport
|
|
777
|
+
});
|
|
778
|
+
connectedAddress = provider.account.address;
|
|
779
|
+
} else {
|
|
780
|
+
throw new Error(
|
|
781
|
+
"Invalid wallet provider. Expected EIP-1193 provider or viem WalletClient."
|
|
782
|
+
);
|
|
764
783
|
}
|
|
765
|
-
this.walletClient = createWalletClient({
|
|
766
|
-
account: accounts[0],
|
|
767
|
-
chain: chainConfig.chain,
|
|
768
|
-
transport: custom(provider)
|
|
769
|
-
});
|
|
770
|
-
return accounts[0];
|
|
771
|
-
}
|
|
772
|
-
if (provider.account && provider.transport) {
|
|
773
|
-
this.walletClient = createWalletClient({
|
|
774
|
-
account: provider.account,
|
|
775
|
-
chain: chainConfig.chain,
|
|
776
|
-
transport: provider.transport
|
|
777
|
-
});
|
|
778
|
-
return provider.account.address;
|
|
779
784
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
785
|
+
await this.authenticateUser();
|
|
786
|
+
return connectedAddress;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Disconnect account and clear authentication state
|
|
790
|
+
* Resets wallet connection, JWT token, and all authentication-related state
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* ```typescript
|
|
794
|
+
* await sdk.disconnectAccount();
|
|
795
|
+
* console.log("Account disconnected");
|
|
796
|
+
* ```
|
|
797
|
+
*/
|
|
798
|
+
async disconnectAccount() {
|
|
799
|
+
this.signer = null;
|
|
800
|
+
this.walletClient = null;
|
|
801
|
+
this.isAuthenticated = false;
|
|
802
|
+
this.authenticatedUserId = null;
|
|
803
|
+
this.hasActiveSessionKey = false;
|
|
804
|
+
this.httpClient.clearAuthToken();
|
|
783
805
|
}
|
|
784
806
|
/**
|
|
785
807
|
* Get wallet client (throws if not connected)
|
|
@@ -1151,18 +1173,20 @@ var ZyfaiSDK = class {
|
|
|
1151
1173
|
}
|
|
1152
1174
|
/**
|
|
1153
1175
|
* Withdraw funds from Safe smart wallet
|
|
1154
|
-
*
|
|
1176
|
+
* Initiates a withdrawal request to the ZyFAI API
|
|
1177
|
+
* Note: The withdrawal is processed asynchronously, so txHash may not be immediately available
|
|
1155
1178
|
*
|
|
1156
1179
|
* @param userAddress - User's address (owner of the Safe)
|
|
1157
1180
|
* @param chainId - Target chain ID
|
|
1158
1181
|
* @param amount - Optional: Amount in least decimal units to withdraw (partial withdrawal). If not specified, withdraws all funds
|
|
1159
1182
|
* @param receiver - Optional: Receiver address. If not specified, sends to Safe owner
|
|
1160
|
-
* @returns Withdraw response with transaction hash
|
|
1183
|
+
* @returns Withdraw response with message and optional transaction hash (available once processed)
|
|
1161
1184
|
*
|
|
1162
1185
|
* @example
|
|
1163
1186
|
* ```typescript
|
|
1164
1187
|
* // Full withdrawal
|
|
1165
1188
|
* const result = await sdk.withdrawFunds("0xUser...", 42161);
|
|
1189
|
+
* console.log(result.message); // "Withdrawal request sent"
|
|
1166
1190
|
*
|
|
1167
1191
|
* // Partial withdrawal of 50 USDC (6 decimals)
|
|
1168
1192
|
* const result = await sdk.withdrawFunds(
|
|
@@ -1213,9 +1237,12 @@ var ZyfaiSDK = class {
|
|
|
1213
1237
|
});
|
|
1214
1238
|
}
|
|
1215
1239
|
const success = response?.success ?? true;
|
|
1240
|
+
const message = response?.message || "Withdrawal request sent";
|
|
1241
|
+
const txHash = response?.txHash || response?.transactionHash;
|
|
1216
1242
|
return {
|
|
1217
1243
|
success,
|
|
1218
|
-
|
|
1244
|
+
message,
|
|
1245
|
+
txHash,
|
|
1219
1246
|
type: amount ? "partial" : "full",
|
|
1220
1247
|
amount: amount || "all",
|
|
1221
1248
|
receiver: receiver || userAddress,
|
|
@@ -1455,11 +1482,11 @@ var ZyfaiSDK = class {
|
|
|
1455
1482
|
*
|
|
1456
1483
|
* @example
|
|
1457
1484
|
* ```typescript
|
|
1458
|
-
* const result = await sdk.
|
|
1485
|
+
* const result = await sdk.getSmartWalletByEOA("0x...");
|
|
1459
1486
|
* console.log("Smart wallets:", result.smartWallets);
|
|
1460
1487
|
* ```
|
|
1461
1488
|
*/
|
|
1462
|
-
async
|
|
1489
|
+
async getSmartWalletByEOA(eoaAddress) {
|
|
1463
1490
|
try {
|
|
1464
1491
|
if (!eoaAddress) {
|
|
1465
1492
|
throw new Error("EOA address is required");
|
|
@@ -1467,14 +1494,12 @@ var ZyfaiSDK = class {
|
|
|
1467
1494
|
const response = await this.httpClient.get(
|
|
1468
1495
|
ENDPOINTS.DATA_BY_EOA(eoaAddress)
|
|
1469
1496
|
);
|
|
1470
|
-
const smartWallet = response.agent ||
|
|
1471
|
-
const smartWallets = smartWallet ? [smartWallet] : [];
|
|
1497
|
+
const smartWallet = response.agent || null;
|
|
1472
1498
|
const chains = response.chains || [];
|
|
1473
1499
|
return {
|
|
1474
1500
|
success: true,
|
|
1475
1501
|
eoa: eoaAddress,
|
|
1476
|
-
smartWallet
|
|
1477
|
-
smartWallets,
|
|
1502
|
+
smartWallet,
|
|
1478
1503
|
chains
|
|
1479
1504
|
};
|
|
1480
1505
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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",
|