Class: Solace::SquadsSmartAccounts::SettingsAction

Inherits:
Data
  • Object
show all
Defined in:
lib/solace/squads_smart_accounts/types/settings_action.rb

Overview

Immutable value object representing one variant of the program’s SettingsAction Borsh enum — a single configuration change applied by a settings transaction. Build instances via the variant factories.

Borsh enums encode as a u8 variant index followed by the variant’s fields; the field bytes are encoded at construction and held in data.

Supported variants (IDL order): AddSigner (0), RemoveSigner (1), ChangeThreshold (2), SetTimeLock (3), AddSpendingLimit (4), RemoveSpendingLimit (5). SetArchivalAuthority (6) is not implemented —the archival feature is unimplemented in the deployed program.

Examples:

Batch two changes atomically

[
  SettingsAction.add_signer(pubkey: key, permission: Permissions::ALL),
  SettingsAction.change_threshold(2)
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



22
23
24
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 22

def data
  @data
end

#variantObject (readonly)

Returns the value of attribute variant

Returns:

  • (Object)

    the current value of variant



22
23
24
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 22

def variant
  @variant
end

Class Method Details

.add_signer(pubkey:, permission:) ⇒ SettingsAction

Builds an AddSigner action (variant 0).

Parameters:

  • pubkey (#to_s)

    Pubkey of the signer to add.

  • permission (Integer)

    Bitmask built from Permissions constants.

Returns:



31
32
33
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 31

def self.add_signer(pubkey:, permission:)
  new(variant: 0, data: Solace::Utils::Codecs.encode_pubkey(pubkey) + [permission])
end

.add_spending_limit(seed:, account_index:, mint:, amount:, period:, signers:, destinations:, expiration:) ⇒ SettingsAction

Builds an AddSpendingLimit action (variant 4).

Parameters:

  • seed (#to_s)

    Arbitrary pubkey seeding the SpendingLimit PDA.

  • account_index (Integer)

    Vault index the limit spends from.

  • mint (#to_s)

    Token mint; DEFAULT_PUBKEY for SOL.

  • amount (Integer)

    Amount spendable per period (mint decimals).

  • period (Integer)

    Period enum value (reset cadence).

  • signers (Array<#to_s>)

    Pubkeys allowed to use the limit.

  • destinations (Array<#to_s>)

    Allowed destinations; empty = any.

  • expiration (Integer)

    Unix expiration timestamp; I64_MAX = never.

Returns:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 70

def self.add_spending_limit(
  seed:,
  account_index:,
  mint:,
  amount:,
  period:,
  signers:,
  destinations:,
  expiration:
)
  new(
    variant: 4,
    data:    Solace::Utils::Codecs.encode_pubkey(seed) +
             [] +
             Solace::Utils::Codecs.encode_pubkey(mint) +
             Solace::Utils::Codecs.encode_le_u64(amount).bytes +
             [period] +
             Solace::Utils::Codecs.encode_vec_pubkeys(signers) +
             Solace::Utils::Codecs.encode_vec_pubkeys(destinations) +
             Solace::Utils::Codecs.encode_le_i64(expiration).bytes
  )
end

.change_threshold(threshold) ⇒ SettingsAction

Builds a ChangeThreshold action (variant 2).

Parameters:

  • threshold (Integer)

    The new approval threshold (u16).

Returns:



47
48
49
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 47

def self.change_threshold(threshold)
  new(variant: 2, data: Solace::Utils::Codecs.encode_le_u16(threshold).bytes)
end

.remove_signer(pubkey) ⇒ SettingsAction

Builds a RemoveSigner action (variant 1).

Parameters:

  • pubkey (#to_s)

    Pubkey of the signer to remove.

Returns:



39
40
41
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 39

def self.remove_signer(pubkey)
  new(variant: 1, data: Solace::Utils::Codecs.encode_pubkey(pubkey))
end

.remove_spending_limit(spending_limit) ⇒ SettingsAction

Builds a RemoveSpendingLimit action (variant 5).

Parameters:

  • spending_limit (#to_s)

    Address of the SpendingLimit PDA to remove.

Returns:



97
98
99
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 97

def self.remove_spending_limit(spending_limit)
  new(variant: 5, data: Solace::Utils::Codecs.encode_pubkey(spending_limit))
end

.set_time_lock(seconds) ⇒ SettingsAction

Builds a SetTimeLock action (variant 3).

Parameters:

  • seconds (Integer)

    Seconds between approval and execution (u32).

Returns:



55
56
57
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 55

def self.set_time_lock(seconds)
  new(variant: 3, data: Solace::Utils::Codecs.encode_le_u32(seconds).bytes)
end

Instance Method Details

#serializeArray<Integer>

Serializes the action in Borsh format: u8 variant index + field bytes.

Returns:

  • (Array<Integer>)

    The serialized action.



104
105
106
# File 'lib/solace/squads_smart_accounts/types/settings_action.rb', line 104

def serialize
  [variant] + data
end