Skip to content

Commit

Permalink
Updating readme, Deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
Admin committed Nov 29, 2024
1 parent c307e0e commit 94123df
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 169 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ docs/

# Dotenv file
.env
.gas-report
.gas-snapshot

instructions
220 changes: 112 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ Backr is a decentralized platform built on Ethereum that enables transparent and

## Key Features

### 👤 Enhanced User Profiles
- Verified profiles with trusted verification system
- Profile recovery mechanism with time-locked security
- Reputation scoring system
- Profile metadata standards for better interoperability
- Username indexing for efficient querying

### 🎯 Milestone-Based Project Funding
- Create projects with detailed milestones
- Secure fund release through community voting
- Transparent progress tracking
- Project analytics and reporting

### 🏛 Decentralized Governance
- Community-driven decision making
- Proposal creation and voting system
- Time-locked execution for security
- Multi-role access control system

### 💧 Liquidity Pool
- Automated Market Maker (AMM) for ETH/BACKR trading
- Advanced slippage protection
- Emergency withdrawal mechanisms
- Low 0.3% fee structure
- Minimum liquidity requirements for stability

Expand All @@ -28,10 +39,13 @@ Backr is a decentralized platform built on Ethereum that enables transparent and
- Governance Active
- Stackable benefits up to 25%

### 💫 Quadratic Funding
- Fair fund distribution
- Matching pool for contributions
- Round-based funding cycles
### 💫 Advanced Quadratic Funding
- Fair fund distribution with matching pools
- Round-based funding cycles with configurable parameters
- Eligibility verification for participants
- Comprehensive round analytics
- Minimum and maximum contribution limits
- Anti-sybil mechanisms

## Architecture

