In Vyper, there's a built-in function called create_forwarder_to
, which
Duplicates a contract’s code and deploys it as a new instance, by means of a DELEGATECALL.
If my understanding is correct, what create_forwarder_to
does is:
- Choose an existing contract instance
A
. - Deploy a new contract
B
that will behave the same asA
by delegatecallingA
's functions whenever there's an incoming function call toB
.
The size of bytecode of B
can be extremely small, since it's not deploying A
again but deploying a forwarder contract that utilizes A
's bytecode.
Here is an example of a forwarder contract in Uniswap, and you can see how the forwarder contract is deployed in the factory contract of Uniswap. (create_forwarder_to
was called create_with_code_of
before and got renamed in this release.)
How can I do what create_forwarder_to
does with Solidity?