@zyfai/sdk 0.1.7 → 0.1.8

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/dist/index.d.mts CHANGED
@@ -437,6 +437,21 @@ declare class ZyfaiSDK {
437
437
  * ```
438
438
  */
439
439
  updateUserProfile(request: UpdateUserProfileRequest): Promise<UpdateUserProfileResponse>;
440
+ /**
441
+ * Initialize user after Safe deployment
442
+ * This method is automatically called after deploySafe to initialize user state
443
+ *
444
+ * @param smartWallet - Safe smart wallet address
445
+ * @param chainId - Target chain ID
446
+ * @returns Initialization response
447
+ *
448
+ * @example
449
+ * ```typescript
450
+ * await sdk.initializeUser("0x1396730...", 8453);
451
+ * ```
452
+ * @internal
453
+ */
454
+ private initializeUser;
440
455
  /**
441
456
  * Handle account changes from wallet provider
442
457
  * Resets authentication state when wallet is switched
@@ -515,6 +530,14 @@ declare class ZyfaiSDK {
515
530
  * @private
516
531
  */
517
532
  private signSessionKey;
533
+ /**
534
+ * Update user protocols with available protocols from the chain
535
+ * This method is automatically called before activating session key
536
+ *
537
+ * @param chainId - Target chain ID
538
+ * @internal
539
+ */
540
+ private updateUserProtocols;
518
541
  /**
519
542
  * Activate session key via ZyFAI API
520
543
  */
package/dist/index.d.ts CHANGED
@@ -437,6 +437,21 @@ declare class ZyfaiSDK {
437
437
  * ```
438
438
  */
439
439
  updateUserProfile(request: UpdateUserProfileRequest): Promise<UpdateUserProfileResponse>;
440
+ /**
441
+ * Initialize user after Safe deployment
442
+ * This method is automatically called after deploySafe to initialize user state
443
+ *
444
+ * @param smartWallet - Safe smart wallet address
445
+ * @param chainId - Target chain ID
446
+ * @returns Initialization response
447
+ *
448
+ * @example
449
+ * ```typescript
450
+ * await sdk.initializeUser("0x1396730...", 8453);
451
+ * ```
452
+ * @internal
453
+ */
454
+ private initializeUser;
440
455
  /**
441
456
  * Handle account changes from wallet provider
442
457
  * Resets authentication state when wallet is switched
@@ -515,6 +530,14 @@ declare class ZyfaiSDK {
515
530
  * @private
516
531
  */
517
532
  private signSessionKey;
533
+ /**
534
+ * Update user protocols with available protocols from the chain
535
+ * This method is automatically called before activating session key
536
+ *
537
+ * @param chainId - Target chain ID
538
+ * @internal
539
+ */
540
+ private updateUserProtocols;
518
541
  /**
519
542
  * Activate session key via ZyFAI API
520
543
  */
package/dist/index.js CHANGED
@@ -57,6 +57,7 @@ var ENDPOINTS = {
57
57
  AUTH_CHALLENGE: "/auth/challenge",
58
58
  // User
59
59
  USER_ME: "/users/me",
60
+ USER_INITIALIZE: "/users/initialize",
60
61
  USER_WITHDRAW: "/users/withdraw",
61
62
  PARTIAL_WITHDRAW: "/users/partial-withdraw",
62
63
  // Session Keys
@@ -733,6 +734,43 @@ var ZyfaiSDK = class {
733
734
  );
734
735
  }
735
736
  }
737
+ /**
738
+ * Initialize user after Safe deployment
739
+ * This method is automatically called after deploySafe to initialize user state
740
+ *
741
+ * @param smartWallet - Safe smart wallet address
742
+ * @param chainId - Target chain ID
743
+ * @returns Initialization response
744
+ *
745
+ * @example
746
+ * ```typescript
747
+ * await sdk.initializeUser("0x1396730...", 8453);
748
+ * ```
749
+ * @internal
750
+ */
751
+ async initializeUser(smartWallet, chainId) {
752
+ try {
753
+ await this.authenticateUser();
754
+ const response = await this.httpClient.post(
755
+ ENDPOINTS.USER_INITIALIZE,
756
+ {
757
+ smartWallet,
758
+ chainId
759
+ }
760
+ );
761
+ return {
762
+ success: true,
763
+ userId: response.userId || response.id,
764
+ smartWallet: response.smartWallet,
765
+ chainId: response.chainId,
766
+ message: response.message
767
+ };
768
+ } catch (error) {
769
+ throw new Error(
770
+ `Failed to initialize user: ${error.message}`
771
+ );
772
+ }
773
+ }
736
774
  /**
737
775
  * Handle account changes from wallet provider
738
776
  * Resets authentication state when wallet is switched
@@ -1001,6 +1039,14 @@ var ZyfaiSDK = class {
1001
1039
  updateError.message
1002
1040
  );
1003
1041
  }
1042
+ try {
1043
+ await this.initializeUser(deploymentResult.safeAddress, chainId);
1044
+ } catch (initError) {
1045
+ console.warn(
1046
+ "Failed to initialize user after Safe deployment:",
1047
+ initError.message
1048
+ );
1049
+ }
1004
1050
  return {
1005
1051
  success: true,
1006
1052
  safeAddress: deploymentResult.safeAddress,
@@ -1061,6 +1107,7 @@ var ZyfaiSDK = class {
1061
1107
  if (!signatureResult.signature) {
1062
1108
  throw new Error("Failed to obtain session key signature");
1063
1109
  }
1110
+ await this.updateUserProtocols(chainId);
1064
1111
  const activation = await this.activateSessionKey(
1065
1112
  signatureResult.signature,
1066
1113
  signatureResult.sessionNonces
@@ -1136,6 +1183,30 @@ var ZyfaiSDK = class {
1136
1183
  );
1137
1184
  }
1138
1185
  }
1186
+ /**
1187
+ * Update user protocols with available protocols from the chain
1188
+ * This method is automatically called before activating session key
1189
+ *
1190
+ * @param chainId - Target chain ID
1191
+ * @internal
1192
+ */
1193
+ async updateUserProtocols(chainId) {
1194
+ try {
1195
+ const protocolsResponse = await this.getAvailableProtocols(chainId);
1196
+ if (!protocolsResponse.protocols || protocolsResponse.protocols.length === 0) {
1197
+ console.warn(`No protocols available for chain ${chainId}`);
1198
+ return;
1199
+ }
1200
+ const protocolIds = protocolsResponse.protocols.map((p) => p.id);
1201
+ await this.updateUserProfile({
1202
+ protocols: protocolIds
1203
+ });
1204
+ } catch (error) {
1205
+ console.warn(
1206
+ `Failed to update user protocols: ${error.message}`
1207
+ );
1208
+ }
1209
+ }
1139
1210
  /**
1140
1211
  * Activate session key via ZyFAI API
1141
1212
  */
