@gooddollar/goodprotocol 1.0.19-beta.2 → 1.0.19-beta.3

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 (179) hide show
  1. package/artifacts/abis/DistributionHelper.min.json +1 -0
  2. package/artifacts/abis/ERC20.min.json +1 -1
  3. package/artifacts/abis/GoodDollarMintBurnWrapper.min.json +1 -0
  4. package/artifacts/abis/GoodDollarStaking.min.json +1 -0
  5. package/artifacts/abis/GoodReserveCDai.min.json +1 -1
  6. package/artifacts/abis/IERC2917.min.json +1 -1
  7. package/artifacts/abis/IMultichainRouter.min.json +1 -0
  8. package/artifacts/abis/IRouter.min.json +1 -0
  9. package/artifacts/abis/Math64x64.min.json +1 -0
  10. package/artifacts/abis/PausableControl.min.json +1 -0
  11. package/artifacts/abis/RewardsMinter.min.json +1 -0
  12. package/artifacts/abis/StakingRewardsFixedAPY.min.json +1 -0
  13. package/artifacts/abis/TokenOperation.min.json +1 -0
  14. package/artifacts/abis/cERC20.min.json +1 -1
  15. package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
  16. package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
  17. package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
  18. package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
  19. package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
  20. package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
  21. package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
  22. package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
  23. package/artifacts/contracts/Interfaces.sol/ERC20.json +13 -0
  24. package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
  25. package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
  26. package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
  27. package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
  28. package/artifacts/contracts/Interfaces.sol/IERC2917.json +13 -0
  29. package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
  30. package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
  31. package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
  32. package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
  33. package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
  34. package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
  35. package/artifacts/contracts/Interfaces.sol/IMultichainRouter.dbg.json +4 -0
  36. package/artifacts/contracts/Interfaces.sol/IMultichainRouter.json +39 -0
  37. package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
  38. package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
  39. package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
  40. package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
  41. package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
  42. package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
  43. package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
  44. package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
  45. package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
  46. package/artifacts/contracts/Interfaces.sol/cERC20.json +13 -0
  47. package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
  48. package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.json +2 -2
  49. package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
  50. package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.json +2 -2
  51. package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
  52. package/artifacts/contracts/governance/GReputation.sol/GReputation.json +2 -2
  53. package/artifacts/contracts/governance/GoodDollarStaking.sol/GoodDollarStaking.dbg.json +4 -0
  54. package/artifacts/contracts/governance/GoodDollarStaking.sol/GoodDollarStaking.json +1028 -0
  55. package/artifacts/contracts/governance/GoodDollarStaking.sol/RewardsMinter.dbg.json +4 -0
  56. package/artifacts/contracts/governance/GoodDollarStaking.sol/RewardsMinter.json +35 -0
  57. package/artifacts/contracts/governance/GovernanceStaking.sol/GovernanceStaking.dbg.json +1 -1
  58. package/artifacts/contracts/governance/GovernanceStaking.sol/GovernanceStaking.json +2 -2
  59. package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
  60. package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
  61. package/artifacts/contracts/governance/Reputation.sol/Reputation.json +2 -2
  62. package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
  63. package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.json +2 -2
  64. package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
  65. package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
  66. package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
  67. package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
  68. package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.json +2 -2
  69. package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
  70. package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.json +2 -2
  71. package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
  72. package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
  73. package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
  74. package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.json +2 -2
  75. package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
  76. package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.json +2 -2
  77. package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
  78. package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
  79. package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.json +2 -2
  80. package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
  81. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
  82. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.json +2 -2
  83. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
  84. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.json +2 -2
  85. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.dbg.json +1 -1
  86. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.json +2 -2
  87. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.dbg.json +1 -1
  88. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.json +2 -2
  89. package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
  90. package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
  91. package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
  92. package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
  93. package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
  94. package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
  95. package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
  96. package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
  97. package/artifacts/contracts/reserve/DistributionHelper.sol/DistributionHelper.dbg.json +4 -0
  98. package/artifacts/contracts/reserve/DistributionHelper.sol/DistributionHelper.json +574 -0
  99. package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
  100. package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.json +2 -2
  101. package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
  102. package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.json +2 -2
  103. package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
  104. package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
  105. package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.json +65 -2
  106. package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
  107. package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.json +2 -2
  108. package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +1 -1
  109. package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.json +2 -2
  110. package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
  111. package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.json +2 -2
  112. package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
  113. package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.json +2 -2
  114. package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
  115. package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +1 -1
  116. package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
  117. package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.json +2 -2
  118. package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
  119. package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.json +2 -2
  120. package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
  121. package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.json +2 -2
  122. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
  123. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +2 -2
  124. package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
  125. package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.json +2 -2
  126. package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
  127. package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.json +2 -2
  128. package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +1 -1
  129. package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.json +2 -2
  130. package/artifacts/contracts/staking/utils/Math64X64.sol/Math64x64.dbg.json +4 -0
  131. package/artifacts/contracts/staking/utils/Math64X64.sol/Math64x64.json +10 -0
  132. package/artifacts/contracts/staking/utils/StakingRewardsFixedAPY.sol/StakingRewardsFixedAPY.dbg.json +4 -0
  133. package/artifacts/contracts/staking/utils/StakingRewardsFixedAPY.sol/StakingRewardsFixedAPY.json +153 -0
  134. package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
  135. package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.json +2 -2
  136. package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
  137. package/artifacts/contracts/utils/BulkProof.sol/BulkProof.dbg.json +1 -1
  138. package/artifacts/contracts/utils/BulkProof.sol/BulkProof.json +2 -2
  139. package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
  140. package/artifacts/contracts/utils/DAOContract.sol/DAOContract.json +2 -2
  141. package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
  142. package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.json +2 -2
  143. package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
  144. package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
  145. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/GoodDollarMintBurnWrapper.dbg.json +4 -0
  146. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/GoodDollarMintBurnWrapper.json +954 -0
  147. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/IRouter.dbg.json +4 -0
  148. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/IRouter.json +59 -0
  149. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/PausableControl.dbg.json +4 -0
  150. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/PausableControl.json +69 -0
  151. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/TokenOperation.dbg.json +4 -0
  152. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/TokenOperation.json +10 -0
  153. package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
  154. package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
  155. package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
  156. package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.json +2 -2
  157. package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
  158. package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.json +2 -2
  159. package/artifacts/contracts/utils/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.dbg.json +1 -1
  160. package/artifacts/contracts/utils/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.json +2 -2
  161. package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.dbg.json +1 -1
  162. package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.json +2 -2
  163. package/artifacts/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy.dbg.json +1 -1
  164. package/artifacts/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967.dbg.json +1 -1
  165. package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
  166. package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.json +2 -2
  167. package/contracts/Interfaces.sol +12 -0
  168. package/contracts/governance/GoodDollarStaking.sol +260 -0
  169. package/contracts/reserve/DistributionHelper.sol +118 -0
  170. package/contracts/reserve/GoodReserveCDai.sol +28 -1
  171. package/contracts/staking/utils/Math64X64.sol +268 -0
  172. package/contracts/staking/utils/StakingRewardsFixedAPY.sol +141 -0
  173. package/contracts/utils/GoodDollarMintBurnWrapper.sol +417 -0
  174. package/package.json +1 -1
  175. package/releases/deployment.json +4 -1
  176. package/scripts/multichain-deploy/basicdao-deploy.ts +22 -20
  177. package/scripts/multichain-deploy/helpers.ts +5 -3
  178. package/scripts/multichain-deploy/multichainWrapper-deploy.ts +67 -0
  179. package/scripts/voltageswaps.ts +47 -0
@@ -0,0 +1,417 @@
1
+ // SPDX-License-Identifier: MIT
2
+ /**
3
+ Wrap the G$ token to provide mint permissions to multichain.org router/bridge
4
+ based on https://github.com/anyswap/multichain-smart-contracts/blob/1459fe6281867319af8ffb1849e5c16d242d6530/contracts/wrapper/MintBurnWrapper.sol
5
+
6
+ Added onTokenTransfer
7
+
8
+ Fixed:
9
+ https://github.com/anyswap/multichain-smart-contracts/issues/4
10
+ https://github.com/anyswap/multichain-smart-contracts/issues/3
11
+ */
12
+
13
+ pragma solidity ^0.8;
14
+
15
+ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
16
+ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
17
+ import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol";
18
+ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
19
+ import "@openzeppelin/contracts/utils/math/Math.sol";
20
+
21
+ import "./DAOUpgradeableContract.sol";
22
+
23
+ library TokenOperation {
24
+ using Address for address;
25
+
26
+ function safeMint(
27
+ address token,
28
+ address to,
29
+ uint256 value
30
+ ) internal {
31
+ // mint(address,uint256)
32
+ _callOptionalReturn(token, abi.encodeWithSelector(0x40c10f19, to, value));
33
+ }
34
+
35
+ function safeBurnAny(
36
+ address token,
37
+ address from,
38
+ uint256 value
39
+ ) internal {
40
+ // burn(address,uint256)
41
+ _callOptionalReturn(token, abi.encodeWithSelector(0x9dc29fac, from, value));
42
+ }
43
+
44
+ function safeBurnSelf(address token, uint256 value) internal {
45
+ // burn(uint256)
46
+ _callOptionalReturn(token, abi.encodeWithSelector(0x42966c68, value));
47
+ }
48
+
49
+ function safeBurnFrom(
50
+ address token,
51
+ address from,
52
+ uint256 value
53
+ ) internal {
54
+ // burnFrom(address,uint256)
55
+ _callOptionalReturn(token, abi.encodeWithSelector(0x79cc6790, from, value));
56
+ }
57
+
58
+ function _callOptionalReturn(address token, bytes memory data) private {
59
+ bytes memory returndata = token.functionCall(
60
+ data,
61
+ "TokenOperation: low-level call failed"
62
+ );
63
+ if (returndata.length > 0) {
64
+ // Return data is optional
65
+ require(
66
+ abi.decode(returndata, (bool)),
67
+ "TokenOperation: did not succeed"
68
+ );
69
+ }
70
+ }
71
+ }
72
+
73
+ interface IRouter {
74
+ function mint(address to, uint256 amount) external returns (bool);
75
+
76
+ function burn(address from, uint256 amount) external returns (bool);
77
+ }
78
+
79
+ //License-Identifier: GPL-3.0-or-later
80
+
81
+ abstract contract PausableControl {
82
+ mapping(bytes32 => bool) private _pausedRoles;
83
+
84
+ bytes32 public constant PAUSE_ALL_ROLE = 0x00;
85
+
86
+ event Paused(bytes32 role);
87
+ event Unpaused(bytes32 role);
88
+
89
+ modifier whenNotPaused(bytes32 role) {
90
+ require(
91
+ !paused(role) && !paused(PAUSE_ALL_ROLE),
92
+ "PausableControl: paused"
93
+ );
94
+ _;
95
+ }
96
+
97
+ modifier whenPaused(bytes32 role) {
98
+ require(
99
+ paused(role) || paused(PAUSE_ALL_ROLE),
100
+ "PausableControl: not paused"
101
+ );
102
+ _;
103
+ }
104
+
105
+ function paused(bytes32 role) public view virtual returns (bool) {
106
+ return _pausedRoles[role];
107
+ }
108
+
109
+ function _pause(bytes32 role) internal virtual whenNotPaused(role) {
110
+ _pausedRoles[role] = true;
111
+ emit Paused(role);
112
+ }
113
+
114
+ function _unpause(bytes32 role) internal virtual whenPaused(role) {
115
+ _pausedRoles[role] = false;
116
+ emit Unpaused(role);
117
+ }
118
+ }
119
+
120
+ /// @dev MintBurnWrapper has the following aims:
121
+ /// 1. wrap token which does not support interface `IBridge` or `IRouter`
122
+ /// 2. wrap token which wants to support multiple minters
123
+ /// 3. add security enhancement (mint cap, pausable, etc.)
124
+ contract GoodDollarMintBurnWrapper is
125
+ IRouter,
126
+ AccessControlEnumerableUpgradeable,
127
+ PausableControl,
128
+ DAOUpgradeableContract
129
+ {
130
+ using SafeERC20 for IERC20;
131
+
132
+ // access control roles
133
+ bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
134
+ bytes32 public constant BRIDGE_ROLE = keccak256("BRIDGE_ROLE");
135
+ bytes32 public constant ROUTER_ROLE = keccak256("ROUTER_ROLE");
136
+ bytes32 public constant REWARDS_ROLE = keccak256("REWARDS_ROLE");
137
+
138
+ // pausable control roles
139
+ bytes32 public constant PAUSE_MINT_ROLE = keccak256("PAUSE_MINT_ROLE");
140
+ bytes32 public constant PAUSE_BURN_ROLE = keccak256("PAUSE_BURN_ROLE");
141
+ bytes32 public constant PAUSE_ROUTER_ROLE = keccak256("PAUSE_ROUTER_ROLE");
142
+ bytes32 public constant PAUSE_REWARDS_ROLE = keccak256("PAUSE_REWARDS_ROLE");
143
+
144
+ struct Supply {
145
+ uint256 max; // single limit of each mint
146
+ uint256 cap; // total limit of all mint
147
+ uint256 total; // total minted minus burned
148
+ uint128 dailyCap; //cap per day
149
+ uint128 mintedToday; //total minted today
150
+ uint128 lastUpdate; //last update of dailyCap
151
+ uint128 mintDebt;
152
+ uint32 bpsPerDay; //basis points relative to token supply daily limit
153
+ }
154
+
155
+ mapping(address => Supply) public minterSupply;
156
+ uint256 public totalMintCap; // total mint cap
157
+ uint256 public totalMinted; // total minted amount
158
+
159
+ enum TokenType {
160
+ MintBurnAny, // mint and burn(address from, uint256 amount), don't need approve
161
+ MintBurnFrom, // mint and burnFrom(address from, uint256 amount), need approve
162
+ MintBurnSelf, // mint and burn(uint256 amount), call transferFrom first, need approve
163
+ Transfer, // transfer and transferFrom, need approve
164
+ TransferDeposit // transfer and transferFrom, deposit and withdraw, need approve
165
+ }
166
+
167
+ address public token; // the target token this contract is wrapping
168
+ TokenType public tokenType;
169
+
170
+ uint128 currentDay; //used to reset daily minter limit
171
+ uint128 updateFrequency; //how often to update the relative to supply daily limit
172
+
173
+ event SendOrMint(address to, uint256 amount, uint256 sent, uint256 minted);
174
+
175
+ function initialize(
176
+ address _token,
177
+ TokenType _tokenType,
178
+ uint256 _totalMintCap,
179
+ address _admin,
180
+ INameService _nameService
181
+ ) external initializer {
182
+ __AccessControlEnumerable_init();
183
+ require(_token != address(0), "zero token address");
184
+ require(_admin != address(0), "zero admin address");
185
+ token = _token;
186
+ tokenType = _tokenType;
187
+ totalMintCap = _totalMintCap;
188
+ updateFrequency = 90 days;
189
+ _setupRole(DEFAULT_ADMIN_ROLE, _admin);
190
+ setDAO(_nameService);
191
+ grantRole(DEFAULT_ADMIN_ROLE, avatar);
192
+ }
193
+
194
+ function upgrade1() external {
195
+ if (updateFrequency == 0) {
196
+ updateFrequency = 90 days;
197
+ }
198
+ }
199
+
200
+ function setUpdateFrequency(uint128 inSeconds)
201
+ external
202
+ onlyRole(DEFAULT_ADMIN_ROLE)
203
+ {
204
+ updateFrequency = inSeconds;
205
+ }
206
+
207
+ function owner() external view returns (address) {
208
+ return getRoleMember(DEFAULT_ADMIN_ROLE, 0);
209
+ }
210
+
211
+ function pause(bytes32 role) external onlyRole(DEFAULT_ADMIN_ROLE) {
212
+ _pause(role);
213
+ }
214
+
215
+ function unpause(bytes32 role) external onlyRole(DEFAULT_ADMIN_ROLE) {
216
+ _unpause(role);
217
+ }
218
+
219
+ function _updateCurrentDay() internal {
220
+ currentDay = uint128(block.timestamp / 1 days);
221
+ }
222
+
223
+ function _mint(address to, uint256 amount)
224
+ internal
225
+ whenNotPaused(PAUSE_MINT_ROLE)
226
+ {
227
+ require(to != address(this), "forbid mint to address(this)");
228
+
229
+ Supply storage s = minterSupply[msg.sender];
230
+ require(s.max == 0 || amount <= s.max, "minter max exceeded");
231
+ s.total += amount;
232
+ require(s.total == 0 || s.total <= s.cap, "minter cap exceeded");
233
+
234
+ totalMinted += amount;
235
+ require(totalMinted <= totalMintCap, "total mint cap exceeded");
236
+
237
+ if (
238
+ tokenType == TokenType.Transfer || tokenType == TokenType.TransferDeposit
239
+ ) {
240
+ IERC20(token).safeTransfer(to, amount);
241
+ } else {
242
+ TokenOperation.safeMint(token, to, amount);
243
+ }
244
+ }
245
+
246
+ function _burn(address from, uint256 amount)
247
+ internal
248
+ whenNotPaused(PAUSE_BURN_ROLE)
249
+ {
250
+ //update stats correctly, but dont fail if it tries to transfer tokens minted elsewhere as long as we burn some
251
+ if (totalMinted >= amount) {
252
+ totalMinted -= amount;
253
+ } else {
254
+ totalMinted = 0;
255
+ }
256
+
257
+ if (hasRole(MINTER_ROLE, msg.sender)) {
258
+ Supply storage s = minterSupply[msg.sender];
259
+
260
+ if (s.total >= amount) {
261
+ s.total -= amount;
262
+ } else {
263
+ s.total = 0;
264
+ }
265
+ }
266
+
267
+ //handle onTokenTransfer (ERC677), assume tokens has been transfered
268
+ if (from == address(this)) {
269
+ TokenOperation.safeBurnSelf(token, amount);
270
+ } else if (
271
+ tokenType == TokenType.Transfer || tokenType == TokenType.TransferDeposit
272
+ ) {
273
+ IERC20(token).safeTransferFrom(from, address(this), amount);
274
+ } else if (tokenType == TokenType.MintBurnAny) {
275
+ TokenOperation.safeBurnAny(token, from, amount);
276
+ } else if (tokenType == TokenType.MintBurnFrom) {
277
+ TokenOperation.safeBurnFrom(token, from, amount);
278
+ } else if (tokenType == TokenType.MintBurnSelf) {
279
+ IERC20(token).safeTransferFrom(from, address(this), amount);
280
+ TokenOperation.safeBurnSelf(token, amount);
281
+ }
282
+ }
283
+
284
+ // impl IRouter `mint`
285
+ function mint(address to, uint256 amount)
286
+ external
287
+ onlyRole(MINTER_ROLE)
288
+ returns (bool)
289
+ {
290
+ _mint(to, amount);
291
+ return true;
292
+ }
293
+
294
+ // impl IRouter `burn`
295
+ function burn(address from, uint256 amount)
296
+ external
297
+ onlyRole(MINTER_ROLE)
298
+ onlyRole(ROUTER_ROLE)
299
+ whenNotPaused(PAUSE_ROUTER_ROLE)
300
+ returns (bool)
301
+ {
302
+ _burn(from, amount);
303
+ return true;
304
+ }
305
+
306
+ //impl swapout for erc677
307
+ function onTokenTransfer(
308
+ address sender,
309
+ uint256 amount,
310
+ bytes memory data
311
+ ) external returns (bool) {
312
+ require(msg.sender == token); //verify this was called from a token transfer
313
+ (address bindaddr, uint256 chainId) = abi.decode(data, (address, uint256));
314
+ require(chainId != 0, "zero chainId");
315
+ bindaddr = bindaddr != address(0) ? bindaddr : sender;
316
+
317
+ IMultichainRouter(getRoleMember(ROUTER_ROLE, 0)).anySwapOut(
318
+ address(this),
319
+ bindaddr,
320
+ amount,
321
+ chainId
322
+ );
323
+ return true;
324
+ }
325
+
326
+ function _balanceDebt(Supply storage minter) internal {
327
+ uint256 toBurn = Math.min(
328
+ minter.mintDebt,
329
+ IERC20(token).balanceOf(address(this))
330
+ );
331
+
332
+ if (toBurn > 0) {
333
+ minter.mintDebt -= uint128(toBurn);
334
+ ERC20(token).burn(toBurn); //from DAOUpgradableContract -> Interfaces
335
+ }
336
+ }
337
+
338
+ function _updateDailyLimitCap(Supply storage minter) internal {
339
+ uint256 blocksPassed = block.timestamp - minter.lastUpdate;
340
+ if (blocksPassed > updateFrequency) {
341
+ minter.dailyCap =
342
+ uint128(IERC20(token).totalSupply() * minter.bpsPerDay) /
343
+ 10000;
344
+ minter.lastUpdate = uint128(block.timestamp);
345
+ }
346
+ }
347
+
348
+ function sendOrMint(address to, uint256 amount)
349
+ external
350
+ onlyRole(REWARDS_ROLE)
351
+ whenNotPaused(PAUSE_REWARDS_ROLE)
352
+ returns (uint256 totalSent)
353
+ {
354
+ Supply storage m = minterSupply[msg.sender];
355
+ _updateDailyLimitCap(m);
356
+
357
+ //check if daily limit needs reset
358
+ uint256 today = currentDay;
359
+ _updateCurrentDay();
360
+ if (currentDay != today) {
361
+ m.mintedToday = 0;
362
+ }
363
+ uint256 maxMintToday = m.dailyCap - m.mintedToday;
364
+
365
+ //calcualte how much to send and mint
366
+ uint256 toSend = Math.min(IERC20(token).balanceOf(address(this)), amount);
367
+ uint256 toMint = Math.min(amount - toSend, maxMintToday);
368
+ totalSent = toSend + toMint;
369
+ m.mintedToday += uint128(toMint);
370
+ m.mintDebt += uint128(toMint);
371
+
372
+ if (toMint > 0) _mint(to, toMint);
373
+ else {
374
+ //if we are not minting then we probably have positive balance, check if we can cover out debt and burn some
375
+ //from balance in exchange for what we minted in the past ie mintDebt
376
+ _balanceDebt(m);
377
+ }
378
+
379
+ if (toSend > 0) IERC20(token).safeTransfer(to, toSend);
380
+
381
+ emit SendOrMint(to, amount, toSend, toMint);
382
+ }
383
+
384
+ function addMinter(
385
+ address minter,
386
+ uint256 cap,
387
+ uint256 max,
388
+ uint32 bpsPerDay,
389
+ bool withRewardsRole
390
+ ) external onlyRole(DEFAULT_ADMIN_ROLE) {
391
+ grantRole(MINTER_ROLE, minter);
392
+ Supply storage m = minterSupply[minter];
393
+ m.cap = cap;
394
+ m.max = max;
395
+ m.bpsPerDay = bpsPerDay;
396
+ m.lastUpdate = uint128(block.timestamp);
397
+ m.dailyCap = uint128(IERC20(token).totalSupply() * bpsPerDay) / 10000;
398
+ if (withRewardsRole) {
399
+ grantRole(REWARDS_ROLE, minter);
400
+ } else {
401
+ revokeRole(REWARDS_ROLE, minter);
402
+ }
403
+ }
404
+
405
+ function setTotalMintCap(uint256 cap) external onlyRole(DEFAULT_ADMIN_ROLE) {
406
+ totalMintCap = cap;
407
+ }
408
+
409
+ function setMinterTotal(
410
+ address minter,
411
+ uint256 total,
412
+ bool force
413
+ ) external onlyRole(DEFAULT_ADMIN_ROLE) {
414
+ require(force || hasRole(MINTER_ROLE, minter), "not minter");
415
+ minterSupply[minter].total = total;
416
+ }
417
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gooddollar/goodprotocol",
3
- "version": "1.0.19-beta.2",
3
+ "version": "1.0.19-beta.3",
4
4
  "description": "GoodDollar Protocol",
5
5
  "scripts": {
6
6
  "build": "scripts/build.sh deploy",
@@ -538,7 +538,10 @@
538
538
  "Identity": "0x96B81f82A29e78C5ba9E2034Ce8490fd641a24eb",
539
539
  "NameService": "0x563a80a452264a9e1aa37c6FA0B46D04C3c71b24",
540
540
  "GReputation": "0xAC132ECe25217867E318eA8ff63420C90d5a74A6",
541
+ "GuardiansSafe": "0xC9D09BA972B4EB6Bb7347F2229FB6d50434fFCa6",
541
542
  "network": "production-celo",
542
- "networkId": 42220
543
+ "networkId": 42220,
544
+ "MultichainWrapper": "0x5566b6E4962BA83e05a426Ad89031ec18e9CadD3",
545
+ "MultichainRouter": "0xf27Ee99622C3C9b264583dACB2cCE056e194494f"
543
546
  }
544
547
  }
