Skip to content

Commit

Permalink
feat(init): first pass hh script marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbeckers committed Nov 9, 2023
1 parent fc0161d commit 1be339c
Show file tree
Hide file tree
Showing 5 changed files with 1,043 additions and 12 deletions.
4 changes: 4 additions & 0 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@nomicfoundation/hardhat-chai-matchers";
import "@openzeppelin/hardhat-upgrades";
import "@openzeppelin/defender-sdk";

import "@primitivefi/hardhat-dodoc";
import { config as dotenvConfig } from "dotenv";
Expand Down Expand Up @@ -137,6 +138,9 @@ const config: HardhatUserConfig = {
],
},
networks: {
fork: {
url: `https://eth-goerli.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
},
hardhat: {
// Setting this is necessary for metamask to work with hardhat. Otherwise
// metamask can't transfer when connected to hardhat's network.
Expand Down
1 change: 1 addition & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@looksrare/contracts-libs": "^3.4.0",
"@nomicfoundation/hardhat-toolbox": "^3.0.0",
"@openzeppelin/contracts": "<5.0.0",
"@openzeppelin/defender-sdk": "^1.4.0",
"@openzeppelin/hardhat-upgrades": "2.3.3",
"@primitivefi/hardhat-dodoc": "^0.2.3",
"@rollup/plugin-commonjs": "^24.0.1",
Expand Down
146 changes: 146 additions & 0 deletions contracts/tasks/deploy-marketplace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { task } from "hardhat/config";
import { BytesLike, getAddress, keccak256, solidityPacked } from "ethers";

function getCreate2Address(name: string, factoryAddress: `0x${string}`, bytecode: BytesLike) {
const deployer = "0xdf2C3dacE6F31e650FD03B8Ff72beE82Cb1C199A";
const version = 1;

const salt = keccak256(solidityPacked(["address", "uint256", "string"], [deployer, version, name]));

const create2Inputs = ["0xff", factoryAddress, salt, keccak256(bytecode)];
const sanitizedInputs = `0x${create2Inputs.map((i) => i.slice(2)).join("")}`;
return { address: getAddress(`0x${keccak256(sanitizedInputs).slice(-40)}`), salt };
}

task("deploy-marketplace", "Deploy marketplace contracts and verify")
.addOptionalParam("output", "write the details of the deployment to this file if this is set")
.setAction(async ({ output }, hre) => {
const { ethers, network, defender, run } = hre;

const HypercertsExchange = await ethers.getContractFactory("LooksRareProtocol");
const TransferManager = await ethers.getContractFactory("TransferManager");
const OrderValidator = await ethers.getContractFactory("OrderValidatorV2A");
const StrategyCollectionOffer = await ethers.getContractFactory("StrategyCollectionOffer");

const _standardProtocolFeeBP = 50;
const _minTotalFeeBp = 50;
const _maxProtocolFeeBp = 200;

const owner = "0xdf2C3dacE6F31e650FD03B8Ff72beE82Cb1C199A";
const create2Address = "0x0000000000FFe8B47B3e2130213B802212439497";

const defaultApprovalProcess = await defender.getDefaultApprovalProcess();

if (defaultApprovalProcess.address === undefined) {
throw new Error(
`Upgrade approval process with id ${defaultApprovalProcess.approvalProcessId} has no assigned address`,
);
}

// Determine create2 address HypercertsExchange
const { address: hypercertsExchangeAddress, salt } = getCreate2Address(
"HypercertsExchange",
create2Address,
HypercertsExchange.bytecode,
);

console.log("Calculated address using CREATE2: ", hypercertsExchangeAddress);
// Deploy transferManager
const transferManager = await defender.deployContract(TransferManager, [owner], { salt });
await transferManager.deployed();

// Transfer 1 wei to hypercertsExchange
await (
await ethers.provider.getSigner()
).sendTransaction({
to: hypercertsExchangeAddress,
value: 1,
});

// Deploy HypercertsExchange
const protocolFeeRecipient = owner;
const transferManagerAddress = transferManager.address;
const wethAddress = "0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6";
const hypercertsExchange = await defender.deployContract(HypercertsExchange, [
owner,
protocolFeeRecipient,
transferManagerAddress,
wethAddress,
]);

// Allow Exchange as operator on transferManager
transferManager.allowOperator(hypercertsExchange.address);

// Update currencyStatus address(0) to true
hypercertsExchange.updateCurrencyStatus("0x0000000000000000000000000000000000000000", true);

// Update currencyStatus address(weth) to true
hypercertsExchange.updateCurrencyStatus("0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", true);

// Deploy OrderValidator
const orderValidator = await defender.deployContract(OrderValidator, [hypercertsExchange.address]);
await orderValidator.deployed();

// Deploy strategyCollectionOffer
const strategyCollectionOfferInstance = await defender.deployContract(StrategyCollectionOffer);
await strategyCollectionOfferInstance.deployed();

// Add executeCollectionStrategyWithTakerAsk strategy to HypercertsExchange

hypercertsExchange.addStrategy(
_standardProtocolFeeBP,
_minTotalFeeBp,
_maxProtocolFeeBp,
strategyCollectionOfferInstance.interface.getFunction("executeCollectionStrategyWithTakerAsk").selector,
true,
strategyCollectionOfferInstance.address,
);

hypercertsExchange.addStrategy(
_standardProtocolFeeBP,
_minTotalFeeBp,
_maxProtocolFeeBp,
strategyCollectionOfferInstance.interface.getFunction("executeCollectionStrategyWithTakerAskWithProof").selector,
true,
strategyCollectionOfferInstance.address,
);

// Add executeCollectionStrategyWithTakerAskWithProof strategy to HypercertsExchange

// Done!

// If the `deploymentFile` option is set then write the deployed address to
// a json object on disk. This is intended to be deliberate with how we
// output the contract address and other contract information.
// if (output) {
// const txReceipt = await contract.provider.getTransactionReceipt(hypercertMinter.deployTransaction.hash);
// await writeFile(
// output,
// JSON.stringify({
// address: hypercertMinter.address,
// blockNumber: txReceipt.blockNumber,
// }),
// "utf-8",
// );
// }

// if (network.name !== "hardhat" && network.name !== "localhost") {
// try {
// const code = await hypercertMinter.instance?.provider.getCode(hypercertMinter.address);
// if (code === "0x") {
// console.log(`${hypercertMinter.name} contract deployment has not completed. waiting to verify...`);
// await hypercertMinter.instance?.deployed();
// }
// await run("verify:verify", {
// address: hypercertMinter.address,
// });
// } catch (error) {
// const errorMessage = (error as Error).message;

// if (errorMessage.includes("Reason: Already Verified")) {
// console.log("Reason: Already Verified");
// }
// console.error(errorMessage);
// }
// }
});
1 change: 1 addition & 0 deletions contracts/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from "./test-tx-client";
export * from "./upgrade";
export * from "./unpause";
export * from "./validate-upgrade";
export * from "./deploy-marketplace";
Loading

0 comments on commit 1be339c

Please sign in to comment.