Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: dumper #47

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions contracts/Mocks/MockTradeFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.18;

contract MockTradeFactory {
function enable(address, address) external {}

function disable(address, address) external {}
}
94 changes: 94 additions & 0 deletions contracts/splitter/Dumper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: GNU AGPLv3
pragma solidity >=0.8.18;

import {Governance} from "@periphery/utils/Governance.sol";
import {TradeFactorySwapper} from "@periphery/swappers/TradeFactorySwapper.sol";
import {Accountant, ERC20, SafeERC20} from "../accountants/Accountant.sol";

contract Dumper is TradeFactorySwapper, Governance {
using SafeERC20 for ERC20;

Accountant public immutable accountant;

address public immutable splitter;

address public splitToken;

constructor(
address _governance,
address _accountant,
address _splitter,
address _tf,
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;
_setTradeFactory(_tf, _splitToken);
splitToken = _splitToken;
}

function setTradeFactory(address _tf) external onlyGovernance {
_setTradeFactory(_tf, splitToken);
}

function addToken(address _tokenFrom) external onlyGovernance {
_addToken(_tokenFrom, splitToken);
}

function addTokens(address[] calldata _tokens) external onlyGovernance {
address _splitToken = splitToken;
for (uint256 i; i < _tokens.length; ++i) {
_addToken(_tokens[i], _splitToken);
}
}

function removeTokens(address[] calldata _tokens) external onlyGovernance {
address _splitToken = splitToken;
for (uint256 i; i < _tokens.length; ++i) {
_removeToken(_tokens[i], _splitToken);
}
}

function setSplitToken(address _splitToken) external onlyGovernance {
require(_splitToken != address(0), "ZERO ADDRESS");
// Set to same Trade Factory address but new split token
_setTradeFactory(tradeFactory(), _splitToken);
splitToken = _splitToken;
}

// Send the split token to the Splitter contract.
function distribute() external {
ERC20(splitToken).safeTransfer(
splitter,
ERC20(splitToken).balanceOf(address(this)) - 1
);
}

function _claimRewards() internal override {}

// Claim the fees from the accountant
function claim(address _token) external onlyGovernance {
accountant.distribute(_token);
}

function claim(address[] calldata _tokens) external onlyGovernance {
for (uint256 i; i < _tokens.length; ++i) {
accountant.distribute(_tokens[i]);
}
}

function claim(address _token, uint256 _amount) external onlyGovernance {
accountant.distribute(_token, _amount);
}

function sweep(address _token) external onlyGovernance {
address daddy = accountant.feeManager();
ERC20(_token).safeTransfer(
daddy,
ERC20(_token).balanceOf(address(this))
);
}
}
78 changes: 78 additions & 0 deletions tests/splitter/test_dumper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import ape
from ape import project


def test_dumper(asset, vault, accountant, daddy, brain, amount):
splitter = daddy
tf = brain.deploy(project.MockTradeFactory)
dumper = brain.deploy(
project.Dumper, brain, accountant.address, splitter, tf, vault
)
accountant.setFeeRecipient(dumper, sender=daddy)

assert dumper.governance() == brain
assert dumper.accountant() == accountant
assert dumper.tradeFactory() == tf
assert dumper.splitToken() == vault
assert dumper.rewardTokens() == []

with ape.reverts("!governance"):
dumper.addTokens([asset], sender=daddy)

with ape.reverts("!governance"):
dumper.addToken(asset, sender=daddy)

dumper.addTokens([asset], sender=brain)

assert dumper.rewardTokens() == [asset]

asset.mint(accountant, amount, sender=brain)

assert asset.balanceOf(accountant) == amount
assert asset.balanceOf(dumper) == 0
assert asset.balanceOf(splitter) == 0

with ape.reverts("!governance"):
dumper.claim([asset], sender=daddy)

dumper.claim([asset], sender=brain)

assert asset.balanceOf(accountant) == 0
assert asset.balanceOf(dumper) == amount
assert vault.balanceOf(dumper) == 0
assert asset.balanceOf(splitter) == 0
assert vault.balanceOf(splitter) == 0

asset.transferFrom(dumper, tf, amount, sender=tf)

assert asset.balanceOf(accountant) == 0
assert asset.balanceOf(dumper) == 0
assert asset.balanceOf(tf) == amount

asset.approve(vault, amount, sender=tf)
vault.deposit(amount, dumper, sender=tf)

assert asset.balanceOf(accountant) == 0
assert asset.balanceOf(dumper) == 0
assert vault.balanceOf(dumper) == amount
assert asset.balanceOf(splitter) == 0
assert vault.balanceOf(splitter) == 0

dumper.distribute(sender=daddy)

assert asset.balanceOf(accountant) == 0
assert asset.balanceOf(dumper) == 0
assert vault.balanceOf(dumper) == 1
assert asset.balanceOf(splitter) == 0
assert vault.balanceOf(splitter) == amount - 1

with ape.reverts("!governance"):
dumper.setSplitToken(asset, sender=daddy)

dumper.setSplitToken(asset, sender=brain)

assert dumper.governance() == brain
assert dumper.accountant() == accountant
assert dumper.tradeFactory() == tf
assert dumper.splitToken() == asset
assert dumper.rewardTokens() == [asset]
Loading