From 4f1becde00dca13cde023148e096df660ebd81b6 Mon Sep 17 00:00:00 2001 From: Cody Butz Date: Tue, 20 Jan 2026 10:42:58 -0500 Subject: [PATCH 1/3] Allow the adjustment of LRP max price --- src/contracts/lrp/transactions.ts | 4 +++- tests/lrp.test.ts | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/contracts/lrp/transactions.ts b/src/contracts/lrp/transactions.ts index f7488dc..0b169fb 100644 --- a/src/contracts/lrp/transactions.ts +++ b/src/contracts/lrp/transactions.ts @@ -173,6 +173,7 @@ export async function adjustLrp( * and a negative amount takes lovelaces from the LRP. */ lovelacesAdjustAmt: bigint, + newMaxPrice: OnChainDecimal | undefined, sysParams: SystemParams, ): Promise { const lrpScriptRefUtxo = matchSingle( @@ -223,6 +224,7 @@ export async function adjustLrp( value: serialiseLrpDatum({ ...lrpDatum, lovelacesToSpend: lrpDatum.lovelacesToSpend + lovelacesAdjustAmt, + maxPrice: newMaxPrice ? newMaxPrice : lrpDatum.maxPrice, }), }, addAssets( @@ -242,5 +244,5 @@ export async function claimLrp( lrpOutRef: OutRef, sysParams: SystemParams, ): Promise { - return adjustLrp(lucid, lrpOutRef, 0n, sysParams); + return adjustLrp(lucid, lrpOutRef, 0n, undefined, sysParams); } diff --git a/tests/lrp.test.ts b/tests/lrp.test.ts index 3c9ca39..9e29464 100644 --- a/tests/lrp.test.ts +++ b/tests/lrp.test.ts @@ -92,7 +92,7 @@ describe('LRP', () => { await runAndAwaitTx( context.lucid, findSingleLrp(context, sysParams, iasset, ownPkh).then((lrp) => - adjustLrp(context.lucid, lrp, -1_000_000n, sysParams), + adjustLrp(context.lucid, lrp, -1_000_000n, undefined, sysParams), ), ); @@ -118,7 +118,7 @@ describe('LRP', () => { await runAndAwaitTx( context.lucid, - adjustLrp(context.lucid, adjustedUtxo1, 5_000_000n, sysParams), + adjustLrp(context.lucid, adjustedUtxo1, 5_000_000n, undefined, sysParams), ); const adjustedUtxo2 = await findSingleLrp( @@ -327,7 +327,7 @@ describe('LRP', () => { await runAndAwaitTx( context.lucid, - adjustLrp(context.lucid, redeemedLrp, -1_000_000n, sysParams), + adjustLrp(context.lucid, redeemedLrp, -1_000_000n, undefined, sysParams), ); const adjustedLrp = await findSingleLrp(context, sysParams, iasset, ownPkh); From c9907a5cd84ceeacee6b2077ed5d76ef958d473a Mon Sep 17 00:00:00 2001 From: Cody Butz Date: Tue, 20 Jan 2026 10:47:24 -0500 Subject: [PATCH 2/3] Fix staking tests --- tests/staking.test.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/staking.test.ts b/tests/staking.test.ts index 1476a18..f6acc5f 100644 --- a/tests/staking.test.ts +++ b/tests/staking.test.ts @@ -54,6 +54,7 @@ test('Staking - Create Position', async ({ test('Staking - Adjust Position', async ({ lucid, users, + emulator, }: MyContext) => { lucid.selectWallet.fromSeed(users.admin.seedPhrase); const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]); @@ -78,6 +79,7 @@ test('Staking - Adjust Position', async ({ 1_000_000n, systemParams, lucid, + emulator.slot, ), ); }); @@ -85,6 +87,7 @@ test('Staking - Adjust Position', async ({ test('Staking - Close Position', async ({ lucid, users, + emulator, }: MyContext) => { lucid.selectWallet.fromSeed(users.admin.seedPhrase); const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]); @@ -104,13 +107,19 @@ test('Staking - Close Position', async ({ await runAndAwaitTx( lucid, - closeStakingPosition(myStakingPosition.utxo, systemParams, lucid), + closeStakingPosition( + myStakingPosition.utxo, + systemParams, + lucid, + emulator.slot, + ), ); }); test('Staking - Distribute ADA to Stakers', async ({ lucid, users, + emulator, }: MyContext) => { lucid.selectWallet.fromSeed(users.admin.seedPhrase); const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]); @@ -159,7 +168,12 @@ test('Staking - Distribute ADA to Stakers', async ({ () => runAndAwaitTx( lucid, - closeStakingPosition(myStakingPosition.utxo, systemParams, lucid), + closeStakingPosition( + myStakingPosition.utxo, + systemParams, + lucid, + emulator.slot, + ), ), ); From f33d58e29985636841fa4b64c0b17712d3a2f0c2 Mon Sep 17 00:00:00 2001 From: Cody Butz Date: Tue, 20 Jan 2026 10:48:13 -0500 Subject: [PATCH 3/3] Add max price sanity check --- src/contracts/lrp/transactions.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/contracts/lrp/transactions.ts b/src/contracts/lrp/transactions.ts index 0b169fb..9bd7f2b 100644 --- a/src/contracts/lrp/transactions.ts +++ b/src/contracts/lrp/transactions.ts @@ -213,6 +213,10 @@ export async function adjustLrp( ); } + if (newMaxPrice && newMaxPrice.getOnChainInt < 0n) { + throw new Error('Max price cannot be negative'); + } + return lucid .newTx() .readFrom([lrpScriptRefUtxo])