Skip to content

Commit

Permalink
Use rew tokens state variable. Use decimals in UniV2 compounder
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreadinenno committed Jun 13, 2024
1 parent 6a6de72 commit 9afc7f8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
10 changes: 9 additions & 1 deletion src/peripheral/BaseUniV2Compounder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.25;

import {UniswapV2TradeLibrary, IUniswapRouterV2} from "./UniswapV2TradeLibrary.sol";
import {IERC20} from "openzeppelin-contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "openzeppelin-contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "openzeppelin-contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "openzeppelin-contracts/utils/math/Math.sol";

Expand Down Expand Up @@ -32,8 +33,15 @@ abstract contract BaseUniV2Compounder {
uint256 totAmount = IERC20(sellTokens[i]).balanceOf(address(this));

// sell half for tokenA
uint256 decimals = IERC20Metadata(sellTokens[i]).decimals();
uint256 amount = totAmount.mulDiv(
10**decimals,
20**decimals,
Math.Rounding.Floor
);

swap = sellSwaps[2 * i];
uint256 amount = totAmount.mulDiv(1e18, 2e18, Math.Rounding.Floor);

if (amount > 0) {
UniswapV2TradeLibrary.trade(router, swap.path, address(this), block.timestamp, amount, 0);
}
Expand Down
7 changes: 1 addition & 6 deletions src/strategies/peapods/PeapodsBalancerUniV2Compounder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract PeapodsDepositorBalancerUniV2Compounder is PeapodsDepositor, BaseBalanc

/// @notice The token rewarded from the pendle market
function rewardTokens() external view override returns (address[] memory) {
return _getRewardTokens();
return sellTokens;
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -82,9 +82,4 @@ contract PeapodsDepositorBalancerUniV2Compounder is PeapodsDepositor, BaseBalanc
setUniswapTradeValues(newUniswapRouter, rewTokens, newSwapSteps);
setBalancerLpCompounderValues(newBalancerVault, newTradePaths, harvestValues_);
}

function _getRewardTokens() internal view returns (address[] memory tokens) {
tokens = new address[](1);
tokens[0] = poolRewards.rewardsToken();
}
}
10 changes: 3 additions & 7 deletions src/strategies/peapods/PeapodsUniswapV2Compounder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract PeapodsDepositorUniswapV2Compounder is PeapodsDepositor, BaseUniV2LpCom

/// @notice The token rewarded from the pendle market
function rewardTokens() external view override returns (address[] memory) {
return _getRewardTokens();
return sellTokens;
}

/*//////////////////////////////////////////////////////////////
Expand All @@ -66,11 +66,12 @@ contract PeapodsDepositorUniswapV2Compounder is PeapodsDepositor, BaseUniV2LpCom
}

function setHarvestValues(
address[] memory rewTokens,
address newRouter,
address[2] memory newDepositAssets,
SwapStep[] memory newSwaps
) external onlyOwner {
setUniswapLpCompounderValues(newRouter, newDepositAssets, _getRewardTokens(), newSwaps);
setUniswapLpCompounderValues(newRouter, newDepositAssets, rewTokens, newSwaps);
}

// allow owner to withdraw eventual dust amount of tokens
Expand All @@ -81,9 +82,4 @@ contract PeapodsDepositorUniswapV2Compounder is PeapodsDepositor, BaseUniV2LpCom

IERC20(token).safeTransfer(owner, IERC20(token).balanceOf(address(this)));
}

function _getRewardTokens() internal view returns (address[] memory tokens) {
tokens = new address[](1);
tokens[0] = poolRewards.rewardsToken();
}
}
6 changes: 6 additions & 0 deletions test/strategies/peapods/PeapodsUniV2Compounder.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"0x3a590132Da355fdf36656807e9DB8ea1c9f4a431",
"0x6B175474E89094C44Da98b954EedeAC495271d0F"
],
"rewards": {
"length": 1,
"tokens": [
"0x02f92800F57BCD74066F5709F1Daa1A4302Df875"
]
},
"tradePaths": [
{
"length": "4",
Expand Down
11 changes: 10 additions & 1 deletion test/strategies/peapods/PeapodsUniswapV2Compounder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ contract PeapodsUniswapV2CompounderTest is BaseStrategyTest {
swaps[0] = SwapStep(swap0);
swaps[1] = SwapStep(swap1);

strategy.setHarvestValues(router, depositAssets, swaps);
// rewards
uint256 rewLen = json_.readUint(string.concat(".configs[", index_, "].specific.harvest.rewards.length"));
address[] memory rewardTokens = new address[](rewLen);
for(uint256 i=0; i<rewLen; i++) {
rewardTokens[i] = json_.readAddress(
string.concat(".configs[", index_, "].specific.harvest.rewards.tokens[", vm.toString(i), "]"));
}

strategy.setHarvestValues(rewardTokens, router, depositAssets, swaps);

asset = strategy.asset();

return IBaseStrategy(address(strategy));
Expand Down

0 comments on commit 9afc7f8

Please sign in to comment.