- Protocol Agnositic approach to token rate limiting
- Performant Codebase
- Easy integration
- Multiple tokens supports with custom withdrawal rate limits and periods for each token.
- Records inflows/outflows of token and maintains a Historical Oracle of the protocol's token Liquidity.
- Enforces withdrawal limits and periods to prevent excessive fund withdrawals (hack prevention).
- Allows the contract owner to register tokens, override limits, and transfer admin privileges.
- Provides a convenient function for guarded contracts to record inflows and withdraw available funds.
forge test
forge coverage
File | % Lines | % Statements | % Branches | % Funcs |
---|---|---|---|---|
src/Guardian.sol | 100.00% (89/89) | 100.00% (99/99) | 85.29% (29/34) | 93.33% (14/15) |
src/MockDeFiProtocol.sol | 100.00% (5/5) | 100.00% (5/5) | 100.00% (0/0) | 100.00% (3/3) |
src/MockToken.sol | 100.00% (2/2) | 100.00% (2/2) | 100.00% (0/0) | 100.00% (2/2) |
Total | 100.00% (96/96) | 100.00% (106/106) | 85.29% (29/34) | 95.00% (19/20) |
There are three easy points of integration that you must do to have your protocol guardian properly set up.
- Onboard Token Logic
- Deposit Token integration
- Withdraw Token integration
- Set the Contract as a guarded contract on your Guardian
contract MockDeFi {
using SafeERC20 for IERC20;
IGuardian guardian;
function setGuardian(address _guardian) external {
guardian = IGuardian(_guardian);
}
function deposit(address token, uint256 amount) external {
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
guardian.recordInflow(token, amount);
}
function withdraw(address token, uint256 amount) external {
IERC20(token).safeTransfer(address(guardian), amount);
guardian.withdraw(token, amount, msg.sender);
}
}
The smart contract is licensed under the UNLICENSED license.
Note: The provided smart contract is a simplified example and might not cover all security considerations and edge cases. It is always recommended to conduct a thorough security review and testing before deploying any smart contract in a production environment.