@@ -1,24 +1,15 @@
1
+ /***
2
+ * to get same addresses as on Celo
3
+ * deploy proxyfactory with 0x271cd5391016eb621aB3f9c0c70F5cF91DFd3FB0 with nonce 2
4
+ * create a gnosissafe with 0x3de7216149f12d8f51540d9a870149560fc11bfb with nonce 3
5
+ * run this script with 0x3de7216149f12d8f51540d9a870149560fc11bfb with nonce 7
6
+ */
1
7
  import { network, ethers, upgrades, run } from "hardhat";
2
- import { networkNames } from "@openzeppelin/upgrades-core";
3
- import { isFunction, get, omitBy } from "lodash";
4
- import { getImplementationAddress } from "@openzeppelin/upgrades-core";
5
- import pressAnyKey from "press-any-key";
6
8
  import { Contract } from "ethers";
7
- import { range } from "lodash";
8
- // import DAOCreatorABI from "@gooddollar/goodcontracts/build/contracts/DaoCreatorGoodDollar.json";
9
- import DAOCreatorABI from "../../../GoodBootstrap/packages/contracts/build/contracts/DaoCreatorGoodDollarWithRep.json";
10
- // import IdentityABI from "@gooddollar/goodcontracts/build/contracts/Identity.json";
11
- import IdentityABI from "../../../GoodBootstrap/packages/contracts/build/contracts/IdentityWithOwner.json";
9
+ import DAOCreatorABI from "@gooddollar/goodcontracts/contracts/build/contracts/DaoCreatorGoodDollarWithRep.json";
10
+ import IdentityABI from "@gooddollar/goodcontracts/contracts/build/contracts/IdentityWithOwner.json";
12
11
  import FeeFormulaABI from "@gooddollar/goodcontracts/build/contracts/FeeFormula.json";
