Skip to content

Route Scrypt EUR via USDT instead of BTC#3740

Closed
TaprootFreak wants to merge 1 commit into
developfrom
feat/scrypt-eur-via-usdt-3739
Closed

Route Scrypt EUR via USDT instead of BTC#3740
TaprootFreak wants to merge 1 commit into
developfrom
feat/scrypt-eur-via-usdt-3739

Conversation

@TaprootFreak
Copy link
Copy Markdown
Collaborator

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():
    1. UPDATE liquidity_management_rule SET redundancyStartActionId = 233 WHERE id = 313 — re-points Scrypt/EUR redundancy at the existing Scrypt sell USDT action (same one Rule 312 / CHF already uses).
    2. DELETE FROM liquidity_management_action WHERE id = 261 AND system = 'Scrypt' AND command = 'sell-if-deficit' — removes the now-unreferenced action.
  • down(): faithful inverse of 1774100000000-AddScryptSellIfDeficitAction.js — re-inserts Action 261 (with IDENTITY_INSERT so the id is preserved, important because Rule 313's redundancyStartActionId references 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=261 returns []. 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 Active before this migration deploys, otherwise large BTC buys will pile up on MissingLiquidity. Verify with:

SELECT id, status, [minimal], optimal FROM liquidity_management_rule WHERE id = 210;

Acceptance criteria

  • New migration committed in migration/ with timestamp > 1775745823000 (1779381590531)
  • up() reroutes Rule 313 to Action 233 and deletes Action 261
  • down() restores the previous state (re-inserts Action 261 + re-points Rule 313 → 261)
  • Lint, format:check, build green locally
  • Verification queries produce expected results in DEV (post-deploy)
  • Draft PR opened against develop on DFXswiss/api
  • Linked back to Stop buying BTC on Scrypt — route EUR via USDT instead #3739

Verification queries (post-deploy)

-- Rule 313 now points at 233
SELECT id, redundancyStartActionId FROM liquidity_management_rule WHERE id = 313;
-- Expected: 233

-- Action 261 is gone
SELECT id FROM liquidity_management_action WHERE id = 261;
-- Expected: [] empty

-- No new Scrypt BTC/EUR trades after deploy
SELECT TOP 5 id, created, symbol, cost, [order]
FROM exchange_tx
WHERE exchange = 'Scrypt' AND symbol = 'BTC/EUR' AND created > '<deploy-date>'
ORDER BY id DESC;
-- Expected: [] empty

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
@TaprootFreak TaprootFreak marked this pull request as ready for review May 21, 2026 16:50
@TaprootFreak TaprootFreak requested a review from davidleomay as a code owner May 21, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop buying BTC on Scrypt — route EUR via USDT instead

1 participant