In this pull request, I've added a simulate_market_transaction function that allows for simulating market buys/sells off-chain (without using simulateTransaction)
Key Changes:
Added based orderbook tallying for Ladder - this was done in a trait MarketSimulator that was attached to the Ladder struct (without having to change phoenix-v1)
Added simulate_market_transaction on the SDK which is the main entrypoint and wrapper around the new MarketSimulator code. This function accounts for lots/atoms conversion and adds fees appropriately.
Added unit tests for Ladder
🔐 Security-wise: all functions are non &mut, and there are no code deletions - only additions.
Testing Considerations:
The simulate_market_transaction function in SDK currently lacks tests since it's tightly coupled with networking. We can solve this in a follow up PR by allowing the function to process raw data without network dependencies. Once we do this, we'll be in a position to implement dedicated tests for it.
How to review
Suggested way to review
Start from Ladder code changes
Ensure unit tests are correct
Review the SDK changes
Specifically, make sure the fees are adjusted for appropriately
E2E tests using Phoenix CLI:
I did some E2E tests by creating a dummy function on phoenix-cli which calls simulate_market_transaction on an assortment of prices and directions. IN specifies what we are selling and OUT is the outcome of the swap
In this pull request, I've added a
simulate_market_transaction
function that allows for simulating market buys/sells off-chain (without using simulateTransaction)Key Changes:
Ladder
- this was done in a traitMarketSimulator
that was attached to theLadder
struct (without having to changephoenix-v1
)simulate_market_transaction
on the SDK which is the main entrypoint and wrapper around the newMarketSimulator
code. This function accounts for lots/atoms conversion and adds fees appropriately.🔐 Security-wise: all functions are non
&mut
, and there are no code deletions - only additions.Testing Considerations:
simulate_market_transaction
function in SDK currently lacks tests since it's tightly coupled with networking. We can solve this in a follow up PR by allowing the function to process raw data without network dependencies. Once we do this, we'll be in a position to implement dedicated tests for it.How to review
Suggested way to review
E2E tests using Phoenix CLI:
I did some E2E tests by creating a dummy function on
phoenix-cli
which callssimulate_market_transaction
on an assortment of prices and directions.IN
specifies what we are selling andOUT
is the outcome of the swapAppreciate your feedback! and let me know what you think