Skip to content

About

Foundry project for a yield farming system written in Solidity, with extra utilities that demonstrate practical abi.encodePacked usage for DeFi-style payloads and identifiers.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

Yield Farming

Foundry project for a simple yield farming system written in Solidity, with extra utilities that demonstrate practical abi.encodePacked usage for DeFi-style payloads and identifiers.

Overview

The repository currently has three main contracts:

The project uses Foundry for compilation, testing, and formatting.

YieldFarmingPool Features

src/YieldFarmingPool.sol currently supports:

  • Owner-only pool creation
  • Pool tracking by deterministic bytes32 identifiers
  • Staking into active pools
  • Withdrawals with reward settlement
  • Reward claiming
  • Owner-controlled reward rate updates
  • Emergency token withdrawal for the owner
  • Encoded pool snapshots through getPoolEncodedData
  • Deterministic per-user hashes through getUserHash
  • Active pool enumeration with getActivePools and getActivePoolsCount

Each pool stores:

  • Staking token address
  • Total staked balance
  • Reward rate
  • Last update timestamp
  • Accumulated reward-per-token value
  • Active status flag

ABIEncoder Utility Contract

src/utils/ABIEncoder.sol acts as a compact reference for abi.encodePacked patterns, including:

  • Pool identifiers
  • Trading positions
  • Swap payloads
  • Limit orders
  • Yield positions
  • Flash loan payloads
  • Staking configuration snapshots
  • Multi-pool user hashes
  • Yield strategies
  • Cross-chain bridge metadata
  • Generic DeFi transaction IDs
  • Stop-loss, take-profit, and trailing-stop order payloads

This contract is useful for learning how deterministic hashes and compact payloads can be built from structured DeFi inputs.

Important Note About abi.encodePacked

abi.encodePacked is compact, but it should be used carefully. Combining variable-length values without clear boundaries can create collisions. This repository shows safer patterns such as:

  • Fixed field ordering
  • Domain/type suffixes like "LIMIT_ORDER_V1" and "YIELD_FARMING_USER"
  • Length validation for correlated arrays

Requirements

Commands

Build the project:

forge build

Run all tests:

forge test

Run only the ABI encoder tests:

forge test --match-contract ABIEncoderTest

Run only the yield farming pool tests:

forge test --match-contract YieldFarmingPoolTest

Format the code:

forge fmt

Check formatting without modifying files:

forge fmt --check

Generate a coverage summary:

forge coverage --report summary

Current Test Status

The repository now includes dedicated test suites for both the encoder helpers and the yield farming pool:

The automated tests currently validate:

  • Deterministic pool IDs
  • Timestamp-dependent trading position encoding
  • Swap payload construction
  • Custom error reverts on mismatched array lengths
  • Hash consistency for order and position encodings
  • Flash loan, bridge, and advanced order payloads
  • Strategy encoding and multi-pool hashing
  • Pool creation and duplicate protection
  • Owner access control on administrative functions
  • Staking, reward claiming, and withdrawals
  • Full-position withdrawals
  • Reward rate updates
  • Emergency withdrawal behavior
  • Encoded pool snapshots and active pool enumeration

Coverage

Latest measured coverage summary:

╭--------------------------+------------------+------------------+-----------------+-----------------╮
| File                     | % Lines          | % Statements     | % Branches      | % Funcs         |
+====================================================================================================+
| src/MockToken.sol        | 66.67% (4/6)     | 66.67% (2/3)     | 100.00% (0/0)   | 66.67% (2/3)    |
|--------------------------+------------------+------------------+-----------------+-----------------|
| src/YieldFarmingPool.sol | 100.00% (90/90)  | 100.00% (84/84)  | 100.00% (25/25) | 100.00% (14/14) |
|--------------------------+------------------+------------------+-----------------+-----------------|
| src/utils/ABIEncoder.sol | 100.00% (56/56)  | 100.00% (54/54)  | 100.00% (2/2)   | 100.00% (17/17) |
|--------------------------+------------------+------------------+-----------------+-----------------|
| Total                    | 98.68% (150/152) | 99.29% (140/141) | 100.00% (27/27) | 97.06% (33/34)  |
╰--------------------------+------------------+------------------+-----------------+-----------------╯

These numbers were produced with:

forge coverage

Repository Structure

src/
  MockToken.sol
  YieldFarmingPool.sol
  utils/
    ABIEncoder.sol
test/
  YieldFarmingPool.t.sol
  utils/
    ABIEncoder.t.sol

Foundry

Foundry documentation: https://book.getfoundry.sh/

About

Foundry project for a yield farming system written in Solidity, with extra utilities that demonstrate practical abi.encodePacked usage for DeFi-style payloads and identifiers.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages