andromedaprotocol / andromeda-core

Operating System and ADO Smart Contracts
https://andromedaprotocol.io/
38 stars 27 forks source link

[Rates] Make Rates Work on Any Action in an ADO #530

Open daniel-wehbe opened 3 months ago

daniel-wehbe commented 3 months ago

Description

Currently, the rates can be added to specific actions (for example Buy in a marketplace ADO). We want to make it so the rate can be applied to any action. This would probably be added in the call_action call:

let action_response = call_action(
        &mut ctx.deps,
        &ctx.info,
        &ctx.env,
        &ctx.amp_ctx,
        msg.as_ref(),
    )?;

Somewhere here (not sure might be other better way):

pub fn call_action(
    deps: &mut DepsMut,
    info: &MessageInfo,
    env: &Env,
    amp_ctx: &Option<AMPPkt>,
    action: &str,
) -> Result<Response, ContractError> {
    ensure!(
        is_context_permissioned(deps, info, env, amp_ctx, action)?,
        ContractError::Unauthorized {}
    );

    let payee = if let Some(amp_ctx) = amp_ctx.clone() {
        deps.api.addr_validate(amp_ctx.ctx.get_origin().as_str())?
    } else {
        info.sender.clone()
    };

    let fee_msg =
        ADOContract::default().pay_fee(deps.storage, &deps.querier, action.to_owned(), payee)?;

    Ok(Response::default().add_submessage(fee_msg))
}

Note: We should also decide on actions where rates are never applicable hard coded into the ADO.

joemonem commented 2 months ago

The operation of applying rates can be unique depending on the type of message. Different code is needed for rates on a Claim than a Buy message. I think that the current approach of enabling rates to the messages we see fit is cleaner. cc: @crnbarr93