Skip to content
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

Merged

Conversation

KevinLiLu
Copy link
Contributor

@KevinLiLu KevinLiLu commented Jun 30, 2018

Closes #185

  • Make auction start immediately upon creation
  • Only allow auctions to be started at most once a month (per token)

@KevinLiLu KevinLiLu force-pushed the feature/185-limit-auctions-to-once-a-month branch from 5f961d0 to 9a1011c Compare July 3, 2018 16:23
@KevinLiLu
Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor

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.

@elenadimitrova elenadimitrova requested a review from area July 6, 2018 06:25
@@ -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.");
Copy link
Member

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;
Copy link
Member

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.

@KevinLiLu KevinLiLu force-pushed the feature/185-limit-auctions-to-once-a-month branch from 9a1011c to d7a0fb9 Compare July 10, 2018 04:10
@KevinLiLu
Copy link
Contributor Author

@elenadimitrova @area

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 ready-for-review again?

Copy link
Member

@area area left a 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.

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();
Copy link
Member

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?

Copy link
Contributor Author

@KevinLiLu KevinLiLu Jul 11, 2018

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

await token.mint(quantity.toString());
await token.transfer(colonyNetwork.address, quantity.toString());
await colonyNetwork.startTokenAuction(token.address);
const newAuctionStartTime = await tokenAuction.startTime.call();
Copy link
Member

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.

Copy link
Contributor Author

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.

@KevinLiLu KevinLiLu force-pushed the feature/185-limit-auctions-to-once-a-month branch 2 times, most recently from 356054d to 980c82e Compare July 11, 2018 04:50
@KevinLiLu KevinLiLu force-pushed the feature/185-limit-auctions-to-once-a-month branch from 980c82e to bb8ffe4 Compare July 11, 2018 07:22
@area area merged commit 6674f0c into JoinColony:develop Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants