Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeTransaction(base64Tx string) (*solana.Transaction, error)
- func EncodeTransaction(tx *solana.Transaction) (string, error)
- func FormatAmount(amount uint64, decimals int) string
- func GetTokenPayerFromTransaction(tx *solana.Transaction) (string, error)
- func IsValidNetwork(network string) bool
- func NormalizeNetwork(network string) (string, error)
- func ParseAmount(amount string, decimals int) (uint64, error)
- func ValidateSolanaAddress(address string) bool
- type AssetInfo
- type ClientConfig
- type ClientSvmSigner
- type ExactSvmPayload
- type ExactSvmPayloadV1
- type ExactSvmPayloadV2
- type FacilitatorSvmSigner
- type NetworkConfig
- type SettlementCache
Constants ¶
const ( // SchemeExact is the scheme identifier for exact payments SchemeExact = "exact" // DefaultDecimals is the default token decimals for USDC DefaultDecimals = 6 // DefaultComputeUnitPriceMicrolamports is the default compute unit price in microlamports DefaultComputeUnitPriceMicrolamports = 1 // MaxComputeUnitPriceMicrolamports is the maximum compute unit price in microlamports (facilitator validation limit) // 5 lamports = 5,000,000 microlamports MaxComputeUnitPriceMicrolamports = 5_000_000 // DefaultComputeUnitLimit is the default compute unit limit for transactions // Set to 20000 to accommodate: transfer (~6200 CUs) + memo (~8500 CUs without signer) + budget instructions (~300 CUs) + headroom DefaultComputeUnitLimit uint32 = 20000 // LighthouseProgramAddress is the Phantom/Solflare Lighthouse program address // Phantom and Solflare wallets inject Lighthouse instructions for user protection on mainnet transactions. // - Phantom adds 1 Lighthouse instruction (4th instruction) // - Solflare adds 2 Lighthouse instructions (4th and 5th instructions) // We allow these as optional instructions to support these wallets. // See: https://github.com/coinbase/x402/issues/828 LighthouseProgramAddress = "L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95" // MemoProgramAddress is the SPL Memo program address MemoProgramAddress = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr" // DefaultCommitment is the default commitment level for transactions DefaultCommitment = rpc.CommitmentConfirmed // MaxConfirmAttempts is the maximum number of confirmation attempts MaxConfirmAttempts = 30 // ConfirmRetryDelay is the base delay between confirmation attempts ConfirmRetryDelay = 1 * time.Second // SettlementTTL is how long a transaction is held in the duplicate settlement cache. // Covers the Solana blockhash lifetime (~60-90s) with margin. SettlementTTL = 120 * time.Second // CAIP-2 network identifiers (V2) SolanaMainnetCAIP2 = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" SolanaDevnetCAIP2 = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1" SolanaTestnetCAIP2 = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z" // V1 network names SolanaMainnetV1 = "solana" SolanaDevnetV1 = "solana-devnet" SolanaTestnetV1 = "solana-testnet" // USDC mint addresses USDCMainnetAddress = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" USDCDevnetAddress = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU" USDCTestnetAddress = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU" // Same as devnet )
Variables ¶
var ( // NetworkConfigs maps CAIP-2 identifiers to network configurations // See DEFAULT_ASSET.md for guidelines on adding new networks NetworkConfigs = map[string]NetworkConfig{ SolanaMainnetCAIP2: { Name: "Solana Mainnet", CAIP2: SolanaMainnetCAIP2, RPCURL: "https://api.mainnet-beta.solana.com", DefaultAsset: AssetInfo{ Address: USDCMainnetAddress, Symbol: "USDC", Decimals: DefaultDecimals, }, }, SolanaDevnetCAIP2: { Name: "Solana Devnet", CAIP2: SolanaDevnetCAIP2, RPCURL: "https://api.devnet.solana.com", DefaultAsset: AssetInfo{ Address: USDCDevnetAddress, Symbol: "USDC", Decimals: DefaultDecimals, }, }, SolanaTestnetCAIP2: { Name: "Solana Testnet", CAIP2: SolanaTestnetCAIP2, RPCURL: "https://api.testnet.solana.com", DefaultAsset: AssetInfo{ Address: USDCTestnetAddress, Symbol: "USDC", Decimals: DefaultDecimals, }, }, } // V1ToV2NetworkMap maps V1 network names to CAIP-2 identifiers V1ToV2NetworkMap = map[string]string{ SolanaMainnetV1: SolanaMainnetCAIP2, SolanaDevnetV1: SolanaDevnetCAIP2, SolanaTestnetV1: SolanaTestnetCAIP2, } )
Functions ¶
func DecodeTransaction ¶
func DecodeTransaction(base64Tx string) (*solana.Transaction, error)
DecodeTransaction decodes a base64 encoded Solana transaction
func EncodeTransaction ¶
func EncodeTransaction(tx *solana.Transaction) (string, error)
EncodeTransaction encodes a Solana transaction to base64
func FormatAmount ¶
FormatAmount converts an amount in smallest units to a decimal string
func GetTokenPayerFromTransaction ¶
func GetTokenPayerFromTransaction(tx *solana.Transaction) (string, error)
GetTokenPayerFromTransaction extracts the token payer (owner) address from a transaction This looks for the TransferChecked instruction and returns the owner/authority address
func IsValidNetwork ¶
IsValidNetwork checks if the network is supported for Solana
func NormalizeNetwork ¶
NormalizeNetwork converts V1 network names to CAIP-2 format
func ParseAmount ¶
ParseAmount converts a decimal string amount to token smallest units
func ValidateSolanaAddress ¶
ValidateSolanaAddress checks if a string is a valid Solana address
Types ¶
type AssetInfo ¶
type AssetInfo struct {
Address string // Mint address
Symbol string // Token symbol (e.g., "USDC")
Decimals int // Token decimals
}
AssetInfo contains information about a SPL token
type ClientConfig ¶
type ClientConfig struct {
RPCURL string // Custom RPC URL
}
ClientConfig contains optional client configuration
type ClientSvmSigner ¶
type ClientSvmSigner interface {
// Address returns the signer's Solana address (base58)
Address() solana.PublicKey
// SignTransaction signs a Solana transaction
SignTransaction(ctx context.Context, tx *solana.Transaction) error
}
ClientSvmSigner defines client-side operations
type ExactSvmPayload ¶
type ExactSvmPayload struct {
Transaction string `json:"transaction"` // Base64 encoded Solana transaction
}
ExactSvmPayload represents a SVM (Solana) payment payload
func PayloadFromMap ¶
func PayloadFromMap(data map[string]interface{}) (*ExactSvmPayload, error)
PayloadFromMap creates an ExactSvmPayload from a map
func (*ExactSvmPayload) ToMap ¶
func (p *ExactSvmPayload) ToMap() map[string]interface{}
ToMap converts an ExactSvmPayload to a map for JSON marshaling
type ExactSvmPayloadV1 ¶
type ExactSvmPayloadV1 = ExactSvmPayload
ExactSvmPayloadV1 - alias for v1 compatibility
type ExactSvmPayloadV2 ¶
type ExactSvmPayloadV2 = ExactSvmPayload
ExactSvmPayloadV2 - alias for v2 (currently identical, reserved for future)
type FacilitatorSvmSigner ¶
type FacilitatorSvmSigner interface {
// GetAddresses returns all addresses this facilitator can use as fee payers for a network
// Enables dynamic address selection for load balancing and key rotation
GetAddresses(ctx context.Context, network string) []solana.PublicKey
// SignTransaction signs a transaction with the signer matching feePayer
// Transaction is modified in-place to add the facilitator's signature
// Returns error if no signer exists for feePayer or signing fails
SignTransaction(ctx context.Context, tx *solana.Transaction, feePayer solana.PublicKey, network string) error
// SimulateTransaction simulates a signed transaction to verify it would succeed
// Returns error if simulation fails
SimulateTransaction(ctx context.Context, tx *solana.Transaction, network string) error
// SendTransaction sends a signed transaction to the network
// Returns transaction signature or error if send fails
SendTransaction(ctx context.Context, tx *solana.Transaction, network string) (solana.Signature, error)
// ConfirmTransaction waits for transaction confirmation
// Returns error if confirmation fails or times out
ConfirmTransaction(ctx context.Context, signature solana.Signature, network string) error
}
FacilitatorSvmSigner defines facilitator operations for SVM Supports multiple signers for load balancing, key rotation, and high availability All implementation details (RPC clients, key management) are hidden
type NetworkConfig ¶
type NetworkConfig struct {
Name string // Network name
CAIP2 string // CAIP-2 identifier
RPCURL string // Default RPC URL
DefaultAsset AssetInfo // Default stablecoin
}
NetworkConfig contains network-specific configuration See DEFAULT_ASSET.md for guidelines on adding new chains
func GetNetworkConfig ¶
func GetNetworkConfig(network string) (*NetworkConfig, error)
GetNetworkConfig returns the configuration for a network
type SettlementCache ¶
type SettlementCache struct {
// contains filtered or unexported fields
}
SettlementCache is a thread-safe in-memory cache for deduplicating concurrent settlement requests. A single instance should be shared across V1 and V2 facilitator scheme instances so that a transaction submitted through one protocol version is also blocked on the other.
func NewSettlementCache ¶
func NewSettlementCache() *SettlementCache
NewSettlementCache creates a new, empty SettlementCache.
func (*SettlementCache) Entries ¶
func (c *SettlementCache) Entries() map[string]time.Time
Entries returns a snapshot of the underlying map — use only in tests.
func (*SettlementCache) IsDuplicate ¶
func (c *SettlementCache) IsDuplicate(key string) bool
IsDuplicate returns true if key is already pending settlement (duplicate). Otherwise it records the key as newly pending and returns false. Callers should reject the settlement when this returns true.
func (*SettlementCache) Mu ¶
func (c *SettlementCache) Mu() *sync.Mutex
Mu returns the mutex — use only in tests.