mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
fix self cpi
This commit is contained in:
@@ -83,6 +83,7 @@ pub fn close(
|
||||
AccountMeta::new(vault_quote, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Close {}.to_bytes(),
|
||||
}
|
||||
@@ -100,13 +101,12 @@ pub fn log(signer: Pubkey, msg: &[u8]) -> Instruction {
|
||||
|
||||
pub fn program_log(
|
||||
block_id: u64,
|
||||
block_info: AccountInfo,
|
||||
// ore_program: AccountInfo,
|
||||
accounts: &[AccountInfo],
|
||||
msg: &[u8],
|
||||
) -> Result<(), ProgramError> {
|
||||
invoke_signed(
|
||||
&log(*block_info.key, msg),
|
||||
&[block_info],
|
||||
&log(*accounts[0].key, msg),
|
||||
accounts,
|
||||
&crate::ID,
|
||||
&[BLOCK, &block_id.to_le_bytes()],
|
||||
)
|
||||
@@ -129,6 +129,7 @@ pub fn mine(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
AccountMeta::new(sender, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
AccountMeta::new_readonly(sysvar::slot_hashes::ID, false),
|
||||
],
|
||||
data: Mine {
|
||||
@@ -166,6 +167,7 @@ pub fn commit(
|
||||
AccountMeta::new(sender_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Commit {
|
||||
amount: amount.to_le_bytes(),
|
||||
@@ -198,6 +200,7 @@ pub fn uncommit(signer: Pubkey, amount: u64, id: u64) -> Instruction {
|
||||
AccountMeta::new(recipient_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Uncommit {
|
||||
amount: amount.to_le_bytes(),
|
||||
@@ -222,6 +225,7 @@ pub fn deposit(signer: Pubkey, id: u64, amount: u64) -> Instruction {
|
||||
AccountMeta::new(stake_address, false),
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Deposit {
|
||||
amount: amount.to_le_bytes(),
|
||||
@@ -262,6 +266,7 @@ pub fn swap(
|
||||
AccountMeta::new_readonly(system_program::ID, false),
|
||||
AccountMeta::new_readonly(spl_token::ID, false),
|
||||
AccountMeta::new_readonly(spl_associated_token_account::ID, false),
|
||||
AccountMeta::new_readonly(crate::ID, false),
|
||||
],
|
||||
data: Swap {
|
||||
amount: amount.to_le_bytes(),
|
||||
|
||||
@@ -5,7 +5,7 @@ use steel::*;
|
||||
pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, config_info, collateral_info, commitment_info, fee_collector_info, market_info, miner_info, mint_base_info, mint_quote_info, opener_info, recipient_info, treasury_info, vault_base_info, vault_quote_info, system_program, token_program] =
|
||||
let [signer_info, block_info, config_info, collateral_info, commitment_info, fee_collector_info, market_info, miner_info, mint_base_info, mint_quote_info, opener_info, recipient_info, treasury_info, vault_base_info, vault_quote_info, system_program, token_program, ore_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -53,6 +53,7 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
.assert(|t| t.owner() == *market_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
|
||||
// Payout block reward.
|
||||
if block.reward.lode_reward > 0 && block.reward.lode_authority != Pubkey::default() {
|
||||
@@ -174,7 +175,7 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
|
||||
// Emit event.
|
||||
program_log(
|
||||
block.id,
|
||||
block_info.clone(),
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&CloseEvent {
|
||||
authority: *signer_info.key,
|
||||
id: block.id,
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, sender_info, system_program, token_program] =
|
||||
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, sender_info, system_program, token_program, ore_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -34,6 +34,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
.as_associated_token_account(signer_info.key, &mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
|
||||
// Normalize amount.
|
||||
let amount = sender.amount().min(amount);
|
||||
@@ -107,7 +108,7 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
|
||||
// Emit event.
|
||||
program_log(
|
||||
block.id,
|
||||
block_info.clone(),
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&CommitEvent {
|
||||
disc: OreEvent::Commit as u64,
|
||||
authority: *signer_info.key,
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, collateral_info, mint_ore_info, sender_info, stake_info, system_program, token_program] =
|
||||
let [signer_info, block_info, collateral_info, mint_ore_info, sender_info, stake_info, system_program, token_program, ore_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -31,6 +31,7 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu
|
||||
.assert(|t| t.amount() >= amount)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
|
||||
// Load stake account.
|
||||
let stake = if stake_info.data_is_empty() {
|
||||
@@ -69,7 +70,7 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu
|
||||
// Emit event.
|
||||
program_log(
|
||||
block.id,
|
||||
block_info.clone(),
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&DepositEvent {
|
||||
disc: OreEvent::Deposit as u64,
|
||||
authority: *signer_info.key,
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, authority_info, block_info, commitment_info, market_info, miner_info, mint_hash_info, mint_ore_info, permit_info, recipient_info, treasury_info, system_program, token_program, slot_hashes_sysvar] =
|
||||
let [signer_info, authority_info, block_info, commitment_info, market_info, miner_info, mint_hash_info, mint_ore_info, permit_info, recipient_info, treasury_info, system_program, token_program, slot_hashes_sysvar, ore_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -46,6 +46,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
slot_hashes_sysvar.is_sysvar(&sysvar::slot_hashes::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
|
||||
// Reduce permit amount.
|
||||
let amount = permit.commitment.min(amount);
|
||||
@@ -141,7 +142,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
// Emit event.
|
||||
program_log(
|
||||
block.id,
|
||||
block_info.clone(),
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&RewardEvent {
|
||||
disc: OreEvent::Reward as u64,
|
||||
amount: reward_amount,
|
||||
@@ -157,7 +158,7 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
// Emit event.
|
||||
program_log(
|
||||
block.id,
|
||||
block_info.clone(),
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&MineEvent {
|
||||
disc: OreEvent::Mine as u64,
|
||||
authority: miner.authority,
|
||||
|
||||
@@ -313,40 +313,22 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
&[BLOCK, &id.to_le_bytes()],
|
||||
)?;
|
||||
|
||||
// let msg = OpenEvent {
|
||||
// disc: OreEvent::Open as u64,
|
||||
// id,
|
||||
// start_slot,
|
||||
// signer: *signer_info.key,
|
||||
// reward_config: block.reward,
|
||||
// liquidity_base: market.base.liquidity() as u64,
|
||||
// liquidity_quote: market.quote.liquidity() as u64,
|
||||
// ts: clock.unix_timestamp,
|
||||
// }
|
||||
// .to_bytes();
|
||||
|
||||
invoke_signed(
|
||||
&ore_api::sdk::log(
|
||||
*block_info.key,
|
||||
&OpenEvent {
|
||||
disc: OreEvent::Open as u64,
|
||||
id,
|
||||
start_slot,
|
||||
signer: *signer_info.key,
|
||||
reward_config: block.reward,
|
||||
liquidity_base: market.base.liquidity() as u64,
|
||||
liquidity_quote: market.quote.liquidity() as u64,
|
||||
ts: clock.unix_timestamp,
|
||||
}
|
||||
.to_bytes(),
|
||||
),
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&ore_api::ID,
|
||||
&[BLOCK, &id.to_le_bytes()],
|
||||
)?;
|
||||
|
||||
// Emit event.
|
||||
// program_log(id, block_info.clone(), &msg)?;
|
||||
program_log(
|
||||
id,
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&OpenEvent {
|
||||
disc: OreEvent::Open as u64,
|
||||
id,
|
||||
start_slot,
|
||||
signer: *signer_info.key,
|
||||
reward_config: block.reward,
|
||||
liquidity_base: market.base.liquidity() as u64,
|
||||
liquidity_quote: market.quote.liquidity() as u64,
|
||||
ts: clock.unix_timestamp,
|
||||
}
|
||||
.to_bytes(),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -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, mint_base_info, mint_quote_info, stake_info, tokens_base_info, tokens_quote_info, vault_base_info, vault_quote_info, system_program, token_program, associated_token_program] =
|
||||
let [signer_info, block_info, market_info, mint_base_info, mint_quote_info, stake_info, tokens_base_info, tokens_quote_info, vault_base_info, vault_quote_info, system_program, token_program, associated_token_program, ore_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -46,6 +46,7 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
associated_token_program.is_program(&spl_associated_token_account::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
|
||||
// Load token acccounts.
|
||||
if tokens_base_info.data_is_empty() {
|
||||
@@ -137,7 +138,11 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
market.check_vaults(&vault_base, &vault_quote)?;
|
||||
|
||||
// Emit event.
|
||||
program_log(block.id, block_info.clone(), &swap_event.to_bytes())?;
|
||||
program_log(
|
||||
block.id,
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&swap_event.to_bytes(),
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, recipient_info, system_program, token_program] =
|
||||
let [signer_info, block_info, commitment_info, market_info, miner_info, mint_info, permit_info, recipient_info, system_program, token_program, ore_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -40,6 +40,7 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
.as_associated_token_account(signer_info.key, &mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
|
||||
// Normalize amount.
|
||||
let amount = permit.commitment.min(amount);
|
||||
@@ -67,7 +68,7 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
// Emit event.
|
||||
program_log(
|
||||
block.id,
|
||||
block_info.clone(),
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&UncommitEvent {
|
||||
disc: OreEvent::Uncommit as u64,
|
||||
authority: *signer_info.key,
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, block_info, collateral_info, mint_ore_info, recipient_info, stake_info, system_program, token_program] =
|
||||
let [signer_info, block_info, collateral_info, mint_ore_info, recipient_info, stake_info, system_program, token_program, ore_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -31,6 +31,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
.assert(|t| t.owner() == *block_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
ore_program.is_program(&ore_api::ID)?;
|
||||
|
||||
// Check timestamp. Collateral can only be withdrawn after the block has started mining
|
||||
let start_slot = stake.block_id * 1500;
|
||||
@@ -59,7 +60,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
// Emit event.
|
||||
program_log(
|
||||
stake.block_id,
|
||||
block_info.clone(),
|
||||
&[block_info.clone(), ore_program.clone()],
|
||||
&WithdrawEvent {
|
||||
disc: OreEvent::Withdraw as u64,
|
||||
authority: *signer_info.key,
|
||||
|
||||
Reference in New Issue
Block a user