@gooddollar/goodprotocol 1.0.9-beta.0 → 1.0.12

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.
Files changed (128) hide show
  1. package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
  2. package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
  3. package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
  4. package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
  5. package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
  6. package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
  7. package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
  8. package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
  9. package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
  10. package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
  11. package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
  12. package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
  13. package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
  14. package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
  15. package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
  16. package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
  17. package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
  18. package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
  19. package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
  20. package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
  21. package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
  22. package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
  23. package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
  24. package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
  25. package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
  26. package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
  27. package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
  28. package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
  29. package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
  30. package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
  31. package/artifacts/contracts/governance/GovarnanceStaking.sol/GovernanceStaking.dbg.json +1 -1
  32. package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
  33. package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
  34. package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
  35. package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.json +2 -2
  36. package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
  37. package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
  38. package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
  39. package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
  40. package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.json +6 -6
  41. package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
  42. package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
  43. package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
  44. package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
  45. package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
  46. package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.json +2 -2
  47. package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
  48. package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
  49. package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
  50. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
  51. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
  52. package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
  53. package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
  54. package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
  55. package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
  56. package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
  57. package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
  58. package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
  59. package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
  60. package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
  61. package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
  62. package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
  63. package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
  64. package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
  65. package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +1 -1
  66. package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.json +48 -104
  67. package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
  68. package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.json +2 -2
  69. package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
  70. package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
  71. package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +1 -1
  72. package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.json +48 -123
  73. package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
  74. package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
  75. package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.json +65 -12
  76. package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
  77. package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.json +4 -4
  78. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
  79. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +52 -127
  80. package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
  81. package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.json +57 -14
  82. package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
  83. package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.json +6 -6
  84. package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +4 -0
  85. package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.json +1092 -0
  86. package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
  87. package/artifacts/contracts/unaudited-foundation/FuseFaucet.sol/FuseFaucet.dbg.json +1 -1
  88. package/artifacts/contracts/unaudited-foundation/InvitesV1.sol/InvitesV1.dbg.json +1 -1
  89. package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
  90. package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
  91. package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
  92. package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
  93. package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
  94. package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
  95. package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
  96. package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
  97. package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
  98. package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
  99. package/contracts/staking/BaseShareFieldV2.sol +45 -21
  100. package/contracts/staking/SimpleStaking.sol +0 -7
  101. package/contracts/staking/SimpleStakingV2.sol +10 -44
  102. package/contracts/staking/aave/AaveStakingFactory.sol +45 -19
  103. package/contracts/staking/aave/GoodAaveStaking.sol +1 -1
  104. package/contracts/staking/aave/GoodAaveStakingV2.sol +2 -2
  105. package/contracts/staking/compound/CompoundStakingFactory.sol +41 -18
  106. package/contracts/staking/compound/GoodCompoundStaking.sol +1 -1
  107. package/contracts/staking/compound/GoodCompoundStakingV2.sol +315 -0
  108. package/package.json +1 -1
  109. package/releases/deployment.json +57 -47
  110. package/scripts/deployFullDAO.ts +1 -1
  111. package/scripts/upgradeToV2/upgradeToV2.ts +7 -3
  112. package/test/governance/StakersDistribution.test.ts +43 -14
  113. package/test/helpers.ts +1 -0
  114. package/test/staking/CompoundStakingFactory.test.ts +24 -21
  115. package/test/staking/DifferentStakingTokens.test.ts +3 -1
  116. package/test/staking/DonationsStaking.test.ts +3 -1
  117. package/test/staking/GoodAaveStakingFactory.test.ts +26 -23
  118. package/test/staking/SimpleDAIStaking.test.ts +3 -11
  119. package/test/staking/StakingRewards.test.ts +20 -14
  120. package/test/staking/SwapHelper.test.ts +4 -1
  121. package/test/staking/UsdcAaveStaking.test.ts +23 -8
  122. package/test/ubi/UBIScheme.e2e.test.ts +1 -1
  123. package/test/utils/ProtocolUpgrade.test.ts +1 -1
  124. package/artifacts/contracts/staking/aave/AaveStakingFactoryV2.sol/AaveStakingFactoryV2.dbg.json +0 -4
  125. package/artifacts/contracts/staking/aave/AaveStakingFactoryV2.sol/AaveStakingFactoryV2.json +0 -148
  126. package/contracts/staking/aave/AaveStakingFactoryV2.sol +0 -93
  127. package/test/staking/GoodAaveStakingFactoryV2.test.ts +0 -122
  128. package/test/staking/UsdcAaveStakingV2.test.ts +0 -291
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/432071a069fa44ffd3a7f92eee83d72e.json"
3
+ "buildInfo": "../../../build-info/78fe23216a2e71b0745d62e12899dde9.json"
4
4
  }
