Skip to content

Conversation

@reymom
Copy link

@reymom reymom commented Nov 23, 2025

Pyth Examples Contribution

Type of Contribution

  • New Example Project (Adding a new example to demonstrate Pyth integration)
  • Bug Fix (Fixing an issue in existing examples)
  • Documentation Update (Improving README, comments, or guides)
  • Enhancement (Improving existing functionality or adding features)
  • Hackathon Submission (Submitting a project from a hackathon)

Project Information

Project/Example Name: Chaos LP — MEV-Resistant Uniswap v4 Liquidity Using Pyth Price Feeds + Entropy

Pyth Product Used:

  • Pyth Price Feeds
  • Pyth Entropy
  • Multiple Products
  • Other: ___________

Blockchain/Platform:

  • Ethereum/EVM
  • Solana
  • Aptos
  • Sui
  • Fuel
  • Starknet
  • TON
  • Other: ___________

Description

What does this contribution do?

This PR adds a full working example demonstrating how to combine Pyth Price Feeds (pull oracle) and Pyth Entropy to create a MEV-resistant Uniswap v4 Liquidity Provider called Chaos LP.

Chaos LP deploys a Uniswap v4 pool + hook on Base Sepolia and uses:

  • Pyth Hermes to pull fresh price update data (bytes[])
  • Pyth Price Feed update via getUpdateFee() + updatePriceFeeds()
  • Pyth Entropy via getFeeV2() + requestV2()
  • Entropy callback to deliver random numbers on-chain
  • Randomized liquidity bands that reduce MEV opportunities

The example includes:

  • Solidity contracts
  • Foundry deployment scripts
  • A TypeScript script to perform a Chaos LP request
  • A Rust-based Monte Carlo MEV simulator
  • Full README documentation, diagrams, and instructions

How does it integrate with Pyth?

  1. Pyth Price Feeds (Pull Oracle)
    The hook fetches price update blobs from Hermes:
    https://hermes.pyth.network/v2/updates/price/latest?ids[]=<feed-id>
    Then the hook:
uint256 pythFee = pyth.getUpdateFee(updateData);
pyth.updatePriceFeeds{value: pythFee}(updateData);
PythStructs.Price memory price = pyth.getPriceNoOlderThan(feedId, maxAge);

This provides a fresh, cryptographically signed ETH/USD price for tick calculation.

  1. Pyth Entropy
    Chaos LP requests on-chain randomness:
uint128 entropyFee = entropy.getFeeV2();
uint64 seq = entropy.requestV2{value: entropyFee}();

Then in the callback:

function entropyCallback(uint64 seq, address provider, uint256 randomNumber)

The randomness determines the LP band offset, making attacks unpredictable.

What problem does it solve or demonstrate?

Chaos LP demonstrates that price-informed + randomness-informed liquidity dramatically reduces MEV extraction.
The included Rust simulator shows:

  • ~96% reduction in attacker expected payoff
  • ~92% reduction in MEV success rate
    Highly chaotic, unpredictable LP positions versus standard static LP bands

This example demonstrates a novel, production-relevant use case for Pyth:

  • Using price updates + randomness to generate unpredictable DeFi liquidity behavior.

Directory Structure (for new examples)

entropy/chaos-lp-uniswap-v4/
├── contracts/            # Uniswap v4 Hook + Deployers
├── scripts/              # Foundry + TS chaos request script
├── mev-sim/              # Rust Monte Carlo MEV simulator
├── deployments/          # Example JSON deployment artifacts
├── README.md             # Full documentation
└── ...

Testing & Verification

How to Test This Contribution

Smart Contracts: forge test -vv. Then also deploy and run scripts as documented below.

Prerequisites

Node.js ≥ 18
Rust ≥ 1.77
Foundry (forge + anvil)
Base Sepolia RPC (Alchemy/Infura/etc.)

Setup & Run Instructions

cd entropy/chaos-lp-uniswap-v4
cp .env.example .env   # fill RPC + addresses
npm install

Run anvil fork:

anvil \
  --fork-url $BASE_RPC \
  --fork-block-number 20000000 \
  --chain-id 8453

Deploy Chaos LP locally:

forge script scripts/DeployChaosSystem.s.sol:DeployChaosSystem \
  --rpc-url http://127.0.0.1:8545 \
  --private-key $DEPLOYER_PK \
  --broadcast \
  -vv

Trigger Chaos LP request (Pyth + Entropy):

npm run request:chaos:base

Run the MEV simulator:

Run the MEV simulator:

This outputs:

  • chaos_vs_normal.csv
  • expected_mev_bar.png
  • chaos_mev_dashboard.png

Deployment Information (if applicable)

Network: Base Sepolia (Chain ID 84532)

Contract Address(es):
ChaosHook: 0xD4ED3f079E04f681F8c3C16D4589c4eF82AFC800
Token0: 0xE47bC56b07f1E3D4faB5f16bD3Be53A8B6470d2E
Token1: 0x51Ea2928c87328D6Df0e4569DcC60b78EcEc725f

Demo URL: https://www.canva.com/design/DAG4n6h_QZA/tBSK1NuMxQ-6tN-UsrQSfg/view?utm_content=DAG4n6h_QZA&utm_campaign=designshare&utm_medium=link2&utm_source=uniquelinks&utlId=h927271b026

Checklist

Code Quality

  • Code follows existing patterns in the repository
  • Proper error handling implemented
  • No hardcoded values (use environment variables where appropriate)

Testing

  • Tested locally and works as expected
  • All existing functionality still works (no breaking changes)

Additional Context

Related Issues

Fixes #

Screenshots/Demo (if applicable)

Notes for Reviewers

The project demonstrates a novel, fully working integration of:
Pyth Price Feeds (pull mode)
Pyth Entropy
Randomized Uniswap v4 liquidity strategies
Backed by a quantitative MEV study
This is my submission for ETHGlobal Buenos Aires (Pyth Track: Price Feeds + Entropy).

As being part of a hackathon project, many details can be improved, I can do it in the future.


Thank you for contributing to Pyth Examples!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant