Skip to content

Commit

Permalink
LM-168-Rename-liquidityrebalancer-package-and-interface (#1093)
Browse files Browse the repository at this point in the history
## Motivation


## Solution
  • Loading branch information
cmalec authored Jun 27, 2024
1 parent 0519f29 commit 434129b
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 35 deletions.
10 changes: 5 additions & 5 deletions core/services/ocr2/plugins/liquiditymanager/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/bridge"
liquiditymanager "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/chain/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/discoverer"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/liquidityrebalancer"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/models"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/rebalalgo"
)

const (
Expand Down Expand Up @@ -60,14 +60,14 @@ func NewPluginFactory(
}, nil
}

func (p PluginFactory) buildRebalancer() (liquidityrebalancer.Rebalancer, error) {
func (p PluginFactory) buildRebalancer() (rebalalgo.RebalancingAlgo, error) {
switch p.config.RebalancerConfig.Type {
case models.RebalancerTypePingPong:
return liquidityrebalancer.NewPingPong(), nil
return rebalalgo.NewPingPong(), nil
case models.RebalancerTypeMinLiquidity:
return liquidityrebalancer.NewMinLiquidityRebalancer(p.lggr), nil
return rebalalgo.NewMinLiquidityRebalancer(p.lggr), nil
case models.RebalancerTypeTargetAndMin:
return liquidityrebalancer.NewTargetMinBalancer(p.lggr), nil
return rebalalgo.NewTargetMinBalancer(p.lggr), nil
default:
return nil, fmt.Errorf("invalid rebalancer type %s", p.config.RebalancerConfig.Type)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions core/services/ocr2/plugins/liquiditymanager/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
import (
"errors"
"fmt"
"math/big"
"slices"
)

Expand All @@ -19,6 +20,11 @@ type RebalancerConfig struct {
Type string `json:"type"`
}

type NetworkTarget struct {
Network NetworkSelector `json:"network,string"`
Target *big.Int `json:"target"`
}

func ValidateRebalancerConfig(config RebalancerConfig) error {
if config.Type == "" {
return errors.New("rebalancerType must be provided")
Expand Down
10 changes: 5 additions & 5 deletions core/services/ocr2/plugins/liquiditymanager/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/discoverer"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/graph"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/inflight"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/liquidityrebalancer"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/models"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/rebalalgo"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/rebalcalc"
)

Expand All @@ -33,7 +33,7 @@ type Plugin struct {
bridgeFactory bridge.Factory
mu sync.RWMutex
liquidityGraph graph.Graph
liquidityRebalancer liquidityrebalancer.Rebalancer
liquidityRebalancer rebalalgo.RebalancingAlgo
inflight inflight.Container
lggr logger.Logger
reportCodec evmliquiditymanager.OnchainReportCodec
Expand All @@ -47,7 +47,7 @@ func NewPlugin(
liquidityManagerFactory evmliquiditymanager.Factory,
discoverer discoverer.Discoverer,
bridgeFactory bridge.Factory,
liquidityRebalancer liquidityrebalancer.Rebalancer,
liquidityRebalancer rebalalgo.RebalancingAlgo,
reportCodec evmliquiditymanager.OnchainReportCodec,
lggr logger.Logger,
) *Plugin {
Expand Down Expand Up @@ -217,8 +217,8 @@ func combinedUnexecutedTransfers(
pendingTransfers []models.PendingTransfer,
resolvedTransfersQuorum []models.Transfer,
inflightTransfers []models.Transfer,
) []liquidityrebalancer.UnexecutedTransfer {
unexecuted := make([]liquidityrebalancer.UnexecutedTransfer, 0, len(resolvedTransfersQuorum)+len(inflightTransfers)+len(pendingTransfers))
) []rebalalgo.UnexecutedTransfer {
unexecuted := make([]rebalalgo.UnexecutedTransfer, 0, len(resolvedTransfersQuorum)+len(inflightTransfers)+len(pendingTransfers))
for _, resolvedTransfer := range resolvedTransfersQuorum {
unexecuted = append(unexecuted, resolvedTransfer)
}
Expand Down
8 changes: 4 additions & 4 deletions core/services/ocr2/plugins/liquiditymanager/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import (
liquiditymanagermocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/chain/evm/mocks"
discoverermocks "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/discoverer/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/graph"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/liquidityrebalancer"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/models"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/rebalalgo"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/liquiditymanager/testhelpers"
)

Expand Down Expand Up @@ -1563,7 +1563,7 @@ func newNode(t *testing.T, lggr logger.Logger, f int) node {
// discovererMock.On("Discover", mock.Anything).Return(g, nil).Maybe()
discovererFactory.On("NewDiscoverer", mock.Anything, mock.Anything).Return(discovererMock, nil).Maybe()
bridgeFactory := bridgemocks.NewFactory(t)
rebalancerAlg := liquidityrebalancer.NewPingPong()
rebalancerAlg := rebalalgo.NewPingPong()

node1 := NewPlugin(
f,
Expand Down Expand Up @@ -1603,7 +1603,7 @@ type pluginWithMocks struct {
lmFactory *mocks.Factory
discovererFactory *discoverermocks.Factory
bridgeFactory *bridgemocks.Factory
rebalancerAlg *liquidityrebalancer.PingPong
rebalancerAlg *rebalalgo.PingPong
}

func newPluginWithMocksAndDefaults(t *testing.T) *pluginWithMocks {
Expand All @@ -1625,7 +1625,7 @@ func newPluginWithMocks(
discovererMock := discoverermocks.NewDiscoverer(t)
discovererFactory.On("NewDiscoverer", mock.Anything, mock.Anything).Return(discovererMock, nil).Maybe()
bridgeFactory := bridgemocks.NewFactory(t)
rebalancerAlg := liquidityrebalancer.NewPingPong()
rebalancerAlg := rebalalgo.NewPingPong()
return &pluginWithMocks{
plugin: NewPlugin(
f,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package liquidityrebalancer
package rebalalgo

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package liquidityrebalancer
package rebalalgo

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package liquidityrebalancer
package rebalalgo

import (
"math/big"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package liquidityrebalancer
package rebalalgo

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package liquidityrebalancer
package rebalalgo

import (
"math/big"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package liquidityrebalancer
package rebalalgo

import (
"math/big"
Expand All @@ -17,8 +17,8 @@ type UnexecutedTransfer interface {
TransferStatus() models.TransferStatus
}

//go:generate mockery --quiet --name Rebalancer --output ../mocks --filename rebalancer_mock.go --case=underscore
type Rebalancer interface {
//go:generate mockery --quiet --name RebalancingAlgo --output ../mocks --filename rebalancer_mock.go --case=underscore
type RebalancingAlgo interface {
// ComputeTransfersToBalance computes the transfers needed to balance the
// liquidity across the provided graph. The rebalancer will also take into account
// currently unexecuted transfers to avoid proposing transfers that would be
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package liquidityrebalancer
package rebalalgo

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package liquidityrebalancer
package rebalalgo

import (
"math/big"
Expand Down

0 comments on commit 434129b

Please sign in to comment.