-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from sanbir/deoracleized
Deoracleized
- Loading branch information
Showing
8 changed files
with
481 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-FileCopyrightText: 2024 P2P Validator <info@p2p.org> | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.24; | ||
|
||
import "../@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||
import "../@openzeppelin/contracts/utils/introspection/ERC165.sol"; | ||
import "../@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; | ||
import "../feeDistributorFactory/IFeeDistributorFactory.sol"; | ||
import "../assetRecovering/OwnableTokenRecoverer.sol"; | ||
import "./IFeeDistributor.sol"; | ||
import "../structs/P2pStructs.sol"; | ||
import "./BaseFeeDistributor.sol"; | ||
|
||
/// @title FeeDistributor | ||
contract DeoracleizedFeeDistributor is BaseFeeDistributor { | ||
/// @dev Set values that are constant, common for all the clients, known at the initial deploy time. | ||
/// @param _factory address of FeeDistributorFactory | ||
/// @param _service address of the service (P2P) fee recipient | ||
constructor( | ||
address _factory, | ||
address payable _service | ||
) BaseFeeDistributor(_factory, _service) {} | ||
|
||
/// @notice Withdraw | ||
function withdraw(Withdrawal calldata _withdrawal) external nonReentrant { | ||
i_factory.checkOperatorOrOwner(msg.sender); | ||
|
||
if (s_clientConfig.recipient == address(0)) { | ||
revert FeeDistributor__ClientNotSet(); | ||
} | ||
|
||
if (address(this).balance == 0) { | ||
// revert if there is no ether to withdraw | ||
revert FeeDistributor__NothingToWithdraw(); | ||
} | ||
|
||
uint256 clientAmount = uint256(_withdrawal.clientAmount); | ||
uint256 serviceAmount = uint256(_withdrawal.serviceAmount); | ||
uint256 referrerAmount = uint256(_withdrawal.referrerAmount); | ||
|
||
if ( | ||
clientAmount + serviceAmount + referrerAmount > | ||
address(this).balance | ||
) { | ||
revert FeeDistributor__AmountsExceedBalance(); | ||
} | ||
|
||
if (clientAmount + serviceAmount + referrerAmount == 0) { | ||
revert FeeDistributor__AmountsAreZero(); | ||
} | ||
|
||
if (referrerAmount > 0) { | ||
if (s_referrerConfig.recipient != address(0)) { | ||
// if there is a referrer | ||
|
||
// Send ETH to referrer. Ignore the possible yet unlikely revert in the receive function. | ||
P2pAddressLib._sendValue( | ||
s_referrerConfig.recipient, | ||
referrerAmount | ||
); | ||
} else { | ||
revert FeeDistributor__ReferrerNotSet(); | ||
} | ||
} | ||
|
||
if (serviceAmount > 0) { | ||
// Send ETH to service. Ignore the possible yet unlikely revert in the receive function. | ||
P2pAddressLib._sendValue(i_service, serviceAmount); | ||
} | ||
|
||
if (clientAmount > 0) { | ||
// Send ETH to client. Ignore the possible yet unlikely revert in the receive function. | ||
P2pAddressLib._sendValue(s_clientConfig.recipient, clientAmount); | ||
} | ||
|
||
emit FeeDistributor__Withdrawn( | ||
serviceAmount, | ||
clientAmount, | ||
referrerAmount | ||
); | ||
} | ||
|
||
/// @inheritdoc Erc4337Account | ||
function withdrawSelector() public pure override returns (bytes4) { | ||
return DeoracleizedFeeDistributor.withdraw.selector; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
7a70df6
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.
@check-spelling-bot Report
🔴 Please review
See the 📜action log or 📝 job summary for details.
Unrecognized words (4)
Bbf
cancun
deoracleized
xec
These words are not needed and should be removed
aae aaf ada adaefbe aecded aefb afdcab afe Bbbd bfbe BFF cafec cbb cdd cfe dcc dcdd dda DEAE debd deca ded ecca EFBA fca fccdea Fcd fdf fea fffebe hex'a hex'adfdd hex'bTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands
... in a clone of the git@github.com:p2p-org/eth-staking-fee-distributor-contracts.git repository
on the
master
branch (ℹ️ how do I use this?):Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary
This includes both expected items (76) from .github/actions/spelling/expect.txt and unrecognized words (4)
Consider adding them (in
.github/workflows/spelling.yml
) injobs:
/spelling:
foruses: check-spelling/check-spelling@main
in itswith
:To stop checking additional dictionaries, add (in
.github/workflows/spelling.yml
) foruses: check-spelling/check-spelling@main
in itswith
:If the flagged items are false positives
If items relate to a ...
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txt
file matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^
refers to the file's path from the root of the repository, so^README\.md$
would exclude README.md (on whichever branch you're using).well-formed pattern.
If you can write a pattern that would match it,
try adding it to the
patterns.txt
file.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.