Conversation
|
@greptile review the PR according to the CONTRIBUTION.md |
Greptile OverviewGreptile SummaryThis PR adds a new “Active Options Positions” section to the CLI Main issue: the new maker-position calculation attempts to account for “option tokens in offers” by querying Confidence Score: 2/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CLI as cli-client
participant Wallet
participant Store as coin_store
participant PF as price_fetcher
User->>CLI: positions
CLI->>Wallet: open wallet
CLI->>PF: fetch BTC/USD
PF-->>CLI: btc_price (optional)
CLI->>Wallet: derive user script_pubkey
CLI->>Store: query token-tagged UTXOs (option)
Store-->>CLI: option_tokens
CLI->>Store: query token-tagged UTXOs (grantor)
Store-->>CLI: grantor_tokens
CLI->>CLI: build active positions
par check collateral per contract
CLI->>Store: query contract UTXOs (options contract + collateral asset)
Store-->>CLI: has_collateral map
and sum offer-held amounts
CLI->>Store: list offer contracts
Store-->>CLI: offer contracts
CLI->>Store: query offer UTXOs (offer contract + collateral asset)
Store-->>CLI: totals by asset
end
CLI-->>User: render active options table
|
| /// Query all option tokens locked in option-offer contracts for multiple asset IDs | ||
| async fn query_all_option_tokens_in_offers( | ||
| wallet: &crate::wallet::Wallet, |
There was a problem hiding this comment.
Incorrect offer token accounting
query_all_option_tokens_in_offers is described/used as summing “option tokens locked in option-offer contracts”, but option-offer contracts lock collateral/premium (and later settlement), not option tokens. In this function you filter and sum using OptionOfferArguments::get_collateral_asset_id() and UtxoFilter::asset_id(collateral_id) (positions.rs:237-248), so option_tokens_in_offers is actually collateral-in-offers keyed by the collateral asset id. Downstream, build_maker_positions treats that map as “unsold option tokens” (option_tokens_in_offers.get(&option_asset_id) at positions.rs:371-372), so Maker “sold of total” will be wrong (typically under/over-counting depending on assets).
Also appears at positions.rs:213-274 and positions.rs:367-383.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/cli-client/src/cli/positions.rs
Line: 213:215
Comment:
**Incorrect offer token accounting**
`query_all_option_tokens_in_offers` is described/used as summing “option tokens locked in option-offer contracts”, but option-offer contracts lock *collateral/premium* (and later settlement), not option tokens. In this function you filter and sum using `OptionOfferArguments::get_collateral_asset_id()` and `UtxoFilter::asset_id(collateral_id)` (positions.rs:237-248), so `option_tokens_in_offers` is actually *collateral-in-offers* keyed by the collateral asset id. Downstream, `build_maker_positions` treats that map as “unsold option tokens” (`option_tokens_in_offers.get(&option_asset_id)` at positions.rs:371-372), so Maker “sold of total” will be wrong (typically under/over-counting depending on assets).
Also appears at positions.rs:213-274 and positions.rs:367-383.
How can I resolve this? If you propose a fix, please make it concise.
Implement a basic feature to display users’ active options positions.
Resolve: #41 (comment)