@owney/sdk 0.7.32-beta.11 → 0.7.32-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +615 -181
- package/dist/index.d.cts +71 -30
- package/dist/index.d.ts +71 -30
- package/dist/index.js +612 -178
- package/package.json +1 -1
package/dist/index.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.13";
|
|
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 {
|
|
@@ -3694,8 +3734,11 @@ var clearSession = (address, _chainId) => {
|
|
|
3694
3734
|
function buildAutoSelectUpdate(current, asset, chainId) {
|
|
3695
3735
|
const chains = current.chains ?? [];
|
|
3696
3736
|
const chainMissing = chainId !== void 0 && !chains.includes(chainId);
|
|
3697
|
-
if (current.autoSelectProtocols === true && !chainMissing) return null;
|
|
3698
3737
|
const nextChains = chainMissing ? [...chains, chainId] : chains;
|
|
3738
|
+
if (current.savedPoolChoices) {
|
|
3739
|
+
return chainMissing ? { asset, chains: nextChains } : null;
|
|
3740
|
+
}
|
|
3741
|
+
if (current.autoSelectProtocols === true && !chainMissing) return null;
|
|
3699
3742
|
return {
|
|
3700
3743
|
asset,
|
|
3701
3744
|
autoSelectProtocols: true,
|
|
@@ -3845,11 +3888,107 @@ function protocolsPolicyNeedsUpdate(current, desiredProtocols, desiredAutoSelect
|
|
|
3845
3888
|
}
|
|
3846
3889
|
function mergeScopedPoolNames(current, scoped, allAvailableNames) {
|
|
3847
3890
|
const managed = new Set(scoped.flatMap((entry) => entry.availablePools));
|
|
3891
|
+
const offered = new Set(allAvailableNames);
|
|
3848
3892
|
const existing = current.autoselect ? allAvailableNames : current.pools;
|
|
3849
|
-
const preserved = existing.filter(
|
|
3893
|
+
const preserved = existing.filter(
|
|
3894
|
+
(name) => !managed.has(name) && (offered.size === 0 || offered.has(name))
|
|
3895
|
+
);
|
|
3850
3896
|
const selected = scoped.flatMap((entry) => entry.pools);
|
|
3851
3897
|
return [.../* @__PURE__ */ new Set([...preserved, ...selected])];
|
|
3852
3898
|
}
|
|
3899
|
+
function savedPoolRecords(customization, protocolId, chainId) {
|
|
3900
|
+
if (!customization || typeof customization !== "object") return [];
|
|
3901
|
+
const records = [];
|
|
3902
|
+
for (const byProtocol of Object.values(customization)) {
|
|
3903
|
+
const byChain = byProtocol?.[protocolId];
|
|
3904
|
+
const record2 = byChain?.[String(chainId)];
|
|
3905
|
+
if (!record2 || typeof record2 !== "object") continue;
|
|
3906
|
+
records.push({
|
|
3907
|
+
pools: Array.isArray(record2.pools) ? record2.pools.filter((name) => typeof name === "string") : [],
|
|
3908
|
+
autoselect: typeof record2.autoselect === "boolean" ? record2.autoselect : void 0
|
|
3909
|
+
});
|
|
3910
|
+
}
|
|
3911
|
+
return records;
|
|
3912
|
+
}
|
|
3913
|
+
function hasManualPoolChoices(customization) {
|
|
3914
|
+
return manuallyChosenProtocols(customization).size > 0;
|
|
3915
|
+
}
|
|
3916
|
+
function manuallyChosenProtocols(customization) {
|
|
3917
|
+
const chosen = /* @__PURE__ */ new Set();
|
|
3918
|
+
if (!customization || typeof customization !== "object") return chosen;
|
|
3919
|
+
for (const byProtocol of Object.values(customization)) {
|
|
3920
|
+
for (const [protocolId, byChain] of Object.entries(byProtocol ?? {})) {
|
|
3921
|
+
const manual = Object.values(byChain ?? {}).some(
|
|
3922
|
+
(record2) => record2?.autoselect === false
|
|
3923
|
+
);
|
|
3924
|
+
if (manual) chosen.add(protocolId);
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
return chosen;
|
|
3928
|
+
}
|
|
3929
|
+
function manualChainsOf(customization, protocolId) {
|
|
3930
|
+
if (!customization || typeof customization !== "object") return [];
|
|
3931
|
+
const chains = /* @__PURE__ */ new Set();
|
|
3932
|
+
for (const byProtocol of Object.values(customization)) {
|
|
3933
|
+
const byChain = byProtocol?.[protocolId];
|
|
3934
|
+
for (const [chainKey, record2] of Object.entries(byChain ?? {})) {
|
|
3935
|
+
const chainId = Number(chainKey);
|
|
3936
|
+
if (Number.isFinite(chainId) && record2?.autoselect === false) {
|
|
3937
|
+
chains.add(chainId);
|
|
3938
|
+
}
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
3941
|
+
return [...chains];
|
|
3942
|
+
}
|
|
3943
|
+
function protocolsSyncLeavesOff(customization, available, assetChains) {
|
|
3944
|
+
const off = /* @__PURE__ */ new Set();
|
|
3945
|
+
for (const protocol of available) {
|
|
3946
|
+
const chains = (protocol.chains ?? []).filter((chainId) => assetChains.includes(chainId));
|
|
3947
|
+
if (chains.length === 0) continue;
|
|
3948
|
+
const decided = chains.every((chainId) => {
|
|
3949
|
+
const records = savedPoolRecords(customization, protocol.id, chainId);
|
|
3950
|
+
return records.length > 0 && !savedRecordsAreAuto(records);
|
|
3951
|
+
});
|
|
3952
|
+
if (decided) off.add(protocol.id);
|
|
3953
|
+
}
|
|
3954
|
+
return off;
|
|
3955
|
+
}
|
|
3956
|
+
function tokenIsAsset(token, asset) {
|
|
3957
|
+
const upper = token.toUpperCase();
|
|
3958
|
+
return asset === "WETH" ? upper === "WETH" || upper === "ETH" : upper === asset;
|
|
3959
|
+
}
|
|
3960
|
+
function savedRecordsAreAuto(records) {
|
|
3961
|
+
return records.length === 0 || records.some((record2) => record2.autoselect !== false);
|
|
3962
|
+
}
|
|
3963
|
+
function protocolsToKeep(params) {
|
|
3964
|
+
const { asset, chains, customization, catalogs } = params;
|
|
3965
|
+
const entries = params.selections.filter(
|
|
3966
|
+
(entry) => entry.asset === asset && entry.availablePools.length > 0
|
|
3967
|
+
);
|
|
3968
|
+
const picked = entries.filter((entry) => entry.pools.length > 0).map((entry) => entry.protocolId);
|
|
3969
|
+
const candidates = [.../* @__PURE__ */ new Set([...params.current, ...picked])];
|
|
3970
|
+
const inUse = (protocolId) => {
|
|
3971
|
+
if (picked.includes(protocolId)) return true;
|
|
3972
|
+
const catalog = catalogs.get(protocolId);
|
|
3973
|
+
if (!catalog || catalog.length === 0) return true;
|
|
3974
|
+
const covered = new Set(
|
|
3975
|
+
entries.filter((entry) => entry.protocolId === protocolId).map((entry) => entry.chainId)
|
|
3976
|
+
);
|
|
3977
|
+
const assetChains = new Set(chains);
|
|
3978
|
+
const toCheck = [.../* @__PURE__ */ new Set([...chains, ...manualChainsOf(customization, protocolId)])];
|
|
3979
|
+
return toCheck.some((chainId) => {
|
|
3980
|
+
if (covered.has(chainId)) return false;
|
|
3981
|
+
const offered = new Set(
|
|
3982
|
+
catalog.filter((pool) => pool.chainId === chainId && tokenIsAsset(pool.token, asset)).map((pool) => pool.name)
|
|
3983
|
+
);
|
|
3984
|
+
if (offered.size === 0) return false;
|
|
3985
|
+
const records = savedPoolRecords(customization, protocolId, chainId);
|
|
3986
|
+
return assetChains.has(chainId) && savedRecordsAreAuto(records) || records.some((record2) => record2.autoselect === false && record2.pools.some((name) => offered.has(name)));
|
|
3987
|
+
});
|
|
3988
|
+
};
|
|
3989
|
+
const kept = candidates.filter(inUse);
|
|
3990
|
+
return kept.length > 0 ? kept : candidates;
|
|
3991
|
+
}
|
|
3853
3992
|
function mapAvailablePools(raw2) {
|
|
3854
3993
|
const byChain = raw2 ?? {};
|
|
3855
3994
|
if (typeof byChain !== "object" || byChain === null) return [];
|
|
@@ -4180,6 +4319,8 @@ async function withPaidRpcDiagnostics(operation, chainId, rpcMethod, agentId) {
|
|
|
4180
4319
|
var ERC7579_IS_MODULE_INSTALLED_ABI = parseAbi3([
|
|
4181
4320
|
"function isModuleInstalled(uint256 moduleTypeId, address module, bytes additionalContext) view returns (bool)"
|
|
4182
4321
|
]);
|
|
4322
|
+
var ZYFAI_SIGN_IN_REQUIRED_MESSAGE = "No Zyfai sign-in is available without a prompt.";
|
|
4323
|
+
var isSignInFailure = (error) => error instanceof OwneyError && error.code === "AGENT_AUTH_FAILED";
|
|
4183
4324
|
var WETH_ADDRESS_BY_CHAIN = {
|
|
4184
4325
|
8453: "0x4200000000000000000000000000000000000006",
|
|
4185
4326
|
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
@@ -4294,6 +4435,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4294
4435
|
}
|
|
4295
4436
|
];
|
|
4296
4437
|
sdk;
|
|
4438
|
+
signInRefusedListener;
|
|
4297
4439
|
connectedAddress = null;
|
|
4298
4440
|
connectedChainId = null;
|
|
4299
4441
|
smartWalletCache = /* @__PURE__ */ new Map();
|
|
@@ -4308,6 +4450,12 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4308
4450
|
reportedAccounts = /* @__PURE__ */ new Set();
|
|
4309
4451
|
connectAuthPromise = null;
|
|
4310
4452
|
connectAuthScope = null;
|
|
4453
|
+
/** Whether `connectAuthPromise` is a read's connect, which never signs. */
|
|
4454
|
+
connectAuthPromptless = false;
|
|
4455
|
+
/** Vendor clients that may not sign in: one connecting for a read, and one
|
|
4456
|
+
* whose session a read dropped (the next connect replaces it). Their sign-in
|
|
4457
|
+
* uses the saved session or fails. */
|
|
4458
|
+
promptlessSdks = /* @__PURE__ */ new WeakSet();
|
|
4311
4459
|
connectionGeneration = 0;
|
|
4312
4460
|
sdkHasConnected = false;
|
|
4313
4461
|
rpcUrls;
|
|
@@ -4488,6 +4636,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4488
4636
|
return;
|
|
4489
4637
|
}
|
|
4490
4638
|
}
|
|
4639
|
+
if (this.promptlessSdks.has(sdk)) throw this.signInRequired();
|
|
4491
4640
|
await original();
|
|
4492
4641
|
const newAddress = internals.walletClient?.account?.address;
|
|
4493
4642
|
const newChainId = internals.currentChainId ?? 0;
|
|
@@ -4533,18 +4682,35 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4533
4682
|
if (this.connectedAddress?.toLowerCase() === owner && this.connectedChainId === chainId) return false;
|
|
4534
4683
|
return readSession(state.walletAddress, chainId) === null;
|
|
4535
4684
|
}
|
|
4536
|
-
/**
|
|
4685
|
+
/** A read (promptless state) needs a sign-in it may not ask for. */
|
|
4686
|
+
signInRequired() {
|
|
4687
|
+
return new OwneyError(
|
|
4688
|
+
"AGENT_AUTH_FAILED",
|
|
4689
|
+
ZYFAI_SIGN_IN_REQUIRED_MESSAGE,
|
|
4690
|
+
{ reason: "ZYFAI_SIGN_IN_REQUIRED" },
|
|
4691
|
+
this.id
|
|
4692
|
+
);
|
|
4693
|
+
}
|
|
4694
|
+
/**
|
|
4695
|
+
* Light connect: SIWE auth only. Re-auths if chain changed. Under a
|
|
4696
|
+
* promptless state (a read) it connects with the saved session only and
|
|
4697
|
+
* never opens the wallet's sign-in prompt: with no saved session it fails
|
|
4698
|
+
* at once with `ZYFAI_SIGN_IN_REQUIRED`.
|
|
4699
|
+
*/
|
|
4537
4700
|
async connectAuth(state, chainId) {
|
|
4538
4701
|
const validChainId = isValidChainId(chainId);
|
|
4539
4702
|
const owner = state.walletAddress.toLowerCase();
|
|
4540
4703
|
const scope = `${owner}:${validChainId}`;
|
|
4704
|
+
const promptless = state.promptless === true;
|
|
4541
4705
|
if (this.connectedAddress?.toLowerCase() === owner && this.connectedChainId === validChainId) {
|
|
4542
4706
|
return;
|
|
4543
4707
|
}
|
|
4544
4708
|
if (this.connectAuthPromise && this.connectAuthScope === scope) {
|
|
4545
|
-
await this.connectAuthPromise;
|
|
4709
|
+
if (this.connectAuthPromptless && !promptless) await this.connectAuthPromise.catch(() => void 0);
|
|
4710
|
+
else await this.connectAuthPromise;
|
|
4546
4711
|
return this.connectAuth(state, chainId);
|
|
4547
4712
|
}
|
|
4713
|
+
if (promptless && readSession(state.walletAddress, validChainId) === null) throw this.signInRequired();
|
|
4548
4714
|
if (this.sdkHasConnected || this.connectedAddress) this.sdk = this.createSdk();
|
|
4549
4715
|
this.sdkHasConnected = true;
|
|
4550
4716
|
const executionSdk = this.sdk;
|
|
@@ -4557,7 +4723,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4557
4723
|
const address = await this.connectAccountWithRetry(
|
|
4558
4724
|
state.provider,
|
|
4559
4725
|
validChainId,
|
|
4560
|
-
executionSdk
|
|
4726
|
+
executionSdk,
|
|
4727
|
+
promptless
|
|
4561
4728
|
);
|
|
4562
4729
|
if (generation !== this.connectionGeneration || address.toLowerCase() !== owner)
|
|
4563
4730
|
throw new OwneyError("NOT_CONNECTED", "Wallet changed while connecting Zyfai.", void 0, this.id);
|
|
@@ -4566,12 +4733,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4566
4733
|
})();
|
|
4567
4734
|
this.connectAuthPromise = pending;
|
|
4568
4735
|
this.connectAuthScope = scope;
|
|
4736
|
+
this.connectAuthPromptless = promptless;
|
|
4569
4737
|
try {
|
|
4570
4738
|
await pending;
|
|
4571
4739
|
} finally {
|
|
4572
4740
|
if (this.connectAuthPromise === pending) {
|
|
4573
4741
|
this.connectAuthPromise = null;
|
|
4574
4742
|
this.connectAuthScope = null;
|
|
4743
|
+
this.connectAuthPromptless = false;
|
|
4575
4744
|
}
|
|
4576
4745
|
}
|
|
4577
4746
|
}
|
|
@@ -4584,19 +4753,86 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4584
4753
|
* which does not separate a revoked JWT from a misconfigured API key; we
|
|
4585
4754
|
* retry once either way, and if the second attempt still fails the original
|
|
4586
4755
|
* error propagates.
|
|
4756
|
+
*
|
|
4757
|
+
* `promptless` (a read): the saved session only. The patched
|
|
4758
|
+
* `authenticateUser` will not fall back to the SIWE prompt for this client,
|
|
4759
|
+
* and a refused session is dropped without a retry
|
|
4760
|
+
* (`dropRefusedReadSession`); the next sign-in is the user's.
|
|
4587
4761
|
*/
|
|
4588
|
-
async connectAccountWithRetry(provider, chainId, executionSdk = this.sdk) {
|
|
4762
|
+
async connectAccountWithRetry(provider, chainId, executionSdk = this.sdk, promptless = false) {
|
|
4763
|
+
if (promptless) this.promptlessSdks.add(executionSdk);
|
|
4589
4764
|
try {
|
|
4590
|
-
|
|
4765
|
+
const address = await executionSdk.connectAccount(provider, chainId);
|
|
4766
|
+
this.promptlessSdks.delete(executionSdk);
|
|
4767
|
+
return address;
|
|
4591
4768
|
} catch (error) {
|
|
4592
4769
|
const message = error instanceof Error ? error.message : String(error);
|
|
4593
4770
|
if (!message.toLowerCase().includes("unauthorized")) throw error;
|
|
4594
4771
|
const internals = executionSdk;
|
|
4595
4772
|
const address = internals.walletClient?.account?.address;
|
|
4773
|
+
if (promptless) throw this.dropRefusedReadSession(address, executionSdk, internals.httpClient.authToken, message);
|
|
4596
4774
|
if (address) clearSession(address, chainId);
|
|
4597
4775
|
return await executionSdk.connectAccount(provider, chainId);
|
|
4598
4776
|
}
|
|
4599
4777
|
}
|
|
4778
|
+
setSignInRefusedListener(listener) {
|
|
4779
|
+
this.signInRefusedListener = listener;
|
|
4780
|
+
}
|
|
4781
|
+
/** A saved session was dropped because Zyfai refused it (not during connect). */
|
|
4782
|
+
tellSignInRefused() {
|
|
4783
|
+
try {
|
|
4784
|
+
this.signInRefusedListener?.();
|
|
4785
|
+
} catch {
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4788
|
+
/**
|
|
4789
|
+
* Zyfai refused the session a read used (HTTP 401): the one place a read
|
|
4790
|
+
* drops a refused session. The saved session is cleared unless it was
|
|
4791
|
+
* renewed meanwhile, and the client stops using its token and may no longer
|
|
4792
|
+
* sign in, so no read reuses the session or signs in again: reads now need
|
|
4793
|
+
* a sign-in (`ensureReadSession` sees no live session), and the next one is
|
|
4794
|
+
* the user's (connect, deposit, withdraw), on a new client. Returns the
|
|
4795
|
+
* read's error.
|
|
4796
|
+
*/
|
|
4797
|
+
dropRefusedReadSession(owner, executionSdk, authToken, refusal) {
|
|
4798
|
+
debugLog("zyfai:auth", "a read's session was refused; dropped without signing in again", { refusal });
|
|
4799
|
+
if (owner && typeof authToken === "string") {
|
|
4800
|
+
let dropped = false;
|
|
4801
|
+
if (readSession(owner, 0)?.token === authToken) {
|
|
4802
|
+
clearSession(owner, 0);
|
|
4803
|
+
dropped = true;
|
|
4804
|
+
}
|
|
4805
|
+
const internals = executionSdk;
|
|
4806
|
+
if (internals.httpClient.authToken === authToken) {
|
|
4807
|
+
dropped = true;
|
|
4808
|
+
internals.httpClient.clearAuthToken();
|
|
4809
|
+
internals.authenticatedUserId = null;
|
|
4810
|
+
this.promptlessSdks.add(executionSdk);
|
|
4811
|
+
if (executionSdk === this.sdk && this.connectedAddress?.toLowerCase() === owner.toLowerCase())
|
|
4812
|
+
this.connectedChainId = null;
|
|
4813
|
+
}
|
|
4814
|
+
if (dropped) this.tellSignInRefused();
|
|
4815
|
+
}
|
|
4816
|
+
return this.signInRequired();
|
|
4817
|
+
}
|
|
4818
|
+
/**
|
|
4819
|
+
* One data call of a read, on `executionSdk`. Under a promptless state a
|
|
4820
|
+
* session Zyfai refuses (`isZyfaiSessionRejected`) is dropped
|
|
4821
|
+
* (`dropRefusedReadSession`) and the read fails with
|
|
4822
|
+
* `ZYFAI_SIGN_IN_REQUIRED`, never signing in again.
|
|
4823
|
+
*/
|
|
4824
|
+
async readCall(state, call, executionSdk = this.sdk) {
|
|
4825
|
+
const authToken = executionSdk.httpClient?.authToken;
|
|
4826
|
+
try {
|
|
4827
|
+
return await call();
|
|
4828
|
+
} catch (error) {
|
|
4829
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4830
|
+
if (state.promptless !== true || error instanceof OwneyError) throw error;
|
|
4831
|
+
if (message.includes(ZYFAI_SIGN_IN_REQUIRED_MESSAGE)) throw this.signInRequired();
|
|
4832
|
+
if (!isZyfaiSessionRejected(message)) throw error;
|
|
4833
|
+
throw this.dropRefusedReadSession(state.walletAddress, executionSdk, authToken, message);
|
|
4834
|
+
}
|
|
4835
|
+
}
|
|
4600
4836
|
/**
|
|
4601
4837
|
* Reconnect if the Zyfai connection was torn down behind our back: a
|
|
4602
4838
|
* chain/account switch fires the provider's `accountsChanged` →
|
|
@@ -4634,6 +4870,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4634
4870
|
internals.httpClient.clearAuthToken();
|
|
4635
4871
|
internals.authenticatedUserId = null;
|
|
4636
4872
|
this.connectedChainId = null;
|
|
4873
|
+
this.tellSignInRefused();
|
|
4637
4874
|
}
|
|
4638
4875
|
/**
|
|
4639
4876
|
* Sync newly-available protocols onto an existing user's profile at wallet
|
|
@@ -4665,7 +4902,16 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4665
4902
|
);
|
|
4666
4903
|
return;
|
|
4667
4904
|
}
|
|
4668
|
-
const
|
|
4905
|
+
const decided = protocolsSyncLeavesOff(
|
|
4906
|
+
current.customization,
|
|
4907
|
+
available,
|
|
4908
|
+
current.chains ?? []
|
|
4909
|
+
);
|
|
4910
|
+
const update = buildProtocolMergeUpdate(
|
|
4911
|
+
available.filter((protocol) => !decided.has(protocol.id)),
|
|
4912
|
+
current,
|
|
4913
|
+
asset
|
|
4914
|
+
);
|
|
4669
4915
|
if (!update) return;
|
|
4670
4916
|
await this.sdk.updateUserProfile(update);
|
|
4671
4917
|
debugLog("zyfai:protocol-sync", `${asset}: wrote profile update`, update);
|
|
@@ -4685,11 +4931,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4685
4931
|
* per chain, in parallel) cancel each other's sign-in. Funding keeps
|
|
4686
4932
|
* `connectAuth`/`ensureConnected`. Returns the owner verified for this call,
|
|
4687
4933
|
* so a later reconnect cannot leave the caller without an address.
|
|
4934
|
+
* The client reads under a promptless state, so with no live session this
|
|
4935
|
+
* connects from the saved one or fails without a prompt (`connectAuth`).
|
|
4688
4936
|
*/
|
|
4689
4937
|
async ensureReadSession(state, chainId) {
|
|
4690
4938
|
const owner = state.walletAddress?.toLowerCase();
|
|
4691
4939
|
if (this.connectAuthPromise) await this.connectAuthPromise.catch(() => void 0);
|
|
4692
|
-
if (!owner || this.connectedAddress?.toLowerCase() !== owner
|
|
4940
|
+
if (!owner || this.connectedAddress?.toLowerCase() !== owner || this.connectedChainId === null)
|
|
4941
|
+
await this.connectAuth(state, chainId);
|
|
4693
4942
|
}
|
|
4694
4943
|
/** `ensureReadSession`, then the owner it verified, read in the same turn. */
|
|
4695
4944
|
async connectForRead(state, chainId) {
|
|
@@ -4723,7 +4972,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4723
4972
|
return pending;
|
|
4724
4973
|
}
|
|
4725
4974
|
// --- IAgent: Connection lifecycle ---
|
|
4726
|
-
async disconnect() {
|
|
4975
|
+
async disconnect(options) {
|
|
4727
4976
|
const executionSdk = this.sdk;
|
|
4728
4977
|
this.connectionGeneration++;
|
|
4729
4978
|
this.earningsGeneration++;
|
|
@@ -4736,7 +4985,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
4736
4985
|
this.holdActiveScopes.clear();
|
|
4737
4986
|
this.pendingRegistrations.clear();
|
|
4738
4987
|
this.lastGoodEarnings.clear();
|
|
4739
|
-
if (this.connectedAddress && this.connectedChainId !== null) {
|
|
4988
|
+
if (!options?.keepSignIns && this.connectedAddress && this.connectedChainId !== null) {
|
|
4740
4989
|
clearSession(this.connectedAddress, this.connectedChainId);
|
|
4741
4990
|
}
|
|
4742
4991
|
this.connectedAddress = null;
|
|
@@ -5004,14 +5253,23 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5004
5253
|
group.push(entry);
|
|
5005
5254
|
byPair.set(pair, group);
|
|
5006
5255
|
}
|
|
5256
|
+
const catalogReads = /* @__PURE__ */ new Map();
|
|
5257
|
+
const catalogOf = (protocolId) => {
|
|
5258
|
+
let read2 = catalogReads.get(protocolId);
|
|
5259
|
+
if (!read2) {
|
|
5260
|
+
read2 = this.sdk.getAvailablePools(protocolId, "yieldmaxxing").then(mapAvailablePools);
|
|
5261
|
+
catalogReads.set(protocolId, read2);
|
|
5262
|
+
}
|
|
5263
|
+
return read2;
|
|
5264
|
+
};
|
|
5007
5265
|
const customizations = await Promise.all(
|
|
5008
5266
|
[...byPair.values()].map(async (scoped) => {
|
|
5009
5267
|
const { protocolId, chainId } = scoped[0];
|
|
5010
|
-
const [current,
|
|
5268
|
+
const [current, catalog] = await Promise.all([
|
|
5011
5269
|
this.sdk.getSelectedPools(protocolId, chainId),
|
|
5012
|
-
|
|
5270
|
+
catalogOf(protocolId)
|
|
5013
5271
|
]);
|
|
5014
|
-
const allAvailableNames =
|
|
5272
|
+
const allAvailableNames = catalog.filter((pool) => pool.chainId === chainId).map((pool) => pool.name);
|
|
5015
5273
|
return {
|
|
5016
5274
|
protocolId,
|
|
5017
5275
|
chainId,
|
|
@@ -5035,13 +5293,25 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5035
5293
|
await Promise.all(
|
|
5036
5294
|
selection.strategies.map(async ({ asset, strategy }) => {
|
|
5037
5295
|
const current = await this.sdk.getUserDetails(asset);
|
|
5038
|
-
const
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5296
|
+
const listed = current.protocols ?? [];
|
|
5297
|
+
const unpicked = listed.filter((protocolId) => !selection.selections.some(
|
|
5298
|
+
(entry) => entry.asset === asset && entry.protocolId === protocolId && entry.pools.length > 0
|
|
5299
|
+
));
|
|
5300
|
+
const catalogs = new Map(await Promise.all(unpicked.map(async (protocolId) => [protocolId, await catalogOf(protocolId).catch(() => null)])));
|
|
5301
|
+
const protocols = protocolsToKeep({
|
|
5302
|
+
asset,
|
|
5303
|
+
current: listed,
|
|
5304
|
+
chains: current.chains ?? [],
|
|
5305
|
+
selections: selection.selections,
|
|
5306
|
+
customization: current.customization,
|
|
5307
|
+
catalogs
|
|
5308
|
+
});
|
|
5309
|
+
await this.sdk.updateUserProfile({
|
|
5310
|
+
asset,
|
|
5311
|
+
strategy,
|
|
5312
|
+
protocols,
|
|
5313
|
+
autoSelectProtocols: false
|
|
5314
|
+
});
|
|
5045
5315
|
})
|
|
5046
5316
|
);
|
|
5047
5317
|
} catch (error) {
|
|
@@ -5114,13 +5384,14 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5114
5384
|
Promise.all(
|
|
5115
5385
|
params.pairs.map(async ({ protocolId, chainId: chainId2 }) => {
|
|
5116
5386
|
try {
|
|
5117
|
-
const current = await this.sdk.getSelectedPools(
|
|
5387
|
+
const current = await this.readCall(state, () => this.sdk.getSelectedPools(
|
|
5118
5388
|
protocolId,
|
|
5119
5389
|
chainId2
|
|
5120
|
-
);
|
|
5390
|
+
));
|
|
5121
5391
|
if (current.autoselect) return null;
|
|
5122
5392
|
return { protocolId, chainId: chainId2, pools: current.pools ?? [] };
|
|
5123
|
-
} catch {
|
|
5393
|
+
} catch (error) {
|
|
5394
|
+
if (isSignInFailure(error)) throw error;
|
|
5124
5395
|
return null;
|
|
5125
5396
|
}
|
|
5126
5397
|
})
|
|
@@ -5128,9 +5399,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
5128
5399
|
Promise.all(
|
|
5129
5400
|
params.assets.map(async (asset) => {
|
|
5130
5401
|
try {
|
|
5131
|
-
const current = await this.sdk.getUserDetails(asset);
|
|
5402
|
+
const current = await this.readCall(state, () => this.sdk.getUserDetails(asset));
|
|
5132
5403
|
return current.strategy ? { asset, strategy: current.strategy } : null;
|
|
5133
|
-
} catch {
|
|
5404
|
+
} catch (error) {
|
|
5405
|
+
if (isSignInFailure(error)) throw error;
|
|
5134
5406
|
return null;
|
|
5135
5407
|
}
|
|
5136
5408
|
})
|
|
@@ -6523,7 +6795,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6523
6795
|
const requestedAt = Date.now();
|
|
6524
6796
|
const generation = this.earningsGeneration;
|
|
6525
6797
|
const { smartWallet, chainId: validChainId } = await this.resolveSmartWallet(state, chainId);
|
|
6526
|
-
const raw2 = await this.sdk.getPortfolio(this.getAddress());
|
|
6798
|
+
const raw2 = await this.readCall(state, () => this.sdk.getPortfolio(this.getAddress()));
|
|
6527
6799
|
debugLog("zyfai:balances", "read", { ms: Date.now() - requestedAt });
|
|
6528
6800
|
const balance = mapBalances(raw2, validChainId, smartWallet);
|
|
6529
6801
|
const reads = balance.readMetadata?.map((read2) => ({ ...read2, requestedAt })) ?? [];
|
|
@@ -6585,7 +6857,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6585
6857
|
async getEarnings(state, chainId) {
|
|
6586
6858
|
const { smartWallet } = await this.resolveSmartWallet(state, chainId);
|
|
6587
6859
|
const key2 = this.earningsKey(state, chainId, smartWallet);
|
|
6588
|
-
const raw2 = await this.readEarnings(key2, smartWallet);
|
|
6860
|
+
const raw2 = await this.readCall(state, () => this.readEarnings(key2, smartWallet));
|
|
6589
6861
|
const held = await this.holdEarnings(state, chainId, smartWallet, key2, raw2);
|
|
6590
6862
|
if (held.active) void this.refreshEarnings(state, chainId).catch(() => void 0);
|
|
6591
6863
|
return mapEarnings(held.value, smartWallet);
|
|
@@ -6736,7 +7008,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6736
7008
|
if (existing) return existing;
|
|
6737
7009
|
const pending = (async () => {
|
|
6738
7010
|
const recent = this.earningsSnapshot;
|
|
6739
|
-
const current = recent?.key === key2 && Date.now() - recent.at < 5e3 ? recent.raw : await this.readEarnings(key2, smartWallet);
|
|
7011
|
+
const current = recent?.key === key2 && Date.now() - recent.at < 5e3 ? recent.raw : await this.readCall(state, () => this.readEarnings(key2, smartWallet), executionSdk);
|
|
6740
7012
|
const lastCheck = current.data.lastCheckTimestamp ? Date.parse(current.data.lastCheckTimestamp) : Number.NaN;
|
|
6741
7013
|
const mapped = mapEarnings(current, smartWallet);
|
|
6742
7014
|
const held = await this.holdEarnings(state, chainId, smartWallet, key2, current);
|
|
@@ -6750,7 +7022,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6750
7022
|
if (isFresh && !negative || !canCalculate)
|
|
6751
7023
|
return held.active ? mapEarnings(held.value, smartWallet) : mapped;
|
|
6752
7024
|
this.earningsCalculationAttempts.set(calculationKey, now);
|
|
6753
|
-
const earnings = await executionSdk.calculateOnchainEarnings(smartWallet);
|
|
7025
|
+
const earnings = await this.readCall(state, () => executionSdk.calculateOnchainEarnings(smartWallet), executionSdk);
|
|
6754
7026
|
assertCurrent();
|
|
6755
7027
|
this.earningsSnapshot = { key: key2, raw: earnings, at: Date.now() };
|
|
6756
7028
|
const recalculated = await this.holdEarnings(state, chainId, smartWallet, key2, earnings);
|
|
@@ -6765,7 +7037,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6765
7037
|
}
|
|
6766
7038
|
async getAccountApy(state, chainId, days, tokenSymbol, scopeChainId) {
|
|
6767
7039
|
const { smartWallet } = await this.resolveSmartWallet(state, chainId);
|
|
6768
|
-
const raw2 = await this.sdk.getDailyApyHistory(smartWallet, days);
|
|
7040
|
+
const raw2 = await this.readCall(state, () => this.sdk.getDailyApyHistory(smartWallet, days));
|
|
6769
7041
|
const scope = scopeChainId === null ? void 0 : scopeChainId ?? chainId;
|
|
6770
7042
|
const ethUsd = tokenSymbol === void 0 && holdsEthPosition(raw2) ? await readEthUsdPrice(this.getPublicClient(8453)) : void 0;
|
|
6771
7043
|
return mapApyHistory(raw2, scope, tokenSymbol, ethUsd);
|
|
@@ -6775,10 +7047,10 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6775
7047
|
const start = new Date(
|
|
6776
7048
|
Date.now() - (DayFilterMapping[days] + 1) * 864e5
|
|
6777
7049
|
);
|
|
6778
|
-
const raw2 = await this.sdk.getDailyEarnings(
|
|
7050
|
+
const raw2 = await this.readCall(state, () => this.sdk.getDailyEarnings(
|
|
6779
7051
|
smartWallet,
|
|
6780
7052
|
start.toISOString().slice(0, 10)
|
|
6781
|
-
);
|
|
7053
|
+
));
|
|
6782
7054
|
return mapDailyEarnings(raw2, chainId, tokenSymbol);
|
|
6783
7055
|
}
|
|
6784
7056
|
/**
|
|
@@ -6822,7 +7094,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6822
7094
|
const matched = [];
|
|
6823
7095
|
let backendExhausted = false;
|
|
6824
7096
|
for (let i = 0; i < MAX_BACKEND_CALLS && matched.length < limit; i++) {
|
|
6825
|
-
const raw2 = await this.sdk.getHistory(smartWallet, validChainId, {
|
|
7097
|
+
const raw2 = await this.readCall(state, () => this.sdk.getHistory(smartWallet, validChainId, {
|
|
6826
7098
|
limit: backendPageSize,
|
|
6827
7099
|
offset,
|
|
6828
7100
|
fromDate: options?.fromDate,
|
|
@@ -6832,7 +7104,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6832
7104
|
// relevant entries instead of spending its budget on the other
|
|
6833
7105
|
// asset's rows and handing back a page that filters to nothing.
|
|
6834
7106
|
assetType
|
|
6835
|
-
});
|
|
7107
|
+
}));
|
|
6836
7108
|
raw2.data.forEach((entry, idx) => {
|
|
6837
7109
|
if (entry.chainId === validChainId) {
|
|
6838
7110
|
matched.push({ entry, rawIdx: offset + idx });
|
|
@@ -6868,7 +7140,7 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6868
7140
|
}
|
|
6869
7141
|
async getUserProfile(state, chainId) {
|
|
6870
7142
|
await this.ensureReadSession(state, chainId);
|
|
6871
|
-
const raw2 = await this.sdk.getUserDetails();
|
|
7143
|
+
const raw2 = await this.readCall(state, () => this.sdk.getUserDetails());
|
|
6872
7144
|
debugLog("zyfai:profile", "getUserProfile \u2014 Zyfai reports", {
|
|
6873
7145
|
asset: "USDC (default \u2014 no asset passed)",
|
|
6874
7146
|
splitting: raw2.splitting,
|
|
@@ -6900,7 +7172,8 @@ var ZyfaiAgent = class _ZyfaiAgent {
|
|
|
6900
7172
|
const update = buildAutoSelectUpdate(
|
|
6901
7173
|
{
|
|
6902
7174
|
autoSelectProtocols: current.autoSelectProtocols,
|
|
6903
|
-
chains: current.chains
|
|
7175
|
+
chains: current.chains,
|
|
7176
|
+
savedPoolChoices: hasManualPoolChoices(current.customization)
|
|
6904
7177
|
},
|
|
6905
7178
|
asset,
|
|
6906
7179
|
isValidChainId(chainId)
|
|
@@ -6977,7 +7250,7 @@ var INVALIDATED_KEY_PREFIXES = [
|
|
|
6977
7250
|
"owney.yieldseeker.session.v3",
|
|
6978
7251
|
"owney.yieldseeker.session.v4"
|
|
6979
7252
|
];
|
|
6980
|
-
var
|
|
7253
|
+
var storage4 = () => {
|
|
6981
7254
|
if (typeof window === "undefined") return null;
|
|
6982
7255
|
try {
|
|
6983
7256
|
return window.localStorage;
|
|
@@ -7011,7 +7284,7 @@ var isValidSession = (session) => {
|
|
|
7011
7284
|
var readYieldseekerSession = (address, chainId) => {
|
|
7012
7285
|
if (typeof window === "undefined") return null;
|
|
7013
7286
|
const key2 = buildKey2(address, chainId);
|
|
7014
|
-
const store =
|
|
7287
|
+
const store = storage4();
|
|
7015
7288
|
clearInvalidatedSessions(store, address, chainId);
|
|
7016
7289
|
let raw2 = null;
|
|
7017
7290
|
try {
|
|
@@ -7043,7 +7316,7 @@ var writeYieldseekerSession = (address, chainId, token) => {
|
|
|
7043
7316
|
if (!isValidSession(session)) return;
|
|
7044
7317
|
const key2 = buildKey2(address, chainId);
|
|
7045
7318
|
memorySessions2.set(key2, session);
|
|
7046
|
-
const store =
|
|
7319
|
+
const store = storage4();
|
|
7047
7320
|
try {
|
|
7048
7321
|
store?.setItem(key2, JSON.stringify(session));
|
|
7049
7322
|
} catch {
|
|
@@ -7052,7 +7325,7 @@ var writeYieldseekerSession = (address, chainId, token) => {
|
|
|
7052
7325
|
var clearYieldseekerSession = (address, chainId) => {
|
|
7053
7326
|
const key2 = buildKey2(address, chainId);
|
|
7054
7327
|
memorySessions2.delete(key2);
|
|
7055
|
-
const store =
|
|
7328
|
+
const store = storage4();
|
|
7056
7329
|
clearInvalidatedSessions(store, address, chainId);
|
|
7057
7330
|
try {
|
|
7058
7331
|
store?.removeItem(key2);
|
|
@@ -7164,12 +7437,21 @@ var YieldseekerAuth = class {
|
|
|
7164
7437
|
return this.getToken(state, chainId);
|
|
7165
7438
|
}
|
|
7166
7439
|
/** Drop a proof the provider refused, without signing a new one: a
|
|
7167
|
-
* promptless read cannot renew it, and must stop offering it.
|
|
7440
|
+
* promptless read cannot renew it, and must stop offering it. Returns
|
|
7441
|
+
* whether it dropped anything: false when the proof was already dropped or
|
|
7442
|
+
* replaced meanwhile. */
|
|
7168
7443
|
discardToken(state, chainId, rejectedToken) {
|
|
7169
7444
|
const key2 = this.key(state, chainId);
|
|
7170
|
-
|
|
7171
|
-
if (
|
|
7445
|
+
let dropped = false;
|
|
7446
|
+
if (this.tokens.get(key2) === rejectedToken) {
|
|
7447
|
+
this.tokens.delete(key2);
|
|
7448
|
+
dropped = true;
|
|
7449
|
+
}
|
|
7450
|
+
if (readYieldseekerSession(state.walletAddress, chainId) === rejectedToken) {
|
|
7172
7451
|
clearYieldseekerSession(state.walletAddress, chainId);
|
|
7452
|
+
dropped = true;
|
|
7453
|
+
}
|
|
7454
|
+
return dropped;
|
|
7173
7455
|
}
|
|
7174
7456
|
isReusable(token, state, chainId) {
|
|
7175
7457
|
try {
|
|
@@ -7185,6 +7467,12 @@ var YieldseekerAuth = class {
|
|
|
7185
7467
|
return false;
|
|
7186
7468
|
}
|
|
7187
7469
|
}
|
|
7470
|
+
/** Drops what this instance holds in memory; saved sign-ins in storage stay. */
|
|
7471
|
+
forgetInMemory() {
|
|
7472
|
+
this.tokens.clear();
|
|
7473
|
+
this.pending.clear();
|
|
7474
|
+
this.scopes.clear();
|
|
7475
|
+
}
|
|
7188
7476
|
clear(state, chainId) {
|
|
7189
7477
|
if (!state || chainId === void 0) {
|
|
7190
7478
|
for (const scope of this.scopes.values()) {
|
|
@@ -7229,9 +7517,9 @@ var YieldseekerAuth = class {
|
|
|
7229
7517
|
|
|
7230
7518
|
// src/agents/yieldseeker/yieldseeker.identity-cache.ts
|
|
7231
7519
|
var KEY_PREFIX3 = "owney.yieldseeker.identity.v1";
|
|
7232
|
-
var YIELDSEEKER_IDENTITY_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
7520
|
+
var YIELDSEEKER_IDENTITY_TTL_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
7233
7521
|
var memoryIdentities = /* @__PURE__ */ new Map();
|
|
7234
|
-
var
|
|
7522
|
+
var storage5 = () => {
|
|
7235
7523
|
if (typeof window === "undefined") return null;
|
|
7236
7524
|
try {
|
|
7237
7525
|
return window.localStorage;
|
|
@@ -7248,7 +7536,7 @@ function valid(value, walletAddress, chainId, now) {
|
|
|
7248
7536
|
function readYieldseekerIdentity(walletAddress, chainId, now = Date.now()) {
|
|
7249
7537
|
if (typeof window === "undefined") return null;
|
|
7250
7538
|
const key2 = keyFor(walletAddress, chainId);
|
|
7251
|
-
const store =
|
|
7539
|
+
const store = storage5();
|
|
7252
7540
|
let parsed = null;
|
|
7253
7541
|
try {
|
|
7254
7542
|
const raw2 = store?.getItem(key2);
|
|
@@ -7280,7 +7568,7 @@ function writeYieldseekerIdentity(walletAddress, chainId, userId, now = Date.now
|
|
|
7280
7568
|
const key2 = keyFor(walletAddress, chainId);
|
|
7281
7569
|
memoryIdentities.set(key2, identity);
|
|
7282
7570
|
try {
|
|
7283
|
-
|
|
7571
|
+
storage5()?.setItem(key2, JSON.stringify(identity));
|
|
7284
7572
|
} catch {
|
|
7285
7573
|
}
|
|
7286
7574
|
}
|
|
@@ -7288,11 +7576,43 @@ function clearYieldseekerIdentity(walletAddress, chainId) {
|
|
|
7288
7576
|
const key2 = keyFor(walletAddress, chainId);
|
|
7289
7577
|
memoryIdentities.delete(key2);
|
|
7290
7578
|
try {
|
|
7291
|
-
|
|
7579
|
+
storage5()?.removeItem(key2);
|
|
7292
7580
|
} catch {
|
|
7293
7581
|
}
|
|
7294
7582
|
}
|
|
7295
7583
|
|
|
7584
|
+
// src/agents/yieldseeker/yieldseeker.login-cooldown.ts
|
|
7585
|
+
var KEY2 = "owney.yieldseeker.login-cooldown.v1";
|
|
7586
|
+
var YIELDSEEKER_LOGIN_COOLDOWN_FLOOR_MS = 3 * 6e4;
|
|
7587
|
+
var memoryUntil = 0;
|
|
7588
|
+
var storage6 = () => {
|
|
7589
|
+
if (typeof window === "undefined") return null;
|
|
7590
|
+
try {
|
|
7591
|
+
return window.localStorage;
|
|
7592
|
+
} catch {
|
|
7593
|
+
return null;
|
|
7594
|
+
}
|
|
7595
|
+
};
|
|
7596
|
+
function readYieldseekerLoginCooldown(now = Date.now()) {
|
|
7597
|
+
let until = memoryUntil;
|
|
7598
|
+
try {
|
|
7599
|
+
const stored = Number(storage6()?.getItem(KEY2));
|
|
7600
|
+
if (Number.isSafeInteger(stored) && stored > until) until = stored;
|
|
7601
|
+
} catch {
|
|
7602
|
+
}
|
|
7603
|
+
return until > now ? until : void 0;
|
|
7604
|
+
}
|
|
7605
|
+
function startYieldseekerLoginCooldown(retryAfterMs, now = Date.now()) {
|
|
7606
|
+
const wait3 = Math.max(YIELDSEEKER_LOGIN_COOLDOWN_FLOOR_MS, Number.isFinite(retryAfterMs) ? retryAfterMs : 0);
|
|
7607
|
+
const until = Math.max(readYieldseekerLoginCooldown(now) ?? 0, now + wait3);
|
|
7608
|
+
memoryUntil = until;
|
|
7609
|
+
try {
|
|
7610
|
+
storage6()?.setItem(KEY2, String(until));
|
|
7611
|
+
} catch {
|
|
7612
|
+
}
|
|
7613
|
+
return until;
|
|
7614
|
+
}
|
|
7615
|
+
|
|
7296
7616
|
// src/agents/yieldseeker/yieldseeker.client.ts
|
|
7297
7617
|
var DEFAULT_ROUTING_API_BASE_URL = "https://owney-routing-api-243946518160.europe-west4.run.app";
|
|
7298
7618
|
function getYieldseekerProxyBaseUrl(routingApiBaseUrl = DEFAULT_ROUTING_API_BASE_URL) {
|
|
@@ -8931,7 +9251,7 @@ var DEPOSIT_NOTICE_ATTEMPTS = 3;
|
|
|
8931
9251
|
var DEPOSIT_ALLOCATION_CHECK_MS = 6e4;
|
|
8932
9252
|
var DEPOSIT_NOTICE_RETRY_MS = 15e3;
|
|
8933
9253
|
var DEPOSIT_NOTICE_RETRY_MAX_MS = 6e4;
|
|
8934
|
-
var
|
|
9254
|
+
var WITHDRAWAL_UNDER_WAY_MAX_AGE_MS = 60 * 6e4;
|
|
8935
9255
|
var YIELDSEEKER_LIVE_IDLE_CACHE_MS = 15e3;
|
|
8936
9256
|
var YIELDSEEKER_LIVE_IDLE_BUDGET_MS = 3e3;
|
|
8937
9257
|
var YIELDSEEKER_SERVER_BASELINE_CACHE_MS = 10 * 6e4;
|
|
@@ -8953,6 +9273,12 @@ function generateYieldseekerUsername() {
|
|
|
8953
9273
|
const suffix = globalThis.crypto.randomUUID().replaceAll("-", "").slice(0, YIELDSEEKER_USERNAME_RANDOM_LENGTH).toLowerCase();
|
|
8954
9274
|
return `${YIELDSEEKER_USERNAME_PREFIX}${suffix}`;
|
|
8955
9275
|
}
|
|
9276
|
+
function isSignInRateLimit(error) {
|
|
9277
|
+
return error instanceof YieldseekerApiError && error.status === 429;
|
|
9278
|
+
}
|
|
9279
|
+
function isWalletAlreadyRegistered(error) {
|
|
9280
|
+
return error instanceof YieldseekerApiError && error.providerCode.toUpperCase() === "USER_WALLET_EXISTS";
|
|
9281
|
+
}
|
|
8956
9282
|
function isUsernameConflict(error) {
|
|
8957
9283
|
if (!(error instanceof YieldseekerApiError)) return false;
|
|
8958
9284
|
const code = error.providerCode.toUpperCase();
|
|
@@ -9100,6 +9426,15 @@ var YieldseekerAgent = class {
|
|
|
9100
9426
|
balanceContexts = /* @__PURE__ */ new WeakMap();
|
|
9101
9427
|
balanceVaults = /* @__PURE__ */ new Map();
|
|
9102
9428
|
users = /* @__PURE__ */ new Map();
|
|
9429
|
+
/**
|
|
9430
|
+
* Agent wallets (lowercase) this page started releasing vault funds from for
|
|
9431
|
+
* a withdrawal, and when. Until the payout is done the released money sits
|
|
9432
|
+
* in the agent wallet, so no deposit notice may go out (it would be
|
|
9433
|
+
* reinvested). The ledger shows the same once it lists the withdrawal.
|
|
9434
|
+
*/
|
|
9435
|
+
releasingWallets = /* @__PURE__ */ new Map();
|
|
9436
|
+
/** One login (and, for a new wallet, one create) per wallet and chain at a time. */
|
|
9437
|
+
pendingUsers = /* @__PURE__ */ new Map();
|
|
9103
9438
|
pendingAgents = /* @__PURE__ */ new Map();
|
|
9104
9439
|
pendingWalletContexts = /* @__PURE__ */ new Map();
|
|
9105
9440
|
readCache = /* @__PURE__ */ new Map();
|
|
@@ -9126,6 +9461,7 @@ var YieldseekerAgent = class {
|
|
|
9126
9461
|
// or while the ledger read is null, settlement and earnings are as before.
|
|
9127
9462
|
ledgerAccess;
|
|
9128
9463
|
accountRefusedListener;
|
|
9464
|
+
signInRefusedListener;
|
|
9129
9465
|
ledgerReads = /* @__PURE__ */ new Map();
|
|
9130
9466
|
/** contextKey -> movements this instance started settling (by tx hash) and how they refresh:
|
|
9131
9467
|
* awaiting the ledger, refreshed when ready (ledger), or on the timed backoff (legacy). */
|
|
@@ -9421,16 +9757,16 @@ var YieldseekerAgent = class {
|
|
|
9421
9757
|
this.rememberWalletStatus(versionKey, status);
|
|
9422
9758
|
return { txHash: hash2, status };
|
|
9423
9759
|
};
|
|
9424
|
-
let
|
|
9760
|
+
let storage11;
|
|
9425
9761
|
try {
|
|
9426
|
-
|
|
9762
|
+
storage11 = typeof window === "undefined" ? void 0 : window.localStorage;
|
|
9427
9763
|
} catch {
|
|
9428
|
-
|
|
9764
|
+
storage11 = void 0;
|
|
9429
9765
|
}
|
|
9430
9766
|
const clearRecordedUpgrade = () => {
|
|
9431
9767
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9432
9768
|
try {
|
|
9433
|
-
|
|
9769
|
+
storage11?.removeItem(pendingKey2);
|
|
9434
9770
|
} catch {
|
|
9435
9771
|
this.pendingUpgrades.set(pendingKey2, null);
|
|
9436
9772
|
}
|
|
@@ -9453,7 +9789,7 @@ var YieldseekerAgent = class {
|
|
|
9453
9789
|
throw pendingUpgrade(hash2);
|
|
9454
9790
|
}
|
|
9455
9791
|
};
|
|
9456
|
-
if (!
|
|
9792
|
+
if (!storage11 && (gasMode === "sponsored" || before.ownerPath === "smart"))
|
|
9457
9793
|
throw new OwneyError(
|
|
9458
9794
|
"SPONSOR_REQUEST_FAILED",
|
|
9459
9795
|
"Upgrade status cannot be saved in this browser.",
|
|
@@ -9462,14 +9798,14 @@ var YieldseekerAgent = class {
|
|
|
9462
9798
|
);
|
|
9463
9799
|
let prior = null;
|
|
9464
9800
|
try {
|
|
9465
|
-
const saved = this.pendingUpgrades.has(pendingKey2) ? JSON.stringify(this.pendingUpgrades.get(pendingKey2)) :
|
|
9801
|
+
const saved = this.pendingUpgrades.has(pendingKey2) ? JSON.stringify(this.pendingUpgrades.get(pendingKey2)) : storage11?.getItem(pendingKey2);
|
|
9466
9802
|
try {
|
|
9467
9803
|
prior = JSON.parse(saved ?? "null");
|
|
9468
9804
|
} catch {
|
|
9469
9805
|
prior = { callsId: void 0 };
|
|
9470
9806
|
}
|
|
9471
9807
|
} catch {
|
|
9472
|
-
if (gasMode === "paid" && before.ownerPath === "eoa")
|
|
9808
|
+
if (gasMode === "paid" && before.ownerPath === "eoa") storage11 = void 0;
|
|
9473
9809
|
else throw new OwneyError(
|
|
9474
9810
|
"SPONSOR_REQUEST_FAILED",
|
|
9475
9811
|
"Upgrade status cannot be read in this browser.",
|
|
@@ -9563,9 +9899,9 @@ var YieldseekerAgent = class {
|
|
|
9563
9899
|
asset: YIELDSEEKER_ASSET_METADATA[asset].address,
|
|
9564
9900
|
callData: data,
|
|
9565
9901
|
onPending: (pending) => {
|
|
9566
|
-
const current = this.pendingUpgrades.has(pendingKey2) ? this.pendingUpgrades.get(pendingKey2) : JSON.parse(
|
|
9902
|
+
const current = this.pendingUpgrades.has(pendingKey2) ? this.pendingUpgrades.get(pendingKey2) : JSON.parse(storage11.getItem(pendingKey2) ?? "null");
|
|
9567
9903
|
const next = { startedAt: Date.now(), ...current, ...pending };
|
|
9568
|
-
|
|
9904
|
+
storage11.setItem(pendingKey2, JSON.stringify(next));
|
|
9569
9905
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9570
9906
|
}
|
|
9571
9907
|
});
|
|
@@ -9589,8 +9925,8 @@ var YieldseekerAgent = class {
|
|
|
9589
9925
|
const pending = { txHash: hash2 };
|
|
9590
9926
|
this.pendingUpgrades.set(pendingKey2, pending);
|
|
9591
9927
|
try {
|
|
9592
|
-
if (
|
|
9593
|
-
|
|
9928
|
+
if (storage11) {
|
|
9929
|
+
storage11.setItem(pendingKey2, JSON.stringify(pending));
|
|
9594
9930
|
this.pendingUpgrades.delete(pendingKey2);
|
|
9595
9931
|
}
|
|
9596
9932
|
} catch {
|
|
@@ -9611,14 +9947,18 @@ var YieldseekerAgent = class {
|
|
|
9611
9947
|
clearRecordedUpgrade();
|
|
9612
9948
|
return confirmed;
|
|
9613
9949
|
}
|
|
9614
|
-
async disconnect() {
|
|
9950
|
+
async disconnect(options) {
|
|
9615
9951
|
this.withdrawalVersionCache.clear();
|
|
9616
9952
|
this.pendingWalletStatus.clear();
|
|
9617
9953
|
this.readGeneration += 1;
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9954
|
+
if (options?.keepSignIns) {
|
|
9955
|
+
this.auth.forgetInMemory();
|
|
9956
|
+
} else {
|
|
9957
|
+
this.auth.clear();
|
|
9958
|
+
for (const key2 of this.users.keys()) {
|
|
9959
|
+
const [walletAddress, chainId] = key2.split(":");
|
|
9960
|
+
clearYieldseekerIdentity(walletAddress, Number(chainId));
|
|
9961
|
+
}
|
|
9622
9962
|
}
|
|
9623
9963
|
this.users.clear();
|
|
9624
9964
|
this.agentContexts.clear();
|
|
@@ -9837,6 +10177,7 @@ var YieldseekerAgent = class {
|
|
|
9837
10177
|
}
|
|
9838
10178
|
async withdraw(state, chainId, asset, amount, onProgress, gasMode = "auto", onBeforeSubmission, assertOperation, submission) {
|
|
9839
10179
|
let ownerTransferAttempted = false;
|
|
10180
|
+
const startedAt = Date.now();
|
|
9840
10181
|
let evidence = {
|
|
9841
10182
|
agentId: this.id,
|
|
9842
10183
|
chainId,
|
|
@@ -9878,6 +10219,10 @@ var YieldseekerAgent = class {
|
|
|
9878
10219
|
delivery: "failed"
|
|
9879
10220
|
});
|
|
9880
10221
|
throw error;
|
|
10222
|
+
} finally {
|
|
10223
|
+
for (const [wallet, markedAt] of this.releasingWallets) {
|
|
10224
|
+
if (markedAt >= startedAt) this.releasingWallets.delete(wallet);
|
|
10225
|
+
}
|
|
9881
10226
|
}
|
|
9882
10227
|
}
|
|
9883
10228
|
async withdrawInternal(state, chainId, asset, amount, onProgress, onOwnerTransferAttempted, gasMode = "auto", onBeforeSubmission, assertOperation, operationId) {
|
|
@@ -10212,6 +10557,7 @@ var YieldseekerAgent = class {
|
|
|
10212
10557
|
const unwind = async (position2, assetsRaw) => {
|
|
10213
10558
|
this.assertSession(generation, chainId, asset);
|
|
10214
10559
|
assertOperation?.();
|
|
10560
|
+
this.releasingWallets.set(context.wallet.walletAddress.toLowerCase(), Date.now());
|
|
10215
10561
|
let unwindTransactionHash;
|
|
10216
10562
|
try {
|
|
10217
10563
|
const response = await this.walletRequest(
|
|
@@ -11007,7 +11353,9 @@ var YieldseekerAgent = class {
|
|
|
11007
11353
|
* left idle. While it has not, Yieldseeker is told again, up to
|
|
11008
11354
|
* DEPOSIT_NOTICE_ATTEMPTS calls in all; a failed call (network, server, rate
|
|
11009
11355
|
* limit) is sent again after a wait. Within an hour of a withdrawal it is
|
|
11010
|
-
* told once, since nothing can move yet.
|
|
11356
|
+
* told once, since nothing can move yet. While a withdrawal from the agent
|
|
11357
|
+
* wallet is under way it is not told at all: its released funds wait in that
|
|
11358
|
+
* wallet for the payout, and a notice would reinvest them (ROUT-790). Uses the agent this session already
|
|
11011
11359
|
* knows for the asset and the saved sign-in only: never prompts, never
|
|
11012
11360
|
* throws. Each call is reported through `onNotice`.
|
|
11013
11361
|
*/
|
|
@@ -11024,7 +11372,8 @@ var YieldseekerAgent = class {
|
|
|
11024
11372
|
if (!this.auth.peekToken(state, chainId)) return { notified: false, reason: "NO_SESSION" };
|
|
11025
11373
|
const generation = this.readGeneration;
|
|
11026
11374
|
const amount = parseRawAmount(evidence.confirmedAmount ?? evidence.intendedAmount);
|
|
11027
|
-
|
|
11375
|
+
if (await this.withdrawalUnderWay(state, chainId, slotAsset, context))
|
|
11376
|
+
return { notified: false, reason: "WITHDRAWAL_IN_PROGRESS" };
|
|
11028
11377
|
let notified = false;
|
|
11029
11378
|
let reason = "NOT_ALLOCATED";
|
|
11030
11379
|
while (attempts < DEPOSIT_NOTICE_ATTEMPTS) {
|
|
@@ -11045,14 +11394,6 @@ var YieldseekerAgent = class {
|
|
|
11045
11394
|
if (this.readGeneration !== generation) return { notified: true, attempts, reason: "SESSION_ENDED" };
|
|
11046
11395
|
const idle = await this.readIdleBalance(chainId, slotAsset, context.wallet.walletAddress);
|
|
11047
11396
|
if (idle !== null && idle < amount) return { notified: true, attempts, allocated: true };
|
|
11048
|
-
if (cooldownEnds !== null)
|
|
11049
|
-
return {
|
|
11050
|
-
notified: true,
|
|
11051
|
-
attempts,
|
|
11052
|
-
allocated: false,
|
|
11053
|
-
reason: "RECENT_WITHDRAWAL",
|
|
11054
|
-
allocatesAfter: new Date(cooldownEnds).toISOString()
|
|
11055
|
-
};
|
|
11056
11397
|
reason = idle === null ? "UNVERIFIED" : "NOT_ALLOCATED";
|
|
11057
11398
|
}
|
|
11058
11399
|
return { notified: true, attempts, allocated: false, reason };
|
|
@@ -11110,24 +11451,17 @@ var YieldseekerAgent = class {
|
|
|
11110
11451
|
}
|
|
11111
11452
|
}
|
|
11112
11453
|
/**
|
|
11113
|
-
*
|
|
11114
|
-
*
|
|
11115
|
-
* the
|
|
11454
|
+
* A withdrawal from this agent wallet that has started but not finished,
|
|
11455
|
+
* within the last hour: released by this page, or listed on the ledger with
|
|
11456
|
+
* the agent's leg still created, submitted or unknown. Older unfinished rows
|
|
11457
|
+
* do not count, so a stuck record cannot hold deposits back for good.
|
|
11116
11458
|
*/
|
|
11117
|
-
async
|
|
11118
|
-
const rows = await withinBudget(this.readLedger(state, chainId, asset), this.ledgerBudgetMs, null);
|
|
11459
|
+
async withdrawalUnderWay(state, chainId, asset, context) {
|
|
11119
11460
|
const wallet = context.wallet.walletAddress.toLowerCase();
|
|
11120
|
-
|
|
11121
|
-
|
|
11122
|
-
|
|
11123
|
-
|
|
11124
|
-
if (leg.legKey !== `agent:${this.id}` || leg.status !== "confirmed" || leg.agentWallet?.toLowerCase() !== wallet) continue;
|
|
11125
|
-
const at = Date.parse(leg.confirmedAt ?? row.settledAt ?? "");
|
|
11126
|
-
if (Number.isFinite(at)) latest = Math.max(latest, at);
|
|
11127
|
-
}
|
|
11128
|
-
}
|
|
11129
|
-
const ends = latest + YIELDSEEKER_WITHDRAWAL_COOLDOWN_MS;
|
|
11130
|
-
return latest > 0 && ends > Date.now() ? ends : null;
|
|
11461
|
+
const since = Date.now() - WITHDRAWAL_UNDER_WAY_MAX_AGE_MS;
|
|
11462
|
+
if ((this.releasingWallets.get(wallet) ?? 0) > since) return true;
|
|
11463
|
+
const rows = await withinBudget(this.readLedger(state, chainId, asset), this.ledgerBudgetMs, null);
|
|
11464
|
+
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)));
|
|
11131
11465
|
}
|
|
11132
11466
|
/**
|
|
11133
11467
|
* The agent wallet's base-asset balance and the platform fee Yieldseeker has
|
|
@@ -12229,6 +12563,29 @@ var YieldseekerAgent = class {
|
|
|
12229
12563
|
this.users.set(key2, persisted);
|
|
12230
12564
|
return persisted;
|
|
12231
12565
|
}
|
|
12566
|
+
const pending = this.pendingUsers.get(key2);
|
|
12567
|
+
if (pending) return pending;
|
|
12568
|
+
const request2 = this.signInUser(state, chainId);
|
|
12569
|
+
this.pendingUsers.set(key2, request2);
|
|
12570
|
+
try {
|
|
12571
|
+
return await request2;
|
|
12572
|
+
} finally {
|
|
12573
|
+
if (this.pendingUsers.get(key2) === request2) this.pendingUsers.delete(key2);
|
|
12574
|
+
}
|
|
12575
|
+
}
|
|
12576
|
+
/**
|
|
12577
|
+
* `login-with-wallet`, and `POST /users` for a wallet without an account.
|
|
12578
|
+
* Both draw on Yieldseeker's per-IP sign-in allowance, which all our users
|
|
12579
|
+
* share: while a 429's pause lasts nothing is sent, and a new 429 starts one.
|
|
12580
|
+
*/
|
|
12581
|
+
async signInUser(state, chainId) {
|
|
12582
|
+
const key2 = this.userKey(state, chainId);
|
|
12583
|
+
const pausedUntil = readYieldseekerLoginCooldown();
|
|
12584
|
+
if (pausedUntil !== void 0) throw this.signInRateLimited(pausedUntil);
|
|
12585
|
+
const limited = (error) => {
|
|
12586
|
+
const retryAfter = error instanceof YieldseekerApiError ? rateLimitDelay({ status: error.status, fields: error.responseFields }) : rateLimitDelay(error);
|
|
12587
|
+
throw this.signInRateLimited(startYieldseekerLoginCooldown(retryAfter));
|
|
12588
|
+
};
|
|
12232
12589
|
const walletAddress = getAddress6(state.walletAddress);
|
|
12233
12590
|
const generation = this.readGeneration;
|
|
12234
12591
|
let user = null;
|
|
@@ -12246,11 +12603,13 @@ var YieldseekerAgent = class {
|
|
|
12246
12603
|
});
|
|
12247
12604
|
}
|
|
12248
12605
|
} catch (error) {
|
|
12606
|
+
if (isSignInRateLimit(error)) limited(error);
|
|
12249
12607
|
if (!(error instanceof YieldseekerApiError) || error.providerCode !== "NO_USER") {
|
|
12250
12608
|
if (error instanceof OwneyError) throw error;
|
|
12251
12609
|
throw this.mapRequestFailure(error);
|
|
12252
12610
|
}
|
|
12253
12611
|
let created;
|
|
12612
|
+
let registeredMeanwhile = false;
|
|
12254
12613
|
for (let attempt = 0; attempt < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS; attempt += 1) {
|
|
12255
12614
|
try {
|
|
12256
12615
|
created = await this.providerRequest(
|
|
@@ -12267,12 +12626,32 @@ var YieldseekerAgent = class {
|
|
|
12267
12626
|
);
|
|
12268
12627
|
break;
|
|
12269
12628
|
} catch (createError) {
|
|
12629
|
+
if (isSignInRateLimit(createError)) limited(createError);
|
|
12630
|
+
if (isWalletAlreadyRegistered(createError)) {
|
|
12631
|
+
registeredMeanwhile = true;
|
|
12632
|
+
break;
|
|
12633
|
+
}
|
|
12270
12634
|
const canRetry = isUsernameConflict(createError) && attempt + 1 < YIELDSEEKER_USERNAME_CREATE_ATTEMPTS;
|
|
12271
12635
|
if (canRetry) continue;
|
|
12272
12636
|
throw this.mapRequestFailure(createError);
|
|
12273
12637
|
}
|
|
12274
12638
|
}
|
|
12275
12639
|
user = created?.user ?? null;
|
|
12640
|
+
if (registeredMeanwhile) {
|
|
12641
|
+
try {
|
|
12642
|
+
const login = await this.providerRequest(
|
|
12643
|
+
state,
|
|
12644
|
+
chainId,
|
|
12645
|
+
"/users/login-with-wallet",
|
|
12646
|
+
{ method: "POST", body: { walletAddress } }
|
|
12647
|
+
);
|
|
12648
|
+
user = login?.user ?? null;
|
|
12649
|
+
} catch (loginError) {
|
|
12650
|
+
if (isSignInRateLimit(loginError)) limited(loginError);
|
|
12651
|
+
if (loginError instanceof OwneyError) throw loginError;
|
|
12652
|
+
throw this.mapRequestFailure(loginError);
|
|
12653
|
+
}
|
|
12654
|
+
}
|
|
12276
12655
|
}
|
|
12277
12656
|
if (!user || !/^[a-zA-Z0-9_-]{1,128}$/.test(user.userId)) {
|
|
12278
12657
|
throw this.invalidResponse("wallet identity");
|
|
@@ -12283,6 +12662,19 @@ var YieldseekerAgent = class {
|
|
|
12283
12662
|
writeYieldseekerIdentity(state.walletAddress, chainId, resolved.userId);
|
|
12284
12663
|
return resolved;
|
|
12285
12664
|
}
|
|
12665
|
+
signInRateLimited(until) {
|
|
12666
|
+
return new OwneyError(
|
|
12667
|
+
"AGENT_RATE_LIMITED",
|
|
12668
|
+
"Too many sign-in attempts right now. Please wait before trying again.",
|
|
12669
|
+
{
|
|
12670
|
+
reason: "YIELDSEEKER_SIGN_IN_RATE_LIMITED",
|
|
12671
|
+
statusCode: 429,
|
|
12672
|
+
retryAt: until,
|
|
12673
|
+
retryAfterSeconds: Math.max(0, Math.ceil((until - Date.now()) / 1e3))
|
|
12674
|
+
},
|
|
12675
|
+
this.id
|
|
12676
|
+
);
|
|
12677
|
+
}
|
|
12286
12678
|
forgetUser(state, chainId) {
|
|
12287
12679
|
this.users.delete(this.userKey(state, chainId));
|
|
12288
12680
|
clearYieldseekerIdentity(state.walletAddress, chainId);
|
|
@@ -12764,6 +13156,9 @@ var YieldseekerAgent = class {
|
|
|
12764
13156
|
setAccountRefusedListener(listener) {
|
|
12765
13157
|
this.accountRefusedListener = listener;
|
|
12766
13158
|
}
|
|
13159
|
+
setSignInRefusedListener(listener) {
|
|
13160
|
+
this.signInRefusedListener = listener;
|
|
13161
|
+
}
|
|
12767
13162
|
setFundingLedgerAccess(access) {
|
|
12768
13163
|
this.ledgerAccess = access;
|
|
12769
13164
|
this.ledgerReads.clear();
|
|
@@ -13157,7 +13552,13 @@ var YieldseekerAgent = class {
|
|
|
13157
13552
|
if (error.providerCode === "NO_USER") throw error;
|
|
13158
13553
|
if (!error.isAuthenticationError) throw error;
|
|
13159
13554
|
if (promptless) {
|
|
13160
|
-
this.auth.discardToken(state, chainId, signature);
|
|
13555
|
+
const dropped = this.auth.discardToken(state, chainId, signature);
|
|
13556
|
+
if (dropped) {
|
|
13557
|
+
try {
|
|
13558
|
+
this.signInRefusedListener?.();
|
|
13559
|
+
} catch {
|
|
13560
|
+
}
|
|
13561
|
+
}
|
|
13161
13562
|
throw error;
|
|
13162
13563
|
}
|
|
13163
13564
|
signature = await this.auth.refreshToken(state, chainId, signature);
|
|
@@ -14267,7 +14668,7 @@ function runSameChainOrder(deps, options) {
|
|
|
14267
14668
|
|
|
14268
14669
|
// src/lib/swap/swap.secret-store.ts
|
|
14269
14670
|
var KEY_PREFIX4 = "owney.swap.order";
|
|
14270
|
-
var
|
|
14671
|
+
var storage7 = () => {
|
|
14271
14672
|
if (typeof window === "undefined") return null;
|
|
14272
14673
|
try {
|
|
14273
14674
|
return window.localStorage;
|
|
@@ -14277,7 +14678,7 @@ var storage5 = () => {
|
|
|
14277
14678
|
};
|
|
14278
14679
|
var keyFor2 = (orderHash) => `${KEY_PREFIX4}.${orderHash}`;
|
|
14279
14680
|
function saveOrder(order) {
|
|
14280
|
-
const store =
|
|
14681
|
+
const store = storage7();
|
|
14281
14682
|
if (!store) return false;
|
|
14282
14683
|
try {
|
|
14283
14684
|
const value = JSON.stringify(order);
|
|
@@ -14288,7 +14689,7 @@ function saveOrder(order) {
|
|
|
14288
14689
|
}
|
|
14289
14690
|
}
|
|
14290
14691
|
function loadOrder(orderHash) {
|
|
14291
|
-
const store =
|
|
14692
|
+
const store = storage7();
|
|
14292
14693
|
if (!store) return null;
|
|
14293
14694
|
try {
|
|
14294
14695
|
const raw2 = store.getItem(keyFor2(orderHash));
|
|
@@ -14303,7 +14704,7 @@ function loadOrder(orderHash) {
|
|
|
14303
14704
|
}
|
|
14304
14705
|
}
|
|
14305
14706
|
function clearOrder(orderHash) {
|
|
14306
|
-
const store =
|
|
14707
|
+
const store = storage7();
|
|
14307
14708
|
if (!store) return;
|
|
14308
14709
|
try {
|
|
14309
14710
|
store.removeItem(keyFor2(orderHash));
|
|
@@ -14311,7 +14712,7 @@ function clearOrder(orderHash) {
|
|
|
14311
14712
|
}
|
|
14312
14713
|
}
|
|
14313
14714
|
function listOrders(_now = Date.now()) {
|
|
14314
|
-
const store =
|
|
14715
|
+
const store = storage7();
|
|
14315
14716
|
if (!store) return [];
|
|
14316
14717
|
const out = [];
|
|
14317
14718
|
try {
|
|
@@ -15122,7 +15523,7 @@ async function buildErc2612Permit(reads, input) {
|
|
|
15122
15523
|
// src/lib/swap/swap.withdraw-swap.ts
|
|
15123
15524
|
var KEY_PREFIX5 = "owney.swap.withdraw";
|
|
15124
15525
|
var MAX_AGE_MS = 24 * 60 * 60 * 1e3;
|
|
15125
|
-
var
|
|
15526
|
+
var storage8 = () => {
|
|
15126
15527
|
if (typeof window === "undefined") return null;
|
|
15127
15528
|
try {
|
|
15128
15529
|
return window.localStorage;
|
|
@@ -15147,7 +15548,7 @@ var notify = () => {
|
|
|
15147
15548
|
}
|
|
15148
15549
|
};
|
|
15149
15550
|
function saveWithdrawSwap(record2) {
|
|
15150
|
-
const store =
|
|
15551
|
+
const store = storage8();
|
|
15151
15552
|
if (!store) return false;
|
|
15152
15553
|
try {
|
|
15153
15554
|
const current = store.getItem(keyFor3(record2.orderHash));
|
|
@@ -15161,7 +15562,7 @@ function saveWithdrawSwap(record2) {
|
|
|
15161
15562
|
return true;
|
|
15162
15563
|
}
|
|
15163
15564
|
function updateWithdrawSwap(orderHash, patch) {
|
|
15164
|
-
const store =
|
|
15565
|
+
const store = storage8();
|
|
15165
15566
|
if (!store) return;
|
|
15166
15567
|
try {
|
|
15167
15568
|
const raw2 = store.getItem(keyFor3(orderHash));
|
|
@@ -15178,7 +15579,7 @@ function updateWithdrawSwap(orderHash, patch) {
|
|
|
15178
15579
|
notify();
|
|
15179
15580
|
}
|
|
15180
15581
|
function clearWithdrawSwap(orderHash) {
|
|
15181
|
-
const store =
|
|
15582
|
+
const store = storage8();
|
|
15182
15583
|
if (!store) return;
|
|
15183
15584
|
try {
|
|
15184
15585
|
const raw2 = store.getItem(keyFor3(orderHash));
|
|
@@ -15192,7 +15593,7 @@ function clearWithdrawSwap(orderHash) {
|
|
|
15192
15593
|
notify();
|
|
15193
15594
|
}
|
|
15194
15595
|
function listWithdrawSwaps(now = Date.now(), includeDismissed = false) {
|
|
15195
|
-
const store =
|
|
15596
|
+
const store = storage8();
|
|
15196
15597
|
if (!store) return [];
|
|
15197
15598
|
const out = [];
|
|
15198
15599
|
try {
|
|
@@ -15229,7 +15630,7 @@ if (typeof window !== "undefined" && typeof window.addEventListener === "functio
|
|
|
15229
15630
|
// src/lib/swap/swap.pending-deposit.ts
|
|
15230
15631
|
var KEY_PREFIX6 = "owney.swap.pending-deposit";
|
|
15231
15632
|
var MAX_AGE_MS2 = 24 * 60 * 60 * 1e3;
|
|
15232
|
-
var
|
|
15633
|
+
var storage9 = () => {
|
|
15233
15634
|
if (typeof window === "undefined") return null;
|
|
15234
15635
|
try {
|
|
15235
15636
|
return window.localStorage;
|
|
@@ -15239,7 +15640,7 @@ var storage7 = () => {
|
|
|
15239
15640
|
};
|
|
15240
15641
|
var keyFor4 = (id) => `${KEY_PREFIX6}.${id}`;
|
|
15241
15642
|
function savePendingDeposit(entry) {
|
|
15242
|
-
const store =
|
|
15643
|
+
const store = storage9();
|
|
15243
15644
|
if (!store) return;
|
|
15244
15645
|
try {
|
|
15245
15646
|
store.setItem(keyFor4(entry.id), JSON.stringify(entry));
|
|
@@ -15248,7 +15649,7 @@ function savePendingDeposit(entry) {
|
|
|
15248
15649
|
}
|
|
15249
15650
|
}
|
|
15250
15651
|
function clearPendingDeposit(id) {
|
|
15251
|
-
const store =
|
|
15652
|
+
const store = storage9();
|
|
15252
15653
|
if (!store) return;
|
|
15253
15654
|
try {
|
|
15254
15655
|
store.removeItem(keyFor4(id));
|
|
@@ -15257,7 +15658,7 @@ function clearPendingDeposit(id) {
|
|
|
15257
15658
|
}
|
|
15258
15659
|
}
|
|
15259
15660
|
function listPendingDeposits(now = Date.now()) {
|
|
15260
|
-
const store =
|
|
15661
|
+
const store = storage9();
|
|
15261
15662
|
if (!store) return [];
|
|
15262
15663
|
const out = [];
|
|
15263
15664
|
try {
|
|
@@ -16760,15 +17161,8 @@ var OwneySDK = class {
|
|
|
16760
17161
|
*/
|
|
16761
17162
|
disabledAgents = /* @__PURE__ */ new Set();
|
|
16762
17163
|
accountRefusedListeners = /* @__PURE__ */ new Set();
|
|
17164
|
+
signInRefusedListeners = /* @__PURE__ */ new Set();
|
|
16763
17165
|
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
17166
|
state = null;
|
|
16773
17167
|
connectionRevision = 0;
|
|
16774
17168
|
disconnectingAgents = null;
|
|
@@ -16975,7 +17369,7 @@ var OwneySDK = class {
|
|
|
16975
17369
|
read: async () => {
|
|
16976
17370
|
const state = this.state;
|
|
16977
17371
|
if (!state || state.walletAddress.toLowerCase() !== owner) return null;
|
|
16978
|
-
const sample = await agent.providerEarningsSample(state, evidence.chainId);
|
|
17372
|
+
const sample = await agent.providerEarningsSample(this.readStateFor(state), evidence.chainId);
|
|
16979
17373
|
return sample ? { ...sample, observedAt: (/* @__PURE__ */ new Date()).toISOString() } : null;
|
|
16980
17374
|
},
|
|
16981
17375
|
emit: (data) => op.event?.("provider.sample", data)
|
|
@@ -16994,6 +17388,19 @@ var OwneySDK = class {
|
|
|
16994
17388
|
this.accountRefusedListeners.delete(listener);
|
|
16995
17389
|
};
|
|
16996
17390
|
}
|
|
17391
|
+
/**
|
|
17392
|
+
* Listens for an agent dropping a saved sign-in its server refused, outside
|
|
17393
|
+
* connect (a read or a withdrawal found it refused). The agent will not
|
|
17394
|
+
* sign in again by itself; the next sign-in is the user's. Not fired where a
|
|
17395
|
+
* refused sign-in is renewed (connect, deposit). Returns the unsubscribe
|
|
17396
|
+
* function.
|
|
17397
|
+
*/
|
|
17398
|
+
onSignInRefused(listener) {
|
|
17399
|
+
this.signInRefusedListeners.add(listener);
|
|
17400
|
+
return () => {
|
|
17401
|
+
this.signInRefusedListeners.delete(listener);
|
|
17402
|
+
};
|
|
17403
|
+
}
|
|
16997
17404
|
/**
|
|
16998
17405
|
* Listens for the sign-ins a connect asks for (`SignInProgress`): which
|
|
16999
17406
|
* agents will ask the wallet to sign in, and each one as it starts and ends,
|
|
@@ -17007,6 +17414,28 @@ var OwneySDK = class {
|
|
|
17007
17414
|
this.signInProgressListeners.delete(listener);
|
|
17008
17415
|
};
|
|
17009
17416
|
}
|
|
17417
|
+
/**
|
|
17418
|
+
* The agents that would ask the wallet to sign in on `chainId` right now:
|
|
17419
|
+
* enabled agents on that chain whose `needsSignIn` says yes. One with no
|
|
17420
|
+
* such check counts as no; one that throws counts as yes, so an unknown
|
|
17421
|
+
* answer never lets the app retry quietly into a prompt. Never prompts and
|
|
17422
|
+
* never calls the network. Empty before connect.
|
|
17423
|
+
*/
|
|
17424
|
+
signInsNeeded(chainId) {
|
|
17425
|
+
const state = this.state;
|
|
17426
|
+
if (state === null) return [];
|
|
17427
|
+
const needed = [];
|
|
17428
|
+
for (const [id, agent] of this.agents) {
|
|
17429
|
+
if (this.isAgentDisabled(id)) continue;
|
|
17430
|
+
if (!agent.supportedChainIds.includes(chainId)) continue;
|
|
17431
|
+
try {
|
|
17432
|
+
if (agent.needsSignIn?.(state, chainId) === true) needed.push(id);
|
|
17433
|
+
} catch {
|
|
17434
|
+
needed.push(id);
|
|
17435
|
+
}
|
|
17436
|
+
}
|
|
17437
|
+
return needed;
|
|
17438
|
+
}
|
|
17010
17439
|
/**
|
|
17011
17440
|
* The sign-ins this connect asks for: the agents whose `needsSignIn` says
|
|
17012
17441
|
* yes now (one that throws counts as no). Each is announced at its first
|
|
@@ -17064,6 +17493,14 @@ var OwneySDK = class {
|
|
|
17064
17493
|
}
|
|
17065
17494
|
}
|
|
17066
17495
|
});
|
|
17496
|
+
agent.setSignInRefusedListener?.(() => {
|
|
17497
|
+
for (const listener of [...this.signInRefusedListeners]) {
|
|
17498
|
+
try {
|
|
17499
|
+
listener(agent.id);
|
|
17500
|
+
} catch {
|
|
17501
|
+
}
|
|
17502
|
+
}
|
|
17503
|
+
});
|
|
17067
17504
|
}
|
|
17068
17505
|
/**
|
|
17069
17506
|
* Funding-ledger read access handed to agents for earnings holds. Reads only
|
|
@@ -17143,7 +17580,6 @@ var OwneySDK = class {
|
|
|
17143
17580
|
}
|
|
17144
17581
|
const replacingOwner = this.state !== null && this.state.walletAddress.toLowerCase() !== walletAddress.toLowerCase();
|
|
17145
17582
|
this.clearConnectionState();
|
|
17146
|
-
if (replacingOwner) this.declinedSignIns.clear();
|
|
17147
17583
|
await (replacingOwner ? this.disconnectAgents() : this.disconnectingAgents);
|
|
17148
17584
|
if (revision !== this.connectionRevision)
|
|
17149
17585
|
throw new OwneyError("NOT_CONNECTED", "Wallet connection changed while connecting.");
|
|
@@ -17157,11 +17593,10 @@ var OwneySDK = class {
|
|
|
17157
17593
|
* Disconnect from all agents and clear connection state.
|
|
17158
17594
|
* After calling this, `connect()` must be called again before using agent methods.
|
|
17159
17595
|
*/
|
|
17160
|
-
async disconnect() {
|
|
17596
|
+
async disconnect(options) {
|
|
17161
17597
|
++this.connectionRevision;
|
|
17162
17598
|
this.clearConnectionState();
|
|
17163
|
-
this.
|
|
17164
|
-
await this.disconnectAgents();
|
|
17599
|
+
await this.disconnectAgents(options);
|
|
17165
17600
|
}
|
|
17166
17601
|
clearConnectionState() {
|
|
17167
17602
|
this.state = null;
|
|
@@ -17173,9 +17608,9 @@ var OwneySDK = class {
|
|
|
17173
17608
|
this.cachedWethSponsoredCallback = null;
|
|
17174
17609
|
this.cachedSponsoredCallsCallbacks.clear();
|
|
17175
17610
|
}
|
|
17176
|
-
disconnectAgents() {
|
|
17611
|
+
disconnectAgents(options) {
|
|
17177
17612
|
if (this.disconnectingAgents) return this.disconnectingAgents;
|
|
17178
|
-
const pending = Promise.allSettled([...this.agents.values()].map(async (agent) => agent.disconnect())).then((results) => {
|
|
17613
|
+
const pending = Promise.allSettled([...this.agents.values()].map(async (agent) => agent.disconnect(options))).then((results) => {
|
|
17179
17614
|
const failure = results.find((result) => result.status === "rejected");
|
|
17180
17615
|
if (failure?.status === "rejected") throw failure.reason;
|
|
17181
17616
|
});
|
|
@@ -17216,17 +17651,14 @@ var OwneySDK = class {
|
|
|
17216
17651
|
return agent?.isSlotUnavailable?.(state, chainId, asset) === true;
|
|
17217
17652
|
}
|
|
17218
17653
|
/**
|
|
17219
|
-
* The state
|
|
17220
|
-
*
|
|
17221
|
-
*
|
|
17222
|
-
*
|
|
17223
|
-
*
|
|
17224
|
-
* lifts it.
|
|
17654
|
+
* The state every agent read uses: promptless, so a read uses a saved
|
|
17655
|
+
* sign-in only and never opens a wallet prompt. A read that would need one
|
|
17656
|
+
* fails for that agent instead; the app keeps the last known value and
|
|
17657
|
+
* retries later. Only connect/activation and user actions (deposit,
|
|
17658
|
+
* withdraw) may ask the wallet to sign in, and they use the plain state.
|
|
17225
17659
|
*/
|
|
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;
|
|
17660
|
+
readStateFor(state) {
|
|
17661
|
+
return state.promptless === true ? state : { ...state, promptless: true };
|
|
17230
17662
|
}
|
|
17231
17663
|
/**
|
|
17232
17664
|
* Check if the SDK has an active connection state.
|
|
@@ -17450,7 +17882,7 @@ var OwneySDK = class {
|
|
|
17450
17882
|
}
|
|
17451
17883
|
/** The active agents, each with the state its reads use (`readStateFor`). */
|
|
17452
17884
|
activeReads(state, chainId) {
|
|
17453
|
-
return [...this.getActiveAgents()].map(([id, agent]) => ({ id, agent, state: this.readStateFor(
|
|
17885
|
+
return [...this.getActiveAgents()].map(([id, agent]) => ({ id, agent, state: this.readStateFor(state), chainId }));
|
|
17454
17886
|
}
|
|
17455
17887
|
/**
|
|
17456
17888
|
* Read the org's agent policy once and reuse it. fetchOrgAgentConfig never
|
|
@@ -17736,12 +18168,7 @@ var OwneySDK = class {
|
|
|
17736
18168
|
...error instanceof OwneyError && error.details ? { details: error.details } : {}
|
|
17737
18169
|
});
|
|
17738
18170
|
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
|
-
}
|
|
18171
|
+
if (this.isUserRejectedWithdrawal(error)) walletRejected = true;
|
|
17745
18172
|
};
|
|
17746
18173
|
for (const agent of agents) {
|
|
17747
18174
|
if (!agent.checkAccount) continue;
|
|
@@ -17768,7 +18195,6 @@ var OwneySDK = class {
|
|
|
17768
18195
|
await this.applyOrgPolicyTo(agent, state, chainId);
|
|
17769
18196
|
this.assertActivationSession(state);
|
|
17770
18197
|
activatedAgentIds.push(agent.id);
|
|
17771
|
-
this.declinedSignIns.get(chainId)?.delete(agent.id);
|
|
17772
18198
|
} catch (error) {
|
|
17773
18199
|
recordFailure(agent, error);
|
|
17774
18200
|
break;
|
|
@@ -18502,7 +18928,8 @@ var OwneySDK = class {
|
|
|
18502
18928
|
}
|
|
18503
18929
|
/** Revalidate a saved transfer against the authenticated account and actual receipt. */
|
|
18504
18930
|
async inspectFunding(evidence, direction, options = {}) {
|
|
18505
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
18931
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
18932
|
+
const state = this.readStateFor(connection);
|
|
18506
18933
|
if (state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase() || !evidence.txHash)
|
|
18507
18934
|
throw new OwneyError("AGENT_API_ERROR", "Funding evidence does not match the connected account.");
|
|
18508
18935
|
const agent = this.getAgent(evidence.agentId);
|
|
@@ -18615,8 +19042,9 @@ var OwneySDK = class {
|
|
|
18615
19042
|
const movement = evidence.txHash ?? evidence.userOpHash ?? evidence.callsId;
|
|
18616
19043
|
if (!agent?.depositConfirmed || !movement) return;
|
|
18617
19044
|
const key2 = `${state.walletAddress.toLowerCase()}:${chainId}:${evidence.agentId}:${evidence.token}:${movement.toLowerCase()}`;
|
|
18618
|
-
if (this.announcedDeposits.has(key2)) return;
|
|
19045
|
+
if (this.announcedDeposits.has(key2) || wasDepositAnnounced(key2)) return;
|
|
18619
19046
|
this.announcedDeposits.add(key2);
|
|
19047
|
+
rememberAnnouncedDeposit(key2);
|
|
18620
19048
|
if (this.announcedDeposits.size > 256) this.announcedDeposits.delete(this.announcedDeposits.values().next().value);
|
|
18621
19049
|
const legKey = `agent:${evidence.agentId}`;
|
|
18622
19050
|
const record2 = (type, notice) => {
|
|
@@ -18677,7 +19105,8 @@ var OwneySDK = class {
|
|
|
18677
19105
|
const fromBlock = parseBlock(opts?.fromBlock ?? evidence.payoutSearch?.fromBlock);
|
|
18678
19106
|
const cursor = parseBlock(opts?.cursor);
|
|
18679
19107
|
if (fromBlock === null || cursor === null) return null;
|
|
18680
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19108
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19109
|
+
const state = this.readStateFor(connection);
|
|
18681
19110
|
if (typeof evidence.walletAddress !== "string" || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18682
19111
|
const agent = this.getAgent(evidence.agentId);
|
|
18683
19112
|
const verifiedWallet = agent.getFundingWallet ? await agent.getFundingWallet(state, chainId, evidence.token) : (await agent.getUserProfile(state, chainId)).smartWallet;
|
|
@@ -18702,7 +19131,8 @@ var OwneySDK = class {
|
|
|
18702
19131
|
/** Resolve a saved sponsored-withdrawal ID without opening a wallet prompt. */
|
|
18703
19132
|
async resolveSponsoredWithdrawalEvidence(evidence, options = {}) {
|
|
18704
19133
|
if (evidence.callsId && !evidence.userOpHash) return this.resolveWalletCallsFundingEvidence(evidence, "withdraw");
|
|
18705
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19134
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19135
|
+
const state = this.readStateFor(connection);
|
|
18706
19136
|
if (evidence.agentId !== "yieldseeker" || chainId !== 8453 || evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return evidence;
|
|
18707
19137
|
const agent = this.getAgent("yieldseeker");
|
|
18708
19138
|
const wallet = await agent.getFundingWallet?.(state, chainId, evidence.token);
|
|
@@ -18749,7 +19179,8 @@ var OwneySDK = class {
|
|
|
18749
19179
|
}
|
|
18750
19180
|
/** Recover an EIP-5792 deposit or payout using this account's exact batch ID. */
|
|
18751
19181
|
async resolveWalletCallsFundingEvidence(evidence, direction) {
|
|
18752
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19182
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19183
|
+
const state = this.readStateFor(connection);
|
|
18753
19184
|
if (!evidence.callsId || evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return evidence;
|
|
18754
19185
|
const agent = this.getAgent(evidence.agentId);
|
|
18755
19186
|
const wallet = agent.getFundingWallet ? await agent.getFundingWallet(state, chainId, evidence.token) : (await agent.getUserProfile(state, chainId)).smartWallet;
|
|
@@ -18782,7 +19213,8 @@ var OwneySDK = class {
|
|
|
18782
19213
|
const first = evidences[0];
|
|
18783
19214
|
const saved = !first.txHash && evidences.every((e) => !e.txHash && (e.serverBroadcast === "unknown" || e.serverBroadcast === true) && typeof e.authorizationDeadline === "number");
|
|
18784
19215
|
if (!first.txHash && !saved) return false;
|
|
18785
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(first.chainId);
|
|
19216
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(first.chainId);
|
|
19217
|
+
const state = this.readStateFor(connection);
|
|
18786
19218
|
const token = SupportedAssets.find((value) => value.chainId === chainId && value.symbol === first.token);
|
|
18787
19219
|
if (!token) return false;
|
|
18788
19220
|
const scope = {
|
|
@@ -18899,7 +19331,8 @@ var OwneySDK = class {
|
|
|
18899
19331
|
/** Optional post-payout display proof; receipt verification and the provider
|
|
18900
19332
|
* adapter must agree before attaching it to this exact balance object. */
|
|
18901
19333
|
async verifyWithdrawalBalance(evidence, balance) {
|
|
18902
|
-
const { state, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19334
|
+
const { state: connection, chainId, assertCurrent } = this.captureReadScope(evidence.chainId);
|
|
19335
|
+
const state = this.readStateFor(connection);
|
|
18903
19336
|
const agent = this.getAgent(evidence.agentId);
|
|
18904
19337
|
if (!agent.verifyWithdrawalBalance || !evidence.txHash || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return balance;
|
|
18905
19338
|
const key2 = `${state.walletAddress.toLowerCase()}:${chainId}:${evidence.agentId}:${evidence.token}:${evidence.txHash}:${evidence.intendedAmount}`;
|
|
@@ -18948,7 +19381,8 @@ var OwneySDK = class {
|
|
|
18948
19381
|
const agent = this.getAgent(evidence.agentId);
|
|
18949
19382
|
if (!agent.getFundingHistory) return { data: [], hasMore: false };
|
|
18950
19383
|
const filters = { tokenSymbol: evidence.token, fromDate, limit: 50, ...options };
|
|
18951
|
-
const
|
|
19384
|
+
const readState = this.readStateFor(state);
|
|
19385
|
+
const page = await this.readAgent(agent, "history", () => agent.getFundingHistory(readState, chainId, filters), filters);
|
|
18952
19386
|
assertCurrent();
|
|
18953
19387
|
return page;
|
|
18954
19388
|
}
|
|
@@ -18965,7 +19399,7 @@ var OwneySDK = class {
|
|
|
18965
19399
|
const state = this.state;
|
|
18966
19400
|
const id = evidence.withdrawalRequest?.providerWithdrawalId;
|
|
18967
19401
|
if (evidence.agentId !== "zyfai" || !id || !state || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18968
|
-
return this.getAgent("zyfai").getWithdrawalLifecycle(state, id);
|
|
19402
|
+
return this.getAgent("zyfai").getWithdrawalLifecycle(this.readStateFor(state), id);
|
|
18969
19403
|
}
|
|
18970
19404
|
/** A Zyfai deposit's placement status by the id recorded on its evidence. Never signs,
|
|
18971
19405
|
* prompts or authenticates; `null` when unavailable or not this wallet's Zyfai deposit. */
|
|
@@ -18973,7 +19407,7 @@ var OwneySDK = class {
|
|
|
18973
19407
|
const state = this.state;
|
|
18974
19408
|
const id = evidence.providerDepositId;
|
|
18975
19409
|
if (evidence.agentId !== "zyfai" || !id || !state || state.walletAddress.toLowerCase() !== evidence.walletAddress.toLowerCase()) return null;
|
|
18976
|
-
return this.getAgent("zyfai").getDepositPlacement(state, id);
|
|
19410
|
+
return this.getAgent("zyfai").getDepositPlacement(this.readStateFor(state), id);
|
|
18977
19411
|
}
|
|
18978
19412
|
// --- Fund operations ---
|
|
18979
19413
|
/** On-chain version and ownership status for this owner's Yieldseeker agent. */
|
|
@@ -18981,7 +19415,7 @@ var OwneySDK = class {
|
|
|
18981
19415
|
const state = this.requireState();
|
|
18982
19416
|
const chainId = this.requireChainId();
|
|
18983
19417
|
const agent = this.getAgent("yieldseeker");
|
|
18984
|
-
return agent.getWalletStatus(state, chainId, asset);
|
|
19418
|
+
return agent.getWalletStatus(this.readStateFor(state), chainId, asset);
|
|
18985
19419
|
}
|
|
18986
19420
|
/** Deployment gate; an unavailable response keeps the current paid path. */
|
|
18987
19421
|
async isYieldseekerWithdrawalSponsorshipAvailable() {
|
|
@@ -20054,7 +20488,7 @@ var OwneySDK = class {
|
|
|
20054
20488
|
inspect: (value, fromHistory) => this.inspectFunding(value, "withdraw", { requireAmountMatch: fromHistory, refreshBalance: false }),
|
|
20055
20489
|
resolve: (value) => this.resolveSponsoredWithdrawalEvidence(value, { submittedAt: recovery.submittedAt }),
|
|
20056
20490
|
history: (value, fromDate, filters) => this.getFundingHistory(value, fromDate, filters),
|
|
20057
|
-
verifyCompletion: (value) => this.getAgent(value.agentId).verifyWithdrawalCompletion?.(state, value) ?? Promise.resolve({ status: "unavailable" }),
|
|
20491
|
+
verifyCompletion: (value) => this.getAgent(value.agentId).verifyWithdrawalCompletion?.(this.readStateFor(state), value) ?? Promise.resolve({ status: "unavailable" }),
|
|
20058
20492
|
onProgress: (value) => {
|
|
20059
20493
|
recovery.evidence[value.agentId] = value;
|
|
20060
20494
|
persist();
|
|
@@ -21474,7 +21908,7 @@ var OwneySDK = class {
|
|
|
21474
21908
|
const { state: scope, chainId, assertCurrent } = this.captureReadScope(options?.chainId);
|
|
21475
21909
|
const asset = options?.asset;
|
|
21476
21910
|
const agent = this.getAgent(agentId);
|
|
21477
|
-
const state = this.readStateFor(
|
|
21911
|
+
const state = this.readStateFor(scope);
|
|
21478
21912
|
const result = await this.readAgent(
|
|
21479
21913
|
agent,
|
|
21480
21914
|
"balances",
|
|
@@ -21573,7 +22007,7 @@ var OwneySDK = class {
|
|
|
21573
22007
|
const chainId = this.requireChainId();
|
|
21574
22008
|
if (agentId) {
|
|
21575
22009
|
const agent = this.getAgent(agentId);
|
|
21576
|
-
const readState = this.readStateFor(
|
|
22010
|
+
const readState = this.readStateFor(state);
|
|
21577
22011
|
return this.readAgent(
|
|
21578
22012
|
agent,
|
|
21579
22013
|
"earnings",
|
|
@@ -21603,7 +22037,7 @@ var OwneySDK = class {
|
|
|
21603
22037
|
() => agent.refreshEarnings?.(readState, readChain) ?? agent.getEarnings(readState, readChain),
|
|
21604
22038
|
offChain ? { chainId: readChain } : null
|
|
21605
22039
|
);
|
|
21606
|
-
if (agentId) return refreshAgent({ agent: this.getAgent(agentId), state: this.readStateFor(
|
|
22040
|
+
if (agentId) return refreshAgent({ agent: this.getAgent(agentId), state: this.readStateFor(state), chainId });
|
|
21607
22041
|
return this.aggregateEarnings(this.portfolioReads(state, chainId), refreshAgent);
|
|
21608
22042
|
}
|
|
21609
22043
|
async aggregateEarnings(entries, read2) {
|
|
@@ -21671,7 +22105,7 @@ var OwneySDK = class {
|
|
|
21671
22105
|
for (const agent of agents) {
|
|
21672
22106
|
for (const legChainId of chainIds) {
|
|
21673
22107
|
if (agentRunsOn(agent, legChainId))
|
|
21674
|
-
legs.push({ agent, legChainId, legState: this.readStateFor(
|
|
22108
|
+
legs.push({ agent, legChainId, legState: this.readStateFor(state) });
|
|
21675
22109
|
}
|
|
21676
22110
|
}
|
|
21677
22111
|
if (!agentId) {
|
|
@@ -21711,7 +22145,7 @@ var OwneySDK = class {
|
|
|
21711
22145
|
assets: []
|
|
21712
22146
|
};
|
|
21713
22147
|
}
|
|
21714
|
-
const readState = this.readStateFor(
|
|
22148
|
+
const readState = this.readStateFor(state);
|
|
21715
22149
|
return this.readAgent(
|
|
21716
22150
|
agent,
|
|
21717
22151
|
"dailyEarnings",
|
|
@@ -21792,7 +22226,7 @@ var OwneySDK = class {
|
|
|
21792
22226
|
`Agent ${agent.id} does not support pool customization`
|
|
21793
22227
|
);
|
|
21794
22228
|
}
|
|
21795
|
-
return agent.getPoolSelection(state, chainId, {
|
|
22229
|
+
return agent.getPoolSelection(this.readStateFor(state), chainId, {
|
|
21796
22230
|
pairs: params.pairs,
|
|
21797
22231
|
assets: params.assets
|
|
21798
22232
|
});
|
|
@@ -21817,7 +22251,7 @@ var OwneySDK = class {
|
|
|
21817
22251
|
const scopeChainId = scope === "all" ? null : scope;
|
|
21818
22252
|
if (agentId) {
|
|
21819
22253
|
const agent = this.getAgent(agentId);
|
|
21820
|
-
const readState = this.readStateFor(
|
|
22254
|
+
const readState = this.readStateFor(state);
|
|
21821
22255
|
const accountApy = await this.readAgent(
|
|
21822
22256
|
agent,
|
|
21823
22257
|
"accountApy",
|
|
@@ -21957,7 +22391,7 @@ var OwneySDK = class {
|
|
|
21957
22391
|
for (const agent of agents) {
|
|
21958
22392
|
for (const legChainId of chainIds) {
|
|
21959
22393
|
if (agentRunsOn(agent, legChainId))
|
|
21960
|
-
legs.push({ agentId: agent.id, chainId: legChainId, legState: this.readStateFor(
|
|
22394
|
+
legs.push({ agentId: agent.id, chainId: legChainId, legState: this.readStateFor(state2) });
|
|
21961
22395
|
}
|
|
21962
22396
|
}
|
|
21963
22397
|
if (!agentId) {
|
|
@@ -22001,7 +22435,7 @@ var OwneySDK = class {
|
|
|
22001
22435
|
const { state, chainId, assertCurrent } = this.captureReadScope(options?.chainId);
|
|
22002
22436
|
if (agentId) {
|
|
22003
22437
|
const agent = this.getAgent(agentId);
|
|
22004
|
-
const readState = this.readStateFor(
|
|
22438
|
+
const readState = this.readStateFor(state);
|
|
22005
22439
|
const page = await this.readAgent(agent, "history", () => agent.getHistory(readState, chainId, filters), filters);
|
|
22006
22440
|
assertCurrent();
|
|
22007
22441
|
return page;
|
|
@@ -22016,7 +22450,7 @@ var OwneySDK = class {
|
|
|
22016
22450
|
}
|
|
22017
22451
|
const agentFilters = { ...filters, cursor: agentCursor || void 0 };
|
|
22018
22452
|
try {
|
|
22019
|
-
const readState = this.readStateFor(
|
|
22453
|
+
const readState = this.readStateFor(state);
|
|
22020
22454
|
const page = await this.readAgent(
|
|
22021
22455
|
agent,
|
|
22022
22456
|
"history",
|
|
@@ -22078,7 +22512,7 @@ var OwneySDK = class {
|
|
|
22078
22512
|
const chainId = this.requireChainId();
|
|
22079
22513
|
if (agentId) {
|
|
22080
22514
|
const agent = this.getAgent(agentId);
|
|
22081
|
-
const readState = this.readStateFor(
|
|
22515
|
+
const readState = this.readStateFor(state);
|
|
22082
22516
|
return this.readAgent(
|
|
22083
22517
|
agent,
|
|
22084
22518
|
"profile",
|
|
@@ -22301,7 +22735,7 @@ var OwneySDK = class {
|
|
|
22301
22735
|
const entries = [...activeAgents.entries()];
|
|
22302
22736
|
const balanceResults = await Promise.allSettled(
|
|
22303
22737
|
entries.map(async ([id, agent]) => {
|
|
22304
|
-
const readState = this.readStateFor(
|
|
22738
|
+
const readState = this.readStateFor(state);
|
|
22305
22739
|
const b = await this.readAgent(
|
|
22306
22740
|
agent,
|
|
22307
22741
|
"balances",
|
|
@@ -22357,7 +22791,7 @@ import { ZyfaiSDK as ZyfaiSDK2 } from "@zyfai/sdk";
|
|
|
22357
22791
|
|
|
22358
22792
|
// src/agents/zyfai/zyfai.siwx-cache.ts
|
|
22359
22793
|
var KEY_PREFIX7 = "owney.siwx.session";
|
|
22360
|
-
var
|
|
22794
|
+
var storage10 = () => {
|
|
22361
22795
|
if (typeof window === "undefined") return null;
|
|
22362
22796
|
try {
|
|
22363
22797
|
return window.localStorage;
|
|
@@ -22398,7 +22832,7 @@ var readLegacySiwxSession = (store, address) => {
|
|
|
22398
22832
|
var readSiwxSession = (address, chainId) => {
|
|
22399
22833
|
if (typeof window === "undefined") return null;
|
|
22400
22834
|
const key2 = buildKey3(address);
|
|
22401
|
-
const store =
|
|
22835
|
+
const store = storage10();
|
|
22402
22836
|
let raw2 = null;
|
|
22403
22837
|
try {
|
|
22404
22838
|
raw2 = store?.getItem(key2) ?? null;
|
|
@@ -22428,7 +22862,7 @@ var writeSiwxSession = (address, _chainId, session) => {
|
|
|
22428
22862
|
if (typeof window === "undefined") return;
|
|
22429
22863
|
const key2 = buildKey3(address);
|
|
22430
22864
|
memorySiwxSessions.set(key2, session);
|
|
22431
|
-
const store =
|
|
22865
|
+
const store = storage10();
|
|
22432
22866
|
try {
|
|
22433
22867
|
store?.setItem(key2, JSON.stringify(session));
|
|
22434
22868
|
} catch {
|
|
@@ -22437,7 +22871,7 @@ var writeSiwxSession = (address, _chainId, session) => {
|
|
|
22437
22871
|
var clearSiwxSession = (address, _chainId) => {
|
|
22438
22872
|
const key2 = buildKey3(address);
|
|
22439
22873
|
memorySiwxSessions.delete(key2);
|
|
22440
|
-
const store =
|
|
22874
|
+
const store = storage10();
|
|
22441
22875
|
try {
|
|
22442
22876
|
store?.removeItem(key2);
|
|
22443
22877
|
} catch {
|