This tutorial explains how to interact with the LiquidityIncentives contract, which manages liquidity provider tiers, yield farming, and flash loans on the Backr platform.
- Three tiers with increasing benefits
- Based on liquidity provided
- Affects reward multipliers and flash loan fees
- Multiple staking pools
- Time-based rewards
- Customizable reward rates
- Tier-based access
- Variable fees based on tier
- Instant borrowing and repayment
// Tier 1
- Minimum Liquidity: 0.001 tokens
- Reward Multiplier: 1x
- Flash Loan Fee: 0.3%
// Tier 2
- Minimum Liquidity: 0.01 tokens
- Reward Multiplier: 1.5x
- Flash Loan Fee: 0.25%
// Tier 3
- Minimum Liquidity: 0.1 tokens
- Reward Multiplier: 2x
- Flash Loan Fee: 0.2%
// Get user's current tier
uint256 tier = liquidityIncentives.userTiers(userAddress);
// Get tier details
(uint256 minLiquidity, uint256 rewardMultiplier, uint256 flashLoanFee, bool enabled) =
liquidityIncentives.tiers(tierLevel);
// Only owner can create pools
liquidityIncentives.createPool(
1, // poolId
100000000 // rewardRate (tokens per second)
);
// First approve tokens
token.approve(liquidityIncentives, amount);
// Stake tokens in pool
liquidityIncentives.stake(poolId, amount);
// Unstake tokens
liquidityIncentives.unstake(poolId, amount);
// Claim rewards
liquidityIncentives.claimRewards(poolId);
// Check pending rewards
uint256 pending = liquidityIncentives.calculatePendingRewards(poolId, userAddress);
// Implement flash loan receiver interface
contract MyContract is IFlashLoanReceiver {
function executeOperation(
uint256 amount,
uint256 fee,
bytes calldata data
) external override {
// Use borrowed funds here
// Ensure repayment
token.transfer(msg.sender, amount + fee);
}
}
// Request flash loan
liquidityIncentives.flashLoan(
amount,
abi.encode(/* your parameters */)
);
- Must have active tier
- Sufficient contract balance
- Complete repayment in same transaction
- Pay tier-based fee
-
Tier Events:
event TierUpdated( uint256 tierId, uint256 minLiquidity, uint256 rewardMultiplier, uint256 flashLoanFee ); event UserTierChanged( address indexed user, uint256 oldTier, uint256 newTier );
-
Yield Farming Events:
event PoolCreated(uint256 poolId, uint256 rewardRate); event Staked(address indexed user, uint256 poolId, uint256 amount); event Unstaked(address indexed user, uint256 poolId, uint256 amount); event RewardsClaimed(address indexed user, uint256 poolId, uint256 amount);
-
Flash Loan Events:
event FlashLoanTaken( address indexed borrower, uint256 amount, uint256 fee ); event FlashLoanRepaid( address indexed borrower, uint256 amount, uint256 fee );
-
Tier Management
- Monitor liquidity levels
- Track tier changes
- Understand benefits
- Plan for upgrades
-
Yield Farming
- Calculate optimal staking
- Monitor reward rates
- Time claims efficiently
- Consider gas costs
-
Flash Loans
- Verify tier status
- Calculate fees accurately
- Ensure repayment
- Handle failures gracefully
// Complete yield farming flow
contract YieldFarmingStrategy {
LiquidityIncentives public incentives;
PlatformToken public token;
constructor(address _incentives, address _token) {
incentives = LiquidityIncentives(_incentives);
token = PlatformToken(_token);
}
function startFarming(uint256 poolId, uint256 amount) external {
// 1. Approve tokens
token.approve(address(incentives), amount);
// 2. Stake in pool
incentives.stake(poolId, amount);
// 3. Monitor rewards
uint256 pending = incentives.calculatePendingRewards(
poolId,
address(this)
);
// 4. Claim when profitable
if (pending > getGasCost()) {
incentives.claimRewards(poolId);
}
}
}
contract FlashLoanExample is IFlashLoanReceiver {
LiquidityIncentives public incentives;
PlatformToken public token;
constructor(address _incentives, address _token) {
incentives = LiquidityIncentives(_incentives);
token = PlatformToken(_token);
}
function executeFlashLoan(uint256 amount) external {
// 1. Request flash loan
incentives.flashLoan(
amount,
abi.encode("Example")
);
}
function executeOperation(
uint256 amount,
uint256 fee,
bytes calldata data
) external override {
// 2. Use funds
// ... your arbitrage or other logic here ...
// 3. Repay loan
uint256 repayAmount = amount + fee;
require(
token.transfer(msg.sender, repayAmount),
"Repayment failed"
);
}
}
Common errors you might encounter:
InvalidTier() // Invalid tier parameters
InvalidPool() // Pool doesn't exist
PoolNotActive() // Pool is not accepting stakes
InsufficientBalance() // Not enough tokens
FlashLoanActive() // Another loan in progress
UnauthorizedFlashLoan() // Not eligible for flash loans
FlashLoanRepaymentFailed() // Repayment unsuccessful
-
Tier System
- Verify tier updates
- Monitor threshold changes
- Track user eligibility
-
Yield Farming
- Check reward calculations
- Monitor pool balances
- Verify staking amounts
- Track reward distribution
-
Flash Loans
- Validate borrower eligibility
- Ensure proper repayment
- Monitor loan usage
- Track fee collection
-
General Security
- Monitor contract state
- Watch for paused status
- Track owner actions
- Verify calculations
The LiquidityIncentives contract works closely with the LiquidityPool:
- Automatic tier updates based on liquidity
- Reward multipliers affect earnings
- Flash loan access tied to liquidity
- Pool state affects incentives
Remember to:
- Monitor both contracts
- Understand interactions
- Track state changes
- Coordinate operations