Skip to content

Commit

Permalink
test: coverage for SuccinctFeeVault (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam authored Nov 7, 2023
1 parent 598e609 commit 14ac0e5
Show file tree
Hide file tree
Showing 3 changed files with 671 additions and 27 deletions.
20 changes: 8 additions & 12 deletions contracts/src/payments/SuccinctFeeVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.16;
import {IFeeVault} from "./interfaces/IFeeVault.sol";
import {TimelockedUpgradeable} from "../upgrades/TimelockedUpgradeable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/// @title SuccinctFeeVault
/// @author Succinct Labs
Expand All @@ -18,24 +19,15 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// make a bulk deposit.
/// @dev Address(0) is used to represent native currency in places where token address is specified.
contract SuccinctFeeVault is IFeeVault, TimelockedUpgradeable {
using SafeERC20 for IERC20;

/// @notice Tracks the amount of active balance that an account has for Succinct services.
/// @dev balances[token][account] returns the amount of balance for token the account has. To
/// check native currency balance, use address(0) as the token address.
mapping(address => mapping(address => uint256)) public balances;
/// @notice The allowed senders for the deduct functions.
mapping(address => bool) public allowedDeductors;

event Received(address indexed account, address indexed token, uint256 amount);
event Deducted(address indexed account, address indexed token, uint256 amount);
event Collected(address indexed to, address indexed token, uint256 amount);

error InvalidAccount(address account);
error InvalidToken(address token);
error InsufficentAllowance(address token, uint256 amount);
error InsufficientBalance(address token, uint256 amount);
error FailedToSendNative(uint256 amount);
error OnlyDeductor(address sender);

modifier onlyDeductor() {
if (!allowedDeductors[msg.sender]) {
revert OnlyDeductor(msg.sender);
Expand Down Expand Up @@ -94,7 +86,7 @@ contract SuccinctFeeVault is IFeeVault, TimelockedUpgradeable {
revert InsufficentAllowance(_token, _amount);
}

token.transferFrom(msg.sender, address(this), _amount);
token.safeTransferFrom(msg.sender, address(this), _amount);
balances[_token][_account] += _amount;

emit Received(_account, _token, _amount);
Expand Down Expand Up @@ -168,4 +160,8 @@ contract SuccinctFeeVault is IFeeVault, TimelockedUpgradeable {

emit Collected(_to, _token, _amount);
}

/// @dev This empty reserved space to add new variables without shifting down storage.
/// See: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
uint256[50] private __gap;
}
31 changes: 16 additions & 15 deletions contracts/src/payments/interfaces/IFeeVault.sol
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;

interface IFeeVault {
/// @notice Returns the amount of active balance that an account has.
/// @param token The address of the token to check the balance of. To check native currency
/// balance, use address(0) as the token address.
/// @param account The address of the account to check the balance of.
function balances(address token, address account) external view returns (uint256);
interface IFeeVaultEvents {
event Received(address indexed account, address indexed token, uint256 amount);
event Deducted(address indexed account, address indexed token, uint256 amount);
event Collected(address indexed to, address indexed token, uint256 amount);
}

/// @notice Deposit the specified amount of native currency from the caller.
/// @dev The native currency is represented by address(0) in balances.
/// @param account The account to deposit the native currency for.
function depositNative(address account) external payable;
interface IFeeVaultErrors {
error InvalidAccount(address account);
error InvalidToken(address token);
error InsufficentAllowance(address token, uint256 amount);
error InsufficientBalance(address token, uint256 amount);
error FailedToSendNative(uint256 amount);
error OnlyDeductor(address sender);
}

/// @notice Deposit the specified amount of the specified token from the caller.
/// @dev MUST approve this contract to spend at least `amount` of `token` before calling this.
/// @param account The account to deposit the tokens to.
/// @param token The address of the token to deposit.
/// @param amount The amount of the token to deposit.
interface IFeeVault is IFeeVaultEvents, IFeeVaultErrors {
function balances(address token, address account) external view returns (uint256);
function depositNative(address account) external payable;
function deposit(address account, address token, uint256 amount) external;
}
Loading

0 comments on commit 14ac0e5

Please sign in to comment.