Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tasks: Order base task methods #89

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 38 additions & 35 deletions packages/tasks/contracts/base/BaseTask.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,44 @@ 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
facuspagnuolo marked this conversation as resolved.
Show resolved Hide resolved
* @param token Address of the token to be checked
*/
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
facuspagnuolo marked this conversation as resolved.
Show resolved Hide resolved
* @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();
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 +180,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
Loading