// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
contract AuthAdmin {
string private parentContractName;
address public ArchAdmin;
mapping (address => uint256) public admins;
uint256 public live;
event Rely(address indexed usr);
event Deny(address indexed usr);
event Cage(uint256 live);
modifier auth {
require(admins[msg.sender] == 1, string.concat(parentContractName, "/not-authorized"));
_;
}
modifier alive {
require(live == 1, string.concat(parentContractName, "/not-live"));
_;
}
constructor(string memory contractName, address deployer) {
parentContractName = contractName;
admins[deployer] = 1;
ArchAdmin = deployer;
emit Rely(deployer);
}
function setArchAdmin(address newArch) external auth {
require(ArchAdmin == msg.sender && newArch != address(0), string.concat(parentContractName, "/Must be ArchAdmin"));
ArchAdmin = newArch;
admins[ArchAdmin] = 1;
}
function rely(address usr) external auth {
admins[usr] = 1;
emit Rely(usr);
}
function deny(address usr) external auth {
require(usr != ArchAdmin, string.concat(parentContractName, "/ArchAdmin cannot lose admin - update ArchAdmin to another address"));
admins[usr] = 0;
emit Deny(usr);
}
function cage(uint256 _live) external auth {
live = _live;
emit Cage(_live);
}
}
// SPDX-License-Identifier: AGPL-3.0-or-later
/// pink.sol -- pink evm token
pragma solidity 0.8.23;
import "./AuthAdmin.sol";
contract Pink is AuthAdmin("Pink", msg.sender) {
// --- ERC20 Data ---
string public constant name = "Pink";
string public constant symbol = "PINK";
string public constant version = "1";
uint8 public constant decimals = 10;
uint256 public totalSupply;
uint256 public transferBlockWait; //Amount of blocks to wait before user can transfer pink after minting cross-chain
uint256 public lockupTriggerAmt; //pink amount where lockup will kick in after cross-chain transfer
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
mapping (address => uint256) public nonces;
mapping (address => uint256) public transferBlockRelease; //Block number after which user is able to transfer pink
// --- Events ---
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
event TransferBlockWait(uint256 blockWait);
event TransferBlockUpdate(address indexed user, uint256 blockNumer);
event LockupTriggerAmount(uint256 amount);
// --- EIP712 niceties ---
uint256 public immutable deploymentChainId;
bytes32 private immutable _DOMAIN_SEPARATOR;
bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
constructor() {
live = 1;
deploymentChainId = block.chainid;
_DOMAIN_SEPARATOR = _calculateDomainSeparator(block.chainid);
}
function _calculateDomainSeparator(uint256 chainId) private view returns (bytes32) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes(version)),
chainId,
address(this)
)
);
}
function DOMAIN_SEPARATOR() external view returns (bytes32) {
return block.chainid == deploymentChainId ? _DOMAIN_SEPARATOR : _calculateDomainSeparator(block.chainid);
}
// --- Administration ---
function setTransferBlockWait(uint256 num) external auth {
transferBlockWait = num;
emit TransferBlockWait(transferBlockWait);
}
function setTransferBlockRelease(address user, uint256 blockNumber) external auth {
transferBlockRelease[user] = blockNumber;
emit TransferBlockUpdate(user, blockNumber);
}
function setLockupTriggerAmount(uint256 amount) external auth {
lockupTriggerAmt = amount;
emit LockupTriggerAmount(amount);
}
// --- ERC20 Mutations ---
function transfer(address to, uint256 value) external alive returns (bool) {
require(to != address(0) && to != address(this), "pink/invalid-address");
require(block.number > transferBlockRelease[msg.sender], "pink/transfer too soon after cross-chain mint");
uint256 balance = balanceOf[msg.sender];
require(balance >= value, "pink/insufficient-balance");
unchecked {
balanceOf[msg.sender] = balance - value;
balanceOf[to] += value;
}
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external alive returns (bool) {
require(to != address(0) && to != address(this), "pink/invalid-address");
require(block.number > transferBlockRelease[from], "pink/transfer too soon after cross-chain mint");
uint256 balance = balanceOf[from];
require(balance >= value, "pink/insufficient-balance");
if (from != msg.sender) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
require(allowed >= value, "pink/insufficient-allowance");
unchecked {
allowance[from][msg.sender] = allowed - value;
}
}
}
unchecked {
balanceOf[from] = balance - value;
balanceOf[to] += value;
}
emit Transfer(from, 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 increaseAllowance(address spender, uint256 addedValue) external returns (bool) {
uint256 newValue = allowance[msg.sender][spender] + addedValue;
allowance[msg.sender][spender] = newValue;
emit Approval(msg.sender, spender, newValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) external returns (bool) {
uint256 allowed = allowance[msg.sender][spender];
require(allowed >= subtractedValue, "pink/insufficient-allowance");
unchecked{
allowed = allowed - subtractedValue;
}
allowance[msg.sender][spender] = allowed;
emit Approval(msg.sender, spender, allowed);
return true;
}
// --- Mint/Burn ---
function mint(address to, uint256 value) external auth {
_mint(to, value);
}
function mintAndDelay(address to, uint256 value) external auth {
if(value > lockupTriggerAmt){
transferBlockRelease[to] = block.number + transferBlockWait;
}
_mint(to, value);
}
function _mint(address to, uint256 value) internal alive {
require(to != address(0) && to != address(this), "pink/invalid-address");
unchecked {
balanceOf[to] = balanceOf[to] + value; // note: we don't need an overflow check here b/c balanceOf[to] <= totalSupply and there is an overflow check below
}
totalSupply = totalSupply + value;
emit Transfer(address(0), to, value);
}
function burn(address from, uint256 value) external alive {
uint256 balance = balanceOf[from];
require(balance >= value, "pink/insufficient-balance");
require(block.number > transferBlockRelease[from] || admins[msg.sender] == 1, "pink/burn too soon after cross-chain mint");
if (from != msg.sender && admins[msg.sender] != 1) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
require(allowed >= value, "pink/insufficient-allowance");
unchecked {
allowance[from][msg.sender] = allowed - value;
}
}
}
unchecked {
balanceOf[from] = balance - value; // note: we don't need overflow checks b/c require(balance >= value) and balance <= totalSupply
totalSupply = totalSupply - value;
}
emit Transfer(from, address(0), value);
}
// --- Approve by signature ---
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
require(block.timestamp <= deadline, "pink/permit-expired");
uint256 nonce;
unchecked { nonce = nonces[owner]++; }
bytes32 digest =
keccak256(abi.encodePacked(
"\x19\x01",
block.chainid == deploymentChainId ? _DOMAIN_SEPARATOR : _calculateDomainSeparator(block.chainid),
keccak256(abi.encode(
PERMIT_TYPEHASH,
owner,
spender,
value,
nonce,
deadline
))
));
require(owner != address(0) && owner == ecrecover(digest, v, r, s), "pink/invalid-permit");
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
}
{
"compilationTarget": {
"contracts/Pink.sol": "Pink"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 20
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"live","type":"uint256"}],"name":"Cage","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"usr","type":"address"}],"name":"Deny","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LockupTriggerAmount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"usr","type":"address"}],"name":"Rely","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"blockNumer","type":"uint256"}],"name":"TransferBlockUpdate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"blockWait","type":"uint256"}],"name":"TransferBlockWait","type":"event"},{"inputs":[],"name":"ArchAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"admins","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_live","type":"uint256"}],"name":"cage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"deny","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deploymentChainId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"live","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockupTriggerAmt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"mintAndDelay","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"rely","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newArch","type":"address"}],"name":"setArchAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"setLockupTriggerAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"blockNumber","type":"uint256"}],"name":"setTransferBlockRelease","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"num","type":"uint256"}],"name":"setTransferBlockWait","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"transferBlockRelease","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"transferBlockWait","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]