diff --git a/service_contracts/abi/FilecoinWarmStorageService.abi.json b/service_contracts/abi/FilecoinWarmStorageService.abi.json index 7fe69b87..eeb21226 100644 --- a/service_contracts/abi/FilecoinWarmStorageService.abi.json +++ b/service_contracts/abi/FilecoinWarmStorageService.abi.json @@ -114,16 +114,6 @@ "name": "storageRate", "type": "uint256", "internalType": "uint256" - }, - { - "name": "cacheMissRate", - "type": "uint256", - "internalType": "uint256" - }, - { - "name": "cdnRate", - "type": "uint256", - "internalType": "uint256" } ], "stateMutability": "view" @@ -349,7 +339,12 @@ "internalType": "uint256" }, { - "name": "pricePerTiBPerMonthWithCDN", + "name": "pricePerTiBCdnEgress", + "type": "uint256", + "internalType": "uint256" + }, + { + "name": "pricePerTiBCacheMissEgress", "type": "uint256", "internalType": "uint256" }, diff --git a/service_contracts/src/FilecoinWarmStorageService.sol b/service_contracts/src/FilecoinWarmStorageService.sol index da3ad9ff..295a4b7b 100644 --- a/service_contracts/src/FilecoinWarmStorageService.sol +++ b/service_contracts/src/FilecoinWarmStorageService.sol @@ -155,7 +155,8 @@ contract FilecoinWarmStorageService is // Structure for service pricing information struct ServicePricing { uint256 pricePerTiBPerMonthNoCDN; // Price without CDN add-on (2.5 USDFC per TiB per month) - uint256 pricePerTiBPerMonthWithCDN; // Price with CDN add-on (3 USDFC per TiB per month) + uint256 pricePerTiBCdnEgress; // CDN egress price per TiB (usage-based) + uint256 pricePerTiBCacheMissEgress; // Cache miss egress price per TiB (usage-based) IERC20 tokenAddress; // Address of the USDFC token uint256 epochsPerMonth; // Number of epochs in a month } @@ -194,8 +195,8 @@ contract FilecoinWarmStorageService is // Pricing constants uint256 private immutable STORAGE_PRICE_PER_TIB_PER_MONTH; // 2.5 USDFC per TiB per month without CDN with correct decimals - uint256 private immutable CACHE_MISS_PRICE_PER_TIB_PER_MONTH; // .5 USDFC per TiB per month for CDN with correct decimals - uint256 private immutable CDN_PRICE_PER_TIB_PER_MONTH; // .5 USDFC per TiB per month for CDN with correct decimals + uint256 private immutable CDN_EGRESS_PRICE_PER_TIB; // 7 USDFC per TiB of CDN egress + uint256 private immutable CACHE_MISS_EGRESS_PRICE_PER_TIB; // 7 USDFC per TiB of cache miss egress // Fixed lockup amounts for CDN rails uint256 private immutable DEFAULT_CDN_LOCKUP_AMOUNT; // 0.7 USDFC @@ -328,8 +329,8 @@ contract FilecoinWarmStorageService is // Initialize the fee constants based on the actual token decimals STORAGE_PRICE_PER_TIB_PER_MONTH = (5 * 10 ** TOKEN_DECIMALS) / 2; // 2.5 USDFC - CACHE_MISS_PRICE_PER_TIB_PER_MONTH = (1 * 10 ** TOKEN_DECIMALS) / 2; // 0.5 USDFC - CDN_PRICE_PER_TIB_PER_MONTH = (1 * 10 ** TOKEN_DECIMALS) / 2; // 0.5 USDFC + CDN_EGRESS_PRICE_PER_TIB = 7 * 10 ** TOKEN_DECIMALS; // 7 USDFC per TiB + CACHE_MISS_EGRESS_PRICE_PER_TIB = 7 * 10 ** TOKEN_DECIMALS; // 7 USDFC per TiB // Initialize the lockup constants based on the actual token decimals DEFAULT_CDN_LOCKUP_AMOUNT = (7 * 10 ** TOKEN_DECIMALS) / 10; // 0.7 USDFC @@ -1112,19 +1113,6 @@ contract FilecoinWarmStorageService is 0 // No one-time payment during rate update ); emit RailRateUpdated(dataSetId, pdpRailId, newStorageRatePerEpoch); - - // Update the CDN rail payment rates, if applicable - if (dataSetHasCDNMetadataKey(dataSetId)) { - (uint256 newCacheMissRatePerEpoch, uint256 newCDNRatePerEpoch) = _calculateCDNRates(totalBytes); - - uint256 cacheMissRailId = dataSetInfo[dataSetId].cacheMissRailId; - payments.modifyRailPayment(cacheMissRailId, newCacheMissRatePerEpoch, 0); - emit RailRateUpdated(dataSetId, cacheMissRailId, newCacheMissRatePerEpoch); - - uint256 cdnRailId = dataSetInfo[dataSetId].cdnRailId; - payments.modifyRailPayment(cdnRailId, newCDNRatePerEpoch, 0); - emit RailRateUpdated(dataSetId, cdnRailId, newCDNRatePerEpoch); - } } /** @@ -1188,21 +1176,13 @@ contract FilecoinWarmStorageService is } /** - * @notice Calculate all per-epoch rates based on total storage size - * @dev Returns storage, cache miss, and CDN rates per TiB per month + * @notice Calculate storage rate per epoch based on total storage size + * @dev Returns storage rate per TiB per month * @param totalBytes Total size of the stored data in bytes * @return storageRate The PDP storage rate per epoch - * @return cacheMissRate The cache miss rate per epoch - * @return cdnRate The CDN rate per epoch */ - function calculateRatesPerEpoch(uint256 totalBytes) - external - view - returns (uint256 storageRate, uint256 cacheMissRate, uint256 cdnRate) - { + function calculateRatesPerEpoch(uint256 totalBytes) external view returns (uint256 storageRate) { storageRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, STORAGE_PRICE_PER_TIB_PER_MONTH); - cacheMissRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, CACHE_MISS_PRICE_PER_TIB_PER_MONTH); - cdnRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, CDN_PRICE_PER_TIB_PER_MONTH); } /** @@ -1214,17 +1194,6 @@ contract FilecoinWarmStorageService is return calculateStorageSizeBasedRatePerEpoch(totalBytes, STORAGE_PRICE_PER_TIB_PER_MONTH); } - /** - * @notice Calculate the CDN rates per epoch (internal use) - * @param totalBytes Total size of the stored data in bytes - * @return cacheMissRate The cache miss rate per epoch - * @return cdnRate The CDN rate per epoch - */ - function _calculateCDNRates(uint256 totalBytes) internal view returns (uint256 cacheMissRate, uint256 cdnRate) { - cacheMissRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, CACHE_MISS_PRICE_PER_TIB_PER_MONTH); - cdnRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, CDN_PRICE_PER_TIB_PER_MONTH); - } - /** * @notice Decode extra data for data set creation * @param extraData The encoded extra data from PDPVerifier @@ -1312,12 +1281,13 @@ contract FilecoinWarmStorageService is /** * @notice Get the service pricing information - * @return pricing A struct containing pricing details for both CDN and non-CDN storage + * @return pricing A struct containing pricing details for storage and CDN/cache miss egress */ function getServicePrice() external view returns (ServicePricing memory pricing) { pricing = ServicePricing({ pricePerTiBPerMonthNoCDN: STORAGE_PRICE_PER_TIB_PER_MONTH, - pricePerTiBPerMonthWithCDN: STORAGE_PRICE_PER_TIB_PER_MONTH + CDN_PRICE_PER_TIB_PER_MONTH, + pricePerTiBCdnEgress: CDN_EGRESS_PRICE_PER_TIB, + pricePerTiBCacheMissEgress: CACHE_MISS_EGRESS_PRICE_PER_TIB, tokenAddress: usdfcTokenAddress, epochsPerMonth: EPOCHS_PER_MONTH }); diff --git a/service_contracts/test/FilecoinWarmStorageService.t.sol b/service_contracts/test/FilecoinWarmStorageService.t.sol index 0d6af506..eea02ca9 100644 --- a/service_contracts/test/FilecoinWarmStorageService.t.sol +++ b/service_contracts/test/FilecoinWarmStorageService.t.sol @@ -911,16 +911,23 @@ contract FilecoinWarmStorageServiceTest is MockFVMTest { uint256 decimals = 6; // MockUSDFC uses 6 decimals in tests uint256 expectedNoCDN = 25 * 10 ** (decimals - 1); // 2.5 USDFC with 6 decimals - uint256 expectedWithCDN = 3 * 10 ** decimals; // 3 USDFC with 6 decimals (2.5 + 0.5 CDN) + uint256 expectedCDNEgress = 7 * 10 ** decimals; // 7 USDFC per TiB of CDN egress + uint256 expectedCacheMissEgress = 7 * 10 ** decimals; // 7 USDFC per TiB of cache miss egress assertEq(pricing.pricePerTiBPerMonthNoCDN, expectedNoCDN, "No CDN price should be 2.5 * 10^decimals"); - assertEq(pricing.pricePerTiBPerMonthWithCDN, expectedWithCDN, "With CDN price should be 3 * 10^decimals"); + assertEq(pricing.pricePerTiBCdnEgress, expectedCDNEgress, "CDN egress price should be 7 * 10^decimals per TiB"); + assertEq( + pricing.pricePerTiBCacheMissEgress, + expectedCacheMissEgress, + "Cache miss egress price should be 7 * 10^decimals per TiB" + ); assertEq(address(pricing.tokenAddress), address(mockUSDFC), "Token address should match USDFC"); assertEq(pricing.epochsPerMonth, 86400, "Epochs per month should be 86400"); // Verify the values are in expected range assert(pricing.pricePerTiBPerMonthNoCDN < 10 ** 8); // Less than 10^8 - assert(pricing.pricePerTiBPerMonthWithCDN < 10 ** 8); // Less than 10^8 + assert(pricing.pricePerTiBCdnEgress < 10 ** 8); // Less than 10^8 + assert(pricing.pricePerTiBCacheMissEgress < 10 ** 8); // Less than 10^8 } function testGetEffectiveRatesValues() public view {