Skip to content

feat(contracts): add remove liquidity example - #256

Open
SharkHand3 wants to merge 1 commit into
alloy-rs:mainfrom
SharkHand3:feat/remove-liquidity-example
Open

feat(contracts): add remove liquidity example#256
SharkHand3 wants to merge 1 commit into
alloy-rs:mainfrom
SharkHand3:feat/remove-liquidity-example

Conversation

@SharkHand3

@SharkHand3 SharkHand3 commented Jul 30, 2026

Copy link
Copy Markdown

Motivation

Closes #52.

The repository did not have an Alloy example for removing liquidity from a Uniswap V2-compatible pair. The ethers-rs reference linked in the issue also hardcoded a deprecated RPC endpoint and a private key.

Solution

  • add IUniswapV2Pair and IUniswapV2Router02 bindings generated by sol!
  • load the RPC endpoint, signer, contract addresses, liquidity, and minimum output amounts from required environment variables
  • verify the signer has enough LP tokens and display the pair tokens and reserves
  • approve only the requested LP-token amount
  • use caller-provided minimum outputs and a bounded 20-minute deadline
  • simulate removeLiquidity before sending the removal transaction
  • document the example in the README and generated example index

Testing

  • cargo check --locked -p examples-contracts --example remove_liquidity
  • cargo check --workspace --examples --all-features --locked
  • cargo +nightly fmt --all --check
  • cargo clippy --workspace --examples --all-features --locked -- -D warnings
  • end-to-end execution against a local Ethereum mainnet fork using the deployed Uniswap V2 USDC/WETH pair and router; both the approval and removal receipts succeeded without broadcasting to mainnet

@SharkHand3
SharkHand3 force-pushed the feat/remove-liquidity-example branch from ba308f7 to fd42165 Compare July 30, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Add example of using sol! to remove_liquidity

1 participant