MCPcopy Create free account
hub / github.com/clockwork-xyz/examples / handler

Function handler

orca_dca/programs/orca_dca/src/instructions/dca_create.rs:84–120  ·  view source on GitHub ↗
(
    ctx: Context<'_, '_, '_, 'info, DcaCreate<'info>>,
    amount_in: u64,
    minimum_amount_out: u64,
)

Source from the content-addressed store, hash-verified

82}
83
84pub fn handler<'info>(
85 ctx: Context<'_, '_, '_, 'info, DcaCreate<'info>>,
86 amount_in: u64,
87 minimum_amount_out: u64,
88) -> Result<()> {
89 // Get accounts
90 let authority = &ctx.accounts.authority;
91 let authority_a_vault = &mut ctx.accounts.authority_a_vault;
92 let a_mint = &ctx.accounts.a_mint;
93 let b_mint = &ctx.accounts.b_mint;
94 let dca = &mut ctx.accounts.dca;
95 let token_program = &ctx.accounts.token_program;
96
97 // initialize dca account
98 dca.new(
99 authority.key(),
100 a_mint.key(),
101 b_mint.key(),
102 amount_in,
103 minimum_amount_out,
104 )?;
105
106 // Approve the dca account to spend from the authority's token account.
107 token::approve(
108 CpiContext::new(
109 token_program.to_account_info(),
110 token::Approve {
111 to: authority_a_vault.to_account_info(),
112 delegate: dca.to_account_info(),
113 authority: authority.to_account_info(),
114 },
115 ),
116 u64::MAX,
117 )?;
118
119 Ok(())
120}

Callers

nothing calls this directly

Calls 1

newMethod · 0.45

Tested by

no test coverage detected