Skip to content
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
29 changes: 29 additions & 0 deletions contracts/JoeToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ contract JoeToken is ERC20("JoeToken", "JOE"), Ownable {
return _delegates[delegator];
}

/**
* @notice Transfer `rawAmount` tokens from `msg.sender` to `dst`
* @param dst The address of the destination account
* @param rawAmount The number of tokens to transfer
* @return Whether or not the transfer succeeded
*/
function transfer(address dst, uint256 rawAmount) public override returns (bool) {
super.transfer(dst, rawAmount);
_moveDelegates(_delegates[msg.sender], _delegates[dst], rawAmount);
return true;
}

/**
* @notice Transfer `rawAmount` tokens from `src` to `dst`
* @param src The address of the source account
* @param dst The address of the destination account
* @param rawAmount The number of tokens to transfer
* @return Whether or not the transfer succeeded
*/
function transferFrom(
address src,
address dst,
uint256 rawAmount
) public override returns (bool) {
super.transferFrom(src, dst, rawAmount);
_moveDelegates(_delegates[src], _delegates[dst], rawAmount);
return true;
}

/**
* @notice Delegate votes from `msg.sender` to `delegatee`
* @param delegatee The address to delegate votes to
Expand Down
12 changes: 12 additions & 0 deletions test/JoeToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ describe("JoeToken", function () {
await this.joe.mint(this.alice.address, "500000000000000000000000000")
})

it("should not double spend delegation votes", async function () {
await this.joe.mint(this.alice.address, "100")
await this.joe.delegate(this.bob.address)

await this.joe.transfer(this.carol.address, "100")
await this.joe.connect(this.carol).delegate(this.bob.address)

const votes = await this.joe.getCurrentVotes(this.bob.address)

expect(votes).to.equal("100") // bob should have 100 votes instead of 200
})

after(async function () {
await network.provider.request({
method: "hardhat_reset",
Expand Down