Skip to content

refactor: simplify Squid funding API - #10

Merged
snissn merged 2 commits into
mainfrom
refactor/minimal-api
Jul 31, 2026
Merged

refactor: simplify Squid funding API#10
snissn merged 2 commits into
mainfrom
refactor/minimal-api

Conversation

@snissn

@snissn snissn commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

What changed

This reduces squid-evm-funding to the API needed by Filecoin Pin:

  • planSquidFunding resolves a source token from Squid's current token catalog and plans exact FIL and USDFC shortfalls.
  • executeSquidFunding validates refreshed routes, allowances, balances, transaction fees, receipts, provider status, and destination balances.
  • The public runtime surface is limited to the planner, executor, and native-token sentinel.
  • Transaction preparation is delegated to viem, including complete OP Stack fee estimation with a caller-provided buffer.
  • The account-bound wallet prepares and signs requests; invalid multi-leg plans fail before provider calls.
  • The package no longer owns checkpoint persistence or a custom package-verification framework.

The retained checks cover arbitrary catalog tokens, native tokens, route identity, trusted targets and spenders, exact allowances, standard and OP Stack native-fee ceilings, wallet and chain identity, nonce drift, partial failure, and sensitive-value redaction.

This is consumed by filecoin-project/filecoin-pin#637.

Validation

  • pnpm lint
  • pnpm typecheck
  • pnpm test — 18 passing tests
  • pnpm build
  • pnpm pack:check
  • Clean Git-dependency installation and full Filecoin Pin test suite — 750 passing, 11 skipped

The change is not performance-oriented. It removes internal abstractions without changing the network transaction contract, so no performance benchmark is required.

Size

11 files changed
1,075 insertions
1,712 deletions
net -637 lines

Copilot AI review requested due to automatic review settings July 31, 2026 02:04

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR updates the library to Squid v2. Planning resolves source tokens and returns a SquidFundingPlan. Execution consumes that plan, refreshes routes, validates chain and wallet state, prepares transactions, manages allowances, and polls status. Packaging uses pnpm pack --dry-run.

Changes

Squid v2 funding workflow

Layer / File(s) Summary
Contracts and source-token resolution
src/types.ts, src/catalog.ts
Public types now define SquidFundingPlan, direct chain IDs, prepared transaction requests, and account-bound wallet clients. Token parsing validates and resolves source-chain tokens.
Planning and Squid API integration
src/planner.ts, src/squid.ts, src/index.ts, src/index.test.ts
planSquidFunding fetches source tokens, parses decimal caps, requests routes, and returns a funding plan. Squid status and route APIs use the updated identifiers and response shapes.
Plan execution and validation
src/execution.ts, src/execution.test.ts, README.md
executeSquidFunding validates plan limits, client identity, balances, allowances, nonces, fees, refreshed routes, receipts, and status. Tests cover standard, OP Stack, native-token, and multi-leg flows. Documentation describes the new workflow and constraints.

Packaging validation

Layer / File(s) Summary
Package archive check
package.json, scripts/pack-check.mjs
pack:check now runs pnpm pack --dry-run; the custom packaging validation script was removed.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related issues

  • snissn/filecoin-pin#28 — The issue proposes integrating this library into Filecoin Pin, which aligns with the updated planning and execution APIs.

Possibly related PRs

Suggested reviewers: copilot

Poem

A rabbit plans routes, neat and bright,
Then hops through chains by lantern light.
Tokens checked and fees held tight,
Wallets guard each step just right.
Squid status glows: success in sight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: simplifying and refactoring the Squid funding API.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/minimal-api

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@snissn

snissn commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 831c922c7e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/execution.ts Outdated

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/execution.ts (1)

392-421: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Attach completed route hashes to the error when a later leg fails.

routes is a local array. When a leg throws after an earlier leg already broadcast and settled, the error propagates and routes is discarded. The host then knows that funding partially completed, but it does not receive the transaction hashes or requirement IDs of the settled legs. Manual chain search becomes the only recovery path. Expose the completed routes on the thrown error so the host can reconcile.

