elevenbuckets / OptractContract

Solidity smart contact of https://github.com/elevenbuckets/Optract-Tokenized-Opinions
GNU General Public License v3.0
1 stars 0 forks source link

Meta Mining Integration #3

Open infwonder opened 5 years ago

infwonder commented 5 years ago
  1. With each newly committed Optract block, the mapping in block registry should also include (directly or indirectly) "fortify defence" of next block. If indirectly stored, a constant function should be added to calculate current fortify defence based on a formula in the same contract.

  2. Need to define how tippers' lottery tickets are calculated... And it needs to use side chain tx as proof.

infwonder commented 5 years ago

In the end, we may be able to merge the simplified meta mining code into Optract main contract. What do you think @akaron ?

akaron commented 5 years ago

I think there's no need for players to calculate best answers, right? Here are some preliminary pseudo-code:

contract Optract {

    mapping (uint => mapping(address => address[])) tipRecord;
    // uint: block, address: tipper, address[]: receivers
    mapping (address => bytes32[2]) tipTickets
    // tickets for metamining; ticket 0 is holding, ticket 1 is challanging

    constructor() public {
    }

    // prepare for metamining
    function fortify(bytes32 defense) public validatorOnly returns() {
        // set up new game for current sblock
        // how to synchronize the time of a new game and a new sblock
    }

    function adjustDifficulty() public validatorOnly returns() {
        // tuning digits?
    }

    // tipping and metamining
    function tipping(address _to, uint amount) public payable returns() {
        // `amount` should be fixed, or, at least restricted.
        // verify membership of `msg.sender` and `_to`
        // we may need to restrict that msg.sender can only tip `_to` once per block
        tipRecord[sblockNo][msg.sender].push(_to);
        if (tipRecord[sblockNo][msg.sender].length == 1) {  // 1 can be adjusted to larger value
            // while claim(), need to verify tipRecord[sblockNo][msg.sender].length >= 1
            tipTickets[msg.sender][0] = keccak256(abi.encodePacked(msg.sender, block.height));  // should have better ticket
        }
        QOTInterface(QOTAddr).transferFrom(msg.sender, _to, amount); // need approve first
    }

    function challenge() public isActiveMember notDefender gameStarted returns (bool) {
        // here, one no need to use the ticket at this sblock
        tipTickets[msg.sender][1] = tipTickets[msg.sender][0];
        delete tipTickets[msg.sender][0];
    }

    function claim() public returns (bool) {
        // ERC20 and ERC721
        // check tipTickets[msg.sender][1] wins or not
    }

}
akaron commented 5 years ago

should add a data structure to record how much tip an user has received, maybe simply mapping(address=>uint)? And a query function to return this mapping.

infwonder commented 5 years ago

For that please see issue #4

infwonder commented 5 years ago

Claim function needs to submit:

akaron commented 5 years ago
1. With each newly committed Optract block, the mapping in block registry should also include (directly or indirectly) "fortify defence" of next block. If indirectly stored, a constant function should be added to calculate current fortify defence based on a formula in the same contract.

2. Need to define how tippers' lottery tickets are calculated... And it needs to use side chain tx as proof.
  1. answered here: https://github.com/elevenbuckets/OptractContract/blob/317898df39ac730cc6731afa2f30425c2c9c951c/contracts/BlockRegistry.sol#L189
  2. use the txHash