From 206c8b6b128ab6666ed86c460ef19e13a3730733 Mon Sep 17 00:00:00 2001 From: Ben DiFrancesco Date: Fri, 24 Apr 2020 06:57:18 -0400 Subject: [PATCH] Store Sablier streamId for each grant created --- contracts/GuildBank.sol | 9 +++++++-- contracts/Moloch.sol | 26 +++++++++++++++++++------- test/endaoment-test.js | 3 +++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/contracts/GuildBank.sol b/contracts/GuildBank.sol index e8e3306..c2621f1 100644 --- a/contracts/GuildBank.sol +++ b/contracts/GuildBank.sol @@ -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 { @@ -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() { diff --git a/contracts/Moloch.sol b/contracts/Moloch.sol index e1924e0..cf34f4a 100644 --- a/contracts/Moloch.sol +++ b/contracts/Moloch.sol @@ -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 @@ -89,6 +96,7 @@ contract Moloch { mapping (address => Member) public members; mapping (address => address) public memberAddressByDelegateKey; Proposal[] public proposalQueue; + Grant[] public grants; /******** MODIFIERS @@ -405,15 +413,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 { diff --git a/test/endaoment-test.js b/test/endaoment-test.js index 51a921f..d0fbc9e 100644 --- a/test/endaoment-test.js +++ b/test/endaoment-test.js @@ -112,6 +112,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