This applies to every throw site after the first successful send, including "Squid route failed" at line 410 and "did not complete within the poll limit" at line 419.

♻️ Proposed approach
export class SquidPartialExecutionError extends Error {
  constructor(
    message: string,
    readonly routes: readonly { requirementId: string; transactionHash: Hash }[],
    options?: ErrorOptions,
  ) {
    super(message, options)
    this.name = "SquidPartialExecutionError"
  }
}

Wrap the per-leg body in try/catch, and rethrow with new SquidPartialExecutionError(message, routes, { cause: error }) when routes.length > 0.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/execution.ts` around lines 392 - 421, Preserve completed route metadata
when a later leg fails: add the proposed SquidPartialExecutionError type, then
wrap each per-leg execution flow after the first successful send in try/catch
and rethrow this error with the current routes and original error as cause when
routes is non-empty. Update all relevant failure paths, including “Squid route
failed” and the poll-limit failure, while leaving initial-leg errors unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/planner.ts`:
- Around line 32-38: Extend the validation in planSquidFunding around the
existing sourceChainId and requirements checks to reject duplicate requirement
IDs and requirements targeting more than one destination chain. Match the
corresponding validation rules used by executeSquidFunding, ensuring invalid
plans fail before any provider or route requests.

In `@src/squid.ts`:
- Around line 81-92: Add optional timeoutMs to SquidClientOptions and have the
shared client helper create an AbortSignal.timeout(timeoutMs) for requests. In
src/squid.ts lines 81-92, update fetchSourceTokens’ /tokens request to pass that
signal; likewise update the /status request at lines 225-228. Ensure both
requests use the configured deadline while preserving existing headers and
behavior.

In `@src/types.ts`:
- Around line 61-68: Remove prepareTransactionRequest from the SquidPublicClient
Pick in the SquidPublicClient type. Update any callers that require this wallet
action to use the appropriate wallet-client abstraction instead, while
preserving the remaining PublicClient methods.

---

Outside diff comments:
In `@src/execution.ts`:
- Around line 392-421: Preserve completed route metadata when a later leg fails:
add the proposed SquidPartialExecutionError type, then wrap each per-leg
execution flow after the first successful send in try/catch and rethrow this
error with the current routes and original error as cause when routes is
non-empty. Update all relevant failure paths, including “Squid route failed” and
the poll-limit failure, while leaving initial-leg errors unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c1d6a719-fbca-4c08-a1ca-3d88cff63191

📥 Commits

Reviewing files that changed from the base of the PR and between ad4c7f0 and 831c922.

📒 Files selected for processing (11)
  • README.md
  • package.json
  • scripts/pack-check.mjs
  • src/catalog.ts
  • src/execution.test.ts
  • src/execution.ts
  • src/index.test.ts
  • src/index.ts
  • src/planner.ts
  • src/squid.ts
  • src/types.ts
💤 Files with no reviewable changes (1)
  • scripts/pack-check.mjs

Comment thread src/planner.ts
Comment thread src/squid.ts
Comment thread src/types.ts
@snissn

snissn commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Review follow-up at ba3c5bb:

  • Fixed local-account preservation, moved transaction preparation to the wallet client, and added a regression assertion.
  • Added duplicate-requirement and single-destination validation before provider calls.
  • Kept request timeouts in the host-supplied fetch; Filecoin Pin already applies a 15-second timeout there.
  • Did not add a partial-execution error class or docstring scaffolding. The library remains stateless; the host owns recovery markers and rechecks destination balances before another attempt.

Local validation passes: lint, typecheck, 18 tests, build, package dry-run, and git diff --check.

@snissn

snissn commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba3c5bba20

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/squid.ts
@snissn
snissn merged commit b89293a into main Jul 31, 2026
4 checks passed
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