2023-01-09 13:56:29 +01:00
// SPDX-License-Identifier: MIT
2024-01-23 10:24:02 +01:00
pragma solidity 0 . 8 . 23 ;
2023-01-09 13:56:29 +01:00
type RequestId is bytes32 ;
type SlotId is bytes32 ;
struct Request {
address client ;
Ask ask ;
Content content ;
2024-05-06 15:13:32 +02:00
uint256 expiry ; // amount of seconds since start of the request at which this request expires
2023-01-09 13:56:29 +01:00
bytes32 nonce ; // random nonce to differentiate between similar requests
2024-09-19 16:55:47 +10:00
uint8 expansion ; // Percentage of addresses eligible to reserve a slot halfway between request creation and when all network addresses are eligible to participate. [1-100].
2023-01-09 13:56:29 +01:00
}
struct Ask {
uint64 slots ; // the number of requested slots
uint256 slotSize ; // amount of storage per slot (in number of bytes)
uint256 duration ; // how long content should be stored (in seconds)
uint256 proofProbability ; // how often storage proofs are required
uint256 reward ; // amount of tokens paid per second per slot to hosts
2023-03-08 12:02:34 +01:00
uint256 collateral ; // amount of tokens required to be deposited by the hosts in order to fill the slot
2023-01-09 13:56:29 +01:00
uint64 maxSlotLoss ; // Max slots that can be lost without data considered to be lost
}
struct Content {
2023-10-18 16:27:42 +02:00
string cid ; // content id, used to download the dataset
2023-11-22 12:47:31 +01:00
bytes32 merkleRoot ; // merkle root of the dataset, used to verify storage proofs
2023-01-09 13:56:29 +01:00
}
2023-01-10 15:04:16 +01:00
2023-01-16 14:21:58 +01:00
enum RequestState {
New , // [default] waiting to fill slots
Started , // all slots filled, accepting regular proofs
Cancelled , // not enough slots filled before expiry
Finished , // successfully completed
Failed // too many nodes have failed to provide proofs, data lost
}
2023-01-16 16:31:04 +01:00
enum SlotState {
2023-01-18 15:26:21 +01:00
Free , // [default] not filled yet, or host has vacated the slot
2023-01-16 16:31:04 +01:00
Filled , // host has filled slot
2023-01-16 17:18:17 +01:00
Finished , // successfully completed
2023-01-18 15:26:21 +01:00
Failed , // the request has failed
2023-10-16 11:14:02 +02:00
Paid , // host has been paid
Cancelled // when request was cancelled then slot is cancelled as well
2023-01-16 16:31:04 +01:00
}
2023-01-10 15:04:16 +01:00
library Requests {
function id ( Request memory request ) internal pure returns ( RequestId ) {
return RequestId . wrap ( keccak256 ( abi . encode ( request ) ) ) ;
}
2023-01-11 10:52:08 +01:00
function slotId (
RequestId requestId ,
uint256 slotIndex
) internal pure returns ( SlotId ) {
return SlotId . wrap ( keccak256 ( abi . encode ( requestId , slotIndex ) ) ) ;
}
2023-01-10 15:04:16 +01:00
function toRequestIds (
bytes32 [ ] memory ids
) internal pure returns ( RequestId [ ] memory result ) {
// solhint-disable-next-line no-inline-assembly
assembly {
result : = ids
}
}
function toSlotIds (
bytes32 [ ] memory ids
) internal pure returns ( SlotId [ ] memory result ) {
// solhint-disable-next-line no-inline-assembly
assembly {
result : = ids
}
}
2023-01-17 09:19:51 +01:00
function pricePerSlot (
Request memory request
) internal pure returns ( uint256 ) {
return request . ask . duration * request . ask . reward ;
}
function price ( Request memory request ) internal pure returns ( uint256 ) {
return request . ask . slots * pricePerSlot ( request ) ;
}
2023-01-10 15:04:16 +01:00
}