@zyfai/sdk 0.2.3 → 0.2.5
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 +3 -1
- package/dist/index.d.mts +60 -1
- package/dist/index.d.ts +60 -1
- package/dist/index.js +108 -38
- package/dist/index.mjs +108 -38
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -258,6 +258,8 @@ console.log("Disconnected and cleared");
|
|
|
258
258
|
|
|
259
259
|
Get the Smart Wallet (Safe) address for a user.
|
|
260
260
|
|
|
261
|
+
**Note:** This is a **read-only** operation and does **not** require `connectAccount()`.
|
|
262
|
+
|
|
261
263
|
**Parameters:**
|
|
262
264
|
|
|
263
265
|
- `userAddress`: User's EOA address
|
|
@@ -861,7 +863,7 @@ CHAIN_ID=8453
|
|
|
861
863
|
|
|
862
864
|
### "No account connected" Error
|
|
863
865
|
|
|
864
|
-
Make sure to call `connectAccount()` before calling
|
|
866
|
+
Make sure to call `connectAccount()` before calling methods that require **signing or SIWE authentication** (e.g. `deploySafe`, `createSessionKey`, `withdrawFunds`, `updateUserProfile`). Read-only data methods (e.g. `getPositions`, `getHistory`, `getOnchainEarnings`) do not require a connected wallet.
|
|
865
867
|
|
|
866
868
|
### "Unsupported chain" Error
|
|
867
869
|
|
package/dist/index.d.mts
CHANGED
|
@@ -24,6 +24,7 @@ interface DeploySafeResponse {
|
|
|
24
24
|
/** @internal */
|
|
25
25
|
interface UpdateUserProfileRequest {
|
|
26
26
|
smartWallet?: string;
|
|
27
|
+
strategy?: string;
|
|
27
28
|
chains?: number[];
|
|
28
29
|
protocols?: string[];
|
|
29
30
|
autoSelectProtocols?: boolean;
|
|
@@ -34,6 +35,7 @@ interface UpdateUserProfileResponse {
|
|
|
34
35
|
userId: string;
|
|
35
36
|
smartWallet?: Address;
|
|
36
37
|
chains?: number[];
|
|
38
|
+
strategy?: string;
|
|
37
39
|
}
|
|
38
40
|
/** @internal */
|
|
39
41
|
interface AddSessionKeyResponse {
|
|
@@ -354,6 +356,26 @@ interface AddWalletToSdkResponse {
|
|
|
354
356
|
success: boolean;
|
|
355
357
|
message: string;
|
|
356
358
|
}
|
|
359
|
+
interface WalletTVL {
|
|
360
|
+
walletAddress: Address;
|
|
361
|
+
tvl: number;
|
|
362
|
+
positions?: {
|
|
363
|
+
chainId: number;
|
|
364
|
+
protocol: string;
|
|
365
|
+
amount: number;
|
|
366
|
+
}[];
|
|
367
|
+
}
|
|
368
|
+
interface SdkKeyTVLResponse {
|
|
369
|
+
success: boolean;
|
|
370
|
+
allowedWallets: Address[];
|
|
371
|
+
totalTvl: number;
|
|
372
|
+
tvlByWallet: WalletTVL[];
|
|
373
|
+
metadata?: {
|
|
374
|
+
sdkKeyId: string;
|
|
375
|
+
clientName: string;
|
|
376
|
+
walletsCount: number;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
357
379
|
interface PolicyData {
|
|
358
380
|
policy: Address;
|
|
359
381
|
initData: Hex;
|
|
@@ -870,6 +892,43 @@ declare class ZyfaiSDK {
|
|
|
870
892
|
* ```
|
|
871
893
|
*/
|
|
872
894
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
895
|
+
/**
|
|
896
|
+
* Get allowed wallets for the current SDK API key
|
|
897
|
+
* Returns the list of smart wallet addresses created via this SDK key
|
|
898
|
+
*
|
|
899
|
+
* @returns List of allowed wallet addresses with metadata
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
* ```typescript
|
|
903
|
+
* const result = await sdk.getSdkAllowedWallets();
|
|
904
|
+
* console.log("Allowed wallets:", result.allowedWallets);
|
|
905
|
+
* console.log("Total count:", result.metadata.walletsCount);
|
|
906
|
+
* ```
|
|
907
|
+
*/
|
|
908
|
+
getSdkAllowedWallets(): Promise<{
|
|
909
|
+
success: boolean;
|
|
910
|
+
allowedWallets: Address[];
|
|
911
|
+
metadata: {
|
|
912
|
+
sdkKeyId: string;
|
|
913
|
+
clientName: string;
|
|
914
|
+
walletsCount: number;
|
|
915
|
+
};
|
|
916
|
+
}>;
|
|
917
|
+
/**
|
|
918
|
+
* Get total TVL for all wallets under the current SDK API key
|
|
919
|
+
* This method calculates the total value locked across all wallets created via this SDK key
|
|
920
|
+
*
|
|
921
|
+
* @returns SDK key TVL information including allowed wallets and their individual/total TVL
|
|
922
|
+
*
|
|
923
|
+
* @example
|
|
924
|
+
* ```typescript
|
|
925
|
+
* const sdkTvl = await sdk.getSdkKeyTVL();
|
|
926
|
+
* console.log("Total TVL across all SDK wallets:", sdkTvl.totalTvl);
|
|
927
|
+
* console.log("Number of wallets:", sdkTvl.allowedWallets.length);
|
|
928
|
+
* console.log("TVL by wallet:", sdkTvl.tvlByWallet);
|
|
929
|
+
* ```
|
|
930
|
+
*/
|
|
931
|
+
getSdkKeyTVL(): Promise<SdkKeyTVLResponse>;
|
|
873
932
|
}
|
|
874
933
|
|
|
875
|
-
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type SDKConfig, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
|
934
|
+
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ interface DeploySafeResponse {
|
|
|
24
24
|
/** @internal */
|
|
25
25
|
interface UpdateUserProfileRequest {
|
|
26
26
|
smartWallet?: string;
|
|
27
|
+
strategy?: string;
|
|
27
28
|
chains?: number[];
|
|
28
29
|
protocols?: string[];
|
|
29
30
|
autoSelectProtocols?: boolean;
|
|
@@ -34,6 +35,7 @@ interface UpdateUserProfileResponse {
|
|
|
34
35
|
userId: string;
|
|
35
36
|
smartWallet?: Address;
|
|
36
37
|
chains?: number[];
|
|
38
|
+
strategy?: string;
|
|
37
39
|
}
|
|
38
40
|
/** @internal */
|
|
39
41
|
interface AddSessionKeyResponse {
|
|
@@ -354,6 +356,26 @@ interface AddWalletToSdkResponse {
|
|
|
354
356
|
success: boolean;
|
|
355
357
|
message: string;
|
|
356
358
|
}
|
|
359
|
+
interface WalletTVL {
|
|
360
|
+
walletAddress: Address;
|
|
361
|
+
tvl: number;
|
|
362
|
+
positions?: {
|
|
363
|
+
chainId: number;
|
|
364
|
+
protocol: string;
|
|
365
|
+
amount: number;
|
|
366
|
+
}[];
|
|
367
|
+
}
|
|
368
|
+
interface SdkKeyTVLResponse {
|
|
369
|
+
success: boolean;
|
|
370
|
+
allowedWallets: Address[];
|
|
371
|
+
totalTvl: number;
|
|
372
|
+
tvlByWallet: WalletTVL[];
|
|
373
|
+
metadata?: {
|
|
374
|
+
sdkKeyId: string;
|
|
375
|
+
clientName: string;
|
|
376
|
+
walletsCount: number;
|
|
377
|
+
};
|
|
378
|
+
}
|
|
357
379
|
interface PolicyData {
|
|
358
380
|
policy: Address;
|
|
359
381
|
initData: Hex;
|
|
@@ -870,6 +892,43 @@ declare class ZyfaiSDK {
|
|
|
870
892
|
* ```
|
|
871
893
|
*/
|
|
872
894
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
895
|
+
/**
|
|
896
|
+
* Get allowed wallets for the current SDK API key
|
|
897
|
+
* Returns the list of smart wallet addresses created via this SDK key
|
|
898
|
+
*
|
|
899
|
+
* @returns List of allowed wallet addresses with metadata
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
* ```typescript
|
|
903
|
+
* const result = await sdk.getSdkAllowedWallets();
|
|
904
|
+
* console.log("Allowed wallets:", result.allowedWallets);
|
|
905
|
+
* console.log("Total count:", result.metadata.walletsCount);
|
|
906
|
+
* ```
|
|
907
|
+
*/
|
|
908
|
+
getSdkAllowedWallets(): Promise<{
|
|
909
|
+
success: boolean;
|
|
910
|
+
allowedWallets: Address[];
|
|
911
|
+
metadata: {
|
|
912
|
+
sdkKeyId: string;
|
|
913
|
+
clientName: string;
|
|
914
|
+
walletsCount: number;
|
|
915
|
+
};
|
|
916
|
+
}>;
|
|
917
|
+
/**
|
|
918
|
+
* Get total TVL for all wallets under the current SDK API key
|
|
919
|
+
* This method calculates the total value locked across all wallets created via this SDK key
|
|
920
|
+
*
|
|
921
|
+
* @returns SDK key TVL information including allowed wallets and their individual/total TVL
|
|
922
|
+
*
|
|
923
|
+
* @example
|
|
924
|
+
* ```typescript
|
|
925
|
+
* const sdkTvl = await sdk.getSdkKeyTVL();
|
|
926
|
+
* console.log("Total TVL across all SDK wallets:", sdkTvl.totalTvl);
|
|
927
|
+
* console.log("Number of wallets:", sdkTvl.allowedWallets.length);
|
|
928
|
+
* console.log("TVL by wallet:", sdkTvl.tvlByWallet);
|
|
929
|
+
* ```
|
|
930
|
+
*/
|
|
931
|
+
getSdkKeyTVL(): Promise<SdkKeyTVLResponse>;
|
|
873
932
|
}
|
|
874
933
|
|
|
875
|
-
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type SDKConfig, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
|
934
|
+
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type ChainConfig, type ChainPortfolio, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DeploySafeResponse, type DepositResponse, type ERC7739Context, type ERC7739Data, type FirstTopupResponse, type Hex, type HistoryEntry, type HistoryPosition, type HistoryResponse, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type PolicyData, type Pool, type PortfolioToken, type Position, type PositionSlot, type PositionsResponse, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type SDKConfig, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedChainId, type TVLResponse, type UserDetails, type UserDetailsResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, ZyfaiSDK, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
package/dist/index.js
CHANGED
|
@@ -55,6 +55,7 @@ var ENDPOINTS = {
|
|
|
55
55
|
USER_ME: "/users/me",
|
|
56
56
|
USER_WITHDRAW: "/users/withdraw",
|
|
57
57
|
PARTIAL_WITHDRAW: "/users/partial-withdraw",
|
|
58
|
+
LOG_DEPOSIT: "/users/log_deposit",
|
|
58
59
|
// Safe Deployment (single endpoint)
|
|
59
60
|
SAFE_DEPLOY: "/users/safe-deploy",
|
|
60
61
|
// Session Keys
|
|
@@ -70,7 +71,10 @@ var ENDPOINTS = {
|
|
|
70
71
|
DATA_FIRST_TOPUP: (walletAddress, chainId) => `/data/first-topup?walletAddress=${walletAddress}&chainId=${chainId}`,
|
|
71
72
|
DATA_ACTIVE_WALLETS: (chainId) => `/data/active-wallets?chainId=${chainId}`,
|
|
72
73
|
DATA_BY_EOA: (address) => `/data/by-eoa?address=${address}`,
|
|
73
|
-
DATA_REBALANCE_FREQUENCY: (walletAddress) => `/data/rebalance-frequency?walletAddress=${walletAddress}
|
|
74
|
+
DATA_REBALANCE_FREQUENCY: (walletAddress) => `/data/rebalance-frequency?walletAddress=${walletAddress}`,
|
|
75
|
+
// SDK Keys
|
|
76
|
+
SDK_ALLOWED_WALLETS: "/data/sdk-allowed-wallets",
|
|
77
|
+
SDK_TVL: "/data/sdk-tvl"
|
|
74
78
|
};
|
|
75
79
|
var DATA_ENDPOINTS = {
|
|
76
80
|
// User Initialization
|
|
@@ -437,33 +441,18 @@ var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
|
437
441
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
438
442
|
var ACCOUNT_SALT = "zyfai";
|
|
439
443
|
var getSafeAccount = async (config) => {
|
|
440
|
-
const {
|
|
441
|
-
if (!
|
|
442
|
-
throw new Error("
|
|
443
|
-
}
|
|
444
|
-
const signerAddress = owner.account.address;
|
|
445
|
-
if (!signerAddress) {
|
|
446
|
-
throw new Error("Owner account address is required");
|
|
447
|
-
}
|
|
448
|
-
const effectiveOwnerAddress = safeOwnerAddress || signerAddress;
|
|
449
|
-
if (!effectiveOwnerAddress) {
|
|
450
|
-
throw new Error("Address is required");
|
|
451
|
-
}
|
|
452
|
-
const formattedEffectiveAddress = (0, import_viem3.getAddress)(effectiveOwnerAddress);
|
|
453
|
-
const isReadOnly = safeOwnerAddress && safeOwnerAddress.toLowerCase() !== signerAddress.toLowerCase();
|
|
454
|
-
if (!isReadOnly && safeOwnerAddress && safeOwnerAddress.toLowerCase() !== signerAddress.toLowerCase()) {
|
|
455
|
-
throw new Error(
|
|
456
|
-
`Connected wallet address (${signerAddress}) must match the Safe owner address (${safeOwnerAddress}). Please connect with the correct wallet.`
|
|
457
|
-
);
|
|
444
|
+
const { safeOwnerAddress, publicClient } = config;
|
|
445
|
+
if (!safeOwnerAddress) {
|
|
446
|
+
throw new Error("Safe owner address is required");
|
|
458
447
|
}
|
|
448
|
+
const formattedOwnerAddress = (0, import_viem3.getAddress)(safeOwnerAddress);
|
|
459
449
|
const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
|
|
460
|
-
owners: [
|
|
461
|
-
// Use formatted effective owner address for validator
|
|
450
|
+
owners: [formattedOwnerAddress],
|
|
462
451
|
threshold: 1
|
|
463
452
|
});
|
|
464
453
|
const saltHex = (0, import_viem3.fromHex)((0, import_viem3.toHex)(ACCOUNT_SALT), "bigint");
|
|
465
454
|
const tempOwner = {
|
|
466
|
-
address:
|
|
455
|
+
address: formattedOwnerAddress,
|
|
467
456
|
type: "json-rpc"
|
|
468
457
|
};
|
|
469
458
|
const safeAccount = await (0, import_accounts.toSafeSmartAccount)({
|
|
@@ -648,6 +637,9 @@ function toPublicStrategy(internalStrategy) {
|
|
|
648
637
|
`Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy" or "degen_strategy".`
|
|
649
638
|
);
|
|
650
639
|
}
|
|
640
|
+
function isValidPublicStrategy(strategy) {
|
|
641
|
+
return strategy === "conservative" || strategy === "aggressive";
|
|
642
|
+
}
|
|
651
643
|
function convertStrategyToPublic(obj) {
|
|
652
644
|
if (!obj.strategy) {
|
|
653
645
|
return obj;
|
|
@@ -771,15 +763,27 @@ var ZyfaiSDK = class {
|
|
|
771
763
|
async updateUserProfile(request) {
|
|
772
764
|
try {
|
|
773
765
|
await this.authenticateUser();
|
|
766
|
+
const payload = { ...request };
|
|
767
|
+
if (payload.strategy) {
|
|
768
|
+
if (!isValidPublicStrategy(payload.strategy)) {
|
|
769
|
+
throw new Error(
|
|
770
|
+
`Invalid strategy: ${payload.strategy}. Must be "conservative" or "aggressive".`
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
payload.strategy = toInternalStrategy(
|
|
774
|
+
payload.strategy
|
|
775
|
+
);
|
|
776
|
+
}
|
|
774
777
|
const response = await this.httpClient.patch(
|
|
775
778
|
ENDPOINTS.USER_ME,
|
|
776
|
-
|
|
779
|
+
payload
|
|
777
780
|
);
|
|
778
781
|
return {
|
|
779
782
|
success: true,
|
|
780
783
|
userId: response.userId || response.id,
|
|
781
784
|
smartWallet: response.smartWallet,
|
|
782
|
-
chains: response.chains
|
|
785
|
+
chains: response.chains,
|
|
786
|
+
strategy: response.strategy
|
|
783
787
|
};
|
|
784
788
|
} catch (error) {
|
|
785
789
|
throw new Error(
|
|
@@ -1027,9 +1031,7 @@ var ZyfaiSDK = class {
|
|
|
1027
1031
|
}
|
|
1028
1032
|
} catch {
|
|
1029
1033
|
}
|
|
1030
|
-
const walletClient = this.getWalletClient(chainId);
|
|
1031
1034
|
const safeAddress = await getDeterministicSafeAddress({
|
|
1032
|
-
owner: walletClient,
|
|
1033
1035
|
safeOwnerAddress: userAddress,
|
|
1034
1036
|
chain: chainConfig.chain,
|
|
1035
1037
|
publicClient: chainConfig.publicClient
|
|
@@ -1072,7 +1074,6 @@ var ZyfaiSDK = class {
|
|
|
1072
1074
|
const walletClient = this.getWalletClient(chainId);
|
|
1073
1075
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1074
1076
|
const safeAddress = await getDeterministicSafeAddress({
|
|
1075
|
-
owner: walletClient,
|
|
1076
1077
|
safeOwnerAddress: userAddress,
|
|
1077
1078
|
chain: chainConfig.chain,
|
|
1078
1079
|
publicClient: chainConfig.publicClient
|
|
@@ -1257,12 +1258,6 @@ var ZyfaiSDK = class {
|
|
|
1257
1258
|
allPublicClients,
|
|
1258
1259
|
signingParams
|
|
1259
1260
|
);
|
|
1260
|
-
const safeAddress = await getDeterministicSafeAddress({
|
|
1261
|
-
owner: walletClient,
|
|
1262
|
-
safeOwnerAddress: userAddress,
|
|
1263
|
-
chain: chainConfig.chain,
|
|
1264
|
-
publicClient: chainConfig.publicClient
|
|
1265
|
-
});
|
|
1266
1261
|
return {
|
|
1267
1262
|
success: true,
|
|
1268
1263
|
signature,
|
|
@@ -1368,7 +1363,6 @@ var ZyfaiSDK = class {
|
|
|
1368
1363
|
const walletClient = this.getWalletClient();
|
|
1369
1364
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1370
1365
|
const safeAddress = await getDeterministicSafeAddress({
|
|
1371
|
-
owner: walletClient,
|
|
1372
1366
|
safeOwnerAddress: userAddress,
|
|
1373
1367
|
chain: chainConfig.chain,
|
|
1374
1368
|
publicClient: chainConfig.publicClient
|
|
@@ -1394,6 +1388,16 @@ var ZyfaiSDK = class {
|
|
|
1394
1388
|
const receipt = await chainConfig.publicClient.waitForTransactionReceipt({
|
|
1395
1389
|
hash: txHash
|
|
1396
1390
|
});
|
|
1391
|
+
try {
|
|
1392
|
+
await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
|
|
1393
|
+
chainId,
|
|
1394
|
+
transaction: txHash,
|
|
1395
|
+
token,
|
|
1396
|
+
amount
|
|
1397
|
+
});
|
|
1398
|
+
} catch (logError) {
|
|
1399
|
+
console.warn("Failed to log deposit:", logError.message);
|
|
1400
|
+
}
|
|
1397
1401
|
if (receipt.status !== "success") {
|
|
1398
1402
|
throw new Error("Deposit transaction failed");
|
|
1399
1403
|
}
|
|
@@ -1447,18 +1451,14 @@ var ZyfaiSDK = class {
|
|
|
1447
1451
|
if (smartWalletInfo.smartWallet) {
|
|
1448
1452
|
safeAddress = smartWalletInfo.smartWallet;
|
|
1449
1453
|
} else {
|
|
1450
|
-
const walletClient = this.getWalletClient();
|
|
1451
1454
|
safeAddress = await getDeterministicSafeAddress({
|
|
1452
|
-
owner: walletClient,
|
|
1453
1455
|
safeOwnerAddress: userAddress,
|
|
1454
1456
|
chain: chainConfig.chain,
|
|
1455
1457
|
publicClient: chainConfig.publicClient
|
|
1456
1458
|
});
|
|
1457
1459
|
}
|
|
1458
1460
|
} catch {
|
|
1459
|
-
const walletClient = this.getWalletClient();
|
|
1460
1461
|
safeAddress = await getDeterministicSafeAddress({
|
|
1461
|
-
owner: walletClient,
|
|
1462
1462
|
safeOwnerAddress: userAddress,
|
|
1463
1463
|
chain: chainConfig.chain,
|
|
1464
1464
|
publicClient: chainConfig.publicClient
|
|
@@ -2192,6 +2192,76 @@ var ZyfaiSDK = class {
|
|
|
2192
2192
|
);
|
|
2193
2193
|
}
|
|
2194
2194
|
}
|
|
2195
|
+
// ============================================================================
|
|
2196
|
+
// SDK Key Methods
|
|
2197
|
+
// ============================================================================
|
|
2198
|
+
/**
|
|
2199
|
+
* Get allowed wallets for the current SDK API key
|
|
2200
|
+
* Returns the list of smart wallet addresses created via this SDK key
|
|
2201
|
+
*
|
|
2202
|
+
* @returns List of allowed wallet addresses with metadata
|
|
2203
|
+
*
|
|
2204
|
+
* @example
|
|
2205
|
+
* ```typescript
|
|
2206
|
+
* const result = await sdk.getSdkAllowedWallets();
|
|
2207
|
+
* console.log("Allowed wallets:", result.allowedWallets);
|
|
2208
|
+
* console.log("Total count:", result.metadata.walletsCount);
|
|
2209
|
+
* ```
|
|
2210
|
+
*/
|
|
2211
|
+
async getSdkAllowedWallets() {
|
|
2212
|
+
try {
|
|
2213
|
+
const response = await this.httpClient.get(
|
|
2214
|
+
ENDPOINTS.SDK_ALLOWED_WALLETS
|
|
2215
|
+
);
|
|
2216
|
+
return {
|
|
2217
|
+
success: response.success || true,
|
|
2218
|
+
allowedWallets: response.allowedWallets || [],
|
|
2219
|
+
metadata: response.metadata || {
|
|
2220
|
+
sdkKeyId: "",
|
|
2221
|
+
clientName: "",
|
|
2222
|
+
walletsCount: 0
|
|
2223
|
+
}
|
|
2224
|
+
};
|
|
2225
|
+
} catch (error) {
|
|
2226
|
+
throw new Error(
|
|
2227
|
+
`Failed to get SDK allowed wallets: ${error.message}`
|
|
2228
|
+
);
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
/**
|
|
2232
|
+
* Get total TVL for all wallets under the current SDK API key
|
|
2233
|
+
* This method calculates the total value locked across all wallets created via this SDK key
|
|
2234
|
+
*
|
|
2235
|
+
* @returns SDK key TVL information including allowed wallets and their individual/total TVL
|
|
2236
|
+
*
|
|
2237
|
+
* @example
|
|
2238
|
+
* ```typescript
|
|
2239
|
+
* const sdkTvl = await sdk.getSdkKeyTVL();
|
|
2240
|
+
* console.log("Total TVL across all SDK wallets:", sdkTvl.totalTvl);
|
|
2241
|
+
* console.log("Number of wallets:", sdkTvl.allowedWallets.length);
|
|
2242
|
+
* console.log("TVL by wallet:", sdkTvl.tvlByWallet);
|
|
2243
|
+
* ```
|
|
2244
|
+
*/
|
|
2245
|
+
async getSdkKeyTVL() {
|
|
2246
|
+
try {
|
|
2247
|
+
const response = await this.httpClient.get(ENDPOINTS.SDK_TVL);
|
|
2248
|
+
return {
|
|
2249
|
+
success: response.success || true,
|
|
2250
|
+
allowedWallets: response.allowedWallets || [],
|
|
2251
|
+
totalTvl: response.totalTvl || 0,
|
|
2252
|
+
tvlByWallet: response.tvlByWallet || [],
|
|
2253
|
+
metadata: response.metadata || {
|
|
2254
|
+
sdkKeyId: "",
|
|
2255
|
+
clientName: "",
|
|
2256
|
+
walletsCount: 0
|
|
2257
|
+
}
|
|
2258
|
+
};
|
|
2259
|
+
} catch (error) {
|
|
2260
|
+
throw new Error(
|
|
2261
|
+
`Failed to get SDK key TVL: ${error.message}`
|
|
2262
|
+
);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2195
2265
|
};
|
|
2196
2266
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2197
2267
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -14,6 +14,7 @@ var ENDPOINTS = {
|
|
|
14
14
|
USER_ME: "/users/me",
|
|
15
15
|
USER_WITHDRAW: "/users/withdraw",
|
|
16
16
|
PARTIAL_WITHDRAW: "/users/partial-withdraw",
|
|
17
|
+
LOG_DEPOSIT: "/users/log_deposit",
|
|
17
18
|
// Safe Deployment (single endpoint)
|
|
18
19
|
SAFE_DEPLOY: "/users/safe-deploy",
|
|
19
20
|
// Session Keys
|
|
@@ -29,7 +30,10 @@ var ENDPOINTS = {
|
|
|
29
30
|
DATA_FIRST_TOPUP: (walletAddress, chainId) => `/data/first-topup?walletAddress=${walletAddress}&chainId=${chainId}`,
|
|
30
31
|
DATA_ACTIVE_WALLETS: (chainId) => `/data/active-wallets?chainId=${chainId}`,
|
|
31
32
|
DATA_BY_EOA: (address) => `/data/by-eoa?address=${address}`,
|
|
32
|
-
DATA_REBALANCE_FREQUENCY: (walletAddress) => `/data/rebalance-frequency?walletAddress=${walletAddress}
|
|
33
|
+
DATA_REBALANCE_FREQUENCY: (walletAddress) => `/data/rebalance-frequency?walletAddress=${walletAddress}`,
|
|
34
|
+
// SDK Keys
|
|
35
|
+
SDK_ALLOWED_WALLETS: "/data/sdk-allowed-wallets",
|
|
36
|
+
SDK_TVL: "/data/sdk-tvl"
|
|
33
37
|
};
|
|
34
38
|
var DATA_ENDPOINTS = {
|
|
35
39
|
// User Initialization
|
|
@@ -414,33 +418,18 @@ var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
|
414
418
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
415
419
|
var ACCOUNT_SALT = "zyfai";
|
|
416
420
|
var getSafeAccount = async (config) => {
|
|
417
|
-
const {
|
|
418
|
-
if (!
|
|
419
|
-
throw new Error("
|
|
420
|
-
}
|
|
421
|
-
const signerAddress = owner.account.address;
|
|
422
|
-
if (!signerAddress) {
|
|
423
|
-
throw new Error("Owner account address is required");
|
|
424
|
-
}
|
|
425
|
-
const effectiveOwnerAddress = safeOwnerAddress || signerAddress;
|
|
426
|
-
if (!effectiveOwnerAddress) {
|
|
427
|
-
throw new Error("Address is required");
|
|
428
|
-
}
|
|
429
|
-
const formattedEffectiveAddress = getAddress(effectiveOwnerAddress);
|
|
430
|
-
const isReadOnly = safeOwnerAddress && safeOwnerAddress.toLowerCase() !== signerAddress.toLowerCase();
|
|
431
|
-
if (!isReadOnly && safeOwnerAddress && safeOwnerAddress.toLowerCase() !== signerAddress.toLowerCase()) {
|
|
432
|
-
throw new Error(
|
|
433
|
-
`Connected wallet address (${signerAddress}) must match the Safe owner address (${safeOwnerAddress}). Please connect with the correct wallet.`
|
|
434
|
-
);
|
|
421
|
+
const { safeOwnerAddress, publicClient } = config;
|
|
422
|
+
if (!safeOwnerAddress) {
|
|
423
|
+
throw new Error("Safe owner address is required");
|
|
435
424
|
}
|
|
425
|
+
const formattedOwnerAddress = getAddress(safeOwnerAddress);
|
|
436
426
|
const ownableValidator = getOwnableValidator({
|
|
437
|
-
owners: [
|
|
438
|
-
// Use formatted effective owner address for validator
|
|
427
|
+
owners: [formattedOwnerAddress],
|
|
439
428
|
threshold: 1
|
|
440
429
|
});
|
|
441
430
|
const saltHex = fromHex(toHex(ACCOUNT_SALT), "bigint");
|
|
442
431
|
const tempOwner = {
|
|
443
|
-
address:
|
|
432
|
+
address: formattedOwnerAddress,
|
|
444
433
|
type: "json-rpc"
|
|
445
434
|
};
|
|
446
435
|
const safeAccount = await toSafeSmartAccount({
|
|
@@ -625,6 +614,9 @@ function toPublicStrategy(internalStrategy) {
|
|
|
625
614
|
`Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy" or "degen_strategy".`
|
|
626
615
|
);
|
|
627
616
|
}
|
|
617
|
+
function isValidPublicStrategy(strategy) {
|
|
618
|
+
return strategy === "conservative" || strategy === "aggressive";
|
|
619
|
+
}
|
|
628
620
|
function convertStrategyToPublic(obj) {
|
|
629
621
|
if (!obj.strategy) {
|
|
630
622
|
return obj;
|
|
@@ -748,15 +740,27 @@ var ZyfaiSDK = class {
|
|
|
748
740
|
async updateUserProfile(request) {
|
|
749
741
|
try {
|
|
750
742
|
await this.authenticateUser();
|
|
743
|
+
const payload = { ...request };
|
|
744
|
+
if (payload.strategy) {
|
|
745
|
+
if (!isValidPublicStrategy(payload.strategy)) {
|
|
746
|
+
throw new Error(
|
|
747
|
+
`Invalid strategy: ${payload.strategy}. Must be "conservative" or "aggressive".`
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
payload.strategy = toInternalStrategy(
|
|
751
|
+
payload.strategy
|
|
752
|
+
);
|
|
753
|
+
}
|
|
751
754
|
const response = await this.httpClient.patch(
|
|
752
755
|
ENDPOINTS.USER_ME,
|
|
753
|
-
|
|
756
|
+
payload
|
|
754
757
|
);
|
|
755
758
|
return {
|
|
756
759
|
success: true,
|
|
757
760
|
userId: response.userId || response.id,
|
|
758
761
|
smartWallet: response.smartWallet,
|
|
759
|
-
chains: response.chains
|
|
762
|
+
chains: response.chains,
|
|
763
|
+
strategy: response.strategy
|
|
760
764
|
};
|
|
761
765
|
} catch (error) {
|
|
762
766
|
throw new Error(
|
|
@@ -1004,9 +1008,7 @@ var ZyfaiSDK = class {
|
|
|
1004
1008
|
}
|
|
1005
1009
|
} catch {
|
|
1006
1010
|
}
|
|
1007
|
-
const walletClient = this.getWalletClient(chainId);
|
|
1008
1011
|
const safeAddress = await getDeterministicSafeAddress({
|
|
1009
|
-
owner: walletClient,
|
|
1010
1012
|
safeOwnerAddress: userAddress,
|
|
1011
1013
|
chain: chainConfig.chain,
|
|
1012
1014
|
publicClient: chainConfig.publicClient
|
|
@@ -1049,7 +1051,6 @@ var ZyfaiSDK = class {
|
|
|
1049
1051
|
const walletClient = this.getWalletClient(chainId);
|
|
1050
1052
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1051
1053
|
const safeAddress = await getDeterministicSafeAddress({
|
|
1052
|
-
owner: walletClient,
|
|
1053
1054
|
safeOwnerAddress: userAddress,
|
|
1054
1055
|
chain: chainConfig.chain,
|
|
1055
1056
|
publicClient: chainConfig.publicClient
|
|
@@ -1234,12 +1235,6 @@ var ZyfaiSDK = class {
|
|
|
1234
1235
|
allPublicClients,
|
|
1235
1236
|
signingParams
|
|
1236
1237
|
);
|
|
1237
|
-
const safeAddress = await getDeterministicSafeAddress({
|
|
1238
|
-
owner: walletClient,
|
|
1239
|
-
safeOwnerAddress: userAddress,
|
|
1240
|
-
chain: chainConfig.chain,
|
|
1241
|
-
publicClient: chainConfig.publicClient
|
|
1242
|
-
});
|
|
1243
1238
|
return {
|
|
1244
1239
|
success: true,
|
|
1245
1240
|
signature,
|
|
@@ -1345,7 +1340,6 @@ var ZyfaiSDK = class {
|
|
|
1345
1340
|
const walletClient = this.getWalletClient();
|
|
1346
1341
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1347
1342
|
const safeAddress = await getDeterministicSafeAddress({
|
|
1348
|
-
owner: walletClient,
|
|
1349
1343
|
safeOwnerAddress: userAddress,
|
|
1350
1344
|
chain: chainConfig.chain,
|
|
1351
1345
|
publicClient: chainConfig.publicClient
|
|
@@ -1371,6 +1365,16 @@ var ZyfaiSDK = class {
|
|
|
1371
1365
|
const receipt = await chainConfig.publicClient.waitForTransactionReceipt({
|
|
1372
1366
|
hash: txHash
|
|
1373
1367
|
});
|
|
1368
|
+
try {
|
|
1369
|
+
await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
|
|
1370
|
+
chainId,
|
|
1371
|
+
transaction: txHash,
|
|
1372
|
+
token,
|
|
1373
|
+
amount
|
|
1374
|
+
});
|
|
1375
|
+
} catch (logError) {
|
|
1376
|
+
console.warn("Failed to log deposit:", logError.message);
|
|
1377
|
+
}
|
|
1374
1378
|
if (receipt.status !== "success") {
|
|
1375
1379
|
throw new Error("Deposit transaction failed");
|
|
1376
1380
|
}
|
|
@@ -1424,18 +1428,14 @@ var ZyfaiSDK = class {
|
|
|
1424
1428
|
if (smartWalletInfo.smartWallet) {
|
|
1425
1429
|
safeAddress = smartWalletInfo.smartWallet;
|
|
1426
1430
|
} else {
|
|
1427
|
-
const walletClient = this.getWalletClient();
|
|
1428
1431
|
safeAddress = await getDeterministicSafeAddress({
|
|
1429
|
-
owner: walletClient,
|
|
1430
1432
|
safeOwnerAddress: userAddress,
|
|
1431
1433
|
chain: chainConfig.chain,
|
|
1432
1434
|
publicClient: chainConfig.publicClient
|
|
1433
1435
|
});
|
|
1434
1436
|
}
|
|
1435
1437
|
} catch {
|
|
1436
|
-
const walletClient = this.getWalletClient();
|
|
1437
1438
|
safeAddress = await getDeterministicSafeAddress({
|
|
1438
|
-
owner: walletClient,
|
|
1439
1439
|
safeOwnerAddress: userAddress,
|
|
1440
1440
|
chain: chainConfig.chain,
|
|
1441
1441
|
publicClient: chainConfig.publicClient
|
|
@@ -2169,6 +2169,76 @@ var ZyfaiSDK = class {
|
|
|
2169
2169
|
);
|
|
2170
2170
|
}
|
|
2171
2171
|
}
|
|
2172
|
+
// ============================================================================
|
|
2173
|
+
// SDK Key Methods
|
|
2174
|
+
// ============================================================================
|
|
2175
|
+
/**
|
|
2176
|
+
* Get allowed wallets for the current SDK API key
|
|
2177
|
+
* Returns the list of smart wallet addresses created via this SDK key
|
|
2178
|
+
*
|
|
2179
|
+
* @returns List of allowed wallet addresses with metadata
|
|
2180
|
+
*
|
|
2181
|
+
* @example
|
|
2182
|
+
* ```typescript
|
|
2183
|
+
* const result = await sdk.getSdkAllowedWallets();
|
|
2184
|
+
* console.log("Allowed wallets:", result.allowedWallets);
|
|
2185
|
+
* console.log("Total count:", result.metadata.walletsCount);
|
|
2186
|
+
* ```
|
|
2187
|
+
*/
|
|
2188
|
+
async getSdkAllowedWallets() {
|
|
2189
|
+
try {
|
|
2190
|
+
const response = await this.httpClient.get(
|
|
2191
|
+
ENDPOINTS.SDK_ALLOWED_WALLETS
|
|
2192
|
+
);
|
|
2193
|
+
return {
|
|
2194
|
+
success: response.success || true,
|
|
2195
|
+
allowedWallets: response.allowedWallets || [],
|
|
2196
|
+
metadata: response.metadata || {
|
|
2197
|
+
sdkKeyId: "",
|
|
2198
|
+
clientName: "",
|
|
2199
|
+
walletsCount: 0
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
} catch (error) {
|
|
2203
|
+
throw new Error(
|
|
2204
|
+
`Failed to get SDK allowed wallets: ${error.message}`
|
|
2205
|
+
);
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
/**
|
|
2209
|
+
* Get total TVL for all wallets under the current SDK API key
|
|
2210
|
+
* This method calculates the total value locked across all wallets created via this SDK key
|
|
2211
|
+
*
|
|
2212
|
+
* @returns SDK key TVL information including allowed wallets and their individual/total TVL
|
|
2213
|
+
*
|
|
2214
|
+
* @example
|
|
2215
|
+
* ```typescript
|
|
2216
|
+
* const sdkTvl = await sdk.getSdkKeyTVL();
|
|
2217
|
+
* console.log("Total TVL across all SDK wallets:", sdkTvl.totalTvl);
|
|
2218
|
+
* console.log("Number of wallets:", sdkTvl.allowedWallets.length);
|
|
2219
|
+
* console.log("TVL by wallet:", sdkTvl.tvlByWallet);
|
|
2220
|
+
* ```
|
|
2221
|
+
*/
|
|
2222
|
+
async getSdkKeyTVL() {
|
|
2223
|
+
try {
|
|
2224
|
+
const response = await this.httpClient.get(ENDPOINTS.SDK_TVL);
|
|
2225
|
+
return {
|
|
2226
|
+
success: response.success || true,
|
|
2227
|
+
allowedWallets: response.allowedWallets || [],
|
|
2228
|
+
totalTvl: response.totalTvl || 0,
|
|
2229
|
+
tvlByWallet: response.tvlByWallet || [],
|
|
2230
|
+
metadata: response.metadata || {
|
|
2231
|
+
sdkKeyId: "",
|
|
2232
|
+
clientName: "",
|
|
2233
|
+
walletsCount: 0
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
} catch (error) {
|
|
2237
|
+
throw new Error(
|
|
2238
|
+
`Failed to get SDK key TVL: ${error.message}`
|
|
2239
|
+
);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2172
2242
|
};
|
|
2173
2243
|
export {
|
|
2174
2244
|
DEFAULT_TOKEN_ADDRESSES,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
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",
|