ProviderStakingFactory.sol
The ProviderStakingFactory contract is responsible for creating and managing instances of ProviderStaking contracts. It facilitates model registration, minimal proxy cloning for efficiency, and integration with the Model and Router contracts.
Key Features
Dynamic Staking Contract Creation:
Creates new
ProviderStakingcontracts using the minimal proxy pattern.Links new contracts to models in the
Modelcontract.
Model Integration:
Registers newly created
ProviderStakinginstances with theModelcontract and links them to theRouter.
Access Control:
Role-based access control ensures secure operations.
Supports admin and model creator roles.
Efficiency:
Uses the minimal proxy pattern (via OpenZeppelin's
Clones) to optimize contract deployment.
Roles and Access Control
DEFAULT_ADMIN_ROLE:Full administrative control over the contract.
Can set the
ProviderStakingimplementation address.
MODEL_CREATOR_ROLE:Limited to creating new models and associated
ProviderStakingcontracts.
State Variables
Core Components:
FUNC: Address of the FUNC ERC20 token.router: Address of the Router contract.
Provider Staking Implementation:
providerStakingImplementation: Address of theProviderStakingimplementation contract.providerStakingImplementationAddressSet: Tracks whether the implementation address has been set.
Key Functions
Administrative Functions
setProviderStakingImplementation
setProviderStakingImplementationSets the address of the ProviderStaking implementation contract for minimal proxy cloning.
Access:
DEFAULT_ADMIN_ROLEParameters:
_implementation: Address of theProviderStakingimplementation contract.
Staking Contract Creation
createNewProviderStaking
createNewProviderStakingCreates a new ProviderStaking contract using a minimal proxy, registers it with the Model contract, and links it in the Router.
Access:
DEFAULT_ADMIN_ROLEorMODEL_CREATOR_ROLEParameters:
_modelId: Unique ID for the model being created._shards: Number of shards allocated to the model._computeUnits: Number of compute units associated with the model._stakeAmount: Required stake amount for the model._modelName: Name of the model.
Returns: Address of the newly created
ProviderStakingcontract.
Workflow
Set ProviderStaking Implementation:
Admin sets the address of the
ProviderStakingimplementation contract viasetProviderStakingImplementation.
Create New Provider Staking:
A user with the appropriate role calls
createNewProviderStaking.A new
ProviderStakinginstance is created using the minimal proxy pattern.The new instance is initialized and registered with the
Modelcontract.
Events
ProviderStakingCreated(uint256 indexed modelId, address indexed providerStakingAddress, string modelName):Emitted when a new
ProviderStakingcontract is created.
Example Usage
Setting the ProviderStaking Implementation:
providerStakingFactory.setProviderStakingImplementation(address(providerStakingImplementation));Creating a New ProviderStaking Contract:
providerStakingFactory.createNewProviderStaking(
1, // Model ID
100, // Number of shards
1000, // Compute units
500 * 10**18, // Required stake amount
"Example Model" // Model name
);Last updated