Skip to content

Instantly share code, notes, and snippets.

@z0r0z
Last active May 13, 2022 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z0r0z/4c797e4a185a5ea9a2ab9ef49ecd53f0 to your computer and use it in GitHub Desktop.
Save z0r0z/4c797e4a185a5ea9a2ab9ef49ecd53f0 to your computer and use it in GitHub Desktop.
// 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;
}
}
@z0r0z
Copy link
Author

z0r0z commented May 13, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment