marketplace: collateral is uint128

Vault stores balances as uint128
This commit is contained in:
Mark Spanbroek 2025-02-26 14:03:02 +01:00
parent 4f45856a5e
commit 761fbd4f84
2 changed files with 8 additions and 8 deletions

View File

@ -243,8 +243,8 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
context.fundsToReturnToClient -= _slotPayout(requestId, slot.filledAt);
// Collect collateral
uint256 collateralAmount;
uint256 collateralPerSlot = request.ask.collateralPerSlot();
uint128 collateralAmount;
uint128 collateralPerSlot = request.ask.collateralPerSlot();
if (slotState(slotId) == SlotState.Repair) {
// Host is repairing a slot and is entitled for repair reward, so he gets "discounted collateral"
// in this way he gets "physically" the reward at the end of the request when the full amount of collateral
@ -261,7 +261,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
AccountId hostAccount = _vault.hostAccount(slot.host, slotIndex);
TokensPerSecond rate = request.ask.pricePerSlotPerSecond();
_transferToVault(slot.host, fund, hostAccount, uint128(collateralAmount));
_transferToVault(slot.host, fund, hostAccount, collateralAmount);
_vault.flow(fund, clientAccount, hostAccount, rate);
_marketplaceTotals.received += collateralAmount;
@ -374,10 +374,10 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
Slot storage slot = _slots[slotId];
Request storage request = _requests[slot.requestId];
uint256 slashedAmount = (request.ask.collateralPerSlot() *
uint128 slashedAmount = (request.ask.collateralPerSlot() *
_config.collateral.slashPercentage) / 100;
uint256 validatorRewardAmount = (slashedAmount *
uint128 validatorRewardAmount = (slashedAmount *
_config.collateral.validatorRewardPercentage) / 100;
_marketplaceTotals.sent += validatorRewardAmount;
@ -388,7 +388,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
fund,
hostAccount,
validatorAccount,
uint128(validatorRewardAmount)
validatorRewardAmount
);
slot.currentCollateral -= slashedAmount;

View File

@ -18,7 +18,7 @@ struct Request {
struct Ask {
uint256 proofProbability; // how often storage proofs are required
TokensPerSecond pricePerBytePerSecond; // amount of tokens paid per second per byte to hosts
uint256 collateralPerByte; // amount of tokens per byte required to be deposited by the hosts in order to fill the slot
uint128 collateralPerByte; // amount of tokens per byte required to be deposited by the hosts in order to fill the slot
uint64 slots; // the number of requested slots
uint64 slotSize; // amount of storage per slot (in number of bytes)
Duration duration; // how long content should be stored (in seconds)
@ -49,7 +49,7 @@ enum SlotState {
}
library AskHelpers {
function collateralPerSlot(Ask memory ask) internal pure returns (uint256) {
function collateralPerSlot(Ask memory ask) internal pure returns (uint128) {
return ask.collateralPerByte * ask.slotSize;
}