-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute.go
54 lines (44 loc) · 1.09 KB
/
compute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package compute
import (
"errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/holiman/uint256"
"github.com/qrinef/arbitrage-bot/services/pools"
)
type Service struct {
poolsService *pools.Service
routers map[common.Address]common.Address
}
func NewService(poolsService *pools.Service) *Service {
return &Service{
poolsService: poolsService,
routers: map[common.Address]common.Address{
common.HexToAddress(""): common.HexToAddress(""),
common.HexToAddress(""): common.HexToAddress(""),
},
}
}
func (s *Service) Compute(tx *types.Transaction) (err error) {
if tx == nil || tx.To() == nil {
return errors.New("tx / to address is incorrect")
}
factory, ok := s.routers[*tx.To()]
if !ok {
return errors.New("tx router not found")
}
method, err := s.decodeMethod(tx.Data(), uint256.MustFromBig(tx.Value()))
if err != nil {
return err
}
swapsData, err := s.handler(method, factory)
if err != nil {
return err
}
strategy, err := s.strategy(swapsData, factory)
if err != nil {
return err
}
_ = strategy
return err
}