Skip to content

Commit e226e3f

Browse files
authored
Add an option to specify lot numbers for jup swap subcommand (mvines#21)
1 parent 87d86b8 commit e226e3f

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/bin/sys.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,7 @@ async fn process_jup_swap<T: Signers>(
10241024
ui_amount: Option<f64>,
10251025
slippage_bps: u64,
10261026
lot_selection_method: LotSelectionMethod,
1027+
lot_numbers: Option<HashSet<usize>>,
10271028
signers: T,
10281029
existing_signature: Option<Signature>,
10291030
if_from_balance_exceeds: Option<u64>,
@@ -1051,6 +1052,7 @@ async fn process_jup_swap<T: Signers>(
10511052
to_token,
10521053
to_token_price,
10531054
lot_selection_method,
1055+
lot_numbers,
10541056
)?;
10551057
} else {
10561058
let amount = match ui_amount {
@@ -1228,6 +1230,7 @@ async fn process_jup_swap<T: Signers>(
12281230
to_token,
12291231
to_token_price,
12301232
lot_selection_method,
1233+
lot_numbers,
12311234
)?;
12321235

12331236
if !send_transaction_until_expired(rpc_clients, &transaction, last_valid_block_height)
@@ -5287,6 +5290,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
52875290
price exceeds this percentage"),
52885291
)
52895292
.arg(lot_selection_arg())
5293+
.arg(lot_numbers_arg())
52905294
.arg(
52915295
Arg::with_name("transaction")
52925296
.long("transaction")
@@ -6471,6 +6475,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
64716475
let address = address.expect("address");
64726476
let lot_selection_method =
64736477
value_t_or_exit!(arg_matches, "lot_selection", LotSelectionMethod);
6478+
let lot_numbers = lot_numbers_of(arg_matches, "lot_numbers");
64746479
let signature = value_t!(arg_matches, "transaction", Signature).ok();
64756480
let if_from_balance_exceeds = value_t!(arg_matches, "if_from_balance_exceeds", f64)
64766481
.ok()
@@ -6488,6 +6493,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
64886493
ui_amount,
64896494
slippage_bps,
64906495
lot_selection_method,
6496+
lot_numbers,
64916497
vec![signer],
64926498
signature,
64936499
if_from_balance_exceeds,

src/db.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub struct PendingSwap {
157157
pub to_token_price: Decimal,
158158

159159
pub lot_selection_method: LotSelectionMethod,
160+
pub lot_numbers: Option<HashSet<usize>>,
160161
}
161162

162163
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
@@ -909,6 +910,7 @@ impl Db {
909910
to_token: MaybeToken,
910911
to_token_price: Decimal,
911912
lot_selection_method: LotSelectionMethod,
913+
lot_numbers: Option<HashSet<usize>>,
912914
) -> DbResult<()> {
913915
let _ = self
914916
.get_account(address, from_token)
@@ -923,6 +925,7 @@ impl Db {
923925
to_token,
924926
to_token_price,
925927
lot_selection_method,
928+
lot_numbers,
926929
});
927930
self.save()
928931
}
@@ -940,6 +943,7 @@ impl Db {
940943
to_token,
941944
to_token_price,
942945
lot_selection_method,
946+
lot_numbers,
943947
..
944948
} = self
945949
.data
@@ -962,7 +966,8 @@ impl Db {
962966

963967
self.auto_save(false)?;
964968
if let Some((when, from_amount, to_amount)) = success {
965-
let lots = from_account.extract_lots(self, from_amount, lot_selection_method, None)?;
969+
let lots =
970+
from_account.extract_lots(self, from_amount, lot_selection_method, lot_numbers)?;
966971

967972
let to_amount_over_from_amount = to_amount as f64 / from_amount as f64;
968973
for lot in lots {

0 commit comments

Comments
 (0)