13
- // import AddFoundersABI from "@gooddollar/goodcontracts/build/contracts/AddFoundersGoodDollar.json";
14
- import AddFoundersABI from "../../../GoodBootstrap/packages/contracts/build/contracts/AddFoundersGoodDollarWithRep.json";
15
- import ContributionCalculation from "@gooddollar/goodcontracts/stakingModel/build/contracts/ContributionCalculation.json";
16
- import FirstClaimPool from "@gooddollar/goodcontracts/stakingModel/build/contracts/FirstClaimPool.json";
17
- import BridgeMock from "@gooddollar/goodcontracts/stakingModel/build/contracts/BridgeMock.json";
18
- import AdminWalletABI from "@gooddollar/goodcontracts/build/contracts/AdminWallet.json";
19
- import OTPABI from "@gooddollar/goodcontracts/build/contracts/OneTimePayments.json";
20
- import HomeBridgeABI from "@gooddollar/goodcontracts/build/contracts/DeployHomeBridge.json";
21
- import ForeignBridgeABI from "@gooddollar/goodcontracts/build/contracts/DeployForeignBridge.json";
12
+ import AddFoundersABI from "@gooddollar/goodcontracts/contracts/build/contracts/AddFoundersGoodDollarWithRep.json";
22
13
 
23
14
  import { deployDeterministic } from "./helpers";
