Skip to content
Merged
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
6 changes: 3 additions & 3 deletions abis/PoRepMarket.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"internalType": "uint256"
},
{
"name": "pricePerSector",
"name": "pricePerSectorPerMonth",
"type": "uint256",
"internalType": "uint256"
},
Expand Down Expand Up @@ -255,7 +255,7 @@
"internalType": "uint256"
},
{
"name": "pricePerSector",
"name": "pricePerSectorPerMonth",
"type": "uint256",
"internalType": "uint256"
},
Expand Down Expand Up @@ -436,7 +436,7 @@
"internalType": "uint256"
},
{
"name": "pricePerSector",
"name": "pricePerSectorPerMonth",
"type": "uint256",
"internalType": "uint256"
},
Expand Down
8 changes: 4 additions & 4 deletions abis/SPRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
"internalType": "uint256"
},
{
"name": "pricePerSector",
"name": "pricePerSectorPerMonth",
"type": "uint256",
"internalType": "uint256"
},
Expand Down Expand Up @@ -310,7 +310,7 @@
"internalType": "uint256"
},
{
"name": "pricePerSector",
"name": "pricePerSectorPerMonth",
"type": "uint256",
"internalType": "uint256"
}
Expand Down Expand Up @@ -567,7 +567,7 @@
"internalType": "uint256"
},
{
"name": "pricePerSector",
"name": "pricePerSectorPerMonth",
"type": "uint256",
"internalType": "uint256"
},
Expand Down Expand Up @@ -720,7 +720,7 @@
"internalType": "CommonTypes.FilActorId"
},
{
"name": "pricePerSector",
"name": "pricePerSectorPerMonth",
"type": "uint256",
"internalType": "uint256"
}
Expand Down
5 changes: 0 additions & 5 deletions abis/Validator.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,6 @@
"name": "InvalidClientSCAddress",
"inputs": []
},
{
"type": "error",
"name": "InvalidDealDuration",
"inputs": []
},
{
"type": "error",
"name": "InvalidDealId",
Expand Down
24 changes: 12 additions & 12 deletions src/SPRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract SPRegistry is Initializable, AccessControlUpgradeable, UUPSUpgradeable,
uint256 availableBytes;
uint256 committedBytes;
uint256 pendingBytes;
uint256 pricePerSector;
uint256 pricePerSectorPerMonth;
}

/// @custom:storage-location erc7201:porepmarket.storage.SPRegistryStorage
Expand Down Expand Up @@ -312,17 +312,17 @@ contract SPRegistry is Initializable, AccessControlUpgradeable, UUPSUpgradeable,
}

/// @inheritdoc ISPRegistry
function setPrice(CommonTypes.FilActorId provider, uint256 pricePerSector) external {
function setPrice(CommonTypes.FilActorId provider, uint256 pricePerSectorPerMonth) external {
_ensureProviderRegistered(provider);
_ensureProviderNotBlocked(provider);
_onlyProviderControllerOrAdmin(provider);

SPRegistryStorage storage $ = _getSPRegistryStorage();
uint64 id = CommonTypes.FilActorId.unwrap(provider);
uint256 oldPrice = $._providers[id].pricePerSector;
$._providers[id].pricePerSector = pricePerSector;
uint256 oldPrice = $._providers[id].pricePerSectorPerMonth;
$._providers[id].pricePerSectorPerMonth = pricePerSectorPerMonth;

emit PriceUpdated(provider, oldPrice, pricePerSector);
emit PriceUpdated(provider, oldPrice, pricePerSectorPerMonth);
}

/// @inheritdoc ISPRegistry
Expand Down Expand Up @@ -366,7 +366,7 @@ contract SPRegistry is Initializable, AccessControlUpgradeable, UUPSUpgradeable,
availableBytes: p.availableBytes,
committedBytes: p.committedBytes,
pendingBytes: p.pendingBytes,
pricePerSector: p.pricePerSector
pricePerSectorPerMonth: p.pricePerSectorPerMonth
});
}

