-
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.
- Loading branch information
Showing
12 changed files
with
1,116 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 } | ||
ed25519-dalek = { version = "1.0.1" } |
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; |
289 changes: 289 additions & 0 deletions
289
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,289 @@ | ||
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)] | ||
#[instruction(src_network: String, conn_sn: u128)] | ||
pub struct RecvMessage<'info> { | ||
#[account(mut)] | ||
pub admin: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
|
||
/// Config | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
has_one = admin @ ConnectionError::OnlyAdmin, | ||
)] | ||
pub config: Account<'info, Config>, | ||
|
||
#[account( | ||
init, | ||
payer = admin, | ||
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>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct RevertMessage<'info> { | ||
#[account(mut)] | ||
pub admin: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
|
||
/// Config | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
has_one = admin @ ConnectionError::OnlyAdmin, | ||
)] | ||
pub config: Account<'info, Config>, | ||
|
||
#[account( | ||
seeds = [Authority::SEED_PREFIX.as_bytes()], | ||
bump = authority.bump | ||
)] | ||
pub authority: Account<'info, Authority>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct SetAdmin<'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 admin: Signer<'info>, | ||
|
||
/// System Program: Required to create program-derived address | ||
pub system_program: Program<'info, System>, | ||
|
||
/// Fee | ||
#[account( | ||
init_if_needed, | ||
payer = admin, | ||
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 = admin @ ConnectionError::OnlyAdmin, | ||
)] | ||
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 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)] | ||
pub struct SetThreshold<'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)] | ||
pub struct GetThreshold<'info> { | ||
/// Config | ||
#[account( | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump | ||
)] | ||
pub config: Account<'info, Config>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct AddValidator<'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)] | ||
pub struct RemoveValidator<'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)] | ||
pub struct GetValidators<'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 admin: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
|
||
/// Config | ||
#[account( | ||
mut, | ||
seeds = [Config::SEED_PREFIX.as_bytes()], | ||
bump = config.bump, | ||
has_one = admin @ ConnectionError::OnlyAdmin, | ||
)] | ||
pub config: Account<'info, Config>, | ||
|
||
#[account( | ||
init, | ||
payer = admin, | ||
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,16 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
#[error_code] | ||
pub enum ConnectionError { | ||
#[msg("Only admin")] | ||
OnlyAdmin, | ||
|
||
#[msg("Only xcall")] | ||
OnlyXcall, | ||
|
||
#[msg("Admin Validator Cnnot Be Removed")] | ||
AdminValidatorCnnotBeRemoved, | ||
|
||
#[msg("Validators Must Be Greater Than Threshold")] | ||
ValidatorsMustBeGreaterThanThreshold, | ||
} |
Oops, something went wrong.