(impl-trait .proposal-trait.proposal-trait)
(define-constant ONE_8 (pow u10 u8))
(define-constant expiry-length (* u525 u2))
(define-constant activation-block u64451)
(define-constant bounty-in-fixed ONE_8)
(define-constant shortfall-coverage (/ (* u11 ONE_8) u10))
(define-constant bot1 'SP1A6F9ABHQMVP92GH7T9ZBF029T1WG3SHPNMKT0D)
(define-constant bot2 'SP22PCWZ9EJMHV4PHVS0C8H3B3E4Q079ZHY6CXDS1)
(define-constant bot3 'SP3TSDZ2JZB44ND6VGW3HXB3S3FZSYRSCWCDB7YCY)
(define-constant ytp-balance (* u500000 ONE_8))
(define-constant ytp-fee (/ ONE_8 u100))
(define-constant ytp-fee-rebate (/ ONE_8 u2))
(define-constant ytp-small-threshold (* u500 ONE_8))
(define-constant ytp-min-fee u0)
(define-constant crp-to-hold (* u1000 ONE_8))
(define-constant crp-balance (* u2200 ONE_8))
(define-constant crp-fee u0)
(define-constant crp-fee-rebate u0)
(define-constant crp-ltv-0 (/ (* u75 ONE_8) u100))
(define-constant crp-conversion-ltv (/ (* u95 ONE_8) u100))
(define-constant crp-bs-vol (/ (* u60 ONE_8) u100))
(define-constant crp-moving-average u0)
(define-constant crp-token-to-maturity u525)
(define-constant crp-capacity-multiplier (* u8 ONE_8))
(define-constant crp-strike-multiplier (/ (* u25 ONE_8) u100))
(define-constant max-ratio (/ (* u30 ONE_8) u100))
(define-public (execute (sender principal))
	(begin			
		(try! (contract-call? .collateral-rebalancing-pool-v1 set-expiry-cycle-length expiry-length))		
		(try! (contract-call? .collateral-rebalancing-pool-v1 set-approved-pair .auto-ytp-alex .ytp-alex-v1 activation-block bounty-in-fixed))
		(try! (contract-call? .collateral-rebalancing-pool-v1 set-approved-pair .auto-yield-alex .yield-alex-v1 activation-block bounty-in-fixed))
		(try! (contract-call? .collateral-rebalancing-pool-v1 set-approved-pair .auto-key-alex-autoalex .key-alex-autoalex-v1 activation-block bounty-in-fixed))
        (try! (contract-call? .alex-vault add-approved-token .ytp-alex-v1))
        (try! (contract-call? .alex-vault add-approved-token .yield-alex-v1))
        (try! (contract-call? .alex-vault add-approved-token .key-alex-autoalex-v1))
        (try! (contract-call? .alex-vault add-approved-token .auto-ytp-alex))
        (try! (contract-call? .alex-vault add-approved-token .auto-yield-alex))
        (try! (contract-call? .alex-vault add-approved-token .auto-key-alex-autoalex))
        
        (try! (contract-call? .alex-vault add-approved-contract .collateral-rebalancing-pool-v1))
        (try! (contract-call? .alex-reserve-pool add-approved-contract .collateral-rebalancing-pool-v1))        
        (try! (contract-call? .yield-token-pool set-approved-contract .collateral-rebalancing-pool false))
        (try! (contract-call? .key-alex-autoalex set-approved-contract .collateral-rebalancing-pool false))
        (try! (contract-call? .yield-alex set-approved-contract .collateral-rebalancing-pool false))
        (try! (contract-call? .ytp-alex set-approved-contract .yield-token-pool false))
        (try! (contract-call? .auto-key-alex-autoalex set-approved-contract .collateral-rebalancing-pool false))
        (try! (contract-call? .auto-yield-alex set-approved-contract .collateral-rebalancing-pool false))
        (try! (contract-call? .auto-ytp-alex set-approved-contract .collateral-rebalancing-pool false))     
        
        (try! (contract-call? .key-alex-autoalex-v1 set-approved-contract .collateral-rebalancing-pool false))
        (try! (contract-call? .yield-alex-v1 set-approved-contract .collateral-rebalancing-pool false))
        (try! (contract-call? .yield-token-pool set-approved-contract .collateral-rebalancing-pool-v1 true))
        (try! (contract-call? .key-alex-autoalex-v1 set-approved-contract .collateral-rebalancing-pool-v1 true))
        (try! (contract-call? .yield-alex-v1 set-approved-contract .collateral-rebalancing-pool-v1 true))       
        (try! (contract-call? .auto-key-alex-autoalex set-approved-contract .collateral-rebalancing-pool-v1 true))
        (try! (contract-call? .auto-yield-alex set-approved-contract .collateral-rebalancing-pool-v1 true))
        (try! (contract-call? .auto-ytp-alex set-approved-contract .collateral-rebalancing-pool-v1 true))               
        (let 
            (
                (expiry (try! (contract-call? .collateral-rebalancing-pool-v1 get-expiry .ytp-alex-v1)))
            )
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-shortfall-coverage shortfall-coverage))
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-approved-contract bot1 true))
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-approved-contract bot2 true))
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-approved-contract bot3 true))
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-approved-contract tx-sender true))
            (try! (contract-call? .age000-governance-token mint-fixed ytp-balance tx-sender))
            (try! (contract-call? .auto-alex transfer-fixed crp-to-hold tx-sender .collateral-rebalancing-pool-v1 none))
            (try! (contract-call? .yield-token-pool create-and-configure-pool expiry .yield-alex-v1 .age000-governance-token .ytp-alex-v1 .multisig-ytp-alex ytp-fee-rebate ytp-fee ytp-fee ytp-small-threshold ytp-min-fee ytp-balance ytp-balance))
            (try! (contract-call? .collateral-rebalancing-pool-v1 create-and-configure-pool .age000-governance-token .auto-alex expiry .yield-alex-v1 .key-alex-autoalex-v1 .multisig-crp-alex-autoalex-v1 crp-ltv-0 crp-conversion-ltv crp-bs-vol crp-moving-average crp-token-to-maturity crp-fee-rebate crp-fee crp-fee crp-balance))
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-capacity-multiplier crp-capacity-multiplier))
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-strike-multiplier crp-strike-multiplier))
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-max-in-ratio max-ratio))
            (try! (contract-call? .collateral-rebalancing-pool-v1 set-max-out-ratio max-ratio))
            (try! (contract-call? .yield-token-pool set-max-in-ratio max-ratio))
            (try! (contract-call? .yield-token-pool set-max-out-ratio max-ratio))
            (let 
                (
                    (ytp-alex-balance (unwrap-panic (contract-call? .ytp-alex-v1 get-balance-fixed expiry tx-sender)))
                    (crp-alex-balance (unwrap-panic (contract-call? .key-alex-autoalex-v1 get-balance-fixed expiry tx-sender)))
                )
                (try! (contract-call? .collateral-rebalancing-pool-v1 mint-auto .ytp-alex-v1 .auto-ytp-alex ytp-alex-balance))
                (try! (contract-call? .collateral-rebalancing-pool-v1 mint-auto .key-alex-autoalex-v1 .auto-key-alex-autoalex crp-alex-balance))
                (print { expiry: expiry, ytp-alex-balance: ytp-alex-balance, crp-alex-balance: crp-alex-balance })
                (ok true)
            )  
        )
	)
)