Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-chairs-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smartcontractkit/mcms": patch
---

chore: refactor aptos curse converter constructor as a func. option
7 changes: 4 additions & 3 deletions chainwrappers/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func BuildConverters(chainMetadata map[types.ChainSelector]types.ChainMetadata)
case chainsel.FamilyAptos:
converter, err = buildAptosTimelockConverter(metadata)
if err != nil {
return nil, fmt.Errorf("error creating Aptos converter for selector %d: %w", selector, err)
return nil, fmt.Errorf("failed to create Aptos converter for selector %d: %w", selector, err)
}
case chainsel.FamilySui:
converter, _ = sui.NewTimelockConverter()
Expand All @@ -59,9 +59,10 @@ func buildAptosTimelockConverter(metadata types.ChainMetadata) (sdk.TimelockConv
return nil, fmt.Errorf("failed to unmarshal Aptos additional fields: %w", err)
}

opts := []aptos.TimelockConverterOption{}
if af.MCMSType.IsCurseMCMS() {
return aptos.NewCurseTimelockConverter(), nil
opts = append(opts, aptos.WithMCMSType(aptos.MCMSTypeCurse))
}

return aptos.NewTimelockConverter(), nil
return aptos.NewTimelockConverter(opts...), nil
}
31 changes: 24 additions & 7 deletions sdk/aptos/timelock_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,35 @@ type TimelockConverter struct {
encoderFn func(address aptos.AccountAddress, client aptos.AptosRpcClient) timelockEncoder
}

func NewTimelockConverter() *TimelockConverter {
return &TimelockConverter{
encoderFn: func(address aptos.AccountAddress, client aptos.AptosRpcClient) timelockEncoder {
return mcms.Bind(address, client).MCMS().Encoder()
},
type TimelockConverterOption func(*timelockConverterOptions)

type timelockConverterOptions struct {
mcmsType MCMSType
}

func WithMCMSType(mcmsType MCMSType) TimelockConverterOption {
return func(opts *timelockConverterOptions) {
opts.mcmsType = mcmsType
}
}

func NewCurseTimelockConverter() *TimelockConverter {
func NewTimelockConverter(opts ...TimelockConverterOption) *TimelockConverter {
converterOptions := timelockConverterOptions{mcmsType: MCMSTypeRegular}
for _, opt := range opts {
opt(&converterOptions)
}

if converterOptions.mcmsType == MCMSTypeCurse {
return &TimelockConverter{
encoderFn: func(address aptos.AccountAddress, client aptos.AptosRpcClient) timelockEncoder {
return curse_mcms.Bind(address, client).CurseMCMS().Encoder()
},
}
}
Comment on lines +48 to +60
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes the exported NewCurseTimelockConverter constructor entirely. If sdk/aptos is consumed as a library, that’s a breaking API change; consider keeping NewCurseTimelockConverter as a thin wrapper around NewTimelockConverter(WithMCMSType(MCMSTypeCurse)) (optionally marked deprecated) to preserve backward compatibility.

Copilot uses AI. Check for mistakes.

return &TimelockConverter{
encoderFn: func(address aptos.AccountAddress, client aptos.AptosRpcClient) timelockEncoder {
return curse_mcms.Bind(address, client).CurseMCMS().Encoder()
return mcms.Bind(address, client).MCMS().Encoder()
},
}
}
Expand Down
6 changes: 2 additions & 4 deletions sdk/aptos/timelock_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ import (

func TestNewTimelockConverter(t *testing.T) {
t.Parallel()

converter := NewTimelockConverter()
assert.NotNil(t, converter)
assert.NotNil(t, converter.encoderFn)
}

func TestNewCurseTimelockConverter(t *testing.T) {
t.Parallel()
converter := NewCurseTimelockConverter()
converter = NewTimelockConverter(WithMCMSType(MCMSTypeCurse))
assert.NotNil(t, converter)
assert.NotNil(t, converter.encoderFn)
}
Expand Down
Loading