Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unclaimed fees #51

Open
wants to merge 1 commit into
base: gmx-vault
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions contracts/interfaces/gmx/IRewardRouterV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ interface IRewardRouterV2 {
event StakeGlp(address account, uint256 amount);
event UnstakeGlp(address account, uint256 amount);

function feeGmxTracker() external view returns (address);

function feeGlpTracker() external view returns (address);

function batchStakeGmxForAccount(address[] memory _accounts, uint256[] memory _amounts) external;

function stakeGmxForAccount(address _account, uint256 _amount) external;
Expand Down
16 changes: 14 additions & 2 deletions contracts/yieldStrategy/gmx/GlpStakingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IERC20Metadata } from '@openzeppelin/contracts/interfaces/IERC20Metadat
import { IGlpManager } from 'contracts/interfaces/gmx/IGlpManager.sol';
import { IVault as IGMXVault } from 'contracts/interfaces/gmx/IVault.sol';
import { ISGLPExtended } from 'contracts/interfaces/gmx/ISGLPExtended.sol';
import { IRewardTracker } from 'contracts/interfaces/gmx/IRewardTracker.sol';
import { IRewardRouterV2 } from 'contracts/interfaces/gmx/IRewardRouterV2.sol';
import { IGMXBatchingManager } from 'contracts/interfaces/gmx/IGMXBatchingManager.sol';
import { FullMath } from '@uniswap/v3-core-0.8-support/contracts/libraries/FullMath.sol';
Expand Down Expand Up @@ -152,7 +153,7 @@ contract GlpStakingManager is RageERC4626, OwnableUpgradeable {
}

/// @notice stakes the rewards from the staked Glp and claims WETH to buy glp
function _harvestFees() internal {
function harvestFees() public {
rewardRouter.handleRewards(
false, // _shouldClaimGmx
false, // _shouldStakeGmx
Expand Down Expand Up @@ -185,7 +186,7 @@ contract GlpStakingManager is RageERC4626, OwnableUpgradeable {
function _beforeShareAllocation() internal override {
/// @dev check if the msg.sender is vault
if (!isVault[msg.sender]) revert GSM_CALLER_NOT_VAULT();
_harvestFees();
harvestFees();
}

/* solhint-disable no-empty-blocks */
Expand All @@ -207,6 +208,17 @@ contract GlpStakingManager is RageERC4626, OwnableUpgradeable {
return fsGlp.balanceOf(address(this)) + batchingManager.stakingManagerGlpBalance();
}

/// @notice unclaimed WETH rewards of sGlp, esGmx & bnGmx
function unclaimedFees() external view returns (uint256) {
IRewardTracker feeGmxTracker = IRewardTracker(rewardRouter.feeGmxTracker());
IRewardTracker feeGlpTracker = IRewardTracker(rewardRouter.feeGlpTracker());

uint256 wethGmx = feeGmxTracker.claimable(address(this));
uint256 wethGlp = feeGlpTracker.claimable(address(this));

return wethGmx + wethGlp;
}

/// @notice converts input token to sGLP
/// @dev only works for usdc and weth because approval is only given for those tokens
/// @param token address of token
Expand Down