@zyfai/sdk 0.2.43 → 0.2.45
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 +20 -14
- package/dist/index.d.mts +64 -25
- package/dist/index.d.ts +64 -25
- package/dist/index.js +202 -66
- package/dist/index.mjs +203 -66
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31,13 +31,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
DEFAULT_TOKEN_ADDRESSES: () => DEFAULT_TOKEN_ADDRESSES,
|
|
34
|
-
ERC7579_LAUNCHPAD_ADDRESS: () =>
|
|
34
|
+
ERC7579_LAUNCHPAD_ADDRESS: () => ERC7579_LAUNCHPAD_ADDRESS,
|
|
35
35
|
INTENT_EXECUTOR: () => INTENT_EXECUTOR,
|
|
36
36
|
INTENT_SMART_SESSIONS: () => INTENT_SMART_SESSIONS,
|
|
37
37
|
OWNABLE_VALIDATOR: () => OWNABLE_VALIDATOR,
|
|
38
38
|
POOL_MODULE_ADDRESSES: () => POOL_MODULE_ADDRESSES,
|
|
39
39
|
PROXY_EXECUTOR: () => PROXY_EXECUTOR,
|
|
40
|
-
SAFE_7579_ADDRESS: () =>
|
|
40
|
+
SAFE_7579_ADDRESS: () => SAFE_7579_ADDRESS,
|
|
41
41
|
SMART_SESSIONS_FALLBACK: () => SMART_SESSIONS_FALLBACK,
|
|
42
42
|
SMART_SESSIONS_VALIDATOR: () => SMART_SESSIONS_VALIDATOR,
|
|
43
43
|
VAULT_ADDRESS: () => VAULT_ADDRESS,
|
|
@@ -345,6 +345,15 @@ var HttpClient = class {
|
|
|
345
345
|
|
|
346
346
|
// src/config/abis.ts
|
|
347
347
|
var import_viem = require("viem");
|
|
348
|
+
var OWNABLE_VALIDATOR_ABI = [
|
|
349
|
+
{
|
|
350
|
+
name: "getOwners",
|
|
351
|
+
type: "function",
|
|
352
|
+
stateMutability: "view",
|
|
353
|
+
inputs: [{ name: "account", type: "address" }],
|
|
354
|
+
outputs: [{ name: "ownersArray", type: "address[]" }]
|
|
355
|
+
}
|
|
356
|
+
];
|
|
348
357
|
var ERC20_ABI = [
|
|
349
358
|
{
|
|
350
359
|
name: "transfer",
|
|
@@ -593,6 +602,25 @@ var ASSET_CONFIGS = {
|
|
|
593
602
|
// Linea
|
|
594
603
|
},
|
|
595
604
|
enabled: true
|
|
605
|
+
},
|
|
606
|
+
EURC: {
|
|
607
|
+
symbol: "EURC",
|
|
608
|
+
assetType: "eurc",
|
|
609
|
+
displayName: "EURC",
|
|
610
|
+
icon: "/ai-dashboard/eurc-token.png",
|
|
611
|
+
decimals: 6,
|
|
612
|
+
tokenSymbols: ["EURC"],
|
|
613
|
+
tokenSymbolsByChainId: {
|
|
614
|
+
1: "EURC",
|
|
615
|
+
8453: "EURC"
|
|
616
|
+
},
|
|
617
|
+
addresses: {
|
|
618
|
+
1: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
619
|
+
// Ethereum
|
|
620
|
+
8453: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"
|
|
621
|
+
// Base
|
|
622
|
+
},
|
|
623
|
+
enabled: true
|
|
596
624
|
}
|
|
597
625
|
};
|
|
598
626
|
var getDefaultTokenAddress = (chainId, asset) => {
|
|
@@ -642,8 +670,28 @@ var import_module_sdk = require("@rhinestone/module-sdk");
|
|
|
642
670
|
var import_accounts = require("permissionless/accounts");
|
|
643
671
|
var import_viem3 = require("viem");
|
|
644
672
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
673
|
+
|
|
674
|
+
// src/config/modules.ts
|
|
675
|
+
var SMART_SESSIONS_VALIDATOR = "0x00000000008bDABA73cD9815d79069c247Eb4bDA";
|
|
676
|
+
var SMART_SESSIONS_FALLBACK = "0x12cae64c42f362e7d5a847c2d33388373f629177";
|
|
677
|
+
var INTENT_EXECUTOR = "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF";
|
|
678
|
+
var PROXY_EXECUTOR = "0xF659d30D4EB88B06A909F20839D8959Bd77d8790";
|
|
679
|
+
var INTENT_SMART_SESSIONS = "0xad568b3f825a8d5ffc06dd3253526b64d810ae89";
|
|
680
|
+
var OWNABLE_VALIDATOR = "0x000000000013fdB5234E4E3162a810F54d9f7E98";
|
|
645
681
|
var SAFE_7579_ADDRESS = "0x7579EE8307284F293B1927136486880611F20002";
|
|
646
682
|
var ERC7579_LAUNCHPAD_ADDRESS = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
683
|
+
var POOL_MODULE_ADDRESSES = [
|
|
684
|
+
SMART_SESSIONS_VALIDATOR,
|
|
685
|
+
SMART_SESSIONS_FALLBACK,
|
|
686
|
+
INTENT_EXECUTOR,
|
|
687
|
+
PROXY_EXECUTOR,
|
|
688
|
+
INTENT_SMART_SESSIONS,
|
|
689
|
+
OWNABLE_VALIDATOR
|
|
690
|
+
];
|
|
691
|
+
|
|
692
|
+
// src/utils/safe-account.ts
|
|
693
|
+
var SAFE_7579_ADDRESS2 = "0x7579EE8307284F293B1927136486880611F20002";
|
|
694
|
+
var ERC7579_LAUNCHPAD_ADDRESS2 = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
647
695
|
var ACCOUNT_SALT = "zyfai";
|
|
648
696
|
var getSafeAccount = async (config) => {
|
|
649
697
|
const { safeOwnerAddress, publicClient } = config;
|
|
@@ -668,8 +716,8 @@ var getSafeAccount = async (config) => {
|
|
|
668
716
|
address: import_account_abstraction.entryPoint07Address,
|
|
669
717
|
version: "0.7"
|
|
670
718
|
},
|
|
671
|
-
safe4337ModuleAddress:
|
|
672
|
-
erc7579LaunchpadAddress:
|
|
719
|
+
safe4337ModuleAddress: SAFE_7579_ADDRESS2,
|
|
720
|
+
erc7579LaunchpadAddress: ERC7579_LAUNCHPAD_ADDRESS2,
|
|
673
721
|
attesters: [import_module_sdk.RHINESTONE_ATTESTER_ADDRESS],
|
|
674
722
|
attestersThreshold: 1,
|
|
675
723
|
validators: [
|
|
@@ -701,6 +749,31 @@ var isSafeDeployed = async (address, publicClient) => {
|
|
|
701
749
|
return false;
|
|
702
750
|
}
|
|
703
751
|
};
|
|
752
|
+
var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
|
|
753
|
+
const normalizedUser = (0, import_viem3.getAddress)(userAddress);
|
|
754
|
+
const normalizedSafe = (0, import_viem3.getAddress)(safeAddress);
|
|
755
|
+
const validatorAddresses = Array.from(
|
|
756
|
+
/* @__PURE__ */ new Set([
|
|
757
|
+
(0, import_viem3.getAddress)(OWNABLE_VALIDATOR),
|
|
758
|
+
(0, import_viem3.getAddress)(import_module_sdk.OWNABLE_VALIDATOR_ADDRESS)
|
|
759
|
+
])
|
|
760
|
+
);
|
|
761
|
+
for (const validatorAddress of validatorAddresses) {
|
|
762
|
+
try {
|
|
763
|
+
const owners = await publicClient.readContract({
|
|
764
|
+
address: validatorAddress,
|
|
765
|
+
abi: OWNABLE_VALIDATOR_ABI,
|
|
766
|
+
functionName: "getOwners",
|
|
767
|
+
args: [normalizedSafe]
|
|
768
|
+
});
|
|
769
|
+
if (owners.some((owner) => (0, import_viem3.getAddress)(owner) === normalizedUser)) {
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
} catch {
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return false;
|
|
776
|
+
};
|
|
704
777
|
var getAccountType = async (address, publicClient) => {
|
|
705
778
|
try {
|
|
706
779
|
const code = await publicClient.getCode({ address });
|
|
@@ -743,10 +816,12 @@ var deploySafeAccount = async (config) => {
|
|
|
743
816
|
"Wallet not connected. Please connect your wallet first."
|
|
744
817
|
);
|
|
745
818
|
}
|
|
819
|
+
console.log("strategy", strategy);
|
|
746
820
|
const prepareResponse = await httpClient.post(
|
|
747
821
|
`${ENDPOINTS.SAFE_DEPLOY}?chainId=${chainId}`,
|
|
748
822
|
{ strategy }
|
|
749
823
|
);
|
|
824
|
+
console.log("prepareResponse", prepareResponse);
|
|
750
825
|
if (!prepareResponse.userOpHashToSign) {
|
|
751
826
|
throw new Error(
|
|
752
827
|
"Backend did not return userOpHashToSign. Response: " + JSON.stringify(prepareResponse)
|
|
@@ -892,7 +967,12 @@ function convertAssetInternally(asset) {
|
|
|
892
967
|
if (asset === "WETH") {
|
|
893
968
|
return "eth";
|
|
894
969
|
}
|
|
895
|
-
|
|
970
|
+
if (asset === "EURC") {
|
|
971
|
+
return "eurc";
|
|
972
|
+
}
|
|
973
|
+
throw new Error(
|
|
974
|
+
`Invalid asset: ${asset}. Must be "USDC", "WETH", or "EURC".`
|
|
975
|
+
);
|
|
896
976
|
}
|
|
897
977
|
function convertStrategiesToPublic(array) {
|
|
898
978
|
return array.map((item) => convertStrategyToPublic(item));
|
|
@@ -985,6 +1065,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
985
1065
|
this.rpcUrls = rpcUrls;
|
|
986
1066
|
this.referralSource = referralSource;
|
|
987
1067
|
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Warn that a legacy method is deprecated in favor of depositFunds.
|
|
1070
|
+
* Predeployed wallets no longer require deploySafe / createSessionKey.
|
|
1071
|
+
*/
|
|
1072
|
+
warnDeprecatedOnboardingMethod(methodName) {
|
|
1073
|
+
console.warn(
|
|
1074
|
+
`[ZyfaiSDK] ${methodName}() is deprecated for partner integrations. Prefer depositFunds() \u2014 predeployed Safes and session keys are handled automatically on first deposit.`
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
988
1077
|
/**
|
|
989
1078
|
* Authenticate user with SIWE (Sign-In with Ethereum) & JWT token
|
|
990
1079
|
* This is required for accessing user-specific endpoints like session-keys/config
|
|
@@ -1138,10 +1227,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1138
1227
|
asset: "USDC",
|
|
1139
1228
|
protocols: []
|
|
1140
1229
|
});
|
|
1141
|
-
|
|
1230
|
+
await this.updateUserProfile({
|
|
1142
1231
|
asset: "WETH",
|
|
1143
1232
|
protocols: []
|
|
1144
1233
|
});
|
|
1234
|
+
const response = await this.updateUserProfile({
|
|
1235
|
+
asset: "EURC",
|
|
1236
|
+
protocols: []
|
|
1237
|
+
});
|
|
1145
1238
|
return response;
|
|
1146
1239
|
} catch (error) {
|
|
1147
1240
|
throw new Error(`Failed to pause agent: ${error.message}`);
|
|
@@ -1169,16 +1262,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1169
1262
|
try {
|
|
1170
1263
|
const userDetailsUSDC = await this.getUserDetails("USDC");
|
|
1171
1264
|
const userDetailsETH = await this.getUserDetails("WETH");
|
|
1265
|
+
const userDetailsEURC = await this.getUserDetails("EURC");
|
|
1172
1266
|
const chains = userDetailsUSDC.chains && userDetailsUSDC.chains.length > 0 ? userDetailsUSDC.chains : [8453, 42161];
|
|
1267
|
+
const eurcChains = userDetailsEURC.chains && userDetailsEURC.chains.length > 0 ? userDetailsEURC.chains.filter((c) => c === 1 || c === 8453) : [1, 8453];
|
|
1173
1268
|
const allProtocols = await this.httpClient.get(
|
|
1174
1269
|
ENDPOINTS.PROTOCOLS()
|
|
1175
1270
|
);
|
|
1176
1271
|
const usdcStrategy = userDetailsUSDC.strategy || "safe_strategy";
|
|
1177
1272
|
const ethStrategy = userDetailsETH.strategy || "safe_strategy";
|
|
1178
|
-
const
|
|
1273
|
+
const eurcStrategy = userDetailsEURC.strategy || "safe_strategy";
|
|
1274
|
+
const filterProtocolsByStrategy = (strategy, selectedChains) => {
|
|
1179
1275
|
return allProtocols.filter((protocol) => {
|
|
1180
1276
|
const hasMatchingChain = protocol.chains.some(
|
|
1181
|
-
(chain) =>
|
|
1277
|
+
(chain) => selectedChains.includes(chain)
|
|
1182
1278
|
);
|
|
1183
1279
|
if (!hasMatchingChain) {
|
|
1184
1280
|
return false;
|
|
@@ -1189,17 +1285,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1189
1285
|
return protocol.strategies?.includes("safe_strategy");
|
|
1190
1286
|
}).map((protocol) => protocol.id);
|
|
1191
1287
|
};
|
|
1192
|
-
const usdcProtocols = filterProtocolsByStrategy(usdcStrategy);
|
|
1193
|
-
const ethProtocols = filterProtocolsByStrategy(ethStrategy);
|
|
1288
|
+
const usdcProtocols = filterProtocolsByStrategy(usdcStrategy, chains);
|
|
1289
|
+
const ethProtocols = filterProtocolsByStrategy(ethStrategy, chains);
|
|
1290
|
+
const eurcProtocols = filterProtocolsByStrategy(eurcStrategy, eurcChains);
|
|
1194
1291
|
await this.updateUserProfile({
|
|
1195
1292
|
asset: "USDC",
|
|
1196
1293
|
protocols: usdcProtocols
|
|
1197
1294
|
});
|
|
1198
|
-
|
|
1295
|
+
await this.updateUserProfile({
|
|
1199
1296
|
asset: "WETH",
|
|
1200
1297
|
protocols: ethProtocols
|
|
1201
1298
|
});
|
|
1202
|
-
return
|
|
1299
|
+
return await this.updateUserProfile({
|
|
1300
|
+
asset: "EURC",
|
|
1301
|
+
protocols: eurcProtocols
|
|
1302
|
+
});
|
|
1203
1303
|
} catch (error) {
|
|
1204
1304
|
throw new Error(`Failed to resume agent: ${error.message}`);
|
|
1205
1305
|
}
|
|
@@ -1555,11 +1655,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1555
1655
|
}
|
|
1556
1656
|
/**
|
|
1557
1657
|
* Get smart wallet address for a user
|
|
1558
|
-
* Returns the
|
|
1658
|
+
* Returns the Safe address for an EOA (deterministic for legacy wallets,
|
|
1659
|
+
* backend-assigned for predeployed pool wallets).
|
|
1559
1660
|
*
|
|
1560
1661
|
* @param userAddress - User's EOA address
|
|
1561
1662
|
* @param chainId - Target chain ID
|
|
1562
|
-
* @returns Smart wallet
|
|
1663
|
+
* @returns Smart wallet address, deployment status, and whether userAddress
|
|
1664
|
+
* is an on-chain OwnableValidator owner (false for reserved predeployed
|
|
1665
|
+
* wallets until the first deposit rotates ownership)
|
|
1563
1666
|
*/
|
|
1564
1667
|
async getSmartWalletAddress(userAddress, chainId) {
|
|
1565
1668
|
if (!userAddress) {
|
|
@@ -1574,14 +1677,24 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1574
1677
|
safeAddress,
|
|
1575
1678
|
chainConfig.publicClient
|
|
1576
1679
|
);
|
|
1680
|
+
const isOwner = isDeployed ? await isOwnableValidatorOwner(
|
|
1681
|
+
safeAddress,
|
|
1682
|
+
userAddress,
|
|
1683
|
+
chainConfig.publicClient
|
|
1684
|
+
) : false;
|
|
1577
1685
|
return {
|
|
1578
1686
|
address: safeAddress,
|
|
1579
|
-
isDeployed
|
|
1687
|
+
isDeployed,
|
|
1688
|
+
isOwner
|
|
1580
1689
|
};
|
|
1581
1690
|
}
|
|
1582
1691
|
/**
|
|
1583
1692
|
* Deploy Safe Smart Wallet for a user
|
|
1584
1693
|
*
|
|
1694
|
+
* @deprecated Prefer `depositFunds()`. Predeployed Safes and session keys are
|
|
1695
|
+
* managed automatically on first deposit. This method remains available for
|
|
1696
|
+
* legacy flows.
|
|
1697
|
+
*
|
|
1585
1698
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
1586
1699
|
* @param chainId - Target chain ID
|
|
1587
1700
|
* @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
|
|
@@ -1590,17 +1703,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1590
1703
|
*
|
|
1591
1704
|
* @example
|
|
1592
1705
|
* ```typescript
|
|
1593
|
-
* //
|
|
1594
|
-
* await sdk.
|
|
1706
|
+
* // Preferred: depositFunds handles predeployed wallet onboarding
|
|
1707
|
+
* await sdk.depositFunds(userAddress, 8453, amount, "USDC");
|
|
1595
1708
|
*
|
|
1596
|
-
* //
|
|
1597
|
-
* await sdk.deploySafe(userAddress, 8453
|
|
1598
|
-
*
|
|
1599
|
-
* // Deploy and automatically create session key
|
|
1600
|
-
* await sdk.deploySafe(userAddress, 8453, "conservative", true);
|
|
1709
|
+
* // Legacy: deploy with default conservative strategy
|
|
1710
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
1601
1711
|
* ```
|
|
1602
1712
|
*/
|
|
1603
1713
|
async deploySafe(userAddress, chainId, strategy, createSessionKey) {
|
|
1714
|
+
this.warnDeprecatedOnboardingMethod("deploySafe");
|
|
1604
1715
|
try {
|
|
1605
1716
|
if (!userAddress) {
|
|
1606
1717
|
throw new Error("User address is required");
|
|
@@ -1614,7 +1725,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1614
1725
|
userAddress,
|
|
1615
1726
|
chainId
|
|
1616
1727
|
);
|
|
1617
|
-
await this.updateUserProtocols(
|
|
1728
|
+
await this.updateUserProtocols(strategy);
|
|
1618
1729
|
return {
|
|
1619
1730
|
success: true,
|
|
1620
1731
|
safeAddress: predeployedAddress,
|
|
@@ -1635,7 +1746,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1635
1746
|
chainConfig.publicClient
|
|
1636
1747
|
);
|
|
1637
1748
|
if (alreadyDeployed) {
|
|
1638
|
-
await this.updateUserProtocols(
|
|
1749
|
+
await this.updateUserProtocols(strategy);
|
|
1639
1750
|
let sessionKeyCreated2 = false;
|
|
1640
1751
|
if (createSessionKey) {
|
|
1641
1752
|
try {
|
|
@@ -1675,7 +1786,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1675
1786
|
initError.message
|
|
1676
1787
|
);
|
|
1677
1788
|
}
|
|
1678
|
-
await this.updateUserProtocols(chainId, strategy);
|
|
1679
1789
|
let sessionKeyCreated = false;
|
|
1680
1790
|
if (createSessionKey) {
|
|
1681
1791
|
try {
|
|
@@ -1697,25 +1807,34 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1697
1807
|
};
|
|
1698
1808
|
} catch (error) {
|
|
1699
1809
|
console.error("Safe deployment failed:", error);
|
|
1700
|
-
throw new Error(
|
|
1810
|
+
throw new Error(
|
|
1811
|
+
`Safe deployment failed: ${error.message}. deploySafe() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
|
|
1812
|
+
);
|
|
1701
1813
|
}
|
|
1702
1814
|
}
|
|
1703
1815
|
/**
|
|
1704
1816
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
1705
1817
|
* This is the simplified method that automatically fetches session configuration
|
|
1706
1818
|
*
|
|
1819
|
+
* @deprecated Prefer `depositFunds()`. Predeployed wallets already have the
|
|
1820
|
+
* agent session enabled; session activation is handled after first deposit.
|
|
1821
|
+
* This method remains available for legacy flows.
|
|
1822
|
+
*
|
|
1707
1823
|
* @param userAddress - User's EOA or Safe address
|
|
1708
1824
|
* @param chainId - Target chain ID
|
|
1709
1825
|
* @returns Session key response with signature and nonces
|
|
1710
1826
|
*
|
|
1711
1827
|
* @example
|
|
1712
1828
|
* ```typescript
|
|
1713
|
-
* //
|
|
1829
|
+
* // Preferred: depositFunds handles session onboarding for predeployed wallets
|
|
1830
|
+
* await sdk.depositFunds(userAddress, 8453, amount, "USDC");
|
|
1831
|
+
*
|
|
1832
|
+
* // Legacy:
|
|
1714
1833
|
* const result = await sdk.createSessionKey(userAddress, 8453);
|
|
1715
|
-
* console.log("Session created:", result.signature);
|
|
1716
1834
|
* ```
|
|
1717
1835
|
*/
|
|
1718
1836
|
async createSessionKey(userAddress, chainId) {
|
|
1837
|
+
this.warnDeprecatedOnboardingMethod("createSessionKey");
|
|
1719
1838
|
try {
|
|
1720
1839
|
await this.authenticateUser();
|
|
1721
1840
|
if (!this.authenticatedUserId) {
|
|
@@ -1789,7 +1908,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1789
1908
|
};
|
|
1790
1909
|
} catch (error) {
|
|
1791
1910
|
throw new Error(
|
|
1792
|
-
`Failed to create session key: ${error.message}
|
|
1911
|
+
`Failed to create session key: ${error.message}. createSessionKey() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
|
|
1793
1912
|
);
|
|
1794
1913
|
}
|
|
1795
1914
|
}
|
|
@@ -1846,29 +1965,33 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1846
1965
|
}
|
|
1847
1966
|
}
|
|
1848
1967
|
/**
|
|
1849
|
-
* Patch the user's protocol selection
|
|
1850
|
-
*
|
|
1851
|
-
*
|
|
1968
|
+
* Patch the user's protocol selection on USDC, WETH, and EURC across all
|
|
1969
|
+
* supported chains (EURC limited to Mainnet/Base). Mirrors the front-end
|
|
1970
|
+
* customization flow:
|
|
1971
|
+
* 1. Merge existing chains from `getUserDetails` with the target chains
|
|
1852
1972
|
* (never overwrite already-configured chains).
|
|
1853
1973
|
* 2. Filter protocols by strategy, chain and asset support.
|
|
1854
1974
|
* 3. Drop protocols that don't have any pools available for the
|
|
1855
1975
|
* asset/chain/strategy combo.
|
|
1856
1976
|
* 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
|
|
1857
1977
|
*
|
|
1858
|
-
* Called from `
|
|
1978
|
+
* Called once from `depositFunds` on the account's first deposit.
|
|
1859
1979
|
*
|
|
1860
1980
|
* @internal
|
|
1861
1981
|
*/
|
|
1862
|
-
async updateUserProtocols(
|
|
1982
|
+
async updateUserProtocols(strategy) {
|
|
1863
1983
|
try {
|
|
1864
1984
|
const allProtocols = await this.httpClient.get(
|
|
1865
1985
|
ENDPOINTS.PROTOCOLS()
|
|
1866
1986
|
);
|
|
1867
|
-
|
|
1987
|
+
const allChains = [1, 8453, 42161];
|
|
1988
|
+
const assets = ["USDC", "WETH", "EURC"];
|
|
1989
|
+
for (const asset of assets) {
|
|
1868
1990
|
try {
|
|
1991
|
+
const chainsForAsset = asset === "EURC" ? [1, 8453] : allChains;
|
|
1869
1992
|
await this.updateUserProtocolsForAsset(
|
|
1870
1993
|
asset,
|
|
1871
|
-
|
|
1994
|
+
chainsForAsset,
|
|
1872
1995
|
strategy,
|
|
1873
1996
|
allProtocols
|
|
1874
1997
|
);
|
|
@@ -1888,11 +2011,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1888
2011
|
* Compute and persist the protocol selection for a single asset.
|
|
1889
2012
|
* @internal
|
|
1890
2013
|
*/
|
|
1891
|
-
async updateUserProtocolsForAsset(asset,
|
|
2014
|
+
async updateUserProtocolsForAsset(asset, chains, strategy, allProtocols) {
|
|
1892
2015
|
const userDetails = await this.getUserDetails(asset);
|
|
1893
2016
|
const existingChains = userDetails.chains ?? [];
|
|
1894
2017
|
const effectiveChains = Array.from(
|
|
1895
|
-
/* @__PURE__ */ new Set([...existingChains,
|
|
2018
|
+
/* @__PURE__ */ new Set([...existingChains, ...chains])
|
|
1896
2019
|
);
|
|
1897
2020
|
const publicStrategy = strategy ?? (isValidPublicStrategy(userDetails.strategy ?? "") ? userDetails.strategy : "conservative");
|
|
1898
2021
|
const internalStrategy = toInternalStrategy(publicStrategy);
|
|
@@ -1907,7 +2030,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1907
2030
|
effectiveChains,
|
|
1908
2031
|
asset
|
|
1909
2032
|
);
|
|
1910
|
-
console.log("withPools", withPools, "effectiveChains", effectiveChains, "asset", asset);
|
|
1911
2033
|
await this.updateUserProfile({
|
|
1912
2034
|
asset,
|
|
1913
2035
|
protocols: withPools,
|
|
@@ -1971,8 +2093,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1971
2093
|
* Deposit funds from EOA to Safe smart wallet
|
|
1972
2094
|
* Transfers tokens from the connected wallet to the user's Safe and logs the deposit
|
|
1973
2095
|
*
|
|
1974
|
-
* Token is
|
|
1975
|
-
* - Ethereum Mainnet (1), Base (8453), Arbitrum (42161)
|
|
2096
|
+
* Token address is selected from `asset` for the given chain:
|
|
2097
|
+
* - Ethereum Mainnet (1), Base (8453), Arbitrum (42161): USDC or WETH
|
|
2098
|
+
* - Ethereum Mainnet (1), Base (8453): EURC
|
|
2099
|
+
*
|
|
2100
|
+
* On the account's first deposit (USDC profile has no chains yet), patches
|
|
2101
|
+
* protocol selection for USDC, WETH, and EURC across all supported chains
|
|
2102
|
+
* (EURC on Mainnet/Base only) before the transfer and log_deposit.
|
|
2103
|
+
* Pass `strategy` to select protocols for that first-deposit setup
|
|
2104
|
+
* (same role as the former `deploySafe` strategy argument).
|
|
1976
2105
|
*
|
|
1977
2106
|
* Minimum portfolio balance enforced (Safe balance + deposit amount),
|
|
1978
2107
|
* configured per-chain in `MIN_PORTFOLIO_BALANCE`:
|
|
@@ -1985,7 +2114,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1985
2114
|
* @param userAddress - User's address (owner of the Safe)
|
|
1986
2115
|
* @param chainId - Target chain ID
|
|
1987
2116
|
* @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
|
|
1988
|
-
* @param asset -
|
|
2117
|
+
* @param asset - Asset symbol: "USDC", "WETH", or "EURC".
|
|
2118
|
+
* EURC is supported on Ethereum Mainnet and Base only.
|
|
2119
|
+
* @param strategy - Optional strategy for first-deposit protocol patching:
|
|
2120
|
+
* "conservative" (default) or "aggressive"
|
|
1989
2121
|
* @returns Deposit response with transaction hash
|
|
1990
2122
|
*
|
|
1991
2123
|
* @example
|
|
@@ -1994,11 +2126,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1994
2126
|
* const result = await sdk.depositFunds(
|
|
1995
2127
|
* "0xUser...",
|
|
1996
2128
|
* 8453,
|
|
1997
|
-
* "10000000000"
|
|
2129
|
+
* "10000000000",
|
|
2130
|
+
* "USDC"
|
|
1998
2131
|
* );
|
|
2132
|
+
*
|
|
2133
|
+
* // First deposit with aggressive strategy
|
|
2134
|
+
* await sdk.depositFunds(userAddress, 8453, "10000000000", "USDC", "aggressive");
|
|
1999
2135
|
* ```
|
|
2000
2136
|
*/
|
|
2001
|
-
async depositFunds(userAddress, chainId, amount, asset) {
|
|
2137
|
+
async depositFunds(userAddress, chainId, amount, asset, strategy) {
|
|
2002
2138
|
try {
|
|
2003
2139
|
if (!userAddress) {
|
|
2004
2140
|
throw new Error("User address is required");
|
|
@@ -2009,11 +2145,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2009
2145
|
if (!amount || isNaN(Number(amount)) || Number(amount) <= 0) {
|
|
2010
2146
|
throw new Error("Valid amount is required");
|
|
2011
2147
|
}
|
|
2012
|
-
|
|
2148
|
+
if (!asset) {
|
|
2149
|
+
throw new Error("Asset is required (USDC, WETH, or EURC)");
|
|
2150
|
+
}
|
|
2151
|
+
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
2152
|
+
throw new Error(
|
|
2153
|
+
`Invalid strategy: ${strategy}. Must be "conservative" or "aggressive".`
|
|
2154
|
+
);
|
|
2155
|
+
}
|
|
2156
|
+
const assetSymbol = asset.toUpperCase();
|
|
2013
2157
|
const assetConfig = ASSET_CONFIGS[assetSymbol];
|
|
2014
2158
|
if (!assetConfig) {
|
|
2015
2159
|
throw new Error(
|
|
2016
|
-
`Unsupported asset: ${assetSymbol}. Supported: USDC, WETH.`
|
|
2160
|
+
`Unsupported asset: ${assetSymbol}. Supported: USDC, WETH, EURC.`
|
|
2017
2161
|
);
|
|
2018
2162
|
}
|
|
2019
2163
|
const minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
|
|
@@ -2027,7 +2171,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2027
2171
|
);
|
|
2028
2172
|
if (!isDeployed) {
|
|
2029
2173
|
throw new Error(
|
|
2030
|
-
`Safe not
|
|
2174
|
+
`Safe not available for ${userAddress} on chain ${chainId}.`
|
|
2175
|
+
);
|
|
2176
|
+
}
|
|
2177
|
+
try {
|
|
2178
|
+
const usdcDetails = await this.getUserDetails("USDC");
|
|
2179
|
+
if ((usdcDetails.chains?.length ?? 0) === 0) {
|
|
2180
|
+
await this.updateUserProtocols(strategy);
|
|
2181
|
+
}
|
|
2182
|
+
} catch (protocolError) {
|
|
2183
|
+
console.warn(
|
|
2184
|
+
"Failed to update user protocols before deposit:",
|
|
2185
|
+
protocolError.message
|
|
2031
2186
|
);
|
|
2032
2187
|
}
|
|
2033
2188
|
const amountBigInt = BigInt(amount);
|
|
@@ -2201,7 +2356,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2201
2356
|
tokenSymbol
|
|
2202
2357
|
});
|
|
2203
2358
|
} else {
|
|
2204
|
-
console.log("Full withdrawal", tokenSymbol);
|
|
2205
2359
|
response = await this.httpClient.get(ENDPOINTS.USER_WITHDRAW, {
|
|
2206
2360
|
params: { chainId, tokenSymbol }
|
|
2207
2361
|
});
|
|
@@ -3993,24 +4147,6 @@ function createBankrProvider(config) {
|
|
|
3993
4147
|
};
|
|
3994
4148
|
return provider;
|
|
3995
4149
|
}
|
|
3996
|
-
|
|
3997
|
-
// src/config/modules.ts
|
|
3998
|
-
var SMART_SESSIONS_VALIDATOR = "0x00000000008bDABA73cD9815d79069c247Eb4bDA";
|
|
3999
|
-
var SMART_SESSIONS_FALLBACK = "0x12cae64c42f362e7d5a847c2d33388373f629177";
|
|
4000
|
-
var INTENT_EXECUTOR = "0x00000000005aD9ce1f5035FD62CA96CEf16AdAAF";
|
|
4001
|
-
var PROXY_EXECUTOR = "0xF659d30D4EB88B06A909F20839D8959Bd77d8790";
|
|
4002
|
-
var INTENT_SMART_SESSIONS = "0xad568b3f825a8d5ffc06dd3253526b64d810ae89";
|
|
4003
|
-
var OWNABLE_VALIDATOR = "0x000000000013fdB5234E4E3162a810F54d9f7E98";
|
|
4004
|
-
var SAFE_7579_ADDRESS2 = "0x7579EE8307284F293B1927136486880611F20002";
|
|
4005
|
-
var ERC7579_LAUNCHPAD_ADDRESS2 = "0x7579011aB74c46090561ea277Ba79D510c6C00ff";
|
|
4006
|
-
var POOL_MODULE_ADDRESSES = [
|
|
4007
|
-
SMART_SESSIONS_VALIDATOR,
|
|
4008
|
-
SMART_SESSIONS_FALLBACK,
|
|
4009
|
-
INTENT_EXECUTOR,
|
|
4010
|
-
PROXY_EXECUTOR,
|
|
4011
|
-
INTENT_SMART_SESSIONS,
|
|
4012
|
-
OWNABLE_VALIDATOR
|
|
4013
|
-
];
|
|
4014
4150
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4015
4151
|
0 && (module.exports = {
|
|
4016
4152
|
DEFAULT_TOKEN_ADDRESSES,
|