Skip to content

Commit

Permalink
sync with phase 1
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Jan 9, 2025
1 parent e82fd0f commit ca0507d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
31 changes: 30 additions & 1 deletion api/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use steel::*;
use crate::{
error::ApiError,
instruction::*,
state::{member_pda, pool_pda, pool_proof_pda, share_pda},
state::{member_pda, migration_pda, pool_pda, pool_proof_pda, share_pda},
};

/// Builds a launch instruction.
Expand Down Expand Up @@ -276,6 +276,35 @@ pub fn open_stake(signer: Pubkey, mint: Pubkey) -> Instruction {
}
}

pub fn migrate_pool(signer: Pubkey, pool: Pubkey) -> Instruction {
let (migration_address, _) = migration_pda(pool);
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(pool, false),
AccountMeta::new(migration_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: MigratePool {}.to_bytes(),
}
}

pub fn migrate_member_balance(signer: Pubkey, pool: Pubkey, member: Pubkey) -> Instruction {
let (migration_address, _) = migration_pda(pool);
Instruction {
program_id: crate::ID,
accounts: vec![
AccountMeta::new(signer, true),
AccountMeta::new(pool, false),
AccountMeta::new_readonly(member, false),
AccountMeta::new(migration_address, false),
AccountMeta::new_readonly(system_program::ID, false),
],
data: MigrateMemberBalance {}.to_bytes(),
}
}

fn url_to_bytes(input: &str) -> Result<[u8; 128], ApiError> {
let bytes = input.as_bytes();
let len = bytes.len();
Expand Down
7 changes: 2 additions & 5 deletions api/src/state/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub struct Pool {
/// Foreign key to the ORE proof account.
pub last_hash_at: i64,

/// The reward from the most recent solution.
pub reward: u64,
/// The total claimable rewards in the pool.
pub total_rewards: u64,

/// The total number of hashes this pool has submitted.
pub total_submissions: u64,
Expand All @@ -32,9 +32,6 @@ pub struct Pool {

// The total number of members in this pool at the last submission.
pub last_total_members: u64,

// The total claimable rewards in the pool.
pub claimable_rewards: u64,
}

account!(AccountDiscriminator, Pool);
9 changes: 5 additions & 4 deletions program/src/migrate_member_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use steel::*;

pub fn process_migrate_member_balance(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts.
let [signer_info, pool_info, member_info, migration_info] = accounts else {
let [signer_info, pool_info, member_info, migration_info, system_program] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.is_signer()?.has_address(&ADMIN_ADDRESS)?;
Expand All @@ -15,9 +15,10 @@ pub fn process_migrate_member_balance(accounts: &[AccountInfo<'_>], _data: &[u8]
.as_account_mut::<Migration>(&ore_pool_api::ID)?
.assert_mut(|m| m.pool == *pool_info.key)?
.assert_mut(|m| m.members_migrated == member.id)?;
system_program.is_program(&system_program::ID)?;

// Increment pool claimable balance
pool.claimable_rewards += member.balance;
// Increment pool total rewards counter
pool.total_rewards += member.balance;

// Increment migrated balance
migration.members_migrated += 1;
Expand All @@ -28,4 +29,4 @@ pub fn process_migrate_member_balance(accounts: &[AccountInfo<'_>], _data: &[u8]
}

Ok(())
}
}

0 comments on commit ca0507d

Please sign in to comment.