operations

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildMCMSFiredrillProposalOp = fwops.NewOperation(
	"mcms-firedrill-proposal",
	semver.MustParse("1.0.0"),
	"Build noop MCMS timelock proposal for signing fire drills",
	buildMCMSFiredrillProposal,
)

BuildMCMSFiredrillProposalOp builds a noop MCMS timelock proposal covering the configured chains. Use fwops.WithForceExecute at the call site so repeated drills record fresh proposals under identical inputs.

View Source
var OpSolanaGrantRoleTimelock = fwops.NewOperation(
	"solana-grant-role-timelock",
	semver.MustParse("1.0.0"),
	"Grant a role to an account in a Solana Timelock instance",
	func(b fwops.Bundle, deps OpSolanaGrantRoleTimelockDeps, in OpSolanaGrantRoleTimelockInput) (OpSolanaGrantRoleTimelockOutput, error) {
		if in.ChainState == nil {
			return OpSolanaGrantRoleTimelockOutput{}, errors.New("chainState is required")
		}

		if in.ChainState.TimelockProgram.IsZero() || in.ChainState.AccessControllerProgram.IsZero() {
			return OpSolanaGrantRoleTimelockOutput{}, errors.New("timelock and access controller program IDs are required")
		}

		accessController, err := selectAccessControllerGrantRole(in)
		if err != nil {
			return OpSolanaGrantRoleTimelockOutput{}, fmt.Errorf("failed to select access controller: %w", err)
		}

		timelockbindings.SetProgramID(in.ChainState.TimelockProgram)
		accesscontrollerbindings.SetProgramID(in.ChainState.AccessControllerProgram)
		var signer solana.PublicKey
		if in.IsDeployerKeyAdmin {
			signer = deps.Chain.DeployerKey.PublicKey()
		} else {
			signer = solanastate.GetTimelockSignerPDA(in.ChainState.TimelockProgram, in.ChainState.TimelockSeed)
		}

		ix, err := accesscontrollerbindings.NewAddAccessInstruction(accessController, signer, in.Account).ValidateAndBuild()
		if err != nil {
			return OpSolanaGrantRoleTimelockOutput{}, fmt.Errorf("failed to create add access instruction: %w", err)
		}

		if in.IsDeployerKeyAdmin {
			cerr := deps.Chain.SendAndConfirm(b.GetContext(), []solana.Instruction{ix})
			if cerr != nil {
				return OpSolanaGrantRoleTimelockOutput{}, fmt.Errorf("failed to confirm instructions: %w", cerr)
			}

			return OpSolanaGrantRoleTimelockOutput{}, nil
		}

		transaction, err := mcmssolanasdk.NewTransactionFromInstruction(ix, "AccessController", []string{})
		if err != nil {
			return OpSolanaGrantRoleTimelockOutput{}, fmt.Errorf("failed to create transaction: %w", err)
		}

		return OpSolanaGrantRoleTimelockOutput{MCMSTransaction: transaction}, nil
	},
)
View Source
var SeqSolanaGrantRoleTimelock = fwops.NewSequence(
	"seq-solana-grant-role-timelock",
	semver.MustParse("1.0.0"),
	"Grant a role to multiple accounts in a Solana Timelock instance",
	func(b fwops.Bundle, deps SeqSolanaGrantRoleTimelockDeps, in SeqSolanaGrantRoleTimelockInput) (SeqSolanaGrantRoleTimelockOutput, error) {
		if in.ChainState == nil {
			return SeqSolanaGrantRoleTimelockOutput{}, errors.New("chainState is required")
		}

		mcmsTxs := make([]mcmstypes.Transaction, 0, len(in.Accounts))

		for _, account := range in.Accounts {
			opReport, err := fwops.ExecuteOperation(b, OpSolanaGrantRoleTimelock,
				OpSolanaGrantRoleTimelockDeps(deps),
				OpSolanaGrantRoleTimelockInput{
					ChainState:         in.ChainState,
					Role:               in.Role,
					Account:            account,
					IsDeployerKeyAdmin: in.IsDeployerKeyAdmin,
				},
			)
			if err != nil {
				b.Logger.Errorw("Failed to grant role", "chainSelector", deps.Chain.ChainSelector(), "chainName", deps.Chain.Name(),
					"timelock", solanastate.EncodeAddressWithSeed(in.ChainState.TimelockProgram, in.ChainState.TimelockSeed),
					"role", in.Role, "account", account)

				return SeqSolanaGrantRoleTimelockOutput{}, err
			}

			if !in.IsDeployerKeyAdmin {
				mcmsTxs = append(mcmsTxs, opReport.Output.MCMSTransaction)
			}
		}

		return SeqSolanaGrantRoleTimelockOutput{McmsTransactions: mcmsTxs}, nil
	},
)

Functions

This section is empty.

Types

type FireDrillDeps

type FireDrillDeps struct {
	Environment cldf.Environment
}

FireDrillDeps holds non-serializable dependencies for the fire-drill operation.

type FireDrillInput

type FireDrillInput struct {
	TimelockCfg cldfproposalutils.TimelockConfig `json:"timelockCfg"`
	Selectors   []uint64                         `json:"selectors,omitempty"`
}

FireDrillInput is JSON-serializable input for the MCMS signing fire-drill proposal operation.

type FireDrillOutput

type FireDrillOutput struct {
	Proposal mcmslib.TimelockProposal `json:"proposal"`
}

FireDrillOutput is the serializable result of building the fire-drill proposal.

type OpSolanaGrantRoleTimelockDeps

type OpSolanaGrantRoleTimelockDeps struct {
	Chain cldfsolana.Chain
}

type OpSolanaGrantRoleTimelockInput

type OpSolanaGrantRoleTimelockInput struct {
	ChainState         *solanastate.MCMSWithTimelockState `json:"chainState"`
	Role               timelockbindings.Role              `json:"role"`
	Account            solana.PublicKey                   `json:"account"`
	IsDeployerKeyAdmin bool                               `json:"isDeployerKeyAdmin"`
}

type OpSolanaGrantRoleTimelockOutput

type OpSolanaGrantRoleTimelockOutput struct {
	MCMSTransaction mcmstypes.Transaction `json:"mcmsTransaction"`
}

type SeqSolanaGrantRoleTimelockDeps

type SeqSolanaGrantRoleTimelockDeps struct {
	Chain cldfsolana.Chain
}

type SeqSolanaGrantRoleTimelockInput

type SeqSolanaGrantRoleTimelockInput struct {
	ChainState         *solanastate.MCMSWithTimelockState `json:"chainState"`
	Role               timelockbindings.Role              `json:"role"`
	Accounts           []solana.PublicKey                 `json:"accounts"`
	IsDeployerKeyAdmin bool                               `json:"isDeployerKeyAdmin"`
}

type SeqSolanaGrantRoleTimelockOutput

type SeqSolanaGrantRoleTimelockOutput struct {
	McmsTransactions []mcmstypes.Transaction `json:"mcmsTxs"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL