marketplace: move collateralPerSlot() to Requests.sol

reason: the function only depends on the request, and it is similar
to the pricePerSlotPerSecond function

Co-Authored-By: Adam Uhlíř <adam@uhlir.dev>
This commit is contained in:
Mark Spanbroek 2025-05-27 12:46:23 +02:00
parent 1fb3d2130b
commit bdee8de9cc
3 changed files with 7 additions and 9 deletions

View File

@ -209,7 +209,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
AccountId hostAccount = _vault.hostAccount(slot.host, slotIndex);
TokensPerSecond rate = request.ask.pricePerSlotPerSecond();
uint128 collateral = request.collateralPerSlot();
uint128 collateral = request.ask.collateralPerSlot();
uint128 designated = _config.collateral.designatedCollateral(collateral);
if (slotState(slotId) == SlotState.Repair) {
@ -327,7 +327,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
Slot storage slot = _slots[slotId];
Request storage request = _requests[slot.requestId];
uint128 collateral = request.collateralPerSlot();
uint128 collateral = request.ask.collateralPerSlot();
uint128 slashedAmount = _config.collateral.slashAmount(collateral);
uint128 validatorReward = _config.collateral.validatorReward(slashedAmount);
@ -355,7 +355,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
Request storage request = _requests[requestId];
TokensPerSecond rate = request.ask.pricePerSlotPerSecond();
uint128 collateral = request.collateralPerSlot();
uint128 collateral = request.ask.collateralPerSlot();
uint128 repairReward = _config.collateral.repairReward(collateral);
FundId fund = requestId.asFundId();

View File

@ -63,6 +63,10 @@ library AskHelpers {
uint96 perSlot = TokensPerSecond.unwrap(ask.pricePerSlotPerSecond());
return TokensPerSecond.wrap(perSlot * ask.slots);
}
function collateralPerSlot(Ask memory ask) internal pure returns (uint128) {
return ask.collateralPerByte * ask.slotSize;
}
}
library Requests {

View File

@ -25,12 +25,6 @@ library Collateral {
);
}
function collateralPerSlot(
Request storage request
) internal view returns (uint128) {
return request.ask.collateralPerByte * request.ask.slotSize;
}
function slashAmount(
CollateralConfig storage configuration,
uint128 collateral