Skip to content

Commit

Permalink
docs: enhance README with comprehensive protocol documentation
Browse files Browse the repository at this point in the history
- Add detailed project overview and key features
- Document smart contract architecture and security features
- Include step-by-step deployment instructions with contract dependencies
- Add protocol initialization guide
- Reorganize development setup for better clarity
  • Loading branch information
Admin committed Nov 29, 2024
1 parent 5d8d4b5 commit cca5047
Show file tree
Hide file tree
Showing 10 changed files with 769 additions and 143 deletions.
173 changes: 145 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,183 @@
## Foundry
# Backr

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
Backr is a decentralized platform built on Ethereum that enables transparent and accountable project funding through milestone-based releases and community governance. The platform incorporates quadratic funding mechanisms, liquidity pools, and achievement badges to create a robust ecosystem for project creators and backers.

Foundry consists of:
## Key Features

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
### 🎯 Milestone-Based Project Funding
- Create projects with detailed milestones
- Secure fund release through community voting
- Transparent progress tracking

## Documentation
### 🏛 Decentralized Governance
- Community-driven decision making
- Proposal creation and voting system
- Time-locked execution for security

https://book.getfoundry.sh/
### 💧 Liquidity Pool
- Automated Market Maker (AMM) for ETH/BACKR trading
- Low 0.3% fee structure
- Minimum liquidity requirements for stability

## Usage
### 🏆 Achievement Badges
- NFT-based recognition system
- Multiple badge types:
- Early Supporter
- Power Backer
- Liquidity Provider
- Governance Active
- Stackable benefits up to 25%

### Build
### 💫 Quadratic Funding
- Fair fund distribution
- Matching pool for contributions
- Round-based funding cycles

## Architecture

### Smart Contracts

- `Project.sol`: Core contract managing project creation and milestone tracking
- `Governance.sol`: DAO functionality for platform governance
- `LiquidityPool.sol`: AMM implementation for token liquidity
- `Badge.sol`: NFT-based achievement system
- `QuadraticFunding.sol`: Implementation of quadratic funding mechanism
- `PlatformToken.sol`: BACKR token with staking capabilities
- `UserProfile.sol`: User reputation and profile management

### Security Features
- Reentrancy guards
- Time-locked execution
- Access control mechanisms
- Minimum liquidity requirements
- Pausable functionality

## Development

### Technical Stack

