-
Notifications
You must be signed in to change notification settings - Fork 29
Wisdom #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
enyinnaya1234
wants to merge
2
commits into
BlockheaderWeb3-Community:main
Choose a base branch
from
enyinnaya1234:wisdom
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Wisdom #14
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
submissions/Assignment3/enyinnaya1234/CrowdFundingContract.sol
This file contains hidden or 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,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; | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } |
This file contains hidden or 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,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); | ||
| } | ||
| } |
This file contains hidden or 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,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"); | ||
| } | ||
| } |
This file contains hidden or 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,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; | ||
| } |
This file contains hidden or 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,7 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
|
|
||
| pragma solidity ^0.8.24; | ||
|
|
||
| interface IERC721{ | ||
| function _mint(address to, uint256 tokenId) external; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()tomint()There was a problem hiding this comment.
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