文件 1 的 1:RoyaltiesGovernance.sol
pragma solidity ^0.8.0;
abstract contract Ownable {
address public owner;
constructor() { owner = msg.sender; }
modifier onlyOwner { require(owner == msg.sender, "Not Owner!"); _; }
function transferOwnership(address new_) external onlyOwner { owner = new_; }
}
contract RoyaltiesGovernance is Ownable {
address public payableGovernanceSetter;
constructor() payable { payableGovernanceSetter = msg.sender; }
modifier onlyPayableGovernanceSetter {
require(msg.sender == payableGovernanceSetter,
"PayableGovernance: Caller is not Setter!"); _; }
function reouncePayableGovernancePermissions() public onlyPayableGovernanceSetter {
payableGovernanceSetter = address(0x0); }
event Received(address from, uint amount);
receive() external payable { emit Received(msg.sender, msg.value); }
address payable[] internal _payableGovernanceAddresses;
uint256[] internal _payableGovernanceShares;
mapping(address => bool) public addressToEmergencyUnlocked;
function _withdraw(address payable address_, uint256 amount_) internal {
(bool success, ) = payable(address_).call{value: amount_}("");
require(success, "Transfer failed");
}
function setPayableGovernanceShareholders(address payable[] memory addresses_,
uint256[] memory shares_) public onlyPayableGovernanceSetter {
require(_payableGovernanceAddresses.length == 0
&& _payableGovernanceShares.length == 0,
"Payable Governance already set! To set again, reset first!");
require(addresses_.length == shares_.length,
"Address and Shares length mismatch!");
uint256 _totalShares;
for (uint256 i = 0; i < addresses_.length; i++) {
_totalShares += shares_[i];
_payableGovernanceAddresses.push(addresses_[i]);
_payableGovernanceShares.push(shares_[i]);
}
require(_totalShares == 1000, "Total Shares is not 1000!");
}
function resetPayableGovernanceShareholders() public onlyPayableGovernanceSetter {
while (_payableGovernanceAddresses.length != 0) {
_payableGovernanceAddresses.pop(); }
while (_payableGovernanceShares.length != 0) {
_payableGovernanceShares.pop(); }
}
function balance() public view returns (uint256) {
return address(this).balance;
}
function payableGovernanceAddresses() public view
returns (address payable[] memory) {
return _payableGovernanceAddresses;
}
function payableGovernanceShares() public view returns (uint256[] memory) {
return _payableGovernanceShares;
}
function withdrawEther() public onlyShareholder {
require(_payableGovernanceAddresses.length > 0
&& _payableGovernanceShares.length > 0,
"Payable governance not set yet!");
require(_payableGovernanceAddresses.length
== _payableGovernanceShares.length,
"Payable governance length mismatch!");
uint256 _totalPayableShares;
for (uint256 i = 0; i < _payableGovernanceShares.length; i++) {
_totalPayableShares += _payableGovernanceShares[i]; }
require(_totalPayableShares == 1000, "Payable Governance Shares is not 1000!");
uint256 _totalETH = address(this).balance;
for (uint256 i = 0; i < _payableGovernanceAddresses.length; i++) {
uint256 _ethToWithdraw = ((_totalETH * _payableGovernanceShares[i]) / 1000);
_withdraw(_payableGovernanceAddresses[i], _ethToWithdraw);
}
}
function viewWithdrawAmounts() public view onlyShareholder returns (uint256[] memory) {
require(_payableGovernanceAddresses.length > 0
&& _payableGovernanceShares.length > 0,
"Payable governance not set yet!");
require(_payableGovernanceAddresses.length
== _payableGovernanceShares.length,
"Payable governance length mismatch!");
uint256 _totalPayableShares;
for (uint256 i = 0; i < _payableGovernanceShares.length; i++) {
_totalPayableShares += _payableGovernanceShares[i]; }
require(_totalPayableShares == 1000, "Payable Governance Shares is not 1000!");
uint256 _totalETH = address(this).balance;
uint256[] memory _withdrawals = new uint256[]
(_payableGovernanceAddresses.length + 2);
for (uint256 i = 0; i < _payableGovernanceAddresses.length; i++) {
_withdrawals[i] = ( (_totalETH * _payableGovernanceShares[i]) / 1000 );
}
_withdrawals[_payableGovernanceAddresses.length] = _totalETH;
for (uint256 i = 0; i < _payableGovernanceAddresses.length; i++) {
_withdrawals[_payableGovernanceAddresses.length + 1] += _withdrawals[i]; }
return _withdrawals;
}
modifier onlyShareholder {
bool _isShareholder;
for (uint256 i = 0; i < _payableGovernanceAddresses.length; i++) {
if (msg.sender == _payableGovernanceAddresses[i]) {
_isShareholder = true;
}
}
require(_isShareholder, "You are not a shareholder!");
_;
}
function unlockEmergencyFunctionsAsShareholder() public onlyShareholder {
addressToEmergencyUnlocked[msg.sender] = true;
}
modifier onlyEmergency {
for (uint256 i = 0; i < _payableGovernanceAddresses.length; i++) {
require(addressToEmergencyUnlocked[_payableGovernanceAddresses[i]],
"Emergency Functions are not unlocked!");
}
_;
}
function emergencyWithdrawEther() public onlyOwner onlyEmergency {
_withdraw(payable(msg.sender), address(this).balance);
}
}
{
"compilationTarget": {
"RoyaltiesGovernance.sol": "RoyaltiesGovernance"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}