@owney/sdk 0.6.9-beta.1 → 0.6.9-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 +78 -7
- package/dist/index.d.cts +46 -1
- package/dist/index.d.ts +46 -1
- package/dist/index.js +76 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,8 @@ __export(index_exports, {
|
|
|
26
26
|
NotConnectedError: () => NotConnectedError,
|
|
27
27
|
OwneyError: () => OwneyError,
|
|
28
28
|
OwneySDK: () => OwneySDK,
|
|
29
|
-
createOwneySIWX: () => createOwneySIWX
|
|
29
|
+
createOwneySIWX: () => createOwneySIWX,
|
|
30
|
+
setOwneyDebug: () => setOwneyDebug
|
|
30
31
|
});
|
|
31
32
|
module.exports = __toCommonJS(index_exports);
|
|
32
33
|
|
|
@@ -412,7 +413,9 @@ function mapUserProfile(raw, userAddress) {
|
|
|
412
413
|
chains: raw.chains || [],
|
|
413
414
|
strategy: raw.strategy,
|
|
414
415
|
hasActiveSessionKey: raw.hasActiveSessionKey || false,
|
|
415
|
-
protocols: raw.protocols || []
|
|
416
|
+
protocols: raw.protocols || [],
|
|
417
|
+
splitting: raw.splitting,
|
|
418
|
+
minSplits: raw.minSplits
|
|
416
419
|
};
|
|
417
420
|
}
|
|
418
421
|
function mapApyByStrategy(raw) {
|
|
@@ -693,6 +696,23 @@ function splittingNeedsUpdate(current, desired) {
|
|
|
693
696
|
return current.minSplits !== desired.minSplits;
|
|
694
697
|
}
|
|
695
698
|
|
|
699
|
+
// src/lib/debug.ts
|
|
700
|
+
var configuredDebug = false;
|
|
701
|
+
function setOwneyDebug(enabled) {
|
|
702
|
+
configuredDebug = enabled;
|
|
703
|
+
}
|
|
704
|
+
function isOwneyDebug() {
|
|
705
|
+
return globalThis.__OWNEY_DEBUG__ === true || configuredDebug;
|
|
706
|
+
}
|
|
707
|
+
function debugLog(scope, message, data) {
|
|
708
|
+
if (!isOwneyDebug()) return;
|
|
709
|
+
if (data === void 0) {
|
|
710
|
+
console.log(`[${scope}] ${message}`);
|
|
711
|
+
} else {
|
|
712
|
+
console.log(`[${scope}] ${message}`, data);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
696
716
|
// src/agents/zyfai/zyfai.agent.ts
|
|
697
717
|
var DEFAULT_ZYFAI_RPC_URLS = {
|
|
698
718
|
8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
|
|
@@ -1082,6 +1102,11 @@ var ZyfaiAgent = class {
|
|
|
1082
1102
|
* activation.
|
|
1083
1103
|
*/
|
|
1084
1104
|
async applyOrgPolicy(_state, _chainId, policy) {
|
|
1105
|
+
debugLog("zyfai:splitting", "applying org policy", {
|
|
1106
|
+
policy,
|
|
1107
|
+
// Per asset because Zyfai stores splitting under assetTypeSettings[asset].
|
|
1108
|
+
assets: SPLITTING_ASSETS
|
|
1109
|
+
});
|
|
1085
1110
|
await Promise.all(
|
|
1086
1111
|
SPLITTING_ASSETS.map((asset) => this.applySplitting(asset, policy))
|
|
1087
1112
|
);
|
|
@@ -1090,8 +1115,30 @@ var ZyfaiAgent = class {
|
|
|
1090
1115
|
try {
|
|
1091
1116
|
const desired = toZyfaiSplitting(policy);
|
|
1092
1117
|
const current = await this.sdk.getUserDetails(asset);
|
|
1093
|
-
|
|
1094
|
-
|
|
1118
|
+
const currentSplitting = {
|
|
1119
|
+
splitting: current?.splitting,
|
|
1120
|
+
minSplits: current?.minSplits
|
|
1121
|
+
};
|
|
1122
|
+
const needsUpdate = splittingNeedsUpdate(current, desired);
|
|
1123
|
+
debugLog("zyfai:splitting", `${asset}: comparing`, {
|
|
1124
|
+
mode: policy.splittingMode,
|
|
1125
|
+
current: currentSplitting,
|
|
1126
|
+
desired,
|
|
1127
|
+
// Spelled out because the "why" is the non-obvious part: minSplits is
|
|
1128
|
+
// what separates automatic (1) from force (2-4), not `splitting`.
|
|
1129
|
+
decision: needsUpdate ? "will write \u2014 profile differs from the org policy" : "skipping \u2014 profile already matches"
|
|
1130
|
+
});
|
|
1131
|
+
if (!needsUpdate) return;
|
|
1132
|
+
const result = await this.sdk.updateUserProfile({ asset, ...desired });
|
|
1133
|
+
debugLog("zyfai:splitting", `${asset}: wrote updateUserProfile`, {
|
|
1134
|
+
sent: { asset, ...desired },
|
|
1135
|
+
// updateUserProfile re-reads the profile after PATCHing, so this is
|
|
1136
|
+
// Zyfai's own view of the result rather than an echo of what we sent.
|
|
1137
|
+
zyfaiNowReports: {
|
|
1138
|
+
splitting: result?.splitting,
|
|
1139
|
+
minSplits: result?.minSplits
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1095
1142
|
} catch (error) {
|
|
1096
1143
|
console.warn(
|
|
1097
1144
|
`[zyfai] applyOrgPolicy(${asset}) failed (non-fatal):`,
|
|
@@ -1219,6 +1266,16 @@ var ZyfaiAgent = class {
|
|
|
1219
1266
|
await this.connectAuth(state, chainId);
|
|
1220
1267
|
const validChainId = isValidChainId(chainId);
|
|
1221
1268
|
const raw = await this.sdk.getUserDetails();
|
|
1269
|
+
debugLog("zyfai:profile", "getUserProfile \u2014 Zyfai reports", {
|
|
1270
|
+
asset: "USDC (default \u2014 no asset passed)",
|
|
1271
|
+
splitting: raw.splitting,
|
|
1272
|
+
minSplits: raw.minSplits,
|
|
1273
|
+
strategy: raw.strategy,
|
|
1274
|
+
chains: raw.chains,
|
|
1275
|
+
protocolCount: raw.protocols?.length,
|
|
1276
|
+
hasActiveSessionKey: raw.hasActiveSessionKey,
|
|
1277
|
+
smartWallet: raw.smartWallet
|
|
1278
|
+
});
|
|
1222
1279
|
await this.ensureSessionKey(state, this.getAddress(), validChainId);
|
|
1223
1280
|
return mapUserProfile(raw, this.connectedAddress);
|
|
1224
1281
|
}
|
|
@@ -1271,7 +1328,13 @@ async function fetchOrgAgentConfig(apiKey) {
|
|
|
1271
1328
|
return null;
|
|
1272
1329
|
}
|
|
1273
1330
|
const json = await res.json();
|
|
1274
|
-
|
|
1331
|
+
const policy = json.success ? json.data ?? null : null;
|
|
1332
|
+
debugLog(
|
|
1333
|
+
"owney-sdk",
|
|
1334
|
+
policy ? "org agent config: loaded" : "org agent config: none set by this partner \u2014 user profiles will be left as they are",
|
|
1335
|
+
policy ?? void 0
|
|
1336
|
+
);
|
|
1337
|
+
return policy;
|
|
1275
1338
|
} catch (error) {
|
|
1276
1339
|
console.warn(
|
|
1277
1340
|
"[owney-sdk] Could not read org agent config (non-fatal):",
|
|
@@ -1907,6 +1970,7 @@ var OwneySDK = class {
|
|
|
1907
1970
|
initializingAgentsPromise = null;
|
|
1908
1971
|
constructor(config) {
|
|
1909
1972
|
this.apiKey = config.apiKey;
|
|
1973
|
+
if (config.debug) setOwneyDebug(true);
|
|
1910
1974
|
this.zyfaiRpcUrls = config.zyfaiRpcUrls;
|
|
1911
1975
|
this.routingApiBaseUrl = config.routingApiBaseUrl;
|
|
1912
1976
|
this.referralSource = config.referralSource;
|
|
@@ -2093,7 +2157,13 @@ var OwneySDK = class {
|
|
|
2093
2157
|
* user's connect over.
|
|
2094
2158
|
*/
|
|
2095
2159
|
async applyOrgPolicyTo(agent, state, chainId) {
|
|
2096
|
-
if (!agent.applyOrgPolicy)
|
|
2160
|
+
if (!agent.applyOrgPolicy) {
|
|
2161
|
+
debugLog(
|
|
2162
|
+
"owney-sdk",
|
|
2163
|
+
`${agent.id}: no applyOrgPolicy \u2014 agent has no org-level knobs, skipping`
|
|
2164
|
+
);
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2097
2167
|
try {
|
|
2098
2168
|
const policy = await this.getOrgAgentConfig();
|
|
2099
2169
|
if (!policy) return;
|
|
@@ -3227,5 +3297,6 @@ function createOwneySIWX(config) {
|
|
|
3227
3297
|
NotConnectedError,
|
|
3228
3298
|
OwneyError,
|
|
3229
3299
|
OwneySDK,
|
|
3230
|
-
createOwneySIWX
|
|
3300
|
+
createOwneySIWX,
|
|
3301
|
+
setOwneyDebug
|
|
3231
3302
|
});
|
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;
|
|
@@ -263,6 +272,19 @@ interface AgentUserProfile {
|
|
|
263
272
|
strategy?: string;
|
|
264
273
|
hasActiveSessionKey: boolean;
|
|
265
274
|
protocols: string[];
|
|
275
|
+
/**
|
|
276
|
+
* Capital splitting, as the agent currently has it (ROUT-229). Optional
|
|
277
|
+
* because not every agent has the concept — Sail omits both.
|
|
278
|
+
*
|
|
279
|
+
* `minSplits` is the field that carries the meaning: 1 means "split only when
|
|
280
|
+
* it beats a single pool", 2-4 means "force a split for diversification".
|
|
281
|
+
*
|
|
282
|
+
* Zyfai stores these PER ASSET. This profile read does not pass an asset, so
|
|
283
|
+
* these reflect the USDC bucket; a WETH-only user's real setting is not shown
|
|
284
|
+
* here.
|
|
285
|
+
*/
|
|
286
|
+
splitting?: boolean;
|
|
287
|
+
minSplits?: number;
|
|
266
288
|
}
|
|
267
289
|
interface OwneyUserProfile {
|
|
268
290
|
agentUserProfile: Record<AgentId, AgentUserProfile>;
|
|
@@ -594,6 +616,29 @@ declare class InvalidHistoryCursorError extends Error {
|
|
|
594
616
|
constructor(message: string);
|
|
595
617
|
}
|
|
596
618
|
|
|
619
|
+
/**
|
|
620
|
+
* Opt-in debug logging.
|
|
621
|
+
*
|
|
622
|
+
* The SDK is deliberately quiet: before this, `src/` contained no `console.log`
|
|
623
|
+
* at all, only `console.warn`/`console.error` for genuine faults. That is worth
|
|
624
|
+
* preserving — this runs inside every partner's app, on every user's connect, so
|
|
625
|
+
* unconditional chatter would land in end users' consoles forever.
|
|
626
|
+
*
|
|
627
|
+
* Two ways to turn it on:
|
|
628
|
+
*
|
|
629
|
+
* 1. From the app: new OwneySDK({ apiKey, debug: true })
|
|
630
|
+
* 2. From devtools, live: globalThis.__OWNEY_DEBUG__ = true
|
|
631
|
+
*
|
|
632
|
+
* (2) is the useful one when diagnosing something on an already-deployed app:
|
|
633
|
+
* the flag is read on every call, not captured once, so flipping it in the
|
|
634
|
+
* console takes effect on the next action without a rebuild or a republish.
|
|
635
|
+
*/
|
|
636
|
+
declare global {
|
|
637
|
+
var __OWNEY_DEBUG__: boolean | undefined;
|
|
638
|
+
}
|
|
639
|
+
/** Enable/disable debug logging programmatically. */
|
|
640
|
+
declare function setOwneyDebug(enabled: boolean): void;
|
|
641
|
+
|
|
597
642
|
type OwneySIWXConfig = {
|
|
598
643
|
/** Owney/Zyfai API key — same value passed to `new OwneySDK({ apiKey })`. */
|
|
599
644
|
apiKey: string;
|
|
@@ -607,4 +652,4 @@ type OwneySIWXConfig = {
|
|
|
607
652
|
*/
|
|
608
653
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
609
654
|
|
|
610
|
-
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
|
|
655
|
+
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, 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;
|
|
@@ -263,6 +272,19 @@ interface AgentUserProfile {
|
|
|
263
272
|
strategy?: string;
|
|
264
273
|
hasActiveSessionKey: boolean;
|
|
265
274
|
protocols: string[];
|
|
275
|
+
/**
|
|
276
|
+
* Capital splitting, as the agent currently has it (ROUT-229). Optional
|
|
277
|
+
* because not every agent has the concept — Sail omits both.
|
|
278
|
+
*
|
|
279
|
+
* `minSplits` is the field that carries the meaning: 1 means "split only when
|
|
280
|
+
* it beats a single pool", 2-4 means "force a split for diversification".
|
|
281
|
+
*
|
|
282
|
+
* Zyfai stores these PER ASSET. This profile read does not pass an asset, so
|
|
283
|
+
* these reflect the USDC bucket; a WETH-only user's real setting is not shown
|
|
284
|
+
* here.
|
|
285
|
+
*/
|
|
286
|
+
splitting?: boolean;
|
|
287
|
+
minSplits?: number;
|
|
266
288
|
}
|
|
267
289
|
interface OwneyUserProfile {
|
|
268
290
|
agentUserProfile: Record<AgentId, AgentUserProfile>;
|
|
@@ -594,6 +616,29 @@ declare class InvalidHistoryCursorError extends Error {
|
|
|
594
616
|
constructor(message: string);
|
|
595
617
|
}
|
|
596
618
|
|
|
619
|
+
/**
|
|
620
|
+
* Opt-in debug logging.
|
|
621
|
+
*
|
|
622
|
+
* The SDK is deliberately quiet: before this, `src/` contained no `console.log`
|
|
623
|
+
* at all, only `console.warn`/`console.error` for genuine faults. That is worth
|
|
624
|
+
* preserving — this runs inside every partner's app, on every user's connect, so
|
|
625
|
+
* unconditional chatter would land in end users' consoles forever.
|
|
626
|
+
*
|
|
627
|
+
* Two ways to turn it on:
|
|
628
|
+
*
|
|
629
|
+
* 1. From the app: new OwneySDK({ apiKey, debug: true })
|
|
630
|
+
* 2. From devtools, live: globalThis.__OWNEY_DEBUG__ = true
|
|
631
|
+
*
|
|
632
|
+
* (2) is the useful one when diagnosing something on an already-deployed app:
|
|
633
|
+
* the flag is read on every call, not captured once, so flipping it in the
|
|
634
|
+
* console takes effect on the next action without a rebuild or a republish.
|
|
635
|
+
*/
|
|
636
|
+
declare global {
|
|
637
|
+
var __OWNEY_DEBUG__: boolean | undefined;
|
|
638
|
+
}
|
|
639
|
+
/** Enable/disable debug logging programmatically. */
|
|
640
|
+
declare function setOwneyDebug(enabled: boolean): void;
|
|
641
|
+
|
|
597
642
|
type OwneySIWXConfig = {
|
|
598
643
|
/** Owney/Zyfai API key — same value passed to `new OwneySDK({ apiKey })`. */
|
|
599
644
|
apiKey: string;
|
|
@@ -607,4 +652,4 @@ type OwneySIWXConfig = {
|
|
|
607
652
|
*/
|
|
608
653
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
609
654
|
|
|
610
|
-
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
|
|
655
|
+
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, AllocationApyOptions, ApyByChainAndAsset, ApyHistoryPoint, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX, setOwneyDebug };
|
package/dist/index.js
CHANGED
|
@@ -380,7 +380,9 @@ function mapUserProfile(raw, userAddress) {
|
|
|
380
380
|
chains: raw.chains || [],
|
|
381
381
|
strategy: raw.strategy,
|
|
382
382
|
hasActiveSessionKey: raw.hasActiveSessionKey || false,
|
|
383
|
-
protocols: raw.protocols || []
|
|
383
|
+
protocols: raw.protocols || [],
|
|
384
|
+
splitting: raw.splitting,
|
|
385
|
+
minSplits: raw.minSplits
|
|
384
386
|
};
|
|
385
387
|
}
|
|
386
388
|
function mapApyByStrategy(raw) {
|
|
@@ -661,6 +663,23 @@ function splittingNeedsUpdate(current, desired) {
|
|
|
661
663
|
return current.minSplits !== desired.minSplits;
|
|
662
664
|
}
|
|
663
665
|
|
|
666
|
+
// src/lib/debug.ts
|
|
667
|
+
var configuredDebug = false;
|
|
668
|
+
function setOwneyDebug(enabled) {
|
|
669
|
+
configuredDebug = enabled;
|
|
670
|
+
}
|
|
671
|
+
function isOwneyDebug() {
|
|
672
|
+
return globalThis.__OWNEY_DEBUG__ === true || configuredDebug;
|
|
673
|
+
}
|
|
674
|
+
function debugLog(scope, message, data) {
|
|
675
|
+
if (!isOwneyDebug()) return;
|
|
676
|
+
if (data === void 0) {
|
|
677
|
+
console.log(`[${scope}] ${message}`);
|
|
678
|
+
} else {
|
|
679
|
+
console.log(`[${scope}] ${message}`, data);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
664
683
|
// src/agents/zyfai/zyfai.agent.ts
|
|
665
684
|
var DEFAULT_ZYFAI_RPC_URLS = {
|
|
666
685
|
8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
|
|
@@ -1050,6 +1069,11 @@ var ZyfaiAgent = class {
|
|
|
1050
1069
|
* activation.
|
|
1051
1070
|
*/
|
|
1052
1071
|
async applyOrgPolicy(_state, _chainId, policy) {
|
|
1072
|
+
debugLog("zyfai:splitting", "applying org policy", {
|
|
1073
|
+
policy,
|
|
1074
|
+
// Per asset because Zyfai stores splitting under assetTypeSettings[asset].
|
|
1075
|
+
assets: SPLITTING_ASSETS
|
|
1076
|
+
});
|
|
1053
1077
|
await Promise.all(
|
|
1054
1078
|
SPLITTING_ASSETS.map((asset) => this.applySplitting(asset, policy))
|
|
1055
1079
|
);
|
|
@@ -1058,8 +1082,30 @@ var ZyfaiAgent = class {
|
|
|
1058
1082
|
try {
|
|
1059
1083
|
const desired = toZyfaiSplitting(policy);
|
|
1060
1084
|
const current = await this.sdk.getUserDetails(asset);
|
|
1061
|
-
|
|
1062
|
-
|
|
1085
|
+
const currentSplitting = {
|
|
1086
|
+
splitting: current?.splitting,
|
|
1087
|
+
minSplits: current?.minSplits
|
|
1088
|
+
};
|
|
1089
|
+
const needsUpdate = splittingNeedsUpdate(current, desired);
|
|
1090
|
+
debugLog("zyfai:splitting", `${asset}: comparing`, {
|
|
1091
|
+
mode: policy.splittingMode,
|
|
1092
|
+
current: currentSplitting,
|
|
1093
|
+
desired,
|
|
1094
|
+
// Spelled out because the "why" is the non-obvious part: minSplits is
|
|
1095
|
+
// what separates automatic (1) from force (2-4), not `splitting`.
|
|
1096
|
+
decision: needsUpdate ? "will write \u2014 profile differs from the org policy" : "skipping \u2014 profile already matches"
|
|
1097
|
+
});
|
|
1098
|
+
if (!needsUpdate) return;
|
|
1099
|
+
const result = await this.sdk.updateUserProfile({ asset, ...desired });
|
|
1100
|
+
debugLog("zyfai:splitting", `${asset}: wrote updateUserProfile`, {
|
|
1101
|
+
sent: { asset, ...desired },
|
|
1102
|
+
// updateUserProfile re-reads the profile after PATCHing, so this is
|
|
1103
|
+
// Zyfai's own view of the result rather than an echo of what we sent.
|
|
1104
|
+
zyfaiNowReports: {
|
|
1105
|
+
splitting: result?.splitting,
|
|
1106
|
+
minSplits: result?.minSplits
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1063
1109
|
} catch (error) {
|
|
1064
1110
|
console.warn(
|
|
1065
1111
|
`[zyfai] applyOrgPolicy(${asset}) failed (non-fatal):`,
|
|
@@ -1187,6 +1233,16 @@ var ZyfaiAgent = class {
|
|
|
1187
1233
|
await this.connectAuth(state, chainId);
|
|
1188
1234
|
const validChainId = isValidChainId(chainId);
|
|
1189
1235
|
const raw = await this.sdk.getUserDetails();
|
|
1236
|
+
debugLog("zyfai:profile", "getUserProfile \u2014 Zyfai reports", {
|
|
1237
|
+
asset: "USDC (default \u2014 no asset passed)",
|
|
1238
|
+
splitting: raw.splitting,
|
|
1239
|
+
minSplits: raw.minSplits,
|
|
1240
|
+
strategy: raw.strategy,
|
|
1241
|
+
chains: raw.chains,
|
|
1242
|
+
protocolCount: raw.protocols?.length,
|
|
1243
|
+
hasActiveSessionKey: raw.hasActiveSessionKey,
|
|
1244
|
+
smartWallet: raw.smartWallet
|
|
1245
|
+
});
|
|
1190
1246
|
await this.ensureSessionKey(state, this.getAddress(), validChainId);
|
|
1191
1247
|
return mapUserProfile(raw, this.connectedAddress);
|
|
1192
1248
|
}
|
|
@@ -1239,7 +1295,13 @@ async function fetchOrgAgentConfig(apiKey) {
|
|
|
1239
1295
|
return null;
|
|
1240
1296
|
}
|
|
1241
1297
|
const json = await res.json();
|
|
1242
|
-
|
|
1298
|
+
const policy = json.success ? json.data ?? null : null;
|
|
1299
|
+
debugLog(
|
|
1300
|
+
"owney-sdk",
|
|
1301
|
+
policy ? "org agent config: loaded" : "org agent config: none set by this partner \u2014 user profiles will be left as they are",
|
|
1302
|
+
policy ?? void 0
|
|
1303
|
+
);
|
|
1304
|
+
return policy;
|
|
1243
1305
|
} catch (error) {
|
|
1244
1306
|
console.warn(
|
|
1245
1307
|
"[owney-sdk] Could not read org agent config (non-fatal):",
|
|
@@ -1879,6 +1941,7 @@ var OwneySDK = class {
|
|
|
1879
1941
|
initializingAgentsPromise = null;
|
|
1880
1942
|
constructor(config) {
|
|
1881
1943
|
this.apiKey = config.apiKey;
|
|
1944
|
+
if (config.debug) setOwneyDebug(true);
|
|
1882
1945
|
this.zyfaiRpcUrls = config.zyfaiRpcUrls;
|
|
1883
1946
|
this.routingApiBaseUrl = config.routingApiBaseUrl;
|
|
1884
1947
|
this.referralSource = config.referralSource;
|
|
@@ -2065,7 +2128,13 @@ var OwneySDK = class {
|
|
|
2065
2128
|
* user's connect over.
|
|
2066
2129
|
*/
|
|
2067
2130
|
async applyOrgPolicyTo(agent, state, chainId) {
|
|
2068
|
-
if (!agent.applyOrgPolicy)
|
|
2131
|
+
if (!agent.applyOrgPolicy) {
|
|
2132
|
+
debugLog(
|
|
2133
|
+
"owney-sdk",
|
|
2134
|
+
`${agent.id}: no applyOrgPolicy \u2014 agent has no org-level knobs, skipping`
|
|
2135
|
+
);
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2069
2138
|
try {
|
|
2070
2139
|
const policy = await this.getOrgAgentConfig();
|
|
2071
2140
|
if (!policy) return;
|
|
@@ -3198,5 +3267,6 @@ export {
|
|
|
3198
3267
|
NotConnectedError,
|
|
3199
3268
|
OwneyError,
|
|
3200
3269
|
OwneySDK,
|
|
3201
|
-
createOwneySIWX
|
|
3270
|
+
createOwneySIWX,
|
|
3271
|
+
setOwneyDebug
|
|
3202
3272
|
};
|