@zyfai/sdk 0.2.51 → 0.2.53
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 +7 -5
- package/dist/index.d.mts +23 -25
- package/dist/index.d.ts +23 -25
- package/dist/index.js +98 -51
- package/dist/index.mjs +97 -51
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -393,10 +393,11 @@ Transfer tokens to your Safe smart wallet. Token address is automatically select
|
|
|
393
393
|
|
|
394
394
|
**Minimum portfolio balance (enforced on Safe balance + deposit amount):**
|
|
395
395
|
|
|
396
|
-
- Ethereum Mainnet (1) / USDC
|
|
397
|
-
-
|
|
396
|
+
- Ethereum Mainnet (1) / USDC or EURC: 10,000 units
|
|
397
|
+
- Base (8453) and Arbitrum (42161) / USDC or EURC: 100 units
|
|
398
|
+
- WETH: about **$10,000** of ETH on Ethereum Mainnet, **$100** on Base and Arbitrum, using the live USD price from Data API `GET /api/v2/price?token=eth` (same API key as the SDK)
|
|
398
399
|
|
|
399
|
-
|
|
400
|
+
Top-ups smaller than the minimum are allowed if the Safe already holds enough of the asset to meet it after the deposit.
|
|
400
401
|
|
|
401
402
|
```typescript
|
|
402
403
|
// Deposit 10 USDC (6 decimals) to Safe on Base — no minimum on Base
|
|
@@ -420,7 +421,7 @@ if (result.success) {
|
|
|
420
421
|
|
|
421
422
|
- Amount must be in least decimal units. For USDC (6 decimals): 1 USDC = 1000000
|
|
422
423
|
- `asset` is required (`"USDC"`, `"WETH"`, or `"EURC"` — EURC on Mainnet/Base only); token address is selected from that for the chain
|
|
423
|
-
-
|
|
424
|
+
- The total Safe balance must meet the per-asset minimum after the deposit (see above). WETH uses a live ETH/USD price, so the wei threshold moves with the market.
|
|
424
425
|
- The SDK automatically authenticates via SIWE before logging the deposit with Zyfai's API, so no extra steps are required on your end once the transfer confirms
|
|
425
426
|
- **First deposit only** (before transfer + `log_deposit`): if the USDC profile has no `chains` yet, the SDK patches protocols for **USDC, WETH, and EURC** across all supported chains (EURC on Mainnet/Base only → `assetTypeSettings.[usdc|eth|eurc]`). Pass optional `strategy` (`"conservative"` default or `"aggressive"`) — same role as the former `deploySafe` strategy argument. Later deposits skip this.
|
|
426
427
|
|
|
@@ -530,7 +531,7 @@ positions.positions.forEach((bundle) => {
|
|
|
530
531
|
});
|
|
531
532
|
```
|
|
532
533
|
|
|
533
|
-
**Note**: This endpoint uses `/api/v1/data/position?walletAddress={address}` (Smart wallet address) and returns bundles with nested slot data. Use each slot's `underlyingAmount` for the canonical token balance.
|
|
534
|
+
**Note**: This endpoint uses `/api/v1/data/position?walletAddress={address}` (Smart wallet address) and returns bundles with nested slot data. Use each slot's `underlyingAmount` for the canonical token balance. The Safe is resolved via `getSafeAddressFor` (backend-assigned for predeployed wallets, registered agent for legacy). An EOA with no agent returns an empty portfolio — the SDK does not derive a CREATE2 address. Optional `chainId` defaults to Base (8453) for that resolution only.
|
|
534
535
|
|
|
535
536
|
#### Get Portfolio (with fee-adjusted balances)
|
|
536
537
|
|
|
@@ -804,6 +805,7 @@ Returns per-position APY breakdowns with per-token weighted averages.
|
|
|
804
805
|
|
|
805
806
|
```typescript
|
|
806
807
|
const apyHistory = await sdk.getDailyApyHistory(walletAddress, "30D");
|
|
808
|
+
// days: "7D" | "14D" | "30D" | "60D" | "120D" | "180D" (default "7D")
|
|
807
809
|
// Per-token weighted APY: { "USDC": 4.64, "WETH": 1.94 }
|
|
808
810
|
console.log("Weighted APY after fee:", apyHistory.weightedApyAfterFee);
|
|
809
811
|
console.log("Weighted APY (with rZFI Merkl):", apyHistory.weightedApyWithRzfiAfterFee);
|
package/dist/index.d.mts
CHANGED
|
@@ -725,6 +725,16 @@ declare const isSupportedChain: (chainId: number) => chainId is SupportedChainId
|
|
|
725
725
|
*/
|
|
726
726
|
declare const getSupportedChainIds: () => SupportedChainId[];
|
|
727
727
|
|
|
728
|
+
/**
|
|
729
|
+
* Global SDK Constants
|
|
730
|
+
*/
|
|
731
|
+
|
|
732
|
+
/** Allowed lookback windows for `getDailyApyHistory`, in days. */
|
|
733
|
+
declare const ALLOWED_HISTORY_DAYS: readonly [7, 14, 30, 60, 120, 180];
|
|
734
|
+
type AllowedHistoryDays = (typeof ALLOWED_HISTORY_DAYS)[number];
|
|
735
|
+
/** Query period passed to the daily APY history endpoint, e.g. `"30D"`. */
|
|
736
|
+
type DailyApyHistoryPeriod = `${AllowedHistoryDays}D`;
|
|
737
|
+
|
|
728
738
|
/**
|
|
729
739
|
* Zyfai SDK Main Class
|
|
730
740
|
*/
|
|
@@ -929,13 +939,9 @@ declare class ZyfaiSDK {
|
|
|
929
939
|
*/
|
|
930
940
|
private isConnectedUser;
|
|
931
941
|
/**
|
|
932
|
-
* Resolve the Safe
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
* deploy time, so their address CANNOT be derived from the user's EOA with
|
|
936
|
-
* getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
|
|
937
|
-
* For the connected predeployed user we always use the backend-assigned
|
|
938
|
-
* address. Legacy wallets keep the API-first, deterministic-fallback behavior.
|
|
942
|
+
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
943
|
+
* user, registered agent for everyone else. If none, CREATE2-derive when
|
|
944
|
+
* `deriveIfMissing` is true; otherwise return null (read paths).
|
|
939
945
|
* @private
|
|
940
946
|
*/
|
|
941
947
|
private getSafeAddressFor;
|
|
@@ -1053,13 +1059,9 @@ declare class ZyfaiSDK {
|
|
|
1053
1059
|
* Pass `strategy` to select protocols for that first-deposit setup
|
|
1054
1060
|
* (same role as the former `deploySafe` strategy argument).
|
|
1055
1061
|
*
|
|
1056
|
-
* Minimum portfolio balance enforced (Safe balance + deposit amount)
|
|
1057
|
-
*
|
|
1058
|
-
* -
|
|
1059
|
-
* - Base (8453) & Arbitrum (42161): no minimum
|
|
1060
|
-
*
|
|
1061
|
-
* If no minimum is configured for a given (chainId, asset) pair,
|
|
1062
|
-
* the check is skipped.
|
|
1062
|
+
* Minimum portfolio balance enforced (Safe balance + deposit amount):
|
|
1063
|
+
* - Stablecoins: `MIN_PORTFOLIO_BALANCE` (Mainnet 10,000 USDC/EURC; Base/Arbitrum 100)
|
|
1064
|
+
* - WETH: about $10,000 on Mainnet, $100 on Base/Arbitrum, from Data API `/price?token=eth`
|
|
1063
1065
|
*
|
|
1064
1066
|
* @param userAddress - User's address (owner of the Safe)
|
|
1065
1067
|
* @param chainId - Target chain ID
|
|
@@ -1094,8 +1096,9 @@ declare class ZyfaiSDK {
|
|
|
1094
1096
|
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
1095
1097
|
* already deployed are a no-op.
|
|
1096
1098
|
*
|
|
1097
|
-
* `depositFunds`
|
|
1098
|
-
*
|
|
1099
|
+
* Optional for deposits: `depositFunds` no longer pre-deploys the target chain — the ERC20
|
|
1100
|
+
* transfer lands on the counterfactual address and the backend deploys + hands over on first
|
|
1101
|
+
* deposit (report-deposit). Use this only to pre-provision chains ahead of time.
|
|
1099
1102
|
*
|
|
1100
1103
|
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
1101
1104
|
*/
|
|
@@ -1105,11 +1108,6 @@ declare class ZyfaiSDK {
|
|
|
1105
1108
|
chains: number[];
|
|
1106
1109
|
status: string;
|
|
1107
1110
|
}>;
|
|
1108
|
-
/**
|
|
1109
|
-
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
1110
|
-
* responds, so this only guards against read-after-write RPC lag.
|
|
1111
|
-
*/
|
|
1112
|
-
private waitForSafeDeployed;
|
|
1113
1111
|
depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
|
|
1114
1112
|
/**
|
|
1115
1113
|
* Log a deposit that was executed client-side
|
|
@@ -1195,7 +1193,7 @@ declare class ZyfaiSDK {
|
|
|
1195
1193
|
* Get all active DeFi positions for a user
|
|
1196
1194
|
*
|
|
1197
1195
|
* @param userAddress - User's EOA address
|
|
1198
|
-
* @param chainId - Optional
|
|
1196
|
+
* @param chainId - Optional chain used to resolve the Safe address (defaults to Base 8453)
|
|
1199
1197
|
* @returns User's positions across all protocols
|
|
1200
1198
|
*
|
|
1201
1199
|
* @example
|
|
@@ -1488,7 +1486,7 @@ declare class ZyfaiSDK {
|
|
|
1488
1486
|
* Get daily APY history with weighted average for a wallet
|
|
1489
1487
|
*
|
|
1490
1488
|
* @param walletAddress - Smart wallet address
|
|
1491
|
-
* @param days - Period: "7D", "14D", or "
|
|
1489
|
+
* @param days - Period: "7D", "14D", "30D", "60D", "120D", or "180D" (default: "7D")
|
|
1492
1490
|
* @returns Daily APY history with per-position breakdowns and weighted averages
|
|
1493
1491
|
*
|
|
1494
1492
|
* @example
|
|
@@ -1497,7 +1495,7 @@ declare class ZyfaiSDK {
|
|
|
1497
1495
|
* console.log("Weighted APY after fee:", apyHistory.weightedApyAfterFee); // { "USDC": 4.64, "WETH": 1.94 }
|
|
1498
1496
|
* ```
|
|
1499
1497
|
*/
|
|
1500
|
-
getDailyApyHistory(walletAddress: string, days?:
|
|
1498
|
+
getDailyApyHistory(walletAddress: string, days?: DailyApyHistoryPeriod): Promise<DailyApyHistoryResponse>;
|
|
1501
1499
|
/**
|
|
1502
1500
|
* Get rebalance frequency/tier for a wallet
|
|
1503
1501
|
* Determines how often the wallet can be rebalanced based on tier
|
|
@@ -1889,4 +1887,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
1889
1887
|
*/
|
|
1890
1888
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
1891
1889
|
|
|
1892
|
-
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryFeeData, type HistoryPosition, type HistoryRebalanceLog, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
|
1890
|
+
export { ALLOWED_HISTORY_DAYS, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryFeeData, type HistoryPosition, type HistoryRebalanceLog, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -725,6 +725,16 @@ declare const isSupportedChain: (chainId: number) => chainId is SupportedChainId
|
|
|
725
725
|
*/
|
|
726
726
|
declare const getSupportedChainIds: () => SupportedChainId[];
|
|
727
727
|
|
|
728
|
+
/**
|
|
729
|
+
* Global SDK Constants
|
|
730
|
+
*/
|
|
731
|
+
|
|
732
|
+
/** Allowed lookback windows for `getDailyApyHistory`, in days. */
|
|
733
|
+
declare const ALLOWED_HISTORY_DAYS: readonly [7, 14, 30, 60, 120, 180];
|
|
734
|
+
type AllowedHistoryDays = (typeof ALLOWED_HISTORY_DAYS)[number];
|
|
735
|
+
/** Query period passed to the daily APY history endpoint, e.g. `"30D"`. */
|
|
736
|
+
type DailyApyHistoryPeriod = `${AllowedHistoryDays}D`;
|
|
737
|
+
|
|
728
738
|
/**
|
|
729
739
|
* Zyfai SDK Main Class
|
|
730
740
|
*/
|
|
@@ -929,13 +939,9 @@ declare class ZyfaiSDK {
|
|
|
929
939
|
*/
|
|
930
940
|
private isConnectedUser;
|
|
931
941
|
/**
|
|
932
|
-
* Resolve the Safe
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
* deploy time, so their address CANNOT be derived from the user's EOA with
|
|
936
|
-
* getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
|
|
937
|
-
* For the connected predeployed user we always use the backend-assigned
|
|
938
|
-
* address. Legacy wallets keep the API-first, deterministic-fallback behavior.
|
|
942
|
+
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
943
|
+
* user, registered agent for everyone else. If none, CREATE2-derive when
|
|
944
|
+
* `deriveIfMissing` is true; otherwise return null (read paths).
|
|
939
945
|
* @private
|
|
940
946
|
*/
|
|
941
947
|
private getSafeAddressFor;
|
|
@@ -1053,13 +1059,9 @@ declare class ZyfaiSDK {
|
|
|
1053
1059
|
* Pass `strategy` to select protocols for that first-deposit setup
|
|
1054
1060
|
* (same role as the former `deploySafe` strategy argument).
|
|
1055
1061
|
*
|
|
1056
|
-
* Minimum portfolio balance enforced (Safe balance + deposit amount)
|
|
1057
|
-
*
|
|
1058
|
-
* -
|
|
1059
|
-
* - Base (8453) & Arbitrum (42161): no minimum
|
|
1060
|
-
*
|
|
1061
|
-
* If no minimum is configured for a given (chainId, asset) pair,
|
|
1062
|
-
* the check is skipped.
|
|
1062
|
+
* Minimum portfolio balance enforced (Safe balance + deposit amount):
|
|
1063
|
+
* - Stablecoins: `MIN_PORTFOLIO_BALANCE` (Mainnet 10,000 USDC/EURC; Base/Arbitrum 100)
|
|
1064
|
+
* - WETH: about $10,000 on Mainnet, $100 on Base/Arbitrum, from Data API `/price?token=eth`
|
|
1063
1065
|
*
|
|
1064
1066
|
* @param userAddress - User's address (owner of the Safe)
|
|
1065
1067
|
* @param chainId - Target chain ID
|
|
@@ -1094,8 +1096,9 @@ declare class ZyfaiSDK {
|
|
|
1094
1096
|
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
1095
1097
|
* already deployed are a no-op.
|
|
1096
1098
|
*
|
|
1097
|
-
* `depositFunds`
|
|
1098
|
-
*
|
|
1099
|
+
* Optional for deposits: `depositFunds` no longer pre-deploys the target chain — the ERC20
|
|
1100
|
+
* transfer lands on the counterfactual address and the backend deploys + hands over on first
|
|
1101
|
+
* deposit (report-deposit). Use this only to pre-provision chains ahead of time.
|
|
1099
1102
|
*
|
|
1100
1103
|
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
1101
1104
|
*/
|
|
@@ -1105,11 +1108,6 @@ declare class ZyfaiSDK {
|
|
|
1105
1108
|
chains: number[];
|
|
1106
1109
|
status: string;
|
|
1107
1110
|
}>;
|
|
1108
|
-
/**
|
|
1109
|
-
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
1110
|
-
* responds, so this only guards against read-after-write RPC lag.
|
|
1111
|
-
*/
|
|
1112
|
-
private waitForSafeDeployed;
|
|
1113
1111
|
depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
|
|
1114
1112
|
/**
|
|
1115
1113
|
* Log a deposit that was executed client-side
|
|
@@ -1195,7 +1193,7 @@ declare class ZyfaiSDK {
|
|
|
1195
1193
|
* Get all active DeFi positions for a user
|
|
1196
1194
|
*
|
|
1197
1195
|
* @param userAddress - User's EOA address
|
|
1198
|
-
* @param chainId - Optional
|
|
1196
|
+
* @param chainId - Optional chain used to resolve the Safe address (defaults to Base 8453)
|
|
1199
1197
|
* @returns User's positions across all protocols
|
|
1200
1198
|
*
|
|
1201
1199
|
* @example
|
|
@@ -1488,7 +1486,7 @@ declare class ZyfaiSDK {
|
|
|
1488
1486
|
* Get daily APY history with weighted average for a wallet
|
|
1489
1487
|
*
|
|
1490
1488
|
* @param walletAddress - Smart wallet address
|
|
1491
|
-
* @param days - Period: "7D", "14D", or "
|
|
1489
|
+
* @param days - Period: "7D", "14D", "30D", "60D", "120D", or "180D" (default: "7D")
|
|
1492
1490
|
* @returns Daily APY history with per-position breakdowns and weighted averages
|
|
1493
1491
|
*
|
|
1494
1492
|
* @example
|
|
@@ -1497,7 +1495,7 @@ declare class ZyfaiSDK {
|
|
|
1497
1495
|
* console.log("Weighted APY after fee:", apyHistory.weightedApyAfterFee); // { "USDC": 4.64, "WETH": 1.94 }
|
|
1498
1496
|
* ```
|
|
1499
1497
|
*/
|
|
1500
|
-
getDailyApyHistory(walletAddress: string, days?:
|
|
1498
|
+
getDailyApyHistory(walletAddress: string, days?: DailyApyHistoryPeriod): Promise<DailyApyHistoryResponse>;
|
|
1501
1499
|
/**
|
|
1502
1500
|
* Get rebalance frequency/tier for a wallet
|
|
1503
1501
|
* Determines how often the wallet can be rebalanced based on tier
|
|
@@ -1889,4 +1887,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
1889
1887
|
*/
|
|
1890
1888
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
1891
1889
|
|
|
1892
|
-
export { type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryFeeData, type HistoryPosition, type HistoryRebalanceLog, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
|
1890
|
+
export { ALLOWED_HISTORY_DAYS, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, type ExcludedPool, type FirstTopupResponse, type GetPoolsResponse, type GetSelectedPoolsResponse, type Hex, type HistoryEntry, type HistoryFeeData, type HistoryPosition, type HistoryRebalanceLog, type HistoryResponse, INTENT_EXECUTOR, INTENT_SMART_SESSIONS, type LiquidityDropEvent, type LogDepositResponse, type NewCollateralDetectedEvent, OWNABLE_VALIDATOR, type OnchainEarnings, type OnchainEarningsResponse, type OpportunitiesResponse, type Opportunity, type OpportunityPosition, POOL_MODULE_ADDRESSES, PROXY_EXECUTOR, type PolicyData, type Pool, type Portfolio, type PortfolioAssetBalance, type PortfolioByAssetType, type PortfolioByChain, type PortfolioDetailed, type PortfolioDetailedResponse, type PortfolioResponse, type PortfolioToken, type PositionSlot, type Protocol, type ProtocolsResponse, type RebalanceFrequencyResponse, type RegisterAgentResponse, SAFE_7579_ADDRESS, type SDKConfig, SMART_SESSIONS_FALLBACK, SMART_SESSIONS_VALIDATOR, type SdkKeyTVLResponse, type Session, type SessionKeyResponse, type SimulateBestPositionsParams, type SimulateBestPositionsResponse, type SimulateCalldataItem, type SimulatedPosition, type SmartWalletByEOAResponse, type SmartWalletResponse, type Strategy, type SupportedAsset, type SupportedChainId, type TVLResponse, type TokenApy, type TokenEarnings, type UpdateUserProfileRequest, type UpdateUserProfileResponse, type UserPosition, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDefaultTokenAddress, getSupportedChainIds, isSupportedChain };
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
ALLOWED_HISTORY_DAYS: () => ALLOWED_HISTORY_DAYS,
|
|
33
34
|
DEFAULT_TOKEN_ADDRESSES: () => DEFAULT_TOKEN_ADDRESSES,
|
|
34
35
|
ERC7579_LAUNCHPAD_ADDRESS: () => ERC7579_LAUNCHPAD_ADDRESS,
|
|
35
36
|
INTENT_EXECUTOR: () => INTENT_EXECUTOR,
|
|
@@ -150,6 +151,8 @@ var DATA_ENDPOINTS = {
|
|
|
150
151
|
if (options?.tokenSymbol) params.push(`tokenSymbol=${options.tokenSymbol}`);
|
|
151
152
|
return params.length > 0 ? `/rebalance/rebalance-info?${params.join("&")}` : "/rebalance/rebalance-info";
|
|
152
153
|
},
|
|
154
|
+
// Token USD price (e.g. token=eth)
|
|
155
|
+
TOKEN_PRICE: (token) => `/price?token=${encodeURIComponent(token)}`,
|
|
153
156
|
// APY Per Strategy
|
|
154
157
|
APY_PER_STRATEGY: (options = {}) => {
|
|
155
158
|
const params = [];
|
|
@@ -346,6 +349,27 @@ var HttpClient = class {
|
|
|
346
349
|
}
|
|
347
350
|
};
|
|
348
351
|
|
|
352
|
+
// src/utils/eth-price.ts
|
|
353
|
+
var PRICE_SCALE = 8;
|
|
354
|
+
var parseEthUsdPrice = (response) => {
|
|
355
|
+
const priceUsd = response?.data?.price_usd;
|
|
356
|
+
if (typeof priceUsd !== "number" || !Number.isFinite(priceUsd) || priceUsd <= 0) {
|
|
357
|
+
throw new Error("ETH/USD price must be a positive number");
|
|
358
|
+
}
|
|
359
|
+
return priceUsd;
|
|
360
|
+
};
|
|
361
|
+
var usdToWethWei = (usdAmount, ethUsd) => {
|
|
362
|
+
if (!Number.isFinite(ethUsd) || ethUsd <= 0) {
|
|
363
|
+
throw new Error("ETH/USD price must be positive");
|
|
364
|
+
}
|
|
365
|
+
const scaledPrice = BigInt(Math.round(ethUsd * 10 ** PRICE_SCALE));
|
|
366
|
+
if (scaledPrice <= 0n) {
|
|
367
|
+
throw new Error("ETH/USD price must be positive");
|
|
368
|
+
}
|
|
369
|
+
return usdAmount * 10n ** 18n * 10n ** BigInt(PRICE_SCALE) / scaledPrice;
|
|
370
|
+
};
|
|
371
|
+
var minWethWeiForUsd = (ethUsd, usdAmount) => usdToWethWei(usdAmount, ethUsd);
|
|
372
|
+
|
|
349
373
|
// src/config/abis.ts
|
|
350
374
|
var import_viem = require("viem");
|
|
351
375
|
var OWNABLE_VALIDATOR_ABI = [
|
|
@@ -516,14 +540,32 @@ var VAULT_ADDRESS = "0xD580071c47d4a667858B5FafAb85BC9C609beC5D";
|
|
|
516
540
|
|
|
517
541
|
// src/config/constants.ts
|
|
518
542
|
var ZYFI_FEE_RATE = 0.1;
|
|
543
|
+
var ALLOWED_HISTORY_DAYS = [7, 14, 30, 60, 120, 180];
|
|
519
544
|
var MIN_PORTFOLIO_BALANCE = {
|
|
520
545
|
1: {
|
|
546
|
+
USDC: 10000n * 10n ** 6n,
|
|
547
|
+
// 10,000 USDC (6 decimals)
|
|
548
|
+
EURC: 10000n * 10n ** 6n
|
|
549
|
+
// 10,000 EURC (6 decimals)
|
|
550
|
+
},
|
|
551
|
+
8453: {
|
|
552
|
+
USDC: 100n * 10n ** 6n,
|
|
553
|
+
// 100 USDC (6 decimals)
|
|
554
|
+
EURC: 100n * 10n ** 6n
|
|
555
|
+
// 100 EURC (6 decimals)
|
|
556
|
+
},
|
|
557
|
+
42161: {
|
|
521
558
|
USDC: 100n * 10n ** 6n,
|
|
522
559
|
// 100 USDC (6 decimals)
|
|
523
|
-
|
|
524
|
-
//
|
|
560
|
+
EURC: 100n * 10n ** 6n
|
|
561
|
+
// 100 EURC (6 decimals)
|
|
525
562
|
}
|
|
526
563
|
};
|
|
564
|
+
var MIN_WETH_USD = {
|
|
565
|
+
1: 10000n,
|
|
566
|
+
8453: 100n,
|
|
567
|
+
42161: 100n
|
|
568
|
+
};
|
|
527
569
|
var formatMinPortfolioLabel = (raw, decimals, symbol) => {
|
|
528
570
|
const base2 = 10n ** BigInt(decimals);
|
|
529
571
|
const whole = raw / base2;
|
|
@@ -1951,16 +1993,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1951
1993
|
return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
|
|
1952
1994
|
}
|
|
1953
1995
|
/**
|
|
1954
|
-
* Resolve the Safe
|
|
1955
|
-
*
|
|
1956
|
-
*
|
|
1957
|
-
* deploy time, so their address CANNOT be derived from the user's EOA with
|
|
1958
|
-
* getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
|
|
1959
|
-
* For the connected predeployed user we always use the backend-assigned
|
|
1960
|
-
* address. Legacy wallets keep the API-first, deterministic-fallback behavior.
|
|
1996
|
+
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
1997
|
+
* user, registered agent for everyone else. If none, CREATE2-derive when
|
|
1998
|
+
* `deriveIfMissing` is true; otherwise return null (read paths).
|
|
1961
1999
|
* @private
|
|
1962
2000
|
*/
|
|
1963
|
-
async getSafeAddressFor(userAddress, chainId) {
|
|
2001
|
+
async getSafeAddressFor(userAddress, chainId, deriveIfMissing = true) {
|
|
1964
2002
|
if (this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
1965
2003
|
if (this.connectedSmartWallet) return this.connectedSmartWallet;
|
|
1966
2004
|
try {
|
|
@@ -1968,6 +2006,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1968
2006
|
if (info.smartWallet) return info.smartWallet;
|
|
1969
2007
|
} catch {
|
|
1970
2008
|
}
|
|
2009
|
+
if (!deriveIfMissing) return null;
|
|
1971
2010
|
throw new Error(
|
|
1972
2011
|
"Predeployed smart wallet address is not available from the API yet. Ensure the user has signed in so the pool can reserve their wallet."
|
|
1973
2012
|
);
|
|
@@ -1977,6 +2016,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1977
2016
|
if (info.smartWallet) return info.smartWallet;
|
|
1978
2017
|
} catch {
|
|
1979
2018
|
}
|
|
2019
|
+
if (!deriveIfMissing) return null;
|
|
1980
2020
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1981
2021
|
return getDeterministicSafeAddress({
|
|
1982
2022
|
safeOwnerAddress: userAddress,
|
|
@@ -2004,6 +2044,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2004
2044
|
}
|
|
2005
2045
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
2006
2046
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
2047
|
+
if (!safeAddress) {
|
|
2048
|
+
throw new Error("Smart wallet address is not available");
|
|
2049
|
+
}
|
|
2007
2050
|
const isDeployed = await isSafeDeployed(
|
|
2008
2051
|
safeAddress,
|
|
2009
2052
|
chainConfig.publicClient
|
|
@@ -2056,6 +2099,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2056
2099
|
userAddress,
|
|
2057
2100
|
chainId
|
|
2058
2101
|
);
|
|
2102
|
+
if (!predeployedAddress) {
|
|
2103
|
+
throw new Error(
|
|
2104
|
+
"Predeployed smart wallet address is not available from the API yet. Ensure the user has signed in so the pool can reserve their wallet."
|
|
2105
|
+
);
|
|
2106
|
+
}
|
|
2059
2107
|
try {
|
|
2060
2108
|
await this.initializeUser(predeployedAddress, chainId);
|
|
2061
2109
|
} catch (initError) {
|
|
@@ -2444,13 +2492,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2444
2492
|
* Pass `strategy` to select protocols for that first-deposit setup
|
|
2445
2493
|
* (same role as the former `deploySafe` strategy argument).
|
|
2446
2494
|
*
|
|
2447
|
-
* Minimum portfolio balance enforced (Safe balance + deposit amount)
|
|
2448
|
-
*
|
|
2449
|
-
* -
|
|
2450
|
-
* - Base (8453) & Arbitrum (42161): no minimum
|
|
2451
|
-
*
|
|
2452
|
-
* If no minimum is configured for a given (chainId, asset) pair,
|
|
2453
|
-
* the check is skipped.
|
|
2495
|
+
* Minimum portfolio balance enforced (Safe balance + deposit amount):
|
|
2496
|
+
* - Stablecoins: `MIN_PORTFOLIO_BALANCE` (Mainnet 10,000 USDC/EURC; Base/Arbitrum 100)
|
|
2497
|
+
* - WETH: about $10,000 on Mainnet, $100 on Base/Arbitrum, from Data API `/price?token=eth`
|
|
2454
2498
|
*
|
|
2455
2499
|
* @param userAddress - User's address (owner of the Safe)
|
|
2456
2500
|
* @param chainId - Target chain ID
|
|
@@ -2485,8 +2529,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2485
2529
|
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
2486
2530
|
* already deployed are a no-op.
|
|
2487
2531
|
*
|
|
2488
|
-
* `depositFunds`
|
|
2489
|
-
*
|
|
2532
|
+
* Optional for deposits: `depositFunds` no longer pre-deploys the target chain — the ERC20
|
|
2533
|
+
* transfer lands on the counterfactual address and the backend deploys + hands over on first
|
|
2534
|
+
* deposit (report-deposit). Use this only to pre-provision chains ahead of time.
|
|
2490
2535
|
*
|
|
2491
2536
|
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
2492
2537
|
*/
|
|
@@ -2500,17 +2545,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2500
2545
|
await this.authenticateUser();
|
|
2501
2546
|
return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
|
|
2502
2547
|
}
|
|
2503
|
-
/**
|
|
2504
|
-
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
2505
|
-
* responds, so this only guards against read-after-write RPC lag.
|
|
2506
|
-
*/
|
|
2507
|
-
async waitForSafeDeployed(safeAddress, publicClient, tries = 5, delayMs = 2e3) {
|
|
2508
|
-
for (let i = 0; i < tries; i++) {
|
|
2509
|
-
if (await isSafeDeployed(safeAddress, publicClient)) return true;
|
|
2510
|
-
await new Promise((r) => setTimeout(r, delayMs));
|
|
2511
|
-
}
|
|
2512
|
-
return isSafeDeployed(safeAddress, publicClient);
|
|
2513
|
-
}
|
|
2514
2548
|
async depositFunds(userAddress, chainId, amount, asset, strategy) {
|
|
2515
2549
|
try {
|
|
2516
2550
|
if (!userAddress) {
|
|
@@ -2537,28 +2571,29 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2537
2571
|
`Unsupported asset: ${assetSymbol}. Supported: USDC, WETH, EURC.`
|
|
2538
2572
|
);
|
|
2539
2573
|
}
|
|
2540
|
-
|
|
2574
|
+
let minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
|
|
2575
|
+
if (assetSymbol === "WETH") {
|
|
2576
|
+
const priceResponse = await this.httpClient.dataGet(
|
|
2577
|
+
DATA_ENDPOINTS.TOKEN_PRICE("eth")
|
|
2578
|
+
);
|
|
2579
|
+
minRequired = minWethWeiForUsd(
|
|
2580
|
+
parseEthUsdPrice(priceResponse),
|
|
2581
|
+
MIN_WETH_USD[chainId]
|
|
2582
|
+
);
|
|
2583
|
+
}
|
|
2541
2584
|
const token = getDefaultTokenAddress(chainId, assetSymbol);
|
|
2542
2585
|
const walletClient = this.getWalletClient();
|
|
2543
2586
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
2544
2587
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
2588
|
+
if (!safeAddress) {
|
|
2589
|
+
throw new Error("Smart wallet address is not available");
|
|
2590
|
+
}
|
|
2545
2591
|
const isDeployed = await isSafeDeployed(
|
|
2546
2592
|
safeAddress,
|
|
2547
2593
|
chainConfig.publicClient
|
|
2548
2594
|
);
|
|
2549
2595
|
if (!isDeployed) {
|
|
2550
|
-
if (this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
2551
|
-
await this.deployOnChains([chainId]);
|
|
2552
|
-
const landed = await this.waitForSafeDeployed(
|
|
2553
|
-
safeAddress,
|
|
2554
|
-
chainConfig.publicClient
|
|
2555
|
-
);
|
|
2556
|
-
if (!landed) {
|
|
2557
|
-
throw new Error(
|
|
2558
|
-
`Safe deploy on chain ${chainId} for ${userAddress} did not land \u2014 retry the deposit.`
|
|
2559
|
-
);
|
|
2560
|
-
}
|
|
2561
|
-
} else {
|
|
2596
|
+
if (!(this.isPredeployed && this.isConnectedUser(userAddress))) {
|
|
2562
2597
|
throw new Error(
|
|
2563
2598
|
`Safe not available for ${userAddress} on chain ${chainId}.`
|
|
2564
2599
|
);
|
|
@@ -2728,6 +2763,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2728
2763
|
}
|
|
2729
2764
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
2730
2765
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
2766
|
+
if (!safeAddress) {
|
|
2767
|
+
throw new Error("Smart wallet address is not available");
|
|
2768
|
+
}
|
|
2731
2769
|
const isDeployed = await isSafeDeployed(
|
|
2732
2770
|
safeAddress,
|
|
2733
2771
|
chainConfig.publicClient
|
|
@@ -2802,7 +2840,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2802
2840
|
* Get all active DeFi positions for a user
|
|
2803
2841
|
*
|
|
2804
2842
|
* @param userAddress - User's EOA address
|
|
2805
|
-
* @param chainId - Optional
|
|
2843
|
+
* @param chainId - Optional chain used to resolve the Safe address (defaults to Base 8453)
|
|
2806
2844
|
* @returns User's positions across all protocols
|
|
2807
2845
|
*
|
|
2808
2846
|
* @example
|
|
@@ -2822,8 +2860,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2822
2860
|
if (chainId && !isSupportedChain(chainId)) {
|
|
2823
2861
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
2824
2862
|
}
|
|
2825
|
-
const
|
|
2826
|
-
|
|
2863
|
+
const targetChainId = chainId ?? 8453;
|
|
2864
|
+
const smartWallet = await this.getSafeAddressFor(
|
|
2865
|
+
userAddress,
|
|
2866
|
+
targetChainId,
|
|
2867
|
+
false
|
|
2868
|
+
);
|
|
2869
|
+
if (!smartWallet) {
|
|
2827
2870
|
return {
|
|
2828
2871
|
success: true,
|
|
2829
2872
|
userAddress,
|
|
@@ -2831,7 +2874,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2831
2874
|
};
|
|
2832
2875
|
}
|
|
2833
2876
|
const response = await this.httpClient.get(
|
|
2834
|
-
ENDPOINTS.DATA_POSITION(
|
|
2877
|
+
ENDPOINTS.DATA_POSITION(smartWallet)
|
|
2835
2878
|
);
|
|
2836
2879
|
const convertedPosition = response ? convertStrategyToPublic(response) : void 0;
|
|
2837
2880
|
return {
|
|
@@ -2869,15 +2912,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2869
2912
|
if (!userAddress) {
|
|
2870
2913
|
throw new Error("User address is required");
|
|
2871
2914
|
}
|
|
2872
|
-
const
|
|
2873
|
-
|
|
2915
|
+
const smartWallet = await this.getSafeAddressFor(
|
|
2916
|
+
userAddress,
|
|
2917
|
+
8453,
|
|
2918
|
+
false
|
|
2919
|
+
);
|
|
2920
|
+
if (!smartWallet) {
|
|
2874
2921
|
return {
|
|
2875
2922
|
success: true,
|
|
2876
2923
|
userAddress,
|
|
2877
2924
|
portfolio: {}
|
|
2878
2925
|
};
|
|
2879
2926
|
}
|
|
2880
|
-
const smartWallet = smartWalletInfo.smartWallet;
|
|
2881
2927
|
const [response, earningsResult] = await Promise.all([
|
|
2882
2928
|
this.httpClient.get(
|
|
2883
2929
|
ENDPOINTS.DATA_PORTFOLIO(smartWallet)
|
|
@@ -3601,7 +3647,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3601
3647
|
* Get daily APY history with weighted average for a wallet
|
|
3602
3648
|
*
|
|
3603
3649
|
* @param walletAddress - Smart wallet address
|
|
3604
|
-
* @param days - Period: "7D", "14D", or "
|
|
3650
|
+
* @param days - Period: "7D", "14D", "30D", "60D", "120D", or "180D" (default: "7D")
|
|
3605
3651
|
* @returns Daily APY history with per-position breakdowns and weighted averages
|
|
3606
3652
|
*
|
|
3607
3653
|
* @example
|
|
@@ -4592,6 +4638,7 @@ function createBankrProvider(config) {
|
|
|
4592
4638
|
}
|
|
4593
4639
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4594
4640
|
0 && (module.exports = {
|
|
4641
|
+
ALLOWED_HISTORY_DAYS,
|
|
4595
4642
|
DEFAULT_TOKEN_ADDRESSES,
|
|
4596
4643
|
ERC7579_LAUNCHPAD_ADDRESS,
|
|
4597
4644
|
INTENT_EXECUTOR,
|
package/dist/index.mjs
CHANGED
|
@@ -98,6 +98,8 @@ var DATA_ENDPOINTS = {
|
|
|
98
98
|
if (options?.tokenSymbol) params.push(`tokenSymbol=${options.tokenSymbol}`);
|
|
99
99
|
return params.length > 0 ? `/rebalance/rebalance-info?${params.join("&")}` : "/rebalance/rebalance-info";
|
|
100
100
|
},
|
|
101
|
+
// Token USD price (e.g. token=eth)
|
|
102
|
+
TOKEN_PRICE: (token) => `/price?token=${encodeURIComponent(token)}`,
|
|
101
103
|
// APY Per Strategy
|
|
102
104
|
APY_PER_STRATEGY: (options = {}) => {
|
|
103
105
|
const params = [];
|
|
@@ -294,6 +296,27 @@ var HttpClient = class {
|
|
|
294
296
|
}
|
|
295
297
|
};
|
|
296
298
|
|
|
299
|
+
// src/utils/eth-price.ts
|
|
300
|
+
var PRICE_SCALE = 8;
|
|
301
|
+
var parseEthUsdPrice = (response) => {
|
|
302
|
+
const priceUsd = response?.data?.price_usd;
|
|
303
|
+
if (typeof priceUsd !== "number" || !Number.isFinite(priceUsd) || priceUsd <= 0) {
|
|
304
|
+
throw new Error("ETH/USD price must be a positive number");
|
|
305
|
+
}
|
|
306
|
+
return priceUsd;
|
|
307
|
+
};
|
|
308
|
+
var usdToWethWei = (usdAmount, ethUsd) => {
|
|
309
|
+
if (!Number.isFinite(ethUsd) || ethUsd <= 0) {
|
|
310
|
+
throw new Error("ETH/USD price must be positive");
|
|
311
|
+
}
|
|
312
|
+
const scaledPrice = BigInt(Math.round(ethUsd * 10 ** PRICE_SCALE));
|
|
313
|
+
if (scaledPrice <= 0n) {
|
|
314
|
+
throw new Error("ETH/USD price must be positive");
|
|
315
|
+
}
|
|
316
|
+
return usdAmount * 10n ** 18n * 10n ** BigInt(PRICE_SCALE) / scaledPrice;
|
|
317
|
+
};
|
|
318
|
+
var minWethWeiForUsd = (ethUsd, usdAmount) => usdToWethWei(usdAmount, ethUsd);
|
|
319
|
+
|
|
297
320
|
// src/config/abis.ts
|
|
298
321
|
import { parseAbi } from "viem";
|
|
299
322
|
var OWNABLE_VALIDATOR_ABI = [
|
|
@@ -464,14 +487,32 @@ var VAULT_ADDRESS = "0xD580071c47d4a667858B5FafAb85BC9C609beC5D";
|
|
|
464
487
|
|
|
465
488
|
// src/config/constants.ts
|
|
466
489
|
var ZYFI_FEE_RATE = 0.1;
|
|
490
|
+
var ALLOWED_HISTORY_DAYS = [7, 14, 30, 60, 120, 180];
|
|
467
491
|
var MIN_PORTFOLIO_BALANCE = {
|
|
468
492
|
1: {
|
|
493
|
+
USDC: 10000n * 10n ** 6n,
|
|
494
|
+
// 10,000 USDC (6 decimals)
|
|
495
|
+
EURC: 10000n * 10n ** 6n
|
|
496
|
+
// 10,000 EURC (6 decimals)
|
|
497
|
+
},
|
|
498
|
+
8453: {
|
|
499
|
+
USDC: 100n * 10n ** 6n,
|
|
500
|
+
// 100 USDC (6 decimals)
|
|
501
|
+
EURC: 100n * 10n ** 6n
|
|
502
|
+
// 100 EURC (6 decimals)
|
|
503
|
+
},
|
|
504
|
+
42161: {
|
|
469
505
|
USDC: 100n * 10n ** 6n,
|
|
470
506
|
// 100 USDC (6 decimals)
|
|
471
|
-
|
|
472
|
-
//
|
|
507
|
+
EURC: 100n * 10n ** 6n
|
|
508
|
+
// 100 EURC (6 decimals)
|
|
473
509
|
}
|
|
474
510
|
};
|
|
511
|
+
var MIN_WETH_USD = {
|
|
512
|
+
1: 10000n,
|
|
513
|
+
8453: 100n,
|
|
514
|
+
42161: 100n
|
|
515
|
+
};
|
|
475
516
|
var formatMinPortfolioLabel = (raw, decimals, symbol) => {
|
|
476
517
|
const base2 = 10n ** BigInt(decimals);
|
|
477
518
|
const whole = raw / base2;
|
|
@@ -1919,16 +1960,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1919
1960
|
return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
|
|
1920
1961
|
}
|
|
1921
1962
|
/**
|
|
1922
|
-
* Resolve the Safe
|
|
1923
|
-
*
|
|
1924
|
-
*
|
|
1925
|
-
* deploy time, so their address CANNOT be derived from the user's EOA with
|
|
1926
|
-
* getDeterministicSafeAddress (CREATE2 from the EOA yields the wrong address).
|
|
1927
|
-
* For the connected predeployed user we always use the backend-assigned
|
|
1928
|
-
* address. Legacy wallets keep the API-first, deterministic-fallback behavior.
|
|
1963
|
+
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
1964
|
+
* user, registered agent for everyone else. If none, CREATE2-derive when
|
|
1965
|
+
* `deriveIfMissing` is true; otherwise return null (read paths).
|
|
1929
1966
|
* @private
|
|
1930
1967
|
*/
|
|
1931
|
-
async getSafeAddressFor(userAddress, chainId) {
|
|
1968
|
+
async getSafeAddressFor(userAddress, chainId, deriveIfMissing = true) {
|
|
1932
1969
|
if (this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
1933
1970
|
if (this.connectedSmartWallet) return this.connectedSmartWallet;
|
|
1934
1971
|
try {
|
|
@@ -1936,6 +1973,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1936
1973
|
if (info.smartWallet) return info.smartWallet;
|
|
1937
1974
|
} catch {
|
|
1938
1975
|
}
|
|
1976
|
+
if (!deriveIfMissing) return null;
|
|
1939
1977
|
throw new Error(
|
|
1940
1978
|
"Predeployed smart wallet address is not available from the API yet. Ensure the user has signed in so the pool can reserve their wallet."
|
|
1941
1979
|
);
|
|
@@ -1945,6 +1983,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1945
1983
|
if (info.smartWallet) return info.smartWallet;
|
|
1946
1984
|
} catch {
|
|
1947
1985
|
}
|
|
1986
|
+
if (!deriveIfMissing) return null;
|
|
1948
1987
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1949
1988
|
return getDeterministicSafeAddress({
|
|
1950
1989
|
safeOwnerAddress: userAddress,
|
|
@@ -1972,6 +2011,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1972
2011
|
}
|
|
1973
2012
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
1974
2013
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
2014
|
+
if (!safeAddress) {
|
|
2015
|
+
throw new Error("Smart wallet address is not available");
|
|
2016
|
+
}
|
|
1975
2017
|
const isDeployed = await isSafeDeployed(
|
|
1976
2018
|
safeAddress,
|
|
1977
2019
|
chainConfig.publicClient
|
|
@@ -2024,6 +2066,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2024
2066
|
userAddress,
|
|
2025
2067
|
chainId
|
|
2026
2068
|
);
|
|
2069
|
+
if (!predeployedAddress) {
|
|
2070
|
+
throw new Error(
|
|
2071
|
+
"Predeployed smart wallet address is not available from the API yet. Ensure the user has signed in so the pool can reserve their wallet."
|
|
2072
|
+
);
|
|
2073
|
+
}
|
|
2027
2074
|
try {
|
|
2028
2075
|
await this.initializeUser(predeployedAddress, chainId);
|
|
2029
2076
|
} catch (initError) {
|
|
@@ -2412,13 +2459,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2412
2459
|
* Pass `strategy` to select protocols for that first-deposit setup
|
|
2413
2460
|
* (same role as the former `deploySafe` strategy argument).
|
|
2414
2461
|
*
|
|
2415
|
-
* Minimum portfolio balance enforced (Safe balance + deposit amount)
|
|
2416
|
-
*
|
|
2417
|
-
* -
|
|
2418
|
-
* - Base (8453) & Arbitrum (42161): no minimum
|
|
2419
|
-
*
|
|
2420
|
-
* If no minimum is configured for a given (chainId, asset) pair,
|
|
2421
|
-
* the check is skipped.
|
|
2462
|
+
* Minimum portfolio balance enforced (Safe balance + deposit amount):
|
|
2463
|
+
* - Stablecoins: `MIN_PORTFOLIO_BALANCE` (Mainnet 10,000 USDC/EURC; Base/Arbitrum 100)
|
|
2464
|
+
* - WETH: about $10,000 on Mainnet, $100 on Base/Arbitrum, from Data API `/price?token=eth`
|
|
2422
2465
|
*
|
|
2423
2466
|
* @param userAddress - User's address (owner of the Safe)
|
|
2424
2467
|
* @param chainId - Target chain ID
|
|
@@ -2453,8 +2496,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2453
2496
|
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
2454
2497
|
* already deployed are a no-op.
|
|
2455
2498
|
*
|
|
2456
|
-
* `depositFunds`
|
|
2457
|
-
*
|
|
2499
|
+
* Optional for deposits: `depositFunds` no longer pre-deploys the target chain — the ERC20
|
|
2500
|
+
* transfer lands on the counterfactual address and the backend deploys + hands over on first
|
|
2501
|
+
* deposit (report-deposit). Use this only to pre-provision chains ahead of time.
|
|
2458
2502
|
*
|
|
2459
2503
|
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
2460
2504
|
*/
|
|
@@ -2468,17 +2512,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2468
2512
|
await this.authenticateUser();
|
|
2469
2513
|
return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
|
|
2470
2514
|
}
|
|
2471
|
-
/**
|
|
2472
|
-
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
2473
|
-
* responds, so this only guards against read-after-write RPC lag.
|
|
2474
|
-
*/
|
|
2475
|
-
async waitForSafeDeployed(safeAddress, publicClient, tries = 5, delayMs = 2e3) {
|
|
2476
|
-
for (let i = 0; i < tries; i++) {
|
|
2477
|
-
if (await isSafeDeployed(safeAddress, publicClient)) return true;
|
|
2478
|
-
await new Promise((r) => setTimeout(r, delayMs));
|
|
2479
|
-
}
|
|
2480
|
-
return isSafeDeployed(safeAddress, publicClient);
|
|
2481
|
-
}
|
|
2482
2515
|
async depositFunds(userAddress, chainId, amount, asset, strategy) {
|
|
2483
2516
|
try {
|
|
2484
2517
|
if (!userAddress) {
|
|
@@ -2505,28 +2538,29 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2505
2538
|
`Unsupported asset: ${assetSymbol}. Supported: USDC, WETH, EURC.`
|
|
2506
2539
|
);
|
|
2507
2540
|
}
|
|
2508
|
-
|
|
2541
|
+
let minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
|
|
2542
|
+
if (assetSymbol === "WETH") {
|
|
2543
|
+
const priceResponse = await this.httpClient.dataGet(
|
|
2544
|
+
DATA_ENDPOINTS.TOKEN_PRICE("eth")
|
|
2545
|
+
);
|
|
2546
|
+
minRequired = minWethWeiForUsd(
|
|
2547
|
+
parseEthUsdPrice(priceResponse),
|
|
2548
|
+
MIN_WETH_USD[chainId]
|
|
2549
|
+
);
|
|
2550
|
+
}
|
|
2509
2551
|
const token = getDefaultTokenAddress(chainId, assetSymbol);
|
|
2510
2552
|
const walletClient = this.getWalletClient();
|
|
2511
2553
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
2512
2554
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
2555
|
+
if (!safeAddress) {
|
|
2556
|
+
throw new Error("Smart wallet address is not available");
|
|
2557
|
+
}
|
|
2513
2558
|
const isDeployed = await isSafeDeployed(
|
|
2514
2559
|
safeAddress,
|
|
2515
2560
|
chainConfig.publicClient
|
|
2516
2561
|
);
|
|
2517
2562
|
if (!isDeployed) {
|
|
2518
|
-
if (this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
2519
|
-
await this.deployOnChains([chainId]);
|
|
2520
|
-
const landed = await this.waitForSafeDeployed(
|
|
2521
|
-
safeAddress,
|
|
2522
|
-
chainConfig.publicClient
|
|
2523
|
-
);
|
|
2524
|
-
if (!landed) {
|
|
2525
|
-
throw new Error(
|
|
2526
|
-
`Safe deploy on chain ${chainId} for ${userAddress} did not land \u2014 retry the deposit.`
|
|
2527
|
-
);
|
|
2528
|
-
}
|
|
2529
|
-
} else {
|
|
2563
|
+
if (!(this.isPredeployed && this.isConnectedUser(userAddress))) {
|
|
2530
2564
|
throw new Error(
|
|
2531
2565
|
`Safe not available for ${userAddress} on chain ${chainId}.`
|
|
2532
2566
|
);
|
|
@@ -2696,6 +2730,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2696
2730
|
}
|
|
2697
2731
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
2698
2732
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
2733
|
+
if (!safeAddress) {
|
|
2734
|
+
throw new Error("Smart wallet address is not available");
|
|
2735
|
+
}
|
|
2699
2736
|
const isDeployed = await isSafeDeployed(
|
|
2700
2737
|
safeAddress,
|
|
2701
2738
|
chainConfig.publicClient
|
|
@@ -2770,7 +2807,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2770
2807
|
* Get all active DeFi positions for a user
|
|
2771
2808
|
*
|
|
2772
2809
|
* @param userAddress - User's EOA address
|
|
2773
|
-
* @param chainId - Optional
|
|
2810
|
+
* @param chainId - Optional chain used to resolve the Safe address (defaults to Base 8453)
|
|
2774
2811
|
* @returns User's positions across all protocols
|
|
2775
2812
|
*
|
|
2776
2813
|
* @example
|
|
@@ -2790,8 +2827,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2790
2827
|
if (chainId && !isSupportedChain(chainId)) {
|
|
2791
2828
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
2792
2829
|
}
|
|
2793
|
-
const
|
|
2794
|
-
|
|
2830
|
+
const targetChainId = chainId ?? 8453;
|
|
2831
|
+
const smartWallet = await this.getSafeAddressFor(
|
|
2832
|
+
userAddress,
|
|
2833
|
+
targetChainId,
|
|
2834
|
+
false
|
|
2835
|
+
);
|
|
2836
|
+
if (!smartWallet) {
|
|
2795
2837
|
return {
|
|
2796
2838
|
success: true,
|
|
2797
2839
|
userAddress,
|
|
@@ -2799,7 +2841,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2799
2841
|
};
|
|
2800
2842
|
}
|
|
2801
2843
|
const response = await this.httpClient.get(
|
|
2802
|
-
ENDPOINTS.DATA_POSITION(
|
|
2844
|
+
ENDPOINTS.DATA_POSITION(smartWallet)
|
|
2803
2845
|
);
|
|
2804
2846
|
const convertedPosition = response ? convertStrategyToPublic(response) : void 0;
|
|
2805
2847
|
return {
|
|
@@ -2837,15 +2879,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2837
2879
|
if (!userAddress) {
|
|
2838
2880
|
throw new Error("User address is required");
|
|
2839
2881
|
}
|
|
2840
|
-
const
|
|
2841
|
-
|
|
2882
|
+
const smartWallet = await this.getSafeAddressFor(
|
|
2883
|
+
userAddress,
|
|
2884
|
+
8453,
|
|
2885
|
+
false
|
|
2886
|
+
);
|
|
2887
|
+
if (!smartWallet) {
|
|
2842
2888
|
return {
|
|
2843
2889
|
success: true,
|
|
2844
2890
|
userAddress,
|
|
2845
2891
|
portfolio: {}
|
|
2846
2892
|
};
|
|
2847
2893
|
}
|
|
2848
|
-
const smartWallet = smartWalletInfo.smartWallet;
|
|
2849
2894
|
const [response, earningsResult] = await Promise.all([
|
|
2850
2895
|
this.httpClient.get(
|
|
2851
2896
|
ENDPOINTS.DATA_PORTFOLIO(smartWallet)
|
|
@@ -3569,7 +3614,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3569
3614
|
* Get daily APY history with weighted average for a wallet
|
|
3570
3615
|
*
|
|
3571
3616
|
* @param walletAddress - Smart wallet address
|
|
3572
|
-
* @param days - Period: "7D", "14D", or "
|
|
3617
|
+
* @param days - Period: "7D", "14D", "30D", "60D", "120D", or "180D" (default: "7D")
|
|
3573
3618
|
* @returns Daily APY history with per-position breakdowns and weighted averages
|
|
3574
3619
|
*
|
|
3575
3620
|
* @example
|
|
@@ -4559,6 +4604,7 @@ function createBankrProvider(config) {
|
|
|
4559
4604
|
return provider;
|
|
4560
4605
|
}
|
|
4561
4606
|
export {
|
|
4607
|
+
ALLOWED_HISTORY_DAYS,
|
|
4562
4608
|
DEFAULT_TOKEN_ADDRESSES,
|
|
4563
4609
|
ERC7579_LAUNCHPAD_ADDRESS,
|
|
4564
4610
|
INTENT_EXECUTOR,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.53",
|
|
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",
|