Skip to content
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

General gas tweaks #57

Merged
merged 10 commits into from
May 31, 2024
2 changes: 1 addition & 1 deletion .forge-snapshots/BinHookTest#testMintSucceedsWithHook.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
331249
331216
Original file line number Diff line number Diff line change
@@ -1 +1 @@
137063
137002
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1866
1824
Original file line number Diff line number Diff line change
@@ -1 +1 @@
30417
30405
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146800
146702
Original file line number Diff line number Diff line change
@@ -1 +1 @@
294359
294281
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasBurnOneBin.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
130273
130194
2 changes: 1 addition & 1 deletion .forge-snapshots/BinPoolManagerTest#testGasDonate.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
119515
119509
Original file line number Diff line number Diff line change
@@ -1 +1 @@
976064
976097
Original file line number Diff line number Diff line change
@@ -1 +1 @@
338254
338287
Original file line number Diff line number Diff line change
@@ -1 +1 @@
341835
341796
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144778
144739
Original file line number Diff line number Diff line change
@@ -1 +1 @@
179149
179097
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185132
185080
Original file line number Diff line number Diff line change
@@ -1 +1 @@
137587
137535
Original file line number Diff line number Diff line change
@@ -1 +1 @@
308314
308275
Original file line number Diff line number Diff line change
@@ -1 +1 @@
360107
360023
Original file line number Diff line number Diff line change
@@ -1 +1 @@
175275
175191
Original file line number Diff line number Diff line change
@@ -1 +1 @@
245216
245111
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#donateBothTokens.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
168619
168607
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#gasDonateOneToken.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
112426
112417
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121370
121271
Original file line number Diff line number Diff line change
@@ -1 +1 @@
138739
137753
Original file line number Diff line number Diff line change
@@ -1 +1 @@
172226
170905
Original file line number Diff line number Diff line change
@@ -1 +1 @@
158653
157667
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_simple.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76594
76212
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150915
149916
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withHooks.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
93486
93104
2 changes: 1 addition & 1 deletion .forge-snapshots/CLPoolManagerTest#swap_withNative.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76597
76215
Original file line number Diff line number Diff line change
@@ -1 +1 @@
32316
32304
2 changes: 1 addition & 1 deletion .forge-snapshots/ExtsloadTest#extsload.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7446
7404
2 changes: 1 addition & 1 deletion .forge-snapshots/ExtsloadTest#extsloadInBatch.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11394
10654
Original file line number Diff line number Diff line change
@@ -1 +1 @@
516
502
Original file line number Diff line number Diff line change
@@ -1 +1 @@
665
651
Original file line number Diff line number Diff line change
@@ -1 +1 @@
594
520
Original file line number Diff line number Diff line change
@@ -1 +1 @@
776
724
Original file line number Diff line number Diff line change
@@ -1 +1 @@
878
759
Original file line number Diff line number Diff line change
@@ -1 +1 @@
468
398
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2234
1942
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3019
2697
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1976
1692
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3019
2697
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2224
1911
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3177
2831
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1966
1661
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3177
2831
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#Vault.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7181
7124
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#collectFee.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
25187
25138
Original file line number Diff line number Diff line change
@@ -1 +1 @@
81469
81463
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenFlashloan.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
121465
121269
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45057
45005
2 changes: 1 addition & 1 deletion .forge-snapshots/VaultTest#lockSettledWhenSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45056
45004
36 changes: 24 additions & 12 deletions src/Extsload.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,34 @@ import {IExtsload} from "./interfaces/IExtsload.sol";
/// @notice Allows the inheriting contract make it's state accessable to other contracts
/// https://ethereum-magicians.org/t/extsload-opcode-proposal/2410/11
abstract contract Extsload is IExtsload {
function extsload(bytes32 slot) external view returns (bytes32 val) {
assembly {
val := sload(slot)
/// @inheritdoc IExtsload
function extsload(bytes32 slot) external view returns (bytes32) {
assembly ("memory-safe") {
mstore(0, sload(slot))
return(0, 0x20)
}
}

function extsload(bytes32[] memory slots) external view returns (bytes32[] memory) {
assembly {
let end := add(0x20, add(slots, mul(mload(slots), 0x20)))
for { let pointer := add(slots, 32) } lt(pointer, end) {} {
let value := sload(mload(pointer))
mstore(pointer, value)
pointer := add(pointer, 0x20)
/// @inheritdoc IExtsload
function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory) {
// since the function is external and enters a new call context and exits right
// after execution, Solidity's memory management convention can be disregarded
// and a direct slice of memory can be returned
assembly ("memory-safe") {
// Copy the abi offset of dynamic array and the length of the array to memory.
calldatacopy(0, 0x04, 0x40)
// A left bit-shift of 5 is equivalent to multiplying by 32 but costs less gas.
let end := add(0x40, shl(5, slots.length))
let calldataptr := slots.offset
// Return values will start at 64 while calldata offset is 68.
for { let memptr := 0x40 } 1 {} {
mstore(memptr, sload(calldataload(calldataptr)))
memptr := add(memptr, 0x20)
calldataptr := add(calldataptr, 0x20)
if iszero(lt(memptr, end)) { break }
}
// The end offset is also the length of the returndata.
return(0, end)
}

return slots;
}
}
2 changes: 1 addition & 1 deletion src/ProtocolFees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract contract ProtocolFees is IProtocolFees, PausableRole {
if (gasleft() < controllerGasLimit) revert ProtocolFeeCannotBeFetched();

(bool _success, bytes memory _data) = address(protocolFeeController).call{gas: controllerGasLimit}(
abi.encodeWithSelector(IProtocolFeeController.protocolFeeForPool.selector, key)
abi.encodeCall(IProtocolFeeController.protocolFeeForPool, (key))
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh i never used encodeCall before 😂.. Just in case someone is with me

CleanShot 2024-05-31 at 10 09 42@2x

https://soliditylang.org/blog/2021/12/20/solidity-0.8.11-release-announcement/

// Ensure that the return data fits within a word
if (!_success || _data.length > 32) return (false, 0);
Expand Down
15 changes: 7 additions & 8 deletions src/interfaces/IExtsload.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/// @title This is an interface to read contract's state that supports extsload.
interface IExtsload {
/// @notice Returns a value from the storage.
/// @param slot to read from.
/// @return value stored at the slot.
/// @notice Called by external contracts to access granular pool state
/// @param slot Key of slot to sload
/// @return value The value of the slot as bytes32
function extsload(bytes32 slot) external view returns (bytes32 value);

/// @notice Returns multiple values from storage.
/// @param slots to read from.
/// @return values stored at the slots.
function extsload(bytes32[] memory slots) external view returns (bytes32[] memory);
/// @notice Called by external contracts to access sparse pool state
/// @param slots List of slots to SLOAD from.
/// @return values List of loaded values.
function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory values);
}
Loading
Loading