Skip to content

Commit

Permalink
Merge pull request igneous-labs#35 from igneous-labs/feat/sanctum-macros
Browse files Browse the repository at this point in the history
Feat: sanctum-macros for compile-time keys derivation
  • Loading branch information
billythedummy authored Dec 24, 2023
2 parents b063676 + 8ff5596 commit d17ecac
Show file tree
Hide file tree
Showing 26 changed files with 1,342 additions and 971 deletions.
1,949 changes: 1,207 additions & 742 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ members = [
[workspace.dependencies]
anyhow = "^1.0"
bincode = "^1.0"
borsh = ">=0.9"
borsh = "^0.9"
jupiter-amm-interface = "~0.3.2"
lazy_static = "^1.0"
num-derive = ">=0.1"
num-traits = ">=0.1"
rust_decimal = "^1.0"
sanctum-macros = "^1.2"
serde = "^1"
solana-client = "^1.9"
solana-program = "^1.9"
Expand Down
5 changes: 3 additions & 2 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ edition = "2021"
anyhow = { workspace = true }
bincode = { workspace = true }
jupiter-amm-interface = { workspace = true }
rust_decimal = "^1.0"
rust_decimal = { workspace = true }
sanctum-macros = { workspace = true }
solana-program = { workspace = true }
solana-sdk = { workspace = true }
spl-token = { workspace = true }
stakedex_deposit_sol_interface = { workspace = true }
stakedex_interface = { workspace = true }
thiserror = { workspace = true }
thiserror = { workspace = true }
14 changes: 10 additions & 4 deletions common/src/address/lido.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
pub mod lido_program {
solana_program::declare_id!("CrX7kMhLC3cSsXJdT7JDgqrRVWGnUpX3gfEfxxU2NVLi");
// .\xc3...xd1 = lido state
sanctum_macros::declare_program_keys!(
"CrX7kMhLC3cSsXJdT7JDgqrRVWGnUpX3gfEfxxU2NVLi",
[
("stake_authority", b".\xc3\x8e\xfaG\x07\x0e\x1f\x83\r)\xbc%\xb8\x18\xa5U`rD\x01{\xdf\x9e\"\x9d\xfab\x18\xa2Y\xd1", b"stake_authority")
]
);
}

pub mod lido_state {
solana_program::declare_id!("49Yi1TKkNyYjPAFdR9LBvoHcUjuPX4Df5T5yv39w2XTn");
sanctum_macros::declare_program_keys!("49Yi1TKkNyYjPAFdR9LBvoHcUjuPX4Df5T5yv39w2XTn", []);
}

pub mod lido_validator_list {
solana_program::declare_id!("GL9kqRNUTUosW3RsDoXHCuXUZn73SgQQmBvtp1ng2co4");
sanctum_macros::declare_program_keys!("GL9kqRNUTUosW3RsDoXHCuXUZn73SgQQmBvtp1ng2co4", []);
}

pub mod stsol {
solana_program::declare_id!("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj");
sanctum_macros::declare_program_keys!("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj", []);
}
15 changes: 12 additions & 3 deletions common/src/address/marinade.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
pub mod marinade_program {
solana_program::declare_id!("MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD");
// u\x11...\xf1 = marinade state addr
sanctum_macros::declare_program_keys!(
"MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD",
[
("liq_pool_sol_leg", b"u\x11\x9b1u\x80u\x86\xe3\xf4\xa7\xe5\xcd\x0f\x89\x0e\x96\xa7S\xb1\x0f\xcc\xc7h\x1e\x94s\xa0\x082p\xf1", b"liq_sol"),
("liq_pool_msol_leg_authority", b"u\x11\x9b1u\x80u\x86\xe3\xf4\xa7\xe5\xcd\x0f\x89\x0e\x96\xa7S\xb1\x0f\xcc\xc7h\x1e\x94s\xa0\x082p\xf1", b"liq_st_sol_authority"),
("msol_mint_auth", b"u\x11\x9b1u\x80u\x86\xe3\xf4\xa7\xe5\xcd\x0f\x89\x0e\x96\xa7S\xb1\x0f\xcc\xc7h\x1e\x94s\xa0\x082p\xf1", b"st_mint"),
("reserve", b"u\x11\x9b1u\x80u\x86\xe3\xf4\xa7\xe5\xcd\x0f\x89\x0e\x96\xa7S\xb1\x0f\xcc\xc7h\x1e\x94s\xa0\x082p\xf1", b"reserve"),
]
);
}

pub mod marinade_state {
solana_program::declare_id!("8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC");
sanctum_macros::declare_program_keys!("8szGkuLTAux9XMgZ2vtY39jVSowEcpBfFfD8hXSEqdGC", []);
}

pub mod msol {
solana_program::declare_id!("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So");
sanctum_macros::declare_program_keys!("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So", []);
}
2 changes: 2 additions & 0 deletions common/src/address/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod lido;
mod marinade;
mod spl_stake_pool_like;
mod stakedex;
mod unstake_it;

pub use lido::*;
pub use marinade::*;
pub use spl_stake_pool_like::*;
pub use stakedex::*;
pub use unstake_it::*;
56 changes: 28 additions & 28 deletions common/src/address/spl_stake_pool_like.rs
Original file line number Diff line number Diff line change
@@ -1,111 +1,111 @@
pub mod cogent_stake_pool {
solana_program::declare_id!("CgntPoLka5pD5fesJYhGmUCF8KU1QS1ZmZiuAuMZr2az");
sanctum_macros::declare_program_keys!("CgntPoLka5pD5fesJYhGmUCF8KU1QS1ZmZiuAuMZr2az", []);
}

pub mod cogent_validator_list {
solana_program::declare_id!("CGNTvFQ5yhxp2H5RmmXJ2w3LXJ3kAHrgPMrfABBTkeTr");
sanctum_macros::declare_program_keys!("CGNTvFQ5yhxp2H5RmmXJ2w3LXJ3kAHrgPMrfABBTkeTr", []);
}

pub mod cogentsol {
solana_program::declare_id!("CgnTSoL3DgY9SFHxcLj6CgCgKKoTBr6tp4CPAEWy25DE");
sanctum_macros::declare_program_keys!("CgnTSoL3DgY9SFHxcLj6CgCgKKoTBr6tp4CPAEWy25DE", []);
}

pub mod daopool_stake_pool {
solana_program::declare_id!("7ge2xKsZXmqPxa3YmXxXmzCp9Hc2ezrTxh6PECaxCwrL");
sanctum_macros::declare_program_keys!("7ge2xKsZXmqPxa3YmXxXmzCp9Hc2ezrTxh6PECaxCwrL", []);
}

pub mod daopool_validator_list {
solana_program::declare_id!("CKG4Jci9tGSrZtetnLXuDKV2WqaknFCUX9CY3ahfw2n6");
sanctum_macros::declare_program_keys!("CKG4Jci9tGSrZtetnLXuDKV2WqaknFCUX9CY3ahfw2n6", []);
}

pub mod daosol {
solana_program::declare_id!("GEJpt3Wjmr628FqXxTgxMce1pLntcPV4uFi8ksxMyPQh");
sanctum_macros::declare_program_keys!("GEJpt3Wjmr628FqXxTgxMce1pLntcPV4uFi8ksxMyPQh", []);
}

pub mod jito_stake_pool {
solana_program::declare_id!("Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb");
sanctum_macros::declare_program_keys!("Jito4APyf642JPZPx3hGc6WWJ8zPKtRbRs4P815Awbb", []);
}

pub mod jito_validator_list {
solana_program::declare_id!("3R3nGZpQs2aZo5FDQvd2MUQ6R7KhAPainds6uT6uE2mn");
sanctum_macros::declare_program_keys!("3R3nGZpQs2aZo5FDQvd2MUQ6R7KhAPainds6uT6uE2mn", []);
}

pub mod jitosol {
solana_program::declare_id!("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn");
sanctum_macros::declare_program_keys!("J1toso1uCk3RLmjorhTtrVwY9HJ7X8V9yYac6Y7kGCPn", []);
}

pub mod jpool_stake_pool {
solana_program::declare_id!("CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1");
sanctum_macros::declare_program_keys!("CtMyWsrUtAwXWiGr9WjHT5fC3p3fgV8cyGpLTo2LJzG1", []);
}

pub mod jpool_validator_list {
solana_program::declare_id!("Ei2LhH2tDKPERnoNjQV5darTToZmbg45vDvftFFLNNWd");
sanctum_macros::declare_program_keys!("Ei2LhH2tDKPERnoNjQV5darTToZmbg45vDvftFFLNNWd", []);
}

pub mod jsol {
solana_program::declare_id!("7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn");
sanctum_macros::declare_program_keys!("7Q2afV64in6N6SeZsAAB81TJzwDoD6zpqmHkzi9Dcavn", []);
}

pub mod laine_stake_pool {
solana_program::declare_id!("2qyEeSAWKfU18AFthrF7JA8z8ZCi1yt76Tqs917vwQTV");
sanctum_macros::declare_program_keys!("2qyEeSAWKfU18AFthrF7JA8z8ZCi1yt76Tqs917vwQTV", []);
}

pub mod laine_validator_list {
solana_program::declare_id!("sHPN95ARJpwN3Yipc22Z3m5118K3czRLBG7WmLDLsMp");
sanctum_macros::declare_program_keys!("sHPN95ARJpwN3Yipc22Z3m5118K3czRLBG7WmLDLsMp", []);
}

pub mod lainesol {
solana_program::declare_id!("LAinEtNLgpmCP9Rvsf5Hn8W6EhNiKLZQti1xfWMLy6X");
sanctum_macros::declare_program_keys!("LAinEtNLgpmCP9Rvsf5Hn8W6EhNiKLZQti1xfWMLy6X", []);
}

pub mod risklol_stake_pool {
solana_program::declare_id!("F8h46pYkaqPJNP2MRkUUUtRkf8efCkpoqehn9g1bTTm7");
sanctum_macros::declare_program_keys!("F8h46pYkaqPJNP2MRkUUUtRkf8efCkpoqehn9g1bTTm7", []);
}

pub mod risklol_validator_list {
solana_program::declare_id!("3p3pwXkx15WSphpmcQyBqJ235pMVQkLYM9t2faBH1Zix");
sanctum_macros::declare_program_keys!("3p3pwXkx15WSphpmcQyBqJ235pMVQkLYM9t2faBH1Zix", []);
}

pub mod risksol {
solana_program::declare_id!("C4kq9QRFLAqwYHK7p4Ez54KMZLZNw2yLsiT3KN4FSmdH");
sanctum_macros::declare_program_keys!("C4kq9QRFLAqwYHK7p4Ez54KMZLZNw2yLsiT3KN4FSmdH", []);
}

pub mod socean_program {
solana_program::declare_id!("5ocnV1qiCgaQR8Jb8xWnVbApfaygJ8tNoZfgPwsgx9kx");
sanctum_macros::declare_program_keys!("5ocnV1qiCgaQR8Jb8xWnVbApfaygJ8tNoZfgPwsgx9kx", []);
}

pub mod socean_stake_pool {
solana_program::declare_id!("5oc4nmbNTda9fx8Tw57ShLD132aqDK65vuHH4RU1K4LZ");
sanctum_macros::declare_program_keys!("5oc4nmbNTda9fx8Tw57ShLD132aqDK65vuHH4RU1K4LZ", []);
}

pub mod socean_validator_list {
solana_program::declare_id!("8pTa29ovYHxjQgX7gjxGi395GAo8DSXCRTKJZvwMc6MR");
sanctum_macros::declare_program_keys!("8pTa29ovYHxjQgX7gjxGi395GAo8DSXCRTKJZvwMc6MR", []);
}

pub mod scnsol {
solana_program::declare_id!("5oVNBeEEQvYi1cX3ir8Dx5n1P7pdxydbGF2X4TxVusJm");
sanctum_macros::declare_program_keys!("5oVNBeEEQvYi1cX3ir8Dx5n1P7pdxydbGF2X4TxVusJm", []);
}

pub mod solblaze_stake_pool {
solana_program::declare_id!("stk9ApL5HeVAwPLr3TLhDXdZS8ptVu7zp6ov8HFDuMi");
sanctum_macros::declare_program_keys!("stk9ApL5HeVAwPLr3TLhDXdZS8ptVu7zp6ov8HFDuMi", []);
}

pub mod solblaze_validator_list {
solana_program::declare_id!("1istpXjy8BM7Vd5vPfA485frrV7SRJhgq5vs3sskWmc");
sanctum_macros::declare_program_keys!("1istpXjy8BM7Vd5vPfA485frrV7SRJhgq5vs3sskWmc", []);
}

pub mod bsol {
solana_program::declare_id!("bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1");
sanctum_macros::declare_program_keys!("bSo13r4TkiE4KumL71LsHTPpL2euBYLFx6h9HP3piy1", []);
}

pub mod mrgn_stake_pool {
solana_program::declare_id!("DqhH94PjkZsjAqEze2BEkWhFQJ6EyU6MdtMphMgnXqeK");
sanctum_macros::declare_program_keys!("DqhH94PjkZsjAqEze2BEkWhFQJ6EyU6MdtMphMgnXqeK", []);
}

pub mod mrgn_validator_list {
solana_program::declare_id!("77Nc7i2Pe4ktkPVsk2KsZeLZRMUMKpddheBUgW727XR4");
sanctum_macros::declare_program_keys!("77Nc7i2Pe4ktkPVsk2KsZeLZRMUMKpddheBUgW727XR4", []);
}

pub mod lst {
solana_program::declare_id!("LSTxxxnJzKDFSLr4dUkPcmCf5VyryEqzPLz5j4bpxFp");
sanctum_macros::declare_program_keys!("LSTxxxnJzKDFSLr4dUkPcmCf5VyryEqzPLz5j4bpxFp", []);
}
14 changes: 14 additions & 0 deletions common/src/address/stakedex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub mod stakedex_program {
sanctum_macros::declare_program_keys!(
"stkitrT1Uoy18Dk1fTrgPw8W6MVzoCfYoAFT4MLsmhq",
[("sol-bridge-out", b"sol_bridge_out")]
);
}

pub mod wsol_bridge_in {
sanctum_macros::create_with_seed!(
"75jTZDE78xpBJokeB2BcimRNY5BZ7U45bWhpgUrTzWZC",
"wsol_bridge_in",
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
);
}
12 changes: 10 additions & 2 deletions common/src/address/unstake_it.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
pub mod unstake_it_program {
solana_program::declare_id!("unpXTU2Ndrc7WWNyEhQWe4udTzSibLPi25SXv2xbCHQ");
// \xde\...\xc6 = unstakeit pool
sanctum_macros::declare_program_keys!(
"unpXTU2Ndrc7WWNyEhQWe4udTzSibLPi25SXv2xbCHQ",
[
("sol_reserves", b"\xde\x91\xbbP4tnb;\xfb6\xb7=\xae\"\xa4\x83\xb7\xcf\'\xd2\xad\x83\xfa\x8cx\x05\xa6\xcc`+\xc6"),
("fee", b"\xde\x91\xbbP4tnb;\xfb6\xb7=\xae\"\xa4\x83\xb7\xcf\'\xd2\xad\x83\xfa\x8cx\x05\xa6\xcc`+\xc6", b"fee"),
("protocol_fee", b"protocol-fee")
]
);
}

pub mod unstake_it_pool {
solana_program::declare_id!("FypPtwbY3FUfzJUtXHSyVRokVKG2jKtH29FmK4ebxRSd");
sanctum_macros::declare_program_keys!("FypPtwbY3FUfzJUtXHSyVRokVKG2jKtH29FmK4ebxRSd", []);
}
12 changes: 5 additions & 7 deletions common/src/deposit_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use stakedex_interface::{StakeWrappedSolKeys, STAKE_WRAPPED_SOL_IX_ACCOUNTS_LEN}
use crate::{
init_from_keyed_account::InitFromKeyedAccount,
jupiter_stakedex_interface::STAKEDEX_ACCOUNT_META,
pda::{
cws_wsol_bridge_in, find_deposit_stake_amm_key, find_fee_token_acc, find_sol_bridge_out,
},
BaseStakePoolAmm, DepositSolQuoteError, TEMPORARY_JUP_AMM_LABEL,
pda::{find_deposit_stake_amm_key, find_fee_token_acc},
stakedex_program, wsol_bridge_in, BaseStakePoolAmm, DepositSolQuoteError,
TEMPORARY_JUP_AMM_LABEL,
};

#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -123,7 +122,6 @@ where
}

