Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
killroy192 committed Mar 6, 2024
1 parent 5007465 commit 51b451b
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-include .env

.PHONY: all test clean install compile snapshot
.PHONY: all test clean install compile snapshot run

all: clean install test

Expand Down Expand Up @@ -35,6 +35,6 @@ task?=mine

deploy :; npx hardhat --network $(network) deploy-bundle

task :; npx hardhat --network $(network) $(task)
run :; npx hardhat --network $(network) $(task)

-include ${FCT_PLUGIN_PATH}/makefile-external
8 changes: 8 additions & 0 deletions deployment.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const { VerifyPlugin } = require("@dgma/hardhat-sol-bundler/plugins/Verify");
const { dynamicAddress, SupportedProxies } = require("@dgma/hardhat-sol-bundler");

const config = {
SwapToken: {
contractName: "SomeToken",
args: ["SWT", "Swap Token"],
},
RedeemToken: {
contractName: "SomeToken",
args: ["RT", "Redeem Token"],
},
Utils: {},
DutchAuctionHouse: {
options: {
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require("@nomicfoundation/hardhat-foundry");
require("@nomicfoundation/hardhat-toolbox");
require("@openzeppelin/hardhat-upgrades");
require("@dgma/hardhat-sol-bundler");
require('./tasks');
const { ZeroHash } = require("ethers");
const deployments = require("./deployment.config");

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@openzeppelin/contracts-upgradeable": "^5.0.2"
},
"devDependencies": {
"@dgma/hardhat-sol-bundler": "^0.5.4",
"@dgma/hardhat-sol-bundler": "^0.5.6",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@nomicfoundation/hardhat-foundry": "^1.1.1",
"@nomicfoundation/hardhat-network-helpers": "^1.0.10",
Expand Down
35 changes: 23 additions & 12 deletions src/DutchAuctionHouse.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.16;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand All @@ -22,7 +22,7 @@ import {
HasNotFinished
} from "./DutchAuctionHouse.types.sol";

contract DutchAuctionHouse is IDutchAuctionHouse, Ownable {
contract DutchAuctionHouse is IDutchAuctionHouse, OwnableUpgradeable {
using Math for uint256;
using Utils for uint256;
using EnumerableSet for EnumerableSet.Bytes32Set;
Expand Down Expand Up @@ -62,13 +62,27 @@ contract DutchAuctionHouse is IDutchAuctionHouse, Ownable {
_;
}

constructor() Ownable(msg.sender) {}
constructor() {
_disableInitializers();
}

function initialize(address owner, uint256 lotSize_, uint256 stepRate_, uint8 stepLength_)
external
initializer
{
__Ownable_init(owner);
_setHouseParams(lotSize_, stepRate_, stepLength_);
}

function setHouseParams(uint256 lotSize_, uint256 stepRate_, uint8 stepLength_)
public
onlyOwner
onlyNotActiveHouse
{
_setHouseParams(lotSize_, stepRate_, stepLength_);
}

function _setHouseParams(uint256 lotSize_, uint256 stepRate_, uint8 stepLength_) private {
stepRate = stepRate_;
stepLength = stepLength_;
lotSize = lotSize_;
Expand Down Expand Up @@ -196,18 +210,14 @@ contract DutchAuctionHouse is IDutchAuctionHouse, Ownable {
emit AuctionEnds(id);
}

function getActiveAuctions()
external
view
returns (ActiveAuctionReport[] memory activeAuctionReport)
{
function getActiveAuctions() external view returns (ActiveAuctionReport[] memory) {
uint256 len = auctionsSet.length();
activeAuctionReport = new ActiveAuctionReport[](len);
ActiveAuctionReport[] memory activeAuctionReport = new ActiveAuctionReport[](len);
bytes32 id;
for (uint256 index = 0; index < len; index++) {
id = auctionsSet.at(index);
for (uint256 i = 0; i < len; i++) {
id = auctionsSet.at(i);
Auction memory auction = auctions[id];
activeAuctionReport[index] = ActiveAuctionReport({
activeAuctionReport[i] = ActiveAuctionReport({
stepRate: _ratePerStep(id),
step: _step(id, block.number) + 1,
amountToCollect: auction.amountToCollect,
Expand All @@ -218,5 +228,6 @@ contract DutchAuctionHouse is IDutchAuctionHouse, Ownable {
redeemToken: auction.redeemToken
});
}
return activeAuctionReport;
}
}
8 changes: 4 additions & 4 deletions src/DutchAuctionHouse.types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ interface IDutchAuctionHouseEvents {
}

interface IDutchAuctionHouse is IDutchAuctionHouseEvents {
function initialize(address owner, uint256 lotSize_, uint256 stepRate_, uint8 stepLength_)
external;

function setHouseParams(uint256 lotSize_, uint256 stepRate_, uint8 stepLength_) external;

function isAuctionHouseActive() external view returns (bool);
Expand Down Expand Up @@ -73,8 +76,5 @@ interface IDutchAuctionHouse is IDutchAuctionHouseEvents {

function close(bytes32 id) external;

function getActiveAuctions()
external
view
returns (ActiveAuctionReport[] memory activeAuctionReport);
function getActiveAuctions() external view returns (ActiveAuctionReport[] memory);
}
10 changes: 5 additions & 5 deletions src/DutchAuctionHousesManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.16;

import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";

Expand All @@ -20,7 +19,7 @@ contract DutchAuctionHousesManager is OwnableUpgradeable, UUPSUpgradeable {
mapping(address => EnumerableSet.AddressSet) private auctionHouses;

modifier onlyHouseOwner(address auctionHouseInstance) {
if (Ownable(auctionHouseInstance).owner() != msg.sender) {
if (OwnableUpgradeable(auctionHouseInstance).owner() != msg.sender) {
revert WrongOwnership();
}
_;
Expand All @@ -41,7 +40,7 @@ contract DutchAuctionHousesManager is OwnableUpgradeable, UUPSUpgradeable {
__Ownable_init(msg.sender);
}

function upgradeCallback(address) external reinitializer(2) {}
function upgradeCallBack() external reinitializer(2) {}

Check warning on line 43 in src/DutchAuctionHousesManager.sol

View workflow job for this annotation

GitHub Actions / lint

Code contains empty blocks

function _authorizeUpgrade(address) internal view override onlyOwner {}

Check warning on line 45 in src/DutchAuctionHousesManager.sol

View workflow job for this annotation

GitHub Actions / lint

Code contains empty blocks

Expand All @@ -50,8 +49,9 @@ contract DutchAuctionHousesManager is OwnableUpgradeable, UUPSUpgradeable {
returns (address auctionHouseInstance)
{
auctionHouseInstance = Clones.clone(address(auctionHouse));
IDutchAuctionHouse(auctionHouseInstance).setHouseParams(lotSize, stepRate, stepLength);
Ownable(auctionHouseInstance).transferOwnership(msg.sender);
IDutchAuctionHouse(auctionHouseInstance).initialize(
msg.sender, lotSize, stepRate, stepLength
);
auctionHouses[msg.sender].add(auctionHouseInstance);
emit AuctionCreated(msg.sender, auctionHouseInstance);
}
Expand Down
31 changes: 31 additions & 0 deletions tasks/auction/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { task } = require("hardhat/config");
const { getLock, getDeployment } = require("@dgma/hardhat-sol-bundler");

const CREATE_AUCTION = "create-auction";

task(CREATE_AUCTION, "Create public auction").setAction(async (_, hre) => {
const { DutchPublicAuctionHouse, DutchAuctionHousesManager, RedeemToken } = getLock(
getDeployment(hre)?.lockFile,
)[hre.network.name];

const DutchPublicAuctionHouseContract = await hre.ethers.getContractAt(
DutchPublicAuctionHouse.abi,
DutchPublicAuctionHouse.address,
);

const DutchAuctionHousesManagerContract = await hre.ethers.getContractAt(
DutchAuctionHousesManager.abi,
DutchAuctionHousesManager.address,
);

const RedeemTokenContract = await hre.ethers.getContractAt(RedeemToken.abi, RedeemToken.address);

const decimals = Number(await RedeemTokenContract.decimals());

await DutchAuctionHousesManagerContract.createHouse(
hre.ethers.parseUnits("1", decimals - 1),
hre.ethers.parseUnits("125", 4),
"3",
DutchPublicAuctionHouse.address,
);
});
2 changes: 1 addition & 1 deletion tasks/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require("./mine");
require("./mint");
require("./postDeploy");
require("./auction/create");
15 changes: 9 additions & 6 deletions tasks/mint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ const { getLock, getDeployment } = require("@dgma/hardhat-sol-bundler");

const MINT_COLLATERAL = "mint";

const mintToken = async (lockContract, amount, address) => {
const Contract = await hre.ethers.getContractAt(lockContract.abi, lockContract.address);
await Contract.mint(address, hre.ethers.parseEther(amount));
};

task(MINT_COLLATERAL, "Mint SlopeCollateral tokens to faucet").setAction(async (_, hre) => {
const { SlopeCollateral } = getLock(getDeployment(hre)?.lockFile)[hre.network.name];
const SlopeCollateralContract = await hre.ethers.getContractAt(
SlopeCollateral.abi,
SlopeCollateral.address,
);
const { SwapToken, RedeemToken } = getLock(getDeployment(hre)?.lockFile)[hre.network.name];
const defaultAddr = (await hre.ethers.getSigners())[0].address;
const faucetAddr =
hre.network.name === "localhost" ? defaultAddr : config?.parsed?.FAUCET_ADDRESS || defaultAddr;
await SlopeCollateralContract.mint(faucetAddr, hre.ethers.parseEther("10000"));

await mintToken(SwapToken, "100", faucetAddr);
await mintToken(RedeemToken, "1000", faucetAddr);
});
Empty file removed tasks/postDeploy.js
Empty file.
6 changes: 4 additions & 2 deletions test/DutchAuctionHouse.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pragma solidity ^0.8.16;
import "@std/Test.sol";

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";

import {TestUtils} from "./TestUtils.sol";
import {SomeToken} from "src/SomeToken.sol";

Expand Down Expand Up @@ -53,8 +55,8 @@ contract DutchAuctionHouseTest is IDutchAuctionHouseEvents, Test {
swapToken.mint(address(this), amountToCollect);
redeemToken.mint(address(this), amountToDistribute);

auctionHouse = new DutchAuctionHouse();
auctionHouse.setHouseParams(lotSize, stepRate, stepLength);
auctionHouse = DutchAuctionHouse(Clones.clone(address(new DutchAuctionHouse())));
auctionHouse.initialize(address(this), lotSize, stepRate, stepLength);
}

function _maxFizzAuctionBlocks() private view returns (uint256) {
Expand Down
6 changes: 4 additions & 2 deletions test/DutchPublicAuctionHouse.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pragma solidity ^0.8.16;
import "@std/Test.sol";

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";

import {TestUtils} from "./TestUtils.sol";
import {SomeToken} from "src/SomeToken.sol";

Expand Down Expand Up @@ -52,8 +54,8 @@ contract DutchPublicAuctionHouseTest is Test {
swapToken.mint(notOwner, amountToCollect);
redeemToken.mint(address(this), amountToDistribute);

auctionHouse = new DutchPublicAuctionHouse();
auctionHouse.setHouseParams(lotSize, stepRate, stepLength);
auctionHouse = DutchPublicAuctionHouse(Clones.clone(address(new DutchPublicAuctionHouse())));
auctionHouse.initialize(address(this), lotSize, stepRate, stepLength);

redeemToken.approve(address(auctionHouse), type(uint256).max);

Expand Down

0 comments on commit 51b451b

Please sign in to comment.