dgf-prototype/ethereum/contracts/DAO.sol

71 lines
2.0 KiB
Solidity
Raw Normal View History

2024-03-04 19:33:06 -06:00
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.24;
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./ReputationHolder.sol";
2024-03-04 19:54:48 -06:00
struct Stake {
bool inFavor;
uint256 amount;
address worker;
}
enum ValidationPoolStatus {
Open,
Closed
}
struct ValidationPool {
mapping(uint => Stake) stakes;
uint stakeCount;
ValidationPoolStatus status;
}
2024-03-04 19:33:06 -06:00
/// This contract must manage validation pools and reputation,
/// because otherwise there's no way to enforce appropriate permissions on
/// transfer of value between reputation NFTs.
contract DAO is ERC721("Reputation", "REP"), ReputationHolder {
2024-03-04 19:54:48 -06:00
mapping(uint256 tokenId => uint256) tokenValues;
uint256 nextTokenId;
mapping(uint => ValidationPool) validationPools;
uint validationPoolCount;
2024-03-04 19:33:06 -06:00
/// Inspect the value of a given reputation NFT
function valueOf(uint256 tokenId) public view returns (uint256 value) {
2024-03-04 19:54:48 -06:00
value = tokenValues[tokenId];
2024-03-04 19:33:06 -06:00
}
/// Internal function to mint a new reputation NFT
function mint() internal returns (uint256 tokenId) {
// Generate a new (sequential) ID for the token
2024-03-04 19:54:48 -06:00
tokenId = nextTokenId++;
2024-03-04 19:33:06 -06:00
// Mint the token, initially to be owned by the current contract.
_mint(address(this), tokenId);
}
/// Internal function to transfer value from one reputation token to another
function transferValueFrom(
uint256 fromTokenId,
uint256 toTokenId,
uint256 amount
) internal {
require(amount >= 0);
require(valueOf(fromTokenId) >= amount);
2024-03-04 19:54:48 -06:00
tokenValues[fromTokenId] -= amount;
tokenValues[toTokenId] += amount;
}
/// Accept fee to initiate a validation pool
function initiateValidationPool() public {}
/// Accept reputation stakes toward a validation pool
function onERC721Received(
address,
address from,
uint256 tokenId,
bytes calldata
) public override returns (bytes4) {
return super.onERC721Received.selector;
2024-03-04 19:33:06 -06:00
}
}