From 6844f53217ed96ce064b97c6142f41a30a69e687 Mon Sep 17 00:00:00 2001 From: veeso Date: Sat, 30 Nov 2024 17:15:19 +0100 Subject: [PATCH] feat: burn method --- ethereum/contracts/Ekoke.sol | 15 ++++++++++++++ ethereum/test/Ekoke.ts | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/ethereum/contracts/Ekoke.sol b/ethereum/contracts/Ekoke.sol index 5ae2f24..b6a599b 100644 --- a/ethereum/contracts/Ekoke.sol +++ b/ethereum/contracts/Ekoke.sol @@ -48,6 +48,21 @@ contract Ekoke is ERC20, Ownable { return DECIMALS; } + /// @notice Burn the provided amount of tokens. Burned tokens are returned to the reward pool. + /// @param amount the amount of tokens to burn. + function burn(uint256 amount) public { + // check if amount is less or equal than `rewardPoolMintedSupply` + require( + amount <= rewardPoolMintedSupply, + "Ekoke: amount exceeds the reward pool minted supply" + ); + + // burn the tokens + _burn(msg.sender, amount); + // decrement the amount of tokens minted by the reward pool + rewardPoolMintedSupply -= amount; + } + /// @notice Mint the provided amount of tokens to the recipient. Only the reward pool can call this function. /// @param _to the address that will receive the ETH Ekoke tokens. /// @param _amount the amount of tokens to mint. diff --git a/ethereum/test/Ekoke.ts b/ethereum/test/Ekoke.ts index 9d63458..c7f464a 100644 --- a/ethereum/test/Ekoke.ts +++ b/ethereum/test/Ekoke.ts @@ -137,4 +137,42 @@ describe("Ekoke", () => { await token.transferOwnership(rewardPool.address); expect(await token.owner()).to.equal(rewardPool.address); }); + + it("should burn tokens to allow more minting by the reward pool", async () => { + const { token, rewardPool, owner } = deploy; + const maxRewardSupply = await token.MAX_REWARD_POOL_MINT(); + + await token.adminSetRewardPoolAddress(rewardPool.address); + await token + .connect(rewardPool) + .mintRewardTokens(owner.address, maxRewardSupply); + + expect(await token.balanceOf(owner.address)).to.equal(maxRewardSupply); + expect(await token.rewardPoolMintedSupply()).to.equal(maxRewardSupply); + + // burn some tokens + const amount = 100_000; + await token.burn(amount); + + // mint more tokens + expect(await token.rewardPoolMintedSupply()).to.equal( + maxRewardSupply - BigInt(amount) + ); + expect(await token.balanceOf(owner.address)).to.equal( + maxRewardSupply - BigInt(amount) + ); + + // should mint more tokens + await token.connect(rewardPool).mintRewardTokens(owner.address, 100_000); + }); + + it("should not allowing burning if reward pool has not mint so much", async () => { + const { token, owner } = deploy; + + await token.adminMint(owner.address, 1_000); + + await expect(token.burn(1000)).to.be.revertedWith( + "Ekoke: amount exceeds the reward pool minted supply" + ); + }); });