Skip to content

Commit

Permalink
Add Router to CCIP Offramp interface (#420)
Browse files Browse the repository at this point in the history
* Get router from offramp

* fix ctx
  • Loading branch information
matYang authored Mar 22, 2024
1 parent c0188fb commit c150979
Show file tree
Hide file tree
Showing 7 changed files with 429 additions and 255 deletions.
20 changes: 20 additions & 0 deletions pkg/loop/internal/ccip/offramp.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ func (o *OffRampReaderGRPCClient) GetTokens(ctx context.Context) (cciptypes.OffR
return offRampTokens(resp.Tokens), nil
}

// GetRouter i[github.com/smartcontractkit/chainlink-common/pkg/types/ccip.OffRampReader]
func (o *OffRampReaderGRPCClient) GetRouter(ctx context.Context) (cciptypes.Address, error) {
resp, err := o.client.GetRouter(ctx, &emptypb.Empty{})
if err != nil {
return cciptypes.Address(""), err
}
return cciptypes.Address(resp.Router), nil
}

// OffchainConfig i[github.com/smartcontractkit/chainlink-common/pkg/types/ccip.OffRampReader]
func (o *OffRampReaderGRPCClient) OffchainConfig(ctx context.Context) (cciptypes.ExecOffchainConfig, error) {
resp, err := o.client.OffchainConfig(ctx, &emptypb.Empty{})
Expand All @@ -244,6 +253,7 @@ func (o *OffRampReaderGRPCClient) OnchainConfig(ctx context.Context) (cciptypes.
}
return cciptypes.ExecOnchainConfig{
PermissionLessExecutionThresholdSeconds: resp.Config.PermissionlessExecThresholdSeconds.AsDuration(),
Router: cciptypes.Address(resp.Config.Router),
}, nil
}

Expand Down Expand Up @@ -375,6 +385,15 @@ func (o *OffRampReaderGRPCServer) GetTokens(ctx context.Context, req *emptypb.Em
return &ccippb.GetTokensResponse{Tokens: offRampTokensToPB(tokens)}, nil
}

// GetRouter implements ccippb.OffRampReaderServer.
func (o *OffRampReaderGRPCServer) GetRouter(ctx context.Context, req *emptypb.Empty) (*ccippb.GetRouterResponse, error) {
router, err := o.impl.GetRouter(ctx)
if err != nil {
return nil, err
}
return &ccippb.GetRouterResponse{Router: string(router)}, nil
}

// OffchainConfig implements ccippb.OffRampReaderServer.
func (o *OffRampReaderGRPCServer) OffchainConfig(ctx context.Context, req *emptypb.Empty) (*ccippb.OffchainConfigResponse, error) {
config, err := o.impl.OffchainConfig(ctx)
Expand All @@ -392,6 +411,7 @@ func (o *OffRampReaderGRPCServer) OnchainConfig(ctx context.Context, req *emptyp
}
pbConfig := ccippb.ExecOnchainConfig{
PermissionlessExecThresholdSeconds: durationpb.New(config.PermissionLessExecutionThresholdSeconds),
Router: string(config.Router),
}
return &ccippb.OnchainConfigResponse{Config: &pbConfig}, nil
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/loop/internal/ccip/test/offramp.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ var OffRampReader = staticOffRamp{
ccip.Address("key1"): ccip.Address("value1"),
},
},

// GetRouter test data
getRouterResponse: ccip.Address("getRouterResponse"),
},
}

Expand Down Expand Up @@ -187,6 +190,8 @@ type staticOffRampConfig struct {

getTokensResponse ccip.OffRampTokens

getRouterResponse ccip.Address

offchainConfigResponse ccip.ExecOffchainConfig

onchainConfigResponse ccip.ExecOnchainConfig
Expand Down Expand Up @@ -294,6 +299,11 @@ func (s staticOffRamp) GetTokens(ctx context.Context) (ccip.OffRampTokens, error
return s.getTokensResponse, nil
}

// GetRouter implements OffRampEvaluator.
func (s staticOffRamp) GetRouter(ctx context.Context) (ccip.Address, error) {
return s.getRouterResponse, nil
}

// OffchainConfig implements OffRampEvaluator.
func (s staticOffRamp) OffchainConfig(ctx context.Context) (ccip.ExecOffchainConfig, error) {
return s.offchainConfigResponse, nil
Expand Down Expand Up @@ -439,6 +449,14 @@ func (s staticOffRamp) Evaluate(ctx context.Context, other ccip.OffRampReader) e
return fmt.Errorf("expected getTokens %v but got %v", s.getTokensResponse, getTokens)
}

getRouter, err := other.GetRouter(ctx)
if err != nil {
return fmt.Errorf("failed to get getRouter: %w", err)
}
if getRouter != s.getRouterResponse {
return fmt.Errorf("expected getRouter %s but got %s", s.getRouterResponse, getRouter)
}

offchainConfig, err := other.OffchainConfig(ctx)
if err != nil {
return fmt.Errorf("failed to get offchainConfig: %w", err)
Expand Down
6 changes: 6 additions & 0 deletions pkg/loop/internal/ccip/test/offramp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ func roundTripOffRampTests(ctx context.Context, t *testing.T, client *ccip.OffRa
assert.Equal(t, OffRampReader.getTokensResponse, tokens)
})

t.Run("GetRouter", func(t *testing.T) {
router, err := client.GetRouter(ctx)
require.NoError(t, err)
assert.Equal(t, OffRampReader.getRouterResponse, router)
})

t.Run("OffchainConfig", func(t *testing.T) {
config, err := client.OffchainConfig(ctx)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit c150979

Please sign in to comment.