Expand Down Expand Up @@ -421,7 +421,7 @@ contract SPRegistry is Initializable, AccessControlUpgradeable, UUPSUpgradeable,
if (p.committedBytes < lowestCommitted) {
lowestCommitted = p.committedBytes;
bestProvider = CommonTypes.FilActorId.wrap(id);
bestProviderPrice = p.pricePerSector;
bestProviderPrice = p.pricePerSectorPerMonth;
if (lowestCommitted == 0) break;
}
}
Expand All @@ -434,7 +434,7 @@ contract SPRegistry is Initializable, AccessControlUpgradeable, UUPSUpgradeable,

// solhint-disable gas-strict-inequalities
bool autoApprove = bestProviderPrice > 0 && CommonTypes.FilActorId.unwrap(bestProvider) != 0
&& terms.pricePerSector >= bestProviderPrice;
&& terms.pricePerSectorPerMonth >= bestProviderPrice;
// solhint-enable gas-strict-inequalities

return (bestProvider, autoApprove);
Expand Down Expand Up @@ -524,15 +524,15 @@ contract SPRegistry is Initializable, AccessControlUpgradeable, UUPSUpgradeable,
* @param organization The address of the provider's organization
* @param capabilities The SLI thresholds this provider guarantees
* @param availableBytes The provider's available storage capacity
* @param pricePerSector The provider's auto-approve price per sector (0 to skip)
* @param pricePerSectorPerMonth The provider's auto-approve price per sector per month (0 to skip)
* @param payee The payment recipient address (address(0) defaults to organization)
*/
function registerProviderFor(
CommonTypes.FilActorId provider,
address organization,
SLITypes.SLIThresholds calldata capabilities,
uint256 availableBytes,
uint256 pricePerSector,
uint256 pricePerSectorPerMonth,
address payee
) external {
_onlyAdminOrOperator();
Expand All @@ -546,11 +546,11 @@ contract SPRegistry is Initializable, AccessControlUpgradeable, UUPSUpgradeable,
uint64 id = CommonTypes.FilActorId.unwrap(provider);
$._providers[id].capabilities = capabilities;
$._providers[id].availableBytes = availableBytes;
$._providers[id].pricePerSector = pricePerSector;
$._providers[id].pricePerSectorPerMonth = pricePerSectorPerMonth;

emit CapabilitiesUpdated(provider, capabilities);
emit AvailableSpaceUpdated(provider, availableBytes);
emit PriceUpdated(provider, 0, pricePerSector);
emit PriceUpdated(provider, 0, pricePerSectorPerMonth);
}

/// @inheritdoc ISPRegistry
Expand Down
20 changes: 2 additions & 18 deletions src/Validator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ contract Validator is Initializable, AccessControlUpgradeable, IValidator, Opera
*/
error InvalidSectorCount();

/**
* @notice Error indicating that the duration of the deal is zero, which is invalid
*/
error InvalidDealDuration();

/**
* @notice Error indicating that the caller is not authorized to perform the action
*/
Expand Down Expand Up @@ -230,11 +225,6 @@ contract Validator is Initializable, AccessControlUpgradeable, IValidator, Opera
* @dev 365 days * 24 hours/day * 60 minutes/hour * 2 epochs/minute = 1_051_200 epochs
*/
uint256 private constant EPOCHS_IN_YEAR = 1_051_200;
/**
* @notice Number of epochs in one day
* @dev 24 hours/day * 60 minutes/hour * 2 epochs/minute = 2_880 epochs
*/
uint256 private constant EPOCHS_IN_DAY = 2_880;

