@kaspacom/kcc20-tx-builder 0.1.0 → 0.2.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/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/src/engine.ts
CHANGED
|
@@ -62,8 +62,11 @@ import {
|
|
|
62
62
|
ownerAuthorizationWitness,
|
|
63
63
|
} from "./abi.js";
|
|
64
64
|
import { KCC20_BUILDER_KEYS } from "./operations.js";
|
|
65
|
+
import { splitKcc20MintSupply } from "./protocol.js";
|
|
66
|
+
import { buildKcc20DeployIntentOutputs } from "./deploy-receipt.js";
|
|
65
67
|
import {
|
|
66
68
|
KCC20_ARTIFACT_SCRIPT_SHA256,
|
|
69
|
+
KCC20_CURRENT_NATIVE_ARTIFACT_KEY,
|
|
67
70
|
assertKcc20ArtifactScriptHash,
|
|
68
71
|
} from "./artifacts.js";
|
|
69
72
|
|
|
@@ -110,8 +113,7 @@ export interface Kcc20PsktBuilderEngine {
|
|
|
110
113
|
export function createKcc20PsktBuilderEngine(
|
|
111
114
|
options: Kcc20PsktBuilderEngineOptions,
|
|
112
115
|
): Kcc20PsktBuilderEngine {
|
|
113
|
-
const
|
|
114
|
-
const process = { env: config };
|
|
116
|
+
const env = options.config ?? {};
|
|
115
117
|
class InjectedRpcClient {
|
|
116
118
|
private readonly inner: any;
|
|
117
119
|
constructor(rpcConfig: unknown) {
|
|
@@ -205,7 +207,7 @@ export function createKcc20PsktBuilderEngine(
|
|
|
205
207
|
KCC20_ORDERBOOK_SWEEP_ASK_COMPUTE_BUDGET_PROFILE.feeTicket,
|
|
206
208
|
],
|
|
207
209
|
]);
|
|
208
|
-
const KCC20_ARTIFACT_PATH =
|
|
210
|
+
const KCC20_ARTIFACT_PATH = KCC20_CURRENT_NATIVE_ARTIFACT_KEY;
|
|
209
211
|
const WRAPPER_ARTIFACT_PATH = "KCC20Wrapper.placeholder.json";
|
|
210
212
|
const WRAPPED_ARTIFACT_PATH = "KCC20Orderbook.placeholder.json";
|
|
211
213
|
const FEE_TICKET_ARTIFACT_PATH = "KCC20FeeTicket.placeholder.json";
|
|
@@ -442,7 +444,7 @@ export function createKcc20PsktBuilderEngine(
|
|
|
442
444
|
await readFeeTicketArtifacts(),
|
|
443
445
|
rootState,
|
|
444
446
|
requireKaspaAddress(input.rootAddress),
|
|
445
|
-
input.network ||
|
|
447
|
+
input.network || env.KASPA_NETWORK || "testnet-10",
|
|
446
448
|
"active FeeTicket root UTXO address",
|
|
447
449
|
);
|
|
448
450
|
return {
|
|
@@ -569,17 +571,17 @@ export function createKcc20PsktBuilderEngine(
|
|
|
569
571
|
"utilityTokenAmount",
|
|
570
572
|
);
|
|
571
573
|
const network =
|
|
572
|
-
request.network ||
|
|
574
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
573
575
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
574
576
|
const rootAddress = requireKaspaAddress(rootUtxo.address);
|
|
575
|
-
const rpcUrl =
|
|
577
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
576
578
|
const priorityFee = parseU64(
|
|
577
|
-
|
|
579
|
+
env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
578
580
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
579
581
|
"priorityFee",
|
|
580
582
|
);
|
|
581
583
|
const computeBudget = parsePositiveNumber(
|
|
582
|
-
|
|
584
|
+
env.KCC20_FEE_TICKET_COMPUTE_BUDGET || DEFAULT_COMPUTE_BUDGET,
|
|
583
585
|
"computeBudget",
|
|
584
586
|
);
|
|
585
587
|
|
|
@@ -791,18 +793,18 @@ export function createKcc20PsktBuilderEngine(
|
|
|
791
793
|
);
|
|
792
794
|
}
|
|
793
795
|
const network =
|
|
794
|
-
request.network ||
|
|
796
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
795
797
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
796
|
-
const rpcUrl =
|
|
798
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
797
799
|
const tokenOutputSompi =
|
|
798
800
|
configuredFeeTicketOutputSompiForQuantity(quantity);
|
|
799
801
|
const priorityFee = parseU64(
|
|
800
|
-
|
|
802
|
+
env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
801
803
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
802
804
|
"priorityFee",
|
|
803
805
|
);
|
|
804
806
|
const computeBudget = parsePositiveNumber(
|
|
805
|
-
|
|
807
|
+
env.KCC20_FEE_TICKET_COMPUTE_BUDGET || DEFAULT_COMPUTE_BUDGET,
|
|
806
808
|
"computeBudget",
|
|
807
809
|
);
|
|
808
810
|
|
|
@@ -1147,16 +1149,16 @@ export function createKcc20PsktBuilderEngine(
|
|
|
1147
1149
|
}
|
|
1148
1150
|
|
|
1149
1151
|
const network =
|
|
1150
|
-
request.network ||
|
|
1152
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
1151
1153
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
1152
|
-
const rpcUrl =
|
|
1154
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
1153
1155
|
const priorityFee = parseU64(
|
|
1154
|
-
|
|
1156
|
+
env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
1155
1157
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
1156
1158
|
"priorityFee",
|
|
1157
1159
|
);
|
|
1158
1160
|
const computeBudget = parsePositiveNumber(
|
|
1159
|
-
|
|
1161
|
+
env.KCC20_FEE_TICKET_COMPUTE_BUDGET || DEFAULT_COMPUTE_BUDGET,
|
|
1160
1162
|
"computeBudget",
|
|
1161
1163
|
);
|
|
1162
1164
|
const artifacts = await readFeeTicketArtifacts();
|
|
@@ -1375,16 +1377,16 @@ export function createKcc20PsktBuilderEngine(
|
|
|
1375
1377
|
}
|
|
1376
1378
|
|
|
1377
1379
|
const network =
|
|
1378
|
-
request.network ||
|
|
1380
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
1379
1381
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
1380
|
-
const rpcUrl =
|
|
1382
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
1381
1383
|
const priorityFee = parseU64(
|
|
1382
|
-
|
|
1384
|
+
env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
1383
1385
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
1384
1386
|
"priorityFee",
|
|
1385
1387
|
);
|
|
1386
1388
|
const computeBudget = parsePositiveNumber(
|
|
1387
|
-
|
|
1389
|
+
env.KCC20_FEE_TICKET_COMPUTE_BUDGET || DEFAULT_COMPUTE_BUDGET,
|
|
1388
1390
|
"computeBudget",
|
|
1389
1391
|
);
|
|
1390
1392
|
const artifacts = await readFeeTicketArtifacts();
|
|
@@ -1598,7 +1600,7 @@ export function createKcc20PsktBuilderEngine(
|
|
|
1598
1600
|
|
|
1599
1601
|
function configuredFeeTicketOutputSompiForQuantity(
|
|
1600
1602
|
quantity,
|
|
1601
|
-
environment =
|
|
1603
|
+
environment = env,
|
|
1602
1604
|
) {
|
|
1603
1605
|
const configured = parseU64(
|
|
1604
1606
|
Number(quantity) === 1
|
|
@@ -2601,20 +2603,20 @@ export function createKcc20PsktBuilderEngine(
|
|
|
2601
2603
|
);
|
|
2602
2604
|
assertWrapperArtifactPriceScale(priceScale);
|
|
2603
2605
|
const network =
|
|
2604
|
-
request.network ||
|
|
2606
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
2605
2607
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
2606
|
-
const rpcUrl =
|
|
2608
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
2607
2609
|
const amountTkas = parseAmountTkas(
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
+
env.KCC20_WRAPPER_DEPLOY_OUTPUT_TKAS ||
|
|
2611
|
+
env.KCC20_DEPLOY_OUTPUT_TKAS ||
|
|
2610
2612
|
DEFAULT_DEPLOY_TKAS,
|
|
2611
2613
|
"KCC20_WRAPPER_DEPLOY_OUTPUT_TKAS",
|
|
2612
2614
|
);
|
|
2613
2615
|
const priorityFee = wrapperDeployPriorityFee(
|
|
2614
|
-
|
|
2616
|
+
env.KCC20_WRAPPER_DEPLOY_PRIORITY_FEE_SOMPI,
|
|
2615
2617
|
);
|
|
2616
2618
|
const computeBudget = parsePositiveNumber(
|
|
2617
|
-
|
|
2619
|
+
env.KCC20_WRAPPER_DEPLOY_COMPUTE_BUDGET || 600,
|
|
2618
2620
|
"computeBudget",
|
|
2619
2621
|
);
|
|
2620
2622
|
|
|
@@ -2914,21 +2916,21 @@ export function createKcc20PsktBuilderEngine(
|
|
|
2914
2916
|
"fee ticket id",
|
|
2915
2917
|
);
|
|
2916
2918
|
const network =
|
|
2917
|
-
request.network ||
|
|
2919
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
2918
2920
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
2919
|
-
const rpcUrl =
|
|
2921
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
2920
2922
|
const tokenOutputSompi = parseU64(
|
|
2921
|
-
|
|
2923
|
+
env.KCC20_WRAP_TOKEN_OUTPUT_SOMPI ||
|
|
2922
2924
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
2923
2925
|
"tokenOutputSompi",
|
|
2924
2926
|
);
|
|
2925
2927
|
const priorityFee = parseU64(
|
|
2926
|
-
|
|
2928
|
+
env.KCC20_WRAP_PRIORITY_FEE_SOMPI ||
|
|
2927
2929
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
2928
2930
|
"priorityFee",
|
|
2929
2931
|
);
|
|
2930
2932
|
const computeBudget = parsePositiveNumber(
|
|
2931
|
-
|
|
2933
|
+
env.KCC20_WRAP_COMPUTE_BUDGET || 700,
|
|
2932
2934
|
"computeBudget",
|
|
2933
2935
|
);
|
|
2934
2936
|
|
|
@@ -3332,21 +3334,21 @@ export function createKcc20PsktBuilderEngine(
|
|
|
3332
3334
|
);
|
|
3333
3335
|
const tokenAmount = parsePositiveU64(params.tokenAmount, "tokenAmount");
|
|
3334
3336
|
const network =
|
|
3335
|
-
request.network ||
|
|
3337
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
3336
3338
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
3337
|
-
const rpcUrl =
|
|
3339
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
3338
3340
|
const tokenOutputSompi = parseU64(
|
|
3339
|
-
|
|
3341
|
+
env.KCC20_UNWRAP_TOKEN_OUTPUT_SOMPI ||
|
|
3340
3342
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
3341
3343
|
"tokenOutputSompi",
|
|
3342
3344
|
);
|
|
3343
3345
|
const priorityFee = parseU64(
|
|
3344
|
-
|
|
3346
|
+
env.KCC20_UNWRAP_PRIORITY_FEE_SOMPI ||
|
|
3345
3347
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
3346
3348
|
"priorityFee",
|
|
3347
3349
|
);
|
|
3348
3350
|
const computeBudget = parsePositiveNumber(
|
|
3349
|
-
|
|
3351
|
+
env.KCC20_UNWRAP_COMPUTE_BUDGET || 700,
|
|
3350
3352
|
"computeBudget",
|
|
3351
3353
|
);
|
|
3352
3354
|
|
|
@@ -3823,21 +3825,21 @@ export function createKcc20PsktBuilderEngine(
|
|
|
3823
3825
|
? requireHex32(params.feeTicketId, "fee ticket id")
|
|
3824
3826
|
: null;
|
|
3825
3827
|
const network =
|
|
3826
|
-
request.network ||
|
|
3828
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
3827
3829
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
3828
|
-
const rpcUrl =
|
|
3830
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
3829
3831
|
const tokenOutputSompi = parseU64(
|
|
3830
|
-
|
|
3832
|
+
env.KCC20_ORDER_TOKEN_OUTPUT_SOMPI ||
|
|
3831
3833
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
3832
3834
|
"tokenOutputSompi",
|
|
3833
3835
|
);
|
|
3834
3836
|
const priorityFee = parseU64(
|
|
3835
|
-
|
|
3837
|
+
env.KCC20_ORDER_PRIORITY_FEE_SOMPI ||
|
|
3836
3838
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
3837
3839
|
"priorityFee",
|
|
3838
3840
|
);
|
|
3839
3841
|
const computeBudget = parsePositiveNumber(
|
|
3840
|
-
|
|
3842
|
+
env.KCC20_ORDER_COMPUTE_BUDGET || 700,
|
|
3841
3843
|
"computeBudget",
|
|
3842
3844
|
);
|
|
3843
3845
|
|
|
@@ -4181,21 +4183,21 @@ export function createKcc20PsktBuilderEngine(
|
|
|
4181
4183
|
"unitPriceSompi",
|
|
4182
4184
|
);
|
|
4183
4185
|
const network =
|
|
4184
|
-
request.network ||
|
|
4186
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
4185
4187
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
4186
|
-
const rpcUrl =
|
|
4188
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
4187
4189
|
const tokenOutputSompi = parseU64(
|
|
4188
|
-
|
|
4190
|
+
env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
4189
4191
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
4190
4192
|
"tokenOutputSompi",
|
|
4191
4193
|
);
|
|
4192
4194
|
const priorityFee = parseU64(
|
|
4193
|
-
|
|
4195
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
4194
4196
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
4195
4197
|
"priorityFee",
|
|
4196
4198
|
);
|
|
4197
4199
|
const computeBudget = parsePositiveNumber(
|
|
4198
|
-
|
|
4200
|
+
env.KCC20_FILL_COMPUTE_BUDGET || 800,
|
|
4199
4201
|
"computeBudget",
|
|
4200
4202
|
);
|
|
4201
4203
|
|
|
@@ -4604,21 +4606,21 @@ export function createKcc20PsktBuilderEngine(
|
|
|
4604
4606
|
"unitPriceSompi",
|
|
4605
4607
|
);
|
|
4606
4608
|
const network =
|
|
4607
|
-
request.network ||
|
|
4609
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
4608
4610
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
4609
|
-
const rpcUrl =
|
|
4611
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
4610
4612
|
const tokenOutputSompi = parseU64(
|
|
4611
|
-
|
|
4613
|
+
env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
4612
4614
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
4613
4615
|
"tokenOutputSompi",
|
|
4614
4616
|
);
|
|
4615
4617
|
const priorityFee = parseU64(
|
|
4616
|
-
|
|
4618
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
4617
4619
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
4618
4620
|
"priorityFee",
|
|
4619
4621
|
);
|
|
4620
4622
|
const computeBudget = parsePositiveNumber(
|
|
4621
|
-
|
|
4623
|
+
env.KCC20_FILL_COMPUTE_BUDGET || 800,
|
|
4622
4624
|
"computeBudget",
|
|
4623
4625
|
);
|
|
4624
4626
|
|
|
@@ -5196,16 +5198,16 @@ export function createKcc20PsktBuilderEngine(
|
|
|
5196
5198
|
);
|
|
5197
5199
|
const buyerOwner = requireHex32(request.owner?.kcc20Owner, "buyer owner");
|
|
5198
5200
|
const network =
|
|
5199
|
-
request.network ||
|
|
5201
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
5200
5202
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
5201
|
-
const rpcUrl =
|
|
5203
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
5202
5204
|
const tokenOutputSompi = parseU64(
|
|
5203
|
-
|
|
5205
|
+
env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
5204
5206
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
5205
5207
|
"tokenOutputSompi",
|
|
5206
5208
|
);
|
|
5207
5209
|
const priorityFee = parseU64(
|
|
5208
|
-
|
|
5210
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
5209
5211
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
5210
5212
|
"priorityFee",
|
|
5211
5213
|
);
|
|
@@ -5745,16 +5747,16 @@ export function createKcc20PsktBuilderEngine(
|
|
|
5745
5747
|
);
|
|
5746
5748
|
const sellerOwner = requireHex32(request.owner?.kcc20Owner, "seller owner");
|
|
5747
5749
|
const network =
|
|
5748
|
-
request.network ||
|
|
5750
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
5749
5751
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
5750
|
-
const rpcUrl =
|
|
5752
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
5751
5753
|
const tokenOutputSompi = parseU64(
|
|
5752
|
-
|
|
5754
|
+
env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
5753
5755
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
5754
5756
|
"tokenOutputSompi",
|
|
5755
5757
|
);
|
|
5756
5758
|
const priorityFee = parseU64(
|
|
5757
|
-
|
|
5759
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
5758
5760
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
5759
5761
|
"priorityFee",
|
|
5760
5762
|
);
|
|
@@ -6502,16 +6504,16 @@ export function createKcc20PsktBuilderEngine(
|
|
|
6502
6504
|
);
|
|
6503
6505
|
const sellerOwner = requireHex32(request.owner?.kcc20Owner, "seller owner");
|
|
6504
6506
|
const network =
|
|
6505
|
-
request.network ||
|
|
6507
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
6506
6508
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
6507
|
-
const rpcUrl =
|
|
6509
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
6508
6510
|
const configuredTokenOutputSompi = parseU64(
|
|
6509
|
-
|
|
6511
|
+
env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
6510
6512
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
6511
6513
|
"tokenOutputSompi",
|
|
6512
6514
|
);
|
|
6513
6515
|
const priorityFee = parseU64(
|
|
6514
|
-
|
|
6516
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
6515
6517
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
6516
6518
|
"priorityFee",
|
|
6517
6519
|
);
|
|
@@ -7281,23 +7283,23 @@ export function createKcc20PsktBuilderEngine(
|
|
|
7281
7283
|
);
|
|
7282
7284
|
const owner = requireHex32(request.owner?.kcc20Owner, "token owner");
|
|
7283
7285
|
const network =
|
|
7284
|
-
request.network ||
|
|
7286
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
7285
7287
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
7286
|
-
const rpcUrl =
|
|
7288
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
7287
7289
|
const priorityFee = parseU64(
|
|
7288
|
-
|
|
7289
|
-
|
|
7290
|
+
env.KCC20_CONSOLIDATE_PRIORITY_FEE_SOMPI ||
|
|
7291
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
7290
7292
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
7291
7293
|
"priorityFee",
|
|
7292
7294
|
);
|
|
7293
7295
|
const configuredPrimaryComputeBudget = parsePositiveNumber(
|
|
7294
|
-
|
|
7295
|
-
|
|
7296
|
+
env.KCC20_CONSOLIDATE_COMPUTE_BUDGET ||
|
|
7297
|
+
env.KCC20_FILL_COMPUTE_BUDGET ||
|
|
7296
7298
|
800,
|
|
7297
7299
|
"configuredPrimaryComputeBudget",
|
|
7298
7300
|
);
|
|
7299
7301
|
const peerComputeBudget = parsePositiveNumber(
|
|
7300
|
-
|
|
7302
|
+
env.KCC20_CONSOLIDATE_PEER_COMPUTE_BUDGET || 200,
|
|
7301
7303
|
"peerComputeBudget",
|
|
7302
7304
|
);
|
|
7303
7305
|
const computeBudget = Math.max(
|
|
@@ -7581,37 +7583,37 @@ export function createKcc20PsktBuilderEngine(
|
|
|
7581
7583
|
: null;
|
|
7582
7584
|
const maxFeeSompi = parseU64(params.maxFeeSompi || "0", "maxFeeSompi");
|
|
7583
7585
|
const network =
|
|
7584
|
-
request.network ||
|
|
7586
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
7585
7587
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
7586
7588
|
const expectedOwner = request.owner?.kcc20Owner
|
|
7587
7589
|
? requireHex32(request.owner.kcc20Owner, "matcher owner")
|
|
7588
7590
|
: null;
|
|
7589
|
-
const rpcUrl =
|
|
7591
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
7590
7592
|
const tokenOutputSompi = parseU64(
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
+
env.KCC20_MATCHER_TOKEN_OUTPUT_SOMPI ||
|
|
7594
|
+
env.KCC20_FILL_TOKEN_OUTPUT_SOMPI ||
|
|
7593
7595
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
7594
7596
|
"tokenOutputSompi",
|
|
7595
7597
|
);
|
|
7596
7598
|
const priorityFee = parseU64(
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
+
env.KCC20_MATCHER_PRIORITY_FEE_SOMPI ||
|
|
7600
|
+
env.KCC20_FILL_PRIORITY_FEE_SOMPI ||
|
|
7599
7601
|
DEFAULT_MATCHER_PRIORITY_FEE.toString(),
|
|
7600
7602
|
"priorityFee",
|
|
7601
7603
|
);
|
|
7602
7604
|
const networkFeeReserve = parseU64(
|
|
7603
|
-
|
|
7605
|
+
env.KCC20_MATCHER_NETWORK_FEE_RESERVE_SOMPI || "5000000",
|
|
7604
7606
|
"networkFeeReserve",
|
|
7605
7607
|
);
|
|
7606
7608
|
const transactionFeeReserve = priorityFee + networkFeeReserve;
|
|
7607
7609
|
const computeBudget = parsePositiveNumber(
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
+
env.KCC20_MATCHER_COMPUTE_BUDGET ||
|
|
7611
|
+
env.KCC20_FILL_COMPUTE_BUDGET ||
|
|
7610
7612
|
800,
|
|
7611
7613
|
"computeBudget",
|
|
7612
7614
|
);
|
|
7613
7615
|
const privateKeyHex = String(
|
|
7614
|
-
|
|
7616
|
+
env.KCC20_WRAPPER_OPERATOR_PRIVATE_KEY || "",
|
|
7615
7617
|
)
|
|
7616
7618
|
.trim()
|
|
7617
7619
|
.replace(/^0x/i, "");
|
|
@@ -8277,16 +8279,16 @@ export function createKcc20PsktBuilderEngine(
|
|
|
8277
8279
|
"target order id",
|
|
8278
8280
|
);
|
|
8279
8281
|
const network =
|
|
8280
|
-
request.network ||
|
|
8282
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
8281
8283
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
8282
|
-
const rpcUrl =
|
|
8284
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
8283
8285
|
const priorityFee = parseU64(
|
|
8284
|
-
|
|
8286
|
+
env.KCC20_CANCEL_PRIORITY_FEE_SOMPI ||
|
|
8285
8287
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
8286
8288
|
"priorityFee",
|
|
8287
8289
|
);
|
|
8288
8290
|
const computeBudget = parsePositiveNumber(
|
|
8289
|
-
|
|
8291
|
+
env.KCC20_CANCEL_COMPUTE_BUDGET || 800,
|
|
8290
8292
|
"computeBudget",
|
|
8291
8293
|
);
|
|
8292
8294
|
|
|
@@ -8601,24 +8603,24 @@ export function createKcc20PsktBuilderEngine(
|
|
|
8601
8603
|
const minterVout = parseVout(activeMinterUtxo.vout, "minter vout");
|
|
8602
8604
|
const minterAddress = requireKaspaAddress(activeMinterUtxo.address);
|
|
8603
8605
|
const network =
|
|
8604
|
-
request.network ||
|
|
8606
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
8605
8607
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
8606
|
-
const rpcUrl =
|
|
8608
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
8607
8609
|
const tokenOutputSompi = assertKcc20TokenOutputSompi(
|
|
8608
8610
|
parseU64(
|
|
8609
|
-
|
|
8611
|
+
env.KCC20_MINT_TOKEN_OUTPUT_SOMPI ||
|
|
8610
8612
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
8611
8613
|
"tokenOutputSompi",
|
|
8612
8614
|
),
|
|
8613
8615
|
"mint",
|
|
8614
8616
|
);
|
|
8615
8617
|
const priorityFee = parseU64(
|
|
8616
|
-
|
|
8618
|
+
env.KCC20_MINT_PRIORITY_FEE_SOMPI ||
|
|
8617
8619
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
8618
8620
|
"priorityFee",
|
|
8619
8621
|
);
|
|
8620
8622
|
const computeBudget = parsePositiveNumber(
|
|
8621
|
-
|
|
8623
|
+
env.KCC20_MINT_COMPUTE_BUDGET || DEFAULT_COMPUTE_BUDGET,
|
|
8622
8624
|
"computeBudget",
|
|
8623
8625
|
);
|
|
8624
8626
|
|
|
@@ -8971,8 +8973,14 @@ export function createKcc20PsktBuilderEngine(
|
|
|
8971
8973
|
async function buildKcc20SetPublicMintActivePskt(input) {
|
|
8972
8974
|
const request = input.request || {};
|
|
8973
8975
|
const params = request.params || {};
|
|
8974
|
-
const
|
|
8975
|
-
|
|
8976
|
+
const requestedMinterUtxos =
|
|
8977
|
+
Array.isArray(params.activeMinterUtxos) &&
|
|
8978
|
+
params.activeMinterUtxos.length > 0
|
|
8979
|
+
? params.activeMinterUtxos
|
|
8980
|
+
: params.activeMinterUtxo
|
|
8981
|
+
? [params.activeMinterUtxo]
|
|
8982
|
+
: [];
|
|
8983
|
+
if (requestedMinterUtxos.length === 0) {
|
|
8976
8984
|
throw new Error("active KCC20 mint-authority UTXO is required");
|
|
8977
8985
|
}
|
|
8978
8986
|
if (typeof params.active !== "boolean") {
|
|
@@ -8981,132 +8989,186 @@ export function createKcc20PsktBuilderEngine(
|
|
|
8981
8989
|
|
|
8982
8990
|
const covenantId = requireHex32(params.covenantId, "canonical covenant id");
|
|
8983
8991
|
const network =
|
|
8984
|
-
request.network ||
|
|
8992
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
8985
8993
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
8986
8994
|
const walletOwner = requireHex32(
|
|
8987
8995
|
request.owner?.kcc20Owner,
|
|
8988
8996
|
"authenticated wallet owner",
|
|
8989
8997
|
);
|
|
8990
|
-
const minterAddress = requireKaspaAddress(activeMinterUtxo.address);
|
|
8991
|
-
const minterOwner = requireHex32(
|
|
8992
|
-
activeMinterUtxo.state?.owner ?? activeMinterUtxo.state?.ownerIdentifier,
|
|
8993
|
-
"active mint-authority owner",
|
|
8994
|
-
);
|
|
8995
|
-
const minterOwnerScheme = parseOwnerScheme(
|
|
8996
|
-
activeMinterUtxo.state?.ownerScheme ??
|
|
8997
|
-
activeMinterUtxo.state?.identifierType ??
|
|
8998
|
-
0,
|
|
8999
|
-
"active mint-authority owner scheme",
|
|
9000
|
-
);
|
|
9001
|
-
if (minterOwnerScheme !== 0) {
|
|
9002
|
-
throw new Error(
|
|
9003
|
-
"public mint availability requires a pubkey-owned minter",
|
|
9004
|
-
);
|
|
9005
|
-
}
|
|
9006
|
-
if (minterOwner !== walletOwner) {
|
|
9007
|
-
throw new Error(
|
|
9008
|
-
"public mint availability requires authenticated wallet to own the active minter UTXO",
|
|
9009
|
-
);
|
|
9010
|
-
}
|
|
9011
8998
|
const mintPolicy = params.mintPolicy || {};
|
|
9012
|
-
const remainingSupply = parsePositiveU64(
|
|
9013
|
-
activeMinterUtxo.state?.remainingSupply ?? mintPolicy.remainingSupply,
|
|
9014
|
-
"active mint-authority remaining supply",
|
|
9015
|
-
);
|
|
9016
8999
|
const displayScale = parsePositiveU64(
|
|
9017
9000
|
params.priceScale ??
|
|
9018
9001
|
params.tokenDisplayScale ??
|
|
9019
9002
|
DEFAULT_KCC20_PRICE_SCALE,
|
|
9020
9003
|
"displayScale",
|
|
9021
9004
|
);
|
|
9022
|
-
const
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9005
|
+
const seenOutpoints = new Set();
|
|
9006
|
+
const laneContexts = (
|
|
9007
|
+
await Promise.all(
|
|
9008
|
+
requestedMinterUtxos.map(async (activeMinterUtxo, laneIndex) => {
|
|
9009
|
+
if (
|
|
9010
|
+
activeMinterUtxo.state?.isMintAuthority !== true ||
|
|
9011
|
+
parseMintPolicy(activeMinterUtxo.state?.mintPolicy) !== 2
|
|
9012
|
+
) {
|
|
9013
|
+
throw new Error(
|
|
9014
|
+
"public mint availability requires public mint-authority lanes",
|
|
9015
|
+
);
|
|
9016
|
+
}
|
|
9017
|
+
const minterAddress = requireKaspaAddress(activeMinterUtxo.address);
|
|
9018
|
+
const minterOwner = requireHex32(
|
|
9019
|
+
activeMinterUtxo.state?.owner ??
|
|
9020
|
+
activeMinterUtxo.state?.ownerIdentifier,
|
|
9021
|
+
"active mint-authority owner",
|
|
9022
|
+
);
|
|
9023
|
+
const minterOwnerScheme = parseOwnerScheme(
|
|
9024
|
+
activeMinterUtxo.state?.ownerScheme ??
|
|
9025
|
+
activeMinterUtxo.state?.identifierType ??
|
|
9026
|
+
0,
|
|
9027
|
+
"active mint-authority owner scheme",
|
|
9028
|
+
);
|
|
9029
|
+
if (minterOwnerScheme !== 0) {
|
|
9030
|
+
throw new Error(
|
|
9031
|
+
"public mint availability requires a pubkey-owned minter",
|
|
9032
|
+
);
|
|
9033
|
+
}
|
|
9034
|
+
if (minterOwner !== walletOwner) {
|
|
9035
|
+
throw new Error(
|
|
9036
|
+
"public mint availability requires authenticated wallet to own every active minter UTXO",
|
|
9037
|
+
);
|
|
9038
|
+
}
|
|
9039
|
+
const remainingSupply = parsePositiveU64(
|
|
9040
|
+
activeMinterUtxo.state?.remainingSupply ??
|
|
9041
|
+
mintPolicy.remainingSupply,
|
|
9042
|
+
"active mint-authority remaining supply",
|
|
9043
|
+
);
|
|
9044
|
+
const extension = kcc20MintExtensionFromSources(
|
|
9045
|
+
activeMinterUtxo,
|
|
9046
|
+
params,
|
|
9047
|
+
mintPolicy,
|
|
9048
|
+
2,
|
|
9049
|
+
remainingSupply,
|
|
9050
|
+
displayScale,
|
|
9051
|
+
);
|
|
9052
|
+
if (extension.publicMintActive === params.active) {
|
|
9053
|
+
return null;
|
|
9054
|
+
}
|
|
9055
|
+
const inputState = {
|
|
9056
|
+
amount: 0n,
|
|
9057
|
+
owner: hexToBytes(minterOwner),
|
|
9058
|
+
ownerScheme: minterOwnerScheme,
|
|
9059
|
+
borrowScheme: 0,
|
|
9060
|
+
borrowGuard: hexToBytes(ZERO_HASH),
|
|
9061
|
+
extensionCommitment: mintExtensionCommitment(extension),
|
|
9062
|
+
};
|
|
9063
|
+
const nextExtension = {
|
|
9064
|
+
...extension,
|
|
9065
|
+
publicMintActive: params.active,
|
|
9066
|
+
};
|
|
9067
|
+
const outputState = {
|
|
9068
|
+
...inputState,
|
|
9069
|
+
extensionCommitment: mintExtensionCommitment(nextExtension),
|
|
9070
|
+
};
|
|
9071
|
+
const resolvedArtifact = await resolveKcc20ArtifactForState(
|
|
9072
|
+
inputState,
|
|
9073
|
+
minterAddress,
|
|
9074
|
+
network,
|
|
9075
|
+
);
|
|
9076
|
+
dispatchTagFor(resolvedArtifact.artifact, "set_public_mint_active");
|
|
9077
|
+
const minterTxid = requireHex32(
|
|
9078
|
+
activeMinterUtxo.txidHex,
|
|
9079
|
+
"minter txid",
|
|
9080
|
+
);
|
|
9081
|
+
const minterVout = parseVout(activeMinterUtxo.vout, "minter vout");
|
|
9082
|
+
const outpoint = `${minterTxid}:${minterVout}`;
|
|
9083
|
+
if (seenOutpoints.has(outpoint)) {
|
|
9084
|
+
throw new Error(`duplicate active minter outpoint ${outpoint}`);
|
|
9085
|
+
}
|
|
9086
|
+
seenOutpoints.add(outpoint);
|
|
9087
|
+
return {
|
|
9088
|
+
activeMinterUtxo,
|
|
9089
|
+
laneIndex,
|
|
9090
|
+
minterAddress,
|
|
9091
|
+
minterTxid,
|
|
9092
|
+
minterVout,
|
|
9093
|
+
outpoint,
|
|
9094
|
+
remainingSupply,
|
|
9095
|
+
extension,
|
|
9096
|
+
nextExtension,
|
|
9097
|
+
inputState,
|
|
9098
|
+
outputState,
|
|
9099
|
+
resolvedArtifact,
|
|
9100
|
+
};
|
|
9101
|
+
}),
|
|
9102
|
+
)
|
|
9103
|
+
).filter(Boolean);
|
|
9104
|
+
if (laneContexts.length === 0) {
|
|
9031
9105
|
throw new Error(
|
|
9032
9106
|
params.active
|
|
9033
9107
|
? "public mint is not paused"
|
|
9034
9108
|
: "public mint is not active",
|
|
9035
9109
|
);
|
|
9036
9110
|
}
|
|
9037
|
-
const inputState = {
|
|
9038
|
-
amount: 0n,
|
|
9039
|
-
owner: hexToBytes(minterOwner),
|
|
9040
|
-
ownerScheme: minterOwnerScheme,
|
|
9041
|
-
borrowScheme: 0,
|
|
9042
|
-
borrowGuard: hexToBytes(ZERO_HASH),
|
|
9043
|
-
extensionCommitment: mintExtensionCommitment(extension),
|
|
9044
|
-
};
|
|
9045
|
-
const nextExtension = { ...extension, publicMintActive: params.active };
|
|
9046
|
-
const outputState = {
|
|
9047
|
-
...inputState,
|
|
9048
|
-
extensionCommitment: mintExtensionCommitment(nextExtension),
|
|
9049
|
-
};
|
|
9050
|
-
const resolvedArtifact = await resolveKcc20ArtifactForState(
|
|
9051
|
-
inputState,
|
|
9052
|
-
minterAddress,
|
|
9053
|
-
network,
|
|
9054
|
-
);
|
|
9055
|
-
const artifact = resolvedArtifact.artifact;
|
|
9056
|
-
dispatchTagFor(artifact, "set_public_mint_active");
|
|
9057
|
-
|
|
9058
|
-
const minterTxid = requireHex32(activeMinterUtxo.txidHex, "minter txid");
|
|
9059
|
-
const minterVout = parseVout(activeMinterUtxo.vout, "minter vout");
|
|
9060
9111
|
const priorityFee = parseU64(
|
|
9061
|
-
|
|
9112
|
+
env.KCC20_MINT_AVAILABILITY_PRIORITY_FEE_SOMPI ||
|
|
9062
9113
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
9063
9114
|
"priorityFee",
|
|
9064
9115
|
);
|
|
9065
9116
|
const computeBudget = parsePositiveNumber(
|
|
9066
|
-
|
|
9117
|
+
env.KCC20_MINT_AVAILABILITY_COMPUTE_BUDGET ||
|
|
9067
9118
|
DEFAULT_COMPUTE_BUDGET,
|
|
9068
9119
|
"computeBudget",
|
|
9069
9120
|
);
|
|
9070
9121
|
const rpc = new kaspaWasm.RpcClient({
|
|
9071
|
-
url:
|
|
9122
|
+
url: env.KASPA_WRPC_URL || DEFAULT_WRPC_URL,
|
|
9072
9123
|
encoding: kaspaWasm.Encoding.Borsh,
|
|
9073
9124
|
networkId: network,
|
|
9074
9125
|
});
|
|
9075
9126
|
await rpc.connect();
|
|
9076
9127
|
try {
|
|
9077
9128
|
const [minterUtxos, walletUtxos] = await Promise.all([
|
|
9078
|
-
getUtxosByAddresses(rpc, [
|
|
9129
|
+
getUtxosByAddresses(rpc, [
|
|
9130
|
+
...new Set(laneContexts.map((lane) => lane.minterAddress)),
|
|
9131
|
+
]),
|
|
9079
9132
|
getUtxosByAddresses(rpc, [walletAddress]),
|
|
9080
9133
|
]);
|
|
9081
|
-
const
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
if (!minterEntry) {
|
|
9087
|
-
throw new Error(
|
|
9088
|
-
`active minter UTXO ${minterTxid}:${minterVout} not found`,
|
|
9134
|
+
const resolvedLanes = laneContexts.map((lane, laneIndex) => {
|
|
9135
|
+
const minterEntry = findUtxoEntry(
|
|
9136
|
+
minterUtxos.entries,
|
|
9137
|
+
lane.minterTxid,
|
|
9138
|
+
lane.minterVout,
|
|
9089
9139
|
);
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9140
|
+
if (!minterEntry) {
|
|
9141
|
+
throw new Error(`active minter UTXO ${lane.outpoint} not found`);
|
|
9142
|
+
}
|
|
9143
|
+
const spendCovenantId = requireMatchingCovenantId(
|
|
9144
|
+
minterEntry,
|
|
9145
|
+
covenantId,
|
|
9146
|
+
`active minter lane ${laneIndex}`,
|
|
9147
|
+
);
|
|
9148
|
+
return {
|
|
9149
|
+
...lane,
|
|
9150
|
+
laneIndex,
|
|
9151
|
+
minterEntry,
|
|
9152
|
+
spendCovenantId,
|
|
9153
|
+
minterInputSompi: BigInt(minterEntry.amount),
|
|
9154
|
+
};
|
|
9155
|
+
});
|
|
9094
9156
|
const fundingEntry = selectFundingEntry(
|
|
9095
9157
|
walletUtxos.entries,
|
|
9096
9158
|
priorityFee + 10_000n,
|
|
9097
9159
|
);
|
|
9098
|
-
const fundingInputIndex =
|
|
9160
|
+
const fundingInputIndex = resolvedLanes.length;
|
|
9099
9161
|
const fundingChange = BigInt(fundingEntry.amount) - priorityFee;
|
|
9100
|
-
const outputs =
|
|
9162
|
+
const outputs = resolvedLanes.map((lane, laneIndex) =>
|
|
9101
9163
|
tokenOutput(
|
|
9102
9164
|
kaspaWasm,
|
|
9103
|
-
artifact,
|
|
9104
|
-
outputState,
|
|
9105
|
-
minterInputSompi,
|
|
9106
|
-
spendCovenantId,
|
|
9107
|
-
|
|
9165
|
+
lane.resolvedArtifact.artifact,
|
|
9166
|
+
lane.outputState,
|
|
9167
|
+
lane.minterInputSompi,
|
|
9168
|
+
lane.spendCovenantId,
|
|
9169
|
+
laneIndex,
|
|
9108
9170
|
),
|
|
9109
|
-
|
|
9171
|
+
);
|
|
9110
9172
|
let fundingChangeOutputIndex = -1;
|
|
9111
9173
|
if (fundingChange > 10_000n) {
|
|
9112
9174
|
fundingChangeOutputIndex = outputs.length;
|
|
@@ -9121,13 +9183,13 @@ export function createKcc20PsktBuilderEngine(
|
|
|
9121
9183
|
version: 1,
|
|
9122
9184
|
lockTime: 0n,
|
|
9123
9185
|
inputs: [
|
|
9124
|
-
{
|
|
9125
|
-
previousOutpoint: minterEntry.outpoint,
|
|
9126
|
-
utxo: minterEntry,
|
|
9186
|
+
...resolvedLanes.map((lane) => ({
|
|
9187
|
+
previousOutpoint: lane.minterEntry.outpoint,
|
|
9188
|
+
utxo: lane.minterEntry,
|
|
9127
9189
|
sequence: 0n,
|
|
9128
9190
|
sigOpCount: 0,
|
|
9129
9191
|
computeBudget,
|
|
9130
|
-
},
|
|
9192
|
+
})),
|
|
9131
9193
|
{
|
|
9132
9194
|
previousOutpoint: fundingEntry.outpoint,
|
|
9133
9195
|
utxo: fundingEntry,
|
|
@@ -9142,20 +9204,21 @@ export function createKcc20PsktBuilderEngine(
|
|
|
9142
9204
|
payload: new Uint8Array(),
|
|
9143
9205
|
});
|
|
9144
9206
|
setVersionOneInputMassFields(unsignedTx, computeBudget);
|
|
9145
|
-
|
|
9146
|
-
|
|
9147
|
-
|
|
9207
|
+
unsignedTx.inputs[fundingInputIndex].computeBudget = 30;
|
|
9208
|
+
const scripts = resolvedLanes.map((lane, laneIndex) => ({
|
|
9209
|
+
inputIndex: laneIndex,
|
|
9210
|
+
scriptHex: bytesToHex(lane.resolvedArtifact.script),
|
|
9148
9211
|
signType: 1,
|
|
9149
9212
|
signatureScript: {
|
|
9150
9213
|
mode: "ordered-args",
|
|
9151
9214
|
args: kcc20SetPublicMintActiveOrderedArgs(
|
|
9152
|
-
artifact,
|
|
9153
|
-
extension,
|
|
9215
|
+
lane.resolvedArtifact.artifact,
|
|
9216
|
+
lane.extension,
|
|
9154
9217
|
params.active,
|
|
9155
|
-
|
|
9218
|
+
laneIndex,
|
|
9156
9219
|
),
|
|
9157
9220
|
},
|
|
9158
|
-
};
|
|
9221
|
+
}));
|
|
9159
9222
|
const predictSignedTransaction = (transaction) => {
|
|
9160
9223
|
const predicted = cloneTransactionForMassPreflight(
|
|
9161
9224
|
kaspaWasm,
|
|
@@ -9163,20 +9226,23 @@ export function createKcc20PsktBuilderEngine(
|
|
|
9163
9226
|
"KCC20 public mint availability",
|
|
9164
9227
|
);
|
|
9165
9228
|
const dummySignature = dummySignatureBytes();
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
9176
|
-
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9229
|
+
resolvedLanes.forEach((lane, laneIndex) => {
|
|
9230
|
+
const prefix = buildKcc20SetPublicMintActiveSigScript(
|
|
9231
|
+
kaspaWasm,
|
|
9232
|
+
lane.resolvedArtifact.artifact,
|
|
9233
|
+
{
|
|
9234
|
+
extension: lane.extension,
|
|
9235
|
+
authoritySignature: dummySignature,
|
|
9236
|
+
active: params.active,
|
|
9237
|
+
minterOutputIndex: laneIndex,
|
|
9238
|
+
},
|
|
9239
|
+
);
|
|
9240
|
+
predicted.inputs[laneIndex].signatureScript =
|
|
9241
|
+
encodeCovenantP2shSignatureScript(
|
|
9242
|
+
prefix,
|
|
9243
|
+
lane.resolvedArtifact.script,
|
|
9244
|
+
);
|
|
9245
|
+
});
|
|
9180
9246
|
predicted.inputs[fundingInputIndex].signatureScript =
|
|
9181
9247
|
encodeP2pkSignatureScript(bytesToHex(dummySignature));
|
|
9182
9248
|
return predicted;
|
|
@@ -9199,21 +9265,34 @@ export function createKcc20PsktBuilderEngine(
|
|
|
9199
9265
|
schema: OUTPUT_SCHEMA,
|
|
9200
9266
|
psktTransactionJson,
|
|
9201
9267
|
signInputs: [{ index: fundingInputIndex, sighashType: 1 }],
|
|
9202
|
-
scripts
|
|
9268
|
+
scripts,
|
|
9203
9269
|
submitTransactionSupported: true,
|
|
9204
9270
|
metadata: {
|
|
9205
9271
|
builderKey: "kcc20.set-public-mint-active",
|
|
9206
9272
|
contract: "KCC20",
|
|
9207
9273
|
network,
|
|
9208
9274
|
walletAddress,
|
|
9209
|
-
covenantId
|
|
9210
|
-
minterOutpoint:
|
|
9275
|
+
covenantId,
|
|
9276
|
+
minterOutpoint: resolvedLanes[0].outpoint,
|
|
9277
|
+
minterOutpoints: resolvedLanes.map((lane) => lane.outpoint),
|
|
9211
9278
|
minterOutputIndex: 0,
|
|
9279
|
+
minterOutputIndexes: resolvedLanes.map((_, index) => index),
|
|
9280
|
+
mintLaneCount: Number(resolvedLanes[0].extension.mintLaneCount),
|
|
9281
|
+
updatedMintLaneCount: resolvedLanes.length,
|
|
9212
9282
|
publicMintActive: params.active,
|
|
9213
9283
|
mintPolicy: 2,
|
|
9214
|
-
remainingSupply: remainingSupply.toString(),
|
|
9215
|
-
|
|
9216
|
-
|
|
9284
|
+
remainingSupply: resolvedLanes[0].remainingSupply.toString(),
|
|
9285
|
+
remainingSupplies: resolvedLanes.map((lane) =>
|
|
9286
|
+
lane.remainingSupply.toString(),
|
|
9287
|
+
),
|
|
9288
|
+
extension: jsonKcc20MintExtension(resolvedLanes[0].nextExtension),
|
|
9289
|
+
extensions: resolvedLanes.map((lane) =>
|
|
9290
|
+
jsonKcc20MintExtension(lane.nextExtension),
|
|
9291
|
+
),
|
|
9292
|
+
artifactVersion: resolvedLanes[0].resolvedArtifact.version,
|
|
9293
|
+
artifactVersions: resolvedLanes.map(
|
|
9294
|
+
(lane) => lane.resolvedArtifact.version,
|
|
9295
|
+
),
|
|
9217
9296
|
},
|
|
9218
9297
|
};
|
|
9219
9298
|
} finally {
|
|
@@ -9282,23 +9361,23 @@ export function createKcc20PsktBuilderEngine(
|
|
|
9282
9361
|
);
|
|
9283
9362
|
const owner = requireHex32(request.owner?.kcc20Owner, "token owner");
|
|
9284
9363
|
const network =
|
|
9285
|
-
request.network ||
|
|
9364
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
9286
9365
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
9287
|
-
const rpcUrl =
|
|
9366
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
9288
9367
|
const priorityFee = parseU64(
|
|
9289
|
-
|
|
9290
|
-
|
|
9368
|
+
env.KCC20_CONSOLIDATE_PRIORITY_FEE_SOMPI ||
|
|
9369
|
+
env.KCC20_TRANSFER_PRIORITY_FEE_SOMPI ||
|
|
9291
9370
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
9292
9371
|
"priorityFee",
|
|
9293
9372
|
);
|
|
9294
9373
|
const configuredPrimaryComputeBudget = parsePositiveNumber(
|
|
9295
|
-
|
|
9296
|
-
|
|
9374
|
+
env.KCC20_CONSOLIDATE_COMPUTE_BUDGET ||
|
|
9375
|
+
env.KCC20_TRANSFER_COMPUTE_BUDGET ||
|
|
9297
9376
|
DEFAULT_COMPUTE_BUDGET,
|
|
9298
9377
|
"configuredPrimaryComputeBudget",
|
|
9299
9378
|
);
|
|
9300
9379
|
const peerComputeBudget = parsePositiveNumber(
|
|
9301
|
-
|
|
9380
|
+
env.KCC20_CONSOLIDATE_PEER_COMPUTE_BUDGET || 200,
|
|
9302
9381
|
"peerComputeBudget",
|
|
9303
9382
|
);
|
|
9304
9383
|
const computeBudget = Math.max(
|
|
@@ -9549,16 +9628,16 @@ export function createKcc20PsktBuilderEngine(
|
|
|
9549
9628
|
const covenantId = requireHex32(params.covenantId, "canonical covenant id");
|
|
9550
9629
|
const owner = requireHex32(request.owner?.kcc20Owner, "token owner");
|
|
9551
9630
|
const network =
|
|
9552
|
-
request.network ||
|
|
9631
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
9553
9632
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
9554
|
-
const rpcUrl =
|
|
9633
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
9555
9634
|
const priorityFee = parseU64(
|
|
9556
|
-
|
|
9635
|
+
env.KCC20_REVEAL_PRIORITY_FEE_SOMPI ||
|
|
9557
9636
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
9558
9637
|
"priorityFee",
|
|
9559
9638
|
);
|
|
9560
9639
|
const computeBudget = parsePositiveNumber(
|
|
9561
|
-
|
|
9640
|
+
env.KCC20_REVEAL_COMPUTE_BUDGET || DEFAULT_COMPUTE_BUDGET,
|
|
9562
9641
|
"computeBudget",
|
|
9563
9642
|
);
|
|
9564
9643
|
|
|
@@ -9754,24 +9833,24 @@ export function createKcc20PsktBuilderEngine(
|
|
|
9754
9833
|
);
|
|
9755
9834
|
const transferAmount = parsePositiveU64(params.tokenAmount, "tokenAmount");
|
|
9756
9835
|
const network =
|
|
9757
|
-
request.network ||
|
|
9836
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
9758
9837
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
9759
|
-
const rpcUrl =
|
|
9838
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
9760
9839
|
const tokenOutputSompi = assertKcc20TokenOutputSompi(
|
|
9761
9840
|
parseU64(
|
|
9762
|
-
|
|
9841
|
+
env.KCC20_TRANSFER_TOKEN_OUTPUT_SOMPI ||
|
|
9763
9842
|
DEFAULT_TOKEN_OUTPUT_SOMPI.toString(),
|
|
9764
9843
|
"tokenOutputSompi",
|
|
9765
9844
|
),
|
|
9766
9845
|
"transfer",
|
|
9767
9846
|
);
|
|
9768
9847
|
const priorityFee = parseU64(
|
|
9769
|
-
|
|
9848
|
+
env.KCC20_TRANSFER_PRIORITY_FEE_SOMPI ||
|
|
9770
9849
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
9771
9850
|
"priorityFee",
|
|
9772
9851
|
);
|
|
9773
9852
|
const computeBudget = parsePositiveNumber(
|
|
9774
|
-
|
|
9853
|
+
env.KCC20_TRANSFER_COMPUTE_BUDGET || DEFAULT_COMPUTE_BUDGET,
|
|
9775
9854
|
"computeBudget",
|
|
9776
9855
|
);
|
|
9777
9856
|
|
|
@@ -10031,20 +10110,20 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10031
10110
|
);
|
|
10032
10111
|
const feeBps = parseFeeBps(
|
|
10033
10112
|
params.protocolFeeBps ??
|
|
10034
|
-
|
|
10113
|
+
env.KCC20_PROTOCOL_FEE_BPS ??
|
|
10035
10114
|
DEFAULT_KCC20_FEE_BPS,
|
|
10036
10115
|
);
|
|
10037
10116
|
const decimals = parseU64(params.decimals ?? "0", "decimals");
|
|
10038
10117
|
const priceScale = 10n ** decimals;
|
|
10039
10118
|
const network =
|
|
10040
|
-
request.network ||
|
|
10119
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
10041
10120
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
10042
|
-
const rpcUrl =
|
|
10121
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
10043
10122
|
const amountTkas = parseAmountTkas(
|
|
10044
|
-
|
|
10123
|
+
env.KCC20_DEPLOY_OUTPUT_TKAS || DEFAULT_DEPLOY_TKAS,
|
|
10045
10124
|
);
|
|
10046
10125
|
const priorityFee = parseU64(
|
|
10047
|
-
|
|
10126
|
+
env.KCC20_DEPLOY_PRIORITY_FEE_SOMPI ||
|
|
10048
10127
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
10049
10128
|
"priorityFee",
|
|
10050
10129
|
);
|
|
@@ -10067,6 +10146,14 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10067
10146
|
const artifact = await readStaticArtifact(KCC20_ARTIFACT_PATH);
|
|
10068
10147
|
const displayScale = priceScale;
|
|
10069
10148
|
const remainingSupply = maxSupply - premintSupply;
|
|
10149
|
+
const mintLaneCount =
|
|
10150
|
+
mintPolicy === 0
|
|
10151
|
+
? 1n
|
|
10152
|
+
: parseMintLaneCount(params.mintLaneCount ?? 1, "mintLaneCount");
|
|
10153
|
+
const mintLaneSupplies =
|
|
10154
|
+
mintPolicy === 0
|
|
10155
|
+
? []
|
|
10156
|
+
: splitKcc20MintSupply(remainingSupply, mintLaneCount);
|
|
10070
10157
|
const immutableExtension = {
|
|
10071
10158
|
kind: 1,
|
|
10072
10159
|
creator: hexToBytes(owner),
|
|
@@ -10074,8 +10161,7 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10074
10161
|
name: asciiToBytes32(metadata.name, "token name"),
|
|
10075
10162
|
displayScale,
|
|
10076
10163
|
maxSupply,
|
|
10077
|
-
|
|
10078
|
-
mintLaneCount: 1n,
|
|
10164
|
+
mintLaneCount,
|
|
10079
10165
|
mintPolicy,
|
|
10080
10166
|
mintPriceSompi,
|
|
10081
10167
|
treasury: hexToBytes(treasury),
|
|
@@ -10083,24 +10169,33 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10083
10169
|
protocolFeeBps: BigInt(feeBps),
|
|
10084
10170
|
};
|
|
10085
10171
|
const holderCommitment = holderExtensionCommitment(immutableExtension);
|
|
10086
|
-
const
|
|
10172
|
+
const baseExtension =
|
|
10087
10173
|
mintPolicy === 0
|
|
10088
10174
|
? null
|
|
10089
10175
|
: {
|
|
10090
10176
|
...immutableExtension,
|
|
10091
|
-
remainingSupply,
|
|
10092
10177
|
publicMintActive: false,
|
|
10093
10178
|
holderExtensionCommitment: holderCommitment,
|
|
10094
10179
|
};
|
|
10180
|
+
const minterStates = baseExtension
|
|
10181
|
+
? mintLaneSupplies.map((laneSupply) => {
|
|
10182
|
+
const extension = { ...baseExtension, remainingSupply: laneSupply };
|
|
10183
|
+
return {
|
|
10184
|
+
extension,
|
|
10185
|
+
state: {
|
|
10186
|
+
amount: 0n,
|
|
10187
|
+
owner: hexToBytes(owner),
|
|
10188
|
+
ownerScheme: 0,
|
|
10189
|
+
borrowScheme: 0,
|
|
10190
|
+
borrowGuard: hexToBytes(ZERO_HASH),
|
|
10191
|
+
extensionCommitment: mintExtensionCommitment(extension),
|
|
10192
|
+
},
|
|
10193
|
+
};
|
|
10194
|
+
})
|
|
10195
|
+
: [];
|
|
10196
|
+
const extension = minterStates[0]?.extension ?? null;
|
|
10095
10197
|
const state = extension
|
|
10096
|
-
?
|
|
10097
|
-
amount: 0n,
|
|
10098
|
-
owner: hexToBytes(owner),
|
|
10099
|
-
ownerScheme: 0,
|
|
10100
|
-
borrowScheme: 0,
|
|
10101
|
-
borrowGuard: hexToBytes(ZERO_HASH),
|
|
10102
|
-
extensionCommitment: mintExtensionCommitment(extension),
|
|
10103
|
-
}
|
|
10198
|
+
? minterStates[0].state
|
|
10104
10199
|
: {
|
|
10105
10200
|
amount: maxSupply,
|
|
10106
10201
|
owner: hexToBytes(premintRecipient),
|
|
@@ -10120,6 +10215,10 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10120
10215
|
extensionCommitment: holderCommitment,
|
|
10121
10216
|
}
|
|
10122
10217
|
: null;
|
|
10218
|
+
const covenantStates = extension
|
|
10219
|
+
? minterStates.map(({ state }) => state)
|
|
10220
|
+
: [state];
|
|
10221
|
+
if (premintState) covenantStates.push(premintState);
|
|
10123
10222
|
|
|
10124
10223
|
const kw = kaspaWasm;
|
|
10125
10224
|
const {
|
|
@@ -10133,23 +10232,25 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10133
10232
|
payToScriptHashScript,
|
|
10134
10233
|
} = kw;
|
|
10135
10234
|
|
|
10136
|
-
const
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
|
|
10142
|
-
|
|
10235
|
+
const covenantOutputs = covenantStates.map((covenantState) => {
|
|
10236
|
+
const script = buildKcc20ScriptForState(artifact, covenantState);
|
|
10237
|
+
const scriptPublicKey = payToScriptHashScript(script);
|
|
10238
|
+
return {
|
|
10239
|
+
script,
|
|
10240
|
+
scriptPublicKey,
|
|
10241
|
+
address: addressFromScriptPublicKey(
|
|
10242
|
+
scriptPublicKey,
|
|
10243
|
+
network,
|
|
10244
|
+
).toString(),
|
|
10245
|
+
};
|
|
10246
|
+
});
|
|
10247
|
+
const contractAddress = covenantOutputs[0].address;
|
|
10248
|
+
const canonicalCovenantId = p2shScriptHashHex(
|
|
10249
|
+
kw,
|
|
10250
|
+
covenantOutputs[0].script,
|
|
10251
|
+
);
|
|
10143
10252
|
const deploySompi = BigInt(Math.round(amountTkas * Number(SOMPI_PER_TKAS)));
|
|
10144
|
-
const
|
|
10145
|
-
let premintAddress = null;
|
|
10146
|
-
if (premintState) {
|
|
10147
|
-
premintAddress = addressFromScriptPublicKey(
|
|
10148
|
-
payToScriptHashScript(buildKcc20ScriptForState(artifact, premintState)),
|
|
10149
|
-
network,
|
|
10150
|
-
).toString();
|
|
10151
|
-
deployOutputs.push({ address: premintAddress, amount: deploySompi });
|
|
10152
|
-
}
|
|
10253
|
+
const premintOutputIndex = premintState ? covenantOutputs.length - 1 : null;
|
|
10153
10254
|
|
|
10154
10255
|
const rpc = new RpcClient({
|
|
10155
10256
|
url: rpcUrl,
|
|
@@ -10159,12 +10260,12 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10159
10260
|
await rpc.connect();
|
|
10160
10261
|
try {
|
|
10161
10262
|
const utxos = await getUtxosByAddresses(rpc, [walletAddress]);
|
|
10162
|
-
const outputSompi = deploySompi * BigInt(
|
|
10263
|
+
const outputSompi = deploySompi * BigInt(covenantOutputs.length);
|
|
10163
10264
|
const fundingEntry = selectFundingEntry(
|
|
10164
10265
|
utxos.entries,
|
|
10165
10266
|
outputSompi + priorityFee + 10_000_000n,
|
|
10166
10267
|
);
|
|
10167
|
-
const fundingChangeOutputIndex =
|
|
10268
|
+
const fundingChangeOutputIndex = covenantOutputs.length;
|
|
10168
10269
|
const change = utxoAmountSompi(fundingEntry) - outputSompi - priorityFee;
|
|
10169
10270
|
if (change <= 10_000n) {
|
|
10170
10271
|
throw kcc20PsktBuilderError(
|
|
@@ -10174,19 +10275,12 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10174
10275
|
}
|
|
10175
10276
|
|
|
10176
10277
|
const outputs = [
|
|
10177
|
-
|
|
10278
|
+
...covenantOutputs.map(
|
|
10279
|
+
({ scriptPublicKey }) =>
|
|
10280
|
+
new TransactionOutput(deploySompi, scriptPublicKey),
|
|
10281
|
+
),
|
|
10178
10282
|
new TransactionOutput(change, payToAddressScript(walletAddress)),
|
|
10179
10283
|
];
|
|
10180
|
-
if (premintState) {
|
|
10181
|
-
outputs.push(
|
|
10182
|
-
new TransactionOutput(
|
|
10183
|
-
deploySompi,
|
|
10184
|
-
payToScriptHashScript(
|
|
10185
|
-
buildKcc20ScriptForState(artifact, premintState),
|
|
10186
|
-
),
|
|
10187
|
-
),
|
|
10188
|
-
);
|
|
10189
|
-
}
|
|
10190
10284
|
|
|
10191
10285
|
const unsignedTx = new Transaction({
|
|
10192
10286
|
version: 1,
|
|
@@ -10223,29 +10317,8 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10223
10317
|
unsignedTx.version = 1;
|
|
10224
10318
|
setVersionOneInputMassFields(unsignedTx);
|
|
10225
10319
|
|
|
10226
|
-
const covenantOutputIndex =
|
|
10227
|
-
|
|
10228
|
-
contractAddress,
|
|
10229
|
-
network,
|
|
10230
|
-
addressFromScriptPublicKey,
|
|
10231
|
-
);
|
|
10232
|
-
if (covenantOutputIndex < 0)
|
|
10233
|
-
throw new Error("final transaction did not contain the KCC20 output");
|
|
10234
|
-
const covenantOutputIndexes = [covenantOutputIndex];
|
|
10235
|
-
let premintOutputIndex = null;
|
|
10236
|
-
if (premintAddress) {
|
|
10237
|
-
premintOutputIndex = findOutputIndex(
|
|
10238
|
-
unsignedTx,
|
|
10239
|
-
premintAddress,
|
|
10240
|
-
network,
|
|
10241
|
-
addressFromScriptPublicKey,
|
|
10242
|
-
);
|
|
10243
|
-
if (premintOutputIndex < 0)
|
|
10244
|
-
throw new Error(
|
|
10245
|
-
"final transaction did not contain the KCC20 premint output",
|
|
10246
|
-
);
|
|
10247
|
-
covenantOutputIndexes.push(premintOutputIndex);
|
|
10248
|
-
}
|
|
10320
|
+
const covenantOutputIndex = 0;
|
|
10321
|
+
const covenantOutputIndexes = covenantOutputs.map((_, index) => index);
|
|
10249
10322
|
unsignedTx.populateGenesisCovenants([
|
|
10250
10323
|
new GenesisCovenantGroup(0, covenantOutputIndexes),
|
|
10251
10324
|
]);
|
|
@@ -10273,6 +10346,9 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10273
10346
|
"KCC20 deploy PSKT serialization did not return JSON text",
|
|
10274
10347
|
);
|
|
10275
10348
|
}
|
|
10349
|
+
const revealScriptHex = bytesToHex(
|
|
10350
|
+
covenantOutputs[covenantOutputIndex].script,
|
|
10351
|
+
);
|
|
10276
10352
|
|
|
10277
10353
|
return {
|
|
10278
10354
|
schema: OUTPUT_SCHEMA,
|
|
@@ -10289,6 +10365,9 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10289
10365
|
walletAddress,
|
|
10290
10366
|
contractAddress,
|
|
10291
10367
|
covenantOutputIndex,
|
|
10368
|
+
minterOutputIndexes: extension
|
|
10369
|
+
? minterStates.map((_, index) => index)
|
|
10370
|
+
: undefined,
|
|
10292
10371
|
premintOutputIndex,
|
|
10293
10372
|
covenantId: kip20BindingCovenantId,
|
|
10294
10373
|
scriptHashHex: canonicalCovenantId,
|
|
@@ -10299,6 +10378,59 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10299
10378
|
mintPolicy,
|
|
10300
10379
|
publicMintActive: mintPolicy === 2 ? false : undefined,
|
|
10301
10380
|
mintLaneCount: immutableExtension.mintLaneCount.toString(),
|
|
10381
|
+
holderExtensionCommitment: bytesToHex(holderCommitment),
|
|
10382
|
+
revealScriptHex,
|
|
10383
|
+
maximumFeeSompi: (
|
|
10384
|
+
[...feeAdjustedTx.inputs].reduce(
|
|
10385
|
+
(sum, input) =>
|
|
10386
|
+
sum + BigInt(input.utxo?.amount ?? input.utxo?.value),
|
|
10387
|
+
0n,
|
|
10388
|
+
) -
|
|
10389
|
+
[...feeAdjustedTx.outputs].reduce(
|
|
10390
|
+
(sum, output) => sum + BigInt(output.value ?? output.amount),
|
|
10391
|
+
0n,
|
|
10392
|
+
)
|
|
10393
|
+
).toString(),
|
|
10394
|
+
intentInputs: [{ role: "creator-funding", index: 0 }],
|
|
10395
|
+
intentOutputs: buildKcc20DeployIntentOutputs({
|
|
10396
|
+
mintPolicy,
|
|
10397
|
+
covenantId: kip20BindingCovenantId,
|
|
10398
|
+
creator: owner,
|
|
10399
|
+
premintRecipient,
|
|
10400
|
+
premintOwnerScheme,
|
|
10401
|
+
maxSupply,
|
|
10402
|
+
premintSupply,
|
|
10403
|
+
borrowGuard: ZERO_HASH,
|
|
10404
|
+
fixedOutput:
|
|
10405
|
+
mintPolicy === 0
|
|
10406
|
+
? {
|
|
10407
|
+
index: covenantOutputIndex,
|
|
10408
|
+
revealScriptHex,
|
|
10409
|
+
extensionCommitment: bytesToHex(holderCommitment),
|
|
10410
|
+
}
|
|
10411
|
+
: undefined,
|
|
10412
|
+
minterOutputs: minterStates.map(({ state }, index) => ({
|
|
10413
|
+
index,
|
|
10414
|
+
revealScriptHex: bytesToHex(covenantOutputs[index].script),
|
|
10415
|
+
extensionCommitment: bytesToHex(state.extensionCommitment),
|
|
10416
|
+
remainingSupply: mintLaneSupplies[index],
|
|
10417
|
+
})),
|
|
10418
|
+
premintOutput:
|
|
10419
|
+
premintState && premintOutputIndex !== null
|
|
10420
|
+
? {
|
|
10421
|
+
index: premintOutputIndex,
|
|
10422
|
+
revealScriptHex: bytesToHex(
|
|
10423
|
+
covenantOutputs[premintOutputIndex].script,
|
|
10424
|
+
),
|
|
10425
|
+
extensionCommitment: bytesToHex(
|
|
10426
|
+
premintState.extensionCommitment,
|
|
10427
|
+
),
|
|
10428
|
+
}
|
|
10429
|
+
: undefined,
|
|
10430
|
+
}),
|
|
10431
|
+
mintLaneSupplies: extension
|
|
10432
|
+
? mintLaneSupplies.map((supply) => supply.toString())
|
|
10433
|
+
: undefined,
|
|
10302
10434
|
extension: extension ? jsonKcc20MintExtension(extension) : undefined,
|
|
10303
10435
|
...stateToReceiptFields(state),
|
|
10304
10436
|
},
|
|
@@ -10324,14 +10456,14 @@ export function createKcc20PsktBuilderEngine(
|
|
|
10324
10456
|
"utilityTokenAmount",
|
|
10325
10457
|
);
|
|
10326
10458
|
const network =
|
|
10327
|
-
request.network ||
|
|
10459
|
+
request.network || env.KASPA_NETWORK || "testnet-10";
|
|
10328
10460
|
const walletAddress = requireKaspaAddress(request.owner?.walletAddress);
|
|
10329
|
-
const rpcUrl =
|
|
10461
|
+
const rpcUrl = env.KASPA_WRPC_URL || DEFAULT_WRPC_URL;
|
|
10330
10462
|
const amountTkas = parseAmountTkas(
|
|
10331
|
-
|
|
10463
|
+
env.KCC20_FEE_TICKET_OUTPUT_TKAS || DEFAULT_DEPLOY_TKAS,
|
|
10332
10464
|
);
|
|
10333
10465
|
const priorityFee = parseU64(
|
|
10334
|
-
|
|
10466
|
+
env.KCC20_FEE_TICKET_PRIORITY_FEE_SOMPI ||
|
|
10335
10467
|
DEFAULT_PRIORITY_FEE.toString(),
|
|
10336
10468
|
"priorityFee",
|
|
10337
10469
|
);
|
|
@@ -11568,11 +11700,11 @@ export function createKcc20PsktBuilderEngine(
|
|
|
11568
11700
|
|
|
11569
11701
|
async function retryUtxosByAddresses(rpc, addresses, isReady, initial) {
|
|
11570
11702
|
const attempts = parseRetryInteger(
|
|
11571
|
-
|
|
11703
|
+
env.KCC20_SOURCE_UTXO_RETRY_ATTEMPTS,
|
|
11572
11704
|
3,
|
|
11573
11705
|
);
|
|
11574
11706
|
const delayMs = parseRetryInteger(
|
|
11575
|
-
|
|
11707
|
+
env.KCC20_SOURCE_UTXO_RETRY_DELAY_MS,
|
|
11576
11708
|
500,
|
|
11577
11709
|
);
|
|
11578
11710
|
let latest = initial ?? { entries: [] };
|
|
@@ -13221,6 +13353,7 @@ export function createKcc20PsktBuilderEngine(
|
|
|
13221
13353
|
assertTransactionStorageMassStandard,
|
|
13222
13354
|
calculateToccataStorageMass,
|
|
13223
13355
|
parseQuotedProtocolFeeSompi,
|
|
13356
|
+
splitKcc20MintSupply,
|
|
13224
13357
|
}),
|
|
13225
13358
|
};
|
|
13226
13359
|
}
|