@kaspacom/kcc20-tx-builder 0.1.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/LICENSE +201 -0
- package/README.md +104 -0
- package/artifacts/KCC20.placeholder.json +77479 -0
- package/artifacts/KCC20FeeTicket.placeholder.json +16846 -0
- package/artifacts/KCC20Orderbook.placeholder.json +78001 -0
- package/artifacts/KCC20Vesting.placeholder.json +4298 -0
- package/artifacts/KCC20Wrapper.placeholder.json +12246 -0
- package/dist/abi.d.ts +44 -0
- package/dist/abi.d.ts.map +1 -0
- package/dist/abi.js +336 -0
- package/dist/abi.js.map +1 -0
- package/dist/action-source-resolver.d.ts +80 -0
- package/dist/action-source-resolver.d.ts.map +1 -0
- package/dist/action-source-resolver.js +412 -0
- package/dist/action-source-resolver.js.map +1 -0
- package/dist/artifacts.d.ts +14 -0
- package/dist/artifacts.d.ts.map +1 -0
- package/dist/artifacts.js +44 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/builder.d.ts +12 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +18 -0
- package/dist/builder.js.map +1 -0
- package/dist/cjs/abi.d.ts +43 -0
- package/dist/cjs/abi.js +361 -0
- package/dist/cjs/abi.js.map +1 -0
- package/dist/cjs/action-source-resolver.d.ts +79 -0
- package/dist/cjs/action-source-resolver.js +435 -0
- package/dist/cjs/action-source-resolver.js.map +1 -0
- package/dist/cjs/artifacts.d.ts +13 -0
- package/dist/cjs/artifacts.js +51 -0
- package/dist/cjs/artifacts.js.map +1 -0
- package/dist/cjs/builder.d.ts +11 -0
- package/dist/cjs/builder.js +22 -0
- package/dist/cjs/builder.js.map +1 -0
- package/dist/cjs/deploy-operation.d.ts +103 -0
- package/dist/cjs/deploy-operation.js +335 -0
- package/dist/cjs/deploy-operation.js.map +1 -0
- package/dist/cjs/encoding.d.ts +5 -0
- package/dist/cjs/encoding.js +51 -0
- package/dist/cjs/encoding.js.map +1 -0
- package/dist/cjs/engine.d.ts +40 -0
- package/dist/cjs/engine.js +8972 -0
- package/dist/cjs/engine.js.map +1 -0
- package/dist/cjs/errors.d.ts +7 -0
- package/dist/cjs/errors.js +23 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/fee-ticket-operation.d.ts +204 -0
- package/dist/cjs/fee-ticket-operation.js +327 -0
- package/dist/cjs/fee-ticket-operation.js.map +1 -0
- package/dist/cjs/index.d.ts +27 -0
- package/dist/cjs/index.js +45 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/ladder-limit-orders.d.ts +41 -0
- package/dist/cjs/ladder-limit-orders.js +129 -0
- package/dist/cjs/ladder-limit-orders.js.map +1 -0
- package/dist/cjs/mint-availability-operation.d.ts +56 -0
- package/dist/cjs/mint-availability-operation.js +95 -0
- package/dist/cjs/mint-availability-operation.js.map +1 -0
- package/dist/cjs/models.d.ts +90 -0
- package/dist/cjs/models.js +6 -0
- package/dist/cjs/models.js.map +1 -0
- package/dist/cjs/operations.d.ts +6 -0
- package/dist/cjs/operations.js +41 -0
- package/dist/cjs/operations.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/paid-mint-amount.d.ts +69 -0
- package/dist/cjs/paid-mint-amount.js +281 -0
- package/dist/cjs/paid-mint-amount.js.map +1 -0
- package/dist/cjs/protocol.d.ts +21 -0
- package/dist/cjs/protocol.js +25 -0
- package/dist/cjs/protocol.js.map +1 -0
- package/dist/cjs/runtime.d.ts +27 -0
- package/dist/cjs/runtime.js +3 -0
- package/dist/cjs/runtime.js.map +1 -0
- package/dist/cjs/sale-common.d.ts +287 -0
- package/dist/cjs/sale-common.js +928 -0
- package/dist/cjs/sale-common.js.map +1 -0
- package/dist/cjs/source-provider.d.ts +11 -0
- package/dist/cjs/source-provider.js +3 -0
- package/dist/cjs/source-provider.js.map +1 -0
- package/dist/cjs/source-validation.d.ts +9 -0
- package/dist/cjs/source-validation.js +33 -0
- package/dist/cjs/source-validation.js.map +1 -0
- package/dist/cjs/token-amount.d.ts +31 -0
- package/dist/cjs/token-amount.js +252 -0
- package/dist/cjs/token-amount.js.map +1 -0
- package/dist/cjs/token-operation.d.ts +135 -0
- package/dist/cjs/token-operation.js +236 -0
- package/dist/cjs/token-operation.js.map +1 -0
- package/dist/cjs/trade-fee.d.ts +60 -0
- package/dist/cjs/trade-fee.js +185 -0
- package/dist/cjs/trade-fee.js.map +1 -0
- package/dist/cjs/trading-operation.d.ts +212 -0
- package/dist/cjs/trading-operation.js +587 -0
- package/dist/cjs/trading-operation.js.map +1 -0
- package/dist/cjs/verify-operation.d.ts +79 -0
- package/dist/cjs/verify-operation.js +246 -0
- package/dist/cjs/verify-operation.js.map +1 -0
- package/dist/cjs/wallet-operation.d.ts +52 -0
- package/dist/cjs/wallet-operation.js +58 -0
- package/dist/cjs/wallet-operation.js.map +1 -0
- package/dist/cjs/wasm-provider.d.ts +15 -0
- package/dist/cjs/wasm-provider.js +20 -0
- package/dist/cjs/wasm-provider.js.map +1 -0
- package/dist/cjs/wrapper-operation.d.ts +196 -0
- package/dist/cjs/wrapper-operation.js +317 -0
- package/dist/cjs/wrapper-operation.js.map +1 -0
- package/dist/deploy-operation.d.ts +104 -0
- package/dist/deploy-operation.d.ts.map +1 -0
- package/dist/deploy-operation.js +327 -0
- package/dist/deploy-operation.js.map +1 -0
- package/dist/encoding.d.ts +6 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +44 -0
- package/dist/encoding.js.map +1 -0
- package/dist/engine.d.ts +41 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +8969 -0
- package/dist/engine.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +18 -0
- package/dist/errors.js.map +1 -0
- package/dist/fee-ticket-operation.d.ts +205 -0
- package/dist/fee-ticket-operation.d.ts.map +1 -0
- package/dist/fee-ticket-operation.js +320 -0
- package/dist/fee-ticket-operation.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/ladder-limit-orders.d.ts +42 -0
- package/dist/ladder-limit-orders.d.ts.map +1 -0
- package/dist/ladder-limit-orders.js +121 -0
- package/dist/ladder-limit-orders.js.map +1 -0
- package/dist/mint-availability-operation.d.ts +57 -0
- package/dist/mint-availability-operation.d.ts.map +1 -0
- package/dist/mint-availability-operation.js +91 -0
- package/dist/mint-availability-operation.js.map +1 -0
- package/dist/models.d.ts +91 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +3 -0
- package/dist/models.js.map +1 -0
- package/dist/operations.d.ts +7 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +36 -0
- package/dist/operations.js.map +1 -0
- package/dist/paid-mint-amount.d.ts +70 -0
- package/dist/paid-mint-amount.d.ts.map +1 -0
- package/dist/paid-mint-amount.js +268 -0
- package/dist/paid-mint-amount.js.map +1 -0
- package/dist/protocol.d.ts +22 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +22 -0
- package/dist/protocol.js.map +1 -0
- package/dist/runtime.d.ts +28 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +2 -0
- package/dist/runtime.js.map +1 -0
- package/dist/sale-common.d.ts +288 -0
- package/dist/sale-common.d.ts.map +1 -0
- package/dist/sale-common.js +844 -0
- package/dist/sale-common.js.map +1 -0
- package/dist/source-provider.d.ts +12 -0
- package/dist/source-provider.d.ts.map +1 -0
- package/dist/source-provider.js +2 -0
- package/dist/source-provider.js.map +1 -0
- package/dist/source-validation.d.ts +10 -0
- package/dist/source-validation.d.ts.map +1 -0
- package/dist/source-validation.js +28 -0
- package/dist/source-validation.js.map +1 -0
- package/dist/token-amount.d.ts +32 -0
- package/dist/token-amount.d.ts.map +1 -0
- package/dist/token-amount.js +237 -0
- package/dist/token-amount.js.map +1 -0
- package/dist/token-operation.d.ts +136 -0
- package/dist/token-operation.d.ts.map +1 -0
- package/dist/token-operation.js +231 -0
- package/dist/token-operation.js.map +1 -0
- package/dist/trade-fee.d.ts +61 -0
- package/dist/trade-fee.d.ts.map +1 -0
- package/dist/trade-fee.js +173 -0
- package/dist/trade-fee.js.map +1 -0
- package/dist/trading-operation.d.ts +213 -0
- package/dist/trading-operation.d.ts.map +1 -0
- package/dist/trading-operation.js +580 -0
- package/dist/trading-operation.js.map +1 -0
- package/dist/verify-operation.d.ts +80 -0
- package/dist/verify-operation.d.ts.map +1 -0
- package/dist/verify-operation.js +243 -0
- package/dist/verify-operation.js.map +1 -0
- package/dist/wallet-operation.d.ts +53 -0
- package/dist/wallet-operation.d.ts.map +1 -0
- package/dist/wallet-operation.js +55 -0
- package/dist/wallet-operation.js.map +1 -0
- package/dist/wasm-provider.d.ts +16 -0
- package/dist/wasm-provider.d.ts.map +1 -0
- package/dist/wasm-provider.js +17 -0
- package/dist/wasm-provider.js.map +1 -0
- package/dist/wrapper-operation.d.ts +197 -0
- package/dist/wrapper-operation.d.ts.map +1 -0
- package/dist/wrapper-operation.js +311 -0
- package/dist/wrapper-operation.js.map +1 -0
- package/index.d.ts +1 -0
- package/package.json +84 -0
- package/src/abi.ts +493 -0
- package/src/action-source-resolver.ts +660 -0
- package/src/artifacts.ts +87 -0
- package/src/builder.ts +37 -0
- package/src/deploy-operation.ts +458 -0
- package/src/encoding.ts +58 -0
- package/src/engine.ts +13226 -0
- package/src/errors.ts +35 -0
- package/src/fee-ticket-operation.ts +518 -0
- package/src/index.ts +27 -0
- package/src/ladder-limit-orders.ts +184 -0
- package/src/mint-availability-operation.ts +146 -0
- package/src/models.ts +103 -0
- package/src/operations.ts +46 -0
- package/src/paid-mint-amount.ts +402 -0
- package/src/protocol.ts +28 -0
- package/src/runtime.ts +29 -0
- package/src/sale-common.ts +1238 -0
- package/src/source-provider.ts +12 -0
- package/src/source-validation.ts +47 -0
- package/src/token-amount.ts +302 -0
- package/src/token-operation.ts +384 -0
- package/src/trade-fee.ts +264 -0
- package/src/trading-operation.ts +842 -0
- package/src/verify-operation.ts +400 -0
- package/src/wallet-operation.ts +86 -0
- package/src/wasm-provider.ts +32 -0
- package/src/wrapper-operation.ts +531 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const KCC20_LADDER_MAX_ORDERS = 20;
|
|
2
|
+
export type Kcc20LadderDirection = "increment" | "decrement";
|
|
3
|
+
export interface Kcc20LadderLimitPlan {
|
|
4
|
+
unitPriceSompi: string[];
|
|
5
|
+
notionalsSompi: bigint[];
|
|
6
|
+
minNotionalSompi: bigint;
|
|
7
|
+
totalNotionalSompi: bigint;
|
|
8
|
+
totalProtocolFeeSompi: bigint;
|
|
9
|
+
totalBuySettlementSompi: bigint;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Builds compounded unit prices for a same-amount resting limit-order ladder.
|
|
13
|
+
*/
|
|
14
|
+
export declare function kcc20LadderUnitPricesSompi(input: {
|
|
15
|
+
baseUnitPriceSompi: bigint;
|
|
16
|
+
count: number;
|
|
17
|
+
direction: Kcc20LadderDirection;
|
|
18
|
+
percent: number;
|
|
19
|
+
}): bigint[];
|
|
20
|
+
export declare function parseKcc20LadderPercent(value: string): number | undefined;
|
|
21
|
+
export declare function planKcc20LadderLimitOrders(input: {
|
|
22
|
+
tokenAmount: string;
|
|
23
|
+
baseUnitPriceSompi: string;
|
|
24
|
+
decimals: number;
|
|
25
|
+
count: number;
|
|
26
|
+
direction: Kcc20LadderDirection;
|
|
27
|
+
percent: number;
|
|
28
|
+
protocolFeeBps: number;
|
|
29
|
+
}): Kcc20LadderLimitPlan | undefined;
|
|
30
|
+
export declare function kcc20LadderMeetsMinOrderValue(plan: Kcc20LadderLimitPlan, minSompi?: bigint): boolean;
|
|
31
|
+
export declare function maxAffordableKcc20LadderCount(input: {
|
|
32
|
+
side: "buy" | "sell";
|
|
33
|
+
tokenAmount: string;
|
|
34
|
+
baseUnitPriceSompi: string;
|
|
35
|
+
decimals: number;
|
|
36
|
+
direction: Kcc20LadderDirection;
|
|
37
|
+
percent: number;
|
|
38
|
+
protocolFeeBps: number;
|
|
39
|
+
availableTokenBaseUnits?: bigint;
|
|
40
|
+
availableKasSompi?: bigint;
|
|
41
|
+
}): number;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KCC20_LADDER_MAX_ORDERS = void 0;
|
|
4
|
+
exports.kcc20LadderUnitPricesSompi = kcc20LadderUnitPricesSompi;
|
|
5
|
+
exports.parseKcc20LadderPercent = parseKcc20LadderPercent;
|
|
6
|
+
exports.planKcc20LadderLimitOrders = planKcc20LadderLimitOrders;
|
|
7
|
+
exports.kcc20LadderMeetsMinOrderValue = kcc20LadderMeetsMinOrderValue;
|
|
8
|
+
exports.maxAffordableKcc20LadderCount = maxAffordableKcc20LadderCount;
|
|
9
|
+
const token_amount_js_1 = require("./token-amount.js");
|
|
10
|
+
const trade_fee_js_1 = require("./trade-fee.js");
|
|
11
|
+
exports.KCC20_LADDER_MAX_ORDERS = 20;
|
|
12
|
+
/**
|
|
13
|
+
* Builds compounded unit prices for a same-amount resting limit-order ladder.
|
|
14
|
+
*/
|
|
15
|
+
function kcc20LadderUnitPricesSompi(input) {
|
|
16
|
+
const count = Math.min(exports.KCC20_LADDER_MAX_ORDERS, Math.max(1, Math.floor(input.count)));
|
|
17
|
+
if (input.baseUnitPriceSompi <= 0n)
|
|
18
|
+
return [];
|
|
19
|
+
const percent = Number.isFinite(input.percent)
|
|
20
|
+
? Math.max(0, input.percent)
|
|
21
|
+
: 0;
|
|
22
|
+
const stepPpm = BigInt(Math.round(percent * 10_000));
|
|
23
|
+
const million = 1000000n;
|
|
24
|
+
const sign = input.direction === "increment" ? 1n : -1n;
|
|
25
|
+
const prices = [];
|
|
26
|
+
let current = input.baseUnitPriceSompi;
|
|
27
|
+
for (let index = 0; index < count; index += 1) {
|
|
28
|
+
if (current <= 0n)
|
|
29
|
+
break;
|
|
30
|
+
prices.push(current);
|
|
31
|
+
if (index === count - 1 || stepPpm === 0n)
|
|
32
|
+
continue;
|
|
33
|
+
const factor = million + sign * stepPpm;
|
|
34
|
+
if (factor <= 0n)
|
|
35
|
+
break;
|
|
36
|
+
const next = (current * factor + million / 2n) / million;
|
|
37
|
+
current =
|
|
38
|
+
next === current
|
|
39
|
+
? input.direction === "increment"
|
|
40
|
+
? current + 1n
|
|
41
|
+
: current - 1n
|
|
42
|
+
: next;
|
|
43
|
+
}
|
|
44
|
+
return prices;
|
|
45
|
+
}
|
|
46
|
+
function parseKcc20LadderPercent(value) {
|
|
47
|
+
const trimmed = value.trim();
|
|
48
|
+
if (!trimmed)
|
|
49
|
+
return undefined;
|
|
50
|
+
const parsed = Number(trimmed);
|
|
51
|
+
return Number.isFinite(parsed) && parsed >= 0 && parsed <= 100
|
|
52
|
+
? parsed
|
|
53
|
+
: undefined;
|
|
54
|
+
}
|
|
55
|
+
function planKcc20LadderLimitOrders(input) {
|
|
56
|
+
let base;
|
|
57
|
+
try {
|
|
58
|
+
base = BigInt(input.baseUnitPriceSompi.trim());
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
if (base <= 0n)
|
|
64
|
+
return undefined;
|
|
65
|
+
const prices = kcc20LadderUnitPricesSompi({
|
|
66
|
+
baseUnitPriceSompi: base,
|
|
67
|
+
count: input.count,
|
|
68
|
+
direction: input.direction,
|
|
69
|
+
percent: input.percent,
|
|
70
|
+
});
|
|
71
|
+
const requested = Math.min(exports.KCC20_LADDER_MAX_ORDERS, Math.max(1, Math.floor(input.count)));
|
|
72
|
+
if (prices.length !== requested)
|
|
73
|
+
return undefined;
|
|
74
|
+
const notionalsSompi = [];
|
|
75
|
+
let totalBuySettlementSompi = 0n;
|
|
76
|
+
for (const price of prices) {
|
|
77
|
+
const total = (0, token_amount_js_1.calculateKcc20OrderTotalSompi)(input.tokenAmount, price.toString(), input.decimals);
|
|
78
|
+
if (!total)
|
|
79
|
+
return undefined;
|
|
80
|
+
const notional = BigInt(total.totalSompi);
|
|
81
|
+
notionalsSompi.push(notional);
|
|
82
|
+
totalBuySettlementSompi +=
|
|
83
|
+
notional + (0, trade_fee_js_1.calculateKcc20ProtocolFeeSompi)(notional, input.protocolFeeBps);
|
|
84
|
+
}
|
|
85
|
+
const totalNotionalSompi = notionalsSompi.reduce((sum, value) => sum + value, 0n);
|
|
86
|
+
const minNotionalSompi = notionalsSompi.reduce((min, value) => (value < min ? value : min), notionalsSompi[0]);
|
|
87
|
+
return {
|
|
88
|
+
unitPriceSompi: prices.map((price) => price.toString()),
|
|
89
|
+
notionalsSompi,
|
|
90
|
+
minNotionalSompi,
|
|
91
|
+
totalNotionalSompi,
|
|
92
|
+
totalProtocolFeeSompi: totalBuySettlementSompi - totalNotionalSompi,
|
|
93
|
+
totalBuySettlementSompi,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function kcc20LadderMeetsMinOrderValue(plan, minSompi = trade_fee_js_1.KCC20_MIN_PROTOCOL_FEE_SOMPI) {
|
|
97
|
+
return plan.minNotionalSompi >= minSompi;
|
|
98
|
+
}
|
|
99
|
+
function maxAffordableKcc20LadderCount(input) {
|
|
100
|
+
if (input.side === "sell") {
|
|
101
|
+
if (input.availableTokenBaseUnits === undefined)
|
|
102
|
+
return exports.KCC20_LADDER_MAX_ORDERS;
|
|
103
|
+
let amount;
|
|
104
|
+
try {
|
|
105
|
+
amount = BigInt((0, token_amount_js_1.parseKcc20DisplayAmountToBaseUnits)(input.tokenAmount, input.decimals, "token amount"));
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return exports.KCC20_LADDER_MAX_ORDERS;
|
|
109
|
+
}
|
|
110
|
+
if (amount <= 0n)
|
|
111
|
+
return exports.KCC20_LADDER_MAX_ORDERS;
|
|
112
|
+
const affordable = input.availableTokenBaseUnits / amount;
|
|
113
|
+
if (affordable < 1n)
|
|
114
|
+
return 1;
|
|
115
|
+
const asNumber = Number(affordable);
|
|
116
|
+
return Number.isSafeInteger(asNumber)
|
|
117
|
+
? Math.min(exports.KCC20_LADDER_MAX_ORDERS, asNumber)
|
|
118
|
+
: exports.KCC20_LADDER_MAX_ORDERS;
|
|
119
|
+
}
|
|
120
|
+
if (input.availableKasSompi === undefined)
|
|
121
|
+
return exports.KCC20_LADDER_MAX_ORDERS;
|
|
122
|
+
for (let count = exports.KCC20_LADDER_MAX_ORDERS; count >= 1; count -= 1) {
|
|
123
|
+
const plan = planKcc20LadderLimitOrders({ ...input, count });
|
|
124
|
+
if (plan && plan.totalBuySettlementSompi <= input.availableKasSompi)
|
|
125
|
+
return count;
|
|
126
|
+
}
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=ladder-limit-orders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ladder-limit-orders.js","sourceRoot":"","sources":["../../src/ladder-limit-orders.ts"],"names":[],"mappings":";;;AAyBA,gEAqCC;AAED,0DAOC;AAED,gEA2DC;AAED,sEAKC;AAED,sEA0CC;AAvLD,uDAG2B;AAC3B,iDAGwB;AAEX,QAAA,uBAAuB,GAAG,EAAE,CAAC;AAa1C;;GAEG;AACH,SAAgB,0BAA0B,CAAC,KAK1C;IACC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CACpB,+BAAuB,EACvB,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CACrC,CAAC;IACF,IAAI,KAAK,CAAC,kBAAkB,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IAE9C,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;QAC5C,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC;QAC5B,CAAC,CAAC,CAAC,CAAC;I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AuB,CAAC;QACjC,CAAC;QACD,IAAI,MAAM,IAAI,EAAE;YAAE,OAAO,+BAAuB,CAAC;QACjD,MAAM,UAAU,GAAG,KAAK,CAAC,uBAAuB,GAAG,MAAM,CAAC;QAC1D,IAAI,UAAU,GAAG,EAAE;YAAE,OAAO,CAAC,CAAC;QAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;QACpC,OAAO,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC;YACnC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,+BAAuB,EAAE,QAAQ,CAAC;YAC7C,CAAC,CAAC,+BAAuB,CAAC;IAC9B,CAAC;IAED,IAAI,KAAK,CAAC,iBAAiB,KAAK,SAAS;QAAE,OAAO,+BAAuB,CAAC;IAC1E,KAAK,IAAI,KAAK,GAAG,+BAAuB,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACjE,MAAM,IAAI,GAAG,0BAA0B,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7D,IAAI,IAAI,IAAI,IAAI,CAAC,uBAAuB,IAAI,KAAK,CAAC,iBAAiB;YACjE,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Kcc20IndexedCovenantUtxo } from "./action-source-resolver.js";
|
|
2
|
+
export interface Kcc20MintAvailabilityWalletInfo {
|
|
3
|
+
walletAddress: string;
|
|
4
|
+
kcc20Owner: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Kcc20BuildMintAvailabilityOperationInput {
|
|
7
|
+
covenantId: string;
|
|
8
|
+
active: boolean;
|
|
9
|
+
activeMinterUtxo: Record<string, unknown>;
|
|
10
|
+
activeMinterUtxos: Record<string, unknown>[];
|
|
11
|
+
}
|
|
12
|
+
export interface Kcc20MintAvailabilityOperationOptions {
|
|
13
|
+
network?: string;
|
|
14
|
+
createdAt?: string;
|
|
15
|
+
requestId?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function resolveKcc20MintAvailabilitySources(input: {
|
|
18
|
+
publicMintControlSupported: boolean;
|
|
19
|
+
activeUtxos: readonly Kcc20IndexedCovenantUtxo[];
|
|
20
|
+
owner: string;
|
|
21
|
+
active: boolean;
|
|
22
|
+
}): {
|
|
23
|
+
activeMinterUtxo: Kcc20IndexedCovenantUtxo;
|
|
24
|
+
activeMinterUtxos: Kcc20IndexedCovenantUtxo[];
|
|
25
|
+
};
|
|
26
|
+
export declare function buildKcc20MintAvailabilityOperation(walletInfo: Kcc20MintAvailabilityWalletInfo, input: Kcc20BuildMintAvailabilityOperationInput, options?: Kcc20MintAvailabilityOperationOptions): {
|
|
27
|
+
requestId: string;
|
|
28
|
+
description: string;
|
|
29
|
+
payload: {
|
|
30
|
+
params: Record<string, unknown>;
|
|
31
|
+
signing: {
|
|
32
|
+
standard: string;
|
|
33
|
+
walletAction: string;
|
|
34
|
+
status: string;
|
|
35
|
+
builderKey: string;
|
|
36
|
+
builderStatus: string;
|
|
37
|
+
submitTransactionSupported: boolean;
|
|
38
|
+
missingDependencies: string[];
|
|
39
|
+
missingSources: never[];
|
|
40
|
+
};
|
|
41
|
+
sourceRequirements: Record<string, unknown>[];
|
|
42
|
+
signerRequirements: Record<string, unknown>[];
|
|
43
|
+
warnings: string[];
|
|
44
|
+
tokenIdentity?: Record<string, unknown> | undefined;
|
|
45
|
+
schema: string;
|
|
46
|
+
status: string;
|
|
47
|
+
requestId: string;
|
|
48
|
+
chain: string;
|
|
49
|
+
network: string;
|
|
50
|
+
createdAt: string;
|
|
51
|
+
owner: import("./wallet-operation.js").Kcc20WalletOperationOwner;
|
|
52
|
+
operation: string;
|
|
53
|
+
contract: string;
|
|
54
|
+
action: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveKcc20MintAvailabilitySources = resolveKcc20MintAvailabilitySources;
|
|
4
|
+
exports.buildKcc20MintAvailabilityOperation = buildKcc20MintAvailabilityOperation;
|
|
5
|
+
const wallet_operation_js_1 = require("./wallet-operation.js");
|
|
6
|
+
const HEX_64_RE = /^[a-f0-9]{64}$/;
|
|
7
|
+
function resolveKcc20MintAvailabilitySources(input) {
|
|
8
|
+
if (!input.publicMintControlSupported) {
|
|
9
|
+
throw new Error("This KCC20 token does not support public mint availability updates");
|
|
10
|
+
}
|
|
11
|
+
const activeMinterUtxos = input.activeUtxos.filter((utxo) => utxo.state?.["isMintAuthority"] === true &&
|
|
12
|
+
Number(utxo.state?.["mintPolicy"]) === 2);
|
|
13
|
+
const activeMinterUtxo = activeMinterUtxos[0];
|
|
14
|
+
if (!activeMinterUtxo?.state)
|
|
15
|
+
throw new Error("Active public minter UTXO not found");
|
|
16
|
+
const state = activeMinterUtxo.state;
|
|
17
|
+
const owner = String(state["owner"] ?? state["ownerIdentifier"] ?? "").toLowerCase();
|
|
18
|
+
const ownerScheme = Number(state["ownerScheme"] ?? state["identifierType"]);
|
|
19
|
+
if (ownerScheme !== 0 || owner !== input.owner.toLowerCase()) {
|
|
20
|
+
throw new Error("Public mint availability updates require the active minter owner");
|
|
21
|
+
}
|
|
22
|
+
const currentActive = state["publicMintActive"] === true;
|
|
23
|
+
if (currentActive === input.active) {
|
|
24
|
+
throw new Error(input.active
|
|
25
|
+
? "Public mint is already active"
|
|
26
|
+
: "Public mint is already paused");
|
|
27
|
+
}
|
|
28
|
+
return { activeMinterUtxo, activeMinterUtxos };
|
|
29
|
+
}
|
|
30
|
+
function buildKcc20MintAvailabilityOperation(walletInfo, input, options = {}) {
|
|
31
|
+
const covenantId = requireHex64(input.covenantId, "covenantId");
|
|
32
|
+
if (typeof input.active !== "boolean") {
|
|
33
|
+
throw new Error("active must be a boolean");
|
|
34
|
+
}
|
|
35
|
+
if (!input.activeMinterUtxo || typeof input.activeMinterUtxo !== "object") {
|
|
36
|
+
throw new Error("activeMinterUtxo is required");
|
|
37
|
+
}
|
|
38
|
+
if (!Array.isArray(input.activeMinterUtxos) ||
|
|
39
|
+
!input.activeMinterUtxos.length) {
|
|
40
|
+
throw new Error("activeMinterUtxos must contain at least one source");
|
|
41
|
+
}
|
|
42
|
+
const outpoints = input.activeMinterUtxos.map((utxo) => utxoOutpoint(utxo));
|
|
43
|
+
const selectedOutpoint = utxoOutpoint(input.activeMinterUtxo);
|
|
44
|
+
return (0, wallet_operation_js_1.buildKcc20WalletOperationFromPlan)(walletInfo, {
|
|
45
|
+
builderKey: "kcc20.set-public-mint-active",
|
|
46
|
+
operation: "set-mint-availability",
|
|
47
|
+
contract: "KCC20",
|
|
48
|
+
action: "setPublicMintActive",
|
|
49
|
+
description: "Build a public mint availability update request.",
|
|
50
|
+
params: {
|
|
51
|
+
covenantId,
|
|
52
|
+
active: input.active,
|
|
53
|
+
activeMinterUtxo: input.activeMinterUtxo,
|
|
54
|
+
activeMinterUtxos: input.activeMinterUtxos,
|
|
55
|
+
},
|
|
56
|
+
sourceRequirements: [
|
|
57
|
+
{
|
|
58
|
+
type: "kcc20-mint-authority-utxo",
|
|
59
|
+
covenantId,
|
|
60
|
+
outpoint: selectedOutpoint,
|
|
61
|
+
outpoints,
|
|
62
|
+
purpose: "preserve remaining supply while updating public mint availability",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: "kaspa-funding-utxo",
|
|
66
|
+
ownerAddress: walletInfo.walletAddress,
|
|
67
|
+
purpose: "fund network fee",
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
warnings: [],
|
|
71
|
+
tokenIdentity: {
|
|
72
|
+
canonicalCovenantId: covenantId,
|
|
73
|
+
deployCandidateId: covenantId,
|
|
74
|
+
},
|
|
75
|
+
}, options);
|
|
76
|
+
}
|
|
77
|
+
function utxoOutpoint(utxo) {
|
|
78
|
+
const txidHex = requireHex64(utxo["txidHex"], "minter txid");
|
|
79
|
+
const vout = Number(utxo["vout"]);
|
|
80
|
+
if (!Number.isInteger(vout) || vout < 0) {
|
|
81
|
+
throw new Error("minter vout must be a non-negative integer");
|
|
82
|
+
}
|
|
83
|
+
return `${txidHex}:${vout}`;
|
|
84
|
+
}
|
|
85
|
+
function requireHex64(value, field) {
|
|
86
|
+
if (typeof value !== "string") {
|
|
87
|
+
throw new Error(`${field} must be 64 hex characters`);
|
|
88
|
+
}
|
|
89
|
+
const normalized = value.trim().toLowerCase().replace(/^0x/, "");
|
|
90
|
+
if (!HEX_64_RE.test(normalized)) {
|
|
91
|
+
throw new Error(`${field} must be 64 hex characters`);
|
|
92
|
+
}
|
|
93
|
+
return normalized;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=mint-availability-operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mint-availability-operation.js","sourceRoot":"","sources":["../../src/mint-availability-operation.ts"],"names":[],"mappings":";;AAuBA,kFA0CC;AAED,kFA0DC;AA7HD,+DAA0E;AAG1E,MAAM,SAAS,GAAG,gBAAgB,CAAC;AAoBnC,SAAgB,mCAAmC,CAAC,KAKnD;IAIC,IAAI,CAAC,KAAK,CAAC,0BAA0B,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IACD,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAChD,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,KAAK,EAAE,CAAC,iBAAiB,CAAC,KAAK,IAAI;QACxC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,CAC3C,CAAC;IACF,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAC9C,IAAI,CAAC,gBAAgB,EAAE,KAAK;QAC1B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,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MAAM,CAAC,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,GAAG,OAAO,IAAI,IAAI,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,YAAY,CAAC,KAAc,EAAE,KAAa;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,4BAA4B,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,4BAA4B,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { KaspaWasmRuntime } from "./runtime.js";
|
|
2
|
+
export declare const KCC20_BUILDER_INPUT_SCHEMA: "kcc20-shared-pskt-builder-input/v1";
|
|
3
|
+
export declare const KCC20_BUILDER_OUTPUT_SCHEMA: "kcc20-shared-pskt-builder-output/v1";
|
|
4
|
+
export type Hex64 = string;
|
|
5
|
+
export interface TransactionOutpoint {
|
|
6
|
+
txidHex: Hex64;
|
|
7
|
+
vout: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CovenantUtxo extends TransactionOutpoint {
|
|
10
|
+
address: string;
|
|
11
|
+
amountSompi: string;
|
|
12
|
+
/** Decoded state required by the selected operation. */
|
|
13
|
+
state: Record<string, unknown>;
|
|
14
|
+
/** Optional script/artifact data supplied by the source resolver. */
|
|
15
|
+
scriptHex?: string;
|
|
16
|
+
artifactKey?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface FundingUtxo extends TransactionOutpoint {
|
|
19
|
+
address: string;
|
|
20
|
+
amountSompi: string;
|
|
21
|
+
scriptPublicKeyHex?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface BuildSources {
|
|
24
|
+
covenantUtxos?: CovenantUtxo[];
|
|
25
|
+
walletUtxos: FundingUtxo[];
|
|
26
|
+
optionalFeeTicketUtxos?: CovenantUtxo[];
|
|
27
|
+
}
|
|
28
|
+
export interface ArtifactDescriptor {
|
|
29
|
+
key: string;
|
|
30
|
+
version: string;
|
|
31
|
+
hash: Hex64;
|
|
32
|
+
abi?: unknown;
|
|
33
|
+
script?: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface BuildContext {
|
|
36
|
+
network: string;
|
|
37
|
+
walletAddress: string;
|
|
38
|
+
ownerIdentifier: string;
|
|
39
|
+
protocolVersion: string;
|
|
40
|
+
artifacts: Record<string, ArtifactDescriptor>;
|
|
41
|
+
/** Values normally controlled by backend configuration. */
|
|
42
|
+
protocolFeeBps?: string;
|
|
43
|
+
priorityFeeSompi?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface Kcc20PsktBuildRequest {
|
|
46
|
+
schema: typeof KCC20_BUILDER_INPUT_SCHEMA;
|
|
47
|
+
builderKey: string;
|
|
48
|
+
operation: string;
|
|
49
|
+
action: string;
|
|
50
|
+
params: Record<string, unknown>;
|
|
51
|
+
context: BuildContext;
|
|
52
|
+
sources: BuildSources;
|
|
53
|
+
}
|
|
54
|
+
export interface SignInput {
|
|
55
|
+
index: number;
|
|
56
|
+
sighashType?: number;
|
|
57
|
+
}
|
|
58
|
+
export interface CovenantSigningScript {
|
|
59
|
+
inputIndex: number;
|
|
60
|
+
scriptHex: string;
|
|
61
|
+
signType?: string;
|
|
62
|
+
signatureScriptHex?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface Kcc20PsktBuildResult {
|
|
65
|
+
schema: typeof KCC20_BUILDER_OUTPUT_SCHEMA;
|
|
66
|
+
psktTransactionJson: string;
|
|
67
|
+
signInputs: SignInput[];
|
|
68
|
+
scripts?: CovenantSigningScript[];
|
|
69
|
+
sourceOutpoints: string[];
|
|
70
|
+
artifactHashes: Record<string, Hex64>;
|
|
71
|
+
operationDigest: Hex64;
|
|
72
|
+
metadata?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
export interface Kcc20PsktBuilderDependencies {
|
|
75
|
+
wasm: KaspaWasmRuntime;
|
|
76
|
+
artifacts?: Record<string, unknown>;
|
|
77
|
+
artifactProvider?: (key: string) => Promise<unknown>;
|
|
78
|
+
config?: Record<string, unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* Host-owned source transport. When supplied, the builder does not create,
|
|
81
|
+
* connect, or disconnect an RPC client; the host may therefore back this
|
|
82
|
+
* provider with one long-lived browser or server connection.
|
|
83
|
+
*/
|
|
84
|
+
sourceProvider?: {
|
|
85
|
+
getUtxosByAddresses(args: {
|
|
86
|
+
addresses: string[];
|
|
87
|
+
}): Promise<unknown>;
|
|
88
|
+
};
|
|
89
|
+
rpcClientFactory?: (config: unknown) => any;
|
|
90
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KCC20_BUILDER_OUTPUT_SCHEMA = exports.KCC20_BUILDER_INPUT_SCHEMA = void 0;
|
|
4
|
+
exports.KCC20_BUILDER_INPUT_SCHEMA = "kcc20-shared-pskt-builder-input/v1";
|
|
5
|
+
exports.KCC20_BUILDER_OUTPUT_SCHEMA = "kcc20-shared-pskt-builder-output/v1";
|
|
6
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":";;;AAEa,QAAA,0BAA0B,GACrC,oCAA6C,CAAC;AACnC,QAAA,2BAA2B,GACtC,qCAA8C,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const KCC20_BUILDER_KEYS: readonly ["kcc20.deploy-token", "kcc20.mint", "kcc20.set-public-mint-active", "kcc20.transfer", "kcc20.consolidate-holders", "kcc20.reveal-token", "kcc20wrapper.deploy-market", "kcc20wrapper.wrap", "kcc20wrapper.unwrap", "kcc20orderbook.create-bid", "kcc20orderbook.create-ask", "kcc20orderbook.fill-ask", "kcc20orderbook.fill-bid", "kcc20orderbook.sweep-asks", "kcc20orderbook.sweep-bids", "kcc20orderbook.consolidate-holders", "kcc20orderbook.cancel-ask", "kcc20orderbook.cancel-bid", "fee-ticket.deploy-root", "fee-ticket.update-denomination", "fee-ticket.create-from-utility-burn", "fee-ticket.burn", "fee-ticket.transfer"];
|
|
2
|
+
export type Kcc20BuilderKey = (typeof KCC20_BUILDER_KEYS)[number];
|
|
3
|
+
export declare function isKcc20BuilderKey(value: string): value is Kcc20BuilderKey;
|
|
4
|
+
export declare const BACKEND_ONLY_BUILDER_KEYS: readonly ["kcc20orderbook.matcher-settle-crossed"];
|
|
5
|
+
export type BackendOnlyBuilderKey = (typeof BACKEND_ONLY_BUILDER_KEYS)[number];
|
|
6
|
+
export declare function isBackendOnlyBuilderKey(value: unknown): value is BackendOnlyBuilderKey;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BACKEND_ONLY_BUILDER_KEYS = exports.KCC20_BUILDER_KEYS = void 0;
|
|
4
|
+
exports.isKcc20BuilderKey = isKcc20BuilderKey;
|
|
5
|
+
exports.isBackendOnlyBuilderKey = isBackendOnlyBuilderKey;
|
|
6
|
+
exports.KCC20_BUILDER_KEYS = [
|
|
7
|
+
"kcc20.deploy-token",
|
|
8
|
+
"kcc20.mint",
|
|
9
|
+
"kcc20.set-public-mint-active",
|
|
10
|
+
"kcc20.transfer",
|
|
11
|
+
"kcc20.consolidate-holders",
|
|
12
|
+
"kcc20.reveal-token",
|
|
13
|
+
"kcc20wrapper.deploy-market",
|
|
14
|
+
"kcc20wrapper.wrap",
|
|
15
|
+
"kcc20wrapper.unwrap",
|
|
16
|
+
"kcc20orderbook.create-bid",
|
|
17
|
+
"kcc20orderbook.create-ask",
|
|
18
|
+
"kcc20orderbook.fill-ask",
|
|
19
|
+
"kcc20orderbook.fill-bid",
|
|
20
|
+
"kcc20orderbook.sweep-asks",
|
|
21
|
+
"kcc20orderbook.sweep-bids",
|
|
22
|
+
"kcc20orderbook.consolidate-holders",
|
|
23
|
+
"kcc20orderbook.cancel-ask",
|
|
24
|
+
"kcc20orderbook.cancel-bid",
|
|
25
|
+
"fee-ticket.deploy-root",
|
|
26
|
+
"fee-ticket.update-denomination",
|
|
27
|
+
"fee-ticket.create-from-utility-burn",
|
|
28
|
+
"fee-ticket.burn",
|
|
29
|
+
"fee-ticket.transfer",
|
|
30
|
+
];
|
|
31
|
+
function isKcc20BuilderKey(value) {
|
|
32
|
+
return exports.KCC20_BUILDER_KEYS.includes(value);
|
|
33
|
+
}
|
|
34
|
+
exports.BACKEND_ONLY_BUILDER_KEYS = [
|
|
35
|
+
"kcc20orderbook.matcher-settle-crossed",
|
|
36
|
+
];
|
|
37
|
+
function isBackendOnlyBuilderKey(value) {
|
|
38
|
+
return (typeof value === "string" &&
|
|
39
|
+
exports.BACKEND_ONLY_BUILDER_KEYS.includes(value));
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/operations.ts"],"names":[],"mappings":";;;AA4BA,8CAEC;AAQD,0DAOC;AA7CY,QAAA,kBAAkB,GAAG;IAChC,oBAAoB;IACpB,YAAY;IACZ,8BAA8B;IAC9B,gBAAgB;IAChB,2BAA2B;IAC3B,oBAAoB;IACpB,4BAA4B;IAC5B,mBAAmB;IACnB,qBAAqB;IACrB,2BAA2B;IAC3B,2BAA2B;IAC3B,yBAAyB;IACzB,yBAAyB;IACzB,2BAA2B;IAC3B,2BAA2B;IAC3B,oCAAoC;IACpC,2BAA2B;IAC3B,2BAA2B;IAC3B,wBAAwB;IACxB,gCAAgC;IAChC,qCAAqC;IACrC,iBAAiB;IACjB,qBAAqB;CACb,CAAC;AAIX,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,OAAQ,0BAAwC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAEY,QAAA,yBAAyB,GAAG;IACvC,uCAAuC;CAC/B,CAAC;AAIX,SAAgB,uBAAuB,CACrC,KAAc;IAEd,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACxB,iCAA+C,CAAC,QAAQ,CAAC,KAAK,CAAC,CACjE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare const KCC20_PAID_MINT_MIN_GROSS_SOMPI = 50000000n;
|
|
2
|
+
export declare const KCC20_VERIFY_PAID_MINT_MIN_GROSS_SOMPI = 100000000n;
|
|
3
|
+
export declare const KCC20_RECOMMENDED_PAID_MINT_MIN_GROSS_SOMPI = 55000000n;
|
|
4
|
+
export declare const KCC20_MIN_PAID_MINT_TREASURY_OUTPUT_SOMPI = 2003085n;
|
|
5
|
+
export interface Kcc20PaidMintAmountQuote {
|
|
6
|
+
tokenAmount: bigint;
|
|
7
|
+
adjustedTokenAmount: bigint;
|
|
8
|
+
grossSompi: bigint;
|
|
9
|
+
adjusted: boolean;
|
|
10
|
+
belowMinimumGross: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Checks whether all remaining paid-mint supply can produce at least the
|
|
14
|
+
* required gross amount. The comparison is cross-multiplied so fractional
|
|
15
|
+
* display scales are handled without rounding or floating-point arithmetic.
|
|
16
|
+
*/
|
|
17
|
+
export declare function kcc20PaidMintCapacityMeetsMinimumGross(input: {
|
|
18
|
+
remainingTokenAmount: bigint;
|
|
19
|
+
unitPriceSompi: bigint;
|
|
20
|
+
priceScale: bigint;
|
|
21
|
+
minimumGrossSompi?: bigint;
|
|
22
|
+
}): boolean;
|
|
23
|
+
export declare function kcc20PaidMintExactGrossSompi(input: {
|
|
24
|
+
tokenAmount: bigint;
|
|
25
|
+
unitPriceSompi: bigint;
|
|
26
|
+
priceScale: bigint;
|
|
27
|
+
}): bigint;
|
|
28
|
+
export declare function kcc20PaidMintAmountStep(unitPriceSompi: bigint, priceScale: bigint): bigint;
|
|
29
|
+
export declare function kcc20SnapPaidMintAmountUp(input: {
|
|
30
|
+
tokenAmount: bigint;
|
|
31
|
+
unitPriceSompi: bigint;
|
|
32
|
+
priceScale: bigint;
|
|
33
|
+
}): bigint;
|
|
34
|
+
export declare function kcc20MinimumPaidMintAmount(input: {
|
|
35
|
+
unitPriceSompi: bigint;
|
|
36
|
+
priceScale: bigint;
|
|
37
|
+
minGrossSompi?: bigint;
|
|
38
|
+
protocolFeeBps?: number | null;
|
|
39
|
+
}): bigint;
|
|
40
|
+
export declare function kcc20ValidatePaidMintAmount(input: {
|
|
41
|
+
tokenAmount: bigint;
|
|
42
|
+
unitPriceSompi: bigint;
|
|
43
|
+
priceScale: bigint;
|
|
44
|
+
minGrossSompi?: bigint;
|
|
45
|
+
protocolFeeBps?: number | null;
|
|
46
|
+
minimumGrossLabel?: string;
|
|
47
|
+
}): void;
|
|
48
|
+
export declare function kcc20PaidMintFeeSplit(grossSompi: bigint, protocolFeeBps: number | null | undefined, minGrossSompi?: bigint): {
|
|
49
|
+
fee: bigint;
|
|
50
|
+
net: bigint;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Produces a transaction-safe paid-mint amount. It enforces exact sompi,
|
|
54
|
+
* protocol-fee, and non-zero treasury-output dust constraints in one place.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildKcc20PaidMintAmountQuote(input: {
|
|
57
|
+
tokenAmount: bigint;
|
|
58
|
+
unitPriceSompi: bigint;
|
|
59
|
+
priceScale: bigint;
|
|
60
|
+
protocolFeeBps?: number | null;
|
|
61
|
+
minimumGrossSompi?: bigint;
|
|
62
|
+
}): Kcc20PaidMintAmountQuote | undefined;
|
|
63
|
+
export declare function kcc20MinimumSafePaidMintAmount(input: {
|
|
64
|
+
unitPriceSompi: bigint;
|
|
65
|
+
priceScale: bigint;
|
|
66
|
+
protocolFeeBps?: number | null;
|
|
67
|
+
minimumGrossSompi?: bigint;
|
|
68
|
+
}): bigint | undefined;
|
|
69
|
+
export declare function isKcc20SafePaidMintGross(grossSompi: bigint, protocolFeeBps?: number | null): boolean;
|