Skip to content

Instantly share code, notes, and snippets.

@ravachol70
Created October 20, 2023 12:21
Show Gist options
  • Save ravachol70/087334d354775a5eb63d1a7a1ba8a7d3 to your computer and use it in GitHub Desktop.
Save ravachol70/087334d354775a5eb63d1a7a1ba8a7d3 to your computer and use it in GitHub Desktop.
Mini Micro-Cartelism in a Nutshell
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract MicroCartelBidding {
address public owner; // The owner of the bidding contract
address[] public cartelMembers; // Addresses of cartel members
uint public highestBid; // Highest bid amount
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner, "Only owner can perform this action");
_;
}
modifier onlyCartelMember() {
bool isCartelMember = false;
for (uint i = 0; i < cartelMembers.length; i++) {
if (cartelMembers[i] == msg.sender) {
isCartelMember = true;
break;
}
}
require(isCartelMember, "Only cartel members can perform this action");
_;
}
// Function to join the cartel (only owner can invite members)
function joinCartel(address _member) public onlyOwner {
cartelMembers.push(_member);
}
// Function for cartel members to place unlimited bids
function placeBid() public payable onlyCartelMember {
// The highest bid is always set to the maximum amount sent
highestBid = msg.value;
}
// Function for cartel members to withdraw their bids
function withdrawBid() public onlyCartelMember {
// Implement logic to refund the bidder
// Note: In this scenario, cartel members can freely withdraw bids.
}
// Function to end the bidding and transfer all funds to the owner
function endBidding() public onlyOwner {
// Transfer all funds to the owner
payable(owner).transfer(address(this).balance);
}
// Function to check the current highest bid
function getCurrentHighestBid() public view returns (uint) {
return highestBid;
}
}
@ravachol70
Copy link
Author

`// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract RealTimeBiddingRegime {
address public owner; // The owner of the bidding regime
uint public biddingEndTime; // Timestamp when the bidding ends
uint public minBidIncrement; // Minimum bid increment required

struct Bidder {
    uint bidAmount;
    bool hasWithdrawn;
}

address public highestBidder; // Address of the highest bidder
uint public highestBid; // Highest bid amount
mapping(address => Bidder) public bidders; // Mapping of bidders

enum BiddingState { Active, Ended }
BiddingState public biddingState = BiddingState.Active;

constructor(uint _biddingDuration, uint _minIncrement) {
    owner = msg.sender;
    biddingEndTime = block.timestamp + _biddingDuration;
    minBidIncrement = _minIncrement;
}

modifier onlyOwner() {
    require(msg.sender == owner, "Only owner can perform this action");
    _;
}

modifier onlyBiddingActive() {
    require(biddingState == BiddingState.Active, "Bidding has ended");
    _;
}

modifier onlyHighestBidder() {
    require(msg.sender == highestBidder, "Only highest bidder can perform this action");
    _;
}

function placeBid() public payable onlyBiddingActive {
    require(msg.value > highestBid + minBidIncrement, "Bid amount must be higher than the current highest bid plus increment");
    
    // Refund the previous highest bidder
    if (highestBidder != address(0)) {
        uint refundAmount = bidders[highestBidder].bidAmount;
        payable(highestBidder).transfer(refundAmount);
        bidders[highestBidder].hasWithdrawn = true;
    }
    
    highestBidder = msg.sender;
    highestBid = msg.value;
    bidders[msg.sender].bidAmount = msg.value;
    bidders[msg.sender].hasWithdrawn = false;
}

function withdrawBid() public onlyBiddingActive {
    require(msg.sender != highestBidder, "You are the highest bidder");
    require(bidders[msg.sender].bidAmount > 0, "No bid to withdraw");
    require(!bidders[msg.sender].hasWithdrawn, "Bidder has already withdrawn");
    
    uint refundAmount = bidders[msg.sender].bidAmount;
    bidders[msg.sender].bidAmount = 0;
    bidders[msg.sender].hasWithdrawn = true;
    payable(msg.sender).transfer(refundAmount);
}

function endBidding() public onlyOwner {
    require(block.timestamp >= biddingEndTime, "Bidding has not ended yet");
    require(biddingState == BiddingState.Active, "Bidding has already ended");
    
    biddingState = BiddingState.Ended;
    
    // Transfer the highest bid to the owner
    payable(owner).transfer(highestBid);
}

// Additional functions for monitoring and reporting the bidding regime's status

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment