Skip to content

Instantly share code, notes, and snippets.

@rfikki
Created June 18, 2025 21:55
Show Gist options
  • Save rfikki/27770a26e4e305212c73c83618b6e59a to your computer and use it in GitHub Desktop.
Save rfikki/27770a26e4e305212c73c83618b6e59a to your computer and use it in GitHub Desktop.
WrappedCurrencyCoin wrapper for 2015 currency.sol located here: 0x8494F777d13503BE928BB22b1F4ae3289E634FD3
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
interface CurrencyCoin {
function coinBalanceOf(address _owner) external returns (uint256);
function sendCoin(uint256 _amount, address _receiver) external;
}
contract DropBox is Ownable(msg.sender) {
function collect(uint256 value, CurrencyCoin ccInt) public onlyOwner {
ccInt.sendCoin(value, owner());
}
}
contract WrappedCurrencyCoin is ERC20 {
event DropBoxCreated(address indexed owner);
event Wrapped(uint256 indexed value, address indexed owner);
event Unwrapped(uint256 indexed value, address indexed owner);
address constant ccAddr = 0x8494F777d13503BE928BB22b1F4ae3289E634FD3;
CurrencyCoin constant ccInt = CurrencyCoin(ccAddr);
mapping(address => address) public dropBoxes;
constructor() ERC20("Wrapped CurrencyCoin", "WCC") {}
function createDropBox() public {
require(dropBoxes[msg.sender] == address(0), "Drop box already exists");
dropBoxes[msg.sender] = address(new DropBox());
emit DropBoxCreated(msg.sender);
}
function wrap(uint256 value) public {
address dropBox = dropBoxes[msg.sender];
require(dropBox != address(0), "You must create a drop box first");
require(ccInt.coinBalanceOf(dropBox) >= value, "Not enough coins in drop box");
DropBox(dropBox).collect(value, ccInt);
_mint(msg.sender, value);
emit Wrapped(value, msg.sender);
}
function unwrap(uint256 value) public {
require(balanceOf(msg.sender) >= value, "Not enough coins to unwrap");
ccInt.sendCoin(value, msg.sender);
_burn(msg.sender, value);
emit Unwrapped(value, msg.sender);
}
function decimals() public pure override returns (uint8) {
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment