RewardsDistributorFactoryV1
Overview
RewardsDistributorFactoryV1 is an upgradeable contract (using UUPS) that deploys new instances of IncentiveRewardsDistributor. It restricts calls to createRewardsDistributor
such that only the escrow vote manager can request a new distributor, thus ensuring controlled creation of additional reward distribution contracts.
Key Roles and Features:
Factory Pattern: It centralizes the instantiation of IncentiveRewardsDistributor contracts, simplifying the process of creating new distributors for different escrow managers.
Access Control: Only the escrow vote manager can call
createRewardsDistributor
, preventing unauthorized distribution contract creation.Upgradeable via UUPS: Ensures the factory contract can be upgraded over time, with ownership-based control on upgrades.
By implementing IRewardsDistributorFactoryV1
, RewardsDistributorFactoryV1 provides a standard interface for deployment logic and event transparency (though no new custom events are declared here beyond the interface's contract structure).
Inherited Contracts and Interfaces
UUPSUpgradeable (OpenZeppelin): Provides the upgrade mechanism under the UUPS proxy standard, restricting upgrades to the contract owner.
OwnableUpgradeable (OpenZeppelin): Establishes ownership logic, allowing the owner to authorize upgrades and potentially modify other aspects of the factory (not used extensively here but available if needed).
IRewardsDistributorFactoryV1: Declares the
initialize
andcreateRewardsDistributor
functions, along with anInvalidCaller
error.
Additional External References:
IncentiveRewardsDistributor: The contract being deployed by this factory. It manages incentive reward distributions for an escrow manager and is constructed with references to the escrow vote manager and escrow manager.
State Variables
s_escrowVoteManager (address)
: The address of the escrow vote manager contract. Only this address may invokecreateRewardsDistributor
on the factory.
Constructor
Description: Disables contract initializers to ensure
initialize()
can only be called once. A standard pattern for UUPS upgradeable contracts.
External Functions
1. initialize(address owner_, address escrowVoteManager_)
initialize(address owner_, address escrowVoteManager_)
Description: Configures the factory contract by assigning ownership (
owner_
) and storing the escrow vote manager address. This function can be called only once due to theinitializer
modifier.Parameters:
owner_
: The address to be assigned as the owner of this factory contract.escrowVoteManager_
: The address of the escrow vote manager responsible for orchestrating new distributor creations.
Logic and Effects:
Invokes
__UUPSUpgradeable_init()
and__Ownable_init(owner_)
for upgrade and ownership setup.Sets
s_escrowVoteManager = escrowVoteManager_
.
2. createRewardsDistributor(address escrowManager_)
createRewardsDistributor(address escrowManager_)
Description: Creates and returns a new IncentiveRewardsDistributor contract instance, linking it to the calling escrow vote manager (
msg.sender
) and the providedescrowManager_
. The call reverts if not invoked bys_escrowVoteManager
.Checks:
Must be called by
s_escrowVoteManager
. Otherwise, it reverts withInvalidCaller()
.
Logic:
If
msg.sender != s_escrowVoteManager
, revert withInvalidCaller()
.Deploys a new IncentiveRewardsDistributor by calling its constructor:
Returns the newly created contract’s address.
Return:
address
: The address of the newly created incentive rewards distributor contract.
Internal Functions
1. _authorizeUpgrade(address newImplementation)
_authorizeUpgrade(address newImplementation)
Description: Restricts upgrades of this factory to the contract’s owner, following the UUPS standard. This ensures that only the owner can deploy a new logic implementation for this factory contract.
Errors
InvalidCaller()
Thrown ifcreateRewardsDistributor
is called by an address other thans_escrowVoteManager
.
Summary
RewardsDistributorFactoryV1 provides a straightforward pattern for creating new IncentiveRewardsDistributor instances. By restricting calls to its createRewardsDistributor
function to the escrow vote manager, it ensures that only authorized processes can spin up new distributor contracts. Coupled with UUPS upgradeability, the factory is future-proofed, allowing for modifications to how distributors are instantiated if the protocol’s requirements evolve over time.
Last updated