mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-08 15:11:42 +00:00
permit
This commit is contained in:
@@ -46,9 +46,9 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
|||||||
&[PERMIT, &signer_info.key.to_bytes(), &block.id.to_le_bytes()],
|
&[PERMIT, &signer_info.key.to_bytes(), &block.id.to_le_bytes()],
|
||||||
)?;
|
)?;
|
||||||
let permit = permit_info.as_account_mut::<Permit>(&ore_api::ID)?;
|
let permit = permit_info.as_account_mut::<Permit>(&ore_api::ID)?;
|
||||||
|
permit.amount = 0;
|
||||||
permit.authority = *signer_info.key;
|
permit.authority = *signer_info.key;
|
||||||
permit.block_id = block.id;
|
permit.block_id = block.id;
|
||||||
permit.amount = 0;
|
|
||||||
permit
|
permit
|
||||||
} else {
|
} else {
|
||||||
permit_info
|
permit_info
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ pub fn process_decommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
|||||||
// Update block.
|
// Update block.
|
||||||
permit.amount -= amount;
|
permit.amount -= amount;
|
||||||
|
|
||||||
// Close permit, if empty.
|
// Close permit account, if empty.
|
||||||
if permit.amount == 0 {
|
if permit.amount == 0 {
|
||||||
permit_info.close(signer_info)?;
|
permit_info.close(signer_info)?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
|||||||
|
|
||||||
// Load accounts.
|
// Load accounts.
|
||||||
let clock = Clock::get()?;
|
let clock = Clock::get()?;
|
||||||
let [signer_info, block_info, market_info, miner_info, mint_hash_info, mint_ore_info, permit_info, recipient_info, sender_info, treasury_info, system_program, token_program, slot_hashes_sysvar] =
|
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_hash_info, mint_ore_info, permit_info, recipient_info, sender_info, treasury_info, system_program, token_program, slot_hashes_sysvar] =
|
||||||
accounts
|
accounts
|
||||||
else {
|
else {
|
||||||
return Err(ProgramError::NotEnoughAccountKeys);
|
return Err(ProgramError::NotEnoughAccountKeys);
|
||||||
@@ -21,14 +21,18 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
|||||||
.as_account_mut::<Block>(&ore_api::ID)?
|
.as_account_mut::<Block>(&ore_api::ID)?
|
||||||
.assert_mut(|b| clock.slot >= b.start_slot)?
|
.assert_mut(|b| clock.slot >= b.start_slot)?
|
||||||
.assert_mut(|b| clock.slot < b.start_slot + 1500)?;
|
.assert_mut(|b| clock.slot < b.start_slot + 1500)?;
|
||||||
|
commitment_info
|
||||||
|
.is_writable()?
|
||||||
|
.as_associated_token_account(block_info.key, mint_hash_info.key)?;
|
||||||
let market = market_info
|
let market = market_info
|
||||||
.as_account::<Market>(&ore_api::ID)?
|
.as_account::<Market>(&ore_api::ID)?
|
||||||
.assert(|m| m.id == block.id)?;
|
.assert(|m| m.id == block.id)?;
|
||||||
mint_hash_info.has_address(&market.base.mint)?.as_mint()?;
|
mint_hash_info.has_address(&market.base.mint)?.as_mint()?;
|
||||||
mint_ore_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
mint_ore_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||||
permit_info
|
let permit = permit_info
|
||||||
.as_account::<Permit>(&ore_api::ID)?
|
.as_account_mut::<Permit>(&ore_api::ID)?
|
||||||
.assert(|p| p.authority == *signer_info.key)?;
|
.assert_mut(|p| p.authority == *signer_info.key)?
|
||||||
|
.assert_mut(|p| p.amount >= amount)?;
|
||||||
recipient_info
|
recipient_info
|
||||||
.is_writable()?
|
.is_writable()?
|
||||||
.as_associated_token_account(signer_info.key, &MINT_ADDRESS)?;
|
.as_associated_token_account(signer_info.key, &MINT_ADDRESS)?;
|
||||||
@@ -63,13 +67,22 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
|||||||
.assert_mut(|m| m.authority == *signer_info.key)?
|
.assert_mut(|m| m.authority == *signer_info.key)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Reduce permit amount.
|
||||||
|
permit.amount -= amount;
|
||||||
|
|
||||||
|
// Close permit account, if empty.
|
||||||
|
if permit.amount == 0 {
|
||||||
|
permit_info.close(signer_info)?;
|
||||||
|
}
|
||||||
|
|
||||||
// Burn hash tokens.
|
// Burn hash tokens.
|
||||||
burn(
|
burn_signed(
|
||||||
sender_info,
|
commitment_info,
|
||||||
mint_hash_info,
|
mint_hash_info,
|
||||||
signer_info,
|
block_info,
|
||||||
token_program,
|
token_program,
|
||||||
amount,
|
amount,
|
||||||
|
&[BLOCK, &block.id.to_le_bytes()],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Set block slot hash.
|
// Set block slot hash.
|
||||||
|
|||||||
Reference in New Issue
Block a user