Skip to content

Commit

Permalink
lint fixes + change ci yml
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Oct 7, 2024
1 parent 2b48403 commit 27a1527
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 77 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22' # Specify the Node.js version you want to use

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn cache clean && yarn install

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jobs:
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "20.x"
node-version: '22' # Specify the Node.js version you want to use

- name: Install lcov (for genhtml)
run: sudo apt-get update && sudo apt-get install -y lcov

- name: Install JavaScript Dependencies
run: yarn install --frozen-lockfile
run: yarn cache clean && yarn install

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
4 changes: 2 additions & 2 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"imports-on-top": "error",
"ordering": "error",
"visibility-modifier-order": "error",
"code-complexity": ["error", 7],
"function-max-lines": ["error", 80],
"code-complexity": ["error", 10],
"function-max-lines": ["error", 90],
"max-line-length": ["warn", 120],
"no-empty-blocks": "error",
"no-unused-vars": "error",
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/oracles/IOracle.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.27;

interface IOracle {
function decimals() external view returns (uint8);
Expand Down
48 changes: 24 additions & 24 deletions contracts/references/SampleTokenPaymaster.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.23;
pragma solidity ^0.8.27;

// Import the required libraries and contracts
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
Expand Down Expand Up @@ -41,17 +41,17 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper {
uint48 priceMaxAge;
}

/// @notice All 'price' variables are multiplied by this value to avoid rounding up
uint256 private constant PRICE_DENOMINATOR = 1e26;

TokenPaymasterConfig public tokenPaymasterConfig;

event ConfigUpdated(TokenPaymasterConfig tokenPaymasterConfig);

event UserOperationSponsored(address indexed user, uint256 actualTokenCharge, uint256 actualGasCost, uint256 actualTokenPriceWithMarkup);

event Received(address indexed sender, uint256 value);

/// @notice All 'price' variables are multiplied by this value to avoid rounding up
uint256 private constant PRICE_DENOMINATOR = 1e26;

TokenPaymasterConfig public tokenPaymasterConfig;

/// @notice Initializes the TokenPaymaster contract with the given parameters.
/// @param _token The ERC20 token used for transaction fee payments.
/// @param _entryPoint The EntryPoint contract used in the Account Abstraction infrastructure.
Expand Down Expand Up @@ -88,15 +88,13 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper {
transferOwnership(_owner);
}

/// @notice Updates the configuration for the Token Paymaster.
/// @param _tokenPaymasterConfig The new configuration struct.
function setTokenPaymasterConfig(
TokenPaymasterConfig memory _tokenPaymasterConfig
) public onlyOwner {
require(_tokenPaymasterConfig.priceMarkup <= 2 * PRICE_DENOMINATOR, "TPM: price markup too high");
require(_tokenPaymasterConfig.priceMarkup >= PRICE_DENOMINATOR, "TPM: price markup too low");
tokenPaymasterConfig = _tokenPaymasterConfig;
emit ConfigUpdated(_tokenPaymasterConfig);
receive() external payable {
emit Received(msg.sender, msg.value);
}

function withdrawEth(address payable recipient, uint256 amount) external onlyOwner {
(bool success,) = recipient.call{value: amount}("");
require(success, "withdraw failed");
}

function setUniswapConfiguration(
Expand All @@ -112,6 +110,17 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper {
SafeERC20.safeTransfer(token, to, amount);
}

/// @notice Updates the configuration for the Token Paymaster.
/// @param _tokenPaymasterConfig The new configuration struct.
function setTokenPaymasterConfig(
TokenPaymasterConfig memory _tokenPaymasterConfig
) public onlyOwner {
require(_tokenPaymasterConfig.priceMarkup <= 2 * PRICE_DENOMINATOR, "TPM: price markup too high");
require(_tokenPaymasterConfig.priceMarkup >= PRICE_DENOMINATOR, "TPM: price markup too low");
tokenPaymasterConfig = _tokenPaymasterConfig;
emit ConfigUpdated(_tokenPaymasterConfig);
}

/// @notice Validates a paymaster user operation and calculates the required token amount for the transaction.
/// @param userOp The user operation data.
/// @param requiredPreFund The maximum cost (in native token) the paymaster has to prefund.
Expand Down Expand Up @@ -205,13 +214,4 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper {
entryPoint.depositTo{value: address(this).balance}(address(this));
}
}

receive() external payable {
emit Received(msg.sender, msg.value);
}

function withdrawEth(address payable recipient, uint256 amount) external onlyOwner {
(bool success,) = recipient.call{value: amount}("");
require(success, "withdraw failed");
}
}
12 changes: 6 additions & 6 deletions contracts/sponsorship/BiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,6 @@ contract BiconomySponsorshipPaymaster is
return (context, _packValidationData(false, validUntil, validAfter));
}

function _withdrawERC20(IERC20 token, address target, uint256 amount) private {
if (target == address(0)) revert CanNotWithdrawToZeroAddress();
SafeTransferLib.safeTransfer(address(token), target, amount);
emit TokensWithdrawn(address(token), target, amount, msg.sender);
}

function _checkConstructorArgs(
address _verifyingSigner,
address _feeCollector,
Expand All @@ -364,4 +358,10 @@ contract BiconomySponsorshipPaymaster is
revert UnaccountedGasTooHigh();
}
}

