Skip to content

refactor!: unify payment vaults into PaymentVaultV2 and align Rust cost estimation with Solidity#4

Merged
mickvandijke merged 8 commits intomainfrom
refactor/unify-payment-vault-v2
Apr 2, 2026
Merged

refactor!: unify payment vaults into PaymentVaultV2 and align Rust cost estimation with Solidity#4
mickvandijke merged 8 commits intomainfrom
refactor/unify-payment-vault-v2

Conversation

@mickvandijke
Copy link
Copy Markdown
Contributor

@mickvandijke mickvandijke commented Apr 1, 2026

Summary

Merge the separate MerklePaymentVault and PaymentVault Solidity contracts into a single PaymentVaultV2 contract, and consolidate the corresponding Rust modules. This removes ~2,200 net lines of code and fixes several discrepancies between the Rust cost estimation logic and the on-chain Solidity implementation.

Contract unification

  • Replace MerklePaymentVault.sol + PaymentVault.sol with a single PaymentVaultV2.sol that handles both single-quote and merkle batch payments
  • Extract shared merkle logic into MerklePaymentLib.sol and common types into Types.sol
  • Add IPaymentVaultV2.sol interface; remove stale IPaymentVaultV6.json and PaymentVaultNoProxyV6.json artifacts
  • Update deployed contract addresses for Arbitrum One and Arbitrum Sepolia

Rust module consolidation

  • Remove the merkle_payment_vault module entirely; absorb its functionality into payment_vault
  • Deduplicate cost estimation by removing the private estimate_merkle_cost_local in favor of the shared Network::estimate_merkle_payment_cost

Bug fixes

  • Pool count formula: Rust used floor(depth/2) but Solidity uses ceil(depth/2) — caused WrongPoolCount reverts for odd depths
  • Cost estimation: Rust summed top-N prices but Solidity computes median16(quotes) * (1 << depth) — caused balance pre-checks to pass while on-chain txs reverted

Other changes

  • Remove unused max_records field from QuotingMetrics (breaking)
  • Add integration tests exercising the full payForMerkleTree flow on Anvil

Test plan

  • cargo check passes
  • cargo test against local Anvil instance
  • Merkle batch payments work end-to-end with the unified contract
  • Single-quote payments still work as before

🤖 Generated with Claude Code

mickvandijke and others added 4 commits April 1, 2026 17:54
Merge the separate MerklePaymentVault and PaymentVault contracts into a
single PaymentVaultV2 contract. This removes the merkle_payment_vault
Rust module and consolidates all payment logic into the payment_vault
module, simplifying the codebase and reducing duplication.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Rust `expected_reward_pools` and `midpoint_level` used floor(depth/2)
while the Solidity `MerklePaymentLib.expectedRewardPools` uses ceil(depth/2).
This caused WrongPoolCount reverts for odd depths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Rust cost estimation used `sum of top N prices` but the Solidity
contract computes `median16(quotes) * (1 << depth)`. This caused the
balance/allowance pre-check to pass while the on-chain tx reverted.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mickvandijke mickvandijke marked this pull request as ready for review April 1, 2026 22:56
mickvandijke and others added 3 commits April 2, 2026 10:16
Nodes no longer have a storage capacity limit, so the max_records
field is unused. Removed from the struct, Debug impl, and to_bytes
serialization.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ests

Remove the private `estimate_merkle_cost_local` from wallet.rs in favor
of the shared `Network::estimate_merkle_payment_cost`, and add three
integration tests that exercise the full payForMerkleTree flow on Anvil.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mickvandijke mickvandijke changed the title refactor!: unify MerklePaymentVault and PaymentVault into PaymentVaultV2 refactor!: unify payment vaults into PaymentVaultV2 and align Rust cost estimation with Solidity Apr 2, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mickvandijke mickvandijke merged commit fa5c8b1 into main Apr 2, 2026
7 checks passed
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