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

feat: added docs for multicall [APE-1311] #1617

Closed
wants to merge 20 commits into from
Closed
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ef06fa2
added docs for multicall
Aviksaikat Aug 22, 2023
37a0894
Merge branch 'ApeWorX:main' into feat/Add-documentation-for-multicall
Aviksaikat Aug 23, 2023
e48fece
fix: issues causing dev messages from working on vyper 0.3.9 [APE-132…
antazoey Aug 25, 2023
9ed80f4
Merge branch 'ApeWorX:main' into feat/Add-documentation-for-multicall
Aviksaikat Aug 25, 2023
5c6e35d
made suggested chages
Aviksaikat Aug 25, 2023
ceeb7e1
feat: show plugin name in log messages [APE-1327] (#1628)
antazoey Aug 25, 2023
76181e7
Merge branch 'main' into feat/Add-documentation-for-multicall
Aviksaikat Aug 25, 2023
bd6cf06
Update networks.md (#1629)
0xJchen Aug 28, 2023
66703f0
fix: attempt fixing geth install [APE-1333] (#1634)
antazoey Aug 28, 2023
e456173
Merge branch 'ApeWorX:main' into feat/Add-documentation-for-multicall
Aviksaikat Aug 28, 2023
0e584b3
fix: pluggy (#1633)
antazoey Aug 28, 2023
92b1191
docs for multicall moved to contracts.md
Aviksaikat Aug 28, 2023
eeff46c
Merge branch 'ApeWorX:main' into feat/Add-documentation-for-multicall
Aviksaikat Aug 28, 2023
ddb63ef
fixed mdformat issue
Aviksaikat Aug 28, 2023
3b2eb07
Merge branch 'main' into feat/Add-documentation-for-multicall
antazoey Aug 29, 2023
d6f8e4e
made suggested chages
Aviksaikat Aug 29, 2023
239d3f2
docs: Update docs/userguides/contracts.md
antazoey Aug 29, 2023
371dd32
made suggested chages
Aviksaikat Aug 29, 2023
4e539e2
made suggested chages: method docs removed
Aviksaikat Aug 29, 2023
ad6d440
Merge branch 'main' into feat/Add-documentation-for-multicall
Aviksaikat Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions docs/userguides/contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,93 @@ contract = ape.Contract("0x...")
bytes_value = contract.encode_input(0, 1, 2, 4, 5)
method_id, input_dict = contract.decode_input(bytes_value)
```

## Multicall

The `ape_ethereum` core plugin comes with a `multi-call` module.
Aviksaikat marked this conversation as resolved.
Show resolved Hide resolved

```bash
Raises:
Aviksaikat marked this conversation as resolved.
Show resolved Hide resolved
:class:`~ape_ethereum.multicall.exceptions.UnsupportedChain`: If there is not an instance of Multicall3 deployed on the current chain at the expected address.

Args:
**call_kwargs: the kwargs to pass through to the call handler.

Returns:
Iterator[Any]: the sequence of values produced by performing each call stored by this instance.
```

### Usage
Aviksaikat marked this conversation as resolved.
Show resolved Hide resolved

Here is an example of how you can use multicall.

```py
from ape_ethereum import multicall

call = multicall.Call()

call.add(contract.myMethod, *call_args)
call.add(contract.myMethod, *call_args)
... # Add as many calls as desired
call.add(contract.myMethod, *call_args)

a, b, ..., z = call() # Performs multicall
# OR
# The return type of the multicall is a generator object. So basically this will convert the result returned by the multicall into a list
result = list(call())
```

## Multicall Transaction

Create a sequence of calls to execute at once using `eth_sendTransaction` via the Multicall3 contract.
Execute the Multicall transaction.
The transaction will broadcast again every time the `Transaction` object is called.

```bash
Raises:
:class:`UnsupportedChain`: If there is not an instance of Multicall3 deployed
on the current chain at the expected address.

Args:
**txn_kwargs: the kwargs to pass through to the transaction handler.

Returns:
:class:`~ape.api.transactions.ReceiptAPI`
```

### Usage example:
Aviksaikat marked this conversation as resolved.
Show resolved Hide resolved

```py
from ape_ethereum import multicall

txn = multitxn.Transaction()
txn.add(contract.myMethod, *call_args)
txn.add(contract.myMethod, *call_args)
... # Add as many calls as desired to execute
txn.add(contract.myMethod, *call_args)
a, b, ..., z = txn(sender=my_signer) # Sends the multical transaction
# OR
result = list(txn(sender=my_signer))
```

### Practical Example

This is a sample example of how you can perform multicall in a real world scenario.
antazoey marked this conversation as resolved.
Show resolved Hide resolved
This piece of code will perfrom multicall on a `Uniswap V2` pool contract.

```py
from ape_ethereum import multicall
from ape import project

pool = ["0xF4b8A02D4e8D76070bD7092B54D2cBbe90fa72e9","0x80067013d7F7aF4e86b3890489AcAFe79F31a4Cb"]

for pool_address in pools:
uniswap_v2_pair_contract = project.IUniswapV2Pair.at(pool_address)
call.add(uniswap_v2_pair_contract.getReserves)
multicall_result = list(call())

print(multicall_result[0])

# output
[17368643486106939361172, 31867695075486]
```
Loading