{"id":21670751,"url":"https://github.com/flowstake/contracts","last_synced_at":"2025-03-20T07:43:26.232Z","repository":{"id":250473399,"uuid":"834562447","full_name":"flowstake/contracts","owner":"flowstake","description":"Smart contracts for staking ERC20 tokens into Proof of Activity","archived":false,"fork":false,"pushed_at":"2024-10-27T06:35:33.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-11-25T12:41:19.575Z","etag":null,"topics":["contracts"],"latest_commit_sha":null,"homepage":null,"language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flowstake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-27T16:41:14.000Z","updated_at":"2024-10-27T06:35:36.000Z","dependencies_parsed_at":"2024-10-27T07:44:52.876Z","dependency_job_id":null,"html_url":"https://github.com/flowstake/contracts","commit_stats":null,"previous_names":["flowstake/contracts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowstake%2Fcontracts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowstake%2Fcontracts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowstake%2Fcontracts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowstake%2Fcontracts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flowstake","download_url":"https://codeload.github.com/flowstake/contracts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235558342,"owners_count":19009396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contracts"],"created_at":"2024-11-25T12:35:02.217Z","updated_at":"2025-01-25T09:10:00.770Z","avatar_url":"https://github.com/flowstake.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Creating a Self-Staking Solidity Smart Contract (Strava data Oracle)\n\nCreating a self-staking Solidity smart contract connected to the data output of a completed Strava activity with the title \"Proof of Activity as a Stake\" and including P2P attestation with a photo of the activity involves several components. The contract needs to handle data input from Strava, verify the proof of activity, and manage staking logic. This example will focus on the core functionalities:\n\n## Core Functionalities\n\n### Tracking Activity Completion\nThe contract will store the proof of activity from Strava.\n\n### P2P Attestation\nUsers can attest to the activity by submitting photos.\n\n### Staking Logic\nUsers can stake tokens based on their activities.\n\nHere's a version of such a contract:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ncontract ProofOfActivityStake {\n    // Struct to store activity details\n    struct Activity {\n        string stravaActivityId;  // Unique identifier for the Strava activity\n        address user;             // Address of the user who completed the activity\n        string activityData;      // Data of the activity (e.g., distance, duration)\n        bool isCompleted;         // Flag indicating if the activity is completed\n        uint256 stakedAmount;     // Amount of tokens staked on the activity\n        string photoHash;         // Hash of the photo for P2P attestation\n    }\n\n    // Mapping from Strava activity ID to Activity details\n    mapping(string =\u003e Activity) public activities;\n    // Mapping from user address to their staked token amount\n    mapping(address =\u003e uint256) public stakes;\n\n    // Event emitted when an activity is completed\n    event ActivityCompleted(string indexed stravaActivityId, address indexed user, string activityData);\n    // Event emitted when an activity is attested with a photo\n    event ActivityAttested(string indexed stravaActivityId, address indexed user, string photoHash);\n    // Event emitted when tokens are staked on an activity\n    event TokensStaked(address indexed user, uint256 amount);\n\n    // Function to mark an activity as completed\n    function completeActivity(string memory stravaActivityId, string memory activityData) public {\n        require(bytes(activityData).length \u003e 0, \"Activity data cannot be empty\");\n\n        // Store the activity details in the mapping\n        activities[stravaActivityId] = Activity({\n            stravaActivityId: stravaActivityId,\n            user: msg.sender,\n            activityData: activityData,\n            isCompleted: true,\n            stakedAmount: 0,\n            photoHash: \"\"\n        });\n\n        // Emit an event for activity completion\n        emit ActivityCompleted(stravaActivityId, msg.sender, activityData);\n    }\n\n    // Function for users to attest to their activity with a photo\n    function attestActivity(string memory stravaActivityId, string memory photoHash) public {\n        Activity storage activity = activities[stravaActivityId];\n        require(activity.isCompleted, \"Activity not completed\");\n        require(activity.user == msg.sender, \"Only the user who completed the activity can attest\");\n\n        // Store the photo hash for attestation\n        activity.photoHash = photoHash;\n\n        // Emit an event for activity attestation\n        emit ActivityAttested(stravaActivityId, msg.sender, photoHash);\n    }\n\n    // Function for users to stake tokens on their completed activity\n    function stakeTokens(string memory stravaActivityId, uint256 amount) public {\n        Activity storage activity = activities[stravaActivityId];\n        require(activity.isCompleted, \"Activity not completed\");\n        require(activity.user == msg.sender, \"Only the user who completed the activity can stake tokens\");\n\n        // Update the user's staked token amount and the activity's staked amount\n        stakes[msg.sender] += amount;\n        activity.stakedAmount += amount;\n\n        // Emit an event for token staking\n        emit TokensStaked(msg.sender, amount);\n    }\n}\n```\n\n# Key Functionalities of the ProofOfActivityStake Contract\n\n## Overview\nThe `ProofOfActivityStake` contract is designed to integrate with Strava activities, enabling users to:\n1. Record and verify their activities.\n2. Provide peer-to-peer (P2P) attestations with photos.\n3. Stake tokens based on their completed activities.\n\n## Core Functionalities\n\n### Tracking Activity Completion\n\n#### Function: `completeActivity`\n- **Purpose:** To record the completion of an activity from Strava.\n- **Inputs:**\n  - `stravaActivityId`: A unique identifier for the Strava activity.\n  - `activityData`: Details about the activity (e.g., distance, duration).\n- **Behavior:**\n  - Validates that the activity data is not empty.\n  - Creates an `Activity` struct with the provided details and stores it in the `activities` mapping.\n  - Sets `isCompleted` to `true` to indicate the activity is completed.\n  - Emits the `ActivityCompleted` event.\n\n### P2P Attestation\n\n#### Function: `attestActivity`\n- **Purpose:** To allow users to attest to their activity by submitting a photo.\n- **Inputs:**\n  - `stravaActivityId`: The unique identifier for the Strava activity.\n  - `photoHash`: The hash of the photo for attestation.\n- **Behavior:**\n  - Ensures the activity is completed and that the user submitting the attestation is the same user who completed the activity.\n  - Stores the photo hash in the corresponding `Activity` struct.\n  - Emits the `ActivityAttested` event.\n\n### Staking Logic\n\n#### Function: `stakeTokens`\n- **Purpose:** To enable users to stake tokens based on their completed activities.\n- **Inputs:**\n  - `stravaActivityId`: The unique identifier for the Strava activity.\n  - `amount`: The amount of tokens to be staked.\n- **Behavior:**\n  - Ensures the activity is completed and that the user staking tokens is the same user who completed the activity.\n  - Updates the user's total staked tokens and the activity's staked amount.\n  - Emits the `TokensStaked` event.\n\n## Events\n- `ActivityCompleted`: Emitted when an activity is marked as completed.\n- `ActivityAttested`: Emitted when an activity is attested with a photo.\n- `TokensStaked`: Emitted when tokens are staked on an activity.\n\n## Mappings\n- `activities`: Stores the details of each activity, indexed by `stravaActivityId`.\n- `stakes`: Tracks the total amount of tokens staked by each user.\n\nBy utilizing these functionalities, the `ProofOfActivityStake` contract ensures a comprehensive system for recording, verifying, and staking on Strava activities, enhancing user engagement and accountability.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowstake%2Fcontracts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflowstake%2Fcontracts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowstake%2Fcontracts/lists"}