;; Fee Maximizer optimizer — LLM seed
;;
;; Philosophy: "every trade pays us."
;; Concentrate liquidity in high-traffic price ranges by keeping anchor share
;; high and anchor width wide enough to capture price movement volatility.
;;
;; Inputs on DYADIC stack (slot 0 on top, slot 7 at bottom):
;;   [0] percentageStaked      (0 to 1e18, where 1e18 = 100%)
;;   [1] averageTaxRate        (0 to 1e18)
;;   [2..7] reserved / future indicators
;;
;; Outputs (bottom-to-top push order → top = ci):
;;   discoveryDepth  (bottom)  — DD: aggressive upside discovery
;;   anchorWidth               — AW: wide coverage of price movement
;;   anchorShare               — AS: most ETH in the fee-earning zone
;;   ci              (top)     — always 0 (no capital inefficiency)
;;
;; Strategy matrix (staking threshold: 60%, tax threshold: 10%):
;;
;;                  | tax < 10%                 | tax >= 10%
;;   ---------------+---------------------------+--------------------------
;;   staked < 60%   | CI=0 AS=0.70 AW=60 DD=0.50 | CI=0 AS=0.80 AW=80 DD=0.60
;;   staked >= 60%  | CI=0 AS=0.90 AW=40 DD=0.80 | CI=0 AS=0.95 AW=50 DD=0.90
;;
;; Rationale:
;;   - High staking → bullish sentiment → push discovery depth up
;;   - High tax → more staking/trade activity → widen anchor to capture volume
;;   - Anchor share always > 0.70 so capital stays in the fee-earning zone

(
  ;; Step 1: Bind slot 0 (top) → PERCENTAGESTAKED, slot 1 → TAXRATE.
  PERCENTAGESTAKED DYADIC.DEFINE
  ;; Stack: [slot7(bot), slot6, slot5, slot4, slot3, slot2, slot1(top)]
  TAXRATE DYADIC.DEFINE
  ;; Stack: [slot7(bot), slot6, slot5, slot4, slot3, slot2(top)]

  ;; Step 2: Discard unused inputs (slots 2-7) — 6 pops.
  DYADIC.POP
  DYADIC.POP
  DYADIC.POP
  DYADIC.POP
  DYADIC.POP
  DYADIC.POP
  ;; Stack: []

  ;; Step 3: Compute stakedPct = percentageStaked * 100 / 1e18  (integer 0..100)
  PERCENTAGESTAKED
  100 DYADIC.*
  1000000000000000000 DYADIC./
  ;; Stack: [stakedPct]
  STAKED DYADIC.DEFINE
  ;; Stack: []

  ;; Step 4: Branch on staking level — >= 60 is "bullish".
  STAKED 60 DYADIC.>=
  ;; bool_stack: [staking_bullish]

  EXEC.IF

  ;; TRUE branch: High staking (>= 60%) — bullish sentiment.
  ;; Shift positions upward: maximum discovery depth, high anchor share.
  (
    ;; Sub-branch: is tax rate high (>= 10% of 1e18)?
    TAXRATE 100000000000000000 DYADIC.>=
    ;; bool_stack: [tax_high]

    EXEC.IF

    ;; TRUE: High staking + High tax
    ;; → Maximum fee capture: wide anchor to absorb volume, max share & discovery.
    ;; CI=0, AS=0.95e18, AW=50, DD=0.90e18
    (
      900000000000000000
      50
      950000000000000000
      0
    )

    ;; FALSE: High staking + Low tax
    ;; → Bullish upside focus: tighter anchor, high share, strong discovery.
    ;; CI=0, AS=0.90e18, AW=40, DD=0.80e18
    (
      800000000000000000
      40
      900000000000000000
      0
    )
  )

  ;; FALSE branch: Low staking (<= 60%) — neutral/bearish sentiment.
  ;; Still fee-aggressive: keep wide positions and moderate share.
  (
    ;; Sub-branch: is tax rate high (>= 10% of 1e18)?
    TAXRATE 100000000000000000 DYADIC.>=
    ;; bool_stack: [tax_high]

    EXEC.IF

    ;; TRUE: Low staking + High tax
    ;; → High volume with caution: widen anchor to capture swap fees.
    ;; CI=0, AS=0.80e18, AW=80, DD=0.60e18
    (
      600000000000000000
      80
      800000000000000000
      0
    )

    ;; FALSE: Low staking + Low tax
    ;; → Conservative fee base: broad coverage, steady share.
    ;; CI=0, AS=0.70e18, AW=60, DD=0.50e18
    (
      500000000000000000
      60
      700000000000000000
      0
    )
  )
)
