@zyfai/sdk 0.2.43 → 0.2.44
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 +15 -13
- package/dist/index.d.mts +51 -21
- package/dist/index.d.ts +51 -21
- package/dist/index.js +187 -60
- package/dist/index.mjs +188 -60
- 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
|
|
@@ -1047,6 +1136,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1047
1136
|
}
|
|
1048
1137
|
this.httpClient.setAuthToken(authToken);
|
|
1049
1138
|
this.authenticatedUserId = loginResponse.userId || null;
|
|
1139
|
+
console.log("this.authenticatedUserId", loginResponse);
|
|
1050
1140
|
this.hasActiveSessionKey = loginResponse.hasActiveSessionKey || false;
|
|
1051
1141
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
1052
1142
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
@@ -1138,10 +1228,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1138
1228
|
asset: "USDC",
|
|
1139
1229
|
protocols: []
|
|
1140
1230
|
});
|
|
1141
|
-
|
|
1231
|
+
await this.updateUserProfile({
|
|
1142
1232
|
asset: "WETH",
|
|
1143
1233
|
protocols: []
|
|
1144
1234
|
});
|
|
1235
|
+
const response = await this.updateUserProfile({
|
|
1236
|
+
asset: "EURC",
|
|
1237
|
+
protocols: []
|
|
1238
|
+
});
|
|
1145
1239
|
return response;
|
|
1146
1240
|
} catch (error) {
|
|
1147
1241
|
throw new Error(`Failed to pause agent: ${error.message}`);
|
|
@@ -1169,16 +1263,19 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1169
1263
|
try {
|
|
1170
1264
|
const userDetailsUSDC = await this.getUserDetails("USDC");
|
|
1171
1265
|
const userDetailsETH = await this.getUserDetails("WETH");
|
|
1266
|
+
const userDetailsEURC = await this.getUserDetails("EURC");
|
|
1172
1267
|
const chains = userDetailsUSDC.chains && userDetailsUSDC.chains.length > 0 ? userDetailsUSDC.chains : [8453, 42161];
|
|
1268
|
+
const eurcChains = userDetailsEURC.chains && userDetailsEURC.chains.length > 0 ? userDetailsEURC.chains.filter((c) => c === 1 || c === 8453) : [1, 8453];
|
|
1173
1269
|
const allProtocols = await this.httpClient.get(
|
|
1174
1270
|
ENDPOINTS.PROTOCOLS()
|
|
1175
1271
|
);
|
|
1176
1272
|
const usdcStrategy = userDetailsUSDC.strategy || "safe_strategy";
|
|
1177
1273
|
const ethStrategy = userDetailsETH.strategy || "safe_strategy";
|
|
1178
|
-
const
|
|
1274
|
+
const eurcStrategy = userDetailsEURC.strategy || "safe_strategy";
|
|
1275
|
+
const filterProtocolsByStrategy = (strategy, selectedChains) => {
|
|
1179
1276
|
return allProtocols.filter((protocol) => {
|
|
1180
1277
|
const hasMatchingChain = protocol.chains.some(
|
|
1181
|
-
(chain) =>
|
|
1278
|
+
(chain) => selectedChains.includes(chain)
|
|
1182
1279
|
);
|
|
1183
1280
|
if (!hasMatchingChain) {
|
|
1184
1281
|
return false;
|
|
@@ -1189,17 +1286,21 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1189
1286
|
return protocol.strategies?.includes("safe_strategy");
|
|
1190
1287
|
}).map((protocol) => protocol.id);
|
|
1191
1288
|
};
|
|
1192
|
-
const usdcProtocols = filterProtocolsByStrategy(usdcStrategy);
|
|
1193
|
-
const ethProtocols = filterProtocolsByStrategy(ethStrategy);
|
|
1289
|
+
const usdcProtocols = filterProtocolsByStrategy(usdcStrategy, chains);
|
|
1290
|
+
const ethProtocols = filterProtocolsByStrategy(ethStrategy, chains);
|
|
1291
|
+
const eurcProtocols = filterProtocolsByStrategy(eurcStrategy, eurcChains);
|
|
1194
1292
|
await this.updateUserProfile({
|
|
1195
1293
|
asset: "USDC",
|
|
1196
1294
|
protocols: usdcProtocols
|
|
1197
1295
|
});
|
|
1198
|
-
|
|
1296
|
+
await this.updateUserProfile({
|
|
1199
1297
|
asset: "WETH",
|
|
1200
1298
|
protocols: ethProtocols
|
|
1201
1299
|
});
|
|
1202
|
-
return
|
|
1300
|
+
return await this.updateUserProfile({
|
|
1301
|
+
asset: "EURC",
|
|
1302
|
+
protocols: eurcProtocols
|
|
1303
|
+
});
|
|
1203
1304
|
} catch (error) {
|
|
1204
1305
|
throw new Error(`Failed to resume agent: ${error.message}`);
|
|
1205
1306
|
}
|
|
@@ -1555,11 +1656,14 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1555
1656
|
}
|
|
1556
1657
|
/**
|
|
1557
1658
|
* Get smart wallet address for a user
|
|
1558
|
-
* Returns the
|
|
1659
|
+
* Returns the Safe address for an EOA (deterministic for legacy wallets,
|
|
1660
|
+
* backend-assigned for predeployed pool wallets).
|
|
1559
1661
|
*
|
|
1560
1662
|
* @param userAddress - User's EOA address
|
|
1561
1663
|
* @param chainId - Target chain ID
|
|
1562
|
-
* @returns Smart wallet
|
|
1664
|
+
* @returns Smart wallet address, deployment status, and whether userAddress
|
|
1665
|
+
* is an on-chain OwnableValidator owner (false for reserved predeployed
|
|
1666
|
+
* wallets until the first deposit rotates ownership)
|
|
1563
1667
|
*/
|
|
1564
1668
|
async getSmartWalletAddress(userAddress, chainId) {
|
|
1565
1669
|
if (!userAddress) {
|
|
@@ -1574,14 +1678,24 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1574
1678
|
safeAddress,
|
|
1575
1679
|
chainConfig.publicClient
|
|
1576
1680
|
);
|
|
1681
|
+
const isOwner = isDeployed ? await isOwnableValidatorOwner(
|
|
1682
|
+
safeAddress,
|
|
1683
|
+
userAddress,
|
|
1684
|
+
chainConfig.publicClient
|
|
1685
|
+
) : false;
|
|
1577
1686
|
return {
|
|
1578
1687
|
address: safeAddress,
|
|
1579
|
-
isDeployed
|
|
1688
|
+
isDeployed,
|
|
1689
|
+
isOwner
|
|
1580
1690
|
};
|
|
1581
1691
|
}
|
|
1582
1692
|
/**
|
|
1583
1693
|
* Deploy Safe Smart Wallet for a user
|
|
1584
1694
|
*
|
|
1695
|
+
* @deprecated Prefer `depositFunds()`. Predeployed Safes and session keys are
|
|
1696
|
+
* managed automatically on first deposit. This method remains available for
|
|
1697
|
+
* legacy flows.
|
|
1698
|
+
*
|
|
1585
1699
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
1586
1700
|
* @param chainId - Target chain ID
|
|
1587
1701
|
* @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
|
|
@@ -1590,17 +1704,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1590
1704
|
*
|
|
1591
1705
|
* @example
|
|
1592
1706
|
* ```typescript
|
|
1593
|
-
* //
|
|
1594
|
-
* await sdk.
|
|
1707
|
+
* // Preferred: depositFunds handles predeployed wallet onboarding
|
|
1708
|
+
* await sdk.depositFunds(userAddress, 8453, amount, "USDC");
|
|
1595
1709
|
*
|
|
1596
|
-
* //
|
|
1597
|
-
* await sdk.deploySafe(userAddress, 8453
|
|
1598
|
-
*
|
|
1599
|
-
* // Deploy and automatically create session key
|
|
1600
|
-
* await sdk.deploySafe(userAddress, 8453, "conservative", true);
|
|
1710
|
+
* // Legacy: deploy with default conservative strategy
|
|
1711
|
+
* await sdk.deploySafe(userAddress, 8453);
|
|
1601
1712
|
* ```
|
|
1602
1713
|
*/
|
|
1603
1714
|
async deploySafe(userAddress, chainId, strategy, createSessionKey) {
|
|
1715
|
+
this.warnDeprecatedOnboardingMethod("deploySafe");
|
|
1604
1716
|
try {
|
|
1605
1717
|
if (!userAddress) {
|
|
1606
1718
|
throw new Error("User address is required");
|
|
@@ -1614,7 +1726,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1614
1726
|
userAddress,
|
|
1615
1727
|
chainId
|
|
1616
1728
|
);
|
|
1617
|
-
await this.updateUserProtocols(
|
|
1729
|
+
await this.updateUserProtocols(strategy);
|
|
1618
1730
|
return {
|
|
1619
1731
|
success: true,
|
|
1620
1732
|
safeAddress: predeployedAddress,
|
|
@@ -1635,7 +1747,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1635
1747
|
chainConfig.publicClient
|
|
1636
1748
|
);
|
|
1637
1749
|
if (alreadyDeployed) {
|
|
1638
|
-
await this.updateUserProtocols(
|
|
1750
|
+
await this.updateUserProtocols(strategy);
|
|
1639
1751
|
let sessionKeyCreated2 = false;
|
|
1640
1752
|
if (createSessionKey) {
|
|
1641
1753
|
try {
|
|
@@ -1675,7 +1787,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1675
1787
|
initError.message
|
|
1676
1788
|
);
|
|
1677
1789
|
}
|
|
1678
|
-
await this.updateUserProtocols(chainId, strategy);
|
|
1679
1790
|
let sessionKeyCreated = false;
|
|
1680
1791
|
if (createSessionKey) {
|
|
1681
1792
|
try {
|
|
@@ -1697,25 +1808,34 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1697
1808
|
};
|
|
1698
1809
|
} catch (error) {
|
|
1699
1810
|
console.error("Safe deployment failed:", error);
|
|
1700
|
-
throw new Error(
|
|
1811
|
+
throw new Error(
|
|
1812
|
+
`Safe deployment failed: ${error.message}. deploySafe() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
|
|
1813
|
+
);
|
|
1701
1814
|
}
|
|
1702
1815
|
}
|
|
1703
1816
|
/**
|
|
1704
1817
|
* Create session key with auto-fetched configuration from Zyfai API
|
|
1705
1818
|
* This is the simplified method that automatically fetches session configuration
|
|
1706
1819
|
*
|
|
1820
|
+
* @deprecated Prefer `depositFunds()`. Predeployed wallets already have the
|
|
1821
|
+
* agent session enabled; session activation is handled after first deposit.
|
|
1822
|
+
* This method remains available for legacy flows.
|
|
1823
|
+
*
|
|
1707
1824
|
* @param userAddress - User's EOA or Safe address
|
|
1708
1825
|
* @param chainId - Target chain ID
|
|
1709
1826
|
* @returns Session key response with signature and nonces
|
|
1710
1827
|
*
|
|
1711
1828
|
* @example
|
|
1712
1829
|
* ```typescript
|
|
1713
|
-
* //
|
|
1830
|
+
* // Preferred: depositFunds handles session onboarding for predeployed wallets
|
|
1831
|
+
* await sdk.depositFunds(userAddress, 8453, amount, "USDC");
|
|
1832
|
+
*
|
|
1833
|
+
* // Legacy:
|
|
1714
1834
|
* const result = await sdk.createSessionKey(userAddress, 8453);
|
|
1715
|
-
* console.log("Session created:", result.signature);
|
|
1716
1835
|
* ```
|
|
1717
1836
|
*/
|
|
1718
1837
|
async createSessionKey(userAddress, chainId) {
|
|
1838
|
+
this.warnDeprecatedOnboardingMethod("createSessionKey");
|
|
1719
1839
|
try {
|
|
1720
1840
|
await this.authenticateUser();
|
|
1721
1841
|
if (!this.authenticatedUserId) {
|
|
@@ -1789,7 +1909,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1789
1909
|
};
|
|
1790
1910
|
} catch (error) {
|
|
1791
1911
|
throw new Error(
|
|
1792
|
-
`Failed to create session key: ${error.message}
|
|
1912
|
+
`Failed to create session key: ${error.message}. createSessionKey() is deprecated \u2014 prefer depositFunds() for predeployed wallet onboarding.`
|
|
1793
1913
|
);
|
|
1794
1914
|
}
|
|
1795
1915
|
}
|
|
@@ -1846,29 +1966,33 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1846
1966
|
}
|
|
1847
1967
|
}
|
|
1848
1968
|
/**
|
|
1849
|
-
* Patch the user's protocol selection
|
|
1850
|
-
*
|
|
1851
|
-
*
|
|
1969
|
+
* Patch the user's protocol selection on USDC, WETH, and EURC across all
|
|
1970
|
+
* supported chains (EURC limited to Mainnet/Base). Mirrors the front-end
|
|
1971
|
+
* customization flow:
|
|
1972
|
+
* 1. Merge existing chains from `getUserDetails` with the target chains
|
|
1852
1973
|
* (never overwrite already-configured chains).
|
|
1853
1974
|
* 2. Filter protocols by strategy, chain and asset support.
|
|
1854
1975
|
* 3. Drop protocols that don't have any pools available for the
|
|
1855
1976
|
* asset/chain/strategy combo.
|
|
1856
1977
|
* 4. Persist via `updateUserProfile` (writes `assetTypeSettings`).
|
|
1857
1978
|
*
|
|
1858
|
-
* Called from `
|
|
1979
|
+
* Called once from `depositFunds` on the account's first deposit.
|
|
1859
1980
|
*
|
|
1860
1981
|
* @internal
|
|
1861
1982
|
*/
|
|
1862
|
-
async updateUserProtocols(
|
|
1983
|
+
async updateUserProtocols(strategy) {
|
|
1863
1984
|
try {
|
|
1864
1985
|
const allProtocols = await this.httpClient.get(
|
|
1865
1986
|
ENDPOINTS.PROTOCOLS()
|
|
1866
1987
|
);
|
|
1867
|
-
|
|
1988
|
+
const allChains = [1, 8453, 42161];
|
|
1989
|
+
const assets = ["USDC", "WETH", "EURC"];
|
|
1990
|
+
for (const asset of assets) {
|
|
1868
1991
|
try {
|
|
1992
|
+
const chainsForAsset = asset === "EURC" ? [1, 8453] : allChains;
|
|
1869
1993
|
await this.updateUserProtocolsForAsset(
|
|
1870
1994
|
asset,
|
|
1871
|
-
|
|
1995
|
+
chainsForAsset,
|
|
1872
1996
|
strategy,
|
|
1873
1997
|
allProtocols
|
|
1874
1998
|
);
|
|
@@ -1888,11 +2012,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1888
2012
|
* Compute and persist the protocol selection for a single asset.
|
|
1889
2013
|
* @internal
|
|
1890
2014
|
*/
|
|
1891
|
-
async updateUserProtocolsForAsset(asset,
|
|
2015
|
+
async updateUserProtocolsForAsset(asset, chains, strategy, allProtocols) {
|
|
1892
2016
|
const userDetails = await this.getUserDetails(asset);
|
|
1893
2017
|
const existingChains = userDetails.chains ?? [];
|
|
1894
2018
|
const effectiveChains = Array.from(
|
|
1895
|
-
/* @__PURE__ */ new Set([...existingChains,
|
|
2019
|
+
/* @__PURE__ */ new Set([...existingChains, ...chains])
|
|
1896
2020
|
);
|
|
1897
2021
|
const publicStrategy = strategy ?? (isValidPublicStrategy(userDetails.strategy ?? "") ? userDetails.strategy : "conservative");
|
|
1898
2022
|
const internalStrategy = toInternalStrategy(publicStrategy);
|
|
@@ -1907,7 +2031,6 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1907
2031
|
effectiveChains,
|
|
1908
2032
|
asset
|
|
1909
2033
|
);
|
|
1910
|
-
console.log("withPools", withPools, "effectiveChains", effectiveChains, "asset", asset);
|
|
1911
2034
|
await this.updateUserProfile({
|
|
1912
2035
|
asset,
|
|
1913
2036
|
protocols: withPools,
|
|
@@ -1974,6 +2097,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1974
2097
|
* Token is automatically selected based on chain (USDC by default):
|
|
1975
2098
|
* - Ethereum Mainnet (1), Base (8453), Arbitrum (42161)
|
|
1976
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
|
+
*
|
|
1977
2104
|
* Minimum portfolio balance enforced (Safe balance + deposit amount),
|
|
1978
2105
|
* configured per-chain in `MIN_PORTFOLIO_BALANCE`:
|
|
1979
2106
|
* - Ethereum Mainnet (1): 5 USDC (test threshold)
|
|
@@ -1985,7 +2112,8 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
1985
2112
|
* @param userAddress - User's address (owner of the Safe)
|
|
1986
2113
|
* @param chainId - Target chain ID
|
|
1987
2114
|
* @param amount - Amount in least decimal units (e.g., "100000000" for 100 USDC with 6 decimals)
|
|
1988
|
-
* @param asset - Optional asset symbol ("USDC" or "
|
|
2115
|
+
* @param asset - Optional asset symbol ("USDC", "WETH", or "EURC"). Defaults to "USDC".
|
|
2116
|
+
* EURC is supported on Ethereum Mainnet and Base only.
|
|
1989
2117
|
* @returns Deposit response with transaction hash
|
|
1990
2118
|
*
|
|
1991
2119
|
* @example
|
|
@@ -2013,7 +2141,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2013
2141
|
const assetConfig = ASSET_CONFIGS[assetSymbol];
|
|
2014
2142
|
if (!assetConfig) {
|
|
2015
2143
|
throw new Error(
|
|
2016
|
-
`Unsupported asset: ${assetSymbol}. Supported: USDC, WETH.`
|
|
2144
|
+
`Unsupported asset: ${assetSymbol}. Supported: USDC, WETH, EURC.`
|
|
2017
2145
|
);
|
|
2018
2146
|
}
|
|
2019
2147
|
const minRequired = MIN_PORTFOLIO_BALANCE[chainId]?.[assetSymbol];
|
|
@@ -2027,7 +2155,18 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2027
2155
|
);
|
|
2028
2156
|
if (!isDeployed) {
|
|
2029
2157
|
throw new Error(
|
|
2030
|
-
`Safe not
|
|
2158
|
+
`Safe not available for ${userAddress} on chain ${chainId}.`
|
|
2159
|
+
);
|
|
2160
|
+
}
|
|
2161
|
+
try {
|
|
2162
|
+
const usdcDetails = await this.getUserDetails("USDC");
|
|
2163
|
+
if ((usdcDetails.chains?.length ?? 0) === 0) {
|
|
2164
|
+
await this.updateUserProtocols();
|
|
2165
|
+
}
|
|
2166
|
+
} catch (protocolError) {
|
|
2167
|
+
console.warn(
|
|
2168
|
+
"Failed to update user protocols before deposit:",
|
|
2169
|
+
protocolError.message
|
|
2031
2170
|
);
|
|
2032
2171
|
}
|
|
2033
2172
|
const amountBigInt = BigInt(amount);
|
|
@@ -2062,6 +2201,12 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2062
2201
|
hash: txHash
|
|
2063
2202
|
});
|
|
2064
2203
|
try {
|
|
2204
|
+
console.log("Logging deposit to backend", {
|
|
2205
|
+
chainId,
|
|
2206
|
+
transaction: txHash,
|
|
2207
|
+
token,
|
|
2208
|
+
amount
|
|
2209
|
+
});
|
|
2065
2210
|
await this.httpClient.post(ENDPOINTS.LOG_DEPOSIT, {
|
|
2066
2211
|
chainId,
|
|
2067
2212
|
transaction: txHash,
|
|
@@ -3993,24 +4138,6 @@ function createBankrProvider(config) {
|
|
|
3993
4138
|
};
|
|
3994
4139
|
return provider;
|
|
3995
4140
|
}
|
|
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
4141
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4015
4142
|
0 && (module.exports = {
|
|
4016
4143
|
DEFAULT_TOKEN_ADDRESSES,
|