@gooddollar/goodprotocol 1.0.30 → 1.0.31-beta.0

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 (151) hide show
  1. package/artifacts/abis/FuseStakingV3.min.json +1 -1
  2. package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
  3. package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
  4. package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
  5. package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
  6. package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
  7. package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
  8. package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
  9. package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
  10. package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
  11. package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
  12. package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
  13. package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
  14. package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
  15. package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
  16. package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
  17. package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
  18. package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
  19. package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
  20. package/artifacts/contracts/Interfaces.sol/IMultichainRouter.dbg.json +1 -1
  21. package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
  22. package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
  23. package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
  24. package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
  25. package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
  26. package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
  27. package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
  28. package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
  29. package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
  30. package/artifacts/contracts/fuseFaucet/FuseFaucet.sol/FuseFaucet.dbg.json +1 -1
  31. package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
  32. package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
  33. package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
  34. package/artifacts/contracts/governance/GoodDollarStaking.sol/GoodDollarStaking.dbg.json +1 -1
  35. package/artifacts/contracts/governance/GoodDollarStaking.sol/RewardsMinter.dbg.json +1 -1
  36. package/artifacts/contracts/governance/GovernanceStaking.sol/GovernanceStaking.dbg.json +1 -1
  37. package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
  38. package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
  39. package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
  40. package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.json +2 -2
  41. package/artifacts/contracts/invite/InvitesV1.sol/InvitesV1.dbg.json +1 -1
  42. package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
  43. package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
  44. package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
  45. package/artifacts/contracts/mocks/DistributionBridgeMock.sol/DistributionBridgeMock.dbg.json +1 -1
  46. package/artifacts/contracts/mocks/DistributionHelperTest.sol/DistributionHelperTest.dbg.json +1 -1
  47. package/artifacts/contracts/mocks/DistributionHelperTest.sol/DistributionHelperTestHelper.dbg.json +1 -1
  48. package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
  49. package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.json +2 -2
  50. package/artifacts/contracts/mocks/GoodDollarStakingMock.sol/GoodDollarStakingMock.dbg.json +1 -1
  51. package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
  52. package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.json +2 -2
  53. package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
  54. package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
  55. package/artifacts/contracts/mocks/MultichainRouterMock.sol/IWrapper.dbg.json +1 -1
  56. package/artifacts/contracts/mocks/MultichainRouterMock.sol/MultichainRouterMock.dbg.json +1 -1
  57. package/artifacts/contracts/mocks/OverMintTester.sol/IGoodDollarStakingTest.dbg.json +1 -1
  58. package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
  59. package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
  60. package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.json +2 -2
  61. package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
  62. package/artifacts/contracts/mocks/StakingMockFixedAPY.sol/StakingMockFixedAPY.dbg.json +1 -1
  63. package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
  64. package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
  65. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
  66. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
  67. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.dbg.json +1 -1
  68. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.dbg.json +1 -1
  69. package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
  70. package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
  71. package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
  72. package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
  73. package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
  74. package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
  75. package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
  76. package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
  77. package/artifacts/contracts/reserve/DistributionHelper.sol/DistributionHelper.dbg.json +1 -1
  78. package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
  79. package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
  80. package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
  81. package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
  82. package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
  83. package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +1 -1
  84. package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
  85. package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.json +2 -2
  86. package/artifacts/contracts/staking/FuseStakingV3.sol/FuseStakingV3.dbg.json +1 -1
  87. package/artifacts/contracts/staking/FuseStakingV3.sol/FuseStakingV3.json +31 -83
  88. package/artifacts/contracts/staking/FuseStakingV3.sol/IConsensus.dbg.json +1 -1
  89. package/artifacts/contracts/staking/FuseStakingV3.sol/PegSwap.dbg.json +1 -1
  90. package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
  91. package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.json +2 -2
  92. package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
  93. package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +1 -1
  94. package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
  95. package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
  96. package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.json +2 -2
  97. package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
  98. package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.json +2 -2
  99. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
  100. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +2 -2
  101. package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
  102. package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.json +2 -2
  103. package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
  104. package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.json +2 -2
  105. package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +1 -1
  106. package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.json +2 -2
  107. package/artifacts/contracts/staking/utils/Math64X64.sol/Math64x64.dbg.json +1 -1
  108. package/artifacts/contracts/staking/utils/StakingRewardsFixedAPY.sol/StakingRewardsFixedAPY.dbg.json +1 -1
  109. package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
  110. package/artifacts/contracts/utils/AdminWallet.sol/AdminWallet.dbg.json +1 -1
  111. package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
  112. package/artifacts/contracts/utils/BulkProof.sol/BulkProof.dbg.json +1 -1
  113. package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
  114. package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
  115. package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
  116. package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
  117. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/GoodDollarMintBurnWrapper.dbg.json +1 -1
  118. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/IRouter.dbg.json +1 -1
  119. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/PausableControl.dbg.json +1 -1
  120. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/TokenOperation.dbg.json +1 -1
  121. package/artifacts/contracts/utils/MultichainBridgeHelper.sol/MultichainBridgeHelper.dbg.json +1 -1
  122. package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
  123. package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
  124. package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
  125. package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
  126. package/artifacts/contracts/utils/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.dbg.json +1 -1
  127. package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.dbg.json +1 -1
  128. package/artifacts/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy.dbg.json +1 -1
  129. package/artifacts/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967.dbg.json +1 -1
  130. package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
  131. package/contracts/staking/FuseStakingV3.sol +42 -112
  132. package/contracts/staking/GoodFundManager.sol +2 -2
  133. package/hardhat.config.ts +4 -1
  134. package/package.json +1 -1
  135. package/scripts/multichain-deploy/v3-fix.ts +120 -0
  136. package/test/staking/FuseStaking.test.ts +2 -4
  137. package/test/staking/StakingRewards.test.ts +13 -16
  138. package/types/FuseStakingV3.ts +66 -208
  139. package/types/factories/AaveStakingFactory__factory.ts +1 -1
  140. package/types/factories/CompoundStakingFactory__factory.ts +1 -1
  141. package/types/factories/DonationsStaking__factory.ts +1 -1
  142. package/types/factories/FuseStakingV3__factory.ts +30 -82
  143. package/types/factories/GoodAaveStakingV2__factory.ts +1 -1
  144. package/types/factories/GoodAaveStaking__factory.ts +1 -1
  145. package/types/factories/GoodCompoundStakingTest__factory.ts +1 -1
  146. package/types/factories/GoodCompoundStakingV2__factory.ts +1 -1
  147. package/types/factories/GoodCompoundStaking__factory.ts +1 -1
  148. package/types/factories/GoodFundManagerTest__factory.ts +1 -1
  149. package/types/factories/GoodFundManager__factory.ts +1 -1
  150. package/types/factories/OverMintTesterRegularStake__factory.ts +1 -1
  151. package/types/factories/StakersDistribution__factory.ts +1 -1
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/1978ac65522bd5d330515fa5e80306f2.json"
3
+ "buildInfo": "../../../build-info/82edabb017e079b951c9a9557f562e2a.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/1978ac65522bd5d330515fa5e80306f2.json"
3
+ "buildInfo": "../../../build-info/82edabb017e079b951c9a9557f562e2a.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/1978ac65522bd5d330515fa5e80306f2.json"
3
+ "buildInfo": "../../../build-info/82edabb017e079b951c9a9557f562e2a.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/1978ac65522bd5d330515fa5e80306f2.json"
3
+ "buildInfo": "../../../build-info/82edabb017e079b951c9a9557f562e2a.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/1978ac65522bd5d330515fa5e80306f2.json"
3
+ "buildInfo": "../../../build-info/82edabb017e079b951c9a9557f562e2a.json"
4
4
  }
