Giter VIP home page Giter VIP logo

brt-smart-contract's Introduction

BeRightThereV1

Be Right There Thumbnail

Overview

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.

How it Works

How it Works

Deployed Addresses

BeRightThereV1(formerly:EventContract): https://sepolia.scrollscan.com/address/0xfcc5aff8946aa3a8015959bc468255489fcad241

Mock Token For Demo: https://sepolia.scrollscan.com/address/0xf8bc58f8aef773abba1019e8aa048fc5af876a38

Installation

To deploy this project, install all dependencies:

npm install

Contract Functions

initialize(address _token)

Initializes the contract with the token address and sets the contract owner. This function is called only once during deployment.

Modifiers:

  • initializer

createEvent

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)

inviteUser

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)

inviteUsers

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

acceptInvite

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)

checkArrivals

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)

validateArrival

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.

validateArrivalMock

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.

mockValidationTrue

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.

handlePenalty

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.

getUserJoinedEvents

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.

getUserLateCount

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.

claim

function claim() public

Allows a user to claim their claimable amount after an event.

Requirements:

  • The caller must have a claimable amount.

decodeCoordinates

function decodeCoordinates(bytes32 encoded) public pure returns (int256 latitude, int256 longitude)

Decodes encoded coordinates.

Parameters:

  • encoded: The encoded coordinates.

Returns:

  • latitude: The latitude as int256.
  • longitude: The longitude as int256.

encodeCoordinates

function encodeCoordinates(int256 latitude, int256 longitude) public pure returns (bytes32)

Encodes coordinates.

Parameters:

  • latitude: The latitude as int256.
  • longitude: The longitude as int256.

Returns:

  • bytes32: The encoded coordinates.

Events

EventCreated

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.

UserInvited

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.

UserAccepted

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.

UserCheckedArrival

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.

Claimed

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.

brt-smart-contract's People

Contributors

0xkmg avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.