-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #353 from lidofinance/feature/si-1434-fix-rewards-fee
fix: fee from staking router
- Loading branch information
Showing
6 changed files
with
211 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_depositContract", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "uint256", | ||
"name": "stakingModuleId", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "stakingModuleFee", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "treasuryFee", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "setBy", | ||
"type": "address" | ||
} | ||
], | ||
"name": "StakingModuleFeesSet", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "FEE_PRECISION_POINTS", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "TOTAL_BASIS_POINTS", | ||
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "getLido", | ||
"outputs": [{ "internalType": "address", "name": "", "type": "address" }], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "getStakingFeeAggregateDistribution", | ||
"outputs": [ | ||
{ "internalType": "uint96", "name": "modulesFee", "type": "uint96" }, | ||
{ "internalType": "uint96", "name": "treasuryFee", "type": "uint96" }, | ||
{ "internalType": "uint256", "name": "basePrecision", "type": "uint256" } | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "getStakingFeeAggregateDistributionE4Precision", | ||
"outputs": [ | ||
{ "internalType": "uint16", "name": "modulesFee", "type": "uint16" }, | ||
{ "internalType": "uint16", "name": "treasuryFee", "type": "uint16" } | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "getStakingRewardsDistribution", | ||
"outputs": [ | ||
{ | ||
"internalType": "address[]", | ||
"name": "recipients", | ||
"type": "address[]" | ||
}, | ||
{ | ||
"internalType": "uint256[]", | ||
"name": "stakingModuleIds", | ||
"type": "uint256[]" | ||
}, | ||
{ | ||
"internalType": "uint96[]", | ||
"name": "stakingModuleFees", | ||
"type": "uint96[]" | ||
}, | ||
{ "internalType": "uint96", "name": "totalFee", "type": "uint96" }, | ||
{ | ||
"internalType": "uint256", | ||
"name": "precisionPoints", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "getTotalFeeE4Precision", | ||
"outputs": [ | ||
{ "internalType": "uint16", "name": "totalFee", "type": "uint16" } | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ "stateMutability": "payable", "type": "receive" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { CHAINS } from '@lido-sdk/constants'; | ||
import { contractHooksFactory } from '@lido-sdk/react'; | ||
import invariant from 'tiny-invariant'; | ||
|
||
import { PartialStakingRouterAbi__factory } from 'generated/factories/PartialStakingRouterAbi__factory'; | ||
|
||
export const STAKING_ROUTER_BY_NETWORK: { | ||
[key in CHAINS]?: string; | ||
} = { | ||
[CHAINS.Mainnet]: '0xFdDf38947aFB03C621C71b06C9C70bce73f12999', | ||
[CHAINS.Holesky]: '0xd6EbF043D30A7fe46D1Db32BA90a0A51207FE229', | ||
}; | ||
|
||
export const getStakingRouterAddress = (chainId: CHAINS): string => { | ||
const address = STAKING_ROUTER_BY_NETWORK[chainId]; | ||
invariant(address, 'chain is not supported'); | ||
return address; | ||
}; | ||
|
||
export const stakingRouter = contractHooksFactory( | ||
PartialStakingRouterAbi__factory, | ||
(chainId) => getStakingRouterAddress(chainId), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { formatEther } from '@ethersproject/units'; | ||
|
||
import { CHAINS } from '@lido-sdk/constants'; | ||
import { useLidoSWR, useSDK } from '@lido-sdk/react'; | ||
import { useStakingRouter } from './use-stakign-router-contract'; | ||
import { PartialStakingRouterAbi } from 'generated/PartialStakingRouterAbi'; | ||
|
||
import { config } from 'config'; | ||
import { STRATEGY_CONSTANT } from 'consts/swr-strategies'; | ||
|
||
export const useProtocolFee = () => { | ||
const { chainId } = useSDK(); | ||
const { contractRpc } = useStakingRouter(); | ||
|
||
return useLidoSWR<number>( | ||
['swr:useProtocolFee', chainId, contractRpc, config.enableQaHelpers], | ||
// @ts-expect-error broken lidoSWR typings | ||
async ( | ||
_key: string, | ||
_chainId: CHAINS, | ||
contractRpc: PartialStakingRouterAbi, | ||
shouldMock: boolean, | ||
) => { | ||
const mockDataString = window.localStorage.getItem('protocolFee'); | ||
|
||
if (shouldMock && mockDataString) { | ||
try { | ||
const mockData = JSON.parse(mockDataString); | ||
return mockData; | ||
} catch (e) { | ||
console.warn('Failed to load mock data'); | ||
console.warn(e); | ||
} | ||
} | ||
|
||
const fee = await contractRpc.getStakingFeeAggregateDistribution(); | ||
const value = Number(formatEther(fee.modulesFee.add(fee.treasuryFee))); | ||
|
||
return value.toFixed(0); | ||
}, | ||
{ | ||
...STRATEGY_CONSTANT, | ||
refreshInterval: 60000, | ||
}, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { stakingRouter } from 'consts/staking-router'; | ||
|
||
export const useStakingRouter = () => { | ||
const contractRpc = stakingRouter.useContractRPC(); | ||
|
||
return { contractRpc }; | ||
}; |