Skip to content

Commit

Permalink
refactoring archi + address provider start
Browse files Browse the repository at this point in the history
  • Loading branch information
drikssy committed Sep 14, 2024
1 parent fc4c234 commit 7a92e1a
Show file tree
Hide file tree
Showing 41 changed files with 538 additions and 476 deletions.
12 changes: 6 additions & 6 deletions contracts/Airdrop/Airdrop.sol → contracts/Airdrop.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "./IAirdrop.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import {IAirdrop} from "contracts/interfaces/IAirdrop.sol";

contract Airdrop is IAirdrop, Ownable, ReentrancyGuard, Pausable {
// Type declarations
Expand Down Expand Up @@ -53,7 +53,7 @@ contract Airdrop is IAirdrop, Ownable, ReentrancyGuard, Pausable {
if (address(traitToken) == address(0)) revert Airdrop__AddressZero();
started = true;
totalTokenAmount = amount;
traitToken.transferFrom(tx.origin, address(this), amount); // Why tx.origin and not msg.sender?
traitToken.transferFrom(msg.sender, address(this), amount);
}

function allowDaoFund() external onlyOwner {
Expand Down
11 changes: 9 additions & 2 deletions contracts/DAOFund/DAOFund.sol → contracts/DAOFund.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import './IUniswapV2Router.sol';
import '../Trait/ITrait.sol';
import { ITrait } from './interfaces/ITrait.sol';
import { IUniswapV2Router01, IUniswapV2Router02 } from './interfaces/IUniswapV2Router.sol';

contract DAOFund {
// Type declarations

// Events

// Modifiers

// State variables
ITrait public token;
IUniswapV2Router01 public uniswapV2Router;

Expand Down
8 changes: 4 additions & 4 deletions contracts/DevFund/DevFund.sol → contracts/DevFund.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import '@openzeppelin/contracts/security/Pausable.sol';
import './IDevFund.sol';
import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol';
import {ReentrancyGuard} from '@openzeppelin/contracts/security/ReentrancyGuard.sol';
import {Pausable} from '@openzeppelin/contracts/security/Pausable.sol';
import {IDevFund} from './interfaces/IDevFund.sol';

contract DevFund is IDevFund, Ownable, ReentrancyGuard, Pausable {
// State variables
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "./IEntityForging.sol";
import "../TraitForgeNft/ITraitForgeNft.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import {ITraitForgeNft} from "./interfaces/ITraitForgeNft.sol";
import {IEntityForging} from "./interfaces/IEntityForging.sol";

contract EntityForging is IEntityForging, ReentrancyGuard, Ownable, Pausable {
ITraitForgeNft public nftContract;
Expand Down
104 changes: 104 additions & 0 deletions contracts/EntityTrading.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol";
import {IEntityTrading} from "./interfaces/IEntityTrading.sol";
import {ITraitForgeNft} from "./interfaces/ITraitForgeNft.sol";

contract EntityTrading is IEntityTrading, ReentrancyGuard, Ownable, Pausable {
ITraitForgeNft public nftContract;
address payable public nukeFundAddress;
uint256 private constant BPS = 10_000; // denominator of basis points
uint256 public taxCut = 1000; //10%

uint256 public listingCount = 0;
/// @dev tokenid -> listings index
mapping(uint256 => uint256) public listedTokenIds;
/// @dev index -> listing info
mapping(uint256 => Listing) public listings;

constructor(address _traitForgeNft) {
nftContract = ITraitForgeNft(_traitForgeNft);
}

function pause() public onlyOwner {
_pause();
}

function unpause() public onlyOwner {
_unpause();
}

// allows the owner to set NukeFund address
function setNukeFundAddress(address payable _nukeFundAddress) external onlyOwner {
nukeFundAddress = _nukeFundAddress;
}

function setTaxCut(uint256 _taxCut) external onlyOwner {
require(_taxCut <= BPS, "Tax cut cannot exceed 100%");
taxCut = _taxCut;
}

// function to lsit NFT for sale
function listNFTForSale(uint256 tokenId, uint256 price) public whenNotPaused nonReentrant {
require(price > 0, "Price must be greater than zero");
require(nftContract.ownerOf(tokenId) == msg.sender, "Sender must be the NFT owner.");
require(
nftContract.getApproved(tokenId) == address(this) || nftContract.isApprovedForAll(msg.sender, address(this)),
"Contract must be approved to transfer the NFT."
);

nftContract.transferFrom(msg.sender, address(this), tokenId); // trasnfer NFT to contract

++listingCount;
listings[listingCount] = Listing(msg.sender, tokenId, price, true);
listedTokenIds[tokenId] = listingCount;

emit NFTListed(tokenId, msg.sender, price);
}

// function to buy an NFT listed for sale
function buyNFT(uint256 tokenId) external payable whenNotPaused nonReentrant {
Listing memory listing = listings[listedTokenIds[tokenId]];
require(msg.value == listing.price, "ETH sent does not match the listing price");
require(listing.seller != address(0), "NFT is not listed for sale.");

//transfer eth to seller (distribute to nukefund)
uint256 devShare = (msg.value * taxCut) / BPS;
uint256 sellerProceeds = msg.value - devShare;
transferToNukeFund(devShare); // transfer contribution to nukeFund

// transfer NFT from contract to buyer
(bool success,) = payable(listing.seller).call{value: sellerProceeds}("");
require(success, "Failed to send to seller");
nftContract.transferFrom(address(this), msg.sender, tokenId); // transfer NFT to the buyer

delete listings[listedTokenIds[tokenId]]; // remove listing

emit NFTSold(tokenId, listing.seller, msg.sender, msg.value, devShare); // emit an event for the sale
}

function cancelListing(uint256 tokenId) public whenNotPaused nonReentrant {
Listing storage listing = listings[listedTokenIds[tokenId]];

// check if caller is the seller and listing is acivte
require(listing.seller == msg.sender, "Only the seller can canel the listing.");
require(listing.isActive, "Listing is not active.");

nftContract.transferFrom(address(this), msg.sender, tokenId); // transfer the nft back to seller

delete listings[listedTokenIds[tokenId]]; // mark the listing as inactive or delete it

emit ListingCanceled(tokenId, msg.sender);
}

// Correct and secure version of transferToNukeFund function
function transferToNukeFund(uint256 amount) private {
require(nukeFundAddress != address(0), "NukeFund address not set");
(bool success,) = nukeFundAddress.call{value: amount}("");
require(success, "Failed to send Ether to NukeFund");
emit NukeFundContribution(address(this), amount);
}
}
128 changes: 0 additions & 128 deletions contracts/EntityTrading/EntityTrading.sol

This file was deleted.

Loading

0 comments on commit 7a92e1a

Please sign in to comment.