@zyfai/sdk 0.3.1 → 0.4.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 +11 -11
- package/dist/index.d.mts +80 -51
- package/dist/index.d.ts +80 -51
- package/dist/index.js +155 -42
- package/dist/index.mjs +155 -42
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@zyfai/sdk)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
TypeScript SDK for
|
|
6
|
+
TypeScript SDK for integrating self-custodial Zyfai yield agents. Discover DeFi opportunities and manage deposits, withdrawals, positions, and strategies across Ethereum Mainnet, Base, and Arbitrum.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Get an API key from [sma.zyf.ai](https://sma.zyf.ai/). For chat-based integrations, use the hosted MCP endpoint at [`https://mcp.zyf.ai/mcp`](https://mcp.zyf.ai/mcp) (registry ID: `io.github.ondefy/zyfai`).
|
|
9
9
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
12
|
-
- **
|
|
12
|
+
- **First-Deposit Onboarding**: The first deposit assigns a pre-deployed Safe and active session to the user's EOA
|
|
13
13
|
- **Flexible Authentication**: Support for private keys and modern wallet providers
|
|
14
14
|
- **Multi-Chain Support**: Works on Ethereum Mainnet, Base, and Arbitrum
|
|
15
15
|
- **Yield Optimization**: Access to multiple DeFi protocols and strategies
|
|
@@ -51,7 +51,7 @@ After changesets merge to `main`, a maintainer runs `npm run version-packages`,
|
|
|
51
51
|
|
|
52
52
|
1. **API Key**: Single API key for both Execution API (Safe deployment, transactions, session keys) and Data API (earnings, opportunities, analytics)
|
|
53
53
|
|
|
54
|
-
**Get your API key from [Zyfai Dashboard](https://
|
|
54
|
+
**Get your API key from [Zyfai Dashboard](https://sma.zyf.ai)**
|
|
55
55
|
|
|
56
56
|
## Quick Start
|
|
57
57
|
|
|
@@ -426,9 +426,9 @@ Transfer tokens to your Safe smart wallet. Token address is automatically select
|
|
|
426
426
|
**Minimum portfolio balance (enforced on Safe balance + deposit amount):**
|
|
427
427
|
|
|
428
428
|
- Ethereum Mainnet (1) / USDC or EURC: 10,000 units
|
|
429
|
-
- Base (8453) and Arbitrum (42161) / USDC or EURC:
|
|
430
|
-
- WETH: about **$10,000** of ETH on Ethereum Mainnet, **$
|
|
431
|
-
- NVDAc: about **$
|
|
429
|
+
- Base (8453) and Arbitrum (42161) / USDC or EURC: 10 units
|
|
430
|
+
- WETH: about **$10,000** of ETH on Ethereum Mainnet, **$10** on Base and Arbitrum
|
|
431
|
+
- NVDAc: about **$10** on Base
|
|
432
432
|
|
|
433
433
|
Minimums for WETH and NVDAc are quoted in dollars and converted at deposit time from the live USD price (Data API `GET /api/v2/price?token=eth` and `?token=nvdac`, same API key as the SDK), so the on-chain threshold moves with the market.
|
|
434
434
|
|
|
@@ -1131,9 +1131,9 @@ resolves to zero protocols for NVDAc and the agent has nothing to deploy into.
|
|
|
1131
1131
|
Every NVDAc withdrawal is therefore a delayed one — read
|
|
1132
1132
|
[Total balance](#total-balance) before showing a balance.
|
|
1133
1133
|
|
|
1134
|
-
**The minimum deposit is $
|
|
1134
|
+
**The minimum deposit is $10 of NVDAc, not 10 NVDAc.** It is converted from
|
|
1135
1135
|
the live price at deposit time, so the threshold in token units moves daily
|
|
1136
|
-
(around `0.
|
|
1136
|
+
(around `0.044` NVDAc at $225/share).
|
|
1137
1137
|
|
|
1138
1138
|
**Deposits pause when the market is closed**, typically over the weekend. Funds
|
|
1139
1139
|
stay idle in the Safe and are deployed at the next open; other assets are
|
|
@@ -1145,7 +1145,7 @@ unaffected. `getPortfolio` returns ready-to-display copy in
|
|
|
1145
1145
|
// Chains default to Base, the only one NVDAc exists on.
|
|
1146
1146
|
await sdk.setAssetStrategy({ asset: "NVDAc", strategy: "yieldmaxxing" });
|
|
1147
1147
|
|
|
1148
|
-
// 1 NVDAc = 100000000 (8 decimals). Must leave at least ~$
|
|
1148
|
+
// 1 NVDAc = 100000000 (8 decimals). Must leave at least ~$10 in the Safe.
|
|
1149
1149
|
const sentNvda = await sdk.sendDeposit(userAddress, 8453, "100000000", "NVDAc");
|
|
1150
1150
|
await sdk.waitForDepositCredit(sentNvda.registration.id, 8453);
|
|
1151
1151
|
```
|
|
@@ -1555,7 +1555,7 @@ npx vitest src/integration/get-protocols.integration.test.ts --fileParallelism=f
|
|
|
1555
1555
|
|
|
1556
1556
|
Tests call `describe.skipIf(!integrationEnvReady())` and skip cleanly when `.env.test` is missing or invalid.
|
|
1557
1557
|
|
|
1558
|
-
When the execution API is **local** or **staging** and `NODE_ENV` is not `production`, the SDK skips client-side minimum portfolio checks so small test deposits (e.g. 0.1 USDC) work without topping up
|
|
1558
|
+
When the execution API is **local** or **staging** and `NODE_ENV` is not `production`, the SDK skips client-side minimum portfolio checks so small test deposits (e.g. 0.1 USDC) work without topping up 10 USDC on Base. Production (`api.zyf.ai`) always enforces real minimums.
|
|
1559
1559
|
|
|
1560
1560
|
**Release smoke (`deposit-withdraw`)** on Base USDC: **local and staging only** — **0.1 USDC** round-trip (fund the test EOA on Base with ~0.1 USDC plus gas). Staging api must have **`SMOKE_AMOUNTS_ENABLED=true`** in its `.env` (see `zyfai-api/docs/deployment.md`). One withdraw per run. Production does not run fund-spending integration tests.
|
|
1561
1561
|
|
package/dist/index.d.mts
CHANGED
|
@@ -44,47 +44,46 @@ interface SDKConfig {
|
|
|
44
44
|
/** @internal Override client-side minimum portfolio checks (local integration). */
|
|
45
45
|
bypassMinPortfolio?: boolean;
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
* Skips SIWE `connectAccount` when the Zyfai access token is already known.
|
|
50
|
-
*/
|
|
51
|
-
/** Agent autonomy limits for MCP / delegated management. */
|
|
52
|
-
interface AgentMandate {
|
|
53
|
-
id: string;
|
|
54
|
-
oauthClientId: string;
|
|
55
|
-
/** Maximum USD of one deposit. Not total capital under management. */
|
|
56
|
-
maxDepositUsd?: string | null;
|
|
57
|
-
allowedChainIds: number[];
|
|
58
|
-
allowedAssets: string[];
|
|
59
|
-
allowRebalance: boolean;
|
|
60
|
-
allowWithdraw: boolean;
|
|
61
|
-
expiresAt?: string | null;
|
|
62
|
-
}
|
|
63
|
-
interface UpsertAgentMandateRequest {
|
|
64
|
-
oauthClientId: string;
|
|
65
|
-
/** Maximum USD of one deposit. Not total capital under management. */
|
|
66
|
-
maxDepositUsd?: string | null;
|
|
67
|
-
allowedChainIds?: number[];
|
|
68
|
-
allowedAssets?: string[];
|
|
69
|
-
allowRebalance?: boolean;
|
|
70
|
-
allowWithdraw?: boolean;
|
|
71
|
-
expiresAt?: string | null;
|
|
72
|
-
}
|
|
73
|
-
/** One-time prepare → enter binding for MCP deposit flows (least-unit amount). */
|
|
74
|
-
interface CreateAgentEnterIntentRequest {
|
|
47
|
+
/** One-time prepare → deposit binding for MCP flows (least-unit amount). */
|
|
48
|
+
interface CreateAgentDepositIntentRequest {
|
|
75
49
|
chainId: number;
|
|
76
50
|
amount: string;
|
|
77
51
|
asset: SupportedAsset;
|
|
78
|
-
strategy?: Strategy;
|
|
79
52
|
}
|
|
80
|
-
interface
|
|
53
|
+
interface AgentDepositIntent {
|
|
81
54
|
actionId: string;
|
|
82
55
|
expiresAt: string;
|
|
56
|
+
signingTicket: string;
|
|
57
|
+
}
|
|
58
|
+
type AgentDepositIntentStatusValue = "pending" | "completed" | "expired";
|
|
59
|
+
interface AgentDepositIntentStatus {
|
|
60
|
+
status: AgentDepositIntentStatusValue;
|
|
61
|
+
actionId?: string;
|
|
62
|
+
depositId?: string;
|
|
63
|
+
txHash?: string;
|
|
64
|
+
chainId?: number;
|
|
65
|
+
asset?: string;
|
|
66
|
+
amount?: string;
|
|
83
67
|
}
|
|
84
|
-
interface
|
|
68
|
+
interface ResolvedAgentDepositIntent {
|
|
69
|
+
actionId: string;
|
|
70
|
+
chainId: number;
|
|
71
|
+
asset: string;
|
|
72
|
+
amount: string;
|
|
73
|
+
status: AgentDepositIntentStatusValue;
|
|
74
|
+
ownerAddress: string;
|
|
75
|
+
expiresAt: string;
|
|
76
|
+
}
|
|
77
|
+
interface ConsumeAgentDepositIntentRequest {
|
|
85
78
|
chainId: number;
|
|
86
79
|
amount: string;
|
|
87
80
|
asset: SupportedAsset;
|
|
81
|
+
txHash: string;
|
|
82
|
+
depositId: string;
|
|
83
|
+
}
|
|
84
|
+
interface CompleteAgentDepositIntentRequest {
|
|
85
|
+
txHash: string;
|
|
86
|
+
depositId: string;
|
|
88
87
|
}
|
|
89
88
|
interface UserSessionAuth {
|
|
90
89
|
/** Zyfai execution API JWT from SIWE login. */
|
|
@@ -93,6 +92,8 @@ interface UserSessionAuth {
|
|
|
93
92
|
userId?: string;
|
|
94
93
|
/** User EOA address (checksum) for address binding checks. */
|
|
95
94
|
eoa?: Address;
|
|
95
|
+
/** Delegated MCP agent JWT (`channel=agent` on the execution API). */
|
|
96
|
+
channel?: "agent";
|
|
96
97
|
}
|
|
97
98
|
interface DeploySafeResponse {
|
|
98
99
|
success: boolean;
|
|
@@ -1005,6 +1006,8 @@ declare class ZyfaiSDK {
|
|
|
1005
1006
|
private authenticatedUserId;
|
|
1006
1007
|
private hasActiveSessionKey;
|
|
1007
1008
|
private isPredeployed;
|
|
1009
|
+
/** False until SIWE login or GET /users/me has set `isPredeployed`. */
|
|
1010
|
+
private predeployedResolved;
|
|
1008
1011
|
private connectedSmartWallet;
|
|
1009
1012
|
private currentProvider;
|
|
1010
1013
|
private currentChainId;
|
|
@@ -1012,6 +1015,8 @@ declare class ZyfaiSDK {
|
|
|
1012
1015
|
private referralSource?;
|
|
1013
1016
|
/** EOA of the active user session (bearer or SIWE). Cleared on disconnect. */
|
|
1014
1017
|
private sessionEoa;
|
|
1018
|
+
/** When set, profile writes use agent-accessible endpoints instead of PATCH /users/me. */
|
|
1019
|
+
private sessionChannel?;
|
|
1015
1020
|
/**
|
|
1016
1021
|
* Create an SDK instance with an existing Zyfai user JWT (no wallet connected).
|
|
1017
1022
|
*
|
|
@@ -1297,10 +1302,16 @@ declare class ZyfaiSDK {
|
|
|
1297
1302
|
*/
|
|
1298
1303
|
private getWalletClient;
|
|
1299
1304
|
/**
|
|
1300
|
-
* True when userAddress is the
|
|
1305
|
+
* True when userAddress is the signer, wallet client, or agent session EOA.
|
|
1301
1306
|
* @private
|
|
1302
1307
|
*/
|
|
1303
1308
|
private isConnectedUser;
|
|
1309
|
+
/**
|
|
1310
|
+
* SIWE login sets predeployed. Agent sessions (`forUser`) do not, so read it
|
|
1311
|
+
* from the user record before allowing a transfer to an undeployed pool Safe.
|
|
1312
|
+
* @private
|
|
1313
|
+
*/
|
|
1314
|
+
private hydrateSessionWallet;
|
|
1304
1315
|
/**
|
|
1305
1316
|
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
1306
1317
|
* user, registered agent for everyone else. If none, CREATE2-derive when
|
|
@@ -1406,6 +1417,11 @@ declare class ZyfaiSDK {
|
|
|
1406
1417
|
* @internal
|
|
1407
1418
|
*/
|
|
1408
1419
|
private updateUserProtocolsForAsset;
|
|
1420
|
+
/**
|
|
1421
|
+
* Persist protocol discovery for one asset (user PATCH or agent deposit-setup).
|
|
1422
|
+
* @internal
|
|
1423
|
+
*/
|
|
1424
|
+
private persistDiscoveredAssetProfile;
|
|
1409
1425
|
/**
|
|
1410
1426
|
* Switch one asset to a strategy and select the protocols that go with it.
|
|
1411
1427
|
*
|
|
@@ -1585,17 +1601,22 @@ declare class ZyfaiSDK {
|
|
|
1585
1601
|
applied: boolean;
|
|
1586
1602
|
}>;
|
|
1587
1603
|
/**
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1604
|
+
* Idempotently configure the deposit asset for a single chain before MCP prepare.
|
|
1605
|
+
*
|
|
1606
|
+
* @internal
|
|
1607
|
+
*/
|
|
1608
|
+
private ensureDepositProfileForPrepare;
|
|
1609
|
+
/**
|
|
1610
|
+
* Prepare a deposit: persist first-deposit profile when needed and return
|
|
1611
|
+
* ERC-20 transfer calldata for the user to sign (does not broadcast).
|
|
1590
1612
|
*
|
|
1591
1613
|
* @group Deposits and withdrawals
|
|
1592
1614
|
*/
|
|
1593
|
-
|
|
1615
|
+
prepareDeposit(params: {
|
|
1594
1616
|
userAddress: string;
|
|
1595
1617
|
chainId: SupportedChainId;
|
|
1596
1618
|
amount: string;
|
|
1597
1619
|
asset: SupportedAsset;
|
|
1598
|
-
strategy?: Strategy;
|
|
1599
1620
|
}): Promise<{
|
|
1600
1621
|
phase: "prepare_transfer";
|
|
1601
1622
|
setup: {
|
|
@@ -2290,43 +2311,51 @@ declare class ZyfaiSDK {
|
|
|
2290
2311
|
* ```
|
|
2291
2312
|
*/
|
|
2292
2313
|
/**
|
|
2293
|
-
* Get
|
|
2314
|
+
* Get persisted per-asset-type management settings (strategy, chains, protocols).
|
|
2294
2315
|
*
|
|
2295
2316
|
* @group Agent management
|
|
2296
2317
|
*/
|
|
2297
|
-
|
|
2298
|
-
|
|
2318
|
+
getAssetTypeSettings(): Promise<unknown>;
|
|
2319
|
+
/**
|
|
2320
|
+
* Reserve a one-time action id before the user signs an ERC-20 transfer.
|
|
2321
|
+
*
|
|
2322
|
+
* @group Agent management
|
|
2323
|
+
*/
|
|
2324
|
+
createAgentDepositIntent(request: CreateAgentDepositIntentRequest): Promise<{
|
|
2325
|
+
data: AgentDepositIntent;
|
|
2299
2326
|
}>;
|
|
2300
2327
|
/**
|
|
2301
|
-
*
|
|
2328
|
+
* Consume a one-time action id when registering the signed deposit.
|
|
2302
2329
|
*
|
|
2303
2330
|
* @group Agent management
|
|
2304
2331
|
*/
|
|
2305
|
-
|
|
2306
|
-
data:
|
|
2332
|
+
consumeAgentDepositIntent(actionId: string, request: ConsumeAgentDepositIntentRequest): Promise<{
|
|
2333
|
+
data: AgentDepositIntentStatus;
|
|
2307
2334
|
}>;
|
|
2308
2335
|
/**
|
|
2309
|
-
*
|
|
2336
|
+
* Poll MCP deposit-intent status (agent delegated session).
|
|
2310
2337
|
*
|
|
2311
2338
|
* @group Agent management
|
|
2312
2339
|
*/
|
|
2313
|
-
|
|
2314
|
-
|
|
2340
|
+
getAgentDepositIntentStatus(actionId: string): Promise<{
|
|
2341
|
+
data: AgentDepositIntentStatus;
|
|
2315
2342
|
}>;
|
|
2316
2343
|
/**
|
|
2317
|
-
*
|
|
2344
|
+
* Mark intent complete after the user signed on zyf.ai (SIWE session).
|
|
2318
2345
|
*
|
|
2319
2346
|
* @group Agent management
|
|
2320
2347
|
*/
|
|
2321
|
-
|
|
2322
|
-
data:
|
|
2348
|
+
completeAgentDepositIntent(actionId: string, request: CompleteAgentDepositIntentRequest): Promise<{
|
|
2349
|
+
data: AgentDepositIntentStatus;
|
|
2323
2350
|
}>;
|
|
2324
2351
|
/**
|
|
2325
|
-
*
|
|
2352
|
+
* Resolve a signing ticket from prepare_deposit (no user auth).
|
|
2326
2353
|
*
|
|
2327
2354
|
* @group Agent management
|
|
2328
2355
|
*/
|
|
2329
|
-
|
|
2356
|
+
resolveAgentDepositIntentTicket(ticket: string): Promise<{
|
|
2357
|
+
data: ResolvedAgentDepositIntent;
|
|
2358
|
+
}>;
|
|
2330
2359
|
customizeBatch(customizations: CustomizationConfig[]): Promise<CustomizeBatchResponse>;
|
|
2331
2360
|
/**
|
|
2332
2361
|
* Get available pools for a protocol.
|
|
@@ -2710,4 +2739,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
2710
2739
|
*/
|
|
2711
2740
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
2712
2741
|
|
|
2713
|
-
export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -44,47 +44,46 @@ interface SDKConfig {
|
|
|
44
44
|
/** @internal Override client-side minimum portfolio checks (local integration). */
|
|
45
45
|
bypassMinPortfolio?: boolean;
|
|
46
46
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
* Skips SIWE `connectAccount` when the Zyfai access token is already known.
|
|
50
|
-
*/
|
|
51
|
-
/** Agent autonomy limits for MCP / delegated management. */
|
|
52
|
-
interface AgentMandate {
|
|
53
|
-
id: string;
|
|
54
|
-
oauthClientId: string;
|
|
55
|
-
/** Maximum USD of one deposit. Not total capital under management. */
|
|
56
|
-
maxDepositUsd?: string | null;
|
|
57
|
-
allowedChainIds: number[];
|
|
58
|
-
allowedAssets: string[];
|
|
59
|
-
allowRebalance: boolean;
|
|
60
|
-
allowWithdraw: boolean;
|
|
61
|
-
expiresAt?: string | null;
|
|
62
|
-
}
|
|
63
|
-
interface UpsertAgentMandateRequest {
|
|
64
|
-
oauthClientId: string;
|
|
65
|
-
/** Maximum USD of one deposit. Not total capital under management. */
|
|
66
|
-
maxDepositUsd?: string | null;
|
|
67
|
-
allowedChainIds?: number[];
|
|
68
|
-
allowedAssets?: string[];
|
|
69
|
-
allowRebalance?: boolean;
|
|
70
|
-
allowWithdraw?: boolean;
|
|
71
|
-
expiresAt?: string | null;
|
|
72
|
-
}
|
|
73
|
-
/** One-time prepare → enter binding for MCP deposit flows (least-unit amount). */
|
|
74
|
-
interface CreateAgentEnterIntentRequest {
|
|
47
|
+
/** One-time prepare → deposit binding for MCP flows (least-unit amount). */
|
|
48
|
+
interface CreateAgentDepositIntentRequest {
|
|
75
49
|
chainId: number;
|
|
76
50
|
amount: string;
|
|
77
51
|
asset: SupportedAsset;
|
|
78
|
-
strategy?: Strategy;
|
|
79
52
|
}
|
|
80
|
-
interface
|
|
53
|
+
interface AgentDepositIntent {
|
|
81
54
|
actionId: string;
|
|
82
55
|
expiresAt: string;
|
|
56
|
+
signingTicket: string;
|
|
57
|
+
}
|
|
58
|
+
type AgentDepositIntentStatusValue = "pending" | "completed" | "expired";
|
|
59
|
+
interface AgentDepositIntentStatus {
|
|
60
|
+
status: AgentDepositIntentStatusValue;
|
|
61
|
+
actionId?: string;
|
|
62
|
+
depositId?: string;
|
|
63
|
+
txHash?: string;
|
|
64
|
+
chainId?: number;
|
|
65
|
+
asset?: string;
|
|
66
|
+
amount?: string;
|
|
83
67
|
}
|
|
84
|
-
interface
|
|
68
|
+
interface ResolvedAgentDepositIntent {
|
|
69
|
+
actionId: string;
|
|
70
|
+
chainId: number;
|
|
71
|
+
asset: string;
|
|
72
|
+
amount: string;
|
|
73
|
+
status: AgentDepositIntentStatusValue;
|
|
74
|
+
ownerAddress: string;
|
|
75
|
+
expiresAt: string;
|
|
76
|
+
}
|
|
77
|
+
interface ConsumeAgentDepositIntentRequest {
|
|
85
78
|
chainId: number;
|
|
86
79
|
amount: string;
|
|
87
80
|
asset: SupportedAsset;
|
|
81
|
+
txHash: string;
|
|
82
|
+
depositId: string;
|
|
83
|
+
}
|
|
84
|
+
interface CompleteAgentDepositIntentRequest {
|
|
85
|
+
txHash: string;
|
|
86
|
+
depositId: string;
|
|
88
87
|
}
|
|
89
88
|
interface UserSessionAuth {
|
|
90
89
|
/** Zyfai execution API JWT from SIWE login. */
|
|
@@ -93,6 +92,8 @@ interface UserSessionAuth {
|
|
|
93
92
|
userId?: string;
|
|
94
93
|
/** User EOA address (checksum) for address binding checks. */
|
|
95
94
|
eoa?: Address;
|
|
95
|
+
/** Delegated MCP agent JWT (`channel=agent` on the execution API). */
|
|
96
|
+
channel?: "agent";
|
|
96
97
|
}
|
|
97
98
|
interface DeploySafeResponse {
|
|
98
99
|
success: boolean;
|
|
@@ -1005,6 +1006,8 @@ declare class ZyfaiSDK {
|
|
|
1005
1006
|
private authenticatedUserId;
|
|
1006
1007
|
private hasActiveSessionKey;
|
|
1007
1008
|
private isPredeployed;
|
|
1009
|
+
/** False until SIWE login or GET /users/me has set `isPredeployed`. */
|
|
1010
|
+
private predeployedResolved;
|
|
1008
1011
|
private connectedSmartWallet;
|
|
1009
1012
|
private currentProvider;
|
|
1010
1013
|
private currentChainId;
|
|
@@ -1012,6 +1015,8 @@ declare class ZyfaiSDK {
|
|
|
1012
1015
|
private referralSource?;
|
|
1013
1016
|
/** EOA of the active user session (bearer or SIWE). Cleared on disconnect. */
|
|
1014
1017
|
private sessionEoa;
|
|
1018
|
+
/** When set, profile writes use agent-accessible endpoints instead of PATCH /users/me. */
|
|
1019
|
+
private sessionChannel?;
|
|
1015
1020
|
/**
|
|
1016
1021
|
* Create an SDK instance with an existing Zyfai user JWT (no wallet connected).
|
|
1017
1022
|
*
|
|
@@ -1297,10 +1302,16 @@ declare class ZyfaiSDK {
|
|
|
1297
1302
|
*/
|
|
1298
1303
|
private getWalletClient;
|
|
1299
1304
|
/**
|
|
1300
|
-
* True when userAddress is the
|
|
1305
|
+
* True when userAddress is the signer, wallet client, or agent session EOA.
|
|
1301
1306
|
* @private
|
|
1302
1307
|
*/
|
|
1303
1308
|
private isConnectedUser;
|
|
1309
|
+
/**
|
|
1310
|
+
* SIWE login sets predeployed. Agent sessions (`forUser`) do not, so read it
|
|
1311
|
+
* from the user record before allowing a transfer to an undeployed pool Safe.
|
|
1312
|
+
* @private
|
|
1313
|
+
*/
|
|
1314
|
+
private hydrateSessionWallet;
|
|
1304
1315
|
/**
|
|
1305
1316
|
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
1306
1317
|
* user, registered agent for everyone else. If none, CREATE2-derive when
|
|
@@ -1406,6 +1417,11 @@ declare class ZyfaiSDK {
|
|
|
1406
1417
|
* @internal
|
|
1407
1418
|
*/
|
|
1408
1419
|
private updateUserProtocolsForAsset;
|
|
1420
|
+
/**
|
|
1421
|
+
* Persist protocol discovery for one asset (user PATCH or agent deposit-setup).
|
|
1422
|
+
* @internal
|
|
1423
|
+
*/
|
|
1424
|
+
private persistDiscoveredAssetProfile;
|
|
1409
1425
|
/**
|
|
1410
1426
|
* Switch one asset to a strategy and select the protocols that go with it.
|
|
1411
1427
|
*
|
|
@@ -1585,17 +1601,22 @@ declare class ZyfaiSDK {
|
|
|
1585
1601
|
applied: boolean;
|
|
1586
1602
|
}>;
|
|
1587
1603
|
/**
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1604
|
+
* Idempotently configure the deposit asset for a single chain before MCP prepare.
|
|
1605
|
+
*
|
|
1606
|
+
* @internal
|
|
1607
|
+
*/
|
|
1608
|
+
private ensureDepositProfileForPrepare;
|
|
1609
|
+
/**
|
|
1610
|
+
* Prepare a deposit: persist first-deposit profile when needed and return
|
|
1611
|
+
* ERC-20 transfer calldata for the user to sign (does not broadcast).
|
|
1590
1612
|
*
|
|
1591
1613
|
* @group Deposits and withdrawals
|
|
1592
1614
|
*/
|
|
1593
|
-
|
|
1615
|
+
prepareDeposit(params: {
|
|
1594
1616
|
userAddress: string;
|
|
1595
1617
|
chainId: SupportedChainId;
|
|
1596
1618
|
amount: string;
|
|
1597
1619
|
asset: SupportedAsset;
|
|
1598
|
-
strategy?: Strategy;
|
|
1599
1620
|
}): Promise<{
|
|
1600
1621
|
phase: "prepare_transfer";
|
|
1601
1622
|
setup: {
|
|
@@ -2290,43 +2311,51 @@ declare class ZyfaiSDK {
|
|
|
2290
2311
|
* ```
|
|
2291
2312
|
*/
|
|
2292
2313
|
/**
|
|
2293
|
-
* Get
|
|
2314
|
+
* Get persisted per-asset-type management settings (strategy, chains, protocols).
|
|
2294
2315
|
*
|
|
2295
2316
|
* @group Agent management
|
|
2296
2317
|
*/
|
|
2297
|
-
|
|
2298
|
-
|
|
2318
|
+
getAssetTypeSettings(): Promise<unknown>;
|
|
2319
|
+
/**
|
|
2320
|
+
* Reserve a one-time action id before the user signs an ERC-20 transfer.
|
|
2321
|
+
*
|
|
2322
|
+
* @group Agent management
|
|
2323
|
+
*/
|
|
2324
|
+
createAgentDepositIntent(request: CreateAgentDepositIntentRequest): Promise<{
|
|
2325
|
+
data: AgentDepositIntent;
|
|
2299
2326
|
}>;
|
|
2300
2327
|
/**
|
|
2301
|
-
*
|
|
2328
|
+
* Consume a one-time action id when registering the signed deposit.
|
|
2302
2329
|
*
|
|
2303
2330
|
* @group Agent management
|
|
2304
2331
|
*/
|
|
2305
|
-
|
|
2306
|
-
data:
|
|
2332
|
+
consumeAgentDepositIntent(actionId: string, request: ConsumeAgentDepositIntentRequest): Promise<{
|
|
2333
|
+
data: AgentDepositIntentStatus;
|
|
2307
2334
|
}>;
|
|
2308
2335
|
/**
|
|
2309
|
-
*
|
|
2336
|
+
* Poll MCP deposit-intent status (agent delegated session).
|
|
2310
2337
|
*
|
|
2311
2338
|
* @group Agent management
|
|
2312
2339
|
*/
|
|
2313
|
-
|
|
2314
|
-
|
|
2340
|
+
getAgentDepositIntentStatus(actionId: string): Promise<{
|
|
2341
|
+
data: AgentDepositIntentStatus;
|
|
2315
2342
|
}>;
|
|
2316
2343
|
/**
|
|
2317
|
-
*
|
|
2344
|
+
* Mark intent complete after the user signed on zyf.ai (SIWE session).
|
|
2318
2345
|
*
|
|
2319
2346
|
* @group Agent management
|
|
2320
2347
|
*/
|
|
2321
|
-
|
|
2322
|
-
data:
|
|
2348
|
+
completeAgentDepositIntent(actionId: string, request: CompleteAgentDepositIntentRequest): Promise<{
|
|
2349
|
+
data: AgentDepositIntentStatus;
|
|
2323
2350
|
}>;
|
|
2324
2351
|
/**
|
|
2325
|
-
*
|
|
2352
|
+
* Resolve a signing ticket from prepare_deposit (no user auth).
|
|
2326
2353
|
*
|
|
2327
2354
|
* @group Agent management
|
|
2328
2355
|
*/
|
|
2329
|
-
|
|
2356
|
+
resolveAgentDepositIntentTicket(ticket: string): Promise<{
|
|
2357
|
+
data: ResolvedAgentDepositIntent;
|
|
2358
|
+
}>;
|
|
2330
2359
|
customizeBatch(customizations: CustomizationConfig[]): Promise<CustomizeBatchResponse>;
|
|
2331
2360
|
/**
|
|
2332
2361
|
* Get available pools for a protocol.
|
|
@@ -2710,4 +2739,4 @@ declare const ERC7579_LAUNCHPAD_ADDRESS: Address$1;
|
|
|
2710
2739
|
*/
|
|
2711
2740
|
declare const POOL_MODULE_ADDRESSES: readonly Address$1[];
|
|
2712
2741
|
|
|
2713
|
-
export { ALLOWED_HISTORY_DAYS, API_ENDPOINT, type APYPerStrategy, type APYPerStrategyResponse, type ActionData, type ActiveWallet, type ActiveWalletsResponse, type AddWalletToSdkResponse, type Address, type
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -112,9 +112,13 @@ var ENDPOINTS = {
|
|
|
112
112
|
AUTH_CHALLENGE: "/auth/challenge",
|
|
113
113
|
// User
|
|
114
114
|
USER_ME: "/users/me",
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
USER_ASSET_TYPE_SETTINGS: "/users/asset-type-settings",
|
|
116
|
+
AGENT_DEPOSIT_SETUP: "/users/me/agent-deposit-setup",
|
|
117
|
+
USER_AGENT_DEPOSIT_INTENTS: "/users/me/agent-deposit-intents",
|
|
118
|
+
USER_AGENT_DEPOSIT_INTENT: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}`,
|
|
119
|
+
USER_AGENT_DEPOSIT_INTENT_CONSUME: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}/consume`,
|
|
120
|
+
USER_AGENT_DEPOSIT_INTENT_COMPLETE: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}/complete`,
|
|
121
|
+
AGENT_DEPOSIT_INTENT_RESOLVE: "/agent-deposit-intents/resolve",
|
|
118
122
|
USER_WITHDRAW: "/users/withdraw",
|
|
119
123
|
PARTIAL_WITHDRAW: "/users/partial-withdraw",
|
|
120
124
|
LOG_DEPOSIT: "/users/log_deposit/v2",
|
|
@@ -644,22 +648,22 @@ var MIN_PORTFOLIO_BALANCE = {
|
|
|
644
648
|
// 10,000 EURC (6 decimals)
|
|
645
649
|
},
|
|
646
650
|
8453: {
|
|
647
|
-
USDC:
|
|
648
|
-
//
|
|
649
|
-
EURC:
|
|
650
|
-
//
|
|
651
|
+
USDC: 10n * 10n ** 6n,
|
|
652
|
+
// 10 USDC (6 decimals)
|
|
653
|
+
EURC: 10n * 10n ** 6n
|
|
654
|
+
// 10 EURC (6 decimals)
|
|
651
655
|
},
|
|
652
656
|
42161: {
|
|
653
|
-
USDC:
|
|
654
|
-
//
|
|
655
|
-
EURC:
|
|
656
|
-
//
|
|
657
|
+
USDC: 10n * 10n ** 6n,
|
|
658
|
+
// 10 USDC (6 decimals)
|
|
659
|
+
EURC: 10n * 10n ** 6n
|
|
660
|
+
// 10 EURC (6 decimals)
|
|
657
661
|
}
|
|
658
662
|
};
|
|
659
663
|
var MIN_PORTFOLIO_USD = {
|
|
660
664
|
1: { WETH: 10000n },
|
|
661
|
-
8453: { WETH:
|
|
662
|
-
42161: { WETH:
|
|
665
|
+
8453: { WETH: 10n, NVDAc: 10n },
|
|
666
|
+
42161: { WETH: 10n }
|
|
663
667
|
};
|
|
664
668
|
var DEPOSIT_CREDIT_INTERVAL_MS = {
|
|
665
669
|
1: 2e3,
|
|
@@ -1684,6 +1688,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1684
1688
|
this.authenticatedUserId = null;
|
|
1685
1689
|
this.hasActiveSessionKey = false;
|
|
1686
1690
|
this.isPredeployed = false;
|
|
1691
|
+
/** False until SIWE login or GET /users/me has set `isPredeployed`. */
|
|
1692
|
+
this.predeployedResolved = false;
|
|
1687
1693
|
this.connectedSmartWallet = null;
|
|
1688
1694
|
this.currentProvider = null;
|
|
1689
1695
|
this.currentChainId = null;
|
|
@@ -1736,6 +1742,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1736
1742
|
this.httpClient.setAuthToken(session.accessToken);
|
|
1737
1743
|
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
1738
1744
|
this.sessionEoa = session.eoa ? (0, import_viem4.getAddress)(session.eoa) : null;
|
|
1745
|
+
this.sessionChannel = session.channel;
|
|
1746
|
+
this.isPredeployed = false;
|
|
1747
|
+
this.predeployedResolved = false;
|
|
1748
|
+
this.connectedSmartWallet = null;
|
|
1739
1749
|
}
|
|
1740
1750
|
/**
|
|
1741
1751
|
* @internal Attach headers to execution API requests (MCP server agent channel).
|
|
@@ -1778,8 +1788,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1778
1788
|
this.authenticatedUserId = loginResponse.userId || null;
|
|
1779
1789
|
this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
|
|
1780
1790
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
1791
|
+
this.predeployedResolved = true;
|
|
1781
1792
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
1782
1793
|
this.sessionEoa = (0, import_viem4.getAddress)(params.message.address);
|
|
1794
|
+
this.sessionChannel = void 0;
|
|
1783
1795
|
return loginResponse;
|
|
1784
1796
|
}
|
|
1785
1797
|
/**
|
|
@@ -1858,6 +1870,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1858
1870
|
this.authenticatedUserId = loginResponse.userId || null;
|
|
1859
1871
|
this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
|
|
1860
1872
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
1873
|
+
this.predeployedResolved = true;
|
|
1861
1874
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
1862
1875
|
this.sessionEoa = userAddress;
|
|
1863
1876
|
} catch (error) {
|
|
@@ -2231,9 +2244,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2231
2244
|
}
|
|
2232
2245
|
this.authenticatedUserId = null;
|
|
2233
2246
|
this.isPredeployed = false;
|
|
2247
|
+
this.predeployedResolved = false;
|
|
2234
2248
|
this.connectedSmartWallet = null;
|
|
2235
2249
|
this.currentChainId = null;
|
|
2236
2250
|
this.sessionEoa = null;
|
|
2251
|
+
this.sessionChannel = void 0;
|
|
2237
2252
|
this.httpClient.clearAuthToken();
|
|
2238
2253
|
if (this.currentProvider?.removeAllListeners) {
|
|
2239
2254
|
try {
|
|
@@ -2327,8 +2342,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2327
2342
|
this.authenticatedUserId = null;
|
|
2328
2343
|
this.hasActiveSessionKey = false;
|
|
2329
2344
|
this.isPredeployed = false;
|
|
2345
|
+
this.predeployedResolved = false;
|
|
2330
2346
|
this.connectedSmartWallet = null;
|
|
2331
2347
|
this.sessionEoa = null;
|
|
2348
|
+
this.sessionChannel = void 0;
|
|
2332
2349
|
this.httpClient.clearAuthToken();
|
|
2333
2350
|
}
|
|
2334
2351
|
/**
|
|
@@ -2355,13 +2372,25 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2355
2372
|
}
|
|
2356
2373
|
}
|
|
2357
2374
|
/**
|
|
2358
|
-
* True when userAddress is the
|
|
2375
|
+
* True when userAddress is the signer, wallet client, or agent session EOA.
|
|
2359
2376
|
* @private
|
|
2360
2377
|
*/
|
|
2361
2378
|
isConnectedUser(userAddress) {
|
|
2362
|
-
const connected = this.signer?.address ?? this.walletClient?.account?.address;
|
|
2379
|
+
const connected = this.signer?.address ?? this.walletClient?.account?.address ?? this.sessionEoa;
|
|
2363
2380
|
return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
|
|
2364
2381
|
}
|
|
2382
|
+
/**
|
|
2383
|
+
* SIWE login sets predeployed. Agent sessions (`forUser`) do not, so read it
|
|
2384
|
+
* from the user record before allowing a transfer to an undeployed pool Safe.
|
|
2385
|
+
* @private
|
|
2386
|
+
*/
|
|
2387
|
+
async hydrateSessionWallet() {
|
|
2388
|
+
if (this.predeployedResolved || !this.sessionEoa) return;
|
|
2389
|
+
const me = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
2390
|
+
this.isPredeployed = !!me?.predeployed;
|
|
2391
|
+
this.connectedSmartWallet = me?.smartWallet || null;
|
|
2392
|
+
this.predeployedResolved = true;
|
|
2393
|
+
}
|
|
2365
2394
|
/**
|
|
2366
2395
|
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
2367
2396
|
* user, registered agent for everyone else. If none, CREATE2-derive when
|
|
@@ -2816,6 +2845,43 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2816
2845
|
asset,
|
|
2817
2846
|
internalStrategy
|
|
2818
2847
|
);
|
|
2848
|
+
const mandateChainId = chains.find((c) => !existingChains.includes(c)) ?? chains[0];
|
|
2849
|
+
return await this.persistDiscoveredAssetProfile(
|
|
2850
|
+
asset,
|
|
2851
|
+
effectiveChains,
|
|
2852
|
+
withPools,
|
|
2853
|
+
strategy,
|
|
2854
|
+
mandateChainId
|
|
2855
|
+
);
|
|
2856
|
+
}
|
|
2857
|
+
/**
|
|
2858
|
+
* Persist protocol discovery for one asset (user PATCH or agent deposit-setup).
|
|
2859
|
+
* @internal
|
|
2860
|
+
*/
|
|
2861
|
+
async persistDiscoveredAssetProfile(asset, effectiveChains, withPools, strategy, agentDepositChainId) {
|
|
2862
|
+
const internalAsset = convertAssetInternally(asset);
|
|
2863
|
+
const assetSettings = {
|
|
2864
|
+
chains: effectiveChains,
|
|
2865
|
+
protocols: withPools
|
|
2866
|
+
};
|
|
2867
|
+
if (strategy !== void 0) {
|
|
2868
|
+
assetSettings.rebalanceStrategy = toInternalStrategy(strategy);
|
|
2869
|
+
}
|
|
2870
|
+
if (this.sessionChannel === "agent") {
|
|
2871
|
+
const chainId = agentDepositChainId ?? effectiveChains[effectiveChains.length - 1] ?? effectiveChains[0];
|
|
2872
|
+
await this.httpClient.post(
|
|
2873
|
+
ENDPOINTS.AGENT_DEPOSIT_SETUP,
|
|
2874
|
+
{
|
|
2875
|
+
asset,
|
|
2876
|
+
chainId,
|
|
2877
|
+
strategy,
|
|
2878
|
+
assetTypeSettings: {
|
|
2879
|
+
[internalAsset]: assetSettings
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
);
|
|
2883
|
+
return await this.getUserDetails(asset);
|
|
2884
|
+
}
|
|
2819
2885
|
return await this.updateUserProfile({
|
|
2820
2886
|
asset,
|
|
2821
2887
|
protocols: withPools,
|
|
@@ -3062,6 +3128,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3062
3128
|
} else {
|
|
3063
3129
|
await this.authenticateUser();
|
|
3064
3130
|
}
|
|
3131
|
+
await this.hydrateSessionWallet();
|
|
3065
3132
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
3066
3133
|
if (!safeAddress) {
|
|
3067
3134
|
throw new Error("Smart wallet address is not available");
|
|
@@ -3188,6 +3255,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3188
3255
|
)}.`
|
|
3189
3256
|
);
|
|
3190
3257
|
}
|
|
3258
|
+
await this.hydrateSessionWallet();
|
|
3191
3259
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
3192
3260
|
if (!safeAddress) {
|
|
3193
3261
|
throw new Error("Smart wallet address is not available");
|
|
@@ -3305,17 +3373,54 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3305
3373
|
return { applied: true };
|
|
3306
3374
|
}
|
|
3307
3375
|
/**
|
|
3308
|
-
*
|
|
3309
|
-
*
|
|
3376
|
+
* Idempotently configure the deposit asset for a single chain before MCP prepare.
|
|
3377
|
+
*
|
|
3378
|
+
* @internal
|
|
3379
|
+
*/
|
|
3380
|
+
async ensureDepositProfileForPrepare(params) {
|
|
3381
|
+
const { strategy, asset, chainId } = params;
|
|
3382
|
+
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
3383
|
+
throw new Error(
|
|
3384
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
3385
|
+
);
|
|
3386
|
+
}
|
|
3387
|
+
await this.authenticateUser();
|
|
3388
|
+
const details = await this.getUserDetails(asset);
|
|
3389
|
+
if (details.chains?.includes(chainId)) {
|
|
3390
|
+
return { applied: false };
|
|
3391
|
+
}
|
|
3392
|
+
const allProtocols = await this.httpClient.get(
|
|
3393
|
+
ENDPOINTS.PROTOCOLS()
|
|
3394
|
+
);
|
|
3395
|
+
await this.updateUserProtocolsForAsset(
|
|
3396
|
+
asset,
|
|
3397
|
+
[chainId],
|
|
3398
|
+
strategy,
|
|
3399
|
+
allProtocols
|
|
3400
|
+
);
|
|
3401
|
+
const afterSetup = await this.getUserDetails(asset);
|
|
3402
|
+
if (!afterSetup.chains?.includes(chainId)) {
|
|
3403
|
+
throw new Error(
|
|
3404
|
+
`First-deposit setup did not persist ${asset} chain ${chainId} configuration.`
|
|
3405
|
+
);
|
|
3406
|
+
}
|
|
3407
|
+
return { applied: true };
|
|
3408
|
+
}
|
|
3409
|
+
/**
|
|
3410
|
+
* Prepare a deposit: persist first-deposit profile when needed and return
|
|
3411
|
+
* ERC-20 transfer calldata for the user to sign (does not broadcast).
|
|
3310
3412
|
*
|
|
3311
3413
|
* @group Deposits and withdrawals
|
|
3312
3414
|
*/
|
|
3313
|
-
async
|
|
3314
|
-
const { userAddress, chainId, amount, asset
|
|
3415
|
+
async prepareDeposit(params) {
|
|
3416
|
+
const { userAddress, chainId, amount, asset } = params;
|
|
3315
3417
|
if (this.sessionEoa && (0, import_viem4.getAddress)(userAddress) !== this.sessionEoa) {
|
|
3316
3418
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
3317
3419
|
}
|
|
3318
|
-
const setup = await this.
|
|
3420
|
+
const setup = await this.ensureDepositProfileForPrepare({
|
|
3421
|
+
asset,
|
|
3422
|
+
chainId
|
|
3423
|
+
});
|
|
3319
3424
|
const transfer = await this.buildDepositTransfer({
|
|
3320
3425
|
userAddress,
|
|
3321
3426
|
chainId,
|
|
@@ -4834,62 +4939,70 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4834
4939
|
* ```
|
|
4835
4940
|
*/
|
|
4836
4941
|
/**
|
|
4837
|
-
* Get
|
|
4942
|
+
* Get persisted per-asset-type management settings (strategy, chains, protocols).
|
|
4838
4943
|
*
|
|
4839
4944
|
* @group Agent management
|
|
4840
4945
|
*/
|
|
4841
|
-
async
|
|
4946
|
+
async getAssetTypeSettings() {
|
|
4842
4947
|
await this.authenticateUser();
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4948
|
+
return this.httpClient.get(ENDPOINTS.USER_ASSET_TYPE_SETTINGS);
|
|
4949
|
+
}
|
|
4950
|
+
/**
|
|
4951
|
+
* Reserve a one-time action id before the user signs an ERC-20 transfer.
|
|
4952
|
+
*
|
|
4953
|
+
* @group Agent management
|
|
4954
|
+
*/
|
|
4955
|
+
async createAgentDepositIntent(request) {
|
|
4956
|
+
await this.authenticateUser();
|
|
4957
|
+
return this.httpClient.post(
|
|
4958
|
+
ENDPOINTS.USER_AGENT_DEPOSIT_INTENTS,
|
|
4959
|
+
request
|
|
4846
4960
|
);
|
|
4847
4961
|
}
|
|
4848
4962
|
/**
|
|
4849
|
-
*
|
|
4963
|
+
* Consume a one-time action id when registering the signed deposit.
|
|
4850
4964
|
*
|
|
4851
4965
|
* @group Agent management
|
|
4852
4966
|
*/
|
|
4853
|
-
async
|
|
4967
|
+
async consumeAgentDepositIntent(actionId, request) {
|
|
4854
4968
|
await this.authenticateUser();
|
|
4855
|
-
return this.httpClient.
|
|
4856
|
-
ENDPOINTS.
|
|
4969
|
+
return this.httpClient.post(
|
|
4970
|
+
ENDPOINTS.USER_AGENT_DEPOSIT_INTENT_CONSUME(actionId),
|
|
4857
4971
|
request
|
|
4858
4972
|
);
|
|
4859
4973
|
}
|
|
4860
4974
|
/**
|
|
4861
|
-
*
|
|
4975
|
+
* Poll MCP deposit-intent status (agent delegated session).
|
|
4862
4976
|
*
|
|
4863
4977
|
* @group Agent management
|
|
4864
4978
|
*/
|
|
4865
|
-
async
|
|
4979
|
+
async getAgentDepositIntentStatus(actionId) {
|
|
4866
4980
|
await this.authenticateUser();
|
|
4867
|
-
return this.httpClient.
|
|
4868
|
-
|
|
4981
|
+
return this.httpClient.get(
|
|
4982
|
+
ENDPOINTS.USER_AGENT_DEPOSIT_INTENT(actionId)
|
|
4869
4983
|
);
|
|
4870
4984
|
}
|
|
4871
4985
|
/**
|
|
4872
|
-
*
|
|
4986
|
+
* Mark intent complete after the user signed on zyf.ai (SIWE session).
|
|
4873
4987
|
*
|
|
4874
4988
|
* @group Agent management
|
|
4875
4989
|
*/
|
|
4876
|
-
async
|
|
4990
|
+
async completeAgentDepositIntent(actionId, request) {
|
|
4877
4991
|
await this.authenticateUser();
|
|
4878
4992
|
return this.httpClient.post(
|
|
4879
|
-
ENDPOINTS.
|
|
4993
|
+
ENDPOINTS.USER_AGENT_DEPOSIT_INTENT_COMPLETE(actionId),
|
|
4880
4994
|
request
|
|
4881
4995
|
);
|
|
4882
4996
|
}
|
|
4883
4997
|
/**
|
|
4884
|
-
*
|
|
4998
|
+
* Resolve a signing ticket from prepare_deposit (no user auth).
|
|
4885
4999
|
*
|
|
4886
5000
|
* @group Agent management
|
|
4887
5001
|
*/
|
|
4888
|
-
async
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
ENDPOINTS.
|
|
4892
|
-
request
|
|
5002
|
+
async resolveAgentDepositIntentTicket(ticket) {
|
|
5003
|
+
const query = `?ticket=${encodeURIComponent(ticket)}`;
|
|
5004
|
+
return this.httpClient.get(
|
|
5005
|
+
`${ENDPOINTS.AGENT_DEPOSIT_INTENT_RESOLVE}${query}`
|
|
4893
5006
|
);
|
|
4894
5007
|
}
|
|
4895
5008
|
async customizeBatch(customizations) {
|
package/dist/index.mjs
CHANGED
|
@@ -44,9 +44,13 @@ var ENDPOINTS = {
|
|
|
44
44
|
AUTH_CHALLENGE: "/auth/challenge",
|
|
45
45
|
// User
|
|
46
46
|
USER_ME: "/users/me",
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
USER_ASSET_TYPE_SETTINGS: "/users/asset-type-settings",
|
|
48
|
+
AGENT_DEPOSIT_SETUP: "/users/me/agent-deposit-setup",
|
|
49
|
+
USER_AGENT_DEPOSIT_INTENTS: "/users/me/agent-deposit-intents",
|
|
50
|
+
USER_AGENT_DEPOSIT_INTENT: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}`,
|
|
51
|
+
USER_AGENT_DEPOSIT_INTENT_CONSUME: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}/consume`,
|
|
52
|
+
USER_AGENT_DEPOSIT_INTENT_COMPLETE: (actionId) => `/users/me/agent-deposit-intents/${encodeURIComponent(actionId)}/complete`,
|
|
53
|
+
AGENT_DEPOSIT_INTENT_RESOLVE: "/agent-deposit-intents/resolve",
|
|
50
54
|
USER_WITHDRAW: "/users/withdraw",
|
|
51
55
|
PARTIAL_WITHDRAW: "/users/partial-withdraw",
|
|
52
56
|
LOG_DEPOSIT: "/users/log_deposit/v2",
|
|
@@ -576,22 +580,22 @@ var MIN_PORTFOLIO_BALANCE = {
|
|
|
576
580
|
// 10,000 EURC (6 decimals)
|
|
577
581
|
},
|
|
578
582
|
8453: {
|
|
579
|
-
USDC:
|
|
580
|
-
//
|
|
581
|
-
EURC:
|
|
582
|
-
//
|
|
583
|
+
USDC: 10n * 10n ** 6n,
|
|
584
|
+
// 10 USDC (6 decimals)
|
|
585
|
+
EURC: 10n * 10n ** 6n
|
|
586
|
+
// 10 EURC (6 decimals)
|
|
583
587
|
},
|
|
584
588
|
42161: {
|
|
585
|
-
USDC:
|
|
586
|
-
//
|
|
587
|
-
EURC:
|
|
588
|
-
//
|
|
589
|
+
USDC: 10n * 10n ** 6n,
|
|
590
|
+
// 10 USDC (6 decimals)
|
|
591
|
+
EURC: 10n * 10n ** 6n
|
|
592
|
+
// 10 EURC (6 decimals)
|
|
589
593
|
}
|
|
590
594
|
};
|
|
591
595
|
var MIN_PORTFOLIO_USD = {
|
|
592
596
|
1: { WETH: 10000n },
|
|
593
|
-
8453: { WETH:
|
|
594
|
-
42161: { WETH:
|
|
597
|
+
8453: { WETH: 10n, NVDAc: 10n },
|
|
598
|
+
42161: { WETH: 10n }
|
|
595
599
|
};
|
|
596
600
|
var DEPOSIT_CREDIT_INTERVAL_MS = {
|
|
597
601
|
1: 2e3,
|
|
@@ -1636,6 +1640,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1636
1640
|
this.authenticatedUserId = null;
|
|
1637
1641
|
this.hasActiveSessionKey = false;
|
|
1638
1642
|
this.isPredeployed = false;
|
|
1643
|
+
/** False until SIWE login or GET /users/me has set `isPredeployed`. */
|
|
1644
|
+
this.predeployedResolved = false;
|
|
1639
1645
|
this.connectedSmartWallet = null;
|
|
1640
1646
|
this.currentProvider = null;
|
|
1641
1647
|
this.currentChainId = null;
|
|
@@ -1688,6 +1694,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1688
1694
|
this.httpClient.setAuthToken(session.accessToken);
|
|
1689
1695
|
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
1690
1696
|
this.sessionEoa = session.eoa ? getAddress2(session.eoa) : null;
|
|
1697
|
+
this.sessionChannel = session.channel;
|
|
1698
|
+
this.isPredeployed = false;
|
|
1699
|
+
this.predeployedResolved = false;
|
|
1700
|
+
this.connectedSmartWallet = null;
|
|
1691
1701
|
}
|
|
1692
1702
|
/**
|
|
1693
1703
|
* @internal Attach headers to execution API requests (MCP server agent channel).
|
|
@@ -1730,8 +1740,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1730
1740
|
this.authenticatedUserId = loginResponse.userId || null;
|
|
1731
1741
|
this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
|
|
1732
1742
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
1743
|
+
this.predeployedResolved = true;
|
|
1733
1744
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
1734
1745
|
this.sessionEoa = getAddress2(params.message.address);
|
|
1746
|
+
this.sessionChannel = void 0;
|
|
1735
1747
|
return loginResponse;
|
|
1736
1748
|
}
|
|
1737
1749
|
/**
|
|
@@ -1810,6 +1822,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1810
1822
|
this.authenticatedUserId = loginResponse.userId || null;
|
|
1811
1823
|
this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
|
|
1812
1824
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
1825
|
+
this.predeployedResolved = true;
|
|
1813
1826
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
1814
1827
|
this.sessionEoa = userAddress;
|
|
1815
1828
|
} catch (error) {
|
|
@@ -2183,9 +2196,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2183
2196
|
}
|
|
2184
2197
|
this.authenticatedUserId = null;
|
|
2185
2198
|
this.isPredeployed = false;
|
|
2199
|
+
this.predeployedResolved = false;
|
|
2186
2200
|
this.connectedSmartWallet = null;
|
|
2187
2201
|
this.currentChainId = null;
|
|
2188
2202
|
this.sessionEoa = null;
|
|
2203
|
+
this.sessionChannel = void 0;
|
|
2189
2204
|
this.httpClient.clearAuthToken();
|
|
2190
2205
|
if (this.currentProvider?.removeAllListeners) {
|
|
2191
2206
|
try {
|
|
@@ -2279,8 +2294,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2279
2294
|
this.authenticatedUserId = null;
|
|
2280
2295
|
this.hasActiveSessionKey = false;
|
|
2281
2296
|
this.isPredeployed = false;
|
|
2297
|
+
this.predeployedResolved = false;
|
|
2282
2298
|
this.connectedSmartWallet = null;
|
|
2283
2299
|
this.sessionEoa = null;
|
|
2300
|
+
this.sessionChannel = void 0;
|
|
2284
2301
|
this.httpClient.clearAuthToken();
|
|
2285
2302
|
}
|
|
2286
2303
|
/**
|
|
@@ -2307,13 +2324,25 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2307
2324
|
}
|
|
2308
2325
|
}
|
|
2309
2326
|
/**
|
|
2310
|
-
* True when userAddress is the
|
|
2327
|
+
* True when userAddress is the signer, wallet client, or agent session EOA.
|
|
2311
2328
|
* @private
|
|
2312
2329
|
*/
|
|
2313
2330
|
isConnectedUser(userAddress) {
|
|
2314
|
-
const connected = this.signer?.address ?? this.walletClient?.account?.address;
|
|
2331
|
+
const connected = this.signer?.address ?? this.walletClient?.account?.address ?? this.sessionEoa;
|
|
2315
2332
|
return !!connected && connected.toLowerCase() === userAddress.toLowerCase();
|
|
2316
2333
|
}
|
|
2334
|
+
/**
|
|
2335
|
+
* SIWE login sets predeployed. Agent sessions (`forUser`) do not, so read it
|
|
2336
|
+
* from the user record before allowing a transfer to an undeployed pool Safe.
|
|
2337
|
+
* @private
|
|
2338
|
+
*/
|
|
2339
|
+
async hydrateSessionWallet() {
|
|
2340
|
+
if (this.predeployedResolved || !this.sessionEoa) return;
|
|
2341
|
+
const me = await this.httpClient.get(ENDPOINTS.USER_ME);
|
|
2342
|
+
this.isPredeployed = !!me?.predeployed;
|
|
2343
|
+
this.connectedSmartWallet = me?.smartWallet || null;
|
|
2344
|
+
this.predeployedResolved = true;
|
|
2345
|
+
}
|
|
2317
2346
|
/**
|
|
2318
2347
|
* Resolve the Safe address: backend-assigned for the connected predeployed
|
|
2319
2348
|
* user, registered agent for everyone else. If none, CREATE2-derive when
|
|
@@ -2768,6 +2797,43 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2768
2797
|
asset,
|
|
2769
2798
|
internalStrategy
|
|
2770
2799
|
);
|
|
2800
|
+
const mandateChainId = chains.find((c) => !existingChains.includes(c)) ?? chains[0];
|
|
2801
|
+
return await this.persistDiscoveredAssetProfile(
|
|
2802
|
+
asset,
|
|
2803
|
+
effectiveChains,
|
|
2804
|
+
withPools,
|
|
2805
|
+
strategy,
|
|
2806
|
+
mandateChainId
|
|
2807
|
+
);
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* Persist protocol discovery for one asset (user PATCH or agent deposit-setup).
|
|
2811
|
+
* @internal
|
|
2812
|
+
*/
|
|
2813
|
+
async persistDiscoveredAssetProfile(asset, effectiveChains, withPools, strategy, agentDepositChainId) {
|
|
2814
|
+
const internalAsset = convertAssetInternally(asset);
|
|
2815
|
+
const assetSettings = {
|
|
2816
|
+
chains: effectiveChains,
|
|
2817
|
+
protocols: withPools
|
|
2818
|
+
};
|
|
2819
|
+
if (strategy !== void 0) {
|
|
2820
|
+
assetSettings.rebalanceStrategy = toInternalStrategy(strategy);
|
|
2821
|
+
}
|
|
2822
|
+
if (this.sessionChannel === "agent") {
|
|
2823
|
+
const chainId = agentDepositChainId ?? effectiveChains[effectiveChains.length - 1] ?? effectiveChains[0];
|
|
2824
|
+
await this.httpClient.post(
|
|
2825
|
+
ENDPOINTS.AGENT_DEPOSIT_SETUP,
|
|
2826
|
+
{
|
|
2827
|
+
asset,
|
|
2828
|
+
chainId,
|
|
2829
|
+
strategy,
|
|
2830
|
+
assetTypeSettings: {
|
|
2831
|
+
[internalAsset]: assetSettings
|
|
2832
|
+
}
|
|
2833
|
+
}
|
|
2834
|
+
);
|
|
2835
|
+
return await this.getUserDetails(asset);
|
|
2836
|
+
}
|
|
2771
2837
|
return await this.updateUserProfile({
|
|
2772
2838
|
asset,
|
|
2773
2839
|
protocols: withPools,
|
|
@@ -3014,6 +3080,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3014
3080
|
} else {
|
|
3015
3081
|
await this.authenticateUser();
|
|
3016
3082
|
}
|
|
3083
|
+
await this.hydrateSessionWallet();
|
|
3017
3084
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
3018
3085
|
if (!safeAddress) {
|
|
3019
3086
|
throw new Error("Smart wallet address is not available");
|
|
@@ -3140,6 +3207,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3140
3207
|
)}.`
|
|
3141
3208
|
);
|
|
3142
3209
|
}
|
|
3210
|
+
await this.hydrateSessionWallet();
|
|
3143
3211
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
3144
3212
|
if (!safeAddress) {
|
|
3145
3213
|
throw new Error("Smart wallet address is not available");
|
|
@@ -3257,17 +3325,54 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3257
3325
|
return { applied: true };
|
|
3258
3326
|
}
|
|
3259
3327
|
/**
|
|
3260
|
-
*
|
|
3261
|
-
*
|
|
3328
|
+
* Idempotently configure the deposit asset for a single chain before MCP prepare.
|
|
3329
|
+
*
|
|
3330
|
+
* @internal
|
|
3331
|
+
*/
|
|
3332
|
+
async ensureDepositProfileForPrepare(params) {
|
|
3333
|
+
const { strategy, asset, chainId } = params;
|
|
3334
|
+
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
3335
|
+
throw new Error(
|
|
3336
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
3337
|
+
);
|
|
3338
|
+
}
|
|
3339
|
+
await this.authenticateUser();
|
|
3340
|
+
const details = await this.getUserDetails(asset);
|
|
3341
|
+
if (details.chains?.includes(chainId)) {
|
|
3342
|
+
return { applied: false };
|
|
3343
|
+
}
|
|
3344
|
+
const allProtocols = await this.httpClient.get(
|
|
3345
|
+
ENDPOINTS.PROTOCOLS()
|
|
3346
|
+
);
|
|
3347
|
+
await this.updateUserProtocolsForAsset(
|
|
3348
|
+
asset,
|
|
3349
|
+
[chainId],
|
|
3350
|
+
strategy,
|
|
3351
|
+
allProtocols
|
|
3352
|
+
);
|
|
3353
|
+
const afterSetup = await this.getUserDetails(asset);
|
|
3354
|
+
if (!afterSetup.chains?.includes(chainId)) {
|
|
3355
|
+
throw new Error(
|
|
3356
|
+
`First-deposit setup did not persist ${asset} chain ${chainId} configuration.`
|
|
3357
|
+
);
|
|
3358
|
+
}
|
|
3359
|
+
return { applied: true };
|
|
3360
|
+
}
|
|
3361
|
+
/**
|
|
3362
|
+
* Prepare a deposit: persist first-deposit profile when needed and return
|
|
3363
|
+
* ERC-20 transfer calldata for the user to sign (does not broadcast).
|
|
3262
3364
|
*
|
|
3263
3365
|
* @group Deposits and withdrawals
|
|
3264
3366
|
*/
|
|
3265
|
-
async
|
|
3266
|
-
const { userAddress, chainId, amount, asset
|
|
3367
|
+
async prepareDeposit(params) {
|
|
3368
|
+
const { userAddress, chainId, amount, asset } = params;
|
|
3267
3369
|
if (this.sessionEoa && getAddress2(userAddress) !== this.sessionEoa) {
|
|
3268
3370
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
3269
3371
|
}
|
|
3270
|
-
const setup = await this.
|
|
3372
|
+
const setup = await this.ensureDepositProfileForPrepare({
|
|
3373
|
+
asset,
|
|
3374
|
+
chainId
|
|
3375
|
+
});
|
|
3271
3376
|
const transfer = await this.buildDepositTransfer({
|
|
3272
3377
|
userAddress,
|
|
3273
3378
|
chainId,
|
|
@@ -4786,62 +4891,70 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4786
4891
|
* ```
|
|
4787
4892
|
*/
|
|
4788
4893
|
/**
|
|
4789
|
-
* Get
|
|
4894
|
+
* Get persisted per-asset-type management settings (strategy, chains, protocols).
|
|
4790
4895
|
*
|
|
4791
4896
|
* @group Agent management
|
|
4792
4897
|
*/
|
|
4793
|
-
async
|
|
4898
|
+
async getAssetTypeSettings() {
|
|
4794
4899
|
await this.authenticateUser();
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4900
|
+
return this.httpClient.get(ENDPOINTS.USER_ASSET_TYPE_SETTINGS);
|
|
4901
|
+
}
|
|
4902
|
+
/**
|
|
4903
|
+
* Reserve a one-time action id before the user signs an ERC-20 transfer.
|
|
4904
|
+
*
|
|
4905
|
+
* @group Agent management
|
|
4906
|
+
*/
|
|
4907
|
+
async createAgentDepositIntent(request) {
|
|
4908
|
+
await this.authenticateUser();
|
|
4909
|
+
return this.httpClient.post(
|
|
4910
|
+
ENDPOINTS.USER_AGENT_DEPOSIT_INTENTS,
|
|
4911
|
+
request
|
|
4798
4912
|
);
|
|
4799
4913
|
}
|
|
4800
4914
|
/**
|
|
4801
|
-
*
|
|
4915
|
+
* Consume a one-time action id when registering the signed deposit.
|
|
4802
4916
|
*
|
|
4803
4917
|
* @group Agent management
|
|
4804
4918
|
*/
|
|
4805
|
-
async
|
|
4919
|
+
async consumeAgentDepositIntent(actionId, request) {
|
|
4806
4920
|
await this.authenticateUser();
|
|
4807
|
-
return this.httpClient.
|
|
4808
|
-
ENDPOINTS.
|
|
4921
|
+
return this.httpClient.post(
|
|
4922
|
+
ENDPOINTS.USER_AGENT_DEPOSIT_INTENT_CONSUME(actionId),
|
|
4809
4923
|
request
|
|
4810
4924
|
);
|
|
4811
4925
|
}
|
|
4812
4926
|
/**
|
|
4813
|
-
*
|
|
4927
|
+
* Poll MCP deposit-intent status (agent delegated session).
|
|
4814
4928
|
*
|
|
4815
4929
|
* @group Agent management
|
|
4816
4930
|
*/
|
|
4817
|
-
async
|
|
4931
|
+
async getAgentDepositIntentStatus(actionId) {
|
|
4818
4932
|
await this.authenticateUser();
|
|
4819
|
-
return this.httpClient.
|
|
4820
|
-
|
|
4933
|
+
return this.httpClient.get(
|
|
4934
|
+
ENDPOINTS.USER_AGENT_DEPOSIT_INTENT(actionId)
|
|
4821
4935
|
);
|
|
4822
4936
|
}
|
|
4823
4937
|
/**
|
|
4824
|
-
*
|
|
4938
|
+
* Mark intent complete after the user signed on zyf.ai (SIWE session).
|
|
4825
4939
|
*
|
|
4826
4940
|
* @group Agent management
|
|
4827
4941
|
*/
|
|
4828
|
-
async
|
|
4942
|
+
async completeAgentDepositIntent(actionId, request) {
|
|
4829
4943
|
await this.authenticateUser();
|
|
4830
4944
|
return this.httpClient.post(
|
|
4831
|
-
ENDPOINTS.
|
|
4945
|
+
ENDPOINTS.USER_AGENT_DEPOSIT_INTENT_COMPLETE(actionId),
|
|
4832
4946
|
request
|
|
4833
4947
|
);
|
|
4834
4948
|
}
|
|
4835
4949
|
/**
|
|
4836
|
-
*
|
|
4950
|
+
* Resolve a signing ticket from prepare_deposit (no user auth).
|
|
4837
4951
|
*
|
|
4838
4952
|
* @group Agent management
|
|
4839
4953
|
*/
|
|
4840
|
-
async
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
ENDPOINTS.
|
|
4844
|
-
request
|
|
4954
|
+
async resolveAgentDepositIntentTicket(ticket) {
|
|
4955
|
+
const query = `?ticket=${encodeURIComponent(ticket)}`;
|
|
4956
|
+
return this.httpClient.get(
|
|
4957
|
+
`${ENDPOINTS.AGENT_DEPOSIT_INTENT_RESOLVE}${query}`
|
|
4845
4958
|
);
|
|
4846
4959
|
}
|
|
4847
4960
|
async customizeBatch(customizations) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TypeScript SDK for Zyfai
|
|
3
|
+
"version": "0.4.1",
|
|
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",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -44,6 +44,9 @@
|
|
|
44
44
|
"defi",
|
|
45
45
|
"yield",
|
|
46
46
|
"yield-optimization",
|
|
47
|
+
"yield-agent",
|
|
48
|
+
"defi-agent",
|
|
49
|
+
"self-custodial",
|
|
47
50
|
"web3",
|
|
48
51
|
"ethereum",
|
|
49
52
|
"smart-wallet",
|