Skip to content

Commit

Permalink
ERC 1155 tokens bridge integration (#1332)
Browse files Browse the repository at this point in the history
* Generate ERC1155 bindings

* Initialize contracts

* Deposit ERC1155 tokens

* Withdraw ERC1155 tokens

* ERC1155 E2E test

* Rename withdraw result

* Provide corret child predicate address to the root predicate

* Pass E2E test

* Refactor commands and E2E test a bit

* Simplifications

* Simplify ERC 20 bridge commands

* Address comment

* Comment

* Move disabled root predicate dummy address to a const

* Update SC spec

* Fix ERC-1155 bridge e2e test

* Regenerate SC without logs
  • Loading branch information
Stefan-Ethernal authored Apr 22, 2023
1 parent 8165cd8 commit b2b7c15
Show file tree
Hide file tree
Showing 22 changed files with 1,406 additions and 206 deletions.
18 changes: 12 additions & 6 deletions command/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package bridge
import (
"github.com/spf13/cobra"

"github.com/0xPolygon/polygon-edge/command/bridge/deposit"
depositERC1155 "github.com/0xPolygon/polygon-edge/command/bridge/deposit/erc1155"
depositERC20 "github.com/0xPolygon/polygon-edge/command/bridge/deposit/erc20"
"github.com/0xPolygon/polygon-edge/command/bridge/exit"
"github.com/0xPolygon/polygon-edge/command/bridge/withdraw"
withdrawERC1155 "github.com/0xPolygon/polygon-edge/command/bridge/withdraw/erc1155"
withdrawERC20 "github.com/0xPolygon/polygon-edge/command/bridge/withdraw/erc20"
)

// GetCommand creates "bridge" helper command
Expand All @@ -22,10 +24,14 @@ func GetCommand() *cobra.Command {

func registerSubcommands(baseCmd *cobra.Command) {
baseCmd.AddCommand(
// bridge deposit
deposit.GetCommand(),
// bridge withdraw
withdraw.GetCommand(),
// bridge deposit-erc20
depositERC20.GetCommand(),
// bridge deposit-erc1155
depositERC1155.GetCommand(),
// bridge withdraw-erc20
withdrawERC20.GetCommand(),
// bridge withdraw-erc1155
withdrawERC1155.GetCommand(),
// bridge exit
exit.GetCommand(),
)
Expand Down
29 changes: 0 additions & 29 deletions command/bridge/common/bridge_erc20_params.go

This file was deleted.

78 changes: 78 additions & 0 deletions command/bridge/common/params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package common

import (
"errors"
)

type TokenType int

const (
ERC20 TokenType = iota
ERC721
ERC1155
)

const (
SenderKeyFlag = "sender-key"
ReceiversFlag = "receivers"
AmountsFlag = "amounts"
TokenIDsFlag = "token-ids"

RootTokenFlag = "root-token"
RootPredicateFlag = "root-predicate"
ChildPredicateFlag = "child-predicate"
ChildTokenFlag = "child-token"
JSONRPCFlag = "json-rpc"
)

var (
errInconsistentAmounts = errors.New("receivers and amounts must be equal length")
errInconsistentTokenIds = errors.New("receivers and token ids must be equal length")
)

type BridgeParams struct {
SenderKey string
Receivers []string
TokenAddr string
PredicateAddr string
JSONRPCAddr string
}

type ERC20BridgeParams struct {
*BridgeParams
Amounts []string
}

func NewERC20BridgeParams() *ERC20BridgeParams {
return &ERC20BridgeParams{BridgeParams: &BridgeParams{}}
}

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

return nil
}

type ERC1155BridgeParams struct {
*BridgeParams
Amounts []string
TokenIDs []string
}

func NewERC1155BridgeParams() *ERC1155BridgeParams {
return &ERC1155BridgeParams{BridgeParams: &BridgeParams{}}
}

func (bp *ERC1155BridgeParams) Validate() error {
if len(bp.Receivers) != len(bp.Amounts) {
return errInconsistentAmounts
}

if len(bp.Receivers) != len(bp.TokenIDs) {
return errInconsistentTokenIds
}

return nil
}
Loading

0 comments on commit b2b7c15

Please sign in to comment.