BeRightThereV1
is a smart contract solution designed to promote punctuality through behavioral economics and gamification. This project aims to address the common issue of lateness in social gatherings by turning punctuality into a playful bet, incentivizing users to arrive on time through friendly wagers. Built on the Scroll testnet, this version leverages simple smart contract logic to manage event creation, participant tracking, and bet distribution without the use of Chainlink Functions and Chainlink Automation (For an implementation with Chainlink, check out BeRightThereV2.
BeRightThereV1(formerly:EventContract): https://sepolia.scrollscan.com/address/0xfcc5aff8946aa3a8015959bc468255489fcad241
Mock Token For Demo: https://sepolia.scrollscan.com/address/0xf8bc58f8aef773abba1019e8aa048fc5af876a38
To deploy this project, install all dependencies:
npm install
Initializes the contract with the token address and sets the contract owner. This function is called only once during deployment.
Modifiers:
initializer
function createEvent(
string memory _name,
uint256 _regDeadline,
uint256 _arrivalTime,
uint256 commitment,
uint256 penalty,
bytes32 _location,
address[] memory _invitees
) public onlyOwner
Creates a new event with specified parameters.
Parameters:
_name
: The name of the event._regDeadline
: The registration deadline._arrivalTime
: The scheduled arrival time.commitment
: The amount of commitment required.penalty
: The penalty for being late._location
: The encoded location of the event._invitees
: An array of addresses to invite.
Modifiers:
onlyOwner
Emits:
EventCreated(uint256 eventId, string name, uint256 regDeadline, uint256 arrivalTime, bytes32 location)
function inviteUser(uint256 _eventId, address _invitee) public onlyOwner
Invites a user to participate in an event.
Parameters:
_eventId
: The ID of the event._invitee
: The address of the user to be invited.
Modifiers:
onlyOwner
Emits:
UserInvited(uint256 eventId, address invitee)
function inviteUsers(uint256 _eventId, address[] memory _invitees) public onlyOwner
Invites multiple users to an event.
Parameters:
_eventId
: The ID of the event._invitees
: The addresses of the invitees.
Modifiers:
onlyOwner
function acceptInvite(uint256 _eventId) public
Allows an invited user to accept the invitation and join the event.
Parameters:
_eventId
: The ID of the event.
Requirements:
- The caller must be invited.
- The current timestamp must be before the registration deadline.
Emits:
UserAccepted(uint256 eventId, address participant)
function checkArrivals(uint256 _eventId) public
Checks whether participants arrived on time for the event and applies penalties if necessary.
Parameters:
_eventId
: The ID of the event.
Emits:
UserCheckedArrival(uint256 eventId, address participant, bool onTime)
function validateArrival(uint256 _eventId, address _participant) internal view returns (bool)
Validates the arrival of a participant.
Parameters:
_eventId
: The ID of the event._participant
: The address of the participant.
Returns:
bool
: Whether the participant arrived on time.
function validateArrivalMock(uint256 _eventId, address _participant) public view returns (bool)
Mocks the validation of a participant's arrival.
Parameters:
_eventId
: The ID of the event._participant
: The address of the participant.
Returns:
bool
: Mock validation status.
function mockValidationTrue(uint256 _eventId, address _participant) public
Mocks setting a participant's validation status to true.
Parameters:
_eventId
: The ID of the event._participant
: The address of the participant.
function _handlePenalty(uint256 _eventId, address _participant) internal
Handles the distribution of penalties to participants who did not arrive on time.
Parameters:
_eventId
: The ID of the event._participant
: The address of the participant.
function getUserJoinedEvents(address _user) public view returns (uint256[] memory)
Returns a list of event IDs that the user has joined.
Parameters:
_user
: The address of the user.
Returns:
uint256[]
: An array of event IDs.
function getUserLateCount(address _user) public view returns (uint256)
Returns the number of times a user was late for events.
Parameters:
_user
: The address of the user.
Returns:
uint256
: The count of late occurrences.
function claim() public
Allows a user to claim their claimable amount after an event.
Requirements:
- The caller must have a claimable amount.
function decodeCoordinates(bytes32 encoded) public pure returns (int256 latitude, int256 longitude)
Decodes encoded coordinates.
Parameters:
encoded
: The encoded coordinates.
Returns:
latitude
: The latitude asint256
.longitude
: The longitude asint256
.
function encodeCoordinates(int256 latitude, int256 longitude) public pure returns (bytes32)
Encodes coordinates.
Parameters:
latitude
: The latitude asint256
.longitude
: The longitude asint256
.
Returns:
bytes32
: The encoded coordinates.
event EventCreated(uint256 eventId, string name, uint256 regDeadline, uint256 arrivalTime, bytes32 location)
Emitted when a new event is created.
Parameters:
eventId
: The ID of the event.name
: The name of the event.regDeadline
: The registration deadline.arrivalTime
: The scheduled arrival time.location
: The encoded location of the event.
event UserInvited(uint256 eventId, address invitee)
Emitted when a user is invited to an event.
Parameters:
eventId
: The ID of the event.invitee
: The address of the invited user.
event UserAccepted(uint256 eventId, address participant)
Emitted when an invited user accepts the invitation and joins the event.
Parameters:
eventId
: The ID of the event.participant
: The address of the participant.
event UserCheckedArrival(uint256 eventId, address participant, bool onTime)
Emitted when a participant's arrival is checked and validated.
Parameters:
eventId
: The ID of the event.participant
: The address of the participant.onTime
: Whether the participant arrived on time.
event Claimed(address user, uint256 amount)
Emitted when a user claims their claimable amount.
Parameters:
user
: The address of the user.amount
: The amount claimed.