-
Notifications
You must be signed in to change notification settings - Fork 5
Implement tBTC Bridge fees reimbursement #942
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity 0.8.24; | ||
|
||
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; | ||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
/// @title Fees Reimbursement Pool | ||
/// @notice A contract that allows the Bitcoin Depositor to reimburse fees | ||
/// for deposits. | ||
contract FeesReimbursementPool is Ownable2StepUpgradeable { | ||
using SafeERC20 for IERC20; | ||
|
||
address public tbtcToken; | ||
address public bitcoinDepositor; | ||
|
||
/// @dev Caller is not the Bitcoin Depositor contract. | ||
error CallerNotBitcoinDepositor(); | ||
|
||
/// @dev Attempted to reimburse zero amount. | ||
error ZeroAmount(); | ||
|
||
/// @custom:oz-upgrades-unsafe-allow constructor | ||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
/// @notice Initialize the fees reimbursement pool. | ||
/// @param _tbtcToken The tBTC token address. | ||
/// @param _bitcoinDepositor The bitcoin depositor address. | ||
function initialize( | ||
address _tbtcToken, | ||
address _bitcoinDepositor | ||
) external initializer { | ||
__Ownable2Step_init(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be good not calling it at all, given it does nothing, but if you want to make it more future-proof, this could make sense. |
||
__Ownable_init(msg.sender); | ||
|
||
tbtcToken = _tbtcToken; | ||
bitcoinDepositor = _bitcoinDepositor; | ||
} | ||
|
||
/// @notice Reimburse the fees. | ||
/// @param reimbursedAmount The amount to reimburse. | ||
/// @return The amount reimbursed. | ||
function reimburse(uint256 reimbursedAmount) external returns (uint256) { | ||
if (msg.sender != bitcoinDepositor) revert CallerNotBitcoinDepositor(); | ||
if (reimbursedAmount == 0) revert ZeroAmount(); | ||
|
||
uint256 availableBalance = IERC20(tbtcToken).balanceOf(address(this)); | ||
|
||
if (availableBalance < reimbursedAmount) { | ||
reimbursedAmount = availableBalance; | ||
} | ||
|
||
if (reimbursedAmount > 0) { | ||
IERC20(tbtcToken).safeTransfer(msg.sender, reimbursedAmount); | ||
} | ||
Comment on lines
+49
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there is some logic to calculate the reimbursed amount (I mean, in some cases the full amount cannot be covered), maybe we can create a view function so we can call it in SDK and use it in this function? |
||
|
||
return reimbursedAmount; | ||
} | ||
|
||
/// @notice Withdraw the tokens from the pool. | ||
/// @param to The address to withdraw to. | ||
/// @param amount The amount to withdraw. | ||
function withdraw(address to, uint256 amount) external onlyOwner { | ||
IERC20(tbtcToken).safeTransfer(to, amount); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we deploying a new
BitcoinDepositor
contract or upgrading the existing one? For this line it does not make a lot of difference as the default value is 0 but I want to understand the flow.