From 2e20a7dce85b4b4daa042dcd52de2df1f33c086c Mon Sep 17 00:00:00 2001 From: iteye Date: Thu, 16 May 2024 10:19:57 +0800 Subject: [PATCH 1/2] Check prepaid balance --- contracts/EthStorageContract.sol | 1 + scripts/deploy.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/contracts/EthStorageContract.sol b/contracts/EthStorageContract.sol index b4920eb..703a0b2 100644 --- a/contracts/EthStorageContract.sol +++ b/contracts/EthStorageContract.sol @@ -18,6 +18,7 @@ contract EthStorageContract is StorageContract, Decoder { address _treasury, address _owner ) public payable initializer { + require(msg.value >= prepaidAmount, "prepaid amount is not enough"); __init_storage(_treasury, _owner); } diff --git a/scripts/deploy.js b/scripts/deploy.js index ffe9ca5..051c305 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -9,6 +9,8 @@ const adminContractAddr = "0x11aceF404143514dbe0C1477250605646754F9e6"; const storageContractProxy = "0x804C520d3c084C805E37A35E90057Ac32831F96f"; const gasPrice = null; +const prepaidAmount = 3145728000000000000000n; // prepaidAmount - 50% * 2^39 / 131072 * 1500000Gwei, it also means 3145 ETH for half of the shard + async function deployContract() { const [deployer] = await hre.ethers.getSigners(); ownerAddress = deployer.address; @@ -27,7 +29,10 @@ async function deployContract() { ]); console.log(impl, ownerAddress, data); const EthStorageUpgradeableProxy = await hre.ethers.getContractFactory("EthStorageUpgradeableProxy"); - const ethStorageProxy = await EthStorageUpgradeableProxy.deploy(impl, ownerAddress, data, { gasPrice: gasPrice }); + const ethStorageProxy = await EthStorageUpgradeableProxy.deploy(impl, ownerAddress, data, { + gasPrice: gasPrice, + value: prepaidAmount + }); await ethStorageProxy.deployed(); const admin = await ethStorageProxy.admin(); @@ -40,12 +45,13 @@ async function deployContract() { "at", new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" }) ); + console.log("balance of " + ethStorageProxy.address, await hre.ethers.provider.getBalance(ethStorageProxy.address)); // fund 0.5 eth into the storage contract to give reward for empty mining - const ethStorage = StorageContract.attach(ethStorageProxy.address); - const tx = await ethStorage.sendValue({ value: hre.ethers.utils.parseEther("0.5") }); - await tx.wait(); - console.log("balance of " + ethStorage.address, await hre.ethers.provider.getBalance(ethStorage.address)); + // const ethStorage = StorageContract.attach(ethStorageProxy.address); + // const tx = await ethStorage.sendValue({ value: hre.ethers.utils.parseEther("0.5") }); + // await tx.wait(); + // console.log("balance of " + ethStorage.address, await hre.ethers.provider.getBalance(ethStorage.address)); // save address to file const addresses = { From 83b72b9325d0b9ccb5cab3e23f109c3b839566f4 Mon Sep 17 00:00:00 2001 From: iteye Date: Thu, 13 Jun 2024 17:55:45 +0800 Subject: [PATCH 2/2] fix deploy.js --- scripts/deploy.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/deploy.js b/scripts/deploy.js index 4b6c6a6..957e7aa 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -19,6 +19,7 @@ const config = [ ]; const storageCost = 1500000000000000; // storageCost - 1,500,000Gwei forever per blob - https://ethresear.ch/t/ethstorage-scaling-ethereum-storage-via-l2-and-da/14223/6#incentivization-for-storing-m-physical-replicas-1 const dcfFactor = 340282366367469178095360967382638002176n; // dcfFactor, it mean 0.95 for yearly discount +const prepaidAmount = 3145728000000000000000n; // prepaidAmount - 50% * 2^39 / 131072 * 1500000Gwei, it also means 3145 ETH for half of the shard async function verifyContract(contract, args) { if (!process.env.ETHERSCAN_API_KEY) { @@ -52,16 +53,20 @@ async function deployContract() { const data = implContract.interface.encodeFunctionData("initialize", [ 4718592000, // minimumDiff 5 * 3 * 3600 * 1024 * 1024 / 12 = 4718592000 for 5 replicas that can have 1M IOs in one epoch - 3145728000000000000000n, // prepaidAmount - 50% * 2^39 / 131072 * 1500000Gwei, it also means 3145 ETH for half of the shard + prepaidAmount, // prepaidAmount - 50% * 2^39 / 131072 * 1500000Gwei, it also means 3145 ETH for half of the shard 1048576, // nonceLimit 1024 * 1024 = 1M samples and finish sampling in 1.3s with IO rate 6144 MB/s: 4k * 2(random checks) / 6144 = 1.3s treasuryAddress, // treasury ownerAddress, ]); console.log(impl, ownerAddress, data); const EthStorageUpgradeableProxy = await hre.ethers.getContractFactory("EthStorageUpgradeableProxy"); - const ethStorageProxy = await EthStorageUpgradeableProxy.deploy(impl, ownerAddress, data, { gasPrice: gasPrice }); + const ethStorageProxy = await EthStorageUpgradeableProxy.deploy(impl, ownerAddress, data, { + gasPrice: gasPrice, + value: prepaidAmount + }); await ethStorageProxy.deployed(); const admin = await ethStorageProxy.admin(); + console.log("balance of " + ethStorageProxy.address, await hre.ethers.provider.getBalance(ethStorageProxy.address)); console.log("storage admin address is ", admin); console.log("storage contract address is ", ethStorageProxy.address); @@ -73,11 +78,11 @@ async function deployContract() { new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" }) ); - // fund 0.5 eth into the storage contract to give reward for empty mining - const ethStorage = StorageContract.attach(ethStorageProxy.address); - const tx = await ethStorage.sendValue({ value: hre.ethers.utils.parseEther("0.5") }); - await tx.wait(); - console.log("balance of " + ethStorage.address, await hre.ethers.provider.getBalance(ethStorage.address)); + // // fund 0.5 eth into the storage contract to give reward for empty mining + // const ethStorage = StorageContract.attach(ethStorageProxy.address); + // const tx = await ethStorage.sendValue({ value: hre.ethers.utils.parseEther("0.5") }); + // await tx.wait(); + // console.log("balance of " + ethStorageProxy.address, await hre.ethers.provider.getBalance(ethStorageProxy.address)); // verify contract await verifyContract(ethStorageProxy.address);