fix: execution fee refund, limit order boundary tests, weighted avg entry price, write-ordering docs#349
Merged
abayomicornelius merged 1 commit intoJun 27, 2026
Conversation
…hted avg entry price, write-ordering docs Closes SO4-Markets#258 Closes SO4-Markets#259 Closes SO4-Markets#260 Closes SO4-Markets#261
|
@kulayddon 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! 🚀 |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
exchange_router: cancel_order does not refund execution fee to user #258
exchange_router/order_handler:cancel_ordernow refunds the fullexecution_feeto the user in addition to collateral. Previously, the fee was silently retained in the order vault even though no keeper performed any work. A matching test (cancel_order_refunds_execution_fee_to_user) verifies both collateral and fee are returned and the vault balance reaches zero.order_handler: limit order incorrectly triggers when price equals trigger_price exactly #259
order_handler: all limit/stop trigger conditions already use inclusive bounds (<=/>=), soLimitIncreasewithoracle_price == trigger_pricealways executed. Added boundary tests for all four relevant order-type/direction combinations (limit_increase_at_trigger_price_executes,limit_decrease_long_at_trigger_price_executes,limit_decrease_short_at_trigger_price_executes,stop_loss_long_at_trigger_price_executes) to lock in this behaviour and prevent regressions.reader: get_position_info returns wrong entry_price after multiple position increases #260
reader/libs/types: addedavg_entry_price: i128toPositionInfo. Bothget_position_infoandget_position_info_by_keynow compute the weighted average entry price assize_in_usd / size_in_tokens × TOKEN_PRECISION. Also fixed a pre-existing compile error:IncreasePositionParamswas missing thefor_positive_impactfield added in issue feat: maker/taker fee tiers — lower fees for limit orders, higher for market orders #284. A test (position_avg_entry_price_is_weighted_average_after_two_increases) opens a position twice at different prices and asserts the implied average lies between the two prices.data_store: no write guard — two handlers writing same key in one tx produce inconsistent state #261
data_store: added a doc comment onapply_delta_to_u128explaining that Soroban's sequential execution model within a transaction makes a separate version/nonce guard unnecessary. True concurrent writes across transactions are prevented by Soroban's footprint model. A test (sequential_pool_amount_writes_both_accumulate) demonstrates that two consecutiveapply_delta_to_u128calls accumulate correctly.Test plan
cancel_order_refunds_execution_fee_to_user— collateral + fee returned, vault emptylimit_increase_at_trigger_price_executes— boundary execution for LimitIncreaselimit_decrease_long_at_trigger_price_executes— boundary execution for long take-profitlimit_decrease_short_at_trigger_price_executes— boundary execution for short take-profitstop_loss_long_at_trigger_price_executes— boundary execution for long stop-lossposition_avg_entry_price_is_weighted_average_after_two_increases— weighted avg correctnesssequential_pool_amount_writes_both_accumulate— sequential write orderingCloses #258
Closes #259
Closes #260
Closes #261