From 448bbd541e2ae7a6600d09bc282d9286943b282e Mon Sep 17 00:00:00 2001 From: Jingfu Wang Date: Thu, 9 Feb 2023 19:00:31 -0500 Subject: [PATCH] refactor: remove bridge (#23) * refactor: remove bridge Signed-off-by: Jingfu Wang * refactor: consume latest rosetta-geth-sdk Signed-off-by: Jingfu Wang --------- Signed-off-by: Jingfu Wang --- go.mod | 2 +- go.sum | 4 +-- pkg/handlers/erc20_bridge.go | 57 ------------------------------- pkg/handlers/erc20_bridge_test.go | 22 ------------ 4 files changed, 3 insertions(+), 82 deletions(-) delete mode 100644 pkg/handlers/erc20_bridge.go delete mode 100644 pkg/handlers/erc20_bridge_test.go diff --git a/go.mod b/go.mod index ea825b7..9195a05 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/mdehoog/op-rosetta go 1.18 require ( - github.com/coinbase/rosetta-geth-sdk v0.0.6-0.20230206215226-b11722a3d172 + github.com/coinbase/rosetta-geth-sdk v0.0.6-0.20230209235333-933f79cd0082 github.com/coinbase/rosetta-sdk-go v0.8.2 github.com/ethereum/go-ethereum v1.10.26 ) diff --git a/go.sum b/go.sum index bf83f9e..99ee850 100644 --- a/go.sum +++ b/go.sum @@ -120,8 +120,8 @@ github.com/cloudflare/cloudflare-go v0.14.0/go.mod h1:EnwdgGMaFOruiPZRFSgn+TsQ3h github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI= -github.com/coinbase/rosetta-geth-sdk v0.0.6-0.20230206215226-b11722a3d172 h1:1ejgBHdDdULLs8hga2EwSMMbIfUNV+L81uKptWfk0MU= -github.com/coinbase/rosetta-geth-sdk v0.0.6-0.20230206215226-b11722a3d172/go.mod h1:J7HROpwZhupXOZ7Vazr/qv9teosQjU5MBapBOZzTcLI= +github.com/coinbase/rosetta-geth-sdk v0.0.6-0.20230209235333-933f79cd0082 h1:VaKzsVJO6H8gxBRlkB5NJDwTJa9DQ5T5tpbJvTUP/0U= +github.com/coinbase/rosetta-geth-sdk v0.0.6-0.20230209235333-933f79cd0082/go.mod h1:J7HROpwZhupXOZ7Vazr/qv9teosQjU5MBapBOZzTcLI= github.com/coinbase/rosetta-sdk-go v0.8.2 h1:+sNgMUPpntOsYLy5aRsHqBY6I0MTxZkS4JXV1Un3DKc= github.com/coinbase/rosetta-sdk-go v0.8.2/go.mod h1:tXPR6AIW9ogsH4tYIaFOKOgfJNanCvcyl7JKLd4DToc= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= diff --git a/pkg/handlers/erc20_bridge.go b/pkg/handlers/erc20_bridge.go deleted file mode 100644 index abbb41b..0000000 --- a/pkg/handlers/erc20_bridge.go +++ /dev/null @@ -1,57 +0,0 @@ -package handlers - -import ( - evmClient "github.com/coinbase/rosetta-geth-sdk/client" - sdkTypes "github.com/coinbase/rosetta-geth-sdk/types" - RosettaTypes "github.com/coinbase/rosetta-sdk-go/types" - EthTypes "github.com/ethereum/go-ethereum/core/types" - "github.com/mdehoog/op-rosetta/pkg/common" -) - -// Erc20BridgeOps constructs a list of [RosettaTypes.Operation]s for ERC20 transactions when bridging. -func Erc20BridgeOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaTypes.Operation { - ops := []*RosettaTypes.Operation{} - ops = append(ops, NativeInitializationOps(tx, startIndex)...) - - return ops -} - -// NativeInitializationOps constructs a list of [RosettaTypes.Operation]s for native token initializations. -// -// Native token initializations occur when a native token is being *sent* to a non-native chain. -// In this case, `ERC20BridgeInitiated` and `Transfer` events are emitted FROM the sender TO the bridge contract. -func NativeInitializationOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaTypes.Operation { - // The bridge transaction must be sent to the [common.L2StandardBridge] - if *tx.Transaction.To() != common.L2StandardBridge { - return nil - } - - // Parse tx receipt logs - var receiptLogs []*EthTypes.Log - if tx.Receipt != nil { - receiptLogs = tx.Receipt.Logs - } - - // Grab the transfer log - var transferLog *EthTypes.Log - for _, log := range receiptLogs { - // Check if this is a transfer event - if common.ContainsTopic(log, common.TransferEvent) { - transferLog = log - } - } - if transferLog == (&EthTypes.Log{}) || transferLog == nil { - return nil - } - - // Return the associated operation - opIndex := int64(startIndex) - opType := sdkTypes.OpErc20Transfer - opStatus := sdkTypes.SuccessStatus - fromAddress := evmClient.MustChecksum(tx.From.String()) - amount := evmClient.Erc20Amount(transferLog.Data, transferLog.Address, sdkTypes.Currency.Symbol, sdkTypes.Currency.Decimals, false) - - return []*RosettaTypes.Operation{ - GenerateOp(opIndex, nil, opType, opStatus, fromAddress, amount, nil), - } -} diff --git a/pkg/handlers/erc20_bridge_test.go b/pkg/handlers/erc20_bridge_test.go deleted file mode 100644 index 59f3fe1..0000000 --- a/pkg/handlers/erc20_bridge_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package handlers_test - -import ( - "testing" - - suite "github.com/stretchr/testify/suite" -) - -type Erc20BridgeTestSuite struct { - suite.Suite -} - -// TestErc20Bridging runs the Erc20BridgeTestSuite. -func TestErc20Bridging(t *testing.T) { - suite.Run(t, new(Erc20BridgeTestSuite)) -} - -// TestValidNativeInitialization tests that a valid ERC20 transfer was made to the L2StandardBridge contract. -// This is when a native token is being bridged from L2 to L1. -func (testSuite *Erc20BridgeTestSuite) TestValidNativeInitialization() { - // TODO: -}