Skip to content

Commit b21c36b

Browse files
authored
feat: integrate solver config (#41)
* Replace shared singer config with solver config * Update config tests to include solver config * Bump solver config lib * Add solver config options * Tidy go.sum * Add goprivate to github actions * Remove duplicate action environment * Fix actions * Add token to env * Ignore gosec solver config recomendations * Convert publish image secret to build secrets
1 parent f33a6c4 commit b21c36b

File tree

17 files changed

+252
-107
lines changed

17 files changed

+252
-107
lines changed

.github/workflows/checks.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on: [pull_request]
55
name: Linter check
66
env:
77
GO111MODULE: on
8+
GOPRIVATE: github.com/sprintertech
9+
TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
810

911
jobs:
1012
linter-check:
@@ -17,6 +19,9 @@ jobs:
1719

1820
- uses: actions/checkout@v2
1921

22+
- name: setup git access to private repos
23+
run: git config --global url."https://${TOKEN}:[email protected]/sprintertech/".insteadOf "https://github.com/sprintertech/"
24+
2025
- name: Install linter
2126
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
2227

.github/workflows/code-quality.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ on:
2020
# * * * * *
2121
- cron: '30 1 * * 0'
2222

23+
env:
24+
GO111MODULE: on
25+
GOPRIVATE: github.com/sprintertech
26+
2327
jobs:
2428
CodeQL-Build:
2529
runs-on: ubuntu-latest

.github/workflows/mocks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on: [pull_request]
55
name: Mocks check
66
env:
77
GO111MODULE: on
8+
GOPRIVATE: github.com/sprintertech
89

910
jobs:
1011
mocks-check:

.github/workflows/publish-binaries.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
release:
88
types: [published]
99

10+
env:
11+
GO111MODULE: on
12+
GOPRIVATE: github.com/sprintertech
13+
1014
jobs:
1115
publish:
1216
name: publish

.github/workflows/publish-latest.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ on:
1010
- main
1111

1212
env:
13+
GO111MODULE: on
14+
GOPRIVATE: github.com/sprintertech
1315
ORG: 'sprintertech'
1416
REGISTRY: 'ghcr.io'
17+
TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
1518

1619
jobs:
1720
build-and-push:
@@ -21,6 +24,9 @@ jobs:
2124
- name: Checkout code
2225
uses: actions/checkout@v4
2326

27+
- name: setup git access to private repos
28+
run: git config --global url."https://${TOKEN}:[email protected]/sprintertech/".insteadOf "https://github.com/sprintertech/"
29+
2430
# Log in to GHCR
2531
- name: Log in to GHCR
2632
id: ghcr
@@ -38,7 +44,7 @@ jobs:
3844
context: .
3945
push: true
4046
# Pass build arguments for the GitHub credentials
41-
build-args: |
47+
secrets: |
4248
GH_USER_NAME=${{ secrets.GH_USER_NAME }}
4349
GH_USER_TOKEN=${{ secrets.GHCR_TOKEN }}
4450
tags: |

.github/workflows/publish-tagged.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Publish Tagged Docker Image
33
permissions:
44
packages: write
55
contents: read
6-
6+
77
on:
88
release:
99
types:
@@ -12,6 +12,10 @@ on:
1212
env:
1313
ORG: 'sprintertech'
1414
REGISTRY: 'ghcr.io'
15+
GO111MODULE: on
16+
GOPRIVATE: github.com/sprintertech
17+
TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
18+
1519

1620
jobs:
1721
build-and-push:
@@ -21,6 +25,9 @@ jobs:
2125
- name: Checkout code
2226
uses: actions/checkout@v4
2327

28+
- name: setup git access to private repos
29+
run: git config --global url."https://${TOKEN}:[email protected]/sprintertech/".insteadOf "https://github.com/sprintertech/"
30+
2431
# Log in to GHCR
2532
- name: Log in to GHCR
2633
id: ghcr
@@ -38,7 +45,7 @@ jobs:
3845
context: .
3946
push: true
4047
# Pass build arguments for the GitHub credentials
41-
build-args: |
48+
secrets: |
4249
GH_USER_NAME=${{ secrets.GH_USER_NAME }}
4350
GH_USER_TOKEN=${{ secrets.GHCR_TOKEN }}
4451
tags: |

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ on:
55
pull_request:
66
types: [opened, synchronize, reopened]
77

8+
env:
9+
GO111MODULE: on
10+
GOPRIVATE: github.com/sprintertech
11+
TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
12+
813
concurrency:
914
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1015
cancel-in-progress: true
@@ -30,6 +35,8 @@ jobs:
3035
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
3136
restore-keys: |
3237
${{ runner.os }}-go-
38+
- name: setup git access to private repos
39+
run: git config --global url."https://${TOKEN}:[email protected]/sprintertech/".insteadOf "https://github.com/sprintertech/"
3340
- name: Unit tests
3441
run: make test
3542
- name: Cover

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ FROM golang:1.23 AS builder
88
ADD . /src
99
WORKDIR /src
1010
RUN cd /src && echo $(ls -1 /src)
11+
RUN --mount=type=secret,id=GH_USER_NAME \
12+
--mount=type=secret,id=GH_USER_TOKEN \
13+
GH_USER_NAME=$(cat /run/secrets/GH_USER_NAME) && \
14+
GH_USER_TOKEN=$(cat /run/secrets/GH_USER_TOKEN) && \
15+
go env -w GOPRIVATE=github.com/sprintertech && \
16+
git config --global url."https://${GH_USER_NAME}:${GH_USER_TOKEN}@github.com".insteadOf "https://github.com"
1117
RUN go mod download
1218
RUN go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore -X github.com/sprintertech/sprinter-signing/app.Version=$(sed -n '0,/## \[\([0-9.]*\)\]/s/.*\[\([0-9.]*\)\].*/\1/p' CHANGELOG.md)" -o /signing .
1319

app/app.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/libp2p/go-libp2p/core/crypto"
1919
"github.com/rs/zerolog/log"
2020
"github.com/spf13/viper"
21+
solverConfig "github.com/sprintertech/solver-config/go/config"
2122
"github.com/sprintertech/sprinter-signing/api"
2223
"github.com/sprintertech/sprinter-signing/api/handlers"
2324
"github.com/sprintertech/sprinter-signing/cache"
@@ -56,14 +57,7 @@ func Run() error {
5657
var err error
5758

5859
configFlag := viper.GetString(config.ConfigFlagName)
59-
configURL := viper.GetString("config-url")
60-
6160
var configuration *config.Config
62-
if configURL != "" {
63-
configuration, err = config.GetSharedConfigFromNetwork(configURL)
64-
panicOnError(err)
65-
}
66-
6761
if strings.ToLower(configFlag) == "env" {
6862
configuration, err = config.GetConfigFromENV(configuration)
6963
panicOnError(err)
@@ -143,17 +137,29 @@ func Run() error {
143137
confirmationsPerChain := make(map[uint64]map[uint64]uint64)
144138
domains := make(map[uint64]relayer.RelayedChain)
145139

140+
solverConfigOpts := []solverConfig.Option{
141+
solverConfig.WithCredentials(
142+
configuration.RelayerConfig.SolverConfig.AccessKey,
143+
configuration.RelayerConfig.SolverConfig.SecretKey),
144+
}
145+
staging := viper.GetBool(config.StagingFlagName)
146+
if staging {
147+
solverConfigOpts = append(solverConfigOpts, solverConfig.WithStaging())
148+
}
149+
solverConfig, err := solverConfig.FetchSolverConfig(ctx, solverConfigOpts...)
150+
panicOnError(err)
151+
146152
var hubPoolContract evmMessage.TokenMatcher
147153
var mayanSwiftContract *contracts.MayanSwiftContract
148154
acrossPools := make(map[uint64]common.Address)
149155
mayanPools := make(map[uint64]common.Address)
150-
liquidityPools := make(map[uint64]common.Address)
156+
repayerAddresses := make(map[uint64]common.Address)
151157
tokens := make(map[uint64]map[string]config.TokenConfig)
152158
for _, chainConfig := range configuration.ChainConfigs {
153159
switch chainConfig["type"] {
154160
case "evm":
155161
{
156-
c, err := evm.NewEVMConfig(chainConfig)
162+
c, err := evm.NewEVMConfig(chainConfig, *solverConfig)
157163
panicOnError(err)
158164
kp, _ := secp256k1.GenerateKeypair()
159165
client, err := evmClient.NewEVMClient(c.GeneralChainConfig.Endpoint, kp)
@@ -170,14 +176,14 @@ func Run() error {
170176
mayanSwiftContract = contracts.NewMayanSwiftContract(client, common.HexToAddress(c.MayanSwift))
171177
}
172178

173-
if c.HubPool != "" {
174-
hubPoolAddress := common.HexToAddress(c.HubPool)
179+
if c.AcrossHubPool != "" {
180+
hubPoolAddress := common.HexToAddress(c.AcrossHubPool)
175181
hubPoolContract = contracts.NewHubPoolContract(client, hubPoolAddress, c.Tokens)
176182
}
177183

178-
if c.LiquidityPool != "" {
179-
lpAddress := common.HexToAddress(c.LiquidityPool)
180-
liquidityPools[*c.GeneralChainConfig.Id] = lpAddress
184+
if c.Repayer != "" {
185+
repayerAddress := common.HexToAddress(c.Repayer)
186+
repayerAddresses[*c.GeneralChainConfig.Id] = repayerAddress
181187
}
182188

183189
tokens[*c.GeneralChainConfig.Id] = c.Tokens
@@ -194,7 +200,7 @@ func Run() error {
194200
switch chainConfig["type"] {
195201
case "evm":
196202
{
197-
c, err := evm.NewEVMConfig(chainConfig)
203+
c, err := evm.NewEVMConfig(chainConfig, *solverConfig)
198204
panicOnError(err)
199205

200206
client, err := evmClient.NewEVMClient(c.GeneralChainConfig.Endpoint, nil)
@@ -239,7 +245,7 @@ func Run() error {
239245
mayanMh := evmMessage.NewMayanMessageHandler(
240246
*c.GeneralChainConfig.Id,
241247
client,
242-
liquidityPools,
248+
repayerAddresses,
243249
mayanPools,
244250
coordinator,
245251
host,

chains/evm/config.go

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,41 @@ package evm
66
import (
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

2020
type 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

3437
type 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

4746
func (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

Comments
 (0)