package/dist/index.mjs CHANGED
@@ -18,6 +18,7 @@ var ENDPOINTS = {
18
18
  AUTH_CHALLENGE: "/auth/challenge",
19
19
  // User
20
20
  USER_ME: "/users/me",
21
+ USER_INITIALIZE: "/users/initialize",
21
22
  USER_WITHDRAW: "/users/withdraw",
22
23
  PARTIAL_WITHDRAW: "/users/partial-withdraw",
23
24
  // Session Keys
@@ -712,6 +713,43 @@ var ZyfaiSDK = class {
712
713
  );
713
714
  }
714
715
  }
716
+ /**
717
+ * Initialize user after Safe deployment
718
+ * This method is automatically called after deploySafe to initialize user state
719
+ *
720
+ * @param smartWallet - Safe smart wallet address
721
+ * @param chainId - Target chain ID
722
+ * @returns Initialization response
723
+ *
724
+ * @example
725
+ * ```typescript
726
+ * await sdk.initializeUser("0x1396730...", 8453);
727
+ * ```
728
+ * @internal
729
+ */
730
+ async initializeUser(smartWallet, chainId) {
731
+ try {
732
+ await this.authenticateUser();
733
+ const response = await this.httpClient.post(
734
+ ENDPOINTS.USER_INITIALIZE,
735
+ {
736
+ smartWallet,
737
+ chainId
738
+ }
739
+ );
740
+ return {
741
+ success: true,
742
+ userId: response.userId || response.id,
743
+ smartWallet: response.smartWallet,
744
+ chainId: response.chainId,
745
+ message: response.message
746
+ };
747
+ } catch (error) {
748
+ throw new Error(
749
+ `Failed to initialize user: ${error.message}`
750
+ );
751
+ }
752
+ }
715
753
  /**
716
754
  * Handle account changes from wallet provider
717
755
  * Resets authentication state when wallet is switched
@@ -980,6 +1018,14 @@ var ZyfaiSDK = class {
980
1018
  updateError.message
981
1019
  );
982
1020
  }
1021
+ try {
1022
+ await this.initializeUser(deploymentResult.safeAddress, chainId);
1023
+ } catch (initError) {
1024
+ console.warn(
1025
+ "Failed to initialize user after Safe deployment:",
1026
+ initError.message
1027
+ );
1028
+ }
983
1029
  return {
984
1030
  success: true,
985
1031
  safeAddress: deploymentResult.safeAddress,
@@ -1040,6 +1086,7 @@ var ZyfaiSDK = class {
1040
1086
  if (!signatureResult.signature) {
1041
1087
  throw new Error("Failed to obtain session key signature");
1042
1088
  }
1089
+ await this.updateUserProtocols(chainId);
1043
1090
  const activation = await this.activateSessionKey(
1044
1091
  signatureResult.signature,
1045
1092
  signatureResult.sessionNonces
@@ -1115,6 +1162,30 @@ var ZyfaiSDK = class {
1115
1162
  );
1116
1163
  }
1117
1164
  }
1165
+ /**
1166
+ * Update user protocols with available protocols from the chain
1167
+ * This method is automatically called before activating session key
1168
+ *
1169
+ * @param chainId - Target chain ID
1170
+ * @internal
1171
+ */
1172
+ async updateUserProtocols(chainId) {
1173
+ try {
1174
+ const protocolsResponse = await this.getAvailableProtocols(chainId);
1175
+ if (!protocolsResponse.protocols || protocolsResponse.protocols.length === 0) {
1176
+ console.warn(`No protocols available for chain ${chainId}`);
1177
+ return;
1178
+ }
1179
+ const protocolIds = protocolsResponse.protocols.map((p) => p.id);
1180
+ await this.updateUserProfile({
1181
+ protocols: protocolIds
1182
+ });
1183
+ } catch (error) {
1184
+ console.warn(
1185
+ `Failed to update user protocols: ${error.message}`
1186
+ );
1187
+ }
1188
+ }
1118
1189
  /**
1119
1190
  * Activate session key via ZyFAI API
1120
1191
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zyfai/sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
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",