mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
remove staking
This commit is contained in:
@@ -21,8 +21,8 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
market_hash_info.as_associated_token_account(market_info.key, mint_hash_info.key)?;
|
||||
let market_ore =
|
||||
market_ore_info.as_associated_token_account(market_info.key, mint_ore_info.key)?;
|
||||
mint_hash_info.has_address(&market.base.mint)?.as_mint();
|
||||
mint_ore_info.has_address(&market.quote.mint)?.as_mint();
|
||||
mint_hash_info.has_address(&market.base.mint)?.as_mint()?;
|
||||
mint_ore_info.has_address(&market.quote.mint)?.as_mint()?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Deposits stake.
|
||||
pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = Deposit::try_from_bytes(data)?;
|
||||
let amount = u64::from_le_bytes(args.amount);
|
||||
|
||||
// Load accounts.
|
||||
let [signer_info, miner_info, sender_info, treasury_info, treasury_tokens_info, token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let miner = miner_info
|
||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.authority == *signer_info.key)?;
|
||||
sender_info.as_associated_token_account(&signer_info.key, &MINT_ADDRESS)?;
|
||||
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
treasury_tokens_info.as_associated_token_account(&treasury_info.key, &MINT_ADDRESS)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
|
||||
// Update account state.
|
||||
miner.stake += amount;
|
||||
treasury.total_stake += amount;
|
||||
|
||||
// Execute transfer.
|
||||
transfer(
|
||||
signer_info,
|
||||
sender_info,
|
||||
treasury_tokens_info,
|
||||
token_program,
|
||||
amount,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Free up capacity.
|
||||
pub fn process_free(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, miner_info, receipt_info] = accounts else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let miner = miner_info
|
||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.authority == *signer_info.key)?;
|
||||
let receipt = receipt_info
|
||||
.as_account_mut::<Receipt>(&ore_api::ID)?
|
||||
.assert_mut(|r| r.authority == *signer_info.key)?;
|
||||
|
||||
// Asset that block has ended.
|
||||
let start_slot = 1500 * receipt.block_id;
|
||||
let end_slot = start_slot + 1500;
|
||||
assert!(clock.slot >= end_slot, "Block has not yet closed.");
|
||||
|
||||
// Free up miner capacity.
|
||||
miner.deployed -= receipt.amount;
|
||||
|
||||
// Close the receipt.
|
||||
receipt_info.close(signer_info)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,18 +1,12 @@
|
||||
mod close;
|
||||
mod deposit;
|
||||
mod free;
|
||||
mod mine;
|
||||
mod open;
|
||||
mod swap;
|
||||
mod withdraw;
|
||||
|
||||
use close::*;
|
||||
use deposit::*;
|
||||
use free::*;
|
||||
use mine::*;
|
||||
use open::*;
|
||||
use swap::*;
|
||||
use withdraw::*;
|
||||
|
||||
use ore_api::instruction::*;
|
||||
use steel::*;
|
||||
@@ -25,17 +19,9 @@ pub fn process_instruction(
|
||||
let (ix, data) = parse_instruction(&ore_api::ID, program_id, data)?;
|
||||
|
||||
match ix {
|
||||
// Mine
|
||||
OreInstruction::Open => process_open(accounts, data)?,
|
||||
OreInstruction::Close => process_close(accounts, data)?,
|
||||
OreInstruction::Mine => process_mine(accounts, data)?,
|
||||
|
||||
// Stake
|
||||
OreInstruction::Deposit => process_deposit(accounts, data)?,
|
||||
OreInstruction::Withdraw => process_withdraw(accounts, data)?,
|
||||
|
||||
// Trade
|
||||
OreInstruction::Free => process_free(accounts, data)?,
|
||||
OreInstruction::Swap => process_swap(accounts, data)?,
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, market_info, miner_info, mint_base_info, mint_quote_info, receipt_info, tokens_base_info, tokens_quote_info, vault_base_info, vault_quote_info, system_program, token_program] =
|
||||
let [signer_info, block_info, market_info, miner_info, mint_base_info, mint_quote_info, tokens_base_info, tokens_quote_info, vault_base_info, vault_quote_info, system_program, token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -51,8 +51,6 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
|
||||
// TODO Buy hash tokens
|
||||
|
||||
// Update market state.
|
||||
let swap_result = market.swap(amount, direction, precision, clock)?;
|
||||
swap_result.log_return();
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
use ore_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Withdraws stake.
|
||||
pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = Withdraw::try_from_bytes(data)?;
|
||||
let amount = u64::from_le_bytes(args.amount);
|
||||
|
||||
// Load accounts.
|
||||
let [signer_info, miner_info, recipient_info, treasury_info, treasury_tokens_info, token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
};
|
||||
signer_info.is_signer()?;
|
||||
let miner = miner_info
|
||||
.as_account_mut::<Miner>(&ore_api::ID)?
|
||||
.assert_mut(|m| m.authority == *signer_info.key)?;
|
||||
recipient_info.as_associated_token_account(&signer_info.key, &MINT_ADDRESS)?;
|
||||
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
treasury_tokens_info.as_associated_token_account(&treasury_info.key, &MINT_ADDRESS)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
|
||||
// Update account state.
|
||||
miner.stake -= amount;
|
||||
treasury.total_stake -= amount;
|
||||
|
||||
// Asset miner has enough stake to cover the withdrawal.
|
||||
assert!(
|
||||
miner.stake >= miner.deployed,
|
||||
"Withdrawal cannot reduce capacity below deployment levels."
|
||||
);
|
||||
|
||||
// Execute transfer.
|
||||
transfer_signed(
|
||||
signer_info,
|
||||
treasury_tokens_info,
|
||||
recipient_info,
|
||||
token_program,
|
||||
amount,
|
||||
&[TREASURY],
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user