Skip to content

Fix Reserve swap handling and Microbridge history reads - #274

Draft
L03TJ3 wants to merge 2 commits into
masterfrom
reserve-and-bridge-fixes
Draft

L03TJ3 wants to merge 2 commits into
masterfrom
reserve-and-bridge-fixes

Conversation

@L03TJ3

@L03TJ3 L03TJ3 commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Improves Reserve swap transaction handling and error messaging, and reduces oversized Microbridge history requests.

Reserve fixes

  • Recognize known trading-limit errors within nested RPC responses, keeping wallet rejection separate.
  • Submit approvals and swaps through the wallet signer, avoiding incorrect Safe detection for wallets with EIP-7702 delegation markers.
  • Handle signature, mining, success and failure states, including mined reverts and successful replacement transactions.
  • Expose an alternative-Reserve availability check for Celo/XDC using quotes, slippage bounds and trading limits. Failed, stale or timed-out checks produce no recommendation.

Microbridge and provider fixes

  • Fetch wallet-filtered Fuse/Celo history in sequential chunks of at most 500 blocks, preserving the existing 20,000-block lookback.
  • Cache history progress per account, chain and deployment; retain partial results for retry after failures.
  • Allow read-only SDK providers without getSigner.

UI

  • Add a reusable Reserve limit modal with chain-specific DEX links and optional verified alternative-chain messaging.
  • Support custom titles and footers in ErrorModal.

Testing and integration

  • Add mocked regression tests for history fetching and provider compatibility.
  • The modal and alternative-chain check are exported for consumer integration; this PR does not wire them into an application.
  • Tests and builds were not rerun during this review against the final commit.

Summary by Sourcery

Improve Reserve swap reliability and Microbridge history retrieval while exposing reusable limit handling and alternative-chain integration APIs.

New Features:

  • Add Reserve alternative-chain availability checks and expose reusable Reserve limit UI components.
  • Add account-scoped Microbridge history synchronization with persistent progress and partial-result recovery.

Bug Fixes:

  • Improve Reserve error classification, transaction-state handling, and wallet signer compatibility for rejected, reverted, replaced, and successful transactions.
  • Prevent oversized Microbridge history requests by fetching the existing lookback in sequential blocks of no more than 500.

Enhancements:

  • Support read-only providers without signers and preserve wallet signer behavior when available.
  • Allow customizable ErrorModal titles and footers.

Build:

  • Extend SDK lint-staged checks to include production and test TypeScript configurations.

Tests:

  • Add regression coverage for provider compatibility, Microbridge history chunking, caching, retries, cancellation, decoding, and account isolation.

L03TJ3 added 2 commits October 6, 2026 20:11
- Fetch wallet-filtered Microbridge history in sequential chunks of at most 500 blocks.
- Cache successful history progress and retain partial results when requests fail.
- Support read-only SDK providers without getSigner.
- Add a reusable Reserve limit modal with chain-specific DEX links and optional alternative-chain messaging.
- Add history and provider regression tests.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Provider compatibility, CommonJS loading, history correctness, and TypeScript issues remain unresolved.

7 open findings
What changed in this PR

Improves Reserve swap reliability, Microbridge history synchronization, read-only provider support, and reusable error UI.

Changes:

  • Adds Reserve error detection, signer-based transactions, and alternative-chain checks.
  • Reworks Microbridge history into chunked, account-scoped cached reads.
  • Extends provider compatibility, tests, type-checking, and modal customization.
File Description
.eslintrc.cjs Adds SDK test lint configuration.
packages/​sdk-v2/​tsconfig.tests.json Adds test-specific TypeScript configuration.
packages/​sdk-v2/​lint-staged.config.js Type-checks production and test sources.
packages/​sdk-v2/​src/​sdk/​base/​sdk.ts Guards signer access for read-only providers.
packages/​sdk-v2/​src/​sdk/​base/​sdk.test.ts Tests provider and signer compatibility.
packages/​sdk-v2/​src/​sdk/​base/​react.readProviders.test.tsx Tests fallback-provider hook integration.
packages/​sdk-v2/​src/​sdk/​reserve/​react.tsx Adds direct wallet submission and alternative checks.
packages/​sdk-v2/​src/​sdk/​reserve/​errors.ts Classifies nested Reserve-limit errors.
packages/​sdk-v2/​src/​sdk/​reserve/​alternative.ts Validates alternative-chain quotes and limits.
packages/​sdk-v2/​src/​sdk/​reserve/​index.ts Exports new Reserve APIs.
packages/​sdk-v2/​src/​sdk/​microbridge/​history.helpers.ts Implements chunked, cached history synchronization.
packages/​sdk-v2/​src/​sdk/​microbridge/​history.helpers.test.ts Tests chunking, retries, caching, and decoding.
packages/​sdk-v2/​src/​sdk/​microbridge/​useMicroBridgeHistory.ts Adds the history synchronization hook.
packages/​sdk-v2/​src/​sdk/​microbridge/​useMicroBridgeHistory.test.tsx Tests hook refresh and account isolation.
packages/​sdk-v2/​src/​sdk/​microbridge/​react.ts Uses the new history hook.
packages/​sdk-v2/​src/​sdk/​microbridge/​index.ts Exports history APIs.
packages/​good-design/​src/​core/​web3/​modals/​ReserveLimitModal.tsx Adds Reserve-limit guidance UI.
packages/​good-design/​src/​core/​web3/​modals/​ErrorModal.tsx Supports custom titles and footers.
packages/​good-design/​src/​core/​web3/​modals/​index.ts Exports the Reserve modal.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

jest.mock("../../hooks/useRefreshOrNever", () => ({ __esModule: true, default: () => 5 }));
jest.mock("../storage", () => ({ AsyncStorage: { getItem: jest.fn(), setItem: jest.fn() } }));

let latest: ReturnType<typeof useMicroBridgeHistory>;
@@ -0,0 +1,86 @@
import { useBlockNumbers, useEthers } from "@usedapp/core";
import { useReadonlyNetworks } from "@usedapp/core/dist/esm/src/providers/network/readonlyNetworks";
Comment on lines +13 to +17
export interface ReserveTransactionStatus extends TransactionStatus {
errorType?: typeof RESERVE_LIMIT_ERROR;
/** The unmodified provider/ethers error, for debugging rather than display. */
originalError?: unknown;
}
Comment on lines +104 to +105
// Read-only BaseProviders (including FallbackProvider) do not expose a signer.
if (typeof provider.getSigner === "function") {
cancelled: () => boolean = () => false
) => {
const windowStart = Math.max(0, latestBlock - HISTORY_LOOKBACK_BLOCKS);
const fromBlock = Math.max(windowStart, (cache.lastSyncedBlock ?? -1) + 1);
): Promise<ReserveAlternative | undefined> => {
if (!deployment?.MentoBroker || !deployment.MentoExchangeProvider || !deployment.GoodDollar) return undefined;
if (!!request.exactInput === !!request.exactOutput) return undefined;
const actualChainId = BigNumber.from(await provider.send("eth_chainId", [])).toNumber();
Comment on lines +78 to +80
} else if (value && typeof value === "object" && !seen.has(value)) {
seen.add(value);
const record = value as Record<string, unknown>;

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants