Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/core/payments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Comprehensive payment rail management for Filecoin Pay:
- **Token Operations**: ERC20 approve/deposit patterns
- **Service Approvals**: Storage operator authorization
- **Capacity Calculations**: Human-friendly storage unit conversions
- **Funding Planner**: Build and execute Filecoin Pay funding plans for runway or fixed deposits

## Filecoin Pin Use Examples

Expand Down Expand Up @@ -97,7 +98,9 @@ console.log(`Download URL: ${result.providerInfo?.downloadURL}`)
```typescript
import {
calculateStorageAllowances,
executeFilecoinPayFunding,
depositUSDFC,
planFilecoinPayFunding,
setServiceApprovals,
} from 'filecoin-pin/core/payments'
import { ethers } from 'ethers'
Expand All @@ -117,4 +120,18 @@ const txHash = await setServiceApprovals(
allowances.rateAllowance,
allowances.lockupAllowance
)

// Plan and execute a Filecoin Pay top-up for 30 days of runway
const { plan } = await planFilecoinPayFunding({
synapse,
targetRunwayDays: 30,
ensureAllowances: true, // also sets WarmStorage allowances
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ensureAllowances: true, // also sets WarmStorage allowances
ensureAllowances: true, // also checks and sets WarmStorage allowances

I feel like there should be a stronger recommendation to always use this, could even be an opt-out instead of opt-in, but I'll leave it to you

Copy link
Member

Choose a reason for hiding this comment

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

Although .. depositUSDFC does it for you automatically, so maybe this is not even needed as an option here, we just do it by default anyway?

You might want to look through the flow in there and where it's called from your code in here to see if you're not doing too many calls. Probably not a big deal but also might be some flow optimisation that can be done.

})

if (plan.delta > 0n) {
const execution = await executeFilecoinPayFunding(synapse, plan)
console.log(`Deposited ${execution.delta} wei USDFC for ~${execution.newRunwayDays} day(s) runway`)
} else {
console.log('No additional funding required')
}
```
Loading