all files / contracts/ wLYX.sol

100% Statements 8/8
100% Branches 6/6
100% Functions 4/4
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70                                                                                               
// SPDX-License-Identifier: MIT
pragma solidity =0.8.20;
 
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { AbstractDAO } from "./AbstractDAO.sol";
 
contract WrappedLYX is ERC20, AbstractDAO {
    event Unwrapped(
        address indexed recipient,
        uint256 indexed amount,
        uint256 indexed nonce
    );
 
    uint256 public _chainID;
    address internal _contractAddress;
 
    constructor(uint256 thresholdLevel) ERC20("Wrapped LYX", "wLYX") Ownable(msg.sender) {
        _thresholdLevel = thresholdLevel;
        _threshold = thresholdLevel;
        _operator = owner();
        _queueOrder = 1;
        _votesSent = 0;
        _votingInProgress = 0;
        _bps = 6666;
        _requiredVoteThreshold = 2 * _bps;
        _authorizedAddressesCount = 2;
        uint256 id;
        assembly {
            id := chainid()
        }
        _chainID = id;
        _contractAddress = address(this);
    }
 
    function mint(
        uint256 value,
        uint256 bridgeNonce,
        address recipient,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external {
        require(_nonces[bridgeNonce] == false, "Nonce already used");
        require(
            ECDSA.recover(
                keccak256(abi.encodePacked(value, recipient, bridgeNonce, _chainID, _contractAddress)),
                v,
                r,
                s
            ) == _operator,
            "Signature verification failure"
        );
        require(_threshold >= value, "Value exceeds current threshold");
        _nonces[bridgeNonce] = true;
        _mint(recipient, value);
        _threshold -= value;
    }
 
    function burn(uint256 value) external {
        burnFor(msg.sender, value);
    }
 
    function burnFor(address recipient, uint256 value) public {
        _burn(msg.sender, value);
        emit Unwrapped(recipient, value, _burnNonce++);
    }
}