@gooddollar/goodprotocol 1.0.18 → 1.0.19-beta.2
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/abis/GReputation.min.json +1 -1
- package/artifacts/abis/GoodAaveStaking.min.json +1 -1
- package/artifacts/abis/GoodAaveStakingV2.min.json +1 -1
- package/artifacts/abis/GoodCompoundStaking.min.json +1 -1
- package/artifacts/abis/GoodCompoundStakingTest.min.json +1 -1
- package/artifacts/abis/GoodCompoundStakingV2.min.json +1 -1
- package/artifacts/abis/UpgradableMock3.min.json +1 -0
- package/artifacts/abis/UpgradableMock4.min.json +1 -0
- 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 +15 -2
- package/artifacts/contracts/governance/GovernanceStaking.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 +2 -2
- 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/AaveUSDMockOracle.sol/AaveUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/BatUSDMockOracle.sol/BatUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/CompUsdMockOracle.sol/CompUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/DAIMock.sol/DAIMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DaiEthPriceMockOracle.sol/DaiEthPriceMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/DecimalsMock.sol/DecimalsMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/EthUSDMockOracle.sol/EthUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/GasPriceMockOracle.sol/GasPriceMockOracle.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/UpgradableMock.json +2 -2
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock2.json +2 -2
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.dbg.json +4 -0
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock3.json +172 -0
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.dbg.json +4 -0
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.json +172 -0
- 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/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/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 +2 -2
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStaking.sol/GoodAaveStaking.json +3 -3
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.json +3 -3
- 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/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.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/utils/BancorFormula.sol/BancorFormula.dbg.json +1 -1
- package/artifacts/contracts/utils/BulkProof.sol/BulkProof.dbg.json +1 -1
- package/artifacts/contracts/utils/BulkProof.sol/BulkProof.json +2 -2
- 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/MultiCall.sol/Multicall.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/ProtocolUpgradeFuseRecover.sol/ProtocolUpgradeFuseRecover.dbg.json +1 -1
- package/artifacts/contracts/utils/ProtocolUpgradeRecover.sol/ProtocolUpgradeRecover.dbg.json +1 -1
- package/artifacts/contracts/utils/ProxyFactory1967.sol/ERC1967Proxy.dbg.json +1 -1
- package/artifacts/contracts/utils/ProxyFactory1967.sol/ProxyFactory1967.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 +8 -0
- package/contracts/governance/Reputation.sol +5 -3
- package/contracts/mocks/UpgradableMocks.sol +18 -0
- package/contracts/staking/SimpleStaking.sol +2 -1
- package/contracts/staking/SimpleStakingV2.sol +2 -1
- package/hardhat.config.ts +63 -8
- package/package.json +7 -5
- package/releases/deployment.json +11 -0
- package/scripts/multichain-deploy/basicdao-deploy.ts +256 -0
- package/scripts/multichain-deploy/helpers.ts +96 -0
- package/test/governance/ClaimersDistribution.test.ts +6 -6
- package/test/governance/CompoundVotingMachine.daoscheme.ts +14 -1
- package/test/governance/CompoundVotingMachine.guardian.test.ts +11 -1
- package/test/governance/GReputation.test.ts +32 -1
- package/test/governance/StakersDistribution.test.ts +62 -1
- package/test/helpers.ts +15 -0
- package/test/reserve/GoodMarketMaker.test.ts +11 -0
- package/test/reserve/GoodReserveCDai.gdx.test.ts +23 -8
- package/test/reserve/GoodReserveCDai.test.ts +37 -2
- package/test/staking/CompoundStakingFactory.test.ts +31 -0
- package/test/staking/DonationsStaking.test.ts +99 -2
- package/test/staking/GoodAaveStakingFactory.test.ts +36 -1
- package/test/staking/SimpleDAIStaking.test.ts +52 -2
- package/test/staking/StakingRewards.test.ts +38 -0
- package/test/staking/UsdcAaveStaking.test.ts +45 -19
- package/test/ubi/UBIScheme.test.ts +68 -0
- package/test/utils/DAOUpgradeableContract.test.ts +47 -0
- package/test/utils/NameService.test.ts +50 -55
- package/test/utils/ProxyFactory.test.ts +17 -0
- package/yarn.lock +607 -119
- package/artifacts/abis/FuseFaucet.min.json +0 -1
- package/artifacts/abis/InvitesV1.min.json +0 -1
- package/artifacts/contracts/unaudited-foundation/FuseFaucet.sol/FuseFaucet.dbg.json +0 -4
- package/artifacts/contracts/unaudited-foundation/FuseFaucet.sol/FuseFaucet.json +0 -200
- package/artifacts/contracts/unaudited-foundation/InvitesV1.sol/InvitesV1.dbg.json +0 -4
- package/artifacts/contracts/unaudited-foundation/InvitesV1.sol/InvitesV1.json +0 -486
- package/contracts/unaudited-foundation/FuseFaucet.sol +0 -120
- package/contracts/unaudited-foundation/InvitesV1.sol +0 -304
|
@@ -8,6 +8,7 @@ export const NULL_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
|
8
8
|
|
|
9
9
|
const MAX_INACTIVE_DAYS = 3;
|
|
10
10
|
const ONE_DAY = 86400;
|
|
11
|
+
const ONE_HOUR = 3600;
|
|
11
12
|
|
|
12
13
|
describe("UBIScheme", () => {
|
|
13
14
|
let goodDollar,
|
|
@@ -28,6 +29,7 @@ describe("UBIScheme", () => {
|
|
|
28
29
|
claimer5,
|
|
29
30
|
claimer6,
|
|
30
31
|
claimer7,
|
|
32
|
+
claimer8,
|
|
31
33
|
signers,
|
|
32
34
|
fisherman,
|
|
33
35
|
nameService,
|
|
@@ -44,6 +46,7 @@ describe("UBIScheme", () => {
|
|
|
44
46
|
claimer5,
|
|
45
47
|
claimer6,
|
|
46
48
|
claimer7,
|
|
49
|
+
claimer8,
|
|
47
50
|
fisherman,
|
|
48
51
|
...signers
|
|
49
52
|
] = await ethers.getSigners();
|
|
@@ -83,6 +86,13 @@ describe("UBIScheme", () => {
|
|
|
83
86
|
// await increaseTime(60 * 60 * 24);
|
|
84
87
|
});
|
|
85
88
|
|
|
89
|
+
async function deployNewUbi() {
|
|
90
|
+
return await upgrades.deployProxy(
|
|
91
|
+
await ethers.getContractFactory("UBIScheme"),
|
|
92
|
+
[nameService.address, firstClaimPool.address, 14]
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
86
96
|
it("should not accept 0 inactive days in the constructor", async () => {
|
|
87
97
|
let ubi1 = await (await ethers.getContractFactory("UBIScheme")).deploy();
|
|
88
98
|
|
|
@@ -115,6 +125,22 @@ describe("UBIScheme", () => {
|
|
|
115
125
|
expect(error.message).to.have.string("only Avatar");
|
|
116
126
|
});
|
|
117
127
|
|
|
128
|
+
it("should return zero entitlement before UBI started", async () => {
|
|
129
|
+
let blockTimestamp = (await ethers.provider.getBlock("latest")).timestamp;
|
|
130
|
+
const timeInDay = (blockTimestamp % (ONE_DAY));
|
|
131
|
+
// Move to before 12pm of the current day
|
|
132
|
+
if (timeInDay > 12 * ONE_HOUR) {
|
|
133
|
+
blockTimestamp += 12 * ONE_HOUR;
|
|
134
|
+
await ethers.provider.send("evm_setNextBlockTimestamp", [
|
|
135
|
+
blockTimestamp
|
|
136
|
+
]);
|
|
137
|
+
await ethers.provider.send("evm_mine", []);
|
|
138
|
+
}
|
|
139
|
+
const ubiNew = await deployNewUbi();
|
|
140
|
+
let amount = await ubiNew.connect(claimer1)["checkEntitlement()"]();
|
|
141
|
+
expect(amount).to.equal(0);
|
|
142
|
+
});
|
|
143
|
+
|
|
118
144
|
it("should start the ubi", async () => {
|
|
119
145
|
await setSchemes([ubi.address]);
|
|
120
146
|
// await ubi.start();
|
|
@@ -174,6 +200,27 @@ describe("UBIScheme", () => {
|
|
|
174
200
|
expect(error.message).to.have.string("Only UBIScheme can call this method");
|
|
175
201
|
});
|
|
176
202
|
|
|
203
|
+
it("should estimate next daily UBI to default value when no claimers and not using first claim pool", async () => {
|
|
204
|
+
const nextDailyUBIBefore = await ubi.estimateNextDailyUBI();
|
|
205
|
+
const defaultDailyUbi = await ubi.defaultDailyUbi();
|
|
206
|
+
let encodedCall = ubi.interface.encodeFunctionData(
|
|
207
|
+
"setUseFirstClaimPool",
|
|
208
|
+
[false]
|
|
209
|
+
);
|
|
210
|
+
await genericCall(ubi.address, encodedCall);
|
|
211
|
+
const nextDailyUBIAfter = await ubi.estimateNextDailyUBI();
|
|
212
|
+
|
|
213
|
+
expect(nextDailyUBIBefore.eq(0));
|
|
214
|
+
expect(nextDailyUBIAfter.gt(nextDailyUBIBefore));
|
|
215
|
+
expect(nextDailyUBIAfter.eq(defaultDailyUbi));
|
|
216
|
+
|
|
217
|
+
encodedCall = ubi.interface.encodeFunctionData(
|
|
218
|
+
"setUseFirstClaimPool",
|
|
219
|
+
[true]
|
|
220
|
+
);
|
|
221
|
+
await genericCall(ubi.address, encodedCall);
|
|
222
|
+
});
|
|
223
|
+
|
|
177
224
|
it("should award a new user with 0 on first time execute claim if the first claim contract has no balance", async () => {
|
|
178
225
|
let tx = await (await ubi.connect(claimer1).claim()).wait();
|
|
179
226
|
let claimer1Balance = await goodDollar.balanceOf(claimer1.address);
|
|
@@ -189,8 +236,11 @@ describe("UBIScheme", () => {
|
|
|
189
236
|
let transaction = await (await ubi.connect(claimer2).claim()).wait();
|
|
190
237
|
let activeUsersCount = await ubi.activeUsersCount();
|
|
191
238
|
let claimer2Balance = await goodDollar.balanceOf(claimer2.address);
|
|
239
|
+
const [claimersCount, amountClaimed] = await ubi.getDailyStats();
|
|
192
240
|
expect(claimer2Balance.toNumber()).to.be.equal(100);
|
|
241
|
+
expect(amountClaimed.eq(100));
|
|
193
242
|
expect(activeUsersCount.toNumber()).to.be.equal(2);
|
|
243
|
+
expect(claimersCount.eq(2));
|
|
194
244
|
expect(transaction.events.find(_ => _.event === "ActivatedUser")).to.be.not
|
|
195
245
|
.empty;
|
|
196
246
|
});
|
|
@@ -574,4 +624,22 @@ describe("UBIScheme", () => {
|
|
|
574
624
|
const shouldWithdrawFromDAO = await ubi.shouldWithdrawFromDAO();
|
|
575
625
|
expect(shouldWithdrawFromDAO).to.be.equal(false);
|
|
576
626
|
});
|
|
627
|
+
|
|
628
|
+
it("should award first claimer with default value when not using first claim pool", async () => {
|
|
629
|
+
const ubiNew = await deployNewUbi();
|
|
630
|
+
const defaultDailyUbi = await ubiNew.defaultDailyUbi();
|
|
631
|
+
await goodDollar.mint(ubiNew.address, defaultDailyUbi);
|
|
632
|
+
await addWhitelisted(claimer8.address, "claimer8");
|
|
633
|
+
const encodedCall = ubiNew.interface.encodeFunctionData(
|
|
634
|
+
"setUseFirstClaimPool",
|
|
635
|
+
[false]
|
|
636
|
+
);
|
|
637
|
+
await genericCall(ubiNew.address, encodedCall);
|
|
638
|
+
const claimerBalanceBefore = await goodDollar.balanceOf(claimer8.address);
|
|
639
|
+
await (await ubiNew.connect(claimer8).claim()).wait();
|
|
640
|
+
const claimerBalanceAfter = await goodDollar.balanceOf(claimer8.address);
|
|
641
|
+
|
|
642
|
+
expect(claimerBalanceAfter.gt(claimerBalanceBefore));
|
|
643
|
+
expect(claimerBalanceAfter.sub(claimerBalanceBefore).eq(defaultDailyUbi));
|
|
644
|
+
});
|
|
577
645
|
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { ethers, upgrades } from "hardhat";
|
|
3
|
+
import { createDAO } from "../helpers";
|
|
4
|
+
|
|
5
|
+
describe("DAOUpgradeableContract", () => {
|
|
6
|
+
let signers, avatar, genericCall, controller, nameService;
|
|
7
|
+
before(async () => {
|
|
8
|
+
signers = await ethers.getSigners();
|
|
9
|
+
|
|
10
|
+
let {
|
|
11
|
+
controller: ctrl,
|
|
12
|
+
avatar: av,
|
|
13
|
+
genericCall: gc,
|
|
14
|
+
nameService: ns
|
|
15
|
+
} = await createDAO();
|
|
16
|
+
|
|
17
|
+
avatar = av;
|
|
18
|
+
genericCall = gc;
|
|
19
|
+
controller = ctrl;
|
|
20
|
+
nameService = ns;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should be able to authorize upgrade for dao upgradable contract", async () => {
|
|
24
|
+
const upgradableMockFactory = await ethers.getContractFactory(
|
|
25
|
+
"UpgradableMock3"
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const daoUpgradableProxy = await upgrades.deployProxy(
|
|
29
|
+
upgradableMockFactory,
|
|
30
|
+
[nameService.address],
|
|
31
|
+
{ kind: "uups" }
|
|
32
|
+
);
|
|
33
|
+
const differentUpgradableMock = await (
|
|
34
|
+
await ethers.getContractFactory("UpgradableMock4")
|
|
35
|
+
).deploy();
|
|
36
|
+
const secondContractDecimals = await differentUpgradableMock.decimals();
|
|
37
|
+
const decimalsBeforeUpgrade = await daoUpgradableProxy.decimals();
|
|
38
|
+
const encodedData = daoUpgradableProxy.interface.encodeFunctionData(
|
|
39
|
+
"upgradeTo",
|
|
40
|
+
[differentUpgradableMock.address]
|
|
41
|
+
);
|
|
42
|
+
await (await genericCall(daoUpgradableProxy.address, encodedData)).wait();
|
|
43
|
+
const decimalsAfterUpgrade = await daoUpgradableProxy.decimals();
|
|
44
|
+
expect(decimalsBeforeUpgrade).to.not.eq(decimalsAfterUpgrade);
|
|
45
|
+
expect(decimalsAfterUpgrade).to.eq(secondContractDecimals);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -1,27 +1,15 @@
|
|
|
1
|
-
import { default as hre, ethers, upgrades } from "hardhat";
|
|
2
|
-
import { BigNumber, Contract, Signer } from "ethers";
|
|
3
|
-
import { deployMockContract, MockContract } from "ethereum-waffle";
|
|
4
1
|
import { expect } from "chai";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
GoodReserveCDai,
|
|
9
|
-
UniswapFactory
|
|
10
|
-
} from "../../types";
|
|
11
|
-
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/dist/src/signer-with-address";
|
|
12
|
-
import { createDAO, increaseTime, advanceBlocks } from "../helpers";
|
|
13
|
-
import ContributionCalculation from "@gooddollar/goodcontracts/stakingModel/build/contracts/ContributionCalculation.json";
|
|
14
|
-
import { parseUnits } from "@ethersproject/units";
|
|
15
|
-
import ERC20 from "@uniswap/v2-core/build/ERC20.json";
|
|
16
|
-
import WETH9 from "@uniswap/v2-periphery/build/WETH9.json";
|
|
17
|
-
import UniswapV2Router02 from "@uniswap/v2-periphery/build/UniswapV2Router02.json";
|
|
2
|
+
import { ethers, upgrades, network } from 'hardhat';
|
|
3
|
+
import { createDAO } from "../helpers";
|
|
4
|
+
import { getImplementationAddress } from "@openzeppelin/upgrades-core";
|
|
18
5
|
|
|
19
6
|
const BN = ethers.BigNumber;
|
|
20
7
|
export const NULL_ADDRESS = ethers.constants.AddressZero;
|
|
21
8
|
export const BLOCK_INTERVAL = 1;
|
|
22
9
|
|
|
23
10
|
describe("NameService - Setup and functionalities", () => {
|
|
24
|
-
let nameService, dai, avatar, controller, schemeMock, signers
|
|
11
|
+
let nameService, dai, avatar, controller, schemeMock, signers, genericCall,
|
|
12
|
+
runAsAvatarOnly;
|
|
25
13
|
|
|
26
14
|
before(async () => {
|
|
27
15
|
signers = await ethers.getSigners();
|
|
@@ -39,12 +27,16 @@ describe("NameService - Setup and functionalities", () => {
|
|
|
39
27
|
nameService: ns,
|
|
40
28
|
setDAOAddress: sda,
|
|
41
29
|
setSchemes,
|
|
42
|
-
marketMaker: mm
|
|
30
|
+
marketMaker: mm,
|
|
31
|
+
genericCall: gc,
|
|
32
|
+
runAsAvatarOnly: raao,
|
|
43
33
|
} = await createDAO();
|
|
44
34
|
|
|
45
35
|
controller = ctrl;
|
|
46
36
|
avatar = av;
|
|
47
37
|
nameService = ns;
|
|
38
|
+
genericCall = gc;
|
|
39
|
+
runAsAvatarOnly = raao;
|
|
48
40
|
console.log("deployed dao", {
|
|
49
41
|
gd,
|
|
50
42
|
identity,
|
|
@@ -55,61 +47,64 @@ describe("NameService - Setup and functionalities", () => {
|
|
|
55
47
|
await setSchemes([schemeMock.address]);
|
|
56
48
|
});
|
|
57
49
|
|
|
58
|
-
it(" address should not be set ", async () => {
|
|
59
|
-
await expect(nameService.setAddress("DAI", dai.address)).to.be.revertedWith(
|
|
60
|
-
"only avatar can call this method"
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it(" addresses should not be set ", async () => {
|
|
65
|
-
await expect(
|
|
66
|
-
nameService.setAddresses(
|
|
67
|
-
[
|
|
68
|
-
ethers.utils.formatBytes32String("DAI"),
|
|
69
|
-
ethers.utils.formatBytes32String("cDAI")
|
|
70
|
-
],
|
|
71
|
-
[(signers[0].address, signers[1].address)]
|
|
72
|
-
)
|
|
73
|
-
).to.be.revertedWith("only avatar can call this method");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
50
|
it("should set address by avatar", async () => {
|
|
77
|
-
|
|
78
|
-
|
|
51
|
+
await runAsAvatarOnly(
|
|
52
|
+
nameService,
|
|
53
|
+
"setAddress(string,address)",
|
|
79
54
|
"DAI",
|
|
80
55
|
dai.address
|
|
81
|
-
]);
|
|
82
|
-
|
|
83
|
-
const ictrl = await ethers.getContractAt(
|
|
84
|
-
"Controller",
|
|
85
|
-
controller,
|
|
86
|
-
schemeMock
|
|
87
56
|
);
|
|
88
|
-
|
|
89
|
-
await ictrl.genericCall(nameService.address, encoded, avatar, 0);
|
|
90
57
|
expect(await nameService.getAddress("DAI")).to.be.equal(dai.address);
|
|
91
58
|
});
|
|
92
59
|
|
|
93
60
|
it("should set multiple addresses by avatar", async () => {
|
|
94
|
-
|
|
95
|
-
|
|
61
|
+
await runAsAvatarOnly(
|
|
62
|
+
nameService,
|
|
63
|
+
"setAddresses(bytes32[],address[])",
|
|
96
64
|
[
|
|
97
65
|
ethers.utils.keccak256(ethers.utils.toUtf8Bytes("DAI")),
|
|
98
66
|
ethers.utils.keccak256(ethers.utils.toUtf8Bytes("cDAI"))
|
|
99
67
|
],
|
|
100
68
|
[signers[0].address, signers[1].address]
|
|
101
|
-
]);
|
|
102
|
-
|
|
103
|
-
const ictrl = await ethers.getContractAt(
|
|
104
|
-
"Controller",
|
|
105
|
-
controller,
|
|
106
|
-
schemeMock
|
|
107
69
|
);
|
|
108
70
|
|
|
109
|
-
await ictrl.genericCall(nameService.address, encoded, avatar, 0);
|
|
110
71
|
expect(await nameService.getAddress("DAI")).to.be.equal(signers[0].address);
|
|
111
72
|
expect(await nameService.getAddress("cDAI")).to.be.equal(
|
|
112
73
|
signers[1].address
|
|
113
74
|
);
|
|
114
75
|
});
|
|
76
|
+
|
|
77
|
+
it("should authorize upgrade only for avatar", async () => {
|
|
78
|
+
const nameServiceProxy = await upgrades.deployProxy(
|
|
79
|
+
await ethers.getContractFactory("NameService"),
|
|
80
|
+
[
|
|
81
|
+
controller,
|
|
82
|
+
[
|
|
83
|
+
"CONTROLLER",
|
|
84
|
+
].map(_ => ethers.utils.keccak256(ethers.utils.toUtf8Bytes(_))),
|
|
85
|
+
[
|
|
86
|
+
controller
|
|
87
|
+
]
|
|
88
|
+
],
|
|
89
|
+
{
|
|
90
|
+
kind: "uups"
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
const implementationBeforeUpgrade =
|
|
94
|
+
await getImplementationAddress(network.provider, nameServiceProxy.address);
|
|
95
|
+
const newNameServiceLogic = await (await ethers.getContractFactory("NameService")).deploy();
|
|
96
|
+
const encodedData = nameServiceProxy.interface.encodeFunctionData(
|
|
97
|
+
"upgradeTo",
|
|
98
|
+
[newNameServiceLogic.address]
|
|
99
|
+
);
|
|
100
|
+
await (await genericCall(nameServiceProxy.address, encodedData)).wait();
|
|
101
|
+
const implementationAfterUpgrade =
|
|
102
|
+
await getImplementationAddress(network.provider, nameServiceProxy.address);
|
|
103
|
+
expect(implementationBeforeUpgrade).to.not.equal(implementationAfterUpgrade);
|
|
104
|
+
expect(implementationAfterUpgrade).to.equal(newNameServiceLogic.address);
|
|
105
|
+
|
|
106
|
+
const newNameServiceLogic2 = await (await ethers.getContractFactory("NameService")).deploy();
|
|
107
|
+
await expect(nameServiceProxy.upgradeTo(newNameServiceLogic2.address)).
|
|
108
|
+
to.be.revertedWith("only avatar can call this method");
|
|
109
|
+
});
|
|
115
110
|
});
|
|
@@ -130,4 +130,21 @@ describe("proxyfactory", () => {
|
|
|
130
130
|
let orgproxy = await ethers.getContractAt("UpgradableMock", proxyAddr);
|
|
131
131
|
expect(await orgproxy.owner()).to.eq(signers[2].address);
|
|
132
132
|
});
|
|
133
|
+
|
|
134
|
+
it("should use deploy minimal to deploy proxy with impl and initialize it", async () => {
|
|
135
|
+
const c1 = await (
|
|
136
|
+
await ethers.getContractFactory("UpgradableMock")
|
|
137
|
+
).deploy();
|
|
138
|
+
|
|
139
|
+
const encoded = c1.interface.encodeFunctionData("initialize", [
|
|
140
|
+
signers[2].address
|
|
141
|
+
]);
|
|
142
|
+
const deployTX = await (
|
|
143
|
+
await factory.deployMinimal(c1.address, encoded)
|
|
144
|
+
).wait();
|
|
145
|
+
const proxyAddr = deployTX.events.find(_ => _.event === "ProxyCreated").args
|
|
146
|
+
.proxy;
|
|
147
|
+
proxy = await ethers.getContractAt("UpgradableMock", proxyAddr);
|
|
148
|
+
expect(await proxy.owner()).to.eq(signers[2].address);
|
|
149
|
+
});
|
|
133
150
|
});
|