Skip to content

Commit

Permalink
check fee
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Nov 28, 2024
1 parent 1a26c3e commit f66f48b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
5 changes: 0 additions & 5 deletions contracts/common/BiconomyTokenPaymasterErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ contract BiconomyTokenPaymasterErrors {
*/
error InvalidTokenAddress();

/**
* @notice Throws when user tries to pay with an unsupported token
*/
error TokenNotSupported();

/**
* @notice Throws when oracle decimals aren't equal to 8
*/
Expand Down
3 changes: 3 additions & 0 deletions contracts/interfaces/oracles/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ pragma solidity ^0.8.27;

interface IOracle {
function decimals() external view returns (uint8);

function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

function latestAnswer() external view returns (int256);
}
4 changes: 4 additions & 0 deletions contracts/token/oracles/TwapOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ contract TwapOracle is IOracle {
return _buildLatestRoundData(normalizedPrice);
}

function latestAnswer() external view override returns (int256) {
return int256(_fetchTwap());
}

function decimals() external pure override returns (uint8) {
return 8;
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/token/swaps/Uniswapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ abstract contract Uniswapper {
// Errors
error UniswapReverted(address tokenIn, address tokenOut, uint256 amountIn);
error TokensAndPoolsLengthMismatch();
error TokenNotSupported();

constructor(
IV3SwapRouter uniswapRouterArg,
Expand Down Expand Up @@ -56,6 +57,7 @@ abstract contract Uniswapper {
}

function _swapTokenToWeth(address tokenIn, uint256 amountIn, uint256 minAmountOut) internal returns (uint256 amountOut) {
require(tokenToPools[tokenIn] != 0, TokenNotSupported());
IV3SwapRouter.ExactInputSingleParams memory params = IV3SwapRouter.ExactInputSingleParams({
tokenIn: tokenIn,
tokenOut: wrappedNative,
Expand Down
4 changes: 4 additions & 0 deletions test/mocks/MockOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ contract MockOracle is IOracle {
73_786_976_294_838_215_802 // Mock round ID for answeredInRound
);
}

function latestAnswer() external view override returns (int256) {
return price;
}
}
5 changes: 1 addition & 4 deletions test/unit/concrete/TestTokenPaymaster.Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,7 @@ contract TestTokenPaymasterBase is TestBase {
initialPaymasterEpBalance,
initialUserTokenBalance,
initialPaymasterTokenBalance,
// IF THIS CASE FAILS ON 2% TOLERANCE => PUT THE FRESH PRICE FROM ORACLE HERE
// https://basescan.org/address/0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70#readContract#F8
// and remove two last digits from the price
3358580000,
uint256(nativeOracle.latestAnswer()) / 100,
_PRICE_MARKUP_DENOMINATOR,
this.getMaxPenalty(ops[0]),
this.getRealPenalty(ops[0], gasValue, customGasPrice));
Expand Down

0 comments on commit f66f48b

Please sign in to comment.