@gooddollar/goodprotocol 1.0.7-beta.2 → 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.
- 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/ClaimersDistribution.sol/ClaimersDistribution.json +2 -2
- 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/GReputation.sol/GReputation.json +62 -4
- 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/Reputation.sol/Reputation.json +17 -17
- 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 +4 -0
- package/artifacts/contracts/staking/BaseShareFieldV2.sol/BaseShareFieldV2.json +256 -0
- 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 +4 -0
- package/artifacts/contracts/staking/SimpleStakingV2.sol/SimpleStakingV2.json +1033 -0
- 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 +3 -3
- package/artifacts/contracts/staking/aave/AaveStakingFactoryV2.sol/AaveStakingFactoryV2.dbg.json +4 -0
- package/artifacts/contracts/staking/aave/AaveStakingFactoryV2.sol/AaveStakingFactoryV2.json +148 -0
- 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 +4 -0
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +1224 -0
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.json +2 -2
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.json +4 -4
- package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
- package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.json +2 -2
- 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/artifacts/contracts/utils/ReputationTestHelper.sol/ReputationTestHelper.json +2 -2
- package/contracts/governance/GReputation.sol +53 -14
- package/contracts/governance/Reputation.sol +13 -25
- package/contracts/staking/BaseShareFieldV2.sol +319 -0
- package/contracts/staking/SimpleStakingV2.sol +522 -0
- package/contracts/staking/aave/AaveStakingFactoryV2.sol +93 -0
- package/contracts/staking/aave/GoodAaveStaking.sol +4 -3
- package/contracts/staking/aave/GoodAaveStakingV2.sol +263 -0
- package/contracts/staking/compound/GoodCompoundStaking.sol +4 -3
- package/contracts/ubi/UBIScheme.sol +2 -2
- package/package.json +1 -1
- package/releases/deployment.json +108 -97
- package/releases/olddao.json +1 -406
- package/scripts/deployFullDAO.ts +7 -7
- package/scripts/misc/goodgiveback.ts +64 -0
- package/scripts/verify.ts +60 -47
- package/test/governance/ClaimersDistribution.test.ts +5 -5
- package/test/governance/CompoundVotingMachine.castvote.test.ts +1 -1
- package/test/governance/CompoundVotingMachine.daoscheme.ts +1 -1
- package/test/governance/CompoundVotingMachine.guardian.test.ts +1 -1
- package/test/governance/GReputation.test.ts +49 -18
- package/test/governance/GovernanceStaking.test.ts +71 -47
- package/test/governance/Reputation.test.ts +52 -51
- package/test/governance/StakersDistribution.test.ts +12 -8
- package/test/helpers.ts +5 -1
- package/test/staking/GoodAaveStakingFactoryV2.test.ts +122 -0
- package/test/staking/UsdcAaveStaking.test.ts +5 -1
- package/test/staking/UsdcAaveStakingV2.test.ts +291 -0
- package/truffle-config.js +12 -0
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:
|
|
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,
|
|
@@ -0,0 +1,291 @@
|
|
|
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
|
+
});
|
package/truffle-config.js
CHANGED
|
@@ -70,6 +70,18 @@ module.exports = {
|
|
|
70
70
|
timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
|
|
71
71
|
skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
|
|
72
72
|
},
|
|
73
|
+
ropsten: {
|
|
74
|
+
provider: () =>
|
|
75
|
+
new HDWalletProvider(
|
|
76
|
+
mnemonic,
|
|
77
|
+
`https://ropsten.infura.io/v3/YOUR-PROJECT-ID`
|
|
78
|
+
),
|
|
79
|
+
network_id: 3, // Ropsten's id
|
|
80
|
+
gas: 5000000, // Ropsten has a lower block limit than mainnet
|
|
81
|
+
confirmations: 2, // # of confs to wait between deployments. (default: 0)
|
|
82
|
+
timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
|
|
83
|
+
skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
|
|
84
|
+
},
|
|
73
85
|
fuse: {
|
|
74
86
|
provider: () => new HDWalletProvider(mnemonic, `https://rpc.fuse.io`),
|
|
75
87
|
network_id: 122, // Ropsten's id
|