Skip to content

Commit

Permalink
feat: burn method
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Nov 30, 2024
1 parent 13b1951 commit 6844f53
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ethereum/contracts/Ekoke.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions ethereum/test/Ekoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});
});

0 comments on commit 6844f53

Please sign in to comment.