chore: port mcms contract loading functions solutils#10
Draft
chore: port mcms contract loading functions solutils#10
Conversation
7319f18 to
d009e27
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Ports/introduces helper utilities and “view” generators to support loading and inspecting MCMS (EVM + Solana) and LINK token contract/program state, primarily for use in downstream helpers/tests (e.g., BuildProposalFromBatches) while moving functionality into cld-changesets.
Changes:
- Added Solana MCMS program directory metadata plus artifact download/extraction helpers and related test utilities.
- Added/updated EVM state loading helpers (AddressBook + DataStore merge, qualifier support) and expanded tests.
- Added LINK token and MCMS “view” structs/generators, plus common semver/version and contract metadata helpers; updated Go dependencies.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/family/solana/utils/directory.go | Adds program-name constants and a directory mapping for Solana program IDs/buffer sizes. |
| pkg/family/solana/utils/artifacts.go | Implements GitHub release artifact download + tar.gz extraction and go.mod dependency SHA resolution. |
| pkg/family/solana/utils/artifacts_test.go | Adds tests for artifact download/extraction behavior and error cases. |
| pkg/family/solana/testutils/preload.go | Adds test helpers to preload MCMS program artifacts into a directory. |
| pkg/family/solana/testutils/datastore.go | Adds test helper to preload AddressBook entries for MCMS Solana programs. |
| pkg/family/solana/testutils/artifacts.go | Adds caching/downloading helper for Solana program artifacts used in tests. |
| pkg/family/evm/state.go | Adds/updates EVM state helpers (AddressBook + DataStore merge, qualifier-aware loading, view generation). |
| pkg/family/evm/state_test.go | Adds/updates tests for MCMS-with-timelock views and address merging/qualifier behavior. |
| pkg/common/version.go | Introduces common semver constants used across views/state helpers. |
| pkg/common/types.go | Adds reusable ContractMetaData + Meta interface for metadata extraction. |
| mcms/common/view/v1_0/mcms.go | Adds MCMS/timelock/callproxy view generators for EVM and Solana. |
| link/view/link_token.go | Adds LINK token view generator and view type. |
| link/view/link_token_test.go | Adds tests for LINK token view generation. |
| link/view/static_link_token.go | Adds static LINK token view generator and view type. |
| link/view/static_link_token_test.go | Adds tests for static LINK token view generation. |
| go.mod | Updates/adjusts dependencies for added view/state functionality. |
| go.sum | Updates sums for dependency changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,60 @@ | |||
| package view | |||
| @@ -0,0 +1,42 @@ | |||
| package v1_0 | |||
Comment on lines
+1
to
+6
| package v1_0 | ||
|
|
||
| import ( | ||
| "math/big" | ||
| "testing" | ||
|
|
Comment on lines
+152
to
+163
| // Limit individual file size to 100MB to prevent decompression bombs | ||
| const maxFileSize = 100 * 1024 * 1024 // 100MB | ||
| limitedReader := io.LimitReader(tarReader, maxFileSize) | ||
| bytesWritten, err := io.Copy(outFile, limitedReader) | ||
| if err != nil { | ||
| outFile.Close() | ||
| return err | ||
| } | ||
|
|
||
| // Update total size counter | ||
| totalSize += bytesWritten | ||
|
|
| totalSize += bytesWritten | ||
|
|
||
| if lggr != nil { | ||
| lggr.Infof("Extracted Solana chainlink-solana artifact: %s", outPath) |
Comment on lines
+57
to
+78
| id := solutils.GetProgramID(name) | ||
| require.NotEmpty(t, id, "program id not found for program name: %s", name) | ||
|
|
||
| src := filepath.Join(cachePath, name+".so") | ||
| dst := filepath.Join(targetDir, name+".so") | ||
|
|
||
| // Copy the cached artifacts to the target directory | ||
| srcFile, err := os.Open(src) | ||
| require.NoError(t, err) | ||
|
|
||
| dstFile, err := os.Create(dst) | ||
| require.NoError(t, err) | ||
|
|
||
| _, err = io.Copy(dstFile, srcFile) | ||
| require.NoError(t, err) | ||
|
|
||
| srcFile.Close() | ||
| dstFile.Close() | ||
|
|
||
| // Add the program ID to the map | ||
| progIDs[name] = id | ||
| t.Logf("copied solana program %s to %s", name, dst) |
Comment on lines
+26
to
+45
| owner, err := lt.Owner(nil) | ||
| if err != nil { | ||
| owner = common.Address{} | ||
| } | ||
| decimals, err := lt.Decimals(nil) | ||
| if err != nil { | ||
| return LinkTokenView{}, fmt.Errorf("failed to get decimals %s: %w", lt.Address(), err) | ||
| } | ||
| totalSupply, err := lt.TotalSupply(nil) | ||
| if err != nil { | ||
| return LinkTokenView{}, fmt.Errorf("failed to get total supply %s: %w", lt.Address(), err) | ||
| } | ||
| minters, err := lt.GetMinters(nil) | ||
| if err != nil { | ||
| minters = []common.Address{} | ||
| } | ||
| burners, err := lt.GetBurners(nil) | ||
| if err != nil { | ||
| burners = []common.Address{} | ||
| } |
Comment on lines
+251
to
+256
| return MCMViewSolana{ | ||
| ProgramID: programID, | ||
| Seed: string(seed[:]), | ||
| Owner: solana.PublicKey{}, // FIXME: needs inspector.GetOwner() in mcms solana sdk | ||
| Config: *config, | ||
| }, nil |
Comment on lines
+291
to
+299
| return TimelockViewSolana{ | ||
| ProgramID: programID, | ||
| Seed: string(seed[:]), | ||
| Owner: solana.PublicKey{}, // FIXME: needs inspector.GetOwner() in mcms solana sdk | ||
| Proposers: slices.Sorted(slices.Values(proposers)), | ||
| Executors: slices.Sorted(slices.Values(executors)), | ||
| Cancellers: slices.Sorted(slices.Values(cancellers)), | ||
| Bypassers: slices.Sorted(slices.Values(bypassers)), | ||
| }, nil |
Comment on lines
+30
to
+35
| cachePath := programsCachePath() | ||
|
|
||
| onceCCIP.Do(func() { | ||
| err := solutils.DownloadChainlinkCCIPProgramArtifacts(t.Context(), cachePath, "", nil) | ||
| require.NoError(t, err) | ||
| }) |
…s during archive extraction ("Zip Slip")'
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports multiple functions used to load mcms programs which are used in other helper's unit tests like
BuildProposalFromBatches. We need to move and replace these before we can fully move theBuildProposalFromBatcheshelper. Once these are moved, we'll remove usages from core so all reference are pointing to cld-changesets.AI Summary
This pull request introduces new "view" functionality for smart contracts, primarily focused on generating structured representations of contract state for LINK tokens and MCMS (Many Chain MultiSig) contracts, including support for both EVM and Solana chains. It adds types and helper functions for extracting and formatting contract metadata, and includes comprehensive tests for the new views. Additionally, it updates dependencies and introduces common version constants.
The most important changes are:
LINK Token View Functionality:
GenerateLinkTokenViewandGenerateStaticLinkTokenViewfunctions to create structured views of LINK token contracts, capturing key metadata such as decimals, supply, minters, burners, and ownership. Includes corresponding types and test coverage. (link/view/link_token.go,link/view/static_link_token.go,link/view/link_token_test.go,link/view/static_link_token_test.go) [1] [2] [3] [4]MCMS Contract View Functionality:
mcms/common/view/v1_0/mcms.go)Common Utilities and Types:
ContractMetaDatastruct and related helpers for extracting type, version, address, and owner information from contracts, as well as aMetainterface for contract metadata access. (pkg/common/types.go)pkg/common/version.go)Dependency Management:
go.modto use a local replacement forchainlink-deployments-framework, ensuring development uses the correct version. (go.mod)