@owney/sdk 0.7.32-beta.10 → 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 +555 -141
- package/dist/index.d.cts +119 -23
- package/dist/index.d.ts +119 -23
- package/dist/index.js +552 -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;
|
|
@@ -4523,18 +4573,45 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4523
4573
|
}
|
|
4524
4574
|
return this.connectedAddress;
|
|
4525
4575
|
}
|
|
4526
|
-
/**
|
|
4576
|
+
/**
|
|
4577
|
+
* Whether connecting now would ask the wallet to sign in: not connected for
|
|
4578
|
+
* this wallet and chain (the check `connectAuth` returns early on) and no
|
|
4579
|
+
* fresh saved session. Never prompts; reads only what is saved.
|
|
4580
|
+
*/
|
|
4581
|
+
needsSignIn(state, chainId) {
|
|
4582
|
+
const owner = state.walletAddress.toLowerCase();
|
|
4583
|
+
if (this.connectedAddress?.toLowerCase() === owner && this.connectedChainId === chainId) return false;
|
|
4584
|
+
return readSession(state.walletAddress, chainId) === null;
|
|
4585
|
+
}
|
|
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
|
+
*/
|
|
4527
4601
|
async connectAuth(state, chainId) {
|
|
4528
4602
|
const validChainId = isValidChainId(chainId);
|
|
4529
4603
|
const owner = state.walletAddress.toLowerCase();
|
|
4530
4604
|
const scope = `${owner}:${validChainId}`;
|
|
4605
|
+
const promptless = state.promptless === true;
|
|
4531
4606
|
if (this.connectedAddress?.toLowerCase() === owner && this.connectedChainId === validChainId) {
|
|
4532
4607
|
return;
|
|
4533
4608
|
}
|
|
4534
4609
|
if (this.connectAuthPromise && this.connectAuthScope === scope) {
|
|
4535
|
-
await this.connectAuthPromise;
|
|
4610
|
+
if (this.connectAuthPromptless && !promptless) await this.connectAuthPromise.catch(() => void 0);
|
|
4611
|
+
else await this.connectAuthPromise;
|
|
4536
4612
|
return this.connectAuth(state, chainId);
|
|
4537
4613
|
}
|
|
4614
|
+
if (promptless && readSession(state.walletAddress, validChainId) === null) throw this.signInRequired();
|
|
4538
4615
|
if (this.sdkHasConnected || this.connectedAddress) this.sdk = this.createSdk();
|
|
4539
4616
|
this.sdkHasConnected = true;
|
|
4540
4617
|
const executionSdk = this.sdk;
|
|
@@ -4547,7 +4624,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4547
4624
|
const address = await this.connectAccountWithRetry(
|
|
4548
4625
|
state.provider,
|
|
4549
4626
|
validChainId,
|
|
4550
|
-
executionSdk
|
|
4627
|
+
executionSdk,
|
|
4628
|
+
promptless
|
|
4551
4629
|
);
|
|
4552
4630
|
if (generation !== this.connectionGeneration || address.toLowerCase() !== owner)
|
|
4553
4631
|
throw new OwneyError("NOT_CONNECTED", "Wallet changed while connecting Zyfai.", void 0, this.id);
|
|
@@ -4556,12 +4634,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4556
4634
|
})();
|
|
4557
4635
|
this.connectAuthPromise = pending;
|
|
4558
4636
|
this.connectAuthScope = scope;
|
|
4637
|
+
this.connectAuthPromptless = promptless;
|
|
4559
4638
|
try {
|
|
4560
4639
|
await pending;
|
|
4561
4640
|
} finally {
|
|
4562
4641
|
if (this.connectAuthPromise === pending) {
|
|
4563
4642
|
this.connectAuthPromise = null;
|
|
4564
4643
|
this.connectAuthScope = null;
|
|
4644
|
+
this.connectAuthPromptless = false;
|
|
4565
4645
|
}
|
|
4566
4646
|
}
|
|
4567
4647
|
}
|
|
@@ -4574,19 +4654,86 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4574
4654
|
* which does not separate a revoked JWT from a misconfigured API key; we
|
|
4575
4655
|
* retry once either way, and if the second attempt still fails the original
|
|
4576
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.
|
|
4577
4662
|
*/
|
|
4578
|
-
async connectAccountWithRetry(provider, chainId, executionSdk = this.sdk) {
|
|
4663
|
+
async connectAccountWithRetry(provider, chainId, executionSdk = this.sdk, promptless = false) {
|
|
4664
|
+
if (promptless) this.promptlessSdks.add(executionSdk);
|
|
4579
4665
|
try {
|
|
4580
|
-
|
|
4666
|
+
const address = await executionSdk.connectAccount(provider, chainId);
|
|
4667
|
+
this.promptlessSdks.delete(executionSdk);
|
|
4668
|
+
return address;
|
|
4581
4669
|
} catch (error) {
|
|
4582
4670
|
const message = error instanceof Error ? error.message : String(error);
|
|
4583
4671
|
if (!message.toLowerCase().includes("unauthorized")) throw error;
|
|
4584
4672
|
const internals = executionSdk;
|
|
4585
4673
|
const address = internals.walletClient?.account?.address;
|
|
4674
|
+
if (promptless) throw this.dropRefusedReadSession(address, executionSdk, internals.httpClient.authToken, message);
|
|
4586
4675
|
if (address) clearSession(address, chainId);
|
|
4587
4676
|
return await executionSdk.connectAccount(provider, chainId);
|
|
4588
4677
|
}
|
|
4589
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
|
+
}
|
|
4590
4737
|
/**
|
|
4591
4738
|
* Reconnect if the Zyfai connection was torn down behind our back: a
|
|
4592
4739
|
* chain/account switch fires the provider's `accountsChanged` →
|
|
@@ -4624,6 +4771,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4624
4771
|
internals.httpClient.clearAuthToken();
|
|
4625
4772
|
internals.authenticatedUserId = null;
|
|
4626
4773
|
this.connectedChainId = null;
|
|
4774
|
+
this.tellSignInRefused();
|
|
4627
4775
|
}
|
|
4628
4776
|
/**
|
|
4629
4777
|
* Sync newly-available protocols onto an existing user's profile at wallet
|
|
@@ -4675,11 +4823,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4675
4823
|
* per chain, in parallel) cancel each other's sign-in. Funding keeps
|
|
4676
4824
|
* `connectAuth`/`ensureConnected`. Returns the owner verified for this call,
|
|
4677
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`).
|
|
4678
4828
|
*/
|
|
4679
4829
|
async ensureReadSession(state, chainId) {
|
|
4680
4830
|
const owner = state.walletAddress?.toLowerCase();
|
|
4681
4831
|
if (this.connectAuthPromise) await this.connectAuthPromise.catch(() => void 0);
|
|
4682
|
-
if (!owner || this.connectedAddress?.toLowerCase() !== owner
|
|
4832
|
+
if (!owner || this.connectedAddress?.toLowerCase() !== owner || this.connectedChainId === null)
|
|
4833
|
+
await this.connectAuth(state, chainId);
|
|
4683
4834
|
}
|
|
4684
4835
|
/** `ensureReadSession`, then the owner it verified, read in the same turn. */
|
|
4685
4836
|
async connectForRead(state, chainId) {
|
|
@@ -4713,7 +4864,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4713
4864
|
return pending;
|
|
4714
4865
|
}
|
|
4715
4866
|
// --- IAgent: Connection lifecycle ---
|
|
4716
|
-
async disconnect() {
|
|
4867
|
+
async disconnect(options) {
|
|
4717
4868
|
const executionSdk = this.sdk;
|
|
4718
4869
|
this.connectionGeneration++;
|
|
4719
4870
|
this.earningsGeneration++;
|
|
@@ -4726,7 +4877,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4726
4877
|
this.holdActiveScopes.clear();
|
|
4727
4878
|
this.pendingRegistrations.clear();
|
|
4728
4879
|
this.lastGoodEarnings.clear();
|
|
4729
|
-
if (this.connectedAddress && this.connectedChainId !== null) {
|
|
4880
|
+
if (!options?.keepSignIns && this.connectedAddress && this.connectedChainId !== null) {
|
|
4730
4881
|
clearSession(this.connectedAddress, this.connectedChainId);
|
|
4731
4882
|
}
|
|
4732
4883
|
this.connectedAddress = null;
|
|
@@ -5104,13 +5255,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5104
5255
|
Promise.all(
|
|
5105
5256
|
params.pairs.map(async ({ protocolId, chainId: chainId2 }) => {
|
|
5106
5257
|
try {
|
|
5107
|
-
const current = await this.sdk.getSelectedPools(
|
|
5258
|
+
const current = await this.readCall(state, () => this.sdk.getSelectedPools(
|
|
5108
5259
|
protocolId,
|
|
5109
5260
|
chainId2
|
|
5110
|
-
);
|
|
5261
|
+
));
|
|
5111
5262
|
if (current.autoselect) return null;
|
|
5112
5263
|
return { protocolId, chainId: chainId2, pools: current.pools ?? [] };
|
|
5113
|
-
} catch {
|
|
5264
|
+
} catch (error) {
|
|
5265
|
+
if (isSignInFailure(error)) throw error;
|
|
5114
5266
|
return null;
|
|
5115
5267
|
}
|
|
5116
5268
|
})
|
|
@@ -5118,9 +5270,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5118
5270
|
Promise.all(
|
|
5119
5271
|
params.assets.map(async (asset) => {
|
|
5120
5272
|
try {
|
|
5121
|
-
const current = await this.sdk.getUserDetails(asset);
|
|
5273
|
+
const current = await this.readCall(state, () => this.sdk.getUserDetails(asset));
|
|
5122
5274
|
return current.strategy ? { asset, strategy: current.strategy } : null;
|
|
5123
|
-
} catch {
|
|
5275
|
+
} catch (error) {
|
|
5276
|
+
if (isSignInFailure(error)) throw error;
|
|
5124
5277
|
return null;
|
|
5125
5278
|
}
|
|
5126
5279
|
})
|
|
@@ -6513,7 +6666,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6513
6666
|
const requestedAt = Date.now();
|
|
6514
6667
|
const generation = this.earningsGeneration;
|
|
6515
6668
|
const { smartWallet, chainId: validChainId } = await this.resolveSmartWallet(state, chainId);
|
|
6516
|
-
const raw2 = await this.sdk.getPortfolio(this.getAddress());
|
|
6669
|
+
const raw2 = await this.readCall(state, () => this.sdk.getPortfolio(this.getAddress()));
|
|
6517
6670
|
debugLog("zyfai:balances", "read", { ms: Date.now() - requestedAt });
|
|
6518
6671
|
const balance = mapBalances(raw2, validChainId, smartWallet);
|
|
6519
6672
|
const reads = balance.readMetadata?.map((read2) => ({ ...read2, requestedAt })) ?? [];
|
|
@@ -6575,7 +6728,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6575
6728
|
async getEarnings(state, chainId) {
|
|
6576
6729
|
const { smartWallet } = await this.resolveSmartWallet(state, chainId);
|
|
6577
6730
|
const key2 = this.earningsKey(state, chainId, smartWallet);
|
|
6578
|
-
const raw2 = await this.readEarnings(key2, smartWallet);
|
|
6731
|
+
const raw2 = await this.readCall(state, () => this.readEarnings(key2, smartWallet));
|
|
6579
6732
|
const held = await this.holdEarnings(state, chainId, smartWallet, key2, raw2);
|
|
6580
6733
|
if (held.active) void this.refreshEarnings(state, chainId).catch(() => void 0);
|
|
6581
6734
|
return mapEarnings(held.value, smartWallet);
|
|
@@ -6726,7 +6879,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6726
6879
|
if (existing) return existing;
|
|
6727
6880
|
const pending = (async () => {
|
|
6728
6881
|
const recent = this.earningsSnapshot;
|
|
6729
|
-
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);
|
|
6730
6883
|
const lastCheck = current.data.lastCheckTimestamp ? Date.parse(current.data.lastCheckTimestamp) : Number.NaN;
|
|
6731
6884
|
const mapped = mapEarnings(current, smartWallet);
|
|
6732
6885
|
const held = await this.holdEarnings(state, chainId, smartWallet, key2, current);
|
|
@@ -6740,7 +6893,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6740
6893
|
if (isFresh && !negative || !canCalculate)
|
|
6741
6894
|
return held.active ? mapEarnings(held.value, smartWallet) : mapped;
|
|
6742
6895
|
this.earningsCalculationAttempts.set(calculationKey, now);
|
|
6743
|
-
const earnings = await executionSdk.calculateOnchainEarnings(smartWallet);
|
|
6896
|
+
const earnings = await this.readCall(state, () => executionSdk.calculateOnchainEarnings(smartWallet), executionSdk);
|
|
6744
6897
|
assertCurrent();
|
|
6745
6898
|
this.earningsSnapshot = { key: key2, raw: earnings, at: Date.now() };
|
|
6746
6899
|
const recalculated = await this.holdEarnings(state, chainId, smartWallet, key2, earnings);
|
|
@@ -6755,7 +6908,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6755
6908
|
}
|
|
6756
6909
|
async getAccountApy(state, chainId, days, tokenSymbol, scopeChainId) {
|
|
6757
6910
|
const { smartWallet } = await this.resolveSmartWallet(state, chainId);
|
|
6758
|
-
const raw2 = await this.sdk.getDailyApyHistory(smartWallet, days);
|
|
6911
|
+
const raw2 = await this.readCall(state, () => this.sdk.getDailyApyHistory(smartWallet, days));
|
|
6759
6912
|
const scope = scopeChainId === null ? void 0 : scopeChainId ?? chainId;
|
|
6760
6913
|
const ethUsd = tokenSymbol === void 0 && holdsEthPosition(raw2) ? await readEthUsdPrice(this.getPublicClient(8453)) : void 0;
|
|
6761
6914
|
return mapApyHistory(raw2, scope, tokenSymbol, ethUsd);
|
|
@@ -6765,10 +6918,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6765
6918
|
const start = new Date(
|
|
6766
6919
|
Date.now() - (DayFilterMapping[days] + 1) * 864e5
|
|
6767
6920
|
);
|
|
6768
|
-
const raw2 = await this.sdk.getDailyEarnings(
|
|
6921
|
+
const raw2 = await this.readCall(state, () => this.sdk.getDailyEarnings(
|
|
6769
6922
|
smartWallet,
|
|
6770
6923
|
start.toISOString().slice(0, 10)
|
|
6771
|
-
);
|
|
6924
|
+
));
|
|
6772
6925
|
return mapDailyEarnings(raw2, chainId, tokenSymbol);
|
|
6773
6926
|
}
|
|
6774
6927
|
/**
|
|
@@ -6812,7 +6965,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6812
6965
|
const matched = [];
|
|
6813
6966
|
let backendExhausted = false;
|
|
6814
6967
|
for (let i = 0; i < MAX_BACKEND_CALLS && matched.length < limit; i++) {
|
|
6815
|
-
const raw2 = await this.sdk.getHistory(smartWallet, validChainId, {
|
|
6968
|
+
const raw2 = await this.readCall(state, () => this.sdk.getHistory(smartWallet, validChainId, {
|
|
6816
6969
|
limit: backendPageSize,
|
|
6817
6970
|
offset,
|
|
6818
6971
|
fromDate: options?.fromDate,
|
|
@@ -6822,7 +6975,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6822
6975
|
// relevant entries instead of spending its budget on the other
|
|
6823
6976
|
// asset's rows and handing back a page that filters to nothing.
|
|
6824
6977
|
assetType
|
|
6825
|
-
});
|
|
6978
|
+
}));
|
|
6826
6979
|
raw2.data.forEach((entry, idx) => {
|
|
6827
6980
|
if (entry.chainId === validChainId) {
|
|
6828
6981
|
matched.push({ entry, rawIdx: offset + idx });
|
|
@@ -6858,7 +7011,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6858
7011
|
}
|
|
6859
7012
|
async getUserProfile(state, chainId) {
|
|
6860
7013
|
await this.ensureReadSession(state, chainId);
|
|
6861
|
-
const raw2 = await this.sdk.getUserDetails();
|
|
7014
|
+
const raw2 = await this.readCall(state, () => this.sdk.getUserDetails());
|
|
6862
7015
|
debugLog("zyfai:profile", "getUserProfile \u2014 Zyfai reports", {
|
|
6863
7016
|
asset: "USDC (default \u2014 no asset passed)",
|
|
6864
7017
|
splitting: raw2.splitting,
|
|
@@ -6967,7 +7120,7 @@ var INVALIDATED_KEY_PREFIXES = [
|
|
|
6967
7120
|
"owney.yieldseeker.session.v3",
|
|
6968
7121
|
"owney.yieldseeker.session.v4"
|
|
6969
7122
|
];
|
|
6970
|
-
var
|
|
7123
|
+
var storage4 = () => {
|
|
6971
7124
|
if (typeof window === "undefined") return null;
|
|
6972
7125
|
try {
|
|
6973
7126
|
return window.localStorage;
|
|
@@ -7001,7 +7154,7 @@ var isValidSession = (session) => {
|
|
|
7001
7154
|
var readYieldseekerSession = (address, chainId) => {
|
|
7002
7155
|
if (typeof window === "undefined") return null;
|
|
7003
7156
|
const key2 = buildKey2(address, chainId);
|
|
7004
|
-
const store =
|
|
7157
|
+
const store = storage4();
|
|
7005
7158
|
clearInvalidatedSessions(store, address, chainId);
|
|
7006
7159
|
let raw2 = null;
|
|
7007
7160
|
try {
|
|
@@ -7033,7 +7186,7 @@ var writeYieldseekerSession = (address, chainId, token) => {
|
|
|
7033
7186
|
if (!isValidSession(session)) return;
|
|
7034
7187
|
const key2 = buildKey2(address, chainId);
|
|
7035
7188
|
memorySessions2.set(key2, session);
|
|
7036
|
-
const store =
|
|
7189
|
+
const store = storage4();
|
|
7037
7190
|
try {
|
|
7038
7191
|
store?.setItem(key2, JSON.stringify(session));
|
|
7039
7192
|
} catch {
|
|
@@ -7042,7 +7195,7 @@ var writeYieldseekerSession = (address, chainId, token) => {
|
|
|
7042
7195
|
var clearYieldseekerSession = (address, chainId) => {
|
|
7043
7196
|
const key2 = buildKey2(address, chainId);
|
|
7044
7197
|
memorySessions2.delete(key2);
|
|
7045
|
-
const store =
|
|
7198
|
+
const store = storage4();
|
|
7046
7199
|
clearInvalidatedSessions(store, address, chainId);
|
|
7047
7200
|
try {
|
|
7048
7201
|
store?.removeItem(key2);
|
|
@@ -7154,12 +7307,21 @@ var YieldseekerAuth = class {
|
|
|
7154
7307
|
return this.getToken(state, chainId);
|
|
7155
7308
|
}
|
|
7156
7309
|
/** Drop a proof the provider refused, without signing a new one: a
|
|
7157
|
-
* 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. */
|
|
7158
7313
|
discardToken(state, chainId, rejectedToken) {
|
|
7159
7314
|
const key2 = this.key(state, chainId);
|
|
7160
|
-
|
|
7161
|
-
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) {
|
|
7162
7321
|
clearYieldseekerSession(state.walletAddress, chainId);
|
|
7322
|
+
dropped = true;
|
|
7323
|
+
}
|
|
7324
|
+
return dropped;
|
|
7163
7325
|
}
|
|
7164
7326
|
isReusable(token, state, chainId) {
|
|
7165
7327
|
try {
|
|
@@ -7175,6 +7337,12 @@ var YieldseekerAuth = class {
|
|
|
7175
7337
|
return false;
|
|
7176
7338
|
}
|
|
7177
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
|
+
}
|
|
7178
7346
|
clear(state, chainId) {
|
|
7179
7347
|
if (!state || chainId === void 0) {
|
|
7180
7348
|
for (const scope of this.scopes.values()) {
|
|
@@ -7219,9 +7387,9 @@ var YieldseekerAuth = class {
|
|
|
7219
7387
|
|
|
7220
7388
|
// src/agents/yieldseeker/yieldseeker.identity-cache.ts
|
|
7221
7389
|
var KEY_PREFIX3 = "owney.yieldseeker.identity.v1";
|
|
7222
|
-
var YIELDSEEKER_IDENTITY_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
7390
|
+
var YIELDSEEKER_IDENTITY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
7223
7391
|
var memoryIdentities = /* @__PURE__ */ new Map();
|
|
7224
|
-
var
|
|
7392
|
+
var storage5 = () => {
|
|
7225
7393
|
if (typeof window === "undefined") return null;
|
|
7226
7394
|
try {
|
|
7227
7395
|
return window.localStorage;
|
|
@@ -7238,7 +7406,7 @@ function valid(value, walletAddress, chainId, now) {
|
|
|
7238
7406
|
function readYieldseekerIdentity(walletAddress, chainId, now = Date.now()) {
|
|
7239
7407
|
if (typeof window === "undefined") return null;
|
|
7240
7408
|
const key2 = keyFor(walletAddress, chainId);
|
|
7241
|
-
const store =
|
|
7409
|
+
const store = storage5();
|
|
7242
7410
|
let parsed = null;
|
|
7243
7411
|
try {
|
|
7244
7412
|
const raw2 = store?.getItem(key2);
|
|
@@ -7270,7 +7438,7 @@ function writeYieldseekerIdentity(walletAddress, chainId, userId, now = Date.now
|
|
|
7270
7438
|
const key2 = keyFor(walletAddress, chainId);
|
|
7271
7439
|
memoryIdentities.set(key2, identity);
|
|
7272
7440
|
try {
|
|
7273
|
-
|
|
7441
|
+
storage5()?.setItem(key2, JSON.stringify(identity));
|
|
7274
7442
|
} catch {
|
|
7275
7443
|
}
|
|
7276
7444
|
}
|
|
@@ -7278,9 +7446,41 @@ function clearYieldseekerIdentity(walletAddress, chainId) {
|
|
|
7278
7446
|
const key2 = keyFor(walletAddress, chainId);
|
|
7279
7447
|
memoryIdentities.delete(key2);
|
|
7280
7448
|
try {
|
|
7281
|
-
|
|
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));
|
|
7282
7481
|
} catch {
|
|
7283
7482
|
}
|
|
7483
|
+
return until;
|
|
7284
7484
|
}
|
|
7285
7485
|
|
|
7286
7486
|
// src/agents/yieldseeker/yieldseeker.client.ts
|
|
@@ -8943,6 +9143,12 @@ function generateYieldseekerUsername() {
|
|
|
8943
9143
|
const suffix = globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, YIELDSEEKER_USERNAME_RANDOM_LENGTH).toLowerCase();
|
|
8944
9144
|
return `${YIELDSEEKER_USERNAME_PREFIX}${suffix}`;
|
|
8945
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
|
+
}
|
|
8946
9152
|
function isUsernameConflict(error) {
|
|
8947
9153
|
if (!(error instanceof YieldseekerApiError)) return false;
|
|
8948
9154
|
const code = error.providerCode.toUpperCase();
|
|
@@ -9090,6 +9296,15 @@ var YieldseekerAgent = class {
|
|
|
9090
9296
|
balanceContexts = /* @__PURE__ */ new WeakMap();
|
|
9091
9297
|
balanceVaults = /* @__PURE__ */ new Map();
|
|
9092
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();
|
|
9093
9308
|
pendingAgents = /* @__PURE__ */ new Map();
|
|
9094
9309
|
pendingWalletContexts = /* @__PURE__ */ new Map();
|
|
9095
9310
|
readCache = /* @__PURE__ */ new Map();
|
|
@@ -9116,6 +9331,7 @@ var YieldseekerAgent = class {
|
|
|
9116
9331
|
// or while the ledger read is null, settlement and earnings are as before.
|
|
9117
9332
|
ledgerAccess;
|
|
9118
9333
|
accountRefusedListener;
|
|
9334
|
+
signInRefusedListener;
|
|
9119
9335
|
ledgerReads = /* @__PURE__ */ new Map();
|
|
9120
9336
|
/** contextKey -> movements this instance started settling (by tx hash) and how they refresh:
|
|
9121
9337
|
* awaiting the ledger, refreshed when ready (ledger), or on the timed backoff (legacy). */
|
|
@@ -9411,16 +9627,16 @@ var YieldseekerAgent = class {
|
|
|
9411
9627
|
this.rememberWalletStatus(versionKey, status);
|
|
9412
9628
|
return { txHash: hash2, status };
|
|
9413
9629
|
};
|
|
9414
|
-
let
|
|
9630
|
+
let storage11;
|
|
9415
9631
|
try {
|
|
9416
|
-
|
|
9632
|
+
storage11 = typeof window === "undefined" ? void 0 : window.localStorage;
|
|
9417
9633
|
} catch {
|
|
9418
|
-
|
|
9634
|
+
storage11 = void 0;
|
|
9419
9635
|
}
|
|
9420
9636
|
const clearRecordedUpgrade = () => {
|
|
9421
9637
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9422
9638
|
try {
|
|
9423
|
-
|
|
9639
|
+
storage11?.removeItem(pendingKey2);
|
|
9424
9640
|
} catch {
|
|
9425
9641
|
this.pendingUpgrades.set(pendingKey2, null);
|
|
9426
9642
|
}
|
|
@@ -9443,7 +9659,7 @@ var YieldseekerAgent = class {
|
|
|
9443
9659
|
throw pendingUpgrade(hash2);
|
|
9444
9660
|
}
|
|
9445
9661
|
};
|
|
9446
|
-
if (!
|
|
9662
|
+
if (!storage11 && (gasMode === "sponsored" || before.ownerPath === "smart"))
|
|
9447
9663
|
throw new OwneyError(
|
|
9448
9664
|
"SPONSOR_REQUEST_FAILED",
|
|
9449
9665
|
"Upgrade status cannot be saved in this browser.",
|
|
@@ -9452,14 +9668,14 @@ var YieldseekerAgent = class {
|
|
|
9452
9668
|
);
|
|
9453
9669
|
let prior = null;
|
|
9454
9670
|
try {
|
|
9455
|
-
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);
|
|
9456
9672
|
try {
|
|
9457
9673
|
prior = JSON.parse(saved ?? "null");
|
|
9458
9674
|
} catch {
|
|
9459
9675
|
prior = { callsId: void 0 };
|
|
9460
9676
|
}
|
|
9461
9677
|
} catch {
|
|
9462
|
-
if (gasMode === "paid" && before.ownerPath === "eoa")
|
|
9678
|
+
if (gasMode === "paid" && before.ownerPath === "eoa") storage11 = void 0;
|
|
9463
9679
|
else throw new OwneyError(
|
|
9464
9680
|
"SPONSOR_REQUEST_FAILED",
|
|
9465
9681
|
"Upgrade status cannot be read in this browser.",
|
|
@@ -9553,9 +9769,9 @@ var YieldseekerAgent = class {
|
|
|
9553
9769
|
asset: YIELDSEEKER_ASSET_METADATA[asset].address,
|
|
9554
9770
|
callData: data,
|
|
9555
9771
|
onPending: (pending) => {
|
|
9556
|
-
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");
|
|
9557
9773
|
const next = { startedAt: Date.now(), ...current, ...pending };
|
|
9558
|
-
|
|
9774
|
+
storage11.setItem(pendingKey2, JSON.stringify(next));
|
|
9559
9775
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9560
9776
|
}
|
|
9561
9777
|
});
|
|
@@ -9579,8 +9795,8 @@ var YieldseekerAgent = class {
|
|
|
9579
9795
|
const pending = { txHash: hash2 };
|
|
9580
9796
|
this.pendingUpgrades.set(pendingKey2, pending);
|
|
9581
9797
|
try {
|
|
9582
|
-
if (
|
|
9583
|
-
|
|
9798
|
+
if (storage11) {
|
|
9799
|
+
storage11.setItem(pendingKey2, JSON.stringify(pending));
|
|
9584
9800
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9585
9801
|
}
|
|
9586
9802
|
} catch {
|
|
@@ -9601,14 +9817,18 @@ var YieldseekerAgent = class {
|
|
|
9601
9817
|
clearRecordedUpgrade();
|
|
9602
9818
|
return confirmed;
|
|
9603
9819
|
}
|
|
9604
|
-
async disconnect() {
|
|
9820
|
+
async disconnect(options) {
|
|
9605
9821
|
this.withdrawalVersionCache.clear();
|
|
9606
9822
|
this.pendingWalletStatus.clear();
|
|
9607
9823
|
this.readGeneration += 1;
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
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
|
+
}
|
|
9612
9832
|
}
|
|
9613
9833
|
this.users.clear();
|
|
9614
9834
|
this.agentContexts.clear();
|
|
@@ -9650,6 +9870,13 @@ var YieldseekerAgent = class {
|
|
|
9650
9870
|
this.planHistoryKeys.clear();
|
|
9651
9871
|
this.lastLedgerRows.clear();
|
|
9652
9872
|
}
|
|
9873
|
+
/**
|
|
9874
|
+
* Whether connecting now would ask the wallet to sign in: no reusable saved
|
|
9875
|
+
* sign-in for this wallet and chain. Never prompts; reads only what is saved.
|
|
9876
|
+
*/
|
|
9877
|
+
needsSignIn(state, chainId) {
|
|
9878
|
+
return !this.auth.peekToken(state, chainId);
|
|
9879
|
+
}
|
|
9653
9880
|
/**
|
|
9654
9881
|
* The connect's account check (2026-11-13), run before any agent activates:
|
|
9655
9882
|
* sign in (a saved sign-in, else login-with-wallet, else POST /users for a
|
|
@@ -10195,6 +10422,7 @@ var YieldseekerAgent = class {
|
|
|
10195
10422
|
const unwind = async (position2, assetsRaw) => {
|
|
10196
10423
|
this.assertSession(generation, chainId, asset);
|
|
10197
10424
|
assertOperation?.();
|
|
10425
|
+
this.releasingWallets.set(context.wallet.walletAddress.toLowerCase(), Date.now());
|
|
10198
10426
|
let unwindTransactionHash;
|
|
10199
10427
|
try {
|
|
10200
10428
|
const response = await this.walletRequest(
|
|
@@ -10990,7 +11218,9 @@ var YieldseekerAgent = class {
|
|
|
10990
11218
|
* left idle. While it has not, Yieldseeker is told again, up to
|
|
10991
11219
|
* DEPOSIT_NOTICE_ATTEMPTS calls in all; a failed call (network, server, rate
|
|
10992
11220
|
* limit) is sent again after a wait. Within an hour of a withdrawal it is
|
|
10993
|
-
* 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
|
|
10994
11224
|
* knows for the asset and the saved sign-in only: never prompts, never
|
|
10995
11225
|
* throws. Each call is reported through `onNotice`.
|
|
10996
11226
|
*/
|
|
@@ -11007,6 +11237,8 @@ var YieldseekerAgent = class {
|
|
|
11007
11237
|
if (!this.auth.peekToken(state, chainId)) return { notified: false, reason: "NO_SESSION" };
|
|
11008
11238
|
const generation = this.readGeneration;
|
|
11009
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" };
|
|
11010
11242
|
const cooldownEnds = await this.withdrawalCooldownEnd(state, chainId, slotAsset, context);
|
|
11011
11243
|
let notified = false;
|
|
11012
11244
|
let reason = "NOT_ALLOCATED";
|
|
@@ -11097,6 +11329,19 @@ var YieldseekerAgent = class {
|
|
|
11097
11329
|
* confirmed withdrawal, if that is still ahead; null when there was none in
|
|
11098
11330
|
* the last hour or the ledger cannot say.
|
|
11099
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
|
+
}
|
|
11100
11345
|
async withdrawalCooldownEnd(state, chainId, asset, context) {
|
|
11101
11346
|
const rows = await withinBudget(this.readLedger(state, chainId, asset), this.ledgerBudgetMs, null);
|
|
11102
11347
|
const wallet = context.wallet.walletAddress.toLowerCase();
|
|
@@ -12212,6 +12457,29 @@ var YieldseekerAgent = class {
|
|
|
12212
12457
|
this.users.set(key2, persisted);
|
|
12213
12458
|
return persisted;
|
|
12214
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
|
+
};
|
|
12215
12483
|
const walletAddress = getAddress6(state.walletAddress);
|
|
12216
12484
|
const generation = this.readGeneration;
|
|
12217
12485
|
let user = null;
|
|
@@ -12229,11 +12497,13 @@ var YieldseekerAgent = class {
|
|
|
12229
12497
|
});
|
|
12230
12498
|
}
|
|
12231
12499
|
} catch (error) {
|
|
12500
|
+
if (isSignInRateLimit(error)) limited(error);
|
|
12232
12501
|
if (!(error instanceof YieldseekerApiError) || error.providerCode !== "NO_USER") {
|
|
12233
12502
|
if (error instanceof OwneyError) throw error;
|
|
12234
12503
|
throw this.mapRequestFailure(error);
|
|
12235
12504
|
}
|
|
12236
12505
|
let created;
|
|
12506
|
+
let registeredMeanwhile = false;
|
|
12237
12507
|
for (let attempt = 0; attempt < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS; attempt += 1) {
|
|
12238
12508
|
try {
|
|
12239
12509
|
created = await this.providerRequest(
|
|
@@ -12250,12 +12520,32 @@ var YieldseekerAgent = class {
|
|
|
12250
12520
|
);
|
|
12251
12521
|
break;
|
|
12252
12522
|
} catch (createError) {
|
|
12523
|
+
if (isSignInRateLimit(createError)) limited(createError);
|
|
12524
|
+
if (isWalletAlreadyRegistered(createError)) {
|
|
12525
|
+
registeredMeanwhile = true;
|
|
12526
|
+
break;
|
|
12527
|
+
}
|
|
12253
12528
|
const canRetry = isUsernameConflict(createError) && attempt + 1 < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS;
|
|
12254
12529
|
if (canRetry) continue;
|
|
12255
12530
|
throw this.mapRequestFailure(createError);
|
|
12256
12531
|
}
|
|
12257
12532
|
}
|
|
12258
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
|
+
}
|
|
12259
12549
|
}
|
|
12260
12550
|
if (!user || !/^[a-zA-Z0-9_-]{1,128}$/.test(user.userId)) {
|
|
12261
12551
|
throw this.invalidResponse("wallet identity");
|
|
@@ -12266,6 +12556,19 @@ var YieldseekerAgent = class {
|
|
|
12266
12556
|
writeYieldseekerIdentity(state.walletAddress, chainId, resolved.userId);
|
|
12267
12557
|
return resolved;
|
|
12268
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
|
+
}
|
|
12269
12572
|
forgetUser(state, chainId) {
|
|
12270
12573
|
this.users.delete(this.userKey(state, chainId));
|
|
12271
12574
|
clearYieldseekerIdentity(state.walletAddress, chainId);
|
|
@@ -12747,6 +13050,9 @@ var YieldseekerAgent = class {
|
|
|
12747
13050
|
setAccountRefusedListener(listener) {
|
|
12748
13051
|
this.accountRefusedListener = listener;
|
|
12749
13052
|
}
|
|
13053
|
+
setSignInRefusedListener(listener) {
|
|
13054
|
+
this.signInRefusedListener = listener;
|
|
13055
|
+
}
|
|
12750
13056
|
setFundingLedgerAccess(access) {
|
|
12751
13057
|
this.ledgerAccess = access;
|
|
12752
13058
|
this.ledgerReads.clear();
|
|
@@ -13140,7 +13446,13 @@ var YieldseekerAgent = class {
|
|
|
13140
13446
|
if (error.providerCode === "NO_USER") throw error;
|
|
13141
13447
|
if (!error.isAuthenticationError) throw error;
|
|
13142
13448
|
if (promptless) {
|
|
13143
|
-
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
|
+
}
|
|
13144
13456
|
throw error;
|
|
13145
13457
|
}
|
|
13146
13458
|
signature = await this.auth.refreshToken(state, chainId, signature);
|
|
@@ -14250,7 +14562,7 @@ function runSameChainOrder(deps, options) {
|
|
|
14250
14562
|
|
|
14251
14563
|
// src/lib/swap/swap.secret-store.ts
|
|
14252
14564
|
var KEY_PREFIX4 = "owney.swap.order";
|
|
14253
|
-
var
|
|
14565
|
+
var storage7 = () => {
|
|
14254
14566
|
if (typeof window === "undefined") return null;
|
|
14255
14567
|
try {
|
|
14256
14568
|
return window.localStorage;
|
|
@@ -14260,7 +14572,7 @@ var storage5 = () => {
|
|
|
14260
14572
|
};
|
|
14261
14573
|
var keyFor2 = (orderHash) => `${KEY_PREFIX4}.${orderHash}`;
|
|
14262
14574
|
function saveOrder(order) {
|
|
14263
|
-
const store =
|
|
14575
|
+
const store = storage7();
|
|
14264
14576
|
if (!store) return false;
|
|
14265
14577
|
try {
|
|
14266
14578
|
const value = JSON.stringify(order);
|
|
@@ -14271,7 +14583,7 @@ function saveOrder(order) {
|
|
|
14271
14583
|
}
|
|
14272
14584
|
}
|
|
14273
14585
|
function loadOrder(orderHash) {
|
|
14274
|
-
const store =
|
|
14586
|
+
const store = storage7();
|
|
14275
14587
|
if (!store) return null;
|
|
14276
14588
|
try {
|
|
14277
14589
|
const raw2 = store.getItem(keyFor2(orderHash));
|
|
@@ -14286,7 +14598,7 @@ function loadOrder(orderHash) {
|
|
|
14286
14598
|
}
|
|
14287
14599
|
}
|
|
14288
14600
|
function clearOrder(orderHash) {
|
|
14289
|
-
const store =
|
|
14601
|
+
const store = storage7();
|
|
14290
14602
|
if (!store) return;
|
|
14291
14603
|
try {
|
|
14292
14604
|
store.removeItem(keyFor2(orderHash));
|
|
@@ -14294,7 +14606,7 @@ function clearOrder(orderHash) {
|
|
|
14294
14606
|
}
|
|
14295
14607
|
}
|
|
14296
14608
|
function listOrders(_now = Date.now()) {
|
|
14297
|
-
const store =
|
|
14609
|
+
const store = storage7();
|
|
14298
14610
|
if (!store) return [];
|
|
14299
14611
|
const out = [];
|
|
14300
14612
|
try {
|
|
@@ -15105,7 +15417,7 @@ async function buildErc2612Permit(reads, input) {
|
|
|
15105
15417
|
// src/lib/swap/swap.withdraw-swap.ts
|
|
15106
15418
|
var KEY_PREFIX5 = "owney.swap.withdraw";
|
|
15107
15419
|
var MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
15108
|
-
var
|
|
15420
|
+
var storage8 = () => {
|
|
15109
15421
|
if (typeof window === "undefined") return null;
|
|
15110
15422
|
try {
|
|
15111
15423
|
return window.localStorage;
|
|
@@ -15130,7 +15442,7 @@ var notify = () => {
|
|
|
15130
15442
|
}
|
|
15131
15443
|
};
|
|
15132
15444
|
function saveWithdrawSwap(record2) {
|
|
15133
|
-
const store =
|
|
15445
|
+
const store = storage8();
|
|
15134
15446
|
if (!store) return false;
|
|
15135
15447
|
try {
|
|
15136
15448
|
const current = store.getItem(keyFor3(record2.orderHash));
|
|
@@ -15144,7 +15456,7 @@ function saveWithdrawSwap(record2) {
|
|
|
15144
15456
|
return true;
|
|
15145
15457
|
}
|
|
15146
15458
|
function updateWithdrawSwap(orderHash, patch) {
|
|
15147
|
-
const store =
|
|
15459
|
+
const store = storage8();
|
|
15148
15460
|
if (!store) return;
|
|
15149
15461
|
try {
|
|
15150
15462
|
const raw2 = store.getItem(keyFor3(orderHash));
|
|
@@ -15161,7 +15473,7 @@ function updateWithdrawSwap(orderHash, patch) {
|
|
|
15161
15473
|
notify();
|
|
15162
15474
|
}
|
|
15163
15475
|
function clearWithdrawSwap(orderHash) {
|
|
15164
|
-
const store =
|
|
15476
|
+
const store = storage8();
|
|
15165
15477
|
if (!store) return;
|
|
15166
15478
|
try {
|
|
15167
15479
|
const raw2 = store.getItem(keyFor3(orderHash));
|
|
@@ -15175,7 +15487,7 @@ function clearWithdrawSwap(orderHash) {
|
|
|
15175
15487
|
notify();
|
|
15176
15488
|
}
|
|
15177
15489
|
function listWithdrawSwaps(now = Date.now(), includeDismissed = false) {
|
|
15178
|
-
const store =
|
|
15490
|
+
const store = storage8();
|
|
15179
15491
|
if (!store) return [];
|
|
15180
15492
|
const out = [];
|
|
15181
15493
|
try {
|
|
@@ -15212,7 +15524,7 @@ if (typeof window !== "undefined" && typeof window.addEventListener === "functio
|
|
|
15212
15524
|
// src/lib/swap/swap.pending-deposit.ts
|
|
15213
15525
|
var KEY_PREFIX6 = "owney.swap.pending-deposit";
|
|
15214
15526
|
var MAX_AGE_MS2 = 24 * 60 * 60 * 1e3;
|
|
15215
|
-
var
|
|
15527
|
+
var storage9 = () => {
|
|
15216
15528
|
if (typeof window === "undefined") return null;
|
|
15217
15529
|
try {
|
|
15218
15530
|
return window.localStorage;
|
|
@@ -15222,7 +15534,7 @@ var storage7 = () => {
|
|
|
15222
15534
|
};
|
|
15223
15535
|
var keyFor4 = (id) => `${KEY_PREFIX6}.${id}`;
|
|
15224
15536
|
function savePendingDeposit(entry) {
|
|
15225
|
-
const store =
|
|
15537
|
+
const store = storage9();
|
|
15226
15538
|
if (!store) return;
|
|
15227
15539
|
try {
|
|
15228
15540
|
store.setItem(keyFor4(entry.id), JSON.stringify(entry));
|
|
@@ -15231,7 +15543,7 @@ function savePendingDeposit(entry) {
|
|
|
15231
15543
|
}
|
|
15232
15544
|
}
|
|
15233
15545
|
function clearPendingDeposit(id) {
|
|
15234
|
-
const store =
|
|
15546
|
+
const store = storage9();
|
|
15235
15547
|
if (!store) return;
|
|
15236
15548
|
try {
|
|
15237
15549
|
store.removeItem(keyFor4(id));
|
|
@@ -15240,7 +15552,7 @@ function clearPendingDeposit(id) {
|
|
|
15240
15552
|
}
|
|
15241
15553
|
}
|
|
15242
15554
|
function listPendingDeposits(now = Date.now()) {
|
|
15243
|
-
const store =
|
|
15555
|
+
const store = storage9();
|
|
15244
15556
|
if (!store) return [];
|
|
15245
15557
|
const out = [];
|
|
15246
15558
|
try {
|
|
@@ -16743,14 +17055,8 @@ var OwneySDK = class {
|
|
|
16743
17055
|
*/
|
|
16744
17056
|
disabledAgents = /* @__PURE__ */ new Set();
|
|
16745
17057
|
accountRefusedListeners = /* @__PURE__ */ new Set();
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
* the prompt), keyed by chain. Until the app ends the session they are read
|
|
16749
|
-
* from a saved sign-in only (`readStateFor`), so no read reopens the prompt
|
|
16750
|
-
* the user cancelled. A later successful activation of the agent removes
|
|
16751
|
-
* it, and `disconnect()` or a different wallet's `connect()` clears the map.
|
|
16752
|
-
*/
|
|
16753
|
-
declinedSignIns = /* @__PURE__ */ new Map();
|
|
17058
|
+
signInRefusedListeners = /* @__PURE__ */ new Set();
|
|
17059
|
+
signInProgressListeners = /* @__PURE__ */ new Set();
|
|
16754
17060
|
state = null;
|
|
16755
17061
|
connectionRevision = 0;
|
|
16756
17062
|
disconnectingAgents = null;
|
|
@@ -16957,7 +17263,7 @@ var OwneySDK = class {
|
|
|
16957
17263
|
read: async () => {
|
|
16958
17264
|
const state = this.state;
|
|
16959
17265
|
if (!state || state.walletAddress.toLowerCase() !== owner) return null;
|
|
16960
|
-
const sample = await agent.providerEarningsSample(state, evidence.chainId);
|
|
17266
|
+
const sample = await agent.providerEarningsSample(this.readStateFor(state), evidence.chainId);
|
|
16961
17267
|
return sample ? { ...sample, observedAt: (/* @__PURE__ */ new Date()).toISOString() } : null;
|
|
16962
17268
|
},
|
|
16963
17269
|
emit: (data) => op.event?.("provider.sample", data)
|
|
@@ -16976,6 +17282,97 @@ var OwneySDK = class {
|
|
|
16976
17282
|
this.accountRefusedListeners.delete(listener);
|
|
16977
17283
|
};
|
|
16978
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
|
+
}
|
|
17298
|
+
/**
|
|
17299
|
+
* Listens for the sign-ins a connect asks for (`SignInProgress`): which
|
|
17300
|
+
* agents will ask the wallet to sign in, and each one as it starts and ends,
|
|
17301
|
+
* then `"finished"` after the last one (or when the connect ends first).
|
|
17302
|
+
* Nothing is sent when no agent needs a sign-in. Returns the unsubscribe
|
|
17303
|
+
* function.
|
|
17304
|
+
*/
|
|
17305
|
+
onSignInProgress(listener) {
|
|
17306
|
+
this.signInProgressListeners.add(listener);
|
|
17307
|
+
return () => {
|
|
17308
|
+
this.signInProgressListeners.delete(listener);
|
|
17309
|
+
};
|
|
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
|
+
}
|
|
17333
|
+
/**
|
|
17334
|
+
* The sign-ins this connect asks for: the agents whose `needsSignIn` says
|
|
17335
|
+
* yes now (one that throws counts as no). Each is announced at its first
|
|
17336
|
+
* step (its account check, or its activation when it has none) and counted
|
|
17337
|
+
* once.
|
|
17338
|
+
*/
|
|
17339
|
+
planSignIns(agents, state, chainId) {
|
|
17340
|
+
const planned = /* @__PURE__ */ new Set();
|
|
17341
|
+
for (const agent of agents) {
|
|
17342
|
+
try {
|
|
17343
|
+
if (agent.needsSignIn?.(state, chainId) === true) planned.add(agent.id);
|
|
17344
|
+
} catch {
|
|
17345
|
+
}
|
|
17346
|
+
}
|
|
17347
|
+
const total = planned.size;
|
|
17348
|
+
let done = 0;
|
|
17349
|
+
let finished = false;
|
|
17350
|
+
const send = (progress) => {
|
|
17351
|
+
if (total === 0 || finished) return;
|
|
17352
|
+
for (const listener of [...this.signInProgressListeners]) {
|
|
17353
|
+
try {
|
|
17354
|
+
listener(progress);
|
|
17355
|
+
} catch {
|
|
17356
|
+
}
|
|
17357
|
+
}
|
|
17358
|
+
};
|
|
17359
|
+
const finish = () => {
|
|
17360
|
+
send({ state: "finished", total, done });
|
|
17361
|
+
finished = true;
|
|
17362
|
+
};
|
|
17363
|
+
return {
|
|
17364
|
+
before: (agent) => {
|
|
17365
|
+
if (planned.has(agent.id)) send({ state: "waiting", total, done, agentId: agent.id });
|
|
17366
|
+
},
|
|
17367
|
+
after: (agent) => {
|
|
17368
|
+
if (!planned.delete(agent.id)) return;
|
|
17369
|
+
done += 1;
|
|
17370
|
+
send({ state: "signed", total, done, agentId: agent.id });
|
|
17371
|
+
if (done === total) finish();
|
|
17372
|
+
},
|
|
17373
|
+
finish
|
|
17374
|
+
};
|
|
17375
|
+
}
|
|
16979
17376
|
/** Wires the optional hooks the SDK offers an agent. */
|
|
16980
17377
|
attachAgentHooks(agent) {
|
|
16981
17378
|
try {
|
|
@@ -16990,6 +17387,14 @@ var OwneySDK = class {
|
|
|
16990
17387
|
}
|
|
16991
17388
|
}
|
|
16992
17389
|
});
|
|
17390
|
+
agent.setSignInRefusedListener?.(() => {
|
|
17391
|
+
for (const listener of [...this.signInRefusedListeners]) {
|
|
17392
|
+
try {
|
|
17393
|
+
listener(agent.id);
|
|
17394
|
+
} catch {
|
|
17395
|
+
}
|
|
17396
|
+
}
|
|
17397
|
+
});
|
|
16993
17398
|
}
|
|
16994
17399
|
/**
|
|
16995
17400
|
* Funding-ledger read access handed to agents for earnings holds. Reads only
|
|
@@ -17069,7 +17474,6 @@ var OwneySDK = class {
|
|
|
17069
17474
|
}
|
|
17070
17475
|
const replacingOwner = this.state !== null && this.state.walletAddress.toLowerCase() !== walletAddress.toLowerCase();
|
|
17071
17476
|
this.clearConnectionState();
|
|
17072
|
-
if (replacingOwner) this.declinedSignIns.clear();
|
|
17073
17477
|
await (replacingOwner ? this.disconnectAgents() : this.disconnectingAgents);
|
|
17074
17478
|
if (revision !== this.connectionRevision)
|
|
17075
17479
|
throw new OwneyError("NOT_CONNECTED", "Wallet connection changed while connecting.");
|
|
@@ -17083,11 +17487,10 @@ var OwneySDK = class {
|
|
|
17083
17487
|
* Disconnect from all agents and clear connection state.
|
|
17084
17488
|
* After calling this, `connect()` must be called again before using agent methods.
|
|
17085
17489
|
*/
|
|
17086
|
-
async disconnect() {
|
|
17490
|
+
async disconnect(options) {
|
|
17087
17491
|
++this.connectionRevision;
|
|
17088
17492
|
this.clearConnectionState();
|
|
17089
|
-
this.
|
|
17090
|
-
await this.disconnectAgents();
|
|
17493
|
+
await this.disconnectAgents(options);
|
|
17091
17494
|
}
|
|
17092
17495
|
clearConnectionState() {
|
|
17093
17496
|
this.state = null;
|
|
@@ -17099,9 +17502,9 @@ var OwneySDK = class {
|
|
|
17099
17502
|
this.cachedWethSponsoredCallback = null;
|
|
17100
17503
|
this.cachedSponsoredCallsCallbacks.clear();
|
|
17101
17504
|
}
|
|
17102
|
-
disconnectAgents() {
|
|
17505
|
+
disconnectAgents(options) {
|
|
17103
17506
|
if (this.disconnectingAgents) return this.disconnectingAgents;
|
|
17104
|
-
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) => {
|
|
17105
17508
|
const failure = results.find((result) => result.status === "rejected");
|
|
17106
17509
|
if (failure?.status === "rejected") throw failure.reason;
|
|
17107
17510
|
});
|
|
@@ -17142,17 +17545,14 @@ var OwneySDK = class {
|
|
|
17142
17545
|
return agent?.isSlotUnavailable?.(state, chainId, asset) === true;
|
|
17143
17546
|
}
|
|
17144
17547
|
/**
|
|
17145
|
-
* The state
|
|
17146
|
-
*
|
|
17147
|
-
*
|
|
17148
|
-
*
|
|
17149
|
-
*
|
|
17150
|
-
* 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.
|
|
17151
17553
|
*/
|
|
17152
|
-
readStateFor(
|
|
17153
|
-
|
|
17154
|
-
if (state.promptless === true || chainId === null) return state;
|
|
17155
|
-
return this.declinedSignIns.get(chainId)?.has(agentId) === true ? { ...state, promptless: true } : state;
|
|
17554
|
+
readStateFor(state) {
|
|
17555
|
+
return state.promptless === true ? state : { ...state, promptless: true };
|
|
17156
17556
|
}
|
|
17157
17557
|
/**
|
|
17158
17558
|
* Check if the SDK has an active connection state.
|
|
@@ -17376,7 +17776,7 @@ var OwneySDK = class {
|
|
|
17376
17776
|
}
|
|
17377
17777
|
/** The active agents, each with the state its reads use (`readStateFor`). */
|
|
17378
17778
|
activeReads(state, chainId) {
|
|
17379
|
-
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 }));
|
|
17380
17780
|
}
|
|
17381
17781
|
/**
|
|
17382
17782
|
* Read the org's agent policy once and reuse it. fetchOrgAgentConfig never
|
|
@@ -17640,6 +18040,14 @@ var OwneySDK = class {
|
|
|
17640
18040
|
* activation, with nothing activated.
|
|
17641
18041
|
*/
|
|
17642
18042
|
async activateAgentsInTurn(agents, state, chainId, asset, onAgentsSelected) {
|
|
18043
|
+
const signIns = this.planSignIns(agents, state, chainId);
|
|
18044
|
+
try {
|
|
18045
|
+
await this.activatePlannedAgents(agents, state, chainId, signIns, asset, onAgentsSelected);
|
|
18046
|
+
} finally {
|
|
18047
|
+
signIns.finish();
|
|
18048
|
+
}
|
|
18049
|
+
}
|
|
18050
|
+
async activatePlannedAgents(agents, state, chainId, signIns, asset, onAgentsSelected) {
|
|
17643
18051
|
let firstError = null;
|
|
17644
18052
|
let walletRejected = false;
|
|
17645
18053
|
const activatedAgentIds = [];
|
|
@@ -17654,19 +18062,16 @@ var OwneySDK = class {
|
|
|
17654
18062
|
...error instanceof OwneyError && error.details ? { details: error.details } : {}
|
|
17655
18063
|
});
|
|
17656
18064
|
firstError = error;
|
|
17657
|
-
if (this.isUserRejectedWithdrawal(error))
|
|
17658
|
-
walletRejected = true;
|
|
17659
|
-
const declined = this.declinedSignIns.get(chainId) ?? /* @__PURE__ */ new Set();
|
|
17660
|
-
declined.add(agent.id);
|
|
17661
|
-
this.declinedSignIns.set(chainId, declined);
|
|
17662
|
-
}
|
|
18065
|
+
if (this.isUserRejectedWithdrawal(error)) walletRejected = true;
|
|
17663
18066
|
};
|
|
17664
18067
|
for (const agent of agents) {
|
|
17665
18068
|
if (!agent.checkAccount) continue;
|
|
17666
18069
|
this.assertActivationSession(state);
|
|
17667
18070
|
try {
|
|
18071
|
+
signIns.before(agent);
|
|
17668
18072
|
await agent.checkAccount(state, chainId);
|
|
17669
18073
|
this.assertActivationSession(state);
|
|
18074
|
+
signIns.after(agent);
|
|
17670
18075
|
} catch (error) {
|
|
17671
18076
|
recordFailure(agent, error);
|
|
17672
18077
|
break;
|
|
@@ -17677,12 +18082,13 @@ var OwneySDK = class {
|
|
|
17677
18082
|
for (const agent of agents) {
|
|
17678
18083
|
this.assertActivationSession(state);
|
|
17679
18084
|
try {
|
|
18085
|
+
signIns.before(agent);
|
|
17680
18086
|
await agent.activateAgent(state, chainId, asset);
|
|
17681
18087
|
this.assertActivationSession(state);
|
|
18088
|
+
signIns.after(agent);
|
|
17682
18089
|
await this.applyOrgPolicyTo(agent, state, chainId);
|
|
17683
18090
|
this.assertActivationSession(state);
|
|
17684
18091
|
activatedAgentIds.push(agent.id);
|
|
17685
|
-
this.declinedSignIns.get(chainId)?.delete(agent.id);
|
|
17686
18092
|
} catch (error) {
|
|
17687
18093
|
recordFailure(agent, error);
|
|
17688
18094
|
break;
|
|
@@ -18416,7 +18822,8 @@ var OwneySDK = class {
|
|
|
18416
18822
|
}
|
|
18417
18823
|
/** Revalidate a saved transfer against the authenticated account and actual receipt. */
|
|
18418
18824
|
async inspectFunding(evidence, direction, options = {}) {
|
|
18419
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
18825
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
18826
|
+
const state = this.readStateFor(connection);
|
|
18420
18827
|
if (state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase() || !evidence.txHash)
|
|
18421
18828
|
throw new OwneyError("AGENT_API_ERROR", "Funding evidence does not match the connected account.");
|
|
18422
18829
|
const agent = this.getAgent(evidence.agentId);
|
|
@@ -18529,8 +18936,9 @@ var OwneySDK = class {
|
|
|
18529
18936
|
const movement = evidence.txHash ?? evidence.userOpHash ?? evidence.callsId;
|
|
18530
18937
|
if (!agent?.depositConfirmed || !movement) return;
|
|
18531
18938
|
const key2 = `${state.walletAddress.toLowerCase()}:${chainId}:${evidence.agentId}:${evidence.token}:${movement.toLowerCase()}`;
|
|
18532
|
-
if (this.announcedDeposits.has(key2)) return;
|
|
18939
|
+
if (this.announcedDeposits.has(key2) || wasDepositAnnounced(key2)) return;
|
|
18533
18940
|
this.announcedDeposits.add(key2);
|
|
18941
|
+
rememberAnnouncedDeposit(key2);
|
|
18534
18942
|
if (this.announcedDeposits.size > 256) this.announcedDeposits.delete(this.announcedDeposits.values().next().value);
|
|
18535
18943
|
const legKey = `agent:${evidence.agentId}`;
|
|
18536
18944
|
const record2 = (type, notice) => {
|
|
@@ -18591,7 +18999,8 @@ var OwneySDK = class {
|
|
|
18591
18999
|
const fromBlock = parseBlock(opts?.fromBlock ?? evidence.payoutSearch?.fromBlock);
|
|
18592
19000
|
const cursor = parseBlock(opts?.cursor);
|
|
18593
19001
|
if (fromBlock === null || cursor === null) return null;
|
|
18594
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19002
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19003
|
+
const state = this.readStateFor(connection);
|
|
18595
19004
|
if (typeof evidence.walletAddress !== "string" || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18596
19005
|
const agent = this.getAgent(evidence.agentId);
|
|
18597
19006
|
const verifiedWallet = agent.getFundingWallet ? await agent.getFundingWallet(state, chainId, evidence.token) : (await agent.getUserProfile(state, chainId)).smartWallet;
|
|
@@ -18616,7 +19025,8 @@ var OwneySDK = class {
|
|
|
18616
19025
|
/** Resolve a saved sponsored-withdrawal ID without opening a wallet prompt. */
|
|
18617
19026
|
async resolveSponsoredWithdrawalEvidence(evidence, options = {}) {
|
|
18618
19027
|
if (evidence.callsId && !evidence.userOpHash) return this.resolveWalletCallsFundingEvidence(evidence, "withdraw");
|
|
18619
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19028
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19029
|
+
const state = this.readStateFor(connection);
|
|
18620
19030
|
if (evidence.agentId !== "yieldseeker" || chainId !== 8453 || evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return evidence;
|
|
18621
19031
|
const agent = this.getAgent("yieldseeker");
|
|
18622
19032
|
const wallet = await agent.getFundingWallet?.(state, chainId, evidence.token);
|
|
@@ -18663,7 +19073,8 @@ var OwneySDK = class {
|
|
|
18663
19073
|
}
|
|
18664
19074
|
/** Recover an EIP-5792 deposit or payout using this account's exact batch ID. */
|
|
18665
19075
|
async resolveWalletCallsFundingEvidence(evidence, direction) {
|
|
18666
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19076
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19077
|
+
const state = this.readStateFor(connection);
|
|
18667
19078
|
if (!evidence.callsId || evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return evidence;
|
|
18668
19079
|
const agent = this.getAgent(evidence.agentId);
|
|
18669
19080
|
const wallet = agent.getFundingWallet ? await agent.getFundingWallet(state, chainId, evidence.token) : (await agent.getUserProfile(state, chainId)).smartWallet;
|
|
@@ -18696,7 +19107,8 @@ var OwneySDK = class {
|
|
|
18696
19107
|
const first = evidences[0];
|
|
18697
19108
|
const saved = !first.txHash && evidences.every((e) => !e.txHash && (e.serverBroadcast === "unknown" || e.serverBroadcast === true) && typeof e.authorizationDeadline === "number");
|
|
18698
19109
|
if (!first.txHash && !saved) return false;
|
|
18699
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(first.chainId);
|
|
19110
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(first.chainId);
|
|
19111
|
+
const state = this.readStateFor(connection);
|
|
18700
19112
|
const token = SupportedAssets.find((value) => value.chainId === chainId && value.symbol === first.token);
|
|
18701
19113
|
if (!token) return false;
|
|
18702
19114
|
const scope = {
|
|
@@ -18813,7 +19225,8 @@ var OwneySDK = class {
|
|
|
18813
19225
|
/** Optional post-payout display proof; receipt verification and the provider
|
|
18814
19226
|
* adapter must agree before attaching it to this exact balance object. */
|
|
18815
19227
|
async verifyWithdrawalBalance(evidence, balance) {
|
|
18816
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19228
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19229
|
+
const state = this.readStateFor(connection);
|
|
18817
19230
|
const agent = this.getAgent(evidence.agentId);
|
|
18818
19231
|
if (!agent.verifyWithdrawalBalance || !evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return balance;
|
|
18819
19232
|
const key2 = `${state.walletAddress.toLowerCase()}:${chainId}:${evidence.agentId}:${evidence.token}:${evidence.txHash}:${evidence.intendedAmount}`;
|
|
@@ -18862,7 +19275,8 @@ var OwneySDK = class {
|
|
|
18862
19275
|
const agent = this.getAgent(evidence.agentId);
|
|
18863
19276
|
if (!agent.getFundingHistory) return { data: [], hasMore: false };
|
|
18864
19277
|
const filters = { tokenSymbol: evidence.token, fromDate, limit: 50, ...options };
|
|
18865
|
-
const
|
|
19278
|
+
const readState = this.readStateFor(state);
|
|
19279
|
+
const page = await this.readAgent(agent, "history", () => agent.getFundingHistory(readState, chainId, filters), filters);
|
|
18866
19280
|
assertCurrent();
|
|
18867
19281
|
return page;
|
|
18868
19282
|
}
|
|
@@ -18879,7 +19293,7 @@ var OwneySDK = class {
|
|
|
18879
19293
|
const state = this.state;
|
|
18880
19294
|
const id = evidence.withdrawalRequest?.providerWithdrawalId;
|
|
18881
19295
|
if (evidence.agentId !== "zyfai" || !id || !state || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18882
|
-
return this.getAgent("zyfai").getWithdrawalLifecycle(state, id);
|
|
19296
|
+
return this.getAgent("zyfai").getWithdrawalLifecycle(this.readStateFor(state), id);
|
|
18883
19297
|
}
|
|
18884
19298
|
/** A Zyfai deposit's placement status by the id recorded on its evidence. Never signs,
|
|
18885
19299
|
* prompts or authenticates; `null` when unavailable or not this wallet's Zyfai deposit. */
|
|
@@ -18887,7 +19301,7 @@ var OwneySDK = class {
|
|
|
18887
19301
|
const state = this.state;
|
|
18888
19302
|
const id = evidence.providerDepositId;
|
|
18889
19303
|
if (evidence.agentId !== "zyfai" || !id || !state || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18890
|
-
return this.getAgent("zyfai").getDepositPlacement(state, id);
|
|
19304
|
+
return this.getAgent("zyfai").getDepositPlacement(this.readStateFor(state), id);
|
|
18891
19305
|
}
|
|
18892
19306
|
// --- Fund operations ---
|
|
18893
19307
|
/** On-chain version and ownership status for this owner's Yieldseeker agent. */
|
|
@@ -18895,7 +19309,7 @@ var OwneySDK = class {
|
|
|
18895
19309
|
const state = this.requireState();
|
|
18896
19310
|
const chainId = this.requireChainId();
|
|
18897
19311
|
const agent = this.getAgent("yieldseeker");
|
|
18898
|
-
return agent.getWalletStatus(state, chainId, asset);
|
|
19312
|
+
return agent.getWalletStatus(this.readStateFor(state), chainId, asset);
|
|
18899
19313
|
}
|
|
18900
19314
|
/** Deployment gate; an unavailable response keeps the current paid path. */
|
|
18901
19315
|
async isYieldseekerWithdrawalSponsorshipAvailable() {
|
|
@@ -19968,7 +20382,7 @@ var OwneySDK = class {
|
|
|
19968
20382
|
inspect: (value, fromHistory) => this.inspectFunding(value, "withdraw", { requireAmountMatch: fromHistory, refreshBalance: false }),
|
|
19969
20383
|
resolve: (value) => this.resolveSponsoredWithdrawalEvidence(value, { submittedAt: recovery.submittedAt }),
|
|
19970
20384
|
history: (value, fromDate, filters) => this.getFundingHistory(value, fromDate, filters),
|
|
19971
|
-
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" }),
|
|
19972
20386
|
onProgress: (value) => {
|
|
19973
20387
|
recovery.evidence[value.agentId] = value;
|
|
19974
20388
|
persist();
|
|
@@ -21388,7 +21802,7 @@ var OwneySDK = class {
|
|
|
21388
21802
|
const { state: scope, chainId, assertCurrent } = this.captureReadScope(options?.chainId);
|
|
21389
21803
|
const asset = options?.asset;
|
|
21390
21804
|
const agent = this.getAgent(agentId);
|
|
21391
|
-
const state = this.readStateFor(
|
|
21805
|
+
const state = this.readStateFor(scope);
|
|
21392
21806
|
const result = await this.readAgent(
|
|
21393
21807
|
agent,
|
|
21394
21808
|
"balances",
|
|
@@ -21487,7 +21901,7 @@ var OwneySDK = class {
|
|
|
21487
21901
|
const chainId = this.requireChainId();
|
|
21488
21902
|
if (agentId) {
|
|
21489
21903
|
const agent = this.getAgent(agentId);
|
|
21490
|
-
const readState = this.readStateFor(
|
|
21904
|
+
const readState = this.readStateFor(state);
|
|
21491
21905
|
return this.readAgent(
|
|
21492
21906
|
agent,
|
|
21493
21907
|
"earnings",
|
|
@@ -21517,7 +21931,7 @@ var OwneySDK = class {
|
|
|
21517
21931
|
() => agent.refreshEarnings?.(readState, readChain) ?? agent.getEarnings(readState, readChain),
|
|
21518
21932
|
offChain ? { chainId: readChain } : null
|
|
21519
21933
|
);
|
|
21520
|
-
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 });
|
|
21521
21935
|
return this.aggregateEarnings(this.portfolioReads(state, chainId), refreshAgent);
|
|
21522
21936
|
}
|
|
21523
21937
|
async aggregateEarnings(entries, read2) {
|
|
@@ -21585,7 +21999,7 @@ var OwneySDK = class {
|
|
|
21585
21999
|
for (const agent of agents) {
|
|
21586
22000
|
for (const legChainId of chainIds) {
|
|
21587
22001
|
if (agentRunsOn(agent, legChainId))
|
|
21588
|
-
legs.push({ agent, legChainId, legState: this.readStateFor(
|
|
22002
|
+
legs.push({ agent, legChainId, legState: this.readStateFor(state) });
|
|
21589
22003
|
}
|
|
21590
22004
|
}
|
|
21591
22005
|
if (!agentId) {
|
|
@@ -21625,7 +22039,7 @@ var OwneySDK = class {
|
|
|
21625
22039
|
assets: []
|
|
21626
22040
|
};
|
|
21627
22041
|
}
|
|
21628
|
-
const readState = this.readStateFor(
|
|
22042
|
+
const readState = this.readStateFor(state);
|
|
21629
22043
|
return this.readAgent(
|
|
21630
22044
|
agent,
|
|
21631
22045
|
"dailyEarnings",
|
|
@@ -21706,7 +22120,7 @@ var OwneySDK = class {
|
|
|
21706
22120
|
`Agent ${agent.id} does not support pool customization`
|
|
21707
22121
|
);
|
|
21708
22122
|
}
|
|
21709
|
-
return agent.getPoolSelection(state, chainId, {
|
|
22123
|
+
return agent.getPoolSelection(this.readStateFor(state), chainId, {
|
|
21710
22124
|
pairs: params.pairs,
|
|
21711
22125
|
assets: params.assets
|
|
21712
22126
|
});
|
|
@@ -21731,7 +22145,7 @@ var OwneySDK = class {
|
|
|
21731
22145
|
const scopeChainId = scope === "all" ? null : scope;
|
|
21732
22146
|
if (agentId) {
|
|
21733
22147
|
const agent = this.getAgent(agentId);
|
|
21734
|
-
const readState = this.readStateFor(
|
|
22148
|
+
const readState = this.readStateFor(state);
|
|
21735
22149
|
const accountApy = await this.readAgent(
|
|
21736
22150
|
agent,
|
|
21737
22151
|
"accountApy",
|
|
@@ -21871,7 +22285,7 @@ var OwneySDK = class {
|
|
|
21871
22285
|
for (const agent of agents) {
|
|
21872
22286
|
for (const legChainId of chainIds) {
|
|
21873
22287
|
if (agentRunsOn(agent, legChainId))
|
|
21874
|
-
legs.push({ agentId: agent.id, chainId: legChainId, legState: this.readStateFor(
|
|
22288
|
+
legs.push({ agentId: agent.id, chainId: legChainId, legState: this.readStateFor(state2) });
|
|
21875
22289
|
}
|
|
21876
22290
|
}
|
|
21877
22291
|
if (!agentId) {
|
|
@@ -21915,7 +22329,7 @@ var OwneySDK = class {
|
|
|
21915
22329
|
const { state, chainId, assertCurrent } = this.captureReadScope(options?.chainId);
|
|
21916
22330
|
if (agentId) {
|
|
21917
22331
|
const agent = this.getAgent(agentId);
|
|
21918
|
-
const readState = this.readStateFor(
|
|
22332
|
+
const readState = this.readStateFor(state);
|
|
21919
22333
|
const page = await this.readAgent(agent, "history", () => agent.getHistory(readState, chainId, filters), filters);
|
|
21920
22334
|
assertCurrent();
|
|
21921
22335
|
return page;
|
|
@@ -21930,7 +22344,7 @@ var OwneySDK = class {
|
|
|
21930
22344
|
}
|
|
21931
22345
|
const agentFilters = { ...filters, cursor: agentCursor || void 0 };
|
|
21932
22346
|
try {
|
|
21933
|
-
const readState = this.readStateFor(
|
|
22347
|
+
const readState = this.readStateFor(state);
|
|
21934
22348
|
const page = await this.readAgent(
|
|
21935
22349
|
agent,
|
|
21936
22350
|
"history",
|
|
@@ -21992,7 +22406,7 @@ var OwneySDK = class {
|
|
|
21992
22406
|
const chainId = this.requireChainId();
|
|
21993
22407
|
if (agentId) {
|
|
21994
22408
|
const agent = this.getAgent(agentId);
|
|
21995
|
-
const readState = this.readStateFor(
|
|
22409
|
+
const readState = this.readStateFor(state);
|
|
21996
22410
|
return this.readAgent(
|
|
21997
22411
|
agent,
|
|
21998
22412
|
"profile",
|
|
@@ -22215,7 +22629,7 @@ var OwneySDK = class {
|
|
|
22215
22629
|
const entries = [...activeAgents.entries()];
|
|
22216
22630
|
const balanceResults = await Promise.allSettled(
|
|
22217
22631
|
entries.map(async ([id, agent]) => {
|
|
22218
|
-
const readState = this.readStateFor(
|
|
22632
|
+
const readState = this.readStateFor(state);
|
|
22219
22633
|
const b = await this.readAgent(
|
|
22220
22634
|
agent,
|
|
22221
22635
|
"balances",
|
|
@@ -22271,7 +22685,7 @@ import { ZyfaiSDK as ZyfaiSDK2 } from "@zyfai/sdk";
|
|
|
22271
22685
|
|
|
22272
22686
|
// src/agents/zyfai/zyfai.siwx-cache.ts
|
|
22273
22687
|
var KEY_PREFIX7 = "owney.siwx.session";
|
|
22274
|
-
var
|
|
22688
|
+
var storage10 = () => {
|
|
22275
22689
|
if (typeof window === "undefined") return null;
|
|
22276
22690
|
try {
|
|
22277
22691
|
return window.localStorage;
|
|
@@ -22312,7 +22726,7 @@ var readLegacySiwxSession = (store, address) => {
|
|
|
22312
22726
|
var readSiwxSession = (address, chainId) => {
|
|
22313
22727
|
if (typeof window === "undefined") return null;
|
|
22314
22728
|
const key2 = buildKey3(address);
|
|
22315
|
-
const store =
|
|
22729
|
+
const store = storage10();
|
|
22316
22730
|
let raw2 = null;
|
|
22317
22731
|
try {
|
|
22318
22732
|
raw2 = store?.getItem(key2) ?? null;
|
|
@@ -22342,7 +22756,7 @@ var writeSiwxSession = (address, _chainId, session) => {
|
|
|
22342
22756
|
if (typeof window === "undefined") return;
|
|
22343
22757
|
const key2 = buildKey3(address);
|
|
22344
22758
|
memorySiwxSessions.set(key2, session);
|
|
22345
|
-
const store =
|
|
22759
|
+
const store = storage10();
|
|
22346
22760
|
try {
|
|
22347
22761
|
store?.setItem(key2, JSON.stringify(session));
|
|
22348
22762
|
} catch {
|
|
@@ -22351,7 +22765,7 @@ var writeSiwxSession = (address, _chainId, session) => {
|
|
|
22351
22765
|
var clearSiwxSession = (address, _chainId) => {
|
|
22352
22766
|
const key2 = buildKey3(address);
|
|
22353
22767
|
memorySiwxSessions.delete(key2);
|
|
22354
|
-
const store =
|
|
22768
|
+
const store = storage10();
|
|
22355
22769
|
try {
|
|
22356
22770
|
store?.removeItem(key2);
|
|
22357
22771
|
} catch {
|