Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/target
target
Cargo.lock
19 changes: 19 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "squifi-cli"
version = "0.1.0"
authors = ["Callum Michael Waters <cmwaters19@gmail.com>", "Marko Baricevic <marbar3778@yahoo.com>"]
description = "Squifi - Squad Finance Command Line Tool"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = "2.33.3"
solana-clap-utils = "1.4.5"
fund = {path = "../"}
client = {path = "../client/"}

[[bin]]
name = "squifi"
path = "src/main.rs"

148 changes: 148 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
use clap::{crate_name, crate_description, crate_version, value_t, Arg, App, SubCommand };
use solana_clap_utils::{
input_parsers::pubkey_of,
input_validators::{is_keypair, is_pubkey},
keypair::signer_from_path,
};
use std::process::exit;
use fund::accounts::{fund::FundType};
use client::{create_fund, check_balance};

type Error = Box<dyn std::error::Error>;

const DEFAULT_MAX_BALANCE: u64 = 1000;

struct Config {
rpc_client: RpcClient,
pool: Pubkey,
owner: Box<dyn Signer>,
fee_payer: Box<dyn Signer>,
}

fn main() {
let matches = App::new(crate_name!())
.about(crate_description!())
.version(crate_version!())
.arg({
let arg = Arg::with_name("config_file")
.short("c")
.long("config")
.value_name("PATH")
.takes_value(true)
.global(true)
.help("Configuration file to use");
if let Some(ref config_file) = *solana_cli_config::CONFIG_FILE {
arg.default_value(&config_file)
} else {
arg
}
})
.subcommand(
SubCommand::with_name("create")
.about("creates a new pool")
)
.subcommand(
SubCommand::with_name("list")
.about("lists pools user account has access to")
)
.subcommand(
SubCommand::with_name("balance")
.about("show the balance of a pool")
.arg(
Arg::with_name("pool")
.validator(is_pubkey)
.value_name("POOL")
.index(1)
.help("the pool with which you wish to check the balance of")
.takes_value(true)
.required(true)
)
)
.subcommand(
SubCommand::with_name("deposit")
.about("deposit tokens into a pool")
)
.subcommand(
SubCommand::with_name("proposals")
.about("create, view and vote on proposals")
.subcommand(
SubCommand::with_name("create")
.about("create a proposal for a pool")
)
.subcommand(
SubCommand::with_name("list")
.about("create a proposal for a pool")
)
.subcommand(
SubCommand::with_name("vote")
.about("create a proposal for a pool")
)
)
.subcommand(
SubCommand::with_name("withdraw")
.about("withdraw allocated tokens")
)
.subcommand(
SubCommand::with_name("destroy")
.about("destroys the pool")
)
.get_matches();

let config = {
let cli_config = if let Some(config_file) = matches.value_of("config_file") {
solana_cli_config::Config::load(config_file).unwrap_or_default()
} else {
solana_cli_config::Config::default()
};
let json_rpc_url = value_t!(matches, "json_rpc_url", String)
.unwrap_or_else(|_| cli_config.json_rpc_url.clone());

let mut wallet_manager = None;
let owner = signer_from_path(
&matches,
&cli_config.keypair_path,
"owner",
&mut wallet_manager,
)
.unwrap_or_else(|e| {
println!("error: {}", e);
exit(1);
});

let fee_payer = signer_from_path(
&matches,
&cli_config.keypair_path,
"fee_payer",
&mut wallet_manager,
)
.unwrap_or_else(|e| {
println!("error: {}", e);
exit(1);
});

Config {
rpc: RpcClient::new(json_rpc_url),
owner: owner,
fee_payer: fee_payer
}
};

let _ = match matches.subcommand() {
("create", Some(_arg_matches)) => {
// should save account to the config
let account = create_fund(
&config.rpc_client,
&config.owner.pubkey(),
config.fee_payer,
DEFAULT_MAX_BALANCE,
FundType::FundMe,
);
}
("balance", Some(arg_matches)) => {
let pool = pubkey_of(arg_matches, "pool").unwrap();
check_balance(&config, pool)
}
_ => unreachable!(),
};
}

13 changes: 13 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "squifi-client"
version = "0.1.0"
authors = ["Callum Michael Waters <cmwaters19@gmail.com>", "Marko Baricevic <marbar3778@yahoo.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
fund = {path = "../"}
serum-common = {git = "https://github.com/project-serum/serum-dex", features = ["program"]}
solana-client = "1.4.5"
solana-sdk = "1.4.5"
55 changes: 55 additions & 0 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use solana_sdk::{
signature::{Keypair},
pubkey::Pubkey,
transaction::Transaction,
};
use solana_client::{
rpc_client::RpcClient,
};
use serum_common::client::rpc;
use fund::{
accounts::{fund::FundType},
instruction::FundInstruction,
};

#[cfg(feature = "client")]
lazy_static::lazy_static! {
pub static ref SIZE: u64 = Vesting::default()
.size()
.expect("Vesting has a fixed size");
}

pub fn create_fund(
client: &RpcClient,
owner: &Pubkey,
payer: &Keypair,
max_balance: u64,
fund_type: FundType,
) -> Result<Keypair> {
let account = serum_common::client::rpc::create_account_rent_exempt(client, payer, SIZE, owner);

let signers = vec![payer, &account];

let create_fund_instruction = FundInstruction::Initialize(
&owner,
&account.pubkey(),
max_balance,
fund_type,
);

let (recent_hash, _fee_calc) = client.get_recent_blockhash()?;

let txn = Transaction::new_signed_with_payer(
&[create_fund_instruction],
Some(&payer.pubkey()),
&signers,
recent_hash,
);

serum_common::client::rpc::send_txn(client, &txn, false)?;
Ok(account)
}

pub fn check_balance(fund: Pubkey) {
println!("Checking balance...")
}
2 changes: 0 additions & 2 deletions program/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version = "0.1.0"

[lib]
crate-type = ["cdylib", "lib"]
name = "fund_program"
name = "spool_fund"

[features]
program = ["spl-token/program", "spl-token/no-entrypoint", "fund/program"]
Expand Down
4 changes: 4 additions & 0 deletions program/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use solana_program::{
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, info, pubkey::Pubkey,
};

pub use solana_program;

solana_program::declare_id!("SPQQL11111111111111111111111111111111111111");

pub(crate) mod access_control;
mod close;
mod deposit;
Expand Down