Skip to content

nodew #30

Description

@DOUGLASDAVIS08161978

docker run -p 50001:50001 -p 8080:80
--volume $PWD/data_bitcoin_mainnet:/data
--rm -i -t esplora
bash -c "/srv/explorer/run.sh bitcoin-mainnet explorer" && // SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract WrappedTestnetBTC {
string public constant name = "Wrapped Testnet Bitcoin";
string public constant symbol = "wTBTC";
uint8 public constant decimals = 18;
uint256 public totalSupply;

address public bridgeOperator;
bool public paused = false;

mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;

event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event Mint(address indexed to, uint256 amount, string bitcoinTxId);
event Burn(address indexed from, uint256 amount, string bitcoinAddress);
event BridgeOperatorChanged(address indexed oldOperator, address indexed newOperator);
event Paused(bool status);

modifier onlyBridgeOperator() {
    require(msg.sender == bridgeOperator, "Only bridge operator");
    _;
}

modifier whenNotPaused() {
    require(!paused, "Contract paused");
    _;
}

constructor(address _initialOperator) {
    bridgeOperator = _initialOperator;
    emit BridgeOperatorChanged(address(0), _initialOperator);
}

// Bridge function: Mint wTBTC when BTC is locked on Bitcoin testnet
function mint(address to, uint256 amount, string calldata bitcoinTxId) 
    external 
    onlyBridgeOperator 
    whenNotPaused 
{
    require(to != address(0), "Mint to zero address");
    require(amount > 0, "Amount must be positive");
    
    balanceOf[to] += amount;
    totalSupply += amount;
    
    emit Transfer(address(0), to, amount);
    emit Mint(to, amount, bitcoinTxId);
}

// Bridge function: Burn wTBTC to unlock BTC on Bitcoin testnet
function burn(uint256 amount, string calldata bitcoinAddress) 
    external 
    whenNotPaused 
{
    require(balanceOf[msg.sender] >= amount, "Insufficient balance");
    require(bytes(bitcoinAddress).length > 0, "Bitcoin address required");
    
    balanceOf[msg.sender] -= amount;
    totalSupply -= amount;
    
    emit Transfer(msg.sender, address(0), amount);
    emit Burn(msg.sender, amount, bitcoinAddress);
}

// ERC20 standard functions
function approve(address spender, uint256 amount) 
    external 
    whenNotPaused 
    returns (bool) 
{
    allowance[msg.sender][spender] = amount;
    emit Approval(msg.sender, spender, amount);
    return true;
}

function transfer(address to, uint256 amount) 
    external 
    whenNotPaused 
    returns (bool) 
{
    _transfer(msg.sender, to, amount);
    return true;
}

function transferFrom(address from, address to, uint256 amount) 
    external 
    whenNotPaused 
    returns (bool) 
{
    require(allowance[from][msg.sender] >= amount, "Allowance exceeded");
    
    allowance[from][msg.sender] -= amount;
    _transfer(from, to, amount);
    
    return true;
}

// Admin functions
function changeBridgeOperator(address newOperator) external onlyBridgeOperator {
    require(newOperator != address(0), "Zero address");
    emit BridgeOperatorChanged(bridgeOperator, newOperator);
    bridgeOperator = newOperator;
}

function setPaused(bool _paused) external onlyBridgeOperator {
    paused = _paused;
    emit Paused(_paused);
}

// Internal function
function _transfer(address from, address to, uint256 amount) internal {
    require(from != address(0), "Transfer from zero address");
    require(to != address(0), "Transfer to zero address");
    require(balanceOf[from] >= amount, "Insufficient balance");
    
    balanceOf[from] -= amount;
    balanceOf[to] += amount;
    
    emit Transfer(from, to, amount);
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions