Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Equious committed Jan 3, 2025
0 parents commit 5902ebc
Show file tree
Hide file tree
Showing 13 changed files with 861 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:

env:
FOUNDRY_PROFILE: ci

jobs:
check:
strategy:
fail-fast: true

name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Show Forge version
run: |
forge --version
- name: Run Forge fmt
run: |
forge fmt --check
id: fmt

- name: Run Forge build
run: |
forge build --sizes
id: build

- name: Run Forge tests
run: |
forge test -vvv
id: test
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
[submodule "lib/foundry-devops"]
path = lib/foundry-devops
url = https://github.com/Cyfrin/foundry-devops
[submodule "lib/slither"]
path = lib/slither
url = https://github.com/crytic/slither
7 changes: 7 additions & 0 deletions MakeFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-include .env
.PHONY: all test clean deploy fund help install snapshot format anvil

install:
@forge install OpenZeppelin/openzeppelin-contracts --no-commit
@forge install foundry-rs/forge-std --no-commit
@forge install foundry-rs/foundry-devops --no-commit
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Pieces Protocol

# Contest Details

### Prize Pool

- High - 100xp
- Medium - 20xp
- Low - 2xp

- Starts: January 16, 2025 Noon UTC
- Ends: January 23, 2025 Noon UTC

### Stats

- nSLOC:
- Complexity Score:

[//]: # "contest-details-open"

## About the Project

## Summary

A new marketplace where users can buy a fraction of an nft and trade with this one, if some user has all the fractions of an nft, can claim the original nft that is locked.

## Actors

- Buyer: The purchaser of the nft fraction.
- Seller: The seller of the nft fraction

[//]: # "contest-details-close"

## Scope (contracts)

```
├── src
│ ├── TokenDivider.sol
│ └── token
│ └── ERC20ToGenerateNftFraccion.sol
```

Compatibilities:

Blockchains:

- Ethereum
- EVM Equivalent

Tokens:

- ETH
- ERC721 Standard

[//]: # "scope-close"
[//]: # "getting-started-open"

## Setup

Build:

```bash
git clone https://github.com/JuanPeVentura/NftFractionMarketplace.git

make install

forge build
```

Tests:

```bash
forge test
```

[//]: # "getting-started-close"
[//]: # "known-issues-open"

## Known Issues

No known issues reported

[//]: # "known-issues-close"
9 changes: 9 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
remappings=['@openzeppelin/contracts=lib/openzeppelin-contracts/contracts']

fs_permissions = [{ access = "read", path = "./broadcast" }, {access = "read", path = "./Images/"}]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
17 changes: 17 additions & 0 deletions script/DeployTokenDivider.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity ^0.8.18;


import {Script} from 'forge-std/Script.sol';
import {TokenDivider} from 'src/TokenDivider.sol';

contract DeployTokenDivider is Script {
function run() external returns(TokenDivider){
vm.startBroadcast();
TokenDivider tokenDivider = new TokenDivider();
vm.stopBroadcast();

return tokenDivider;
}

}
110 changes: 110 additions & 0 deletions script/Interactions.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;


import {Script, console} from "forge-std/Script.sol";
import {DevOpsTools} from "lib/foundry-devops/src/DevOpsTools.sol";
import {TokenDivider} from "src/TokenDivider.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";




contract DivideNft is Script {

function run(address nftAddress, uint256 tokenId, uint256 amount) public {
address mostRecentDelployment = DevOpsTools.get_most_recent_deployment("TokenDivider", block.chainid);
divideNft(mostRecentDelployment, nftAddress, tokenId, amount);

}


function divideNft(address mostRecentDeployment, address nftAddress, uint256 tokenId, uint256 amount) public {
vm.startBroadcast(msg.sender);
IERC721(nftAddress).approve(mostRecentDeployment, tokenId);
vm.stopBroadcast();
TokenDivider(mostRecentDeployment).divideNft(nftAddress, tokenId, amount);


}
}

contract ClaimNft is Script {

function run(address nftAddress) public {
address mostRecentDelployment = DevOpsTools.get_most_recent_deployment("TokenDivider", block.chainid);
claimNft(mostRecentDelployment, nftAddress);
}


function claimNft(address mostRecentDeployment, address nftAddress) public {
address erc20 = TokenDivider(mostRecentDeployment).getErc20InfoFromNft(nftAddress).erc20Address;
uint256 totalErc20MintedAmount = TokenDivider(mostRecentDeployment).getErc20TotalMintedAmount(erc20);
vm.startBroadcast(msg.sender);
IERC20(erc20).approve(mostRecentDeployment, totalErc20MintedAmount);
TokenDivider(mostRecentDeployment).claimNft(nftAddress);
vm.stopBroadcast();


}
}


contract TransferErc20 is Script {
function run(address nftAddress, address to, uint256 amount) public {
address mostRecentDelployment = DevOpsTools.get_most_recent_deployment("TokenDivider", block.chainid);
transferErc20(mostRecentDelployment, nftAddress, to, amount);
}


function transferErc20(address mostRecentDeployment, address nftAddress, address to, uint256 amount) public {
address erc20 = TokenDivider(mostRecentDeployment).getErc20InfoFromNft(nftAddress).erc20Address;

vm.startBroadcast(msg.sender);
IERC20(erc20).approve(mostRecentDeployment, amount);
TokenDivider(mostRecentDeployment).transferErcTokens(nftAddress, to, amount);
vm.stopBroadcast();



}
}


contract SellErc20 is Script {
function run(address nftAddress, uint256 price, uint256 amount) public {
address mostRecentDelployment = DevOpsTools.get_most_recent_deployment("TokenDivider", block.chainid);
sellErc20(mostRecentDelployment, nftAddress, price, amount);
}


function sellErc20(address mostRecentDeployment, address nftAddress, uint256 price, uint256 amount) public {
address erc20 = TokenDivider(mostRecentDeployment).getErc20InfoFromNft(nftAddress).erc20Address;

vm.startBroadcast(msg.sender);
IERC20(erc20).approve(mostRecentDeployment, amount);
TokenDivider(mostRecentDeployment).sellErc20(nftAddress, price, amount);
vm.stopBroadcast();



}
}

contract BuyErc20 is Script {
function run(uint256 orderIndex, address seller) public {
address mostRecentDelployment = DevOpsTools.get_most_recent_deployment("TokenDivider", block.chainid);
buyErc20(mostRecentDelployment, orderIndex, seller);
}


function buyErc20(address mostRecentDeployment, uint256 orderIndex ,address seller) public {
vm.startBroadcast(msg.sender);
TokenDivider(mostRecentDeployment).buyOrder{value: TokenDivider(mostRecentDeployment).getOrderPrice(seller, orderIndex) + ((TokenDivider(mostRecentDeployment).getOrderPrice(seller, orderIndex) / 100) / 2)}(orderIndex, seller);
vm.stopBroadcast();



}
}
Loading

0 comments on commit 5902ebc

Please sign in to comment.