mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-15 23:16:46 +00:00
swap
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use ore_api::prelude::*;
|
||||
use solana_program::program_pack::Pack;
|
||||
use spl_token_2022::instruction::AuthorityType;
|
||||
use steel::*;
|
||||
|
||||
/// Opens a new block.
|
||||
@@ -9,7 +10,7 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
let id = u64::from_le_bytes(args.id);
|
||||
|
||||
// Load accounts.
|
||||
let [signer_info, block_info, market_info, market_hash_info, market_ore_info, mint_hash_info, mint_ore_info, system_program, token_program, associated_token_program, rent_sysvar] =
|
||||
let [signer_info, block_info, market_info, mint_base_info, mint_quote_info, system_program, vault_base_info, vault_quote_info, token_program, associated_token_program, rent_sysvar] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -23,11 +24,11 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
.is_empty()?
|
||||
.is_writable()?
|
||||
.has_seeds(&[MARKET, &id.to_le_bytes()], &ore_api::ID)?;
|
||||
mint_hash_info
|
||||
mint_base_info
|
||||
.is_empty()?
|
||||
.is_writable()?
|
||||
.has_seeds(&[MINT, &id.to_le_bytes()], &ore_api::ID)?;
|
||||
mint_ore_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
mint_quote_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
associated_token_program.is_program(&spl_associated_token_account::ID)?;
|
||||
@@ -59,14 +60,14 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
)?;
|
||||
let market = market_info.as_account_mut::<Market>(&ore_api::ID)?;
|
||||
market.base = TokenParams {
|
||||
mint: Pubkey::default(),
|
||||
balance: 0,
|
||||
mint: *mint_base_info.key,
|
||||
balance: HASH_TOKEN_SUPPLY,
|
||||
balance_virtual: 0,
|
||||
};
|
||||
market.quote = TokenParams {
|
||||
mint: Pubkey::default(),
|
||||
mint: *mint_quote_info.key,
|
||||
balance: 0,
|
||||
balance_virtual: 0,
|
||||
balance_virtual: ONE_ORE,
|
||||
};
|
||||
market.fee = FeeParams {
|
||||
rate: FEE_RATE_BPS,
|
||||
@@ -83,7 +84,7 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
|
||||
// Initialize hash token mint.
|
||||
allocate_account(
|
||||
mint_hash_info,
|
||||
mint_base_info,
|
||||
system_program,
|
||||
signer_info,
|
||||
spl_token::state::Mint::LEN,
|
||||
@@ -91,7 +92,7 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
&[MINT, &id.to_le_bytes()],
|
||||
)?;
|
||||
initialize_mint_signed(
|
||||
mint_hash_info,
|
||||
mint_base_info,
|
||||
block_info,
|
||||
None,
|
||||
token_program,
|
||||
@@ -102,50 +103,50 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
|
||||
|
||||
// TODO Initialize hash token metadata.
|
||||
|
||||
// Initialize token accounts for market.
|
||||
if market_hash_info.data_is_empty() {
|
||||
// Initialize vault token accounts.
|
||||
if vault_base_info.data_is_empty() {
|
||||
create_associated_token_account(
|
||||
signer_info,
|
||||
market_info,
|
||||
market_hash_info,
|
||||
mint_hash_info,
|
||||
vault_base_info,
|
||||
mint_base_info,
|
||||
system_program,
|
||||
token_program,
|
||||
associated_token_program,
|
||||
)?;
|
||||
} else {
|
||||
market_hash_info.as_associated_token_account(market_info.key, mint_hash_info.key)?;
|
||||
vault_base_info.as_associated_token_account(market_info.key, mint_base_info.key)?;
|
||||
}
|
||||
if market_ore_info.data_is_empty() {
|
||||
if vault_quote_info.data_is_empty() {
|
||||
create_associated_token_account(
|
||||
signer_info,
|
||||
market_info,
|
||||
market_ore_info,
|
||||
mint_ore_info,
|
||||
vault_quote_info,
|
||||
mint_quote_info,
|
||||
system_program,
|
||||
token_program,
|
||||
associated_token_program,
|
||||
)?;
|
||||
} else {
|
||||
market_ore_info.as_associated_token_account(market_info.key, mint_ore_info.key)?;
|
||||
vault_quote_info.as_associated_token_account(market_info.key, mint_quote_info.key)?;
|
||||
}
|
||||
|
||||
// Mint hash tokens to market.
|
||||
mint_to_signed(
|
||||
mint_hash_info,
|
||||
market_hash_info,
|
||||
mint_base_info,
|
||||
vault_base_info,
|
||||
block_info,
|
||||
token_program,
|
||||
10_000_000,
|
||||
HASH_TOKEN_SUPPLY,
|
||||
&[BLOCK, &id.to_le_bytes()],
|
||||
)?;
|
||||
|
||||
// Burn mint authority.
|
||||
set_authority_signed(
|
||||
mint_hash_info,
|
||||
mint_base_info,
|
||||
block_info,
|
||||
None,
|
||||
spl_token_2022::instruction::AuthorityType::MintTokens,
|
||||
AuthorityType::MintTokens,
|
||||
token_program,
|
||||
&[BLOCK, &id.to_le_bytes()],
|
||||
)?;
|
||||
|
||||
Reference in New Issue
Block a user