Skip to content

chore: Implement VedaAdapter#166

Open
MoMannn wants to merge 18 commits intomainfrom
chore-veda-adapter
Open

chore: Implement VedaAdapter#166
MoMannn wants to merge 18 commits intomainfrom
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

High Risk
Introduces a new adapter that can move user tokens/shares via redeemDelegations and grants (potentially unlimited) ERC20 allowances to the Veda boringVault, so any mistake in delegation/caveat assumptions could lead to fund loss. Also adds mainnet-fork tests and CI env changes that may be flaky due to external RPC dependencies.

Overview
Adds VedaAdapter, an Ownable2Step helper that executes delegation-based deposits and withdrawals against Veda’s Teller/BoringVault by redeeming a delegation chain, parsing the token+amount from the leaf caveat terms, and then calling teller.deposit/teller.withdraw (plus a batch variant for each).

The adapter includes batch-level events (BatchDepositExecuted, BatchWithdrawExecuted), per-call events, basic input/terms validation, a lazy “approve max” allowance strategy for deposits, and an owner-only withdrawEmergency for recovering stuck tokens.

Adds IVedaTeller, a DeployVedaAdapter foundry script, and a large Arbitrum mainnet-fork test suite covering happy paths, reverts, replay protection assumptions, batching, and emergency withdrawal; CI and .env.example are updated to include Arbitrum/RPC secrets and Veda deployment addresses.

Reviewed by Cursor Bugbot for commit 01be197. 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
@MoMannn MoMannn requested a review from hanzel98 March 30, 2026 09:52
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 4 potential issues.

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.

@MoMannn MoMannn requested a review from McOso April 2, 2026 07:39
* @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).

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