@owney/sdk 0.7.32-beta.11 → 0.7.32-beta.12
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 +469 -141
- package/dist/index.d.cts +72 -23
- package/dist/index.d.ts +72 -23
- package/dist/index.js +466 -138
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -717,6 +717,46 @@ async function fetchProviderSnapshot(input) {
|
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
719
|
|
|
720
|
+
// src/lib/announced-deposits.ts
|
|
721
|
+
var KEY = "owney.announced-deposits.v1";
|
|
722
|
+
var TTL_MS = 7 * 24 * 60 * 6e4;
|
|
723
|
+
var MAX_ENTRIES = 256;
|
|
724
|
+
var storage = () => {
|
|
725
|
+
if (typeof window === "undefined") return null;
|
|
726
|
+
try {
|
|
727
|
+
return window.localStorage;
|
|
728
|
+
} catch {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
function load(now) {
|
|
733
|
+
const entries = /* @__PURE__ */ new Map();
|
|
734
|
+
try {
|
|
735
|
+
const raw2 = storage()?.getItem(KEY);
|
|
736
|
+
const parsed = raw2 ? JSON.parse(raw2) : null;
|
|
737
|
+
if (parsed && typeof parsed === "object") {
|
|
738
|
+
for (const [key2, at] of Object.entries(parsed)) {
|
|
739
|
+
if (typeof at === "number" && Number.isFinite(at)) entries.set(key2, Math.max(entries.get(key2) ?? 0, at));
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
} catch {
|
|
743
|
+
}
|
|
744
|
+
for (const [key2, at] of entries) if (at + TTL_MS <= now) entries.delete(key2);
|
|
745
|
+
return entries;
|
|
746
|
+
}
|
|
747
|
+
function wasDepositAnnounced(key2, now = Date.now()) {
|
|
748
|
+
return load(now).has(key2);
|
|
749
|
+
}
|
|
750
|
+
function rememberAnnouncedDeposit(key2, now = Date.now()) {
|
|
751
|
+
const entries = load(now);
|
|
752
|
+
entries.set(key2, now);
|
|
753
|
+
const kept = [...entries].sort((a, b) => a[1] - b[1]).slice(-MAX_ENTRIES);
|
|
754
|
+
try {
|
|
755
|
+
storage()?.setItem(KEY, JSON.stringify(Object.fromEntries(kept)));
|
|
756
|
+
} catch {
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
720
760
|
// src/lib/earnings-hold.ts
|
|
721
761
|
var EARNINGS_HOLD_CAP_MS = 24 * 60 * 6e4;
|
|
722
762
|
var REFRESH_INDEX_WINDOW_MS = 60 * 6e4;
|
|
@@ -1011,7 +1051,7 @@ var SnapshotHistory = class {
|
|
|
1011
1051
|
};
|
|
1012
1052
|
|
|
1013
1053
|
// src/lib/funding-ledger.ts
|
|
1014
|
-
var SDK_VERSION = "0.7.32-beta.
|
|
1054
|
+
var SDK_VERSION = "0.7.32-beta.12";
|
|
1015
1055
|
var SCOPE2 = "funding-ledger";
|
|
1016
1056
|
var REQUEST_TIMEOUT_MS2 = 5e3;
|
|
1017
1057
|
var RETRY_DELAYS_MS = [1e3, 4e3, 16e3];
|
|
@@ -1680,7 +1720,7 @@ function releaseWithdrawalReservationHold(cfg, operationId, holderToken, reason,
|
|
|
1680
1720
|
return track(holderRequest(cfg, operationId, "release", compact2({ holderToken, agents, reason }), RELEASE_RETRY_DELAYS_MS));
|
|
1681
1721
|
}
|
|
1682
1722
|
var memoryTokens = /* @__PURE__ */ new Map();
|
|
1683
|
-
function
|
|
1723
|
+
function storage2() {
|
|
1684
1724
|
try {
|
|
1685
1725
|
const store = globalThis.localStorage;
|
|
1686
1726
|
return store && typeof store.getItem === "function" ? store : null;
|
|
@@ -1704,7 +1744,7 @@ function saveHolderToken(operationId, holderToken, hardExpiresAt = Date.now() +
|
|
|
1704
1744
|
const entry = { token: holderToken, hardExpiresAt };
|
|
1705
1745
|
memoryTokens.set(key2, entry);
|
|
1706
1746
|
try {
|
|
1707
|
-
|
|
1747
|
+
storage2()?.setItem(key2, JSON.stringify(entry));
|
|
1708
1748
|
} catch {
|
|
1709
1749
|
}
|
|
1710
1750
|
}
|
|
@@ -1712,7 +1752,7 @@ function loadHolderToken(operationId, now = Date.now()) {
|
|
|
1712
1752
|
const key2 = STORAGE_PREFIX + operationId.toLowerCase();
|
|
1713
1753
|
let entry;
|
|
1714
1754
|
try {
|
|
1715
|
-
entry = parseStored(
|
|
1755
|
+
entry = parseStored(storage2()?.getItem(key2));
|
|
1716
1756
|
} catch {
|
|
1717
1757
|
}
|
|
1718
1758
|
entry ??= memoryTokens.get(key2);
|
|
@@ -1727,14 +1767,14 @@ function deleteHolderToken(operationId) {
|
|
|
1727
1767
|
const key2 = STORAGE_PREFIX + operationId.toLowerCase();
|
|
1728
1768
|
memoryTokens.delete(key2);
|
|
1729
1769
|
try {
|
|
1730
|
-
|
|
1770
|
+
storage2()?.removeItem(key2);
|
|
1731
1771
|
} catch {
|
|
1732
1772
|
}
|
|
1733
1773
|
}
|
|
1734
1774
|
function sweepHolderTokens(now = Date.now()) {
|
|
1735
1775
|
for (const [key2, entry] of memoryTokens) if (entry.hardExpiresAt <= now) memoryTokens.delete(key2);
|
|
1736
1776
|
try {
|
|
1737
|
-
const store =
|
|
1777
|
+
const store = storage2();
|
|
1738
1778
|
if (!store) return;
|
|
1739
1779
|
const keys = [];
|
|
1740
1780
|
for (let i = 0; i < store.length; i++) {
|
|
@@ -3582,7 +3622,7 @@ function decodeHistoryCursor(token) {
|
|
|
3582
3622
|
|
|
3583
3623
|
// src/agents/zyfai/zyfai.auth-cache.ts
|
|
3584
3624
|
var KEY_PREFIX = "owney.zyfai.session";
|
|
3585
|
-
var
|
|
3625
|
+
var storage3 = () => {
|
|
3586
3626
|
if (typeof window === "undefined") return null;
|
|
3587
3627
|
try {
|
|
3588
3628
|
return window.localStorage;
|
|
@@ -3639,7 +3679,7 @@ var readLegacySession = (store, address) => {
|
|
|
3639
3679
|
var readSession = (address, _chainId) => {
|
|
3640
3680
|
if (typeof window === "undefined") return null;
|
|
3641
3681
|
const key2 = buildKey(address);
|
|
3642
|
-
const store =
|
|
3682
|
+
const store = storage3();
|
|
3643
3683
|
let raw2 = null;
|
|
3644
3684
|
try {
|
|
3645
3685
|
raw2 = store?.getItem(key2) ?? null;
|
|
@@ -3673,7 +3713,7 @@ var writeSession = (address, _chainId, session) => {
|
|
|
3673
3713
|
if (typeof window === "undefined") return;
|
|
3674
3714
|
const key2 = buildKey(address);
|
|
3675
3715
|
memorySessions.set(key2, session);
|
|
3676
|
-
const store =
|
|
3716
|
+
const store = storage3();
|
|
3677
3717
|
try {
|
|
3678
3718
|
store?.setItem(key2, JSON.stringify(session));
|
|
3679
3719
|
} catch {
|
|
@@ -3682,7 +3722,7 @@ var writeSession = (address, _chainId, session) => {
|
|
|
3682
3722
|
var clearSession = (address, _chainId) => {
|
|
3683
3723
|
const key2 = buildKey(address);
|
|
3684
3724
|
memorySessions.delete(key2);
|
|
3685
|
-
const store =
|
|
3725
|
+
const store = storage3();
|
|
3686
3726
|
try {
|
|
3687
3727
|
store?.removeItem(key2);
|
|
3688
3728
|
} catch {
|
|
@@ -4180,6 +4220,8 @@ async function withPaidRpcDiagnostics(operation, chainId, rpcMethod, agentId) {
|
|
|
4180
4220
|
var ERC7579_IS_MODULE_INSTALLED_ABI = parseAbi3([
|
|
4181
4221
|
"function isModuleInstalled(uint256 moduleTypeId, address module, bytes additionalContext) view returns (bool)"
|
|
4182
4222
|
]);
|
|
4223
|
+
var ZYFAI_SIGN_IN_REQUIRED_MESSAGE = "No Zyfai sign-in is available without a prompt.";
|
|
4224
|
+
var isSignInFailure = (error) => error instanceof OwneyError && error.code === "AGENT_AUTH_FAILED";
|
|
4183
4225
|
var WETH_ADDRESS_BY_CHAIN = {
|
|
4184
4226
|
8453: "0x4200000000000000000000000000000000000006",
|
|
4185
4227
|
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
@@ -4294,6 +4336,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4294
4336
|
}
|
|
4295
4337
|
];
|
|
4296
4338
|
sdk;
|
|
4339
|
+
signInRefusedListener;
|
|
4297
4340
|
connectedAddress = null;
|
|
4298
4341
|
connectedChainId = null;
|
|
4299
4342
|
smartWalletCache = /* @__PURE__ */ new Map();
|
|
@@ -4308,6 +4351,12 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4308
4351
|
reportedAccounts = /* @__PURE__ */ new Set();
|
|
4309
4352
|
connectAuthPromise = null;
|
|
4310
4353
|
connectAuthScope = null;
|
|
4354
|
+
/** Whether `connectAuthPromise` is a read's connect, which never signs. */
|
|
4355
|
+
connectAuthPromptless = false;
|
|
4356
|
+
/** Vendor clients that may not sign in: one connecting for a read, and one
|
|
4357
|
+
* whose session a read dropped (the next connect replaces it). Their sign-in
|
|
4358
|
+
* uses the saved session or fails. */
|
|
4359
|
+
promptlessSdks = /* @__PURE__ */ new WeakSet();
|
|
4311
4360
|
connectionGeneration = 0;
|
|
4312
4361
|
sdkHasConnected = false;
|
|
4313
4362
|
rpcUrls;
|
|
@@ -4488,6 +4537,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4488
4537
|
return;
|
|
4489
4538
|
}
|
|
4490
4539
|
}
|
|
4540
|
+
if (this.promptlessSdks.has(sdk)) throw this.signInRequired();
|
|
4491
4541
|
await original();
|
|
4492
4542
|
const newAddress = internals.walletClient?.account?.address;
|
|
4493
4543
|
const newChainId = internals.currentChainId ?? 0;
|
|
@@ -4533,18 +4583,35 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4533
4583
|
if (this.connectedAddress?.toLowerCase() === owner && this.connectedChainId === chainId) return false;
|
|
4534
4584
|
return readSession(state.walletAddress, chainId) === null;
|
|
4535
4585
|
}
|
|
4536
|
-
/**
|
|
4586
|
+
/** A read (promptless state) needs a sign-in it may not ask for. */
|
|
4587
|
+
signInRequired() {
|
|
4588
|
+
return new OwneyError(
|
|
4589
|
+
"AGENT_AUTH_FAILED",
|
|
4590
|
+
ZYFAI_SIGN_IN_REQUIRED_MESSAGE,
|
|
4591
|
+
{ reason: "ZYFAI_SIGN_IN_REQUIRED" },
|
|
4592
|
+
this.id
|
|
4593
|
+
);
|
|
4594
|
+
}
|
|
4595
|
+
/**
|
|
4596
|
+
* Light connect: SIWE auth only. Re-auths if chain changed. Under a
|
|
4597
|
+
* promptless state (a read) it connects with the saved session only and
|
|
4598
|
+
* never opens the wallet's sign-in prompt: with no saved session it fails
|
|
4599
|
+
* at once with `ZYFAI_SIGN_IN_REQUIRED`.
|
|
4600
|
+
*/
|
|
4537
4601
|
async connectAuth(state, chainId) {
|
|
4538
4602
|
const validChainId = isValidChainId(chainId);
|
|
4539
4603
|
const owner = state.walletAddress.toLowerCase();
|
|
4540
4604
|
const scope = `${owner}:${validChainId}`;
|
|
4605
|
+
const promptless = state.promptless === true;
|
|
4541
4606
|
if (this.connectedAddress?.toLowerCase() === owner && this.connectedChainId === validChainId) {
|
|
4542
4607
|
return;
|
|
4543
4608
|
}
|
|
4544
4609
|
if (this.connectAuthPromise && this.connectAuthScope === scope) {
|
|
4545
|
-
await this.connectAuthPromise;
|
|
4610
|
+
if (this.connectAuthPromptless && !promptless) await this.connectAuthPromise.catch(() => void 0);
|
|
4611
|
+
else await this.connectAuthPromise;
|
|
4546
4612
|
return this.connectAuth(state, chainId);
|
|
4547
4613
|
}
|
|
4614
|
+
if (promptless && readSession(state.walletAddress, validChainId) === null) throw this.signInRequired();
|
|
4548
4615
|
if (this.sdkHasConnected || this.connectedAddress) this.sdk = this.createSdk();
|
|
4549
4616
|
this.sdkHasConnected = true;
|
|
4550
4617
|
const executionSdk = this.sdk;
|
|
@@ -4557,7 +4624,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4557
4624
|
const address = await this.connectAccountWithRetry(
|
|
4558
4625
|
state.provider,
|
|
4559
4626
|
validChainId,
|
|
4560
|
-
executionSdk
|
|
4627
|
+
executionSdk,
|
|
4628
|
+
promptless
|
|
4561
4629
|
);
|
|
4562
4630
|
if (generation !== this.connectionGeneration || address.toLowerCase() !== owner)
|
|
4563
4631
|
throw new OwneyError("NOT_CONNECTED", "Wallet changed while connecting Zyfai.", void 0, this.id);
|
|
@@ -4566,12 +4634,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4566
4634
|
})();
|
|
4567
4635
|
this.connectAuthPromise = pending;
|
|
4568
4636
|
this.connectAuthScope = scope;
|
|
4637
|
+
this.connectAuthPromptless = promptless;
|
|
4569
4638
|
try {
|
|
4570
4639
|
await pending;
|
|
4571
4640
|
} finally {
|
|
4572
4641
|
if (this.connectAuthPromise === pending) {
|
|
4573
4642
|
this.connectAuthPromise = null;
|
|
4574
4643
|
this.connectAuthScope = null;
|
|
4644
|
+
this.connectAuthPromptless = false;
|
|
4575
4645
|
}
|
|
4576
4646
|
}
|
|
4577
4647
|
}
|
|
@@ -4584,19 +4654,86 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4584
4654
|
* which does not separate a revoked JWT from a misconfigured API key; we
|
|
4585
4655
|
* retry once either way, and if the second attempt still fails the original
|
|
4586
4656
|
* error propagates.
|
|
4657
|
+
*
|
|
4658
|
+
* `promptless` (a read): the saved session only. The patched
|
|
4659
|
+
* `authenticateUser` will not fall back to the SIWE prompt for this client,
|
|
4660
|
+
* and a refused session is dropped without a retry
|
|
4661
|
+
* (`dropRefusedReadSession`); the next sign-in is the user's.
|
|
4587
4662
|
*/
|
|
4588
|
-
async connectAccountWithRetry(provider, chainId, executionSdk = this.sdk) {
|
|
4663
|
+
async connectAccountWithRetry(provider, chainId, executionSdk = this.sdk, promptless = false) {
|
|
4664
|
+
if (promptless) this.promptlessSdks.add(executionSdk);
|
|
4589
4665
|
try {
|
|
4590
|
-
|
|
4666
|
+
const address = await executionSdk.connectAccount(provider, chainId);
|
|
4667
|
+
this.promptlessSdks.delete(executionSdk);
|
|
4668
|
+
return address;
|
|
4591
4669
|
} catch (error) {
|
|
4592
4670
|
const message = error instanceof Error ? error.message : String(error);
|
|
4593
4671
|
if (!message.toLowerCase().includes("unauthorized")) throw error;
|
|
4594
4672
|
const internals = executionSdk;
|
|
4595
4673
|
const address = internals.walletClient?.account?.address;
|
|
4674
|
+
if (promptless) throw this.dropRefusedReadSession(address, executionSdk, internals.httpClient.authToken, message);
|
|
4596
4675
|
if (address) clearSession(address, chainId);
|
|
4597
4676
|
return await executionSdk.connectAccount(provider, chainId);
|
|
4598
4677
|
}
|
|
4599
4678
|
}
|
|
4679
|
+
setSignInRefusedListener(listener) {
|
|
4680
|
+
this.signInRefusedListener = listener;
|
|
4681
|
+
}
|
|
4682
|
+
/** A saved session was dropped because Zyfai refused it (not during connect). */
|
|
4683
|
+
tellSignInRefused() {
|
|
4684
|
+
try {
|
|
4685
|
+
this.signInRefusedListener?.();
|
|
4686
|
+
} catch {
|
|
4687
|
+
}
|
|
4688
|
+
}
|
|
4689
|
+
/**
|
|
4690
|
+
* Zyfai refused the session a read used (HTTP 401): the one place a read
|
|
4691
|
+
* drops a refused session. The saved session is cleared unless it was
|
|
4692
|
+
* renewed meanwhile, and the client stops using its token and may no longer
|
|
4693
|
+
* sign in, so no read reuses the session or signs in again: reads now need
|
|
4694
|
+
* a sign-in (`ensureReadSession` sees no live session), and the next one is
|
|
4695
|
+
* the user's (connect, deposit, withdraw), on a new client. Returns the
|
|
4696
|
+
* read's error.
|
|
4697
|
+
*/
|
|
4698
|
+
dropRefusedReadSession(owner, executionSdk, authToken, refusal) {
|
|
4699
|
+
debugLog("zyfai:auth", "a read's session was refused; dropped without signing in again", { refusal });
|
|
4700
|
+
if (owner && typeof authToken === "string") {
|
|
4701
|
+
let dropped = false;
|
|
4702
|
+
if (readSession(owner, 0)?.token === authToken) {
|
|
4703
|
+
clearSession(owner, 0);
|
|
4704
|
+
dropped = true;
|
|
4705
|
+
}
|
|
4706
|
+
const internals = executionSdk;
|
|
4707
|
+
if (internals.httpClient.authToken === authToken) {
|
|
4708
|
+
dropped = true;
|
|
4709
|
+
internals.httpClient.clearAuthToken();
|
|
4710
|
+
internals.authenticatedUserId = null;
|
|
4711
|
+
this.promptlessSdks.add(executionSdk);
|
|
4712
|
+
if (executionSdk === this.sdk && this.connectedAddress?.toLowerCase() === owner.toLowerCase())
|
|
4713
|
+
this.connectedChainId = null;
|
|
4714
|
+
}
|
|
4715
|
+
if (dropped) this.tellSignInRefused();
|
|
4716
|
+
}
|
|
4717
|
+
return this.signInRequired();
|
|
4718
|
+
}
|
|
4719
|
+
/**
|
|
4720
|
+
* One data call of a read, on `executionSdk`. Under a promptless state a
|
|
4721
|
+
* session Zyfai refuses (`isZyfaiSessionRejected`) is dropped
|
|
4722
|
+
* (`dropRefusedReadSession`) and the read fails with
|
|
4723
|
+
* `ZYFAI_SIGN_IN_REQUIRED`, never signing in again.
|
|
4724
|
+
*/
|
|
4725
|
+
async readCall(state, call, executionSdk = this.sdk) {
|
|
4726
|
+
const authToken = executionSdk.httpClient?.authToken;
|
|
4727
|
+
try {
|
|
4728
|
+
return await call();
|
|
4729
|
+
} catch (error) {
|
|
4730
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4731
|
+
if (state.promptless !== true || error instanceof OwneyError) throw error;
|
|
4732
|
+
if (message.includes(ZYFAI_SIGN_IN_REQUIRED_MESSAGE)) throw this.signInRequired();
|
|
4733
|
+
if (!isZyfaiSessionRejected(message)) throw error;
|
|
4734
|
+
throw this.dropRefusedReadSession(state.walletAddress, executionSdk, authToken, message);
|
|
4735
|
+
}
|
|
4736
|
+
}
|
|
4600
4737
|
/**
|
|
4601
4738
|
* Reconnect if the Zyfai connection was torn down behind our back: a
|
|
4602
4739
|
* chain/account switch fires the provider's `accountsChanged` →
|
|
@@ -4634,6 +4771,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4634
4771
|
internals.httpClient.clearAuthToken();
|
|
4635
4772
|
internals.authenticatedUserId = null;
|
|
4636
4773
|
this.connectedChainId = null;
|
|
4774
|
+
this.tellSignInRefused();
|
|
4637
4775
|
}
|
|
4638
4776
|
/**
|
|
4639
4777
|
* Sync newly-available protocols onto an existing user's profile at wallet
|
|
@@ -4685,11 +4823,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4685
4823
|
* per chain, in parallel) cancel each other's sign-in. Funding keeps
|
|
4686
4824
|
* `connectAuth`/`ensureConnected`. Returns the owner verified for this call,
|
|
4687
4825
|
* so a later reconnect cannot leave the caller without an address.
|
|
4826
|
+
* The client reads under a promptless state, so with no live session this
|
|
4827
|
+
* connects from the saved one or fails without a prompt (`connectAuth`).
|
|
4688
4828
|
*/
|
|
4689
4829
|
async ensureReadSession(state, chainId) {
|
|
4690
4830
|
const owner = state.walletAddress?.toLowerCase();
|
|
4691
4831
|
if (this.connectAuthPromise) await this.connectAuthPromise.catch(() => void 0);
|
|
4692
|
-
if (!owner || this.connectedAddress?.toLowerCase() !== owner
|
|
4832
|
+
if (!owner || this.connectedAddress?.toLowerCase() !== owner || this.connectedChainId === null)
|
|
4833
|
+
await this.connectAuth(state, chainId);
|
|
4693
4834
|
}
|
|
4694
4835
|
/** `ensureReadSession`, then the owner it verified, read in the same turn. */
|
|
4695
4836
|
async connectForRead(state, chainId) {
|
|
@@ -4723,7 +4864,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4723
4864
|
return pending;
|
|
4724
4865
|
}
|
|
4725
4866
|
// --- IAgent: Connection lifecycle ---
|
|
4726
|
-
async disconnect() {
|
|
4867
|
+
async disconnect(options) {
|
|
4727
4868
|
const executionSdk = this.sdk;
|
|
4728
4869
|
this.connectionGeneration++;
|
|
4729
4870
|
this.earningsGeneration++;
|
|
@@ -4736,7 +4877,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4736
4877
|
this.holdActiveScopes.clear();
|
|
4737
4878
|
this.pendingRegistrations.clear();
|
|
4738
4879
|
this.lastGoodEarnings.clear();
|
|
4739
|
-
if (this.connectedAddress && this.connectedChainId !== null) {
|
|
4880
|
+
if (!options?.keepSignIns && this.connectedAddress && this.connectedChainId !== null) {
|
|
4740
4881
|
clearSession(this.connectedAddress, this.connectedChainId);
|
|
4741
4882
|
}
|
|
4742
4883
|
this.connectedAddress = null;
|
|
@@ -5114,13 +5255,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5114
5255
|
Promise.all(
|
|
5115
5256
|
params.pairs.map(async ({ protocolId, chainId: chainId2 }) => {
|
|
5116
5257
|
try {
|
|
5117
|
-
const current = await this.sdk.getSelectedPools(
|
|
5258
|
+
const current = await this.readCall(state, () => this.sdk.getSelectedPools(
|
|
5118
5259
|
protocolId,
|
|
5119
5260
|
chainId2
|
|
5120
|
-
);
|
|
5261
|
+
));
|
|
5121
5262
|
if (current.autoselect) return null;
|
|
5122
5263
|
return { protocolId, chainId: chainId2, pools: current.pools ?? [] };
|
|
5123
|
-
} catch {
|
|
5264
|
+
} catch (error) {
|
|
5265
|
+
if (isSignInFailure(error)) throw error;
|
|
5124
5266
|
return null;
|
|
5125
5267
|
}
|
|
5126
5268
|
})
|
|
@@ -5128,9 +5270,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5128
5270
|
Promise.all(
|
|
5129
5271
|
params.assets.map(async (asset) => {
|
|
5130
5272
|
try {
|
|
5131
|
-
const current = await this.sdk.getUserDetails(asset);
|
|
5273
|
+
const current = await this.readCall(state, () => this.sdk.getUserDetails(asset));
|
|
5132
5274
|
return current.strategy ? { asset, strategy: current.strategy } : null;
|
|
5133
|
-
} catch {
|
|
5275
|
+
} catch (error) {
|
|
5276
|
+
if (isSignInFailure(error)) throw error;
|
|
5134
5277
|
return null;
|
|
5135
5278
|
}
|
|
5136
5279
|
})
|
|
@@ -6523,7 +6666,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6523
6666
|
const requestedAt = Date.now();
|
|
6524
6667
|
const generation = this.earningsGeneration;
|
|
6525
6668
|
const { smartWallet, chainId: validChainId } = await this.resolveSmartWallet(state, chainId);
|
|
6526
|
-
const raw2 = await this.sdk.getPortfolio(this.getAddress());
|
|
6669
|
+
const raw2 = await this.readCall(state, () => this.sdk.getPortfolio(this.getAddress()));
|
|
6527
6670
|
debugLog("zyfai:balances", "read", { ms: Date.now() - requestedAt });
|
|
6528
6671
|
const balance = mapBalances(raw2, validChainId, smartWallet);
|
|
6529
6672
|
const reads = balance.readMetadata?.map((read2) => ({ ...read2, requestedAt })) ?? [];
|
|
@@ -6585,7 +6728,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6585
6728
|
async getEarnings(state, chainId) {
|
|
6586
6729
|
const { smartWallet } = await this.resolveSmartWallet(state, chainId);
|
|
6587
6730
|
const key2 = this.earningsKey(state, chainId, smartWallet);
|
|
6588
|
-
const raw2 = await this.readEarnings(key2, smartWallet);
|
|
6731
|
+
const raw2 = await this.readCall(state, () => this.readEarnings(key2, smartWallet));
|
|
6589
6732
|
const held = await this.holdEarnings(state, chainId, smartWallet, key2, raw2);
|
|
6590
6733
|
if (held.active) void this.refreshEarnings(state, chainId).catch(() => void 0);
|
|
6591
6734
|
return mapEarnings(held.value, smartWallet);
|
|
@@ -6736,7 +6879,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6736
6879
|
if (existing) return existing;
|
|
6737
6880
|
const pending = (async () => {
|
|
6738
6881
|
const recent = this.earningsSnapshot;
|
|
6739
|
-
const current = recent?.key === key2 && Date.now() - recent.at < 5e3 ? recent.raw : await this.readEarnings(key2, smartWallet);
|
|
6882
|
+
const current = recent?.key === key2 && Date.now() - recent.at < 5e3 ? recent.raw : await this.readCall(state, () => this.readEarnings(key2, smartWallet), executionSdk);
|
|
6740
6883
|
const lastCheck = current.data.lastCheckTimestamp ? Date.parse(current.data.lastCheckTimestamp) : Number.NaN;
|
|
6741
6884
|
const mapped = mapEarnings(current, smartWallet);
|
|
6742
6885
|
const held = await this.holdEarnings(state, chainId, smartWallet, key2, current);
|
|
@@ -6750,7 +6893,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6750
6893
|
if (isFresh && !negative || !canCalculate)
|
|
6751
6894
|
return held.active ? mapEarnings(held.value, smartWallet) : mapped;
|
|
6752
6895
|
this.earningsCalculationAttempts.set(calculationKey, now);
|
|
6753
|
-
const earnings = await executionSdk.calculateOnchainEarnings(smartWallet);
|
|
6896
|
+
const earnings = await this.readCall(state, () => executionSdk.calculateOnchainEarnings(smartWallet), executionSdk);
|
|
6754
6897
|
assertCurrent();
|
|
6755
6898
|
this.earningsSnapshot = { key: key2, raw: earnings, at: Date.now() };
|
|
6756
6899
|
const recalculated = await this.holdEarnings(state, chainId, smartWallet, key2, earnings);
|
|
@@ -6765,7 +6908,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6765
6908
|
}
|
|
6766
6909
|
async getAccountApy(state, chainId, days, tokenSymbol, scopeChainId) {
|
|
6767
6910
|
const { smartWallet } = await this.resolveSmartWallet(state, chainId);
|
|
6768
|
-
const raw2 = await this.sdk.getDailyApyHistory(smartWallet, days);
|
|
6911
|
+
const raw2 = await this.readCall(state, () => this.sdk.getDailyApyHistory(smartWallet, days));
|
|
6769
6912
|
const scope = scopeChainId === null ? void 0 : scopeChainId ?? chainId;
|
|
6770
6913
|
const ethUsd = tokenSymbol === void 0 && holdsEthPosition(raw2) ? await readEthUsdPrice(this.getPublicClient(8453)) : void 0;
|
|
6771
6914
|
return mapApyHistory(raw2, scope, tokenSymbol, ethUsd);
|
|
@@ -6775,10 +6918,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6775
6918
|
const start = new Date(
|
|
6776
6919
|
Date.now() - (DayFilterMapping[days] + 1) * 864e5
|
|
6777
6920
|
);
|
|
6778
|
-
const raw2 = await this.sdk.getDailyEarnings(
|
|
6921
|
+
const raw2 = await this.readCall(state, () => this.sdk.getDailyEarnings(
|
|
6779
6922
|
smartWallet,
|
|
6780
6923
|
start.toISOString().slice(0, 10)
|
|
6781
|
-
);
|
|
6924
|
+
));
|
|
6782
6925
|
return mapDailyEarnings(raw2, chainId, tokenSymbol);
|
|
6783
6926
|
}
|
|
6784
6927
|
/**
|
|
@@ -6822,7 +6965,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6822
6965
|
const matched = [];
|
|
6823
6966
|
let backendExhausted = false;
|
|
6824
6967
|
for (let i = 0; i < MAX_BACKEND_CALLS && matched.length < limit; i++) {
|
|
6825
|
-
const raw2 = await this.sdk.getHistory(smartWallet, validChainId, {
|
|
6968
|
+
const raw2 = await this.readCall(state, () => this.sdk.getHistory(smartWallet, validChainId, {
|
|
6826
6969
|
limit: backendPageSize,
|
|
6827
6970
|
offset,
|
|
6828
6971
|
fromDate: options?.fromDate,
|
|
@@ -6832,7 +6975,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6832
6975
|
// relevant entries instead of spending its budget on the other
|
|
6833
6976
|
// asset's rows and handing back a page that filters to nothing.
|
|
6834
6977
|
assetType
|
|
6835
|
-
});
|
|
6978
|
+
}));
|
|
6836
6979
|
raw2.data.forEach((entry, idx) => {
|
|
6837
6980
|
if (entry.chainId === validChainId) {
|
|
6838
6981
|
matched.push({ entry, rawIdx: offset + idx });
|
|
@@ -6868,7 +7011,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6868
7011
|
}
|
|
6869
7012
|
async getUserProfile(state, chainId) {
|
|
6870
7013
|
await this.ensureReadSession(state, chainId);
|
|
6871
|
-
const raw2 = await this.sdk.getUserDetails();
|
|
7014
|
+
const raw2 = await this.readCall(state, () => this.sdk.getUserDetails());
|
|
6872
7015
|
debugLog("zyfai:profile", "getUserProfile \u2014 Zyfai reports", {
|
|
6873
7016
|
asset: "USDC (default \u2014 no asset passed)",
|
|
6874
7017
|
splitting: raw2.splitting,
|
|
@@ -6977,7 +7120,7 @@ var INVALIDATED_KEY_PREFIXES = [
|
|
|
6977
7120
|
"owney.yieldseeker.session.v3",
|
|
6978
7121
|
"owney.yieldseeker.session.v4"
|
|
6979
7122
|
];
|
|
6980
|
-
var
|
|
7123
|
+
var storage4 = () => {
|
|
6981
7124
|
if (typeof window === "undefined") return null;
|
|
6982
7125
|
try {
|
|
6983
7126
|
return window.localStorage;
|
|
@@ -7011,7 +7154,7 @@ var isValidSession = (session) => {
|
|
|
7011
7154
|
var readYieldseekerSession = (address, chainId) => {
|
|
7012
7155
|
if (typeof window === "undefined") return null;
|
|
7013
7156
|
const key2 = buildKey2(address, chainId);
|
|
7014
|
-
const store =
|
|
7157
|
+
const store = storage4();
|
|
7015
7158
|
clearInvalidatedSessions(store, address, chainId);
|
|
7016
7159
|
let raw2 = null;
|
|
7017
7160
|
try {
|
|
@@ -7043,7 +7186,7 @@ var writeYieldseekerSession = (address, chainId, token) => {
|
|
|
7043
7186
|
if (!isValidSession(session)) return;
|
|
7044
7187
|
const key2 = buildKey2(address, chainId);
|
|
7045
7188
|
memorySessions2.set(key2, session);
|
|
7046
|
-
const store =
|
|
7189
|
+
const store = storage4();
|
|
7047
7190
|
try {
|
|
7048
7191
|
store?.setItem(key2, JSON.stringify(session));
|
|
7049
7192
|
} catch {
|
|
@@ -7052,7 +7195,7 @@ var writeYieldseekerSession = (address, chainId, token) => {
|
|
|
7052
7195
|
var clearYieldseekerSession = (address, chainId) => {
|
|
7053
7196
|
const key2 = buildKey2(address, chainId);
|
|
7054
7197
|
memorySessions2.delete(key2);
|
|
7055
|
-
const store =
|
|
7198
|
+
const store = storage4();
|
|
7056
7199
|
clearInvalidatedSessions(store, address, chainId);
|
|
7057
7200
|
try {
|
|
7058
7201
|
store?.removeItem(key2);
|
|
@@ -7164,12 +7307,21 @@ var YieldseekerAuth = class {
|
|
|
7164
7307
|
return this.getToken(state, chainId);
|
|
7165
7308
|
}
|
|
7166
7309
|
/** Drop a proof the provider refused, without signing a new one: a
|
|
7167
|
-
* promptless read cannot renew it, and must stop offering it.
|
|
7310
|
+
* promptless read cannot renew it, and must stop offering it. Returns
|
|
7311
|
+
* whether it dropped anything: false when the proof was already dropped or
|
|
7312
|
+
* replaced meanwhile. */
|
|
7168
7313
|
discardToken(state, chainId, rejectedToken) {
|
|
7169
7314
|
const key2 = this.key(state, chainId);
|
|
7170
|
-
|
|
7171
|
-
if (
|
|
7315
|
+
let dropped = false;
|
|
7316
|
+
if (this.tokens.get(key2) === rejectedToken) {
|
|
7317
|
+
this.tokens.delete(key2);
|
|
7318
|
+
dropped = true;
|
|
7319
|
+
}
|
|
7320
|
+
if (readYieldseekerSession(state.walletAddress, chainId) === rejectedToken) {
|
|
7172
7321
|
clearYieldseekerSession(state.walletAddress, chainId);
|
|
7322
|
+
dropped = true;
|
|
7323
|
+
}
|
|
7324
|
+
return dropped;
|
|
7173
7325
|
}
|
|
7174
7326
|
isReusable(token, state, chainId) {
|
|
7175
7327
|
try {
|
|
@@ -7185,6 +7337,12 @@ var YieldseekerAuth = class {
|
|
|
7185
7337
|
return false;
|
|
7186
7338
|
}
|
|
7187
7339
|
}
|
|
7340
|
+
/** Drops what this instance holds in memory; saved sign-ins in storage stay. */
|
|
7341
|
+
forgetInMemory() {
|
|
7342
|
+
this.tokens.clear();
|
|
7343
|
+
this.pending.clear();
|
|
7344
|
+
this.scopes.clear();
|
|
7345
|
+
}
|
|
7188
7346
|
clear(state, chainId) {
|
|
7189
7347
|
if (!state || chainId === void 0) {
|
|
7190
7348
|
for (const scope of this.scopes.values()) {
|
|
@@ -7229,9 +7387,9 @@ var YieldseekerAuth = class {
|
|
|
7229
7387
|
|
|
7230
7388
|
// src/agents/yieldseeker/yieldseeker.identity-cache.ts
|
|
7231
7389
|
var KEY_PREFIX3 = "owney.yieldseeker.identity.v1";
|
|
7232
|
-
var YIELDSEEKER_IDENTITY_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
7390
|
+
var YIELDSEEKER_IDENTITY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
7233
7391
|
var memoryIdentities = /* @__PURE__ */ new Map();
|
|
7234
|
-
var
|
|
7392
|
+
var storage5 = () => {
|
|
7235
7393
|
if (typeof window === "undefined") return null;
|
|
7236
7394
|
try {
|
|
7237
7395
|
return window.localStorage;
|
|
@@ -7248,7 +7406,7 @@ function valid(value, walletAddress, chainId, now) {
|
|
|
7248
7406
|
function readYieldseekerIdentity(walletAddress, chainId, now = Date.now()) {
|
|
7249
7407
|
if (typeof window === "undefined") return null;
|
|
7250
7408
|
const key2 = keyFor(walletAddress, chainId);
|
|
7251
|
-
const store =
|
|
7409
|
+
const store = storage5();
|
|
7252
7410
|
let parsed = null;
|
|
7253
7411
|
try {
|
|
7254
7412
|
const raw2 = store?.getItem(key2);
|
|
@@ -7280,7 +7438,7 @@ function writeYieldseekerIdentity(walletAddress, chainId, userId, now = Date.now
|
|
|
7280
7438
|
const key2 = keyFor(walletAddress, chainId);
|
|
7281
7439
|
memoryIdentities.set(key2, identity);
|
|
7282
7440
|
try {
|
|
7283
|
-
|
|
7441
|
+
storage5()?.setItem(key2, JSON.stringify(identity));
|
|
7284
7442
|
} catch {
|
|
7285
7443
|
}
|
|
7286
7444
|
}
|
|
@@ -7288,9 +7446,41 @@ function clearYieldseekerIdentity(walletAddress, chainId) {
|
|
|
7288
7446
|
const key2 = keyFor(walletAddress, chainId);
|
|
7289
7447
|
memoryIdentities.delete(key2);
|
|
7290
7448
|
try {
|
|
7291
|
-
|
|
7449
|
+
storage5()?.removeItem(key2);
|
|
7450
|
+
} catch {
|
|
7451
|
+
}
|
|
7452
|
+
}
|
|
7453
|
+
|
|
7454
|
+
// src/agents/yieldseeker/yieldseeker.login-cooldown.ts
|
|
7455
|
+
var KEY2 = "owney.yieldseeker.login-cooldown.v1";
|
|
7456
|
+
var YIELDSEEKER_LOGIN_COOLDOWN_FLOOR_MS = 3 * 6e4;
|
|
7457
|
+
var memoryUntil = 0;
|
|
7458
|
+
var storage6 = () => {
|
|
7459
|
+
if (typeof window === "undefined") return null;
|
|
7460
|
+
try {
|
|
7461
|
+
return window.localStorage;
|
|
7462
|
+
} catch {
|
|
7463
|
+
return null;
|
|
7464
|
+
}
|
|
7465
|
+
};
|
|
7466
|
+
function readYieldseekerLoginCooldown(now = Date.now()) {
|
|
7467
|
+
let until = memoryUntil;
|
|
7468
|
+
try {
|
|
7469
|
+
const stored = Number(storage6()?.getItem(KEY2));
|
|
7470
|
+
if (Number.isSafeInteger(stored) && stored > until) until = stored;
|
|
7471
|
+
} catch {
|
|
7472
|
+
}
|
|
7473
|
+
return until > now ? until : void 0;
|
|
7474
|
+
}
|
|
7475
|
+
function startYieldseekerLoginCooldown(retryAfterMs, now = Date.now()) {
|
|
7476
|
+
const wait3 = Math.max(YIELDSEEKER_LOGIN_COOLDOWN_FLOOR_MS, Number.isFinite(retryAfterMs) ? retryAfterMs : 0);
|
|
7477
|
+
const until = Math.max(readYieldseekerLoginCooldown(now) ?? 0, now + wait3);
|
|
7478
|
+
memoryUntil = until;
|
|
7479
|
+
try {
|
|
7480
|
+
storage6()?.setItem(KEY2, String(until));
|
|
7292
7481
|
} catch {
|
|
7293
7482
|
}
|
|
7483
|
+
return until;
|
|
7294
7484
|
}
|
|
7295
7485
|
|
|
7296
7486
|
// src/agents/yieldseeker/yieldseeker.client.ts
|
|
@@ -8953,6 +9143,12 @@ function generateYieldseekerUsername() {
|
|
|
8953
9143
|
const suffix = globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, YIELDSEEKER_USERNAME_RANDOM_LENGTH).toLowerCase();
|
|
8954
9144
|
return `${YIELDSEEKER_USERNAME_PREFIX}${suffix}`;
|
|
8955
9145
|
}
|
|
9146
|
+
function isSignInRateLimit(error) {
|
|
9147
|
+
return error instanceof YieldseekerApiError && error.status === 429;
|
|
9148
|
+
}
|
|
9149
|
+
function isWalletAlreadyRegistered(error) {
|
|
9150
|
+
return error instanceof YieldseekerApiError && error.providerCode.toUpperCase() === "USER_WALLET_EXISTS";
|
|
9151
|
+
}
|
|
8956
9152
|
function isUsernameConflict(error) {
|
|
8957
9153
|
if (!(error instanceof YieldseekerApiError)) return false;
|
|
8958
9154
|
const code = error.providerCode.toUpperCase();
|
|
@@ -9100,6 +9296,15 @@ var YieldseekerAgent = class {
|
|
|
9100
9296
|
balanceContexts = /* @__PURE__ */ new WeakMap();
|
|
9101
9297
|
balanceVaults = /* @__PURE__ */ new Map();
|
|
9102
9298
|
users = /* @__PURE__ */ new Map();
|
|
9299
|
+
/**
|
|
9300
|
+
* Agent wallets (lowercase) this page started releasing vault funds from for
|
|
9301
|
+
* a withdrawal, and when. Until the payout is done the released money sits
|
|
9302
|
+
* in the agent wallet, so no deposit notice may go out (it would be
|
|
9303
|
+
* reinvested). The ledger shows the same once it lists the withdrawal.
|
|
9304
|
+
*/
|
|
9305
|
+
releasingWallets = /* @__PURE__ */ new Map();
|
|
9306
|
+
/** One login (and, for a new wallet, one create) per wallet and chain at a time. */
|
|
9307
|
+
pendingUsers = /* @__PURE__ */ new Map();
|
|
9103
9308
|
pendingAgents = /* @__PURE__ */ new Map();
|
|
9104
9309
|
pendingWalletContexts = /* @__PURE__ */ new Map();
|
|
9105
9310
|
readCache = /* @__PURE__ */ new Map();
|
|
@@ -9126,6 +9331,7 @@ var YieldseekerAgent = class {
|
|
|
9126
9331
|
// or while the ledger read is null, settlement and earnings are as before.
|
|
9127
9332
|
ledgerAccess;
|
|
9128
9333
|
accountRefusedListener;
|
|
9334
|
+
signInRefusedListener;
|
|
9129
9335
|
ledgerReads = /* @__PURE__ */ new Map();
|
|
9130
9336
|
/** contextKey -> movements this instance started settling (by tx hash) and how they refresh:
|
|
9131
9337
|
* awaiting the ledger, refreshed when ready (ledger), or on the timed backoff (legacy). */
|
|
@@ -9421,16 +9627,16 @@ var YieldseekerAgent = class {
|
|
|
9421
9627
|
this.rememberWalletStatus(versionKey, status);
|
|
9422
9628
|
return { txHash: hash2, status };
|
|
9423
9629
|
};
|
|
9424
|
-
let
|
|
9630
|
+
let storage11;
|
|
9425
9631
|
try {
|
|
9426
|
-
|
|
9632
|
+
storage11 = typeof window === "undefined" ? void 0 : window.localStorage;
|
|
9427
9633
|
} catch {
|
|
9428
|
-
|
|
9634
|
+
storage11 = void 0;
|
|
9429
9635
|
}
|
|
9430
9636
|
const clearRecordedUpgrade = () => {
|
|
9431
9637
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9432
9638
|
try {
|
|
9433
|
-
|
|
9639
|
+
storage11?.removeItem(pendingKey2);
|
|
9434
9640
|
} catch {
|
|
9435
9641
|
this.pendingUpgrades.set(pendingKey2, null);
|
|
9436
9642
|
}
|
|
@@ -9453,7 +9659,7 @@ var YieldseekerAgent = class {
|
|
|
9453
9659
|
throw pendingUpgrade(hash2);
|
|
9454
9660
|
}
|
|
9455
9661
|
};
|
|
9456
|
-
if (!
|
|
9662
|
+
if (!storage11 && (gasMode === "sponsored" || before.ownerPath === "smart"))
|
|
9457
9663
|
throw new OwneyError(
|
|
9458
9664
|
"SPONSOR_REQUEST_FAILED",
|
|
9459
9665
|
"Upgrade status cannot be saved in this browser.",
|
|
@@ -9462,14 +9668,14 @@ var YieldseekerAgent = class {
|
|
|
9462
9668
|
);
|
|
9463
9669
|
let prior = null;
|
|
9464
9670
|
try {
|
|
9465
|
-
const saved = this.pendingUpgrades.has(pendingKey2) ? JSON.stringify(this.pendingUpgrades.get(pendingKey2)) :
|
|
9671
|
+
const saved = this.pendingUpgrades.has(pendingKey2) ? JSON.stringify(this.pendingUpgrades.get(pendingKey2)) : storage11?.getItem(pendingKey2);
|
|
9466
9672
|
try {
|
|
9467
9673
|
prior = JSON.parse(saved ?? "null");
|
|
9468
9674
|
} catch {
|
|
9469
9675
|
prior = { callsId: void 0 };
|
|
9470
9676
|
}
|
|
9471
9677
|
} catch {
|
|
9472
|
-
if (gasMode === "paid" && before.ownerPath === "eoa")
|
|
9678
|
+
if (gasMode === "paid" && before.ownerPath === "eoa") storage11 = void 0;
|
|
9473
9679
|
else throw new OwneyError(
|
|
9474
9680
|
"SPONSOR_REQUEST_FAILED",
|
|
9475
9681
|
"Upgrade status cannot be read in this browser.",
|
|
@@ -9563,9 +9769,9 @@ var YieldseekerAgent = class {
|
|
|
9563
9769
|
asset: YIELDSEEKER_ASSET_METADATA[asset].address,
|
|
9564
9770
|
callData: data,
|
|
9565
9771
|
onPending: (pending) => {
|
|
9566
|
-
const current = this.pendingUpgrades.has(pendingKey2) ? this.pendingUpgrades.get(pendingKey2) : JSON.parse(
|
|
9772
|
+
const current = this.pendingUpgrades.has(pendingKey2) ? this.pendingUpgrades.get(pendingKey2) : JSON.parse(storage11.getItem(pendingKey2) ?? "null");
|
|
9567
9773
|
const next = { startedAt: Date.now(), ...current, ...pending };
|
|
9568
|
-
|
|
9774
|
+
storage11.setItem(pendingKey2, JSON.stringify(next));
|
|
9569
9775
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9570
9776
|
}
|
|
9571
9777
|
});
|
|
@@ -9589,8 +9795,8 @@ var YieldseekerAgent = class {
|
|
|
9589
9795
|
const pending = { txHash: hash2 };
|
|
9590
9796
|
this.pendingUpgrades.set(pendingKey2, pending);
|
|
9591
9797
|
try {
|
|
9592
|
-
if (
|
|
9593
|
-
|
|
9798
|
+
if (storage11) {
|
|
9799
|
+
storage11.setItem(pendingKey2, JSON.stringify(pending));
|
|
9594
9800
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9595
9801
|
}
|
|
9596
9802
|
} catch {
|
|
@@ -9611,14 +9817,18 @@ var YieldseekerAgent = class {
|
|
|
9611
9817
|
clearRecordedUpgrade();
|
|
9612
9818
|
return confirmed;
|
|
9613
9819
|
}
|
|
9614
|
-
async disconnect() {
|
|
9820
|
+
async disconnect(options) {
|
|
9615
9821
|
this.withdrawalVersionCache.clear();
|
|
9616
9822
|
this.pendingWalletStatus.clear();
|
|
9617
9823
|
this.readGeneration += 1;
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9824
|
+
if (options?.keepSignIns) {
|
|
9825
|
+
this.auth.forgetInMemory();
|
|
9826
|
+
} else {
|
|
9827
|
+
this.auth.clear();
|
|
9828
|
+
for (const key2 of this.users.keys()) {
|
|
9829
|
+
const [walletAddress, chainId] = key2.split(":");
|
|
9830
|
+
clearYieldseekerIdentity(walletAddress, Number(chainId));
|
|
9831
|
+
}
|
|
9622
9832
|
}
|
|
9623
9833
|
this.users.clear();
|
|
9624
9834
|
this.agentContexts.clear();
|
|
@@ -10212,6 +10422,7 @@ var YieldseekerAgent = class {
|
|
|
10212
10422
|
const unwind = async (position2, assetsRaw) => {
|
|
10213
10423
|
this.assertSession(generation, chainId, asset);
|
|
10214
10424
|
assertOperation?.();
|
|
10425
|
+
this.releasingWallets.set(context.wallet.walletAddress.toLowerCase(), Date.now());
|
|
10215
10426
|
let unwindTransactionHash;
|
|
10216
10427
|
try {
|
|
10217
10428
|
const response = await this.walletRequest(
|
|
@@ -11007,7 +11218,9 @@ var YieldseekerAgent = class {
|
|
|
11007
11218
|
* left idle. While it has not, Yieldseeker is told again, up to
|
|
11008
11219
|
* DEPOSIT_NOTICE_ATTEMPTS calls in all; a failed call (network, server, rate
|
|
11009
11220
|
* limit) is sent again after a wait. Within an hour of a withdrawal it is
|
|
11010
|
-
* told once, since nothing can move yet.
|
|
11221
|
+
* told once, since nothing can move yet. While a withdrawal from the agent
|
|
11222
|
+
* wallet is under way it is not told at all: its released funds wait in that
|
|
11223
|
+
* wallet for the payout, and a notice would reinvest them (ROUT-790). Uses the agent this session already
|
|
11011
11224
|
* knows for the asset and the saved sign-in only: never prompts, never
|
|
11012
11225
|
* throws. Each call is reported through `onNotice`.
|
|
11013
11226
|
*/
|
|
@@ -11024,6 +11237,8 @@ var YieldseekerAgent = class {
|
|
|
11024
11237
|
if (!this.auth.peekToken(state, chainId)) return { notified: false, reason: "NO_SESSION" };
|
|
11025
11238
|
const generation = this.readGeneration;
|
|
11026
11239
|
const amount = parseRawAmount(evidence.confirmedAmount ?? evidence.intendedAmount);
|
|
11240
|
+
if (await this.withdrawalUnderWay(state, chainId, slotAsset, context))
|
|
11241
|
+
return { notified: false, reason: "WITHDRAWAL_IN_PROGRESS" };
|
|
11027
11242
|
const cooldownEnds = await this.withdrawalCooldownEnd(state, chainId, slotAsset, context);
|
|
11028
11243
|
let notified = false;
|
|
11029
11244
|
let reason = "NOT_ALLOCATED";
|
|
@@ -11114,6 +11329,19 @@ var YieldseekerAgent = class {
|
|
|
11114
11329
|
* confirmed withdrawal, if that is still ahead; null when there was none in
|
|
11115
11330
|
* the last hour or the ledger cannot say.
|
|
11116
11331
|
*/
|
|
11332
|
+
/**
|
|
11333
|
+
* A withdrawal from this agent wallet that has started but not finished,
|
|
11334
|
+
* within the last hour: released by this page, or listed on the ledger with
|
|
11335
|
+
* the agent's leg still created, submitted or unknown. Older unfinished rows
|
|
11336
|
+
* do not count, so a stuck record cannot hold deposits back for good.
|
|
11337
|
+
*/
|
|
11338
|
+
async withdrawalUnderWay(state, chainId, asset, context) {
|
|
11339
|
+
const wallet = context.wallet.walletAddress.toLowerCase();
|
|
11340
|
+
const since = Date.now() - YIELDSEEKER_WITHDRAWAL_COOLDOWN_MS;
|
|
11341
|
+
if ((this.releasingWallets.get(wallet) ?? 0) > since) return true;
|
|
11342
|
+
const rows = await withinBudget(this.readLedger(state, chainId, asset), this.ledgerBudgetMs, null);
|
|
11343
|
+
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)));
|
|
11344
|
+
}
|
|
11117
11345
|
async withdrawalCooldownEnd(state, chainId, asset, context) {
|
|
11118
11346
|
const rows = await withinBudget(this.readLedger(state, chainId, asset), this.ledgerBudgetMs, null);
|
|
11119
11347
|
const wallet = context.wallet.walletAddress.toLowerCase();
|
|
@@ -12229,6 +12457,29 @@ var YieldseekerAgent = class {
|
|
|
12229
12457
|
this.users.set(key2, persisted);
|
|
12230
12458
|
return persisted;
|
|
12231
12459
|
}
|
|
12460
|
+
const pending = this.pendingUsers.get(key2);
|
|
12461
|
+
if (pending) return pending;
|
|
12462
|
+
const request2 = this.signInUser(state, chainId);
|
|
12463
|
+
this.pendingUsers.set(key2, request2);
|
|
12464
|
+
try {
|
|
12465
|
+
return await request2;
|
|
12466
|
+
} finally {
|
|
12467
|
+
if (this.pendingUsers.get(key2) === request2) this.pendingUsers.delete(key2);
|
|
12468
|
+
}
|
|
12469
|
+
}
|
|
12470
|
+
/**
|
|
12471
|
+
* `login-with-wallet`, and `POST /users` for a wallet without an account.
|
|
12472
|
+
* Both draw on Yieldseeker's per-IP sign-in allowance, which all our users
|
|
12473
|
+
* share: while a 429's pause lasts nothing is sent, and a new 429 starts one.
|
|
12474
|
+
*/
|
|
12475
|
+
async signInUser(state, chainId) {
|
|
12476
|
+
const key2 = this.userKey(state, chainId);
|
|
12477
|
+
const pausedUntil = readYieldseekerLoginCooldown();
|
|
12478
|
+
if (pausedUntil !== void 0) throw this.signInRateLimited(pausedUntil);
|
|
12479
|
+
const limited = (error) => {
|
|
12480
|
+
const retryAfter = error instanceof YieldseekerApiError ? rateLimitDelay({ status: error.status, fields: error.responseFields }) : rateLimitDelay(error);
|
|
12481
|
+
throw this.signInRateLimited(startYieldseekerLoginCooldown(retryAfter));
|
|
12482
|
+
};
|
|
12232
12483
|
const walletAddress = getAddress6(state.walletAddress);
|
|
12233
12484
|
const generation = this.readGeneration;
|
|
12234
12485
|
let user = null;
|
|
@@ -12246,11 +12497,13 @@ var YieldseekerAgent = class {
|
|
|
12246
12497
|
});
|
|
12247
12498
|
}
|
|
12248
12499
|
} catch (error) {
|
|
12500
|
+
if (isSignInRateLimit(error)) limited(error);
|
|
12249
12501
|
if (!(error instanceof YieldseekerApiError) || error.providerCode !== "NO_USER") {
|
|
12250
12502
|
if (error instanceof OwneyError) throw error;
|
|
12251
12503
|
throw this.mapRequestFailure(error);
|
|
12252
12504
|
}
|
|
12253
12505
|
let created;
|
|
12506
|
+
let registeredMeanwhile = false;
|
|
12254
12507
|
for (let attempt = 0; attempt < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS; attempt += 1) {
|
|
12255
12508
|
try {
|
|
12256
12509
|
created = await this.providerRequest(
|
|
@@ -12267,12 +12520,32 @@ var YieldseekerAgent = class {
|
|
|
12267
12520
|
);
|
|
12268
12521
|
break;
|
|
12269
12522
|
} catch (createError) {
|
|
12523
|
+
if (isSignInRateLimit(createError)) limited(createError);
|
|
12524
|
+
if (isWalletAlreadyRegistered(createError)) {
|
|
12525
|
+
registeredMeanwhile = true;
|
|
12526
|
+
break;
|
|
12527
|
+
}
|
|
12270
12528
|
const canRetry = isUsernameConflict(createError) && attempt + 1 < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS;
|
|
12271
12529
|
if (canRetry) continue;
|
|
12272
12530
|
throw this.mapRequestFailure(createError);
|
|
12273
12531
|
}
|
|
12274
12532
|
}
|
|
12275
12533
|
user = created?.user ?? null;
|
|
12534
|
+
if (registeredMeanwhile) {
|
|
12535
|
+
try {
|
|
12536
|
+
const login = await this.providerRequest(
|
|
12537
|
+
state,
|
|
12538
|
+
chainId,
|
|
12539
|
+
"/users/login-with-wallet",
|
|
12540
|
+
{ method: "POST", body: { walletAddress } }
|
|
12541
|
+
);
|
|
12542
|
+
user = login?.user ?? null;
|
|
12543
|
+
} catch (loginError) {
|
|
12544
|
+
if (isSignInRateLimit(loginError)) limited(loginError);
|
|
12545
|
+
if (loginError instanceof OwneyError) throw loginError;
|
|
12546
|
+
throw this.mapRequestFailure(loginError);
|
|
12547
|
+
}
|
|
12548
|
+
}
|
|
12276
12549
|
}
|
|
12277
12550
|
if (!user || !/^[a-zA-Z0-9_-]{1,128}$/.test(user.userId)) {
|
|
12278
12551
|
throw this.invalidResponse("wallet identity");
|
|
@@ -12283,6 +12556,19 @@ var YieldseekerAgent = class {
|
|
|
12283
12556
|
writeYieldseekerIdentity(state.walletAddress, chainId, resolved.userId);
|
|
12284
12557
|
return resolved;
|
|
12285
12558
|
}
|
|
12559
|
+
signInRateLimited(until) {
|
|
12560
|
+
return new OwneyError(
|
|
12561
|
+
"AGENT_RATE_LIMITED",
|
|
12562
|
+
"Too many sign-in attempts right now. Please wait before trying again.",
|
|
12563
|
+
{
|
|
12564
|
+
reason: "YIELDSEEKER_SIGN_IN_RATE_LIMITED",
|
|
12565
|
+
statusCode: 429,
|
|
12566
|
+
retryAt: until,
|
|
12567
|
+
retryAfterSeconds: Math.max(0, Math.ceil((until - Date.now()) / 1e3))
|
|
12568
|
+
},
|
|
12569
|
+
this.id
|
|
12570
|
+
);
|
|
12571
|
+
}
|
|
12286
12572
|
forgetUser(state, chainId) {
|
|
12287
12573
|
this.users.delete(this.userKey(state, chainId));
|
|
12288
12574
|
clearYieldseekerIdentity(state.walletAddress, chainId);
|
|
@@ -12764,6 +13050,9 @@ var YieldseekerAgent = class {
|
|
|
12764
13050
|
setAccountRefusedListener(listener) {
|
|
12765
13051
|
this.accountRefusedListener = listener;
|
|
12766
13052
|
}
|
|
13053
|
+
setSignInRefusedListener(listener) {
|
|
13054
|
+
this.signInRefusedListener = listener;
|
|
13055
|
+
}
|
|
12767
13056
|
setFundingLedgerAccess(access) {
|
|
12768
13057
|
this.ledgerAccess = access;
|
|
12769
13058
|
this.ledgerReads.clear();
|
|
@@ -13157,7 +13446,13 @@ var YieldseekerAgent = class {
|
|
|
13157
13446
|
if (error.providerCode === "NO_USER") throw error;
|
|
13158
13447
|
if (!error.isAuthenticationError) throw error;
|
|
13159
13448
|
if (promptless) {
|
|
13160
|
-
this.auth.discardToken(state, chainId, signature);
|
|
13449
|
+
const dropped = this.auth.discardToken(state, chainId, signature);
|
|
13450
|
+
if (dropped) {
|
|
13451
|
+
try {
|
|
13452
|
+
this.signInRefusedListener?.();
|
|
13453
|
+
} catch {
|
|
13454
|
+
}
|
|
13455
|
+
}
|
|
13161
13456
|
throw error;
|
|
13162
13457
|
}
|
|
13163
13458
|
signature = await this.auth.refreshToken(state, chainId, signature);
|
|
@@ -14267,7 +14562,7 @@ function runSameChainOrder(deps, options) {
|
|
|
14267
14562
|
|
|
14268
14563
|
// src/lib/swap/swap.secret-store.ts
|
|
14269
14564
|
var KEY_PREFIX4 = "owney.swap.order";
|
|
14270
|
-
var
|
|
14565
|
+
var storage7 = () => {
|
|
14271
14566
|
if (typeof window === "undefined") return null;
|
|
14272
14567
|
try {
|
|
14273
14568
|
return window.localStorage;
|
|
@@ -14277,7 +14572,7 @@ var storage5 = () => {
|
|
|
14277
14572
|
};
|
|
14278
14573
|
var keyFor2 = (orderHash) => `${KEY_PREFIX4}.${orderHash}`;
|
|
14279
14574
|
function saveOrder(order) {
|
|
14280
|
-
const store =
|
|
14575
|
+
const store = storage7();
|
|
14281
14576
|
if (!store) return false;
|
|
14282
14577
|
try {
|
|
14283
14578
|
const value = JSON.stringify(order);
|
|
@@ -14288,7 +14583,7 @@ function saveOrder(order) {
|
|
|
14288
14583
|
}
|
|
14289
14584
|
}
|
|
14290
14585
|
function loadOrder(orderHash) {
|
|
14291
|
-
const store =
|
|
14586
|
+
const store = storage7();
|
|
14292
14587
|
if (!store) return null;
|
|
14293
14588
|
try {
|
|
14294
14589
|
const raw2 = store.getItem(keyFor2(orderHash));
|
|
@@ -14303,7 +14598,7 @@ function loadOrder(orderHash) {
|
|
|
14303
14598
|
}
|
|
14304
14599
|
}
|
|
14305
14600
|
function clearOrder(orderHash) {
|
|
14306
|
-
const store =
|
|
14601
|
+
const store = storage7();
|
|
14307
14602
|
if (!store) return;
|
|
14308
14603
|
try {
|
|
14309
14604
|
store.removeItem(keyFor2(orderHash));
|
|
@@ -14311,7 +14606,7 @@ function clearOrder(orderHash) {
|
|
|
14311
14606
|
}
|
|
14312
14607
|
}
|
|
14313
14608
|
function listOrders(_now = Date.now()) {
|
|
14314
|
-
const store =
|
|
14609
|
+
const store = storage7();
|
|
14315
14610
|
if (!store) return [];
|
|
14316
14611
|
const out = [];
|
|
14317
14612
|
try {
|
|
@@ -15122,7 +15417,7 @@ async function buildErc2612Permit(reads, input) {
|
|
|
15122
15417
|
// src/lib/swap/swap.withdraw-swap.ts
|
|
15123
15418
|
var KEY_PREFIX5 = "owney.swap.withdraw";
|
|
15124
15419
|
var MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
15125
|
-
var
|
|
15420
|
+
var storage8 = () => {
|
|
15126
15421
|
if (typeof window === "undefined") return null;
|
|
15127
15422
|
try {
|
|
15128
15423
|
return window.localStorage;
|
|
@@ -15147,7 +15442,7 @@ var notify = () => {
|
|
|
15147
15442
|
}
|
|
15148
15443
|
};
|
|
15149
15444
|
function saveWithdrawSwap(record2) {
|
|
15150
|
-
const store =
|
|
15445
|
+
const store = storage8();
|
|
15151
15446
|
if (!store) return false;
|
|
15152
15447
|
try {
|
|
15153
15448
|
const current = store.getItem(keyFor3(record2.orderHash));
|
|
@@ -15161,7 +15456,7 @@ function saveWithdrawSwap(record2) {
|
|
|
15161
15456
|
return true;
|
|
15162
15457
|
}
|
|
15163
15458
|
function updateWithdrawSwap(orderHash, patch) {
|
|
15164
|
-
const store =
|
|
15459
|
+
const store = storage8();
|
|
15165
15460
|
if (!store) return;
|
|
15166
15461
|
try {
|
|
15167
15462
|
const raw2 = store.getItem(keyFor3(orderHash));
|
|
@@ -15178,7 +15473,7 @@ function updateWithdrawSwap(orderHash, patch) {
|
|
|
15178
15473
|
notify();
|
|
15179
15474
|
}
|
|
15180
15475
|
function clearWithdrawSwap(orderHash) {
|
|
15181
|
-
const store =
|
|
15476
|
+
const store = storage8();
|
|
15182
15477
|
if (!store) return;
|
|
15183
15478
|
try {
|
|
15184
15479
|
const raw2 = store.getItem(keyFor3(orderHash));
|
|
@@ -15192,7 +15487,7 @@ function clearWithdrawSwap(orderHash) {
|
|
|
15192
15487
|
notify();
|
|
15193
15488
|
}
|
|
15194
15489
|
function listWithdrawSwaps(now = Date.now(), includeDismissed = false) {
|
|
15195
|
-
const store =
|
|
15490
|
+
const store = storage8();
|
|
15196
15491
|
if (!store) return [];
|
|
15197
15492
|
const out = [];
|
|
15198
15493
|
try {
|
|
@@ -15229,7 +15524,7 @@ if (typeof window !== "undefined" && typeof window.addEventListener === "functio
|
|
|
15229
15524
|
// src/lib/swap/swap.pending-deposit.ts
|
|
15230
15525
|
var KEY_PREFIX6 = "owney.swap.pending-deposit";
|
|
15231
15526
|
var MAX_AGE_MS2 = 24 * 60 * 60 * 1e3;
|
|
15232
|
-
var
|
|
15527
|
+
var storage9 = () => {
|
|
15233
15528
|
if (typeof window === "undefined") return null;
|
|
15234
15529
|
try {
|
|
15235
15530
|
return window.localStorage;
|
|
@@ -15239,7 +15534,7 @@ var storage7 = () => {
|
|
|
15239
15534
|
};
|
|
15240
15535
|
var keyFor4 = (id) => `${KEY_PREFIX6}.${id}`;
|
|
15241
15536
|
function savePendingDeposit(entry) {
|
|
15242
|
-
const store =
|
|
15537
|
+
const store = storage9();
|
|
15243
15538
|
if (!store) return;
|
|
15244
15539
|
try {
|
|
15245
15540
|
store.setItem(keyFor4(entry.id), JSON.stringify(entry));
|
|
@@ -15248,7 +15543,7 @@ function savePendingDeposit(entry) {
|
|
|
15248
15543
|
}
|
|
15249
15544
|
}
|
|
15250
15545
|
function clearPendingDeposit(id) {
|
|
15251
|
-
const store =
|
|
15546
|
+
const store = storage9();
|
|
15252
15547
|
if (!store) return;
|
|
15253
15548
|
try {
|
|
15254
15549
|
store.removeItem(keyFor4(id));
|
|
@@ -15257,7 +15552,7 @@ function clearPendingDeposit(id) {
|
|
|
15257
15552
|
}
|
|
15258
15553
|
}
|
|
15259
15554
|
function listPendingDeposits(now = Date.now()) {
|
|
15260
|
-
const store =
|
|
15555
|
+
const store = storage9();
|
|
15261
15556
|
if (!store) return [];
|
|
15262
15557
|
const out = [];
|
|
15263
15558
|
try {
|
|
@@ -16760,15 +17055,8 @@ var OwneySDK = class {
|
|
|
16760
17055
|
*/
|
|
16761
17056
|
disabledAgents = /* @__PURE__ */ new Set();
|
|
16762
17057
|
accountRefusedListeners = /* @__PURE__ */ new Set();
|
|
17058
|
+
signInRefusedListeners = /* @__PURE__ */ new Set();
|
|
16763
17059
|
signInProgressListeners = /* @__PURE__ */ new Set();
|
|
16764
|
-
/**
|
|
16765
|
-
* Agents whose sign-in the user cancelled this session (the wallet rejected
|
|
16766
|
-
* the prompt), keyed by chain. Until the app ends the session they are read
|
|
16767
|
-
* from a saved sign-in only (`readStateFor`), so no read reopens the prompt
|
|
16768
|
-
* the user cancelled. A later successful activation of the agent removes
|
|
16769
|
-
* it, and `disconnect()` or a different wallet's `connect()` clears the map.
|
|
16770
|
-
*/
|
|
16771
|
-
declinedSignIns = /* @__PURE__ */ new Map();
|
|
16772
17060
|
state = null;
|
|
16773
17061
|
connectionRevision = 0;
|
|
16774
17062
|
disconnectingAgents = null;
|
|
@@ -16975,7 +17263,7 @@ var OwneySDK = class {
|
|
|
16975
17263
|
read: async () => {
|
|
16976
17264
|
const state = this.state;
|
|
16977
17265
|
if (!state || state.walletAddress.toLowerCase() !== owner) return null;
|
|
16978
|
-
const sample = await agent.providerEarningsSample(state, evidence.chainId);
|
|
17266
|
+
const sample = await agent.providerEarningsSample(this.readStateFor(state), evidence.chainId);
|
|
16979
17267
|
return sample ? { ...sample, observedAt: (/* @__PURE__ */ new Date()).toISOString() } : null;
|
|
16980
17268
|
},
|
|
16981
17269
|
emit: (data) => op.event?.("provider.sample", data)
|
|
@@ -16994,6 +17282,19 @@ var OwneySDK = class {
|
|
|
16994
17282
|
this.accountRefusedListeners.delete(listener);
|
|
16995
17283
|
};
|
|
16996
17284
|
}
|
|
17285
|
+
/**
|
|
17286
|
+
* Listens for an agent dropping a saved sign-in its server refused, outside
|
|
17287
|
+
* connect (a read or a withdrawal found it refused). The agent will not
|
|
17288
|
+
* sign in again by itself; the next sign-in is the user's. Not fired where a
|
|
17289
|
+
* refused sign-in is renewed (connect, deposit). Returns the unsubscribe
|
|
17290
|
+
* function.
|
|
17291
|
+
*/
|
|
17292
|
+
onSignInRefused(listener) {
|
|
17293
|
+
this.signInRefusedListeners.add(listener);
|
|
17294
|
+
return () => {
|
|
17295
|
+
this.signInRefusedListeners.delete(listener);
|
|
17296
|
+
};
|
|
17297
|
+
}
|
|
16997
17298
|
/**
|
|
16998
17299
|
* Listens for the sign-ins a connect asks for (`SignInProgress`): which
|
|
16999
17300
|
* agents will ask the wallet to sign in, and each one as it starts and ends,
|
|
@@ -17007,6 +17308,28 @@ var OwneySDK = class {
|
|
|
17007
17308
|
this.signInProgressListeners.delete(listener);
|
|
17008
17309
|
};
|
|
17009
17310
|
}
|
|
17311
|
+
/**
|
|
17312
|
+
* The agents that would ask the wallet to sign in on `chainId` right now:
|
|
17313
|
+
* enabled agents on that chain whose `needsSignIn` says yes. One with no
|
|
17314
|
+
* such check counts as no; one that throws counts as yes, so an unknown
|
|
17315
|
+
* answer never lets the app retry quietly into a prompt. Never prompts and
|
|
17316
|
+
* never calls the network. Empty before connect.
|
|
17317
|
+
*/
|
|
17318
|
+
signInsNeeded(chainId) {
|
|
17319
|
+
const state = this.state;
|
|
17320
|
+
if (state === null) return [];
|
|
17321
|
+
const needed = [];
|
|
17322
|
+
for (const [id, agent] of this.agents) {
|
|
17323
|
+
if (this.isAgentDisabled(id)) continue;
|
|
17324
|
+
if (!agent.supportedChainIds.includes(chainId)) continue;
|
|
17325
|
+
try {
|
|
17326
|
+
if (agent.needsSignIn?.(state, chainId) === true) needed.push(id);
|
|
17327
|
+
} catch {
|
|
17328
|
+
needed.push(id);
|
|
17329
|
+
}
|
|
17330
|
+
}
|
|
17331
|
+
return needed;
|
|
17332
|
+
}
|
|
17010
17333
|
/**
|
|
17011
17334
|
* The sign-ins this connect asks for: the agents whose `needsSignIn` says
|
|
17012
17335
|
* yes now (one that throws counts as no). Each is announced at its first
|
|
@@ -17064,6 +17387,14 @@ var OwneySDK = class {
|
|
|
17064
17387
|
}
|
|
17065
17388
|
}
|
|
17066
17389
|
});
|
|
17390
|
+
agent.setSignInRefusedListener?.(() => {
|
|
17391
|
+
for (const listener of [...this.signInRefusedListeners]) {
|
|
17392
|
+
try {
|
|
17393
|
+
listener(agent.id);
|
|
17394
|
+
} catch {
|
|
17395
|
+
}
|
|
17396
|
+
}
|
|
17397
|
+
});
|
|
17067
17398
|
}
|
|
17068
17399
|
/**
|
|
17069
17400
|
* Funding-ledger read access handed to agents for earnings holds. Reads only
|
|
@@ -17143,7 +17474,6 @@ var OwneySDK = class {
|
|
|
17143
17474
|
}
|
|
17144
17475
|
const replacingOwner = this.state !== null && this.state.walletAddress.toLowerCase() !== walletAddress.toLowerCase();
|
|
17145
17476
|
this.clearConnectionState();
|
|
17146
|
-
if (replacingOwner) this.declinedSignIns.clear();
|
|
17147
17477
|
await (replacingOwner ? this.disconnectAgents() : this.disconnectingAgents);
|
|
17148
17478
|
if (revision !== this.connectionRevision)
|
|
17149
17479
|
throw new OwneyError("NOT_CONNECTED", "Wallet connection changed while connecting.");
|
|
@@ -17157,11 +17487,10 @@ var OwneySDK = class {
|
|
|
17157
17487
|
* Disconnect from all agents and clear connection state.
|
|
17158
17488
|
* After calling this, `connect()` must be called again before using agent methods.
|
|
17159
17489
|
*/
|
|
17160
|
-
async disconnect() {
|
|
17490
|
+
async disconnect(options) {
|
|
17161
17491
|
++this.connectionRevision;
|
|
17162
17492
|
this.clearConnectionState();
|
|
17163
|
-
this.
|
|
17164
|
-
await this.disconnectAgents();
|
|
17493
|
+
await this.disconnectAgents(options);
|
|
17165
17494
|
}
|
|
17166
17495
|
clearConnectionState() {
|
|
17167
17496
|
this.state = null;
|
|
@@ -17173,9 +17502,9 @@ var OwneySDK = class {
|
|
|
17173
17502
|
this.cachedWethSponsoredCallback = null;
|
|
17174
17503
|
this.cachedSponsoredCallsCallbacks.clear();
|
|
17175
17504
|
}
|
|
17176
|
-
disconnectAgents() {
|
|
17505
|
+
disconnectAgents(options) {
|
|
17177
17506
|
if (this.disconnectingAgents) return this.disconnectingAgents;
|
|
17178
|
-
const pending = Promise.allSettled([...this.agents.values()].map(async (agent) => agent.disconnect())).then((results) => {
|
|
17507
|
+
const pending = Promise.allSettled([...this.agents.values()].map(async (agent) => agent.disconnect(options))).then((results) => {
|
|
17179
17508
|
const failure = results.find((result) => result.status === "rejected");
|
|
17180
17509
|
if (failure?.status === "rejected") throw failure.reason;
|
|
17181
17510
|
});
|
|
@@ -17216,17 +17545,14 @@ var OwneySDK = class {
|
|
|
17216
17545
|
return agent?.isSlotUnavailable?.(state, chainId, asset) === true;
|
|
17217
17546
|
}
|
|
17218
17547
|
/**
|
|
17219
|
-
* The state
|
|
17220
|
-
*
|
|
17221
|
-
*
|
|
17222
|
-
*
|
|
17223
|
-
*
|
|
17224
|
-
* lifts it.
|
|
17548
|
+
* The state every agent read uses: promptless, so a read uses a saved
|
|
17549
|
+
* sign-in only and never opens a wallet prompt. A read that would need one
|
|
17550
|
+
* fails for that agent instead; the app keeps the last known value and
|
|
17551
|
+
* retries later. Only connect/activation and user actions (deposit,
|
|
17552
|
+
* withdraw) may ask the wallet to sign in, and they use the plain state.
|
|
17225
17553
|
*/
|
|
17226
|
-
readStateFor(
|
|
17227
|
-
|
|
17228
|
-
if (state.promptless === true || chainId === null) return state;
|
|
17229
|
-
return this.declinedSignIns.get(chainId)?.has(agentId) === true ? { ...state, promptless: true } : state;
|
|
17554
|
+
readStateFor(state) {
|
|
17555
|
+
return state.promptless === true ? state : { ...state, promptless: true };
|
|
17230
17556
|
}
|
|
17231
17557
|
/**
|
|
17232
17558
|
* Check if the SDK has an active connection state.
|
|
@@ -17450,7 +17776,7 @@ var OwneySDK = class {
|
|
|
17450
17776
|
}
|
|
17451
17777
|
/** The active agents, each with the state its reads use (`readStateFor`). */
|
|
17452
17778
|
activeReads(state, chainId) {
|
|
17453
|
-
return [...this.getActiveAgents()].map(([id, agent]) => ({ id, agent, state: this.readStateFor(
|
|
17779
|
+
return [...this.getActiveAgents()].map(([id, agent]) => ({ id, agent, state: this.readStateFor(state), chainId }));
|
|
17454
17780
|
}
|
|
17455
17781
|
/**
|
|
17456
17782
|
* Read the org's agent policy once and reuse it. fetchOrgAgentConfig never
|
|
@@ -17736,12 +18062,7 @@ var OwneySDK = class {
|
|
|
17736
18062
|
...error instanceof OwneyError && error.details ? { details: error.details } : {}
|
|
17737
18063
|
});
|
|
17738
18064
|
firstError = error;
|
|
17739
|
-
if (this.isUserRejectedWithdrawal(error))
|
|
17740
|
-
walletRejected = true;
|
|
17741
|
-
const declined = this.declinedSignIns.get(chainId) ?? /* @__PURE__ */ new Set();
|
|
17742
|
-
declined.add(agent.id);
|
|
17743
|
-
this.declinedSignIns.set(chainId, declined);
|
|
17744
|
-
}
|
|
18065
|
+
if (this.isUserRejectedWithdrawal(error)) walletRejected = true;
|
|
17745
18066
|
};
|
|
17746
18067
|
for (const agent of agents) {
|
|
17747
18068
|
if (!agent.checkAccount) continue;
|
|
@@ -17768,7 +18089,6 @@ var OwneySDK = class {
|
|
|
17768
18089
|
await this.applyOrgPolicyTo(agent, state, chainId);
|
|
17769
18090
|
this.assertActivationSession(state);
|
|
17770
18091
|
activatedAgentIds.push(agent.id);
|
|
17771
|
-
this.declinedSignIns.get(chainId)?.delete(agent.id);
|
|
17772
18092
|
} catch (error) {
|
|
17773
18093
|
recordFailure(agent, error);
|
|
17774
18094
|
break;
|
|
@@ -18502,7 +18822,8 @@ var OwneySDK = class {
|
|
|
18502
18822
|
}
|
|
18503
18823
|
/** Revalidate a saved transfer against the authenticated account and actual receipt. */
|
|
18504
18824
|
async inspectFunding(evidence, direction, options = {}) {
|
|
18505
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
18825
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
18826
|
+
const state = this.readStateFor(connection);
|
|
18506
18827
|
if (state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase() || !evidence.txHash)
|
|
18507
18828
|
throw new OwneyError("AGENT_API_ERROR", "Funding evidence does not match the connected account.");
|
|
18508
18829
|
const agent = this.getAgent(evidence.agentId);
|
|
@@ -18615,8 +18936,9 @@ var OwneySDK = class {
|
|
|
18615
18936
|
const movement = evidence.txHash ?? evidence.userOpHash ?? evidence.callsId;
|
|
18616
18937
|
if (!agent?.depositConfirmed || !movement) return;
|
|
18617
18938
|
const key2 = `${state.walletAddress.toLowerCase()}:${chainId}:${evidence.agentId}:${evidence.token}:${movement.toLowerCase()}`;
|
|
18618
|
-
if (this.announcedDeposits.has(key2)) return;
|
|
18939
|
+
if (this.announcedDeposits.has(key2) || wasDepositAnnounced(key2)) return;
|
|
18619
18940
|
this.announcedDeposits.add(key2);
|
|
18941
|
+
rememberAnnouncedDeposit(key2);
|
|
18620
18942
|
if (this.announcedDeposits.size > 256) this.announcedDeposits.delete(this.announcedDeposits.values().next().value);
|
|
18621
18943
|
const legKey = `agent:${evidence.agentId}`;
|
|
18622
18944
|
const record2 = (type, notice) => {
|
|
@@ -18677,7 +18999,8 @@ var OwneySDK = class {
|
|
|
18677
18999
|
const fromBlock = parseBlock(opts?.fromBlock ?? evidence.payoutSearch?.fromBlock);
|
|
18678
19000
|
const cursor = parseBlock(opts?.cursor);
|
|
18679
19001
|
if (fromBlock === null || cursor === null) return null;
|
|
18680
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19002
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19003
|
+
const state = this.readStateFor(connection);
|
|
18681
19004
|
if (typeof evidence.walletAddress !== "string" || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18682
19005
|
const agent = this.getAgent(evidence.agentId);
|
|
18683
19006
|
const verifiedWallet = agent.getFundingWallet ? await agent.getFundingWallet(state, chainId, evidence.token) : (await agent.getUserProfile(state, chainId)).smartWallet;
|
|
@@ -18702,7 +19025,8 @@ var OwneySDK = class {
|
|
|
18702
19025
|
/** Resolve a saved sponsored-withdrawal ID without opening a wallet prompt. */
|
|
18703
19026
|
async resolveSponsoredWithdrawalEvidence(evidence, options = {}) {
|
|
18704
19027
|
if (evidence.callsId && !evidence.userOpHash) return this.resolveWalletCallsFundingEvidence(evidence, "withdraw");
|
|
18705
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19028
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19029
|
+
const state = this.readStateFor(connection);
|
|
18706
19030
|
if (evidence.agentId !== "yieldseeker" || chainId !== 8453 || evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return evidence;
|
|
18707
19031
|
const agent = this.getAgent("yieldseeker");
|
|
18708
19032
|
const wallet = await agent.getFundingWallet?.(state, chainId, evidence.token);
|
|
@@ -18749,7 +19073,8 @@ var OwneySDK = class {
|
|
|
18749
19073
|
}
|
|
18750
19074
|
/** Recover an EIP-5792 deposit or payout using this account's exact batch ID. */
|
|
18751
19075
|
async resolveWalletCallsFundingEvidence(evidence, direction) {
|
|
18752
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19076
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19077
|
+
const state = this.readStateFor(connection);
|
|
18753
19078
|
if (!evidence.callsId || evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return evidence;
|
|
18754
19079
|
const agent = this.getAgent(evidence.agentId);
|
|
18755
19080
|
const wallet = agent.getFundingWallet ? await agent.getFundingWallet(state, chainId, evidence.token) : (await agent.getUserProfile(state, chainId)).smartWallet;
|
|
@@ -18782,7 +19107,8 @@ var OwneySDK = class {
|
|
|
18782
19107
|
const first = evidences[0];
|
|
18783
19108
|
const saved = !first.txHash && evidences.every((e) => !e.txHash && (e.serverBroadcast === "unknown" || e.serverBroadcast === true) && typeof e.authorizationDeadline === "number");
|
|
18784
19109
|
if (!first.txHash && !saved) return false;
|
|
18785
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(first.chainId);
|
|
19110
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(first.chainId);
|
|
19111
|
+
const state = this.readStateFor(connection);
|
|
18786
19112
|
const token = SupportedAssets.find((value) => value.chainId === chainId && value.symbol === first.token);
|
|
18787
19113
|
if (!token) return false;
|
|
18788
19114
|
const scope = {
|
|
@@ -18899,7 +19225,8 @@ var OwneySDK = class {
|
|
|
18899
19225
|
/** Optional post-payout display proof; receipt verification and the provider
|
|
18900
19226
|
* adapter must agree before attaching it to this exact balance object. */
|
|
18901
19227
|
async verifyWithdrawalBalance(evidence, balance) {
|
|
18902
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19228
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19229
|
+
const state = this.readStateFor(connection);
|
|
18903
19230
|
const agent = this.getAgent(evidence.agentId);
|
|
18904
19231
|
if (!agent.verifyWithdrawalBalance || !evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return balance;
|
|
18905
19232
|
const key2 = `${state.walletAddress.toLowerCase()}:${chainId}:${evidence.agentId}:${evidence.token}:${evidence.txHash}:${evidence.intendedAmount}`;
|
|
@@ -18948,7 +19275,8 @@ var OwneySDK = class {
|
|
|
18948
19275
|
const agent = this.getAgent(evidence.agentId);
|
|
18949
19276
|
if (!agent.getFundingHistory) return { data: [], hasMore: false };
|
|
18950
19277
|
const filters = { tokenSymbol: evidence.token, fromDate, limit: 50, ...options };
|
|
18951
|
-
const
|
|
19278
|
+
const readState = this.readStateFor(state);
|
|
19279
|
+
const page = await this.readAgent(agent, "history", () => agent.getFundingHistory(readState, chainId, filters), filters);
|
|
18952
19280
|
assertCurrent();
|
|
18953
19281
|
return page;
|
|
18954
19282
|
}
|
|
@@ -18965,7 +19293,7 @@ var OwneySDK = class {
|
|
|
18965
19293
|
const state = this.state;
|
|
18966
19294
|
const id = evidence.withdrawalRequest?.providerWithdrawalId;
|
|
18967
19295
|
if (evidence.agentId !== "zyfai" || !id || !state || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18968
|
-
return this.getAgent("zyfai").getWithdrawalLifecycle(state, id);
|
|
19296
|
+
return this.getAgent("zyfai").getWithdrawalLifecycle(this.readStateFor(state), id);
|
|
18969
19297
|
}
|
|
18970
19298
|
/** A Zyfai deposit's placement status by the id recorded on its evidence. Never signs,
|
|
18971
19299
|
* prompts or authenticates; `null` when unavailable or not this wallet's Zyfai deposit. */
|
|
@@ -18973,7 +19301,7 @@ var OwneySDK = class {
|
|
|
18973
19301
|
const state = this.state;
|
|
18974
19302
|
const id = evidence.providerDepositId;
|
|
18975
19303
|
if (evidence.agentId !== "zyfai" || !id || !state || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18976
|
-
return this.getAgent("zyfai").getDepositPlacement(state, id);
|
|
19304
|
+
return this.getAgent("zyfai").getDepositPlacement(this.readStateFor(state), id);
|
|
18977
19305
|
}
|
|
18978
19306
|
// --- Fund operations ---
|
|
18979
19307
|
/** On-chain version and ownership status for this owner's Yieldseeker agent. */
|
|
@@ -18981,7 +19309,7 @@ var OwneySDK = class {
|
|
|
18981
19309
|
const state = this.requireState();
|
|
18982
19310
|
const chainId = this.requireChainId();
|
|
18983
19311
|
const agent = this.getAgent("yieldseeker");
|
|
18984
|
-
return agent.getWalletStatus(state, chainId, asset);
|
|
19312
|
+
return agent.getWalletStatus(this.readStateFor(state), chainId, asset);
|
|
18985
19313
|
}
|
|
18986
19314
|
/** Deployment gate; an unavailable response keeps the current paid path. */
|
|
18987
19315
|
async isYieldseekerWithdrawalSponsorshipAvailable() {
|
|
@@ -20054,7 +20382,7 @@ var OwneySDK = class {
|
|
|
20054
20382
|
inspect: (value, fromHistory) => this.inspectFunding(value, "withdraw", { requireAmountMatch: fromHistory, refreshBalance: false }),
|
|
20055
20383
|
resolve: (value) => this.resolveSponsoredWithdrawalEvidence(value, { submittedAt: recovery.submittedAt }),
|
|
20056
20384
|
history: (value, fromDate, filters) => this.getFundingHistory(value, fromDate, filters),
|
|
20057
|
-
verifyCompletion: (value) => this.getAgent(value.agentId).verifyWithdrawalCompletion?.(state, value) ?? Promise.resolve({ status: "unavailable" }),
|
|
20385
|
+
verifyCompletion: (value) => this.getAgent(value.agentId).verifyWithdrawalCompletion?.(this.readStateFor(state), value) ?? Promise.resolve({ status: "unavailable" }),
|
|
20058
20386
|
onProgress: (value) => {
|
|
20059
20387
|
recovery.evidence[value.agentId] = value;
|
|
20060
20388
|
persist();
|
|
@@ -21474,7 +21802,7 @@ var OwneySDK = class {
|
|
|
21474
21802
|
const { state: scope, chainId, assertCurrent } = this.captureReadScope(options?.chainId);
|
|
21475
21803
|
const asset = options?.asset;
|
|
21476
21804
|
const agent = this.getAgent(agentId);
|
|
21477
|
-
const state = this.readStateFor(
|
|
21805
|
+
const state = this.readStateFor(scope);
|
|
21478
21806
|
const result = await this.readAgent(
|
|
21479
21807
|
agent,
|
|
21480
21808
|
"balances",
|
|
@@ -21573,7 +21901,7 @@ var OwneySDK = class {
|
|
|
21573
21901
|
const chainId = this.requireChainId();
|
|
21574
21902
|
if (agentId) {
|
|
21575
21903
|
const agent = this.getAgent(agentId);
|
|
21576
|
-
const readState = this.readStateFor(
|
|
21904
|
+
const readState = this.readStateFor(state);
|
|
21577
21905
|
return this.readAgent(
|
|
21578
21906
|
agent,
|
|
21579
21907
|
"earnings",
|
|
@@ -21603,7 +21931,7 @@ var OwneySDK = class {
|
|
|
21603
21931
|
() => agent.refreshEarnings?.(readState, readChain) ?? agent.getEarnings(readState, readChain),
|
|
21604
21932
|
offChain ? { chainId: readChain } : null
|
|
21605
21933
|
);
|
|
21606
|
-
if (agentId) return refreshAgent({ agent: this.getAgent(agentId), state: this.readStateFor(
|
|
21934
|
+
if (agentId) return refreshAgent({ agent: this.getAgent(agentId), state: this.readStateFor(state), chainId });
|
|
21607
21935
|
return this.aggregateEarnings(this.portfolioReads(state, chainId), refreshAgent);
|
|
21608
21936
|
}
|
|
21609
21937
|
async aggregateEarnings(entries, read2) {
|
|
@@ -21671,7 +21999,7 @@ var OwneySDK = class {
|
|
|
21671
21999
|
for (const agent of agents) {
|
|
21672
22000
|
for (const legChainId of chainIds) {
|
|
21673
22001
|
if (agentRunsOn(agent, legChainId))
|
|
21674
|
-
legs.push({ agent, legChainId, legState: this.readStateFor(
|
|
22002
|
+
legs.push({ agent, legChainId, legState: this.readStateFor(state) });
|
|
21675
22003
|
}
|
|
21676
22004
|
}
|
|
21677
22005
|
if (!agentId) {
|
|
@@ -21711,7 +22039,7 @@ var OwneySDK = class {
|
|
|
21711
22039
|
assets: []
|
|
21712
22040
|
};
|
|
21713
22041
|
}
|
|
21714
|
-
const readState = this.readStateFor(
|
|
22042
|
+
const readState = this.readStateFor(state);
|
|
21715
22043
|
return this.readAgent(
|
|
21716
22044
|
agent,
|
|
21717
22045
|
"dailyEarnings",
|
|
@@ -21792,7 +22120,7 @@ var OwneySDK = class {
|
|
|
21792
22120
|
`Agent ${agent.id} does not support pool customization`
|
|
21793
22121
|
);
|
|
21794
22122
|
}
|
|
21795
|
-
return agent.getPoolSelection(state, chainId, {
|
|
22123
|
+
return agent.getPoolSelection(this.readStateFor(state), chainId, {
|
|
21796
22124
|
pairs: params.pairs,
|
|
21797
22125
|
assets: params.assets
|
|
21798
22126
|
});
|
|
@@ -21817,7 +22145,7 @@ var OwneySDK = class {
|
|
|
21817
22145
|
const scopeChainId = scope === "all" ? null : scope;
|
|
21818
22146
|
if (agentId) {
|
|
21819
22147
|
const agent = this.getAgent(agentId);
|
|
21820
|
-
const readState = this.readStateFor(
|
|
22148
|
+
const readState = this.readStateFor(state);
|
|
21821
22149
|
const accountApy = await this.readAgent(
|
|
21822
22150
|
agent,
|
|
21823
22151
|
"accountApy",
|
|
@@ -21957,7 +22285,7 @@ var OwneySDK = class {
|
|
|
21957
22285
|
for (const agent of agents) {
|
|
21958
22286
|
for (const legChainId of chainIds) {
|
|
21959
22287
|
if (agentRunsOn(agent, legChainId))
|
|
21960
|
-
legs.push({ agentId: agent.id, chainId: legChainId, legState: this.readStateFor(
|
|
22288
|
+
legs.push({ agentId: agent.id, chainId: legChainId, legState: this.readStateFor(state2) });
|
|
21961
22289
|
}
|
|
21962
22290
|
}
|
|
21963
22291
|
if (!agentId) {
|
|
@@ -22001,7 +22329,7 @@ var OwneySDK = class {
|
|
|
22001
22329
|
const { state, chainId, assertCurrent } = this.captureReadScope(options?.chainId);
|
|
22002
22330
|
if (agentId) {
|
|
22003
22331
|
const agent = this.getAgent(agentId);
|
|
22004
|
-
const readState = this.readStateFor(
|
|
22332
|
+
const readState = this.readStateFor(state);
|
|
22005
22333
|
const page = await this.readAgent(agent, "history", () => agent.getHistory(readState, chainId, filters), filters);
|
|
22006
22334
|
assertCurrent();
|
|
22007
22335
|
return page;
|
|
@@ -22016,7 +22344,7 @@ var OwneySDK = class {
|
|
|
22016
22344
|
}
|
|
22017
22345
|
const agentFilters = { ...filters, cursor: agentCursor || void 0 };
|
|
22018
22346
|
try {
|
|
22019
|
-
const readState = this.readStateFor(
|
|
22347
|
+
const readState = this.readStateFor(state);
|
|
22020
22348
|
const page = await this.readAgent(
|
|
22021
22349
|
agent,
|
|
22022
22350
|
"history",
|
|
@@ -22078,7 +22406,7 @@ var OwneySDK = class {
|
|
|
22078
22406
|
const chainId = this.requireChainId();
|
|
22079
22407
|
if (agentId) {
|
|
22080
22408
|
const agent = this.getAgent(agentId);
|
|
22081
|
-
const readState = this.readStateFor(
|
|
22409
|
+
const readState = this.readStateFor(state);
|
|
22082
22410
|
return this.readAgent(
|
|
22083
22411
|
agent,
|
|
22084
22412
|
"profile",
|
|
@@ -22301,7 +22629,7 @@ var OwneySDK = class {
|
|
|
22301
22629
|
const entries = [...activeAgents.entries()];
|
|
22302
22630
|
const balanceResults = await Promise.allSettled(
|
|
22303
22631
|
entries.map(async ([id, agent]) => {
|
|
22304
|
-
const readState = this.readStateFor(
|
|
22632
|
+
const readState = this.readStateFor(state);
|
|
22305
22633
|
const b = await this.readAgent(
|
|
22306
22634
|
agent,
|
|
22307
22635
|
"balances",
|
|
@@ -22357,7 +22685,7 @@ import { ZyfaiSDK as ZyfaiSDK2 } from "@zyfai/sdk";
|
|
|
22357
22685
|
|
|
22358
22686
|
// src/agents/zyfai/zyfai.siwx-cache.ts
|
|
22359
22687
|
var KEY_PREFIX7 = "owney.siwx.session";
|
|
22360
|
-
var
|
|
22688
|
+
var storage10 = () => {
|
|
22361
22689
|
if (typeof window === "undefined") return null;
|
|
22362
22690
|
try {
|
|
22363
22691
|
return window.localStorage;
|
|
@@ -22398,7 +22726,7 @@ var readLegacySiwxSession = (store, address) => {
|
|
|
22398
22726
|
var readSiwxSession = (address, chainId) => {
|
|
22399
22727
|
if (typeof window === "undefined") return null;
|
|
22400
22728
|
const key2 = buildKey3(address);
|
|
22401
|
-
const store =
|
|
22729
|
+
const store = storage10();
|
|
22402
22730
|
let raw2 = null;
|
|
22403
22731
|
try {
|
|
22404
22732
|
raw2 = store?.getItem(key2) ?? null;
|
|
@@ -22428,7 +22756,7 @@ var writeSiwxSession = (address, _chainId, session) => {
|
|
|
22428
22756
|
if (typeof window === "undefined") return;
|
|
22429
22757
|
const key2 = buildKey3(address);
|
|
22430
22758
|
memorySiwxSessions.set(key2, session);
|
|
22431
|
-
const store =
|
|
22759
|
+
const store = storage10();
|
|
22432
22760
|
try {
|
|
22433
22761
|
store?.setItem(key2, JSON.stringify(session));
|
|
22434
22762
|
} catch {
|
|
@@ -22437,7 +22765,7 @@ var writeSiwxSession = (address, _chainId, session) => {
|
|
|
22437
22765
|
var clearSiwxSession = (address, _chainId) => {
|
|
22438
22766
|
const key2 = buildKey3(address);
|
|
22439
22767
|
memorySiwxSessions.delete(key2);
|
|
22440
|
-
const store =
|
|
22768
|
+
const store = storage10();
|
|
22441
22769
|
try {
|
|
22442
22770
|
store?.removeItem(key2);
|
|
22443
22771
|
} catch {
|