-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fundraising-contract): initial project setup, initial scaffold o…
…f contract & tests
- Loading branch information
Korbinian Kasberger
committed
May 15, 2023
0 parents
commit b1362a0
Showing
11 changed files
with
9,620 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 4, | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Fundraising contract | ||
|
||
### Development | ||
|
||
**Tools**: | ||
|
||
- Solidity | ||
- Hardhat | ||
|
||
**Commands**: | ||
|
||
```shell | ||
# run all tests | ||
npm run test | ||
|
||
# compile the smart contracts and creates the artifacs | ||
npm run compile | ||
|
||
# start simulated local network with prefunded wallets | ||
npm run node | ||
|
||
# deploy the contracts configured in the deploy script to the local network (prev. command) | ||
npm run deploy::local | ||
|
||
# open a web3 cli | ||
npm run console | ||
``` | ||
|
||
More info: [hardhat.org](https://hardhat.org/docs) | ||
|
||
### Participants | ||
|
||
**Admin** | ||
|
||
- Creates a new project inside the smart contract | ||
- Changes the funding goal of a project | ||
- Default owner of all projects | ||
|
||
**Investor** | ||
|
||
- Creates a new project | ||
- Donates to a project | ||
- Checks the total amount raised for a project | ||
|
||
**Smart Contract** | ||
|
||
- Holds the logic for creating, donating to and updating a project | ||
- Ensures donations do not exceed the funding goal | ||
- Checks that the new funding goal is not less than the amount raised | ||
|
||
### Out of scope | ||
|
||
- Roles & Permissions (e.g. OpenZeppelin access management) | ||
- Upgradability (e.g. OpenZepplin proxy) | ||
- Handle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.20; | ||
|
||
import "hardhat/console.sol"; | ||
|
||
contract FundraiserContract { | ||
address owner; | ||
|
||
event ProjectCreated(uint projectId, uint fundingGoal, uint currentAmount, address owner); | ||
event ContributionMade(uint projectId, uint fundingGoal, uint currentAmount, address contributer); | ||
event FundingGoalUpdated(uint projectId, uint oldGoal, uint newGoal, uint currentAmount, address sender); | ||
|
||
mapping(uint => Project) public projects; | ||
|
||
constructor() { | ||
owner = msg.sender; | ||
} | ||
|
||
struct Project { | ||
uint id; | ||
uint fundingGoal; | ||
uint currentAmount; | ||
address payable owner; | ||
} | ||
|
||
function createProject(uint _projectId, uint _fundingGoal) public { | ||
console.log("Creating a new project"); | ||
} | ||
|
||
function contribute(uint _projectId) public payable { | ||
console.log("Contributing to a project"); | ||
} | ||
|
||
function setFundingGoal(uint _projectId, uint _fundingGoal) public { | ||
console.log("Setting the funding goal for a project"); | ||
} | ||
|
||
function getProjectTotalAmountRaised(uint _projectId) public view returns (uint) { | ||
console.log("Getting the total amount raised for a project"); | ||
return 0; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@startuml project-funding | ||
Title: Project Funding via Smart Contract | ||
Participant "Admin" as A | ||
Participant "SmartContract" as SC | ||
Participant "Investor" as I | ||
|
||
|
||
A -> SC: createProject(projectId, fundingGoal) | ||
activate SC | ||
SC -> SC: Project(projectOwner, fundingGoal, totalAmount) | ||
SC --> A: Event: ProjectCreated | ||
deactivate SC | ||
|
||
I -> SC: contribute(projectId, amount) | ||
activate SC | ||
SC -> SC: check(amount <= fundingGoal - totalAmount) | ||
alt amount <= fundingGoal - totalAmount | ||
SC -> SC: totalAmount += amount | ||
SC --> I: Event: DonationMade | ||
else | ||
SC --> I: Error: "Donation exceeds funding goal" | ||
end | ||
deactivate SC | ||
|
||
I -> SC: getProjectTotalAmount(projectId) | ||
activate SC | ||
SC --> I: return totalAmount | ||
deactivate SC | ||
|
||
A -> SC: setFundingGoal(projectId, newFundingGoal) | ||
activate SC | ||
SC -> SC: check(msg.sender == projectOwner) | ||
SC -> SC: check(newFundingGoal >= totalAmount) | ||
alt newFundingGoal >= totalAmount | ||
SC -> SC: fundingGoal = newFundingGoal | ||
SC --> A: Event: FundingGoalUpdated | ||
else | ||
SC --> A: Error: "New funding goal cannot be less than the amount already raised" | ||
end | ||
deactivate SC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { HardhatUserConfig } from 'hardhat/config' | ||
import '@nomicfoundation/hardhat-toolbox' | ||
|
||
const config: HardhatUserConfig = { | ||
solidity: '0.8.20', | ||
} | ||
|
||
export default config |
Oops, something went wrong.