This contract's source code is verified! Compiler
0.8.13+commit.abaa5c0e
File 1 of 4: ERC20.sol
pragma solidity >=0.8.0;
abstract contract ERC20 {
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
string public name;
string public symbol;
uint8 public immutable decimals;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
File 2 of 4: ICNV.sol
pragma solidity 0.8.13;
interface ICNV {
function mint(address account, uint256 amount) external;
function totalSupply() external view returns (uint256);
}
File 3 of 4: Owned.sol
pragma solidity >=0.8.0;
abstract contract Owned {
event OwnerUpdated(address indexed user, address indexed newOwner);
address public owner;
modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");
_;
}
constructor(address _owner) {
owner = _owner;
emit OwnerUpdated(address(0), _owner);
}
function setOwner(address newOwner) public virtual onlyOwner {
owner = newOwner;
emit OwnerUpdated(msg.sender, newOwner);
}
}
File 4 of 4: pCNV.sol
pragma solidity ^0.8.13;
import {ERC20} from "solmate/tokens/ERC20.sol";
import {Owned} from "solmate/auth/Owned.sol";
import {ICNV} from "./interface/ICNV.sol";
contract pCNV is ERC20, Owned {
event Paused(bool indexed _paused);
event Mint(uint256 indexed _amount);
event Redemption(
address indexed _from,
address indexed _who,
uint256 indexed _amount
);
uint256 public constant VESTING_TIME_START = 1656633600;
uint256 public constant LINEAR_VESTING_TIME_START = 1680307200;
uint256 public constant VESTING_TIME_END = 1711929600;
uint256 public constant LINEAR_VESTING_TIME_LENGTH = 31622400;
uint256 public constant VESTING_AMOUNT_START = 5e17;
uint256 public constant VESTING_AMOUNT_LENGTH = 5e17;
uint256 public constant MAX_SUPPLY = 333e23;
address public immutable CNV;
bool public paused;
uint256 public totalMinted;
mapping(address => uint256) public redeemed;
constructor(address _CNV)
ERC20("Concave pCNV", "pCNV", 18)
Owned(0x226e7AF139a0F34c6771DeB252F9988876ac1Ced)
{
CNV = _CNV;
}
function setPause(bool _paused) external onlyOwner {
paused = _paused;
emit Paused(paused);
}
function mint(address to, uint256 amount) external onlyOwner {
require(to != address(0), "ZERO_ADDRESS");
require(totalMinted + amount <= MAX_SUPPLY, "MAX_SUPPLY");
unchecked {
totalMinted += amount;
}
_mint(to, amount);
emit Mint(amount);
}
function transfer(address to, uint256 amount)
public
virtual
override
returns (bool)
{
uint256 amountRedeemed = (redeemed[msg.sender] * amount) /
balanceOf[msg.sender];
redeemed[msg.sender] -= amountRedeemed;
balanceOf[msg.sender] -= amount;
unchecked {
redeemed[to] += amountRedeemed;
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max)
allowance[from][msg.sender] = allowed - amount;
uint256 amountRedeemed = (redeemed[from] * amount) / balanceOf[from];
redeemed[from] -= amountRedeemed;
balanceOf[from] -= amount;
unchecked {
redeemed[to] += amountRedeemed;
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
function redeem(
uint256 _amount,
address _who,
address _to,
bool _max
) external returns (uint256 amountOut) {
require(!paused, "PAUSED");
uint256 pCNVBalance = balanceOf[_who];
require(pCNVBalance > 0, "NONE_LEFT");
uint256 currentTime = block.timestamp;
require(currentTime >= VESTING_TIME_START, "!VESTING");
uint256 amountRedeemed = redeemed[_who];
uint256 amountVested;
if (currentTime >= VESTING_TIME_END) {
amountVested = pCNVBalance + amountRedeemed;
} else {
uint256 vpct = vestedPercent(currentTime);
amountVested = ((pCNVBalance + amountRedeemed) * vpct) / 1e18;
}
require(amountVested > amountRedeemed, "NONE_LEFT");
uint256 amountRedeemable = amountVested - amountRedeemed;
if (!_max) {
require(amountRedeemable >= _amount, "EXCEEDS");
amountRedeemable = _amount;
}
if (_who != msg.sender) {
uint256 allowed = allowance[_who][msg.sender];
require(allowed >= amountRedeemable, "!ALLOWED");
if (allowed != type(uint256).max)
allowance[_who][msg.sender] = allowed - amountRedeemable;
}
redeemed[_who] = amountRedeemed + amountRedeemable;
_burn(_who, amountRedeemable);
amountOut =
(ICNV(CNV).totalSupply() * amountRedeemable) /
(10 * MAX_SUPPLY);
ICNV(CNV).mint(_to, amountOut);
emit Redemption(msg.sender, _who, amountOut);
}
function redeemable(address _who) external view returns (uint256) {
uint256 pCNVBalance = balanceOf[_who];
if (pCNVBalance == 0) return 0;
uint256 currentTime = block.timestamp;
if (currentTime < VESTING_TIME_START) return 0;
uint256 amountRedeemed = redeemed[_who];
uint256 amountVested;
if (currentTime >= VESTING_TIME_END) {
amountVested = pCNVBalance + amountRedeemed;
} else {
uint256 vpct = vestedPercent(currentTime);
amountVested = ((pCNVBalance + amountRedeemed) * vpct) / 1e18;
}
if (amountVested <= amountRedeemed) return 0;
return amountVested - amountRedeemed;
}
function vestedPercent(uint256 _time) public pure returns (uint256) {
if (_time < VESTING_TIME_START) {
return 0;
}
if (_time <= LINEAR_VESTING_TIME_START) {
return VESTING_AMOUNT_START;
}
if (_time >= VESTING_TIME_END) {
return 1e18;
}
uint256 pctOf = _percentOf(
LINEAR_VESTING_TIME_START,
_time,
LINEAR_VESTING_TIME_LENGTH
);
return
_linearMapping(VESTING_AMOUNT_START, pctOf, VESTING_AMOUNT_LENGTH);
}
function _percentOf(
uint256 _start,
uint256 _point,
uint256 _length
) internal pure returns (uint256 elapsedPct) {
uint256 elapsed = _point - _start;
elapsedPct = (elapsed * 1e18) / _length;
}
function _linearMapping(
uint256 _start,
uint256 _pct,
uint256 _length
) internal pure returns (uint256 point) {
uint256 elapsed = (_length * _pct) / 1e18;
point = _start + elapsed;
}
}
{
"compilationTarget": {
"src/pCNV.sol": "pCNV"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":ds-test/=lib/ds-test/src/",
":forge-std/=lib/forge-std/src/",
":solmate/=lib/solmate/src/",
":src/=src/"
]
}
[{"inputs":[{"internalType":"address","name":"_CNV","type":"address"}],"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":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"_paused","type":"bool"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_who","type":"address"},{"indexed":true,"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"Redemption","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":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"CNV","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":"LINEAR_VESTING_TIME_LENGTH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LINEAR_VESTING_TIME_START","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VESTING_AMOUNT_LENGTH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VESTING_AMOUNT_START","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VESTING_TIME_END","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"VESTING_TIME_START","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":"amount","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":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","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":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_who","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"bool","name":"_max","type":"bool"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_who","type":"address"}],"name":"redeemable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"redeemed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalMinted","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"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":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_time","type":"uint256"}],"name":"vestedPercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]