1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::str::FromStr;

use crate::AbstractOS;
use abstract_os::{add_on::BaseInstantiateMsg, subscription::*};
use boot_core::{Contract, IndexResponse, TxHandler, TxResponse};
use cosmwasm_std::{Decimal, Uint128};
use cw_asset::AssetInfoUnchecked;

pub type Subscription<Chain> = AbstractOS<Chain, ExecuteMsg, InstantiateMsg, QueryMsg, MigrateMsg>;

impl<Chain: TxHandler + Clone> Subscription<Chain>
where
    TxResponse<Chain>: IndexResponse,
{
    pub fn new(name: &str, chain: &Chain) -> Self {
        Self(
            Contract::new(name, chain).with_wasm_path("subscription"), // .with_mock(Box::new(
                                                                       //     ContractWrapper::new_with_empty(
                                                                       //         ::contract::execute,
                                                                       //         ::contract::instantiate,
                                                                       //         ::contract::query,
                                                                       //     ),
                                                                       // ))
        )
    }
    pub fn init_msg(
        payment_denom: String,
        token_addr: String,
        memory_address: String,
        factory_addr: String,
        version_control_addr: String,
    ) -> InstantiateMsg {
        InstantiateMsg {
            base: BaseInstantiateMsg { memory_address },
            subscription: abstract_os::subscription::SubscriptionInstantiateMsg {
                factory_addr,
                payment_asset: AssetInfoUnchecked::native(payment_denom),
                subscription_cost_per_block: Decimal::from_str("0.000001").unwrap(),
                version_control_addr,
                subscription_per_block_emissions: state::UncheckedEmissionType::IncomeBased(
                    AssetInfoUnchecked::cw20(token_addr.clone()),
                ),
            },
            contribution: Some(abstract_os::subscription::ContributionInstantiateMsg {
                protocol_income_share: Decimal::percent(10),
                emission_user_share: Decimal::percent(50),
                max_emissions_multiple: Decimal::from_ratio(2u128, 1u128),
                token_info: AssetInfoUnchecked::cw20(token_addr),
                emissions_amp_factor: Uint128::new(680000),
                emissions_offset: Uint128::new(5200),
                // 3 days
                income_averaging_period: 259200u64.into(),
            }),
        }
    }

    // pub  fn pay_subscription(&self, os_id: u32, manager: Manager<'_>) -> Result<CosmTxResponse, BootError> {
    //     let result: SubscriptionFeeResponse = self.query(QueryMsg::Fee {  })?;

    //     let asset = result.fee;
    //     let msg = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: (), msg: (), funds: () });
    //     manager.execute(&ManagerExec::ConfigureModule { module_name: PROXY, config_msg: () }, coins);

    //     self.execute(&ExecuteMsg::Pay {  os_id: os_id }, Some(&[Coin::create("uusd", asset.amount.u128().into())]))
    // }

    pub fn claim_contribution(&self, os_id: u32) -> anyhow::Result<()> {
        self.execute(&ExecuteMsg::ClaimCompensation { os_id }, None)?;
        Ok(())
    }

    pub fn claim_emissions(&self, os_id: u32) -> anyhow::Result<()> {
        self.execute(&ExecuteMsg::ClaimEmissions { os_id }, None)?;
        Ok(())
    }
}