dgf-prototype/ethereum/contracts/DAO.sol

39 lines
1.3 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";
/// 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 {
mapping(uint256 tokenId => uint256) _tokenValues;
uint256 _nextTokenId;
/// Inspect the value of a given reputation NFT
function valueOf(uint256 tokenId) public view returns (uint256 value) {
value = _tokenValues[tokenId];
}
/// Internal function to mint a new reputation NFT
function mint() internal returns (uint256 tokenId) {
// Generate a new (sequential) ID for the token
tokenId = _nextTokenId++;
// 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);
_tokenValues[fromTokenId] -= amount;
_tokenValues[toTokenId] += amount;
}
}