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

Bridging Native Token between Rootchain and Childchain #299

Open
rzmahmood opened this issue Jul 16, 2023 · 4 comments
Open

Bridging Native Token between Rootchain and Childchain #299

rzmahmood opened this issue Jul 16, 2023 · 4 comments

Comments

@rzmahmood
Copy link

rzmahmood commented Jul 16, 2023

Currently, there is no support for bridging the native token between rootchain and childchain.

For example, on Ethereum, the native token is Ether, i.e. not an ERC20. This means the RootERC20Predicate contract cannot be used to facilitate the deposit and withdrawal of Ether.

This Github issue proposes adding new contracts RootNativePredicate and ChildNativePredicate which can be used to facilitate the deposit and withdrawal of Ether. (Open to naming convention changes)

One could argue that users can deposit WETH (an ERC20 wrapper of Ether) however, this causes significant UX friction, requiring users to wrap and unwrap, while also introducing issues for non-crypto native users who are not familiar with WETH and the need for wrapping.

I will be implementing the contracts required to support Native Token Bridging and ideally, it would be merged back to this repository. I'll share a draft PR as it progresses. Open to discussion here

@lolchocotaco
Copy link

A cleaner implementation path (imo) would be adding support to wrap ether+bridge within the same txn. Keeps the implementation details the same for token bridging.

otherwise, you're adding more configuration complexity and another branching path for how the bridge works. (NativeToken vs normal ERC20)

@rzmahmood
Copy link
Author

I considered that approach but a few things come up:

Relies on an existing WETH deployment on any root chain of interest. Easy for mainnet, not as easy for testnets as we would need to deploy our own WETH copy

Native Token and WETH represented as the same token on L2 unless we use a WETH copy.

We have to modify the withdrawals flow as it would end up returning WETH instead of ETH during withdrawal which has invasive changes

We have to make separate code branch for deposits as well since we use rootToken.safeTransferFrom(msg.sender, address(this), amount); which wouldn't be applicable` for deposit + wrap transaction

Overall, it makes more sense to use a WETH copy regardless. When and how it is deployed would be up to discussion, but regardless, I currently feel that the changes required to support native token would require ugly specialised handling in the RootERC20Predicate. I'm happy to PoC this approach and make a PR though

@rzmahmood
Copy link
Author

Thinking about this more, wrapping does not make sense since none of the ERC20 operations are required on the native token. There is no transfers or approvals etc.

@Faiqonli
Copy link

$ npm run deploy

[email protected] deploy
hardhat run scripts/deploy.ts --network polygonedge

Generating typings for: 0 artifacts in dir: types for target: ethers-v5
Successfully generated 3 typings!
Successfully generated 3 typings for external artifacts!
Deploying contracts with the account: 0xfb4d51a5E2dc6dA7a81A1c07352495e4E508DD89
Account balance: 100000000000000000000000
Error: invalid BigNumber string (argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.5.0)
at Logger.makeError (/Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
at Logger.throwError (/Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
at Logger.throwArgumentError (/Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/logger/src.ts/index.ts:241:21)
at Function.BigNumber.from (/Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/bignumber/src.ts/bignumber.ts:240:27)
at NumberCoder.encode (/Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/abi/src.ts/coders/number.ts:25:27)
at /Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/abi/src.ts/coders/array.ts:71:19
at Array.forEach ()
at pack (/Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/abi/src.ts/coders/array.ts:54:12)
at TupleCoder.encode (/Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/abi/src.ts/coders/tuple.ts:54:20)
at AbiCoder.encode (/Users/jacobkim/Documents/web3/jacob-test/polygon-edge/staking-contracts/node_modules/@ethersproject/abi/src.ts/abi-coder.ts:112:15) {
reason: 'invalid BigNumber string',
code: 'INVALID_ARGUMENT',
argument: 'value',
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

4 participants
@lolchocotaco @rzmahmood @Faiqonli and others