@zyfai/sdk 0.2.46 → 0.2.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +55 -4
- package/dist/index.mjs +55 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1063,6 +1063,32 @@ declare class ZyfaiSDK {
|
|
|
1063
1063
|
* await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
|
|
1064
1064
|
* ```
|
|
1065
1065
|
*/
|
|
1066
|
+
/**
|
|
1067
|
+
* Deploy the connected predeployed (pool) wallet on one or more chains.
|
|
1068
|
+
*
|
|
1069
|
+
* A pool wallet is only deployed on the chains it has been onboarded to (see
|
|
1070
|
+
* the `chains` array from getSmartWalletByEOA); every other supported chain is
|
|
1071
|
+
* counterfactual until deployed here. The backend deploys + rotates the same
|
|
1072
|
+
* address on each chain in parallel (sponsored, no user signature) and only
|
|
1073
|
+
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
1074
|
+
* already deployed are a no-op.
|
|
1075
|
+
*
|
|
1076
|
+
* `depositFunds` calls this automatically when the target chain isn't deployed,
|
|
1077
|
+
* so most integrations never need it directly; use it to pre-provision chains.
|
|
1078
|
+
*
|
|
1079
|
+
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
1080
|
+
*/
|
|
1081
|
+
deployOnChains(chainIds: SupportedChainId[]): Promise<{
|
|
1082
|
+
success: boolean;
|
|
1083
|
+
safeAddress: string;
|
|
1084
|
+
chains: number[];
|
|
1085
|
+
status: string;
|
|
1086
|
+
}>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
1089
|
+
* responds, so this only guards against read-after-write RPC lag.
|
|
1090
|
+
*/
|
|
1091
|
+
private waitForSafeDeployed;
|
|
1066
1092
|
depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
|
|
1067
1093
|
/**
|
|
1068
1094
|
* Log a deposit that was executed client-side
|
package/dist/index.d.ts
CHANGED
|
@@ -1063,6 +1063,32 @@ declare class ZyfaiSDK {
|
|
|
1063
1063
|
* await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
|
|
1064
1064
|
* ```
|
|
1065
1065
|
*/
|
|
1066
|
+
/**
|
|
1067
|
+
* Deploy the connected predeployed (pool) wallet on one or more chains.
|
|
1068
|
+
*
|
|
1069
|
+
* A pool wallet is only deployed on the chains it has been onboarded to (see
|
|
1070
|
+
* the `chains` array from getSmartWalletByEOA); every other supported chain is
|
|
1071
|
+
* counterfactual until deployed here. The backend deploys + rotates the same
|
|
1072
|
+
* address on each chain in parallel (sponsored, no user signature) and only
|
|
1073
|
+
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
1074
|
+
* already deployed are a no-op.
|
|
1075
|
+
*
|
|
1076
|
+
* `depositFunds` calls this automatically when the target chain isn't deployed,
|
|
1077
|
+
* so most integrations never need it directly; use it to pre-provision chains.
|
|
1078
|
+
*
|
|
1079
|
+
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
1080
|
+
*/
|
|
1081
|
+
deployOnChains(chainIds: SupportedChainId[]): Promise<{
|
|
1082
|
+
success: boolean;
|
|
1083
|
+
safeAddress: string;
|
|
1084
|
+
chains: number[];
|
|
1085
|
+
status: string;
|
|
1086
|
+
}>;
|
|
1087
|
+
/**
|
|
1088
|
+
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
1089
|
+
* responds, so this only guards against read-after-write RPC lag.
|
|
1090
|
+
*/
|
|
1091
|
+
private waitForSafeDeployed;
|
|
1066
1092
|
depositFunds(userAddress: string, chainId: SupportedChainId, amount: string, asset: string, strategy?: Strategy): Promise<DepositResponse>;
|
|
1067
1093
|
/**
|
|
1068
1094
|
* Log a deposit that was executed client-side
|
package/dist/index.js
CHANGED
|
@@ -70,6 +70,9 @@ var ENDPOINTS = {
|
|
|
70
70
|
LOG_DEPOSIT: "/users/log_deposit",
|
|
71
71
|
// Safe Deployment (single endpoint)
|
|
72
72
|
SAFE_DEPLOY: "/users/safe-deploy",
|
|
73
|
+
// Multichain deploy for predeployed (pool) wallets — deploys + rotates the
|
|
74
|
+
// same address on the requested chains (sponsored, no user signature).
|
|
75
|
+
DEPLOY_CHAINS: "/users/deploy-chains",
|
|
73
76
|
// Session Keys
|
|
74
77
|
SESSION_KEYS_CONFIG: "/session-keys/config",
|
|
75
78
|
SESSION_KEYS_ADD: "/session-keys/add",
|
|
@@ -2439,6 +2442,42 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2439
2442
|
* await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
|
|
2440
2443
|
* ```
|
|
2441
2444
|
*/
|
|
2445
|
+
/**
|
|
2446
|
+
* Deploy the connected predeployed (pool) wallet on one or more chains.
|
|
2447
|
+
*
|
|
2448
|
+
* A pool wallet is only deployed on the chains it has been onboarded to (see
|
|
2449
|
+
* the `chains` array from getSmartWalletByEOA); every other supported chain is
|
|
2450
|
+
* counterfactual until deployed here. The backend deploys + rotates the same
|
|
2451
|
+
* address on each chain in parallel (sponsored, no user signature) and only
|
|
2452
|
+
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
2453
|
+
* already deployed are a no-op.
|
|
2454
|
+
*
|
|
2455
|
+
* `depositFunds` calls this automatically when the target chain isn't deployed,
|
|
2456
|
+
* so most integrations never need it directly; use it to pre-provision chains.
|
|
2457
|
+
*
|
|
2458
|
+
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
2459
|
+
*/
|
|
2460
|
+
async deployOnChains(chainIds) {
|
|
2461
|
+
if (!chainIds?.length) {
|
|
2462
|
+
throw new Error("At least one chainId is required");
|
|
2463
|
+
}
|
|
2464
|
+
for (const c of chainIds) {
|
|
2465
|
+
if (!isSupportedChain(c)) throw new Error(`Unsupported chain ID: ${c}`);
|
|
2466
|
+
}
|
|
2467
|
+
await this.authenticateUser();
|
|
2468
|
+
return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
|
|
2469
|
+
}
|
|
2470
|
+
/**
|
|
2471
|
+
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
2472
|
+
* responds, so this only guards against read-after-write RPC lag.
|
|
2473
|
+
*/
|
|
2474
|
+
async waitForSafeDeployed(safeAddress, publicClient, tries = 5, delayMs = 2e3) {
|
|
2475
|
+
for (let i = 0; i < tries; i++) {
|
|
2476
|
+
if (await isSafeDeployed(safeAddress, publicClient)) return true;
|
|
2477
|
+
await new Promise((r) => setTimeout(r, delayMs));
|
|
2478
|
+
}
|
|
2479
|
+
return isSafeDeployed(safeAddress, publicClient);
|
|
2480
|
+
}
|
|
2442
2481
|
async depositFunds(userAddress, chainId, amount, asset, strategy) {
|
|
2443
2482
|
try {
|
|
2444
2483
|
if (!userAddress) {
|
|
@@ -2475,9 +2514,22 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2475
2514
|
chainConfig.publicClient
|
|
2476
2515
|
);
|
|
2477
2516
|
if (!isDeployed) {
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2517
|
+
if (this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
2518
|
+
await this.deployOnChains([chainId]);
|
|
2519
|
+
const landed = await this.waitForSafeDeployed(
|
|
2520
|
+
safeAddress,
|
|
2521
|
+
chainConfig.publicClient
|
|
2522
|
+
);
|
|
2523
|
+
if (!landed) {
|
|
2524
|
+
throw new Error(
|
|
2525
|
+
`Safe deploy on chain ${chainId} for ${userAddress} did not land \u2014 retry the deposit.`
|
|
2526
|
+
);
|
|
2527
|
+
}
|
|
2528
|
+
} else {
|
|
2529
|
+
throw new Error(
|
|
2530
|
+
`Safe not available for ${userAddress} on chain ${chainId}.`
|
|
2531
|
+
);
|
|
2532
|
+
}
|
|
2481
2533
|
}
|
|
2482
2534
|
try {
|
|
2483
2535
|
const usdcDetails = await this.getUserDetails("USDC");
|
|
@@ -3134,7 +3186,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3134
3186
|
DATA_ENDPOINTS.ONCHAIN_EARNINGS(walletAddress)
|
|
3135
3187
|
);
|
|
3136
3188
|
const data = response.data || response;
|
|
3137
|
-
console.log(JSON.stringify(data, null, 2));
|
|
3138
3189
|
const withFee = enrichOnchainEarningsTotals(data);
|
|
3139
3190
|
return {
|
|
3140
3191
|
success: true,
|
package/dist/index.mjs
CHANGED
|
@@ -18,6 +18,9 @@ var ENDPOINTS = {
|
|
|
18
18
|
LOG_DEPOSIT: "/users/log_deposit",
|
|
19
19
|
// Safe Deployment (single endpoint)
|
|
20
20
|
SAFE_DEPLOY: "/users/safe-deploy",
|
|
21
|
+
// Multichain deploy for predeployed (pool) wallets — deploys + rotates the
|
|
22
|
+
// same address on the requested chains (sponsored, no user signature).
|
|
23
|
+
DEPLOY_CHAINS: "/users/deploy-chains",
|
|
21
24
|
// Session Keys
|
|
22
25
|
SESSION_KEYS_CONFIG: "/session-keys/config",
|
|
23
26
|
SESSION_KEYS_ADD: "/session-keys/add",
|
|
@@ -2407,6 +2410,42 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2407
2410
|
* await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
|
|
2408
2411
|
* ```
|
|
2409
2412
|
*/
|
|
2413
|
+
/**
|
|
2414
|
+
* Deploy the connected predeployed (pool) wallet on one or more chains.
|
|
2415
|
+
*
|
|
2416
|
+
* A pool wallet is only deployed on the chains it has been onboarded to (see
|
|
2417
|
+
* the `chains` array from getSmartWalletByEOA); every other supported chain is
|
|
2418
|
+
* counterfactual until deployed here. The backend deploys + rotates the same
|
|
2419
|
+
* address on each chain in parallel (sponsored, no user signature) and only
|
|
2420
|
+
* resolves once all requested chains have landed on-chain. Idempotent — chains
|
|
2421
|
+
* already deployed are a no-op.
|
|
2422
|
+
*
|
|
2423
|
+
* `depositFunds` calls this automatically when the target chain isn't deployed,
|
|
2424
|
+
* so most integrations never need it directly; use it to pre-provision chains.
|
|
2425
|
+
*
|
|
2426
|
+
* @param chainIds - Chain IDs to deploy the wallet on (e.g. [1, 42161])
|
|
2427
|
+
*/
|
|
2428
|
+
async deployOnChains(chainIds) {
|
|
2429
|
+
if (!chainIds?.length) {
|
|
2430
|
+
throw new Error("At least one chainId is required");
|
|
2431
|
+
}
|
|
2432
|
+
for (const c of chainIds) {
|
|
2433
|
+
if (!isSupportedChain(c)) throw new Error(`Unsupported chain ID: ${c}`);
|
|
2434
|
+
}
|
|
2435
|
+
await this.authenticateUser();
|
|
2436
|
+
return this.httpClient.post(ENDPOINTS.DEPLOY_CHAINS, { chainIds });
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Poll until the Safe has code on-chain. The backend awaits landing before it
|
|
2440
|
+
* responds, so this only guards against read-after-write RPC lag.
|
|
2441
|
+
*/
|
|
2442
|
+
async waitForSafeDeployed(safeAddress, publicClient, tries = 5, delayMs = 2e3) {
|
|
2443
|
+
for (let i = 0; i < tries; i++) {
|
|
2444
|
+
if (await isSafeDeployed(safeAddress, publicClient)) return true;
|
|
2445
|
+
await new Promise((r) => setTimeout(r, delayMs));
|
|
2446
|
+
}
|
|
2447
|
+
return isSafeDeployed(safeAddress, publicClient);
|
|
2448
|
+
}
|
|
2410
2449
|
async depositFunds(userAddress, chainId, amount, asset, strategy) {
|
|
2411
2450
|
try {
|
|
2412
2451
|
if (!userAddress) {
|
|
@@ -2443,9 +2482,22 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2443
2482
|
chainConfig.publicClient
|
|
2444
2483
|
);
|
|
2445
2484
|
if (!isDeployed) {
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2485
|
+
if (this.isPredeployed && this.isConnectedUser(userAddress)) {
|
|
2486
|
+
await this.deployOnChains([chainId]);
|
|
2487
|
+
const landed = await this.waitForSafeDeployed(
|
|
2488
|
+
safeAddress,
|
|
2489
|
+
chainConfig.publicClient
|
|
2490
|
+
);
|
|
2491
|
+
if (!landed) {
|
|
2492
|
+
throw new Error(
|
|
2493
|
+
`Safe deploy on chain ${chainId} for ${userAddress} did not land \u2014 retry the deposit.`
|
|
2494
|
+
);
|
|
2495
|
+
}
|
|
2496
|
+
} else {
|
|
2497
|
+
throw new Error(
|
|
2498
|
+
`Safe not available for ${userAddress} on chain ${chainId}.`
|
|
2499
|
+
);
|
|
2500
|
+
}
|
|
2449
2501
|
}
|
|
2450
2502
|
try {
|
|
2451
2503
|
const usdcDetails = await this.getUserDetails("USDC");
|
|
@@ -3102,7 +3154,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3102
3154
|
DATA_ENDPOINTS.ONCHAIN_EARNINGS(walletAddress)
|
|
3103
3155
|
);
|
|
3104
3156
|
const data = response.data || response;
|
|
3105
|
-
console.log(JSON.stringify(data, null, 2));
|
|
3106
3157
|
const withFee = enrichOnchainEarningsTotals(data);
|
|
3107
3158
|
return {
|
|
3108
3159
|
success: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.48",
|
|
4
4
|
"description": "TypeScript SDK for Zyfai Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|