Skip to content

Commit

Permalink
Add deployer contract to deploy grantfund, fund treasury and startNew…
Browse files Browse the repository at this point in the history
…Distribution
  • Loading branch information
prateek105 committed Aug 4, 2023
1 parent 545ab18 commit 82bb87c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/grants/Deployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;

import { IERC20 } from "@oz/token/ERC20/IERC20.sol";

import { GrantFund } from "./GrantFund.sol";

contract Deployer {

GrantFund public grantFund;

function deployGrantFund(address ajnaToken_, uint256 treasury_) public returns (GrantFund) {

IERC20(ajnaToken_).transferFrom(msg.sender, address(this), treasury_);

grantFund = new GrantFund(ajnaToken_);

IERC20(ajnaToken_).approve(address(grantFund), treasury_);

grantFund.fundTreasury(treasury_);

grantFund.startNewDistributionPeriod();
return grantFund;
}
}
32 changes: 32 additions & 0 deletions test/unit/Deployer.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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);
}
}

0 comments on commit 82bb87c

Please sign in to comment.