@@ -42,6 +42,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
42
42
using EnumerableSet for EnumerableSet.Bytes32Set;
43
43
using EnumerableSet for EnumerableSet.AddressSet;
44
44
using Requests for Request;
45
+ using AskHelpers for Ask;
45
46
46
47
IERC20 private immutable _token;
47
48
MarketplaceConfig private _config;
@@ -72,14 +73,20 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
72
73
SlotState state;
73
74
RequestId requestId;
74
75
/// @notice Timestamp that signals when slot was filled
75
- /// @dev Used for calculating payouts as hosts are paid based on time they actually host the content
76
+ /// @dev Used for calculating payouts as hosts are paid
77
+ /// based on time they actually host the content
76
78
uint256 filledAt;
77
79
uint256 slotIndex;
78
- /// @notice Tracks the current amount of host's collateral that is to be payed out at the end of Slot's lifespan.
79
- /// @dev When Slot is filled, the collateral is collected in amount of request.ask.collateral
80
- /// @dev When Host is slashed for missing a proof the slashed amount is reflected in this variable
80
+ /// @notice Tracks the current amount of host's collateral that is
81
+ /// to be payed out at the end of Slot's lifespan.
82
+ /// @dev When Slot is filled, the collateral is collected in amount
83
+ /// of request.ask.collateralPerByte * request.ask.slotSize
84
+ /// (== request.ask.collateralPerSlot() when using the AskHelpers library)
85
+ /// @dev When Host is slashed for missing a proof the slashed amount is
86
+ /// reflected in this variable
81
87
uint256 currentCollateral;
82
- address host; // address used for collateral interactions and identifying hosts
88
+ /// @notice address used for collateral interactions and identifying hosts
89
+ address host;
83
90
}
84
91
85
92
struct ActiveSlot {
@@ -120,6 +127,10 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
120
127
return _token;
121
128
}
122
129
130
+ function currentCollateral (SlotId slotId ) public view returns (uint256 ) {
131
+ return _slots[slotId].currentCollateral;
132
+ }
133
+
123
134
function requestStorage (Request calldata request ) public {
124
135
RequestId id = request.id ();
125
136
@@ -137,10 +148,10 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
137
148
if (request.ask.proofProbability == 0 ) {
138
149
revert Marketplace_InsufficientProofProbability ();
139
150
}
140
- if (request.ask.collateral == 0 ) {
151
+ if (request.ask.collateralPerByte == 0 ) {
141
152
revert Marketplace_InsufficientCollateral ();
142
153
}
143
- if (request.ask.reward == 0 ) {
154
+ if (request.ask.pricePerBytePerSecond == 0 ) {
144
155
revert Marketplace_InsufficientReward ();
145
156
}
146
157
if (bytes (request.content.cid).length == 0 ) {
@@ -205,20 +216,20 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
205
216
206
217
// Collect collateral
207
218
uint256 collateralAmount;
219
+ uint256 collateralPerSlot = request.ask.collateralPerSlot ();
208
220
if (slotState (slotId) == SlotState.Repair) {
209
221
// Host is repairing a slot and is entitled for repair reward, so he gets "discounted collateral"
210
222
// in this way he gets "physically" the reward at the end of the request when the full amount of collateral
211
223
// is returned to him.
212
224
collateralAmount =
213
- request.ask.collateral -
214
- ((request.ask.collateral * _config.collateral.repairRewardPercentage) /
215
- 100 );
225
+ collateralPerSlot -
226
+ ((collateralPerSlot * _config.collateral.repairRewardPercentage) / 100 );
216
227
} else {
217
- collateralAmount = request.ask.collateral ;
228
+ collateralAmount = collateralPerSlot ;
218
229
}
219
230
_transferFrom (msg .sender , collateralAmount);
220
231
_marketplaceTotals.received += collateralAmount;
221
- slot.currentCollateral = request.ask.collateral ; // Even if he has collateral discounted, he is operating with full collateral
232
+ slot.currentCollateral = collateralPerSlot ; // Even if he has collateral discounted, he is operating with full collateral
222
233
223
234
_addToMySlots (slot.host, slotId);
224
235
@@ -326,7 +337,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
326
337
// TODO: Reward for validator that calls this function
327
338
328
339
if (missingProofs (slotId) % _config.collateral.slashCriterion == 0 ) {
329
- uint256 slashedAmount = (request.ask.collateral *
340
+ uint256 slashedAmount = (request.ask.collateralPerSlot () *
330
341
_config.collateral.slashPercentage) / 100 ;
331
342
slot.currentCollateral -= slashedAmount;
332
343
if (
@@ -586,7 +597,9 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
586
597
Request storage request = _requests[requestId];
587
598
if (startingTimestamp >= endingTimestamp)
588
599
revert Marketplace_StartNotBeforeExpiry ();
589
- return (endingTimestamp - startingTimestamp) * request.ask.reward;
600
+ return
601
+ (endingTimestamp - startingTimestamp) *
602
+ request.ask.pricePerSlotPerSecond ();
590
603
}
591
604
592
605
function getHost (SlotId slotId ) public view returns (address ) {
0 commit comments