Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/change output fee calc #513

Merged
merged 2 commits into from
Feb 26, 2025
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
3,989 changes: 354 additions & 3,635 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/hydra/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/hydra",
"version": "1.9.0-beta.7",
"version": "1.9.0-beta.8",
"description": "Mesh Hydra package",
"main": "./dist/index.cjs",
"browser": "./dist/index.js",
Expand All @@ -27,8 +27,8 @@
"test": "jest"
},
"dependencies": {
"@meshsdk/common": "1.9.0-beta.7",
"@meshsdk/core-cst": "1.9.0-beta.7",
"@meshsdk/common": "1.9.0-beta.8",
"@meshsdk/core-cst": "1.9.0-beta.8",
"axios": "^1.7.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/mesh-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/common",
"version": "1.9.0-beta.7",
"version": "1.9.0-beta.8",
"description": "Contains constants, types and interfaces used across the SDK and different serialization libraries",
"main": "./dist/index.cjs",
"browser": "./dist/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/mesh-contract/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/contract",
"version": "1.9.0-beta.7",
"version": "1.9.0-beta.8",
"description": "List of open-source smart contracts, complete with documentation, live demos, and end-to-end source code. https://meshjs.dev/smart-contracts",
"main": "./dist/index.cjs",
"browser": "./dist/index.js",
Expand Down Expand Up @@ -34,8 +34,8 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@meshsdk/common": "1.9.0-beta.7",
"@meshsdk/core": "1.9.0-beta.7"
"@meshsdk/common": "1.9.0-beta.8",
"@meshsdk/core": "1.9.0-beta.8"
},
"prettier": "@meshsdk/configs/prettier",
"publishConfig": {
Expand Down
6 changes: 3 additions & 3 deletions packages/mesh-core-csl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/core-csl",
"version": "1.9.0-beta.7",
"version": "1.9.0-beta.8",
"description": "Types and utilities functions between Mesh and cardano-serialization-lib",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -31,15 +31,15 @@
},
"devDependencies": {
"@meshsdk/configs": "*",
"@meshsdk/provider": "1.9.0-beta.7",
"@meshsdk/provider": "1.9.0-beta.8",
"@types/json-bigint": "^1.0.4",
"eslint": "^8.57.0",
"ts-jest": "^29.1.4",
"tsup": "^8.0.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@meshsdk/common": "1.9.0-beta.7",
"@meshsdk/common": "1.9.0-beta.8",
"@sidan-lab/sidan-csl-rs-browser": "0.9.21",
"@sidan-lab/sidan-csl-rs-nodejs": "0.9.21",
"@types/base32-encoding": "^1.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/mesh-core-cst/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meshsdk/core-cst",
"version": "1.9.0-beta.7",
"version": "1.9.0-beta.8",
"description": "Types and utilities functions between Mesh and cardano-js-sdk",
"main": "./dist/index.cjs",
"browser": "./dist/index.js",
Expand Down Expand Up @@ -45,7 +45,7 @@
"@harmoniclabs/pair": "1.0.0",
"@harmoniclabs/plutus-data": "1.2.4",
"@harmoniclabs/uplc": "1.2.4",
"@meshsdk/common": "1.9.0-beta.7",
"@meshsdk/common": "1.9.0-beta.8",
"@types/base32-encoding": "^1.0.2",
"base32-encoding": "^1.0.0",
"bech32": "^2.0.0",
Expand Down
33 changes: 17 additions & 16 deletions packages/mesh-core-cst/src/serializer/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Serialization } from "@cardano-sdk/core";
import { Serialization, setInConwayEra } from "@cardano-sdk/core";
import { HexBlob } from "@cardano-sdk/util";
import {
Cbor,
Expand Down Expand Up @@ -115,6 +115,7 @@ export class CardanoSDKSerializer implements IMeshTxSerializer {
protocolParams: Protocol;

constructor(protocolParams?: Protocol, verbose = false) {
setInConwayEra(true);
this.protocolParams = protocolParams || DEFAULT_PROTOCOL_PARAMETERS;
this.verbose = verbose;
}
Expand Down Expand Up @@ -742,9 +743,7 @@ class CardanoSDKSerializerCore {
if (output.datum?.type === "Hash") {
cardanoOutput.setDatum(
Datum.newDataHash(
DatumHash.fromHexBlob(
HexBlob(fromBuilderToPlutusData(output.datum.data).hash()),
),
DatumHash(fromBuilderToPlutusData(output.datum.data).hash()),
),
);
} else if (output.datum?.type === "Inline") {
Expand Down Expand Up @@ -809,7 +808,7 @@ class CardanoSDKSerializerCore {

referenceInputsList.push(
new TransactionInput(
TransactionId.fromHexBlob(HexBlob(refInput.txHash)),
TransactionId(refInput.txHash),
BigInt(refInput.txIndex),
),
);
Expand Down Expand Up @@ -1416,9 +1415,7 @@ class CardanoSDKSerializerCore {
remainingValue,
);

let minUtxoValue =
(160 + dummyChangeOutput.toCbor().length / 2 + 1) *
this.protocolParams.coinsPerUtxoSize;
currentOutputs.push(dummyChangeOutput);

// Create a dummy tx that we will use to calculate fees
this.txBody.setFee(BigInt("10000000"));
Expand All @@ -1438,14 +1435,11 @@ class CardanoSDKSerializerCore {
this.refScriptSize,
);

if (remainingValue.coin() >= fee + BigInt(minUtxoValue)) {
dummyChangeOutput
.amount()
.setCoin(dummyChangeOutput.amount().coin() - fee);
currentOutputs.push(dummyChangeOutput);
this.txBody.setOutputs(currentOutputs);
remainingValue = new Value(BigInt(0));
} else if (remainingValue.coin() >= fee) {
let minUtxoValue =
(160 + dummyChangeOutput.toCbor().length / 2 + 1) *
this.protocolParams.coinsPerUtxoSize;

if (remainingValue.coin() <= fee + BigInt(minUtxoValue)) {
if (
remainingValue.multiasset() &&
remainingValue.multiasset()!.size > 0
Expand All @@ -1455,6 +1449,13 @@ class CardanoSDKSerializerCore {
);
} else {
fee = remainingValue.coin();
currentOutputs.pop();
}
} else {
const changeOutput = currentOutputs.pop();
if (changeOutput) {
changeOutput.amount().setCoin(changeOutput.amount().coin() - fee);
currentOutputs.push(changeOutput);
}
}

Expand Down
12 changes: 9 additions & 3 deletions packages/mesh-core-cst/src/types/cardano-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export type TokenMap = Cardano.TokenMap;
export const Transaction = Serialization.Transaction;
export type Transaction = Serialization.Transaction;

export const TransactionId = Cardano.TransactionId;
export const TransactionId = (value: string) => {
return Cardano.TransactionId(value);
};
export type TransactionId = Cardano.TransactionId;

export const TransactionBody = Serialization.TransactionBody;
Expand Down Expand Up @@ -135,7 +137,9 @@ export type Ed25519KeyHashHex = Crypto.Ed25519KeyHashHex;
export const Hash28ByteBase16 = Crypto.Hash28ByteBase16;
export type Hash28ByteBase16 = Crypto.Hash28ByteBase16;

export const Hash32ByteBase16 = Crypto.Hash32ByteBase16;
export const Hash32ByteBase16 = (value: string) => {
return Crypto.Hash32ByteBase16(value);
};
export type Hash32ByteBase16 = Crypto.Hash32ByteBase16;

export const CredentialType = Cardano.CredentialType;
Expand Down Expand Up @@ -227,7 +231,9 @@ export type RewardAccount = Cardano.RewardAccount;
export const Hash = Serialization.Hash;
export type Hash<T extends string> = Serialization.Hash<T>;

export const DatumHash = Crypto.Hash32ByteBase16;
export const DatumHash = (value: string) => {
return Crypto.Hash32ByteBase16(value);
};
export type DatumHash = Crypto.Hash32ByteBase16;

export const Datum = Serialization.Datum;
Expand Down
2 changes: 1 addition & 1 deletion packages/mesh-core-cst/src/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export const parseInlineDatum = <T extends { inline_datum?: string }, X>(
};

export const deserializeDataHash = (dataHash: string): DatumHash =>
DatumHash.fromHexBlob(HexBlob(dataHash));
DatumHash(dataHash);

export const deserializePlutusData = (plutusData: string): PlutusData =>
PlutusData.fromCbor(HexBlob(plutusData));
6 changes: 1 addition & 5 deletions packages/mesh-core-cst/src/utils/deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ import { HexBlob } from "@cardano-sdk/util";
import { DeserializedAddress, LanguageVersion, toBytes } from "@meshsdk/common";

import {
Address,
CredentialType,
DatumHash,
Ed25519KeyHash,
NativeScript,
PlutusData,
PlutusV1Script,
PlutusV2Script,
PlutusV3Script,
Expand Down Expand Up @@ -62,4 +58,4 @@ export const deserializeTx = (tx: string): Transaction =>
Transaction.fromCbor(Serialization.TxCBOR(tx));

export const deserializeTxHash = (txHash: string): TransactionId =>
TransactionId.fromHexBlob(HexBlob(txHash));
TransactionId(txHash);
Loading