solana

package
v0.0.0-...-1329066 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package solana privides structures and constants that are used when interacting with the gateway program on Solana chain.

Index

Constants

View Source
const (
	// MaxSignaturesPerTicker is the maximum number of signatures to process on a ticker
	MaxSignaturesPerTicker = 100
)
View Source
const (
	// PDASeed is the seed for the Solana gateway program derived address
	PDASeed = "meta"
)

Variables

View Source
var (
	// DiscriminatorInitialize returns the discriminator for Solana gateway 'initialize' instruction
	DiscriminatorInitialize = idlgateway.IDLGateway.GetDiscriminator("initialize")

	// DiscriminatorDeposit returns the discriminator for Solana gateway 'deposit' instruction
	DiscriminatorDeposit = idlgateway.IDLGateway.GetDiscriminator("deposit")

	// DiscriminatorDepositSPL returns the discriminator for Solana gateway 'deposit_spl_token' instruction
	DiscriminatorDepositSPL = idlgateway.IDLGateway.GetDiscriminator("deposit_spl_token")

	// DiscriminatorWithdraw returns the discriminator for Solana gateway 'withdraw' instruction
	DiscriminatorWithdraw = idlgateway.IDLGateway.GetDiscriminator("withdraw")

	// DiscriminatorWithdrawSPL returns the discriminator for Solana gateway 'withdraw_spl_token' instruction
	DiscriminatorWithdrawSPL = idlgateway.IDLGateway.GetDiscriminator("withdraw_spl_token")

	// DiscriminatorWhitelist returns the discriminator for Solana gateway 'whitelist_spl_mint' instruction
	DiscriminatorWhitelistSplMint = idlgateway.IDLGateway.GetDiscriminator("whitelist_spl_mint")
)

Functions

func ParseGatewayWithPDA

func ParseGatewayWithPDA(gatewayAddress string) (solana.PublicKey, solana.PublicKey, error)

ParseGatewayWithPDA parses the gateway id and program derived address from the given string

func RecoverSigner

func RecoverSigner(msgHash []byte, msgSig []byte) (signer common.Address, err error)

RecoverSigner recover the ECDSA signer from given message hash and signature

Types

type Account

type Account struct {
	Name     string `json:"name"`
	Writable bool   `json:"writable,omitempty"`
	Signer   bool   `json:"signer,omitempty"`
	Address  string `json:"address,omitempty"`
	PDA      *PDA   `json:"pda,omitempty"`
}

type Arg

type Arg struct {
	Name string      `json:"name"`
	Type interface{} `json:"type"`
}

type Deposit

type Deposit struct {
	Sender string
	Amount uint64
	Memo   []byte
	Slot   uint64
	Asset  string
}

func ParseInboundAsDeposit

func ParseInboundAsDeposit(
	tx *solana.Transaction,
	instructionIndex int,
	slot uint64,
) (*Deposit, error)

ParseInboundAsDeposit tries to parse an instruction as a 'deposit'. It returns nil if the instruction can't be parsed as a 'deposit'.

func ParseInboundAsDepositSPL

func ParseInboundAsDepositSPL(
	tx *solana.Transaction,
	instructionIndex int,
	slot uint64,
) (*Deposit, error)

ParseInboundAsDepositSPL tries to parse an instruction as a 'deposit_spl_token'. It returns nil if the instruction can't be parsed as a 'deposit_spl_token'.

type DepositInstructionParams

type DepositInstructionParams struct {
	// Discriminator is the unique identifier for the deposit instruction
	Discriminator [8]byte

	// Amount is the lamports amount for the deposit
	Amount uint64

	// Memo is the memo for the deposit
	Memo []byte
}

DepositInstructionParams contains the parameters for a gateway deposit instruction

type DepositSPLInstructionParams

type DepositSPLInstructionParams struct {
	// Discriminator is the unique identifier for the deposit instruction
	Discriminator [8]byte

	// Amount is the lamports amount for the deposit
	Amount uint64

	// Memo is the memo for the deposit
	Memo []byte
}

DepositSPLInstructionParams contains the parameters for a gateway deposit spl instruction

type Error

type Error struct {
	Code int    `json:"code"`
	Name string `json:"name"`
	Msg  string `json:"msg"`
}

type Field

type Field struct {
	Name string      `json:"name"`
	Type interface{} `json:"type"`
}

type IDL

type IDL struct {
	Address      string        `json:"address"`
	Metadata     Metadata      `json:"metadata"`
	Instructions []Instruction `json:"instructions"`
	Accounts     []Account     `json:"accounts"`
	Errors       []Error       `json:"errors"`
	Types        []Type        `json:"types"`
}

type InitializeParams

type InitializeParams struct {
	// Discriminator is the unique identifier for the initialize instruction
	Discriminator [8]byte

	// TssAddress is the TSS address
	TssAddress [20]byte

	// ChainID is the chain ID for the gateway program
	ChainID uint64
}

InitializeParams contains the parameters for a gateway initialize instruction

type Instruction

type Instruction struct {
	Name          string    `json:"name"`
	Discriminator []byte    `json:"discriminator"`
	Accounts      []Account `json:"accounts"`
	Args          []Arg     `json:"args"`
}

type Metadata

type Metadata struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Spec        string `json:"spec"`
	Description string `json:"description"`
}

type MsgWhitelist

type MsgWhitelist struct {
	// contains filtered or unexported fields
}

MsgWhitelist is the message for the Solana gateway whitelist_spl_mint instruction

func NewMsgWhitelist

func NewMsgWhitelist(
	whitelistCandidate solana.PublicKey,
	whitelistEntry solana.PublicKey,
	chainID, nonce uint64,
) *MsgWhitelist

NewMsgWhitelist returns a new whitelist_spl_mint message

func (*MsgWhitelist) ChainID

func (msg *MsgWhitelist) ChainID() uint64

ChainID returns the chain ID of the message

func (*MsgWhitelist) Hash

func (msg *MsgWhitelist) Hash() [32]byte

Hash packs the whitelist message and computes the hash

func (*MsgWhitelist) Nonce

func (msg *MsgWhitelist) Nonce() uint64

Nonce returns the nonce of the message

func (*MsgWhitelist) SetSignature

func (msg *MsgWhitelist) SetSignature(signature [65]byte) *MsgWhitelist

SetSignature attaches the signature to the message

func (*MsgWhitelist) SigRS

func (msg *MsgWhitelist) SigRS() [64]byte

SigRS returns the 64-byte [R+S] core part of the signature

func (*MsgWhitelist) SigRSV

func (msg *MsgWhitelist) SigRSV() [65]byte

SigRSV returns the full 65-byte [R+S+V] signature

func (*MsgWhitelist) SigV

func (msg *MsgWhitelist) SigV() uint8

SigV returns the V part (recovery ID) of the signature

func (*MsgWhitelist) Signer

func (msg *MsgWhitelist) Signer() (common.Address, error)

Signer returns the signer of the message

func (*MsgWhitelist) WhitelistCandidate

func (msg *MsgWhitelist) WhitelistCandidate() solana.PublicKey

To returns the recipient address of the message

func (*MsgWhitelist) WhitelistEntry

func (msg *MsgWhitelist) WhitelistEntry() solana.PublicKey

type MsgWithdraw

type MsgWithdraw struct {
	// contains filtered or unexported fields
}

MsgWithdraw is the message for the Solana gateway withdraw instruction

func NewMsgWithdraw

func NewMsgWithdraw(chainID, nonce, amount uint64, to solana.PublicKey) *MsgWithdraw

NewMsgWithdraw returns a new withdraw message

func (*MsgWithdraw) Amount

func (msg *MsgWithdraw) Amount() uint64

Amount returns the amount of the message

func (*MsgWithdraw) ChainID

func (msg *MsgWithdraw) ChainID() uint64

ChainID returns the chain ID of the message

func (*MsgWithdraw) Hash

func (msg *MsgWithdraw) Hash() [32]byte

Hash packs the withdraw message and computes the hash

func (*MsgWithdraw) Nonce

func (msg *MsgWithdraw) Nonce() uint64

Nonce returns the nonce of the message

func (*MsgWithdraw) SetSignature

func (msg *MsgWithdraw) SetSignature(signature [65]byte) *MsgWithdraw

SetSignature attaches the signature to the message

func (*MsgWithdraw) SigRS

func (msg *MsgWithdraw) SigRS() [64]byte

SigRS returns the 64-byte [R+S] core part of the signature

func (*MsgWithdraw) SigRSV

func (msg *MsgWithdraw) SigRSV() [65]byte

SigRSV returns the full 65-byte [R+S+V] signature

