Skip to content

chore: port mcms contract loading functions solutils#10

Draft
ecPablo wants to merge 2 commits intomainfrom
ecpablo/port-solutils
Draft

chore: port mcms contract loading functions solutils#10
ecPablo wants to merge 2 commits intomainfrom
ecpablo/port-solutils

Conversation

@ecPablo
Copy link
Copy Markdown
Contributor

@ecPablo ecPablo commented Apr 22, 2026

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 the BuildProposalFromBatches helper. 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:

  • Added GenerateLinkTokenView and GenerateStaticLinkTokenView functions 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:

  • Introduced comprehensive view types and generator functions for MCMS contracts and associated timelocks and proxies, supporting both EVM and Solana implementations. These views aggregate contract metadata, configuration, and role/member mappings, enabling easier inspection and testing of contract state. (mcms/common/view/v1_0/mcms.go)

Common Utilities and Types:

  • Added a reusable ContractMetaData struct and related helpers for extracting type, version, address, and owner information from contracts, as well as a Meta interface for contract metadata access. (pkg/common/types.go)
  • Introduced a set of semantic version constants for consistent versioning throughout the codebase. (pkg/common/version.go)

Dependency Management:

  • Updated go.mod to use a local replacement for chainlink-deployments-framework, ensuring development uses the correct version. (go.mod)

Comment thread pkg/family/solana/utils/artifacts.go Fixed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread link/view/link_token.go
@@ -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 thread link/view/link_token.go
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants