Skip to content

Commit

Permalink
checks + refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Dec 2, 2024
1 parent 4725ef3 commit b834dca
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions contracts/token/BiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,9 @@ contract BiconomyTokenPaymaster is
sstore(nativeAssetToUsdOracle.slot, nativeAssetToUsdOracleArg)
}

// Populate the tokenToOracle mapping
for (uint256 i = 0; i < independentTokensArg.length; i++) {
if (tokenInfosArg[i].oracle.decimals() != 8) {
// Token -> USD will always have 8 decimals
revert InvalidOracleDecimals();
}
if (tokenInfosArg[i].priceMarkup > _MAX_PRICE_MARKUP || tokenInfosArg[i].priceMarkup < _PRICE_DENOMINATOR) {
// Not between 0% and 100% markup
revert InvalidPriceMarkup();
}
if (block.timestamp < tokenInfosArg[i].priceExpiryDuration) {
revert InvalidPriceExpiryDuration();
}
independentTokenDirectory[independentTokensArg[i]] =
TokenInfo(
tokenInfosArg[i].oracle,
tokenInfosArg[i].priceMarkup,
tokenInfosArg[i].priceExpiryDuration
);
_validateTokenInfo(tokenInfosArg[i]);
independentTokenDirectory[independentTokensArg[i]] = tokenInfosArg[i];
}
}

Expand Down Expand Up @@ -308,10 +292,7 @@ contract BiconomyTokenPaymaster is
* @notice only to be called by the owner of the contract.
*/
function addToTokenDirectory(address tokenAddress, TokenInfo memory tokenInfo) external payable onlyOwner {
if (tokenInfo.oracle.decimals() != 8) {
// Token -> USD will always have 8 decimals
revert InvalidOracleDecimals();
}
_validateTokenInfo(tokenInfo);

independentTokenDirectory[tokenAddress] = tokenInfo;

Expand Down Expand Up @@ -642,6 +623,18 @@ contract BiconomyTokenPaymaster is
);
}

function _validateTokenInfo(TokenInfo memory tokenInfo) internal view {
if (tokenInfo.oracle.decimals() != 8) {
revert InvalidOracleDecimals();
}
if (tokenInfo.priceMarkup > _MAX_PRICE_MARKUP || tokenInfo.priceMarkup < _PRICE_DENOMINATOR) {
revert InvalidPriceMarkup();
}
if (block.timestamp < tokenInfo.priceExpiryDuration) {
revert InvalidPriceExpiryDuration();
}
}

/// @notice Fetches the latest token price.
/// @return price The latest token price fetched from the oracles.
function _getPrice(address tokenAddress) internal view returns (uint256 price) {
Expand Down

0 comments on commit b834dca

Please sign in to comment.