-
Notifications
You must be signed in to change notification settings - Fork 947
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
gas limit as percentage #861
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
59963 | ||
60018 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
23925 | ||
23914 |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ import {IProtocolFeeController} from "./interfaces/IProtocolFeeController.sol"; | |
import {IProtocolFees} from "./interfaces/IProtocolFees.sol"; | ||
import {PoolKey} from "./types/PoolKey.sol"; | ||
import {ProtocolFeeLibrary} from "./libraries/ProtocolFeeLibrary.sol"; | ||
import {BipsLibrary} from "./libraries/BipsLibrary.sol"; | ||
import {Owned} from "solmate/src/auth/Owned.sol"; | ||
import {PoolId, PoolIdLibrary} from "./types/PoolId.sol"; | ||
import {Pool} from "./libraries/Pool.sol"; | ||
|
@@ -17,18 +18,19 @@ abstract contract ProtocolFees is IProtocolFees, Owned { | |
using PoolIdLibrary for PoolKey; | ||
using Pool for Pool.State; | ||
using CustomRevert for bytes4; | ||
using BipsLibrary for uint256; | ||
|
||
/// @inheritdoc IProtocolFees | ||
mapping(Currency currency => uint256 amount) public protocolFeesAccrued; | ||
|
||
/// @inheritdoc IProtocolFees | ||
IProtocolFeeController public protocolFeeController; | ||
|
||
uint256 private immutable controllerGasLimit; | ||
// a percentage of the block.gaslimit denoted in basis points, used as the gas limit for fee controller calls | ||
// 100 bps is 1%, at 30M gas, the limit is 300K | ||
uint256 private constant BLOCK_LIMIT_BPS = 100; | ||
|
||
constructor(uint256 _controllerGasLimit) Owned(msg.sender) { | ||
controllerGasLimit = _controllerGasLimit; | ||
} | ||
constructor() Owned(msg.sender) {} | ||
Comment on lines
-28
to
+32
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. *happy noises* |
||
|
||
/// @inheritdoc IProtocolFees | ||
function setProtocolFeeController(IProtocolFeeController controller) external onlyOwner { | ||
|
@@ -67,12 +69,13 @@ abstract contract ProtocolFees is IProtocolFees, Owned { | |
/// the success of this function is NOT checked on initialize and if the call fails, the protocol fees are set to 0. | ||
function _fetchProtocolFee(PoolKey memory key) internal returns (uint24 protocolFee) { | ||
if (address(protocolFeeController) != address(0)) { | ||
uint256 controllerGasLimit = block.gaslimit.calculatePortion(BLOCK_LIMIT_BPS); | ||
|
||
// note that EIP-150 mandates that calls requesting more than 63/64ths of remaining gas | ||
// will be allotted no more than this amount, so controllerGasLimit must be set with this | ||
// in mind. | ||
if (gasleft() < controllerGasLimit) ProtocolFeeCannotBeFetched.selector.revertWith(); | ||
|
||
uint256 gasLimit = controllerGasLimit; | ||
address toAddress = address(protocolFeeController); | ||
|
||
bytes memory data = abi.encodeCall(IProtocolFeeController.protocolFeeForPool, (key)); | ||
|
@@ -81,7 +84,7 @@ abstract contract ProtocolFees is IProtocolFees, Owned { | |
uint256 returnData; | ||
assembly ("memory-safe") { | ||
// only load the first 32 bytes of the return data to prevent gas griefing | ||
success := call(gasLimit, toAddress, 0, add(data, 0x20), mload(data), 0, 32) | ||
success := call(controllerGasLimit, toAddress, 0, add(data, 0x20), mload(data), 0, 32) | ||
// if success is false this wont actually be returned, instead 0 will be returned | ||
returnData := mload(0) | ||
|
||
|
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,17 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
pragma solidity ^0.8.0; | ||
|
||
/// @title For calculating a percentage of an amount, using bips | ||
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. This is copied across from periphery now that its been audited. |
||
library BipsLibrary { | ||
uint256 internal constant BPS_DENOMINATOR = 10_000; | ||
|
||
/// @notice emitted when an invalid percentage is provided | ||
error InvalidBips(); | ||
|
||
/// @param amount The total amount to calculate a percentage of | ||
/// @param bips The percentage to calculate, in bips | ||
function calculatePortion(uint256 amount, uint256 bips) internal pure returns (uint256) { | ||
if (bips > BPS_DENOMINATOR) revert InvalidBips(); | ||
return (amount * bips) / BPS_DENOMINATOR; | ||
} | ||
} |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 fine with this number?
This is what we use for subscribers on periphery?
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.
yeah it seemed reasonable here too. 300k would be a lotttttttt. arguably id be happy to go with smaller lol