Skip to content

Commit 572d927

Browse files
authored
feat(rewards): add staking rewards (#1220)
1 parent a63293f commit 572d927

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

docs/network/fsp/5-solidity-reference.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const contracts = [
2020
"VoterRegistry",
2121
"FlareSystemsCalculator",
2222
"WNatDelegationFee",
23+
"ValidatorRewardManager",
2324
];
2425

2526
<Tabs block>

docs/network/fsp/guides/claiming-rewards.mdx

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ You will:
1515
- read the claimable reward epoch range onchain,
1616
- fetch the distribution tuples JSON offchain,
1717
- extract your Merkle proof + claim tuple,
18-
- submit `RewardManager.claim(...)`.
18+
- submit `RewardManager.claim(...)`,
19+
- claim staking rewards `ValidatorRewardManager.claim(...)`.
1920

2021
:::warning[Reward claim period]
2122

22-
Delegation rewards expire after 25 reward epochs. Make sure to claim before then.
23+
Delegation rewards expire after 25 reward epochs, make sure to claim before then.
24+
Staking rewards do not expire.
2325

2426
Learn more about how [signing](/network/fsp/weights-and-signing) and [rewards](/network/fsp/rewarding) work in the FSP.
2527

@@ -33,6 +35,7 @@ Learn more about how [signing](/network/fsp/weights-and-signing) and [rewards](/
3335
- [`FlareSystemsManager`](/network/fsp/solidity-reference/IFlareSystemsManager)
3436
- [`RewardManager`](/network/fsp/solidity-reference/IRewardManager)
3537
- [`ClaimSetupManager`](/network/solidity-reference/IClaimSetupManager)
38+
- [`ValidatorRewardManager`](/network/fsp/solidity-reference)
3639
4. **Recipient address:** The address that will receive the rewards (`recipient`).
3740
5. **Reward distribution data access:** You must be able to fetch per-epoch `reward-distribution-data-tuples.json` from the official distribution locations on GitHub or GitLab.
3841
6. **Wrap option:** `wrapRewards` is `true` unless explicitly set to `false`, i.e. on Flare Mainnet you will receive `WFLR`.
@@ -332,6 +335,60 @@ await tx.wait();
332335
console.log("Confirmed:", tx.hash);
333336
```
334337

338+
### 7. Claim staking rewards
339+
340+
:::tip
341+
342+
You can also claim staking rewards via the [Flare Portal](https://portal.flare.network/) or using the [flare-tx-sdk](/network/flare-tx-sdk).
343+
344+
:::
345+
346+
Instantiate contract clients (ABI + address) for:
347+
348+
- [`ValidatorRewardManager`](/network/fsp/solidity-reference)
349+
350+
```ts
351+
import { JsonRpcProvider, Wallet, Contract } from "ethers";
352+
353+
// 1) Provider + signer
354+
const provider = new JsonRpcProvider(process.env.RPC_URL);
355+
// Signer must be a self-bond address or an address used for delegating stake.
356+
const stakingSigner = new Wallet(process.env.STAKING_PRIVATE_KEY!, provider);
357+
358+
// 2) Contract instances (ABI omitted here; use your generated ABI or interface)
359+
const validatorRewardManager = new Contract(
360+
process.env.VALIDATOR_REWARD_MANAGER_ADDRESS!,
361+
VALIDATOR_REWARD_MANAGER_ABI,
362+
provider,
363+
);
364+
```
365+
366+
Call:
367+
368+
`ValidatorRewardManager.claim(rewardOwner, recipient, rewardAmount, wrapRewards)`
369+
370+
Where:
371+
372+
- `rewardOwner`: self-bond address or address used for delegating stake
373+
- `recipient`: the address that should receive rewards
374+
- `rewardAmount`: amount of rewards to be claimed
375+
- `wrapRewards`: boolean (`true` unless explicitly set to `false`)
376+
377+
Example:
378+
379+
```ts
380+
const state = await validatorRewardManager.getStateOfRewards(rewardOwner);
381+
let rewardAmount = state[0] - state[1];
382+
383+
const tx = await validatorRewardManager
384+
.connect(stakingSigner)
385+
.claim(rewardOwner, recipient, rewardAmount, wrapRewards);
386+
387+
console.log("Submitted:", tx.hash);
388+
await tx.wait();
389+
console.log("Confirmed:", tx.hash);
390+
```
391+
335392
## Troubleshooting
336393

337394
<details>

docs/network/guides/flare-for-react-developers.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This guide is for React developers who want to interact with Flare using [Wagmi]
2222

2323
The package provides two ways to read and write Flare contracts:
2424

25-
- **Generic hooks:** use Wagmi's [`useReadContract`](https://wagmi.sh/react/hooks/useReadContract) with typed ABIs imported from the Flare Wagmi Periphery package.
25+
- **Generic hooks:** use Wagmi's [`useReadContract`](https://wagmi.sh/react/api/hooks/useReadContract) with typed ABIs imported from the Flare Wagmi Periphery package.
2626
- **Contract-specific hooks:** use auto-generated hooks like `useReadIFlareContractRegistry` that already know the ABI.
2727

2828
In this guide, you will set up a React project, configure Wagmi for Flare, and query the [`WNat`](/network/solidity-reference/IWNat) contract address from the [`FlareContractRegistry`](/network/solidity-reference/IFlareContractRegistry) using both approaches.
@@ -95,7 +95,7 @@ The example below queries the [`FlareContractRegistry`](/network/solidity-refere
9595

9696
It demonstrates both approaches to query the contract data:
9797

98-
- **Generic hooks:** use Wagmi's [`useReadContract`](https://wagmi.sh/react/hooks/useReadContract) with typed ABIs imported from the Flare Wagmi Periphery package.
98+
- **Generic hooks:** use Wagmi's [`useReadContract`](https://wagmi.sh/react/api/hooks/useReadContract) with typed ABIs imported from the Flare Wagmi Periphery package.
9999
- **Contract-specific hooks:** use auto-generated hooks like `useReadIFlareContractRegistry` that already know the ABI.
100100

101101
```typescript title="src/WNatQuery.tsx"
@@ -190,7 +190,7 @@ The app will query the [`FlareContractRegistry`](/network/solidity-reference/IFl
190190

191191
### Generic hooks
192192

193-
The generic approach uses the [`useReadContract`](https://wagmi.sh/react/hooks/useReadContract) hook from Wagmi.
193+
The generic approach uses the [`useReadContract`](https://wagmi.sh/react/api/hooks/useReadContract) hook from Wagmi.
194194
You import the typed ABI (`iFlareContractRegistryAbi`) from the package and pass it as the `abi` prop.
195195
This gives you complete type safety for `functionName` and `args`.
196196

0 commit comments

Comments
 (0)