From 94123dfda1777367bd29a2c0440a085a12cdbe75 Mon Sep 17 00:00:00 2001 From: Admin Date: Thu, 28 Nov 2024 22:11:54 -0800 Subject: [PATCH] Updating readme, Deploy script --- .gitignore | 3 + README.md | 220 ++++++++++++++++++++------------------- script/Counter.s.sol | 19 ---- script/Deploy.s.sol | 35 +++++++ src/Counter.sol | 14 --- test/Counter.t.sol | 24 ----- test/LiquidityPool.t.sol | 8 +- 7 files changed, 154 insertions(+), 169 deletions(-) delete mode 100644 script/Counter.s.sol create mode 100644 script/Deploy.s.sol delete mode 100644 src/Counter.sol delete mode 100644 test/Counter.t.sol diff --git a/.gitignore b/.gitignore index 1af0dd0..fa497d9 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,7 @@ docs/ # Dotenv file .env +.gas-report +.gas-snapshot + instructions \ No newline at end of file diff --git a/README.md b/README.md index 35d7165..0487e31 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 \ - --compiler-version \ - \ - \ - +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 \ - "addLiquidity(uint256)" \ - \ - --value - -# Set up initial governance parameters -cast send --private-key $PRIVATE_KEY \ - "initialize()" - -# Initialize QuadraticFunding with first round -cast send --private-key $PRIVATE_KEY \ - "startRound()" \ - --value -``` - -### 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 --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 src/Contract.sol:Contract --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 diff --git a/script/Counter.s.sol b/script/Counter.s.sol deleted file mode 100644 index cdc1fe9..0000000 --- a/script/Counter.s.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Script, console} from "forge-std/Script.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterScript is Script { - Counter public counter; - - function setUp() public {} - - function run() public { - vm.startBroadcast(); - - counter = new Counter(); - - vm.stopBroadcast(); - } -} diff --git a/script/Deploy.s.sol b/script/Deploy.s.sol new file mode 100644 index 0000000..a82a0ab --- /dev/null +++ b/script/Deploy.s.sol @@ -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(); + } +} diff --git a/src/Counter.sol b/src/Counter.sol deleted file mode 100644 index aded799..0000000 --- a/src/Counter.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -contract Counter { - uint256 public number; - - function setNumber(uint256 newNumber) public { - number = newNumber; - } - - function increment() public { - number++; - } -} diff --git a/test/Counter.t.sol b/test/Counter.t.sol deleted file mode 100644 index 54b724f..0000000 --- a/test/Counter.t.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Test, console} from "forge-std/Test.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterTest is Test { - Counter public counter; - - function setUp() public { - counter = new Counter(); - counter.setNumber(0); - } - - function test_Increment() public { - counter.increment(); - assertEq(counter.number(), 1); - } - - function testFuzz_SetNumber(uint256 x) public { - counter.setNumber(x); - assertEq(counter.number(), x); - } -} diff --git a/test/LiquidityPool.t.sol b/test/LiquidityPool.t.sol index 7a96cbb..e25087c 100644 --- a/test/LiquidityPool.t.sol +++ b/test/LiquidityPool.t.sol @@ -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); @@ -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); @@ -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(); }