Skip to content

Commit 5f12162

Browse files
feat: update docs to include solana examples [DPA-1468] (#263)
Update documentation with Solana SDK usage. This pull request includes significant updates to the documentation and codebase to support both EVM and Solana operations. The changes include adding new sections to the documentation, updating examples to include Solana operations, and modifying existing functions to support Solana transactions. Documentation updates: * [`docs/usage/building-proposals.md`](diffhunk://#diff-f2c895c7db2493321408b30577edeb76dd8247a05c9dc7b78933350654d50cfbL3-R11): Added a table of contents and new sections for EVM and Solana operations, including examples of how to build chain-specific transactions. [[1]](diffhunk://#diff-f2c895c7db2493321408b30577edeb76dd8247a05c9dc7b78933350654d50cfbL3-R11) [[2]](diffhunk://#diff-f2c895c7db2493321408b30577edeb76dd8247a05c9dc7b78933350654d50cfbR257-R301) * [`docs/usage/contract-inspection.md`](diffhunk://#diff-7bd3cd1c719d5716be3268cd8e6c501aa9dc6239ba2717acc0ad3075b18e438cL5-R14): Added sections for EVM and Solana inspections with examples for inspecting MCMS and timelock contracts on both chains. [[1]](diffhunk://#diff-7bd3cd1c719d5716be3268cd8e6c501aa9dc6239ba2717acc0ad3075b18e438cL5-R14) [[2]](diffhunk://#diff-7bd3cd1c719d5716be3268cd8e6c501aa9dc6239ba2717acc0ad3075b18e438cL55-R64) [[3]](diffhunk://#diff-7bd3cd1c719d5716be3268cd8e6c501aa9dc6239ba2717acc0ad3075b18e438cR140-R280) * [`docs/usage/executing-proposals.md`](diffhunk://#diff-6ad3c9eb17115042ad9f06566434efd865c2e42892a7c8f41aa4a52445791405R9-R27): Updated examples to include both EVM and Solana executors and operations. [[1]](diffhunk://#diff-6ad3c9eb17115042ad9f06566434efd865c2e42892a7c8f41aa4a52445791405R9-R27) [[2]](diffhunk://#diff-6ad3c9eb17115042ad9f06566434efd865c2e42892a7c8f41aa4a52445791405L36-R87) * [`docs/usage/set-config.md`](diffhunk://#diff-e422368e569c4be5329fb9f9b27c501ba22839cc3bde0a6db5016efb1b4c677aR9-R20): Added examples for setting configuration on both EVM and Solana. [[1]](diffhunk://#diff-e422368e569c4be5329fb9f9b27c501ba22839cc3bde0a6db5016efb1b4c677aR9-R20) [[2]](diffhunk://#diff-e422368e569c4be5329fb9f9b27c501ba22839cc3bde0a6db5016efb1b4c677aR45-R70) * [`docs/usage/signing-proposals.md`](diffhunk://#diff-a5997610f4f18eabb2a378ebcd6420d8208bd2ff06e250a4b46b7c0cb7a84116R15-R21): Included Solana inspector in the signing proposals example. [[1]](diffhunk://#diff-a5997610f4f18eabb2a378ebcd6420d8208bd2ff06e250a4b46b7c0cb7a84116R15-R21) [[2]](diffhunk://#diff-a5997610f4f18eabb2a378ebcd6420d8208bd2ff06e250a4b46b7c0cb7a84116R40-R50) * [`docs/usage/timelock-proposal-flow.md`](diffhunk://#diff-f7366839527870209c28c70f0bd2901e5ef262c816365a737565c6f94250b512R29-R35): Updated timelock proposal flow to support both EVM and Solana. [[1]](diffhunk://#diff-f7366839527870209c28c70f0bd2901e5ef262c816365a737565c6f94250b512R29-R35) [[2]](diffhunk://#diff-f7366839527870209c28c70f0bd2901e5ef262c816365a737565c6f94250b512L53-R60) [[3]](diffhunk://#diff-f7366839527870209c28c70f0bd2901e5ef262c816365a737565c6f94250b512L64-R71) Code updates: * [`e2e/tests/evm/executable.go`](diffhunk://#diff-bbe2ffda1b9ebcc15c396ab8d7423168da6a71a0939b685bbf7c8fb98b85c85fL152-R152): Replaced `evm.NewOperation` with `evm.NewTransaction` in multiple test cases to reflect the updated function name. [[1]](diffhunk://#diff-bbe2ffda1b9ebcc15c396ab8d7423168da6a71a0939b685bbf7c8fb98b85c85fL152-R152) [[2]](diffhunk://#diff-bbe2ffda1b9ebcc15c396ab8d7423168da6a71a0939b685bbf7c8fb98b85c85fL277-R277) [[3]](diffhunk://#diff-bbe2ffda1b9ebcc15c396ab8d7423168da6a71a0939b685bbf7c8fb98b85c85fL387-R387) * [`executable_test.go`](diffhunk://#diff-a58de0dcac6ed4265c64734bdd796348f6d4b120c6abd6a099b3e96ee64bbf7fL142-R142): Updated test cases to use `evm.NewTransaction` instead of `evm.NewOperation`. [[1]](diffhunk://#diff-a58de0dcac6ed4265c64734bdd796348f6d4b120c6abd6a099b3e96ee64bbf7fL142-R142) [[2]](diffhunk://#diff-a58de0dcac6ed4265c64734bdd796348f6d4b120c6abd6a099b3e96ee64bbf7fL263-R263) [[3]](diffhunk://#diff-a58de0dcac6ed4265c64734bdd796348f6d4b120c6abd6a099b3e96ee64bbf7fL379-R379) [[4]](diffhunk://#diff-a58de0dcac6ed4265c64734bdd796348f6d4b120c6abd6a099b3e96ee64bbf7fL516-R516) * [`sdk/evm/encoder_test.go`](diffhunk://#diff-89878e327ef9b5fd7b36336cced2ca1717c64105ebd0c6f27ac546038efb0f1aL39-R39): Modified encoder tests to use `NewTransaction` for creating EVM transactions. [[1]](diffhunk://#diff-89878e327ef9b5fd7b36336cced2ca1717c64105ebd0c6f27ac546038efb0f1aL39-R39) [[2]](diffhunk://#diff-89878e327ef9b5fd7b36336cced2ca1717c64105ebd0c6f27ac546038efb0f1aL150-R150) * [`sdk/evm/operation.go`](diffhunk://#diff-a9c98a174c17d0c6331f9481acfec27c452027cfea530cb2586408850d03c48dL26-R26): Renamed `NewOperation` to `NewTransaction` to better reflect its purpose. --------- Co-authored-by: Graham Goh <[email protected]>
1 parent a481d17 commit 5f12162

16 files changed

+709
-434
lines changed

docs/usage/building-proposals.md

+250-191
Large diffs are not rendered by default.

docs/usage/contract-inspection.md

+250-100
Original file line numberDiff line numberDiff line change
@@ -2,130 +2,280 @@
22

33
You can use the chain specific SDKs to inspect the state of your MCMS and timelock contracts.
44

5-
### Example: MCMS Inspection
5+
- [EVM](#evm)
6+
- [MCMS Inspection](#example-evm-mcms-inspection)
7+
- [Timelock Inspection](#example-evm-timelock-inspection)
8+
- [Solana](#solana)
9+
- [MCMS Inspection](#example-solana-mcms-inspection)
10+
- [Timelock Inspection](#example-solana-timelock-inspection)
11+
12+
## EVM
13+
14+
### Example: EVM MCMS Inspection
15+
16+
```go
17+
package main
18+
19+
import (
20+
"log"
21+
22+
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
23+
24+
"github.com/smartcontractkit/mcms/sdk/evm"
25+
)
26+
27+
func main() {
28+
// Inspecting MCMS contract on EVM
29+
backend := backends.SimulatedBackend{}
30+
inspector := evm.NewInspector(backend)
31+
contractAddress := "0x123" // replace with your address
32+
33+
// Get the op count
34+
opcount, err := inspector.GetOpCount(contractAddress)
35+
if err != nil {
36+
log.Fatalf("failed to get op count: %v", err)
37+
}
38+
log.Printf("Op count: %d", opcount)
39+
40+
// Get the config
41+
config, err := inspector.GetConfig(contractAddress)
42+
if err != nil {
43+
log.Fatalf("failed to get config: %v", err)
44+
}
45+
log.Printf("Config: %+v", config)
46+
47+
// Get the root
48+
root, validUntil, err := inspector.GetRoot(contractAddress)
49+
if err != nil {
50+
log.Fatalf("failed to get root: %v", err)
51+
}
52+
log.Printf("Root: %s, Valid until: %d", root.Hex(), validUntil)
53+
54+
// Get the proposers
55+
metadata, err := inspector.GetRootMetadata(contractAddress)
56+
if err != nil {
57+
log.Fatalf("failed to get root metadata: %v", err)
58+
}
59+
log.Printf("Metadata: %+v", metadata)
60+
61+
}
62+
```
63+
64+
### Example: EVM Timelock Inspection
65+
66+
```go
67+
package main
68+
69+
import (
70+
"fmt"
71+
"log"
72+
73+
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
74+
75+
"github.com/smartcontractkit/mcms/sdk/evm"
76+
)
77+
78+
func main() {
79+
// Inspecting Timelock contract on EVM
80+
backend := backends.SimulatedBackend{}
81+
inspector := evm.NewTimelockInspector(backend)
82+
contractAddress := "0x123" // replace with your address
83+
84+
// Get the proposers
85+
proposers, err := inspector.GetProposers(contractAddress)
86+
if err != nil {
87+
log.Fatalf("failed to get op count: %v", err)
88+
}
89+
log.Printf("proposers: %d", proposers)
90+
91+
// Get the bypassers
92+
bypassers, err := inspector.GetBypassers(contractAddress)
93+
if err != nil {
94+
log.Fatalf("failed to get bypassers: %v", err)
95+
}
96+
log.Printf("bypassers: %+v", bypassers)
97+
98+
// Get the executors
99+
executors, err := inspector.GetExecutors(contractAddress)
100+
if err != nil {
101+
log.Fatalf("failed to get executors: %v", err)
102+
}
103+
log.Printf("executors: %s", executors)
104+
105+
// Get the cancellers
106+
cancellers, err := inspector.GetCancellers(contractAddress)
107+
if err != nil {
108+
log.Fatalf("failed to get root metadata: %v", err)
109+
}
110+
log.Printf("Metadata: %+v", cancellers)
111+
112+
// Get operation statuses, opID is a [32]byte representing the operation ID
113+
opID := [32]byte{} // replace with your operation ID
114+
isOp, err := inspector.IsOperation(contractAddress, opID)
115+
if err != nil {
116+
log.Fatalf("failed to get operation status: %v", err)
117+
}
118+
log.Printf("IsOperation: %t", isOp)
119+
120+
isReady, err := inspector.IsOperationReady(contractAddress, opID)
121+
if err != nil {
122+
log.Fatalf("failed to get operation status: %v", err)
123+
}
124+
fmt.Printf("IsOperationReady: %t", isReady)
125+
126+
isPending, err := inspector.IsOperationPending(contractAddress, opID)
127+
if err != nil {
128+
log.Fatalf("failed to get operation status: %v", err)
129+
}
130+
fmt.Printf("IsOperationPending: %t", isPending)
131+
132+
isDone, err := inspector.IsOperationDone(contractAddress, opID)
133+
if err != nil {
134+
log.Fatalf("failed to get operation status: %v", err)
135+
}
136+
fmt.Printf("IsOperationDone: %t", isDone)
137+
138+
}
139+
140+
```
141+
142+
## Solana
143+
144+
### Example: Solana MCMS Inspection
6145

7146
```go
8147
package main
9148

10149
import (
11-
"log"
150+
"context"
151+
"log"
12152

13-
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
153+
"github.com/gagliardetto/solana-go"
154+
"github.com/gagliardetto/solana-go/rpc"
14155

15-
"github.com/smartcontractkit/mcms/sdk/evm"
156+
mcmsSolana "github.com/smartcontractkit/mcms/sdk/solana"
16157
)
17158

18159
func main() {
19-
// Inspecting MCMS contract on EVM
20-
backend := backends.SimulatedBackend{}
21-
inspector := evm.NewInspector(backend)
22-
contractAddress := "0x123" // replace with your address
23-
24-
// Get the op count
25-
opcount, err := inspector.GetOpCount(contractAddress)
26-
if err != nil {
27-
log.Fatalf("failed to get op count: %v", err)
28-
}
29-
log.Printf("Op count: %d", opcount)
30-
31-
// Get the config
32-
config, err := inspector.GetConfig(contractAddress)
33-
if err != nil {
34-
log.Fatalf("failed to get config: %v", err)
35-
}
36-
log.Printf("Config: %+v", config)
37-
38-
// Get the root
39-
root, validUntil, err := inspector.GetRoot(contractAddress)
40-
if err != nil {
41-
log.Fatalf("failed to get root: %v", err)
42-
}
43-
log.Printf("Root: %s, Valid until: %d", root.Hex(), validUntil)
44-
45-
// Get the proposers
46-
metadata, err := inspector.GetRootMetadata(contractAddress)
47-
if err != nil {
48-
log.Fatalf("failed to get root metadata: %v", err)
49-
}
50-
log.Printf("Metadata: %+v", metadata)
160+
testMCMProgramID := solana.MustPublicKeyFromBase58("6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX")
161+
testMCMSeed := [32]byte{'t', 'e', 's', 't', '-', 'm', 'c', 'm'}
162+
contractID := mcmsSolana.ContractAddress(testMCMProgramID, testMCMSeed)
163+
164+
// Inspecting MCMS contract on Solana
165+
ctx := context.Background()
166+
backend := rpc.New("https://api.devnet.solana.com")
167+
inspector := mcmsSolana.NewInspector(backend)
168+
169+
// Get the op count
170+
opcount, err := inspector.GetOpCount(ctx, contractID)
171+
if err != nil {
172+
log.Fatalf("failed to get op count: %v", err)
173+
}
174+
log.Printf("Op count: %d", opcount)
175+
176+
// Get the config
177+
config, err := inspector.GetConfig(ctx, contractID)
178+
if err != nil {
179+
log.Fatalf("failed to get config: %v", err)
180+
}
181+
log.Printf("Config: %+v", config)
182+
183+
// Get the root
184+
root, validUntil, err := inspector.GetRoot(ctx, contractID)
185+
if err != nil {
186+
log.Fatalf("failed to get root: %v", err)
187+
}
188+
log.Printf("Root: %s, Valid until: %d", root.Hex(), validUntil)
189+
190+
// Get the proposers
191+
metadata, err := inspector.GetRootMetadata(ctx, contractID)
192+
if err != nil {
193+
log.Fatalf("failed to get root metadata: %v", err)
194+
}
195+
log.Printf("Metadata: %+v", metadata)
51196

52197
}
53198
```
54199

55-
### Example: Timelock Inspection
200+
### Example: Solana Timelock Inspection
56201

57202
```go
58203
package main
59204

60205
import (
61-
"fmt"
62-
"log"
206+
"context"
207+
"fmt"
208+
"log"
63209

64-
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
210+
"github.com/gagliardetto/solana-go"
211+
"github.com/gagliardetto/solana-go/rpc"
65212

66-
"github.com/smartcontractkit/mcms/sdk/evm"
213+
mcmsSolana "github.com/smartcontractkit/mcms/sdk/solana"
67214
)
68215

69216
func main() {
70-
// Inspecting Timelock contract on EVM
71-
backend := backends.SimulatedBackend{}
72-
inspector := evm.NewTimelockInspector(backend)
73-
contractAddress := "0x123" // replace with your address
74-
75-
// Get the proposers
76-
proposers, err := inspector.GetProposers(contractAddress)
77-
if err != nil {
78-
log.Fatalf("failed to get op count: %v", err)
79-
}
80-
log.Printf("proposers: %d", proposers)
81-
82-
// Get the bypassers
83-
bypassers, err := inspector.GetBypassers(contractAddress)
84-
if err != nil {
85-
log.Fatalf("failed to get bypassers: %v", err)
86-
}
87-
log.Printf("bypassers: %+v", bypassers)
88-
89-
// Get the executors
90-
executors, err := inspector.GetExecutors(contractAddress)
91-
if err != nil {
92-
log.Fatalf("failed to get executors: %v", err)
93-
}
94-
log.Printf("executors: %s", executors)
95-
96-
// Get the cancellers
97-
cancellers, err := inspector.GetCancellers(contractAddress)
98-
if err != nil {
99-
log.Fatalf("failed to get root metadata: %v", err)
100-
}
101-
log.Printf("Metadata: %+v", cancellers)
102-
103-
// Get operation statuses, opID is a [32]byte representing the operation ID
104-
opID := [32]byte{} // replace with your operation ID
105-
isOp, err := inspector.IsOperation(contractAddress, opID)
106-
if err != nil {
107-
log.Fatalf("failed to get operation status: %v", err)
108-
}
109-
log.Printf("IsOperation: %t", isOp)
110-
111-
isReady, err := inspector.IsOperationReady(contractAddress, opID)
112-
if err != nil {
113-
log.Fatalf("failed to get operation status: %v", err)
114-
}
115-
fmt.Printf("IsOperationReady: %t", isReady)
116-
117-
isPending, err := inspector.IsOperationPending(contractAddress, opID)
118-
if err != nil {
119-
log.Fatalf("failed to get operation status: %v", err)
120-
}
121-
fmt.Printf("IsOperationPending: %t", isPending)
122-
123-
isDone, err := inspector.IsOperationDone(contractAddress, opID)
124-
if err != nil {
125-
log.Fatalf("failed to get operation status: %v", err)
126-
}
127-
fmt.Printf("IsOperationDone: %t", isDone)
217+
testMCMProgramID := solana.MustPublicKeyFromBase58("6UmMZr5MEqiKWD5jqTJd1WCR5kT8oZuFYBLJFi1o6GQX")
218+
testMCMSeed := [32]byte{'t', 'e', 's', 't', '-', 'm', 'c', 'm'}
219+
contractID := mcmsSolana.ContractAddress(testMCMProgramID, testMCMSeed)
220+
ctx := context.Background()
221+
backend := rpc.New("https://api.devnet.solana.com")
222+
inspector := mcmsSolana.NewTimelockInspector(backend)
223+
// Step 1: Initialize the ProposalBuilder
224+
// Get the proposers
225+
proposers, err := inspector.GetProposers(ctx, contractID)
226+
if err != nil {
227+
log.Fatalf("failed to get op count: %v", err)
228+
}
229+
log.Printf("proposers: %d", proposers)
230+
231+
// Get the bypassers
232+
bypassers, err := inspector.GetBypassers(ctx, contractID)
233+
if err != nil {
234+
log.Fatalf("failed to get bypassers: %v", err)
235+
}
236+
log.Printf("bypassers: %+v", bypassers)
237+
238+
// Get the executors
239+
executors, err := inspector.GetExecutors(ctx, contractID)
240+
if err != nil {
241+
log.Fatalf("failed to get executors: %v", err)
242+
}
243+
log.Printf("executors: %s", executors)
244+
245+
// Get the cancellers
246+
cancellers, err := inspector.GetCancellers(ctx, contractID)
247+
if err != nil {
248+
log.Fatalf("failed to get root metadata: %v", err)
249+
}
250+
log.Printf("Metadata: %+v", cancellers)
251+
252+
// Get operation statuses, opID is a [32]byte representing the operation ID
253+
opID := [32]byte{} // replace with your operation ID
254+
isOp, err := inspector.IsOperation(ctx, contractID, opID)
255+
if err != nil {
256+
log.Fatalf("failed to get operation status: %v", err)
257+
}
258+
log.Printf("IsOperation: %t", isOp)
259+
260+
isReady, err := inspector.IsOperationReady(ctx, contractID, opID)
261+
if err != nil {
262+
log.Fatalf("failed to get operation status: %v", err)
263+
}
264+
fmt.Printf("IsOperationReady: %t", isReady)
265+
266+
isPending, err := inspector.IsOperationPending(ctx, contractID, opID)
267+
if err != nil {
268+
log.Fatalf("failed to get operation status: %v", err)
269+
}
270+
fmt.Printf("IsOperationPending: %t", isPending)
271+
272+
isDone, err := inspector.IsOperationDone(ctx, contractID, opID)
273+
if err != nil {
274+
log.Fatalf("failed to get operation status: %v", err)
275+
}
276+
fmt.Printf("IsOperationDone: %t", isDone)
128277

129278
}
130279

131-
```
280+
281+
```

0 commit comments

Comments
 (0)