Skip to content

fix: compounding fee dead liquidity reward accounting#212

Merged
andrewsource147 merged 6 commits into
release_0.2.2from
fix/compounding_fee_dead_liquidity_reward_accounting
Jun 18, 2026
Merged

fix: compounding fee dead liquidity reward accounting#212
andrewsource147 merged 6 commits into
release_0.2.2from
fix/compounding_fee_dead_liquidity_reward_accounting

Conversation

@bangyro

@bangyro bangyro commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@bangyro

bangyro commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

/bot review

@metoeraag-bot

metoeraag-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

Bot Agent progress: /bot review

Progress:

  • Repo checks (5 ok, 4 failed)
  • Context build
  • OMP review (OMP 2 finding(s))
  • OMP debate (1 debate round(s))
  • Post review

@metoeraag-bot metoeraag-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

Request changes

Review coverage

Findings: P0:0 P1:1 P2:1 P3:0
Reviewed by: OMP GPT openai/gpt-5.5 + Opus anthropic/claude-opus-4-8 + arbiter openai/gpt-5.5
Coverage lanes: Correctness, System integration, State machine, Regression tests, Repo checks
Risk focus: state-machine paths changed; tests changed
Evidence: repo-grounded (reviewers verified findings against the checkout)

Summary

⚠️ Limited-confidence review: check failed: cargo clippy --workspace --all-targets -- -D warnings.

Request changes for two supported issues: a committed describe.only in the new Mocha test file will cause the globbed TypeScript test run to execute only that suite, and reward carry-forward funding does not include or clear the newly introduced pending_dead_liquidity_reward, leaving that ineligible amount outside the next campaign despite being withdrawable in the alternate path.

Findings
  • [P1] tests/deadLiquidityReward.test.ts:41 Remove the focused Mocha suite (via GPT+Opus)
  • [P2] programs/cp-amm/src/state/pool.rs:1111 Carry-forward funding ignores pending dead-liquidity rewards (via GPT+Opus)
OMP GPT + Opus review

native:ok 502441ms
gpt:ok 35971ms
opus:ok 132488ms
gpt:ok 210246ms
opus:ok 283948ms
gpt_critique:ok 187337ms
opus_critique:ok 315760ms
arbiter:ok 105437ms

Synthesis

OMP final arbiter used openai/gpt-5.5; 2 final finding(s).

Repo checks

Repo Checks

  • rustup component add --toolchain 1.93.0-x86_64-unknown-linux-gnu rustfmt: ok
info: component rustfmt is up to date
  • rustup component add --toolchain 1.93.0-x86_64-unknown-linux-gnu clippy: ok
info: component clippy is up to date
  • cargo fetch --locked: ok
loaded smallvec v1.14.0
  Downloaded parking_lot v0.12.1
  Downloaded byteorder v1.4.3
  Downloaded r-efi v5.2.0
  Downloaded lock_api v0.4.10
  Downloaded redox_syscall v0.3.5
  Downloaded windows_aarch64_msvc v0.48.0
  Downloaded parking_lot_core v0.9.8
  Downloaded windows_x86_64_msvc v0.48.0
  Downloaded windows_i686_msvc v0.48.0
  Downloaded windows_i686_gnu v0.48.0
  Downloaded windows_x86_64_gnu v0.48.0
  Downloaded libc v0.2.171
  Downloaded sha2 v0.10.8
  Downloaded typenum v1.16.0
  Downloaded either v1.13.0
  Downloaded rusty-fork v0.3.0
  Downloaded log v0.4.26
  Downloaded solana-fee-calculator v3.1.0
  Downloaded serde_bytes v0.11.15
  Downloaded solana-clock v2.2.3
  Downloaded solana-instruction v2.3.3
  Downloaded itoa v1.0.8
  Downloaded keccak v0.1.4
  Downloaded solana-signature v3.3.0
  Downloaded solana-instruction-error v2.2.0
  Downloaded windows-targets v0.48.1
  Downloaded solana-define-syscall v5.0.0
  Downloaded solana-address v2.5.0
  Downloaded solana-zero-copy v1.0.0
  Downloaded solana-hash v4.2.0
  Downloaded cpufeatures v0.2.9
  Downloaded alloy-rlp v0.3.11
  Downloaded version_check v0.9.4
  Downloaded rustc_version v0.4.0
  Downloaded arrayvec v0.7.4
  Downloaded parity-scale-codec-derive v3.6.12
  Downloaded crunchy v0.2.2
  Downloaded autocfg v1.1.0
  Downloaded rand_xorshift v0.3.0
  Downloaded rustversion v1.0.17
  Downloaded getrandom v0.2.10
  Downloaded solana-curve25519 v3.1.12
  Downloaded ppv-lite86 v0.2.17
  Downloaded cfg-if v1.0.0
  Downloaded bitflags v2.9.0
  Downloaded unicode-ident v1.0.10
  Downloaded opaque-debug v0.3.0
  Downloaded solana-pubkey v4.1.0
  Downloaded solana-instruction v3.3.0
  Downloaded solana-transaction-error v3.1.0
  Downloaded solana-nullable v1.1.0
  Downloaded pastey v0.2.1
  Downloaded wincode-derive v0.4.3
  Downloaded five8_core v0.1.1
  Downloaded impl-trait-for-tuples v0.2.2
  Downloaded equivalent v1.0.0
  Downloaded wasi v0.11.0+wasi-snapshot-preview1
  Downloaded once_cell v1.21.1
  • bun install --frozen-lockfile: ok