24
15
  import releaser from "../../scripts/releaser";
@@ -61,6 +52,17 @@ export const createDAO = async () => {
61
52
  .then(_ => _.toString())
62
53
  });
63
54
 
55
+ if (network.name.includes("production")) {
56
+ const txCount = await root.getTransactionCount();
57
+ if (txCount !== 7) {
58
+ console.error(
59
+ "nonce doesnt match expected 7, to have same contract address",
60
+ { txCount }
61
+ );
62
+ return;
63
+ }
64
+ }
65
+
64
66
  const DAOCreatorFactory = new ethers.ContractFactory(
65
67
  DAOCreatorABI.abi,
66
68
  DAOCreatorABI.bytecode,
@@ -114,7 +116,7 @@ export const createDAO = async () => {
114
116
  const GReputation = (await deployDeterministic(
115
117
  {
116
118
  name: "GReputation",
117
- isUpgradable: true,
119
+ isUpgradeable: true,
118
120
  initializer: "initialize(address, string, bytes32, uint256)"
119
121
  },
120
122
  [
@@ -184,7 +186,7 @@ export const createDAO = async () => {
184
186
  .then(printDeploy);
185
187
 
186
188
  const NameService = await deployDeterministic(
187
- { name: "NameService", isUpgradable: true },
189
+ { name: "NameService", isUpgradeable: true },
188
190
  [
189
191
  controller,
190
192
  ["CONTROLLER", "AVATAR", "IDENTITY", "GOODDOLLAR"].map(_ =>
@@ -3,7 +3,7 @@ import { network, ethers, upgrades, run } from "hardhat";
3
3
 
4
4
  let totalGas = 0;
5
5
  const gasUsage = {};
6
- const GAS_SETTINGS = {};
6
+ const GAS_SETTINGS = { gasLimit: 5000000 };
7
7
  export const countTotalGas = async (tx, name) => {
8
8
  let res = tx;
9
9
  if (tx.deployTransaction) tx = tx.deployTransaction;
@@ -36,10 +36,12 @@ export const deployDeterministic = async (
36
36
  (await ethers.getContractFactory(contract.name, factoryOpts));
37
37
 
38
38
  const salt = ethers.BigNumber.from(
39
- ethers.utils.keccak256(ethers.utils.toUtf8Bytes(contract.name))
39
+ ethers.utils.keccak256(
40
+ ethers.utils.toUtf8Bytes(contract.salt || contract.name)
41
+ )
40
42
  );
41
43
 
42
- if (contract.isUpgradable === true) {
44
+ if (contract.isUpgradeable === true) {
43
45
  console.log("Deploying:", contract.name, "using proxyfactory");
44
46
  const encoded = Contract.interface.encodeFunctionData(
45
47
  contract.initializer || "initialize",
@@ -0,0 +1,67 @@
1
+ import { network, ethers, upgrades, run } from "hardhat";
2
+ import { Contract } from "ethers";
3
+
4
+ import { deployDeterministic } from "./helpers";
5
+ import releaser from "../../scripts/releaser";
6
+ import ProtocolSettings from "../../releases/deploy-settings.json";
7
+ import dao from "../../releases/deployment.json";
8
+ import { TransactionResponse } from "@ethersproject/providers";
9
+
10
+ const INITIAL_CAP = 100000000000; //1B G$s
11
+ const { name } = network;
12
+
13
+ const printDeploy = async (
14
+ c: Contract | TransactionResponse
15
+ ): Promise<Contract | TransactionResponse> => {
16
+ if (c instanceof Contract) {
17
+ await c.deployed();
18
+ console.log("deployed to: ", c.address);
19
+ }
20
+ if (c.wait) {
21
+ await c.wait();
22
+ console.log("tx done:", c.hash);
23
+ }
24
+ return c;
25
+ };
26
+
27
+ export const deployWrapper = async () => {
28
+ let release: { [key: string]: any } = dao[network.name];
29
+
30
+ let [root, ...signers] = await ethers.getSigners();
31
+ //generic call permissions
32
+ let schemeMock = root;
33
+
34
+ console.log("got signers:", {
35
+ network,
36
+ root: root.address,
37
+ schemeMock: schemeMock.address,
38
+ balance: await ethers.provider
39
+ .getBalance(root.address)
40
+ .then(_ => _.toString())
41
+ });
42
+
43
+ const Wrapper = (await deployDeterministic(
44
+ {
45
+ name: "GoodDollarMintBurnWrapper",
46
+ salt: "MintBurnWrapper",
47
+ isUpgradeable: true
48
+ },
49
+ [
50
+ release.GoodDollar,
51
+ 1,
52
+ INITIAL_CAP,
53
+ release.GuardiansSafe,
54
+ release.NameService
55
+ ]
56
+ ).then(printDeploy)) as Contract;
57
+
58
+ release = {
59
+ MultichainWrapper: Wrapper.address
60
+ };
61
+ await releaser(release, network.name, "deployment", false);
62
+ };
63
+
64
+ export const main = async (networkName = name) => {
65
+ await deployWrapper().catch(console.log);
66
+ };
67
+ main();
@@ -0,0 +1,47 @@
1
+ import { request, gql } from "graphql-request";
2
+ import fetch from "node-fetch";
3
+
4
+ let txCount = {};
5
+ const fetchSwaps = async (to, url, pair) => {
6
+ let from = to - 60 * 60 * 24;
7
+ //0xa02ed9fe9e3351fe2cd1f588b23973c1542dcbcc
8
+ //0x8d441c2ff54c015a1be22ad88e5d42efbec6c7ef
9
+ const query = gql`
10
+ {
11
+ swaps(first:1000 where:{pair: "${pair}", timestamp_gt:${from}, timestamp_lte:${to}}) {
12
+ to
13
+ }
14
+ }
15
+ `;
16
+
17
+ const { swaps } = await request(
18
+ url,
19
+ // "https://api.thegraph.com/subgraphs/name/fuseio/fuseswap",
20
+ //"https://api.thegraph.com/subgraphs/name/voltfinance/voltage-exchange",
21
+ query
22
+ );
23
+ swaps.forEach(({ to }) => (txCount[to] = (txCount[to] || 0) + 1));
24
+ console.log(swaps.length);
25
+ // if (from < 1646925850) return;
26
+ if (from < 1604823310) return;
27
+ return fetchSwaps(from, url, pair);
28
+ };
29
+ //1652752130
30
+
31
+ const main = async () => {
32
+ await Promise.all([
33
+ fetchSwaps(
34
+ 1652755140,
35
+ "https://api.thegraph.com/subgraphs/name/fuseio/fuseswap",
36
+ "0x8d441c2ff54c015a1be22ad88e5d42efbec6c7ef"
37
+ ).then(_ => console.log({ txCount, unique: Object.keys(txCount).length })),
38
+ fetchSwaps(
39
+ 1652755140,
40
+ "https://api.thegraph.com/subgraphs/name/voltfinance/voltage-exchange",
41
+ "0xa02ed9fe9e3351fe2cd1f588b23973c1542dcbcc"
42
+ ).then(_ => console.log({ txCount, unique: Object.keys(txCount).length }))
43
+ ]);
44
+
45
+ console.log("final:", { txCount, unique: Object.keys(txCount).length });
46
+ };
47
+ main();