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
ProviderStaking
contracts using the minimal proxy pattern.Links new contracts to models in the
Model
contract.
Model Integration:
Registers newly created
ProviderStaking
instances with theModel
contract 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
ProviderStaking
implementation address.
MODEL_CREATOR_ROLE
:Limited to creating new models and associated
ProviderStaking
contracts.
State Variables
Core Components:
FUNC
: Address of the FUNC ERC20 token.router
: Address of the Router contract.
Provider Staking Implementation:
providerStakingImplementation
: Address of theProviderStaking
implementation contract.providerStakingImplementationAddressSet
: Tracks whether the implementation address has been set.
Key Functions
Administrative Functions
setProviderStakingImplementation
setProviderStakingImplementation
Sets the address of the ProviderStaking
implementation contract for minimal proxy cloning.
Access:
DEFAULT_ADMIN_ROLE
Parameters:
_implementation
: Address of theProviderStaking
implementation contract.
Staking Contract Creation
createNewProviderStaking
createNewProviderStaking
Creates a new ProviderStaking
contract using a minimal proxy, registers it with the Model
contract, and links it in the Router
.
Access:
DEFAULT_ADMIN_ROLE
orMODEL_CREATOR_ROLE
Parameters:
_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
ProviderStaking
contract.
Workflow
Set ProviderStaking Implementation:
Admin sets the address of the
ProviderStaking
implementation contract viasetProviderStakingImplementation
.
Create New Provider Staking:
A user with the appropriate role calls
createNewProviderStaking
.A new
ProviderStaking
instance is created using the minimal proxy pattern.The new instance is initialized and registered with the
Model
contract.
Events
ProviderStakingCreated(uint256 indexed modelId, address indexed providerStakingAddress, string modelName)
:Emitted when a new
ProviderStaking
contract 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