Skip to content

Commit

Permalink
feat(fundraising-contract): initial project setup, initial scaffold o…
Browse files Browse the repository at this point in the history
…f contract & tests
  • Loading branch information
Korbinian Kasberger committed May 15, 2023
0 parents commit b1362a0
Show file tree
Hide file tree
Showing 11 changed files with 9,620 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
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

6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
55 changes: 55 additions & 0 deletions Readme.md
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
44 changes: 44 additions & 0 deletions contracts/FundraiserContract.sol
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;
}


}
40 changes: 40 additions & 0 deletions diagram.plantuml
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
8 changes: 8 additions & 0 deletions hardhat.config.ts
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
Loading

0 comments on commit b1362a0

Please sign in to comment.