From f7d4066165f81947302f9241af51e571b407d14e Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Wed, 13 Nov 2024 17:36:19 -0700 Subject: [PATCH] build: dumper --- scripts/Deploy.s.sol | 4 +- src/splitter/Dumper.sol | 112 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 src/splitter/Dumper.sol diff --git a/scripts/Deploy.s.sol b/scripts/Deploy.s.sol index e65bc19..df4cb29 100644 --- a/scripts/Deploy.s.sol +++ b/scripts/Deploy.s.sol @@ -16,8 +16,8 @@ contract Deploy is Script { // Append constructor args to the bytecode bytes memory bytecode = abi.encodePacked( - vm.getCode("registry/ReleaseRegistry.sol:ReleaseRegistry"), - abi.encode(initGov) + vm.getCode("splitter/Dumper.sol:Dumper"), + abi.encode(0x16388463d60FFE0661Cf7F1f31a7D658aC790ff7, 0x5A74Cb32D36f2f517DB6f7b0A0591e09b22cDE69, 0xd6748776CF06a80EbE36cd83D325B31bb916bf54, 0xBe53A109B494E5c9f97b9Cd39Fe969BE68BF6204) ); // Use salt of 0. diff --git a/src/splitter/Dumper.sol b/src/splitter/Dumper.sol new file mode 100644 index 0000000..80fa819 --- /dev/null +++ b/src/splitter/Dumper.sol @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GNU AGPLv3 +pragma solidity >=0.8.18; + +import {Governance} from "@periphery/utils/Governance.sol"; +import {Accountant, ERC20, SafeERC20} from "../accountants/Accountant.sol"; + +interface IAuction { + function kick(address _token) external view returns (uint256); +} + +contract Dumper is Governance { + using SafeERC20 for ERC20; + + modifier onlyAllowed() { + require(msg.sender == governance || allowed[msg.sender], "NOT ALLOWED"); + _; + } + + Accountant public immutable accountant; + + address public immutable splitter; + + address public splitToken; + + address public auction; + + mapping(address => bool) public allowed; + + constructor( + address _governance, + address _accountant, + address _splitter, + address _splitToken + ) Governance(_governance) { + require(_accountant != address(0), "ZERO ADDRESS"); + require(_splitter != address(0), "ZERO ADDRESS"); + require(_splitToken != address(0), "ZERO ADDRESS"); + accountant = Accountant(_accountant); + splitter = _splitter; + splitToken = _splitToken; + } + + // Send the split token to the Splitter contract. + function distribute() external { + ERC20(splitToken).safeTransfer( + splitter, + ERC20(splitToken).balanceOf(address(this)) - 1 + ); + } + + function dumpToken(address _token) external onlyAllowed { + _dumpToken(_token); + } + + function dumpTokens(address[] calldata _tokens) external onlyAllowed { + for (uint256 i; i < _tokens.length; ++i) { + _dumpToken(_tokens[i]); + } + } + + function _dumpToken(address _token) internal { + uint256 accountantBalance = ERC20(_token).balanceOf( + address(accountant) + ); + if (accountantBalance > 0) { + accountant.distribute(_token); + } + ERC20(_token).safeTransfer( + auction, + ERC20(_token).balanceOf(address(this)) - 1 + ); + IAuction(auction).kick(_token); + } + + // Claim the fees from the accountant + function claimToken(address _token) external onlyAllowed { + accountant.distribute(_token); + } + + function claimTokens(address[] calldata _tokens) external onlyAllowed { + for (uint256 i; i < _tokens.length; ++i) { + accountant.distribute(_tokens[i]); + } + } + + function claimToken(address _token, uint256 _amount) external onlyAllowed { + accountant.distribute(_token, _amount); + } + + function sweep(address _token) external onlyGovernance { + ERC20(_token).safeTransfer( + governance, + ERC20(_token).balanceOf(address(this)) + ); + } + + function setSplitToken(address _splitToken) external onlyGovernance { + require(_splitToken != address(0), "ZERO ADDRESS"); + splitToken = _splitToken; + } + + function setAuction(address _auction) external onlyGovernance { + auction = _auction; + } + + function setAllowed( + address _person, + bool _allowed + ) external onlyGovernance { + allowed[_person] = _allowed; + } +}