Skip to content

Commit

Permalink
Fix correct collateral percentage calculation and add initial support…
Browse files Browse the repository at this point in the history
… for PlutusV3 script (#172)

* fix: correct collateral percentage calculation and add initial support for PlutusV3 script

* fix: correct collateral percentage in Blockfrost and Maestro providers
  • Loading branch information
ilap authored Sep 20, 2024
1 parent 88ee831 commit b3efddf
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/blaze-core/src/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const hardCodedProtocolParams: ProtocolParameters = {
minPoolCost: 170000000, // The minimum pool cost.
protocolVersion: { major: 9, minor: 0 }, // The protocol version.
maxValueSize: 5000, // The maximum value size.
collateralPercentage: 150 / 100, // The collateral percentage.
collateralPercentage: 150, // The collateral percentage.
maxCollateralInputs: 3, // The maximum collateral inputs.
costModels: new Map() // The cost models.
.set(
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-emulator/src/emulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export class Emulator {

// Minimum collateral amount included
const minCollateral = BigInt(
Math.ceil(this.params.collateralPercentage * Number(body.fee())),
Math.ceil((this.params.collateralPercentage * Number(body.fee())) / 100),
);

// If any scripts have been invoked, minimum collateral must be included
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-query/src/blockfrost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class Blockfrost implements Provider {
minor: response.protocol_minor_ver,
},
maxValueSize: response.max_val_size,
collateralPercentage: response.collateral_percent / 100,
collateralPercentage: response.collateral_percent,
maxCollateralInputs: response.max_collateral_inputs,
costModels: costModels,
prices: {
Expand Down
2 changes: 1 addition & 1 deletion packages/blaze-query/src/maestro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Maestro implements Provider {
minPoolCost: params.min_stake_pool_cost.ada.lovelace,
protocolVersion: params.version,
maxValueSize: params.max_value_size.bytes,
collateralPercentage: params.collateral_percentage / 100,
collateralPercentage: params.collateral_percentage,
maxCollateralInputs: params.max_collateral_inputs,
costModels: costModels,
prices: {
Expand Down
5 changes: 3 additions & 2 deletions packages/blaze-tx/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,9 @@ export class TxBuilder {
// Calculate the total collateral based on the transaction fee and collateral percentage.
const totalCollateral = BigInt(
Math.ceil(
this.params.collateralPercentage *
Number(bigintMax(this.fee, this.minimumFee) + this.feePadding),
(this.params.collateralPercentage *
Number(bigintMax(this.fee, this.minimumFee) + this.feePadding)) /
100,
),
);
// Calculate the collateral value by summing up the amounts from collateral inputs.
Expand Down
3 changes: 2 additions & 1 deletion packages/blaze-uplc/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CborReader,
CborWriter,
CborReaderState,
PlutusV3Script,
} from "@blaze-cardano/core";
import { HexBlob } from "@blaze-cardano/core";
import { UPLCDecoder } from "./decoder";
Expand Down Expand Up @@ -123,7 +124,7 @@ export function cborToScript(cbor: string, type: ScriptType): Script {
} else if (type === "PlutusV2") {
return Script.newPlutusV2Script(new PlutusV2Script(cborHex));
} else {
throw new Error("Unsupported script type");
return Script.newPlutusV3Script(new PlutusV3Script(cborHex));
}
}
}

0 comments on commit b3efddf

Please sign in to comment.