@gooddollar/goodprotocol 1.0.15-beta.4 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
- package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
- package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
- package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
- package/artifacts/contracts/governance/GovernanceStaking.sol/GovernanceStaking.dbg.json +1 -1
- package/artifacts/contracts/governance/GovernanceStaking.sol/GovernanceStaking.json +18 -18
- package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
- package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.json +8 -8
- package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
- package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
- package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.json +10 -10
- package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.json +2 -2
- package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.json +2 -2
- package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.json +2 -2
- package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.json +2 -2
- package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
- package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
- package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
- package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.json +2 -2
- package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.json +2 -2
- package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
- package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +1 -1
- package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.json +2 -2
- package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
- package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.json +2 -2
- package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.json +13 -0
- package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.json +3 -3
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.json +2 -2
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +17 -4
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.json +4 -4
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.json +2 -2
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.json +19 -6
- package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
- package/artifacts/contracts/unaudited-foundation/FuseFaucet.sol/FuseFaucet.dbg.json +1 -1
- package/artifacts/contracts/unaudited-foundation/InvitesV1.sol/InvitesV1.dbg.json +1 -1
- package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
- package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
- package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
- package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
- package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
- package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.dbg.json +1 -1
- package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
- package/contracts/governance/MultiBaseGovernanceShareField.sol +12 -13
- package/contracts/governance/StakersDistribution.sol +11 -25
- package/contracts/reserve/ExchangeHelper.sol +28 -19
- package/contracts/reserve/GoodReserveCDai.sol +19 -19
- package/contracts/staking/SimpleStakingV2.sol +13 -1
- package/package.json +1 -1
- package/releases/deployment.json +14 -2
- package/test/governance/StakersDistribution.test.ts +31 -24
|
@@ -22,10 +22,10 @@ abstract contract MultiBaseGovernanceShareField is DSMath {
|
|
|
22
22
|
mapping(address => uint256) public rewardsPerBlock;
|
|
23
23
|
|
|
24
24
|
struct UserInfo {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
uint128 amount; // How many tokens the user has staked.
|
|
26
|
+
uint128 rewardDebt; // Rewards that accounted already so should be substracted while calculating rewards of staker
|
|
27
|
+
uint128 rewardEarn; // Reward earn and not minted
|
|
28
|
+
uint128 rewardMinted; // rewards sent to the user
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
mapping(address => mapping(address => UserInfo)) public contractToUsers;
|
|
@@ -115,15 +115,15 @@ abstract contract MultiBaseGovernanceShareField is DSMath {
|
|
|
115
115
|
uint256 pending = (userInfo.amount * accAmountPerShare[_contract]) /
|
|
116
116
|
1e27 -
|
|
117
117
|
userInfo.rewardDebt; // Divide 1e27(because userinfo.amount in 18 decimals and accAmountPerShare is in 27decimals) since rewardDebt in 18 decimals so we can calculate how much reward earned in that cycle
|
|
118
|
-
userInfo.rewardEarn = userInfo.rewardEarn + pending; // Add user's earned rewards to user's account so it can be minted later
|
|
118
|
+
userInfo.rewardEarn = userInfo.rewardEarn + uint128(pending); // Add user's earned rewards to user's account so it can be minted later
|
|
119
119
|
totalRewardsAccumulated[_contract] =
|
|
120
120
|
totalRewardsAccumulated[_contract] +
|
|
121
121
|
pending;
|
|
122
122
|
}
|
|
123
|
-
userInfo.amount = _updatedAmount;
|
|
124
|
-
userInfo.rewardDebt =
|
|
125
|
-
(_updatedAmount * accAmountPerShare[_contract]) /
|
|
126
|
-
|
|
123
|
+
userInfo.amount = uint128(_updatedAmount);
|
|
124
|
+
userInfo.rewardDebt = uint128(
|
|
125
|
+
(_updatedAmount * accAmountPerShare[_contract]) / 1e27
|
|
126
|
+
); // Divide to 1e27 to keep rewardDebt in 18 decimals since accAmountPerShare is in 27 decimals and amount is 18 decimals
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/**
|
|
@@ -216,10 +216,9 @@ abstract contract MultiBaseGovernanceShareField is DSMath {
|
|
|
216
216
|
) internal returns (uint256) {
|
|
217
217
|
_update(_contract, _blockStart, _blockEnd);
|
|
218
218
|
_audit(_contract, _user, contractToUsers[_contract][_user].amount);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
userInfo.rewardMinted += amount;
|
|
219
|
+
uint128 amount = contractToUsers[_contract][_user].rewardEarn;
|
|
220
|
+
contractToUsers[_contract][_user].rewardMinted += amount;
|
|
221
|
+
contractToUsers[_contract][_user].rewardEarn = 0;
|
|
223
222
|
rewardsMintedSoFar[_contract] = rewardsMintedSoFar[_contract] + amount;
|
|
224
223
|
return amount;
|
|
225
224
|
}
|
|
@@ -7,7 +7,7 @@ import "../Interfaces.sol";
|
|
|
7
7
|
import "../governance/GReputation.sol";
|
|
8
8
|
import "../governance/MultiBaseGovernanceShareField.sol";
|
|
9
9
|
import "../staking/GoodFundManager.sol";
|
|
10
|
-
import "../staking/
|
|
10
|
+
import "../staking/SimpleStakingV2.sol";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Staking contracts will update this contract with staker token stake amount
|
|
@@ -34,7 +34,6 @@ contract StakersDistribution is
|
|
|
34
34
|
function initialize(INameService _ns) public initializer {
|
|
35
35
|
monthlyReputationDistribution = 2000000 ether; //2M as specified in specs
|
|
36
36
|
setDAO(_ns);
|
|
37
|
-
_updateMonth();
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
/**
|
|
@@ -58,12 +57,8 @@ contract StakersDistribution is
|
|
|
58
57
|
/**
|
|
59
58
|
* @dev internal function to switch to new month. records for new month the current monthlyReputationDistribution
|
|
60
59
|
*/
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
nameService.getAddress("FUND_MANAGER") != address(0) &&
|
|
65
|
-
month != currentMonth
|
|
66
|
-
) {
|
|
60
|
+
function _updateRewards() internal {
|
|
61
|
+
if (nameService.getAddress("FUND_MANAGER") != address(0)) {
|
|
67
62
|
//read active staking contracts set pro rate monthly share
|
|
68
63
|
GoodFundManager gfm = GoodFundManager(
|
|
69
64
|
nameService.getAddress("FUND_MANAGER")
|
|
@@ -83,9 +78,8 @@ contract StakersDistribution is
|
|
|
83
78
|
(, uint64 blockStart, uint64 blockEnd, ) = gfm
|
|
84
79
|
.rewardsForStakingContract(activeStakingList[i]);
|
|
85
80
|
if (blockStart <= block.number && blockEnd > block.number) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
).currentGains(true, false);
|
|
81
|
+
uint256 lockedValueInUSD = SimpleStakingV2(activeStakingList[i])
|
|
82
|
+
.lockedUSDValue();
|
|
89
83
|
contractLockedValue[i] = lockedValueInUSD;
|
|
90
84
|
totalLockedValue += contractLockedValue[i];
|
|
91
85
|
}
|
|
@@ -101,9 +95,6 @@ contract StakersDistribution is
|
|
|
101
95
|
_setMonthlyRewards(activeStakingList[i], contractShare);
|
|
102
96
|
}
|
|
103
97
|
}
|
|
104
|
-
|
|
105
|
-
//update new month
|
|
106
|
-
currentMonth = month;
|
|
107
98
|
}
|
|
108
99
|
}
|
|
109
100
|
|
|
@@ -137,7 +128,7 @@ contract StakersDistribution is
|
|
|
137
128
|
|
|
138
129
|
_claimReputation(_staker, contracts);
|
|
139
130
|
|
|
140
|
-
|
|
131
|
+
_updateRewards();
|
|
141
132
|
}
|
|
142
133
|
|
|
143
134
|
/**
|
|
@@ -168,7 +159,7 @@ contract StakersDistribution is
|
|
|
168
159
|
address[] memory contracts = new address[](1);
|
|
169
160
|
contracts[0] = stakingContract;
|
|
170
161
|
_claimReputation(_staker, contracts);
|
|
171
|
-
|
|
162
|
+
_updateRewards();
|
|
172
163
|
}
|
|
173
164
|
|
|
174
165
|
/**
|
|
@@ -181,13 +172,11 @@ contract StakersDistribution is
|
|
|
181
172
|
address[] calldata _stakingContracts
|
|
182
173
|
) external {
|
|
183
174
|
_claimReputation(_staker, _stakingContracts);
|
|
184
|
-
_updateMonth(); //previous calls will use previous month reputation
|
|
185
175
|
}
|
|
186
176
|
|
|
187
|
-
function _claimReputation(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
) internal {
|
|
177
|
+
function _claimReputation(address _staker, address[] memory _stakingContracts)
|
|
178
|
+
internal
|
|
179
|
+
{
|
|
191
180
|
uint256 totalRep;
|
|
192
181
|
GoodFundManager gfm = GoodFundManager(
|
|
193
182
|
nameService.getAddress("FUND_MANAGER")
|
|
@@ -206,10 +195,7 @@ contract StakersDistribution is
|
|
|
206
195
|
);
|
|
207
196
|
}
|
|
208
197
|
if (totalRep > 0) {
|
|
209
|
-
GReputation(nameService.getAddress("REPUTATION")).mint(
|
|
210
|
-
_staker,
|
|
211
|
-
totalRep
|
|
212
|
-
);
|
|
198
|
+
GReputation(nameService.getAddress("REPUTATION")).mint(_staker, totalRep);
|
|
213
199
|
emit ReputationEarned(_staker, _stakingContracts, totalRep);
|
|
214
200
|
}
|
|
215
201
|
}
|
|
@@ -99,8 +99,8 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
99
99
|
uint256 _minReturn,
|
|
100
100
|
uint256 _minDAIAmount,
|
|
101
101
|
address _targetAddress
|
|
102
|
-
) public nonReentrant
|
|
103
|
-
require(_buyPath.length > 0
|
|
102
|
+
) public payable nonReentrant returns (uint256) {
|
|
103
|
+
require(_buyPath.length > 0, "Provide valid path");
|
|
104
104
|
GoodReserveCDai reserve = GoodReserveCDai(
|
|
105
105
|
nameService.getAddress("RESERVE")
|
|
106
106
|
);
|
|
@@ -114,7 +114,10 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
114
114
|
"you need to pay with ETH"
|
|
115
115
|
);
|
|
116
116
|
} else {
|
|
117
|
-
require(
|
|
117
|
+
require(
|
|
118
|
+
msg.value == 0,
|
|
119
|
+
"When input token is different than ETH message value should be zero"
|
|
120
|
+
);
|
|
118
121
|
require(
|
|
119
122
|
ERC20(_buyPath[0]).transferFrom(
|
|
120
123
|
msg.sender,
|
|
@@ -133,7 +136,10 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
133
136
|
} else if (_buyPath[0] == daiAddress) {
|
|
134
137
|
result = _cdaiMintAndBuy(_tokenAmount, _minReturn, receiver);
|
|
135
138
|
} else {
|
|
136
|
-
require(
|
|
139
|
+
require(
|
|
140
|
+
_buyPath[_buyPath.length - 1] == daiAddress,
|
|
141
|
+
"Target token in the path must be DAI"
|
|
142
|
+
);
|
|
137
143
|
uint256[] memory swap = _uniswapSwap(
|
|
138
144
|
_buyPath,
|
|
139
145
|
_tokenAmount,
|
|
@@ -175,7 +181,7 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
175
181
|
uint256 _minTokenReturn,
|
|
176
182
|
address _targetAddress
|
|
177
183
|
) public nonReentrant returns (uint256) {
|
|
178
|
-
require(_sellPath.length > 0
|
|
184
|
+
require(_sellPath.length > 0, "Provide valid path");
|
|
179
185
|
address receiver = _targetAddress == address(0x0)
|
|
180
186
|
? msg.sender
|
|
181
187
|
: _targetAddress;
|
|
@@ -193,11 +199,16 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
193
199
|
(result, contributionAmount) = reserve.sell(
|
|
194
200
|
_gdAmount,
|
|
195
201
|
_minReturn,
|
|
196
|
-
(_sellPath.length == 1 && _sellPath[0] == cDaiAddress)
|
|
202
|
+
(_sellPath.length == 1 && _sellPath[0] == cDaiAddress)
|
|
203
|
+
? receiver
|
|
204
|
+
: address(this), // if the tokens that will received is cDai then return it directly to receiver
|
|
197
205
|
msg.sender
|
|
198
206
|
);
|
|
199
|
-
if (
|
|
200
|
-
|
|
207
|
+
if (
|
|
208
|
+
_sellPath.length == 1 &&
|
|
209
|
+
(_sellPath[0] == daiAddress || _sellPath[0] == cDaiAddress)
|
|
210
|
+
) {
|
|
211
|
+
if (_sellPath[0] == daiAddress) {
|
|
201
212
|
result = _redeemDAI(result);
|
|
202
213
|
|
|
203
214
|
require(
|
|
@@ -205,9 +216,12 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
205
216
|
"Transfer failed"
|
|
206
217
|
);
|
|
207
218
|
}
|
|
208
|
-
} else if(_sellPath[0] != cDaiAddress){
|
|
219
|
+
} else if (_sellPath[0] != cDaiAddress) {
|
|
209
220
|
result = _redeemDAI(result);
|
|
210
|
-
require(
|
|
221
|
+
require(
|
|
222
|
+
_sellPath[0] == daiAddress,
|
|
223
|
+
"Input token for uniswap must be DAI"
|
|
224
|
+
);
|
|
211
225
|
uint256[] memory swap = _uniswapSwap(
|
|
212
226
|
_sellPath,
|
|
213
227
|
result,
|
|
@@ -218,12 +232,12 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
218
232
|
|
|
219
233
|
result = swap[swap.length - 1];
|
|
220
234
|
require(result > 0, "token selling failed");
|
|
221
|
-
}else{
|
|
235
|
+
} else {
|
|
222
236
|
revert();
|
|
223
237
|
}
|
|
224
238
|
|
|
225
239
|
emit TokenSold(
|
|
226
|
-
|
|
240
|
+
msg.sender,
|
|
227
241
|
_sellPath[_sellPath.length - 1],
|
|
228
242
|
_gdAmount,
|
|
229
243
|
contributionAmount,
|
|
@@ -295,9 +309,7 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
295
309
|
uint256 _minTokenReturn,
|
|
296
310
|
address _receiver
|
|
297
311
|
) internal returns (uint256[] memory) {
|
|
298
|
-
Uniswap uniswapContract = Uniswap(
|
|
299
|
-
nameService.getAddress("UNISWAP_ROUTER")
|
|
300
|
-
);
|
|
312
|
+
Uniswap uniswapContract = Uniswap(nameService.getAddress("UNISWAP_ROUTER"));
|
|
301
313
|
address wETH = uniswapContract.WETH();
|
|
302
314
|
uint256[] memory swap;
|
|
303
315
|
bool isBuy = _inputPath[_inputPath.length - 1] == daiAddress; // if outputToken is dai then transaction is buy with any ERC20 token
|
|
@@ -322,10 +334,7 @@ contract ExchangeHelper is DAOUpgradeableContract {
|
|
|
322
334
|
return swap;
|
|
323
335
|
} else {
|
|
324
336
|
if (isBuy)
|
|
325
|
-
ERC20(_inputPath[0]).approve(
|
|
326
|
-
address(uniswapContract),
|
|
327
|
-
_tokenAmount
|
|
328
|
-
);
|
|
337
|
+
ERC20(_inputPath[0]).approve(address(uniswapContract), _tokenAmount);
|
|
329
338
|
swap = uniswapContract.swapExactTokensForTokens(
|
|
330
339
|
_tokenAmount,
|
|
331
340
|
isBuy ? _minDAIAmount : _minTokenReturn,
|
|
@@ -192,14 +192,14 @@ contract GoodReserveCDai is
|
|
|
192
192
|
_mintGoodDollars(_targetAddress, gdReturn, true);
|
|
193
193
|
//mint GDX
|
|
194
194
|
_mintGDX(_targetAddress, gdReturn);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
195
|
+
|
|
196
|
+
emit TokenPurchased(
|
|
197
|
+
msg.sender != exchangeHelper ? msg.sender : tx.origin,
|
|
198
|
+
cDaiAddress,
|
|
199
|
+
_tokenAmount,
|
|
200
|
+
gdReturn,
|
|
201
|
+
_targetAddress
|
|
202
|
+
);
|
|
203
203
|
return gdReturn;
|
|
204
204
|
}
|
|
205
205
|
|
|
@@ -250,8 +250,7 @@ contract GoodReserveCDai is
|
|
|
250
250
|
uint256 discount = gdx <= _gdAmount ? gdx : _gdAmount;
|
|
251
251
|
|
|
252
252
|
//burn gdx used for discount
|
|
253
|
-
if (discount > 0)
|
|
254
|
-
_burn(_seller, discount);
|
|
253
|
+
if (discount > 0) _burn(_seller, discount);
|
|
255
254
|
|
|
256
255
|
uint256 contributionAmount = 0;
|
|
257
256
|
uint256 gdAmountTemp = _gdAmount; // to prevent stack too deep errors
|
|
@@ -276,15 +275,16 @@ contract GoodReserveCDai is
|
|
|
276
275
|
"Token return must be above the minReturn"
|
|
277
276
|
);
|
|
278
277
|
cERC20(cDaiAddress).transfer(_target, tokenReturn);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
278
|
+
|
|
279
|
+
emit TokenSold(
|
|
280
|
+
_seller,
|
|
281
|
+
cDaiAddress,
|
|
282
|
+
_gdAmount,
|
|
283
|
+
contributionAmount,
|
|
284
|
+
tokenReturn,
|
|
285
|
+
_target
|
|
286
|
+
);
|
|
287
|
+
|
|
288
288
|
return (tokenReturn, contributionAmount);
|
|
289
289
|
}
|
|
290
290
|
|
|
@@ -37,6 +37,8 @@ abstract contract SimpleStakingV2 is
|
|
|
37
37
|
//max percentage of token/dai pool liquidity to swap to DAI when collecting interest out of 100000
|
|
38
38
|
uint24 public maxLiquidityPercentageSwap = 300; //0.3%
|
|
39
39
|
|
|
40
|
+
uint256 public lockedUSDValue;
|
|
41
|
+
|
|
40
42
|
/**
|
|
41
43
|
* @dev Emitted when `staker` stake `value` tokens of `token`
|
|
42
44
|
*/
|
|
@@ -216,6 +218,9 @@ abstract contract SimpleStakingV2 is
|
|
|
216
218
|
_donationPer
|
|
217
219
|
);
|
|
218
220
|
|
|
221
|
+
(, , , uint256 lockedValueInUSD, ) = currentGains(true, false);
|
|
222
|
+
lockedUSDValue = lockedValueInUSD;
|
|
223
|
+
|
|
219
224
|
//notify GDAO distrbution for stakers
|
|
220
225
|
StakersDistribution sd = StakersDistribution(
|
|
221
226
|
nameService.getAddress("GDAO_STAKERS")
|
|
@@ -259,6 +264,9 @@ abstract contract SimpleStakingV2 is
|
|
|
259
264
|
nameService.getAddress("FUND_MANAGER")
|
|
260
265
|
);
|
|
261
266
|
|
|
267
|
+
(, , , uint256 lockedValueInUSD, ) = currentGains(true, false);
|
|
268
|
+
lockedUSDValue = lockedValueInUSD;
|
|
269
|
+
|
|
262
270
|
//this will revert in case user doesnt have enough productivity to withdraw _amount, as productivity=staking tokens amount
|
|
263
271
|
_burn(msg.sender, _amount); // burn their staking tokens
|
|
264
272
|
|
|
@@ -350,7 +358,11 @@ abstract contract SimpleStakingV2 is
|
|
|
350
358
|
}
|
|
351
359
|
}
|
|
352
360
|
|
|
353
|
-
function _convertValueTo18Decimals(uint256 _amount)
|
|
361
|
+
function _convertValueTo18Decimals(uint256 _amount)
|
|
362
|
+
internal
|
|
363
|
+
view
|
|
364
|
+
returns (uint256 amountInEighteenDecimals)
|
|
365
|
+
{
|
|
354
366
|
amountInEighteenDecimals = token.decimals() == 18
|
|
355
367
|
? _amount
|
|
356
368
|
: _amount * 10**(18 - token.decimals());
|
package/package.json
CHANGED
package/releases/deployment.json
CHANGED
|
@@ -458,6 +458,10 @@
|
|
|
458
458
|
"GoodMarketMaker": "0xDAC6A0c973Ba7cF3526dE456aFfA43AB421f659F",
|
|
459
459
|
"GoodReserveCDai": "0xa150a825d425B36329D8294eeF8bD0fE68f8F6E0",
|
|
460
460
|
"ExchangeHelper": "0x98FA532Dd5C3a6b66fbf370813803192DE4e0abd",
|
|
461
|
+
"CompoundStakingFactory": "0x78cc5ab2f0990b5fe58f95baebf8f37879534aeb",
|
|
462
|
+
"AaveStakingFactory": "0xf4411c22766947DB2da39Ad534A040b770B51153",
|
|
463
|
+
"StakersDistribution": "0x5766cf4b2fdb09d986eb1783d276013c224e28c8",
|
|
464
|
+
"GoodFundManager": "0x0c6c80d2061afa35e160f3799411d83bdeea0a5a",
|
|
461
465
|
"ProtocolUpgradeRecover": "0x6f1b4dFDd7156FC5752541Ef35EDF57B48E74475",
|
|
462
466
|
"network": "production-mainnet",
|
|
463
467
|
"networkId": 1,
|
|
@@ -488,8 +492,16 @@
|
|
|
488
492
|
6944
|
|
489
493
|
]
|
|
490
494
|
],
|
|
491
|
-
"
|
|
492
|
-
|
|
495
|
+
"StakingContractsV3": [
|
|
496
|
+
[
|
|
497
|
+
"0x7b7246c78e2f900d17646ff0cb2ec47d6ba10754",
|
|
498
|
+
13888
|
|
499
|
+
],
|
|
500
|
+
[
|
|
501
|
+
"0x3ff2d8eb2573819a9ef7167d2ba6fd6d31b17f4f",
|
|
502
|
+
6944
|
|
503
|
+
]
|
|
504
|
+
],
|
|
493
505
|
"GReputation": "0x3A9299BE789ac3730e4E4c49d6d2Ad1b8BC34DFf",
|
|
494
506
|
"CompoundVotingMachine": "0xc2Ff55b896e3c42f9e1c2f7467C51b93F1C23dFD"
|
|
495
507
|
},
|
|
@@ -383,23 +383,21 @@ describe("StakersDistribution - staking with GD and get Rewards in GDAO", () =>
|
|
|
383
383
|
await simpleStaking.connect(staker).stake(stakingAmount, 0, false);
|
|
384
384
|
await advanceBlocks(40);
|
|
385
385
|
await increaseTime(86700 * 30); // Increase one month
|
|
386
|
-
const stakerGDAOBalanceBeforeStake = await grep.
|
|
387
|
-
staker.address
|
|
388
|
-
);
|
|
386
|
+
const stakerGDAOBalanceBeforeStake = await grep.balanceOf(staker.address);
|
|
389
387
|
await simpleStaking.connect(staker).stake(stakingAmount, 0, false);
|
|
390
|
-
const stakerGDAOBalanceAfterStake = await grep.
|
|
391
|
-
staker.address
|
|
392
|
-
);
|
|
388
|
+
const stakerGDAOBalanceAfterStake = await grep.balanceOf(staker.address);
|
|
393
389
|
await simpleStaking.connect(staker).withdrawRewards();
|
|
394
390
|
|
|
395
391
|
const rewardsPerBlockAfterStake = await stakersDistribution.rewardsPerBlock(
|
|
396
392
|
simpleStaking.address
|
|
397
393
|
);
|
|
398
|
-
const GDAOBalanceBeforeWithdraw = await grep.
|
|
394
|
+
const GDAOBalanceBeforeWithdraw = await grep.balanceOf(staker.address);
|
|
399
395
|
await advanceBlocks(10);
|
|
400
396
|
await simpleStaking.connect(staker).withdrawStake(stakingAmount, false);
|
|
401
|
-
const GDAOBalanceAfterWithdraw = await grep.
|
|
402
|
-
expect(rewardsPerBlockAfterStake).to.be.equal(
|
|
397
|
+
const GDAOBalanceAfterWithdraw = await grep.balanceOf(staker.address);
|
|
398
|
+
expect(rewardsPerBlockAfterStake).to.not.be.equal(
|
|
399
|
+
rewardsPerBlockBeforeStake
|
|
400
|
+
); // Should update rewards per block every stake/withdraw
|
|
403
401
|
expect(GDAOBalanceBeforeWithdraw).to.be.equal(GDAOBalanceAfterWithdraw); // Should not earn any GDAO since simplestaking blockend passed
|
|
404
402
|
expect(stakerGDAOBalanceAfterStake.gt(stakerGDAOBalanceBeforeStake)).to.be
|
|
405
403
|
.true;
|
|
@@ -438,10 +436,10 @@ describe("StakersDistribution - staking with GD and get Rewards in GDAO", () =>
|
|
|
438
436
|
const blockNumberOfStake = (await ethers.provider.getBlockNumber()) + 1;
|
|
439
437
|
await simpleStaking.connect(staker).stake(stakingAmount, 0, false);
|
|
440
438
|
await advanceBlocks(30);
|
|
441
|
-
const GDAOBalanceBeforeWithdraw = await grep.
|
|
439
|
+
const GDAOBalanceBeforeWithdraw = await grep.balanceOf(staker.address);
|
|
442
440
|
await simpleStaking.connect(staker).withdrawStake(stakingAmount, false);
|
|
443
441
|
|
|
444
|
-
const GDAOBalanceAfterWithdraw = await grep.
|
|
442
|
+
const GDAOBalanceAfterWithdraw = await grep.balanceOf(staker.address);
|
|
445
443
|
expect(GDAOBalanceAfterWithdraw).to.be.gt(GDAOBalanceBeforeWithdraw);
|
|
446
444
|
|
|
447
445
|
expect(GDAOBalanceAfterWithdraw).to.be.equal(
|
|
@@ -653,18 +651,23 @@ describe("StakersDistribution - staking with GD and get Rewards in GDAO", () =>
|
|
|
653
651
|
simpleStaking1.address
|
|
654
652
|
);
|
|
655
653
|
await advanceBlocks(4);
|
|
656
|
-
const gdaoBalanceBeforeWithdraw = await
|
|
657
|
-
|
|
658
|
-
);
|
|
654
|
+
const gdaoBalanceBeforeWithdraw = await grep.balanceOf(staker.address);
|
|
655
|
+
console.log({ gdaoBalanceBeforeWithdraw, rewardsPerBlock });
|
|
659
656
|
await simpleStaking1.connect(staker).withdrawStake(stakingAmount, false);
|
|
660
657
|
const withdrawBlockNumber = await ethers.provider.getBlockNumber();
|
|
661
|
-
|
|
658
|
+
await stakersDistribution.claimReputation(staker.address, [
|
|
659
|
+
simpleUsdcStaking.address,
|
|
660
|
+
simpleStaking.address
|
|
661
|
+
]);
|
|
662
|
+
|
|
663
|
+
const gdaoBalanceAfterWithdraw = await grep.balanceOf(staker.address);
|
|
662
664
|
const calculatedNewBalance = gdaoBalanceBeforeWithdraw.add(
|
|
663
665
|
rewardsPerBlock.mul(withdrawBlockNumber - stakeBlockNumber)
|
|
664
666
|
);
|
|
665
667
|
expect(gdaoBalanceAfterWithdraw).to.be.gt(gdaoBalanceBeforeWithdraw);
|
|
666
668
|
|
|
667
|
-
expect(
|
|
669
|
+
expect(gdaoBalanceAfterWithdraw).to.be.equal(calculatedNewBalance);
|
|
670
|
+
|
|
668
671
|
encodedData = goodFundManagerFactory.interface.encodeFunctionData(
|
|
669
672
|
"setStakingReward",
|
|
670
673
|
[
|
|
@@ -756,17 +759,19 @@ describe("StakersDistribution - staking with GD and get Rewards in GDAO", () =>
|
|
|
756
759
|
const daiStakingRewardsPerBlock = await stakersDistribution.rewardsPerBlock(
|
|
757
760
|
simpleStaking.address
|
|
758
761
|
);
|
|
759
|
-
|
|
762
|
+
|
|
763
|
+
expect(usdcStakingRewardsPerBlock).to.equal(daiStakingRewardsPerBlock);
|
|
764
|
+
|
|
760
765
|
await simpleUsdcStaking
|
|
761
766
|
.connect(staker)
|
|
762
767
|
.withdrawStake(stakingAmountUsdc, false);
|
|
763
768
|
await simpleStaking.connect(staker).withdrawStake(stakingAmountDai, false);
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
769
|
+
|
|
770
|
+
await stakersDistribution.claimReputation(staker.address, [
|
|
771
|
+
simpleUsdcStaking.address,
|
|
772
|
+
simpleStaking.address
|
|
773
|
+
]);
|
|
774
|
+
|
|
770
775
|
expect(UserPendingGdaos).to.be.equal(
|
|
771
776
|
usdcStakingPendingGdaos.add(daiStakingPendingGdaos)
|
|
772
777
|
);
|
|
@@ -834,7 +839,9 @@ describe("StakersDistribution - staking with GD and get Rewards in GDAO", () =>
|
|
|
834
839
|
.approve(simpleUsdcStaking.address, stakingAmountUsdc);
|
|
835
840
|
await increaseTime(86700 * 30); // Increase one month
|
|
836
841
|
await simpleUsdcStaking.connect(sender).stake(stakingAmountUsdc, 0, false);
|
|
837
|
-
await simpleUsdcStaking
|
|
842
|
+
await simpleUsdcStaking
|
|
843
|
+
.connect(sender)
|
|
844
|
+
.transfer(receiver.address, stakingAmountUsdc);
|
|
838
845
|
await advanceBlocks(10);
|
|
839
846
|
const UserPendingGdaos = await stakersDistribution.getUserPendingRewards(
|
|
840
847
|
[simpleUsdcStaking.address],
|