GaugeFactoryV1

Overview

GaugeFactoryV1 is a contract responsible for deploying and initializing new gauge contracts. Gauges are used in the EYWA ecosystem to manage rewards distribution based on votes cast by escrowed token holders. This factory integrates with the escrow vote manager to ensure that only authorized entities can create gauges. Each newly created gauge is deployed as a proxy, allowing for future upgrades while maintaining state and logic integrity.

The key roles of GaugeFactoryV1 are:

  • Gauge Creation: Deploys new gauge instances as upgradeable proxies, governed by a gauge implementation contract.

  • Access Control: Ensures that only the escrow vote manager can trigger gauge creation.

  • Initialization: Sets up ownership and links to the escrow vote manager upon factory initialization.

This contract uses the UUPS (Universal Upgradeable Proxy Standard) upgrade pattern and adheres to OwnableUpgradeable principles, allowing controlled, secure upgrades and ownership transfers.


Inherited Contracts and Interfaces

  • UUPSUpgradeable (OpenZeppelin): Provides the upgrade functionality for UUPS-proxy-based contracts, ensuring that only authorized accounts can perform upgrades.

  • OwnableUpgradeable (OpenZeppelin): Adds ownership management, allowing only the owner to perform certain critical operations (e.g., upgrading the contract).

  • IGaugeFactoryV1: Interface defining the functions and events required by the gauge factory, including gauge creation.

Additional External References:

  • ERC1967Proxy (OpenZeppelin): Used to create upgradeable proxy instances of gauges.

  • IDistributionCreator: Provides the structure for campaign parameters required by newly created gauges.

  • GaugeV1: The gauge implementation contract whose instances are deployed as proxies by the factory.


State Variables

  • s_escrowVoteManager

    • Type: address

    • Description: The address of the escrow vote manager contract. This contract acts as an authorized caller that can request the factory to create new gauges.


Constructor

  • constructor()

    • Description: Disables initializers, ensuring this upgradeable contract cannot be re-initialized.


External Functions

initialize(...)

Signature:

function initialize(address owner_, address escrowVoteManager_) external initializer

Description: Initializes the factory with the specified owner and escrow vote manager addresses. This function can only be called once. After initialization, the contract is fully operational with an owner and a reference to the escrow vote manager contract.

Parameters:

  • owner_: The address to be set as the contract owner.

  • escrowVoteManager_: The address of the escrow vote manager contract.

Effects:

  • Initializes UUPSUpgradeable and OwnableUpgradeable modules.

  • Sets s_escrowVoteManager to escrowVoteManager_.

  • Transfers contract ownership to owner_.


createGauge(...)

Signature:

function createGauge(
    address owner_,
    address eywa_,
    IDistributionCreator.CampaignParameters calldata campaignParameters_
) external returns (address)

Description: Deploys a new gauge contract as an upgradeable proxy. This function can only be called by the escrow vote manager (s_escrowVoteManager), ensuring controlled gauge creation. The new gauge is initialized with specified owner, EYWA token address, and reward distribution campaign parameters.

Parameters:

  • owner_: The address that will own the newly created gauge.

  • eywa_: The address of the EYWA token used by the gauge.

  • campaignParameters_: The parameters defining the reward distribution campaign for this gauge (e.g., schedule, amounts, etc.).

Checks:

  • The caller must be s_escrowVoteManager. If not, the InvalidCaller() error is thrown.

Logic:

  1. Deploy a new GaugeV1 implementation contract.

  2. Create an ERC1967Proxy pointing to the new gauge implementation.

  3. Initialize the proxy using the initialize function of the gauge implementation, passing owner_, the caller (msg.sender, which is s_escrowVoteManager), eywa_, and campaignParameters_.

  4. Emit the GaugeCreated event with the addresses of the gauge and its implementation.

  5. Return the address of the newly created gauge.

Return:

  • address: The address of the newly created gauge contract.


Internal Functions

_authorizeUpgrade(address)

Signature:

function _authorizeUpgrade(address) internal override onlyOwner

Description: Ensures that only the contract owner can authorize upgrades to the contract’s implementation. This protects the contract from unauthorized changes.


Events

GaugeCreated

Emitted When: A new gauge is successfully created by the factory.

Parameters:

  • gauge: The address of the newly created gauge contract (proxy address).

  • implementation: The address of the gauge implementation contract used by the new gauge proxy.


Errors

InvalidCaller()

Description: Thrown if createGauge is called by an address other than s_escrowVoteManager. This ensures that only authorized callers (the escrow vote manager) can request the creation of new gauges.


Summary

GaugeFactoryV1 is a specialized factory contract that streamlines the creation and deployment of new gauge contracts in the EYWA ecosystem. By restricting gauge creation to the escrow vote manager, it ensures a secure, orchestrated approach to gauge deployment. Its use of upgradeable patterns, clear access control, and structured initialization procedures guarantees that gauges are created consistently and can evolve over time with secure upgrades.

Last updated