(define-constant ERR-NOT-OWNER u101)
(define-constant ERR-NO-ARBI u102)

(define-constant CONTRACT-OWNER tx-sender)

(define-public (arbi-diko-alex (amountIn uint))
  (begin
    (asserts! (is-eq CONTRACT-OWNER tx-sender) (err ERR-NOT-OWNER))
    (let ((b1 (unwrap-panic (swap-stx-usda-arkadiko amountIn)))
          (b2 (unwrap-panic (swap-usda-alex-alex (* b1 u100))))
          (b3 (unwrap-panic (swap-alex-stx-alex b2))))
      (asserts! (> b3 (* amountIn u100)) (err ERR-NO-ARBI))
      (ok (list amountIn b1 b2 b3)))))
(define-public (arbi-alex-diko (amountIn uint))
  (begin
    (asserts! (is-eq CONTRACT-OWNER tx-sender) (err ERR-NOT-OWNER))
    (let ((b1 (unwrap-panic (swap-stx-alex-alex amountIn)))
          (b2 (unwrap-panic (swap-alex-usda-alex b1)))
          (b3 (unwrap-panic (swap-usda-stx-arkadiko (/ b2 u100)))))
      (asserts! (> (* b3 u100) amountIn) (err ERR-NO-ARBI))
      (ok (list amountIn b1 b2 b3)))))

(define-public (arbi-diko-alex-diko-xbtc (amountIn uint))
  (begin
    (asserts! (is-eq CONTRACT-OWNER tx-sender) (err ERR-NOT-OWNER))
    (let ((b1 (unwrap-panic (swap-stx-usda-arkadiko amountIn)))
          (b2 (unwrap-panic (swap-usda-wbtc-alex (* b1 100))))
          (b3 (unwrap-panic (swap-wbtc-stx-arkadiko (/ b2 u100)))))
      (asserts! (> b3 amountIn) (err ERR-NO-ARBI))
      (ok (list amountIn b1 b2 b3)))))
(define-public (arbi-diko-alex-diko-xbtc-batch
                (amountPerTimes (list 1000 uint)))
  (begin
    (asserts! (is-eq CONTRACT-OWNER tx-sender) (err ERR-NOT-OWNER))
    (let ((results (map arbi-diko-alex-diko-xbtc amountPerTimes))
          (results-err (filter is-err results)))
      (asserts! (is-eq 0 (len results-err)) (err ERR-NO-ARBI))
      (ok results))))

;; Stackswap
(define-public (swap-stx-usda-stackswap (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.stackswap-swap-v5k swap-x-for-y 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.wstx-token-v4a 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.liquidity-token-v5k0yl5ot8l dx u0)))) (ok (unwrap-panic (element-at r u1)))))
(define-public (swap-usda-stx-stackswap (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.stackswap-swap-v5k swap-y-for-x 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.wstx-token-v4a 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.liquidity-token-v5k0yl5ot8l dx u0)))) (ok (unwrap-panic (element-at r u1)))))
(define-public (swap-stx-diko-stackswap (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.stackswap-swap-v5k swap-x-for-y 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.wstx-token-v4a 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-token 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.liquidity-token-v5kt9nmle8c dx u0)))) (ok (unwrap-panic (element-at r u1)))))
(define-public (swap-diko-stx-stackswap (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.stackswap-swap-v5k swap-y-for-x 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.wstx-token-v4a 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-token 'SP1Z92MPDQEWZXW36VX71Q25HKF5K2EPCJ304F275.liquidity-token-v5kt9nmle8c dx u0)))) (ok (unwrap-panic (element-at r u1)))))
;; Arkadiko
(define-public (swap-stx-usda-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-x-for-y 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.wrapped-stx-token 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token dx u0)))) (ok (unwrap-panic (element-at r u1)))))
(define-public (swap-usda-stx-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-y-for-x 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.wrapped-stx-token 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token dx u0)))) (ok (unwrap-panic (element-at r u0)))))
(define-public (swap-diko-usda-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-x-for-y 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-token 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token dx u0)))) (ok (unwrap-panic (element-at r u1)))))
(define-public (swap-usda-diko-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-y-for-x 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-token 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token dx u0)))) (ok (unwrap-panic (element-at r u0)))))
(define-public (swap-stx-diko-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-x-for-y 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.wrapped-stx-token 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-token dx u0)))) (ok (unwrap-panic (element-at r u1)))))
(define-public (swap-diko-stx-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-y-for-x 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.wrapped-stx-token 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-token dx u0)))) (ok (unwrap-panic (element-at r u0)))))
(define-public (swap-stx-xbtc-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-x-for-y 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.wrapped-stx-token 'SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin dx u0)))) (ok (unwrap-panic (element-at r u1)))))
(define-public (swap-xbtc-stx-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-y-for-x 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.wrapped-stx-token 'SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin dx u0)))) (ok (unwrap-panic (element-at r u0)))))
(define-public (swap-xbtc-usda-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-x-for-y 'SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token dx u0)))) (ok (unwrap-panic (element-at r u1)))))
(define-public (swap-usda-xbtc-arkadiko (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.arkadiko-swap-v2-1 swap-y-for-x 'SP3DX3H4FEYZJZ586MFBS25ZW3HZDMEW92260R2PR.Wrapped-Bitcoin 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR.usda-token dx u0)))) (ok (unwrap-panic (element-at r u0)))))
;; Alex
(define-public (swap-stx-xbtc-alex (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.fixed-weight-pool-v1-01 swap-x-for-y 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wbtc u50000000 u50000000 dx (some u0))))) (ok (get dy r))))
(define-public (swap-xbtc-stx-alex (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.fixed-weight-pool-v1-01 swap-y-for-x 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wbtc u50000000 u50000000 dx (some u0))))) (ok (get dx r))))
(define-public (swap-stx-alex-alex (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.fixed-weight-pool-v1-01 swap-x-for-y 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.age000-governance-token u50000000 u50000000 dx (some u0))))) (ok (get dy r))))
(define-public (swap-alex-stx-alex (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.fixed-weight-pool-v1-01 swap-y-for-x 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wstx 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.age000-governance-token u50000000 u50000000 dx (some u0))))) (ok (get dx r))))
(define-public (swap-alex-usda-alex (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.simple-weight-pool-alex swap-x-for-y 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.age000-governance-token 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wusda dx (some u0))))) (ok (get dy r))))
(define-public (swap-usda-alex-alex (dx uint)) (let ((r (unwrap-panic (contract-call? 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.simple-weight-pool-alex swap-y-for-x 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.age000-governance-token 'SP3K8BC0PPEVCV7NZ6QSRWPQ2JE9E5B6N3PA0KBR9.token-wusda dx (some u0))))) (ok (get dx r))))