diff --git a/src/contracts/lrp/transactions.ts b/src/contracts/lrp/transactions.ts index f7488dc..9bd7f2b 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( @@ -212,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]) @@ -223,6 +228,7 @@ export async function adjustLrp( value: serialiseLrpDatum({ ...lrpDatum, lovelacesToSpend: lrpDatum.lovelacesToSpend + lovelacesAdjustAmt, + maxPrice: newMaxPrice ? newMaxPrice : lrpDatum.maxPrice, }), }, addAssets( @@ -242,5 +248,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); 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, + ), ), );