1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
pub mod curve;
pub mod error;
pub mod instructions;
pub mod states;
pub mod utils;
use anchor_lang::prelude::*;
use instructions::*;
#[cfg(not(feature = "no-entrypoint"))]
solana_security_txt::security_txt! {
name: "raydium-cp-swap",
project_url: "https://raydium.io",
contacts: "link:https://immunefi.com/bounty/raydium",
policy: "https://immunefi.com/bounty/raydium",
source_code: "https://github.com/raydium-io/raydium-cp-swap",
preferred_languages: "en",
auditors: "https://github.com/raydium-io/raydium-docs/blob/master/audit/MadShield%20Q1%202024/raydium-cp-swap-v-1.0.0.pdf"
}
// #[cfg(feature = "devnet")]
// declare_id!("FDnQgwtdB4rK194E39KRmWTKLsL4mqX9jKrBFZgkuWbN");
// #[cfg(not(feature = "devnet"))]
declare_id!("FUNZ2HupCYvrnNfmwSE3yuCZkTYvcjA6xky2Q5g1kFkS");
pub mod admin {
use anchor_lang::prelude::declare_id;
#[cfg(feature = "devnet")]
declare_id!("7Ykem4ENTbVr5Si1PE4esGpaZt3YT8i7mh92hvN6CAua");
#[cfg(not(feature = "devnet"))]
declare_id!("7Ykem4ENTbVr5Si1PE4esGpaZt3YT8i7mh92hvN6CAua");
}
pub const AUTH_SEED: &str = "vault_and_lp_mint_auth_seed";
#[program]
pub mod gobbler {
use super::*;
// The configuation of AMM protocol, include trade fee and protocol fee
/// # Arguments
///
/// * `ctx`- The accounts needed by instruction.
/// * `index` - The index of amm config, there may be multiple config.
/// * `trade_fee_rate` - Trade fee rate, can be changed.
/// * `protocol_fee_rate` - The rate of protocol fee within tarde fee.
/// * `fund_fee_rate` - The rate of fund fee within tarde fee.
///
pub fn create_amm_config(
ctx: Context<CreateAmmConfig>,
index: u64,
token_0_lp_rate: u64,
token_1_lp_rate: u64,
protocol_fee: u64,
creator_fee: u64,
) -> Result<()> {
instructions::create_amm_config(
ctx,
index,
token_0_lp_rate,
token_1_lp_rate,
protocol_fee,
creator_fee,
)
}
/// Updates the owner of the amm config
/// Must be called by the current owner or admin
///
/// # Arguments
///
/// * `ctx`- The context of accounts
/// * `trade_fee_rate`- The new trade fee rate of amm config, be set when `param` is 0
/// * `protocol_fee_rate`- The new protocol fee rate of amm config, be set when `param` is 1
/// * `fund_fee_rate`- The new fund fee rate of amm config, be set when `param` is 2
/// * `new_owner`- The config's new owner, be set when `param` is 3
/// * `new_fund_owner`- The config's new fund owner, be set when `param` is 4
/// * `param`- The vaule can be 0 | 1 | 2 | 3 | 4, otherwise will report a error
///
pub fn update_amm_config(ctx: Context<UpdateAmmConfig>, param: u8, value: u64) -> Result<()> {
instructions::update_amm_config(ctx, param, value)
}
/// Update pool status for given vaule
///
/// # Arguments
///
/// * `ctx`- The context of accounts
/// * `status` - The vaule of status
///
pub fn update_pool_status(ctx: Context<UpdatePoolStatus>, status: u8) -> Result<()> {
instructions::update_pool_status(ctx, status)
}
/// Collect the protocol fee accrued to the pool
///
/// # Arguments
///
/// * `ctx` - The context of accounts
/// * `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1
/// * `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0
///
pub fn collect_protocol_fee(
ctx: Context<CollectProtocolFee>,
amount_0_requested: u64,
amount_1_requested: u64,
) -> Result<()> {
instructions::collect_protocol_fee(ctx, amount_0_requested, amount_1_requested)
}
/// Collect the fund fee accrued to the pool
///
/// # Arguments
///
/// * `ctx` - The context of accounts
/// * `amount_0_requested` - The maximum amount of token_0 to send, can be 0 to collect fees in only token_1
/// * `amount_1_requested` - The maximum amount of token_1 to send, can be 0 to collect fees in only token_0
///
pub fn collect_fund_fee(
ctx: Context<CollectFundFee>,
amount_0_requested: u64,
amount_1_requested: u64,
) -> Result<()> {
instructions::collect_fund_fee(ctx, amount_0_requested, amount_1_requested)
}
/// Creates a pool for the given token pair and the initial price
///
/// # Arguments
///
/// * `ctx`- The context of accounts
/// * `init_amount_0` - the initial amount_0 to deposit
/// * `init_amount_1` - the initial amount_1 to deposit
/// * `open_time` - the timestamp allowed for swap
///
pub fn initialize(
ctx: Context<Initialize>,
init_amount_0: u64,
init_amount_1: u64,
open_time: u64,
) -> Result<()> {
instructions::initialize(ctx, init_amount_0, init_amount_1, open_time)
}
/// Creates a metadata pool for the given token pair and the initial price
///
/// # Arguments
///
/// * `ctx`- The context of accounts
/// * `init_amount_0` - the initial amount_0 to deposit
/// * `init_amount_1` - the initial amount_1 to deposit
/// * `open_time` - the timestamp allowed for swap
///
pub fn initialize_metadata(
ctx: Context<InitializeMetadata>,
name: String,
symbol: String,
uri: String,
) -> Result<()> {
instructions::initialize_metadata(ctx, name, symbol, uri)
}
/// Creates a pool for the given token pair and the initial price
///
/// # Arguments
///
/// * `ctx`- The context of accounts
/// * `lp_token_amount` - Pool token amount to transfer. token_a and token_b amount are set by the current exchange rate and size of the pool
/// * `maximum_token_0_amount` - Maximum token 0 amount to deposit, prevents excessive slippage
/// * `maximum_token_1_amount` - Maximum token 1 amount to deposit, prevents excessive slippage
///
pub fn deposit(
ctx: Context<Deposit>,
lp_token_amount: u64,
maximum_token_0_amount: u64,
maximum_token_1_amount: u64,
) -> Result<()> {
instructions::deposit(
ctx,
lp_token_amount,
maximum_token_0_amount,
maximum_token_1_amount,
)
}
/// Withdraw lp for token0 ande token1
///
/// # Arguments
///
/// * `ctx`- The context of accounts
/// * `lp_token_amount` - Amount of pool tokens to burn. User receives an output of token a and b based on the percentage of the pool tokens that are returned.
/// * `minimum_token_0_amount` - Minimum amount of token 0 to receive, prevents excessive slippage
/// * `minimum_token_1_amount` - Minimum amount of token 1 to receive, prevents excessive slippage
///
pub fn withdraw(
ctx: Context<Withdraw>,
lp_token_amount: u64,
minimum_token_0_amount: u64,
minimum_token_1_amount: u64,
) -> Result<()> {
instructions::withdraw(
ctx,
lp_token_amount,
minimum_token_0_amount,
minimum_token_1_amount,
)
}
/// Swap the tokens in the pool base input amount
///
/// # Arguments
///
/// * `ctx`- The context of accounts
/// * `amount_in` - input amount to transfer, output to DESTINATION is based on the exchange rate
/// * `minimum_amount_out` - Minimum amount of output token, prevents excessive slippage
///
pub fn swap_base_input(
ctx: Context<Swap>,
amount_in: u64,
minimum_amount_out: u64,
) -> Result<()> {
instructions::swap_base_input(ctx, amount_in, minimum_amount_out)
}
/// Swap the tokens in the pool base output amount
///
/// # Arguments
///
/// * `ctx`- The context of accounts
/// * `max_amount_in` - input amount prevents excessive slippage
/// * `amount_out` - amount of output token
///
pub fn swap_base_output(ctx: Context<Swap>, max_amount_in: u64, amount_out: u64) -> Result<()> {
instructions::swap_base_output(ctx, max_amount_in, amount_out)
}
}