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

added beneficiary #53

Open
wants to merge 1 commit into
base: feature/multiple-queued-fc
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions contracts/JBTokenStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,12 @@ contract JBTokenStore is JBControllerUtility, JBOperatable, IJBTokenStore {
/// @param _holder The owner of the tokens being claimed.
/// @param _projectId The ID of the project whose tokens are being claimed.
/// @param _amount The amount of tokens to claim.
/// @param _beneficiary The account into which the claimed tokens will go.
function claimFor(
address _holder,
uint256 _projectId,
uint256 _amount
uint256 _amount,
address _beneficiary
) external override requirePermission(_holder, _projectId, JBOperations.CLAIM) {
// Get a reference to the project's current token.
IJBToken _token = tokenOf[_projectId];
Expand All @@ -324,9 +326,9 @@ contract JBTokenStore is JBControllerUtility, JBOperatable, IJBTokenStore {
}

// Mint the equivalent amount of the project's token for the holder.
_token.mint(_projectId, _holder, _amount);
_token.mint(_projectId, _beneficiary, _amount);

emit Claim(_holder, _projectId, _unclaimedBalance, _amount, msg.sender);
emit Claim(_holder, _projectId, _unclaimedBalance, _amount, _beneficiary, msg.sender);
}

/// @notice Allows a holder to transfer unclaimed tokens to another account.
Expand Down
8 changes: 7 additions & 1 deletion contracts/interfaces/IJBTokenStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface IJBTokenStore {
uint256 indexed projectId,
uint256 initialUnclaimedBalance,
uint256 amount,
address beneficiary,
address caller
);

Expand Down Expand Up @@ -87,7 +88,12 @@ interface IJBTokenStore {
bool preferClaimedTokens
) external;

function claimFor(address holder, uint256 projectId, uint256 amount) external;
function claimFor(
address holder,
uint256 projectId,
uint256 amount,
address benenficiary
) external;

function transferFrom(
address holder,
Expand Down
2 changes: 1 addition & 1 deletion test/jb_funding_cycle_store/configure_for.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ijbFundingCycleBallot from '../../artifacts/contracts/interfaces/IJBFundi
import { BigNumber } from 'ethers';
import errors from '../helpers/errors.json';

describe.only('JBFundingCycleStore::configureFor(...)', function () {
describe('JBFundingCycleStore::configureFor(...)', function () {
const PROJECT_ID = 2;

const EMPTY_FUNDING_CYCLE = {
Expand Down
63 changes: 57 additions & 6 deletions test/jb_token_store/claim_for.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('JBTokenStore::claimFor(...)', function () {
const TOKEN_SYMBOL = 'TEST';

async function setup() {
const [deployer, controller, newHolder, projectOwner] = await ethers.getSigners();
const [deployer, controller, newHolder, beneficiary, projectOwner] = await ethers.getSigners();

const mockJbDirectory = await deployMockContract(deployer, jbDirectory.abi);
const mockJbFundingCycleStore = await deployMockContract(deployer, jbFundingCycleStore.abi);
Expand All @@ -39,6 +39,7 @@ describe('JBTokenStore::claimFor(...)', function () {
return {
controller,
newHolder,
beneficiary,
projectOwner,
mockJbDirectory,
mockJbProjects,
Expand Down Expand Up @@ -82,7 +83,7 @@ describe('JBTokenStore::claimFor(...)', function () {
// Claim the unclaimed tokens
const claimForTx = await jbTokenStore
.connect(controller)
.claimFor(newHolder.address, PROJECT_ID, amountToClaim);
.claimFor(newHolder.address, PROJECT_ID, amountToClaim, newHolder.address);

expect(await jbTokenStore.unclaimedBalanceOf(newHolder.address, PROJECT_ID)).to.equal(
numTokens - amountToClaim,
Expand All @@ -92,14 +93,64 @@ describe('JBTokenStore::claimFor(...)', function () {

await expect(claimForTx)
.to.emit(jbTokenStore, 'Claim')
.withArgs(newHolder.address, PROJECT_ID, numTokens, amountToClaim, controller.address);
.withArgs(newHolder.address, PROJECT_ID, numTokens, amountToClaim, newHolder.address, controller.address);
});
it('Should claim tokens to a different beneficiary and emit event', async function () {
const {
controller,
newHolder,
projectOwner,
mockJbDirectory,
mockJbOperatorStore,
mockJbProjects,
jbTokenStore,
beneficiary,
CLAIM_INDEX,
addrs
} = await setup();

// Mint access:
await mockJbDirectory.mock.controllerOf.withArgs(PROJECT_ID).returns(controller.address);

// Issue access:
await mockJbProjects.mock.ownerOf.withArgs(PROJECT_ID).returns(controller.address);

await jbTokenStore.connect(controller).issueFor(PROJECT_ID, TOKEN_NAME, TOKEN_SYMBOL);
await mockJbOperatorStore.mock.hasPermission
.withArgs(controller.address, newHolder.address, PROJECT_ID, CLAIM_INDEX)
.returns(true);

// Mint more unclaimed tokens
const numTokens = 20;
await jbTokenStore
.connect(controller)
.mintFor(newHolder.address, PROJECT_ID, numTokens, /* preferClaimedTokens= */ false);

const amountToClaim = numTokens - 1;

// Claim the unclaimed tokens
const claimForTx = await jbTokenStore
.connect(controller)
.claimFor(newHolder.address, PROJECT_ID, amountToClaim, beneficiary.address);

expect(await jbTokenStore.unclaimedBalanceOf(newHolder.address, PROJECT_ID)).to.equal(
numTokens - amountToClaim,
);
expect(await jbTokenStore.unclaimedBalanceOf(beneficiary.address, PROJECT_ID)).to.equal(0);
expect(await jbTokenStore.balanceOf(newHolder.address, PROJECT_ID)).to.equal(numTokens - amountToClaim);
expect(await jbTokenStore.balanceOf(beneficiary.address, PROJECT_ID)).to.equal(amountToClaim);
expect(await jbTokenStore.totalSupplyOf(PROJECT_ID)).to.equal(numTokens);

await expect(claimForTx)
.to.emit(jbTokenStore, 'Claim')
.withArgs(newHolder.address, PROJECT_ID, numTokens, amountToClaim, beneficiary.address, controller.address);
});
it(`Can't claim tokens if projectId isn't found`, async function () {
const { newHolder, jbTokenStore } = await setup();
const numTokens = 1;

await expect(
jbTokenStore.connect(newHolder).claimFor(newHolder.address, PROJECT_ID, numTokens),
jbTokenStore.connect(newHolder).claimFor(newHolder.address, PROJECT_ID, numTokens, newHolder.address),
).to.be.revertedWith(errors.TOKEN_NOT_FOUND);
});

Expand All @@ -119,7 +170,7 @@ describe('JBTokenStore::claimFor(...)', function () {
.mintFor(newHolder.address, PROJECT_ID, numTokens, /* preferClaimedTokens= */ false);

await expect(
jbTokenStore.connect(newHolder).claimFor(newHolder.address, PROJECT_ID, numTokens + 1),
jbTokenStore.connect(newHolder).claimFor(newHolder.address, PROJECT_ID, numTokens + 1, newHolder.address),
).to.be.revertedWith(errors.INSUFFICIENT_UNCLAIMED_TOKENS);
});
it(`Can't claim unclaimed tokens if caller lacks permission`, async function () {
Expand All @@ -128,7 +179,7 @@ describe('JBTokenStore::claimFor(...)', function () {
await expect(
jbTokenStore
.connect(controller)
.claimFor(/* holder */ newHolder.address, PROJECT_ID, /* amount= */ 1),
.claimFor(/* holder */ newHolder.address, PROJECT_ID, /* amount= */ 1, newHolder.address),
).to.be.reverted;
});
});