@fxnlabs/v1-contracts
v0.0.5
Published
Function Network is a decentralized infrastructure designed to power AI inference workloads. Function Network democratizes access to AI compute by enabling anyone with computational resources to participate. Gateways facilitate seamless interaction for us
Downloads
30
Readme
Function Network
Function Network is a decentralized infrastructure designed to power AI inference workloads. Function Network democratizes access to AI compute by enabling anyone with computational resources to participate. Gateways facilitate seamless interaction for users, while providers execute computational tasks defined by cutting-edge AI models.
At its core, Function Network utilizes FUNC, a blockchain-based token, to enable staking, governance, and reward distribution, ensuring efficiency and trust within the system. By connecting compute providers, gateways, and AI models, the network creates a scalable, transparent, and incentive-driven ecosystem.
Table of Contents
- Developer Documentation
- Glossary of Terms
- Benefits of Function
- How it Works
- How to Participate
- Key Features
- Core Components
- Tokenomics
- Fees & Discounts
- Staking Workflows
- Provider & Gateway Active Status
- Roadmap
- FAQ
- Get Involved
Benefits of Function Network
- Decentralized AI Infrastructure: Democratizes access to AI compute, enabling fair and transparent participation.
- Scalable and Flexible: Dynamically supports multiple models, providers, and gateways for evolving AI workloads.
- Fair Reward System: Checkpoints and performance tracking ensure transparent distribution of FUNC rewards.
Key Features
1. Decentralized AI Inference
Function Network enables AI inference tasks to be processed through a decentralized network:
- AI Models: Define specific computational workloads (e.g., image recognition, NLP).
- Providers: Supply computational power to execute these tasks.
- Gateways: Act as the interface between users and the network.
2. Staking and Rewards
Participants stake FUNC tokens to contribute to the network and earn rewards:
- Providers: Stake FUNC to support AI models and earn FUNC based on their contributions.
- Gateways: Stake FUNC to act as intermediaries and earn rewards for routing user requests.
3. Transparent Reward Distribution
Rewards are allocated based on performance metrics:
- Epoch-based Rewards: Incentives are distributed periodically at the end of each epoch.
- Checkpointing: Tracks historical contributions for accurate reward calculations.
4. Scalable Infrastructure
The Function Network dynamically scales with demand:
- Providers can support multiple models to maximize their earnings.
- Gateways ensure seamless routing and scalability for users.
How It Works
Registration Providers and gateways register on the network, linking their accounts to specific models or operations.
Staking Providers and gateways stake FUNC tokens to participate in the network. Staking ensures accountability and incentivizes contributions.
Task Execution Providers execute tasks defined by AI models, while gateways route requests to the appropriate providers.
Reward Distribution Rewards are calculated and distributed at the end of each epoch based on contributions and performance.
How to Participate
For Providers
To participate as a provider:
- Register your provider ID and link it to a specific AI model.
- Stake FUNC tokens as required by the model.
- Execute Tasks: Provide computational resources to support AI inference workloads.
- Claim Rewards: Collect FUNC rewards based on your performance.
- Unstake: After meeting the minimum lock period, unstake your FUNC tokens if desired.
For Gateways
To participate as a gateway:
- Register your gateway ID and add metadata for identification.
- Stake FUNC tokens to activate your gateway.
- Facilitate Requests: Route user requests to the appropriate providers.
- Claim Rewards: Earn FUNC based on your routing and performance.
- Unstake: Deactivate and unstake FUNC tokens when no longer operating.
Core Components
FUNC Token
FUNC is the native utility token of the Function Network. It powers the ecosystem by:
- Staking: Required for providers and gateways to participate.
- Rewards: Distributed to contributors based on performance.
- Governance (Roadmap): FUNC holders influence decisions about the network's evolution.
Providers
Providers supply computational resources for running AI models. They:
- Stake FUNC to participate.
- Execute AI inference tasks and earn FUNC rewards.
- Support specific models by aligning with their staking and performance requirements.
Gateways
Gateways enable users to interact with the network. They:
- Stake FUNC to operate.
- Route user requests to providers and ensure task execution.
- Earn FUNC for their role in connecting users to the network.
Models
AI models define the computational workloads to be executed on the network. Each model:
- Specifies computational requirements like shards and compute units.
- Requires providers to stake FUNC to support them.
Router
The Router acts as the central management hub, connecting providers, gateways, models, and other core components.
Treasury
The Treasury manages FUNC tokens and ensures accurate reward distribution to providers and gateways.
Checkpoints
Checkpoint contracts track contributions and performance over time:
- Provider Checkpoints: Monitor provider activity and shards contributed.
- Gateway Checkpoints: Track gateway usage and compute units consumed.
Tokenomics
FUNC Token Utility
- Staking: FUNC tokens must be staked by providers and gateways to participate in the network.
- Rewards: FUNC tokens are distributed to staked participants based on their contributions to the network.
- Governance: FUNC tokens may be used for proposal voting and treasury management in the future.
Earning Potential
- Providers and gateways earn FUNC based on the shards (work) they contribute during each epoch.
- Example:
- If the total reward pool for an epoch is 10,000 FUNC and a provider contributes 10% of the shards, they earn 1,000 FUNC.
Economic Design
- Fixed Supply:
- FUNC tokens have a fixed supply, with no inflationary mechanisms, ensuring scarcity and value retention.
- Treasury Management:
- FUNC tokens in the treasury are allocated for ecosystem development, community initiatives, and network rewards.
Understanding Fees in the FUNC Ecosystem
The FUNC ecosystem implements a dynamic mechanism for calculating burn amounts based on consumed Compute Units (CU). This mechanism ensures fairness by rewarding users who stake more FUNC tokens or commit to longer staking durations. Below is an overview of how burn amounts are determined and the various discount mechanisms available.
[!IMPORTANT] Burn is disabled on network launch and for the foreseeable future
Fee Calculation
The fee is the FUNC tokens deducted based on consumed Compute Units (CU). It is calculated as:
Fee = CU Consumed × Fee Multiplier × Conversion FactorWhere:
- Fee Multiplier: Determined dynamically based on stake size and staking duration.
- Conversion Factor: Adjusts the relationship between CU and FUNC, defined by a configurable numerator and denominator:
- Conversion =
(CU × Denominator) / Numerator - This ensures flexibility in setting CU-to-FUNC ratios, which may vary based on network needs.
- Conversion =
Types of Discounts
Stake-Based Discounts
- Users with higher FUNC stakes qualify for lower fees.
- Discount tiers define minimum stake levels and their associated fees (expressed as percentages).
- Example:
- Stake ≥ 5000 FUNC: Fee = 95%
- Stake ≥ 1000 FUNC: Fee = 97%
- Stake < 1000 FUNC: Fee = 100% (no discount)
Duration-Based Discounts
- Users who stake FUNC for longer durations qualify for additional discounts.
- Discount tiers define minimum staking durations (measured in epochs) and their associated discounts.
- Example:
- Staked for ≥ 180 epochs (6 months): Discount = 5%
- Staked for ≥ 30 epochs (1 month): Discount = 2%
Additive Discount Mechanism
The total fee multiplier applied to the Fee is calculated as:
Final Fee = Stake-Based Fee - Duration Discount- Stake-Based Fee: Based on the user’s FUNC stake amount.
- Duration Discount: Based on the user’s staking duration (in epochs).
- The final fee cannot go below 0%.
Example Calculation
User Parameters:
- Compute Units Consumed: 100 CU
- FUNC Staked: 5000 FUNC (qualifies for a 95% fee).
- Staking Duration: 6 months (qualifies for a 5% discount).
- Conversion Factor: Numerator = 1, Denominator = 2 (1 CU Costs 2 FUNC).
Calculation:
Stake-Based Fee: 95% (9500 basis points).
Duration Discount: 5% (500 basis points).
Final Fee: 95% - 5% = 90% (9000 basis points).
Fee:
Fee = (CU Consumed × Final Fee In Basis × Denominator) / (Numerator × Basis Denominator) = (100 × 9000 × 2) / (1 × 10000) = 180 FUNC
Key Takeaways
- Flexible Conversion: CU and FUNC are not always 1:1. The conversion factor (numerator and denominator) allows adjustments to the CU-to-FUNC ratio to meet network needs.
- Stake-Based Discounts: Encourages users to stake more FUNC by reducing fees for higher stakes.
- Duration-Based Discounts: Rewards users who commit to longer staking periods.
- Fair Mechanism: The additive discount approach ensures fairness, combining discounts without compounding.
This mechanism incentivizes greater participation and long-term commitment, promoting network stability and security.
Staking Workflows for Function Network
Below are detailed workflows for registering, staking, unstaking, claiming rewards, and winding down for both Gateways and Providers within the Function Network.
Gateway Staking Workflows
1. Registering a Gateway
Gateways must be registered before staking FUNC tokens. Registration associates metadata and allows the Gateway to participate in the network.
Steps
- Call
registerinGatewayRegistry:- Provide a unique
id(max 64 bytes) and optional metadata (max 1024 bytes). - Metadata is intended for descriptive information about the Gateway, such as its role or identifier.
- Provide a unique
- Auto-whitelisting (if enabled):
- The gateway will automatically be whitelisted for participation.
- Emit event:
GatewayRegistered.
Example:
register("unique-gateway-id", "My Gateway Metadata")2. Staking FUNC for a Gateway
Once registered, the Gateway owner can stake FUNC tokens to participate in the network.
Steps
- Determine Stake Amount:
- Ensure you have enough FUNC tokens to stake.
- Transfer FUNC tokens to the
GatewayRegistrycontract.
- Call
registerAndStake:- Provide the
id, metadata, and amount of FUNC tokens to stake.
- Provide the
- Auto-update Staking Contract:
- The FUNC tokens are approved and forwarded to the
GatewayStakingcontract.
- The FUNC tokens are approved and forwarded to the
- Emit event:
GatewayRegisteredAndStaked.
Example:
registerAndStake("unique-gateway-id", "My Gateway Metadata", 1000 * 10**18)3. Wind Down a Gateway
Gateways must be wound down before they can be unstaked. This marks the gateway for eventual deactivation.
Steps
- Call
windDownGatewaysinGatewayStaking:- Provide a list of gateway IDs to wind down.
- Wait for the wind-down delay:
- A specified delay period (defined in
EpochController) must pass before the gateway can be unstaked.
- A specified delay period (defined in
- Emit event:
GatewayWoundDown.
Example:
windDownGateways(["unique-gateway-id"])4. Unstaking a Gateway
To retrieve staked FUNC tokens, the gateway must complete the wind-down and lock periods defined by the system.
Steps
- Ensure Wind-Down Delay is Complete:
- Gateways must meet the wind-down delay requirement before unstaking.
- Ensure Minimum Lock Period Elapsed:
- Gateways must also meet the
minEpochsLockedrequirement.
- Gateways must also meet the
- Call
unstakeForGatewayinGatewayStaking:- Provide the
idof the gateway to unstake FUNC.
- Provide the
- FUNC Transfer:
- The FUNC tokens are transferred back to the gateway owner.
- Emit event:
GatewayUnstaked.
Example:
unstakeForGateway("unique-gateway-id")5. Claiming Rewards
Gateways earn FUNC rewards based on compute usage and participation metrics.
Steps
- Ensure Rewards Are Delayed:
- Rewards can only be claimed for epochs up to
currentEpoch - epochRewardDelayas defined inEpochController.
- Rewards can only be claimed for epochs up to
- Call
claimRewardsinGatewayStaking:- Provide the
idand range of epochs for claiming rewards.
- Provide the
- Emit event:
GatewayClaimedRewards.
claimRewards("unique-gateway-id", 10, 20)Provider Staking Workflows
1. Registering a Provider
Providers must be linked to a specific model and registered before staking.
Steps
- Call
registerinProviderRegistry:- Provide a unique
id(max 64 bytes),modelId, and optional metadata. - Metadata: The metadata field for a provider is intended to be the URL to access the provider's node, enabling connection to its services.
- Provide a unique
- Auto-whitelisting (if enabled):
- The provider will automatically be whitelisted for participation.
- Emit event:
ProviderRegistered.
register("unique-provider-id", 1, "https://provider-node.example.com")2. Staking FUNC for a Provider
Providers must meet the required stake amount defined by the model.
Steps
- Determine Stake Amount:
- Check the model's required stake amount using
modelStakeAmount.
- Check the model's required stake amount using
- Call
registerAndStake:- Provide the
id,modelId, metadata, and FUNC stake amount.
- Provide the
- Emit event:
ProviderRegisteredAndStaked.
Example:
registerAndStake("unique-provider-id", 1, "https://provider-node.example.com")3. Unstaking a Provider
To retrieve staked FUNC tokens, providers must ensure all lock periods and requirements are met.
Steps
- Ensure Minimum Lock Period Elapsed:
- Providers must meet the
minEpochsLockedrequirement.
- Providers must meet the
- Call
unstakeProviderinProviderStaking:- Provide the
idof the provider to unstake FUNC.
- Provide the
- FUNC Transfer:
- The FUNC tokens are transferred back to the provider owner.
- Emit event:
ProviderUnstaked.
Example:
unstakeProvider("unique-provider-id")4. Claiming Rewards
Providers earn FUNC rewards based on shard contributions and participation metrics.
Steps
- Ensure Rewards Are Delayed:
- Rewards can only be claimed for epochs up to
currentEpoch - epochRewardDelayas defined inEpochController.
- Rewards can only be claimed for epochs up to
- Call
claimRewardsCluster:- Provide the range of epochs to claim rewards for all providers owned by the caller.
- Emit event:
RewardClaimedForCluster.
Example:
claimRewardsCluster(10, 20)Common Notes
- Wind-Down Delay: Gateways must wait a specified number of epochs after calling
windDownGatewaysbefore unstaking. - Minimum Epochs Locked: Applies to both Gateways and Providers. Check this value using
minEpochsLockedinEpochController. - Reward Delay: Rewards can only be claimed for epochs up to
currentEpoch - epochRewardDelay. - Provider Metadata: The metadata for a provider is typically the URL to access its node, enabling external systems to connect and send inference requests.
- FUNC Token Approvals: Always approve FUNC transfers before staking.
Provider and Gateway Active Status
Provider Active Status
A Provider is considered Active if the following conditions are met:
- Registered: The provider has been registered in the Function Network.
- Not Deactivated: The provider has not been explicitly deactivated.
- Sufficiently Staked: The provider has staked an amount of FUNC tokens equal to or greater than the
modelStakeAmountfor the associated model. - Whitelisted: The provider is whitelisted.
- Model is Active: The model associated with the provider is enabled and functional.
Gateway Active Status
A Gateway is considered Active if the following conditions are met:
- Registered: The gateway has been registered in the Function Network.
- Not Deactivated: The gateway has not been explicitly deactivated.
- Effective Stake Amount: The gateway has an effective stake balance that is not overdrawn.
- Whitelisted: The gateway is whitelisted.
Roadmap for Governance and Protocol Changes
Short-Term Goals (1–6 Months)
Parameter Adjustment Mechanism:
- Allow the community to vote on epoch length, reward delay, and staking requirements.
- Provide an interface for transparent proposal submissions.
Enhanced Whitelist Governance:
- Decentralize the whitelisting process to allow token holders to propose and vote on new providers and gateways.
Documentation and Usability Improvements:
- Expand network documentation, including tutorials for onboarding providers and gateways.
- Develop an intuitive dashboard for users to manage their stakes and monitor rewards.
Medium-Term Goals (6–12 Months)
Dynamic Reward Adjustment:
- Implement a model to dynamically adjust staking and reward parameters based on network usage and demand.
AI Model Voting:
- Enable community proposals to add new AI models to the Function Network, with voting on model acceptance and staking requirements.
Transparency Dashboard:
- Build a dashboard displaying governance decisions, staking statistics, and reward distributions.
Long-Term Goals (12+ Months)
Community-Owned Treasury:
- Transition the treasury to community control, enabling FUNC holders to propose and approve funding for initiatives.
Cross-Chain Expansion:
- Launch support for other blockchain ecosystems and allow cross-chain staking and rewards.
Protocol Upgrades:
- Allow community-led protocol upgrades, including smart contract improvements and feature additions.
Dev Documentation
Check out our developer documentation here.
Glossary of Terms
Function Network Core Concepts
- Function Network: A decentralized system designed for AI inference, connecting Gateways (clients) to Providers (AI model operators) through a tokenized staking and reward mechanism.
- FUNC Token: The native utility token of the Function Network, used for staking, rewarding, and facilitating transactions.
- Provider: An operator hosting and maintaining AI inference models, offering services through the Function Network.
- Gateway: An entity that connects users to providers, aggregating and routing AI inference requests.
- Epoch: A fixed time period (in blocks) during which staking, rewards, and network activities are synchronized.
- Shard: A unit of work or compute contribution attributed to providers, determining rewards.
- Stake: FUNC tokens locked to participate in network operations, either as a provider or gateway.
- Whitelist: A status allowing providers or gateways to participate in the network.
- Jail: A status temporarily restricting a provider or gateway due to violations or inactivity.
FAQ
General Questions
What is the Function Network?
- A decentralized system for AI inference, connecting gateways to AI providers using FUNC tokens for staking and rewards.
What are FUNC tokens used for?
- FUNC tokens are used for staking by providers and gateways, distributed as rewards, and may be used for governance in the future.
What is an epoch, and how does it work?
- An epoch is a time period defined by a fixed number of blocks during which network activities like staking and rewards are synchronized.
How are rewards calculated?
- Rewards are based on the shards (units of work) contributed by providers within an epoch, distributed proportionally from the epoch’s reward pool.
What is the significance of
minEpochsLocked?- This is the minimum number of epochs for which FUNC tokens must remain staked before they can be unstaked.
Provider Questions
What is required to register as a provider?
- Register with metadata (typically the URL for the node), stake the required FUNC tokens, and ensure the provider is whitelisted.
What happens if I don’t claim my rewards?
- Rewards remain claimable indefinitely but are subject to the epoch reward delay before they become available.
What is the penalty for being jailed?
- Jailed providers cannot participate in staking or claim rewards during the jail period.
What does the metadata of a provider represent?
- The metadata is typically the URL where the provider’s node can be accessed for inference requests.
Gateway Questions
How do gateways interact with providers?
- Gateways aggregate client requests and route them to the appropriate providers based on availability and compute requirements.
Can gateways unstake immediately?
- No, gateways must initiate a wind-down process, followed by a staking delay before they can unstake.
What metadata do gateways need?
- Gateways typically include routing-related metadata like endpoint URLs or regional availability.
Get Involved
To join the Function Network as a provider, gateway, or developer:
- Obtain FUNC tokens.
- Register and stake on the network.
- Start contributing and earning FUNC rewards!
Join the Function Network and power the future of decentralized computation! For more information or questions, check us out at Function Network.
