### Install Anchor and Solana Tools Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/README.md Installs the Anchor framework, Solana Version Manager (avm), and Anza CLI, which are prerequisites for building and testing the Solana protocol contracts. ```bash $ cargo install --git https://github.com/coral-xyz/anchor avm --force $ avm install 0.31.0 $ sh -c "$(curl -sSfL https://release.anza.xyz/v2.1.0/install)" ``` -------------------------------- ### Configure Zsh Environment Path for GNU Tar Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/README.md This snippet demonstrates how to export the GNU tar path to your shell's environment variables. This is typically done in the ~/.zshrc file to ensure the path is set every time a new shell session starts. It ensures that the system can find and use the specified GNU tar version. ```bash export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" ``` -------------------------------- ### Get Program ID Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Returns the program's unique identifier (Program ID) on the Solana blockchain. This is a fundamental piece of information for interacting with the program. ```rust pub fn id() -> anchor_lang::solana_program::pubkey::Pubkey { /* ... */ } ``` -------------------------------- ### Get Program ID (Const) Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Provides a compile-time constant version of the program's ID. This can be useful for static initializations and compile-time checks. ```rust pub const fn id_const() -> anchor_lang::solana_program::pubkey::Pubkey { /* ... */ } ``` -------------------------------- ### Build Solana Protocol Contracts Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/README.md Builds the Solana smart contract using the Anchor framework. This command compiles the contract and generates necessary artifacts for deployment and testing. ```bash $ anchor build ``` -------------------------------- ### Run Solana Protocol Contract Tests Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/README.md Executes the test suite for the Solana protocol contracts. This ensures the contract's functionality and integrity before deployment. ```bash $ anchor test ``` -------------------------------- ### Generate Go Bindings for Solana Contract Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/README.md Generates Go language bindings for the Solana program's Interface Definition Language (IDL). This is typically used for interacting with the contract from Go applications in development or production environments. ```bash Development environments : Localnet $ make generate-dev Production environments : Mainnet,Testnet $ make generate-prod ``` -------------------------------- ### Implement Gateway Program State in Rust (Solana) Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/README.md This Rust code defines the data structure for the Gateway program's state stored in a Program Derived Address (PDA). It includes fields for the nonce (for replay protection), the ZetaChain TSS address, and an authority for updates. The `initialize` function sets the initial state. ```rust #[account] pub struct GatewayConfig { pub nonce: u64, pub tss_address: [u8; 20], pub authority: Pubkey, } pub fn initialize( ctx: Context, tss_address: [u8; 20], authority: Pubkey, ) -> Result<()> { let config = &mut ctx.accounts.gateway_config; config.nonce = 0; config.tss_address = tss_address; config.authority = authority; Ok(()) } ``` -------------------------------- ### Solana Program Entrypoint (Unsafe) Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md The unsafe C-style entry point for the Solana program, handling raw input data. This function is the initial execution point for any Solana program. ```rust pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 { /* ... */ } ``` -------------------------------- ### Anchor Program Entry Function Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the standard entry point for an Anchor Solana program. It handles program ID validation, method dispatch using sighash, account deserialization, and execution of user-defined program logic. ```rust pub fn entry<''info>(program_id: &Pubkey, accounts: &''info [AccountInfo<''info>], data: &[u8]) -> anchor_lang::solana_program::entrypoint::ProgramResult { /* ... */ } ``` -------------------------------- ### Rust Trait Implementations: TryFrom and Sync Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Covers the implementation of TryFrom and Sync traits in Rust. TryFrom provides fallible conversion from another type, and Sync ensures safe sharing of data across threads. ```rust fn try_from(value: U) -> Result>::Error> { /* ... */ } ``` ```rust // No code provided for Sync ``` -------------------------------- ### Rust Trait Implementations: Borrow, BorrowMut, and From Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Demonstrates the implementation of the Borrow, BorrowMut, and From traits in Rust. These traits are fundamental for managing data access and conversions within the protocol contracts. ```rust fn borrow(self: &Self) -> &T { /* ... */ } ``` ```rust fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ } ``` ```rust fn from(t: T) -> T { /* ... */ } Returns the argument unchanged. ``` -------------------------------- ### Rust: Initialize Instruction Data Structure Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the data structure for the 'Initialize' instruction, used for setting up the program. It includes the TSS address and the chain ID. ```rust pub struct Initialize { pub tss_address: [u8; 20], pub chain_id: u64, } ``` -------------------------------- ### Rust Trait Implementations: From, Into, Borrow, BorrowMut Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Demonstrates basic Rust trait implementations for data manipulation and access. These include converting between types, borrowing immutable references, and borrowing mutable references. The `From` trait implementation returns the argument unchanged, while `Into` calls `U::from(self)`. `Borrow` and `BorrowMut` provide access to the inner data. ```rust fn from(t: T) -> T { /* ... */ } Returns the argument unchanged. fn into(self: Self) -> U { U::from(self) } Calls `U::from(self)`. fn borrow(self: &Self) -> &T { /* ... */ } fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ } ``` -------------------------------- ### Initialize Gateway PDA Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Initializes the gateway's Program Derived Address (PDA). This function sets up essential parameters for the gateway, including the TSS address and the associated chain ID. It requires the instruction context and specific parameters for initialization. ```rust pub fn initialize(ctx: Context<''_, ''_, ''_, ''_, Initialize<''_>>, tss_address: [u8; 20], chain_id: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Rust Trait Implementations: Into, VZip, and InstructionData Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Showcases the implementation of Into, VZip, and InstructionData traits in Rust. Into provides a conversion to another type, VZip might be for vector-related operations, and InstructionData is specific to the contract's instruction format. ```rust fn into(self: Self) -> U { Calls `U::from(self)`. } ``` ```rust fn vzip(self: Self) -> V { /* ... */ } ``` ```rust // No code provided for InstructionData ``` -------------------------------- ### Rust: Call ZetaChain zEVM Contract Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Calls a contract on ZetaChain's zEVM from Solana. Requires instruction context, receiver address, message, and optional revert options. ```rust pub fn call(ctx: Context<''_, ''_, ''_, ''_, Call<''_>>, receiver: [u8; 20], message: Vec, revert_options: Option) -> Result<()> { /* ... */ } ``` -------------------------------- ### Rust Trait Implementations: TryInto and Discriminator Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Illustrates the implementation of TryInto and Discriminator traits in Rust. TryInto handles fallible conversions, while Discriminator might be used for type identification within the contract system. ```rust fn try_into(self: Self) -> Result>::Error> { /* ... */ } ``` ```rust // No code provided for Discriminator ``` -------------------------------- ### Rust Accounts Module Definition Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the 'accounts' module in Rust. This module is generated by Anchor and provides client-friendly account structures mirroring those deriving Accounts, with fields as Pubkeys. ```rust pub mod accounts { /* ... */ } ``` -------------------------------- ### Re-export Contexts Module Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports all items from the `contexts` module. This allows direct use of account context definitions. ```rust pub use contexts::*; ``` -------------------------------- ### Rust Trait Implementations for Protocol Contracts Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Demonstrates various standard and custom trait implementations in Rust for Solana smart contracts. These include traits for data serialization (BorshSerialize, BorshDeserialize), memory management (Borrow, BorrowMut, Unpin), error handling (TryFrom, TryInto), and general object capabilities (Any, Into, From). ```rust fn borrow(self: &Self) -> &T { /* ... */ } ``` ```rust fn type_id(self: &Self) -> TypeId { /* ... */ } ``` ```rust fn vzip(self: Self) -> V { /* ... */ } ``` ```rust fn try_from(value: U) -> Result>::Error> { /* ... */ } ``` ```rust fn owner() -> Pubkey { /* ... */ } ``` ```rust fn into(self: Self) -> U { /* ... */ } ``` ```rust fn deserialize_reader(reader: &mut R) -> ::core::result::Result { /* ... */ } ``` ```rust fn try_into(self: Self) -> Result>::Error> { /* ... */ } ``` ```rust fn serialize(self: &Self, writer: &mut W) -> ::core::result::Result<(), borsh::maybestd::io::Error> { /* ... */ } ``` ```rust fn from(t: T) -> T { /* ... */ } ``` ```rust fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ } ``` -------------------------------- ### Rust Trait Implementations: TryFrom and TryInto Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Provides fallible conversions between types using `TryFrom` and `TryInto`. These traits are essential when a conversion might fail, returning a `Result` type. `TryFrom` attempts to create a value of one type from another, while `TryInto` is the inverse. ```rust fn try_from(value: U) -> Result>::Error> { /* ... */ } fn try_into(self: Self) -> Result>::Error> { /* ... */ } ``` -------------------------------- ### Rust: Deposit SPL Token and Call ZetaChain zEVM Contract Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Deposits SPL tokens on Solana and calls a contract on ZetaChain's zEVM. Requires instruction context, amount, receiver address, message, and optional revert options. ```rust pub fn deposit_spl_token_and_call(ctx: Context<''_, ''_, ''_, ''_, DepositSplToken<''_>>, amount: u64, receiver: [u8; 20], message: Vec, revert_options: Option) -> Result<()> { /* ... */ } ``` -------------------------------- ### Deposit SOL and Call Contract on ZetaChain zEVM - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Enables depositing SOL to the program and simultaneously calling a contract on ZetaChain zEVM. This function requires the amount of SOL, the receiver's zEVM address, the message payload for the contract call, and optional revert options. It uses the 'Deposit' context. ```rust pub fn deposit_and_call(ctx: Context<''_, ''_, ''_, ''_, Deposit<''_>>, amount: u64, receiver: [u8; 20], message: Vec, revert_options: Option) -> Result<()> { /* ... */ } ``` -------------------------------- ### TryInto Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the TryInto trait, providing a fallible way to convert the current type into another type `U`. The `try_into` method returns a `Result` to indicate the success or failure of the conversion. ```rust fn try_into(self: Self) -> Result>::Error> { /* ... */ } ``` -------------------------------- ### Rust Struct Deposit Definition Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `Deposit` struct, representing a deposit instruction. It contains fields for the deposit amount, receiver's address, and optional revert options. This struct implements various traits including `Into`, `BorshSerialize`, `Owner`, `RefUnwindSafe`, `Unpin`, `BorshDeserialize`, `VZip`, `TryFrom`, `Borrow`, `Discriminator`, `InstructionData`, `Freeze`, `BorrowMut`, `Any`, `UnwindSafe`, `Sync`, `Send`, `TryInto`, `IntoEither`, and `From`. ```rust pub struct Deposit { pub amount: u64, pub receiver: [u8; 20], pub revert_options: Option, } ``` -------------------------------- ### Deposit SOL to ZetaChain zEVM - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Facilitates the deposit of SOL (in lamports) into the program, crediting the specified receiver address on the ZetaChain zEVM. It can optionally include revert options for managing failed transactions. Uses the 'Deposit' context. ```rust pub fn deposit(ctx: Context<''_, ''_, ''_, ''_, Deposit<''_>>, amount: u64, receiver: [u8; 20], revert_options: Option) -> Result<()> { /* ... */ } ``` -------------------------------- ### ExecuteSplToken Struct Definition Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `ExecuteSplToken` struct, which represents an instruction for executing an SPL Token operation on Solana. It includes fields for token details, sender, data, and cryptographic signature components. ```rust pub struct ExecuteSplToken { pub decimals: u8, pub amount: u64, pub sender: [u8; 20], pub data: Vec, pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### Rust Struct: Execute Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the 'Execute' struct, representing an instruction within the protocol. It includes fields for amount, sender, data, signature, recovery ID, message hash, and nonce. ```rust pub struct Execute { pub amount: u64, pub sender: [u8; 20], pub data: Vec, pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### VZip Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the VZip trait, likely for specialized data compression or packing. The `vzip` method takes ownership of the object and returns a compressed representation `V`. ```rust fn vzip(self: Self) -> V { /* ... */ } ``` -------------------------------- ### Rust Struct: DepositSplTokenAndCall Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `DepositSplTokenAndCall` struct in Rust, representing an instruction to deposit SPL tokens and then call another function. It includes fields for amount, receiver, message data, and revert options. ```rust pub struct DepositSplTokenAndCall { pub amount: u64, pub receiver: [u8; 20], pub message: Vec, pub revert_options: Option, } ``` -------------------------------- ### Re-export Client Accounts Reset Nonce Module Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports all items from the `__client_accounts_reset_nonce` module. This allows direct use of nonce reset related functionalities. ```rust pub use crate::__client_accounts_reset_nonce::*; ``` -------------------------------- ### Rust Struct Definition: WhitelistSplMint Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `WhitelistSplMint` struct, likely used for whitelisting SPL Mints in Solana. It includes fields for signature, recovery ID, message hash, and nonce, suggesting it's involved in cryptographic verification processes. ```rust pub struct WhitelistSplMint { pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### Rust Struct: DepositSplToken Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `DepositSplToken` struct in Rust, representing an instruction for depositing SPL tokens. It includes fields for the amount, receiver's address, and optional revert options. ```rust pub struct DepositSplToken { pub amount: u64, pub receiver: [u8; 20], pub revert_options: Option, } ``` -------------------------------- ### Re-export State Module Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports all items from the `state` module. This makes program state structures and related functionalities readily available. ```rust pub use state::*; ``` -------------------------------- ### Into Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the Into trait, providing a consuming conversion from one type to another. The `into` method takes ownership of `self` and converts it into type `U`, typically by calling `U::from(self)`. ```rust fn into(self: Self) -> U { /* ... */ } ``` -------------------------------- ### Rust Struct DepositAndCall Definition Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `DepositAndCall` struct, used for depositing assets and executing a call. It includes fields for the deposit amount, receiver's address, a message payload, and optional revert options. This struct is part of the Solana protocol contracts. ```rust pub struct DepositAndCall { pub amount: u64, pub receiver: [u8; 20], pub message: Vec, pub revert_options: Option, } ``` -------------------------------- ### Re-export Client Accounts Execute Spl Token Module Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports all items from the `__client_accounts_execute_spl_token` module. This facilitates access to SPL token related functionalities within the program. ```rust pub use crate::__client_accounts_execute_spl_token::*; ``` -------------------------------- ### Constant Program ID Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines a compile-time constant for the program ID. This is an alternative to the static `ID` and is available at compile time. ```rust pub const ID_CONST: anchor_lang::solana_program::pubkey::Pubkey = _; ``` -------------------------------- ### Execute SPL Token Withdrawal and Cross-Program Invocation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Withdraws a specified amount of SPL tokens to a destination program's PDA and invokes the `on_call` function on the destination program. This facilitates cross-chain SPL token transfers. It requires the instruction context, token decimals, amount, sender, data, and signature for verification. ```rust pub fn execute_spl_token(ctx: Context<''_, ''_, ''_, ''_, ExecuteSPLToken<''_>>, decimals: u8, amount: u64, sender: [u8; 20], data: Vec, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Rust Struct: ExecuteRevert Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the 'ExecuteRevert' struct, another type of instruction. It is similar to 'Execute' but uses a Pubkey for the sender. ```rust pub struct ExecuteRevert { pub amount: u64, pub sender: Pubkey, pub data: Vec, pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### From Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the From trait, providing a way to convert one type into another. This specific implementation returns the argument unchanged, acting as an identity conversion. ```rust fn from(t: T) -> T { /* ... */ } ``` -------------------------------- ### Rust Trait Implementations: Owner and Any Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements traits for identifying ownership and type information. The `Owner` trait provides a method to retrieve the owner's public key, likely for authentication or authorization purposes. The `Any` trait provides a `type_id` method for runtime type introspection. ```rust fn owner() -> Pubkey { /* ... */ } fn type_id(self: &Self) -> TypeId { /* ... */ } ``` -------------------------------- ### Execute Reverted SOL Withdrawal and Cross-Program Invocation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Handles the execution of a reverted SOL withdrawal, calling `on_revert` on the destination program. This is used to process transactions that were initially intended for a different chain or failed. It requires the instruction context, amount, sender, data, and signature for verification. ```rust pub fn execute_revert(ctx: Context<''_, ''_, ''_, ''_, Execute<''_>>, amount: u64, sender: Pubkey, data: Vec, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Check Program ID Match Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Validates if a given public key matches the program's ID. This is crucial for ensuring that instructions are directed to the correct program on the Solana blockchain. ```rust pub fn check_id(id: &anchor_lang::solana_program::pubkey::Pubkey) -> bool { /* ... */ } ``` -------------------------------- ### Rust Trait Implementations: Any and UnwindSafe Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Details the implementation of the Any and UnwindSafe traits in Rust. Any is likely for dynamic type information, while UnwindSafe concerns exception safety during unwinding. ```rust fn type_id(self: &Self) -> TypeId { /* ... */ } ``` ```rust // No code provided for UnwindSafe ``` -------------------------------- ### Re-export Client Accounts Update Paused Module Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports all items from the `__client_accounts_update_paused` module. This is a common pattern for organizing and exposing sub-modules within a Rust crate. ```rust pub use crate::__client_accounts_update_paused::*; ``` -------------------------------- ### Execute SOL Withdrawal and Cross-Program Invocation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Withdraws a specified amount of SOL to a destination program's PDA and invokes the `on_call` function on the destination program. This is used for cross-chain communication. It requires the instruction context, amount, sender, arbitrary data, and signature for verification. ```rust pub fn execute(ctx: Context<''_, ''_, ''_, ''_, Execute<''_>>, amount: u64, sender: [u8; 20], data: Vec, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Deposit SPL Token to ZetaChain zEVM - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Allows depositing SPL tokens into the program, crediting the specified receiver address on ZetaChain zEVM. The function takes the amount of SPL tokens, the receiver's zEVM address, and optional revert options. It utilizes the 'DepositSplToken' context. ```rust pub fn deposit_spl_token(ctx: Context<''_, ''_, ''_, ''_, DepositSplToken<''_>>, amount: u64, receiver: [u8; 20], revert_options: Option) -> Result<()> { /* ... */ } ``` -------------------------------- ### Rust: Withdraw SOL from Solana Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Withdraws SOL from the program on Solana, initiated by the TSS (Thetan System). Requires instruction context, amount, and signature verification details. ```rust pub fn withdraw(ctx: Context<''_, ''_, ''_, ''_, Withdraw<''_>>, amount: u64, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Rust Struct: Call Instruction Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `Call` struct, representing an instruction for sending a message to a receiver on Solana. It includes fields for the recipient's address, the message payload, and optional revert options. This struct is often used in smart contract interactions. ```rust pub struct Call { pub receiver: [u8; 20], pub message: Vec, pub revert_options: Option, } ``` -------------------------------- ### Rust Trait Implementations: BorshSerialize and BorshDeserialize Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Details the implementation of BorshSerialize and BorshDeserialize traits for efficient data serialization and deserialization using the Borsh crate. This is crucial for data storage and network transmission. ```rust fn serialize(self: &Self, writer: &mut W) -> ::core::result::Result<(), borsh::maybestd::io::Error> { /* ... */ } ``` ```rust fn deserialize_reader(reader: &mut R) -> ::core::result::Result { /* ... */ } ``` -------------------------------- ### Re-export Deposit Fee Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports the `DEPOSIT_FEE` constant from the `utils` module. This makes the deposit fee value directly accessible. ```rust pub use utils::DEPOSIT_FEE; ``` -------------------------------- ### Static Program ID Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Declares the static program ID for the Zeta Chain protocol contract. This is the runtime-available program identifier. ```rust pub static ID: anchor_lang::solana_program::pubkey::Pubkey = _; ``` -------------------------------- ### TryFrom Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the TryFrom trait for fallible conversions between types. The `try_from` method attempts to convert a value of type `U` into type `T`, returning a `Result` to indicate success or failure. ```rust fn try_from(value: U) -> Result>::Error> { /* ... */ } ``` -------------------------------- ### Any Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the Any trait, which is part of Rust's dynamic dispatch mechanism. The `type_id` method returns a `TypeId` that uniquely identifies the type of the instance. ```rust fn type_id(self: &Self) -> TypeId { /* ... */ } ``` -------------------------------- ### Rust Trait Implementations: BorshSerialize and BorshDeserialize Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements serialization and deserialization for data structures using the Borsh crate. `BorshSerialize` allows objects to be written to a byte stream, while `BorshDeserialize` enables reading from a byte stream to reconstruct objects. These are crucial for data persistence and network communication. ```rust fn serialize(self: &Self, writer: &mut W) -> ::core::result::Result<(), borsh::maybestd::io::Error> { /* ... */ } fn deserialize_reader(reader: &mut R) -> ::core::result::Result { /* ... */ } ``` -------------------------------- ### Rust Re-export Accounts Module Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports all items from a specific client accounts module, likely for easier access and use in other parts of the crate. This is a common pattern for organizing generated code. ```rust pub use crate::__client_accounts_deposit_spl_token::*; ``` ```rust pub use crate::__client_accounts_call::*; ``` ```rust pub use crate::__client_accounts_initialize::*; ``` ```rust pub use crate::__client_accounts_whitelist::*; ``` ```rust pub use crate::__client_accounts_update_authority::*; ``` ```rust pub use crate::__client_accounts_unwhitelist::*; ``` ```rust pub use crate::__client_accounts_execute::*; ``` ```rust pub use crate::__client_accounts_withdraw_spl_token::*; ``` ```rust pub use crate::__client_accounts_withdraw::*; ``` ```rust pub use crate::__client_accounts_update_tss::*; ``` ```rust pub use crate::__client_accounts_deposit::*; ``` -------------------------------- ### Execute SPL Token Revert with Signature Verification - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Withdraws a specified amount of SPL tokens to a destination program's PDA and triggers an on_revert call on that program. It requires signature verification parameters for security. Dependencies include the 'Context' and associated structs for instruction handling. ```rust pub fn execute_spl_token_revert(ctx: Context<''_, ''_, ''_, ''_, ExecuteSPLToken<''_>>, decimals: u8, amount: u64, sender: Pubkey, data: Vec, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Re-export Client Accounts Increment Nonce Module Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports all items from the `__client_accounts_increment_nonce` module. This is used to make nonce incrementing related account structures and functions available. ```rust pub use crate::__client_accounts_increment_nonce::*; ``` -------------------------------- ### Rust Trait Implementations: Send, Unpin, and RefUnwindSafe Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Showcases the implementation of Send, Unpin, and RefUnwindSafe traits. These traits relate to thread safety, memory pinning, and exception safety, crucial for robust contract execution. ```rust // No code provided for Send, Unpin, RefUnwindSafe ``` -------------------------------- ### Rust: IncrementNonce Instruction Data Structure Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the data structure for the 'IncrementNonce' instruction, used for managing nonces. It includes amount, signature, recovery ID, message hash, and nonce value. ```rust pub struct IncrementNonce { pub amount: u64, pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### Rust Trait Implementation: Owner Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Shows the implementation of the Owner trait, likely used to identify the owner or deployer of the contract. It returns a Pubkey identifier. ```rust fn owner() -> Pubkey { /* ... */ } ``` -------------------------------- ### Re-export Errors Module Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Re-exports all items from the `errors` module. This provides direct access to the program's error definitions. ```rust pub use errors::*; ``` -------------------------------- ### Whitelist SPL Mint Token with Signature Verification - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Adds a new SPL token mint to the program's whitelist, enabling it for deposits and other operations. This function is restricted to be called by the TSS, requiring signature verification. It uses the 'Whitelist' context and signature parameters. ```rust pub fn whitelist_spl_mint(ctx: Context<''_, ''_, ''_, ''_, Whitelist<''_>>, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Rust Struct UnwhitelistSplMint Definition Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `UnwhitelistSplMint` struct used for unwhitelisting SPL Mints. It includes fields for signature, recovery ID, message hash, and nonce. This struct implements several standard Rust traits such as `BorrowMut`, `TryFrom`, `Owner`, `Send`, `Any`, `Unpin`, `Same`, `Discriminator`, `Borrow`, `IntoEither`, `Freeze`, `Sync`, `TryInto`, `VZip`, `InstructionData`, `Into`, `From`, `BorshSerialize`, `BorshDeserialize`, `RefUnwindSafe`, and `UnwindSafe`. ```rust pub struct UnwhitelistSplMint { pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### BorrowMut Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the BorrowMut trait, enabling mutable borrowing of the type. The `borrow_mut` method returns a mutable reference `&mut T` to the contained data. ```rust fn borrow_mut(self: &mut Self) -> &mut T { /* ... */ } ``` -------------------------------- ### Rust WithdrawSplToken Struct Definition Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the WithdrawSplToken struct, which likely represents data for withdrawing SPL tokens on Solana. It includes fields for decimals, amount, signature, recovery ID, message hash, and nonce. ```rust pub struct WithdrawSplToken { pub decimals: u8, pub amount: u64, pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### ExecuteSplTokenRevert Struct Definition Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `ExecuteSplTokenRevert` struct, representing an instruction for reverting an SPL Token operation on Solana. It contains similar fields to `ExecuteSplToken` but uses `Pubkey` for the sender. ```rust pub struct ExecuteSplTokenRevert { pub decimals: u8, pub amount: u64, pub sender: Pubkey, pub data: Vec, pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### Rust Struct: Withdraw Instruction Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `Withdraw` struct, used for executing a withdrawal operation on Solana. It contains essential fields such as the amount to withdraw, signature, recovery ID, message hash, and a nonce for transaction security and idempotency. This is typically part of a financial transaction flow. ```rust pub struct Withdraw { pub amount: u64, pub signature: [u8; 64], pub recovery_id: u8, pub message_hash: [u8; 32], pub nonce: u64, } ``` -------------------------------- ### Rust: Withdraw SPL Token from Solana Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Withdraws SPL tokens from the program on Solana, initiated by the TSS. Requires instruction context, token decimals, amount, and signature verification details. ```rust pub fn withdraw_spl_token(ctx: Context<''_, ''_, ''_, ''_, WithdrawSPLToken<''_>>, decimals: u8, amount: u64, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Rust: Define UpdateAuthority Instruction Struct Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `UpdateAuthority` struct, used for an instruction to update the authority address. It contains a `Pubkey` field for the new authority's address. ```rust pub struct UpdateAuthority { pub new_authority_address: Pubkey, } ``` -------------------------------- ### Rust: Define UpdateTss Instruction Struct Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `UpdateTss` struct, used for an instruction to update the TSS (Token Transfer System) address. It holds a 20-byte array representing the TSS address. ```rust pub struct UpdateTss { pub tss_address: [u8; 20], } ``` -------------------------------- ### Borrow Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the Borrow trait, allowing immutable borrowing of the type. The `borrow` method returns an immutable reference `&T` to the contained data. ```rust fn borrow(self: &Self) -> &T { /* ... */ } ``` -------------------------------- ### BorshSerialize Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the BorshSerialize trait for custom types, allowing them to be serialized into a byte stream using the Borsh serialization format. This is crucial for data persistence and network transmission. ```rust fn serialize(self: &Self, writer: &mut W) -> ::core::result::Result<(), borsh::maybestd::io::Error> { /* ... */ } ``` -------------------------------- ### Rust Struct Definition: ResetNonce Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `ResetNonce` struct used for instruction data in Solana. It contains a single field `new_nonce` of type `u64` to specify the new nonce value. This struct likely facilitates nonce reset operations within the protocol. ```rust pub struct ResetNonce { pub new_nonce: u64, } ``` -------------------------------- ### Verify ECDSA TSS Signature in Rust (Solana) Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/README.md This snippet demonstrates how to verify an ECDSA secp256k1 TSS signature within a Solana program using the bundled Rust secp256k1 library. It takes the message hash, signature, and public key components to recover the Ethereum-compatible address. This is crucial for authenticating off-chain signed messages. ```rust pub fn recover_eth_address( message_hash: &[u8; 32], signature: &[u8; 65], public_key: &[u8; 33], ) -> Result<[u8; 20], ProgramError> { let mut compressed_public_key = [0u8; 64]; let mut signature_bytes = [0u8; 64]; signature_bytes.copy_from_slice(&signature[0..64]); // Public key recovery from signature let recovered_pubkey = secp256k1_recover( &signature_bytes, &message_hash, signature[64] % 2 + 27, // v value adjustment ) .map_err(|_| ProgramError::InvalidSignature)?; // Convert recovered public key to compressed format compressed_public_key[1..].copy_from_slice(&recovered_pubkey[1..]); // Verify that the recovered public key matches the provided public key if compressed_public_key != public_key { return Err(ProgramError::InvalidAccountData); } // Hash the public key to get the Ethereum address let eth_address = &solana_program::keccak::keccak256(public_key)[12..32]; let mut result = [0u8; 20]; result.copy_from_slice(eth_address); Ok(result) } ``` -------------------------------- ### BorshDeserialize Trait Implementation Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Implements the BorshDeserialize trait for custom types, enabling them to be deserialized from a byte stream using the Borsh deserialization format. This is essential for reconstructing data from persisted or transmitted formats. ```rust fn deserialize_reader(reader: &mut R) -> ::core::result::Result { /* ... */ } ``` -------------------------------- ### Reset Nonce Value - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Resets the nonce value associated with the program's PDA. This function is callable by the current authority and requires the new nonce value as input. It depends on the 'ResetNonce' context. ```rust pub fn reset_nonce(ctx: Context<''_, ''_, ''_, ''_, ResetNonce<''_>>, new_nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Rust: Define SetDepositPaused Instruction Struct Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Defines the `SetDepositPaused` struct, representing an instruction for pausing deposits. It contains a single boolean field `deposit_paused` to control the paused state. ```rust pub struct SetDepositPaused { pub deposit_paused: bool, } ``` -------------------------------- ### Set Deposit Paused Status - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Allows an authorized caller (authority stored in PDA) to pause or unpause deposit operations. This function takes a boolean flag to determine the new state of deposits. It relies on the 'UpdatePaused' context. ```rust pub fn set_deposit_paused(ctx: Context<''_, ''_, ''_, ''_, UpdatePaused<''_>>, deposit_paused: bool) -> Result<()> { /* ... */ } ``` -------------------------------- ### Unwhitelist SPL Mint Token with Signature Verification - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Removes an SPL token mint from the program's whitelist, revoking its ability to be deposited. This action is performed by the TSS and requires signature verification. It uses the 'Unwhitelist' context and associated signature parameters. ```rust pub fn unwhitelist_spl_mint(ctx: Context<''_, ''_, ''_, ''_, Unwhitelist<''_>>, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` -------------------------------- ### Update Authority Address - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Changes the authority address for the program's PDA. This is a critical security function that must be performed by the current authority. The new authority's public key is passed as an argument. Utilizes the 'UpdateAuthority' context. ```rust pub fn update_authority(ctx: Context<''_, ''_, ''_, ''_, UpdateAuthority<''_>>, new_authority_address: Pubkey) -> Result<()> { /* ... */ } ``` -------------------------------- ### Update TSS Address - Rust Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Enables the update of the Threshold Signature Scheme (TSS) address. This operation can only be performed by the authority stored in the program's PDA. The new TSS address is provided as a 20-byte array. Uses the 'UpdateTss' context. ```rust pub fn update_tss(ctx: Context<''_, ''_, ''_, ''_, UpdateTss<''_>>, tss_address: [u8; 20]) -> Result<()> { /* ... */ } ``` -------------------------------- ### Increment Nonce for Outbound Transactions Source: https://github.com/zeta-chain/protocol-contracts-solana/blob/main/docs/gateway.md Increments the nonce for TSS in case an outbound transaction fails. This function is crucial for maintaining transaction integrity and retries. It requires the instruction context, transaction details like amount and signature, and message hash for verification. ```rust pub fn increment_nonce(ctx: Context<''_, ''_, ''_, ''_, IncrementNonce<''_>>, amount: u64, signature: [u8; 64], recovery_id: u8, message_hash: [u8; 32], nonce: u64) -> Result<()> { /* ... */ } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.