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

Add Deposit and Withdraw event for LP staking #40

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions contracts/solidity/NFTXLPStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ contract NFTXLPStaking is PausableUpgradeable {
event PoolUpdated(uint256 vaultId, address pool);
event FeesReceived(uint256 vaultId, uint256 amount);

event Deposit(uint256 vaultId, address stakingToken, uint256 amount, address account, uint256 timelockLength);
event Withdraw(uint256 vaultId, address stakingToken, uint256 amount, address account);

struct StakingPool {
address stakingToken;
address rewardToken;
Expand Down Expand Up @@ -136,10 +139,13 @@ contract NFTXLPStaking is PausableUpgradeable {
// Maintain the same timelock if they already have one.
// We do this instead of patching in the token because
// the xSLP contracts as currently deployed are not upgradeable.
xSLPToken.timelockMint(msg.sender, amount, currentTimelock-block.timestamp);
uint256 timestamp = currentTimelock-block.timestamp;
xSLPToken.timelockMint(msg.sender, amount, timestamp);
emit Deposit(vaultId, pool.stakingToken, amount, msg.sender, timestamp);
} else {
// Timelock for 2 seconds if they don't already have a timelock to prevent flash loans.
xSLPToken.timelockMint(msg.sender, amount, 2);
emit Deposit(vaultId, pool.stakingToken, amount, msg.sender, 2);
}
}

Expand All @@ -156,13 +162,14 @@ contract NFTXLPStaking is PausableUpgradeable {
require(pool.stakingToken != address(0), "LPStaking: Nonexistent pool");
IERC20Upgradeable(pool.stakingToken).safeTransferFrom(msg.sender, address(this), amount);
_rewardDistributionTokenAddr(pool).timelockMint(account, amount, timelockLength);
emit Deposit(vaultId, pool.stakingToken, amount, account, timelockLength);
}

function exit(uint256 vaultId) external {
StakingPool memory pool = vaultStakingInfo[vaultId];
_distributeFees(vaultId);
_claimRewards(pool, msg.sender);
_withdraw(pool, balanceOf(vaultId, msg.sender), msg.sender);
_withdraw(vaultId, pool, balanceOf(vaultId, msg.sender), msg.sender);
}

function emergencyExitAndClaim(address _stakingToken, address _rewardToken) external {
Expand All @@ -171,14 +178,14 @@ contract NFTXLPStaking is PausableUpgradeable {
require(isContract(address(dist)), "Not a pool");
_distributeFees(INFTXVault(_rewardToken).vaultId());
_claimRewards(pool, msg.sender);
_withdraw(pool, dist.balanceOf(msg.sender), msg.sender);
_withdraw(INFTXVault(_rewardToken).vaultId(), pool, dist.balanceOf(msg.sender), msg.sender);
}

function emergencyExit(address _stakingToken, address _rewardToken) external {
StakingPool memory pool = StakingPool(_stakingToken, _rewardToken);
TimelockRewardDistributionTokenImpl dist = _rewardDistributionTokenAddr(pool);
require(isContract(address(dist)), "Not a pool");
_withdraw(pool, dist.balanceOf(msg.sender), msg.sender);
_withdraw(INFTXVault(_rewardToken).vaultId(), pool, dist.balanceOf(msg.sender), msg.sender);
}

// function emergencyMigrate(uint256 vaultId) external {
Expand Down Expand Up @@ -216,7 +223,7 @@ contract NFTXLPStaking is PausableUpgradeable {
StakingPool memory pool = vaultStakingInfo[vaultId];
_distributeFees(vaultId);
_claimRewards(pool, msg.sender);
_withdraw(pool, amount, msg.sender);
_withdraw(vaultId, pool, amount, msg.sender);
}

function claimRewards(uint256 vaultId) public {
Expand Down Expand Up @@ -310,10 +317,11 @@ contract NFTXLPStaking is PausableUpgradeable {
_rewardDistributionTokenAddr(pool).withdrawReward(account);
}

function _withdraw(StakingPool memory pool, uint256 amount, address account) internal {
function _withdraw(uint256 vaultId, StakingPool memory pool, uint256 amount, address account) internal {
require(pool.stakingToken != address(0), "LPStaking: Nonexistent pool");
_rewardDistributionTokenAddr(pool).burnFrom(account, amount);
IERC20Upgradeable(pool.stakingToken).safeTransfer(account, amount);
emit Withdraw(vaultId, pool.stakingToken, amount, account);
}

function _deployDividendToken(StakingPool memory pool) internal returns (address) {
Expand Down