@owney/sdk 0.7.28-beta.2 → 0.7.28-beta.3

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.cjs CHANGED
@@ -1116,6 +1116,13 @@ function protocolsPolicyNeedsUpdate(current, desiredProtocols, desiredAutoSelect
1116
1116
  if (desiredProtocols === null) return false;
1117
1117
  return !protocolListsEqual(current.protocols, desiredProtocols);
1118
1118
  }
1119
+ function mergeScopedPoolNames(current, scoped, allAvailableNames) {
1120
+ const managed = new Set(scoped.flatMap((entry) => entry.availablePools));
1121
+ const existing = current.autoselect ? allAvailableNames : current.pools;
1122
+ const preserved = existing.filter((name) => !managed.has(name));
1123
+ const selected = scoped.flatMap((entry) => entry.pools);
1124
+ return [.../* @__PURE__ */ new Set([...preserved, ...selected])];
1125
+ }
1119
1126
  function mapAvailablePools(raw) {
1120
1127
  const byChain = raw ?? {};
1121
1128
  if (typeof byChain !== "object" || byChain === null) return [];
@@ -1712,14 +1719,73 @@ var ZyfaiAgent = class _ZyfaiAgent {
1712
1719
  return assemblePoolCatalog(universe, poolsByProtocol, params.asset);
1713
1720
  }
1714
1721
  /**
1715
- * Apply a user's own pool selection (the deposit-time Pools step) to their
1716
- * Zyfai profile. Same two writes as the org path — this is `applyPoolPolicy`
1717
- * driven by the user's `policy` instead of the organization's, with the
1718
- * deposit's chosen `strategy` passed through so pool names validate against
1719
- * the strategy the user just picked rather than their stored one.
1722
+ * Persist an explicitly saved deposit-time draft at Zyfai profile level.
1723
+ * Pool choices are merged into protocol/chain records and each active asset
1724
+ * is kept at aggressive unless the draft includes a yieldmaxxing-only pool.
1720
1725
  */
1721
- async setPoolSelection(policy, opts = {}) {
1722
- await this.applyPoolPolicy(policy, opts);
1726
+ async setPoolSelection(selection) {
1727
+ try {
1728
+ const byPair = /* @__PURE__ */ new Map();
1729
+ for (const entry of selection.selections) {
1730
+ const pair = `${entry.protocolId}:${entry.chainId}`;
1731
+ const group = byPair.get(pair) ?? [];
1732
+ group.push(entry);
1733
+ byPair.set(pair, group);
1734
+ }
1735
+ const customizations = (await Promise.all(
1736
+ [...byPair.values()].map(async (scoped) => {
1737
+ const { protocolId, chainId } = scoped[0];
1738
+ try {
1739
+ const [current, rawAvailable] = await Promise.all([
1740
+ this.sdk.getSelectedPools(protocolId, chainId),
1741
+ this.sdk.getAvailablePools(protocolId, "yieldmaxxing")
1742
+ ]);
1743
+ const allAvailableNames = mapAvailablePools(rawAvailable).filter((pool) => pool.chainId === chainId).map((pool) => pool.name);
1744
+ return {
1745
+ protocolId,
1746
+ chainId,
1747
+ pools: mergeScopedPoolNames(
1748
+ {
1749
+ pools: current.pools ?? [],
1750
+ autoselect: current.autoselect
1751
+ },
1752
+ scoped,
1753
+ allAvailableNames
1754
+ ),
1755
+ // An explicit Save freezes exactly the choices the user saw.
1756
+ // This also lets an empty list disable the pair deliberately.
1757
+ autoselect: false
1758
+ };
1759
+ } catch (error) {
1760
+ console.warn(
1761
+ `[zyfai] setPoolSelection: preserving ${protocolId}/${chainId} failed; skipping the pair:`,
1762
+ error instanceof Error ? error.message : String(error)
1763
+ );
1764
+ return null;
1765
+ }
1766
+ })
1767
+ )).filter((value) => value !== null);
1768
+ if (customizations.length > 0) {
1769
+ await this.sdk.customizeBatch(customizations);
1770
+ }
1771
+ await Promise.all(
1772
+ selection.strategies.map(async ({ asset, strategy }) => {
1773
+ const current = await this.sdk.getUserDetails(asset);
1774
+ const selectedProtocols = selection.selections.filter(
1775
+ (entry) => entry.asset === asset && entry.pools.length > 0
1776
+ ).map((entry) => entry.protocolId);
1777
+ const protocols = [
1778
+ .../* @__PURE__ */ new Set([...current.protocols ?? [], ...selectedProtocols])
1779
+ ];
1780
+ await this.sdk.updateUserProfile({ asset, strategy, protocols });
1781
+ })
1782
+ );
1783
+ } catch (error) {
1784
+ console.warn(
1785
+ "[zyfai] setPoolSelection failed (non-fatal):",
1786
+ error instanceof Error ? error.message : String(error)
1787
+ );
1788
+ }
1723
1789
  }
1724
1790
  /**
1725
1791
  * True when `smartWallet` is the backend-managed pool wallet Zyfai assigned
@@ -6461,7 +6527,10 @@ var OwneySDK = class {
6461
6527
  agent,
6462
6528
  "dailyEarnings",
6463
6529
  () => agent.getDailyEarnings(state, legChainId, days, tokenSymbol),
6464
- { days, tokenSymbol }
6530
+ // The leg's chain must be in the key: the read key otherwise names
6531
+ // only the CONNECTION chain, so every leg shared the first leg's
6532
+ // request and the sum counted that chain once per leg. (ROUT-561)
6533
+ { days, tokenSymbol, chainId: legChainId }
6465
6534
  )
6466
6535
  )
6467
6536
  );
@@ -6525,8 +6594,8 @@ var OwneySDK = class {
6525
6594
  }
6526
6595
  /**
6527
6596
  * Apply a user's deposit-time pool selection to their account (ROUT-569).
6528
- * `strategy` is the one chosen in the deposit flow, passed through so pool
6529
- * names validate against it rather than the user's stored strategy.
6597
+ * The request carries explicit pool choices plus the resulting strategy for
6598
+ * each asset reviewed in the deposit flow.
6530
6599
  */
6531
6600
  async setPoolSelection(params) {
6532
6601
  await this.ensureAgentsInitialized();
@@ -6537,7 +6606,7 @@ var OwneySDK = class {
6537
6606
  `Agent ${agent.id} does not support pool customization`
6538
6607
  );
6539
6608
  }
6540
- await agent.setPoolSelection(params.policy, { strategy: params.strategy });
6609
+ await agent.setPoolSelection(params.selection);
6541
6610
  }
6542
6611
  async getAccountApy({
6543
6612
  agentId,
@@ -6661,7 +6730,8 @@ var OwneySDK = class {
6661
6730
  agent,
6662
6731
  "history",
6663
6732
  () => agent.getHistory(state, leg.chainId, legFilters),
6664
- legFilters
6733
+ // Keyed per leg for the same reason as getDailyEarnings' fan-out.
6734
+ { ...legFilters, chainId: leg.chainId }
6665
6735
  );
6666
6736
  return { leg, page };
6667
6737
  })
package/dist/index.d.cts CHANGED
@@ -543,6 +543,26 @@ type AvailablePool = {
543
543
  /** Per-pool deep link (e.g. the Morpho vault page). null when absent. */
544
544
  link: string | null;
545
545
  };
546
+ /** Public Zyfai strategies used by deposit-time pool customization. */
547
+ type PoolSelectionStrategy = "aggressive" | "yieldmaxxing";
548
+ /** One asset's explicit choice for a protocol on one chain. */
549
+ type UserPoolSelection = {
550
+ asset: "USDC" | "WETH";
551
+ protocolId: string;
552
+ chainId: number;
553
+ /** Names enabled by the user for this asset/protocol/chain. */
554
+ pools: string[];
555
+ /** Every name shown for this asset/protocol/chain in the superset catalog. */
556
+ availablePools: string[];
557
+ };
558
+ /** The complete saved draft for the asset/chain legs selected in the deposit. */
559
+ type UserPoolSelectionRequest = {
560
+ strategies: Array<{
561
+ asset: "USDC" | "WETH";
562
+ strategy: PoolSelectionStrategy;
563
+ }>;
564
+ selections: UserPoolSelection[];
565
+ };
546
566
  /** One protocol with its pools for the deposit asset — what the Pools step
547
567
  * renders: a protocol row that opens to a list of selectable pools. */
548
568
  type PoolCatalogProtocol = {
@@ -886,16 +906,14 @@ interface IAgent {
886
906
  */
887
907
  getPoolCatalog?(params: {
888
908
  asset: string;
889
- strategy: "conservative" | "aggressive";
909
+ strategy: "conservative" | "aggressive" | "yieldmaxxing";
890
910
  }): Promise<PoolCatalogProtocol[]>;
891
911
  /**
892
912
  * Apply a user's own pool selection to their account, driven by the
893
913
  * deposit-time Pools step. Optional, and non-fatal like `applyOrgPolicy`.
894
914
  * (ROUT-569)
895
915
  */
896
- setPoolSelection?(policy: OrgPoolPolicy, opts?: {
897
- strategy?: "conservative" | "aggressive";
898
- }): Promise<void>;
916
+ setPoolSelection?(selection: UserPoolSelectionRequest): Promise<void>;
899
917
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
900
918
  withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
901
919
  getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
@@ -1728,17 +1746,16 @@ declare class OwneySDK {
1728
1746
  */
1729
1747
  getPoolCatalog(params: {
1730
1748
  asset: OwneySupportedTokens;
1731
- strategy: "conservative" | "aggressive";
1749
+ strategy: "conservative" | "aggressive" | "yieldmaxxing";
1732
1750
  agentId?: AgentId;
1733
1751
  }): Promise<PoolCatalogProtocol[]>;
1734
1752
  /**
1735
1753
  * Apply a user's deposit-time pool selection to their account (ROUT-569).
1736
- * `strategy` is the one chosen in the deposit flow, passed through so pool
1737
- * names validate against it rather than the user's stored strategy.
1754
+ * The request carries explicit pool choices plus the resulting strategy for
1755
+ * each asset reviewed in the deposit flow.
1738
1756
  */
1739
1757
  setPoolSelection(params: {
1740
- policy: OrgPoolPolicy;
1741
- strategy?: "conservative" | "aggressive";
1758
+ selection: UserPoolSelectionRequest;
1742
1759
  agentId?: AgentId;
1743
1760
  }): Promise<void>;
1744
1761
  getAccountApy({ agentId, days, tokenSymbol, chainId: scope, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
@@ -1883,4 +1900,4 @@ type StoredOrder = {
1883
1900
  */
1884
1901
  declare function listOrders(now?: number): StoredOrder[];
1885
1902
 
1886
- export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type RebalanceLog, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, updateWithdrawSwap };
1903
+ export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type PoolSelectionStrategy, type RebalanceLog, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type UserPoolSelection, type UserPoolSelectionRequest, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, updateWithdrawSwap };
package/dist/index.d.ts CHANGED
@@ -543,6 +543,26 @@ type AvailablePool = {
543
543
  /** Per-pool deep link (e.g. the Morpho vault page). null when absent. */
544
544
  link: string | null;
545
545
  };
546
+ /** Public Zyfai strategies used by deposit-time pool customization. */
547
+ type PoolSelectionStrategy = "aggressive" | "yieldmaxxing";
548
+ /** One asset's explicit choice for a protocol on one chain. */
549
+ type UserPoolSelection = {
550
+ asset: "USDC" | "WETH";
551
+ protocolId: string;
552
+ chainId: number;
553
+ /** Names enabled by the user for this asset/protocol/chain. */
554
+ pools: string[];
555
+ /** Every name shown for this asset/protocol/chain in the superset catalog. */
556
+ availablePools: string[];
557
+ };
558
+ /** The complete saved draft for the asset/chain legs selected in the deposit. */
559
+ type UserPoolSelectionRequest = {
560
+ strategies: Array<{
561
+ asset: "USDC" | "WETH";
562
+ strategy: PoolSelectionStrategy;
563
+ }>;
564
+ selections: UserPoolSelection[];
565
+ };
546
566
  /** One protocol with its pools for the deposit asset — what the Pools step
547
567
  * renders: a protocol row that opens to a list of selectable pools. */
548
568
  type PoolCatalogProtocol = {
@@ -886,16 +906,14 @@ interface IAgent {
886
906
  */
887
907
  getPoolCatalog?(params: {
888
908
  asset: string;
889
- strategy: "conservative" | "aggressive";
909
+ strategy: "conservative" | "aggressive" | "yieldmaxxing";
890
910
  }): Promise<PoolCatalogProtocol[]>;
891
911
  /**
892
912
  * Apply a user's own pool selection to their account, driven by the
893
913
  * deposit-time Pools step. Optional, and non-fatal like `applyOrgPolicy`.
894
914
  * (ROUT-569)
895
915
  */
896
- setPoolSelection?(policy: OrgPoolPolicy, opts?: {
897
- strategy?: "conservative" | "aggressive";
898
- }): Promise<void>;
916
+ setPoolSelection?(selection: UserPoolSelectionRequest): Promise<void>;
899
917
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
900
918
  withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
901
919
  getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
@@ -1728,17 +1746,16 @@ declare class OwneySDK {
1728
1746
  */
1729
1747
  getPoolCatalog(params: {
1730
1748
  asset: OwneySupportedTokens;
1731
- strategy: "conservative" | "aggressive";
1749
+ strategy: "conservative" | "aggressive" | "yieldmaxxing";
1732
1750
  agentId?: AgentId;
1733
1751
  }): Promise<PoolCatalogProtocol[]>;
1734
1752
  /**
1735
1753
  * Apply a user's deposit-time pool selection to their account (ROUT-569).
1736
- * `strategy` is the one chosen in the deposit flow, passed through so pool
1737
- * names validate against it rather than the user's stored strategy.
1754
+ * The request carries explicit pool choices plus the resulting strategy for
1755
+ * each asset reviewed in the deposit flow.
1738
1756
  */
1739
1757
  setPoolSelection(params: {
1740
- policy: OrgPoolPolicy;
1741
- strategy?: "conservative" | "aggressive";
1758
+ selection: UserPoolSelectionRequest;
1742
1759
  agentId?: AgentId;
1743
1760
  }): Promise<void>;
1744
1761
  getAccountApy({ agentId, days, tokenSymbol, chainId: scope, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
@@ -1883,4 +1900,4 @@ type StoredOrder = {
1883
1900
  */
1884
1901
  declare function listOrders(now?: number): StoredOrder[];
1885
1902
 
1886
- export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type RebalanceLog, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, updateWithdrawSwap };
1903
+ export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type PoolSelectionStrategy, type RebalanceLog, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type UserPoolSelection, type UserPoolSelectionRequest, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, updateWithdrawSwap };
package/dist/index.js CHANGED
@@ -1076,6 +1076,13 @@ function protocolsPolicyNeedsUpdate(current, desiredProtocols, desiredAutoSelect
1076
1076
  if (desiredProtocols === null) return false;
1077
1077
  return !protocolListsEqual(current.protocols, desiredProtocols);
1078
1078
  }
1079
+ function mergeScopedPoolNames(current, scoped, allAvailableNames) {
1080
+ const managed = new Set(scoped.flatMap((entry) => entry.availablePools));
1081
+ const existing = current.autoselect ? allAvailableNames : current.pools;
1082
+ const preserved = existing.filter((name) => !managed.has(name));
1083
+ const selected = scoped.flatMap((entry) => entry.pools);
1084
+ return [.../* @__PURE__ */ new Set([...preserved, ...selected])];
1085
+ }
1079
1086
  function mapAvailablePools(raw) {
1080
1087
  const byChain = raw ?? {};
1081
1088
  if (typeof byChain !== "object" || byChain === null) return [];
@@ -1672,14 +1679,73 @@ var ZyfaiAgent = class _ZyfaiAgent {
1672
1679
  return assemblePoolCatalog(universe, poolsByProtocol, params.asset);
1673
1680
  }
1674
1681
  /**
1675
- * Apply a user's own pool selection (the deposit-time Pools step) to their
1676
- * Zyfai profile. Same two writes as the org path — this is `applyPoolPolicy`
1677
- * driven by the user's `policy` instead of the organization's, with the
1678
- * deposit's chosen `strategy` passed through so pool names validate against
1679
- * the strategy the user just picked rather than their stored one.
1682
+ * Persist an explicitly saved deposit-time draft at Zyfai profile level.
1683
+ * Pool choices are merged into protocol/chain records and each active asset
1684
+ * is kept at aggressive unless the draft includes a yieldmaxxing-only pool.
1680
1685
  */
1681
- async setPoolSelection(policy, opts = {}) {
1682
- await this.applyPoolPolicy(policy, opts);
1686
+ async setPoolSelection(selection) {
1687
+ try {
1688
+ const byPair = /* @__PURE__ */ new Map();
1689
+ for (const entry of selection.selections) {
1690
+ const pair = `${entry.protocolId}:${entry.chainId}`;
1691
+ const group = byPair.get(pair) ?? [];
1692
+ group.push(entry);
1693
+ byPair.set(pair, group);
1694
+ }
1695
+ const customizations = (await Promise.all(
1696
+ [...byPair.values()].map(async (scoped) => {
1697
+ const { protocolId, chainId } = scoped[0];
1698
+ try {
1699
+ const [current, rawAvailable] = await Promise.all([
1700
+ this.sdk.getSelectedPools(protocolId, chainId),
1701
+ this.sdk.getAvailablePools(protocolId, "yieldmaxxing")
1702
+ ]);
1703
+ const allAvailableNames = mapAvailablePools(rawAvailable).filter((pool) => pool.chainId === chainId).map((pool) => pool.name);
1704
+ return {
1705
+ protocolId,
1706
+ chainId,
1707
+ pools: mergeScopedPoolNames(
1708
+ {
1709
+ pools: current.pools ?? [],
1710
+ autoselect: current.autoselect
1711
+ },
1712
+ scoped,
1713
+ allAvailableNames
1714
+ ),
1715
+ // An explicit Save freezes exactly the choices the user saw.
1716
+ // This also lets an empty list disable the pair deliberately.
1717
+ autoselect: false
1718
+ };
1719
+ } catch (error) {
1720
+ console.warn(
1721
+ `[zyfai] setPoolSelection: preserving ${protocolId}/${chainId} failed; skipping the pair:`,
1722
+ error instanceof Error ? error.message : String(error)
1723
+ );
1724
+ return null;
1725
+ }
1726
+ })
1727
+ )).filter((value) => value !== null);
1728
+ if (customizations.length > 0) {
1729
+ await this.sdk.customizeBatch(customizations);
1730
+ }
1731
+ await Promise.all(
1732
+ selection.strategies.map(async ({ asset, strategy }) => {
1733
+ const current = await this.sdk.getUserDetails(asset);
1734
+ const selectedProtocols = selection.selections.filter(
1735
+ (entry) => entry.asset === asset && entry.pools.length > 0
1736
+ ).map((entry) => entry.protocolId);
1737
+ const protocols = [
1738
+ .../* @__PURE__ */ new Set([...current.protocols ?? [], ...selectedProtocols])
1739
+ ];
1740
+ await this.sdk.updateUserProfile({ asset, strategy, protocols });
1741
+ })
1742
+ );
1743
+ } catch (error) {
1744
+ console.warn(
1745
+ "[zyfai] setPoolSelection failed (non-fatal):",
1746
+ error instanceof Error ? error.message : String(error)
1747
+ );
1748
+ }
1683
1749
  }
1684
1750
  /**
1685
1751
  * True when `smartWallet` is the backend-managed pool wallet Zyfai assigned
@@ -6442,7 +6508,10 @@ var OwneySDK = class {
6442
6508
  agent,
6443
6509
  "dailyEarnings",
6444
6510
  () => agent.getDailyEarnings(state, legChainId, days, tokenSymbol),
6445
- { days, tokenSymbol }
6511
+ // The leg's chain must be in the key: the read key otherwise names
6512
+ // only the CONNECTION chain, so every leg shared the first leg's
6513
+ // request and the sum counted that chain once per leg. (ROUT-561)
6514
+ { days, tokenSymbol, chainId: legChainId }
6446
6515
  )
6447
6516
  )
6448
6517
  );
@@ -6506,8 +6575,8 @@ var OwneySDK = class {
6506
6575
  }
6507
6576
  /**
6508
6577
  * Apply a user's deposit-time pool selection to their account (ROUT-569).
6509
- * `strategy` is the one chosen in the deposit flow, passed through so pool
6510
- * names validate against it rather than the user's stored strategy.
6578
+ * The request carries explicit pool choices plus the resulting strategy for
6579
+ * each asset reviewed in the deposit flow.
6511
6580
  */
6512
6581
  async setPoolSelection(params) {
6513
6582
  await this.ensureAgentsInitialized();
@@ -6518,7 +6587,7 @@ var OwneySDK = class {
6518
6587
  `Agent ${agent.id} does not support pool customization`
6519
6588
  );
6520
6589
  }
6521
- await agent.setPoolSelection(params.policy, { strategy: params.strategy });
6590
+ await agent.setPoolSelection(params.selection);
6522
6591
  }
6523
6592
  async getAccountApy({
6524
6593
  agentId,
@@ -6642,7 +6711,8 @@ var OwneySDK = class {
6642
6711
  agent,
6643
6712
  "history",
6644
6713
  () => agent.getHistory(state, leg.chainId, legFilters),
6645
- legFilters
6714
+ // Keyed per leg for the same reason as getDailyEarnings' fan-out.
6715
+ { ...legFilters, chainId: leg.chainId }
6646
6716
  );
6647
6717
  return { leg, page };
6648
6718
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.28-beta.2",
3
+ "version": "0.7.28-beta.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "test:watch": "vitest"
24
24
  },
25
25
  "dependencies": {
26
- "@zyfai/sdk": "0.2.55",
26
+ "@zyfai/sdk": "0.2.57",
27
27
  "siwe": "^3.0.0",
28
28
  "viem": "^2.48.1"
29
29
  },