-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only allow auctions to be started at most once a month per token #254
Only allow auctions to be started at most once a month per token #254
Conversation
5f961d0
to
9a1011c
Compare
Hi @area, can I get a review? I'm also unable to change the label. |
@@ -70,4 +70,7 @@ contract ColonyNetworkStorage is DSAuth { | |||
uint256 reputationRootHashNNodes; | |||
// Mapping containing how much has been staked by each user | |||
mapping (address => uint) stakedBalances; | |||
|
|||
// Mapping containing the last auction start timestamp for a token address | |||
mapping (address => uint) recentAuctions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an idea to map token address to auction address and get the start time off that. This would give us a mapping for the latest token auction (which is not maintained on-chain currently but probably should be) and additionally avoid duplicating the startTime
value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the auction contracts selfdestruct when complete, we'd have to check that there was still a contract there before trying to call startTime
on it, otherwise we'd revert. That's fairly straightforward to do in assembly with the extcodesize
call though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, you're right. But we probably won't be able to determine if a month has gone by if the auction contract is destroyed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, also true, I hadn't considered that an auction could finish within the 30 days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave it as is then. At most we might add the auction contract address record to this mapping at some point.
contracts/ColonyNetworkAuction.sol
Outdated
@@ -28,10 +28,14 @@ contract ColonyNetworkAuction is ColonyNetworkStorage { | |||
event AuctionCreated(address auction, address token, uint256 quantity); | |||
|
|||
function startTokenAuction(address _token) public { | |||
uint lastAuctionTimestamp = recentAuctions[_token]; | |||
require(lastAuctionTimestamp == 0 || now - lastAuctionTimestamp >= 30 days, "An auction may only be started once every 30 days."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been using kebab-case messages in requires. So something like colony-auction-start-too-soon
would be appropriate here; the primary use case we're targeting is for clients to be able to interpret them with user-friendly messages, not for users to see them themselves.
@@ -70,4 +70,7 @@ contract ColonyNetworkStorage is DSAuth { | |||
uint256 reputationRootHashNNodes; | |||
// Mapping containing how much has been staked by each user | |||
mapping (address => uint) stakedBalances; | |||
|
|||
// Mapping containing the last auction start timestamp for a token address | |||
mapping (address => uint) recentAuctions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the auction contracts selfdestruct when complete, we'd have to check that there was still a contract there before trying to call startTime
on it, otherwise we'd revert. That's fairly straightforward to do in assembly with the extcodesize
call though.
9a1011c
to
d7a0fb9
Compare
I was on vacation the last few days so I did not get around to working on this. I just pushed an update to address the review comments. Can you mark this as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, only a couple of things left to address. When you've dealt with my comments, make sure to rebase on the currentdevelop
branch too so we can merge it in.
contracts/ColonyNetworkAuction.sol
Outdated
address clny = IColony(metaColony).getToken(); | ||
DutchAuction auction = new DutchAuction(clny, _token); | ||
uint availableTokens = ERC20Extended(_token).balanceOf(this); | ||
ERC20Extended(_token).transfer(auction, availableTokens); | ||
auction.start(); | ||
recentAuctions[_token] = auction.startTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the call to auction.startTime()
here? Why not just now
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe both evaluate to the same value. Does using auction.startTime()
incur a higher cost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, a call to an external contract is going to cost more than reading the state by about 2000 gas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Latest push addresses all the comments and rebases onto current develop
branch.
test/colony-network-auction.js
Outdated
await token.mint(quantity.toString()); | ||
await token.transfer(colonyNetwork.address, quantity.toString()); | ||
await colonyNetwork.startTokenAuction(token.address); | ||
const newAuctionStartTime = await tokenAuction.startTime.call(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be a need for the .call()
here. I know we explicitly use call
elsewhere in the file, but that's a relic from days gone by, and we've been trying to remove it where possible / not introduce more ones. Same on L194 as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. I changed the old startTime.call()
usage on L104 too.
356054d
to
980c82e
Compare
980c82e
to
bb8ffe4
Compare
Closes #185