-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathMCV2_Token.sol
More file actions
58 lines (49 loc) · 1.99 KB
/
Copy pathMCV2_Token.sol
File metadata and controls
58 lines (49 loc) · 1.99 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
// SPDX-License-Identifier: BUSL-1.1
pragma solidity =0.8.20;
import {ERC20Initializable} from "./lib/ERC20Initializable.sol";
/**
* @title MCV2_Token
* @dev A token contract that implements a bonding curve and allows minting and burning of tokens.
*/
contract MCV2_Token is ERC20Initializable {
error MCV2_Token__AlreadyInitialized();
error MCV2_Token__PermissionDenied();
bool private _initialized; // false by default
address public bond; // Bonding curve contract should have its minting permission
/**
* @dev Initializes the token contract with the provided name and symbol.
* @param name_ The name of the token.
* @param symbol_ The symbol of the token.
*/
function init(string calldata name_, string calldata symbol_) external {
if(_initialized) revert MCV2_Token__AlreadyInitialized();
_initialized = true;
_name = name_;
_symbol = symbol_;
bond = _msgSender();
}
modifier onlyBond() {
if (bond != _msgSender()) revert MCV2_Token__PermissionDenied();
_;
}
/**
* @dev Mint tokens by the bonding curve contract.
* Minting should also provide liquidity to the bonding curve contract.
* @param to The address to which the minted tokens will be transferred.
* @param amount The amount of tokens to mint.
*/
function mintByBond(address to, uint256 amount) external onlyBond {
_mint(to, amount);
}
/**
* @dev Burns tokens by the bonding curve contract.
* Burning tokens affects the bonding curve.
* Users can simply send tokens to the token contract address for the same burning effect without changing the totalSupply.
* @param account The address from which the tokens will be burned.
* @param amount The amount of tokens to burn.
*/
function burnByBond(address account, uint256 amount) external onlyBond {
_spendAllowance(account, bond, amount); // `msg.sender` is always `bond`
_burn(account, amount);
}
}