Liquidity pools ensure there is sufficient market liquidity for trading KLIKcoin on decentralized exchanges (DEXs). Liquidity providers (LPs) deposit equal amounts of KLIKcoin and ETH into the liquidity pool. In return, they earn both transaction fees and liquidity mining rewards.
How Liquidity Pools Work:
Provide Liquidity: Users deposit KLIKcoin and ETH into the pool, ensuring trading liquidity for the KLIK/ETH pair.
Earn Transaction Fees: For every trade in the pool, a 0.3% fee is charged and distributed proportionally to liquidity providers based on their share of the pool.
Liquidity Mining Rewards: LPs also earn KLIKcoin rewards from the 1.75 billion KLIKcoins allocated to liquidity mining. These rewards are distributed over time, with larger rewards for long-term liquidity provision.
Solidity Code for Liquidity Pool Mechanism:
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract KLIKLiquidityPool is Ownable {
ERC20 public klikToken;
ERC20 public ethToken;
uint256 public rewardRate;
uint256 public totalLiquidity;
mapping(address => uint256) public liquidityProvided;
mapping(address => uint256) public rewards;
constructor(ERC20 _klikToken, ERC20 _ethToken, uint256 _rewardRate) {
klikToken = _klikToken;
ethToken = _ethToken;
rewardRate = _rewardRate; // Reward rate for distributing KLIK rewards
}
// Stake KLIK and ETH to provide liquidity
function provideLiquidity(uint256 klikAmount, uint256 ethAmount) external {
require(klikToken.balanceOf(msg.sender) >= klikAmount, "Insufficient KLIK balance");
require(ethToken.balanceOf(msg.sender) >= ethAmount, "Insufficient ETH balance");
klikToken.transferFrom(msg.sender, address(this), klikAmount);
ethToken.transferFrom(msg.sender, address(this), ethAmount);
liquidityProvided[msg.sender] += klikAmount + ethAmount; // Record total liquidity provided
totalLiquidity += klikAmount + ethAmount; // Update total pool liquidity
rewards[msg.sender] += (klikAmount + ethAmount) * rewardRate; // Reward based on liquidity provided
}
// Withdraw liquidity from the pool
function withdrawLiquidity(uint256 klikAmount, uint256 ethAmount) external {
require(liquidityProvided[msg.sender] >= klikAmount + ethAmount, "Insufficient liquidity");
klikToken.transfer(msg.sender, klikAmount);
ethToken.transfer(msg.sender, ethAmount);
liquidityProvided[msg.sender] -= klikAmount + ethAmount; // Update liquidity records
totalLiquidity -= klikAmount + ethAmount;
}
// Claim earned KLIK rewards
function claimRewards() external {
uint256 reward = rewards[msg.sender];
require(reward > 0, "No rewards available");
rewards[msg.sender] = 0; // Reset reward balance
klikToken.transfer(msg.sender, reward); // Transfer KLIK rewards
}
// Distribute transaction fees proportionally
function distributeFees(uint256 klikFee, uint256 ethFee) external onlyOwner {
for (address provider : getLiquidityProviders()) {
uint256 providerShare = (liquidityProvided[provider] / totalLiquidity);
klikToken.transfer(provider, klikFee * providerShare);
ethToken.transfer(provider, ethFee * providerShare);
}
}
}