Skip to content

Commit 411e59e

Browse files
authored
feat: missing interfaces updated & updated previous ones (#36)
1 parent 7d77dc9 commit 411e59e

File tree

15 files changed

+343
-101
lines changed

15 files changed

+343
-101
lines changed

abis/Validator.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@
365365
{
366366
"name": "result",
367367
"type": "tuple",
368-
"internalType": "struct IValidator.ValidationResult",
368+
"internalType": "struct IFilecoinPayValidator.ValidationResult",
369369
"components": [
370370
{
371371
"name": "modifiedAmount",

script/utils/DeployUtils.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ contract DeployUtils is Script {
5151
}
5252

5353
function readLatestDeploymentArtifact() internal view returns (string memory json) {
54+
// forge-lint: disable-next-line(unsafe-cheatcode)
5455
json = vm.readFile(string.concat("./deployments/", network(), "/latest.json"));
5556
}
5657

src/Client.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,24 @@ import {VerifRegAPI} from "filecoin-solidity/v0.8/VerifRegAPI.sol";
1313
import {UtilsHandlers} from "filecoin-solidity/v0.8/utils/UtilsHandlers.sol";
1414
import {FilAddresses} from "filecoin-solidity/v0.8/utils/FilAddresses.sol";
1515
import {AllocationResponseCbor} from "./lib/AllocationResponseCbor.sol";
16-
import {PoRepMarket} from "./PoRepMarket.sol";
16+
import {IPoRepMarket} from "./interfaces/IPoRepMarket.sol";
17+
import {IClient} from "./interfaces/IClient.sol";
1718
import {PoRepTypes} from "./types/PoRepTypes.sol";
1819
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
1920
import {IMetaAllocator} from "./interfaces/IMetaAllocator.sol";
2021

2122
/**
2223
* @title Client
23-
* @notice Upgradeable contract for managing client allowances with role-based access control
24+
* @notice Contract for clients to interact with storage providers, manage deals, and handle DataCap transfers
2425
*/
25-
contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable, ReentrancyGuard {
26+
contract Client is IClient, Initializable, AccessControlUpgradeable, UUPSUpgradeable, ReentrancyGuard {
2627
using AllocationResponseCbor for DataCapTypes.TransferReturn;
2728

2829
// @custom:storage-location erc7201:porepmarket.storage.ClientStorage
2930
struct ClientStorage {
3031
mapping(uint256 dealId => Deal deal) _deals;
3132
mapping(uint64 claim => bool isTerminated) _terminatedClaims;
32-
PoRepMarket _poRepMarketContract;
33+
IPoRepMarket _poRepMarketContract;
3334
IMetaAllocator _metaAllocatorContract;
3435
}
3536

@@ -205,7 +206,7 @@ contract Client is Initializable, AccessControlUpgradeable, UUPSUpgradeable, Ree
205206
_grantRole(TERMINATION_ORACLE, terminationOracle);
206207

207208
ClientStorage storage $ = s();
208-
$._poRepMarketContract = PoRepMarket(_poRepMarketContract);
209+
$._poRepMarketContract = IPoRepMarket(_poRepMarketContract);
209210
$._metaAllocatorContract = IMetaAllocator(_metaAllocatorContract);
210211
}
211212

src/PoRepMarket.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
77
import {CommonTypes} from "filecoin-solidity/v0.8/types/CommonTypes.sol";
88
import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
99
import {ISPRegistry} from "./interfaces/ISPRegistry.sol";
10-
import {ValidatorFactory} from "./ValidatorFactory.sol";
10+
import {IValidatorFactory} from "./interfaces/IValidatorFactory.sol";
11+
import {IPoRepMarket} from "./interfaces/IPoRepMarket.sol";
1112
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
1213
import {SLITypes} from "./types/SLITypes.sol";
1314
import {PoRepTypes} from "./types/PoRepTypes.sol";
@@ -18,7 +19,7 @@ import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet
1819
* @dev PoRepMarket contract is a contract that allows users to create and manage deal proposals for PoRep deals
1920
* @notice PoRepMarket contract
2021
*/
21-
contract PoRepMarket is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
22+
contract PoRepMarket is IPoRepMarket, Initializable, AccessControlUpgradeable, UUPSUpgradeable {
2223
using EnumerableSet for EnumerableSet.UintSet;
2324
/**
2425
* @notice role to manage contract upgrades
@@ -39,7 +40,7 @@ contract PoRepMarket is Initializable, AccessControlUpgradeable, UUPSUpgradeable
3940
mapping(uint256 dealId => PoRepTypes.DealProposal) _dealProposals;
4041
EnumerableSet.UintSet _dealIdsReadyForPayment;
4142
ISPRegistry _SPRegistryContract;
42-
ValidatorFactory _validatorFactoryContract;
43+
IValidatorFactory _validatorFactoryContract;
4344
address _clientSmartContract;
4445
uint256 _dealIdCounter;
4546
}
@@ -187,7 +188,7 @@ contract PoRepMarket is Initializable, AccessControlUpgradeable, UUPSUpgradeable
187188
_grantRole(UPGRADER_ROLE, _admin);
188189

189190
DealProposalsStorage storage $ = s();
190-
$._validatorFactoryContract = ValidatorFactory(_validatorFactory);
191+
$._validatorFactoryContract = IValidatorFactory(_validatorFactory);
191192
$._SPRegistryContract = ISPRegistry(_spRegistry);
192193
}
193194

@@ -248,7 +249,7 @@ contract PoRepMarket is Initializable, AccessControlUpgradeable, UUPSUpgradeable
248249
}
249250

250251
/**
251-
* @notice Updates the validator and rail id for a deal proposal
252+
* @notice Updates the validator for a deal proposal
252253
* @param dealId The id of the deal proposal
253254
*/
254255
function updateValidator(uint256 dealId) external {

src/SLIOracle.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {SLITypes} from "./types/SLITypes.sol";
1111

1212
/**
1313
* @title SLI Oracle
14-
* @notice
14+
* @notice Contract for managing and retrieving SLI values for storage providers
1515
*/
1616
contract SLIOracle is ISLIOracle, Initializable, AccessControlUpgradeable, UUPSUpgradeable, MulticallUpgradeable {
1717
/**

src/Validator.sol

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1010
import {CommonTypes} from "filecoin-solidity/v0.8/types/CommonTypes.sol";
1111

1212
import {IFilecoinPayV1} from "./interfaces/IFilecoinPayV1.sol";
13-
import {IValidator} from "./interfaces/IValidator.sol";
13+
import {IFilecoinPayValidator} from "./interfaces/IFilecoinPayValidator.sol";
1414
import {ISLIScorer} from "./interfaces/ISLIScorer.sol";
1515
import {IPoRepMarket} from "./interfaces/IPoRepMarket.sol";
1616
import {ISPRegistry} from "./interfaces/ISPRegistry.sol";
17+
import {IClient} from "./interfaces/IClient.sol";
18+
import {IValidator} from "./interfaces/IValidator.sol";
1719
import {Operator} from "./abstracts/Operator.sol";
1820
import {PoRepTypes} from "./types/PoRepTypes.sol";
19-
import {Client} from "./Client.sol";
2021

2122
/**
2223
* @title Validator
2324
* @dev Implements validator and operator logic for managing Filecoin Pay rails
2425
* @notice Validator contract for Filecoin Pay
2526
*/
26-
contract Validator is Initializable, AccessControlUpgradeable, IValidator, Operator {
27+
contract Validator is Initializable, AccessControlUpgradeable, IFilecoinPayValidator, IValidator, Operator {
2728
/**
2829
* @notice Error indicating that the caller is not the FilecoinPay contract
2930
*/
@@ -311,7 +312,8 @@ contract Validator is Initializable, AccessControlUpgradeable, IValidator, Opera
311312
*/
312313
function validatePayment(uint256 railId, uint256 proposedAmount, uint256 fromEpoch, uint256 toEpoch, uint256 rate)
313314
external
314-
returns (IValidator.ValidationResult memory result)
315+
override
316+
returns (ValidationResult memory result)
315317
{
316318
ValidatorStorage storage $ = _getValidatorStorage();
317319
if (msg.sender != $.filecoinPay) {
@@ -341,7 +343,7 @@ contract Validator is Initializable, AccessControlUpgradeable, IValidator, Opera
341343
uint256 score = ISLIScorer($.SLIScorer).calculateScore($.providerId, dealProposal.requirements);
342344

343345
bool scoreMatches = score == 100;
344-
bool dataSizeMatches = Client($.clientSC).isDataSizeMatching($.dealId);
346+
bool dataSizeMatches = IClient($.clientSC).isDataSizeMatching($.dealId);
345347

346348
if (!scoreMatches || !dataSizeMatches) {
347349
result.settleUpto = toEpoch;
@@ -571,7 +573,7 @@ contract Validator is Initializable, AccessControlUpgradeable, IValidator, Opera
571573
ValidatorStorage storage $ = _getValidatorStorage();
572574

573575
PoRepTypes.DealProposal memory dealProposal = IPoRepMarket($.poRepMarket).getDealProposal($.dealId);
574-
CommonTypes.FilActorId[] memory allocationIds = Client($.clientSC).getClientAllocationIdsPerDeal($.dealId);
576+
CommonTypes.FilActorId[] memory allocationIds = IClient($.clientSC).getClientAllocationIdsPerDeal($.dealId);
575577

576578
uint256 sectorCount = allocationIds.length;
577579
uint256 pricePerSectorPerMonth = dealProposal.terms.pricePerSectorPerMonth;

src/ValidatorFactory.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import {BeaconProxy} from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"
99
import {Validator} from "./Validator.sol";
1010
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
1111
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
12-
import {PoRepMarket} from "./PoRepMarket.sol";
12+
import {IPoRepMarket} from "./interfaces/IPoRepMarket.sol";
13+
import {IValidatorFactory} from "./interfaces/IValidatorFactory.sol";
1314
import {PoRepTypes} from "./types/PoRepTypes.sol";
1415

1516
/**
1617
* @title ValidatorFactory
1718
* @notice Beacon factory contract for creating Validator instances
1819
*/
19-
contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
20+
contract ValidatorFactory is IValidatorFactory, UUPSUpgradeable, AccessControlUpgradeable {
2021
/**
2122
* @notice Upgradable role which allows for contract upgrades
2223
*/
@@ -159,7 +160,7 @@ contract ValidatorFactory is UUPSUpgradeable, AccessControlUpgradeable {
159160
ValidatorFactoryStorage storage $ = s();
160161
if ($._instances[dealId] != address(0)) revert InstanceAlreadyExists();
161162

162-
PoRepTypes.DealProposal memory dp = PoRepMarket($._poRepMarket).getDealProposal(dealId);
163+
PoRepTypes.DealProposal memory dp = IPoRepMarket($._poRepMarket).getDealProposal(dealId);
163164
if (msg.sender != dp.client) revert InvalidClientAddress();
164165

165166
bytes memory initCode = abi.encodePacked(

src/abstracts/Operator.sol

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,14 @@ pragma solidity =0.8.30;
33

44
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
55
import {IFilecoinPayV1} from "../interfaces/IFilecoinPayV1.sol";
6+
import {IOperator} from "../interfaces/IOperator.sol";
67

78
/**
89
* @title Operator abstract contract
910
* @notice Abstract contract defining operator functions for creating and managing payment rails in the FilecoinPayV1 system.
1011
* This contract provides internal helper functions for interacting with the FilecoinPayV1 interface, while leaving the implementation of the external functions to derived contracts.
1112
*/
12-
abstract contract Operator {
13-
/**
14-
* @notice Creates a payment rail
15-
* @param token The ERC20 token to use for the payment rail
16-
*/
17-
function createRail(IERC20 token) external virtual;
18-
19-
/**
20-
* @notice Updates the lockup period of a payment rail
21-
* @param railId ID of the payment rail
22-
* @param newLockupPeriod New lockup period to set
23-
*/
24-
function updateLockupPeriod(uint256 railId, uint256 newLockupPeriod) external virtual;
25-
26-
/**
27-
* @notice Modifies the payment rate and optionally makes a one-time payment.
28-
* @param railId The ID of the rail to modify.
29-
*/
30-
function modifyRailPayment(uint256 railId) external virtual;
31-
32-
/**
33-
* @notice Terminates a payment rail, preventing further payments after the rail's lockup period. After calling this method, the lockup period cannot be changed, and the rail's rate and fixed lockup may only be reduced.
34-
* @param railId The ID of the rail to terminate.
35-
*/
36-
function terminateRail(uint256 railId) external virtual;
37-
13+
abstract contract Operator is IOperator {
3814
/**
3915
* @notice Internal function to create a payment rail
4016
* @param filecoinPay The FilecoinPayV1 interface

src/interfaces/IClient.sol

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-License-Identifier: MIT
2+
// solhint-disable func-name-mixedcase
3+
4+
pragma solidity =0.8.30;
5+
6+
import {CommonTypes} from "filecoin-solidity/v0.8/types/CommonTypes.sol";
7+
import {DataCapTypes} from "filecoin-solidity/v0.8/types/DataCapTypes.sol";
8+
9+
/**
10+
* @title IClient
11+
* @notice Interface for client interactions with storage providers
12+
*/
13+
interface IClient {
14+
/**
15+
* @notice This function transfers DataCap tokens from the client to the storage provider
16+
* @dev This function can only be called by the client
17+
* @param params The parameters for the transfer
18+
* @param dealId The id of the deal
19+
* @param dealCompleted Whether the deal is completed
20+
*/
21+
function transfer(DataCapTypes.TransferParams calldata params, uint256 dealId, bool dealCompleted) external;
22+
23+
/**
24+
* @notice The handle_filecoin_method function is a universal entry point for calls
25+
* coming from built-in Filecoin actors. Datacap is an FRC-46 Token. Receiving FRC46
26+
* tokens requires implementing a Receiver Hook:
27+
* https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0046.md#receiver-hook.
28+
* We use handle_filecoin_method to handle the receiver hook and make sure that the token
29+
* sent to our contract is freshly minted Datacap and reject all other calls and transfers.
30+
* @param method Method number
31+
* @param inputCodec Codec of the payload
32+
* @param params Params of the call
33+
* @return exitCode The exit code of the operation
34+
* @return codec The codec used for the response
35+
* @return data The response data
36+
* @dev Reverts if trying to send a unsupported token type
37+
* @dev Reverts if trying to receive invalid token
38+
*/
39+
function handle_filecoin_method(uint64 method, uint64 inputCodec, bytes calldata params)
40+
external
41+
view
42+
returns (uint32 exitCode, uint64 codec, bytes memory data);
43+
44+
/**
45+
* @notice custom getter to retrieve allocation ids per client and provider
46+
* @param dealId the id of the deal
47+
* @return allocationIds the allocation ids for the client and provider
48+
*/
49+
function getClientAllocationIdsPerDeal(uint256 dealId) external view returns (CommonTypes.FilActorId[] memory);
50+
51+
/**
52+
* @notice custom getter to check if claim is terminated
53+
* @param claimId the id of the claim
54+
* @return isTerminated whether the claim is terminated
55+
*/
56+
function terminatedClaims(uint64 claimId) external view returns (bool);
57+
58+
/**
59+
* @notice Checks if the total active data size for the client with the specified provider matches the expected size
60+
* @dev This function can only be called by the validator of the deal
61+
* @param dealId The id of the deal
62+
* @return totalSizePerSp The total active data size for the client with the specified provider
63+
*/
64+
function isDataSizeMatching(uint256 dealId) external returns (bool);
65+
66+
/**
67+
* @notice Marks the given claims as terminated early.
68+
* @dev Only callable by TERMINATION_ORACLE role.
69+
* @param claims An array of claim IDs to mark as terminated.
70+
*/
71+
function claimsTerminatedEarly(uint64[] calldata claims) external;
72+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity =0.8.30;
3+
4+
/**
5+
* @title Interface for Filecoin Pay Validator
6+
* @notice Defines the interface for payment validation in Filecoin Pay rails
7+
*/
8+
interface IFilecoinPayValidator {
9+
/**
10+
* @notice Result structure for validation during rail settlement
11+
* @param modifiedAmount The actual payment amount determined by the validator after validation of a rail during settlement
12+
* @param settleUpto The epoch up to and including which settlement should occur
13+
* @param note A placeholder note for any additional information the validator wants to send to the caller of `settleRail`
14+
*/
15+
struct ValidationResult {
16+
// The actual payment amount determined by the validator after validation of a rail during settlement
17+
uint256 modifiedAmount;
18+
// The epoch up to and including which settlement should occur.
19+
uint256 settleUpto;
20+
// A placeholder note for any additional information the validator wants to send to the caller of `settleRail`
21+
string note;
22+
}
23+
24+
/**
25+
* @notice Validates a proposed payment amount for a payment rail
26+
* @param railId ID of the payment rail
27+
* @param proposedAmount Proposed payment amount to validate
28+
* @param fromEpoch The epoch up to and including which the rail has already been settled
29+
* @param toEpoch The epoch up to and including which validation is requested; payment will be validated for (toEpoch - fromEpoch) epochs
30+
* @param rate Rate used for payment calculation
31+
* @return result ValidationResult struct containing validation outcome
32+
*/
33+
function validatePayment(
34+
uint256 railId,
35+
uint256 proposedAmount,
36+
// the epoch up to and including which the rail has already been settled
37+
uint256 fromEpoch,
38+
// the epoch up to and including which validation is requested; payment will be validated for (toEpoch - fromEpoch) epochs
39+
uint256 toEpoch,
40+
uint256 rate
41+
) external returns (ValidationResult memory result);
42+
43+
/**
44+
* @notice Invoked when a payment rail is terminated
45+
* @param railId The ID of the terminated rail
46+
* @param terminator Address that initiated the termination
47+
* @param endEpoch Filecoin epoch at which the rail was terminated
48+
*/
49+
function railTerminated(uint256 railId, address terminator, uint256 endEpoch) external;
50+
}

0 commit comments

Comments
 (0)