FlashCollector is a Solidity smart contract designed to leverage Kodiak V3 flash loans for claiming tokens from the Infared BribeCollector contract and swapping them for WBERA (Wrapped BERA) on decentralized exchanges (DEXs) like Kodiak V3 and Beraswap. The contract streamlines the process of token claiming and swapping, repaying the flash loan, and keeping any remaining WBERA as profit—all in a single transaction.
This project is experimental and open-source, inviting developers and users to explore, use, and contribute to its development.
The FlashCollector contract enables users to:
- Borrow WBERA via Kodiak V3 flash loans without requiring upfront capital.
- Use the borrowed WBERA to claim tokens from the Infared
BribeCollectorcontract. - Swap the claimed tokens for WBERA or HONEY on supported DEXs (Kodiak V3 and Beraswap).
- Repay the flash loan and retain any leftover WBERA as profit.
This project is ideal for developers and traders looking to automate token claiming and arbitrage strategies efficiently.
- Flash Loan Integration: Borrows WBERA from Kodiak V3 pools to fund token claiming.
- Token Claiming: Interacts with Infared
BribeCollectorcontract to claim multiple tokens in one go. - Flexible Swapping: Supports token swaps on:
- Kodiak V3: With fee tiers of 0.3%, 0.05%, 0.01%, and 1%.
- Beraswap: Using specific pool IDs.
- Profit Maximization: Automatically calculates and sends profits in WBERA to the caller.
- Configurable Pools: Allows customization of swap pools and parameters per token.
The FlashCollector contract operates as follows:
- Initiate Flash Loan: The user calls the
initFlashfunction, passing parameters for token claiming and swapping. - Flash Loan Callback: In the
uniswapV3FlashCallbackfunction:- Approves the Infared
BribeCollectorcontract to spend the borrowed WBERA. - Claims the specified tokens from the
BribeCollectorcontract. - Swaps each claimed token for WBERA or HONEY on the configured DEX.
- If HONEY is received, swaps it for WBERA.
- Repays the flash loan (principal + fees).
- Transfers any remaining WBERA to the caller as profit.
- Approves the Infared
- Kodiak V3: Provides flash loans and handles token swaps with configurable fee tiers.
- Beraswap: Facilitates swaps using predefined pool IDs.
- BribeCollector Contract: Source of the tokens to be claimed.
To set up the project locally:
-
Install Foundry: Follow the Foundry installation guide.
-
Clone the Repository:
git clone https://github.com/infrared-dao/flash-collector.git cd flash-collector -
Install Dependencies:
forge install
-
Test:
forge test
- Compile the Contract:
forge build
- Deploy the Contract:
Set
PRIVATE_KEYin.env, then use the included deployment script:chmod +x /shell/*.sh ./shell/deploy.sh
Prepare FlashParams:
feeTokens: List of tokens to claim.feeAmounts: Amounts to claim for each token.swapPools: Array of PoolIdentifier structs defining swap configurations.
Run flash claim when conditions are correct:
```bash
./shell/run.sh
```
For each token, configure a PoolIdentifier:
poolType:0: Kodiak V3.1: Balancer.
useHoney:true: Swap to HONEY.false: Swap to WBERA.
poolData:Kodiak V3: Fee tier (e.g.,abi.encode(3000)for 0.3%).Balancer: Pool ID (e.g.,abi.encode(poolId)).
Examples:
- Kodiak V3 (0.3% fee, to WBERA):
PoolIdentifier({poolType: 0, useHoney: false, poolData: abi.encode(3000)})
- Balancer (to HONEY):
PoolIdentifier({poolType: 1, useHoney: true, poolData: abi.encode(poolId)})
We’d love your help! To contribute:
- Fork the Repository.
- Create a Branch:
git checkout -b feature/your-feature
- Commit Changes:
git commit -m "Describe your changes" - Push to Your Fork:
git push origin feature/your-feature
- Submit a Pull Request.
Please include tests and follow the project’s coding style.
This project is released under the MIT License.
Why use flash loans?
Flash loans eliminate the need for upfront capital, enabling efficient token claiming and swapping in one transaction.
How is profitability ensured?
The contract estimates swap outputs and proceeds only if profits exceed flash loan fees, though market conditions may affect results.
What are the risks?
- Slippage in swaps.
- Failures in external contracts (e.g., auction or DEXs).
- Reentrancy vulnerabilities if not secured.