72: Add the Evelyn IOU buyback-and-burn service

This commit is contained in:
2026-08-13 16:47:01 +02:00
parent 961f8c69cb
commit 3d5de0e09b
11 changed files with 1790 additions and 8 deletions
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-08-13
@@ -0,0 +1,83 @@
## Context
See `proposal.md` for motivation. The lower-level services already separate wallet state and signing, Jupiter's single managed execution plus `CONFIRMED` wait, generic Solana `FINALIZED` awaiting, price observations, AssetAZ identity translation, and synchronous bound notification delivery. The new component must orchestrate those boundaries without widening their APIs, leaking Solana details into Evelyn configuration, or mistaking timeout and communication failure for permission to repeat a transaction.
## Goals / Non-Goals
**Goals:**
- Keep the public API minimal while documenting the complete externally significant iteration and safety contract.
- Make stable AssetAZ UUIDs and an ordered `List<MoneyAmount>` the only input-selection model, with CIS and Solana resolving technical representations internally.
- Encode swap and burn uncertainty as conservative process-local lifecycle state so a periodic worker cannot duplicate an operation automatically.
- Keep each iteration sequential, permit existing EVE to be burned independently of swap success, and bind notification data to the exact submitted burn.
**Non-Goals:**
- Persisting reconciliation state or providing operator recovery tooling after restart.
- Adding configuration objects, parsers, extra constructors, Nenjim autorun/composition wiring, or wallet/webhook secrets.
- Introducing burner-specific input types, a reusable generic burner, new ValueTags, dependencies, tests, or production test hooks.
- Retrying transactions, transaction awaits, or notifications, closing token accounts, or estimating native SOL fees.
## Decisions
### Keep input configuration unchanged and canonicalize on use
The implementation stores `List.copyOf(inputCurrencyMinimumReserves)` after validating every entry. It does not replace `MoneyAmount`, attach mint/program fields, or create an input-specific interface, record, or hierarchy. Construction resolves every configured UUID to prove it is known, detects duplicates and EVE, and verifies exactly one non-blank `solana-mint` reference for every non-SOL input. Each iteration resolves the UUID again and uses the returned canonical `CurrencyType`, deliberately ignoring configured display metadata.
Caching pre-resolved integration DTOs was rejected because it would create the prohibited parallel burner input model and weaken the visible rule that UUID is authoritative. Extending `MoneyAmount` was rejected because reserve validity and accepted-input policy belong only to this service.
### Resolve representation and precision at the point of use
The input loop handles candidates inline in priority order rather than materializing burner-specific candidate objects. SOL is recognized by `CurrencyTypeIds.SOLANA_ID`, read through `getSolanaBalance()`, assigned its protocol-defined nine decimals, and translated to the unique canonical CIS SOL/WSOL mint only when calling Jupiter. Other currencies resolve their unique CIS mint, inspect the mint-account owner against the two supported `SolanaSPLTokenProgram` values, read balance with that program, and obtain decimals from current mint supply metadata.
A constructor-supplied program or mint was rejected because those are mutable integration facts rather than Evelyn domain configuration. Treating native SOL as a wallet SPL holding was rejected because it would observe the wrong balance. A general CIS preferred-mint redesign was rejected because the current burner contract deliberately fails ambiguous non-SOL configuration.
### Round the exact-input limit downward at mint precision
For a candidate with positive spendable balance and usable price, the implementation divides the positive USDC cap by price using the input precision and `RoundingMode.DOWN`, takes the lesser of that cap and `balance - reserve`, then applies the same downward scale once more. USDC bypasses ticker lookup with an exact price of one. This produces an exactly representable Jupiter amount that cannot exceed the USDC cap through rounding.
Using arbitrary high precision followed by Jupiter rejection was rejected because supported precision is already available. Half-up rounding was rejected for transaction amounts because it can cross either the configured cap or reserve boundary. SOL fees remain intentionally outside the calculation, so execution may consume part of the reserve or fail when no fee balance remains.
### Use one daemon scheduled worker and fixed delay
Each start creates one single-thread scheduled executor, resets process-local state, and schedules with zero initial delay plus the validated interval as fixed delay. The task boundary catches ordinary failures so one bad iteration does not silently cancel future scheduling. Interruption is restored and terminates current processing. Stop prevents scheduling, interrupts the executor, waits for bounded clean termination, and clears state only after the worker has ended; a still-active or stopping instance cannot start another worker.
A timer that dispatches concurrent jobs was rejected because overlap would violate transaction ordering. A global worker was rejected because state and lifecycle belong to the service instance. Fixed rate was rejected because a slow blockchain wait could cause catch-up behavior instead of delaying from completion.
### Model transaction uncertainty as two suspensions plus one pending burn
The worker owns separate boolean flags for swap and burn suspension and one private pending-burn value containing signature, exact submitted EVE amount, and calculated USD value. A pending signature always short-circuits the next iteration before input inspection. Timeout and await I/O retain it; definitive failure clears it without same-iteration work; success proceeds to the associated notification only.
For swaps, `JupiterTransactionOutcomeException` exposes the needed distinction: `FAILED` is definitive and allows later-iteration swaps, while `TIMED_OUT` suspends them. Any swap `IOException` is treated as potentially post-submission because the public contract permits that state. Interruption is also conservative because it can occur during execution or confirmation. In every case the input loop returns after its first Jupiter invocation.
For burns, a returned signature is stored before awaiting. An `IOException`, interruption, blank signature, or other submission-contract failure that can have occurred after send suspends future burn submissions when no usable signature is available. Local validation failures that are known to precede submission may be reconsidered after a later state reload. Swap and burn suspension remain separate: one unknown operation does not authorize repetition and does not erase the other safe parts of an iteration.
Persisting flags/signatures was rejected by issue scope. Consequently, an explicit stop/start or process restart intentionally forgets unknown state. Wallet reloading reduces stale-state risk but cannot prove an unknown transaction is dead; operators should reconcile known chain activity before deliberately resetting a suspended or pending lifecycle.
### Bind price and notification data before the burn
The complete EVE wallet balance is always reloaded after the optional swap attempt rather than trusting `JupiterSwapResult.receivedOutputTokenAmount()`. Before submission, the implementation validates the latest canonical EVE/USDT observation against the current time and stores the resulting unrounded USD value together with the returned burn signature. This postpones every burn that could not be truthfully announced and ensures a later price movement cannot change the value associated with a pending burn.
On successful `FINALIZED`, the pending state is made ineligible for another delivery before calling the synchronous notification service. Amount formatting uses `stripTrailingZeros().toPlainString()`; USD formatting uses scale two and `HALF_UP`. Delivery exceptions are logged by type and transaction identity without including destination details, and pending state is never restored.
Deriving the burn from Jupiter output was rejected because the wallet can already contain EVE. Pricing after finalization was rejected because a future missing price would leave a completed burn without its required announcement. Keeping pending state until notification returns was rejected because an unchecked delivery failure could otherwise cause a second attempt.
### Clarify Jupiter native SOL support without widening its API
The existing Jupiter reference implementation already treats its `inputTokenMint` as a mint used for precision validation and passes it unchanged to Swap V2. The canonical SOL/WSOL mint is a valid Solana mint, and Jupiter interprets it for native SOL input from the taker. Therefore only the public JavaDoc and `jupiter-swap-service` contract need clarification; no separate method or implementation branch is required, and legacy SPL plus Token-2022 behavior remains unchanged.
## Risks / Trade-offs
- [A process or explicit lifecycle reset forgets a pending signature or suspension] → Document the safety limitation prominently, reload balances on every later decision, and require deliberate external reconciliation before an operator resets unknown state.
- [A wallet or network exception may have occurred before submission but cannot prove that] → Prefer conservative lifecycle suspension over a possible duplicate buyback or burn.
- [A stale mint reference was valid at construction but CIS changes dynamically] → Resolve canonical identity and external references again during processing and skip unusable representations safely.
- [A mint balance or supply changes between reads and submission] → Submit only exactly representable observed amounts once and let wallet/Solana validation reject races without automatic retry.
- [Notification succeeds remotely but the response is lost] → Count the single local invocation as the only attempt and never retry it, because notification delivery is not transaction completion.
- [Stop cannot promptly interrupt a misbehaving dependency] → Use interruption plus bounded termination and refuse a new worker while termination remains unconfirmed.
## Migration Plan
1. Add the Evelyn burner API and reference implementation without composing or starting it in production.
2. Clarify the existing Jupiter JavaDoc while preserving its public method signature and reference implementation.
3. Compile and assemble production sources, perform strict OpenSpec validation, and use structural/manual review only; add no automated tests.
4. Leave this change active for review. Rollback removes the new service and documentation delta; there is no persisted state, configuration, or data migration.
@@ -0,0 +1,30 @@
## Why
The available wallet, Jupiter, Solana transaction-awaiting, ticker, currency-identity, and notification services now make an automated Evelyn IOU buyback-and-burn flow possible, but no Evelyn-owned orchestration currently combines them with the transaction-safety rules needed to avoid duplicate swaps or burns. Issue #72 adds that orchestration while keeping stable AssetAZ UUIDs—not Solana integration details—as its configuration boundary.
## What Changes
- Add an Evelyn-specific continuously running `EvelynIOUBurnerService` API and reference implementation with immediate, non-overlapping, fixed-delay iterations and explicit start/stop lifecycle behavior.
- Configure prioritized accepted inputs and their minimum reserves as an ordered defensive copy of `List<MoneyAmount>`, using each entry's AssetAZ UUID as authoritative and canonicalizing metadata through `CurrencyIdentityService`.
- Resolve native SOL and unique non-SOL `solana-mint` representations internally through CIS, detect supported SPL token programs and token precision through Solana, and keep mints/programs out of Evelyn's constructor configuration.
- Limit each iteration to at most one exact-input Jupiter attempt and to the configured USDC-equivalent ceiling, while preserving each currency's reserve and rounding downward to its supported precision.
- Reload and burn the complete visible EVE balance only with a fresh canonical EVE/USDT price, retain pending burn signatures until a definitive `FINALIZED` result, and make exactly one notification attempt after successful finalization.
- Suspend later swaps or burns for the current lifecycle when their submission outcome may be unknown; never automatically retry, rebuild, re-sign, or resubmit a transaction. Reset process-local pending and suspension state only on an explicit stop/start cycle.
- Clarify the existing Jupiter swap contract so the canonical SOL/WSOL mint may represent native SOL input without changing the existing `swap(...)` signature or SPL/Token-2022 behavior.
- Keep configuration parsing, Nenjim autorun wiring, persistence, generic burner abstractions, tests, and test hooks out of scope.
## Capabilities
### New Capabilities
- `evelyn-iou-burner-service`: Defines the Evelyn-specific configuration, identity resolution, buyback limit and priority rules, sequential lifecycle, complete-balance burn, pending/unknown transaction safety, finalization, and one-attempt notification behavior.
### Modified Capabilities
- `jupiter-swap-service`: Explicitly supports native SOL input when represented by the canonical CIS-resolved SOL/WSOL mint while retaining the existing exact-input API and behavior for supported SPL token programs.
## Impact
- Adds public API source under `com.fanitas.evelyn.service.burner` and its reference implementation under `com.fanitas.evelyn.service.burner.impl.ref`.
- Uses existing `SolanaWallet`, `JupiterSwapService`, `SolanaBlockChain`, `TickerService`, `CurrencyIdentityService`, `BoundNotificationService`, `MoneyAmount`, and ValueTags without adding dependencies or changing DeTag configuration.
- Updates `JupiterSwapService` JavaDoc and the active OpenSpec delta only; no composition-root, configuration-file, persistence, generated-source, or automated-test changes are included.
@@ -0,0 +1,227 @@
## Purpose
Defines the Evelyn-specific service that safely converts prioritized wallet assets into Evelyn IOU, burns the complete visible EVE balance, and announces only finalized burns without automatically repeating transactions whose outcomes may be unknown.
## ADDED Requirements
### Requirement: Evelyn-specific public service boundary
The system SHALL expose `EvelynIOUBurnerService` under `com.fanitas.evelyn.service.burner` with only `start()` and `stop()` operations, and SHALL keep its reference implementation under `com.fanitas.evelyn.service.burner.impl.ref`. The service SHALL remain specific to Evelyn IOU and SHALL NOT introduce a generic token-burner abstraction, burner-specific input interfaces, records, or class hierarchies.
#### Scenario: Downstream lifecycle consumer
- **WHEN** a downstream component depends on the Evelyn burner API
- **THEN** it can start and stop the service without depending on reference-implementation types or a generic burner model
#### Scenario: Input model remains domain-level
- **WHEN** callers configure accepted buyback currencies
- **THEN** they use existing `MoneyAmount` values rather than burner-specific Solana, SPL-token, or input-asset types
### Requirement: Ordered AssetAZ input configuration
The authoritative constructor SHALL accept a non-null ordered `List<MoneyAmount>` named `inputCurrencyMinimumReserves`, defensively copy it without changing order, and interpret inclusion as acceptance, list position as priority, each `currencyType().id()` as the authoritative AssetAZ identity, and each `amount()` as the minimum balance that must remain. It SHALL ignore supplied currency name and symbol metadata by resolving each UUID through the injected Currency Identity Service and using the canonical returned currency for pricing and processing. An empty list SHALL be valid and SHALL still permit directly deposited EVE to be burned.
#### Scenario: Stale configured metadata
- **WHEN** a configured `MoneyAmount` carries a known UUID but stale name or symbol metadata
- **THEN** the service processes the current canonical currency resolved for that UUID
#### Scenario: Priority is preserved
- **WHEN** multiple configured entries have spendable balances and usable prices
- **THEN** the earliest entry in the defensively copied list is the only input selected in that iteration
#### Scenario: Empty input list
- **WHEN** no buyback inputs are configured but the wallet contains EVE
- **THEN** the service skips input selection and still evaluates the complete EVE balance for burning
### Requirement: Complete constructor validation
Construction SHALL require all injected services, the input list, maximum swap amount, and durations to be non-null; every list entry, entry amount, entry currency, and currency UUID to be non-null; each reserve to be zero or greater; each UUID to be known to the injected Currency Identity Service; UUIDs to be unique; and EVE not to be an input currency. It SHALL require `maximumSwapAmountInUSDC` to be greater than zero, slippage to be from 0 through 10000 basis points inclusive, `maximumPriceAge` to be greater than zero milliseconds, and both finalization timeout and iteration interval to be positive and non-zero.
Every configured non-SOL UUID SHALL resolve through reverse CIS lookup to exactly one external reference in the `solana-mint` namespace, and that reference's external ID SHALL be non-null and non-blank. Construction SHALL fail for a missing, ambiguous, null, or blank non-SOL mint representation. These burner-specific rules SHALL NOT change the general-purpose `MoneyAmount` contract.
#### Scenario: Valid configuration
- **WHEN** every dependency and value is valid, reserves are non-negative, UUIDs are distinct and known, EVE is absent, and every non-SOL input has one non-blank Solana mint reference
- **THEN** construction succeeds and preserves the configured priority order
#### Scenario: Invalid reserve or operating limit
- **WHEN** a reserve is negative or null, the USDC cap is non-positive, slippage is outside its inclusive range, maximum price age is non-positive, or either duration is null or non-positive
- **THEN** construction fails before a worker or transaction is created
#### Scenario: Invalid input identity
- **WHEN** an entry or its currency or UUID is null, a UUID is unknown or duplicated, or the EVE UUID is configured as input
- **THEN** construction fails with a diagnostic identifying the invalid configuration
#### Scenario: Non-SOL representation is not unique and usable
- **WHEN** a configured non-SOL currency has zero or multiple `solana-mint` references or its sole external ID is null or blank
- **THEN** construction fails without adding mint or token-program selection to Evelyn's configuration model
### Requirement: Fixed Evelyn domain values and internally resolved integration values
The service SHALL fix the EVE mint as `meveYG2iXYSkgSUn1T1uxcthH1EGMZdRHGgCntXZA3Y`, construct the EVE/USDT notification-price pair from canonical CIS resolutions of the stable EVE and USDT UUIDs, construct input/USDC pairs with the canonical USDC UUID, and use fixed notification wording. Native SOL SHALL be identified only by the stable SOL UUID; when sent to Jupiter, its input mint SHALL be the canonical CIS Solana-mint reference `So11111111111111111111111111111111111111112`. Mint addresses, token programs, price pairs, notification wording, and a separate SOL reserve SHALL NOT be constructor configuration.
#### Scenario: Native SOL configuration
- **WHEN** a configured input UUID is the stable SOL UUID
- **THEN** the service reads the native wallet balance and later supplies Jupiter with the CIS-resolved canonical SOL/WSOL mint rather than treating SOL as an SPL-token holding
#### Scenario: Fixed EVE behavior
- **WHEN** the service evaluates a burn and notification
- **THEN** it uses the fixed EVE mint and the canonical EVE/USDT pair without accepting replacements through construction
### Requirement: Immediate sequential fixed-delay lifecycle
Each service instance SHALL own at most one dedicated background worker. A successful `start()` SHALL begin the first iteration immediately; every later iteration SHALL begin only after the previous iteration completes and the configured fixed delay elapses; and iterations SHALL never overlap. `stop()` SHALL prevent new iterations, interrupt and stop the worker cleanly, and preserve interruption if the stopping thread is interrupted. A repeated start while active SHALL NOT create another worker.
Pending burn information and swap/burn suspension flags SHALL be process-local only. A completed explicit stop followed by start SHALL clear those states. The public JavaDoc SHALL disclose that this reset, or a process restart, loses reconciliation state and can weaken duplicate-prevention until unknown transactions have been reconciled externally.
#### Scenario: First and later iterations
- **WHEN** the service starts and one iteration takes longer than usual
- **THEN** the first iteration starts without initial delay and the next starts only after completion plus the configured interval
#### Scenario: Active service is started again
- **WHEN** `start()` is called while the instance already owns an active worker
- **THEN** the call is rejected without creating an overlapping worker
#### Scenario: Explicit lifecycle reset
- **WHEN** a service with pending or suspended process-local state is cleanly stopped and then explicitly started
- **THEN** the new lifecycle begins without that state and reloads wallet and chain state normally
### Requirement: Pending burn is handled before all new work
At the start of an iteration, if a prior burn signature is pending, the service SHALL only await that exact signature at `FINALIZED`. It SHALL submit no swap or burn in that iteration. An unknown timeout or I/O outcome SHALL retain the pending state and end the iteration; definitive success SHALL make the one associated notification attempt and end the iteration; and definitive on-chain failure SHALL log the slot and complete failure details, clear pending state, send no notification, and defer any new wallet decision to a later iteration.
#### Scenario: Pending result remains unknown
- **WHEN** awaiting the retained signature times out or fails through I/O
- **THEN** the service retains that signature and performs no swap, burn, or notification in the iteration
#### Scenario: Pending burn succeeds
- **WHEN** the retained signature reaches `FINALIZED` with a successful outcome
- **THEN** the service performs its sole notification attempt and does no other transaction work in that iteration
#### Scenario: Pending burn fails definitively
- **WHEN** the retained signature reaches `FINALIZED` with an on-chain failure
- **THEN** the service logs its slot and complete failure details, clears it without notification, and waits until a later iteration before evaluating another burn
### Requirement: Prioritized input inspection with internal Solana translation
Unless swaps are suspended, an iteration SHALL inspect configured input entries in order until it finds the first usable candidate. For every entry it SHALL resolve the configured UUID to its canonical currency. Native SOL SHALL use `getSolanaBalance().amount()` and nine-decimal precision. Every other input SHALL use its unique CIS-resolved Solana mint; the service SHALL inspect the mint account owner to detect the original SPL Token Program or Token-2022, use that program for wallet balance lookup, and obtain precision from Solana mint metadata. A missing SPL-token account SHALL equal zero balance.
For each entry the service SHALL subtract its configured reserve and skip non-positive spendable balance. Missing or unusable balance, mint account, supported program, mint metadata, or price SHALL produce a warning and allow later configured entries to be examined. Interruption SHALL preserve the thread interrupt state and end processing rather than becoming a skipped candidate. Failure to select an input SHALL NOT prevent the later complete-EVE burn evaluation.
#### Scenario: Missing token account
- **WHEN** a configured non-SOL mint is valid but the wallet has no token account under its detected program
- **THEN** that input is treated as a zero balance and later inputs are considered
#### Scenario: Missing or unsupported mint account
- **WHEN** a configured token's mint account is absent or owned by an unsupported program
- **THEN** the service warns, skips that input, considers later priorities, and still reaches the EVE-balance step
#### Scenario: Candidate read is interrupted
- **WHEN** wallet, CIS-adjacent processing, or Solana access is interrupted while inspecting an input
- **THEN** the service preserves interruption and ends processing without treating the input as an ordinary failure
### Requirement: Fresh canonical input prices
For each non-USDC candidate, the service SHALL request the canonical `<INPUT_CURRENCY>/USDC` pair and accept only a positive price with a non-null observation timestamp no more than `maximumPriceAge` milliseconds old at the current iteration time. The stable USDC UUID SHALL instead receive an exact price of one without a ticker observation. A missing, unsupported, invalid, or stale input price SHALL be warned about using canonical currency identity, SHALL allow the next configured input to be considered, and SHALL NOT prevent later EVE burning.
#### Scenario: USDC is the input
- **WHEN** the canonical input UUID is USDC and its spendable balance is positive
- **THEN** the service uses exactly one USDC per USDC without querying the ticker for that input price
#### Scenario: Input price is unusable
- **WHEN** an input observation is missing, unsupported, non-positive, lacks a timestamp, or is older than the maximum age
- **THEN** the service does not swap that currency and continues with later configured priorities
### Requirement: Exact USDC-capped amount and per-currency reserve
For a usable candidate, the service SHALL calculate `availableForSwap = max(balance - minimumReserve, 0)`, calculate `maximumInputAmount = maximumSwapAmountInUSDC / inputPriceInUSDC`, select the lesser amount, and round downward to the input currency's supported decimal precision. It SHALL skip a result that rounds to zero and SHALL never intentionally swap more than either the spendable balance or the configured USDC-equivalent maximum through rounding.
The SOL reserve comparison SHALL use the native balance without estimating or subtracting future transaction fees. The USDC maximum SHALL limit buybacks only and SHALL NOT cap how much EVE may be burned.
#### Scenario: Price cap is lower than spendable balance
- **WHEN** a currency has five spendable units, its price is 100 USDC per unit, and the USDC maximum is one
- **THEN** no more than 0.01 unit is selected before downward precision rounding
#### Scenario: Reserve consumes the balance
- **WHEN** the current balance is equal to or below that entry's minimum reserve
- **THEN** no amount of that currency is intentionally swapped
#### Scenario: Native transaction fees
- **WHEN** native SOL is selected with a configured reserve
- **THEN** the service enforces the reserve against the observed balance only and does not estimate fees, even though later fees may reduce the final balance or cause execution to fail
### Requirement: At most one confirmed swap attempt per iteration
After selecting a positive exact amount, the service SHALL invoke the existing Jupiter exact-input operation once with the selected CIS-resolved input mint, fixed EVE output mint, selected amount, and configured slippage. Normal return SHALL be treated as already `CONFIRMED` and SHALL NOT trigger a second confirmation wait. Once invoked, no later input currency SHALL be attempted in that iteration regardless of success or failure, and the service SHALL proceed to reload the complete EVE balance whenever processing was not interrupted.
A structured definitive on-chain swap failure SHALL be logged without suspending later-lifecycle swaps. A timed-out structured outcome SHALL suspend all later swaps in that lifecycle. Because the Jupiter `IOException` and interruption contracts can represent an unknown post-submission result, either SHALL conservatively suspend later swaps. The service SHALL never automatically rebuild, re-sign, retry, or resubmit such a swap; while swaps are suspended, later iterations SHALL continue only their burn path.
#### Scenario: First swap fails definitively
- **WHEN** the first attempted input returns a definitive on-chain failure
- **THEN** no second input is attempted in that iteration, the EVE balance is still reloaded, and a later iteration may attempt a new swap
#### Scenario: Swap outcome is unknown
- **WHEN** the attempted swap times out, throws an I/O failure that permits unknown post-submission status, or is interrupted
- **THEN** no equivalent or alternative swap is attempted and all later swaps remain suspended until explicit stop/start
#### Scenario: Swap returns normally
- **WHEN** Jupiter returns a successful result whose transaction already reached `CONFIRMED`
- **THEN** the burner performs no additional confirmation wait and reloads the wallet instead of deriving its burn amount only from the returned output amount
### Requirement: Complete visible EVE balance is eligible
After the optional swap attempt, the service SHALL detect the fixed EVE mint's supported token program internally and reload the wallet's complete available EVE balance. A missing EVE mint account, unsupported program, absent wallet token account, zero balance, or negative/invalid balance SHALL cause no burn or notification in that iteration. Every positive complete balance SHALL be eligible without a minimum threshold, including EVE deposited before the iteration or visible after a failed or absent swap.
#### Scenario: Existing EVE without buyback
- **WHEN** no swap is performed but the wallet contains a positive EVE balance
- **THEN** the service evaluates that complete balance for burning
#### Scenario: EVE account is absent or empty
- **WHEN** the wallet has no EVE token account or its complete balance is zero
- **THEN** the iteration submits no burn and sends no notification
### Requirement: Fresh EVE value is required before submission
Immediately before a new burn, the service SHALL obtain the latest canonical EVE/USDT observation and require a positive price, non-null observation timestamp, and age no greater than `maximumPriceAge` milliseconds. USDT SHALL be treated as USD for notification value, calculated as the complete EVE amount multiplied by that fresh price. If the pair is unsupported or the observation is missing, invalid, or stale, the service SHALL warn, postpone the burn, send no notification, and retry only by re-evaluating state in a later scheduled iteration.
#### Scenario: Fresh EVE price exists
- **WHEN** a complete positive EVE balance and sufficiently fresh positive EVE/USDT observation are available
- **THEN** the service calculates the notification's USD value from that complete balance before submitting the burn
#### Scenario: EVE price is stale
- **WHEN** EVE is present but its observation is older than the configured age limit
- **THEN** the service leaves EVE unburned and sends no notification in that iteration
### Requirement: Single complete-balance burn submission and pending state
For a positive EVE balance with a usable price, the service SHALL call the wallet burn operation exactly once with the fixed EVE mint and complete observed balance. It SHALL NOT automatically retry, rebuild, re-sign, or resubmit within or across iterations. Immediately after a non-blank signature is returned, it SHALL retain process-local pending data containing that signature, submitted EVE amount, and its calculated notification value or complete notification text before awaiting the signature.
If burn submission fails without a usable signature and its outcome may be unknown, including an I/O or interruption path whose contract permits post-submission uncertainty, the service SHALL conservatively suspend further burn submissions for the current lifecycle. It MAY continue ordinary iteration work that does not submit another burn. Explicit stop/start SHALL reset that suspension.
#### Scenario: Burn returns a signature
- **WHEN** the wallet submits the complete observed EVE balance and returns a non-blank signature
- **THEN** pending state is retained before the service begins finalization waiting
#### Scenario: Submission outcome may be unknown without a signature
- **WHEN** burn submission fails or is interrupted without providing a usable signature and may already have reached Solana
- **THEN** the service performs no further burn submission until explicit stop/start
### Requirement: Finalized burn outcome governs completion
Every known burn signature SHALL be awaited through the Solana blockchain at `FINALIZED` with exactly the configured finalization timeout. `SUCCEEDED` SHALL authorize notification; `FAILED` SHALL log the slot and complete on-chain failure details, clear pending state, and send no notification; `TIMED_OUT` and `IOException` SHALL keep the pending signature because its result remains unknown; and `InterruptedException` SHALL preserve interruption and pending state. None of these outcomes SHALL cause automatic transaction resubmission.
#### Scenario: Burn finalizes successfully
- **WHEN** the submitted signature reaches `FINALIZED` without an on-chain error
- **THEN** the service may perform the notification attempt associated with that exact burn
#### Scenario: Burn fails on-chain
- **WHEN** the signature reaches `FINALIZED` with an on-chain error
- **THEN** the service logs its slot and complete error, clears pending state, and never announces that burn
#### Scenario: Finalized result remains unknown
- **WHEN** finalization times out or communication fails
- **THEN** the service retains the exact signature and later awaits it again without submitting another burn
### Requirement: Exactly one post-finalization notification attempt
Only after a burn reaches successful `FINALIZED` status, the service SHALL invoke the bound notification service exactly once with this structure, using the burn signature rather than any swap signature:
```text
🔥🔥🔥 We have bought back and burned <EVE_AMOUNT> EVE (Evelyn IOU tokens, value $<USD_VALUE>) to reduce the circulating supply! 🔥🔥🔥
Proof:
https://solscan.io/tx/<BURN_TRANSACTION_SIGNATURE>
```
The EVE amount SHALL use plain decimal notation without unnecessary trailing zeroes or scientific notation. The USD value SHALL have exactly two decimal places using half-up monetary rounding. The blank line before `Proof:` SHALL be preserved. Before invoking delivery, the service SHALL make the completed pending burn ineligible for another attempt. Delivery failure SHALL be logged without notification secrets and SHALL NOT retry notification or repeat the burn.
#### Scenario: Successful finalized burn is announced
- **WHEN** 10 EVE with a calculated value of 150.225 USDT reaches successful `FINALIZED` status under a burn signature
- **THEN** one message reports `10 EVE`, `$150.23`, preserves the blank line, and links to that burn signature
#### Scenario: Notification delivery fails
- **WHEN** the sole notification invocation throws
- **THEN** the service logs a non-secret failure, clears completed state, and never retries either notification or burn
@@ -0,0 +1,20 @@
## MODIFIED Requirements
### Requirement: Public exact-input swap contract
The service SHALL accept a positive human-readable exact input amount, a maximum slippage in basis points, a supported output SPL-token mint, and a distinct input representation that is either a supported SPL-token mint or native SOL expressed as the canonical SOL/WSOL mint `So11111111111111111111111111111111111111112`. It SHALL pass that canonical native-SOL representation unchanged to Jupiter as `inputMint`, preserve the existing `swap(...)` signature, and return the confirmed Solana transaction signature together with the actual human-readable input amount spent and output amount received. Callers that select native SOL SHALL remain responsible for identifying the AssetAZ SOL UUID, resolving the canonical mint through CIS, reading native wallet balance, and applying any reserve policy; the swap service SHALL NOT introduce a separate native-SOL operation.
#### Scenario: Successful exact-input swap
- **WHEN** a caller requests a valid exact-input swap from a supported legacy SPL or Token-2022 mint that Jupiter executes successfully
- **THEN** the result contains the confirmed signature and the actual spent and received amounts converted with their respective mint decimal precision
#### Scenario: Successful native SOL input swap
- **WHEN** a caller requests a valid exact-input swap using `So11111111111111111111111111111111111111112` as input and Jupiter executes it from the taker's native SOL balance
- **THEN** Jupiter receives that same canonical input mint and the service returns the confirmed signature and actual human-readable spent and received amounts through the existing result contract
#### Scenario: Existing token-program behavior is preserved
- **WHEN** a caller uses a supported legacy SPL-token or Token-2022 input
- **THEN** mint validation, decimal conversion, signing, single managed execution, and independent `CONFIRMED` handling remain unchanged
#### Scenario: Invalid caller input
- **WHEN** either mint representation is blank, both mints are equal, the amount is null or non-positive, or the maximum slippage is outside 0 through 10000 basis points
- **THEN** the service rejects the request before requesting a Jupiter order
@@ -0,0 +1,32 @@
## 1. Public contracts
- [x] 1.1 Add the `EvelynIOUBurnerService` API with complete JavaDoc for ordered `List<MoneyAmount>` configuration, iteration order, transaction uncertainty, finalization, notification, lifecycle, and process-local reset risks.
- [x] 1.2 Update `JupiterSwapService` JavaDoc to support canonical SOL/WSOL native input through the unchanged exact-input method while preserving legacy SPL and Token-2022 behavior.
## 2. Construction and identity boundaries
- [x] 2.1 Add the reference implementation's authoritative constructor with dependency, numeric, duration, reserve, duplicate, known-UUID, and EVE-input validation plus an order-preserving defensive list copy.
- [x] 2.2 Resolve canonical fixed currencies and validate exactly one non-blank CIS `solana-mint` representation for each configured non-SOL UUID without adding burner-specific input types or changing `MoneyAmount`/DeTag configuration.
## 3. Sequential lifecycle and iteration control
- [x] 3.1 Implement one immediate fixed-delay daemon worker, non-overlapping start/stop semantics, interruption preservation, bounded clean termination, and explicit stop/start reset of process-local pending and suspension state.
- [x] 3.2 Implement the safe iteration boundary and pending-burn-first short circuit so unresolved signatures are awaited before and instead of any new swap or burn work.
## 4. Prioritized buyback path
- [x] 4.1 Inspect configured UUIDs in order, canonicalize through CIS, distinguish native SOL from mint-backed tokens, detect supported token programs and precision internally, enforce reserves, and skip unusable candidates without blocking later inputs or EVE processing.
- [x] 4.2 Resolve fresh canonical input/USDC prices (with exact-one USDC), calculate a downward-rounded exact amount within the reserve and USDC cap, and attempt at most one Jupiter swap per iteration.
- [x] 4.3 Classify definitive versus unknown Jupiter outcomes, never add a second confirmation wait or transaction attempt, and suspend later-lifecycle swaps conservatively for timeout, applicable I/O, or interruption while retaining the burn path.
## 5. Burn finalization and notification
- [x] 5.1 Reload the complete EVE balance with internally detected token program, require a fresh canonical EVE/USDT price, calculate its bound USD value, submit one complete-balance burn, and retain pending data before awaiting.
- [x] 5.2 Handle `FINALIZED` success, definitive failure, timeout, I/O, and interruption without resubmission; suspend unknown signature-less burn submission outcomes for the lifecycle.
- [x] 5.3 Format the fixed proof message exactly and make at most one non-secret-logging notification attempt for each successfully finalized burn, clearing completed pending state before delivery.
## 6. Verification
- [x] 6.1 Review production JavaDoc, lifecycle/state transitions, ValueTag imports, changed-file scope, and absence of parser, autorun wiring, persistence, tests, test hooks, generated-source edits, or burner-specific input types.
- [x] 6.2 Run production compilation and assembly successfully without creating or modifying automated tests.
- [x] 6.3 Run strict OpenSpec validation and safe narrowly scoped structural/manual verification while leaving the change active and unsynchronized.