Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why this as_aggregate_3_value only available in send mode #2738

Open
ethever opened this issue Feb 13, 2024 · 0 comments
Open

Why this as_aggregate_3_value only available in send mode #2738

ethever opened this issue Feb 13, 2024 · 0 comments

Comments

@ethever
Copy link

ethever commented Feb 13, 2024

/// v3 + values (only .send())

Why this as_aggregate_3_value only available in send mode? what i need to do if i want to use the MulticallV3 to simulate some function that comsume eth...

/// v3
    #[inline]
    fn as_aggregate_3(&self) -> ContractCall<M, Vec<MulticallResult>> {
        // Map the calls vector into appropriate types for `aggregate_3` function
        let calls: Vec<Multicall3Call> = self
            .calls
            .clone()
            .into_iter()
            .map(|call| Multicall3Call {
                target: call.target,
                call_data: call.data,
                allow_failure: call.allow_failure,
            })
            .collect();

        // Construct the ContractCall for `aggregate_3` function to broadcast the transaction
        let contract_call = self.contract.aggregate_3(calls);

        self.set_call_flags(contract_call)
    }

    /// v3 + values (only .send())
    #[inline]
    fn as_aggregate_3_value(&self) -> ContractCall<M, Vec<MulticallResult>> {
        // Map the calls vector into appropriate types for `aggregate_3_value` function
        let mut total_value = U256::zero();
        let calls: Vec<Multicall3CallValue> = self
            .calls
            .clone()
            .into_iter()
            .map(|call| {
                total_value += call.value;
                Multicall3CallValue {
                    target: call.target,
                    call_data: call.data,
                    allow_failure: call.allow_failure,
                    value: call.value,
                }
            })
            .collect();

        if total_value.is_zero() {
            // No value is being sent
            self.as_aggregate_3()
        } else {
            // Construct the ContractCall for `aggregate_3_value` function to broadcast the
            // transaction
            let contract_call = self.contract.aggregate_3_value(calls);

            self.set_call_flags(contract_call).value(total_value)
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant