-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStratPacoca.sol
More file actions
149 lines (115 loc) · 4.51 KB
/
StratPacoca.sol
File metadata and controls
149 lines (115 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
import "./helpers/Governable.sol";
// Pacoca single token farm strategy
contract StratPacoca is Ownable, ReentrancyGuard, Pausable, Governable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
address public immutable wantAddress;
address public immutable pacocaFarmAddress;
// Total want tokens managed by strategy
uint256 public wantLockedTotal = 0;
// Sum of all shares of users to wantLockedTotal
uint256 public sharesTotal = 0;
uint256 public entranceFeeFactor = 10000; // No deposit fees
uint256 public constant entranceFeeFactorMax = 10000;
uint256 public constant entranceFeeFactorLL = 9950; // 0.5% is the max entrance fee settable. LL = lowerlimit
uint256 public withdrawFeeFactor = 10000; // No withdraw fees
uint256 public constant withdrawFeeFactorMax = 10000;
uint256 public constant withdrawFeeFactorLL = 9950; // 0.5% is the max entrance fee settable. LL = lowerlimit
event SetSettings(uint256 _entranceFeeFactor, uint256 _withdrawFeeFactor);
constructor (address _pacoca, address _pacocaFarmAddress, address _govAddress) public {
wantAddress = _pacoca;
pacocaFarmAddress = _pacocaFarmAddress;
govAddress = _govAddress;
transferOwnership(_pacocaFarmAddress);
}
// This contract doesn't auto-compound
// earn() function is here to follow the Strategy interface
function earn() external {}
// Transfer want tokens pacocaFarm -> strategy
function deposit(
address _userAddress,
uint256 _wantAmt
) external virtual onlyOwner nonReentrant whenNotPaused returns (uint256) {
IERC20(wantAddress).safeTransferFrom(
address(msg.sender),
address(this),
_wantAmt
);
uint256 sharesAdded = _wantAmt;
if (wantLockedTotal > 0 && sharesTotal > 0) {
sharesAdded = _wantAmt
.mul(sharesTotal)
.mul(entranceFeeFactor)
.div(wantLockedTotal)
.div(entranceFeeFactorMax);
}
sharesTotal = sharesTotal.add(sharesAdded);
wantLockedTotal = wantLockedTotal.add(_wantAmt);
return sharesAdded;
}
// Transfer want tokens strategy -> pacocaFarm
function withdraw(
address _userAddress,
uint256 _wantAmt
) external virtual onlyOwner nonReentrant returns (uint256) {
require(_wantAmt > 0, "_wantAmt <= 0");
uint256 sharesRemoved = _wantAmt.mul(sharesTotal).div(wantLockedTotal);
if (sharesRemoved > sharesTotal) {
sharesRemoved = sharesTotal;
}
sharesTotal = sharesTotal.sub(sharesRemoved);
if (withdrawFeeFactor < withdrawFeeFactorMax) {
_wantAmt = _wantAmt.mul(withdrawFeeFactor).div(
withdrawFeeFactorMax
);
}
uint256 wantAmt = IERC20(wantAddress).balanceOf(address(this));
if (_wantAmt > wantAmt) {
_wantAmt = wantAmt;
}
if (wantLockedTotal < _wantAmt) {
_wantAmt = wantLockedTotal;
}
wantLockedTotal = wantLockedTotal.sub(_wantAmt);
IERC20(wantAddress).safeTransfer(pacocaFarmAddress, _wantAmt);
return sharesRemoved;
}
function inCaseTokensGetStuck(
address _token,
uint256 _amount,
address _to
) external virtual onlyAllowGov {
require(_token != wantAddress, "!safe");
IERC20(_token).safeTransfer(_to, _amount);
}
function setSettings(
uint256 _entranceFeeFactor,
uint256 _withdrawFeeFactor
) external virtual onlyAllowGov {
require(
_entranceFeeFactor >= entranceFeeFactorLL,
"_entranceFeeFactor too low"
);
require(
_entranceFeeFactor <= entranceFeeFactorMax,
"_entranceFeeFactor too high"
);
entranceFeeFactor = _entranceFeeFactor;
require(
_withdrawFeeFactor >= withdrawFeeFactorLL,
"_withdrawFeeFactor too low"
);
require(
_withdrawFeeFactor <= withdrawFeeFactorMax,
"_withdrawFeeFactor too high"
);
withdrawFeeFactor = _withdrawFeeFactor;
emit SetSettings(_entranceFeeFactor, _withdrawFeeFactor);
}
}