Skip to content

feat: add sell-if-deficit command to Scrypt adapter#3474

Open
TaprootFreak wants to merge 2 commits intodevelopfrom
feature/scrypt-sell-if-deficit
Open

feat: add sell-if-deficit command to Scrypt adapter#3474
TaprootFreak wants to merge 2 commits intodevelopfrom
feature/scrypt-sell-if-deficit

Conversation

@TaprootFreak
Copy link
Collaborator

Summary

  • Adds sell-if-deficit command to ScryptAdapter that conditionally sells EUR for BTC when Bitcoin on-chain (asset 113) has a balance below its rule's minimum
  • If no BTC deficit exists, falls through via onFail to the existing sell EUR → USDT action (233)
  • Only sells enough EUR to cover the BTC deficit (up to optimal), remaining EUR surplus is handled in the next cycle via USDT

DB setup required after merge

-- 1. Create new action
INSERT INTO liquidity_management_action (system, command, tag, params, onSuccessId, onFailId)
VALUES ('Scrypt', 'sell-if-deficit', 'SCRYPT EUR→BTC if deficit',
        '{"tradeAsset":"BTC","checkAssetId":113}', NULL, 233);

-- 2. Update rule 313 to use new action as redundancy start
UPDATE liquidity_management_rule
SET redundancyStartActionId = (
  SELECT id FROM liquidity_management_action
  WHERE command = 'sell-if-deficit' AND system = 'Scrypt'
)
WHERE id = 313;

Flow

EUR > 1'000 (Rule 313)
  → sell-if-deficit: check Bitcoin/BTC balance < minimal?
    → YES: sell EUR for BTC (amount = deficit to optimal)
    → NO:  onFail → Action 233 (sell EUR → USDT, as before)

Test plan

  • Verify build passes
  • Deploy to staging and create DB actions
  • Test with BTC deficit: EUR should be sold for BTC
  • Test without BTC deficit: EUR should fall through to USDT sell
  • Verify amount is capped to BTC deficit (not full EUR surplus)

Adds conditional selling of EUR for BTC on Scrypt when Bitcoin on-chain
has a deficit. Falls through to existing EUR→USDT sell if no BTC is needed.

DB setup required:
- Create action: system=Scrypt, command=sell-if-deficit,
  params={"tradeAsset":"BTC","checkAssetId":113}, onFailId=233
- Update rule 313: set redundancyStartActionId to new action
Creates the Scrypt sell-if-deficit action (EUR→BTC when Bitcoin has a
deficit, fallback to EUR→USDT via onFail=233) and updates rule 313 to
use it as the redundancy start action.
@TaprootFreak TaprootFreak marked this pull request as ready for review March 20, 2026 08:18
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.

1 participant