@gooddollar/goodprotocol 1.0.8 → 1.0.9-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
  2. package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
  3. package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
  4. package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
  5. package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
  6. package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
  7. package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
  8. package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
  9. package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
  10. package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
  11. package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
  12. package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
  13. package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
  14. package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
  15. package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
  16. package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
  17. package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
  18. package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
  19. package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
  20. package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
  21. package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
  22. package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
  23. package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
  24. package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
  25. package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
  26. package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
  27. package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
  28. package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
  29. package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
  30. package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
  31. package/artifacts/contracts/governance/GovarnanceStaking.sol/GovernanceStaking.dbg.json +1 -1
  32. package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
  33. package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
  34. package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
  35. package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
  36. package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
  37. package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
  38. package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
  39. package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
  40. package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
  41. package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
  42. package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
  43. package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
  44. package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
  45. package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
  46. package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
  47. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
  48. package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
  49. package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
  50. package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
  51. package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
  52. package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
  53. package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
  54. package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
  55. package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
  56. package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
  57. package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
  58. package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
  59. package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
  60. package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
  61. package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
  62. package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +4 -0
  63. package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.json +256 -0
  64. package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
  65. package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
  66. package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
  67. package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +4 -0
  68. package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.json +1033 -0
  69. package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
  70. package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
  71. package/artifacts/contracts/staking/aave/AaveStakingFactoryV2.sol/AaveStakingFactoryV2.dbg.json +4 -0
  72. package/artifacts/contracts/staking/aave/AaveStakingFactoryV2.sol/AaveStakingFactoryV2.json +148 -0
  73. package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
  74. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +4 -0
  75. package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +1224 -0
  76. package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
  77. package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
  78. package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
  79. package/artifacts/contracts/unaudited-foundation/FuseFaucet.sol/FuseFaucet.dbg.json +1 -1
  80. package/artifacts/contracts/unaudited-foundation/InvitesV1.sol/InvitesV1.dbg.json +1 -1
  81. package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
  82. package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
  83. package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
  84. package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
  85. package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
  86. package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
  87. package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
  88. package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
  89. package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
  90. package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
  91. package/contracts/staking/BaseShareFieldV2.sol +319 -0
  92. package/contracts/staking/SimpleStakingV2.sol +522 -0
  93. package/contracts/staking/aave/AaveStakingFactoryV2.sol +93 -0
  94. package/contracts/staking/aave/GoodAaveStakingV2.sol +263 -0
  95. package/package.json +1 -1
  96. package/test/helpers.ts +5 -1
  97. package/test/staking/GoodAaveStakingFactoryV2.test.ts +122 -0
  98. package/test/staking/UsdcAaveStaking.test.ts +5 -1
  99. package/test/staking/UsdcAaveStakingV2.test.ts +291 -0
