(impl-trait .proposal-trait.proposal-trait)

(define-constant ERR-GET-BALANCE-FIXED-FAIL (err u6001))

(define-constant ONE_8 (pow u10 u8))

;; simple-equation
(define-constant max-in-ratio (/ (* ONE_8 u1) u100)) ;; 1%
(define-constant max-out-ratio (/ (* ONE_8 u1) u100)) ;; 1%

;; fwp-alex-usda
(define-constant oracle-average (/ (* ONE_8 u95) u100)) ;; resilient oracle follows (0.05 * now + 0.95 * resilient-oracle-before)
(define-constant fee-rebate (/ ONE_8 u2)) ;; 50% of tx fee goes to LPs
(define-constant fee-rate-x (/ (* ONE_8 u3) u1000)) ;; 0.3% charged on token-x when token-x is sold to buy token-y
(define-constant fee-rate-y (/ (* ONE_8 u3) u1000)) ;; 0.3% charged on token-y when token-y is sold to buy token-x
(define-constant start-block u55526)

;; initial liquidity
(define-constant dy (* u100000 ONE_8)) ;; 100,000 USDA
(define-constant dx (* u87250 ONE_8)) ;; 87,250 ALEX

(define-constant diko-to-alex u2000) ;; 12,500 DIKO equivalent (as of the date of writing)

;; staking
(define-constant fwp-alex-activation-block start-block) ;; matches DEX start-block
(define-constant fwp-alex-coinbase-1 (* diko-to-alex ONE_8)) ;; emission of $ALEX per cycle in 1st year
(define-constant fwp-alex-coinbase-2 (* u0 ONE_8)) ;; emission of $ALEX per cycle in 2nd year
(define-constant fwp-alex-coinbase-3 (* u0 ONE_8)) ;; emission of $ALEX per cycle in 3rd year
(define-constant fwp-alex-coinbase-4 (* u0 ONE_8)) ;; emission of $ALEX per cycle in 4th year
(define-constant fwp-alex-coinbase-5 (* u0 ONE_8)) ;; emission of $ALEX per cycle in 5th year
(define-constant fwp-alex-apower-multipler (/ (* u6 ONE_8) u10)) ;; APower multipler (as % of ALEX emission)

(define-constant fwp-alex-dual-multiplier-in-fixed (/ (* u12500 ONE_8) diko-to-alex)) ;; 12,500 DIKO as % of ALEX emission

(define-public (execute (sender principal))
	(begin
		(try! (contract-call? .simple-equation set-max-in-ratio max-in-ratio))
        (try! (contract-call? .simple-equation set-max-out-ratio max-out-ratio))

		(try! (contract-call? .alex-vault add-approved-contract .simple-weight-pool-alex))
		(try! (contract-call? .alex-reserve-pool add-approved-contract .simple-weight-pool-alex))

		(try! (contract-call? .age000-governance-token mint-fixed dx .executor-dao))

		(try! (contract-call? .simple-weight-pool-alex create-pool 
			.age000-governance-token
			.token-wusda
			.fwp-alex-usda 
			.multisig-fwp-alex-usda 
			dx 
			dy
		))
		(try! (contract-call? .simple-weight-pool-alex set-start-block .age000-governance-token .token-wusda start-block))		
		(try! (contract-call? .simple-weight-pool-alex set-fee-rebate .age000-governance-token .token-wusda fee-rebate))
		(try! (contract-call? .simple-weight-pool-alex set-fee-rate-x .age000-governance-token .token-wusda fee-rate-x))
		(try! (contract-call? .simple-weight-pool-alex set-fee-rate-y .age000-governance-token .token-wusda fee-rate-y))
		(try! (contract-call? .simple-weight-pool-alex set-oracle-enabled .age000-governance-token .token-wusda))
		(try! (contract-call? .simple-weight-pool-alex set-oracle-average .age000-governance-token .token-wusda oracle-average))

		;; staking
    	(try! (contract-call? .dual-farming-pool add-token .fwp-alex-usda .dual-farm-diko-helper .token-wdiko))
		(try! (contract-call? .dual-farming-pool set-multiplier-in-fixed .fwp-alex-usda fwp-alex-dual-multiplier-in-fixed))

    	(try! (contract-call? .alex-reserve-pool set-coinbase-amount .fwp-alex-usda fwp-alex-coinbase-1 fwp-alex-coinbase-2 fwp-alex-coinbase-3 fwp-alex-coinbase-4 fwp-alex-coinbase-5))
    	(try! (contract-call? .alex-reserve-pool set-apower-multiplier-in-fixed .fwp-alex-usda fwp-alex-apower-multipler))
    	(try! (contract-call? .alex-reserve-pool set-activation-block .fwp-alex-usda fwp-alex-activation-block))

		(try! (contract-call? .alex-vault add-approved-flash-loan-user 'SP2FJ75N8SNQY91W997VEPPCZX41GXBXR8B2QRTR9.flash-loan-wusda-to-wstx))
		(try! (contract-call? .alex-vault add-approved-flash-loan-user 'SP2FJ75N8SNQY91W997VEPPCZX41GXBXR8B2QRTR9.flash-loan-wstx-to-wusda))		

		(let 
      		(
        		(lp-token (unwrap! (contract-call? .fwp-alex-usda get-balance-fixed tx-sender) ERR-GET-BALANCE-FIXED-FAIL))
      		)
			;; transfer half of lp-token to arkadiko
			(try! (contract-call? .fwp-alex-usda transfer-fixed (/ lp-token u2) tx-sender 'SP2C2YFP12AJZB4MABJBAJ55XECVS7E4PMMZ89YZR none))
      		(ok true)
    	)
	)
)
