@owney/sdk 0.6.6 → 0.6.7-beta.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/chunk-GMNQBWUB.js +55 -0
- package/dist/index.cjs +608 -103
- package/dist/index.d.cts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +101 -88
- package/dist/surfliquid.agent-OMOYXWLP.js +385 -0
- package/package.json +3 -1
package/dist/index.d.cts
CHANGED
|
@@ -28,7 +28,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
|
28
28
|
type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
|
|
29
29
|
type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
|
|
30
30
|
|
|
31
|
-
type AgentId = "zyfai" | "sail";
|
|
31
|
+
type AgentId = "zyfai" | "sail" | "surfliquid";
|
|
32
32
|
type Asset = string;
|
|
33
33
|
type AgentSupportedAsset = {
|
|
34
34
|
readonly symbol: string;
|
|
@@ -101,6 +101,12 @@ interface OwneyDepositResult {
|
|
|
101
101
|
}
|
|
102
102
|
interface OwneyMultiDepositResult {
|
|
103
103
|
agentResults: Record<string, OwneyDepositResult>;
|
|
104
|
+
/**
|
|
105
|
+
* Per-agent failure messages for agents that errored during a diversified
|
|
106
|
+
* deposit. Present only when at least one (but not all) agents failed —
|
|
107
|
+
* the deposit is partial, not total. Omitted when every agent succeeded.
|
|
108
|
+
*/
|
|
109
|
+
agentErrors?: Record<string, string>;
|
|
104
110
|
}
|
|
105
111
|
interface AgentWithdrawResult {
|
|
106
112
|
txHash?: string;
|
|
@@ -422,6 +428,17 @@ declare class OwneySDK {
|
|
|
422
428
|
private hasExistingBalance;
|
|
423
429
|
private validateAssetSupport;
|
|
424
430
|
private getEligibleAgents;
|
|
431
|
+
/**
|
|
432
|
+
* Agent ids the routing API provisioned for this org that support the given
|
|
433
|
+
* chain + asset, ordered by preference ({@link AGENT_ELIGIBILITY_ORDER},
|
|
434
|
+
* surfliquid first). Returns `[]` when the org has no compatible agent — never
|
|
435
|
+
* throws on an empty org. Loads agent keys on first call (apiKey only, no
|
|
436
|
+
* wallet), so the UI can resolve which agent to use before the user connects.
|
|
437
|
+
*
|
|
438
|
+
* This is the source of truth for agent availability: an agent appears here
|
|
439
|
+
* iff the routing API returned its key. No per-app feature flags.
|
|
440
|
+
*/
|
|
441
|
+
getEligibleAgentIds(chainId: number, asset: string): Promise<AgentId[]>;
|
|
425
442
|
/**
|
|
426
443
|
* Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
|
|
427
444
|
* Validates that the asset is supported by the target agent(s) on the active chain.
|
|
@@ -517,7 +534,7 @@ declare class OwneySDK {
|
|
|
517
534
|
getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
|
|
518
535
|
}
|
|
519
536
|
|
|
520
|
-
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" | "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";
|
|
537
|
+
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" | "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";
|
|
521
538
|
declare class OwneyError extends Error {
|
|
522
539
|
readonly code: OwneyErrorCode;
|
|
523
540
|
readonly details?: Record<string, unknown>;
|
package/dist/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
|
28
28
|
type OwneySupportedChains = (typeof SUPPORTED_CHAINS)[number];
|
|
29
29
|
type OwneySupportedTokens = (typeof SUPPORTED_TOKENS)[number];
|
|
30
30
|
|
|
31
|
-
type AgentId = "zyfai" | "sail";
|
|
31
|
+
type AgentId = "zyfai" | "sail" | "surfliquid";
|
|
32
32
|
type Asset = string;
|
|
33
33
|
type AgentSupportedAsset = {
|
|
34
34
|
readonly symbol: string;
|
|
@@ -101,6 +101,12 @@ interface OwneyDepositResult {
|
|
|
101
101
|
}
|
|
102
102
|
interface OwneyMultiDepositResult {
|
|
103
103
|
agentResults: Record<string, OwneyDepositResult>;
|
|
104
|
+
/**
|
|
105
|
+
* Per-agent failure messages for agents that errored during a diversified
|
|
106
|
+
* deposit. Present only when at least one (but not all) agents failed —
|
|
107
|
+
* the deposit is partial, not total. Omitted when every agent succeeded.
|
|
108
|
+
*/
|
|
109
|
+
agentErrors?: Record<string, string>;
|
|
104
110
|
}
|
|
105
111
|
interface AgentWithdrawResult {
|
|
106
112
|
txHash?: string;
|
|
@@ -422,6 +428,17 @@ declare class OwneySDK {
|
|
|
422
428
|
private hasExistingBalance;
|
|
423
429
|
private validateAssetSupport;
|
|
424
430
|
private getEligibleAgents;
|
|
431
|
+
/**
|
|
432
|
+
* Agent ids the routing API provisioned for this org that support the given
|
|
433
|
+
* chain + asset, ordered by preference ({@link AGENT_ELIGIBILITY_ORDER},
|
|
434
|
+
* surfliquid first). Returns `[]` when the org has no compatible agent — never
|
|
435
|
+
* throws on an empty org. Loads agent keys on first call (apiKey only, no
|
|
436
|
+
* wallet), so the UI can resolve which agent to use before the user connects.
|
|
437
|
+
*
|
|
438
|
+
* This is the source of truth for agent availability: an agent appears here
|
|
439
|
+
* iff the routing API returned its key. No per-app feature flags.
|
|
440
|
+
*/
|
|
441
|
+
getEligibleAgentIds(chainId: number, asset: string): Promise<AgentId[]>;
|
|
425
442
|
/**
|
|
426
443
|
* Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
|
|
427
444
|
* Validates that the asset is supported by the target agent(s) on the active chain.
|
|
@@ -517,7 +534,7 @@ declare class OwneySDK {
|
|
|
517
534
|
getAllocationApy({ agentId, }?: AllocationApyOptions): Promise<OwneyAllocationApy>;
|
|
518
535
|
}
|
|
519
536
|
|
|
520
|
-
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" | "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";
|
|
537
|
+
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" | "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";
|
|
521
538
|
declare class OwneyError extends Error {
|
|
522
539
|
readonly code: OwneyErrorCode;
|
|
523
540
|
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),
|
|
@@ -1593,6 +1551,7 @@ var VIEM_CHAIN2 = {
|
|
|
1593
1551
|
42161: arbitrum2,
|
|
1594
1552
|
1: mainnet2
|
|
1595
1553
|
};
|
|
1554
|
+
var AGENT_ELIGIBILITY_ORDER = ["surfliquid", "zyfai", "sail"];
|
|
1596
1555
|
var SPONSORED_WETH_BY_CHAIN = {
|
|
1597
1556
|
8453: "0x4200000000000000000000000000000000000006",
|
|
1598
1557
|
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
@@ -1780,8 +1739,8 @@ var OwneySDK = class {
|
|
|
1780
1739
|
this.initializingAgentsPromise = (async () => {
|
|
1781
1740
|
const agentKeys = await fetchAgentKeys(this.apiKey);
|
|
1782
1741
|
this.disabledAgents.clear();
|
|
1783
|
-
for (const { key, agent_type, is_enabled } of agentKeys) {
|
|
1784
|
-
const agent = this.createAgent(agent_type, key);
|
|
1742
|
+
for (const { key, agent_type, project_name, is_enabled } of agentKeys) {
|
|
1743
|
+
const agent = await this.createAgent(agent_type, key, project_name);
|
|
1785
1744
|
if (!agent) continue;
|
|
1786
1745
|
this.agents.set(agent_type, agent);
|
|
1787
1746
|
if (is_enabled === false) {
|
|
@@ -1802,10 +1761,15 @@ var OwneySDK = class {
|
|
|
1802
1761
|
this.initializingAgentsPromise = null;
|
|
1803
1762
|
}
|
|
1804
1763
|
}
|
|
1805
|
-
createAgent(agentId, key) {
|
|
1764
|
+
async createAgent(agentId, key, projectName) {
|
|
1806
1765
|
if (agentId === "zyfai") {
|
|
1807
1766
|
return new ZyfaiAgent(key, this.zyfaiRpcUrls);
|
|
1808
1767
|
}
|
|
1768
|
+
if (agentId === "surfliquid") {
|
|
1769
|
+
if (!projectName) return null;
|
|
1770
|
+
const { SurfLiquidAgent } = await import("./surfliquid.agent-OMOYXWLP.js");
|
|
1771
|
+
return new SurfLiquidAgent({ projectName, appId: key });
|
|
1772
|
+
}
|
|
1809
1773
|
return null;
|
|
1810
1774
|
}
|
|
1811
1775
|
// --- Account lifecycle ---
|
|
@@ -1958,18 +1922,30 @@ var OwneySDK = class {
|
|
|
1958
1922
|
);
|
|
1959
1923
|
}
|
|
1960
1924
|
const agentResults = {};
|
|
1925
|
+
const agentErrors = {};
|
|
1961
1926
|
for (const { agent, amount: agentAmount } of agentAmounts) {
|
|
1962
|
-
|
|
1963
|
-
agent
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1927
|
+
try {
|
|
1928
|
+
agentResults[agent.id] = await this.depositWithFallback(
|
|
1929
|
+
agent,
|
|
1930
|
+
state,
|
|
1931
|
+
chainId,
|
|
1932
|
+
agentAmount,
|
|
1933
|
+
asset,
|
|
1934
|
+
effectiveCallback,
|
|
1935
|
+
depositCallback
|
|
1936
|
+
);
|
|
1937
|
+
} catch (error) {
|
|
1938
|
+
agentErrors[agent.id] = error instanceof Error ? error.message : String(error);
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
if (Object.keys(agentResults).length === 0) {
|
|
1942
|
+
throw new OwneyError(
|
|
1943
|
+
"DEPOSIT_ALL_FAILED",
|
|
1944
|
+
`All ${agentAmounts.length} agent deposit(s) failed.`,
|
|
1945
|
+
{ agentErrors }
|
|
1970
1946
|
);
|
|
1971
1947
|
}
|
|
1972
|
-
return { agentResults };
|
|
1948
|
+
return Object.keys(agentErrors).length > 0 ? { agentResults, agentErrors } : { agentResults };
|
|
1973
1949
|
}
|
|
1974
1950
|
/**
|
|
1975
1951
|
* Invokes `agent.deposit` with the resolved sponsored callback, composing
|
|
@@ -2126,6 +2102,34 @@ var OwneySDK = class {
|
|
|
2126
2102
|
}
|
|
2127
2103
|
return eligible;
|
|
2128
2104
|
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Agent ids the routing API provisioned for this org that support the given
|
|
2107
|
+
* chain + asset, ordered by preference ({@link AGENT_ELIGIBILITY_ORDER},
|
|
2108
|
+
* surfliquid first). Returns `[]` when the org has no compatible agent — never
|
|
2109
|
+
* throws on an empty org. Loads agent keys on first call (apiKey only, no
|
|
2110
|
+
* wallet), so the UI can resolve which agent to use before the user connects.
|
|
2111
|
+
*
|
|
2112
|
+
* This is the source of truth for agent availability: an agent appears here
|
|
2113
|
+
* iff the routing API returned its key. No per-app feature flags.
|
|
2114
|
+
*/
|
|
2115
|
+
async getEligibleAgentIds(chainId, asset) {
|
|
2116
|
+
try {
|
|
2117
|
+
await this.ensureAgentsInitialized();
|
|
2118
|
+
} catch (error) {
|
|
2119
|
+
if (error instanceof OwneyError && error.code === "API_NO_AGENTS") {
|
|
2120
|
+
return [];
|
|
2121
|
+
}
|
|
2122
|
+
throw error;
|
|
2123
|
+
}
|
|
2124
|
+
return [...this.agents.values()].filter((agent) => {
|
|
2125
|
+
const chainAssets = agent.supportedAssets.find(
|
|
2126
|
+
(sa) => sa.chainId === chainId
|
|
2127
|
+
);
|
|
2128
|
+
return chainAssets?.assets.some((a) => a.symbol === asset) ?? false;
|
|
2129
|
+
}).map((agent) => agent.id).sort(
|
|
2130
|
+
(a, b) => AGENT_ELIGIBILITY_ORDER.indexOf(a) - AGENT_ELIGIBILITY_ORDER.indexOf(b)
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2129
2133
|
// --- Fund operations ---
|
|
2130
2134
|
/**
|
|
2131
2135
|
* Withdraw funds from a specific agent, or all agents that support the active chain+asset if agentId is omitted.
|
|
@@ -2161,9 +2165,17 @@ var OwneySDK = class {
|
|
|
2161
2165
|
}
|
|
2162
2166
|
const eligibleAgents = this.getEligibleAgents(chainId, asset);
|
|
2163
2167
|
if (!amount) {
|
|
2168
|
+
const aggregated2 = await this.getBalances();
|
|
2169
|
+
const funded = projectAgentBalancesForAsset(
|
|
2170
|
+
eligibleAgents,
|
|
2171
|
+
aggregated2.agentBalances,
|
|
2172
|
+
chainId,
|
|
2173
|
+
asset,
|
|
2174
|
+
assetInfo.decimals
|
|
2175
|
+
).filter((b) => b.balance > 0n);
|
|
2164
2176
|
const results2 = {};
|
|
2165
2177
|
const agentErrors2 = {};
|
|
2166
|
-
for (const agent of
|
|
2178
|
+
for (const { agent } of funded) {
|
|
2167
2179
|
try {
|
|
2168
2180
|
results2[agent.id] = await agent.withdraw(state, chainId, token);
|
|
2169
2181
|
} catch (err) {
|
|
@@ -2180,9 +2192,10 @@ var OwneySDK = class {
|
|
|
2180
2192
|
{ asset, agentErrors: agentErrors2 }
|
|
2181
2193
|
);
|
|
2182
2194
|
}
|
|
2195
|
+
const totalWithdrawn = funded.filter(({ agent }) => results2[agent.id] !== void 0).reduce((sum, { balance }) => sum + balance, 0n);
|
|
2183
2196
|
return {
|
|
2184
2197
|
agentResult: results2,
|
|
2185
|
-
totalWithdrawn:
|
|
2198
|
+
totalWithdrawn: totalWithdrawn.toString()
|
|
2186
2199
|
};
|
|
2187
2200
|
}
|
|
2188
2201
|
const requested = BigInt(amount);
|