-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleQRC20.sol
More file actions
71 lines (63 loc) · 2.83 KB
/
ExampleQRC20.sol
File metadata and controls
71 lines (63 loc) · 2.83 KB
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
71
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;
/// @title ExampleQRC20
/// @notice A minimal QRC20 fungible token for the Quantova Virtual Machine (QVM).
/// @dev QRC20 mirrors the familiar fungible-token surface (balances, transfers,
/// approvals) for the QVM. The QVM is Solidity-compatible, so this compiles
/// with a standard Solidity toolchain and deploys as a QVM transaction
/// (see scripts/deploy.js and docs/deploying.md).
///
/// This example keeps the core surface only. A production QRC20 may add the
/// optional post-quantum permit (a gasless approval authorized by a Falcon
/// signature and verified on-chain via the Falcon precompile, with a
/// monotonic per-account nonce for replay protection). See the QRC20
/// standard in the developer documentation.
contract ExampleQRC20 {
string public name;
string public symbol;
uint8 public constant decimals = 18;
uint256 public totalSupply;
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);
/// @param _name Token name.
/// @param _symbol Token symbol.
/// @param _initialSupply Initial supply (in whole tokens; scaled by 10**decimals).
constructor(string memory _name, string memory _symbol, uint256 _initialSupply) {
name = _name;
symbol = _symbol;
uint256 minted = _initialSupply * (10 ** decimals);
totalSupply = minted;
balanceOf[msg.sender] = minted;
emit Transfer(address(0), msg.sender, minted);
}
function transfer(address to, uint256 value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function approve(address spender, uint256 value) external returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external returns (bool) {
uint256 allowed = allowance[from][msg.sender];
require(allowed >= value, "QRC20: insufficient allowance");
if (allowed != type(uint256).max) {
allowance[from][msg.sender] = allowed - value;
}
_transfer(from, to, value);
return true;
}
function _transfer(address from, address to, uint256 value) internal {
require(to != address(0), "QRC20: transfer to zero address");
uint256 bal = balanceOf[from];
require(bal >= value, "QRC20: insufficient balance");
unchecked {
balanceOf[from] = bal - value;
balanceOf[to] += value;
}
emit Transfer(from, to, value);
}
}