Skip to content

🏦 Create Treasury Protection Policies #144

Description

@mijinummi

🏦 Create Treasury Protection Policies

Issue: #144
Type: Feature
Priority: High
Estimated Effort: 2–3 days


🧠 Concept

Implement a configurable treasury protection policy engine that allows organizations to define security rules for monitoring treasury wallets and high-value assets. The engine should continuously evaluate treasury-related activity against configured policies and generate alerts whenever a policy is violated.

The goal is to provide an additional layer of governance and risk management for wallets that hold significant organizational funds.


⚠️ Problem

Treasury wallets often contain an organization's most valuable on-chain assets and therefore require stricter monitoring than regular wallets.

Common treasury risks include:

  • Unauthorized high-value transfers
  • Unexpected treasury depletion
  • Transfers to unapproved recipient addresses
  • Large withdrawals outside business hours
  • Excessive transaction frequency
  • Misconfigured automation or compromised treasury accounts
  • Policy violations that may indicate insider threats or external attacks

Currently, there is no centralized mechanism to define organization-specific treasury protection rules or automatically enforce monitoring against those rules.

Without configurable treasury policies:

  • High-risk transactions may go unnoticed until after execution.
  • Organizations cannot tailor monitoring to their operational requirements.
  • Security teams lack consistent enforcement of treasury controls.
  • Incident response is delayed due to missing contextual alerts.

πŸ“ Implementation Scope

src/modules/treasury/policies/

Suggested structure:

policies/
β”œβ”€β”€ treasury-policy.service.ts
β”œβ”€β”€ treasury-policy.engine.ts
β”œβ”€β”€ treasury-policy.repository.ts
β”œβ”€β”€ treasury-policy.validator.ts
β”œβ”€β”€ treasury-policy.scheduler.ts
β”œβ”€β”€ dto/
β”œβ”€β”€ entities/
β”œβ”€β”€ interfaces/
β”œβ”€β”€ enums/
β”œβ”€β”€ alerts/
└── utils/

βœ… Requirements

Treasury Policy Management

Implement CRUD operations for treasury protection policies.

Each policy should support configurable fields such as:

  • Policy name
  • Description
  • Status (Enabled / Disabled)
  • Protected wallet(s)
  • Network
  • Rule type
  • Threshold values
  • Severity level
  • Notification preferences

Policies should be editable without requiring application redeployment.


Policy Types

Support configurable rule types, including but not limited to:

  • Maximum transaction amount
  • Daily transfer limit
  • Hourly transfer limit
  • Maximum number of transactions
  • Percentage of treasury balance transferred
  • Unauthorized destination address
  • Large balance decrease
  • High-frequency transfers
  • First-time recipient detection

The architecture should allow additional policy types to be added with minimal changes.


Threshold Definitions

Allow administrators to configure thresholds such as:

  • Fixed asset amount
  • Percentage of treasury balance
  • Number of transactions within a time window
  • Time-based limits
  • Risk score thresholds

Threshold values should be configurable and validated before activation.


Policy Evaluation Engine

Continuously evaluate treasury transactions against active policies.

The engine should:

  • Evaluate all enabled policies
  • Support multiple active policies per wallet
  • Detect violations in near real time
  • Prevent duplicate processing of the same transaction
  • Produce deterministic evaluation results

Violation Detection

Detect policy violations including:

  • Transaction exceeds configured limit
  • Daily transfer quota exceeded
  • Transfer sent to an unapproved wallet
  • Treasury balance drops below configured minimum
  • Multiple high-value transfers within a short period
  • Suspicious transfer velocity
  • Excessive treasury activity outside approved operating hours (if configured)

Each violation should include the triggering rule and supporting context.


Alert Integration

Generate alerts whenever a policy violation occurs.

Alerts should include:

  • Policy name
  • Wallet address
  • Network
  • Transaction hash
  • Violated rule
  • Configured threshold
  • Observed value
  • Timestamp
  • Severity
  • Recommended action (where applicable)

Alerts should integrate with the existing notification and incident management system.


Policy Persistence

Persist:

  • Active policies
  • Policy versions (optional)
  • Violation history
  • Evaluation results
  • Alert references

Historical records should support audits and compliance reporting.


Audit Logging

Record administrative actions such as:

  • Policy creation
  • Policy updates
  • Policy deletion
  • Policy activation/deactivation
  • Threshold modifications

Logs should include timestamps and sufficient metadata for auditing.


Error Handling

The policy engine should:

  • Retry transient failures
  • Log evaluation errors
  • Continue processing unaffected policies if one evaluation fails
  • Handle malformed or incomplete policy configurations gracefully

πŸ”’ Non-Functional Requirements

  • Configurable and extensible rule engine
  • Idempotent policy evaluation
  • Efficient processing for high transaction volumes
  • Structured logging
  • Type-safe DTOs and entities
  • Modular architecture for future policy types
  • Unit-testable evaluation logic
  • Minimal duplicate alerts

🎯 Acceptance Criteria

  • Treasury protection policies can be created, updated, enabled, disabled, and deleted
  • Multiple policies can be applied to the same treasury wallet
  • Configurable thresholds are validated and enforced correctly
  • Policy violations are detected automatically during transaction monitoring
  • Duplicate violations are not generated for the same triggering event
  • Alerts are generated with sufficient contextual information
  • Policy evaluations and violation history are persisted for auditing
  • Administrative policy changes are audit logged
  • Code passes linting, type checking, and existing test suites

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions