Skip to content

Commit 12a33dd

Browse files
authored
feat: optional memo (#458)
* basic server implementation * update a bunch of files * add to js sdk * python * refactor instruction extractor * refactor instruction extractor * refactor instruction extractor * add memo verif * update changelog * add tests * add char limit * fix: make backward comp change clearer * refactor test opportunities * Fixed namings.
1 parent 484ad63 commit 12a33dd

24 files changed

Lines changed: 525 additions & 250 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to the searcher sdks will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [Unreleased]
8+
9+
### Added
10+
11+
- For swap opportunities, the searcher sdks will now add a memo instruction to the bid transaction if the quote requester so desires. This allows the quote requester to track which on-chain transactions correspond to quotes they requested. [458](https://github.com/pyth-network/per/pull/458)
12+
713
## [Rust: 0.7.0, Python 0.22.0, Javascript 0.23.0] - 2025-03-25
814

915
### Changed

Cargo.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ litesvm = "0.6.0"
4444
borsh = "1.5.1"
4545
spl-associated-token-account = "6.0.0"
4646
spl-token = "7.0.0"
47+
spl-memo-client = "0.1.0"
4748
spl-token-2022 = "7.0.0"
4849

4950
# This patch disables debugging features in litesvm runtime_environments

auction-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ strum.workspace = true
5757
spl-associated-token-account = { workspace = true }
5858
spl-token = { workspace = true }
5959
mockall_double = "0.3.1"
60+
spl-memo-client = { workspace = true }
6061
spl-token-2022 = { workspace = true }
6162

6263
[dev-dependencies]

auction-server/api-types/src/opportunity.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ pub enum OpportunityParamsV1ProgramSvm {
344344

345345
/// Details about which token accounts need to be initialized and by whom
346346
token_account_initialization_configs: TokenAccountInitializationConfigs,
347+
348+
/// If provided, this memo must be included in the bid transaction as a Memo program instruction.
349+
#[schema(example = "memo")]
350+
memo: Option<String>,
347351
},
348352
}
349353

@@ -575,6 +579,9 @@ pub struct QuoteCreateV1SvmParams {
575579
/// The chain id for creating the quote.
576580
#[schema(example = "solana", value_type = String)]
577581
pub chain_id: ChainId,
582+
/// Optional memo to be included in the transaction
583+
#[schema(example = "memo")]
584+
pub memo: Option<String>,
578585
}
579586

580587
#[serde_as]
@@ -627,6 +634,14 @@ impl QuoteCreate {
627634
QuoteCreate::Svm(QuoteCreateSvm::V1(params)) => params.user_wallet_address,
628635
}
629636
}
637+
638+
pub fn get_memo_length(&self) -> Option<usize> {
639+
match self {
640+
QuoteCreate::Svm(QuoteCreateSvm::V1(params)) => {
641+
params.memo.as_ref().map(|memo| memo.len())
642+
}
643+
}
644+
}
630645
}
631646

632647
#[derive(Serialize, Deserialize, ToSchema, Clone, PartialEq, Debug)]

auction-server/src/api.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ pub enum InstructionError {
126126
InvalidTokenProgramInCreateAtaInstruction { expected: Pubkey, found: Pubkey },
127127
InvalidSystemProgramInCreateAtaInstruction(Pubkey),
128128
MissingCreateAtaInstruction(Pubkey),
129+
InvalidMemoInstructionCount { expected: usize, found: usize },
130+
InvalidMemoString { expected: String, found: String },
129131
}
130132

131133
impl std::fmt::Display for InstructionError {
@@ -258,6 +260,20 @@ impl std::fmt::Display for InstructionError {
258260
ata
259261
)
260262
}
263+
InstructionError::InvalidMemoInstructionCount { expected, found } => {
264+
write!(
265+
f,
266+
"Invalid memo instruction count. Expected: {:?} found: {:?}",
267+
expected, found
268+
)
269+
}
270+
InstructionError::InvalidMemoString { expected, found } => {
271+
write!(
272+
f,
273+
"Invalid memo string in memo instruction. Expected: {:?} found: {:?}",
274+
expected, found
275+
)
276+
}
261277
}
262278
}
263279
}

0 commit comments

Comments
 (0)