Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions submissions/Assignment3/enyinnaya1234/CrowdFundingContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.24;

import "./ERC20.sol";
import "./ERC721.sol";

contract CrowdFundingContract{
bool public fundingGoalMet = false;
uint public fundingThreshold;
uint public fundingGoal;
address public owner;

// initialize imported files
ERC20 private erc20;
ERC721 private erc721;

// Mapping
mapping(address => uint256) public _tokenBalances;
mapping(address => uint256) public _contributions;

// Events
event trackContributions(address contributor, uint amount);

constructor(uint _fundingGoal, uint _fundingThreshold, address payable Erc20Address, address Erc721Address){
fundingGoal = _fundingGoal;
fundingThreshold = _fundingThreshold;
owner = msg.sender;
erc20 = ERC20(Erc20Address); //0xdA36e707Af22009FA453Fe3D2707c510C8E4AC46
erc721 = ERC721(Erc721Address); //0xee41a93503C6007c72BbfEc027412430B3c743F0
}


// modifiers
modifier onlyOwner(){
require(msg.sender == owner, "Not owner");
_;
}

// Functions
// Tracking contributions
// Contribution exceed a set threshold, mint an ERC721 NFT and send to contributor's account
function exceedThreshold(address to ) external onlyOwner payable {
if (address(this).balance < fundingGoal){
require(msg.value > 0, "contributions must be above 0");
_contributions[msg.sender] += msg.value;
if(msg.value > fundingThreshold){
uint256 tokenId = uint256(keccak256(abi.encodePacked(msg.sender)));
erc721._mint(to, tokenId);
}
else{
erc20.mint(to, msg.value);
}
}
else{
// withdraw funds
uint balance = address(this).balance;
address payable sendTo = payable(owner);
sendTo.transfer(balance);
fundingGoalMet = true;
}

}


}
47 changes: 47 additions & 0 deletions submissions/Assignment3/enyinnaya1234/ERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.24;


contract ERC20 {
error FunctionDoesNotExist();
string public name;
string public symbol;
uint8 public decimals ;
uint256 public totalSupply;

mapping(address => uint256) public balanceOf;
//mapping(address)

event Transfer(address indexed _from, address indexed _to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);

constructor(uint _totalSupply, string memory _name, string memory _symbol, uint8 _decimals){
_totalSupply = totalSupply;
_name = name;
_symbol = symbol;
_decimals = decimals;
}

receive() external payable{}
fallback() external payable{
revert FunctionDoesNotExist();
}

function transfer(address recipient, uint256 amount) external returns (bool){
require(balanceOf[msg.sender] >= amount, "Insufficient funds");
balanceOf[msg.sender] -= amount;
balanceOf[recipient] += amount;

emit Transfer(msg.sender, recipient, amount);
return true;
}

function mint(address _to, uint256 _amount) external{
require(msg.sender != address(0), "zero address");
balanceOf[_to] += _amount;
totalSupply += _amount;

emit Transfer(address(0), _to, _amount);
}
}
33 changes: 33 additions & 0 deletions submissions/Assignment3/enyinnaya1234/ERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.24;


contract ERC721 {
// Mapping
mapping(uint256 => address) internal _ownerOf;
mapping(address => uint256) internal _balanceOf;

// event
event Transfer(address indexed from, address indexed to, uint256 indexed id);

function _mint(address to, uint256 tokenId) external{
require(to != address(0), "mint to zero address");
require(_ownerOf[tokenId] == address(0), "already minted");

_balanceOf[to]++;
_ownerOf[tokenId] = to;

emit Transfer(address(0), to, tokenId);
}

function balanceOf(address owner) external view returns (uint256){
require(owner != address(0), "owner = zero address");
return _balanceOf[owner];
}

function ownerOf(uint256 tokenId) external view returns (address ownerOfToken){
ownerOfToken = _ownerOf[tokenId];
require(ownerOfToken != address(0), "token doesn't exist");
}
}
8 changes: 8 additions & 0 deletions submissions/Assignment3/enyinnaya1234/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.24;

interface IERC20{
function transfer(address recipient, uint256 amount) external returns (bool);
function mint(address _to, uint256 _amount) external;
}
7 changes: 7 additions & 0 deletions submissions/Assignment3/enyinnaya1234/IERC721.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.24;

interface IERC721{
function _mint(address to, uint256 tokenId) external;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, external functions are not named with an underscore.
Update _mint() to mint()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sir...

God bless the instructor sir

}