@zyfai/sdk 0.13.0 → 0.15.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 +21 -7
- package/dist/index.d.mts +70 -17
- package/dist/index.d.ts +70 -17
- package/dist/index.js +243 -51
- package/dist/index.mjs +214 -21
- 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`,
|
|
@@ -335,8 +338,9 @@ var HttpClient = class {
|
|
|
335
338
|
case 403:
|
|
336
339
|
throw new Error("Forbidden: Access denied");
|
|
337
340
|
case 404:
|
|
338
|
-
throw
|
|
339
|
-
`Not found: ${data.message || "Resource not found"}`
|
|
341
|
+
throw Object.assign(
|
|
342
|
+
new Error(`Not found: ${data.message || "Resource not found"}`),
|
|
343
|
+
{ status }
|
|
340
344
|
);
|
|
341
345
|
case 429:
|
|
342
346
|
throw new Error("Rate limit exceeded. Please try again later.");
|
|
@@ -459,6 +463,20 @@ var HttpClient = class {
|
|
|
459
463
|
};
|
|
460
464
|
|
|
461
465
|
// src/utils/poll.ts
|
|
466
|
+
async function pollUntil(fn, predicate, options) {
|
|
467
|
+
const intervalMs = options?.intervalMs ?? 5e3;
|
|
468
|
+
const timeoutMs = options?.timeoutMs ?? 12e4;
|
|
469
|
+
const label = options?.label ?? "condition";
|
|
470
|
+
const started = Date.now();
|
|
471
|
+
while (Date.now() - started < timeoutMs) {
|
|
472
|
+
const value = await fn();
|
|
473
|
+
if (predicate(value)) {
|
|
474
|
+
return { value, elapsedMs: Date.now() - started };
|
|
475
|
+
}
|
|
476
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
477
|
+
}
|
|
478
|
+
throw new Error(`Timed out waiting for ${label} after ${timeoutMs}ms`);
|
|
479
|
+
}
|
|
462
480
|
function sleep(ms) {
|
|
463
481
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
464
482
|
}
|
|
@@ -882,7 +900,7 @@ function isMainnetMinPortfolioExempt(chainId, ...addresses) {
|
|
|
882
900
|
|
|
883
901
|
// src/core/ZyfaiSDK.ts
|
|
884
902
|
var import_accounts2 = require("viem/accounts");
|
|
885
|
-
var
|
|
903
|
+
var import_viem6 = require("viem");
|
|
886
904
|
var import_relay_sdk2 = require("@relayprotocol/relay-sdk");
|
|
887
905
|
|
|
888
906
|
// src/config/chains.ts
|
|
@@ -1198,6 +1216,29 @@ var positiveUnits = (value) => {
|
|
|
1198
1216
|
};
|
|
1199
1217
|
var resolveCollateralMinimum = (storedMinimum, quote) => positiveUnits(storedMinimum) ?? positiveUnits(quote.details?.currencyOut?.minimumAmount) ?? positiveUnits(quote.details?.currencyOut?.amount) ?? "0";
|
|
1200
1218
|
|
|
1219
|
+
// src/deposits/first-permit-deposit.ts
|
|
1220
|
+
var import_viem4 = require("viem");
|
|
1221
|
+
var firstPermitTypes = {
|
|
1222
|
+
Permit: [
|
|
1223
|
+
{ name: "owner", type: "address" },
|
|
1224
|
+
{ name: "spender", type: "address" },
|
|
1225
|
+
{ name: "value", type: "uint256" },
|
|
1226
|
+
{ name: "nonce", type: "uint256" },
|
|
1227
|
+
{ name: "deadline", type: "uint256" }
|
|
1228
|
+
]
|
|
1229
|
+
};
|
|
1230
|
+
function matchesFirstPermitDeposit(intent, request) {
|
|
1231
|
+
return intent.chainId === request.chainId && (0, import_viem4.isAddressEqual)(intent.token, request.token) && intent.amount === request.amount.toString();
|
|
1232
|
+
}
|
|
1233
|
+
function validateFirstPermit({ domain, message }, request) {
|
|
1234
|
+
const value = BigInt(message.value);
|
|
1235
|
+
const nonce = BigInt(message.nonce);
|
|
1236
|
+
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)) {
|
|
1237
|
+
throw new Error("Prepared permit does not match this deposit");
|
|
1238
|
+
}
|
|
1239
|
+
return { ...message, value, nonce, deadline: BigInt(message.deadline) };
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1201
1242
|
// src/deposits/relay-slippage.ts
|
|
1202
1243
|
var DEFAULT_RELAY_SLIPPAGE_BPS = 200;
|
|
1203
1244
|
var MAX_RELAY_SLIPPAGE_BPS = 500;
|
|
@@ -1321,7 +1362,7 @@ function getManagedAssets() {
|
|
|
1321
1362
|
// src/utils/safe-account.ts
|
|
1322
1363
|
var import_module_sdk = require("@rhinestone/module-sdk");
|
|
1323
1364
|
var import_accounts = require("permissionless/accounts");
|
|
1324
|
-
var
|
|
1365
|
+
var import_viem5 = require("viem");
|
|
1325
1366
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
1326
1367
|
|
|
1327
1368
|
// src/config/modules.ts
|
|
@@ -1351,12 +1392,12 @@ var getSafeAccount = async (config) => {
|
|
|
1351
1392
|
if (!safeOwnerAddress) {
|
|
1352
1393
|
throw new Error("Safe owner address is required");
|
|
1353
1394
|
}
|
|
1354
|
-
const formattedOwnerAddress = (0,
|
|
1395
|
+
const formattedOwnerAddress = (0, import_viem5.getAddress)(safeOwnerAddress);
|
|
1355
1396
|
const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
|
|
1356
1397
|
owners: [formattedOwnerAddress],
|
|
1357
1398
|
threshold: 1
|
|
1358
1399
|
});
|
|
1359
|
-
const saltHex = (0,
|
|
1400
|
+
const saltHex = (0, import_viem5.fromHex)((0, import_viem5.toHex)(ACCOUNT_SALT), "bigint");
|
|
1360
1401
|
const tempOwner = {
|
|
1361
1402
|
address: formattedOwnerAddress,
|
|
1362
1403
|
type: "json-rpc"
|
|
@@ -1403,12 +1444,12 @@ var isSafeDeployed = async (address, publicClient) => {
|
|
|
1403
1444
|
}
|
|
1404
1445
|
};
|
|
1405
1446
|
var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
|
|
1406
|
-
const normalizedUser = (0,
|
|
1407
|
-
const normalizedSafe = (0,
|
|
1447
|
+
const normalizedUser = (0, import_viem5.getAddress)(userAddress);
|
|
1448
|
+
const normalizedSafe = (0, import_viem5.getAddress)(safeAddress);
|
|
1408
1449
|
const validatorAddresses = Array.from(
|
|
1409
1450
|
/* @__PURE__ */ new Set([
|
|
1410
|
-
(0,
|
|
1411
|
-
(0,
|
|
1451
|
+
(0, import_viem5.getAddress)(OWNABLE_VALIDATOR),
|
|
1452
|
+
(0, import_viem5.getAddress)(import_module_sdk.OWNABLE_VALIDATOR_ADDRESS)
|
|
1412
1453
|
])
|
|
1413
1454
|
);
|
|
1414
1455
|
for (const validatorAddress of validatorAddresses) {
|
|
@@ -1419,7 +1460,7 @@ var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) =>
|
|
|
1419
1460
|
functionName: "getOwners",
|
|
1420
1461
|
args: [normalizedSafe]
|
|
1421
1462
|
});
|
|
1422
|
-
if (owners.some((owner) => (0,
|
|
1463
|
+
if (owners.some((owner) => (0, import_viem5.getAddress)(owner) === normalizedUser)) {
|
|
1423
1464
|
return true;
|
|
1424
1465
|
}
|
|
1425
1466
|
} catch {
|
|
@@ -2197,7 +2238,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2197
2238
|
}
|
|
2198
2239
|
this.httpClient.setAuthToken(session.accessToken);
|
|
2199
2240
|
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
2200
|
-
this.sessionEoa = session.eoa ? (0,
|
|
2241
|
+
this.sessionEoa = session.eoa ? (0, import_viem6.getAddress)(session.eoa) : null;
|
|
2201
2242
|
this.sessionChannel = session.channel;
|
|
2202
2243
|
this.isPredeployed = false;
|
|
2203
2244
|
this.predeployedResolved = false;
|
|
@@ -2246,7 +2287,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2246
2287
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
2247
2288
|
this.predeployedResolved = true;
|
|
2248
2289
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
2249
|
-
this.sessionEoa = (0,
|
|
2290
|
+
this.sessionEoa = (0, import_viem6.getAddress)(params.message.address);
|
|
2250
2291
|
this.sessionChannel = void 0;
|
|
2251
2292
|
return loginResponse;
|
|
2252
2293
|
}
|
|
@@ -2275,7 +2316,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2275
2316
|
return;
|
|
2276
2317
|
}
|
|
2277
2318
|
const walletClient = this.getWalletClient();
|
|
2278
|
-
const userAddress = (0,
|
|
2319
|
+
const userAddress = (0, import_viem6.getAddress)(walletClient.account.address);
|
|
2279
2320
|
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
2280
2321
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
2281
2322
|
let uri;
|
|
@@ -2653,10 +2694,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2653
2694
|
this.walletClient.chain?.id || 8453,
|
|
2654
2695
|
this.rpcUrls
|
|
2655
2696
|
);
|
|
2656
|
-
this.walletClient = (0,
|
|
2697
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
2657
2698
|
account: newAddress,
|
|
2658
2699
|
chain: chainConfig.chain,
|
|
2659
|
-
transport: (0,
|
|
2700
|
+
transport: (0, import_viem6.custom)(this.currentProvider)
|
|
2660
2701
|
});
|
|
2661
2702
|
this.currentChainId = this.walletClient.chain?.id || null;
|
|
2662
2703
|
try {
|
|
@@ -2721,10 +2762,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2721
2762
|
}
|
|
2722
2763
|
this.signer = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
2723
2764
|
this.currentChainId = chainId;
|
|
2724
|
-
this.walletClient = (0,
|
|
2765
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
2725
2766
|
account: this.signer,
|
|
2726
2767
|
chain: chainConfig.chain,
|
|
2727
|
-
transport: (0,
|
|
2768
|
+
transport: (0, import_viem6.http)(chainConfig.rpcUrl)
|
|
2728
2769
|
});
|
|
2729
2770
|
connectedAddress = this.signer.address;
|
|
2730
2771
|
this.currentProvider = null;
|
|
@@ -2742,10 +2783,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2742
2783
|
if (!accounts || accounts.length === 0) {
|
|
2743
2784
|
throw new Error("No accounts found in wallet provider");
|
|
2744
2785
|
}
|
|
2745
|
-
this.walletClient = (0,
|
|
2786
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
2746
2787
|
account: accounts[0],
|
|
2747
2788
|
chain: chainConfig.chain,
|
|
2748
|
-
transport: (0,
|
|
2789
|
+
transport: (0, import_viem6.custom)(provider)
|
|
2749
2790
|
});
|
|
2750
2791
|
connectedAddress = accounts[0];
|
|
2751
2792
|
this.currentProvider = provider;
|
|
@@ -2754,7 +2795,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2754
2795
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
2755
2796
|
}
|
|
2756
2797
|
} else if (provider.account && provider.transport) {
|
|
2757
|
-
this.walletClient = (0,
|
|
2798
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
2758
2799
|
account: provider.account,
|
|
2759
2800
|
chain: chainConfig.chain,
|
|
2760
2801
|
transport: provider.transport
|
|
@@ -2815,10 +2856,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2815
2856
|
targetChainId,
|
|
2816
2857
|
this.rpcUrls
|
|
2817
2858
|
);
|
|
2818
|
-
return (0,
|
|
2859
|
+
return (0, import_viem6.createWalletClient)({
|
|
2819
2860
|
account: this.signer,
|
|
2820
2861
|
chain: targetChainConfig.chain,
|
|
2821
|
-
transport: (0,
|
|
2862
|
+
transport: (0, import_viem6.http)(targetChainConfig.rpcUrl)
|
|
2822
2863
|
});
|
|
2823
2864
|
} else {
|
|
2824
2865
|
if (!this.walletClient) {
|
|
@@ -3588,14 +3629,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3588
3629
|
return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
|
|
3589
3630
|
}
|
|
3590
3631
|
/**
|
|
3591
|
-
*
|
|
3632
|
+
* Deposit a collateral token the wallet already holds into the Safe.
|
|
3592
3633
|
*
|
|
3593
3634
|
* @remarks
|
|
3594
3635
|
* Use this when the connected wallet holds the strategy collateral on the
|
|
3595
3636
|
* deposit chain. {@link ZyfaiSDK.sendDeposit} calls this automatically in
|
|
3596
3637
|
* that case. A different token uses {@link ZyfaiSDK.sendSwapDeposit}.
|
|
3597
3638
|
*
|
|
3598
|
-
*
|
|
3639
|
+
* Eligible first deposits sign an ERC-2612 permit and the backend sponsors and
|
|
3640
|
+
* registers the pull. Other direct deposits confirm an ERC-20 transfer and
|
|
3641
|
+
* call {@link ZyfaiSDK.logDeposit}.
|
|
3599
3642
|
* Requires {@link ZyfaiSDK.connectAccount}. Pass the **EOA** as `userAddress`.
|
|
3600
3643
|
*
|
|
3601
3644
|
* @group Deposits and withdrawals
|
|
@@ -3619,6 +3662,9 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3619
3662
|
* ```
|
|
3620
3663
|
*/
|
|
3621
3664
|
async sendDirectDeposit(userAddress, chainId, amount, asset, strategy) {
|
|
3665
|
+
return this.sendCollateralDeposit(userAddress, chainId, amount, asset, strategy, true);
|
|
3666
|
+
}
|
|
3667
|
+
async sendCollateralDeposit(userAddress, chainId, amount, asset, strategy, allowPermit) {
|
|
3622
3668
|
try {
|
|
3623
3669
|
if (!userAddress) {
|
|
3624
3670
|
throw new Error("User address is required");
|
|
@@ -3710,6 +3756,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3710
3756
|
);
|
|
3711
3757
|
}
|
|
3712
3758
|
}
|
|
3759
|
+
if (allowPermit && this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
3760
|
+
const sponsored = await this.sendFirstPermitDeposit({
|
|
3761
|
+
owner: (0, import_viem6.getAddress)(userAddress),
|
|
3762
|
+
safe: safeAddress,
|
|
3763
|
+
chainId,
|
|
3764
|
+
token: (0, import_viem6.getAddress)(token),
|
|
3765
|
+
amount: amountBigInt
|
|
3766
|
+
});
|
|
3767
|
+
if (sponsored) return sponsored;
|
|
3768
|
+
}
|
|
3713
3769
|
const txHash = await walletClient.writeContract({
|
|
3714
3770
|
address: token,
|
|
3715
3771
|
abi: erc20TransferWriteAbi(assetSymbol),
|
|
@@ -3742,6 +3798,115 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3742
3798
|
throw new Error(`Deposit failed: ${error.message}`);
|
|
3743
3799
|
}
|
|
3744
3800
|
}
|
|
3801
|
+
/**
|
|
3802
|
+
* Read the current first-deposit permit intent after a pending or interrupted deposit.
|
|
3803
|
+
*
|
|
3804
|
+
* @remarks
|
|
3805
|
+
* Uses the execution API and the SIWE session from {@link ZyfaiSDK.connectAccount}.
|
|
3806
|
+
* A registered intent provides the deposit id for {@link ZyfaiSDK.getDepositStatus}.
|
|
3807
|
+
*
|
|
3808
|
+
* @group Deposits and withdrawals
|
|
3809
|
+
*
|
|
3810
|
+
* @param userAddress - Authenticated EOA
|
|
3811
|
+
* @returns The latest permit intent, or null when no intent exists
|
|
3812
|
+
* @throws If the address differs from the authenticated EOA or the request fails
|
|
3813
|
+
*
|
|
3814
|
+
* @example
|
|
3815
|
+
* ```typescript
|
|
3816
|
+
* const intent = await sdk.getFirstPermitDepositStatus(eoa);
|
|
3817
|
+
* if (intent?.depositId) await sdk.waitForDepositCredit(intent.depositId, intent.chainId);
|
|
3818
|
+
* ```
|
|
3819
|
+
*/
|
|
3820
|
+
async getFirstPermitDepositStatus(userAddress) {
|
|
3821
|
+
if (!this.sessionEoa || !(0, import_viem6.isAddressEqual)((0, import_viem6.getAddress)(userAddress), this.sessionEoa)) {
|
|
3822
|
+
throw new Error("userAddress does not match authenticated session EOA");
|
|
3823
|
+
}
|
|
3824
|
+
return (await this.getFirstPermitDepositAvailability()).intent;
|
|
3825
|
+
}
|
|
3826
|
+
async getFirstPermitDepositAvailability(chainId) {
|
|
3827
|
+
try {
|
|
3828
|
+
return await this.httpClient.get(
|
|
3829
|
+
ENDPOINTS.FIRST_PERMIT_DEPOSIT,
|
|
3830
|
+
chainId != null ? { params: { chainId } } : void 0
|
|
3831
|
+
);
|
|
3832
|
+
} catch (error) {
|
|
3833
|
+
if (error instanceof Error && "status" in error && error.status === 404) {
|
|
3834
|
+
return { enabledTokens: [], intent: null };
|
|
3835
|
+
}
|
|
3836
|
+
throw error;
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
async sendFirstPermitDeposit(request) {
|
|
3840
|
+
const { enabledTokens, intent, permitPreferred } = await this.getFirstPermitDepositAvailability(request.chainId);
|
|
3841
|
+
let id;
|
|
3842
|
+
let accepted;
|
|
3843
|
+
if (intent?.status === "queued" || intent?.status === "submitted") {
|
|
3844
|
+
if (!matchesFirstPermitDeposit(intent, request)) {
|
|
3845
|
+
throw new Error(`First permit deposit ${intent.id} is already pending for a different deposit`);
|
|
3846
|
+
}
|
|
3847
|
+
id = intent.id;
|
|
3848
|
+
accepted = intent;
|
|
3849
|
+
} else {
|
|
3850
|
+
const { owner, chainId, token, amount } = request;
|
|
3851
|
+
if (permitPreferred === false) return null;
|
|
3852
|
+
if (!enabledTokens.includes(`${chainId}:${token.toLowerCase()}`)) return null;
|
|
3853
|
+
const prepared = await this.httpClient.post(
|
|
3854
|
+
ENDPOINTS.FIRST_PERMIT_DEPOSIT_PREPARE,
|
|
3855
|
+
{ owner, chainId, token, amount: amount.toString() }
|
|
3856
|
+
);
|
|
3857
|
+
if (!prepared) return null;
|
|
3858
|
+
const message = validateFirstPermit(prepared, request);
|
|
3859
|
+
const currentWallet = this.getWalletClient();
|
|
3860
|
+
const wallet = currentWallet.chain?.id === chainId ? currentWallet : await this.walletClientForOrigin(chainId);
|
|
3861
|
+
const signature = await wallet.signTypedData({
|
|
3862
|
+
account: wallet.account,
|
|
3863
|
+
domain: prepared.domain,
|
|
3864
|
+
types: firstPermitTypes,
|
|
3865
|
+
primaryType: "Permit",
|
|
3866
|
+
message
|
|
3867
|
+
});
|
|
3868
|
+
id = prepared.id;
|
|
3869
|
+
try {
|
|
3870
|
+
accepted = await this.httpClient.post(
|
|
3871
|
+
ENDPOINTS.FIRST_PERMIT_DEPOSIT_SUBMIT(id),
|
|
3872
|
+
{ signature }
|
|
3873
|
+
);
|
|
3874
|
+
} catch (error) {
|
|
3875
|
+
accepted = await this.getFirstPermitDepositStatus(owner).catch(() => null);
|
|
3876
|
+
if (accepted?.id !== id || accepted.status === "prepared") {
|
|
3877
|
+
throw new Error(
|
|
3878
|
+
`Could not confirm first permit deposit ${id}. Check getFirstPermitDepositStatus before retrying: ${thrownMessage(error)}`
|
|
3879
|
+
);
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
let status = accepted;
|
|
3884
|
+
const { value: registered } = await pollUntil(async () => {
|
|
3885
|
+
const current = status ?? await this.getFirstPermitDepositStatus(request.owner);
|
|
3886
|
+
status = null;
|
|
3887
|
+
if (current?.id !== id || !matchesFirstPermitDeposit(current, request)) {
|
|
3888
|
+
throw new Error(`Unable to resolve first permit deposit ${id}. Check getFirstPermitDepositStatus before retrying.`);
|
|
3889
|
+
}
|
|
3890
|
+
if (current.status === "failed") {
|
|
3891
|
+
throw new Error(`First permit deposit ${id} failed`);
|
|
3892
|
+
}
|
|
3893
|
+
return current;
|
|
3894
|
+
}, (current) => current.status === "registered", {
|
|
3895
|
+
intervalMs: 3e3,
|
|
3896
|
+
label: `first permit deposit ${id} registration. Check getFirstPermitDepositStatus before retrying`
|
|
3897
|
+
});
|
|
3898
|
+
if (!registered.txHash || !registered.depositId) {
|
|
3899
|
+
throw new Error(`First permit deposit ${id} is missing its registration. Check getFirstPermitDepositStatus before retrying.`);
|
|
3900
|
+
}
|
|
3901
|
+
return {
|
|
3902
|
+
success: true,
|
|
3903
|
+
txHash: registered.txHash,
|
|
3904
|
+
smartWallet: request.safe,
|
|
3905
|
+
amount: registered.amount,
|
|
3906
|
+
route: "direct",
|
|
3907
|
+
registration: await this.getDepositStatus(registered.depositId)
|
|
3908
|
+
};
|
|
3909
|
+
}
|
|
3745
3910
|
async sendDeposit(userAddressOrParams, chainId, amount, asset, strategy) {
|
|
3746
3911
|
if (typeof userAddressOrParams !== "string") {
|
|
3747
3912
|
return this.sendRoutedDeposit(userAddressOrParams);
|
|
@@ -4030,12 +4195,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4030
4195
|
BigInt(params.amount)
|
|
4031
4196
|
);
|
|
4032
4197
|
await this.wrapNativeEth(params.chainId, params.amount);
|
|
4033
|
-
const sent = await this.
|
|
4198
|
+
const sent = await this.sendCollateralDeposit(
|
|
4034
4199
|
params.userAddress,
|
|
4035
4200
|
params.chainId,
|
|
4036
4201
|
params.amount,
|
|
4037
4202
|
"WETH",
|
|
4038
|
-
params.strategy
|
|
4203
|
+
params.strategy,
|
|
4204
|
+
false
|
|
4039
4205
|
);
|
|
4040
4206
|
return { ...sent, route: "wrap" };
|
|
4041
4207
|
}
|
|
@@ -4123,16 +4289,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4123
4289
|
method: "wallet_switchEthereumChain",
|
|
4124
4290
|
params: [{ chainId: `0x${originChainId.toString(16)}` }]
|
|
4125
4291
|
});
|
|
4126
|
-
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0,
|
|
4292
|
+
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0, import_viem6.defineChain)({
|
|
4127
4293
|
id: originChainId,
|
|
4128
4294
|
name: `Chain ${originChainId}`,
|
|
4129
4295
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
4130
4296
|
rpcUrls: { default: { http: ["http://127.0.0.1"] } }
|
|
4131
4297
|
});
|
|
4132
|
-
this.walletClient = (0,
|
|
4298
|
+
this.walletClient = (0, import_viem6.createWalletClient)({
|
|
4133
4299
|
account: this.walletClient.account,
|
|
4134
4300
|
chain,
|
|
4135
|
-
transport: (0,
|
|
4301
|
+
transport: (0, import_viem6.custom)(this.currentProvider)
|
|
4136
4302
|
});
|
|
4137
4303
|
if (isSupportedChain(originChainId)) {
|
|
4138
4304
|
this.currentChainId = originChainId;
|
|
@@ -4308,7 +4474,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4308
4474
|
safeAddress,
|
|
4309
4475
|
tokenAddress,
|
|
4310
4476
|
to: tokenAddress,
|
|
4311
|
-
data: (0,
|
|
4477
|
+
data: (0, import_viem6.encodeFunctionData)({
|
|
4312
4478
|
abi: ERC20_ABI,
|
|
4313
4479
|
functionName: "transfer",
|
|
4314
4480
|
args: [safeAddress, amountBigInt]
|
|
@@ -4337,7 +4503,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4337
4503
|
if (!userAddress) {
|
|
4338
4504
|
throw new Error("A user address is required");
|
|
4339
4505
|
}
|
|
4340
|
-
const owner = (0,
|
|
4506
|
+
const owner = (0, import_viem6.getAddress)(userAddress);
|
|
4341
4507
|
const chainId = 8453;
|
|
4342
4508
|
await this.hydrateSessionWallet();
|
|
4343
4509
|
const safe = await this.getSafeAddressFor(owner, chainId);
|
|
@@ -4359,7 +4525,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4359
4525
|
]).catch(() => {
|
|
4360
4526
|
throw new Error(`Safe ${safe} is not deployed on Base`);
|
|
4361
4527
|
});
|
|
4362
|
-
if (threshold !== 1n || !owners.some((o) => (0,
|
|
4528
|
+
if (threshold !== 1n || !owners.some((o) => (0, import_viem6.getAddress)(o) === owner)) {
|
|
4363
4529
|
throw new Error(
|
|
4364
4530
|
`${owner} cannot execute Safe ${safe} alone (not an owner, or threshold above 1)`
|
|
4365
4531
|
);
|
|
@@ -4448,7 +4614,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4448
4614
|
if (!userAddress) {
|
|
4449
4615
|
throw new Error("A user address is required");
|
|
4450
4616
|
}
|
|
4451
|
-
if (this.sessionEoa && (0,
|
|
4617
|
+
if (this.sessionEoa && (0, import_viem6.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4452
4618
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4453
4619
|
}
|
|
4454
4620
|
}
|
|
@@ -4594,7 +4760,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4594
4760
|
*/
|
|
4595
4761
|
async prepareDeposit(params) {
|
|
4596
4762
|
const { userAddress, chainId, amount, asset } = params;
|
|
4597
|
-
if (this.sessionEoa && (0,
|
|
4763
|
+
if (this.sessionEoa && (0, import_viem6.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4598
4764
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4599
4765
|
}
|
|
4600
4766
|
const setup = await this.ensureDepositProfileForPrepare({
|
|
@@ -5855,19 +6021,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5855
6021
|
}
|
|
5856
6022
|
}
|
|
5857
6023
|
/**
|
|
5858
|
-
* Get
|
|
6024
|
+
* Get balanced (high-risk, high-reward) yield opportunities.
|
|
5859
6025
|
*
|
|
5860
6026
|
* @param chainId - Optional chain ID filter
|
|
5861
6027
|
* @param asset - Optional asset filter (e.g. "USDC", "WETH", "WBTC")
|
|
5862
|
-
* @returns List of
|
|
6028
|
+
* @returns List of balanced opportunities
|
|
5863
6029
|
*
|
|
5864
6030
|
* @example
|
|
5865
6031
|
* ```typescript
|
|
5866
|
-
* const opportunities = await sdk.
|
|
6032
|
+
* const opportunities = await sdk.getBalancedOpportunities(8453, "WETH");
|
|
5867
6033
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
5868
6034
|
* ```
|
|
5869
6035
|
*/
|
|
5870
|
-
async
|
|
6036
|
+
async getBalancedOpportunities(chainId, asset, status) {
|
|
5871
6037
|
try {
|
|
5872
6038
|
const response = await this.httpClient.dataGet(
|
|
5873
6039
|
DATA_ENDPOINTS.OPPORTUNITIES_DEGEN(chainId, asset, status)
|
|
@@ -5876,7 +6042,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5876
6042
|
return {
|
|
5877
6043
|
success: true,
|
|
5878
6044
|
chainId,
|
|
5879
|
-
strategyType: "
|
|
6045
|
+
strategyType: "balanced",
|
|
5880
6046
|
data: Array.isArray(data) ? data.map((o) => ({
|
|
5881
6047
|
id: o.id,
|
|
5882
6048
|
protocolId: o.protocol_id || o.protocolId,
|
|
@@ -5887,34 +6053,47 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5887
6053
|
tvl: o.tvl || o.zyfiTvl,
|
|
5888
6054
|
asset: o.asset || o.underlying_token,
|
|
5889
6055
|
risk: o.risk,
|
|
5890
|
-
strategyType: "
|
|
6056
|
+
strategyType: "balanced",
|
|
5891
6057
|
status: o.status
|
|
5892
6058
|
})) : []
|
|
5893
6059
|
};
|
|
5894
6060
|
} catch (error) {
|
|
5895
6061
|
throw new Error(
|
|
5896
|
-
`Failed to get
|
|
6062
|
+
`Failed to get balanced opportunities: ${error.message}`
|
|
5897
6063
|
);
|
|
5898
6064
|
}
|
|
5899
6065
|
}
|
|
5900
6066
|
/**
|
|
5901
|
-
*
|
|
5902
|
-
* `
|
|
6067
|
+
* @deprecated Use {@link getBalancedOpportunities} instead. Retains the
|
|
6068
|
+
* pre-rename `getAggressiveOpportunities` entry point; same HTTP request as
|
|
6069
|
+
* balanced, with legacy `strategyType: "aggressive"` on the response and rows.
|
|
6070
|
+
*/
|
|
6071
|
+
async getAggressiveOpportunities(chainId, asset, status) {
|
|
6072
|
+
const result = await this.getBalancedOpportunities(chainId, asset, status);
|
|
6073
|
+
return {
|
|
6074
|
+
...result,
|
|
6075
|
+
strategyType: "aggressive",
|
|
6076
|
+
data: result.data.map((o) => ({ ...o, strategyType: "aggressive" }))
|
|
6077
|
+
};
|
|
6078
|
+
}
|
|
6079
|
+
/**
|
|
6080
|
+
* Get advanced yield opportunities — pools reachable only with the
|
|
6081
|
+
* `"advanced"` strategy, including protocols whose withdrawals are
|
|
5903
6082
|
* asynchronous (Ipor, Superform). Exiting these pools takes about a day
|
|
5904
6083
|
* on Ipor and three on Superform; track the redemption through
|
|
5905
6084
|
* `getPortfolio().portfolio.pendingAsyncWithdrawals`.
|
|
5906
6085
|
*
|
|
5907
6086
|
* @param chainId - Optional chain ID filter
|
|
5908
6087
|
* @param asset - Optional asset filter (e.g. "USDC", "WETH")
|
|
5909
|
-
* @returns List of
|
|
6088
|
+
* @returns List of advanced opportunities
|
|
5910
6089
|
*
|
|
5911
6090
|
* @example
|
|
5912
6091
|
* ```typescript
|
|
5913
|
-
* const opportunities = await sdk.
|
|
6092
|
+
* const opportunities = await sdk.getAdvancedOpportunities(8453);
|
|
5914
6093
|
* opportunities.data.forEach(o => console.log(o.protocolName, o.apy));
|
|
5915
6094
|
* ```
|
|
5916
6095
|
*/
|
|
5917
|
-
async
|
|
6096
|
+
async getAdvancedOpportunities(chainId, asset, status) {
|
|
5918
6097
|
try {
|
|
5919
6098
|
const response = await this.httpClient.dataGet(
|
|
5920
6099
|
DATA_ENDPOINTS.OPPORTUNITIES_ASYNC(chainId, asset, status)
|
|
@@ -5923,7 +6102,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5923
6102
|
return {
|
|
5924
6103
|
success: true,
|
|
5925
6104
|
chainId,
|
|
5926
|
-
strategyType: "
|
|
6105
|
+
strategyType: "advanced",
|
|
5927
6106
|
data: Array.isArray(data) ? data.map((o) => ({
|
|
5928
6107
|
id: o.id,
|
|
5929
6108
|
protocolId: o.protocol_id || o.protocolId,
|
|
@@ -5934,16 +6113,29 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5934
6113
|
tvl: o.tvl || o.zyfiTvl,
|
|
5935
6114
|
asset: o.asset || o.underlying_token,
|
|
5936
6115
|
risk: o.risk,
|
|
5937
|
-
strategyType: "
|
|
6116
|
+
strategyType: "advanced",
|
|
5938
6117
|
status: o.status
|
|
5939
6118
|
})) : []
|
|
5940
6119
|
};
|
|
5941
6120
|
} catch (error) {
|
|
5942
6121
|
throw new Error(
|
|
5943
|
-
`Failed to get
|
|
6122
|
+
`Failed to get advanced opportunities: ${error.message}`
|
|
5944
6123
|
);
|
|
5945
6124
|
}
|
|
5946
6125
|
}
|
|
6126
|
+
/**
|
|
6127
|
+
* @deprecated Use {@link getAdvancedOpportunities} instead. Retains the
|
|
6128
|
+
* pre-rename `getAsyncOpportunities` entry point; same HTTP request as
|
|
6129
|
+
* advanced, with legacy `strategyType: "yieldmaxxing"` on the response and rows.
|
|
6130
|
+
*/
|
|
6131
|
+
async getAsyncOpportunities(chainId, asset, status) {
|
|
6132
|
+
const result = await this.getAdvancedOpportunities(chainId, asset, status);
|
|
6133
|
+
return {
|
|
6134
|
+
...result,
|
|
6135
|
+
strategyType: "yieldmaxxing",
|
|
6136
|
+
data: result.data.map((o) => ({ ...o, strategyType: "yieldmaxxing" }))
|
|
6137
|
+
};
|
|
6138
|
+
}
|
|
5947
6139
|
/**
|
|
5948
6140
|
* Get active conservative opportunities (status = "live") with risk and utilization data
|
|
5949
6141
|
* Returns pool info, liquidity depth (true if > 1M), utilization rate, stability metrics, avg APY, and collateral
|
|
@@ -6614,7 +6806,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6614
6806
|
if (!tokenUriResponse.tokenUri) {
|
|
6615
6807
|
throw new Error("API did not return a tokenUri");
|
|
6616
6808
|
}
|
|
6617
|
-
const callData = (0,
|
|
6809
|
+
const callData = (0, import_viem6.encodeFunctionData)({
|
|
6618
6810
|
abi: IDENTITY_REGISTRY_ABI,
|
|
6619
6811
|
functionName: "register",
|
|
6620
6812
|
args: [tokenUriResponse.tokenUri]
|