/**
* @notice Storage location for ValidatorStorage struct
Expand Down Expand Up @@ -584,19 +574,13 @@ contract Validator is Initializable, AccessControlUpgradeable, IValidator, Opera
CommonTypes.FilActorId[] memory allocationIds = Client($.clientSC).getClientAllocationIdsPerDeal($.dealId);

uint256 sectorCount = allocationIds.length;
uint256 pricePerSector = dealProposal.terms.pricePerSector;
uint32 durationDays = dealProposal.terms.durationDays;
uint256 pricePerSectorPerMonth = dealProposal.terms.pricePerSectorPerMonth;

if (sectorCount == 0) {
revert InvalidSectorCount();
}

if (durationDays == 0) {
revert InvalidDealDuration();
}

uint256 totalEpochs = durationDays * EPOCHS_IN_DAY;
uint256 amount = (pricePerSector * sectorCount) / totalEpochs;
uint256 amount = (pricePerSectorPerMonth * sectorCount) / EPOCHS_IN_MONTH;

if (amount == 0) {
revert InvalidZeroAmount();
Expand Down
10 changes: 5 additions & 5 deletions src/interfaces/ISPRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ interface ISPRegistry {
uint256 availableBytes;
uint256 committedBytes;
uint256 pendingBytes;
/// @notice USDFC price per 32 GiB sector in smallest units (0 = manual approval)
uint256 pricePerSector;
/// @notice Monthly ERC20 token price per 32 GiB sector in smallest units (0 = manual approval)
uint256 pricePerSectorPerMonth;
}

/**
Expand Down Expand Up @@ -144,11 +144,11 @@ interface ISPRegistry {
function setCapabilities(CommonTypes.FilActorId provider, SLITypes.SLIThresholds calldata capabilities) external;

/**
* @notice Set the price per sector for a provider
* @notice Set the monthly price per sector for a provider
* @param provider The provider to update
* @param pricePerSector The USDFC price per 32 GiB sector in smallest units (0 to disable auto-approve)
* @param pricePerSectorPerMonth The monthly ERC20 token price per 32 GiB sector in smallest units (0 to disable auto-approve)
*/
function setPrice(CommonTypes.FilActorId provider, uint256 pricePerSector) external;
function setPrice(CommonTypes.FilActorId provider, uint256 pricePerSectorPerMonth) external;

/**
* @notice Set the payment recipient address for a provider
Expand Down
4 changes: 2 additions & 2 deletions src/types/SLITypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ library SLITypes {
*/
struct DealTerms {
uint256 dealSizeBytes;
/// @notice Price per 32 GiB sector in USDFC smallest units (wei-equivalent)
uint256 pricePerSector;
/// @notice Monthly price per 32 GiB sector in USDFC smallest units (wei-equivalent)
uint256 pricePerSectorPerMonth;
uint32 durationDays;
}

Expand Down
12 changes: 6 additions & 6 deletions test/Client.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract ClientTest is Test {
requirements: SLITypes.SLIThresholds({
retrievabilityBps: 80, bandwidthMbps: 500, latencyMs: 200, indexingPct: 90
}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSector: 100, durationDays: 365}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSectorPerMonth: 100, durationDays: 365}),
validator: address(validatorMock),
state: PoRepTypes.DealState.Accepted,
railId: 0,
Expand Down Expand Up @@ -263,7 +263,7 @@ contract ClientTest is Test {
requirements: SLITypes.SLIThresholds({
retrievabilityBps: 80, bandwidthMbps: 500, latencyMs: 200, indexingPct: 90
}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSector: 100, durationDays: 365}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSectorPerMonth: 100, durationDays: 365}),
validator: address(validatorMock),
state: PoRepTypes.DealState.Completed,
railId: 0,
Expand Down Expand Up @@ -394,7 +394,7 @@ contract ClientTest is Test {
requirements: SLITypes.SLIThresholds({
retrievabilityBps: 80, bandwidthMbps: 500, latencyMs: 200, indexingPct: 90
}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSector: 100, durationDays: 365}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSectorPerMonth: 100, durationDays: 365}),
validator: address(validatorMock),
state: PoRepTypes.DealState.Accepted,
railId: 0,
Expand Down Expand Up @@ -435,7 +435,7 @@ contract ClientTest is Test {
requirements: SLITypes.SLIThresholds({
retrievabilityBps: 80, bandwidthMbps: 500, latencyMs: 200, indexingPct: 90
}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSector: 100, durationDays: 365}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSectorPerMonth: 100, durationDays: 365}),
state: PoRepTypes.DealState.Accepted,
validator: address(validatorMock),
railId: 0,
Expand Down Expand Up @@ -468,7 +468,7 @@ contract ClientTest is Test {
requirements: SLITypes.SLIThresholds({
retrievabilityBps: 80, bandwidthMbps: 500, latencyMs: 200, indexingPct: 90
}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSector: 100, durationDays: 365}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSectorPerMonth: 100, durationDays: 365}),
validator: address(validatorMock),
state: PoRepTypes.DealState.Accepted,
railId: 0,
Expand Down Expand Up @@ -715,7 +715,7 @@ contract ClientTest is Test {
requirements: SLITypes.SLIThresholds({
retrievabilityBps: 80, bandwidthMbps: 500, latencyMs: 200, indexingPct: 90
}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSector: 100, durationDays: 365}),
terms: SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSectorPerMonth: 100, durationDays: 365}),
validator: address(0),
state: PoRepTypes.DealState.Accepted,
railId: 0,
Expand Down
12 changes: 6 additions & 6 deletions test/PoRepMarket.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract PoRepMarketTest is Test {
SLITypes.SLIThresholds({retrievabilityBps: 80, bandwidthMbps: 500, latencyMs: 200, indexingPct: 90});

SLITypes.DealTerms internal defaultTerms =
SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSector: 100, durationDays: 360});
SLITypes.DealTerms({dealSizeBytes: 1024, pricePerSectorPerMonth: 100, durationDays: 360});

