From afb89c923374934e3096c288ca66f4119aa2f862 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 9 Jan 2023 16:01:43 +0100 Subject: [PATCH] [Storage] Remove Storage Rationale: it was already a very thin wrapper around Marketplace, and now that its remaining functionality has been moved to Proofs and Marketplace, we no longer need it. --- Readme.md | 2 +- contracts/Storage.sol | 30 ----------- deploy/{storage.js => marketplace.js} | 16 +++--- test/Storage.test.js | 74 --------------------------- 4 files changed, 9 insertions(+), 113 deletions(-) delete mode 100644 contracts/Storage.sol rename deploy/{storage.js => marketplace.js} (77%) delete mode 100644 test/Storage.test.js diff --git a/Readme.md b/Readme.md index edcd024..a1de391 100644 --- a/Readme.md +++ b/Readme.md @@ -31,7 +31,7 @@ certain amount of time. When all goes well, the client and host perform the following steps: - Client Host Storage Contract + Client Host Marketplace Contract | | | | | | --------------- request (1) -------------> | diff --git a/contracts/Storage.sol b/contracts/Storage.sol deleted file mode 100644 index 5385a0e..0000000 --- a/contracts/Storage.sol +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -import "./Marketplace.sol"; -import "./Proofs.sol"; -import "./Collateral.sol"; - -contract Storage is Marketplace { - constructor( - IERC20 token, - uint256 _proofPeriod, - uint256 _proofTimeout, - uint8 _proofDowntime, - uint256 _collateralAmount, - uint256 _slashMisses, - uint256 _slashPercentage, - uint256 _minCollateralThreshold - ) - Marketplace( - token, - _collateralAmount, - _minCollateralThreshold, - _slashMisses, - _slashPercentage, - _proofPeriod, - _proofTimeout, - _proofDowntime - ) - {} -} diff --git a/deploy/storage.js b/deploy/marketplace.js similarity index 77% rename from deploy/storage.js rename to deploy/marketplace.js index c9c83d2..f1f606a 100644 --- a/deploy/storage.js +++ b/deploy/marketplace.js @@ -1,4 +1,4 @@ -async function deployStorage({ deployments, getNamedAccounts }) { +async function deployMarketplace({ deployments, getNamedAccounts }) { const token = await deployments.get("TestToken") const proofPeriod = 10 const proofTimeout = 5 @@ -9,16 +9,16 @@ async function deployStorage({ deployments, getNamedAccounts }) { const minCollateralThreshold = 40 const args = [ token.address, + collateralAmount, + minCollateralThreshold, + slashMisses, + slashPercentage, proofPeriod, proofTimeout, proofDowntime, - collateralAmount, - slashMisses, - slashPercentage, - minCollateralThreshold, ] const { deployer } = await getNamedAccounts() - await deployments.deploy("Storage", { args, from: deployer }) + await deployments.deploy("Marketplace", { args, from: deployer }) } async function mine256blocks({ network, ethers }) { @@ -29,8 +29,8 @@ async function mine256blocks({ network, ethers }) { module.exports = async (environment) => { await mine256blocks(environment) - await deployStorage(environment) + await deployMarketplace(environment) } -module.exports.tags = ["Storage"] +module.exports.tags = ["Marketplace"] module.exports.dependencies = ["TestToken"] diff --git a/test/Storage.test.js b/test/Storage.test.js deleted file mode 100644 index d7193ab..0000000 --- a/test/Storage.test.js +++ /dev/null @@ -1,74 +0,0 @@ -const { expect } = require("chai") -const { ethers, deployments } = require("hardhat") -const { hexlify, randomBytes } = ethers.utils -const { AddressZero } = ethers.constants -const { exampleRequest } = require("./examples") -const { advanceTime, advanceTimeTo, currentTime } = require("./evm") -const { requestId, slotId } = require("./ids") -const { periodic } = require("./time") -const { price } = require("./price") -const { - waitUntilCancelled, - waitUntilStarted, - waitUntilFinished, -} = require("./marketplace") - -describe("Storage", function () { - const proof = hexlify(randomBytes(42)) - - let storage - let token - let client, host - let request - let collateralAmount, slashMisses, slashPercentage - let slot - - function switchAccount(account) { - token = token.connect(account) - storage = storage.connect(account) - } - - beforeEach(async function () { - ;[client, host] = await ethers.getSigners() - - await deployments.fixture(["TestToken", "Storage"]) - token = await ethers.getContract("TestToken") - storage = await ethers.getContract("Storage") - - await token.mint(client.address, 1_000_000_000) - await token.mint(host.address, 1_000_000_000) - - collateralAmount = await storage.collateral() - slashMisses = await storage.slashMisses() - slashPercentage = await storage.slashPercentage() - minCollateralThreshold = await storage.minCollateralThreshold() - - request = await exampleRequest() - request.client = client.address - slot = { - request: requestId(request), - index: request.ask.slots / 2, - } - - switchAccount(client) - await token.approve(storage.address, price(request)) - await storage.requestStorage(request) - switchAccount(host) - await token.approve(storage.address, collateralAmount) - await storage.deposit(collateralAmount) - }) - - describe("ending the contract", function () { - it("unlocks the host collateral", async function () { - await storage.fillSlot(slot.request, slot.index, proof) - await waitUntilFinished(storage, slot.request) - await storage.freeSlot(slotId(slot)) - await expect(storage.withdraw()).not.to.be.reverted - }) - }) -}) - -// TODO: implement checking of actual proofs of storage, instead of dummy bool -// TODO: allow other host to take over contract when too many missed proofs -// TODO: small partial payouts when proofs are being submitted -// TODO: reward caller of markProofAsMissing