Skip to content

Commit

Permalink
ERC20 token bridging (withdrawal flow) (#1259)
Browse files Browse the repository at this point in the history
* Extract common code for withdraw and deposit commands

* Refactor deposit and withdraw commands, introduce exit command (draft)

* Mark json rpc flags optional and rely on default values

* Withdrawal workflow implemented

* Cleanups

* Remove child-token flag

* E2E build fix

* Document bridge exit command

* Refactor flags in bridge subcommands

* Remove AdminAddr from manifest file

* Update polybft readme

* Update README.md

Remove child-token flag from deposit-erc20 command example.

* Fix receivers addresses

* Code cleanup and wrapping up

* Generate missing bindings

* Remove json rpc unused flag name

* Introduce L2StateSyncedEvent and utilize it

* Remove outdated comment
  • Loading branch information
Stefan-Ethernal authored Mar 3, 2023
1 parent ee35129 commit a20e154
Show file tree
Hide file tree
Showing 27 changed files with 1,221 additions and 610 deletions.
41 changes: 35 additions & 6 deletions command/bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,42 @@

This is a helper command, which allows sending deposits from root to child chain and make withdrawals from child chain to root chain.

## Deposit
This is a helper command which bridges assets from rootchain to the child chain (allows depositing)
## Deposit ERC20
This is a helper command which deposits ERC20 tokens from the root chain to the child chain

```bash
$ polygon-edge bridge deposit
--depositor-key <hex_encoded_depositor_private_key>
--token <token_type>
$ polygon-edge bridge deposit-erc20
--sender-key <hex_encoded_depositor_private_key>
--receivers <receivers_addresses>
--amounts <amounts>
```
--root-token <root_erc20_token_address>
--root-predicate <root_erc20_predicate_address>
--json-rpc <root_chain_json_rpc_endpoint>
```

## Withdraw ERC20
This is a helper command which withdraws ERC20 tokens from the child chain to the root chain

```bash
$ polygon-edge bridge withdraw-erc20
--sender-key <hex_encoded_withdraw_sender_private_key>
--receivers <receivers_addresses>
--amounts <amounts>
--child-predicate <rchild_erc20_predicate_address>
[--child-token <child_erc20_token_address>]
--json-rpc <child_chain_json_rpc_endpoint>
```

## Exit
This is a helper command which qeuries child chain for exit event proof and sends an exit transaction to ExitHelper smart contract.

```bash
$ polygon-edge bridge exit
--sender-key <hex_encoded_withdraw_sender_private_key>
--exit-helper <exit_helper_address>
--event-id <exit_event_id>
--epoch <epoch_in_which_exit_event_got_processed>
--checkpoint-block <epoch_in_which_exit_event_got_processed>
--root-json-rpc <root_chain_json_rpc_endpoint>
--child-json-rpc <child_chain_json_rpc_endpoint>
```
8 changes: 7 additions & 1 deletion command/bridge/bridge.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package bridge

import (
"github.com/0xPolygon/polygon-edge/command/bridge/deposit"
"github.com/spf13/cobra"

"github.com/0xPolygon/polygon-edge/command/bridge/deposit"
"github.com/0xPolygon/polygon-edge/command/bridge/withdraw"
)

// GetCommand creates "bridge" helper command
Expand All @@ -21,5 +23,9 @@ func registerSubcommands(baseCmd *cobra.Command) {
baseCmd.AddCommand(
// bridge deposit
deposit.GetCommand(),
// bridge withdraw
withdraw.GetWithdrawCommand(),
// bridge exit
withdraw.GetExitCommand(),
)
}
29 changes: 29 additions & 0 deletions command/bridge/common/bridge_erc20_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package common

import (
"errors"
)

const (
SenderKeyFlag = "sender-key"
ReceiversFlag = "receivers"
AmountsFlag = "amounts"
)

var (
errInconsistentAccounts = errors.New("receivers and amounts must be equal length")
)

type ERC20BridgeParams struct {
TxnSenderKey string
Receivers []string
Amounts []string
}

func (bp *ERC20BridgeParams) ValidateFlags() error {
if len(bp.Receivers) != len(bp.Amounts) {
return errInconsistentAccounts
}

return nil
}
295 changes: 0 additions & 295 deletions command/bridge/deposit/deposit.go

This file was deleted.

Loading

0 comments on commit a20e154

Please sign in to comment.