feat(models): add SwapPayment model and SwapStatus enum (#41) - #46
Conversation
…l#41) Add src/shade/models/swap.py implementing SwapPayment and SwapStatus for Shade's cross-asset payment routing capability. Changes: - New SwapStatus(str, Enum) with 5 states: pending, swapping, completed, failed, slippage_exceeded - New SwapPayment class with all required fields: id, pay_in_token, settle_out_token, amount_in, amount_out (Optional[Decimal]), routing_path (list[str]), slippage_tolerance (float), status (SwapStatus), stellar_tx_hash (Optional[str]), created_at (Optional[datetime]) - SwapPayment.from_dict() populates all fields including routing_path - slippage_tolerance validated strictly in the open interval (0, 1); raises ValueError otherwise - SwapPayment.to_dict() for serialisation round-trips - New src/shade/models/__init__.py package init - SwapPayment and SwapStatus surfaced in top-level shade namespace - tests/test_swap_payment.py covering all acceptance criteria Closes ShadeProtocol#41
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a ChangesSwapPayment model
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/shade/models/swap.py`:
- Around line 156-169: Update Swap.to_dict() so the "routing_path" serialized
value is a copy of self.routing_path rather than the original mutable list,
while preserving the existing serialized contents and behavior for other fields.
- Around line 74-92: Update the direct constructor around the status assignment
to enforce the SwapStatus contract: normalize valid string inputs to SwapStatus
or reject non-enum values before assigning self.status. Ensure self.status is
always a SwapStatus instance so to_dict() can safely access .value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0157ab4e-496c-4a11-910b-3569f6711cac
📒 Files selected for processing (4)
src/shade/__init__.pysrc/shade/models/__init__.pysrc/shade/models/swap.pytests/test_swap_payment.py
- Normalize status to SwapStatus enum in __init__ so the invariant holds even when a raw string is passed directly to the constructor; invalid strings raise ValueError via SwapStatus() - Return list(self.routing_path) from to_dict() to prevent callers from mutating the model's internal routing path list - Add tests: raw-string status coercion, to_dict routing_path isolation
|
GM @ALIPHATICHYD |
|
GM @codebestia |
codebestia
left a comment
There was a problem hiding this comment.
LGTM!
Nice implementation.
Thank you for your contribution.
Summary
Closes #41
Implements the
SwapPaymentmodel andSwapStatusenum for Shade's cross-asset payment routing, as described in issue #41.Changes
src/shade/models/swap.py(new)SwapStatus(str, Enum)— five lifecycle states:pending,swapping,completed,failed,slippage_exceededSwapPayment— all required fields:id: str,pay_in_token: str,settle_out_token: stramount_in: Decimal,amount_out: Optional[Decimal]routing_path: list[str]slippage_tolerance: float— validated strictly in(0, 1); raisesValueErrorotherwisestatus: SwapStatus,stellar_tx_hash: Optional[str],created_at: Optional[datetime]SwapPayment.from_dict(data)— deserialises all fields including the routing path listSwapPayment.to_dict()— serialises back to a plaindict(round-trip safe)src/shade/models/__init__.py(new)SwapPaymentandSwapStatussrc/shade/__init__.py(modified)SwapPaymentandSwapStatusin the top-levelshadenamespacetests/test_swap_payment.py(new)Acceptance Criteria
SwapPayment.from_dict(...)populates all fields including routing path listslippage_toleranceoutside(0, 1)raisesValueErrorstatusis aSwapStatusenumSummary by CodeRabbit
New Features
Bug Fixes
Tests