Mango Markets
Searchโ€ฆ
Mango Program API
This is a complete reference of all instructions processed by the Mango on-chain program. You might want to use the Mango Client API as a reference on how to call these instructions. You can find the typescript code creating the instructions on github.
1
#[repr(C)]
2
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3
pub enum MangoInstruction {
4
/// Initialize a group of lending pools that can be cross margined
5
///
6
/// Accounts expected by this instruction (7 + 2 * NUM_TOKENS + 2 * NUM_MARKETS):
7
///
8
/// 0. `[writable]` mango_group_acc - the data account to store mango group state vars
9
/// 1. `[]` rent_acc - Rent sysvar account
10
/// 2. `[]` clock_acc - clock sysvar account
11
/// 3. `[]` signer_acc - pubkey of program_id hashed with signer_nonce and mango_group_acc.key
12
/// 4. `[]` dex_prog_acc - program id of serum dex
13
/// 5. `[]` srm_vault_acc - vault for fee tier reductions
14
/// 6. `[signer]` admin_acc - admin key who can change borrow limits
15
/// 7..7+NUM_TOKENS `[]` token_mint_accs - mint of each token in the same order as the spot
16
/// markets. Quote currency mint should be last.
17
/// e.g. for spot markets BTC/USDC, ETH/USDC -> [BTC, ETH, USDC]
18
///
19
/// 7+NUM_TOKENS..7+2*NUM_TOKENS `[]`
20
/// vault_accs - Vault owned by signer_acc.key for each of the mints
21
///
22
/// 7+2*NUM_TOKENS..7+2*NUM_TOKENS+NUM_MARKETS `[]`
23
/// spot_market_accs - MarketState account from serum dex for each of the spot markets
24
/// 7+2*NUM_TOKENS+NUM_MARKETS..7+2*NUM_TOKENS+2*NUM_MARKETS `[]`
25
/// oracle_accs - Solana Flux Aggregator accounts corresponding to each trading pair
26
InitMangoGroup {
27
signer_nonce: u64,
28
maint_coll_ratio: U64F64,
29
init_coll_ratio: U64F64,
30
borrow_limits: [u64; NUM_TOKENS]
31
},
32
โ€‹
33
/// Initialize a margin account for a user
34
///
35
/// Accounts expected by this instruction (4):
36
///
37
/// 0. `[]` mango_group_acc - MangoGroup that this margin account is for
38
/// 1. `[writable]` margin_account_acc - the margin account data
39
/// 2. `[signer]` owner_acc - Solana account of owner of the margin account
40
/// 3. `[]` rent_acc - Rent sysvar account
41
InitMarginAccount,
42
โ€‹
43
/// Deposit funds into margin account to be used as collateral and earn interest.
44
///
45
/// Accounts expected by this instruction (7):
46
///
47
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
48
/// 1. `[writable]` margin_account_acc - the margin account for this user
49
/// 2. `[signer]` owner_acc - Solana account of owner of the margin account
50
/// 3. `[writable]` token_account_acc - TokenAccount owned by user which will be sending the funds
51
/// 4. `[writable]` vault_acc - TokenAccount owned by MangoGroup
52
/// 5. `[]` token_prog_acc - acc pointed to by SPL token program id
53
/// 6. `[]` clock_acc - Clock sysvar account
54
Deposit {
55
quantity: u64
56
},
57
โ€‹
58
/// Withdraw funds that were deposited earlier.
59
///
60
/// Accounts expected by this instruction (8 + 2 * NUM_MARKETS):
61
///
62
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
63
/// 1. `[writable]` margin_account_acc - the margin account for this user
64
/// 2. `[signer]` owner_acc - Solana account of owner of the margin account
65
/// 3. `[writable]` token_account_acc - TokenAccount owned by user which will be receiving the funds
66
/// 4. `[writable]` vault_acc - TokenAccount owned by MangoGroup which will be sending
67
/// 5. `[]` signer_acc - acc pointed to by signer_key
68
/// 6. `[]` token_prog_acc - acc pointed to by SPL token program id
69
/// 7. `[]` clock_acc - Clock sysvar account
70
/// 8..8+NUM_MARKETS `[]` open_orders_accs - open orders for each of the spot market
71
/// 8+NUM_MARKETS..8+2*NUM_MARKETS `[]`
72
/// oracle_accs - flux aggregator feed accounts
73
Withdraw {
74
quantity: u64
75
},
76
โ€‹
77
/// Borrow by incrementing MarginAccount.borrows given collateral ratio is below init_coll_rat
78
///
79
/// Accounts expected by this instruction (4 + 2 * NUM_MARKETS):
80
///
81
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
82
/// 1. `[writable]` margin_account_acc - the margin account for this user
83
/// 2. `[signer]` owner_acc - Solana account of owner of the margin account
84
/// 3. `[]` clock_acc - Clock sysvar account
85
/// 4..4+NUM_MARKETS `[]` open_orders_accs - open orders for each of the spot market
86
/// 4+NUM_MARKETS..4+2*NUM_MARKETS `[]`
87
/// oracle_accs - flux aggregator feed accounts
88
Borrow {
89
token_index: usize,
90
quantity: u64
91
},
92
โ€‹
93
/// Use this token's position and deposit to reduce borrows
94
///
95
/// Accounts expected by this instruction (4):
96
///
97
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
98
/// 1. `[writable]` margin_account_acc - the margin account for this user
99
/// 2. `[signer]` owner_acc - Solana account of owner of the margin account
100
/// 3. `[]` clock_acc - Clock sysvar account
101
SettleBorrow {
102
token_index: usize,
103
quantity: u64
104
},
105
โ€‹
106
/// Take over a MarginAccount that is below init_coll_ratio by depositing funds
107
///
108
/// Accounts expected by this instruction (5 + 2 * NUM_MARKETS + 2 * NUM_TOKENS):
109
///
110
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
111
/// 1. `[signer]` liqor_acc - liquidator's solana account
112
/// 2. `[writable]` liqee_margin_account_acc - MarginAccount of liquidatee
113
/// 3. `[]` token_prog_acc - SPL token program id
114
/// 4. `[]` clock_acc - Clock sysvar account
115
/// 5..5+NUM_MARKETS `[]` open_orders_accs - open orders for each of the spot market
116
/// 5+NUM_MARKETS..5+2*NUM_MARKETS `[]`
117
/// oracle_accs - flux aggregator feed accounts
118
/// 5+2*NUM_MARKETS..5+2*NUM_MARKETS+NUM_TOKENS `[writable]`
119
/// vault_accs - MangoGroup vaults
120
/// 5+2*NUM_MARKETS+NUM_TOKENS..5+2*NUM_MARKETS+2*NUM_TOKENS `[writable]`
121
/// liqor_token_account_accs - Liquidator's token wallets
122
Liquidate {
123
/// Quantity of each token liquidator is depositing in order to bring account above maint
124
deposit_quantities: [u64; NUM_TOKENS]
125
},
126
โ€‹
127
/// Deposit SRM into the SRM vault for MangoGroup
128
/// These SRM are not at risk and are not counted towards collateral or any margin calculations
129
/// Depositing SRM is a strictly altruistic act with no upside and no downside
130
///
131
/// Accounts expected by this instruction (8):
132
///
133
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
134
/// 1. `[writable]` mango_srm_account_acc - the mango srm account for user
135
/// 2. `[signer]` owner_acc - Solana account of owner of the margin account
136
/// 3. `[writable]` srm_account_acc - TokenAccount owned by user which will be sending the funds
137
/// 4. `[writable]` vault_acc - SRM vault of MangoGroup
138
/// 5. `[]` token_prog_acc - acc pointed to by SPL token program id
139
/// 6. `[]` clock_acc - Clock sysvar account
140
/// 7. `[]` rent_acc - Rent sysvar account
141
DepositSrm {
142
quantity: u64
143
},
144
/// Withdraw SRM owed to this MarginAccount
145
/// These SRM are not at risk and are not counted towards collateral or any margin calculations
146
/// Depositing SRM is a strictly altruistic act with no upside and no downside
147
///
148
/// Accounts expected by this instruction (8):
149
///
150
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
151
/// 1. `[writable]` mango_srm_account_acc - the mango srm account for user
152
/// 2. `[signer]` owner_acc - Solana account of owner of the margin account
153
/// 3. `[writable]` srm_account_acc - TokenAccount owned by user which will be sending the funds
154
/// 4. `[writable]` vault_acc - SRM vault of MangoGroup
155
/// 5. `[]` signer_acc - acc pointed to by signer_key
156
/// 6. `[]` token_prog_acc - acc pointed to by SPL token program id
157
/// 7. `[]` clock_acc - Clock sysvar account
158
WithdrawSrm {
159
quantity: u64
160
},
161
โ€‹
162
// Proxy instructions to Dex
163
/// Place an order on the Serum Dex using Mango margin facilities
164
///
165
/// Accounts expected by this instruction (17 + 2 * NUM_MARKETS):
166
///
167
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
168
/// 1. `[signer]` owner_acc - MarginAccount owner
169
/// 2. `[writable]` margin_account_acc - MarginAccount
170
/// 3. `[]` clock_acc - Clock sysvar account
171
/// 4. `[]` dex_prog_acc - program id of serum dex
172
/// 5. `[writable]` spot_market_acc - serum dex MarketState
173
/// 6. `[writable]` dex_request_queue_acc - serum dex request queue for this market
174
/// 7. `[writable]` dex_event_queue - serum dex event queue for this market
175
/// 8. `[writable]` bids_acc - serum dex bids for this market
176
/// 9. `[writable]` asks_acc - serum dex asks for this market
177
/// 10. `[writable]` vault_acc - mango's vault for this currency (quote if buying, base if selling)
178
/// 11. `[]` signer_acc - mango signer key
179
/// 12. `[writable]` dex_base_acc - serum dex market's vault for base (coin) currency
180
/// 13. `[writable]` dex_quote_acc - serum dex market's vault for quote (pc) currency
181
/// 14. `[]` spl token program
182
/// 15. `[]` the rent sysvar
183
/// 16. `[writable]` srm_vault_acc - MangoGroup's srm_vault used for fee reduction
184
/// 17..17+NUM_MARKETS `[writable]` open_orders_accs - open orders for each of the spot market
185
/// 17+NUM_MARKETS..17+2*NUM_MARKETS `[]`
186
/// oracle_accs - flux aggregator feed accounts
187
PlaceOrder {
188
order: serum_dex::instruction::NewOrderInstructionV3
189
},
190
โ€‹
191
/// Settle all funds from serum dex open orders into MarginAccount positions
192
///
193
/// Accounts expected by this instruction (14):
194
///
195
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
196
/// 1. `[signer]` owner_acc - MarginAccount owner
197
/// 2. `[writable]` margin_account_acc - MarginAccount
198
/// 3. `[]` clock_acc - Clock sysvar account
199
/// 4. `[]` dex_prog_acc - program id of serum dex
200
/// 5 `[writable]` spot_market_acc - dex MarketState account
201
/// 6 `[writable]` open_orders_acc - open orders for this market for this MarginAccount
202
/// 7. `[]` signer_acc - MangoGroup signer key
203
/// 8. `[writable]` dex_base_acc - base vault for dex MarketState
204
/// 9. `[writable]` dex_quote_acc - quote vault for dex MarketState
205
/// 10. `[writable]` base_vault_acc - MangoGroup base vault acc
206
/// 11. `[writable]` quote_vault_acc - MangoGroup quote vault acc
207
/// 12. `[]` dex_signer_acc - dex Market signer account
208
/// 13. `[]` spl token program
209
SettleFunds,
210
โ€‹
211
/// Cancel an order using dex instruction
212
///
213
/// Accounts expected by this instruction (11):
214
///
215
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
216
/// 1. `[signer]` owner_acc - MarginAccount owner
217
/// 2. `[]` margin_account_acc - MarginAccount
218
/// 3. `[]` clock_acc - Clock sysvar account
219
/// 4. `[]` dex_prog_acc - program id of serum dex
220
/// 5. `[writable]` spot_market_acc - serum dex MarketState
221
/// 6. `[writable]` bids_acc - serum dex bids
222
/// 7. `[writable]` asks_acc - serum dex asks
223
/// 8. `[writable]` open_orders_acc - OpenOrders for the market this order belongs to
224
/// 9. `[]` signer_acc - MangoGroup signer key
225
/// 10. `[writable]` dex_event_queue_acc - serum dex event queue for this market
226
CancelOrder {
227
order: serum_dex::instruction::CancelOrderInstructionV2
228
},
229
โ€‹
230
/// Cancel an order using client_id
231
///
232
/// Accounts expected by this instruction (11):
233
///
234
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
235
/// 1. `[signer]` owner_acc - MarginAccount owner
236
/// 2. `[]` margin_account_acc - MarginAccount
237
/// 3. `[]` clock_acc - Clock sysvar account
238
/// 4. `[]` dex_prog_acc - program id of serum dex
239
/// 5. `[writable]` spot_market_acc - serum dex MarketState
240
/// 6. `[writable]` bids_acc - serum dex bids
241
/// 7. `[writable]` asks_acc - serum dex asks
242
/// 8. `[writable]` open_orders_acc - OpenOrders for the market this order belongs to
243
/// 9. `[]` signer_acc - MangoGroup signer key
244
/// 10. `[writable]` dex_event_queue_acc - serum dex event queue for this market
245
CancelOrderByClientId {
246
client_id: u64
247
},
248
โ€‹
249
/// Change the borrow limit using admin key. This will not affect any open positions on any MarginAccount
250
/// This is intended to be an instruction only in alpha stage while liquidity is slowly improved
251
///
252
/// Accounts expected by this instruction (2):
253
///
254
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
255
/// 1. `[signer]` admin_acc - admin of the MangoGroup
256
ChangeBorrowLimit {
257
token_index: usize,
258
borrow_limit: u64
259
},
260
โ€‹
261
/// Place an order on the Serum Dex and settle funds from the open orders account
262
///
263
/// Accounts expected by this instruction (19 + 2 * NUM_MARKETS):
264
///
265
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
266
/// 1. `[signer]` owner_acc - MarginAccount owner
267
/// 2. `[writable]` margin_account_acc - MarginAccount
268
/// 3. `[]` clock_acc - Clock sysvar account
269
/// 4. `[]` dex_prog_acc - program id of serum dex
270
/// 5. `[writable]` spot_market_acc - serum dex MarketState
271
/// 6. `[writable]` dex_request_queue_acc - serum dex request queue for this market
272
/// 7. `[writable]` dex_event_queue - serum dex event queue for this market
273
/// 8. `[writable]` bids_acc - serum dex bids for this market
274
/// 9. `[writable]` asks_acc - serum dex asks for this market
275
/// 10. `[writable]` base_vault_acc - mango vault for base currency
276
/// 11. `[writable]` quote_vault_acc - mango vault for quote currency
277
/// 12. `[]` signer_acc - mango signer key
278
/// 13. `[writable]` dex_base_acc - serum dex market's vault for base (coin) currency
279
/// 14. `[writable]` dex_quote_acc - serum dex market's vault for quote (pc) currency
280
/// 15. `[]` spl token program
281
/// 16. `[]` the rent sysvar
282
/// 17. `[writable]` srm_vault_acc - MangoGroup's srm_vault used for fee reduction
283
/// 18. `[]` dex_signer_acc - signer for serum dex MarketState
284
/// 19..19+NUM_MARKETS `[writable]` open_orders_accs - open orders for each of the spot market
285
/// 19+NUM_MARKETS..19+2*NUM_MARKETS `[]`
286
/// oracle_accs - flux aggregator feed accounts
287
PlaceAndSettle {
288
order: serum_dex::instruction::NewOrderInstructionV3
289
},
290
โ€‹
291
/// Allow a liquidator to cancel open orders and settle to recoup funds for partial liquidation
292
///
293
/// Accounts expected by this instruction (16 + 2 * NUM_MARKETS):
294
///
295
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
296
/// 1. `[signer]` liqor_acc - liquidator's solana account
297
/// 2. `[writable]` liqee_margin_account_acc - MarginAccount of liquidatee
298
/// 3. `[writable]` base_vault_acc - mango vault for base currency
299
/// 4. `[writable]` quote_vault_acc - mango vault for quote currency
300
/// 5. `[writable]` spot_market_acc - serum dex MarketState
301
/// 6. `[writable]` bids_acc - serum dex bids for this market
302
/// 7. `[writable]` asks_acc - serum dex asks for this market
303
/// 8. `[]` signer_acc - mango signer key
304
/// 9. `[writable]` dex_event_queue - serum dex event queue for this market
305
/// 10. `[writable]` dex_base_acc - serum dex market's vault for base (coin) currency
306
/// 11. `[writable]` dex_quote_acc - serum dex market's vault for quote (pc) currency
307
/// 12. `[]` dex_signer_acc - signer for serum dex MarketState
308
/// 13. `[]` token_prog_acc - SPL token program
309
/// 14. `[]` dex_prog_acc - Serum dex program id
310
/// 15. `[]` clock_acc - Clock sysvar account
311
/// 16..16+NUM_MARKETS `[writable]` open_orders_accs - open orders for each of the spot market
312
/// 16+NUM_MARKETS..16+2*NUM_MARKETS `[]`
313
/// oracle_accs - flux aggregator feed accounts
314
ForceCancelOrders {
315
/// Max orders to cancel -- could be useful to lower this if running into compute limits
316
/// Recommended: 5
317
limit: u8
318
},
319
โ€‹
320
/// Take over a MarginAccount that is below init_coll_ratio by depositing funds
321
///
322
/// Accounts expected by this instruction (10 + 2 * NUM_MARKETS):
323
///
324
/// 0. `[writable]` mango_group_acc - MangoGroup that this margin account is for
325
/// 1. `[signer]` liqor_acc - liquidator's solana account
326
/// 2. `[writable]` liqor_in_token_acc - liquidator's token account to deposit
327
/// 3. `[writable]` liqor_out_token_acc - liquidator's token account to withdraw into
328
/// 4. `[writable]` liqee_margin_account_acc - MarginAccount of liquidatee
329
/// 5. `[writable]` in_vault_acc - Mango vault of in_token
330
/// 6. `[writable]` out_vault_acc - Mango vault of out_token
331
/// 7. `[]` signer_acc
332
/// 8. `[]` token_prog_acc - Token program id
333
/// 9. `[]` clock_acc - Clock sysvar account
334
/// 10..10+NUM_MARKETS `[]` open_orders_accs - open orders for each of the spot market
335
/// 10+NUM_MARKETS..10+2*NUM_MARKETS `[]`
336
/// oracle_accs - flux aggregator feed accounts
337
PartialLiquidate {
338
/// Quantity of the token being deposited to repay borrows
339
max_deposit: u64
340
}
341
}
342
โ€‹
Copied!
Last modified 7mo ago
Copy link