Проверенный контрактТочноеMIT
WithdrawDAO
Адрес0xd25a72aec9356cedbe690c4ecf7b36a2a608f40d
- Баланс
0 ETH
- Транзакций
23
- Компилятор
solc 0.4.26
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.4.26+commit.4563c3fc
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Лицензия
- MIT
- Совпадение
- Точноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 25 723 924
- Транзакция создания
- 0xe4eae70b08…d141049868
WithdrawDAO.sol
// SPDX-License-Identifier: MIT
// thereum WithdrawDAO.
pragma solidity 0.4.26;
interface ILegacyERC20 {
function balanceOf(address account) external view returns (uint256);
}
library VaultSafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "subtraction overflow");
return a - b;
}
}
library LegacySafeToken {
function safeTransfer(address token, address to, uint256 amount) internal {
callOptionalReturn(
token,
abi.encodeWithSelector(bytes4(keccak256("transfer(address,uint256)")), to, amount)
);
}
function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
callOptionalReturn(
token,
abi.encodeWithSelector(
bytes4(keccak256("transferFrom(address,address,uint256)")),
from,
to,
amount
)
);
}
function callOptionalReturn(address token, bytes memory data) private {
uint256 size;
assembly { size := extcodesize(token) }
require(size > 0, "token is not a contract");
bool success;
assembly {
let pointer := mload(0x40)
success := call(gas, token, 0, add(data, 0x20), mload(data), 0, 0)
let returnSize := returndatasize
switch success
case 0 { }
default {
switch returnSize
case 0 { }
case 0x20 {
returndatacopy(pointer, 0, 0x20)
success := iszero(iszero(mload(pointer)))
}
default { success := 0 }
}
}
require(success, "token operation failed");
}
}
contract WithdrawDAO {
using VaultSafeMath for uint256;
using LegacySafeToken for address;
uint8 public constant STATE_NONE = 0;
uint8 public constant STATE_DEPOSITED = 1;
uint8 public constant STATE_COLLECTED = 2;
uint8 public constant STATE_PROCESSING = 3;
uint8 public constant STATE_CLAIMED = 4;
uint8 public constant STATE_PAID = 5;
uint8 public constant STATE_REFUNDED = 6;
uint256 public constant MAX_BATCH_SIZE = 50;
struct TokenPolicy {
bool enabled;
uint256 minimumAmount;
uint256 maximumAmount;
}
struct DepositRecord {
address depositor;
address beneficiary;
address token;
bytes32 projectId;
uint256 tokenAmount;
uint256 claimedWei;
uint256 paidWei;
uint256 createdAt;
uint8 state;
bytes32 clientReference;
bytes32 processingReference;
}
address public administrator;
address public pendingAdministrator;
address public collector;
address public pauser;
address public custodyRecipient;
address public pendingCustodyRecipient;
uint256 public custodyRecipientChangeTime;
uint256 public constant CUSTODY_RECIPIENT_CHANGE_DELAY = 48 hours;
bool public paused;
bool private entered;
uint256 public depositNonce;
mapping(bytes32 => mapping(address => TokenPolicy)) public tokenPolicies;
mapping(bytes32 => DepositRecord) public deposits;
mapping(address => uint256) public reservedTokenBalance;
event ProjectTokenPolicyUpdated(
bytes32 indexed projectId,
address indexed token,
bool enabled,
uint256 minimumAmount,
uint256 maximumAmount
);
event Deposited(
bytes32 indexed depositId,
bytes32 indexed projectId,
address indexed depositor,
address beneficiary,
address token,
uint256 requestedAmount,
uint256 receivedAmount,
bytes32 clientReference
);
event Collected(
bytes32 indexed depositId,
address indexed token,
address indexed custodyRecipient,
uint256 amount
);
event ProcessingStarted(bytes32 indexed depositId, bytes32 indexed processingReference);
event ClaimRecorded(bytes32 indexed depositId, uint256 claimedWei, bytes32 indexed processingReference);
event Settled(bytes32 indexed depositId, address indexed beneficiary, uint256 paidWei);
event Refunded(bytes32 indexed depositId, address indexed depositor, address indexed token, uint256 amount);
event CollectedDepositReturned(bytes32 indexed depositId, address indexed depositor, address indexed token, uint256 amount);
event PauseUpdated(bool paused);
event CollectorUpdated(address indexed previousCollector, address indexed newCollector);
event PauserUpdated(address indexed previousPauser, address indexed newPauser);
event CustodyRecipientChangeScheduled(
address indexed currentRecipient,
address indexed pendingRecipient,
uint256 executableAt
);
event CustodyRecipientChangeCancelled(address indexed pendingRecipient);
event CustodyRecipientChanged(address indexed previousRecipient, address indexed newRecipient);
event AdministratorTransferStarted(address indexed previousAdministrator, address indexed pendingAdministrator);
event AdministratorTransferred(address indexed previousAdministrator, address indexed newAdministrator);
event ExcessTokenRecovered(address indexed token, address indexed recipient, uint256 amount);
event ForcedEtherRecovered(address indexed recipient, uint256 amount);
event CustodyTokenWithdrawal(address indexed token, address indexed recipient, uint256 amount);
event CustodyEtherWithdrawal(address indexed recipient, uint256 amount);
event EtherReceived(address indexed sender, uint256 amount);
modifier onlyAdministrator() {
require(msg.sender == administrator, "administrator only");
_;
}
modifier onlyCollector() {
require(msg.sender == collector, "collector only");
_;
}
modifier onlyCustodyRecipient() {
require(msg.sender == custodyRecipient, "custody recipient only");
_;
}
modifier onlyPauserOrAdministrator() {
require(msg.sender == pauser || msg.sender == administrator, "pauser only");
_;
}
modifier whenNotPaused() {
require(!paused, "contract paused");
_;
}
modifier nonReentrant() {
require(!entered, "reentrant call");
entered = true;
_;
entered = false;
}
constructor(
address initialAdministrator,
address initialCollector,
address initialPauser,
address initialCustodyRecipient
) public {
require(initialAdministrator != address(0), "invalid administrator");
require(initialCollector != address(0), "invalid collector");
require(initialPauser != address(0), "invalid pauser");
require(initialCustodyRecipient != address(0), "invalid custody recipient");
require(initialAdministrator != initialCustodyRecipient, "roles must differ");
administrator = initialAdministrator;
collector = initialCollector;
pauser = initialPauser;
custodyRecipient = initialCustodyRecipient;
emit AdministratorTransferred(address(0), initialAdministrator);
emit CollectorUpdated(address(0), initialCollector);
emit PauserUpdated(address(0), initialPauser);
emit CustodyRecipientChanged(address(0), initialCustodyRecipient);
}
function() external payable {
emit EtherReceived(msg.sender, msg.value);
}
function setProjectTokenPolicy(
bytes32 projectId,
address token,
bool enabled,
uint256 minimumAmount,
uint256 maximumAmount
) external onlyAdministrator {
require(projectId != bytes32(0), "invalid project");
require(token != address(0), "invalid token");
require(minimumAmount > 0, "invalid minimum");
require(maximumAmount == 0 || maximumAmount >= minimumAmount, "invalid maximum");
tokenPolicies[projectId][token] = TokenPolicy({
enabled: enabled,
minimumAmount: minimumAmount,
maximumAmount: maximumAmount
});
emit ProjectTokenPolicyUpdated(projectId, token, enabled, minimumAmount, maximumAmount);
}
function depositToken(
bytes32 projectId,
address token,
uint256 requestedAmount,
address beneficiary,
bytes32 clientReference
) external whenNotPaused nonReentrant returns (bytes32 depositId) {
require(beneficiary != address(0), "invalid beneficiary");
require(requestedAmount > 0, "invalid amount");
TokenPolicy storage policy = tokenPolicies[projectId][token];
require(policy.enabled, "project token disabled");
uint256 balanceBefore = ILegacyERC20(token).balanceOf(address(this));
token.safeTransferFrom(msg.sender, address(this), requestedAmount);
uint256 balanceAfter = ILegacyERC20(token).balanceOf(address(this));
require(balanceAfter > balanceBefore, "nothing received");
uint256 receivedAmount = balanceAfter.sub(balanceBefore);
require(receivedAmount >= policy.minimumAmount, "below minimum");
require(policy.maximumAmount == 0 || receivedAmount <= policy.maximumAmount, "above maximum");
depositNonce = depositNonce.add(1);
depositId = keccak256(
abi.encodePacked(address(this), msg.sender, beneficiary, projectId, token, depositNonce)
);
require(deposits[depositId].state == STATE_NONE, "duplicate deposit");
deposits[depositId] = DepositRecord({
depositor: msg.sender,
beneficiary: beneficiary,
token: token,
projectId: projectId,
tokenAmount: receivedAmount,
claimedWei: 0,
paidWei: 0,
createdAt: now,
state: STATE_DEPOSITED,
clientReference: clientReference,
processingReference: bytes32(0)
});
reservedTokenBalance[token] = reservedTokenBalance[token].add(receivedAmount);
emit Deposited(
depositId,
projectId,
msg.sender,
beneficiary,
token,
requestedAmount,
receivedAmount,
clientReference
);
}
function collectDeposit(bytes32 depositId) external onlyCollector nonReentrant {
collectOne(depositId);
}
function collectDeposits(bytes32[] depositIds) external onlyCollector nonReentrant {
require(depositIds.length > 0 && depositIds.length <= MAX_BATCH_SIZE, "invalid batch");
for (uint256 i = 0; i < depositIds.length; i++) {
collectOne(depositIds[i]);
}
}
function collectOne(bytes32 depositId) private {
DepositRecord storage record = deposits[depositId];
require(record.state == STATE_DEPOSITED, "deposit not collectable");
record.state = STATE_COLLECTED;
reservedTokenBalance[record.token] = reservedTokenBalance[record.token].sub(record.tokenAmount);
record.token.safeTransfer(custodyRecipient, record.tokenAmount);
emit Collected(depositId, record.token, custodyRecipient, record.tokenAmount);
}
function markProcessing(bytes32 depositId, bytes32 processingReference) external onlyCollector {
DepositRecord storage record = deposits[depositId];
require(record.state == STATE_COLLECTED, "deposit not collected");
require(processingReference != bytes32(0), "invalid reference");
record.state = STATE_PROCESSING;
record.processingReference = processingReference;
emit ProcessingStarted(depositId, processingReference);
}
function recordClaim(
bytes32 depositId,
uint256 claimedWei,
bytes32 processingReference
) external onlyCollector {
DepositRecord storage record = deposits[depositId];
require(record.state == STATE_COLLECTED || record.state == STATE_PROCESSING, "invalid state");
require(claimedWei > 0, "invalid claim amount");
require(processingReference != bytes32(0), "invalid reference");
record.state = STATE_CLAIMED;
record.claimedWei = claimedWei;
record.processingReference = processingReference;
emit ClaimRecorded(depositId, claimedWei, processingReference);
}
function settleETH(bytes32 depositId) external payable onlyCollector nonReentrant {
DepositRecord storage record = deposits[depositId];
require(record.state == STATE_CLAIMED, "claim not recorded");
require(msg.value == record.claimedWei, "incorrect settlement amount");
record.state = STATE_PAID;
record.paidWei = msg.value;
require(record.beneficiary.call.value(msg.value)(), "ETH payment failed");
emit Settled(depositId, record.beneficiary, msg.value);
}
function refundDeposit(bytes32 depositId) external onlyAdministrator nonReentrant {
DepositRecord storage record = deposits[depositId];
require(record.state == STATE_DEPOSITED, "deposit not refundable");
record.state = STATE_REFUNDED;
reservedTokenBalance[record.token] = reservedTokenBalance[record.token].sub(record.tokenAmount);
record.token.safeTransfer(record.depositor, record.tokenAmount);
emit Refunded(depositId, record.depositor, record.token, record.tokenAmount);
}
function returnCollectedDeposit(bytes32 depositId) external onlyAdministrator nonReentrant {
DepositRecord storage record = deposits[depositId];
require(record.state == STATE_COLLECTED || record.state == STATE_PROCESSING, "invalid state");
uint256 balanceBefore = ILegacyERC20(record.token).balanceOf(address(this));
record.token.safeTransferFrom(
custodyRecipient,
address(this),
record.tokenAmount
);
uint256 balanceAfter = ILegacyERC20(record.token).balanceOf(address(this));
require(balanceAfter.sub(balanceBefore) == record.tokenAmount, "incorrect return amount");
record.state = STATE_REFUNDED;
record.token.safeTransfer(record.depositor, record.tokenAmount);
emit CollectedDepositReturned(depositId, record.depositor, record.token, record.tokenAmount);
}
function setPaused(bool newPaused) external onlyPauserOrAdministrator {
paused = newPaused;
emit PauseUpdated(newPaused);
}
function setCollector(address newCollector) external onlyAdministrator {
require(newCollector != address(0), "invalid collector");
address previous = collector;
collector = newCollector;
emit CollectorUpdated(previous, newCollector);
}
function setPauser(address newPauser) external onlyAdministrator {
require(newPauser != address(0), "invalid pauser");
address previous = pauser;
pauser = newPauser;
emit PauserUpdated(previous, newPauser);
}
function scheduleCustodyRecipientChange(address newRecipient) external onlyCustodyRecipient {
require(newRecipient != address(0), "invalid custody recipient");
require(newRecipient != custodyRecipient, "same custody recipient");
require(newRecipient != administrator, "roles must differ");
pendingCustodyRecipient = newRecipient;
custodyRecipientChangeTime = now.add(CUSTODY_RECIPIENT_CHANGE_DELAY);
emit CustodyRecipientChangeScheduled(
custodyRecipient,
newRecipient,
custodyRecipientChangeTime
);
}
function cancelCustodyRecipientChange() external onlyCustodyRecipient {
address cancelled = pendingCustodyRecipient;
require(cancelled != address(0), "no pending custody recipient");
pendingCustodyRecipient = address(0);
custodyRecipientChangeTime = 0;
emit CustodyRecipientChangeCancelled(cancelled);
}
function executeCustodyRecipientChange() external {
address next = pendingCustodyRecipient;
require(next != address(0), "no pending custody recipient");
require(now >= custodyRecipientChangeTime, "delay not elapsed");
address previous = custodyRecipient;
custodyRecipient = next;
pendingCustodyRecipient = address(0);
custodyRecipientChangeTime = 0;
emit CustodyRecipientChanged(previous, next);
}
function beginAdministratorTransfer(address newAdministrator) external onlyAdministrator {
require(newAdministrator != address(0), "invalid administrator");
require(newAdministrator != custodyRecipient, "roles must differ");
require(newAdministrator != pendingCustodyRecipient, "pending custody conflict");
pendingAdministrator = newAdministrator;
emit AdministratorTransferStarted(administrator, newAdministrator);
}
function acceptAdministratorRole() external {
require(msg.sender == pendingAdministrator, "pending administrator only");
address previous = administrator;
administrator = msg.sender;
pendingAdministrator = address(0);
emit AdministratorTransferred(previous, msg.sender);
}
function recoverExcessToken(address token, uint256 amount) external onlyCustodyRecipient nonReentrant {
require(token != address(0), "invalid token");
require(amount > 0, "invalid amount");
uint256 balance = ILegacyERC20(token).balanceOf(address(this));
require(balance >= reservedTokenBalance[token], "reserved balance missing");
require(amount <= balance.sub(reservedTokenBalance[token]), "amount exceeds excess");
token.safeTransfer(custodyRecipient, amount);
emit ExcessTokenRecovered(token, custodyRecipient, amount);
}
function recoverForcedEther(uint256 amount) external onlyCustodyRecipient nonReentrant {
require(paused, "pause before ETH recovery");
require(amount > 0 && amount <= address(this).balance, "invalid amount");
require(custodyRecipient.call.value(amount)(), "ETH recovery failed");
emit ForcedEtherRecovered(custodyRecipient, amount);
}
function custodyWithdrawToken(
address token,
uint256 amount
) external onlyCustodyRecipient nonReentrant {
require(token != address(0), "invalid token");
require(amount > 0, "invalid amount");
token.safeTransfer(custodyRecipient, amount);
emit CustodyTokenWithdrawal(token, custodyRecipient, amount);
}
function custodyWithdrawEther(uint256 amount) external onlyCustodyRecipient nonReentrant {
require(amount > 0 && amount <= address(this).balance, "invalid amount");
require(custodyRecipient.call.value(amount)(), "ETH withdrawal failed");
emit CustodyEtherWithdrawal(custodyRecipient, amount);
}
function getDepositCore(bytes32 depositId) external view returns (
address depositor,
address beneficiary,
address token,
bytes32 projectId,
uint256 tokenAmount,
uint256 claimedWei,
uint256 paidWei,
uint8 state
) {
DepositRecord storage record = deposits[depositId];
return (
record.depositor,
record.beneficiary,
record.token,
record.projectId,
record.tokenAmount,
record.claimedWei,
record.paidWei,
record.state
);
}
}
Настройки компилятораПоказать
{
"optimizer": {
"runs": 200,
"enabled": true
},
"remappings": []
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.