-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
blockchain_integration/pi_network/contracts/ERC20Token.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/security/Pausable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol"; | ||
|
||
contract ERC20Token is ERC20, Ownable, Pausable, ERC20Burnable, ERC20Pausable, ERC20Snapshot, ERC20Votes { | ||
// Events | ||
event Minted(address indexed to, uint256 amount); | ||
event Burned(address indexed from, uint256 amount); | ||
|
||
constructor(uint256 initialSupply) ERC20("PiToken", "PIT") { | ||
_mint(msg.sender, initialSupply); | ||
} | ||
|
||
// Mint new tokens | ||
function mint(address to, uint256 amount) public onlyOwner { | ||
_mint(to, amount); | ||
emit Minted(to, amount); | ||
} | ||
|
||
// Override the _beforeTokenTransfer hook to implement pausable functionality | ||
function _beforeTokenTransfer(address from, address to, uint256 amount) internal whenNotPaused override(ERC20, ERC20Pausable) { | ||
super._beforeTokenTransfer(from, to, amount); | ||
} | ||
|
||
// Pause the contract | ||
function pause() public onlyOwner { | ||
_pause(); | ||
} | ||
|
||
// Unpause the contract | ||
function unpause() public onlyOwner { | ||
_unpause(); | ||
} | ||
|
||
// Snapshot the current state of the token | ||
function snapshot() public onlyOwner returns (uint256) { | ||
return _snapshot(); | ||
} | ||
|
||
// Override required by Solidity for ERC20Votes | ||
function _afterTokenTransfer(address from, address to, uint256 amount) internal override(ERC20, ERC20Votes) { | ||
super._afterTokenTransfer(from, to, amount); | ||
} | ||
|
||
// Burn tokens | ||
function burn(uint256 amount) public override { | ||
super.burn(amount); | ||
emit Burned(msg.sender, amount); | ||
} | ||
|
||
// Burn tokens from a specific address | ||
function burnFrom(address account, uint256 amount) public override { | ||
super.burnFrom(account, amount); | ||
emit Burned(account, amount); | ||
} | ||
} |