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

TokenPaymaster (0.7, Adjusted) #660

Merged
merged 6 commits into from
Oct 28, 2024
Merged

Conversation

0xFirekeeper
Copy link
Member

Uniswap + Oracle based single ERC20 Paymaster for runtime sponsorship, compatible with sdks

Uniswap + Oracle based single ERC20 Paymaster for runtime sponsorship, compatible with sdks
abstract contract BasePaymaster is IPaymaster, Ownable {
IEntryPoint public immutable entryPoint;

uint256 internal constant PAYMASTER_VALIDATION_GAS_OFFSET = UserOperationLib.PAYMASTER_VALIDATION_GAS_OFFSET;

Check warning

Code scanning / Slither

Unused state variable Warning

IEntryPoint public immutable entryPoint;

uint256 internal constant PAYMASTER_VALIDATION_GAS_OFFSET = UserOperationLib.PAYMASTER_VALIDATION_GAS_OFFSET;
uint256 internal constant PAYMASTER_POSTOP_GAS_OFFSET = UserOperationLib.PAYMASTER_POSTOP_GAS_OFFSET;

Check warning

Code scanning / Slither

Unused state variable Warning

contracts/prebuilts/account/token-paymaster/TokenPaymaster.sol Dismissed Show dismissed Hide dismissed
TokenPaymasterConfig memory _tokenPaymasterConfig,
OracleHelperConfig memory _oracleHelperConfig,
UniswapHelperConfig memory _uniswapHelperConfig,
address _owner
Comment on lines 133 to 157
function calculatePrice(
uint256 tokenPrice,
uint256 nativeAssetPrice,
bool tokenOracleReverse,
bool nativeOracleReverse
) private view returns (uint256){
// tokenPrice is normalized as bridging-asset-per-token
if (tokenOracleReverse) {
// inverting tokenPrice that was tokens-per-bridging-asset (or tokens-per-native-asset)
tokenPrice = PRICE_DENOMINATOR * tokenOracleDecimalPower / tokenPrice;
} else {
// tokenPrice already bridging-asset-per-token (or native-asset-per-token)
tokenPrice = PRICE_DENOMINATOR * tokenPrice / tokenOracleDecimalPower;
}

if (nativeOracleReverse) {
// multiplying by nativeAssetPrice that is native-asset-per-bridging-asset
// => result = (bridging-asset / token) * (native-asset / bridging-asset) = native-asset / token
return nativeAssetPrice * tokenPrice / nativeOracleDecimalPower;
} else {
// dividing by nativeAssetPrice that is bridging-asset-per-native-asset
// => result = (bridging-asset / token) / (bridging-asset / native-asset) = native-asset / token
return tokenPrice * nativeOracleDecimalPower / nativeAssetPrice;
}
}

Check warning

Code scanning / Slither

Divide before multiply Medium

Comment on lines 133 to 157
function calculatePrice(
uint256 tokenPrice,
uint256 nativeAssetPrice,
bool tokenOracleReverse,
bool nativeOracleReverse
) private view returns (uint256){
// tokenPrice is normalized as bridging-asset-per-token
if (tokenOracleReverse) {
// inverting tokenPrice that was tokens-per-bridging-asset (or tokens-per-native-asset)
tokenPrice = PRICE_DENOMINATOR * tokenOracleDecimalPower / tokenPrice;
} else {
// tokenPrice already bridging-asset-per-token (or native-asset-per-token)
tokenPrice = PRICE_DENOMINATOR * tokenPrice / tokenOracleDecimalPower;
}

if (nativeOracleReverse) {
// multiplying by nativeAssetPrice that is native-asset-per-bridging-asset
// => result = (bridging-asset / token) * (native-asset / bridging-asset) = native-asset / token
return nativeAssetPrice * tokenPrice / nativeOracleDecimalPower;
} else {
// dividing by nativeAssetPrice that is bridging-asset-per-native-asset
// => result = (bridging-asset / token) / (bridging-asset / native-asset) = native-asset / token
return tokenPrice * nativeOracleDecimalPower / nativeAssetPrice;
}
}

Check warning

Code scanning / Slither

Divide before multiply Medium

Comment on lines 163 to 169
function fetchPrice(IOracle _oracle) internal view returns (uint256 price) {
(uint80 roundId, int256 answer,, uint256 updatedAt, uint80 answeredInRound) = _oracle.latestRoundData();
require(answer > 0, "TPM: Chainlink price <= 0");
require(updatedAt >= block.timestamp - oracleHelperConfig.maxOracleRoundAge, "TPM: Incomplete round");
require(answeredInRound >= roundId, "TPM: Stale price");
price = uint256(answer);
}

Check warning

Code scanning / Slither

Unused return Medium

Comment on lines +87 to +110
function swapToToken(
address tokenIn,
address tokenOut,
uint256 amountIn,
uint256 amountOutMin,
uint24 fee
) internal returns (uint256 amountOut) {
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams(
tokenIn, //tokenIn
tokenOut, //tokenOut
fee,
address(uniswap),
block.timestamp, //deadline
amountIn,
amountOutMin,
0
);
try uniswap.exactInputSingle(params) returns (uint256 _amountOut) {
amountOut = _amountOut;
} catch {
emit UniswapReverted(tokenIn, tokenOut, amountIn, amountOutMin);
amountOut = 0;
}
}

Check notice

Code scanning / Slither

Reentrancy vulnerabilities Low

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 66.12903% with 42 lines in your changes missing coverage. Please review.

Project coverage is 65.50%. Comparing base (2104a1a) to head (934707d).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...ontracts/prebuilts/account/utils/UniswapHelper.sol 33.33% 14 Missing ⚠️
...ebuilts/account/token-paymaster/TokenPaymaster.sol 73.33% 12 Missing ⚠️
contracts/prebuilts/account/utils/OracleHelper.sol 76.74% 10 Missing ⚠️
...rebuilts/account/token-paymaster/BasePaymaster.sol 60.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #660      +/-   ##
==========================================
- Coverage   66.21%   65.50%   -0.72%     
==========================================
  Files         220      225       +5     
  Lines        6900     7528     +628     
==========================================
+ Hits         4569     4931     +362     
- Misses       2331     2597     +266     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kumaryash90 kumaryash90 merged commit cf51bfa into main Oct 28, 2024
9 checks passed
@kumaryash90 kumaryash90 deleted the firekeeper/tokenpaymaster-0.7 branch October 28, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants