@zyfai/sdk 0.1.13 → 0.1.14
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 -22
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +18 -11
- package/dist/index.mjs +18 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ The SDK accepts either a private key or a modern wallet provider. **The SDK auto
|
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
71
|
// Option 1: With private key (chainId required)
|
|
72
|
-
await sdk.connectAccount("0x...",
|
|
72
|
+
await sdk.connectAccount("0x...", 8453);
|
|
73
73
|
|
|
74
74
|
// Option 2: With wallet provider (chainId optional - uses provider's chain)
|
|
75
75
|
const provider = await connector.getProvider();
|
|
@@ -81,7 +81,7 @@ await sdk.connectAccount(provider); // Automatically uses provider's current cha
|
|
|
81
81
|
|
|
82
82
|
// Now call methods with explicit user addresses
|
|
83
83
|
const userAddress = "0xUser...";
|
|
84
|
-
await sdk.deploySafe(userAddress,
|
|
84
|
+
await sdk.deploySafe(userAddress, 8453);
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
**Note:**
|
|
@@ -116,12 +116,12 @@ Deploy a Safe smart wallet:
|
|
|
116
116
|
const userAddress = "0xUser..."; // User's EOA address
|
|
117
117
|
|
|
118
118
|
// Get the deterministic Safe address (before deployment)
|
|
119
|
-
const walletInfo = await sdk.getSmartWalletAddress(userAddress,
|
|
119
|
+
const walletInfo = await sdk.getSmartWalletAddress(userAddress, 8453);
|
|
120
120
|
console.log("Safe Address:", walletInfo.address);
|
|
121
121
|
console.log("Is Deployed:", walletInfo.isDeployed);
|
|
122
122
|
|
|
123
123
|
// Deploy the Safe (automatically checks if already deployed)
|
|
124
|
-
const result = await sdk.deploySafe(userAddress,
|
|
124
|
+
const result = await sdk.deploySafe(userAddress, 8453);
|
|
125
125
|
|
|
126
126
|
if (result.success) {
|
|
127
127
|
console.log("Safe Address:", result.safeAddress);
|
|
@@ -157,9 +157,9 @@ const chains = getSupportedChainIds();
|
|
|
157
157
|
console.log("Supported chains:", chains);
|
|
158
158
|
|
|
159
159
|
// Check if a chain is supported
|
|
160
|
-
if (isSupportedChain(
|
|
160
|
+
if (isSupportedChain(8453)) {
|
|
161
161
|
const userAddress = "0xUser...";
|
|
162
|
-
const result = await sdk.deploySafe(userAddress,
|
|
162
|
+
const result = await sdk.deploySafe(userAddress, 8453); // Base
|
|
163
163
|
}
|
|
164
164
|
```
|
|
165
165
|
|
|
@@ -192,7 +192,7 @@ Connect account for signing transactions and authenticate via SIWE. Accepts eith
|
|
|
192
192
|
- `chainId`: Target chain ID
|
|
193
193
|
- **Required** for private key
|
|
194
194
|
- **Optional** for wallet providers (auto-detects from provider)
|
|
195
|
-
- Default:
|
|
195
|
+
- Default: 8453 (Base)
|
|
196
196
|
|
|
197
197
|
**Returns:** Connected wallet address
|
|
198
198
|
|
|
@@ -206,7 +206,7 @@ Connect account for signing transactions and authenticate via SIWE. Accepts eith
|
|
|
206
206
|
|
|
207
207
|
```typescript
|
|
208
208
|
// With private key (chainId required)
|
|
209
|
-
await sdk.connectAccount("0x...",
|
|
209
|
+
await sdk.connectAccount("0x...", 8453);
|
|
210
210
|
|
|
211
211
|
// With wallet provider (chainId optional)
|
|
212
212
|
const provider = await connector.getProvider();
|
|
@@ -307,7 +307,7 @@ The SDK automatically fetches optimal session configuration from ZyFAI API:
|
|
|
307
307
|
// 5. Signs the session key
|
|
308
308
|
// 6. Calls /session-keys/add so the session becomes active immediately
|
|
309
309
|
|
|
310
|
-
const result = await sdk.createSessionKey(userAddress,
|
|
310
|
+
const result = await sdk.createSessionKey(userAddress, 8453);
|
|
311
311
|
|
|
312
312
|
// Check if session key already existed
|
|
313
313
|
if (result.alreadyActive) {
|
|
@@ -332,11 +332,11 @@ console.log("User ID:", result.userId);
|
|
|
332
332
|
Transfer tokens to your Safe smart wallet:
|
|
333
333
|
|
|
334
334
|
```typescript
|
|
335
|
-
// Deposit 100 USDC (6 decimals) to Safe on
|
|
335
|
+
// Deposit 100 USDC (6 decimals) to Safe on Base
|
|
336
336
|
const result = await sdk.depositFunds(
|
|
337
337
|
userAddress,
|
|
338
|
-
|
|
339
|
-
"
|
|
338
|
+
8453, // Chain ID
|
|
339
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
|
|
340
340
|
"100000000" // Amount: 100 USDC = 100 * 10^6
|
|
341
341
|
);
|
|
342
342
|
|
|
@@ -355,12 +355,12 @@ Initiate a withdrawal from your Safe. **Note: Withdrawals are processed asynchro
|
|
|
355
355
|
|
|
356
356
|
```typescript
|
|
357
357
|
// Full withdrawal
|
|
358
|
-
const result = await sdk.withdrawFunds(userAddress,
|
|
358
|
+
const result = await sdk.withdrawFunds(userAddress, 8453);
|
|
359
359
|
|
|
360
360
|
// Partial withdrawal of 50 USDC (6 decimals)
|
|
361
361
|
const result = await sdk.withdrawFunds(
|
|
362
362
|
userAddress,
|
|
363
|
-
|
|
363
|
+
8453,
|
|
364
364
|
"50000000", // Amount: 50 USDC = 50 * 10^6
|
|
365
365
|
"0xReceiverAddress" // Optional: receiver address
|
|
366
366
|
);
|
|
@@ -389,7 +389,7 @@ if (result.success) {
|
|
|
389
389
|
Retrieve all available DeFi protocols and pools for a specific chain:
|
|
390
390
|
|
|
391
391
|
```typescript
|
|
392
|
-
const protocols = await sdk.getAvailableProtocols(
|
|
392
|
+
const protocols = await sdk.getAvailableProtocols(8453);
|
|
393
393
|
|
|
394
394
|
console.log(`Found ${protocols.protocols.length} protocols`);
|
|
395
395
|
protocols.protocols.forEach((protocol) => {
|
|
@@ -626,7 +626,7 @@ pnpm tsx examples/end-to-end.ts
|
|
|
626
626
|
|
|
627
627
|
## Complete Examples
|
|
628
628
|
|
|
629
|
-
### Example 1: Deploy Safe on
|
|
629
|
+
### Example 1: Deploy Safe on Base
|
|
630
630
|
|
|
631
631
|
```typescript
|
|
632
632
|
import { ZyfaiSDK } from "@zyfai/sdk";
|
|
@@ -638,12 +638,12 @@ async function main() {
|
|
|
638
638
|
});
|
|
639
639
|
|
|
640
640
|
// Connect account (automatically authenticates via SIWE)
|
|
641
|
-
await sdk.connectAccount(process.env.PRIVATE_KEY!,
|
|
641
|
+
await sdk.connectAccount(process.env.PRIVATE_KEY!, 8453);
|
|
642
642
|
|
|
643
643
|
const userAddress = "0xUser..."; // User's EOA address
|
|
644
644
|
|
|
645
645
|
// Check if Safe already exists
|
|
646
|
-
const walletInfo = await sdk.getSmartWalletAddress(userAddress,
|
|
646
|
+
const walletInfo = await sdk.getSmartWalletAddress(userAddress, 8453);
|
|
647
647
|
|
|
648
648
|
if (walletInfo.isDeployed) {
|
|
649
649
|
console.log("Safe already deployed at:", walletInfo.address);
|
|
@@ -651,7 +651,7 @@ async function main() {
|
|
|
651
651
|
}
|
|
652
652
|
|
|
653
653
|
// Deploy Safe
|
|
654
|
-
const result = await sdk.deploySafe(userAddress,
|
|
654
|
+
const result = await sdk.deploySafe(userAddress, 8453);
|
|
655
655
|
|
|
656
656
|
if (result.success) {
|
|
657
657
|
console.log("✅ Successfully deployed Safe");
|
|
@@ -692,7 +692,7 @@ function SafeDeployment() {
|
|
|
692
692
|
console.log("Connected and authenticated:", address);
|
|
693
693
|
|
|
694
694
|
// Get Safe address for this user
|
|
695
|
-
const walletInfo = await sdk.getSmartWalletAddress(address,
|
|
695
|
+
const walletInfo = await sdk.getSmartWalletAddress(address, 8453);
|
|
696
696
|
setSafeAddress(walletInfo.address);
|
|
697
697
|
} catch (error) {
|
|
698
698
|
console.error("Connection failed:", error);
|
|
@@ -704,7 +704,7 @@ function SafeDeployment() {
|
|
|
704
704
|
|
|
705
705
|
setIsDeploying(true);
|
|
706
706
|
try {
|
|
707
|
-
const result = await sdk.deploySafe(userAddress,
|
|
707
|
+
const result = await sdk.deploySafe(userAddress, 8453);
|
|
708
708
|
if (result.success) {
|
|
709
709
|
alert(`Safe deployed at ${result.safeAddress}`);
|
|
710
710
|
}
|
|
@@ -761,7 +761,7 @@ The SDK is built on top of:
|
|
|
761
761
|
```typescript
|
|
762
762
|
try {
|
|
763
763
|
const userAddress = "0xUser...";
|
|
764
|
-
const result = await sdk.deploySafe(userAddress,
|
|
764
|
+
const result = await sdk.deploySafe(userAddress, 8453);
|
|
765
765
|
if (!result.success) {
|
|
766
766
|
console.error("Deployment failed:", result.status);
|
|
767
767
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -437,7 +437,7 @@ declare class ZyfaiSDK {
|
|
|
437
437
|
* ```typescript
|
|
438
438
|
* await sdk.updateUserProfile({
|
|
439
439
|
* smartWallet: "0x1396730...",
|
|
440
|
-
* chains: [8453
|
|
440
|
+
* chains: [8453],
|
|
441
441
|
* });
|
|
442
442
|
* ```
|
|
443
443
|
*/
|
|
@@ -468,7 +468,7 @@ declare class ZyfaiSDK {
|
|
|
468
468
|
* Accepts either a private key string or a modern wallet provider
|
|
469
469
|
*
|
|
470
470
|
* @param account - Private key string or wallet provider object
|
|
471
|
-
* @param chainId - Target chain ID (default:
|
|
471
|
+
* @param chainId - Target chain ID (default: 8453 - Base)
|
|
472
472
|
* @returns The connected EOA address
|
|
473
473
|
*
|
|
474
474
|
* @example
|
|
@@ -563,10 +563,10 @@ declare class ZyfaiSDK {
|
|
|
563
563
|
*
|
|
564
564
|
* @example
|
|
565
565
|
* ```typescript
|
|
566
|
-
* // Deposit 100 USDC (6 decimals) to Safe on
|
|
566
|
+
* // Deposit 100 USDC (6 decimals) to Safe on Base
|
|
567
567
|
* const result = await sdk.depositFunds(
|
|
568
568
|
* "0xUser...",
|
|
569
|
-
*
|
|
569
|
+
* 8453,
|
|
570
570
|
* "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
|
|
571
571
|
* "100000000" // 100 USDC = 100 * 10^6
|
|
572
572
|
* );
|
|
@@ -587,13 +587,13 @@ declare class ZyfaiSDK {
|
|
|
587
587
|
* @example
|
|
588
588
|
* ```typescript
|
|
589
589
|
* // Full withdrawal
|
|
590
|
-
* const result = await sdk.withdrawFunds("0xUser...",
|
|
590
|
+
* const result = await sdk.withdrawFunds("0xUser...", 8453);
|
|
591
591
|
* console.log(result.message); // "Withdrawal request sent"
|
|
592
592
|
*
|
|
593
593
|
* // Partial withdrawal of 50 USDC (6 decimals)
|
|
594
594
|
* const result = await sdk.withdrawFunds(
|
|
595
595
|
* "0xUser...",
|
|
596
|
-
*
|
|
596
|
+
* 8453,
|
|
597
597
|
* "50000000", // 50 USDC = 50 * 10^6
|
|
598
598
|
* "0xReceiver..."
|
|
599
599
|
* );
|
|
@@ -608,7 +608,7 @@ declare class ZyfaiSDK {
|
|
|
608
608
|
*
|
|
609
609
|
* @example
|
|
610
610
|
* ```typescript
|
|
611
|
-
* const protocols = await sdk.getAvailableProtocols(
|
|
611
|
+
* const protocols = await sdk.getAvailableProtocols(8453);
|
|
612
612
|
* protocols.forEach(protocol => {
|
|
613
613
|
* console.log(`${protocol.name}: ${protocol.minApy}% - ${protocol.maxApy}% APY`);
|
|
614
614
|
* });
|
|
@@ -628,7 +628,7 @@ declare class ZyfaiSDK {
|
|
|
628
628
|
* const positions = await sdk.getPositions(userAddress);
|
|
629
629
|
*
|
|
630
630
|
* // Get positions on a specific chain
|
|
631
|
-
* const
|
|
631
|
+
* const basePositions = await sdk.getPositions(userAddress, 8453);
|
|
632
632
|
* ```
|
|
633
633
|
*/
|
|
634
634
|
getPositions(userAddress: string, chainId?: SupportedChainId): Promise<PositionsResponse>;
|
package/dist/index.d.ts
CHANGED
|
@@ -437,7 +437,7 @@ declare class ZyfaiSDK {
|
|
|
437
437
|
* ```typescript
|
|
438
438
|
* await sdk.updateUserProfile({
|
|
439
439
|
* smartWallet: "0x1396730...",
|
|
440
|
-
* chains: [8453
|
|
440
|
+
* chains: [8453],
|
|
441
441
|
* });
|
|
442
442
|
* ```
|
|
443
443
|
*/
|
|
@@ -468,7 +468,7 @@ declare class ZyfaiSDK {
|
|
|
468
468
|
* Accepts either a private key string or a modern wallet provider
|
|
469
469
|
*
|
|
470
470
|
* @param account - Private key string or wallet provider object
|
|
471
|
-
* @param chainId - Target chain ID (default:
|
|
471
|
+
* @param chainId - Target chain ID (default: 8453 - Base)
|
|
472
472
|
* @returns The connected EOA address
|
|
473
473
|
*
|
|
474
474
|
* @example
|
|
@@ -563,10 +563,10 @@ declare class ZyfaiSDK {
|
|
|
563
563
|
*
|
|
564
564
|
* @example
|
|
565
565
|
* ```typescript
|
|
566
|
-
* // Deposit 100 USDC (6 decimals) to Safe on
|
|
566
|
+
* // Deposit 100 USDC (6 decimals) to Safe on Base
|
|
567
567
|
* const result = await sdk.depositFunds(
|
|
568
568
|
* "0xUser...",
|
|
569
|
-
*
|
|
569
|
+
* 8453,
|
|
570
570
|
* "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
|
|
571
571
|
* "100000000" // 100 USDC = 100 * 10^6
|
|
572
572
|
* );
|
|
@@ -587,13 +587,13 @@ declare class ZyfaiSDK {
|
|
|
587
587
|
* @example
|
|
588
588
|
* ```typescript
|
|
589
589
|
* // Full withdrawal
|
|
590
|
-
* const result = await sdk.withdrawFunds("0xUser...",
|
|
590
|
+
* const result = await sdk.withdrawFunds("0xUser...", 8453);
|
|
591
591
|
* console.log(result.message); // "Withdrawal request sent"
|
|
592
592
|
*
|
|
593
593
|
* // Partial withdrawal of 50 USDC (6 decimals)
|
|
594
594
|
* const result = await sdk.withdrawFunds(
|
|
595
595
|
* "0xUser...",
|
|
596
|
-
*
|
|
596
|
+
* 8453,
|
|
597
597
|
* "50000000", // 50 USDC = 50 * 10^6
|
|
598
598
|
* "0xReceiver..."
|
|
599
599
|
* );
|
|
@@ -608,7 +608,7 @@ declare class ZyfaiSDK {
|
|
|
608
608
|
*
|
|
609
609
|
* @example
|
|
610
610
|
* ```typescript
|
|
611
|
-
* const protocols = await sdk.getAvailableProtocols(
|
|
611
|
+
* const protocols = await sdk.getAvailableProtocols(8453);
|
|
612
612
|
* protocols.forEach(protocol => {
|
|
613
613
|
* console.log(`${protocol.name}: ${protocol.minApy}% - ${protocol.maxApy}% APY`);
|
|
614
614
|
* });
|
|
@@ -628,7 +628,7 @@ declare class ZyfaiSDK {
|
|
|
628
628
|
* const positions = await sdk.getPositions(userAddress);
|
|
629
629
|
*
|
|
630
630
|
* // Get positions on a specific chain
|
|
631
|
-
* const
|
|
631
|
+
* const basePositions = await sdk.getPositions(userAddress, 8453);
|
|
632
632
|
* ```
|
|
633
633
|
*/
|
|
634
634
|
getPositions(userAddress: string, chainId?: SupportedChainId): Promise<PositionsResponse>;
|
package/dist/index.js
CHANGED
|
@@ -697,6 +697,7 @@ var ZyfaiSDK = class {
|
|
|
697
697
|
let uri;
|
|
698
698
|
let domain;
|
|
699
699
|
const globalWindow = typeof globalThis !== "undefined" ? globalThis.window : void 0;
|
|
700
|
+
const isNodeJs = !globalWindow?.location?.origin;
|
|
700
701
|
if (globalWindow?.location?.origin) {
|
|
701
702
|
uri = globalWindow.location.origin;
|
|
702
703
|
domain = globalWindow.location.host;
|
|
@@ -724,7 +725,13 @@ var ZyfaiSDK = class {
|
|
|
724
725
|
{
|
|
725
726
|
message: messageObj,
|
|
726
727
|
signature
|
|
727
|
-
}
|
|
728
|
+
},
|
|
729
|
+
// Set Origin header in Node.js to match message.uri (required by backend validation)
|
|
730
|
+
isNodeJs ? {
|
|
731
|
+
headers: {
|
|
732
|
+
Origin: uri
|
|
733
|
+
}
|
|
734
|
+
} : void 0
|
|
728
735
|
);
|
|
729
736
|
const authToken = loginResponse.accessToken;
|
|
730
737
|
if (!authToken) {
|
|
@@ -750,7 +757,7 @@ var ZyfaiSDK = class {
|
|
|
750
757
|
* ```typescript
|
|
751
758
|
* await sdk.updateUserProfile({
|
|
752
759
|
* smartWallet: "0x1396730...",
|
|
753
|
-
* chains: [8453
|
|
760
|
+
* chains: [8453],
|
|
754
761
|
* });
|
|
755
762
|
* ```
|
|
756
763
|
*/
|
|
@@ -827,7 +834,7 @@ var ZyfaiSDK = class {
|
|
|
827
834
|
this.httpClient.clearAuthToken();
|
|
828
835
|
if (this.walletClient && this.currentProvider) {
|
|
829
836
|
const chainConfig = getChainConfig(
|
|
830
|
-
this.walletClient.chain?.id ||
|
|
837
|
+
this.walletClient.chain?.id || 8453
|
|
831
838
|
);
|
|
832
839
|
this.walletClient = (0, import_viem4.createWalletClient)({
|
|
833
840
|
account: newAddress,
|
|
@@ -850,7 +857,7 @@ var ZyfaiSDK = class {
|
|
|
850
857
|
* Accepts either a private key string or a modern wallet provider
|
|
851
858
|
*
|
|
852
859
|
* @param account - Private key string or wallet provider object
|
|
853
|
-
* @param chainId - Target chain ID (default:
|
|
860
|
+
* @param chainId - Target chain ID (default: 8453 - Base)
|
|
854
861
|
* @returns The connected EOA address
|
|
855
862
|
*
|
|
856
863
|
* @example
|
|
@@ -862,7 +869,7 @@ var ZyfaiSDK = class {
|
|
|
862
869
|
* const provider = await connector.getProvider();
|
|
863
870
|
* await sdk.connectAccount(provider);
|
|
864
871
|
*/
|
|
865
|
-
async connectAccount(account, chainId =
|
|
872
|
+
async connectAccount(account, chainId = 8453) {
|
|
866
873
|
if (!isSupportedChain(chainId)) {
|
|
867
874
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
868
875
|
}
|
|
@@ -1307,10 +1314,10 @@ var ZyfaiSDK = class {
|
|
|
1307
1314
|
*
|
|
1308
1315
|
* @example
|
|
1309
1316
|
* ```typescript
|
|
1310
|
-
* // Deposit 100 USDC (6 decimals) to Safe on
|
|
1317
|
+
* // Deposit 100 USDC (6 decimals) to Safe on Base
|
|
1311
1318
|
* const result = await sdk.depositFunds(
|
|
1312
1319
|
* "0xUser...",
|
|
1313
|
-
*
|
|
1320
|
+
* 8453,
|
|
1314
1321
|
* "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
|
|
1315
1322
|
* "100000000" // 100 USDC = 100 * 10^6
|
|
1316
1323
|
* );
|
|
@@ -1388,13 +1395,13 @@ var ZyfaiSDK = class {
|
|
|
1388
1395
|
* @example
|
|
1389
1396
|
* ```typescript
|
|
1390
1397
|
* // Full withdrawal
|
|
1391
|
-
* const result = await sdk.withdrawFunds("0xUser...",
|
|
1398
|
+
* const result = await sdk.withdrawFunds("0xUser...", 8453);
|
|
1392
1399
|
* console.log(result.message); // "Withdrawal request sent"
|
|
1393
1400
|
*
|
|
1394
1401
|
* // Partial withdrawal of 50 USDC (6 decimals)
|
|
1395
1402
|
* const result = await sdk.withdrawFunds(
|
|
1396
1403
|
* "0xUser...",
|
|
1397
|
-
*
|
|
1404
|
+
* 8453,
|
|
1398
1405
|
* "50000000", // 50 USDC = 50 * 10^6
|
|
1399
1406
|
* "0xReceiver..."
|
|
1400
1407
|
* );
|
|
@@ -1480,7 +1487,7 @@ var ZyfaiSDK = class {
|
|
|
1480
1487
|
*
|
|
1481
1488
|
* @example
|
|
1482
1489
|
* ```typescript
|
|
1483
|
-
* const protocols = await sdk.getAvailableProtocols(
|
|
1490
|
+
* const protocols = await sdk.getAvailableProtocols(8453);
|
|
1484
1491
|
* protocols.forEach(protocol => {
|
|
1485
1492
|
* console.log(`${protocol.name}: ${protocol.minApy}% - ${protocol.maxApy}% APY`);
|
|
1486
1493
|
* });
|
|
@@ -1518,7 +1525,7 @@ var ZyfaiSDK = class {
|
|
|
1518
1525
|
* const positions = await sdk.getPositions(userAddress);
|
|
1519
1526
|
*
|
|
1520
1527
|
* // Get positions on a specific chain
|
|
1521
|
-
* const
|
|
1528
|
+
* const basePositions = await sdk.getPositions(userAddress, 8453);
|
|
1522
1529
|
* ```
|
|
1523
1530
|
*/
|
|
1524
1531
|
async getPositions(userAddress, chainId) {
|
package/dist/index.mjs
CHANGED
|
@@ -677,6 +677,7 @@ var ZyfaiSDK = class {
|
|
|
677
677
|
let uri;
|
|
678
678
|
let domain;
|
|
679
679
|
const globalWindow = typeof globalThis !== "undefined" ? globalThis.window : void 0;
|
|
680
|
+
const isNodeJs = !globalWindow?.location?.origin;
|
|
680
681
|
if (globalWindow?.location?.origin) {
|
|
681
682
|
uri = globalWindow.location.origin;
|
|
682
683
|
domain = globalWindow.location.host;
|
|
@@ -704,7 +705,13 @@ var ZyfaiSDK = class {
|
|
|
704
705
|
{
|
|
705
706
|
message: messageObj,
|
|
706
707
|
signature
|
|
707
|
-
}
|
|
708
|
+
},
|
|
709
|
+
// Set Origin header in Node.js to match message.uri (required by backend validation)
|
|
710
|
+
isNodeJs ? {
|
|
711
|
+
headers: {
|
|
712
|
+
Origin: uri
|
|
713
|
+
}
|
|
714
|
+
} : void 0
|
|
708
715
|
);
|
|
709
716
|
const authToken = loginResponse.accessToken;
|
|
710
717
|
if (!authToken) {
|
|
@@ -730,7 +737,7 @@ var ZyfaiSDK = class {
|
|
|
730
737
|
* ```typescript
|
|
731
738
|
* await sdk.updateUserProfile({
|
|
732
739
|
* smartWallet: "0x1396730...",
|
|
733
|
-
* chains: [8453
|
|
740
|
+
* chains: [8453],
|
|
734
741
|
* });
|
|
735
742
|
* ```
|
|
736
743
|
*/
|
|
@@ -807,7 +814,7 @@ var ZyfaiSDK = class {
|
|
|
807
814
|
this.httpClient.clearAuthToken();
|
|
808
815
|
if (this.walletClient && this.currentProvider) {
|
|
809
816
|
const chainConfig = getChainConfig(
|
|
810
|
-
this.walletClient.chain?.id ||
|
|
817
|
+
this.walletClient.chain?.id || 8453
|
|
811
818
|
);
|
|
812
819
|
this.walletClient = createWalletClient({
|
|
813
820
|
account: newAddress,
|
|
@@ -830,7 +837,7 @@ var ZyfaiSDK = class {
|
|
|
830
837
|
* Accepts either a private key string or a modern wallet provider
|
|
831
838
|
*
|
|
832
839
|
* @param account - Private key string or wallet provider object
|
|
833
|
-
* @param chainId - Target chain ID (default:
|
|
840
|
+
* @param chainId - Target chain ID (default: 8453 - Base)
|
|
834
841
|
* @returns The connected EOA address
|
|
835
842
|
*
|
|
836
843
|
* @example
|
|
@@ -842,7 +849,7 @@ var ZyfaiSDK = class {
|
|
|
842
849
|
* const provider = await connector.getProvider();
|
|
843
850
|
* await sdk.connectAccount(provider);
|
|
844
851
|
*/
|
|
845
|
-
async connectAccount(account, chainId =
|
|
852
|
+
async connectAccount(account, chainId = 8453) {
|
|
846
853
|
if (!isSupportedChain(chainId)) {
|
|
847
854
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
848
855
|
}
|
|
@@ -1287,10 +1294,10 @@ var ZyfaiSDK = class {
|
|
|
1287
1294
|
*
|
|
1288
1295
|
* @example
|
|
1289
1296
|
* ```typescript
|
|
1290
|
-
* // Deposit 100 USDC (6 decimals) to Safe on
|
|
1297
|
+
* // Deposit 100 USDC (6 decimals) to Safe on Base
|
|
1291
1298
|
* const result = await sdk.depositFunds(
|
|
1292
1299
|
* "0xUser...",
|
|
1293
|
-
*
|
|
1300
|
+
* 8453,
|
|
1294
1301
|
* "0xaf88d065e77c8cc2239327c5edb3a432268e5831", // USDC
|
|
1295
1302
|
* "100000000" // 100 USDC = 100 * 10^6
|
|
1296
1303
|
* );
|
|
@@ -1368,13 +1375,13 @@ var ZyfaiSDK = class {
|
|
|
1368
1375
|
* @example
|
|
1369
1376
|
* ```typescript
|
|
1370
1377
|
* // Full withdrawal
|
|
1371
|
-
* const result = await sdk.withdrawFunds("0xUser...",
|
|
1378
|
+
* const result = await sdk.withdrawFunds("0xUser...", 8453);
|
|
1372
1379
|
* console.log(result.message); // "Withdrawal request sent"
|
|
1373
1380
|
*
|
|
1374
1381
|
* // Partial withdrawal of 50 USDC (6 decimals)
|
|
1375
1382
|
* const result = await sdk.withdrawFunds(
|
|
1376
1383
|
* "0xUser...",
|
|
1377
|
-
*
|
|
1384
|
+
* 8453,
|
|
1378
1385
|
* "50000000", // 50 USDC = 50 * 10^6
|
|
1379
1386
|
* "0xReceiver..."
|
|
1380
1387
|
* );
|
|
@@ -1460,7 +1467,7 @@ var ZyfaiSDK = class {
|
|
|
1460
1467
|
*
|
|
1461
1468
|
* @example
|
|
1462
1469
|
* ```typescript
|
|
1463
|
-
* const protocols = await sdk.getAvailableProtocols(
|
|
1470
|
+
* const protocols = await sdk.getAvailableProtocols(8453);
|
|
1464
1471
|
* protocols.forEach(protocol => {
|
|
1465
1472
|
* console.log(`${protocol.name}: ${protocol.minApy}% - ${protocol.maxApy}% APY`);
|
|
1466
1473
|
* });
|
|
@@ -1498,7 +1505,7 @@ var ZyfaiSDK = class {
|
|
|
1498
1505
|
* const positions = await sdk.getPositions(userAddress);
|
|
1499
1506
|
*
|
|
1500
1507
|
* // Get positions on a specific chain
|
|
1501
|
-
* const
|
|
1508
|
+
* const basePositions = await sdk.getPositions(userAddress, 8453);
|
|
1502
1509
|
* ```
|
|
1503
1510
|
*/
|
|
1504
1511
|
async getPositions(userAddress, chainId) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
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",
|