- Solidity ^0.8.13
- OpenZeppelin Contracts
- [Foundry](https://book.getfoundry.sh/) - Development Framework

### Prerequisites

- [Foundry toolkit](https://book.getfoundry.sh/getting-started/installation)
- Node.js and npm
- Git

### Local Setup

1. Clone the repository
```shell
$ forge build
git clone https://github.com/yourusername/backr.git
cd backr
```

### Test
2. Install dependencies
```shell
forge install
```

3. Build the project
```shell
$ forge test
forge build
```

### Format
4. Run tests
```shell
forge test
```

5. Format code
```shell
$ forge fmt
forge fmt
```

### Gas Snapshots
6. Check gas usage
```shell
forge snapshot
```

### Local Development

1. Start local node
```shell
$ forge snapshot
anvil
```

### Anvil
2. Deploy Protocol Contracts

The deployment order matters due to contract dependencies. Use the following commands:

```shell
$ anvil
# Deploy UserProfile contract first
forge script script/deploy/DeployUserProfile.s.sol:DeployUserProfile --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcast

# Deploy PlatformToken
forge script script/deploy/DeployPlatformToken.s.sol:DeployPlatformToken --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcast

# Deploy Badge system (requires PlatformToken address)
forge script script/deploy/DeployBadge.s.sol:DeployBadge --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcast

# Deploy Governance (requires PlatformToken address)
forge script script/deploy/DeployGovernance.s.sol:DeployGovernance --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcast

# Deploy LiquidityPool (requires PlatformToken address)
forge script script/deploy/DeployLiquidityPool.s.sol:DeployLiquidityPool --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcast

# Deploy Project contract (requires UserProfile address)
forge script script/deploy/DeployProject.s.sol:DeployProject --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcast

# Deploy QuadraticFunding (requires Project contract address)
forge script script/deploy/DeployQuadraticFunding.s.sol:DeployQuadraticFunding --rpc-url http://localhost:8545 --private-key $PRIVATE_KEY --broadcast
```

### Deploy
For testnet or mainnet deployment, replace `http://localhost:8545` with your network RPC URL.

3. Verify Contracts (for public networks)
```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
forge verify-contract --chain-id <CHAIN_ID> \
--compiler-version <COMPILER_VERSION> \
<CONTRACT_ADDRESS> \
<CONTRACT_NAME> \
<ETHERSCAN_API_KEY>
```

### Cast
4. Initialize Protocol

After deployment, the following initialization steps are required:

```shell
$ cast <subcommand>
# Initialize LiquidityPool with initial liquidity
cast send --private-key $PRIVATE_KEY <LIQUIDITY_POOL_ADDRESS> \
"addLiquidity(uint256)" \
<TOKEN_AMOUNT> \
--value <ETH_AMOUNT>

# Set up initial governance parameters
cast send --private-key $PRIVATE_KEY <GOVERNANCE_ADDRESS> \
"initialize()"

# Initialize QuadraticFunding with first round
cast send --private-key $PRIVATE_KEY <QUADRATIC_FUNDING_ADDRESS> \
"startRound()" \
--value <MATCHING_POOL_AMOUNT>
```

### Help
### Additional Commands

For more detailed information about available commands:
```shell
$ forge --help
$ anvil --help
$ cast --help
forge --help
anvil --help
cast --help
```

## Contributing

Contributions are welcome! Please read our contributing guidelines before submitting pull requests.

## License

This project is licensed under the MIT License.
6 changes: 6 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ src = "src"
out = "out"
libs = ["lib"]

# Explicit remappings for OpenZeppelin contracts
remappings = [
"@openzeppelin/=lib/openzeppelin-contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/"
]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@openzeppelin/=lib/openzeppelin-contracts/
100 changes: 100 additions & 0 deletions src/Badge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/**
* @title Badge
* @dev NFT-based badge system for platform achievements
*/
contract Badge is ERC721, Ownable {
uint256 private _tokenIds;

// Badge types and their requirements
enum BadgeType {
EARLY_SUPPORTER, // First 100 users to back a project
POWER_BACKER, // Backed more than 5 projects
LIQUIDITY_PROVIDER, // Provided significant liquidity
GOVERNANCE_ACTIVE // Participated in multiple proposals
}

// Mapping from token ID to badge type
mapping(uint256 => BadgeType) public badgeTypes;

// Mapping from address to badge type to whether they have earned it
mapping(address => mapping(BadgeType => bool)) public hasBadge;

// Mapping from badge type to its benefits multiplier (in basis points, 100 = 1%)
mapping(BadgeType => uint256) public badgeBenefits;

event BadgeAwarded(address indexed recipient, BadgeType badgeType, uint256 tokenId);
event BenefitUpdated(BadgeType badgeType, uint256 newBenefit);

constructor() ERC721("Platform Achievement Badge", "BADGE") Ownable() {
_tokenIds = 0;
// Set initial badge benefits
badgeBenefits[BadgeType.EARLY_SUPPORTER] = 500; // 5% discount
badgeBenefits[BadgeType.POWER_BACKER] = 1000; // 10% discount
badgeBenefits[BadgeType.LIQUIDITY_PROVIDER] = 1500; // 15% discount
badgeBenefits[BadgeType.GOVERNANCE_ACTIVE] = 750; // 7.5% discount
}

/**
* @dev Award a badge to an address
* @param recipient Address to receive the badge
* @param badgeType Type of badge to award
*/
function awardBadge(address recipient, BadgeType badgeType) external onlyOwner {
require(!hasBadge[recipient][badgeType], "Badge already awarded");

_tokenIds++;
uint256 newTokenId = _tokenIds;

_safeMint(recipient, newTokenId);
badgeTypes[newTokenId] = badgeType;
hasBadge[recipient][badgeType] = true;

emit BadgeAwarded(recipient, badgeType, newTokenId);
}

/**
* @dev Update the benefit percentage for a badge type
* @param badgeType Type of badge to update
* @param newBenefit New benefit value in basis points
*/
function updateBadgeBenefit(BadgeType badgeType, uint256 newBenefit) external onlyOwner {
require(newBenefit <= 10000, "Benefit cannot exceed 100%");
badgeBenefits[badgeType] = newBenefit;
emit BenefitUpdated(badgeType, newBenefit);
}

/**
* @dev Get the total discount percentage for an address (sum of all badge benefits)
* @param user Address to check benefits for
* @return Total benefit in basis points
*/
function getTotalBenefits(address user) external view returns (uint256) {
uint256 totalBenefit = 0;

for (uint i = 0; i <= uint(type(BadgeType).max); i++) {
BadgeType badgeType = BadgeType(i);
if (hasBadge[user][badgeType]) {
totalBenefit += badgeBenefits[badgeType];
}
}

// Cap total benefit at 25%
return totalBenefit > 2500 ? 2500 : totalBenefit;
}

/**
* @dev Check if an address has a specific badge
* @param user Address to check
* @param badgeType Type of badge to check for
* @return bool Whether the address has the badge
*/
function hasSpecificBadge(address user, BadgeType badgeType) external view returns (bool) {
return hasBadge[user][badgeType];
}
}
Loading

0 comments on commit cca5047

Please sign in to comment.