function _withdrawERC20(IERC20 token, address target, uint256 amount) private {
if (target == address(0)) revert CanNotWithdrawToZeroAddress();
SafeTransferLib.safeTransfer(address(token), target, amount);
emit TokensWithdrawn(address(token), target, amount, msg.sender);
}
}
53 changes: 27 additions & 26 deletions contracts/token/BiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract BiconomyTokenPaymaster is
uint256 public independentPriceMarkup; // price markup used for independent mode
uint256 public priceExpiryDuration; // oracle price expiry duration
IOracle public nativeAssetToUsdOracle; // ETH -> USD price oracle
mapping(address => TokenInfo) independentTokenDirectory; // mapping of token address => info for tokens supported in
mapping(address => TokenInfo) public independentTokenDirectory; // mapping of token address => info for tokens supported in
// independent mode

// PAYMASTER_ID_OFFSET
Expand Down Expand Up @@ -125,25 +125,6 @@ contract BiconomyTokenPaymaster is
}
}

/**
* Add a deposit in native currency for this paymaster, used for paying for transaction fees.
* This is ideally done by the entity who is managing the received ERC20 gas tokens.
*/
function deposit() public payable virtual override nonReentrant {
entryPoint.depositTo{ value: msg.value }(address(this));
}

/**
* @dev Withdraws the specified amount of gas tokens from the paymaster's balance and transfers them to the
* specified address.
* @param withdrawAddress The address to which the gas tokens should be transferred.
* @param amount The amount of gas tokens to withdraw.
*/
function withdrawTo(address payable withdrawAddress, uint256 amount) public override onlyOwner nonReentrant {
if (withdrawAddress == address(0)) revert CanNotWithdrawToZeroAddress();
entryPoint.withdrawTo(withdrawAddress, amount);
}

/**
* @dev pull tokens out of paymaster in case they were sent to the paymaster at any point.
* @param token the token deposit to withdraw
Expand Down Expand Up @@ -363,6 +344,25 @@ contract BiconomyTokenPaymaster is
entryPoint.depositTo{ value: amountOut }(address(this));
}

/**
* Add a deposit in native currency for this paymaster, used for paying for transaction fees.
* This is ideally done by the entity who is managing the received ERC20 gas tokens.
*/
function deposit() public payable virtual override nonReentrant {
entryPoint.depositTo{ value: msg.value }(address(this));
}

/**
* @dev Withdraws the specified amount of gas tokens from the paymaster's balance and transfers them to the
* specified address.
* @param withdrawAddress The address to which the gas tokens should be transferred.
* @param amount The amount of gas tokens to withdraw.
*/
function withdrawTo(address payable withdrawAddress, uint256 amount) public override onlyOwner nonReentrant {
if (withdrawAddress == address(0)) revert CanNotWithdrawToZeroAddress();
entryPoint.withdrawTo(withdrawAddress, amount);
}

/**
* return the hash we're going to sign off-chain (and validate on-chain)
* this method is called by the off-chain service, to sign the request.
Expand Down Expand Up @@ -542,12 +542,6 @@ contract BiconomyTokenPaymaster is
);
}

function _withdrawERC20(IERC20 token, address target, uint256 amount) private {
if (target == address(0)) revert CanNotWithdrawToZeroAddress();
SafeTransferLib.safeTransfer(address(token), target, amount);
emit TokensWithdrawn(address(token), target, amount, msg.sender);
}

/// @notice Fetches the latest token price.
/// @return price The latest token price fetched from the oracles.
function getPrice(address tokenAddress) internal view returns (uint192 price) {
Expand Down Expand Up @@ -581,4 +575,11 @@ contract BiconomyTokenPaymaster is
}
price = uint192(int192(answer));
}

function _withdrawERC20(IERC20 token, address target, uint256 amount) private {
if (target == address(0)) revert CanNotWithdrawToZeroAddress();
SafeTransferLib.safeTransfer(address(token), target, amount);
emit TokensWithdrawn(address(token), target, amount, msg.sender);
}

}
26 changes: 13 additions & 13 deletions contracts/token/oracles/TwapOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ import {IUniswapV3PoolImmutables} from "@uniswap/v3-core/interfaces/pool/IUniswa


contract TwapOracle is IOracle {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Invalid TWAP age, either too low or too high
error InvalidTwapAge();

/// @dev Pool doesn't contain the base token
error InvalidTokenOrPool();

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS AND IMMUTABLES */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Expand All @@ -43,6 +34,15 @@ contract TwapOracle is IOracle {

uint256 public constant ORACLE_DECIMALS = 1e8;

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Invalid TWAP age, either too low or too high
error InvalidTwapAge();

/// @dev Pool doesn't contain the base token
error InvalidTokenOrPool();

constructor(
address _pool,
uint32 _twapAge,
Expand All @@ -65,10 +65,6 @@ contract TwapOracle is IOracle {
quoteTokenDecimals = 10 ** IERC20Metadata(quoteToken).decimals();
}

function decimals() external override pure returns (uint8) {
return 8;
}

function latestRoundData() external override view returns (
uint80 roundId,
int256 answer,
Expand All @@ -84,6 +80,10 @@ contract TwapOracle is IOracle {
return _buildLatestRoundData(price);
}

function decimals() external override pure returns (uint8) {
return 8;
}

function _buildLatestRoundData(uint256 price) internal view returns (
uint80 roundId,
int256 answer,
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/swaps/Uniswapper.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.26;
pragma solidity ^0.8.27;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
Expand Down

0 comments on commit 27a1527

Please sign in to comment.