@gooddollar/goodprotocol 2.0.23 → 2.0.24

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/DonateGDClone.min.json +1 -1
  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/GoodDollar.sol/GoodDollar.dbg.json +1 -1
  119. package/artifacts/contracts/token/IFeesFormula.sol/IFeesFormula.dbg.json +1 -1
  120. package/artifacts/contracts/token/MultichainFeeFormula.sol/MultichainFeeFormula.dbg.json +1 -1
  121. package/artifacts/contracts/token/superfluid/ERC20Permit.sol/ERC20Permit.dbg.json +1 -1
  122. package/artifacts/contracts/token/superfluid/ERC20Permit.sol/SelfApprove.dbg.json +1 -1
  123. package/artifacts/contracts/token/superfluid/ISuperGoodDollar.sol/IGoodDollarCustom.dbg.json +1 -1
  124. package/artifacts/contracts/token/superfluid/ISuperGoodDollar.sol/ISuperGoodDollar.dbg.json +1 -1
  125. package/artifacts/contracts/token/superfluid/ISuperToken.sol/ISuperToken.dbg.json +1 -1
  126. package/artifacts/contracts/token/superfluid/SuperGoodDollar.sol/SuperGoodDollar.dbg.json +1 -1
  127. package/artifacts/contracts/token/superfluid/SuperToken.sol/SuperToken.dbg.json +1 -1
  128. package/artifacts/contracts/token/superfluid/SuperfluidToken.sol/SuperfluidToken.dbg.json +1 -1
  129. package/artifacts/contracts/token/superfluid/UUPSProxiable.sol/UUPSProxiable.dbg.json +1 -1
  130. package/artifacts/contracts/token/superfluid/UUPSProxy.sol/Proxy.dbg.json +1 -1
  131. package/artifacts/contracts/token/superfluid/UUPSProxy.sol/UUPSProxy.dbg.json +1 -1
  132. package/artifacts/contracts/token/superfluid/UUPSProxy.sol/UUPSUtils.dbg.json +1 -1
  133. package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
  134. package/artifacts/contracts/ubi/UBISchemeV2.sol/UBISchemeV2.dbg.json +1 -1
  135. package/artifacts/contracts/utils/AdminWallet.sol/AdminWallet.dbg.json +1 -1
  136. package/artifacts/contracts/utils/AdminWalletFuse.sol/AdminWalletFuse.dbg.json +1 -1
  137. package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
  138. package/artifacts/contracts/utils/BulkProof.sol/BulkProof.dbg.json +1 -1
  139. package/artifacts/contracts/utils/BuyAndBridgeHelper.sol/BuyAndBridgeHelper.dbg.json +1 -1
  140. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDClone.dbg.json +1 -1
  141. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDClone.json +48 -5
  142. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDCloneFactory.dbg.json +1 -1
  143. package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDCloneFactory.json +41 -2
  144. package/artifacts/contracts/utils/BuyGDClone.sol/DonateGDClone.dbg.json +1 -1
  145. package/artifacts/contracts/utils/BuyGDClone.sol/DonateGDClone.json +79 -5
  146. package/artifacts/contracts/utils/BuyGDClone.sol/IQuoterV2.dbg.json +1 -1
  147. package/artifacts/contracts/utils/BuyGDClone.sol/ISwapRouter.dbg.json +1 -1
  148. package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
  149. package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
  150. package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
  151. package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
  152. package/artifacts/contracts/utils/GDFaucet.sol/GDFaucet.dbg.json +1 -1
  153. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/GoodDollarMintBurnWrapper.dbg.json +1 -1
  154. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/IRouter.dbg.json +1 -1
  155. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/PausableControl.dbg.json +1 -1
  156. package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/TokenOperation.dbg.json +1 -1
  157. package/artifacts/contracts/utils/IdentityFix.sol/IdentityFix.dbg.json +1 -1
  158. package/artifacts/contracts/utils/MultiCall.sol/Multicall.dbg.json +1 -1
  159. package/artifacts/contracts/utils/MultichainBridgeHelper.sol/MultichainBridgeHelper.dbg.json +1 -1
  160. package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
  161. package/artifacts/contracts/utils/OneTimePayments.sol/OneTimePayments.dbg.json +1 -1
  162. package/artifacts/contracts/utils/OneTimePaymentsV2.sol/OneTimePaymentsV2.dbg.json +1 -1
  163. package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
  164. package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
  165. package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
  166. package/artifacts/contracts/utils/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.dbg.json +1 -1
  167. package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.dbg.json +1 -1
  168. package/artifacts/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy.dbg.json +1 -1
  169. package/artifacts/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967.dbg.json +1 -1
  170. package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
  171. package/contracts/utils/BuyGDClone.sol +82 -14
  172. package/package.json +1 -1
  173. package/releases/deployment.json +3 -3
  174. package/types/contracts/utils/BuyGDClone.sol/BuyGDClone.ts +28 -3
  175. package/types/contracts/utils/BuyGDClone.sol/BuyGDCloneFactory.ts +52 -2
  176. package/types/contracts/utils/BuyGDClone.sol/DonateGDClone.ts +56 -3
  177. package/types/factories/contracts/utils/BuyGDClone.sol/BuyGDCloneFactory__factory.ts +40 -1
  178. package/types/factories/contracts/utils/BuyGDClone.sol/BuyGDClone__factory.ts +47 -4
  179. package/types/factories/contracts/utils/BuyGDClone.sol/DonateGDClone__factory.ts +78 -4
