Skip to content

Commit

Permalink
feat: dust collector
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Aug 9, 2024
1 parent 6ab31cb commit 0c420d2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/contracts/EBORequestCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ pragma solidity 0.8.26;

import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import {Arbitrable} from 'contracts/Arbitrable.sol';
import {IEBORequestCreator, IOracle} from 'interfaces/IEBORequestCreator.sol';
import {IEBORequestCreator, IERC20, IOracle} from 'interfaces/IEBORequestCreator.sol';

contract EBORequestCreator is IEBORequestCreator, Arbitrable {
using EnumerableSet for EnumerableSet.Bytes32Set;
using SafeERC20 for IERC20;

/// @inheritdoc IEBORequestCreator
IOracle public oracle;
Expand Down Expand Up @@ -129,6 +131,14 @@ contract EBORequestCreator is IEBORequestCreator, Arbitrable {
emit FinalityModuleDataSet(_finalityModule, _finalityModuleData);
}

/// @inheritdoc IEBORequestCreator
function dustCollector(IERC20 _token, address _to) external onlyCouncil {
uint256 _amount = _token.balanceOf(address(this));
_token.safeTransfer(_to, _amount);

emit DustCollected(_token, _to, _amount);
}

/**
* @notice Encodes the chain id
* @dev The chain id is hashed to have a enumerable set to avoid duplicates
Expand Down
16 changes: 16 additions & 0 deletions src/interfaces/IEBORequestCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.26;

import {IOracle} from '@defi-wonderland/prophet-core/solidity/interfaces/IOracle.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

interface IEBORequestCreator {
/*///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -63,6 +64,14 @@ interface IEBORequestCreator {
*/
event FinalityModuleDataSet(address indexed _finalityModule, bytes _finalityModuleData);

/**
* @notice Emitted when the dust is collected
* @param _token The token collected
* @param _to The address to send the dust
* @param _amount The amount collected
*/
event DustCollected(IERC20 indexed _token, address indexed _to, uint256 _amount);

/*///////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -175,4 +184,11 @@ interface IEBORequestCreator {
* @param _finalityModuleData The finality module data
*/
function setFinalityModuleData(address _finalityModule, bytes calldata _finalityModuleData) external;

/**
* @notice Collect the dust
* @param _token The token to collect
* @param _to The address to send the dust
*/
function dustCollector(IERC20 _token, address _to) external;
}
32 changes: 31 additions & 1 deletion test/unit/EBORequestCreator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.26;

import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';

import {EBORequestCreator, IEBORequestCreator, IOracle} from 'contracts/EBORequestCreator.sol';
import {EBORequestCreator, IEBORequestCreator, IERC20, IOracle, SafeERC20} from 'contracts/EBORequestCreator.sol';

Check warning on line 6 in test/unit/EBORequestCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "SafeERC20" is unused
import {IArbitrable} from 'interfaces/IArbitrable.sol';

import {Test} from 'forge-std/Test.sol';
Expand Down Expand Up @@ -34,6 +34,7 @@ abstract contract EBORequestCreator_Unit_BaseTest is Test {
event DisputeModuleDataSet(address indexed _disputeModule, bytes _disputeModuleData);
event ResolutionModuleDataSet(address indexed _resolutionModule, bytes _resolutionModuleData);
event FinalityModuleDataSet(address indexed _finalityModule, bytes _finalityModuleData);
event DustCollected(IERC20 indexed _token, address indexed _to, uint256 _amount);

/// Contracts
EBORequestCreatorForTest public eboRequestCreator;
Expand Down Expand Up @@ -342,3 +343,32 @@ contract EBORequestCreator_Unit_SetFinalityModuleData is EBORequestCreator_Unit_
eboRequestCreator.setFinalityModuleData(_finalityModule, _finalityModuleData);
}
}

contract EBORequestCreator_Unit_DustCollector is EBORequestCreator_Unit_BaseTest {
/**
* @notice Test the revert if the caller is not the council
*/
function test_revertIfNotCouncil(IERC20 _token, address _to) external {
vm.expectRevert(abi.encodeWithSelector(IArbitrable.Arbitrable_OnlyCouncil.selector));
eboRequestCreator.dustCollector(_token, _to);
}

/**
* @notice Test the emit dust collected
*/
function test_emitDustCollected(IERC20 _token, address _to, uint256 _amount) external {
vm.expectEmit();
emit DustCollected(_token, _to, _amount);

vm.mockCall(
address(_token),
abi.encodeWithSelector(IERC20.balanceOf.selector, address(eboRequestCreator)),
abi.encode(_amount)
);

vm.mockCall(address(_token), abi.encodeWithSelector(IERC20.transfer.selector, _to, _amount), abi.encode(true));

vm.prank(council);
eboRequestCreator.dustCollector(_token, _to);
}
}

0 comments on commit 0c420d2

Please sign in to comment.