Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5c63bc9
feat: add OpenZeppelin upgradeable contracts dependencies
pyropy Sep 29, 2025
7b15d0e
feat: add FilBeam contract infrastructure
pyropy Sep 29, 2025
d9ea814
feat: implement upgradeable FilBeam contract
pyropy Sep 29, 2025
0b5b4e3
test: add comprehensive FilBeam test suite
pyropy Sep 29, 2025
7b83b93
feat: add deployment script with USDFC integration
pyropy Sep 29, 2025
4f61629
chore: remove unused Counter contract files
pyropy Sep 29, 2025
d6e3eb6
docs: add project specification and update documentation
pyropy Sep 29, 2025
c1e64ed
feat: add batch usage reporting with reportUsageRollupBatch method
pyropy Sep 29, 2025
733c495
feat: add decimal pricing support for deployment script
pyropy Sep 29, 2025
9ea164a
feat: add batch settlement methods for payment rails
pyropy Sep 29, 2025
dd81176
docs: add comprehensive deployment guide and API documentation
pyropy Sep 29, 2025
7f97814
refactor: simplify epoch validation using maxReportedEpoch only
pyropy Sep 29, 2025
2bfb0ab
feat: add filBeamController role for access control
pyropy Sep 30, 2025
b460676
refactor: remove upgradeable pattern and use direct deployment
pyropy Sep 30, 2025
b27c24a
feat: add setFilBeamController method for updating authorized controller
pyropy Sep 30, 2025
567bc87
refactor: make deployer the default owner, remove initialOwner parameter
pyropy Sep 30, 2025
94baf6f
docs: update README with FILBEAM_CONTROLLER and remove proxy references
pyropy Sep 30, 2025
0692c8a
refactor: use InvalidAddress error for zero address validations
pyropy Sep 30, 2025
2ab1bba
Remove OpenZeppelin/openzeppelin-contracts-upgradeable
pyropy Sep 30, 2025
50b3bd9
refactor: improve FilBeam contract with gas optimizations and enhance…
pyropy Sep 30, 2025
b6c7244
Update AGENTS.md
pyropy Sep 30, 2025
e8ba6ab
docs: update README and SPEC to match current contract API
pyropy Oct 1, 2025
c2028ce
chore: Do not validate data set in terminateCDNPaymentRails
pyropy Oct 1, 2025
f2e6e51
chore: Cleanup docs and fix deployment example
pyropy Oct 1, 2025
98f47cd
fix: move last settlement epoch assignment after settlement
pyropy Oct 1, 2025
69814c0
refactor: rename FilBeam to FilBeamOperator and update parameter names
pyropy Oct 7, 2025
7ec4fb6
refactor: rename settleCDNPaymentRails to settleFilBeamPaymentRails
pyropy Oct 7, 2025
1f34058
refactor: remove single operation methods, use batch-only API
pyropy Oct 7, 2025
71db784
refactor: rename batch methods to use plural form
pyropy Oct 7, 2025
5d28a4d
refactor: renamed variable filBeamController to filBeamOperatorContro…
pyropy Oct 7, 2025
e87edf9
feat: read USDFC address from FWSS contract in deployment script
pyropy Oct 7, 2025
ac6abe5
chore: Update README.md deployment example
pyropy Oct 7, 2025
2c6c242
refactor: rename setFilBeamController to setFilBeamOperatorController
pyropy Oct 7, 2025
eed86bc
feat: calculate settlement amounts at report time instead of settlem…
pyropy Oct 7, 2025
7f5870e
chore: update readme
pyropy Oct 7, 2025
8cd48ab
chore: add methods docs
pyropy Oct 8, 2025
ca5b0cb
refactor: make CDN and cache miss rates immutable
pyropy Oct 10, 2025
cdcc16c
refactor: make settlement methods non-reverting for better UX
pyropy Oct 10, 2025
745e157
feat: refactor payment rail settlements for partial payments and simp…
pyropy Oct 10, 2025
7bf5726
refactor: save fwss and payments address
pyropy Oct 10, 2025
e35cb62
chore: update deployment example
pyropy Oct 13, 2025
7ffb6c9
chore: add toEpoch to UsageReported and rename epoch to toEpoch
pyropy Oct 14, 2025
28dbd65
chore: update UsageReported event signature in SPEC.md
pyropy Oct 14, 2025
86cd989
refactor: report usage up to single epoch for all data sets
pyropy Oct 15, 2025
1d74f6b
chore: forge fmt
pyropy Oct 15, 2025
014498d
Update script/DeployFilBeamOperator.s.sol
pyropy Oct 17, 2025
1e5f146
refactor: unify payment rail settlement into one internal method
pyropy Oct 23, 2025
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
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts-upgradeable"]
path = lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Bash commands
- `forge fmt`: Format the project
- `forge test`: Test the project
- `forge install`: Install dependencies