@@ -138,6 +138,8 @@ contract BuyGDClone is Initializable {
138
138
  error REFUND_FAILED(uint256);
139
139
  error NO_BALANCE();
140
140
 
141
+ event Bought(address inToken, uint256 inAmount, uint256 outAmount);
142
+
141
143
  ISwapRouter public immutable router;
142
144
  address public constant celo = 0x471EcE3750Da237f93B8E339c536989b8978a438;
143
145
  uint32 public immutable twapPeriod;
@@ -176,12 +178,23 @@ contract BuyGDClone is Initializable {
176
178
  * @dev If the contract has a balance of cUSD, it will swap cUSD for GD tokens.
177
179
  * @param _minAmount The minimum amount of GD tokens to receive from the swap.
178
180
  */
179
- function swap(uint256 _minAmount, address payable refundGas) public payable {
181
+ function swap(
182
+ uint256 _minAmount,
183
+ address payable refundGas
184
+ ) public payable returns (uint256 bought) {
180
185
  uint256 balance = address(this).balance;
181
- if (balance > 0) return swapCelo(_minAmount, refundGas);
182
186
 
187
+ if (balance > 0) {
188
+ bought = swapCelo(_minAmount, refundGas);
189
+ emit Bought(celo, balance, bought);
190
+ return bought;
191
+ }
183
192
  balance = ERC20(cusd).balanceOf(address(this));
184
- if (balance > 0) return swapCusd(_minAmount, refundGas);
193
+ if (balance > 0) {
194
+ bought = swapCusd(_minAmount, refundGas);
195
+ emit Bought(celo, balance, bought);
196
+ return bought;
197
+ }
185
198
 
186
199
  revert NO_BALANCE();
187
200
  }
@@ -193,7 +206,7 @@ contract BuyGDClone is Initializable {
193
206
  function swapCelo(
194
207
  uint256 _minAmount,
195
208
  address payable refundGas
196
- ) public payable {
209
+ ) public payable returns (uint256 bought) {
197
210
  uint256 gasCosts;
198
211
  if (refundGas != owner) {
199
212
  (gasCosts, ) = oracle.quoteAllAvailablePoolsWithTimePeriod(
@@ -216,7 +229,7 @@ contract BuyGDClone is Initializable {
216
229
  amountIn: amountIn,
217
230
  amountOutMinimum: _minAmount
218
231
  });
219
- router.exactInput(params);
232
+ bought = router.exactInput(params);
220
233
  if (refundGas != owner) {
221
234
  (bool sent, ) = refundGas.call{ value: gasCosts }("");
222
235
  if (!sent) revert REFUND_FAILED(gasCosts);
@@ -227,7 +240,10 @@ contract BuyGDClone is Initializable {
227
240
  * @notice Swaps cUSD for GD tokens.
228
241
  * @param _minAmount The minimum amount of GD tokens to receive from the swap.
229
242
  */
230
- function swapCusd(uint256 _minAmount, address refundGas) public {
243
+ function swapCusd(
244
+ uint256 _minAmount,
245
+ address refundGas
246
+ ) public returns (uint256 bought) {
231
247
  uint256 gasCosts = refundGas != owner ? 1e17 : 0; //fixed 0.1$
232
248
  uint256 amountIn = ERC20(cusd).balanceOf(address(this)) - gasCosts;
233
249
 
@@ -241,7 +257,7 @@ contract BuyGDClone is Initializable {
241
257
  amountIn: amountIn,
242
258
  amountOutMinimum: _minAmount
243
259
  });
244
- router.exactInput(params);
260
+ bought = router.exactInput(params);
245
261
  if (refundGas != owner) {
246
262
  ERC20(cusd).transfer(refundGas, gasCosts);
247
263
  }
@@ -300,6 +316,13 @@ contract BuyGDClone is Initializable {
300
316
  contract DonateGDClone is BuyGDClone {
301
317
  error EXEC_FAILED(bytes error);
302
318
 
319
+ event Donated(
320
+ address donor,
321
+ address recipient,
322
+ address tokenDonated,
323
+ uint256 amountDonated
324
+ );
325
+
303
326
  address public recoverTo;
304
327
  bytes public callData;
305
328
 
@@ -336,8 +359,11 @@ contract DonateGDClone is BuyGDClone {
336
359
  owner = address(this);
337
360
  }
338
361
  //no perform swap
362
+ address token;
363
+ uint256 donated;
339
364
  if (withSwap) {
340
- swap(_minAmount, refundGas);
365
+ token = gd;
366
+ donated = swap(_minAmount, refundGas);
341
367
  owner = tempOwner;
342
368
  }
343
369
 
@@ -348,13 +374,26 @@ contract DonateGDClone is BuyGDClone {
348
374
  uint256 gdBalance = ERC20(gd).balanceOf(address(this));
349
375
  uint256 celoBalance = address(this).balance;
350
376
 
351
- if (cusdBalance > 0) ERC20(cusd).approve(address(owner), cusdBalance);
352
- if (gdBalance > 0) ERC20(gd).approve(address(owner), gdBalance);
353
- if (celoBalance > 0) ERC20(celo).approve(address(owner), celoBalance);
377
+ if (cusdBalance > 0) {
378
+ ERC20(cusd).approve(address(owner), cusdBalance);
379
+ token = cusd;
380
+ donated = cusdBalance;
381
+ }
382
+ if (gdBalance > 0) {
383
+ ERC20(gd).approve(address(owner), gdBalance);
384
+ token = gd;
385
+ donated = gdBalance;
386
+ }
387
+ if (celoBalance > 0) {
388
+ ERC20(celo).approve(address(owner), celoBalance);
389
+ token = celo;
390
+ donated = celoBalance;
391
+ }
354
392
 
355
393
  (bool success, bytes memory data) = owner.call{ value: 0 }(callData);
356
394
  if (!success) revert EXEC_FAILED(data);
357
395
  }
396
+ emit Donated(recoverTo, owner, token, donated);
358
397
  }
359
398
 
360
399
  /**
@@ -381,6 +420,7 @@ contract BuyGDCloneFactory {
381
420
  error NOT_GD_TOKEN();
382
421
  error INVALID_TWAP();
383
422
  error RECIPIENT_ZERO();
423
+ error ZERO_MINAMOUNT();
384
424
 
385
425
  IQuoterV2 public constant quoter =
386
426
  IQuoterV2(0x82825d0554fA07f7FC52Ab63c961F330fdEFa8E8); // celo quoter
@@ -546,7 +586,8 @@ contract BuyGDCloneFactory {
546
586
  ERC20(gd).transferFrom(msg.sender, address(this), amountIn);
547
587
  }
548
588
 
549
- if (_minAmount == 0) (_minAmount, ) = minAmountByTWAP(amountIn, gd, 60);
589
+ if (_minAmount == 0)
590
+ (_minAmount, ) = minAmountByTWAP(amountIn, gd, cusd, 60);
550
591
 
551
592
  ERC20(gd).approve(address(router), amountIn);
552
593
  ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
@@ -558,16 +599,43 @@ contract BuyGDCloneFactory {
558
599
  return router.exactInput(params);
559
600
  }
560
601
 
602
+ /**
603
+ * @notice Swaps cUSD for GD tokens.
604
+ * @param _minAmount The minimum amount of GD tokens to receive from the swap.
605
+ */
606
+ function swapFromCusd(
607
+ uint256 amountIn,
608
+ uint256 _minAmount,
609
+ address recipient
610
+ ) public returns (uint256) {
611
+ ERC20(cusd).transferFrom(msg.sender, address(this), amountIn);
612
+
613
+ if (_minAmount == 0)
614
+ (_minAmount, ) = minAmountByTWAP(amountIn, cusd, gd, 60);
615
+
616
+ ERC20(cusd).approve(address(router), amountIn);
617
+ ISwapRouter.ExactInputParams memory params = ISwapRouter.ExactInputParams({
618
+ path: abi.encodePacked(cusd, uint24(10000), gd),
619
+ recipient: recipient,
620
+ amountIn: amountIn,
621
+ amountOutMinimum: _minAmount
622
+ });
623
+ return router.exactInput(params);
624
+ }
625
+
561
626
  /**
562
627
  * @notice Calculates the minimum amount of tokens that can be received for a given amount of base tokens,
563
628
  * based on the time-weighted average price (TWAP) of the token pair over a specified period of time.
564
629
  * @param baseAmount The amount of base tokens to swap.
565
630
  * @param baseToken The address of the base token.
631
+ * @param qtToken The address of the quote token.
632
+
566
633
  * @return minTwap The minimum amount of G$ expected to receive by twap
567
634
  */
568
635
  function minAmountByTWAP(
569
636
  uint256 baseAmount,
570
637
  address baseToken,
638
+ address qtToken,
571
639
  uint32 period
572
640
  ) public view returns (uint256 minTwap, uint256 quote) {
573
641
  uint24[] memory fees = new uint24[](1);
@@ -576,7 +644,7 @@ contract BuyGDCloneFactory {
576
644
  (quote, ) = oracle.quoteSpecificFeeTiersWithTimePeriod(
577
645
  toConvert,
578
646
  baseToken,
579
- cusd,
647
+ qtToken,
580
648
  fees,
581
649
  period
582
650
  );
@@ -584,7 +652,7 @@ contract BuyGDCloneFactory {
584
652
  (uint256 curPrice, ) = oracle.quoteSpecificFeeTiersWithTimePeriod(
585
653
  toConvert,
586
654
  baseToken,
587
- cusd,
655
+ qtToken,
588
656
  fees,
589
657
  0
590
658
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gooddollar/goodprotocol",
3
- "version": "2.0.23",
3
+ "version": "2.0.24",
4
4
  "description": "GoodDollar Protocol",
5
5
  "engines": {
6
6
  "node": ">=16.x"
@@ -487,7 +487,7 @@
487
487
  "MpbBridge": "0xa3247276DbCC76Dd7705273f766eB3E8a5ecF4a5",
488
488
  "StaticOracle": "0x00851A91a3c4E9a4c1B48df827Bacc1f884bdE28",
489
489
  "BuyGDFactory": "0x00e533B7d6255D05b7f15034B1c989c21F51b91C",
490
- "BuyGDFactoryV2": "0xBB2Ef9b160741AAC9e7e654E2fAAf8CE0EDe95fe"
490
+ "BuyGDFactoryV2": "0x1F60C4C7037C6766924A43666B781ED1479587a2"
491
491
  },
492
492
  "gnosis": {
493
493
  "GuardiansSafe": "0x84c10b45fe51bfb4f86c19a47fdbc187d4572fb8"
@@ -517,7 +517,7 @@
517
517
  "OneTimePaymentsV2": "0x2cb1c7d50371e277d7a36B171c0ACe9B157518EE",
518
518
  "UniswapV3Router": "0x5615CDAb10dc425a742d643d949a7F474C01abc4",
519
519
  "BuyGDFactory": "0x00e533B7d6255D05b7f15034B1c989c21F51b91C",
520
- "BuyGDFactoryV2": "0xBB2Ef9b160741AAC9e7e654E2fAAf8CE0EDe95fe"
520
+ "BuyGDFactoryV2": "0x1F60C4C7037C6766924A43666B781ED1479587a2"
521
521
  },
522
522
  "staging-celo": {
523
523
  "network": "staging-celo",
@@ -544,7 +544,7 @@
544
544
  "OneTimePaymentsV2": "0x963E7B4c970626Bb103c61fA16b002AFf6E6c2C7",
545
545
  "UniswapV3Router": "0x5615CDAb10dc425a742d643d949a7F474C01abc4",
546
546
  "BuyGDFactory": "0x00e533B7d6255D05b7f15034B1c989c21F51b91C",
547
- "BuyGDFactoryV2": "0xBB2Ef9b160741AAC9e7e654E2fAAf8CE0EDe95fe"
547
+ "BuyGDFactoryV2": "0x1F60C4C7037C6766924A43666B781ED1479587a2"
548
548
  },
549
549
  "development-goerli": {
550
550
  "ProxyFactory": "0x65D8eACBCd9618b8780C4b444081915a5D54D611",
@@ -108,12 +108,26 @@ export interface BuyGDCloneInterface extends utils.Interface {
108
108
  decodeFunctionResult(functionFragment: "twapPeriod", data: BytesLike): Result;
109
109
 
110
110
  events: {
111
+ "Bought(address,uint256,uint256)": EventFragment;
111
112
  "Initialized(uint8)": EventFragment;
112
113
  };
113
114
 
115
+ getEvent(nameOrSignatureOrTopic: "Bought"): EventFragment;
114
116
  getEvent(nameOrSignatureOrTopic: "Initialized"): EventFragment;
115
117
  }
116
118
 
119
+ export interface BoughtEventObject {
120
+ inToken: string;
121
+ inAmount: BigNumber;
122
+ outAmount: BigNumber;
123
+ }
124
+ export type BoughtEvent = TypedEvent<
125
+ [string, BigNumber, BigNumber],
126
+ BoughtEventObject
127
+ >;
128
+
129
+ export type BoughtEventFilter = TypedEventFilter<BoughtEvent>;
130
+
117
131
  export interface InitializedEventObject {
118
132
  version: number;
119
133
  }
@@ -279,24 +293,35 @@ export interface BuyGDClone extends BaseContract {
279
293
  _minAmount: BigNumberish,
280
294
  refundGas: string,
281
295
  overrides?: CallOverrides
282
- ): Promise<void>;
296
+ ): Promise<BigNumber>;
283
297
 
284
298
  swapCelo(
285
299
  _minAmount: BigNumberish,
286
300
  refundGas: string,
287
301
  overrides?: CallOverrides
288
- ): Promise<void>;
302
+ ): Promise<BigNumber>;
289
303
 
290
304
  swapCusd(
291
305
  _minAmount: BigNumberish,
292
306
  refundGas: string,
293
307
  overrides?: CallOverrides
294
- ): Promise<void>;
308
+ ): Promise<BigNumber>;
295
309
 
296
310
  twapPeriod(overrides?: CallOverrides): Promise<number>;
297
311
  };
298
312
 
299
313
  filters: {
314
+ "Bought(address,uint256,uint256)"(
315
+ inToken?: null,
316
+ inAmount?: null,
317
+ outAmount?: null
318
+ ): BoughtEventFilter;
319
+ Bought(
320
+ inToken?: null,
321
+ inAmount?: null,
322
+ outAmount?: null
323
+ ): BoughtEventFilter;
324
+
300
325
  "Initialized(uint8)"(version?: null): InitializedEventFilter;
301
326
  Initialized(version?: null): InitializedEventFilter;
302
327
  };
@@ -37,7 +37,7 @@ export interface BuyGDCloneFactoryInterface extends utils.Interface {
37
37
  "gd()": FunctionFragment;
38
38
  "getBaseFee()": FunctionFragment;
39
39
  "impl()": FunctionFragment;
40
- "minAmountByTWAP(uint256,address,uint32)": FunctionFragment;
40
+ "minAmountByTWAP(uint256,address,address,uint32)": FunctionFragment;
41
41
  "onTokenTransfer(address,uint256,bytes)": FunctionFragment;
42
42
  "oracle()": FunctionFragment;
43
43
  "predict(address)": FunctionFragment;
@@ -46,6 +46,7 @@ export interface BuyGDCloneFactoryInterface extends utils.Interface {
46
46
  "quoteToken(uint256,uint24,address)": FunctionFragment;
47
47
  "quoter()": FunctionFragment;
48
48
  "router()": FunctionFragment;
49
+ "swapFromCusd(uint256,uint256,address)": FunctionFragment;
49
50
  "swapToCusd(uint256,uint256,address)": FunctionFragment;
50
51
  };
51
52
 
@@ -69,6 +70,7 @@ export interface BuyGDCloneFactoryInterface extends utils.Interface {
69
70
  | "quoteToken"
70
71
  | "quoter"
71
72
  | "router"
73
+ | "swapFromCusd"
72
74
  | "swapToCusd"
73
75
  ): FunctionFragment;
74
76
 
@@ -98,7 +100,7 @@ export interface BuyGDCloneFactoryInterface extends utils.Interface {
98
100
  encodeFunctionData(functionFragment: "impl", values?: undefined): string;
99
101
  encodeFunctionData(
100
102
  functionFragment: "minAmountByTWAP",
101
- values: [BigNumberish, string, BigNumberish]
103
+ values: [BigNumberish, string, string, BigNumberish]
102
104
  ): string;
103
105
  encodeFunctionData(
104
106
  functionFragment: "onTokenTransfer",
@@ -120,6 +122,10 @@ export interface BuyGDCloneFactoryInterface extends utils.Interface {
120
122
  ): string;
121
123
  encodeFunctionData(functionFragment: "quoter", values?: undefined): string;
122
124
  encodeFunctionData(functionFragment: "router", values?: undefined): string;
125
+ encodeFunctionData(
126
+ functionFragment: "swapFromCusd",
127
+ values: [BigNumberish, BigNumberish, string]
128
+ ): string;
123
129
  encodeFunctionData(
124
130
  functionFragment: "swapToCusd",
125
131
  values: [BigNumberish, BigNumberish, string]
@@ -161,6 +167,10 @@ export interface BuyGDCloneFactoryInterface extends utils.Interface {
161
167
  decodeFunctionResult(functionFragment: "quoteToken", data: BytesLike): Result;
162
168
  decodeFunctionResult(functionFragment: "quoter", data: BytesLike): Result;
163
169
  decodeFunctionResult(functionFragment: "router", data: BytesLike): Result;
170
+ decodeFunctionResult(
171
+ functionFragment: "swapFromCusd",
172
+ data: BytesLike
173
+ ): Result;
164
174
  decodeFunctionResult(functionFragment: "swapToCusd", data: BytesLike): Result;
165
175
 
166
176
  events: {
@@ -251,6 +261,7 @@ export interface BuyGDCloneFactory extends BaseContract {
251
261
  minAmountByTWAP(
252
262
  baseAmount: BigNumberish,
253
263
  baseToken: string,
264
+ qtToken: string,
254
265
  period: BigNumberish,
255
266
  overrides?: CallOverrides
256
267
  ): Promise<
@@ -291,6 +302,13 @@ export interface BuyGDCloneFactory extends BaseContract {
291
302
 
292
303
  router(overrides?: CallOverrides): Promise<[string]>;
293
304
 
305
+ swapFromCusd(
306
+ amountIn: BigNumberish,
307
+ _minAmount: BigNumberish,
308
+ recipient: string,
309
+ overrides?: Overrides & { from?: string }
310
+ ): Promise<ContractTransaction>;
311
+
294
312
  swapToCusd(
295
313
  amountIn: BigNumberish,
296
314
  _minAmount: BigNumberish,
@@ -339,6 +357,7 @@ export interface BuyGDCloneFactory extends BaseContract {
339
357
  minAmountByTWAP(
340
358
  baseAmount: BigNumberish,
341
359
  baseToken: string,
360
+ qtToken: string,
342
361
  period: BigNumberish,
343
362
  overrides?: CallOverrides
344
363
  ): Promise<[BigNumber, BigNumber] & { minTwap: BigNumber; quote: BigNumber }>;
@@ -377,6 +396,13 @@ export interface BuyGDCloneFactory extends BaseContract {
377
396
 
378
397
  router(overrides?: CallOverrides): Promise<string>;
379
398
 
399
+ swapFromCusd(
400
+ amountIn: BigNumberish,
401
+ _minAmount: BigNumberish,
402
+ recipient: string,
403
+ overrides?: Overrides & { from?: string }
404
+ ): Promise<ContractTransaction>;
405
+
380
406
  swapToCusd(
381
407
  amountIn: BigNumberish,
382
408
  _minAmount: BigNumberish,
@@ -422,6 +448,7 @@ export interface BuyGDCloneFactory extends BaseContract {
422
448
  minAmountByTWAP(
423
449
  baseAmount: BigNumberish,
424
450
  baseToken: string,
451
+ qtToken: string,
425
452
  period: BigNumberish,
426
453
  overrides?: CallOverrides
427
454
  ): Promise<
@@ -462,6 +489,13 @@ export interface BuyGDCloneFactory extends BaseContract {
462
489
 
463
490
  router(overrides?: CallOverrides): Promise<string>;
464
491
 
492
+ swapFromCusd(
493
+ amountIn: BigNumberish,
494
+ _minAmount: BigNumberish,
495
+ recipient: string,
496
+ overrides?: CallOverrides
497
+ ): Promise<BigNumber>;
498
+
465
499
  swapToCusd(
466
500
  amountIn: BigNumberish,
467
501
  _minAmount: BigNumberish,
@@ -528,6 +562,7 @@ export interface BuyGDCloneFactory extends BaseContract {
528
562
  minAmountByTWAP(
529
563
  baseAmount: BigNumberish,
530
564
  baseToken: string,
565
+ qtToken: string,
531
566
  period: BigNumberish,
532
567
  overrides?: CallOverrides
533
568
  ): Promise<BigNumber>;
@@ -566,6 +601,13 @@ export interface BuyGDCloneFactory extends BaseContract {
566
601
 
567
602
  router(overrides?: CallOverrides): Promise<BigNumber>;
568
603
 
604
+ swapFromCusd(
605
+ amountIn: BigNumberish,
606
+ _minAmount: BigNumberish,
607
+ recipient: string,
608
+ overrides?: Overrides & { from?: string }
609
+ ): Promise<BigNumber>;
610
+
569
611
  swapToCusd(
570
612
  amountIn: BigNumberish,
571
613
  _minAmount: BigNumberish,
@@ -615,6 +657,7 @@ export interface BuyGDCloneFactory extends BaseContract {
615
657
  minAmountByTWAP(
616
658
  baseAmount: BigNumberish,
617
659
  baseToken: string,
660
+ qtToken: string,
618
661
  period: BigNumberish,
619
662
  overrides?: CallOverrides
620
663
  ): Promise<PopulatedTransaction>;
@@ -656,6 +699,13 @@ export interface BuyGDCloneFactory extends BaseContract {
656
699
 
657
700
  router(overrides?: CallOverrides): Promise<PopulatedTransaction>;
658
701
 
702
+ swapFromCusd(
703
+ amountIn: BigNumberish,
704
+ _minAmount: BigNumberish,
705
+ recipient: string,
706
+ overrides?: Overrides & { from?: string }
707
+ ): Promise<PopulatedTransaction>;
708
+
659
709
  swapToCusd(
660
710
  amountIn: BigNumberish,
661
711
  _minAmount: BigNumberish,
@@ -139,12 +139,41 @@ export interface DonateGDCloneInterface extends utils.Interface {
139
139
  decodeFunctionResult(functionFragment: "twapPeriod", data: BytesLike): Result;
140
140
 
141
141
  events: {
142
+ "Bought(address,uint256,uint256)": EventFragment;
143
+ "Donated(address,address,address,uint256)": EventFragment;
142
144
  "Initialized(uint8)": EventFragment;
143
145
  };
144
146
 
147
+ getEvent(nameOrSignatureOrTopic: "Bought"): EventFragment;
148
+ getEvent(nameOrSignatureOrTopic: "Donated"): EventFragment;
145
149
  getEvent(nameOrSignatureOrTopic: "Initialized"): EventFragment;
146
150
  }
147
151
 
152
+ export interface BoughtEventObject {
153
+ inToken: string;
154
+ inAmount: BigNumber;
155
+ outAmount: BigNumber;
156
+ }
157
+ export type BoughtEvent = TypedEvent<
158
+ [string, BigNumber, BigNumber],
159
+ BoughtEventObject
160
+ >;
161
+
162
+ export type BoughtEventFilter = TypedEventFilter<BoughtEvent>;
163
+
164
+ export interface DonatedEventObject {
165
+ donor: string;
166
+ recipient: string;
167
+ tokenDonated: string;
168
+ amountDonated: BigNumber;
169
+ }
170
+ export type DonatedEvent = TypedEvent<
171
+ [string, string, string, BigNumber],
172
+ DonatedEventObject
173
+ >;
174
+
175
+ export type DonatedEventFilter = TypedEventFilter<DonatedEvent>;
176
+
148
177
  export interface InitializedEventObject {
149
178
  version: number;
150
179
  }
@@ -367,24 +396,48 @@ export interface DonateGDClone extends BaseContract {
367
396
  _minAmount: BigNumberish,
368
397
  refundGas: string,
369
398
  overrides?: CallOverrides
370
- ): Promise<void>;
399
+ ): Promise<BigNumber>;
371
400
 
372
401
  swapCelo(
373
402
  _minAmount: BigNumberish,
374
403
  refundGas: string,
375
404
  overrides?: CallOverrides
376
- ): Promise<void>;
405
+ ): Promise<BigNumber>;
377
406
 
378
407
  swapCusd(
379
408
  _minAmount: BigNumberish,
380
409
  refundGas: string,
381
410
  overrides?: CallOverrides
382
- ): Promise<void>;
411
+ ): Promise<BigNumber>;
383
412
 
384
413
  twapPeriod(overrides?: CallOverrides): Promise<number>;
385
414
  };
386
415
 
387
416
  filters: {
417
+ "Bought(address,uint256,uint256)"(
418
+ inToken?: null,
419
+ inAmount?: null,
420
+ outAmount?: null
421
+ ): BoughtEventFilter;
422
+ Bought(
423
+ inToken?: null,
424
+ inAmount?: null,
425
+ outAmount?: null
426
+ ): BoughtEventFilter;
427
+
428
+ "Donated(address,address,address,uint256)"(
429
+ donor?: null,
430
+ recipient?: null,
431
+ tokenDonated?: null,
432
+ amountDonated?: null
433
+ ): DonatedEventFilter;
434
+ Donated(
435
+ donor?: null,
436
+ recipient?: null,
437
+ tokenDonated?: null,
438
+ amountDonated?: null
439
+ ): DonatedEventFilter;
440
+
388
441
  "Initialized(uint8)"(version?: null): InitializedEventFilter;
389
442
  Initialized(version?: null): InitializedEventFilter;
390
443
  };