-
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 #125 from ajna-finance/grantfund-deployer
Add GrantFund Deployer contract
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
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
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); | ||
} | ||
} |