Address Contract Partially Verified
Address
0xaFa52E3860b4371ab9d8F08E801E9EA1027C0CA2
Balance
0 ETH
Nonce
1
Code Size
6194 bytes
Creator
0x0bF38960...242c at tx 0x0c99e373...2f0620
Indexed Transactions
0
Contract Bytecode
6194 bytes
0x60806040908082526004918236101561001757600080fd5b600092833560e01c92836306fdde0314610f2957508263095ea7b314610e8d57826318160ddd14610e5057826323b872dd14610d365782632495a59914610cc75782633013ce2914610c58578263313ce56714610bfc5782633644e51514610bc157826340c10f1914610b7b57826361d027b314610b2857826370a0823114610ac65782637adbf97314610a155782637dc0d1d0146109c25782637ecebe00146109605782638da5cb5b1461090d57826395d89b41146107f2578263a1d50c3a14610777578263a9059cbb146106ca578263b7e1917c1461065b578263d505accf1461035c578263d6379b721461030a578263dd62ed3e146102915750508063f0f44260146101e25763f2fde38b1461012f57600080fd5b346101df5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df577fffffffffffffffffffffffff0000000000000000000000000000000000000000610187611116565b6006549073ffffffffffffffffffffffffffffffffffffffff906101ae8284163314611184565b169182911617600655337f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b80fd5b50346101df5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df5761021a611116565b73ffffffffffffffffffffffffffffffffffffffff9061023f82600654163314611184565b16807fffffffffffffffffffffffff000000000000000000000000000000000000000060085416176008557fcb7ef3e545f5cdb893f5c568ba710fe08f336375a2d9fd66e161033f8fc09ef38280a280f35b9091503461030657817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103065760209282916102cf611116565b6102d761113e565b9173ffffffffffffffffffffffffffffffffffffffff8092168452865283832091168252845220549051908152f35b8280fd5b9083346101df5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df575061035560209261034a611161565b9060243590356114ca565b9051908152f35b8382346106575760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261065757610395611116565b9061039e61113e565b91604435606435926084359260ff8416809403610653574285106105f6576103c4611225565b9573ffffffffffffffffffffffffffffffffffffffff8092169586895260209560058752848a209889549960018b01905585519285898501957f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c987528b89870152169a8b606086015288608086015260a085015260c084015260c0835260e0830167ffffffffffffffff94848210868311176105c957818852845190206101008501927f19010000000000000000000000000000000000000000000000000000000000008452610102860152610122850152604281526101608401948186109086111761059d57848752519020835261018082015260a4356101a082015260c4356101c0909101528780528490889060809060015afa1561059357865116968715158061058a575b1561052f5786977f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259596975283528087208688528352818188205551908152a380f35b8360649251917f08c379a0000000000000000000000000000000000000000000000000000000008352820152600e60248201527f494e56414c49445f5349474e45520000000000000000000000000000000000006044820152fd5b508488146104ec565b81513d88823e3d90fd5b60248c60418f7f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b5060248c60418f7f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b60648860208451917f08c379a0000000000000000000000000000000000000000000000000000000008352820152601760248201527f5045524d49545f444541444c494e455f455850495245440000000000000000006044820152fd5b8680fd5b5080fd5b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610657576020905173ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000003d103c547b43b5a76df7e652bd0bb61be0bd70d168152f35b83823461065757807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261065757602091610705611116565b8273ffffffffffffffffffffffffffffffffffffffff60243592338552600387528285206107348582546111e9565b90551692838152600386522081815401905582519081527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef843392a35160018152f35b9083346101df5760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df57506107b1611161565b60643542116107cb576103559060209360243590356114ca565b50517f94a5fd94000000000000000000000000000000000000000000000000000000008152fd5b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126106575780519082600180549161083483610fed565b808652928281169081156108c7575060011461086b575b50505061085d82610867940383611040565b51918291826110b0565b0390f35b94508085527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8286106108af5750505061085d826020610867958201019461084b565b80546020878701810191909152909501948101610892565b61086797508693506020925061085d9491507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001682840152151560051b8201019461084b565b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126106575760209073ffffffffffffffffffffffffffffffffffffffff600654169051908152f35b8382346106575760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610657578060209273ffffffffffffffffffffffffffffffffffffffff6109b2611116565b1681526005845220549051908152f35b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126106575760209073ffffffffffffffffffffffffffffffffffffffff600754169051908152f35b8390346106575760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610657573573ffffffffffffffffffffffffffffffffffffffff80821680920361030657610a7590600654163314611184565b807fffffffffffffffffffffffff000000000000000000000000000000000000000060075416176007557fd3b5d1e0ffaeff528910f3663f0adace7694ab8241d58e17a91351ced2e080318280a280f35b8382346106575760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610657578060209273ffffffffffffffffffffffffffffffffffffffff610b18611116565b1681526003845220549051908152f35b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126106575760209073ffffffffffffffffffffffffffffffffffffffff600854169051908152f35b838234610657577ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df57610bbe610bb5611116565b60243590611402565b80f35b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261065757602090610355611225565b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610657576020905160ff7f0000000000000000000000000000000000000000000000000000000000000012168152f35b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610657576020905173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168152f35b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610657576020905173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000ce246eea10988c495b4a90a905ee9237a0f91543168152f35b9083346101df5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df57610d6f611116565b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef610d9861113e565b946044358573ffffffffffffffffffffffffffffffffffffffff80951694858752602098848a958652838920338a52865283892054857fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610e2d575b50505086885260038552828820610e0e8582546111e9565b9055169586815260038452208181540190558551908152a35160018152f35b610e36916111e9565b90888a528652838920338a528652838920558a8085610df6565b83823461065757817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360112610657576020906002549051908152f35b9091503461030657817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261030657602092610ec9611116565b9183602435928392338252875273ffffffffffffffffffffffffffffffffffffffff8282209516948582528752205582519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925843392a35160018152f35b9250503461030657827ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261030657828054610f6681610fed565b808552916001918083169081156108c75750600114610f915750505061085d82610867940383611040565b80809650527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5635b828610610fd55750505061085d826020610867958201019461084b565b80546020878701810191909152909501948101610fb8565b90600182811c92168015611036575b602083101461100757565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b91607f1691610ffc565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761108157604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60208082528251818301819052939260005b858110611102575050507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8460006040809697860101520116010190565b8181018301518482016040015282016110c2565b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361113957565b600080fd5b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361113957565b6044359073ffffffffffffffffffffffffffffffffffffffff8216820361113957565b1561118b57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152fd5b919082039182116111f657565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000467f00000000000000000000000000000000000000000000000000000000000000010361127357507fb8af12c3f3b7324692eeb9ac1b004d2ef1ee9a9955f923575740c872a23b1d3c90565b6040518154829161128382610fed565b80825281602094858201946001908782821691826000146113c657505060011461136d575b506112b592500382611040565b51902091604051918201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f845260408301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a083015260a0825260c082019082821067ffffffffffffffff831117611340575060405251902090565b807f4e487b7100000000000000000000000000000000000000000000000000000000602492526041600452fd5b87805286915087907f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5635b8583106113ae5750506112b59350820101386112a8565b80548388018501528694508893909201918101611397565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001688526112b595151560051b85010192503891506112a89050565b73ffffffffffffffffffffffffffffffffffffffff90817f00000000000000000000000003d103c547b43b5a76df7e652bd0bb61be0bd70d1633036114a057821561149b576002548381018091116111f6576000927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9260209260025516938484526003825260408420818154019055604051908152a3565b505050565b60046040517f7bbe6d0a000000000000000000000000000000000000000000000000000000008152fd5b9291909280156117f45760003381526020600381526040908183206114f08582546111e9565b9055828052600381528183208481540190558282518581527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef833392a373ffffffffffffffffffffffffffffffffffffffff9460048287600754168551928380927f98d5fdca0000000000000000000000000000000000000000000000000000000082525afa9081156117ea5785916117b9575b50670de0b6b3a764000090807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0487118102158202156117b557860290808204910615150197881161178c578184606488600854168651907f23b872dd00000000000000000000000000000000000000000000000000000000825233600483015260248201528b6044820152827f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25af13d15601f3d1160018751141617161561172f57818660448693865197889384927fa9059cbb000000000000000000000000000000000000000000000000000000008452169a8b60048401528a60248401527f000000000000000000000000ce246eea10988c495b4a90a905ee9237a0f91543165af1801561172357908892916116e9575b507fb1c971764663d561c0ec2baf395a55f33f0a79fabb35bbad580247ba2959523d935082519485528401523392a3565b915091928281813d831161171c575b6117028183611040565b810103126106575751801515036101df57829187916116b8565b503d6116f8565b508251903d90823e3d90fd5b5060649151907f08c379a00000000000000000000000000000000000000000000000000000000082526004820152601460248201527f5452414e534645525f46524f4d5f4641494c45440000000000000000000000006044820152fd5b600483517fd193bd20000000000000000000000000000000000000000000000000000000008152fd5b8580fd5b90508281813d83116117e3575b6117d08183611040565b810103126117df575138611584565b8480fd5b503d6117c6565b84513d87823e3d90fd5b50600092505056fea264697066735822122056a0b6a2dd9a59c28ae166956b5ab208cfe3ea999e5c42dc5a0c78a37654aafe64736f6c63430008130033
Verified Source Code Partial Match
Compiler: v0.8.19+commit.7dd6d404
EVM: paris
Optimization: Yes (1000000 runs)
OptionsToken.sol 198 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.13;
import {Owned} from "solmate/auth/Owned.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol";
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";
import {IOracle} from "./interfaces/IOracle.sol";
import {IERC20Mintable} from "./interfaces/IERC20Mintable.sol";
/// @title Options Token
/// @author zefram.eth
/// @author ruhum
/// @notice Options token representing the right to purchase the underlying token
/// at an oracle-specified rate. Similar to call options but with a variable strike
/// price that's always at a certain discount to the market price.
/// @dev Assumes the underlying token and the payment token both use 18 decimals.
/// @dev Popcorn fork: instead of minting new underlying tokens, we transfer them
/// from this contract. POP is already fully minted.
contract OptionsToken is ERC20, Owned, IERC20Mintable {
/// -----------------------------------------------------------------------
/// Library usage
/// -----------------------------------------------------------------------
using SafeTransferLib for ERC20;
using FixedPointMathLib for uint256;
/// -----------------------------------------------------------------------
/// Errors
/// -----------------------------------------------------------------------
error OptionsToken__PastDeadline();
error OptionsToken__NotTokenAdmin();
error OptionsToken__SlippageTooHigh();
/// -----------------------------------------------------------------------
/// Events
/// -----------------------------------------------------------------------
event Exercise(address indexed sender, address indexed recipient, uint256 amount, uint256 paymentAmount);
event SetOracle(IOracle indexed newOracle);
event SetTreasury(address indexed newTreasury);
/// -----------------------------------------------------------------------
/// Immutable parameters
/// -----------------------------------------------------------------------
/// @notice The contract that has the right to mint options tokens
address public immutable tokenAdmin;
/// @notice The token paid by the options token holder during redemption
ERC20 public immutable paymentToken;
/// @notice The underlying token purchased during redemption
ERC20 public immutable underlyingToken;
/// -----------------------------------------------------------------------
/// Storage variables
/// -----------------------------------------------------------------------
/// @notice The oracle contract that provides the current price to purchase
/// the underlying token while exercising options (the strike price)
IOracle public oracle;
/// @notice The treasury address which receives tokens paid during redemption
address public treasury;
/// -----------------------------------------------------------------------
/// Constructor
/// -----------------------------------------------------------------------
constructor(
string memory name_,
string memory symbol_,
address owner_,
address tokenAdmin_,
ERC20 paymentToken_,
ERC20 underlyingToken_,
IOracle oracle_,
address treasury_
) ERC20(name_, symbol_, 18) Owned(owner_) {
tokenAdmin = tokenAdmin_;
paymentToken = paymentToken_;
underlyingToken = underlyingToken_;
oracle = oracle_;
treasury = treasury_;
emit SetOracle(oracle_);
emit SetTreasury(treasury_);
}
/// -----------------------------------------------------------------------
/// External functions
/// -----------------------------------------------------------------------
/// @notice Called by the token admin to mint options tokens
/// @param to The address that will receive the minted options tokens
/// @param amount The amount of options tokens that will be minted
function mint(address to, uint256 amount) external virtual override {
/// -----------------------------------------------------------------------
/// Verification
/// -----------------------------------------------------------------------
if (msg.sender != tokenAdmin) revert OptionsToken__NotTokenAdmin();
/// -----------------------------------------------------------------------
/// State updates
/// -----------------------------------------------------------------------
// skip if amount is zero
if (amount == 0) return;
// mint options tokens
_mint(to, amount);
}
/// @notice Exercises options tokens to purchase the underlying tokens.
/// @dev The options tokens are not burnt but sent to address(0) to avoid messing up the
/// inflation schedule.
/// The oracle may revert if it cannot give a secure result.
/// @param amount The amount of options tokens to exercise
/// @param maxPaymentAmount The maximum acceptable amount to pay. Used for slippage protection.
/// @param recipient The recipient of the purchased underlying tokens
/// @return paymentAmount The amount paid to the treasury to purchase the underlying tokens
function exercise(uint256 amount, uint256 maxPaymentAmount, address recipient)
external
virtual
returns (uint256 paymentAmount)
{
return _exercise(amount, maxPaymentAmount, recipient);
}
/// @notice Exercises options tokens to purchase the underlying tokens.
/// @dev The options tokens are not burnt but sent to address(0) to avoid messing up the
/// inflation schedule.
/// The oracle may revert if it cannot give a secure result.
/// @param amount The amount of options tokens to exercise
/// @param maxPaymentAmount The maximum acceptable amount to pay. Used for slippage protection.
/// @param recipient The recipient of the purchased underlying tokens
/// @param deadline The Unix timestamp (in seconds) after which the call will revert
/// @return paymentAmount The amount paid to the treasury to purchase the underlying tokens
function exercise(uint256 amount, uint256 maxPaymentAmount, address recipient, uint256 deadline)
external
virtual
returns (uint256 paymentAmount)
{
if (block.timestamp > deadline) revert OptionsToken__PastDeadline();
return _exercise(amount, maxPaymentAmount, recipient);
}
/// -----------------------------------------------------------------------
/// Owner functions
/// -----------------------------------------------------------------------
/// @notice Sets the oracle contract. Only callable by the owner.
/// @param oracle_ The new oracle contract
function setOracle(IOracle oracle_) external onlyOwner {
oracle = oracle_;
emit SetOracle(oracle_);
}
/// @notice Sets the treasury address. Only callable by the owner.
/// @param treasury_ The new treasury address
function setTreasury(address treasury_) external onlyOwner {
treasury = treasury_;
emit SetTreasury(treasury_);
}
/// -----------------------------------------------------------------------
/// Internal functions
/// -----------------------------------------------------------------------
function _exercise(uint256 amount, uint256 maxPaymentAmount, address recipient)
internal
virtual
returns (uint256 paymentAmount)
{
// skip if amount is zero
if (amount == 0) return 0;
// transfer options tokens from msg.sender to address(0)
// we transfer instead of burn because TokenAdmin cares about totalSupply
// which we don't want to change in order to follow the emission schedule
transfer(address(0), amount);
// transfer payment tokens from msg.sender to the treasury
paymentAmount = amount.mulWadUp(oracle.getPrice());
if (paymentAmount > maxPaymentAmount) revert OptionsToken__SlippageTooHigh();
paymentToken.safeTransferFrom(msg.sender, treasury, paymentAmount);
// transfer underlying tokens to recipient.
// Will revert if this contract doesn't have enough tokens
underlyingToken.transfer(recipient, amount);
emit Exercise(msg.sender, recipient, amount, paymentAmount);
}
}
IOracle.sol 14 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/// @title Interface for an oracle of the options token's strike price
/// @author zefram.eth
/// @notice An oracle of the options token's strike price
interface IOracle {
/// @notice Computes the current strike price of the option
/// @return price The strike price in terms of the payment token, scaled by 18 decimals.
/// For example, if the payment token is $2 and the strike price is $4, the return value
/// would be 2e18.
function getPrice() external view returns (uint256 price);
}
Owned.sol 44 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event OwnershipTransferred(address indexed user, address indexed newOwner);
/*//////////////////////////////////////////////////////////////
OWNERSHIP STORAGE
//////////////////////////////////////////////////////////////*/
address public owner;
modifier onlyOwner() virtual {
require(msg.sender == owner, "UNAUTHORIZED");
_;
}
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(address _owner) {
owner = _owner;
emit OwnershipTransferred(address(0), _owner);
}
/*//////////////////////////////////////////////////////////////
OWNERSHIP LOGIC
//////////////////////////////////////////////////////////////*/
function transferOwnership(address newOwner) public virtual onlyOwner {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
ERC20.sol 206 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
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;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
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]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
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 because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
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)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
IERC20Mintable.sol 7 lines
// SPDX-License-Identifier: AGPL-3.0
pragma solidity >=0.7.0 <0.9.0;
interface IERC20Mintable {
function mint(address to, uint256 amount) external;
}
SafeTransferLib.sol 128 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument.
mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}
FixedPointMathLib.sol 255 lines
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
library FixedPointMathLib {
/*//////////////////////////////////////////////////////////////
SIMPLIFIED FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
uint256 internal constant MAX_UINT256 = 2**256 - 1;
uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s.
function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
}
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up.
}
function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down.
}
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up.
}
/*//////////////////////////////////////////////////////////////
LOW LEVEL FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
function mulDivDown(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) {
revert(0, 0)
}
// Divide x * y by the denominator.
z := div(mul(x, y), denominator)
}
}
function mulDivUp(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) {
revert(0, 0)
}
// If x * y modulo the denominator is strictly greater than 0,
// 1 is added to round up the division of x * y by the denominator.
z := add(gt(mod(mul(x, y), denominator), 0), div(mul(x, y), denominator))
}
}
function rpow(
uint256 x,
uint256 n,
uint256 scalar
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
switch x
case 0 {
switch n
case 0 {
// 0 ** 0 = 1
z := scalar
}
default {
// 0 ** n = 0
z := 0
}
}
default {
switch mod(n, 2)
case 0 {
// If n is even, store scalar in z for now.
z := scalar
}
default {
// If n is odd, store x in z for now.
z := x
}
// Shifting right by 1 is like dividing by 2.
let half := shr(1, scalar)
for {
// Shift n right by 1 before looping to halve it.
n := shr(1, n)
} n {
// Shift n right by 1 each iteration to halve it.
n := shr(1, n)
} {
// Revert immediately if x ** 2 would overflow.
// Equivalent to iszero(eq(div(xx, x), x)) here.
if shr(128, x) {
revert(0, 0)
}
// Store x squared.
let xx := mul(x, x)
// Round to the nearest number.
let xxRound := add(xx, half)
// Revert if xx + half overflowed.
if lt(xxRound, xx) {
revert(0, 0)
}
// Set x to scaled xxRound.
x := div(xxRound, scalar)
// If n is even:
if mod(n, 2) {
// Compute z * x.
let zx := mul(z, x)
// If z * x overflowed:
if iszero(eq(div(zx, x), z)) {
// Revert if x is non-zero.
if iszero(iszero(x)) {
revert(0, 0)
}
}
// Round to the nearest number.
let zxRound := add(zx, half)
// Revert if zx + half overflowed.
if lt(zxRound, zx) {
revert(0, 0)
}
// Return properly scaled zxRound.
z := div(zxRound, scalar)
}
}
}
}
}
/*//////////////////////////////////////////////////////////////
GENERAL NUMBER UTILITIES
//////////////////////////////////////////////////////////////*/
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let y := x // We start y at x, which will help us make our initial estimate.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// We check y >= 2^(k + 8) but shift right by k bits
// each branch to ensure that if x >= 256, then y >= 256.
if iszero(lt(y, 0x10000000000000000000000000000000000)) {
y := shr(128, y)
z := shl(64, z)
}
if iszero(lt(y, 0x1000000000000000000)) {
y := shr(64, y)
z := shl(32, z)
}
if iszero(lt(y, 0x10000000000)) {
y := shr(32, y)
z := shl(16, z)
}
if iszero(lt(y, 0x1000000)) {
y := shr(16, y)
z := shl(8, z)
}
// Goal was to get z*z*y within a small factor of x. More iterations could
// get y in a tighter range. Currently, we will have y in [256, 256*2^16).
// We ensured y >= 256 so that the relative difference between y and y+1 is small.
// That's not possible if x < 256 but we can just verify those cases exhaustively.
// Now, z*z*y <= x < z*z*(y+1), and y <= 2^(16+8), and either y >= 256, or x < 256.
// Correctness can be checked exhaustively for x < 256, so we assume y >= 256.
// Then z*sqrt(y) is within sqrt(257)/sqrt(256) of sqrt(x), or about 20bps.
// For s in the range [1/256, 256], the estimate f(s) = (181/1024) * (s+1) is in the range
// (1/2.84 * sqrt(s), 2.84 * sqrt(s)), with largest error when s = 1 and when s = 256 or 1/256.
// Since y is in [256, 256*2^16), let a = y/65536, so that a is in [1/256, 256). Then we can estimate
// sqrt(y) using sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2^18.
// There is no overflow risk here since y < 2^136 after the first branch above.
z := shr(18, mul(z, add(y, 65536))) // A mul() is saved from starting z at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If x+1 is a perfect square, the Babylonian method cycles between
// floor(sqrt(x)) and ceil(sqrt(x)). This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
// Since the ceil is rare, we save gas on the assignment and repeat division in the rare case.
// If you don't care whether the floor or ceil square root is returned, you can remove this statement.
z := sub(z, lt(div(x, z), z))
}
}
function unsafeMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Mod x by y. Note this will return
// 0 instead of reverting if y is zero.
z := mod(x, y)
}
}
function unsafeDiv(uint256 x, uint256 y) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
// Divide x by y. Note this will return
// 0 instead of reverting if y is zero.
r := div(x, y)
}
}
function unsafeDivUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Add 1 to x * y if x % y > 0. Note this will
// return 0 instead of reverting if y is zero.
z := add(gt(mod(x, y), 0), div(x, y))
}
}
}
Read Contract
DOMAIN_SEPARATOR 0x3644e515 → bytes32
allowance 0xdd62ed3e → uint256
balanceOf 0x70a08231 → uint256
decimals 0x313ce567 → uint8
name 0x06fdde03 → string
nonces 0x7ecebe00 → uint256
oracle 0x7dc0d1d0 → address
owner 0x8da5cb5b → address
paymentToken 0x3013ce29 → address
symbol 0x95d89b41 → string
tokenAdmin 0xb7e1917c → address
totalSupply 0x18160ddd → uint256
treasury 0x61d027b3 → address
underlyingToken 0x2495a599 → address
Write Contract 10 functions
These functions modify contract state and require a wallet transaction to execute.
approve 0x095ea7b3
address spender
uint256 amount
returns: bool
exercise 0xa1d50c3a
uint256 amount
uint256 maxPaymentAmount
address recipient
uint256 deadline
returns: uint256
exercise 0xd6379b72
uint256 amount
uint256 maxPaymentAmount
address recipient
returns: uint256
mint 0x40c10f19
address to
uint256 amount
permit 0xd505accf
address owner
address spender
uint256 value
uint256 deadline
uint8 v
bytes32 r
bytes32 s
setOracle 0x7adbf973
address oracle_
setTreasury 0xf0f44260
address treasury_
transfer 0xa9059cbb
address to
uint256 amount
returns: bool
transferFrom 0x23b872dd
address from
address to
uint256 amount
returns: bool
transferOwnership 0xf2fde38b
address newOwner
Recent Transactions
No transactions found for this address