// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
/*
Wrapped MitoBlobs (wBLOBS)
Turn your BLOBs into wBLOBS that can be fractionally traded on Uniswap.
@MitoBlobs
https://mitoblobs.xyz
*/
interface Callable {
function tokenCallback(
address _from,
uint256 _tokens,
bytes calldata _data
) external returns (bool);
}
interface MB {
function balanceOf(address) external view returns (uint256);
function allowance(address, address) external view returns (uint256);
function isApprovedForAll(address, address) external view returns (bool);
function transfer(address _to, uint256 _tokens) external returns (bool);
function transferFrom(
address _from,
address _to,
uint256 _tokens
) external returns (bool);
}
contract wBLOBS {
uint256 private constant UINT_MAX = type(uint256).max;
MB public mitoblobs;
string public constant name = "Wrapped Blobs";
string public constant symbol = "wBLOBS";
uint8 public constant decimals = 18;
struct User {
uint256 balance;
mapping(address => uint256) allowance;
}
struct Info {
mapping(address => User) users;
}
Info private info;
event Transfer(address indexed from, address indexed to, uint256 tokens);
event Approval(
address indexed owner,
address indexed spender,
uint256 tokens
);
event Wrap(address indexed owner, uint256 tokens);
event Unwrap(address indexed owner, uint256 tokens);
constructor(address _mitoblobs) {
mitoblobs = MB(_mitoblobs);
}
function wrap(uint256 tokenId) public {
uint256 _balanceBefore = mitoblobs.balanceOf(address(this));
mitoblobs.transferFrom(msg.sender, address(this), tokenId);
uint256 _wrapped = mitoblobs.balanceOf(address(this)) - _balanceBefore;
require(_wrapped > 0);
info.users[msg.sender].balance += _wrapped * 1e18;
emit Transfer(address(0x0), msg.sender, _wrapped * 1e18);
emit Wrap(msg.sender, _wrapped);
}
function wrapMultiple(uint256[] memory tokenIds) external {
for (uint256 i; i < tokenIds.length; i++) {
wrap(tokenIds[i]);
}
}
function unwrap(uint256 _tokens) external {
require(_tokens > 0);
require(balanceOf(msg.sender) >= _tokens * 1e18);
info.users[msg.sender].balance -= _tokens * 1e18;
mitoblobs.transfer(msg.sender, _tokens);
emit Transfer(msg.sender, address(0x0), _tokens * 1e18);
emit Unwrap(msg.sender, _tokens);
}
function multisend(address[] memory recipients, uint256 amount) external {
require(balanceOf(msg.sender) >= recipients.length * amount, "Your balance is too low");
for (uint256 i; i < recipients.length; i++) {
_transfer(msg.sender, recipients[i], amount);
}
}
function transfer(address _to, uint256 _tokens) external returns (bool) {
return _transfer(msg.sender, _to, _tokens);
}
function approve(
address _spender,
uint256 _tokens
) external returns (bool) {
info.users[msg.sender].allowance[_spender] = _tokens;
emit Approval(msg.sender, _spender, _tokens);
return true;
}
function transferFrom(
address _from,
address _to,
uint256 _tokens
) external returns (bool) {
uint256 _allowance = allowance(_from, msg.sender);
require(_allowance >= _tokens);
if (_allowance != UINT_MAX) {
info.users[_from].allowance[msg.sender] -= _tokens;
}
return _transfer(_from, _to, _tokens);
}
function transferAndCall(
address _to,
uint256 _tokens,
bytes calldata _data
) external returns (bool) {
_transfer(msg.sender, _to, _tokens);
uint32 _size;
assembly {
_size := extcodesize(_to)
}
if (_size > 0) {
require(Callable(_to).tokenCallback(msg.sender, _tokens, _data));
}
return true;
}
function totalSupply() public view returns (uint256) {
return mitoblobs.balanceOf(address(this)) * 1e18;
}
function balanceOf(address _user) public view returns (uint256) {
return info.users[_user].balance;
}
function allowance(
address _user,
address _spender
) public view returns (uint256) {
return info.users[_user].allowance[_spender];
}
function allInfoFor(
address _user
)
external
view
returns (
uint256 totalTokens,
uint256 userBLOBs,
uint256 userAllowance,
bool userApprovedForAll,
uint256 userBalance
)
{
totalTokens = totalSupply();
userBLOBs = mitoblobs.balanceOf(_user);
userAllowance = mitoblobs.allowance(_user, address(this));
userApprovedForAll = mitoblobs.isApprovedForAll(_user, address(this));
userBalance = balanceOf(_user);
}
function _transfer(
address _from,
address _to,
uint256 _tokens
) internal returns (bool) {
unchecked {
require(balanceOf(_from) >= _tokens);
info.users[_from].balance -= _tokens;
info.users[_to].balance += _tokens;
emit Transfer(_from, _to, _tokens);
return true;
}
}
}
{
"compilationTarget": {
"wBLOBS.sol": "wBLOBS"
},
"evmVersion": "shanghai",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_mitoblobs","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":"tokens","type":"uint256"}],"name":"Approval","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":"tokens","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"}],"name":"Unwrap","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"}],"name":"Wrap","type":"event"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"allInfoFor","outputs":[{"internalType":"uint256","name":"totalTokens","type":"uint256"},{"internalType":"uint256","name":"userBLOBs","type":"uint256"},{"internalType":"uint256","name":"userAllowance","type":"uint256"},{"internalType":"bool","name":"userApprovedForAll","type":"bool"},{"internalType":"uint256","name":"userBalance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"address","name":"_spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_tokens","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","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":[],"name":"mitoblobs","outputs":[{"internalType":"contract MB","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"recipients","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"multisend","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokens","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokens","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"transferAndCall","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":"_tokens","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokens","type":"uint256"}],"name":"unwrap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"wrap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"wrapMultiple","outputs":[],"stateMutability":"nonpayable","type":"function"}]