Skip to content
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
2 changes: 1 addition & 1 deletion contracts/strategies/VariableRewardsStrategyForSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract contract VariableRewardsStrategyForSA is VariableRewardsStrategy {
assignSwapPairSafely(_swapPairDepositToken);
}

function assignSwapPairSafely(address _swapPairDepositToken) private {
function assignSwapPairSafely(address _swapPairDepositToken) internal virtual {
if (address(rewardToken) != address(depositToken)) {
require(
DexLibrary.checkSwapPairCompatibility(
Expand Down
28 changes: 15 additions & 13 deletions contracts/strategies/avalanche/vector/VectorStrategyForSAV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@ pragma solidity 0.8.13;

import "../../VariableRewardsStrategyForSA.sol";
import "../../../lib/SafeERC20.sol";
import "../../../lib/SafeMath.sol";
import "../../../interfaces/IBoosterFeeCollector.sol";

import "./interfaces/IVectorMainStaking.sol";
import "./interfaces/IVectorPoolHelperV2.sol";

contract VectorStrategyForSAV2 is VariableRewardsStrategyForSA {
using SafeMath for uint256;
using SafeERC20 for IERC20;

struct VectorStrategyForSAV2Settings {
address swapPairDepositToken;
address vectorMainStaking;
address boosterFeeCollector;
}

IERC20 private constant PTP = IERC20(0x22d4002028f537599bE9f666d1c4Fa138522f9c8);
IERC20 private constant VTX = IERC20(0x5817D4F0b62A59b17f75207DA1848C2cE75e7AF4);

IVectorMainStaking public immutable vectorMainStaking;
IBoosterFeeCollector public boosterFeeCollector;

constructor(
address _swapPairDepositToken,
address _stakingContract,
address _boosterFeeCollector,
VectorStrategyForSAV2Settings memory _vectorStrategyForSAV2Settings,
VariableRewardsStrategySettings memory _settings,
StrategySettings memory _strategySettings
) VariableRewardsStrategyForSA(_swapPairDepositToken, _settings, _strategySettings) {
vectorMainStaking = IVectorMainStaking(_stakingContract);
boosterFeeCollector = IBoosterFeeCollector(_boosterFeeCollector);
) VariableRewardsStrategyForSA(_vectorStrategyForSAV2Settings.swapPairDepositToken, _settings, _strategySettings) {
vectorMainStaking = IVectorMainStaking(_vectorStrategyForSAV2Settings.vectorMainStaking);
boosterFeeCollector = IBoosterFeeCollector(_vectorStrategyForSAV2Settings.boosterFeeCollector);
}

function updateBoosterFeeCollector(address _collector) public onlyOwner {
Expand All @@ -45,7 +47,7 @@ contract VectorStrategyForSAV2 is VariableRewardsStrategyForSA {
uint256 balanceBefore = depositToken.balanceOf(address(this));
_vectorPoolHelper().withdraw(_amount, 0);
uint256 balanceAfter = depositToken.balanceOf(address(this));
return balanceAfter.sub(balanceBefore);
return balanceAfter - balanceBefore;
}

function _emergencyWithdraw() internal override {
Expand All @@ -54,13 +56,13 @@ contract VectorStrategyForSAV2 is VariableRewardsStrategyForSA {
vectorPoolHelper.withdraw(totalDeposits(), 0);
}

function _pendingRewards() internal view override returns (Reward[] memory) {
function _pendingRewards() internal view virtual override returns (Reward[] memory) {
IVectorPoolHelperV2 vectorPoolHelper = _vectorPoolHelper();
uint256 count = rewardCount;
Reward[] memory pendingRewards = new Reward[](count);
(uint256 pendingVTX, uint256 pendingPTP) = vectorPoolHelper.earned(address(PTP));
uint256 boostFee = boosterFeeCollector.calculateBoostFee(address(this), pendingPTP);
pendingRewards[0] = Reward({reward: address(PTP), amount: pendingPTP.sub(boostFee)});
pendingRewards[0] = Reward({reward: address(PTP), amount: pendingPTP - boostFee});
pendingRewards[1] = Reward({reward: address(VTX), amount: pendingVTX});
uint256 offset = 2;
for (uint256 i = 0; i < count; i++) {
Expand All @@ -75,10 +77,10 @@ contract VectorStrategyForSAV2 is VariableRewardsStrategyForSA {
return pendingRewards;
}

function _getRewards() internal override {
function _getRewards() internal virtual override {
uint256 ptpBalanceBefore = PTP.balanceOf(address(this));
_vectorPoolHelper().getReward();
uint256 amount = PTP.balanceOf(address(this)).sub(ptpBalanceBefore);
uint256 amount = PTP.balanceOf(address(this)) - ptpBalanceBefore;
uint256 boostFee = boosterFeeCollector.calculateBoostFee(address(this), amount);
PTP.safeTransfer(address(boosterFeeCollector), boostFee);
}
Expand Down
58 changes: 58 additions & 0 deletions contracts/strategies/avalanche/vector/YYAvaxVectorStrategy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

import "./VectorStrategyForSAV2.sol";
import "./../platypus/interfaces/IPlatypusAsset.sol";
import "./../platypus/interfaces/IPlatypusPool.sol";

contract YYAvaxVectorStrategy is VectorStrategyForSAV2 {
address public constant yyAVAX = 0xF7D9281e8e363584973F946201b82ba72C965D27;
IPlatypusPool immutable pool;

constructor(
VectorStrategyForSAV2Settings memory _vectorStrategyForSAV2Settings,
VariableRewardsStrategySettings memory _variableRewardsStrategySettings,
StrategySettings memory _strategySettings
) VectorStrategyForSAV2(_vectorStrategyForSAV2Settings, _variableRewardsStrategySettings, _strategySettings) {
(, , , address asset, , , , , ) = IVectorMainStaking(_vectorStrategyForSAV2Settings.vectorMainStaking)
.getPoolInfo(yyAVAX);
pool = IPlatypusPool(IPlatypusAsset(asset).pool());
}

function assignSwapPairSafely(address _swapPairDepositToken) internal virtual override {
if (address(depositToken) != yyAVAX) {
super.assignSwapPairSafely(_swapPairDepositToken);
}
}

function _pendingRewards() internal view override returns (Reward[] memory) {
Reward[] memory rewards = super._pendingRewards();
for (uint256 i = 0; i < rewards.length; i++) {
if (rewards[i].reward == yyAVAX) {
(rewards[i].amount, ) = pool.quotePotentialSwap(yyAVAX, address(WAVAX), rewards[i].amount);
rewards[i].reward = address(WAVAX);
}
}
return rewards;
}

function _getRewards() internal override {
super._getRewards();
uint256 yyAvaxBalance = IERC20(yyAVAX).balanceOf(address(this));
if (yyAvaxBalance > 0) {
IERC20(yyAVAX).approve(address(pool), yyAvaxBalance);
pool.swap(yyAVAX, address(WAVAX), yyAvaxBalance, 0, address(this), type(uint256).max);
IERC20(yyAVAX).approve(address(pool), 0);
}
}

function _convertRewardTokenToDepositToken(uint256 _fromAmount) internal override returns (uint256 toAmount) {
if (address(depositToken) == yyAVAX) {
WAVAX.approve(address(pool), _fromAmount);
(toAmount, ) = pool.swap(address(WAVAX), yyAVAX, _fromAmount, 0, address(this), type(uint256).max);
WAVAX.approve(address(pool), 0);
} else {
return super._convertRewardTokenToDepositToken(_fromAmount);
}
}
}