From 3d5fa4708b08af90283234cedb15b7d820c043de Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:48:16 +1000 Subject: [PATCH] feat(slot-reservations): Add expansion parameter Add "expansion" parameter, that indicates the percentage of addresses eligible to reserve a slot halfway between request creation and when all network addresses are eligible to participate. Valid range = [1-100]. --- contracts/Marketplace.sol | 4 ++++ contracts/Requests.sol | 1 + test/Marketplace.test.js | 12 ++++++++++++ test/examples.js | 1 + test/ids.js | 3 ++- 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index f7a083a..6ea64b3 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -101,6 +101,10 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { request.ask.maxSlotLoss <= request.ask.slots, "maxSlotLoss exceeds slots" ); + require( + request.ask.expansion > 0 && request.ask.expansion <= 100, + "expansion must be [1, 100]" + ); _requests[id] = request; _requestContexts[id].endsAt = block.timestamp + request.ask.duration; diff --git a/contracts/Requests.sol b/contracts/Requests.sol index 1771719..46be82b 100644 --- a/contracts/Requests.sol +++ b/contracts/Requests.sol @@ -20,6 +20,7 @@ struct Ask { uint256 reward; // amount of tokens paid per second per slot to hosts uint256 collateral; // amount of tokens required to be deposited by the hosts in order to fill the slot uint64 maxSlotLoss; // Max slots that can be lost without data considered to be lost + 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]. } struct Content { diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 3b4f1a9..5911609 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -225,6 +225,18 @@ describe("Marketplace", function () { ) }) + it("is rejected when expansion is out of bounds", async function () { + request.ask.expansion = 0 + await expect(marketplace.requestStorage(request)).to.be.revertedWith( + "expansion must be [1, 100]" + ) + + request.ask.expansion = 101 + await expect(marketplace.requestStorage(request)).to.be.revertedWith( + "expansion must be [1, 100]" + ) + }) + it("rejects resubmission of request", async function () { await token.approve(marketplace.address, price(request) * 2) await marketplace.requestStorage(request) diff --git a/test/examples.js b/test/examples.js index 06d8428..4f750a2 100644 --- a/test/examples.js +++ b/test/examples.js @@ -29,6 +29,7 @@ const exampleRequest = async () => { reward: 84, maxSlotLoss: 2, collateral: 200, + expansion: 60, }, content: { cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob", diff --git a/test/ids.js b/test/ids.js index 5ef1220..b1a3be3 100644 --- a/test/ids.js +++ b/test/ids.js @@ -2,7 +2,7 @@ const { ethers } = require("hardhat") const { keccak256, defaultAbiCoder } = ethers.utils function requestId(request) { - const Ask = "tuple(int64, uint256, uint256, uint256, uint256, uint256, int64)" + const Ask = "tuple(int64, uint256, uint256, uint256, uint256, uint256, uint64, uint8)" const Content = "tuple(string, bytes32)" const Request = "tuple(address, " + Ask + ", " + Content + ", uint256, bytes32)" @@ -18,6 +18,7 @@ function askToArray(ask) { ask.reward, ask.collateral, ask.maxSlotLoss, + ask.expansion, ] }