This repository has been archived by the owner on Mar 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BalancerUtilities.sol
56 lines (49 loc) · 2.17 KB
/
BalancerUtilities.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2023 Tokemak Foundation. All rights reserved.
pragma solidity 0.8.17;
import { IVault } from "src/interfaces/external/balancer/IVault.sol";
import { IERC20 } from "openzeppelin-contracts/token/ERC20/IERC20.sol";
library BalancerUtilities {
error BalancerVaultReentrancy();
// 400 is Balancers Vault REENTRANCY error code
bytes32 internal constant REENTRANCY_ERROR_HASH = keccak256(abi.encodeWithSignature("Error(string)", "BAL#400"));
/**
* @notice Verifies reentrancy to the Balancer Vault
* @dev Reverts if gets BAL#400 error
*/
function checkReentrancy(address balancerVault) external view {
// solhint-disable max-line-length
// https://github.com/balancer/balancer-v2-monorepo/blob/90f77293fef4b8782feae68643c745c754bac45c/pkg/pool-utils/contracts/lib/VaultReentrancyLib.sol
(, bytes memory returnData) = balancerVault.staticcall(
abi.encodeWithSelector(IVault.manageUserBalance.selector, new IVault.UserBalanceOp[](0))
);
if (keccak256(returnData) == REENTRANCY_ERROR_HASH) {
revert BalancerVaultReentrancy();
}
}
/**
* @notice Checks if a given address is Balancer Composable pool
* @dev Using the presence of a getBptIndex() fn as an indicator of pool type
*/
function isComposablePool(address pool) public view returns (bool) {
// slither-disable-start low-level-calls
// solhint-disable-next-line no-unused-vars
(bool success, bytes memory data) = pool.staticcall(abi.encodeWithSignature("getBptIndex()"));
if (success) {
return data.length > 0;
}
// slither-disable-end low-level-calls
return success;
}
/**
* @dev This helper function is a fast and cheap way to convert between IERC20[] and IAsset[] types
*/
function _convertERC20sToAddresses(IERC20[] memory tokens) internal pure returns (address[] memory assets) {
//slither-disable-start assembly
//solhint-disable-next-line no-inline-assembly
assembly {
assets := tokens
}
//slither-disable-end assembly
}
}