# Workflow
- Make sure to run `forge fmt` when you're done making a series of test changes
Expand Down
192 changes: 180 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
## Foundry
# FilBeam Contract

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
FilBeam is an upgradeable smart contract for managing CDN and cache-miss usage-based payments in the Filecoin ecosystem. It provides batch processing capabilities and flexible decimal pricing support.

## Features

Foundry consists of:
- **Usage Reporting**: Single and batch methods for reporting CDN and cache-miss usage
- **Rail Settlements**: Independent settlement for CDN and cache-miss payment rails
- **Upgradeable**: UUPS proxy pattern for contract upgrades

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
## Built with Foundry

## Documentation
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

https://book.getfoundry.sh/
Documentation: https://book.getfoundry.sh/

## Usage

Expand Down Expand Up @@ -45,12 +46,179 @@ $ forge snapshot
$ anvil
```

### Deploy
### Deploy FilBeam Contract

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
The FilBeam contract can be deployed using the provided deployment script with flexible pricing configuration.

#### Environment Variables

Set the following environment variables before deployment:

```bash
export PRIVATE_KEY="0x1234..." # Deployer's private key
export FWSS_ADDRESS="0xabc..." # FWSS contract address
export USDFC_ADDRESS="0xdef..." # USDFC token contract address
export CDN_PRICE_USD_PER_TIB="1250" # CDN price (scaled by PRICE_DECIMALS)
export CACHE_MISS_PRICE_USD_PER_TIB="1575" # Cache miss price (scaled by PRICE_DECIMALS)
export PRICE_DECIMALS="2" # Number of decimal places (2 = cents precision)
```

#### Deployment Examples

**Example 1: Decimal Pricing ($12.50 CDN, $15.75 Cache Miss)**
```bash
PRIVATE_KEY=0x1234... \
FWSS_ADDRESS=0xabc... \
USDFC_ADDRESS=0xdef... \
CDN_PRICE_USD_PER_TIB=1250 \
CACHE_MISS_PRICE_USD_PER_TIB=1575 \
PRICE_DECIMALS=2 \
forge script script/DeployFilBeam.s.sol:DeployFilBeam --rpc-url <your_rpc_url> --broadcast
```

**Example 2: Whole Dollar Pricing ($10 CDN, $15 Cache Miss)**
```bash
PRIVATE_KEY=0x1234... \
FWSS_ADDRESS=0xabc... \
USDFC_ADDRESS=0xdef... \
CDN_PRICE_USD_PER_TIB=10 \
CACHE_MISS_PRICE_USD_PER_TIB=15 \
PRICE_DECIMALS=0 \
forge script script/DeployFilBeam.s.sol:DeployFilBeam --rpc-url <your_rpc_url> --broadcast
```

**Example 3: High Precision Pricing ($9.995 CDN, $12.750 Cache Miss)**
```bash
PRIVATE_KEY=0x1234... \
FWSS_ADDRESS=0xabc... \
USDFC_ADDRESS=0xdef... \
CDN_PRICE_USD_PER_TIB=9995 \
CACHE_MISS_PRICE_USD_PER_TIB=12750 \
PRICE_DECIMALS=3 \
forge script script/DeployFilBeam.s.sol:DeployFilBeam --rpc-url <your_rpc_url> --broadcast
```

#### Pricing Configuration Guide

| Desired Price | CDN_PRICE_USD_PER_TIB | PRICE_DECIMALS | Result |
|---------------|----------------------|----------------|---------|
| $10.00/TiB | 10 | 0 | $10.00 |
| $12.50/TiB | 1250 | 2 | $12.50 |
| $9.99/TiB | 999 | 2 | $9.99 |
| $15.750/TiB | 15750 | 3 | $15.750 |
| $7.5/TiB | 75 | 1 | $7.5 |

#### Deployment Output

The deployment script provides detailed information about the deployed contracts:

```
=== FilBeam Deployment Complete ===
Implementation deployed at: 0x123...
Proxy deployed at: 0x456...
FilBeam contract available at: 0x456...

