-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: solana cluster connection (#405)
* fix: solana cluster connection init * fix: solana cluster connection * fix: solana cluster spec update * fix: tests * feat: solana changes according to centralized * fix: increased config size * fix: break if thereshold met --------- Co-authored-by: gcranju <[email protected]> Co-authored-by: ibrizsabin <[email protected]>
- Loading branch information
1 parent
8d50787
commit 1d60dd5
Showing
12 changed files
with
987 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "cluster-connection" | ||
version = "0.1.0" | ||
description = "Created with Anchor" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
name = "cluster_connection" | ||
|
||
[features] | ||
default = [] | ||
cpi = ["no-entrypoint"] | ||
no-entrypoint = [] | ||
no-idl = [] | ||
no-log-ix-name = [] | ||
idl-build = ["anchor-lang/idl-build"] | ||
|
||
[dependencies] | ||
anchor-lang = { workspace = true, features = ["init-if-needed"] } | ||
|
||
xcall-lib = { workspace = true } | ||
rlp = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.bpfel-unknown-unknown.dependencies.std] | ||
features = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const ACCOUNT_DISCRIMINATOR_SIZE: usize = 8; |
198 changes: 198 additions & 0 deletions
198
contracts/solana/programs/cluster-connection/src/contexts.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
use crate::{error::ConnectionError, state::*}; | ||
|
||
#[derive(Accounts)] | ||
pub struct Initialize<'info> { | ||
/// Rent payer | ||
#[account(mut)] | ||
pub signer: Signer<'info>, | ||
|
||
/// System Program: Required for creating the centralized-connection config | ||
pub system_program: Program<'info, System>, | ||
|
||
/// Config | ||
#[account( | ||
init, | ||
payer = signer, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump, | ||
space = Config::LEN | ||
)] | ||
pub config: Account<'info, Config>, | ||
|
||
#[account( | ||
init, | ||
payer = signer, | ||
space = Authority::LEN, | ||
seeds = [Authority::SEED_PREFIX.as_bytes()], | ||
bump | ||
)] | ||
pub authority: Account<'info, Authority>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(to: String)] | ||
pub struct SendMessage<'info> { | ||
#[account(mut)] | ||
pub signer: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
|
||
#[account( | ||
owner = config.xcall @ ConnectionError::OnlyXcall | ||
)] | ||
pub xcall: Signer<'info>, | ||
|
||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
)] | ||
pub config: Account<'info, Config>, | ||
|
||
#[account( | ||
seeds = [NetworkFee::SEED_PREFIX.as_bytes(), to.as_bytes()], | ||
bump = network_fee.bump | ||
)] | ||
pub network_fee: Account<'info, NetworkFee>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct RevertMessage<'info> { | ||
#[account(mut)] | ||
pub relayer: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
|
||
/// Config | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
has_one = relayer @ ConnectionError::OnlyRelayer, | ||
)] | ||
pub config: Account<'info, Config>, | ||
|
||
#[account( | ||
seeds = [Authority::SEED_PREFIX.as_bytes()], | ||
bump = authority.bump | ||
)] | ||
pub authority: Account<'info, Authority>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct SetConfigItem<'info> { | ||
/// Transaction signer | ||
#[account(mut)] | ||
pub admin: Signer<'info>, | ||
|
||
/// Config | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
has_one = admin @ ConnectionError::OnlyAdmin, | ||
)] | ||
pub config: Account<'info, Config>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(network_id: String)] | ||
pub struct SetFee<'info> { | ||
/// Rent payer | ||
#[account(mut)] | ||
pub relayer: Signer<'info>, | ||
|
||
/// System Program: Required to create program-derived address | ||
pub system_program: Program<'info, System>, | ||
|
||
/// Fee | ||
#[account( | ||
init_if_needed, | ||
payer = relayer, | ||
seeds = [NetworkFee::SEED_PREFIX.as_bytes(), network_id.as_bytes()], | ||
bump, | ||
space = NetworkFee::LEN | ||
)] | ||
pub network_fee: Account<'info, NetworkFee>, | ||
|
||
/// Config | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
has_one = relayer @ ConnectionError::OnlyRelayer, | ||
)] | ||
pub config: Account<'info, Config>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(network_id: String)] | ||
pub struct GetFee<'info> { | ||
/// Fee | ||
#[account( | ||
seeds = [NetworkFee::SEED_PREFIX.as_bytes(), network_id.as_bytes()], | ||
bump = network_fee.bump | ||
)] | ||
pub network_fee: Account<'info, NetworkFee>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct ClaimFees<'info> { | ||
/// Rent payer | ||
#[account(mut)] | ||
pub relayer: Signer<'info>, | ||
|
||
/// Config | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
has_one = relayer @ ConnectionError::OnlyRelayer, | ||
)] | ||
pub config: Account<'info, Config>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct GetConfigItem<'info> { | ||
/// Config | ||
#[account( | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump | ||
)] | ||
pub config: Account<'info, Config>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(src_network: String, conn_sn: u128)] | ||
pub struct ReceiveMessageWithSignatures<'info> { | ||
#[account(mut)] | ||
pub relayer: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
|
||
/// Config | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
has_one = relayer @ ConnectionError::OnlyRelayer, | ||
)] | ||
pub config: Account<'info, Config>, | ||
|
||
#[account( | ||
init, | ||
payer = relayer, | ||
seeds = [Receipt::SEED_PREFIX.as_bytes(), src_network.as_bytes(), &conn_sn.to_be_bytes()], | ||
space = Receipt::LEN, | ||
bump | ||
)] | ||
pub receipt: Account<'info, Receipt>, | ||
|
||
#[account( | ||
seeds = [Authority::SEED_PREFIX.as_bytes()], | ||
bump = authority.bump | ||
)] | ||
pub authority: Account<'info, Authority>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
#[error_code] | ||
pub enum ConnectionError { | ||
#[msg("Only admin")] | ||
OnlyAdmin, | ||
|
||
#[msg("Only relayer")] | ||
OnlyRelayer, | ||
|
||
#[msg("Only xcall")] | ||
OnlyXcall, | ||
|
||
#[msg("Admin Validator Cnnot Be Removed")] | ||
AdminValidatorCnnotBeRemoved, | ||
|
||
#[msg("Validators Must Be Greater Than Threshold")] | ||
ValidatorsMustBeGreaterThanThreshold, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![allow(non_snake_case)] | ||
|
||
use anchor_lang::prelude::*; | ||
|
||
#[event] | ||
pub struct SendMessage { | ||
pub targetNetwork: String, | ||
pub connSn: u128, | ||
pub msg: Vec<u8>, | ||
} |
Oops, something went wrong.