Skip to content

Commit 5901766

Browse files
committed
feat: floor price set to 0.06 USDFC/month per data set
For storage amounts below ~24.576 GiB, the rate will be 0.06 USDFC / month. Above this amount the price is per-byte. Closes: #319
1 parent e664ae8 commit 5901766

File tree

6 files changed

+212
-60
lines changed

6 files changed

+212
-60
lines changed

service_contracts/abi/FilecoinWarmStorageService.abi.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@
362362
"name": "epochsPerMonth",
363363
"type": "uint256",
364364
"internalType": "uint256"
365+
},
366+
{
367+
"name": "minimumPricePerMonth",
368+
"type": "uint256",
369+
"internalType": "uint256"
365370
}
366371
]
367372
}
@@ -1686,6 +1691,27 @@
16861691
}
16871692
]
16881693
},
1694+
{
1695+
"type": "error",
1696+
"name": "InsufficientFundsForMinimumRate",
1697+
"inputs": [
1698+
{
1699+
"name": "payer",
1700+
"type": "address",
1701+
"internalType": "address"
1702+
},
1703+
{
1704+
"name": "minimumRequired",
1705+
"type": "uint256",
1706+
"internalType": "uint256"
1707+
},
1708+
{
1709+
"name": "available",
1710+
"type": "uint256",
1711+
"internalType": "uint256"
1712+
}
1713+
]
1714+
},
16891715
{
16901716
"type": "error",
16911717
"name": "InvalidChallengeCount",

service_contracts/src/FilecoinWarmStorageService.sol

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ contract FilecoinWarmStorageService is
158158
uint256 pricePerTiBPerMonthWithCDN; // Price with CDN add-on (3 USDFC per TiB per month)
159159
IERC20 tokenAddress; // Address of the USDFC token
160160
uint256 epochsPerMonth; // Number of epochs in a month
161+
uint256 minimumPricePerMonth; // Minimum monthly charge for any dataset size (0.06 USDFC)
161162
}
162163

163164
// Used for announcing upgrades, packed into one slot
@@ -196,6 +197,7 @@ contract FilecoinWarmStorageService is
196197
uint256 private immutable STORAGE_PRICE_PER_TIB_PER_MONTH; // 2.5 USDFC per TiB per month without CDN with correct decimals
197198
uint256 private immutable CACHE_MISS_PRICE_PER_TIB_PER_MONTH; // .5 USDFC per TiB per month for CDN with correct decimals
198199
uint256 private immutable CDN_PRICE_PER_TIB_PER_MONTH; // .5 USDFC per TiB per month for CDN with correct decimals
200+
uint256 private immutable MINIMUM_STORAGE_RATE_PER_MONTH; // 0.06 USDFC per month minimum pricing floor
199201

200202
// Fixed lockup amounts for CDN rails
201203
uint256 private immutable DEFAULT_CDN_LOCKUP_AMOUNT; // 0.7 USDFC
@@ -330,6 +332,7 @@ contract FilecoinWarmStorageService is
330332
STORAGE_PRICE_PER_TIB_PER_MONTH = (5 * 10 ** TOKEN_DECIMALS) / 2; // 2.5 USDFC
331333
CACHE_MISS_PRICE_PER_TIB_PER_MONTH = (1 * 10 ** TOKEN_DECIMALS) / 2; // 0.5 USDFC
332334
CDN_PRICE_PER_TIB_PER_MONTH = (1 * 10 ** TOKEN_DECIMALS) / 2; // 0.5 USDFC
335+
MINIMUM_STORAGE_RATE_PER_MONTH = (6 * 10 ** TOKEN_DECIMALS) / 100; // 0.06 USDFC minimum
333336

334337
// Initialize the lockup constants based on the actual token decimals
335338
DEFAULT_CDN_LOCKUP_AMOUNT = (7 * 10 ** TOKEN_DECIMALS) / 10; // 0.7 USDFC
@@ -1189,7 +1192,8 @@ contract FilecoinWarmStorageService is
11891192

11901193
/**
11911194
* @notice Calculate all per-epoch rates based on total storage size
1192-
* @dev Returns storage, cache miss, and CDN rates per TiB per month
1195+
* @dev Returns storage, cache miss, and CDN rates per TiB per month.
1196+
* Storage rate includes minimum pricing floor.
11931197
* @param totalBytes Total size of the stored data in bytes
11941198
* @return storageRate The PDP storage rate per epoch
11951199
* @return cacheMissRate The cache miss rate per epoch
@@ -1200,18 +1204,26 @@ contract FilecoinWarmStorageService is
12001204
view
12011205
returns (uint256 storageRate, uint256 cacheMissRate, uint256 cdnRate)
12021206
{
1203-
storageRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, STORAGE_PRICE_PER_TIB_PER_MONTH);
1207+
storageRate = _calculateStorageRate(totalBytes);
12041208
cacheMissRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, CACHE_MISS_PRICE_PER_TIB_PER_MONTH);
12051209
cdnRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, CDN_PRICE_PER_TIB_PER_MONTH);
12061210
}
12071211

12081212
/**
12091213
* @notice Calculate the storage rate per epoch (internal use)
1214+
* @dev Implements minimum pricing floor and returns the higher of the natural size-based rate or the minimum rate.
12101215
* @param totalBytes Total size of the stored data in bytes
12111216
* @return The storage rate per epoch
12121217
*/
12131218
function _calculateStorageRate(uint256 totalBytes) internal view returns (uint256) {
1214-
return calculateStorageSizeBasedRatePerEpoch(totalBytes, STORAGE_PRICE_PER_TIB_PER_MONTH);
1219+
// Calculate natural size-based rate
1220+
uint256 naturalRate = calculateStorageSizeBasedRatePerEpoch(totalBytes, STORAGE_PRICE_PER_TIB_PER_MONTH);
1221+
1222+
// Calculate minimum rate (floor price converted to per-epoch)
1223+
uint256 minimumRate = MINIMUM_STORAGE_RATE_PER_MONTH / EPOCHS_PER_MONTH;
1224+
1225+
// Return whichever is higher: natural rate or minimum rate
1226+
return naturalRate > minimumRate ? naturalRate : minimumRate;
12151227
}
12161228

12171229
/**
@@ -1319,7 +1331,8 @@ contract FilecoinWarmStorageService is
13191331
pricePerTiBPerMonthNoCDN: STORAGE_PRICE_PER_TIB_PER_MONTH,
13201332
pricePerTiBPerMonthWithCDN: STORAGE_PRICE_PER_TIB_PER_MONTH + CDN_PRICE_PER_TIB_PER_MONTH,
13211333
tokenAddress: usdfcTokenAddress,
1322-
epochsPerMonth: EPOCHS_PER_MONTH
1334+
epochsPerMonth: EPOCHS_PER_MONTH,
1335+
minimumPricePerMonth: MINIMUM_STORAGE_RATE_PER_MONTH
13231336
});
13241337
}
13251338

0 commit comments

Comments
 (0)