Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.
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
62 changes: 41 additions & 21 deletions .openzeppelin/unknown-31337.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"address": "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
"txHash": "0x1b25bd0739cc1e0d1c850cfebd4273b79d2593c341e7e8a55df3259914468a3b",
"txHash": "0x865a93f841d6c73187ddd877834c2c70d4282a05b7e970227c02c085a6ac4b25",
"kind": "uups"
}
],
Expand Down Expand Up @@ -927,9 +927,9 @@
}
}
},
"08e568abb411d5c8caac9e482efebae786da16b3856a7277c4c7f7c78618d2b6": {
"d589917e3a1c0e8f02bc1bda753219a3899683e50e7d2a7eb6cea546e952206a": {
"address": "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
"txHash": "0x799f1e3a8ca9299a2e8416665af5d650cdca69975d1e2fc52a22fbe632d00e39",
"txHash": "0x7234df4f543caa7d96e4cf6ed42869291cb235b5752e47870b2d5cc87646179b",
"layout": {
"storage": [
{
Expand Down Expand Up @@ -1110,76 +1110,92 @@
"src": "contracts\\abstract\\ReaperBaseStrategyv4.sol:78"
},
{
"label": "usedPools",
"label": "wantToUsdcRoute",
"offset": 0,
"slot": "312",
"type": "t_bytes_storage",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:44"
},
{
"label": "usedPools",
"offset": 0,
"slot": "313",
"type": "t_struct(AddressSet)3096_storage",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:51"
"src": "contracts\\ReaperStrategyTarot.sol:57"
},
{
"label": "maxPools",
"offset": 0,
"slot": "314",
"slot": "315",
"type": "t_uint256",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:52"
"src": "contracts\\ReaperStrategyTarot.sol:58"
},
{
"label": "depositPool",
"offset": 0,
"slot": "315",
"slot": "316",
"type": "t_address",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:53"
"src": "contracts\\ReaperStrategyTarot.sol:59"
},
{
"label": "sharePriceSnapshot",
"offset": 0,
"slot": "316",
"slot": "317",
"type": "t_uint256",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:54"
"src": "contracts\\ReaperStrategyTarot.sol:60"
},
{
"label": "minProfitToChargeFees",
"offset": 0,
"slot": "317",
"slot": "318",
"type": "t_uint256",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:55"
"src": "contracts\\ReaperStrategyTarot.sol:61"
},
{
"label": "minWantToDepositOrWithdraw",
"offset": 0,
"slot": "318",
"slot": "319",
"type": "t_uint256",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:56"
"src": "contracts\\ReaperStrategyTarot.sol:62"
},
{
"label": "maxWantRemainingToRemovePool",
"offset": 0,
"slot": "319",
"slot": "320",
"type": "t_uint256",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:57"
"src": "contracts\\ReaperStrategyTarot.sol:63"
},
{
"label": "shouldHarvestOnDeposit",
"offset": 0,
"slot": "320",
"slot": "321",
"type": "t_bool",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:58"
"src": "contracts\\ReaperStrategyTarot.sol:64"
},
{
"label": "shouldHarvestOnWithdraw",
"offset": 1,
"slot": "320",
"slot": "321",
"type": "t_bool",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:59"
"src": "contracts\\ReaperStrategyTarot.sol:65"
},
{
"label": "minWantToSell",
"offset": 0,
"slot": "322",
"type": "t_uint256",
"contract": "ReaperStrategyTarot",
"src": "contracts\\ReaperStrategyTarot.sol:67"
}
],
"types": {
Expand Down Expand Up @@ -1207,6 +1223,10 @@
"label": "bytes32",
"numberOfBytes": "32"
},
"t_bytes_storage": {
"label": "bytes",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_bool)": {
"label": "mapping(address => bool)",
"numberOfBytes": "32"
Expand Down
73 changes: 39 additions & 34 deletions contracts/ReaperStrategyTarot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@ contract ReaperStrategyTarot is ReaperBaseStrategyv4 {

/**
* @dev Tokens Used:
* {WFTM} - Required for liquidity routing when doing swaps.
* {want} - Address of the token being lent
* {USDC} - Token for charging fees
*/
address public constant WFTM = address(0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83);
address public constant USDC = address(0x7F5c764cBc14f9669B88837ca1490cCa17c31607);

/**
* @dev UniV3 routes:
* {wantToUsdcRoute} - Route for charging fees from profit
*/
bytes public wantToUsdcRoute;

/**
* @dev Tarot variables
Expand All @@ -59,6 +64,7 @@ contract ReaperStrategyTarot is ReaperBaseStrategyv4 {
bool public shouldHarvestOnDeposit;
bool public shouldHarvestOnWithdraw;
uint256 public constant MAX_SLIPPAGE_TOLERANCE = 100;
uint256 public minWantToSell;

/**
* @dev Initializes the strategy. Sets parameters, saves routes, and gives allowances.
Expand All @@ -69,19 +75,22 @@ contract ReaperStrategyTarot is ReaperBaseStrategyv4 {
address[] memory _feeRemitters,
address[] memory _strategists,
address[] memory _multisigRoles,
uint256 _initialPoolIndex,
address _want
address[] memory _wantToUsdcRoute,
uint24[] memory _wantToDaiFee,
uint256 _initialPoolIndex
) public initializer {
__ReaperBaseStrategy_init(_vault, _want, _feeRemitters, _strategists, _multisigRoles);
sharePriceSnapshot = IVault(_vault).getPricePerFullShare();
__ReaperBaseStrategy_init(_vault, _wantToUsdcRoute[0], _feeRemitters, _strategists, _multisigRoles);
sharePriceSnapshot = IVault(_vault).getPricePerFullShare();
maxPools = 40;
minProfitToChargeFees = 1e16;
minProfitToChargeFees = 1e9;
minWantToDepositOrWithdraw = 10;
maxWantRemainingToRemovePool = 100;
minWantToSell = 12 * 1e8;
addUsedPool(_initialPoolIndex);
depositPool = usedPools.at(0); // Guarantees depositPool is always a Tarot pool
shouldHarvestOnDeposit = true;
shouldHarvestOnWithdraw = true;
wantToUsdcRoute = UniswapV3Utils.routeToPath(_wantToUsdcRoute, _wantToDaiFee);
}

function _adjustPosition(uint256 _debt) internal override {
Expand Down Expand Up @@ -245,7 +254,6 @@ contract ReaperStrategyTarot is ReaperBaseStrategyv4 {
uint256 profit = profitSinceHarvest();
if (profit >= minProfitToChargeFees) {
uint256 fee = (profit * totalFee) / PERCENT_DIVISOR;
IERC20Upgradeable wftm = IERC20Upgradeable(WFTM);

if (fee != 0) {
uint256 wantBal = IERC20Upgradeable(want).balanceOf(address(this));
Expand All @@ -255,44 +263,33 @@ contract ReaperStrategyTarot is ReaperBaseStrategyv4 {
fee = withdrawn + wantBal;
}
}
_swap(want, WFTM, fee);
uint256 wftmBalance = IERC20Upgradeable(WFTM).balanceOf(address(this));
callerFee = (wftmBalance * callFee) / PERCENT_DIVISOR;
uint256 treasuryFeeToVault = (wftmBalance * treasuryFee) / PERCENT_DIVISOR;
_swapToUsdc(fee);
IERC20Upgradeable usdc = IERC20Upgradeable(USDC);
uint256 usdcBalance = usdc.balanceOf(address(this));
callerFee = (usdcBalance * callFee) / PERCENT_DIVISOR;
uint256 treasuryFeeToVault = (usdcBalance * treasuryFee) / PERCENT_DIVISOR;
uint256 feeToStrategist = (treasuryFeeToVault * strategistFee) / PERCENT_DIVISOR;
treasuryFeeToVault -= feeToStrategist;

wftm.safeTransfer(msg.sender, callerFee);
wftm.safeTransfer(treasury, treasuryFeeToVault);
wftm.safeTransfer(strategistRemitter, feeToStrategist);

usdc.safeTransfer(msg.sender, callerFee);
usdc.safeTransfer(treasury, treasuryFeeToVault);
usdc.safeTransfer(strategistRemitter, feeToStrategist);
sharePriceSnapshot = IVault(vault).getPricePerFullShare();
}
}
}

/**
* @dev Helper function to swap tokens given {_from}, {_to} and {_amount}
* @dev Helper function to swap want to USDC
*/
function _swap(
address _from,
address _to,
function _swapToUsdc(
uint256 _amount
) internal {
if (_from == _to || _amount == 0) {
return;
if (_amount >= minWantToSell) {
IERC20Upgradeable(want).safeIncreaseAllowance(UNI_ROUTER, _amount);
UniswapV3Utils.swap(UNI_ROUTER, wantToUsdcRoute, _amount);
}

address[] memory path = new address[](2);
path[0] = _from;
path[1] = _to;
IERC20Upgradeable(_from).safeIncreaseAllowance(UNI_ROUTER, _amount);
IUniswapV2Router02(UNI_ROUTER).swapExactTokensForTokensSupportingFeeOnTransferTokens(
_amount,
0,
path,
address(this),
block.timestamp
);
}

/**
Expand Down Expand Up @@ -555,4 +552,12 @@ contract ReaperStrategyTarot is ReaperBaseStrategyv4 {
_atLeastRole(STRATEGIST);
shouldHarvestOnWithdraw = _shouldHarvestOnWithdraw;
}

/**
* @dev Sets the minimum want that will be sold (too little causes revert from Uniswap)
*/
function setMinWantToSell(uint256 _minWantToSell) external {
_atLeastRole(STRATEGIST);
minWantToSell = _minWantToSell;
}
}
63 changes: 0 additions & 63 deletions contracts/interfaces/IUniswapRouterV3.sol

This file was deleted.

Loading