Skip to content

Commit

Permalink
fix(roles): updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ogmedia committed Oct 20, 2022
1 parent 1264d6a commit dfbac0f
Show file tree
Hide file tree
Showing 8 changed files with 4,684 additions and 38 deletions.
1,589 changes: 1,589 additions & 0 deletions idl/mesh.ts

Large diffs are not rendered by default.

633 changes: 633 additions & 0 deletions idl/program_manager.ts

Large diffs are not rendered by default.

605 changes: 605 additions & 0 deletions idl/roles.ts

Large diffs are not rendered by default.

1,435 changes: 1,435 additions & 0 deletions idl/squads_mpl.ts

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions idl/txmeta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export type Txmeta = {
"version": "0.1.0",
"name": "txmeta",
"instructions": [
{
"name": "trackMeta",
"accounts": [
{
"name": "member",
"isMut": true,
"isSigner": true
}
],
"args": [
{
"name": "meta",
"type": "string"
}
]
}
]
};

export const IDL: Txmeta = {
"version": "0.1.0",
"name": "txmeta",
"instructions": [
{
"name": "trackMeta",
"accounts": [
{
"name": "member",
"isMut": true,
"isSigner": true
}
],
"args": [
{
"name": "meta",
"type": "string"
}
]
}
]
};
141 changes: 118 additions & 23 deletions programs/roles/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
use anchor_lang::prelude::*;

use squads_mpl::state::{Ms, MsTransaction, MsInstruction, IncomingInstruction};
use squads_mpl::cpi::accounts::{
CreateTransaction,
AddInstruction,
ActivateTransaction,
VoteTransaction,
ExecuteTransaction
};
use squads_mpl::errors::MsError;
use squads_mpl::program::SquadsMpl;

use state::roles::{User,Role};
use squads_mpl::cpi::{
accounts::{
CreateTransaction,
AddInstruction,
ActivateTransaction,
VoteTransaction,
ExecuteTransaction,
}
};
use state::roles::*;
pub use squads_mpl::state::ms::{Ms, MsInstruction, MsTransaction};
pub mod state;

declare_id!("8hG7uP3qM5NKSpNnNVsiRP2YoYLA91kcwZb8CZ4U7fV2");

#[program]
pub mod roles {
use squads_mpl::state::IncomingInstruction;

use super::*;

pub fn add_user(ctx: Context<NewUser>, origin_key: Pubkey, role: Role) -> Result<()> {
Expand All @@ -36,7 +35,7 @@ pub mod roles {
}

pub fn add_proxy(ctx: Context<AddProxy>, incoming_instruction: IncomingInstruction) -> Result<()> {
squads_mpl::cpi::add_instruction(ctx.accounts.add_instruction_ctx(), incoming_instruction)
squads_mpl::cpi::add_instruction(ctx.accounts.add_instruction_ctx(), incoming_instruction.into())
}

pub fn activate_proxy(ctx: Context<ActivateProxy>) -> Result<()> {
Expand Down Expand Up @@ -64,19 +63,35 @@ pub struct NewUser<'info>{
], bump
)]
pub user: Box<Account<'info, User>>,

#[account(
seeds = [
b"squad",
multisig.create_key.as_ref(),
b"multisig"
],
bump = multisig.bump,
seeds::program = squads_mpl::ID,
)]
pub multisig: Box<Account<'info, Ms>>,

#[account(mut)]
#[account(
mut,
constraint = matches!(multisig.is_member(payer.key()), Some(..)) @MsError::KeyNotInMultisig,
)]
pub payer: Signer<'info>,
pub rent: Sysvar<'info, Rent>,
pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct CreateProxy<'info> {
#[account(mut)]
#[account(
mut,
owner = squads_mpl::ID,
)]
pub multisig: Account<'info, Ms>,

#[account(mut)]
pub transaction: Account<'info, MsTransaction>,

#[account(
Expand All @@ -92,7 +107,7 @@ pub struct CreateProxy<'info> {

#[account(
mut,
constraint = user.origin_key == creator.key()
constraint = user.origin_key == creator.key() @MsError::InvalidInstructionAccount
)]
pub creator: Signer<'info>,
pub system_program: Program<'info, System>,
Expand All @@ -114,12 +129,43 @@ impl<'info> CreateProxy<'info> {

#[derive(Accounts)]
pub struct AddProxy<'info> {
#[account(
seeds = [
b"squad",
multisig.create_key.as_ref(),
b"multisig"
],
bump = multisig.bump,
seeds::program = squads_mpl::ID,
)]
pub multisig: Account<'info, Ms>,

#[account(mut)]
#[account(
mut,
owner = squads_mpl::ID,
seeds = [
b"squad",
multisig.key().as_ref(),
&transaction.transaction_index.to_le_bytes(),
b"transaction"
],
bump = transaction.bump,
seeds::program = squads_mpl::ID,
)]
pub transaction: Account<'info, MsTransaction>,

#[account(mut)]
#[account(
mut,
owner = squads_mpl::ID,
seeds = [
b"squad",
transaction.key().as_ref(),
&instruction.instruction_index.to_le_bytes(),
b"instruction"
],
bump = instruction.bump,
seeds::program = squads_mpl::ID,
)]
pub instruction: Account<'info, MsInstruction>,

#[account(
Expand Down Expand Up @@ -158,9 +204,29 @@ impl<'info> AddProxy<'info> {

#[derive(Accounts)]
pub struct ActivateProxy<'info> {
#[account(
seeds = [
b"squad",
multisig.create_key.as_ref(),
b"multisig"
],
bump = multisig.bump,
seeds::program = squads_mpl::ID,
)]
pub multisig: Account<'info, Ms>,

#[account(mut)]
#[account(
mut,
owner = squads_mpl::ID,
seeds = [
b"squad",
multisig.key().as_ref(),
&transaction.transaction_index.to_le_bytes(),
b"transaction"
],
bump = transaction.bump,
seeds::program = squads_mpl::ID,
)]
pub transaction: Account<'info, MsTransaction>,

#[account(
Expand Down Expand Up @@ -199,9 +265,29 @@ impl<'info> ActivateProxy<'info> {

#[derive(Accounts)]
pub struct VoteProxy<'info> {
#[account(
seeds = [
b"squad",
multisig.create_key.as_ref(),
b"multisig"
],
bump = multisig.bump,
seeds::program = squads_mpl::ID,
)]
pub multisig: Account<'info, Ms>,

#[account(mut)]
#[account(
mut,
owner = squads_mpl::ID,
seeds = [
b"squad",
multisig.key().as_ref(),
&transaction.transaction_index.to_le_bytes(),
b"transaction"
],
bump = transaction.bump,
seeds::program = squads_mpl::ID,
)]
pub transaction: Account<'info, MsTransaction>,

#[account(
Expand Down Expand Up @@ -240,7 +326,16 @@ impl<'info> VoteProxy<'info> {

#[derive(Accounts)]
pub struct ExecuteTxProxy<'info> {
#[account(mut)]
#[account(
mut,
seeds = [
b"squad",
multisig.create_key.as_ref(),
b"multisig"
],
bump = multisig.bump,
seeds::program = squads_mpl::ID,
)]
pub multisig: Box<Account<'info, Ms>>,

#[account(mut)]
Expand Down
39 changes: 35 additions & 4 deletions programs/roles/src/state/roles.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::convert::TryInto;

use anchor_lang::{prelude::*, solana_program::instruction::Instruction};
use anchor_lang::solana_program::borsh::get_instance_packed_len;
use anchor_lang::{prelude::*};
// use squads_mpl::state::IncomingInstruction;

#[account]
pub struct User {
Expand Down Expand Up @@ -33,4 +31,37 @@ pub enum Role {

impl Role {
pub const MAXIMUM_SIZE: usize = 1 + 18;
}

#[derive(AnchorSerialize,AnchorDeserialize, Copy, Clone)]
pub struct MsAccountMeta {
pub pubkey: Pubkey,
pub is_signer: bool,
pub is_writable: bool
}

// serialization schema for incoming instructions to be attached to transaction
#[derive(AnchorSerialize,AnchorDeserialize, Clone)]
pub struct IncomingInstruction {
pub program_id: Pubkey,
pub keys: Vec<MsAccountMeta>,
pub data: Vec<u8>
}

impl From<IncomingInstruction> for squads_mpl::state::IncomingInstruction{
fn from(incoming_instruction: IncomingInstruction) -> Self {
let mut keys = vec![];
for key in incoming_instruction.keys {
keys.push(squads_mpl::state::MsAccountMeta{
pubkey: key.pubkey,
is_signer: key.is_signer,
is_writable: key.is_writable
})
}
squads_mpl::state::IncomingInstruction{
program_id: incoming_instruction.program_id,
keys,
data: incoming_instruction.data
}
}
}
Loading

0 comments on commit dfbac0f

Please sign in to comment.