@zyfai/sdk 0.4.1 → 0.7.1
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 +10 -4
- package/dist/index.d.mts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +150 -4
- package/dist/index.mjs +149 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ Commit the generated file in `.changeset/` with your PR.
|
|
|
45
45
|
|
|
46
46
|
### Publishing (maintainers)
|
|
47
47
|
|
|
48
|
-
After changesets merge to `
|
|
48
|
+
After changesets merge to `release`, a maintainer runs `npm run version-packages` (`changeset version`), then `npm publish`. Details: [`docs/RELEASING.md`](docs/RELEASING.md).
|
|
49
49
|
|
|
50
50
|
## Prerequisites
|
|
51
51
|
|
|
@@ -472,10 +472,10 @@ if (credited.status === "credited") {
|
|
|
472
472
|
- `depositFunds()` remains a compatibility wrapper that calls both steps and waits through the normal completion window; it **rejects** if credit is not confirmed in that window (track in-flight deposits with `getDepositStatus()` or call `waitForDepositCredit()` with a longer `timeoutMs`).
|
|
473
473
|
- If first-deposit protocol patching fails, the transfer still runs. `sendDeposit()` throws if deposit registration is not accepted; retry `logDeposit()` after `connectAccount()`.
|
|
474
474
|
- **First deposit only** (before transfer + `log_deposit`): if the USDC profile has no `chains` yet, the SDK patches protocols for **USDC, WETH, EURC, and NVDAc**, each across the chains it exists on (EURC on Mainnet/Base, NVDAc on Base → `assetTypeSettings.[usdc|eth|eurc|nvdac]`). Pass optional `strategy` (`"conservative"` default, `"aggressive"` or `"yieldmaxxing"`) — same role as the former `deploySafe` strategy argument. Later deposits skip this.
|
|
475
|
-
- **`strategy` is ignored on later deposits, and no error is raised.** Re-running the patch would overwrite a protocol selection the user may have customised, so passing `"yieldmaxxing"` to an account that has already deposited leaves it on its current strategy. To change an existing account,
|
|
475
|
+
- **`strategy` is ignored on later deposits, and no error is raised.** Re-running the patch would overwrite a protocol selection the user may have customised, so passing `"yieldmaxxing"` to an account that has already deposited leaves it on its current strategy. To change an existing account, use `setStrategyWithProtocols` or `setAssetStrategy` (not `updateUserProfile` alone):
|
|
476
476
|
|
|
477
477
|
```typescript
|
|
478
|
-
await sdk.
|
|
478
|
+
await sdk.setStrategyWithProtocols({ strategy: "yieldmaxxing" });
|
|
479
479
|
```
|
|
480
480
|
|
|
481
481
|
#### Deposit With an External Wallet (Sponsored Transactions)
|
|
@@ -1098,9 +1098,15 @@ but the funds are in flight in between. See
|
|
|
1098
1098
|
|
|
1099
1099
|
`updateUserProfile({ asset, strategy })` stores a strategy but does **not**
|
|
1100
1100
|
compute the protocol list that goes with it, so on its own it leaves the asset
|
|
1101
|
-
with nothing to deploy into. `setAssetStrategy` does both in one call
|
|
1101
|
+
with nothing to deploy into. `setAssetStrategy` does both in one call for one
|
|
1102
|
+
asset. `setStrategyWithProtocols` does the same for one asset or for every
|
|
1103
|
+
entry in `getManagedAssets()` when `asset` is omitted:
|
|
1102
1104
|
|
|
1103
1105
|
```typescript
|
|
1106
|
+
const profiles = await sdk.setStrategyWithProtocols({
|
|
1107
|
+
strategy: "yieldmaxxing",
|
|
1108
|
+
});
|
|
1109
|
+
// Or a single asset:
|
|
1104
1110
|
const profile = await sdk.setAssetStrategy({
|
|
1105
1111
|
asset: "NVDAc",
|
|
1106
1112
|
strategy: "yieldmaxxing",
|
package/dist/index.d.mts
CHANGED
|
@@ -650,6 +650,17 @@ interface WaitForDepositCreditOptions {
|
|
|
650
650
|
/** Maximum wait before throwing `DepositCreditTimeoutError`. */
|
|
651
651
|
timeoutMs?: number;
|
|
652
652
|
}
|
|
653
|
+
/** Polling overrides for {@link ZyfaiSDK.waitForAgentDepositIntent}. */
|
|
654
|
+
interface WaitForAgentDepositIntentOptions {
|
|
655
|
+
intervalMs?: number;
|
|
656
|
+
timeoutMs?: number;
|
|
657
|
+
}
|
|
658
|
+
/** Options for {@link ZyfaiSDK.waitForAgentDepositHandover}. */
|
|
659
|
+
interface WaitForAgentDepositHandoverOptions extends WaitForAgentDepositIntentOptions {
|
|
660
|
+
/** When true (default), poll through custody credit after intent completes. */
|
|
661
|
+
waitForCredit?: boolean;
|
|
662
|
+
credit?: WaitForDepositCreditOptions;
|
|
663
|
+
}
|
|
653
664
|
/** Result of {@link ZyfaiSDK.withdrawFunds}. */
|
|
654
665
|
interface WithdrawResponse {
|
|
655
666
|
success: boolean;
|
|
@@ -1463,6 +1474,19 @@ declare class ZyfaiSDK {
|
|
|
1463
1474
|
strategy?: Strategy;
|
|
1464
1475
|
chains?: SupportedChainId[];
|
|
1465
1476
|
}): Promise<UpdateUserProfileResponse>;
|
|
1477
|
+
/**
|
|
1478
|
+
* Apply a strategy and auto-select matching protocols for one or all managed
|
|
1479
|
+
* assets ({@link getManagedAssets}). Prefer this over
|
|
1480
|
+
* {@link updateUserProfile} when changing strategy so protocols stay aligned
|
|
1481
|
+
* with the tier (including `yieldmaxxing` async venues).
|
|
1482
|
+
*
|
|
1483
|
+
* @group Portfolio and execution
|
|
1484
|
+
*/
|
|
1485
|
+
setStrategyWithProtocols(params: {
|
|
1486
|
+
strategy: Strategy;
|
|
1487
|
+
asset?: SupportedAsset;
|
|
1488
|
+
chains?: SupportedChainId[];
|
|
1489
|
+
}): Promise<UpdateUserProfileResponse[]>;
|
|
1466
1490
|
/**
|
|
1467
1491
|
* Drop protocols that have no pools on any of the selected chains for the
|
|
1468
1492
|
* requested asset. The /customization/pools endpoint filters server-side on
|
|
@@ -2340,6 +2364,27 @@ declare class ZyfaiSDK {
|
|
|
2340
2364
|
getAgentDepositIntentStatus(actionId: string): Promise<{
|
|
2341
2365
|
data: AgentDepositIntentStatus;
|
|
2342
2366
|
}>;
|
|
2367
|
+
/**
|
|
2368
|
+
* Poll MCP deposit-intent status until the signing page registers the transfer.
|
|
2369
|
+
*
|
|
2370
|
+
* @group Agent management
|
|
2371
|
+
*
|
|
2372
|
+
* @throws `AgentDepositIntentTimeoutError` when the intent stays pending past `timeoutMs`
|
|
2373
|
+
* @throws When the intent expires before completion
|
|
2374
|
+
*/
|
|
2375
|
+
waitForAgentDepositIntent(actionId: string, options?: WaitForAgentDepositIntentOptions): Promise<AgentDepositIntentStatus>;
|
|
2376
|
+
/**
|
|
2377
|
+
* Wait for MCP signing completion, then optionally through custody credit.
|
|
2378
|
+
*
|
|
2379
|
+
* Pair with {@link ZyfaiSDK.prepareDeposit} and a browser `signingUrl` from
|
|
2380
|
+
* `createAgentDepositIntent`. Start this poll as soon as the user has the link.
|
|
2381
|
+
*
|
|
2382
|
+
* @group Agent management
|
|
2383
|
+
*/
|
|
2384
|
+
waitForAgentDepositHandover(actionId: string, chainId: SupportedChainId, options?: WaitForAgentDepositHandoverOptions): Promise<{
|
|
2385
|
+
intent: AgentDepositIntentStatus;
|
|
2386
|
+
credited?: DepositLifecycleResponse;
|
|
2387
|
+
}>;
|
|
2343
2388
|
/**
|
|
2344
2389
|
* Mark intent complete after the user signed on zyf.ai (SIWE session).
|
|
2345
2390
|
*
|
|
@@ -2640,6 +2685,13 @@ declare function createBankrProvider(config: BankrProviderConfig): {
|
|
|
2640
2685
|
};
|
|
2641
2686
|
type BankrProvider = ReturnType<typeof createBankrProvider>;
|
|
2642
2687
|
|
|
2688
|
+
/**
|
|
2689
|
+
* Assets the agent manages for pause, resume, first-deposit protocol setup,
|
|
2690
|
+
* and bulk strategy changes. Derived from {@link ASSET_CONFIGS} where
|
|
2691
|
+
* `enabled === true`, with a stable product order for known symbols.
|
|
2692
|
+
*/
|
|
2693
|
+
declare function getManagedAssets(): SupportedAsset[];
|
|
2694
|
+
|
|
2643
2695
|
/**
|
|
2644
2696
|
* API Endpoints Configuration
|
|
2645
2697
|
*
|
|
@@ -2739,4 +2791,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
2739
2791
|
*/
|
|
2740
2792
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
2741
2793
|
|
|
2742
|
-
export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type AsyncWithdrawal, type AsyncWithdrawalStatus, type BackendEnvironment, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DATA_API_BASE_URLS, DATA_API_ENDPOINT, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, 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, LOCAL_DATA_API_BASE_URL, LOCAL_EXECUTION_API_BASE_URL, LOCAL_WS_URL, 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, STAGING_DATA_API_BASE_URL, STAGING_EXECUTION_API_BASE_URL, STAGING_WS_URL, 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, type UserSessionAuth, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, WS_ENDPOINT, WS_URLS, type WaitForDepositCreditOptions, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getSupportedChainIds, getWsUrl, isSupportedChain, type staleBalances };
|
|
2794
|
+
export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type AsyncWithdrawal, type AsyncWithdrawalStatus, type BackendEnvironment, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DATA_API_BASE_URLS, DATA_API_ENDPOINT, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, 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, LOCAL_DATA_API_BASE_URL, LOCAL_EXECUTION_API_BASE_URL, LOCAL_WS_URL, 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, STAGING_DATA_API_BASE_URL, STAGING_EXECUTION_API_BASE_URL, STAGING_WS_URL, 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, type UserSessionAuth, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, WS_ENDPOINT, WS_URLS, type WaitForDepositCreditOptions, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, isSupportedChain, type staleBalances };
|
package/dist/index.d.ts
CHANGED
|
@@ -650,6 +650,17 @@ interface WaitForDepositCreditOptions {
|
|
|
650
650
|
/** Maximum wait before throwing `DepositCreditTimeoutError`. */
|
|
651
651
|
timeoutMs?: number;
|
|
652
652
|
}
|
|
653
|
+
/** Polling overrides for {@link ZyfaiSDK.waitForAgentDepositIntent}. */
|
|
654
|
+
interface WaitForAgentDepositIntentOptions {
|
|
655
|
+
intervalMs?: number;
|
|
656
|
+
timeoutMs?: number;
|
|
657
|
+
}
|
|
658
|
+
/** Options for {@link ZyfaiSDK.waitForAgentDepositHandover}. */
|
|
659
|
+
interface WaitForAgentDepositHandoverOptions extends WaitForAgentDepositIntentOptions {
|
|
660
|
+
/** When true (default), poll through custody credit after intent completes. */
|
|
661
|
+
waitForCredit?: boolean;
|
|
662
|
+
credit?: WaitForDepositCreditOptions;
|
|
663
|
+
}
|
|
653
664
|
/** Result of {@link ZyfaiSDK.withdrawFunds}. */
|
|
654
665
|
interface WithdrawResponse {
|
|
655
666
|
success: boolean;
|
|
@@ -1463,6 +1474,19 @@ declare class ZyfaiSDK {
|
|
|
1463
1474
|
strategy?: Strategy;
|
|
1464
1475
|
chains?: SupportedChainId[];
|
|
1465
1476
|
}): Promise<UpdateUserProfileResponse>;
|
|
1477
|
+
/**
|
|
1478
|
+
* Apply a strategy and auto-select matching protocols for one or all managed
|
|
1479
|
+
* assets ({@link getManagedAssets}). Prefer this over
|
|
1480
|
+
* {@link updateUserProfile} when changing strategy so protocols stay aligned
|
|
1481
|
+
* with the tier (including `yieldmaxxing` async venues).
|
|
1482
|
+
*
|
|
1483
|
+
* @group Portfolio and execution
|
|
1484
|
+
*/
|
|
1485
|
+
setStrategyWithProtocols(params: {
|
|
1486
|
+
strategy: Strategy;
|
|
1487
|
+
asset?: SupportedAsset;
|
|
1488
|
+
chains?: SupportedChainId[];
|
|
1489
|
+
}): Promise<UpdateUserProfileResponse[]>;
|
|
1466
1490
|
/**
|
|
1467
1491
|
* Drop protocols that have no pools on any of the selected chains for the
|
|
1468
1492
|
* requested asset. The /customization/pools endpoint filters server-side on
|
|
@@ -2340,6 +2364,27 @@ declare class ZyfaiSDK {
|
|
|
2340
2364
|
getAgentDepositIntentStatus(actionId: string): Promise<{
|
|
2341
2365
|
data: AgentDepositIntentStatus;
|
|
2342
2366
|
}>;
|
|
2367
|
+
/**
|
|
2368
|
+
* Poll MCP deposit-intent status until the signing page registers the transfer.
|
|
2369
|
+
*
|
|
2370
|
+
* @group Agent management
|
|
2371
|
+
*
|
|
2372
|
+
* @throws `AgentDepositIntentTimeoutError` when the intent stays pending past `timeoutMs`
|
|
2373
|
+
* @throws When the intent expires before completion
|
|
2374
|
+
*/
|
|
2375
|
+
waitForAgentDepositIntent(actionId: string, options?: WaitForAgentDepositIntentOptions): Promise<AgentDepositIntentStatus>;
|
|
2376
|
+
/**
|
|
2377
|
+
* Wait for MCP signing completion, then optionally through custody credit.
|
|
2378
|
+
*
|
|
2379
|
+
* Pair with {@link ZyfaiSDK.prepareDeposit} and a browser `signingUrl` from
|
|
2380
|
+
* `createAgentDepositIntent`. Start this poll as soon as the user has the link.
|
|
2381
|
+
*
|
|
2382
|
+
* @group Agent management
|
|
2383
|
+
*/
|
|
2384
|
+
waitForAgentDepositHandover(actionId: string, chainId: SupportedChainId, options?: WaitForAgentDepositHandoverOptions): Promise<{
|
|
2385
|
+
intent: AgentDepositIntentStatus;
|
|
2386
|
+
credited?: DepositLifecycleResponse;
|
|
2387
|
+
}>;
|
|
2343
2388
|
/**
|
|
2344
2389
|
* Mark intent complete after the user signed on zyf.ai (SIWE session).
|
|
2345
2390
|
*
|
|
@@ -2640,6 +2685,13 @@ declare function createBankrProvider(config: BankrProviderConfig): {
|
|
|
2640
2685
|
};
|
|
2641
2686
|
type BankrProvider = ReturnType<typeof createBankrProvider>;
|
|
2642
2687
|
|
|
2688
|
+
/**
|
|
2689
|
+
* Assets the agent manages for pause, resume, first-deposit protocol setup,
|
|
2690
|
+
* and bulk strategy changes. Derived from {@link ASSET_CONFIGS} where
|
|
2691
|
+
* `enabled === true`, with a stable product order for known symbols.
|
|
2692
|
+
*/
|
|
2693
|
+
declare function getManagedAssets(): SupportedAsset[];
|
|
2694
|
+
|
|
2643
2695
|
/**
|
|
2644
2696
|
* API Endpoints Configuration
|
|
2645
2697
|
*
|
|
@@ -2739,4 +2791,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
2739
2791
|
*/
|
|
2740
2792
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
2741
2793
|
|
|
2742
|
-
export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type AsyncWithdrawal, type AsyncWithdrawalStatus, type BackendEnvironment, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DATA_API_BASE_URLS, DATA_API_ENDPOINT, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, 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, LOCAL_DATA_API_BASE_URL, LOCAL_EXECUTION_API_BASE_URL, LOCAL_WS_URL, 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, STAGING_DATA_API_BASE_URL, STAGING_EXECUTION_API_BASE_URL, STAGING_WS_URL, 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, type UserSessionAuth, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, WS_ENDPOINT, WS_URLS, type WaitForDepositCreditOptions, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getSupportedChainIds, getWsUrl, isSupportedChain, type staleBalances };
|
|
2794
|
+
export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type AllocationDetail, type AllowedHistoryDays, type ApyPosition, type AsyncWithdrawal, type AsyncWithdrawalStatus, type BackendEnvironment, type BankrProvider, type BankrProviderConfig, type BestOpportunityDetails, type BestOpportunityResponse, type ChainConfig, type ChainPortfolio, type ChainTokenEarnings, type CustomizationConfig, type CustomizeBatchRequest, type CustomizeBatchResponse, DATA_API_BASE_URLS, DATA_API_ENDPOINT, DEFAULT_TOKEN_ADDRESSES, type DailyApyEntry, type DailyApyHistoryPeriod, type DailyApyHistoryResponse, type DailyEarning, type DailyEarningsResponse, type DebankPortfolioResponse, type DepegEvent, type DeploySafeResponse, type DepositLifecycleResponse, type DepositLifecycleStatus, type DepositResponse, ERC7579_LAUNCHPAD_ADDRESS, type ERC7739Context, type ERC7739Data, EXECUTION_API_BASE_URLS, 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, LOCAL_DATA_API_BASE_URL, LOCAL_EXECUTION_API_BASE_URL, LOCAL_WS_URL, 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, STAGING_DATA_API_BASE_URL, STAGING_EXECUTION_API_BASE_URL, STAGING_WS_URL, 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, type UserSessionAuth, VAULT_ADDRESS, type VaultAsset, type VaultClaimResponse, type VaultDepositResponse, type VaultSharesResponse, type VaultWithdrawResponse, type VaultWithdrawStatusResponse, type VolumeResponse, WS_ENDPOINT, WS_URLS, type WaitForDepositCreditOptions, type WalletTVL, type WithdrawResponse, type ZyfaiEventFilters, type ZyfaiEventHandlers, ZyfaiSDK, createBankrProvider, getChainConfig, getDataApiBaseUrl, getDefaultTokenAddress, getExecutionApiBaseUrl, getManagedAssets, getSupportedChainIds, getWsUrl, isSupportedChain, type staleBalances };
|
package/dist/index.js
CHANGED
|
@@ -60,6 +60,7 @@ __export(index_exports, {
|
|
|
60
60
|
getDataApiBaseUrl: () => getDataApiBaseUrl,
|
|
61
61
|
getDefaultTokenAddress: () => getDefaultTokenAddress,
|
|
62
62
|
getExecutionApiBaseUrl: () => getExecutionApiBaseUrl,
|
|
63
|
+
getManagedAssets: () => getManagedAssets,
|
|
63
64
|
getSupportedChainIds: () => getSupportedChainIds,
|
|
64
65
|
getWsUrl: () => getWsUrl,
|
|
65
66
|
isSupportedChain: () => isSupportedChain
|
|
@@ -680,6 +681,8 @@ var DEPOSIT_CREDIT_TIMEOUT_MS = {
|
|
|
680
681
|
};
|
|
681
682
|
var getDepositCreditIntervalMs = (chainId) => DEPOSIT_CREDIT_INTERVAL_MS[chainId];
|
|
682
683
|
var getDepositCreditTimeoutMs = (chainId) => DEPOSIT_CREDIT_TIMEOUT_MS[chainId];
|
|
684
|
+
var AGENT_DEPOSIT_INTENT_INTERVAL_MS = 1500;
|
|
685
|
+
var AGENT_DEPOSIT_INTENT_TIMEOUT_MS = 30 * 60 * 1e3;
|
|
683
686
|
var formatMinPortfolioLabel = (raw, decimals, symbol) => {
|
|
684
687
|
const base2 = 10n ** BigInt(decimals);
|
|
685
688
|
const whole = raw / base2;
|
|
@@ -888,6 +891,22 @@ var getSupportedChainIds = () => {
|
|
|
888
891
|
return Object.keys(CHAINS).map(Number);
|
|
889
892
|
};
|
|
890
893
|
|
|
894
|
+
// src/config/managed-assets.ts
|
|
895
|
+
var MANAGED_ASSET_ORDER = [
|
|
896
|
+
"USDC",
|
|
897
|
+
"WETH",
|
|
898
|
+
"EURC",
|
|
899
|
+
"NVDAc"
|
|
900
|
+
];
|
|
901
|
+
function getManagedAssets() {
|
|
902
|
+
const enabled = Object.entries(ASSET_CONFIGS).filter(([, config]) => config?.enabled === true).map(([key]) => key);
|
|
903
|
+
const ordered = MANAGED_ASSET_ORDER.filter(
|
|
904
|
+
(symbol) => enabled.includes(symbol)
|
|
905
|
+
);
|
|
906
|
+
const remainder = enabled.filter((symbol) => !MANAGED_ASSET_ORDER.includes(symbol)).sort((a, b) => a.localeCompare(b));
|
|
907
|
+
return [...ordered, ...remainder];
|
|
908
|
+
}
|
|
909
|
+
|
|
891
910
|
// src/utils/safe-account.ts
|
|
892
911
|
var import_module_sdk = require("@rhinestone/module-sdk");
|
|
893
912
|
var import_accounts = require("permissionless/accounts");
|
|
@@ -1664,7 +1683,12 @@ var DepositCreditTimeoutError = class extends Error {
|
|
|
1664
1683
|
this.name = "DepositCreditTimeoutError";
|
|
1665
1684
|
}
|
|
1666
1685
|
};
|
|
1667
|
-
var
|
|
1686
|
+
var AgentDepositIntentTimeoutError = class extends Error {
|
|
1687
|
+
constructor(actionId) {
|
|
1688
|
+
super(`Timed out waiting for agent deposit intent ${actionId} to complete`);
|
|
1689
|
+
this.name = "AgentDepositIntentTimeoutError";
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1668
1692
|
var _ZyfaiSDK = class _ZyfaiSDK {
|
|
1669
1693
|
/**
|
|
1670
1694
|
* Create an SDK instance bound to a partner API key.
|
|
@@ -1970,7 +1994,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1970
1994
|
async pauseAgent() {
|
|
1971
1995
|
try {
|
|
1972
1996
|
let latest;
|
|
1973
|
-
for (const asset of
|
|
1997
|
+
for (const asset of getManagedAssets()) {
|
|
1974
1998
|
latest = await this.updateUserProfile({ asset, protocols: [] });
|
|
1975
1999
|
}
|
|
1976
2000
|
if (!latest) {
|
|
@@ -2009,7 +2033,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2009
2033
|
ENDPOINTS.PROTOCOLS()
|
|
2010
2034
|
);
|
|
2011
2035
|
let latest;
|
|
2012
|
-
for (const asset of
|
|
2036
|
+
for (const asset of getManagedAssets()) {
|
|
2013
2037
|
latest = await this.updateUserProtocolsForAsset(
|
|
2014
2038
|
asset,
|
|
2015
2039
|
getAssetChainIds(asset),
|
|
@@ -2788,7 +2812,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2788
2812
|
const allProtocols = await this.httpClient.get(
|
|
2789
2813
|
ENDPOINTS.PROTOCOLS()
|
|
2790
2814
|
);
|
|
2791
|
-
for (const asset of
|
|
2815
|
+
for (const asset of getManagedAssets()) {
|
|
2792
2816
|
try {
|
|
2793
2817
|
await this.updateUserProtocolsForAsset(
|
|
2794
2818
|
asset,
|
|
@@ -2961,6 +2985,77 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2961
2985
|
);
|
|
2962
2986
|
}
|
|
2963
2987
|
}
|
|
2988
|
+
/**
|
|
2989
|
+
* Apply a strategy and auto-select matching protocols for one or all managed
|
|
2990
|
+
* assets ({@link getManagedAssets}). Prefer this over
|
|
2991
|
+
* {@link updateUserProfile} when changing strategy so protocols stay aligned
|
|
2992
|
+
* with the tier (including `yieldmaxxing` async venues).
|
|
2993
|
+
*
|
|
2994
|
+
* @group Portfolio and execution
|
|
2995
|
+
*/
|
|
2996
|
+
async setStrategyWithProtocols(params) {
|
|
2997
|
+
const { strategy, asset, chains } = params;
|
|
2998
|
+
if (!isValidPublicStrategy(strategy)) {
|
|
2999
|
+
throw new Error(
|
|
3000
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
3001
|
+
);
|
|
3002
|
+
}
|
|
3003
|
+
const assets = asset ? [asset] : getManagedAssets();
|
|
3004
|
+
if (assets.length === 0) {
|
|
3005
|
+
throw new Error("No managed assets available to configure.");
|
|
3006
|
+
}
|
|
3007
|
+
const plannedUpdates = [];
|
|
3008
|
+
const validationErrors = [];
|
|
3009
|
+
for (const targetAsset of assets) {
|
|
3010
|
+
const supported = getAssetChainIds(targetAsset);
|
|
3011
|
+
if (supported.length === 0) {
|
|
3012
|
+
validationErrors.push(`${targetAsset}: Unsupported asset: ${targetAsset}.`);
|
|
3013
|
+
continue;
|
|
3014
|
+
}
|
|
3015
|
+
const targetChains = chains ?? supported;
|
|
3016
|
+
const unsupported = targetChains.filter((c) => !supported.includes(c));
|
|
3017
|
+
if (unsupported.length > 0) {
|
|
3018
|
+
validationErrors.push(
|
|
3019
|
+
`${targetAsset}: ${targetAsset} is not available on chain ${unsupported.join(
|
|
3020
|
+
", "
|
|
3021
|
+
)}. Supported chains: ${supported.join(", ")}.`
|
|
3022
|
+
);
|
|
3023
|
+
continue;
|
|
3024
|
+
}
|
|
3025
|
+
plannedUpdates.push({ targetAsset, targetChains });
|
|
3026
|
+
}
|
|
3027
|
+
if (validationErrors.length > 0) {
|
|
3028
|
+
throw new Error(
|
|
3029
|
+
`Failed to set strategy with protocols: ${validationErrors.join("; ")}`
|
|
3030
|
+
);
|
|
3031
|
+
}
|
|
3032
|
+
const allProtocols = await this.httpClient.get(
|
|
3033
|
+
ENDPOINTS.PROTOCOLS()
|
|
3034
|
+
);
|
|
3035
|
+
const results = [];
|
|
3036
|
+
const errors = [];
|
|
3037
|
+
for (const { targetAsset, targetChains } of plannedUpdates) {
|
|
3038
|
+
try {
|
|
3039
|
+
const profile = await this.updateUserProtocolsForAsset(
|
|
3040
|
+
targetAsset,
|
|
3041
|
+
targetChains,
|
|
3042
|
+
strategy,
|
|
3043
|
+
allProtocols
|
|
3044
|
+
);
|
|
3045
|
+
results.push(profile);
|
|
3046
|
+
} catch (error) {
|
|
3047
|
+
errors.push(
|
|
3048
|
+
`${targetAsset}: ${error instanceof Error ? error.message : String(error)}`
|
|
3049
|
+
);
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
if (errors.length > 0) {
|
|
3053
|
+
throw new Error(
|
|
3054
|
+
`Failed to set strategy with protocols: ${errors.join("; ")}`
|
|
3055
|
+
);
|
|
3056
|
+
}
|
|
3057
|
+
return results;
|
|
3058
|
+
}
|
|
2964
3059
|
/**
|
|
2965
3060
|
* Drop protocols that have no pools on any of the selected chains for the
|
|
2966
3061
|
* requested asset. The /customization/pools endpoint filters server-side on
|
|
@@ -4982,6 +5077,56 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4982
5077
|
ENDPOINTS.USER_AGENT_DEPOSIT_INTENT(actionId)
|
|
4983
5078
|
);
|
|
4984
5079
|
}
|
|
5080
|
+
/**
|
|
5081
|
+
* Poll MCP deposit-intent status until the signing page registers the transfer.
|
|
5082
|
+
*
|
|
5083
|
+
* @group Agent management
|
|
5084
|
+
*
|
|
5085
|
+
* @throws `AgentDepositIntentTimeoutError` when the intent stays pending past `timeoutMs`
|
|
5086
|
+
* @throws When the intent expires before completion
|
|
5087
|
+
*/
|
|
5088
|
+
async waitForAgentDepositIntent(actionId, options) {
|
|
5089
|
+
if (!actionId) {
|
|
5090
|
+
throw new Error("actionId is required");
|
|
5091
|
+
}
|
|
5092
|
+
const intervalMs = options?.intervalMs ?? AGENT_DEPOSIT_INTENT_INTERVAL_MS;
|
|
5093
|
+
const timeoutMs = options?.timeoutMs ?? AGENT_DEPOSIT_INTENT_TIMEOUT_MS;
|
|
5094
|
+
const started = Date.now();
|
|
5095
|
+
while (Date.now() - started < timeoutMs) {
|
|
5096
|
+
const { data } = await this.getAgentDepositIntentStatus(actionId);
|
|
5097
|
+
if (data.status === "completed") {
|
|
5098
|
+
return data;
|
|
5099
|
+
}
|
|
5100
|
+
if (data.status === "expired") {
|
|
5101
|
+
throw new Error(`Agent deposit intent ${actionId} expired`);
|
|
5102
|
+
}
|
|
5103
|
+
if (Date.now() - started >= timeoutMs) {
|
|
5104
|
+
break;
|
|
5105
|
+
}
|
|
5106
|
+
await sleep(intervalMs);
|
|
5107
|
+
}
|
|
5108
|
+
throw new AgentDepositIntentTimeoutError(actionId);
|
|
5109
|
+
}
|
|
5110
|
+
/**
|
|
5111
|
+
* Wait for MCP signing completion, then optionally through custody credit.
|
|
5112
|
+
*
|
|
5113
|
+
* Pair with {@link ZyfaiSDK.prepareDeposit} and a browser `signingUrl` from
|
|
5114
|
+
* `createAgentDepositIntent`. Start this poll as soon as the user has the link.
|
|
5115
|
+
*
|
|
5116
|
+
* @group Agent management
|
|
5117
|
+
*/
|
|
5118
|
+
async waitForAgentDepositHandover(actionId, chainId, options) {
|
|
5119
|
+
const intent = await this.waitForAgentDepositIntent(actionId, options);
|
|
5120
|
+
if (options?.waitForCredit === false || !intent.depositId) {
|
|
5121
|
+
return { intent };
|
|
5122
|
+
}
|
|
5123
|
+
const credited = await this.waitForDepositCredit(
|
|
5124
|
+
intent.depositId,
|
|
5125
|
+
chainId,
|
|
5126
|
+
options?.credit
|
|
5127
|
+
);
|
|
5128
|
+
return { intent, credited };
|
|
5129
|
+
}
|
|
4985
5130
|
/**
|
|
4986
5131
|
* Mark intent complete after the user signed on zyf.ai (SIWE session).
|
|
4987
5132
|
*
|
|
@@ -5865,6 +6010,7 @@ function createBankrProvider(config) {
|
|
|
5865
6010
|
getDataApiBaseUrl,
|
|
5866
6011
|
getDefaultTokenAddress,
|
|
5867
6012
|
getExecutionApiBaseUrl,
|
|
6013
|
+
getManagedAssets,
|
|
5868
6014
|
getSupportedChainIds,
|
|
5869
6015
|
getWsUrl,
|
|
5870
6016
|
isSupportedChain
|
package/dist/index.mjs
CHANGED
|
@@ -612,6 +612,8 @@ var DEPOSIT_CREDIT_TIMEOUT_MS = {
|
|
|
612
612
|
};
|
|
613
613
|
var getDepositCreditIntervalMs = (chainId) => DEPOSIT_CREDIT_INTERVAL_MS[chainId];
|
|
614
614
|
var getDepositCreditTimeoutMs = (chainId) => DEPOSIT_CREDIT_TIMEOUT_MS[chainId];
|
|
615
|
+
var AGENT_DEPOSIT_INTENT_INTERVAL_MS = 1500;
|
|
616
|
+
var AGENT_DEPOSIT_INTENT_TIMEOUT_MS = 30 * 60 * 1e3;
|
|
615
617
|
var formatMinPortfolioLabel = (raw, decimals, symbol) => {
|
|
616
618
|
const base2 = 10n ** BigInt(decimals);
|
|
617
619
|
const whole = raw / base2;
|
|
@@ -826,6 +828,22 @@ var getSupportedChainIds = () => {
|
|
|
826
828
|
return Object.keys(CHAINS).map(Number);
|
|
827
829
|
};
|
|
828
830
|
|
|
831
|
+
// src/config/managed-assets.ts
|
|
832
|
+
var MANAGED_ASSET_ORDER = [
|
|
833
|
+
"USDC",
|
|
834
|
+
"WETH",
|
|
835
|
+
"EURC",
|
|
836
|
+
"NVDAc"
|
|
837
|
+
];
|
|
838
|
+
function getManagedAssets() {
|
|
839
|
+
const enabled = Object.entries(ASSET_CONFIGS).filter(([, config]) => config?.enabled === true).map(([key]) => key);
|
|
840
|
+
const ordered = MANAGED_ASSET_ORDER.filter(
|
|
841
|
+
(symbol) => enabled.includes(symbol)
|
|
842
|
+
);
|
|
843
|
+
const remainder = enabled.filter((symbol) => !MANAGED_ASSET_ORDER.includes(symbol)).sort((a, b) => a.localeCompare(b));
|
|
844
|
+
return [...ordered, ...remainder];
|
|
845
|
+
}
|
|
846
|
+
|
|
829
847
|
// src/utils/safe-account.ts
|
|
830
848
|
import {
|
|
831
849
|
RHINESTONE_ATTESTER_ADDRESS,
|
|
@@ -1616,7 +1634,12 @@ var DepositCreditTimeoutError = class extends Error {
|
|
|
1616
1634
|
this.name = "DepositCreditTimeoutError";
|
|
1617
1635
|
}
|
|
1618
1636
|
};
|
|
1619
|
-
var
|
|
1637
|
+
var AgentDepositIntentTimeoutError = class extends Error {
|
|
1638
|
+
constructor(actionId) {
|
|
1639
|
+
super(`Timed out waiting for agent deposit intent ${actionId} to complete`);
|
|
1640
|
+
this.name = "AgentDepositIntentTimeoutError";
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1620
1643
|
var _ZyfaiSDK = class _ZyfaiSDK {
|
|
1621
1644
|
/**
|
|
1622
1645
|
* Create an SDK instance bound to a partner API key.
|
|
@@ -1922,7 +1945,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1922
1945
|
async pauseAgent() {
|
|
1923
1946
|
try {
|
|
1924
1947
|
let latest;
|
|
1925
|
-
for (const asset of
|
|
1948
|
+
for (const asset of getManagedAssets()) {
|
|
1926
1949
|
latest = await this.updateUserProfile({ asset, protocols: [] });
|
|
1927
1950
|
}
|
|
1928
1951
|
if (!latest) {
|
|
@@ -1961,7 +1984,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1961
1984
|
ENDPOINTS.PROTOCOLS()
|
|
1962
1985
|
);
|
|
1963
1986
|
let latest;
|
|
1964
|
-
for (const asset of
|
|
1987
|
+
for (const asset of getManagedAssets()) {
|
|
1965
1988
|
latest = await this.updateUserProtocolsForAsset(
|
|
1966
1989
|
asset,
|
|
1967
1990
|
getAssetChainIds(asset),
|
|
@@ -2740,7 +2763,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2740
2763
|
const allProtocols = await this.httpClient.get(
|
|
2741
2764
|
ENDPOINTS.PROTOCOLS()
|
|
2742
2765
|
);
|
|
2743
|
-
for (const asset of
|
|
2766
|
+
for (const asset of getManagedAssets()) {
|
|
2744
2767
|
try {
|
|
2745
2768
|
await this.updateUserProtocolsForAsset(
|
|
2746
2769
|
asset,
|
|
@@ -2913,6 +2936,77 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2913
2936
|
);
|
|
2914
2937
|
}
|
|
2915
2938
|
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Apply a strategy and auto-select matching protocols for one or all managed
|
|
2941
|
+
* assets ({@link getManagedAssets}). Prefer this over
|
|
2942
|
+
* {@link updateUserProfile} when changing strategy so protocols stay aligned
|
|
2943
|
+
* with the tier (including `yieldmaxxing` async venues).
|
|
2944
|
+
*
|
|
2945
|
+
* @group Portfolio and execution
|
|
2946
|
+
*/
|
|
2947
|
+
async setStrategyWithProtocols(params) {
|
|
2948
|
+
const { strategy, asset, chains } = params;
|
|
2949
|
+
if (!isValidPublicStrategy(strategy)) {
|
|
2950
|
+
throw new Error(
|
|
2951
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
2952
|
+
);
|
|
2953
|
+
}
|
|
2954
|
+
const assets = asset ? [asset] : getManagedAssets();
|
|
2955
|
+
if (assets.length === 0) {
|
|
2956
|
+
throw new Error("No managed assets available to configure.");
|
|
2957
|
+
}
|
|
2958
|
+
const plannedUpdates = [];
|
|
2959
|
+
const validationErrors = [];
|
|
2960
|
+
for (const targetAsset of assets) {
|
|
2961
|
+
const supported = getAssetChainIds(targetAsset);
|
|
2962
|
+
if (supported.length === 0) {
|
|
2963
|
+
validationErrors.push(`${targetAsset}: Unsupported asset: ${targetAsset}.`);
|
|
2964
|
+
continue;
|
|
2965
|
+
}
|
|
2966
|
+
const targetChains = chains ?? supported;
|
|
2967
|
+
const unsupported = targetChains.filter((c) => !supported.includes(c));
|
|
2968
|
+
if (unsupported.length > 0) {
|
|
2969
|
+
validationErrors.push(
|
|
2970
|
+
`${targetAsset}: ${targetAsset} is not available on chain ${unsupported.join(
|
|
2971
|
+
", "
|
|
2972
|
+
)}. Supported chains: ${supported.join(", ")}.`
|
|
2973
|
+
);
|
|
2974
|
+
continue;
|
|
2975
|
+
}
|
|
2976
|
+
plannedUpdates.push({ targetAsset, targetChains });
|
|
2977
|
+
}
|
|
2978
|
+
if (validationErrors.length > 0) {
|
|
2979
|
+
throw new Error(
|
|
2980
|
+
`Failed to set strategy with protocols: ${validationErrors.join("; ")}`
|
|
2981
|
+
);
|
|
2982
|
+
}
|
|
2983
|
+
const allProtocols = await this.httpClient.get(
|
|
2984
|
+
ENDPOINTS.PROTOCOLS()
|
|
2985
|
+
);
|
|
2986
|
+
const results = [];
|
|
2987
|
+
const errors = [];
|
|
2988
|
+
for (const { targetAsset, targetChains } of plannedUpdates) {
|
|
2989
|
+
try {
|
|
2990
|
+
const profile = await this.updateUserProtocolsForAsset(
|
|
2991
|
+
targetAsset,
|
|
2992
|
+
targetChains,
|
|
2993
|
+
strategy,
|
|
2994
|
+
allProtocols
|
|
2995
|
+
);
|
|
2996
|
+
results.push(profile);
|
|
2997
|
+
} catch (error) {
|
|
2998
|
+
errors.push(
|
|
2999
|
+
`${targetAsset}: ${error instanceof Error ? error.message : String(error)}`
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
if (errors.length > 0) {
|
|
3004
|
+
throw new Error(
|
|
3005
|
+
`Failed to set strategy with protocols: ${errors.join("; ")}`
|
|
3006
|
+
);
|
|
3007
|
+
}
|
|
3008
|
+
return results;
|
|
3009
|
+
}
|
|
2916
3010
|
/**
|
|
2917
3011
|
* Drop protocols that have no pools on any of the selected chains for the
|
|
2918
3012
|
* requested asset. The /customization/pools endpoint filters server-side on
|
|
@@ -4934,6 +5028,56 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4934
5028
|
ENDPOINTS.USER_AGENT_DEPOSIT_INTENT(actionId)
|
|
4935
5029
|
);
|
|
4936
5030
|
}
|
|
5031
|
+
/**
|
|
5032
|
+
* Poll MCP deposit-intent status until the signing page registers the transfer.
|
|
5033
|
+
*
|
|
5034
|
+
* @group Agent management
|
|
5035
|
+
*
|
|
5036
|
+
* @throws `AgentDepositIntentTimeoutError` when the intent stays pending past `timeoutMs`
|
|
5037
|
+
* @throws When the intent expires before completion
|
|
5038
|
+
*/
|
|
5039
|
+
async waitForAgentDepositIntent(actionId, options) {
|
|
5040
|
+
if (!actionId) {
|
|
5041
|
+
throw new Error("actionId is required");
|
|
5042
|
+
}
|
|
5043
|
+
const intervalMs = options?.intervalMs ?? AGENT_DEPOSIT_INTENT_INTERVAL_MS;
|
|
5044
|
+
const timeoutMs = options?.timeoutMs ?? AGENT_DEPOSIT_INTENT_TIMEOUT_MS;
|
|
5045
|
+
const started = Date.now();
|
|
5046
|
+
while (Date.now() - started < timeoutMs) {
|
|
5047
|
+
const { data } = await this.getAgentDepositIntentStatus(actionId);
|
|
5048
|
+
if (data.status === "completed") {
|
|
5049
|
+
return data;
|
|
5050
|
+
}
|
|
5051
|
+
if (data.status === "expired") {
|
|
5052
|
+
throw new Error(`Agent deposit intent ${actionId} expired`);
|
|
5053
|
+
}
|
|
5054
|
+
if (Date.now() - started >= timeoutMs) {
|
|
5055
|
+
break;
|
|
5056
|
+
}
|
|
5057
|
+
await sleep(intervalMs);
|
|
5058
|
+
}
|
|
5059
|
+
throw new AgentDepositIntentTimeoutError(actionId);
|
|
5060
|
+
}
|
|
5061
|
+
/**
|
|
5062
|
+
* Wait for MCP signing completion, then optionally through custody credit.
|
|
5063
|
+
*
|
|
5064
|
+
* Pair with {@link ZyfaiSDK.prepareDeposit} and a browser `signingUrl` from
|
|
5065
|
+
* `createAgentDepositIntent`. Start this poll as soon as the user has the link.
|
|
5066
|
+
*
|
|
5067
|
+
* @group Agent management
|
|
5068
|
+
*/
|
|
5069
|
+
async waitForAgentDepositHandover(actionId, chainId, options) {
|
|
5070
|
+
const intent = await this.waitForAgentDepositIntent(actionId, options);
|
|
5071
|
+
if (options?.waitForCredit === false || !intent.depositId) {
|
|
5072
|
+
return { intent };
|
|
5073
|
+
}
|
|
5074
|
+
const credited = await this.waitForDepositCredit(
|
|
5075
|
+
intent.depositId,
|
|
5076
|
+
chainId,
|
|
5077
|
+
options?.credit
|
|
5078
|
+
);
|
|
5079
|
+
return { intent, credited };
|
|
5080
|
+
}
|
|
4937
5081
|
/**
|
|
4938
5082
|
* Mark intent complete after the user signed on zyf.ai (SIWE session).
|
|
4939
5083
|
*
|
|
@@ -5816,6 +5960,7 @@ export {
|
|
|
5816
5960
|
getDataApiBaseUrl,
|
|
5817
5961
|
getDefaultTokenAddress,
|
|
5818
5962
|
getExecutionApiBaseUrl,
|
|
5963
|
+
getManagedAssets,
|
|
5819
5964
|
getSupportedChainIds,
|
|
5820
5965
|
getWsUrl,
|
|
5821
5966
|
isSupportedChain
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "TypeScript SDK for self-custodial Zyfai yield agents: discover DeFi opportunities and manage deposits, withdrawals, positions, and strategies across Ethereum, Base, and Arbitrum",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"changeset": "changeset",
|
|
35
35
|
"version-packages": "changeset version",
|
|
36
36
|
"prepublishOnly": "npm run build",
|
|
37
|
+
"prepare": "npm run build",
|
|
37
38
|
"docs": "typedoc",
|
|
38
39
|
"docs:watch": "typedoc --watch",
|
|
39
40
|
"docs:json": "typedoc --json docs/api.json",
|