Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GrantFund Deployer contract #125

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ deploy-grantfund:
deploy-burnwrapper:
eval AJNA_TOKEN=${ajna}
forge script script/BurnWrapper.s.sol:DeployBurnWrapper \
--rpc-url ${ETH_RPC_URL} --sender ${DEPLOY_ADDRESS} --keystore ${DEPLOY_KEY} --broadcast -vvv --verify
--rpc-url ${ETH_RPC_URL} --sender ${DEPLOY_ADDRESS} --keystore ${DEPLOY_KEY} --broadcast -vvv --verify
deploy-grantfund-deployer:
forge create --rpc-url ${ETH_RPC_URL} --keystore ${DEPLOY_KEY} --verify src/grants/Deployer.sol:Deployer
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ make deploy-grantfund ajna=<AJNA_TOKEN_ADDRESS>
```

See [GRANT_FUND.md](src/grants/GRANT_FUND.md#deployment) for next steps.

#### Grant Fund deployer
Deployer contract can be used to deploy grant fund, fund treasury and start distribution in a single call to avoid someone starting a distribution without treasury.

Steps to use Deployer contract to deploy grant Fund:
1. Deploy `Deployer` contract.
2. Approve `<treasury_amount>` `AJNA ` to `Deployer` contract from `treasury` address.
3. Call `deployGrantFund(address ajnaToken_, uint256 treasury_)` from `treasury` address to deploy grant fund and start distribution with treasury amount.
4. GrantFund can be verified using remix contract verification plugin, foundry or hardhat.

To deploy Deployer contract, run:
```
make deploy-grantfund-deployer
```
40 changes: 40 additions & 0 deletions src/grants/Deployer.sol
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_);
grandizzy marked this conversation as resolved.
Show resolved Hide resolved

// 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_;
}
}
34 changes: 34 additions & 0 deletions test/unit/Deployer.t.sol
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);
prateek105 marked this conversation as resolved.
Show resolved Hide resolved

assertEq(fundAvailable, treasury * 3 / 100);
}
}
Loading