@owney/sdk 0.7.0 → 0.7.1

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.d.cts CHANGED
@@ -21,6 +21,15 @@ interface OwneySDKConfig {
21
21
  * `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
22
22
  */
23
23
  referralSource?: string;
24
+ /**
25
+ * Turn on the SDK's debug logging (default false). Traces the decisions that
26
+ * are otherwise invisible — notably how the organization's agent policy is
27
+ * compared against each user's Zyfai profile and whether it writes.
28
+ *
29
+ * Also switchable at runtime without a rebuild, which is what you want on an
30
+ * already-deployed app: set `globalThis.__OWNEY_DEBUG__ = true` in devtools.
31
+ */
32
+ debug?: boolean;
24
33
  }
25
34
  interface ConnectionState {
26
35
  provider: any;
@@ -101,6 +110,39 @@ type DepositOptions = {
101
110
  onApproved?: () => void;
102
111
  };
103
112
 
113
+ /**
114
+ * One protocol's pool selection on one chain. `pools` holds Zyfai pool NAMES
115
+ * verbatim — matched case-sensitively by customizeBatch, and an unrecognised
116
+ * name makes Zyfai's rebalance engine skip the whole protocol, so these strings
117
+ * must not be normalised anywhere.
118
+ *
119
+ * An empty array means "no usable pools on this chain".
120
+ */
121
+ type OrgPoolSelection = {
122
+ protocolId: string;
123
+ chainId: number;
124
+ pools: string[];
125
+ };
126
+ /**
127
+ * The partner's protocol/pool policy (ROUT-224). Sparse — only protocols they
128
+ * narrowed appear. Optional so an older routing API, which does not return the
129
+ * field, still parses; undefined and null both mean "change nothing".
130
+ */
131
+ type OrgPoolPolicy = {
132
+ autoApproveProtocols: boolean;
133
+ autoApprovePools: boolean;
134
+ selections: OrgPoolSelection[];
135
+ };
136
+ /**
137
+ * The organization's agent execution policy, or null when the partner has never
138
+ * configured one — in which case the agents leave the user's profile alone.
139
+ */
140
+ type OrgAgentConfig = {
141
+ splittingMode: "none" | "automatic" | "force";
142
+ minSplits: number | null;
143
+ poolPolicy?: OrgPoolPolicy | null;
144
+ };
145
+
104
146
  interface OwneyDepositResult {
105
147
  txHash: string;
106
148
  smartWallet: string;
@@ -253,6 +295,19 @@ interface AgentUserProfile {
253
295
  strategy?: string;
254
296
  hasActiveSessionKey: boolean;
255
297
  protocols: string[];
298
+ /**
299
+ * Capital splitting, as the agent currently has it (ROUT-229). Optional
300
+ * because not every agent has the concept — Sail omits both.
301
+ *
302
+ * `minSplits` is the field that carries the meaning: 1 means "split only when
303
+ * it beats a single pool", 2-4 means "force a split for diversification".
304
+ *
305
+ * Zyfai stores these PER ASSET. This profile read does not pass an asset, so
306
+ * these reflect the USDC bucket; a WETH-only user's real setting is not shown
307
+ * here.
308
+ */
309
+ splitting?: boolean;
310
+ minSplits?: number;
256
311
  }
257
312
  interface OwneyUserProfile {
258
313
  agentUserProfile: Record<AgentId, AgentUserProfile>;
@@ -275,6 +330,19 @@ interface IAgent {
275
330
  readonly supportedAssets: readonly AgentSupportedAssets[];
276
331
  disconnect(): Promise<void>;
277
332
  activateAgent(state: ConnectionState, chainId: number): Promise<void>;
333
+ /**
334
+ * Apply the organization's agent policy to this user's account.
335
+ *
336
+ * Optional: an agent that has no equivalent knob simply omits it, which is why
337
+ * this is not part of `activateAgent`'s signature. Declared on the interface
338
+ * rather than only on ZyfaiAgent so the contract stays agent-neutral — the
339
+ * ticket asks for a design that can also cover Surf, which has no adapter yet.
340
+ *
341
+ * Implementations must be **non-fatal**: this runs during activation as a side
342
+ * effect, so a failure has to leave the user connected and their profile
343
+ * unchanged rather than break the connect.
344
+ */
345
+ applyOrgPolicy?(state: ConnectionState, chainId: number, policy: OrgAgentConfig): Promise<void>;
278
346
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
279
347
  withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
280
348
  getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
@@ -318,6 +386,8 @@ declare class OwneySDK {
318
386
  private disabledAgents;
319
387
  private state;
320
388
  private apiKey;
389
+ private orgAgentConfig;
390
+ private orgAgentConfigPromise;
321
391
  private zyfaiRpcUrls?;
322
392
  private routingApiBaseUrl?;
323
393
  private referralSource?;
@@ -366,6 +436,20 @@ declare class OwneySDK {
366
436
  private getDefaultWethSponsoredCallback;
367
437
  private getAgent;
368
438
  private getActiveAgents;
439
+ /**
440
+ * Read the org's agent policy once and reuse it. fetchOrgAgentConfig never
441
+ * throws — it degrades to null — so this cannot break activation.
442
+ */
443
+ private getOrgAgentConfig;
444
+ /**
445
+ * Apply the org policy to one agent, after it has activated.
446
+ *
447
+ * Sequenced after activation rather than alongside it because applying the
448
+ * policy needs the authenticated session activation establishes. Every failure
449
+ * mode is swallowed: a partner's splitting preference is not worth failing a
450
+ * user's connect over.
451
+ */
452
+ private applyOrgPolicyTo;
369
453
  private ensureAgentsInitialized;
370
454
  private createAgent;
371
455
  /**
@@ -555,6 +639,29 @@ declare class InvalidHistoryCursorError extends Error {
555
639
  constructor(message: string);
556
640
  }
557
641
 
642
+ /**
643
+ * Opt-in debug logging.
644
+ *
645
+ * The SDK is deliberately quiet: before this, `src/` contained no `console.log`
646
+ * at all, only `console.warn`/`console.error` for genuine faults. That is worth
647
+ * preserving — this runs inside every partner's app, on every user's connect, so
648
+ * unconditional chatter would land in end users' consoles forever.
649
+ *
650
+ * Two ways to turn it on:
651
+ *
652
+ * 1. From the app: new OwneySDK({ apiKey, debug: true })
653
+ * 2. From devtools, live: globalThis.__OWNEY_DEBUG__ = true
654
+ *
655
+ * (2) is the useful one when diagnosing something on an already-deployed app:
656
+ * the flag is read on every call, not captured once, so flipping it in the
657
+ * console takes effect on the next action without a rebuild or a republish.
658
+ */
659
+ declare global {
660
+ var __OWNEY_DEBUG__: boolean | undefined;
661
+ }
662
+ /** Enable/disable debug logging programmatically. */
663
+ declare function setOwneyDebug(enabled: boolean): void;
664
+
558
665
  type OwneySIWXConfig = {
559
666
  /** Owney/Zyfai API key — same value passed to `new OwneySDK({ apiKey })`. */
560
667
  apiKey: string;
@@ -568,4 +675,4 @@ type OwneySIWXConfig = {
568
675
  */
569
676
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
570
677
 
571
- export { type AccountAgentApy, type AccountApyOptions, 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 ApyHistoryPoint, type Asset, type ConnectionState, type DailyApyDays, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, NotConnectedError, 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 OwneyWithdrawResult, type RebalanceLog, type WithdrawOptions, createOwneySIWX };
678
+ export { type AccountAgentApy, type AccountApyOptions, 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 ApyHistoryPoint, type Asset, type ConnectionState, type DailyApyDays, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, NotConnectedError, 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 OwneyWithdrawResult, type RebalanceLog, type WithdrawOptions, createOwneySIWX, setOwneyDebug };
package/dist/index.d.ts CHANGED
@@ -21,6 +21,15 @@ interface OwneySDKConfig {
21
21
  * `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
22
22
  */
23
23
  referralSource?: string;
24
+ /**
25
+ * Turn on the SDK's debug logging (default false). Traces the decisions that
26
+ * are otherwise invisible — notably how the organization's agent policy is
27
+ * compared against each user's Zyfai profile and whether it writes.
28
+ *
29
+ * Also switchable at runtime without a rebuild, which is what you want on an
30
+ * already-deployed app: set `globalThis.__OWNEY_DEBUG__ = true` in devtools.
31
+ */
32
+ debug?: boolean;
24
33
  }
25
34
  interface ConnectionState {
26
35
  provider: any;
@@ -101,6 +110,39 @@ type DepositOptions = {
101
110
  onApproved?: () => void;
102
111
  };
103
112
 
113
+ /**
114
+ * One protocol's pool selection on one chain. `pools` holds Zyfai pool NAMES
115
+ * verbatim — matched case-sensitively by customizeBatch, and an unrecognised
116
+ * name makes Zyfai's rebalance engine skip the whole protocol, so these strings
117
+ * must not be normalised anywhere.
118
+ *
119
+ * An empty array means "no usable pools on this chain".
120
+ */
121
+ type OrgPoolSelection = {
122
+ protocolId: string;
123
+ chainId: number;
124
+ pools: string[];
125
+ };
126
+ /**
127
+ * The partner's protocol/pool policy (ROUT-224). Sparse — only protocols they
128
+ * narrowed appear. Optional so an older routing API, which does not return the
129
+ * field, still parses; undefined and null both mean "change nothing".
130
+ */
131
+ type OrgPoolPolicy = {
132
+ autoApproveProtocols: boolean;
133
+ autoApprovePools: boolean;
134
+ selections: OrgPoolSelection[];
135
+ };
136
+ /**
137
+ * The organization's agent execution policy, or null when the partner has never
138
+ * configured one — in which case the agents leave the user's profile alone.
139
+ */
140
+ type OrgAgentConfig = {
141
+ splittingMode: "none" | "automatic" | "force";
142
+ minSplits: number | null;
143
+ poolPolicy?: OrgPoolPolicy | null;
144
+ };
145
+
104
146
  interface OwneyDepositResult {
105
147
  txHash: string;
106
148
  smartWallet: string;
@@ -253,6 +295,19 @@ interface AgentUserProfile {
253
295
  strategy?: string;
254
296
  hasActiveSessionKey: boolean;
255
297
  protocols: string[];
298
+ /**
299
+ * Capital splitting, as the agent currently has it (ROUT-229). Optional
300
+ * because not every agent has the concept — Sail omits both.
301
+ *
302
+ * `minSplits` is the field that carries the meaning: 1 means "split only when
303
+ * it beats a single pool", 2-4 means "force a split for diversification".
304
+ *
305
+ * Zyfai stores these PER ASSET. This profile read does not pass an asset, so
306
+ * these reflect the USDC bucket; a WETH-only user's real setting is not shown
307
+ * here.
308
+ */
309
+ splitting?: boolean;
310
+ minSplits?: number;
256
311
  }
257
312
  interface OwneyUserProfile {
258
313
  agentUserProfile: Record<AgentId, AgentUserProfile>;
@@ -275,6 +330,19 @@ interface IAgent {
275
330
  readonly supportedAssets: readonly AgentSupportedAssets[];
276
331
  disconnect(): Promise<void>;
277
332
  activateAgent(state: ConnectionState, chainId: number): Promise<void>;
333
+ /**
334
+ * Apply the organization's agent policy to this user's account.
335
+ *
336
+ * Optional: an agent that has no equivalent knob simply omits it, which is why
337
+ * this is not part of `activateAgent`'s signature. Declared on the interface
338
+ * rather than only on ZyfaiAgent so the contract stays agent-neutral — the
339
+ * ticket asks for a design that can also cover Surf, which has no adapter yet.
340
+ *
341
+ * Implementations must be **non-fatal**: this runs during activation as a side
342
+ * effect, so a failure has to leave the user connected and their profile
343
+ * unchanged rather than break the connect.
344
+ */
345
+ applyOrgPolicy?(state: ConnectionState, chainId: number, policy: OrgAgentConfig): Promise<void>;
278
346
  deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
279
347
  withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
280
348
  getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
@@ -318,6 +386,8 @@ declare class OwneySDK {
318
386
  private disabledAgents;
319
387
  private state;
320
388
  private apiKey;
389
+ private orgAgentConfig;
390
+ private orgAgentConfigPromise;
321
391
  private zyfaiRpcUrls?;
322
392
  private routingApiBaseUrl?;
323
393
  private referralSource?;
@@ -366,6 +436,20 @@ declare class OwneySDK {
366
436
  private getDefaultWethSponsoredCallback;
367
437
  private getAgent;
368
438
  private getActiveAgents;
439
+ /**
440
+ * Read the org's agent policy once and reuse it. fetchOrgAgentConfig never
441
+ * throws — it degrades to null — so this cannot break activation.
442
+ */
443
+ private getOrgAgentConfig;
444
+ /**
445
+ * Apply the org policy to one agent, after it has activated.
446
+ *
447
+ * Sequenced after activation rather than alongside it because applying the
448
+ * policy needs the authenticated session activation establishes. Every failure
449
+ * mode is swallowed: a partner's splitting preference is not worth failing a
450
+ * user's connect over.
451
+ */
452
+ private applyOrgPolicyTo;
369
453
  private ensureAgentsInitialized;
370
454
  private createAgent;
371
455
  /**
@@ -555,6 +639,29 @@ declare class InvalidHistoryCursorError extends Error {
555
639
  constructor(message: string);
556
640
  }
557
641
 
642
+ /**
643
+ * Opt-in debug logging.
644
+ *
645
+ * The SDK is deliberately quiet: before this, `src/` contained no `console.log`
646
+ * at all, only `console.warn`/`console.error` for genuine faults. That is worth
647
+ * preserving — this runs inside every partner's app, on every user's connect, so
648
+ * unconditional chatter would land in end users' consoles forever.
649
+ *
650
+ * Two ways to turn it on:
651
+ *
652
+ * 1. From the app: new OwneySDK({ apiKey, debug: true })
653
+ * 2. From devtools, live: globalThis.__OWNEY_DEBUG__ = true
654
+ *
655
+ * (2) is the useful one when diagnosing something on an already-deployed app:
656
+ * the flag is read on every call, not captured once, so flipping it in the
657
+ * console takes effect on the next action without a rebuild or a republish.
658
+ */
659
+ declare global {
660
+ var __OWNEY_DEBUG__: boolean | undefined;
661
+ }
662
+ /** Enable/disable debug logging programmatically. */
663
+ declare function setOwneyDebug(enabled: boolean): void;
664
+
558
665
  type OwneySIWXConfig = {
559
666
  /** Owney/Zyfai API key — same value passed to `new OwneySDK({ apiKey })`. */
560
667
  apiKey: string;
@@ -568,4 +675,4 @@ type OwneySIWXConfig = {
568
675
  */
569
676
  declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
570
677
 
571
- export { type AccountAgentApy, type AccountApyOptions, 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 ApyHistoryPoint, type Asset, type ConnectionState, type DailyApyDays, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, NotConnectedError, 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 OwneyWithdrawResult, type RebalanceLog, type WithdrawOptions, createOwneySIWX };
678
+ export { type AccountAgentApy, type AccountApyOptions, 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 ApyHistoryPoint, type Asset, type ConnectionState, type DailyApyDays, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, NotConnectedError, 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 OwneyWithdrawResult, type RebalanceLog, type WithdrawOptions, createOwneySIWX, setOwneyDebug };