Skip to content

Commit df530cd

Browse files
committed
Rendu controle
1 parent 5b83731 commit df530cd

File tree

9 files changed

+570
-34
lines changed

9 files changed

+570
-34
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "lib/forge-std"]
22
path = lib/forge-std
33
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/openzeppelin-contracts"]
5+
path = lib/openzeppelin-contracts
6+
url = https://github.com/OpenZeppelin/openzeppelin-contracts

foundry.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@
44
"name": "v1.11.0",
55
"rev": "8e40513d678f392f398620b3ef2b418648b33e89"
66
}
7+
},
8+
"lib/openzeppelin-contracts": {
9+
"tag": {
10+
"name": "v5.5.0",
11+
"rev": "fcbae5394ae8ad52d8e580a3477db99814b9d565"
12+
}
713
}
814
}

lib/openzeppelin-contracts

Submodule openzeppelin-contracts added at fcbae53
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.26;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {SimpleVotingSystem} from "../src/SimpleVotingSystem.sol";
6+
import {VoterNFT} from "../src/VoterNFT.sol";
7+
import {DonorNFT} from "../src/DonorNFT.sol";
8+
9+
contract DeploySimpleVotingSystem is Script {
10+
function run() external returns (SimpleVotingSystem, VoterNFT, DonorNFT) {
11+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
12+
13+
vm.startBroadcast(deployerPrivateKey);
14+
15+
VoterNFT voterNFT = new VoterNFT();
16+
17+
DonorNFT donorNFT = new DonorNFT();
18+
19+
SimpleVotingSystem votingSystem = new SimpleVotingSystem(
20+
address(voterNFT),
21+
address(donorNFT)
22+
);
23+
24+
voterNFT.transferOwnership(address(votingSystem));
25+
donorNFT.transferOwnership(address(votingSystem));
26+
27+
vm.stopBroadcast();
28+
29+
return (votingSystem, voterNFT, donorNFT);
30+
}
31+
}

src/DonorNFT.sol

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.26;
3+
4+
import {ERC721} from "lib/openzeppelin-contracts/contracts/token/ERC721/ERC721.sol";
5+
import {Ownable} from "lib/openzeppelin-contracts/contracts/access/Ownable.sol";
6+
7+
8+
contract DonorNFT is ERC721, Ownable {
9+
uint256 private _nextTokenId;
10+
11+
12+
mapping(uint256 => uint256) public donationAmount;
13+
mapping(uint256 => uint256) public donationTimestamp;
14+
15+
error OnlyVotingSystem();
16+
17+
event DonorNFTMinted(address indexed donor, uint256 tokenId, uint256 amount, uint256 timestamp);
18+
19+
20+
constructor() ERC721("Donor Proof", "DONOR") Ownable(msg.sender) {
21+
_nextTokenId = 1;
22+
}
23+
24+
25+
function mint(address _donor, uint256 _amount) external onlyOwner returns (uint256) {
26+
if(_donor == address(0)) revert OnlyVotingSystem();
27+
28+
uint256 tokenId = _nextTokenId;
29+
_nextTokenId++;
30+
31+
donationAmount[tokenId] = _amount;
32+
donationTimestamp[tokenId] = block.timestamp;
33+
_safeMint(_donor, tokenId);
34+
35+
emit DonorNFTMinted(_donor, tokenId, _amount, block.timestamp);
36+
37+
return tokenId;
38+
}
39+
40+
41+
function totalSupply() external view returns (uint256) {
42+
return _nextTokenId - 1;
43+
}
44+
45+
46+
function hasDonated(address _donor) external view returns (bool) {
47+
return balanceOf(_donor) > 0;
48+
}
49+
}

0 commit comments

Comments
 (0)