pub fn execute_claim_unbonded(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
) -> Result<Response, ContractError> {
    let config = CONFIG.load(deps.storage)?;
    let state = STATE.load(deps.storage)?;

    let mut depositor = read_depositor_info(deps.storage, &info.sender);

    let to_send = claim_unbonded_withdrawals(&mut depositor, &env.block, None)?;

    let current_lottery = read_lottery_info(deps.storage, state.current_lottery);
    if current_lottery.rand_round != 0 {
        return Err(ContractError::LotteryAlreadyStarted {});
    }

    if to_send == Uint128::zero() {
        return Err(ContractError::InsufficientClaimableFunds {});
    }

    // Deduct taxes on the claim
    let net_send = deduct_tax(
        deps.as_ref(),
        coin(to_send.into(), config.stable_denom.clone()),
    )?
    .amount;

    // Double-check if there is enough balance to send in the contract
    let balance = query_balance(
        deps.as_ref(),
        env.contract.address.to_string(),
        config.stable_denom.clone(),
    )?;

    let reserved_for_prizes = state
        .prize_buckets
        .iter()
        .fold(Uint256::zero(), |sum, val| sum + *val);

    if to_send > (balance - reserved_for_prizes).into() {
        return Err(ContractError::InsufficientFunds {
            to_send,
            available_balance: balance - reserved_for_prizes,
        });
    }

    store_depositor_info(deps.storage, &info.sender, depositor, env.block.height)?;
    STATE.save(deps.storage, &state)?;

    Ok(Response::new()
        .add_message(CosmosMsg::Bank(BankMsg::Send {
            to_address: info.sender.to_string(),
            amount: vec![Coin {
                denom: config.stable_denom,
                amount: net_send,
            }],
        }))
        .add_attributes(vec![
            attr("action", "claim_unbonded"),
            attr("depositor", info.sender.to_string()),
            attr("redeemed_amount", net_send),
        ]))
}
// Send available UST to user from unbonded withdrawals
Send available UST to user from unbonded withdrawals
Send available UST to user from unbonded withdrawals
pub fn execute_claim_unbonded(
    deps: DepsMut,
    env: Env,
    info: MessageInfo,
) -> Result<Response, ContractError> {
    let config = CONFIG.load(deps.storage)?;
    let state = STATE.load(deps.storage)?;
    let mut depositor = read_depositor_info(deps.storage, &info.sender);
    let to_send = claim_unbonded_withdrawals(&mut depositor, &env.block, None)?;
    let current_lottery = read_lottery_info(deps.storage, state.current_lottery);
    if current_lottery.rand_round != 0 {
        return Err(ContractError::LotteryAlreadyStarted {});
    }
    if to_send == Uint128::zero() {
        return Err(ContractError::InsufficientClaimableFunds {});
    }
    // Deduct taxes on the claim
    let net_send = deduct_tax(
        deps.as_ref(),
        coin(to_send.into(), config.stable_denom.clone()),
    )?
    .amount;
    // Double-check if there is enough balance to send in the contract
    let balance = query_balance(
        deps.as_ref(),
        env.contract.address.to_string(),
        config.stable_denom.clone(),
    )?;
    let reserved_for_prizes = state
        .prize_buckets
        .iter()
        .fold(Uint256::zero(), |sum, val| sum + *val);
    if to_send > (balance - reserved_for_prizes).into() {
        return Err(ContractError::InsufficientFunds {
            to_send,
            available_balance: balance - reserved_for_prizes,
        });
    }
    store_depositor_info(deps.storage, &info.sender, depositor, env.block.height)?;
    STATE.save(deps.storage, &state)?;
    Ok(Response::new()
        .add_message(CosmosMsg::Bank(BankMsg::Send {
            to_address: info.sender.to_string(),
            amount: vec![Coin {
                denom: config.stable_denom,
                amount: net_send,
            }],
        }))
        .add_attributes(vec![
            attr("action", "claim_unbonded"),
            attr("depositor", info.sender.to_string()),
            attr("redeemed_amount", net_send),
        ]))
}
pub fn execute_claim_unbonded ( deps : DepsMut , env : Env , info : MessageInfo , ) -> Result < Response , ContractError > { let config = CONFIG . load ( deps . storage ) ? ; let state = STATE . load ( deps . storage ) ? ; let mut depositor = read_depositor_info ( deps . storage , & info . sender ) ; let to_send = claim_unbonded_withdrawals ( & mut depositor , & env . block , None ) ? ; let current_lottery = read_lottery_info ( deps . storage , state . current_lottery ) ; if current_lottery . rand_round != 0 { return Err ( ContractError :: LotteryAlreadyStarted { } ) ; } if to_send == Uint128 :: zero ( ) { return Err ( ContractError :: InsufficientClaimableFunds { } ) ; } // Deduct taxes on the claim let net_send = deduct_tax ( deps . as_ref ( ) , coin ( to_send . into ( ) , config . stable_denom . clone ( ) ) , ) ? . amount ; // Double-check if there is enough balance to send in the contract let balance = query_balance ( deps . as_ref ( ) , env . contract . address . to_string ( ) , config . stable_denom . clone ( ) , ) ? ; let reserved_for_prizes = state . prize_buckets . iter ( ) . fold ( Uint256 :: zero ( ) , | sum , val | sum + * val ) ; if to_send > ( balance - reserved_for_prizes ) . into ( ) { return Err ( ContractError :: InsufficientFunds { to_send , available_balance : balance - reserved_for_prizes , } ) ; } store_depositor_info ( deps . storage , & info . sender , depositor , env . block . height ) ? ; STATE . save ( deps . storage , & state ) ? ; Ok ( Response :: new ( ) . add_message ( CosmosMsg :: Bank ( BankMsg :: Send { to_address : info . sender . to_string ( ) , amount : vec ! [ Coin { denom config stable_denom amount net_send } ] , } ) ) . add_attributes ( vec ! [ attr ( " " " " ) attr ( " " info sender to_string ( ) ) attr ( " " net_send ) ] ) ) }
Send available UST to user from unbonded withdrawals
Send available UST to user from unbonded withdrawals
deps
DepsMut
env
Env
info
MessageInfo
deps
DepsMut
env
Env
info
MessageInfo