Skip to content

feat: add filecoin pay funding planner#286

Merged
SgtPooki merged 6 commits intomasterfrom
feat/export-autoFund-function
Jan 15, 2026
Merged

feat: add filecoin pay funding planner#286
SgtPooki merged 6 commits intomasterfrom
feat/export-autoFund-function

Conversation

@SgtPooki
Copy link
Copy Markdown
Collaborator

@SgtPooki SgtPooki commented Dec 9, 2025

Summary

Expose Filecoin Pay funding logic as a reusable core API, refactor CLI funding to use it, and add coverage/docs. Remove legacy top-up calc in favor of the new planner.

What Changed

  • Added planFilecoinPayFunding, executeFilecoinPayFunding, and getFilecoinPayFundingInsights in src/core/payments/funding.ts, exported via core/payments.
  • Updated funding types (FilecoinPayFundingPlan/Execution/Insights, options) and refactored payments fund / auto-fund to consume the new API.
  • Documented the planner/executor in src/core/payments/README.md with usage examples.
  • Added unit tests for the planner (wallet shortfall, minimum/no-withdraw, zero-spend) and executor deposit path.

Removal

  • Removed calculateRequiredTopUp/formatTopUpReason path to avoid duplication; callers should use planFilecoinPayFunding + executeFilecoinPayFunding.

@SgtPooki SgtPooki requested a review from Copilot December 9, 2025 03:31
@FilOzzy FilOzzy added team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board. labels Dec 9, 2025
@SgtPooki SgtPooki self-assigned this Dec 9, 2025
@FilOzzy FilOzzy added this to FOC Dec 9, 2025
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Dec 9, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a comprehensive Filecoin Pay funding planner API that consolidates and improves upon the legacy top-up calculation logic. The new API provides a cleaner separation between planning (calculation) and execution phases, with detailed insights about current and projected funding states.

Key changes:

  • Added planFilecoinPayFunding, executeFilecoinPayFunding, and getFilecoinPayFundingInsights as the new core funding APIs
  • Removed legacy calculateRequiredTopUp and formatTopUpReason functions to eliminate duplication
  • Refactored CLI payments fund and auto-fund commands to use the new planner
  • Added comprehensive unit tests covering wallet shortfall detection, minimum mode, and zero-spend scenarios

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/core/payments/funding.ts New file introducing the funding planner with calculation, planning, and execution functions
src/core/payments/types.ts Added new types (FundingMode, FundingReasonCode, FilecoinPayFundingPlan, etc.) and updated documentation for existing types
src/core/payments/index.ts Exports new funding module (export * from './funding.js')
src/core/payments/top-up.ts Removed calculateRequiredTopUp and formatTopUpReason, kept executeTopUp for backward compatibility
src/core/payments/README.md Added documentation and usage examples for the new funding planner API
src/payments/types.ts Updated to re-export FundingMode from core, replaced deprecated FundMode type
src/payments/fund.ts Refactored to use planFilecoinPayFunding and executeFilecoinPayFunding, but contains a critical bug with parameter passing
upload-action/src/filecoin.js Migrated to use calculateFilecoinPayFundingPlan and formatFundingReason
upload-action/package-lock.json Version bump from 0.13.0 to 0.14.0 reflecting the minor version change
src/test/unit/payments-funding.test.ts New comprehensive unit tests for the funding planner functions
Files not reviewed (1)
  • upload-action/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/payments/funding.ts
Comment thread src/payments/fund.ts Outdated
Comment thread src/test/unit/payments-funding.test.ts
Comment thread src/payments/fund.ts Outdated
Comment thread src/core/payments/funding.ts Outdated
Comment thread src/core/payments/funding.ts
Comment thread src/core/payments/funding.ts Outdated
@SgtPooki SgtPooki requested a review from rvagg December 9, 2025 03:57
@SgtPooki SgtPooki marked this pull request as ready for review December 9, 2025 03:57
Comment thread src/core/payments/README.md Outdated
Comment thread src/core/payments/funding.ts Outdated
Comment thread src/core/payments/funding.ts Outdated
Comment thread src/core/payments/funding.ts Outdated
Copy link
Copy Markdown
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

I guess this is OK, I haven't reviewed it all in depth, if it works in practice I'll take your word for it!

@github-project-automation github-project-automation Bot moved this from 📌 Triage to ✔️ Approved by reviewer in FOC Dec 10, 2025
@rjan90
Copy link
Copy Markdown
Collaborator

rjan90 commented Jan 5, 2026

@SgtPooki Is this good to merge now? Or is there other work that you want landed first?

Co-authored-by: Rod Vagg <rod@vagg.org>
@BigLep BigLep added this to the M4: Filecoin Service Liftoff milestone Jan 15, 2026
@SgtPooki
Copy link
Copy Markdown
Collaborator Author

@rjan90 this is ready to merge once all tests pass here.

@SgtPooki SgtPooki merged commit f22a6c6 into master Jan 15, 2026
12 checks passed
@SgtPooki SgtPooki deleted the feat/export-autoFund-function branch January 15, 2026 16:07
@github-project-automation github-project-automation Bot moved this from ✔️ Approved by reviewer to 🎉 Done in FOC Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team/filecoin-pin "Filecoin Pin" project is a stakeholder for this work. team/fs-wg FOC working group is a stakeholder for this work, and thus wants to track it on their project board.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants