Skip to content

Commit

Permalink
build: dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Nov 14, 2024
1 parent f507720 commit f7d4066
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
112 changes: 112 additions & 0 deletions src/splitter/Dumper.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit f7d4066

Please sign in to comment.