@@ -0,0 +1,263 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ pragma solidity >=0.8.0;
4
+ import "../SimpleStakingV2.sol";
5
+ import "../../Interfaces.sol";
6
+ import "../../utils/DataTypes.sol";
7
+ import "../UniswapV2SwapHelper.sol";
8
+
9
+ /**
10
+ * @title Staking contract that donates earned interest to the DAO
11
+ * allowing stakers to deposit Token
12
+ * or withdraw their stake in Token
13
+ * the contracts buy cToken and can transfer the daily interest to the DAO
14
+ */
15
+ contract GoodAaveStakingV2 is SimpleStakingV2 {
16
+ using UniswapV2SwapHelper for IHasRouter;
17
+
18
+ // Address of the TOKEN/USD oracle from chainlink
19
+ address public tokenUsdOracle;
20
+
21
+ //LendingPool of aave
22
+ ILendingPool public lendingPool;
23
+
24
+ //Address of the AaveIncentivesController
25
+ IAaveIncentivesController public incentiveController;
26
+
27
+ //address of the AAVE/USD oracle
28
+ address public aaveUSDOracle;
29
+ // Gas cost to collect interest from this staking contract
30
+ uint32 public collectInterestGasCost;
31
+ // Gas cost to claim stkAave rewards
32
+ uint32 public stkAaveClaimGasCost;
33
+
34
+ address[] public tokenToDaiSwapPath;
35
+
36
+ /**
37
+ * @param _token Token to swap DEFI token
38
+ * @param _lendingPool LendingPool address
39
+ * @param _ns Address of the NameService
40
+ * @param _tokenName Name of the staking token which will be provided to staker for their staking share
41
+ * @param _tokenSymbol Symbol of the staking token which will be provided to staker for their staking share
42
+ * @param _tokenSymbol Determines blocks to pass for 1x Multiplier
43
+ * @param _tokenUsdOracle address of the TOKEN/USD oracle
44
+ * @param _incentiveController Aave incentive controller which provides AAVE rewards
45
+ * @param _aaveUSDOracle address of the AAVE/USD oracle
46
+ */
47
+ function init(
48
+ address _token,
49
+ address _lendingPool,
50
+ INameService _ns,
51
+ string memory _tokenName,
52
+ string memory _tokenSymbol,
53
+ uint64 _maxRewardThreshold,
54
+ address _tokenUsdOracle,
55
+ IAaveIncentivesController _incentiveController,
56
+ address _aaveUSDOracle,
57
+ address[] memory _tokenToDaiSwapPath
58
+ ) public {
59
+ lendingPool = ILendingPool(_lendingPool);
60
+ DataTypes.ReserveData memory reserve = lendingPool.getReserveData(_token);
61
+ initialize(
62
+ _token,
63
+ reserve.aTokenAddress,
64
+ _ns,
65
+ _tokenName,
66
+ _tokenSymbol,
67
+ _maxRewardThreshold
68
+ );
69
+ require(
70
+ _tokenToDaiSwapPath[0] == _token &&
71
+ _tokenToDaiSwapPath[_tokenToDaiSwapPath.length - 1] ==
72
+ nameService.getAddress("DAI"),
73
+ "invalid _tokenToDaiSwapPath"
74
+ );
75
+ tokenToDaiSwapPath = _tokenToDaiSwapPath;
76
+
77
+ //above initialize going to revert on second call, so this is safe
78
+ tokenUsdOracle = _tokenUsdOracle;
79
+ incentiveController = _incentiveController;
80
+ aaveUSDOracle = _aaveUSDOracle;
81
+ collectInterestGasCost = 250000;
82
+ stkAaveClaimGasCost = 50000;
83
+ _approveTokens();
84
+ }
85
+
86
+ /**
87
+ * @dev stake some Token
88
+ * @param _amount of Token to stake
89
+ */
90
+ function mintInterestToken(uint256 _amount) internal override {
91
+ lendingPool.deposit(address(token), _amount, address(this), 0);
92
+ }
93
+
94
+ /**
95
+ * @dev redeem Token from aave
96
+ * @param _amount of token to redeem in Token
97
+ */
98
+ function redeem(uint256 _amount) internal override {
99
+ uint256 withdrawnAmount = lendingPool.withdraw(
100
+ address(token),
101
+ _amount,
102
+ address(this)
103
+ );
104
+ require(withdrawnAmount > 0, "Withdrawn amount should be bigger than zero");
105
+ }
106
+
107
+ /**
108
+ * @dev Function to redeem aToken for DAI, so reserve knows how to handle it. (reserve can handle dai or cdai)
109
+ * also transfers stkaave to reserve
110
+ * @dev _amount of token in iToken
111
+ * @dev _recipient recipient of the DAI
112
+ * @return actualTokenGains amount of token redeemed for dai,
113
+ actualRewardTokenGains amount of reward token earned,
114
+ daiAmount total dai received
115
+ */
116
+ function redeemUnderlyingToDAI(uint256 _amount, address _recipient)
117
+ internal
118
+ override
119
+ returns (
120
+ uint256 actualTokenGains,
121
+ uint256 actualRewardTokenGains,
122
+ uint256 daiAmount
123
+ )
124
+ {
125
+ //out of requested interests to withdraw how much is it safe to swap
126
+ actualTokenGains = IHasRouter(this).maxSafeTokenAmount(
127
+ address(token),
128
+ tokenToDaiSwapPath[1],
129
+ _amount,
130
+ maxLiquidityPercentageSwap
131
+ );
132
+
133
+ lendingPool.withdraw(address(token), actualTokenGains, address(this));
134
+ actualTokenGains = token.balanceOf(address(this));
135
+
136
+ address[] memory tokenAddress = new address[](1);
137
+ tokenAddress[0] = address(iToken);
138
+
139
+ actualRewardTokenGains = incentiveController.claimRewards(
140
+ tokenAddress,
141
+ type(uint256).max,
142
+ avatar
143
+ );
144
+
145
+ if (actualTokenGains > 0) {
146
+ daiAmount = IHasRouter(this).swap(
147
+ tokenToDaiSwapPath,
148
+ actualTokenGains,
149
+ 0,
150
+ _recipient
151
+ );
152
+ }
153
+ }
154
+
155
+ /**
156
+ * @dev returns decimals of token.
157
+ */
158
+ function tokenDecimal() internal view override returns (uint256) {
159
+ ERC20 token = ERC20(address(token));
160
+ return uint256(token.decimals());
161
+ }
162
+
163
+ /**
164
+ * @dev returns decimals of interest token.
165
+ */
166
+ function iTokenDecimal() internal view override returns (uint256) {
167
+ ERC20 aToken = ERC20(address(iToken));
168
+ return uint256(aToken.decimals());
169
+ }
170
+
171
+ /**
172
+ * @dev Function that calculates current interest gains of this staking contract
173
+ * @param _returnTokenBalanceInUSD determine return token balance of staking contract in USD
174
+ * @param _returnTokenGainsInUSD determine return token gains of staking contract in USD
175
+ * @return iTokenGains gains in iToken, tokenGains gains in token, tokenBalance current balance , balanceInUSD, tokenGainsInUSD
176
+ */
177
+ function currentGains(
178
+ bool _returnTokenBalanceInUSD,
179
+ bool _returnTokenGainsInUSD
180
+ )
181
+ public
182
+ view
183
+ override
184
+ returns (
185
+ uint256 iTokenGains,
186
+ uint256 tokenGains,
187
+ uint256 tokenBalance,
188
+ uint256 balanceInUSD,
189
+ uint256 tokenGainsInUSD
190
+ )
191
+ {
192
+ ERC20 aToken = ERC20(address(iToken));
193
+ tokenBalance = aToken.balanceOf(address(this));
194
+ balanceInUSD = _returnTokenBalanceInUSD
195
+ ? getTokenValueInUSD(tokenUsdOracle, tokenBalance, token.decimals())
196
+ : 0;
197
+ address[] memory tokenAddress = new address[](1);
198
+ tokenAddress[0] = address(token);
199
+ if (tokenBalance <= totalProductivity) {
200
+ return (0, 0, tokenBalance, balanceInUSD, 0);
201
+ }
202
+ iTokenGains = tokenGains = tokenBalance - totalProductivity;
203
+
204
+ tokenGainsInUSD = _returnTokenGainsInUSD
205
+ ? getTokenValueInUSD(tokenUsdOracle, tokenGains, token.decimals())
206
+ : 0;
207
+ }
208
+
209
+ /**
210
+ * @dev Function to get interest transfer cost for this particular staking contract
211
+ */
212
+ function getGasCostForInterestTransfer()
213
+ external
214
+ view
215
+ override
216
+ returns (uint32)
217
+ {
218
+ address[] memory tokenAddress = new address[](1);
219
+ tokenAddress[0] = address(iToken);
220
+ uint256 stkAaaveBalance = incentiveController.getRewardsBalance(
221
+ tokenAddress,
222
+ address(this)
223
+ );
224
+ if (stkAaaveBalance > 0)
225
+ return collectInterestGasCost + stkAaveClaimGasCost;
226
+
227
+ return collectInterestGasCost;
228
+ }
229
+
230
+ /**
231
+ * @dev Set Gas cost to interest collection for this contract
232
+ * @param _collectInterestGasCost Gas cost to collect interest
233
+ * @param _rewardTokenCollectCost gas cost to collect reward tokens
234
+ */
235
+ function setcollectInterestGasCostParams(
236
+ uint32 _collectInterestGasCost,
237
+ uint32 _rewardTokenCollectCost
238
+ ) external {
239
+ _onlyAvatar();
240
+ collectInterestGasCost = _collectInterestGasCost;
241
+ stkAaveClaimGasCost = _rewardTokenCollectCost;
242
+ }
243
+
244
+ /**
245
+ * @dev Calculates worth of given amount of iToken in Token
246
+ * @param _amount Amount of token to calculate worth in Token
247
+ * @return Worth of given amount of token in Token
248
+ */
249
+ function iTokenWorthInToken(uint256 _amount)
250
+ public
251
+ view
252
+ override
253
+ returns (uint256)
254
+ {
255
+ return _amount; // since aToken is peg to Token 1:1 return exact amount
256
+ }
257
+
258
+ function _approveTokens() internal override {
259
+ address uniswapRouter = nameService.getAddress("UNISWAP_ROUTER");
260
+ token.approve(uniswapRouter, type(uint256).max);
261
+ token.approve(address(lendingPool), type(uint256).max); // approve the transfers to defi protocol as much as possible in order to save gas
262
+ }
263
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gooddollar/goodprotocol",
3
- "version": "1.0.8",
3
+ "version": "1.0.9-beta.0",
4
4
  "description": "GoodDollar Protocol",
5
5
  "scripts": {
6
6
  "build": "scripts/build.sh deploy",
package/test/helpers.ts CHANGED
@@ -18,7 +18,11 @@ import { GoodMarketMaker, CompoundVotingMachine } from "../types";
18
18
  import { Contract } from "ethers";
19
19
 
20
20
  export const getStakingFactory = async (
21
- factory: "GoodCompoundStaking" | "GoodAaveStaking" | "GoodCompoundStakingTest"
21
+ factory:
22
+ | "GoodCompoundStaking"
23
+ | "GoodAaveStaking"
24
+ | "GoodCompoundStakingTest"
25
+ | "GoodAaveStakingV2"
22
26
  ) => {
23
27
  let swapHelper = await ethers
24
28
  .getContractFactory("UniswapV2SwapHelper")
@@ -0,0 +1,122 @@
1
+ import { default as hre, ethers, upgrades } from "hardhat";
2
+ import { deployMockContract, MockContract } from "ethereum-waffle";
3
+ import { expect } from "chai";
4
+ import { CERC20, GoodAaveStaking, AaveStakingFactory } from "../../types";
5
+ import { createDAO, deployUniswap } from "../helpers";
6
+ import { Contract } from "ethers";
7
+
8
+ const BN = ethers.BigNumber;
9
+ export const NULL_ADDRESS = ethers.constants.AddressZero;
10
+
11
+ let cdai: CERC20;
12
+
13
+ describe("AaveStakingFactoryV2", () => {
14
+ let founder,
15
+ signers,
16
+ cdai,
17
+ usdc,
18
+ aave,
19
+ incentiveController,
20
+ aaveUsdOracle: Contract,
21
+ dai,
22
+ dao,
23
+ stakingFactory: AaveStakingFactory,
24
+ lendingPool: Contract;
25
+
26
+ before(async () => {
27
+ [founder, ...signers] = await ethers.getSigners();
28
+ dao = await createDAO();
29
+ const usdcFactory = await ethers.getContractFactory("USDCMock");
30
+ const lendingPoolFactory = await ethers.getContractFactory(
31
+ "LendingPoolMock"
32
+ );
33
+ aave = await (await ethers.getContractFactory("AaveMock")).deploy();
34
+ incentiveController = await (
35
+ await ethers.getContractFactory("IncentiveControllerMock")
36
+ ).deploy(aave.address);
37
+ usdc = await usdcFactory.deploy();
38
+ lendingPool = await lendingPoolFactory.deploy(usdc.address);
39
+ aaveUsdOracle = await (
40
+ await ethers.getContractFactory("AaveUSDMockOracle")
41
+ ).deploy();
42
+ dai = dao.daiAddress;
43
+ cdai = dao.cdaiAddress;
44
+ const uniswap = await deployUniswap(
45
+ dao.COMP,
46
+ await ethers.getContractAt("DAIMock", dai)
47
+ );
48
+ const router = uniswap.router;
49
+ await dao.setDAOAddress("UNISWAP_ROUTER", router.address);
50
+ await dao.setDAOAddress("AAVE", aave.address);
51
+ let swapHelper = await ethers
52
+ .getContractFactory("UniswapV2SwapHelper")
53
+ .then(_ => _.deploy());
54
+
55
+ stakingFactory = (await ethers
56
+ .getContractFactory("AaveStakingFactoryV2", {
57
+ libraries: { UniswapV2SwapHelper: swapHelper.address }
58
+ })
59
+ .then(_ => _.deploy())) as AaveStakingFactory;
60
+ });
61
+
62
+ it("should create proxy clone", async () => {
63
+ const res = await (
64
+ await stakingFactory.clone(usdc.address, ethers.constants.HashZero)
65
+ ).wait();
66
+ const log = res.events.find(_ => _.event === "Deployed");
67
+ const detAddress = await stakingFactory.predictAddress(
68
+ usdc.address,
69
+ ethers.constants.HashZero
70
+ );
71
+
72
+ expect(log).to.not.empty;
73
+ expect(log.args.proxy).to.equal(detAddress);
74
+ expect(log.args.token).to.equal(usdc.address);
75
+ });
76
+
77
+ it("should create and initialize clone", async () => {
78
+ const ns = await ethers
79
+ .getContractFactory("NameService")
80
+ .then(_ => _.deploy());
81
+ const res = await (
82
+ await stakingFactory.cloneAndInit(
83
+ usdc.address,
84
+ lendingPool.address,
85
+ dao.nameService.address,
86
+ 5760,
87
+ stakingFactory.address,
88
+ incentiveController.address,
89
+ aaveUsdOracle.address,
90
+ [usdc.address, dai]
91
+ )
92
+ ).wait();
93
+ const log = res.events.find(_ => _.event === "Deployed");
94
+ const detAddress = await stakingFactory.predictAddress(
95
+ usdc.address,
96
+ ethers.utils.solidityKeccak256(
97
+ ["address", "address", "uint64", "address", "address", "address"],
98
+ [
99
+ lendingPool.address,
100
+ dao.nameService.address,
101
+ 5760,
102
+ stakingFactory.address,
103
+ incentiveController.address,
104
+ aaveUsdOracle.address
105
+ ]
106
+ )
107
+ );
108
+ expect(log).to.not.empty;
109
+ expect(log.args.proxy).to.equal(detAddress);
110
+ expect(log.args.token).to.equal(usdc.address);
111
+
112
+ //check initialization
113
+ const staking: GoodAaveStaking = (await ethers.getContractAt(
114
+ "GoodAaveStaking",
115
+ detAddress
116
+ )) as GoodAaveStaking;
117
+ expect(await staking.iToken()).to.equal(lendingPool.address);
118
+ expect(await staking.token()).to.equal(usdc.address);
119
+ expect(await staking.name()).to.equal("GoodAaveStakingV2 aUSDC");
120
+ expect(await staking.symbol()).to.equal("gaUSDC");
121
+ });
122
+ });
@@ -29,6 +29,7 @@ describe("UsdcAaveStaking - staking with USDC mocks to AAVE interface", () => {
29
29
  lendingPool,
30
30
  setDAOAddress,
31
31
  genericCall,
32
+ goodReserve,
32
33
  goodAaveStakingFactory;
33
34
  before(async () => {
34
35
  [founder, staker, ...signers] = await ethers.getSigners();
@@ -55,8 +56,10 @@ describe("UsdcAaveStaking - staking with USDC mocks to AAVE interface", () => {
55
56
  marketMaker: mm,
56
57
  daiAddress,
57
58
  genericCall: gc,
58
- COMP
59
+ COMP,
60
+ reserve
59
61
  } = await createDAO();
62
+ goodReserve = reserve;
60
63
  dai = await ethers.getContractAt("DAIMock", daiAddress);
61
64
  avatar = av;
62
65
  controller = ctrl;
@@ -275,6 +278,7 @@ describe("UsdcAaveStaking - staking with USDC mocks to AAVE interface", () => {
275
278
  );
276
279
  expect(currentGainsAfterEarnRewards[4]).to.be.equal(0); // stkAAVE rewards shouldnt count as gain
277
280
  expect(currentGainsAfterCollectInterest[4]).to.be.equal("0");
281
+ expect(await aave.balanceOf(goodReserve.address)).gt(0);
278
282
  });
279
283
  async function addLiquidity(
280
284
  token0: Contract,