@owney/sdk 0.7.32-beta.11 → 0.7.32-beta.13
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 +615 -181
- package/dist/index.d.cts +71 -30
- package/dist/index.d.ts +71 -30
- package/dist/index.js +612 -178
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -246,10 +246,10 @@ function tokenBatchClear(key2, expected) {
|
|
|
246
246
|
}
|
|
247
247
|
function keys() {
|
|
248
248
|
if (typeof window === "undefined") return [...memory.keys()];
|
|
249
|
-
const
|
|
249
|
+
const storage11 = window.localStorage;
|
|
250
250
|
return Array.from(
|
|
251
|
-
{ length:
|
|
252
|
-
(_, i) =>
|
|
251
|
+
{ length: storage11.length },
|
|
252
|
+
(_, i) => storage11.key(i)
|
|
253
253
|
).filter((key2) => key2 !== null);
|
|
254
254
|
}
|
|
255
255
|
function pending(message = "The saved deposit could not be verified. Its existing transactions remain pending.") {
|
|
@@ -1389,6 +1389,46 @@ async function fetchProviderSnapshot(input) {
|
|
|
1389
1389
|
}
|
|
1390
1390
|
}
|
|
1391
1391
|
|
|
1392
|
+
// src/lib/announced-deposits.ts
|
|
1393
|
+
var KEY = "owney.announced-deposits.v1";
|
|
1394
|
+
var TTL_MS = 7 * 24 * 60 * 6e4;
|
|
1395
|
+
var MAX_ENTRIES = 256;
|
|
1396
|
+
var storage = () => {
|
|
1397
|
+
if (typeof window === "undefined") return null;
|
|
1398
|
+
try {
|
|
1399
|
+
return window.localStorage;
|
|
1400
|
+
} catch {
|
|
1401
|
+
return null;
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
function load(now) {
|
|
1405
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1406
|
+
try {
|
|
1407
|
+
const raw2 = storage()?.getItem(KEY);
|
|
1408
|
+
const parsed = raw2 ? JSON.parse(raw2) : null;
|
|
1409
|
+
if (parsed && typeof parsed === "object") {
|
|
1410
|
+
for (const [key2, at] of Object.entries(parsed)) {
|
|
1411
|
+
if (typeof at === "number" && Number.isFinite(at)) entries.set(key2, Math.max(entries.get(key2) ?? 0, at));
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
} catch {
|
|
1415
|
+
}
|
|
1416
|
+
for (const [key2, at] of entries) if (at + TTL_MS <= now) entries.delete(key2);
|
|
1417
|
+
return entries;
|
|
1418
|
+
}
|
|
1419
|
+
function wasDepositAnnounced(key2, now = Date.now()) {
|
|
1420
|
+
return load(now).has(key2);
|
|
1421
|
+
}
|
|
1422
|
+
function rememberAnnouncedDeposit(key2, now = Date.now()) {
|
|
1423
|
+
const entries = load(now);
|
|
1424
|
+
entries.set(key2, now);
|
|
1425
|
+
const kept = [...entries].sort((a, b) => a[1] - b[1]).slice(-MAX_ENTRIES);
|
|
1426
|
+
try {
|
|
1427
|
+
storage()?.setItem(KEY, JSON.stringify(Object.fromEntries(kept)));
|
|
1428
|
+
} catch {
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1392
1432
|
// src/lib/earnings-hold.ts
|
|
1393
1433
|
var EARNINGS_HOLD_CAP_MS = 24 * 60 * 6e4;
|
|
1394
1434
|
var REFRESH_INDEX_WINDOW_MS = 60 * 6e4;
|
|
@@ -1683,7 +1723,7 @@ var SnapshotHistory = class {
|
|
|
1683
1723
|
};
|
|
1684
1724
|
|
|
1685
1725
|
// src/lib/funding-ledger.ts
|
|
1686
|
-
var SDK_VERSION = "0.7.32-beta.
|
|
1726
|
+
var SDK_VERSION = "0.7.32-beta.13";
|
|
1687
1727
|
var SCOPE2 = "funding-ledger";
|
|
1688
1728
|
var REQUEST_TIMEOUT_MS2 = 5e3;
|
|
1689
1729
|
var RETRY_DELAYS_MS = [1e3, 4e3, 16e3];
|
|
@@ -2352,7 +2392,7 @@ function releaseWithdrawalReservationHold(cfg, operationId, holderToken, reason,
|
|
|
2352
2392
|
return track(holderRequest(cfg, operationId, "release", compact2({ holderToken, agents, reason }), RELEASE_RETRY_DELAYS_MS));
|
|
2353
2393
|
}
|
|
2354
2394
|
var memoryTokens = /* @__PURE__ */ new Map();
|
|
2355
|
-
function
|
|
2395
|
+
function storage2() {
|
|
2356
2396
|
try {
|
|
2357
2397
|
const store = globalThis.localStorage;
|
|
2358
2398
|
return store && typeof store.getItem === "function" ? store : null;
|
|
@@ -2376,7 +2416,7 @@ function saveHolderToken(operationId, holderToken, hardExpiresAt = Date.now() +
|
|
|
2376
2416
|
const entry = { token: holderToken, hardExpiresAt };
|
|
2377
2417
|
memoryTokens.set(key2, entry);
|
|
2378
2418
|
try {
|
|
2379
|
-
|
|
2419
|
+
storage2()?.setItem(key2, JSON.stringify(entry));
|
|
2380
2420
|
} catch {
|
|
2381
2421
|
}
|
|
2382
2422
|
}
|
|
@@ -2384,7 +2424,7 @@ function loadHolderToken(operationId, now = Date.now()) {
|
|
|
2384
2424
|
const key2 = STORAGE_PREFIX + operationId.toLowerCase();
|
|
2385
2425
|
let entry;
|
|
2386
2426
|
try {
|
|
2387
|
-
entry = parseStored(
|
|
2427
|
+
entry = parseStored(storage2()?.getItem(key2));
|
|
2388
2428
|
} catch {
|
|
2389
2429
|
}
|
|
2390
2430
|
entry ??= memoryTokens.get(key2);
|
|
@@ -2399,14 +2439,14 @@ function deleteHolderToken(operationId) {
|
|
|
2399
2439
|
const key2 = STORAGE_PREFIX + operationId.toLowerCase();
|
|
2400
2440
|
memoryTokens.delete(key2);
|
|
2401
2441
|
try {
|
|
2402
|
-
|
|
2442
|
+
storage2()?.removeItem(key2);
|
|
2403
2443
|
} catch {
|
|
2404
2444
|
}
|
|
2405
2445
|
}
|
|
2406
2446
|
function sweepHolderTokens(now = Date.now()) {
|
|
2407
2447
|
for (const [key2, entry] of memoryTokens) if (entry.hardExpiresAt <= now) memoryTokens.delete(key2);
|
|
2408
2448
|
try {
|
|
2409
|
-
const store =
|
|
2449
|
+
const store = storage2();
|
|
2410
2450
|
if (!store) return;
|
|
2411
2451
|
const keys2 = [];
|
|
2412
2452
|
for (let i = 0; i < store.length; i++) {
|
|
@@ -4267,7 +4307,7 @@ init_errors();
|
|
|
4267
4307
|
|
|
4268
4308
|
// src/agents/zyfai/zyfai.auth-cache.ts
|
|
4269
4309
|
var KEY_PREFIX = "owney.zyfai.session";
|
|
4270
|
-
var
|
|
4310
|
+
var storage3 = () => {
|
|
4271
4311
|
if (typeof window === "undefined") return null;
|
|
4272
4312
|
try {
|
|
4273
4313
|
return window.localStorage;
|
|
@@ -4324,7 +4364,7 @@ var readLegacySession = (store, address) => {
|
|
|
4324
4364
|
var readSession = (address, _chainId) => {
|
|
4325
4365
|
if (typeof window === "undefined") return null;
|
|
4326
4366
|
const key2 = buildKey(address);
|
|
4327
|
-
const store =
|
|
4367
|
+
const store = storage3();
|
|
4328
4368
|
let raw2 = null;
|
|
4329
4369
|
try {
|
|
4330
4370
|
raw2 = store?.getItem(key2) ?? null;
|
|
@@ -4358,7 +4398,7 @@ var writeSession = (address, _chainId, session) => {
|
|
|
4358
4398
|
if (typeof window === "undefined") return;
|
|
4359
4399
|
const key2 = buildKey(address);
|
|
4360
4400
|
memorySessions.set(key2, session);
|
|
4361
|
-
const store =
|
|
4401
|
+
const store = storage3();
|
|
4362
4402
|
try {
|
|
4363
4403
|
store?.setItem(key2, JSON.stringify(session));
|
|
4364
4404
|
} catch {
|
|
@@ -4367,7 +4407,7 @@ var writeSession = (address, _chainId, session) => {
|
|
|
4367
4407
|
var clearSession = (address, _chainId) => {
|
|
4368
4408
|
const key2 = buildKey(address);
|
|
4369
4409
|
memorySessions.delete(key2);
|
|
4370
|
-
const store =
|
|
4410
|
+
const store = storage3();
|
|
4371
4411
|
try {
|
|
4372
4412
|
store?.removeItem(key2);
|
|
4373
4413
|
} catch {
|
|
@@ -4379,8 +4419,11 @@ var clearSession = (address, _chainId) => {
|
|
|
4379
4419
|
function buildAutoSelectUpdate(current, asset, chainId) {
|
|
4380
4420
|
const chains = current.chains ?? [];
|
|
4381
4421
|
const chainMissing = chainId !== void 0 && !chains.includes(chainId);
|
|
4382
|
-
if (current.autoSelectProtocols === true && !chainMissing) return null;
|
|
4383
4422
|
const nextChains = chainMissing ? [...chains, chainId] : chains;
|
|
4423
|
+
if (current.savedPoolChoices) {
|
|
4424
|
+
return chainMissing ? { asset, chains: nextChains } : null;
|
|
4425
|
+
}
|
|
4426
|
+
if (current.autoSelectProtocols === true && !chainMissing) return null;
|
|
4384
4427
|
return {
|
|
4385
4428
|
asset,
|
|
4386
4429
|
autoSelectProtocols: true,
|
|
@@ -4530,11 +4573,107 @@ function protocolsPolicyNeedsUpdate(current, desiredProtocols, desiredAutoSelect
|
|
|
4530
4573
|
}
|
|
4531
4574
|
function mergeScopedPoolNames(current, scoped, allAvailableNames) {
|
|
4532
4575
|
const managed = new Set(scoped.flatMap((entry) => entry.availablePools));
|
|
4576
|
+
const offered = new Set(allAvailableNames);
|
|
4533
4577
|
const existing = current.autoselect ? allAvailableNames : current.pools;
|
|
4534
|
-
const preserved = existing.filter(
|
|
4578
|
+
const preserved = existing.filter(
|
|
4579
|
+
(name) => !managed.has(name) && (offered.size === 0 || offered.has(name))
|
|
4580
|
+
);
|
|
4535
4581
|
const selected = scoped.flatMap((entry) => entry.pools);
|
|
4536
4582
|
return [.../* @__PURE__ */ new Set([...preserved, ...selected])];
|
|
4537
4583
|
}
|
|
4584
|
+
function savedPoolRecords(customization, protocolId, chainId) {
|
|
4585
|
+
if (!customization || typeof customization !== "object") return [];
|
|
4586
|
+
const records = [];
|
|
4587
|
+
for (const byProtocol of Object.values(customization)) {
|
|
4588
|
+
const byChain = byProtocol?.[protocolId];
|
|
4589
|
+
const record2 = byChain?.[String(chainId)];
|
|
4590
|
+
if (!record2 || typeof record2 !== "object") continue;
|
|
4591
|
+
records.push({
|
|
4592
|
+
pools: Array.isArray(record2.pools) ? record2.pools.filter((name) => typeof name === "string") : [],
|
|
4593
|
+
autoselect: typeof record2.autoselect === "boolean" ? record2.autoselect : void 0
|
|
4594
|
+
});
|
|
4595
|
+
}
|
|
4596
|
+
return records;
|
|
4597
|
+
}
|
|
4598
|
+
function hasManualPoolChoices(customization) {
|
|
4599
|
+
return manuallyChosenProtocols(customization).size > 0;
|
|
4600
|
+
}
|
|
4601
|
+
function manuallyChosenProtocols(customization) {
|
|
4602
|
+
const chosen = /* @__PURE__ */ new Set();
|
|
4603
|
+
if (!customization || typeof customization !== "object") return chosen;
|
|
4604
|
+
for (const byProtocol of Object.values(customization)) {
|
|
4605
|
+
for (const [protocolId, byChain] of Object.entries(byProtocol ?? {})) {
|
|
4606
|
+
const manual = Object.values(byChain ?? {}).some(
|
|
4607
|
+
(record2) => record2?.autoselect === false
|
|
4608
|
+
);
|
|
4609
|
+
if (manual) chosen.add(protocolId);
|
|
4610
|
+
}
|
|
4611
|
+
}
|
|
4612
|
+
return chosen;
|
|
4613
|
+
}
|
|
4614
|
+
function manualChainsOf(customization, protocolId) {
|
|
4615
|
+
if (!customization || typeof customization !== "object") return [];
|
|
4616
|
+
const chains = /* @__PURE__ */ new Set();
|
|
4617
|
+
for (const byProtocol of Object.values(customization)) {
|
|
4618
|
+
const byChain = byProtocol?.[protocolId];
|
|
4619
|
+
for (const [chainKey, record2] of Object.entries(byChain ?? {})) {
|
|
4620
|
+
const chainId = Number(chainKey);
|
|
4621
|
+
if (Number.isFinite(chainId) && record2?.autoselect === false) {
|
|
4622
|
+
chains.add(chainId);
|
|
4623
|
+
}
|
|
4624
|
+
}
|
|
4625
|
+
}
|
|
4626
|
+
return [...chains];
|
|
4627
|
+
}
|
|
4628
|
+
function protocolsSyncLeavesOff(customization, available, assetChains) {
|
|
4629
|
+
const off = /* @__PURE__ */ new Set();
|
|
4630
|
+
for (const protocol of available) {
|
|
4631
|
+
const chains = (protocol.chains ?? []).filter((chainId) => assetChains.includes(chainId));
|
|
4632
|
+
if (chains.length === 0) continue;
|
|
4633
|
+
const decided = chains.every((chainId) => {
|
|
4634
|
+
const records = savedPoolRecords(customization, protocol.id, chainId);
|
|
4635
|
+
return records.length > 0 && !savedRecordsAreAuto(records);
|
|
4636
|
+
});
|
|
4637
|
+
if (decided) off.add(protocol.id);
|
|
4638
|
+
}
|
|
4639
|
+
return off;
|
|
4640
|
+
}
|
|
4641
|
+
function tokenIsAsset(token, asset) {
|
|
4642
|
+
const upper = token.toUpperCase();
|
|
4643
|
+
return asset === "WETH" ? upper === "WETH" || upper === "ETH" : upper === asset;
|
|
4644
|
+
}
|
|
4645
|
+
function savedRecordsAreAuto(records) {
|
|
4646
|
+
return records.length === 0 || records.some((record2) => record2.autoselect !== false);
|
|
4647
|
+
}
|
|
4648
|
+
function protocolsToKeep(params) {
|
|
4649
|
+
const { asset, chains, customization, catalogs } = params;
|
|
4650
|
+
const entries = params.selections.filter(
|
|
4651
|
+
(entry) => entry.asset === asset && entry.availablePools.length > 0
|
|
4652
|
+
);
|
|
4653
|
+
const picked = entries.filter((entry) => entry.pools.length > 0).map((entry) => entry.protocolId);
|
|
4654
|
+
const candidates = [.../* @__PURE__ */ new Set([...params.current, ...picked])];
|
|
4655
|
+
const inUse = (protocolId) => {
|
|
4656
|
+
if (picked.includes(protocolId)) return true;
|
|
4657
|
+
const catalog = catalogs.get(protocolId);
|
|
4658
|
+
if (!catalog || catalog.length === 0) return true;
|
|
4659
|
+
const covered = new Set(
|
|
4660
|
+
entries.filter((entry) => entry.protocolId === protocolId).map((entry) => entry.chainId)
|
|
4661
|
+
);
|
|
4662
|
+
const assetChains = new Set(chains);
|
|
4663
|
+
const toCheck = [.../* @__PURE__ */ new Set([...chains, ...manualChainsOf(customization, protocolId)])];
|
|
4664
|
+
return toCheck.some((chainId) => {
|
|
4665
|
+
if (covered.has(chainId)) return false;
|
|
4666
|
+
const offered = new Set(
|
|
4667
|
+
catalog.filter((pool) => pool.chainId === chainId && tokenIsAsset(pool.token, asset)).map((pool) => pool.name)
|
|
4668
|
+
);
|
|
4669
|
+
if (offered.size === 0) return false;
|
|
4670
|
+
const records = savedPoolRecords(customization, protocolId, chainId);
|
|
4671
|
+
return assetChains.has(chainId) && savedRecordsAreAuto(records) || records.some((record2) => record2.autoselect === false && record2.pools.some((name) => offered.has(name)));
|
|
4672
|
+
});
|
|
4673
|
+
};
|
|
4674
|
+
const kept = candidates.filter(inUse);
|
|
4675
|
+
return kept.length > 0 ? kept : candidates;
|
|
4676
|
+
}
|
|
4538
4677
|
function mapAvailablePools(raw2) {
|
|
4539
4678
|
const byChain = raw2 ?? {};
|
|
4540
4679
|
if (typeof byChain !== "object" || byChain === null) return [];
|
|
@@ -4863,6 +5002,8 @@ async function withPaidRpcDiagnostics(operation, chainId, rpcMethod, agentId) {
|
|
|
4863
5002
|
var ERC7579_IS_MODULE_INSTALLED_ABI = (0, import_viem10.parseAbi)([
|
|
4864
5003
|
"function isModuleInstalled(uint256 moduleTypeId, address module, bytes additionalContext) view returns (bool)"
|
|
4865
5004
|
]);
|
|
5005
|
+
var ZYFAI_SIGN_IN_REQUIRED_MESSAGE = "No Zyfai sign-in is available without a prompt.";
|
|
5006
|
+
var isSignInFailure = (error) => error instanceof OwneyError && error.code === "AGENT_AUTH_FAILED";
|
|
4866
5007
|
var WETH_ADDRESS_BY_CHAIN = {
|
|
4867
5008
|
8453: "0x4200000000000000000000000000000000000006",
|
|
4868
5009
|
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
@@ -4977,6 +5118,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4977
5118
|
}
|
|
4978
5119
|
];
|
|
4979
5120
|
sdk;
|
|
5121
|
+
signInRefusedListener;
|
|
4980
5122
|
connectedAddress = null;
|
|
4981
5123
|
connectedChainId = null;
|
|
4982
5124
|
smartWalletCache = /* @__PURE__ */ new Map();
|
|
@@ -4991,6 +5133,12 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4991
5133
|
reportedAccounts = /* @__PURE__ */ new Set();
|
|
4992
5134
|
connectAuthPromise = null;
|
|
4993
5135
|
connectAuthScope = null;
|
|
5136
|
+
/** Whether `connectAuthPromise` is a read's connect, which never signs. */
|
|
5137
|
+
connectAuthPromptless = false;
|
|
5138
|
+
/** Vendor clients that may not sign in: one connecting for a read, and one
|
|
5139
|
+
* whose session a read dropped (the next connect replaces it). Their sign-in
|
|
5140
|
+
* uses the saved session or fails. */
|
|
5141
|
+
promptlessSdks = /* @__PURE__ */ new WeakSet();
|
|
4994
5142
|
connectionGeneration = 0;
|
|
4995
5143
|
sdkHasConnected = false;
|
|
4996
5144
|
rpcUrls;
|
|
@@ -5171,6 +5319,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5171
5319
|
return;
|
|
5172
5320
|
}
|
|
5173
5321
|
}
|
|
5322
|
+
if (this.promptlessSdks.has(sdk)) throw this.signInRequired();
|
|
5174
5323
|
await original();
|
|
5175
5324
|
const newAddress = internals.walletClient?.account?.address;
|
|
5176
5325
|
const newChainId = internals.currentChainId ?? 0;
|
|
@@ -5216,18 +5365,35 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5216
5365
|
if (this.connectedAddress?.toLowerCase() === owner && this.connectedChainId === chainId) return false;
|
|
5217
5366
|
return readSession(state.walletAddress, chainId) === null;
|
|
5218
5367
|
}
|
|
5219
|
-
/**
|
|
5368
|
+
/** A read (promptless state) needs a sign-in it may not ask for. */
|
|
5369
|
+
signInRequired() {
|
|
5370
|
+
return new OwneyError(
|
|
5371
|
+
"AGENT_AUTH_FAILED",
|
|
5372
|
+
ZYFAI_SIGN_IN_REQUIRED_MESSAGE,
|
|
5373
|
+
{ reason: "ZYFAI_SIGN_IN_REQUIRED" },
|
|
5374
|
+
this.id
|
|
5375
|
+
);
|
|
5376
|
+
}
|
|
5377
|
+
/**
|
|
5378
|
+
* Light connect: SIWE auth only. Re-auths if chain changed. Under a
|
|
5379
|
+
* promptless state (a read) it connects with the saved session only and
|
|
5380
|
+
* never opens the wallet's sign-in prompt: with no saved session it fails
|
|
5381
|
+
* at once with `ZYFAI_SIGN_IN_REQUIRED`.
|
|
5382
|
+
*/
|
|
5220
5383
|
async connectAuth(state, chainId) {
|
|
5221
5384
|
const validChainId = isValidChainId(chainId);
|
|
5222
5385
|
const owner = state.walletAddress.toLowerCase();
|
|
5223
5386
|
const scope = `${owner}:${validChainId}`;
|
|
5387
|
+
const promptless = state.promptless === true;
|
|
5224
5388
|
if (this.connectedAddress?.toLowerCase() === owner && this.connectedChainId === validChainId) {
|
|
5225
5389
|
return;
|
|
5226
5390
|
}
|
|
5227
5391
|
if (this.connectAuthPromise && this.connectAuthScope === scope) {
|
|
5228
|
-
await this.connectAuthPromise;
|
|
5392
|
+
if (this.connectAuthPromptless && !promptless) await this.connectAuthPromise.catch(() => void 0);
|
|
5393
|
+
else await this.connectAuthPromise;
|
|
5229
5394
|
return this.connectAuth(state, chainId);
|
|
5230
5395
|
}
|
|
5396
|
+
if (promptless && readSession(state.walletAddress, validChainId) === null) throw this.signInRequired();
|
|
5231
5397
|
if (this.sdkHasConnected || this.connectedAddress) this.sdk = this.createSdk();
|
|
5232
5398
|
this.sdkHasConnected = true;
|
|
5233
5399
|
const executionSdk = this.sdk;
|
|
@@ -5240,7 +5406,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5240
5406
|
const address = await this.connectAccountWithRetry(
|
|
5241
5407
|
state.provider,
|
|
5242
5408
|
validChainId,
|
|
5243
|
-
executionSdk
|
|
5409
|
+
executionSdk,
|
|
5410
|
+
promptless
|
|
5244
5411
|
);
|
|
5245
5412
|
if (generation !== this.connectionGeneration || address.toLowerCase() !== owner)
|
|
5246
5413
|
throw new OwneyError("NOT_CONNECTED", "Wallet changed while connecting Zyfai.", void 0, this.id);
|
|
@@ -5249,12 +5416,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5249
5416
|
})();
|
|
5250
5417
|
this.connectAuthPromise = pending2;
|
|
5251
5418
|
this.connectAuthScope = scope;
|
|
5419
|
+
this.connectAuthPromptless = promptless;
|
|
5252
5420
|
try {
|
|
5253
5421
|
await pending2;
|
|
5254
5422
|
} finally {
|
|
5255
5423
|
if (this.connectAuthPromise === pending2) {
|
|
5256
5424
|
this.connectAuthPromise = null;
|
|
5257
5425
|
this.connectAuthScope = null;
|
|
5426
|
+
this.connectAuthPromptless = false;
|
|
5258
5427
|
}
|
|
5259
5428
|
}
|
|
5260
5429
|
}
|
|
@@ -5267,19 +5436,86 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5267
5436
|
* which does not separate a revoked JWT from a misconfigured API key; we
|
|
5268
5437
|
* retry once either way, and if the second attempt still fails the original
|
|
5269
5438
|
* error propagates.
|
|
5439
|
+
*
|
|
5440
|
+
* `promptless` (a read): the saved session only. The patched
|
|
5441
|
+
* `authenticateUser` will not fall back to the SIWE prompt for this client,
|
|
5442
|
+
* and a refused session is dropped without a retry
|
|
5443
|
+
* (`dropRefusedReadSession`); the next sign-in is the user's.
|
|
5270
5444
|
*/
|
|
5271
|
-
async connectAccountWithRetry(provider, chainId, executionSdk = this.sdk) {
|
|
5445
|
+
async connectAccountWithRetry(provider, chainId, executionSdk = this.sdk, promptless = false) {
|
|
5446
|
+
if (promptless) this.promptlessSdks.add(executionSdk);
|
|
5272
5447
|
try {
|
|
5273
|
-
|
|
5448
|
+
const address = await executionSdk.connectAccount(provider, chainId);
|
|
5449
|
+
this.promptlessSdks.delete(executionSdk);
|
|
5450
|
+
return address;
|
|
5274
5451
|
} catch (error) {
|
|
5275
5452
|
const message = error instanceof Error ? error.message : String(error);
|
|
5276
5453
|
if (!message.toLowerCase().includes("unauthorized")) throw error;
|
|
5277
5454
|
const internals = executionSdk;
|
|
5278
5455
|
const address = internals.walletClient?.account?.address;
|
|
5456
|
+
if (promptless) throw this.dropRefusedReadSession(address, executionSdk, internals.httpClient.authToken, message);
|
|
5279
5457
|
if (address) clearSession(address, chainId);
|
|
5280
5458
|
return await executionSdk.connectAccount(provider, chainId);
|
|
5281
5459
|
}
|
|
5282
5460
|
}
|
|
5461
|
+
setSignInRefusedListener(listener) {
|
|
5462
|
+
this.signInRefusedListener = listener;
|
|
5463
|
+
}
|
|
5464
|
+
/** A saved session was dropped because Zyfai refused it (not during connect). */
|
|
5465
|
+
tellSignInRefused() {
|
|
5466
|
+
try {
|
|
5467
|
+
this.signInRefusedListener?.();
|
|
5468
|
+
} catch {
|
|
5469
|
+
}
|
|
5470
|
+
}
|
|
5471
|
+
/**
|
|
5472
|
+
* Zyfai refused the session a read used (HTTP 401): the one place a read
|
|
5473
|
+
* drops a refused session. The saved session is cleared unless it was
|
|
5474
|
+
* renewed meanwhile, and the client stops using its token and may no longer
|
|
5475
|
+
* sign in, so no read reuses the session or signs in again: reads now need
|
|
5476
|
+
* a sign-in (`ensureReadSession` sees no live session), and the next one is
|
|
5477
|
+
* the user's (connect, deposit, withdraw), on a new client. Returns the
|
|
5478
|
+
* read's error.
|
|
5479
|
+
*/
|
|
5480
|
+
dropRefusedReadSession(owner, executionSdk, authToken, refusal) {
|
|
5481
|
+
debugLog("zyfai:auth", "a read's session was refused; dropped without signing in again", { refusal });
|
|
5482
|
+
if (owner && typeof authToken === "string") {
|
|
5483
|
+
let dropped = false;
|
|
5484
|
+
if (readSession(owner, 0)?.token === authToken) {
|
|
5485
|
+
clearSession(owner, 0);
|
|
5486
|
+
dropped = true;
|
|
5487
|
+
}
|
|
5488
|
+
const internals = executionSdk;
|
|
5489
|
+
if (internals.httpClient.authToken === authToken) {
|
|
5490
|
+
dropped = true;
|
|
5491
|
+
internals.httpClient.clearAuthToken();
|
|
5492
|
+
internals.authenticatedUserId = null;
|
|
5493
|
+
this.promptlessSdks.add(executionSdk);
|
|
5494
|
+
if (executionSdk === this.sdk && this.connectedAddress?.toLowerCase() === owner.toLowerCase())
|
|
5495
|
+
this.connectedChainId = null;
|
|
5496
|
+
}
|
|
5497
|
+
if (dropped) this.tellSignInRefused();
|
|
5498
|
+
}
|
|
5499
|
+
return this.signInRequired();
|
|
5500
|
+
}
|
|
5501
|
+
/**
|
|
5502
|
+
* One data call of a read, on `executionSdk`. Under a promptless state a
|
|
5503
|
+
* session Zyfai refuses (`isZyfaiSessionRejected`) is dropped
|
|
5504
|
+
* (`dropRefusedReadSession`) and the read fails with
|
|
5505
|
+
* `ZYFAI_SIGN_IN_REQUIRED`, never signing in again.
|
|
5506
|
+
*/
|
|
5507
|
+
async readCall(state, call, executionSdk = this.sdk) {
|
|
5508
|
+
const authToken = executionSdk.httpClient?.authToken;
|
|
5509
|
+
try {
|
|
5510
|
+
return await call();
|
|
5511
|
+
} catch (error) {
|
|
5512
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
5513
|
+
if (state.promptless !== true || error instanceof OwneyError) throw error;
|
|
5514
|
+
if (message.includes(ZYFAI_SIGN_IN_REQUIRED_MESSAGE)) throw this.signInRequired();
|
|
5515
|
+
if (!isZyfaiSessionRejected(message)) throw error;
|
|
5516
|
+
throw this.dropRefusedReadSession(state.walletAddress, executionSdk, authToken, message);
|
|
5517
|
+
}
|
|
5518
|
+
}
|
|
5283
5519
|
/**
|
|
5284
5520
|
* Reconnect if the Zyfai connection was torn down behind our back: a
|
|
5285
5521
|
* chain/account switch fires the provider's `accountsChanged` →
|
|
@@ -5317,6 +5553,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5317
5553
|
internals.httpClient.clearAuthToken();
|
|
5318
5554
|
internals.authenticatedUserId = null;
|
|
5319
5555
|
this.connectedChainId = null;
|
|
5556
|
+
this.tellSignInRefused();
|
|
5320
5557
|
}
|
|
5321
5558
|
/**
|
|
5322
5559
|
* Sync newly-available protocols onto an existing user's profile at wallet
|
|
@@ -5348,7 +5585,16 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5348
5585
|
);
|
|
5349
5586
|
return;
|
|
5350
5587
|
}
|
|
5351
|
-
const
|
|
5588
|
+
const decided = protocolsSyncLeavesOff(
|
|
5589
|
+
current.customization,
|
|
5590
|
+
available,
|
|
5591
|
+
current.chains ?? []
|
|
5592
|
+
);
|
|
5593
|
+
const update = buildProtocolMergeUpdate(
|
|
5594
|
+
available.filter((protocol) => !decided.has(protocol.id)),
|
|
5595
|
+
current,
|
|
5596
|
+
asset
|
|
5597
|
+
);
|
|
5352
5598
|
if (!update) return;
|
|
5353
5599
|
await this.sdk.updateUserProfile(update);
|
|
5354
5600
|
debugLog("zyfai:protocol-sync", `${asset}: wrote profile update`, update);
|
|
@@ -5368,11 +5614,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5368
5614
|
* per chain, in parallel) cancel each other's sign-in. Funding keeps
|
|
5369
5615
|
* `connectAuth`/`ensureConnected`. Returns the owner verified for this call,
|
|
5370
5616
|
* so a later reconnect cannot leave the caller without an address.
|
|
5617
|
+
* The client reads under a promptless state, so with no live session this
|
|
5618
|
+
* connects from the saved one or fails without a prompt (`connectAuth`).
|
|
5371
5619
|
*/
|
|
5372
5620
|
async ensureReadSession(state, chainId) {
|
|
5373
5621
|
const owner = state.walletAddress?.toLowerCase();
|
|
5374
5622
|
if (this.connectAuthPromise) await this.connectAuthPromise.catch(() => void 0);
|
|
5375
|
-
if (!owner || this.connectedAddress?.toLowerCase() !== owner
|
|
5623
|
+
if (!owner || this.connectedAddress?.toLowerCase() !== owner || this.connectedChainId === null)
|
|
5624
|
+
await this.connectAuth(state, chainId);
|
|
5376
5625
|
}
|
|
5377
5626
|
/** `ensureReadSession`, then the owner it verified, read in the same turn. */
|
|
5378
5627
|
async connectForRead(state, chainId) {
|
|
@@ -5406,7 +5655,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5406
5655
|
return pending2;
|
|
5407
5656
|
}
|
|
5408
5657
|
// --- IAgent: Connection lifecycle ---
|
|
5409
|
-
async disconnect() {
|
|
5658
|
+
async disconnect(options) {
|
|
5410
5659
|
const executionSdk = this.sdk;
|
|
5411
5660
|
this.connectionGeneration++;
|
|
5412
5661
|
this.earningsGeneration++;
|
|
@@ -5419,7 +5668,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5419
5668
|
this.holdActiveScopes.clear();
|
|
5420
5669
|
this.pendingRegistrations.clear();
|
|
5421
5670
|
this.lastGoodEarnings.clear();
|
|
5422
|
-
if (this.connectedAddress && this.connectedChainId !== null) {
|
|
5671
|
+
if (!options?.keepSignIns && this.connectedAddress && this.connectedChainId !== null) {
|
|
5423
5672
|
clearSession(this.connectedAddress, this.connectedChainId);
|
|
5424
5673
|
}
|
|
5425
5674
|
this.connectedAddress = null;
|
|
@@ -5687,14 +5936,23 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5687
5936
|
group.push(entry);
|
|
5688
5937
|
byPair.set(pair, group);
|
|
5689
5938
|
}
|
|
5939
|
+
const catalogReads = /* @__PURE__ */ new Map();
|
|
5940
|
+
const catalogOf = (protocolId) => {
|
|
5941
|
+
let read2 = catalogReads.get(protocolId);
|
|
5942
|
+
if (!read2) {
|
|
5943
|
+
read2 = this.sdk.getAvailablePools(protocolId, "yieldmaxxing").then(mapAvailablePools);
|
|
5944
|
+
catalogReads.set(protocolId, read2);
|
|
5945
|
+
}
|
|
5946
|
+
return read2;
|
|
5947
|
+
};
|
|
5690
5948
|
const customizations = await Promise.all(
|
|
5691
5949
|
[...byPair.values()].map(async (scoped) => {
|
|
5692
5950
|
const { protocolId, chainId } = scoped[0];
|
|
5693
|
-
const [current,
|
|
5951
|
+
const [current, catalog] = await Promise.all([
|
|
5694
5952
|
this.sdk.getSelectedPools(protocolId, chainId),
|
|
5695
|
-
|
|
5953
|
+
catalogOf(protocolId)
|
|
5696
5954
|
]);
|
|
5697
|
-
const allAvailableNames =
|
|
5955
|
+
const allAvailableNames = catalog.filter((pool) => pool.chainId === chainId).map((pool) => pool.name);
|
|
5698
5956
|
return {
|
|
5699
5957
|
protocolId,
|
|
5700
5958
|
chainId,
|
|
@@ -5718,13 +5976,25 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5718
5976
|
await Promise.all(
|
|
5719
5977
|
selection.strategies.map(async ({ asset, strategy }) => {
|
|
5720
5978
|
const current = await this.sdk.getUserDetails(asset);
|
|
5721
|
-
const
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5979
|
+
const listed = current.protocols ?? [];
|
|
5980
|
+
const unpicked = listed.filter((protocolId) => !selection.selections.some(
|
|
5981
|
+
(entry) => entry.asset === asset && entry.protocolId === protocolId && entry.pools.length > 0
|
|
5982
|
+
));
|
|
5983
|
+
const catalogs = new Map(await Promise.all(unpicked.map(async (protocolId) => [protocolId, await catalogOf(protocolId).catch(() => null)])));
|
|
5984
|
+
const protocols = protocolsToKeep({
|
|
5985
|
+
asset,
|
|
5986
|
+
current: listed,
|
|
5987
|
+
chains: current.chains ?? [],
|
|
5988
|
+
selections: selection.selections,
|
|
5989
|
+
customization: current.customization,
|
|
5990
|
+
catalogs
|
|
5991
|
+
});
|
|
5992
|
+
await this.sdk.updateUserProfile({
|
|
5993
|
+
asset,
|
|
5994
|
+
strategy,
|
|
5995
|
+
protocols,
|
|
5996
|
+
autoSelectProtocols: false
|
|
5997
|
+
});
|
|
5728
5998
|
})
|
|
5729
5999
|
);
|
|
5730
6000
|
} catch (error) {
|
|
@@ -5797,13 +6067,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5797
6067
|
Promise.all(
|
|
5798
6068
|
params.pairs.map(async ({ protocolId, chainId: chainId2 }) => {
|
|
5799
6069
|
try {
|
|
5800
|
-
const current = await this.sdk.getSelectedPools(
|
|
6070
|
+
const current = await this.readCall(state, () => this.sdk.getSelectedPools(
|
|
5801
6071
|
protocolId,
|
|
5802
6072
|
chainId2
|
|
5803
|
-
);
|
|
6073
|
+
));
|
|
5804
6074
|
if (current.autoselect) return null;
|
|
5805
6075
|
return { protocolId, chainId: chainId2, pools: current.pools ?? [] };
|
|
5806
|
-
} catch {
|
|
6076
|
+
} catch (error) {
|
|
6077
|
+
if (isSignInFailure(error)) throw error;
|
|
5807
6078
|
return null;
|
|
5808
6079
|
}
|
|
5809
6080
|
})
|
|
@@ -5811,9 +6082,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5811
6082
|
Promise.all(
|
|
5812
6083
|
params.assets.map(async (asset) => {
|
|
5813
6084
|
try {
|
|
5814
|
-
const current = await this.sdk.getUserDetails(asset);
|
|
6085
|
+
const current = await this.readCall(state, () => this.sdk.getUserDetails(asset));
|
|
5815
6086
|
return current.strategy ? { asset, strategy: current.strategy } : null;
|
|
5816
|
-
} catch {
|
|
6087
|
+
} catch (error) {
|
|
6088
|
+
if (isSignInFailure(error)) throw error;
|
|
5817
6089
|
return null;
|
|
5818
6090
|
}
|
|
5819
6091
|
})
|
|
@@ -7206,7 +7478,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7206
7478
|
const requestedAt = Date.now();
|
|
7207
7479
|
const generation = this.earningsGeneration;
|
|
7208
7480
|
const { smartWallet, chainId: validChainId } = await this.resolveSmartWallet(state, chainId);
|
|
7209
|
-
const raw2 = await this.sdk.getPortfolio(this.getAddress());
|
|
7481
|
+
const raw2 = await this.readCall(state, () => this.sdk.getPortfolio(this.getAddress()));
|
|
7210
7482
|
debugLog("zyfai:balances", "read", { ms: Date.now() - requestedAt });
|
|
7211
7483
|
const balance = mapBalances(raw2, validChainId, smartWallet);
|
|
7212
7484
|
const reads = balance.readMetadata?.map((read2) => ({ ...read2, requestedAt })) ?? [];
|
|
@@ -7268,7 +7540,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7268
7540
|
async getEarnings(state, chainId) {
|
|
7269
7541
|
const { smartWallet } = await this.resolveSmartWallet(state, chainId);
|
|
7270
7542
|
const key2 = this.earningsKey(state, chainId, smartWallet);
|
|
7271
|
-
const raw2 = await this.readEarnings(key2, smartWallet);
|
|
7543
|
+
const raw2 = await this.readCall(state, () => this.readEarnings(key2, smartWallet));
|
|
7272
7544
|
const held = await this.holdEarnings(state, chainId, smartWallet, key2, raw2);
|
|
7273
7545
|
if (held.active) void this.refreshEarnings(state, chainId).catch(() => void 0);
|
|
7274
7546
|
return mapEarnings(held.value, smartWallet);
|
|
@@ -7419,7 +7691,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7419
7691
|
if (existing) return existing;
|
|
7420
7692
|
const pending2 = (async () => {
|
|
7421
7693
|
const recent = this.earningsSnapshot;
|
|
7422
|
-
const current = recent?.key === key2 && Date.now() - recent.at < 5e3 ? recent.raw : await this.readEarnings(key2, smartWallet);
|
|
7694
|
+
const current = recent?.key === key2 && Date.now() - recent.at < 5e3 ? recent.raw : await this.readCall(state, () => this.readEarnings(key2, smartWallet), executionSdk);
|
|
7423
7695
|
const lastCheck = current.data.lastCheckTimestamp ? Date.parse(current.data.lastCheckTimestamp) : Number.NaN;
|
|
7424
7696
|
const mapped = mapEarnings(current, smartWallet);
|
|
7425
7697
|
const held = await this.holdEarnings(state, chainId, smartWallet, key2, current);
|
|
@@ -7433,7 +7705,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7433
7705
|
if (isFresh && !negative || !canCalculate)
|
|
7434
7706
|
return held.active ? mapEarnings(held.value, smartWallet) : mapped;
|
|
7435
7707
|
this.earningsCalculationAttempts.set(calculationKey, now);
|
|
7436
|
-
const earnings = await executionSdk.calculateOnchainEarnings(smartWallet);
|
|
7708
|
+
const earnings = await this.readCall(state, () => executionSdk.calculateOnchainEarnings(smartWallet), executionSdk);
|
|
7437
7709
|
assertCurrent();
|
|
7438
7710
|
this.earningsSnapshot = { key: key2, raw: earnings, at: Date.now() };
|
|
7439
7711
|
const recalculated = await this.holdEarnings(state, chainId, smartWallet, key2, earnings);
|
|
@@ -7448,7 +7720,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7448
7720
|
}
|
|
7449
7721
|
async getAccountApy(state, chainId, days, tokenSymbol, scopeChainId) {
|
|
7450
7722
|
const { smartWallet } = await this.resolveSmartWallet(state, chainId);
|
|
7451
|
-
const raw2 = await this.sdk.getDailyApyHistory(smartWallet, days);
|
|
7723
|
+
const raw2 = await this.readCall(state, () => this.sdk.getDailyApyHistory(smartWallet, days));
|
|
7452
7724
|
const scope = scopeChainId === null ? void 0 : scopeChainId ?? chainId;
|
|
7453
7725
|
const ethUsd = tokenSymbol === void 0 && holdsEthPosition(raw2) ? await readEthUsdPrice(this.getPublicClient(8453)) : void 0;
|
|
7454
7726
|
return mapApyHistory(raw2, scope, tokenSymbol, ethUsd);
|
|
@@ -7458,10 +7730,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7458
7730
|
const start = new Date(
|
|
7459
7731
|
Date.now() - (DayFilterMapping[days] + 1) * 864e5
|
|
7460
7732
|
);
|
|
7461
|
-
const raw2 = await this.sdk.getDailyEarnings(
|
|
7733
|
+
const raw2 = await this.readCall(state, () => this.sdk.getDailyEarnings(
|
|
7462
7734
|
smartWallet,
|
|
7463
7735
|
start.toISOString().slice(0, 10)
|
|
7464
|
-
);
|
|
7736
|
+
));
|
|
7465
7737
|
return mapDailyEarnings(raw2, chainId, tokenSymbol);
|
|
7466
7738
|
}
|
|
7467
7739
|
/**
|
|
@@ -7505,7 +7777,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7505
7777
|
const matched = [];
|
|
7506
7778
|
let backendExhausted = false;
|
|
7507
7779
|
for (let i = 0; i < MAX_BACKEND_CALLS && matched.length < limit; i++) {
|
|
7508
|
-
const raw2 = await this.sdk.getHistory(smartWallet, validChainId, {
|
|
7780
|
+
const raw2 = await this.readCall(state, () => this.sdk.getHistory(smartWallet, validChainId, {
|
|
7509
7781
|
limit: backendPageSize,
|
|
7510
7782
|
offset,
|
|
7511
7783
|
fromDate: options?.fromDate,
|
|
@@ -7515,7 +7787,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7515
7787
|
// relevant entries instead of spending its budget on the other
|
|
7516
7788
|
// asset's rows and handing back a page that filters to nothing.
|
|
7517
7789
|
assetType
|
|
7518
|
-
});
|
|
7790
|
+
}));
|
|
7519
7791
|
raw2.data.forEach((entry, idx) => {
|
|
7520
7792
|
if (entry.chainId === validChainId) {
|
|
7521
7793
|
matched.push({ entry, rawIdx: offset + idx });
|
|
@@ -7551,7 +7823,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7551
7823
|
}
|
|
7552
7824
|
async getUserProfile(state, chainId) {
|
|
7553
7825
|
await this.ensureReadSession(state, chainId);
|
|
7554
|
-
const raw2 = await this.sdk.getUserDetails();
|
|
7826
|
+
const raw2 = await this.readCall(state, () => this.sdk.getUserDetails());
|
|
7555
7827
|
debugLog("zyfai:profile", "getUserProfile \u2014 Zyfai reports", {
|
|
7556
7828
|
asset: "USDC (default \u2014 no asset passed)",
|
|
7557
7829
|
splitting: raw2.splitting,
|
|
@@ -7583,7 +7855,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
7583
7855
|
const update = buildAutoSelectUpdate(
|
|
7584
7856
|
{
|
|
7585
7857
|
autoSelectProtocols: current.autoSelectProtocols,
|
|
7586
|
-
chains: current.chains
|
|
7858
|
+
chains: current.chains,
|
|
7859
|
+
savedPoolChoices: hasManualPoolChoices(current.customization)
|
|
7587
7860
|
},
|
|
7588
7861
|
asset,
|
|
7589
7862
|
isValidChainId(chainId)
|
|
@@ -7644,7 +7917,7 @@ var INVALIDATED_KEY_PREFIXES = [
|
|
|
7644
7917
|
"owney.yieldseeker.session.v3",
|
|
7645
7918
|
"owney.yieldseeker.session.v4"
|
|
7646
7919
|
];
|
|
7647
|
-
var
|
|
7920
|
+
var storage4 = () => {
|
|
7648
7921
|
if (typeof window === "undefined") return null;
|
|
7649
7922
|
try {
|
|
7650
7923
|
return window.localStorage;
|
|
@@ -7678,7 +7951,7 @@ var isValidSession = (session) => {
|
|
|
7678
7951
|
var readYieldseekerSession = (address, chainId) => {
|
|
7679
7952
|
if (typeof window === "undefined") return null;
|
|
7680
7953
|
const key2 = buildKey2(address, chainId);
|
|
7681
|
-
const store =
|
|
7954
|
+
const store = storage4();
|
|
7682
7955
|
clearInvalidatedSessions(store, address, chainId);
|
|
7683
7956
|
let raw2 = null;
|
|
7684
7957
|
try {
|
|
@@ -7710,7 +7983,7 @@ var writeYieldseekerSession = (address, chainId, token) => {
|
|
|
7710
7983
|
if (!isValidSession(session)) return;
|
|
7711
7984
|
const key2 = buildKey2(address, chainId);
|
|
7712
7985
|
memorySessions2.set(key2, session);
|
|
7713
|
-
const store =
|
|
7986
|
+
const store = storage4();
|
|
7714
7987
|
try {
|
|
7715
7988
|
store?.setItem(key2, JSON.stringify(session));
|
|
7716
7989
|
} catch {
|
|
@@ -7719,7 +7992,7 @@ var writeYieldseekerSession = (address, chainId, token) => {
|
|
|
7719
7992
|
var clearYieldseekerSession = (address, chainId) => {
|
|
7720
7993
|
const key2 = buildKey2(address, chainId);
|
|
7721
7994
|
memorySessions2.delete(key2);
|
|
7722
|
-
const store =
|
|
7995
|
+
const store = storage4();
|
|
7723
7996
|
clearInvalidatedSessions(store, address, chainId);
|
|
7724
7997
|
try {
|
|
7725
7998
|
store?.removeItem(key2);
|
|
@@ -7831,12 +8104,21 @@ var YieldseekerAuth = class {
|
|
|
7831
8104
|
return this.getToken(state, chainId);
|
|
7832
8105
|
}
|
|
7833
8106
|
/** Drop a proof the provider refused, without signing a new one: a
|
|
7834
|
-
* promptless read cannot renew it, and must stop offering it.
|
|
8107
|
+
* promptless read cannot renew it, and must stop offering it. Returns
|
|
8108
|
+
* whether it dropped anything: false when the proof was already dropped or
|
|
8109
|
+
* replaced meanwhile. */
|
|
7835
8110
|
discardToken(state, chainId, rejectedToken) {
|
|
7836
8111
|
const key2 = this.key(state, chainId);
|
|
7837
|
-
|
|
7838
|
-
if (
|
|
8112
|
+
let dropped = false;
|
|
8113
|
+
if (this.tokens.get(key2) === rejectedToken) {
|
|
8114
|
+
this.tokens.delete(key2);
|
|
8115
|
+
dropped = true;
|
|
8116
|
+
}
|
|
8117
|
+
if (readYieldseekerSession(state.walletAddress, chainId) === rejectedToken) {
|
|
7839
8118
|
clearYieldseekerSession(state.walletAddress, chainId);
|
|
8119
|
+
dropped = true;
|
|
8120
|
+
}
|
|
8121
|
+
return dropped;
|
|
7840
8122
|
}
|
|
7841
8123
|
isReusable(token, state, chainId) {
|
|
7842
8124
|
try {
|
|
@@ -7852,6 +8134,12 @@ var YieldseekerAuth = class {
|
|
|
7852
8134
|
return false;
|
|
7853
8135
|
}
|
|
7854
8136
|
}
|
|
8137
|
+
/** Drops what this instance holds in memory; saved sign-ins in storage stay. */
|
|
8138
|
+
forgetInMemory() {
|
|
8139
|
+
this.tokens.clear();
|
|
8140
|
+
this.pending.clear();
|
|
8141
|
+
this.scopes.clear();
|
|
8142
|
+
}
|
|
7855
8143
|
clear(state, chainId) {
|
|
7856
8144
|
if (!state || chainId === void 0) {
|
|
7857
8145
|
for (const scope of this.scopes.values()) {
|
|
@@ -7896,9 +8184,9 @@ var YieldseekerAuth = class {
|
|
|
7896
8184
|
|
|
7897
8185
|
// src/agents/yieldseeker/yieldseeker.identity-cache.ts
|
|
7898
8186
|
var KEY_PREFIX3 = "owney.yieldseeker.identity.v1";
|
|
7899
|
-
var YIELDSEEKER_IDENTITY_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
8187
|
+
var YIELDSEEKER_IDENTITY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
7900
8188
|
var memoryIdentities = /* @__PURE__ */ new Map();
|
|
7901
|
-
var
|
|
8189
|
+
var storage5 = () => {
|
|
7902
8190
|
if (typeof window === "undefined") return null;
|
|
7903
8191
|
try {
|
|
7904
8192
|
return window.localStorage;
|
|
@@ -7915,7 +8203,7 @@ function valid(value, walletAddress, chainId, now) {
|
|
|
7915
8203
|
function readYieldseekerIdentity(walletAddress, chainId, now = Date.now()) {
|
|
7916
8204
|
if (typeof window === "undefined") return null;
|
|
7917
8205
|
const key2 = keyFor(walletAddress, chainId);
|
|
7918
|
-
const store =
|
|
8206
|
+
const store = storage5();
|
|
7919
8207
|
let parsed = null;
|
|
7920
8208
|
try {
|
|
7921
8209
|
const raw2 = store?.getItem(key2);
|
|
@@ -7947,7 +8235,7 @@ function writeYieldseekerIdentity(walletAddress, chainId, userId, now = Date.now
|
|
|
7947
8235
|
const key2 = keyFor(walletAddress, chainId);
|
|
7948
8236
|
memoryIdentities.set(key2, identity);
|
|
7949
8237
|
try {
|
|
7950
|
-
|
|
8238
|
+
storage5()?.setItem(key2, JSON.stringify(identity));
|
|
7951
8239
|
} catch {
|
|
7952
8240
|
}
|
|
7953
8241
|
}
|
|
@@ -7955,11 +8243,43 @@ function clearYieldseekerIdentity(walletAddress, chainId) {
|
|
|
7955
8243
|
const key2 = keyFor(walletAddress, chainId);
|
|
7956
8244
|
memoryIdentities.delete(key2);
|
|
7957
8245
|
try {
|
|
7958
|
-
|
|
8246
|
+
storage5()?.removeItem(key2);
|
|
7959
8247
|
} catch {
|
|
7960
8248
|
}
|
|
7961
8249
|
}
|
|
7962
8250
|
|
|
8251
|
+
// src/agents/yieldseeker/yieldseeker.login-cooldown.ts
|
|
8252
|
+
var KEY2 = "owney.yieldseeker.login-cooldown.v1";
|
|
8253
|
+
var YIELDSEEKER_LOGIN_COOLDOWN_FLOOR_MS = 3 * 6e4;
|
|
8254
|
+
var memoryUntil = 0;
|
|
8255
|
+
var storage6 = () => {
|
|
8256
|
+
if (typeof window === "undefined") return null;
|
|
8257
|
+
try {
|
|
8258
|
+
return window.localStorage;
|
|
8259
|
+
} catch {
|
|
8260
|
+
return null;
|
|
8261
|
+
}
|
|
8262
|
+
};
|
|
8263
|
+
function readYieldseekerLoginCooldown(now = Date.now()) {
|
|
8264
|
+
let until = memoryUntil;
|
|
8265
|
+
try {
|
|
8266
|
+
const stored = Number(storage6()?.getItem(KEY2));
|
|
8267
|
+
if (Number.isSafeInteger(stored) && stored > until) until = stored;
|
|
8268
|
+
} catch {
|
|
8269
|
+
}
|
|
8270
|
+
return until > now ? until : void 0;
|
|
8271
|
+
}
|
|
8272
|
+
function startYieldseekerLoginCooldown(retryAfterMs, now = Date.now()) {
|
|
8273
|
+
const wait3 = Math.max(YIELDSEEKER_LOGIN_COOLDOWN_FLOOR_MS, Number.isFinite(retryAfterMs) ? retryAfterMs : 0);
|
|
8274
|
+
const until = Math.max(readYieldseekerLoginCooldown(now) ?? 0, now + wait3);
|
|
8275
|
+
memoryUntil = until;
|
|
8276
|
+
try {
|
|
8277
|
+
storage6()?.setItem(KEY2, String(until));
|
|
8278
|
+
} catch {
|
|
8279
|
+
}
|
|
8280
|
+
return until;
|
|
8281
|
+
}
|
|
8282
|
+
|
|
7963
8283
|
// src/agents/yieldseeker/yieldseeker.client.ts
|
|
7964
8284
|
var DEFAULT_ROUTING_API_BASE_URL = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
7965
8285
|
function getYieldseekerProxyBaseUrl(routingApiBaseUrl = DEFAULT_ROUTING_API_BASE_URL) {
|
|
@@ -9591,7 +9911,7 @@ var DEPOSIT_NOTICE_ATTEMPTS = 3;
|
|
|
9591
9911
|
var DEPOSIT_ALLOCATION_CHECK_MS = 6e4;
|
|
9592
9912
|
var DEPOSIT_NOTICE_RETRY_MS = 15e3;
|
|
9593
9913
|
var DEPOSIT_NOTICE_RETRY_MAX_MS = 6e4;
|
|
9594
|
-
var
|
|
9914
|
+
var WITHDRAWAL_UNDER_WAY_MAX_AGE_MS = 60 * 6e4;
|
|
9595
9915
|
var YIELDSEEKER_LIVE_IDLE_CACHE_MS = 15e3;
|
|
9596
9916
|
var YIELDSEEKER_LIVE_IDLE_BUDGET_MS = 3e3;
|
|
9597
9917
|
var YIELDSEEKER_SERVER_BASELINE_CACHE_MS = 10 * 6e4;
|
|
@@ -9613,6 +9933,12 @@ function generateYieldseekerUsername() {
|
|
|
9613
9933
|
const suffix = globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, YIELDSEEKER_USERNAME_RANDOM_LENGTH).toLowerCase();
|
|
9614
9934
|
return `${YIELDSEEKER_USERNAME_PREFIX}${suffix}`;
|
|
9615
9935
|
}
|
|
9936
|
+
function isSignInRateLimit(error) {
|
|
9937
|
+
return error instanceof YieldseekerApiError && error.status === 429;
|
|
9938
|
+
}
|
|
9939
|
+
function isWalletAlreadyRegistered(error) {
|
|
9940
|
+
return error instanceof YieldseekerApiError && error.providerCode.toUpperCase() === "USER_WALLET_EXISTS";
|
|
9941
|
+
}
|
|
9616
9942
|
function isUsernameConflict(error) {
|
|
9617
9943
|
if (!(error instanceof YieldseekerApiError)) return false;
|
|
9618
9944
|
const code = error.providerCode.toUpperCase();
|
|
@@ -9760,6 +10086,15 @@ var YieldseekerAgent = class {
|
|
|
9760
10086
|
balanceContexts = /* @__PURE__ */ new WeakMap();
|
|
9761
10087
|
balanceVaults = /* @__PURE__ */ new Map();
|
|
9762
10088
|
users = /* @__PURE__ */ new Map();
|
|
10089
|
+
/**
|
|
10090
|
+
* Agent wallets (lowercase) this page started releasing vault funds from for
|
|
10091
|
+
* a withdrawal, and when. Until the payout is done the released money sits
|
|
10092
|
+
* in the agent wallet, so no deposit notice may go out (it would be
|
|
10093
|
+
* reinvested). The ledger shows the same once it lists the withdrawal.
|
|
10094
|
+
*/
|
|
10095
|
+
releasingWallets = /* @__PURE__ */ new Map();
|
|
10096
|
+
/** One login (and, for a new wallet, one create) per wallet and chain at a time. */
|
|
10097
|
+
pendingUsers = /* @__PURE__ */ new Map();
|
|
9763
10098
|
pendingAgents = /* @__PURE__ */ new Map();
|
|
9764
10099
|
pendingWalletContexts = /* @__PURE__ */ new Map();
|
|
9765
10100
|
readCache = /* @__PURE__ */ new Map();
|
|
@@ -9786,6 +10121,7 @@ var YieldseekerAgent = class {
|
|
|
9786
10121
|
// or while the ledger read is null, settlement and earnings are as before.
|
|
9787
10122
|
ledgerAccess;
|
|
9788
10123
|
accountRefusedListener;
|
|
10124
|
+
signInRefusedListener;
|
|
9789
10125
|
ledgerReads = /* @__PURE__ */ new Map();
|
|
9790
10126
|
/** contextKey -> movements this instance started settling (by tx hash) and how they refresh:
|
|
9791
10127
|
* awaiting the ledger, refreshed when ready (ledger), or on the timed backoff (legacy). */
|
|
@@ -10081,16 +10417,16 @@ var YieldseekerAgent = class {
|
|
|
10081
10417
|
this.rememberWalletStatus(versionKey, status);
|
|
10082
10418
|
return { txHash: hash2, status };
|
|
10083
10419
|
};
|
|
10084
|
-
let
|
|
10420
|
+
let storage11;
|
|
10085
10421
|
try {
|
|
10086
|
-
|
|
10422
|
+
storage11 = typeof window === "undefined" ? void 0 : window.localStorage;
|
|
10087
10423
|
} catch {
|
|
10088
|
-
|
|
10424
|
+
storage11 = void 0;
|
|
10089
10425
|
}
|
|
10090
10426
|
const clearRecordedUpgrade = () => {
|
|
10091
10427
|
this.pendingUpgrades.delete(pendingKey2);
|
|
10092
10428
|
try {
|
|
10093
|
-
|
|
10429
|
+
storage11?.removeItem(pendingKey2);
|
|
10094
10430
|
} catch {
|
|
10095
10431
|
this.pendingUpgrades.set(pendingKey2, null);
|
|
10096
10432
|
}
|
|
@@ -10113,7 +10449,7 @@ var YieldseekerAgent = class {
|
|
|
10113
10449
|
throw pendingUpgrade(hash2);
|
|
10114
10450
|
}
|
|
10115
10451
|
};
|
|
10116
|
-
if (!
|
|
10452
|
+
if (!storage11 && (gasMode === "sponsored" || before.ownerPath === "smart"))
|
|
10117
10453
|
throw new OwneyError(
|
|
10118
10454
|
"SPONSOR_REQUEST_FAILED",
|
|
10119
10455
|
"Upgrade status cannot be saved in this browser.",
|
|
@@ -10122,14 +10458,14 @@ var YieldseekerAgent = class {
|
|
|
10122
10458
|
);
|
|
10123
10459
|
let prior = null;
|
|
10124
10460
|
try {
|
|
10125
|
-
const saved = this.pendingUpgrades.has(pendingKey2) ? JSON.stringify(this.pendingUpgrades.get(pendingKey2)) :
|
|
10461
|
+
const saved = this.pendingUpgrades.has(pendingKey2) ? JSON.stringify(this.pendingUpgrades.get(pendingKey2)) : storage11?.getItem(pendingKey2);
|
|
10126
10462
|
try {
|
|
10127
10463
|
prior = JSON.parse(saved ?? "null");
|
|
10128
10464
|
} catch {
|
|
10129
10465
|
prior = { callsId: void 0 };
|
|
10130
10466
|
}
|
|
10131
10467
|
} catch {
|
|
10132
|
-
if (gasMode === "paid" && before.ownerPath === "eoa")
|
|
10468
|
+
if (gasMode === "paid" && before.ownerPath === "eoa") storage11 = void 0;
|
|
10133
10469
|
else throw new OwneyError(
|
|
10134
10470
|
"SPONSOR_REQUEST_FAILED",
|
|
10135
10471
|
"Upgrade status cannot be read in this browser.",
|
|
@@ -10223,9 +10559,9 @@ var YieldseekerAgent = class {
|
|
|
10223
10559
|
asset: YIELDSEEKER_ASSET_METADATA[asset].address,
|
|
10224
10560
|
callData: data,
|
|
10225
10561
|
onPending: (pending2) => {
|
|
10226
|
-
const current = this.pendingUpgrades.has(pendingKey2) ? this.pendingUpgrades.get(pendingKey2) : JSON.parse(
|
|
10562
|
+
const current = this.pendingUpgrades.has(pendingKey2) ? this.pendingUpgrades.get(pendingKey2) : JSON.parse(storage11.getItem(pendingKey2) ?? "null");
|
|
10227
10563
|
const next = { startedAt: Date.now(), ...current, ...pending2 };
|
|
10228
|
-
|
|
10564
|
+
storage11.setItem(pendingKey2, JSON.stringify(next));
|
|
10229
10565
|
this.pendingUpgrades.delete(pendingKey2);
|
|
10230
10566
|
}
|
|
10231
10567
|
});
|
|
@@ -10249,8 +10585,8 @@ var YieldseekerAgent = class {
|
|
|
10249
10585
|
const pending2 = { txHash: hash2 };
|
|
10250
10586
|
this.pendingUpgrades.set(pendingKey2, pending2);
|
|
10251
10587
|
try {
|
|
10252
|
-
if (
|
|
10253
|
-
|
|
10588
|
+
if (storage11) {
|
|
10589
|
+
storage11.setItem(pendingKey2, JSON.stringify(pending2));
|
|
10254
10590
|
this.pendingUpgrades.delete(pendingKey2);
|
|
10255
10591
|
}
|
|
10256
10592
|
} catch {
|
|
@@ -10271,14 +10607,18 @@ var YieldseekerAgent = class {
|
|
|
10271
10607
|
clearRecordedUpgrade();
|
|
10272
10608
|
return confirmed;
|
|
10273
10609
|
}
|
|
10274
|
-
async disconnect() {
|
|
10610
|
+
async disconnect(options) {
|
|
10275
10611
|
this.withdrawalVersionCache.clear();
|
|
10276
10612
|
this.pendingWalletStatus.clear();
|
|
10277
10613
|
this.readGeneration += 1;
|
|
10278
|
-
|
|
10279
|
-
|
|
10280
|
-
|
|
10281
|
-
|
|
10614
|
+
if (options?.keepSignIns) {
|
|
10615
|
+
this.auth.forgetInMemory();
|
|
10616
|
+
} else {
|
|
10617
|
+
this.auth.clear();
|
|
10618
|
+
for (const key2 of this.users.keys()) {
|
|
10619
|
+
const [walletAddress, chainId] = key2.split(":");
|
|
10620
|
+
clearYieldseekerIdentity(walletAddress, Number(chainId));
|
|
10621
|
+
}
|
|
10282
10622
|
}
|
|
10283
10623
|
this.users.clear();
|
|
10284
10624
|
this.agentContexts.clear();
|
|
@@ -10497,6 +10837,7 @@ var YieldseekerAgent = class {
|
|
|
10497
10837
|
}
|
|
10498
10838
|
async withdraw(state, chainId, asset, amount, onProgress, gasMode = "auto", onBeforeSubmission, assertOperation, submission) {
|
|
10499
10839
|
let ownerTransferAttempted = false;
|
|
10840
|
+
const startedAt = Date.now();
|
|
10500
10841
|
let evidence = {
|
|
10501
10842
|
agentId: this.id,
|
|
10502
10843
|
chainId,
|
|
@@ -10538,6 +10879,10 @@ var YieldseekerAgent = class {
|
|
|
10538
10879
|
delivery: "failed"
|
|
10539
10880
|
});
|
|
10540
10881
|
throw error;
|
|
10882
|
+
} finally {
|
|
10883
|
+
for (const [wallet, markedAt] of this.releasingWallets) {
|
|
10884
|
+
if (markedAt >= startedAt) this.releasingWallets.delete(wallet);
|
|
10885
|
+
}
|
|
10541
10886
|
}
|
|
10542
10887
|
}
|
|
10543
10888
|
async withdrawInternal(state, chainId, asset, amount, onProgress, onOwnerTransferAttempted, gasMode = "auto", onBeforeSubmission, assertOperation, operationId) {
|
|
@@ -10872,6 +11217,7 @@ var YieldseekerAgent = class {
|
|
|
10872
11217
|
const unwind = async (position2, assetsRaw) => {
|
|
10873
11218
|
this.assertSession(generation, chainId, asset);
|
|
10874
11219
|
assertOperation?.();
|
|
11220
|
+
this.releasingWallets.set(context.wallet.walletAddress.toLowerCase(), Date.now());
|
|
10875
11221
|
let unwindTransactionHash;
|
|
10876
11222
|
try {
|
|
10877
11223
|
const response = await this.walletRequest(
|
|
@@ -11667,7 +12013,9 @@ var YieldseekerAgent = class {
|
|
|
11667
12013
|
* left idle. While it has not, Yieldseeker is told again, up to
|
|
11668
12014
|
* DEPOSIT_NOTICE_ATTEMPTS calls in all; a failed call (network, server, rate
|
|
11669
12015
|
* limit) is sent again after a wait. Within an hour of a withdrawal it is
|
|
11670
|
-
* told once, since nothing can move yet.
|
|
12016
|
+
* told once, since nothing can move yet. While a withdrawal from the agent
|
|
12017
|
+
* wallet is under way it is not told at all: its released funds wait in that
|
|
12018
|
+
* wallet for the payout, and a notice would reinvest them (ROUT-790). Uses the agent this session already
|
|
11671
12019
|
* knows for the asset and the saved sign-in only: never prompts, never
|
|
11672
12020
|
* throws. Each call is reported through `onNotice`.
|
|
11673
12021
|
*/
|
|
@@ -11684,7 +12032,8 @@ var YieldseekerAgent = class {
|
|
|
11684
12032
|
if (!this.auth.peekToken(state, chainId)) return { notified: false, reason: "NO_SESSION" };
|
|
11685
12033
|
const generation = this.readGeneration;
|
|
11686
12034
|
const amount = parseRawAmount(evidence.confirmedAmount ?? evidence.intendedAmount);
|
|
11687
|
-
|
|
12035
|
+
if (await this.withdrawalUnderWay(state, chainId, slotAsset, context))
|
|
12036
|
+
return { notified: false, reason: "WITHDRAWAL_IN_PROGRESS" };
|
|
11688
12037
|
let notified = false;
|
|
11689
12038
|
let reason = "NOT_ALLOCATED";
|
|
11690
12039
|
while (attempts < DEPOSIT_NOTICE_ATTEMPTS) {
|
|
@@ -11705,14 +12054,6 @@ var YieldseekerAgent = class {
|
|
|
11705
12054
|
if (this.readGeneration !== generation) return { notified: true, attempts, reason: "SESSION_ENDED" };
|
|
11706
12055
|
const idle = await this.readIdleBalance(chainId, slotAsset, context.wallet.walletAddress);
|
|
11707
12056
|
if (idle !== null && idle < amount) return { notified: true, attempts, allocated: true };
|
|
11708
|
-
if (cooldownEnds !== null)
|
|
11709
|
-
return {
|
|
11710
|
-
notified: true,
|
|
11711
|
-
attempts,
|
|
11712
|
-
allocated: false,
|
|
11713
|
-
reason: "RECENT_WITHDRAWAL",
|
|
11714
|
-
allocatesAfter: new Date(cooldownEnds).toISOString()
|
|
11715
|
-
};
|
|
11716
12057
|
reason = idle === null ? "UNVERIFIED" : "NOT_ALLOCATED";
|
|
11717
12058
|
}
|
|
11718
12059
|
return { notified: true, attempts, allocated: false, reason };
|
|
@@ -11770,24 +12111,17 @@ var YieldseekerAgent = class {
|
|
|
11770
12111
|
}
|
|
11771
12112
|
}
|
|
11772
12113
|
/**
|
|
11773
|
-
*
|
|
11774
|
-
*
|
|
11775
|
-
* the
|
|
12114
|
+
* A withdrawal from this agent wallet that has started but not finished,
|
|
12115
|
+
* within the last hour: released by this page, or listed on the ledger with
|
|
12116
|
+
* the agent's leg still created, submitted or unknown. Older unfinished rows
|
|
12117
|
+
* do not count, so a stuck record cannot hold deposits back for good.
|
|
11776
12118
|
*/
|
|
11777
|
-
async
|
|
11778
|
-
const rows = await withinBudget(this.readLedger(state, chainId, asset), this.ledgerBudgetMs, null);
|
|
12119
|
+
async withdrawalUnderWay(state, chainId, asset, context) {
|
|
11779
12120
|
const wallet = context.wallet.walletAddress.toLowerCase();
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
|
|
11783
|
-
|
|
11784
|
-
if (leg.legKey !== `agent:${this.id}` || leg.status !== "confirmed" || leg.agentWallet?.toLowerCase() !== wallet) continue;
|
|
11785
|
-
const at = Date.parse(leg.confirmedAt ?? row.settledAt ?? "");
|
|
11786
|
-
if (Number.isFinite(at)) latest = Math.max(latest, at);
|
|
11787
|
-
}
|
|
11788
|
-
}
|
|
11789
|
-
const ends = latest + YIELDSEEKER_WITHDRAWAL_COOLDOWN_MS;
|
|
11790
|
-
return latest > 0 && ends > Date.now() ? ends : null;
|
|
12121
|
+
const since = Date.now() - WITHDRAWAL_UNDER_WAY_MAX_AGE_MS;
|
|
12122
|
+
if ((this.releasingWallets.get(wallet) ?? 0) > since) return true;
|
|
12123
|
+
const rows = await withinBudget(this.readLedger(state, chainId, asset), this.ledgerBudgetMs, null);
|
|
12124
|
+
return (rows ?? []).some((row) => (row.kind === "withdraw" || row.kind === "withdraw_swap") && Date.parse(row.createdAt) > since && row.legs.some((leg) => leg.legKey === `agent:${this.id}` && !leg.closed && ["created", "submitted", "unknown"].includes(leg.status) && (leg.agentWallet === null || leg.agentWallet.toLowerCase() === wallet)));
|
|
11791
12125
|
}
|
|
11792
12126
|
/**
|
|
11793
12127
|
* The agent wallet's base-asset balance and the platform fee Yieldseeker has
|
|
@@ -12889,6 +13223,29 @@ var YieldseekerAgent = class {
|
|
|
12889
13223
|
this.users.set(key2, persisted);
|
|
12890
13224
|
return persisted;
|
|
12891
13225
|
}
|
|
13226
|
+
const pending2 = this.pendingUsers.get(key2);
|
|
13227
|
+
if (pending2) return pending2;
|
|
13228
|
+
const request2 = this.signInUser(state, chainId);
|
|
13229
|
+
this.pendingUsers.set(key2, request2);
|
|
13230
|
+
try {
|
|
13231
|
+
return await request2;
|
|
13232
|
+
} finally {
|
|
13233
|
+
if (this.pendingUsers.get(key2) === request2) this.pendingUsers.delete(key2);
|
|
13234
|
+
}
|
|
13235
|
+
}
|
|
13236
|
+
/**
|
|
13237
|
+
* `login-with-wallet`, and `POST /users` for a wallet without an account.
|
|
13238
|
+
* Both draw on Yieldseeker's per-IP sign-in allowance, which all our users
|
|
13239
|
+
* share: while a 429's pause lasts nothing is sent, and a new 429 starts one.
|
|
13240
|
+
*/
|
|
13241
|
+
async signInUser(state, chainId) {
|
|
13242
|
+
const key2 = this.userKey(state, chainId);
|
|
13243
|
+
const pausedUntil = readYieldseekerLoginCooldown();
|
|
13244
|
+
if (pausedUntil !== void 0) throw this.signInRateLimited(pausedUntil);
|
|
13245
|
+
const limited = (error) => {
|
|
13246
|
+
const retryAfter = error instanceof YieldseekerApiError ? rateLimitDelay({ status: error.status, fields: error.responseFields }) : rateLimitDelay(error);
|
|
13247
|
+
throw this.signInRateLimited(startYieldseekerLoginCooldown(retryAfter));
|
|
13248
|
+
};
|
|
12892
13249
|
const walletAddress = (0, import_viem17.getAddress)(state.walletAddress);
|
|
12893
13250
|
const generation = this.readGeneration;
|
|
12894
13251
|
let user = null;
|
|
@@ -12906,11 +13263,13 @@ var YieldseekerAgent = class {
|
|
|
12906
13263
|
});
|
|
12907
13264
|
}
|
|
12908
13265
|
} catch (error) {
|
|
13266
|
+
if (isSignInRateLimit(error)) limited(error);
|
|
12909
13267
|
if (!(error instanceof YieldseekerApiError) || error.providerCode !== "NO_USER") {
|
|
12910
13268
|
if (error instanceof OwneyError) throw error;
|
|
12911
13269
|
throw this.mapRequestFailure(error);
|
|
12912
13270
|
}
|
|
12913
13271
|
let created;
|
|
13272
|
+
let registeredMeanwhile = false;
|
|
12914
13273
|
for (let attempt = 0; attempt < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS; attempt += 1) {
|
|
12915
13274
|
try {
|
|
12916
13275
|
created = await this.providerRequest(
|
|
@@ -12927,12 +13286,32 @@ var YieldseekerAgent = class {
|
|
|
12927
13286
|
);
|
|
12928
13287
|
break;
|
|
12929
13288
|
} catch (createError) {
|
|
13289
|
+
if (isSignInRateLimit(createError)) limited(createError);
|
|
13290
|
+
if (isWalletAlreadyRegistered(createError)) {
|
|
13291
|
+
registeredMeanwhile = true;
|
|
13292
|
+
break;
|
|
13293
|
+
}
|
|
12930
13294
|
const canRetry = isUsernameConflict(createError) && attempt + 1 < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS;
|
|
12931
13295
|
if (canRetry) continue;
|
|
12932
13296
|
throw this.mapRequestFailure(createError);
|
|
12933
13297
|
}
|
|
12934
13298
|
}
|
|
12935
13299
|
user = created?.user ?? null;
|
|
13300
|
+
if (registeredMeanwhile) {
|
|
13301
|
+
try {
|
|
13302
|
+
const login = await this.providerRequest(
|
|
13303
|
+
state,
|
|
13304
|
+
chainId,
|
|
13305
|
+
"/users/login-with-wallet",
|
|
13306
|
+
{ method: "POST", body: { walletAddress } }
|
|
13307
|
+
);
|
|
13308
|
+
user = login?.user ?? null;
|
|
13309
|
+
} catch (loginError) {
|
|
13310
|
+
if (isSignInRateLimit(loginError)) limited(loginError);
|
|
13311
|
+
if (loginError instanceof OwneyError) throw loginError;
|
|
13312
|
+
throw this.mapRequestFailure(loginError);
|
|
13313
|
+
}
|
|
13314
|
+
}
|
|
12936
13315
|
}
|
|
12937
13316
|
if (!user || !/^[a-zA-Z0-9_-]{1,128}$/.test(user.userId)) {
|
|
12938
13317
|
throw this.invalidResponse("wallet identity");
|
|
@@ -12943,6 +13322,19 @@ var YieldseekerAgent = class {
|
|
|
12943
13322
|
writeYieldseekerIdentity(state.walletAddress, chainId, resolved.userId);
|
|
12944
13323
|
return resolved;
|
|
12945
13324
|
}
|
|
13325
|
+
signInRateLimited(until) {
|
|
13326
|
+
return new OwneyError(
|
|
13327
|
+
"AGENT_RATE_LIMITED",
|
|
13328
|
+
"Too many sign-in attempts right now. Please wait before trying again.",
|
|
13329
|
+
{
|
|
13330
|
+
reason: "YIELDSEEKER_SIGN_IN_RATE_LIMITED",
|
|
13331
|
+
statusCode: 429,
|
|
13332
|
+
retryAt: until,
|
|
13333
|
+
retryAfterSeconds: Math.max(0, Math.ceil((until - Date.now()) / 1e3))
|
|
13334
|
+
},
|
|
13335
|
+
this.id
|
|
13336
|
+
);
|
|
13337
|
+
}
|
|
12946
13338
|
forgetUser(state, chainId) {
|
|
12947
13339
|
this.users.delete(this.userKey(state, chainId));
|
|
12948
13340
|
clearYieldseekerIdentity(state.walletAddress, chainId);
|
|
@@ -13424,6 +13816,9 @@ var YieldseekerAgent = class {
|
|
|
13424
13816
|
setAccountRefusedListener(listener) {
|
|
13425
13817
|
this.accountRefusedListener = listener;
|
|
13426
13818
|
}
|
|
13819
|
+
setSignInRefusedListener(listener) {
|
|
13820
|
+
this.signInRefusedListener = listener;
|
|
13821
|
+
}
|
|
13427
13822
|
setFundingLedgerAccess(access) {
|
|
13428
13823
|
this.ledgerAccess = access;
|
|
13429
13824
|
this.ledgerReads.clear();
|
|
@@ -13817,7 +14212,13 @@ var YieldseekerAgent = class {
|
|
|
13817
14212
|
if (error.providerCode === "NO_USER") throw error;
|
|
13818
14213
|
if (!error.isAuthenticationError) throw error;
|
|
13819
14214
|
if (promptless) {
|
|
13820
|
-
this.auth.discardToken(state, chainId, signature);
|
|
14215
|
+
const dropped = this.auth.discardToken(state, chainId, signature);
|
|
14216
|
+
if (dropped) {
|
|
14217
|
+
try {
|
|
14218
|
+
this.signInRefusedListener?.();
|
|
14219
|
+
} catch {
|
|
14220
|
+
}
|
|
14221
|
+
}
|
|
13821
14222
|
throw error;
|
|
13822
14223
|
}
|
|
13823
14224
|
signature = await this.auth.refreshToken(state, chainId, signature);
|
|
@@ -14930,7 +15331,7 @@ function runSameChainOrder(deps, options) {
|
|
|
14930
15331
|
|
|
14931
15332
|
// src/lib/swap/swap.secret-store.ts
|
|
14932
15333
|
var KEY_PREFIX4 = "owney.swap.order";
|
|
14933
|
-
var
|
|
15334
|
+
var storage7 = () => {
|
|
14934
15335
|
if (typeof window === "undefined") return null;
|
|
14935
15336
|
try {
|
|
14936
15337
|
return window.localStorage;
|
|
@@ -14940,7 +15341,7 @@ var storage5 = () => {
|
|
|
14940
15341
|
};
|
|
14941
15342
|
var keyFor2 = (orderHash) => `${KEY_PREFIX4}.${orderHash}`;
|
|
14942
15343
|
function saveOrder(order) {
|
|
14943
|
-
const store =
|
|
15344
|
+
const store = storage7();
|
|
14944
15345
|
if (!store) return false;
|
|
14945
15346
|
try {
|
|
14946
15347
|
const value = JSON.stringify(order);
|
|
@@ -14951,7 +15352,7 @@ function saveOrder(order) {
|
|
|
14951
15352
|
}
|
|
14952
15353
|
}
|
|
14953
15354
|
function loadOrder(orderHash) {
|
|
14954
|
-
const store =
|
|
15355
|
+
const store = storage7();
|
|
14955
15356
|
if (!store) return null;
|
|
14956
15357
|
try {
|
|
14957
15358
|
const raw2 = store.getItem(keyFor2(orderHash));
|
|
@@ -14966,7 +15367,7 @@ function loadOrder(orderHash) {
|
|
|
14966
15367
|
}
|
|
14967
15368
|
}
|
|
14968
15369
|
function clearOrder(orderHash) {
|
|
14969
|
-
const store =
|
|
15370
|
+
const store = storage7();
|
|
14970
15371
|
if (!store) return;
|
|
14971
15372
|
try {
|
|
14972
15373
|
store.removeItem(keyFor2(orderHash));
|
|
@@ -14974,7 +15375,7 @@ function clearOrder(orderHash) {
|
|
|
14974
15375
|
}
|
|
14975
15376
|
}
|
|
14976
15377
|
function listOrders(_now = Date.now()) {
|
|
14977
|
-
const store =
|
|
15378
|
+
const store = storage7();
|
|
14978
15379
|
if (!store) return [];
|
|
14979
15380
|
const out = [];
|
|
14980
15381
|
try {
|
|
@@ -15782,7 +16183,7 @@ async function buildErc2612Permit(reads, input) {
|
|
|
15782
16183
|
// src/lib/swap/swap.withdraw-swap.ts
|
|
15783
16184
|
var KEY_PREFIX5 = "owney.swap.withdraw";
|
|
15784
16185
|
var MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
15785
|
-
var
|
|
16186
|
+
var storage8 = () => {
|
|
15786
16187
|
if (typeof window === "undefined") return null;
|
|
15787
16188
|
try {
|
|
15788
16189
|
return window.localStorage;
|
|
@@ -15807,7 +16208,7 @@ var notify = () => {
|
|
|
15807
16208
|
}
|
|
15808
16209
|
};
|
|
15809
16210
|
function saveWithdrawSwap(record2) {
|
|
15810
|
-
const store =
|
|
16211
|
+
const store = storage8();
|
|
15811
16212
|
if (!store) return false;
|
|
15812
16213
|
try {
|
|
15813
16214
|
const current = store.getItem(keyFor3(record2.orderHash));
|
|
@@ -15821,7 +16222,7 @@ function saveWithdrawSwap(record2) {
|
|
|
15821
16222
|
return true;
|
|
15822
16223
|
}
|
|
15823
16224
|
function updateWithdrawSwap(orderHash, patch) {
|
|
15824
|
-
const store =
|
|
16225
|
+
const store = storage8();
|
|
15825
16226
|
if (!store) return;
|
|
15826
16227
|
try {
|
|
15827
16228
|
const raw2 = store.getItem(keyFor3(orderHash));
|
|
@@ -15838,7 +16239,7 @@ function updateWithdrawSwap(orderHash, patch) {
|
|
|
15838
16239
|
notify();
|
|
15839
16240
|
}
|
|
15840
16241
|
function clearWithdrawSwap(orderHash) {
|
|
15841
|
-
const store =
|
|
16242
|
+
const store = storage8();
|
|
15842
16243
|
if (!store) return;
|
|
15843
16244
|
try {
|
|
15844
16245
|
const raw2 = store.getItem(keyFor3(orderHash));
|
|
@@ -15852,7 +16253,7 @@ function clearWithdrawSwap(orderHash) {
|
|
|
15852
16253
|
notify();
|
|
15853
16254
|
}
|
|
15854
16255
|
function listWithdrawSwaps(now = Date.now(), includeDismissed = false) {
|
|
15855
|
-
const store =
|
|
16256
|
+
const store = storage8();
|
|
15856
16257
|
if (!store) return [];
|
|
15857
16258
|
const out = [];
|
|
15858
16259
|
try {
|
|
@@ -15889,7 +16290,7 @@ if (typeof window !== "undefined" && typeof window.addEventListener === "functio
|
|
|
15889
16290
|
// src/lib/swap/swap.pending-deposit.ts
|
|
15890
16291
|
var KEY_PREFIX6 = "owney.swap.pending-deposit";
|
|
15891
16292
|
var MAX_AGE_MS2 = 24 * 60 * 60 * 1e3;
|
|
15892
|
-
var
|
|
16293
|
+
var storage9 = () => {
|
|
15893
16294
|
if (typeof window === "undefined") return null;
|
|
15894
16295
|
try {
|
|
15895
16296
|
return window.localStorage;
|
|
@@ -15899,7 +16300,7 @@ var storage7 = () => {
|
|
|
15899
16300
|
};
|
|
15900
16301
|
var keyFor4 = (id) => `${KEY_PREFIX6}.${id}`;
|
|
15901
16302
|
function savePendingDeposit(entry) {
|
|
15902
|
-
const store =
|
|
16303
|
+
const store = storage9();
|
|
15903
16304
|
if (!store) return;
|
|
15904
16305
|
try {
|
|
15905
16306
|
store.setItem(keyFor4(entry.id), JSON.stringify(entry));
|
|
@@ -15908,7 +16309,7 @@ function savePendingDeposit(entry) {
|
|
|
15908
16309
|
}
|
|
15909
16310
|
}
|
|
15910
16311
|
function clearPendingDeposit(id) {
|
|
15911
|
-
const store =
|
|
16312
|
+
const store = storage9();
|
|
15912
16313
|
if (!store) return;
|
|
15913
16314
|
try {
|
|
15914
16315
|
store.removeItem(keyFor4(id));
|
|
@@ -15917,7 +16318,7 @@ function clearPendingDeposit(id) {
|
|
|
15917
16318
|
}
|
|
15918
16319
|
}
|
|
15919
16320
|
function listPendingDeposits(now = Date.now()) {
|
|
15920
|
-
const store =
|
|
16321
|
+
const store = storage9();
|
|
15921
16322
|
if (!store) return [];
|
|
15922
16323
|
const out = [];
|
|
15923
16324
|
try {
|
|
@@ -17415,15 +17816,8 @@ var OwneySDK = class {
|
|
|
17415
17816
|
*/
|
|
17416
17817
|
disabledAgents = /* @__PURE__ */ new Set();
|
|
17417
17818
|
accountRefusedListeners = /* @__PURE__ */ new Set();
|
|
17819
|
+
signInRefusedListeners = /* @__PURE__ */ new Set();
|
|
17418
17820
|
signInProgressListeners = /* @__PURE__ */ new Set();
|
|
17419
|
-
/**
|
|
17420
|
-
* Agents whose sign-in the user cancelled this session (the wallet rejected
|
|
17421
|
-
* the prompt), keyed by chain. Until the app ends the session they are read
|
|
17422
|
-
* from a saved sign-in only (`readStateFor`), so no read reopens the prompt
|
|
17423
|
-
* the user cancelled. A later successful activation of the agent removes
|
|
17424
|
-
* it, and `disconnect()` or a different wallet's `connect()` clears the map.
|
|
17425
|
-
*/
|
|
17426
|
-
declinedSignIns = /* @__PURE__ */ new Map();
|
|
17427
17821
|
state = null;
|
|
17428
17822
|
connectionRevision = 0;
|
|
17429
17823
|
disconnectingAgents = null;
|
|
@@ -17630,7 +18024,7 @@ var OwneySDK = class {
|
|
|
17630
18024
|
read: async () => {
|
|
17631
18025
|
const state = this.state;
|
|
17632
18026
|
if (!state || state.walletAddress.toLowerCase() !== owner) return null;
|
|
17633
|
-
const sample = await agent.providerEarningsSample(state, evidence.chainId);
|
|
18027
|
+
const sample = await agent.providerEarningsSample(this.readStateFor(state), evidence.chainId);
|
|
17634
18028
|
return sample ? { ...sample, observedAt: (/* @__PURE__ */ new Date()).toISOString() } : null;
|
|
17635
18029
|
},
|
|
17636
18030
|
emit: (data) => op.event?.("provider.sample", data)
|
|
@@ -17649,6 +18043,19 @@ var OwneySDK = class {
|
|
|
17649
18043
|
this.accountRefusedListeners.delete(listener);
|
|
17650
18044
|
};
|
|
17651
18045
|
}
|
|
18046
|
+
/**
|
|
18047
|
+
* Listens for an agent dropping a saved sign-in its server refused, outside
|
|
18048
|
+
* connect (a read or a withdrawal found it refused). The agent will not
|
|
18049
|
+
* sign in again by itself; the next sign-in is the user's. Not fired where a
|
|
18050
|
+
* refused sign-in is renewed (connect, deposit). Returns the unsubscribe
|
|
18051
|
+
* function.
|
|
18052
|
+
*/
|
|
18053
|
+
onSignInRefused(listener) {
|
|
18054
|
+
this.signInRefusedListeners.add(listener);
|
|
18055
|
+
return () => {
|
|
18056
|
+
this.signInRefusedListeners.delete(listener);
|
|
18057
|
+
};
|
|
18058
|
+
}
|
|
17652
18059
|
/**
|
|
17653
18060
|
* Listens for the sign-ins a connect asks for (`SignInProgress`): which
|
|
17654
18061
|
* agents will ask the wallet to sign in, and each one as it starts and ends,
|
|
@@ -17662,6 +18069,28 @@ var OwneySDK = class {
|
|
|
17662
18069
|
this.signInProgressListeners.delete(listener);
|
|
17663
18070
|
};
|
|
17664
18071
|
}
|
|
18072
|
+
/**
|
|
18073
|
+
* The agents that would ask the wallet to sign in on `chainId` right now:
|
|
18074
|
+
* enabled agents on that chain whose `needsSignIn` says yes. One with no
|
|
18075
|
+
* such check counts as no; one that throws counts as yes, so an unknown
|
|
18076
|
+
* answer never lets the app retry quietly into a prompt. Never prompts and
|
|
18077
|
+
* never calls the network. Empty before connect.
|
|
18078
|
+
*/
|
|
18079
|
+
signInsNeeded(chainId) {
|
|
18080
|
+
const state = this.state;
|
|
18081
|
+
if (state === null) return [];
|
|
18082
|
+
const needed = [];
|
|
18083
|
+
for (const [id, agent] of this.agents) {
|
|
18084
|
+
if (this.isAgentDisabled(id)) continue;
|
|
18085
|
+
if (!agent.supportedChainIds.includes(chainId)) continue;
|
|
18086
|
+
try {
|
|
18087
|
+
if (agent.needsSignIn?.(state, chainId) === true) needed.push(id);
|
|
18088
|
+
} catch {
|
|
18089
|
+
needed.push(id);
|
|
18090
|
+
}
|
|
18091
|
+
}
|
|
18092
|
+
return needed;
|
|
18093
|
+
}
|
|
17665
18094
|
/**
|
|
17666
18095
|
* The sign-ins this connect asks for: the agents whose `needsSignIn` says
|
|
17667
18096
|
* yes now (one that throws counts as no). Each is announced at its first
|
|
@@ -17719,6 +18148,14 @@ var OwneySDK = class {
|
|
|
17719
18148
|
}
|
|
17720
18149
|
}
|
|
17721
18150
|
});
|
|
18151
|
+
agent.setSignInRefusedListener?.(() => {
|
|
18152
|
+
for (const listener of [...this.signInRefusedListeners]) {
|
|
18153
|
+
try {
|
|
18154
|
+
listener(agent.id);
|
|
18155
|
+
} catch {
|
|
18156
|
+
}
|
|
18157
|
+
}
|
|
18158
|
+
});
|
|
17722
18159
|
}
|
|
17723
18160
|
/**
|
|
17724
18161
|
* Funding-ledger read access handed to agents for earnings holds. Reads only
|
|
@@ -17798,7 +18235,6 @@ var OwneySDK = class {
|
|
|
17798
18235
|
}
|
|
17799
18236
|
const replacingOwner = this.state !== null && this.state.walletAddress.toLowerCase() !== walletAddress.toLowerCase();
|
|
17800
18237
|
this.clearConnectionState();
|
|
17801
|
-
if (replacingOwner) this.declinedSignIns.clear();
|
|
17802
18238
|
await (replacingOwner ? this.disconnectAgents() : this.disconnectingAgents);
|
|
17803
18239
|
if (revision !== this.connectionRevision)
|
|
17804
18240
|
throw new OwneyError("NOT_CONNECTED", "Wallet connection changed while connecting.");
|
|
@@ -17812,11 +18248,10 @@ var OwneySDK = class {
|
|
|
17812
18248
|
* Disconnect from all agents and clear connection state.
|
|
17813
18249
|
* After calling this, `connect()` must be called again before using agent methods.
|
|
17814
18250
|
*/
|
|
17815
|
-
async disconnect() {
|
|
18251
|
+
async disconnect(options) {
|
|
17816
18252
|
++this.connectionRevision;
|
|
17817
18253
|
this.clearConnectionState();
|
|
17818
|
-
this.
|
|
17819
|
-
await this.disconnectAgents();
|
|
18254
|
+
await this.disconnectAgents(options);
|
|
17820
18255
|
}
|
|
17821
18256
|
clearConnectionState() {
|
|
17822
18257
|
this.state = null;
|
|
@@ -17828,9 +18263,9 @@ var OwneySDK = class {
|
|
|
17828
18263
|
this.cachedWethSponsoredCallback = null;
|
|
17829
18264
|
this.cachedSponsoredCallsCallbacks.clear();
|
|
17830
18265
|
}
|
|
17831
|
-
disconnectAgents() {
|
|
18266
|
+
disconnectAgents(options) {
|
|
17832
18267
|
if (this.disconnectingAgents) return this.disconnectingAgents;
|
|
17833
|
-
const pending2 = Promise.allSettled([...this.agents.values()].map(async (agent) => agent.disconnect())).then((results) => {
|
|
18268
|
+
const pending2 = Promise.allSettled([...this.agents.values()].map(async (agent) => agent.disconnect(options))).then((results) => {
|
|
17834
18269
|
const failure = results.find((result) => result.status === "rejected");
|
|
17835
18270
|
if (failure?.status === "rejected") throw failure.reason;
|
|
17836
18271
|
});
|
|
@@ -17871,17 +18306,14 @@ var OwneySDK = class {
|
|
|
17871
18306
|
return agent?.isSlotUnavailable?.(state, chainId, asset) === true;
|
|
17872
18307
|
}
|
|
17873
18308
|
/**
|
|
17874
|
-
* The state
|
|
17875
|
-
*
|
|
17876
|
-
*
|
|
17877
|
-
*
|
|
17878
|
-
*
|
|
17879
|
-
* lifts it.
|
|
18309
|
+
* The state every agent read uses: promptless, so a read uses a saved
|
|
18310
|
+
* sign-in only and never opens a wallet prompt. A read that would need one
|
|
18311
|
+
* fails for that agent instead; the app keeps the last known value and
|
|
18312
|
+
* retries later. Only connect/activation and user actions (deposit,
|
|
18313
|
+
* withdraw) may ask the wallet to sign in, and they use the plain state.
|
|
17880
18314
|
*/
|
|
17881
|
-
readStateFor(
|
|
17882
|
-
|
|
17883
|
-
if (state.promptless === true || chainId === null) return state;
|
|
17884
|
-
return this.declinedSignIns.get(chainId)?.has(agentId) === true ? { ...state, promptless: true } : state;
|
|
18315
|
+
readStateFor(state) {
|
|
18316
|
+
return state.promptless === true ? state : { ...state, promptless: true };
|
|
17885
18317
|
}
|
|
17886
18318
|
/**
|
|
17887
18319
|
* Check if the SDK has an active connection state.
|
|
@@ -18105,7 +18537,7 @@ var OwneySDK = class {
|
|
|
18105
18537
|
}
|
|
18106
18538
|
/** The active agents, each with the state its reads use (`readStateFor`). */
|
|
18107
18539
|
activeReads(state, chainId) {
|
|
18108
|
-
return [...this.getActiveAgents()].map(([id, agent]) => ({ id, agent, state: this.readStateFor(
|
|
18540
|
+
return [...this.getActiveAgents()].map(([id, agent]) => ({ id, agent, state: this.readStateFor(state), chainId }));
|
|
18109
18541
|
}
|
|
18110
18542
|
/**
|
|
18111
18543
|
* Read the org's agent policy once and reuse it. fetchOrgAgentConfig never
|
|
@@ -18391,12 +18823,7 @@ var OwneySDK = class {
|
|
|
18391
18823
|
...error instanceof OwneyError && error.details ? { details: error.details } : {}
|
|
18392
18824
|
});
|
|
18393
18825
|
firstError = error;
|
|
18394
|
-
if (this.isUserRejectedWithdrawal(error))
|
|
18395
|
-
walletRejected = true;
|
|
18396
|
-
const declined = this.declinedSignIns.get(chainId) ?? /* @__PURE__ */ new Set();
|
|
18397
|
-
declined.add(agent.id);
|
|
18398
|
-
this.declinedSignIns.set(chainId, declined);
|
|
18399
|
-
}
|
|
18826
|
+
if (this.isUserRejectedWithdrawal(error)) walletRejected = true;
|
|
18400
18827
|
};
|
|
18401
18828
|
for (const agent of agents) {
|
|
18402
18829
|
if (!agent.checkAccount) continue;
|
|
@@ -18423,7 +18850,6 @@ var OwneySDK = class {
|
|
|
18423
18850
|
await this.applyOrgPolicyTo(agent, state, chainId);
|
|
18424
18851
|
this.assertActivationSession(state);
|
|
18425
18852
|
activatedAgentIds.push(agent.id);
|
|
18426
|
-
this.declinedSignIns.get(chainId)?.delete(agent.id);
|
|
18427
18853
|
} catch (error) {
|
|
18428
18854
|
recordFailure(agent, error);
|
|
18429
18855
|
break;
|
|
@@ -19157,7 +19583,8 @@ var OwneySDK = class {
|
|
|
19157
19583
|
}
|
|
19158
19584
|
/** Revalidate a saved transfer against the authenticated account and actual receipt. */
|
|
19159
19585
|
async inspectFunding(evidence, direction, options = {}) {
|
|
19160
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19586
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19587
|
+
const state = this.readStateFor(connection);
|
|
19161
19588
|
if (state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase() || !evidence.txHash)
|
|
19162
19589
|
throw new OwneyError("AGENT_API_ERROR", "Funding evidence does not match the connected account.");
|
|
19163
19590
|
const agent = this.getAgent(evidence.agentId);
|
|
@@ -19270,8 +19697,9 @@ var OwneySDK = class {
|
|
|
19270
19697
|
const movement = evidence.txHash ?? evidence.userOpHash ?? evidence.callsId;
|
|
19271
19698
|
if (!agent?.depositConfirmed || !movement) return;
|
|
19272
19699
|
const key2 = `${state.walletAddress.toLowerCase()}:${chainId}:${evidence.agentId}:${evidence.token}:${movement.toLowerCase()}`;
|
|
19273
|
-
if (this.announcedDeposits.has(key2)) return;
|
|
19700
|
+
if (this.announcedDeposits.has(key2) || wasDepositAnnounced(key2)) return;
|
|
19274
19701
|
this.announcedDeposits.add(key2);
|
|
19702
|
+
rememberAnnouncedDeposit(key2);
|
|
19275
19703
|
if (this.announcedDeposits.size > 256) this.announcedDeposits.delete(this.announcedDeposits.values().next().value);
|
|
19276
19704
|
const legKey = `agent:${evidence.agentId}`;
|
|
19277
19705
|
const record2 = (type, notice) => {
|
|
@@ -19332,7 +19760,8 @@ var OwneySDK = class {
|
|
|
19332
19760
|
const fromBlock = parseBlock(opts?.fromBlock ?? evidence.payoutSearch?.fromBlock);
|
|
19333
19761
|
const cursor = parseBlock(opts?.cursor);
|
|
19334
19762
|
if (fromBlock === null || cursor === null) return null;
|
|
19335
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19763
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19764
|
+
const state = this.readStateFor(connection);
|
|
19336
19765
|
if (typeof evidence.walletAddress !== "string" || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
19337
19766
|
const agent = this.getAgent(evidence.agentId);
|
|
19338
19767
|
const verifiedWallet = agent.getFundingWallet ? await agent.getFundingWallet(state, chainId, evidence.token) : (await agent.getUserProfile(state, chainId)).smartWallet;
|
|
@@ -19357,7 +19786,8 @@ var OwneySDK = class {
|
|
|
19357
19786
|
/** Resolve a saved sponsored-withdrawal ID without opening a wallet prompt. */
|
|
19358
19787
|
async resolveSponsoredWithdrawalEvidence(evidence, options = {}) {
|
|
19359
19788
|
if (evidence.callsId && !evidence.userOpHash) return this.resolveWalletCallsFundingEvidence(evidence, "withdraw");
|
|
19360
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19789
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19790
|
+
const state = this.readStateFor(connection);
|
|
19361
19791
|
if (evidence.agentId !== "yieldseeker" || chainId !== 8453 || evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return evidence;
|
|
19362
19792
|
const agent = this.getAgent("yieldseeker");
|
|
19363
19793
|
const wallet = await agent.getFundingWallet?.(state, chainId, evidence.token);
|
|
@@ -19404,7 +19834,8 @@ var OwneySDK = class {
|
|
|
19404
19834
|
}
|
|
19405
19835
|
/** Recover an EIP-5792 deposit or payout using this account's exact batch ID. */
|
|
19406
19836
|
async resolveWalletCallsFundingEvidence(evidence, direction) {
|
|
19407
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19837
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19838
|
+
const state = this.readStateFor(connection);
|
|
19408
19839
|
if (!evidence.callsId || evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return evidence;
|
|
19409
19840
|
const agent = this.getAgent(evidence.agentId);
|
|
19410
19841
|
const wallet = agent.getFundingWallet ? await agent.getFundingWallet(state, chainId, evidence.token) : (await agent.getUserProfile(state, chainId)).smartWallet;
|
|
@@ -19437,7 +19868,8 @@ var OwneySDK = class {
|
|
|
19437
19868
|
const first = evidences[0];
|
|
19438
19869
|
const saved = !first.txHash && evidences.every((e) => !e.txHash && (e.serverBroadcast === "unknown" || e.serverBroadcast === true) && typeof e.authorizationDeadline === "number");
|
|
19439
19870
|
if (!first.txHash && !saved) return false;
|
|
19440
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(first.chainId);
|
|
19871
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(first.chainId);
|
|
19872
|
+
const state = this.readStateFor(connection);
|
|
19441
19873
|
const token = SupportedAssets.find((value) => value.chainId === chainId && value.symbol === first.token);
|
|
19442
19874
|
if (!token) return false;
|
|
19443
19875
|
const scope = {
|
|
@@ -19554,7 +19986,8 @@ var OwneySDK = class {
|
|
|
19554
19986
|
/** Optional post-payout display proof; receipt verification and the provider
|
|
19555
19987
|
* adapter must agree before attaching it to this exact balance object. */
|
|
19556
19988
|
async verifyWithdrawalBalance(evidence, balance) {
|
|
19557
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19989
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19990
|
+
const state = this.readStateFor(connection);
|
|
19558
19991
|
const agent = this.getAgent(evidence.agentId);
|
|
19559
19992
|
if (!agent.verifyWithdrawalBalance || !evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return balance;
|
|
19560
19993
|
const key2 = `${state.walletAddress.toLowerCase()}:${chainId}:${evidence.agentId}:${evidence.token}:${evidence.txHash}:${evidence.intendedAmount}`;
|
|
@@ -19603,7 +20036,8 @@ var OwneySDK = class {
|
|
|
19603
20036
|
const agent = this.getAgent(evidence.agentId);
|
|
19604
20037
|
if (!agent.getFundingHistory) return { data: [], hasMore: false };
|
|
19605
20038
|
const filters = { tokenSymbol: evidence.token, fromDate, limit: 50, ...options };
|
|
19606
|
-
const
|
|
20039
|
+
const readState = this.readStateFor(state);
|
|
20040
|
+
const page = await this.readAgent(agent, "history", () => agent.getFundingHistory(readState, chainId, filters), filters);
|
|
19607
20041
|
assertCurrent();
|
|
19608
20042
|
return page;
|
|
19609
20043
|
}
|
|
@@ -19620,7 +20054,7 @@ var OwneySDK = class {
|
|
|
19620
20054
|
const state = this.state;
|
|
19621
20055
|
const id = evidence.withdrawalRequest?.providerWithdrawalId;
|
|
19622
20056
|
if (evidence.agentId !== "zyfai" || !id || !state || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
19623
|
-
return this.getAgent("zyfai").getWithdrawalLifecycle(state, id);
|
|
20057
|
+
return this.getAgent("zyfai").getWithdrawalLifecycle(this.readStateFor(state), id);
|
|
19624
20058
|
}
|
|
19625
20059
|
/** A Zyfai deposit's placement status by the id recorded on its evidence. Never signs,
|
|
19626
20060
|
* prompts or authenticates; `null` when unavailable or not this wallet's Zyfai deposit. */
|
|
@@ -19628,7 +20062,7 @@ var OwneySDK = class {
|
|
|
19628
20062
|
const state = this.state;
|
|
19629
20063
|
const id = evidence.providerDepositId;
|
|
19630
20064
|
if (evidence.agentId !== "zyfai" || !id || !state || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
19631
|
-
return this.getAgent("zyfai").getDepositPlacement(state, id);
|
|
20065
|
+
return this.getAgent("zyfai").getDepositPlacement(this.readStateFor(state), id);
|
|
19632
20066
|
}
|
|
19633
20067
|
// --- Fund operations ---
|
|
19634
20068
|
/** On-chain version and ownership status for this owner's Yieldseeker agent. */
|
|
@@ -19636,7 +20070,7 @@ var OwneySDK = class {
|
|
|
19636
20070
|
const state = this.requireState();
|
|
19637
20071
|
const chainId = this.requireChainId();
|
|
19638
20072
|
const agent = this.getAgent("yieldseeker");
|
|
19639
|
-
return agent.getWalletStatus(state, chainId, asset);
|
|
20073
|
+
return agent.getWalletStatus(this.readStateFor(state), chainId, asset);
|
|
19640
20074
|
}
|
|
19641
20075
|
/** Deployment gate; an unavailable response keeps the current paid path. */
|
|
19642
20076
|
async isYieldseekerWithdrawalSponsorshipAvailable() {
|
|
@@ -20709,7 +21143,7 @@ var OwneySDK = class {
|
|
|
20709
21143
|
inspect: (value, fromHistory) => this.inspectFunding(value, "withdraw", { requireAmountMatch: fromHistory, refreshBalance: false }),
|
|
20710
21144
|
resolve: (value) => this.resolveSponsoredWithdrawalEvidence(value, { submittedAt: recovery.submittedAt }),
|
|
20711
21145
|
history: (value, fromDate, filters) => this.getFundingHistory(value, fromDate, filters),
|
|
20712
|
-
verifyCompletion: (value) => this.getAgent(value.agentId).verifyWithdrawalCompletion?.(state, value) ?? Promise.resolve({ status: "unavailable" }),
|
|
21146
|
+
verifyCompletion: (value) => this.getAgent(value.agentId).verifyWithdrawalCompletion?.(this.readStateFor(state), value) ?? Promise.resolve({ status: "unavailable" }),
|
|
20713
21147
|
onProgress: (value) => {
|
|
20714
21148
|
recovery.evidence[value.agentId] = value;
|
|
20715
21149
|
persist();
|
|
@@ -22129,7 +22563,7 @@ var OwneySDK = class {
|
|
|
22129
22563
|
const { state: scope, chainId, assertCurrent } = this.captureReadScope(options?.chainId);
|
|
22130
22564
|
const asset = options?.asset;
|
|
22131
22565
|
const agent = this.getAgent(agentId);
|
|
22132
|
-
const state = this.readStateFor(
|
|
22566
|
+
const state = this.readStateFor(scope);
|
|
22133
22567
|
const result = await this.readAgent(
|
|
22134
22568
|
agent,
|
|
22135
22569
|
"balances",
|
|
@@ -22228,7 +22662,7 @@ var OwneySDK = class {
|
|
|
22228
22662
|
const chainId = this.requireChainId();
|
|
22229
22663
|
if (agentId) {
|
|
22230
22664
|
const agent = this.getAgent(agentId);
|
|
22231
|
-
const readState = this.readStateFor(
|
|
22665
|
+
const readState = this.readStateFor(state);
|
|
22232
22666
|
return this.readAgent(
|
|
22233
22667
|
agent,
|
|
22234
22668
|
"earnings",
|
|
@@ -22258,7 +22692,7 @@ var OwneySDK = class {
|
|
|
22258
22692
|
() => agent.refreshEarnings?.(readState, readChain) ?? agent.getEarnings(readState, readChain),
|
|
22259
22693
|
offChain ? { chainId: readChain } : null
|
|
22260
22694
|
);
|
|
22261
|
-
if (agentId) return refreshAgent({ agent: this.getAgent(agentId), state: this.readStateFor(
|
|
22695
|
+
if (agentId) return refreshAgent({ agent: this.getAgent(agentId), state: this.readStateFor(state), chainId });
|
|
22262
22696
|
return this.aggregateEarnings(this.portfolioReads(state, chainId), refreshAgent);
|
|
22263
22697
|
}
|
|
22264
22698
|
async aggregateEarnings(entries, read2) {
|
|
@@ -22326,7 +22760,7 @@ var OwneySDK = class {
|
|
|
22326
22760
|
for (const agent of agents) {
|
|
22327
22761
|
for (const legChainId of chainIds) {
|
|
22328
22762
|
if (agentRunsOn(agent, legChainId))
|
|
22329
|
-
legs.push({ agent, legChainId, legState: this.readStateFor(
|
|
22763
|
+
legs.push({ agent, legChainId, legState: this.readStateFor(state) });
|
|
22330
22764
|
}
|
|
22331
22765
|
}
|
|
22332
22766
|
if (!agentId) {
|
|
@@ -22366,7 +22800,7 @@ var OwneySDK = class {
|
|
|
22366
22800
|
assets: []
|
|
22367
22801
|
};
|
|
22368
22802
|
}
|
|
22369
|
-
const readState = this.readStateFor(
|
|
22803
|
+
const readState = this.readStateFor(state);
|
|
22370
22804
|
return this.readAgent(
|
|
22371
22805
|
agent,
|
|
22372
22806
|
"dailyEarnings",
|
|
@@ -22447,7 +22881,7 @@ var OwneySDK = class {
|
|
|
22447
22881
|
`Agent ${agent.id} does not support pool customization`
|
|
22448
22882
|
);
|
|
22449
22883
|
}
|
|
22450
|
-
return agent.getPoolSelection(state, chainId, {
|
|
22884
|
+
return agent.getPoolSelection(this.readStateFor(state), chainId, {
|
|
22451
22885
|
pairs: params.pairs,
|
|
22452
22886
|
assets: params.assets
|
|
22453
22887
|
});
|
|
@@ -22472,7 +22906,7 @@ var OwneySDK = class {
|
|
|
22472
22906
|
const scopeChainId = scope === "all" ? null : scope;
|
|
22473
22907
|
if (agentId) {
|
|
22474
22908
|
const agent = this.getAgent(agentId);
|
|
22475
|
-
const readState = this.readStateFor(
|
|
22909
|
+
const readState = this.readStateFor(state);
|
|
22476
22910
|
const accountApy = await this.readAgent(
|
|
22477
22911
|
agent,
|
|
22478
22912
|
"accountApy",
|
|
@@ -22612,7 +23046,7 @@ var OwneySDK = class {
|
|
|
22612
23046
|
for (const agent of agents) {
|
|
22613
23047
|
for (const legChainId of chainIds) {
|
|
22614
23048
|
if (agentRunsOn(agent, legChainId))
|
|
22615
|
-
legs.push({ agentId: agent.id, chainId: legChainId, legState: this.readStateFor(
|
|
23049
|
+
legs.push({ agentId: agent.id, chainId: legChainId, legState: this.readStateFor(state2) });
|
|
22616
23050
|
}
|
|
22617
23051
|
}
|
|
22618
23052
|
if (!agentId) {
|
|
@@ -22656,7 +23090,7 @@ var OwneySDK = class {
|
|
|
22656
23090
|
const { state, chainId, assertCurrent } = this.captureReadScope(options?.chainId);
|
|
22657
23091
|
if (agentId) {
|
|
22658
23092
|
const agent = this.getAgent(agentId);
|
|
22659
|
-
const readState = this.readStateFor(
|
|
23093
|
+
const readState = this.readStateFor(state);
|
|
22660
23094
|
const page = await this.readAgent(agent, "history", () => agent.getHistory(readState, chainId, filters), filters);
|
|
22661
23095
|
assertCurrent();
|
|
22662
23096
|
return page;
|
|
@@ -22671,7 +23105,7 @@ var OwneySDK = class {
|
|
|
22671
23105
|
}
|
|
22672
23106
|
const agentFilters = { ...filters, cursor: agentCursor || void 0 };
|
|
22673
23107
|
try {
|
|
22674
|
-
const readState = this.readStateFor(
|
|
23108
|
+
const readState = this.readStateFor(state);
|
|
22675
23109
|
const page = await this.readAgent(
|
|
22676
23110
|
agent,
|
|
22677
23111
|
"history",
|
|
@@ -22733,7 +23167,7 @@ var OwneySDK = class {
|
|
|
22733
23167
|
const chainId = this.requireChainId();
|
|
22734
23168
|
if (agentId) {
|
|
22735
23169
|
const agent = this.getAgent(agentId);
|
|
22736
|
-
const readState = this.readStateFor(
|
|
23170
|
+
const readState = this.readStateFor(state);
|
|
22737
23171
|
return this.readAgent(
|
|
22738
23172
|
agent,
|
|
22739
23173
|
"profile",
|
|
@@ -22956,7 +23390,7 @@ var OwneySDK = class {
|
|
|
22956
23390
|
const entries = [...activeAgents.entries()];
|
|
22957
23391
|
const balanceResults = await Promise.allSettled(
|
|
22958
23392
|
entries.map(async ([id, agent]) => {
|
|
22959
|
-
const readState = this.readStateFor(
|
|
23393
|
+
const readState = this.readStateFor(state);
|
|
22960
23394
|
const b = await this.readAgent(
|
|
22961
23395
|
agent,
|
|
22962
23396
|
"balances",
|
|
@@ -23015,7 +23449,7 @@ var import_sdk2 = require("@zyfai/sdk");
|
|
|
23015
23449
|
|
|
23016
23450
|
// src/agents/zyfai/zyfai.siwx-cache.ts
|
|
23017
23451
|
var KEY_PREFIX7 = "owney.siwx.session";
|
|
23018
|
-
var
|
|
23452
|
+
var storage10 = () => {
|
|
23019
23453
|
if (typeof window === "undefined") return null;
|
|
23020
23454
|
try {
|
|
23021
23455
|
return window.localStorage;
|
|
@@ -23056,7 +23490,7 @@ var readLegacySiwxSession = (store, address) => {
|
|
|
23056
23490
|
var readSiwxSession = (address, chainId) => {
|
|
23057
23491
|
if (typeof window === "undefined") return null;
|
|
23058
23492
|
const key2 = buildKey3(address);
|
|
23059
|
-
const store =
|
|
23493
|
+
const store = storage10();
|
|
23060
23494
|
let raw2 = null;
|
|
23061
23495
|
try {
|
|
23062
23496
|
raw2 = store?.getItem(key2) ?? null;
|
|
@@ -23086,7 +23520,7 @@ var writeSiwxSession = (address, _chainId, session) => {
|
|
|
23086
23520
|
if (typeof window === "undefined") return;
|
|
23087
23521
|
const key2 = buildKey3(address);
|
|
23088
23522
|
memorySiwxSessions.set(key2, session);
|
|
23089
|
-
const store =
|
|
23523
|
+
const store = storage10();
|
|
23090
23524
|
try {
|
|
23091
23525
|
store?.setItem(key2, JSON.stringify(session));
|
|
23092
23526
|
} catch {
|
|
@@ -23095,7 +23529,7 @@ var writeSiwxSession = (address, _chainId, session) => {
|
|
|
23095
23529
|
var clearSiwxSession = (address, _chainId) => {
|
|
23096
23530
|
const key2 = buildKey3(address);
|
|
23097
23531
|
memorySiwxSessions.delete(key2);
|
|
23098
|
-
const store =
|
|
23532
|
+
const store = storage10();
|
|
23099
23533
|
try {
|
|
23100
23534
|
store?.removeItem(key2);
|
|
23101
23535
|
} catch {
|