Skip to content

Commit

Permalink
Merge pull request #4574 from vegaprotocol/feature/4553-internalize-e…
Browse files Browse the repository at this point in the history
…thereum-event-forwarder

Internalize ethereum event forwarder
  • Loading branch information
jeremyletang authored Jan 26, 2022
2 parents 3b55d85 + 963cc1e commit 3101450
Show file tree
Hide file tree
Showing 31 changed files with 1,402 additions and 297 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
- [4653](https://github.com/vegaprotocol/vega/issues/4653) - Replace asset insurance pool with network treasury
- [4638](https://github.com/vegaprotocol/vega/pull/4638) - CI add option to specify connected changes in other repos
- [4650](https://github.com/vegaprotocol/vega/pull/4650) - Restore code from rebase and ensure node retries connection with application
- [4570](https://github.com/vegaprotocol/vega/pull/4570) - Internalize Ethereum Event Forwarder

### 🐛 Fixes
- [4521](https://github.com/vegaprotocol/vega/pull/4521) - Better error when trying to use the null-blockchain with an ERC20 asset
Expand Down
10 changes: 9 additions & 1 deletion assets/erc20/bridge/bridge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 10 additions & 22 deletions assets/erc20/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"code.vegaprotocol.io/vega/assets/common"
"code.vegaprotocol.io/vega/assets/erc20/bridge"
"code.vegaprotocol.io/vega/bridges"
vgerrors "code.vegaprotocol.io/vega/libs/errors"
"code.vegaprotocol.io/vega/metrics"
ethnw "code.vegaprotocol.io/vega/nodewallets/eth"
"code.vegaprotocol.io/vega/types"
Expand All @@ -26,8 +27,6 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
)

const MaxNonce = 100000000

var (
ErrUnableToFindDeposit = errors.New("unable to find erc20 deposit event")
ErrUnableToFindWithdrawal = errors.New("unable to find erc20 withdrawal event")
Expand Down Expand Up @@ -103,24 +102,24 @@ func (e *ERC20) Validate() error {
return err
}

var carryErr error
validationErrs := vgerrors.NewCumulatedErrors()

if name, err := t.Name(&bind.CallOpts{}); err != nil {
carryErr = fmt.Errorf("couldn't get name %v: %w", err, carryErr)
validationErrs.Add(fmt.Errorf("couldn't get name: %w", err))
} else if name != e.asset.Details.Name {
carryErr = maybeError(err, "invalid name, expected(%s), got(%s)", e.asset.Details.Name, name)
validationErrs.Add(fmt.Errorf("invalid name, expected(%s), got(%s)", e.asset.Details.Name, name))
}

if symbol, err := t.Symbol(&bind.CallOpts{}); err != nil {
carryErr = fmt.Errorf("couldn't get symbol %v: %w", err, carryErr)
validationErrs.Add(fmt.Errorf("couldn't get symbol: %w", err))
} else if symbol != e.asset.Details.Symbol {
carryErr = maybeError(carryErr, "invalid symbol, expected(%s), got(%s)", e.asset.Details.Symbol, symbol)
validationErrs.Add(fmt.Errorf("invalid symbol, expected(%s), got(%s)", e.asset.Details.Symbol, symbol))
}

if decimals, err := t.Decimals(&bind.CallOpts{}); err != nil {
carryErr = fmt.Errorf("couldn't get decimals %v: %w", err, carryErr)
validationErrs.Add(fmt.Errorf("couldn't get decimals: %w", err))
} else if uint64(decimals) != e.asset.Details.Decimals {
carryErr = maybeError(carryErr, "invalid decimals, expected(%d), got(%d)", e.asset.Details.Decimals, decimals)
validationErrs.Add(fmt.Errorf("invalid decimals, expected(%d), got(%d)", e.asset.Details.Decimals, decimals))
}

// FIXME: We do not check the total supply for now.
Expand All @@ -132,25 +131,14 @@ func (e *ERC20) Validate() error {
// carryErr = maybeError(carryErr, "invalid symbol, expected(%s), got(%s)", b.asset.Details.TotalSupply, totalSupply)
// }

if carryErr != nil {
return carryErr
if validationErrs.HasAny() {
return validationErrs
}

e.ok = true
return nil
}

func maybeError(err error, format string, a ...interface{}) error {
if err != nil {
format = format + ": %w"
args := []interface{}{}
args = append(args, a...)
args = append(args, err)
return fmt.Errorf(format, args...)
}
return fmt.Errorf(format, a...)
}

// SignBridgeListing create and sign the message to
// be sent to the bridge to whitelist the asset
// return the generated message and the signature for this message.
Expand Down
Loading

0 comments on commit 3101450

Please sign in to comment.