Module: Solace::Constants

Defined in:
lib/solace/constants.rb

Overview

Constants module

Contains constants used across the library.

Returns:

  • (Module)

    Constants module

Constant Summary collapse

SYSTEM_PROGRAM_ID =
'11111111111111111111111111111111'
SYSVAR_RENT_PROGRAM_ID =
'SysvarRent111111111111111111111111111111111'
COMPUTE_BUDGET_PROGRAM_ID =
'ComputeBudget111111111111111111111111111111'
TOKEN_PROGRAM_ID =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID =
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'
MEMO_PROGRAM_ID =
'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'
ADDRESS_LOOKUP_TABLE_PROGRAM_ID =
'AddressLookupTab1e1111111111111111111111111'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#ADDRESS_LOOKUP_TABLE_PROGRAM_IDObject

The public key of the Address Lookup Table Program This is the same across all Solana clusters



43
# File 'lib/solace/constants.rb', line 43

ADDRESS_LOOKUP_TABLE_PROGRAM_ID = 'AddressLookupTab1e1111111111111111111111111'

#ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_IDObject

The public key of the Associated Token Account Program This is the same across all Solana clusters



33
# File 'lib/solace/constants.rb', line 33

ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL'

#COMPUTE_BUDGET_PROGRAM_IDObject

The public key of the Compute Budget Program This is the same across all Solana clusters



23
# File 'lib/solace/constants.rb', line 23

COMPUTE_BUDGET_PROGRAM_ID = 'ComputeBudget111111111111111111111111111111'

#MEMO_PROGRAM_IDObject

The public key of the Memo Program This is the same across all Solana clusters



38
# File 'lib/solace/constants.rb', line 38

MEMO_PROGRAM_ID = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr'

#SYSTEM_PROGRAM_IDObject

The public key of the System Program (native SOL transfers, account creation, etc) This is the same across all Solana clusters



13
# File 'lib/solace/constants.rb', line 13

SYSTEM_PROGRAM_ID = '11111111111111111111111111111111'

#SYSVAR_RENT_PROGRAM_IDObject

The public key of the Rent Program This is the same across all Solana clusters



18
# File 'lib/solace/constants.rb', line 18

SYSVAR_RENT_PROGRAM_ID = 'SysvarRent111111111111111111111111111111111'

#TOKEN_PROGRAM_IDObject

The public key of the SPL Token Program This is the same across all Solana clusters



28
# File 'lib/solace/constants.rb', line 28

TOKEN_PROGRAM_ID = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'

Class Method Details

.load(path:, namespace: 'default', protect_overrides: true) ⇒ void

This method returns an undefined value.

Loads the constants declared in a YAML file

Developers require adding program addresses and mint accounts that will not be added directly to Solace. This method allows for loading those constants from a YAML file and extends the Constants module with them.

The YAML file should be a hash of key-value pairs, where the key is the constant name and the value is the constant value.

Examples:

# constants.yml
devnet:
  my_program_id: some_devnet_program_id
  squads_program_id: some_devnet_program_id
  usdc_mint_account: some_devnet_program_id
  usdt_mint_account: some_devnet_program_id

mainnet:
  my_program_id: some_mainnet_program_id
  squads_program_id: some_mainnet_program_id
  usdc_mint_account: some_mainnet_program_id
  usdt_mint_account: some_mainnet_program_id
Solace::Constants.load(
  path: '/home/user/my-project/config/constants.yml',
  namespace: 'devnet',
  protect_overrides: false
)

Solace::Constants::MY_PROGRAM_ID
Solace::Constants::SQUADS_PROGRAM_ID
Solace::Constants::USDC_MINT_ACCOUNT
Solace::Constants::USDT_MINT_ACCOUNT

Parameters:

  • path (String)

    The path to the YAML file

  • namespace (String) (defaults to: 'default')

    The namespace to load the constants from

  • protect_overrides (Boolean) (defaults to: true)

    Whether to protect constants that are already defined

Raises:

  • (ArgumentError)

    If protect_overrides is on and a constant is already defined



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/solace/constants.rb', line 85

def self.load(
  path:,
  namespace: 'default',
  protect_overrides: true
)
  content = YAML.load_file(path)

  content[namespace].each do |key, value|
    if const_defined?(key.upcase)
      raise ArgumentError, "Constant #{key} is already defined" if protect_overrides

      remove_const(key.upcase)
    end

    const_set(key.upcase, value)
  end
end