@harmoniclabs/buildooor 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { GenesisInfos, NormalizedGenesisInfos } from "./GenesisInfos.js";
2
2
  import { CostModelsToLanguageViewCborOpts } from "@harmoniclabs/cardano-costmodels-ts";
3
3
  import { Tx, Value, ValueUnits, TxOut, TxRedeemerTag, ScriptType, UTxO, TxRedeemer, TxWitnessSet, ScriptDataHash, ITxOut } from "@harmoniclabs/cardano-ledger-ts";
4
- import { CborString, CanBeCborString } from "@harmoniclabs/cbor";
4
+ import { CanBeCborString } from "@harmoniclabs/cbor";
5
5
  import { Data } from "@harmoniclabs/plutus-data";
6
6
  import { ITxBuildArgs, ITxBuildOptions, ITxBuildInput, ITxBuildSyncOptions } from "../txBuild/index.js";
7
7
  import { CanBeUInteger } from "../utils/ints.js";
@@ -16,7 +16,7 @@ export declare class TxBuilder {
16
16
  runWithProvider(provider: Partial<ITxRunnerProvider>): TxBuilderRunner;
17
17
  constructor(protocolParamters?: Readonly<TxBuilderProtocolParams>, genesisInfos?: GenesisInfos);
18
18
  keepRelevant(requestedOutputSet: Value | ValueUnits, initialUTxOSet: ITxBuildInput[], minimumLovelaceRequired?: CanBeUInteger): ITxBuildInput[];
19
- calcLinearFee(tx: Tx | CborString): bigint;
19
+ private calcLinearFee;
20
20
  calcMinFee(tx: Tx): bigint;
21
21
  getMinimumOutputLovelaces(tx_out: TxOut | CanBeCborString): bigint;
22
22
  addMinLovelacesIfMissing(txOut: TxOut): TxOut;
@@ -168,7 +168,9 @@ var TxBuilder = /** @class */ (function () {
168
168
  };
169
169
  TxBuilder.prototype.calcLinearFee = function (tx) {
170
170
  return ((0, ints_1.forceBigUInt)(this.protocolParamters.txFeePerByte) *
171
- BigInt((tx instanceof cardano_ledger_ts_1.Tx ? tx.toCbor() : tx).toBuffer().length) +
171
+ BigInt((tx instanceof cardano_ledger_ts_1.Tx ? tx.toCbor() : tx).toBuffer().length
172
+ + 2 // for good measure
173
+ ) +
172
174
  (0, ints_1.forceBigUInt)(this.protocolParamters.txFeeFixed));
173
175
  };
174
176
  TxBuilder.prototype.calcMinFee = function (tx) {
@@ -192,9 +194,10 @@ var TxBuilder = /** @class */ (function () {
192
194
  // each vkey witness has fixed size of 102 cbor bytes
193
195
  // (1 bytes cbor array tag (length 2)) + (34 cbor bytes of length 32) + (67 cbor bytes of length 64)
194
196
  // for a fixed length of 102
195
- BigInt(102) * nVkeyWits * minFeeMultiplier +
197
+ // we also add 2 for possible unwanted encoding
198
+ BigInt(104) * nVkeyWits * minFeeMultiplier +
196
199
  // we add some more bytes for the array tag
197
- BigInt(nVkeyWits < 24 ? 1 : (nVkeyWits < 256 ? 2 : 3)) * minFeeMultiplier;
200
+ BigInt(nVkeyWits < 24 ? 1 : (nVkeyWits < 256 ? 2 : 4)) * minFeeMultiplier;
198
201
  return minFee;
199
202
  };
200
203
  TxBuilder.prototype.getMinimumOutputLovelaces = function (tx_out) {
@@ -943,6 +946,8 @@ var TxBuilder = /** @class */ (function () {
943
946
  isScriptValid: isScriptValid
944
947
  });
945
948
  var minFee = this.calcMinFee(dummyTx);
949
+ if (typeof args.fee === "bigint" && args.fee > minFee)
950
+ minFee = args.fee;
946
951
  var txOuts = new Array(outs.length + 1);
947
952
  outs.forEach(function (txO, i) { return txOuts[i] = _this.addMinLovelacesIfMissing(txO); });
948
953
  var changeOutput = new cardano_ledger_ts_1.TxOut({
@@ -31,6 +31,8 @@ export interface ITxBuildArgs {
31
31
  invalidAfter?: CanBeUInteger;
32
32
  certificates?: ITxBuildCert[];
33
33
  withdrawals?: ITxBuildWithdrawal[];
34
+ /** explicitly sets the fee (if higher than calculated minFee) */
35
+ fee?: CanBeUInteger;
34
36
  /**
35
37
  * # metadata message following cip20
36
38
  *
@@ -57,6 +59,7 @@ export interface NormalizedITxBuildArgs extends ITxBuildArgs {
57
59
  invalidAfter?: CanBeUInteger;
58
60
  certificates?: NormalizedITxBuildCert[];
59
61
  withdrawals?: NormalizedITxBuildWithdrawal[];
62
+ fee?: bigint;
60
63
  /**
61
64
  * # metadata message following cip20
62
65
  *
@@ -69,6 +72,6 @@ export interface NormalizedITxBuildArgs extends ITxBuildArgs {
69
72
  currentTreasuryValue?: bigint;
70
73
  paymentToTreasury?: bigint;
71
74
  }
72
- export declare function normalizeITxBuildArgs({ inputs, change, changeAddress, outputs, readonlyRefInputs, requiredSigners, collaterals, collateralReturn, mints, invalidBefore, invalidAfter, certificates, withdrawals, memo, metadata, votingProcedures, proposalProcedures, currentTreasuryValue, paymentToTreasury }: ITxBuildArgs): NormalizedITxBuildArgs;
75
+ export declare function normalizeITxBuildArgs({ inputs, change, changeAddress, outputs, readonlyRefInputs, requiredSigners, collaterals, collateralReturn, mints, invalidBefore, invalidAfter, certificates, withdrawals, fee, memo, metadata, votingProcedures, proposalProcedures, currentTreasuryValue, paymentToTreasury }: ITxBuildArgs): NormalizedITxBuildArgs;
73
76
  /** @deprecated use `normalizeITxBuildArgs` instead */
74
77
  export declare function cloneITxBuildArgs(args: ITxBuildArgs): ITxBuildArgs;
@@ -7,11 +7,12 @@ var ITxBuildInput_1 = require("./ITxBuildInput/ITxBuildInput.js");
7
7
  var ITxBuildMint_1 = require("./ITxBuildMint.js");
8
8
  var ITxBuildOutput_1 = require("./ITxBuildOutput.js");
9
9
  var ITxBuildWithdrawal_1 = require("./ITxBuildWithdrawal.js");
10
+ var ints_1 = require("../utils/ints.js");
10
11
  var ChangeInfos_1 = require("./ChangeInfos/ChangeInfos.js");
11
12
  var ITxBuildVotingProcedure_1 = require("./ITxBuildVotingProcedure.js");
12
13
  var ITxBuildProposalProcedure_1 = require("./ITxBuildProposalProcedure.js");
13
14
  function normalizeITxBuildArgs(_a) {
14
- var inputs = _a.inputs, change = _a.change, changeAddress = _a.changeAddress, outputs = _a.outputs, readonlyRefInputs = _a.readonlyRefInputs, requiredSigners = _a.requiredSigners, collaterals = _a.collaterals, collateralReturn = _a.collateralReturn, mints = _a.mints, invalidBefore = _a.invalidBefore, invalidAfter = _a.invalidAfter, certificates = _a.certificates, withdrawals = _a.withdrawals, memo = _a.memo, metadata = _a.metadata, votingProcedures = _a.votingProcedures, proposalProcedures = _a.proposalProcedures, currentTreasuryValue = _a.currentTreasuryValue, paymentToTreasury = _a.paymentToTreasury;
15
+ var inputs = _a.inputs, change = _a.change, changeAddress = _a.changeAddress, outputs = _a.outputs, readonlyRefInputs = _a.readonlyRefInputs, requiredSigners = _a.requiredSigners, collaterals = _a.collaterals, collateralReturn = _a.collateralReturn, mints = _a.mints, invalidBefore = _a.invalidBefore, invalidAfter = _a.invalidAfter, certificates = _a.certificates, withdrawals = _a.withdrawals, fee = _a.fee, memo = _a.memo, metadata = _a.metadata, votingProcedures = _a.votingProcedures, proposalProcedures = _a.proposalProcedures, currentTreasuryValue = _a.currentTreasuryValue, paymentToTreasury = _a.paymentToTreasury;
15
16
  return {
16
17
  inputs: inputs.map(normalizeITxBuildArgsInputs),
17
18
  change: change ? (0, ChangeInfos_1.normalizeChangeInfos)(change) : undefined,
@@ -28,6 +29,7 @@ function normalizeITxBuildArgs(_a) {
28
29
  invalidAfter: invalidAfter === undefined ? undefined : BigInt(invalidAfter),
29
30
  certificates: certificates === null || certificates === void 0 ? void 0 : certificates.map(ITxBuildCert_1.normalizeITxBuildCert),
30
31
  withdrawals: withdrawals === null || withdrawals === void 0 ? void 0 : withdrawals.map(ITxBuildWithdrawal_1.normalizeITxBuildWithdrawal),
32
+ fee: (0, ints_1.canBeUInteger)(fee) ? BigInt(fee) : undefined,
31
33
  memo: memo ? String(memo) : undefined,
32
34
  metadata: metadata,
33
35
  votingProcedures: Array.isArray(votingProcedures) ?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/buildooor",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Cardano transaction builder in typescript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",