fn get_swap_and_account_metas(&self, swap_params: &SwapParams) -> Result<SwapAndAccountMetas> {
let (sol_bridge_out, _) = find_sol_bridge_out();
let mut account_metas = vec![STAKEDEX_ACCOUNT_META.clone()];
account_metas.extend(<[AccountMeta; STAKE_WRAPPED_SOL_IX_ACCOUNTS_LEN]>::from(
StakeWrappedSolKeys {
Expand All @@ -134,8 +132,8 @@ where
dest_token_mint: swap_params.destination_mint,
token_program: spl_token::ID,
system_program: system_program::ID,
wsol_bridge_in: cws_wsol_bridge_in(&sol_bridge_out),
sol_bridge_out,
wsol_bridge_in: wsol_bridge_in::ID,
sol_bridge_out: stakedex_program::SOL_BRIDGE_OUT_ID,
dest_token_fee_token_account: find_fee_token_acc(&swap_params.destination_mint).0,
},
));
Expand Down
20 changes: 0 additions & 20 deletions common/src/pda.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
use solana_program::pubkey::Pubkey;

pub const WSOL_BRIDGE_IN_SEED: &str = "wsol_bridge_in";

pub const SOL_BRIDGE_OUT_SEED: &[u8; 14] = b"sol_bridge_out";

pub const FEE_TOKEN_ACCOUNT_SEED_PREFIX: &[u8; 3] = b"fee";

pub const BRIDGE_STAKE_SEED_PREFIX: &[u8; 12] = b"bridge_stake";

pub fn sol_bridge_out_seeds() -> [&'static [u8]; 1] {
[SOL_BRIDGE_OUT_SEED]
}

pub fn fee_token_account_seeds(token_mint: &Pubkey) -> [&[u8]; 2] {
[FEE_TOKEN_ACCOUNT_SEED_PREFIX, token_mint.as_ref()]
}
Expand All @@ -38,18 +30,6 @@ pub fn bridge_stake_seeds<'seeds>(
]
}

