Skip to content

Commit

Permalink
tasks: order base task methods
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Jul 29, 2023
1 parent 10d593d commit e8774c9
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions packages/tasks/contracts/base/BaseTask.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e8774c9

Please sign in to comment.