@owney/sdk 0.7.28-beta.5 → 0.7.28-beta.6

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
@@ -523,23 +523,33 @@ function rawPoolApyForChain(entry, chainId, tokenSymbol) {
523
523
  function historyCoverage(raw) {
524
524
  const chains = /* @__PURE__ */ new Map();
525
525
  const assets = /* @__PURE__ */ new Map();
526
+ const pairs = /* @__PURE__ */ new Map();
526
527
  for (const date of Object.keys(raw.history ?? {}).sort()) {
527
528
  void date;
528
529
  const seenChains = /* @__PURE__ */ new Set();
529
530
  const seenAssets = /* @__PURE__ */ new Set();
531
+ const seenPairs = /* @__PURE__ */ new Map();
530
532
  for (const p of (raw.history ?? {})[date].positions ?? []) {
531
533
  const balance = p.balance ?? 0;
532
534
  const apy = netApy(p.apy_withFee, p.apy, "apy_withFee");
533
535
  if (balance <= 0 || typeof apy !== "number") continue;
534
536
  seenChains.add(p.chainId);
535
- if (p.tokenSymbol) seenAssets.add(p.tokenSymbol.toUpperCase());
537
+ if (p.tokenSymbol) {
538
+ const asset = p.tokenSymbol.toUpperCase();
539
+ seenAssets.add(asset);
540
+ seenPairs.set(`${p.chainId}:${asset}`, { chainId: p.chainId, asset });
541
+ }
536
542
  }
537
543
  for (const c of seenChains) chains.set(c, (chains.get(c) ?? 0) + 1);
538
544
  for (const a of seenAssets) assets.set(a, (assets.get(a) ?? 0) + 1);
545
+ for (const [key2, pair] of seenPairs) {
546
+ pairs.set(key2, { ...pair, days: (pairs.get(key2)?.days ?? 0) + 1 });
547
+ }
539
548
  }
540
549
  return {
541
550
  chains: [...chains].map(([chainId, days]) => ({ chainId, days })),
542
- assets: [...assets].map(([asset, days]) => ({ asset, days }))
551
+ assets: [...assets].map(([asset, days]) => ({ asset, days })),
552
+ pairs: [...pairs.values()]
543
553
  };
544
554
  }
545
555
  function mapApyHistory(raw, chainId, tokenSymbol) {
@@ -584,6 +594,9 @@ function mapEntries(rawEntries, chainId) {
584
594
  // "Top up wallet" and for slightly less (gas). `Deposit` already exists in
585
595
  // the public HistoryAction union, so no consumer type change is needed.
586
596
  "Deposit to protocol": "Deposit",
597
+ // Withdrawing from an async vault (Superform) is logged under its own
598
+ // label and paid out later in a separate batch (ROUT-624).
599
+ "Request async withdrawal": "Withdraw",
587
600
  Rebalance: "Rebalance"
588
601
  };
589
602
  void chainId;
@@ -626,8 +639,9 @@ function mapEntries(rawEntries, chainId) {
626
639
  ];
627
640
  }
628
641
  const mappedAction = (entry.action ? actionMap[entry.action] : void 0) ?? entry.action;
642
+ const asyncRequest = entry.action === "Request async withdrawal";
629
643
  const rawAmount = entry?.positions?.[0]?.amount;
630
- const hasAmount = mappedAction !== "Withdraw" && typeof rawAmount === "string" && rawAmount !== "" && rawAmount !== "0x" && rawAmount !== "0x0" && rawAmount !== "0";
644
+ const hasAmount = (mappedAction !== "Withdraw" || asyncRequest) && typeof rawAmount === "string" && rawAmount !== "" && rawAmount !== "0x" && rawAmount !== "0x0" && rawAmount !== "0";
631
645
  const mappedPositions = positions.filter((p) => p.protocol_name).map((p) => ({
632
646
  protocol: p.protocol_name,
633
647
  pool: p.pool ?? void 0,
@@ -641,6 +655,7 @@ function mapEntries(rawEntries, chainId) {
641
655
  newApy: newApy === null ? null : String(newApy),
642
656
  oldApy: oldApy === null ? null : String(oldApy),
643
657
  ...mappedPositions.length ? { positions: mappedPositions } : {},
658
+ ...asyncRequest ? { asyncRequest: true } : {},
644
659
  transactions: [
645
660
  {
646
661
  txHashes: entry.transactionHash ? [entry.transactionHash] : [],
@@ -1281,7 +1296,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1281
1296
  */
1282
1297
  async resolveWithdrawnAmounts(entries, chainId, recipient) {
1283
1298
  const withdrawals = entries.filter(
1284
- (e) => e.action === "Withdraw" && e.transactions[0]?.txHashes[0]
1299
+ (e) => e.action === "Withdraw" && !e.asyncRequest && e.transactions[0]?.txHashes[0]
1285
1300
  );
1286
1301
  if (withdrawals.length === 0) return;
1287
1302
  const client = this.getPublicClient(chainId);
@@ -1787,6 +1802,44 @@ var ZyfaiAgent = class _ZyfaiAgent {
1787
1802
  );
1788
1803
  }
1789
1804
  }
1805
+ /**
1806
+ * Read back what `setPoolSelection` wrote (ROUT-650). Zyfai keeps the saved
1807
+ * pools per protocol/chain and the strategy per asset; both are read for the
1808
+ * pairs and assets asked about. A pair still on autoselect, or one whose
1809
+ * lookup fails, is left out so the caller falls back to its default for it.
1810
+ */
1811
+ async getPoolSelection(params) {
1812
+ const [pairs, strategies] = await Promise.all([
1813
+ Promise.all(
1814
+ params.pairs.map(async ({ protocolId, chainId }) => {
1815
+ try {
1816
+ const current = await this.sdk.getSelectedPools(
1817
+ protocolId,
1818
+ chainId
1819
+ );
1820
+ if (current.autoselect) return null;
1821
+ return { protocolId, chainId, pools: current.pools ?? [] };
1822
+ } catch {
1823
+ return null;
1824
+ }
1825
+ })
1826
+ ),
1827
+ Promise.all(
1828
+ params.assets.map(async (asset) => {
1829
+ try {
1830
+ const current = await this.sdk.getUserDetails(asset);
1831
+ return current.strategy ? { asset, strategy: current.strategy } : null;
1832
+ } catch {
1833
+ return null;
1834
+ }
1835
+ })
1836
+ )
1837
+ ]);
1838
+ return {
1839
+ pairs: pairs.filter((value) => value !== null),
1840
+ strategies: strategies.filter((value) => value !== null)
1841
+ };
1842
+ }
1790
1843
  /**
1791
1844
  * True when `smartWallet` is the backend-managed pool wallet Zyfai assigned
1792
1845
  * to this EOA — the "new wallet" kind that is predeployed on the chains it
@@ -5512,6 +5565,19 @@ var OwneySDK = class {
5512
5565
  chain: dstChain,
5513
5566
  transport: swapReadTransport(quote.dst.chainId, this.zyfaiRpcUrls)
5514
5567
  });
5568
+ const walletPublic = (0, import_viem9.createPublicClient)({
5569
+ chain: srcChain,
5570
+ transport: (0, import_viem9.custom)(provider)
5571
+ });
5572
+ const signOnSource = (payload) => signWithChainRetry(
5573
+ walletPublic,
5574
+ wallet,
5575
+ quote.src.chainId,
5576
+ () => wallet.signTypedData({
5577
+ account: state.walletAddress,
5578
+ ...payload
5579
+ })
5580
+ );
5515
5581
  return {
5516
5582
  api: this.swapApi(),
5517
5583
  // Native-aware, like readSourceBalance below. Native ETH is never a
@@ -5552,10 +5618,7 @@ var OwneySDK = class {
5552
5618
  }
5553
5619
  return hash;
5554
5620
  },
5555
- signTypedData: (typedData) => wallet.signTypedData({
5556
- account: state.walletAddress,
5557
- ...typedData
5558
- }),
5621
+ signTypedData: signOnSource,
5559
5622
  // Chain-bound like every other read here: the wallet provider's chain is
5560
5623
  // not ours to rely on mid-swap.
5561
5624
  readSourceBalance: async () => {
@@ -5612,10 +5675,7 @@ var OwneySDK = class {
5612
5675
  spender,
5613
5676
  value: amount,
5614
5677
  chainId: quote.src.chainId,
5615
- signTypedData: (payload) => wallet.signTypedData({
5616
- account: state.walletAddress,
5617
- ...payload
5618
- })
5678
+ signTypedData: signOnSource
5619
5679
  }
5620
5680
  ),
5621
5681
  /**
@@ -6738,6 +6798,25 @@ var OwneySDK = class {
6738
6798
  }
6739
6799
  await agent.setPoolSelection(params.selection);
6740
6800
  }
6801
+ /**
6802
+ * The pool selection saved on the user's account (ROUT-650), so the Pools
6803
+ * step can show what applies now rather than the defaults. `pairs` and
6804
+ * `assets` say which protocol/chain lists and strategies to read.
6805
+ */
6806
+ async getPoolSelection(params) {
6807
+ await this.ensureAgentsInitialized();
6808
+ const agent = this.getAgent(params.agentId ?? "zyfai");
6809
+ if (!agent.getPoolSelection) {
6810
+ throw new OwneyError(
6811
+ "POOL_SELECTION_UNSUPPORTED",
6812
+ `Agent ${agent.id} does not support pool customization`
6813
+ );
6814
+ }
6815
+ return agent.getPoolSelection({
6816
+ pairs: params.pairs,
6817
+ assets: params.assets
6818
+ });
6819
+ }
6741
6820
  async getAccountApy({
6742
6821
  agentId,
6743
6822
  days,
package/dist/index.d.cts CHANGED
@@ -563,6 +563,22 @@ type UserPoolSelectionRequest = {
563
563
  }>;
564
564
  selections: UserPoolSelection[];
565
565
  };
566
+ /**
567
+ * What a user's account currently has saved (ROUT-650): each asset's strategy,
568
+ * plus the pool list of every protocol/chain pair frozen by an earlier Save.
569
+ * Pairs Zyfai still autoselects are left out, so "no entry" means "default".
570
+ */
571
+ type SavedPoolSelection = {
572
+ strategies: Array<{
573
+ asset: "USDC" | "WETH";
574
+ strategy: string;
575
+ }>;
576
+ pairs: Array<{
577
+ protocolId: string;
578
+ chainId: number;
579
+ pools: string[];
580
+ }>;
581
+ };
566
582
  /** One protocol with its pools for the deposit asset — what the Pools step
567
583
  * renders: a protocol row that opens to a list of selectable pools. */
568
584
  type PoolCatalogProtocol = {
@@ -723,6 +739,14 @@ interface ApyCoverage {
723
739
  asset: string;
724
740
  days: number;
725
741
  }[];
742
+ /** Each asset on each chain, for a menu that offers the two together
743
+ * (ROUT-647). The lists above cannot say this: USDC on Base and WETH on
744
+ * Arbitrum put both chains and both assets in them, and no WETH on Base. */
745
+ pairs: {
746
+ chainId: number;
747
+ asset: string;
748
+ days: number;
749
+ }[];
726
750
  }
727
751
  interface AccountAgentApy {
728
752
  walletAddress: string;
@@ -802,6 +826,13 @@ interface AgentHistoryEntry {
802
826
  transactions: HistoryTransaction[];
803
827
  rebalanceLog: RebalanceLog[];
804
828
  positions?: AgentHistoryPosition[];
829
+ /**
830
+ * Set on a `Withdraw` that was only requested from an async vault
831
+ * (ROUT-624). The vault pays out in batches later, so the funds have not
832
+ * reached the wallet yet and `transactions[0].amount` is the amount
833
+ * requested.
834
+ */
835
+ asyncRequest?: true;
805
836
  }
806
837
  interface OwneyAgentHistory {
807
838
  data: AgentHistoryEntry[];
@@ -914,6 +945,17 @@ interface IAgent {
914
945
  * (ROUT-569)
915
946
  */
916
947
  setPoolSelection?(selection: UserPoolSelectionRequest): Promise<void>;
948
+ /**
949
+ * Read back what `setPoolSelection` saved, for the pairs and assets given,
950
+ * so the Pools step can open on the user's own choices. Optional. (ROUT-650)
951
+ */
952
+ getPoolSelection?(params: {
953
+ pairs: Array<{
954
+ protocolId: string;
955
+ chainId: number;
956
+ }>;
957
+ assets: Array<"USDC" | "WETH">;
958
+ }): Promise<SavedPoolSelection>;
917
959
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
918
960
  withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
919
961
  getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
@@ -1782,6 +1824,19 @@ declare class OwneySDK {
1782
1824
  selection: UserPoolSelectionRequest;
1783
1825
  agentId?: AgentId;
1784
1826
  }): Promise<void>;
1827
+ /**
1828
+ * The pool selection saved on the user's account (ROUT-650), so the Pools
1829
+ * step can show what applies now rather than the defaults. `pairs` and
1830
+ * `assets` say which protocol/chain lists and strategies to read.
1831
+ */
1832
+ getPoolSelection(params: {
1833
+ pairs: Array<{
1834
+ protocolId: string;
1835
+ chainId: number;
1836
+ }>;
1837
+ assets: Array<"USDC" | "WETH">;
1838
+ agentId?: AgentId;
1839
+ }): Promise<SavedPoolSelection>;
1785
1840
  getAccountApy({ agentId, days, tokenSymbol, chainId: scope, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
1786
1841
  /**
1787
1842
  * Get transaction history for a specific agent, or all agents.
@@ -1924,4 +1979,4 @@ type StoredOrder = {
1924
1979
  */
1925
1980
  declare function listOrders(now?: number): StoredOrder[];
1926
1981
 
1927
- 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 };
1982
+ 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 SavedPoolSelection, 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
@@ -563,6 +563,22 @@ type UserPoolSelectionRequest = {
563
563
  }>;
564
564
  selections: UserPoolSelection[];
565
565
  };
566
+ /**
567
+ * What a user's account currently has saved (ROUT-650): each asset's strategy,
568
+ * plus the pool list of every protocol/chain pair frozen by an earlier Save.
569
+ * Pairs Zyfai still autoselects are left out, so "no entry" means "default".
570
+ */
571
+ type SavedPoolSelection = {
572
+ strategies: Array<{
573
+ asset: "USDC" | "WETH";
574
+ strategy: string;
575
+ }>;
576
+ pairs: Array<{
577
+ protocolId: string;
578
+ chainId: number;
579
+ pools: string[];
580
+ }>;
581
+ };
566
582
  /** One protocol with its pools for the deposit asset — what the Pools step
567
583
  * renders: a protocol row that opens to a list of selectable pools. */
568
584
  type PoolCatalogProtocol = {
@@ -723,6 +739,14 @@ interface ApyCoverage {
723
739
  asset: string;
724
740
  days: number;
725
741
  }[];
742
+ /** Each asset on each chain, for a menu that offers the two together
743
+ * (ROUT-647). The lists above cannot say this: USDC on Base and WETH on
744
+ * Arbitrum put both chains and both assets in them, and no WETH on Base. */
745
+ pairs: {
746
+ chainId: number;
747
+ asset: string;
748
+ days: number;
749
+ }[];
726
750
  }
727
751
  interface AccountAgentApy {
728
752
  walletAddress: string;
@@ -802,6 +826,13 @@ interface AgentHistoryEntry {
802
826
  transactions: HistoryTransaction[];
803
827
  rebalanceLog: RebalanceLog[];
804
828
  positions?: AgentHistoryPosition[];
829
+ /**
830
+ * Set on a `Withdraw` that was only requested from an async vault
831
+ * (ROUT-624). The vault pays out in batches later, so the funds have not
832
+ * reached the wallet yet and `transactions[0].amount` is the amount
833
+ * requested.
834
+ */
835
+ asyncRequest?: true;
805
836
  }
806
837
  interface OwneyAgentHistory {
807
838
  data: AgentHistoryEntry[];
@@ -914,6 +945,17 @@ interface IAgent {
914
945
  * (ROUT-569)
915
946
  */
916
947
  setPoolSelection?(selection: UserPoolSelectionRequest): Promise<void>;
948
+ /**
949
+ * Read back what `setPoolSelection` saved, for the pairs and assets given,
950
+ * so the Pools step can open on the user's own choices. Optional. (ROUT-650)
951
+ */
952
+ getPoolSelection?(params: {
953
+ pairs: Array<{
954
+ protocolId: string;
955
+ chainId: number;
956
+ }>;
957
+ assets: Array<"USDC" | "WETH">;
958
+ }): Promise<SavedPoolSelection>;
917
959
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
918
960
  withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
919
961
  getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
@@ -1782,6 +1824,19 @@ declare class OwneySDK {
1782
1824
  selection: UserPoolSelectionRequest;
1783
1825
  agentId?: AgentId;
1784
1826
  }): Promise<void>;
1827
+ /**
1828
+ * The pool selection saved on the user's account (ROUT-650), so the Pools
1829
+ * step can show what applies now rather than the defaults. `pairs` and
1830
+ * `assets` say which protocol/chain lists and strategies to read.
1831
+ */
1832
+ getPoolSelection(params: {
1833
+ pairs: Array<{
1834
+ protocolId: string;
1835
+ chainId: number;
1836
+ }>;
1837
+ assets: Array<"USDC" | "WETH">;
1838
+ agentId?: AgentId;
1839
+ }): Promise<SavedPoolSelection>;
1785
1840
  getAccountApy({ agentId, days, tokenSymbol, chainId: scope, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
1786
1841
  /**
1787
1842
  * Get transaction history for a specific agent, or all agents.
@@ -1924,4 +1979,4 @@ type StoredOrder = {
1924
1979
  */
1925
1980
  declare function listOrders(now?: number): StoredOrder[];
1926
1981
 
1927
- 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 };
1982
+ 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 SavedPoolSelection, 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
@@ -483,23 +483,33 @@ function rawPoolApyForChain(entry, chainId, tokenSymbol) {
483
483
  function historyCoverage(raw) {
484
484
  const chains = /* @__PURE__ */ new Map();
485
485
  const assets = /* @__PURE__ */ new Map();
486
+ const pairs = /* @__PURE__ */ new Map();
486
487
  for (const date of Object.keys(raw.history ?? {}).sort()) {
487
488
  void date;
488
489
  const seenChains = /* @__PURE__ */ new Set();
489
490
  const seenAssets = /* @__PURE__ */ new Set();
491
+ const seenPairs = /* @__PURE__ */ new Map();
490
492
  for (const p of (raw.history ?? {})[date].positions ?? []) {
491
493
  const balance = p.balance ?? 0;
492
494
  const apy = netApy(p.apy_withFee, p.apy, "apy_withFee");
493
495
  if (balance <= 0 || typeof apy !== "number") continue;
494
496
  seenChains.add(p.chainId);
495
- if (p.tokenSymbol) seenAssets.add(p.tokenSymbol.toUpperCase());
497
+ if (p.tokenSymbol) {
498
+ const asset = p.tokenSymbol.toUpperCase();
499
+ seenAssets.add(asset);
500
+ seenPairs.set(`${p.chainId}:${asset}`, { chainId: p.chainId, asset });
501
+ }
496
502
  }
497
503
  for (const c of seenChains) chains.set(c, (chains.get(c) ?? 0) + 1);
498
504
  for (const a of seenAssets) assets.set(a, (assets.get(a) ?? 0) + 1);
505
+ for (const [key2, pair] of seenPairs) {
506
+ pairs.set(key2, { ...pair, days: (pairs.get(key2)?.days ?? 0) + 1 });
507
+ }
499
508
  }
500
509
  return {
501
510
  chains: [...chains].map(([chainId, days]) => ({ chainId, days })),
502
- assets: [...assets].map(([asset, days]) => ({ asset, days }))
511
+ assets: [...assets].map(([asset, days]) => ({ asset, days })),
512
+ pairs: [...pairs.values()]
503
513
  };
504
514
  }
505
515
  function mapApyHistory(raw, chainId, tokenSymbol) {
@@ -544,6 +554,9 @@ function mapEntries(rawEntries, chainId) {
544
554
  // "Top up wallet" and for slightly less (gas). `Deposit` already exists in
545
555
  // the public HistoryAction union, so no consumer type change is needed.
546
556
  "Deposit to protocol": "Deposit",
557
+ // Withdrawing from an async vault (Superform) is logged under its own
558
+ // label and paid out later in a separate batch (ROUT-624).
559
+ "Request async withdrawal": "Withdraw",
547
560
  Rebalance: "Rebalance"
548
561
  };
549
562
  void chainId;
@@ -586,8 +599,9 @@ function mapEntries(rawEntries, chainId) {
586
599
  ];
587
600
  }
588
601
  const mappedAction = (entry.action ? actionMap[entry.action] : void 0) ?? entry.action;
602
+ const asyncRequest = entry.action === "Request async withdrawal";
589
603
  const rawAmount = entry?.positions?.[0]?.amount;
590
- const hasAmount = mappedAction !== "Withdraw" && typeof rawAmount === "string" && rawAmount !== "" && rawAmount !== "0x" && rawAmount !== "0x0" && rawAmount !== "0";
604
+ const hasAmount = (mappedAction !== "Withdraw" || asyncRequest) && typeof rawAmount === "string" && rawAmount !== "" && rawAmount !== "0x" && rawAmount !== "0x0" && rawAmount !== "0";
591
605
  const mappedPositions = positions.filter((p) => p.protocol_name).map((p) => ({
592
606
  protocol: p.protocol_name,
593
607
  pool: p.pool ?? void 0,
@@ -601,6 +615,7 @@ function mapEntries(rawEntries, chainId) {
601
615
  newApy: newApy === null ? null : String(newApy),
602
616
  oldApy: oldApy === null ? null : String(oldApy),
603
617
  ...mappedPositions.length ? { positions: mappedPositions } : {},
618
+ ...asyncRequest ? { asyncRequest: true } : {},
604
619
  transactions: [
605
620
  {
606
621
  txHashes: entry.transactionHash ? [entry.transactionHash] : [],
@@ -1241,7 +1256,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
1241
1256
  */
1242
1257
  async resolveWithdrawnAmounts(entries, chainId, recipient) {
1243
1258
  const withdrawals = entries.filter(
1244
- (e) => e.action === "Withdraw" && e.transactions[0]?.txHashes[0]
1259
+ (e) => e.action === "Withdraw" && !e.asyncRequest && e.transactions[0]?.txHashes[0]
1245
1260
  );
1246
1261
  if (withdrawals.length === 0) return;
1247
1262
  const client = this.getPublicClient(chainId);
@@ -1747,6 +1762,44 @@ var ZyfaiAgent = class _ZyfaiAgent {
1747
1762
  );
1748
1763
  }
1749
1764
  }
1765
+ /**
1766
+ * Read back what `setPoolSelection` wrote (ROUT-650). Zyfai keeps the saved
1767
+ * pools per protocol/chain and the strategy per asset; both are read for the
1768
+ * pairs and assets asked about. A pair still on autoselect, or one whose
1769
+ * lookup fails, is left out so the caller falls back to its default for it.
1770
+ */
1771
+ async getPoolSelection(params) {
1772
+ const [pairs, strategies] = await Promise.all([
1773
+ Promise.all(
1774
+ params.pairs.map(async ({ protocolId, chainId }) => {
1775
+ try {
1776
+ const current = await this.sdk.getSelectedPools(
1777
+ protocolId,
1778
+ chainId
1779
+ );
1780
+ if (current.autoselect) return null;
1781
+ return { protocolId, chainId, pools: current.pools ?? [] };
1782
+ } catch {
1783
+ return null;
1784
+ }
1785
+ })
1786
+ ),
1787
+ Promise.all(
1788
+ params.assets.map(async (asset) => {
1789
+ try {
1790
+ const current = await this.sdk.getUserDetails(asset);
1791
+ return current.strategy ? { asset, strategy: current.strategy } : null;
1792
+ } catch {
1793
+ return null;
1794
+ }
1795
+ })
1796
+ )
1797
+ ]);
1798
+ return {
1799
+ pairs: pairs.filter((value) => value !== null),
1800
+ strategies: strategies.filter((value) => value !== null)
1801
+ };
1802
+ }
1750
1803
  /**
1751
1804
  * True when `smartWallet` is the backend-managed pool wallet Zyfai assigned
1752
1805
  * to this EOA — the "new wallet" kind that is predeployed on the chains it
@@ -5493,6 +5546,19 @@ var OwneySDK = class {
5493
5546
  chain: dstChain,
5494
5547
  transport: swapReadTransport(quote.dst.chainId, this.zyfaiRpcUrls)
5495
5548
  });
5549
+ const walletPublic = createPublicClient2({
5550
+ chain: srcChain,
5551
+ transport: custom(provider)
5552
+ });
5553
+ const signOnSource = (payload) => signWithChainRetry(
5554
+ walletPublic,
5555
+ wallet,
5556
+ quote.src.chainId,
5557
+ () => wallet.signTypedData({
5558
+ account: state.walletAddress,
5559
+ ...payload
5560
+ })
5561
+ );
5496
5562
  return {
5497
5563
  api: this.swapApi(),
5498
5564
  // Native-aware, like readSourceBalance below. Native ETH is never a
@@ -5533,10 +5599,7 @@ var OwneySDK = class {
5533
5599
  }
5534
5600
  return hash;
5535
5601
  },
5536
- signTypedData: (typedData) => wallet.signTypedData({
5537
- account: state.walletAddress,
5538
- ...typedData
5539
- }),
5602
+ signTypedData: signOnSource,
5540
5603
  // Chain-bound like every other read here: the wallet provider's chain is
5541
5604
  // not ours to rely on mid-swap.
5542
5605
  readSourceBalance: async () => {
@@ -5593,10 +5656,7 @@ var OwneySDK = class {
5593
5656
  spender,
5594
5657
  value: amount,
5595
5658
  chainId: quote.src.chainId,
5596
- signTypedData: (payload) => wallet.signTypedData({
5597
- account: state.walletAddress,
5598
- ...payload
5599
- })
5659
+ signTypedData: signOnSource
5600
5660
  }
5601
5661
  ),
5602
5662
  /**
@@ -6719,6 +6779,25 @@ var OwneySDK = class {
6719
6779
  }
6720
6780
  await agent.setPoolSelection(params.selection);
6721
6781
  }
6782
+ /**
6783
+ * The pool selection saved on the user's account (ROUT-650), so the Pools
6784
+ * step can show what applies now rather than the defaults. `pairs` and
6785
+ * `assets` say which protocol/chain lists and strategies to read.
6786
+ */
6787
+ async getPoolSelection(params) {
6788
+ await this.ensureAgentsInitialized();
6789
+ const agent = this.getAgent(params.agentId ?? "zyfai");
6790
+ if (!agent.getPoolSelection) {
6791
+ throw new OwneyError(
6792
+ "POOL_SELECTION_UNSUPPORTED",
6793
+ `Agent ${agent.id} does not support pool customization`
6794
+ );
6795
+ }
6796
+ return agent.getPoolSelection({
6797
+ pairs: params.pairs,
6798
+ assets: params.assets
6799
+ });
6800
+ }
6722
6801
  async getAccountApy({
6723
6802
  agentId,
6724
6803
  days,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owney/sdk",
3
- "version": "0.7.28-beta.5",
3
+ "version": "0.7.28-beta.6",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",