Skip to content

Commit

Permalink
program: allow non writable ix at end of swap (#1356)
Browse files Browse the repository at this point in the history
* program: allow non writable ix at end of swap

* CHANGELOG
  • Loading branch information
crispheaney authored Dec 5, 2024
1 parent e17ae06 commit 82224b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 31 additions & 21 deletions programs/drift/src/instructions/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)?;
}
}
}

Expand Down

0 comments on commit 82224b2

Please sign in to comment.