diff --git a/api/src/event.rs b/api/src/event.rs index 7f0cfb4..a8be86d 100644 --- a/api/src/event.rs +++ b/api/src/event.rs @@ -195,7 +195,7 @@ pub struct DepositEvent { pub amount: u64, /// The total amount of ORE this user has deposited as collateral. - pub capacity: u64, + pub collateral: u64, /// The timestamp of the event. pub ts: i64, @@ -217,7 +217,7 @@ pub struct WithdrawEvent { pub amount: u64, /// The total amount of ORE this user has deposited as collateral. - pub capacity: u64, + pub collateral: u64, /// The timestamp of the event. pub ts: i64, diff --git a/api/src/state/block.rs b/api/src/state/block.rs index edc0b32..78cf38e 100644 --- a/api/src/state/block.rs +++ b/api/src/state/block.rs @@ -26,7 +26,10 @@ pub struct Block { pub start_slot: u64, /// The total number of hashes submitted to the block. - pub total_hashes: u64, + pub total_committed: u64, + + /// The total number of hashes deployed to the block. + pub total_deployed: u64, /// The total amount of rewards paid out to miners. pub total_rewards: u64, diff --git a/api/src/state/miner.rs b/api/src/state/miner.rs index e6558eb..eb52ed7 100644 --- a/api/src/state/miner.rs +++ b/api/src/state/miner.rs @@ -16,10 +16,13 @@ pub struct Miner { /// The hash of the last block this miner mined in. pub hash: [u8; 32], - /// The total number of hashes this miner has submitted. - pub total_hashes: u64, + /// The total number of hashes this miner has committed to the block. + pub total_committed: u64, - /// The amount of ORE this miner has mined. + /// The total number of hashes this miner has deployed to the block. + pub total_deployed: u64, + + /// The total amount of ORE this miner has mined across all blocks. pub total_rewards: u64, } diff --git a/api/src/state/permit.rs b/api/src/state/permit.rs index 6ba9f09..a51bcc6 100644 --- a/api/src/state/permit.rs +++ b/api/src/state/permit.rs @@ -7,15 +7,15 @@ use super::OreAccount; #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)] pub struct Permit { - /// The amount of hash tokens this miner has committed to the block. - pub amount: u64, - /// The authority of the miner account. pub authority: Pubkey, /// The ID of the block this permit is for. pub block_id: u64, + /// The amount of hash tokens this miner has committed to the block. + pub commitment: u64, + /// The executor of the permit. pub executor: Pubkey, diff --git a/api/src/state/stake.rs b/api/src/state/stake.rs index 5d14cb2..c593cd3 100644 --- a/api/src/state/stake.rs +++ b/api/src/state/stake.rs @@ -13,11 +13,11 @@ pub struct Stake { /// The ID of the block this collateral is associated with. pub block_id: u64, - /// The amount of ORE this miner can commit to the block. - pub capacity: u64, + /// The amount of ORE this miner has deposited as collateral for trading. + pub collateral: u64, - /// The amount of ORE this miner has committed to the block. - pub utilization: u64, + /// The amount of ORE this miner has spent on hashpower in this market. + pub spend: u64, } impl Stake { diff --git a/cli/src/main.rs b/cli/src/main.rs index e2e6fa5..c5dcb06 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -148,7 +148,9 @@ fn print_block(block: Block, clock: &Clock) { println!(" Start slot: {:?}", block.start_slot); println!(" Starts in: {:?} sec", elapsed_time as u64); println!(" Slot hash: {:?}", block.slot_hash); - println!(" Total hashes: {:?}", block.total_hashes); + println!(" Total hashes: {:?}", block.total_committed); + println!(" Total deployed: {:?}", block.total_deployed); + println!(" Total rewards: {:?}", block.total_rewards); println!(" Lode reward: {:?}", block.reward.lode_reward); println!(" Lode authority: {:?}", block.reward.lode_authority); println!(" Lode hash: {:?}", block.reward.lode_hash); diff --git a/program/src/commit.rs b/program/src/commit.rs index b8f528d..c705a27 100644 --- a/program/src/commit.rs +++ b/program/src/commit.rs @@ -18,8 +18,8 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul }; signer_info.is_signer()?; let block = block_info - .as_account::(&ore_api::ID)? - .assert(|b| clock.slot < b.start_slot)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| clock.slot < b.start_slot)?; commitment_info.as_associated_token_account(block_info.key, mint_info.key)?; let market = market_info .as_account::(&ore_api::ID)? @@ -35,7 +35,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul let amount = sender.amount().min(amount); // Load miner account. - let _miner = if miner_info.data_is_empty() { + let miner = if miner_info.data_is_empty() { create_program_account::( miner_info, system_program, @@ -47,7 +47,8 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul miner.authority = *signer_info.key; miner.block_id = 0; miner.hash = [0; 32]; - miner.total_hashes = 0; + miner.total_committed = 0; + miner.total_deployed = 0; miner.total_rewards = 0; miner } else { @@ -66,9 +67,12 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul &[PERMIT, &signer_info.key.to_bytes(), &block.id.to_le_bytes()], )?; let permit = permit_info.as_account_mut::(&ore_api::ID)?; - permit.amount = 0; permit.authority = *signer_info.key; permit.block_id = block.id; + permit.commitment = 0; + permit.executor = Pubkey::default(); + permit.fee = 0; + permit.seed = [0; 32]; permit } else { permit_info @@ -92,7 +96,9 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul )?; // Update block. - permit.amount += amount; + permit.commitment += amount; + miner.total_committed += amount; + block.total_committed += amount; // Emit event. CommitEvent { @@ -100,7 +106,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul authority: *signer_info.key, block_id: block.id, amount, - commitment: permit.amount, + commitment: permit.commitment, ts: clock.unix_timestamp, } .log_return(); diff --git a/program/src/deposit.rs b/program/src/deposit.rs index 568a538..f9cd4c9 100644 --- a/program/src/deposit.rs +++ b/program/src/deposit.rs @@ -41,8 +41,8 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu let stake = stake_info.as_account_mut::(&ore_api::ID)?; stake.authority = *signer_info.key; stake.block_id = block.id; - stake.capacity = 0; - stake.utilization = 0; + stake.collateral = 0; + stake.spend = 0; stake } else { stake_info @@ -52,7 +52,7 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu }; // Update stake state. - stake.capacity += amount; + stake.collateral += amount; // Transfer collateral. transfer( @@ -69,7 +69,7 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu authority: *signer_info.key, block_id: block.id, amount, - capacity: stake.capacity, + collateral: stake.collateral, ts: clock.unix_timestamp, } .log_return(); diff --git a/program/src/mine.rs b/program/src/mine.rs index dfbb659..1a5551e 100644 --- a/program/src/mine.rs +++ b/program/src/mine.rs @@ -50,8 +50,8 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?; // Reduce permit amount. - let amount = permit.amount.min(amount); - permit.amount -= amount; + let amount = permit.commitment.min(amount); + permit.commitment -= amount; // Pay executor fee. if permit.fee > 0 { @@ -59,7 +59,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult } // Close permit account, if empty. - if permit.amount == 0 { + if permit.commitment == 0 { permit_info.close(authority_info)?; } @@ -100,8 +100,8 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult let mut nugget_reward = 0; for _ in 0..amount { // Update stats - block.total_hashes += 1; - miner.total_hashes += 1; + block.total_deployed += 1; + miner.total_deployed += 1; // Generate hash. miner.hash = hash(miner.hash.as_ref()); diff --git a/program/src/open.rs b/program/src/open.rs index c7a6f90..ce3ae61 100644 --- a/program/src/open.rs +++ b/program/src/open.rs @@ -78,7 +78,9 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult }; block.slot_hash = [0; 32]; block.start_slot = start_slot; - block.total_hashes = 0; + block.total_committed = 0; + block.total_deployed = 0; + block.total_rewards = 0; // Select reward strategy. let noise_seed = block.id.to_le_bytes(); diff --git a/program/src/swap.rs b/program/src/swap.rs index df6de56..4d781d2 100644 --- a/program/src/swap.rs +++ b/program/src/swap.rs @@ -105,16 +105,16 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult match direction { SwapDirection::Buy => { // TODO Fail if out_amount is zero - stake.utilization += in_amount; + stake.spend += in_amount; } SwapDirection::Sell => { - stake.utilization = stake.utilization.saturating_sub(out_amount); + stake.spend = stake.spend.saturating_sub(out_amount); } } // Assert utilization is not greater than capacity. - if stake.utilization > stake.capacity { - panic!("utilization is greater than capacity"); + if stake.spend > stake.collateral { + panic!("spend is greater than collateral"); } // Transfer tokens. diff --git a/program/src/uncommit.rs b/program/src/uncommit.rs index 0e981b5..5cdd232 100644 --- a/program/src/uncommit.rs +++ b/program/src/uncommit.rs @@ -16,17 +16,17 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes }; signer_info.is_signer()?; let block = block_info - .as_account::(&ore_api::ID)? - .assert(|b| clock.slot < b.start_slot)?; + .as_account_mut::(&ore_api::ID)? + .assert_mut(|b| clock.slot < b.start_slot)?; commitment_info .is_writable()? .as_associated_token_account(block_info.key, mint_info.key)?; let market = market_info .as_account::(&ore_api::ID)? .assert(|m| m.id == block.id)?; - miner_info - .as_account::(&ore_api::ID)? - .assert(|m| m.authority == *signer_info.key)?; + let miner = miner_info + .as_account_mut::(&ore_api::ID)? + .assert_mut(|m| m.authority == *signer_info.key)?; mint_info.has_address(&market.base.mint)?.as_mint()?; let permit = permit_info .as_account_mut::(&ore_api::ID)? @@ -39,7 +39,7 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes token_program.is_program(&spl_token::ID)?; // Normalize amount. - let amount = permit.amount.min(amount); + let amount = permit.commitment.min(amount); // Transfer hash tokens. transfer_signed( @@ -52,10 +52,12 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes )?; // Update block. - permit.amount -= amount; + permit.commitment -= amount; + miner.total_committed -= amount; + block.total_committed -= amount; // Close permit account, if empty. - if permit.amount == 0 { + if permit.commitment == 0 { permit_info.close(signer_info)?; } @@ -64,7 +66,7 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes disc: OreEvent::Uncommit as u64, authority: *signer_info.key, block_id: block.id, - commitment: permit.amount, + commitment: permit.commitment, amount, ts: clock.unix_timestamp, } diff --git a/program/src/withdraw.rs b/program/src/withdraw.rs index a51cf75..a2730e3 100644 --- a/program/src/withdraw.rs +++ b/program/src/withdraw.rs @@ -36,7 +36,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes } // Update stake state. - stake.capacity -= amount; + stake.collateral -= amount; // Transfer collateral. transfer_signed( @@ -49,7 +49,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes )?; // Close stake account, if empty. - if stake.capacity == 0 { + if stake.collateral == 0 { stake_info.close(signer_info)?; } @@ -59,7 +59,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes authority: *signer_info.key, block_id: stake.block_id, amount, - capacity: stake.capacity, + collateral: stake.collateral, ts: clock.unix_timestamp, } .log_return();