@zyfai/sdk 0.2.4 → 0.2.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/dist/index.d.mts +128 -1
- package/dist/index.d.ts +128 -1
- package/dist/index.js +124 -1
- package/dist/index.mjs +124 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -356,6 +356,70 @@ interface AddWalletToSdkResponse {
|
|
|
356
356
|
success: boolean;
|
|
357
357
|
message: string;
|
|
358
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
|
+
}
|
|
379
|
+
interface OpportunityPosition {
|
|
380
|
+
protocol: string;
|
|
381
|
+
pool: string;
|
|
382
|
+
apy: number;
|
|
383
|
+
tvl?: number;
|
|
384
|
+
}
|
|
385
|
+
interface BestOpportunityDetails {
|
|
386
|
+
protocol: string;
|
|
387
|
+
pool: string;
|
|
388
|
+
apy: number;
|
|
389
|
+
tvl: number;
|
|
390
|
+
zyfiTvl?: number;
|
|
391
|
+
poolApy?: number;
|
|
392
|
+
rewardsApy?: number;
|
|
393
|
+
protocolApy?: number;
|
|
394
|
+
}
|
|
395
|
+
interface BestOpportunityResponse {
|
|
396
|
+
success: boolean;
|
|
397
|
+
error?: string;
|
|
398
|
+
wallet?: Address;
|
|
399
|
+
chainId?: number;
|
|
400
|
+
strategy?: string;
|
|
401
|
+
token?: {
|
|
402
|
+
symbol: string;
|
|
403
|
+
address: string;
|
|
404
|
+
decimals: number;
|
|
405
|
+
};
|
|
406
|
+
currentPosition?: OpportunityPosition | null;
|
|
407
|
+
bestOpportunity?: BestOpportunityDetails | null;
|
|
408
|
+
shouldRebalance?: boolean;
|
|
409
|
+
apyImprovement?: number | null;
|
|
410
|
+
allOpportunities?: Array<{
|
|
411
|
+
protocol: string;
|
|
412
|
+
pool: string;
|
|
413
|
+
apy: number;
|
|
414
|
+
tvl: number;
|
|
415
|
+
zyfiTvl?: number;
|
|
416
|
+
}>;
|
|
417
|
+
userConfig?: {
|
|
418
|
+
autoSelectProtocols: boolean;
|
|
419
|
+
enabledProtocols: string[];
|
|
420
|
+
};
|
|
421
|
+
enabledChains?: number[];
|
|
422
|
+
}
|
|
359
423
|
interface PolicyData {
|
|
360
424
|
policy: Address;
|
|
361
425
|
initData: Hex;
|
|
@@ -872,6 +936,69 @@ declare class ZyfaiSDK {
|
|
|
872
936
|
* ```
|
|
873
937
|
*/
|
|
874
938
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
939
|
+
/**
|
|
940
|
+
* Get allowed wallets for the current SDK API key
|
|
941
|
+
* Returns the list of smart wallet addresses created via this SDK key
|
|
942
|
+
*
|
|
943
|
+
* @returns List of allowed wallet addresses with metadata
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* ```typescript
|
|
947
|
+
* const result = await sdk.getSdkAllowedWallets();
|
|
948
|
+
* console.log("Allowed wallets:", result.allowedWallets);
|
|
949
|
+
* console.log("Total count:", result.metadata.walletsCount);
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
getSdkAllowedWallets(): Promise<{
|
|
953
|
+
success: boolean;
|
|
954
|
+
allowedWallets: Address[];
|
|
955
|
+
metadata: {
|
|
956
|
+
sdkKeyId: string;
|
|
957
|
+
clientName: string;
|
|
958
|
+
walletsCount: number;
|
|
959
|
+
};
|
|
960
|
+
}>;
|
|
961
|
+
/**
|
|
962
|
+
* Get total TVL for all wallets under the current SDK API key
|
|
963
|
+
* This method calculates the total value locked across all wallets created via this SDK key
|
|
964
|
+
*
|
|
965
|
+
* @returns SDK key TVL information including allowed wallets and their individual/total TVL
|
|
966
|
+
*
|
|
967
|
+
* @example
|
|
968
|
+
* ```typescript
|
|
969
|
+
* const sdkTvl = await sdk.getSdkKeyTVL();
|
|
970
|
+
* console.log("Total TVL across all SDK wallets:", sdkTvl.totalTvl);
|
|
971
|
+
* console.log("Number of wallets:", sdkTvl.allowedWallets.length);
|
|
972
|
+
* console.log("TVL by wallet:", sdkTvl.tvlByWallet);
|
|
973
|
+
* ```
|
|
974
|
+
*/
|
|
975
|
+
getSdkKeyTVL(): Promise<SdkKeyTVLResponse>;
|
|
976
|
+
/**
|
|
977
|
+
* Get the best yield opportunity for a registered wallet.
|
|
978
|
+
*
|
|
979
|
+
* Returns the highest-APY opportunity available based on the wallet's strategy
|
|
980
|
+
* and enabled protocols. This reflects what the rebalance engine would select.
|
|
981
|
+
*
|
|
982
|
+
* @param walletAddress - The smart wallet address (must be registered)
|
|
983
|
+
* @param chainId - The chain ID to check opportunities on
|
|
984
|
+
* @returns Best opportunity details with comparison to current position
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```typescript
|
|
988
|
+
* const result = await sdk.getBestOpportunity(walletAddress, 8453);
|
|
989
|
+
*
|
|
990
|
+
* console.log("Current position:", result.currentPosition);
|
|
991
|
+
* console.log("Best opportunity:", result.bestOpportunity);
|
|
992
|
+
* console.log("Should rebalance:", result.shouldRebalance);
|
|
993
|
+
* console.log("APY improvement:", result.apyImprovement);
|
|
994
|
+
*
|
|
995
|
+
* // List all available opportunities
|
|
996
|
+
* result.allOpportunities?.forEach(opp => {
|
|
997
|
+
* console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}%`);
|
|
998
|
+
* });
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
1001
|
+
getBestOpportunity(walletAddress: Address, chainId: SupportedChainId): Promise<BestOpportunityResponse>;
|
|
875
1002
|
}
|
|
876
1003
|
|
|
877
|
-
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 };
|
|
1004
|
+
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, 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 OpportunityPosition, 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
|
@@ -356,6 +356,70 @@ interface AddWalletToSdkResponse {
|
|
|
356
356
|
success: boolean;
|
|
357
357
|
message: string;
|
|
358
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
|
+
}
|
|
379
|
+
interface OpportunityPosition {
|
|
380
|
+
protocol: string;
|
|
381
|
+
pool: string;
|
|
382
|
+
apy: number;
|
|
383
|
+
tvl?: number;
|
|
384
|
+
}
|
|
385
|
+
interface BestOpportunityDetails {
|
|
386
|
+
protocol: string;
|
|
387
|
+
pool: string;
|
|
388
|
+
apy: number;
|
|
389
|
+
tvl: number;
|
|
390
|
+
zyfiTvl?: number;
|
|
391
|
+
poolApy?: number;
|
|
392
|
+
rewardsApy?: number;
|
|
393
|
+
protocolApy?: number;
|
|
394
|
+
}
|
|
395
|
+
interface BestOpportunityResponse {
|
|
396
|
+
success: boolean;
|
|
397
|
+
error?: string;
|
|
398
|
+
wallet?: Address;
|
|
399
|
+
chainId?: number;
|
|
400
|
+
strategy?: string;
|
|
401
|
+
token?: {
|
|
402
|
+
symbol: string;
|
|
403
|
+
address: string;
|
|
404
|
+
decimals: number;
|
|
405
|
+
};
|
|
406
|
+
currentPosition?: OpportunityPosition | null;
|
|
407
|
+
bestOpportunity?: BestOpportunityDetails | null;
|
|
408
|
+
shouldRebalance?: boolean;
|
|
409
|
+
apyImprovement?: number | null;
|
|
410
|
+
allOpportunities?: Array<{
|
|
411
|
+
protocol: string;
|
|
412
|
+
pool: string;
|
|
413
|
+
apy: number;
|
|
414
|
+
tvl: number;
|
|
415
|
+
zyfiTvl?: number;
|
|
416
|
+
}>;
|
|
417
|
+
userConfig?: {
|
|
418
|
+
autoSelectProtocols: boolean;
|
|
419
|
+
enabledProtocols: string[];
|
|
420
|
+
};
|
|
421
|
+
enabledChains?: number[];
|
|
422
|
+
}
|
|
359
423
|
interface PolicyData {
|
|
360
424
|
policy: Address;
|
|
361
425
|
initData: Hex;
|
|
@@ -872,6 +936,69 @@ declare class ZyfaiSDK {
|
|
|
872
936
|
* ```
|
|
873
937
|
*/
|
|
874
938
|
getRebalanceFrequency(walletAddress: string): Promise<RebalanceFrequencyResponse>;
|
|
939
|
+
/**
|
|
940
|
+
* Get allowed wallets for the current SDK API key
|
|
941
|
+
* Returns the list of smart wallet addresses created via this SDK key
|
|
942
|
+
*
|
|
943
|
+
* @returns List of allowed wallet addresses with metadata
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* ```typescript
|
|
947
|
+
* const result = await sdk.getSdkAllowedWallets();
|
|
948
|
+
* console.log("Allowed wallets:", result.allowedWallets);
|
|
949
|
+
* console.log("Total count:", result.metadata.walletsCount);
|
|
950
|
+
* ```
|
|
951
|
+
*/
|
|
952
|
+
getSdkAllowedWallets(): Promise<{
|
|
953
|
+
success: boolean;
|
|
954
|
+
allowedWallets: Address[];
|
|
955
|
+
metadata: {
|
|
956
|
+
sdkKeyId: string;
|
|
957
|
+
clientName: string;
|
|
958
|
+
walletsCount: number;
|
|
959
|
+
};
|
|
960
|
+
}>;
|
|
961
|
+
/**
|
|
962
|
+
* Get total TVL for all wallets under the current SDK API key
|
|
963
|
+
* This method calculates the total value locked across all wallets created via this SDK key
|
|
964
|
+
*
|
|
965
|
+
* @returns SDK key TVL information including allowed wallets and their individual/total TVL
|
|
966
|
+
*
|
|
967
|
+
* @example
|
|
968
|
+
* ```typescript
|
|
969
|
+
* const sdkTvl = await sdk.getSdkKeyTVL();
|
|
970
|
+
* console.log("Total TVL across all SDK wallets:", sdkTvl.totalTvl);
|
|
971
|
+
* console.log("Number of wallets:", sdkTvl.allowedWallets.length);
|
|
972
|
+
* console.log("TVL by wallet:", sdkTvl.tvlByWallet);
|
|
973
|
+
* ```
|
|
974
|
+
*/
|
|
975
|
+
getSdkKeyTVL(): Promise<SdkKeyTVLResponse>;
|
|
976
|
+
/**
|
|
977
|
+
* Get the best yield opportunity for a registered wallet.
|
|
978
|
+
*
|
|
979
|
+
* Returns the highest-APY opportunity available based on the wallet's strategy
|
|
980
|
+
* and enabled protocols. This reflects what the rebalance engine would select.
|
|
981
|
+
*
|
|
982
|
+
* @param walletAddress - The smart wallet address (must be registered)
|
|
983
|
+
* @param chainId - The chain ID to check opportunities on
|
|
984
|
+
* @returns Best opportunity details with comparison to current position
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```typescript
|
|
988
|
+
* const result = await sdk.getBestOpportunity(walletAddress, 8453);
|
|
989
|
+
*
|
|
990
|
+
* console.log("Current position:", result.currentPosition);
|
|
991
|
+
* console.log("Best opportunity:", result.bestOpportunity);
|
|
992
|
+
* console.log("Should rebalance:", result.shouldRebalance);
|
|
993
|
+
* console.log("APY improvement:", result.apyImprovement);
|
|
994
|
+
*
|
|
995
|
+
* // List all available opportunities
|
|
996
|
+
* result.allOpportunities?.forEach(opp => {
|
|
997
|
+
* console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}%`);
|
|
998
|
+
* });
|
|
999
|
+
* ```
|
|
1000
|
+
*/
|
|
1001
|
+
getBestOpportunity(walletAddress: Address, chainId: SupportedChainId): Promise<BestOpportunityResponse>;
|
|
875
1002
|
}
|
|
876
1003
|
|
|
877
|
-
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 };
|
|
1004
|
+
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type BestOpportunityDetails, type BestOpportunityResponse, 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 OpportunityPosition, 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,12 @@ 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",
|
|
78
|
+
// Best Opportunity
|
|
79
|
+
BEST_OPPORTUNITY: (walletAddress, chainId) => `/data/best-opportunity?walletAddress=${walletAddress}&chainId=${chainId}`
|
|
74
80
|
};
|
|
75
81
|
var DATA_ENDPOINTS = {
|
|
76
82
|
// User Initialization
|
|
@@ -1384,6 +1390,16 @@ var ZyfaiSDK = class {
|
|
|
1384
1390
|
const receipt = await chainConfig.publicClient.waitForTransactionReceipt({
|
|
1385
1391
|
hash: txHash
|
|
1386
1392
|
});
|
|
1393
|
+
try {
|
|
1394
|
+
await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
|
|
1395
|
+
chainId,
|
|
1396
|
+
transaction: txHash,
|
|
1397
|
+
token,
|
|
1398
|
+
amount
|
|
1399
|
+
});
|
|
1400
|
+
} catch (logError) {
|
|
1401
|
+
console.warn("Failed to log deposit:", logError.message);
|
|
1402
|
+
}
|
|
1387
1403
|
if (receipt.status !== "success") {
|
|
1388
1404
|
throw new Error("Deposit transaction failed");
|
|
1389
1405
|
}
|
|
@@ -2178,6 +2194,113 @@ var ZyfaiSDK = class {
|
|
|
2178
2194
|
);
|
|
2179
2195
|
}
|
|
2180
2196
|
}
|
|
2197
|
+
// ============================================================================
|
|
2198
|
+
// SDK Key Methods
|
|
2199
|
+
// ============================================================================
|
|
2200
|
+
/**
|
|
2201
|
+
* Get allowed wallets for the current SDK API key
|
|
2202
|
+
* Returns the list of smart wallet addresses created via this SDK key
|
|
2203
|
+
*
|
|
2204
|
+
* @returns List of allowed wallet addresses with metadata
|
|
2205
|
+
*
|
|
2206
|
+
* @example
|
|
2207
|
+
* ```typescript
|
|
2208
|
+
* const result = await sdk.getSdkAllowedWallets();
|
|
2209
|
+
* console.log("Allowed wallets:", result.allowedWallets);
|
|
2210
|
+
* console.log("Total count:", result.metadata.walletsCount);
|
|
2211
|
+
* ```
|
|
2212
|
+
*/
|
|
2213
|
+
async getSdkAllowedWallets() {
|
|
2214
|
+
try {
|
|
2215
|
+
const response = await this.httpClient.get(
|
|
2216
|
+
ENDPOINTS.SDK_ALLOWED_WALLETS
|
|
2217
|
+
);
|
|
2218
|
+
return {
|
|
2219
|
+
success: response.success || true,
|
|
2220
|
+
allowedWallets: response.allowedWallets || [],
|
|
2221
|
+
metadata: response.metadata || {
|
|
2222
|
+
sdkKeyId: "",
|
|
2223
|
+
clientName: "",
|
|
2224
|
+
walletsCount: 0
|
|
2225
|
+
}
|
|
2226
|
+
};
|
|
2227
|
+
} catch (error) {
|
|
2228
|
+
throw new Error(
|
|
2229
|
+
`Failed to get SDK allowed wallets: ${error.message}`
|
|
2230
|
+
);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* Get total TVL for all wallets under the current SDK API key
|
|
2235
|
+
* This method calculates the total value locked across all wallets created via this SDK key
|
|
2236
|
+
*
|
|
2237
|
+
* @returns SDK key TVL information including allowed wallets and their individual/total TVL
|
|
2238
|
+
*
|
|
2239
|
+
* @example
|
|
2240
|
+
* ```typescript
|
|
2241
|
+
* const sdkTvl = await sdk.getSdkKeyTVL();
|
|
2242
|
+
* console.log("Total TVL across all SDK wallets:", sdkTvl.totalTvl);
|
|
2243
|
+
* console.log("Number of wallets:", sdkTvl.allowedWallets.length);
|
|
2244
|
+
* console.log("TVL by wallet:", sdkTvl.tvlByWallet);
|
|
2245
|
+
* ```
|
|
2246
|
+
*/
|
|
2247
|
+
async getSdkKeyTVL() {
|
|
2248
|
+
try {
|
|
2249
|
+
const response = await this.httpClient.get(ENDPOINTS.SDK_TVL);
|
|
2250
|
+
return {
|
|
2251
|
+
success: response.success || true,
|
|
2252
|
+
allowedWallets: response.allowedWallets || [],
|
|
2253
|
+
totalTvl: response.totalTvl || 0,
|
|
2254
|
+
tvlByWallet: response.tvlByWallet || [],
|
|
2255
|
+
metadata: response.metadata || {
|
|
2256
|
+
sdkKeyId: "",
|
|
2257
|
+
clientName: "",
|
|
2258
|
+
walletsCount: 0
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2261
|
+
} catch (error) {
|
|
2262
|
+
throw new Error(
|
|
2263
|
+
`Failed to get SDK key TVL: ${error.message}`
|
|
2264
|
+
);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* Get the best yield opportunity for a registered wallet.
|
|
2269
|
+
*
|
|
2270
|
+
* Returns the highest-APY opportunity available based on the wallet's strategy
|
|
2271
|
+
* and enabled protocols. This reflects what the rebalance engine would select.
|
|
2272
|
+
*
|
|
2273
|
+
* @param walletAddress - The smart wallet address (must be registered)
|
|
2274
|
+
* @param chainId - The chain ID to check opportunities on
|
|
2275
|
+
* @returns Best opportunity details with comparison to current position
|
|
2276
|
+
*
|
|
2277
|
+
* @example
|
|
2278
|
+
* ```typescript
|
|
2279
|
+
* const result = await sdk.getBestOpportunity(walletAddress, 8453);
|
|
2280
|
+
*
|
|
2281
|
+
* console.log("Current position:", result.currentPosition);
|
|
2282
|
+
* console.log("Best opportunity:", result.bestOpportunity);
|
|
2283
|
+
* console.log("Should rebalance:", result.shouldRebalance);
|
|
2284
|
+
* console.log("APY improvement:", result.apyImprovement);
|
|
2285
|
+
*
|
|
2286
|
+
* // List all available opportunities
|
|
2287
|
+
* result.allOpportunities?.forEach(opp => {
|
|
2288
|
+
* console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}%`);
|
|
2289
|
+
* });
|
|
2290
|
+
* ```
|
|
2291
|
+
*/
|
|
2292
|
+
async getBestOpportunity(walletAddress, chainId) {
|
|
2293
|
+
try {
|
|
2294
|
+
const response = await this.httpClient.get(
|
|
2295
|
+
ENDPOINTS.BEST_OPPORTUNITY(walletAddress, chainId)
|
|
2296
|
+
);
|
|
2297
|
+
return response;
|
|
2298
|
+
} catch (error) {
|
|
2299
|
+
throw new Error(
|
|
2300
|
+
`Failed to get best opportunity: ${error.message}`
|
|
2301
|
+
);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2181
2304
|
};
|
|
2182
2305
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2183
2306
|
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,12 @@ 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",
|
|
37
|
+
// Best Opportunity
|
|
38
|
+
BEST_OPPORTUNITY: (walletAddress, chainId) => `/data/best-opportunity?walletAddress=${walletAddress}&chainId=${chainId}`
|
|
33
39
|
};
|
|
34
40
|
var DATA_ENDPOINTS = {
|
|
35
41
|
// User Initialization
|
|
@@ -1361,6 +1367,16 @@ var ZyfaiSDK = class {
|
|
|
1361
1367
|
const receipt = await chainConfig.publicClient.waitForTransactionReceipt({
|
|
1362
1368
|
hash: txHash
|
|
1363
1369
|
});
|
|
1370
|
+
try {
|
|
1371
|
+
await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
|
|
1372
|
+
chainId,
|
|
1373
|
+
transaction: txHash,
|
|
1374
|
+
token,
|
|
1375
|
+
amount
|
|
1376
|
+
});
|
|
1377
|
+
} catch (logError) {
|
|
1378
|
+
console.warn("Failed to log deposit:", logError.message);
|
|
1379
|
+
}
|
|
1364
1380
|
if (receipt.status !== "success") {
|
|
1365
1381
|
throw new Error("Deposit transaction failed");
|
|
1366
1382
|
}
|
|
@@ -2155,6 +2171,113 @@ var ZyfaiSDK = class {
|
|
|
2155
2171
|
);
|
|
2156
2172
|
}
|
|
2157
2173
|
}
|
|
2174
|
+
// ============================================================================
|
|
2175
|
+
// SDK Key Methods
|
|
2176
|
+
// ============================================================================
|
|
2177
|
+
/**
|
|
2178
|
+
* Get allowed wallets for the current SDK API key
|
|
2179
|
+
* Returns the list of smart wallet addresses created via this SDK key
|
|
2180
|
+
*
|
|
2181
|
+
* @returns List of allowed wallet addresses with metadata
|
|
2182
|
+
*
|
|
2183
|
+
* @example
|
|
2184
|
+
* ```typescript
|
|
2185
|
+
* const result = await sdk.getSdkAllowedWallets();
|
|
2186
|
+
* console.log("Allowed wallets:", result.allowedWallets);
|
|
2187
|
+
* console.log("Total count:", result.metadata.walletsCount);
|
|
2188
|
+
* ```
|
|
2189
|
+
*/
|
|
2190
|
+
async getSdkAllowedWallets() {
|
|
2191
|
+
try {
|
|
2192
|
+
const response = await this.httpClient.get(
|
|
2193
|
+
ENDPOINTS.SDK_ALLOWED_WALLETS
|
|
2194
|
+
);
|
|
2195
|
+
return {
|
|
2196
|
+
success: response.success || true,
|
|
2197
|
+
allowedWallets: response.allowedWallets || [],
|
|
2198
|
+
metadata: response.metadata || {
|
|
2199
|
+
sdkKeyId: "",
|
|
2200
|
+
clientName: "",
|
|
2201
|
+
walletsCount: 0
|
|
2202
|
+
}
|
|
2203
|
+
};
|
|
2204
|
+
} catch (error) {
|
|
2205
|
+
throw new Error(
|
|
2206
|
+
`Failed to get SDK allowed wallets: ${error.message}`
|
|
2207
|
+
);
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
/**
|
|
2211
|
+
* Get total TVL for all wallets under the current SDK API key
|
|
2212
|
+
* This method calculates the total value locked across all wallets created via this SDK key
|
|
2213
|
+
*
|
|
2214
|
+
* @returns SDK key TVL information including allowed wallets and their individual/total TVL
|
|
2215
|
+
*
|
|
2216
|
+
* @example
|
|
2217
|
+
* ```typescript
|
|
2218
|
+
* const sdkTvl = await sdk.getSdkKeyTVL();
|
|
2219
|
+
* console.log("Total TVL across all SDK wallets:", sdkTvl.totalTvl);
|
|
2220
|
+
* console.log("Number of wallets:", sdkTvl.allowedWallets.length);
|
|
2221
|
+
* console.log("TVL by wallet:", sdkTvl.tvlByWallet);
|
|
2222
|
+
* ```
|
|
2223
|
+
*/
|
|
2224
|
+
async getSdkKeyTVL() {
|
|
2225
|
+
try {
|
|
2226
|
+
const response = await this.httpClient.get(ENDPOINTS.SDK_TVL);
|
|
2227
|
+
return {
|
|
2228
|
+
success: response.success || true,
|
|
2229
|
+
allowedWallets: response.allowedWallets || [],
|
|
2230
|
+
totalTvl: response.totalTvl || 0,
|
|
2231
|
+
tvlByWallet: response.tvlByWallet || [],
|
|
2232
|
+
metadata: response.metadata || {
|
|
2233
|
+
sdkKeyId: "",
|
|
2234
|
+
clientName: "",
|
|
2235
|
+
walletsCount: 0
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
} catch (error) {
|
|
2239
|
+
throw new Error(
|
|
2240
|
+
`Failed to get SDK key TVL: ${error.message}`
|
|
2241
|
+
);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* Get the best yield opportunity for a registered wallet.
|
|
2246
|
+
*
|
|
2247
|
+
* Returns the highest-APY opportunity available based on the wallet's strategy
|
|
2248
|
+
* and enabled protocols. This reflects what the rebalance engine would select.
|
|
2249
|
+
*
|
|
2250
|
+
* @param walletAddress - The smart wallet address (must be registered)
|
|
2251
|
+
* @param chainId - The chain ID to check opportunities on
|
|
2252
|
+
* @returns Best opportunity details with comparison to current position
|
|
2253
|
+
*
|
|
2254
|
+
* @example
|
|
2255
|
+
* ```typescript
|
|
2256
|
+
* const result = await sdk.getBestOpportunity(walletAddress, 8453);
|
|
2257
|
+
*
|
|
2258
|
+
* console.log("Current position:", result.currentPosition);
|
|
2259
|
+
* console.log("Best opportunity:", result.bestOpportunity);
|
|
2260
|
+
* console.log("Should rebalance:", result.shouldRebalance);
|
|
2261
|
+
* console.log("APY improvement:", result.apyImprovement);
|
|
2262
|
+
*
|
|
2263
|
+
* // List all available opportunities
|
|
2264
|
+
* result.allOpportunities?.forEach(opp => {
|
|
2265
|
+
* console.log(`${opp.protocol} - ${opp.pool}: ${opp.apy}%`);
|
|
2266
|
+
* });
|
|
2267
|
+
* ```
|
|
2268
|
+
*/
|
|
2269
|
+
async getBestOpportunity(walletAddress, chainId) {
|
|
2270
|
+
try {
|
|
2271
|
+
const response = await this.httpClient.get(
|
|
2272
|
+
ENDPOINTS.BEST_OPPORTUNITY(walletAddress, chainId)
|
|
2273
|
+
);
|
|
2274
|
+
return response;
|
|
2275
|
+
} catch (error) {
|
|
2276
|
+
throw new Error(
|
|
2277
|
+
`Failed to get best opportunity: ${error.message}`
|
|
2278
|
+
);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2158
2281
|
};
|
|
2159
2282
|
export {
|
|
2160
2283
|
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.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",
|