@zyfai/sdk 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +80 -51
- package/dist/index.d.ts +80 -51
- package/dist/index.js +145 -32
- package/dist/index.mjs +145 -32
- package/package.json +1 -1
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",
|
|
@@ -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",
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "TypeScript SDK for Zyfai Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|