-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from ajna-finance/develop
Merge develop
- Loading branch information
Showing
9 changed files
with
284 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.18; | ||
|
||
import { IERC20 } from "@oz/token/ERC20/IERC20.sol"; | ||
|
||
import { GrantFund } from "./GrantFund.sol"; | ||
|
||
contract Deployer { | ||
|
||
error IncorrectTreasuryBalance(); | ||
|
||
error DistributionNotStarted(); | ||
|
||
GrantFund public grantFund; | ||
|
||
function deployGrantFund(address ajnaToken_, uint256 treasury_) public returns (GrantFund grantFund_) { | ||
|
||
// deploy grant Fund | ||
grantFund_ = new GrantFund(ajnaToken_); | ||
|
||
// Approve ajna token to fund treasury | ||
IERC20(ajnaToken_).approve(address(grantFund_), treasury_); | ||
|
||
// Transfer treasury ajna tokens to Deployer contract | ||
IERC20(ajnaToken_).transferFrom(msg.sender, address(this), treasury_); | ||
|
||
// Fund treasury and start new distribution | ||
grantFund_.fundTreasury(treasury_); | ||
grantFund_.startNewDistributionPeriod(); | ||
|
||
// check treasury balance is correct | ||
if(IERC20(ajnaToken_).balanceOf(address(grantFund_)) != treasury_) revert IncorrectTreasuryBalance(); | ||
|
||
// check new distribution started | ||
if(grantFund_.getDistributionId() != 1) revert DistributionNotStarted(); | ||
|
||
grantFund = grantFund_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
test/invariants/scenarios/MultipleTreasuryFundingInvariant.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.18; | ||
|
||
import { console } from "@std/console.sol"; | ||
import { SafeCast } from "@oz/utils/math/SafeCast.sol"; | ||
|
||
import { Maths } from "../../../src/grants/libraries/Maths.sol"; | ||
|
||
import { StandardTestBase } from "../base/StandardTestBase.sol"; | ||
import { StandardHandler } from "../handlers/StandardHandler.sol"; | ||
import { Handler } from "../handlers/Handler.sol"; | ||
|
||
contract MultipleTreasuryFundingInvariant is StandardTestBase { | ||
|
||
// run tests against all functions, having just started a distribution period | ||
function setUp() public virtual override { | ||
super.setUp(); | ||
|
||
// set the list of function selectors to run | ||
bytes4[] memory selectors = new bytes4[](11); | ||
selectors[0] = _standardHandler.startNewDistributionPeriod.selector; | ||
selectors[1] = _standardHandler.propose.selector; | ||
selectors[2] = _standardHandler.screeningVote.selector; | ||
selectors[3] = _standardHandler.fundingVote.selector; | ||
selectors[4] = _standardHandler.updateSlate.selector; | ||
selectors[5] = _standardHandler.execute.selector; | ||
selectors[6] = _standardHandler.claimDelegateReward.selector; | ||
selectors[7] = _standardHandler.roll.selector; | ||
selectors[8] = _standardHandler.fundTreasury.selector; | ||
selectors[9] = _standardHandler.transferAjna.selector; | ||
selectors[10] = _standardHandler.addActors.selector; | ||
|
||
// ensure utility functions are excluded from the invariant runs | ||
targetSelector(FuzzSelector({ | ||
addr: address(_standardHandler), | ||
selectors: selectors | ||
})); | ||
|
||
// update scenarioType to fast to have larger rolls | ||
_standardHandler.setCurrentScenarioType(Handler.ScenarioType.Fast); | ||
|
||
vm.roll(block.number + 100); | ||
currentBlock = block.number; | ||
} | ||
|
||
function invariant_all() external useCurrentBlock { | ||
// screening invariants | ||
_invariant_SS1_SS3_SS4_SS5_SS6_SS7_SS8_SS10_SS11_P1_P2(_grantFund, _standardHandler); | ||
_invariant_SS2_SS4_SS9(_grantFund, _standardHandler); | ||
|
||
// funding invariants | ||
_invariant_FS1_FS2_FS3(_grantFund, _standardHandler); | ||
_invariant_FS4_FS5_FS6_FS7_FS8(_grantFund, _standardHandler); | ||
|
||
// finalize invariants | ||
_invariant_CS1_CS2_CS3_CS4_CS5_CS6_CS7(_grantFund, _standardHandler); | ||
_invariant_ES1_ES2_ES3_ES4_ES5(_grantFund, _standardHandler); | ||
_invariant_DR1_DR2_DR3_DR4_DR5(_grantFund, _standardHandler); | ||
|
||
// distribution period invariants | ||
_invariant_DP1_DP2_DP3_DP4_DP5(_grantFund, _standardHandler); | ||
_invariant_DP6(_grantFund, _standardHandler); | ||
_invariant_T1_T2(_grantFund); | ||
} | ||
|
||
function invariant_call_summary() external useCurrentBlock { | ||
uint24 distributionId = _grantFund.getDistributionId(); | ||
|
||
_logger.logCallSummary(); | ||
_logger.logTimeSummary(); | ||
_logger.logProposalSummary(); | ||
console.log("scenario type", uint8(_standardHandler.getCurrentScenarioType())); | ||
|
||
while (distributionId > 0) { | ||
|
||
_logger.logFundingSummary(distributionId); | ||
_logger.logFinalizeSummary(distributionId); | ||
_logger.logActorSummary(distributionId, true, true); | ||
_logger.logActorDelegationRewards(distributionId); | ||
|
||
--distributionId; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.18; | ||
|
||
import { Test } from "@std/Test.sol"; | ||
|
||
import { Deployer } from "../../src/grants/Deployer.sol"; | ||
import { GrantFund } from "../../src/grants/GrantFund.sol"; | ||
import { TestAjnaToken } from "../utils/harness/TestAjnaToken.sol"; | ||
|
||
contract DeployerTest is Test { | ||
|
||
function testGrantFundDeployment() external { | ||
address owner = makeAddr("owner"); | ||
vm.startPrank(owner); | ||
|
||
uint256 treasury = 50_000_000 * 1e18; | ||
|
||
TestAjnaToken ajnaToken = new TestAjnaToken(); | ||
ajnaToken.mint(owner, treasury); | ||
|
||
Deployer deployer = new Deployer(); | ||
ajnaToken.approve(address(deployer), treasury); | ||
|
||
GrantFund grantFund = deployer.deployGrantFund(address(ajnaToken), treasury); | ||
|
||
assertEq(grantFund.getDistributionId(), 1); | ||
|
||
(,,,uint256 fundAvailable,,) = grantFund.getDistributionPeriodInfo(1); | ||
|
||
assertEq(grantFund.treasury(), treasury - fundAvailable); | ||
|
||
assertEq(fundAvailable, treasury * 3 / 100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters