Route Scrypt EUR via USDT instead of BTC#3740
Closed
TaprootFreak wants to merge 1 commit into
Closed
Conversation
Re-point Rule 313 (Scrypt/EUR redundancy) from Action 261 (Scrypt sell-if-deficit BTC) to Action 233 (Scrypt sell USDT), matching the existing CHF route (Rule 312). Remove the now unreferenced Action 261. Scrypt's BTC/EUR pricing is structurally worse than its USDT pairs (~0.6% spread vs ~0.13%). Incident on 2026-05-21 saw a 570k EUR buy_crypto routed to Scrypt BTC/EUR at +0.41% premium over Kraken VWAP because Rule 210 (Binance USDT refill) was Inactive. Routing EUR via USDT eliminates the costly BTC fill. Rule 314 (Scrypt/BTC withdraw) is retained as cleanup path for any residual BTC sitting on Scrypt. Closes #3739
9 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.
Why
On 2026-05-21, buy_crypto #123090 routed a 570'000 EUR → BTC trade to Scrypt BTC/EUR at 66'487 EUR/BTC vs. Kraken VWAP @ 13:44 UTC of 66'218 EUR/BTC — a +0.41 % premium (~2'257 EUR more than a Kraken-VWAP fill, ~1'530 EUR more than an actual Kraken trade incl. fees). The fallback chain landed on Scrypt because Binance had insufficient BTC (Rule 192) and the Binance USDT refill (Rule 210) is
Inactive.Scrypt's BTC/EUR pricing is structurally worse than its USDT pairs (~0.6 % spread vs ~0.13 % on 6-month history). The USDT route already exists end-to-end for CHF (Rule 312 → Action 233 → Rule 315 → Binance).
Closes #3739
What
New TypeORM migration
migration/1779381590531-RouteScryptEurViaUsdt.js:up():UPDATE liquidity_management_rule SET redundancyStartActionId = 233 WHERE id = 313— re-points Scrypt/EUR redundancy at the existingScrypt sell USDTaction (same one Rule 312 / CHF already uses).DELETE FROM liquidity_management_action WHERE id = 261 AND system = 'Scrypt' AND command = 'sell-if-deficit'— removes the now-unreferenced action.down(): faithful inverse of1774100000000-AddScryptSellIfDeficitAction.js— re-inserts Action 261 (withIDENTITY_INSERTso the id is preserved, important because Rule 313'sredundancyStartActionIdreferences it by id) and re-points Rule 313 back to 261.Verified before merge (per issue):
SELECT id FROM liquidity_management_action WHERE onSuccessId=261 OR onFailId=261returns[]. Rule 314 (Scrypt/BTC withdraw) and Action 262 are intentionally retained as cleanup path for any residual BTC on Scrypt.Deploy prerequisite (out of scope for this PR)
Per the issue, Rule 210 (Binance/USDT refill) must be
Activebefore this migration deploys, otherwise large BTC buys will pile up onMissingLiquidity. Verify with:Acceptance criteria
migration/with timestamp >1775745823000(1779381590531)up()reroutes Rule 313 to Action 233 and deletes Action 261down()restores the previous state (re-inserts Action 261 + re-points Rule 313 → 261)developonDFXswiss/apiVerification queries (post-deploy)