func (*MsgWithdraw) SigV

func (msg *MsgWithdraw) SigV() uint8

SigV returns the V part (recovery ID) of the signature

func (*MsgWithdraw) Signer

func (msg *MsgWithdraw) Signer() (common.Address, error)

Signer returns the signer of the message

func (*MsgWithdraw) To

func (msg *MsgWithdraw) To() solana.PublicKey

To returns the recipient address of the message

type MsgWithdrawSPL

type MsgWithdrawSPL struct {
	// contains filtered or unexported fields
}

MsgWithdrawSPL is the message for the Solana gateway withdraw_spl instruction

func NewMsgWithdrawSPL

func NewMsgWithdrawSPL(
	chainID, nonce, amount uint64,
	decimals uint8,
	mintAccount, to, toAta solana.PublicKey,
) *MsgWithdrawSPL

NewMsgWithdrawSPL returns a new withdraw spl message

func (*MsgWithdrawSPL) Amount

func (msg *MsgWithdrawSPL) Amount() uint64

Amount returns the amount of the message

func (*MsgWithdrawSPL) ChainID

func (msg *MsgWithdrawSPL) ChainID() uint64

ChainID returns the chain ID of the message

func (*MsgWithdrawSPL) Decimals

func (msg *MsgWithdrawSPL) Decimals() uint8

func (*MsgWithdrawSPL) Hash

func (msg *MsgWithdrawSPL) Hash() [32]byte

Hash packs the withdraw spl message and computes the hash

func (*MsgWithdrawSPL) MintAccount

func (msg *MsgWithdrawSPL) MintAccount() solana.PublicKey

func (*MsgWithdrawSPL) Nonce

func (msg *MsgWithdrawSPL) Nonce() uint64

Nonce returns the nonce of the message

func (*MsgWithdrawSPL) RecipientAta

func (msg *MsgWithdrawSPL) RecipientAta() solana.PublicKey

func (*MsgWithdrawSPL) SetSignature

func (msg *MsgWithdrawSPL) SetSignature(signature [65]byte) *MsgWithdrawSPL

SetSignature attaches the signature to the message

func (*MsgWithdrawSPL) SigRS

func (msg *MsgWithdrawSPL) SigRS() [64]byte

SigRS returns the 64-byte [R+S] core part of the signature

func (*MsgWithdrawSPL) SigRSV

func (msg *MsgWithdrawSPL) SigRSV() [65]byte

SigRSV returns the full 65-byte [R+S+V] signature

func (*MsgWithdrawSPL) SigV

func (msg *MsgWithdrawSPL) SigV() uint8

SigV returns the V part (recovery ID) of the signature

func (*MsgWithdrawSPL) Signer

func (msg *MsgWithdrawSPL) Signer() (common.Address, error)

Signer returns the signer of the message

func (*MsgWithdrawSPL) To

func (msg *MsgWithdrawSPL) To() solana.PublicKey

To returns the recipient address of the message

type OutboundInstruction

type OutboundInstruction interface {
	// Signer returns the signer of the instruction
	Signer() (common.Address, error)

	// GatewayNonce returns the nonce of the instruction
	GatewayNonce() uint64

	// TokenAmount returns the amount of the instruction
	TokenAmount() uint64
}

OutboundInstruction is the interface for all gateway outbound instructions

type PDA

type PDA struct {
	Seeds []Seed `json:"seeds"`
}

type PdaInfo

type PdaInfo struct {
	// Discriminator is the unique identifier for the PDA
	Discriminator [8]byte

	// Nonce is the current nonce for the PDA
	Nonce uint64

	// TssAddress is the TSS address for the PDA
	TssAddress [20]byte

	// Authority is the authority for the PDA
	Authority [32]byte

	// ChainId is the Solana chain id
	ChainID uint64
}

PdaInfo represents the PDA for the gateway program

type Seed

type Seed struct {
	Kind  string `json:"kind"`
	Value []byte `json:"value,omitempty"`
}

type Type

type Type struct {
	Name string    `json:"name"`
	Type TypeField `json:"type"`
}

type TypeField

type TypeField struct {
	Kind   string  `json:"kind"`
	Fields []Field `json:"fields"`
}

type WhitelistInstructionParams

