From 761fbd4f84ed5dac5d0d21c2d7b48393c2713cf2 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 26 Feb 2025 14:03:02 +0100 Subject: [PATCH] marketplace: collateral is uint128 Vault stores balances as uint128 --- contracts/Marketplace.sol | 12 ++++++------ contracts/Requests.sol | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 3ba6236..3ff1590 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -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; diff --git a/contracts/Requests.sol b/contracts/Requests.sol index 1bebeb3..c6cc99b 100644 --- a/contracts/Requests.sol +++ b/contracts/Requests.sol @@ -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; }