@harmoniclabs/buildooor 0.1.2 → 0.1.4

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,8 +16,8 @@ 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;
20
- calcMinFee(tx: Tx): bigint;
19
+ private calcLinearFee;
20
+ calcMinFee(tx: Tx, minimum?: CanBeUInteger | undefined): bigint;
21
21
  getMinimumOutputLovelaces(tx_out: TxOut | CanBeCborString): bigint;
22
22
  addMinLovelacesIfMissing(txOut: TxOut): TxOut;
23
23
  minimizeLovelaces(out: ITxOut): TxOut;
@@ -168,10 +168,12 @@ 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
- TxBuilder.prototype.calcMinFee = function (tx) {
176
+ TxBuilder.prototype.calcMinFee = function (tx, minimum) {
175
177
  var _a;
176
178
  var totRefScriptBytes = ((_a = tx.body.refInputs) !== null && _a !== void 0 ? _a : [])
177
179
  .reduce(function (sum, refIn) {
@@ -192,10 +194,14 @@ 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;
198
- return minFee;
200
+ BigInt(nVkeyWits < 24 ? 1 : (nVkeyWits < 256 ? 2 : 4)) * minFeeMultiplier;
201
+ if (!(0, ints_1.canBeUInteger)(minimum))
202
+ return minFee;
203
+ var min = (0, ints_1.forceBigUInt)(minimum);
204
+ return minFee < min ? min : minFee;
199
205
  };
200
206
  TxBuilder.prototype.getMinimumOutputLovelaces = function (tx_out) {
201
207
  var size = BigInt(0);
@@ -407,7 +413,7 @@ var TxBuilder = /** @class */ (function () {
407
413
  for (var i = 0; i < nRdmrs; i++) {
408
414
  _loop_2(i);
409
415
  }
410
- minFee = this_1.calcMinFee(tx);
416
+ minFee = this_1.calcMinFee(tx, buildArgs.fee);
411
417
  fee = minFee +
412
418
  ((totExBudget.mem * memRational.num) / memRational.den) +
413
419
  ((totExBudget.cpu * cpuRational.num) / cpuRational.den) +
@@ -942,7 +948,7 @@ var TxBuilder = /** @class */ (function () {
942
948
  auxiliaryData: auxData,
943
949
  isScriptValid: isScriptValid
944
950
  });
945
- var minFee = this.calcMinFee(dummyTx);
951
+ var minFee = this.calcMinFee(dummyTx, args.fee);
946
952
  var txOuts = new Array(outs.length + 1);
947
953
  outs.forEach(function (txO, i) { return txOuts[i] = _this.addMinLovelacesIfMissing(txO); });
948
954
  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.4",
4
4
  "description": "Cardano transaction builder in typescript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",