-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring archi + address provider start
- Loading branch information
Showing
41 changed files
with
538 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
contracts/EntityForging/EntityForging.sol → contracts/EntityForging.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.