Skip to content

chore: Implement VedaAdapter#166

Open
MoMannn wants to merge 29 commits into
mainfrom
chore-veda-adapter
Open

chore: Implement VedaAdapter#166
MoMannn wants to merge 29 commits into
mainfrom
chore-veda-adapter

Conversation

@MoMannn
Copy link
Copy Markdown
Member

@MoMannn MoMannn commented Mar 2, 2026

What?

  • Adds VedaAdapter.sol — a new adapter contract for delegation-based deposits and withdrawals on Veda BoringVault
  • Adds IVedaTeller.sol — minimal interface for Veda's TellerWithMultiAssetSupport
  • Adds VedaLending.t.sol — comprehensive test suite (fork tests, happy paths, input validation, events, batch operations, edge cases, 3-level delegation chain, terms validation, replay prevention, slippage protection, alternative delegator)
  • Adds BatchDepositExecuted and BatchWithdrawExecuted events for off-chain indexing of batch operations

Why?

  • Enables users to deposit into and withdraw from Veda BoringVaults through the delegation framework, without requiring direct token approvals
  • Allows operators to execute vault operations on behalf of users via the redelegation pattern, with fine-grained control over tokens, amounts, and who can redeem

How?

  • Uses the redelegation pattern (user → operator → adapter) consistent with DelegationMetaSwapAdapter
  • Parses deposit token/amount and withdrawal share amount from the leaf delegation's caveat terms via a shared _parseERC20TransferTerms helper, which validates that terms are at least 52 bytes (ERC20TransferAmountEnforcer format) before reading with assembly
  • On deposit: redeems the delegation chain to transfer tokens to the adapter, approves the BoringVault, and calls the 5-arg teller.deposit() to mint shares directly to the root delegator
  • On withdraw: redeems the delegation chain to transfer vault shares to the adapter, then calls teller.withdraw() to burn shares and send the desired underlying output asset to the root delegator. The output token is passed as a function parameter (distinct from the vault share token in the caveat)
  • Supports batched operations via depositByDelegationBatch / withdrawByDelegationBatch, each emitting a batch-level event alongside per-stream DepositExecuted / WithdrawExecuted events
  • Includes withdrawEmergency (owner-only) for recovering tokens accidentally sent to the contract

Note

  • Tests are being run on a mainnet fork of Arbitrum on a deployment of Veda protocol

Note

Medium Risk
Introduces a new funds-moving adapter (VedaAdapter) that redeems delegations to transfer ERC20s/vault shares and calls into external Veda contracts; any mistakes in terms parsing, delegation assumptions, or approvals could lead to loss of funds. Risk is mitigated by extensive fork-based tests and input validation, but the surface area is still security-sensitive.

Overview
Adds a new VedaAdapter contract to support delegation-based deposits/withdrawals into Veda’s BoringVault via IDelegationManager.redeemDelegations, including batch variants (depositByDelegationBatch / withdrawByDelegationBatch) and per-stream + batch events for indexing.

The adapter now parses transfer amounts from the leaf delegation’s first caveat terms (ERC20TransferAmountEnforcer format) and includes owner-only safety utilities (ensureAllowance to restore max vault allowance; withdrawEmergency to recover stuck tokens).

Also adds a minimal IVedaTeller interface, a deployment script (DeployVedaAdapter.s.sol), and a large Arbitrum-fork test suite covering happy paths, validation/reverts, events, batching, replay prevention, and allowance behavior; CI and .env.example are updated with required Veda/Arbitrum RPC env vars.

Reviewed by Cursor Bugbot for commit d6fe82a. Bugbot is set up for automated code reviews on this repo. Configure here.

@MoMannn MoMannn requested a review from a team as a code owner March 2, 2026 10:34
Comment thread src/helpers/VedaAdapter.sol Outdated
@MoMannn MoMannn requested a review from hanzel98 March 30, 2026 09:52
Comment thread src/helpers/VedaAdapter.sol Outdated
Comment thread src/helpers/VedaAdapter.sol Outdated
Comment thread src/helpers/VedaAdapter.sol Outdated
Comment thread test/helpers/VedaLending.t.sol Outdated
@MoMannn MoMannn requested a review from McOso April 2, 2026 07:39
Comment thread script/DeployVedaAdapter.s.sol Outdated
Comment thread src/helpers/interfaces/IVedaTeller.sol
Comment thread src/helpers/VedaAdapter.sol Outdated
Comment thread src/helpers/VedaAdapter.sol Outdated
* @param _amount The amount of tokens to recover
* @param _recipient The address to receive the recovered tokens
*/
function withdrawEmergency(IERC20 _token, uint256 _amount, address _recipient) external onlyOwner {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm im thinking we get rid of this function. It doesnt seem possible for tokens to be left in this contract without the tx reverting, since it's atomic. If we remove, it really makes the adapter clean and lightweight, removes the need for owner / state.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is in case of someone sending tokens directly to the contract (mistaking it for EOA).

Comment thread src/helpers/VedaAdapter.sol Outdated
Comment thread src/helpers/VedaAdapter.sol Outdated
Comment thread src/helpers/VedaAdapter.sol Outdated
@MoMannn MoMannn requested review from McOso and hanzel98 April 7, 2026 07:59
Comment thread src/helpers/VedaAdapter.sol
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ede87fa. Configure here.

Comment thread test/helpers/VedaLending.t.sol
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.

3 participants