Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/contracts/lrp/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TxBuilder> {
const lrpScriptRefUtxo = matchSingle(
Expand Down Expand Up @@ -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])
Expand All @@ -223,6 +228,7 @@ export async function adjustLrp(
value: serialiseLrpDatum({
...lrpDatum,
lovelacesToSpend: lrpDatum.lovelacesToSpend + lovelacesAdjustAmt,
maxPrice: newMaxPrice ? newMaxPrice : lrpDatum.maxPrice,
}),
},
addAssets(
Expand All @@ -242,5 +248,5 @@ export async function claimLrp(
lrpOutRef: OutRef,
sysParams: SystemParams,
): Promise<TxBuilder> {
return adjustLrp(lucid, lrpOutRef, 0n, sysParams);
return adjustLrp(lucid, lrpOutRef, 0n, undefined, sysParams);
}
6 changes: 3 additions & 3 deletions tests/lrp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
);

Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 16 additions & 2 deletions tests/staking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ test<MyContext>('Staking - Create Position', async ({
test<MyContext>('Staking - Adjust Position', async ({
lucid,
users,
emulator,
}: MyContext) => {
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]);
Expand All @@ -78,13 +79,15 @@ test<MyContext>('Staking - Adjust Position', async ({
1_000_000n,
systemParams,
lucid,
emulator.slot,
),
);
});

test<MyContext>('Staking - Close Position', async ({
lucid,
users,
emulator,
}: MyContext) => {
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]);
Expand All @@ -104,13 +107,19 @@ test<MyContext>('Staking - Close Position', async ({

await runAndAwaitTx(
lucid,
closeStakingPosition(myStakingPosition.utxo, systemParams, lucid),
closeStakingPosition(
myStakingPosition.utxo,
systemParams,
lucid,
emulator.slot,
),
);
});

test<MyContext>('Staking - Distribute ADA to Stakers', async ({
lucid,
users,
emulator,
}: MyContext) => {
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
const [systemParams, _] = await init(lucid, [iusdInitialAssetCfg]);
Expand Down Expand Up @@ -159,7 +168,12 @@ test<MyContext>('Staking - Distribute ADA to Stakers', async ({
() =>
runAndAwaitTx(
lucid,
closeStakingPosition(myStakingPosition.utxo, systemParams, lucid),
closeStakingPosition(
myStakingPosition.utxo,
systemParams,
lucid,
emulator.slot,
),
),
);

Expand Down