@kaspacom/kcc20-tx-builder 0.8.0-fee.1 → 0.8.0-fee.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 +13 -0
- package/RELEASING.md +8 -7
- package/dist/cjs/engine.js +252 -0
- package/dist/cjs/engine.js.map +1 -1
- package/dist/cjs/escrow-account-setup.d.ts +53 -0
- package/dist/cjs/escrow-account-setup.js +103 -0
- package/dist/cjs/escrow-account-setup.js.map +1 -0
- package/dist/cjs/escrow-claim-plan.d.ts +74 -0
- package/dist/cjs/escrow-claim-plan.js +98 -0
- package/dist/cjs/escrow-claim-plan.js.map +1 -0
- package/dist/cjs/escrow-receipt.d.ts +103 -0
- package/dist/cjs/escrow-receipt.js +293 -0
- package/dist/cjs/escrow-receipt.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/operations.d.ts +1 -1
- package/dist/cjs/operations.js +2 -0
- package/dist/cjs/operations.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +252 -0
- package/dist/engine.js.map +1 -1
- package/dist/escrow-account-setup.d.ts +54 -0
- package/dist/escrow-account-setup.d.ts.map +1 -0
- package/dist/escrow-account-setup.js +99 -0
- package/dist/escrow-account-setup.js.map +1 -0
- package/dist/escrow-claim-plan.d.ts +75 -0
- package/dist/escrow-claim-plan.d.ts.map +1 -0
- package/dist/escrow-claim-plan.js +95 -0
- package/dist/escrow-claim-plan.js.map +1 -0
- package/dist/escrow-receipt.d.ts +104 -0
- package/dist/escrow-receipt.d.ts.map +1 -0
- package/dist/escrow-receipt.js +287 -0
- package/dist/escrow-receipt.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/operations.d.ts +1 -1
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +2 -0
- package/dist/operations.js.map +1 -1
- package/docs/COMPATIBILITY.json +1 -1
- package/docs/escrow-fees.md +47 -3
- package/package.json +3 -3
- package/src/engine.ts +292 -0
- package/src/escrow-account-setup.ts +124 -0
- package/src/escrow-claim-plan.ts +130 -0
- package/src/escrow-receipt.ts +333 -0
- package/src/index.ts +3 -0
- package/src/operations.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.0-fee.3
|
|
4
|
+
|
|
5
|
+
- Build wallet-signable fee-account genesis and one-time market binding PSKTs from the pinned escrow artifact.
|
|
6
|
+
- Keep the account's full KAS principal and lineage during binding; check current node UTXOs, signed fees and mass.
|
|
7
|
+
- Return a creation hint for the first bind, since the account state is not visible from an unspent P2SH genesis output.
|
|
8
|
+
- Keep fee-market trading, claims, rotation and new-market creation disabled in this prerelease.
|
|
9
|
+
|
|
10
|
+
## 0.8.0-fee.2
|
|
11
|
+
|
|
12
|
+
- Verify fee receipts and fee accounts against the pinned escrow artifact and fresh node UTXOs before claim construction.
|
|
13
|
+
- Plan independent protocol or creator claims while preserving the other share and matching the signed consensus commitment.
|
|
14
|
+
- Keep signing, complete transaction mass checks, and market creation disabled in this prerelease.
|
|
15
|
+
|
|
3
16
|
## 0.8.0-fee.1
|
|
4
17
|
|
|
5
18
|
- Package the pinned fee v1 contract artifacts and fixed policy manifest for integration work.
|
package/RELEASING.md
CHANGED
|
@@ -15,7 +15,8 @@ Prerelease versions use the `next` tag in both registries; stable versions use
|
|
|
15
15
|
## Publishing setup
|
|
16
16
|
|
|
17
17
|
After a successful `main` CI run, `.github/workflows/publish.yml` compares the
|
|
18
|
-
package version with the first parent of the merged commit
|
|
18
|
+
package version with the first parent of the merged commit and checks whether
|
|
19
|
+
the current version is visible on npmjs. A changed or unpublished version
|
|
19
20
|
triggers one job that packs the package once, publishes that tarball to npmjs
|
|
20
21
|
and GitHub Packages, verifies both registries, then creates the matching tag
|
|
21
22
|
and GitHub Release. A manual workflow dispatch retries a partial upload only
|
|
@@ -94,9 +95,9 @@ consumer deployment. Record any unverified operation families explicitly.
|
|
|
94
95
|
|
|
95
96
|
## Fee integration prerelease
|
|
96
97
|
|
|
97
|
-
Version `0.8.0-fee.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
Version `0.8.0-fee.3` adds fee-account creation and binding PSKTs for DEV
|
|
99
|
+
integration. Run the existing snapshot and example tests against the pinned
|
|
100
|
+
WASM before publishing it under `next`. This prerelease does not build
|
|
101
|
+
fee-market trades, claims or authority rotation. Funded fee-market journeys and
|
|
102
|
+
signed settlement construction remain required before enabling markets or
|
|
103
|
+
promoting a stable fee release.
|
package/dist/cjs/engine.js
CHANGED
|
@@ -10,6 +10,7 @@ const token_profiles_generated_js_1 = require("./token-profiles.generated.js");
|
|
|
10
10
|
const sale_common_js_1 = require("./sale-common.js");
|
|
11
11
|
const abi_js_1 = require("./abi.js");
|
|
12
12
|
const operations_js_1 = require("./operations.js");
|
|
13
|
+
const escrow_account_setup_js_1 = require("./escrow-account-setup.js");
|
|
13
14
|
const snapshot_operation_js_1 = require("./snapshot-operation.js");
|
|
14
15
|
const protocol_js_1 = require("./protocol.js");
|
|
15
16
|
const deploy_receipt_js_1 = require("./deploy-receipt.js");
|
|
@@ -335,6 +336,8 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
335
336
|
"fee-ticket.create-from-utility-burn": buildFeeTicketCreatePskt,
|
|
336
337
|
"fee-ticket.burn": buildFeeTicketBurnPskt,
|
|
337
338
|
"fee-ticket.transfer": buildFeeTicketTransferPskt,
|
|
339
|
+
"kcc20fee.create-account": buildFeeAccountCreatePskt,
|
|
340
|
+
"kcc20fee.bind-account": buildFeeAccountBindPskt,
|
|
338
341
|
"kcc20wrapper.deploy-market": buildWrapperMarketDeployPskt,
|
|
339
342
|
"kcc20wrapper.wrap": buildWrapperWrapPskt,
|
|
340
343
|
"kcc20wrapper.unwrap": buildWrapperUnwrapPskt,
|
|
@@ -372,6 +375,255 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
372
375
|
}
|
|
373
376
|
return builder(input);
|
|
374
377
|
}
|
|
378
|
+
async function buildFeeAccountCreatePskt(input) {
|
|
379
|
+
const request = input.request || {};
|
|
380
|
+
const params = request.params || {};
|
|
381
|
+
const tokenId = (0, sale_common_js_1.requireHex32)(params.tokenId, "fee account token id");
|
|
382
|
+
const owner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "fee account owner");
|
|
383
|
+
const principalSompi = parseU64(params.principalSompi, "fee account principal");
|
|
384
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
385
|
+
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
386
|
+
const priorityFee = parseU64(env.KCC20_FEE_ACCOUNT_PRIORITY_FEE_SOMPI || DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
387
|
+
const artifactKey = "KCC20FeeEscrowV1.placeholder.json";
|
|
388
|
+
const supplied = options.artifacts?.[artifactKey] ?? await options.artifactProvider?.(artifactKey);
|
|
389
|
+
const artifact = supplied?.artifact ?? supplied;
|
|
390
|
+
if (!artifact)
|
|
391
|
+
throw new Error("missing pinned fee escrow artifact");
|
|
392
|
+
const initial = (0, escrow_account_setup_js_1.buildKcc20InitialFeeAccount)({
|
|
393
|
+
artifact, tokenId, ownerSchnorrPublicKey: owner, principalSompi,
|
|
394
|
+
});
|
|
395
|
+
const kw = kaspaWasm;
|
|
396
|
+
const { Encoding, GenesisCovenantGroup, RpcClient, Transaction, TransactionOutput, covenantId, payToAddressScript, payToScriptHashScript } = kw;
|
|
397
|
+
const rpc = new RpcClient({
|
|
398
|
+
url: env.KASPA_WRPC_URL || DEFAULT_WRPC_URL,
|
|
399
|
+
encoding: Encoding.Borsh,
|
|
400
|
+
networkId: network,
|
|
401
|
+
});
|
|
402
|
+
await rpc.connect();
|
|
403
|
+
try {
|
|
404
|
+
const walletUtxos = await getUtxosByAddresses(rpc, [walletAddress]);
|
|
405
|
+
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, principalSompi + priorityFee + 10000n, [], params.fundingOutpoint);
|
|
406
|
+
const fundingAmount = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry);
|
|
407
|
+
const change = fundingAmount - principalSompi - priorityFee;
|
|
408
|
+
if (change <= 10000n)
|
|
409
|
+
throw new Error("fee account creation funding change is too small");
|
|
410
|
+
const transaction = new Transaction({
|
|
411
|
+
version: 1,
|
|
412
|
+
lockTime: 0n,
|
|
413
|
+
inputs: [{ previousOutpoint: fundingEntry.outpoint, utxo: fundingEntry,
|
|
414
|
+
sequence: 0n, sigOpCount: 0, computeBudget: 30 }],
|
|
415
|
+
outputs: [
|
|
416
|
+
new TransactionOutput(principalSompi, payToScriptHashScript(initial.redeemScript)),
|
|
417
|
+
new TransactionOutput(change, payToAddressScript(walletAddress)),
|
|
418
|
+
],
|
|
419
|
+
subnetworkId: sale_common_js_1.SUBNETWORK_ID_NATIVE,
|
|
420
|
+
gas: 0n,
|
|
421
|
+
payload: "",
|
|
422
|
+
});
|
|
423
|
+
(0, sale_common_js_1.setVersionOneInputMassFields)(transaction, 30);
|
|
424
|
+
transaction.populateGenesisCovenants([new GenesisCovenantGroup(0, [0])]);
|
|
425
|
+
transaction.finalize();
|
|
426
|
+
const accountId = transaction.outputs[0]?.covenant?.covenantId?.toString();
|
|
427
|
+
if (!accountId)
|
|
428
|
+
throw new Error("fee account genesis covenant id is missing");
|
|
429
|
+
const expectedId = covenantId(fundingEntry.outpoint, [
|
|
430
|
+
{ index: 0, output: transaction.outputs[0] },
|
|
431
|
+
]).toString();
|
|
432
|
+
if (accountId !== expectedId)
|
|
433
|
+
throw new Error("fee account genesis covenant id mismatch");
|
|
434
|
+
const feeResult = transactionWithPredictedSignedFeeChange(kw, transaction, 1, network, "fee account creation", candidate => {
|
|
435
|
+
const predicted = cloneTransactionForMassPreflight(kw, candidate, "fee account creation");
|
|
436
|
+
predicted.inputs[0].signatureScript = encodeP2pkSignatureScript((0, sale_common_js_1.bytesToHex)(dummySignatureBytes()));
|
|
437
|
+
return predicted;
|
|
438
|
+
});
|
|
439
|
+
const nonContextualMass = calculateToccataV1NonContextualMass(feeResult.predictedTransaction, "fee account creation").transactionMass;
|
|
440
|
+
const storageMass = calculateToccataStorageMass(feeResult.predictedTransaction, "fee account creation");
|
|
441
|
+
if (nonContextualMass > CONSOLIDATION_TARGET_TRANSACTION_MASS ||
|
|
442
|
+
storageMass > CONSOLIDATION_TARGET_TRANSACTION_MASS) {
|
|
443
|
+
throw (0, sale_common_js_1.kcc20PsktBuilderError)("fee account creation exceeds the signed transaction mass target", "TRANSACTION_MASS_EXCEEDED", { nonContextualMass, storageMass, targetMass: CONSOLIDATION_TARGET_TRANSACTION_MASS });
|
|
444
|
+
}
|
|
445
|
+
const finalAccountId = covenantId(fundingEntry.outpoint, [
|
|
446
|
+
{ index: 0, output: feeResult.transaction.outputs[0] },
|
|
447
|
+
]).toString();
|
|
448
|
+
if (finalAccountId !== accountId)
|
|
449
|
+
throw new Error("fee account genesis id changed after fee calculation");
|
|
450
|
+
const psktTransactionJson = feeResult.transaction.serializeToSafeJSON();
|
|
451
|
+
if (typeof psktTransactionJson !== "string")
|
|
452
|
+
throw new Error("fee account creation PSKT serialization failed");
|
|
453
|
+
return {
|
|
454
|
+
schema: OUTPUT_SCHEMA,
|
|
455
|
+
psktTransactionJson,
|
|
456
|
+
signInputs: [{ index: 0, sighashType: 1 }],
|
|
457
|
+
scripts: [],
|
|
458
|
+
submitTransactionSupported: true,
|
|
459
|
+
metadata: {
|
|
460
|
+
builderKey: "kcc20fee.create-account",
|
|
461
|
+
operation: "create-fee-account",
|
|
462
|
+
action: "genesis",
|
|
463
|
+
contract: "KCC20FeeEscrowV1",
|
|
464
|
+
network, walletAddress, tokenId, owner, accountId,
|
|
465
|
+
accountPrincipalSompi: principalSompi.toString(),
|
|
466
|
+
// Attach the broadcast txid to this hint before binding. The first
|
|
467
|
+
// spend reveals the script; until then the indexer sees only P2SH.
|
|
468
|
+
accountGenesisHint: {
|
|
469
|
+
vout: 0,
|
|
470
|
+
address: kw.addressFromScriptPublicKey(payToScriptHashScript(initial.redeemScript), network).toString(),
|
|
471
|
+
covenantIdHex: accountId,
|
|
472
|
+
scriptHashHex: initial.scriptHash,
|
|
473
|
+
amountSompiExact: principalSompi.toString(),
|
|
474
|
+
state: { ...initial.state, roleName: "account" },
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
finally {
|
|
480
|
+
await rpc.disconnect();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
async function buildFeeAccountBindPskt(input) {
|
|
484
|
+
const request = input.request || {};
|
|
485
|
+
const params = request.params || {};
|
|
486
|
+
// A genesis output has no revealed script yet. The caller keeps the
|
|
487
|
+
// creation hint, adds its accepted txid, then we check the live UTXO.
|
|
488
|
+
const indexed = params.accountGenesisHint
|
|
489
|
+
? { ...params.accountGenesisHint, status: "active", spentByTxidHex: null }
|
|
490
|
+
: params.activeAccountUtxo;
|
|
491
|
+
if (!indexed || !indexed.address)
|
|
492
|
+
throw new Error("active unbound fee account UTXO and address are required");
|
|
493
|
+
const tokenId = (0, sale_common_js_1.requireHex32)(params.tokenId, "fee account token id");
|
|
494
|
+
const accountId = (0, sale_common_js_1.requireHex32)(params.accountId, "fee account id");
|
|
495
|
+
const marketId = (0, sale_common_js_1.requireHex32)(params.marketId, "fee account market id");
|
|
496
|
+
const policyId = (0, sale_common_js_1.requireHex32)(params.policyId, "fee account policy id");
|
|
497
|
+
const owner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "fee account owner");
|
|
498
|
+
if (String(indexed.state?.owner || "").toLowerCase() !== owner) {
|
|
499
|
+
throw new Error("fee account owner does not match connected wallet");
|
|
500
|
+
}
|
|
501
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
502
|
+
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
503
|
+
const accountAddress = requireKaspaAddress(indexed.address);
|
|
504
|
+
const priorityFee = parseU64(env.KCC20_FEE_ACCOUNT_PRIORITY_FEE_SOMPI || DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
505
|
+
const computeBudget = parsePositiveNumber(env.KCC20_FEE_ACCOUNT_COMPUTE_BUDGET || 500, "computeBudget");
|
|
506
|
+
const artifactKey = "KCC20FeeEscrowV1.placeholder.json";
|
|
507
|
+
const supplied = options.artifacts?.[artifactKey] ?? await options.artifactProvider?.(artifactKey);
|
|
508
|
+
const artifact = supplied?.artifact ?? supplied;
|
|
509
|
+
if (!artifact)
|
|
510
|
+
throw new Error("missing pinned fee escrow artifact");
|
|
511
|
+
const kw = kaspaWasm;
|
|
512
|
+
const { CovenantBinding, Encoding, Hash, RpcClient, Transaction, TransactionOutput, payToAddressScript, payToScriptHashScript } = kw;
|
|
513
|
+
const rpc = new RpcClient({
|
|
514
|
+
url: env.KASPA_WRPC_URL || DEFAULT_WRPC_URL,
|
|
515
|
+
encoding: Encoding.Borsh,
|
|
516
|
+
networkId: network,
|
|
517
|
+
});
|
|
518
|
+
await rpc.connect();
|
|
519
|
+
try {
|
|
520
|
+
const [accountUtxos, walletUtxos] = await Promise.all([
|
|
521
|
+
getUtxosByAddresses(rpc, [accountAddress]),
|
|
522
|
+
getUtxosByAddresses(rpc, [walletAddress]),
|
|
523
|
+
]);
|
|
524
|
+
const txid = (0, sale_common_js_1.requireHex32)(indexed.txidHex, "fee account txid");
|
|
525
|
+
const vout = parseVout(indexed.vout, "fee account vout");
|
|
526
|
+
const accountEntry = findUtxoEntry(accountUtxos.entries, txid, vout);
|
|
527
|
+
if (!accountEntry)
|
|
528
|
+
throw new Error("unbound fee account UTXO is spent or unavailable");
|
|
529
|
+
requireMatchingCovenantId(accountEntry, accountId, "unbound fee account");
|
|
530
|
+
const spk = accountEntry.scriptPublicKey ??
|
|
531
|
+
accountEntry.entry?.scriptPublicKey ?? accountEntry.utxoEntry?.scriptPublicKey;
|
|
532
|
+
const scriptBytes = spk?.script;
|
|
533
|
+
if (!spk || !scriptBytes)
|
|
534
|
+
throw new Error("unbound fee account has no script public key");
|
|
535
|
+
const scriptHex = typeof scriptBytes === "string" ? scriptBytes : (0, sale_common_js_1.bytesToHex)(scriptBytes);
|
|
536
|
+
const plan = (0, escrow_account_setup_js_1.planKcc20FeeAccountBinding)({
|
|
537
|
+
artifact,
|
|
538
|
+
indexed,
|
|
539
|
+
live: {
|
|
540
|
+
outpoint: { transactionId: txid, index: vout },
|
|
541
|
+
amountSompi: (0, sale_common_js_1.utxoAmountSompi)(accountEntry),
|
|
542
|
+
covenantIdHex: accountId,
|
|
543
|
+
scriptPublicKey: { version: Number(spk.version), scriptHex },
|
|
544
|
+
},
|
|
545
|
+
tokenId, accountId, marketId, policyId,
|
|
546
|
+
});
|
|
547
|
+
assertScriptAddress(kw, plan.currentRedeemScript, accountAddress, network, "unbound fee account address");
|
|
548
|
+
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n, [], params.fundingOutpoint);
|
|
549
|
+
const fundingAmount = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry);
|
|
550
|
+
if (fundingAmount <= priorityFee + 10000n)
|
|
551
|
+
throw new Error("fee account binding funding change is too small");
|
|
552
|
+
const unsignedTx = new Transaction({
|
|
553
|
+
version: 1,
|
|
554
|
+
lockTime: 0n,
|
|
555
|
+
inputs: [
|
|
556
|
+
{ previousOutpoint: accountEntry.outpoint, utxo: accountEntry,
|
|
557
|
+
sequence: 0n, sigOpCount: 0, computeBudget },
|
|
558
|
+
{ previousOutpoint: fundingEntry.outpoint, utxo: fundingEntry,
|
|
559
|
+
sequence: 0n, sigOpCount: 0, computeBudget: 30 },
|
|
560
|
+
],
|
|
561
|
+
outputs: [
|
|
562
|
+
new TransactionOutput(plan.successorAmountSompi, payToScriptHashScript(plan.successorRedeemScript), new CovenantBinding(0, new Hash(accountId))),
|
|
563
|
+
new TransactionOutput(fundingAmount - priorityFee, payToAddressScript(walletAddress)),
|
|
564
|
+
],
|
|
565
|
+
subnetworkId: sale_common_js_1.SUBNETWORK_ID_NATIVE,
|
|
566
|
+
gas: 0n,
|
|
567
|
+
payload: "",
|
|
568
|
+
});
|
|
569
|
+
(0, sale_common_js_1.setVersionOneInputMassFields)(unsignedTx, computeBudget);
|
|
570
|
+
unsignedTx.inputs[1].computeBudget = 30;
|
|
571
|
+
const scripts = [{
|
|
572
|
+
inputIndex: 0,
|
|
573
|
+
scriptHex: (0, sale_common_js_1.bytesToHex)(plan.currentRedeemScript),
|
|
574
|
+
signType: 1,
|
|
575
|
+
signatureScript: {
|
|
576
|
+
mode: "ordered-args",
|
|
577
|
+
args: [
|
|
578
|
+
dataTemplateArg((0, sale_common_js_1.hexToBytes)(marketId)),
|
|
579
|
+
dataTemplateArg((0, sale_common_js_1.hexToBytes)(policyId)),
|
|
580
|
+
{ type: "signature" },
|
|
581
|
+
i64TemplateArg(0),
|
|
582
|
+
dataTemplateArg((0, abi_js_1.dispatchTagFor)(artifact, "bindMarket")),
|
|
583
|
+
],
|
|
584
|
+
},
|
|
585
|
+
}];
|
|
586
|
+
const feeResult = transactionWithPredictedSignedFeeChange(kw, unsignedTx, 1, network, "fee account binding", candidate => {
|
|
587
|
+
const serialized = candidate.serializeToSafeJSON();
|
|
588
|
+
if (typeof serialized !== "string")
|
|
589
|
+
throw new Error("fee account mass preflight serialization failed");
|
|
590
|
+
const predictedJson = transactionJsonWithScriptHints(kw, JSON.parse(serialized), scripts);
|
|
591
|
+
predictedJson.inputs[1].signatureScript = encodeP2pkSignatureScript((0, sale_common_js_1.bytesToHex)(dummySignatureBytes()));
|
|
592
|
+
return typeof kw.Transaction.deserializeFromSafeJSON === "function"
|
|
593
|
+
? kw.Transaction.deserializeFromSafeJSON(JSON.stringify(predictedJson))
|
|
594
|
+
: kw.Transaction.deserializeFromJSON(JSON.stringify(predictedJson));
|
|
595
|
+
});
|
|
596
|
+
const nonContextualMass = calculateToccataV1NonContextualMass(feeResult.predictedTransaction, "fee account binding").transactionMass;
|
|
597
|
+
const storageMass = calculateToccataStorageMass(feeResult.predictedTransaction, "fee account binding");
|
|
598
|
+
if (nonContextualMass > CONSOLIDATION_TARGET_TRANSACTION_MASS ||
|
|
599
|
+
storageMass > CONSOLIDATION_TARGET_TRANSACTION_MASS) {
|
|
600
|
+
throw (0, sale_common_js_1.kcc20PsktBuilderError)("fee account binding exceeds the signed transaction mass target", "TRANSACTION_MASS_EXCEEDED", { nonContextualMass, storageMass, targetMass: CONSOLIDATION_TARGET_TRANSACTION_MASS });
|
|
601
|
+
}
|
|
602
|
+
const transaction = feeResult.transaction;
|
|
603
|
+
const psktTransactionJson = transaction.serializeToSafeJSON();
|
|
604
|
+
if (typeof psktTransactionJson !== "string")
|
|
605
|
+
throw new Error("fee account binding PSKT serialization failed");
|
|
606
|
+
return {
|
|
607
|
+
schema: OUTPUT_SCHEMA,
|
|
608
|
+
psktTransactionJson,
|
|
609
|
+
signInputs: [{ index: 1, sighashType: 1 }],
|
|
610
|
+
scripts,
|
|
611
|
+
submitTransactionSupported: true,
|
|
612
|
+
metadata: {
|
|
613
|
+
builderKey: "kcc20fee.bind-account",
|
|
614
|
+
operation: "bind-fee-account",
|
|
615
|
+
action: "bindMarket",
|
|
616
|
+
contract: "KCC20FeeEscrowV1",
|
|
617
|
+
network, walletAddress, tokenId, accountId, marketId, policyId,
|
|
618
|
+
accountInput: `${txid}:${vout}`,
|
|
619
|
+
accountPrincipalSompi: plan.successorAmountSompi.toString(),
|
|
620
|
+
},
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
finally {
|
|
624
|
+
await rpc.disconnect();
|
|
625
|
+
}
|
|
626
|
+
}
|
|
375
627
|
async function buildFeeTicketRootUpdatePskt(input) {
|
|
376
628
|
const request = input.request || {};
|
|
377
629
|
const params = request.params || {};
|