Expand Down Expand Up @@ -59,120 +73,110 @@ Backr is a decentralized platform built on Ethereum that enables transparent and
- Solidity ^0.8.13
- OpenZeppelin Contracts
- [Foundry](https://book.getfoundry.sh/) - Development Framework
- Ethereum Development Environment
- Local: Anvil (Foundry's built-in local testnet)
- Testnet: Sepolia
- Mainnet: Ethereum

### Prerequisites

- [Foundry toolkit](https://book.getfoundry.sh/getting-started/installation)
- Node.js and npm
- Node.js and npm (for additional tooling)
- Git
- An Ethereum wallet with testnet ETH (for testnet deployment)
- RPC URLs for your desired networks (local, testnet, or mainnet)

### Local Setup

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

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

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

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

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

6. Check gas usage
```shell
forge snapshot
```

### Local Development

1. Start local node
```shell
anvil
```

2. Deploy Protocol Contracts
### Project Structure

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

```shell
# 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
```

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

3. Verify Contracts (for public networks)
```shell
forge verify-contract --chain-id <CHAIN_ID> \
--compiler-version <COMPILER_VERSION> \
<CONTRACT_ADDRESS> \
<CONTRACT_NAME> \
<ETHERSCAN_API_KEY>
backr/
├── src/ # Smart contract source files
│ ├── PlatformToken.sol # BACKR token implementation
│ ├── UserProfile.sol # User profile management
│ ├── Project.sol # Project and milestone management
│ └── QuadraticFunding.sol# Quadratic funding implementation
├── script/ # Deployment and interaction scripts
│ └── Deploy.s.sol # Main deployment script
├── test/ # Test files
├── lib/ # Dependencies
├── .env # Environment variables (git-ignored)
└── foundry.toml # Foundry configuration
```

4. Initialize Protocol

After deployment, the following initialization steps are required:

```shell
# 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>
```

### Additional Commands

For more detailed information about available commands:
```shell
forge --help
anvil --help
cast --help
```
### Development Workflow

1. **Local Development**
```shell
# Start a local Ethereum node
anvil

# In a new terminal, deploy to local network
forge script script/Deploy.s.sol:DeployScript --rpc-url http://localhost:8545 --private-key <PRIVATE_KEY> --broadcast
```

2. **Testing**
```shell
# Run all tests
forge test

# Run specific test file
forge test --match-path test/Project.t.sol

# Run tests with verbosity
forge test -vvv

# Run tests and show gas report
forge test --gas-report
```

3. **Code Quality**
```shell
# Format code
forge fmt

# Check gas usage
forge snapshot

# Run static analysis (if slither is installed)
slither .
```

4. **Contract Verification**
```shell
# Verify on Etherscan (after deployment)
forge verify-contract <DEPLOYED_ADDRESS> src/Contract.sol:Contract --chain-id <CHAIN_ID> --api-key $ETHERSCAN_API_KEY
```

### Common Tasks

1. **Compile Contracts**
```shell
forge build
```

2. **Clean Build Files**
```shell
forge clean
```

3. **Update Dependencies**
```shell
forge update
```

4. **Generate Gas Report**
```shell
forge test --gas-report > gas-report.txt
```

### Best Practices

1. Always run tests before deploying
2. Keep your private keys and API keys secure
3. Use the gas reporter to optimize expensive functions
4. Verify contracts after deployment for transparency
5. Document any deployed contract addresses
6. Test on testnet before mainnet deployment

## Contributing

Expand Down
19 changes: 0 additions & 19 deletions script/Counter.s.sol

This file was deleted.

35 changes: 35 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";
import {UserProfile} from "../src/UserProfile.sol";
import {QuadraticFunding} from "../src/QuadraticFunding.sol";
import {Project} from "../src/Project.sol";
import {PlatformToken} from "../src/PlatformToken.sol";

contract DeployScript is Script {
function setUp() public {}

function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(deployerPrivateKey);

// Deploy PlatformToken first
PlatformToken token = new PlatformToken();
console2.log("PlatformToken deployed to:", address(token));

// Deploy UserProfile
UserProfile userProfile = new UserProfile();
console2.log("UserProfile deployed to:", address(userProfile));

// Deploy Project contract with UserProfile dependency
Project project = new Project(address(userProfile));
console2.log("Project deployed to:", address(project));

// Deploy QuadraticFunding with dependencies
QuadraticFunding qf = new QuadraticFunding(payable(address(project)));
console2.log("QuadraticFunding deployed to:", address(qf));

vm.stopBroadcast();
}
}
14 changes: 0 additions & 14 deletions src/Counter.sol

This file was deleted.

24 changes: 0 additions & 24 deletions test/Counter.t.sol

This file was deleted.

8 changes: 4 additions & 4 deletions test/LiquidityPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ contract LiquidityPoolTest is Test {

function test_SlippageProtection() public {
// Add initial liquidity
(uint256 initialEthReserve, uint256 initialTokenReserve) = _addInitialLiquidity();
_addInitialLiquidity();

// Try to make a large swap that would exceed slippage
vm.startPrank(user1);
Expand Down Expand Up @@ -429,7 +429,7 @@ contract LiquidityPoolTest is Test {

function test_EmergencyWithdrawal() public {
// Add initial liquidity
(uint256 initialEthReserve, uint256 initialTokenReserve) = _addInitialLiquidity();
_addInitialLiquidity();

// Try emergency withdrawal without being owner
vm.startPrank(user1);
Expand All @@ -455,8 +455,8 @@ contract LiquidityPoolTest is Test {
// Verify balances
assertEq(address(pool).balance, 0, "Pool should have 0 ETH after emergency withdrawal");
assertEq(token.balanceOf(address(pool)), 0, "Pool should have 0 tokens after emergency withdrawal");
assertEq(owner.balance - ownerEthBefore, initialEthReserve, "Owner should receive all ETH");
assertEq(token.balanceOf(owner) - ownerTokensBefore, initialTokenReserve, "Owner should receive all tokens");
assertEq(owner.balance - ownerEthBefore, pool.ethReserve(), "Owner should receive all ETH");
assertEq(token.balanceOf(owner) - ownerTokensBefore, pool.tokenReserve(), "Owner should receive all tokens");

vm.stopPrank();
}
Expand Down

0 comments on commit 94123df

Please sign in to comment.