@gooddollar/goodprotocol 2.0.7-beta.3 → 2.0.7-beta.4

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/BuyGDClone.min.json +1 -1
  2. package/artifacts/abis/BuyGDCloneFactory.min.json +1 -1
  3. package/artifacts/abis/IStaticOracle.min.json +1 -0
  4. package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
  5. package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
  6. package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
  7. package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
  8. package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
  9. package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
  10. package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
  11. package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
  12. package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
  13. package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
  14. package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
  15. package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
  16. package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
  17. package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
  18. package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
  19. package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
  20. package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
  21. package/artifacts/contracts/Interfaces.sol/IIdentityV2.dbg.json +1 -1
  22. package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
  23. package/artifacts/contracts/Interfaces.sol/IMultichainRouter.dbg.json +1 -1
  24. package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
  25. package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
  26. package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
  27. package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
  28. package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
  29. package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
  30. package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
  31. package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
  32. package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
  33. package/artifacts/contracts/fuseFaucet/Faucet.sol/Faucet.dbg.json +1 -1
  34. package/artifacts/contracts/fuseFaucet/FuseFaucet.sol/FuseFaucet.dbg.json +1 -1
  35. package/artifacts/contracts/fuseFaucet/FuseFaucetV2.sol/FuseFaucetV2.dbg.json +1 -1
  36. package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
  37. package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
  38. package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
  39. package/artifacts/contracts/governance/GoodDollarStaking.sol/GoodDollarStaking.dbg.json +1 -1
  40. package/artifacts/contracts/governance/GoodDollarStaking.sol/IGovernanceStaking.dbg.json +1 -1
  41. package/artifacts/contracts/governance/GoodDollarStaking.sol/IStakingUpgrade.dbg.json +1 -1
  42. package/artifacts/contracts/governance/GoodDollarStaking.sol/RewardsMinter.dbg.json +1 -1
  43. package/artifacts/contracts/governance/GovernanceStaking.sol/GovernanceStaking.dbg.json +1 -1
  44. package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
  45. package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
  46. package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
  47. package/artifacts/contracts/identity/IdentityV2.sol/IdentityV2.dbg.json +1 -1
  48. package/artifacts/contracts/invite/InvitesFuseV2.sol/InvitesFuseV2.dbg.json +1 -1
  49. package/artifacts/contracts/invite/InvitesV1.sol/InvitesV1.dbg.json +1 -1
  50. package/artifacts/contracts/invite/InvitesV2.sol/InvitesV2.dbg.json +1 -1
  51. package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
  52. package/artifacts/contracts/mocks/AaveUSDMockOracle.sol/AaveUSDMockOracle.dbg.json +1 -1
  53. package/artifacts/contracts/mocks/BatUSDMockOracle.sol/BatUSDMockOracle.dbg.json +1 -1
  54. package/artifacts/contracts/mocks/CompUsdMockOracle.sol/CompUSDMockOracle.dbg.json +1 -1
  55. package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
  56. package/artifacts/contracts/mocks/DaiEthPriceMockOracle.sol/DaiEthPriceMockOracle.dbg.json +1 -1
  57. package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
  58. package/artifacts/contracts/mocks/DistributionBridgeMock.sol/DistributionBridgeMock.dbg.json +1 -1
  59. package/artifacts/contracts/mocks/DistributionHelperTest.sol/DistributionHelperTest.dbg.json +1 -1
  60. package/artifacts/contracts/mocks/DistributionHelperTest.sol/DistributionHelperTestHelper.dbg.json +1 -1
  61. package/artifacts/contracts/mocks/EthUSDMockOracle.sol/EthUSDMockOracle.dbg.json +1 -1
  62. package/artifacts/contracts/mocks/FeesFormularMock.sol/FeesFormulaMock.dbg.json +1 -1
  63. package/artifacts/contracts/mocks/GasPriceMockOracle.sol/GasPriceMockOracle.dbg.json +1 -1
  64. package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
  65. package/artifacts/contracts/mocks/GoodDollarStakingMock.sol/GoodDollarStakingMock.dbg.json +1 -1
  66. package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
  67. package/artifacts/contracts/mocks/IdentityMock.sol/IdentityMock.dbg.json +1 -1
  68. package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
  69. package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
  70. package/artifacts/contracts/mocks/MultichainRouterMock.sol/IWrapper.dbg.json +1 -1
  71. package/artifacts/contracts/mocks/MultichainRouterMock.sol/MultichainRouterMock.dbg.json +1 -1
  72. package/artifacts/contracts/mocks/OverMintTester.sol/IGoodDollarStakingTest.dbg.json +1 -1
  73. package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
  74. package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
  75. package/artifacts/contracts/mocks/PayableMock.sol/PayableMock.dbg.json +1 -1
  76. package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
  77. package/artifacts/contracts/mocks/StakingMockFixedAPY.sol/StakingMockFixedAPY.dbg.json +1 -1
  78. package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
  79. package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
  80. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
  81. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
  82. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.dbg.json +1 -1
  83. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.dbg.json +1 -1
  84. package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
  85. package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
  86. package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
  87. package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
  88. package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
  89. package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
  90. package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
  91. package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
  92. package/artifacts/contracts/reserve/DistributionHelper.sol/DistributionHelper.dbg.json +1 -1
  93. package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
  94. package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
  95. package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
  96. package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
  97. package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
  98. package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +1 -1
  99. package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
  100. package/artifacts/contracts/staking/FuseStakingV3.sol/FuseStakingV3.dbg.json +1 -1
  101. package/artifacts/contracts/staking/FuseStakingV3.sol/IConsensus.dbg.json +1 -1
  102. package/artifacts/contracts/staking/FuseStakingV3.sol/PegSwap.dbg.json +1 -1
  103. package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
  104. package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
  105. package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +1 -1
  106. package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
  107. package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
  108. package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
  109. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
  110. package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
  111. package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
  112. package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +1 -1
  113. package/artifacts/contracts/staking/utils/Math64X64.sol/Math64x64.dbg.json +1 -1
  114. package/artifacts/contracts/staking/utils/StakingRewardsFixedAPY.sol/StakingRewardsFixedAPY.dbg.json +1 -1
  115. package/artifacts/contracts/token/ERC20PresetMinterPauserUpgradeable.sol/ERC20PresetMinterPauserUpgradeable.dbg.json +1 -1
  116. package/artifacts/contracts/token/ERC677.sol/ERC677.dbg.json +1 -1
  117. package/artifacts/contracts/token/ERC677.sol/ERC677Receiver.dbg.json +1 -1
  118. package/artifacts/contracts/token/FeesFormula.sol/IFeesFormula.dbg.json +1 -1
  119. package/artifacts/contracts/token/GoodDollar.sol/GoodDollar.dbg.json +1 -1
  120. package/artifacts/contracts/token/superfluid/ERC20Permit.sol/ERC20Permit.dbg.json +1 -1
  121. package/artifacts/contracts/token/superfluid/ERC20Permit.sol/SelfApprove.dbg.json +1 -1
  122. package/artifacts/contracts/token/superfluid/ISuperGoodDollar.sol/IGoodDollarCustom.dbg.json +1 -1
  123. package/artifacts/contracts/token/superfluid/ISuperGoodDollar.sol/ISuperGoodDollar.dbg.json +1 -1
  124. package/artifacts/contracts/token/superfluid/SuperGoodDollar.sol/SuperGoodDollar.dbg.json +1 -1
  125. package/artifacts/contracts/token/superfluid/SuperToken.sol/SuperToken.dbg.json +1 -1
  126. package/artifacts/contracts/token/superfluid/SuperfluidToken.sol/SuperfluidToken.dbg.json +1 -1
  127. package/artifacts/contracts/token/superfluid/UUPSProxiable.sol/UUPSProxiable.dbg.json +1 -1
  128. package/artifacts/contracts/token/superfluid/UUPSProxy.sol/Proxy.dbg.json +1 -1
  129. package/artifacts/contracts/token/superfluid/UUPSProxy.sol/UUPSProxy.dbg.json +1 -1
  130. package/artifacts/contracts/token/superfluid/UUPSProxy.sol/UUPSUtils.dbg.json +1 -1
  131. package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
  132. package/artifacts/contracts/ubi/UBISchemeV2.sol/UBISchemeV2.dbg.json +1 -1
  133. package/artifacts/contracts/utils/AdminWallet.sol/AdminWallet.dbg.json +1 -1
  134. package/artifacts/contracts/utils/AdminWalletFuse.sol/AdminWalletFuse.dbg.json +1 -1
  135. package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
  136. package/artifacts/contracts/utils/BulkProof.sol/BulkProof.dbg.json +1 -1
  137. package/artifacts/contracts/utils/BuyAndBridgeHelper.sol/BuyAndBridgeHelper.dbg.json +1 -1
  138. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDClone.dbg.json +1 -1
  139. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDClone.json +68 -24
  140. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDCloneFactory.dbg.json +1 -1
  141. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDCloneFactory.json +7 -12
  142. package/artifacts/contracts/utils/BuyGDClone.sol/IStaticOracle.dbg.json +4 -0
  143. package/artifacts/contracts/utils/BuyGDClone.sol/IStaticOracle.json +79 -0
  144. package/artifacts/contracts/utils/BuyGDClone.sol/ISwapRouter.dbg.json +1 -1
  145. package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
  146. package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
  147. package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
  148. package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
  149. package/artifacts/contracts/utils/GDFaucet.sol/GDFaucet.dbg.json +1 -1
  150. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/GoodDollarMintBurnWrapper.dbg.json +1 -1
  151. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/IRouter.dbg.json +1 -1
  152. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/PausableControl.dbg.json +1 -1
  153. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/TokenOperation.dbg.json +1 -1
  154. package/artifacts/contracts/utils/IdentityFix.sol/IdentityFix.dbg.json +1 -1
  155. package/artifacts/contracts/utils/MultiCall.sol/Multicall.dbg.json +1 -1
  156. package/artifacts/contracts/utils/MultichainBridgeHelper.sol/MultichainBridgeHelper.dbg.json +1 -1
  157. package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
  158. package/artifacts/contracts/utils/OneTimePayments.sol/OneTimePayments.dbg.json +1 -1
  159. package/artifacts/contracts/utils/OneTimePaymentsV2.sol/OneTimePaymentsV2.dbg.json +1 -1
  160. package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
  161. package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
  162. package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
  163. package/artifacts/contracts/utils/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.dbg.json +1 -1
  164. package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.dbg.json +1 -1
  165. package/artifacts/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy.dbg.json +1 -1
  166. package/artifacts/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967.dbg.json +1 -1
  167. package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
  168. package/contracts/utils/BuyGDClone.sol +162 -24
  169. package/package.json +1 -1
  170. package/scripts/upgrades/multichain-temp-fix.ts +6 -3
  171. package/truffle-config.js +4 -0
  172. package/types/BuyGDClone.ts +104 -28
  173. package/types/BuyGDCloneFactory.ts +9 -40
  174. package/types/IStaticOracle.ts +170 -0
  175. package/types/factories/BuyGDCloneFactory__factory.ts +16 -12
  176. package/types/factories/BuyGDClone__factory.ts +76 -23
  177. package/types/factories/IStaticOracle__factory.ts +91 -0
  178. package/types/hardhat.d.ts +9 -0
  179. package/types/index.ts +2 -0
@@ -5,6 +5,38 @@ import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";
5
5
  import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
6
6
  import "../Interfaces.sol";
7
7
 
8
+ //@mean-finance/uniswap-v3-oracle
9
+ interface IStaticOracle {
10
+ /// @notice Will increase observations for all existing pools for the given pair, so they start accruing information for twap calculations
11
+ /// @dev Will revert if there are no pools available for the pair and period combination
12
+ /// @param tokenA One of the pair's tokens
13
+ /// @param tokenB The other of the pair's tokens
14
+ /// @param cardinality The cardinality that will be guaranteed when quoting
15
+ /// @return preparedPools The pools that were prepared
16
+ function prepareAllAvailablePoolsWithCardinality(
17
+ address tokenA,
18
+ address tokenB,
19
+ uint16 cardinality
20
+ ) external returns (address[] memory preparedPools);
21
+
22
+ /// @notice Returns a quote, based on the given tokens and amount, by querying all of the pair's pools
23
+ /// @dev If some pools are not configured correctly for the given period, then they will be ignored
24
+ /// @dev Will revert if there are no pools available/configured for the pair and period combination
25
+ /// @param baseAmount Amount of token to be converted
26
+ /// @param baseToken Address of an ERC20 token contract used as the baseAmount denomination
27
+ /// @param quoteToken Address of an ERC20 token contract used as the quoteAmount denomination
28
+ /// @param period Number of seconds from which to calculate the TWAP
29
+ /// @return quoteAmount Amount of quoteToken received for baseAmount of baseToken
30
+ /// @return queriedPools The pools that were queried to calculate the quote
31
+ function quoteAllAvailablePoolsWithTimePeriod(
32
+ uint128 baseAmount,
33
+ address baseToken,
34
+ address quoteToken,
35
+ uint32 period
36
+ ) external view returns (uint256 quoteAmount, address[] memory queriedPools);
37
+ }
38
+
39
+ // @uniswap/v3-core
8
40
  interface ISwapRouter {
9
41
  struct ExactInputSingleParams {
10
42
  address tokenIn;
@@ -75,36 +107,75 @@ interface ISwapRouter {
75
107
  ) external payable returns (uint256 amountIn);
76
108
  }
77
109
 
110
+ /*
111
+ * @title BuyGDClone
112
+ * @notice This contract allows users to swap Celo or cUSD for GoodDollar (GD) tokens.
113
+ * @dev This contract is a clone of the BuyGD contract, which is used to buy GD tokens on the GoodDollar platform.
114
+ * @dev This contract uses the SwapRouter contract to perform the swaps.
115
+ */
78
116
  contract BuyGDClone is Initializable {
79
- error NOT_ALLOWED(address);
80
117
  error REFUND_FAILED(uint256);
118
+ error NO_BALANCE();
81
119
 
82
120
  ISwapRouter public immutable router;
83
121
  address public constant celo = 0x471EcE3750Da237f93B8E339c536989b8978a438;
122
+ uint32 public immutable twapPeriod;
84
123
  address public immutable cusd;
85
124
  address public immutable gd;
125
+ IStaticOracle public immutable oracle;
86
126
 
87
127
  address public owner;
88
- address public executer;
89
128
 
90
129
  receive() external payable {}
91
130
 
92
- constructor(ISwapRouter _router, address _cusd, address _gd) {
131
+ constructor(
132
+ ISwapRouter _router,
133
+ address _cusd,
134
+ address _gd,
135
+ IStaticOracle _oracle
136
+ ) {
93
137
  router = _router;
94
138
  cusd = _cusd;
95
139
  gd = _gd;
140
+ oracle = _oracle;
141
+ twapPeriod = 300; //5 minutes
96
142
  }
97
143
 
98
- function initialize(address _owner, address _executer) external initializer {
144
+ /**
145
+ * @notice Initializes the contract with the owner's address.
146
+ * @param _owner The address of the owner of the contract.
147
+ */
148
+ function initialize(address _owner) external initializer {
99
149
  owner = _owner;
100
- executer = _executer;
101
150
  }
102
151
 
103
- function swap(uint256 _minAmount) external {
152
+ /**
153
+ * @notice Swaps either Celo or cUSD for GD tokens.
154
+ * @dev If the contract has a balance of Celo, it will swap Celo for GD tokens.
155
+ * @dev If the contract has a balance of cUSD, it will swap cUSD for GD tokens.
156
+ * @param _minAmount The minimum amount of GD tokens to receive from the swap.
157
+ */
158
+ function swap(uint256 _minAmount) external payable {
159
+ uint256 balance = address(this).balance;
160
+ if (balance > 0) return swapCelo(_minAmount);
161
+
162
+ balance = ERC20(cusd).balanceOf(address(this));
163
+ if (balance > 0) return swapCusd(_minAmount);
164
+
165
+ revert NO_BALANCE();
166
+ }
167
+
168
+ /**
169
+ * @notice Swaps Celo for GD tokens.
170
+ * @param _minAmount The minimum amount of GD tokens to receive from the swap.
171
+ */
172
+ function swapCelo(uint256 _minAmount) public payable {
104
173
  uint256 gasCosts = msg.sender == owner ? 0 : (block.basefee + 1e9) * 400000;
105
- if (msg.sender != owner && msg.sender != executer)
106
- revert NOT_ALLOWED(msg.sender);
107
174
  uint256 balance = address(this).balance;
175
+
176
+ uint256 minByTwap = minAmountByTWAP(balance, celo);
177
+ _minAmount = _minAmount > minByTwap ? _minAmount : minByTwap;
178
+
108
179
  ERC20(celo).approve(address(router), balance);
109
180
  ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
110
181
  path: abi.encodePacked(celo, uint24(3000), cusd, uint24(10000), gd),
@@ -119,11 +190,17 @@ contract BuyGDClone is Initializable {
119
190
  }
120
191
  }
121
192
 
122
- function swapCusd(uint256 _minAmount) external {
123
- uint256 gasCosts = msg.sender == executer ? 1e17 : 0;
124
- if (msg.sender != owner && msg.sender != executer)
125
- revert NOT_ALLOWED(msg.sender);
193
+ /**
194
+ * @notice Swaps cUSD for GD tokens.
195
+ * @param _minAmount The minimum amount of GD tokens to receive from the swap.
196
+ */
197
+ function swapCusd(uint256 _minAmount) public {
198
+ uint256 gasCosts = msg.sender != owner ? 1e17 : 0; //fixed 0.1$
126
199
  uint balance = ERC20(cusd).balanceOf(address(this));
200
+
201
+ uint256 minByTwap = minAmountByTWAP(balance, cusd);
202
+ _minAmount = _minAmount > minByTwap ? _minAmount : minByTwap;
203
+
127
204
  ERC20(cusd).approve(address(router), balance);
128
205
  ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
129
206
  path: abi.encodePacked(cusd, uint24(10000), gd),
@@ -132,38 +209,99 @@ contract BuyGDClone is Initializable {
132
209
  amountOutMinimum: _minAmount
133
210
  });
134
211
  router.exactInput(params);
135
- if (msg.sender == executer) {
212
+ if (msg.sender != owner) {
136
213
  ERC20(cusd).transfer(msg.sender, gasCosts);
137
214
  }
138
215
  }
139
216
 
217
+ /**
218
+ * @notice Calculates the minimum amount of tokens that can be received for a given amount of base tokens,
219
+ * based on the time-weighted average price (TWAP) of the token pair over a specified period of time.
220
+ * @param baseAmount The amount of base tokens to swap.
221
+ * @param baseToken The address of the base token.
222
+ * @return minTwap The minimum amount of G$ expected to receive by twap
223
+ */
224
+ function minAmountByTWAP(
225
+ uint256 baseAmount,
226
+ address baseToken
227
+ ) public view returns (uint256 minTwap) {
228
+ uint128 toConvert = uint128(baseAmount);
229
+ uint256 quote;
230
+ if (baseToken == celo) {
231
+ (quote, ) = oracle.quoteAllAvailablePoolsWithTimePeriod(
232
+ toConvert,
233
+ baseToken,
234
+ cusd,
235
+ twapPeriod
236
+ );
237
+ toConvert = uint128(quote);
238
+ }
239
+ (quote, ) = oracle.quoteAllAvailablePoolsWithTimePeriod(
240
+ toConvert,
241
+ cusd,
242
+ gd,
243
+ twapPeriod
244
+ );
245
+ //minAmount should not be 5% under twap (ie we dont expect price movement > 5% in timePeriod)
246
+ return (quote * 95) / 100;
247
+ }
248
+
249
+ /**
250
+ * @notice Recovers tokens accidentally sent to the contract.
251
+ * @param token The address of the token to recover. Use address(0) to recover ETH.
252
+ */
140
253
  function recover(address token) external {
141
254
  if (token == address(0)) {
142
255
  (bool sent, ) = payable(owner).call{ value: address(this).balance }("");
143
256
  if (!sent) revert REFUND_FAILED(address(this).balance);
144
- } else ERC20(token).transfer(owner, ERC20(token).balanceOf(address(this)));
257
+ } else {
258
+ ERC20(token).transfer(owner, ERC20(token).balanceOf(address(this)));
259
+ }
145
260
  }
146
261
  }
147
262
 
263
+ /**
264
+ * @title BuyGDCloneFactory
265
+ * @notice Factory contract for creating clones of BuyGDClone contract
266
+ */
148
267
  contract BuyGDCloneFactory {
149
268
  address immutable impl;
150
269
 
151
- constructor(ISwapRouter _router, address _cusd, address _gd) {
152
- impl = address(new BuyGDClone(_router, _cusd, _gd));
270
+ /**
271
+ * @notice Initializes the BuyGDCloneFactory contract with the provided parameters.
272
+ * @param _router The address of the SwapRouter contract.
273
+ * @param _cusd The address of the cUSD token contract.
274
+ * @param _gd The address of the GD token contract.
275
+ * @param _oracle The address of the StaticOracle contract.
276
+ */
277
+ constructor(
278
+ ISwapRouter _router,
279
+ address _cusd,
280
+ address _gd,
281
+ IStaticOracle _oracle
282
+ ) {
283
+ impl = address(new BuyGDClone(_router, _cusd, _gd, _oracle));
153
284
  }
154
285
 
155
- function create(address owner, address executer) external returns (address) {
156
- bytes32 salt = keccak256(abi.encode(owner, executer));
286
+ /**
287
+ * @notice Creates a new clone of the BuyGDClone contract with the provided owner address.
288
+ * @param owner The address of the owner of the new BuyGDClone contract.
289
+ * @return The address of the new BuyGDClone contract.
290
+ */
291
+ function create(address owner) external returns (address) {
292
+ bytes32 salt = keccak256(abi.encode(owner));
157
293
  address clone = ClonesUpgradeable.cloneDeterministic(impl, salt);
158
- BuyGDClone(payable(clone)).initialize(owner, executer);
294
+ BuyGDClone(payable(clone)).initialize(owner);
159
295
  return clone;
160
296
  }
161
297
 
162
- function predict(
163
- address owner,
164
- address executer
165
- ) external view returns (address) {
166
- bytes32 salt = keccak256(abi.encode(owner, executer));
298
+ /**
299
+ * @notice Predicts the address of a new clone of the BuyGDClone contract with the provided owner address.
300
+ * @param owner The address of the owner of the new BuyGDClone contract.
301
+ * @return The predicted address of the new BuyGDClone contract.
302
+ */
303
+ function predict(address owner) external view returns (address) {
304
+ bytes32 salt = keccak256(abi.encode(owner));
167
305
 
168
306
  return
169
307
  ClonesUpgradeable.predictDeterministicAddress(impl, salt, address(this));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gooddollar/goodprotocol",
3
- "version": "2.0.7-beta.3",
3
+ "version": "2.0.7-beta.4",
4
4
  "description": "GoodDollar Protocol",
5
5
  "engines": {
6
6
  "node": "18.x"
@@ -9,7 +9,6 @@
9
9
  import { network, ethers } from "hardhat";
10
10
  import { Contract } from "ethers";
11
11
  import { defaultsDeep } from "lodash";
12
-
13
12
  import { printDeploy, executeViaGuardian, executeViaSafe, verifyProductionSigner } from "../multichain-deploy/helpers";
14
13
 
15
14
  import ProtocolSettings from "../../releases/deploy-settings.json";
@@ -54,8 +53,12 @@ export const upgrade = async () => {
54
53
 
55
54
  let f = await ethers.getContractFactory("GoodFundManager");
56
55
  console.log("bytecode", f.bytecode.length);
57
- let newDistHelper = (await ethers.deployContract("DistributionHelper").then(printDeploy)) as Contract;
58
-
56
+ // let newDistHelper = (await ethers
57
+ // .deployContract("DistributionHelper", { maxFeePerGas: 22e9, nonce: 118 })
58
+ // .then(printDeploy)) as Contract;
59
+ let newDistHelper = (await (await ethers.getContractFactory("DistributionHelper"))
60
+ .deploy({ maxFeePerGas: 15e9, maxPriorityFeePerGas: 1e9 })
61
+ .then(printDeploy)) as Contract;
59
62
  if (isProduction) await verifyContract(newDistHelper, "GoodReserveCDai", networkName);
60
63
 
61
64
  const proposalContracts = [
package/truffle-config.js CHANGED
@@ -58,6 +58,10 @@ module.exports = {
58
58
  // },
59
59
  // Useful for deploying to a public network.
60
60
  // NB: It's important to wrap the provider as a function.
61
+ "production-mainnet": {
62
+ provider: () => new Web3.providers.HttpProvider(`https://cloudflare-eth.com`),
63
+ network_id: 1
64
+ },
61
65
  kovan: {
62
66
  provider: () => new Web3.providers.HttpProvider(`https://ropsten.infura.io/v3/YOUR-PROJECT-ID`),
63
67
  network_id: 42, // Ropsten's id
@@ -12,6 +12,7 @@ import {
12
12
  BaseContract,
13
13
  ContractTransaction,
14
14
  Overrides,
15
+ PayableOverrides,
15
16
  CallOverrides,
16
17
  } from "ethers";
17
18
  import { BytesLike } from "@ethersproject/bytes";
@@ -28,43 +29,61 @@ export interface BuyGDCloneInterface extends ethers.utils.Interface {
28
29
  functions: {
29
30
  "celo()": FunctionFragment;
30
31
  "cusd()": FunctionFragment;
31
- "executer()": FunctionFragment;
32
32
  "gd()": FunctionFragment;
33
- "initialize(address,address)": FunctionFragment;
33
+ "initialize(address)": FunctionFragment;
34
+ "minAmountByTWAP(uint256,address)": FunctionFragment;
35
+ "oracle()": FunctionFragment;
34
36
  "owner()": FunctionFragment;
35
37
  "recover(address)": FunctionFragment;
36
38
  "router()": FunctionFragment;
37
39
  "swap(uint256)": FunctionFragment;
40
+ "swapCelo(uint256)": FunctionFragment;
38
41
  "swapCusd(uint256)": FunctionFragment;
42
+ "twapPeriod()": FunctionFragment;
39
43
  };
40
44
 
41
45
  encodeFunctionData(functionFragment: "celo", values?: undefined): string;
42
46
  encodeFunctionData(functionFragment: "cusd", values?: undefined): string;
43
- encodeFunctionData(functionFragment: "executer", values?: undefined): string;
44
47
  encodeFunctionData(functionFragment: "gd", values?: undefined): string;
48
+ encodeFunctionData(functionFragment: "initialize", values: [string]): string;
45
49
  encodeFunctionData(
46
- functionFragment: "initialize",
47
- values: [string, string]
50
+ functionFragment: "minAmountByTWAP",
51
+ values: [BigNumberish, string]
48
52
  ): string;
53
+ encodeFunctionData(functionFragment: "oracle", values?: undefined): string;
49
54
  encodeFunctionData(functionFragment: "owner", values?: undefined): string;
50
55
  encodeFunctionData(functionFragment: "recover", values: [string]): string;
51
56
  encodeFunctionData(functionFragment: "router", values?: undefined): string;
52
57
  encodeFunctionData(functionFragment: "swap", values: [BigNumberish]): string;
58
+ encodeFunctionData(
59
+ functionFragment: "swapCelo",
60
+ values: [BigNumberish]
61
+ ): string;
53
62
  encodeFunctionData(
54
63
  functionFragment: "swapCusd",
55
64
  values: [BigNumberish]
56
65
  ): string;
66
+ encodeFunctionData(
67
+ functionFragment: "twapPeriod",
68
+ values?: undefined
69
+ ): string;
57
70
 
58
71
  decodeFunctionResult(functionFragment: "celo", data: BytesLike): Result;
59
72
  decodeFunctionResult(functionFragment: "cusd", data: BytesLike): Result;
60
- decodeFunctionResult(functionFragment: "executer", data: BytesLike): Result;
61
73
  decodeFunctionResult(functionFragment: "gd", data: BytesLike): Result;
62
74
  decodeFunctionResult(functionFragment: "initialize", data: BytesLike): Result;
75
+ decodeFunctionResult(
76
+ functionFragment: "minAmountByTWAP",
77
+ data: BytesLike
78
+ ): Result;
79
+ decodeFunctionResult(functionFragment: "oracle", data: BytesLike): Result;
63
80
  decodeFunctionResult(functionFragment: "owner", data: BytesLike): Result;
64
81
  decodeFunctionResult(functionFragment: "recover", data: BytesLike): Result;
65
82
  decodeFunctionResult(functionFragment: "router", data: BytesLike): Result;
66
83
  decodeFunctionResult(functionFragment: "swap", data: BytesLike): Result;
84
+ decodeFunctionResult(functionFragment: "swapCelo", data: BytesLike): Result;
67
85
  decodeFunctionResult(functionFragment: "swapCusd", data: BytesLike): Result;
86
+ decodeFunctionResult(functionFragment: "twapPeriod", data: BytesLike): Result;
68
87
 
69
88
  events: {
70
89
  "Initialized(uint8)": EventFragment;
@@ -108,16 +127,21 @@ export interface BuyGDClone extends BaseContract {
108
127
 
109
128
  cusd(overrides?: CallOverrides): Promise<[string]>;
110
129
 
111
- executer(overrides?: CallOverrides): Promise<[string]>;
112
-
113
130
  gd(overrides?: CallOverrides): Promise<[string]>;
114
131
 
115
132
  initialize(
116
133
  _owner: string,
117
- _executer: string,
118
134
  overrides?: Overrides & { from?: string | Promise<string> }
119
135
  ): Promise<ContractTransaction>;
120
136
 
137
+ minAmountByTWAP(
138
+ baseAmount: BigNumberish,
139
+ baseToken: string,
140
+ overrides?: CallOverrides
141
+ ): Promise<[BigNumber] & { minTwap: BigNumber }>;
142
+
143
+ oracle(overrides?: CallOverrides): Promise<[string]>;
144
+
121
145
  owner(overrides?: CallOverrides): Promise<[string]>;
122
146
 
123
147
  recover(
@@ -129,29 +153,41 @@ export interface BuyGDClone extends BaseContract {
129
153
 
130
154
  swap(
131
155
  _minAmount: BigNumberish,
132
- overrides?: Overrides & { from?: string | Promise<string> }
156
+ overrides?: PayableOverrides & { from?: string | Promise<string> }
157
+ ): Promise<ContractTransaction>;
158
+
159
+ swapCelo(
160
+ _minAmount: BigNumberish,
161
+ overrides?: PayableOverrides & { from?: string | Promise<string> }
133
162
  ): Promise<ContractTransaction>;
134
163
 
135
164
  swapCusd(
136
165
  _minAmount: BigNumberish,
137
166
  overrides?: Overrides & { from?: string | Promise<string> }
138
167
  ): Promise<ContractTransaction>;
168
+
169
+ twapPeriod(overrides?: CallOverrides): Promise<[number]>;
139
170
  };
140
171
 
141
172
  celo(overrides?: CallOverrides): Promise<string>;
142
173
 
143
174
  cusd(overrides?: CallOverrides): Promise<string>;
144
175
 
145
- executer(overrides?: CallOverrides): Promise<string>;
146
-
147
176
  gd(overrides?: CallOverrides): Promise<string>;
148
177
 
149
178
  initialize(
150
179
  _owner: string,
151
- _executer: string,
152
180
  overrides?: Overrides & { from?: string | Promise<string> }
153
181
  ): Promise<ContractTransaction>;
154
182
 
183
+ minAmountByTWAP(
184
+ baseAmount: BigNumberish,
185
+ baseToken: string,
186
+ overrides?: CallOverrides
187
+ ): Promise<BigNumber>;
188
+
189
+ oracle(overrides?: CallOverrides): Promise<string>;
190
+
155
191
  owner(overrides?: CallOverrides): Promise<string>;
156
192
 
157
193
  recover(
@@ -163,7 +199,12 @@ export interface BuyGDClone extends BaseContract {
163
199
 
164
200
  swap(
165
201
  _minAmount: BigNumberish,
166
- overrides?: Overrides & { from?: string | Promise<string> }
202
+ overrides?: PayableOverrides & { from?: string | Promise<string> }
203
+ ): Promise<ContractTransaction>;
204
+
205
+ swapCelo(
206
+ _minAmount: BigNumberish,
207
+ overrides?: PayableOverrides & { from?: string | Promise<string> }
167
208
  ): Promise<ContractTransaction>;
168
209
 
169
210
  swapCusd(
@@ -171,20 +212,24 @@ export interface BuyGDClone extends BaseContract {
171
212
  overrides?: Overrides & { from?: string | Promise<string> }
172
213
  ): Promise<ContractTransaction>;
173
214
 
215
+ twapPeriod(overrides?: CallOverrides): Promise<number>;
216
+
174
217
  callStatic: {
175
218
  celo(overrides?: CallOverrides): Promise<string>;
176
219
 
177
220
  cusd(overrides?: CallOverrides): Promise<string>;
178
221
 
179
- executer(overrides?: CallOverrides): Promise<string>;
180
-
181
222
  gd(overrides?: CallOverrides): Promise<string>;
182
223
 
183
- initialize(
184
- _owner: string,
185
- _executer: string,
224
+ initialize(_owner: string, overrides?: CallOverrides): Promise<void>;
225
+
226
+ minAmountByTWAP(
227
+ baseAmount: BigNumberish,
228
+ baseToken: string,
186
229
  overrides?: CallOverrides
187
- ): Promise<void>;
230
+ ): Promise<BigNumber>;
231
+
232
+ oracle(overrides?: CallOverrides): Promise<string>;
188
233
 
189
234
  owner(overrides?: CallOverrides): Promise<string>;
190
235
 
@@ -194,10 +239,17 @@ export interface BuyGDClone extends BaseContract {
194
239
 
195
240
  swap(_minAmount: BigNumberish, overrides?: CallOverrides): Promise<void>;
196
241
 
242
+ swapCelo(
243
+ _minAmount: BigNumberish,
244
+ overrides?: CallOverrides
245
+ ): Promise<void>;
246
+
197
247
  swapCusd(
198
248
  _minAmount: BigNumberish,
199
249
  overrides?: CallOverrides
200
250
  ): Promise<void>;
251
+
252
+ twapPeriod(overrides?: CallOverrides): Promise<number>;
201
253
  };
202
254
 
203
255
  filters: {
@@ -210,16 +262,21 @@ export interface BuyGDClone extends BaseContract {
210
262
 
211
263
  cusd(overrides?: CallOverrides): Promise<BigNumber>;
212
264
 
213
- executer(overrides?: CallOverrides): Promise<BigNumber>;
214
-
215
265
  gd(overrides?: CallOverrides): Promise<BigNumber>;
216
266
 
217
267
  initialize(
218
268
  _owner: string,
219
- _executer: string,
220
269
  overrides?: Overrides & { from?: string | Promise<string> }
221
270
  ): Promise<BigNumber>;
222
271
 
272
+ minAmountByTWAP(
273
+ baseAmount: BigNumberish,
274
+ baseToken: string,
275
+ overrides?: CallOverrides
276
+ ): Promise<BigNumber>;
277
+
278
+ oracle(overrides?: CallOverrides): Promise<BigNumber>;
279
+
223
280
  owner(overrides?: CallOverrides): Promise<BigNumber>;
224
281
 
225
282
  recover(
@@ -231,13 +288,20 @@ export interface BuyGDClone extends BaseContract {
231
288
 
232
289
  swap(
233
290
  _minAmount: BigNumberish,
234
- overrides?: Overrides & { from?: string | Promise<string> }
291
+ overrides?: PayableOverrides & { from?: string | Promise<string> }
292
+ ): Promise<BigNumber>;
293
+
294
+ swapCelo(
295
+ _minAmount: BigNumberish,
296
+ overrides?: PayableOverrides & { from?: string | Promise<string> }
235
297
  ): Promise<BigNumber>;
236
298
 
237
299
  swapCusd(
238
300
  _minAmount: BigNumberish,
239
301
  overrides?: Overrides & { from?: string | Promise<string> }
240
302
  ): Promise<BigNumber>;
303
+
304
+ twapPeriod(overrides?: CallOverrides): Promise<BigNumber>;
241
305
  };
242
306
 
243
307
  populateTransaction: {
@@ -245,16 +309,21 @@ export interface BuyGDClone extends BaseContract {
245
309
 
246
310
  cusd(overrides?: CallOverrides): Promise<PopulatedTransaction>;
247
311
 
248
- executer(overrides?: CallOverrides): Promise<PopulatedTransaction>;
249
-
250
312
  gd(overrides?: CallOverrides): Promise<PopulatedTransaction>;
251
313
 
252
314
  initialize(
253
315
  _owner: string,
254
- _executer: string,
255
316
  overrides?: Overrides & { from?: string | Promise<string> }
256
317
  ): Promise<PopulatedTransaction>;
257
318
 
319
+ minAmountByTWAP(
320
+ baseAmount: BigNumberish,
321
+ baseToken: string,
322
+ overrides?: CallOverrides
323
+ ): Promise<PopulatedTransaction>;
324
+
325
+ oracle(overrides?: CallOverrides): Promise<PopulatedTransaction>;
326
+
258
327
  owner(overrides?: CallOverrides): Promise<PopulatedTransaction>;
259
328
 
260
329
  recover(
@@ -266,12 +335,19 @@ export interface BuyGDClone extends BaseContract {
266
335
 
267
336
  swap(
268
337
  _minAmount: BigNumberish,
269
- overrides?: Overrides & { from?: string | Promise<string> }
338
+ overrides?: PayableOverrides & { from?: string | Promise<string> }
339
+ ): Promise<PopulatedTransaction>;
340
+
341
+ swapCelo(
342
+ _minAmount: BigNumberish,
343
+ overrides?: PayableOverrides & { from?: string | Promise<string> }
270
344
  ): Promise<PopulatedTransaction>;
271
345
 
272
346
  swapCusd(
273
347
  _minAmount: BigNumberish,
274
348
  overrides?: Overrides & { from?: string | Promise<string> }
275
349
  ): Promise<PopulatedTransaction>;
350
+
351
+ twapPeriod(overrides?: CallOverrides): Promise<PopulatedTransaction>;
276
352
  };
277
353
  }