Skip to content

Commit 13c0665

Browse files
authored
feat: refactor usages of chain selectors API to use remote API (#614)
This PR upgrades usages of the chain selectors lib to use the new Remote API smartcontractkit/chain-selectors#182 Notes: * The SUI and Aptos chain selectors remote APIs are not implemented yet. So we are keeping the local ones. Those chains don't have many updates so it's not as important to support that in the remote API + remote support is only available on EVM in the meantime. * A lot of the file changes are just standardising on the import name to `chainsel` * There's a couple of `context.Background` that I had to hardcode in the evm sdk. This is because we still need to provide a `ctx` variable at the interface level, which would mean a breaking change is introduced and all chain families sdk would need to be updated. I'd prefer to leave that for a separate PR to handle communications and keep things isolated in case of reverts, etc. --------- Signed-off-by: Pablo <pablo.estrada@smartcontract.com>
1 parent 043ba6d commit 13c0665

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+316
-281
lines changed

.changeset/gold-toes-lose.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smartcontractkit/mcms": minor
3+
---
4+
5+
feat: add remote chain selectors API

docs/docs/usage/building-proposals.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ object.
2020
package main
2121

2222
import (
23+
"io"
2324
"log"
2425
"os"
25-
"io"
2626

2727
"github.com/smartcontractkit/mcms"
2828
)
@@ -49,17 +49,17 @@ For the JSON structure of the proposal please check the [MCMS Proposal Format Do
4949

5050
### Build Proposal Given Staged but Non-Executed Predecessor Proposals
5151

52-
In scenarios where a proposal is generated with the assumption that multiple proposals are executed beforehand,
52+
In scenarios where a proposal is generated with the assumption that multiple proposals are executed beforehand,
5353
you can enable proposals to be signed in parallel with a pre-determined execution order. This can be achieved
5454
by passing a list of files using the `WithPredecessors` functional option, as shown below:
5555

5656
```go
5757
package main
5858

5959
import (
60+
"io"
6061
"log"
6162
"os"
62-
"io"
6363

6464
"github.com/smartcontractkit/mcms"
6565
)
@@ -102,7 +102,7 @@ package main
102102
import (
103103
"log"
104104

105-
chain_selectors "github.com/smartcontractkit/chain-selectors"
105+
chainsel "github.com/smartcontractkit/chain-selectors"
106106

107107
"github.com/smartcontractkit/mcms"
108108
"github.com/smartcontractkit/mcms/types"
@@ -111,7 +111,7 @@ import (
111111
func main() {
112112
// Step 1: Initialize the ProposalBuilder
113113
timelockBuilder := mcms.NewProposalBuilder()
114-
selector := types.ChainSelector(chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector)
114+
selector := types.ChainSelector(chainsel.ETHEREUM_TESTNET_SEPOLIA.Selector)
115115

116116
// Step 2: Set Proposal Details
117117
timelockBuilder.
@@ -198,7 +198,7 @@ package main
198198
import (
199199
"log"
200200

201-
chain_selectors "github.com/smartcontractkit/chain-selectors"
201+
chainsel "github.com/smartcontractkit/chain-selectors"
202202

203203
"github.com/smartcontractkit/mcms"
204204
"github.com/smartcontractkit/mcms/types"
@@ -207,7 +207,7 @@ import (
207207
func main() {
208208
// Step 1: Initialize the ProposalBuilder
209209
builder := mcms.NewTimelockProposalBuilder()
210-
selector := types.ChainSelector(chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector)
210+
selector := types.ChainSelector(chainsel.ETHEREUM_TESTNET_SEPOLIA.Selector)
211211

212212
delay, err := types.ParseDuration("1h")
213213
if err != nil {
@@ -334,15 +334,15 @@ accounts := []*solana.AccountMeta{
334334
PublicKey: solana.MustPublicKeyFromBase58("account pub key"),
335335
IsSigner: false,
336336
IsWritable: true,
337-
}
337+
},
338338
}
339339

340340
tx := solana.NewTransaction(
341341
"programIDGoesHere",
342342
[]byte("data bytes of the instruction"),
343343
accounts,
344344
"MySolanaContractType",
345-
[]string{"tag1", "tag2"}
345+
[]string{"tag1", "tag2"},
346346
)
347347

348348
builder.AddOperation(types.Operation{ChainSelector: selector, Transaction: tx})
@@ -367,7 +367,7 @@ tx, err := aptossdk.NewTransaction(
367367
toAddress,
368368
[]byte("calldata"),
369369
"MyAptosContractType",
370-
[]string("tag1", "tag2")
370+
[]string{"tag1", "tag2"},
371371
)
372372
if err != nil {
373373
panic(err)

docs/docs/usage/executing-proposals.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
1414
"github.com/gagliardetto/solana-go"
1515
"github.com/gagliardetto/solana-go/rpc"
16-
chain_selectors "github.com/smartcontractkit/chain-selectors"
16+
chainsel "github.com/smartcontractkit/chain-selectors"
1717

1818
"github.com/smartcontractkit/mcms"
1919
"github.com/smartcontractkit/mcms/sdk"
@@ -38,8 +38,8 @@ func main() {
3838
}
3939

4040
// Step 2: Initialize the Chain Family Executors
41-
evmSelector := chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector
42-
solanaSelector := chain_selectors.SOLANA_DEVNET.Selector
41+
evmSelector := chainsel.ETHEREUM_TESTNET_SEPOLIA.Selector
42+
solanaSelector := chainsel.SOLANA_DEVNET.Selector
4343

4444
// EVM executor
4545
backend := backends.SimulatedBackend{}

docs/docs/usage/set-config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/ethereum/go-ethereum/common"
1515
"github.com/gagliardetto/solana-go"
1616
rpc2 "github.com/gagliardetto/solana-go/rpc"
17-
chain_selectors "github.com/smartcontractkit/chain-selectors"
17+
chainsel "github.com/smartcontractkit/chain-selectors"
1818

1919
"github.com/smartcontractkit/mcms/sdk/evm"
2020
mcmsSolana "github.com/smartcontractkit/mcms/sdk/solana"
@@ -45,7 +45,7 @@ func main() {
4545
ctx := context.Background()
4646

4747
// On EVM
48-
solanaSelector := chain_selectors.SOLANA_DEVNET.Selector
48+
solanaSelector := chainsel.SOLANA_DEVNET.Selector
4949
mcmsContractAddr := "0x123"
5050
backend := backends.SimulatedBackend{}
5151
auth := &bind.TransactOpts{}

docs/docs/usage/signing-proposals.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
1515
"github.com/gagliardetto/solana-go/rpc"
16-
chain_selectors "github.com/smartcontractkit/chain-selectors"
16+
chainsel "github.com/smartcontractkit/chain-selectors"
1717

1818
"github.com/smartcontractkit/mcms"
1919
"github.com/smartcontractkit/mcms/sdk"
@@ -36,7 +36,7 @@ func main() {
3636
}
3737

3838
// 2. Create the signable type from the proposal
39-
selector := chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector
39+
selector := chainsel.ETHEREUM_TESTNET_SEPOLIA.Selector
4040

4141
// if evm required: Add EVM Inspector
4242
backend := backends.SimulatedBackend{}
@@ -45,7 +45,7 @@ func main() {
4545

4646
// if solana required: Add Solana Inspector
4747
client := rpc.New("https://api.devnet.solana.com")
48-
inspectorsMap[types.ChainSelector(chain_selectors.SOLANA_DEVNET.Selector)] = solana.NewInspector(client)
48+
inspectorsMap[types.ChainSelector(chainsel.SOLANA_DEVNET.Selector)] = solana.NewInspector(client)
4949

5050
// Create Signable
5151
signable, err := mcms.NewSignable(proposal, inspectorsMap)

docs/docs/usage/timelock-proposal-flow.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
2929
rpc2 "github.com/gagliardetto/solana-go/rpc"
30-
chain_selectors "github.com/smartcontractkit/chain-selectors"
30+
chainsel "github.com/smartcontractkit/chain-selectors"
3131

3232
"github.com/smartcontractkit/mcms"
3333
"github.com/smartcontractkit/mcms/sdk"
@@ -52,8 +52,8 @@ func main() {
5252
}
5353

5454
// 1.1 Convert to MCMS proposal
55-
selectorEVM := types.ChainSelector(chain_selectors.ETHEREUM_TESTNET_SEPOLIA.Selector)
56-
selectorSolana := types.ChainSelector(chain_selectors.SOLANA_DEVNET.Selector)
55+
selectorEVM := types.ChainSelector(chainsel.ETHEREUM_TESTNET_SEPOLIA.Selector)
56+
selectorSolana := types.ChainSelector(chainsel.SOLANA_DEVNET.Selector)
5757

5858
convertersMap := make(map[types.ChainSelector]sdk.TimelockConverter)
5959
convertersMap[selectorEVM] = &evm.TimelockConverter{}

e2e/config.evm.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type = "anvil"
1515
family = "evm"
1616

1717
[evm_config_b]
18-
chain_id = "2337"
18+
chain_id = "11155111"
1919
image = "f4hrenh9it/foundry:latest"
2020
port = "8546"
2121
type = "anvil"

e2e/ledger/ledger_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/stretchr/testify/suite"
1313

14-
cselectors "github.com/smartcontractkit/chain-selectors"
14+
chainsel "github.com/smartcontractkit/chain-selectors"
1515

1616
"github.com/smartcontractkit/mcms"
1717
e2e "github.com/smartcontractkit/mcms/e2e/tests"
@@ -108,7 +108,8 @@ func (s *ManualLedgerSigningTestSuite) setRootEVM(
108108
s.Require().NoError(err, "Failed to mine set config transaction")
109109

110110
// set root
111-
executable, err := mcms.NewExecutable(proposal, executorsMap)
111+
112+
executable, err := mcms.NewExecutable(proposal, executorsMap) //nolint:contextcheck //OPT-400
112113
s.Require().NoError(err)
113114
tx, err = executable.SetRoot(ctx, s.chainSelectorEVM)
114115
s.Require().NoError(err)
@@ -134,7 +135,8 @@ func (s *ManualLedgerSigningTestSuite) setRootSolana(
134135
s.Require().NoError(err)
135136

136137
// set root
137-
executable, err := mcms.NewExecutable(proposal, executorsMap)
138+
139+
executable, err := mcms.NewExecutable(proposal, executorsMap) //nolint:contextcheck //OPT-400
138140
s.Require().NoError(err)
139141
tx, err := executable.SetRoot(ctx, s.chainSelectorSolana)
140142
s.Require().NoError(err)
@@ -151,9 +153,9 @@ func (s *ManualLedgerSigningTestSuite) TestManualLedgerSigning() {
151153
ctx := context.Background()
152154
s.TestSetup = *e2e.InitializeSharedTestSetup(s.T())
153155

154-
chainDetailsEVM, err := cselectors.GetChainDetailsByChainIDAndFamily(s.BlockchainA.Out.ChainID, s.BlockchainA.Out.Family)
156+
chainDetailsEVM, err := chainsel.GetChainDetailsByChainIDAndFamily(s.BlockchainA.Out.ChainID, s.BlockchainA.Out.Family)
155157
s.Require().NoError(err)
156-
chainDetailsSolana, err := cselectors.GetChainDetailsByChainIDAndFamily(s.SolanaChain.ChainID, s.SolanaChain.Out.Family)
158+
chainDetailsSolana, err := chainsel.GetChainDetailsByChainIDAndFamily(s.SolanaChain.ChainID, s.SolanaChain.Out.Family)
157159
s.Require().NoError(err)
158160

159161
s.chainSelectorEVM = types.ChainSelector(chainDetailsEVM.ChainSelector)

e2e/tests/aptos/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/stretchr/testify/suite"
99

10-
cselectors "github.com/smartcontractkit/chain-selectors"
10+
chainsel "github.com/smartcontractkit/chain-selectors"
1111

1212
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
1313

@@ -34,7 +34,7 @@ type TestSuite struct {
3434

3535
func (a *TestSuite) SetupSuite() {
3636
a.TestSetup = *e2e.InitializeSharedTestSetup(a.T())
37-
details, err := cselectors.GetChainDetailsByChainIDAndFamily(a.AptosChain.ChainID, cselectors.FamilyAptos)
37+
details, err := chainsel.GetChainDetailsByChainIDAndFamily(a.AptosChain.ChainID, chainsel.FamilyAptos)
3838
a.Require().NoError(err)
3939
a.ChainSelector = types.ChainSelector(details.ChainSelector)
4040

e2e/tests/evm/executable.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/samber/lo"
1515
"github.com/stretchr/testify/suite"
1616

17-
cselectors "github.com/smartcontractkit/chain-selectors"
17+
chainsel "github.com/smartcontractkit/chain-selectors"
1818

1919
"github.com/smartcontractkit/mcms"
2020
e2e "github.com/smartcontractkit/mcms/e2e/tests"
@@ -76,7 +76,7 @@ func (s *ExecutionTestSuite) SetupSuite() {
7676
s.ChainA.auth, err = bind.NewKeyedTransactorWithChainID(privateKey, chainIDA)
7777
s.Require().NoError(err, "Failed to create transactor for Chain A")
7878

79-
chainDetailsA, err := cselectors.GetChainDetailsByChainIDAndFamily(s.BlockchainA.Out.ChainID, s.BlockchainA.Out.Family)
79+
chainDetailsA, err := chainsel.GetChainDetailsByChainIDAndFamily(s.BlockchainA.Out.ChainID, s.BlockchainA.Out.Family)
8080
s.Require().NoError(err)
8181
s.ChainA.chainSelector = mcmtypes.ChainSelector(chainDetailsA.ChainSelector)
8282

@@ -87,7 +87,7 @@ func (s *ExecutionTestSuite) SetupSuite() {
8787
s.ChainB.auth, err = bind.NewKeyedTransactorWithChainID(privateKey, chainIDB)
8888
s.Require().NoError(err, "Failed to create transactor for Chain B")
8989

90-
chainDetailsB, err := cselectors.GetChainDetailsByChainIDAndFamily(s.BlockchainB.Out.ChainID, s.BlockchainB.Out.Family)
90+
chainDetailsB, err := chainsel.GetChainDetailsByChainIDAndFamily(s.BlockchainB.Out.ChainID, s.BlockchainB.Out.Family)
9191
s.Require().NoError(err)
9292
s.ChainB.chainSelector = mcmtypes.ChainSelector(chainDetailsB.ChainSelector)
9393

0 commit comments

Comments
 (0)