NGOLisFactory
The contract includes functionality for creating new NGO instances, associating them with owners, and emitting events to log these actions. Additionally, it provides a method for the contract owner to withdraw fees in the form of staked Ether (stETH), ensuring proper fund management and transparency. The contract leverages interfaces and events to interact with other smart contracts and to notify external systems of significant actions. It utilizes the ERC1967 proxy pattern to create upgradeable NGO instances, manages ownership associations, and handles platform fee collection.
Contract Architecture
Proxy Implementation
Uses OpenZeppelin's
ERC1967Proxy
for creating upgradeable NGO instancesMaintains a reference to the current NGOLis implementation contract
Allows implementation updates through owner-controlled function
Each deployed NGO is a separate proxy pointing to the same implementation
Core Components
Implementation Management
address private _ngoImplementation; // Current NGO implementation
Stores the reference implementation for all NGO proxies
Can be updated by factory owner through
setImplementation
Protocol Addresses
address _lidoSCAddress; // Lido staking contract address _withdrawalSCAddress; // Withdrawal queue contract address wstETHSC; // Wrapped stETH contract
Core protocol contracts used by NGO instances
Set during factory construction
Immutable after deployment
Ownership Tracking
mapping(address => address) public ownerToNgo;
Maps NGO owners to their respective NGO contract addresses
One-to-one relationship between owners and NGO
Sequential Diagram

Core Logic and Operations
NGO Deployment Process
Proxy Creation
Creates new
ERC1967Proxy
instancePoints to current implementation
Initializes with provided parameters
Ownership Association
Records owner to NGO address mapping
Enables lookup of NGO contracts by owner
Configuration
Sets initial rewards owner
Configures oracle permissions
Associates with Lido protocol contracts
Fee Management
Collects platform fees in wstETH
Owner can withdraw accumulated fees
Emits events for fee collection transparency
Function Documentation
Administrative Functions
constructor
constructor
constructor(
address _lidoSC,
address _withdrawalSC,
address _ngoImplementationAddress,
address _wstETHSC
) Ownable(msg.sender)
Initializes the factory with required protocol addresses.
Parameters
_lidoSC
: Lido protocol contract address_withdrawalSC
: Withdrawal queue contract address_ngoImplementationAddress
: NGOLis implementation contract_wstETHSC
: Wrapped stETH contract address
Effects
Sets immutable protocol addresses
Establishes initial implementation reference
Sets contract owner
setImplementation
setImplementation
function setImplementation(address newImplementation) public onlyOwner
Updates the NGO implementation contract address.
Parameters
newImplementation
: Address of new implementation contract
Access Control
Restricted to factory owner
Effects
Updates implementation reference for future deployments
Does not affect existing NGO proxies
Deployment Functions
createNGO
createNGO
function createNGO(
string memory _name,
string memory _imageLink,
string memory _description,
string memory _link,
string memory _location,
address _rewardsOwner,
address owner,
address oracle
) public onlyOwner
Creates and initializes a new NGO contract instance.
Parameters
_name
: NGO name identifier_imageLink
: URL to NGO image_description
: NGO description_link
: External NGO website/resource_location
: Physical/operational location_rewardsOwner
: Address to receive NGO rewardsowner
: NGO contract administratororacle
: Address with oracle privileges
Access Control
Restricted to factory owner
Effects
Deploys new proxy contract
Initializes NGO configuration
Records owner association
Emits
NGOCreated
event
Fee Management Functions
withdrawFeeStEth
withdrawFeeStEth
function withdrawFeeStEth() public onlyOwner
Withdraws accumulated platform fees.
Access Control
Restricted to factory owner
Effects
Transfers all wstETH balance to owner
Emits
LisFeeClaimed
event
Requirements
Factory must have non-zero wstETH balance
Events
NGOCreated
NGOCreated
event NGOCreated(
string _name,
string _imageLink,
string _description,
string _link,
address _rewardsOwner,
address _ngoAddress,
string _location,
address oracle
);
Emitted when new NGO is deployed.
Includes all NGO metadata
Records contract addresses
Enables frontend/indexer tracking
LisFeeClaimed
LisFeeClaimed
event LisFeeClaimed(uint256 _value);
Emitted when platform fees are withdrawn.
Records withdrawal amount
Provides transparency for fee collection
Security Features
Access Control
Owner-only administrative functions
Protected implementation updates
Controlled NGO deployment
Proxy Pattern
Upgradeable NGO instances
Consistent implementation reference
State isolation between NGOs
Address Validation
Protocol contract verification
Owner-NGO relationship tracking
Unique NGO deployment per owner
Integration Guidelines
Deployment Process
// Example deployment sequence const factory = await NGOLisFactory.deploy( lidoAddress, withdrawalAddress, implementationAddress, wstETHAddress ); // Create NGO instance await factory.createNGO( "NGO Name", "image.url", "Description", "website.url", "Location", rewardsOwner, ngoAdmin, oracleAddress );
Fee Management
// Withdraw platform fees await factory.withdrawFeeStEth();
Implementation Updates
// Update NGO implementation await factory.setImplementation(newImplementationAddress);
Common Operations
Finding NGO Address
address ngoAddress = factory.ownerToNgo(ownerAddress);
Verifying Ownership
bool hasNGO = factory.ownerToNgo(address) != address(0);
Last updated