@@ -1,26 +1,25 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
  pragma solidity >=0.8.0;
3
3
  import "../Interfaces.sol";
4
- import "openzeppelin-solidity/contracts/utils/math/Math.sol";
5
- import "../utils/DSMath.sol";
6
4
 
7
- contract BaseShareFieldV2 is DSMath {
5
+ contract BaseShareFieldV2 {
8
6
  // rewards claimed by users
9
- uint128 public mintedRewards;
10
- // number of blocks before reaching the max rewards multiplier (starting at 0.5 reaching 1 after maxMultiplierThreshold)
11
- uint64 public maxMultiplierThreshold;
12
- // Staking contracts accepts Tokens with max 18 decimals so this variable holds decimal difference between 18 and Token's decimal in order to make calculations
13
- uint8 public tokenDecimalDifference;
7
+ uint128 mintedRewards;
14
8
  // total staked for shares calculation
15
- uint128 public totalProductivity;
9
+ uint128 totalProductivity;
16
10
  // total staked that earns rewards (some stakers can donate their rewards)
17
- uint128 public totalEffectiveStakes;
11
+ uint128 totalEffectiveStakes;
18
12
  // rewards accumulated for distribution
19
- uint128 public accumulatedRewards;
13
+ uint128 accumulatedRewards;
20
14
  // block of last rewards accumulation
21
- uint128 public lastRewardBlock;
15
+ uint128 lastRewardBlock;
16
+ // number of blocks before reaching the max rewards multiplier (starting at 0.5 reaching 1 after maxMultiplierThreshold)
17
+ uint64 maxMultiplierThreshold;
18
+ // Staking contracts accepts Tokens with max 18 decimals so this variable holds decimal difference between 18 and Token's decimal in order to make calculations
19
+ uint8 tokenDecimalDifference;
20
+
22
21
  // accumulated rewards per share in 27 decimals precision
23
- uint256 public accAmountPerShare;
22
+ uint256 accAmountPerShare;
24
23
 
25
24
  //status of user rewards. everything is in 18 decimals
26
25
  struct UserInfo {
@@ -34,6 +33,32 @@ contract BaseShareFieldV2 is DSMath {
34
33
  }
35
34
  mapping(address => UserInfo) public users;
36
35
 
36
+ function getStats()
37
+ external
38
+ view
39
+ returns (
40
+ uint256 _accAmountPerShare,
41
+ uint128 _mintedRewards,
42
+ uint128 _totalProductivity,
43
+ uint128 _totalEffectiveStakes,
44
+ uint128 _accumulatedRewards,
45
+ uint128 _lastRewardBlock,
46
+ uint64 _maxMultiplierThreshold,
47
+ uint8 _tokenDecimalDifference
48
+ )
49
+ {
50
+ return (
51
+ accAmountPerShare,
52
+ mintedRewards,
53
+ totalProductivity,
54
+ totalEffectiveStakes,
55
+ accumulatedRewards,
56
+ lastRewardBlock,
57
+ maxMultiplierThreshold,
58
+ tokenDecimalDifference
59
+ );
60
+ }
61
+
37
62
  /**
38
63
  * @dev Helper function to check if caller is fund manager
39
64
  */
@@ -159,10 +184,10 @@ contract BaseShareFieldV2 is DSMath {
159
184
  {
160
185
  uint256 blocksPaid = _userInfo.lastRewardTime -
161
186
  _userInfo.multiplierResetTime; // lastRewardTime is always >= multiplierResetTime
162
- uint256 blocksPassedFirstMonth = Math.min(
163
- maxMultiplierThreshold,
187
+ uint256 blocksPassedFirstMonth = maxMultiplierThreshold <
164
188
  block.number - _userInfo.multiplierResetTime
165
- );
189
+ ? maxMultiplierThreshold
190
+ : block.number - _userInfo.multiplierResetTime;
166
191
  // blocks which is after first month
167
192
  uint256 blocksToPay = block.number - _userInfo.lastRewardTime; // blocks passed since last payment
168
193
  uint256 firstMonthBlocksToPay = blocksPaid >= maxMultiplierThreshold
@@ -292,13 +317,12 @@ contract BaseShareFieldV2 is DSMath {
292
317
  uint256 blockStart,
293
318
  uint256 blockEnd
294
319
  ) public returns (uint256) {
295
- UserInfo storage userInfo = users[user];
296
320
  _canMintRewards();
297
321
  _update(rewardsPerBlock, blockStart, blockEnd);
298
- _audit(user, userInfo.amount, 1); // donationPer variable should be something different than zero so called with 1
299
- uint128 amount = userInfo.rewardEarn;
300
- userInfo.rewardEarn = 0;
301
- userInfo.rewardMinted += amount;
322
+ _audit(user, users[user].amount, 1); // donationPer variable should be something different than zero so called with 1
323
+ uint128 amount = users[user].rewardEarn;
324
+ users[user].rewardEarn = 0;
325
+ users[user].rewardMinted += amount;
302
326
  mintedRewards = mintedRewards + amount;
303
327
  amount = amount / 1e16; // change decimal of mint amount to GD decimals
304
328
  return amount;
@@ -174,11 +174,6 @@ abstract contract SimpleStaking is
174
174
  uint256
175
175
  );
176
176
 
177
- /**
178
- * @dev Approve infinite tokens to defi protocols in order to save gas
179
- */
180
- function _approveTokens() internal virtual;
181
-
182
177
  /**
183
178
  * @dev Allows a staker to deposit Tokens. Notice that `approve` is
184
179
  * needed to be executed before the execution of this method.
@@ -368,8 +363,6 @@ abstract contract SimpleStaking is
368
363
  );
369
364
 
370
365
  if (address(sd) != address(0)) {
371
- address[] memory contracts;
372
- contracts[0] = (address(this));
373
366
  sd.userWithdraw(_from, _value);
374
367
  sd.userStaked(_to, _value);
375
368
  }
@@ -83,10 +83,7 @@ abstract contract SimpleStakingV2 is
83
83
  token = ERC20(_token);
84
84
  iToken = ERC20(_iToken);
85
85
  __ERC20_init(_tokenName, _tokenSymbol);
86
- require(
87
- token.decimals() <= 18,
88
- "Token decimals should be less than 18 decimals"
89
- );
86
+ require(token.decimals() <= 18, "decimals");
90
87
  tokenDecimalDifference = 18 - token.decimals();
91
88
  maxMultiplierThreshold = _maxRewardThreshold;
92
89
  }
@@ -102,7 +99,7 @@ abstract contract SimpleStakingV2 is
102
99
  * @return Worth of given amount of iToken in Token
103
100
  */
104
101
  function iTokenWorthInToken(uint256 _amount)
105
- public
102
+ internal
106
103
  view
107
104
  virtual
108
105
  returns (uint256);
@@ -174,11 +171,6 @@ abstract contract SimpleStakingV2 is
174
171
  uint256
175
172
  );
176
173
 
177
- /**
178
- * @dev Approve infinite tokens to defi protocols in order to save gas
179
- */
180
- function _approveTokens() internal virtual;
181
-
182
174
  /**
183
175
  * @dev Allows a staker to deposit Tokens. Notice that `approve` is
184
176
  * needed to be executed before the execution of this method.
@@ -193,18 +185,15 @@ abstract contract SimpleStakingV2 is
193
185
  bool _inInterestToken
194
186
  ) external virtual nonReentrant {
195
187
  require(isPaused == false, "Staking is paused");
196
- require(
197
- _donationPer == 0 || _donationPer == 100,
198
- "Donation percentage should be 0 or 100"
199
- );
200
- require(_amount > 0, "You need to stake a positive token amount");
188
+ require(_donationPer == 0 || _donationPer == 100, "donationPer");
189
+ require(_amount > 0, "amount");
201
190
  require(
202
191
  (_inInterestToken ? iToken : token).transferFrom(
203
192
  _msgSender(),
204
193
  address(this),
205
194
  _amount
206
195
  ),
207
- "transferFrom failed, make sure you approved token transfer"
196
+ "approve"
208
197
  );
209
198
  _amount = _inInterestToken ? iTokenWorthInToken(_amount) : _amount;
210
199
  if (_inInterestToken == false) {
@@ -255,10 +244,7 @@ abstract contract SimpleStakingV2 is
255
244
 
256
245
  if (_inInterestToken) {
257
246
  uint256 tokenWorth = iTokenWorthInToken(_amount);
258
- require(
259
- iToken.transfer(_msgSender(), _amount),
260
- "withdraw transfer failed"
261
- );
247
+ require(iToken.transfer(_msgSender(), _amount), "iWithdraw");
262
248
  tokenWithdraw = _amount = tokenWorth;
263
249
  } else {
264
250
  tokenWithdraw = _amount;
@@ -269,10 +255,7 @@ abstract contract SimpleStakingV2 is
269
255
  if (tokenActual < tokenWithdraw) {
270
256
  tokenWithdraw = tokenActual;
271
257
  }
272
- require(
273
- token.transfer(_msgSender(), tokenWithdraw),
274
- "withdraw transfer failed"
275
- );
258
+ require(token.transfer(_msgSender(), tokenWithdraw), "withdraw");
276
259
  }
277
260
 
278
261
  GoodFundManager fm = GoodFundManager(
@@ -344,7 +327,6 @@ abstract contract SimpleStakingV2 is
344
327
  uint256 _value
345
328
  ) internal override {
346
329
  super._transfer(_from, _to, _value);
347
-
348
330
  StakersDistribution sd = StakersDistribution(
349
331
  nameService.getAddress("GDAO_STAKERS")
350
332
  );
@@ -368,8 +350,6 @@ abstract contract SimpleStakingV2 is
368
350
  );
369
351
 
370
352
  if (address(sd) != address(0)) {
371
- address[] memory contracts;
372
- contracts[0] = (address(this));
373
353
  sd.userWithdraw(_from, _value);
374
354
  sd.userStaked(_to, _value);
375
355
  }
@@ -403,11 +383,6 @@ abstract contract SimpleStakingV2 is
403
383
  )
404
384
  {
405
385
  _canMintRewards();
406
- // otherwise fund manager has to wait for the next interval
407
- require(
408
- _recipient != address(this),
409
- "Recipient cannot be the staking contract"
410
- );
411
386
 
412
387
  (uint256 iTokenGains, uint256 tokenGains, , , ) = currentGains(
413
388
  false,
@@ -449,15 +424,9 @@ abstract contract SimpleStakingV2 is
449
424
 
450
425
  // recover left iToken(stakers token) only when all stakes have been withdrawn
451
426
  if (address(_token) == address(iToken)) {
452
- require(
453
- totalProductivity == 0 && isPaused,
454
- "can recover iToken only when stakes have been withdrawn"
455
- );
427
+ require(totalProductivity == 0 && isPaused, "recover");
456
428
  }
457
- require(
458
- _token.transfer(address(avatar), toWithdraw),
459
- "recover transfer failed"
460
- );
429
+ require(_token.transfer(address(avatar), toWithdraw), "transfer");
461
430
  }
462
431
 
463
432
  /**
@@ -478,10 +447,7 @@ abstract contract SimpleStakingV2 is
478
447
  }
479
448
 
480
449
  function _canMintRewards() internal view override {
481
- require(
482
- _msgSender() == nameService.getAddress("FUND_MANAGER"),
483
- "Only FundManager can call this method"
484
- );
450
+ require(_msgSender() == nameService.getAddress("FUND_MANAGER"), "fund");
485
451
  }
486
452
 
487
453
  function decimals() public view virtual override returns (uint8) {
@@ -2,7 +2,7 @@
2
2
 
3
3
  pragma solidity >=0.8.0;
4
4
  import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";
5
- import "./GoodAaveStaking.sol";
5
+ import "./GoodAaveStakingV2.sol";
6
6
  import "../../Interfaces.sol";
7
7
 
8
8
  /**
@@ -14,19 +14,43 @@ import "../../Interfaces.sol";
14
14
  contract AaveStakingFactory {
15
15
  using ClonesUpgradeable for address;
16
16
 
17
- address impl = address(new GoodAaveStaking());
17
+ address public impl = address(new GoodAaveStakingV2());
18
18
 
19
- event Deployed(address proxy, address token);
19
+ event Deployed(address proxy, address token, address impl);
20
20
 
21
- function clone(ERC20 token, bytes32 paramsHash)
22
- public
23
- returns (GoodAaveStaking)
24
- {
25
- address deployed = address(impl).cloneDeterministic(
21
+ function clone(
22
+ address _impl,
23
+ ERC20 token,
24
+ bytes32 paramsHash
25
+ ) internal returns (GoodAaveStakingV2) {
26
+ address deployed = address(_impl).cloneDeterministic(
26
27
  keccak256(abi.encodePacked(address(token), paramsHash))
27
28
  );
28
- emit Deployed(deployed, address(token));
29
- return GoodAaveStaking(deployed);
29
+ emit Deployed(deployed, address(token), _impl);
30
+ return GoodAaveStakingV2(deployed);
31
+ }
32
+
33
+ function cloneAndInit(
34
+ ERC20 token,
35
+ address _lendingPool,
36
+ INameService _ns,
37
+ uint64 _maxRewardThreshold,
38
+ address _tokenUsdOracle,
39
+ IAaveIncentivesController _incentiveController,
40
+ address _aaveUSDOracle,
41
+ address[] memory _tokenToDaiSwapPath
42
+ ) public {
43
+ cloneAndInit(
44
+ impl,
45
+ token,
46
+ _lendingPool,
47
+ _ns,
48
+ _maxRewardThreshold,
49
+ _tokenUsdOracle,
50
+ _incentiveController,
51
+ _aaveUSDOracle,
52
+ _tokenToDaiSwapPath
53
+ );
30
54
  }
31
55
 
32
56
  /**
@@ -40,6 +64,7 @@ contract AaveStakingFactory {
40
64
  @param _aaveUSDOracle address of the AAVE/USD oracle
41
65
  */
42
66
  function cloneAndInit(
67
+ address _impl,
43
68
  ERC20 token,
44
69
  address _lendingPool,
45
70
  INameService _ns,
@@ -49,7 +74,8 @@ contract AaveStakingFactory {
49
74
  address _aaveUSDOracle,
50
75
  address[] memory _tokenToDaiSwapPath
51
76
  ) public {
52
- GoodAaveStaking deployed = clone(
77
+ GoodAaveStakingV2 deployed = clone(
78
+ _impl,
53
79
  token,
54
80
  keccak256(
55
81
  abi.encodePacked(
@@ -67,8 +93,8 @@ contract AaveStakingFactory {
67
93
  address(token),
68
94
  address(_lendingPool),
69
95
  _ns,
70
- string(abi.encodePacked("GoodAaveStaking ", token.name())),
71
- string(abi.encodePacked("g", token.symbol())),
96
+ string(abi.encodePacked("GoodAaveStakingV2 ", token.name())),
97
+ string(abi.encodePacked("ga", token.symbol())),
72
98
  _maxRewardThreshold,
73
99
  _tokenUsdOracle,
74
100
  _incentiveController,
@@ -77,13 +103,13 @@ contract AaveStakingFactory {
77
103
  );
78
104
  }
79
105
 
80
- function predictAddress(ERC20 token, bytes32 paramsHash)
81
- public
82
- view
83
- returns (address)
84
- {
106
+ function predictAddress(
107
+ address _impl,
108
+ ERC20 token,
109
+ bytes32 paramsHash
110
+ ) public view returns (address) {
85
111
  return
86
- address(impl).predictDeterministicAddress(
112
+ address(_impl).predictDeterministicAddress(
87
113
  keccak256(abi.encodePacked(address(token), paramsHash))
88
114
  );
89
115
  }
@@ -262,7 +262,7 @@ contract GoodAaveStaking is SimpleStaking {
262
262
  return _amount; // since aToken is peg to Token 1:1 return exact amount
263
263
  }
264
264
 
265
- function _approveTokens() internal override {
265
+ function _approveTokens() internal {
266
266
  address uniswapRouter = nameService.getAddress("UNISWAP_ROUTER");
267
267
  token.approve(uniswapRouter, type(uint256).max);
268
268
  token.approve(address(lendingPool), type(uint256).max); // approve the transfers to defi protocol as much as possible in order to save gas
@@ -247,7 +247,7 @@ contract GoodAaveStakingV2 is SimpleStakingV2 {
247
247
  * @return Worth of given amount of token in Token
248
248
  */
249
249
  function iTokenWorthInToken(uint256 _amount)
250
- public
250
+ internal
251
251
  view
252
252
  override
253
253
  returns (uint256)
@@ -255,7 +255,7 @@ contract GoodAaveStakingV2 is SimpleStakingV2 {
255
255
  return _amount; // since aToken is peg to Token 1:1 return exact amount
256
256
  }
257
257
 
258
- function _approveTokens() internal override {
258
+ function _approveTokens() internal {
259
259
  address uniswapRouter = nameService.getAddress("UNISWAP_ROUTER");
260
260
  token.approve(uniswapRouter, type(uint256).max);
261
261
  token.approve(address(lendingPool), type(uint256).max); // approve the transfers to defi protocol as much as possible in order to save gas
@@ -2,7 +2,7 @@
2
2
 
3
3
  pragma solidity >=0.8.0;
4
4
  import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";
5
- import "./GoodCompoundStaking.sol";
5
+ import "./GoodCompoundStakingV2.sol";
6
6
  import "../../Interfaces.sol";
7
7
 
8
8
  /**
@@ -14,23 +14,44 @@ import "../../Interfaces.sol";
14
14
  contract CompoundStakingFactory {
15
15
  using ClonesUpgradeable for address;
16
16
 
17
- address impl = address(new GoodCompoundStaking());
17
+ address public impl = address(new GoodCompoundStakingV2());
18
18
 
19
- event Deployed(address proxy, address cToken);
19
+ event Deployed(address proxy, address cToken, address impl);
20
20
 
21
- function clone(cERC20 cToken, bytes32 paramsHash)
22
- public
23
- returns (GoodCompoundStaking)
24
- {
25
- address deployed = address(impl).cloneDeterministic(
21
+ function clone(
22
+ address _impl,
23
+ cERC20 cToken,
24
+ bytes32 paramsHash
25
+ ) internal returns (GoodCompoundStakingV2) {
26
+ address deployed = address(_impl).cloneDeterministic(
26
27
  keccak256(abi.encodePacked(address(cToken), paramsHash))
27
28
  );
28
- emit Deployed(deployed, address(cToken));
29
- return GoodCompoundStaking(deployed);
29
+ emit Deployed(deployed, address(cToken), _impl);
30
+ return GoodCompoundStakingV2(deployed);
31
+ }
32
+
33
+ function cloneAndInit(
34
+ cERC20 _cToken,
35
+ INameService _ns,
36
+ uint64 _maxRewardThreshold,
37
+ address _tokenUsdOracle,
38
+ address _compUsdOracle,
39
+ address[] memory _tokenToDaiSwapPath
40
+ ) public {
41
+ cloneAndInit(
42
+ impl,
43
+ _cToken,
44
+ _ns,
45
+ _maxRewardThreshold,
46
+ _tokenUsdOracle,
47
+ _compUsdOracle,
48
+ _tokenToDaiSwapPath
49
+ );
30
50
  }
31
51
 
32
52
  /**
33
53
  @dev Function to clone Staking contract and initialize new one with new ctoken
54
+ @param _impl address of contract to clone
34
55
  @param cToken Staking cToken to use in staking contract
35
56
  @param _ns NameService that holds whole necessary addresses
36
57
  @param _maxRewardThreshold Block numbers that need to pass in order to user would get their rewards with 1x multiplier instead of 0.5x
@@ -38,6 +59,7 @@ contract CompoundStakingFactory {
38
59
  @param _compUsdOracle address of the AAVE/USD oracle
39
60
  */
40
61
  function cloneAndInit(
62
+ address _impl,
41
63
  cERC20 cToken,
42
64
  INameService _ns,
43
65
  uint64 _maxRewardThreshold,
@@ -45,7 +67,8 @@ contract CompoundStakingFactory {
45
67
  address _compUsdOracle,
46
68
  address[] memory _tokenToDaiSwapPath
47
69
  ) public {
48
- GoodCompoundStaking deployed = clone(
70
+ GoodCompoundStakingV2 deployed = clone(
71
+ _impl,
49
72
  cToken,
50
73
  keccak256(
51
74
  abi.encodePacked(
@@ -60,7 +83,7 @@ contract CompoundStakingFactory {
60
83
  cToken.underlying(),
61
84
  address(cToken),
62
85
  _ns,
63
- string(abi.encodePacked("GoodCompoundStaking ", cToken.name())),
86
+ string(abi.encodePacked("GoodCompoundStakingV2 ", cToken.name())),
64
87
  string(abi.encodePacked("g", cToken.symbol())),
65
88
  _maxRewardThreshold,
66
89
  _tokenUsdOracle,
@@ -69,13 +92,13 @@ contract CompoundStakingFactory {
69
92
  );
70
93
  }
71
94
 
72
- function predictAddress(cERC20 cToken, bytes32 paramsHash)
73
- public
74
- view
75
- returns (address)
76
- {
95
+ function predictAddress(
96
+ address _impl,
97
+ cERC20 cToken,
98
+ bytes32 paramsHash
99
+ ) public view returns (address) {
77
100
  return
78
- address(impl).predictDeterministicAddress(
101
+ address(_impl).predictDeterministicAddress(
79
102
  keccak256(abi.encodePacked(address(cToken), paramsHash))
80
103
  );
81
104
  }
@@ -315,7 +315,7 @@ contract GoodCompoundStaking is SimpleStaking {
315
315
  compCollectGasCost = _rewardTokenCollectCost;
316
316
  }
317
317
 
318
- function _approveTokens() internal override {
318
+ function _approveTokens() internal {
319
319
  address uniswapRouter = address(uniswapContract);
320
320
  comp.approve(uniswapRouter, type(uint256).max);
321
321
  token.approve(uniswapRouter, type(uint256).max);