@zyfai/sdk 0.2.57 → 0.3.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 +260 -71
- package/dist/index.d.mts +716 -122
- package/dist/index.d.ts +716 -122
- package/dist/index.js +1115 -275
- package/dist/index.mjs +1115 -275
- package/package.json +9 -4
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
|
+
USER_AGENT_MANDATE: "/users/me/agent-mandate",
|
|
48
|
+
USER_AGENT_ENTER_INTENTS: "/users/me/agent-enter-intents",
|
|
49
|
+
USER_AGENT_ENTER_INTENT_CONSUME: (actionId) => `/users/me/agent-enter-intents/${encodeURIComponent(actionId)}/consume`,
|
|
47
50
|
USER_WITHDRAW: "/users/withdraw",
|
|
48
51
|
PARTIAL_WITHDRAW: "/users/partial-withdraw",
|
|
49
|
-
LOG_DEPOSIT: "/users/log_deposit",
|
|
52
|
+
LOG_DEPOSIT: "/users/log_deposit/v2",
|
|
53
|
+
DEPOSIT_STATUS: (depositId) => `/users/deposits/${depositId}`,
|
|
50
54
|
// Safe Deployment (single endpoint)
|
|
51
55
|
SAFE_DEPLOY: "/users/safe-deploy",
|
|
52
56
|
// Multichain deploy for predeployed (pool) wallets — deploys + rotates the
|
|
@@ -168,6 +172,8 @@ var HttpClient = class {
|
|
|
168
172
|
*/
|
|
169
173
|
constructor(apiKey, config = {}) {
|
|
170
174
|
this.authToken = null;
|
|
175
|
+
/** @internal Extra headers on execution API requests (e.g. MCP server channel key). */
|
|
176
|
+
this.extraExecutionHeaders = {};
|
|
171
177
|
this.apiKey = apiKey;
|
|
172
178
|
const executionApiUrl = config.executionApiUrl ?? API_ENDPOINT;
|
|
173
179
|
this.dataApiBaseUrl = config.dataApiUrl ?? DATA_API_ENDPOINT;
|
|
@@ -196,9 +202,17 @@ var HttpClient = class {
|
|
|
196
202
|
setAuthToken(token) {
|
|
197
203
|
this.authToken = token;
|
|
198
204
|
}
|
|
205
|
+
/** @internal */
|
|
206
|
+
setExtraExecutionHeaders(headers) {
|
|
207
|
+
this.extraExecutionHeaders = headers;
|
|
208
|
+
}
|
|
199
209
|
clearAuthToken() {
|
|
200
210
|
this.authToken = null;
|
|
201
211
|
}
|
|
212
|
+
/** Whether a user Bearer token is set on this client instance. */
|
|
213
|
+
hasAuthToken() {
|
|
214
|
+
return this.authToken !== null;
|
|
215
|
+
}
|
|
202
216
|
getOrigin() {
|
|
203
217
|
return this.origin;
|
|
204
218
|
}
|
|
@@ -212,6 +226,9 @@ var HttpClient = class {
|
|
|
212
226
|
if (this.authToken) {
|
|
213
227
|
config.headers["Authorization"] = `Bearer ${this.authToken}`;
|
|
214
228
|
}
|
|
229
|
+
for (const [key, value] of Object.entries(this.extraExecutionHeaders)) {
|
|
230
|
+
config.headers[key] = value;
|
|
231
|
+
}
|
|
215
232
|
return config;
|
|
216
233
|
},
|
|
217
234
|
(error) => {
|
|
@@ -264,6 +281,10 @@ var HttpClient = class {
|
|
|
264
281
|
const response = await this.client.patch(url, data, config);
|
|
265
282
|
return response.data;
|
|
266
283
|
}
|
|
284
|
+
async put(url, data, config) {
|
|
285
|
+
const response = await this.client.put(url, data, config);
|
|
286
|
+
return response.data;
|
|
287
|
+
}
|
|
267
288
|
async delete(url, config) {
|
|
268
289
|
const response = await this.client.delete(url, config);
|
|
269
290
|
return response.data;
|
|
@@ -351,26 +372,30 @@ var HttpClient = class {
|
|
|
351
372
|
}
|
|
352
373
|
};
|
|
353
374
|
|
|
354
|
-
// src/utils/
|
|
375
|
+
// src/utils/poll.ts
|
|
376
|
+
function sleep(ms) {
|
|
377
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/utils/token-price.ts
|
|
355
381
|
var PRICE_SCALE = 8;
|
|
356
|
-
var
|
|
382
|
+
var parseTokenUsdPrice = (response) => {
|
|
357
383
|
const priceUsd = response?.data?.price_usd;
|
|
358
384
|
if (typeof priceUsd !== "number" || !Number.isFinite(priceUsd) || priceUsd <= 0) {
|
|
359
|
-
throw new Error("
|
|
385
|
+
throw new Error("Token USD price must be a positive number");
|
|
360
386
|
}
|
|
361
387
|
return priceUsd;
|
|
362
388
|
};
|
|
363
|
-
var
|
|
364
|
-
if (!Number.isFinite(
|
|
365
|
-
throw new Error("
|
|
389
|
+
var usdToTokenUnits = (usdAmount, priceUsd, decimals) => {
|
|
390
|
+
if (!Number.isFinite(priceUsd) || priceUsd <= 0) {
|
|
391
|
+
throw new Error("Token USD price must be positive");
|
|
366
392
|
}
|
|
367
|
-
const scaledPrice = BigInt(Math.round(
|
|
393
|
+
const scaledPrice = BigInt(Math.round(priceUsd * 10 ** PRICE_SCALE));
|
|
368
394
|
if (scaledPrice <= 0n) {
|
|
369
|
-
throw new Error("
|
|
395
|
+
throw new Error("Token USD price must be positive");
|
|
370
396
|
}
|
|
371
|
-
return usdAmount * 10n **
|
|
397
|
+
return usdAmount * 10n ** BigInt(decimals) * 10n ** BigInt(PRICE_SCALE) / scaledPrice;
|
|
372
398
|
};
|
|
373
|
-
var minWethWeiForUsd = (ethUsd, usdAmount) => usdToWethWei(usdAmount, ethUsd);
|
|
374
399
|
|
|
375
400
|
// src/config/abis.ts
|
|
376
401
|
import { parseAbi } from "viem";
|
|
@@ -563,11 +588,26 @@ var MIN_PORTFOLIO_BALANCE = {
|
|
|
563
588
|
// 100 EURC (6 decimals)
|
|
564
589
|
}
|
|
565
590
|
};
|
|
566
|
-
var
|
|
567
|
-
1: 10000n,
|
|
568
|
-
8453: 100n,
|
|
569
|
-
42161: 100n
|
|
591
|
+
var MIN_PORTFOLIO_USD = {
|
|
592
|
+
1: { WETH: 10000n },
|
|
593
|
+
8453: { WETH: 100n, NVDAc: 100n },
|
|
594
|
+
42161: { WETH: 100n }
|
|
595
|
+
};
|
|
596
|
+
var DEPOSIT_CREDIT_INTERVAL_MS = {
|
|
597
|
+
1: 2e3,
|
|
598
|
+
8453: 500,
|
|
599
|
+
42161: 250
|
|
570
600
|
};
|
|
601
|
+
var DEPOSIT_CREDIT_TIMEOUT_MS = {
|
|
602
|
+
1: 6e4,
|
|
603
|
+
// 1 minute
|
|
604
|
+
8453: 2e4,
|
|
605
|
+
// ~10 Base blocks
|
|
606
|
+
42161: 2e4
|
|
607
|
+
// ~10 Arbitrum blocks
|
|
608
|
+
};
|
|
609
|
+
var getDepositCreditIntervalMs = (chainId) => DEPOSIT_CREDIT_INTERVAL_MS[chainId];
|
|
610
|
+
var getDepositCreditTimeoutMs = (chainId) => DEPOSIT_CREDIT_TIMEOUT_MS[chainId];
|
|
571
611
|
var formatMinPortfolioLabel = (raw, decimals, symbol) => {
|
|
572
612
|
const base2 = 10n ** BigInt(decimals);
|
|
573
613
|
const whole = raw / base2;
|
|
@@ -579,6 +619,36 @@ var formatMinPortfolioLabel = (raw, decimals, symbol) => {
|
|
|
579
619
|
return `${whole.toString()}.${fractionStr} ${symbol}`;
|
|
580
620
|
};
|
|
581
621
|
|
|
622
|
+
// src/config/local-dev.ts
|
|
623
|
+
function isLocalExecutionApiUrl(executionApiUrl) {
|
|
624
|
+
if (executionApiUrl === EXECUTION_API_BASE_URLS.local) {
|
|
625
|
+
return true;
|
|
626
|
+
}
|
|
627
|
+
try {
|
|
628
|
+
const { hostname } = new URL(executionApiUrl);
|
|
629
|
+
return hostname === "localhost" || hostname === "127.0.0.1";
|
|
630
|
+
} catch {
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function isStagingExecutionApiUrl(executionApiUrl) {
|
|
635
|
+
if (executionApiUrl === EXECUTION_API_BASE_URLS.staging) {
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
638
|
+
try {
|
|
639
|
+
const { hostname } = new URL(executionApiUrl);
|
|
640
|
+
return hostname === "staging-api.zyf.ai";
|
|
641
|
+
} catch {
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function shouldBypassMinPortfolioCheck(executionApiUrl) {
|
|
646
|
+
if (process.env.NODE_ENV === "production") {
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
return isLocalExecutionApiUrl(executionApiUrl) || isStagingExecutionApiUrl(executionApiUrl);
|
|
650
|
+
}
|
|
651
|
+
|
|
582
652
|
// src/core/ZyfaiSDK.ts
|
|
583
653
|
import { privateKeyToAccount } from "viem/accounts";
|
|
584
654
|
import {
|
|
@@ -635,6 +705,8 @@ var ASSET_CONFIGS = {
|
|
|
635
705
|
displayName: "WETH",
|
|
636
706
|
icon: "/ai-dashboard/eth-token.png",
|
|
637
707
|
decimals: 18,
|
|
708
|
+
// Data API `/price?token=` identifier, used for USD-denominated minimums.
|
|
709
|
+
priceTokenSymbol: "eth",
|
|
638
710
|
tokenSymbols: ["WETH", "ETH"],
|
|
639
711
|
tokenSymbolsByChainId: {
|
|
640
712
|
1: "WETH",
|
|
@@ -675,8 +747,39 @@ var ASSET_CONFIGS = {
|
|
|
675
747
|
// Base
|
|
676
748
|
},
|
|
677
749
|
enabled: true
|
|
750
|
+
},
|
|
751
|
+
// Coinbase B20 tokenized NVIDIA equity. Base only, and only reachable through
|
|
752
|
+
// protocols with delayed withdrawals — see the `yieldmaxxing` strategy.
|
|
753
|
+
NVDAc: {
|
|
754
|
+
symbol: "NVDAc",
|
|
755
|
+
assetType: "nvdac",
|
|
756
|
+
displayName: "NVIDIA",
|
|
757
|
+
icon: "https://metadata.coinbase.com/equity_icons/1fee9b7a44e800d438dd9d96c3283e05784c925c2c871a48ff735950740b551a.png",
|
|
758
|
+
decimals: 8,
|
|
759
|
+
priceTokenSymbol: "nvdac",
|
|
760
|
+
tokenSymbols: ["NVDAc"],
|
|
761
|
+
tokenSymbolsByChainId: {
|
|
762
|
+
8453: "NVDAc"
|
|
763
|
+
},
|
|
764
|
+
addresses: {
|
|
765
|
+
8453: "0xb20000000000000000000078ee7ce2fE4908108C"
|
|
766
|
+
// Base
|
|
767
|
+
},
|
|
768
|
+
enabled: true
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
var resolveAssetSymbol = (asset) => {
|
|
772
|
+
const match = Object.keys(ASSET_CONFIGS).find(
|
|
773
|
+
(key) => key.toLowerCase() === asset.toLowerCase()
|
|
774
|
+
);
|
|
775
|
+
if (!match) {
|
|
776
|
+
throw new Error(
|
|
777
|
+
`Unsupported asset: ${asset}. Supported: ${Object.keys(ASSET_CONFIGS).join(", ")}.`
|
|
778
|
+
);
|
|
678
779
|
}
|
|
780
|
+
return match;
|
|
679
781
|
};
|
|
782
|
+
var getAssetChainIds = (asset) => Object.keys(ASSET_CONFIGS[asset]?.addresses ?? {}).map(Number).filter((chainId) => chainId in CHAINS);
|
|
680
783
|
var getDefaultTokenAddress = (chainId, asset) => {
|
|
681
784
|
const address = ASSET_CONFIGS[asset || "USDC"]?.addresses[chainId];
|
|
682
785
|
if (!address || address === "0x0000000000000000000000000000000000000000") {
|
|
@@ -966,6 +1069,7 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
|
|
|
966
1069
|
|
|
967
1070
|
// src/utils/strategy.ts
|
|
968
1071
|
var PUBLIC_STRATEGIES = `"conservative", "aggressive" or "yieldmaxxing"`;
|
|
1072
|
+
var SUPPORTED_ASSETS = `"USDC", "WETH", "EURC" or "NVDAc"`;
|
|
969
1073
|
function toInternalStrategy(publicStrategy) {
|
|
970
1074
|
switch (publicStrategy) {
|
|
971
1075
|
case "conservative":
|
|
@@ -1054,8 +1158,11 @@ function convertAssetInternally(asset) {
|
|
|
1054
1158
|
if (asset === "EURC") {
|
|
1055
1159
|
return "eurc";
|
|
1056
1160
|
}
|
|
1161
|
+
if (asset === "NVDAc") {
|
|
1162
|
+
return "nvdac";
|
|
1163
|
+
}
|
|
1057
1164
|
throw new Error(
|
|
1058
|
-
`Invalid asset: ${asset}. Must be
|
|
1165
|
+
`Invalid asset: ${asset}. Must be ${SUPPORTED_ASSETS}.`
|
|
1059
1166
|
);
|
|
1060
1167
|
}
|
|
1061
1168
|
function convertStrategiesToPublic(array) {
|
|
@@ -1443,7 +1550,7 @@ function enrichOnchainEarningsTotals(apiData) {
|
|
|
1443
1550
|
const unrealized = unrealizedByToken[symbol] ?? 0;
|
|
1444
1551
|
const current = currentByToken[symbol] ?? 0;
|
|
1445
1552
|
totalEarningsByTokenWithFee[symbol] = formatHumanAmount(
|
|
1446
|
-
lifetime + unrealized + current * keepRate
|
|
1553
|
+
(lifetime + unrealized + current) * keepRate
|
|
1447
1554
|
);
|
|
1448
1555
|
});
|
|
1449
1556
|
const chainKeys = /* @__PURE__ */ new Set([
|
|
@@ -1467,7 +1574,7 @@ function enrichOnchainEarningsTotals(apiData) {
|
|
|
1467
1574
|
const unrealized = parseHumanAmount(unrealizedTokens[symbol]);
|
|
1468
1575
|
const current = parseHumanAmount(currentTokens[symbol]);
|
|
1469
1576
|
chainMap[symbol] = formatHumanAmount(
|
|
1470
|
-
lifetime + unrealized + current * keepRate
|
|
1577
|
+
(lifetime + unrealized + current) * keepRate
|
|
1471
1578
|
);
|
|
1472
1579
|
});
|
|
1473
1580
|
totalEarningsByChainWithFee[chainId] = chainMap;
|
|
@@ -1478,9 +1585,51 @@ function enrichOnchainEarningsTotals(apiData) {
|
|
|
1478
1585
|
};
|
|
1479
1586
|
}
|
|
1480
1587
|
|
|
1588
|
+
// src/utils/async-withdrawals.ts
|
|
1589
|
+
var findBlockingAsyncRedemption = (portfolio, chainId, tokenSymbol) => {
|
|
1590
|
+
const matchesToken = (symbol) => !tokenSymbol || symbol?.toLowerCase() === tokenSymbol.toLowerCase();
|
|
1591
|
+
const blocked = (portfolio.pendingAsyncWithdrawals ?? []).filter(
|
|
1592
|
+
(w) => w.chainId === chainId && (w.status === "REQUESTED" || w.status === "CLAIMABLE") && matchesToken(w.token?.symbol)
|
|
1593
|
+
);
|
|
1594
|
+
if (blocked.length === 0) return void 0;
|
|
1595
|
+
const blockedPools = new Set(
|
|
1596
|
+
blocked.map((w) => w.pool?.toLowerCase()).filter(Boolean)
|
|
1597
|
+
);
|
|
1598
|
+
const hasFreePosition = (portfolio.positions ?? []).some(
|
|
1599
|
+
(p) => matchesToken(p.token_symbol) && Number(chainNameToId(p.chain ?? "")) === chainId && !blockedPools.has(p.pool?.toLowerCase() ?? "")
|
|
1600
|
+
);
|
|
1601
|
+
const hasIdleBalance = (portfolio.staleBalances ?? []).some(
|
|
1602
|
+
(b) => b.chainId === chainId && matchesToken(b.tokenSymbol) && BigInt(b.balance ?? "0") > 0n
|
|
1603
|
+
);
|
|
1604
|
+
return hasFreePosition || hasIdleBalance ? void 0 : blocked[0];
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1481
1607
|
// src/core/ZyfaiSDK.ts
|
|
1482
1608
|
import { SiweMessage } from "siwe";
|
|
1609
|
+
var DepositCreditTimeoutError = class extends Error {
|
|
1610
|
+
constructor(depositId) {
|
|
1611
|
+
super(`Timed out waiting for deposit ${depositId} to be credited`);
|
|
1612
|
+
this.name = "DepositCreditTimeoutError";
|
|
1613
|
+
}
|
|
1614
|
+
};
|
|
1615
|
+
var MANAGED_ASSETS = ["USDC", "WETH", "EURC", "NVDAc"];
|
|
1483
1616
|
var _ZyfaiSDK = class _ZyfaiSDK {
|
|
1617
|
+
/**
|
|
1618
|
+
* Create an SDK instance bound to a partner API key.
|
|
1619
|
+
*
|
|
1620
|
+
* @param config - API key string or {@link SDKConfig} with optional `rpcUrls` and `referralSource`
|
|
1621
|
+
*
|
|
1622
|
+
* @remarks
|
|
1623
|
+
* `@internal` fields on {@link SDKConfig} (`executionApiUrl`, `dataApiUrl`,
|
|
1624
|
+
* `bypassMinPortfolio`) are for local integration tests only.
|
|
1625
|
+
*
|
|
1626
|
+
* @throws If `apiKey` is missing
|
|
1627
|
+
*
|
|
1628
|
+
* @example
|
|
1629
|
+
* ```typescript
|
|
1630
|
+
* const sdk = new ZyfaiSDK({ apiKey: process.env.ZYFAI_API_KEY! });
|
|
1631
|
+
* ```
|
|
1632
|
+
*/
|
|
1484
1633
|
constructor(config) {
|
|
1485
1634
|
this.signer = null;
|
|
1486
1635
|
this.walletClient = null;
|
|
@@ -1490,18 +1639,22 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1490
1639
|
this.connectedSmartWallet = null;
|
|
1491
1640
|
this.currentProvider = null;
|
|
1492
1641
|
this.currentChainId = null;
|
|
1642
|
+
/** EOA of the active user session (bearer or SIWE). Cleared on disconnect. */
|
|
1643
|
+
this.sessionEoa = null;
|
|
1493
1644
|
const sdkConfig = typeof config === "string" ? { apiKey: config } : config;
|
|
1494
1645
|
const {
|
|
1495
1646
|
apiKey,
|
|
1496
1647
|
rpcUrls,
|
|
1497
1648
|
referralSource,
|
|
1498
1649
|
executionApiUrl,
|
|
1499
|
-
dataApiUrl
|
|
1650
|
+
dataApiUrl,
|
|
1651
|
+
bypassMinPortfolio
|
|
1500
1652
|
} = sdkConfig;
|
|
1501
1653
|
if (!apiKey) {
|
|
1502
1654
|
throw new Error("API key is required");
|
|
1503
1655
|
}
|
|
1504
1656
|
this.executionApiUrl = executionApiUrl ?? API_ENDPOINT;
|
|
1657
|
+
this.bypassMinPortfolio = bypassMinPortfolio ?? shouldBypassMinPortfolioCheck(this.executionApiUrl);
|
|
1505
1658
|
this.httpClient = new HttpClient(apiKey, {
|
|
1506
1659
|
executionApiUrl: this.executionApiUrl,
|
|
1507
1660
|
dataApiUrl
|
|
@@ -1510,12 +1663,84 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1510
1663
|
this.referralSource = referralSource;
|
|
1511
1664
|
}
|
|
1512
1665
|
/**
|
|
1513
|
-
*
|
|
1666
|
+
* Create an SDK instance with an existing Zyfai user JWT (no wallet connected).
|
|
1667
|
+
*
|
|
1668
|
+
* @group Authentication and wallet
|
|
1669
|
+
*/
|
|
1670
|
+
static forUser(config, session) {
|
|
1671
|
+
const sdk = new _ZyfaiSDK(config);
|
|
1672
|
+
sdk.applyUserSession(session);
|
|
1673
|
+
return sdk;
|
|
1674
|
+
}
|
|
1675
|
+
/** Alias for MCP delegated grants (scoped agent JWT). */
|
|
1676
|
+
static forDelegatedGrant(config, session) {
|
|
1677
|
+
return _ZyfaiSDK.forUser(config, session);
|
|
1678
|
+
}
|
|
1679
|
+
/**
|
|
1680
|
+
* Attach a Zyfai user JWT for API calls without `connectAccount`.
|
|
1681
|
+
*
|
|
1682
|
+
* @group Authentication and wallet
|
|
1683
|
+
*/
|
|
1684
|
+
applyUserSession(session) {
|
|
1685
|
+
if (!session.accessToken) {
|
|
1686
|
+
throw new Error("accessToken is required");
|
|
1687
|
+
}
|
|
1688
|
+
this.httpClient.setAuthToken(session.accessToken);
|
|
1689
|
+
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
1690
|
+
this.sessionEoa = session.eoa ? getAddress2(session.eoa) : null;
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* @internal Attach headers to execution API requests (MCP server agent channel).
|
|
1694
|
+
*/
|
|
1695
|
+
setExecutionRequestHeaders(headers) {
|
|
1696
|
+
this.httpClient.setExtraExecutionHeaders(headers);
|
|
1697
|
+
}
|
|
1698
|
+
/** EOA of the active user session, if one is bound. */
|
|
1699
|
+
getSessionEoa() {
|
|
1700
|
+
return this.sessionEoa;
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Complete SIWE login with a prepared message and signature (OAuth consent, MCP).
|
|
1704
|
+
*
|
|
1705
|
+
* @group Authentication and wallet
|
|
1706
|
+
*
|
|
1707
|
+
* @param params.message - SIWE message fields (same shape as login API body)
|
|
1708
|
+
* @param params.signature - Wallet signature over the prepared SIWE string
|
|
1709
|
+
* @param params.origin - Origin header value; must match `message.uri`
|
|
1710
|
+
*/
|
|
1711
|
+
async authenticateWithSignature(params) {
|
|
1712
|
+
const origin = params.origin ?? params.message.uri;
|
|
1713
|
+
const loginResponse = await this.httpClient.post(
|
|
1714
|
+
ENDPOINTS.AUTH_LOGIN,
|
|
1715
|
+
{
|
|
1716
|
+
message: params.message,
|
|
1717
|
+
signature: params.signature,
|
|
1718
|
+
referralSource: this.referralSource
|
|
1719
|
+
},
|
|
1720
|
+
{
|
|
1721
|
+
headers: {
|
|
1722
|
+
Origin: origin
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
);
|
|
1726
|
+
if (!loginResponse.accessToken) {
|
|
1727
|
+
throw new Error("Authentication response missing access token");
|
|
1728
|
+
}
|
|
1729
|
+
this.httpClient.setAuthToken(loginResponse.accessToken);
|
|
1730
|
+
this.authenticatedUserId = loginResponse.userId || null;
|
|
1731
|
+
this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
|
|
1732
|
+
this.isPredeployed = loginResponse.predeployed || false;
|
|
1733
|
+
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
1734
|
+
this.sessionEoa = getAddress2(params.message.address);
|
|
1735
|
+
return loginResponse;
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Warn that a legacy method is deprecated in favor of sendDeposit.
|
|
1514
1739
|
* Predeployed wallets no longer require deploySafe / createSessionKey.
|
|
1515
1740
|
*/
|
|
1516
1741
|
warnDeprecatedOnboardingMethod(methodName) {
|
|
1517
1742
|
console.warn(
|
|
1518
|
-
`[ZyfaiSDK] ${methodName}() is deprecated for partner integrations. Prefer
|
|
1743
|
+
`[ZyfaiSDK] ${methodName}() is deprecated for partner integrations. Prefer sendDeposit() \u2014 predeployed Safes and session keys are handled automatically on first deposit.`
|
|
1519
1744
|
);
|
|
1520
1745
|
}
|
|
1521
1746
|
/**
|
|
@@ -1530,6 +1755,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1530
1755
|
if (this.authenticatedUserId !== null) {
|
|
1531
1756
|
return;
|
|
1532
1757
|
}
|
|
1758
|
+
if (this.httpClient.hasAuthToken()) {
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1533
1761
|
const walletClient = this.getWalletClient();
|
|
1534
1762
|
const userAddress = getAddress2(walletClient.account.address);
|
|
1535
1763
|
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
@@ -1583,6 +1811,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1583
1811
|
this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
|
|
1584
1812
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
1585
1813
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
1814
|
+
this.sessionEoa = userAddress;
|
|
1586
1815
|
} catch (error) {
|
|
1587
1816
|
throw new Error(
|
|
1588
1817
|
`Failed to authenticate user: ${error.message}`
|
|
@@ -1593,8 +1822,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1593
1822
|
* Update user profile with Smart Wallet address and chain configuration
|
|
1594
1823
|
* This method requires SIWE authentication and is automatically called after deploySafe
|
|
1595
1824
|
*
|
|
1596
|
-
* @
|
|
1597
|
-
*
|
|
1825
|
+
* @group Portfolio and execution
|
|
1826
|
+
*
|
|
1827
|
+
* @param request - Profile fields to update (per-asset settings supported)
|
|
1828
|
+
* @returns Updated user profile from the execution API
|
|
1829
|
+
*
|
|
1830
|
+
* @throws If strategy is invalid or authentication fails
|
|
1598
1831
|
*
|
|
1599
1832
|
* @example
|
|
1600
1833
|
* ```typescript
|
|
@@ -1619,25 +1852,31 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1619
1852
|
rebalanceStrategy = toInternalStrategy(request.strategy);
|
|
1620
1853
|
}
|
|
1621
1854
|
const assetSettings = {};
|
|
1622
|
-
if (rebalanceStrategy !== void 0)
|
|
1623
|
-
|
|
1624
|
-
if (request.
|
|
1625
|
-
|
|
1626
|
-
if (request.
|
|
1855
|
+
if (rebalanceStrategy !== void 0)
|
|
1856
|
+
assetSettings.rebalanceStrategy = rebalanceStrategy;
|
|
1857
|
+
if (request.autocompounding !== void 0)
|
|
1858
|
+
assetSettings.autocompounding = request.autocompounding;
|
|
1859
|
+
if (request.crosschainStrategy !== void 0)
|
|
1860
|
+
assetSettings.crosschainStrategy = request.crosschainStrategy;
|
|
1861
|
+
if (request.splitting !== void 0)
|
|
1862
|
+
assetSettings.splitting = request.splitting;
|
|
1863
|
+
if (request.minSplits !== void 0)
|
|
1864
|
+
assetSettings.minSplits = request.minSplits;
|
|
1627
1865
|
if (request.chains !== void 0) assetSettings.chains = request.chains;
|
|
1628
|
-
if (request.autoSelectProtocols !== void 0)
|
|
1629
|
-
|
|
1866
|
+
if (request.autoSelectProtocols !== void 0)
|
|
1867
|
+
assetSettings.autoSelectProtocols = request.autoSelectProtocols;
|
|
1868
|
+
if (request.protocols !== void 0)
|
|
1869
|
+
assetSettings.protocols = request.protocols;
|
|
1630
1870
|
const payload = {
|
|
1631
1871
|
assetTypeSettings: {
|
|
1632
1872
|
[internalAsset]: assetSettings
|
|
1633
1873
|
}
|
|
1634
1874
|
};
|
|
1635
|
-
if (request.omniAccount !== void 0)
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
);
|
|
1875
|
+
if (request.omniAccount !== void 0)
|
|
1876
|
+
payload.omniAccount = request.omniAccount;
|
|
1877
|
+
if (request.agentName !== void 0)
|
|
1878
|
+
payload.agentName = request.agentName;
|
|
1879
|
+
await this.httpClient.patch(ENDPOINTS.USER_ME, payload);
|
|
1641
1880
|
return await this.getUserDetails(asset);
|
|
1642
1881
|
} catch (error) {
|
|
1643
1882
|
throw new Error(
|
|
@@ -1649,8 +1888,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1649
1888
|
* Pause the agent by clearing all protocols
|
|
1650
1889
|
* Sets the user's protocols to an empty array, effectively pausing automated operations
|
|
1651
1890
|
*
|
|
1891
|
+
* @group Portfolio and execution
|
|
1892
|
+
*
|
|
1652
1893
|
* @returns Response indicating success and updated user details
|
|
1653
1894
|
*
|
|
1895
|
+
* @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
|
|
1896
|
+
*
|
|
1654
1897
|
* @example
|
|
1655
1898
|
* ```typescript
|
|
1656
1899
|
* const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
|
|
@@ -1665,19 +1908,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1665
1908
|
*/
|
|
1666
1909
|
async pauseAgent() {
|
|
1667
1910
|
try {
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
protocols: []
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
const response = await this.updateUserProfile({
|
|
1677
|
-
asset: "EURC",
|
|
1678
|
-
protocols: []
|
|
1679
|
-
});
|
|
1680
|
-
return response;
|
|
1911
|
+
let latest;
|
|
1912
|
+
for (const asset of MANAGED_ASSETS) {
|
|
1913
|
+
latest = await this.updateUserProfile({ asset, protocols: [] });
|
|
1914
|
+
}
|
|
1915
|
+
if (!latest) {
|
|
1916
|
+
throw new Error("No supported assets to pause");
|
|
1917
|
+
}
|
|
1918
|
+
return latest;
|
|
1681
1919
|
} catch (error) {
|
|
1682
1920
|
throw new Error(`Failed to pause agent: ${error.message}`);
|
|
1683
1921
|
}
|
|
@@ -1686,8 +1924,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1686
1924
|
* Resume the agent by restoring protocols based on user's strategy for each asset
|
|
1687
1925
|
* Fetches available protocols and assigns them based on each asset's strategy
|
|
1688
1926
|
*
|
|
1927
|
+
* @group Portfolio and execution
|
|
1928
|
+
*
|
|
1689
1929
|
* @returns Response indicating success and updated user details
|
|
1690
1930
|
*
|
|
1931
|
+
* @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
|
|
1932
|
+
*
|
|
1691
1933
|
* @example
|
|
1692
1934
|
* ```typescript
|
|
1693
1935
|
* const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
|
|
@@ -1702,50 +1944,22 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1702
1944
|
*/
|
|
1703
1945
|
async resumeAgent() {
|
|
1704
1946
|
try {
|
|
1705
|
-
const userDetailsUSDC = await this.getUserDetails("USDC");
|
|
1706
|
-
const userDetailsETH = await this.getUserDetails("WETH");
|
|
1707
|
-
const userDetailsEURC = await this.getUserDetails("EURC");
|
|
1708
|
-
const chains = userDetailsUSDC.chains && userDetailsUSDC.chains.length > 0 ? userDetailsUSDC.chains : [8453, 42161];
|
|
1709
|
-
const eurcChains = userDetailsEURC.chains && userDetailsEURC.chains.length > 0 ? userDetailsEURC.chains.filter((c) => c === 1 || c === 8453) : [1, 8453];
|
|
1710
1947
|
const allProtocols = await this.httpClient.get(
|
|
1711
1948
|
ENDPOINTS.PROTOCOLS()
|
|
1712
1949
|
);
|
|
1713
|
-
|
|
1714
|
-
const
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
return protocol.strategies?.includes("safe_strategy") || protocol.strategies?.includes("degen_strategy") || protocol.strategies?.includes("async_strategy");
|
|
1727
|
-
}
|
|
1728
|
-
if (strategy === "degen_strategy") {
|
|
1729
|
-
return protocol.strategies?.includes("safe_strategy") || protocol.strategies?.includes("degen_strategy");
|
|
1730
|
-
}
|
|
1731
|
-
return protocol.strategies?.includes("safe_strategy");
|
|
1732
|
-
}).map((protocol) => protocol.id);
|
|
1733
|
-
};
|
|
1734
|
-
const usdcProtocols = filterProtocolsByStrategy(usdcStrategy, chains);
|
|
1735
|
-
const ethProtocols = filterProtocolsByStrategy(ethStrategy, chains);
|
|
1736
|
-
const eurcProtocols = filterProtocolsByStrategy(eurcStrategy, eurcChains);
|
|
1737
|
-
await this.updateUserProfile({
|
|
1738
|
-
asset: "USDC",
|
|
1739
|
-
protocols: usdcProtocols
|
|
1740
|
-
});
|
|
1741
|
-
await this.updateUserProfile({
|
|
1742
|
-
asset: "WETH",
|
|
1743
|
-
protocols: ethProtocols
|
|
1744
|
-
});
|
|
1745
|
-
return await this.updateUserProfile({
|
|
1746
|
-
asset: "EURC",
|
|
1747
|
-
protocols: eurcProtocols
|
|
1748
|
-
});
|
|
1950
|
+
let latest;
|
|
1951
|
+
for (const asset of MANAGED_ASSETS) {
|
|
1952
|
+
latest = await this.updateUserProtocolsForAsset(
|
|
1953
|
+
asset,
|
|
1954
|
+
getAssetChainIds(asset),
|
|
1955
|
+
void 0,
|
|
1956
|
+
allProtocols
|
|
1957
|
+
);
|
|
1958
|
+
}
|
|
1959
|
+
if (!latest) {
|
|
1960
|
+
throw new Error("No supported assets to resume");
|
|
1961
|
+
}
|
|
1962
|
+
return latest;
|
|
1749
1963
|
} catch (error) {
|
|
1750
1964
|
throw new Error(`Failed to resume agent: ${error.message}`);
|
|
1751
1965
|
}
|
|
@@ -1754,9 +1968,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1754
1968
|
* Enable splitting for the user's account
|
|
1755
1969
|
* When enabled, deposits are split across multiple protocols based on minSplits setting
|
|
1756
1970
|
*
|
|
1757
|
-
* @
|
|
1971
|
+
* @group Portfolio and execution
|
|
1972
|
+
*
|
|
1973
|
+
* @param minSplits - Minimum protocols to split across (max 4)
|
|
1974
|
+
* @defaultValue 1
|
|
1758
1975
|
* @returns Response indicating success and updated user details
|
|
1759
1976
|
*
|
|
1977
|
+
* @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
|
|
1978
|
+
*
|
|
1979
|
+
* @throws If `minSplits` exceeds 4
|
|
1980
|
+
*
|
|
1760
1981
|
* @example
|
|
1761
1982
|
* ```typescript
|
|
1762
1983
|
* const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
|
|
@@ -1780,15 +2001,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1780
2001
|
});
|
|
1781
2002
|
return response;
|
|
1782
2003
|
} catch (error) {
|
|
1783
|
-
throw new Error(
|
|
2004
|
+
throw new Error(
|
|
2005
|
+
`Failed to enable splitting: ${error.message}`
|
|
2006
|
+
);
|
|
1784
2007
|
}
|
|
1785
2008
|
}
|
|
1786
2009
|
/**
|
|
1787
2010
|
* Disable splitting for the user's account
|
|
1788
2011
|
* When disabled, deposits will not be split across multiple protocols
|
|
1789
2012
|
*
|
|
2013
|
+
* @group Portfolio and execution
|
|
2014
|
+
*
|
|
1790
2015
|
* @returns Response indicating success and updated user details
|
|
1791
2016
|
*
|
|
2017
|
+
* @remarks Requires {@link ZyfaiSDK.connectAccount} (SIWE).
|
|
2018
|
+
*
|
|
1792
2019
|
* @example
|
|
1793
2020
|
* ```typescript
|
|
1794
2021
|
* const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
|
|
@@ -1808,16 +2035,22 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1808
2035
|
});
|
|
1809
2036
|
return response;
|
|
1810
2037
|
} catch (error) {
|
|
1811
|
-
throw new Error(
|
|
2038
|
+
throw new Error(
|
|
2039
|
+
`Failed to disable splitting: ${error.message}`
|
|
2040
|
+
);
|
|
1812
2041
|
}
|
|
1813
2042
|
}
|
|
1814
2043
|
/**
|
|
1815
2044
|
* Update the minimum number of splits for the user's account
|
|
1816
2045
|
* This controls across how many protocols deposits should be distributed
|
|
1817
2046
|
*
|
|
1818
|
-
* @
|
|
2047
|
+
* @group Portfolio and execution
|
|
2048
|
+
*
|
|
2049
|
+
* @param minSplits - Minimum number of protocols to split across (at least 1)
|
|
1819
2050
|
* @returns Response indicating success and updated user details
|
|
1820
2051
|
*
|
|
2052
|
+
* @throws If `minSplits` is less than 1
|
|
2053
|
+
*
|
|
1821
2054
|
* @example
|
|
1822
2055
|
* ```typescript
|
|
1823
2056
|
* const sdk = new ZyfaiSDK({ apiKey: 'your-api-key' });
|
|
@@ -1840,7 +2073,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1840
2073
|
});
|
|
1841
2074
|
return response;
|
|
1842
2075
|
} catch (error) {
|
|
1843
|
-
throw new Error(
|
|
2076
|
+
throw new Error(
|
|
2077
|
+
`Failed to update min splits: ${error.message}`
|
|
2078
|
+
);
|
|
1844
2079
|
}
|
|
1845
2080
|
}
|
|
1846
2081
|
/**
|
|
@@ -1894,6 +2129,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1894
2129
|
}
|
|
1895
2130
|
this.authenticatedUserId = null;
|
|
1896
2131
|
this.hasActiveSessionKey = false;
|
|
2132
|
+
this.sessionEoa = null;
|
|
1897
2133
|
this.httpClient.clearAuthToken();
|
|
1898
2134
|
if (this.walletClient && this.currentProvider) {
|
|
1899
2135
|
const chainConfig = getChainConfig(
|
|
@@ -1917,12 +2153,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1917
2153
|
}
|
|
1918
2154
|
}
|
|
1919
2155
|
/**
|
|
1920
|
-
* Connect account for signing
|
|
1921
|
-
*
|
|
2156
|
+
* Connect an account for signing (SIWE and on-chain transfers).
|
|
2157
|
+
*
|
|
2158
|
+
* @remarks
|
|
2159
|
+
* Required before user-scoped execution calls (deposits, withdrawals, profile).
|
|
2160
|
+
* Data API reads typically need only the API key.
|
|
1922
2161
|
*
|
|
1923
|
-
* @
|
|
1924
|
-
*
|
|
1925
|
-
* @
|
|
2162
|
+
* @group Authentication and wallet
|
|
2163
|
+
*
|
|
2164
|
+
* @param account - Private key hex string or EIP-1193 wallet provider
|
|
2165
|
+
* @param chainId - Initial chain for RPC and SIWE
|
|
2166
|
+
* @defaultValue 8453
|
|
2167
|
+
* @returns The connected EOA address (checksum)
|
|
2168
|
+
*
|
|
2169
|
+
* @throws If the chain is unsupported or the provider returns no accounts
|
|
1926
2170
|
*
|
|
1927
2171
|
* @example
|
|
1928
2172
|
* // With private key
|
|
@@ -1941,6 +2185,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1941
2185
|
this.isPredeployed = false;
|
|
1942
2186
|
this.connectedSmartWallet = null;
|
|
1943
2187
|
this.currentChainId = null;
|
|
2188
|
+
this.sessionEoa = null;
|
|
1944
2189
|
this.httpClient.clearAuthToken();
|
|
1945
2190
|
if (this.currentProvider?.removeAllListeners) {
|
|
1946
2191
|
try {
|
|
@@ -2008,8 +2253,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2008
2253
|
return connectedAddress;
|
|
2009
2254
|
}
|
|
2010
2255
|
/**
|
|
2011
|
-
*
|
|
2012
|
-
*
|
|
2256
|
+
* Clear the connected wallet, SIWE session, and cached smart-wallet state.
|
|
2257
|
+
*
|
|
2258
|
+
* @group Authentication and wallet
|
|
2259
|
+
*
|
|
2260
|
+
* @returns Resolves when local SDK state is cleared
|
|
2013
2261
|
*
|
|
2014
2262
|
* @example
|
|
2015
2263
|
* ```typescript
|
|
@@ -2032,6 +2280,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2032
2280
|
this.hasActiveSessionKey = false;
|
|
2033
2281
|
this.isPredeployed = false;
|
|
2034
2282
|
this.connectedSmartWallet = null;
|
|
2283
|
+
this.sessionEoa = null;
|
|
2035
2284
|
this.httpClient.clearAuthToken();
|
|
2036
2285
|
}
|
|
2037
2286
|
/**
|
|
@@ -2098,15 +2347,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2098
2347
|
});
|
|
2099
2348
|
}
|
|
2100
2349
|
/**
|
|
2101
|
-
*
|
|
2102
|
-
*
|
|
2103
|
-
*
|
|
2350
|
+
* Resolve the Safe smart wallet for an EOA on a chain.
|
|
2351
|
+
*
|
|
2352
|
+
* @remarks
|
|
2353
|
+
* Predeployed pool wallets use a backend-assigned address; legacy wallets use
|
|
2354
|
+
* a deterministic CREATE2 address.
|
|
2355
|
+
*
|
|
2356
|
+
* @group Authentication and wallet
|
|
2104
2357
|
*
|
|
2105
2358
|
* @param userAddress - User's EOA address
|
|
2106
2359
|
* @param chainId - Target chain ID
|
|
2107
|
-
* @returns Smart wallet address, deployment status, and
|
|
2108
|
-
*
|
|
2109
|
-
*
|
|
2360
|
+
* @returns Smart wallet address, deployment status, and on-chain ownership flag
|
|
2361
|
+
*
|
|
2362
|
+
* @throws If `userAddress` is missing or `chainId` is unsupported
|
|
2110
2363
|
*/
|
|
2111
2364
|
async getSmartWalletAddress(userAddress, chainId) {
|
|
2112
2365
|
if (!userAddress) {
|
|
@@ -2138,10 +2391,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2138
2391
|
/**
|
|
2139
2392
|
* Deploy Safe Smart Wallet for a user
|
|
2140
2393
|
*
|
|
2141
|
-
* @deprecated Prefer
|
|
2394
|
+
* @deprecated Prefer {@link ZyfaiSDK.sendDeposit}. Predeployed Safes and session keys are
|
|
2142
2395
|
* managed automatically on first deposit. This method remains available for
|
|
2143
2396
|
* legacy flows.
|
|
2144
2397
|
*
|
|
2398
|
+
* @see {@link ZyfaiSDK.sendDeposit}
|
|
2399
|
+
*
|
|
2400
|
+
* @group Deposits and withdrawals
|
|
2401
|
+
*
|
|
2145
2402
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
2146
2403
|
* @param chainId - Target chain ID
|
|
2147
2404
|
* @param strategy - Optional strategy selection: "conservative" (default), "aggressive" or "yieldmaxxing"
|
|
@@ -2150,8 +2407,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2150
2407
|
*
|
|
2151
2408
|
* @example
|
|
2152
2409
|
* ```typescript
|
|
2153
|
-
* // Preferred:
|
|
2154
|
-
* await sdk.
|
|
2410
|
+
* // Preferred: sendDeposit handles predeployed wallet onboarding
|
|
2411
|
+
* const sent = await sdk.sendDeposit(userAddress, 8453, amount, "USDC");
|
|
2412
|
+
* await sdk.waitForDepositCredit(sent.registration.id, 8453);
|
|
2155
2413
|
*
|
|
2156
2414
|
* // Legacy: deploy with default conservative strategy
|
|
2157
2415
|
* await sdk.deploySafe(userAddress, 8453);
|
|
@@ -2269,7 +2527,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2269
2527
|
} catch (error) {
|
|
2270
2528
|
console.error("Safe deployment failed:", error);
|
|
2271
2529
|
throw new Error(
|
|
2272
|
-
`Safe deployment failed: ${error.message}. deploySafe() is deprecated \u2014 prefer
|
|
2530
|
+
`Safe deployment failed: ${error.message}. deploySafe() is deprecated \u2014 prefer sendDeposit() for predeployed wallet onboarding.`
|
|
2273
2531
|
);
|
|
2274
2532
|
}
|
|
2275
2533
|
}
|
|
@@ -2277,18 +2535,23 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2277
2535
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
2278
2536
|
* This is the simplified method that automatically fetches session configuration
|
|
2279
2537
|
*
|
|
2280
|
-
* @deprecated Prefer
|
|
2538
|
+
* @deprecated Prefer {@link ZyfaiSDK.sendDeposit}. Predeployed wallets already have the
|
|
2281
2539
|
* agent session enabled; session activation is handled after first deposit.
|
|
2282
2540
|
* This method remains available for legacy flows.
|
|
2283
2541
|
*
|
|
2542
|
+
* @see {@link ZyfaiSDK.sendDeposit}
|
|
2543
|
+
*
|
|
2544
|
+
* @group Deposits and withdrawals
|
|
2545
|
+
*
|
|
2284
2546
|
* @param userAddress - User's EOA or Safe address
|
|
2285
2547
|
* @param chainId - Target chain ID
|
|
2286
2548
|
* @returns Session key response with signature and nonces
|
|
2287
2549
|
*
|
|
2288
2550
|
* @example
|
|
2289
2551
|
* ```typescript
|
|
2290
|
-
* // Preferred:
|
|
2291
|
-
* await sdk.
|
|
2552
|
+
* // Preferred: sendDeposit handles session onboarding for predeployed wallets
|
|
2553
|
+
* const sent = await sdk.sendDeposit(userAddress, 8453, amount, "USDC");
|
|
2554
|
+
* await sdk.waitForDepositCredit(sent.registration.id, 8453);
|
|
2292
2555
|
*
|
|
2293
2556
|
* // Legacy:
|
|
2294
2557
|
* const result = await sdk.createSessionKey(userAddress, 8453);
|
|
@@ -2369,7 +2632,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2369
2632
|
};
|
|
2370
2633
|
} catch (error) {
|
|
2371
2634
|
throw new Error(
|
|
2372
|
-
`Failed to create session key: ${error.message}. createSessionKey() is deprecated \u2014 prefer
|
|
2635
|
+
`Failed to create session key: ${error.message}. createSessionKey() is deprecated \u2014 prefer sendDeposit() for predeployed wallet onboarding.`
|
|
2373
2636
|
);
|
|
2374
2637
|
}
|
|
2375
2638
|
}
|
|
@@ -2436,34 +2699,46 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2436
2699
|
* asset/chain/strategy combo.
|
|
2437
2700
|
* 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
|
|
2438
2701
|
*
|
|
2439
|
-
* Called from `deploySafe` after every path, and from `
|
|
2702
|
+
* Called from `deploySafe` after every path, and from `sendDeposit` on
|
|
2440
2703
|
* the account's first deposit (when USDC chains are still empty).
|
|
2441
2704
|
*
|
|
2442
2705
|
* @internal
|
|
2443
2706
|
*/
|
|
2444
|
-
async updateUserProtocols(strategy) {
|
|
2707
|
+
async updateUserProtocols(strategy, options) {
|
|
2708
|
+
const strict = options?.strict ?? false;
|
|
2709
|
+
const assetErrors = [];
|
|
2445
2710
|
try {
|
|
2446
2711
|
const allProtocols = await this.httpClient.get(
|
|
2447
2712
|
ENDPOINTS.PROTOCOLS()
|
|
2448
2713
|
);
|
|
2449
|
-
const
|
|
2450
|
-
const assets = ["USDC", "WETH", "EURC"];
|
|
2451
|
-
for (const asset of assets) {
|
|
2714
|
+
for (const asset of MANAGED_ASSETS) {
|
|
2452
2715
|
try {
|
|
2453
|
-
const chainsForAsset = asset === "EURC" ? [1, 8453] : allChains;
|
|
2454
2716
|
await this.updateUserProtocolsForAsset(
|
|
2455
2717
|
asset,
|
|
2456
|
-
|
|
2718
|
+
getAssetChainIds(asset),
|
|
2457
2719
|
strategy,
|
|
2458
2720
|
allProtocols
|
|
2459
2721
|
);
|
|
2460
2722
|
} catch (assetError) {
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2723
|
+
const message = assetError.message;
|
|
2724
|
+
if (strict) {
|
|
2725
|
+
assetErrors.push(`${asset}: ${message}`);
|
|
2726
|
+
} else {
|
|
2727
|
+
console.warn(`Failed to update ${asset} protocols: ${message}`);
|
|
2728
|
+
}
|
|
2464
2729
|
}
|
|
2465
2730
|
}
|
|
2731
|
+
if (strict && assetErrors.length > 0) {
|
|
2732
|
+
throw new Error(
|
|
2733
|
+
`Failed to configure user protocols for first deposit: ${assetErrors.join(
|
|
2734
|
+
"; "
|
|
2735
|
+
)}`
|
|
2736
|
+
);
|
|
2737
|
+
}
|
|
2466
2738
|
} catch (error) {
|
|
2739
|
+
if (strict) {
|
|
2740
|
+
throw error;
|
|
2741
|
+
}
|
|
2467
2742
|
console.warn(
|
|
2468
2743
|
`Failed to update user protocols: ${error.message}`
|
|
2469
2744
|
);
|
|
@@ -2493,13 +2768,85 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2493
2768
|
asset,
|
|
2494
2769
|
internalStrategy
|
|
2495
2770
|
);
|
|
2496
|
-
await this.updateUserProfile({
|
|
2771
|
+
return await this.updateUserProfile({
|
|
2497
2772
|
asset,
|
|
2498
2773
|
protocols: withPools,
|
|
2499
2774
|
chains: effectiveChains,
|
|
2500
2775
|
...strategy !== void 0 && { strategy }
|
|
2501
2776
|
});
|
|
2502
2777
|
}
|
|
2778
|
+
/**
|
|
2779
|
+
* Switch one asset to a strategy and select the protocols that go with it.
|
|
2780
|
+
*
|
|
2781
|
+
* `updateUserProfile` stores a strategy but does not compute a protocol
|
|
2782
|
+
* list, so on its own it leaves the asset with nothing to deploy into. This
|
|
2783
|
+
* method does both in one call: it resolves the protocols that support the
|
|
2784
|
+
* asset on the requested chains under the requested strategy, drops those
|
|
2785
|
+
* with no pool available, and persists strategy, chains and protocols
|
|
2786
|
+
* together.
|
|
2787
|
+
*
|
|
2788
|
+
* Mostly needed for assets that are not set up by the account's first
|
|
2789
|
+
* deposit, or to change an existing account's strategy — `sendDeposit`
|
|
2790
|
+
* ignores its `strategy` argument after the first deposit.
|
|
2791
|
+
*
|
|
2792
|
+
* @param params.asset - Asset to configure
|
|
2793
|
+
* @param params.strategy - Strategy to apply; defaults to the one already
|
|
2794
|
+
* stored for this asset (`"conservative"` on a fresh account), which lets
|
|
2795
|
+
* you recompute a protocol list without changing the strategy
|
|
2796
|
+
* @param params.chains - Chains to enable. Defaults to every chain the asset
|
|
2797
|
+
* exists on. **Additive**: chains already enabled are kept, so this cannot
|
|
2798
|
+
* be used to disable one.
|
|
2799
|
+
* @group Portfolio and execution
|
|
2800
|
+
*
|
|
2801
|
+
* @returns The updated profile for that asset
|
|
2802
|
+
*
|
|
2803
|
+
* @example
|
|
2804
|
+
* ```typescript
|
|
2805
|
+
* // NVDAc only lives in async protocols, so it needs "yieldmaxxing".
|
|
2806
|
+
* // Chains default to Base, the only chain it exists on.
|
|
2807
|
+
* const profile = await sdk.setAssetStrategy({
|
|
2808
|
+
* asset: "NVDAc",
|
|
2809
|
+
* strategy: "yieldmaxxing",
|
|
2810
|
+
* });
|
|
2811
|
+
* console.log(profile.protocols); // Ipor + Superform
|
|
2812
|
+
* ```
|
|
2813
|
+
*/
|
|
2814
|
+
async setAssetStrategy(params) {
|
|
2815
|
+
const { asset, strategy, chains } = params;
|
|
2816
|
+
try {
|
|
2817
|
+
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
2818
|
+
throw new Error(
|
|
2819
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
2820
|
+
);
|
|
2821
|
+
}
|
|
2822
|
+
const supported = getAssetChainIds(asset);
|
|
2823
|
+
if (supported.length === 0) {
|
|
2824
|
+
throw new Error(`Unsupported asset: ${asset}.`);
|
|
2825
|
+
}
|
|
2826
|
+
const targetChains = chains ?? supported;
|
|
2827
|
+
const unsupported = targetChains.filter((c) => !supported.includes(c));
|
|
2828
|
+
if (unsupported.length > 0) {
|
|
2829
|
+
throw new Error(
|
|
2830
|
+
`${asset} is not available on chain ${unsupported.join(
|
|
2831
|
+
", "
|
|
2832
|
+
)}. Supported chains: ${supported.join(", ")}.`
|
|
2833
|
+
);
|
|
2834
|
+
}
|
|
2835
|
+
const allProtocols = await this.httpClient.get(
|
|
2836
|
+
ENDPOINTS.PROTOCOLS()
|
|
2837
|
+
);
|
|
2838
|
+
return await this.updateUserProtocolsForAsset(
|
|
2839
|
+
asset,
|
|
2840
|
+
targetChains,
|
|
2841
|
+
strategy,
|
|
2842
|
+
allProtocols
|
|
2843
|
+
);
|
|
2844
|
+
} catch (error) {
|
|
2845
|
+
throw new Error(
|
|
2846
|
+
`Failed to set ${asset} strategy: ${error.message}`
|
|
2847
|
+
);
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2503
2850
|
/**
|
|
2504
2851
|
* Drop protocols that have no pools on any of the selected chains for the
|
|
2505
2852
|
* requested asset. The /customization/pools endpoint filters server-side on
|
|
@@ -2554,55 +2901,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2554
2901
|
return value;
|
|
2555
2902
|
});
|
|
2556
2903
|
}
|
|
2557
|
-
/**
|
|
2558
|
-
* Deposit funds from EOA to Safe smart wallet
|
|
2559
|
-
* Transfers tokens from the connected wallet to the user's Safe and logs the deposit
|
|
2560
|
-
*
|
|
2561
|
-
* Token address is selected from `asset` for the given chain:
|
|
2562
|
-
* - Ethereum Mainnet (1), Base (8453), Arbitrum (42161): USDC or WETH
|
|
2563
|
-
* - Ethereum Mainnet (1), Base (8453): EURC
|
|
2564
|
-
*
|
|
2565
|
-
* On the account's first deposit (USDC profile has no chains yet), patches
|
|
2566
|
-
* protocol selection for USDC, WETH, and EURC across all supported chains
|
|
2567
|
-
* (EURC on Mainnet/Base only) before the transfer and log_deposit.
|
|
2568
|
-
* Pass `strategy` to select protocols for that first-deposit setup
|
|
2569
|
-
* (same role as the former `deploySafe` strategy argument). On every later
|
|
2570
|
-
* deposit the argument is ignored without error, since re-running the patch
|
|
2571
|
-
* would overwrite a protocol selection the user may have customised. To
|
|
2572
|
-
* change the strategy of an existing account, call
|
|
2573
|
-
* `updateUserProfile({ asset, strategy })`.
|
|
2574
|
-
*
|
|
2575
|
-
* Minimum portfolio balance enforced (Safe balance + deposit amount):
|
|
2576
|
-
* - Stablecoins: `MIN_PORTFOLIO_BALANCE` (Mainnet 10,000 USDC/EURC; Base/Arbitrum 100)
|
|
2577
|
-
* - WETH: about $10,000 on Mainnet, $100 on Base/Arbitrum, from Data API `/price?token=eth`
|
|
2578
|
-
*
|
|
2579
|
-
* @param userAddress - User's address (owner of the Safe)
|
|
2580
|
-
* @param chainId - Target chain ID
|
|
2581
|
-
* @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
|
|
2582
|
-
* @param asset - Asset symbol: "USDC", "WETH", or "EURC".
|
|
2583
|
-
* EURC is supported on Ethereum Mainnet and Base only.
|
|
2584
|
-
* @param strategy - Optional strategy for first-deposit protocol patching:
|
|
2585
|
-
* "conservative" (default), "aggressive" or "yieldmaxxing". Ignored on
|
|
2586
|
-
* later deposits — use `updateUserProfile` to change an existing account.
|
|
2587
|
-
* @returns Deposit response with transaction hash
|
|
2588
|
-
*
|
|
2589
|
-
* @example
|
|
2590
|
-
* ```typescript
|
|
2591
|
-
* // Deposit 10,000 USDC (6 decimals) to Safe on Base
|
|
2592
|
-
* const result = await sdk.depositFunds(
|
|
2593
|
-
* "0xUser...",
|
|
2594
|
-
* 8453,
|
|
2595
|
-
* "10000000000",
|
|
2596
|
-
* "USDC"
|
|
2597
|
-
* );
|
|
2598
|
-
*
|
|
2599
|
-
* // First deposit with aggressive strategy
|
|
2600
|
-
* await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
|
|
2601
|
-
*
|
|
2602
|
-
* // Changing the strategy of an account that has already deposited
|
|
2603
|
-
* await sdk.updateUserProfile({ asset: "USDC", strategy: "yieldmaxxing" });
|
|
2604
|
-
* ```
|
|
2605
|
-
*/
|
|
2606
2904
|
/**
|
|
2607
2905
|
* Deploy the connected predeployed (pool) wallet on one or more chains.
|
|
2608
2906
|
*
|
|
@@ -2613,11 +2911,20 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2613
2911
|
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
2614
2912
|
* already deployed are a no-op.
|
|
2615
2913
|
*
|
|
2616
|
-
* Optional for deposits: `
|
|
2914
|
+
* Optional for deposits: `sendDeposit` no longer pre-deploys the target chain — the ERC20
|
|
2617
2915
|
* transfer lands on the counterfactual address and the backend deploys + hands over on first
|
|
2618
2916
|
* deposit (report-deposit). Use this only to pre-provision chains ahead of time.
|
|
2619
2917
|
*
|
|
2620
|
-
* @
|
|
2918
|
+
* @group Deposits and withdrawals
|
|
2919
|
+
*
|
|
2920
|
+
* @param chainIds - Chain IDs to deploy the wallet on (e.g. `[1, 42161]`)
|
|
2921
|
+
* @returns Deployment summary from the execution API
|
|
2922
|
+
*
|
|
2923
|
+
* @throws If `chainIds` is empty or contains an unsupported chain
|
|
2924
|
+
*
|
|
2925
|
+
* @remarks
|
|
2926
|
+
* Requires {@link ZyfaiSDK.connectAccount} (SIWE). Optional ahead of deposits;
|
|
2927
|
+
* {@link ZyfaiSDK.sendDeposit} can deploy on first deposit for predeployed wallets.
|
|
2621
2928
|
*/
|
|
2622
2929
|
async deployOnChains(chainIds) {
|
|
2623
2930
|
if (!chainIds?.length) {
|
|
@@ -2629,7 +2936,36 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2629
2936
|
await this.authenticateUser();
|
|
2630
2937
|
return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
|
|
2631
2938
|
}
|
|
2632
|
-
|
|
2939
|
+
/**
|
|
2940
|
+
* Transfer funds from the connected EOA to the user's Safe and register the deposit.
|
|
2941
|
+
*
|
|
2942
|
+
* @remarks
|
|
2943
|
+
* Execution API + on-chain ERC-20 `transfer`. Confirms the transaction, then calls
|
|
2944
|
+
* {@link ZyfaiSDK.logDeposit}. Pair with {@link ZyfaiSDK.waitForDepositCredit} for
|
|
2945
|
+
* investable balance. Custom-wallet flows: {@link ZyfaiSDK.buildDepositTransfer},
|
|
2946
|
+
* {@link ZyfaiSDK.logDeposit}, {@link ZyfaiSDK.getDepositStatus}.
|
|
2947
|
+
*
|
|
2948
|
+
* Requires {@link ZyfaiSDK.connectAccount}. Pass the **EOA** as `userAddress`.
|
|
2949
|
+
*
|
|
2950
|
+
* @group Deposits and withdrawals
|
|
2951
|
+
*
|
|
2952
|
+
* @param userAddress - Owner EOA (not the Safe)
|
|
2953
|
+
* @param chainId - Chain for the transfer
|
|
2954
|
+
* @param amount - Amount in least units (string integer)
|
|
2955
|
+
* @param asset - Asset symbol (`USDC`, `WETH`, `EURC`, `NVDAc`)
|
|
2956
|
+
* @param strategy - Optional first-deposit {@link Strategy}
|
|
2957
|
+
* @returns Transfer receipt and deposit registration (not yet credited until polled)
|
|
2958
|
+
*
|
|
2959
|
+
* @throws If validation fails, minimum portfolio is not met, Safe is unavailable, or transfer/register fails
|
|
2960
|
+
*
|
|
2961
|
+
* @example
|
|
2962
|
+
* ```typescript
|
|
2963
|
+
* await sdk.connectAccount(provider);
|
|
2964
|
+
* const sent = await sdk.sendDeposit(eoa, 8453, "10000000", "USDC", "conservative");
|
|
2965
|
+
* await sdk.waitForDepositCredit(sent.registration.id, 8453);
|
|
2966
|
+
* ```
|
|
2967
|
+
*/
|
|
2968
|
+
async sendDeposit(userAddress, chainId, amount, asset, strategy) {
|
|
2633
2969
|
try {
|
|
2634
2970
|
if (!userAddress) {
|
|
2635
2971
|
throw new Error("User address is required");
|
|
@@ -2648,35 +2984,51 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2648
2984
|
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
2649
2985
|
);
|
|
2650
2986
|
}
|
|
2651
|
-
const assetSymbol = asset
|
|
2987
|
+
const assetSymbol = resolveAssetSymbol(asset);
|
|
2652
2988
|
const assetConfig = ASSET_CONFIGS[assetSymbol];
|
|
2653
|
-
|
|
2989
|
+
const assetChains = getAssetChainIds(assetSymbol);
|
|
2990
|
+
if (!assetChains.includes(chainId)) {
|
|
2654
2991
|
throw new Error(
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
let minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
|
|
2659
|
-
if (assetSymbol === "WETH") {
|
|
2660
|
-
const priceResponse = await this.httpClient.dataGet(
|
|
2661
|
-
DATA_ENDPOINTS.TOKEN_PRICE("eth")
|
|
2662
|
-
);
|
|
2663
|
-
minRequired = minWethWeiForUsd(
|
|
2664
|
-
parseEthUsdPrice(priceResponse),
|
|
2665
|
-
MIN_WETH_USD[chainId]
|
|
2992
|
+
`${assetSymbol} is not available on chain ${chainId}. Supported chains: ${assetChains.join(
|
|
2993
|
+
", "
|
|
2994
|
+
)}.`
|
|
2666
2995
|
);
|
|
2667
2996
|
}
|
|
2997
|
+
let minRequired = this.bypassMinPortfolio ? void 0 : MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
|
|
2998
|
+
const minUsd = this.bypassMinPortfolio ? void 0 : MIN_PORTFOLIO_USD[chainId]?.[assetSymbol];
|
|
2668
2999
|
const token = getDefaultTokenAddress(chainId, assetSymbol);
|
|
2669
3000
|
const walletClient = this.getWalletClient();
|
|
2670
|
-
await this.authenticateUser();
|
|
2671
3001
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
3002
|
+
if (minUsd !== void 0) {
|
|
3003
|
+
const [, priceResponse] = await Promise.all([
|
|
3004
|
+
this.authenticateUser(),
|
|
3005
|
+
this.httpClient.dataGet(
|
|
3006
|
+
DATA_ENDPOINTS.TOKEN_PRICE(assetConfig.priceTokenSymbol)
|
|
3007
|
+
)
|
|
3008
|
+
]);
|
|
3009
|
+
minRequired = usdToTokenUnits(
|
|
3010
|
+
minUsd,
|
|
3011
|
+
parseTokenUsdPrice(priceResponse),
|
|
3012
|
+
assetConfig.decimals
|
|
3013
|
+
);
|
|
3014
|
+
} else {
|
|
3015
|
+
await this.authenticateUser();
|
|
3016
|
+
}
|
|
2672
3017
|
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
2673
3018
|
if (!safeAddress) {
|
|
2674
3019
|
throw new Error("Smart wallet address is not available");
|
|
2675
3020
|
}
|
|
2676
|
-
const
|
|
2677
|
-
|
|
2678
|
-
chainConfig.publicClient
|
|
2679
|
-
|
|
3021
|
+
const amountBigInt = BigInt(amount);
|
|
3022
|
+
const [isDeployed, currentSafeBalance] = await Promise.all([
|
|
3023
|
+
isSafeDeployed(safeAddress, chainConfig.publicClient),
|
|
3024
|
+
minRequired !== void 0 ? chainConfig.publicClient.readContract({
|
|
3025
|
+
address: token,
|
|
3026
|
+
abi: ERC20_ABI,
|
|
3027
|
+
functionName: "balanceOf",
|
|
3028
|
+
args: [safeAddress]
|
|
3029
|
+
}) : Promise.resolve(void 0),
|
|
3030
|
+
this.prepareFirstDeposit(strategy)
|
|
3031
|
+
]).then(([deployed, balance]) => [deployed, balance]);
|
|
2680
3032
|
if (!isDeployed) {
|
|
2681
3033
|
if (!(this.isPredeployed && this.isConnectedUser(userAddress))) {
|
|
2682
3034
|
throw new Error(
|
|
@@ -2684,26 +3036,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2684
3036
|
);
|
|
2685
3037
|
}
|
|
2686
3038
|
}
|
|
2687
|
-
try {
|
|
2688
|
-
const usdcDetails = await this.getUserDetails("USDC");
|
|
2689
|
-
if ((usdcDetails.chains?.length ?? 0) === 0) {
|
|
2690
|
-
await this.updateUserProtocols(strategy);
|
|
2691
|
-
}
|
|
2692
|
-
} catch (protocolError) {
|
|
2693
|
-
console.warn(
|
|
2694
|
-
"Failed to update user protocols before deposit:",
|
|
2695
|
-
protocolError.message
|
|
2696
|
-
);
|
|
2697
|
-
}
|
|
2698
|
-
const amountBigInt = BigInt(amount);
|
|
2699
3039
|
if (minRequired !== void 0) {
|
|
2700
|
-
const
|
|
2701
|
-
|
|
2702
|
-
abi: ERC20_ABI,
|
|
2703
|
-
functionName: "balanceOf",
|
|
2704
|
-
args: [safeAddress]
|
|
2705
|
-
});
|
|
2706
|
-
const totalAfterDeposit = currentSafeBalance + amountBigInt;
|
|
3040
|
+
const safeBalance = currentSafeBalance;
|
|
3041
|
+
const totalAfterDeposit = safeBalance + amountBigInt;
|
|
2707
3042
|
if (totalAfterDeposit < minRequired) {
|
|
2708
3043
|
const minLabel = formatMinPortfolioLabel(
|
|
2709
3044
|
minRequired,
|
|
@@ -2711,7 +3046,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2711
3046
|
assetSymbol
|
|
2712
3047
|
);
|
|
2713
3048
|
throw new Error(
|
|
2714
|
-
`Minimum portfolio balance not met on chain ${chainId}. Total portfolio must be at least ${minLabel}. Current Safe balance: ${
|
|
3049
|
+
`Minimum portfolio balance not met on chain ${chainId}. Total portfolio must be at least ${minLabel}. Current Safe balance: ${safeBalance.toString()}, deposit amount: ${amountBigInt.toString()}, total after deposit: ${totalAfterDeposit.toString()} (raw units, ${assetConfig.decimals} decimals).`
|
|
2715
3050
|
);
|
|
2716
3051
|
}
|
|
2717
3052
|
}
|
|
@@ -2729,27 +3064,254 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2729
3064
|
if (receipt.status !== "success") {
|
|
2730
3065
|
throw new Error("Deposit transaction failed");
|
|
2731
3066
|
}
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
}
|
|
3067
|
+
const registration = await this.registerDeposit(
|
|
3068
|
+
chainId,
|
|
3069
|
+
txHash,
|
|
3070
|
+
amount,
|
|
3071
|
+
token
|
|
3072
|
+
);
|
|
2739
3073
|
return {
|
|
2740
3074
|
success: true,
|
|
2741
3075
|
txHash,
|
|
2742
3076
|
smartWallet: safeAddress,
|
|
2743
|
-
amount: amountBigInt.toString()
|
|
3077
|
+
amount: amountBigInt.toString(),
|
|
3078
|
+
registration
|
|
2744
3079
|
};
|
|
2745
3080
|
} catch (error) {
|
|
2746
3081
|
throw new Error(`Deposit failed: ${error.message}`);
|
|
2747
3082
|
}
|
|
2748
3083
|
}
|
|
3084
|
+
/**
|
|
3085
|
+
* @deprecated Compatibility convenience method. Prefer {@link ZyfaiSDK.sendDeposit} followed by
|
|
3086
|
+
* {@link ZyfaiSDK.waitForDepositCredit} when the caller owns the completion UX.
|
|
3087
|
+
*
|
|
3088
|
+
* @see {@link ZyfaiSDK.sendDeposit}
|
|
3089
|
+
*
|
|
3090
|
+
* @group Deposits and withdrawals
|
|
3091
|
+
*/
|
|
3092
|
+
async depositFunds(userAddress, chainId, amount, asset, strategy) {
|
|
3093
|
+
this.warnDeprecatedOnboardingMethod("depositFunds");
|
|
3094
|
+
const sent = await this.sendDeposit(
|
|
3095
|
+
userAddress,
|
|
3096
|
+
chainId,
|
|
3097
|
+
amount,
|
|
3098
|
+
asset,
|
|
3099
|
+
strategy
|
|
3100
|
+
);
|
|
3101
|
+
return {
|
|
3102
|
+
...sent,
|
|
3103
|
+
registration: await this.waitForDepositCredit(
|
|
3104
|
+
sent.registration.id,
|
|
3105
|
+
chainId
|
|
3106
|
+
)
|
|
3107
|
+
};
|
|
3108
|
+
}
|
|
3109
|
+
/**
|
|
3110
|
+
* Build ERC-20 transfer calldata for a custom signer or sponsored tx flow.
|
|
3111
|
+
*
|
|
3112
|
+
* @remarks
|
|
3113
|
+
* Compose with {@link ZyfaiSDK.ensureFirstDepositSetup}, submit the transfer, then
|
|
3114
|
+
* {@link ZyfaiSDK.logDeposit} and {@link ZyfaiSDK.waitForDepositCredit}.
|
|
3115
|
+
*
|
|
3116
|
+
* @group Deposits and withdrawals
|
|
3117
|
+
*
|
|
3118
|
+
* @param params.userAddress - Owner EOA
|
|
3119
|
+
* @param params.chainId - Target chain
|
|
3120
|
+
* @param params.amount - Least units (string integer)
|
|
3121
|
+
* @param params.asset - {@link SupportedAsset}
|
|
3122
|
+
* @returns Safe address, token, and encoded `transfer` calldata
|
|
3123
|
+
*
|
|
3124
|
+
* @throws If inputs are invalid or the Safe address cannot be resolved
|
|
3125
|
+
*/
|
|
3126
|
+
async buildDepositTransfer(params) {
|
|
3127
|
+
const { userAddress, chainId, amount, asset } = params;
|
|
3128
|
+
if (!userAddress || !amount || BigInt(amount) <= 0n) {
|
|
3129
|
+
throw new Error("A user address and positive amount are required");
|
|
3130
|
+
}
|
|
3131
|
+
if (!isSupportedChain(chainId)) {
|
|
3132
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
3133
|
+
}
|
|
3134
|
+
const assetSymbol = resolveAssetSymbol(asset);
|
|
3135
|
+
const assetChains = getAssetChainIds(assetSymbol);
|
|
3136
|
+
if (!assetChains.includes(chainId)) {
|
|
3137
|
+
throw new Error(
|
|
3138
|
+
`${assetSymbol} is not available on chain ${chainId}. Supported chains: ${assetChains.join(
|
|
3139
|
+
", "
|
|
3140
|
+
)}.`
|
|
3141
|
+
);
|
|
3142
|
+
}
|
|
3143
|
+
const safeAddress = await this.getSafeAddressFor(userAddress, chainId);
|
|
3144
|
+
if (!safeAddress) {
|
|
3145
|
+
throw new Error("Smart wallet address is not available");
|
|
3146
|
+
}
|
|
3147
|
+
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
3148
|
+
const isDeployed = await isSafeDeployed(
|
|
3149
|
+
safeAddress,
|
|
3150
|
+
chainConfig.publicClient
|
|
3151
|
+
);
|
|
3152
|
+
if (!(isDeployed || this.isPredeployed && this.isConnectedUser(userAddress))) {
|
|
3153
|
+
throw new Error(
|
|
3154
|
+
`Safe not available for ${userAddress} on chain ${chainId}.`
|
|
3155
|
+
);
|
|
3156
|
+
}
|
|
3157
|
+
const amountBigInt = BigInt(amount);
|
|
3158
|
+
await this.enforceMinimumPortfolioBalance(
|
|
3159
|
+
chainId,
|
|
3160
|
+
asset,
|
|
3161
|
+
amountBigInt,
|
|
3162
|
+
safeAddress
|
|
3163
|
+
);
|
|
3164
|
+
const tokenAddress = getDefaultTokenAddress(
|
|
3165
|
+
chainId,
|
|
3166
|
+
assetSymbol
|
|
3167
|
+
);
|
|
3168
|
+
return {
|
|
3169
|
+
safeAddress,
|
|
3170
|
+
tokenAddress,
|
|
3171
|
+
to: tokenAddress,
|
|
3172
|
+
data: encodeFunctionData({
|
|
3173
|
+
abi: ERC20_ABI,
|
|
3174
|
+
functionName: "transfer",
|
|
3175
|
+
args: [safeAddress, amountBigInt]
|
|
3176
|
+
}),
|
|
3177
|
+
value: "0"
|
|
3178
|
+
};
|
|
3179
|
+
}
|
|
3180
|
+
/** Apply the same per-asset minimum portfolio rule as sendDeposit. */
|
|
3181
|
+
async enforceMinimumPortfolioBalance(chainId, asset, amount, safeAddress) {
|
|
3182
|
+
if (this.bypassMinPortfolio) {
|
|
3183
|
+
return;
|
|
3184
|
+
}
|
|
3185
|
+
const assetSymbol = resolveAssetSymbol(asset);
|
|
3186
|
+
const assetConfig = ASSET_CONFIGS[assetSymbol];
|
|
3187
|
+
let minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
|
|
3188
|
+
const minUsd = MIN_PORTFOLIO_USD[chainId]?.[assetSymbol];
|
|
3189
|
+
if (minUsd !== void 0) {
|
|
3190
|
+
const [, priceResponse] = await Promise.all([
|
|
3191
|
+
this.authenticateUser(),
|
|
3192
|
+
this.httpClient.dataGet(
|
|
3193
|
+
DATA_ENDPOINTS.TOKEN_PRICE(assetConfig.priceTokenSymbol)
|
|
3194
|
+
)
|
|
3195
|
+
]);
|
|
3196
|
+
minRequired = usdToTokenUnits(
|
|
3197
|
+
minUsd,
|
|
3198
|
+
parseTokenUsdPrice(priceResponse),
|
|
3199
|
+
assetConfig.decimals
|
|
3200
|
+
);
|
|
3201
|
+
}
|
|
3202
|
+
if (minRequired === void 0) return;
|
|
3203
|
+
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
3204
|
+
const token = getDefaultTokenAddress(chainId, assetSymbol);
|
|
3205
|
+
const currentSafeBalance = await chainConfig.publicClient.readContract({
|
|
3206
|
+
address: token,
|
|
3207
|
+
abi: ERC20_ABI,
|
|
3208
|
+
functionName: "balanceOf",
|
|
3209
|
+
args: [safeAddress]
|
|
3210
|
+
});
|
|
3211
|
+
const totalAfterDeposit = currentSafeBalance + amount;
|
|
3212
|
+
if (totalAfterDeposit < minRequired) {
|
|
3213
|
+
const minLabel = formatMinPortfolioLabel(
|
|
3214
|
+
minRequired,
|
|
3215
|
+
assetConfig.decimals,
|
|
3216
|
+
assetSymbol
|
|
3217
|
+
);
|
|
3218
|
+
throw new Error(
|
|
3219
|
+
`Minimum portfolio balance not met on chain ${chainId}. Total portfolio must be at least ${minLabel}. Current Safe balance: ${currentSafeBalance.toString()}, deposit amount: ${amount.toString()}, total after deposit: ${totalAfterDeposit.toString()} (raw units, ${assetConfig.decimals} decimals).`
|
|
3220
|
+
);
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
/**
|
|
3224
|
+
* Idempotently apply the first-deposit profile configuration for builders
|
|
3225
|
+
* composing an advanced custom transfer flow. Most custom-wallet
|
|
3226
|
+
* integrations can use this with `buildDepositTransfer()` and `logDeposit()`.
|
|
3227
|
+
*
|
|
3228
|
+
* When setup runs (`applied: true`), protocol configuration is persisted
|
|
3229
|
+
* before returning. Failures throw so callers can abort before submitting a
|
|
3230
|
+
* transfer. High-level deposit methods still treat setup as best-effort.
|
|
3231
|
+
*
|
|
3232
|
+
* @group Deposits and withdrawals
|
|
3233
|
+
*
|
|
3234
|
+
* @param strategy - Optional first-deposit {@link Strategy}
|
|
3235
|
+
* @returns `{ applied: true }` when chain/protocol config was written; `false` if already configured
|
|
3236
|
+
*
|
|
3237
|
+
* @throws If strategy is invalid or setup did not persist
|
|
3238
|
+
*/
|
|
3239
|
+
async ensureFirstDepositSetup(strategy) {
|
|
3240
|
+
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
3241
|
+
throw new Error(
|
|
3242
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
3243
|
+
);
|
|
3244
|
+
}
|
|
3245
|
+
await this.authenticateUser();
|
|
3246
|
+
const usdcDetails = await this.getUserDetails("USDC");
|
|
3247
|
+
if ((usdcDetails.chains?.length ?? 0) > 0) {
|
|
3248
|
+
return { applied: false };
|
|
3249
|
+
}
|
|
3250
|
+
await this.updateUserProtocols(strategy, { strict: true });
|
|
3251
|
+
const usdcAfterSetup = await this.getUserDetails("USDC");
|
|
3252
|
+
if ((usdcAfterSetup.chains?.length ?? 0) === 0) {
|
|
3253
|
+
throw new Error(
|
|
3254
|
+
"First-deposit setup did not persist USDC chain configuration."
|
|
3255
|
+
);
|
|
3256
|
+
}
|
|
3257
|
+
return { applied: true };
|
|
3258
|
+
}
|
|
3259
|
+
/**
|
|
3260
|
+
* Prepare entering a position: persist first-deposit profile when needed and
|
|
3261
|
+
* return ERC-20 transfer calldata for the user to sign (does not broadcast).
|
|
3262
|
+
*
|
|
3263
|
+
* @group Deposits and withdrawals
|
|
3264
|
+
*/
|
|
3265
|
+
async prepareEnterPosition(params) {
|
|
3266
|
+
const { userAddress, chainId, amount, asset, strategy } = params;
|
|
3267
|
+
if (this.sessionEoa && getAddress2(userAddress) !== this.sessionEoa) {
|
|
3268
|
+
throw new Error("userAddress does not match authenticated session EOA");
|
|
3269
|
+
}
|
|
3270
|
+
const setup = await this.ensureFirstDepositSetup(strategy);
|
|
3271
|
+
const transfer = await this.buildDepositTransfer({
|
|
3272
|
+
userAddress,
|
|
3273
|
+
chainId,
|
|
3274
|
+
amount,
|
|
3275
|
+
asset
|
|
3276
|
+
});
|
|
3277
|
+
return {
|
|
3278
|
+
phase: "prepare_transfer",
|
|
3279
|
+
setup,
|
|
3280
|
+
transfer
|
|
3281
|
+
};
|
|
3282
|
+
}
|
|
3283
|
+
/** Best-effort first-deposit setup shared by both high-level deposit flows. */
|
|
3284
|
+
async prepareFirstDeposit(strategy) {
|
|
3285
|
+
try {
|
|
3286
|
+
await this.ensureFirstDepositSetup(strategy);
|
|
3287
|
+
} catch (protocolError) {
|
|
3288
|
+
console.warn(
|
|
3289
|
+
"Failed to update user protocols before deposit:",
|
|
3290
|
+
protocolError.message
|
|
3291
|
+
);
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
/** Shared post-transfer registration path for every deposit flow. */
|
|
3295
|
+
async registerDeposit(chainId, txHash, amount, tokenAddress) {
|
|
3296
|
+
let registration;
|
|
3297
|
+
try {
|
|
3298
|
+
registration = await this.logDeposit(
|
|
3299
|
+
chainId,
|
|
3300
|
+
txHash,
|
|
3301
|
+
amount,
|
|
3302
|
+
tokenAddress
|
|
3303
|
+
);
|
|
3304
|
+
} catch (logError) {
|
|
3305
|
+
throw new Error(
|
|
3306
|
+
`On-chain deposit succeeded (tx=${txHash}) but backend registration failed: ${logError.message}. Call connectAccount() then logDeposit(${chainId}, "${txHash}", "${amount}") to retry.`
|
|
3307
|
+
);
|
|
3308
|
+
}
|
|
3309
|
+
return registration.deposit;
|
|
3310
|
+
}
|
|
2749
3311
|
/**
|
|
2750
3312
|
* Log a deposit that was executed client-side.
|
|
2751
3313
|
*
|
|
2752
|
-
* `
|
|
3314
|
+
* `sendDeposit()` already calls this after the ERC20 transfer. If you send the
|
|
2753
3315
|
* transfer yourself (front, Privy, Biconomy, custom wallet) you **must** call
|
|
2754
3316
|
* `logDeposit` — otherwise the backend never sees the deposit: a reserved pool
|
|
2755
3317
|
* wallet stays reserved (no ownership rotation), and yield/agent tracking does
|
|
@@ -2773,8 +3335,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2773
3335
|
* @param chainId - Chain ID where the deposit was made
|
|
2774
3336
|
* @param txHash - Transaction hash of the deposit
|
|
2775
3337
|
* @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
|
|
2776
|
-
* @param tokenAddress - Optional
|
|
2777
|
-
* @returns Log deposit response with
|
|
3338
|
+
* @param tokenAddress - Optional token contract (defaults per chain)
|
|
3339
|
+
* @returns Log deposit response with lifecycle record
|
|
3340
|
+
*
|
|
3341
|
+
* @group Deposits and withdrawals
|
|
3342
|
+
*
|
|
3343
|
+
* @throws If inputs are invalid or the execution API rejects registration
|
|
2778
3344
|
*
|
|
2779
3345
|
* @example
|
|
2780
3346
|
* ```typescript
|
|
@@ -2806,20 +3372,97 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2806
3372
|
}
|
|
2807
3373
|
const token = tokenAddress || getDefaultTokenAddress(chainId);
|
|
2808
3374
|
await this.authenticateUser();
|
|
2809
|
-
await this.httpClient.post(
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
3375
|
+
const deposit = await this.httpClient.post(
|
|
3376
|
+
ENDPOINTS.LOG_DEPOSIT,
|
|
3377
|
+
{
|
|
3378
|
+
chainId,
|
|
3379
|
+
transaction: txHash,
|
|
3380
|
+
token,
|
|
3381
|
+
amount
|
|
3382
|
+
}
|
|
3383
|
+
);
|
|
2815
3384
|
return {
|
|
2816
3385
|
success: true,
|
|
2817
|
-
message: "Deposit
|
|
3386
|
+
message: deposit.status === "credited" ? "Deposit credited successfully" : "Deposit accepted; custody handover is pending",
|
|
3387
|
+
deposit
|
|
2818
3388
|
};
|
|
2819
3389
|
} catch (error) {
|
|
2820
3390
|
throw new Error(`Log deposit failed: ${error.message}`);
|
|
2821
3391
|
}
|
|
2822
3392
|
}
|
|
3393
|
+
/**
|
|
3394
|
+
* Fetch custody handover and balance-credit status for a registered deposit.
|
|
3395
|
+
*
|
|
3396
|
+
* @remarks
|
|
3397
|
+
* `status === "credited"` with `balanceCredited === true` means funds are investable.
|
|
3398
|
+
* Requires {@link ZyfaiSDK.connectAccount} (SIWE).
|
|
3399
|
+
*
|
|
3400
|
+
* @group Deposits and withdrawals
|
|
3401
|
+
*
|
|
3402
|
+
* @param depositId - Id from {@link LogDepositResponse} / {@link DepositResponse.registration}
|
|
3403
|
+
* @returns {@link DepositLifecycleResponse}
|
|
3404
|
+
*
|
|
3405
|
+
* @throws If `depositId` is missing
|
|
3406
|
+
*/
|
|
3407
|
+
async getDepositStatus(depositId) {
|
|
3408
|
+
if (!depositId) {
|
|
3409
|
+
throw new Error("Deposit ID is required");
|
|
3410
|
+
}
|
|
3411
|
+
await this.authenticateUser();
|
|
3412
|
+
return this.httpClient.get(
|
|
3413
|
+
ENDPOINTS.DEPOSIT_STATUS(depositId)
|
|
3414
|
+
);
|
|
3415
|
+
}
|
|
3416
|
+
/**
|
|
3417
|
+
* Await deposit credit after `logDeposit` returns `handover_pending`.
|
|
3418
|
+
*
|
|
3419
|
+
* Polls `getDepositStatus` until `status === "credited"` and
|
|
3420
|
+
* `balanceCredited === true`. Rejects on recovery, timeout, or poll errors.
|
|
3421
|
+
*
|
|
3422
|
+
* Poll interval and timeout are chain-specific. Mainnet defaults to a 2s
|
|
3423
|
+
* interval and 1 minute ceiling; Base/Arbitrum use tighter polling (~500ms /
|
|
3424
|
+
* ~250ms) with a ~20 second completion window. Override `timeoutMs` when a
|
|
3425
|
+
* caller intentionally wants to wait longer than the normal UX window.
|
|
3426
|
+
*
|
|
3427
|
+
* Requires {@link ZyfaiSDK.connectAccount} on the same SDK instance.
|
|
3428
|
+
*
|
|
3429
|
+
* @group Deposits and withdrawals
|
|
3430
|
+
*
|
|
3431
|
+
* @param depositId - Deposit lifecycle id
|
|
3432
|
+
* @param chainId - Chain (controls poll interval and default timeout)
|
|
3433
|
+
* @param options - Optional `intervalMs` and `timeoutMs` overrides
|
|
3434
|
+
* @returns Final lifecycle record when credited
|
|
3435
|
+
*
|
|
3436
|
+
* @throws `DepositCreditTimeoutError` when the poll window elapses without credit
|
|
3437
|
+
* @throws If deposit recovers to EOA or polling fails
|
|
3438
|
+
*/
|
|
3439
|
+
async waitForDepositCredit(depositId, chainId, options) {
|
|
3440
|
+
if (!depositId) {
|
|
3441
|
+
throw new Error("Deposit ID is required");
|
|
3442
|
+
}
|
|
3443
|
+
if (!isSupportedChain(chainId)) {
|
|
3444
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
3445
|
+
}
|
|
3446
|
+
const intervalMs = options?.intervalMs ?? getDepositCreditIntervalMs(chainId);
|
|
3447
|
+
const timeoutMs = options?.timeoutMs ?? getDepositCreditTimeoutMs(chainId);
|
|
3448
|
+
const started = Date.now();
|
|
3449
|
+
while (Date.now() - started < timeoutMs) {
|
|
3450
|
+
const status = await this.getDepositStatus(depositId);
|
|
3451
|
+
if (status.status === "credited" && status.balanceCredited) {
|
|
3452
|
+
return status;
|
|
3453
|
+
}
|
|
3454
|
+
if (status.status === "recovered_to_eoa") {
|
|
3455
|
+
throw new Error(
|
|
3456
|
+
`Deposit ${depositId} recovered to EOA (status=${status.status}); balance was not credited`
|
|
3457
|
+
);
|
|
3458
|
+
}
|
|
3459
|
+
if (Date.now() - started >= timeoutMs) {
|
|
3460
|
+
break;
|
|
3461
|
+
}
|
|
3462
|
+
await sleep(intervalMs);
|
|
3463
|
+
}
|
|
3464
|
+
throw new DepositCreditTimeoutError(depositId);
|
|
3465
|
+
}
|
|
2823
3466
|
/**
|
|
2824
3467
|
* Withdraw funds from Safe smart wallet
|
|
2825
3468
|
* Initiates a withdrawal request to the Zyfai API
|
|
@@ -2839,6 +3482,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2839
3482
|
* When every source is an async pool nothing settles on-chain at that point,
|
|
2840
3483
|
* so `txHash` is `undefined` on a successful call.
|
|
2841
3484
|
*
|
|
3485
|
+
* **One redemption per pool at a time.** While an entry for a pool is
|
|
3486
|
+
* `REQUESTED` or `CLAIMABLE`, the backend drops a further withdrawal aimed at
|
|
3487
|
+
* that same pool — the protocols behind it (ERC-7540) hold a single request
|
|
3488
|
+
* slot per user. This method throws rather than reporting that no-op as a
|
|
3489
|
+
* success. It only throws when nothing the call could reach is withdrawable:
|
|
3490
|
+
* another pool, another asset or an idle Safe balance still goes through.
|
|
3491
|
+
*
|
|
2842
3492
|
* Once requested, that amount can no longer be withdrawn: it is gone from
|
|
2843
3493
|
* both the position snapshot and the Safe balance, so a second call silently
|
|
2844
3494
|
* returns only what is left. Validate user-entered amounts against
|
|
@@ -2847,8 +3497,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2847
3497
|
*
|
|
2848
3498
|
* @param userAddress - User's address (owner of the Safe)
|
|
2849
3499
|
* @param chainId - Target chain ID
|
|
2850
|
-
* @param amount - Optional
|
|
2851
|
-
* @
|
|
3500
|
+
* @param amount - Optional amount in least units (partial withdrawal); omit for full withdraw
|
|
3501
|
+
* @param tokenSymbol - Optional asset symbol when withdrawing a specific token
|
|
3502
|
+
* @returns Withdraw response with message and optional transaction hash
|
|
3503
|
+
*
|
|
3504
|
+
* @group Deposits and withdrawals
|
|
3505
|
+
*
|
|
3506
|
+
* @throws If `userAddress` or `chainId` is invalid, or the execution API rejects the request
|
|
2852
3507
|
*
|
|
2853
3508
|
* @example
|
|
2854
3509
|
* ```typescript
|
|
@@ -2887,6 +3542,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2887
3542
|
);
|
|
2888
3543
|
}
|
|
2889
3544
|
await this.authenticateUser();
|
|
3545
|
+
await this.assertAsyncRedemptionSlotFree(
|
|
3546
|
+
userAddress,
|
|
3547
|
+
chainId,
|
|
3548
|
+
tokenSymbol
|
|
3549
|
+
);
|
|
2890
3550
|
let response = {};
|
|
2891
3551
|
if (amount) {
|
|
2892
3552
|
response = await this.httpClient.post(ENDPOINTS.PARTIAL_WITHDRAW, {
|
|
@@ -2915,11 +3575,42 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2915
3575
|
}
|
|
2916
3576
|
}
|
|
2917
3577
|
/**
|
|
2918
|
-
*
|
|
3578
|
+
* Turn a withdrawal the backend would silently drop — one aimed only at
|
|
3579
|
+
* async pools that already hold an in-flight redemption — into an error, so
|
|
3580
|
+
* the caller gets an answer rather than a `success: true` no-op.
|
|
3581
|
+
*
|
|
3582
|
+
* @internal
|
|
3583
|
+
*/
|
|
3584
|
+
async assertAsyncRedemptionSlotFree(userAddress, chainId, tokenSymbol) {
|
|
3585
|
+
let portfolio;
|
|
3586
|
+
try {
|
|
3587
|
+
({ portfolio } = await this.getPortfolio(userAddress));
|
|
3588
|
+
} catch {
|
|
3589
|
+
return;
|
|
3590
|
+
}
|
|
3591
|
+
const blocking = findBlockingAsyncRedemption(
|
|
3592
|
+
portfolio,
|
|
3593
|
+
chainId,
|
|
3594
|
+
tokenSymbol
|
|
3595
|
+
);
|
|
3596
|
+
if (!blocking) return;
|
|
3597
|
+
const eta = blocking.estimatedClaimAt ? ` Estimated settlement: ${blocking.estimatedClaimAt}.` : "";
|
|
3598
|
+
throw new Error(
|
|
3599
|
+
`A redemption is already in flight for ${blocking.token?.symbol ?? "this asset"} on ${blocking.pool ?? "the pool"} (status ${blocking.status}), and async pools allow only one at a time. Wait for it to reach CLAIMED before withdrawing the rest.${eta}`
|
|
3600
|
+
);
|
|
3601
|
+
}
|
|
3602
|
+
/**
|
|
3603
|
+
* Get available DeFi protocols and pools for a specific chain.
|
|
3604
|
+
*
|
|
3605
|
+
* @group Portfolio and execution
|
|
3606
|
+
*
|
|
3607
|
+
* @remarks Execution API. Partner API key only.
|
|
2919
3608
|
*
|
|
2920
3609
|
* @param chainId - Target chain ID
|
|
2921
3610
|
* @returns List of available protocols with their pools and APY data
|
|
2922
3611
|
*
|
|
3612
|
+
* @throws If `chainId` is unsupported
|
|
3613
|
+
*
|
|
2923
3614
|
* @example
|
|
2924
3615
|
* ```typescript
|
|
2925
3616
|
* const protocols = await sdk.getAvailableProtocols(8453);
|
|
@@ -2948,11 +3639,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2948
3639
|
}
|
|
2949
3640
|
}
|
|
2950
3641
|
/**
|
|
2951
|
-
* Get
|
|
3642
|
+
* Get active DeFi positions for a user.
|
|
3643
|
+
*
|
|
3644
|
+
* @group Portfolio and execution
|
|
3645
|
+
*
|
|
3646
|
+
* @remarks Execution API (`/data/position`). Pass the **EOA**; the SDK resolves the Safe.
|
|
2952
3647
|
*
|
|
2953
3648
|
* @param userAddress - User's EOA address
|
|
2954
|
-
* @param chainId -
|
|
2955
|
-
* @returns User's positions across
|
|
3649
|
+
* @param chainId - Chain used to resolve the Safe (defaults to Base `8453`)
|
|
3650
|
+
* @returns User's positions across protocols
|
|
2956
3651
|
*
|
|
2957
3652
|
* @example
|
|
2958
3653
|
* ```typescript
|
|
@@ -3032,9 +3727,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3032
3727
|
* Do not add `CLAIMED` withdrawals either (the array keeps them for 24
|
|
3033
3728
|
* hours); their funds are back in the Safe and already counted.
|
|
3034
3729
|
*
|
|
3730
|
+
* @group Portfolio and execution
|
|
3731
|
+
*
|
|
3732
|
+
* @remarks Data API portfolio endpoint. See {@link PortfolioDetailed.pendingAsyncWithdrawals}
|
|
3733
|
+
* when using {@link Strategy | yieldmaxxing}.
|
|
3734
|
+
*
|
|
3035
3735
|
* @param userAddress - User's EOA address
|
|
3036
3736
|
* @returns Portfolio with optional fee-adjusted balance fields
|
|
3037
3737
|
*
|
|
3738
|
+
* @throws If `userAddress` is missing
|
|
3739
|
+
*
|
|
3038
3740
|
* @example
|
|
3039
3741
|
* ```typescript
|
|
3040
3742
|
* const { portfolio } = await sdk.getPortfolio(userAddress);
|
|
@@ -3089,10 +3791,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3089
3791
|
// User Details Methods
|
|
3090
3792
|
// ============================================================================
|
|
3091
3793
|
/**
|
|
3092
|
-
* Get
|
|
3093
|
-
*
|
|
3794
|
+
* Get the authenticated user's profile for an asset.
|
|
3795
|
+
*
|
|
3796
|
+
* @group Portfolio and execution
|
|
3797
|
+
*
|
|
3798
|
+
* @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
|
|
3094
3799
|
*
|
|
3095
|
-
* @
|
|
3800
|
+
* @param asset - Asset slice of the profile to return
|
|
3801
|
+
* @defaultValue `"USDC"`
|
|
3802
|
+
* @returns User details including smart wallet, chains, and protocols
|
|
3096
3803
|
*
|
|
3097
3804
|
* @example
|
|
3098
3805
|
* ```typescript
|
|
@@ -3139,9 +3846,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3139
3846
|
// TVL & Volume Methods
|
|
3140
3847
|
// ============================================================================
|
|
3141
3848
|
/**
|
|
3142
|
-
* Get total value locked (TVL) across all Zyfai accounts
|
|
3849
|
+
* Get total value locked (TVL) across all Zyfai accounts.
|
|
3143
3850
|
*
|
|
3144
|
-
* @
|
|
3851
|
+
* @group Analytics and opportunities
|
|
3852
|
+
*
|
|
3853
|
+
* @remarks Data API. Partner API key only; SIWE not required.
|
|
3854
|
+
*
|
|
3855
|
+
* @returns Total TVL in USD
|
|
3145
3856
|
*
|
|
3146
3857
|
* @example
|
|
3147
3858
|
* ```typescript
|
|
@@ -3164,7 +3875,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3164
3875
|
// APY Per Strategy Methods
|
|
3165
3876
|
// ============================================================================
|
|
3166
3877
|
/**
|
|
3167
|
-
* Get APY per strategy for a specific chain
|
|
3878
|
+
* Get APY per strategy for a specific chain.
|
|
3879
|
+
*
|
|
3880
|
+
* @group Analytics and opportunities
|
|
3881
|
+
*
|
|
3882
|
+
* @remarks Data API. Partner API key only.
|
|
3168
3883
|
*
|
|
3169
3884
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
3170
3885
|
* @param days - Time period: 7, 14, or 30
|
|
@@ -3207,7 +3922,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3207
3922
|
}
|
|
3208
3923
|
}
|
|
3209
3924
|
/**
|
|
3210
|
-
* Get total volume across all Zyfai accounts
|
|
3925
|
+
* Get total volume across all Zyfai accounts.
|
|
3926
|
+
*
|
|
3927
|
+
* @group Analytics and opportunities
|
|
3928
|
+
*
|
|
3929
|
+
* @remarks Data API. Partner API key only.
|
|
3211
3930
|
*
|
|
3212
3931
|
* @returns Total volume in USD
|
|
3213
3932
|
*
|
|
@@ -3219,7 +3938,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3219
3938
|
*/
|
|
3220
3939
|
async getVolume(assetType = "usdc") {
|
|
3221
3940
|
try {
|
|
3222
|
-
const response = await this.httpClient.get(
|
|
3941
|
+
const response = await this.httpClient.get(
|
|
3942
|
+
ENDPOINTS.DATA_VOLUME(assetType)
|
|
3943
|
+
);
|
|
3223
3944
|
return {
|
|
3224
3945
|
success: true,
|
|
3225
3946
|
volumeInUSD: response.volumeInUSD || "0"
|
|
@@ -3232,7 +3953,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3232
3953
|
// Active Wallets Methods
|
|
3233
3954
|
// ============================================================================
|
|
3234
3955
|
/**
|
|
3235
|
-
* Get active wallets for a specific chain
|
|
3956
|
+
* Get active wallets for a specific chain.
|
|
3957
|
+
*
|
|
3958
|
+
* @group Analytics and opportunities
|
|
3959
|
+
*
|
|
3960
|
+
* @remarks Data API. Partner API key only.
|
|
3236
3961
|
*
|
|
3237
3962
|
* @param chainId - Chain ID to filter wallets
|
|
3238
3963
|
* @returns List of active wallets on the specified chain
|
|
@@ -3269,7 +3994,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3269
3994
|
}
|
|
3270
3995
|
}
|
|
3271
3996
|
/**
|
|
3272
|
-
* Get smart wallets associated with an EOA address
|
|
3997
|
+
* Get smart wallets associated with an EOA address.
|
|
3998
|
+
*
|
|
3999
|
+
* @group Analytics and opportunities
|
|
4000
|
+
*
|
|
4001
|
+
* @remarks Data API. Partner API key only.
|
|
3273
4002
|
*
|
|
3274
4003
|
* @param eoaAddress - EOA (externally owned account) address
|
|
3275
4004
|
* @returns List of smart wallets owned by the EOA
|
|
@@ -3306,7 +4035,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3306
4035
|
// First Topup & History Methods
|
|
3307
4036
|
// ============================================================================
|
|
3308
4037
|
/**
|
|
3309
|
-
* Get the first topup (deposit) information for a wallet
|
|
4038
|
+
* Get the first topup (deposit) information for a wallet.
|
|
4039
|
+
*
|
|
4040
|
+
* @group Analytics and opportunities
|
|
4041
|
+
*
|
|
4042
|
+
* @remarks Data API. Partner API key only.
|
|
3310
4043
|
*
|
|
3311
4044
|
* @param walletAddress - Smart wallet address
|
|
3312
4045
|
* @param chainId - Chain ID
|
|
@@ -3341,7 +4074,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3341
4074
|
}
|
|
3342
4075
|
}
|
|
3343
4076
|
/**
|
|
3344
|
-
* Get transaction history for a wallet
|
|
4077
|
+
* Get transaction history for a wallet.
|
|
4078
|
+
*
|
|
4079
|
+
* @group Analytics and opportunities
|
|
4080
|
+
*
|
|
4081
|
+
* @remarks Data API. Partner API key only.
|
|
3345
4082
|
*
|
|
3346
4083
|
* @param walletAddress - Smart wallet address
|
|
3347
4084
|
* @param chainId - Chain ID
|
|
@@ -3397,11 +4134,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3397
4134
|
// Onchain Earnings Methods (Data API v2)
|
|
3398
4135
|
// ============================================================================
|
|
3399
4136
|
/**
|
|
3400
|
-
* Get onchain earnings for a wallet
|
|
4137
|
+
* Get onchain earnings for a wallet.
|
|
4138
|
+
*
|
|
4139
|
+
* @group Analytics and opportunities
|
|
4140
|
+
*
|
|
4141
|
+
* @remarks Data API. Partner API key only.
|
|
3401
4142
|
*
|
|
3402
4143
|
* Includes gross totals plus net-of-fee totals:
|
|
3403
|
-
* `totalEarningsByTokenWithFee = lifetime + unrealized + current × (1 - feeRate)`.
|
|
3404
|
-
*
|
|
4144
|
+
* `totalEarningsByTokenWithFee = (lifetime + unrealized + current) × (1 - feeRate)`.
|
|
4145
|
+
* Ledger buckets are gross, so the keep-rate applies to all three.
|
|
3405
4146
|
*
|
|
3406
4147
|
* @param walletAddress - Smart wallet address
|
|
3407
4148
|
* @returns Onchain earnings data with per-token breakdowns
|
|
@@ -3550,7 +4291,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3550
4291
|
// Opportunities Methods (Data API v2)
|
|
3551
4292
|
// ============================================================================
|
|
3552
4293
|
/**
|
|
3553
|
-
* Get conservative (low-risk) yield opportunities
|
|
4294
|
+
* Get conservative (low-risk) yield opportunities.
|
|
4295
|
+
*
|
|
4296
|
+
* @group Analytics and opportunities
|
|
4297
|
+
*
|
|
4298
|
+
* @remarks Data API. Partner API key only.
|
|
3554
4299
|
*
|
|
3555
4300
|
* @param chainId - Optional chain ID filter
|
|
3556
4301
|
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
@@ -3996,9 +4741,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3996
4741
|
}
|
|
3997
4742
|
};
|
|
3998
4743
|
} catch (error) {
|
|
3999
|
-
throw new Error(
|
|
4000
|
-
`Failed to get SDK key TVL: ${error.message}`
|
|
4001
|
-
);
|
|
4744
|
+
throw new Error(`Failed to get SDK key TVL: ${error.message}`);
|
|
4002
4745
|
}
|
|
4003
4746
|
}
|
|
4004
4747
|
// ============================================================================
|
|
@@ -4010,6 +4753,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4010
4753
|
* Allows granular control over which pools to use for each protocol on each chain.
|
|
4011
4754
|
* This is useful for advanced users who want to target specific pools with desired APY/risk profiles.
|
|
4012
4755
|
*
|
|
4756
|
+
* @group Customization and simulation
|
|
4757
|
+
*
|
|
4758
|
+
* @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
|
|
4759
|
+
*
|
|
4013
4760
|
* @param customizations - Array of customization configurations
|
|
4014
4761
|
* @returns Response indicating success
|
|
4015
4762
|
*
|
|
@@ -4038,6 +4785,65 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4038
4785
|
* ]);
|
|
4039
4786
|
* ```
|
|
4040
4787
|
*/
|
|
4788
|
+
/**
|
|
4789
|
+
* Get the user's agent management mandate (autonomy limits).
|
|
4790
|
+
*
|
|
4791
|
+
* @group Agent management
|
|
4792
|
+
*/
|
|
4793
|
+
async getAgentMandate(oauthClientId) {
|
|
4794
|
+
await this.authenticateUser();
|
|
4795
|
+
const query = oauthClientId ? `?oauthClientId=${encodeURIComponent(oauthClientId)}` : "";
|
|
4796
|
+
return this.httpClient.get(
|
|
4797
|
+
`${ENDPOINTS.USER_AGENT_MANDATE}${query}`
|
|
4798
|
+
);
|
|
4799
|
+
}
|
|
4800
|
+
/**
|
|
4801
|
+
* Create or update the user's agent management mandate.
|
|
4802
|
+
*
|
|
4803
|
+
* @group Agent management
|
|
4804
|
+
*/
|
|
4805
|
+
async setAgentMandate(request) {
|
|
4806
|
+
await this.authenticateUser();
|
|
4807
|
+
return this.httpClient.put(
|
|
4808
|
+
ENDPOINTS.USER_AGENT_MANDATE,
|
|
4809
|
+
request
|
|
4810
|
+
);
|
|
4811
|
+
}
|
|
4812
|
+
/**
|
|
4813
|
+
* Revoke the user's agent management mandate.
|
|
4814
|
+
*
|
|
4815
|
+
* @group Agent management
|
|
4816
|
+
*/
|
|
4817
|
+
async revokeAgentMandate(oauthClientId) {
|
|
4818
|
+
await this.authenticateUser();
|
|
4819
|
+
return this.httpClient.delete(
|
|
4820
|
+
`${ENDPOINTS.USER_AGENT_MANDATE}?oauthClientId=${encodeURIComponent(oauthClientId)}`
|
|
4821
|
+
);
|
|
4822
|
+
}
|
|
4823
|
+
/**
|
|
4824
|
+
* Reserve a one-time action id before the user signs an ERC-20 transfer.
|
|
4825
|
+
*
|
|
4826
|
+
* @group Agent management
|
|
4827
|
+
*/
|
|
4828
|
+
async createAgentEnterIntent(request) {
|
|
4829
|
+
await this.authenticateUser();
|
|
4830
|
+
return this.httpClient.post(
|
|
4831
|
+
ENDPOINTS.USER_AGENT_ENTER_INTENTS,
|
|
4832
|
+
request
|
|
4833
|
+
);
|
|
4834
|
+
}
|
|
4835
|
+
/**
|
|
4836
|
+
* Consume a one-time action id when registering the signed deposit.
|
|
4837
|
+
*
|
|
4838
|
+
* @group Agent management
|
|
4839
|
+
*/
|
|
4840
|
+
async consumeAgentEnterIntent(actionId, request) {
|
|
4841
|
+
await this.authenticateUser();
|
|
4842
|
+
await this.httpClient.post(
|
|
4843
|
+
ENDPOINTS.USER_AGENT_ENTER_INTENT_CONSUME(actionId),
|
|
4844
|
+
request
|
|
4845
|
+
);
|
|
4846
|
+
}
|
|
4041
4847
|
async customizeBatch(customizations) {
|
|
4042
4848
|
try {
|
|
4043
4849
|
await this.authenticateUser();
|
|
@@ -4057,8 +4863,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4057
4863
|
*
|
|
4058
4864
|
* Returns the list of pools available for a given protocol, optionally filtered by strategy.
|
|
4059
4865
|
*
|
|
4866
|
+
* @group Customization and simulation
|
|
4867
|
+
*
|
|
4868
|
+
* @remarks Execution API. Partner API key only.
|
|
4869
|
+
*
|
|
4060
4870
|
* @param protocolId - The protocol UUID
|
|
4061
|
-
* @param strategy - Optional
|
|
4871
|
+
* @param strategy - Optional {@link Strategy} filter
|
|
4062
4872
|
* @returns List of available pool names
|
|
4063
4873
|
*
|
|
4064
4874
|
* @example
|
|
@@ -4106,7 +4916,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4106
4916
|
* calldata contains a "<RECEIVER>" placeholder that must be replaced with the
|
|
4107
4917
|
* actual receiving address (e.g. the user's Safe) before sending the transaction.
|
|
4108
4918
|
*
|
|
4109
|
-
* @
|
|
4919
|
+
* @group Customization and simulation
|
|
4920
|
+
*
|
|
4921
|
+
* @remarks Data API simulation endpoint. Partner API key only.
|
|
4922
|
+
*
|
|
4923
|
+
* @param params - {@link SimulateBestPositionsParams}
|
|
4110
4924
|
* @returns Chain-keyed map of simulated positions with calldata
|
|
4111
4925
|
*
|
|
4112
4926
|
* @example
|
|
@@ -4149,6 +4963,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4149
4963
|
* Returns the pools that are currently configured for the authenticated user
|
|
4150
4964
|
* for a given protocol and chain combination.
|
|
4151
4965
|
*
|
|
4966
|
+
* @group Customization and simulation
|
|
4967
|
+
*
|
|
4968
|
+
* @remarks Execution API. Requires {@link ZyfaiSDK.connectAccount} (SIWE).
|
|
4969
|
+
*
|
|
4152
4970
|
* @param protocolId - The protocol UUID
|
|
4153
4971
|
* @param chainId - The chain ID
|
|
4154
4972
|
* @returns Currently selected pools and autoselect status
|
|
@@ -4181,7 +4999,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4181
4999
|
* Check if a chain ID supports the Identity Registry
|
|
4182
5000
|
*/
|
|
4183
5001
|
isSupportedIdentityRegistryChain(chainId) {
|
|
4184
|
-
return _ZyfaiSDK.IDENTITY_REGISTRY_CHAIN_IDS.includes(
|
|
5002
|
+
return _ZyfaiSDK.IDENTITY_REGISTRY_CHAIN_IDS.includes(
|
|
5003
|
+
chainId
|
|
5004
|
+
);
|
|
4185
5005
|
}
|
|
4186
5006
|
/**
|
|
4187
5007
|
* Register an agent on the Identity Registry (ERC-8004)
|
|
@@ -4254,10 +5074,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4254
5074
|
// Vault Methods (Base only)
|
|
4255
5075
|
// ============================================
|
|
4256
5076
|
/**
|
|
4257
|
-
* Deposit assets into the Zyfai Vault
|
|
4258
|
-
*
|
|
5077
|
+
* Deposit assets into the Zyfai Vault (USDC on Base by default).
|
|
5078
|
+
*
|
|
5079
|
+
* @group Vault
|
|
4259
5080
|
*
|
|
4260
|
-
* @
|
|
5081
|
+
* @remarks On-chain vault flow via connected wallet. Requires {@link ZyfaiSDK.connectAccount}.
|
|
5082
|
+
*
|
|
5083
|
+
* @param amount - Human-readable amount (e.g. `"100"` USDC)
|
|
4261
5084
|
* @param asset - Asset to deposit (default: "USDC")
|
|
4262
5085
|
* @returns Deposit transaction result
|
|
4263
5086
|
*
|
|
@@ -4278,7 +5101,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4278
5101
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
4279
5102
|
const tokenAddress = getDefaultTokenAddress(chainId, asset);
|
|
4280
5103
|
const decimals = 6;
|
|
4281
|
-
const parsedAmount = BigInt(
|
|
5104
|
+
const parsedAmount = BigInt(
|
|
5105
|
+
Math.floor(parseFloat(amount) * 10 ** decimals)
|
|
5106
|
+
);
|
|
4282
5107
|
try {
|
|
4283
5108
|
const allowance = await chainConfig.publicClient.readContract({
|
|
4284
5109
|
address: tokenAddress,
|
|
@@ -4356,7 +5181,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4356
5181
|
args: [userAddress]
|
|
4357
5182
|
});
|
|
4358
5183
|
if (maxShares === 0n) {
|
|
4359
|
-
throw new Error(
|
|
5184
|
+
throw new Error(
|
|
5185
|
+
"No shares available to redeem or withdrawals are paused"
|
|
5186
|
+
);
|
|
4360
5187
|
}
|
|
4361
5188
|
sharesToRedeem = maxShares;
|
|
4362
5189
|
}
|
|
@@ -4400,7 +5227,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4400
5227
|
status: isClaimable ? "claimable" : "pending"
|
|
4401
5228
|
};
|
|
4402
5229
|
} catch (error) {
|
|
4403
|
-
throw new Error(
|
|
5230
|
+
throw new Error(
|
|
5231
|
+
`Vault withdraw request failed: ${error.message}`
|
|
5232
|
+
);
|
|
4404
5233
|
}
|
|
4405
5234
|
}
|
|
4406
5235
|
/**
|
|
@@ -4480,7 +5309,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4480
5309
|
nonce
|
|
4481
5310
|
};
|
|
4482
5311
|
} catch (error) {
|
|
4483
|
-
throw new Error(
|
|
5312
|
+
throw new Error(
|
|
5313
|
+
`Failed to get withdraw status: ${error.message}`
|
|
5314
|
+
);
|
|
4484
5315
|
}
|
|
4485
5316
|
}
|
|
4486
5317
|
/**
|
|
@@ -4523,7 +5354,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4523
5354
|
if (isClaimed) {
|
|
4524
5355
|
throw new Error("This withdrawal has already been claimed");
|
|
4525
5356
|
}
|
|
4526
|
-
throw new Error(
|
|
5357
|
+
throw new Error(
|
|
5358
|
+
"Withdrawal is not yet claimable. Please wait for processing."
|
|
5359
|
+
);
|
|
4527
5360
|
}
|
|
4528
5361
|
const claimTx = await this.walletClient.writeContract({
|
|
4529
5362
|
address: VAULT_ADDRESS,
|
|
@@ -4563,7 +5396,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4563
5396
|
async getVaultShares(userAddress, chainId = 8453) {
|
|
4564
5397
|
const address = userAddress || this.walletClient?.account?.address;
|
|
4565
5398
|
if (!address) {
|
|
4566
|
-
throw new Error(
|
|
5399
|
+
throw new Error(
|
|
5400
|
+
"User address required. Provide address or connect wallet first."
|
|
5401
|
+
);
|
|
4567
5402
|
}
|
|
4568
5403
|
const chainConfig = getChainConfig(chainId, this.rpcUrls);
|
|
4569
5404
|
const [shareBalance, tokenSymbol] = await Promise.all([
|
|
@@ -4594,9 +5429,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4594
5429
|
* Events: depeg, liquidity_trap, liquidity_restored, pool_status_change,
|
|
4595
5430
|
* new_collateral_detected, liquidity_drop.
|
|
4596
5431
|
*
|
|
4597
|
-
* @
|
|
4598
|
-
*
|
|
4599
|
-
* @
|
|
5432
|
+
* @group Realtime events
|
|
5433
|
+
*
|
|
5434
|
+
* @remarks Connects to defi-api WebSocket (`WS_ENDPOINT`). Auto-reconnects every 3s until
|
|
5435
|
+
* the returned cleanup function is called.
|
|
5436
|
+
*
|
|
5437
|
+
* @param handlers - {@link ZyfaiEventHandlers}
|
|
5438
|
+
* @param filters - Optional {@link ZyfaiEventFilters} sent on subscribe
|
|
5439
|
+
* @returns Cleanup function — call it to close the connection and stop reconnecting
|
|
4600
5440
|
*
|
|
4601
5441
|
* @example
|
|
4602
5442
|
* ```typescript
|