Skip to content

Commit

Permalink
Store Sablier streamId for each grant created
Browse files Browse the repository at this point in the history
  • Loading branch information
apbendi committed Apr 25, 2020
1 parent cd79263 commit 54b124b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
9 changes: 7 additions & 2 deletions contracts/GuildBank.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";

interface ISablier {
function createStream(address recipient, uint256 deposit, address tokenAddress, uint256 startTime, uint256 stopTime) external returns (uint256);
function cancelStream(uint256 streamId) external returns (bool);
}

contract GuildBank {
Expand All @@ -29,8 +30,12 @@ contract GuildBank {
return approvedToken.transfer(receiver, amount);
}

function initiateStream(address grantee, uint256 amount, uint256 duration) public onlyOwner {
sablier.createStream(grantee, amount, address(approvedToken), block.timestamp, block.timestamp + duration);
function initiateStream(address grantee, uint256 amount, uint256 startDate, uint256 endDate) public onlyOwner returns (uint256) {
return sablier.createStream(grantee, amount, address(approvedToken), startDate, endDate);
}

function revokeStream(uint256 streamId) public onlyOwner {
sablier.cancelStream(streamId);
}

modifier onlyOwner() {
Expand Down
26 changes: 19 additions & 7 deletions contracts/Moloch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ contract Moloch {
uint256 highestIndexYesVote; // highest proposal index # on which the member voted YES
}

struct Grant {
uint256 streamId; // Sablier Stream ID of the grant
uint256 proposalIndex; // Position of this Grant in the proposal queue
uint256 startDate; // When stream actually began
uint256 endDate; // When stream will/did end
}

struct Proposal {
address proposer; // the member who submitted the proposal
address applicant; // the applicant who wishes to become a member or receive a grant - this key will be used for withdrawals
Expand All @@ -89,6 +96,7 @@ contract Moloch {
mapping (address => Member) public members;
mapping (address => address) public memberAddressByDelegateKey;
Proposal[] public proposalQueue;
Grant[] public grants;

/********
MODIFIERS
Expand Down Expand Up @@ -407,15 +415,19 @@ contract Moloch {
if (didPass && !proposal.aborted && hasFunds) {

proposal.didPass = true;
guildBank.initiateStream(proposal.applicant, proposal.tokenTribute, proposal.grantDuration);

// TODO: Call guildbank funciton to start the stream!
uint256 start = block.timestamp;
uint256 end = block.timestamp + proposal.grantDuration;
uint256 streamId = guildBank.initiateStream(proposal.applicant, proposal.tokenTribute, start, end);

// transfer tokens to guild bank
// require(
// approvedToken.transfer(address(guildBank), proposal.tokenTribute),
// "Moloch::processProposal - token transfer to guild bank failed"
// );
Grant memory grant = Grant({
streamId: streamId,
proposalIndex: proposalIndex,
startDate: start,
endDate: end
});

grants.push(grant);

// PROPOSAL FAILED OR ABORTED
} else {
Expand Down
3 changes: 3 additions & 0 deletions test/endaoment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ describe('Moloch', () => {
await time.increase(VOTING_DURATION + GRACE_DURATION);

await this.instance.processGrantProposal(2, {from: grantee1});
const grant = await this.instance.grants(0);

expect(grant.proposalIndex.toString()).to.equal('2');
});

// TODO: Test proposal fails if ragequitters deplete required funds
Expand Down

0 comments on commit 54b124b

Please sign in to comment.