Skip to content

Commit d16656a

Browse files
committed
chore: remove few query methods to reduce contract size
1 parent 657bbce commit d16656a

File tree

4 files changed

+227
-354
lines changed

4 files changed

+227
-354
lines changed

contracts/solana/programs/intent/src/instructions/query_accounts.rs

-239
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,6 @@ use crate::{
1010
constants::*, misc::*, order_cancel::*, order_message::*, state::*, OrderFill, SwapOrder,
1111
};
1212

13-
pub fn query_swap_accounts(
14-
ctx: Context<QueryAccountCtx>,
15-
swap_order: SwapOrder,
16-
page: u8,
17-
limit: u8,
18-
) -> Result<QueryAccountsPaginateResponse> {
19-
let config = &ctx.accounts.config;
20-
21-
let signer = Pubkey::from_str(&swap_order.creator()).unwrap();
22-
let (order_pda, _) = Pubkey::find_program_address(
23-
&[
24-
&signer.to_bytes(),
25-
swap_order.dst_nid().as_bytes(),
26-
&swap_order.amount().to_be_bytes(),
27-
&swap_order.to_amount().to_be_bytes(),
28-
],
29-
&crate::id(),
30-
);
31-
let (vault_native_pda, _) =
32-
Pubkey::find_program_address(&[VaultNative::SEED_PREFIX.as_bytes()], &crate::id());
33-
34-
let mut account_metas = vec![
35-
AccountMetadata::new_readonly(system_program::id(), false),
36-
AccountMetadata::new(config.key(), false),
37-
AccountMetadata::new(order_pda, false),
38-
];
39-
40-
if swap_order.token() == NATIVE_ADDRESS {
41-
account_metas.push(AccountMetadata::new(vault_native_pda, false));
42-
43-
account_metas.push(AccountMetadata::new_readonly(crate::id(), false));
44-
account_metas.push(AccountMetadata::new_readonly(crate::id(), false));
45-
account_metas.push(AccountMetadata::new_readonly(crate::id(), false));
46-
} else {
47-
let token_mint_address = Pubkey::from_str(&swap_order.token()).unwrap();
48-
let signer_token = get_associated_token_address(&signer, &token_mint_address);
49-
50-
let (vault_token_pda, _) = Pubkey::find_program_address(
51-
&[
52-
VAULT_TOKEN_SEED_PREFIX.as_bytes(),
53-
&token_mint_address.to_bytes(),
54-
],
55-
&crate::id(),
56-
);
57-
58-
// Vault native account (null)
59-
account_metas.push(AccountMetadata::new_readonly(crate::id(), false));
60-
61-
// Vault token account
62-
account_metas.push(AccountMetadata::new(vault_token_pda, false));
63-
64-
// Signer token account
65-
account_metas.push(AccountMetadata::new(signer_token, false));
66-
67-
// Token mint
68-
account_metas.push(AccountMetadata::new(token_mint_address, false));
69-
}
70-
71-
// Token program
72-
account_metas.push(AccountMetadata::new_readonly(Token::id(), false));
73-
74-
Ok(QueryAccountsPaginateResponse::new(
75-
account_metas,
76-
page,
77-
limit,
78-
))
79-
}
80-
8113
pub fn query_recv_message_accounts(
8214
ctx: Context<QueryAccountCtx>,
8315
src_network: String,
@@ -199,177 +131,6 @@ pub fn query_recv_message_accounts(
199131
))
200132
}
201133

