Skip to content

Commit a7e61c3

Browse files
committed
Make use of the library
1 parent 2a0fb7e commit a7e61c3

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

contracts/access/manager/AuthorityUtils.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pragma solidity ^0.8.20;
55

66
import {IAuthority} from "./IAuthority.sol";
7+
import {Memory} from "../../utils/Memory.sol";
78

89
library AuthorityUtils {
910
/**
@@ -17,6 +18,7 @@ library AuthorityUtils {
1718
address target,
1819
bytes4 selector
1920
) internal view returns (bool immediate, uint32 delay) {
21+
Memory.Pointer ptr = Memory.getFreePointer();
2022
(bool success, bytes memory data) = authority.staticcall(
2123
abi.encodeCall(IAuthority.canCall, (caller, target, selector))
2224
);
@@ -27,6 +29,7 @@ library AuthorityUtils {
2729
immediate = abi.decode(data, (bool));
2830
}
2931
}
32+
Memory.setFreePointer(ptr);
3033
return (immediate, delay);
3134
}
3235
}

contracts/token/ERC20/extensions/ERC4626.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {IERC20, IERC20Metadata, ERC20} from "../ERC20.sol";
77
import {SafeERC20} from "../utils/SafeERC20.sol";
88
import {IERC4626} from "../../../interfaces/IERC4626.sol";
99
import {Math} from "../../../utils/math/Math.sol";
10+
import {Memory} from "../../../utils/Memory.sol";
1011

1112
/**
1213
* @dev Implementation of the ERC-4626 "Tokenized Vault Standard" as defined in
@@ -84,6 +85,7 @@ abstract contract ERC4626 is ERC20, IERC4626 {
8485
* @dev Attempts to fetch the asset decimals. A return value of false indicates that the attempt failed in some way.
8586
*/
8687
function _tryGetAssetDecimals(IERC20 asset_) private view returns (bool, uint8) {
88+
Memory.Pointer ptr = Memory.getFreePointer();
8789
(bool success, bytes memory encodedDecimals) = address(asset_).staticcall(
8890
abi.encodeCall(IERC20Metadata.decimals, ())
8991
);
@@ -93,6 +95,7 @@ abstract contract ERC4626 is ERC20, IERC4626 {
9395
return (true, uint8(returnedDecimals));
9496
}
9597
}
98+
Memory.setFreePointer(ptr);
9699
return (false, 0);
97100
}
98101

contracts/token/ERC20/utils/SafeERC20.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pragma solidity ^0.8.20;
66
import {IERC20} from "../IERC20.sol";
77
import {IERC1363} from "../../../interfaces/IERC1363.sol";
88
import {Address} from "../../../utils/Address.sol";
9+
import {Memory} from "../../../utils/Memory.sol";
910

1011
/**
1112
* @title SafeERC20
@@ -32,15 +33,19 @@ library SafeERC20 {
3233
* non-reverting calls are assumed to be successful.
3334
*/
3435
function safeTransfer(IERC20 token, address to, uint256 value) internal {
36+
Memory.Pointer ptr = Memory.getFreePointer();
3537
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
38+
Memory.setFreePointer(ptr);
3639
}
3740

3841
/**
3942
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
4043
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
4144
*/
4245
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
46+
Memory.Pointer ptr = Memory.getFreePointer();
4347
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
48+
Memory.setFreePointer(ptr);
4449
}
4550

4651
/**
@@ -72,12 +77,14 @@ library SafeERC20 {
7277
* to be set to zero before setting it to a non-zero value, such as USDT.
7378
*/
7479
function forceApprove(IERC20 token, address spender, uint256 value) internal {
80+
Memory.Pointer ptr = Memory.getFreePointer();
7581
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
7682

7783
if (!_callOptionalReturnBool(token, approvalCall)) {
7884
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
7985
_callOptionalReturn(token, approvalCall);
8086
}
87+
Memory.setFreePointer(ptr);
8188
}
8289

8390
/**

contracts/utils/cryptography/SignatureChecker.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.8.20;
55

66
import {ECDSA} from "./ECDSA.sol";
77
import {IERC1271} from "../../interfaces/IERC1271.sol";
8+
import {Memory} from "../Memory.sol";
89

910
/**
1011
* @dev Signature verification helper that can be used instead of `ECDSA.recover` to seamlessly support both ECDSA
@@ -40,11 +41,14 @@ library SignatureChecker {
4041
bytes32 hash,
4142
bytes memory signature
4243
) internal view returns (bool) {
44+
Memory.Pointer ptr = Memory.getFreePointer();
4345
(bool success, bytes memory result) = signer.staticcall(
4446
abi.encodeCall(IERC1271.isValidSignature, (hash, signature))
4547
);
46-
return (success &&
48+
bool valid = (success &&
4749
result.length >= 32 &&
4850
abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
51+
Memory.setFreePointer(ptr);
52+
return valid;
4953
}
5054
}

0 commit comments

Comments
 (0)