From f0df8a192873484a19ac37b3be80a4acbdf33989 Mon Sep 17 00:00:00 2001 From: thal0x Date: Mon, 10 Apr 2023 15:51:00 -0500 Subject: [PATCH 1/3] update method of retrieving account --- skipper-go/bot/uniswapv2.go | 2 -- skipper-go/feed/feed.go | 1 + skipper-go/feed/multifeed.go | 37 ++++++++++++++++++++++++++++++ skipper-go/main.go | 44 +++++++++++++++++++++++++++++++++--- skipper-go/skip/skip.go | 44 ++++++++++++++++++++++++++---------- 5 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 skipper-go/feed/multifeed.go diff --git a/skipper-go/bot/uniswapv2.go b/skipper-go/bot/uniswapv2.go index 1785393..ad6a234 100644 --- a/skipper-go/bot/uniswapv2.go +++ b/skipper-go/bot/uniswapv2.go @@ -70,8 +70,6 @@ func (bot *Bot) HandleUniswapV2Transaction(exchange *uniswapv2.Exchange, targetT return } - fmt.Println(tx) - fmt.Println("-----") fmt.Println("-----") fmt.Println("Arbitrage opportunity found:") diff --git a/skipper-go/feed/feed.go b/skipper-go/feed/feed.go index 7f64337..83438bb 100644 --- a/skipper-go/feed/feed.go +++ b/skipper-go/feed/feed.go @@ -62,6 +62,7 @@ func (feed *TransactionFeed) SubscribeNewTransactions() chan *types.Transaction for { txHashes, err := feed.getUnconfirmedTransactions() if err != nil { + fmt.Println(feed.url) fmt.Println(err) continue } diff --git a/skipper-go/feed/multifeed.go b/skipper-go/feed/multifeed.go new file mode 100644 index 0000000..ad673c3 --- /dev/null +++ b/skipper-go/feed/multifeed.go @@ -0,0 +1,37 @@ +package feed + +import ( + "github.com/ethereum/go-ethereum/core/types" + "github.com/lrita/cmap" +) + +type MultiFeed struct { + Feeds []*TransactionFeed + + knownTxs *cmap.Map[string, bool] +} + +func NewMultiFeed(urls []string, pollMs int) *MultiFeed { + feeds := make([]*TransactionFeed, len(urls)) + for i, url := range urls { + feeds[i] = NewTransactionFeed(url, pollMs) + } + return &MultiFeed{ + Feeds: feeds, + knownTxs: &cmap.Map[string, bool]{}, + } +} + +func (feed *MultiFeed) SubscribeNewTransactions() chan *types.Transaction { + ch := make(chan *types.Transaction) + + for _, feed := range feed.Feeds { + go func(feed *TransactionFeed) { + for tx := range feed.SubscribeNewTransactions() { + ch <- tx + } + }(feed) + } + + return ch +} diff --git a/skipper-go/main.go b/skipper-go/main.go index 3c0f360..9b076ef 100644 --- a/skipper-go/main.go +++ b/skipper-go/main.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" + "github.com/lrita/cmap" "github.com/thal0x/bn/bigint" "github.com/skip-mev/skipper/bindings" @@ -36,6 +37,20 @@ func startCommand() { panic(err) } + // client, err := ethclient.Dial(config.EthRPC) + // if err != nil { + // panic(err) + // } + + // block, err := client.BlockNumber(context.Background()) + // if err != nil { + // panic(err) + // } + + // fmt.Printf("connected to ethereum node, block number: %d\n", block) + + // return + backrunner, err := bot.NewBot(config, common.HexToAddress(*contractAddressFlag), key) if err != nil { panic(err) @@ -48,17 +63,40 @@ func startCommand() { fmt.Println("backrunner listening for transactions...") - txFeed := feed.NewTransactionFeed(config.CosmosRPC, config.PollMs) + knownTxs := cmap.Map[common.Hash, bool]{} + + txFeed := feed.NewMultiFeed([]string{ + "https://evmos-rpc.stakely.io", + "https://tendermint.bd.evmos.org:26657", + // "https://rpc-evmos-ia.cosmosia.notional.ventures:443", + // "https://api-evmos-ia.cosmosia.notional.ventures:443", + "https://rpc.evmos.nodestake.top", + }, config.PollMs) txChan := txFeed.SubscribeNewTransactions() for { tx := <-txChan + _, known := knownTxs.LoadOrStore(tx.Hash(), true) + if known { + continue + } + go backrunner.OnTransaction(tx) - // - // backrunner.OnTransaction(tx) } + + // txFeed := feed.NewTransactionFeed(config.CosmosRPC, config.PollMs) + + // txChan := txFeed.SubscribeNewTransactions() + + // for { + // tx := <-txChan + + // go backrunner.OnTransaction(tx) + // // + // // backrunner.OnTransaction(tx) + // } } func withdrawCommand() { diff --git a/skipper-go/skip/skip.go b/skipper-go/skip/skip.go index a838274..98c855b 100644 --- a/skipper-go/skip/skip.go +++ b/skipper-go/skip/skip.go @@ -23,7 +23,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" evmosEthsecp256k1 "github.com/evmos/ethermint/crypto/ethsecp256k1" - evmostypes "github.com/tharsis/evmos/v5/types" ) type SkipClient struct { @@ -54,13 +53,6 @@ func NewSkipClient( panic(err) } - ethAddressBytes, err := evmostypes.GetEvmosAddressFromBech32(bech32Address) - if err != nil { - panic(err) - } - - ethAddress := fmt.Sprintf("0x%x", ethAddressBytes) - client := &SkipClient{ SignerAddress: bech32Address, @@ -73,7 +65,7 @@ func NewSkipClient( go func() { for { - account, err := client.getAccount(ethAddress) + account, err := client.getAccount(bech32Address) if err != nil { fmt.Println(err) time.Sleep(5 * time.Second) @@ -209,19 +201,47 @@ type Account struct { } func (client *SkipClient) getAccount(accountAddress string) (*Account, error) { - resp, err := http.Get(fmt.Sprintf("%s/ethermint/evm/v1/cosmos_account/%s", client.restURL, accountAddress)) + type responseType struct { + Account struct { + Type string `json:"@type"` + BaseAccount struct { + Address string `json:"address"` + PubKey struct { + Type string `json:"@type"` + Key string `json:"key"` + } `json:"pub_key"` + AccountNumber string `json:"account_number"` + Sequence string `json:"sequence"` + } `json:"base_account"` + CodeHash string `json:"code_hash"` + } `json:"account"` + } + + // https://rest.bd.evmos.org:1317/cosmos/auth/v1beta1/accounts/evmos1z92qlcv6242k6p0c4dqr5ce7rkta5ky9qmakwq" + + resp, err := http.Get(fmt.Sprintf("%s/cosmos/auth/v1beta1/accounts/%s", client.restURL, accountAddress)) if err != nil { return nil, err } - result := Account{} + defer resp.Body.Close() + + result := responseType{} err = json.NewDecoder(resp.Body).Decode(&result) if err != nil { return nil, err } - return &result, nil + account := &Account{ + AccountNumber: result.Account.BaseAccount.AccountNumber, + Sequence: result.Account.BaseAccount.Sequence, + CosmosAddress: result.Account.BaseAccount.Address, + } + + fmt.Println(account) + + return account, nil } type SendBundleResult struct { From b86714d4c8ad1230e37bfec8e4434e92c988845f Mon Sep 17 00:00:00 2001 From: thal0x Date: Mon, 10 Apr 2023 15:53:41 -0500 Subject: [PATCH 2/3] update method of retrieving account --- skipper-go/feed/feed.go | 1 - skipper-go/feed/multifeed.go | 37 ------------------------------------ skipper-go/main.go | 34 +-------------------------------- skipper-go/skip/skip.go | 4 ---- 4 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 skipper-go/feed/multifeed.go diff --git a/skipper-go/feed/feed.go b/skipper-go/feed/feed.go index 83438bb..7f64337 100644 --- a/skipper-go/feed/feed.go +++ b/skipper-go/feed/feed.go @@ -62,7 +62,6 @@ func (feed *TransactionFeed) SubscribeNewTransactions() chan *types.Transaction for { txHashes, err := feed.getUnconfirmedTransactions() if err != nil { - fmt.Println(feed.url) fmt.Println(err) continue } diff --git a/skipper-go/feed/multifeed.go b/skipper-go/feed/multifeed.go deleted file mode 100644 index ad673c3..0000000 --- a/skipper-go/feed/multifeed.go +++ /dev/null @@ -1,37 +0,0 @@ -package feed - -import ( - "github.com/ethereum/go-ethereum/core/types" - "github.com/lrita/cmap" -) - -type MultiFeed struct { - Feeds []*TransactionFeed - - knownTxs *cmap.Map[string, bool] -} - -func NewMultiFeed(urls []string, pollMs int) *MultiFeed { - feeds := make([]*TransactionFeed, len(urls)) - for i, url := range urls { - feeds[i] = NewTransactionFeed(url, pollMs) - } - return &MultiFeed{ - Feeds: feeds, - knownTxs: &cmap.Map[string, bool]{}, - } -} - -func (feed *MultiFeed) SubscribeNewTransactions() chan *types.Transaction { - ch := make(chan *types.Transaction) - - for _, feed := range feed.Feeds { - go func(feed *TransactionFeed) { - for tx := range feed.SubscribeNewTransactions() { - ch <- tx - } - }(feed) - } - - return ch -} diff --git a/skipper-go/main.go b/skipper-go/main.go index 9b076ef..ec22641 100644 --- a/skipper-go/main.go +++ b/skipper-go/main.go @@ -37,20 +37,6 @@ func startCommand() { panic(err) } - // client, err := ethclient.Dial(config.EthRPC) - // if err != nil { - // panic(err) - // } - - // block, err := client.BlockNumber(context.Background()) - // if err != nil { - // panic(err) - // } - - // fmt.Printf("connected to ethereum node, block number: %d\n", block) - - // return - backrunner, err := bot.NewBot(config, common.HexToAddress(*contractAddressFlag), key) if err != nil { panic(err) @@ -65,13 +51,7 @@ func startCommand() { knownTxs := cmap.Map[common.Hash, bool]{} - txFeed := feed.NewMultiFeed([]string{ - "https://evmos-rpc.stakely.io", - "https://tendermint.bd.evmos.org:26657", - // "https://rpc-evmos-ia.cosmosia.notional.ventures:443", - // "https://api-evmos-ia.cosmosia.notional.ventures:443", - "https://rpc.evmos.nodestake.top", - }, config.PollMs) + txFeed := feed.NewTransactionFeed(config.CosmosRPC, config.PollMs) txChan := txFeed.SubscribeNewTransactions() @@ -85,18 +65,6 @@ func startCommand() { go backrunner.OnTransaction(tx) } - - // txFeed := feed.NewTransactionFeed(config.CosmosRPC, config.PollMs) - - // txChan := txFeed.SubscribeNewTransactions() - - // for { - // tx := <-txChan - - // go backrunner.OnTransaction(tx) - // // - // // backrunner.OnTransaction(tx) - // } } func withdrawCommand() { diff --git a/skipper-go/skip/skip.go b/skipper-go/skip/skip.go index 98c855b..0221614 100644 --- a/skipper-go/skip/skip.go +++ b/skipper-go/skip/skip.go @@ -217,8 +217,6 @@ func (client *SkipClient) getAccount(accountAddress string) (*Account, error) { } `json:"account"` } - // https://rest.bd.evmos.org:1317/cosmos/auth/v1beta1/accounts/evmos1z92qlcv6242k6p0c4dqr5ce7rkta5ky9qmakwq" - resp, err := http.Get(fmt.Sprintf("%s/cosmos/auth/v1beta1/accounts/%s", client.restURL, accountAddress)) if err != nil { return nil, err @@ -239,8 +237,6 @@ func (client *SkipClient) getAccount(accountAddress string) (*Account, error) { CosmosAddress: result.Account.BaseAccount.Address, } - fmt.Println(account) - return account, nil } From a93edbac699712b0b618290d224ab1eb39283591 Mon Sep 17 00:00:00 2001 From: thal0x Date: Mon, 10 Apr 2023 15:54:29 -0500 Subject: [PATCH 3/3] update method of retrieving account --- skipper-go/bot/uniswapv2.go | 2 ++ skipper-go/main.go | 8 -------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/skipper-go/bot/uniswapv2.go b/skipper-go/bot/uniswapv2.go index ad6a234..1785393 100644 --- a/skipper-go/bot/uniswapv2.go +++ b/skipper-go/bot/uniswapv2.go @@ -70,6 +70,8 @@ func (bot *Bot) HandleUniswapV2Transaction(exchange *uniswapv2.Exchange, targetT return } + fmt.Println(tx) + fmt.Println("-----") fmt.Println("-----") fmt.Println("Arbitrage opportunity found:") diff --git a/skipper-go/main.go b/skipper-go/main.go index ec22641..4101d89 100644 --- a/skipper-go/main.go +++ b/skipper-go/main.go @@ -11,7 +11,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" - "github.com/lrita/cmap" "github.com/thal0x/bn/bigint" "github.com/skip-mev/skipper/bindings" @@ -49,8 +48,6 @@ func startCommand() { fmt.Println("backrunner listening for transactions...") - knownTxs := cmap.Map[common.Hash, bool]{} - txFeed := feed.NewTransactionFeed(config.CosmosRPC, config.PollMs) txChan := txFeed.SubscribeNewTransactions() @@ -58,11 +55,6 @@ func startCommand() { for { tx := <-txChan - _, known := knownTxs.LoadOrStore(tx.Hash(), true) - if known { - continue - } - go backrunner.OnTransaction(tx) } }