Address Contract Verified
Address
0x627fee87d0D9D2c55098A06ac805Db8F98B158Aa
Balance
0 ETH
Nonce
1
Code Size
6261 bytes
Creator
0x68272d4B...7Ff7 at tx 0x48546401...f8e51b
Indexed Transactions
0
Contract Bytecode
6261 bytes
0x608060408181526004918236101561001657600080fd5b600092833560e01c91826306fdde0314610f2d57508163095ea7b314610e9257816318160ddd14610e5557816323b872dd14610d3b5781632495a59914610ccc5781633013ce2914610c5d578163313ce56714610c015781633644e51514610bc657816340c10f1914610b7f57816361d027b314610b2c57816370a0823114610aca5781637adbf97314610a135781637dc0d1d0146109c05781637ecebe001461095e5781638da5cb5b1461090b57816395d89b41146107f0578163a1d50c3a14610775578163a9059cbb146106c8578163b7e1917c14610659578163d505accf14610361578163d6379b721461030c578163dd62ed3e1461029457508063f0f44260146101e35763f2fde38b1461012d57600080fd5b346101df5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df577fffffffffffffffffffffffff00000000000000000000000000000000000000009061018661111a565b6006549073ffffffffffffffffffffffffffffffffffffffff906101ad8284163314611188565b1692839116176006555190337f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08484a3f35b5080fd5b50346101df5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df5761021b61111a565b73ffffffffffffffffffffffffffffffffffffffff9061024082600654163314611188565b1690817fffffffffffffffffffffffff0000000000000000000000000000000000000000600854161760085551907fcb7ef3e545f5cdb893f5c568ba710fe08f336375a2d9fd66e161033f8fc09ef38383a2f35b90503461030857817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103085760209282916102d161111a565b6102d9611142565b9173ffffffffffffffffffffffffffffffffffffffff8092168452865283832091168252845220549051908152f35b8280fd5b82843461035e5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261035e575061035760209261034c611165565b9060243590356114ce565b9051908152f35b80fd5b9050346103085760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126103085761039a61111a565b6103a2611142565b604435606435936084359360ff8516809503610655574286106105f857866103c8611229565b9473ffffffffffffffffffffffffffffffffffffffff80931696878b5260209660058852838c20998a549a60018c019055858551948b8b8701977f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98952870152169a8b606086015288608086015260a085015260c084015260c0835260e0830167ffffffffffffffff94848210868311176105cc57818d52845190206101008501927f1901000000000000000000000000000000000000000000000000000000000000845261010286015261012285015260428152610160840194818610908611176105a057848c52519020835261018082015260a4356101a082015260c4356101c0909101528880528490899060809060015afa15610596578751168015158061058d575b156105315787528252848620848752825284862081905584519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259190a351f35b606482858951917f08c379a0000000000000000000000000000000000000000000000000000000008352820152600e60248201527f494e56414c49445f5349474e45520000000000000000000000000000000000006044820152fd5b508481146104ee565b86513d89823e3d90fd5b60248d6041897f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b60248e60418a7f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b60648260208951917f08c379a0000000000000000000000000000000000000000000000000000000008352820152601760248201527f5045524d49545f444541444c494e455f455850495245440000000000000000006044820152fd5b8780fd5b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df576020905173ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000004cc39af0d46b0f66fd33778c6629a696bdc310a0168152f35b5050346101df57807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df5760209161070361111a565b8273ffffffffffffffffffffffffffffffffffffffff60243592338552600387528285206107328582546111ed565b90551692838152600386522081815401905582519081527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef843392a35160018152f35b82843461035e5760807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261035e57506107af611165565b60643542116107c9576103579060209360243590356114ce565b50517f94a5fd94000000000000000000000000000000000000000000000000000000008152fd5b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df5780519082600180549161083283610ff1565b808652928281169081156108c55750600114610869575b50505061085b82610865940383611044565b51918291826110b4565b0390f35b94508085527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8286106108ad5750505061085b8260206108659582010194610849565b80546020878701810191909152909501948101610890565b61086597508693506020925061085b9491507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001682840152151560051b82010194610849565b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df5760209073ffffffffffffffffffffffffffffffffffffffff600654169051908152f35b5050346101df5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df578060209273ffffffffffffffffffffffffffffffffffffffff6109b061111a565b1681526005845220549051908152f35b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df5760209073ffffffffffffffffffffffffffffffffffffffff600754169051908152f35b9050346103085760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261030857359073ffffffffffffffffffffffffffffffffffffffff808316809303610ac657610a7490600654163314611188565b817fffffffffffffffffffffffff0000000000000000000000000000000000000000600754161760075551907fd3b5d1e0ffaeff528910f3663f0adace7694ab8241d58e17a91351ced2e080318383a2f35b8380fd5b5050346101df5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df578060209273ffffffffffffffffffffffffffffffffffffffff610b1c61111a565b1681526003845220549051908152f35b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df5760209073ffffffffffffffffffffffffffffffffffffffff600854169051908152f35b5050346101df57807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df57610bc3610bba61111a565b60243590611406565b51f35b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df57602090610357611229565b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df576020905160ff7f0000000000000000000000000000000000000000000000000000000000000012168152f35b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df576020905173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2168152f35b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df576020905173ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000fd0205066521550d7d7ab19da8f72bb004b4c341168152f35b82843461035e5760607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261035e57610d7461111a565b7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef610d9d611142565b946044358573ffffffffffffffffffffffffffffffffffffffff80951694858752602098848a958652838920338a52865283892054857fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610e32575b50505086885260038552828820610e138582546111ed565b9055169586815260038452208181540190558551908152a35160018152f35b610e3b916111ed565b90888a528652838920338a528652838920558a8085610dfb565b5050346101df57817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126101df576020906002549051908152f35b90503461030857817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261030857602092610ecd61111a565b9183602435928392338252875273ffffffffffffffffffffffffffffffffffffffff8282209516948582528752205582519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925843392a35160018152f35b8490843461030857827ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261030857828054610f6a81610ff1565b808552916001918083169081156108c55750600114610f955750505061085b82610865940383611044565b80809650527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5635b828610610fd95750505061085b8260206108659582010194610849565b80546020878701810191909152909501948101610fbc565b90600182811c9216801561103a575b602083101461100b57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b91607f1691611000565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761108557604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60208082528251818301819052939260005b858110611106575050507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8460006040809697860101520116010190565b8181018301518482016040015282016110c6565b6004359073ffffffffffffffffffffffffffffffffffffffff8216820361113d57565b600080fd5b6024359073ffffffffffffffffffffffffffffffffffffffff8216820361113d57565b6044359073ffffffffffffffffffffffffffffffffffffffff8216820361113d57565b1561118f57565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f554e415554484f52495a454400000000000000000000000000000000000000006044820152fd5b919082039182116111fa57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000467f00000000000000000000000000000000000000000000000000000000000000010361127757507fe2b90f7b9acecfc6dbe05354342abfe0f55b6fcf04979dc2b015772ee9a1bcfc90565b6040518154829161128782610ff1565b80825281602094858201946001908782821691826000146113ca575050600114611371575b506112b992500382611044565b51902091604051918201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f845260408301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a083015260a0825260c082019082821067ffffffffffffffff831117611344575060405251902090565b807f4e487b7100000000000000000000000000000000000000000000000000000000602492526041600452fd5b87805286915087907f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5635b8583106113b25750506112b99350820101386112ac565b8054838801850152869450889390920191810161139b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001688526112b995151560051b85010192503891506112ac9050565b73ffffffffffffffffffffffffffffffffffffffff90817f0000000000000000000000004cc39af0d46b0f66fd33778c6629a696bdc310a01633036114a457821561149f576002548381018091116111fa576000927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9260209260025516938484526003825260408420818154019055604051908152a3565b505050565b60046040517f7bbe6d0a000000000000000000000000000000000000000000000000000000008152fd5b9291909280156118375760003381526020600381526040908183206114f48582546111ed565b9055828052600381528183208481540190558282518581527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef833392a38073ffffffffffffffffffffffffffffffffffffffff80600754168451928380927f98d5fdca00000000000000000000000000000000000000000000000000000000825260049586915afa90811561182d578691611800575b50670de0b6b3a764000090807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0488118102158202156117fc5787029080820491061515019889116117d4578285606483600854168751907f23b872dd000000000000000000000000000000000000000000000000000000008252338783015260248201528c6044820152827f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc25af13d15601f3d1160018851141617161561177857807f000000000000000000000000fd0205066521550d7d7ab19da8f72bb004b4c3411696873b156117745785929160448492875198899384927f40c10f19000000000000000000000000000000000000000000000000000000008452169b8c878401528b60248401525af1801561176a5790899392916116f9575b50507fb1c971764663d561c0ec2baf395a55f33f0a79fabb35bbad580247ba2959523d935082519485528401523392a3565b90919394925067ffffffffffffffff831161173e575050829187917fb1c971764663d561c0ec2baf395a55f33f0a79fabb35bbad580247ba2959523d945238806116c7565b9060416024927f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b84513d84823e3d90fd5b8580fd5b509060649251917f08c379a0000000000000000000000000000000000000000000000000000000008352820152601460248201527f5452414e534645525f46524f4d5f4641494c45440000000000000000000000006044820152fd5b5082517fd193bd20000000000000000000000000000000000000000000000000000000008152fd5b8680fd5b90508381813d8311611826575b6118178183611044565b8101031261177457513861158a565b503d61180d565b85513d88823e3d90fd5b50600092505056fea2646970667358221220dfd0ddf544f0b1bbc4f2c33b50d63053ae43340fb51f9c5d77776648ebfc379a64736f6c63430008100033
Verified Source Code Full Match
Compiler: v0.8.16+commit.07a7930e
EVM: london
Optimization: Yes (1000000 runs)
OptionsToken.sol 194 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
/// @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.
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
IERC20Mintable 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_,
IERC20Mintable 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);
// mint underlying tokens to recipient
underlyingToken.mint(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