Skip to content

feat: add Stellar Turrets integration for automated invoice monitoring #801

Description

@sanmipaul

Summary

Invoice due-date monitoring and default triggering currently requires manual admin intervention. If no admin calls `mark_defaulted()` after grace period expiry, the invoice stays in an ambiguous state indefinitely. Stellar Turrets (or a Soroban automation service) can automate this monitoring.

Desired Automation

A Turret function that runs on a schedule:

  1. Fetches all `Active` invoices past their grace period deadline
  2. For each, submits a `mark_defaulted(invoice_id)` transaction signed by the Turret's key
  3. Turret key is whitelisted as a "keeper" in the invoice contract

```rust
// New role: keeper (can only call mark_defaulted, not other admin functions)
pub fn add_keeper(env: Env, keeper: Address) {
admin::require_admin(&env);
// ...
}

pub fn mark_defaulted(env: Env, invoice_id: u64) {
require_admin_or_keeper(&env);
// ... existing default logic ...
}
```

Alternative: Soroban Custom Account

Use a Soroban custom account contract that automatically triggers default when called by anyone, but only if the grace period has verifiably expired.

Acceptance Criteria

  • `keeper` role added with permission to call `mark_defaulted()` only
  • `add_keeper()` and `remove_keeper()` admin functions created
  • Monitoring script created in `scripts/monitor_invoices.ts`
  • Script can be run as a cron job or deployed to a Turret
  • Integration test: grace period expires → keeper call succeeds, non-keeper fails
  • Documentation for deploying the monitor script

References

  • `contracts/invoice/src/lib.rs` — `mark_defaulted()`
  • Stellar Turrets documentation

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or requestsmart-contractSoroban/Rust contract work

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions