@kaspacom/kcc20-tx-builder 0.6.1 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.2
4
+
5
+ - Reuse authenticated profile scripts during native holder consolidation, including the independent Argent implementation.
6
+ - Use each authenticated token profile's consolidation input limit: eight for platform KCC20 and three for Argent. Keep transaction mass and signature checks. Wrapped orderbook limits are unchanged.
7
+ - Native consolidation planning now requires `tokenProfileId` from authenticated token readiness; unknown profiles fail before signing. The engine independently authenticates source scripts and does not trust requested limits.
8
+
9
+
3
10
  ## 0.6.0
4
11
 
5
12
  - Remove manual token profile review and funded proof flags from runtime capability checks.
@@ -427,7 +427,7 @@ function createKcc20PsktBuilderEngine(options) {
427
427
  }
428
428
  requireMatchingCovenantId(rootEntry, rootId, "active FeeTicket root UTXO");
429
429
  const rootOutputIndex = 0;
430
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n);
430
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n, [], request.params?.fundingOutpoint);
431
431
  const fundingInputIndex = 1;
432
432
  const fundingChangeOutputIndex = 1;
433
433
  const fundingChange = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) - priorityFee;
@@ -619,7 +619,7 @@ function createKcc20PsktBuilderEngine(options) {
619
619
  utilityInputSompi +
620
620
  10000n
621
621
  : priorityFee + 10000n;
622
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
622
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
623
623
  const fundingInputIndex = 2;
624
624
  const change = rootInputSompi +
625
625
  utilityInputSompi +
@@ -797,7 +797,7 @@ function createKcc20PsktBuilderEngine(options) {
797
797
  return entry;
798
798
  });
799
799
  const outputs = entries.map((entry, index) => new TransactionOutput((0, sale_common_js_1.utxoAmountSompi)(entry), (0, sale_common_js_1.p2pkScriptPubKey)(kw, (0, sale_common_js_1.bytesToHex)(states[index].ownerIdentifier))));
800
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n);
800
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n, [], request.params?.fundingOutpoint);
801
801
  const fundingInputIndex = entries.length;
802
802
  const fundingChangeOutputIndex = outputs.length;
803
803
  const fundingChange = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) - priorityFee;
@@ -947,7 +947,7 @@ function createKcc20PsktBuilderEngine(options) {
947
947
  ownerIdentifier: (0, sale_common_js_1.hexToBytes)(recipientOwner),
948
948
  }));
949
949
  const outputs = entries.map((entry, index) => new TransactionOutput((0, sale_common_js_1.utxoAmountSompi)(entry), payToScriptHashScript((0, sale_common_js_1.buildKcc20FeeTicketScriptForState)(artifactInfos[index].artifact.script, recipientStates[index])), new CovenantBinding(index, new Hash(ticketId))));
950
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n);
950
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n, [], request.params?.fundingOutpoint);
951
951
  const fundingInputIndex = entries.length;
952
952
  const fundingChangeOutputIndex = outputs.length;
953
953
  const fundingChange = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) - priorityFee;
@@ -1749,7 +1749,7 @@ function createKcc20PsktBuilderEngine(options) {
1749
1749
  evidence.address)
1750
1750
  throw new Error("token evidence script does not match RPC");
1751
1751
  const utxos = await getUtxosByAddresses(rpc, [walletAddress]);
1752
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(utxos.entries, deploySompi * 2n + priorityFee + 10000000n);
1752
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(utxos.entries, deploySompi * 2n + priorityFee + 10000000n, [], request.params?.fundingOutpoint);
1753
1753
  const fundingChangeOutputIndex = 2;
1754
1754
  const change = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) - deploySompi * 2n - priorityFee;
1755
1755
  if (change <= 10000n) {
@@ -2037,7 +2037,7 @@ function createKcc20PsktBuilderEngine(options) {
2037
2037
  const requiredFunding = outputSompi + priorityFee > covenantInputSompi
2038
2038
  ? outputSompi + priorityFee - covenantInputSompi + 10000n
2039
2039
  : priorityFee + 10000n;
2040
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
2040
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
2041
2041
  const fundingInputIndex = 2;
2042
2042
  const change = covenantInputSompi +
2043
2043
  (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) -
@@ -2332,7 +2332,7 @@ function createKcc20PsktBuilderEngine(options) {
2332
2332
  const requiredFunding = outputSompi + priorityFee > covenantInputSompi
2333
2333
  ? outputSompi + priorityFee - covenantInputSompi + 10000n
2334
2334
  : priorityFee + 10000n;
2335
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
2335
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
2336
2336
  const fundingInputIndex = 3;
2337
2337
  const change = covenantInputSompi +
2338
2338
  (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) -
@@ -2608,7 +2608,7 @@ function createKcc20PsktBuilderEngine(options) {
2608
2608
  const requiredFunding = outputSompi + priorityFee > covenantInputSompi
2609
2609
  ? outputSompi + priorityFee - covenantInputSompi + 10000n
2610
2610
  : priorityFee + 10000n;
2611
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
2611
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
2612
2612
  const fundingInputIndex = 1;
2613
2613
  const change = covenantInputSompi +
2614
2614
  (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) -
@@ -2890,7 +2890,7 @@ function createKcc20PsktBuilderEngine(options) {
2890
2890
  const requiredFunding = outputSompi + priorityFee > covenantInputSompi
2891
2891
  ? outputSompi + priorityFee - covenantInputSompi + 10000n
2892
2892
  : priorityFee + 10000n;
2893
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
2893
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
2894
2894
  const ticketInputIndex = ticketEntry ? 1 : -1;
2895
2895
  const fundingInputIndex = ticketEntry ? 2 : 1;
2896
2896
  const change = covenantInputSompi +
@@ -3247,7 +3247,7 @@ function createKcc20PsktBuilderEngine(options) {
3247
3247
  const requiredFunding = outputSompi + priorityFee > covenantInputSompi
3248
3248
  ? outputSompi + priorityFee - covenantInputSompi + 10000n
3249
3249
  : priorityFee + 10000n;
3250
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
3250
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
3251
3251
  const ticketInputIndex = ticketEntry ? 2 : -1;
3252
3252
  const fundingInputIndex = ticketEntry ? 3 : 2;
3253
3253
  const change = covenantInputSompi +
@@ -3628,7 +3628,7 @@ function createKcc20PsktBuilderEngine(options) {
3628
3628
  covenantInputSompi +
3629
3629
  MIN_FUNDING_CHANGE_SOMPI
3630
3630
  : priorityFee + MIN_FUNDING_CHANGE_SOMPI;
3631
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
3631
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
3632
3632
  const fundingInputIndex = resolvedLegs.length + (sharedTicketEntry ? 1 : 0);
3633
3633
  const change = covenantInputSompi +
3634
3634
  (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) -
@@ -4082,7 +4082,7 @@ function createKcc20PsktBuilderEngine(options) {
4082
4082
  : priorityFee + 10000n;
4083
4083
  let fundingEntry;
4084
4084
  try {
4085
- fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
4085
+ fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
4086
4086
  }
4087
4087
  catch (error) {
4088
4088
  if (totalSellerFundedHolderTopUpSompi > 0n) {
@@ -4568,7 +4568,7 @@ function createKcc20PsktBuilderEngine(options) {
4568
4568
  : priorityFee + 10000n;
4569
4569
  let fundingEntry;
4570
4570
  try {
4571
- fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
4571
+ fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
4572
4572
  }
4573
4573
  catch (error) {
4574
4574
  if (totalSellerFundedHolderTopUpSompi > 0n) {
@@ -4891,7 +4891,7 @@ function createKcc20PsktBuilderEngine(options) {
4891
4891
  new TransactionOutput(refundSompi, payToAddressScript(walletAddress)),
4892
4892
  ];
4893
4893
  const requiredFunding = priorityFee + MIN_FUNDING_CHANGE_SOMPI;
4894
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
4894
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
4895
4895
  const fundingInputIndex = entries.length;
4896
4896
  const change = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) - priorityFee;
4897
4897
  let fundingChangeOutputIndex = -1;
@@ -5267,7 +5267,7 @@ function createKcc20PsktBuilderEngine(options) {
5267
5267
  const requiredFunding = outputSompi + transactionFeeReserve > covenantInputSompi
5268
5268
  ? outputSompi + transactionFeeReserve - covenantInputSompi + 10000n
5269
5269
  : transactionFeeReserve + 10000n;
5270
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
5270
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
5271
5271
  const ticketInputIndex = ticketEntry ? 2 : -1;
5272
5272
  const fundingInputIndex = ticketEntry ? 3 : 2;
5273
5273
  const change = covenantInputSompi +
@@ -5546,7 +5546,7 @@ function createKcc20PsktBuilderEngine(options) {
5546
5546
  const requiredFunding = outputSompi + priorityFee > covenantInputSompi
5547
5547
  ? outputSompi + priorityFee - covenantInputSompi + 10000n
5548
5548
  : priorityFee + 10000n;
5549
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
5549
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
5550
5550
  const fundingInputIndex = 1;
5551
5551
  const change = covenantInputSompi +
5552
5552
  (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) -
@@ -5789,7 +5789,7 @@ function createKcc20PsktBuilderEngine(options) {
5789
5789
  const requiredFunding = outputSompi + priorityFee > minterInputSompi
5790
5790
  ? outputSompi + priorityFee - minterInputSompi + 10000n
5791
5791
  : priorityFee + 10000n;
5792
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
5792
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
5793
5793
  const fundingInputIndex = 1;
5794
5794
  const change = minterInputSompi +
5795
5795
  BigInt(fundingEntry.amount) -
@@ -6064,7 +6064,7 @@ function createKcc20PsktBuilderEngine(options) {
6064
6064
  minterInputSompi: BigInt(minterEntry.amount),
6065
6065
  };
6066
6066
  });
6067
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n);
6067
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n, [], request.params?.fundingOutpoint);
6068
6068
  const fundingInputIndex = resolvedLanes.length;
6069
6069
  const fundingChange = BigInt(fundingEntry.amount) - priorityFee;
6070
6070
  const outputs = resolvedLanes.map((lane, laneIndex) => tokenOutput(kaspaWasm, lane.resolvedArtifact.artifact, lane.outputState, lane.minterInputSompi, lane.spendCovenantId, laneIndex));
@@ -6206,8 +6206,16 @@ function createKcc20PsktBuilderEngine(options) {
6206
6206
  const holderUtxos = Array.isArray(params.activeHolderUtxos)
6207
6207
  ? params.activeHolderUtxos
6208
6208
  : [];
6209
- if (holderUtxos.length < 2 || holderUtxos.length > 3) {
6210
- throw new Error("between two and three KCC20 holder UTXOs are required");
6209
+ if (holderUtxos.length < 2) {
6210
+ throw new Error("at least two KCC20 holder UTXOs are required");
6211
+ }
6212
+ const maximumProfileInputs = Math.max(0, ...tokenProfiles.profiles.map((p) => p.maxTokenInputs));
6213
+ if (holderUtxos.length > maximumProfileInputs) {
6214
+ throw new Error(`consolidation exceeds the token profile input bound (${maximumProfileInputs})`);
6215
+ }
6216
+ const sourceOutpoints = holderUtxos.map((u) => `${(0, sale_common_js_1.requireHex32)(u.txidHex, "holder txid")}:${parseVout(u.vout, "holder vout")}`);
6217
+ if (new Set(sourceOutpoints).size !== holderUtxos.length) {
6218
+ throw new Error("consolidation requires distinct holder outpoints");
6211
6219
  }
6212
6220
  const covenantId = (0, sale_common_js_1.requireHex32)(params.activeHolderNativeCovenantId || params.covenantId, "canonical covenant id");
6213
6221
  const appCanonicalTokenId = (0, sale_common_js_1.requireHex32)(params.appCanonicalCovenantId || params.covenantId || covenantId, "app canonical token id");
@@ -6231,7 +6239,7 @@ function createKcc20PsktBuilderEngine(options) {
6231
6239
  }
6232
6240
  const profile = resolvedArtifacts[0].profile;
6233
6241
  if (holderUtxos.length > profile.maxTokenInputs) {
6234
- throw new Error("consolidation exceeds the token profile input bound");
6242
+ throw new Error(`consolidation exceeds the token profile input bound (${profile.maxTokenInputs})`);
6235
6243
  }
6236
6244
  const artifact = resolvedArtifacts[0].artifact;
6237
6245
  for (const peerState of states.slice(1)) {
@@ -6247,7 +6255,8 @@ function createKcc20PsktBuilderEngine(options) {
6247
6255
  const txid = (0, sale_common_js_1.requireHex32)(utxo.txidHex, `holder ${index} txid`);
6248
6256
  const vout = parseVout(utxo.vout, `holder ${index} vout`);
6249
6257
  const address = requireKaspaAddress(utxo.address);
6250
- const script = (0, sale_common_js_1.buildNativeKcc20ScriptForState)(artifact.script, states[index]);
6258
+ // Resolution already authenticated this profile's complete state layout.
6259
+ const script = resolvedArtifacts[index].script;
6251
6260
  assertScriptAddress(kw, script, address, network, `holder ${index} UTXO address`);
6252
6261
  return { txid, vout, address, script };
6253
6262
  });
@@ -6290,7 +6299,7 @@ function createKcc20PsktBuilderEngine(options) {
6290
6299
  new TransactionOutput(refundSompi, payToAddressScript(walletAddress)),
6291
6300
  ];
6292
6301
  const requiredFunding = priorityFee + MIN_FUNDING_CHANGE_SOMPI;
6293
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
6302
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
6294
6303
  const fundingInputIndex = entries.length;
6295
6304
  const change = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) - priorityFee;
6296
6305
  let fundingChangeOutputIndex = -1;
@@ -6431,7 +6440,7 @@ function createKcc20PsktBuilderEngine(options) {
6431
6440
  tokenOutput(kw, artifact, inputState, tokenOutputSompi, spendCovenantId, 0),
6432
6441
  ];
6433
6442
  const requiredFunding = priorityFee + 10000n;
6434
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
6443
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
6435
6444
  const fundingInputIndex = 1;
6436
6445
  const change = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) - priorityFee;
6437
6446
  let fundingChangeOutputIndex = -1;
@@ -6622,7 +6631,7 @@ function createKcc20PsktBuilderEngine(options) {
6622
6631
  const requiredFunding = outputSompi + priorityFee > tokenInputSompi
6623
6632
  ? outputSompi + priorityFee - tokenInputSompi + 10000n
6624
6633
  : priorityFee + 10000n;
6625
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding);
6634
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, requiredFunding, [], request.params?.fundingOutpoint);
6626
6635
  const fundingInputIndex = 1;
6627
6636
  const change = tokenInputSompi +
6628
6637
  (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) -
@@ -7017,7 +7026,7 @@ function createKcc20PsktBuilderEngine(options) {
7017
7026
  await rpc.connect();
7018
7027
  try {
7019
7028
  const utxos = await getUtxosByAddresses(rpc, [walletAddress]);
7020
- const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(utxos.entries, deploySompi + priorityFee + 10000000n);
7029
+ const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(utxos.entries, deploySompi + priorityFee + 10000000n, [], request.params?.fundingOutpoint);
7021
7030
  const created = await createTransactions({
7022
7031
  entries: [fundingEntry],
7023
7032
  outputs: [{ address: contractAddress, amount: deploySompi }],