contract_id
stringlengths
35
71
source_url
stringlengths
76
112
content
stringlengths
787
93.4k
SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01
https://api.hiro.so/extended/v1/contract/SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01
(use-trait ft-trait .trait-sip-010.sip-010-trait)\n(define-constant ERR-NOT-AUTHORIZED (err u1000))\n(define-constant ERR-POOL-ALREADY-EXISTS (err u2000))\n(define-constant ERR-INVALID-POOL (err u2001))\n(define-constant ERR-BLOCKLISTED (err u2002))\n(define-constant ERR-INVALID-LIQUIDITY (err u2003))\n(define-constant ERR-PERCENT-GREATER-THAN-ONE (err u2004))\n(define-constant ERR-EXCEEDS-MAX-SLIPPAGE (err u2005))\n(define-constant ERR-ORACLE-NOT-ENABLED (err u2006))\n(define-constant ERR-ORACLE-AVERAGE-BIGGER-THAN-ONE (err u2007))\n(define-constant ERR-PAUSED (err u2008))\n(define-constant ERR-SWITCH-THRESHOLD-BIGGER-THAN-ONE (err u2009))\n(define-constant ERR-NO-LIQUIDITY (err u2010))\n(define-constant ERR-MAX-IN-RATIO (err u2011))\n(define-constant ERR-MAX-OUT-RATIO (err u2012))\n(define-data-var paused bool true)\n(define-read-only (is-dao-or-extension)\n (ok (asserts! (or (is-eq tx-sender .executor-dao) (contract-call? .executor-dao is-extension contract-caller)) ERR-NOT-AUTHORIZED)))\n(define-read-only (is-blocklisted-or-default (sender principal))\n (contract-call? .amm-registry-v2-01 is-blocklisted-or-default sender))\n(define-read-only (get-switch-threshold)\n (contract-call? .amm-registry-v2-01 get-switch-threshold))\n(define-read-only (get-pool-details-by-id (pool-id uint))\n (contract-call? .amm-registry-v2-01 get-pool-details-by-id pool-id))\n(define-read-only (get-pool-details (token-x principal) (token-y principal) (factor uint))\n (contract-call? .amm-registry-v2-01 get-pool-details token-x token-y factor))\n(define-read-only (get-pool-exists (token-x principal) (token-y principal) (factor uint))\n (contract-call? .amm-registry-v2-01 get-pool-exists token-x token-y factor))\n(define-read-only (is-paused)\n (var-get paused))\n(define-read-only (get-balances (token-x principal) (token-y principal) (factor uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (ok {balance-x: (get balance-x pool), balance-y: (get balance-y pool)})))\n(define-read-only (get-start-block (token-x principal) (token-y principal) (factor uint))\n (ok (get start-block (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-end-block (token-x principal) (token-y principal) (factor uint))\n (ok (get end-block (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-max-in-ratio (token-x principal) (token-y principal) (factor uint))\n (ok (get max-in-ratio (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-max-out-ratio (token-x principal) (token-y principal) (factor uint))\n (ok (get max-out-ratio (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (check-pool-status (token-x principal) (token-y principal) (factor uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (ok (asserts! (and (>= block-height (get start-block pool)) (<= block-height (get end-block pool))) ERR-NOT-AUTHORIZED))))\n(define-read-only (get-oracle-enabled (token-x principal) (token-y principal) (factor uint))\n (ok (get oracle-enabled (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-oracle-average (token-x principal) (token-y principal) (factor uint))\n (ok (get oracle-average (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-oracle-resilient (token-x principal) (token-y principal) (factor uint))\n (let (\n (exists (is-some (get-pool-exists token-x token-y factor)))\n (pool (if exists (try! (get-pool-details token-x token-y factor)) (try! (get-pool-details token-y token-x factor))))\n (oracle-instant (try! (get-oracle-instant token-x token-y factor))))\n (asserts! (get oracle-enabled pool) ERR-ORACLE-NOT-ENABLED)\n (ok (+ (mul-down (- ONE_8 (get oracle-average pool)) oracle-instant) \n (mul-down (get oracle-average pool) (if (is-eq (get oracle-resilient pool) u0) oracle-instant (get oracle-resilient pool)))))))\n(define-read-only (get-oracle-instant (token-x principal) (token-y principal) (factor uint))\n (let (\n (exists (is-some (get-pool-exists token-x token-y factor)))\n (pool (if exists (try! (get-pool-details token-x token-y factor)) (try! (get-pool-details token-y token-x factor))))\n )\n (asserts! (get oracle-enabled pool) ERR-ORACLE-NOT-ENABLED)\n (if exists\n (ok (get-price-internal (get balance-x pool) (get balance-y pool) factor))\n (ok (get-price-internal (get balance-y pool) (get balance-x pool) factor)))))\n(define-read-only (get-price (token-x principal) (token-y principal) (factor uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (ok (get-price-internal (get balance-x pool) (get balance-y pool) factor))))\n(define-read-only (get-threshold-x (token-x principal) (token-y principal) (factor uint))\n (ok (get threshold-x (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-threshold-y (token-x principal) (token-y principal) (factor uint))\n (ok (get threshold-y (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-fee-rebate (token-x principal) (token-y principal) (factor uint))\n (ok (get fee-rebate (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-fee-rate-x (token-x principal) (token-y principal) (factor uint))\n (ok (get fee-rate-x (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-fee-rate-y (token-x principal) (token-y principal) (factor uint))\n (ok (get fee-rate-y (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-pool-owner (token-x principal) (token-y principal) (factor uint))\n (ok (get pool-owner (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-y-given-x (token-x principal) (token-y principal) (factor uint) (dx uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (threshold (get threshold-x pool))\n (dy (if (>= dx threshold)\n (get-y-given-x-internal (get balance-x pool) (get balance-y pool) factor dx)\n (div-down (mul-down dx (get-y-given-x-internal (get balance-x pool) (get balance-y pool) factor threshold)) threshold)))\n )\n (asserts! (< dx (mul-down (get balance-x pool) (get max-in-ratio pool))) ERR-MAX-IN-RATIO)\n (asserts! (< dy (mul-down (get balance-y pool) (get max-out-ratio pool))) ERR-MAX-OUT-RATIO)\n (ok dy)))\n(define-read-only (get-x-given-y (token-x principal) (token-y principal) (factor uint) (dy uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (threshold (get threshold-y pool))\n (dx (if (>= dy threshold)\n (get-x-given-y-internal (get balance-x pool) (get balance-y pool) factor dy)\n (div-down (mul-down dy (get-x-given-y-internal (get balance-x pool) (get balance-y pool) factor threshold)) threshold)))\n )\n (asserts! (< dy (mul-down (get balance-y pool) (get max-in-ratio pool))) ERR-MAX-IN-RATIO)\n (asserts! (< dx (mul-down (get balance-x pool) (get max-out-ratio pool))) ERR-MAX-OUT-RATIO)\n (ok dx)))\n(define-read-only (get-y-in-given-x-out (token-x principal) (token-y principal) (factor uint) (dx uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (threshold (get threshold-x pool))\n (dy (if (>= dx threshold)\n (get-y-in-given-x-out-internal (get balance-x pool) (get balance-y pool) factor dx)\n (div-down (mul-down dx (get-y-in-given-x-out-internal (get balance-x pool) (get balance-y pool) factor threshold)) threshold)))\n )\n (asserts! (< dy (mul-down (get balance-y pool) (get max-in-ratio pool))) ERR-MAX-IN-RATIO)\n (asserts! (< dx (mul-down (get balance-x pool) (get max-out-ratio pool))) ERR-MAX-OUT-RATIO)\n (ok dy)))\n(define-read-only (get-x-in-given-y-out (token-x principal) (token-y principal) (factor uint) (dy uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (threshold (get threshold-y pool))\n (dx (if (>= dy threshold)\n (get-x-in-given-y-out-internal (get balance-x pool) (get balance-y pool) factor dy)\n (div-down (mul-down dy (get-x-in-given-y-out-internal (get balance-x pool) (get balance-y pool) factor threshold)) threshold)))\n )\n (asserts! (< dx (mul-down (get balance-x pool) (get max-in-ratio pool))) ERR-MAX-IN-RATIO)\n (asserts! (< dy (mul-down (get balance-y pool) (get max-out-ratio pool))) ERR-MAX-OUT-RATIO)\n (ok dx)))\n(define-read-only (get-x-given-price (token-x principal) (token-y principal) (factor uint) (price uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (asserts! (< price (get-price-internal (get balance-x pool) (get balance-y pool) factor)) ERR-NO-LIQUIDITY)\n (ok (get-x-given-price-internal (get balance-x pool) (get balance-y pool) factor price))))\n(define-read-only (get-y-given-price (token-x principal) (token-y principal) (factor uint) (price uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (asserts! (> price (get-price-internal (get balance-x pool) (get balance-y pool) factor)) ERR-NO-LIQUIDITY)\n (ok (get-y-given-price-internal (get balance-x pool) (get balance-y pool) factor price))))\n(define-read-only (get-token-given-position (token-x principal) (token-y principal) (factor uint) (dx uint) (max-dy (optional uint)))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (dy (default-to u340282366920938463463374607431768211455 max-dy))\n )\n (asserts! (and (> dx u0) (> dy u0)) ERR-NO-LIQUIDITY)\n (ok (get-token-given-position-internal (get balance-x pool) (get balance-y pool) factor (get total-supply pool) dx dy))))\n(define-read-only (get-position-given-mint (token-x principal) (token-y principal) (factor uint) (token-amount uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (asserts! (> (get total-supply pool) u0) ERR-NO-LIQUIDITY)\n (ok (get-position-given-mint-internal (get balance-x pool) (get balance-y pool) factor (get total-supply pool) token-amount))))\n(define-read-only (get-position-given-burn (token-x principal) (token-y principal) (factor uint) (token-amount uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (asserts! (> (get total-supply pool) u0) ERR-NO-LIQUIDITY)\n (ok (get-position-given-burn-internal (get balance-x pool) (get balance-y pool) factor (get total-supply pool) token-amount))))\n(define-read-only (get-helper (token-x principal) (token-y principal) (factor uint) (dx uint))\n (if (is-some (get-pool-exists token-x token-y factor))\n (get-y-given-x token-x token-y factor dx)\n (get-x-given-y token-y token-x factor dx)))\n(define-read-only (get-helper-a (token-x principal) (token-y principal) (token-z principal) (factor-x uint) (factor-y uint) (dx uint))\n (get-helper token-y token-z factor-y (try! (get-helper token-x token-y factor-x dx))))\n(define-read-only (get-helper-b\n (token-x principal) (token-y principal) (token-z principal) (token-w principal)\n (factor-x uint) (factor-y uint) (factor-z uint)\n (dx uint))\n (get-helper token-z token-w factor-z (try! (get-helper-a token-x token-y token-z factor-x factor-y dx))))\n(define-read-only (get-helper-c\n (token-x principal) (token-y principal) (token-z principal) (token-w principal) (token-v principal)\n (factor-x uint) (factor-y uint) (factor-z uint) (factor-w uint)\n (dx uint))\n (get-helper-a token-z token-w token-v factor-z factor-w (try! (get-helper-a token-x token-y token-z factor-x factor-y dx))))\n(define-read-only (fee-helper (token-x principal) (token-y principal) (factor uint))\n (if (is-some (get-pool-exists token-x token-y factor))\n (get-fee-rate-x token-x token-y factor)\n (get-fee-rate-y token-y token-x factor)))\n(define-read-only (fee-helper-a (token-x principal) (token-y principal) (token-z principal) (factor-x uint) (factor-y uint))\n (ok (+ (try! (fee-helper token-x token-y factor-x)) (try! (fee-helper token-y token-z factor-y)))))\n(define-read-only (fee-helper-b\n (token-x principal) (token-y principal) (token-z principal) (token-w principal)\n (factor-x uint) (factor-y uint) (factor-z uint))\n (ok (+ (try! (fee-helper-a token-x token-y token-z factor-x factor-y)) (try! (fee-helper token-z token-w factor-z)))))\n(define-read-only (fee-helper-c\n (token-x principal) (token-y principal) (token-z principal) (token-w principal) (token-v principal)\n (factor-x uint) (factor-y uint) (factor-z uint) (factor-w uint))\n (ok (+ (try! (fee-helper-a token-x token-y token-z factor-x factor-y)) (try! (fee-helper-a token-z token-w token-v factor-z factor-w)))))\n(define-read-only (get-invariant (balance-x uint) (balance-y uint) (t uint))\n (if (>= t (get-switch-threshold))\n (+ (mul-down (- ONE_8 t) (+ balance-x balance-y)) (mul-down t (mul-down balance-x balance-y)))\n (+ (pow-down balance-x (- ONE_8 t)) (pow-down balance-y (- ONE_8 t)))))\n(define-read-only (get-max-ratio-limit)\n (contract-call? .amm-registry-v2-01 get-max-ratio-limit))\n(define-public (pause (new-paused bool))\n (begin\n (try! (is-dao-or-extension))\n (ok (var-set paused new-paused))))\n(define-public (set-start-block (token-x principal) (token-y principal) (factor uint) (new-start-block uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-start-block token-x token-y factor new-start-block))))\n(define-public (set-end-block (token-x principal) (token-y principal) (factor uint) (new-end-block uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-end-block token-x token-y factor new-end-block))))\n(define-public (set-max-in-ratio (token-x principal) (token-y principal) (factor uint) (new-max-in-ratio uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-max-in-ratio token-x token-y factor new-max-in-ratio))))\n(define-public (set-max-out-ratio (token-x principal) (token-y principal) (factor uint) (new-max-out-ratio uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-max-out-ratio token-x token-y factor new-max-out-ratio))))\n(define-public (set-oracle-enabled (token-x principal) (token-y principal) (factor uint) (enabled bool))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-oracle-enabled token-x token-y factor enabled))))\n(define-public (set-oracle-average (token-x principal) (token-y principal) (factor uint) (new-oracle-average uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-oracle-average token-x token-y factor new-oracle-average))))\n(define-public (set-threshold-x (token-x principal) (token-y principal) (factor uint) (new-threshold uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-threshold-x token-x token-y factor new-threshold))))\n(define-public (set-threshold-y (token-x principal) (token-y principal) (factor uint) (new-threshold uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-threshold-y token-x token-y factor new-threshold))))\n(define-public (set-fee-rate-x (token-x principal) (token-y principal) (factor uint) (fee-rate-x uint))\n (let ( \n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-fee-rate-x token-x token-y factor fee-rate-x))))\n(define-public (set-fee-rate-y (token-x principal) (token-y principal) (factor uint) (fee-rate-y uint))\n (let ( \n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-fee-rate-y token-x token-y factor fee-rate-y))))\n(define-public (create-pool (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (pool-owner principal) (dx uint) (dy uint)) \n (begin\n (asserts! (not (is-blocklisted-or-default tx-sender)) ERR-BLOCKLISTED)\n (as-contract (try! (contract-call? .amm-registry-v2-01 create-pool token-x-trait token-y-trait factor pool-owner)))\n (add-to-position token-x-trait token-y-trait factor dx (some dy))))\n(define-public (add-to-position (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (dx uint) (max-dy (optional uint)))\n (let (\n (token-x (contract-of token-x-trait))\n (token-y (contract-of token-y-trait))\n (pool (try! (get-pool-details token-x token-y factor)))\n (balance-x (get balance-x pool))\n (balance-y (get balance-y pool))\n (total-supply (get total-supply pool))\n (add-data (try! (get-token-given-position token-x token-y factor dx max-dy)))\n (new-supply (get token add-data))\n (dy (get dy add-data))\n (pool-updated (merge pool { total-supply: (+ new-supply total-supply), balance-x: (+ balance-x dx), balance-y: (+ balance-y dy) }))\n (sender tx-sender))\n (asserts! (not (is-paused)) ERR-PAUSED)\n (asserts! (and (> dx u0) (> dy u0)) ERR-INVALID-LIQUIDITY)\n (asserts! (>= (default-to u340282366920938463463374607431768211455 max-dy) dy) ERR-EXCEEDS-MAX-SLIPPAGE)\n (try! (contract-call? token-x-trait transfer-fixed dx sender .amm-vault-v2-01 none))\n (try! (contract-call? token-y-trait transfer-fixed dy sender .amm-vault-v2-01 none))\n (as-contract (try! (contract-call? .amm-registry-v2-01 update-pool token-x token-y factor pool-updated)))\n (as-contract (try! (contract-call? .token-amm-pool-v2-01 mint-fixed (get pool-id pool) new-supply sender)))\n (print { object: "pool", action: "liquidity-added", data: pool-updated, dx: dx, dy: dy, token-x: token-x, token-y: token-y, sender: sender })\n (ok {supply: new-supply, dx: dx, dy: dy})))\n(define-public (reduce-position (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (percent uint))\n (let (\n (token-x (contract-of token-x-trait))\n (token-y (contract-of token-y-trait))\n (pool (try! (get-pool-details token-x token-y factor)))\n (balance-x (get balance-x pool))\n (balance-y (get balance-y pool))\n (total-shares (unwrap-panic (contract-call? .token-amm-pool-v2-01 get-balance-fixed (get pool-id pool) tx-sender)))\n (shares (if (is-eq percent ONE_8) total-shares (mul-down total-shares percent)))\n (total-supply (get total-supply pool))\n (reduce-data (try! (get-position-given-burn token-x token-y factor shares)))\n (dx (get dx reduce-data))\n (dy (get dy reduce-data))\n (pool-updated (merge pool { total-supply: (if (<= total-supply shares) u0 (- total-supply shares)), balance-x: (if (<= balance-x dx) u0 (- balance-x dx)), balance-y: (if (<= balance-y dy) u0 (- balance-y dy)) }))\n (sender tx-sender)) \n (asserts! (not (is-blocklisted-or-default tx-sender)) ERR-BLOCKLISTED) \n (asserts! (not (is-paused)) ERR-PAUSED) \n (asserts! (<= percent ONE_8) ERR-PERCENT-GREATER-THAN-ONE)\n (as-contract (try! (contract-call? .amm-vault-v2-01 transfer-ft-two token-x-trait dx token-y-trait dy sender)))\n (as-contract (try! (contract-call? .amm-registry-v2-01 update-pool token-x token-y factor pool-updated)))\n (as-contract (try! (contract-call? .token-amm-pool-v2-01 burn-fixed (get pool-id pool) shares sender)))\n (print { object: "pool", action: "liquidity-removed", data: pool-updated, dx: dx, dy: dy, token-x: token-x, token-y: token-y, sender: sender })\n (ok {dx: dx, dy: dy})))\n(define-public (swap-x-for-y (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (dx uint) (min-dy (optional uint)))\n (let (\n (token-x (contract-of token-x-trait))\n (token-y (contract-of token-y-trait))\n (pool (try! (get-pool-details token-x token-y factor)))\n (balance-x (get balance-x pool))\n (balance-y (get balance-y pool))\n (fee (mul-up dx (get fee-rate-x pool)))\n (dx-net-fees (if (<= dx fee) u0 (- dx fee)))\n (fee-rebate (mul-down fee (get fee-rebate pool)))\n (dy (try! (get-y-given-x token-x token-y factor dx-net-fees))) \n (pool-updated (merge pool {\n balance-x: (+ balance-x dx-net-fees fee-rebate),\n balance-y: (if (<= balance-y dy) u0 (- balance-y dy)),\n oracle-resilient: (if (get oracle-enabled pool) (try! (get-oracle-resilient token-x token-y factor)) u0)\n }))\n (sender tx-sender))\n (asserts! (not (is-blocklisted-or-default tx-sender)) ERR-BLOCKLISTED)\n (asserts! (not (is-paused)) ERR-PAUSED)\n (try! (check-pool-status token-x token-y factor))\n (asserts! (> dx u0) ERR-INVALID-LIQUIDITY)\n (asserts! (<= (div-down dy dx-net-fees) (get-price-internal balance-x balance-y factor)) ERR-INVALID-LIQUIDITY)\n (asserts! (<= (default-to u0 min-dy) dy) ERR-EXCEEDS-MAX-SLIPPAGE)\n (try! (contract-call? token-x-trait transfer-fixed dx sender .amm-vault-v2-01 none))\n (and (> dy u0) (as-contract (try! (contract-call? .amm-vault-v2-01 transfer-ft token-y-trait dy sender))))\n (as-contract (try! (contract-call? .amm-vault-v2-01 add-to-reserve token-x (- fee fee-rebate))))\n (as-contract (try! (contract-call? .amm-registry-v2-01 update-pool token-x token-y factor pool-updated)))\n (print { object: "pool", action: "swap-x-for-y", data: pool-updated, dx: dx, dy: dy, token-x: token-x, token-y: token-y, sender: sender, fee: fee, fee-rebate: fee-rebate })\n (ok {dx: dx-net-fees, dy: dy})))\n(define-public (swap-y-for-x (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (dy uint) (min-dx (optional uint)))\n (let (\n (token-x (contract-of token-x-trait))\n (token-y (contract-of token-y-trait))\n (pool (try! (get-pool-details token-x token-y factor)))\n (balance-x (get balance-x pool))\n (balance-y (get balance-y pool))\n (fee (mul-up dy (get fee-rate-y pool)))\n (dy-net-fees (if (<= dy fee) u0 (- dy fee)))\n (fee-rebate (mul-down fee (get fee-rebate pool)))\n (dx (try! (get-x-given-y token-x token-y factor dy-net-fees)))\n (pool-updated (merge pool {\n balance-x: (if (<= balance-x dx) u0 (- balance-x dx)),\n balance-y: (+ balance-y dy-net-fees fee-rebate),\n oracle-resilient: (if (get oracle-enabled pool) (try! (get-oracle-resilient token-x token-y factor)) u0)\n }))\n (sender tx-sender))\n (asserts! (not (is-blocklisted-or-default tx-sender)) ERR-BLOCKLISTED)\n (asserts! (not (is-paused)) ERR-PAUSED)\n (try! (check-pool-status token-x token-y factor))\n (asserts! (> dy u0) ERR-INVALID-LIQUIDITY) \n (asserts! (>= (div-down dy-net-fees dx) (get-price-internal balance-x balance-y factor)) ERR-INVALID-LIQUIDITY)\n (asserts! (<= (default-to u0 min-dx) dx) ERR-EXCEEDS-MAX-SLIPPAGE) \n (try! (contract-call? token-y-trait transfer-fixed dy sender .amm-vault-v2-01 none))\n (and (> dx u0) (as-contract (try! (contract-call? .amm-vault-v2-01 transfer-ft token-x-trait dx sender)))) \n (as-contract (try! (contract-call? .amm-vault-v2-01 add-to-reserve token-y (- fee fee-rebate))))\n (as-contract (try! (contract-call? .amm-registry-v2-01 update-pool token-x token-y factor pool-updated)))\n (print { object: "pool", action: "swap-y-for-x", data: pool-updated, dx: dx, dy: dy, token-x: token-x, token-y: token-y, sender: sender, fee: fee, fee-rebate: fee-rebate })\n (ok {dx: dx, dy: dy-net-fees})))\n(define-public (swap-helper (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (dx uint) (min-dy (optional uint)))\n (if (is-some (get-pool-exists (contract-of token-x-trait) (contract-of token-y-trait) factor))\n (ok (get dy (try! (swap-x-for-y token-x-trait token-y-trait factor dx min-dy))))\n (ok (get dx (try! (swap-y-for-x token-y-trait token-x-trait factor dx min-dy))))))\n(define-public (swap-helper-a (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (token-z-trait <ft-trait>) (factor-x uint) (factor-y uint) (dx uint) (min-dz (optional uint)))\n (swap-helper token-y-trait token-z-trait factor-y (try! (swap-helper token-x-trait token-y-trait factor-x dx none)) min-dz))\n(define-public (swap-helper-b\n (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (token-z-trait <ft-trait>) (token-w-trait <ft-trait>)\n (factor-x uint) (factor-y uint) (factor-z uint)\n (dx uint) (min-dw (optional uint)))\n (swap-helper token-z-trait token-w-trait factor-z (try! (swap-helper-a token-x-trait token-y-trait token-z-trait factor-x factor-y dx none)) min-dw))\n(define-public (swap-helper-c\n (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (token-z-trait <ft-trait>) (token-w-trait <ft-trait>) (token-v-trait <ft-trait>)\n (factor-x uint) (factor-y uint) (factor-z uint) (factor-w uint)\n (dx uint) (min-dv (optional uint)))\n (swap-helper-a token-z-trait token-w-trait token-v-trait factor-z factor-w (try! (swap-helper-a token-x-trait token-y-trait token-z-trait factor-x factor-y dx none)) min-dv))\n(define-private (get-price-internal (balance-x uint) (balance-y uint) (factor uint))\n (if (>= factor (get-switch-threshold))\n (div-down (+ (- ONE_8 factor) (mul-down factor balance-y)) (+ (- ONE_8 factor) (mul-down factor balance-x)))\n (pow-down (div-down balance-y balance-x) factor)))\n(define-private (get-y-given-x-internal (balance-x uint) (balance-y uint) (t uint) (dx uint))\n (if (>= t (get-switch-threshold))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))) \n (div-down (+ (mul-down t-comp dx) (mul-down t (mul-down dx balance-y))) (+ t-comp (mul-down t (+ balance-x dx)))))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-up ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (x-pow (pow-up balance-x t-comp))\n (y-pow (pow-up balance-y t-comp))\n (x-dx-pow (pow-down (+ balance-x dx) t-comp))\n (add-term (+ x-pow y-pow))\n (term (if (<= add-term x-dx-pow) u0 (- add-term x-dx-pow)))\n (final-term (pow-up term t-comp-num))) \n (if (<= balance-y final-term) u0 (- balance-y final-term)))))\n(define-private (get-x-given-y-internal (balance-x uint) (balance-y uint) (t uint) (dy uint))\n (if (>= t (get-switch-threshold))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))) \n (div-down (+ (mul-down t-comp dy) (mul-down t (mul-down dy balance-x))) (+ t-comp (mul-down t (+ balance-y dy))))) \n (let ( \n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-up ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (x-pow (pow-up balance-x t-comp))\n (y-pow (pow-up balance-y t-comp))\n (y-dy-pow (pow-down (+ balance-y dy) t-comp))\n (add-term (+ x-pow y-pow))\n (term (if (<= add-term y-dy-pow) u0 (- add-term y-dy-pow)))\n (final-term (pow-up term t-comp-num)))\n (if (<= balance-x final-term) u0 (- balance-x final-term)))))\n(define-private (get-y-in-given-x-out-internal (balance-x uint) (balance-y uint) (t uint) (dx uint)) \n (if (>= t (get-switch-threshold))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t))))\n (div-down (+ (mul-down t-comp dx) (mul-down t (mul-down dx balance-y))) (+ t-comp (mul-down t (- balance-x dx)))))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-down ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (x-pow (pow-down balance-x t-comp))\n (y-pow (pow-down balance-y t-comp))\n (x-dx-pow (pow-up (if (<= balance-x dx) u0 (- balance-x dx)) t-comp))\n (add-term (+ x-pow y-pow))\n (term (if (<= add-term x-dx-pow) u0 (- add-term x-dx-pow)))\n (final-term (pow-down term t-comp-num)))\n (if (<= final-term balance-y) u0 (- final-term balance-y)))))\n(define-private (get-x-in-given-y-out-internal (balance-x uint) (balance-y uint) (t uint) (dy uint))\n (if (>= t (get-switch-threshold))\n (let ( \n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t))))\n (div-down (+ (mul-down t-comp dy) (mul-down t (mul-down dy balance-x))) (+ t-comp (mul-down t (- balance-y dy)))))\n (let ( \n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-down ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (x-pow (pow-down balance-x t-comp))\n (y-pow (pow-down balance-y t-comp))\n (y-dy-pow (pow-up (if (<= balance-y dy) u0 (- balance-y dy)) t-comp))\n (add-term (+ x-pow y-pow))\n (term (if (<= add-term y-dy-pow) u0 (- add-term y-dy-pow)))\n (final-term (pow-down term t-comp-num)))\n (if (<= final-term balance-x) u0 (- final-term balance-x)))))\n(define-private (get-x-given-price-internal (balance-x uint) (balance-y uint) (t uint) (price uint))\n (if (>= t (get-switch-threshold))\n (let (\n (power (pow-down (div-down (get-price-internal balance-x balance-y t) price) u50000000)))\n (mul-down balance-x (if (<= power ONE_8) u0 (- power ONE_8)))) \n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-down ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (numer (+ ONE_8 (pow-down (get-price-internal balance-x balance-y t) (div-down t-comp t))))\n (denom (+ ONE_8 (pow-down price (div-down t-comp t))))\n (lead-term (pow-down (div-down numer denom) t-comp-num)))\n (if (<= lead-term ONE_8) u0 (mul-up balance-x (- lead-term ONE_8))))))\n(define-private (get-y-given-price-internal (balance-x uint) (balance-y uint) (t uint) (price uint))\n (if (>= t (get-switch-threshold))\n (let ( \n (power (pow-down (div-down price (get-price-internal balance-x balance-y t)) u50000000)))\n (mul-down balance-y (if (<= power ONE_8) u0 (- power ONE_8))))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-down ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (numer (+ ONE_8 (pow-down (get-price-internal balance-x balance-y t) (div-down t-comp t))))\n (denom (+ ONE_8 (pow-down price (div-down t-comp t))))\n (lead-term (pow-down (div-down numer denom) t-comp-num)))\n (if (<= ONE_8 lead-term) u0 (mul-up balance-y (- ONE_8 lead-term))))))\n(define-private (get-token-given-position-internal (balance-x uint) (balance-y uint) (t uint) (total-supply uint) (dx uint) (dy uint))\n (if (is-eq total-supply u0)\n {token: (get-invariant dx dy t), dy: dy}\n {token: (div-down (mul-down total-supply dx) balance-x), dy: (div-down (mul-down balance-y dx) balance-x)}))\n(define-private (get-position-given-mint-internal (balance-x uint) (balance-y uint) (t uint) (total-supply uint) (token-amount uint))\n (let (\n (token-div-supply (div-down token-amount total-supply))\n )\n {dx: (mul-down balance-x token-div-supply), dy: (mul-down balance-y token-div-supply)}))\n(define-private (get-position-given-burn-internal (balance-x uint) (balance-y uint) (t uint) (total-supply uint) (token-amount uint))\n (get-position-given-mint-internal balance-x balance-y t total-supply token-amount))\n(define-constant ONE_8 u100000000) ;; 8 decimal places\n(define-constant MAX_POW_RELATIVE_ERROR u4)\n(define-private (mul-down (a uint) (b uint))\n (/ (* a b) ONE_8))\n(define-private (mul-up (a uint) (b uint))\n (let (\n (product (* a b))\n )\n (if (is-eq product u0) u0 (+ u1 (/ (- product u1) ONE_8)))))\n(define-private (div-down (a uint) (b uint))\n (if (is-eq a u0) u0 (/ (* a ONE_8) b)))\n(define-private (div-up (a uint) (b uint))\n (if (is-eq a u0) u0 (+ u1 (/ (- (* a ONE_8) u1) b))))\n(define-private (pow-down (a uint) (b uint))\n (let (\n (raw (unwrap-panic (pow-fixed a b)))\n (max-error (+ u1 (mul-up raw MAX_POW_RELATIVE_ERROR)))\n )\n (if (< raw max-error) u0 (- raw max-error))))\n(define-private (pow-up (a uint) (b uint))\n (let (\n (raw (unwrap-panic (pow-fixed a b)))\n (max-error (+ u1 (mul-up raw MAX_POW_RELATIVE_ERROR)))\n )\n (+ raw max-error)))\n(define-constant UNSIGNED_ONE_8 (pow 10 8))\n(define-constant MAX_NATURAL_EXPONENT (* 69 UNSIGNED_ONE_8))\n(define-constant MIN_NATURAL_EXPONENT (* -18 UNSIGNED_ONE_8))\n(define-constant MILD_EXPONENT_BOUND (/ (pow u2 u126) (to-uint UNSIGNED_ONE_8)))\n(define-constant x_a_list_no_deci (list {x_pre: 6400000000, a_pre: 62351490808116168829, use_deci: false} ))\n(define-constant x_a_list (list\n {x_pre: 3200000000, a_pre: 78962960182680695161, use_deci: true} ;; x2 = 2^5, a2 = e^(x2)\n {x_pre: 1600000000, a_pre: 888611052050787, use_deci: true} ;; x3 = 2^4, a3 = e^(x3)\n {x_pre: 800000000, a_pre: 298095798704, use_deci: true} ;; x4 = 2^3, a4 = e^(x4)\n {x_pre: 400000000, a_pre: 5459815003, use_deci: true} ;; x5 = 2^2, a5 = e^(x5)\n {x_pre: 200000000, a_pre: 738905610, use_deci: true} ;; x6 = 2^1, a6 = e^(x6)\n {x_pre: 100000000, a_pre: 271828183, use_deci: true} ;; x7 = 2^0, a7 = e^(x7)\n {x_pre: 50000000, a_pre: 164872127, use_deci: true} ;; x8 = 2^-1, a8 = e^(x8)\n {x_pre: 25000000, a_pre: 128402542, use_deci: true} ;; x9 = 2^-2, a9 = e^(x9)\n {x_pre: 12500000, a_pre: 113314845, use_deci: true} ;; x10 = 2^-3, a10 = e^(x10)\n {x_pre: 6250000, a_pre: 106449446, use_deci: true} ;; x11 = 2^-4, a11 = e^x(11)\n))\n(define-constant ERR-X-OUT-OF-BOUNDS (err u5009))\n(define-constant ERR-Y-OUT-OF-BOUNDS (err u5010))\n(define-constant ERR-PRODUCT-OUT-OF-BOUNDS (err u5011))\n(define-constant ERR-INVALID-EXPONENT (err u5012))\n(define-constant ERR-OUT-OF-BOUNDS (err u5013))\n(define-private (ln-priv (a int))\n (let (\n (a_sum_no_deci (fold accumulate_division x_a_list_no_deci {a: a, sum: 0}))\n (a_sum (fold accumulate_division x_a_list {a: (get a a_sum_no_deci), sum: (get sum a_sum_no_deci)}))\n (out_a (get a a_sum))\n (out_sum (get sum a_sum))\n (z (/ (* (- out_a UNSIGNED_ONE_8) UNSIGNED_ONE_8) (+ out_a UNSIGNED_ONE_8)))\n (z_squared (/ (* z z) UNSIGNED_ONE_8))\n (div_list (list 3 5 7 9 11))\n (num_sum_zsq (fold rolling_sum_div div_list {num: z, seriesSum: z, z_squared: z_squared}))\n (seriesSum (get seriesSum num_sum_zsq))\n )\n (+ out_sum (* seriesSum 2))))\n(define-private (accumulate_division (x_a_pre (tuple (x_pre int) (a_pre int) (use_deci bool))) (rolling_a_sum (tuple (a int) (sum int))))\n (let (\n (a_pre (get a_pre x_a_pre))\n (x_pre (get x_pre x_a_pre))\n (use_deci (get use_deci x_a_pre))\n (rolling_a (get a rolling_a_sum))\n (rolling_sum (get sum rolling_a_sum))\n )\n (if (>= rolling_a (if use_deci a_pre (* a_pre UNSIGNED_ONE_8)))\n {a: (/ (* rolling_a (if use_deci UNSIGNED_ONE_8 1)) a_pre), sum: (+ rolling_sum x_pre)}\n {a: rolling_a, sum: rolling_sum})))\n(define-private (rolling_sum_div (n int) (rolling (tuple (num int) (seriesSum int) (z_squared int))))\n (let (\n (rolling_num (get num rolling))\n (rolling_sum (get seriesSum rolling))\n (z_squared (get z_squared rolling))\n (next_num (/ (* rolling_num z_squared) UNSIGNED_ONE_8))\n (next_sum (+ rolling_sum (/ next_num n)))\n )\n {num: next_num, seriesSum: next_sum, z_squared: z_squared}))\n(define-private (pow-priv (x uint) (y uint))\n (let (\n (x-int (to-int x))\n (y-int (to-int y))\n (lnx (ln-priv x-int))\n (logx-times-y (/ (* lnx y-int) UNSIGNED_ONE_8)))\n (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) ERR-PRODUCT-OUT-OF-BOUNDS)\n (ok (to-uint (try! (exp-fixed logx-times-y))))))\n(define-private (exp-pos (x int))\n (begin\n (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) ERR-INVALID-EXPONENT)\n (let (\n (x_product_no_deci (fold accumulate_product x_a_list_no_deci {x: x, product: 1}))\n (x_adj (get x x_product_no_deci))\n (firstAN (get product x_product_no_deci))\n (x_product (fold accumulate_product x_a_list {x: x_adj, product: UNSIGNED_ONE_8}))\n (product_out (get product x_product))\n (x_out (get x x_product))\n (seriesSum (+ UNSIGNED_ONE_8 x_out))\n (div_list (list 2 3 4 5 6 7 8 9 10 11 12))\n (term_sum_x (fold rolling_div_sum div_list {term: x_out, seriesSum: seriesSum, x: x_out}))\n (sum (get seriesSum term_sum_x)))\n (ok (* (/ (* product_out sum) UNSIGNED_ONE_8) firstAN)))))\n(define-private (accumulate_product (x_a_pre (tuple (x_pre int) (a_pre int) (use_deci bool))) (rolling_x_p (tuple (x int) (product int))))\n (let (\n (x_pre (get x_pre x_a_pre))\n (a_pre (get a_pre x_a_pre))\n (use_deci (get use_deci x_a_pre))\n (rolling_x (get x rolling_x_p))\n (rolling_product (get product rolling_x_p)))\n (if (>= rolling_x x_pre)\n {x: (- rolling_x x_pre), product: (/ (* rolling_product a_pre) (if use_deci UNSIGNED_ONE_8 1))}\n {x: rolling_x, product: rolling_product})))\n(define-private (rolling_div_sum (n int) (rolling (tuple (term int) (seriesSum int) (x int))))\n (let (\n (rolling_term (get term rolling))\n (rolling_sum (get seriesSum rolling))\n (x (get x rolling))\n (next_term (/ (/ (* rolling_term x) UNSIGNED_ONE_8) n))\n (next_sum (+ rolling_sum next_term))\n )\n {term: next_term, seriesSum: next_sum, x: x}))\n(define-private (pow-fixed (x uint) (y uint))\n (begin\n (asserts! (< x (pow u2 u127)) ERR-X-OUT-OF-BOUNDS)\n (asserts! (< y MILD_EXPONENT_BOUND) ERR-Y-OUT-OF-BOUNDS)\n (if (is-eq y u0)\n (ok (to-uint UNSIGNED_ONE_8))\n (if (is-eq x u0) (ok u0) (pow-priv x y)))))\n(define-private (exp-fixed (x int))\n (begin\n (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) ERR-INVALID-EXPONENT)\n (if (< x 0) (ok (/ (* UNSIGNED_ONE_8 UNSIGNED_ONE_8) (try! (exp-pos (* -1 x))))) (exp-pos x))))\n(define-private (log-fixed (arg int) (base int))\n (let (\n (logBase (* (ln-priv base) UNSIGNED_ONE_8))\n (logArg (* (ln-priv arg) UNSIGNED_ONE_8)))\n (ok (/ (* logArg UNSIGNED_ONE_8) logBase))))\n(define-private (ln-fixed (a int))\n (begin\n (asserts! (> a 0) ERR-OUT-OF-BOUNDS)\n (if (< a UNSIGNED_ONE_8) (ok (- 0 (ln-priv (/ (* UNSIGNED_ONE_8 UNSIGNED_ONE_8) a)))) (ok (ln-priv a)))))
SP20X3DC5R091J8B6YPQT638J8NR1W83KN6TN5BJY.path-apply_staging
https://api.hiro.so/extended/v1/contract/SP20X3DC5R091J8B6YPQT638J8NR1W83KN6TN5BJY.path-apply_staging
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n(use-trait ft-trait 'SP2AKWJYC7BNY18W1XXKPGP0YVEK63QJG4793Z2D4.sip-010-trait-ft-standard.sip-010-trait)\n\n(use-trait share-fee-to-trait 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.univ2-share-fee-to-trait.share-fee-to-trait)\n\n(use-trait univ2v2-pool-trait 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.univ2-pool-trait_v1_0_0.univ2-pool-trait)\n(use-trait univ2v2-fees-trait 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.univ2-fees-trait_v1_0_0.univ2-fees-trait)\n\n(use-trait curve-pool-trait 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.curve-pool-trait_v1_0_0.curve-pool-trait)\n(use-trait curve-fees-trait 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.curve-fees-trait_v1_0_0.curve-fees-trait)\n\n(use-trait ststx-pool-trait 'SP20X3DC5R091J8B6YPQT638J8NR1W83KN6TN5BJY.curve-pool-trait_ststx.curve-pool-trait)\n(use-trait ststx-proxy-trait 'SP20X3DC5R091J8B6YPQT638J8NR1W83KN6TN5BJY.curve-proxy-trait_ststx.curve-proxy-trait)\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n;; max 2047 edge tuples\n(define-constant MAX-EDGES u500) ;;effectively max nr of pools (stx -> *)\n(define-constant MAX-PATH-LEN u4)\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n;; pool types\n(define-constant UNIV2 "u")\n(define-constant UNIV2V2 "v")\n(define-constant CURVE "c")\n(define-constant USDH "h")\n(define-constant STSTX "s")\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n;; edges\n(define-read-only\n (is-univ2 (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (is-eq (get a edge) UNIV2))\n(define-read-only\n (is-univ2v2 (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (is-eq (get a edge) UNIV2V2))\n(define-read-only\n (is-curve (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (is-eq (get a edge) CURVE))\n(define-read-only\n (is-usdh (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (is-eq (get a edge) USDH))\n(define-read-only\n (is-ststx (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (is-eq (get a edge) STSTX))\n\n(define-read-only\n (id (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (get c edge))\n(define-read-only\n (from-is-token0 (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (get f edge))\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n(define-public\n (apply\n (path (list 4 {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (amt-in uint)\n\n ;; ctx\n (token1 (optional <ft-trait>))\n (token2 (optional <ft-trait>))\n (token3 (optional <ft-trait>))\n (token4 (optional <ft-trait>))\n (token5 (optional <ft-trait>))\n\n ;; v1\n (share-fee-to (optional <share-fee-to-trait>))\n\n ;; v2\n (univ2v2-pool-1 (optional <univ2v2-pool-trait>))\n (univ2v2-pool-2 (optional <univ2v2-pool-trait>))\n (univ2v2-pool-3 (optional <univ2v2-pool-trait>))\n (univ2v2-pool-4 (optional <univ2v2-pool-trait>))\n\n (univ2v2-fees-1 (optional <univ2v2-fees-trait>))\n (univ2v2-fees-2 (optional <univ2v2-fees-trait>))\n (univ2v2-fees-3 (optional <univ2v2-fees-trait>))\n (univ2v2-fees-4 (optional <univ2v2-fees-trait>))\n\n (curve-pool-1 (optional <curve-pool-trait>))\n (curve-pool-2 (optional <curve-pool-trait>))\n (curve-pool-3 (optional <curve-pool-trait>))\n (curve-pool-4 (optional <curve-pool-trait>))\n\n (curve-fees-1 (optional <curve-fees-trait>))\n (curve-fees-2 (optional <curve-fees-trait>))\n (curve-fees-3 (optional <curve-fees-trait>))\n (curve-fees-4 (optional <curve-fees-trait>))\n\n (ststx-pool-1 (optional <ststx-pool-trait>))\n (ststx-pool-2 (optional <ststx-pool-trait>))\n (ststx-pool-3 (optional <ststx-pool-trait>))\n (ststx-pool-4 (optional <ststx-pool-trait>))\n\n (ststx-proxy-1 (optional <ststx-proxy-trait>))\n (ststx-proxy-2 (optional <ststx-proxy-trait>))\n (ststx-proxy-3 (optional <ststx-proxy-trait>))\n (ststx-proxy-4 (optional <ststx-proxy-trait>))\n )\n (let ((swap1 (try! (swap (element-at? path u0) amt-in\n token1 token2\n share-fee-to\n univ2v2-pool-1 univ2v2-fees-1\n curve-pool-1 curve-fees-1\n ststx-pool-1 ststx-proxy-1\n )))\n (swap2 (try! (swap (element-at? path u1) (get amt-out swap1)\n token2 token3\n share-fee-to\n univ2v2-pool-2 univ2v2-fees-2\n curve-pool-2 curve-fees-2\n ststx-pool-2 ststx-proxy-2\n )))\n (swap3 (try! (swap (element-at? path u2) (get amt-out swap2)\n token3 token4\n share-fee-to\n univ2v2-pool-3 univ2v2-fees-3\n curve-pool-3 curve-fees-3\n ststx-pool-3 ststx-proxy-3\n )))\n (swap4 (try! (swap (element-at? path u3) (get amt-out swap3)\n token4 token5\n share-fee-to\n univ2v2-pool-4 univ2v2-fees-4\n curve-pool-4 curve-fees-4\n ststx-pool-4 ststx-proxy-4\n )))\n )\n (ok\n {swap1: swap1,\n swap2: swap2,\n swap3: swap3,\n swap4: swap4,\n }) ))\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n(define-private\n (swap\n (edge (optional {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool}))\n (amt-in uint)\n\n (token-in (optional <ft-trait>))\n (token-out (optional <ft-trait>))\n (share-fee-to (optional <share-fee-to-trait>))\n (univ2v2-pool (optional <univ2v2-pool-trait>))\n (univ2v2-fees (optional <univ2v2-fees-trait>))\n (curve-pool (optional <curve-pool-trait>))\n (curve-fees (optional <curve-fees-trait>))\n (ststx-pool (optional <ststx-pool-trait>))\n (ststx-proxy (optional <ststx-proxy-trait>))\n\n )\n (match\n edge\n e\n (if (is-univ2 e) (swap-univ2 e amt-in\n (unwrap-panic token-in) (unwrap-panic token-out)\n (unwrap-panic share-fee-to))\n (if (is-univ2v2 e) (swap-univ2v2 e amt-in\n (unwrap-panic token-in) (unwrap-panic token-out)\n (unwrap-panic univ2v2-pool) (unwrap-panic univ2v2-fees))\n (if (is-curve e) (swap-curve e amt-in\n (unwrap-panic token-in) (unwrap-panic token-out)\n (unwrap-panic curve-pool) (unwrap-panic curve-fees))\n (if (is-usdh e) (swap-curve e amt-in\n (unwrap-panic token-in) (unwrap-panic token-out)\n (unwrap-panic curve-pool) (unwrap-panic curve-fees))\n (if (is-ststx e) (swap-ststx e amt-in\n (unwrap-panic token-in) (unwrap-panic token-out)\n (unwrap-panic ststx-pool) (unwrap-panic curve-fees)\n (unwrap-panic ststx-proxy))\n\n (err u0))))))\n (ok {amt-in: amt-in, amt-out: amt-in}) ))\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n(define-public\n (swap-univ2\n (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool})\n (amt-in uint)\n (token-in <ft-trait>)\n (token-out <ft-trait>)\n (share-fee-to <share-fee-to-trait>) )\n (let ((res\n (try!\n (contract-call?\n 'SP1Y5YSTAHZ88XYK1VPDH24GY0HPX5J4JECTMY4A1.univ2-router\n swap-exact-tokens-for-tokens\n (id edge)\n (if (from-is-token0 edge) token-in token-out)\n (if (from-is-token0 edge) token-out token-in)\n token-in\n token-out\n share-fee-to\n amt-in\n u1 ;;amt-out-min\n ))))\n (ok {amt-in: amt-in, amt-out: (get amt-out res)}) ))\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n(define-public\n (swap-univ2v2\n (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool})\n (amt-in uint)\n (token-in <ft-trait>)\n (token-out <ft-trait>)\n (univ2v2-pool <univ2v2-pool-trait>)\n (univ2v2-fees <univ2v2-fees-trait>)\n )\n (let ((res\n (try!\n (contract-call?\n univ2v2-pool\n swap\n token-in\n token-out\n univ2v2-fees\n amt-in\n u1 ;;amt-out-min\n ))))\n (ok {amt-in: amt-in, amt-out: (get amt-out res)}) ))\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n(define-public\n (swap-curve\n (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool})\n (amt-in uint)\n (token-in <ft-trait>)\n (token-out <ft-trait>)\n (curve-pool <curve-pool-trait>)\n (curve-fees <curve-fees-trait>)\n )\n (let ((res (try! (contract-call?\n curve-pool\n swap\n token-in\n token-out\n curve-fees\n amt-in\n u1 ;;amt-out-min\n ))))\n (ok {amt-in: amt-in, amt-out: (get amt-out res)}) ))\n\n;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n(define-public\n (swap-ststx\n (edge {a:(string-ascii 1),b:principal,c:uint,d:principal,e:principal,f:bool})\n (amt-in uint)\n (token-in <ft-trait>)\n (token-out <ft-trait>)\n (ststx-pool <ststx-pool-trait>)\n (curve-fees <curve-fees-trait>)\n (ststx-proxy <ststx-proxy-trait>)\n )\n (let ((res (try! (contract-call?\n ststx-pool\n swap\n token-in\n token-out\n curve-fees\n ststx-proxy\n amt-in\n u1 ;;amt-out-min\n ))))\n (ok {amt-in: amt-in, amt-out: (get amt-out res)}) ))\n\n;;; eof\n
SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01
https://api.hiro.so/extended/v1/contract/SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01
(use-trait ft-trait .trait-sip-010.sip-010-trait)\n(define-constant ERR-NOT-AUTHORIZED (err u1000))\n(define-constant ERR-POOL-ALREADY-EXISTS (err u2000))\n(define-constant ERR-INVALID-POOL (err u2001))\n(define-constant ERR-BLOCKLISTED (err u2002))\n(define-constant ERR-INVALID-LIQUIDITY (err u2003))\n(define-constant ERR-PERCENT-GREATER-THAN-ONE (err u2004))\n(define-constant ERR-EXCEEDS-MAX-SLIPPAGE (err u2005))\n(define-constant ERR-ORACLE-NOT-ENABLED (err u2006))\n(define-constant ERR-ORACLE-AVERAGE-BIGGER-THAN-ONE (err u2007))\n(define-constant ERR-PAUSED (err u2008))\n(define-constant ERR-SWITCH-THRESHOLD-BIGGER-THAN-ONE (err u2009))\n(define-constant ERR-NO-LIQUIDITY (err u2010))\n(define-constant ERR-MAX-IN-RATIO (err u2011))\n(define-constant ERR-MAX-OUT-RATIO (err u2012))\n(define-data-var paused bool true)\n(define-read-only (is-dao-or-extension)\n (ok (asserts! (or (is-eq tx-sender .executor-dao) (contract-call? .executor-dao is-extension contract-caller)) ERR-NOT-AUTHORIZED)))\n(define-read-only (is-blocklisted-or-default (sender principal))\n (contract-call? .amm-registry-v2-01 is-blocklisted-or-default sender))\n(define-read-only (get-switch-threshold)\n (contract-call? .amm-registry-v2-01 get-switch-threshold))\n(define-read-only (get-pool-details-by-id (pool-id uint))\n (contract-call? .amm-registry-v2-01 get-pool-details-by-id pool-id))\n(define-read-only (get-pool-details (token-x principal) (token-y principal) (factor uint))\n (contract-call? .amm-registry-v2-01 get-pool-details token-x token-y factor))\n(define-read-only (get-pool-exists (token-x principal) (token-y principal) (factor uint))\n (contract-call? .amm-registry-v2-01 get-pool-exists token-x token-y factor))\n(define-read-only (is-paused)\n (var-get paused))\n(define-read-only (get-balances (token-x principal) (token-y principal) (factor uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (ok {balance-x: (get balance-x pool), balance-y: (get balance-y pool)})))\n(define-read-only (get-start-block (token-x principal) (token-y principal) (factor uint))\n (ok (get start-block (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-end-block (token-x principal) (token-y principal) (factor uint))\n (ok (get end-block (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-max-in-ratio (token-x principal) (token-y principal) (factor uint))\n (ok (get max-in-ratio (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-max-out-ratio (token-x principal) (token-y principal) (factor uint))\n (ok (get max-out-ratio (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (check-pool-status (token-x principal) (token-y principal) (factor uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (ok (asserts! (and (>= block-height (get start-block pool)) (<= block-height (get end-block pool))) ERR-NOT-AUTHORIZED))))\n(define-read-only (get-oracle-enabled (token-x principal) (token-y principal) (factor uint))\n (ok (get oracle-enabled (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-oracle-average (token-x principal) (token-y principal) (factor uint))\n (ok (get oracle-average (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-oracle-resilient (token-x principal) (token-y principal) (factor uint))\n (let (\n (exists (is-some (get-pool-exists token-x token-y factor)))\n (pool (if exists (try! (get-pool-details token-x token-y factor)) (try! (get-pool-details token-y token-x factor))))\n (oracle-instant (try! (get-oracle-instant token-x token-y factor))))\n (asserts! (get oracle-enabled pool) ERR-ORACLE-NOT-ENABLED)\n (ok (+ (mul-down (- ONE_8 (get oracle-average pool)) oracle-instant) \n (mul-down (get oracle-average pool) (if (is-eq (get oracle-resilient pool) u0) oracle-instant (get oracle-resilient pool)))))))\n(define-read-only (get-oracle-instant (token-x principal) (token-y principal) (factor uint))\n (let (\n (exists (is-some (get-pool-exists token-x token-y factor)))\n (pool (if exists (try! (get-pool-details token-x token-y factor)) (try! (get-pool-details token-y token-x factor))))\n )\n (asserts! (get oracle-enabled pool) ERR-ORACLE-NOT-ENABLED)\n (if exists\n (ok (get-price-internal (get balance-x pool) (get balance-y pool) factor))\n (ok (get-price-internal (get balance-y pool) (get balance-x pool) factor)))))\n(define-read-only (get-price (token-x principal) (token-y principal) (factor uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (ok (get-price-internal (get balance-x pool) (get balance-y pool) factor))))\n(define-read-only (get-threshold-x (token-x principal) (token-y principal) (factor uint))\n (ok (get threshold-x (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-threshold-y (token-x principal) (token-y principal) (factor uint))\n (ok (get threshold-y (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-fee-rebate (token-x principal) (token-y principal) (factor uint))\n (ok (get fee-rebate (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-fee-rate-x (token-x principal) (token-y principal) (factor uint))\n (ok (get fee-rate-x (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-fee-rate-y (token-x principal) (token-y principal) (factor uint))\n (ok (get fee-rate-y (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-pool-owner (token-x principal) (token-y principal) (factor uint))\n (ok (get pool-owner (try! (get-pool-details token-x token-y factor)))))\n(define-read-only (get-y-given-x (token-x principal) (token-y principal) (factor uint) (dx uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (threshold (get threshold-x pool))\n (dy (if (>= dx threshold)\n (get-y-given-x-internal (get balance-x pool) (get balance-y pool) factor dx)\n (div-down (mul-down dx (get-y-given-x-internal (get balance-x pool) (get balance-y pool) factor threshold)) threshold)))\n )\n (asserts! (< dx (mul-down (get balance-x pool) (get max-in-ratio pool))) ERR-MAX-IN-RATIO)\n (asserts! (< dy (mul-down (get balance-y pool) (get max-out-ratio pool))) ERR-MAX-OUT-RATIO)\n (ok dy)))\n(define-read-only (get-x-given-y (token-x principal) (token-y principal) (factor uint) (dy uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (threshold (get threshold-y pool))\n (dx (if (>= dy threshold)\n (get-x-given-y-internal (get balance-x pool) (get balance-y pool) factor dy)\n (div-down (mul-down dy (get-x-given-y-internal (get balance-x pool) (get balance-y pool) factor threshold)) threshold)))\n )\n (asserts! (< dy (mul-down (get balance-y pool) (get max-in-ratio pool))) ERR-MAX-IN-RATIO)\n (asserts! (< dx (mul-down (get balance-x pool) (get max-out-ratio pool))) ERR-MAX-OUT-RATIO)\n (ok dx)))\n(define-read-only (get-y-in-given-x-out (token-x principal) (token-y principal) (factor uint) (dx uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (threshold (get threshold-x pool))\n (dy (if (>= dx threshold)\n (get-y-in-given-x-out-internal (get balance-x pool) (get balance-y pool) factor dx)\n (div-down (mul-down dx (get-y-in-given-x-out-internal (get balance-x pool) (get balance-y pool) factor threshold)) threshold)))\n )\n (asserts! (< dy (mul-down (get balance-y pool) (get max-in-ratio pool))) ERR-MAX-IN-RATIO)\n (asserts! (< dx (mul-down (get balance-x pool) (get max-out-ratio pool))) ERR-MAX-OUT-RATIO)\n (ok dy)))\n(define-read-only (get-x-in-given-y-out (token-x principal) (token-y principal) (factor uint) (dy uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (threshold (get threshold-y pool))\n (dx (if (>= dy threshold)\n (get-x-in-given-y-out-internal (get balance-x pool) (get balance-y pool) factor dy)\n (div-down (mul-down dy (get-x-in-given-y-out-internal (get balance-x pool) (get balance-y pool) factor threshold)) threshold)))\n )\n (asserts! (< dx (mul-down (get balance-x pool) (get max-in-ratio pool))) ERR-MAX-IN-RATIO)\n (asserts! (< dy (mul-down (get balance-y pool) (get max-out-ratio pool))) ERR-MAX-OUT-RATIO)\n (ok dx)))\n(define-read-only (get-x-given-price (token-x principal) (token-y principal) (factor uint) (price uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (asserts! (< price (get-price-internal (get balance-x pool) (get balance-y pool) factor)) ERR-NO-LIQUIDITY)\n (ok (get-x-given-price-internal (get balance-x pool) (get balance-y pool) factor price))))\n(define-read-only (get-y-given-price (token-x principal) (token-y principal) (factor uint) (price uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (asserts! (> price (get-price-internal (get balance-x pool) (get balance-y pool) factor)) ERR-NO-LIQUIDITY)\n (ok (get-y-given-price-internal (get balance-x pool) (get balance-y pool) factor price))))\n(define-read-only (get-token-given-position (token-x principal) (token-y principal) (factor uint) (dx uint) (max-dy (optional uint)))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n (dy (default-to u340282366920938463463374607431768211455 max-dy))\n )\n (asserts! (and (> dx u0) (> dy u0)) ERR-NO-LIQUIDITY)\n (ok (get-token-given-position-internal (get balance-x pool) (get balance-y pool) factor (get total-supply pool) dx dy))))\n(define-read-only (get-position-given-mint (token-x principal) (token-y principal) (factor uint) (token-amount uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (asserts! (> (get total-supply pool) u0) ERR-NO-LIQUIDITY)\n (ok (get-position-given-mint-internal (get balance-x pool) (get balance-y pool) factor (get total-supply pool) token-amount))))\n(define-read-only (get-position-given-burn (token-x principal) (token-y principal) (factor uint) (token-amount uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor)))\n )\n (asserts! (> (get total-supply pool) u0) ERR-NO-LIQUIDITY)\n (ok (get-position-given-burn-internal (get balance-x pool) (get balance-y pool) factor (get total-supply pool) token-amount))))\n(define-read-only (get-helper (token-x principal) (token-y principal) (factor uint) (dx uint))\n (if (is-some (get-pool-exists token-x token-y factor))\n (get-y-given-x token-x token-y factor dx)\n (get-x-given-y token-y token-x factor dx)))\n(define-read-only (get-helper-a (token-x principal) (token-y principal) (token-z principal) (factor-x uint) (factor-y uint) (dx uint))\n (get-helper token-y token-z factor-y (try! (get-helper token-x token-y factor-x dx))))\n(define-read-only (get-helper-b\n (token-x principal) (token-y principal) (token-z principal) (token-w principal)\n (factor-x uint) (factor-y uint) (factor-z uint)\n (dx uint))\n (get-helper token-z token-w factor-z (try! (get-helper-a token-x token-y token-z factor-x factor-y dx))))\n(define-read-only (get-helper-c\n (token-x principal) (token-y principal) (token-z principal) (token-w principal) (token-v principal)\n (factor-x uint) (factor-y uint) (factor-z uint) (factor-w uint)\n (dx uint))\n (get-helper-a token-z token-w token-v factor-z factor-w (try! (get-helper-a token-x token-y token-z factor-x factor-y dx))))\n(define-read-only (fee-helper (token-x principal) (token-y principal) (factor uint))\n (if (is-some (get-pool-exists token-x token-y factor))\n (get-fee-rate-x token-x token-y factor)\n (get-fee-rate-y token-y token-x factor)))\n(define-read-only (fee-helper-a (token-x principal) (token-y principal) (token-z principal) (factor-x uint) (factor-y uint))\n (ok (+ (try! (fee-helper token-x token-y factor-x)) (try! (fee-helper token-y token-z factor-y)))))\n(define-read-only (fee-helper-b\n (token-x principal) (token-y principal) (token-z principal) (token-w principal)\n (factor-x uint) (factor-y uint) (factor-z uint))\n (ok (+ (try! (fee-helper-a token-x token-y token-z factor-x factor-y)) (try! (fee-helper token-z token-w factor-z)))))\n(define-read-only (fee-helper-c\n (token-x principal) (token-y principal) (token-z principal) (token-w principal) (token-v principal)\n (factor-x uint) (factor-y uint) (factor-z uint) (factor-w uint))\n (ok (+ (try! (fee-helper-a token-x token-y token-z factor-x factor-y)) (try! (fee-helper-a token-z token-w token-v factor-z factor-w)))))\n(define-read-only (get-invariant (balance-x uint) (balance-y uint) (t uint))\n (if (>= t (get-switch-threshold))\n (+ (mul-down (- ONE_8 t) (+ balance-x balance-y)) (mul-down t (mul-down balance-x balance-y)))\n (+ (pow-down balance-x (- ONE_8 t)) (pow-down balance-y (- ONE_8 t)))))\n(define-read-only (get-max-ratio-limit)\n (contract-call? .amm-registry-v2-01 get-max-ratio-limit))\n(define-public (pause (new-paused bool))\n (begin\n (try! (is-dao-or-extension))\n (ok (var-set paused new-paused))))\n(define-public (set-start-block (token-x principal) (token-y principal) (factor uint) (new-start-block uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-start-block token-x token-y factor new-start-block))))\n(define-public (set-end-block (token-x principal) (token-y principal) (factor uint) (new-end-block uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-end-block token-x token-y factor new-end-block))))\n(define-public (set-max-in-ratio (token-x principal) (token-y principal) (factor uint) (new-max-in-ratio uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-max-in-ratio token-x token-y factor new-max-in-ratio))))\n(define-public (set-max-out-ratio (token-x principal) (token-y principal) (factor uint) (new-max-out-ratio uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-max-out-ratio token-x token-y factor new-max-out-ratio))))\n(define-public (set-oracle-enabled (token-x principal) (token-y principal) (factor uint) (enabled bool))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-oracle-enabled token-x token-y factor enabled))))\n(define-public (set-oracle-average (token-x principal) (token-y principal) (factor uint) (new-oracle-average uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-oracle-average token-x token-y factor new-oracle-average))))\n(define-public (set-threshold-x (token-x principal) (token-y principal) (factor uint) (new-threshold uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-threshold-x token-x token-y factor new-threshold))))\n(define-public (set-threshold-y (token-x principal) (token-y principal) (factor uint) (new-threshold uint))\n (let (\n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-threshold-y token-x token-y factor new-threshold))))\n(define-public (set-fee-rate-x (token-x principal) (token-y principal) (factor uint) (fee-rate-x uint))\n (let ( \n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-fee-rate-x token-x token-y factor fee-rate-x))))\n(define-public (set-fee-rate-y (token-x principal) (token-y principal) (factor uint) (fee-rate-y uint))\n (let ( \n (pool (try! (get-pool-details token-x token-y factor))))\n (asserts! (or (is-eq tx-sender (get pool-owner pool)) (is-ok (is-dao-or-extension))) ERR-NOT-AUTHORIZED)\n (as-contract (contract-call? .amm-registry-v2-01 set-fee-rate-y token-x token-y factor fee-rate-y))))\n(define-public (create-pool (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (pool-owner principal) (dx uint) (dy uint)) \n (begin\n (asserts! (not (is-blocklisted-or-default tx-sender)) ERR-BLOCKLISTED)\n (as-contract (try! (contract-call? .amm-registry-v2-01 create-pool token-x-trait token-y-trait factor pool-owner)))\n (add-to-position token-x-trait token-y-trait factor dx (some dy))))\n(define-public (add-to-position (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (dx uint) (max-dy (optional uint)))\n (let (\n (token-x (contract-of token-x-trait))\n (token-y (contract-of token-y-trait))\n (pool (try! (get-pool-details token-x token-y factor)))\n (balance-x (get balance-x pool))\n (balance-y (get balance-y pool))\n (total-supply (get total-supply pool))\n (add-data (try! (get-token-given-position token-x token-y factor dx max-dy)))\n (new-supply (get token add-data))\n (dy (get dy add-data))\n (pool-updated (merge pool { total-supply: (+ new-supply total-supply), balance-x: (+ balance-x dx), balance-y: (+ balance-y dy) }))\n (sender tx-sender))\n (asserts! (not (is-paused)) ERR-PAUSED)\n (asserts! (and (> dx u0) (> dy u0)) ERR-INVALID-LIQUIDITY)\n (asserts! (>= (default-to u340282366920938463463374607431768211455 max-dy) dy) ERR-EXCEEDS-MAX-SLIPPAGE)\n (try! (contract-call? token-x-trait transfer-fixed dx sender .amm-vault-v2-01 none))\n (try! (contract-call? token-y-trait transfer-fixed dy sender .amm-vault-v2-01 none))\n (as-contract (try! (contract-call? .amm-registry-v2-01 update-pool token-x token-y factor pool-updated)))\n (as-contract (try! (contract-call? .token-amm-pool-v2-01 mint-fixed (get pool-id pool) new-supply sender)))\n (print { object: "pool", action: "liquidity-added", data: pool-updated, dx: dx, dy: dy, token-x: token-x, token-y: token-y, sender: sender })\n (ok {supply: new-supply, dx: dx, dy: dy})))\n(define-public (reduce-position (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (percent uint))\n (let (\n (token-x (contract-of token-x-trait))\n (token-y (contract-of token-y-trait))\n (pool (try! (get-pool-details token-x token-y factor)))\n (balance-x (get balance-x pool))\n (balance-y (get balance-y pool))\n (total-shares (unwrap-panic (contract-call? .token-amm-pool-v2-01 get-balance-fixed (get pool-id pool) tx-sender)))\n (shares (if (is-eq percent ONE_8) total-shares (mul-down total-shares percent)))\n (total-supply (get total-supply pool))\n (reduce-data (try! (get-position-given-burn token-x token-y factor shares)))\n (dx (get dx reduce-data))\n (dy (get dy reduce-data))\n (pool-updated (merge pool { total-supply: (if (<= total-supply shares) u0 (- total-supply shares)), balance-x: (if (<= balance-x dx) u0 (- balance-x dx)), balance-y: (if (<= balance-y dy) u0 (- balance-y dy)) }))\n (sender tx-sender)) \n (asserts! (not (is-blocklisted-or-default tx-sender)) ERR-BLOCKLISTED) \n (asserts! (not (is-paused)) ERR-PAUSED) \n (asserts! (<= percent ONE_8) ERR-PERCENT-GREATER-THAN-ONE)\n (as-contract (try! (contract-call? .amm-vault-v2-01 transfer-ft-two token-x-trait dx token-y-trait dy sender)))\n (as-contract (try! (contract-call? .amm-registry-v2-01 update-pool token-x token-y factor pool-updated)))\n (as-contract (try! (contract-call? .token-amm-pool-v2-01 burn-fixed (get pool-id pool) shares sender)))\n (print { object: "pool", action: "liquidity-removed", data: pool-updated, dx: dx, dy: dy, token-x: token-x, token-y: token-y, sender: sender })\n (ok {dx: dx, dy: dy})))\n(define-public (swap-x-for-y (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (dx uint) (min-dy (optional uint)))\n (let (\n (token-x (contract-of token-x-trait))\n (token-y (contract-of token-y-trait))\n (pool (try! (get-pool-details token-x token-y factor)))\n (balance-x (get balance-x pool))\n (balance-y (get balance-y pool))\n (fee (mul-up dx (get fee-rate-x pool)))\n (dx-net-fees (if (<= dx fee) u0 (- dx fee)))\n (fee-rebate (mul-down fee (get fee-rebate pool)))\n (dy (try! (get-y-given-x token-x token-y factor dx-net-fees))) \n (pool-updated (merge pool {\n balance-x: (+ balance-x dx-net-fees fee-rebate),\n balance-y: (if (<= balance-y dy) u0 (- balance-y dy)),\n oracle-resilient: (if (get oracle-enabled pool) (try! (get-oracle-resilient token-x token-y factor)) u0)\n }))\n (sender tx-sender))\n (asserts! (not (is-blocklisted-or-default tx-sender)) ERR-BLOCKLISTED)\n (asserts! (not (is-paused)) ERR-PAUSED)\n (try! (check-pool-status token-x token-y factor))\n (asserts! (> dx u0) ERR-INVALID-LIQUIDITY)\n (asserts! (<= (div-down dy dx-net-fees) (get-price-internal balance-x balance-y factor)) ERR-INVALID-LIQUIDITY)\n (asserts! (<= (default-to u0 min-dy) dy) ERR-EXCEEDS-MAX-SLIPPAGE)\n (try! (contract-call? token-x-trait transfer-fixed dx sender .amm-vault-v2-01 none))\n (and (> dy u0) (as-contract (try! (contract-call? .amm-vault-v2-01 transfer-ft token-y-trait dy sender))))\n (as-contract (try! (contract-call? .amm-vault-v2-01 add-to-reserve token-x (- fee fee-rebate))))\n (as-contract (try! (contract-call? .amm-registry-v2-01 update-pool token-x token-y factor pool-updated)))\n (print { object: "pool", action: "swap-x-for-y", data: pool-updated, dx: dx, dy: dy, token-x: token-x, token-y: token-y, sender: sender, fee: fee, fee-rebate: fee-rebate })\n (ok {dx: dx-net-fees, dy: dy})))\n(define-public (swap-y-for-x (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (dy uint) (min-dx (optional uint)))\n (let (\n (token-x (contract-of token-x-trait))\n (token-y (contract-of token-y-trait))\n (pool (try! (get-pool-details token-x token-y factor)))\n (balance-x (get balance-x pool))\n (balance-y (get balance-y pool))\n (fee (mul-up dy (get fee-rate-y pool)))\n (dy-net-fees (if (<= dy fee) u0 (- dy fee)))\n (fee-rebate (mul-down fee (get fee-rebate pool)))\n (dx (try! (get-x-given-y token-x token-y factor dy-net-fees)))\n (pool-updated (merge pool {\n balance-x: (if (<= balance-x dx) u0 (- balance-x dx)),\n balance-y: (+ balance-y dy-net-fees fee-rebate),\n oracle-resilient: (if (get oracle-enabled pool) (try! (get-oracle-resilient token-x token-y factor)) u0)\n }))\n (sender tx-sender))\n (asserts! (not (is-blocklisted-or-default tx-sender)) ERR-BLOCKLISTED)\n (asserts! (not (is-paused)) ERR-PAUSED)\n (try! (check-pool-status token-x token-y factor))\n (asserts! (> dy u0) ERR-INVALID-LIQUIDITY) \n (asserts! (>= (div-down dy-net-fees dx) (get-price-internal balance-x balance-y factor)) ERR-INVALID-LIQUIDITY)\n (asserts! (<= (default-to u0 min-dx) dx) ERR-EXCEEDS-MAX-SLIPPAGE) \n (try! (contract-call? token-y-trait transfer-fixed dy sender .amm-vault-v2-01 none))\n (and (> dx u0) (as-contract (try! (contract-call? .amm-vault-v2-01 transfer-ft token-x-trait dx sender)))) \n (as-contract (try! (contract-call? .amm-vault-v2-01 add-to-reserve token-y (- fee fee-rebate))))\n (as-contract (try! (contract-call? .amm-registry-v2-01 update-pool token-x token-y factor pool-updated)))\n (print { object: "pool", action: "swap-y-for-x", data: pool-updated, dx: dx, dy: dy, token-x: token-x, token-y: token-y, sender: sender, fee: fee, fee-rebate: fee-rebate })\n (ok {dx: dx, dy: dy-net-fees})))\n(define-public (swap-helper (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (factor uint) (dx uint) (min-dy (optional uint)))\n (if (is-some (get-pool-exists (contract-of token-x-trait) (contract-of token-y-trait) factor))\n (ok (get dy (try! (swap-x-for-y token-x-trait token-y-trait factor dx min-dy))))\n (ok (get dx (try! (swap-y-for-x token-y-trait token-x-trait factor dx min-dy))))))\n(define-public (swap-helper-a (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (token-z-trait <ft-trait>) (factor-x uint) (factor-y uint) (dx uint) (min-dz (optional uint)))\n (swap-helper token-y-trait token-z-trait factor-y (try! (swap-helper token-x-trait token-y-trait factor-x dx none)) min-dz))\n(define-public (swap-helper-b\n (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (token-z-trait <ft-trait>) (token-w-trait <ft-trait>)\n (factor-x uint) (factor-y uint) (factor-z uint)\n (dx uint) (min-dw (optional uint)))\n (swap-helper token-z-trait token-w-trait factor-z (try! (swap-helper-a token-x-trait token-y-trait token-z-trait factor-x factor-y dx none)) min-dw))\n(define-public (swap-helper-c\n (token-x-trait <ft-trait>) (token-y-trait <ft-trait>) (token-z-trait <ft-trait>) (token-w-trait <ft-trait>) (token-v-trait <ft-trait>)\n (factor-x uint) (factor-y uint) (factor-z uint) (factor-w uint)\n (dx uint) (min-dv (optional uint)))\n (swap-helper-a token-z-trait token-w-trait token-v-trait factor-z factor-w (try! (swap-helper-a token-x-trait token-y-trait token-z-trait factor-x factor-y dx none)) min-dv))\n(define-private (get-price-internal (balance-x uint) (balance-y uint) (factor uint))\n (if (>= factor (get-switch-threshold))\n (div-down (+ (- ONE_8 factor) (mul-down factor balance-y)) (+ (- ONE_8 factor) (mul-down factor balance-x)))\n (pow-down (div-down balance-y balance-x) factor)))\n(define-private (get-y-given-x-internal (balance-x uint) (balance-y uint) (t uint) (dx uint))\n (if (>= t (get-switch-threshold))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))) \n (div-down (+ (mul-down t-comp dx) (mul-down t (mul-down dx balance-y))) (+ t-comp (mul-down t (+ balance-x dx)))))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-up ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (x-pow (pow-up balance-x t-comp))\n (y-pow (pow-up balance-y t-comp))\n (x-dx-pow (pow-down (+ balance-x dx) t-comp))\n (add-term (+ x-pow y-pow))\n (term (if (<= add-term x-dx-pow) u0 (- add-term x-dx-pow)))\n (final-term (pow-up term t-comp-num))) \n (if (<= balance-y final-term) u0 (- balance-y final-term)))))\n(define-private (get-x-given-y-internal (balance-x uint) (balance-y uint) (t uint) (dy uint))\n (if (>= t (get-switch-threshold))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))) \n (div-down (+ (mul-down t-comp dy) (mul-down t (mul-down dy balance-x))) (+ t-comp (mul-down t (+ balance-y dy))))) \n (let ( \n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-up ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (x-pow (pow-up balance-x t-comp))\n (y-pow (pow-up balance-y t-comp))\n (y-dy-pow (pow-down (+ balance-y dy) t-comp))\n (add-term (+ x-pow y-pow))\n (term (if (<= add-term y-dy-pow) u0 (- add-term y-dy-pow)))\n (final-term (pow-up term t-comp-num)))\n (if (<= balance-x final-term) u0 (- balance-x final-term)))))\n(define-private (get-y-in-given-x-out-internal (balance-x uint) (balance-y uint) (t uint) (dx uint)) \n (if (>= t (get-switch-threshold))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t))))\n (div-down (+ (mul-down t-comp dx) (mul-down t (mul-down dx balance-y))) (+ t-comp (mul-down t (- balance-x dx)))))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-down ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (x-pow (pow-down balance-x t-comp))\n (y-pow (pow-down balance-y t-comp))\n (x-dx-pow (pow-up (if (<= balance-x dx) u0 (- balance-x dx)) t-comp))\n (add-term (+ x-pow y-pow))\n (term (if (<= add-term x-dx-pow) u0 (- add-term x-dx-pow)))\n (final-term (pow-down term t-comp-num)))\n (if (<= final-term balance-y) u0 (- final-term balance-y)))))\n(define-private (get-x-in-given-y-out-internal (balance-x uint) (balance-y uint) (t uint) (dy uint))\n (if (>= t (get-switch-threshold))\n (let ( \n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t))))\n (div-down (+ (mul-down t-comp dy) (mul-down t (mul-down dy balance-x))) (+ t-comp (mul-down t (- balance-y dy)))))\n (let ( \n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-down ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (x-pow (pow-down balance-x t-comp))\n (y-pow (pow-down balance-y t-comp))\n (y-dy-pow (pow-up (if (<= balance-y dy) u0 (- balance-y dy)) t-comp))\n (add-term (+ x-pow y-pow))\n (term (if (<= add-term y-dy-pow) u0 (- add-term y-dy-pow)))\n (final-term (pow-down term t-comp-num)))\n (if (<= final-term balance-x) u0 (- final-term balance-x)))))\n(define-private (get-x-given-price-internal (balance-x uint) (balance-y uint) (t uint) (price uint))\n (if (>= t (get-switch-threshold))\n (let (\n (power (pow-down (div-down (get-price-internal balance-x balance-y t) price) u50000000)))\n (mul-down balance-x (if (<= power ONE_8) u0 (- power ONE_8)))) \n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-down ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (numer (+ ONE_8 (pow-down (get-price-internal balance-x balance-y t) (div-down t-comp t))))\n (denom (+ ONE_8 (pow-down price (div-down t-comp t))))\n (lead-term (pow-down (div-down numer denom) t-comp-num)))\n (if (<= lead-term ONE_8) u0 (mul-up balance-x (- lead-term ONE_8))))))\n(define-private (get-y-given-price-internal (balance-x uint) (balance-y uint) (t uint) (price uint))\n (if (>= t (get-switch-threshold))\n (let ( \n (power (pow-down (div-down price (get-price-internal balance-x balance-y t)) u50000000)))\n (mul-down balance-y (if (<= power ONE_8) u0 (- power ONE_8))))\n (let (\n (t-comp (if (<= ONE_8 t) u0 (- ONE_8 t)))\n (t-comp-num-uncapped (div-down ONE_8 t-comp))\n (t-comp-num (if (< t-comp-num-uncapped MILD_EXPONENT_BOUND) t-comp-num-uncapped MILD_EXPONENT_BOUND)) \n (numer (+ ONE_8 (pow-down (get-price-internal balance-x balance-y t) (div-down t-comp t))))\n (denom (+ ONE_8 (pow-down price (div-down t-comp t))))\n (lead-term (pow-down (div-down numer denom) t-comp-num)))\n (if (<= ONE_8 lead-term) u0 (mul-up balance-y (- ONE_8 lead-term))))))\n(define-private (get-token-given-position-internal (balance-x uint) (balance-y uint) (t uint) (total-supply uint) (dx uint) (dy uint))\n (if (is-eq total-supply u0)\n {token: (get-invariant dx dy t), dy: dy}\n {token: (div-down (mul-down total-supply dx) balance-x), dy: (div-down (mul-down balance-y dx) balance-x)}))\n(define-private (get-position-given-mint-internal (balance-x uint) (balance-y uint) (t uint) (total-supply uint) (token-amount uint))\n (let (\n (token-div-supply (div-down token-amount total-supply))\n )\n {dx: (mul-down balance-x token-div-supply), dy: (mul-down balance-y token-div-supply)}))\n(define-private (get-position-given-burn-internal (balance-x uint) (balance-y uint) (t uint) (total-supply uint) (token-amount uint))\n (get-position-given-mint-internal balance-x balance-y t total-supply token-amount))\n(define-constant ONE_8 u100000000) ;; 8 decimal places\n(define-constant MAX_POW_RELATIVE_ERROR u4)\n(define-private (mul-down (a uint) (b uint))\n (/ (* a b) ONE_8))\n(define-private (mul-up (a uint) (b uint))\n (let (\n (product (* a b))\n )\n (if (is-eq product u0) u0 (+ u1 (/ (- product u1) ONE_8)))))\n(define-private (div-down (a uint) (b uint))\n (if (is-eq a u0) u0 (/ (* a ONE_8) b)))\n(define-private (div-up (a uint) (b uint))\n (if (is-eq a u0) u0 (+ u1 (/ (- (* a ONE_8) u1) b))))\n(define-private (pow-down (a uint) (b uint))\n (let (\n (raw (unwrap-panic (pow-fixed a b)))\n (max-error (+ u1 (mul-up raw MAX_POW_RELATIVE_ERROR)))\n )\n (if (< raw max-error) u0 (- raw max-error))))\n(define-private (pow-up (a uint) (b uint))\n (let (\n (raw (unwrap-panic (pow-fixed a b)))\n (max-error (+ u1 (mul-up raw MAX_POW_RELATIVE_ERROR)))\n )\n (+ raw max-error)))\n(define-constant UNSIGNED_ONE_8 (pow 10 8))\n(define-constant MAX_NATURAL_EXPONENT (* 69 UNSIGNED_ONE_8))\n(define-constant MIN_NATURAL_EXPONENT (* -18 UNSIGNED_ONE_8))\n(define-constant MILD_EXPONENT_BOUND (/ (pow u2 u126) (to-uint UNSIGNED_ONE_8)))\n(define-constant x_a_list_no_deci (list {x_pre: 6400000000, a_pre: 62351490808116168829, use_deci: false} ))\n(define-constant x_a_list (list\n {x_pre: 3200000000, a_pre: 78962960182680695161, use_deci: true} ;; x2 = 2^5, a2 = e^(x2)\n {x_pre: 1600000000, a_pre: 888611052050787, use_deci: true} ;; x3 = 2^4, a3 = e^(x3)\n {x_pre: 800000000, a_pre: 298095798704, use_deci: true} ;; x4 = 2^3, a4 = e^(x4)\n {x_pre: 400000000, a_pre: 5459815003, use_deci: true} ;; x5 = 2^2, a5 = e^(x5)\n {x_pre: 200000000, a_pre: 738905610, use_deci: true} ;; x6 = 2^1, a6 = e^(x6)\n {x_pre: 100000000, a_pre: 271828183, use_deci: true} ;; x7 = 2^0, a7 = e^(x7)\n {x_pre: 50000000, a_pre: 164872127, use_deci: true} ;; x8 = 2^-1, a8 = e^(x8)\n {x_pre: 25000000, a_pre: 128402542, use_deci: true} ;; x9 = 2^-2, a9 = e^(x9)\n {x_pre: 12500000, a_pre: 113314845, use_deci: true} ;; x10 = 2^-3, a10 = e^(x10)\n {x_pre: 6250000, a_pre: 106449446, use_deci: true} ;; x11 = 2^-4, a11 = e^x(11)\n))\n(define-constant ERR-X-OUT-OF-BOUNDS (err u5009))\n(define-constant ERR-Y-OUT-OF-BOUNDS (err u5010))\n(define-constant ERR-PRODUCT-OUT-OF-BOUNDS (err u5011))\n(define-constant ERR-INVALID-EXPONENT (err u5012))\n(define-constant ERR-OUT-OF-BOUNDS (err u5013))\n(define-private (ln-priv (a int))\n (let (\n (a_sum_no_deci (fold accumulate_division x_a_list_no_deci {a: a, sum: 0}))\n (a_sum (fold accumulate_division x_a_list {a: (get a a_sum_no_deci), sum: (get sum a_sum_no_deci)}))\n (out_a (get a a_sum))\n (out_sum (get sum a_sum))\n (z (/ (* (- out_a UNSIGNED_ONE_8) UNSIGNED_ONE_8) (+ out_a UNSIGNED_ONE_8)))\n (z_squared (/ (* z z) UNSIGNED_ONE_8))\n (div_list (list 3 5 7 9 11))\n (num_sum_zsq (fold rolling_sum_div div_list {num: z, seriesSum: z, z_squared: z_squared}))\n (seriesSum (get seriesSum num_sum_zsq))\n )\n (+ out_sum (* seriesSum 2))))\n(define-private (accumulate_division (x_a_pre (tuple (x_pre int) (a_pre int) (use_deci bool))) (rolling_a_sum (tuple (a int) (sum int))))\n (let (\n (a_pre (get a_pre x_a_pre))\n (x_pre (get x_pre x_a_pre))\n (use_deci (get use_deci x_a_pre))\n (rolling_a (get a rolling_a_sum))\n (rolling_sum (get sum rolling_a_sum))\n )\n (if (>= rolling_a (if use_deci a_pre (* a_pre UNSIGNED_ONE_8)))\n {a: (/ (* rolling_a (if use_deci UNSIGNED_ONE_8 1)) a_pre), sum: (+ rolling_sum x_pre)}\n {a: rolling_a, sum: rolling_sum})))\n(define-private (rolling_sum_div (n int) (rolling (tuple (num int) (seriesSum int) (z_squared int))))\n (let (\n (rolling_num (get num rolling))\n (rolling_sum (get seriesSum rolling))\n (z_squared (get z_squared rolling))\n (next_num (/ (* rolling_num z_squared) UNSIGNED_ONE_8))\n (next_sum (+ rolling_sum (/ next_num n)))\n )\n {num: next_num, seriesSum: next_sum, z_squared: z_squared}))\n(define-private (pow-priv (x uint) (y uint))\n (let (\n (x-int (to-int x))\n (y-int (to-int y))\n (lnx (ln-priv x-int))\n (logx-times-y (/ (* lnx y-int) UNSIGNED_ONE_8)))\n (asserts! (and (<= MIN_NATURAL_EXPONENT logx-times-y) (<= logx-times-y MAX_NATURAL_EXPONENT)) ERR-PRODUCT-OUT-OF-BOUNDS)\n (ok (to-uint (try! (exp-fixed logx-times-y))))))\n(define-private (exp-pos (x int))\n (begin\n (asserts! (and (<= 0 x) (<= x MAX_NATURAL_EXPONENT)) ERR-INVALID-EXPONENT)\n (let (\n (x_product_no_deci (fold accumulate_product x_a_list_no_deci {x: x, product: 1}))\n (x_adj (get x x_product_no_deci))\n (firstAN (get product x_product_no_deci))\n (x_product (fold accumulate_product x_a_list {x: x_adj, product: UNSIGNED_ONE_8}))\n (product_out (get product x_product))\n (x_out (get x x_product))\n (seriesSum (+ UNSIGNED_ONE_8 x_out))\n (div_list (list 2 3 4 5 6 7 8 9 10 11 12))\n (term_sum_x (fold rolling_div_sum div_list {term: x_out, seriesSum: seriesSum, x: x_out}))\n (sum (get seriesSum term_sum_x)))\n (ok (* (/ (* product_out sum) UNSIGNED_ONE_8) firstAN)))))\n(define-private (accumulate_product (x_a_pre (tuple (x_pre int) (a_pre int) (use_deci bool))) (rolling_x_p (tuple (x int) (product int))))\n (let (\n (x_pre (get x_pre x_a_pre))\n (a_pre (get a_pre x_a_pre))\n (use_deci (get use_deci x_a_pre))\n (rolling_x (get x rolling_x_p))\n (rolling_product (get product rolling_x_p)))\n (if (>= rolling_x x_pre)\n {x: (- rolling_x x_pre), product: (/ (* rolling_product a_pre) (if use_deci UNSIGNED_ONE_8 1))}\n {x: rolling_x, product: rolling_product})))\n(define-private (rolling_div_sum (n int) (rolling (tuple (term int) (seriesSum int) (x int))))\n (let (\n (rolling_term (get term rolling))\n (rolling_sum (get seriesSum rolling))\n (x (get x rolling))\n (next_term (/ (/ (* rolling_term x) UNSIGNED_ONE_8) n))\n (next_sum (+ rolling_sum next_term))\n )\n {term: next_term, seriesSum: next_sum, x: x}))\n(define-private (pow-fixed (x uint) (y uint))\n (begin\n (asserts! (< x (pow u2 u127)) ERR-X-OUT-OF-BOUNDS)\n (asserts! (< y MILD_EXPONENT_BOUND) ERR-Y-OUT-OF-BOUNDS)\n (if (is-eq y u0)\n (ok (to-uint UNSIGNED_ONE_8))\n (if (is-eq x u0) (ok u0) (pow-priv x y)))))\n(define-private (exp-fixed (x int))\n (begin\n (asserts! (and (<= MIN_NATURAL_EXPONENT x) (<= x MAX_NATURAL_EXPONENT)) ERR-INVALID-EXPONENT)\n (if (< x 0) (ok (/ (* UNSIGNED_ONE_8 UNSIGNED_ONE_8) (try! (exp-pos (* -1 x))))) (exp-pos x))))\n(define-private (log-fixed (arg int) (base int))\n (let (\n (logBase (* (ln-priv base) UNSIGNED_ONE_8))\n (logArg (* (ln-priv arg) UNSIGNED_ONE_8)))\n (ok (/ (* logArg UNSIGNED_ONE_8) logBase))))\n(define-private (ln-fixed (a int))\n (begin\n (asserts! (> a 0) ERR-OUT-OF-BOUNDS)\n (if (< a UNSIGNED_ONE_8) (ok (- 0 (ln-priv (/ (* UNSIGNED_ONE_8 UNSIGNED_ONE_8) a)))) (ok (ln-priv a)))))
SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.wrapper-alex-v-2-1
https://api.hiro.so/extended/v1/contract/SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.wrapper-alex-v-2-1
\n;; wrapper-alex-v-2-1\n\n(use-trait ft-trait 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.trait-sip-010.sip-010-trait)\n\n(define-public (swap-helper\n (token-x-trait <ft-trait>) (token-y-trait <ft-trait>)\n (factor uint)\n (dx uint) (min-dy (optional uint))\n )\n (let (\n (swap-a (try! (contract-call?\n 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01 swap-helper\n token-x-trait\n token-y-trait\n factor\n dx min-dy)))\n )\n (ok swap-a)\n )\n)\n\n(define-public (swap-helper-a\n (token-x-trait <ft-trait>) (token-y-trait <ft-trait>)\n (token-z-trait <ft-trait>)\n (factor-x uint) (factor-y uint)\n (dx uint) (min-dz (optional uint))\n )\n (let (\n (swap-a (try! (contract-call?\n 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01 swap-helper-a\n token-x-trait token-y-trait\n token-z-trait\n factor-x factor-y\n dx min-dz)))\n )\n (ok swap-a)\n )\n)\n\n(define-public (swap-helper-b\n (token-x-trait <ft-trait>) (token-y-trait <ft-trait>)\n (token-z-trait <ft-trait>) (token-w-trait <ft-trait>)\n (factor-x uint) (factor-y uint) (factor-z uint)\n (dx uint) (min-dw (optional uint))\n )\n (let (\n (swap-a (try! (contract-call?\n 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01 swap-helper-b\n token-x-trait token-y-trait\n token-z-trait token-w-trait\n factor-x factor-y factor-z\n dx min-dw)))\n )\n (ok swap-a)\n )\n)\n\n(define-public (swap-helper-c\n (token-x-trait <ft-trait>) (token-y-trait <ft-trait>)\n (token-z-trait <ft-trait>) (token-w-trait <ft-trait>)\n (token-v-trait <ft-trait>)\n (factor-x uint) (factor-y uint) (factor-z uint) (factor-w uint)\n (dx uint) (min-dv (optional uint))\n )\n (let (\n (swap-a (try! (contract-call?\n 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01 swap-helper-c\n token-x-trait token-y-trait\n token-z-trait token-w-trait\n token-v-trait\n factor-x factor-y factor-z factor-w\n dx min-dv)))\n )\n (ok swap-a)\n )\n)\n
SP2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D96YPGZF.BNS-V2
https://api.hiro.so/extended/v1/contract/SP2QEZ06AGJ3RKJPBV14SY1V5BBFNAW33D96YPGZF.BNS-V2
;; title: BNS-V2\n;; version: V-2\n;; summary: Updated BNS contract, handles the creation of new namespaces and new names on each namespace\n\n;; traits\n;; (new) Import SIP-09 NFT trait \n(impl-trait 'SP2PABAF9FTAJYNFZH93XENAJ8FVY99RRM50D2JG9.nft-trait.nft-trait)\n;; (new) Import a custom commission trait for handling commissions for NFT marketplaces functions\n(use-trait commission-trait .commission-trait.commission)\n\n;; token definition\n;; (new) Define the non-fungible token (NFT) called BNS-V2 with unique identifiers as unsigned integers\n(define-non-fungible-token BNS-V2 uint)\n;; Time-to-live (TTL) constants for namespace preorders and name preorders, and the duration for name grace period.\n;; The TTL for namespace and names preorders. (1 day)\n(define-constant PREORDER-CLAIMABILITY-TTL u144) \n;; The duration after revealing a namespace within which it must be launched. (1 year)\n(define-constant NAMESPACE-LAUNCHABILITY-TTL u52595) \n;; The grace period duration for name renewals post-expiration. (34 days)\n(define-constant NAME-GRACE-PERIOD-DURATION u5000) \n;; (new) The length of the hash should match this\n(define-constant HASH160LEN u20)\n;; Defines the price tiers for namespaces based on their lengths.\n(define-constant NAMESPACE-PRICE-TIERS (list\n u640000000000\n u64000000000 u64000000000 \n u6400000000 u6400000000 u6400000000 u6400000000 \n u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000)\n)\n\n;; Only authorized caller to flip the switch and update URI\n(define-constant DEPLOYER tx-sender)\n\n;; (new) Var to store the token URI, allowing for metadata association with the NFT\n(define-data-var token-uri (string-ascii 256) "ipfs://QmUQY1aZ799SPRaNBFqeCvvmZ4fTQfZvWHauRvHAukyQDB")\n\n(define-public (update-token-uri (new-token-uri (string-ascii 256)))\n (ok \n (begin \n (asserts! (is-eq contract-caller DEPLOYER) ERR-NOT-AUTHORIZED) \n (var-set token-uri new-token-uri)\n )\n )\n)\n\n(define-data-var contract-uri (string-ascii 256) "ipfs://QmWKTZEMQNWngp23i7bgPzkineYC9LDvcxYkwNyVQVoH8y")\n\n(define-public (update-contract-uri (new-contract-uri (string-ascii 256)))\n (ok \n (begin \n (asserts! (is-eq contract-caller DEPLOYER) ERR-NOT-AUTHORIZED) \n (var-set token-uri new-contract-uri)\n )\n )\n)\n\n;; errors\n(define-constant ERR-UNWRAP (err u101))\n(define-constant ERR-NOT-AUTHORIZED (err u102))\n(define-constant ERR-NOT-LISTED (err u103))\n(define-constant ERR-WRONG-COMMISSION (err u104))\n(define-constant ERR-LISTED (err u105))\n(define-constant ERR-NO-NAME (err u106))\n(define-constant ERR-HASH-MALFORMED (err u107))\n(define-constant ERR-STX-BURNT-INSUFFICIENT (err u108))\n(define-constant ERR-PREORDER-NOT-FOUND (err u109))\n(define-constant ERR-CHARSET-INVALID (err u110))\n(define-constant ERR-NAMESPACE-ALREADY-EXISTS (err u111))\n(define-constant ERR-PREORDER-CLAIMABILITY-EXPIRED (err u112))\n(define-constant ERR-NAMESPACE-NOT-FOUND (err u113))\n(define-constant ERR-OPERATION-UNAUTHORIZED (err u114))\n(define-constant ERR-NAMESPACE-ALREADY-LAUNCHED (err u115))\n(define-constant ERR-NAMESPACE-PREORDER-LAUNCHABILITY-EXPIRED (err u116))\n(define-constant ERR-NAMESPACE-NOT-LAUNCHED (err u117))\n(define-constant ERR-NAME-NOT-AVAILABLE (err u118))\n(define-constant ERR-NAMESPACE-BLANK (err u119))\n(define-constant ERR-NAME-BLANK (err u120))\n(define-constant ERR-NAME-PREORDERED-BEFORE-NAMESPACE-LAUNCH (err u121))\n(define-constant ERR-NAMESPACE-HAS-MANAGER (err u122))\n(define-constant ERR-OVERFLOW (err u123))\n(define-constant ERR-NO-NAMESPACE-MANAGER (err u124))\n(define-constant ERR-FAST-MINTED-BEFORE (err u125))\n(define-constant ERR-PREORDERED-BEFORE (err u126))\n(define-constant ERR-NAME-NOT-CLAIMABLE-YET (err u127))\n(define-constant ERR-IMPORTED-BEFORE (err u128))\n(define-constant ERR-LIFETIME-EQUAL-0 (err u129))\n(define-constant ERR-MIGRATION-IN-PROGRESS (err u130))\n(define-constant ERR-NO-PRIMARY-NAME (err u131))\n\n;; variables\n;; (new) Variable to see if migration is complete\n(define-data-var migration-complete bool false)\n\n;; (new) Counter to keep track of the last minted NFT ID, ensuring unique identifiers\n(define-data-var bns-index uint u0)\n\n;; maps\n;; (new) Map to track market listings, associating NFT IDs with price and commission details\n(define-map market uint {price: uint, commission: principal})\n\n;; (new) Define a map to link NFT IDs to their respective names and namespaces.\n(define-map index-to-name uint \n {\n name: (buff 48), namespace: (buff 20)\n } \n)\n;; (new) Define a map to link names and namespaces to their respective NFT IDs.\n(define-map name-to-index \n {\n name: (buff 48), namespace: (buff 20)\n } \n uint\n)\n\n;; (updated) Contains detailed properties of names, including registration and importation times\n(define-map name-properties\n { name: (buff 48), namespace: (buff 20) }\n {\n registered-at: (optional uint),\n imported-at: (optional uint),\n ;; The fqn used to make the earliest preorder at any given point\n hashed-salted-fqn-preorder: (optional (buff 20)),\n ;; Added this field in name-properties to know exactly who has the earliest preorder at any given point\n preordered-by: (optional principal),\n renewal-height: uint,\n stx-burn: uint,\n owner: principal,\n }\n)\n\n;; (update) Stores properties of namespaces, including their import principals, reveal and launch times, and pricing functions.\n(define-map namespaces (buff 20)\n { \n namespace-manager: (optional principal),\n manager-transferable: bool,\n manager-frozen: bool,\n namespace-import: principal,\n revealed-at: uint,\n launched-at: (optional uint),\n lifetime: uint,\n can-update-price-function: bool,\n price-function: \n {\n buckets: (list 16 uint),\n base: uint, \n coeff: uint, \n nonalpha-discount: uint, \n no-vowel-discount: uint\n }\n }\n)\n\n;; Records namespace preorder transactions with their creation times, and STX burned.\n(define-map namespace-preorders\n { hashed-salted-namespace: (buff 20), buyer: principal }\n { created-at: uint, stx-burned: uint, claimed: bool}\n)\n\n;; Tracks preorders, to avoid attacks\n(define-map namespace-single-preorder (buff 20) bool)\n\n;; Tracks preorders, to avoid attacks\n(define-map name-single-preorder (buff 20) bool)\n\n;; Tracks preorders for names, including their creation times, and STX burned.\n(define-map name-preorders\n { hashed-salted-fqn: (buff 20), buyer: principal }\n { created-at: uint, stx-burned: uint, claimed: bool}\n)\n\n;; It maps a user's principal to the ID of their primary name.\n(define-map primary-name principal uint)\n\n;; read-only\n;; @desc (new) SIP-09 compliant function to get the last minted token's ID\n(define-read-only (get-last-token-id)\n ;; Returns the current value of bns-index variable, which tracks the last token ID\n (ok (var-get bns-index))\n)\n\n(define-read-only (get-renewal-height (id uint))\n (let \n (\n (name-namespace (unwrap! (get-bns-from-id id) ERR-NO-NAME))\n (namespace-props (unwrap! (map-get? namespaces (get namespace name-namespace)) ERR-NAMESPACE-NOT-FOUND))\n (name-props (unwrap! (map-get? name-properties name-namespace) ERR-NO-NAME))\n (renewal-height (get renewal-height name-props))\n (namespace-lifetime (get lifetime namespace-props))\n )\n ;; Check if the namespace requires renewals\n (asserts! (not (is-eq namespace-lifetime u0)) ERR-LIFETIME-EQUAL-0) \n ;; If the check passes then check the renewal-height of the name\n (ok \n (if (is-eq renewal-height u0)\n ;; If it is true then it means it was imported so return the namespace launch blockheight + lifetime\n (+ (unwrap! (get launched-at namespace-props) ERR-NAMESPACE-NOT-LAUNCHED) namespace-lifetime) \n renewal-height\n )\n )\n )\n)\n\n(define-read-only (can-resolve-name (namespace (buff 20)) (name (buff 48)))\n (let \n (\n (name-id (unwrap! (get-id-from-bns name namespace) ERR-NO-NAME))\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n (name-props (unwrap! (map-get? name-properties {name: name, namespace: namespace}) ERR-NO-NAME))\n (renewal-height (get renewal-height name-props))\n (namespace-lifetime (get lifetime namespace-props))\n )\n ;; Check if the name can resolve\n (ok \n (if (is-eq u0 namespace-lifetime)\n ;; If true it means that the name is in a managed namespace or the namespace does not require renewals\n {renewal: u0, owner: (get owner name-props)}\n ;; If false then calculate renewal-height\n {renewal: (try! (get-renewal-height name-id)), owner: (get owner name-props)}\n )\n )\n )\n)\n\n;; @desc (new) SIP-09 compliant function to get token URI\n(define-read-only (get-token-uri (id uint))\n ;; Returns a predefined set URI for the token metadata\n (ok (some (var-get token-uri)))\n)\n\n(define-read-only (get-contract-uri)\n ;; Returns a predefined set URI for the contract metadata\n (ok (some (var-get contract-uri)))\n)\n\n;; @desc (new) SIP-09 compliant function to get the owner of a specific token by its ID\n(define-read-only (get-owner (id uint))\n ;; Check and return the owner of the specified NFT\n (ok (nft-get-owner? BNS-V2 id))\n)\n\n;; @desc (new) New get owner function\n(define-read-only (get-owner-name (name (buff 48)) (namespace (buff 20)))\n ;; Check and return the owner of the specified NFT\n (ok (nft-get-owner? BNS-V2 (unwrap! (get-id-from-bns name namespace) ERR-NO-NAME)))\n)\n\n;; Read-only function `get-namespace-price` calculates the registration price for a namespace based on its length.\n;; @params:\n ;; namespace (buff 20): The namespace for which the price is being calculated.\n(define-read-only (get-namespace-price (namespace (buff 20)))\n (let \n (\n ;; Calculate the length of the namespace.\n (namespace-len (len namespace))\n )\n ;; Ensure the namespace is not blank, its length is greater than 0.\n (asserts! (> namespace-len u0) ERR-NAMESPACE-BLANK)\n ;; Retrieve the price for the namespace based on its length from the NAMESPACE-PRICE-TIERS list.\n ;; The price tier is determined by the minimum of 7 or the namespace length minus one.\n (ok (unwrap! (element-at? NAMESPACE-PRICE-TIERS (min u7 (- namespace-len u1))) ERR-UNWRAP))\n )\n)\n\n;; Read-only function `get-name-price` calculates the registration price for a name based on the price buckets of the namespace\n;; @params:\n ;; namespace (buff 20): The namespace for which the price is being calculated.\n ;; name (buff 48): The name for which the price is being calculated.\n(define-read-only (get-name-price (namespace (buff 20)) (name (buff 48)))\n (let \n (\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n )\n (ok (compute-name-price name (get price-function namespace-props)))\n )\n)\n\n;; Read-only function `can-namespace-be-registered` checks if a namespace is available for registration.\n;; @params:\n ;; namespace (buff 20): The namespace being checked for availability.\n(define-read-only (can-namespace-be-registered (namespace (buff 20)))\n ;; Returns the result of `is-namespace-available` directly, indicating if the namespace can be registered.\n (ok (is-namespace-available namespace))\n)\n\n;; Read-only function `get-namespace-properties` for retrieving properties of a specific namespace.\n;; @params:\n ;; namespace (buff 20): The namespace whose properties are being queried.\n(define-read-only (get-namespace-properties (namespace (buff 20)))\n (let \n (\n ;; Fetch the properties of the specified namespace from the `namespaces` map.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n )\n ;; Returns the namespace along with its associated properties.\n (ok { namespace: namespace, properties: namespace-props })\n )\n)\n\n;; Read only function to get name properties\n(define-read-only (get-bns-info (name (buff 48)) (namespace (buff 20)))\n (map-get? name-properties {name: name, namespace: namespace})\n)\n\n;; (new) Defines a read-only function to fetch the unique ID of a BNS name given its name and the namespace it belongs to.\n(define-read-only (get-id-from-bns (name (buff 48)) (namespace (buff 20))) \n ;; Attempts to retrieve the ID from the 'name-to-index' map using the provided name and namespace as the key.\n (map-get? name-to-index {name: name, namespace: namespace})\n)\n\n;; (new) Defines a read-only function to fetch the BNS name and the namespace given a unique ID.\n(define-read-only (get-bns-from-id (id uint)) \n ;; Attempts to retrieve the name and namespace from the 'index-to-name' map using the provided id as the key.\n (map-get? index-to-name id)\n)\n\n;; (new) Fetcher for primary name\n(define-read-only (get-primary-name (owner principal))\n (map-get? primary-name owner)\n)\n\n;; (new) Fetcher for primary name returns name and namespace\n(define-read-only (get-primary (owner principal))\n (ok (get-bns-from-id (unwrap! (map-get? primary-name owner) ERR-NO-PRIMARY-NAME)))\n)\n\n;; public functions\n;; @desc (new) SIP-09 compliant function to transfer a token from one owner to another.\n;; @param id: ID of the NFT being transferred.\n;; @param owner: Principal of the current owner of the NFT.\n;; @param recipient: Principal of the recipient of the NFT.\n(define-public (transfer (id uint) (owner principal) (recipient principal))\n (let \n (\n ;; Get the name and namespace of the NFT.\n (name-and-namespace (unwrap! (get-bns-from-id id) ERR-NO-NAME))\n (namespace (get namespace name-and-namespace))\n (name (get name name-and-namespace))\n ;; Get namespace properties and manager.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n (manager-transfers (get manager-transferable namespace-props))\n ;; Get name properties and owner.\n (name-props (unwrap! (map-get? name-properties name-and-namespace) ERR-NO-NAME))\n (registered-at-value (get registered-at name-props))\n (nft-current-owner (unwrap! (nft-get-owner? BNS-V2 id) ERR-NO-NAME))\n )\n ;; First check if the name was registered\n (match registered-at-value\n is-registered\n ;; If it was registered, check if registered-at is lower than current blockheight\n ;; This check works to make sure that if a name is fast-claimed they have to wait 1 block to transfer it\n (asserts! (< is-registered burn-block-height) ERR-OPERATION-UNAUTHORIZED)\n ;; If it is not registered then continue\n true \n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Check that the namespace is launched\n (asserts! (is-some (get launched-at namespace-props)) ERR-NAMESPACE-NOT-LAUNCHED)\n ;; Check owner and recipient is not the same\n (asserts! (not (is-eq nft-current-owner recipient)) ERR-OPERATION-UNAUTHORIZED)\n ;; We only need to check if manager transfers are true or false, if true then they have to do transfers through the manager contract that calls into mng-transfer, if false then they can call into this function\n (asserts! (not manager-transfers) ERR-NOT-AUTHORIZED)\n ;; Check contract-caller\n (asserts! (is-eq contract-caller nft-current-owner) ERR-NOT-AUTHORIZED)\n ;; Check if in fact the owner is-eq to nft-current-owner\n (asserts! (is-eq owner nft-current-owner) ERR-NOT-AUTHORIZED)\n ;; Ensures the NFT is not currently listed in the market.\n (asserts! (is-none (map-get? market id)) ERR-LISTED)\n ;; Update the name properties with the new owner\n (map-set name-properties name-and-namespace (merge name-props {owner: recipient}))\n ;; Update primary name if needed for owner\n (update-primary-name-owner id owner)\n ;; Update primary name if needed for recipient\n (update-primary-name-recipient id recipient)\n ;; Execute the NFT transfer.\n (try! (nft-transfer? BNS-V2 id nft-current-owner recipient))\n (print \n {\n topic: "transfer-name", \n owner: recipient, \n name: {name: name, namespace: namespace}, \n id: id,\n properties: (map-get? name-properties {name: name, namespace: namespace})\n }\n )\n (ok true)\n )\n)\n\n;; @desc (new) manager function to be called by managed namespaces that allows manager transfers.\n;; @param id: ID of the NFT being transferred.\n;; @param owner: Principal of the current owner of the NFT.\n;; @param recipient: Principal of the recipient of the NFT.\n(define-public (mng-transfer (id uint) (owner principal) (recipient principal))\n (let \n (\n ;; Get the name and namespace of the NFT.\n (name-and-namespace (unwrap! (get-bns-from-id id) ERR-NO-NAME))\n (namespace (get namespace name-and-namespace))\n (name (get name name-and-namespace))\n ;; Get namespace properties and manager.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n (manager-transfers (get manager-transferable namespace-props))\n (manager (get namespace-manager namespace-props))\n ;; Get name properties and owner.\n (name-props (unwrap! (map-get? name-properties name-and-namespace) ERR-NO-NAME))\n (registered-at-value (get registered-at name-props))\n (nft-current-owner (unwrap! (nft-get-owner? BNS-V2 id) ERR-NO-NAME))\n )\n ;; First check if the name was registered\n (match registered-at-value\n is-registered\n ;; If it was registered, check if registered-at is lower than current blockheight\n ;; This check works to make sure that if a name is fast-claimed they have to wait 1 block to transfer it\n (asserts! (< is-registered burn-block-height) ERR-OPERATION-UNAUTHORIZED)\n ;; If it is not registered then continue\n true \n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Check that the namespace is launched\n (asserts! (is-some (get launched-at namespace-props)) ERR-NAMESPACE-NOT-LAUNCHED)\n ;; Check owner and recipient is not the same\n (asserts! (not (is-eq nft-current-owner recipient)) ERR-OPERATION-UNAUTHORIZED)\n ;; We only need to check if manager transfers are true or false, if true then continue, if false then they can call into `transfer` function\n (asserts! manager-transfers ERR-NOT-AUTHORIZED)\n ;; Check contract-caller, we unwrap-panic because if manager-transfers is true then there has to be a manager\n (asserts! (is-eq contract-caller (unwrap-panic manager)) ERR-NOT-AUTHORIZED)\n ;; Check if in fact the owner is-eq to nft-current-owner\n (asserts! (is-eq owner nft-current-owner) ERR-NOT-AUTHORIZED)\n ;; Ensures the NFT is not currently listed in the market.\n (asserts! (is-none (map-get? market id)) ERR-LISTED)\n ;; Update primary name if needed for owner\n (update-primary-name-owner id owner)\n ;; Update primary name if needed for recipient\n (update-primary-name-recipient id recipient)\n ;; Update the name properties with the new owner\n (map-set name-properties name-and-namespace (merge name-props {owner: recipient}))\n ;; Execute the NFT transfer.\n (try! (nft-transfer? BNS-V2 id nft-current-owner recipient))\n (print \n {\n topic: "transfer-name", \n owner: recipient, \n name: {name: name, namespace: namespace}, \n id: id,\n properties: (map-get? name-properties {name: name, namespace: namespace})\n }\n )\n (ok true)\n )\n)\n\n;; @desc (new) Function to list an NFT for sale.\n;; @param id: ID of the NFT being listed.\n;; @param price: Listing price.\n;; @param comm-trait: Address of the commission-trait.\n(define-public (list-in-ustx (id uint) (price uint) (comm-trait <commission-trait>))\n (let\n (\n ;; Get the name and namespace of the NFT.\n (name-and-namespace (unwrap! (map-get? index-to-name id) ERR-NO-NAME))\n (namespace (get namespace name-and-namespace))\n ;; Get namespace properties and manager.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n (namespace-manager (get namespace-manager namespace-props))\n ;; Get name properties and registered-at value.\n (name-props (unwrap! (map-get? name-properties name-and-namespace) ERR-NO-NAME))\n (registered-at-value (get registered-at name-props))\n ;; Creates a listing record with price and commission details\n (listing {price: price, commission: (contract-of comm-trait)})\n )\n ;; Checks if the name was registered\n (match registered-at-value\n is-registered\n ;; If it was registered, check if registered-at is lower than current blockheight\n ;; Same as transfers, this check works to make sure that if a name is fast-claimed they have to wait 1 block to list it\n (asserts! (< is-registered burn-block-height) ERR-OPERATION-UNAUTHORIZED)\n ;; If it is not registered then continue\n true \n )\n ;; Check if there is a namespace manager\n (match namespace-manager \n manager \n ;; If there is then check that the contract-caller is the manager\n (asserts! (is-eq manager contract-caller) ERR-NOT-AUTHORIZED)\n ;; If there isn't assert that the owner is the contract-caller\n (asserts! (is-eq (some contract-caller) (nft-get-owner? BNS-V2 id)) ERR-NOT-AUTHORIZED)\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Updates the market map with the new listing details\n (map-set market id listing)\n ;; Prints listing details\n (ok (print (merge listing {a: "list-in-ustx", id: id})))\n )\n)\n\n;; @desc (new) Function to remove an NFT listing from the market.\n;; @param id: ID of the NFT being unlisted.\n(define-public (unlist-in-ustx (id uint))\n (let\n (\n ;; Get the name and namespace of the NFT.\n (name-and-namespace (unwrap! (map-get? index-to-name id) ERR-NO-NAME))\n (namespace (get namespace name-and-namespace))\n ;; Verify if the NFT is listed in the market.\n (market-map (unwrap! (map-get? market id) ERR-NOT-LISTED))\n ;; Get namespace properties and manager.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n (namespace-manager (get namespace-manager namespace-props))\n )\n ;; Check if there is a namespace manager\n (match namespace-manager \n manager \n ;; If there is then check that the contract-caller is the manager\n (asserts! (is-eq manager contract-caller) ERR-NOT-AUTHORIZED)\n ;; If there isn't assert that the owner is the contract-caller\n (asserts! (is-eq (some contract-caller) (nft-get-owner? BNS-V2 id)) ERR-NOT-AUTHORIZED)\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Deletes the listing from the market map\n (map-delete market id)\n ;; Prints unlisting details\n (ok (print {a: "unlist-in-ustx", id: id}))\n )\n) \n\n;; @desc (new) Function to buy an NFT listed for sale, transferring ownership and handling commission.\n;; @param id: ID of the NFT being purchased.\n;; @param comm-trait: Address of the commission-trait.\n(define-public (buy-in-ustx (id uint) (comm-trait <commission-trait>))\n (let\n (\n ;; Retrieves current owner and listing details\n (owner (unwrap! (nft-get-owner? BNS-V2 id) ERR-NO-NAME))\n (listing (unwrap! (map-get? market id) ERR-NOT-LISTED))\n (price (get price listing))\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Verifies the commission details match the listing\n (asserts! (is-eq (contract-of comm-trait) (get commission listing)) ERR-WRONG-COMMISSION)\n ;; Transfers STX from buyer to seller\n (try! (stx-transfer? price contract-caller owner))\n ;; Handle commission payment\n (try! (contract-call? comm-trait pay id price))\n ;; Transfers the NFT to the buyer\n ;; This function differs from the `transfer` method by not checking who the contract-caller is, otherwise trasnfers would never be executed\n (try! (purchase-transfer id owner contract-caller))\n ;; Removes the listing from the market map\n (map-delete market id)\n ;; Prints purchase details\n (ok (print {a: "buy-in-ustx", id: id}))\n )\n)\n\n;; @desc (new) Sets the primary name for the caller to a specific BNS name they own.\n;; @param primary-name-id: ID of the name to be set as primary.\n(define-public (set-primary-name (primary-name-id uint))\n (begin \n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Verify the contract-caller is the owner of the name.\n (asserts! (is-eq (unwrap! (nft-get-owner? BNS-V2 primary-name-id) ERR-NO-NAME) contract-caller) ERR-NOT-AUTHORIZED)\n ;; Update the contract-caller's primary name.\n (map-set primary-name contract-caller primary-name-id)\n ;; Return true upon successful execution.\n (ok true)\n )\n)\n\n;; @desc (new) Defines a public function to burn an NFT, under managed namespaces.\n;; @param id: ID of the NFT to be burned.\n(define-public (mng-burn (id uint)) \n (let \n (\n ;; Get the name details associated with the given ID.\n (name-and-namespace (unwrap! (get-bns-from-id id) ERR-NO-NAME))\n ;; Get the owner of the name.\n (owner (unwrap! (nft-get-owner? BNS-V2 id) ERR-UNWRAP)) \n ) \n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the caller is the current namespace manager.\n (asserts! (is-eq contract-caller (unwrap! (get namespace-manager (unwrap! (map-get? namespaces (get namespace name-and-namespace)) ERR-NAMESPACE-NOT-FOUND)) ERR-NO-NAMESPACE-MANAGER)) ERR-NOT-AUTHORIZED)\n ;; Unlist the NFT if it is listed.\n (match (map-get? market id)\n listed-name \n (map-delete market id) \n true\n )\n ;; Update primary name if needed for the owner of the name\n (update-primary-name-owner id owner)\n ;; Delete the name from all maps:\n ;; Remove the name-to-index.\n (map-delete name-to-index name-and-namespace)\n ;; Remove the index-to-name.\n (map-delete index-to-name id)\n ;; Remove the name-properties.\n (map-delete name-properties name-and-namespace)\n ;; Executes the burn operation for the specified NFT.\n (try! (nft-burn? BNS-V2 id (unwrap! (nft-get-owner? BNS-V2 id) ERR-UNWRAP)))\n (print \n {\n topic: "burn-name", \n owner: "", \n name: {name: (get name name-and-namespace), namespace: (get namespace name-and-namespace)}, \n id: id\n }\n )\n (ok true)\n )\n)\n\n;; @desc (new) Transfers the management role of a specific namespace to a new principal.\n;; @param new-manager: Principal of the new manager.\n;; @param namespace: Buffer of the namespace.\n(define-public (mng-manager-transfer (new-manager (optional principal)) (namespace (buff 20)))\n (let \n (\n ;; Retrieve namespace properties and current manager.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS) \n ;; Ensure the caller is the current namespace manager.\n (asserts! (is-eq contract-caller (unwrap! (get namespace-manager namespace-props) ERR-NO-NAMESPACE-MANAGER)) ERR-NOT-AUTHORIZED)\n ;; Ensure manager can be changed\n (asserts! (not (get manager-frozen namespace-props)) ERR-NOT-AUTHORIZED)\n ;; Update the namespace manager to the new manager.\n (map-set namespaces namespace \n (merge \n namespace-props \n {namespace-manager: new-manager}\n )\n )\n (print { namespace: namespace, status: "transfer-manager", properties: (map-get? namespaces namespace) })\n (ok true)\n )\n)\n\n;; @desc (new) freezes the ability to make manager transfers\n;; @param namespace: Buffer of the namespace.\n(define-public (freeze-manager (namespace (buff 20)))\n (let \n (\n ;; Retrieve namespace properties and current manager.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the caller is the current namespace manager.\n (asserts! (is-eq contract-caller (unwrap! (get namespace-manager namespace-props) ERR-NO-NAMESPACE-MANAGER)) ERR-NOT-AUTHORIZED)\n ;; Update the namespace manager to the new manager.\n (map-set namespaces namespace \n (merge \n namespace-props \n {manager-frozen: true}\n )\n )\n (print { namespace: namespace, status: "freeze-manager", properties: (map-get? namespaces namespace) })\n (ok true)\n )\n)\n\n;;;; NAMESPACES\n;; @desc Public function `namespace-preorder` initiates the registration process for a namespace by sending a transaction with a salted hash of the namespace.\n;; This transaction burns the registration fee as a commitment.\n;; @params: hashed-salted-namespace (buff 20): The hashed and salted namespace being preordered.\n;; @params: stx-to-burn (uint): The amount of STX tokens to be burned as part of the preorder process.\n(define-public (namespace-preorder (hashed-salted-namespace (buff 20)) (stx-to-burn uint))\n (begin\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS) \n ;; Validate that the hashed-salted-namespace is exactly 20 bytes long.\n (asserts! (is-eq (len hashed-salted-namespace) HASH160LEN) ERR-HASH-MALFORMED)\n ;; Check if the same hashed-salted-fqn has been used before\n (asserts! (is-none (map-get? namespace-single-preorder hashed-salted-namespace)) ERR-PREORDERED-BEFORE)\n ;; Confirm that the STX amount to be burned is positive\n (asserts! (> stx-to-burn u0) ERR-STX-BURNT-INSUFFICIENT)\n ;; Execute the token burn operation.\n (try! (stx-burn? stx-to-burn contract-caller))\n ;; Record the preorder details in the `namespace-preorders` map\n (map-set namespace-preorders\n { hashed-salted-namespace: hashed-salted-namespace, buyer: contract-caller }\n { created-at: burn-block-height, stx-burned: stx-to-burn, claimed: false }\n )\n ;; Sets the map with just the hashed-salted-namespace as the key\n (map-set namespace-single-preorder hashed-salted-namespace true)\n ;; Return the block height at which the preorder claimability expires.\n (ok (+ burn-block-height PREORDER-CLAIMABILITY-TTL))\n )\n)\n\n;; @desc Public function `namespace-reveal` completes the second step in the namespace registration process.\n;; It associates the revealed namespace with its corresponding preorder, establishes the namespace's pricing function, and sets its lifetime and ownership details.\n;; @param: namespace (buff 20): The namespace being revealed.\n;; @param: namespace-salt (buff 20): The salt used during the preorder to generate a unique hash.\n;; @param: p-func-base, p-func-coeff, p-func-b1 to p-func-b16: Parameters defining the price function for registering names within this namespace.\n;; @param: p-func-non-alpha-discount (uint): Discount applied to names with non-alphabetic characters.\n;; @param: p-func-no-vowel-discount (uint): Discount applied to names without vowels.\n;; @param: lifetime (uint): Duration that names within this namespace are valid before needing renewal.\n;; @param: namespace-import (principal): The principal authorized to import names into this namespace.\n;; @param: namespace-manager (optional principal): The principal authorized to manage the namespace.\n(define-public (namespace-reveal \n (namespace (buff 20)) \n (namespace-salt (buff 20)) \n (p-func-base uint) \n (p-func-coeff uint) \n (p-func-b1 uint) \n (p-func-b2 uint) \n (p-func-b3 uint) \n (p-func-b4 uint) \n (p-func-b5 uint) \n (p-func-b6 uint) \n (p-func-b7 uint) \n (p-func-b8 uint) \n (p-func-b9 uint) \n (p-func-b10 uint) \n (p-func-b11 uint) \n (p-func-b12 uint) \n (p-func-b13 uint) \n (p-func-b14 uint) \n (p-func-b15 uint) \n (p-func-b16 uint) \n (p-func-non-alpha-discount uint) \n (p-func-no-vowel-discount uint) \n (lifetime uint) \n (namespace-import principal) \n (namespace-manager (optional principal)) \n (can-update-price bool) \n (manager-transfers bool) \n (manager-frozen bool)\n)\n (let \n (\n ;; Generate the hashed, salted namespace identifier to match with its preorder.\n (hashed-salted-namespace (hash160 (concat (concat namespace 0x2e) namespace-salt)))\n ;; Define the price function based on the provided parameters.\n (price-function \n {\n buckets: (list p-func-b1 p-func-b2 p-func-b3 p-func-b4 p-func-b5 p-func-b6 p-func-b7 p-func-b8 p-func-b9 p-func-b10 p-func-b11 p-func-b12 p-func-b13 p-func-b14 p-func-b15 p-func-b16),\n base: p-func-base,\n coeff: p-func-coeff,\n nonalpha-discount: p-func-non-alpha-discount,\n no-vowel-discount: p-func-no-vowel-discount\n }\n )\n ;; Retrieve the preorder record to ensure it exists and is valid for the revealing namespace\n (preorder (unwrap! (map-get? namespace-preorders { hashed-salted-namespace: hashed-salted-namespace, buyer: contract-caller}) ERR-PREORDER-NOT-FOUND))\n ;; Calculate the namespace's registration price for validation.\n (namespace-price (try! (get-namespace-price namespace)))\n )\n ;; Ensure the preorder has not been claimed before\n (asserts! (not (get claimed preorder)) ERR-NAMESPACE-ALREADY-EXISTS)\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the namespace consists of valid characters only.\n (asserts! (not (has-invalid-chars namespace)) ERR-CHARSET-INVALID)\n ;; Check that the namespace is available for reveal.\n (asserts! (unwrap! (can-namespace-be-registered namespace) ERR-NAMESPACE-ALREADY-EXISTS) ERR-NAMESPACE-ALREADY-EXISTS)\n ;; Verify the burned amount during preorder meets or exceeds the namespace's registration price.\n (asserts! (>= (get stx-burned preorder) namespace-price) ERR-STX-BURNT-INSUFFICIENT)\n ;; Confirm the reveal action is performed within the allowed timeframe from the preorder.\n (asserts! (< burn-block-height (+ (get created-at preorder) PREORDER-CLAIMABILITY-TTL)) ERR-PREORDER-CLAIMABILITY-EXPIRED)\n ;; Ensure at least 1 block has passed after the preorder to avoid namespace sniping.\n (asserts! (>= burn-block-height (+ (get created-at preorder) u1)) ERR-OPERATION-UNAUTHORIZED)\n ;; Check if the namespace manager is assigned\n (match namespace-manager \n namespace-m\n ;; If namespace-manager is assigned, then assign everything except the lifetime, that is set to u0 sinces renewals will be made in the namespace manager contract and set the can update price function to false, since no changes will ever need to be made there.\n (map-set namespaces namespace\n {\n namespace-manager: namespace-manager,\n manager-transferable: manager-transfers,\n manager-frozen: manager-frozen,\n namespace-import: namespace-import,\n revealed-at: burn-block-height,\n launched-at: none,\n lifetime: u0,\n can-update-price-function: can-update-price,\n price-function: price-function \n }\n )\n ;; If no manager is assigned\n (map-set namespaces namespace\n {\n namespace-manager: none,\n manager-transferable: manager-transfers,\n manager-frozen: manager-frozen,\n namespace-import: namespace-import,\n revealed-at: burn-block-height,\n launched-at: none,\n lifetime: lifetime,\n can-update-price-function: can-update-price,\n price-function: price-function \n }\n )\n )\n ;; Update the claimed value for the preorder\n (map-set namespace-preorders { hashed-salted-namespace: hashed-salted-namespace, buyer: contract-caller } \n (merge preorder \n {\n claimed: true\n }\n )\n ) \n ;; Confirm successful reveal of the namespace\n (ok true)\n )\n)\n\n;; @desc Public function `namespace-launch` marks a namespace as launched and available for public name registrations.\n;; @param: namespace (buff 20): The namespace to be launched and made available for public registrations.\n(define-public (namespace-launch (namespace (buff 20)))\n (let \n (\n ;; Retrieve the properties of the namespace to ensure it exists and to check its current state.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the transaction sender is the namespace's designated import principal.\n (asserts! (is-eq (get namespace-import namespace-props) contract-caller) ERR-OPERATION-UNAUTHORIZED)\n ;; Verify the namespace has not already been launched.\n (asserts! (is-none (get launched-at namespace-props)) ERR-NAMESPACE-ALREADY-LAUNCHED)\n ;; Confirm that the action is taken within the permissible time frame since the namespace was revealed.\n (asserts! (< burn-block-height (+ (get revealed-at namespace-props) NAMESPACE-LAUNCHABILITY-TTL)) ERR-NAMESPACE-PREORDER-LAUNCHABILITY-EXPIRED)\n ;; Update the `namespaces` map with the newly launched status.\n (map-set namespaces namespace (merge namespace-props { launched-at: (some burn-block-height) })) \n ;; Emit an event to indicate the namespace is now ready and launched.\n (print { namespace: namespace, status: "launch", properties: (map-get? namespaces namespace) })\n ;; Confirm the successful launch of the namespace.\n (ok true)\n )\n)\n\n;; @desc (new) Public function `turn-off-manager-transfers` disables manager transfers for a namespace (callable only once).\n;; @param: namespace (buff 20): The namespace for which manager transfers will be disabled.\n(define-public (turn-off-manager-transfers (namespace (buff 20)))\n (let \n (\n ;; Retrieve the properties of the namespace and manager.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n (namespace-manager (unwrap! (get namespace-manager namespace-props) ERR-NO-NAMESPACE-MANAGER))\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the function caller is the namespace manager.\n (asserts! (is-eq contract-caller namespace-manager) ERR-NOT-AUTHORIZED)\n ;; Disable manager transfers.\n (map-set namespaces namespace (merge namespace-props {manager-transferable: false}))\n (print { namespace: namespace, status: "turn-off-manager-transfers", properties: (map-get? namespaces namespace) })\n ;; Confirm successful execution.\n (ok true)\n )\n)\n\n;; @desc Public function `name-import` allows the insertion of names into a namespace that has been revealed but not yet launched.\n;; This facilitates pre-populating the namespace with specific names, assigning owners.\n;; @param: namespace (buff 20): The namespace into which the name is being imported.\n;; @param: name (buff 48): The name being imported into the namespace.\n;; @param: beneficiary (principal): The principal who will own the imported name.\n;; @param: stx-burn (uint): The amount of STX tokens to be burned as part of the import process.\n(define-public (name-import (namespace (buff 20)) (name (buff 48)) (beneficiary principal))\n (let \n (\n ;; Fetch properties of the specified namespace.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n ;; Fetch the latest index to mint\n (current-mint (+ (var-get bns-index) u1))\n (price (if (is-none (get namespace-manager namespace-props))\n (try! (compute-name-price name (get price-function namespace-props)))\n u0\n )\n )\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the name is not already registered.\n (asserts! (is-none (map-get? name-properties {name: name, namespace: namespace})) ERR-NAME-NOT-AVAILABLE)\n ;; Verify that the name contains only valid characters.\n (asserts! (not (has-invalid-chars name)) ERR-CHARSET-INVALID)\n ;; Ensure the contract-caller is the namespace's designated import principal or the namespace manager\n (asserts! (or (is-eq (get namespace-import namespace-props) contract-caller) (is-eq (get namespace-manager namespace-props) (some contract-caller))) ERR-OPERATION-UNAUTHORIZED)\n ;; Check that the namespace has not been launched yet, as names can only be imported to namespaces that are revealed but not launched.\n (asserts! (is-none (get launched-at namespace-props)) ERR-NAMESPACE-ALREADY-LAUNCHED)\n ;; Confirm that the import is occurring within the allowed timeframe since the namespace was revealed.\n (asserts! (< burn-block-height (+ (get revealed-at namespace-props) NAMESPACE-LAUNCHABILITY-TTL)) ERR-NAMESPACE-PREORDER-LAUNCHABILITY-EXPIRED)\n ;; Set the name properties\n (map-set name-properties {name: name, namespace: namespace}\n {\n registered-at: none,\n imported-at: (some burn-block-height),\n hashed-salted-fqn-preorder: none,\n preordered-by: none,\n renewal-height: u0,\n stx-burn: price,\n owner: beneficiary,\n }\n )\n (map-set name-to-index {name: name, namespace: namespace} current-mint)\n (map-set index-to-name current-mint {name: name, namespace: namespace})\n ;; Update primary name if needed for send-to\n (update-primary-name-recipient current-mint beneficiary)\n ;; Update the index of the minting\n (var-set bns-index current-mint)\n ;; Mint the name to the beneficiary\n (try! (nft-mint? BNS-V2 current-mint beneficiary))\n ;; Log the new name registration\n (print \n {\n topic: "new-name",\n owner: beneficiary,\n name: {name: name, namespace: namespace},\n id: current-mint,\n properties: (map-get? name-properties {name: name, namespace: namespace})\n }\n )\n ;; Confirm successful import of the name.\n (ok true)\n )\n)\n\n;; @desc Public function `namespace-update-price` updates the pricing function for a specific namespace.\n;; @param: namespace (buff 20): The namespace for which the price function is being updated.\n;; @param: p-func-base (uint): The base price used in the pricing function.\n;; @param: p-func-coeff (uint): The coefficient used in the pricing function.\n;; @param: p-func-b1 to p-func-b16 (uint): The bucket-specific multipliers for the pricing function.\n;; @param: p-func-non-alpha-discount (uint): The discount applied for non-alphabetic characters.\n;; @param: p-func-no-vowel-discount (uint): The discount applied when no vowels are present.\n(define-public (namespace-update-price \n (namespace (buff 20)) \n (p-func-base uint) \n (p-func-coeff uint) \n (p-func-b1 uint) \n (p-func-b2 uint) \n (p-func-b3 uint) \n (p-func-b4 uint) \n (p-func-b5 uint) \n (p-func-b6 uint) \n (p-func-b7 uint) \n (p-func-b8 uint) \n (p-func-b9 uint) \n (p-func-b10 uint) \n (p-func-b11 uint) \n (p-func-b12 uint) \n (p-func-b13 uint) \n (p-func-b14 uint) \n (p-func-b15 uint) \n (p-func-b16 uint) \n (p-func-non-alpha-discount uint) \n (p-func-no-vowel-discount uint)\n)\n (let \n (\n ;; Retrieve the current properties of the namespace.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n ;; Construct the new price function.\n (price-function \n {\n buckets: (list p-func-b1 p-func-b2 p-func-b3 p-func-b4 p-func-b5 p-func-b6 p-func-b7 p-func-b8 p-func-b9 p-func-b10 p-func-b11 p-func-b12 p-func-b13 p-func-b14 p-func-b15 p-func-b16),\n base: p-func-base,\n coeff: p-func-coeff,\n nonalpha-discount: p-func-non-alpha-discount,\n no-vowel-discount: p-func-no-vowel-discount\n }\n )\n )\n (match (get namespace-manager namespace-props) \n manager\n ;; Ensure that the transaction sender is the namespace's designated import principal.\n (asserts! (is-eq manager contract-caller) ERR-OPERATION-UNAUTHORIZED)\n ;; Ensure that the contract-caller is the namespace's designated import principal.\n (asserts! (is-eq (get namespace-import namespace-props) contract-caller) ERR-OPERATION-UNAUTHORIZED)\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Verify the namespace's price function can still be updated.\n (asserts! (get can-update-price-function namespace-props) ERR-OPERATION-UNAUTHORIZED)\n ;; Update the namespace's record in the `namespaces` map with the new price function.\n (map-set namespaces namespace (merge namespace-props { price-function: price-function }))\n (print { namespace: namespace, status: "update-price-manager", properties: (map-get? namespaces namespace) })\n ;; Confirm the successful update of the price function.\n (ok true)\n )\n)\n\n;; @desc Public function `namespace-freeze-price` disables the ability to update the price function for a given namespace.\n;; @param: namespace (buff 20): The target namespace for which the price function update capability is being revoked.\n(define-public (namespace-freeze-price (namespace (buff 20)))\n (let \n (\n ;; Retrieve the properties of the specified namespace to verify its existence and fetch its current settings.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n )\n (match (get namespace-manager namespace-props) \n manager \n ;; Ensure that the transaction sender is the same as the namespace's designated import principal.\n (asserts! (is-eq manager contract-caller) ERR-OPERATION-UNAUTHORIZED)\n ;; Ensure that the contract-caller is the same as the namespace's designated import principal.\n (asserts! (is-eq (get namespace-import namespace-props) contract-caller) ERR-OPERATION-UNAUTHORIZED)\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Update the namespace properties in the `namespaces` map, setting `can-update-price-function` to false.\n (map-set namespaces namespace \n (merge namespace-props { can-update-price-function: false })\n )\n (print { namespace: namespace, status: "freeze-price-manager", properties: (map-get? namespaces namespace) })\n ;; Return a success confirmation.\n (ok true)\n )\n)\n\n;; @desc (new) A 'fast' one-block registration function: (name-claim-fast)\n;; Warning: this *is* snipeable, for a slower but un-snipeable claim, use the pre-order & register functions\n;; @param: name (buff 48): The name being claimed.\n;; @param: namespace (buff 20): The namespace under which the name is being claimed.\n;; @param: stx-burn (uint): The amount of STX to burn for the claim.\n;; @param: send-to (principal): The principal to whom the name will be sent.\n(define-public (name-claim-fast (name (buff 48)) (namespace (buff 20)) (send-to principal)) \n (let \n (\n ;; Retrieve namespace properties.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n (current-namespace-manager (get namespace-manager namespace-props))\n ;; Calculates the ID for the new name to be minted.\n (id-to-be-minted (+ (var-get bns-index) u1))\n ;; Check if the name already exists.\n (name-props (map-get? name-properties {name: name, namespace: namespace}))\n ;; new to get the price of the name\n (name-price (if (is-none current-namespace-manager)\n (try! (compute-name-price name (get price-function namespace-props)))\n u0\n )\n )\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the name is not already registered.\n (asserts! (is-none name-props) ERR-NAME-NOT-AVAILABLE)\n ;; Verify that the name contains only valid characters.\n (asserts! (not (has-invalid-chars name)) ERR-CHARSET-INVALID)\n ;; Ensure that the namespace is launched\n (asserts! (is-some (get launched-at namespace-props)) ERR-NAMESPACE-NOT-LAUNCHED)\n ;; Check namespace manager\n (match current-namespace-manager \n manager \n ;; If manager, check contract-caller is manager\n (asserts! (is-eq contract-caller manager) ERR-NOT-AUTHORIZED)\n ;; If no manager\n (begin \n ;; Asserts contract-caller is the send-to if not a managed namespace\n (asserts! (is-eq contract-caller send-to) ERR-NOT-AUTHORIZED)\n ;; Updated this to burn the actual ammount of the name-price\n (try! (stx-burn? name-price send-to))\n )\n )\n ;; Update the index\n (var-set bns-index id-to-be-minted)\n ;; Sets properties for the newly registered name.\n (map-set name-properties\n {\n name: name, namespace: namespace\n } \n {\n registered-at: (some (+ burn-block-height u1)),\n imported-at: none,\n hashed-salted-fqn-preorder: none,\n preordered-by: none,\n ;; Updated this to actually start with the registered-at date/block, and also to be u0 if it is a managed namespace\n renewal-height: (if (is-eq (get lifetime namespace-props) u0)\n u0\n (+ (get lifetime namespace-props) burn-block-height u1)\n ),\n stx-burn: name-price,\n owner: send-to,\n }\n )\n (map-set name-to-index {name: name, namespace: namespace} id-to-be-minted) \n (map-set index-to-name id-to-be-minted {name: name, namespace: namespace}) \n ;; Update primary name if needed for send-to\n (update-primary-name-recipient id-to-be-minted send-to)\n ;; Mints the new BNS name.\n (try! (nft-mint? BNS-V2 id-to-be-minted send-to))\n ;; Log the new name registration\n (print \n {\n topic: "new-name",\n owner: send-to,\n name: {name: name, namespace: namespace},\n id: id-to-be-minted,\n properties: (map-get? name-properties {name: name, namespace: namespace})\n }\n )\n ;; Signals successful completion.\n (ok id-to-be-minted)\n )\n)\n\n;; @desc Defines a public function `name-preorder` for preordering BNS names by burning the registration fee and submitting the salted hash.\n;; Callable by anyone; the actual check for authorization happens in the `name-register` function.\n;; @param: hashed-salted-fqn (buff 20): The hashed and salted fully qualified name.\n;; @param: stx-to-burn (uint): The amount of STX to burn for the preorder.\n(define-public (name-preorder (hashed-salted-fqn (buff 20)) (stx-to-burn uint))\n (begin\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS) \n ;; Validate the length of the hashed-salted FQN.\n (asserts! (is-eq (len hashed-salted-fqn) HASH160LEN) ERR-HASH-MALFORMED)\n ;; Ensures that the amount of STX specified to burn is greater than zero.\n (asserts! (> stx-to-burn u0) ERR-STX-BURNT-INSUFFICIENT)\n ;; Check if the same hashed-salted-fqn has been used before\n (asserts! (is-none (map-get? name-single-preorder hashed-salted-fqn)) ERR-PREORDERED-BEFORE)\n ;; Transfers the specified amount of stx to the BNS contract to burn on register\n (try! (stx-transfer? stx-to-burn contract-caller .BNS-V2))\n ;; Records the preorder in the 'name-preorders' map.\n (map-set name-preorders\n { hashed-salted-fqn: hashed-salted-fqn, buyer: contract-caller }\n { created-at: burn-block-height, stx-burned: stx-to-burn, claimed: false}\n )\n ;; Sets the map with just the hashed-salted-fqn as the key\n (map-set name-single-preorder hashed-salted-fqn true)\n ;; Returns the block height at which the preorder's claimability period will expire.\n (ok (+ burn-block-height PREORDER-CLAIMABILITY-TTL))\n )\n)\n\n;; @desc Public function `name-register` finalizes the registration of a BNS name for users from unmanaged namespaces.\n;; @param: namespace (buff 20): The namespace to which the name belongs.\n;; @param: name (buff 48): The name to be registered.\n;; @param: salt (buff 20): The salt used during the preorder.\n(define-public (name-register (namespace (buff 20)) (name (buff 48)) (salt (buff 20)))\n (let \n (\n ;; Generate a unique identifier for the name by hashing the fully-qualified name with salt\n (hashed-salted-fqn (hash160 (concat (concat (concat name 0x2e) namespace) salt)))\n ;; Retrieve the preorder details for this name\n (preorder (unwrap! (map-get? name-preorders { hashed-salted-fqn: hashed-salted-fqn, buyer: contract-caller }) ERR-PREORDER-NOT-FOUND))\n ;; Fetch the properties of the namespace\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n ;; Get the amount of burned STX\n (stx-burned (get stx-burned preorder))\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure that the namespace is launched\n (asserts! (is-some (get launched-at namespace-props)) ERR-NAMESPACE-NOT-LAUNCHED)\n ;; Ensure the preorder hasn't been claimed before\n (asserts! (not (get claimed preorder)) ERR-OPERATION-UNAUTHORIZED)\n ;; Check that the namespace doesn't have a manager (implying it's open for registration)\n (asserts! (is-none (get namespace-manager namespace-props)) ERR-NOT-AUTHORIZED)\n ;; Verify that the preorder was made after the namespace was launched\n (asserts! (> (get created-at preorder) (unwrap! (get launched-at namespace-props) ERR-UNWRAP)) ERR-NAME-PREORDERED-BEFORE-NAMESPACE-LAUNCH)\n ;; Ensure the registration is happening within the allowed time window after preorder\n (asserts! (< burn-block-height (+ (get created-at preorder) PREORDER-CLAIMABILITY-TTL)) ERR-PREORDER-CLAIMABILITY-EXPIRED)\n ;; Make sure at least one block has passed since the preorder (prevents front-running)\n (asserts! (> burn-block-height (+ (get created-at preorder) u1)) ERR-NAME-NOT-CLAIMABLE-YET)\n ;; Verify that enough STX was burned during preorder to cover the name price\n (asserts! (is-eq stx-burned (try! (compute-name-price name (get price-function namespace-props)))) ERR-STX-BURNT-INSUFFICIENT)\n ;; Verify that the name contains only valid characters.\n (asserts! (not (has-invalid-chars name)) ERR-CHARSET-INVALID)\n ;; Mark the preorder as claimed to prevent double-spending\n (map-set name-preorders { hashed-salted-fqn: hashed-salted-fqn, buyer: contract-caller } (merge preorder {claimed: true}))\n ;; Check if the name already exists\n (match (map-get? name-properties {name: name, namespace: namespace})\n name-props-exist\n ;; If the name exists \n (handle-existing-name name-props-exist hashed-salted-fqn (get created-at preorder) stx-burned name namespace (get lifetime namespace-props))\n ;; If the name does not exist\n (register-new-name (+ (var-get bns-index) u1) hashed-salted-fqn stx-burned name namespace (get lifetime namespace-props)) \n )\n )\n)\n\n;; @desc (new) Defines a public function `claim-preorder` for claiming back the STX commited to be burnt on registration.\n;; This should only be allowed to go through if preorder-claimability-ttl has passed\n;; @param: hashed-salted-fqn (buff 20): The hashed and salted fully qualified name.\n(define-public (claim-preorder (hashed-salted-fqn (buff 20)))\n (let\n (\n ;; Retrieves the preorder details.\n (preorder (unwrap! (map-get? name-preorders { hashed-salted-fqn: hashed-salted-fqn, buyer: contract-caller }) ERR-PREORDER-NOT-FOUND))\n (claimer contract-caller)\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS) \n ;; Check if the preorder-claimability-ttl has passed\n (asserts! (> burn-block-height (+ (get created-at preorder) PREORDER-CLAIMABILITY-TTL)) ERR-OPERATION-UNAUTHORIZED)\n ;; Asserts that the preorder has not been claimed\n (asserts! (not (get claimed preorder)) ERR-OPERATION-UNAUTHORIZED)\n ;; Transfers back the specified amount of stx from the BNS contract to the contract-caller\n (try! (as-contract (stx-transfer? (get stx-burned preorder) .BNS-V2 claimer)))\n ;; Deletes the preorder in the 'name-preorders' map.\n (map-delete name-preorders { hashed-salted-fqn: hashed-salted-fqn, buyer: contract-caller })\n ;; Remove the entry from the name-single-preorder map\n (map-delete name-single-preorder hashed-salted-fqn)\n ;; Returns ok true\n (ok true)\n )\n)\n\n;; @desc (new) This function is similar to `name-preorder` but only for namespace managers, without the burning of STX tokens.\n;; Intended only for managers as mng-name-register & name-register will validate.\n;; @param: hashed-salted-fqn (buff 20): The hashed and salted fully-qualified name (FQN) being preordered.\n(define-public (mng-name-preorder (hashed-salted-fqn (buff 20)))\n (begin\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Validates that the length of the hashed and salted FQN is exactly 20 bytes.\n (asserts! (is-eq (len hashed-salted-fqn) HASH160LEN) ERR-HASH-MALFORMED)\n ;; Check if the same hashed-salted-fqn has been used before\n (asserts! (is-none (map-get? name-single-preorder hashed-salted-fqn)) ERR-PREORDERED-BEFORE)\n ;; Records the preorder in the 'name-preorders' map. Buyer set to contract-caller\n (map-set name-preorders\n { hashed-salted-fqn: hashed-salted-fqn, buyer: contract-caller }\n { created-at: burn-block-height, stx-burned: u0, claimed: false }\n )\n ;; Sets the map with just the hashed-salted-fqn as the key\n (map-set name-single-preorder hashed-salted-fqn true)\n ;; Returns the block height at which the preorder's claimability period will expire.\n (ok (+ burn-block-height PREORDER-CLAIMABILITY-TTL))\n )\n)\n\n;; @desc (new) This function uses provided details to verify the preorder, register the name, and assign it initial properties.\n;; This should only allow Managers from MANAGED namespaces to register names.\n;; @param: namespace (buff 20): The namespace for the name.\n;; @param: name (buff 48): The name being registered.\n;; @param: salt (buff 20): The salt used in hashing.\n;; @param: send-to (principal): The principal to whom the name will be registered.\n(define-public (mng-name-register (namespace (buff 20)) (name (buff 48)) (salt (buff 20)) (send-to principal))\n (let \n (\n ;; Generates the hashed, salted fully-qualified name.\n (hashed-salted-fqn (hash160 (concat (concat (concat name 0x2e) namespace) salt)))\n ;; Retrieves the existing properties of the namespace to confirm its existence and management details.\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n (current-namespace-manager (unwrap! (get namespace-manager namespace-props) ERR-NO-NAMESPACE-MANAGER))\n ;; Retrieves the preorder information using the hashed-salted FQN to verify the preorder exists\n (preorder (unwrap! (map-get? name-preorders { hashed-salted-fqn: hashed-salted-fqn, buyer: current-namespace-manager }) ERR-PREORDER-NOT-FOUND))\n ;; Calculates the ID for the new name to be minted.\n (id-to-be-minted (+ (var-get bns-index) u1))\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the preorder has not been claimed before\n (asserts! (not (get claimed preorder)) ERR-OPERATION-UNAUTHORIZED)\n ;; Ensure the name is not already registered\n (asserts! (is-none (map-get? name-properties {name: name, namespace: namespace})) ERR-NAME-NOT-AVAILABLE)\n ;; Verify that the name contains only valid characters.\n (asserts! (not (has-invalid-chars name)) ERR-CHARSET-INVALID)\n ;; Verifies that the caller is the namespace manager.\n (asserts! (is-eq contract-caller current-namespace-manager) ERR-NOT-AUTHORIZED)\n ;; Validates that the preorder was made after the namespace was officially launched.\n (asserts! (> (get created-at preorder) (unwrap! (get launched-at namespace-props) ERR-UNWRAP)) ERR-NAME-PREORDERED-BEFORE-NAMESPACE-LAUNCH)\n ;; Verifies the registration is completed within the claimability period.\n (asserts! (< burn-block-height (+ (get created-at preorder) PREORDER-CLAIMABILITY-TTL)) ERR-PREORDER-CLAIMABILITY-EXPIRED)\n ;; Sets properties for the newly registered name.\n (map-set name-properties\n {\n name: name, namespace: namespace\n } \n {\n registered-at: (some burn-block-height),\n imported-at: none,\n hashed-salted-fqn-preorder: (some hashed-salted-fqn),\n preordered-by: (some send-to),\n ;; Updated this to be u0, so that renewals are handled through the namespace manager \n renewal-height: u0,\n stx-burn: u0,\n owner: send-to,\n }\n )\n (map-set name-to-index {name: name, namespace: namespace} id-to-be-minted)\n (map-set index-to-name id-to-be-minted {name: name, namespace: namespace})\n ;; Update primary name if needed for send-to\n (update-primary-name-recipient id-to-be-minted send-to)\n ;; Updates BNS-index variable to the newly minted ID.\n (var-set bns-index id-to-be-minted)\n ;; Update map to claimed for preorder, to avoid people reclaiming stx from an already registered name\n (map-set name-preorders { hashed-salted-fqn: hashed-salted-fqn, buyer: current-namespace-manager } (merge preorder {claimed: true}))\n ;; Mints the BNS name as an NFT to the send-to address, finalizing the registration.\n (try! (nft-mint? BNS-V2 id-to-be-minted send-to))\n ;; Log the new name registration\n (print \n {\n topic: "new-name",\n owner: send-to,\n name: {name: name, namespace: namespace},\n id: id-to-be-minted,\n properties: (map-get? name-properties {name: name, namespace: namespace})\n }\n )\n ;; Confirms successful registration of the name.\n (ok id-to-be-minted)\n )\n)\n\n;; Public function `name-renewal` for renewing ownership of a name.\n;; @param: namespace (buff 20): The namespace of the name to be renewed.\n;; @param: name (buff 48): The actual name to be renewed.\n;; @param: stx-to-burn (uint): The amount of STX tokens to be burned for renewal.\n(define-public (name-renewal (namespace (buff 20)) (name (buff 48)))\n (let \n (\n ;; Get the unique identifier for this name\n (name-index (unwrap! (get-id-from-bns name namespace) ERR-NO-NAME))\n ;; Retrieve the properties of the namespace\n (namespace-props (unwrap! (map-get? namespaces namespace) ERR-NAMESPACE-NOT-FOUND))\n ;; Get the manager of the namespace, if any\n (namespace-manager (get namespace-manager namespace-props))\n ;; Get the current owner of the name\n (owner (unwrap! (nft-get-owner? BNS-V2 name-index) ERR-NO-NAME))\n ;; Retrieve the properties of the name\n (name-props (unwrap! (map-get? name-properties { name: name, namespace: namespace }) ERR-NO-NAME))\n ;; Get the lifetime of names in this namespace\n (lifetime (get lifetime namespace-props))\n ;; Get the current renewal height of the name\n (renewal-height (try! (get-renewal-height name-index)))\n ;; Calculate the new renewal height based on current block height\n (new-renewal-height (+ burn-block-height lifetime))\n )\n ;; Check if migration is complete\n (asserts! (var-get migration-complete) ERR-MIGRATION-IN-PROGRESS)\n ;; Verify that the namespace has been launched\n (asserts! (is-some (get launched-at namespace-props)) ERR-NAMESPACE-NOT-LAUNCHED)\n ;; Ensure the namespace doesn't have a manager\n (asserts! (is-none namespace-manager) ERR-NAMESPACE-HAS-MANAGER)\n ;; Check if renewals are required for this namespace\n (asserts! (> lifetime u0) ERR-LIFETIME-EQUAL-0)\n ;; Handle renewal based on whether it's within the grace period or not\n (if (< burn-block-height (+ renewal-height NAME-GRACE-PERIOD-DURATION)) \n (try! (handle-renewal-in-grace-period name namespace name-props owner lifetime new-renewal-height))\n (try! (handle-renewal-after-grace-period name namespace name-props owner name-index new-renewal-height))\n )\n ;; Burn the specified amount of STX\n (try! (stx-burn? (try! (compute-name-price name (get price-function namespace-props))) contract-caller))\n ;; update the new stx-burn to the one paid in renewal\n (map-set name-properties { name: name, namespace: namespace } (merge (unwrap-panic (map-get? name-properties { name: name, namespace: namespace })) {stx-burn: (try! (compute-name-price name (get price-function namespace-props)))}))\n ;; Return success\n (ok true)\n )\n)\n\n;; Private function to handle renewals within the grace period\n(define-private (handle-renewal-in-grace-period \n (name (buff 48)) \n (namespace (buff 20)) \n (name-props \n {\n registered-at: (optional uint), \n imported-at: (optional uint), \n hashed-salted-fqn-preorder: (optional (buff 20)), \n preordered-by: (optional principal), \n renewal-height: uint, \n stx-burn: uint, \n owner: principal\n }\n ) \n (owner principal) \n (lifetime uint) \n (new-renewal-height uint)\n)\n (begin\n ;; Ensure only the owner can renew within the grace period\n (asserts! (is-eq contract-caller owner) ERR-NOT-AUTHORIZED)\n ;; Update the name properties with the new renewal height\n (map-set name-properties {name: name, namespace: namespace} \n (merge name-props \n {\n renewal-height: \n ;; If still within lifetime, extend from current renewal height; otherwise, use new renewal height\n (if (< burn-block-height (unwrap-panic (get-renewal-height (unwrap-panic (get-id-from-bns name namespace)))))\n (+ (unwrap-panic (get-renewal-height (unwrap-panic (get-id-from-bns name namespace)))) lifetime)\n new-renewal-height\n )\n }\n )\n )\n (print \n {\n topic: "renew-name", \n owner: owner, \n name: {name: name, namespace: namespace}, \n id: (get-id-from-bns name namespace),\n properties: (map-get? name-properties {name: name, namespace: namespace})\n }\n )\n (ok true)\n )\n)\n\n;; Private function to handle renewals after the grace period\n(define-private (handle-renewal-after-grace-period \n (name (buff 48)) \n (namespace (buff 20)) \n (name-props \n {\n registered-at: (optional uint), \n imported-at: (optional uint), \n hashed-salted-fqn-preorder: (optional (buff 20)), \n preordered-by: (optional principal), \n renewal-height: uint, \n stx-burn: uint, \n owner: principal\n }\n ) \n (owner principal) \n (name-index uint) \n (new-renewal-height uint)\n)\n (if (is-eq contract-caller owner)\n ;; If the owner is renewing, simply update the renewal height\n (ok \n (map-set name-properties {name: name, namespace: namespace}\n (merge name-props {renewal-height: new-renewal-height})\n )\n )\n ;; If someone else is renewing (taking over the name)\n (begin \n ;; Check if the name is listed on the market and remove the listing if it is\n (match (map-get? market name-index)\n listed-name \n (map-delete market name-index) \n true\n )\n (map-set name-properties {name: name, namespace: namespace}\n (merge name-props {renewal-height: new-renewal-height})\n )\n ;; Update the name properties with the new renewal height and owner\n (ok (try! (purchase-transfer name-index owner contract-caller)))\n )\n ) \n)\n\n;; Returns the minimum of two uint values.\n(define-private (min (a uint) (b uint))\n ;; If 'a' is less than or equal to 'b', return 'a', else return 'b'.\n (if (<= a b) a b) \n)\n\n;; Returns the maximum of two uint values.\n(define-private (max (a uint) (b uint))\n ;; If 'a' is greater than 'b', return 'a', else return 'b'.\n (if (> a b) a b) \n)\n\n;; Retrieves an exponent value from a list of buckets based on the provided index.\n(define-private (get-exp-at-index (buckets (list 16 uint)) (index uint))\n ;; Retrieves the element at the specified index.\n (unwrap-panic (element-at? buckets index)) \n)\n\n;; Determines if a character is a digit (0-9).\n(define-private (is-digit (char (buff 1)))\n (or \n ;; Checks if the character is between '0' and '9' using hex values.\n (is-eq char 0x30) ;; 0\n (is-eq char 0x31) ;; 1\n (is-eq char 0x32) ;; 2\n (is-eq char 0x33) ;; 3\n (is-eq char 0x34) ;; 4\n (is-eq char 0x35) ;; 5\n (is-eq char 0x36) ;; 6\n (is-eq char 0x37) ;; 7\n (is-eq char 0x38) ;; 8\n (is-eq char 0x39) ;; 9\n )\n) \n\n;; Checks if a character is a lowercase alphabetic character (a-z).\n(define-private (is-lowercase-alpha (char (buff 1)))\n (or \n ;; Checks for each lowercase letter using hex values.\n (is-eq char 0x61) ;; a\n (is-eq char 0x62) ;; b\n (is-eq char 0x63) ;; c\n (is-eq char 0x64) ;; d\n (is-eq char 0x65) ;; e\n (is-eq char 0x66) ;; f\n (is-eq char 0x67) ;; g\n (is-eq char 0x68) ;; h\n (is-eq char 0x69) ;; i\n (is-eq char 0x6a) ;; j\n (is-eq char 0x6b) ;; k\n (is-eq char 0x6c) ;; l\n (is-eq char 0x6d) ;; m\n (is-eq char 0x6e) ;; n\n (is-eq char 0x6f) ;; o\n (is-eq char 0x70) ;; p\n (is-eq char 0x71) ;; q\n (is-eq char 0x72) ;; r\n (is-eq char 0x73) ;; s\n (is-eq char 0x74) ;; t\n (is-eq char 0x75) ;; u\n (is-eq char 0x76) ;; v\n (is-eq char 0x77) ;; w\n (is-eq char 0x78) ;; x\n (is-eq char 0x79) ;; y\n (is-eq char 0x7a) ;; z\n )\n) \n\n;; Determines if a character is a vowel (a, e, i, o, u, and y).\n(define-private (is-vowel (char (buff 1)))\n (or \n (is-eq char 0x61) ;; a\n (is-eq char 0x65) ;; e\n (is-eq char 0x69) ;; i\n (is-eq char 0x6f) ;; o\n (is-eq char 0x75) ;; u\n (is-eq char 0x79) ;; y\n )\n)\n\n;; Identifies if a character is a special character, specifically '-' or '_'.\n(define-private (is-special-char (char (buff 1)))\n (or \n (is-eq char 0x2d) ;; -\n (is-eq char 0x5f)) ;; _\n) \n\n;; Determines if a character is valid within a name, based on allowed character sets.\n(define-private (is-char-valid (char (buff 1)))\n (or (is-lowercase-alpha char) (is-digit char) (is-special-char char))\n)\n\n;; Checks if a character is non-alphabetic, either a digit or a special character.\n(define-private (is-nonalpha (char (buff 1)))\n (or (is-digit char) (is-special-char char))\n)\n\n;; Evaluates if a name contains any vowel characters.\n(define-private (has-vowels-chars (name (buff 48)))\n (> (len (filter is-vowel name)) u0)\n)\n\n;; Determines if a name contains non-alphabetic characters.\n(define-private (has-nonalpha-chars (name (buff 48)))\n (> (len (filter is-nonalpha name)) u0)\n)\n\n;; Identifies if a name contains any characters that are not considered valid.\n(define-private (has-invalid-chars (name (buff 48)))\n (< (len (filter is-char-valid name)) (len name))\n)\n\n;; Private helper function `is-namespace-available` checks if a namespace is available for registration or other operations.\n;; It considers if the namespace has been launched and whether it has expired.\n;; @params:\n ;; namespace (buff 20): The namespace to check for availability.\n(define-private (is-namespace-available (namespace (buff 20)))\n ;; Check if the namespace exists\n (match (map-get? namespaces namespace) \n namespace-props\n ;; If it exists\n ;; Check if the namespace has been launched.\n (match (get launched-at namespace-props) \n launched\n ;; If the namespace is launched, it's considered unavailable if it hasn't expired.\n false\n ;; Check if the namespace is expired by comparing the current block height to the reveal time plus the launchability TTL.\n (> burn-block-height (+ (get revealed-at namespace-props) NAMESPACE-LAUNCHABILITY-TTL))\n )\n ;; If the namespace doesn't exist in the map, it's considered available.\n true\n )\n)\n\n;; Private helper function `compute-name-price` calculates the registration price for a name based on its length and character composition.\n;; It utilizes a configurable pricing function that can adjust prices based on the name's characteristics.\n;; @params:\n;; name (buff 48): The name for which the price is being calculated.\n;; price-function (tuple): A tuple containing the parameters of the pricing function, including:\n;; buckets (list 16 uint): A list defining price multipliers for different name lengths.\n;; base (uint): The base price multiplier.\n;; coeff (uint): A coefficient that adjusts the base price.\n;; nonalpha-discount (uint): A discount applied to names containing non-alphabetic characters.\n;; no-vowel-discount (uint): A discount applied to names lacking vowel characters.\n(define-private (compute-name-price (name (buff 48)) (price-function {buckets: (list 16 uint), base: uint, coeff: uint, nonalpha-discount: uint, no-vowel-discount: uint}))\n (let \n (\n ;; Determine the appropriate exponent based on the name's length.\n ;; This corresponds to a specific bucket in the pricing function.\n ;; The length of the name is used to index into the buckets list, with a maximum index of 15.\n (exponent (get-exp-at-index (get buckets price-function) (min u15 (- (len name) u1)))) \n ;; Calculate the no-vowel discount.\n ;; If the name has no vowels, apply the no-vowel discount from the price function.\n ;; Otherwise, use 1 indicating no discount.\n (no-vowel-discount (if (not (has-vowels-chars name)) (get no-vowel-discount price-function) u1))\n ;; Calculate the non-alphabetic character discount.\n ;; If the name contains non-alphabetic characters, apply the non-alpha discount from the price function.\n ;; Otherwise, use 1 indicating no discount.\n (nonalpha-discount (if (has-nonalpha-chars name) (get nonalpha-discount price-function) u1))\n (len-name (len name))\n )\n (asserts! (> len-name u0) ERR-NAME-BLANK)\n ;; Compute the final price.\n ;; The base price, adjusted by the coefficient and exponent, is divided by the greater of the two discounts (non-alpha or no-vowel).\n ;; The result is then multiplied by 10 to adjust for unit precision.\n (ok (* (/ (* (get coeff price-function) (pow (get base price-function) exponent)) (max nonalpha-discount no-vowel-discount)) u10))\n )\n)\n\n;; This function is similar to the 'transfer' function but does not check that the owner is the contract-caller.\n;; @param id: the id of the nft being transferred.\n;; @param owner: the principal of the current owner of the nft being transferred.\n;; @param recipient: the principal of the recipient to whom the nft is being transferred.\n(define-private (purchase-transfer (id uint) (owner principal) (recipient principal))\n (let \n (\n ;; Attempts to retrieve the name and namespace associated with the given NFT ID.\n (name-and-namespace (unwrap! (map-get? index-to-name id) ERR-NO-NAME))\n ;; Retrieves the properties of the name within the namespace.\n (name-props (unwrap! (map-get? name-properties name-and-namespace) ERR-NO-NAME))\n )\n ;; Check owner and recipient is not the same\n (asserts! (not (is-eq owner recipient)) ERR-OPERATION-UNAUTHORIZED)\n (asserts! (is-eq owner (get owner name-props)) ERR-NOT-AUTHORIZED)\n ;; Update primary name if needed for owner\n (update-primary-name-owner id owner)\n ;; Update primary name if needed for recipient\n (update-primary-name-recipient id recipient)\n ;; Updates the owner to the recipient.\n (map-set name-properties name-and-namespace (merge name-props {owner: recipient}))\n ;; Executes the NFT transfer from the current owner to the recipient.\n (try! (nft-transfer? BNS-V2 id owner recipient))\n (print \n {\n topic: "transfer-name", \n owner: recipient, \n name: {name: (get name name-and-namespace), namespace: (get namespace name-and-namespace)}, \n id: id,\n properties: (map-get? name-properties {name: (get name name-and-namespace), namespace: (get namespace name-and-namespace)})\n }\n )\n (ok true)\n )\n)\n\n;; Private function to update the primary name of an address when transfering a name\n;; If the id is = to the primary name then it means that a transfer is happening and we should delete it\n(define-private (update-primary-name-owner (id uint) (owner principal)) \n ;; Check if the owner is transferring the primary name\n (if (is-eq (map-get? primary-name owner) (some id)) \n ;; If it is, then delete the primary name map\n (map-delete primary-name owner)\n ;; If it is not, do nothing, keep the current primary name\n false\n )\n)\n\n;; Private function to update the primary name of an address when recieving\n(define-private (update-primary-name-recipient (id uint) (recipient principal)) \n ;; Check if recipient has a primary name\n (match (map-get? primary-name recipient)\n recipient-primary-name\n ;; If recipient has a primary name do nothing\n true\n ;; If recipient doesn't have a primary name\n (map-set primary-name recipient id)\n )\n)\n\n(define-private (handle-existing-name \n (name-props \n {\n registered-at: (optional uint), \n imported-at: (optional uint), \n hashed-salted-fqn-preorder: (optional (buff 20)), \n preordered-by: (optional principal), \n renewal-height: uint, \n stx-burn: uint, \n owner: principal\n }\n ) \n (hashed-salted-fqn (buff 20)) \n (contract-caller-preorder-height uint) \n (stx-burned uint) (name (buff 48)) \n (namespace (buff 20)) \n (renewal uint)\n)\n (let \n (\n ;; Retrieve the index of the existing name\n (name-index (unwrap-panic (map-get? name-to-index {name: name, namespace: namespace})))\n )\n ;; Straight up check if the name was imported\n (asserts! (is-none (get imported-at name-props)) ERR-IMPORTED-BEFORE)\n ;; If the check passes then it is registered, we can straight up check the hashed-salted-fqn-preorder\n (match (get hashed-salted-fqn-preorder name-props)\n fqn \n ;; Compare both preorder's height\n (asserts! (> (unwrap-panic (get created-at (map-get? name-preorders {hashed-salted-fqn: fqn, buyer: (unwrap-panic (get preordered-by name-props))}))) contract-caller-preorder-height) ERR-PREORDERED-BEFORE)\n ;; Compare registered with preorder height\n (asserts! (> (unwrap-panic (get registered-at name-props)) contract-caller-preorder-height) ERR-FAST-MINTED-BEFORE)\n )\n ;; Update the name properties with the new preorder information since it is the best preorder\n (map-set name-properties {name: name, namespace: namespace} \n (merge name-props \n {\n hashed-salted-fqn-preorder: (some hashed-salted-fqn), \n preordered-by: (some contract-caller), \n registered-at: (some burn-block-height), \n renewal-height: (if (is-eq renewal u0)\n u0\n (+ burn-block-height renewal)\n ), \n stx-burn: stx-burned\n }\n )\n )\n (try! (as-contract (stx-transfer? stx-burned .BNS-V2 (get owner name-props))))\n ;; Transfer ownership of the name to the new owner\n (try! (purchase-transfer name-index (get owner name-props) contract-caller))\n ;; Log the name transfer event\n (print \n {\n topic: "transfer-name", \n owner: contract-caller, \n name: {name: name, namespace: namespace}, \n id: name-index,\n properties: (map-get? name-properties {name: name, namespace: namespace})\n }\n )\n ;; Return the name index\n (ok name-index)\n )\n)\n\n(define-private (register-new-name (id-to-be-minted uint) (hashed-salted-fqn (buff 20)) (stx-burned uint) (name (buff 48)) (namespace (buff 20)) (lifetime uint))\n (begin\n ;; Set the properties for the newly registered name\n (map-set name-properties\n {name: name, namespace: namespace} \n {\n registered-at: (some burn-block-height),\n imported-at: none,\n hashed-salted-fqn-preorder: (some hashed-salted-fqn),\n preordered-by: (some contract-caller),\n renewal-height: (if (is-eq lifetime u0)\n u0\n (+ burn-block-height lifetime)\n ),\n stx-burn: stx-burned,\n owner: contract-caller,\n }\n )\n ;; Update the index-to-name and name-to-index mappings\n (map-set index-to-name id-to-be-minted {name: name, namespace: namespace})\n (map-set name-to-index {name: name, namespace: namespace} id-to-be-minted)\n ;; Increment the BNS index\n (var-set bns-index id-to-be-minted)\n ;; Update the primary name for the new owner if necessary\n (update-primary-name-recipient id-to-be-minted contract-caller)\n ;; Mint a new NFT for the BNS name\n (try! (nft-mint? BNS-V2 id-to-be-minted contract-caller))\n ;; Burn the STX paid for the name registration\n (try! (as-contract (stx-burn? stx-burned .BNS-V2)))\n ;; Log the new name registration event\n (print \n {\n topic: "new-name", \n owner: contract-caller, \n name: {name: name, namespace: namespace}, \n id: id-to-be-minted,\n properties: (map-get? name-properties {name: name, namespace: namespace})\n }\n )\n ;; Return the ID of the newly minted name\n (ok id-to-be-minted)\n )\n)\n\n;; Migration Functions\n(define-public (namespace-airdrop \n (namespace (buff 20))\n (pricing {base: uint, buckets: (list 16 uint), coeff: uint, no-vowel-discount: uint, nonalpha-discount: uint}) \n (lifetime uint) \n (namespace-import principal) \n (namespace-manager (optional principal)) \n (can-update-price bool) \n (manager-transfers bool) \n (manager-frozen bool)\n (revealed-at uint)\n (launched-at uint)\n)\n (begin\n ;; Check if migration is complete\n (asserts! (not (var-get migration-complete)) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the contract-caller is the airdrop contract.\n (asserts! (is-eq DEPLOYER tx-sender) ERR-OPERATION-UNAUTHORIZED)\n ;; Ensure the namespace consists of valid characters only.\n (asserts! (not (has-invalid-chars namespace)) ERR-CHARSET-INVALID)\n ;; Check that the namespace is available for reveal.\n (asserts! (unwrap! (can-namespace-be-registered namespace) ERR-NAMESPACE-ALREADY-EXISTS) ERR-NAMESPACE-ALREADY-EXISTS)\n ;; Set all properties\n (map-set namespaces namespace\n {\n namespace-manager: namespace-manager,\n manager-transferable: manager-transfers,\n manager-frozen: manager-frozen,\n namespace-import: namespace-import,\n revealed-at: revealed-at,\n launched-at: (some launched-at),\n lifetime: lifetime,\n can-update-price-function: can-update-price,\n price-function: pricing \n }\n )\n ;; Emit an event to indicate the namespace is now ready and launched.\n (print { namespace: namespace, status: "launch", properties: (map-get? namespaces namespace)})\n ;; Confirm successful airdrop of the namespace\n (ok namespace)\n )\n)\n\n(define-public (name-airdrop\n (name (buff 48))\n (namespace (buff 20))\n (registered-at uint)\n (lifetime uint) \n (owner principal)\n)\n (let\n (\n (mint-index (+ u1 (var-get bns-index)))\n )\n ;; Check if migration is complete\n (asserts! (not (var-get migration-complete)) ERR-MIGRATION-IN-PROGRESS)\n ;; Ensure the contract-caller is the airdrop contract.\n (asserts! (is-eq DEPLOYER tx-sender) ERR-OPERATION-UNAUTHORIZED)\n ;; Set all properties\n (map-set name-to-index {name: name, namespace: namespace} mint-index)\n (map-set index-to-name mint-index {name: name, namespace: namespace})\n (map-set name-properties {name: name, namespace: namespace}\n {\n registered-at: (some registered-at),\n imported-at: none,\n hashed-salted-fqn-preorder: none,\n preordered-by: none,\n renewal-height: (if (is-eq lifetime u0) u0 (+ burn-block-height lifetime)),\n stx-burn: u0,\n owner: owner,\n }\n )\n ;; Update the index \n (var-set bns-index mint-index)\n ;; Update the primary name of the recipient\n (map-set primary-name owner mint-index)\n ;; Mint the Name to the owner\n (try! (nft-mint? BNS-V2 mint-index owner))\n (print \n {\n topic: "new-airdrop", \n owner: owner, \n name: {name: name, namespace: namespace}, \n id: mint-index,\n registered-at: registered-at, \n }\n )\n ;; Confirm successful airdrop of the namespace\n (ok mint-index)\n )\n)\n\n(define-public (flip-migration-complete)\n (ok \n (begin \n (asserts! (is-eq contract-caller DEPLOYER) ERR-NOT-AUTHORIZED) \n (var-set migration-complete true)\n )\n )\n)\n\n
SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex
https://api.hiro.so/extended/v1/contract/SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.token-alex
"(impl-trait .trait-sip-010.sip-010-trait)\\n(impl-trait .extension-trait.extension-trait)\\n(define(...TRUNCATED)
SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.router-velar-alex-v-1-2
https://api.hiro.so/extended/v1/contract/SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.router-velar-alex-v-1-2
";; router-velar-alex-v-1-2\\n\\n(use-trait v-ft-trait 'SP2AKWJYC7BNY18W1XXKPGP0YVEK63QJG4793Z2D4.si(...TRUNCATED)
SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stableswap-stx-ststx-v-1-2
https://api.hiro.so/extended/v1/contract/SPQC38PW542EQJ5M11CR25P7BS1CA6QT4TBXGB3M.stableswap-stx-ststx-v-1-2
";; Bitflow Stableswap Core Contract - v1.2\\n;; This contract handles the core logic of the Stables(...TRUNCATED)
SP1NAZ59R1ED0V6NH9N0EQBEB3MKT48CQCMKC5Q41.swap-router-v21
https://api.hiro.so/extended/v1/contract/SP1NAZ59R1ED0V6NH9N0EQBEB3MKT48CQCMKC5Q41.swap-router-v21
"(use-trait et 'SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.extension-trait.extension-trait) (impl-tra(...TRUNCATED)
SP000000000000000000002Q6VF78.pox-4
https://api.hiro.so/extended/v1/contract/SP000000000000000000002Q6VF78.pox-4
";; The .pox-4 contract\\n;; Error codes\\n(define-constant ERR_STACKING_UNREACHABLE 255)\\n(define-(...TRUNCATED)

No dataset card yet

Downloads last month
2