Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Ethereum_Auction_Manager
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
BHAVYA CHOUDHARY
Ethereum_Auction_Manager
Commits
09c1f8f7
Commit
09c1f8f7
authored
Aug 24, 2017
by
BHAVYA CHOUDHARY
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add all the auctions
parent
b0963cbd
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
281 additions
and
57 deletions
+281
-57
Auctions.sol
Auctions.sol
+55
-0
DutchAuction.sol
DutchAuction.sol
+56
-0
EnglishAuction.sol
EnglishAuction.sol
+72
-0
VickreyAuction.sol
VickreyAuction.sol
+98
-57
No files found.
Auctions.sol
0 → 100644
View file @
09c1f8f7
pragma solidity ^0.4.4;
import "DAuction.sol";
import "DVickreyAuction.sol";
import "DDutchAuction.sol";
import "DEnglishAuction.sol";
//This code is provided for you. You can modify if you want to for debugging, but you shouldn't need to put any logic here.
contract DAuctions {
mapping(uint256 => DAuction) auctions;
uint256 numAuctions;
// This function is used for testing
function testAuction(uint256 id) returns (uint256 aid){
return numAuctions;
}
function beginDutchAuction(uint256 reservePrice, address judgeAddress, uint256 biddingTimePeriod, uint256 offerPriceDecrement) returns(uint256 auctionID) {
auctionID = numAuctions++;
auctions[auctionID] = new DDutchAuction(reservePrice, judgeAddress, biddingTimePeriod, offerPriceDecrement);
return auctionID;
}
function beginEnglishAuction(uint256 reservePrice, address judgeAddress, uint256 biddingTimePeriod, uint256 minBidIncrement) returns(uint256 auctionID) {
auctionID = numAuctions++;
auctions[auctionID] = new DEnglishAuction(reservePrice, judgeAddress, biddingTimePeriod, minBidIncrement);
return auctionID;
}
function beginVickreyAuction(uint256 reservePrice, address judgeAddress, uint256 commitTimePeriod, uint256 revealTimePeriod, uint256 bidDepositAmount) returns(uint256 auctionID) {
auctionID = numAuctions++;
auctions[auctionID] = new DVickreyAuction(reservePrice, judgeAddress, commitTimePeriod, revealTimePeriod, bidDepositAmount);
return auctionID;
}
function bid(uint256 id) payable returns(address) {
return auctions[id].bid.value(msg.value)();
}
function finalize(uint256 id) {
auctions[id].finalize();
}
function refund(uint256 id, uint256 amount) {
auctions[id].refund(amount);
}
function revealBid(uint256 id, uint256 nonce) payable returns(address) {
return auctions[id].revealBid.value(msg.value)(nonce);
}
function commitBid(uint256 id, bytes32 bidCommitment) payable returns(bool) {
return auctions[id].commitBid.value(msg.value)(bidCommitment);
}
}
DutchAuction.sol
0 → 100644
View file @
09c1f8f7
pragma solidity ^0.4.4;
import "DAuction.sol";
contract DDutchAuction is DAuction {
uint256 decrementPerBlock;
bool bidover;
uint256 startPrice;
bool refundCalled;
bool finalizeCalled;
// constructor
function DDutchAuction(uint256 reservePrice, address judgeAddress, uint256 biddingPeriod, uint256 offerPriceDecrement) DAuction(reservePrice, biddingPeriod, judgeAddress) {
decrementPerBlock = offerPriceDecrement;
startPrice = reservePrice+biddingPeriod*offerPriceDecrement;
}
function bid() biddingOpen payable returns(address highestBidderAddr){
uint256 currentPrice = startPrice-(block.number-startBlockNum)*decrementPerBlock;
require(msg.value >= currentPrice);
highestBidder = msg.sender;
highestBid = msg.value;
bidover = true;
return highestBidder;
}
function finalize(){
require(msg.sender==highestBidder || msg.sender = judgeAddress);
require(!refundCalled && !finalizeCalled);
finalizeCalled=truel
creator.transfer(highestBid);
}
function refund(uint256 refundAmount) auctionOver judgeOnly {
require(highestBidder!=0);
require(refundAmount<= this.balance);
require(!finalizeCalled && !refundCalled);
refundCalled=true;
highestBidder.transfer(refundAmount);
creator.transfer(this.balance);
}
modifier biddingOpen {
require(block.number<=startBlockNum+biddingBlocksNum);
require(!bidover);
_;
}
modifier auctionOver {
require(block.number>startBlockNum+biddingBlocksNum || bidover);
_;
}
}
EnglishAuction.sol
0 → 100644
View file @
09c1f8f7
pragma solidity ^0.4.4;
import "DAuction.sol";
contract DEnglishAuction is DAuction {
uint256 minBidIncrement;
uint numUnchallengedBlocks;
uint lastBidBlock;
mapping (address => uint) PendingWithdrawals;
bool refundCalled;
bool finalizeCalle
// constructor
function DEnglishAuction(uint256 reservePrice, address judgeAddress, uint256 biddingTimePeriod, uint256 minBidIncrement) DAuction(reservePrice, biddingTimePeriod, judgeAddress) {
this.minBidIncrement = minBidIncrement;
numUnchallengedBlocks = 3;
}
function bid() biddingOpen payable returns(address highestBidderAddr) {
require(msg.value >= minimumPrice);
require(msg.value >= highestBid + minBidIncrement);
if(highestBidder!=0){
if(!highestBidder.send(highestBid)){
PendingWithdrawals[highestBidder]+=highestBid;
}
}
highestBidder = msg.sender;
highestBid = msg.value;
lastBidBlock = block.number;
return highestBidder;
}
function finalize() auctionOver {
require(msg.sender==highestBidder || msg.sender = judgeAddress);
require(!refundCalled && !finalizeCalled);
finalizeCalled=true;
creator.transfer(highestBid);
}
function refund(uint256 refundAmount) auctionOver judgeOnly {
require(highestBidder!=0);
require(refundAmount<= this.balance);
require(!finalizeCalled && !refundCalled);
refundCalled = true;
highestBidder.transfer(refundAmount);
creator.transfer(highestBid-refundAmount);
}
function withdraw(){
int amount = PendingWithdrawals[msg.sender];
PendingWithdrawals[msg.sender]=0;
if(amount>0){
msg.sender.transfer(amount);
}
}
modifier auctionOver {
require(block.number > startBlockNum+biddingBlocksNum);
_;
}
modifier biddingOpen {
require(lastBidBlock+numUnchallengedBlocks>=block.number);
require(block.number<=startBlockNum+biddingBlocksNum);
_;
}
}
VickreyAuction.sol
View file @
09c1f8f7
...
@@ -10,6 +10,9 @@ contract DVickreyAuction is DAuction {
...
@@ -10,6 +10,9 @@ contract DVickreyAuction is DAuction {
bool refundCalled;
bool refundCalled;
bool finalizeCalled;
bool finalizeCalled;
mapping ( address => mapping ( bytes32 => uint32) ) deposits; // maps address,bid => count
mapping ( address => uint ) bidAmount;
// constructor
// constructor
function DVickreyAuction(uint256 reservePrice, address judgeAddress, uint256 commitTimePeriod, uint256 revealTimePeriod, uint256 _bidDepositAmount) DAuction(reservePrice, commitTimePeriod, judgeAddress) {
function DVickreyAuction(uint256 reservePrice, address judgeAddress, uint256 commitTimePeriod, uint256 revealTimePeriod, uint256 _bidDepositAmount) DAuction(reservePrice, commitTimePeriod, judgeAddress) {
...
@@ -18,31 +21,69 @@ contract DVickreyAuction is DAuction {
...
@@ -18,31 +21,69 @@ contract DVickreyAuction is DAuction {
}
}
function commitBid(bytes32 bidCommitment) biddingOpen payable returns(bool) {
function commitBid(bytes32 bidCommitment) biddingOpen payable returns(bool) {
throw;
require(msg.value == bidDepositAmount);
deposits[msg.sender][bidCommitment]+=msg.value;
return true;
}
}
function revealBid(uint256 nonce) revealOpen payable returns(address highestBidder) {
function revealBid(uint256 nonce) revealOpen payable returns(address highestBidder) {
throw;
bytes32 commitval = sha3(nonce,msg.value);
require(deposits[msg.sender][commitval]>0);
deposits[msg.sender][commitval]--;
bidAmount[msg.sender]+=msg.value;
if(msg.value>secondHighestBid && msg.value>=minimumPrice){
if(msg.value>highestBid){
secondHighestBid = highestBid;
highestBid = msg.value;
highestBidder = msg.sender;
}else{
secondHighestBid = msg.value;
}
}
msg.sender.transfer(bidDepositAmount);
returns highestBidder;
}
}
function finalize() auctionover {
function finalize() auctionover {
require(msg.sender == highestBidder);
require(msg.sender == highestBidder);
require(!refundCalled && !finalizeCalled);
require(!refundCalled && !finalizeCalled);
finalizeCalled=true;
finalizeCalled=true;
if(secondHighestBid==0 && highestBid!=0){
creator.transfer(minimumPrice);
}else if(secondHighestBid>0){
creator.transfer(secondHighestBid);
creator.transfer(secondHighestBid);
}
}
}
function refund(uint256 refundAmount) auctionOver judgeOnly {
function refund(uint256 refundAmount) auctionOver judgeOnly {
require(highestBidder!=0);
require(highestBidder!=0);
require(refundAmount<=
this.balance);
require(refundAmount<=
this.balance);
require(!finalizeCalled && !refundCalled);
require(!finalizeCalled && !refundCalled);
refundCalled=true;
refundCalled=true;
highestBidder.transfer(refundAmount);
highestBidder.transfer(refundAmount);
if(secondHighestBid==0 && highestBid>0){
if(minimumPrice>refundAmount)
creator.transfer(minimumPrice-refundAmount)
}else if (secondHighestBid>refundAmount)
creator.transfer(secondHighestBid-refundAmount);
creator.transfer(secondHighestBid-refundAmount);
}
}
function withdraw() auctionover returns (uint){
function withdraw() auctionover returns (uint){
throw;
uint amount;
if(msg.sender==highestBidder){
uint payAmount = secondHighestBid;
if(secondHighestBid == 0)
payAmount = minimumPrice;
amount = bidAmount[msg.sender]-payAmount;
bidAmount[msg.sender]=payAmount;
msg.sender.transfer(amount);
return amount;
}
amount = bidAmount[msg.sender];
bidAmount[msg.sender] = 0;
msg.sender.transfer(amount);
return amount;
}
}
modifier auctionover {
modifier auctionover {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment