Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: update interface and make common lib #158

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ repos:
hooks:
- id: fmt
- id: clippy
args: ["--tests", "--", "-Dwarnings"]
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"[json]": {
"editor.tabSize": 2
},
"[jsonc]": {
"editor.tabSize": 2
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 36 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
[workspace]
members = ["programs/*", "cli-rust", "unstake_interface"]
resolver = "2"
members = ["programs/*", "cli-rust", "unstake-lib", "unstake_interface"]

[workspace.dependencies]
anchor-lang = "0.28.0"
anchor-spl = "0.28.0"
base64 = "0.21.2"
clap = { version = "^4.0" }
clap2 = { package = "clap", version = "^2.0" }
borsh = ">=0.9"
derive_more = "^0.99"
mpl-token-metadata = "^1"
num-derive = ">=0.1"
num-traits = ">=0.1"
proptest = "^1"
serde = "^1"
serde_json = "^1"
spl-associated-token-account = "^1.1" # required for anchor-spl token
spl-token = "^3.0"
spl-math = ">=0.1"
thiserror = "^1"

# solana deps
# Lock to 1.14.20 for prod, but >=1 for flexibility for library users
solana-account-decoder = ">=1"
solana-clap-utils = ">=1"
solana-cli-config = ">=1"
solana-client = ">=1"
solana-sdk = ">=1"
solana-program = ">=1"
solana-stake-program = ">=1"

# workspace members
unstake = { path = "./programs/unstake" }
unstake-lib = { path = "./unstake-lib" }
unstake_interface = { path = "./unstake_interface" }
40 changes: 20 additions & 20 deletions cli-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ name = "unstakeit"
path = "src/main.rs"

[dependencies]
anchor-lang = "0.28.0"
base64 = "0.21.2"
borsh = "^0.9.1"
clap = { version = "^4.0", features = ["derive"] }
clap2 = { package = "clap", version = "^2.0" } # required for solana-clap-utils
derive_more = "^0.99"
mpl-token-metadata = "^1.13"
serde = { version = "1.0.171", features = ["derive"] }
serde_json = "1.0.103"
solana-account-decoder = "~1.14"
solana-clap-utils = "~1.14"
solana-cli-config = "~1.14"
solana-client = "~1.14"
solana-sdk = "~1.14"
solana-program = "~1.14"
solana-stake-program = "~1.14"
spl-associated-token-account = "1.1.1"
spl-token = "^3.0"
unstake = { path = "../programs/unstake" }
unstake_interface = { path = "../unstake_interface", features = ["serde"] }
anchor-lang = { workspace = true }
base64 = { workspace = true }
borsh = { workspace = true }
clap = { workspace = true, features = ["derive"] }
clap2 = { workspace = true } # required for solana-clap-utils
derive_more = { workspace = true }
mpl-token-metadata = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
solana-account-decoder = { workspace = true }
solana-clap-utils = { workspace = true }
solana-cli-config = { workspace = true }
solana-client = { workspace = true }
solana-sdk = { workspace = true }
solana-program = { workspace = true }
solana-stake-program = { workspace = true }
spl-associated-token-account = { workspace = true }
spl-token = { workspace = true }
unstake = { workspace = true }
unstake_interface = { workspace = true, features = ["serde"] }
21 changes: 8 additions & 13 deletions cli-rust/src/subcmd/deactivate_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use clap::Args;

use solana_program::{pubkey::Pubkey, sysvar};
use unstake::ID;
use unstake_interface::{
deactivate_stake_account_ix, DeactivateStakeAccountIxArgs, DeactivateStakeAccountKeys,
};
use unstake_interface::{deactivate_stake_account_ix, DeactivateStakeAccountKeys};

use crate::{
tx_utils::{batch_ixs, chunk_array, send_or_sim_tx},
Expand Down Expand Up @@ -58,16 +56,13 @@ impl SubcmdExec for DeactivateAllArgs {
println!("Generating txs...");
let mut deactivate_ixs = Vec::new();
for stake_account in stake_accounts_to_deactivate.iter() {
let ix = deactivate_stake_account_ix(
DeactivateStakeAccountKeys {
pool_account,
pool_sol_reserves: pool_sol_reserves.0,
clock: sysvar::clock::id(),
stake_account: *stake_account,
stake_program: solana_stake_program::id(),
},
DeactivateStakeAccountIxArgs {},
)
let ix = deactivate_stake_account_ix(DeactivateStakeAccountKeys {
pool_account,
pool_sol_reserves: pool_sol_reserves.0,
clock: sysvar::clock::id(),
stake_account: *stake_account,
stake_program: solana_stake_program::id(),
})
.unwrap();
deactivate_ixs.push(ix);
}
Expand Down
21 changes: 8 additions & 13 deletions cli-rust/src/subcmd/deactivate_stake_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use clap::Args;
use solana_program::{message::Message, pubkey::Pubkey, sysvar};
use solana_sdk::transaction::Transaction;
use unstake::ID;
use unstake_interface::{
deactivate_stake_account_ix, DeactivateStakeAccountIxArgs, DeactivateStakeAccountKeys,
};
use unstake_interface::{deactivate_stake_account_ix, DeactivateStakeAccountKeys};

use crate::tx_utils::send_or_sim_tx;

Expand All @@ -32,16 +30,13 @@ impl SubcmdExec for DeactivateStakeAccountArgs {

let stake_account = Pubkey::from_str(&self.stake_account).unwrap();

let ix = deactivate_stake_account_ix(
DeactivateStakeAccountKeys {
pool_account,
pool_sol_reserves: pool_sol_reserves.0,
clock: sysvar::clock::id(),
stake_account,
stake_program: solana_stake_program::id(),
},
DeactivateStakeAccountIxArgs {},
)
let ix = deactivate_stake_account_ix(DeactivateStakeAccountKeys {
pool_account,
pool_sol_reserves: pool_sol_reserves.0,
clock: sysvar::clock::id(),
stake_account,
stake_program: solana_stake_program::id(),
})
.unwrap();

let payer_pk = payer.pubkey();
Expand Down
15 changes: 6 additions & 9 deletions cli-rust/src/subcmd/init_protocol_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::Args;
use solana_program::{pubkey::Pubkey, system_program};
use solana_sdk::transaction::Transaction;
use unstake::{state::PROTOCOL_FEE_SEED, ID};
use unstake_interface::{init_protocol_fee_ix, InitProtocolFeeIxArgs, InitProtocolFeeKeys};
use unstake_interface::{init_protocol_fee_ix, InitProtocolFeeKeys};

use crate::tx_utils::send_or_sim_tx;

Expand All @@ -19,14 +19,11 @@ impl SubcmdExec for InitProtocolFeeArgs {

let protocol_fee_account = Pubkey::find_program_address(&[PROTOCOL_FEE_SEED], &ID);

let ix = init_protocol_fee_ix(
InitProtocolFeeKeys {
payer: payer.pubkey(),
protocol_fee_account: protocol_fee_account.0,
system_program: system_program::id(),
},
InitProtocolFeeIxArgs {},
)
let ix = init_protocol_fee_ix(InitProtocolFeeKeys {
payer: payer.pubkey(),
protocol_fee_account: protocol_fee_account.0,
system_program: system_program::id(),
})
.unwrap();

let blockhash = client.get_latest_blockhash().unwrap();
Expand Down
25 changes: 10 additions & 15 deletions cli-rust/src/subcmd/reclaim_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use clap::Args;

use solana_program::{pubkey::Pubkey, sysvar};
use unstake::ID;
use unstake_interface::{
reclaim_stake_account_ix, ReclaimStakeAccountIxArgs, ReclaimStakeAccountKeys,
};
use unstake_interface::{reclaim_stake_account_ix, ReclaimStakeAccountKeys};

use crate::{
tx_utils::{batch_ixs, chunk_array, send_or_sim_tx},
Expand Down Expand Up @@ -64,18 +62,15 @@ impl SubcmdExec for ReclaimAllArgs {
&[&pool_account.to_bytes(), &stake_account.to_bytes()],
&ID,
);
let ix = reclaim_stake_account_ix(
ReclaimStakeAccountKeys {
pool_account,
pool_sol_reserves: pool_sol_reserves.0,
clock: sysvar::clock::id(),
stake_account: *stake_account,
stake_account_record_account: stake_account_record_account.0,
stake_history: sysvar::stake_history::id(),
stake_program: solana_stake_program::id(),
},
ReclaimStakeAccountIxArgs {},
)
let ix = reclaim_stake_account_ix(ReclaimStakeAccountKeys {
pool_account,
pool_sol_reserves: pool_sol_reserves.0,
clock: sysvar::clock::id(),
stake_account: *stake_account,
stake_account_record_account: stake_account_record_account.0,
stake_history: sysvar::stake_history::id(),
stake_program: solana_stake_program::id(),
})
.unwrap();
reclaim_ixs.push(ix);
}
Expand Down
25 changes: 10 additions & 15 deletions cli-rust/src/subcmd/reclaim_stake_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use clap::Args;
use solana_program::{message::Message, pubkey::Pubkey, sysvar};
use solana_sdk::transaction::Transaction;
use unstake::ID;
use unstake_interface::{
reclaim_stake_account_ix, ReclaimStakeAccountIxArgs, ReclaimStakeAccountKeys,
};
use unstake_interface::{reclaim_stake_account_ix, ReclaimStakeAccountKeys};

use crate::tx_utils::send_or_sim_tx;

Expand Down Expand Up @@ -38,18 +36,15 @@ impl SubcmdExec for ReclaimStakeAccountArgs {
&ID,
);

let ix = reclaim_stake_account_ix(
ReclaimStakeAccountKeys {
pool_account,
pool_sol_reserves: pool_sol_reserves.0,
clock: sysvar::clock::id(),
stake_account,
stake_account_record_account: stake_account_record_account.0,
stake_history: sysvar::stake_history::id(),
stake_program: solana_stake_program::id(),
},
ReclaimStakeAccountIxArgs {},
)
let ix = reclaim_stake_account_ix(ReclaimStakeAccountKeys {
pool_account,
pool_sol_reserves: pool_sol_reserves.0,
clock: sysvar::clock::id(),
stake_account,
stake_account_record_account: stake_account_record_account.0,
stake_history: sysvar::stake_history::id(),
stake_program: solana_stake_program::id(),
})
.unwrap();

let payer_pk = payer.pubkey();
Expand Down
15 changes: 6 additions & 9 deletions cli-rust/src/subcmd/set_fee_authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use clap::Args;
use solana_program::{message::Message, pubkey::Pubkey};
use solana_sdk::{signature::read_keypair_file, signer::Signer, transaction::Transaction};
use unstake_interface::{set_fee_authority_ix, SetFeeAuthorityIxArgs, SetFeeAuthorityKeys};
use unstake_interface::{set_fee_authority_ix, SetFeeAuthorityKeys};

use crate::tx_utils::send_or_sim_tx;

Expand Down Expand Up @@ -39,14 +39,11 @@ impl SubcmdExec for SetFeeAuthorityArgs {
signers.push(Box::new(fee_authority_keypair));
}

let ix = set_fee_authority_ix(
SetFeeAuthorityKeys {
pool_account,
fee_authority,
new_fee_authority,
},
SetFeeAuthorityIxArgs {},
)
let ix = set_fee_authority_ix(SetFeeAuthorityKeys {
pool_account,
fee_authority,
new_fee_authority,
})
.unwrap();

let msg = Message::new(&[ix], Some(&payer_pk));
Expand Down
28 changes: 17 additions & 11 deletions programs/unstake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ local-testing = []

default = []

[dev-dependencies]
proptest = "1.0"

[dependencies.spl-math]
version = "0.1.0"
features = ["no-entrypoint"]
# Can't use workspace dependencies here because:
# We're using solana-program 1.14 that can't handle workspace dependencies.
# But if we try to upgrade to 1.16, anchor 0.28.0 depends on mpl-token-metadata ^1,
# which has borsh compat issues.
# Fuck this. I'm not gonna waste any more time upgrading anchor or trying to fix this.
# We will remove anchor from all our programs at some point.

[dependencies]
anchor-lang = { version = "0.28.0", features = ["init-if-needed"] }
anchor-spl = { version = "0.28.0", features = ["metadata", "stake", "token"] }
mpl-token-metadata = { version = "^1.13", features = ["no-entrypoint"] }
serde = { version = "1.0.171", features = ["derive"] }
spl-associated-token-account = "^1.1" # required for anchor-spl token
anchor-lang = { workspace = true, features = ["init-if-needed"] }
anchor-spl = { workspace = true, features = ["metadata", "stake", "token"] }
mpl-token-metadata = { workspace = true, features = ["no-entrypoint"] }
serde = { workspace = true, features = ["derive"] }
spl-associated-token-account = { workspace = true, features = ["no-entrypoint"] } # required for anchor-spl token
spl-math = { workspace = true, features = ["no-entrypoint"] }
unstake_interface = { workspace = true }
unstake-lib = { workspace = true }

[dev-dependencies]
proptest = "^1"
Loading