@kaspacom/kcc20-tx-builder 0.1.0 → 0.2.5
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/dist/artifacts.d.ts +2 -0
- package/dist/artifacts.d.ts.map +1 -1
- package/dist/artifacts.js +3 -1
- package/dist/artifacts.js.map +1 -1
- package/dist/builder.d.ts +0 -2
- package/dist/builder.d.ts.map +1 -1
- package/dist/cjs/artifacts.d.ts +2 -0
- package/dist/cjs/artifacts.js +4 -2
- package/dist/cjs/artifacts.js.map +1 -1
- package/dist/cjs/builder.d.ts +0 -2
- package/dist/cjs/deploy-receipt.d.ts +45 -0
- package/dist/cjs/deploy-receipt.js +122 -0
- package/dist/cjs/deploy-receipt.js.map +1 -0
- package/dist/cjs/engine.js +336 -226
- package/dist/cjs/engine.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/protocol.d.ts +1 -0
- package/dist/cjs/protocol.js +15 -0
- package/dist/cjs/protocol.js.map +1 -1
- package/dist/deploy-receipt.d.ts +46 -0
- package/dist/deploy-receipt.d.ts.map +1 -0
- package/dist/deploy-receipt.js +119 -0
- package/dist/deploy-receipt.js.map +1 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +337 -227
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +1 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +14 -0
- package/dist/protocol.js.map +1 -1
- package/package.json +1 -1
- package/src/artifacts.ts +5 -1
- package/src/builder.ts +0 -3
- package/src/deploy-receipt.ts +200 -0
- package/src/engine.ts +429 -296
- package/src/index.ts +1 -0
- package/src/protocol.ts +21 -0
package/dist/cjs/engine.js
CHANGED
|
@@ -6,10 +6,11 @@ const sha256_1 = require("@noble/hashes/sha256");
|
|
|
6
6
|
const sale_common_js_1 = require("./sale-common.js");
|
|
7
7
|
const abi_js_1 = require("./abi.js");
|
|
8
8
|
const operations_js_1 = require("./operations.js");
|
|
9
|
+
const protocol_js_1 = require("./protocol.js");
|
|
10
|
+
const deploy_receipt_js_1 = require("./deploy-receipt.js");
|
|
9
11
|
const artifacts_js_1 = require("./artifacts.js");
|
|
10
12
|
function createKcc20PsktBuilderEngine(options) {
|
|
11
|
-
const
|
|
12
|
-
const process = { env: config };
|
|
13
|
+
const env = options.config ?? {};
|
|
13
14
|
class InjectedRpcClient {
|
|
14
15
|
inner;
|
|
15
16
|
constructor(rpcConfig) {
|
|
@@ -102,7 +103,7 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
102
103
|
KCC20_ORDERBOOK_SWEEP_ASK_COMPUTE_BUDGET_PROFILE.feeTicket,
|
|
103
104
|
],
|
|
104
105
|
]);
|
|
105
|
-
const KCC20_ARTIFACT_PATH =
|
|
106
|
+
const KCC20_ARTIFACT_PATH = artifacts_js_1.KCC20_CURRENT_NATIVE_ARTIFACT_KEY;
|
|
106
107
|
const WRAPPER_ARTIFACT_PATH = "KCC20Wrapper.placeholder.json";
|
|
107
108
|
const WRAPPED_ARTIFACT_PATH = "KCC20Orderbook.placeholder.json";
|
|
108
109
|
const FEE_TICKET_ARTIFACT_PATH = "KCC20FeeTicket.placeholder.json";
|
|
@@ -257,7 +258,7 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
257
258
|
denomination: parsePositiveU64(input.utilityTokenAmount, "FeeTicket utility token amount"),
|
|
258
259
|
};
|
|
259
260
|
try {
|
|
260
|
-
const artifact = selectFeeTicketArtifactForState(await readFeeTicketArtifacts(), rootState, requireKaspaAddress(input.rootAddress), input.network ||
|
|
261
|
+
const artifact = selectFeeTicketArtifactForState(await readFeeTicketArtifacts(), rootState, requireKaspaAddress(input.rootAddress), input.network || env.KASPA_NETWORK || "testnet-10", "active FeeTicket root UTXO address");
|
|
261
262
|
return {
|
|
262
263
|
recognizedArtifact: true,
|
|
263
264
|
batchCreateSupported: artifact.supportsBatchCreate,
|
|
@@ -349,13 +350,13 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
349
350
|
const rootOwner = (0, sale_common_js_1.requireHex32)(params.rootOwner || request.owner?.kcc20Owner, "FeeTicket root owner");
|
|
350
351
|
const utilityTokenId = (0, sale_common_js_1.requireHex32)(params.utilityTokenId, "FeeTicket utility token id");
|
|
351
352
|
const newDenomination = parsePositiveU64(params.utilityTokenAmount, "utilityTokenAmount");
|
|
352
|
-
const network = request.network ||
|
|
353
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
353
354
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
354
355
|
const rootAddress = requireKaspaAddress(rootUtxo.address);
|
|
355
|
-
const rpcUrl =
|
|
356
|
-
const priorityFee = parseU64(
|
|
356
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
357
|
+
const priorityFee = parseU64(env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
357
358
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
358
|
-
const computeBudget = parsePositiveNumber(
|
|
359
|
+
const computeBudget = parsePositiveNumber(env.KCC20_FEE_TICKET_COMPUTE_BUDGET || sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "computeBudget");
|
|
359
360
|
const currentState = kcc20FeeTicketStateFromUtxo(rootUtxo, request.owner);
|
|
360
361
|
if (currentState.mode !== 1) {
|
|
361
362
|
throw new Error("FeeTicket denomination update requires a root UTXO");
|
|
@@ -493,13 +494,13 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
493
494
|
if (totalDenomination > MAX_U64) {
|
|
494
495
|
throw new Error("FeeTicket batch utility token amount must fit in an unsigned 64-bit integer");
|
|
495
496
|
}
|
|
496
|
-
const network = request.network ||
|
|
497
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
497
498
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
498
|
-
const rpcUrl =
|
|
499
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
499
500
|
const tokenOutputSompi = configuredFeeTicketOutputSompiForQuantity(quantity);
|
|
500
|
-
const priorityFee = parseU64(
|
|
501
|
+
const priorityFee = parseU64(env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
501
502
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
502
|
-
const computeBudget = parsePositiveNumber(
|
|
503
|
+
const computeBudget = parsePositiveNumber(env.KCC20_FEE_TICKET_COMPUTE_BUDGET || sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "computeBudget");
|
|
503
504
|
const feeTicketArtifacts = await readFeeTicketArtifacts();
|
|
504
505
|
const rootState = {
|
|
505
506
|
ownerIdentifier: (0, sale_common_js_1.hexToBytes)(rootOwner),
|
|
@@ -721,12 +722,12 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
721
722
|
if (new Set(sourceOutpoints).size !== sourceOutpoints.length) {
|
|
722
723
|
throw new Error("FeeTicket burn source outpoints must be unique");
|
|
723
724
|
}
|
|
724
|
-
const network = request.network ||
|
|
725
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
725
726
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
726
|
-
const rpcUrl =
|
|
727
|
-
const priorityFee = parseU64(
|
|
727
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
728
|
+
const priorityFee = parseU64(env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
728
729
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
729
|
-
const computeBudget = parsePositiveNumber(
|
|
730
|
+
const computeBudget = parsePositiveNumber(env.KCC20_FEE_TICKET_COMPUTE_BUDGET || sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "computeBudget");
|
|
730
731
|
const artifacts = await readFeeTicketArtifacts();
|
|
731
732
|
const states = ticketUtxos.map((utxo) => kcc20FeeTicketStateFromUtxo(utxo, request.owner));
|
|
732
733
|
for (const state of states) {
|
|
@@ -864,12 +865,12 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
864
865
|
if (new Set(sourceOutpoints).size !== sourceOutpoints.length) {
|
|
865
866
|
throw new Error("FeeTicket transfer source outpoints must be unique");
|
|
866
867
|
}
|
|
867
|
-
const network = request.network ||
|
|
868
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
868
869
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
869
|
-
const rpcUrl =
|
|
870
|
-
const priorityFee = parseU64(
|
|
870
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
871
|
+
const priorityFee = parseU64(env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
871
872
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
872
|
-
const computeBudget = parsePositiveNumber(
|
|
873
|
+
const computeBudget = parsePositiveNumber(env.KCC20_FEE_TICKET_COMPUTE_BUDGET || sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "computeBudget");
|
|
873
874
|
const artifacts = await readFeeTicketArtifacts();
|
|
874
875
|
const states = ticketUtxos.map((utxo) => kcc20FeeTicketStateFromUtxo(utxo, request.owner));
|
|
875
876
|
for (const state of states) {
|
|
@@ -1005,7 +1006,7 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
1005
1006
|
const configured = BigInt(configuredOutputSompi);
|
|
1006
1007
|
return configured > minimum ? configured : minimum;
|
|
1007
1008
|
}
|
|
1008
|
-
function configuredFeeTicketOutputSompiForQuantity(quantity, environment =
|
|
1009
|
+
function configuredFeeTicketOutputSompiForQuantity(quantity, environment = env) {
|
|
1009
1010
|
const configured = parseU64(Number(quantity) === 1
|
|
1010
1011
|
? environment.KCC20_FEE_TICKET_OUTPUT_SOMPI ||
|
|
1011
1012
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString()
|
|
@@ -1652,14 +1653,14 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
1652
1653
|
params.tokenDisplayScale ??
|
|
1653
1654
|
sale_common_js_1.DEFAULT_KCC20_PRICE_SCALE, "priceScale");
|
|
1654
1655
|
assertWrapperArtifactPriceScale(priceScale);
|
|
1655
|
-
const network = request.network ||
|
|
1656
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
1656
1657
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
1657
|
-
const rpcUrl =
|
|
1658
|
-
const amountTkas = parseAmountTkas(
|
|
1659
|
-
|
|
1658
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
1659
|
+
const amountTkas = parseAmountTkas(env.KCC20_WRAPPER_DEPLOY_OUTPUT_TKAS ||
|
|
1660
|
+
env.KCC20_DEPLOY_OUTPUT_TKAS ||
|
|
1660
1661
|
DEFAULT_DEPLOY_TKAS, "KCC20_WRAPPER_DEPLOY_OUTPUT_TKAS");
|
|
1661
|
-
const priorityFee = wrapperDeployPriorityFee(
|
|
1662
|
-
const computeBudget = parsePositiveNumber(
|
|
1662
|
+
const priorityFee = wrapperDeployPriorityFee(env.KCC20_WRAPPER_DEPLOY_PRIORITY_FEE_SOMPI);
|
|
1663
|
+
const computeBudget = parsePositiveNumber(env.KCC20_WRAPPER_DEPLOY_COMPUTE_BUDGET || 600, "computeBudget");
|
|
1663
1664
|
const wrapperArtifact = await readStaticArtifact(WRAPPER_ARTIFACT_PATH);
|
|
1664
1665
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
1665
1666
|
const wrappedArtifact = wrappedArtifacts[0].artifact;
|
|
@@ -1845,14 +1846,14 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
1845
1846
|
const recipientOwner = (0, sale_common_js_1.requireHex32)(params.recipientOwner || request.owner?.kcc20Owner, "wrapped recipient owner");
|
|
1846
1847
|
const tokenAmount = parsePositiveU64(params.tokenAmount, "tokenAmount");
|
|
1847
1848
|
const feeTicketId = (0, sale_common_js_1.requireHex32)(params.feeTicketId || sale_common_js_1.ZERO_HASH, "fee ticket id");
|
|
1848
|
-
const network = request.network ||
|
|
1849
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
1849
1850
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
1850
|
-
const rpcUrl =
|
|
1851
|
-
const tokenOutputSompi = parseU64(
|
|
1851
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
1852
|
+
const tokenOutputSompi = parseU64(env.KCC20_WRAP_TOKEN_OUTPUT_SOMPI ||
|
|
1852
1853
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
1853
|
-
const priorityFee = parseU64(
|
|
1854
|
+
const priorityFee = parseU64(env.KCC20_WRAP_PRIORITY_FEE_SOMPI ||
|
|
1854
1855
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
1855
|
-
const computeBudget = parsePositiveNumber(
|
|
1856
|
+
const computeBudget = parsePositiveNumber(env.KCC20_WRAP_COMPUTE_BUDGET || 700, "computeBudget");
|
|
1856
1857
|
const [wrapperArtifacts, wrappedArtifacts] = await Promise.all([
|
|
1857
1858
|
readWrapperArtifacts(),
|
|
1858
1859
|
readWrappedArtifacts(),
|
|
@@ -2116,14 +2117,14 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
2116
2117
|
const wrapperId = (0, sale_common_js_1.requireHex32)(params.wrappedMarketId || params.wrapperId, "wrapped market id");
|
|
2117
2118
|
const recipientOwner = (0, sale_common_js_1.requireHex32)(params.recipientOwner || request.owner?.kcc20Owner, "KCC20 recipient owner");
|
|
2118
2119
|
const tokenAmount = parsePositiveU64(params.tokenAmount, "tokenAmount");
|
|
2119
|
-
const network = request.network ||
|
|
2120
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
2120
2121
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
2121
|
-
const rpcUrl =
|
|
2122
|
-
const tokenOutputSompi = parseU64(
|
|
2122
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
2123
|
+
const tokenOutputSompi = parseU64(env.KCC20_UNWRAP_TOKEN_OUTPUT_SOMPI ||
|
|
2123
2124
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
2124
|
-
const priorityFee = parseU64(
|
|
2125
|
+
const priorityFee = parseU64(env.KCC20_UNWRAP_PRIORITY_FEE_SOMPI ||
|
|
2125
2126
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
2126
|
-
const computeBudget = parsePositiveNumber(
|
|
2127
|
+
const computeBudget = parsePositiveNumber(env.KCC20_UNWRAP_COMPUTE_BUDGET || 700, "computeBudget");
|
|
2127
2128
|
const [wrapperArtifacts, wrappedArtifacts] = await Promise.all([
|
|
2128
2129
|
readWrapperArtifacts(),
|
|
2129
2130
|
readWrappedArtifacts(),
|
|
@@ -2445,14 +2446,14 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
2445
2446
|
const expectedFeeTicketId = params.feeTicketId
|
|
2446
2447
|
? (0, sale_common_js_1.requireHex32)(params.feeTicketId, "fee ticket id")
|
|
2447
2448
|
: null;
|
|
2448
|
-
const network = request.network ||
|
|
2449
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
2449
2450
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
2450
|
-
const rpcUrl =
|
|
2451
|
-
const tokenOutputSompi = parseU64(
|
|
2451
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
2452
|
+
const tokenOutputSompi = parseU64(env.KCC20_ORDER_TOKEN_OUTPUT_SOMPI ||
|
|
2452
2453
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
2453
|
-
const priorityFee = parseU64(
|
|
2454
|
+
const priorityFee = parseU64(env.KCC20_ORDER_PRIORITY_FEE_SOMPI ||
|
|
2454
2455
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
2455
|
-
const computeBudget = parsePositiveNumber(
|
|
2456
|
+
const computeBudget = parsePositiveNumber(env.KCC20_ORDER_COMPUTE_BUDGET || 700, "computeBudget");
|
|
2456
2457
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
2457
2458
|
const activeUtxo = isBid ? rootUtxo : holderUtxo;
|
|
2458
2459
|
const activeState = kcc20V3WrappedStateFromUtxo(activeUtxo, canonicalTokenId, request.owner);
|
|
@@ -2692,14 +2693,14 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
2692
2693
|
const buyerOwner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "buyer owner");
|
|
2693
2694
|
const fillAmount = parsePositiveU64(params.tokenAmount, "tokenAmount");
|
|
2694
2695
|
const unitPriceSompi = parsePositiveU64(params.unitPriceSompi, "unitPriceSompi");
|
|
2695
|
-
const network = request.network ||
|
|
2696
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
2696
2697
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
2697
|
-
const rpcUrl =
|
|
2698
|
-
const tokenOutputSompi = parseU64(
|
|
2698
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
2699
|
+
const tokenOutputSompi = parseU64(env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
2699
2700
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
2700
|
-
const priorityFee = parseU64(
|
|
2701
|
+
const priorityFee = parseU64(env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
2701
2702
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
2702
|
-
const computeBudget = parsePositiveNumber(
|
|
2703
|
+
const computeBudget = parsePositiveNumber(env.KCC20_FILL_COMPUTE_BUDGET || 800, "computeBudget");
|
|
2703
2704
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
2704
2705
|
const ticketArtifacts = ticketUtxo ? await readFeeTicketArtifacts() : null;
|
|
2705
2706
|
const askState = kcc20V3WrappedStateFromUtxo(askUtxo, canonicalTokenId, request.owner);
|
|
@@ -2977,14 +2978,14 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
2977
2978
|
const sellerOwner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "seller owner");
|
|
2978
2979
|
const fillAmount = parsePositiveU64(params.tokenAmount, "tokenAmount");
|
|
2979
2980
|
const unitPriceSompi = parsePositiveU64(params.unitPriceSompi, "unitPriceSompi");
|
|
2980
|
-
const network = request.network ||
|
|
2981
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
2981
2982
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
2982
|
-
const rpcUrl =
|
|
2983
|
-
const tokenOutputSompi = parseU64(
|
|
2983
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
2984
|
+
const tokenOutputSompi = parseU64(env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
2984
2985
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
2985
|
-
const priorityFee = parseU64(
|
|
2986
|
+
const priorityFee = parseU64(env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
2986
2987
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
2987
|
-
const computeBudget = parsePositiveNumber(
|
|
2988
|
+
const computeBudget = parsePositiveNumber(env.KCC20_FILL_COMPUTE_BUDGET || 800, "computeBudget");
|
|
2988
2989
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
2989
2990
|
const ticketArtifacts = ticketUtxo ? await readFeeTicketArtifacts() : null;
|
|
2990
2991
|
const bidState = kcc20V3WrappedStateFromUtxo(bidUtxo, canonicalTokenId, request.owner);
|
|
@@ -3383,12 +3384,12 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
3383
3384
|
const canonicalTokenId = (0, sale_common_js_1.requireHex32)(params.canonicalCovenantId || params.covenantId, "canonical token id");
|
|
3384
3385
|
const wrapperId = (0, sale_common_js_1.requireHex32)(params.wrappedMarketId || params.wrapperId, "wrapped market id");
|
|
3385
3386
|
const buyerOwner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "buyer owner");
|
|
3386
|
-
const network = request.network ||
|
|
3387
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
3387
3388
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
3388
|
-
const rpcUrl =
|
|
3389
|
-
const tokenOutputSompi = parseU64(
|
|
3389
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
3390
|
+
const tokenOutputSompi = parseU64(env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
3390
3391
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
3391
|
-
const priorityFee = parseU64(
|
|
3392
|
+
const priorityFee = parseU64(env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
3392
3393
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
3393
3394
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
3394
3395
|
const ticketArtifacts = params.feeTicketId
|
|
@@ -3746,12 +3747,12 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
3746
3747
|
const canonicalTokenId = (0, sale_common_js_1.requireHex32)(params.canonicalCovenantId || params.covenantId, "canonical token id");
|
|
3747
3748
|
const wrapperId = (0, sale_common_js_1.requireHex32)(params.wrappedMarketId || params.wrapperId, "wrapped market id");
|
|
3748
3749
|
const sellerOwner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "seller owner");
|
|
3749
|
-
const network = request.network ||
|
|
3750
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
3750
3751
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
3751
|
-
const rpcUrl =
|
|
3752
|
-
const tokenOutputSompi = parseU64(
|
|
3752
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
3753
|
+
const tokenOutputSompi = parseU64(env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
3753
3754
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
3754
|
-
const priorityFee = parseU64(
|
|
3755
|
+
const priorityFee = parseU64(env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
3755
3756
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
3756
3757
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
3757
3758
|
const wrappedArtifact = wrappedArtifacts[0].artifact;
|
|
@@ -4243,12 +4244,12 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
4243
4244
|
const canonicalTokenId = (0, sale_common_js_1.requireHex32)(params.canonicalCovenantId || params.covenantId, "canonical token id");
|
|
4244
4245
|
const wrapperId = (0, sale_common_js_1.requireHex32)(params.wrappedMarketId || params.wrapperId, "wrapped market id");
|
|
4245
4246
|
const sellerOwner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "seller owner");
|
|
4246
|
-
const network = request.network ||
|
|
4247
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
4247
4248
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
4248
|
-
const rpcUrl =
|
|
4249
|
-
const configuredTokenOutputSompi = parseU64(
|
|
4249
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
4250
|
+
const configuredTokenOutputSompi = parseU64(env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
4250
4251
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
4251
|
-
const priorityFee = parseU64(
|
|
4252
|
+
const priorityFee = parseU64(env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
4252
4253
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
4253
4254
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
4254
4255
|
const ticketArtifacts = params.feeTicketId
|
|
@@ -4758,16 +4759,16 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
4758
4759
|
params.wrapperId, "wrapped market id");
|
|
4759
4760
|
const requestedWrapperId = (0, sale_common_js_1.requireHex32)(params.wrappedMarketId || params.wrapperId || wrapperId, "requested wrapped market id");
|
|
4760
4761
|
const owner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "token owner");
|
|
4761
|
-
const network = request.network ||
|
|
4762
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
4762
4763
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
4763
|
-
const rpcUrl =
|
|
4764
|
-
const priorityFee = parseU64(
|
|
4765
|
-
|
|
4764
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
4765
|
+
const priorityFee = parseU64(env.KCC20_CONSOLIDATE_PRIORITY_FEE_SOMPI ||
|
|
4766
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
4766
4767
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
4767
|
-
const configuredPrimaryComputeBudget = parsePositiveNumber(
|
|
4768
|
-
|
|
4768
|
+
const configuredPrimaryComputeBudget = parsePositiveNumber(env.KCC20_CONSOLIDATE_COMPUTE_BUDGET ||
|
|
4769
|
+
env.KCC20_FILL_COMPUTE_BUDGET ||
|
|
4769
4770
|
800, "configuredPrimaryComputeBudget");
|
|
4770
|
-
const peerComputeBudget = parsePositiveNumber(
|
|
4771
|
+
const peerComputeBudget = parsePositiveNumber(env.KCC20_CONSOLIDATE_PEER_COMPUTE_BUDGET || 200, "peerComputeBudget");
|
|
4771
4772
|
const computeBudget = Math.max(configuredPrimaryComputeBudget, 500 + holderUtxos.length * 100);
|
|
4772
4773
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
4773
4774
|
const states = holderUtxos.map((utxo) => kcc20V3WrappedStateFromUtxo(utxo, canonicalTokenId, request.owner));
|
|
@@ -4969,24 +4970,24 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
4969
4970
|
? (0, sale_common_js_1.requireHex32)(params.feeTicketId, "fee ticket id")
|
|
4970
4971
|
: null;
|
|
4971
4972
|
const maxFeeSompi = parseU64(params.maxFeeSompi || "0", "maxFeeSompi");
|
|
4972
|
-
const network = request.network ||
|
|
4973
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
4973
4974
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
4974
4975
|
const expectedOwner = request.owner?.kcc20Owner
|
|
4975
4976
|
? (0, sale_common_js_1.requireHex32)(request.owner.kcc20Owner, "matcher owner")
|
|
4976
4977
|
: null;
|
|
4977
|
-
const rpcUrl =
|
|
4978
|
-
const tokenOutputSompi = parseU64(
|
|
4979
|
-
|
|
4978
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
4979
|
+
const tokenOutputSompi = parseU64(env.KCC20_MATCHER_TOKEN_OUTPUT_SOMPI ||
|
|
4980
|
+
env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
4980
4981
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi");
|
|
4981
|
-
const priorityFee = parseU64(
|
|
4982
|
-
|
|
4982
|
+
const priorityFee = parseU64(env.KCC20_MATCHER_PRIORITY_FEE_SOMPI ||
|
|
4983
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
4983
4984
|
DEFAULT_MATCHER_PRIORITY_FEE.toString(), "priorityFee");
|
|
4984
|
-
const networkFeeReserve = parseU64(
|
|
4985
|
+
const networkFeeReserve = parseU64(env.KCC20_MATCHER_NETWORK_FEE_RESERVE_SOMPI || "5000000", "networkFeeReserve");
|
|
4985
4986
|
const transactionFeeReserve = priorityFee + networkFeeReserve;
|
|
4986
|
-
const computeBudget = parsePositiveNumber(
|
|
4987
|
-
|
|
4987
|
+
const computeBudget = parsePositiveNumber(env.KCC20_MATCHER_COMPUTE_BUDGET ||
|
|
4988
|
+
env.KCC20_FILL_COMPUTE_BUDGET ||
|
|
4988
4989
|
800, "computeBudget");
|
|
4989
|
-
const privateKeyHex = String(
|
|
4990
|
+
const privateKeyHex = String(env.KCC20_WRAPPER_OPERATOR_PRIVATE_KEY || "")
|
|
4990
4991
|
.trim()
|
|
4991
4992
|
.replace(/^0x/i, "");
|
|
4992
4993
|
if (!privateKeyHex) {
|
|
@@ -5432,12 +5433,12 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
5432
5433
|
const wrapperId = (0, sale_common_js_1.requireHex32)(params.wrappedMarketId || params.wrapperId, "wrapped market id");
|
|
5433
5434
|
const owner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "order owner");
|
|
5434
5435
|
const targetOrderId = requireOrderId(params.targetOrderId, "target order id");
|
|
5435
|
-
const network = request.network ||
|
|
5436
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
5436
5437
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
5437
|
-
const rpcUrl =
|
|
5438
|
-
const priorityFee = parseU64(
|
|
5438
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
5439
|
+
const priorityFee = parseU64(env.KCC20_CANCEL_PRIORITY_FEE_SOMPI ||
|
|
5439
5440
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
5440
|
-
const computeBudget = parsePositiveNumber(
|
|
5441
|
+
const computeBudget = parsePositiveNumber(env.KCC20_CANCEL_COMPUTE_BUDGET || 800, "computeBudget");
|
|
5441
5442
|
const wrappedArtifacts = await readWrappedArtifacts();
|
|
5442
5443
|
const orderState = kcc20V3WrappedStateFromUtxo(orderUtxo, canonicalTokenId, request.owner);
|
|
5443
5444
|
if (orderState.mode !== expectedMode) {
|
|
@@ -5649,14 +5650,14 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
5649
5650
|
const minterTxid = (0, sale_common_js_1.requireHex32)(activeMinterUtxo.txidHex, "minter txid");
|
|
5650
5651
|
const minterVout = parseVout(activeMinterUtxo.vout, "minter vout");
|
|
5651
5652
|
const minterAddress = requireKaspaAddress(activeMinterUtxo.address);
|
|
5652
|
-
const network = request.network ||
|
|
5653
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
5653
5654
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
5654
|
-
const rpcUrl =
|
|
5655
|
-
const tokenOutputSompi = assertKcc20TokenOutputSompi(parseU64(
|
|
5655
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
5656
|
+
const tokenOutputSompi = assertKcc20TokenOutputSompi(parseU64(env.KCC20_MINT_TOKEN_OUTPUT_SOMPI ||
|
|
5656
5657
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi"), "mint");
|
|
5657
|
-
const priorityFee = parseU64(
|
|
5658
|
+
const priorityFee = parseU64(env.KCC20_MINT_PRIORITY_FEE_SOMPI ||
|
|
5658
5659
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
5659
|
-
const computeBudget = parsePositiveNumber(
|
|
5660
|
+
const computeBudget = parsePositiveNumber(env.KCC20_MINT_COMPUTE_BUDGET || sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "computeBudget");
|
|
5660
5661
|
const inputState = {
|
|
5661
5662
|
amount: 0n,
|
|
5662
5663
|
owner: (0, sale_common_js_1.hexToBytes)(minterOwner),
|
|
@@ -5894,84 +5895,130 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
5894
5895
|
async function buildKcc20SetPublicMintActivePskt(input) {
|
|
5895
5896
|
const request = input.request || {};
|
|
5896
5897
|
const params = request.params || {};
|
|
5897
|
-
const
|
|
5898
|
-
|
|
5898
|
+
const requestedMinterUtxos = Array.isArray(params.activeMinterUtxos) &&
|
|
5899
|
+
params.activeMinterUtxos.length > 0
|
|
5900
|
+
? params.activeMinterUtxos
|
|
5901
|
+
: params.activeMinterUtxo
|
|
5902
|
+
? [params.activeMinterUtxo]
|
|
5903
|
+
: [];
|
|
5904
|
+
if (requestedMinterUtxos.length === 0) {
|
|
5899
5905
|
throw new Error("active KCC20 mint-authority UTXO is required");
|
|
5900
5906
|
}
|
|
5901
5907
|
if (typeof params.active !== "boolean") {
|
|
5902
5908
|
throw new Error("active must be a boolean");
|
|
5903
5909
|
}
|
|
5904
5910
|
const covenantId = (0, sale_common_js_1.requireHex32)(params.covenantId, "canonical covenant id");
|
|
5905
|
-
const network = request.network ||
|
|
5911
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
5906
5912
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
5907
5913
|
const walletOwner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "authenticated wallet owner");
|
|
5908
|
-
const minterAddress = requireKaspaAddress(activeMinterUtxo.address);
|
|
5909
|
-
const minterOwner = (0, sale_common_js_1.requireHex32)(activeMinterUtxo.state?.owner ?? activeMinterUtxo.state?.ownerIdentifier, "active mint-authority owner");
|
|
5910
|
-
const minterOwnerScheme = parseOwnerScheme(activeMinterUtxo.state?.ownerScheme ??
|
|
5911
|
-
activeMinterUtxo.state?.identifierType ??
|
|
5912
|
-
0, "active mint-authority owner scheme");
|
|
5913
|
-
if (minterOwnerScheme !== 0) {
|
|
5914
|
-
throw new Error("public mint availability requires a pubkey-owned minter");
|
|
5915
|
-
}
|
|
5916
|
-
if (minterOwner !== walletOwner) {
|
|
5917
|
-
throw new Error("public mint availability requires authenticated wallet to own the active minter UTXO");
|
|
5918
|
-
}
|
|
5919
5914
|
const mintPolicy = params.mintPolicy || {};
|
|
5920
|
-
const remainingSupply = parsePositiveU64(activeMinterUtxo.state?.remainingSupply ?? mintPolicy.remainingSupply, "active mint-authority remaining supply");
|
|
5921
5915
|
const displayScale = parsePositiveU64(params.priceScale ??
|
|
5922
5916
|
params.tokenDisplayScale ??
|
|
5923
5917
|
sale_common_js_1.DEFAULT_KCC20_PRICE_SCALE, "displayScale");
|
|
5924
|
-
const
|
|
5925
|
-
|
|
5918
|
+
const seenOutpoints = new Set();
|
|
5919
|
+
const laneContexts = (await Promise.all(requestedMinterUtxos.map(async (activeMinterUtxo, laneIndex) => {
|
|
5920
|
+
if (activeMinterUtxo.state?.isMintAuthority !== true ||
|
|
5921
|
+
(0, sale_common_js_1.parseMintPolicy)(activeMinterUtxo.state?.mintPolicy) !== 2) {
|
|
5922
|
+
throw new Error("public mint availability requires public mint-authority lanes");
|
|
5923
|
+
}
|
|
5924
|
+
const minterAddress = requireKaspaAddress(activeMinterUtxo.address);
|
|
5925
|
+
const minterOwner = (0, sale_common_js_1.requireHex32)(activeMinterUtxo.state?.owner ??
|
|
5926
|
+
activeMinterUtxo.state?.ownerIdentifier, "active mint-authority owner");
|
|
5927
|
+
const minterOwnerScheme = parseOwnerScheme(activeMinterUtxo.state?.ownerScheme ??
|
|
5928
|
+
activeMinterUtxo.state?.identifierType ??
|
|
5929
|
+
0, "active mint-authority owner scheme");
|
|
5930
|
+
if (minterOwnerScheme !== 0) {
|
|
5931
|
+
throw new Error("public mint availability requires a pubkey-owned minter");
|
|
5932
|
+
}
|
|
5933
|
+
if (minterOwner !== walletOwner) {
|
|
5934
|
+
throw new Error("public mint availability requires authenticated wallet to own every active minter UTXO");
|
|
5935
|
+
}
|
|
5936
|
+
const remainingSupply = parsePositiveU64(activeMinterUtxo.state?.remainingSupply ??
|
|
5937
|
+
mintPolicy.remainingSupply, "active mint-authority remaining supply");
|
|
5938
|
+
const extension = kcc20MintExtensionFromSources(activeMinterUtxo, params, mintPolicy, 2, remainingSupply, displayScale);
|
|
5939
|
+
if (extension.publicMintActive === params.active) {
|
|
5940
|
+
return null;
|
|
5941
|
+
}
|
|
5942
|
+
const inputState = {
|
|
5943
|
+
amount: 0n,
|
|
5944
|
+
owner: (0, sale_common_js_1.hexToBytes)(minterOwner),
|
|
5945
|
+
ownerScheme: minterOwnerScheme,
|
|
5946
|
+
borrowScheme: 0,
|
|
5947
|
+
borrowGuard: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
5948
|
+
extensionCommitment: (0, abi_js_1.mintExtensionCommitment)(extension),
|
|
5949
|
+
};
|
|
5950
|
+
const nextExtension = {
|
|
5951
|
+
...extension,
|
|
5952
|
+
publicMintActive: params.active,
|
|
5953
|
+
};
|
|
5954
|
+
const outputState = {
|
|
5955
|
+
...inputState,
|
|
5956
|
+
extensionCommitment: (0, abi_js_1.mintExtensionCommitment)(nextExtension),
|
|
5957
|
+
};
|
|
5958
|
+
const resolvedArtifact = await resolveKcc20ArtifactForState(inputState, minterAddress, network);
|
|
5959
|
+
(0, abi_js_1.dispatchTagFor)(resolvedArtifact.artifact, "set_public_mint_active");
|
|
5960
|
+
const minterTxid = (0, sale_common_js_1.requireHex32)(activeMinterUtxo.txidHex, "minter txid");
|
|
5961
|
+
const minterVout = parseVout(activeMinterUtxo.vout, "minter vout");
|
|
5962
|
+
const outpoint = `${minterTxid}:${minterVout}`;
|
|
5963
|
+
if (seenOutpoints.has(outpoint)) {
|
|
5964
|
+
throw new Error(`duplicate active minter outpoint ${outpoint}`);
|
|
5965
|
+
}
|
|
5966
|
+
seenOutpoints.add(outpoint);
|
|
5967
|
+
return {
|
|
5968
|
+
activeMinterUtxo,
|
|
5969
|
+
laneIndex,
|
|
5970
|
+
minterAddress,
|
|
5971
|
+
minterTxid,
|
|
5972
|
+
minterVout,
|
|
5973
|
+
outpoint,
|
|
5974
|
+
remainingSupply,
|
|
5975
|
+
extension,
|
|
5976
|
+
nextExtension,
|
|
5977
|
+
inputState,
|
|
5978
|
+
outputState,
|
|
5979
|
+
resolvedArtifact,
|
|
5980
|
+
};
|
|
5981
|
+
}))).filter(Boolean);
|
|
5982
|
+
if (laneContexts.length === 0) {
|
|
5926
5983
|
throw new Error(params.active
|
|
5927
5984
|
? "public mint is not paused"
|
|
5928
5985
|
: "public mint is not active");
|
|
5929
5986
|
}
|
|
5930
|
-
const
|
|
5931
|
-
amount: 0n,
|
|
5932
|
-
owner: (0, sale_common_js_1.hexToBytes)(minterOwner),
|
|
5933
|
-
ownerScheme: minterOwnerScheme,
|
|
5934
|
-
borrowScheme: 0,
|
|
5935
|
-
borrowGuard: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
5936
|
-
extensionCommitment: (0, abi_js_1.mintExtensionCommitment)(extension),
|
|
5937
|
-
};
|
|
5938
|
-
const nextExtension = { ...extension, publicMintActive: params.active };
|
|
5939
|
-
const outputState = {
|
|
5940
|
-
...inputState,
|
|
5941
|
-
extensionCommitment: (0, abi_js_1.mintExtensionCommitment)(nextExtension),
|
|
5942
|
-
};
|
|
5943
|
-
const resolvedArtifact = await resolveKcc20ArtifactForState(inputState, minterAddress, network);
|
|
5944
|
-
const artifact = resolvedArtifact.artifact;
|
|
5945
|
-
(0, abi_js_1.dispatchTagFor)(artifact, "set_public_mint_active");
|
|
5946
|
-
const minterTxid = (0, sale_common_js_1.requireHex32)(activeMinterUtxo.txidHex, "minter txid");
|
|
5947
|
-
const minterVout = parseVout(activeMinterUtxo.vout, "minter vout");
|
|
5948
|
-
const priorityFee = parseU64(process.env.KCC20_MINT_AVAILABILITY_PRIORITY_FEE_SOMPI ||
|
|
5987
|
+
const priorityFee = parseU64(env.KCC20_MINT_AVAILABILITY_PRIORITY_FEE_SOMPI ||
|
|
5949
5988
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
5950
|
-
const computeBudget = parsePositiveNumber(
|
|
5989
|
+
const computeBudget = parsePositiveNumber(env.KCC20_MINT_AVAILABILITY_COMPUTE_BUDGET ||
|
|
5951
5990
|
sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "computeBudget");
|
|
5952
5991
|
const rpc = new kaspaWasm.RpcClient({
|
|
5953
|
-
url:
|
|
5992
|
+
url: env.KASPA_WRPC_URL || DEFAULT_WRPC_URL,
|
|
5954
5993
|
encoding: kaspaWasm.Encoding.Borsh,
|
|
5955
5994
|
networkId: network,
|
|
5956
5995
|
});
|
|
5957
5996
|
await rpc.connect();
|
|
5958
5997
|
try {
|
|
5959
5998
|
const [minterUtxos, walletUtxos] = await Promise.all([
|
|
5960
|
-
getUtxosByAddresses(rpc, [
|
|
5999
|
+
getUtxosByAddresses(rpc, [
|
|
6000
|
+
...new Set(laneContexts.map((lane) => lane.minterAddress)),
|
|
6001
|
+
]),
|
|
5961
6002
|
getUtxosByAddresses(rpc, [walletAddress]),
|
|
5962
6003
|
]);
|
|
5963
|
-
const
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
6004
|
+
const resolvedLanes = laneContexts.map((lane, laneIndex) => {
|
|
6005
|
+
const minterEntry = findUtxoEntry(minterUtxos.entries, lane.minterTxid, lane.minterVout);
|
|
6006
|
+
if (!minterEntry) {
|
|
6007
|
+
throw new Error(`active minter UTXO ${lane.outpoint} not found`);
|
|
6008
|
+
}
|
|
6009
|
+
const spendCovenantId = requireMatchingCovenantId(minterEntry, covenantId, `active minter lane ${laneIndex}`);
|
|
6010
|
+
return {
|
|
6011
|
+
...lane,
|
|
6012
|
+
laneIndex,
|
|
6013
|
+
minterEntry,
|
|
6014
|
+
spendCovenantId,
|
|
6015
|
+
minterInputSompi: BigInt(minterEntry.amount),
|
|
6016
|
+
};
|
|
6017
|
+
});
|
|
5969
6018
|
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(walletUtxos.entries, priorityFee + 10000n);
|
|
5970
|
-
const fundingInputIndex =
|
|
6019
|
+
const fundingInputIndex = resolvedLanes.length;
|
|
5971
6020
|
const fundingChange = BigInt(fundingEntry.amount) - priorityFee;
|
|
5972
|
-
const outputs =
|
|
5973
|
-
tokenOutput(kaspaWasm, artifact, outputState, minterInputSompi, spendCovenantId, 0),
|
|
5974
|
-
];
|
|
6021
|
+
const outputs = resolvedLanes.map((lane, laneIndex) => tokenOutput(kaspaWasm, lane.resolvedArtifact.artifact, lane.outputState, lane.minterInputSompi, lane.spendCovenantId, laneIndex));
|
|
5975
6022
|
let fundingChangeOutputIndex = -1;
|
|
5976
6023
|
if (fundingChange > 10000n) {
|
|
5977
6024
|
fundingChangeOutputIndex = outputs.length;
|
|
@@ -5981,13 +6028,13 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
5981
6028
|
version: 1,
|
|
5982
6029
|
lockTime: 0n,
|
|
5983
6030
|
inputs: [
|
|
5984
|
-
{
|
|
5985
|
-
previousOutpoint: minterEntry.outpoint,
|
|
5986
|
-
utxo: minterEntry,
|
|
6031
|
+
...resolvedLanes.map((lane) => ({
|
|
6032
|
+
previousOutpoint: lane.minterEntry.outpoint,
|
|
6033
|
+
utxo: lane.minterEntry,
|
|
5987
6034
|
sequence: 0n,
|
|
5988
6035
|
sigOpCount: 0,
|
|
5989
6036
|
computeBudget,
|
|
5990
|
-
},
|
|
6037
|
+
})),
|
|
5991
6038
|
{
|
|
5992
6039
|
previousOutpoint: fundingEntry.outpoint,
|
|
5993
6040
|
utxo: fundingEntry,
|
|
@@ -6002,25 +6049,29 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6002
6049
|
payload: new Uint8Array(),
|
|
6003
6050
|
});
|
|
6004
6051
|
(0, sale_common_js_1.setVersionOneInputMassFields)(unsignedTx, computeBudget);
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6052
|
+
unsignedTx.inputs[fundingInputIndex].computeBudget = 30;
|
|
6053
|
+
const scripts = resolvedLanes.map((lane, laneIndex) => ({
|
|
6054
|
+
inputIndex: laneIndex,
|
|
6055
|
+
scriptHex: (0, sale_common_js_1.bytesToHex)(lane.resolvedArtifact.script),
|
|
6008
6056
|
signType: 1,
|
|
6009
6057
|
signatureScript: {
|
|
6010
6058
|
mode: "ordered-args",
|
|
6011
|
-
args: kcc20SetPublicMintActiveOrderedArgs(artifact, extension, params.active,
|
|
6059
|
+
args: kcc20SetPublicMintActiveOrderedArgs(lane.resolvedArtifact.artifact, lane.extension, params.active, laneIndex),
|
|
6012
6060
|
},
|
|
6013
|
-
};
|
|
6061
|
+
}));
|
|
6014
6062
|
const predictSignedTransaction = (transaction) => {
|
|
6015
6063
|
const predicted = cloneTransactionForMassPreflight(kaspaWasm, transaction, "KCC20 public mint availability");
|
|
6016
6064
|
const dummySignature = dummySignatureBytes();
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6065
|
+
resolvedLanes.forEach((lane, laneIndex) => {
|
|
6066
|
+
const prefix = (0, abi_js_1.buildKcc20SetPublicMintActiveSigScript)(kaspaWasm, lane.resolvedArtifact.artifact, {
|
|
6067
|
+
extension: lane.extension,
|
|
6068
|
+
authoritySignature: dummySignature,
|
|
6069
|
+
active: params.active,
|
|
6070
|
+
minterOutputIndex: laneIndex,
|
|
6071
|
+
});
|
|
6072
|
+
predicted.inputs[laneIndex].signatureScript =
|
|
6073
|
+
encodeCovenantP2shSignatureScript(prefix, lane.resolvedArtifact.script);
|
|
6022
6074
|
});
|
|
6023
|
-
predicted.inputs[0].signatureScript = encodeCovenantP2shSignatureScript(prefix, resolvedArtifact.script);
|
|
6024
6075
|
predicted.inputs[fundingInputIndex].signatureScript =
|
|
6025
6076
|
encodeP2pkSignatureScript((0, sale_common_js_1.bytesToHex)(dummySignature));
|
|
6026
6077
|
return predicted;
|
|
@@ -6034,21 +6085,28 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6034
6085
|
schema: OUTPUT_SCHEMA,
|
|
6035
6086
|
psktTransactionJson,
|
|
6036
6087
|
signInputs: [{ index: fundingInputIndex, sighashType: 1 }],
|
|
6037
|
-
scripts
|
|
6088
|
+
scripts,
|
|
6038
6089
|
submitTransactionSupported: true,
|
|
6039
6090
|
metadata: {
|
|
6040
6091
|
builderKey: "kcc20.set-public-mint-active",
|
|
6041
6092
|
contract: "KCC20",
|
|
6042
6093
|
network,
|
|
6043
6094
|
walletAddress,
|
|
6044
|
-
covenantId
|
|
6045
|
-
minterOutpoint:
|
|
6095
|
+
covenantId,
|
|
6096
|
+
minterOutpoint: resolvedLanes[0].outpoint,
|
|
6097
|
+
minterOutpoints: resolvedLanes.map((lane) => lane.outpoint),
|
|
6046
6098
|
minterOutputIndex: 0,
|
|
6099
|
+
minterOutputIndexes: resolvedLanes.map((_, index) => index),
|
|
6100
|
+
mintLaneCount: Number(resolvedLanes[0].extension.mintLaneCount),
|
|
6101
|
+
updatedMintLaneCount: resolvedLanes.length,
|
|
6047
6102
|
publicMintActive: params.active,
|
|
6048
6103
|
mintPolicy: 2,
|
|
6049
|
-
remainingSupply: remainingSupply.toString(),
|
|
6050
|
-
|
|
6051
|
-
|
|
6104
|
+
remainingSupply: resolvedLanes[0].remainingSupply.toString(),
|
|
6105
|
+
remainingSupplies: resolvedLanes.map((lane) => lane.remainingSupply.toString()),
|
|
6106
|
+
extension: jsonKcc20MintExtension(resolvedLanes[0].nextExtension),
|
|
6107
|
+
extensions: resolvedLanes.map((lane) => jsonKcc20MintExtension(lane.nextExtension)),
|
|
6108
|
+
artifactVersion: resolvedLanes[0].resolvedArtifact.version,
|
|
6109
|
+
artifactVersions: resolvedLanes.map((lane) => lane.resolvedArtifact.version),
|
|
6052
6110
|
},
|
|
6053
6111
|
};
|
|
6054
6112
|
}
|
|
@@ -6105,16 +6163,16 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6105
6163
|
const covenantId = (0, sale_common_js_1.requireHex32)(params.activeHolderNativeCovenantId || params.covenantId, "canonical covenant id");
|
|
6106
6164
|
const appCanonicalTokenId = (0, sale_common_js_1.requireHex32)(params.appCanonicalCovenantId || params.covenantId || covenantId, "app canonical token id");
|
|
6107
6165
|
const owner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "token owner");
|
|
6108
|
-
const network = request.network ||
|
|
6166
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
6109
6167
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
6110
|
-
const rpcUrl =
|
|
6111
|
-
const priorityFee = parseU64(
|
|
6112
|
-
|
|
6168
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
6169
|
+
const priorityFee = parseU64(env.KCC20_CONSOLIDATE_PRIORITY_FEE_SOMPI ||
|
|
6170
|
+
env.KCC20_TRANSFER_PRIORITY_FEE_SOMPI ||
|
|
6113
6171
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
6114
|
-
const configuredPrimaryComputeBudget = parsePositiveNumber(
|
|
6115
|
-
|
|
6172
|
+
const configuredPrimaryComputeBudget = parsePositiveNumber(env.KCC20_CONSOLIDATE_COMPUTE_BUDGET ||
|
|
6173
|
+
env.KCC20_TRANSFER_COMPUTE_BUDGET ||
|
|
6116
6174
|
sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "configuredPrimaryComputeBudget");
|
|
6117
|
-
const peerComputeBudget = parsePositiveNumber(
|
|
6175
|
+
const peerComputeBudget = parsePositiveNumber(env.KCC20_CONSOLIDATE_PEER_COMPUTE_BUDGET || 200, "peerComputeBudget");
|
|
6118
6176
|
const computeBudget = Math.max(configuredPrimaryComputeBudget, 500 + holderUtxos.length * 100);
|
|
6119
6177
|
const states = holderUtxos.map((utxo) => kcc20StateFromUtxo(utxo, request.owner));
|
|
6120
6178
|
const primaryState = states[0];
|
|
@@ -6275,12 +6333,12 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6275
6333
|
const params = request.params || {};
|
|
6276
6334
|
const covenantId = (0, sale_common_js_1.requireHex32)(params.covenantId, "canonical covenant id");
|
|
6277
6335
|
const owner = (0, sale_common_js_1.requireHex32)(request.owner?.kcc20Owner, "token owner");
|
|
6278
|
-
const network = request.network ||
|
|
6336
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
6279
6337
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
6280
|
-
const rpcUrl =
|
|
6281
|
-
const priorityFee = parseU64(
|
|
6338
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
6339
|
+
const priorityFee = parseU64(env.KCC20_REVEAL_PRIORITY_FEE_SOMPI ||
|
|
6282
6340
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
6283
|
-
const computeBudget = parsePositiveNumber(
|
|
6341
|
+
const computeBudget = parsePositiveNumber(env.KCC20_REVEAL_COMPUTE_BUDGET || sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "computeBudget");
|
|
6284
6342
|
const inputState = kcc20StateFromUtxo(activeTokenUtxo, request.owner);
|
|
6285
6343
|
if (inputState.isMintAuthority) {
|
|
6286
6344
|
throw new Error("self-transfer reveal requires a KCC20 holder UTXO");
|
|
@@ -6415,14 +6473,14 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6415
6473
|
const recipientOwner = (0, sale_common_js_1.requireHex32)(params.recipientOwner, "transfer recipient owner");
|
|
6416
6474
|
const recipientOwnerScheme = parseOwnerScheme(params.recipientOwnerScheme ?? params.recipientOwnerType ?? 0, "recipientOwnerScheme");
|
|
6417
6475
|
const transferAmount = parsePositiveU64(params.tokenAmount, "tokenAmount");
|
|
6418
|
-
const network = request.network ||
|
|
6476
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
6419
6477
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
6420
|
-
const rpcUrl =
|
|
6421
|
-
const tokenOutputSompi = assertKcc20TokenOutputSompi(parseU64(
|
|
6478
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
6479
|
+
const tokenOutputSompi = assertKcc20TokenOutputSompi(parseU64(env.KCC20_TRANSFER_TOKEN_OUTPUT_SOMPI ||
|
|
6422
6480
|
sale_common_js_1.DEFAULT_TOKEN_OUTPUT_SOMPI.toString(), "tokenOutputSompi"), "transfer");
|
|
6423
|
-
const priorityFee = parseU64(
|
|
6481
|
+
const priorityFee = parseU64(env.KCC20_TRANSFER_PRIORITY_FEE_SOMPI ||
|
|
6424
6482
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
6425
|
-
const computeBudget = parsePositiveNumber(
|
|
6483
|
+
const computeBudget = parsePositiveNumber(env.KCC20_TRANSFER_COMPUTE_BUDGET || sale_common_js_1.DEFAULT_COMPUTE_BUDGET, "computeBudget");
|
|
6426
6484
|
const inputState = kcc20StateFromUtxo(activeHolderUtxo, request.owner);
|
|
6427
6485
|
if (inputState.isMintAuthority || inputState.amount <= 0n) {
|
|
6428
6486
|
throw new Error("KCC20 transfer requires a holder UTXO");
|
|
@@ -6591,15 +6649,15 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6591
6649
|
const mintPolicy = (0, sale_common_js_1.parseMintPolicy)(params.mintPolicy || (0, sale_common_js_1.mintPolicyName)(params.mintPolicyValue ?? 0));
|
|
6592
6650
|
const mintPriceSompi = parseU64(params.mintPricePerTokenSompi || "0", "mintPricePerTokenSompi");
|
|
6593
6651
|
const feeBps = parseFeeBps(params.protocolFeeBps ??
|
|
6594
|
-
|
|
6652
|
+
env.KCC20_PROTOCOL_FEE_BPS ??
|
|
6595
6653
|
sale_common_js_1.DEFAULT_KCC20_FEE_BPS);
|
|
6596
6654
|
const decimals = parseU64(params.decimals ?? "0", "decimals");
|
|
6597
6655
|
const priceScale = 10n ** decimals;
|
|
6598
|
-
const network = request.network ||
|
|
6656
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
6599
6657
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
6600
|
-
const rpcUrl =
|
|
6601
|
-
const amountTkas = parseAmountTkas(
|
|
6602
|
-
const priorityFee = parseU64(
|
|
6658
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
6659
|
+
const amountTkas = parseAmountTkas(env.KCC20_DEPLOY_OUTPUT_TKAS || DEFAULT_DEPLOY_TKAS);
|
|
6660
|
+
const priorityFee = parseU64(env.KCC20_DEPLOY_PRIORITY_FEE_SOMPI ||
|
|
6603
6661
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
6604
6662
|
const metadata = {
|
|
6605
6663
|
ticker: normalizeTicker(params.ticker || ""),
|
|
@@ -6616,6 +6674,12 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6616
6674
|
const artifact = await readStaticArtifact(KCC20_ARTIFACT_PATH);
|
|
6617
6675
|
const displayScale = priceScale;
|
|
6618
6676
|
const remainingSupply = maxSupply - premintSupply;
|
|
6677
|
+
const mintLaneCount = mintPolicy === 0
|
|
6678
|
+
? 1n
|
|
6679
|
+
: parseMintLaneCount(params.mintLaneCount ?? 1, "mintLaneCount");
|
|
6680
|
+
const mintLaneSupplies = mintPolicy === 0
|
|
6681
|
+
? []
|
|
6682
|
+
: (0, protocol_js_1.splitKcc20MintSupply)(remainingSupply, mintLaneCount);
|
|
6619
6683
|
const immutableExtension = {
|
|
6620
6684
|
kind: 1,
|
|
6621
6685
|
creator: (0, sale_common_js_1.hexToBytes)(owner),
|
|
@@ -6623,8 +6687,7 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6623
6687
|
name: (0, sale_common_js_1.asciiToBytes32)(metadata.name, "token name"),
|
|
6624
6688
|
displayScale,
|
|
6625
6689
|
maxSupply,
|
|
6626
|
-
|
|
6627
|
-
mintLaneCount: 1n,
|
|
6690
|
+
mintLaneCount,
|
|
6628
6691
|
mintPolicy,
|
|
6629
6692
|
mintPriceSompi,
|
|
6630
6693
|
treasury: (0, sale_common_js_1.hexToBytes)(treasury),
|
|
@@ -6632,23 +6695,32 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6632
6695
|
protocolFeeBps: BigInt(feeBps),
|
|
6633
6696
|
};
|
|
6634
6697
|
const holderCommitment = (0, abi_js_1.holderExtensionCommitment)(immutableExtension);
|
|
6635
|
-
const
|
|
6698
|
+
const baseExtension = mintPolicy === 0
|
|
6636
6699
|
? null
|
|
6637
6700
|
: {
|
|
6638
6701
|
...immutableExtension,
|
|
6639
|
-
remainingSupply,
|
|
6640
6702
|
publicMintActive: false,
|
|
6641
6703
|
holderExtensionCommitment: holderCommitment,
|
|
6642
6704
|
};
|
|
6705
|
+
const minterStates = baseExtension
|
|
6706
|
+
? mintLaneSupplies.map((laneSupply) => {
|
|
6707
|
+
const extension = { ...baseExtension, remainingSupply: laneSupply };
|
|
6708
|
+
return {
|
|
6709
|
+
extension,
|
|
6710
|
+
state: {
|
|
6711
|
+
amount: 0n,
|
|
6712
|
+
owner: (0, sale_common_js_1.hexToBytes)(owner),
|
|
6713
|
+
ownerScheme: 0,
|
|
6714
|
+
borrowScheme: 0,
|
|
6715
|
+
borrowGuard: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
6716
|
+
extensionCommitment: (0, abi_js_1.mintExtensionCommitment)(extension),
|
|
6717
|
+
},
|
|
6718
|
+
};
|
|
6719
|
+
})
|
|
6720
|
+
: [];
|
|
6721
|
+
const extension = minterStates[0]?.extension ?? null;
|
|
6643
6722
|
const state = extension
|
|
6644
|
-
?
|
|
6645
|
-
amount: 0n,
|
|
6646
|
-
owner: (0, sale_common_js_1.hexToBytes)(owner),
|
|
6647
|
-
ownerScheme: 0,
|
|
6648
|
-
borrowScheme: 0,
|
|
6649
|
-
borrowGuard: (0, sale_common_js_1.hexToBytes)(sale_common_js_1.ZERO_HASH),
|
|
6650
|
-
extensionCommitment: (0, abi_js_1.mintExtensionCommitment)(extension),
|
|
6651
|
-
}
|
|
6723
|
+
? minterStates[0].state
|
|
6652
6724
|
: {
|
|
6653
6725
|
amount: maxSupply,
|
|
6654
6726
|
owner: (0, sale_common_js_1.hexToBytes)(premintRecipient),
|
|
@@ -6667,19 +6739,26 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6667
6739
|
extensionCommitment: holderCommitment,
|
|
6668
6740
|
}
|
|
6669
6741
|
: null;
|
|
6742
|
+
const covenantStates = extension
|
|
6743
|
+
? minterStates.map(({ state }) => state)
|
|
6744
|
+
: [state];
|
|
6745
|
+
if (premintState)
|
|
6746
|
+
covenantStates.push(premintState);
|
|
6670
6747
|
const kw = kaspaWasm;
|
|
6671
6748
|
const { Encoding, GenesisCovenantGroup, RpcClient, Transaction, TransactionOutput, addressFromScriptPublicKey, payToAddressScript, payToScriptHashScript, } = kw;
|
|
6672
|
-
const
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6749
|
+
const covenantOutputs = covenantStates.map((covenantState) => {
|
|
6750
|
+
const script = (0, abi_js_1.buildKcc20ScriptForState)(artifact, covenantState);
|
|
6751
|
+
const scriptPublicKey = payToScriptHashScript(script);
|
|
6752
|
+
return {
|
|
6753
|
+
script,
|
|
6754
|
+
scriptPublicKey,
|
|
6755
|
+
address: addressFromScriptPublicKey(scriptPublicKey, network).toString(),
|
|
6756
|
+
};
|
|
6757
|
+
});
|
|
6758
|
+
const contractAddress = covenantOutputs[0].address;
|
|
6759
|
+
const canonicalCovenantId = (0, sale_common_js_1.p2shScriptHashHex)(kw, covenantOutputs[0].script);
|
|
6676
6760
|
const deploySompi = BigInt(Math.round(amountTkas * Number(sale_common_js_1.SOMPI_PER_TKAS)));
|
|
6677
|
-
const
|
|
6678
|
-
let premintAddress = null;
|
|
6679
|
-
if (premintState) {
|
|
6680
|
-
premintAddress = addressFromScriptPublicKey(payToScriptHashScript((0, abi_js_1.buildKcc20ScriptForState)(artifact, premintState)), network).toString();
|
|
6681
|
-
deployOutputs.push({ address: premintAddress, amount: deploySompi });
|
|
6682
|
-
}
|
|
6761
|
+
const premintOutputIndex = premintState ? covenantOutputs.length - 1 : null;
|
|
6683
6762
|
const rpc = new RpcClient({
|
|
6684
6763
|
url: rpcUrl,
|
|
6685
6764
|
encoding: Encoding.Borsh,
|
|
@@ -6688,20 +6767,17 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6688
6767
|
await rpc.connect();
|
|
6689
6768
|
try {
|
|
6690
6769
|
const utxos = await getUtxosByAddresses(rpc, [walletAddress]);
|
|
6691
|
-
const outputSompi = deploySompi * BigInt(
|
|
6770
|
+
const outputSompi = deploySompi * BigInt(covenantOutputs.length);
|
|
6692
6771
|
const fundingEntry = (0, sale_common_js_1.selectFundingEntry)(utxos.entries, outputSompi + priorityFee + 10000000n);
|
|
6693
|
-
const fundingChangeOutputIndex =
|
|
6772
|
+
const fundingChangeOutputIndex = covenantOutputs.length;
|
|
6694
6773
|
const change = (0, sale_common_js_1.utxoAmountSompi)(fundingEntry) - outputSompi - priorityFee;
|
|
6695
6774
|
if (change <= 10000n) {
|
|
6696
6775
|
throw (0, sale_common_js_1.kcc20PsktBuilderError)("deploy PSKT builder selected insufficient change", "KAS_FUNDING_CHANGE_TOO_SMALL");
|
|
6697
6776
|
}
|
|
6698
6777
|
const outputs = [
|
|
6699
|
-
new TransactionOutput(deploySompi,
|
|
6778
|
+
...covenantOutputs.map(({ scriptPublicKey }) => new TransactionOutput(deploySompi, scriptPublicKey)),
|
|
6700
6779
|
new TransactionOutput(change, payToAddressScript(walletAddress)),
|
|
6701
6780
|
];
|
|
6702
|
-
if (premintState) {
|
|
6703
|
-
outputs.push(new TransactionOutput(deploySompi, payToScriptHashScript((0, abi_js_1.buildKcc20ScriptForState)(artifact, premintState))));
|
|
6704
|
-
}
|
|
6705
6781
|
const unsignedTx = new Transaction({
|
|
6706
6782
|
version: 1,
|
|
6707
6783
|
lockTime: 0n,
|
|
@@ -6736,17 +6812,8 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6736
6812
|
});
|
|
6737
6813
|
unsignedTx.version = 1;
|
|
6738
6814
|
(0, sale_common_js_1.setVersionOneInputMassFields)(unsignedTx);
|
|
6739
|
-
const covenantOutputIndex =
|
|
6740
|
-
|
|
6741
|
-
throw new Error("final transaction did not contain the KCC20 output");
|
|
6742
|
-
const covenantOutputIndexes = [covenantOutputIndex];
|
|
6743
|
-
let premintOutputIndex = null;
|
|
6744
|
-
if (premintAddress) {
|
|
6745
|
-
premintOutputIndex = (0, sale_common_js_1.findOutputIndex)(unsignedTx, premintAddress, network, addressFromScriptPublicKey);
|
|
6746
|
-
if (premintOutputIndex < 0)
|
|
6747
|
-
throw new Error("final transaction did not contain the KCC20 premint output");
|
|
6748
|
-
covenantOutputIndexes.push(premintOutputIndex);
|
|
6749
|
-
}
|
|
6815
|
+
const covenantOutputIndex = 0;
|
|
6816
|
+
const covenantOutputIndexes = covenantOutputs.map((_, index) => index);
|
|
6750
6817
|
unsignedTx.populateGenesisCovenants([
|
|
6751
6818
|
new GenesisCovenantGroup(0, covenantOutputIndexes),
|
|
6752
6819
|
]);
|
|
@@ -6759,6 +6826,7 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6759
6826
|
if (typeof psktTransactionJson !== "string") {
|
|
6760
6827
|
throw new Error("KCC20 deploy PSKT serialization did not return JSON text");
|
|
6761
6828
|
}
|
|
6829
|
+
const revealScriptHex = (0, sale_common_js_1.bytesToHex)(covenantOutputs[covenantOutputIndex].script);
|
|
6762
6830
|
return {
|
|
6763
6831
|
schema: OUTPUT_SCHEMA,
|
|
6764
6832
|
psktTransactionJson,
|
|
@@ -6774,6 +6842,9 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6774
6842
|
walletAddress,
|
|
6775
6843
|
contractAddress,
|
|
6776
6844
|
covenantOutputIndex,
|
|
6845
|
+
minterOutputIndexes: extension
|
|
6846
|
+
? minterStates.map((_, index) => index)
|
|
6847
|
+
: undefined,
|
|
6777
6848
|
premintOutputIndex,
|
|
6778
6849
|
covenantId: kip20BindingCovenantId,
|
|
6779
6850
|
scriptHashHex: canonicalCovenantId,
|
|
@@ -6784,6 +6855,44 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6784
6855
|
mintPolicy,
|
|
6785
6856
|
publicMintActive: mintPolicy === 2 ? false : undefined,
|
|
6786
6857
|
mintLaneCount: immutableExtension.mintLaneCount.toString(),
|
|
6858
|
+
holderExtensionCommitment: (0, sale_common_js_1.bytesToHex)(holderCommitment),
|
|
6859
|
+
revealScriptHex,
|
|
6860
|
+
maximumFeeSompi: ([...feeAdjustedTx.inputs].reduce((sum, input) => sum + BigInt(input.utxo?.amount ?? input.utxo?.value), 0n) -
|
|
6861
|
+
[...feeAdjustedTx.outputs].reduce((sum, output) => sum + BigInt(output.value ?? output.amount), 0n)).toString(),
|
|
6862
|
+
intentInputs: [{ role: "creator-funding", index: 0 }],
|
|
6863
|
+
intentOutputs: (0, deploy_receipt_js_1.buildKcc20DeployIntentOutputs)({
|
|
6864
|
+
mintPolicy,
|
|
6865
|
+
covenantId: kip20BindingCovenantId,
|
|
6866
|
+
creator: owner,
|
|
6867
|
+
premintRecipient,
|
|
6868
|
+
premintOwnerScheme,
|
|
6869
|
+
maxSupply,
|
|
6870
|
+
premintSupply,
|
|
6871
|
+
borrowGuard: sale_common_js_1.ZERO_HASH,
|
|
6872
|
+
fixedOutput: mintPolicy === 0
|
|
6873
|
+
? {
|
|
6874
|
+
index: covenantOutputIndex,
|
|
6875
|
+
revealScriptHex,
|
|
6876
|
+
extensionCommitment: (0, sale_common_js_1.bytesToHex)(holderCommitment),
|
|
6877
|
+
}
|
|
6878
|
+
: undefined,
|
|
6879
|
+
minterOutputs: minterStates.map(({ state }, index) => ({
|
|
6880
|
+
index,
|
|
6881
|
+
revealScriptHex: (0, sale_common_js_1.bytesToHex)(covenantOutputs[index].script),
|
|
6882
|
+
extensionCommitment: (0, sale_common_js_1.bytesToHex)(state.extensionCommitment),
|
|
6883
|
+
remainingSupply: mintLaneSupplies[index],
|
|
6884
|
+
})),
|
|
6885
|
+
premintOutput: premintState && premintOutputIndex !== null
|
|
6886
|
+
? {
|
|
6887
|
+
index: premintOutputIndex,
|
|
6888
|
+
revealScriptHex: (0, sale_common_js_1.bytesToHex)(covenantOutputs[premintOutputIndex].script),
|
|
6889
|
+
extensionCommitment: (0, sale_common_js_1.bytesToHex)(premintState.extensionCommitment),
|
|
6890
|
+
}
|
|
6891
|
+
: undefined,
|
|
6892
|
+
}),
|
|
6893
|
+
mintLaneSupplies: extension
|
|
6894
|
+
? mintLaneSupplies.map((supply) => supply.toString())
|
|
6895
|
+
: undefined,
|
|
6787
6896
|
extension: extension ? jsonKcc20MintExtension(extension) : undefined,
|
|
6788
6897
|
...(0, sale_common_js_1.stateToReceiptFields)(state),
|
|
6789
6898
|
},
|
|
@@ -6799,11 +6908,11 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
6799
6908
|
const owner = (0, sale_common_js_1.requireHex32)(params.rootOwner || request.owner?.kcc20Owner, "root owner");
|
|
6800
6909
|
const utilityTokenId = (0, sale_common_js_1.requireHex32)(params.utilityTokenId, "utility token id");
|
|
6801
6910
|
const denomination = parsePositiveU64(params.utilityTokenAmount, "utilityTokenAmount");
|
|
6802
|
-
const network = request.network ||
|
|
6911
|
+
const network = request.network || env.KASPA_NETWORK || "testnet-10";
|
|
6803
6912
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
6804
|
-
const rpcUrl =
|
|
6805
|
-
const amountTkas = parseAmountTkas(
|
|
6806
|
-
const priorityFee = parseU64(
|
|
6913
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
6914
|
+
const amountTkas = parseAmountTkas(env.KCC20_FEE_TICKET_OUTPUT_TKAS || DEFAULT_DEPLOY_TKAS);
|
|
6915
|
+
const priorityFee = parseU64(env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
6807
6916
|
DEFAULT_PRIORITY_FEE.toString(), "priorityFee");
|
|
6808
6917
|
const artifact = await readStaticArtifact(FEE_TICKET_ARTIFACT_PATH);
|
|
6809
6918
|
const state = {
|
|
@@ -7796,8 +7905,8 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
7796
7905
|
return rpc.getUtxosByAddresses({ addresses });
|
|
7797
7906
|
}
|
|
7798
7907
|
async function retryUtxosByAddresses(rpc, addresses, isReady, initial) {
|
|
7799
|
-
const attempts = parseRetryInteger(
|
|
7800
|
-
const delayMs = parseRetryInteger(
|
|
7908
|
+
const attempts = parseRetryInteger(env.KCC20_SOURCE_UTXO_RETRY_ATTEMPTS, 3);
|
|
7909
|
+
const delayMs = parseRetryInteger(env.KCC20_SOURCE_UTXO_RETRY_DELAY_MS, 500);
|
|
7801
7910
|
let latest = initial ?? { entries: [] };
|
|
7802
7911
|
for (let attempt = 1; attempt < attempts; attempt += 1) {
|
|
7803
7912
|
if (delayMs > 0) {
|
|
@@ -8966,6 +9075,7 @@ function createKcc20PsktBuilderEngine(options) {
|
|
|
8966
9075
|
assertTransactionStorageMassStandard,
|
|
8967
9076
|
calculateToccataStorageMass,
|
|
8968
9077
|
parseQuotedProtocolFeeSompi,
|
|
9078
|
+
splitKcc20MintSupply: protocol_js_1.splitKcc20MintSupply,
|
|
8969
9079
|
}),
|
|
8970
9080
|
};
|
|
8971
9081
|
}
|