qvtx-developer-kit 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +108 -0
- package/README.md +0 -0
- package/abis/QVTXBridge.json +273 -0
- package/abis/QVTXDirectPurchase.json +621 -0
- package/abis/QVTXGovernance.json +267 -0
- package/abis/QVTXNFT.json +370 -0
- package/abis/QVTXRewards.json +155 -0
- package/abis/QVTXToken.json +311 -0
- package/abis/QVTXVesting.json +216 -0
- package/abis/index.js +16 -0
- package/bin/qvtx-developer-cli.js +99 -0
- package/config/index.js +108 -0
- package/config/networks.js +247 -0
- package/examples/basic-usage.js +39 -0
- package/examples/bridge-example.js +123 -0
- package/examples/direct-purchase.js +300 -0
- package/examples/governance-example.js +140 -0
- package/examples/nft-example.js +141 -0
- package/examples/staking-example.js +96 -0
- package/index.js +145 -0
- package/languages/blockchain_ai_sdk.js +0 -0
- package/languages/node_sdk.js +0 -0
- package/languages/solana_sdk.js +383 -0
- package/package.json +30 -3
- package/purchase/index.js +567 -0
- package/rewards/index.js +71 -0
- package/smart-contracts/QVTXBridge.sol +305 -0
- package/smart-contracts/QVTXDirectPurchase.sol +543 -0
- package/smart-contracts/QVTXGovernance.sol +325 -0
- package/smart-contracts/QVTXNFT.sol +338 -0
- package/smart-contracts/QVTXRewards.sol +102 -0
- package/smart-contracts/QVTXToken.sol +227 -0
- package/smart-contracts/QVTXVesting.sol +411 -0
- package/smart-contracts/interfaces/IERC20.sol +14 -0
- package/smart-contracts/interfaces/IERC20Metadata.sol +8 -0
- package/smart-contracts/interfaces/IERC721.sol +18 -0
- package/smart-contracts/interfaces/IERC721Metadata.sol +8 -0
- package/smart-contracts/interfaces/IERC721Receiver.sol +11 -0
- package/storage/index.js +112 -0
- package/templates/contract/ERC20Token.sol +116 -0
- package/templates/dapp/index.html +93 -0
- package/test/index.js +182 -0
- package/tools/build-tool.js +63 -0
- package/tools/create-template.js +116 -0
- package/tools/deploy-tool.js +55 -0
- package/tools/generate-docs.js +149 -0
- package/tools/init-project.js +138 -0
- package/tools/run-tests.js +64 -0
- package/types/index.d.ts +386 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title QVTX Rewards Contract
|
|
6
|
+
* @dev Cross-chain rewards distribution for QVTX ecosystem
|
|
7
|
+
*/
|
|
8
|
+
interface IERC20 {
|
|
9
|
+
function transfer(address to, uint256 amount) external returns (bool);
|
|
10
|
+
function transferFrom(address from, address to, uint256 amount) external returns (bool);
|
|
11
|
+
function balanceOf(address account) external view returns (uint256);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
contract QVTXRewards {
|
|
15
|
+
address public owner;
|
|
16
|
+
address public rewardToken;
|
|
17
|
+
|
|
18
|
+
uint256 public rewardRate = 100; // Rewards per block
|
|
19
|
+
uint256 public lastUpdateBlock;
|
|
20
|
+
uint256 public rewardPerTokenStored;
|
|
21
|
+
|
|
22
|
+
mapping(address => uint256) public userRewardPerTokenPaid;
|
|
23
|
+
mapping(address => uint256) public rewards;
|
|
24
|
+
mapping(address => uint256) public stakes;
|
|
25
|
+
|
|
26
|
+
uint256 public totalStaked;
|
|
27
|
+
|
|
28
|
+
event Staked(address indexed user, uint256 amount);
|
|
29
|
+
event Withdrawn(address indexed user, uint256 amount);
|
|
30
|
+
event RewardPaid(address indexed user, uint256 reward);
|
|
31
|
+
event RewardRateUpdated(uint256 newRate);
|
|
32
|
+
|
|
33
|
+
modifier onlyOwner() {
|
|
34
|
+
require(msg.sender == owner, "Not owner");
|
|
35
|
+
_;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
modifier updateReward(address account) {
|
|
39
|
+
rewardPerTokenStored = rewardPerToken();
|
|
40
|
+
lastUpdateBlock = block.number;
|
|
41
|
+
if (account != address(0)) {
|
|
42
|
+
rewards[account] = earned(account);
|
|
43
|
+
userRewardPerTokenPaid[account] = rewardPerTokenStored;
|
|
44
|
+
}
|
|
45
|
+
_;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
constructor(address _rewardToken) {
|
|
49
|
+
owner = msg.sender;
|
|
50
|
+
rewardToken = _rewardToken;
|
|
51
|
+
lastUpdateBlock = block.number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function rewardPerToken() public view returns (uint256) {
|
|
55
|
+
if (totalStaked == 0) {
|
|
56
|
+
return rewardPerTokenStored;
|
|
57
|
+
}
|
|
58
|
+
return rewardPerTokenStored +
|
|
59
|
+
((block.number - lastUpdateBlock) * rewardRate * 1e18) / totalStaked;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function earned(address account) public view returns (uint256) {
|
|
63
|
+
return (stakes[account] * (rewardPerToken() - userRewardPerTokenPaid[account])) / 1e18
|
|
64
|
+
+ rewards[account];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function stake(uint256 amount) external updateReward(msg.sender) {
|
|
68
|
+
require(amount > 0, "Cannot stake 0");
|
|
69
|
+
totalStaked += amount;
|
|
70
|
+
stakes[msg.sender] += amount;
|
|
71
|
+
IERC20(rewardToken).transferFrom(msg.sender, address(this), amount);
|
|
72
|
+
emit Staked(msg.sender, amount);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function withdraw(uint256 amount) external updateReward(msg.sender) {
|
|
76
|
+
require(amount > 0, "Cannot withdraw 0");
|
|
77
|
+
require(stakes[msg.sender] >= amount, "Insufficient stake");
|
|
78
|
+
totalStaked -= amount;
|
|
79
|
+
stakes[msg.sender] -= amount;
|
|
80
|
+
IERC20(rewardToken).transfer(msg.sender, amount);
|
|
81
|
+
emit Withdrawn(msg.sender, amount);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function claimReward() external updateReward(msg.sender) {
|
|
85
|
+
uint256 reward = rewards[msg.sender];
|
|
86
|
+
if (reward > 0) {
|
|
87
|
+
rewards[msg.sender] = 0;
|
|
88
|
+
IERC20(rewardToken).transfer(msg.sender, reward);
|
|
89
|
+
emit RewardPaid(msg.sender, reward);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function setRewardRate(uint256 _rate) external onlyOwner updateReward(address(0)) {
|
|
94
|
+
rewardRate = _rate;
|
|
95
|
+
emit RewardRateUpdated(_rate);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function emergencyWithdraw() external onlyOwner {
|
|
99
|
+
uint256 balance = IERC20(rewardToken).balanceOf(address(this));
|
|
100
|
+
IERC20(rewardToken).transfer(owner, balance);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @title QVTX Token
|
|
6
|
+
* @dev QuantVestrix native token with cross-chain capabilities
|
|
7
|
+
* @author QuantVestrix Tech Team (07-Tech)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import "./interfaces/IERC20.sol";
|
|
11
|
+
import "./interfaces/IERC20Metadata.sol";
|
|
12
|
+
|
|
13
|
+
contract QVTXToken is IERC20, IERC20Metadata {
|
|
14
|
+
string private constant _name = "QuantVestrix";
|
|
15
|
+
string private constant _symbol = "QVTX";
|
|
16
|
+
uint8 private constant _decimals = 18;
|
|
17
|
+
|
|
18
|
+
uint256 private _totalSupply;
|
|
19
|
+
address public owner;
|
|
20
|
+
address public bridgeContract;
|
|
21
|
+
|
|
22
|
+
mapping(address => uint256) private _balances;
|
|
23
|
+
mapping(address => mapping(address => uint256)) private _allowances;
|
|
24
|
+
mapping(address => bool) public minters;
|
|
25
|
+
mapping(address => bool) public blacklisted;
|
|
26
|
+
|
|
27
|
+
// Cross-chain tracking
|
|
28
|
+
mapping(uint256 => uint256) public chainSupply; // chainId => supply on that chain
|
|
29
|
+
uint256 public constant MAX_SUPPLY = 1_000_000_000 * 10**18; // 1 billion tokens
|
|
30
|
+
|
|
31
|
+
// Events
|
|
32
|
+
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
|
|
33
|
+
event MinterAdded(address indexed minter);
|
|
34
|
+
event MinterRemoved(address indexed minter);
|
|
35
|
+
event BridgeContractUpdated(address indexed newBridge);
|
|
36
|
+
event CrossChainMint(uint256 indexed sourceChain, address indexed to, uint256 amount);
|
|
37
|
+
event CrossChainBurn(uint256 indexed targetChain, address indexed from, uint256 amount);
|
|
38
|
+
event Blacklisted(address indexed account, bool status);
|
|
39
|
+
|
|
40
|
+
modifier onlyOwner() {
|
|
41
|
+
require(msg.sender == owner, "QVTX: caller is not owner");
|
|
42
|
+
_;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
modifier onlyMinter() {
|
|
46
|
+
require(minters[msg.sender] || msg.sender == owner, "QVTX: caller is not minter");
|
|
47
|
+
_;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
modifier onlyBridge() {
|
|
51
|
+
require(msg.sender == bridgeContract, "QVTX: caller is not bridge");
|
|
52
|
+
_;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
modifier notBlacklisted(address account) {
|
|
56
|
+
require(!blacklisted[account], "QVTX: account is blacklisted");
|
|
57
|
+
_;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
constructor(uint256 initialSupply) {
|
|
61
|
+
require(initialSupply <= MAX_SUPPLY, "QVTX: exceeds max supply");
|
|
62
|
+
owner = msg.sender;
|
|
63
|
+
_mint(msg.sender, initialSupply);
|
|
64
|
+
emit OwnershipTransferred(address(0), msg.sender);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ERC20 Metadata
|
|
68
|
+
function name() external pure override returns (string memory) {
|
|
69
|
+
return _name;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function symbol() external pure override returns (string memory) {
|
|
73
|
+
return _symbol;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function decimals() external pure override returns (uint8) {
|
|
77
|
+
return _decimals;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ERC20 Standard
|
|
81
|
+
function totalSupply() external view override returns (uint256) {
|
|
82
|
+
return _totalSupply;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function balanceOf(address account) external view override returns (uint256) {
|
|
86
|
+
return _balances[account];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function transfer(address to, uint256 amount) external override notBlacklisted(msg.sender) notBlacklisted(to) returns (bool) {
|
|
90
|
+
_transfer(msg.sender, to, amount);
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function allowance(address tokenOwner, address spender) external view override returns (uint256) {
|
|
95
|
+
return _allowances[tokenOwner][spender];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function approve(address spender, uint256 amount) external override notBlacklisted(msg.sender) returns (bool) {
|
|
99
|
+
_approve(msg.sender, spender, amount);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function transferFrom(address from, address to, uint256 amount) external override notBlacklisted(from) notBlacklisted(to) returns (bool) {
|
|
104
|
+
uint256 currentAllowance = _allowances[from][msg.sender];
|
|
105
|
+
require(currentAllowance >= amount, "QVTX: insufficient allowance");
|
|
106
|
+
unchecked {
|
|
107
|
+
_approve(from, msg.sender, currentAllowance - amount);
|
|
108
|
+
}
|
|
109
|
+
_transfer(from, to, amount);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Extended functions
|
|
114
|
+
function increaseAllowance(address spender, uint256 addedValue) external returns (bool) {
|
|
115
|
+
_approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
|
|
120
|
+
uint256 currentAllowance = _allowances[msg.sender][spender];
|
|
121
|
+
require(currentAllowance >= subtractedValue, "QVTX: decreased allowance below zero");
|
|
122
|
+
unchecked {
|
|
123
|
+
_approve(msg.sender, spender, currentAllowance - subtractedValue);
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Minting & Burning
|
|
129
|
+
function mint(address to, uint256 amount) external onlyMinter {
|
|
130
|
+
require(_totalSupply + amount <= MAX_SUPPLY, "QVTX: exceeds max supply");
|
|
131
|
+
_mint(to, amount);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function burn(uint256 amount) external {
|
|
135
|
+
_burn(msg.sender, amount);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function burnFrom(address account, uint256 amount) external {
|
|
139
|
+
uint256 currentAllowance = _allowances[account][msg.sender];
|
|
140
|
+
require(currentAllowance >= amount, "QVTX: burn amount exceeds allowance");
|
|
141
|
+
unchecked {
|
|
142
|
+
_approve(account, msg.sender, currentAllowance - amount);
|
|
143
|
+
}
|
|
144
|
+
_burn(account, amount);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Cross-chain functions
|
|
148
|
+
function bridgeMint(address to, uint256 amount, uint256 sourceChain) external onlyBridge {
|
|
149
|
+
require(_totalSupply + amount <= MAX_SUPPLY, "QVTX: exceeds max supply");
|
|
150
|
+
_mint(to, amount);
|
|
151
|
+
emit CrossChainMint(sourceChain, to, amount);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function bridgeBurn(address from, uint256 amount, uint256 targetChain) external onlyBridge {
|
|
155
|
+
_burn(from, amount);
|
|
156
|
+
emit CrossChainBurn(targetChain, from, amount);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Admin functions
|
|
160
|
+
function transferOwnership(address newOwner) external onlyOwner {
|
|
161
|
+
require(newOwner != address(0), "QVTX: new owner is zero address");
|
|
162
|
+
emit OwnershipTransferred(owner, newOwner);
|
|
163
|
+
owner = newOwner;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function addMinter(address minter) external onlyOwner {
|
|
167
|
+
minters[minter] = true;
|
|
168
|
+
emit MinterAdded(minter);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function removeMinter(address minter) external onlyOwner {
|
|
172
|
+
minters[minter] = false;
|
|
173
|
+
emit MinterRemoved(minter);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function setBridgeContract(address _bridge) external onlyOwner {
|
|
177
|
+
bridgeContract = _bridge;
|
|
178
|
+
emit BridgeContractUpdated(_bridge);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function setBlacklist(address account, bool status) external onlyOwner {
|
|
182
|
+
blacklisted[account] = status;
|
|
183
|
+
emit Blacklisted(account, status);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Internal functions
|
|
187
|
+
function _transfer(address from, address to, uint256 amount) internal {
|
|
188
|
+
require(from != address(0), "QVTX: transfer from zero address");
|
|
189
|
+
require(to != address(0), "QVTX: transfer to zero address");
|
|
190
|
+
require(_balances[from] >= amount, "QVTX: insufficient balance");
|
|
191
|
+
|
|
192
|
+
unchecked {
|
|
193
|
+
_balances[from] -= amount;
|
|
194
|
+
_balances[to] += amount;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
emit Transfer(from, to, amount);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function _mint(address account, uint256 amount) internal {
|
|
201
|
+
require(account != address(0), "QVTX: mint to zero address");
|
|
202
|
+
_totalSupply += amount;
|
|
203
|
+
unchecked {
|
|
204
|
+
_balances[account] += amount;
|
|
205
|
+
}
|
|
206
|
+
emit Transfer(address(0), account, amount);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function _burn(address account, uint256 amount) internal {
|
|
210
|
+
require(account != address(0), "QVTX: burn from zero address");
|
|
211
|
+
require(_balances[account] >= amount, "QVTX: burn exceeds balance");
|
|
212
|
+
|
|
213
|
+
unchecked {
|
|
214
|
+
_balances[account] -= amount;
|
|
215
|
+
_totalSupply -= amount;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
emit Transfer(account, address(0), amount);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function _approve(address tokenOwner, address spender, uint256 amount) internal {
|
|
222
|
+
require(tokenOwner != address(0), "QVTX: approve from zero address");
|
|
223
|
+
require(spender != address(0), "QVTX: approve to zero address");
|
|
224
|
+
_allowances[tokenOwner][spender] = amount;
|
|
225
|
+
emit Approval(tokenOwner, spender, amount);
|
|
226
|
+
}
|
|
227
|
+
}
|