1#![allow(clippy::result_large_err)]
4
5mod error;
6mod instructions;
7mod math;
8mod state;
9
10use {
11 anchor_lang::prelude::*,
12 instructions::*,
13 state::perpetuals::{PriceAndFee, ProfitAndLoss, SwapAmountAndFees},
14};
15
16solana_security_txt::security_txt! {
17 name: "Perpetuals",
18 project_url: "https://github.com/askibin/perpetuals",
19 contacts: "email:solana.farms@protonmail.com",
20 policy: "",
21 preferred_languages: "en",
22 auditors: ""
23}
24
25declare_id!("PERP9EeXeGnyEqGmxGSan4nGRAFNLwTufLJmiYsTJ8j");
26
27#[program]
28pub mod perpetuals {
29 use super::*;
30
31 pub fn init(ctx: Context<Init>, params: InitParams) -> Result<()> {
33 instructions::init(ctx, ¶ms)
34 }
35
36 pub fn add_pool<'info>(
37 ctx: Context<'_, '_, '_, 'info, AddPool<'info>>,
38 params: AddPoolParams,
39 ) -> Result<u8> {
40 instructions::add_pool(ctx, ¶ms)
41 }
42
43 pub fn remove_pool<'info>(
44 ctx: Context<'_, '_, '_, 'info, RemovePool<'info>>,
45 params: RemovePoolParams,
46 ) -> Result<u8> {
47 instructions::remove_pool(ctx, ¶ms)
48 }
49
50 pub fn add_token<'info>(
51 ctx: Context<'_, '_, '_, 'info, AddToken<'info>>,
52 params: AddTokenParams,
53 ) -> Result<u8> {
54 instructions::add_token(ctx, ¶ms)
55 }
56
57 pub fn remove_token<'info>(
58 ctx: Context<'_, '_, '_, 'info, RemoveToken<'info>>,
59 params: RemoveTokenParams,
60 ) -> Result<u8> {
61 instructions::remove_token(ctx, ¶ms)
62 }
63
64 pub fn set_admin_signers<'info>(
65 ctx: Context<'_, '_, '_, 'info, SetAdminSigners<'info>>,
66 params: SetAdminSignersParams,
67 ) -> Result<u8> {
68 instructions::set_admin_signers(ctx, ¶ms)
69 }
70
71 pub fn set_token_config<'info>(
72 ctx: Context<'_, '_, '_, 'info, SetTokenConfig<'info>>,
73 params: SetTokenConfigParams,
74 ) -> Result<u8> {
75 instructions::set_token_config(ctx, ¶ms)
76 }
77
78 pub fn set_borrow_rate<'info>(
79 ctx: Context<'_, '_, '_, 'info, SetBorrowRate<'info>>,
80 params: SetBorrowRateParams,
81 ) -> Result<u8> {
82 instructions::set_borrow_rate(ctx, ¶ms)
83 }
84
85 pub fn set_permissions<'info>(
86 ctx: Context<'_, '_, '_, 'info, SetPermissions<'info>>,
87 params: SetPermissionsParams,
88 ) -> Result<u8> {
89 instructions::set_permissions(ctx, ¶ms)
90 }
91
92 pub fn withdraw_fees<'info>(
93 ctx: Context<'_, '_, '_, 'info, WithdrawFees<'info>>,
94 params: WithdrawFeesParams,
95 ) -> Result<u8> {
96 instructions::withdraw_fees(ctx, ¶ms)
97 }
98
99 pub fn test_init(ctx: Context<TestInit>, params: TestInitParams) -> Result<()> {
102 instructions::test_init(ctx, ¶ms)
103 }
104
105 pub fn set_test_oracle_price<'info>(
106 ctx: Context<'_, '_, '_, 'info, SetTestOraclePrice<'info>>,
107 params: SetTestOraclePriceParams,
108 ) -> Result<u8> {
109 instructions::set_test_oracle_price(ctx, ¶ms)
110 }
111
112 pub fn set_test_time<'info>(
113 ctx: Context<'_, '_, '_, 'info, SetTestTime<'info>>,
114 params: SetTestTimeParams,
115 ) -> Result<u8> {
116 instructions::set_test_time(ctx, ¶ms)
117 }
118
119 pub fn swap(ctx: Context<Swap>, params: SwapParams) -> Result<()> {
122 instructions::swap(ctx, ¶ms)
123 }
124
125 pub fn add_liquidity(ctx: Context<AddLiquidity>, params: AddLiquidityParams) -> Result<()> {
126 instructions::add_liquidity(ctx, ¶ms)
127 }
128
129 pub fn remove_liquidity(
130 ctx: Context<RemoveLiquidity>,
131 params: RemoveLiquidityParams,
132 ) -> Result<()> {
133 instructions::remove_liquidity(ctx, ¶ms)
134 }
135
136 pub fn open_position(ctx: Context<OpenPosition>, params: OpenPositionParams) -> Result<()> {
137 instructions::open_position(ctx, ¶ms)
138 }
139
140 pub fn add_collateral(ctx: Context<AddCollateral>, params: AddCollateralParams) -> Result<()> {
141 instructions::add_collateral(ctx, ¶ms)
142 }
143
144 pub fn remove_collateral(
145 ctx: Context<RemoveCollateral>,
146 params: RemoveCollateralParams,
147 ) -> Result<()> {
148 instructions::remove_collateral(ctx, ¶ms)
149 }
150
151 pub fn close_position(ctx: Context<ClosePosition>, params: ClosePositionParams) -> Result<()> {
152 instructions::close_position(ctx, ¶ms)
153 }
154
155 pub fn liquidate(ctx: Context<Liquidate>, params: LiquidateParams) -> Result<()> {
156 instructions::liquidate(ctx, ¶ms)
157 }
158
159 pub fn get_entry_price_and_fee(
160 ctx: Context<GetEntryPriceAndFee>,
161 params: GetEntryPriceAndFeeParams,
162 ) -> Result<PriceAndFee> {
163 instructions::get_entry_price_and_fee(ctx, ¶ms)
164 }
165
166 pub fn get_exit_price_and_fee(
167 ctx: Context<GetExitPriceAndFee>,
168 params: GetExitPriceAndFeeParams,
169 ) -> Result<PriceAndFee> {
170 instructions::get_exit_price_and_fee(ctx, ¶ms)
171 }
172
173 pub fn get_pnl(ctx: Context<GetPnl>, params: GetPnlParams) -> Result<ProfitAndLoss> {
174 instructions::get_pnl(ctx, ¶ms)
175 }
176
177 pub fn get_liquidation_price(
178 ctx: Context<GetLiquidationPrice>,
179 params: GetLiquidationPriceParams,
180 ) -> Result<u64> {
181 instructions::get_liquidation_price(ctx, ¶ms)
182 }
183
184 pub fn get_swap_amount_and_fees(
185 ctx: Context<GetSwapAmountAndFees>,
186 params: GetSwapAmountAndFeesParams,
187 ) -> Result<SwapAmountAndFees> {
188 instructions::get_swap_amount_and_fees(ctx, ¶ms)
189 }
190}