diff --git a/contracts/JoeToken.sol b/contracts/JoeToken.sol index 78a8322..3f7b04f 100644 --- a/contracts/JoeToken.sol +++ b/contracts/JoeToken.sol @@ -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 diff --git a/test/JoeToken.test.ts b/test/JoeToken.test.ts index c739c20..1e0153f 100644 --- a/test/JoeToken.test.ts +++ b/test/JoeToken.test.ts @@ -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",