that next code compiled successfully? Here coder use ternary operation to choose function that should be called with follow parameters.
(request.tokenOut == _mainToken ? LinearMath._calcMainOutPerBptIn : LinearMath._calcWrappedOutPerBptIn)(
request.amount,
balances[_mainIndex],
balances[_wrappedIndex],
_getApproximateVirtualSupply(balances[_bptIndex]),
params
);
https://github.com/balancer-labs/balancer-v2-monorepo/blob/master/pkg/pool-linear/contracts/LinearPool.sol#L276-L282
found extra example library MathLib { function _a(uint256 val) internal pure returns (uint256 res){ res = val * 2; } function _b(uint256 val) internal pure returns (uint256 res){ res = val / 2; } function _c(uint256 val) internal pure returns ( function(uint256) returns (uint256) ){ if(val == 100) return _a; return _b; } } Does anyone have reference for documentation where explained that function can returns another function?
found docs for "function type". If anyone intrested in callbacks https://docs.soliditylang.org/en/latest/types.html#function-types
Обсуждают сегодня