Skip to content

Conversation

@dkuthoore
Copy link
Collaborator

@dkuthoore dkuthoore commented Oct 30, 2025

Updated the validation logic for AssignDeposit and CreateVault actions in accordance with system prompt updates on the web app.

Summary

This PR does 2 things:

  1. Adds validation support for CreateVault intentions, updates fee validation for AssignDeposit intentions,
    CreateVault intentions can now have empty arrays for inputs, outputs, and all fee fields, while AssignDeposit now allows empty totalFee arrays (previously required non-empty with zero amounts). Both action types have consistent validation patterns and return early after processing to skip unnecessary balance checks. These changes have been reflected in the system prompt as well.

  2. Fully extracts validator functions to utils/validator.ts using a factory pattern. per feedback in [WIP] Assign Deposit Handling #48
    All validation logic is now centralized in validator.ts with contract dependencies injected via a factory function.

Changes Made

AssignDeposit Validation Updates

  • Modified validateAssignDepositStructure() (src/utils/validator.ts):
    • Changed totalFee validation to allow empty arrays; if not empty, all amounts must be '0'
    • Updated function documentation
  • Updated documentation in src/proposer.ts to reflect the new totalFee rule

CreateVault Validation

  • Added validateCreateVaultStructure() function (src/utils/validator.ts):
    • Validates that inputs, outputs, and all fee arrays must be empty
  • Updated validateIntention() function (src/utils/validator.ts):
    • Added special handling for CreateVault actions using optional validation functions
  • Added helper functions (src/utils/validator.ts):
    • validateIntentionInputsOptional(): Allows empty arrays for inputs
    • validateIntentionOutputsOptional(): Allows empty arrays for outputs
  • Updated handleIntention() function (src/proposer.ts):
    • Calls validateCreateVaultStructure() before processing CreateVault intentions
    • Returns early after CreateVault handling (skips balance checks and bundling)

Validator Extraction (Factory Pattern)

  • Added factory function to src/utils/validator.ts:
    • Created VaultIdValidator interface for contract dependency
    • Added createValidators() factory that returns configured validateVaultIdOnChain and validateAssignDepositStructure functions
  • Refactored src/proposer.ts:
    • Removed wrapper functions that depended on module-level contracts
    • Updated initializeWalletAndContract() to use factory pattern after contract initialization
    • Added defensive null checks before validator usage

Validation Consistency

  • Both AssignDeposit and CreateVault follow the same pattern:
    • General validation via validateIntention() first
    • Action-specific structural validation
    • Early return after processing (no balance checks for these special actions)

@dkuthoore dkuthoore requested a review from pemulis as a code owner October 30, 2025 17:04
@pemulis pemulis merged commit 7785305 into main Oct 31, 2025
2 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.

4 participants