#![allow(deprecated)]
pub mod instructions;
pub mod states;
pub mod ops;
pub mod constants;
pub mod utils;
pub mod events;
use self::{
instructions::*,
ops::{
deposit::CreateDepositParams,
glv::{CreateGlvDepositParams, CreateGlvWithdrawalParams},
order::{CreateOrderParams, PositionCutKind},
shift::CreateShiftParams,
withdrawal::CreateWithdrawalParams,
},
states::{
glv::UpdateGlvParams,
market::{config::EntryArgs, status::MarketStatus},
order::UpdateOrderParams,
token_config::UpdateTokenConfigParams,
FactorKey, PriceProviderKind,
},
utils::internal,
};
use anchor_lang::prelude::*;
use gmsol_model::price::Prices;
#[cfg_attr(test, macro_use)]
extern crate static_assertions;
declare_id!("Gmso1uvJnLbawvw7yezdfCDcPydwW2s2iqG3w6MDucLo");
#[program]
pub mod gmsol_store {
use gmsol_utils::token_config::TokenConfigFlag;
use super::*;
pub fn initialize(ctx: Context<Initialize>, key: String) -> Result<()> {
instructions::initialize(ctx, key)
}
#[access_control(internal::Authenticate::only_admin(&ctx))]
pub fn update_last_restarted_slot(ctx: Context<UpdateLastRestartedSlot>) -> Result<()> {
instructions::update_last_restarted_slot(ctx)
}
#[access_control(internal::Authenticate::only_admin(&ctx))]
pub fn transfer_store_authority(ctx: Context<TransferStoreAuthority>) -> Result<()> {
instructions::unchecked_transfer_store_authority(ctx)
}
pub fn accept_store_authority(ctx: Context<AcceptStoreAuthority>) -> Result<()> {
instructions::accept_store_authority(ctx)
}
pub fn transfer_receiver(ctx: Context<TransferReceiver>) -> Result<()> {
instructions::transfer_receiver(ctx)
}
pub fn accept_receiver(ctx: Context<AcceptReceiver>) -> Result<()> {
instructions::accept_receiver(ctx)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn set_token_map(ctx: Context<SetTokenMap>) -> Result<()> {
instructions::unchecked_set_token_map(ctx)
}
pub fn check_admin(ctx: Context<CheckRole>) -> Result<bool> {
instructions::check_admin(ctx)
}
pub fn check_role(ctx: Context<CheckRole>, role: String) -> Result<bool> {
instructions::check_role(ctx, role)
}
pub fn has_admin(ctx: Context<HasRole>, authority: Pubkey) -> Result<bool> {
instructions::has_admin(ctx, authority)
}
pub fn has_role(ctx: Context<HasRole>, authority: Pubkey, role: String) -> Result<bool> {
instructions::has_role(ctx, authority, role)
}
#[access_control(internal::Authenticate::only_admin(&ctx))]
pub fn enable_role(ctx: Context<EnableRole>, role: String) -> Result<()> {
instructions::unchecked_enable_role(ctx, role)
}
#[access_control(internal::Authenticate::only_admin(&ctx))]
pub fn disable_role(ctx: Context<DisableRole>, role: String) -> Result<()> {
instructions::unchecked_disable_role(ctx, role)
}
#[access_control(internal::Authenticate::only_admin(&ctx))]
pub fn grant_role(ctx: Context<GrantRole>, user: Pubkey, role: String) -> Result<()> {
instructions::unchecked_grant_role(ctx, user, role)
}
#[access_control(internal::Authenticate::only_admin(&ctx))]
pub fn revoke_role(ctx: Context<RevokeRole>, user: Pubkey, role: String) -> Result<()> {
instructions::unchecked_revoke_role(ctx, user, role)
}
#[access_control(internal::Authenticate::only_config_keeper(&ctx))]
pub fn insert_amount(ctx: Context<InsertConfig>, key: String, amount: u64) -> Result<()> {
instructions::unchecked_insert_amount(ctx, &key, amount)
}
#[access_control(internal::Authenticate::only_config_keeper(&ctx))]
pub fn insert_factor(ctx: Context<InsertConfig>, key: String, factor: u128) -> Result<()> {
instructions::unchecked_insert_factor(ctx, &key, factor)
}
#[access_control(internal::Authenticate::only_config_keeper(&ctx))]
pub fn insert_address(ctx: Context<InsertConfig>, key: String, address: Pubkey) -> Result<()> {
instructions::unchecked_insert_address(ctx, &key, address)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn insert_order_fee_discount_for_referred_user(
ctx: Context<InsertConfig>,
factor: u128,
) -> Result<()> {
let key = FactorKey::OrderFeeDiscountForReferredUser;
instructions::unchecked_insert_factor(ctx, &key.to_string(), factor)
}
#[access_control(internal::Authenticate::only_feature_keeper(&ctx))]
pub fn toggle_feature(
ctx: Context<ToggleFeature>,
domain: String,
action: String,
enable: bool,
) -> Result<()> {
let domain = domain
.parse()
.map_err(|_| error!(CoreError::InvalidArgument))?;
let action = action
.parse()
.map_err(|_| error!(CoreError::InvalidArgument))?;
instructions::unchecked_toggle_feature(ctx, domain, action, enable)
}
pub fn initialize_token_map(ctx: Context<InitializeTokenMap>) -> Result<()> {
instructions::initialize_token_map(ctx)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn push_to_token_map(
ctx: Context<PushToTokenMap>,
name: String,
builder: UpdateTokenConfigParams,
enable: bool,
new: bool,
) -> Result<()> {
instructions::unchecked_push_to_token_map(ctx, &name, builder, enable, new)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn push_to_token_map_synthetic(
ctx: Context<PushToTokenMapSynthetic>,
name: String,
token: Pubkey,
token_decimals: u8,
builder: UpdateTokenConfigParams,
enable: bool,
new: bool,
) -> Result<()> {
instructions::unchecked_push_to_token_map_synthetic(
ctx,
&name,
token,
token_decimals,
builder,
enable,
new,
)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn toggle_token_config(
ctx: Context<ToggleTokenConfig>,
token: Pubkey,
enable: bool,
) -> Result<()> {
ToggleTokenConfig::invoke_unchecked(ctx, token, TokenConfigFlag::Enabled, enable)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn toggle_token_price_adjustment(
ctx: Context<ToggleTokenConfig>,
token: Pubkey,
enable: bool,
) -> Result<()> {
ToggleTokenConfig::invoke_unchecked(
ctx,
token,
TokenConfigFlag::AllowPriceAdjustment,
enable,
)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn set_expected_provider(
ctx: Context<SetExpectedProvider>,
token: Pubkey,
provider: u8,
) -> Result<()> {
instructions::unchecked_set_expected_provider(
ctx,
token,
PriceProviderKind::try_from(provider)
.map_err(|_| CoreError::InvalidProviderKindIndex)?,
)
}
#[deprecated(since = "0.6.0", note = "use `set_feed_config_v2` instead")]
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn set_feed_config(
ctx: Context<SetFeedConfig>,
token: Pubkey,
provider: u8,
feed: Pubkey,
timestamp_adjustment: u32,
) -> Result<()> {
SetFeedConfig::invoke_unchecked(
ctx,
token,
&PriceProviderKind::try_from(provider)
.map_err(|_| CoreError::InvalidProviderKindIndex)?,
Some(feed),
Some(timestamp_adjustment),
None,
)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn set_feed_config_v2(
ctx: Context<SetFeedConfig>,
token: Pubkey,
provider: u8,
feed: Option<Pubkey>,
timestamp_adjustment: Option<u32>,
max_deviation_factor: Option<u128>,
) -> Result<()> {
SetFeedConfig::invoke_unchecked(
ctx,
token,
&PriceProviderKind::try_from(provider)
.map_err(|_| CoreError::InvalidProviderKindIndex)?,
feed,
timestamp_adjustment,
max_deviation_factor,
)
}
pub fn is_token_config_enabled(ctx: Context<ReadTokenMap>, token: Pubkey) -> Result<bool> {
instructions::is_token_config_enabled(ctx, &token)
}
pub fn token_expected_provider(ctx: Context<ReadTokenMap>, token: Pubkey) -> Result<u8> {
instructions::token_expected_provider(ctx, &token).map(|kind| kind as u8)
}
pub fn token_feed(ctx: Context<ReadTokenMap>, token: Pubkey, provider: u8) -> Result<Pubkey> {
instructions::token_feed(
ctx,
&token,
&PriceProviderKind::try_from(provider)
.map_err(|_| CoreError::InvalidProviderKindIndex)?,
)
}
pub fn token_timestamp_adjustment(
ctx: Context<ReadTokenMap>,
token: Pubkey,
provider: u8,
) -> Result<u32> {
instructions::token_timestamp_adjustment(
ctx,
&token,
&PriceProviderKind::try_from(provider)
.map_err(|_| CoreError::InvalidProviderKindIndex)?,
)
}
pub fn token_name(ctx: Context<ReadTokenMap>, token: Pubkey) -> Result<String> {
instructions::token_name(ctx, &token)
}
pub fn token_decimals(ctx: Context<ReadTokenMap>, token: Pubkey) -> Result<u8> {
instructions::token_decimals(ctx, &token)
}
pub fn token_precision(ctx: Context<ReadTokenMap>, token: Pubkey) -> Result<u8> {
instructions::token_precision(ctx, &token)
}
pub fn initialize_oracle(ctx: Context<InitializeOracle>) -> Result<()> {
instructions::initialize_oracle(ctx)
}
#[access_control(internal::Authenticate::only_oracle_controller(&ctx))]
pub fn clear_all_prices(ctx: Context<ClearAllPrices>) -> Result<()> {
instructions::unchecked_clear_all_prices(ctx)
}
#[access_control(internal::Authenticate::only_oracle_controller(&ctx))]
pub fn set_prices_from_price_feed<'info>(
ctx: Context<'_, '_, 'info, 'info, SetPricesFromPriceFeed<'info>>,
tokens: Vec<Pubkey>,
) -> Result<()> {
instructions::unchecked_set_prices_from_price_feed(ctx, tokens)
}
#[access_control(internal::Authenticate::only_price_keeper(&ctx))]
pub fn initialize_price_feed(
ctx: Context<InitializePriceFeed>,
index: u16,
provider: u8,
token: Pubkey,
feed_id: Pubkey,
) -> Result<()> {
let provider = PriceProviderKind::try_from(provider)
.map_err(|_| error!(CoreError::InvalidProviderKindIndex))?;
instructions::unchecked_initialize_price_feed(ctx, index, provider, &token, &feed_id)
}
#[access_control(internal::Authenticate::only_price_keeper(&ctx))]
pub fn update_price_feed_with_chainlink(
ctx: Context<UpdatePriceFeedWithChainlink>,
compressed_report: Vec<u8>,
) -> Result<()> {
instructions::unchecked_update_price_feed_with_chainlink(ctx, compressed_report)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn initialize_market(
ctx: Context<InitializeMarket>,
index_token_mint: Pubkey,
name: String,
enable: bool,
) -> Result<()> {
instructions::unchecked_initialize_market(ctx, index_token_mint, &name, enable)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn toggle_market(ctx: Context<ToggleMarket>, enable: bool) -> Result<()> {
instructions::unchecked_toggle_market(ctx, enable)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn market_transfer_in(ctx: Context<MarketTransferIn>, amount: u64) -> Result<()> {
instructions::unchecked_market_transfer_in(ctx, amount)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn update_market_config(
ctx: Context<UpdateMarketConfig>,
key: String,
value: u128,
) -> Result<()> {
instructions::unchecked_update_market_config(ctx, &key, value)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn update_market_config_flag(
ctx: Context<UpdateMarketConfig>,
key: String,
value: bool,
) -> Result<()> {
instructions::unchecked_update_market_config_flag(ctx, &key, value)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn update_market_config_with_buffer(
ctx: Context<UpdateMarketConfigWithBuffer>,
) -> Result<()> {
instructions::unchecked_update_market_config_with_buffer(ctx)
}
pub fn get_market_status(
ctx: Context<ReadMarket>,
prices: Prices<u128>,
maximize_pnl: bool,
maximize_pool_value: bool,
) -> Result<MarketStatus> {
instructions::get_market_status(ctx, &prices, maximize_pnl, maximize_pool_value)
}
pub fn get_market_token_price(
ctx: Context<ReadMarketWithToken>,
prices: Prices<u128>,
pnl_factor: String,
maximize: bool,
) -> Result<u128> {
instructions::get_market_token_price(
ctx,
&prices,
pnl_factor
.parse()
.map_err(|_| error!(CoreError::InvalidArgument))?,
maximize,
)
}
pub fn initialize_market_config_buffer(
ctx: Context<InitializeMarketConfigBuffer>,
expire_after_secs: u32,
) -> Result<()> {
instructions::initialize_market_config_buffer(ctx, expire_after_secs)
}
pub fn set_market_config_buffer_authority(
ctx: Context<SetMarketConfigBufferAuthority>,
new_authority: Pubkey,
) -> Result<()> {
instructions::set_market_config_buffer_authority(ctx, new_authority)
}
pub fn close_market_config_buffer(ctx: Context<CloseMarketConfigBuffer>) -> Result<()> {
instructions::close_market_config_buffer(ctx)
}
pub fn push_to_market_config_buffer(
ctx: Context<PushToMarketConfigBuffer>,
new_configs: Vec<EntryArgs>,
) -> Result<()> {
instructions::push_to_market_config_buffer(ctx, new_configs)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn toggle_gt_minting(ctx: Context<ToggleGTMinting>, enable: bool) -> Result<()> {
instructions::unchecked_toggle_gt_minting(ctx, enable)
}
pub fn claim_fees_from_market(ctx: Context<ClaimFeesFromMarket>) -> Result<u64> {
let claimed = instructions::claim_fees_from_market(ctx)?;
Ok(claimed)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn initialize_market_vault(ctx: Context<InitializeMarketVault>) -> Result<()> {
instructions::unchecked_initialize_market_vault(ctx)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn use_claimable_account(
ctx: Context<UseClaimableAccount>,
timestamp: i64,
amount: u64,
) -> Result<()> {
instructions::unchecked_use_claimable_account(ctx, timestamp, amount)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn close_empty_claimable_account(
ctx: Context<CloseEmptyClaimableAccount>,
timestamp: i64,
) -> Result<()> {
instructions::unchecked_close_empty_claimable_account(ctx, timestamp)
}
pub fn prepare_associated_token_account(
ctx: Context<PrepareAssociatedTokenAccount>,
) -> Result<()> {
instructions::prepare_associated_token_account(ctx)
}
pub fn create_deposit<'info>(
mut ctx: Context<'_, '_, 'info, 'info, CreateDeposit<'info>>,
nonce: [u8; 32],
params: CreateDepositParams,
) -> Result<()> {
internal::Create::create(&mut ctx, &nonce, ¶ms, None)
}
pub fn close_deposit<'info>(
ctx: Context<'_, '_, 'info, 'info, CloseDeposit<'info>>,
reason: String,
) -> Result<()> {
internal::Close::close(&ctx, &reason)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_deposit<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteDeposit<'info>>,
execution_fee: u64,
throw_on_execution_error: bool,
) -> Result<()> {
instructions::unchecked_execute_deposit(ctx, execution_fee, throw_on_execution_error)
}
pub fn create_withdrawal<'info>(
mut ctx: Context<'_, '_, 'info, 'info, CreateWithdrawal<'info>>,
nonce: [u8; 32],
params: CreateWithdrawalParams,
) -> Result<()> {
internal::Create::create(&mut ctx, &nonce, ¶ms, None)
}
pub fn close_withdrawal<'info>(
ctx: Context<'_, '_, 'info, 'info, CloseWithdrawal<'info>>,
reason: String,
) -> Result<()> {
internal::Close::close(&ctx, &reason)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_withdrawal<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteWithdrawal<'info>>,
execution_fee: u64,
throw_on_execution_error: bool,
) -> Result<()> {
instructions::unchecked_execute_withdrawal(ctx, execution_fee, throw_on_execution_error)
}
pub fn prepare_position(
ctx: Context<PreparePosition>,
params: CreateOrderParams,
) -> Result<()> {
instructions::prepare_position(ctx, ¶ms)
}
#[deprecated(since = "0.6.0", note = "use `create_order_v2` instead.")]
pub fn create_order<'info>(
mut ctx: Context<'_, '_, 'info, 'info, CreateOrder<'info>>,
nonce: [u8; 32],
params: CreateOrderParams,
) -> Result<()> {
internal::Create::create(&mut ctx, &nonce, ¶ms, None)
}
pub fn create_order_v2<'info>(
mut ctx: Context<'_, '_, 'info, 'info, CreateOrderV2<'info>>,
nonce: [u8; 32],
params: CreateOrderParams,
callback_version: Option<u8>,
) -> Result<()> {
internal::Create::create(&mut ctx, &nonce, ¶ms, callback_version)
}
#[deprecated(since = "0.6.0", note = "use `close_order_v2` instead.")]
pub fn close_order<'info>(
ctx: Context<'_, '_, 'info, 'info, CloseOrder<'info>>,
reason: String,
) -> Result<()> {
internal::Close::close(&ctx, &reason)
}
pub fn close_order_v2<'info>(
ctx: Context<'_, '_, 'info, 'info, CloseOrderV2<'info>>,
reason: String,
) -> Result<()> {
internal::Close::close(&ctx, &reason)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn cancel_order_if_no_position(ctx: Context<CancelOrderIfNoPosition>) -> Result<()> {
instructions::unchecked_cancel_order_if_no_position(ctx)
}
#[allow(rustdoc::broken_intra_doc_links)]
pub fn prepare_trade_event_buffer(
ctx: Context<PrepareTradeEventBuffer>,
index: u16,
) -> Result<()> {
instructions::prepare_trade_event_buffer(ctx, index)
}
#[deprecated(since = "0.6.0", note = "use `update_order_v2` instead")]
pub fn update_order(ctx: Context<UpdateOrder>, params: UpdateOrderParams) -> Result<()> {
instructions::update_order(ctx, ¶ms)
}
pub fn update_order_v2(ctx: Context<UpdateOrderV2>, params: UpdateOrderParams) -> Result<()> {
UpdateOrderV2::invoke(ctx, ¶ms)
}
#[allow(rustdoc::broken_intra_doc_links)]
#[deprecated(
since = "0.6.0",
note = "use `execute_increase_or_swap_order_v2` instead."
)]
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_increase_or_swap_order<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteIncreaseOrSwapOrder<'info>>,
recent_timestamp: i64,
execution_fee: u64,
throw_on_execution_error: bool,
) -> Result<()> {
instructions::unchecked_execute_increase_or_swap_order(
ctx,
recent_timestamp,
execution_fee,
throw_on_execution_error,
)
}
#[allow(rustdoc::broken_intra_doc_links)]
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_increase_or_swap_order_v2<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteIncreaseOrSwapOrderV2<'info>>,
recent_timestamp: i64,
execution_fee: u64,
throw_on_execution_error: bool,
) -> Result<()> {
ExecuteIncreaseOrSwapOrderV2::invoke(
ctx,
recent_timestamp,
execution_fee,
throw_on_execution_error,
)
}
#[allow(rustdoc::broken_intra_doc_links)]
#[deprecated(since = "0.6.0", note = "use `execute_decrease_order_v2` instead.")]
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_decrease_order<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteDecreaseOrder<'info>>,
recent_timestamp: i64,
execution_fee: u64,
throw_on_execution_error: bool,
) -> Result<()> {
instructions::unchecked_execute_decrease_order(
ctx,
recent_timestamp,
execution_fee,
throw_on_execution_error,
)
}
#[allow(rustdoc::broken_intra_doc_links)]
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_decrease_order_v2<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteDecreaseOrderV2<'info>>,
recent_timestamp: i64,
execution_fee: u64,
throw_on_execution_error: bool,
) -> Result<()> {
ExecuteDecreaseOrderV2::invoke(
ctx,
recent_timestamp,
execution_fee,
throw_on_execution_error,
)
}
#[allow(rustdoc::broken_intra_doc_links)]
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn liquidate<'info>(
ctx: Context<'_, '_, 'info, 'info, PositionCut<'info>>,
nonce: [u8; 32],
recent_timestamp: i64,
execution_fee: u64,
) -> Result<()> {
instructions::unchecked_process_position_cut(
ctx,
&nonce,
recent_timestamp,
PositionCutKind::Liquidate,
execution_fee,
true,
)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn update_adl_state<'info>(
ctx: Context<'_, '_, 'info, 'info, UpdateAdlState<'info>>,
is_long: bool,
) -> Result<()> {
instructions::unchecked_update_adl_state(ctx, is_long)
}
#[allow(rustdoc::broken_intra_doc_links)]
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn auto_deleverage<'info>(
ctx: Context<'_, '_, 'info, 'info, PositionCut<'info>>,
nonce: [u8; 32],
recent_timestamp: i64,
size_delta_in_usd: u128,
execution_fee: u64,
) -> Result<()> {
instructions::unchecked_process_position_cut(
ctx,
&nonce,
recent_timestamp,
PositionCutKind::AutoDeleverage(size_delta_in_usd),
execution_fee,
true,
)
}
pub fn create_shift<'info>(
mut ctx: Context<'_, '_, 'info, 'info, CreateShift<'info>>,
nonce: [u8; 32],
params: CreateShiftParams,
) -> Result<()> {
internal::Create::create(&mut ctx, &nonce, ¶ms, None)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_shift<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteShift<'info>>,
execution_lamports: u64,
throw_on_execution_error: bool,
) -> Result<()> {
instructions::unchecked_execute_shift(ctx, execution_lamports, throw_on_execution_error)
}
pub fn close_shift<'info>(
ctx: Context<'_, '_, 'info, 'info, CloseShift<'info>>,
reason: String,
) -> Result<()> {
internal::Close::close(&ctx, &reason)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn initialize_gt(
ctx: Context<InitializeGt>,
decimals: u8,
initial_minting_cost: u128,
grow_factor: u128,
grow_step: u64,
ranks: Vec<u64>,
) -> Result<()> {
instructions::unchecked_initialize_gt(
ctx,
decimals,
initial_minting_cost,
grow_factor,
grow_step,
&ranks,
)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn gt_set_order_fee_discount_factors(
ctx: Context<ConfigureGt>,
factors: Vec<u128>,
) -> Result<()> {
instructions::unchecked_gt_set_order_fee_discount_factors(ctx, &factors)
}
#[access_control(internal::Authenticate::only_gt_controller(&ctx))]
pub fn gt_set_referral_reward_factors(
ctx: Context<ConfigureGt>,
factors: Vec<u128>,
) -> Result<()> {
instructions::unchecked_gt_set_referral_reward_factors(ctx, &factors)
}
#[access_control(internal::Authenticate::only_gt_controller(&ctx))]
pub fn gt_set_exchange_time_window(ctx: Context<ConfigureGt>, window: u32) -> Result<()> {
cfg_if::cfg_if! {
if #[cfg(feature = "test-only")] {
instructions::unchecked_gt_set_exchange_time_window(ctx, window)
} else {
msg!("Trying to set the GT exchange time window to {}, but this is a test-only instruction", window);
Err(CoreError::Unimplemented.into())
}
}
}
pub fn prepare_gt_exchange_vault(
ctx: Context<PrepareGtExchangeVault>,
time_window_index: i64,
) -> Result<()> {
instructions::prepare_gt_exchange_vault(ctx, time_window_index)
}
#[deprecated(since = "0.6.0", note = "use `confirm_gt_exchange_vault_v2` instead")]
#[access_control(internal::Authenticate::only_gt_controller(&ctx))]
pub fn confirm_gt_exchange_vault(ctx: Context<ConfirmGtExchangeVault>) -> Result<()> {
instructions::unchecked_confirm_gt_exchange_vault(ctx, None, None)
}
#[access_control(internal::Authenticate::only_gt_controller(&ctx))]
pub fn confirm_gt_exchange_vault_v2(
ctx: Context<ConfirmGtExchangeVault>,
buyback_value: u128,
buyback_price: Option<u128>,
) -> Result<()> {
instructions::unchecked_confirm_gt_exchange_vault(ctx, Some(buyback_value), buyback_price)
}
pub fn request_gt_exchange(ctx: Context<RequestGtExchange>, amount: u64) -> Result<()> {
instructions::request_gt_exchange(ctx, amount)
}
#[access_control(internal::Authenticate::only_gt_controller(&ctx))]
pub fn close_gt_exchange(ctx: Context<CloseGtExchange>) -> Result<()> {
instructions::unchecked_close_gt_exchange(ctx)
}
pub fn prepare_user(ctx: Context<PrepareUser>) -> Result<()> {
instructions::prepare_user(ctx)
}
pub fn initialize_referral_code(
ctx: Context<InitializeReferralCode>,
code: [u8; 8],
) -> Result<()> {
instructions::initialize_referral_code(ctx, code)
}
pub fn set_referrer(ctx: Context<SetReferrer>, code: [u8; 8]) -> Result<()> {
instructions::set_referrer(ctx, code)
}
pub fn transfer_referral_code(ctx: Context<TransferReferralCode>) -> Result<()> {
instructions::transfer_referral_code(ctx)
}
pub fn cancel_referral_code_transfer(ctx: Context<CancelReferralCodeTransfer>) -> Result<()> {
instructions::cancel_referral_code_transfer(ctx)
}
pub fn accept_referral_code(ctx: Context<AcceptReferralCode>) -> Result<()> {
instructions::accept_referral_code(ctx)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn initialize_glv<'info>(
ctx: Context<'_, '_, 'info, 'info, InitializeGlv<'info>>,
index: u16,
length: u16,
) -> Result<()> {
instructions::unchecked_initialize_glv(ctx, index, length as usize)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn update_glv_market_config(
ctx: Context<UpdateGlvMarketConfig>,
max_amount: Option<u64>,
max_value: Option<u128>,
) -> Result<()> {
instructions::unchecked_update_glv_market_config(ctx, max_amount, max_value)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn toggle_glv_market_flag(
ctx: Context<UpdateGlvMarketConfig>,
flag: String,
enable: bool,
) -> Result<()> {
instructions::unchecked_toggle_glv_market_flag(ctx, &flag, enable)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn update_glv_config(ctx: Context<UpdateGlvConfig>, params: UpdateGlvParams) -> Result<()> {
instructions::unchecked_update_glv(ctx, ¶ms)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn insert_glv_market(ctx: Context<InsertGlvMarket>) -> Result<()> {
instructions::unchecked_insert_glv_market(ctx)
}
#[access_control(internal::Authenticate::only_market_keeper(&ctx))]
pub fn remove_glv_market(ctx: Context<RemoveGlvMarket>) -> Result<()> {
instructions::unchecked_remove_glv_market(ctx)
}
pub fn create_glv_deposit<'info>(
mut ctx: Context<'_, '_, 'info, 'info, CreateGlvDeposit<'info>>,
nonce: [u8; 32],
params: CreateGlvDepositParams,
) -> Result<()> {
internal::Create::create(&mut ctx, &nonce, ¶ms, None)
}
pub fn close_glv_deposit<'info>(
ctx: Context<'_, '_, 'info, 'info, CloseGlvDeposit<'info>>,
reason: String,
) -> Result<()> {
internal::Close::close(&ctx, &reason)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_glv_deposit<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteGlvDeposit<'info>>,
execution_lamports: u64,
throw_on_execution_error: bool,
) -> Result<()> {
instructions::unchecked_execute_glv_deposit(
ctx,
execution_lamports,
throw_on_execution_error,
)
}
pub fn create_glv_withdrawal<'info>(
mut ctx: Context<'_, '_, 'info, 'info, CreateGlvWithdrawal<'info>>,
nonce: [u8; 32],
params: CreateGlvWithdrawalParams,
) -> Result<()> {
internal::Create::create(&mut ctx, &nonce, ¶ms, None)
}
pub fn close_glv_withdrawal<'info>(
ctx: Context<'_, '_, 'info, 'info, CloseGlvWithdrawal<'info>>,
reason: String,
) -> Result<()> {
internal::Close::close(&ctx, &reason)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_glv_withdrawal<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteGlvWithdrawal<'info>>,
execution_lamports: u64,
throw_on_execution_error: bool,
) -> Result<()> {
instructions::unchecked_execute_glv_withdrawal(
ctx,
execution_lamports,
throw_on_execution_error,
)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn create_glv_shift<'info>(
mut ctx: Context<'_, '_, 'info, 'info, CreateGlvShift<'info>>,
nonce: [u8; 32],
params: CreateShiftParams,
) -> Result<()> {
internal::Create::create(&mut ctx, &nonce, ¶ms, None)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn close_glv_shift<'info>(
ctx: Context<'_, '_, 'info, 'info, CloseGlvShift<'info>>,
reason: String,
) -> Result<()> {
internal::Close::close(&ctx, &reason)
}
#[access_control(internal::Authenticate::only_order_keeper(&ctx))]
pub fn execute_glv_shift<'info>(
ctx: Context<'_, '_, 'info, 'info, ExecuteGlvShift<'info>>,
execution_lamports: u64,
throw_on_execution_error: bool,
) -> Result<()> {
instructions::unchecked_execute_glv_shift(ctx, execution_lamports, throw_on_execution_error)
}
#[access_control(internal::Authenticate::only_migration_keeper(&ctx))]
pub fn migrate_referral_code<'info>(
ctx: Context<'_, '_, 'info, 'info, MigrateReferralCode<'info>>,
) -> Result<()> {
cfg_if::cfg_if! {
if #[cfg(feature = "migration")] {
instructions::unchecked_migrate_referral_code(ctx)
} else {
err!(CoreError::Unimplemented)
}
}
}
pub fn initialize_callback_authority(ctx: Context<InitializeCallbackAuthority>) -> Result<()> {
InitializeCallbackAuthority::invoke(ctx)
}
}
pub type CoreResult<T> = std::result::Result<T, CoreError>;
#[error_code]
pub enum CoreError {
#[msg("non-default store is not allowed")]
NonDefaultStore,
#[msg("internal error")]
Internal,
#[msg("unimplemented")]
Unimplemented,
#[msg("not an admin")]
NotAnAdmin,
#[msg("permission denied")]
PermissionDenied,
#[msg("feature disabled")]
FeatureDisabled,
#[msg("model")]
Model,
#[msg("invalid argument")]
InvalidArgument,
#[msg("preconditions are not met")]
PreconditionsAreNotMet,
#[msg("not found")]
NotFound,
#[msg("exceed max length limit")]
ExceedMaxLengthLimit,
#[msg("not enough space")]
NotEnoughSpace,
#[msg("token amount overflow")]
TokenAmountOverflow,
#[msg("value overflow")]
ValueOverflow,
#[msg("unknown action state")]
UnknownActionState,
#[msg("load zero-copy account error")]
LoadAccountError,
#[msg("required token account is not provided")]
TokenAccountNotProvided,
#[msg("required token mint is not provided")]
TokenMintNotProvided,
#[msg("token decimals mismatched")]
TokenDecimalsMismatched,
#[msg("market account is not provided")]
MarketAccountIsNotProvided,
#[msg("store mismatched")]
StoreMismatched,
#[msg("owner mismatched")]
OwnerMismatched,
#[msg("receiver mismatched")]
ReceiverMismatched,
#[msg("rent receiver mismatched")]
RentReceiverMismatched,
#[msg("market mismatched")]
MarketMismatched,
#[msg("market token mint mismatched")]
MarketTokenMintMismatched,
#[msg("mint account not provided")]
MintAccountNotProvided,
#[msg("market token account mismatched")]
MarketTokenAccountMismatched,
#[msg("token mint mismatched")]
TokenMintMismatched,
#[msg("token account mismatched")]
TokenAccountMismatched,
#[msg("not an ATA for the given token")]
NotAnATA,
#[msg("not enough token amount")]
NotEnoughTokenAmount,
#[msg("token amount exceeds limit")]
TokenAmountExceedsLimit,
#[msg("unknown token")]
UnknownToken,
#[msg("not enough execution fee")]
NotEnoughExecutionFee,
#[msg("invalid swap path length")]
InvalidSwapPathLength,
#[msg("not enough swap markets in the path")]
NotEnoughSwapMarkets,
#[msg("invalid swap path")]
InvalidSwapPath,
#[msg("insufficient output amounts")]
InsufficientOutputAmount,
#[msg("store outdated")]
StoreOutdated,
#[msg("invalid store config key")]
InvalidStoreConfigKey,
#[msg("invalid provider kind index")]
InvalidProviderKindIndex,
#[msg("chainlink program is required")]
ChainlinkProgramIsRequired,
#[msg("this price provider is not supported to be used with custom price feed")]
NotSupportedCustomPriceProvider,
#[msg("not enough token feeds")]
NotEnoughTokenFeeds,
#[msg("oracle timestamps are larger than required")]
OracleTimestampsAreLargerThanRequired,
#[msg("oracle timestamps are smaller than required")]
OracleTimestampsAreSmallerThanRequired,
#[msg("invalid oracle timestamps range")]
InvalidOracleTimestampsRange,
#[msg("max oracle timestamps range exceeded")]
MaxOracleTimestampsRangeExceeded,
#[msg("oracle not updated")]
OracleNotUpdated,
#[msg("max price age exceeded")]
MaxPriceAgeExceeded,
#[msg("max price timestamp exceeded")]
MaxPriceTimestampExceeded,
#[msg("negative price is not supported")]
NegativePriceIsNotSupported,
#[msg("invalid oracle slot")]
InvalidOracleSlot,
#[msg("missing oracle price")]
MissingOraclePrice,
#[msg("invalid price feed price")]
InvalidPriceFeedPrice,
#[msg("price overflow")]
PriceOverflow,
#[msg("invalid price feed account")]
InvalidPriceFeedAccount,
#[msg("price feed is not updated")]
PriceFeedNotUpdated,
#[msg("prices are already set")]
PricesAreAlreadySet,
#[msg("price is already set")]
PriceIsAlreadySet,
#[msg("token config is disabled")]
TokenConfigDisabled,
#[msg("synthetic token price is not allowed")]
SyntheticTokenPriceIsNotAllowed,
#[msg("invalid price report")]
InvalidPriceReport,
#[msg("market is not open")]
MarketNotOpen,
#[msg("empty deposit")]
EmptyDeposit,
#[msg("invalid owner for the first deposit")]
InvalidReceiverForFirstDeposit,
#[msg("not enough market token amount for the first deposit")]
NotEnoughMarketTokenAmountForFirstDeposit,
#[msg("not enough GLV token amount for the first deposit")]
NotEnoughGlvTokenAmountForFirstDeposit,
#[msg("empty withdrawal")]
EmptyWithdrawal,
#[msg("empty order")]
EmptyOrder,
#[msg("invalid min output amount for limit swap order")]
InvalidMinOutputAmount,
#[msg("invalid trigger price")]
InvalidTriggerPrice,
#[msg("invalid position")]
InvalidPosition,
#[msg("invalid position kind")]
InvalidPositionKind,
#[msg("position mismatched")]
PositionMismatched,
#[msg("position is not required")]
PositionItNotRequired,
#[msg("position is required")]
PositionIsRequired,
#[msg("the order kind is not allowed by this instruction")]
OrderKindNotAllowed,
#[msg("unknown order kind")]
UnknownOrderKind,
#[msg("unknown order side")]
UnknownOrderSide,
#[msg("unknown decrease position swap type")]
UnknownDecreasePositionSwapType,
#[msg("missing initial collateral token")]
MissingInitialCollateralToken,
#[msg("missing final output token")]
MissingFinalOutputToken,
#[msg("missing pool tokens")]
MissingPoolTokens,
#[msg("invalid trade ID")]
InvalidTradeID,
#[msg("invalid trade delta size")]
InvalidTradeDeltaSize,
#[msg("invalid trade delta tokens")]
InvalidTradeDeltaTokens,
#[msg("invalid borrowing factor")]
InvalidBorrowingFactor,
#[msg("invalid funding factors")]
InvalidFundingFactors,
#[msg("no delegated authority is set")]
NoDelegatedAuthorityIsSet,
#[msg("claimable collateral for holding cannot be in output tokens")]
ClaimableCollateralForHoldingCannotBeInOutputTokens,
#[msg("ADL is not enabled")]
AdlNotEnabled,
#[msg("ADL is not required")]
AdlNotRequired,
#[msg("invalid ADL")]
InvalidAdl,
#[msg("same output tokens not merged")]
SameOutputTokensNotMerged,
#[msg("event buffer is not provided")]
EventBufferNotProvided,
#[msg("empty shift")]
EmptyShift,
#[msg("invalid shift markets")]
InvalidShiftMarkets,
#[msg("GT State has been initialized")]
GTStateHasBeenInitialized,
#[msg("invalid GT config")]
InvalidGTConfig,
#[msg("invalid GT discount")]
InvalidGTDiscount,
#[msg("user account has been initialized")]
UserAccountHasBeenInitialized,
#[msg("referral code has been set")]
ReferralCodeHasBeenSet,
#[msg("referrer has been set")]
ReferrerHasBeenSet,
#[msg("invalid user account")]
InvalidUserAccount,
#[msg("referral code mismatched")]
ReferralCodeMismatched,
#[msg("self-referral is not allowed")]
SelfReferral,
#[msg("mutual-referral is not allowed")]
MutualReferral,
#[msg("invalid market config key")]
InvalidMarketConfigKey,
#[msg("invalid collateral token")]
InvalidCollateralToken,
#[msg("disabled market")]
DisabledMarket,
#[msg("failed to calculate GLV value for this market")]
FailedToCalculateGlvValueForMarket,
#[msg("failed to calculate GLV amount to mint")]
FailedToCalculateGlvAmountToMint,
FailedTOCalculateMarketTokenAmountToBurn,
#[msg("GLV max market token balance amount exceeded")]
ExceedMaxGlvMarketTokenBalanceAmount,
#[msg("GLV max market token balance value exceeded")]
ExceedMaxGlvMarketTokenBalanceValue,
#[msg("empty GLV withdrawal")]
EmptyGlvWithdrawal,
#[msg("GLV: negative market pool value")]
GlvNegativeMarketPoolValue,
#[msg("GLV: deposit is not allowed with the given market")]
GlvDepositIsNotAllowed,
#[msg("GLV: shift interval not yet passed")]
GlvShiftIntervalNotYetPassed,
#[msg("GLV: shift max price impact exceeded")]
GlvShiftMaxPriceImpactExceeded,
#[msg("GLV: shift value is not large enough")]
GlvShiftValueNotLargeEnough,
#[msg("the decimals of token is immutable")]
TokenDecimalsChanged,
#[msg("price is stale")]
PriceIsStale,
#[msg("deprecated")]
Deprecated,
}