Skip to content

Commit

Permalink
🤺 compile plus nits
Browse files Browse the repository at this point in the history
  • Loading branch information
z0r0z committed Dec 17, 2024
1 parent b1c2f78 commit 905cb87
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 49 deletions.
3 changes: 1 addition & 2 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Tester:test(string) (runs: 256, μ: 47790, ~: 24790)
TesterTest:testTest() (gas: 29940)
BountyTest:testDeploy() (gas: 2377346)
28 changes: 2 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
# [zenplate](https://github.com/z0r0z/zenplate) [![License: AGPL-3.0-only](https://img.shields.io/badge/License-AGPL-black.svg)](https://opensource.org/license/agpl-v3/) [![solidity](https://img.shields.io/badge/solidity-%5E0.8.25-black)](https://docs.soliditylang.org/en/v0.8.25/) [![Foundry](https://img.shields.io/badge/Built%20with-Foundry-000000.svg)](https://getfoundry.sh/) ![tests](https://github.com/z0r0z/zenplate/actions/workflows/ci.yml/badge.svg)
# [bounties](https://github.com/NaniDAO/bounties) [![License: AGPL-3.0-only](https://img.shields.io/badge/License-AGPL-black.svg)](https://opensource.org/license/agpl-v3/) [![solidity](https://img.shields.io/badge/solidity-%5E0.8.28-black)](https://docs.soliditylang.org/en/v0.8.28/) [![Foundry](https://img.shields.io/badge/Built%20with-Foundry-000000.svg)](https://getfoundry.sh/) ![tests](https://github.com/NaniDAO/bounties/actions/workflows/ci.yml/badge.svg)

Simpler foundry template.
simple onchain bounties for daos

## Getting Started

Click [`use this template`](https://github.com/z0r0z/zenplate/generate) to start.

Run: `curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundryup`

Build the foundry project with `forge build`. Run tests with `forge test`. Measure gas with `forge snapshot`. Format with `forge fmt`.

## GitHub Actions

Contracts will be tested and gas measured on every push and pull request.

You can edit the CI script in [.github/workflows/ci.yml](./.github/workflows/ci.yml).

## Blueprint

```txt
lib
├─ forge-std — https://github.com/foundry-rs/forge-std
src
├─ Tester — Tester Contract
test
└─ Tester.t - Test Contract
```

## Notable Mentions

- [femplate](https://github.com/refcell/femplate)
- [prb-foundry-template](https://github.dev/PaulRBerg/foundry-template)

## Disclaimer

*These smart contracts and testing suite are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of anything provided herein or through related user interfaces. This repository and related code have not been audited and as such there can be no assurance anything will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. The creators are not liable for any of the foregoing. Users should proceed with caution and use at their own risk.*
Expand Down
5 changes: 2 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ evm_version = "cancun"
optimizer = true
optimizer_runs = 9_999_999

via_ir = true

remappings = [
"@solady=lib/solady/",
"@forge=lib/forge-std/src/"
]

[profile.via-ir]
via_ir = true

[fmt]
line_length = 100

Expand Down
43 changes: 25 additions & 18 deletions src/bounty.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.19;

import {Ownable} from "@solady/src/auth/Ownable.sol";
import {Base64} from "@solady/src/utils/Base64.sol";
import {ERC721} from "@solady/src/tokens/ERC721.sol";
import {Ownable} from "@solady/src/auth/Ownable.sol";
import {LibString} from "@solady/src/utils/LibString.sol";
import {Base64} from "@solady/src/utils/Base64.sol";

/// @notice Simple NFT contract for minting bounties.
/// @dev Emojis also used for people that can't read.
contract bounty is Ownable, ERC721 {
contract bounty is ERC721, Ownable {
using LibString for uint256;

enum Status {
Expand All @@ -20,19 +20,19 @@ contract bounty is Ownable, ERC721 {
}

struct Bounty {
string emojis;
string text;
address token;
uint256 amount;
Status status;
address watcher;
string emojis; // pictoral
string text; // basic gist
address token; // to grant
uint256 amount; // the sum
Status status; // id state
address watcher; // admins
}

uint256[] public bounties;
mapping(uint256 tokenId => Bounty) public requests;

constructor() payable {
_initializeOwner(msg.sender);
_initializeOwner(tx.origin); // Helps factory.
}

function name() public pure override(ERC721) returns (string memory) {
Expand All @@ -43,13 +43,15 @@ contract bounty is Ownable, ERC721 {
return unicode"⌘";
}

function pendingRequest(string calldata emojis, string calldata text)
error Exists();

function propose(string calldata emojis, string calldata text)
public
returns (uint256 tokenId)
{
tokenId = uint256(keccak256(abi.encodePacked(emojis, text)));
if (requests[tokenId].status != Status.None) revert("!none");
requests[tokenId] = Bounty(emojis, text, address(0), 0, Status.Pending, owner());;
if (requests[tokenId].status != Status.None) revert Exists();
requests[tokenId] = Bounty(emojis, text, address(0), 0, Status.Pending, owner());
bounties.push(tokenId);
}

Expand All @@ -59,22 +61,27 @@ contract bounty is Ownable, ERC721 {
address token,
uint256 amount,
address watcher
) public onlyOwner {
uint256 tokenId = uint256(keccak256(abi.encodePacked(emojis, text)));
) public onlyOwner returns (uint256 tokenId) {
tokenId = uint256(keccak256(abi.encodePacked(emojis, text)));
_mint(watcher, tokenId);
requests[tokenId] = Bounty(emojis, text, token, amount, Status.Approved, watcher);
if (requests[tokenId].status == Status.None) bounties.push(tokenId);
}

error NotPending();

function reject(uint256 tokenId) public onlyOwner {
if (requests[tokenId].status != Status.Pending) revert("!pending");
if (requests[tokenId].status != Status.Pending) revert NotPending();
requests[tokenId].status = Status.Rejected;
}

error NotApproved();
error NotWatcher();

function complete(uint256 tokenId, address recipient) public {
Bounty storage _bounty = requests[tokenId];
if (_bounty.status != Status.Approved) revert("!approved");
if (_bounty.watcher != msg.sender) revert("!watcher");
if (_bounty.status != Status.Approved) revert NotApproved();
if (_bounty.watcher != msg.sender) revert NotWatcher();
_bounty.status = Status.Completed;
transferFrom(_bounty.watcher, recipient, tokenId);
}
Expand Down
4 changes: 4 additions & 0 deletions test/bounty.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ contract BountyTest is Test {
// vm.createSelectFork(vm.rpcUrl('arbi')); // Arbitrum EthL2 fork.
_bounty = new bounty();
}

function testDeploy() public payable {
new bounty();
}
}

0 comments on commit 905cb87

Please sign in to comment.