=== Configuration ===
FWSS Address: 0xabc...
USDFC Address: 0xdef...
USDFC Decimals: 6
Price Decimals: 2
Owner: 0x789...

=== Pricing ===
CDN Price (scaled input): 1250
CDN Rate (USDFC per byte): 11368
Cache Miss Price (scaled input): 1575
Cache Miss Rate (USDFC per byte): 14324

=== Actual USD Prices ===
CDN: scaled 1250 with 2 decimals
Cache Miss: scaled 1575 with 2 decimals
```

## Contract API

### Usage Reporting

**Single Report**
```solidity
function reportUsageRollup(
uint256 dataSetId,
uint256 newEpoch,
int256 cdnBytesUsed,
int256 cacheMissBytesUsed
) external onlyOwner
```

**Batch Reports**
```solidity
function reportUsageRollupBatch(
uint256[] calldata dataSetIds,
uint256[] calldata epochs,
int256[] calldata cdnBytesUsed,
int256[] calldata cacheMissBytesUsed
) external onlyOwner
```

### Settlement Operations

**Single Settlement**
```solidity
function settleCDNPaymentRail(uint256 dataSetId) external
function settleCacheMissPaymentRail(uint256 dataSetId) external
```

**Batch Settlement**
```solidity
function settleCDNPaymentRailBatch(uint256[] calldata dataSetIds) external
function settleCacheMissPaymentRailBatch(uint256[] calldata dataSetIds) external
```

### Data Set Management

**Payment Rail Termination**
```solidity
function terminateCDNPaymentRails(uint256 dataSetId) external onlyOwner
```

### Contract Management

**Ownership & Upgrades**
```solidity
function transferOwnership(address newOwner) external onlyOwner
function upgradeToAndCall(address newImplementation, bytes memory data) external onlyOwner
```
### View Functions

**Dataset Information**
```solidity
function getDataSetUsage(uint256 dataSetId) external view returns (
uint256 cdnBytesUsed,
uint256 cacheMissBytesUsed,
uint256 maxReportedEpoch,
uint256 lastCDNSettlementEpoch,
uint256 lastCacheMissSettlementEpoch,
bool isInitialized
)
```

## Key Concepts

### Batch Operations
- **Gas Efficient**: Reduce transaction costs for bulk operations
- **Atomic**: All operations in a batch succeed or all fail
- **Independent Rails**: CDN and cache-miss settlements operate independently

### Pricing Model
- **Rate-Based**: Usage calculated as `bytes * rate_per_byte`
- **Decimal Support**: Flexible pricing with configurable decimal precision
- **Token Agnostic**: Works with any ERC20 token (USDFC assumed)

### Rail Settlement
- **Independent Tracking**: CDN and cache-miss settlements tracked separately
- **Epoch-Based**: Settlement periods defined by epoch ranges
- **Accumulative**: Usage accumulates between settlements

### Cast

```shell
Expand Down
Loading