@gooddollar/goodprotocol 2.0.21 → 2.0.22-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/abis/ISuperToken.min.json +1 -1
- package/artifacts/abis/SuperGoodDollar.min.json +1 -1
- package/artifacts/abis/SuperToken.min.json +1 -1
- 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/IIdentityV2.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/ILendingPool.dbg.json +1 -1
- package/artifacts/contracts/Interfaces.sol/IMultichainRouter.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/fuseFaucet/Faucet.sol/Faucet.dbg.json +1 -1
- package/artifacts/contracts/fuseFaucet/FuseFaucet.sol/FuseFaucet.dbg.json +1 -1
- package/artifacts/contracts/fuseFaucet/FuseFaucetV2.sol/FuseFaucetV2.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/GoodDollarStaking.sol/GoodDollarStaking.dbg.json +1 -1
- package/artifacts/contracts/governance/GoodDollarStaking.sol/IGovernanceStaking.dbg.json +1 -1
- package/artifacts/contracts/governance/GoodDollarStaking.sol/IStakingUpgrade.dbg.json +1 -1
- package/artifacts/contracts/governance/GoodDollarStaking.sol/RewardsMinter.dbg.json +1 -1
- 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/StakersDistribution.sol/StakersDistribution.dbg.json +1 -1
- package/artifacts/contracts/identity/IdentityV2.sol/IdentityV2.dbg.json +1 -1
- package/artifacts/contracts/invite/InvitesFuseV2.sol/InvitesFuseV2.dbg.json +1 -1
- package/artifacts/contracts/invite/InvitesV1.sol/InvitesV1.dbg.json +1 -1
- package/artifacts/contracts/invite/InvitesV2.sol/InvitesV2.dbg.json +1 -1
- 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/DistributionBridgeMock.sol/DistributionBridgeMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/DistributionHelperTest.sol/DistributionHelperTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/DistributionHelperTest.sol/DistributionHelperTestHelper.dbg.json +1 -1
- package/artifacts/contracts/mocks/EthUSDMockOracle.sol/EthUSDMockOracle.dbg.json +1 -1
- package/artifacts/contracts/mocks/FeesFormularMock.sol/FeesFormulaMock.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/GoodDollarStakingMock.sol/GoodDollarStakingMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/GoodFundManagerTest.sol/GoodFundManagerTest.dbg.json +1 -1
- package/artifacts/contracts/mocks/IdentityMock.sol/IdentityMock.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/MultichainRouterMock.sol/IWrapper.dbg.json +1 -1
- package/artifacts/contracts/mocks/MultichainRouterMock.sol/MultichainRouterMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/OverMintTester.sol/IGoodDollarStakingTest.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/PayableMock.sol/PayableMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/SixteenDecimalsTokenMock.sol/SixteenDecimalsTokenMock.dbg.json +1 -1
- package/artifacts/contracts/mocks/StakingMockFixedAPY.sol/StakingMockFixedAPY.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/UpgradableMocks.sol/UpgradableMock3.dbg.json +1 -1
- package/artifacts/contracts/mocks/UpgradableMocks.sol/UpgradableMock4.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/DistributionHelper.sol/DistributionHelper.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/FuseStakingV3.sol/FuseStakingV3.dbg.json +1 -1
- package/artifacts/contracts/staking/FuseStakingV3.sol/IConsensus.dbg.json +1 -1
- package/artifacts/contracts/staking/FuseStakingV3.sol/PegSwap.dbg.json +1 -1
- 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/GoodAaveStaking.sol/GoodAaveStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/aave/GoodAaveStakingV2.sol/GoodAaveStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/CompoundStakingFactory.sol/CompoundStakingFactory.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStaking.sol/GoodCompoundStaking.dbg.json +1 -1
- package/artifacts/contracts/staking/compound/GoodCompoundStakingV2.sol/GoodCompoundStakingV2.dbg.json +1 -1
- package/artifacts/contracts/staking/utils/Math64X64.sol/Math64x64.dbg.json +1 -1
- package/artifacts/contracts/staking/utils/StakingRewardsFixedAPY.sol/StakingRewardsFixedAPY.dbg.json +1 -1
- package/artifacts/contracts/token/ERC20PresetMinterPauserUpgradeable.sol/ERC20PresetMinterPauserUpgradeable.dbg.json +1 -1
- package/artifacts/contracts/token/ERC677.sol/ERC677.dbg.json +1 -1
- package/artifacts/contracts/token/ERC677.sol/ERC677Receiver.dbg.json +1 -1
- package/artifacts/contracts/token/GoodDollar.sol/GoodDollar.dbg.json +1 -1
- package/artifacts/contracts/token/IFeesFormula.sol/IFeesFormula.dbg.json +1 -1
- package/artifacts/contracts/token/MultichainFeeFormula.sol/MultichainFeeFormula.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/ERC20Permit.sol/ERC20Permit.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/ERC20Permit.sol/SelfApprove.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/ISuperGoodDollar.sol/IGoodDollarCustom.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/ISuperGoodDollar.sol/ISuperGoodDollar.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/ISuperToken.sol/ISuperToken.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/ISuperToken.sol/ISuperToken.json +5 -0
- package/artifacts/contracts/token/superfluid/SuperGoodDollar.sol/SuperGoodDollar.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/SuperGoodDollar.sol/SuperGoodDollar.json +25 -2
- package/artifacts/contracts/token/superfluid/SuperToken.sol/SuperToken.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/SuperToken.sol/SuperToken.json +7 -2
- package/artifacts/contracts/token/superfluid/SuperfluidToken.sol/SuperfluidToken.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/UUPSProxiable.sol/UUPSProxiable.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/UUPSProxy.sol/Proxy.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/UUPSProxy.sol/UUPSProxy.dbg.json +1 -1
- package/artifacts/contracts/token/superfluid/UUPSProxy.sol/UUPSUtils.dbg.json +1 -1
- package/artifacts/contracts/ubi/UBIScheme.sol/UBIScheme.dbg.json +1 -1
- package/artifacts/contracts/ubi/UBISchemeV2.sol/UBISchemeV2.dbg.json +1 -1
- package/artifacts/contracts/utils/AdminWallet.sol/AdminWallet.dbg.json +1 -1
- package/artifacts/contracts/utils/AdminWalletFuse.sol/AdminWalletFuse.dbg.json +1 -1
- 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/BuyAndBridgeHelper.sol/BuyAndBridgeHelper.dbg.json +1 -1
- package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDClone.dbg.json +1 -1
- package/artifacts/contracts/utils/BuyGDClone.sol/BuyGDCloneFactory.dbg.json +1 -1
- package/artifacts/contracts/utils/BuyGDClone.sol/DonateGDClone.dbg.json +1 -1
- package/artifacts/contracts/utils/BuyGDClone.sol/IQuoterV2.dbg.json +1 -1
- package/artifacts/contracts/utils/BuyGDClone.sol/ISwapRouter.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/GDFaucet.sol/GDFaucet.dbg.json +1 -1
- package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/GoodDollarMintBurnWrapper.dbg.json +1 -1
- package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/IRouter.dbg.json +1 -1
- package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/PausableControl.dbg.json +1 -1
- package/artifacts/contracts/utils/GoodDollarMintBurnWrapper.sol/TokenOperation.dbg.json +1 -1
- package/artifacts/contracts/utils/IdentityFix.sol/IdentityFix.dbg.json +1 -1
- package/artifacts/contracts/utils/MultiCall.sol/Multicall.dbg.json +1 -1
- package/artifacts/contracts/utils/MultichainBridgeHelper.sol/MultichainBridgeHelper.dbg.json +1 -1
- package/artifacts/contracts/utils/NameService.sol/NameService.dbg.json +1 -1
- package/artifacts/contracts/utils/OneTimePayments.sol/OneTimePayments.dbg.json +1 -1
- package/artifacts/contracts/utils/OneTimePaymentsV2.sol/OneTimePaymentsV2.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/contracts/token/superfluid/ISuperToken.sol +1 -0
- package/contracts/token/superfluid/SuperGoodDollar.sol +11 -2
- package/contracts/token/superfluid/SuperToken.sol +8 -0
- package/dist/artifacts/contracts/token/superfluid/SuperGoodDollar.sol/SuperGoodDollar.json +25 -2
- package/hardhat.config.ts +1 -1
- package/package.json +4 -3
- package/scripts/blockchainTestSetup.sh +1 -1
- package/test/faucet/Faucet.test.ts +63 -19
- package/test/faucet/FuseFaucet.test.ts +43 -14
- package/test/governance/ClaimersDistribution.test.ts +3 -3
- package/test/governance/CompoundVotingMachine.castvote.test.ts +3 -6
- package/test/governance/CompoundVotingMachine.crossblockchain.ts +2 -2
- package/test/governance/CompoundVotingMachine.daoscheme.ts +1 -1
- package/test/governance/CompoundVotingMachine.guardian.test.ts +4 -4
- package/test/governance/CompoundVotingMachine.propose.test.ts +8 -8
- package/test/governance/CompoundVotingMachine.state.test.ts +4 -4
- package/test/governance/GReputation.test.ts +6 -6
- package/test/governance/GoodDollarStaking.gd.test.ts +44 -71
- package/test/governance/GoodDollarStaking.good.test.ts +52 -73
- package/test/governance/GovernanceStaking.test.ts +1 -1
- package/test/governance/Reputation.test.ts +2 -2
- package/test/helpers.ts +1 -1
- package/test/identity/IdentityV2.test.ts +12 -12
- package/test/invite/InvitesV1.test.ts +6 -6
- package/test/invite/InvitesV2.test.ts +272 -81
- package/test/reserve/DistributionHelper.test.ts +232 -139
- package/test/reserve/GoodMarketMaker.test.ts +17 -17
- package/test/reserve/GoodReserveCDai.cap.test.ts +4 -4
- package/test/reserve/GoodReserveCDai.distribution.test.ts +64 -42
- package/test/reserve/GoodReserveCDai.gdx.test.ts +1 -1
- package/test/reserve/GoodReserveCDai.pause.test.ts +8 -8
- package/test/reserve/GoodReserveCDai.test.ts +307 -101
- package/test/reserve/GoodReserveCDai.uniswap.test.ts +1 -1
- package/test/staking/DonationsStaking.test.ts +2 -2
- package/test/staking/FuseStaking.test.ts +3 -3
- package/test/staking/GoodAaveStakingFactory.test.ts +2 -2
- package/test/staking/StakingRewards.test.ts +913 -320
- package/test/staking/StakingRewardsFixedAPY.test.ts +62 -66
- package/test/token/CeloGasToken.test.ts +2 -2
- package/test/token/GoodDollar.test.ts +5 -5
- package/test/token/SuperGoodDollar.test.ts +17 -13
- package/test/ubi/UBIScheme.test.ts +1 -1
- package/test/utils/AdminWallet.test.ts +10 -10
- package/test/utils/BuyAndBridgeHelper.test.ts +33 -9
- package/test/utils/GoodDollarMintBurnWrapper.test.ts +265 -113
- package/test/utils/NameService.test.ts +1 -1
- package/test/utils/ProxyFactory.test.ts +2 -2
- package/types/contracts/token/superfluid/SuperGoodDollar.ts +26 -0
- package/types/factories/contracts/token/superfluid/ISuperToken__factory.ts +5 -0
- package/types/factories/contracts/token/superfluid/SuperGoodDollar__factory.ts +24 -1
- package/types/factories/contracts/token/superfluid/SuperToken__factory.ts +6 -1
- package/yarn.lock +635 -253
|
@@ -58,8 +58,14 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
58
58
|
nameService = ns;
|
|
59
59
|
runAsAvatarOnly = raao;
|
|
60
60
|
await setDAOAddress("UNISWAP_ROUTER", signers[0].address);
|
|
61
|
-
const exchangeHelperFactory = await ethers.getContractFactory(
|
|
62
|
-
|
|
61
|
+
const exchangeHelperFactory = await ethers.getContractFactory(
|
|
62
|
+
"ExchangeHelper"
|
|
63
|
+
);
|
|
64
|
+
exchangeHelper = await upgrades.deployProxy(
|
|
65
|
+
exchangeHelperFactory,
|
|
66
|
+
[nameService.address],
|
|
67
|
+
{ kind: "uups" }
|
|
68
|
+
);
|
|
63
69
|
await exchangeHelper.setAddresses();
|
|
64
70
|
await setDAOAddress("EXCHANGE_HELPER", exchangeHelper.address);
|
|
65
71
|
console.log("deployed dao", {
|
|
@@ -141,7 +147,7 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
141
147
|
// let tx = (await goodReserve.buy(cDAI.address, amount, 0)).wait();
|
|
142
148
|
// const gdBalanceAfter = await goodDollar.balanceOf(founder.address);
|
|
143
149
|
// const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
144
|
-
// expect(tx).to.be.revertedWith(
|
|
150
|
+
// expect(tx).to.be.revertedWith(/not minter/);
|
|
145
151
|
// expect(gdBalanceAfter.toString()).to.be.equal(gdBalanceBefore.toString());
|
|
146
152
|
// expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
147
153
|
// cDAIBalanceBefore.toString()
|
|
@@ -159,11 +165,19 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
159
165
|
|
|
160
166
|
await increaseTime(24 * 60 * 60); //required for reserve ratio advance
|
|
161
167
|
const er = await cDAI.exchangeRateStored();
|
|
162
|
-
const daiAmount = ethers.utils
|
|
168
|
+
const daiAmount = ethers.utils
|
|
169
|
+
.parseEther("0.1")
|
|
170
|
+
.mul(BN.from("10").pow(10))
|
|
171
|
+
.mul(er)
|
|
172
|
+
.div(BN.from("10").pow(28));
|
|
163
173
|
|
|
164
174
|
await dai["mint(address,uint256)"](goodReserve.address, daiAmount);
|
|
165
|
-
const tx = await (
|
|
166
|
-
|
|
175
|
+
const tx = await (
|
|
176
|
+
await goodReserve.mintUBI(daiAmount, 0, cDAI.address)
|
|
177
|
+
).wait();
|
|
178
|
+
const gdBalanceFund = await goodDollar.balanceOf(
|
|
179
|
+
await goodReserve.distributionHelper()
|
|
180
|
+
);
|
|
167
181
|
const gdPriceAfter = await goodReserve["currentPrice()"]();
|
|
168
182
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
169
183
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
@@ -171,20 +185,32 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
171
185
|
let rrAfter = reserveToken.reserveRatio;
|
|
172
186
|
// expected that minted token will be added to the previous supply
|
|
173
187
|
const mintEvent = tx.events.find(_ => _.event === "UBIMinted");
|
|
174
|
-
console.log(
|
|
188
|
+
console.log(
|
|
189
|
+
gdPriceBefore.toNumber(),
|
|
190
|
+
supplyAfter.toNumber(),
|
|
191
|
+
supplyBefore.toNumber()
|
|
192
|
+
);
|
|
175
193
|
expect(supplyAfter).to.be.equal(
|
|
176
|
-
mintEvent.args.gdInterestMinted
|
|
194
|
+
mintEvent.args.gdInterestMinted
|
|
195
|
+
.add(mintEvent.args.gdExpansionMinted)
|
|
196
|
+
.add(supplyBefore)
|
|
177
197
|
);
|
|
178
198
|
// expected that the new reserve balance will include
|
|
179
199
|
// the new 1e18 cdai which transferred
|
|
180
|
-
expect(reserveBalanceAfter).to.be.equal(
|
|
200
|
+
expect(reserveBalanceAfter).to.be.equal(
|
|
201
|
+
reserveBalanceBefore.add(BN.from("10").pow(17))
|
|
202
|
+
);
|
|
181
203
|
// the new reserve ratio should be effected from the mintExpansion by:
|
|
182
204
|
// the daily change that was set up in the constructor (999388834642296)
|
|
183
205
|
// requires the time advance simulation above
|
|
184
206
|
expect(rrAfter.toString()).to.be.equal("999388");
|
|
185
207
|
// the price should be the same
|
|
186
208
|
expect(gdPriceAfter).to.be.equal(gdPriceBefore);
|
|
187
|
-
expect(gdBalanceFund).to.be.equal(
|
|
209
|
+
expect(gdBalanceFund).to.be.equal(
|
|
210
|
+
mintEvent.args.gdInterestMinted
|
|
211
|
+
.add(mintEvent.args.gdExpansionMinted)
|
|
212
|
+
.toString()
|
|
213
|
+
);
|
|
188
214
|
});
|
|
189
215
|
|
|
190
216
|
it("should not mint UBI if the reserve is not cDAI", async () => {
|
|
@@ -194,13 +220,16 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
194
220
|
|
|
195
221
|
it("should not mint UBI if the caller is not the fund manager", async () => {
|
|
196
222
|
let tx = goodReserve.connect(staker).mintUBI(0, 0, cDAI.address);
|
|
197
|
-
await expect(tx).to.be.revertedWith(
|
|
223
|
+
await expect(tx).to.be.revertedWith(/GoodReserve: not a minter/);
|
|
198
224
|
});
|
|
199
225
|
|
|
200
226
|
it("should be able to buy gd with DAI", async () => {
|
|
201
227
|
let daiAmount = ethers.utils.parseEther("100");
|
|
202
228
|
const cdaiRateStored = await cDAI.exchangeRateStored();
|
|
203
|
-
let amount = daiAmount
|
|
229
|
+
let amount = daiAmount
|
|
230
|
+
.div(BigNumber.from(10).pow(10))
|
|
231
|
+
.mul(BigNumber.from(10).pow(28))
|
|
232
|
+
.div(cdaiRateStored);
|
|
204
233
|
await dai["mint(uint256)"](daiAmount);
|
|
205
234
|
await dai.approve(exchangeHelper.address, daiAmount);
|
|
206
235
|
expect(await nameService.getAddress("DAI")).to.be.equal(dai.address);
|
|
@@ -213,7 +242,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
213
242
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
214
243
|
const priceBefore = await goodReserve["currentPrice()"]();
|
|
215
244
|
|
|
216
|
-
let transaction = await (
|
|
245
|
+
let transaction = await (
|
|
246
|
+
await exchangeHelper.buy([dai.address], daiAmount, 0, 0, NULL_ADDRESS)
|
|
247
|
+
).wait();
|
|
217
248
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
218
249
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
219
250
|
let supplyAfter = reserveToken.gdSupply;
|
|
@@ -222,14 +253,21 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
222
253
|
const daiBalanceAfter = await dai.balanceOf(founder.address);
|
|
223
254
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
224
255
|
const priceAfter = await goodReserve["currentPrice()"]();
|
|
225
|
-
expect(
|
|
226
|
-
|
|
227
|
-
|
|
256
|
+
expect(
|
|
257
|
+
(cDAIBalanceReserveAfter - cDAIBalanceReserveBefore).toString()
|
|
258
|
+
).to.be.equal(amount.toString());
|
|
259
|
+
expect(
|
|
260
|
+
reserveBalanceAfter.sub(reserveBalanceBefore).toString()
|
|
261
|
+
).to.be.equal(amount.toString());
|
|
262
|
+
expect(supplyAfter.sub(supplyBefore).toString()).to.be.equal(
|
|
263
|
+
gdBalanceAfter.sub(gdBalanceBefore).toString()
|
|
264
|
+
);
|
|
228
265
|
expect(rrAfter.toString()).to.be.equal(rrBefore.toString());
|
|
229
266
|
expect(gdBalanceAfter.gt(gdBalanceBefore)).to.be.true;
|
|
230
267
|
expect(daiBalanceBefore.gt(daiBalanceAfter)).to.be.true;
|
|
231
268
|
expect(priceAfter.toString()).to.be.equal(priceBefore.toString());
|
|
232
|
-
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
269
|
+
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
270
|
+
.empty;
|
|
233
271
|
});
|
|
234
272
|
|
|
235
273
|
it("should be able to buy gd with cDAI through buy", async () => {
|
|
@@ -246,7 +284,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
246
284
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
247
285
|
const priceBefore = await goodReserve["currentPrice()"]();
|
|
248
286
|
await cDAI.approve(exchangeHelper.address, amount);
|
|
249
|
-
let transaction = await (
|
|
287
|
+
let transaction = await (
|
|
288
|
+
await exchangeHelper.buy([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
289
|
+
).wait();
|
|
250
290
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
251
291
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
252
292
|
let supplyAfter = reserveToken.gdSupply;
|
|
@@ -255,14 +295,21 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
255
295
|
const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
256
296
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
257
297
|
const priceAfter = await goodReserve["currentPrice()"]();
|
|
258
|
-
expect(
|
|
259
|
-
|
|
260
|
-
|
|
298
|
+
expect(
|
|
299
|
+
(cDAIBalanceReserveAfter - cDAIBalanceReserveBefore).toString()
|
|
300
|
+
).to.be.equal(amount.toString());
|
|
301
|
+
expect(
|
|
302
|
+
reserveBalanceAfter.sub(reserveBalanceBefore).toString()
|
|
303
|
+
).to.be.equal(amount.toString());
|
|
304
|
+
expect(supplyAfter.sub(supplyBefore).toString()).to.be.equal(
|
|
305
|
+
gdBalanceAfter.sub(gdBalanceBefore).toString()
|
|
306
|
+
);
|
|
261
307
|
expect(rrAfter.toString()).to.be.equal(rrBefore.toString());
|
|
262
308
|
expect(gdBalanceAfter.gt(gdBalanceBefore)).to.be.true;
|
|
263
309
|
expect(cDAIBalanceBefore.gt(cDAIBalanceAfter)).to.be.true;
|
|
264
310
|
expect(priceAfter.toString()).to.be.equal(priceBefore.toString());
|
|
265
|
-
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
311
|
+
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
312
|
+
.empty;
|
|
266
313
|
});
|
|
267
314
|
|
|
268
315
|
it("should be able to buy gd with cDAI", async () => {
|
|
@@ -279,7 +326,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
279
326
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
280
327
|
const priceBefore = await goodReserve["currentPrice()"]();
|
|
281
328
|
await cDAI.approve(exchangeHelper.address, amount);
|
|
282
|
-
let transaction = await (
|
|
329
|
+
let transaction = await (
|
|
330
|
+
await exchangeHelper.buy([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
331
|
+
).wait();
|
|
283
332
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
284
333
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
285
334
|
let supplyAfter = reserveToken.gdSupply;
|
|
@@ -288,14 +337,21 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
288
337
|
const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
289
338
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
290
339
|
const priceAfter = await goodReserve["currentPrice()"]();
|
|
291
|
-
expect(
|
|
292
|
-
|
|
293
|
-
|
|
340
|
+
expect(
|
|
341
|
+
(cDAIBalanceReserveAfter - cDAIBalanceReserveBefore).toString()
|
|
342
|
+
).to.be.equal(amount.toString());
|
|
343
|
+
expect(
|
|
344
|
+
reserveBalanceAfter.sub(reserveBalanceBefore).toString()
|
|
345
|
+
).to.be.equal(amount.toString());
|
|
346
|
+
expect(supplyAfter.sub(supplyBefore).toString()).to.be.equal(
|
|
347
|
+
gdBalanceAfter.sub(gdBalanceBefore).toString()
|
|
348
|
+
);
|
|
294
349
|
expect(rrAfter.toString()).to.be.equal(rrBefore.toString());
|
|
295
350
|
expect(gdBalanceAfter.gt(gdBalanceBefore)).to.be.true;
|
|
296
351
|
expect(cDAIBalanceBefore.gt(cDAIBalanceAfter)).to.be.true;
|
|
297
352
|
expect(priceAfter.toString()).to.be.equal(priceBefore.toString());
|
|
298
|
-
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
353
|
+
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
354
|
+
.empty;
|
|
299
355
|
});
|
|
300
356
|
|
|
301
357
|
it("should be able to buy gd with cDAI with generic amount of cdai tokens", async () => {
|
|
@@ -311,18 +367,27 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
311
367
|
const gdBalanceBefore = await goodDollar.balanceOf(founder.address);
|
|
312
368
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
313
369
|
await cDAI.approve(exchangeHelper.address, amount);
|
|
314
|
-
let transaction = await (
|
|
370
|
+
let transaction = await (
|
|
371
|
+
await exchangeHelper.buy([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
372
|
+
).wait();
|
|
315
373
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
316
374
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
317
375
|
let supplyAfter = reserveToken.gdSupply;
|
|
318
376
|
const gdBalanceAfter = await goodDollar.balanceOf(founder.address);
|
|
319
377
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
320
378
|
// actual cdai balance
|
|
321
|
-
expect(
|
|
379
|
+
expect(
|
|
380
|
+
cDAIBalanceReserveAfter.sub(cDAIBalanceReserveBefore).toString()
|
|
381
|
+
).to.be.equal(amount.toString());
|
|
322
382
|
// cdai balance according to the market maker
|
|
323
|
-
expect(
|
|
324
|
-
|
|
325
|
-
|
|
383
|
+
expect(
|
|
384
|
+
reserveBalanceAfter.sub(reserveBalanceBefore).toString()
|
|
385
|
+
).to.be.equal(amount.toString());
|
|
386
|
+
expect(supplyAfter.sub(supplyBefore).toString()).to.be.equal(
|
|
387
|
+
gdBalanceAfter.sub(gdBalanceBefore).toString()
|
|
388
|
+
);
|
|
389
|
+
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
390
|
+
.empty;
|
|
326
391
|
});
|
|
327
392
|
|
|
328
393
|
it("should be able to buy gd with other non initialized tokens beside cDAI", async () => {
|
|
@@ -336,7 +401,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
336
401
|
it("should not be able to buy gd without cDAI allowance", async () => {
|
|
337
402
|
let amount = 1e8;
|
|
338
403
|
await cDAI.approve(exchangeHelper.address, "0");
|
|
339
|
-
let error = await exchangeHelper
|
|
404
|
+
let error = await exchangeHelper
|
|
405
|
+
.buy([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
406
|
+
.catch(e => e);
|
|
340
407
|
expect(error.message).to.have.string("ERC20: insufficient allowance");
|
|
341
408
|
});
|
|
342
409
|
|
|
@@ -347,14 +414,20 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
347
414
|
await cDAI.approve(exchangeHelper.address, amount);
|
|
348
415
|
const gdBalanceBefore = await goodDollar.balanceOf(founder.address);
|
|
349
416
|
const cDAIBalanceBefore = await cDAI.balanceOf(founder.address);
|
|
350
|
-
let error = await exchangeHelper
|
|
417
|
+
let error = await exchangeHelper
|
|
418
|
+
.buy([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
419
|
+
.catch(e => e);
|
|
351
420
|
const gdBalanceAfter = await goodDollar.balanceOf(founder.address);
|
|
352
421
|
const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
353
422
|
expect(error.message).not.to.be.empty;
|
|
354
423
|
expect(gdBalanceAfter.toString()).to.be.equal(gdBalanceBefore.toString());
|
|
355
|
-
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
424
|
+
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
425
|
+
cDAIBalanceBefore.toString()
|
|
426
|
+
);
|
|
356
427
|
|
|
357
|
-
await cDAI
|
|
428
|
+
await cDAI
|
|
429
|
+
.connect(staker)
|
|
430
|
+
.transfer(founder.address, cDAIBalanceBeforeTransfer.toString());
|
|
358
431
|
});
|
|
359
432
|
|
|
360
433
|
it("should not be able to buy gd when the minimum return is higher than the actual return", async () => {
|
|
@@ -362,12 +435,18 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
362
435
|
await cDAI.approve(exchangeHelper.address, amount);
|
|
363
436
|
const gdBalanceBefore = await goodDollar.balanceOf(founder.address);
|
|
364
437
|
const cDAIBalanceBefore = await cDAI.balanceOf(founder.address);
|
|
365
|
-
let error = await exchangeHelper
|
|
438
|
+
let error = await exchangeHelper
|
|
439
|
+
.buy([cDAI.address], amount, 2000000, 0, NULL_ADDRESS)
|
|
440
|
+
.catch(e => e);
|
|
366
441
|
const gdBalanceAfter = await goodDollar.balanceOf(founder.address);
|
|
367
442
|
const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
368
|
-
expect(error.message).to.have.string(
|
|
443
|
+
expect(error.message).to.have.string(
|
|
444
|
+
"GD return must be above the minReturn"
|
|
445
|
+
);
|
|
369
446
|
expect(gdBalanceAfter.toString()).to.be.equal(gdBalanceBefore.toString());
|
|
370
|
-
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
447
|
+
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
448
|
+
cDAIBalanceBefore.toString()
|
|
449
|
+
);
|
|
371
450
|
});
|
|
372
451
|
|
|
373
452
|
it("should be able to sell gd to cDAI without contribution", async () => {
|
|
@@ -380,7 +459,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
380
459
|
const cDAIBalanceBefore = await cDAI.balanceOf(founder.address);
|
|
381
460
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
382
461
|
await goodDollar.approve(exchangeHelper.address, amount);
|
|
383
|
-
let transaction = await (
|
|
462
|
+
let transaction = await (
|
|
463
|
+
await exchangeHelper.sell([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
464
|
+
).wait();
|
|
384
465
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
385
466
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
386
467
|
let supplyAfter = reserveToken.gdSupply;
|
|
@@ -389,7 +470,10 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
389
470
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
390
471
|
// according to the initialization settings reserve ratio is 100%. the calculation is:
|
|
391
472
|
// Return = _reserveBalance * (1 - (1 - _sellAmount / _supply) ^ (1000000 / _reserveRatio))
|
|
392
|
-
const bancor = await ethers.getContractAt(
|
|
473
|
+
const bancor = await ethers.getContractAt(
|
|
474
|
+
"BancorFormula",
|
|
475
|
+
await marketMaker.getBancor()
|
|
476
|
+
);
|
|
393
477
|
const expectedReturn = await bancor.calculateSaleReturn(
|
|
394
478
|
supplyBefore.toString(),
|
|
395
479
|
reserveBalanceBefore.toString(),
|
|
@@ -397,13 +481,18 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
397
481
|
amount
|
|
398
482
|
);
|
|
399
483
|
expect(cDAIBalanceAfter - cDAIBalanceBefore).to.be.equal(expectedReturn);
|
|
400
|
-
expect(cDAIBalanceReserveBefore - cDAIBalanceReserveAfter).to.be.equal(
|
|
401
|
-
|
|
484
|
+
expect(cDAIBalanceReserveBefore - cDAIBalanceReserveAfter).to.be.equal(
|
|
485
|
+
expectedReturn
|
|
486
|
+
);
|
|
487
|
+
expect(reserveBalanceBefore.sub(reserveBalanceAfter)).to.be.equal(
|
|
488
|
+
expectedReturn
|
|
489
|
+
);
|
|
402
490
|
// 1e4 gd sold (burn from the supply)
|
|
403
491
|
expect(supplyBefore.sub(supplyAfter)).to.be.equal(amount);
|
|
404
492
|
expect(gdBalanceBefore.gt(gdBalanceAfter)).to.be.true;
|
|
405
493
|
expect(cDAIBalanceAfter.gt(cDAIBalanceBefore)).to.be.true;
|
|
406
|
-
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
494
|
+
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
495
|
+
.empty;
|
|
407
496
|
});
|
|
408
497
|
|
|
409
498
|
it("should be able to sell gd to cDAI without contribution through sell function", async () => {
|
|
@@ -416,7 +505,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
416
505
|
const cDAIBalanceBefore = await cDAI.balanceOf(founder.address);
|
|
417
506
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
418
507
|
await goodDollar.approve(exchangeHelper.address, amount);
|
|
419
|
-
let transaction = await (
|
|
508
|
+
let transaction = await (
|
|
509
|
+
await exchangeHelper.sell([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
510
|
+
).wait();
|
|
420
511
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
421
512
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
422
513
|
let supplyAfter = reserveToken.gdSupply;
|
|
@@ -425,7 +516,10 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
425
516
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
426
517
|
// according to the initialization settings reserve ratio is 100%. the calculation is:
|
|
427
518
|
// Return = _reserveBalance * (1 - (1 - _sellAmount / _supply) ^ (1000000 / _reserveRatio))
|
|
428
|
-
const bancor = await ethers.getContractAt(
|
|
519
|
+
const bancor = await ethers.getContractAt(
|
|
520
|
+
"BancorFormula",
|
|
521
|
+
await marketMaker.getBancor()
|
|
522
|
+
);
|
|
429
523
|
const expectedReturn = await bancor.calculateSaleReturn(
|
|
430
524
|
supplyBefore.toString(),
|
|
431
525
|
reserveBalanceBefore.toString(),
|
|
@@ -433,13 +527,18 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
433
527
|
amount
|
|
434
528
|
);
|
|
435
529
|
expect(cDAIBalanceAfter - cDAIBalanceBefore).to.be.equal(expectedReturn);
|
|
436
|
-
expect(cDAIBalanceReserveBefore - cDAIBalanceReserveAfter).to.be.equal(
|
|
437
|
-
|
|
530
|
+
expect(cDAIBalanceReserveBefore - cDAIBalanceReserveAfter).to.be.equal(
|
|
531
|
+
expectedReturn
|
|
532
|
+
);
|
|
533
|
+
expect(reserveBalanceBefore.sub(reserveBalanceAfter)).to.be.equal(
|
|
534
|
+
expectedReturn
|
|
535
|
+
);
|
|
438
536
|
// 1e4 gd sold (burn from the supply)
|
|
439
537
|
expect(supplyBefore.sub(supplyAfter)).to.be.equal(amount);
|
|
440
538
|
expect(gdBalanceBefore.gt(gdBalanceAfter)).to.be.true;
|
|
441
539
|
expect(cDAIBalanceAfter.gt(cDAIBalanceBefore)).to.be.true;
|
|
442
|
-
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
540
|
+
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
541
|
+
.empty;
|
|
443
542
|
});
|
|
444
543
|
|
|
445
544
|
it("should be able to sell gd to DAI without contribution through sell function", async () => {
|
|
@@ -452,7 +551,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
452
551
|
const daiBalanceBefore = await dai.balanceOf(founder.address);
|
|
453
552
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
454
553
|
await goodDollar.approve(exchangeHelper.address, amount);
|
|
455
|
-
let transaction = await (
|
|
554
|
+
let transaction = await (
|
|
555
|
+
await exchangeHelper.sell([dai.address], amount, 0, 0, NULL_ADDRESS)
|
|
556
|
+
).wait();
|
|
456
557
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
457
558
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
458
559
|
let supplyAfter = reserveToken.gdSupply;
|
|
@@ -461,7 +562,10 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
461
562
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
462
563
|
// according to the initialization settings reserve ratio is 100%. the calculation is:
|
|
463
564
|
// Return = _reserveBalance * (1 - (1 - _sellAmount / _supply) ^ (1000000 / _reserveRatio))
|
|
464
|
-
const bancor = await ethers.getContractAt(
|
|
565
|
+
const bancor = await ethers.getContractAt(
|
|
566
|
+
"BancorFormula",
|
|
567
|
+
await marketMaker.getBancor()
|
|
568
|
+
);
|
|
465
569
|
const expectedReturn = await bancor.calculateSaleReturn(
|
|
466
570
|
supplyBefore.toString(),
|
|
467
571
|
reserveBalanceBefore.toString(),
|
|
@@ -480,15 +584,26 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
480
584
|
//expect(supplyBefore.sub(supplyAfter)).to.be.equal(amount);
|
|
481
585
|
//expect(gdBalanceBefore.gt(gdBalanceAfter)).to.be.true;
|
|
482
586
|
expect(daiBalanceAfter.gt(daiBalanceBefore)).to.be.true;
|
|
483
|
-
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
587
|
+
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
588
|
+
.empty;
|
|
484
589
|
});
|
|
485
590
|
|
|
486
591
|
it("should set sell contribution ratio by avatar", async () => {
|
|
487
592
|
let nom = ethers.utils.parseUnits("2", 14);
|
|
488
593
|
let denom = ethers.utils.parseUnits("1", 15);
|
|
489
|
-
let ccFactory = await ethers.getContractFactory(
|
|
490
|
-
|
|
491
|
-
|
|
594
|
+
let ccFactory = await ethers.getContractFactory(
|
|
595
|
+
ContributionCalculation.abi,
|
|
596
|
+
ContributionCalculation.bytecode
|
|
597
|
+
);
|
|
598
|
+
let encodedCall = ccFactory.interface.encodeFunctionData(
|
|
599
|
+
"setContributionRatio",
|
|
600
|
+
[nom, denom]
|
|
601
|
+
);
|
|
602
|
+
const ctrl = await ethers.getContractAt(
|
|
603
|
+
"Controller",
|
|
604
|
+
controller,
|
|
605
|
+
schemeMock
|
|
606
|
+
);
|
|
492
607
|
|
|
493
608
|
await ctrl.genericCall(contribution.address, encodedCall, avatar, 0);
|
|
494
609
|
const newRatio = await contribution.sellContributionRatio();
|
|
@@ -496,7 +611,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
496
611
|
});
|
|
497
612
|
|
|
498
613
|
it("should not be able to set the sell contribution ratio if not avatar", async () => {
|
|
499
|
-
let error = await contribution
|
|
614
|
+
let error = await contribution
|
|
615
|
+
.setContributionRatio(2e14, 1e15)
|
|
616
|
+
.catch(e => e);
|
|
500
617
|
expect(error.message).to.have.string("only Avatar can call this method");
|
|
501
618
|
});
|
|
502
619
|
|
|
@@ -597,7 +714,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
597
714
|
|
|
598
715
|
await goodDollar.connect(staker).approve(exchangeHelper.address, amount);
|
|
599
716
|
let transaction = await (
|
|
600
|
-
await exchangeHelper
|
|
717
|
+
await exchangeHelper
|
|
718
|
+
.connect(staker)
|
|
719
|
+
.sell([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
601
720
|
).wait();
|
|
602
721
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
603
722
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
@@ -607,18 +726,25 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
607
726
|
const cDAIBalanceAfter = await cDAI.balanceOf(staker.address);
|
|
608
727
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
609
728
|
const priceAfter = await goodReserve["currentPrice()"]();
|
|
610
|
-
expect(cDAIBalanceAfter.sub(cDAIBalanceBefore)).to.be.equal(
|
|
729
|
+
expect(cDAIBalanceAfter.sub(cDAIBalanceBefore)).to.be.equal(
|
|
730
|
+
expectedReturn,
|
|
731
|
+
"seller return mismatch"
|
|
732
|
+
);
|
|
611
733
|
expect(cDAIBalanceReserveBefore.sub(cDAIBalanceReserveAfter)).to.be.equal(
|
|
612
734
|
expectedReturn,
|
|
613
735
|
"reserve balance mismatch"
|
|
614
736
|
);
|
|
615
|
-
expect(reserveBalanceBefore.sub(reserveBalanceAfter)).to.be.equal(
|
|
737
|
+
expect(reserveBalanceBefore.sub(reserveBalanceAfter)).to.be.equal(
|
|
738
|
+
expectedReturn,
|
|
739
|
+
"reserve token data mismatch"
|
|
740
|
+
);
|
|
616
741
|
expect(supplyBefore.sub(supplyAfter)).to.be.equal(amount);
|
|
617
742
|
expect(rrAfter.toString()).to.be.equal(rrBefore.toString());
|
|
618
743
|
expect(gdBalanceBefore.gt(gdBalanceAfter)).to.be.true;
|
|
619
744
|
expect(cDAIBalanceAfter.gt(cDAIBalanceBefore)).to.be.true;
|
|
620
745
|
expect(priceAfter.toString()).to.be.equal(priceBefore.toString());
|
|
621
|
-
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
746
|
+
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
747
|
+
.empty;
|
|
622
748
|
});
|
|
623
749
|
|
|
624
750
|
it("should able to sell gd to DAI or cDAI token", async () => {
|
|
@@ -634,30 +760,43 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
634
760
|
await goodDollar.approve(exchangeHelper.address, "0");
|
|
635
761
|
const gdBalanceBefore = await goodDollar.balanceOf(founder.address);
|
|
636
762
|
const cDAIBalanceBefore = await cDAI.balanceOf(founder.address);
|
|
637
|
-
let error = await exchangeHelper
|
|
763
|
+
let error = await exchangeHelper
|
|
764
|
+
.sell([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
765
|
+
.catch(e => e);
|
|
638
766
|
const gdBalanceAfter = await goodDollar.balanceOf(founder.address);
|
|
639
767
|
const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
640
768
|
expect(error.message).not.to.be.empty;
|
|
641
769
|
expect(gdBalanceAfter.toString()).to.be.equal(gdBalanceBefore.toString());
|
|
642
|
-
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
770
|
+
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
771
|
+
cDAIBalanceBefore.toString()
|
|
772
|
+
);
|
|
643
773
|
});
|
|
644
774
|
|
|
645
775
|
it("should not be able to sell gd without enough gd funds", async () => {
|
|
646
776
|
let amount = 1e4;
|
|
647
777
|
const gdBalanceBeforeTransfer = await goodDollar.balanceOf(founder.address);
|
|
648
778
|
//reset gd holdings
|
|
649
|
-
await goodDollar.transfer(
|
|
779
|
+
await goodDollar.transfer(
|
|
780
|
+
staker.address,
|
|
781
|
+
gdBalanceBeforeTransfer.toString()
|
|
782
|
+
);
|
|
650
783
|
await goodDollar.approve(exchangeHelper.address, amount);
|
|
651
784
|
const gdBalanceBefore = await goodDollar.balanceOf(founder.address);
|
|
652
785
|
const cDAIBalanceBefore = await cDAI.balanceOf(founder.address);
|
|
653
|
-
let error = await exchangeHelper
|
|
786
|
+
let error = await exchangeHelper
|
|
787
|
+
.sell([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
788
|
+
.catch(e => e);
|
|
654
789
|
const gdBalanceAfter = await goodDollar.balanceOf(founder.address);
|
|
655
790
|
const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
656
791
|
expect(error.message).not.to.be.empty;
|
|
657
792
|
expect(gdBalanceAfter.toString()).to.be.equal(gdBalanceBefore.toString());
|
|
658
|
-
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
793
|
+
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
794
|
+
cDAIBalanceBefore.toString()
|
|
795
|
+
);
|
|
659
796
|
//restore gd holdings
|
|
660
|
-
await goodDollar
|
|
797
|
+
await goodDollar
|
|
798
|
+
.connect(staker)
|
|
799
|
+
.transfer(founder.address, gdBalanceBeforeTransfer.toString());
|
|
661
800
|
});
|
|
662
801
|
|
|
663
802
|
it("should not be able to sell gd when the minimum return is higher than the actual return", async () => {
|
|
@@ -665,12 +804,18 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
665
804
|
await goodDollar.approve(exchangeHelper.address, amount);
|
|
666
805
|
const gdBalanceBefore = await goodDollar.balanceOf(founder.address);
|
|
667
806
|
const cDAIBalanceBefore = await cDAI.balanceOf(founder.address);
|
|
668
|
-
let error = await exchangeHelper
|
|
807
|
+
let error = await exchangeHelper
|
|
808
|
+
.sell([cDAI.address], amount, 2000000, 0, NULL_ADDRESS)
|
|
809
|
+
.catch(e => e);
|
|
669
810
|
const gdBalanceAfter = await goodDollar.balanceOf(founder.address);
|
|
670
811
|
const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
671
|
-
expect(error.message).to.have.string(
|
|
812
|
+
expect(error.message).to.have.string(
|
|
813
|
+
"Token return must be above the minReturn"
|
|
814
|
+
);
|
|
672
815
|
expect(gdBalanceAfter.toString()).to.be.equal(gdBalanceBefore.toString());
|
|
673
|
-
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
816
|
+
expect(cDAIBalanceAfter.toString()).to.be.equal(
|
|
817
|
+
cDAIBalanceBefore.toString()
|
|
818
|
+
);
|
|
674
819
|
});
|
|
675
820
|
|
|
676
821
|
it("should return an error if non avatar account is trying to execute recover", async () => {
|
|
@@ -679,14 +824,23 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
679
824
|
});
|
|
680
825
|
|
|
681
826
|
it("should transfer funds when execute recover of token which the reserve has some balance", async () => {
|
|
682
|
-
await dai["mint(address,uint256)"](
|
|
827
|
+
await dai["mint(address,uint256)"](
|
|
828
|
+
goodReserve.address,
|
|
829
|
+
ethers.utils.parseEther("100")
|
|
830
|
+
);
|
|
683
831
|
|
|
684
832
|
let reserveBalance = await dai.balanceOf(goodReserve.address);
|
|
685
833
|
const reserveFactory = await ethers.getContractFactory("GoodReserveCDai");
|
|
686
834
|
|
|
687
|
-
let encodedCall = reserveFactory.interface.encodeFunctionData("recover", [
|
|
835
|
+
let encodedCall = reserveFactory.interface.encodeFunctionData("recover", [
|
|
836
|
+
dai.address
|
|
837
|
+
]);
|
|
688
838
|
|
|
689
|
-
const ctrl = await ethers.getContractAt(
|
|
839
|
+
const ctrl = await ethers.getContractAt(
|
|
840
|
+
"Controller",
|
|
841
|
+
controller,
|
|
842
|
+
schemeMock
|
|
843
|
+
);
|
|
690
844
|
await ctrl.genericCall(goodReserve.address, encodedCall, avatar, 0);
|
|
691
845
|
let recoveredBalance = await dai.balanceOf(avatar);
|
|
692
846
|
expect(recoveredBalance).to.be.equal(reserveBalance);
|
|
@@ -694,7 +848,7 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
694
848
|
|
|
695
849
|
it("should not be able to destroy if not avatar", async () => {
|
|
696
850
|
let tx = goodReserve.end();
|
|
697
|
-
await expect(tx).to.revertedWith(
|
|
851
|
+
await expect(tx).to.revertedWith(/only avatar can call this method/);
|
|
698
852
|
});
|
|
699
853
|
|
|
700
854
|
it("should be able to buy gd with cDAI and reserve should be correct", async () => {
|
|
@@ -711,7 +865,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
711
865
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
712
866
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
713
867
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
714
|
-
expect(cDAIBalanceReserveAfter.sub(cDAIBalanceReserveBefore)).to.be.equal(
|
|
868
|
+
expect(cDAIBalanceReserveAfter.sub(cDAIBalanceReserveBefore)).to.be.equal(
|
|
869
|
+
amount.toString()
|
|
870
|
+
);
|
|
715
871
|
expect(reserveBalanceAfter.sub(reserveBalanceBefore)).to.be.equal(amount);
|
|
716
872
|
});
|
|
717
873
|
it("should be able to buy gd with cDAI directly through reserve", async () => {
|
|
@@ -740,11 +896,15 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
740
896
|
});
|
|
741
897
|
it("should not be able to sell gd through reserve when there is no enough allowance", async () => {
|
|
742
898
|
await goodDollar.approve(goodReserve.address, "0");
|
|
743
|
-
const tx = await goodReserve
|
|
899
|
+
const tx = await goodReserve
|
|
900
|
+
.sell("100", 0, founder.address, staker.address)
|
|
901
|
+
.catch(e => e);
|
|
744
902
|
expect(tx.message).to.be.not.empty;
|
|
745
903
|
});
|
|
746
904
|
it("seller parameter should not matter if caller is not exchange helper", async () => {
|
|
747
|
-
const stakerGDBalanceBeforeSell = await goodDollar.balanceOf(
|
|
905
|
+
const stakerGDBalanceBeforeSell = await goodDollar.balanceOf(
|
|
906
|
+
staker.address
|
|
907
|
+
);
|
|
748
908
|
await goodDollar.approve(goodReserve.address, "100");
|
|
749
909
|
await goodReserve.sell("100", 0, founder.address, staker.address);
|
|
750
910
|
const stakerGDBalanceAfterSell = await goodDollar.balanceOf(staker.address);
|
|
@@ -790,7 +950,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
790
950
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
791
951
|
await goodDollar.connect(staker).approve(exchangeHelper.address, amount);
|
|
792
952
|
const transaction = await (
|
|
793
|
-
await exchangeHelper
|
|
953
|
+
await exchangeHelper
|
|
954
|
+
.connect(staker)
|
|
955
|
+
.sell([cDAI.address], amount, 0, 0, NULL_ADDRESS)
|
|
794
956
|
).wait();
|
|
795
957
|
|
|
796
958
|
const cDAIBalanceAfter = await cDAI.balanceOf(staker.address);
|
|
@@ -802,12 +964,16 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
802
964
|
// the contribution ratio is 20%
|
|
803
965
|
let expected =
|
|
804
966
|
parseInt(reserveBalance.toString()) *
|
|
805
|
-
(1 -
|
|
967
|
+
(1 -
|
|
968
|
+
(1 - amount.toNumber() / parseInt(supply.toString())) **
|
|
969
|
+
(1000000 / reserveToken.reserveRatio));
|
|
806
970
|
|
|
807
971
|
expected = Math.ceil((0.8 * expected) / 100) * 100; //deduct 20% contribution, allow 5 points precission mismatch (due to bancor pow estimation?), match solidity no floating point
|
|
808
972
|
//expected = Math.floor(0.8 * expected);
|
|
809
973
|
expect(cDAIBalanceAfter.sub(cDAIBalanceBefore)).to.be.equal(expected);
|
|
810
|
-
expect(cDAIBalanceReserveBefore.sub(cDAIBalanceReserveAfter)).to.be.equal(
|
|
974
|
+
expect(cDAIBalanceReserveBefore.sub(cDAIBalanceReserveAfter)).to.be.equal(
|
|
975
|
+
expected
|
|
976
|
+
);
|
|
811
977
|
});
|
|
812
978
|
|
|
813
979
|
it("should be able to buy gd with cDAI for some other address through buy", async () => {
|
|
@@ -824,7 +990,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
824
990
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
825
991
|
const priceBefore = await goodReserve["currentPrice()"]();
|
|
826
992
|
await cDAI.approve(exchangeHelper.address, amount);
|
|
827
|
-
let transaction = await (
|
|
993
|
+
let transaction = await (
|
|
994
|
+
await exchangeHelper.buy([cDAI.address], amount, 0, 0, staker.address)
|
|
995
|
+
).wait();
|
|
828
996
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
829
997
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
830
998
|
let supplyAfter = reserveToken.gdSupply;
|
|
@@ -833,14 +1001,21 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
833
1001
|
const cDAIBalanceAfter = await cDAI.balanceOf(founder.address);
|
|
834
1002
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
835
1003
|
const priceAfter = await goodReserve["currentPrice()"]();
|
|
836
|
-
expect(
|
|
837
|
-
|
|
838
|
-
|
|
1004
|
+
expect(
|
|
1005
|
+
(cDAIBalanceReserveAfter - cDAIBalanceReserveBefore).toString()
|
|
1006
|
+
).to.be.equal(amount.toString());
|
|
1007
|
+
expect(
|
|
1008
|
+
reserveBalanceAfter.sub(reserveBalanceBefore).toString()
|
|
1009
|
+
).to.be.equal(amount.toString());
|
|
1010
|
+
expect(supplyAfter.sub(supplyBefore).toString()).to.be.equal(
|
|
1011
|
+
gdBalanceAfter.sub(gdBalanceBefore).toString()
|
|
1012
|
+
);
|
|
839
1013
|
expect(rrAfter.toString()).to.be.equal(rrBefore.toString());
|
|
840
1014
|
expect(gdBalanceAfter.gt(gdBalanceBefore)).to.be.true;
|
|
841
1015
|
expect(cDAIBalanceBefore.gt(cDAIBalanceAfter)).to.be.true;
|
|
842
1016
|
expect(priceAfter.toString()).to.be.equal(priceBefore.toString());
|
|
843
|
-
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
1017
|
+
expect(transaction.events.find(_ => _.event === "TokenPurchased")).to.be.not
|
|
1018
|
+
.empty;
|
|
844
1019
|
});
|
|
845
1020
|
|
|
846
1021
|
it("should be able to sell gd to cDAI without contribution through sell function for some other address", async () => {
|
|
@@ -853,7 +1028,9 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
853
1028
|
const cDAIBalanceBefore = await cDAI.balanceOf(staker.address);
|
|
854
1029
|
const cDAIBalanceReserveBefore = await cDAI.balanceOf(goodReserve.address);
|
|
855
1030
|
await goodDollar.approve(exchangeHelper.address, amount);
|
|
856
|
-
let transaction = await (
|
|
1031
|
+
let transaction = await (
|
|
1032
|
+
await exchangeHelper.sell([cDAI.address], amount, 0, 0, staker.address)
|
|
1033
|
+
).wait();
|
|
857
1034
|
reserveToken = await marketMaker.reserveTokens(cDAI.address);
|
|
858
1035
|
let reserveBalanceAfter = reserveToken.reserveSupply;
|
|
859
1036
|
let supplyAfter = reserveToken.gdSupply;
|
|
@@ -862,7 +1039,10 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
862
1039
|
const cDAIBalanceReserveAfter = await cDAI.balanceOf(goodReserve.address);
|
|
863
1040
|
// according to the initialization settings reserve ratio is 100%. the calculation is:
|
|
864
1041
|
// Return = _reserveBalance * (1 - (1 - _sellAmount / _supply) ^ (1000000 / _reserveRatio))
|
|
865
|
-
const bancor = await ethers.getContractAt(
|
|
1042
|
+
const bancor = await ethers.getContractAt(
|
|
1043
|
+
"BancorFormula",
|
|
1044
|
+
await marketMaker.getBancor()
|
|
1045
|
+
);
|
|
866
1046
|
const expectedReturn = await bancor.calculateSaleReturn(
|
|
867
1047
|
supplyBefore.toString(),
|
|
868
1048
|
reserveBalanceBefore.toString(),
|
|
@@ -870,13 +1050,18 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
870
1050
|
amount
|
|
871
1051
|
);
|
|
872
1052
|
expect(cDAIBalanceAfter - cDAIBalanceBefore).to.be.equal(expectedReturn);
|
|
873
|
-
expect(cDAIBalanceReserveBefore - cDAIBalanceReserveAfter).to.be.equal(
|
|
874
|
-
|
|
1053
|
+
expect(cDAIBalanceReserveBefore - cDAIBalanceReserveAfter).to.be.equal(
|
|
1054
|
+
expectedReturn
|
|
1055
|
+
);
|
|
1056
|
+
expect(reserveBalanceBefore.sub(reserveBalanceAfter)).to.be.equal(
|
|
1057
|
+
expectedReturn
|
|
1058
|
+
);
|
|
875
1059
|
// 1e4 gd sold (burn from the supply)
|
|
876
1060
|
expect(supplyBefore.sub(supplyAfter)).to.be.equal(amount);
|
|
877
1061
|
expect(gdBalanceBefore.gt(gdBalanceAfter)).to.be.true;
|
|
878
1062
|
expect(cDAIBalanceAfter.gt(cDAIBalanceBefore)).to.be.true;
|
|
879
|
-
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
1063
|
+
expect(transaction.events.find(_ => _.event === "TokenSold")).to.be.not
|
|
1064
|
+
.empty;
|
|
880
1065
|
});
|
|
881
1066
|
|
|
882
1067
|
it("should be able to retain the precision when selling a low quantity of tokens", async () => {
|
|
@@ -903,36 +1088,57 @@ describe("GoodReserve - staking with cDAI mocks", () => {
|
|
|
903
1088
|
|
|
904
1089
|
let encodedCall = reserveFactory.interface.encodeFunctionData("end");
|
|
905
1090
|
|
|
906
|
-
const ctrl = await ethers.getContractAt(
|
|
1091
|
+
const ctrl = await ethers.getContractAt(
|
|
1092
|
+
"Controller",
|
|
1093
|
+
controller,
|
|
1094
|
+
schemeMock
|
|
1095
|
+
);
|
|
907
1096
|
|
|
908
|
-
const tx = await (
|
|
1097
|
+
const tx = await (
|
|
1098
|
+
await ctrl.genericCall(goodReserve.address, encodedCall, avatar, 0)
|
|
1099
|
+
).wait();
|
|
909
1100
|
|
|
910
1101
|
let avatarBalanceAfter = await cDAI.balanceOf(avatar);
|
|
911
1102
|
let reserveBalanceAfter = await cDAI.balanceOf(goodReserve.address);
|
|
912
1103
|
|
|
913
|
-
expect(avatarBalanceAfter.sub(avatarBalanceBefore)).to.be.equal(
|
|
1104
|
+
expect(avatarBalanceAfter.sub(avatarBalanceBefore)).to.be.equal(
|
|
1105
|
+
reserveBalanceBefore
|
|
1106
|
+
);
|
|
914
1107
|
expect(reserveBalanceAfter.toString()).to.be.equal("0");
|
|
915
1108
|
expect(await goodDollar.isMinter(goodReserve.address)).to.be.false;
|
|
916
1109
|
expect(await goodDollar.isMinter(avatar)).to.be.true;
|
|
917
1110
|
});
|
|
918
1111
|
|
|
919
1112
|
it("should set reserve ratio daily expansion by avatar", async () => {
|
|
920
|
-
let currentReserveRatioDailyExpansion =
|
|
1113
|
+
let currentReserveRatioDailyExpansion =
|
|
1114
|
+
await marketMaker.reserveRatioDailyExpansion();
|
|
921
1115
|
console.log(currentReserveRatioDailyExpansion.toString());
|
|
922
1116
|
|
|
923
|
-
await runAsAvatarOnly(
|
|
1117
|
+
await runAsAvatarOnly(
|
|
1118
|
+
goodReserve,
|
|
1119
|
+
"setReserveRatioDailyExpansion(uint256,uint256)",
|
|
1120
|
+
1,
|
|
1121
|
+
1e15
|
|
1122
|
+
);
|
|
924
1123
|
|
|
925
|
-
let newReserveRatioDailyExpansion =
|
|
1124
|
+
let newReserveRatioDailyExpansion =
|
|
1125
|
+
await marketMaker.reserveRatioDailyExpansion();
|
|
926
1126
|
console.log(newReserveRatioDailyExpansion.toString());
|
|
927
1127
|
|
|
928
|
-
expect(newReserveRatioDailyExpansion).to.not.equal(
|
|
1128
|
+
expect(newReserveRatioDailyExpansion).to.not.equal(
|
|
1129
|
+
currentReserveRatioDailyExpansion
|
|
1130
|
+
);
|
|
929
1131
|
expect(newReserveRatioDailyExpansion).to.be.equal(BN.from("1000000000000"));
|
|
930
1132
|
|
|
931
|
-
const encodedCall = goodReserve.interface.encodeFunctionData(
|
|
932
|
-
|
|
933
|
-
1e15
|
|
934
|
-
|
|
935
|
-
const ctrl = await ethers.getContractAt(
|
|
1133
|
+
const encodedCall = goodReserve.interface.encodeFunctionData(
|
|
1134
|
+
"setReserveRatioDailyExpansion",
|
|
1135
|
+
[BN.from(currentReserveRatioDailyExpansion).div(1e12), 1e15]
|
|
1136
|
+
);
|
|
1137
|
+
const ctrl = await ethers.getContractAt(
|
|
1138
|
+
"Controller",
|
|
1139
|
+
controller,
|
|
1140
|
+
schemeMock
|
|
1141
|
+
);
|
|
936
1142
|
await ctrl.genericCall(goodReserve.address, encodedCall, avatar, 0);
|
|
937
1143
|
});
|
|
938
1144
|
});
|