# Publish a feed

> Register a data feed in DataProviderRegistry, describe it with a manifest, approve vaults, take subscriptions, claim earnings and end subscriptions.

Source: https://docs.degenhive.ai/data/publish-a-feed

This guide lists a data feed in the marketplace, takes a vault's subscription and collects the USDC it earns.

You need a HyperEVM (chain 999) wallet with HYPE for gas, a payout address, and an API that serves your data. Registering is free and open to any address.

> [!IMPORTANT]
> The registry is not deployed yet. `REGISTRY`, `USDC` and `VAULT` below are placeholders; addresses publish at launch on [Network](https://docs.degenhive.ai/network.md).

## Step 1: Write a manifest

`registerProvider` stores one free-form string, `metadataUri`. The registry pins no hash and never reads the content. Managers and the app read it to learn what you sell and how to connect.

The shape below is a recommended convention, not a rule the contracts enforce. Host it at a content-addressed URI (IPFS or Arweave) so subscribers can trust it has not changed under them.

`manifest.json (recommended convention)`

```json
{
  "name": "Funding Skew 1m",
  "description": "One-minute funding-rate skew and open-interest deltas for HyperCore perps.",
  "provider": { "name": "Example Data Co", "url": "https://example.com", "contact": "data@example.com" },
  "api": {
    "baseUrl": "https://api.example.com/v1",
    "auth": "verifyAccess-challenge",
    "challengeUrl": "https://api.example.com/v1/auth/challenge",
    "docsUrl": "https://example.com/docs"
  },
  "datasets": [
    {
      "id": "funding-skew",
      "assets": "all HyperCore perps on dex 0",
      "frequency": "60s",
      "history": "2023-06-01 onward",
      "format": "json"
    }
  ],
  "terms": "https://example.com/terms",
  "sample": "https://example.com/sample.json"
}
```

On-chain terms (price, royalty, approvals) always come from the registry, never from the manifest. Keep prices out of it, or mark them as informational.

## Step 2: Register the provider

```solidity
struct ProviderParams {
    address payoutRecipient;  // receives every payout; not zero
    uint256 dailyUsdcFee;     // prepaid price per day, USDC 1e6; 0 for royalty-only
    uint16 managerShareBps;   // royalty on the vault's royalty base, at most 500
    uint32 maxPrepaidDays;    // 0 means 90; at most 365
    bool approvalRequired;    // vaults need your approval to subscribe
    string metadataUri;
}
function registerProvider(ProviderParams calldata p) external returns (uint64 providerId);
```

**viem**

```ts
import { createPublicClient, createWalletClient, defineChain, http, parseAbi, parseEventLogs, parseUnits, type Address } from "viem";
import { privateKeyToAccount } from "viem/accounts";

const hyperEvm = defineChain({
  id: 999,
  name: "HyperEVM",
  nativeCurrency: { name: "HYPE", symbol: "HYPE", decimals: 18 },
  rpcUrls: { default: { http: ["https://rpc.hyperliquid.xyz/evm"] } },
});

const REGISTRY = process.env.REGISTRY as Address; // DataProviderRegistry, published at launch
const PAYOUT = process.env.PAYOUT as Address;
const account = privateKeyToAccount(process.env.PROVIDER_KEY as `0x${string}`);
const publicClient = createPublicClient({ chain: hyperEvm, transport: http() });
const wallet = createWalletClient({ account, chain: hyperEvm, transport: http() });

export const registryAbi = parseAbi([
  "struct ProviderParams { address payoutRecipient; uint256 dailyUsdcFee; uint16 managerShareBps; uint32 maxPrepaidDays; bool approvalRequired; string metadataUri; }",
  "function registerProvider(ProviderParams p) returns (uint64 providerId)",
  "function updateProvider(uint64 providerId, ProviderParams p)",
  "function setProviderApproval(uint64 providerId, address vault, bool approved)",
  "function claim(uint64 providerId, address[] vaults) returns (uint256 totalPaid)",
  "function cancel(address vault, uint64 providerId) returns (uint256 refundedUsdc)",
  "function finalize(address vault, uint64 providerId) returns (uint256 refundedUsdc)",
  "event ProviderRegistered(uint64 indexed providerId, address indexed owner, address indexed payoutRecipient, uint256 dailyUsdcFee, uint16 managerShareBps, uint32 maxPrepaidDays, bool approvalRequired, string metadataUri)",
  "error InvalidPolicy()",
  "error ZeroAddress()",
]);

const { request } = await publicClient.simulateContract({
  account, address: REGISTRY, abi: registryAbi, functionName: "registerProvider",
  args: [{
    payoutRecipient: PAYOUT,
    dailyUsdcFee: parseUnits("20", 6), // 20 USDC per day
    managerShareBps: 200,              // plus 2% of the vault's royalty base
    maxPrepaidDays: 0,                 // default: 90 days
    approvalRequired: false,
    metadataUri: "ipfs://bafy.../manifest.json",
  }],
});
const receipt = await publicClient.waitForTransactionReceipt({ hash: await wallet.writeContract(request) });
const [registered] = parseEventLogs({ abi: registryAbi, eventName: "ProviderRegistered", logs: receipt.logs });
console.log("providerId", registered.args.providerId);
```

**cast**

```bash
cast send $REGISTRY "registerProvider((address,uint256,uint16,uint32,bool,string))" \
  "($PAYOUT,20000000,200,0,false,ipfs://bafy.../manifest.json)" \
  --rpc-url $HYPEREVM_RPC --account provider
```

The caller becomes the provider's owner. The feed starts active with the `UNVERIFIED` badge. Provider ids count from 1.

Reverts: `ZeroAddress()` for a zero payout address; `InvalidPolicy()` for a royalty above 500 bps or `maxPrepaidDays` above 365.

## Step 3: Approve vaults

Skip this step if `approvalRequired` is false. Otherwise approve each vault before it subscribes:

**viem**

```ts
await wallet.writeContract({
  address: REGISTRY, abi: registryAbi, functionName: "setProviderApproval", args: [providerId, VAULT, true],
});
```

**cast**

```bash
cast send $REGISTRY "setProviderApproval(uint64,address,bool)" $PROVIDER_ID $VAULT true --rpc-url $HYPEREVM_RPC --account provider
```

Revoking an approval stops new subscriptions and renewals from that vault; it does not end a live one. To end one, use `cancel` (last step).

## Step 4: Let vaults subscribe

The vault side calls `subscribe`. On a third-party vault, the strategy manager or the council may call it; on a flagship, only the council. The prepaid fee comes from the caller's wallet, not from vault assets.

```solidity
function subscribe(address vault, uint64 providerId, uint32 numDays, uint256 maxDailyUsdcFee, uint16 maxShareBps) external;
```

**cast**

```bash
# manager: approve numDays * dailyUsdcFee, then subscribe for 30 days
cast send $USDC "approve(address,uint256)" $REGISTRY 600000000 --rpc-url $HYPEREVM_RPC --account manager
cast send $REGISTRY "subscribe(address,uint64,uint32,uint256,uint16)" $VAULT $PROVIDER_ID 30 20000000 200 \
  --rpc-url $HYPEREVM_RPC --account manager
```

`maxDailyUsdcFee` and `maxShareBps` protect the subscriber: if your live terms exceed them, `subscribe` reverts with `TermsExceeded()`. Terms lock when the subscription starts. Other reverts a manager can hit:

| Revert | Cause |
|---|---|
| `UnauthorizedVault(vault)` | Not a factory vault and not allowlisted |
| `ProviderInactive(providerId)` | You deactivated the feed, or the council suspended it |
| `VaultNotApproved(vault, providerId)` | Approval required and not given |
| `InvalidPolicy()` | `numDays` is 0, or the paid time would run past `maxPrepaidDays` |
| `MaxFeedsReached(vault)` | The vault already has 20 royalty feeds |
| `MaxCombinedShareExceeded(vault, combinedBps)` | Royalties on the vault would pass 5,000 bps |
| `ProviderTerminating(vault, providerId)` | You gave notice on this subscription; it must be finalized first |

Renewal is the same call. While escrow remains, only the original payer can renew, at the locked daily fee.

## Step 5: Serve the data

The vault names one data key for all its feeds with `setVaultDataKey`. Your API accepts requests signed by that key, the vault's keeper or its manager, and checks each one with `verifyAccess(vault, providerId, signer)`. [Gating access](https://docs.degenhive.ai/data/access.md) has a full challenge and response example.

## Step 6: Collect what you earn

```solidity
function claim(uint64 providerId, address[] calldata vaults) external returns (uint256 totalPaid);
```

Anyone can call `claim`. For each vault listed, it settles the prepaid stream up to now (finalizing subscriptions that are ready). Then it pays all of `claimablePrepaid + claimableRoyalties` to your payout address. Royalties need no vault list: the fee router credits them at each vault's fee flush.

**viem**

```ts
const hash = await wallet.writeContract({
  address: REGISTRY, abi: registryAbi, functionName: "claim", args: [providerId, [VAULT_A, VAULT_B]],
});
await publicClient.waitForTransactionReceipt({ hash });
```

**cast**

```bash
cast send $REGISTRY "claim(uint64,address[])" $PROVIDER_ID "[$VAULT_A,$VAULT_B]" --rpc-url $HYPEREVM_RPC --account provider
```

It reverts with `ZeroAmount()` when there is nothing to pay. Read `provider(providerId)` for settled balances, and `subscription(vault, providerId).accruedPrepaid` for what has streamed but not yet settled. The `Subscribed` and `RoyaltySettled` events, or `GET /v1/data/subscriptions` on the [API](https://docs.degenhive.ai/api.md), list your subscribers.

## Step 7: Change terms or ownership

- `updateProvider(providerId, params)` changes price, royalty, payout address, approval mode or manifest. New terms apply to new subscriptions and renewals only.
- `setProviderActive(providerId, false)` stops new subscriptions. Live subscriptions keep access and keep paying.
- `transferProviderOwnership(providerId, newOwner)` hands the feed to another address in one step. Check the address twice; there is no accept step.

## Step 8: End a subscription

Either side can end a subscription with the same function, `cancel(vault, providerId)`. The registry tells the sides apart by caller.

| Who cancels | Effect |
|---|---|
| You (provider owner) | Notice period: access ends at the earlier of `paidUntil` and 7 days from now. The prepaid stream settles first. A second notice reverts with `AlreadyCancelled()`. |
| The manager | Access ends now and the remaining escrow is refunded at once. A royalty feed still earns on every vault epoch before the next one. |

After access ends and the vault has rolled past it, anyone calls `finalize(vault, providerId)`. It settles what you earned, refunds unstreamed escrow to the payer and deletes the subscription. A subscription that simply lapses can be finalized a day after `paidUntil`, once no performance fee is still pending. Until then, `finalize` reverts with `NotReadyToFinalize()`.

## Step 9: Where to go next

- [Gating access](https://docs.degenhive.ai/data/access.md) Authenticate subscribers in your API.
- [Data marketplace](https://docs.degenhive.ai/data.md) Pricing models, take, badges and suspension.
- [Fees](https://docs.degenhive.ai/vaults/fees.md) How performance royalties flow from vaults.
- [API](https://docs.degenhive.ai/api.md) Read providers and subscriptions without a node.
