pub fn handle_depositor_operator_updates(
    deps: DepsMut,
    state: &mut State,
    pool: &mut Pool,
    depositor: &Addr,
    depositor_info: &mut DepositorInfo,
    minted_shares: Uint256,
    new_operator_addr: Option<String>,
) -> StdResult<()> {
    // If an operator is already registered, add to its deposits. If not, handle relevant updates
    if depositor_info.operator_registered() {
        // Read existing operator info
        let mut operator = read_operator_info(deps.storage, &depositor_info.operator_addr);
        // Update reward index for the operator
        compute_operator_reward(state, &mut operator);
        // Then add the new deposit on the operator
        operator.shares = operator.shares.add(minted_shares);
        // store operator info
        store_operator_info(deps.storage, &depositor_info.operator_addr, operator)?;
        // update pool
        pool.total_operator_shares = pool.total_operator_shares.add(minted_shares);
    } else if let Some(new_operator_addr) = new_operator_addr {
        // If there is no operator registered and a new operator address is provided
        let new_operator_addr = deps.api.addr_validate(&new_operator_addr)?;

        // Validate that a user cannot set itself as its own operator
        if &new_operator_addr == depositor {
            return Err(StdError::generic_err(
                "You cannot assign yourself as your own operator",
            ));
        }

        // Set the new depositor_info operator_addr
        depositor_info.operator_addr = new_operator_addr;

        // Read the new operator in question
        let mut new_operator = read_operator_info(deps.storage, &depositor_info.operator_addr);

        // Update the reward index for the new operator
        compute_operator_reward(state, &mut new_operator);

        // Update new operator info deposits
        let post_transaction_depositor_shares = depositor_info.shares + minted_shares;

        new_operator.shares = new_operator.shares.add(post_transaction_depositor_shares);

        // Store new operator info
        store_operator_info(deps.storage, &depositor_info.operator_addr, new_operator)?;

        // Update pool
        pool.total_operator_shares = pool.total_operator_shares.add(minted_shares);
    }

    Ok(())
}
/// Handles all changes to operator's following a deposit
/// Modifies state and depositor_info, but doesn't save them to storage.
/// Call this function before modifying depositor_stats following a deposit.
Handles all changes to operator's following a deposit
Modifies state and depositor_info, but doesn't save them to storage.
Call this function before modifying depositor_stats following a deposit.
Handles all changes to operator ' s following a deposit Modifies state and depositor_info but doesn ' t save them to storage . Call this function before modifying depositor_stats following a deposit .
pub fn handle_depositor_operator_updates(
    deps: DepsMut,
    state: &mut State,
    pool: &mut Pool,
    depositor: &Addr,
    depositor_info: &mut DepositorInfo,
    minted_shares: Uint256,
    new_operator_addr: Option<String>,
) -> StdResult<()> {
    // If an operator is already registered, add to its deposits. If not, handle relevant updates
    if depositor_info.operator_registered() {
        // Read existing operator info
        let mut operator = read_operator_info(deps.storage, &depositor_info.operator_addr);
        // Update reward index for the operator
        compute_operator_reward(state, &mut operator);
        // Then add the new deposit on the operator
        operator.shares = operator.shares.add(minted_shares);
        // store operator info
        store_operator_info(deps.storage, &depositor_info.operator_addr, operator)?;
        // update pool
        pool.total_operator_shares = pool.total_operator_shares.add(minted_shares);
    } else if let Some(new_operator_addr) = new_operator_addr {
        // If there is no operator registered and a new operator address is provided
        let new_operator_addr = deps.api.addr_validate(&new_operator_addr)?;
        // Validate that a user cannot set itself as its own operator
        if &new_operator_addr == depositor {
            return Err(StdError::generic_err(
                "You cannot assign yourself as your own operator",
            ));
        }
        // Set the new depositor_info operator_addr
        depositor_info.operator_addr = new_operator_addr;
        // Read the new operator in question
        let mut new_operator = read_operator_info(deps.storage, &depositor_info.operator_addr);
        // Update the reward index for the new operator
        compute_operator_reward(state, &mut new_operator);
        // Update new operator info deposits
        let post_transaction_depositor_shares = depositor_info.shares + minted_shares;
        new_operator.shares = new_operator.shares.add(post_transaction_depositor_shares);
        // Store new operator info
        store_operator_info(deps.storage, &depositor_info.operator_addr, new_operator)?;
        // Update pool
        pool.total_operator_shares = pool.total_operator_shares.add(minted_shares);
    }
    Ok(())
}
pub fn handle_depositor_operator_updates ( deps : DepsMut , state : & mut State , pool : & mut Pool , depositor : & Addr , depositor_info : & mut DepositorInfo , minted_shares : Uint256 , new_operator_addr : Option < String > , ) -> StdResult < ( ) > { // If an operator is already registered, add to its deposits. If not, handle relevant updates if depositor_info . operator_registered ( ) { // Read existing operator info let mut operator = read_operator_info ( deps . storage , & depositor_info . operator_addr ) ; // Update reward index for the operator compute_operator_reward ( state , & mut operator ) ; // Then add the new deposit on the operator operator . shares = operator . shares . add ( minted_shares ) ; // store operator info store_operator_info ( deps . storage , & depositor_info . operator_addr , operator ) ? ; // update pool pool . total_operator_shares = pool . total_operator_shares . add ( minted_shares ) ; } else if let Some ( new_operator_addr ) = new_operator_addr { // If there is no operator registered and a new operator address is provided let new_operator_addr = deps . api . addr_validate ( & new_operator_addr ) ? ; // Validate that a user cannot set itself as its own operator if & new_operator_addr == depositor { return Err ( StdError :: generic_err ( " " , ) ) ; } // Set the new depositor_info operator_addr depositor_info . operator_addr = new_operator_addr ; // Read the new operator in question let mut new_operator = read_operator_info ( deps . storage , & depositor_info . operator_addr ) ; // Update the reward index for the new operator compute_operator_reward ( state , & mut new_operator ) ; // Update new operator info deposits let post_transaction_depositor_shares = depositor_info . shares + minted_shares ; new_operator . shares = new_operator . shares . add ( post_transaction_depositor_shares ) ; // Store new operator info store_operator_info ( deps . storage , & depositor_info . operator_addr , new_operator ) ? ; // Update pool pool . total_operator_shares = pool . total_operator_shares . add ( minted_shares ) ; } Ok ( ( ) ) }
Handles all changes to operator's following a deposit
Modifies state and depositor_info, but doesn't save them to storage.
Handles all changes to operator ' s following a deposit Modifies state and depositor_info but doesn ' t save them to storage .
deps
DepsMut
state
&mut State
pool
&mut Pool
depositor
&Addr
depositor_info
&mut DepositorInfo
minted_shares
Uint256
new_operator_addr
Option<String>
deps
DepsMut
state
&mut State
pool
&mut Pool
depositor
&Addr
depositor_info
&mut DepositorInfo
minted_shares
Uint256
new_operator_addr
Option<String>