Skip to content

Commit

Permalink
implement decimals setting
Browse files Browse the repository at this point in the history
  • Loading branch information
killroy192 committed Mar 9, 2024
1 parent 67947df commit cc4db99
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "@dgma/reverse-dutch-auction",
"version": "0.0.2",
"version": "0.0.3",
"description": "Contracts for dutch reverse auction implementation",
"files": [
"src/*"
Expand Down
4 changes: 0 additions & 4 deletions src/OpenRDA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ contract OpenRDA is RDA, RDAEvents {

constructor() RDA() {}

function decimals() public pure override returns (uint8) {
return 8;
}

function begin(
bytes32 id,
uint256 amountToCollect,
Expand Down
12 changes: 8 additions & 4 deletions src/RDA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ abstract contract RDA is IRDA, OwnableUpgradeable, RDABase {
_disableInitializers();
}

function initialize(address owner, uint256 lotSize_, uint256 stepRate_, uint8 stepLength_)
external
initializer
{
function initialize(
address owner,
uint256 lotSize_,
uint256 stepRate_,
uint8 stepLength_,
uint8 decimals_
) external initializer {
decimals = decimals_;
__Ownable_init(owner);
_setHouseParams(lotSize_, stepRate_, stepLength_);
}
Expand Down
13 changes: 7 additions & 6 deletions src/RDA.types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ struct Bid {
uint256 toRedeem;
}

interface IRDAMeta {
function decimals() external pure returns (uint8);
}

interface IRDA {
function initialize(address owner, uint256 lotSize_, uint256 stepRate_, uint8 stepLength_)
external;
function initialize(
address owner,
uint256 lotSize_,
uint256 stepRate_,
uint8 stepLength_,
uint8 decimals_
) external;

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

Expand Down
12 changes: 4 additions & 8 deletions src/RDABase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {EnumerableSet} from "node_modules/@openzeppelin/contracts/utils/structs/
import {RDAMathLib} from "./RDAMathLib.sol";

import {
IRDAMeta,
Auction,
AuctionStats,
Bid,
Expand All @@ -16,14 +15,15 @@ import {
AuctionNotActive
} from "./RDA.types.sol";

abstract contract RDABase is IRDAMeta {
abstract contract RDABase {
using Math for uint256;
using RDAMathLib for uint256;
using EnumerableSet for EnumerableSet.Bytes32Set;

uint256 public stepRate;
uint256 public stepLength;
uint256 public lotSize;
uint256 public decimals;

mapping(bytes32 => Auction) internal auctions;
EnumerableSet.Bytes32Set internal auctionsSet;
Expand Down Expand Up @@ -51,10 +51,6 @@ abstract contract RDABase is IRDAMeta {
_;
}

// pure getters

function decimals() public pure virtual returns (uint8);

// internal API setters

function _setHouseParams(uint256 lotSize_, uint256 stepRate_, uint8 stepLength_) internal {
Expand Down Expand Up @@ -95,8 +91,8 @@ abstract contract RDABase is IRDAMeta {

// internal API Getters

function _denominator() internal pure returns (uint256) {
return 10 ** decimals();
function _denominator() internal view returns (uint256) {
return 10 ** decimals;
}

function _isAutcionActive(bytes32 id) internal view returns (bool) {
Expand Down
6 changes: 4 additions & 2 deletions test/OpenRDA.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ contract DutchAuctionHouseTest is RDAEvents, Test {
uint256 private amountToCollect;
uint256 private amountToDistribute;

uint8 private constant decimals = 8;

bytes32 private id = keccak256(abi.encode(address(this)));

address private notOwner = makeAddr("alice");
Expand All @@ -55,11 +57,11 @@ contract DutchAuctionHouseTest is RDAEvents, Test {
redeemToken.mint(address(this), amountToDistribute);

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

function _maxFizzAuctionBlocks() private view returns (uint256) {
return Math.mulDiv(stepLength, 10 ** 8, stepRate);
return Math.mulDiv(stepLength, 10 ** decimals, stepRate);
}

function _prepareNotOwnerToBid(uint256 bidAmount) internal {
Expand Down

0 comments on commit cc4db99

Please sign in to comment.