# SSV-Based Applications Integration Guide
## Introduction
The SSV Network’s “Based Applications” (bApps) framework enables Ethereum validators to delegate new tasks to external smart contracts while maintaining decentralized security. By deploying a bApp smart contract and registering it with the SSV Based Application Manager, services can integrate directly with the SSV ecosystem.
This guide focuses on how to convert Linglong into a SSV bApp.
## How to convert Linglong into a SSV bApp
### How integration with SSV bApps same as Eigenlayer AVS or Symbiotic Network
We need a middleware contract, like `EigenlayerMiddleware`, to coordinate operator registration.
### How integration with SSV bApps different from Eigenlayer AVS or Symbiotic Network
Unlike other designs that require operator sets or subnetworks(such as Gateways or Underwriters), there's only one service running for SSV bApps, which is `ValidatorBApp`. This is equivalent to the `ValidatorOperatorSet` in Eigenlayer AVS or `ValidatorNetwork` in Symbiotic Network.
As such, each validator needs its delegation pointed to either `GatewayOperatorset` in for Eigenlayer or `GatewayNetwork` in Symbiotic, otherwise there will be no delegation available.
### bApp integration

1. Implement Based Application middleware contract
2. Create and Register the bApp
3. Strategies creation
4. Strategies opt-in to the bApp
5. Strategies secured by token deposits or validator balance delegation
6. Build BApp client for strategies to operate
Here, we only need to do step 1 and 2 for operator registration, and couple more steps for validator registration, which is not included in the image above.
### Middleware contract
To integrate Linglong as an SSV-based application, we will create a new middleware smart contract `BAppMiddleware`. This contract will implement SSV’s required interface for bApps and include Linglong-specific logic for validator registration and delegation.
`BAppMiddleware` will act as a module hooks into this system like `EigenlayerMiddleware` did in Linglong.
#### Required interfaces - `IBasedApp`
`BAppMiddleware` needs to implement the [following interface](https://github.com/ssvlabs/based-applications/blob/main/src/middleware/interfaces/IBasedApp.sol) to be recognized as a bApp by the SSV system:
```solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.28;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface IBasedApp is IERC165 {
function registerBApp(address[] calldata tokens, uint32[] calldata sharedRiskLevels, string calldata metadataURI) external;
function optInToBApp(
uint32 strategyId,
address[] calldata tokens,
uint32[] calldata obligationPercentages,
bytes calldata data
) external returns (bool);
function addTokensToBApp(address[] calldata tokens, uint32[] calldata sharedRiskLevels) external;
function updateBAppTokens(address[] calldata tokens, uint32[] calldata sharedRiskLevels) external;
function updateBAppMetadataURI(string calldata metadataURI) external;
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
```
A abstract contract implementation can be found [here](https://github.com/ssvlabs/based-applications/blob/main/src/middleware/modules/core/BasedAppCore.sol).
#### Operator Registration
This will be handled by the `optInToBApp` function(See above). Other than SSV required logic, we'll need to update the operator meta data in `TaiyiRegistryCoordinator` locally as well
#### Validator Registration
Validator registration and slasher opt-in procees via URC's `Registry.sol` will be handled similarly to `EigenlayerMiddleware` and `SymbioticNetworkMiddleware`. The difference is that delegation cannot happend natively inside of `BAppMiddleware`, so we'll need to delegate to `GatewayOperatorset` in Eigenlayer or `GatewayNetwork` in Symbiotic.
See in [`optInToSlasher()`](https://github.com/lu-bann/linglong/blob/a718f285b83b41c89aac70df231fc4ca0eab40d5/src/eigenlayer-avs/EigenLayerMiddleware.sol#L352) function in `EigenlayerMiddleware`, delegatee address is checked against `UnderwriterOperatorset`. Here, since `BAppMiddleware` only has one "operator set", we'll require delegation to `GatewayOperatorset` in Eigenlayer or `GatewayNetwork` in Symbiotic.
#### Strategies
TBD. Need to ask what strategies are available in SSV bApp on testnet.
#### Slashing
For testnet we ignore slashing for now.