Переглянути джерело

spl: Add token and dex methods

armaniferrante 3 роки тому
батько
коміт
316b6b3077
2 змінених файлів з 57 додано та 0 видалено
  1. 33 0
      spl/src/dex.rs
  2. 24 0
      spl/src/token.rs

+ 33 - 0
spl/src/dex.rs

@@ -173,6 +173,7 @@ pub fn initialize_market<'info>(
 ) -> ProgramResult {
     let authority = ctx.remaining_accounts.get(0);
     let prune_authority = ctx.remaining_accounts.get(1);
+    let crank_authority = ctx.remaining_accounts.get(2);
     let ix = serum_dex::instruction::initialize_market(
         ctx.accounts.market.key,
         &ID,
@@ -182,6 +183,7 @@ pub fn initialize_market<'info>(
         ctx.accounts.pc_vault.key,
         authority.map(|r| r.key),
         prune_authority.map(|r| r.key),
+        crank_authority.map(|r| r.key),
         ctx.accounts.bids.key,
         ctx.accounts.asks.key,
         ctx.accounts.req_q.key,
@@ -199,6 +201,26 @@ pub fn initialize_market<'info>(
     Ok(())
 }
 
+pub fn prune<'info>(ctx: CpiContext<'_, '_, '_, 'info, Prune<'info>>, limit: u16) -> ProgramResult {
+    let ix = serum_dex::instruction::prune(
+        &ID,
+        ctx.accounts.market.key,
+        ctx.accounts.bids.key,
+        ctx.accounts.asks.key,
+        ctx.accounts.prune_authority.key,
+        ctx.accounts.open_orders.key,
+        ctx.accounts.open_orders_owner.key,
+        ctx.accounts.event_q.key,
+        limit,
+    )?;
+    solana_program::program::invoke_signed(
+        &ix,
+        &ToAccountInfos::to_account_infos(&ctx),
+        ctx.signer_seeds,
+    )?;
+    Ok(())
+}
+
 #[derive(Accounts)]
 pub struct NewOrderV3<'info> {
     pub market: AccountInfo<'info>,
@@ -286,6 +308,17 @@ pub struct InitializeMarket<'info> {
     pub rent: AccountInfo<'info>,
 }
 
+#[derive(Accounts)]
+pub struct Prune<'info> {
+    pub market: AccountInfo<'info>,
+    pub bids: AccountInfo<'info>,
+    pub asks: AccountInfo<'info>,
+    pub prune_authority: AccountInfo<'info>,
+    pub open_orders: AccountInfo<'info>,
+    pub open_orders_owner: AccountInfo<'info>,
+    pub event_q: AccountInfo<'info>,
+}
+
 #[derive(Clone)]
 pub struct Dex;
 

+ 24 - 0
spl/src/token.rs

@@ -244,6 +244,24 @@ pub fn set_authority<'a, 'b, 'c, 'info>(
     )
 }
 
+pub fn revoke<'info>(ctx: CpiContext<'_, '_, '_, 'info, Revoke<'info>>) -> ProgramResult {
+    let ix = spl_token::instruction::revoke(
+        &spl_token::ID,
+        ctx.accounts.to.key,
+        ctx.accounts.authority.key,
+        &[],
+    )?;
+    solana_program::program::invoke_signed(
+        &ix,
+        &[
+            ctx.accounts.to.clone(),
+            ctx.accounts.authority.clone(),
+            ctx.program.clone(),
+        ],
+        ctx.signer_seeds,
+    )
+}
+
 #[derive(Accounts)]
 pub struct Transfer<'info> {
     pub from: AccountInfo<'info>,
@@ -313,6 +331,12 @@ pub struct SetAuthority<'info> {
     pub account_or_mint: AccountInfo<'info>,
 }
 
+#[derive(Accounts)]
+pub struct Revoke<'info> {
+    pub to: AccountInfo<'info>,
+    pub authority: AccountInfo<'info>,
+}
+
 #[derive(Clone)]
 pub struct TokenAccount(spl_token::state::Account);