Skip to content

feat(compound-v2): Comptroller.enterMarkets toggle for Venus borrow lifecycle - #26

Merged
Hiksang merged 2 commits into
mainfrom
feat/compound-v2-enter-markets
May 8, 2026
Merged

feat(compound-v2): Comptroller.enterMarkets toggle for Venus borrow lifecycle#26
Hiksang merged 2 commits into
mainfrom
feat/compound-v2-enter-markets

Conversation

@Hiksang

@Hiksang Hiksang commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Compound V2 family (Venus on BNB) silently rejects borrows when the supplied cToken hasn't been entered as collateral via `Comptroller.enterMarkets([cToken])`. Without that call, `getAccountLiquidity` reports zero collateral and any borrow reverts. Mirrors PR #21's Aave V3 `setUserUseReserveAsCollateral` toggle.

Changes

  • compound_v2.ts: COMPTROLLER_ABI (enterMarkets/exitMarket) + comptroller field + `buildEnterMarkets(cTokens[])` method.
  • ILending: optional `buildEnterMarkets?(cTokens)`.
  • CLI: `defi lending enter-markets --protocol venus-bnb --asset USDT [--broadcast]` resolves the asset symbol to its registered v* contract via prefix match (USDT → vusdt).
  • compound_v2.test.ts: 4 new regressions pinning calldata + comptroller target + batch enter + missing-comptroller guard.

Live BNB Venus lifecycle (5/5 confirmed)

Step TX
supply 0.05 USDT 0x687ece09…26c5
enter-markets vUSDT 0x21ce1f63…2d2d
borrow 0.02 USDT 0x0b9c7d3e…6857
repay 0.02 USDT 0xe1e98194…e906
withdraw 0.05 USDT 0x9450acb4…6daf

Test plan

  • defi-protocols 59/59 tests pass (compound_v2.test.ts 14 → 18)
  • defi-cli 102/102 tests pass
  • Build/lint clean

🤖 Generated with Claude Code

Hiksang and others added 2 commits May 7, 2026 20:41
…ow lifecycle

