@kaspacom/kcc20-tx-builder 0.7.0 → 0.8.0-fee.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/RELEASING.md +9 -5
- package/dist/cjs/escrow-fee.d.ts +79 -0
- package/dist/cjs/escrow-fee.js +155 -0
- package/dist/cjs/escrow-fee.js.map +1 -0
- package/dist/cjs/escrow-policy.d.ts +72 -0
- package/dist/cjs/escrow-policy.js +118 -0
- package/dist/cjs/escrow-policy.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/escrow-fee.d.ts +80 -0
- package/dist/escrow-fee.d.ts.map +1 -0
- package/dist/escrow-fee.js +148 -0
- package/dist/escrow-fee.js.map +1 -0
- package/dist/escrow-policy.d.ts +73 -0
- package/dist/escrow-policy.d.ts.map +1 -0
- package/dist/escrow-policy.js +111 -0
- package/dist/escrow-policy.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/docs/COMPATIBILITY.json +1 -1
- package/docs/escrow-fees.md +56 -0
- package/package.json +3 -2
- package/src/escrow-fee.ts +181 -0
- package/src/escrow-policy.ts +130 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/** Fee arithmetic for new escrow markets only. Legacy trading is unchanged. */
|
|
2
|
+
export const KCC20_ESCROW_POLICY_VERSION = 1;
|
|
3
|
+
export const KCC20_ESCROW_PROTOCOL_BPS = 100;
|
|
4
|
+
export const KCC20_ESCROW_MAX_CREATOR_BPS = 500;
|
|
5
|
+
export const KCC20_ESCROW_MIN_FEE_SOMPI = 50000000n;
|
|
6
|
+
export const KCC20_ESCROW_MAX_CLAIM_RECEIPTS = 5;
|
|
7
|
+
export const KCC20_ESCROW_MAX_INT = 9223372036854775807n;
|
|
8
|
+
function amount(value, name) {
|
|
9
|
+
if (typeof value !== "bigint" || value < 0n || value > KCC20_ESCROW_MAX_INT) {
|
|
10
|
+
throw new Error(`${name} must be a nonnegative signed-64-bit bigint`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function add(left, right) {
|
|
15
|
+
return amount(left + right, "sum");
|
|
16
|
+
}
|
|
17
|
+
function fee(gross, bps) {
|
|
18
|
+
// Match the contract without overflowing the intermediate multiplication.
|
|
19
|
+
const rate = BigInt(bps);
|
|
20
|
+
const percentage = (gross / 10000n) * rate + ((gross % 10000n) * rate) / 10000n;
|
|
21
|
+
return percentage < KCC20_ESCROW_MIN_FEE_SOMPI ? KCC20_ESCROW_MIN_FEE_SOMPI : percentage;
|
|
22
|
+
}
|
|
23
|
+
/** A waiver here is a quote assumption, never proof of FeeTicket eligibility. */
|
|
24
|
+
export function calculateKcc20EscrowFees(input) {
|
|
25
|
+
const gross = amount(input.grossSompi, "grossSompi");
|
|
26
|
+
if (gross < 50000000n)
|
|
27
|
+
throw new Error("fill gross must be at least 0.5 KAS");
|
|
28
|
+
if (!Number.isInteger(input.creatorFeeBps) || input.creatorFeeBps < 0 || input.creatorFeeBps > KCC20_ESCROW_MAX_CREATOR_BPS) {
|
|
29
|
+
throw new Error("creatorFeeBps must be an integer from 0 to 500");
|
|
30
|
+
}
|
|
31
|
+
if (typeof input.protocolWaived !== "boolean")
|
|
32
|
+
throw new Error("protocolWaived must be boolean");
|
|
33
|
+
const protocolFeeSompi = input.protocolWaived ? 0n : fee(gross, KCC20_ESCROW_PROTOCOL_BPS);
|
|
34
|
+
const creatorFeeSompi = input.creatorFeeBps === 0 ? 0n : fee(gross, input.creatorFeeBps);
|
|
35
|
+
return { protocolFeeSompi, creatorFeeSompi, totalFeeSompi: add(protocolFeeSompi, creatorFeeSompi) };
|
|
36
|
+
}
|
|
37
|
+
/** Trading-price components only; excludes network fees and storage deposits.
|
|
38
|
+
* One matched ask/bid is one fill. Call separately for independent fills. */
|
|
39
|
+
export function quoteKcc20EscrowSettlement(input) {
|
|
40
|
+
const fees = calculateKcc20EscrowFees(input);
|
|
41
|
+
if (!["take-ask", "fill-bid", "cross-match"].includes(input.kind))
|
|
42
|
+
throw new Error("unsupported settlement kind");
|
|
43
|
+
if (input.kind === "fill-bid" && input.grossSompi < fees.totalFeeSompi) {
|
|
44
|
+
throw new Error("fill gross cannot cover protocol and creator fees");
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...fees,
|
|
48
|
+
grossSompi: input.grossSompi,
|
|
49
|
+
buyerPaysSompi: input.kind === "take-ask" ? add(input.grossSompi, fees.totalFeeSompi) : input.grossSompi,
|
|
50
|
+
sellerReceivesSompi: input.kind === "fill-bid" ? input.grossSompi - fees.totalFeeSompi : input.grossSompi,
|
|
51
|
+
matcherPaysSompi: input.kind === "cross-match" ? fees.totalFeeSompi : 0n,
|
|
52
|
+
requiresFeeOutput: fees.totalFeeSompi > 0n,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Arithmetic for one atomic trade group. Artifact and UTXO checks belong to
|
|
56
|
+
* the signed transaction builder; this quote does not authorize a FeeTicket. */
|
|
57
|
+
export function quoteKcc20EscrowTradeGroup(input) {
|
|
58
|
+
const maxFills = input.kind === "take-ask" ? 16 : input.kind === "fill-bid" ? 10 : input.kind === "cross-match" ? 1 : 0;
|
|
59
|
+
if (!Array.isArray(input.fillGrossSompi) || input.fillGrossSompi.length < 1 || input.fillGrossSompi.length > maxFills) {
|
|
60
|
+
throw new Error("invalid trade group size");
|
|
61
|
+
}
|
|
62
|
+
if (input.kind === "cross-match" && input.protocolWaived) {
|
|
63
|
+
throw new Error("crossed matches cannot use a FeeTicket");
|
|
64
|
+
}
|
|
65
|
+
const feeVector = input.fillGrossSompi.map(grossSompi => quoteKcc20EscrowSettlement({
|
|
66
|
+
grossSompi, creatorFeeBps: input.creatorFeeBps,
|
|
67
|
+
protocolWaived: input.protocolWaived, kind: input.kind,
|
|
68
|
+
}));
|
|
69
|
+
const totals = feeVector.reduce((sum, fill) => ({
|
|
70
|
+
grossSompi: add(sum.grossSompi, fill.grossSompi),
|
|
71
|
+
protocolFeeSompi: add(sum.protocolFeeSompi, fill.protocolFeeSompi),
|
|
72
|
+
creatorFeeSompi: add(sum.creatorFeeSompi, fill.creatorFeeSompi),
|
|
73
|
+
buyerPaysSompi: add(sum.buyerPaysSompi, fill.buyerPaysSompi),
|
|
74
|
+
sellerReceivesSompi: add(sum.sellerReceivesSompi, fill.sellerReceivesSompi),
|
|
75
|
+
matcherPaysSompi: add(sum.matcherPaysSompi, fill.matcherPaysSompi),
|
|
76
|
+
}), {
|
|
77
|
+
grossSompi: 0n, protocolFeeSompi: 0n, creatorFeeSompi: 0n,
|
|
78
|
+
buyerPaysSompi: 0n, sellerReceivesSompi: 0n, matcherPaysSompi: 0n,
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
...totals,
|
|
82
|
+
feeVector: feeVector.map(fill => ({
|
|
83
|
+
protocolFeeSompi: fill.protocolFeeSompi,
|
|
84
|
+
creatorFeeSompi: fill.creatorFeeSompi,
|
|
85
|
+
})),
|
|
86
|
+
receiptValueSompi: add(totals.protocolFeeSompi, totals.creatorFeeSompi),
|
|
87
|
+
requiresFeeOutput: totals.protocolFeeSompi + totals.creatorFeeSompi > 0n,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function id(value) {
|
|
91
|
+
if (typeof value !== "string" || !/^[0-9a-fA-F]{64}$/.test(value))
|
|
92
|
+
throw new Error("identity must be 32-byte hex");
|
|
93
|
+
return value.toLowerCase();
|
|
94
|
+
}
|
|
95
|
+
/** Computes a single claim's conservation amounts, without authorizing a spend. */
|
|
96
|
+
export function calculateKcc20FeeClaim(receipts, party) {
|
|
97
|
+
if (party !== "protocol" && party !== "creator")
|
|
98
|
+
throw new Error("unknown claiming party");
|
|
99
|
+
if (!Array.isArray(receipts) || receipts.length < 1 || receipts.length > KCC20_ESCROW_MAX_CLAIM_RECEIPTS) {
|
|
100
|
+
throw new Error("claim must select between one and five receipts");
|
|
101
|
+
}
|
|
102
|
+
const seen = new Set();
|
|
103
|
+
let group;
|
|
104
|
+
let protocol = 0n;
|
|
105
|
+
let creator = 0n;
|
|
106
|
+
let consumed = 0n;
|
|
107
|
+
for (const receipt of receipts) {
|
|
108
|
+
const txid = id(receipt.outpoint.transactionId);
|
|
109
|
+
if (!Number.isInteger(receipt.outpoint.index) || receipt.outpoint.index < 0 || receipt.outpoint.index > 0xffffffff) {
|
|
110
|
+
throw new Error("outpoint index must be uint32");
|
|
111
|
+
}
|
|
112
|
+
const outpoint = `${txid}:${receipt.outpoint.index}`;
|
|
113
|
+
if (seen.has(outpoint))
|
|
114
|
+
throw new Error("duplicate receipt outpoint");
|
|
115
|
+
seen.add(outpoint);
|
|
116
|
+
const identity = [receipt.tokenId, receipt.marketId, receipt.policyId, receipt.protocolAccountId, receipt.creatorAccountId].map(id).join(":");
|
|
117
|
+
const zero = "0".repeat(64);
|
|
118
|
+
if ([receipt.tokenId, receipt.marketId, receipt.policyId, receipt.protocolAccountId].some(value => id(value) === zero)) {
|
|
119
|
+
throw new Error("token, market, policy and protocol account must be nonzero");
|
|
120
|
+
}
|
|
121
|
+
if (id(receipt.protocolAccountId) === id(receipt.creatorAccountId))
|
|
122
|
+
throw new Error("fee accounts must differ");
|
|
123
|
+
if (id(receipt.creatorAccountId) === zero && receipt.creatorSompi !== 0n)
|
|
124
|
+
throw new Error("disabled creator account cannot hold fees");
|
|
125
|
+
if (group !== undefined && identity !== group)
|
|
126
|
+
throw new Error("receipts must share token, market, policy and accounts");
|
|
127
|
+
group = identity;
|
|
128
|
+
const p = amount(receipt.protocolSompi, "protocolSompi");
|
|
129
|
+
const c = amount(receipt.creatorSompi, "creatorSompi");
|
|
130
|
+
const value = amount(receipt.valueSompi, "valueSompi");
|
|
131
|
+
if (value === 0n || value !== add(p, c))
|
|
132
|
+
throw new Error("receipt value must equal nonzero entitlements");
|
|
133
|
+
if ((p > 0n && p < KCC20_ESCROW_MIN_FEE_SOMPI) || (c > 0n && c < KCC20_ESCROW_MIN_FEE_SOMPI)) {
|
|
134
|
+
throw new Error("nonzero entitlement is below the policy minimum");
|
|
135
|
+
}
|
|
136
|
+
if ((party === "protocol" ? p : c) === 0n)
|
|
137
|
+
throw new Error("receipt has no entitlement for claimant");
|
|
138
|
+
protocol = add(protocol, p);
|
|
139
|
+
creator = add(creator, c);
|
|
140
|
+
consumed = add(consumed, value);
|
|
141
|
+
}
|
|
142
|
+
const claimSompi = party === "protocol" ? protocol : creator;
|
|
143
|
+
const remainingProtocolSompi = party === "protocol" ? 0n : protocol;
|
|
144
|
+
const remainingCreatorSompi = party === "creator" ? 0n : creator;
|
|
145
|
+
return { claimSompi, remainingProtocolSompi, remainingCreatorSompi, consumedSompi: consumed,
|
|
146
|
+
remainderSompi: add(remainingProtocolSompi, remainingCreatorSompi) };
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=escrow-fee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-fee.js","sourceRoot":"","sources":["../src/escrow-fee.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAU,CAAC;AACtD,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAC7C,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAChD,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAW,CAAC;AACtD,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAA0B,CAAC;AAQ/D,SAAS,MAAM,CAAC,KAAa,EAAE,IAAY;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,GAAG,oBAAoB,EAAE,CAAC;QAC5E,MAAM,IAAI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,GAAG,0BAA0B,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,0BAA0B,CAAC,EAAE,CAAC;YAC7F,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,CAAC,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QACtG,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAC5B,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QAC1B,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7D,MAAM,sBAAsB,GAAG,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;IACpE,MAAM,qBAAqB,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACjE,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,aAAa,EAAE,QAAQ;QACzF,cAAc,EAAE,GAAG,CAAC,sBAAsB,EAAE,qBAAqB,CAAC,EAAE,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Kcc20FeeReceiptAmounts } from "./escrow-fee.js";
|
|
2
|
+
/** Fixed 361-byte policy for the versioned fee roles. Decoding is not artifact authentication. */
|
|
3
|
+
export interface Kcc20EscrowPolicy {
|
|
4
|
+
version: 1;
|
|
5
|
+
creatorFeeBps: number;
|
|
6
|
+
protocolAccountId: string;
|
|
7
|
+
creatorAccountId: string;
|
|
8
|
+
receiptTemplate: {
|
|
9
|
+
hash: string;
|
|
10
|
+
prefixLength: number;
|
|
11
|
+
suffixLength: number;
|
|
12
|
+
};
|
|
13
|
+
rootTemplate: {
|
|
14
|
+
hash: string;
|
|
15
|
+
prefixLength: number;
|
|
16
|
+
suffixLength: number;
|
|
17
|
+
};
|
|
18
|
+
holderTemplate: {
|
|
19
|
+
hash: string;
|
|
20
|
+
prefixLength: number;
|
|
21
|
+
suffixLength: number;
|
|
22
|
+
};
|
|
23
|
+
askTemplate: {
|
|
24
|
+
hash: string;
|
|
25
|
+
prefixLength: number;
|
|
26
|
+
suffixLength: number;
|
|
27
|
+
};
|
|
28
|
+
bidTemplate: {
|
|
29
|
+
hash: string;
|
|
30
|
+
prefixLength: number;
|
|
31
|
+
suffixLength: number;
|
|
32
|
+
};
|
|
33
|
+
ticketTemplate: {
|
|
34
|
+
hash: string;
|
|
35
|
+
prefixLength: number;
|
|
36
|
+
suffixLength: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare function encodeKcc20EscrowPolicy(policy: Kcc20EscrowPolicy): Uint8Array;
|
|
40
|
+
export declare function decodeKcc20EscrowPolicy(bytes: Uint8Array): Kcc20EscrowPolicy;
|
|
41
|
+
export declare function kcc20EscrowPolicyId(input: {
|
|
42
|
+
tokenId: string;
|
|
43
|
+
feeTicketId: string;
|
|
44
|
+
priceScale: bigint;
|
|
45
|
+
policy: Kcc20EscrowPolicy;
|
|
46
|
+
}): string;
|
|
47
|
+
/** Public consent can be reused only for this TN10 market and fixed fee policy.
|
|
48
|
+
* Send `message` to the wallet's standard personal-message signing API. A wallet
|
|
49
|
+
* signature is still required; creating this payload does not establish authority.
|
|
50
|
+
*/
|
|
51
|
+
export declare function kcc20CreatorFeeConsent(input: {
|
|
52
|
+
tokenId: string;
|
|
53
|
+
marketId: string;
|
|
54
|
+
feeTicketId: string;
|
|
55
|
+
priceScale: bigint;
|
|
56
|
+
policy: Kcc20EscrowPolicy;
|
|
57
|
+
}): {
|
|
58
|
+
commitment: string;
|
|
59
|
+
message: string;
|
|
60
|
+
personalMessageHash: string;
|
|
61
|
+
};
|
|
62
|
+
/** Input order must match the covenant family's consensus input order. */
|
|
63
|
+
export declare function kcc20FeeClaimCommitment(input: {
|
|
64
|
+
receipts: readonly Kcc20FeeReceiptAmounts[];
|
|
65
|
+
party: "protocol" | "creator";
|
|
66
|
+
accountOutpoint: {
|
|
67
|
+
transactionId: string;
|
|
68
|
+
index: number;
|
|
69
|
+
};
|
|
70
|
+
/** Serialized ScriptPublicKey, including its two-byte little-endian version. */
|
|
71
|
+
payoutScriptPublicKey: Uint8Array;
|
|
72
|
+
}): string;
|
|
73
|
+
//# sourceMappingURL=escrow-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-policy.d.ts","sourceRoot":"","sources":["../src/escrow-policy.ts"],"names":[],"mappings":"AAEA,OAAO,EAA0B,KAAK,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEtF,kGAAkG;AAClG,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,CAAC,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9E,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3E,cAAc,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7E,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE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AAU,CAAC;CACnC,GAAG,MAAM,CAST"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { blake3 } from "@noble/hashes/blake3";
|
|
2
|
+
import { blake2b } from "@noble/hashes/blake2b";
|
|
3
|
+
import { calculateKcc20FeeClaim } from "./escrow-fee.js";
|
|
4
|
+
const ZERO = "0".repeat(64);
|
|
5
|
+
function hex32(value, allowZero = false) {
|
|
6
|
+
if (typeof value !== "string" || !/^[0-9a-fA-F]{64}$/.test(value) || (!allowZero && value === ZERO)) {
|
|
7
|
+
throw new Error("expected nonzero 32-byte identity");
|
|
8
|
+
}
|
|
9
|
+
return Uint8Array.from(value.match(/../g).map(byte => Number.parseInt(byte, 16)));
|
|
10
|
+
}
|
|
11
|
+
function hex(value) {
|
|
12
|
+
return Array.from(value, byte => byte.toString(16).padStart(2, "0")).join("");
|
|
13
|
+
}
|
|
14
|
+
function int64(value) {
|
|
15
|
+
if (typeof value !== "bigint" || value < 0n || value > 0x7fffffffffffffffn)
|
|
16
|
+
throw new Error("expected nonnegative int64");
|
|
17
|
+
const result = new Uint8Array(8);
|
|
18
|
+
new DataView(result.buffer).setBigUint64(0, value, true);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
function concat(...parts) {
|
|
22
|
+
const result = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));
|
|
23
|
+
let offset = 0;
|
|
24
|
+
for (const part of parts) {
|
|
25
|
+
result.set(part, offset);
|
|
26
|
+
offset += part.length;
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
function template(value) {
|
|
31
|
+
for (const length of [value.prefixLength, value.suffixLength]) {
|
|
32
|
+
if (!Number.isSafeInteger(length) || length <= 0)
|
|
33
|
+
throw new Error("template lengths must be positive safe integers");
|
|
34
|
+
}
|
|
35
|
+
return concat(hex32(value.hash), int64(BigInt(value.prefixLength)), int64(BigInt(value.suffixLength)));
|
|
36
|
+
}
|
|
37
|
+
export function encodeKcc20EscrowPolicy(policy) {
|
|
38
|
+
if (policy.version !== 1)
|
|
39
|
+
throw new Error("unsupported fee policy version");
|
|
40
|
+
if (!Number.isInteger(policy.creatorFeeBps) || policy.creatorFeeBps < 0 || policy.creatorFeeBps > 500)
|
|
41
|
+
throw new Error("creator rate must be 0 to 500 bps");
|
|
42
|
+
const protocol = hex32(policy.protocolAccountId);
|
|
43
|
+
const creator = hex32(policy.creatorAccountId, policy.creatorFeeBps === 0);
|
|
44
|
+
if (hex(protocol) === hex(creator))
|
|
45
|
+
throw new Error("fee account identities must differ");
|
|
46
|
+
if ((policy.creatorFeeBps === 0) !== (hex(creator) === ZERO))
|
|
47
|
+
throw new Error("creator rate and account do not match");
|
|
48
|
+
return concat(Uint8Array.of(1), int64(BigInt(policy.creatorFeeBps)), protocol, creator, template(policy.receiptTemplate), template(policy.rootTemplate), template(policy.holderTemplate), template(policy.askTemplate), template(policy.bidTemplate), template(policy.ticketTemplate));
|
|
49
|
+
}
|
|
50
|
+
export function decodeKcc20EscrowPolicy(bytes) {
|
|
51
|
+
if (!(bytes instanceof Uint8Array) || bytes.length !== 361 || bytes[0] !== 1)
|
|
52
|
+
throw new Error("invalid fee policy encoding");
|
|
53
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
54
|
+
const integer = (offset) => {
|
|
55
|
+
const value = view.getBigUint64(offset, true);
|
|
56
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER))
|
|
57
|
+
throw new Error("noncanonical or oversized policy integer");
|
|
58
|
+
return Number(value);
|
|
59
|
+
};
|
|
60
|
+
const readTemplate = (offset) => ({ hash: hex(bytes.slice(offset, offset + 32)),
|
|
61
|
+
prefixLength: integer(offset + 32), suffixLength: integer(offset + 40) });
|
|
62
|
+
const policy = {
|
|
63
|
+
version: 1, creatorFeeBps: integer(1),
|
|
64
|
+
protocolAccountId: hex(bytes.slice(9, 41)), creatorAccountId: hex(bytes.slice(41, 73)),
|
|
65
|
+
receiptTemplate: readTemplate(73), rootTemplate: readTemplate(121),
|
|
66
|
+
holderTemplate: readTemplate(169), askTemplate: readTemplate(217),
|
|
67
|
+
bidTemplate: readTemplate(265), ticketTemplate: readTemplate(313),
|
|
68
|
+
};
|
|
69
|
+
encodeKcc20EscrowPolicy(policy);
|
|
70
|
+
return policy;
|
|
71
|
+
}
|
|
72
|
+
export function kcc20EscrowPolicyId(input) {
|
|
73
|
+
if (typeof input.priceScale !== "bigint" || input.priceScale <= 0n)
|
|
74
|
+
throw new Error("priceScale must be positive");
|
|
75
|
+
return hex(blake3(concat(hex32(input.tokenId), hex32(input.feeTicketId, true), int64(input.priceScale), encodeKcc20EscrowPolicy(input.policy))));
|
|
76
|
+
}
|
|
77
|
+
/** Public consent can be reused only for this TN10 market and fixed fee policy.
|
|
78
|
+
* Send `message` to the wallet's standard personal-message signing API. A wallet
|
|
79
|
+
* signature is still required; creating this payload does not establish authority.
|
|
80
|
+
*/
|
|
81
|
+
export function kcc20CreatorFeeConsent(input) {
|
|
82
|
+
if (typeof input.priceScale !== "bigint" || input.priceScale <= 0n)
|
|
83
|
+
throw new Error("priceScale must be positive");
|
|
84
|
+
const policy = encodeKcc20EscrowPolicy(input.policy);
|
|
85
|
+
if (input.policy.creatorFeeBps === 0)
|
|
86
|
+
throw new Error("creator consent is only used when creator fees are enabled");
|
|
87
|
+
const commitment = hex(blake3(concat(Uint8Array.of(0xc1), hex32(input.tokenId), hex32(input.marketId), hex32(input.feeTicketId, true), int64(input.priceScale), policy)));
|
|
88
|
+
const message = `KCC20 creator fee consent v1 (TN10)\n${commitment}`;
|
|
89
|
+
const encoder = new TextEncoder();
|
|
90
|
+
const personalMessageHash = hex(blake2b(encoder.encode(message), {
|
|
91
|
+
dkLen: 32, key: encoder.encode("PersonalMessageSigningHash"),
|
|
92
|
+
}));
|
|
93
|
+
return { commitment, message, personalMessageHash };
|
|
94
|
+
}
|
|
95
|
+
function outpoint(value) {
|
|
96
|
+
if (!Number.isInteger(value.index) || value.index < 0 || value.index > 0xffffffff)
|
|
97
|
+
throw new Error("outpoint index must be uint32");
|
|
98
|
+
return concat(hex32(value.transactionId, true), int64(BigInt(value.index)));
|
|
99
|
+
}
|
|
100
|
+
/** Input order must match the covenant family's consensus input order. */
|
|
101
|
+
export function kcc20FeeClaimCommitment(input) {
|
|
102
|
+
const amounts = calculateKcc20FeeClaim(input.receipts, input.party);
|
|
103
|
+
if (!(input.payoutScriptPublicKey instanceof Uint8Array) || input.payoutScriptPublicKey.length < 3)
|
|
104
|
+
throw new Error("serialized payout ScriptPublicKey is required");
|
|
105
|
+
let receiptHash = new Uint8Array(32);
|
|
106
|
+
for (const receipt of input.receipts)
|
|
107
|
+
receiptHash = blake3(concat(receiptHash, outpoint(receipt.outpoint)));
|
|
108
|
+
const first = input.receipts[0];
|
|
109
|
+
return hex(blake3(concat(Uint8Array.of(0xf1), hex32(first.tokenId), hex32(first.marketId), hex32(first.policyId), receiptHash, outpoint(input.accountOutpoint), int64(input.party === "creator" ? 1n : 0n), int64(amounts.claimSompi), int64(amounts.remainderSompi), blake3(input.payoutScriptPublicKey))));
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=escrow-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-policy.js","sourceRoot":"","sources":["../src/escrow-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAA+B,MAAM,iBAAiB,CAAC;AAgBtF,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC5B,SAAS,KAAK,CAAC,KAAa,EAAE,SAAS,GAAG,KAAK;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,SAAS,IAAI,KAA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AAC,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AACrG,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export * from "./paid-mint-amount.js";
|
|
|
18
18
|
export * from "./token-amount.js";
|
|
19
19
|
export * from "./token-operation.js";
|
|
20
20
|
export * from "./trade-fee.js";
|
|
21
|
+
export * from "./escrow-fee.js";
|
|
22
|
+
export * from "./escrow-policy.js";
|
|
21
23
|
export * from "./trading-operation.js";
|
|
22
24
|
export * from "./protocol.js";
|
|
23
25
|
export * from "./runtime.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,cAAc,sBA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/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uCAAuC,CAAC;AACtD,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AAEtC,OAAO,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,oBAAoB,MAAM,uCAAuC,CAAC;AAC9E,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,8 @@ export * from "./paid-mint-amount.js";
|
|
|
18
18
|
export * from "./token-amount.js";
|
|
19
19
|
export * from "./token-operation.js";
|
|
20
20
|
export * from "./trade-fee.js";
|
|
21
|
+
export * from "./escrow-fee.js";
|
|
22
|
+
export * from "./escrow-policy.js";
|
|
21
23
|
export * from "./trading-operation.js";
|
|
22
24
|
export * from "./protocol.js";
|
|
23
25
|
export * from "./runtime.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,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iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAC/C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uCAAuC,CAAC;AACtD,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AAEtC,OAAO,KAAK,QAAQ,MAAM,0BAA0B,CAAC;AACrD,OAAO,KAAK,oBAAoB,MAAM,uCAAuC,CAAC;AAC9E,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC"}
|
package/docs/COMPATIBILITY.json
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Experimental fee escrow primitives
|
|
2
|
+
|
|
3
|
+
These exports support the new DEV fee-market contracts. Existing transaction
|
|
4
|
+
construction still uses the legacy fee version. These functions do not build,
|
|
5
|
+
authorize or submit escrow spends, and this change does not publish a package.
|
|
6
|
+
|
|
7
|
+
`calculateKcc20EscrowFees` implements the fixed 1% protocol fee and optional
|
|
8
|
+
0–5% creator fee. Each nonzero share has a 0.5 KAS minimum, applied per fill.
|
|
9
|
+
`protocolWaived` is a quote assumption. A transaction builder must independently
|
|
10
|
+
authenticate and consume an eligible FeeTicket before using that assumption.
|
|
11
|
+
|
|
12
|
+
`quoteKcc20EscrowSettlement` returns the trading-price and fee components for
|
|
13
|
+
take-ask, fill-bid and crossed settlements. Ask buyers pay fees above the price;
|
|
14
|
+
bid sellers receive price minus fees; a crossed matcher funds the fee once.
|
|
15
|
+
The result excludes network fees and storage deposits and is not a complete
|
|
16
|
+
wallet debit/proceeds quote. Fills that cannot cover their fees are rejected.
|
|
17
|
+
|
|
18
|
+
`quoteKcc20EscrowTradeGroup` takes ordered fills from one atomic trade group.
|
|
19
|
+
It calculates each fill's fee independently, then returns one fee vector and
|
|
20
|
+
one summed receipt value. A ticket waiver applies to every fill in that group;
|
|
21
|
+
crossed matches reject a ticket. The function checks the contract's maximum
|
|
22
|
+
fill counts, but it does not prove a group fits the signed transaction mass
|
|
23
|
+
budget or that all fills share one authenticated market and taker. The builder
|
|
24
|
+
must perform those checks before signing. In the current offline proof, a
|
|
25
|
+
two-ask buy passes the conservative mass target and a three-ask buy does not.
|
|
26
|
+
|
|
27
|
+
`calculateKcc20FeeClaim` checks the accounting for one through five distinct
|
|
28
|
+
receipts from the same token, market, policy and fee accounts. It returns the
|
|
29
|
+
claim and retained amounts. This does not establish that the receipts exist,
|
|
30
|
+
are unspent or have authenticated scripts. Construction must revalidate all
|
|
31
|
+
inputs against current chain state and the approved artifacts.
|
|
32
|
+
|
|
33
|
+
`encodeKcc20EscrowPolicy` and `decodeKcc20EscrowPolicy` implement the fixed
|
|
34
|
+
361-byte role policy, with receipt, root, holder, ask, bid and FeeTicket
|
|
35
|
+
template tuples in that order. They reject unsupported versions, noncanonical
|
|
36
|
+
integers, invalid rates and invalid account identities. `kcc20EscrowPolicyId`
|
|
37
|
+
hashes token ID, FeeTicket ID, price scale and the complete policy encoding.
|
|
38
|
+
The protocol rate and fee floors are constants of this contract version.
|
|
39
|
+
|
|
40
|
+
`kcc20FeeClaimCommitment` binds the ordered receipt outpoints, account outpoint,
|
|
41
|
+
claiming party, amounts, market identity and payout ScriptPublicKey. Supply the
|
|
42
|
+
ScriptPublicKey's two-byte version prefix as well as its script bytes. Receipt
|
|
43
|
+
order must match the native covenant family's input order. The consensus proof
|
|
44
|
+
harness uses the same fixed commitment vector.
|
|
45
|
+
|
|
46
|
+
Release requires authenticated artifact resolution, settlement and claim
|
|
47
|
+
construction, complete signed-transaction mass checks, application integration,
|
|
48
|
+
funded TN10 lifecycle proof and independent review of the final artifacts.
|
|
49
|
+
# Creator consent
|
|
50
|
+
|
|
51
|
+
`kcc20CreatorFeeConsent` produces the public message and personal-message hash
|
|
52
|
+
for the new TN10 wrapper. The authenticated creator signs `message` using the
|
|
53
|
+
wallet's standard message-signing API. The commitment covers the native token,
|
|
54
|
+
market, FeeTicket, scale and exact immutable fee policy, including account IDs.
|
|
55
|
+
The helper only constructs the message; it does not authenticate metadata,
|
|
56
|
+
verify a signature, grant creator rights or enable a market.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaspacom/kcc20-tx-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-fee.0",
|
|
4
4
|
"description": "Runtime-independent KCC20 covenant transaction and PSKT construction primitives.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "KaspaCom",
|
|
@@ -88,7 +88,8 @@
|
|
|
88
88
|
"scripts": {
|
|
89
89
|
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node scripts/write-cjs-package.mjs",
|
|
90
90
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
91
|
-
"test": "npm run
|
|
91
|
+
"test:escrow-fee": "npm run build && node --test test/escrow-fee.mjs test/escrow-policy.mjs",
|
|
92
|
+
"test": "npm run typecheck && npm run build && node test/smoke.mjs && node test/cjs-smoke.cjs && node test/snapshot-plan.mjs && node test/token-profiles.mjs && node test/profile-transfer.mjs && node --test test/mint-availability-limit.mjs test/consolidation-profile.mjs test/consolidation-transaction.mjs test/escrow-fee.mjs test/escrow-policy.mjs && node test/pinned-funding.mjs",
|
|
92
93
|
"prepack": "npm test",
|
|
93
94
|
"test:examples": "npm run verify:compatibility && node scripts/test-examples.mjs --browser",
|
|
94
95
|
"verify:compatibility": "node scripts/verify-compatibility.mjs",
|