pub fn cws_wsol_bridge_in(sol_bridge_out: &Pubkey) -> Pubkey {
// unwrap() safety:
// - MaxSeedLengthExceeded: WSOL_BRIDGE_IN_SEED is safe
// - InvalidSeeds: tested with program key, is safe
// - IllegalOwner: spl_token::ID is not illegal
Pubkey::create_with_seed(sol_bridge_out, WSOL_BRIDGE_IN_SEED, &spl_token::ID).unwrap()
}

pub fn find_sol_bridge_out() -> (Pubkey, u8) {
Pubkey::find_program_address(&sol_bridge_out_seeds(), &stakedex_interface::ID)
}

pub fn find_fee_token_acc(mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(&fee_token_account_seeds(mint), &stakedex_interface::ID)
}
Expand Down
9 changes: 0 additions & 9 deletions interfaces/stakedex_deposit_sol_interface/src/typedefs.rs

This file was deleted.

5 changes: 0 additions & 5 deletions interfaces/stakedex_deposit_stake_interface/src/typedefs.rs

This file was deleted.

12 changes: 0 additions & 12 deletions interfaces/stakedex_interface/src/typedefs.rs

This file was deleted.

6 changes: 0 additions & 6 deletions interfaces/stakedex_withdraw_stake_interface/src/typedefs.rs

This file was deleted.

4 changes: 1 addition & 3 deletions libs/lido/src/stakedex_traits/withdraw_stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ impl WithdrawStakeBase for LidoStakedex {
Ok(lido_withdraw_stake_ix(LidoWithdrawStakeKeys {
lido_program: lido_program::ID,
withdraw_stake_solido: lido_state::ID,
withdraw_stake_stake_authority: self
.lido_state
.get_stake_authority(&lido_program::ID, &lido_state::ID)?,
withdraw_stake_stake_authority: lido_program::STAKE_AUTHORITY_ID,
withdraw_stake_stake_to_split: validator
.find_stake_account_address(
&lido_program::ID,
Expand Down
1 change: 0 additions & 1 deletion libs/marinade/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod calc;
mod consts;
mod liq_pool;
mod stakedex_traits;
mod state;
mod validator_system;
Expand Down
Loading

0 comments on commit d17ecac

Please sign in to comment.