202-
pub fn query_fill_accounts(
203-
ctx: Context<QueryAccountCtx>,
204-
order: SwapOrder,
205-
signer: Pubkey,
206-
solver_address: String,
207-
page: u8,
208-
limit: u8,
209-
) -> Result<QueryAccountsPaginateResponse> {
210-
let config = &ctx.accounts.config;
211-
let destination_address = Pubkey::from_str(&order.dst_address()).unwrap();
212-
213-
let (order_finished_pda, _) = Pubkey::find_program_address(&[&order.get_hash()], &crate::id());
214-
215-
let mut account_metas = vec![
216-
AccountMetadata::new_readonly(system_program::id(), false),
217-
AccountMetadata::new(config.key(), false),
218-
AccountMetadata::new(config.fee_handler, false),
219-
AccountMetadata::new(destination_address, false),
220-
AccountMetadata::new(order_finished_pda, false),
221-
];
222-
223-
if order.to_token() == NATIVE_ADDRESS {
224-
account_metas.push(AccountMetadata::new(crate::id(), false));
225-
account_metas.push(AccountMetadata::new(crate::id(), false));
226-
account_metas.push(AccountMetadata::new(crate::id(), false));
227-
account_metas.push(AccountMetadata::new(crate::id(), false));
228-
} else {
229-
let token_mint_address = Pubkey::from_str(&order.to_token()).unwrap();
230-
let fee_handler_token =
231-
get_associated_token_address(&config.fee_handler, &token_mint_address);
232-
let destination_token =
233-
get_associated_token_address(&destination_address, &token_mint_address);
234-
let signer_token = get_associated_token_address(&signer, &token_mint_address);
235-
236-
// Fee handler token account
237-
account_metas.push(AccountMetadata::new(fee_handler_token, false));
238-
239-
// Destination token account
240-
account_metas.push(AccountMetadata::new(destination_token, false));
241-
242-
// Signer token account
243-
account_metas.push(AccountMetadata::new(signer_token, false));
244-
245-
// Mint account
246-
account_metas.push(AccountMetadata::new(token_mint_address, false));
247-
}
248-
249-
// Token program
250-
account_metas.push(AccountMetadata::new(Token::id(), false));
251-
252-
// Associated token program
253-
account_metas.push(AccountMetadata::new(AssociatedToken::id(), false));
254-
255-
if order.src_nid() == order.dst_nid() {
256-
let creator = Pubkey::from_str(&order.creator()).unwrap();
257-
let solver = Pubkey::from_str(&solver_address).unwrap();
258-
259-
let (order_pda, _) = Pubkey::find_program_address(
260-
&[
261-
&creator.to_bytes(),
262-
order.dst_nid().as_bytes(),
263-
&order.amount().to_be_bytes(),
264-
&order.to_amount().to_be_bytes(),
265-
],
266-
&crate::id(),
267-
);
268-
269-
// Config account
270-
account_metas.push(AccountMetadata::new(config.key(), false));
271-
272-
// Order account
273-
account_metas.push(AccountMetadata::new(order_pda, false));
274-
275-
// Order creator account
276-
account_metas.push(AccountMetadata::new(creator, false));
277-
278-
// Solver account
279-
account_metas.push(AccountMetadata::new(solver, false));
280-
281-
if order.token() == NATIVE_ADDRESS {
282-
let (vault_native_pda, _) =
283-
Pubkey::find_program_address(&[VaultNative::SEED_PREFIX.as_bytes()], &crate::id());
284-
285-
account_metas.push(AccountMetadata::new(crate::id(), false));
286-
287-
// Vault native account
288-
account_metas.push(AccountMetadata::new(vault_native_pda, false));
289-
290-
account_metas.push(AccountMetadata::new(crate::id(), false));
291-
account_metas.push(AccountMetadata::new(crate::id(), false));
292-
} else {
293-
let token_mint_address = Pubkey::from_str(&order.token()).unwrap();
294-
let solver_token = get_associated_token_address(&solver, &token_mint_address);
295-
let (vault_token_pda, _) = Pubkey::find_program_address(
296-
&[
297-
VAULT_TOKEN_SEED_PREFIX.as_bytes(),
298-
&token_mint_address.to_bytes(),
299-
],
300-
&crate::id(),
301-
);
302-
303-
// Solver token account
304-
account_metas.push(AccountMetadata::new(solver_token, false));
305-
306-
// Vault native account (null)
307-
account_metas.push(AccountMetadata::new(crate::id(), false));
308-
309-
// Vault token account
310-
account_metas.push(AccountMetadata::new(vault_token_pda, false));
311-
312-
// Mint account
313-
account_metas.push(AccountMetadata::new(token_mint_address, false));
314-
}
315-
316-
// Token program
317-
account_metas.push(AccountMetadata::new(Token::id(), false));
318-
319-
// Associated token program
320-
account_metas.push(AccountMetadata::new(AssociatedToken::id(), false));
321-
}
322-
323-
Ok(QueryAccountsPaginateResponse::new(
324-
account_metas,
325-
page,
326-
limit,
327-
))
328-
}
329-
330-
pub fn query_cancel_accounts(
331-
ctx: Context<QueryAccountCtx>,
332-
order: SwapOrder,
333-
page: u8,
334-
limit: u8,
335-
) -> Result<QueryAccountsPaginateResponse> {
336-
let config = &ctx.accounts.config;
337-
let signer = Pubkey::from_str(&order.creator()).unwrap();
338-
339-
let (order_pda, _) = Pubkey::find_program_address(
340-
&[
341-
&signer.to_bytes(),
342-
order.dst_nid().as_bytes(),
343-
&order.amount().to_be_bytes(),
344-
&order.to_amount().to_be_bytes(),
345-
],
346-
&crate::id(),
347-
);
348-
349-
let mut account_metas = vec![
350-
AccountMetadata::new_readonly(system_program::id(), false),
351-
AccountMetadata::new(config.key(), false),
352-
AccountMetadata::new(order_pda, false),
353-
];
354-
355-
if order.src_nid() == order.dst_nid() {
356-
let (order_finished_pda, _) =
357-
Pubkey::find_program_address(&[&order.get_hash()], &crate::id());
358-
359-
// Order finished account
360-
account_metas.push(AccountMetadata::new(order_finished_pda, false));
361-
} else {
362-
// null
363-
account_metas.push(AccountMetadata::new(crate::id(), false));
364-
}
365-
366-
Ok(QueryAccountsPaginateResponse::new(
367-
account_metas,
368-
page,
369-
limit,
370-
))
371-
}
372-
373134
#[derive(Accounts)]
374135
pub struct QueryAccountCtx<'info> {
375136
pub config: Account<'info, Config>,

contracts/solana/programs/intent/src/lib.rs

-29
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,6 @@ pub mod intent {
9595
)
9696
}
9797

98-
pub fn query_swap_accounts<'info>(
99-
ctx: Context<'_, '_, '_, 'info, QueryAccountCtx<'info>>,
100-
swap_order: SwapOrder,
101-
page: u8,
102-
limit: u8,
103-
) -> Result<QueryAccountsPaginateResponse> {
104-
instructions::query_swap_accounts(ctx, swap_order, page, limit)
105-
}
106-
107-
pub fn query_fill_accounts<'info>(
108-
ctx: Context<'_, '_, '_, 'info, QueryAccountCtx<'info>>,
109-
order: SwapOrder,
110-
signer: Pubkey,
111-
solver_address: String,
112-
page: u8,
113-
limit: u8,
114-
) -> Result<QueryAccountsPaginateResponse> {
115-
instructions::query_fill_accounts(ctx, order, signer, solver_address, page, limit)
116-
}
117-
118-
pub fn query_cancel_accounts(
119-
ctx: Context<QueryAccountCtx>,
120-
order: SwapOrder,
121-
page: u8,
122-
limit: u8,
123-
) -> Result<QueryAccountsPaginateResponse> {
124-
instructions::query_cancel_accounts(ctx, order, page, limit)
125-
}
126-
12798
pub fn query_recv_message_accounts(
12899
ctx: Context<QueryAccountCtx>,
129100
src_network: String,

0 commit comments

Comments
 (0)