-
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.
- Loading branch information
Showing
15 changed files
with
192 additions
and
102 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
import "./Dao.sol"; | ||
import "../pool/ERC20DaoPool.sol"; | ||
|
||
contract ERC20Dao is Dao { | ||
|
||
ERC20DaoPool public daoPool; | ||
|
||
constructor(address _daoTokenAddress, uint256 _tokenCollateral, uint256 _challengePeriodSeconds, uint256 _nativeCollateral) | ||
Dao(_tokenCollateral, _challengePeriodSeconds, _nativeCollateral) { | ||
daoPool = new ERC20DaoPool(_daoTokenAddress); | ||
emit DaoPoolCreated(address(daoPool)); | ||
} | ||
|
||
function getDaoPool() override view internal returns (DaoPool) { | ||
return daoPool; | ||
} | ||
} |
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,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
import "./Dao.sol"; | ||
import "../pool/NFTDaoPool.sol"; | ||
|
||
contract NFTDao is Dao { | ||
|
||
NFTDaoPool public daoPool; | ||
|
||
constructor(address _daoTokenAddress, uint256 _tokenCollateral, uint256 _challengePeriodSeconds, uint256 _nativeCollateral) | ||
Dao(_tokenCollateral, _challengePeriodSeconds, _nativeCollateral) { | ||
daoPool = new NFTDaoPool(_daoTokenAddress); | ||
emit DaoPoolCreated(address(daoPool)); | ||
} | ||
|
||
function getDaoPool() override view internal returns (DaoPool) { | ||
return daoPool; | ||
} | ||
} |
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,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "./IDaoPool.sol"; | ||
|
||
abstract contract DaoPool is IDaoPool, Ownable { | ||
|
||
mapping(address => address[]) public proposalForVoters; | ||
mapping(address => address[]) public proposalAgainstVoters; | ||
mapping(address => uint256) public voterActiveProposals; | ||
mapping(address => bool) public approvedProposals; | ||
|
||
// only DAO can call this | ||
function approveProposal(address proposalAddress) public onlyOwner { | ||
approvedProposals[proposalAddress] = true; | ||
} | ||
|
||
// is invoked by proposal | ||
// msg.sender == proposal address | ||
function vote(address voterAddress, bool voteSide) override external { | ||
require(approvedProposals[msg.sender], "Proposal not approved"); | ||
if (voteSide) { | ||
proposalForVoters[msg.sender].push(voterAddress); | ||
} else { | ||
proposalAgainstVoters[msg.sender].push(voterAddress); | ||
} | ||
voterActiveProposals[voterAddress] += 1; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "./DaoPool.sol"; | ||
import "../Proposal.sol"; | ||
|
||
contract NFTDaoPool is DaoPool { | ||
|
||
ERC721 public token; | ||
mapping(address => uint256[]) public balances; | ||
|
||
event TokensDeposited(address indexed user, address indexed tokenAddress, uint256 tokenId); | ||
event TokensWithdrawn(address indexed user, address indexed tokenAddress, uint256 tokenId, address indexed withdrawAddress); | ||
|
||
constructor(address _tokenAddress) { | ||
token = ERC721(_tokenAddress); | ||
} | ||
|
||
function deposit(uint256 tokenId) public { | ||
balances[msg.sender].push(tokenId); | ||
emit TokensDeposited(msg.sender, address(token), tokenId); | ||
token.safeTransferFrom(msg.sender, address(this), tokenId); | ||
} | ||
|
||
function withdraw(uint256 tokenId, address withdrawAddress) public { | ||
require(voterActiveProposals[msg.sender] == 0, "User has active proposals"); | ||
uint256 index; | ||
uint256[] storage userTokenIds = balances[msg.sender]; | ||
for (uint256 i = 0; i < balances[msg.sender].length ; i++) { | ||
if (userTokenIds[i] == tokenId) { | ||
index = userTokenIds[i]; | ||
token.safeTransferFrom(address(this), withdrawAddress, tokenId); | ||
delete userTokenIds[i]; | ||
break; | ||
} | ||
} | ||
emit TokensWithdrawn(msg.sender, address(token), tokenId, withdrawAddress); | ||
} | ||
|
||
function resolveProposal(address proposalAddress) public { | ||
Proposal proposal = Proposal(proposalAddress); | ||
require(proposal.isEnded(), "Proposal not ended"); | ||
address[] memory voters = proposal.isPassed() ? proposalForVoters[proposalAddress] : proposalAgainstVoters[proposalAddress]; | ||
uint256 toTransferAmount = 0; | ||
for (uint256 i = 0; i < voters.length; i++) { | ||
address voterAddress = voters[i]; | ||
uint256[] memory userTokenIds = balances[voterAddress]; | ||
for (uint256 k = 0; k < userTokenIds.length; k++) { | ||
uint256 tokenId = userTokenIds[k]; | ||
token.safeTransferFrom(address(this), owner(), tokenId); | ||
} | ||
delete balances[voterAddress]; | ||
voterActiveProposals[voterAddress] = 0; | ||
} | ||
delete proposalForVoters[proposalAddress]; | ||
delete proposalAgainstVoters[proposalAddress]; | ||
delete approvedProposals[proposalAddress]; | ||
} | ||
|
||
function balanceOf(address account) override public view returns (uint256) { | ||
return balances[account].length; | ||
} | ||
} |
Oops, something went wrong.