From 82224b22a361e9c65359645176501821698aaa5d Mon Sep 17 00:00:00 2001 From: lil perp Date: Wed, 4 Dec 2024 19:31:06 -0500 Subject: [PATCH] program: allow non writable ix at end of swap (#1356) * program: allow non writable ix at end of swap * CHANGELOG --- CHANGELOG.md | 2 +- programs/drift/src/instructions/user.rs | 52 +++++++++++++++---------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 350ed86f3..b52f47e67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - program: add spot market pool ids ([#1250](https://github.com/drift-labs/protocol-v2/pull/1250)) - program: make oracle map work with different sources ([#1346](https://github.com/drift-labs/protocol-v2/pull/1346)) +- program: allow read only ix after swap ([#1356](https://github.com/drift-labs/protocol-v2/pull/1356)) ### Fixes - program: make ModifyOrderParams a bit flag and add ExcludePreviousFill ([#1357](https://github.com/drift-labs/protocol-v2/pull/1357)) - - program: fix force delete user for token 2022 ([#1358](https://github.com/drift-labs/protocol-v2/pull/1358)) ### Breaking diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index c6e92e295..97635e480 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -3174,30 +3174,40 @@ pub fn handle_begin_swap<'c: 'info, 'info>( )?; } } else { - let mut whitelisted_programs = vec![ - serum_program::id(), - AssociatedToken::id(), - jupiter_mainnet_3::ID, - jupiter_mainnet_4::ID, - jupiter_mainnet_6::ID, - ]; - if !delegate_is_signer { - whitelisted_programs.push(Token::id()); - whitelisted_programs.push(Token2022::id()); - whitelisted_programs.push(marinade_mainnet::ID); - } - validate!( - whitelisted_programs.contains(&ix.program_id), - ErrorCode::InvalidSwap, - "only allowed to pass in ixs to token, openbook, and Jupiter v3/v4/v6 programs" - )?; - - for meta in ix.accounts.iter() { + if found_end { + for meta in ix.accounts.iter() { + validate!( + meta.is_writable == false, + ErrorCode::InvalidSwap, + "instructions after swap end must not have writable accounts" + )?; + } + } else { + let mut whitelisted_programs = vec![ + serum_program::id(), + AssociatedToken::id(), + jupiter_mainnet_3::ID, + jupiter_mainnet_4::ID, + jupiter_mainnet_6::ID, + ]; + if !delegate_is_signer { + whitelisted_programs.push(Token::id()); + whitelisted_programs.push(Token2022::id()); + whitelisted_programs.push(marinade_mainnet::ID); + } validate!( - meta.pubkey != crate::id(), + whitelisted_programs.contains(&ix.program_id), ErrorCode::InvalidSwap, - "instructions between begin and end must not be drift instructions" + "only allowed to pass in ixs to token, openbook, and Jupiter v3/v4/v6 programs" )?; + + for meta in ix.accounts.iter() { + validate!( + meta.pubkey != crate::id(), + ErrorCode::InvalidSwap, + "instructions between begin and end must not be drift instructions" + )?; + } } }