@zyfai/sdk 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -39
- package/dist/index.d.mts +89 -27
- package/dist/index.d.ts +89 -27
- package/dist/index.js +296 -80
- package/dist/index.mjs +267 -50
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -128,6 +128,9 @@ var ENDPOINTS = {
|
|
|
128
128
|
USER_WITHDRAW: "/users/withdraw/v2",
|
|
129
129
|
PARTIAL_WITHDRAW: "/users/partial-withdraw/v2",
|
|
130
130
|
LOG_DEPOSIT: "/users/log_deposit/v2",
|
|
131
|
+
FIRST_PERMIT_DEPOSIT: "/users/me/permit-deposit",
|
|
132
|
+
FIRST_PERMIT_DEPOSIT_PREPARE: "/users/me/permit-deposit/prepare",
|
|
133
|
+
FIRST_PERMIT_DEPOSIT_SUBMIT: (id) => `/users/me/permit-deposit/${encodeURIComponent(id)}/submit`,
|
|
131
134
|
FUNDING_ORDERS: "/users/me/funding-orders",
|
|
132
135
|
FUNDING_ORDER: (orderId) => `/users/me/funding-orders/${encodeURIComponent(orderId)}`,
|
|
133
136
|
FUNDING_ORDER_QUOTE: (orderId) => `/users/me/funding-orders/${encodeURIComponent(orderId)}/quote`,
|
|
@@ -201,27 +204,28 @@ var DATA_ENDPOINTS = {
|
|
|
201
204
|
if (endDate) url += `&endDate=${endDate}`;
|
|
202
205
|
return url;
|
|
203
206
|
},
|
|
204
|
-
// Opportunities
|
|
207
|
+
// Opportunities. Omitted status means live pools. Pass not_live to
|
|
208
|
+
// read retired rows. The data API returns both when status is absent.
|
|
205
209
|
OPPORTUNITIES_SAFE: (chainId, asset, status) => {
|
|
206
210
|
const params = [];
|
|
207
211
|
if (chainId !== void 0) params.push(`chainId=${chainId}`);
|
|
208
212
|
if (asset) params.push(`asset=${asset}`);
|
|
209
|
-
|
|
210
|
-
return
|
|
213
|
+
params.push(`status=${status ?? "live"}`);
|
|
214
|
+
return `/opportunities/safe?${params.join("&")}`;
|
|
211
215
|
},
|
|
212
216
|
OPPORTUNITIES_DEGEN: (chainId, asset, status) => {
|
|
213
217
|
const params = [];
|
|
214
218
|
if (chainId !== void 0) params.push(`chainId=${chainId}`);
|
|
215
219
|
if (asset) params.push(`asset=${asset}`);
|
|
216
|
-
|
|
217
|
-
return
|
|
220
|
+
params.push(`status=${status ?? "live"}`);
|
|
221
|
+
return `/opportunities/degen-strategies?${params.join("&")}`;
|
|
218
222
|
},
|
|
219
223
|
OPPORTUNITIES_ASYNC: (chainId, asset, status) => {
|
|
220
224
|
const params = [];
|
|
221
225
|
if (chainId !== void 0) params.push(`chainId=${chainId}`);
|
|
222
226
|
if (asset) params.push(`asset=${asset}`);
|
|
223
|
-
|
|
224
|
-
return
|
|
227
|
+
params.push(`status=${status ?? "live"}`);
|
|
228
|
+
return `/opportunities/async?${params.join("&")}`;
|
|
225
229
|
},
|
|
226
230
|
// APY History
|
|
227
231
|
DAILY_APY_HISTORY_WEIGHTED: (walletAddress, days) => `/daily-apy-history/weighted-multi-asset/${walletAddress}${days ? `?days=${days}` : ""}`,
|
|
@@ -335,8 +339,9 @@ var HttpClient = class {
|
|
|
335
339
|
case 403:
|
|
336
340
|
throw new Error("Forbidden: Access denied");
|
|
337
341
|
case 404:
|
|
338
|
-
throw
|
|
339
|
-
`Not found: ${data.message || "Resource not found"}`
|
|
342
|
+
throw Object.assign(
|
|
343
|
+
new Error(`Not found: ${data.message || "Resource not found"}`),
|
|
344
|
+
{ status }
|
|
340
345
|
);
|
|
341
346
|
case 429:
|
|
342
347
|
throw new Error("Rate limit exceeded. Please try again later.");
|
|
@@ -459,6 +464,20 @@ var HttpClient = class {
|
|
|
459
464
|
};
|
|
460
465
|
|
|
461
466
|
// src/utils/poll.ts
|
|
467
|
+
async function pollUntil(fn, predicate, options) {
|
|
468
|
+
const intervalMs = options?.intervalMs ?? 5e3;
|
|
469
|
+
const timeoutMs = options?.timeoutMs ?? 12e4;
|
|
470
|
+
const label = options?.label ?? "condition";
|
|
471
|
+
const started = Date.now();
|
|
472
|
+
while (Date.now() - started < timeoutMs) {
|
|
473
|
+
const value = await fn();
|
|
474
|
+
if (predicate(value)) {
|
|
475
|
+
return { value, elapsedMs: Date.now() - started };
|
|
476
|
+
}
|
|
477
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
478
|
+
}
|
|
479
|
+
throw new Error(`Timed out waiting for ${label} after ${timeoutMs}ms`);
|
|
480
|
+
}
|
|
462
481
|
function sleep(ms) {
|
|
463
482
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
464
483
|
}
|
|
@@ -882,7 +901,7 @@ function isMainnetMinPortfolioExempt(chainId, ...addresses) {
|
|
|
882
901
|
|
|
883
902
|
// src/core/ZyfaiSDK.ts
|
|
884
903
|
var import_accounts2 = require("viem/accounts");
|
|
885
|
-
var
|
|
904
|
+
var import_viem6 = require("viem");
|
|
886
905
|
var import_relay_sdk2 = require("@relayprotocol/relay-sdk");
|
|
887
906
|
|
|
888
907
|
// src/config/chains.ts
|
|
@@ -1005,7 +1024,7 @@ var ASSET_CONFIGS = {
|
|
|
1005
1024
|
enabled: true
|
|
1006
1025
|
},
|
|
1007
1026
|
// Coinbase B20 tokenized NVIDIA equity. Base only, and only reachable through
|
|
1008
|
-
// protocols with delayed withdrawals — see the `
|
|
1027
|
+
// protocols with delayed withdrawals — see the `yieldmaxxing` strategy.
|
|
1009
1028
|
NVDAc: {
|
|
1010
1029
|
symbol: "NVDAc",
|
|
1011
1030
|
assetType: "nvdac",
|
|
@@ -1198,6 +1217,29 @@ var positiveUnits = (value) => {
|
|
|
1198
1217
|
};
|
|
1199
1218
|
var resolveCollateralMinimum = (storedMinimum, quote) => positiveUnits(storedMinimum) ?? positiveUnits(quote.details?.currencyOut?.minimumAmount) ?? positiveUnits(quote.details?.currencyOut?.amount) ?? "0";
|
|
1200
1219
|
|
|
1220
|
+
// src/deposits/first-permit-deposit.ts
|
|
1221
|
+
var import_viem4 = require("viem");
|
|
1222
|
+
var firstPermitTypes = {
|
|
1223
|
+
Permit: [
|
|
1224
|
+
{ name: "owner", type: "address" },
|
|
1225
|
+
{ name: "spender", type: "address" },
|
|
1226
|
+
{ name: "value", type: "uint256" },
|
|
1227
|
+
{ name: "nonce", type: "uint256" },
|
|
1228
|
+
{ name: "deadline", type: "uint256" }
|
|
1229
|
+
]
|
|
1230
|
+
};
|
|
1231
|
+
function matchesFirstPermitDeposit(intent, request) {
|
|
1232
|
+
return intent.chainId === request.chainId && (0, import_viem4.isAddressEqual)(intent.token, request.token) && intent.amount === request.amount.toString();
|
|
1233
|
+
}
|
|
1234
|
+
function validateFirstPermit({ domain, message }, request) {
|
|
1235
|
+
const value = BigInt(message.value);
|
|
1236
|
+
const nonce = BigInt(message.nonce);
|
|
1237
|
+
if (domain.chainId !== request.chainId || !(0, import_viem4.isAddressEqual)(domain.verifyingContract, request.token) || !(0, import_viem4.isAddressEqual)(message.owner, request.owner) || !(0, import_viem4.isAddressEqual)(message.spender, request.safe) || value !== request.amount || nonce < 0n || !Number.isSafeInteger(message.deadline) || message.deadline <= Math.floor(Date.now() / 1e3)) {
|
|
1238
|
+
throw new Error("Prepared permit does not match this deposit");
|
|
1239
|
+
}
|
|
1240
|
+
return { ...message, value, nonce, deadline: BigInt(message.deadline) };
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1201
1243
|
// src/deposits/relay-slippage.ts
|
|
1202
1244
|
var DEFAULT_RELAY_SLIPPAGE_BPS = 200;
|
|
1203
1245
|
var MAX_RELAY_SLIPPAGE_BPS = 500;
|
|
@@ -1321,7 +1363,7 @@ function getManagedAssets() {
|
|
|
1321
1363
|
// src/utils/safe-account.ts
|
|
1322
1364
|
var import_module_sdk = require("@rhinestone/module-sdk");
|
|
1323
1365
|
var import_accounts = require("permissionless/accounts");
|
|
1324
|
-
var
|
|
1366
|
+
var import_viem5 = require("viem");
|
|
1325
1367
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
1326
1368
|
|
|
1327
1369
|
// src/config/modules.ts
|
|
@@ -1351,12 +1393,12 @@ var getSafeAccount = async (config) => {
|
|
|
1351
1393
|
if (!safeOwnerAddress) {
|
|
1352
1394
|
throw new Error("Safe owner address is required");
|
|
1353
1395
|
}
|
|
1354
|
-
const formattedOwnerAddress = (0,
|
|
1396
|
+
const formattedOwnerAddress = (0, import_viem5.getAddress)(safeOwnerAddress);
|
|
1355
1397
|
const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
|
|
1356
1398
|
owners: [formattedOwnerAddress],
|
|
1357
1399
|
threshold: 1
|
|
1358
1400
|
});
|
|
1359
|
-
const saltHex = (0,
|
|
1401
|
+
const saltHex = (0, import_viem5.fromHex)((0, import_viem5.toHex)(ACCOUNT_SALT), "bigint");
|
|
1360
1402
|
const tempOwner = {
|
|
1361
1403
|
address: formattedOwnerAddress,
|
|
1362
1404
|
type: "json-rpc"
|
|
@@ -1403,12 +1445,12 @@ var isSafeDeployed = async (address, publicClient) => {
|
|
|
1403
1445
|
}
|
|
1404
1446
|
};
|
|
1405
1447
|
var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
|
|
1406
|
-
const normalizedUser = (0,
|
|
1407
|
-
const normalizedSafe = (0,
|
|
1448
|
+
const normalizedUser = (0, import_viem5.getAddress)(userAddress);
|
|
1449
|
+
const normalizedSafe = (0, import_viem5.getAddress)(safeAddress);
|
|
1408
1450
|
const validatorAddresses = Array.from(
|
|
1409
1451
|
/* @__PURE__ */ new Set([
|
|
1410
|
-
(0,
|
|
1411
|
-
(0,
|
|
1452
|
+
(0, import_viem5.getAddress)(OWNABLE_VALIDATOR),
|
|
1453
|
+
(0, import_viem5.getAddress)(import_module_sdk.OWNABLE_VALIDATOR_ADDRESS)
|
|
1412
1454
|
])
|
|
1413
1455
|
);
|
|
1414
1456
|
for (const validatorAddress of validatorAddresses) {
|
|
@@ -1419,7 +1461,7 @@ var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) =>
|
|
|
1419
1461
|
functionName: "getOwners",
|
|
1420
1462
|
args: [normalizedSafe]
|
|
1421
1463
|
});
|
|
1422
|
-
if (owners.some((owner) => (0,
|
|
1464
|
+
if (owners.some((owner) => (0, import_viem5.getAddress)(owner) === normalizedUser)) {
|
|
1423
1465
|
return true;
|
|
1424
1466
|
}
|
|
1425
1467
|
} catch {
|
|
@@ -1550,15 +1592,15 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
|
|
|
1550
1592
|
};
|
|
1551
1593
|
|
|
1552
1594
|
// src/utils/strategy.ts
|
|
1553
|
-
var PUBLIC_STRATEGIES = `"conservative", "
|
|
1595
|
+
var PUBLIC_STRATEGIES = `"conservative", "aggressive" or "yieldmaxxing"`;
|
|
1554
1596
|
var SUPPORTED_ASSETS = Object.entries(ASSET_CONFIGS).filter(([, config]) => config?.enabled === true).map(([symbol]) => `"${symbol}"`).join(", ");
|
|
1555
1597
|
function toInternalStrategy(publicStrategy) {
|
|
1556
1598
|
switch (publicStrategy) {
|
|
1557
1599
|
case "conservative":
|
|
1558
1600
|
return "safe_strategy";
|
|
1559
|
-
case "
|
|
1601
|
+
case "aggressive":
|
|
1560
1602
|
return "degen_strategy";
|
|
1561
|
-
case "
|
|
1603
|
+
case "yieldmaxxing":
|
|
1562
1604
|
return "async_strategy";
|
|
1563
1605
|
default:
|
|
1564
1606
|
throw new Error(
|
|
@@ -1571,10 +1613,10 @@ function toPublicStrategy(internalStrategy) {
|
|
|
1571
1613
|
return "conservative";
|
|
1572
1614
|
}
|
|
1573
1615
|
if (internalStrategy === "degen_strategy" || internalStrategy === "degen") {
|
|
1574
|
-
return "
|
|
1616
|
+
return "aggressive";
|
|
1575
1617
|
}
|
|
1576
1618
|
if (internalStrategy === "async_strategy" || internalStrategy === "async") {
|
|
1577
|
-
return "
|
|
1619
|
+
return "yieldmaxxing";
|
|
1578
1620
|
}
|
|
1579
1621
|
throw new Error(
|
|
1580
1622
|
`Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy", "degen_strategy" or "async_strategy".`
|
|
@@ -1591,7 +1633,11 @@ function toPublicStrategyOrUndefined(internalStrategy) {
|
|
|
1591
1633
|
}
|
|
1592
1634
|
}
|
|
1593
1635
|
function isValidPublicStrategy(strategy) {
|
|
1594
|
-
return strategy === "conservative" || strategy === "
|
|
1636
|
+
return strategy === "conservative" || strategy === "aggressive" || strategy === "yieldmaxxing";
|
|
1637
|
+
}
|
|
1638
|
+
function shouldDefaultAutoSelectNewVaults(input) {
|
|
1639
|
+
if (input.requestedStrategy !== void 0) return true;
|
|
1640
|
+
return !input.hasChains && !input.hasProtocols;
|
|
1595
1641
|
}
|
|
1596
1642
|
function convertStrategyToPublic(obj) {
|
|
1597
1643
|
if (!obj.strategy) {
|
|
@@ -2197,7 +2243,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2197
2243
|
}
|
|
2198
2244
|
this.httpClient.setAuthToken(session.accessToken);
|
|
2199
2245
|
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
2200
|
-
this.sessionEoa = session.eoa ? (0,
|
|
2246
|
+
this.sessionEoa = session.eoa ? (0, import_viem6.getAddress)(session.eoa) : null;
|
|
2201
2247
|
this.sessionChannel = session.channel;
|
|
2202
2248
|
this.isPredeployed = false;
|
|
2203
2249
|
this.predeployedResolved = false;
|
|
@@ -2246,7 +2292,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2246
2292
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
2247
2293
|
this.predeployedResolved = true;
|
|
2248
2294
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
2249
|
-
this.sessionEoa = (0,
|
|
2295
|
+
this.sessionEoa = (0, import_viem6.getAddress)(params.message.address);
|
|
2250
2296
|
this.sessionChannel = void 0;
|
|
2251
2297
|
return loginResponse;
|
|
2252
2298
|
}
|
|
@@ -2275,7 +2321,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2275
2321
|
return;
|
|
2276
2322
|
}
|
|
2277
2323
|
const walletClient = this.getWalletClient();
|
|
2278
|
-
const userAddress = (0,
|
|
2324
|
+
const userAddress = (0, import_viem6.getAddress)(walletClient.account.address);
|
|
2279
2325
|
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
2280
2326
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
2281
2327
|
let uri;
|
|
@@ -2363,7 +2409,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2363
2409
|
if (request.strategy) {
|
|
2364
2410
|
if (!isValidPublicStrategy(request.strategy)) {
|
|
2365
2411
|
throw new Error(
|
|
2366
|
-
`Invalid strategy: ${request.strategy}. Must be "conservative", "
|
|
2412
|
+
`Invalid strategy: ${request.strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
2367
2413
|
);
|
|
2368
2414
|
}
|
|
2369
2415
|
rebalanceStrategy = toInternalStrategy(request.strategy);
|
|
@@ -2653,10 +2699,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2653
2699
|
this.walletClient.chain?.id || 8453,
|
|
2654
2700
|
this.rpcUrls
|
|
2655
2701
|
);
|
|
2656
|
-
this.walletClient = (0,
|
|
2702
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
2657
2703
|
account: newAddress,
|
|
2658
2704
|
chain: chainConfig.chain,
|
|
2659
|
-
transport: (0,
|
|
2705
|
+
transport: (0, import_viem6.custom)(this.currentProvider)
|
|
2660
2706
|
});
|
|
2661
2707
|
this.currentChainId = this.walletClient.chain?.id || null;
|
|
2662
2708
|
try {
|
|
@@ -2721,10 +2767,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2721
2767
|
}
|
|
2722
2768
|
this.signer = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
2723
2769
|
this.currentChainId = chainId;
|
|
2724
|
-
this.walletClient = (0,
|
|
2770
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
2725
2771
|
account: this.signer,
|
|
2726
2772
|
chain: chainConfig.chain,
|
|
2727
|
-
transport: (0,
|
|
2773
|
+
transport: (0, import_viem6.http)(chainConfig.rpcUrl)
|
|
2728
2774
|
});
|
|
2729
2775
|
connectedAddress = this.signer.address;
|
|
2730
2776
|
this.currentProvider = null;
|
|
@@ -2742,10 +2788,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2742
2788
|
if (!accounts || accounts.length === 0) {
|
|
2743
2789
|
throw new Error("No accounts found in wallet provider");
|
|
2744
2790
|
}
|
|
2745
|
-
this.walletClient = (0,
|
|
2791
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
2746
2792
|
account: accounts[0],
|
|
2747
2793
|
chain: chainConfig.chain,
|
|
2748
|
-
transport: (0,
|
|
2794
|
+
transport: (0, import_viem6.custom)(provider)
|
|
2749
2795
|
});
|
|
2750
2796
|
connectedAddress = accounts[0];
|
|
2751
2797
|
this.currentProvider = provider;
|
|
@@ -2754,7 +2800,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2754
2800
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
2755
2801
|
}
|
|
2756
2802
|
} else if (provider.account && provider.transport) {
|
|
2757
|
-
this.walletClient = (0,
|
|
2803
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
2758
2804
|
account: provider.account,
|
|
2759
2805
|
chain: chainConfig.chain,
|
|
2760
2806
|
transport: provider.transport
|
|
@@ -2815,10 +2861,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2815
2861
|
targetChainId,
|
|
2816
2862
|
this.rpcUrls
|
|
2817
2863
|
);
|
|
2818
|
-
return (0,
|
|
2864
|
+
return (0, import_viem6.createWalletClient)({
|
|
2819
2865
|
account: this.signer,
|
|
2820
2866
|
chain: targetChainConfig.chain,
|
|
2821
|
-
transport: (0,
|
|
2867
|
+
transport: (0, import_viem6.http)(targetChainConfig.rpcUrl)
|
|
2822
2868
|
});
|
|
2823
2869
|
} else {
|
|
2824
2870
|
if (!this.walletClient) {
|
|
@@ -2934,7 +2980,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2934
2980
|
*
|
|
2935
2981
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
2936
2982
|
* @param chainId - Target chain ID
|
|
2937
|
-
* @param strategy - Optional strategy selection: "conservative" (default), "
|
|
2983
|
+
* @param strategy - Optional strategy selection: "conservative" (default), "aggressive" or "yieldmaxxing"
|
|
2938
2984
|
* @param createSessionKey - If true, automatically creates a session key after deployment (default: false)
|
|
2939
2985
|
* @returns Deployment response with Safe address and transaction hash
|
|
2940
2986
|
*
|
|
@@ -3302,20 +3348,26 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3302
3348
|
internalStrategy
|
|
3303
3349
|
);
|
|
3304
3350
|
const mandateChainId = chains.find((c) => !existingChains.includes(c)) ?? chains[0];
|
|
3351
|
+
const autoSelectNewVaults = shouldDefaultAutoSelectNewVaults({
|
|
3352
|
+
requestedStrategy: strategy,
|
|
3353
|
+
hasChains: existingChains.length > 0,
|
|
3354
|
+
hasProtocols: (userDetails.protocols?.length ?? 0) > 0
|
|
3355
|
+
});
|
|
3305
3356
|
return await this.persistDiscoveredAssetProfile(
|
|
3306
3357
|
asset,
|
|
3307
3358
|
effectiveChains,
|
|
3308
3359
|
withPools,
|
|
3309
3360
|
strategy,
|
|
3310
3361
|
mandateChainId,
|
|
3311
|
-
existingChains
|
|
3362
|
+
existingChains,
|
|
3363
|
+
autoSelectNewVaults
|
|
3312
3364
|
);
|
|
3313
3365
|
}
|
|
3314
3366
|
/**
|
|
3315
3367
|
* Persist protocol discovery for one asset (user PATCH or agent deposit-setup).
|
|
3316
3368
|
* @internal
|
|
3317
3369
|
*/
|
|
3318
|
-
async persistDiscoveredAssetProfile(asset, effectiveChains, withPools, strategy, agentDepositChainId, existingChains = []) {
|
|
3370
|
+
async persistDiscoveredAssetProfile(asset, effectiveChains, withPools, strategy, agentDepositChainId, existingChains = [], autoSelectNewVaults = false) {
|
|
3319
3371
|
const internalAsset = convertAssetInternally(asset);
|
|
3320
3372
|
const assetSettings = {
|
|
3321
3373
|
chains: effectiveChains,
|
|
@@ -3324,11 +3376,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3324
3376
|
if (strategy !== void 0) {
|
|
3325
3377
|
assetSettings.rebalanceStrategy = toInternalStrategy(strategy);
|
|
3326
3378
|
}
|
|
3379
|
+
if (autoSelectNewVaults) {
|
|
3380
|
+
assetSettings.autoSelectProtocols = true;
|
|
3381
|
+
}
|
|
3327
3382
|
const configureProfile = () => this.updateUserProfile({
|
|
3328
3383
|
asset,
|
|
3329
3384
|
protocols: withPools,
|
|
3330
3385
|
chains: effectiveChains,
|
|
3331
|
-
...strategy !== void 0 && { strategy }
|
|
3386
|
+
...strategy !== void 0 && { strategy },
|
|
3387
|
+
...autoSelectNewVaults && { autoSelectProtocols: true }
|
|
3332
3388
|
});
|
|
3333
3389
|
if (this.sessionChannel === "agent") {
|
|
3334
3390
|
const chainId = agentDepositChainId ?? effectiveChains[effectiveChains.length - 1] ?? effectiveChains[0];
|
|
@@ -3372,7 +3428,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3372
3428
|
* @param params.asset - Asset to configure
|
|
3373
3429
|
* @param params.strategy - Strategy to apply; defaults to the one already
|
|
3374
3430
|
* stored for this asset (`"conservative"` on a fresh account), which lets
|
|
3375
|
-
* you recompute a protocol list without changing the strategy
|
|
3431
|
+
* you recompute a protocol list without changing the strategy. Passing a
|
|
3432
|
+
* strategy also opts the asset into vaults added later. Omitting it does
|
|
3433
|
+
* not change that opt-in.
|
|
3376
3434
|
* @param params.chains - Chains to enable. Defaults to every chain the asset
|
|
3377
3435
|
* exists on. **Additive**: chains already enabled are kept, so this cannot
|
|
3378
3436
|
* be used to disable one.
|
|
@@ -3382,11 +3440,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3382
3440
|
*
|
|
3383
3441
|
* @example
|
|
3384
3442
|
* ```typescript
|
|
3385
|
-
* // NVDAc only lives in async protocols, so it needs "
|
|
3443
|
+
* // NVDAc only lives in async protocols, so it needs "yieldmaxxing".
|
|
3386
3444
|
* // Chains default to Base, the only chain it exists on.
|
|
3387
3445
|
* const profile = await sdk.setAssetStrategy({
|
|
3388
3446
|
* asset: "NVDAc",
|
|
3389
|
-
* strategy: "
|
|
3447
|
+
* strategy: "yieldmaxxing",
|
|
3390
3448
|
* });
|
|
3391
3449
|
* console.log(profile.protocols); // Ipor + Superform
|
|
3392
3450
|
* ```
|
|
@@ -3396,7 +3454,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3396
3454
|
try {
|
|
3397
3455
|
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
3398
3456
|
throw new Error(
|
|
3399
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
3457
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
3400
3458
|
);
|
|
3401
3459
|
}
|
|
3402
3460
|
const supported = getAssetChainIds(asset);
|
|
@@ -3431,7 +3489,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3431
3489
|
* Apply a strategy and auto-select matching protocols for one or all managed
|
|
3432
3490
|
* assets ({@link getManagedAssets}). Prefer this over
|
|
3433
3491
|
* {@link updateUserProfile} when changing strategy so protocols stay aligned
|
|
3434
|
-
* with the tier (including `
|
|
3492
|
+
* with the tier (including `yieldmaxxing` async venues). The chosen strategy
|
|
3493
|
+
* also opts those assets into vaults added later.
|
|
3435
3494
|
*
|
|
3436
3495
|
* @group Portfolio and execution
|
|
3437
3496
|
*/
|
|
@@ -3439,7 +3498,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3439
3498
|
const { strategy, asset, chains } = params;
|
|
3440
3499
|
if (!isValidPublicStrategy(strategy)) {
|
|
3441
3500
|
throw new Error(
|
|
3442
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
3501
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
3443
3502
|
);
|
|
3444
3503
|
}
|
|
3445
3504
|
const assets = asset ? [asset] : getManagedAssets();
|
|
@@ -3588,14 +3647,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3588
3647
|
return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
|
|
3589
3648
|
}
|
|
3590
3649
|
/**
|
|
3591
|
-
*
|
|
3650
|
+
* Deposit a collateral token the wallet already holds into the Safe.
|
|
3592
3651
|
*
|
|
3593
3652
|
* @remarks
|
|
3594
3653
|
* Use this when the connected wallet holds the strategy collateral on the
|
|
3595
3654
|
* deposit chain. {@link ZyfaiSDK.sendDeposit} calls this automatically in
|
|
3596
3655
|
* that case. A different token uses {@link ZyfaiSDK.sendSwapDeposit}.
|
|
3597
3656
|
*
|
|
3598
|
-
*
|
|
3657
|
+
* Eligible first deposits sign an ERC-2612 permit and the backend sponsors and
|
|
3658
|
+
* registers the pull. Other direct deposits confirm an ERC-20 transfer and
|
|
3659
|
+
* call {@link ZyfaiSDK.logDeposit}.
|
|
3599
3660
|
* Requires {@link ZyfaiSDK.connectAccount}. Pass the **EOA** as `userAddress`.
|
|
3600
3661
|
*
|
|
3601
3662
|
* @group Deposits and withdrawals
|
|
@@ -3619,6 +3680,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3619
3680
|
* ```
|
|
3620
3681
|
*/
|
|
3621
3682
|
async sendDirectDeposit(userAddress, chainId, amount, asset, strategy) {
|
|
3683
|
+
return this.sendCollateralDeposit(userAddress, chainId, amount, asset, strategy, true);
|
|
3684
|
+
}
|
|
3685
|
+
async sendCollateralDeposit(userAddress, chainId, amount, asset, strategy, allowPermit) {
|
|
3622
3686
|
try {
|
|
3623
3687
|
if (!userAddress) {
|
|
3624
3688
|
throw new Error("User address is required");
|
|
@@ -3636,7 +3700,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3636
3700
|
}
|
|
3637
3701
|
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
3638
3702
|
throw new Error(
|
|
3639
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
3703
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
3640
3704
|
);
|
|
3641
3705
|
}
|
|
3642
3706
|
const assetSymbol = resolveAssetSymbol(asset);
|
|
@@ -3710,6 +3774,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3710
3774
|
);
|
|
3711
3775
|
}
|
|
3712
3776
|
}
|
|
3777
|
+
if (allowPermit && this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
3778
|
+
const sponsored = await this.sendFirstPermitDeposit({
|
|
3779
|
+
owner: (0, import_viem6.getAddress)(userAddress),
|
|
3780
|
+
safe: safeAddress,
|
|
3781
|
+
chainId,
|
|
3782
|
+
token: (0, import_viem6.getAddress)(token),
|
|
3783
|
+
amount: amountBigInt
|
|
3784
|
+
});
|
|
3785
|
+
if (sponsored) return sponsored;
|
|
3786
|
+
}
|
|
3713
3787
|
const txHash = await walletClient.writeContract({
|
|
3714
3788
|
address: token,
|
|
3715
3789
|
abi: erc20TransferWriteAbi(assetSymbol),
|
|
@@ -3742,6 +3816,115 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3742
3816
|
throw new Error(`Deposit failed: ${error.message}`);
|
|
3743
3817
|
}
|
|
3744
3818
|
}
|
|
3819
|
+
/**
|
|
3820
|
+
* Read the current first-deposit permit intent after a pending or interrupted deposit.
|
|
3821
|
+
*
|
|
3822
|
+
* @remarks
|
|
3823
|
+
* Uses the execution API and the SIWE session from {@link ZyfaiSDK.connectAccount}.
|
|
3824
|
+
* A registered intent provides the deposit id for {@link ZyfaiSDK.getDepositStatus}.
|
|
3825
|
+
*
|
|
3826
|
+
* @group Deposits and withdrawals
|
|
3827
|
+
*
|
|
3828
|
+
* @param userAddress - Authenticated EOA
|
|
3829
|
+
* @returns The latest permit intent, or null when no intent exists
|
|
3830
|
+
* @throws If the address differs from the authenticated EOA or the request fails
|
|
3831
|
+
*
|
|
3832
|
+
* @example
|
|
3833
|
+
* ```typescript
|
|
3834
|
+
* const intent = await sdk.getFirstPermitDepositStatus(eoa);
|
|
3835
|
+
* if (intent?.depositId) await sdk.waitForDepositCredit(intent.depositId, intent.chainId);
|
|
3836
|
+
* ```
|
|
3837
|
+
*/
|
|
3838
|
+
async getFirstPermitDepositStatus(userAddress) {
|
|
3839
|
+
if (!this.sessionEoa || !(0, import_viem6.isAddressEqual)((0, import_viem6.getAddress)(userAddress), this.sessionEoa)) {
|
|
3840
|
+
throw new Error("userAddress does not match authenticated session EOA");
|
|
3841
|
+
}
|
|
3842
|
+
return (await this.getFirstPermitDepositAvailability()).intent;
|
|
3843
|
+
}
|
|
3844
|
+
async getFirstPermitDepositAvailability(chainId) {
|
|
3845
|
+
try {
|
|
3846
|
+
return await this.httpClient.get(
|
|
3847
|
+
ENDPOINTS.FIRST_PERMIT_DEPOSIT,
|
|
3848
|
+
chainId != null ? { params: { chainId } } : void 0
|
|
3849
|
+
);
|
|
3850
|
+
} catch (error) {
|
|
3851
|
+
if (error instanceof Error && "status" in error && error.status === 404) {
|
|
3852
|
+
return { enabledTokens: [], intent: null };
|
|
3853
|
+
}
|
|
3854
|
+
throw error;
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
async sendFirstPermitDeposit(request) {
|
|
3858
|
+
const { enabledTokens, intent, permitPreferred } = await this.getFirstPermitDepositAvailability(request.chainId);
|
|
3859
|
+
let id;
|
|
3860
|
+
let accepted;
|
|
3861
|
+
if (intent?.status === "queued" || intent?.status === "submitted") {
|
|
3862
|
+
if (!matchesFirstPermitDeposit(intent, request)) {
|
|
3863
|
+
throw new Error(`First permit deposit ${intent.id} is already pending for a different deposit`);
|
|
3864
|
+
}
|
|
3865
|
+
id = intent.id;
|
|
3866
|
+
accepted = intent;
|
|
3867
|
+
} else {
|
|
3868
|
+
const { owner, chainId, token, amount } = request;
|
|
3869
|
+
if (permitPreferred === false) return null;
|
|
3870
|
+
if (!enabledTokens.includes(`${chainId}:${token.toLowerCase()}`)) return null;
|
|
3871
|
+
const prepared = await this.httpClient.post(
|
|
3872
|
+
ENDPOINTS.FIRST_PERMIT_DEPOSIT_PREPARE,
|
|
3873
|
+
{ owner, chainId, token, amount: amount.toString() }
|
|
3874
|
+
);
|
|
3875
|
+
if (!prepared) return null;
|
|
3876
|
+
const message = validateFirstPermit(prepared, request);
|
|
3877
|
+
const currentWallet = this.getWalletClient();
|
|
3878
|
+
const wallet = currentWallet.chain?.id === chainId ? currentWallet : await this.walletClientForOrigin(chainId);
|
|
3879
|
+
const signature = await wallet.signTypedData({
|
|
3880
|
+
account: wallet.account,
|
|
3881
|
+
domain: prepared.domain,
|
|
3882
|
+
types: firstPermitTypes,
|
|
3883
|
+
primaryType: "Permit",
|
|
3884
|
+
message
|
|
3885
|
+
});
|
|
3886
|
+
id = prepared.id;
|
|
3887
|
+
try {
|
|
3888
|
+
accepted = await this.httpClient.post(
|
|
3889
|
+
ENDPOINTS.FIRST_PERMIT_DEPOSIT_SUBMIT(id),
|
|
3890
|
+
{ signature }
|
|
3891
|
+
);
|
|
3892
|
+
} catch (error) {
|
|
3893
|
+
accepted = await this.getFirstPermitDepositStatus(owner).catch(() => null);
|
|
3894
|
+
if (accepted?.id !== id || accepted.status === "prepared") {
|
|
3895
|
+
throw new Error(
|
|
3896
|
+
`Could not confirm first permit deposit ${id}. Check getFirstPermitDepositStatus before retrying: ${thrownMessage(error)}`
|
|
3897
|
+
);
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
let status = accepted;
|
|
3902
|
+
const { value: registered } = await pollUntil(async () => {
|
|
3903
|
+
const current = status ?? await this.getFirstPermitDepositStatus(request.owner);
|
|
3904
|
+
status = null;
|
|
3905
|
+
if (current?.id !== id || !matchesFirstPermitDeposit(current, request)) {
|
|
3906
|
+
throw new Error(`Unable to resolve first permit deposit ${id}. Check getFirstPermitDepositStatus before retrying.`);
|
|
3907
|
+
}
|
|
3908
|
+
if (current.status === "failed") {
|
|
3909
|
+
throw new Error(`First permit deposit ${id} failed`);
|
|
3910
|
+
}
|
|
3911
|
+
return current;
|
|
3912
|
+
}, (current) => current.status === "registered", {
|
|
3913
|
+
intervalMs: 3e3,
|
|
3914
|
+
label: `first permit deposit ${id} registration. Check getFirstPermitDepositStatus before retrying`
|
|
3915
|
+
});
|
|
3916
|
+
if (!registered.txHash || !registered.depositId) {
|
|
3917
|
+
throw new Error(`First permit deposit ${id} is missing its registration. Check getFirstPermitDepositStatus before retrying.`);
|
|
3918
|
+
}
|
|
3919
|
+
return {
|
|
3920
|
+
success: true,
|
|
3921
|
+
txHash: registered.txHash,
|
|
3922
|
+
smartWallet: request.safe,
|
|
3923
|
+
amount: registered.amount,
|
|
3924
|
+
route: "direct",
|
|
3925
|
+
registration: await this.getDepositStatus(registered.depositId)
|
|
3926
|
+
};
|
|
3927
|
+
}
|
|
3745
3928
|
async sendDeposit(userAddressOrParams, chainId, amount, asset, strategy) {
|
|
3746
3929
|
if (typeof userAddressOrParams !== "string") {
|
|
3747
3930
|
return this.sendRoutedDeposit(userAddressOrParams);
|
|
@@ -4030,12 +4213,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4030
4213
|
BigInt(params.amount)
|
|
4031
4214
|
);
|
|
4032
4215
|
await this.wrapNativeEth(params.chainId, params.amount);
|
|
4033
|
-
const sent = await this.
|
|
4216
|
+
const sent = await this.sendCollateralDeposit(
|
|
4034
4217
|
params.userAddress,
|
|
4035
4218
|
params.chainId,
|
|
4036
4219
|
params.amount,
|
|
4037
4220
|
"WETH",
|
|
4038
|
-
params.strategy
|
|
4221
|
+
params.strategy,
|
|
4222
|
+
false
|
|
4039
4223
|
);
|
|
4040
4224
|
return { ...sent, route: "wrap" };
|
|
4041
4225
|
}
|
|
@@ -4123,16 +4307,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4123
4307
|
method: "wallet_switchEthereumChain",
|
|
4124
4308
|
params: [{ chainId: `0x${originChainId.toString(16)}` }]
|
|
4125
4309
|
});
|
|
4126
|
-
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0,
|
|
4310
|
+
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0, import_viem6.defineChain)({
|
|
4127
4311
|
id: originChainId,
|
|
4128
4312
|
name: `Chain ${originChainId}`,
|
|
4129
4313
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
4130
4314
|
rpcUrls: { default: { http: ["http://127.0.0.1"] } }
|
|
4131
4315
|
});
|
|
4132
|
-
this.walletClient = (0,
|
|
4316
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
4133
4317
|
account: this.walletClient.account,
|
|
4134
4318
|
chain,
|
|
4135
|
-
transport: (0,
|
|
4319
|
+
transport: (0, import_viem6.custom)(this.currentProvider)
|
|
4136
4320
|
});
|
|
4137
4321
|
if (isSupportedChain(originChainId)) {
|
|
4138
4322
|
this.currentChainId = originChainId;
|
|
@@ -4308,7 +4492,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4308
4492
|
safeAddress,
|
|
4309
4493
|
tokenAddress,
|
|
4310
4494
|
to: tokenAddress,
|
|
4311
|
-
data: (0,
|
|
4495
|
+
data: (0, import_viem6.encodeFunctionData)({
|
|
4312
4496
|
abi: ERC20_ABI,
|
|
4313
4497
|
functionName: "transfer",
|
|
4314
4498
|
args: [safeAddress, amountBigInt]
|
|
@@ -4337,7 +4521,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4337
4521
|
if (!userAddress) {
|
|
4338
4522
|
throw new Error("A user address is required");
|
|
4339
4523
|
}
|
|
4340
|
-
const owner = (0,
|
|
4524
|
+
const owner = (0, import_viem6.getAddress)(userAddress);
|
|
4341
4525
|
const chainId = 8453;
|
|
4342
4526
|
await this.hydrateSessionWallet();
|
|
4343
4527
|
const safe = await this.getSafeAddressFor(owner, chainId);
|
|
@@ -4359,7 +4543,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4359
4543
|
]).catch(() => {
|
|
4360
4544
|
throw new Error(`Safe ${safe} is not deployed on Base`);
|
|
4361
4545
|
});
|
|
4362
|
-
if (threshold !== 1n || !owners.some((o) => (0,
|
|
4546
|
+
if (threshold !== 1n || !owners.some((o) => (0, import_viem6.getAddress)(o) === owner)) {
|
|
4363
4547
|
throw new Error(
|
|
4364
4548
|
`${owner} cannot execute Safe ${safe} alone (not an owner, or threshold above 1)`
|
|
4365
4549
|
);
|
|
@@ -4448,7 +4632,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4448
4632
|
if (!userAddress) {
|
|
4449
4633
|
throw new Error("A user address is required");
|
|
4450
4634
|
}
|
|
4451
|
-
if (this.sessionEoa && (0,
|
|
4635
|
+
if (this.sessionEoa && (0, import_viem6.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4452
4636
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4453
4637
|
}
|
|
4454
4638
|
}
|
|
@@ -4514,7 +4698,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4514
4698
|
async ensureFirstDepositSetup(strategy) {
|
|
4515
4699
|
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
4516
4700
|
throw new Error(
|
|
4517
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
4701
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
4518
4702
|
);
|
|
4519
4703
|
}
|
|
4520
4704
|
await this.authenticateUser();
|
|
@@ -4547,7 +4731,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4547
4731
|
const { strategy, asset, chainId } = params;
|
|
4548
4732
|
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
4549
4733
|
throw new Error(
|
|
4550
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
4734
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
4551
4735
|
);
|
|
4552
4736
|
}
|
|
4553
4737
|
await this.authenticateUser();
|
|
@@ -4594,7 +4778,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4594
4778
|
*/
|
|
4595
4779
|
async prepareDeposit(params) {
|
|
4596
4780
|
const { userAddress, chainId, amount, asset } = params;
|
|
4597
|
-
if (this.sessionEoa && (0,
|
|
4781
|
+
if (this.sessionEoa && (0, import_viem6.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4598
4782
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4599
4783
|
}
|
|
4600
4784
|
const setup = await this.ensureDepositProfileForPrepare({
|
|
@@ -4930,7 +5114,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4930
5114
|
* Note: The withdrawal is processed asynchronously, so txHash may not be immediately available
|
|
4931
5115
|
* Funds are always withdrawn to the Safe owner's address (userAddress)
|
|
4932
5116
|
*
|
|
4933
|
-
* **Delayed withdrawals.** Positions held under the `"
|
|
5117
|
+
* **Delayed withdrawals.** Positions held under the `"yieldmaxxing"`
|
|
4934
5118
|
* strategy sit in protocols that cannot be exited on demand. For those the
|
|
4935
5119
|
* backend transfers the immediately available portion, then queues a
|
|
4936
5120
|
* redemption for the rest and forwards the funds to the EOA once the
|
|
@@ -5177,7 +5361,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5177
5361
|
* a snapshot, so net values can differ slightly from a fully live calc.
|
|
5178
5362
|
*
|
|
5179
5363
|
* **Total balance.** `portfolioByAssetType` sums deployed positions and idle
|
|
5180
|
-
* Safe balances, and nothing else. Under the `"
|
|
5364
|
+
* Safe balances, and nothing else. Under the `"yieldmaxxing"` strategy a
|
|
5181
5365
|
* redemption in flight has already left its position and has not landed in
|
|
5182
5366
|
* the Safe yet, so its funds appear in no balance field at all. That makes
|
|
5183
5367
|
* two distinct numbers:
|
|
@@ -5202,7 +5386,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5202
5386
|
* @group Portfolio and execution
|
|
5203
5387
|
*
|
|
5204
5388
|
* @remarks Data API portfolio endpoint. See {@link PortfolioDetailed.pendingAsyncWithdrawals}
|
|
5205
|
-
* when using {@link Strategy |
|
|
5389
|
+
* when using {@link Strategy | yieldmaxxing}.
|
|
5206
5390
|
*
|
|
5207
5391
|
* @param userAddress - User's EOA address
|
|
5208
5392
|
* @returns Portfolio with optional fee-adjusted balance fields
|
|
@@ -5400,7 +5584,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5400
5584
|
*
|
|
5401
5585
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
5402
5586
|
* @param days - Time period: 7, 14, or 30
|
|
5403
|
-
* @param strategy - Strategy type: "conservative" (default), "
|
|
5587
|
+
* @param strategy - Strategy type: "conservative" (default), "aggressive" or "yieldmaxxing"
|
|
5404
5588
|
* @param chainId - Optional chain ID filter
|
|
5405
5589
|
* @param tokenSymbol - Optional token symbol filter (e.g. "USDC", "WETH", "WBTC")
|
|
5406
5590
|
* @returns APY per strategy for a specific chain
|
|
@@ -5810,6 +5994,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5810
5994
|
/**
|
|
5811
5995
|
* Get conservative (low-risk) yield opportunities.
|
|
5812
5996
|
*
|
|
5997
|
+
* Omitting `status` requests live pools only. Pass `"not_live"` for retired pools.
|
|
5998
|
+
*
|
|
5813
5999
|
* @group Analytics and opportunities
|
|
5814
6000
|
*
|
|
5815
6001
|
* @remarks Data API. Partner API key only.
|
|
@@ -5855,19 +6041,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5855
6041
|
}
|
|
5856
6042
|
}
|
|
5857
6043
|
/**
|
|
5858
|
-
* Get
|
|
6044
|
+
* Get balanced (high-risk, high-reward) yield opportunities.
|
|
6045
|
+
*
|
|
6046
|
+
* Omitting `status` requests live pools only. Pass `"not_live"` for retired pools.
|
|
5859
6047
|
*
|
|
5860
6048
|
* @param chainId - Optional chain ID filter
|
|
5861
6049
|
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
5862
|
-
* @returns List of
|
|
6050
|
+
* @returns List of balanced opportunities
|
|
5863
6051
|
*
|
|
5864
6052
|
* @example
|
|
5865
6053
|
* ```typescript
|
|
5866
|
-
* const opportunities = await sdk.
|
|
6054
|
+
* const opportunities = await sdk.getBalancedOpportunities(8453, "WETH");
|
|
5867
6055
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
5868
6056
|
* ```
|
|
5869
6057
|
*/
|
|
5870
|
-
async
|
|
6058
|
+
async getBalancedOpportunities(chainId, asset, status) {
|
|
5871
6059
|
try {
|
|
5872
6060
|
const response = await this.httpClient.dataGet(
|
|
5873
6061
|
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset, status)
|
|
@@ -5893,28 +6081,43 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5893
6081
|
};
|
|
5894
6082
|
} catch (error) {
|
|
5895
6083
|
throw new Error(
|
|
5896
|
-
`Failed to get
|
|
6084
|
+
`Failed to get balanced opportunities: ${error.message}`
|
|
5897
6085
|
);
|
|
5898
6086
|
}
|
|
5899
6087
|
}
|
|
5900
6088
|
/**
|
|
5901
|
-
*
|
|
6089
|
+
* @deprecated Use {@link getBalancedOpportunities} instead. Retains the
|
|
6090
|
+
* pre-rename `getAggressiveOpportunities` entry point; same HTTP request as
|
|
6091
|
+
* balanced, with legacy `strategyType: "aggressive"` on the response and rows.
|
|
6092
|
+
*/
|
|
6093
|
+
async getAggressiveOpportunities(chainId, asset, status) {
|
|
6094
|
+
const result = await this.getBalancedOpportunities(chainId, asset, status);
|
|
6095
|
+
return {
|
|
6096
|
+
...result,
|
|
6097
|
+
strategyType: "aggressive",
|
|
6098
|
+
data: result.data.map((o) => ({ ...o, strategyType: "aggressive" }))
|
|
6099
|
+
};
|
|
6100
|
+
}
|
|
6101
|
+
/**
|
|
6102
|
+
* Get advanced yield opportunities — pools reachable only with the
|
|
5902
6103
|
* `"advanced"` strategy, including protocols whose withdrawals are
|
|
5903
6104
|
* asynchronous (Ipor, Superform). Exiting these pools takes about a day
|
|
5904
6105
|
* on Ipor and three on Superform; track the redemption through
|
|
5905
6106
|
* `getPortfolio().portfolio.pendingAsyncWithdrawals`.
|
|
5906
6107
|
*
|
|
6108
|
+
* Omitting `status` requests live pools only. Pass `"not_live"` for retired pools.
|
|
6109
|
+
*
|
|
5907
6110
|
* @param chainId - Optional chain ID filter
|
|
5908
6111
|
* @param asset - Optional asset filter (e.g. "USDC", "WETH")
|
|
5909
|
-
* @returns List of
|
|
6112
|
+
* @returns List of advanced opportunities
|
|
5910
6113
|
*
|
|
5911
6114
|
* @example
|
|
5912
6115
|
* ```typescript
|
|
5913
|
-
* const opportunities = await sdk.
|
|
6116
|
+
* const opportunities = await sdk.getAdvancedOpportunities(8453);
|
|
5914
6117
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
5915
6118
|
* ```
|
|
5916
6119
|
*/
|
|
5917
|
-
async
|
|
6120
|
+
async getAdvancedOpportunities(chainId, asset, status) {
|
|
5918
6121
|
try {
|
|
5919
6122
|
const response = await this.httpClient.dataGet(
|
|
5920
6123
|
DATA_ENDPOINTS.OPPORTUNITIES_ASYNC(chainId, asset, status)
|
|
@@ -5940,10 +6143,23 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5940
6143
|
};
|
|
5941
6144
|
} catch (error) {
|
|
5942
6145
|
throw new Error(
|
|
5943
|
-
`Failed to get
|
|
6146
|
+
`Failed to get advanced opportunities: ${error.message}`
|
|
5944
6147
|
);
|
|
5945
6148
|
}
|
|
5946
6149
|
}
|
|
6150
|
+
/**
|
|
6151
|
+
* @deprecated Use {@link getAdvancedOpportunities} instead. Retains the
|
|
6152
|
+
* pre-rename `getAsyncOpportunities` entry point; same HTTP request as
|
|
6153
|
+
* advanced, with legacy `strategyType: "yieldmaxxing"` on the response and rows.
|
|
6154
|
+
*/
|
|
6155
|
+
async getAsyncOpportunities(chainId, asset, status) {
|
|
6156
|
+
const result = await this.getAdvancedOpportunities(chainId, asset, status);
|
|
6157
|
+
return {
|
|
6158
|
+
...result,
|
|
6159
|
+
strategyType: "yieldmaxxing",
|
|
6160
|
+
data: result.data.map((o) => ({ ...o, strategyType: "yieldmaxxing" }))
|
|
6161
|
+
};
|
|
6162
|
+
}
|
|
5947
6163
|
/**
|
|
5948
6164
|
* Get active conservative opportunities (status = "live") with risk and utilization data
|
|
5949
6165
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
@@ -6465,7 +6681,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6465
6681
|
if (strategy) {
|
|
6466
6682
|
if (!isValidPublicStrategy(strategy)) {
|
|
6467
6683
|
throw new Error(
|
|
6468
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
6684
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
6469
6685
|
);
|
|
6470
6686
|
}
|
|
6471
6687
|
internalStrategy = toInternalStrategy(strategy);
|
|
@@ -6515,7 +6731,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6515
6731
|
try {
|
|
6516
6732
|
if (!isValidPublicStrategy(params.strategy)) {
|
|
6517
6733
|
throw new Error(
|
|
6518
|
-
`Invalid strategy: ${params.strategy}. Must be "conservative", "
|
|
6734
|
+
`Invalid strategy: ${params.strategy}. Must be "conservative", "aggressive" or "yieldmaxxing".`
|
|
6519
6735
|
);
|
|
6520
6736
|
}
|
|
6521
6737
|
const internalStrategy = toInternalStrategy(params.strategy);
|
|
@@ -6614,7 +6830,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6614
6830
|
if (!tokenUriResponse.tokenUri) {
|
|
6615
6831
|
throw new Error("API did not return a tokenUri");
|
|
6616
6832
|
}
|
|
6617
|
-
const callData = (0,
|
|
6833
|
+
const callData = (0, import_viem6.encodeFunctionData)({
|
|
6618
6834
|
abi: IDENTITY_REGISTRY_ABI,
|
|
6619
6835
|
functionName: "register",
|
|
6620
6836
|
args: [tokenUriResponse.tokenUri]
|