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

MolochV2 event spec feedback WIP #68

Open
wants to merge 6 commits into
base: pull-pattern
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
28 changes: 18 additions & 10 deletions contracts/Moloch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ contract Moloch is ReentrancyGuard {
// ***************
// EVENTS
// ***************
event SubmitProposal(uint256 proposalIndex, address indexed delegateKey, address indexed memberAddress, address indexed applicant, uint256 sharesRequested, uint256 lootRequested, uint256 tributeOffered, address tributeToken, uint256 paymentRequested, address paymentToken);
event SponsorProposal(address indexed delegateKey, address indexed memberAddress, uint256 proposalIndex, uint256 proposalQueueIndex, uint256 startingPeriod);
event SubmitVote(uint256 indexed proposalIndex, address indexed delegateKey, address indexed memberAddress, uint8 uintVote);
event SummonComplete(address indexed summoner, address[] tokens, uint256 summoningTime, uint256 periodDuration, uint256 votingPeriodLength, uint256 gracePeriodLength, uint256 proposalDeposit, uint256 dilutionBound, uint256 processingReward);
event SubmitProposal(address indexed applicant, uint256 sharesRequested, uint256 lootRequested, uint256 tributeOffered, address tributeToken, uint256 paymentRequested, address paymentToken, string details, bool[6] flags, uint256 proposalId, address indexed delegateKey, address indexed memberAddress);
event SponsorProposal(address indexed delegateKey, address indexed memberAddress, uint256 proposalId, uint256 proposalIndex, uint256 startingPeriod);
event SubmitVote(uint256 proposalId, uint256 indexed proposalIndex, address indexed delegateKey, address indexed memberAddress, uint8 uintVote);
event ProcessProposal(uint256 indexed proposalIndex, uint256 indexed proposalId, bool didPass);
event ProcessWhitelistProposal(uint256 indexed proposalIndex, uint256 indexed proposalId, bool didPass);
event ProcessGuildKickProposal(uint256 indexed proposalIndex, uint256 indexed proposalId, bool didPass);
event Ragequit(address indexed memberAddress, uint256 sharesToBurn, uint256 lootToBurn);
event CancelProposal(uint256 indexed proposalIndex, address applicantAddress);
event Ragekick(address indexed memberAddress, uint256 lootToBurn);
event CancelProposal(uint256 indexed proposalId, address memberAddress, address applicantAddress);
event UpdateDelegateKey(address indexed memberAddress, address newDelegateKey);
event SummonComplete(address indexed summoner, uint256 shares);

event InternalTransfer(address indexed from, address indexed to, address indexed token, uint256 amount);
event Withdraw(address indexed memberAddress, address token, uint256 amount);
event Deposit(address indexed memberAddress, address token, uint256 amount);
// *******************
// INTERNAL ACCOUNTING
// *******************
Expand Down Expand Up @@ -190,6 +195,7 @@ contract Moloch is ReentrancyGuard {
// collect tribute from proposer and store it in the Moloch until the proposal is processed
require(IERC20(tributeToken).transferFrom(msg.sender, address(this), tributeOffered), "tribute token transfer failed");
unsafeAddToBalance(ESCROW, tributeToken, tributeOffered);
emit Deposit(msg.sender, tributeToken, tributeOffered);

bool[6] memory flags; // [sponsored, processed, didPass, cancelled, whitelist, guildkick]

Expand Down Expand Up @@ -261,6 +267,7 @@ contract Moloch is ReentrancyGuard {
// collect proposal deposit from sponsor and store it in the Moloch until the proposal is processed
require(IERC20(depositToken).transferFrom(msg.sender, address(this), proposalDeposit), "proposal deposit token transfer failed");
unsafeAddToBalance(ESCROW, depositToken, proposalDeposit);
emit Deposit(msg.sender, depositToken, proposalDeposit);

Proposal storage proposal = proposals[proposalId];

Expand Down Expand Up @@ -518,6 +525,7 @@ contract Moloch is ReentrancyGuard {
}

function ragequit(uint256 sharesToBurn, uint256 lootToBurn) public nonReentrant onlyMember {
emit Ragequit(msg.sender, sharesToBurn, lootToBurn);
_ragequit(msg.sender, sharesToBurn, lootToBurn, approvedTokens);
}

Expand Down Expand Up @@ -548,8 +556,6 @@ contract Moloch is ReentrancyGuard {
userTokenBalances[memberAddress][tokens[i]] += amountToRagequit;
}
}

emit Ragequit(msg.sender, sharesToBurn, lootToBurn);
}

function ragekick(address memberToKick) public nonReentrant {
Expand All @@ -558,8 +564,9 @@ contract Moloch is ReentrancyGuard {
require(member.jailed != 0, "member must be in jail");
require(member.loot > 0, "member must have some loot"); // note - should be impossible for jailed member to have shares
require(canRagequit(member.highestIndexYesVote), "cannot ragequit until highest index proposal member voted YES on is processed");

_ragequit(memberToKick, 0, member.loot, approvedTokens);

emit Ragekick(memberToKick, member.loot);
_ragequit(memberToKick, 0, member.loot, approvedTokens);
}

function withdrawBalance(address token, uint256 amount) public nonReentrant {
Expand Down Expand Up @@ -672,6 +679,7 @@ contract Moloch is ReentrancyGuard {
function unsafeInternalTransfer(address from, address to, address token, uint256 amount) internal {
unsafeSubtractFromBalance(from, token, amount);
unsafeAddToBalance(to, token, amount);
emit InternalTransfer( from, to, token, amount);
}

function fairShare(uint256 balance, uint256 shares, uint256 totalShares) internal pure returns (uint256) {
Expand Down
20 changes: 2 additions & 18 deletions test/molochV2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2662,7 +2662,7 @@ contract('Moloch', ([creator, summoner, applicant1, applicant2, processor, deleg
expectedApplicantBalance: 0,
})

const emittedLogs = await moloch.processWhitelistProposal(firstProposalIndex, { from: processor })
await moloch.processWhitelistProposal(firstProposalIndex, { from: processor })

const newApprovedToken = await moloch.approvedTokens(1) // second token to be added
assert.equal(newApprovedToken, newToken.address)
Expand Down Expand Up @@ -2701,14 +2701,6 @@ contract('Moloch', ([creator, summoner, applicant1, applicant2, processor, deleg
}
})

// Verify process proposal event
const { logs } = emittedLogs
const log = logs[0]
const { proposalIndex, proposalId, didPass } = log.args
assert.equal(log.event, 'ProcessWhitelistProposal')
assert.equal(proposalIndex, 0)
assert.equal(proposalId, 0)
assert.equal(didPass, true)
})

it('happy path - guild kick member', async () => {
Expand Down Expand Up @@ -2804,7 +2796,7 @@ contract('Moloch', ([creator, summoner, applicant1, applicant2, processor, deleg
await moveForwardPeriods(deploymentConfig.VOTING_DURATON_IN_PERIODS)
await moveForwardPeriods(deploymentConfig.GRACE_DURATON_IN_PERIODS)

const emittedLogs = await moloch.processGuildKickProposal(secondProposalIndex, { from: applicant })
await moloch.processGuildKickProposal(secondProposalIndex, { from: applicant })

// shares removed
await verifyMember({
Expand Down Expand Up @@ -2832,14 +2824,6 @@ contract('Moloch', ([creator, summoner, applicant1, applicant2, processor, deleg
expectedFlags: [true, true, true, false, false, true]
})

// Verify process proposal event
const { logs } = emittedLogs
const log = logs[0]
const { proposalIndex, proposalId, didPass } = log.args
assert.equal(log.event, 'ProcessGuildKickProposal')
assert.equal(proposalIndex, secondProposalIndex)
assert.equal(proposalId, 1)
assert.equal(didPass, true)
})

it('edge case - paymentRequested more than funds in the bank', async () => {
Expand Down
Loading