Skip to content

Commit

Permalink
Merge pull request #2 from sol-farm/feat/atrix-instructions
Browse files Browse the repository at this point in the history
Add Atrix Instructions
  • Loading branch information
bonedaddy authored Apr 1, 2022
2 parents 3f61658 + d8260a4 commit 3322b2d
Show file tree
Hide file tree
Showing 10 changed files with 684 additions and 66 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
target
file.json
35 changes: 33 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"atrix",
"accounts",
"config",
]
Expand Down
2 changes: 1 addition & 1 deletion accounts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "so-defi-accounts"
version = "0.1.0"
version = "0.1.4"
edition = "2021"
authors = ["Tulip Protocol"]
description = "accounts types for solana defi protocols"
Expand Down
222 changes: 162 additions & 60 deletions accounts/src/atrix.rs
Original file line number Diff line number Diff line change
@@ -1,72 +1,174 @@
//! atrix account definitions taken from https://github.com/skaiba0/atrix-farm/blob/main/farmSdk/idl/farm.json
use solana_program::{self, pubkey::Pubkey};
use borsh_derive::{BorshDeserialize, BorshSerialize};
use solana_program::{self, pubkey::Pubkey};

#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct FarmAccount {
_buffer: [u8; 8],
pub base: Pubkey,
pub bump: u8,
pub state_mint: Pubkey,
pub farm_stake_token_account: Pubkey,
pub crop_accounts: [Option<Pubkey>; 4],
pub authority: Pubkey,
}
pub mod farm {
use super::*;
#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct FarmAccount {
_buffer: [u8; 8],
pub base: Pubkey,
pub bump: u8,
pub state_mint: Pubkey,
pub farm_stake_token_account: Pubkey,
pub crop_accounts: [Option<Pubkey>; 4],
pub authority: Pubkey,
}

#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct CropAccount {
_buffer: [u8; 8],
pub authority: Pubkey,
pub farm_account: Pubkey,
pub reward_mint: Pubkey,
pub reward_amount_per_day: u64,
pub rewards_locked: bool,
pub crop_reward_token_account: Pubkey,
pub accrued_reward_per_stake: u128,
pub last_reward_timestamp: i64,
}
#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct CropAccount {
_buffer: [u8; 8],
pub bump: u8,
pub authority: Pubkey,
pub farm_account: Pubkey,
pub reward_mint: Pubkey,
pub reward_amount_per_day: u64,
pub rewards_locked: bool,
pub crop_reward_token_account: Pubkey,
pub accrued_reward_per_stake: u128,
pub last_reward_timestamp: i64,
}

#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct StakerAccount {
_buffer: [u8; 8],
pub bump: u8,
pub farm_account: Pubkey,
pub authority: Pubkey,
pub staked_amount: u64,
}
#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct StakerAccount {
_buffer: [u8; 8],
pub bump: u8,
pub farm_account: Pubkey,
pub authority: Pubkey,
pub staked_amount: u64,
}

#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct HarvesterAccount {
_buffer: [u8; 8],
pub bump: u8,
pub crop_account: Pubkey,
pub reward_debt: u128,
pub earned_rewards: u64,
pub authority: Pubkey,
}
#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct HarvesterAccount {
_buffer: [u8; 8],
pub bump: u8,
pub crop_account: Pubkey,
pub reward_debt: u128,
pub earned_rewards: u64,
pub authority: Pubkey,
}

#[cfg(test)]
mod test {
use super::farm::*;
use borsh::BorshDeserialize;
use solana_client::rpc_client;
use solana_program::{self, system_program};
use static_pubkey::static_pubkey;
#[test]
fn test_load_farm_account() {
let test_key = static_pubkey!("J55atXt8BnF99YUC4AmpHY2VuxZ6XbBTjL7dHaePid42");
let rpc = rpc_client::RpcClient::new("https://ssc-dao.genesysgo.net".to_string());
let farm_account_data = rpc.get_account_data(&test_key).unwrap();
let farm_account = FarmAccount::deserialize(&mut &farm_account_data[..]).unwrap();
println!("{:#?}", farm_account);
for crop_account in farm_account.crop_accounts.iter() {
if let Some(crop_account) = crop_account {
let crop_account_data = rpc.get_account_data(crop_account).unwrap();
println!("crop_address {}", crop_account);
let crop_account =
CropAccount::deserialize(&mut &crop_account_data[..]).unwrap();
println!("crop_account {:#?}", crop_account);
}
}
}
}
}

#[cfg(test)]
mod test {
pub mod pool {
use super::*;
use borsh::BorshDeserialize;
use static_pubkey::static_pubkey;
use solana_program::{self, system_program};
use solana_client::rpc_client;
#[test]
fn test_load_farm_account() {
let test_key = static_pubkey!("J55atXt8BnF99YUC4AmpHY2VuxZ6XbBTjL7dHaePid42");
let rpc = rpc_client::RpcClient::new("https://ssc-dao.genesysgo.net".to_string());
let farm_account_data = rpc.get_account_data(&test_key).unwrap();
let farm_account = FarmAccount::deserialize(&mut &farm_account_data[..]).unwrap();
println!("{:#?}", farm_account);
for crop_account in farm_account.crop_accounts.iter() {
if let Some(crop_account) = crop_account {
let crop_account_data = rpc.get_account_data(crop_account).unwrap();
let crop_account = CropAccount::deserialize(&mut &crop_account_data[..]).unwrap();
println!("crop_account {:#?}", crop_account);
}

#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct ProtocolAccount {
_buffer: [u8; 8],
pub authority: Pubkey,
pub bump: u8,
pub lp_fee_numerator: u16,
pub protocol_fee_numerator: u16,
pub fee_denominator: u16,
pub max_cancel_per_ix: u8,
pub max_place_per_ix: u8,
pub max_place_post_liq: u8,
pub order_proportion_numerators: [u16; 12],
pub order_proportion_len: u8,
pub order_proportion_denominator: u16,
pub crank_sol_account: Pubkey,
pub pool_init_crank_fee: u64,
pub sol_bond: u64,
}

#[derive(Debug, Default, Clone, BorshDeserialize, BorshSerialize)]
pub struct PoolAccount {
_buffer: [u8; 8],
pub coin_mint: Pubkey,
pub pc_mint: Pubkey,
pub market: Pubkey,
pub open_orders: Pubkey,
pub pool_coin_account: Pubkey,
pub pool_pc_account: Pubkey,
pub pool_lp_account: Pubkey,
pub lp_mint: Pubkey,
pub first_placed: bool,
pub order_index: u8,
pub coin_current_protocol_fees: u64,
pub pc_current_protocol_fees: u64,
pub ixi: u8,
pub icx: u8,
pub client_order_id: u64,
pub order_proportion_numerators: [u16; 12],
pub pool_type: u8,
pub stable_swap_amp_coef: u64,
pub coin_decimals: u8,
pub pc_decimals: u8,
pub last_ask_coin: u64,
pub last_ask_pc: u64,
pub last_bid_coin: u64,
pub last_bid_pc: u64,
pub version: u64,
pub placed_asks: [PlacedOrder; 12],
pub placed_bids: [PlacedOrder; 12],
pub pool_coin_amt: u64,
pub pool_pc_amt: u64,
pub mm_active: bool,
}

#[derive(Debug, Default, Clone, Copy, BorshDeserialize, BorshSerialize)]
pub struct PlacedOrder {
pub limit_price: u64,
pub coin_qty: u64,
pub max_native_pc_qty_including_fees: u64,
pub client_order_id: u64,
}

#[cfg(test)]
mod test {
use crate::atrix::pool::PoolAccount;

use super::{farm::*, ProtocolAccount};
use borsh::BorshDeserialize;
use solana_client::rpc_client;
use solana_program::{self, system_program};
use static_pubkey::static_pubkey;
#[test]
fn test_load_pool_account() {
let test_key = static_pubkey!("7yQzTZ9nMpsSePZxgxWpGMK62Zrkr9u7ngEsxyC9j7pG");
let rpc = rpc_client::RpcClient::new("https://ssc-dao.genesysgo.net".to_string());
let farm_account_data = rpc.get_account_data(&test_key).unwrap();
let pool_account = PoolAccount::deserialize(&mut &farm_account_data[..]).unwrap();
assert_eq!(
pool_account.coin_mint.to_string(),
"smbdJcLBrtKPhjrWCpDv5ABdJwz2vYo3mm6ojmePL3t".to_string()
);
}
#[test]
fn test_load_protocol_account() {
let test_key = static_pubkey!("3uTzTX5GBSfbW7eM9R9k95H7Txe32Qw3Z25MtyD2dzwC");
let rpc = rpc_client::RpcClient::new("https://ssc-dao.genesysgo.net".to_string());
let farm_account_data = rpc.get_account_data(&test_key).unwrap();
let protocol_account =
ProtocolAccount::deserialize(&mut &farm_account_data[..]).unwrap();
println!("{:#?}", protocol_account);
}
}
}
}
2 changes: 1 addition & 1 deletion accounts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod atrix;
pub mod atrix;
23 changes: 23 additions & 0 deletions atrix/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "so-defi-atrix"
version = "0.1.4"
edition = "2021"
authors = ["Tulip Protocol"]
description = "atrix protocol instructions, helpers, etc.."
keywords = ["solana", "configuration", "defi", "tulip-protocol"]
license = "MIT/Apache-2.0"
readme = "../README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
solana-program = "1.9"
borsh-derive = "0.9.1"
borsh = "0.9.1"
static-pubkey = "1.0.2"
so-defi-accounts = {path = "../accounts", version = "0.1.4"}
spl-token = "3.2.0"
sighashdb = "0.1.0"
[dev-dependencies]
solana-client = "1.9"
data-encoding = "2.3.2"
ring = "0.16.20"
Loading

0 comments on commit 3322b2d

Please sign in to comment.