type WhitelistInstructionParams struct {
	// Discriminator is the unique identifier for the whitelist instruction
	Discriminator [8]byte

	// Signature is the ECDSA signature (by TSS) for the whitelist
	Signature [64]byte

	// RecoveryID is the recovery ID used to recover the public key from ECDSA signature
	RecoveryID uint8

	// MessageHash is the hash of the message signed by TSS
	MessageHash [32]byte

	// Nonce is the nonce for the whitelist
	Nonce uint64
}

WhitelistInstructionParams contains the parameters for a gateway whitelist_spl_mint instruction

func ParseInstructionWhitelist

func ParseInstructionWhitelist(instruction solana.CompiledInstruction) (*WhitelistInstructionParams, error)

ParseInstructionWhitelist tries to parse the instruction as a 'whitelist_spl_mint'. It returns nil if the instruction can't be parsed as a 'whitelist_spl_mint'.

func (*WhitelistInstructionParams) GatewayNonce

func (inst *WhitelistInstructionParams) GatewayNonce() uint64

GatewayNonce returns the nonce of the instruction

func (*WhitelistInstructionParams) Signer

func (inst *WhitelistInstructionParams) Signer() (signer common.Address, err error)

Signer returns the signer of the signature contained

func (*WhitelistInstructionParams) TokenAmount

func (inst *WhitelistInstructionParams) TokenAmount() uint64

TokenAmount returns the amount of the instruction

type WithdrawInstructionParams

type WithdrawInstructionParams struct {
	// Discriminator is the unique identifier for the withdraw instruction
	Discriminator [8]byte

	// Amount is the lamports amount for the withdraw
	Amount uint64

	// Signature is the ECDSA signature (by TSS) for the withdraw
	Signature [64]byte

	// RecoveryID is the recovery ID used to recover the public key from ECDSA signature
	RecoveryID uint8

	// MessageHash is the hash of the message signed by TSS
	MessageHash [32]byte

	// Nonce is the nonce for the withdraw
	Nonce uint64
}

WithdrawInstructionParams contains the parameters for a gateway withdraw instruction

func ParseInstructionWithdraw

func ParseInstructionWithdraw(instruction solana.CompiledInstruction) (*WithdrawInstructionParams, error)

ParseInstructionWithdraw tries to parse the instruction as a 'withdraw'. It returns nil if the instruction can't be parsed as a 'withdraw'.

func (*WithdrawInstructionParams) GatewayNonce

func (inst *WithdrawInstructionParams) GatewayNonce() uint64

GatewayNonce returns the nonce of the instruction

func (*WithdrawInstructionParams) Signer

func (inst *WithdrawInstructionParams) Signer() (signer common.Address, err error)

Signer returns the signer of the signature contained

func (*WithdrawInstructionParams) TokenAmount

func (inst *WithdrawInstructionParams) TokenAmount() uint64

TokenAmount returns the amount of the instruction

type WithdrawSPLInstructionParams

type WithdrawSPLInstructionParams struct {
	// Discriminator is the unique identifier for the withdraw instruction
	Discriminator [8]byte

	// Decimals is decimals for spl token
	Decimals uint8

	// Amount is the lamports amount for the withdraw
	Amount uint64

	// Signature is the ECDSA signature (by TSS) for the withdraw
	Signature [64]byte

	// RecoveryID is the recovery ID used to recover the public key from ECDSA signature
	RecoveryID uint8

	// MessageHash is the hash of the message signed by TSS
	MessageHash [32]byte

	// Nonce is the nonce for the withdraw
	Nonce uint64
}

func ParseInstructionWithdrawSPL

func ParseInstructionWithdrawSPL(instruction solana.CompiledInstruction) (*WithdrawSPLInstructionParams, error)

ParseInstructionWithdraw tries to parse the instruction as a 'withdraw'. It returns nil if the instruction can't be parsed as a 'withdraw'.

func (*WithdrawSPLInstructionParams) GatewayNonce

func (inst *WithdrawSPLInstructionParams) GatewayNonce() uint64

GatewayNonce returns the nonce of the instruction

func (*WithdrawSPLInstructionParams) Signer

func (inst *WithdrawSPLInstructionParams) Signer() (signer common.Address, err error)

Signer returns the signer of the signature contained

func (*WithdrawSPLInstructionParams) TokenAmount

func (inst *WithdrawSPLInstructionParams) TokenAmount() uint64

TokenAmount returns the amount of the instruction

Jump to

Keyboard shortcuts

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