From 607df8848bb8309774476bf718b9aa6ecb5e2bcb Mon Sep 17 00:00:00 2001 From: Facu Spagnuolo Date: Sat, 29 Jul 2023 16:17:59 +0200 Subject: [PATCH 1/2] tasks: order base task methods --- packages/tasks/contracts/base/BaseTask.sol | 70 +++++++++++----------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/packages/tasks/contracts/base/BaseTask.sol b/packages/tasks/contracts/base/BaseTask.sol index 9a7d2b40..c84db4a3 100644 --- a/packages/tasks/contracts/base/BaseTask.sol +++ b/packages/tasks/contracts/base/BaseTask.sol @@ -94,6 +94,41 @@ abstract contract BaseTask is IBaseTask, Authorized { _setBalanceConnectors(previous, next); } + /** + * @dev Tells the wrapped native token address if the given address is the native token + * @param token Address of the token to be checked + */ + function _wrappedIfNative(address token) internal view returns (address) { + return Denominations.isNativeToken(token) ? _wrappedNativeToken() : token; + } + + /** + * @dev Tells whether a token is the native or the wrapped native token + */ + function _isWrappedOrNative(address token) internal view returns (bool) { + return Denominations.isNativeToken(token) || token == _wrappedNativeToken(); + } + + /** + * @dev Tells the wrapped native token address + */ + function _wrappedNativeToken() internal view returns (address) { + return ISmartVault(smartVault).wrappedNativeToken(); + } + + /** + * @dev Fetches a base/quote price from the smart vault's price oracle + */ + function _getPrice(address base, address quote) internal view virtual returns (uint256) { + address priceOracle = ISmartVault(smartVault).priceOracle(); + if (priceOracle == address(0)) revert TaskSmartVaultPriceOracleNotSet(smartVault); + bytes memory extraCallData = _decodeExtraCallData(); + return + extraCallData.length == 0 + ? IPriceOracle(priceOracle).getPrice(_wrappedIfNative(base), _wrappedIfNative(quote)) + : IPriceOracle(priceOracle).getPrice(_wrappedIfNative(base), _wrappedIfNative(quote), extraCallData); + } + /** * @dev Before base task hook */ @@ -142,41 +177,6 @@ abstract contract BaseTask is IBaseTask, Authorized { emit BalanceConnectorsSet(previous, next); } - /** - * @dev Fetches a base/quote price from the smart vault's price oracle - */ - function _getPrice(address base, address quote) internal view virtual returns (uint256) { - address priceOracle = ISmartVault(smartVault).priceOracle(); - if (priceOracle == address(0)) revert TaskSmartVaultPriceOracleNotSet(smartVault); - bytes memory extraCallData = _decodeExtraCallData(); - return - extraCallData.length == 0 - ? IPriceOracle(priceOracle).getPrice(_wrappedIfNative(base), _wrappedIfNative(quote)) - : IPriceOracle(priceOracle).getPrice(_wrappedIfNative(base), _wrappedIfNative(quote), extraCallData); - } - - /** - * @dev Tells the wrapped native token address if the given address is the native token - * @param token Address of the token to be checked - */ - function _wrappedIfNative(address token) internal view returns (address) { - return Denominations.isNativeToken(token) ? _wrappedNativeToken() : token; - } - - /** - * @dev Tells whether a token is the native or the wrapped native token - */ - function _isWrappedOrNative(address token) internal view returns (bool) { - return Denominations.isNativeToken(token) || token == _wrappedNativeToken(); - } - - /** - * @dev Tells the wrapped native token address - */ - function _wrappedNativeToken() internal view returns (address) { - return ISmartVault(smartVault).wrappedNativeToken(); - } - /** * @dev Decodes any potential extra calldata stored in the calldata space. Tasks relying on the extra calldata * pattern, assume that the last word of the calldata stores the extra calldata length so it can be decoded. Note From 9aec2ef65bfc52453205e48a4bcb9ebd79ab7b5a Mon Sep 17 00:00:00 2001 From: Facu Spagnuolo Date: Mon, 31 Jul 2023 11:41:35 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: lgalende <63872655+lgalende@users.noreply.github.com> --- packages/tasks/contracts/base/BaseTask.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/tasks/contracts/base/BaseTask.sol b/packages/tasks/contracts/base/BaseTask.sol index c84db4a3..2b49dacb 100644 --- a/packages/tasks/contracts/base/BaseTask.sol +++ b/packages/tasks/contracts/base/BaseTask.sol @@ -104,6 +104,7 @@ abstract contract BaseTask is IBaseTask, Authorized { /** * @dev Tells whether a token is the native or the wrapped native token + * @param token Address of the token to be checked */ function _isWrappedOrNative(address token) internal view returns (bool) { return Denominations.isNativeToken(token) || token == _wrappedNativeToken(); @@ -118,6 +119,8 @@ abstract contract BaseTask is IBaseTask, Authorized { /** * @dev Fetches a base/quote price from the smart vault's price oracle + * @param base Token to rate + * @param quote Token used for the price rate */ function _getPrice(address base, address quote) internal view virtual returns (uint256) { address priceOracle = ISmartVault(smartVault).priceOracle();