@gooddollar/goodprotocol 1.0.9 → 1.0.13-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.
- package/artifacts/contracts/DAOStackInterfaces.sol/Avatar.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/Controller.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/GlobalConstraintInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/IntVoteInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/ReputationInterface.dbg.json +1 -1
- package/artifacts/contracts/DAOStackInterfaces.sol/SchemeRegistrar.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/AggregatorV3Interface.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ERC20.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IAaveIncentivesController.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IAdminWallet.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IDonationStaking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IERC2917.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IFirstClaimPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IGoodDollar.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IGoodStaking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IHasRouter.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IIdentity.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/INameService.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IUBIScheme.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ProxyAdmin.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Reserve.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Staking.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/Uniswap.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/UniswapFactory.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/UniswapPair.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/cERC20.dbg.json +1 -1
- package/artifacts/contracts/governance/ClaimersDistribution.sol/ClaimersDistribution.dbg.json +1 -1
- package/artifacts/contracts/governance/CompoundVotingMachine.sol/CompoundVotingMachine.dbg.json +1 -1
- package/artifacts/contracts/governance/GReputation.sol/GReputation.dbg.json +1 -1
- package/artifacts/contracts/governance/GovarnanceStaking.sol/GovernanceStaking.dbg.json +1 -1
- package/artifacts/contracts/governance/MultiBaseGovernanceShareField.sol/MultiBaseGovernanceShareField.dbg.json +1 -1
- package/artifacts/contracts/governance/Reputation.sol/Reputation.dbg.json +1 -1
- package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
- package/artifacts/contracts/governance/StakersDistribution.sol/StakersDistribution.json +2 -2
- package/artifacts/contracts/mocks/AaveMock.sol/AaveMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodCompoundStakingTest.sol/GoodCompoundStakingTest.json +6 -6
- package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/IncentiveControllerMock.sol/IncentiveControllerMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/LendingPoolMock.sol/LendingPoolMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTester.sol/OverMintTester.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTesterRegularStake.sol/OverMintTesterRegularStake.json +2 -2
- package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/SwapHelperTest.sol/SwapHelperTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/TwentyDecimalsTokenMock.sol/TwentyDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
- package/artifacts/contracts/mocks/UsdcMock.sol/USDCMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cBATMock.sol/cBATMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAILowWorthMock.sol/cDAILowWorthMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAIMock.sol/cDAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDAINonMintableMock.sol/cDAINonMintableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cDecimalsMock.sol/cDecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cSDTMock.sol/cSDTMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/cUSDCMock.sol/cUSDCMock.dbg.json +1 -1
- package/artifacts/contracts/reserve/ExchangeHelper.sol/ExchangeHelper.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodMarketMaker.sol/GoodMarketMaker.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/ContributionCalc.dbg.json +1 -1
- package/artifacts/contracts/reserve/GoodReserveCDai.sol/GoodReserveCDai.dbg.json +1 -1
- package/artifacts/contracts/staking/BaseShareField.sol/BaseShareField.dbg.json +1 -1
- package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.dbg.json +1 -1
- package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.json +48 -104
- package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/DonationsStaking.sol/DonationsStaking.json +2 -2
- package/artifacts/contracts/staking/GoodFundManager.sol/GoodFundManager.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStaking.sol/SimpleStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.json +48 -123
- package/artifacts/contracts/staking/UniswapV2SwapHelper.sol/UniswapV2SwapHelper.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/AaveStakingFactory.sol/AaveStakingFactory.json +65 -12
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.json +4 -4
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +52 -127
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.json +57 -14
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.json +6 -6
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +4 -0
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.json +1092 -0
- package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
- package/artifacts/contracts/unaudited-foundation/FuseFaucet.sol/FuseFaucet.dbg.json +1 -1
- package/artifacts/contracts/unaudited-foundation/InvitesV1.sol/InvitesV1.dbg.json +1 -1
- package/artifacts/contracts/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
- package/artifacts/contracts/utils/DAOContract.sol/DAOContract.dbg.json +1 -1
- package/artifacts/contracts/utils/DAOUpgradeableContract.sol/DAOUpgradeableContract.dbg.json +1 -1
- package/artifacts/contracts/utils/DSMath.sol/DSMath.dbg.json +1 -1
- package/artifacts/contracts/utils/DataTypes.sol/DataTypes.dbg.json +1 -1
- package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgrade.sol/OldMarketMaker.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgrade.sol/ProtocolUpgrade.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeFuse.sol/ProtocolUpgradeFuse.dbg.json +1 -1
- package/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.dbg.json +1 -1
- package/contracts/staking/BaseShareFieldV2.sol +45 -21
- package/contracts/staking/SimpleStaking.sol +0 -7
- package/contracts/staking/SimpleStakingV2.sol +10 -44
- package/contracts/staking/aave/AaveStakingFactory.sol +45 -19
- package/contracts/staking/aave/GoodAaveStaking.sol +1 -1
- package/contracts/staking/aave/GoodAaveStakingV2.sol +2 -2
- package/contracts/staking/compound/CompoundStakingFactory.sol +41 -18
- package/contracts/staking/compound/GoodCompoundStaking.sol +1 -1
- package/contracts/staking/compound/GoodCompoundStakingV2.sol +315 -0
- package/package.json +1 -1
- package/releases/deployment.json +57 -47
- package/scripts/upgradeToV2/upgradeToV2.ts +7 -3
- package/test/governance/StakersDistribution.test.ts +30 -1
- package/test/helpers.ts +1 -0
- package/test/staking/CompoundStakingFactory.test.ts +24 -21
- package/test/staking/DifferentStakingTokens.test.ts +3 -1
- package/test/staking/DonationsStaking.test.ts +3 -1
- package/test/staking/GoodAaveStakingFactory.test.ts +26 -23
- package/test/staking/SimpleDAIStaking.test.ts +3 -11
- package/test/staking/StakingRewards.test.ts +20 -14
- package/test/staking/SwapHelper.test.ts +4 -1
- package/test/staking/UsdcAaveStaking.test.ts +23 -8
- package/test/ubi/UBIScheme.e2e.test.ts +1 -1
- package/test/utils/ProtocolUpgrade.test.ts +1 -1
- package/artifacts/contracts/staking/aave/AaveStakingFactoryV2.sol/AaveStakingFactoryV2.dbg.json +0 -4
- package/artifacts/contracts/staking/aave/AaveStakingFactoryV2.sol/AaveStakingFactoryV2.json +0 -148
- package/contracts/staking/aave/AaveStakingFactoryV2.sol +0 -93
- package/test/staking/GoodAaveStakingFactoryV2.test.ts +0 -122
- package/test/staking/UsdcAaveStakingV2.test.ts +0 -291
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
|
|
3
|
-
pragma solidity >=0.8.0;
|
|
4
|
-
import "@openzeppelin/contracts-upgradeable/proxy/ClonesUpgradeable.sol";
|
|
5
|
-
import "./GoodAaveStakingV2.sol";
|
|
6
|
-
import "../../Interfaces.sol";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @title Staking contract that donates earned interest to the DAO
|
|
10
|
-
* allowing stakers to deposit Token
|
|
11
|
-
* or withdraw their stake in Token
|
|
12
|
-
* the contracts buy cToken and can transfer the daily interest to the DAO
|
|
13
|
-
*/
|
|
14
|
-
contract AaveStakingFactoryV2 {
|
|
15
|
-
using ClonesUpgradeable for address;
|
|
16
|
-
|
|
17
|
-
address public impl = address(new GoodAaveStakingV2());
|
|
18
|
-
|
|
19
|
-
event Deployed(address proxy, address token);
|
|
20
|
-
|
|
21
|
-
function clone(ERC20 token, bytes32 paramsHash)
|
|
22
|
-
public
|
|
23
|
-
returns (GoodAaveStakingV2)
|
|
24
|
-
{
|
|
25
|
-
address deployed = address(impl).cloneDeterministic(
|
|
26
|
-
keccak256(abi.encodePacked(address(token), paramsHash))
|
|
27
|
-
);
|
|
28
|
-
emit Deployed(deployed, address(token));
|
|
29
|
-
return GoodAaveStakingV2(deployed);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
@dev Function to clone Staking contract and initialize new one with new token
|
|
34
|
-
@param token Staking token to use in staking contract
|
|
35
|
-
@param _lendingPool address of the lending Pool of AAVE Protocol
|
|
36
|
-
@param _ns NameService that holds whole necessary addresses
|
|
37
|
-
@param _maxRewardThreshold Block numbers that need to pass in order to user would get their rewards with 1x multiplier instead of 0.5x
|
|
38
|
-
@param _tokenUsdOracle address of the TOKEN/USD oracle
|
|
39
|
-
@param _incentiveController Incentive Controller of AAVE protocol in order to claim rewards from AAVE
|
|
40
|
-
@param _aaveUSDOracle address of the AAVE/USD oracle
|
|
41
|
-
*/
|
|
42
|
-
function cloneAndInit(
|
|
43
|
-
ERC20 token,
|
|
44
|
-
address _lendingPool,
|
|
45
|
-
INameService _ns,
|
|
46
|
-
uint64 _maxRewardThreshold,
|
|
47
|
-
address _tokenUsdOracle,
|
|
48
|
-
IAaveIncentivesController _incentiveController,
|
|
49
|
-
address _aaveUSDOracle,
|
|
50
|
-
address[] memory _tokenToDaiSwapPath
|
|
51
|
-
) public {
|
|
52
|
-
GoodAaveStakingV2 deployed = clone(
|
|
53
|
-
token,
|
|
54
|
-
keccak256(
|
|
55
|
-
abi.encodePacked(
|
|
56
|
-
_lendingPool,
|
|
57
|
-
address(_ns),
|
|
58
|
-
_maxRewardThreshold,
|
|
59
|
-
_tokenUsdOracle,
|
|
60
|
-
address(_incentiveController),
|
|
61
|
-
_aaveUSDOracle
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
ERC20 iToken = ERC20(
|
|
67
|
-
ILendingPool(_lendingPool).getReserveData(address(token)).aTokenAddress
|
|
68
|
-
);
|
|
69
|
-
deployed.init(
|
|
70
|
-
address(token),
|
|
71
|
-
address(_lendingPool),
|
|
72
|
-
_ns,
|
|
73
|
-
string(abi.encodePacked("GoodAaveStakingV2 ", iToken.name())),
|
|
74
|
-
string(abi.encodePacked("g", iToken.symbol())),
|
|
75
|
-
_maxRewardThreshold,
|
|
76
|
-
_tokenUsdOracle,
|
|
77
|
-
_incentiveController,
|
|
78
|
-
_aaveUSDOracle,
|
|
79
|
-
_tokenToDaiSwapPath
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function predictAddress(ERC20 token, bytes32 paramsHash)
|
|
84
|
-
public
|
|
85
|
-
view
|
|
86
|
-
returns (address)
|
|
87
|
-
{
|
|
88
|
-
return
|
|
89
|
-
address(impl).predictDeterministicAddress(
|
|
90
|
-
keccak256(abi.encodePacked(address(token), paramsHash))
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { default as hre, ethers, upgrades } from "hardhat";
|
|
2
|
-
import { BigNumber, Contract } from "ethers";
|
|
3
|
-
import { expect } from "chai";
|
|
4
|
-
import { GoodMarketMaker } from "../../types";
|
|
5
|
-
import IUniswapV2Pair from "@uniswap/v2-core/build/IUniswapV2Pair.json";
|
|
6
|
-
import { createDAO, deployUniswap, getStakingFactory } from "../helpers";
|
|
7
|
-
|
|
8
|
-
const BN = ethers.BigNumber;
|
|
9
|
-
export const NULL_ADDRESS = ethers.constants.AddressZero;
|
|
10
|
-
|
|
11
|
-
describe("UsdcAaveStakingV2 - staking with USDC mocks to AAVE interface", () => {
|
|
12
|
-
let dai: Contract;
|
|
13
|
-
let usdc: Contract;
|
|
14
|
-
let pair: Contract, uniswapRouter: Contract;
|
|
15
|
-
let comp: Contract, aave: Contract;
|
|
16
|
-
let daiUsdOracle: Contract, aaveUsdOracle: Contract;
|
|
17
|
-
let goodAaveStaking: Contract;
|
|
18
|
-
let goodFundManager: Contract;
|
|
19
|
-
let avatar,
|
|
20
|
-
goodDollar,
|
|
21
|
-
marketMaker: GoodMarketMaker,
|
|
22
|
-
controller,
|
|
23
|
-
founder,
|
|
24
|
-
staker,
|
|
25
|
-
schemeMock,
|
|
26
|
-
signers,
|
|
27
|
-
nameService,
|
|
28
|
-
incentiveController,
|
|
29
|
-
lendingPool,
|
|
30
|
-
setDAOAddress,
|
|
31
|
-
genericCall,
|
|
32
|
-
goodAaveStakingFactory;
|
|
33
|
-
before(async () => {
|
|
34
|
-
[founder, staker, ...signers] = await ethers.getSigners();
|
|
35
|
-
schemeMock = signers.pop();
|
|
36
|
-
|
|
37
|
-
const cUsdcFactory = await ethers.getContractFactory("cUSDCMock");
|
|
38
|
-
const goodFundManagerFactory = await ethers.getContractFactory(
|
|
39
|
-
"GoodFundManager"
|
|
40
|
-
);
|
|
41
|
-
goodAaveStakingFactory = await getStakingFactory("GoodAaveStakingV2");
|
|
42
|
-
|
|
43
|
-
const lendingPoolFactory = await ethers.getContractFactory(
|
|
44
|
-
"LendingPoolMock"
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const usdcFactory = await ethers.getContractFactory("USDCMock");
|
|
48
|
-
let {
|
|
49
|
-
controller: ctrl,
|
|
50
|
-
avatar: av,
|
|
51
|
-
gd,
|
|
52
|
-
identity,
|
|
53
|
-
nameService: ns,
|
|
54
|
-
setDAOAddress: sda,
|
|
55
|
-
marketMaker: mm,
|
|
56
|
-
daiAddress,
|
|
57
|
-
genericCall: gc,
|
|
58
|
-
COMP
|
|
59
|
-
} = await createDAO();
|
|
60
|
-
dai = await ethers.getContractAt("DAIMock", daiAddress);
|
|
61
|
-
avatar = av;
|
|
62
|
-
controller = ctrl;
|
|
63
|
-
setDAOAddress = sda;
|
|
64
|
-
nameService = ns;
|
|
65
|
-
genericCall = gc;
|
|
66
|
-
console.log("deployed dao", {
|
|
67
|
-
founder: founder.address,
|
|
68
|
-
gd,
|
|
69
|
-
identity,
|
|
70
|
-
controller,
|
|
71
|
-
avatar
|
|
72
|
-
});
|
|
73
|
-
goodFundManager = await upgrades.deployProxy(
|
|
74
|
-
goodFundManagerFactory,
|
|
75
|
-
[nameService.address],
|
|
76
|
-
{ kind: "uups" }
|
|
77
|
-
);
|
|
78
|
-
await setDAOAddress("FUND_MANAGER", goodFundManager.address);
|
|
79
|
-
console.log("Deployed goodfund manager", {
|
|
80
|
-
manager: goodFundManager.address
|
|
81
|
-
});
|
|
82
|
-
goodDollar = await ethers.getContractAt("IGoodDollar", gd);
|
|
83
|
-
|
|
84
|
-
marketMaker = mm;
|
|
85
|
-
const tokenUsdOracleFactory = await ethers.getContractFactory(
|
|
86
|
-
"BatUSDMockOracle"
|
|
87
|
-
);
|
|
88
|
-
daiUsdOracle = await tokenUsdOracleFactory.deploy();
|
|
89
|
-
comp = COMP;
|
|
90
|
-
usdc = await usdcFactory.deploy(); // Another erc20 token for uniswap router test
|
|
91
|
-
const uniswap = await deployUniswap(comp, dai);
|
|
92
|
-
uniswapRouter = uniswap.router;
|
|
93
|
-
const { factory, weth } = uniswap;
|
|
94
|
-
setDAOAddress("UNISWAP_ROUTER", uniswapRouter.address);
|
|
95
|
-
await factory.createPair(usdc.address, dai.address); // Create tokenA and dai pair
|
|
96
|
-
const pairAddress = factory.getPair(usdc.address, dai.address);
|
|
97
|
-
pair = new Contract(
|
|
98
|
-
pairAddress,
|
|
99
|
-
JSON.stringify(IUniswapV2Pair.abi),
|
|
100
|
-
staker
|
|
101
|
-
).connect(founder);
|
|
102
|
-
aave = await (await ethers.getContractFactory("AaveMock")).deploy();
|
|
103
|
-
await factory.createPair(aave.address, dai.address);
|
|
104
|
-
const aavePairAddress = factory.getPair(aave.address, dai.address);
|
|
105
|
-
const aavePair = new Contract(
|
|
106
|
-
aavePairAddress,
|
|
107
|
-
JSON.stringify(IUniswapV2Pair.abi),
|
|
108
|
-
staker
|
|
109
|
-
).connect(founder);
|
|
110
|
-
await dai["mint(address,uint256)"](
|
|
111
|
-
founder.address,
|
|
112
|
-
ethers.utils.parseEther("500000000000000")
|
|
113
|
-
);
|
|
114
|
-
await aave["mint(address,uint256)"](
|
|
115
|
-
founder.address,
|
|
116
|
-
ethers.utils.parseEther("20000")
|
|
117
|
-
);
|
|
118
|
-
await addLiquidity(
|
|
119
|
-
dai,
|
|
120
|
-
aave,
|
|
121
|
-
aavePair,
|
|
122
|
-
ethers.utils.parseEther("2000000"),
|
|
123
|
-
ethers.utils.parseEther("2000")
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
await setDAOAddress("COMP", comp.address);
|
|
127
|
-
|
|
128
|
-
lendingPool = await lendingPoolFactory.deploy(usdc.address);
|
|
129
|
-
incentiveController = await (
|
|
130
|
-
await ethers.getContractFactory("IncentiveControllerMock")
|
|
131
|
-
).deploy(aave.address);
|
|
132
|
-
aaveUsdOracle = await (
|
|
133
|
-
await ethers.getContractFactory("AaveUSDMockOracle")
|
|
134
|
-
).deploy();
|
|
135
|
-
await setDAOAddress("AAVE", aave.address);
|
|
136
|
-
goodAaveStaking = await goodAaveStakingFactory
|
|
137
|
-
.deploy()
|
|
138
|
-
.then(async contract => {
|
|
139
|
-
await contract.init(
|
|
140
|
-
usdc.address,
|
|
141
|
-
lendingPool.address,
|
|
142
|
-
nameService.address,
|
|
143
|
-
"Good USDC",
|
|
144
|
-
"gUSDC",
|
|
145
|
-
"172800",
|
|
146
|
-
daiUsdOracle.address,
|
|
147
|
-
incentiveController.address,
|
|
148
|
-
aaveUsdOracle.address,
|
|
149
|
-
[usdc.address, dai.address]
|
|
150
|
-
);
|
|
151
|
-
return contract;
|
|
152
|
-
});
|
|
153
|
-
await usdc["mint(address,uint256)"](
|
|
154
|
-
founder.address,
|
|
155
|
-
ethers.utils.parseUnits("500000000000000", 6)
|
|
156
|
-
);
|
|
157
|
-
await usdc["mint(address,uint256)"](
|
|
158
|
-
staker.address,
|
|
159
|
-
ethers.utils.parseUnits("10000", 6)
|
|
160
|
-
);
|
|
161
|
-
await usdc["mint(address,uint256)"](
|
|
162
|
-
lendingPool.address,
|
|
163
|
-
ethers.utils.parseEther("100000000")
|
|
164
|
-
); // We should put extra USDC to LendingPool/Atoken contract in order to provide interest
|
|
165
|
-
await addLiquidity(
|
|
166
|
-
usdc,
|
|
167
|
-
dai,
|
|
168
|
-
pair,
|
|
169
|
-
ethers.utils.parseUnits("200000000000000", 6),
|
|
170
|
-
ethers.utils.parseEther("200000000000000")
|
|
171
|
-
);
|
|
172
|
-
await usdc.approve(goodAaveStaking.address, ethers.constants.MaxUint256);
|
|
173
|
-
await usdc
|
|
174
|
-
.connect(staker)
|
|
175
|
-
.approve(goodAaveStaking.address, ethers.constants.MaxUint256);
|
|
176
|
-
const currentBlockNumber = await ethers.provider.getBlockNumber();
|
|
177
|
-
const encodedData = goodFundManagerFactory.interface.encodeFunctionData(
|
|
178
|
-
"setStakingReward",
|
|
179
|
-
[
|
|
180
|
-
"1000",
|
|
181
|
-
goodAaveStaking.address,
|
|
182
|
-
currentBlockNumber - 5,
|
|
183
|
-
currentBlockNumber + 500,
|
|
184
|
-
false
|
|
185
|
-
] // set 10 gd per block
|
|
186
|
-
);
|
|
187
|
-
await genericCall(goodFundManager.address, encodedData, avatar, 0);
|
|
188
|
-
await setDAOAddress("MARKET_MAKER", marketMaker.address);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("it should stake usdc to lendingPool and withdraw", async () => {
|
|
192
|
-
const stakingAmount = ethers.utils.parseUnits("100", 6);
|
|
193
|
-
await goodAaveStaking.stake(stakingAmount, 0, false);
|
|
194
|
-
const aTokenBalanceAfterStake = await lendingPool.balanceOf(
|
|
195
|
-
goodAaveStaking.address
|
|
196
|
-
);
|
|
197
|
-
await goodAaveStaking.withdrawStake(stakingAmount, false);
|
|
198
|
-
const aTokenBalanceAfterWithdraw = await lendingPool.balanceOf(
|
|
199
|
-
goodAaveStaking.address
|
|
200
|
-
);
|
|
201
|
-
expect(aTokenBalanceAfterWithdraw).to.be.equal(0);
|
|
202
|
-
expect(aTokenBalanceAfterStake).to.be.gt(0);
|
|
203
|
-
expect(aTokenBalanceAfterStake).to.be.equal(stakingAmount);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it("stake should generate some interest and should be used to generate UBI", async () => {
|
|
207
|
-
const stakingAmount = ethers.utils.parseUnits("100", 6);
|
|
208
|
-
|
|
209
|
-
await goodAaveStaking.connect(staker).stake(stakingAmount, 0, false);
|
|
210
|
-
|
|
211
|
-
await lendingPool.giveInterestToUser("1500", goodAaveStaking.address); // increase interest by calling giveInterestToUser
|
|
212
|
-
|
|
213
|
-
const currentUBIInterestBeforeWithdraw = await goodAaveStaking.currentGains(
|
|
214
|
-
false,
|
|
215
|
-
true
|
|
216
|
-
);
|
|
217
|
-
await goodAaveStaking.connect(staker).withdrawStake(stakingAmount, false);
|
|
218
|
-
const gdBalanceBeforeCollectInterest = await goodDollar.balanceOf(
|
|
219
|
-
staker.address
|
|
220
|
-
);
|
|
221
|
-
const contractAddressesToBeCollected =
|
|
222
|
-
await goodFundManager.calcSortedContracts();
|
|
223
|
-
console.log(contractAddressesToBeCollected.toString());
|
|
224
|
-
const addressesToCollect = contractAddressesToBeCollected.map(x => x[0]);
|
|
225
|
-
await goodFundManager
|
|
226
|
-
.connect(staker)
|
|
227
|
-
.collectInterest(addressesToCollect, false);
|
|
228
|
-
const gdBalanceAfterCollectInterest = await goodDollar.balanceOf(
|
|
229
|
-
staker.address
|
|
230
|
-
);
|
|
231
|
-
const currentUBIInterestAfterWithdraw = await goodAaveStaking.currentGains(
|
|
232
|
-
false,
|
|
233
|
-
true
|
|
234
|
-
);
|
|
235
|
-
expect(currentUBIInterestBeforeWithdraw[0].toString()).to.not.be.equal("0");
|
|
236
|
-
expect(currentUBIInterestAfterWithdraw[0].toString()).to.be.equal("0");
|
|
237
|
-
expect(gdBalanceAfterCollectInterest.gt(gdBalanceBeforeCollectInterest));
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it("it should not collect stkAAVE when collecting interest", async () => {
|
|
241
|
-
const stakingAmount = ethers.utils.parseUnits("100", 6);
|
|
242
|
-
await goodAaveStaking.stake(stakingAmount, "0", false);
|
|
243
|
-
const currentGainsAfterStake = await goodAaveStaking.currentGains(
|
|
244
|
-
false,
|
|
245
|
-
true
|
|
246
|
-
);
|
|
247
|
-
await incentiveController.increaseRewardsBalance(
|
|
248
|
-
goodAaveStaking.address,
|
|
249
|
-
ethers.utils.parseEther("10")
|
|
250
|
-
);
|
|
251
|
-
const currentGainsAfterEarnRewards = await goodAaveStaking.currentGains(
|
|
252
|
-
false,
|
|
253
|
-
true
|
|
254
|
-
);
|
|
255
|
-
await lendingPool.giveInterestToUser(2000, goodAaveStaking.address);
|
|
256
|
-
const currentGainsAfterGetInterest = await goodAaveStaking.currentGains(
|
|
257
|
-
false,
|
|
258
|
-
true
|
|
259
|
-
);
|
|
260
|
-
const contractAddressesToBeCollected = await goodFundManager
|
|
261
|
-
.connect(staker)
|
|
262
|
-
.calcSortedContracts();
|
|
263
|
-
const addressesToCollect = contractAddressesToBeCollected.map(x => x[0]);
|
|
264
|
-
await goodFundManager.collectInterest(addressesToCollect, false, {
|
|
265
|
-
gasLimit: 1200000
|
|
266
|
-
});
|
|
267
|
-
const currentGainsAfterCollectInterest = await goodAaveStaking.currentGains(
|
|
268
|
-
false,
|
|
269
|
-
true
|
|
270
|
-
);
|
|
271
|
-
await goodAaveStaking.withdrawStake(stakingAmount, false);
|
|
272
|
-
expect(currentGainsAfterStake[4]).to.be.equal("0");
|
|
273
|
-
expect(currentGainsAfterGetInterest[4]).to.be.gt(
|
|
274
|
-
currentGainsAfterEarnRewards[4]
|
|
275
|
-
);
|
|
276
|
-
expect(currentGainsAfterEarnRewards[4]).to.be.equal(0); // stkAAVE rewards shouldnt count as gain
|
|
277
|
-
expect(currentGainsAfterCollectInterest[4]).to.be.equal("0");
|
|
278
|
-
expect(await aave.balanceOf(avatar)).gt(0);
|
|
279
|
-
});
|
|
280
|
-
async function addLiquidity(
|
|
281
|
-
token0: Contract,
|
|
282
|
-
token1: Contract,
|
|
283
|
-
pair: Contract,
|
|
284
|
-
token0Amount: BigNumber,
|
|
285
|
-
token1Amount: BigNumber
|
|
286
|
-
) {
|
|
287
|
-
await token0.transfer(pair.address, token0Amount);
|
|
288
|
-
await token1.transfer(pair.address, token1Amount);
|
|
289
|
-
await pair.mint(founder.address);
|
|
290
|
-
}
|
|
291
|
-
});
|