@zyfai/sdk 0.12.0 → 1.0.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 +47 -45
- package/dist/index.d.mts +43 -14
- package/dist/index.d.ts +43 -14
- package/dist/index.js +204 -62
- package/dist/index.mjs +181 -34
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -691,6 +691,63 @@ var VAULT_ABI = [
|
|
|
691
691
|
}
|
|
692
692
|
];
|
|
693
693
|
var VAULT_ADDRESS = "0xD580071c47d4a667858B5FafAb85BC9C609beC5D";
|
|
694
|
+
var MERKL_DISTRIBUTOR_ADDRESS = "0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae";
|
|
695
|
+
var RZFI_TOKEN_ADDRESS = "0x1c08C7df416062b472F553DCC1ed3045489520C5";
|
|
696
|
+
var MERKL_DISTRIBUTOR_ABI = (0, import_viem.parseAbi)([
|
|
697
|
+
"function claim(address[] users, address[] tokens, uint256[] amounts, bytes32[][] proofs)",
|
|
698
|
+
"function claimed(address user, address token) view returns (uint208 amount, uint48 timestamp, bytes32 merkleRoot)",
|
|
699
|
+
"function getMerkleRoot() view returns (bytes32)"
|
|
700
|
+
]);
|
|
701
|
+
var SAFE_ABI = (0, import_viem.parseAbi)([
|
|
702
|
+
"function execTransaction(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 baseGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures) payable returns (bool success)",
|
|
703
|
+
"function getOwners() view returns (address[])",
|
|
704
|
+
"function getThreshold() view returns (uint256)"
|
|
705
|
+
]);
|
|
706
|
+
|
|
707
|
+
// src/utils/rzfi-claim.ts
|
|
708
|
+
var import_viem2 = require("viem");
|
|
709
|
+
var MERKL_API_URL = "https://api.merkl.xyz/v4";
|
|
710
|
+
async function fetchMerklRzfiReward(safe) {
|
|
711
|
+
const response = await fetch(
|
|
712
|
+
`${MERKL_API_URL}/users/${safe}/rewards?chainId=8453`
|
|
713
|
+
);
|
|
714
|
+
if (!response.ok) {
|
|
715
|
+
throw new Error(`Merkl API error: ${response.status}`);
|
|
716
|
+
}
|
|
717
|
+
const body = await response.json();
|
|
718
|
+
const reward = body[0]?.rewards?.find(
|
|
719
|
+
(r) => r.token.address.toLowerCase() === RZFI_TOKEN_ADDRESS.toLowerCase()
|
|
720
|
+
);
|
|
721
|
+
return reward ? { amount: BigInt(reward.amount), root: reward.root, proofs: reward.proofs } : null;
|
|
722
|
+
}
|
|
723
|
+
function encodeRzfiClaimExecTransaction(params) {
|
|
724
|
+
const { safe, owner, amount, proofs } = params;
|
|
725
|
+
const claimData = (0, import_viem2.encodeFunctionData)({
|
|
726
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
727
|
+
functionName: "claim",
|
|
728
|
+
args: [[safe], [RZFI_TOKEN_ADDRESS], [amount], [proofs]]
|
|
729
|
+
});
|
|
730
|
+
const signature = (0, import_viem2.encodePacked)(
|
|
731
|
+
["bytes32", "bytes32", "uint8"],
|
|
732
|
+
[(0, import_viem2.pad)(owner), (0, import_viem2.pad)("0x00"), 1]
|
|
733
|
+
);
|
|
734
|
+
return (0, import_viem2.encodeFunctionData)({
|
|
735
|
+
abi: SAFE_ABI,
|
|
736
|
+
functionName: "execTransaction",
|
|
737
|
+
args: [
|
|
738
|
+
MERKL_DISTRIBUTOR_ADDRESS,
|
|
739
|
+
0n,
|
|
740
|
+
claimData,
|
|
741
|
+
0,
|
|
742
|
+
0n,
|
|
743
|
+
0n,
|
|
744
|
+
0n,
|
|
745
|
+
import_viem2.zeroAddress,
|
|
746
|
+
import_viem2.zeroAddress,
|
|
747
|
+
signature
|
|
748
|
+
]
|
|
749
|
+
});
|
|
750
|
+
}
|
|
694
751
|
|
|
695
752
|
// src/config/constants.ts
|
|
696
753
|
var ZYFI_FEE_RATE = 0.1;
|
|
@@ -825,11 +882,11 @@ function isMainnetMinPortfolioExempt(chainId, ...addresses) {
|
|
|
825
882
|
|
|
826
883
|
// src/core/ZyfaiSDK.ts
|
|
827
884
|
var import_accounts2 = require("viem/accounts");
|
|
828
|
-
var
|
|
885
|
+
var import_viem5 = require("viem");
|
|
829
886
|
var import_relay_sdk2 = require("@relayprotocol/relay-sdk");
|
|
830
887
|
|
|
831
888
|
// src/config/chains.ts
|
|
832
|
-
var
|
|
889
|
+
var import_viem3 = require("viem");
|
|
833
890
|
var import_chains = require("viem/chains");
|
|
834
891
|
var DEFAULT_TOKEN_ADDRESSES = {
|
|
835
892
|
1: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
@@ -948,7 +1005,7 @@ var ASSET_CONFIGS = {
|
|
|
948
1005
|
enabled: true
|
|
949
1006
|
},
|
|
950
1007
|
// Coinbase B20 tokenized NVIDIA equity. Base only, and only reachable through
|
|
951
|
-
// protocols with delayed withdrawals — see the `
|
|
1008
|
+
// protocols with delayed withdrawals — see the `advanced` strategy.
|
|
952
1009
|
NVDAc: {
|
|
953
1010
|
symbol: "NVDAc",
|
|
954
1011
|
assetType: "nvdac",
|
|
@@ -1004,9 +1061,9 @@ var getChainConfig = (chainId, rpcUrls) => {
|
|
|
1004
1061
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
1005
1062
|
}
|
|
1006
1063
|
const rpcUrl = rpcUrls && rpcUrls[chainId] || DEFAULT_RPC_URLS[chainId];
|
|
1007
|
-
const publicClient = (0,
|
|
1064
|
+
const publicClient = (0, import_viem3.createPublicClient)({
|
|
1008
1065
|
chain,
|
|
1009
|
-
transport: (0,
|
|
1066
|
+
transport: (0, import_viem3.http)(rpcUrl)
|
|
1010
1067
|
});
|
|
1011
1068
|
return {
|
|
1012
1069
|
chain,
|
|
@@ -1264,7 +1321,7 @@ function getManagedAssets() {
|
|
|
1264
1321
|
// src/utils/safe-account.ts
|
|
1265
1322
|
var import_module_sdk = require("@rhinestone/module-sdk");
|
|
1266
1323
|
var import_accounts = require("permissionless/accounts");
|
|
1267
|
-
var
|
|
1324
|
+
var import_viem4 = require("viem");
|
|
1268
1325
|
var import_account_abstraction = require("viem/account-abstraction");
|
|
1269
1326
|
|
|
1270
1327
|
// src/config/modules.ts
|
|
@@ -1294,12 +1351,12 @@ var getSafeAccount = async (config) => {
|
|
|
1294
1351
|
if (!safeOwnerAddress) {
|
|
1295
1352
|
throw new Error("Safe owner address is required");
|
|
1296
1353
|
}
|
|
1297
|
-
const formattedOwnerAddress = (0,
|
|
1354
|
+
const formattedOwnerAddress = (0, import_viem4.getAddress)(safeOwnerAddress);
|
|
1298
1355
|
const ownableValidator = (0, import_module_sdk.getOwnableValidator)({
|
|
1299
1356
|
owners: [formattedOwnerAddress],
|
|
1300
1357
|
threshold: 1
|
|
1301
1358
|
});
|
|
1302
|
-
const saltHex = (0,
|
|
1359
|
+
const saltHex = (0, import_viem4.fromHex)((0, import_viem4.toHex)(ACCOUNT_SALT), "bigint");
|
|
1303
1360
|
const tempOwner = {
|
|
1304
1361
|
address: formattedOwnerAddress,
|
|
1305
1362
|
type: "json-rpc"
|
|
@@ -1346,12 +1403,12 @@ var isSafeDeployed = async (address, publicClient) => {
|
|
|
1346
1403
|
}
|
|
1347
1404
|
};
|
|
1348
1405
|
var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) => {
|
|
1349
|
-
const normalizedUser = (0,
|
|
1350
|
-
const normalizedSafe = (0,
|
|
1406
|
+
const normalizedUser = (0, import_viem4.getAddress)(userAddress);
|
|
1407
|
+
const normalizedSafe = (0, import_viem4.getAddress)(safeAddress);
|
|
1351
1408
|
const validatorAddresses = Array.from(
|
|
1352
1409
|
/* @__PURE__ */ new Set([
|
|
1353
|
-
(0,
|
|
1354
|
-
(0,
|
|
1410
|
+
(0, import_viem4.getAddress)(OWNABLE_VALIDATOR),
|
|
1411
|
+
(0, import_viem4.getAddress)(import_module_sdk.OWNABLE_VALIDATOR_ADDRESS)
|
|
1355
1412
|
])
|
|
1356
1413
|
);
|
|
1357
1414
|
for (const validatorAddress of validatorAddresses) {
|
|
@@ -1362,7 +1419,7 @@ var isOwnableValidatorOwner = async (safeAddress, userAddress, publicClient) =>
|
|
|
1362
1419
|
functionName: "getOwners",
|
|
1363
1420
|
args: [normalizedSafe]
|
|
1364
1421
|
});
|
|
1365
|
-
if (owners.some((owner) => (0,
|
|
1422
|
+
if (owners.some((owner) => (0, import_viem4.getAddress)(owner) === normalizedUser)) {
|
|
1366
1423
|
return true;
|
|
1367
1424
|
}
|
|
1368
1425
|
} catch {
|
|
@@ -1493,15 +1550,15 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
|
|
|
1493
1550
|
};
|
|
1494
1551
|
|
|
1495
1552
|
// src/utils/strategy.ts
|
|
1496
|
-
var PUBLIC_STRATEGIES = `"conservative", "
|
|
1553
|
+
var PUBLIC_STRATEGIES = `"conservative", "balanced" or "advanced"`;
|
|
1497
1554
|
var SUPPORTED_ASSETS = Object.entries(ASSET_CONFIGS).filter(([, config]) => config?.enabled === true).map(([symbol]) => `"${symbol}"`).join(", ");
|
|
1498
1555
|
function toInternalStrategy(publicStrategy) {
|
|
1499
1556
|
switch (publicStrategy) {
|
|
1500
1557
|
case "conservative":
|
|
1501
1558
|
return "safe_strategy";
|
|
1502
|
-
case "
|
|
1559
|
+
case "balanced":
|
|
1503
1560
|
return "degen_strategy";
|
|
1504
|
-
case "
|
|
1561
|
+
case "advanced":
|
|
1505
1562
|
return "async_strategy";
|
|
1506
1563
|
default:
|
|
1507
1564
|
throw new Error(
|
|
@@ -1514,10 +1571,10 @@ function toPublicStrategy(internalStrategy) {
|
|
|
1514
1571
|
return "conservative";
|
|
1515
1572
|
}
|
|
1516
1573
|
if (internalStrategy === "degen_strategy" || internalStrategy === "degen") {
|
|
1517
|
-
return "
|
|
1574
|
+
return "balanced";
|
|
1518
1575
|
}
|
|
1519
1576
|
if (internalStrategy === "async_strategy" || internalStrategy === "async") {
|
|
1520
|
-
return "
|
|
1577
|
+
return "advanced";
|
|
1521
1578
|
}
|
|
1522
1579
|
throw new Error(
|
|
1523
1580
|
`Invalid internal strategy: ${internalStrategy}. Must be "safe_strategy", "degen_strategy" or "async_strategy".`
|
|
@@ -1534,7 +1591,7 @@ function toPublicStrategyOrUndefined(internalStrategy) {
|
|
|
1534
1591
|
}
|
|
1535
1592
|
}
|
|
1536
1593
|
function isValidPublicStrategy(strategy) {
|
|
1537
|
-
return strategy === "conservative" || strategy === "
|
|
1594
|
+
return strategy === "conservative" || strategy === "balanced" || strategy === "advanced";
|
|
1538
1595
|
}
|
|
1539
1596
|
function convertStrategyToPublic(obj) {
|
|
1540
1597
|
if (!obj.strategy) {
|
|
@@ -2140,7 +2197,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2140
2197
|
}
|
|
2141
2198
|
this.httpClient.setAuthToken(session.accessToken);
|
|
2142
2199
|
this.authenticatedUserId = session.userId ?? "bearer-session";
|
|
2143
|
-
this.sessionEoa = session.eoa ? (0,
|
|
2200
|
+
this.sessionEoa = session.eoa ? (0, import_viem5.getAddress)(session.eoa) : null;
|
|
2144
2201
|
this.sessionChannel = session.channel;
|
|
2145
2202
|
this.isPredeployed = false;
|
|
2146
2203
|
this.predeployedResolved = false;
|
|
@@ -2189,7 +2246,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2189
2246
|
this.isPredeployed = loginResponse.predeployed || false;
|
|
2190
2247
|
this.predeployedResolved = true;
|
|
2191
2248
|
this.connectedSmartWallet = loginResponse.smartWallet || null;
|
|
2192
|
-
this.sessionEoa = (0,
|
|
2249
|
+
this.sessionEoa = (0, import_viem5.getAddress)(params.message.address);
|
|
2193
2250
|
this.sessionChannel = void 0;
|
|
2194
2251
|
return loginResponse;
|
|
2195
2252
|
}
|
|
@@ -2218,7 +2275,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2218
2275
|
return;
|
|
2219
2276
|
}
|
|
2220
2277
|
const walletClient = this.getWalletClient();
|
|
2221
|
-
const userAddress = (0,
|
|
2278
|
+
const userAddress = (0, import_viem5.getAddress)(walletClient.account.address);
|
|
2222
2279
|
const chainId = this.currentChainId || walletClient.chain?.id || 8453;
|
|
2223
2280
|
const challengeResponse = await this.httpClient.post(ENDPOINTS.AUTH_CHALLENGE, {});
|
|
2224
2281
|
let uri;
|
|
@@ -2306,7 +2363,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2306
2363
|
if (request.strategy) {
|
|
2307
2364
|
if (!isValidPublicStrategy(request.strategy)) {
|
|
2308
2365
|
throw new Error(
|
|
2309
|
-
`Invalid strategy: ${request.strategy}. Must be "conservative", "
|
|
2366
|
+
`Invalid strategy: ${request.strategy}. Must be "conservative", "balanced" or "advanced".`
|
|
2310
2367
|
);
|
|
2311
2368
|
}
|
|
2312
2369
|
rebalanceStrategy = toInternalStrategy(request.strategy);
|
|
@@ -2596,10 +2653,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2596
2653
|
this.walletClient.chain?.id || 8453,
|
|
2597
2654
|
this.rpcUrls
|
|
2598
2655
|
);
|
|
2599
|
-
this.walletClient = (0,
|
|
2656
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2600
2657
|
account: newAddress,
|
|
2601
2658
|
chain: chainConfig.chain,
|
|
2602
|
-
transport: (0,
|
|
2659
|
+
transport: (0, import_viem5.custom)(this.currentProvider)
|
|
2603
2660
|
});
|
|
2604
2661
|
this.currentChainId = this.walletClient.chain?.id || null;
|
|
2605
2662
|
try {
|
|
@@ -2664,10 +2721,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2664
2721
|
}
|
|
2665
2722
|
this.signer = (0, import_accounts2.privateKeyToAccount)(privateKey);
|
|
2666
2723
|
this.currentChainId = chainId;
|
|
2667
|
-
this.walletClient = (0,
|
|
2724
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2668
2725
|
account: this.signer,
|
|
2669
2726
|
chain: chainConfig.chain,
|
|
2670
|
-
transport: (0,
|
|
2727
|
+
transport: (0, import_viem5.http)(chainConfig.rpcUrl)
|
|
2671
2728
|
});
|
|
2672
2729
|
connectedAddress = this.signer.address;
|
|
2673
2730
|
this.currentProvider = null;
|
|
@@ -2685,10 +2742,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2685
2742
|
if (!accounts || accounts.length === 0) {
|
|
2686
2743
|
throw new Error("No accounts found in wallet provider");
|
|
2687
2744
|
}
|
|
2688
|
-
this.walletClient = (0,
|
|
2745
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2689
2746
|
account: accounts[0],
|
|
2690
2747
|
chain: chainConfig.chain,
|
|
2691
|
-
transport: (0,
|
|
2748
|
+
transport: (0, import_viem5.custom)(provider)
|
|
2692
2749
|
});
|
|
2693
2750
|
connectedAddress = accounts[0];
|
|
2694
2751
|
this.currentProvider = provider;
|
|
@@ -2697,7 +2754,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2697
2754
|
provider.on("accountsChanged", this.handleAccountsChanged.bind(this));
|
|
2698
2755
|
}
|
|
2699
2756
|
} else if (provider.account && provider.transport) {
|
|
2700
|
-
this.walletClient = (0,
|
|
2757
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
2701
2758
|
account: provider.account,
|
|
2702
2759
|
chain: chainConfig.chain,
|
|
2703
2760
|
transport: provider.transport
|
|
@@ -2758,10 +2815,10 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2758
2815
|
targetChainId,
|
|
2759
2816
|
this.rpcUrls
|
|
2760
2817
|
);
|
|
2761
|
-
return (0,
|
|
2818
|
+
return (0, import_viem5.createWalletClient)({
|
|
2762
2819
|
account: this.signer,
|
|
2763
2820
|
chain: targetChainConfig.chain,
|
|
2764
|
-
transport: (0,
|
|
2821
|
+
transport: (0, import_viem5.http)(targetChainConfig.rpcUrl)
|
|
2765
2822
|
});
|
|
2766
2823
|
} else {
|
|
2767
2824
|
if (!this.walletClient) {
|
|
@@ -2877,7 +2934,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
2877
2934
|
*
|
|
2878
2935
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
2879
2936
|
* @param chainId - Target chain ID
|
|
2880
|
-
* @param strategy - Optional strategy selection: "conservative" (default), "
|
|
2937
|
+
* @param strategy - Optional strategy selection: "conservative" (default), "balanced" or "advanced"
|
|
2881
2938
|
* @param createSessionKey - If true, automatically creates a session key after deployment (default: false)
|
|
2882
2939
|
* @returns Deployment response with Safe address and transaction hash
|
|
2883
2940
|
*
|
|
@@ -3325,11 +3382,11 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3325
3382
|
*
|
|
3326
3383
|
* @example
|
|
3327
3384
|
* ```typescript
|
|
3328
|
-
* // NVDAc only lives in async protocols, so it needs "
|
|
3385
|
+
* // NVDAc only lives in async protocols, so it needs "advanced".
|
|
3329
3386
|
* // Chains default to Base, the only chain it exists on.
|
|
3330
3387
|
* const profile = await sdk.setAssetStrategy({
|
|
3331
3388
|
* asset: "NVDAc",
|
|
3332
|
-
* strategy: "
|
|
3389
|
+
* strategy: "advanced",
|
|
3333
3390
|
* });
|
|
3334
3391
|
* console.log(profile.protocols); // Ipor + Superform
|
|
3335
3392
|
* ```
|
|
@@ -3339,7 +3396,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3339
3396
|
try {
|
|
3340
3397
|
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
3341
3398
|
throw new Error(
|
|
3342
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
3399
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "balanced" or "advanced".`
|
|
3343
3400
|
);
|
|
3344
3401
|
}
|
|
3345
3402
|
const supported = getAssetChainIds(asset);
|
|
@@ -3374,7 +3431,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3374
3431
|
* Apply a strategy and auto-select matching protocols for one or all managed
|
|
3375
3432
|
* assets ({@link getManagedAssets}). Prefer this over
|
|
3376
3433
|
* {@link updateUserProfile} when changing strategy so protocols stay aligned
|
|
3377
|
-
* with the tier (including `
|
|
3434
|
+
* with the tier (including `advanced` async venues).
|
|
3378
3435
|
*
|
|
3379
3436
|
* @group Portfolio and execution
|
|
3380
3437
|
*/
|
|
@@ -3382,7 +3439,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3382
3439
|
const { strategy, asset, chains } = params;
|
|
3383
3440
|
if (!isValidPublicStrategy(strategy)) {
|
|
3384
3441
|
throw new Error(
|
|
3385
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
3442
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "balanced" or "advanced".`
|
|
3386
3443
|
);
|
|
3387
3444
|
}
|
|
3388
3445
|
const assets = asset ? [asset] : getManagedAssets();
|
|
@@ -3579,7 +3636,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
3579
3636
|
}
|
|
3580
3637
|
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
3581
3638
|
throw new Error(
|
|
3582
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
3639
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "balanced" or "advanced".`
|
|
3583
3640
|
);
|
|
3584
3641
|
}
|
|
3585
3642
|
const assetSymbol = resolveAssetSymbol(asset);
|
|
@@ -4066,16 +4123,16 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4066
4123
|
method: "wallet_switchEthereumChain",
|
|
4067
4124
|
params: [{ chainId: `0x${originChainId.toString(16)}` }]
|
|
4068
4125
|
});
|
|
4069
|
-
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0,
|
|
4126
|
+
const chain = isSupportedChain(originChainId) ? getChainConfig(originChainId, this.rpcUrls).chain : (0, import_viem5.defineChain)({
|
|
4070
4127
|
id: originChainId,
|
|
4071
4128
|
name: `Chain ${originChainId}`,
|
|
4072
4129
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
4073
4130
|
rpcUrls: { default: { http: ["http://127.0.0.1"] } }
|
|
4074
4131
|
});
|
|
4075
|
-
this.walletClient = (0,
|
|
4132
|
+
this.walletClient = (0, import_viem5.createWalletClient)({
|
|
4076
4133
|
account: this.walletClient.account,
|
|
4077
4134
|
chain,
|
|
4078
|
-
transport: (0,
|
|
4135
|
+
transport: (0, import_viem5.custom)(this.currentProvider)
|
|
4079
4136
|
});
|
|
4080
4137
|
if (isSupportedChain(originChainId)) {
|
|
4081
4138
|
this.currentChainId = originChainId;
|
|
@@ -4251,7 +4308,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4251
4308
|
safeAddress,
|
|
4252
4309
|
tokenAddress,
|
|
4253
4310
|
to: tokenAddress,
|
|
4254
|
-
data: (0,
|
|
4311
|
+
data: (0, import_viem5.encodeFunctionData)({
|
|
4255
4312
|
abi: ERC20_ABI,
|
|
4256
4313
|
functionName: "transfer",
|
|
4257
4314
|
args: [safeAddress, amountBigInt]
|
|
@@ -4259,6 +4316,91 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4259
4316
|
value: "0"
|
|
4260
4317
|
};
|
|
4261
4318
|
}
|
|
4319
|
+
/**
|
|
4320
|
+
* Build the rZFI claim as an unsigned transaction for your own signer.
|
|
4321
|
+
*
|
|
4322
|
+
* @remarks
|
|
4323
|
+
* Same pattern as {@link ZyfaiSDK.buildDepositTransfer}: sign and send
|
|
4324
|
+
* `{ to, data, value }` from `userAddress` on Base (chain 8453). It must be
|
|
4325
|
+
* sent by `userAddress` itself; any other sender reverts. The sender pays the
|
|
4326
|
+
* gas. Claims all unclaimed rZFI into the user's Safe.
|
|
4327
|
+
*
|
|
4328
|
+
* @group Rewards
|
|
4329
|
+
*
|
|
4330
|
+
* @param userAddress - Owner EOA, which must send the transaction
|
|
4331
|
+
* @returns Safe address, claimable amount, and the transaction to send
|
|
4332
|
+
*
|
|
4333
|
+
* @throws If there is no rZFI to claim, the reward tree is updating (retry
|
|
4334
|
+
* later), or `userAddress` cannot execute the Safe alone (not an owner, or threshold above 1)
|
|
4335
|
+
*/
|
|
4336
|
+
async buildRzfiClaimTransaction(userAddress) {
|
|
4337
|
+
if (!userAddress) {
|
|
4338
|
+
throw new Error("A user address is required");
|
|
4339
|
+
}
|
|
4340
|
+
const owner = (0, import_viem5.getAddress)(userAddress);
|
|
4341
|
+
const chainId = 8453;
|
|
4342
|
+
await this.hydrateSessionWallet();
|
|
4343
|
+
const safe = await this.getSafeAddressFor(owner, chainId);
|
|
4344
|
+
if (!safe) {
|
|
4345
|
+
throw new Error("Smart wallet address is not available");
|
|
4346
|
+
}
|
|
4347
|
+
const { publicClient } = getChainConfig(chainId, this.rpcUrls);
|
|
4348
|
+
const [owners, threshold] = await Promise.all([
|
|
4349
|
+
publicClient.readContract({
|
|
4350
|
+
address: safe,
|
|
4351
|
+
abi: SAFE_ABI,
|
|
4352
|
+
functionName: "getOwners"
|
|
4353
|
+
}),
|
|
4354
|
+
publicClient.readContract({
|
|
4355
|
+
address: safe,
|
|
4356
|
+
abi: SAFE_ABI,
|
|
4357
|
+
functionName: "getThreshold"
|
|
4358
|
+
})
|
|
4359
|
+
]).catch(() => {
|
|
4360
|
+
throw new Error(`Safe ${safe} is not deployed on Base`);
|
|
4361
|
+
});
|
|
4362
|
+
if (threshold !== 1n || !owners.some((o) => (0, import_viem5.getAddress)(o) === owner)) {
|
|
4363
|
+
throw new Error(
|
|
4364
|
+
`${owner} cannot execute Safe ${safe} alone (not an owner, or threshold above 1)`
|
|
4365
|
+
);
|
|
4366
|
+
}
|
|
4367
|
+
const [reward, [claimed], liveRoot] = await Promise.all([
|
|
4368
|
+
fetchMerklRzfiReward(safe),
|
|
4369
|
+
publicClient.readContract({
|
|
4370
|
+
address: MERKL_DISTRIBUTOR_ADDRESS,
|
|
4371
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
4372
|
+
functionName: "claimed",
|
|
4373
|
+
args: [safe, RZFI_TOKEN_ADDRESS]
|
|
4374
|
+
}),
|
|
4375
|
+
publicClient.readContract({
|
|
4376
|
+
address: MERKL_DISTRIBUTOR_ADDRESS,
|
|
4377
|
+
abi: MERKL_DISTRIBUTOR_ABI,
|
|
4378
|
+
functionName: "getMerkleRoot"
|
|
4379
|
+
})
|
|
4380
|
+
]);
|
|
4381
|
+
const claimable = reward ? reward.amount - claimed : 0n;
|
|
4382
|
+
if (!reward || claimable <= 0n) {
|
|
4383
|
+
throw new Error("No rZFI available to claim");
|
|
4384
|
+
}
|
|
4385
|
+
if (reward.root.toLowerCase() !== liveRoot.toLowerCase()) {
|
|
4386
|
+
throw new Error(
|
|
4387
|
+
"rZFI rewards are being updated on-chain. Retry in a few minutes."
|
|
4388
|
+
);
|
|
4389
|
+
}
|
|
4390
|
+
return {
|
|
4391
|
+
safeAddress: safe,
|
|
4392
|
+
chainId: 8453,
|
|
4393
|
+
claimableAmount: claimable.toString(),
|
|
4394
|
+
to: safe,
|
|
4395
|
+
data: encodeRzfiClaimExecTransaction({
|
|
4396
|
+
safe,
|
|
4397
|
+
owner,
|
|
4398
|
+
amount: reward.amount,
|
|
4399
|
+
proofs: reward.proofs
|
|
4400
|
+
}),
|
|
4401
|
+
value: "0"
|
|
4402
|
+
};
|
|
4403
|
+
}
|
|
4262
4404
|
/**
|
|
4263
4405
|
* Prepare a gas-sponsored rZFI claim into the user's Safe on Base.
|
|
4264
4406
|
*
|
|
@@ -4306,7 +4448,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4306
4448
|
if (!userAddress) {
|
|
4307
4449
|
throw new Error("A user address is required");
|
|
4308
4450
|
}
|
|
4309
|
-
if (this.sessionEoa && (0,
|
|
4451
|
+
if (this.sessionEoa && (0, import_viem5.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4310
4452
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4311
4453
|
}
|
|
4312
4454
|
}
|
|
@@ -4372,7 +4514,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4372
4514
|
async ensureFirstDepositSetup(strategy) {
|
|
4373
4515
|
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
4374
4516
|
throw new Error(
|
|
4375
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
4517
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "balanced" or "advanced".`
|
|
4376
4518
|
);
|
|
4377
4519
|
}
|
|
4378
4520
|
await this.authenticateUser();
|
|
@@ -4405,7 +4547,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4405
4547
|
const { strategy, asset, chainId } = params;
|
|
4406
4548
|
if (strategy !== void 0 && !isValidPublicStrategy(strategy)) {
|
|
4407
4549
|
throw new Error(
|
|
4408
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
4550
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "balanced" or "advanced".`
|
|
4409
4551
|
);
|
|
4410
4552
|
}
|
|
4411
4553
|
await this.authenticateUser();
|
|
@@ -4452,7 +4594,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4452
4594
|
*/
|
|
4453
4595
|
async prepareDeposit(params) {
|
|
4454
4596
|
const { userAddress, chainId, amount, asset } = params;
|
|
4455
|
-
if (this.sessionEoa && (0,
|
|
4597
|
+
if (this.sessionEoa && (0, import_viem5.getAddress)(userAddress) !== this.sessionEoa) {
|
|
4456
4598
|
throw new Error("userAddress does not match authenticated session EOA");
|
|
4457
4599
|
}
|
|
4458
4600
|
const setup = await this.ensureDepositProfileForPrepare({
|
|
@@ -4788,7 +4930,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
4788
4930
|
* Note: The withdrawal is processed asynchronously, so txHash may not be immediately available
|
|
4789
4931
|
* Funds are always withdrawn to the Safe owner's address (userAddress)
|
|
4790
4932
|
*
|
|
4791
|
-
* **Delayed withdrawals.** Positions held under the `"
|
|
4933
|
+
* **Delayed withdrawals.** Positions held under the `"advanced"`
|
|
4792
4934
|
* strategy sit in protocols that cannot be exited on demand. For those the
|
|
4793
4935
|
* backend transfers the immediately available portion, then queues a
|
|
4794
4936
|
* redemption for the rest and forwards the funds to the EOA once the
|
|
@@ -5035,7 +5177,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5035
5177
|
* a snapshot, so net values can differ slightly from a fully live calc.
|
|
5036
5178
|
*
|
|
5037
5179
|
* **Total balance.** `portfolioByAssetType` sums deployed positions and idle
|
|
5038
|
-
* Safe balances, and nothing else. Under the `"
|
|
5180
|
+
* Safe balances, and nothing else. Under the `"advanced"` strategy a
|
|
5039
5181
|
* redemption in flight has already left its position and has not landed in
|
|
5040
5182
|
* the Safe yet, so its funds appear in no balance field at all. That makes
|
|
5041
5183
|
* two distinct numbers:
|
|
@@ -5060,7 +5202,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5060
5202
|
* @group Portfolio and execution
|
|
5061
5203
|
*
|
|
5062
5204
|
* @remarks Data API portfolio endpoint. See {@link PortfolioDetailed.pendingAsyncWithdrawals}
|
|
5063
|
-
* when using {@link Strategy |
|
|
5205
|
+
* when using {@link Strategy | grow}.
|
|
5064
5206
|
*
|
|
5065
5207
|
* @param userAddress - User's EOA address
|
|
5066
5208
|
* @returns Portfolio with optional fee-adjusted balance fields
|
|
@@ -5258,7 +5400,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5258
5400
|
*
|
|
5259
5401
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
5260
5402
|
* @param days - Time period: 7, 14, or 30
|
|
5261
|
-
* @param strategy - Strategy type: "conservative" (default), "
|
|
5403
|
+
* @param strategy - Strategy type: "conservative" (default), "balanced" or "advanced"
|
|
5262
5404
|
* @param chainId - Optional chain ID filter
|
|
5263
5405
|
* @param tokenSymbol - Optional token symbol filter (e.g. "USDC", "WETH", "WBTC")
|
|
5264
5406
|
* @returns APY per strategy for a specific chain
|
|
@@ -5734,7 +5876,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5734
5876
|
return {
|
|
5735
5877
|
success: true,
|
|
5736
5878
|
chainId,
|
|
5737
|
-
strategyType: "
|
|
5879
|
+
strategyType: "balanced",
|
|
5738
5880
|
data: Array.isArray(data) ? data.map((o) => ({
|
|
5739
5881
|
id: o.id,
|
|
5740
5882
|
protocolId: o.protocol_id || o.protocolId,
|
|
@@ -5745,7 +5887,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5745
5887
|
tvl: o.tvl || o.zyfiTvl,
|
|
5746
5888
|
asset: o.asset || o.underlying_token,
|
|
5747
5889
|
risk: o.risk,
|
|
5748
|
-
strategyType: "
|
|
5890
|
+
strategyType: "balanced",
|
|
5749
5891
|
status: o.status
|
|
5750
5892
|
})) : []
|
|
5751
5893
|
};
|
|
@@ -5756,15 +5898,15 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5756
5898
|
}
|
|
5757
5899
|
}
|
|
5758
5900
|
/**
|
|
5759
|
-
* Get
|
|
5760
|
-
* `"
|
|
5901
|
+
* Get grow opportunities — pools reachable only with the
|
|
5902
|
+
* `"advanced"` strategy, including protocols whose withdrawals are
|
|
5761
5903
|
* asynchronous (Ipor, Superform). Exiting these pools takes about a day
|
|
5762
5904
|
* on Ipor and three on Superform; track the redemption through
|
|
5763
5905
|
* `getPortfolio().portfolio.pendingAsyncWithdrawals`.
|
|
5764
5906
|
*
|
|
5765
5907
|
* @param chainId - Optional chain ID filter
|
|
5766
5908
|
* @param asset - Optional asset filter (e.g. "USDC", "WETH")
|
|
5767
|
-
* @returns List of
|
|
5909
|
+
* @returns List of grow opportunities
|
|
5768
5910
|
*
|
|
5769
5911
|
* @example
|
|
5770
5912
|
* ```typescript
|
|
@@ -5781,7 +5923,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5781
5923
|
return {
|
|
5782
5924
|
success: true,
|
|
5783
5925
|
chainId,
|
|
5784
|
-
strategyType: "
|
|
5926
|
+
strategyType: "advanced",
|
|
5785
5927
|
data: Array.isArray(data) ? data.map((o) => ({
|
|
5786
5928
|
id: o.id,
|
|
5787
5929
|
protocolId: o.protocol_id || o.protocolId,
|
|
@@ -5792,13 +5934,13 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
5792
5934
|
tvl: o.tvl || o.zyfiTvl,
|
|
5793
5935
|
asset: o.asset || o.underlying_token,
|
|
5794
5936
|
risk: o.risk,
|
|
5795
|
-
strategyType: "
|
|
5937
|
+
strategyType: "advanced",
|
|
5796
5938
|
status: o.status
|
|
5797
5939
|
})) : []
|
|
5798
5940
|
};
|
|
5799
5941
|
} catch (error) {
|
|
5800
5942
|
throw new Error(
|
|
5801
|
-
`Failed to get
|
|
5943
|
+
`Failed to get grow opportunities: ${error.message}`
|
|
5802
5944
|
);
|
|
5803
5945
|
}
|
|
5804
5946
|
}
|
|
@@ -6323,7 +6465,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6323
6465
|
if (strategy) {
|
|
6324
6466
|
if (!isValidPublicStrategy(strategy)) {
|
|
6325
6467
|
throw new Error(
|
|
6326
|
-
`Invalid strategy: ${strategy}. Must be "conservative", "
|
|
6468
|
+
`Invalid strategy: ${strategy}. Must be "conservative", "balanced" or "advanced".`
|
|
6327
6469
|
);
|
|
6328
6470
|
}
|
|
6329
6471
|
internalStrategy = toInternalStrategy(strategy);
|
|
@@ -6373,7 +6515,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6373
6515
|
try {
|
|
6374
6516
|
if (!isValidPublicStrategy(params.strategy)) {
|
|
6375
6517
|
throw new Error(
|
|
6376
|
-
`Invalid strategy: ${params.strategy}. Must be "conservative", "
|
|
6518
|
+
`Invalid strategy: ${params.strategy}. Must be "conservative", "balanced" or "advanced".`
|
|
6377
6519
|
);
|
|
6378
6520
|
}
|
|
6379
6521
|
const internalStrategy = toInternalStrategy(params.strategy);
|
|
@@ -6472,7 +6614,7 @@ var _ZyfaiSDK = class _ZyfaiSDK {
|
|
|
6472
6614
|
if (!tokenUriResponse.tokenUri) {
|
|
6473
6615
|
throw new Error("API did not return a tokenUri");
|
|
6474
6616
|
}
|
|
6475
|
-
const callData = (0,
|
|
6617
|
+
const callData = (0, import_viem5.encodeFunctionData)({
|
|
6476
6618
|
abi: IDENTITY_REGISTRY_ABI,
|
|
6477
6619
|
functionName: "register",
|
|
6478
6620
|
args: [tokenUriResponse.tokenUri]
|