@owney/sdk 0.6.9-beta.5 → 0.6.9-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/chunk-GMNQBWUB.js +55 -0
- package/dist/index.cjs +615 -103
- package/dist/index.d.cts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +110 -88
- package/dist/surfliquid.agent-OMOYXWLP.js +385 -0
- package/package.json +3 -1
package/dist/index.d.cts
CHANGED
|
@@ -21,6 +21,16 @@ interface OwneySDKConfig {
|
|
|
21
21
|
* `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
|
|
22
22
|
*/
|
|
23
23
|
referralSource?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Optional override for the SurfLiquid API base URL (defaults to the
|
|
26
|
+
* SurfLiquid SDK's production URL). SurfLiquid auth is an httpOnly
|
|
27
|
+
* SameSite=None cookie set by api.surfliquid.com — a THIRD-PARTY cookie from
|
|
28
|
+
* the embedding app's origin, which WebKit (all iOS browsers) discards, so
|
|
29
|
+
* every authenticated SurfLiquid call 401s on iOS. Point this at a
|
|
30
|
+
* same-origin reverse proxy (e.g. "/api/surf") so the session cookie becomes
|
|
31
|
+
* first-party. Relative paths resolve against the page origin.
|
|
32
|
+
*/
|
|
33
|
+
surfliquidApiBaseUrl?: string;
|
|
24
34
|
/**
|
|
25
35
|
* Turn on the SDK's debug logging (default false). Traces the decisions that
|
|
26
36
|
* are otherwise invisible — notably how the organization's agent policy is
|
|
@@ -43,7 +53,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
|
43
53
|
type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
|
|
44
54
|
type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
|
|
45
55
|
|
|
46
|
-
type AgentId = "zyfai" | "sail";
|
|
56
|
+
type AgentId = "zyfai" | "sail" | "surfliquid";
|
|
47
57
|
type Asset = string;
|
|
48
58
|
type AgentSupportedAsset = {
|
|
49
59
|
readonly symbol: string;
|
|
@@ -150,6 +160,12 @@ interface OwneyDepositResult {
|
|
|
150
160
|
}
|
|
151
161
|
interface OwneyMultiDepositResult {
|
|
152
162
|
agentResults: Record<string, OwneyDepositResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Per-agent failure messages for agents that errored during a diversified
|
|
165
|
+
* deposit. Present only when at least one (but not all) agents failed —
|
|
166
|
+
* the deposit is partial, not total. Omitted when every agent succeeded.
|
|
167
|
+
*/
|
|
168
|
+
agentErrors?: Record<string, string>;
|
|
153
169
|
}
|
|
154
170
|
interface AgentWithdrawResult {
|
|
155
171
|
txHash?: string;
|
|
@@ -391,6 +407,7 @@ declare class OwneySDK {
|
|
|
391
407
|
private zyfaiRpcUrls?;
|
|
392
408
|
private routingApiBaseUrl?;
|
|
393
409
|
private referralSource?;
|
|
410
|
+
private surfliquidApiBaseUrl?;
|
|
394
411
|
private cachedSponsoredCallback;
|
|
395
412
|
private cachedWethSponsoredCallback;
|
|
396
413
|
private initializingAgentsPromise;
|
|
@@ -514,6 +531,17 @@ declare class OwneySDK {
|
|
|
514
531
|
private hasExistingBalance;
|
|
515
532
|
private validateAssetSupport;
|
|
516
533
|
private getEligibleAgents;
|
|
534
|
+
/**
|
|
535
|
+
* Agent ids the routing API provisioned for this org that support the given
|
|
536
|
+
* chain + asset, ordered by preference ({@link AGENT_ELIGIBILITY_ORDER},
|
|
537
|
+
* surfliquid first). Returns `[]` when the org has no compatible agent — never
|
|
538
|
+
* throws on an empty org. Loads agent keys on first call (apiKey only, no
|
|
539
|
+
* wallet), so the UI can resolve which agent to use before the user connects.
|
|
540
|
+
*
|
|
541
|
+
* This is the source of truth for agent availability: an agent appears here
|
|
542
|
+
* iff the routing API returned its key. No per-app feature flags.
|
|
543
|
+
*/
|
|
544
|
+
getEligibleAgentIds(chainId: number, asset: string): Promise<AgentId[]>;
|
|
517
545
|
/**
|
|
518
546
|
* Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
|
|
519
547
|
* Validates that the asset is supported by the target agent(s) on the active chain.
|
|
@@ -609,7 +637,7 @@ declare class OwneySDK {
|
|
|
609
637
|
getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
|
|
610
638
|
}
|
|
611
639
|
|
|
612
|
-
type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
640
|
+
type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_ALL_FAILED" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
613
641
|
declare class OwneyError extends Error {
|
|
614
642
|
readonly code: OwneyErrorCode;
|
|
615
643
|
readonly details?: Record<string, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,16 @@ interface OwneySDKConfig {
|
|
|
21
21
|
* `createOwneySIWX` for apps that don't use the AppKit SIWX modal.
|
|
22
22
|
*/
|
|
23
23
|
referralSource?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Optional override for the SurfLiquid API base URL (defaults to the
|
|
26
|
+
* SurfLiquid SDK's production URL). SurfLiquid auth is an httpOnly
|
|
27
|
+
* SameSite=None cookie set by api.surfliquid.com — a THIRD-PARTY cookie from
|
|
28
|
+
* the embedding app's origin, which WebKit (all iOS browsers) discards, so
|
|
29
|
+
* every authenticated SurfLiquid call 401s on iOS. Point this at a
|
|
30
|
+
* same-origin reverse proxy (e.g. "/api/surf") so the session cookie becomes
|
|
31
|
+
* first-party. Relative paths resolve against the page origin.
|
|
32
|
+
*/
|
|
33
|
+
surfliquidApiBaseUrl?: string;
|
|
24
34
|
/**
|
|
25
35
|
* Turn on the SDK's debug logging (default false). Traces the decisions that
|
|
26
36
|
* are otherwise invisible — notably how the organization's agent policy is
|
|
@@ -43,7 +53,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
|
43
53
|
type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
|
|
44
54
|
type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
|
|
45
55
|
|
|
46
|
-
type AgentId = "zyfai" | "sail";
|
|
56
|
+
type AgentId = "zyfai" | "sail" | "surfliquid";
|
|
47
57
|
type Asset = string;
|
|
48
58
|
type AgentSupportedAsset = {
|
|
49
59
|
readonly symbol: string;
|
|
@@ -150,6 +160,12 @@ interface OwneyDepositResult {
|
|
|
150
160
|
}
|
|
151
161
|
interface OwneyMultiDepositResult {
|
|
152
162
|
agentResults: Record<string, OwneyDepositResult>;
|
|
163
|
+
/**
|
|
164
|
+
* Per-agent failure messages for agents that errored during a diversified
|
|
165
|
+
* deposit. Present only when at least one (but not all) agents failed —
|
|
166
|
+
* the deposit is partial, not total. Omitted when every agent succeeded.
|
|
167
|
+
*/
|
|
168
|
+
agentErrors?: Record<string, string>;
|
|
153
169
|
}
|
|
154
170
|
interface AgentWithdrawResult {
|
|
155
171
|
txHash?: string;
|
|
@@ -391,6 +407,7 @@ declare class OwneySDK {
|
|
|
391
407
|
private zyfaiRpcUrls?;
|
|
392
408
|
private routingApiBaseUrl?;
|
|
393
409
|
private referralSource?;
|
|
410
|
+
private surfliquidApiBaseUrl?;
|
|
394
411
|
private cachedSponsoredCallback;
|
|
395
412
|
private cachedWethSponsoredCallback;
|
|
396
413
|
private initializingAgentsPromise;
|
|
@@ -514,6 +531,17 @@ declare class OwneySDK {
|
|
|
514
531
|
private hasExistingBalance;
|
|
515
532
|
private validateAssetSupport;
|
|
516
533
|
private getEligibleAgents;
|
|
534
|
+
/**
|
|
535
|
+
* Agent ids the routing API provisioned for this org that support the given
|
|
536
|
+
* chain + asset, ordered by preference ({@link AGENT_ELIGIBILITY_ORDER},
|
|
537
|
+
* surfliquid first). Returns `[]` when the org has no compatible agent — never
|
|
538
|
+
* throws on an empty org. Loads agent keys on first call (apiKey only, no
|
|
539
|
+
* wallet), so the UI can resolve which agent to use before the user connects.
|
|
540
|
+
*
|
|
541
|
+
* This is the source of truth for agent availability: an agent appears here
|
|
542
|
+
* iff the routing API returned its key. No per-app feature flags.
|
|
543
|
+
*/
|
|
544
|
+
getEligibleAgentIds(chainId: number, asset: string): Promise<AgentId[]>;
|
|
517
545
|
/**
|
|
518
546
|
* Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
|
|
519
547
|
* Validates that the asset is supported by the target agent(s) on the active chain.
|
|
@@ -609,7 +637,7 @@ declare class OwneySDK {
|
|
|
609
637
|
getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
|
|
610
638
|
}
|
|
611
639
|
|
|
612
|
-
type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
640
|
+
type OwneyErrorCode = "NOT_CONNECTED" | "NO_ACTIVE_CHAIN" | "WALLET_NO_ACCOUNTS" | "WALLET_ADDRESS_REQUIRED" | "AGENT_NOT_FOUND" | "AGENT_CHAIN_INCOMPATIBLE" | "AGENT_EMPTY_LIST" | "AGENT_DISABLED" | "CHAIN_UNSUPPORTED" | "CHAIN_NO_COMPATIBLE_AGENTS" | "ASSET_UNSUPPORTED" | "ASSET_NO_COMPATIBLE_AGENTS" | "DEPOSIT_AMOUNT_BELOW_MINIMUM" | "DEPOSIT_CALLBACK_REQUIRED" | "DEPOSIT_CALLBACK_INVALID" | "DEPOSIT_NO_PERMITTED_TOKENS" | "DEPOSIT_ALL_FAILED" | "DEPOSIT_INSUFFICIENT_BALANCE" | "WITHDRAW_NO_PERMITTED_TOKENS" | "WITHDRAW_INSUFFICIENT_BALANCE" | "WITHDRAW_ALL_FAILED" | "WITHDRAW_PARTIAL_FAILURE" | "WITHDRAW_FAILED" | "API_ROUTING_ERROR" | "API_ROUTING_FAILED" | "API_SAIL_ERROR" | "API_SAIL_TIMEOUT" | "API_NO_AGENTS" | "SPONSOR_REQUEST_FAILED" | "PERMIT2_APPROVAL_REQUIRED" | "BALANCE_ALL_FAILED" | "ALLOCATION_ALL_FAILED" | "VALIDATION_INVALID_DAYS";
|
|
613
641
|
declare class OwneyError extends Error {
|
|
614
642
|
readonly code: OwneyErrorCode;
|
|
615
643
|
readonly details?: Record<string, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentChainIncompatibleError,
|
|
3
|
+
AgentNotFoundError,
|
|
4
|
+
NotConnectedError,
|
|
5
|
+
OwneyError
|
|
6
|
+
} from "./chunk-GMNQBWUB.js";
|
|
7
|
+
|
|
1
8
|
// src/agents/zyfai/zyfai.agent.ts
|
|
2
9
|
import { ZyfaiSDK } from "@zyfai/sdk";
|
|
3
10
|
import { createPublicClient, http } from "viem";
|
|
@@ -56,55 +63,6 @@ var SupportedAssets = [
|
|
|
56
63
|
}
|
|
57
64
|
];
|
|
58
65
|
|
|
59
|
-
// src/errors.ts
|
|
60
|
-
var OwneyError = class extends Error {
|
|
61
|
-
code;
|
|
62
|
-
details;
|
|
63
|
-
agentId;
|
|
64
|
-
constructor(code, message, details, agentId) {
|
|
65
|
-
const prefix = agentId ? `[${code}][agent:${agentId}]` : `[${code}]`;
|
|
66
|
-
super(`${prefix} ${message}`);
|
|
67
|
-
this.name = "OwneyError";
|
|
68
|
-
this.code = code;
|
|
69
|
-
this.details = details;
|
|
70
|
-
this.agentId = agentId;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var AgentNotFoundError = class extends OwneyError {
|
|
74
|
-
constructor(agentId, available) {
|
|
75
|
-
super(
|
|
76
|
-
"AGENT_NOT_FOUND",
|
|
77
|
-
`Unknown agent "${agentId}". Available agents: ${available.join(", ")}`,
|
|
78
|
-
{ agentId, available },
|
|
79
|
-
agentId
|
|
80
|
-
);
|
|
81
|
-
this.name = "AgentNotFoundError";
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
var NotConnectedError = class extends OwneyError {
|
|
85
|
-
constructor() {
|
|
86
|
-
super("NOT_CONNECTED", "Not connected. Call sdk.connect(provider) first.");
|
|
87
|
-
this.name = "NotConnectedError";
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
var AgentChainIncompatibleError = class extends OwneyError {
|
|
91
|
-
incompatibleAgents;
|
|
92
|
-
connectedChainId;
|
|
93
|
-
constructor(incompatibleAgents, connectedChainId) {
|
|
94
|
-
const details = incompatibleAgents.map(
|
|
95
|
-
({ agentId, supportedChainIds }) => `"${agentId}" supports chains [${supportedChainIds.join(", ")}]`
|
|
96
|
-
).join("; ");
|
|
97
|
-
super(
|
|
98
|
-
"AGENT_CHAIN_INCOMPATIBLE",
|
|
99
|
-
`Chain ${connectedChainId} is not supported by the following agents: ${details}`,
|
|
100
|
-
{ incompatibleAgents, connectedChainId }
|
|
101
|
-
);
|
|
102
|
-
this.name = "AgentChainIncompatibleError";
|
|
103
|
-
this.incompatibleAgents = incompatibleAgents;
|
|
104
|
-
this.connectedChainId = connectedChainId;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
66
|
// src/lib/utils.ts
|
|
109
67
|
var isValidChainId = (chainId) => {
|
|
110
68
|
if (!SUPPORTED_CHAIN_IDS.includes(chainId)) {
|
|
@@ -179,46 +137,46 @@ function resolveChainId(chain) {
|
|
|
179
137
|
function mapBalances(raw, _chainId, smartWallet) {
|
|
180
138
|
const portfolio = raw.portfolio;
|
|
181
139
|
const portfolioByChain = portfolio.portfolioByChain ?? {};
|
|
140
|
+
const rawPositions = portfolio.positions ?? [];
|
|
141
|
+
const detailByKey = /* @__PURE__ */ new Map();
|
|
142
|
+
for (const p of rawPositions) {
|
|
143
|
+
const cid = resolveChainId(p.chain ?? "");
|
|
144
|
+
const symbol = (p.token_symbol ?? "").toUpperCase();
|
|
145
|
+
if (Number.isFinite(cid) && symbol) detailByKey.set(`${cid}:${symbol}`, p);
|
|
146
|
+
}
|
|
182
147
|
let totalBalance = 0;
|
|
183
148
|
const tokens = [];
|
|
149
|
+
const positions = [];
|
|
184
150
|
for (const [chainIdKey, tokensBySymbol] of Object.entries(portfolioByChain)) {
|
|
185
151
|
const positionChainId = Number(chainIdKey);
|
|
152
|
+
const chainName = CHAIN_ID_TO_NAME[positionChainId] ?? "BASE";
|
|
186
153
|
for (const [symbol, { balance, decimals }] of Object.entries(
|
|
187
154
|
tokensBySymbol ?? {}
|
|
188
155
|
)) {
|
|
189
|
-
const amount = hexToDecimal(balance || "0", decimals);
|
|
156
|
+
const amount = hexToDecimal(balance || "0", tokenDecimals(symbol, decimals));
|
|
190
157
|
totalBalance += amount;
|
|
191
158
|
tokens.push({
|
|
192
|
-
chain:
|
|
159
|
+
chain: chainName,
|
|
193
160
|
chainId: positionChainId,
|
|
194
161
|
asset: symbol,
|
|
195
162
|
amount: String(amount)
|
|
196
163
|
});
|
|
164
|
+
const detail = detailByKey.get(`${positionChainId}:${symbol.toUpperCase()}`);
|
|
165
|
+
positions.push({
|
|
166
|
+
chain: chainName,
|
|
167
|
+
protocol: detail?.protocol_name ?? detail?.protocol_id ?? "",
|
|
168
|
+
protocolId: detail?.protocol_id,
|
|
169
|
+
pool: detail?.pool,
|
|
170
|
+
asset: symbol,
|
|
171
|
+
amount: String(amount),
|
|
172
|
+
apy: detail?.pool_apy,
|
|
173
|
+
tvl: detail?.pool_tvl,
|
|
174
|
+
// PositionSlot has no `liquidity` field yet; Zyfai will add it. Narrow
|
|
175
|
+
// structural read keeps it undefined today and auto-populates later.
|
|
176
|
+
liquidity: detail?.liquidity
|
|
177
|
+
});
|
|
197
178
|
}
|
|
198
179
|
}
|
|
199
|
-
const positions = (portfolio.positions ?? []).map((p) => ({
|
|
200
|
-
chain: p.chain ?? "",
|
|
201
|
-
protocol: p.protocol_name ?? p.protocol_id ?? "",
|
|
202
|
-
protocolId: p.protocol_id,
|
|
203
|
-
pool: p.pool,
|
|
204
|
-
asset: p.token_symbol ?? "",
|
|
205
|
-
// Position amount is hex-encoded base units (like the token balances
|
|
206
|
-
// above). `PositionSlot` doesn't type a `decimals` field, but runtime
|
|
207
|
-
// getBalances payloads often carry one (e.g. 18 for WETH) — prefer that
|
|
208
|
-
// when present, otherwise fall back to the per-symbol lookup so
|
|
209
|
-
// non-6-decimal assets like WETH don't render 1e12 too large.
|
|
210
|
-
amount: String(
|
|
211
|
-
hexToDecimal(
|
|
212
|
-
p.amount || "0",
|
|
213
|
-
tokenDecimals(p.token_symbol, p.decimals)
|
|
214
|
-
)
|
|
215
|
-
),
|
|
216
|
-
apy: p.pool_apy,
|
|
217
|
-
tvl: p.pool_tvl,
|
|
218
|
-
// PositionSlot has no `liquidity` field yet; Zyfai will add it. Narrow
|
|
219
|
-
// structural read keeps it undefined today and auto-populates later.
|
|
220
|
-
liquidity: p.liquidity
|
|
221
|
-
}));
|
|
222
180
|
return {
|
|
223
181
|
smartWallet,
|
|
224
182
|
totalBalance: String(totalBalance),
|
|
@@ -2116,6 +2074,7 @@ var VIEM_CHAIN2 = {
|
|
|
2116
2074
|
42161: arbitrum2,
|
|
2117
2075
|
1: mainnet2
|
|
2118
2076
|
};
|
|
2077
|
+
var AGENT_ELIGIBILITY_ORDER = ["surfliquid", "zyfai", "sail"];
|
|
2119
2078
|
var SPONSORED_WETH_BY_CHAIN = {
|
|
2120
2079
|
8453: "0x4200000000000000000000000000000000000006",
|
|
2121
2080
|
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
@@ -2144,6 +2103,7 @@ var OwneySDK = class {
|
|
|
2144
2103
|
zyfaiRpcUrls;
|
|
2145
2104
|
routingApiBaseUrl;
|
|
2146
2105
|
referralSource;
|
|
2106
|
+
surfliquidApiBaseUrl;
|
|
2147
2107
|
cachedSponsoredCallback = null;
|
|
2148
2108
|
cachedWethSponsoredCallback = null;
|
|
2149
2109
|
initializingAgentsPromise = null;
|
|
@@ -2153,6 +2113,7 @@ var OwneySDK = class {
|
|
|
2153
2113
|
this.zyfaiRpcUrls = config.zyfaiRpcUrls;
|
|
2154
2114
|
this.routingApiBaseUrl = config.routingApiBaseUrl;
|
|
2155
2115
|
this.referralSource = config.referralSource;
|
|
2116
|
+
this.surfliquidApiBaseUrl = config.surfliquidApiBaseUrl;
|
|
2156
2117
|
}
|
|
2157
2118
|
/**
|
|
2158
2119
|
* Establish connection state for all subsequent SDK calls.
|
|
@@ -2360,8 +2321,8 @@ var OwneySDK = class {
|
|
|
2360
2321
|
this.initializingAgentsPromise = (async () => {
|
|
2361
2322
|
const agentKeys = await fetchAgentKeys(this.apiKey);
|
|
2362
2323
|
this.disabledAgents.clear();
|
|
2363
|
-
for (const { key: key2, agent_type, is_enabled } of agentKeys) {
|
|
2364
|
-
const agent = this.createAgent(agent_type, key2);
|
|
2324
|
+
for (const { key: key2, agent_type, project_name, is_enabled } of agentKeys) {
|
|
2325
|
+
const agent = await this.createAgent(agent_type, key2, project_name);
|
|
2365
2326
|
if (!agent) continue;
|
|
2366
2327
|
this.agents.set(agent_type, agent);
|
|
2367
2328
|
if (is_enabled === false) {
|
|
@@ -2382,10 +2343,22 @@ var OwneySDK = class {
|
|
|
2382
2343
|
this.initializingAgentsPromise = null;
|
|
2383
2344
|
}
|
|
2384
2345
|
}
|
|
2385
|
-
createAgent(agentId, key2) {
|
|
2346
|
+
async createAgent(agentId, key2, projectName) {
|
|
2386
2347
|
if (agentId === "zyfai") {
|
|
2387
2348
|
return new ZyfaiAgent(key2, this.zyfaiRpcUrls, this.referralSource);
|
|
2388
2349
|
}
|
|
2350
|
+
if (agentId === "surfliquid") {
|
|
2351
|
+
if (!projectName) return null;
|
|
2352
|
+
const { SurfLiquidAgent } = await import("./surfliquid.agent-OMOYXWLP.js");
|
|
2353
|
+
return new SurfLiquidAgent({
|
|
2354
|
+
projectName,
|
|
2355
|
+
appId: key2,
|
|
2356
|
+
// Same-origin proxy override — SurfLiquid auth is an httpOnly cookie,
|
|
2357
|
+
// which WebKit (iOS) discards when it is third-party. See
|
|
2358
|
+
// OwneySDKConfig.surfliquidApiBaseUrl.
|
|
2359
|
+
apiBaseUrl: this.surfliquidApiBaseUrl
|
|
2360
|
+
});
|
|
2361
|
+
}
|
|
2389
2362
|
return null;
|
|
2390
2363
|
}
|
|
2391
2364
|
// --- Account lifecycle ---
|
|
@@ -2540,18 +2513,30 @@ var OwneySDK = class {
|
|
|
2540
2513
|
);
|
|
2541
2514
|
}
|
|
2542
2515
|
const agentResults = {};
|
|
2516
|
+
const agentErrors = {};
|
|
2543
2517
|
for (const { agent, amount: agentAmount } of agentAmounts) {
|
|
2544
|
-
|
|
2545
|
-
agent
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2518
|
+
try {
|
|
2519
|
+
agentResults[agent.id] = await this.depositWithFallback(
|
|
2520
|
+
agent,
|
|
2521
|
+
state,
|
|
2522
|
+
chainId,
|
|
2523
|
+
agentAmount,
|
|
2524
|
+
asset,
|
|
2525
|
+
effectiveCallback,
|
|
2526
|
+
depositCallback
|
|
2527
|
+
);
|
|
2528
|
+
} catch (error) {
|
|
2529
|
+
agentErrors[agent.id] = error instanceof Error ? error.message : String(error);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2532
|
+
if (Object.keys(agentResults).length === 0) {
|
|
2533
|
+
throw new OwneyError(
|
|
2534
|
+
"DEPOSIT_ALL_FAILED",
|
|
2535
|
+
`All ${agentAmounts.length} agent deposit(s) failed.`,
|
|
2536
|
+
{ agentErrors }
|
|
2552
2537
|
);
|
|
2553
2538
|
}
|
|
2554
|
-
return { agentResults };
|
|
2539
|
+
return Object.keys(agentErrors).length > 0 ? { agentResults, agentErrors } : { agentResults };
|
|
2555
2540
|
}
|
|
2556
2541
|
/**
|
|
2557
2542
|
* Invokes `agent.deposit` with the resolved sponsored callback, composing
|
|
@@ -2708,6 +2693,34 @@ var OwneySDK = class {
|
|
|
2708
2693
|
}
|
|
2709
2694
|
return eligible;
|
|
2710
2695
|
}
|
|
2696
|
+
/**
|
|
2697
|
+
* Agent ids the routing API provisioned for this org that support the given
|
|
2698
|
+
* chain + asset, ordered by preference ({@link AGENT_ELIGIBILITY_ORDER},
|
|
2699
|
+
* surfliquid first). Returns `[]` when the org has no compatible agent — never
|
|
2700
|
+
* throws on an empty org. Loads agent keys on first call (apiKey only, no
|
|
2701
|
+
* wallet), so the UI can resolve which agent to use before the user connects.
|
|
2702
|
+
*
|
|
2703
|
+
* This is the source of truth for agent availability: an agent appears here
|
|
2704
|
+
* iff the routing API returned its key. No per-app feature flags.
|
|
2705
|
+
*/
|
|
2706
|
+
async getEligibleAgentIds(chainId, asset) {
|
|
2707
|
+
try {
|
|
2708
|
+
await this.ensureAgentsInitialized();
|
|
2709
|
+
} catch (error) {
|
|
2710
|
+
if (error instanceof OwneyError && error.code === "API_NO_AGENTS") {
|
|
2711
|
+
return [];
|
|
2712
|
+
}
|
|
2713
|
+
throw error;
|
|
2714
|
+
}
|
|
2715
|
+
return [...this.agents.values()].filter((agent) => {
|
|
2716
|
+
const chainAssets = agent.supportedAssets.find(
|
|
2717
|
+
(sa) => sa.chainId === chainId
|
|
2718
|
+
);
|
|
2719
|
+
return chainAssets?.assets.some((a) => a.symbol === asset) ?? false;
|
|
2720
|
+
}).map((agent) => agent.id).sort(
|
|
2721
|
+
(a, b) => AGENT_ELIGIBILITY_ORDER.indexOf(a) - AGENT_ELIGIBILITY_ORDER.indexOf(b)
|
|
2722
|
+
);
|
|
2723
|
+
}
|
|
2711
2724
|
// --- Fund operations ---
|
|
2712
2725
|
/**
|
|
2713
2726
|
* Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
|
|
@@ -2743,9 +2756,17 @@ var OwneySDK = class {
|
|
|
2743
2756
|
}
|
|
2744
2757
|
const eligibleAgents = this.getEligibleAgents(chainId, asset);
|
|
2745
2758
|
if (!amount) {
|
|
2759
|
+
const aggregated2 = await this.getBalances();
|
|
2760
|
+
const funded = projectAgentBalancesForAsset(
|
|
2761
|
+
eligibleAgents,
|
|
2762
|
+
aggregated2.agentBalances,
|
|
2763
|
+
chainId,
|
|
2764
|
+
asset,
|
|
2765
|
+
assetInfo.decimals
|
|
2766
|
+
).filter((b) => b.balance > 0n);
|
|
2746
2767
|
const results2 = {};
|
|
2747
2768
|
const agentErrors2 = {};
|
|
2748
|
-
for (const agent of
|
|
2769
|
+
for (const { agent } of funded) {
|
|
2749
2770
|
try {
|
|
2750
2771
|
results2[agent.id] = await agent.withdraw(state, chainId, token);
|
|
2751
2772
|
} catch (err) {
|
|
@@ -2762,9 +2783,10 @@ var OwneySDK = class {
|
|
|
2762
2783
|
{ asset, agentErrors: agentErrors2 }
|
|
2763
2784
|
);
|
|
2764
2785
|
}
|
|
2786
|
+
const totalWithdrawn = funded.filter(({ agent }) => results2[agent.id] !== void 0).reduce((sum, { balance }) => sum + balance, 0n);
|
|
2765
2787
|
return {
|
|
2766
2788
|
agentResult: results2,
|
|
2767
|
-
totalWithdrawn:
|
|
2789
|
+
totalWithdrawn: totalWithdrawn.toString()
|
|
2768
2790
|
};
|
|
2769
2791
|
}
|
|
2770
2792
|
const requested = BigInt(amount);
|