Compound V2 family (Venus on BNB, Compound on Mainnet etc.) silently rejects
borrows when the supplied cToken hasn't been entered as collateral via
Comptroller.enterMarkets([cToken]). Without that call, getAccountLiquidity
reports zero collateral and any borrow reverts. Mirrors the role of Aave V3's
setUserUseReserveAsCollateral (PR #21), but the API is batch-by-cToken.

Changes:
- compound_v2.ts: add COMPTROLLER_ABI (enterMarkets/exitMarket), comptroller
  field, and buildEnterMarkets(cTokens[]) method on CompoundV2Adapter.
- ILending: add optional buildEnterMarkets?(cTokens) for Compound-V2-family
  adapters. Aave V3 / Compound V3 / Morpho leave this undefined.
- defi lending enter-markets: new CLI subcommand resolving --asset to the
  registered v* contract via symbol prefix matching (e.g. USDT → vusdt).
- compound_v2.test.ts: 4 new regressions pinning calldata + comptroller
  target, batch enter, empty-array guard, missing-comptroller guard.

Live BNB Venus lifecycle (5/5 confirmed on bsc mainnet):
- supply  0.05 USDT  → 0x687ece09ff808f61dac7b4adef732baf68e1acd362cc89af8b05f8890b3f26c5
- enter   vUSDT      → 0x21ce1f63d062f7e2c64fffdc5a8bb2ee0417b3a2b964e0f0cdc3e1610f002d2d
- borrow  0.02 USDT  → 0x0b9c7d3e5fcd9161c1888177b1d2b882d50cbd19ab134ed512ad4ddc1b966857
- repay   0.02 USDT  → 0xe1e98194fd0cd33ca6f39333d02c8787c3507e4187102348f0a0b4d29029e906
- withdraw 0.05 USDT → 0x9450acb409d41927e710a1494e097c5980c0ef754609381b946c448dbaf56daf

Borrow tx confirms enter-markets did register vUSDT in accountAssets[]; the
exact same flow without the toggle is what was reverting pre-PR.

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

# Conflicts:
#	ts/packages/defi-cli/dist/index.js
#	ts/packages/defi-cli/dist/index.js.map
#	ts/packages/defi-cli/dist/main.js
#	ts/packages/defi-cli/dist/main.js.map
#	ts/packages/defi-cli/dist/mcp-server.js
#	ts/packages/defi-cli/dist/mcp-server.js.map
#	ts/packages/defi-core/dist/index.d.ts
#	ts/packages/defi-core/dist/index.js.map
#	ts/packages/defi-protocols/dist/index.js
#	ts/packages/defi-protocols/dist/index.js.map
@Hiksang
Hiksang merged commit 5842483 into main May 8, 2026
@Hiksang
Hiksang deleted the feat/compound-v2-enter-markets branch May 8, 2026 11:54
Hiksang added a commit that referenced this pull request May 8, 2026
…ion + adapter fixes (#32)

* build: regenerate dist + sync prebuild package configs for v1.0.13

Re-runs `pnpm -r build` from current main HEAD and syncs the package-
local config mirror so npm-published artifacts match the source tree.

Reason: across PRs #23 / #26 / #27 we resolved dist conflict markers
by taking main's stale dist (`git checkout --theirs`) — that kept the
PRs mergeable but left committed dist files out of sync with the
post-merge source. This single rebuild commit reconciles them.

Affected:
  defi-cli/dist/{index,main,mcp-server}.js  (~+700 lines source-derived)
  defi-cli/dist/*.map
  defi-protocols/dist/{index.js, index.d.ts, *.map}
  defi-core/dist/{index.d.ts, *.map}
  defi-cli/config/protocols/lending/venus_flux_bnb.toml
    (prebuild sync from workspace root: vusdt → vlisusd rename)

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

* Release v1.0.13: bridge feature + production-grade verification + adapter fixes

Highlights since v1.0.12 (30 commits across 8 PRs):

== Bridge feature complete ==
- Relay added as 4th provider (~3s native bridge, executor-wired live)
- LiFi + deBridge + CCTP wired to Executor — `--broadcast` no longer silently ignored
- CCTP V2 `--auto-receive` — burn → poll Iris attestation → auto-receiveMessage on dest
- Live-verified Base→Arbitrum 0.1 USDC E2E (burn 0x6b5d41fd, receive 0x9b5bd5c2)
- Per-chain src/dst token resolution for cross-chain stables
- Relay errorCode parsing → actionable hints (AMOUNT_TOO_LOW, NO_QUOTES, etc)
- MCP `defi_bridge` 3 latent fixes: dst-token, Relay symbol→native, LiFi fromAddress

== Adapter bug fixes ==
- compound_v2: uint256.max withdraw + outstanding-borrow guard (Venus, Compound V2 forks)
- venus-flux-bnb: rename mislabeled `vusdt` → `vlisusd` (actual underlying is lisUSD)
- Ramses CL mint encoding + MerchantMoe/TraderJoe LB token-order realign
- Curve target the pool not router + StableswapNG dynamic uint256[] ABI
- uniswap-v2 / solidly LP-token approval on remove
- Hybra V4 --redeem-type CLI flag for instant-exit vs 2-year veHYBR lock
- Aave V3 collateral toggle + eMode for borrow lifecycle (#21)
- Morpho marketId-based supply/borrow + supplyCollateral (#22)
- Compound V2 enterMarkets toggle for Venus borrow lifecycle (#26)
- Native wrap/unwrap CLI + Morpho marketId registry + max-repay-by-shares (#27)

== Production-grade verification sweep ==
- HyperEVM 11/11 protocols full lifecycle (emission tokens received)
- Mantle: Aave V3 + UniV3 + MerchantMoe LB (MOE 1.009 received)
- Base: UniV3 + Aerodrome V2 + Aerodrome CL (AERO emission received)
- BNB upgraded to 🟢 production: 13/16 protocols verified live
- Monad partial: UniV3 + UniV2 (mainnet TBD for the rest)
- ve(3,3) emission tokens live-received: RAM, KITTEN, MOE, AERO, THE
- ULTRAQA sandbox script (51-test sweep across 4 chains)

== Hardening ==
- ip-address >=10.1.1 via pnpm.overrides (GHSA-v2v4-37r5-5v8g moderate XSS)
- viem wallet/public clients anchored to chainId at construction (#29)
- CLI handler unit-test coverage for status/schema (#28)
- @vitest/coverage-v8 baseline measurement script (#30)
- post-baseline test-foundation QA report (#31)

== Test plan ==
- pnpm -r test: 189/189 pass (defi-core 32, defi-protocols 55, defi-cli 102)
- pnpm -r build: clean across all 3 packages
- pnpm audit: 0 vulnerabilities
- ULTRAQA sandbox: 51/51 pass + 8/8 ve(3,3) lp pipeline
- CCTP --auto-receive E2E: live broadcast verified
- MCP defi_bridge smoke: LiFi USDC + Relay USDC + Relay native — all OK

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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