string public expectedManifestLocation = "https://example.com/manifest";

Expand Down Expand Up @@ -107,7 +107,7 @@ contract PoRepMarketTest is Test {
assertEq(p.requirements.indexingPct, defaultRequirements.indexingPct);
assertEq(p.manifestLocation, expectedManifestLocation);
assertEq(p.terms.dealSizeBytes, defaultTerms.dealSizeBytes);
assertEq(p.terms.pricePerSector, defaultTerms.pricePerSector);
assertEq(p.terms.pricePerSectorPerMonth, defaultTerms.pricePerSectorPerMonth);
assertEq(p.terms.durationDays, defaultTerms.durationDays);
assertEq(p.validator, address(0));
assertEq(p.railId, 0);
Expand All @@ -122,7 +122,7 @@ contract PoRepMarketTest is Test {
assertEq(p.requirements.latencyMs, 0);
assertEq(p.requirements.indexingPct, 0);
assertEq(p.terms.dealSizeBytes, 0);
assertEq(p.terms.pricePerSector, 0);
assertEq(p.terms.pricePerSectorPerMonth, 0);
assertEq(p.terms.durationDays, 0);
assertEq(p.validator, address(0));
assertEq(p.railId, 0);
Expand Down Expand Up @@ -560,23 +560,23 @@ contract PoRepMarketTest is Test {

function testProposeDealRevertsWhenDealDurationIsZero() public {
SLITypes.DealTerms memory badTerms =
SLITypes.DealTerms({durationDays: 0, dealSizeBytes: 1024, pricePerSector: 100});
SLITypes.DealTerms({durationDays: 0, dealSizeBytes: 1024, pricePerSectorPerMonth: 100});
vm.prank(clientAddress);
vm.expectRevert(abi.encodeWithSelector(PoRepMarket.InvalidDealDuration.selector));
poRepMarket.proposeDeal(defaultRequirements, badTerms, expectedManifestLocation);
}

function testProposeDealRevertsWhenDealDurationIsNotMultiplicatioveOf30() public {
SLITypes.DealTerms memory badTerms =
SLITypes.DealTerms({durationDays: 31, dealSizeBytes: 1024, pricePerSector: 100});
SLITypes.DealTerms({durationDays: 31, dealSizeBytes: 1024, pricePerSectorPerMonth: 100});
vm.prank(clientAddress);
vm.expectRevert(abi.encodeWithSelector(PoRepMarket.InvalidDealDuration.selector));
poRepMarket.proposeDeal(defaultRequirements, badTerms, expectedManifestLocation);
}

function testProposeDealRevertsWhenDealDurationExceedsMaximum() public {
SLITypes.DealTerms memory badTerms = SLITypes.DealTerms({
durationDays: poRepMarket.MAX_DEAL_DURATION_DAYS() + 12, dealSizeBytes: 1024, pricePerSector: 100
durationDays: poRepMarket.MAX_DEAL_DURATION_DAYS() + 12, dealSizeBytes: 1024, pricePerSectorPerMonth: 100
});
vm.prank(clientAddress);
vm.expectRevert(abi.encodeWithSelector(PoRepMarket.InvalidDealDuration.selector));
Expand Down
Loading
Loading