Skip to content

Move token whitelist and price feeds management to Factory contract. #95

Description

@TomasDmArg

Description: Move token whitelist and price feed management to the Factory contract to reduce gas costs and simplify wallet management.

Note: It could not be possible due to entrypoint stake increased minimum. We had issues before with Beacons, but not using Factory or UpgradeableBeacon.

Tasks:

  • Add state variables to ChatterPayWalletFactory.sol:
    // Add to state variables
    mapping(address => bool) public globalWhitelistedTokens;
    mapping(address => address) public globalPriceFeeds;
  • Add management functions to ChatterPayWalletFactory:
    /**
     * @notice Sets global token whitelist and price feed
     * @param token Token address
     * @param status Whitelist status
     * @param priceFeed Oracle price feed address
     */
    function setGlobalTokenWhitelistAndPriceFeed(
        address token,
        bool status,
        address priceFeed
    ) external onlyOwner {
        if (token == address(0)) revert ChatterPayWalletFactory__ZeroAddress();
        if (priceFeed == address(0)) revert ChatterPayWalletFactory__ZeroAddress();
        
        globalWhitelistedTokens[token] = status;
        if (status) {
            globalPriceFeeds[token] = priceFeed;
            emit GlobalPriceFeedUpdated(token, priceFeed);
        }
        emit GlobalTokenWhitelisted(token, status);
    }
  • Modify ChatterPay.sol to check factory's whitelist:
    function isTokenWhitelisted(address token) public view returns (bool) {
        return s_state.whitelistedTokens[token] || s_state.factory.globalWhitelistedTokens(token);
    }
    
    function getPriceFeed(address token) public view returns (address) {
        address localFeed = s_state.priceFeeds[token];
        if (localFeed != address(0)) {
            return localFeed;
        }
        return s_state.factory.globalPriceFeeds(token);
    }
  • Add required events to the Factory contract:
    event GlobalTokenWhitelisted(address indexed token, bool status);
    event GlobalPriceFeedUpdated(address indexed token, address indexed priceFeed);
  • Create tests in a new file test/modules/FactoryTokenModule.t.sol to verify the functionality
  • Update existing token tests to ensure compatibility with the new system

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request
No fields configured for Feature.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions