Skip to content

Commit

Permalink
feat: availableReward
Browse files Browse the repository at this point in the history
  • Loading branch information
veeso committed Nov 22, 2024
1 parent 88fd932 commit 57b6ab3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ethereum/contracts/RewardPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ contract RewardPool is Ownable {
emit RewardSent(_to, _amount);
}

/// @notice Get the available reward in the reward pool
/// @return available the amount of EKOKE tokens available for the reward
function availableReward() external view returns (uint256 available) {
uint256 mintedAmount = Ekoke(ekoke).rewardPoolMintedSupply();
uint256 maximumRewardSupply = Ekoke(ekoke).MAX_REWARD_POOL_MINT();

return maximumRewardSupply - (mintedAmount + reservedAmount);
}

/// @notice Set the address of the marketplace
/// @param _marketplace The address of the marketplace
function adminSetMarketplace(address _marketplace) external onlyOwner {
Expand Down
24 changes: 24 additions & 0 deletions ethereum/test/RewardPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,28 @@ describe("RewardPool", () => {
rewardPool.connect(marketplace).sendReward(alice.address, totalReward * 2)
).to.be.revertedWith("RewardPool: not enough reserved amount");
});

it("Should tell available rewards", async () => {
const { rewardPool, deferred, ekoke, alice } = deploy;

await rewardPool.connect(deferred).reservePool(10_000, 1000);
const reserved = await rewardPool.reservedAmount();

// trick to change temporarily the reward pool address
await ekoke.adminSetRewardPoolAddress(alice.address);

// mint some rewards on ekoke
await ekoke.connect(alice).mintRewardTokens(alice.address, 100_000_000);

// trick to change temporarily the reward pool address
await ekoke.adminSetRewardPoolAddress(rewardPool.getAddress());

const expectedAvailable =
(await ekoke.MAX_REWARD_POOL_MINT()) - reserved - BigInt(100_000_000);

// check available
const availableReward = await rewardPool.availableReward();

expect(availableReward).to.equal(expectedAvailable);
});
});

0 comments on commit 57b6ab3

Please sign in to comment.