Skip to content

feat(twap-monitor): build OrderCreation and submit via cow-api (BLEU-828)#5

Open
brunota20 wants to merge 2 commits into
feat/twap-monitor-polling-bleu-827from
feat/twap-monitor-submit-bleu-828
Open

feat(twap-monitor): build OrderCreation and submit via cow-api (BLEU-828)#5
brunota20 wants to merge 2 commits into
feat/twap-monitor-polling-bleu-827from
feat/twap-monitor-submit-bleu-828

Conversation

@brunota20

Copy link
Copy Markdown
Collaborator

Summary

On `PollOutcome::Ready { order, signature }`:

  1. `gpv2_to_order_data` maps the on-chain `bytes32` markers (`kind`, `sellTokenBalance`, `buyTokenBalance`) onto cowprotocol's typed enums via `from_contract_bytes`. Unknown markers skip the watch with a Warn log rather than ship a malformed body.
  2. Wrap signature as `Signature::Eip1271` — ComposableCoW returns the orderbook wire form (raw verifier bytes; the orderbook prepends `from` before settlement).
  3. `OrderCreation::from_signed_order_data` assembles the body. `from` is the watch owner; `app_data` is hard-coded to `EMPTY_APP_DATA_JSON`.
  4. `serde_json::to_vec` → `cow_api::submit_order(chain_id, body)`.
  5. On success, persist `submitted:{uid}` in local-store as an empty marker (presence is the receipt; suppresses double submits).

Scope notes

  • `app_data` is fixed to `EMPTY_APP_DATA_JSON`. Orders that pin a real IPFS document fail `from_signed_order_data` (digest mismatch) and are skipped — resolving the document is a future concern.
  • Submission errors are logged with status. BLEU-829 wires `OrderPostError::retry_hint` into this site so the backoff / drop decision becomes data-driven.
  • `from` = watch owner (emitter of `ConditionalOrderCreated`); orderbook prepends it to the EIP-1271 blob during settlement.

Stacks on #4 (BLEU-827 polling).

Linear: BLEU-828. Ref ADR-0006 (modules build orders themselves).

Test plan

  • `cargo test -p twap-monitor` — 24 host tests (3 BLEU-826 + 14 BLEU-827 + 7 BLEU-828: marker mapping incl. zero-receiver normalisation, unknown kind / balance rejection; build_order_creation happy path with serde round-trip; rejection of non-empty app_data and `from = ZERO`).
  • `cargo clippy --target wasm32-wasip2 -p twap-monitor -- -Dwarnings`.
  • `cargo clippy -p twap-monitor --tests -- -Dwarnings`.
  • `cargo build --target wasm32-wasip2 --release -p twap-monitor` — 273 KB .wasm (was 215 KB; serde for OrderCreation + OrderData/Signature/SigningScheme + serde_with).
  • End-to-end submit against Sepolia — pending BLEU-834 module.toml + a live conditional order.

…828)

On `PollOutcome::Ready { order, signature }`, convert the
`GPv2OrderData` to the typed `OrderData` (maps the on-chain
bytes32 markers `kind` / `sellTokenBalance` / `buyTokenBalance`
via cowprotocol's `from_contract_bytes`), wrap the signature as
`Signature::Eip1271` (ComposableCoW returns the orderbook wire
form: raw verifier bytes, the orderbook re-prepends `from`
before settlement), and feed everything through
`OrderCreation::from_signed_order_data`. The body is then
serde-encoded and pushed to `cow_api::submit_order(chain_id,
body)`.

On success, persist `submitted:{uid}` in local-store as an
empty marker — presence of the key is the receipt; BLEU-830
may later attach metadata but the bare flag is enough to
suppress double submits.

Scope notes (deliberately deferred):

- `app_data` is hard-coded to `EMPTY_APP_DATA_JSON`.
  Conditional orders that pin a real document on IPFS get
  rejected by `from_signed_order_data` (digest mismatch) and
  skipped with a Warn log instead of submitting a corrupt body.
  Resolving the document is its own concern.
- Submission errors are logged. BLEU-829 wires
  `OrderPostError::retry_hint` into this site so the backoff /
  drop decision is data-driven.
- `from` is set to the watch owner (the address that emitted
  `ConditionalOrderCreated`). The orderbook prepends this to
  the EIP-1271 blob during settlement.

Tests: 7 new (gpv2_to_order_data marker mapping incl. zero-
receiver normalisation, unknown kind / balance marker
rejection; build_order_creation happy path with serde round-
trip; rejection of non-empty app_data and `from = ZERO`).
Total 24 host tests. `.wasm` 273 KB (was 215 KB; serde for
OrderCreation, the OrderData/Signature/SigningScheme modules,
and serde_with's runtime ride along).

Linear: BLEU-828. Ref ADR-0006 (modules build orders
themselves).
@linear-code

linear-code Bot commented Jun 15, 2026

Copy link
Copy Markdown

BLEU-828

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.

1 participant