mirror of
https://github.com/codex-storage/codex-contracts-eth.git
synced 2025-02-13 11:56:46 +00:00
Deploy 2 versions of the marketplace on local network
One with the real Groth16 verifier, and one with a dummy verifier used for testing.
This commit is contained in:
parent
ec803adb3d
commit
c7b18af7cd
@ -1,27 +1,22 @@
|
|||||||
const { loadZkeyHash } = require ("../verifier/verifier.js")
|
const { loadZkeyHash } = require("../verifier/verifier.js")
|
||||||
|
|
||||||
const MARKETPLACE_HARDCODED_ADDRESS = "0x59b670e9fA9D0A427751Af201D676719a970857b"
|
// hardcoded addresses when deploying on local network
|
||||||
|
const MARKETPLACE_REAL = "0x59b670e9fA9D0A427751Af201D676719a970857b"
|
||||||
|
const MARKETPLACE_TEST = "0xfacadee9fA9D0A427751Af201D676719a9facade"
|
||||||
|
|
||||||
async function deployMarketplace({ deployments, getNamedAccounts, network }) {
|
// marketplace configuration
|
||||||
const token = await deployments.get("TestToken")
|
const CONFIGURATION = {
|
||||||
const verifier = await deployments.get("Groth16Verifier")
|
collateral: {
|
||||||
const configuration = {
|
repairRewardPercentage: 10,
|
||||||
collateral: {
|
maxNumberOfSlashes: 5,
|
||||||
repairRewardPercentage: 10,
|
slashCriterion: 3,
|
||||||
maxNumberOfSlashes: 5,
|
slashPercentage: 10,
|
||||||
slashCriterion: 3,
|
},
|
||||||
slashPercentage: 10,
|
proofs: {
|
||||||
},
|
period: 10,
|
||||||
proofs: {
|
timeout: 5,
|
||||||
period: 10,
|
downtime: 64,
|
||||||
timeout: 5,
|
},
|
||||||
downtime: 64,
|
|
||||||
zkeyHash: loadZkeyHash(network.name),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const args = [configuration, token.address, verifier.address]
|
|
||||||
const { deployer } = await getNamedAccounts()
|
|
||||||
await deployments.deploy("Marketplace", { args, from: deployer })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function mine256blocks({ network, ethers }) {
|
async function mine256blocks({ network, ethers }) {
|
||||||
@ -30,24 +25,49 @@ async function mine256blocks({ network, ethers }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function aliasContract({deployments, network}) {
|
async function aliasContract(address, alias) {
|
||||||
|
if (address !== alias) {
|
||||||
|
await ethers.provider.send("hardhat_setCode", [alias, address])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// deploys a marketplace with a real Groth16 verifier
|
||||||
|
async function deployMarketplace({ network, deployments, getNamedAccounts }) {
|
||||||
|
const token = await deployments.get("TestToken")
|
||||||
|
const verifier = await deployments.get("Groth16Verifier")
|
||||||
|
const zkeyHash = loadZkeyHash(network.name)
|
||||||
|
const configuration = { ...CONFIGURATION, zkeyHash }
|
||||||
|
const args = [configuration, token.address, verifier.address]
|
||||||
|
const { deployer: from } = await getNamedAccounts()
|
||||||
|
const marketplace = await deployments.deploy("Marketplace", { args, from })
|
||||||
if (network.tags.local) {
|
if (network.tags.local) {
|
||||||
const marketplaceDeployment = await deployments.get("Marketplace")
|
await aliasContract(marketplace.address, MARKETPLACE_REAL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (marketplaceDeployment.address === MARKETPLACE_HARDCODED_ADDRESS) {
|
// deploys a marketplace with a testing verifier
|
||||||
return
|
async function deployTestMarketplace({
|
||||||
}
|
network,
|
||||||
|
deployments,
|
||||||
console.log(`Aliasing marketplace from address ${marketplaceDeployment.address} to ${MARKETPLACE_HARDCODED_ADDRESS}`)
|
getNamedAccounts,
|
||||||
await ethers.provider.send("hardhat_setCode", [MARKETPLACE_HARDCODED_ADDRESS, marketplaceDeployment.address])
|
}) {
|
||||||
|
if (network.tags.local) {
|
||||||
|
const token = await deployments.get("TestToken")
|
||||||
|
const verifier = await deployments.get("TestVerifier")
|
||||||
|
const zkeyHash = loadZkeyHash(network.name)
|
||||||
|
const configuration = { ...CONFIGURATION, zkeyHash }
|
||||||
|
const args = [configuration, token.address, verifier.address]
|
||||||
|
const { deployer: from } = await getNamedAccounts()
|
||||||
|
const marketplace = await deployments.deploy("Marketplace", { args, from })
|
||||||
|
await aliasContract(marketplace.address, MARKETPLACE_TEST)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = async (environment) => {
|
module.exports = async (environment) => {
|
||||||
await mine256blocks(environment)
|
await mine256blocks(environment)
|
||||||
await deployMarketplace(environment)
|
await deployMarketplace(environment)
|
||||||
await aliasContract(environment)
|
await deployTestMarketplace(environment)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.tags = ["Marketplace"]
|
module.exports.tags = ["Marketplace"]
|
||||||
module.exports.dependencies = ["TestToken", "Groth16Verifier"]
|
module.exports.dependencies = ["TestToken", "Verifier"]
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
const { loadVerificationKey } = require ("../verifier/verifier.js")
|
const { loadVerificationKey } = require("../verifier/verifier.js")
|
||||||
|
|
||||||
module.exports = async ({ deployments, getNamedAccounts, network }) => {
|
async function deployVerifier({ deployments, getNamedAccounts }) {
|
||||||
const { deployer } = await getNamedAccounts()
|
const { deployer } = await getNamedAccounts()
|
||||||
const verificationKey = loadVerificationKey(network.name)
|
const verificationKey = loadVerificationKey(network.name)
|
||||||
await deployments.deploy("Groth16Verifier", { args: [verificationKey], from: deployer })
|
await deployments.deploy("Groth16Verifier", {
|
||||||
|
args: [verificationKey],
|
||||||
|
from: deployer,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.tags = ["Groth16Verifier"]
|
async function deployTestVerifier({ network, deployments, getNamedAccounts }) {
|
||||||
|
if (network.tags.local) {
|
||||||
|
const { deployer } = await getNamedAccounts()
|
||||||
|
await deployments.deploy("TestVerifier", { from: deployer })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = async (environment) => {
|
||||||
|
await deployVerifier(environment)
|
||||||
|
await deployTestVerifier(environment)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.tags = ["Verifier"]
|
||||||
|
@ -30,7 +30,7 @@ describe("Proofs", function () {
|
|||||||
await snapshot()
|
await snapshot()
|
||||||
await ensureMinimumBlockHeight(256)
|
await ensureMinimumBlockHeight(256)
|
||||||
const Proofs = await ethers.getContractFactory("TestProofs")
|
const Proofs = await ethers.getContractFactory("TestProofs")
|
||||||
await deployments.fixture(["Groth16Verifier"])
|
await deployments.fixture(["Verifier"])
|
||||||
const verifier = await deployments.get("Groth16Verifier")
|
const verifier = await deployments.get("Groth16Verifier")
|
||||||
proofs = await Proofs.deploy(
|
proofs = await Proofs.deploy(
|
||||||
{ period, timeout, downtime, zkeyHash: "" },
|
{ period, timeout, downtime, zkeyHash: "" },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user