pub fn execute_create_pair(
    deps: DepsMut,
    _env: Env,
    _info: MessageInfo,
    asset_infos: [AssetInfo; 2],
    commission: Option<Decimal>,
) -> Result<Response, ContractError> {
    if let Some(commission) = commission {
        if !(Decimal::zero()..=Decimal::one()).contains(&commission) {
            return Err(ContractError::InvalidCommission(commission));
        }
    }

    let config: Config = CONFIG.load(deps.storage)?;

    let pair_key = pair_key(&asset_infos);
    if let Ok(Some(_)) = PAIRS.may_load(deps.storage, &pair_key) {
        return Err(StdError::generic_err("Pair already exists").into());
    }

    let commission = commission.unwrap_or(config.default_commission);

    TMP_PAIR_INFO.save(
        deps.storage,
        &TmpPairInfo {
            pair_key,
            asset_infos: asset_infos.clone(),
            commission,
        },
    )?;

    let pair_name = format!("{}-{}", asset_infos[0], asset_infos[1]);
    let msg = WasmMsg::Instantiate {
        code_id: config.pair_code_id,
        funds: vec![],
        admin: None,
        label: "Tgrade finance trading pair".to_string(),
        msg: to_binary(
            &PairInstantiateMsg::new(asset_infos, config.token_code_id).with_commission(commission),
        )?,
    };
    let msg = SubMsg::reply_on_success(msg, 1);
    let res = Response::new()
        .add_submessage(msg)
        .add_attribute("action", "create_pair")
        .add_attribute("pair", pair_name);
    Ok(res)
}
// Anyone can execute it to create swap pair
Anyone can execute it to create swap pair
Anyone can execute it to create swap pair
pub fn execute_create_pair(
    deps: DepsMut,
    _env: Env,
    _info: MessageInfo,
    asset_infos: [AssetInfo; 2],
    commission: Option<Decimal>,
) -> Result<Response, ContractError> {
    if let Some(commission) = commission {
        if !(Decimal::zero()..=Decimal::one()).contains(&commission) {
            return Err(ContractError::InvalidCommission(commission));
        }
    }
    let config: Config = CONFIG.load(deps.storage)?;
    let pair_key = pair_key(&asset_infos);
    if let Ok(Some(_)) = PAIRS.may_load(deps.storage, &pair_key) {
        return Err(StdError::generic_err("Pair already exists").into());
    }
    let commission = commission.unwrap_or(config.default_commission);
    TMP_PAIR_INFO.save(
        deps.storage,
        &TmpPairInfo {
            pair_key,
            asset_infos: asset_infos.clone(),
            commission,
        },
    )?;
    let pair_name = format!("{}-{}", asset_infos[0], asset_infos[1]);
    let msg = WasmMsg::Instantiate {
        code_id: config.pair_code_id,
        funds: vec![],
        admin: None,
        label: "Tgrade finance trading pair".to_string(),
        msg: to_binary(
            &PairInstantiateMsg::new(asset_infos, config.token_code_id).with_commission(commission),
        )?,
    };
    let msg = SubMsg::reply_on_success(msg, 1);
    let res = Response::new()
        .add_submessage(msg)
        .add_attribute("action", "create_pair")
        .add_attribute("pair", pair_name);
    Ok(res)
}
pub fn execute_create_pair ( deps : DepsMut , _env : Env , _info : MessageInfo , asset_infos : [ AssetInfo ; 2 ] , commission : Option < Decimal > , ) -> Result < Response , ContractError > { if let Some ( commission ) = commission { if ! ( Decimal :: zero ( ) ..= Decimal :: one ( ) ) . contains ( & commission ) { return Err ( ContractError :: InvalidCommission ( commission ) ) ; } } let config : Config = CONFIG . load ( deps . storage ) ? ; let pair_key = pair_key ( & asset_infos ) ; if let Ok ( Some ( _ ) ) = PAIRS . may_load ( deps . storage , & pair_key ) { return Err ( StdError :: generic_err ( " " ) . into ( ) ) ; } let commission = commission . unwrap_or ( config . default_commission ) ; TMP_PAIR_INFO . save ( deps . storage , & TmpPairInfo { pair_key , asset_infos : asset_infos . clone ( ) , commission , } , ) ? ; let pair_name = format ! ( " " asset_infos [ 0 ] asset_infos [ 1 ] ) ; let msg = WasmMsg :: Instantiate { code_id : config . pair_code_id , funds : vec ! [ ] , admin : None , label : " " . to_string ( ) , msg : to_binary ( & PairInstantiateMsg :: new ( asset_infos , config . token_code_id ) . with_commission ( commission ) , ) ? , } ; let msg = SubMsg :: reply_on_success ( msg , 1 ) ; let res = Response :: new ( ) . add_submessage ( msg ) . add_attribute ( " " , " " ) . add_attribute ( " " , pair_name ) ; Ok ( res ) }
Anyone can execute it to create swap pair
Anyone can execute it to create swap pair
deps
DepsMut
_env
Env
_info
MessageInfo
asset_infos
[AssetInfo; 2]
commission
Option<Decimal>
deps
DepsMut
_env
Env
_info
MessageInfo
asset_infos
[AssetInfo; 2]
commission
Option<Decimal>