Skip to content

Commit

Permalink
Merge pull request #15 from aibtcdev/fix/token-and-dex
Browse files Browse the repository at this point in the history
Update token and dex
  • Loading branch information
whoabuddy authored Jan 13, 2025
2 parents 65b18c3 + 7ebadcb commit cae347d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
39 changes: 11 additions & 28 deletions contracts/dao/extensions/aibtc-token-dex.clar
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
;; @dev The deployer has no ownership privileges or control over the contract's operations.
;; @version 2.0

;; traits
(impl-trait .aibtcdev-dao-traits-v1.token-dex) ;; <%= it.token_dex_trait %>
;; Implement SIP 010 trait
(use-trait sip-010-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait-ft-standard.sip-010-trait) ;; <%= it.sip10_trait %>

;; error constants
Expand All @@ -20,29 +20,27 @@
(define-constant BUY-INFO-ERROR (err u2001))
(define-constant SELL-INFO-ERROR (err u2002))

(define-constant token-supply u21000000) ;; <%= it.token_max_supply %> match with the token's supply (6 decimals)
(define-constant token-supply u1000000000000000) ;; <%= it.token_max_supply %> match with the token's supply (use decimals)
(define-constant BONDING-DEX-ADDRESS (as-contract tx-sender)) ;; one contract per token

;; bonding curve config
(define-constant STX_TARGET_AMOUNT u0) ;; <%= it.stx_target_amount %>
(define-constant VIRTUAL_STX_VALUE u0) ;; <%= it.virtual_stx_value %> 1/5 of STX_TARGET_AMOUNT
(define-constant COMPLETE_FEE u0) ;; <%= it.complete_fee % >2% of STX_TARGET_AMOUNT
(define-constant STX_TARGET_AMOUNT u2000000000) ;; <%= it.stx_target_amount %>
(define-constant VIRTUAL_STX_VALUE u400000000) ;; <%= it.virtual_stx_value %> 1/5 of STX_TARGET_AMOUNT
(define-constant COMPLETE_FEE u40000000) ;; <%= it.complete_fee % > 2% of STX_TARGET_AMOUNT

;; FEE AND DEX WALLETS
(define-constant STX_CITY_SWAP_FEE_WALLET 'ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1) ;; <%= it.stxcity_swap_fee %>
(define-constant STX_CITY_COMPLETE_FEE_WALLET 'ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1) ;; <%= it.stxcity_complete_fee %>
(define-constant BURN_ADDRESS 'ST000000000000000000002AMW42H) ;; <%= it.burn %> burn mainnet

(define-constant deployer tx-sender)
(define-constant allow-token .aibtc-token) ;; <%= it.token_contract %>

;; data vars
(define-data-var tradable bool false)
(define-data-var virtual-stx-amount uint u0)
(define-data-var token-balance uint u0)
(define-data-var stx-balance uint u0)
(define-data-var burn-percent uint u10)
(define-data-var deployer-percent uint u10)
(define-data-var burn-percent uint u25)

(define-public (buy (token-trait <sip-010-trait>) (stx-amount uint) )
(begin
Expand Down Expand Up @@ -75,20 +73,13 @@
(burn-amount (/ (* contract-token-balance burn-percent-val) u100)) ;; burn tokens for a deflationary boost after the bonding curve completed
(remain-tokens (- contract-token-balance burn-amount))
(remain-stx (- (var-get stx-balance) COMPLETE_FEE))
(deployer-amount (/ (* burn-amount (var-get deployer-percent)) u100)) ;; deployer-amount is based on the burn amount
(burn-after-deployer-amount (- burn-amount deployer-amount))
(xyk-pool-uri (default-to u"https://bitflow.finance" (try! (contract-call? token-trait get-token-uri)) ))
(xyk-burn-amount (- (sqrti (* remain-stx remain-tokens)) u1))
)
;; burn tokens
(try! (as-contract (contract-call? token-trait transfer burn-after-deployer-amount tx-sender BURN_ADDRESS none)))
;; send to deployer
(try! (as-contract (contract-call? token-trait transfer deployer-amount tx-sender deployer none)))
(try! (as-contract (contract-call? token-trait transfer burn-amount tx-sender BURN_ADDRESS none)))
;; Call XYK Core v-1-2 pool by Bitflow
;; <%= it.bitflow_core_contract %>
;; <%= it.pool_contract %>
;; <%= it.bitflow_stx_token_address %>
;; <%= it.bitflow_fee_address %>
;; <%= it.bitflow_core_contract %> <%= it.pool_contract %> <%= it.bitflow_stx_token_address %> <%= it.bitflow_fee_address %>
(try! (as-contract (contract-call? 'ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1.xyk-core-v-1-2 create-pool .aibtc-bitflow-pool 'ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1.token-stx-v-1-2 token-trait remain-stx remain-tokens xyk-burn-amount u10 u40 u10 u40 'ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1 xyk-pool-uri true)))
;; send fee
(try! (as-contract (stx-transfer? COMPLETE_FEE tx-sender STX_CITY_COMPLETE_FEE_WALLET)))
Expand Down Expand Up @@ -188,22 +179,14 @@
(begin
;; Set the virtual STX amount
(var-set virtual-stx-amount VIRTUAL_STX_VALUE)

;; Set the token balance to 40% of the total supply using inline division
(var-set token-balance (/ (* token-supply u40) u100)) ;; Direct calculation of 40% of total supply

;; Set the token balance to 20% of the total supply using inline division
(var-set token-balance (/ (* token-supply u20) u100)) ;; Direct calculation of 20% of total supply
;; Set tradable flag
(var-set tradable true)

;; Set burn percentage
(var-set burn-percent u20)

;; Set deployer percentage (based on burn amount)
(var-set deployer-percent u10) ;; About ~0.1 to 0.5% supply based on burn-amount

(var-set burn-percent u25)
;; Transfer STX deployment fee
(try! (stx-transfer? u500000 tx-sender 'ST295MNE41DC74QYCPRS8N37YYMC06N6Q3VQDZ6G1)) ;; <%= it.stxcity_dex_deployment_fee_address %>

;; Return success
(ok true)
)
6 changes: 3 additions & 3 deletions contracts/dao/extensions/aibtc-token.clar
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
(define-constant ERR-NOT-ENOUGH-FUND u101)

;; Constants
(define-constant MAXSUPPLY u21000000) ;; <%= it.token_max_supply %>
(define-constant MAXSUPPLY u1000000000000000) ;; <%= it.token_max_supply %>

;; Variables
(define-fungible-token SYMBOL MAXSUPPLY) ;; <%= it.token_symbol %>
(define-data-var contract-owner principal .aibtc-token-owner) ;; extension to manage token uri
(define-data-var contract-owner principal .aibtc-token-owner) ;; <%= it.token_owner %>

;; SIP-10 Functions
(define-public (transfer (amount uint) (from principal) (to principal) (memo (optional (buff 34))))
Expand All @@ -29,7 +29,7 @@
)

;; Define token metadata
(define-data-var token-uri (optional (string-utf8 256)) (some u"")) ;; (some u"<%= it.token_uri %>")
(define-data-var token-uri (optional (string-utf8 256)) (some u"<%= it.token_uri %>"))

;; Set token uri
(define-public (set-token-uri (value (string-utf8 256)))
Expand Down

0 comments on commit cae347d

Please sign in to comment.