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

Research clone factory to deploy erc20 bond contracts #15

Closed
RusseII opened this issue Feb 3, 2022 · 6 comments
Closed

Research clone factory to deploy erc20 bond contracts #15

RusseII opened this issue Feb 3, 2022 · 6 comments

Comments

@RusseII
Copy link
Contributor

RusseII commented Feb 3, 2022

We are leaning towards using a BondFactory to deploy a new ERC20 bond token before each gnosis auction and using the bond token as the auctioningToken

https://ropsten.etherscan.io/tx/0x387efb77e56e0b3f6066c8a853464c9a4b1b24ffbf0d49a0063793168f058638

2,271,956 gas to deploy current bond contract

https://ropsten.etherscan.io/tx/0xc164917ff5f918aec456e8d9912bd40ea9fc2715a69177093b421a93c6d2c498
1,154,924 gas to deploy very basic erc20 token

@ 100 gwei
100k gas = .01 eth
1m gas = .1 eth
10m gas = 1 eth

So ~ .2eth ($500) to deploy a bond contract - This seems like a lot but might be negligible to the DAOs issuing debt

Are there ways we can reduce these costs significantly?

https://github.com/optionality/clone-factory - would something like this be an option? Repo is quite old

@RusseII RusseII changed the title How should we handle deploying new bond contracts? How should we handle deploying new erc20 bond contracts? Feb 3, 2022
@RusseII RusseII mentioned this issue Feb 3, 2022
@Pet3ris
Copy link

Pet3ris commented Feb 4, 2022

@RusseII
Copy link
Contributor Author

RusseII commented Feb 4, 2022

From @StuartH1

one potential implementation you could look into is EIP 1167 https://eips.ethereum.org/EIPS/eip-1167, https://blog.openzeppelin.com/deep-dive-into-the-minimal-proxy-contract/. It would be a increase in complexity though
oh this is actually what you are looking at with optionality

Here is a more up to date github https://github.com/OpenZeppelin/openzeppelin-contracts/blob/4a9cc8b4918ef3736229a5cc5a310bdc17bf759f/contracts/proxy/Clones.sol

Instadapp uses this implementation in production, https://github.com/Instadapp/dsa-contracts/blob/master/contracts/registry/index.sol

Here is an old account of mine when I was testing it out - https://polygonscan.com/address/0x8eeaf1fc93d8c3d57b5931bf81aadebd24b7bb53 here is the tx when I created my account https://polygonscan.com/tx/0xcb540447d5583e97539ca1d95518d9dcd3ffc4f714f405c21366daf7194c478d

@RusseII
Copy link
Contributor Author

RusseII commented Feb 9, 2022

@luckyrobot what we learn from this issue will be used to determine the answer to #29 - so if you're able to work on this one relatively soon that'd be great!

Also Stu shared some more info/examples around this in the advisor channel

The answers we are trying to figure out are:

  • What are the tradeoffs between using clone factory and regular factory?
  • Gas usage difference between the two? (answer: a new clone is 10x cheaper)
  • Does it make sense for us to use clone factory over normal factory?
  • Can the clones be interacted with like normal tokens?
  • Is it easy to interact with the methods on the bond?
  • Can the bonds created from the cloanfactory be sent like normal erc20 tokens?
  • Can the cloans be used as-is on Uniswap or another platform that supports erc20 tokens?

@luckyrobot luckyrobot changed the title How should we handle deploying new erc20 bond contracts? Research clone factory to deploy erc20 bond contracts? Feb 9, 2022
@luckyrobot luckyrobot changed the title Research clone factory to deploy erc20 bond contracts? Research clone factory to deploy erc20 bond contracts Feb 9, 2022
@luckyrobot
Copy link

found a cool resource https://soliditydeveloper.com/clonefactory

@luckyrobot luckyrobot mentioned this issue Feb 9, 2022
@luckyrobot
Copy link

image

What are the tradeoffs between using clone factory and regular factory?

almost none that i could find

  1. someone mentioned clones could be bad for high volume contracts, but didn't go into why (source)

  2. another one is that if the parent contract self destructs, all previously deployed contracts would stop working

Gas usage difference between the two? (answer: a new clone is 10x cheaper)

clone is much cheaper, depending on contract. here's an example contract

·-------------------------------------------|----------------------------|-------------|----------------------------·
|   Solc version: 0.6.11+commit.5ef660b1    ·  Optimizer enabled: true   ·  Runs: 200  ·  Block limit: 6721975 gas  
············································|····························|·············|·····························
|  Methods                                                                                                          
·························|··················|··············|·············|·············|··············|··············
|  Contract              ·  Method          ·  Min         ·  Max        ·  Avg        ·  # calls     ·  eur (avg)  
·························|··················|··············|·············|·············|··············|··············
|  MetaCoinCloneFactory  ·  createMetaCoin  ·       94539  ·     109527  ·      95039  ·          30  ·      0.68   
·························|··················|··············|·············|·············|··············|··············
|  MetaCoinFactory       ·  createMetaCoin  ·      208441  ·     212653  ·     212513  ·          30  ·      1.53   
·-------------------------------------------|--------------|-------------|-------------|--------------|-------------·

Does it make sense for us to use clone factory over normal factory?

i believe so

Can the clones be interacted with like normal tokens?

yes, can use transfer and such. they each get an address

Is it easy to interact with the methods on the bond?

yea same interaction as previously

Can the bonds created from the cloanfactory be sent like normal erc20 tokens?

in the unit tests the answer seemed to be yes. can transfer in and out of different wallets on different bond token contracts

Can the cloans be used as-is on Uniswap or another platform that supports erc20 tokens?

this says it can be used on erc20 platforms https://forum.openzeppelin.com/t/workshop-recap-cheap-contract-deployment-through-clones/6068

@RusseII
Copy link
Contributor Author

RusseII commented Feb 11, 2022

someone mentioned clones could be bad for high volume contracts, but didn't go into why (source)

I think they were just saying to get it audited if contract has high volume.

Seems like one of the cons of using the cloneFactory is some small overhead on each of the transactions interacting with the cloned contract. Seems to be about 800 gas of overhead between native contract and cloaned contract. Uniswaps factory does not use clones for this reason. (Should be fine for us tho!)

image

i believe so

Great! Let's use it!

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

3 participants