bun install v1.3.14 (0d9b296a)

+ @anchor-lang/borsh@1.0.0
+ @solana/spl-token-metadata@0.1.6
+ @types/bn.js@5.2.0
+ @types/chai@4.3.20
+ @types/mocha@9.1.1
+ chai@4.5.0
+ mocha@9.2.2
+ prettier@2.8.8
+ ts-mocha@10.1.0
+ typescript@5.9.3
+ @anchor-lang/core@1.0.0
+ @solana/spl-token@0.4.14
+ @solana/web3.js@1.98.4
+ borsh@2.0.0
+ decimal.js@10.6.0
+ litesvm@0.1.0

192 packages installed [974.00ms]
  • cargo fmt --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: failed
ed `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:34:5
   |
34 |     assert_eq!(100u128.safe_shl(128).is_err(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
34 -     assert_eq!(100u128.safe_shl(128).is_err(), true);
34 +     assert!(100u128.safe_shl(128).is_err());
   |

error: used `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:40:5
   |
40 |     assert_eq!(100u128.safe_shr(1).is_ok(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
40 -     assert_eq!(100u128.safe_shr(1).is_ok(), true);
40 +     assert!(100u128.safe_shr(1).is_ok());
   |

error: used `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:41:5
   |
41 |     assert_eq!(200u128.safe_shr(129).is_err(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
41 -     assert_eq!(200u128.safe_shr(129).is_err(), true);
41 +     assert!(200u128.safe_shr(129).is_err());
   |

error: casting to the same type is unnecessary (`u16` -> `u16`)
   --> programs/cp-amm/src/params/fee_parameters.rs:167:38
    |
167 |             self.reduction_factor <= MAX_BASIS_POINT as u16,
    |                                      ^^^^^^^^^^^^^^^^^^^^^^ help: try: `MAX_BASIS_POINT`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#unnecessary_cast

error: could not compile `cp-amm` (lib test) due to 240 previous errors
  • bun run lint: failed
Checking formatting...

$ prettier */*.js "*/**/*{.js,.ts}" --check
[warn] tests/compoundingLiquidity.test.ts
[warn] tests/helpers/accounts.ts
[warn] tests/helpers/idl/alpha_vault.ts
[warn] tests/helpers/rateLimiterUtils.ts
[warn] tests/helpers/transferHook/idl/transfer_hook.ts
[warn] tests/zapProtocolFees.test.ts
[warn] Code style issues found in 6 files. Forgot to run Prettier?
error: script "lint" exited with code 1
  • bun run test: failed
$ bun run build-local && ANCHOR_WALLET=keys/local/admin-bossj3JvwiNK7pvjr149DqdtJxf2gdygbcmEPTkb2F1.json bunx ts-mocha -p ./tsconfig.json -t 1000000 tests/*.test.ts
$ anchor build --ignore-keys -- --features local
/usr/bin/bash: line 1: anchor: command not found
error: script "build-local" exited with code 127
error: script "test" exited with code 127
  • bun run build-local: failed
$ anchor build --ignore-keys -- --features local
/usr/bin/bash: line 1: anchor: command not found
error: script "build-local" exited with code 127

Comment thread tests/deadLiquidityReward.test.ts Outdated
Comment thread programs/cp-amm/src/state/pool.rs Outdated
@bangyro bangyro force-pushed the fix/compounding_fee_dead_liquidity_reward_accounting branch from 12d2b5b to 8084034 Compare June 16, 2026 02:48
@bangyro

bangyro commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

/bot review

@metoeraag-bot

metoeraag-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

Bot Agent progress: /bot review

Progress:

  • Repo checks (4 ok, 4 failed)
  • Context build
  • OMP review (OMP 1 finding(s))
  • OMP debate (1 debate round(s))
  • Post review

@metoeraag-bot metoeraag-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

Approve

Review coverage

Findings: P0:0 P1:0 P2:1 P3:0
Reviewed by: OMP GPT openai/gpt-5.5 + Opus anthropic/claude-opus-4-8 + arbiter openai/gpt-5.5
Coverage lanes: Correctness, System integration, State machine, Regression tests, Repo checks
Risk focus: state-machine paths changed; tests changed
Evidence: repo-grounded (reviewers verified findings against the checkout)

Summary

⚠️ Limited-confidence review: check failed: cargo clippy --workspace --all-targets -- -D warnings.

Reviewed correctness, system-integration, state-machine, and regression-test lanes for the reward accounting change. cargo check --workspace passed; other local tooling limitations/failures were outside this patch. Kept one P2 accounting finding: dead-liquidity rewards are converted to u64 and rounded down on every pool reward update, so the funder's recoverable ineligible reward can depend on unrelated update cadence and small per-update shares can remain stranded in the vault.

Findings
  • [P2] programs/cp-amm/src/state/pool.rs:307 Track dead-liquidity rewards at full precision (via GPT+Opus)
OMP GPT + Opus review

native:ok 676177ms
gpt:ok 109282ms
opus:ok 317423ms
gpt:ok 227061ms
opus:ok 308666ms
gpt_critique:ok 191877ms
opus_critique:ok 291244ms
arbiter:ok 123062ms

Synthesis

OMP final arbiter used openai/gpt-5.5; 1 final finding(s).

Repo checks

Repo Checks

  • rustup component add --toolchain 1.93.0-x86_64-unknown-linux-gnu clippy: ok
info: component clippy is up to date
  • cargo fetch --locked: ok
6.0
  Downloaded windows_aarch64_gnullvm v0.48.0
  Downloaded windows_x86_64_gnullvm v0.48.0
  Downloaded ryu v1.0.14
  Downloaded lock_api v0.4.10
  Downloaded rustix v1.0.7
  Downloaded redox_syscall v0.3.5
  Downloaded parking_lot v0.12.1
  Downloaded typenum v1.16.0
  Downloaded memchr v2.7.4
  Downloaded parity-scale-codec v3.6.12
  Downloaded wasi v0.11.0+wasi-snapshot-preview1
  Downloaded once_cell v1.21.1
  Downloaded getrandom v0.2.10
  Downloaded serde_bytes v0.11.15
  Downloaded windows_aarch64_msvc v0.48.0
  Downloaded opaque-debug v0.3.0
  Downloaded solana-instruction-error v2.2.0
  Downloaded smallvec v1.14.0
  Downloaded windows-targets v0.48.1
  Downloaded parking_lot_core v0.9.8
  Downloaded windows_i686_gnu v0.48.0
  Downloaded windows_i686_msvc v0.48.0
  Downloaded libc v0.2.171
  Downloaded windows_x86_64_gnu v0.48.0
  Downloaded windows_x86_64_msvc v0.48.0
  Downloaded solana-zero-copy v1.0.0
  Downloaded five8_core v0.1.1
  Downloaded cpufeatures v0.2.9
  Downloaded sha2 v0.10.8
  Downloaded alloy-rlp v0.3.11
  Downloaded either v1.13.0
  Downloaded impl-trait-for-tuples v0.2.2
  Downloaded equivalent v1.0.0
  Downloaded byteorder v1.4.3
  Downloaded autocfg v1.1.0
  Downloaded rusty-fork v0.3.0
  Downloaded errno v0.3.11
  Downloaded rustversion v1.0.17
  Downloaded ppv-lite86 v0.2.17
  Downloaded bitflags v2.9.0
  Downloaded rand v0.9.1
  Downloaded solana-epoch-schedule v3.0.0
  Downloaded solana-curve25519 v3.1.12
  Downloaded itoa v1.0.8
  Downloaded keccak v0.1.4
  Downloaded solana-instruction v3.3.0
  Downloaded solana-signature v3.3.0
  Downloaded solana-transaction-error v3.1.0
  Downloaded wincode-derive v0.4.3
  Downloaded version_check v0.9.4
  Downloaded rustc_version v0.4.0
  Downloaded arrayvec v0.7.4
  Downloaded cfg-if v1.0.0
  Downloaded r-efi v5.2.0
  Downloaded unicode-ident v1.0.10
  Downloaded solana-fee-calculator v3.1.0
  Downloaded parity-scale-codec-derive v3.6.12
  Downloaded crunchy v0.2.2
  Downloaded log v0.4.26
  • bun install --frozen-lockfile: ok
bun install v1.3.14 (0d9b296a)

+ @anchor-lang/borsh@1.0.0
+ @solana/spl-token-metadata@0.1.6
+ @types/bn.js@5.2.0
+ @types/chai@4.3.20
+ @types/mocha@9.1.1
+ chai@4.5.0
+ mocha@9.2.2
+ prettier@2.8.8
+ ts-mocha@10.1.0
+ typescript@5.9.3
+ @anchor-lang/core@1.0.0
+ @solana/spl-token@0.4.14
+ @solana/web3.js@1.98.4
+ borsh@2.0.0
+ decimal.js@10.6.0
+ litesvm@0.1.0

192 packages installed [826.00ms]
  • cargo check --workspace: ok
e for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_split_position.rs:97:1
   |
97 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_lock_inner_position.rs:11:1
   |
11 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_update_delegate_permission.rs:16:1
   |
16 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `cp_amm::claim_protocol_fee`: Use claim_protocol_fee2 through protocol_fee program instead
   --> programs/cp-amm/src/lib.rs:182:12
    |
182 |     pub fn claim_protocol_fee(
    |            ^^^^^^^^^^^^^^^^^^

warning: use of deprecated function `cp_amm::zap_protocol_fee`: Use claim_protocol_fee2 through protocol_fee program instead
   --> programs/cp-amm/src/lib.rs:195:12
    |
195 |     pub fn zap_protocol_fee(ctx: Context<ZapProtocolFee>, max_amount: u64) -> Result<()> {
    |            ^^^^^^^^^^^^^^^^

warning: `cp-amm` (lib) generated 31 warnings
    Checking rust-sdk v0.2.2 (/data/workdir/2962945/MeteoraAg/damm-v2/rust-sdk)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 25.11s
  • cargo clippy --workspace --all-targets -- -D warnings: failed
ed `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:34:5
   |
34 |     assert_eq!(100u128.safe_shl(128).is_err(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
34 -     assert_eq!(100u128.safe_shl(128).is_err(), true);
34 +     assert!(100u128.safe_shl(128).is_err());
   |

error: used `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:40:5
   |
40 |     assert_eq!(100u128.safe_shr(1).is_ok(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
40 -     assert_eq!(100u128.safe_shr(1).is_ok(), true);
40 +     assert!(100u128.safe_shr(1).is_ok());
   |

error: used `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:41:5
   |
41 |     assert_eq!(200u128.safe_shr(129).is_err(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
41 -     assert_eq!(200u128.safe_shr(129).is_err(), true);
41 +     assert!(200u128.safe_shr(129).is_err());
   |

error: casting to the same type is unnecessary (`u16` -> `u16`)
   --> programs/cp-amm/src/params/fee_parameters.rs:167:38
    |
167 |             self.reduction_factor <= MAX_BASIS_POINT as u16,
    |                                      ^^^^^^^^^^^^^^^^^^^^^^ help: try: `MAX_BASIS_POINT`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#unnecessary_cast

error: could not compile `cp-amm` (lib test) due to 240 previous errors
  • bun run lint: failed
Checking formatting...

$ prettier */*.js "*/**/*{.js,.ts}" --check
[warn] tests/compoundingLiquidity.test.ts
[warn] tests/helpers/accounts.ts
[warn] tests/helpers/idl/alpha_vault.ts
[warn] tests/helpers/rateLimiterUtils.ts
[warn] tests/helpers/transferHook/idl/transfer_hook.ts
[warn] tests/zapProtocolFees.test.ts
[warn] Code style issues found in 6 files. Forgot to run Prettier?
error: script "lint" exited with code 1
  • bun run test: failed
$ bun run build-local && ANCHOR_WALLET=keys/local/admin-bossj3JvwiNK7pvjr149DqdtJxf2gdygbcmEPTkb2F1.json bunx ts-mocha -p ./tsconfig.json -t 1000000 tests/*.test.ts
$ anchor build --ignore-keys -- --features local
/usr/bin/bash: line 1: anchor: command not found
error: script "build-local" exited with code 127
error: script "test" exited with code 127
  • bun run build-local: failed
$ anchor build --ignore-keys -- --features local
/usr/bin/bash: line 1: anchor: command not found
error: script "build-local" exited with code 127

Comment thread programs/cp-amm/src/state/pool.rs Outdated
@bangyro

bangyro commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

/bot review

@metoeraag-bot

metoeraag-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

Bot Agent progress: /bot review

Progress:

  • Repo checks (4 ok, 4 failed)
  • Context build
  • OMP review (OMP 1 finding(s))
  • OMP debate (1 debate round(s))
  • Post review

@bangyro bangyro force-pushed the fix/compounding_fee_dead_liquidity_reward_accounting branch from 0af76cf to ce709d2 Compare June 16, 2026 04:50

@metoeraag-bot metoeraag-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

Comment

Review coverage

Findings: P0:0 P1:0 P2:1 P3:0
Reviewed by: OMP GPT openai/gpt-5.5 + Opus anthropic/claude-opus-4-8 + arbiter openai/gpt-5.5
Coverage lanes: Correctness, System integration, State machine, Regression tests, Repo checks
Risk focus: state-machine paths changed; tests changed
Evidence: repo-grounded (reviewers verified findings against the checkout)

Summary

⚠️ The PR head moved during review (reviewed 0af76cf, now ce709d2). Findings below are posted for the reviewed commit; the verdict is a non-binding comment. Re-run /bot review on the latest head for a binding verdict.

⚠️ Limited-confidence review: check failed: cargo clippy --workspace --all-targets -- -D warnings.

Checked the changed reward state machine, fund/withdraw callers, position reward accounting, and added TS integration tests. cargo check passed; clippy/prettier failures in the provided check report are outside the changed files, and bun tests were blocked by missing anchor. The added tests cover the primary withdraw and carry-forward paths, so the missing-test finding is dropped. One supported non-blocking edge-case remains: the new dead-liquidity checkpoint stores a lifetime cumulative value in u64 and can brick recovery once that cumulative share exceeds u64::MAX.

Findings
  • [P2] programs/cp-amm/src/state/pool.rs:323 Dead-liquidity settlement can get stuck after the cumulative checkpoint exceeds u64 (via GPT+Opus)
OMP GPT + Opus review

native:ok 547325ms
gpt:ok 137111ms
opus:ok 352590ms
gpt:ok 255111ms
opus:ok 400561ms
gpt_critique:ok 122888ms
opus_critique:ok 248455ms
arbiter:ok 87753ms

Synthesis

OMP final arbiter used openai/gpt-5.5; 1 final finding(s).

Repo checks

Repo Checks

  • rustup component add --toolchain 1.93.0-x86_64-unknown-linux-gnu clippy: ok
info: component clippy is up to date
  • cargo fetch --locked: ok
.1
  Downloaded wasm-bindgen v0.2.100
  Downloaded regex-automata v0.4.9
  Downloaded alloy-rlp v0.3.11
  Downloaded web-sys v0.3.77
  Downloaded windows_aarch64_msvc v0.48.0
  Downloaded windows_x86_64_gnu v0.48.0
  Downloaded windows_i686_msvc v0.48.0
  Downloaded windows_x86_64_msvc v0.48.0
  Downloaded windows_i686_gnu v0.48.0
  Downloaded semver v1.0.26
  Downloaded libc v0.2.171
  Downloaded arrayvec v0.7.4
  Downloaded byteorder v1.4.3
  Downloaded redox_syscall v0.3.5
  Downloaded either v1.13.0
  Downloaded log v0.4.26
  Downloaded lock_api v0.4.10
  Downloaded wincode-derive v0.4.3
  Downloaded sha2 v0.10.8
  Downloaded wasm-bindgen-macro-support v0.2.100
  Downloaded cpufeatures v0.2.9
  Downloaded autocfg v1.1.0
  Downloaded equivalent v1.0.0
  Downloaded errno v0.3.11
  Downloaded wasm-bindgen-backend v0.2.100
  Downloaded ppv-lite86 v0.2.17
  Downloaded spl-discriminator-syn v0.2.0
  Downloaded impl-trait-for-tuples v0.2.2
  Downloaded rustversion v1.0.17
  Downloaded serde_bytes v0.11.15
  Downloaded itoa v1.0.8
  Downloaded solana-transaction-error v3.1.0
  Downloaded windows-targets v0.48.1
  Downloaded five8_core v0.1.1
  Downloaded solana-hash v4.2.0
  Downloaded crunchy v0.2.2
  Downloaded constant_time_eq v0.3.1
  Downloaded tinyvec v1.6.0
  Downloaded solana-instruction v3.3.0
  Downloaded percent-encoding v2.3.1
  Downloaded solana-instruction-error v2.2.0
  Downloaded wasm-bindgen-macro v0.2.100
  Downloaded wit-bindgen-rt v0.39.0
  Downloaded zeroize_derive v1.4.2
  Downloaded ruint v1.14.0
  Downloaded solana-fee-calculator v3.1.0
  Downloaded parking_lot_core v0.9.8
  Downloaded solana-zero-copy v1.0.0
  Downloaded parity-scale-codec-derive v3.6.12
  Downloaded wasi v0.14.2+wasi-0.2.4
  Downloaded cargo_toml v0.19.2
  Downloaded rusty-fork v0.3.0
  Downloaded tempfile v3.20.0
  Downloaded solana-curve25519 v3.1.12
  Downloaded linux-raw-sys v0.9.4
  Downloaded getrandom v0.2.10
  Downloaded unicode-ident v1.0.10
  Downloaded zeroize v1.8.1
  • bun install --frozen-lockfile: ok
bun install v1.3.14 (0d9b296a)

+ @anchor-lang/borsh@1.0.0
+ @solana/spl-token-metadata@0.1.6
+ @types/bn.js@5.2.0
+ @types/chai@4.3.20
+ @types/mocha@9.1.1
+ chai@4.5.0
+ mocha@9.2.2
+ prettier@2.8.8
+ ts-mocha@10.1.0
+ typescript@5.9.3
+ @anchor-lang/core@1.0.0
+ @solana/spl-token@0.4.14
+ @solana/web3.js@1.98.4
+ borsh@2.0.0
+ decimal.js@10.6.0
+ litesvm@0.1.0

192 packages installed [2.70s]
  • cargo check --workspace: ok
e for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_split_position.rs:97:1
   |
97 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_lock_inner_position.rs:11:1
   |
11 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_update_delegate_permission.rs:16:1
   |
16 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `cp_amm::claim_protocol_fee`: Use claim_protocol_fee2 through protocol_fee program instead
   --> programs/cp-amm/src/lib.rs:182:12
    |
182 |     pub fn claim_protocol_fee(
    |            ^^^^^^^^^^^^^^^^^^

warning: use of deprecated function `cp_amm::zap_protocol_fee`: Use claim_protocol_fee2 through protocol_fee program instead
   --> programs/cp-amm/src/lib.rs:195:12
    |
195 |     pub fn zap_protocol_fee(ctx: Context<ZapProtocolFee>, max_amount: u64) -> Result<()> {
    |            ^^^^^^^^^^^^^^^^

warning: `cp-amm` (lib) generated 31 warnings
    Checking rust-sdk v0.2.2 (/data/workdir/2962945/MeteoraAg/damm-v2/rust-sdk)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 23.35s
  • cargo clippy --workspace --all-targets -- -D warnings: failed
fe_shl(128).is_err(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
34 -     assert_eq!(100u128.safe_shl(128).is_err(), true);
34 +     assert!(100u128.safe_shl(128).is_err());
   |

error: used `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:40:5
   |
40 |     assert_eq!(100u128.safe_shr(1).is_ok(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
40 -     assert_eq!(100u128.safe_shr(1).is_ok(), true);
40 +     assert!(100u128.safe_shr(1).is_ok());
   |

error: used `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:41:5
   |
41 |     assert_eq!(200u128.safe_shr(129).is_err(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
41 -     assert_eq!(200u128.safe_shr(129).is_err(), true);
41 +     assert!(200u128.safe_shr(129).is_err());
   |

error: casting to the same type is unnecessary (`u16` -> `u16`)
   --> programs/cp-amm/src/params/fee_parameters.rs:167:38
    |
167 |             self.reduction_factor <= MAX_BASIS_POINT as u16,
    |                                      ^^^^^^^^^^^^^^^^^^^^^^ help: try: `MAX_BASIS_POINT`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#unnecessary_cast

error: could not compile `cp-amm` (lib) due to 174 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `cp-amm` (lib test) due to 240 previous errors
  • bun run lint: failed
Checking formatting...

$ prettier */*.js "*/**/*{.js,.ts}" --check
[warn] tests/compoundingLiquidity.test.ts
[warn] tests/helpers/accounts.ts
[warn] tests/helpers/idl/alpha_vault.ts
[warn] tests/helpers/rateLimiterUtils.ts
[warn] tests/helpers/transferHook/idl/transfer_hook.ts
[warn] tests/zapProtocolFees.test.ts
[warn] Code style issues found in 6 files. Forgot to run Prettier?
error: script "lint" exited with code 1
  • bun run test: failed
$ bun run build-local && ANCHOR_WALLET=keys/local/admin-bossj3JvwiNK7pvjr149DqdtJxf2gdygbcmEPTkb2F1.json bunx ts-mocha -p ./tsconfig.json -t 1000000 tests/*.test.ts
$ anchor build --ignore-keys -- --features local
/usr/bin/bash: line 1: anchor: command not found
error: script "build-local" exited with code 127
error: script "test" exited with code 127
  • bun run build-local: failed
$ anchor build --ignore-keys -- --features local
/usr/bin/bash: line 1: anchor: command not found
error: script "build-local" exited with code 127

Comment thread programs/cp-amm/src/state/pool.rs Outdated
@bangyro

bangyro commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator Author

/bot review

@metoeraag-bot

metoeraag-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

Bot Agent progress: /bot review

Progress:

  • Repo checks (6 ok, 3 failed)
  • Context build
  • OMP review (OMP 1 finding(s))
  • OMP debate (1 debate round(s))
  • Post review

@metoeraag-bot metoeraag-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict

Approve

Review coverage

Findings: P0:0 P1:0 P2:1 P3:0
Reviewed by: OMP GPT openai/gpt-5.5 + Opus anthropic/claude-opus-4-8 + arbiter openai/gpt-5.5
Coverage lanes: Correctness, System integration, State machine, Regression tests, Repo checks
Risk focus: state-machine paths changed; tests changed
Evidence: repo-grounded (reviewers verified findings against the checkout)

Summary

⚠️ Limited-confidence review: check failed: cargo clippy --workspace --all-targets -- -D warnings.

Reviewed correctness, integration, state-machine, and regression-test lanes for the dead-liquidity reward accounting change. The production paths are consistent: compounding pools keep DEAD_LIQUIDITY in pool.liquidity but outside positions, position rewards and dead-liquidity rewards use the same reward_per_token scale, and the fund/withdraw callers update rewards before settling the checkpoint. Cargo check and fmt passed; shown clippy/prettier failures are outside the changed files, and bun tests were limited by missing anchor. Approve with one P2 regression-test strengthening comment to assert exact LP versus dead-liquidity reward shares.

Findings
  • [P2] tests/deadLiquidityReward.test.ts:193 Assert the exact dead-liquidity reward share (via OMP native)
OMP GPT + Opus review

native:ok 433635ms
gpt:ok 248901ms
opus:ok 295163ms
gpt:ok 217622ms
opus:ok 444531ms
gpt_critique:ok 253081ms
opus_critique:ok 413342ms
arbiter:ok 193854ms

Synthesis

OMP final arbiter used openai/gpt-5.5; 1 final finding(s).

Repo checks

Repo Checks

  • rustup component add --toolchain 1.93.0-x86_64-unknown-linux-gnu rustfmt: ok
info: component rustfmt is up to date
  • rustup component add --toolchain 1.93.0-x86_64-unknown-linux-gnu clippy: ok
info: component clippy is up to date
  • cargo fetch --locked: ok
  • bun install --frozen-lockfile: ok
bun install v1.3.14 (0d9b296a)

Checked 210 installs across 197 packages (no changes) [46.00ms]
  • cargo check --workspace: ok
ce for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_split_position.rs:97:1
   |
97 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_lock_inner_position.rs:11:1
   |
11 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `anchor_lang::deprecated_account_info_usage`: Use `UncheckedAccount` instead of `AccountInfo` for safer unchecked accounts.
  --> programs/cp-amm/src/instructions/ix_update_delegate_permission.rs:16:1
   |
16 | #[event_cpi]
   | ^^^^^^^^^^^^
   |
   = note: this warning originates in the attribute macro `event_cpi` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: use of deprecated function `cp_amm::claim_protocol_fee`: Use claim_protocol_fee2 through protocol_fee program instead
   --> programs/cp-amm/src/lib.rs:182:12
    |
182 |     pub fn claim_protocol_fee(
    |            ^^^^^^^^^^^^^^^^^^

warning: use of deprecated function `cp_amm::zap_protocol_fee`: Use claim_protocol_fee2 through protocol_fee program instead
   --> programs/cp-amm/src/lib.rs:195:12
    |
195 |     pub fn zap_protocol_fee(ctx: Context<ZapProtocolFee>, max_amount: u64) -> Result<()> {
    |            ^^^^^^^^^^^^^^^^

warning: `cp-amm` (lib) generated 31 warnings
    Checking rust-sdk v0.2.2 (/data/workdir/2962945/MeteoraAg/damm-v2/rust-sdk)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.59s
  • cargo fmt --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: failed
fe_shl(128).is_err(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
34 -     assert_eq!(100u128.safe_shl(128).is_err(), true);
34 +     assert!(100u128.safe_shl(128).is_err());
   |

error: used `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:40:5
   |
40 |     assert_eq!(100u128.safe_shr(1).is_ok(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
40 -     assert_eq!(100u128.safe_shr(1).is_ok(), true);
40 +     assert!(100u128.safe_shr(1).is_ok());
   |

error: used `assert_eq!` with a literal bool
  --> programs/cp-amm/src/tests/test_safe_math.rs:41:5
   |
41 |     assert_eq!(200u128.safe_shr(129).is_err(), true);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#bool_assert_comparison
help: replace it with `assert!(..)`
   |
41 -     assert_eq!(200u128.safe_shr(129).is_err(), true);
41 +     assert!(200u128.safe_shr(129).is_err());
   |

error: casting to the same type is unnecessary (`u16` -> `u16`)
   --> programs/cp-amm/src/params/fee_parameters.rs:167:38
    |
167 |             self.reduction_factor <= MAX_BASIS_POINT as u16,
    |                                      ^^^^^^^^^^^^^^^^^^^^^^ help: try: `MAX_BASIS_POINT`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.93.0/index.html#unnecessary_cast

error: could not compile `cp-amm` (lib) due to 174 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `cp-amm` (lib test) due to 240 previous errors
  • bun run lint: failed
Checking formatting...

$ prettier */*.js "*/**/*{.js,.ts}" --check
[warn] tests/compoundingLiquidity.test.ts
[warn] tests/helpers/accounts.ts
[warn] tests/helpers/idl/alpha_vault.ts
[warn] tests/helpers/rateLimiterUtils.ts
[warn] tests/helpers/transferHook/idl/transfer_hook.ts
[warn] tests/zapProtocolFees.test.ts
[warn] Code style issues found in 6 files. Forgot to run Prettier?
error: script "lint" exited with code 1
  • bun run test: failed
$ bun run build-local && ANCHOR_WALLET=keys/local/admin-bossj3JvwiNK7pvjr149DqdtJxf2gdygbcmEPTkb2F1.json bunx ts-mocha -p ./tsconfig.json -t 1000000 tests/*.test.ts
$ anchor build --ignore-keys -- --features local
/usr/bin/bash: line 1: anchor: command not found
error: script "build-local" exited with code 127
error: script "test" exited with code 127

Comment thread tests/deadLiquidityReward.test.ts
@bangyro bangyro marked this pull request as ready for review June 16, 2026 09:58

@andrewsource147 andrewsource147 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, approved wrong PR

Comment thread programs/cp-amm/src/state/pool.rs Outdated
self.reward_per_token_stored(),
TOTAL_REWARD_SCALE,
)
.unwrap_or(u64::MAX); // saturate to u64::MAX

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it should never be overflow, because we are funding rewards by amount (u64)
So DEAD_LIQUIDITY * SUM(emitted_rewards/(DEAD_LIQUIDITY + other liquidities)) <= SUM(emitted_rewards) <= u64

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible over 2 round of funding.

For example, round 1: funder funds u64::MAX and the pool.liquidity == DEAD_LIQUIDITY (all lp exited).
dead_liquidity_reward_checkpoint will be close to u64::MAX at the end of the reward campaign.

round 2: Funder funds reward u64::MAX again, dead_liquidity_reward_checkpoint will continue to grow since its monotonic

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we do this, then dead_liquidity_reward will return zero, the is more wrong? rather than we return error, then funder can't do such case like that.
If you want to handle such case, then need to do wrapping:

  • new_dead_liquidity_reward_checkpoint = U256 % u64::MAX
  • dead_liquidity_reward = new_dead_liquidity_reward_checkpoint.wrapping_sub(dead_liquidity_reward_checkpoint)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call. I added wrapping logic.

Comment thread programs/cp-amm/src/state/pool.rs Outdated
if collect_fee_mode == CollectFeeMode::Compounding {
// saturate on overflow
let new_dead_liquidity_reward_checkpoint: u64 = safe_mul_shr_256_cast(
U256::from(DEAD_LIQUIDITY),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pool only have dead_liquidity if user already deposited in the pool (at least 1 deposit)
But could have the case that: user create pool + initialize rewards and fund_rewards
But settle_dead_liquidity_reward is assuming that pool already had dead_liquidity

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bangyro bangyro Jun 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a guard for it to be safe

@andrewsource147 andrewsource147 Jun 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, forgot that damm-v2's pool is initialized with initial liquidity, could you revert?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok reverted

@bangyro bangyro force-pushed the fix/compounding_fee_dead_liquidity_reward_accounting branch from 1efffbb to 4119fba Compare June 18, 2026 07:20
@andrewsource147 andrewsource147 merged commit 9f46b32 into release_0.2.2 Jun 18, 2026
7 checks passed
@andrewsource147 andrewsource147 deleted the fix/compounding_fee_dead_liquidity_reward_accounting branch June 18, 2026 08:08
andrewsource147 pushed a commit that referenced this pull request Jun 26, 2026
* bump version

* Feat/nft delegate support (#211)

* feat: nft delegate support

* fix: remove `.only` in test

* feat: negative test cases

* fix: clean up is_position_authority

* fix: permissions for delegate action

* feat: refactor and fix test

* fix: use assert!

* feat: revoke perm test

* refactor: tests

* feat: prevent transfer and burn

* docs: update

* fix: invalid permission

* refactor: minor

* docs: update changelog

* fix: tests

* feat: reduce permission space usage

* feat: rename account owner -> signer

* feat: toOwner perms

* feat: combine lock position perms and remove split position perms

* feat: use derive-variant-count instead of hardcoding

* fix: tests

* docs: comma and rearrange

* fix: address comments

* fix: compounding fee dead liquidity reward accounting (#212)

* fix: compounding fee dead liquidity reward accounting

* feat: carry forward dead liquidity reward

* fix: precision

* docs: update changelog

* fix: saturate and document

* fix: use wrapping to keep dead_liquidity_reward_checkpoint from overflowing

* fix: Reward Delegate Can Clear Rewards Without Transfer (#213)

* feat: update EvtUpdateDelegatePermission to include delegate (#216)

* fix: Incomplete Delegate Endpoint List (#214)

* fix: withdrawing_dead_liquidity_reward & dead_liquidity_reward no longer carry forward (#217)

* fix: add new ix to reduce breaking changes

* fix: test

* fix: remove unnecessary fund reward restriction

* fix: tests

* fix: based on comments

* fix: typo (#218)
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.

2 participants