@kaspacom/kcc20-tx-builder 0.4.0 → 0.6.0
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 +12 -1
- package/README.md +2 -2
- package/RELEASING.md +19 -14
- package/artifacts/ArgentKCC20.reference.json +12428 -0
- package/artifacts/ArgentKCC20Wrapper.placeholder.json +12455 -0
- package/artifacts/KCC20.placeholder.json +1447 -1973
- package/artifacts/KCC20FeeTicket.placeholder.json +816 -1447
- package/artifacts/KCC20Orderbook.placeholder.json +1 -2
- package/artifacts/KCC20SnapshotBootstrap.placeholder.json +101 -100
- package/artifacts/KCC20SnapshotController.placeholder.json +101 -100
- package/artifacts/KCC20Vesting.placeholder.json +427 -429
- package/artifacts/KCC20Wrapper.placeholder.json +733 -734
- package/artifacts/kcc20-snapshot-bootstrap/KCC20SnapshotBootstrap.placeholder.json +101 -100
- package/artifacts/kcc20-snapshot-controller/KCC20SnapshotController.placeholder.json +101 -100
- package/artifacts/snapshot-standards.lock.json +6 -3
- package/artifacts/token-profiles.json +109 -0
- package/artifacts/token-profiles.sha256 +1 -0
- package/dist/action-source-resolver.d.ts.map +1 -1
- package/dist/action-source-resolver.js +11 -2
- package/dist/action-source-resolver.js.map +1 -1
- package/dist/artifacts.d.ts +10 -10
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/artifacts.js +10 -10
- package/dist/artifacts.js.map +1 -1
- package/dist/cjs/action-source-resolver.js +11 -2
- package/dist/cjs/action-source-resolver.js.map +1 -1
- package/dist/cjs/artifacts.d.ts +10 -10
- package/dist/cjs/artifacts.js +10 -10
- package/dist/cjs/artifacts.js.map +1 -1
- package/dist/cjs/engine.d.ts +10 -0
- package/dist/cjs/engine.js +124 -77
- package/dist/cjs/engine.js.map +1 -1
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/profile-transfer.d.ts +60 -0
- package/dist/cjs/profile-transfer.js +248 -0
- package/dist/cjs/profile-transfer.js.map +1 -0
- package/dist/cjs/snapshot-operation.d.ts +0 -1
- package/dist/cjs/snapshot-operation.js +1 -1126
- package/dist/cjs/snapshot-operation.js.map +1 -1
- package/dist/cjs/snapshot-signerless-transactions.d.ts +1 -1
- package/dist/cjs/snapshot-signerless-transactions.js +3 -6
- package/dist/cjs/snapshot-signerless-transactions.js.map +1 -1
- package/dist/cjs/snapshot-signerless.js +5 -3
- package/dist/cjs/snapshot-signerless.js.map +1 -1
- package/dist/cjs/snapshot-verification.d.ts +1 -1
- package/dist/cjs/snapshot-verification.js +16 -12
- package/dist/cjs/snapshot-verification.js.map +1 -1
- package/dist/cjs/token-authorization.d.ts +42 -0
- package/dist/cjs/token-authorization.js +93 -0
- package/dist/cjs/token-authorization.js.map +1 -0
- package/dist/cjs/token-profiles.d.ts +82 -0
- package/dist/cjs/token-profiles.generated.d.ts +3 -0
- package/dist/cjs/token-profiles.generated.js +114 -0
- package/dist/cjs/token-profiles.generated.js.map +1 -0
- package/dist/cjs/token-profiles.js +257 -0
- package/dist/cjs/token-profiles.js.map +1 -0
- package/dist/cjs/transfer-payload.d.ts +9 -0
- package/dist/cjs/transfer-payload.js +37 -0
- package/dist/cjs/transfer-payload.js.map +1 -0
- package/dist/cjs/wrapper-operation.d.ts +1 -0
- package/dist/cjs/wrapper-operation.js +1 -0
- package/dist/cjs/wrapper-operation.js.map +1 -1
- package/dist/engine.d.ts +10 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +125 -78
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/profile-transfer.d.ts +61 -0
- package/dist/profile-transfer.d.ts.map +1 -0
- package/dist/profile-transfer.js +245 -0
- package/dist/profile-transfer.js.map +1 -0
- package/dist/snapshot-operation.d.ts +0 -1
- package/dist/snapshot-operation.d.ts.map +1 -1
- package/dist/snapshot-operation.js +0 -1125
- package/dist/snapshot-operation.js.map +1 -1
- package/dist/snapshot-signerless-transactions.d.ts +1 -1
- package/dist/snapshot-signerless-transactions.d.ts.map +1 -1
- package/dist/snapshot-signerless-transactions.js +3 -6
- package/dist/snapshot-signerless-transactions.js.map +1 -1
- package/dist/snapshot-signerless.d.ts.map +1 -1
- package/dist/snapshot-signerless.js +5 -3
- package/dist/snapshot-signerless.js.map +1 -1
- package/dist/snapshot-verification.d.ts +1 -1
- package/dist/snapshot-verification.d.ts.map +1 -1
- package/dist/snapshot-verification.js +16 -12
- package/dist/snapshot-verification.js.map +1 -1
- package/dist/token-authorization.d.ts +43 -0
- package/dist/token-authorization.d.ts.map +1 -0
- package/dist/token-authorization.js +88 -0
- package/dist/token-authorization.js.map +1 -0
- package/dist/token-profiles.d.ts +83 -0
- package/dist/token-profiles.d.ts.map +1 -0
- package/dist/token-profiles.generated.d.ts +4 -0
- package/dist/token-profiles.generated.d.ts.map +1 -0
- package/dist/token-profiles.generated.js +111 -0
- package/dist/token-profiles.generated.js.map +1 -0
- package/dist/token-profiles.js +245 -0
- package/dist/token-profiles.js.map +1 -0
- package/dist/transfer-payload.d.ts +10 -0
- package/dist/transfer-payload.d.ts.map +1 -0
- package/dist/transfer-payload.js +34 -0
- package/dist/transfer-payload.js.map +1 -0
- package/dist/wrapper-operation.d.ts +1 -0
- package/dist/wrapper-operation.d.ts.map +1 -1
- package/dist/wrapper-operation.js +1 -0
- package/dist/wrapper-operation.js.map +1 -1
- package/docs/API.md +1 -1
- package/docs/COMPATIBILITY.json +24 -33
- package/docs/INTEGRATION.md +2 -2
- package/docs/LAST_CALL.md +50 -0
- package/examples/README.md +5 -2
- package/examples/backend/cli.ts +2 -1
- package/examples/frontend/main.ts +2 -1
- package/examples/shared/build.ts +3 -0
- package/examples/shared/offline-profile.ts +27 -0
- package/examples/shared/recipe-fixtures.ts +3 -2
- package/examples/test/browser.ts +2 -2
- package/examples/test/build.test.ts +21 -8
- package/examples/test/sources.test.ts +3 -2
- package/package.json +2 -2
- package/src/action-source-resolver.ts +22 -4
- package/src/artifacts.ts +12 -10
- package/src/engine.ts +208 -105
- package/src/index.ts +7 -0
- package/src/profile-transfer.ts +425 -0
- package/src/snapshot-operation.ts +59 -1731
- package/src/snapshot-signerless-transactions.ts +8 -17
- package/src/snapshot-signerless.ts +5 -3
- package/src/snapshot-verification.ts +17 -13
- package/src/token-authorization.ts +135 -0
- package/src/token-profiles.generated.ts +112 -0
- package/src/token-profiles.ts +456 -0
- package/src/transfer-payload.ts +45 -0
- package/src/wrapper-operation.ts +2 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.KCC20_SNAPSHOT_BUILDER_KEYS = void 0;
|
|
4
4
|
exports.calculateSnapshotStartRequiredFunding = calculateSnapshotStartRequiredFunding;
|
|
5
5
|
exports.createKcc20SnapshotPsktBuilder = createKcc20SnapshotPsktBuilder;
|
|
6
6
|
/* eslint-disable @typescript-eslint/ban-ts-comment, @typescript-eslint/no-unused-vars */
|
|
@@ -53,7 +53,6 @@ function snapshotFundingI64(value, label, allowZero) {
|
|
|
53
53
|
}
|
|
54
54
|
return amount;
|
|
55
55
|
}
|
|
56
|
-
exports.SNAPSHOT_CANCEL_SINK_P2SH = "d379e50f3e2203f9a92584916335bb7cd014b237ceaa8b36f1d3d80d0cc88b32";
|
|
57
56
|
function createKcc20SnapshotPsktBuilder(options) {
|
|
58
57
|
const config = options.config ?? {};
|
|
59
58
|
const transactionWithCalculatedFeeChange = options.transactionWithCalculatedFeeChange;
|
|
@@ -487,804 +486,6 @@ function createKcc20SnapshotPsktBuilder(options) {
|
|
|
487
486
|
index: unsignedInteger(source?.vout, `${label} vout`),
|
|
488
487
|
};
|
|
489
488
|
}
|
|
490
|
-
async function buildBootstrapCancellation(input) {
|
|
491
|
-
const request = input.request || {};
|
|
492
|
-
const params = request.params || {};
|
|
493
|
-
const network = networkOf(request);
|
|
494
|
-
const walletAddress = walletAddressOf(request);
|
|
495
|
-
const artifacts = await readPinnedArtifacts(params.artifactPins, false, true);
|
|
496
|
-
const template = (0, abi_js_1.templateParts)(artifacts.kcc20);
|
|
497
|
-
const base = bootstrapBaseState(params, template);
|
|
498
|
-
const migrationId = (0, sale_common_js_1.requireHex32)(params.migrationId, "migration ID");
|
|
499
|
-
const bootstrapId = (0, sale_common_js_1.requireHex32)(params.bootstrapId, "bootstrap ID");
|
|
500
|
-
const phase = String(params.bootstrapPhase || "").toUpperCase();
|
|
501
|
-
if (!["UNBOUND", "TOKEN_BOUND", "SEALED"].includes(phase)) {
|
|
502
|
-
throw new Error("bootstrap cancellation phase is not terminally cancellable");
|
|
503
|
-
}
|
|
504
|
-
const bound = phase !== "UNBOUND";
|
|
505
|
-
const tokenId = bound
|
|
506
|
-
? (0, sale_common_js_1.requireHex32)(params.tokenId, "token ID")
|
|
507
|
-
: sale_common_js_1.ZERO_HASH;
|
|
508
|
-
const beforeState = {
|
|
509
|
-
...base,
|
|
510
|
-
phase: phase === "UNBOUND" ? 0n : phase === "TOKEN_BOUND" ? 1n : 2n,
|
|
511
|
-
tokenId: (0, sale_common_js_1.hexToBytes)(tokenId),
|
|
512
|
-
shardPlanCommitment: phase === "SEALED"
|
|
513
|
-
? (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.bootstrapShardPlanCommitment, "bootstrap shard plan commitment"))
|
|
514
|
-
: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
515
|
-
activationDigest: phase === "SEALED"
|
|
516
|
-
? (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.bootstrapActivationDigest, "bootstrap activation digest"))
|
|
517
|
-
: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
518
|
-
shardCount: phase === "SEALED"
|
|
519
|
-
? positiveI64(params.bootstrapShardCount, "bootstrap shard count")
|
|
520
|
-
: 0n,
|
|
521
|
-
};
|
|
522
|
-
if (beforeState.shardCount > 8n) {
|
|
523
|
-
throw new Error("bootstrap cancellation shard count exceeds policy");
|
|
524
|
-
}
|
|
525
|
-
const bootstrapScript = buildSnapshotBootstrapScriptForState(artifacts.bootstrap, beforeState);
|
|
526
|
-
const bootstrapSource = sourceDescriptor(params.bootstrapSource, "bootstrap source", scriptAddress(bootstrapScript, network));
|
|
527
|
-
const tokenState = bound
|
|
528
|
-
? kcc20State(params.tokenSource?.state)
|
|
529
|
-
: undefined;
|
|
530
|
-
if (tokenState &&
|
|
531
|
-
(tokenState.amount !== base.totalSupply ||
|
|
532
|
-
tokenState.ownerScheme !== 4 ||
|
|
533
|
-
(0, sale_common_js_1.bytesToHex)(tokenState.owner) !== bootstrapId ||
|
|
534
|
-
(0, sale_common_js_1.bytesToHex)(tokenState.extensionCommitment) !==
|
|
535
|
-
(0, sale_common_js_1.bytesToHex)(base.holderExtensionCommitment))) {
|
|
536
|
-
throw new Error("bootstrap cancellation token source does not match");
|
|
537
|
-
}
|
|
538
|
-
const tokenScript = tokenState
|
|
539
|
-
? (0, abi_js_1.buildKcc20ScriptForState)(artifacts.kcc20, tokenState)
|
|
540
|
-
: undefined;
|
|
541
|
-
const tokenSource = tokenScript
|
|
542
|
-
? sourceDescriptor(params.tokenSource, "token source", scriptAddress(tokenScript, network))
|
|
543
|
-
: undefined;
|
|
544
|
-
if (!bound && params.tokenSource != null) {
|
|
545
|
-
throw new Error("unbound bootstrap cancellation must not include a token");
|
|
546
|
-
}
|
|
547
|
-
const sinkTokenState = tokenState
|
|
548
|
-
? {
|
|
549
|
-
amount: base.totalSupply,
|
|
550
|
-
owner: (0, sale_common_js_1.hexToBytes)(exports.SNAPSHOT_CANCEL_SINK_P2SH),
|
|
551
|
-
ownerScheme: 3,
|
|
552
|
-
borrowScheme: 0,
|
|
553
|
-
borrowGuard: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
554
|
-
extensionCommitment: base.holderExtensionCommitment,
|
|
555
|
-
}
|
|
556
|
-
: undefined;
|
|
557
|
-
const sinkTokenScript = sinkTokenState
|
|
558
|
-
? (0, abi_js_1.buildKcc20ScriptForState)(artifacts.kcc20, sinkTokenState)
|
|
559
|
-
: undefined;
|
|
560
|
-
const rpc = rpcFor(network);
|
|
561
|
-
await rpc.connect();
|
|
562
|
-
try {
|
|
563
|
-
const bootstrapPromise = rpc.getUtxosByAddresses({
|
|
564
|
-
addresses: [bootstrapSource.address],
|
|
565
|
-
});
|
|
566
|
-
const tokenPromise = tokenSource
|
|
567
|
-
? rpc.getUtxosByAddresses({ addresses: [tokenSource.address] })
|
|
568
|
-
: Promise.resolve({ entries: [] });
|
|
569
|
-
const [bootstrapUtxos, tokenUtxos, walletUtxos] = await Promise.all([
|
|
570
|
-
bootstrapPromise,
|
|
571
|
-
tokenPromise,
|
|
572
|
-
rpc.getUtxosByAddresses({ addresses: [walletAddress] }),
|
|
573
|
-
]);
|
|
574
|
-
const bootstrapEntry = findExactEntry(bootstrapUtxos.entries, bootstrapSource);
|
|
575
|
-
assertCovenantSource(bootstrapEntry, {
|
|
576
|
-
covenantId: bootstrapId,
|
|
577
|
-
script: bootstrapScript,
|
|
578
|
-
amount: base.bootstrapCellKas,
|
|
579
|
-
label: "bootstrap cancellation source",
|
|
580
|
-
});
|
|
581
|
-
const tokenEntry = tokenSource
|
|
582
|
-
? findExactEntry(tokenUtxos.entries, tokenSource)
|
|
583
|
-
: undefined;
|
|
584
|
-
if (tokenEntry) {
|
|
585
|
-
assertCovenantSource(tokenEntry, {
|
|
586
|
-
covenantId: tokenId,
|
|
587
|
-
script: tokenScript,
|
|
588
|
-
amount: base.tokenCellKas,
|
|
589
|
-
label: "bootstrap cancellation token",
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
const consumed = [bootstrapEntry, ...(tokenEntry ? [tokenEntry] : [])];
|
|
593
|
-
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(withoutOutpoints(walletUtxos.entries, consumed.map(({ outpoint }) => outpoint)), priorityFee() + 10000n, [], params.fundingOutpoint);
|
|
594
|
-
const outputs = [];
|
|
595
|
-
if (sinkTokenScript) {
|
|
596
|
-
outputs.push(new kaspaWasm.TransactionOutput(base.tokenCellKas, kaspaWasm.payToScriptHashScript(sinkTokenScript), new kaspaWasm.CovenantBinding(1, new kaspaWasm.Hash(tokenId))));
|
|
597
|
-
}
|
|
598
|
-
const sinkOutputIndex = outputs.length;
|
|
599
|
-
outputs.push(new kaspaWasm.TransactionOutput(base.bootstrapCellKas, kaspaWasm.payToScriptHashScript(Uint8Array.of(0x6a))));
|
|
600
|
-
const fundingChangeOutputIndex = appendFundingChange(outputs, [...consumed, fundingEntry], walletAddress, base.bootstrapCellKas + (bound ? base.tokenCellKas : 0n), priorityFee());
|
|
601
|
-
const inputs = [
|
|
602
|
-
covenantInput(bootstrapEntry, BOOTSTRAP_COMPUTE_BUDGET),
|
|
603
|
-
...(tokenEntry
|
|
604
|
-
? [covenantInput(tokenEntry, KCC20_COMPUTE_BUDGET)]
|
|
605
|
-
: []),
|
|
606
|
-
publicInput(fundingEntry, PUBLIC_INPUT_COMPUTE_BUDGET),
|
|
607
|
-
];
|
|
608
|
-
const transaction = new kaspaWasm.Transaction({
|
|
609
|
-
version: 1,
|
|
610
|
-
lockTime: 0n,
|
|
611
|
-
inputs,
|
|
612
|
-
outputs,
|
|
613
|
-
subnetworkId: NATIVE_SUBNETWORK_ID,
|
|
614
|
-
gas: 0n,
|
|
615
|
-
payload: "",
|
|
616
|
-
});
|
|
617
|
-
(0, sale_common_js_1.setVersionOneInputMassFields)(transaction, PUBLIC_INPUT_COMPUTE_BUDGET);
|
|
618
|
-
transaction.inputs[0].computeBudget = BOOTSTRAP_COMPUTE_BUDGET;
|
|
619
|
-
if (tokenEntry) {
|
|
620
|
-
transaction.inputs[1].computeBudget = KCC20_COMPUTE_BUDGET;
|
|
621
|
-
}
|
|
622
|
-
const recipes = bootstrapApprovalRecipes((0, sale_common_js_1.bytesToHex)(bootstrapScript), bootstrapCancellationArgs(artifacts, bound, sinkOutputIndex, sinkTokenState));
|
|
623
|
-
transaction.inputs[0].signatureScript = encodeP2sh(signatureScriptArgsBytes(recipes.placeholder.args), bootstrapScript);
|
|
624
|
-
if (tokenEntry && tokenScript && sinkTokenState) {
|
|
625
|
-
transaction.inputs[1].signatureScript = encodeP2sh((0, abi_js_1.buildKcc20TransferSigScript)(kaspaWasm, artifacts.kcc20, {
|
|
626
|
-
nextStates: [sinkTokenState],
|
|
627
|
-
witness: Uint8Array.of(0),
|
|
628
|
-
}), tokenScript);
|
|
629
|
-
}
|
|
630
|
-
const fundingInputIndex = inputs.length - 1;
|
|
631
|
-
const adjusted = transactionWithCalculatedFeeChange(kaspaWasm, transaction, fundingChangeOutputIndex, network, "snapshot bootstrap cancellation", [recipes.approval]);
|
|
632
|
-
return outputEnvelope(adjusted, [{ index: fundingInputIndex }], [recipes.approval], {
|
|
633
|
-
migrationId,
|
|
634
|
-
stage: "bootstrap-cancel",
|
|
635
|
-
bootstrapId,
|
|
636
|
-
...(bound ? { tokenId } : {}),
|
|
637
|
-
cancellationMode: bound ? "BOUND" : "UNBOUND",
|
|
638
|
-
cancellationSinkP2sh: exports.SNAPSHOT_CANCEL_SINK_P2SH,
|
|
639
|
-
bootstrapState: {
|
|
640
|
-
...bootstrapStateReceipt(beforeState),
|
|
641
|
-
phase,
|
|
642
|
-
},
|
|
643
|
-
bootstrapOutcome: "CANCELLED",
|
|
644
|
-
maximumFeeSompi: feeOf(adjusted).toString(),
|
|
645
|
-
intentInputs: [
|
|
646
|
-
{
|
|
647
|
-
role: "snapshot-bootstrap",
|
|
648
|
-
index: 0,
|
|
649
|
-
covenantId: bootstrapId,
|
|
650
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(bootstrapScript),
|
|
651
|
-
},
|
|
652
|
-
...(tokenEntry && tokenScript
|
|
653
|
-
? [
|
|
654
|
-
{
|
|
655
|
-
role: "fixed-supply-token",
|
|
656
|
-
index: 1,
|
|
657
|
-
covenantId: tokenId,
|
|
658
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(tokenScript),
|
|
659
|
-
staticSignatureScriptHex: signatureScriptHex(adjusted, 1),
|
|
660
|
-
},
|
|
661
|
-
]
|
|
662
|
-
: []),
|
|
663
|
-
{ role: "creator-funding", index: fundingInputIndex },
|
|
664
|
-
],
|
|
665
|
-
intentOutputs: [
|
|
666
|
-
...(sinkTokenScript && sinkTokenState
|
|
667
|
-
? [
|
|
668
|
-
{
|
|
669
|
-
role: "cancelled-token",
|
|
670
|
-
index: 0,
|
|
671
|
-
covenantId: tokenId,
|
|
672
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(sinkTokenScript),
|
|
673
|
-
owner: exports.SNAPSHOT_CANCEL_SINK_P2SH,
|
|
674
|
-
ownerScheme: 3,
|
|
675
|
-
borrowScheme: 0,
|
|
676
|
-
borrowGuard: sale_common_js_1.ZERO_HASH,
|
|
677
|
-
extensionCommitment: (0, sale_common_js_1.bytesToHex)(sinkTokenState.extensionCommitment),
|
|
678
|
-
tokenAmount: sinkTokenState.amount.toString(),
|
|
679
|
-
},
|
|
680
|
-
]
|
|
681
|
-
: []),
|
|
682
|
-
{
|
|
683
|
-
role: "cancellation-sink",
|
|
684
|
-
index: sinkOutputIndex,
|
|
685
|
-
revealScriptHex: "6a",
|
|
686
|
-
},
|
|
687
|
-
],
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
finally {
|
|
691
|
-
await rpc.disconnect();
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
async function buildBootstrapBind(input) {
|
|
695
|
-
const request = input.request || {};
|
|
696
|
-
const params = request.params || {};
|
|
697
|
-
const network = networkOf(request);
|
|
698
|
-
const walletAddress = walletAddressOf(request);
|
|
699
|
-
const artifacts = await readPinnedArtifacts(params.artifactPins, false, true);
|
|
700
|
-
const template = (0, abi_js_1.templateParts)(artifacts.kcc20);
|
|
701
|
-
const base = bootstrapBaseState(params, template);
|
|
702
|
-
const bootstrapId = (0, sale_common_js_1.requireHex32)(params.bootstrapId, "bootstrap ID");
|
|
703
|
-
const tokenId = (0, sale_common_js_1.requireHex32)(params.tokenId, "token ID");
|
|
704
|
-
const tokenState = kcc20State(params.tokenSource?.state);
|
|
705
|
-
if (tokenState.amount !== base.totalSupply ||
|
|
706
|
-
tokenState.ownerScheme !== 4 ||
|
|
707
|
-
(0, sale_common_js_1.bytesToHex)(tokenState.owner) !== bootstrapId ||
|
|
708
|
-
(0, sale_common_js_1.bytesToHex)(tokenState.extensionCommitment) !==
|
|
709
|
-
(0, sale_common_js_1.bytesToHex)(base.holderExtensionCommitment)) {
|
|
710
|
-
throw new Error("bootstrap bind token source does not match the migration");
|
|
711
|
-
}
|
|
712
|
-
const beforeState = {
|
|
713
|
-
...base,
|
|
714
|
-
phase: 0n,
|
|
715
|
-
tokenId: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
716
|
-
shardPlanCommitment: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
717
|
-
activationDigest: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
718
|
-
shardCount: 0n,
|
|
719
|
-
};
|
|
720
|
-
const afterState = {
|
|
721
|
-
...base,
|
|
722
|
-
phase: 1n,
|
|
723
|
-
tokenId: (0, sale_common_js_1.hexToBytes)(tokenId),
|
|
724
|
-
shardPlanCommitment: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
725
|
-
activationDigest: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
726
|
-
shardCount: 0n,
|
|
727
|
-
};
|
|
728
|
-
const bootstrapScript = buildSnapshotBootstrapScriptForState(artifacts.bootstrap, beforeState);
|
|
729
|
-
const nextBootstrapScript = buildSnapshotBootstrapScriptForState(artifacts.bootstrap, afterState);
|
|
730
|
-
const tokenScript = (0, abi_js_1.buildKcc20ScriptForState)(artifacts.kcc20, tokenState);
|
|
731
|
-
const bootstrapSource = sourceDescriptor(params.bootstrapSource, "bootstrap source", scriptAddress(bootstrapScript, network));
|
|
732
|
-
const tokenSource = sourceDescriptor(params.tokenSource, "token source", scriptAddress(tokenScript, network));
|
|
733
|
-
const rpc = rpcFor(network);
|
|
734
|
-
await rpc.connect();
|
|
735
|
-
try {
|
|
736
|
-
const [bootstrapUtxos, tokenUtxos, walletUtxos] = await Promise.all([
|
|
737
|
-
rpc.getUtxosByAddresses({ addresses: [bootstrapSource.address] }),
|
|
738
|
-
rpc.getUtxosByAddresses({ addresses: [tokenSource.address] }),
|
|
739
|
-
rpc.getUtxosByAddresses({ addresses: [walletAddress] }),
|
|
740
|
-
]);
|
|
741
|
-
const bootstrapEntry = findExactEntry(bootstrapUtxos.entries, bootstrapSource);
|
|
742
|
-
assertCovenantSource(bootstrapEntry, {
|
|
743
|
-
covenantId: bootstrapId,
|
|
744
|
-
script: bootstrapScript,
|
|
745
|
-
amount: base.bootstrapCellKas,
|
|
746
|
-
label: "bootstrap bind source",
|
|
747
|
-
});
|
|
748
|
-
const tokenEntry = findExactEntry(tokenUtxos.entries, tokenSource);
|
|
749
|
-
assertCovenantSource(tokenEntry, {
|
|
750
|
-
covenantId: tokenId,
|
|
751
|
-
script: tokenScript,
|
|
752
|
-
amount: base.tokenCellKas,
|
|
753
|
-
label: "bootstrap bind token source",
|
|
754
|
-
});
|
|
755
|
-
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(withoutOutpoints(walletUtxos.entries, [
|
|
756
|
-
bootstrapEntry.outpoint,
|
|
757
|
-
tokenEntry.outpoint,
|
|
758
|
-
]), priorityFee() + 10000n, [], params.fundingOutpoint);
|
|
759
|
-
const outputs = [
|
|
760
|
-
new kaspaWasm.TransactionOutput(base.tokenCellKas, kaspaWasm.payToScriptHashScript(tokenScript), new kaspaWasm.CovenantBinding(1, new kaspaWasm.Hash(tokenId))),
|
|
761
|
-
new kaspaWasm.TransactionOutput(base.bootstrapCellKas, kaspaWasm.payToScriptHashScript(nextBootstrapScript), new kaspaWasm.CovenantBinding(0, new kaspaWasm.Hash(bootstrapId))),
|
|
762
|
-
];
|
|
763
|
-
const fundingChangeOutputIndex = appendFundingChange(outputs, [bootstrapEntry, tokenEntry, fundingEntry], walletAddress, base.tokenCellKas + base.bootstrapCellKas, priorityFee());
|
|
764
|
-
const transaction = new kaspaWasm.Transaction({
|
|
765
|
-
version: 1,
|
|
766
|
-
lockTime: 0n,
|
|
767
|
-
inputs: [
|
|
768
|
-
covenantInput(bootstrapEntry, BOOTSTRAP_COMPUTE_BUDGET),
|
|
769
|
-
covenantInput(tokenEntry, KCC20_COMPUTE_BUDGET),
|
|
770
|
-
publicInput(fundingEntry, PUBLIC_INPUT_COMPUTE_BUDGET),
|
|
771
|
-
],
|
|
772
|
-
outputs,
|
|
773
|
-
subnetworkId: NATIVE_SUBNETWORK_ID,
|
|
774
|
-
gas: 0n,
|
|
775
|
-
payload: "",
|
|
776
|
-
});
|
|
777
|
-
(0, sale_common_js_1.setVersionOneInputMassFields)(transaction, PUBLIC_INPUT_COMPUTE_BUDGET);
|
|
778
|
-
transaction.inputs[0].computeBudget = BOOTSTRAP_COMPUTE_BUDGET;
|
|
779
|
-
transaction.inputs[1].computeBudget = KCC20_COMPUTE_BUDGET;
|
|
780
|
-
const recipes = bootstrapApprovalRecipes((0, sale_common_js_1.bytesToHex)(bootstrapScript), bootstrapBindArgs(artifacts, afterState, tokenState));
|
|
781
|
-
transaction.inputs[0].signatureScript = encodeP2sh(signatureScriptArgsBytes(recipes.placeholder.args), bootstrapScript);
|
|
782
|
-
transaction.inputs[1].signatureScript = encodeP2sh((0, abi_js_1.buildKcc20TransferSigScript)(kaspaWasm, artifacts.kcc20, {
|
|
783
|
-
nextStates: [tokenState],
|
|
784
|
-
witness: Uint8Array.of(0),
|
|
785
|
-
}), tokenScript);
|
|
786
|
-
const adjusted = transactionWithCalculatedFeeChange(kaspaWasm, transaction, fundingChangeOutputIndex, network, "snapshot bootstrap bind", [recipes.approval]);
|
|
787
|
-
return outputEnvelope(adjusted, [{ index: 2 }], [recipes.approval], {
|
|
788
|
-
migrationId: (0, sale_common_js_1.requireHex32)(params.migrationId, "migration ID"),
|
|
789
|
-
stage: "bootstrap-bind",
|
|
790
|
-
tokenId,
|
|
791
|
-
bootstrapId,
|
|
792
|
-
bootstrapState: {
|
|
793
|
-
...bootstrapStateReceipt(afterState),
|
|
794
|
-
phase: "TOKEN_BOUND",
|
|
795
|
-
},
|
|
796
|
-
maximumFeeSompi: feeOf(adjusted).toString(),
|
|
797
|
-
intentInputs: [
|
|
798
|
-
{
|
|
799
|
-
role: "snapshot-bootstrap",
|
|
800
|
-
index: 0,
|
|
801
|
-
covenantId: bootstrapId,
|
|
802
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(bootstrapScript),
|
|
803
|
-
},
|
|
804
|
-
{
|
|
805
|
-
role: "fixed-supply-token",
|
|
806
|
-
index: 1,
|
|
807
|
-
covenantId: tokenId,
|
|
808
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(tokenScript),
|
|
809
|
-
staticSignatureScriptHex: signatureScriptHex(adjusted, 1),
|
|
810
|
-
},
|
|
811
|
-
{ role: "creator-funding", index: 2 },
|
|
812
|
-
],
|
|
813
|
-
intentOutputs: [
|
|
814
|
-
{
|
|
815
|
-
role: "fixed-supply-token",
|
|
816
|
-
index: 0,
|
|
817
|
-
covenantId: tokenId,
|
|
818
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(tokenScript),
|
|
819
|
-
owner: bootstrapId,
|
|
820
|
-
ownerScheme: 4,
|
|
821
|
-
borrowScheme: 0,
|
|
822
|
-
borrowGuard: (0, sale_common_js_1.bytesToHex)(tokenState.borrowGuard),
|
|
823
|
-
extensionCommitment: (0, sale_common_js_1.bytesToHex)(tokenState.extensionCommitment),
|
|
824
|
-
tokenAmount: tokenState.amount.toString(),
|
|
825
|
-
},
|
|
826
|
-
{
|
|
827
|
-
role: "snapshot-bootstrap",
|
|
828
|
-
index: 1,
|
|
829
|
-
covenantId: bootstrapId,
|
|
830
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(nextBootstrapScript),
|
|
831
|
-
},
|
|
832
|
-
],
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
finally {
|
|
836
|
-
await rpc.disconnect();
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
async function buildBootstrapSeal(input) {
|
|
840
|
-
const request = input.request || {};
|
|
841
|
-
const params = request.params || {};
|
|
842
|
-
const network = networkOf(request);
|
|
843
|
-
const walletAddress = walletAddressOf(request);
|
|
844
|
-
const artifacts = await readPinnedArtifacts(params.artifactPins, false, true);
|
|
845
|
-
const template = (0, abi_js_1.templateParts)(artifacts.kcc20);
|
|
846
|
-
const base = bootstrapBaseState(params, template);
|
|
847
|
-
const migrationId = (0, sale_common_js_1.requireHex32)(params.migrationId, "migration ID");
|
|
848
|
-
const bootstrapId = (0, sale_common_js_1.requireHex32)(params.bootstrapId, "bootstrap ID");
|
|
849
|
-
const tokenId = (0, sale_common_js_1.requireHex32)(params.tokenId, "token ID");
|
|
850
|
-
const shards = reserveShards(params.shards, base.totalSupply);
|
|
851
|
-
const shardPlanCommitment = snapshotShardPlanCommitment({
|
|
852
|
-
migrationCommitment: migrationId,
|
|
853
|
-
manifestCommitment: (0, sale_common_js_1.bytesToHex)(base.manifestCommitment),
|
|
854
|
-
tokenId,
|
|
855
|
-
totalSupply: base.totalSupply,
|
|
856
|
-
shards,
|
|
857
|
-
});
|
|
858
|
-
const beforeState = {
|
|
859
|
-
...base,
|
|
860
|
-
phase: 1n,
|
|
861
|
-
tokenId: (0, sale_common_js_1.hexToBytes)(tokenId),
|
|
862
|
-
shardPlanCommitment: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
863
|
-
activationDigest: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
864
|
-
shardCount: 0n,
|
|
865
|
-
};
|
|
866
|
-
const afterState = {
|
|
867
|
-
...base,
|
|
868
|
-
phase: 2n,
|
|
869
|
-
tokenId: (0, sale_common_js_1.hexToBytes)(tokenId),
|
|
870
|
-
shardPlanCommitment: (0, sale_common_js_1.hexToBytes)(shardPlanCommitment),
|
|
871
|
-
activationDigest: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.activationDigest, "activation digest")),
|
|
872
|
-
shardCount: BigInt(shards.length),
|
|
873
|
-
};
|
|
874
|
-
const bootstrapScript = buildSnapshotBootstrapScriptForState(artifacts.bootstrap, beforeState);
|
|
875
|
-
const nextBootstrapScript = buildSnapshotBootstrapScriptForState(artifacts.bootstrap, afterState);
|
|
876
|
-
const bootstrapSource = sourceDescriptor(params.bootstrapSource, "bootstrap source", scriptAddress(bootstrapScript, network));
|
|
877
|
-
const rpc = rpcFor(network);
|
|
878
|
-
await rpc.connect();
|
|
879
|
-
try {
|
|
880
|
-
const [bootstrapUtxos, walletUtxos] = await Promise.all([
|
|
881
|
-
rpc.getUtxosByAddresses({ addresses: [bootstrapSource.address] }),
|
|
882
|
-
rpc.getUtxosByAddresses({ addresses: [walletAddress] }),
|
|
883
|
-
]);
|
|
884
|
-
const bootstrapEntry = findExactEntry(bootstrapUtxos.entries, bootstrapSource);
|
|
885
|
-
assertCovenantSource(bootstrapEntry, {
|
|
886
|
-
covenantId: bootstrapId,
|
|
887
|
-
script: bootstrapScript,
|
|
888
|
-
amount: base.bootstrapCellKas,
|
|
889
|
-
label: "bootstrap seal source",
|
|
890
|
-
});
|
|
891
|
-
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(withoutOutpoints(walletUtxos.entries, [bootstrapEntry.outpoint]), priorityFee() + 10000n, [], params.fundingOutpoint);
|
|
892
|
-
const outputs = [
|
|
893
|
-
new kaspaWasm.TransactionOutput(base.bootstrapCellKas, kaspaWasm.payToScriptHashScript(nextBootstrapScript), new kaspaWasm.CovenantBinding(0, new kaspaWasm.Hash(bootstrapId))),
|
|
894
|
-
];
|
|
895
|
-
const fundingChangeOutputIndex = appendFundingChange(outputs, [bootstrapEntry, fundingEntry], walletAddress, base.bootstrapCellKas, priorityFee());
|
|
896
|
-
const transaction = new kaspaWasm.Transaction({
|
|
897
|
-
version: 1,
|
|
898
|
-
lockTime: 0n,
|
|
899
|
-
inputs: [
|
|
900
|
-
covenantInput(bootstrapEntry, BOOTSTRAP_COMPUTE_BUDGET),
|
|
901
|
-
publicInput(fundingEntry, PUBLIC_INPUT_COMPUTE_BUDGET),
|
|
902
|
-
],
|
|
903
|
-
outputs,
|
|
904
|
-
subnetworkId: NATIVE_SUBNETWORK_ID,
|
|
905
|
-
gas: 0n,
|
|
906
|
-
payload: "",
|
|
907
|
-
});
|
|
908
|
-
(0, sale_common_js_1.setVersionOneInputMassFields)(transaction, PUBLIC_INPUT_COMPUTE_BUDGET);
|
|
909
|
-
transaction.inputs[0].computeBudget = BOOTSTRAP_COMPUTE_BUDGET;
|
|
910
|
-
const recipes = bootstrapApprovalRecipes((0, sale_common_js_1.bytesToHex)(bootstrapScript), bootstrapSealArgs(artifacts, afterState));
|
|
911
|
-
transaction.inputs[0].signatureScript = encodeP2sh(signatureScriptArgsBytes(recipes.placeholder.args), bootstrapScript);
|
|
912
|
-
const adjusted = transactionWithCalculatedFeeChange(kaspaWasm, transaction, fundingChangeOutputIndex, network, "snapshot bootstrap seal", [recipes.approval]);
|
|
913
|
-
return outputEnvelope(adjusted, [{ index: 1 }], [recipes.approval], {
|
|
914
|
-
migrationId,
|
|
915
|
-
stage: "bootstrap-seal",
|
|
916
|
-
tokenId,
|
|
917
|
-
bootstrapId,
|
|
918
|
-
bootstrapState: {
|
|
919
|
-
...bootstrapStateReceipt(afterState),
|
|
920
|
-
phase: "SEALED",
|
|
921
|
-
},
|
|
922
|
-
shardPlanCommitment,
|
|
923
|
-
activationDigest: (0, sale_common_js_1.bytesToHex)(afterState.activationDigest),
|
|
924
|
-
shards: shards.map((shard) => shard.shardIndex),
|
|
925
|
-
maximumFeeSompi: feeOf(adjusted).toString(),
|
|
926
|
-
intentInputs: [
|
|
927
|
-
{
|
|
928
|
-
role: "snapshot-bootstrap",
|
|
929
|
-
index: 0,
|
|
930
|
-
covenantId: bootstrapId,
|
|
931
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(bootstrapScript),
|
|
932
|
-
},
|
|
933
|
-
{ role: "creator-funding", index: 1 },
|
|
934
|
-
],
|
|
935
|
-
intentOutputs: [
|
|
936
|
-
{
|
|
937
|
-
role: "snapshot-bootstrap",
|
|
938
|
-
index: 0,
|
|
939
|
-
covenantId: bootstrapId,
|
|
940
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(nextBootstrapScript),
|
|
941
|
-
},
|
|
942
|
-
],
|
|
943
|
-
});
|
|
944
|
-
}
|
|
945
|
-
finally {
|
|
946
|
-
await rpc.disconnect();
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
async function buildBootstrapGenesis(input) {
|
|
950
|
-
const request = input.request || {};
|
|
951
|
-
const params = request.params || {};
|
|
952
|
-
const network = networkOf(request);
|
|
953
|
-
const walletAddress = walletAddressOf(request);
|
|
954
|
-
const [kcc20, bootstrap] = await Promise.all([
|
|
955
|
-
readPinnedArtifact(KCC20_ARTIFACT_PATH, params.artifactPins?.kcc20ArtifactSha256, "KCC20"),
|
|
956
|
-
readPinnedArtifact(BOOTSTRAP_ARTIFACT_PATH, params.artifactPins?.bootstrapArtifactSha256, "KCC20SnapshotBootstrap"),
|
|
957
|
-
]);
|
|
958
|
-
const template = (0, abi_js_1.templateParts)(kcc20);
|
|
959
|
-
const expectedTemplateHash = (0, sale_common_js_1.requireHex32)(params.expectedKcc20TemplateHash, "KCC20 template hash");
|
|
960
|
-
if ((0, sale_common_js_1.bytesToHex)(template.hash) !== expectedTemplateHash) {
|
|
961
|
-
throw new Error("KCC20 template hash does not match the migration pin");
|
|
962
|
-
}
|
|
963
|
-
const approvalKey = (0, sale_common_js_1.requireHex32)(params.approvalKey ?? params.approvalKeyA, "approval key");
|
|
964
|
-
if (approvalKey === sale_common_js_1.ZERO_HASH) {
|
|
965
|
-
throw new Error("bootstrap approval key must be nonzero");
|
|
966
|
-
}
|
|
967
|
-
const state = {
|
|
968
|
-
migrationCommitment: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.migrationCommitment, "migration commitment")),
|
|
969
|
-
manifestCommitment: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.manifestCommitment, "manifest commitment")),
|
|
970
|
-
holderExtensionCommitment: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.holderExtensionCommitment, "holder extension commitment")),
|
|
971
|
-
totalSupply: positiveI64(params.totalSupply, "total supply"),
|
|
972
|
-
claimNotBeforeDaaScore: positiveI64(params.claimNotBeforeDaaScore, "claim-not-before DAA score"),
|
|
973
|
-
kcc20TemplateHash: (0, sale_common_js_1.hexToBytes)(expectedTemplateHash),
|
|
974
|
-
kcc20TemplatePrefixLen: BigInt(template.prefix.length),
|
|
975
|
-
kcc20TemplateSuffixLen: BigInt(template.suffix.length),
|
|
976
|
-
tokenCellKas: minimumCell(params.tokenCellKas, "token cell KAS"),
|
|
977
|
-
reserveCellKas: minimumCell(params.reserveCellKas, "reserve cell KAS"),
|
|
978
|
-
bootstrapCellKas: minimumCell(params.bootstrapCellKas, "bootstrap cell KAS"),
|
|
979
|
-
approvalKey: (0, sale_common_js_1.hexToBytes)(approvalKey),
|
|
980
|
-
phase: 0n,
|
|
981
|
-
tokenId: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
982
|
-
shardPlanCommitment: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
983
|
-
activationDigest: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
984
|
-
shardCount: 0n,
|
|
985
|
-
};
|
|
986
|
-
if (state.claimNotBeforeDaaScore >= 500000000000n) {
|
|
987
|
-
throw new Error("claim-not-before must use DAA-score locktime mode");
|
|
988
|
-
}
|
|
989
|
-
const bootstrapScript = buildSnapshotBootstrapScriptForState(bootstrap, state);
|
|
990
|
-
const rpc = rpcFor(network);
|
|
991
|
-
await rpc.connect();
|
|
992
|
-
try {
|
|
993
|
-
const walletUtxos = await rpc.getUtxosByAddresses({
|
|
994
|
-
addresses: [walletAddress],
|
|
995
|
-
});
|
|
996
|
-
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, state.bootstrapCellKas + priorityFee() + 10000n, [], params.fundingOutpoint);
|
|
997
|
-
const outputs = [
|
|
998
|
-
new kaspaWasm.TransactionOutput(state.bootstrapCellKas, kaspaWasm.payToScriptHashScript(bootstrapScript)),
|
|
999
|
-
];
|
|
1000
|
-
const changeIndex = appendFundingChange(outputs, [fundingEntry], walletAddress, state.bootstrapCellKas, priorityFee());
|
|
1001
|
-
const stateReceipt = bootstrapStateReceipt(state);
|
|
1002
|
-
const transaction = new kaspaWasm.Transaction({
|
|
1003
|
-
version: 1,
|
|
1004
|
-
lockTime: 0n,
|
|
1005
|
-
inputs: [publicInput(fundingEntry, PUBLIC_INPUT_COMPUTE_BUDGET)],
|
|
1006
|
-
outputs,
|
|
1007
|
-
subnetworkId: NATIVE_SUBNETWORK_ID,
|
|
1008
|
-
gas: 0n,
|
|
1009
|
-
payload: (0, sale_common_js_1.bytesToHex)(new TextEncoder().encode(JSON.stringify({
|
|
1010
|
-
tn10: {
|
|
1011
|
-
v: 1,
|
|
1012
|
-
tmpl: "KCC20SnapshotBootstrap",
|
|
1013
|
-
args: [
|
|
1014
|
-
{
|
|
1015
|
-
name: "bootstrapState",
|
|
1016
|
-
type: "object",
|
|
1017
|
-
value: stateReceipt,
|
|
1018
|
-
},
|
|
1019
|
-
],
|
|
1020
|
-
},
|
|
1021
|
-
}))),
|
|
1022
|
-
});
|
|
1023
|
-
(0, sale_common_js_1.setVersionOneInputMassFields)(transaction, PUBLIC_INPUT_COMPUTE_BUDGET);
|
|
1024
|
-
transaction.populateGenesisCovenants([
|
|
1025
|
-
new kaspaWasm.GenesisCovenantGroup(0, [0]),
|
|
1026
|
-
]);
|
|
1027
|
-
transaction.finalize();
|
|
1028
|
-
const covenantId = (0, sale_common_js_1.requireHex32)(transaction.outputs[0]?.covenant?.covenantId?.toString(), "bootstrap covenant id");
|
|
1029
|
-
const adjusted = transactionWithCalculatedFeeChange(kaspaWasm, transaction, changeIndex, network, "snapshot bootstrap genesis");
|
|
1030
|
-
return outputEnvelope(adjusted, [{ index: 0 }], [], {
|
|
1031
|
-
migrationId: (0, sale_common_js_1.requireHex32)(params.migrationId, "migration id"),
|
|
1032
|
-
stage: "bootstrap-deploy",
|
|
1033
|
-
covenantId,
|
|
1034
|
-
bootstrapState: { ...stateReceipt, phase: "UNBOUND" },
|
|
1035
|
-
maximumFeeSompi: feeOf(adjusted).toString(),
|
|
1036
|
-
intentInputs: [{ role: "creator-funding", index: 0 }],
|
|
1037
|
-
intentOutputs: [
|
|
1038
|
-
{
|
|
1039
|
-
role: "snapshot-bootstrap",
|
|
1040
|
-
index: 0,
|
|
1041
|
-
covenantId,
|
|
1042
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(bootstrapScript),
|
|
1043
|
-
},
|
|
1044
|
-
],
|
|
1045
|
-
});
|
|
1046
|
-
}
|
|
1047
|
-
finally {
|
|
1048
|
-
await rpc.disconnect();
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
async function buildControllerGenesis(input) {
|
|
1052
|
-
const request = input.request || {};
|
|
1053
|
-
const params = request.params || {};
|
|
1054
|
-
const network = networkOf(request);
|
|
1055
|
-
const walletAddress = walletAddressOf(request);
|
|
1056
|
-
const artifacts = await readPinnedArtifacts(params.artifactPins, true);
|
|
1057
|
-
const definition = snapshotDefinition(params, artifacts);
|
|
1058
|
-
const controllerState = initialControllerState(definition);
|
|
1059
|
-
const controllerScript = buildSnapshotControllerScriptForState(artifacts.controller, controllerState);
|
|
1060
|
-
const outputSompi = definition.controllerCellKas;
|
|
1061
|
-
const rpc = rpcFor(network);
|
|
1062
|
-
await rpc.connect();
|
|
1063
|
-
try {
|
|
1064
|
-
const walletUtxos = await rpc.getUtxosByAddresses({
|
|
1065
|
-
addresses: [walletAddress],
|
|
1066
|
-
});
|
|
1067
|
-
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, outputSompi + priorityFee() + 10000n, [], params.fundingOutpoint);
|
|
1068
|
-
const outputs = [
|
|
1069
|
-
new kaspaWasm.TransactionOutput(outputSompi, kaspaWasm.payToScriptHashScript(controllerScript)),
|
|
1070
|
-
];
|
|
1071
|
-
const fundingChangeOutputIndex = appendFundingChange(outputs, [fundingEntry], walletAddress, outputSompi, priorityFee());
|
|
1072
|
-
const transaction = new kaspaWasm.Transaction({
|
|
1073
|
-
version: 1,
|
|
1074
|
-
lockTime: 0n,
|
|
1075
|
-
inputs: [publicInput(fundingEntry, PUBLIC_INPUT_COMPUTE_BUDGET)],
|
|
1076
|
-
outputs,
|
|
1077
|
-
subnetworkId: NATIVE_SUBNETWORK_ID,
|
|
1078
|
-
gas: 0n,
|
|
1079
|
-
payload: controllerDeploymentPayload(definition, controllerState),
|
|
1080
|
-
});
|
|
1081
|
-
(0, sale_common_js_1.setVersionOneInputMassFields)(transaction, PUBLIC_INPUT_COMPUTE_BUDGET);
|
|
1082
|
-
transaction.populateGenesisCovenants([
|
|
1083
|
-
new kaspaWasm.GenesisCovenantGroup(0, [0]),
|
|
1084
|
-
]);
|
|
1085
|
-
transaction.finalize();
|
|
1086
|
-
const controllerId = (0, sale_common_js_1.requireHex32)(transaction.outputs[0]?.covenant?.covenantId?.toString(), "controller covenant id");
|
|
1087
|
-
const adjusted = transactionWithCalculatedFeeChange(kaspaWasm, transaction, fundingChangeOutputIndex, network, "snapshot controller genesis");
|
|
1088
|
-
return outputEnvelope(adjusted, [{ index: 0 }], [], {
|
|
1089
|
-
migrationId: definition.migrationId,
|
|
1090
|
-
stage: "controller-deploy",
|
|
1091
|
-
controllerId,
|
|
1092
|
-
shard: definition.shard.shardIndex,
|
|
1093
|
-
controllerStateCommitment: snapshotControllerStateCommitment(controllerState),
|
|
1094
|
-
holderExtensionCommitment: definition.holderExtensionCommitment,
|
|
1095
|
-
maximumFeeSompi: feeOf(adjusted).toString(),
|
|
1096
|
-
intentInputs: [{ role: "creator-funding", index: 0 }],
|
|
1097
|
-
intentOutputs: [
|
|
1098
|
-
{
|
|
1099
|
-
role: "snapshot-controller",
|
|
1100
|
-
index: 0,
|
|
1101
|
-
shard: definition.shard.shardIndex,
|
|
1102
|
-
covenantId: controllerId,
|
|
1103
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(controllerScript),
|
|
1104
|
-
},
|
|
1105
|
-
],
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
finally {
|
|
1109
|
-
await rpc.disconnect();
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
async function buildReserveHandoff(input) {
|
|
1113
|
-
const request = input.request || {};
|
|
1114
|
-
const params = request.params || {};
|
|
1115
|
-
const network = networkOf(request);
|
|
1116
|
-
const walletAddress = walletAddressOf(request);
|
|
1117
|
-
const migrationId = (0, sale_common_js_1.requireHex32)(params.migrationId, "migration id");
|
|
1118
|
-
const artifacts = await readPinnedArtifacts(params.artifactPins, false, true);
|
|
1119
|
-
const bootstrapId = (0, sale_common_js_1.requireHex32)(params.bootstrapId, "bootstrap covenant id");
|
|
1120
|
-
const tokenId = (0, sale_common_js_1.requireHex32)(params.tokenId, "token covenant id");
|
|
1121
|
-
const extensionCommitment = (0, sale_common_js_1.requireHex32)(params.holderExtensionCommitment, "holder extension commitment");
|
|
1122
|
-
const totalSupply = positiveI64(params.totalSupply, "total supply");
|
|
1123
|
-
const tokenState = kcc20State(params.tokenSource?.state);
|
|
1124
|
-
if (tokenState.amount !== totalSupply ||
|
|
1125
|
-
tokenState.ownerScheme !== 4 ||
|
|
1126
|
-
(0, sale_common_js_1.bytesToHex)(tokenState.owner) !== bootstrapId ||
|
|
1127
|
-
(0, sale_common_js_1.bytesToHex)(tokenState.extensionCommitment) !== extensionCommitment) {
|
|
1128
|
-
throw new Error("reserve handoff token source does not match the migration");
|
|
1129
|
-
}
|
|
1130
|
-
const shards = reserveShards(params.shards, totalSupply);
|
|
1131
|
-
const template = (0, abi_js_1.templateParts)(artifacts.kcc20);
|
|
1132
|
-
const expectedTemplateHash = (0, sale_common_js_1.requireHex32)(params.kcc20TemplateHash, "KCC20 template hash");
|
|
1133
|
-
if ((0, sale_common_js_1.bytesToHex)(template.hash) !== expectedTemplateHash) {
|
|
1134
|
-
throw new Error("KCC20 template hash does not match the migration pin");
|
|
1135
|
-
}
|
|
1136
|
-
const shardPlanCommitment = snapshotShardPlanCommitment({
|
|
1137
|
-
migrationCommitment: migrationId,
|
|
1138
|
-
manifestCommitment: (0, sale_common_js_1.requireHex32)(params.manifestCommitment, "manifest commitment"),
|
|
1139
|
-
tokenId,
|
|
1140
|
-
totalSupply,
|
|
1141
|
-
shards,
|
|
1142
|
-
});
|
|
1143
|
-
if (shardPlanCommitment !==
|
|
1144
|
-
(0, sale_common_js_1.requireHex32)(params.bootstrapShardPlanCommitment, "bootstrap shard plan commitment")) {
|
|
1145
|
-
throw new Error("activation shards do not match the sealed bootstrap");
|
|
1146
|
-
}
|
|
1147
|
-
const bootstrapState = {
|
|
1148
|
-
migrationCommitment: (0, sale_common_js_1.hexToBytes)(migrationId),
|
|
1149
|
-
manifestCommitment: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.manifestCommitment, "manifest commitment")),
|
|
1150
|
-
holderExtensionCommitment: (0, sale_common_js_1.hexToBytes)(extensionCommitment),
|
|
1151
|
-
totalSupply,
|
|
1152
|
-
claimNotBeforeDaaScore: positiveI64(params.claimNotBeforeDaaScore, "claim-not-before DAA score"),
|
|
1153
|
-
kcc20TemplateHash: (0, sale_common_js_1.hexToBytes)(expectedTemplateHash),
|
|
1154
|
-
kcc20TemplatePrefixLen: BigInt(template.prefix.length),
|
|
1155
|
-
kcc20TemplateSuffixLen: BigInt(template.suffix.length),
|
|
1156
|
-
tokenCellKas: minimumCell(params.tokenCellKas, "token cell KAS"),
|
|
1157
|
-
reserveCellKas: minimumCell(params.reserveCellKas, "reserve cell KAS"),
|
|
1158
|
-
bootstrapCellKas: minimumCell(params.bootstrapCellKas, "bootstrap cell KAS"),
|
|
1159
|
-
approvalKey: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.approvalKey ?? params.approvalKeyA, "approval key")),
|
|
1160
|
-
phase: 2n,
|
|
1161
|
-
tokenId: (0, sale_common_js_1.hexToBytes)(tokenId),
|
|
1162
|
-
shardPlanCommitment: (0, sale_common_js_1.hexToBytes)(shardPlanCommitment),
|
|
1163
|
-
activationDigest: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.bootstrapActivationDigest, "bootstrap activation digest")),
|
|
1164
|
-
shardCount: BigInt(shards.length),
|
|
1165
|
-
};
|
|
1166
|
-
const bootstrapScript = buildSnapshotBootstrapScriptForState(artifacts.bootstrap, bootstrapState);
|
|
1167
|
-
const bootstrapAddress = scriptAddress(bootstrapScript, network);
|
|
1168
|
-
const bootstrapSource = sourceDescriptor(params.bootstrapSource, "bootstrap source", bootstrapAddress);
|
|
1169
|
-
const tokenScript = (0, abi_js_1.buildKcc20ScriptForState)(artifacts.kcc20, tokenState);
|
|
1170
|
-
const tokenAddress = scriptAddress(tokenScript, network);
|
|
1171
|
-
const tokenSource = sourceDescriptor(params.tokenSource, "token source", tokenAddress);
|
|
1172
|
-
const nextStates = shards.map((shard) => ({
|
|
1173
|
-
amount: shard.allocationTotal,
|
|
1174
|
-
owner: (0, sale_common_js_1.hexToBytes)(shard.controllerId),
|
|
1175
|
-
ownerScheme: 4,
|
|
1176
|
-
borrowScheme: 0,
|
|
1177
|
-
borrowGuard: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
1178
|
-
extensionCommitment: (0, sale_common_js_1.hexToBytes)(extensionCommitment),
|
|
1179
|
-
}));
|
|
1180
|
-
const rpc = rpcFor(network);
|
|
1181
|
-
await rpc.connect();
|
|
1182
|
-
try {
|
|
1183
|
-
const [bootstrapUtxos, tokenUtxos, walletUtxos] = await Promise.all([
|
|
1184
|
-
rpc.getUtxosByAddresses({ addresses: [bootstrapAddress] }),
|
|
1185
|
-
rpc.getUtxosByAddresses({ addresses: [tokenAddress] }),
|
|
1186
|
-
rpc.getUtxosByAddresses({ addresses: [walletAddress] }),
|
|
1187
|
-
]);
|
|
1188
|
-
const bootstrapEntry = findExactEntry(bootstrapUtxos.entries, bootstrapSource);
|
|
1189
|
-
assertCovenantSource(bootstrapEntry, {
|
|
1190
|
-
covenantId: bootstrapId,
|
|
1191
|
-
script: bootstrapScript,
|
|
1192
|
-
amount: bootstrapState.bootstrapCellKas,
|
|
1193
|
-
label: "reserve activation bootstrap source",
|
|
1194
|
-
});
|
|
1195
|
-
const tokenEntry = findExactEntry(tokenUtxos.entries, tokenSource);
|
|
1196
|
-
assertCovenantSource(tokenEntry, {
|
|
1197
|
-
covenantId: tokenId,
|
|
1198
|
-
script: tokenScript,
|
|
1199
|
-
amount: bootstrapState.tokenCellKas,
|
|
1200
|
-
label: "reserve handoff token source",
|
|
1201
|
-
});
|
|
1202
|
-
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(withoutOutpoints(walletUtxos.entries, [
|
|
1203
|
-
bootstrapEntry.outpoint,
|
|
1204
|
-
tokenEntry.outpoint,
|
|
1205
|
-
]), priorityFee() + DEFAULT_CELL_SOMPI * BigInt(shards.length) + 10000n, [], params.fundingOutpoint);
|
|
1206
|
-
const outputs = nextStates.map((state) => new kaspaWasm.TransactionOutput(positiveI64(params.reserveCellKas ?? DEFAULT_CELL_SOMPI, "reserve cell KAS"), kaspaWasm.payToScriptHashScript((0, abi_js_1.buildKcc20ScriptForState)(artifacts.kcc20, state)), new kaspaWasm.CovenantBinding(1, new kaspaWasm.Hash(tokenId))));
|
|
1207
|
-
const outputSompi = outputs.reduce((sum, output) => sum + BigInt(output.value), 0n);
|
|
1208
|
-
const fundingChangeOutputIndex = appendFundingChange(outputs, [bootstrapEntry, tokenEntry, fundingEntry], walletAddress, outputSompi, priorityFee());
|
|
1209
|
-
const transaction = new kaspaWasm.Transaction({
|
|
1210
|
-
version: 1,
|
|
1211
|
-
lockTime: 0n,
|
|
1212
|
-
inputs: [
|
|
1213
|
-
covenantInput(bootstrapEntry, BOOTSTRAP_COMPUTE_BUDGET),
|
|
1214
|
-
covenantInput(tokenEntry, KCC20_COMPUTE_BUDGET),
|
|
1215
|
-
publicInput(fundingEntry, PUBLIC_INPUT_COMPUTE_BUDGET),
|
|
1216
|
-
],
|
|
1217
|
-
outputs,
|
|
1218
|
-
subnetworkId: NATIVE_SUBNETWORK_ID,
|
|
1219
|
-
gas: 0n,
|
|
1220
|
-
payload: "",
|
|
1221
|
-
});
|
|
1222
|
-
(0, sale_common_js_1.setVersionOneInputMassFields)(transaction, PUBLIC_INPUT_COMPUTE_BUDGET);
|
|
1223
|
-
transaction.inputs[0].computeBudget = BOOTSTRAP_COMPUTE_BUDGET;
|
|
1224
|
-
transaction.inputs[1].computeBudget = KCC20_COMPUTE_BUDGET;
|
|
1225
|
-
const bootstrapPrefix = new kaspaWasm.ScriptBuilder();
|
|
1226
|
-
for (const field of (0, abi_js_1.encodeKcc20StateRecordArrays)(nextStates)) {
|
|
1227
|
-
bootstrapPrefix.addData(field);
|
|
1228
|
-
}
|
|
1229
|
-
bootstrapPrefix.addData(template.prefix);
|
|
1230
|
-
bootstrapPrefix.addData(template.suffix);
|
|
1231
|
-
bootstrapPrefix.addData((0, abi_js_1.dispatchTagFor)(artifacts.bootstrap, "activate"));
|
|
1232
|
-
transaction.inputs[0].signatureScript = encodeP2sh(bootstrapPrefix.drain(), bootstrapScript);
|
|
1233
|
-
transaction.inputs[1].signatureScript = encodeP2sh((0, abi_js_1.buildKcc20TransferSigScript)(kaspaWasm, artifacts.kcc20, {
|
|
1234
|
-
nextStates,
|
|
1235
|
-
witness: Uint8Array.of(0),
|
|
1236
|
-
}), tokenScript);
|
|
1237
|
-
const scripts = [];
|
|
1238
|
-
const adjusted = transactionWithCalculatedFeeChange(kaspaWasm, transaction, fundingChangeOutputIndex, network, "snapshot reserve handoff", scripts);
|
|
1239
|
-
return outputEnvelope(adjusted, [{ index: 2 }], scripts, {
|
|
1240
|
-
migrationId,
|
|
1241
|
-
stage: "reserve-handoff",
|
|
1242
|
-
tokenId,
|
|
1243
|
-
bootstrapId,
|
|
1244
|
-
bootstrapState: {
|
|
1245
|
-
...bootstrapStateReceipt(bootstrapState),
|
|
1246
|
-
phase: "ACTIVATED",
|
|
1247
|
-
},
|
|
1248
|
-
shardPlanCommitment,
|
|
1249
|
-
activationDigest: (0, sale_common_js_1.bytesToHex)(bootstrapState.activationDigest),
|
|
1250
|
-
shards: shards.map((shard) => shard.shardIndex),
|
|
1251
|
-
maximumFeeSompi: feeOf(adjusted).toString(),
|
|
1252
|
-
intentInputs: [
|
|
1253
|
-
{
|
|
1254
|
-
role: "snapshot-bootstrap",
|
|
1255
|
-
index: 0,
|
|
1256
|
-
covenantId: bootstrapId,
|
|
1257
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(bootstrapScript),
|
|
1258
|
-
staticSignatureScriptHex: signatureScriptHex(adjusted, 0),
|
|
1259
|
-
},
|
|
1260
|
-
{
|
|
1261
|
-
role: "fixed-supply-token",
|
|
1262
|
-
index: 1,
|
|
1263
|
-
covenantId: tokenId,
|
|
1264
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)(tokenScript),
|
|
1265
|
-
staticSignatureScriptHex: signatureScriptHex(adjusted, 1),
|
|
1266
|
-
},
|
|
1267
|
-
{ role: "creator-funding", index: 2 },
|
|
1268
|
-
],
|
|
1269
|
-
intentOutputs: shards.map((shard, index) => ({
|
|
1270
|
-
role: "shard-reserve",
|
|
1271
|
-
index,
|
|
1272
|
-
shard: shard.shardIndex,
|
|
1273
|
-
covenantId: tokenId,
|
|
1274
|
-
revealScriptHex: (0, sale_common_js_1.bytesToHex)((0, abi_js_1.buildKcc20ScriptForState)(artifacts.kcc20, nextStates[index])),
|
|
1275
|
-
owner: shard.controllerId,
|
|
1276
|
-
ownerScheme: 4,
|
|
1277
|
-
borrowScheme: 0,
|
|
1278
|
-
borrowGuard: sale_common_js_1.ZERO_HASH,
|
|
1279
|
-
extensionCommitment: (0, sale_common_js_1.bytesToHex)(bootstrapState.holderExtensionCommitment),
|
|
1280
|
-
tokenAmount: shard.allocationTotal.toString(),
|
|
1281
|
-
})),
|
|
1282
|
-
});
|
|
1283
|
-
}
|
|
1284
|
-
finally {
|
|
1285
|
-
await rpc.disconnect();
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
489
|
async function buildClaim(input) {
|
|
1289
490
|
const request = input.request || {};
|
|
1290
491
|
const params = request.params || {};
|
|
@@ -1622,207 +823,6 @@ function createKcc20SnapshotPsktBuilder(options) {
|
|
|
1622
823
|
kcc20TemplateSuffixLen: template.suffix.length,
|
|
1623
824
|
};
|
|
1624
825
|
}
|
|
1625
|
-
function initialControllerState(definition) {
|
|
1626
|
-
return {
|
|
1627
|
-
tokenId: (0, sale_common_js_1.hexToBytes)(definition.tokenId),
|
|
1628
|
-
holderExtensionCommitment: (0, sale_common_js_1.hexToBytes)(definition.holderExtensionCommitment),
|
|
1629
|
-
manifestCommitment: (0, sale_common_js_1.hexToBytes)(definition.manifestCommitment),
|
|
1630
|
-
snapshotContext: (0, sale_common_js_1.hexToBytes)(definition.snapshotContext),
|
|
1631
|
-
kcc20TemplateHash: (0, sale_common_js_1.hexToBytes)(definition.kcc20TemplateHash),
|
|
1632
|
-
claimNotBeforeDaaScore: definition.claimNotBeforeDaaScore,
|
|
1633
|
-
shardIndex: BigInt(definition.shard.shardIndex),
|
|
1634
|
-
globalIndexStart: BigInt(definition.shard.globalIndexStart),
|
|
1635
|
-
holderCount: BigInt(definition.shard.holderCount),
|
|
1636
|
-
treeDepth: BigInt(definition.shard.depth),
|
|
1637
|
-
kcc20TemplatePrefixLen: BigInt(definition.kcc20TemplatePrefixLen),
|
|
1638
|
-
kcc20TemplateSuffixLen: BigInt(definition.kcc20TemplateSuffixLen),
|
|
1639
|
-
controllerCellKas: definition.controllerCellKas,
|
|
1640
|
-
reserveCellKas: definition.reserveCellKas,
|
|
1641
|
-
recipientMinCellKas: definition.recipientMinCellKas,
|
|
1642
|
-
remainingRoot: (0, sale_common_js_1.hexToBytes)(definition.shard.initialRoot),
|
|
1643
|
-
remainingAmount: definition.shard.allocationTotal,
|
|
1644
|
-
claimsProcessed: 0n,
|
|
1645
|
-
};
|
|
1646
|
-
}
|
|
1647
|
-
function buildSnapshotControllerScriptForState(artifact, state) {
|
|
1648
|
-
const normalized = (0, abi_js_1.normalizeSilverScriptArtifact)(artifact);
|
|
1649
|
-
const encoded = encodeControllerState(state);
|
|
1650
|
-
const start = normalized.state_layout?.start;
|
|
1651
|
-
const length = normalized.state_layout?.len;
|
|
1652
|
-
if (!Number.isInteger(start) ||
|
|
1653
|
-
!Number.isInteger(length) ||
|
|
1654
|
-
encoded.length !== length) {
|
|
1655
|
-
throw new Error("snapshot controller artifact state layout is invalid");
|
|
1656
|
-
}
|
|
1657
|
-
return concatBytes(Uint8Array.from(normalized.script).slice(0, start), encoded, Uint8Array.from(normalized.script).slice(start + length));
|
|
1658
|
-
}
|
|
1659
|
-
function buildSnapshotBootstrapScriptForState(artifact, state) {
|
|
1660
|
-
const normalized = (0, abi_js_1.normalizeSilverScriptArtifact)(artifact);
|
|
1661
|
-
const encoded = encodeBootstrapState(state);
|
|
1662
|
-
const start = normalized.state_layout?.start;
|
|
1663
|
-
const length = normalized.state_layout?.len;
|
|
1664
|
-
if (normalized.contract_name !== "KCC20SnapshotBootstrap" ||
|
|
1665
|
-
!Number.isInteger(start) ||
|
|
1666
|
-
!Number.isInteger(length) ||
|
|
1667
|
-
encoded.length !== length) {
|
|
1668
|
-
throw new Error("snapshot bootstrap artifact state layout is invalid");
|
|
1669
|
-
}
|
|
1670
|
-
return concatBytes(Uint8Array.from(normalized.script).slice(0, start), encoded, Uint8Array.from(normalized.script).slice(start + length));
|
|
1671
|
-
}
|
|
1672
|
-
function encodeBootstrapState(state) {
|
|
1673
|
-
return concatBytes(pushData(state.migrationCommitment), pushData(state.manifestCommitment), pushData(state.holderExtensionCommitment), pushData(i64(state.totalSupply)), pushData(i64(state.claimNotBeforeDaaScore)), pushData(state.kcc20TemplateHash), pushData(i64(state.kcc20TemplatePrefixLen)), pushData(i64(state.kcc20TemplateSuffixLen)), pushData(i64(state.tokenCellKas)), pushData(i64(state.reserveCellKas)), pushData(i64(state.bootstrapCellKas)), pushData(state.approvalKey), pushData(i64(state.phase)), pushData(state.tokenId), pushData(state.shardPlanCommitment), pushData(state.activationDigest), pushData(i64(state.shardCount)));
|
|
1674
|
-
}
|
|
1675
|
-
function bootstrapStateReceipt(state) {
|
|
1676
|
-
return {
|
|
1677
|
-
migrationCommitment: (0, sale_common_js_1.bytesToHex)(state.migrationCommitment),
|
|
1678
|
-
manifestCommitment: (0, sale_common_js_1.bytesToHex)(state.manifestCommitment),
|
|
1679
|
-
holderExtensionCommitment: (0, sale_common_js_1.bytesToHex)(state.holderExtensionCommitment),
|
|
1680
|
-
totalSupply: state.totalSupply.toString(),
|
|
1681
|
-
claimNotBeforeDaaScore: state.claimNotBeforeDaaScore.toString(),
|
|
1682
|
-
kcc20TemplateHash: (0, sale_common_js_1.bytesToHex)(state.kcc20TemplateHash),
|
|
1683
|
-
kcc20TemplatePrefixLen: state.kcc20TemplatePrefixLen.toString(),
|
|
1684
|
-
kcc20TemplateSuffixLen: state.kcc20TemplateSuffixLen.toString(),
|
|
1685
|
-
tokenCellKas: state.tokenCellKas.toString(),
|
|
1686
|
-
reserveCellKas: state.reserveCellKas.toString(),
|
|
1687
|
-
bootstrapCellKas: state.bootstrapCellKas.toString(),
|
|
1688
|
-
approvalKey: (0, sale_common_js_1.bytesToHex)(state.approvalKey),
|
|
1689
|
-
phase: state.phase.toString(),
|
|
1690
|
-
tokenId: (0, sale_common_js_1.bytesToHex)(state.tokenId),
|
|
1691
|
-
shardPlanCommitment: (0, sale_common_js_1.bytesToHex)(state.shardPlanCommitment),
|
|
1692
|
-
activationDigest: (0, sale_common_js_1.bytesToHex)(state.activationDigest),
|
|
1693
|
-
shardCount: state.shardCount.toString(),
|
|
1694
|
-
};
|
|
1695
|
-
}
|
|
1696
|
-
function bootstrapBaseState(params, template) {
|
|
1697
|
-
const approvalKey = (0, sale_common_js_1.requireHex32)(params.approvalKey ?? params.approvalKeyA, "approval key");
|
|
1698
|
-
if (approvalKey === sale_common_js_1.ZERO_HASH) {
|
|
1699
|
-
throw new Error("bootstrap approval key must be nonzero");
|
|
1700
|
-
}
|
|
1701
|
-
const expectedTemplateHash = (0, sale_common_js_1.requireHex32)(params.kcc20TemplateHash, "KCC20 template hash");
|
|
1702
|
-
if ((0, sale_common_js_1.bytesToHex)(template.hash) !== expectedTemplateHash) {
|
|
1703
|
-
throw new Error("KCC20 template hash does not match the migration pin");
|
|
1704
|
-
}
|
|
1705
|
-
const claimNotBeforeDaaScore = positiveI64(params.claimNotBeforeDaaScore, "claim-not-before DAA score");
|
|
1706
|
-
if (claimNotBeforeDaaScore >= 500000000000n) {
|
|
1707
|
-
throw new Error("claim-not-before must use DAA-score locktime mode");
|
|
1708
|
-
}
|
|
1709
|
-
return {
|
|
1710
|
-
migrationCommitment: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.migrationId, "migration ID")),
|
|
1711
|
-
manifestCommitment: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.manifestCommitment, "manifest commitment")),
|
|
1712
|
-
holderExtensionCommitment: (0, sale_common_js_1.hexToBytes)((0, sale_common_js_1.requireHex32)(params.holderExtensionCommitment, "holder extension commitment")),
|
|
1713
|
-
totalSupply: positiveI64(params.totalSupply, "total supply"),
|
|
1714
|
-
claimNotBeforeDaaScore,
|
|
1715
|
-
kcc20TemplateHash: (0, sale_common_js_1.hexToBytes)(expectedTemplateHash),
|
|
1716
|
-
kcc20TemplatePrefixLen: BigInt(template.prefix.length),
|
|
1717
|
-
kcc20TemplateSuffixLen: BigInt(template.suffix.length),
|
|
1718
|
-
tokenCellKas: minimumCell(params.tokenCellKas, "token cell KAS"),
|
|
1719
|
-
reserveCellKas: minimumCell(params.reserveCellKas, "reserve cell KAS"),
|
|
1720
|
-
bootstrapCellKas: minimumCell(params.bootstrapCellKas, "bootstrap cell KAS"),
|
|
1721
|
-
approvalKey: (0, sale_common_js_1.hexToBytes)(approvalKey),
|
|
1722
|
-
};
|
|
1723
|
-
}
|
|
1724
|
-
function bootstrapStateArgs(state) {
|
|
1725
|
-
return [
|
|
1726
|
-
dataArg(state.migrationCommitment),
|
|
1727
|
-
dataArg(state.manifestCommitment),
|
|
1728
|
-
dataArg(state.holderExtensionCommitment),
|
|
1729
|
-
i64Arg(state.totalSupply),
|
|
1730
|
-
i64Arg(state.claimNotBeforeDaaScore),
|
|
1731
|
-
dataArg(state.kcc20TemplateHash),
|
|
1732
|
-
i64Arg(state.kcc20TemplatePrefixLen),
|
|
1733
|
-
i64Arg(state.kcc20TemplateSuffixLen),
|
|
1734
|
-
i64Arg(state.tokenCellKas),
|
|
1735
|
-
i64Arg(state.reserveCellKas),
|
|
1736
|
-
i64Arg(state.bootstrapCellKas),
|
|
1737
|
-
dataArg(state.approvalKey),
|
|
1738
|
-
i64Arg(state.phase),
|
|
1739
|
-
dataArg(state.tokenId),
|
|
1740
|
-
dataArg(state.shardPlanCommitment),
|
|
1741
|
-
dataArg(state.activationDigest),
|
|
1742
|
-
i64Arg(state.shardCount),
|
|
1743
|
-
];
|
|
1744
|
-
}
|
|
1745
|
-
function bootstrapBindArgs(artifacts, nextBootstrapState, tokenState) {
|
|
1746
|
-
const template = (0, abi_js_1.templateParts)(artifacts.kcc20);
|
|
1747
|
-
return [
|
|
1748
|
-
...bootstrapStateArgs(nextBootstrapState),
|
|
1749
|
-
i64Arg(1),
|
|
1750
|
-
i64Arg(0),
|
|
1751
|
-
i64Arg(1),
|
|
1752
|
-
{ type: "approval" },
|
|
1753
|
-
dataArg(template.prefix),
|
|
1754
|
-
dataArg(template.suffix),
|
|
1755
|
-
...kcc20StateArgs(tokenState),
|
|
1756
|
-
dataArg((0, abi_js_1.dispatchTagFor)(artifacts.bootstrap, "bindToken")),
|
|
1757
|
-
];
|
|
1758
|
-
}
|
|
1759
|
-
function bootstrapSealArgs(artifacts, nextBootstrapState) {
|
|
1760
|
-
return [
|
|
1761
|
-
...bootstrapStateArgs(nextBootstrapState),
|
|
1762
|
-
i64Arg(0),
|
|
1763
|
-
{ type: "approval" },
|
|
1764
|
-
dataArg((0, abi_js_1.dispatchTagFor)(artifacts.bootstrap, "seal")),
|
|
1765
|
-
];
|
|
1766
|
-
}
|
|
1767
|
-
function bootstrapCancellationArgs(artifacts, bound, sinkOutputIndex, sinkTokenState) {
|
|
1768
|
-
return [
|
|
1769
|
-
{ type: "approval" },
|
|
1770
|
-
i64Arg(sinkOutputIndex),
|
|
1771
|
-
...(bound
|
|
1772
|
-
? [
|
|
1773
|
-
i64Arg(0),
|
|
1774
|
-
dataArg((0, abi_js_1.templateParts)(artifacts.kcc20).prefix),
|
|
1775
|
-
dataArg((0, abi_js_1.templateParts)(artifacts.kcc20).suffix),
|
|
1776
|
-
...kcc20StateArgs(sinkTokenState),
|
|
1777
|
-
]
|
|
1778
|
-
: []),
|
|
1779
|
-
dataArg((0, abi_js_1.dispatchTagFor)(artifacts.bootstrap, bound ? "cancelBound" : "cancelUnbound")),
|
|
1780
|
-
];
|
|
1781
|
-
}
|
|
1782
|
-
function bootstrapApprovalRecipes(scriptHex, args) {
|
|
1783
|
-
const zeroSignature = "00".repeat(65);
|
|
1784
|
-
const replace = (dynamicSlot) => args.map((arg) => {
|
|
1785
|
-
if (arg.type === dynamicSlot)
|
|
1786
|
-
return { type: "signature" };
|
|
1787
|
-
if (arg.type === "approval") {
|
|
1788
|
-
return { type: "data", hex: zeroSignature };
|
|
1789
|
-
}
|
|
1790
|
-
return arg;
|
|
1791
|
-
});
|
|
1792
|
-
const script = (normalizedArgs) => ({
|
|
1793
|
-
inputIndex: 0,
|
|
1794
|
-
scriptHex,
|
|
1795
|
-
signatureScript: { mode: "ordered-args", args: normalizedArgs },
|
|
1796
|
-
});
|
|
1797
|
-
return {
|
|
1798
|
-
placeholder: { args: replace("none") },
|
|
1799
|
-
approval: script(replace("approval")),
|
|
1800
|
-
};
|
|
1801
|
-
}
|
|
1802
|
-
function signatureScriptArgsBytes(args, signature = new Uint8Array(65)) {
|
|
1803
|
-
const builder = new kaspaWasm.ScriptBuilder({
|
|
1804
|
-
flags: { covenantsEnabled: true },
|
|
1805
|
-
});
|
|
1806
|
-
for (const arg of args || []) {
|
|
1807
|
-
if (arg.type === "i64") {
|
|
1808
|
-
builder.addI64(BigInt(arg.value));
|
|
1809
|
-
}
|
|
1810
|
-
else if (arg.type === "byte") {
|
|
1811
|
-
builder.addData(Uint8Array.of(arg.value));
|
|
1812
|
-
}
|
|
1813
|
-
else if (arg.type === "data") {
|
|
1814
|
-
builder.addData((0, sale_common_js_1.hexToBytes)(arg.hex));
|
|
1815
|
-
}
|
|
1816
|
-
else if (arg.type === "signature") {
|
|
1817
|
-
const prefix = (0, sale_common_js_1.hexToBytes)(arg.prefixHex || "");
|
|
1818
|
-
builder.addData(concatBytes(prefix, signature));
|
|
1819
|
-
}
|
|
1820
|
-
else {
|
|
1821
|
-
throw new Error(`unsupported snapshot signature argument ${arg.type}`);
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
return builder.drain();
|
|
1825
|
-
}
|
|
1826
826
|
function encodeControllerState(state) {
|
|
1827
827
|
return concatBytes(pushData(state.tokenId), pushData(state.holderExtensionCommitment), pushData(state.manifestCommitment), pushData(state.snapshotContext), pushData(state.kcc20TemplateHash), pushData(i64(state.claimNotBeforeDaaScore)), pushData(i64(state.shardIndex)), pushData(i64(state.globalIndexStart)), pushData(i64(state.holderCount)), pushData(i64(state.treeDepth)), pushData(i64(state.kcc20TemplatePrefixLen)), pushData(i64(state.kcc20TemplateSuffixLen)), pushData(i64(state.controllerCellKas)), pushData(i64(state.reserveCellKas)), pushData(i64(state.recipientMinCellKas)), pushData(state.remainingRoot), pushData(i64(state.remainingAmount)), pushData(i64(state.claimsProcessed)));
|
|
1828
828
|
}
|
|
@@ -1956,36 +956,6 @@ function createKcc20SnapshotPsktBuilder(options) {
|
|
|
1956
956
|
}
|
|
1957
957
|
return normalized;
|
|
1958
958
|
}
|
|
1959
|
-
function reserveShards(values, totalSupply) {
|
|
1960
|
-
if (!Array.isArray(values) || values.length < 1 || values.length > 8) {
|
|
1961
|
-
throw new Error("atomic reserve handoff requires 1..8 shards");
|
|
1962
|
-
}
|
|
1963
|
-
const indexes = new Set();
|
|
1964
|
-
const controllerIds = new Set();
|
|
1965
|
-
const shards = values.map((value) => {
|
|
1966
|
-
const shardIndex = unsignedInteger(value?.shardIndex, "shard index");
|
|
1967
|
-
const controllerId = (0, sale_common_js_1.requireHex32)(value?.controllerId, "controller id");
|
|
1968
|
-
const allocationTotal = positiveI64(value?.allocationTotal, "shard allocation total");
|
|
1969
|
-
if (indexes.has(shardIndex) || controllerIds.has(controllerId)) {
|
|
1970
|
-
throw new Error("reserve handoff shard identities must be unique");
|
|
1971
|
-
}
|
|
1972
|
-
indexes.add(shardIndex);
|
|
1973
|
-
controllerIds.add(controllerId);
|
|
1974
|
-
return { shardIndex, controllerId, allocationTotal };
|
|
1975
|
-
});
|
|
1976
|
-
if (shards.reduce((sum, shard) => sum + shard.allocationTotal, 0n) !==
|
|
1977
|
-
totalSupply) {
|
|
1978
|
-
throw new Error("reserve handoff allocations do not equal total supply");
|
|
1979
|
-
}
|
|
1980
|
-
return shards.sort((left, right) => left.shardIndex - right.shardIndex);
|
|
1981
|
-
}
|
|
1982
|
-
function snapshotShardPlanCommitment({ migrationCommitment, manifestCommitment, tokenId, totalSupply, shards, }) {
|
|
1983
|
-
return (0, sale_common_js_1.bytesToHex)((0, blake2b_1.blake2b)(concatBytes(Uint8Array.of(0x20), (0, sale_common_js_1.hexToBytes)(migrationCommitment), (0, sale_common_js_1.hexToBytes)(manifestCommitment), (0, sale_common_js_1.hexToBytes)(tokenId), i64(totalSupply), i64(BigInt(shards.length)), ...shards.flatMap((shard, index) => [
|
|
1984
|
-
i64(BigInt(index)),
|
|
1985
|
-
(0, sale_common_js_1.hexToBytes)(shard.controllerId),
|
|
1986
|
-
i64(shard.allocationTotal),
|
|
1987
|
-
])), { dkLen: 32 }));
|
|
1988
|
-
}
|
|
1989
959
|
function claimProof(value, shard) {
|
|
1990
960
|
const proof = value || {};
|
|
1991
961
|
const normalized = {
|
|
@@ -2204,41 +1174,6 @@ function createKcc20SnapshotPsktBuilder(options) {
|
|
|
2204
1174
|
}
|
|
2205
1175
|
return value.toLowerCase();
|
|
2206
1176
|
}
|
|
2207
|
-
function controllerDeploymentPayload(definition, state) {
|
|
2208
|
-
return (0, sale_common_js_1.bytesToHex)(new TextEncoder().encode(JSON.stringify({
|
|
2209
|
-
tn10: {
|
|
2210
|
-
v: 1,
|
|
2211
|
-
tmpl: "KCC20SnapshotController",
|
|
2212
|
-
migrationId: definition.migrationId,
|
|
2213
|
-
manifestCommitment: definition.manifestCommitment,
|
|
2214
|
-
shardIndex: definition.shard.shardIndex,
|
|
2215
|
-
args: [
|
|
2216
|
-
{
|
|
2217
|
-
name: "controllerState",
|
|
2218
|
-
type: "object",
|
|
2219
|
-
value: jsonControllerState(state),
|
|
2220
|
-
},
|
|
2221
|
-
],
|
|
2222
|
-
},
|
|
2223
|
-
})));
|
|
2224
|
-
}
|
|
2225
|
-
function jsonControllerState(state) {
|
|
2226
|
-
return Object.fromEntries(Object.entries(state).map(([key, value]) => [
|
|
2227
|
-
key,
|
|
2228
|
-
value instanceof Uint8Array
|
|
2229
|
-
? (0, sale_common_js_1.bytesToHex)(value)
|
|
2230
|
-
: controllerInteger(value, key),
|
|
2231
|
-
]));
|
|
2232
|
-
}
|
|
2233
|
-
function controllerInteger(value, key) {
|
|
2234
|
-
if (typeof value !== "string" &&
|
|
2235
|
-
typeof value !== "number" &&
|
|
2236
|
-
typeof value !== "bigint" &&
|
|
2237
|
-
typeof value !== "boolean") {
|
|
2238
|
-
throw new Error(`controller state ${key} is not an integer`);
|
|
2239
|
-
}
|
|
2240
|
-
return BigInt(value).toString();
|
|
2241
|
-
}
|
|
2242
1177
|
function scriptAddress(script, network) {
|
|
2243
1178
|
return kaspaWasm
|
|
2244
1179
|
.addressFromScriptPublicKey(kaspaWasm.payToScriptHashScript(script), network)
|
|
@@ -2370,64 +1305,4 @@ function createKcc20SnapshotPsktBuilder(options) {
|
|
|
2370
1305
|
}
|
|
2371
1306
|
return buildSnapshotMigrationPskt;
|
|
2372
1307
|
}
|
|
2373
|
-
/** Pure script constructors shared by browser verification and server projections. */
|
|
2374
|
-
function buildSnapshotControllerScriptForState(artifact, state) {
|
|
2375
|
-
const normalized = (0, abi_js_1.normalizeSilverScriptArtifact)(artifact);
|
|
2376
|
-
const encoded = encodePortableControllerState(state);
|
|
2377
|
-
const start = normalized.state_layout?.start;
|
|
2378
|
-
const length = normalized.state_layout?.len;
|
|
2379
|
-
if (!Number.isInteger(start) ||
|
|
2380
|
-
!Number.isInteger(length) ||
|
|
2381
|
-
encoded.length !== length) {
|
|
2382
|
-
throw new Error("snapshot controller artifact state layout is invalid");
|
|
2383
|
-
}
|
|
2384
|
-
return portableConcatBytes(Uint8Array.from(normalized.script).slice(0, start), encoded, Uint8Array.from(normalized.script).slice(start + length));
|
|
2385
|
-
}
|
|
2386
|
-
function buildSnapshotBootstrapScriptForState(artifact, state) {
|
|
2387
|
-
const normalized = (0, abi_js_1.normalizeSilverScriptArtifact)(artifact);
|
|
2388
|
-
const encoded = encodePortableBootstrapState(state);
|
|
2389
|
-
const start = normalized.state_layout?.start;
|
|
2390
|
-
const length = normalized.state_layout?.len;
|
|
2391
|
-
if (normalized.contract_name !== "KCC20SnapshotBootstrap" ||
|
|
2392
|
-
!Number.isInteger(start) ||
|
|
2393
|
-
!Number.isInteger(length) ||
|
|
2394
|
-
encoded.length !== length) {
|
|
2395
|
-
throw new Error("snapshot bootstrap artifact state layout is invalid");
|
|
2396
|
-
}
|
|
2397
|
-
return portableConcatBytes(Uint8Array.from(normalized.script).slice(0, start), encoded, Uint8Array.from(normalized.script).slice(start + length));
|
|
2398
|
-
}
|
|
2399
|
-
function encodePortableControllerState(state) {
|
|
2400
|
-
return portableConcatBytes(portablePushData(state.tokenId), portablePushData(state.holderExtensionCommitment), portablePushData(state.manifestCommitment), portablePushData(state.snapshotContext), portablePushData(state.kcc20TemplateHash), portablePushData(portableI64(state.claimNotBeforeDaaScore)), portablePushData(portableI64(state.shardIndex)), portablePushData(portableI64(state.globalIndexStart)), portablePushData(portableI64(state.holderCount)), portablePushData(portableI64(state.treeDepth)), portablePushData(portableI64(state.kcc20TemplatePrefixLen)), portablePushData(portableI64(state.kcc20TemplateSuffixLen)), portablePushData(portableI64(state.controllerCellKas)), portablePushData(portableI64(state.reserveCellKas)), portablePushData(portableI64(state.recipientMinCellKas)), portablePushData(state.remainingRoot), portablePushData(portableI64(state.remainingAmount)), portablePushData(portableI64(state.claimsProcessed)));
|
|
2401
|
-
}
|
|
2402
|
-
function encodePortableBootstrapState(state) {
|
|
2403
|
-
return portableConcatBytes(portablePushData(state.migrationCommitment), portablePushData(state.manifestCommitment), portablePushData(state.holderExtensionCommitment), portablePushData(portableI64(state.totalSupply)), portablePushData(portableI64(state.claimNotBeforeDaaScore)), portablePushData(state.kcc20TemplateHash), portablePushData(portableI64(state.kcc20TemplatePrefixLen)), portablePushData(portableI64(state.kcc20TemplateSuffixLen)), portablePushData(portableI64(state.tokenCellKas)), portablePushData(portableI64(state.reserveCellKas)), portablePushData(portableI64(state.bootstrapCellKas)), portablePushData(state.approvalKey ?? state.approvalKeyA), portablePushData(portableI64(state.phase)), portablePushData(state.tokenId), portablePushData(state.shardPlanCommitment), portablePushData(state.activationDigest), portablePushData(portableI64(state.shardCount)));
|
|
2404
|
-
}
|
|
2405
|
-
function portablePushData(value) {
|
|
2406
|
-
const bytes = Uint8Array.from(value);
|
|
2407
|
-
if (bytes.length > 75)
|
|
2408
|
-
throw new Error("snapshot state push is too large");
|
|
2409
|
-
return portableConcatBytes(Uint8Array.of(bytes.length), bytes);
|
|
2410
|
-
}
|
|
2411
|
-
function portableI64(value) {
|
|
2412
|
-
let cursor = BigInt(value);
|
|
2413
|
-
if (cursor < 0n || cursor > 9223372036854775807n) {
|
|
2414
|
-
throw new Error("snapshot state integer is outside signed i64 range");
|
|
2415
|
-
}
|
|
2416
|
-
const bytes = new Uint8Array(8);
|
|
2417
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
2418
|
-
bytes[index] = Number(cursor & 0xffn);
|
|
2419
|
-
cursor >>= 8n;
|
|
2420
|
-
}
|
|
2421
|
-
return bytes;
|
|
2422
|
-
}
|
|
2423
|
-
function portableConcatBytes(...values) {
|
|
2424
|
-
const arrays = values.map((value) => Uint8Array.from(value));
|
|
2425
|
-
const output = new Uint8Array(arrays.reduce((sum, value) => sum + value.length, 0));
|
|
2426
|
-
let offset = 0;
|
|
2427
|
-
for (const value of arrays) {
|
|
2428
|
-
output.set(value, offset);
|
|
2429
|
-
offset += value.length;
|
|
2430
|
-
}
|
|
2431
|
-
return output;
|
|
2432
|
-
}
|
|
2433
1308
|
//# sourceMappingURL=snapshot-operation.js.map
|