Last active
May 13, 2022 17:02
-
-
Save z0r0z/4c797e4a185a5ea9a2ab9ef49ecd53f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: AGPL-3.0-only | |
pragma solidity >=0.8.0; | |
import "https://github.com/kalidao/multi-sig/blob/main/src/interfaces/IClubLoot.sol"; | |
import "https://github.com/Rari-Capital/solmate/blob/v7/src/tokens/ERC1155.sol"; | |
import "https://github.com/kalidao/multi-sig/blob/main/src/libraries/FixedPointMathLib.sol"; | |
import "https://github.com/kalidao/multi-sig/blob/main/src/libraries/SafeTransferLib.sol"; | |
/// @notice Ch.11 bankruptcy token | |
contract Bankruptcy is ERC1155 { | |
using SafeTransferLib for address; | |
string public name; | |
string public symbol; | |
string private petition; // petition info | |
address public court; // this mints and manages claims | |
address private constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; | |
bool public planApproved; // this tracks confirmation of bruptcy plan | |
mapping(uint256 => uint256) public totalSupplyPerId; | |
// ** PETITION DATA | |
function uri(uint256) public override view returns (string memory) { | |
return petition; | |
} | |
constructor( | |
string memory _name, | |
string memory _symbol, | |
string memory _petition | |
) { | |
name = _name; | |
symbol = _symbol; | |
petition = _petition; | |
court = msg.sender; | |
} | |
// ** COURT FUNCTIONS | |
function mint( | |
address to, | |
uint256 id, | |
uint256 amount | |
) external { | |
require(msg.sender == court, "NOT_COURT"); | |
_mint(to, id, amount, ""); | |
totalSupplyPerId[id] += amount; | |
} | |
function burn(address from, uint256 id, uint256 amount) external { | |
require(msg.sender == court, "NOT_COURT"); | |
_burn(from, id, amount); | |
totalSupplyPerId[id] -= amount; | |
} | |
function approvePlan() external { | |
require(msg.sender == court, "NOT_COURT"); | |
planApproved = !planApproved; | |
} | |
// ** CREDITOR REDEMPTIONS | |
/// @dev redemption is only available for ETH and ERC-20 | |
/// - NFTs will need to be liquidated or fractionalized | |
function redemption( | |
address[] calldata assets, | |
uint256 id, | |
uint256 burnAmt | |
) | |
external | |
payable | |
{ | |
require(planApproved, "NOT_APPROVED"); | |
uint256 total = totalSupplyPerId[id]; | |
address prevAddr; | |
for (uint256 i; i < assets.length; ) { | |
// prevent null and duplicate assets | |
require(prevAddr < assets[i], "WRONG_ORDER"); | |
prevAddr = assets[i]; | |
// calculate fair share of given assets for redemption | |
uint256 amountToRedeem = FixedPointMathLib.mulDivDown( | |
burnAmt, | |
assets[i] == ETH | |
? address(this).balance | |
: IClubLoot(assets[i]).balanceOf(address(this)), | |
total | |
); | |
// transfer to redeemer | |
if (amountToRedeem != 0) | |
assets[i] == ETH | |
? msg.sender._safeTransferETH(amountToRedeem) | |
: assets[i]._safeTransfer(msg.sender, amountToRedeem); | |
// cannot realistically overflow | |
unchecked { | |
++i; | |
} | |
} | |
_burn(msg.sender, id, burnAmt); | |
totalSupplyPerId[id] -= burnAmt; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://hackmd.io/bOGB24qvTBGWM5_qTidGDQ