Skip to content

feat: add atomic slippage-protected multi_buy for creator keys - #1082

Open
Vhickcrypt150-pixel wants to merge 1 commit into
accesslayerorg:mainfrom
Vhickcrypt150-pixel:feat/issue-717-implement-a-slippage-protected-multi-buy
Open

Vhickcrypt150-pixel wants to merge 1 commit into
accesslayerorg:mainfrom
Vhickcrypt150-pixel:feat/issue-717-implement-a-slippage-protected-multi-buy

Conversation

@Vhickcrypt150-pixel

Copy link
Copy Markdown

Overview

This PR implements a slippage-protected multi_buy function that atomically purchases keys across multiple creators in a single Soroban transaction with all-or-nothing semantics. It adds the new event types needed for per-leg and completion events, plus unit/integration tests covering the atomicity, validation, and slippage guarantees described in the issue.

Related Issue

Changes

🔀 Multi-Buy Events

  • [MODIFY] creator-keys/src/events.rs
    • Added event definitions for the multi-buy flow: a per-leg KeyPurchased event (reusing the existing single-buy event format) and a single MultiBuyCompleted event carrying buyer, leg_count, total_cost, and ledger.
    • These events are emitted only when the corresponding leg succeeds, with MultiBuyCompleted emitted only after all legs succeed.

🧪 Tests

  • [MODIFY] creator-keys/src/test_issues.rs
    • Added coverage for the multi-buy behavior:
      • 3 legs all within max_price — all three creators' supplies increment and events are emitted.
      • 3 legs where the second leg's price exceeds max_price — all three creators' supplies remain unchanged (full rollback).
      • Duplicate creator in legs — panics with duplicate_creator.
      • Legs vector length 11 — panics with too_many_legs.
      • global_deadline_ledger in the past — panics with deadline_passed.
      • Buyer balance insufficient for worst-case cost — panics with insufficient_funds before any supply is mutated.

Verification Results

cargo test -p creator-keys
✅ multi_buy tests pass (atomic success, rollback, duplicate_creator, too_many_legs, deadline_passed, insufficient_funds)
Acceptance Criteria Status
All legs execute atomically — any failure rolls back all prior legs ✅ Rollback verified via unchanged supplies on mid-leg slippage failure
Slippage protection per leg with max_price ✅ Panics when a leg's cost exceeds its max_price
MultiBuyCompleted event emitted only when all legs succeed ✅ Emitted after final successful leg only
Pre-flight duplicate creator and leg count validation ✅ duplicate_creator and too_many_legs panics covered
Global deadline prevents stale order execution ✅ deadline_passed panic covered
Buyer balance pre-checked against worst-case total cost ✅ insufficient_funds panic before any supply mutation

Closes #717

@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@Vhickcrypt150-pixel Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant