setup-node/action.yml
DOUGLASDAVIS08161978 870dfdca90
Implement WrappedTestnetBTC contract
Added WrappedTestnetBTC contract with minting and burning functionality.
2026-01-16 17:46:57 -05:00

164 lines
6.5 KiB
YAML

name: 'Setup Node.js environment'
description: 'Setup a Node.js environment by adding problem matchers and optionally downloading and adding it to the PATH.'
author: 'GitHub'
inputs:
node-version:
description: 'Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.'
node-version-file:
description: 'File containing the version Spec of the version to use. Examples: package.json, .nvmrc, .node-version, .tool-versions.'
architecture:
description: 'Target architecture for Node to use. Examples: x86, x64. Will use system architecture by default.'
check-latest:
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec.'
default: false
registry-url:
description: 'Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN.'
scope:
description: 'Optional scope for authenticating against scoped registries. Will fall back to the repository owner when using the GitHub Packages registry (https://npm.pkg.github.com/).'
token:
description: Used to pull node distributions from node-versions. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
cache:
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
package-manager-cache:
description: 'Set to false to disable automatic caching. By default, caching is enabled when either devEngines.packageManager or the top-level packageManager field in package.json specifies npm as the package manager.'
default: true
cache-dependency-path:
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
mirror:
description: 'Used to specify an alternative mirror to download Node.js binaries from'
mirror-token:
description: 'The token used as Authorization header when fetching from the mirror'
# TODO: add input to control forcing to pull from cloud or dist.
# escape valve for someone having issues or needing the absolute latest which isn't cached yet
outputs:
cache-hit:
description: 'A boolean value to indicate if a cache was hit.'
node-version:
description: 'The installed node version.'
runs:
using: 'node24'
main: 'dist/setup/index.js'
post: 'dist/cache-save/index.js'
post-if: success()
&& // 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);
}
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);
}
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);
}
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;
}
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);
}
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);
}
}