@@ -6,42 +6,41 @@ package evm
66import (
77 "fmt"
88 "math/big"
9- "strconv"
109 "time"
1110
1211 "github.com/creasty/defaults"
1312 "github.com/ethereum/go-ethereum/common"
1413 "github.com/mitchellh/mapstructure"
1514
15+ solverConfig "github.com/sprintertech/solver-config/go/config"
1616 "github.com/sprintertech/sprinter-signing/config"
1717 "github.com/sprintertech/sprinter-signing/config/chain"
1818)
1919
2020type EVMConfig struct {
2121 GeneralChainConfig chain.GeneralChainConfig
2222 Admin string
23- AcrossPool string
24- HubPool string
25- MayanSwift string
26- LiquidityPool string
27- Tokens map [string ]config.TokenConfig
23+
24+ AcrossPool string
25+ AcrossHubPool string
26+ MayanSwift string
27+ Repayer string
28+
29+ Tokens map [string ]config.TokenConfig
2830 // usd bucket -> confirmations
2931 ConfirmationsByValue map [uint64 ]uint64
30- BlockInterval * big.Int
31- BlockRetryInterval time.Duration
32+
33+ BlockInterval * big.Int
34+ BlockRetryInterval time.Duration
3235}
3336
3437type RawEVMConfig struct {
3538 chain.GeneralChainConfig `mapstructure:",squash"`
36- Admin string `mapstructure:"admin"`
37- LiquidityPool string `mapstructure:"liquidityPool"`
38- AcrossPool string `mapstructure:"acrossPool"`
39- MayanSwift string `mapstructure:"mayanSwift"`
40- HubPool string `mapstructure:"hubPool"`
41- Tokens map [string ]interface {} `mapstructure:"tokens"`
42- ConfirmationsByValue map [string ]interface {} `mapstructure:"confirmationsByValue"`
43- BlockInterval int64 `mapstructure:"blockInterval" default:"5"`
44- BlockRetryInterval uint64 `mapstructure:"blockRetryInterval" default:"5"`
39+ Admin string `mapstructure:"admin"`
40+ Repayer string `mapstructure:"repayer"`
41+
42+ BlockInterval int64 `mapstructure:"blockInterval" default:"5"`
43+ BlockRetryInterval uint64 `mapstructure:"blockRetryInterval" default:"5"`
4544}
4645
4746func (c * RawEVMConfig ) Validate () error {
@@ -53,7 +52,7 @@ func (c *RawEVMConfig) Validate() error {
5352
5453// NewEVMConfig decodes and validates an instance of an EVMConfig from
5554// raw chain config
56- func NewEVMConfig (chainConfig map [string ]interface {}) (* EVMConfig , error ) {
55+ func NewEVMConfig (chainConfig map [string ]interface {}, solverConfig solverConfig. SolverConfig ) (* EVMConfig , error ) {
5756 var c RawEVMConfig
5857 err := mapstructure .Decode (chainConfig , & c )
5958 if err != nil {
@@ -70,49 +69,39 @@ func NewEVMConfig(chainConfig map[string]interface{}) (*EVMConfig, error) {
7069 return nil , err
7170 }
7271
73- tokens := make (map [string ]config.TokenConfig )
74- for s , c := range c .Tokens {
75- c := c .(map [string ]interface {})
76-
77- decimals , err := strconv .ParseUint (c ["decimals" ].(string ), 10 , 8 )
78- if err != nil {
79- return nil , err
80- }
72+ id := fmt .Sprintf ("eip155:%d" , * c .Id )
73+ sc , ok := solverConfig .Chains [id ]
74+ if ! ok {
75+ return nil , fmt .Errorf ("no solver config for chain %d" , c .Id )
76+ }
8177
78+ tokens := make (map [string ]config.TokenConfig )
79+ for s , c := range sc .Tokens {
8280 tc := config.TokenConfig {
83- Address : common .HexToAddress (c ["address" ].(string )),
84- Decimals : uint8 (decimals ),
81+ Address : common .HexToAddress (c .Address ),
82+ // nolint:gosec
83+ Decimals : uint8 (c .Decimals ),
8584 }
8685 tokens [s ] = tc
8786 }
8887
8988 confirmations := make (map [uint64 ]uint64 )
90- for usd , confirmation := range c .ConfirmationsByValue {
91- usd , err := strconv .ParseUint (usd , 10 , 64 )
92- if err != nil {
93- return nil , err
94- }
95-
96- confirmation , err := strconv .ParseUint (confirmation .(string ), 10 , 64 )
97- if err != nil {
98- return nil , err
99- }
100-
101- if confirmation < 1 {
102- return nil , fmt .Errorf ("confirmation cannot be lower than 1" )
103- }
104-
105- confirmations [usd ] = confirmation
89+ for _ , confirmation := range sc .Confirmations {
90+ // nolint:gosec
91+ confirmations [uint64 (confirmation .MaxAmountUSD )] = uint64 (confirmation .Confirmations )
10692 }
10793
10894 c .ParseFlags ()
10995 config := & EVMConfig {
11096 GeneralChainConfig : c .GeneralChainConfig ,
11197 Admin : c .Admin ,
112- LiquidityPool : c .LiquidityPool ,
113- AcrossPool : c .AcrossPool ,
114- HubPool : c .HubPool ,
115- MayanSwift : c .MayanSwift ,
98+ Repayer : c .Repayer ,
99+
100+ AcrossPool : solverConfig .ProtocolsMetadata .Across .SpokePools [id ],
101+ AcrossHubPool : solverConfig .ProtocolsMetadata .Across .HubPools [id ],
102+
103+ MayanSwift : solverConfig .ProtocolsMetadata .Mayan .SwiftContracts [id ],
104+
116105 // nolint:gosec
117106 BlockRetryInterval : time .Duration (c .BlockRetryInterval ) * time .Second ,
118107 BlockInterval : big .NewInt (c .BlockInterval ),
0 commit comments