async fn is_relaying_valset_profitable(
    valset: &Valset,
    ethereum_key: &EthPrivateKey,
    cost: GasCost,
    web3: &Web3,
) -> bool {
    let mut should_relay;

    let relaying_cost = cost.gas * cost.gas_price;
    let pub_key = ethereum_key.to_address();
    let reward = valset.reward_amount.clone();
    let token_in = valset.reward_token;
    if token_in.is_none() {
        info!("No reward token has been determined for the valset, not relaying!");
        return false;
    }
    let token_in = token_in.unwrap();
    // for now we always want weth
    let token_out = *web30::amm::WETH_CONTRACT_ADDRESS;
    // If we're being rewarded in weth, we can just compare cost of gas to reward and see if we're getting enough
    if token_out == token_in {
        // TODO: Give relayers a configuration option in this case
        should_relay = reward > relaying_cost;
    } else {
        warn!(
            "No potential reward for relaying valset: {:#?} - not relaying!",
            valset
        );
        return false;
    }
    // TODO: Give relayers an option for this value
    // TODO: Understand this value better and give relayers an option
    let sqrt_price_limit_x96_uint160 = 0u8.into();

    if !should_relay {
        let value = web3
            .get_uniswap_price(
                pub_key,
                token_in,
                token_out,
                None,
                reward,
                Some(sqrt_price_limit_x96_uint160),
                None,
            )
            .await;
        if value.is_err() {
            info!(
                "Not relaying because uniswap returned an error {}",
                value.err().unwrap()
            );
        } else {
            let val = value.unwrap();
            // TODO: Give relayers a configuration option in this case too
            should_relay = val > relaying_cost;
            debug!(
                "We will be relaying because value of reward in weth: {} > cost of gas {}",
                val, relaying_cost
            );
        }
    }

    should_relay
}
/// determines if the provided valset is profitable
determines if the provided valset is profitable
determines if the provided valset is profitable
async fn is_relaying_valset_profitable(
    valset: &Valset,
    ethereum_key: &EthPrivateKey,
    cost: GasCost,
    web3: &Web3,
) -> bool {
    let mut should_relay;
    let relaying_cost = cost.gas * cost.gas_price;
    let pub_key = ethereum_key.to_address();
    let reward = valset.reward_amount.clone();
    let token_in = valset.reward_token;
    if token_in.is_none() {
        info!("No reward token has been determined for the valset, not relaying!");
        return false;
    }
    let token_in = token_in.unwrap();
    // for now we always want weth
    let token_out = *web30::amm::WETH_CONTRACT_ADDRESS;
    // If we're being rewarded in weth, we can just compare cost of gas to reward and see if we're getting enough
    if token_out == token_in {
        // TODO: Give relayers a configuration option in this case
        should_relay = reward > relaying_cost;
    } else {
        warn!(
            "No potential reward for relaying valset: {:#?} - not relaying!",
            valset
        );
        return false;
    }
    // TODO: Give relayers an option for this value
    // TODO: Understand this value better and give relayers an option
    let sqrt_price_limit_x96_uint160 = 0u8.into();
    if !should_relay {
        let value = web3
            .get_uniswap_price(
                pub_key,
                token_in,
                token_out,
                None,
                reward,
                Some(sqrt_price_limit_x96_uint160),
                None,
            )
            .await;
        if value.is_err() {
            info!(
                "Not relaying because uniswap returned an error {}",
                value.err().unwrap()
            );
        } else {
            let val = value.unwrap();
            // TODO: Give relayers a configuration option in this case too
            should_relay = val > relaying_cost;
            debug!(
                "We will be relaying because value of reward in weth: {} > cost of gas {}",
                val, relaying_cost
            );
        }
    }
    should_relay
}
async fn is_relaying_valset_profitable ( valset : & Valset , ethereum_key : & EthPrivateKey , cost : GasCost , web3 : & Web3 , ) -> bool { let mut should_relay ; let relaying_cost = cost . gas * cost . gas_price ; let pub_key = ethereum_key . to_address ( ) ; let reward = valset . reward_amount . clone ( ) ; let token_in = valset . reward_token ; if token_in . is_none ( ) { info ! ( " " ) ; return false ; } let token_in = token_in . unwrap ( ) ; // for now we always want weth let token_out = * web30 :: amm :: WETH_CONTRACT_ADDRESS ; // If we're being rewarded in weth, we can just compare cost of gas to reward and see if we're getting enough if token_out == token_in { // TODO: Give relayers a configuration option in this case should_relay = reward > relaying_cost ; } else { warn ! ( " " valset ) ; return false ; } // TODO: Give relayers an option for this value // TODO: Understand this value better and give relayers an option let sqrt_price_limit_x96_uint160 = 0u8 . into ( ) ; if ! should_relay { let value = web3 . get_uniswap_price ( pub_key , token_in , token_out , None , reward , Some ( sqrt_price_limit_x96_uint160 ) , None , ) . await ; if value . is_err ( ) { info ! ( " " value err ( ) unwrap ( ) ) ; } else { let val = value . unwrap ( ) ; // TODO: Give relayers a configuration option in this case too should_relay = val > relaying_cost ; debug ! ( " " val relaying_cost ) ; } } should_relay }
determines if the provided valset is profitable
determines if the provided valset is profitable
valset
&Valset
ethereum_key
&EthPrivateKey
cost
GasCost
web3
&Web3
valset
&Valset
ethereum_key
&EthPrivateKey
cost
GasCost
web3
&Web3