@@ -98,12 +98,27 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
98
98
  /**
99
99
  * @dev initialize
100
100
  */
101
- function initialize() public initializer {
101
+ function initialize(address _uniswap, address _gd) public initializer {
102
102
  __Ownable_init_unchained();
103
- consensus = IConsensus(
104
- address(0x3014ca10b91cb3D0AD85fEf7A3Cb95BCAc9c0f79)
105
- );
103
+ consensus = IConsensus(address(0x3014ca10b91cb3D0AD85fEf7A3Cb95BCAc9c0f79));
106
104
  validators.push(address(0xcb876A393F05a6677a8a029f1C6D7603B416C0A6));
105
+ stakeBackRatio = 33333; //%33
106
+ communityPoolRatio = 33333; //%33
107
+ maxSlippageRatio = 3000; //3%
108
+ keeperFeeRatio = 30; //0.03%
109
+ RATIO_BASE = 100000; //100%
110
+ uniswap = Uniswap(
111
+ _uniswap == address(0)
112
+ ? 0xE3F85aAd0c8DD7337427B9dF5d0fB741d65EEEB5
113
+ : _uniswap
114
+ );
115
+
116
+ GD = IGoodDollar(_gd);
117
+ uniswapFactory = UniswapFactory(uniswap.factory());
118
+ uniswapPair = UniswapPair(uniswapFactory.getPair(uniswap.WETH(), _gd));
119
+ pegSwap = PegSwap(0xdfE016328E7BcD6FA06614fE3AF3877E931F7e0a);
120
+ USDC = address(0x620fd5fa44BE6af63715Ef4E65DDFA0387aD13F5);
121
+ fUSD = address(0x249BE57637D8B013Ad64785404b24aeBaE9B098B);
107
122
  }
108
123
 
109
124
  modifier notPaused() {
@@ -116,79 +131,13 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
116
131
  _;
117
132
  }
118
133
 
119
- function upgrade0() external {
120
- if (RATIO_BASE == 0) {
121
- stakeBackRatio = 33333; //%33
122
- communityPoolRatio = 33333; //%33
123
- maxSlippageRatio = 3000; //3%
124
- keeperFeeRatio = 30; //0.03%
125
- RATIO_BASE = 100000; //100%
126
- }
127
- }
128
-
129
- function upgrade1(
130
- address _gd,
131
- address _ubischeme,
132
- address _uniswap
133
- ) external {
134
- if (address(uniswapPair) == address(0)) {
135
- uniswap = Uniswap(
136
- _uniswap == address(0)
137
- ? 0xFB76e9E7d88E308aB530330eD90e84a952570319
138
- : _uniswap
139
- );
140
- GD = IGoodDollar(_gd);
141
- ubischeme = UBIScheme(_ubischeme);
142
-
143
- uniswapFactory = UniswapFactory(uniswap.factory());
144
- uniswapPair = UniswapPair(
145
- uniswapFactory.getPair(uniswap.WETH(), _gd)
146
- );
147
- }
148
- }
149
-
150
- function upgrade2() external {
151
- if (USDC == address(0)) {
152
- USDC = address(0x620fd5fa44BE6af63715Ef4E65DDFA0387aD13F5);
153
- fUSD = address(0x249BE57637D8B013Ad64785404b24aeBaE9B098B);
154
- }
155
- }
156
-
157
- function upgrade3() external {
158
- if (guardian == address(0)) {
159
- paused = true;
160
- guardian = address(0x5128E3C1f8846724cc1007Af9b4189713922E4BB);
161
- }
162
- }
163
-
164
- function upgrade4() external {
165
- if (address(pegSwap) == address(0)) {
166
- pegSwap = PegSwap(0xdfE016328E7BcD6FA06614fE3AF3877E931F7e0a);
167
- paused = false;
168
- }
169
- }
170
-
171
- function upgrade5() external {
134
+ function approve() external {
172
135
  cERC20(fUSD).approve(address(pegSwap), type(uint256).max);
173
136
  cERC20(USDC).approve(address(uniswap), type(uint256).max);
174
137
  }
175
138
 
176
- function upgrade6() external {
177
- //switch to voltage
178
- uniswap = Uniswap(0xE3F85aAd0c8DD7337427B9dF5d0fB741d65EEEB5);
179
- uniswapFactory = UniswapFactory(uniswap.factory());
180
- uniswapPair = UniswapPair(
181
- uniswapFactory.getPair(uniswap.WETH(), address(GD))
182
- );
183
- }
184
-
185
- function setContracts(address _gd, address _ubischeme) public onlyOwner {
186
- if (_gd != address(0)) {
187
- GD = IGoodDollar(_gd);
188
- }
189
- if (_ubischeme != address(0)) {
190
- ubischeme = UBIScheme(_ubischeme);
191
- }
139
+ function setUBIScheme(address _ubischeme) public onlyOwner {
140
+ ubischeme = UBIScheme(_ubischeme);
192
141
  }
193
142
 
194
143
  function stake() public payable returns (bool) {
@@ -230,17 +179,15 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
230
179
 
231
180
  function withdrawAll() public onlyGuardian {
232
181
  for (uint256 i = 0; i < validators.length; i++) {
233
- uint256 cur = consensus.delegatedAmount(
234
- address(this),
235
- validators[i]
236
- );
182
+ uint256 cur = consensus.delegatedAmount(address(this), validators[i]);
237
183
  if (cur == 0) continue;
238
184
  undelegateWithCatch(validators[i], cur);
239
185
  }
240
186
  uint256 effectiveBalance = balance(); //use only undelegated funds
241
187
  pendingFuseEarnings = 0;
242
188
  if (effectiveBalance > 0) {
243
- msg.sender.call{ value: effectiveBalance }("");
189
+ (bool ok, ) = msg.sender.call{ value: effectiveBalance }("");
190
+ require(ok, "transfer failed");
244
191
  }
245
192
  }
246
193
 
@@ -254,10 +201,7 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
254
201
  );
255
202
  uint256 perValidator = _value.div(validators.length);
256
203
  for (uint256 i = 0; i < validators.length; i++) {
257
- uint256 cur = consensus.delegatedAmount(
258
- address(this),
259
- validators[i]
260
- );
204
+ uint256 cur = consensus.delegatedAmount(address(this), validators[i]);
261
205
  if (cur == 0) continue;
262
206
  if (cur <= perValidator) {
263
207
  undelegateWithCatch(validators[i], cur);
@@ -296,10 +240,7 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
296
240
  uint256 perValidator = (totalDelegated() + _value) / validators.length;
297
241
  uint256 left = _value;
298
242
  for (uint256 i = 0; i < validators.length && left > 0; i++) {
299
- uint256 cur = consensus.delegatedAmount(
300
- address(this),
301
- validators[i]
302
- );
243
+ uint256 cur = consensus.delegatedAmount(address(this), validators[i]);
303
244
 
304
245
  if (cur < perValidator) {
305
246
  uint256 toDelegate = perValidator.sub(cur);
@@ -319,20 +260,14 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
319
260
  function totalDelegated() public view returns (uint256) {
320
261
  uint256 total = 0;
321
262
  for (uint256 i = 0; i < validators.length; i++) {
322
- uint256 cur = consensus.delegatedAmount(
323
- address(this),
324
- validators[i]
325
- );
263
+ uint256 cur = consensus.delegatedAmount(address(this), validators[i]);
326
264
  total += cur;
327
265
  }
328
266
  return total;
329
267
  }
330
268
 
331
269
  function removeValidator(address _validator) public onlyOwner {
332
- uint256 delegated = consensus.delegatedAmount(
333
- address(this),
334
- _validator
335
- );
270
+ uint256 delegated = consensus.delegatedAmount(address(this), _validator);
336
271
  if (delegated > 0) {
337
272
  uint256 prevBalance = balance();
338
273
  undelegateWithCatch(_validator, delegated);
@@ -356,18 +291,13 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
356
291
 
357
292
  function collectUBIInterest() public notPaused {
358
293
  uint256 curDay = ubischeme.currentDay();
359
- require(
360
- curDay != lastDayCollected,
361
- "can collect only once in a ubi cycle"
362
- );
294
+ require(curDay != lastDayCollected, "can collect only once in a ubi cycle");
363
295
 
364
296
  uint256 earnings = balance() - pendingFuseEarnings;
365
297
  require(pendingFuseEarnings + earnings > 0, "no earnings to collect");
366
298
 
367
299
  lastDayCollected = curDay;
368
- uint256 fuseUBI = earnings.mul(RATIO_BASE - stakeBackRatio).div(
369
- RATIO_BASE
370
- );
300
+ uint256 fuseUBI = earnings.mul(RATIO_BASE - stakeBackRatio).div(RATIO_BASE);
371
301
  uint256 stakeBack = earnings - fuseUBI;
372
302
 
373
303
  uint256[] memory fuseswapResult = _buyGD(fuseUBI + pendingFuseEarnings); //buy GD with X% of earnings
@@ -378,9 +308,9 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
378
308
  uint256 keeperFee = gdBought.mul(keeperFeeRatio).div(RATIO_BASE);
379
309
  if (keeperFee > 0) GD.transfer(msg.sender, keeperFee);
380
310
  gdBought -= keeperFee;
381
- uint256 communityPoolContribution = gdBought
382
- .mul(communityPoolRatio)
383
- .div(RATIO_BASE); //subtract fee // * ommunityPoolRatio // = G$ after fee * communityPoolRatio%
311
+ uint256 communityPoolContribution = gdBought.mul(communityPoolRatio).div(
312
+ RATIO_BASE
313
+ ); //subtract fee // * ommunityPoolRatio // = G$ after fee * communityPoolRatio%
384
314
 
385
315
  uint256 ubiAfterFeeAndPool = gdBought.sub(communityPoolContribution);
386
316
 
@@ -407,13 +337,10 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
407
337
  function _buyGD(uint256 _value) internal returns (uint256[] memory) {
408
338
  //buy from uniwasp
409
339
  require(_value > 0, "buy value should be > 0");
410
- (uint256 maxFuse, uint256 fuseGDOut) = calcMaxFuseWithPriceImpact(
340
+ (uint256 maxFuse, uint256 fuseGDOut) = calcMaxFuseWithPriceImpact(_value);
341
+ (uint256 maxFuseUSDC, uint256 usdcGDOut) = calcMaxFuseUSDCWithPriceImpact(
411
342
  _value
412
343
  );
413
- (
414
- uint256 maxFuseUSDC,
415
- uint256 usdcGDOut
416
- ) = calcMaxFuseUSDCWithPriceImpact(_value);
417
344
  address[] memory path;
418
345
  if (maxFuse >= maxFuseUSDC) {
419
346
  path = new address[](2);
@@ -471,9 +398,12 @@ contract FuseStakingV3 is Initializable, OwnableUpgradeable {
471
398
  address[] memory path = new address[](2);
472
399
  path[1] = fUSD;
473
400
  path[0] = uniswap.WETH();
474
- uint256[] memory result = uniswap.swapExactETHForTokens{
475
- value: maxFuse
476
- }((tokenOut * 95) / 100, path, address(this), block.timestamp);
401
+ uint256[] memory result = uniswap.swapExactETHForTokens{ value: maxFuse }(
402
+ (tokenOut * 95) / 100,
403
+ path,
404
+ address(this),
405
+ block.timestamp
406
+ );
477
407
 
478
408
  pegSwap.swap(result[1], fUSD, USDC);
479
409
  usedFuse = result[0];
@@ -194,10 +194,10 @@ contract GoodFundManager is DAOUpgradeableContract, DSMath {
194
194
  }
195
195
  }
196
196
 
197
- if (exist && (_isBlackListed || _rewardsPerBlock == 0)) {
197
+ if (exist && _isBlackListed) {
198
198
  activeContracts[i] = activeContracts[activeContracts.length - 1];
199
199
  activeContracts.pop();
200
- } else if (!exist && !(_isBlackListed || _rewardsPerBlock == 0)) {
200
+ } else if (!exist && !_isBlackListed) {
201
201
  activeContracts.push(_stakingAddress);
202
202
  }
203
203
  emit StakingRewardSet(
package/hardhat.config.ts CHANGED
@@ -83,7 +83,10 @@ const hhconfig: HardhatUserConfig = {
83
83
  accounts: {
84
84
  accountsBalance: "10000000000000000000000000"
85
85
  },
86
- initialDate: "2021-12-01" //required for DAO tests like guardian
86
+ initialDate: "2021-12-01", //required for DAO tests like guardian
87
+ forking: process.env.FORK_CHAIN_ID && {
88
+ url: "https://eth-mainnet.alchemyapi.io/v2/" + process.env.ALCHEMY_KEY
89
+ }
87
90
  },
88
91
  test: {
89
92
  allowUnlimitedContractSize: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gooddollar/goodprotocol",
3
- "version": "1.0.30",
3
+ "version": "1.0.31-beta.0",
4
4
  "description": "GoodDollar Protocol",
5
5
  "scripts": {
6
6
  "build": "scripts/build.sh deploy",
@@ -0,0 +1,120 @@
1
+ /***
2
+ * This script will deploy a fixed goodfundmanager that doenst disable staking contracts if rewards=0
3
+ * It will also then re submit the staking contracts
4
+ */
5
+
6
+ import { network, ethers } from "hardhat";
7
+
8
+ import {
9
+ executeViaGuardian,
10
+ executeViaSafe
11
+ } from "../multichain-deploy/helpers";
12
+
13
+ import releaser from "../releaser";
14
+ import dao from "../../releases/deployment.json";
15
+ const { name: networkName } = network;
16
+
17
+ export const deployMainnet = async () => {
18
+ let [root, ...signers] = await ethers.getSigners();
19
+
20
+ let executionMethod = networkName === "localhost" ? "guardians" : "safe";
21
+
22
+ const networkKey =
23
+ networkName === "localhost" ? "production-mainnet" : networkName;
24
+ let release: { [key: string]: any } = dao[networkKey];
25
+
26
+ let safeOwner = new ethers.Wallet(
27
+ process.env.SAFEOWNER_PRIVATE_KEY || ethers.constants.HashZero,
28
+ ethers.provider
29
+ );
30
+
31
+ //test with guardians safe on hardhat mainnet fork
32
+ if (network.name === "localhost") {
33
+ root = await ethers.getImpersonatedSigner(
34
+ "0xE0c5daa7CC6F88d29505f702a53bb5E67600e7Ec"
35
+ );
36
+ await signers[0].sendTransaction({
37
+ to: root.address,
38
+ value: ethers.constants.WeiPerEther
39
+ });
40
+ }
41
+
42
+ console.log("got signers:", {
43
+ networkName,
44
+ networkKey,
45
+ root: root.address,
46
+ safeOwner: safeOwner.address,
47
+ balance: await ethers.provider
48
+ .getBalance(root.address)
49
+ .then(_ => _.toString())
50
+ });
51
+
52
+ console.log("deploying goodfundmanager implementation");
53
+ const gfmImpl = await (
54
+ await ethers.getContractFactory("GoodFundManager")
55
+ ).deploy();
56
+
57
+ const proposalContracts = [
58
+ release.GoodFundManager, //Fundmanager -> upgrade to new version
59
+ release.GoodFundManager, //Fundmanager -> set staking rewards compound to 0
60
+ release.GoodFundManager //Fundmanager -> set staking rewards aave to 0
61
+ ];
62
+
63
+ const proposalEthValues = proposalContracts.map(_ => 0);
64
+
65
+ const proposalFunctionSignatures = [
66
+ "upgradeTo(address)",
67
+ "setStakingReward(uint32,address,uint32,uint32,bool)",
68
+ "setStakingReward(uint32,address,uint32,uint32,bool)"
69
+ ];
70
+
71
+ const proposalFunctionInputs = [
72
+ ethers.utils.defaultAbiCoder.encode(["address"], [gfmImpl.address]), //upgradeTo(address)
73
+ ethers.utils.defaultAbiCoder.encode(
74
+ ["uint32", "address", "uint32", "uint32", "bool"],
75
+ [
76
+ "0",
77
+ "0x7b7246c78e2f900d17646ff0cb2ec47d6ba10754",
78
+ "14338692",
79
+ "4294967295",
80
+ false
81
+ ]
82
+ ), //setstakingrewards to 0
83
+ ethers.utils.defaultAbiCoder.encode(
84
+ ["uint32", "address", "uint32", "uint32", "bool"],
85
+ [
86
+ "0",
87
+ "0x3ff2d8eb2573819a9ef7167d2ba6fd6d31b17f4f",
88
+ "14338692",
89
+ "4294967295",
90
+ false
91
+ ]
92
+ ) //setstakingrewards to 0
93
+ ];
94
+
95
+ if (executionMethod === "safe") {
96
+ return executeViaSafe(
97
+ proposalContracts,
98
+ proposalEthValues,
99
+ proposalFunctionSignatures,
100
+ proposalFunctionInputs,
101
+ networkName === "localhost"
102
+ ? "0xE0c5daa7CC6F88d29505f702a53bb5E67600e7Ec"
103
+ : release.GuardiansSafe,
104
+ safeOwner
105
+ );
106
+ } else {
107
+ return executeViaGuardian(
108
+ proposalContracts,
109
+ proposalEthValues,
110
+ proposalFunctionSignatures,
111
+ proposalFunctionInputs,
112
+ root
113
+ );
114
+ }
115
+ };
116
+
117
+ export const main = async () => {
118
+ await deployMainnet().catch(console.log);
119
+ };
120
+ if (process.argv[1].includes("v3-fix")) main();
@@ -71,10 +71,8 @@ describe("FuseStakingV3", () => {
71
71
  await ethers.getContractFactory("FuseStakingV3")
72
72
  ).deploy()) as FuseStakingV3;
73
73
 
74
- await staking.initialize();
75
- await staking.upgrade0();
76
- await staking.upgrade1(NULL_ADDRESS, ubiMock.address, uniswap.address);
77
- await staking.upgrade2();
74
+ await staking.initialize(uniswap.address, NULL_ADDRESS);
75
+ await staking.setUBIScheme(ubiMock.address);
78
76
  });
79
77
 
80
78
  it("should have owner", async () => {
@@ -641,12 +641,13 @@ describe("StakingRewards - staking with cDAI mocks and get Rewards in GoodDollar
641
641
 
642
642
  await advanceBlocks(4);
643
643
 
644
- const userMintedAndPending = await goodCompoundStaking.getUserMintedAndPending(staker.address);
644
+ const userMintedAndPending =
645
+ await goodCompoundStaking.getUserMintedAndPending(staker.address);
645
646
  const userMintedReward = userMintedAndPending[0].toString();
646
647
  const userPendingReward = userMintedAndPending[1].toString();
647
648
  expect(userMintedReward).to.equal("5000");
648
649
  expect(userPendingReward).to.equal("2000");
649
-
650
+
650
651
  await goodCompoundStaking
651
652
  .connect(staker)
652
653
  .withdrawStake(stakingAmount, false);
@@ -1430,7 +1431,7 @@ describe("StakingRewards - staking with cDAI mocks and get Rewards in GoodDollar
1430
1431
  expect(data.isBlackListed).to.equal(true);
1431
1432
  });
1432
1433
 
1433
- it("it should remove staking contract from active staking contracts when it's reward set to zero", async () => {
1434
+ it("it should not remove staking contract from active staking contracts when it's reward set to zero", async () => {
1434
1435
  const simpleStaking1 = await goodCompoundStakingTestFactory.deploy(
1435
1436
  bat.address,
1436
1437
  cBat.address,
@@ -1449,9 +1450,6 @@ describe("StakingRewards - staking with cDAI mocks and get Rewards in GoodDollar
1449
1450
  await genericCall(goodFundManager.address, encodedData, avatar, 0);
1450
1451
  const activeContractsCount =
1451
1452
  await goodFundManager.getActiveContractsCount();
1452
- const lastActiveContractBeforeAdd = await goodFundManager.activeContracts(
1453
- activeContractsCount.sub(1)
1454
- );
1455
1453
 
1456
1454
  const simpleStaking = await goodCompoundStakingTestFactory.deploy(
1457
1455
  bat.address,
@@ -1471,9 +1469,9 @@ describe("StakingRewards - staking with cDAI mocks and get Rewards in GoodDollar
1471
1469
  await genericCall(goodFundManager.address, encodedData, avatar, 0);
1472
1470
  const activeContractsCountAfterAdded =
1473
1471
  await goodFundManager.getActiveContractsCount();
1474
- const lastActiveContractAfterAdd = await goodFundManager.activeContracts(
1475
- activeContractsCountAfterAdded.sub(1)
1476
- );
1472
+
1473
+ expect(activeContractsCountAfterAdded).equal(activeContractsCount.add(1));
1474
+
1477
1475
  encodedData = goodFundManager.interface.encodeFunctionData(
1478
1476
  "setStakingReward",
1479
1477
  ["0", simpleStaking.address, 10, 1000, false] // set 10 gd per block
@@ -1485,16 +1483,15 @@ describe("StakingRewards - staking with cDAI mocks and get Rewards in GoodDollar
1485
1483
  const lastActiveContractAfterRemove = await goodFundManager.activeContracts(
1486
1484
  activeContractsCountAfterRemoved.sub(1)
1487
1485
  );
1488
- expect(lastActiveContractBeforeAdd).to.be.equal(
1489
- lastActiveContractAfterRemove
1490
- );
1491
- expect(lastActiveContractAfterAdd).to.be.equal(simpleStaking.address);
1492
- expect(activeContractsCountAfterAdded).to.be.gt(activeContractsCount);
1493
- expect(activeContractsCountAfterAdded).to.be.gt(
1486
+
1487
+ expect(lastActiveContractAfterRemove).to.be.equal(simpleStaking.address);
1488
+ expect(activeContractsCountAfterAdded).to.be.eq(
1494
1489
  activeContractsCountAfterRemoved
1495
1490
  );
1496
- expect(activeContractsCount).to.be.equal(activeContractsCountAfterRemoved);
1491
+
1492
+ expect(activeContractsCount).to.be.lt(activeContractsCountAfterRemoved);
1497
1493
  });
1494
+
1498
1495
  it("it should distribute rewards correctly when there is multiple stakers", async () => {
1499
1496
  const simpleStaking1 = await goodCompoundStakingTestFactory.deploy(
1500
1497
  bat.address,