Vyper Bundle Executor
A Humble Bundle
Building on the previous post covering a generalized Vyper contract, this lesson will extend the contract to handle the execution of multiple payloads instead of a single payload.
It also introduces a nice feature of Vyper called
struct, which allows me to group dissimilar variables together inside a “container” similar to a Python
The advantage of declaring a
struct is that they can be stored inside a
DynArray and iterated over directly, instead of needing loop over multiple arrays and keeping track of a counter.
First let us define the
payload, which will store three values:
target- the destination address for the payload
calldata- the hex byte formatted calldata to be executed at the address
value- the native token value (in Wei) that is sent with the payload
Now define some limits to our payload. First we must decide how long our calldata can be. There is a gas tradeoff to choosing a high calldata limit, and you will pay it every time the contract executes. Consequently, make the limit too low and you may not be able to execute a given function at all. I am in favor of over-estimating the calldata length, but recognize that the extra gas use could make my bundles less competitive.
Similarly, the array function input will be limited to a max count. If this is set too low, you will be limited in how many functions you can perform per transaction. Set too high, you will pay extra gas.
I have chosen to limit my calldata to 1024 Bytes and my input array to 16 items. I will reevaluate these numbers later as I refine my understanding of this approach.