@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
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 0.8.0-fee.0
|
|
4
|
+
|
|
5
|
+
- Add fee arithmetic, grouped quotes, policy encoding, creator consent and claim commitments for DEV integration tests.
|
|
6
|
+
- Keep transaction construction on the legacy market path; this prerelease does not build or authorize fee-market spends.
|
|
4
7
|
|
|
5
8
|
## 0.7.0
|
|
6
9
|
|
|
10
|
+
- Remove duplicate nested snapshot artifact files while preserving their public package subpaths as aliases to the canonical root artifacts.
|
|
7
11
|
- Support fixed snapshot supplies above one signed-64-bit KCC1 integer while keeping every holder and reserve amount signed-64-bit.
|
|
8
12
|
- Bind wide fixed supplies with the domain-separated `KASPACOM/KCC20/HOLDER/V2` commitment and preserve V1 commitments for ordinary supplies.
|
|
9
13
|
- Package the two-limb snapshot bootstrap/controller artifacts and encode their updated immutable state and start-plan commitments.
|
package/RELEASING.md
CHANGED
|
@@ -9,6 +9,8 @@ The package is published under the same version to both registries:
|
|
|
9
9
|
|
|
10
10
|
Never publish different contents under the same version. npm package versions
|
|
11
11
|
are immutable, so update `package.json` before each release.
|
|
12
|
+
Prerelease versions use the `next` tag in both registries; stable versions use
|
|
13
|
+
`latest`. Consumers must pin the full prerelease version.
|
|
12
14
|
|
|
13
15
|
## Publishing setup
|
|
14
16
|
|
|
@@ -90,9 +92,11 @@ A green publishing workflow confirms an upload, not consumer compatibility.
|
|
|
90
92
|
Inspect the installed tarball and complete the live release gate before
|
|
91
93
|
consumer deployment. Record any unverified operation families explicitly.
|
|
92
94
|
|
|
93
|
-
##
|
|
95
|
+
## Fee integration prerelease
|
|
94
96
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
Version `0.8.0-fee.0` exposes accounting and policy helpers for DEV integration
|
|
98
|
+
tests. It does not construct fee-market transactions. Run the existing snapshot
|
|
99
|
+
and example tests against the pinned WASM before publishing it under `next`.
|
|
100
|
+
Funded fee-market journeys and signed settlement construction remain required
|
|
101
|
+
before enabling markets or promoting a stable fee release. Confirm trusted npm
|
|
102
|
+
publishing in the first workflow run.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Fee arithmetic for new escrow markets only. Legacy trading is unchanged. */
|
|
2
|
+
export declare const KCC20_ESCROW_POLICY_VERSION: 1;
|
|
3
|
+
export declare const KCC20_ESCROW_PROTOCOL_BPS = 100;
|
|
4
|
+
export declare const KCC20_ESCROW_MAX_CREATOR_BPS = 500;
|
|
5
|
+
export declare const KCC20_ESCROW_MIN_FEE_SOMPI = 50000000n;
|
|
6
|
+
export declare const KCC20_ESCROW_MAX_CLAIM_RECEIPTS = 5;
|
|
7
|
+
export declare const KCC20_ESCROW_MAX_INT = 9223372036854775807n;
|
|
8
|
+
export interface Kcc20EscrowFeeAmounts {
|
|
9
|
+
protocolFeeSompi: bigint;
|
|
10
|
+
creatorFeeSompi: bigint;
|
|
11
|
+
totalFeeSompi: bigint;
|
|
12
|
+
}
|
|
13
|
+
/** A waiver here is a quote assumption, never proof of FeeTicket eligibility. */
|
|
14
|
+
export declare function calculateKcc20EscrowFees(input: {
|
|
15
|
+
grossSompi: bigint;
|
|
16
|
+
creatorFeeBps: number;
|
|
17
|
+
protocolWaived: boolean;
|
|
18
|
+
}): Kcc20EscrowFeeAmounts;
|
|
19
|
+
/** Trading-price components only; excludes network fees and storage deposits.
|
|
20
|
+
* One matched ask/bid is one fill. Call separately for independent fills. */
|
|
21
|
+
export declare function quoteKcc20EscrowSettlement(input: {
|
|
22
|
+
grossSompi: bigint;
|
|
23
|
+
creatorFeeBps: number;
|
|
24
|
+
protocolWaived: boolean;
|
|
25
|
+
kind: "take-ask" | "fill-bid" | "cross-match";
|
|
26
|
+
}): {
|
|
27
|
+
grossSompi: bigint;
|
|
28
|
+
buyerPaysSompi: bigint;
|
|
29
|
+
sellerReceivesSompi: bigint;
|
|
30
|
+
matcherPaysSompi: bigint;
|
|
31
|
+
requiresFeeOutput: boolean;
|
|
32
|
+
protocolFeeSompi: bigint;
|
|
33
|
+
creatorFeeSompi: bigint;
|
|
34
|
+
totalFeeSompi: bigint;
|
|
35
|
+
};
|
|
36
|
+
/** Arithmetic for one atomic trade group. Artifact and UTXO checks belong to
|
|
37
|
+
* the signed transaction builder; this quote does not authorize a FeeTicket. */
|
|
38
|
+
export declare function quoteKcc20EscrowTradeGroup(input: {
|
|
39
|
+
kind: "take-ask" | "fill-bid" | "cross-match";
|
|
40
|
+
fillGrossSompi: readonly bigint[];
|
|
41
|
+
creatorFeeBps: number;
|
|
42
|
+
protocolWaived: boolean;
|
|
43
|
+
}): {
|
|
44
|
+
feeVector: {
|
|
45
|
+
protocolFeeSompi: bigint;
|
|
46
|
+
creatorFeeSompi: bigint;
|
|
47
|
+
}[];
|
|
48
|
+
receiptValueSompi: bigint;
|
|
49
|
+
requiresFeeOutput: boolean;
|
|
50
|
+
grossSompi: bigint;
|
|
51
|
+
protocolFeeSompi: bigint;
|
|
52
|
+
creatorFeeSompi: bigint;
|
|
53
|
+
buyerPaysSompi: bigint;
|
|
54
|
+
sellerReceivesSompi: bigint;
|
|
55
|
+
matcherPaysSompi: bigint;
|
|
56
|
+
};
|
|
57
|
+
/** Accounting description only. The transaction builder must authenticate scripts and live UTXOs. */
|
|
58
|
+
export interface Kcc20FeeReceiptAmounts {
|
|
59
|
+
outpoint: {
|
|
60
|
+
transactionId: string;
|
|
61
|
+
index: number;
|
|
62
|
+
};
|
|
63
|
+
tokenId: string;
|
|
64
|
+
marketId: string;
|
|
65
|
+
policyId: string;
|
|
66
|
+
protocolAccountId: string;
|
|
67
|
+
creatorAccountId: string;
|
|
68
|
+
valueSompi: bigint;
|
|
69
|
+
protocolSompi: bigint;
|
|
70
|
+
creatorSompi: bigint;
|
|
71
|
+
}
|
|
72
|
+
/** Computes a single claim's conservation amounts, without authorizing a spend. */
|
|
73
|
+
export declare function calculateKcc20FeeClaim(receipts: readonly Kcc20FeeReceiptAmounts[], party: "protocol" | "creator"): {
|
|
74
|
+
claimSompi: bigint;
|
|
75
|
+
remainingProtocolSompi: bigint;
|
|
76
|
+
remainingCreatorSompi: bigint;
|
|
77
|
+
consumedSompi: bigint;
|
|
78
|
+
remainderSompi: bigint;
|
|
79
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KCC20_ESCROW_MAX_INT = exports.KCC20_ESCROW_MAX_CLAIM_RECEIPTS = exports.KCC20_ESCROW_MIN_FEE_SOMPI = exports.KCC20_ESCROW_MAX_CREATOR_BPS = exports.KCC20_ESCROW_PROTOCOL_BPS = exports.KCC20_ESCROW_POLICY_VERSION = void 0;
|
|
4
|
+
exports.calculateKcc20EscrowFees = calculateKcc20EscrowFees;
|
|
5
|
+
exports.quoteKcc20EscrowSettlement = quoteKcc20EscrowSettlement;
|
|
6
|
+
exports.quoteKcc20EscrowTradeGroup = quoteKcc20EscrowTradeGroup;
|
|
7
|
+
exports.calculateKcc20FeeClaim = calculateKcc20FeeClaim;
|
|
8
|
+
/** Fee arithmetic for new escrow markets only. Legacy trading is unchanged. */
|
|
9
|
+
exports.KCC20_ESCROW_POLICY_VERSION = 1;
|
|
10
|
+
exports.KCC20_ESCROW_PROTOCOL_BPS = 100;
|
|
11
|
+
exports.KCC20_ESCROW_MAX_CREATOR_BPS = 500;
|
|
12
|
+
exports.KCC20_ESCROW_MIN_FEE_SOMPI = 50000000n;
|
|
13
|
+
exports.KCC20_ESCROW_MAX_CLAIM_RECEIPTS = 5;
|
|
14
|
+
exports.KCC20_ESCROW_MAX_INT = 9223372036854775807n;
|
|
15
|
+
function amount(value, name) {
|
|
16
|
+
if (typeof value !== "bigint" || value < 0n || value > exports.KCC20_ESCROW_MAX_INT) {
|
|
17
|
+
throw new Error(`${name} must be a nonnegative signed-64-bit bigint`);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function add(left, right) {
|
|
22
|
+
return amount(left + right, "sum");
|
|
23
|
+
}
|
|
24
|
+
function fee(gross, bps) {
|
|
25
|
+
// Match the contract without overflowing the intermediate multiplication.
|
|
26
|
+
const rate = BigInt(bps);
|
|
27
|
+
const percentage = (gross / 10000n) * rate + ((gross % 10000n) * rate) / 10000n;
|
|
28
|
+
return percentage < exports.KCC20_ESCROW_MIN_FEE_SOMPI ? exports.KCC20_ESCROW_MIN_FEE_SOMPI : percentage;
|
|
29
|
+
}
|
|
30
|
+
/** A waiver here is a quote assumption, never proof of FeeTicket eligibility. */
|
|
31
|
+
function calculateKcc20EscrowFees(input) {
|
|
32
|
+
const gross = amount(input.grossSompi, "grossSompi");
|
|
33
|
+
if (gross < 50000000n)
|
|
34
|
+
throw new Error("fill gross must be at least 0.5 KAS");
|
|
35
|
+
if (!Number.isInteger(input.creatorFeeBps) || input.creatorFeeBps < 0 || input.creatorFeeBps > exports.KCC20_ESCROW_MAX_CREATOR_BPS) {
|
|
36
|
+
throw new Error("creatorFeeBps must be an integer from 0 to 500");
|
|
37
|
+
}
|
|
38
|
+
if (typeof input.protocolWaived !== "boolean")
|
|
39
|
+
throw new Error("protocolWaived must be boolean");
|
|
40
|
+
const protocolFeeSompi = input.protocolWaived ? 0n : fee(gross, exports.KCC20_ESCROW_PROTOCOL_BPS);
|
|
41
|
+
const creatorFeeSompi = input.creatorFeeBps === 0 ? 0n : fee(gross, input.creatorFeeBps);
|
|
42
|
+
return { protocolFeeSompi, creatorFeeSompi, totalFeeSompi: add(protocolFeeSompi, creatorFeeSompi) };
|
|
43
|
+
}
|
|
44
|
+
/** Trading-price components only; excludes network fees and storage deposits.
|
|
45
|
+
* One matched ask/bid is one fill. Call separately for independent fills. */
|
|
46
|
+
function quoteKcc20EscrowSettlement(input) {
|
|
47
|
+
const fees = calculateKcc20EscrowFees(input);
|
|
48
|
+
if (!["take-ask", "fill-bid", "cross-match"].includes(input.kind))
|
|
49
|
+
throw new Error("unsupported settlement kind");
|
|
50
|
+
if (input.kind === "fill-bid" && input.grossSompi < fees.totalFeeSompi) {
|
|
51
|
+
throw new Error("fill gross cannot cover protocol and creator fees");
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...fees,
|
|
55
|
+
grossSompi: input.grossSompi,
|
|
56
|
+
buyerPaysSompi: input.kind === "take-ask" ? add(input.grossSompi, fees.totalFeeSompi) : input.grossSompi,
|
|
57
|
+
sellerReceivesSompi: input.kind === "fill-bid" ? input.grossSompi - fees.totalFeeSompi : input.grossSompi,
|
|
58
|
+
matcherPaysSompi: input.kind === "cross-match" ? fees.totalFeeSompi : 0n,
|
|
59
|
+
requiresFeeOutput: fees.totalFeeSompi > 0n,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Arithmetic for one atomic trade group. Artifact and UTXO checks belong to
|
|
63
|
+
* the signed transaction builder; this quote does not authorize a FeeTicket. */
|
|
64
|
+
function quoteKcc20EscrowTradeGroup(input) {
|
|
65
|
+
const maxFills = input.kind === "take-ask" ? 16 : input.kind === "fill-bid" ? 10 : input.kind === "cross-match" ? 1 : 0;
|
|
66
|
+
if (!Array.isArray(input.fillGrossSompi) || input.fillGrossSompi.length < 1 || input.fillGrossSompi.length > maxFills) {
|
|
67
|
+
throw new Error("invalid trade group size");
|
|
68
|
+
}
|
|
69
|
+
if (input.kind === "cross-match" && input.protocolWaived) {
|
|
70
|
+
throw new Error("crossed matches cannot use a FeeTicket");
|
|
71
|
+
}
|
|
72
|
+
const feeVector = input.fillGrossSompi.map(grossSompi => quoteKcc20EscrowSettlement({
|
|
73
|
+
grossSompi, creatorFeeBps: input.creatorFeeBps,
|
|
74
|
+
protocolWaived: input.protocolWaived, kind: input.kind,
|
|
75
|
+
}));
|
|
76
|
+
const totals = feeVector.reduce((sum, fill) => ({
|
|
77
|
+
grossSompi: add(sum.grossSompi, fill.grossSompi),
|
|
78
|
+
protocolFeeSompi: add(sum.protocolFeeSompi, fill.protocolFeeSompi),
|
|
79
|
+
creatorFeeSompi: add(sum.creatorFeeSompi, fill.creatorFeeSompi),
|
|
80
|
+
buyerPaysSompi: add(sum.buyerPaysSompi, fill.buyerPaysSompi),
|
|
81
|
+
sellerReceivesSompi: add(sum.sellerReceivesSompi, fill.sellerReceivesSompi),
|
|
82
|
+
matcherPaysSompi: add(sum.matcherPaysSompi, fill.matcherPaysSompi),
|
|
83
|
+
}), {
|
|
84
|
+
grossSompi: 0n, protocolFeeSompi: 0n, creatorFeeSompi: 0n,
|
|
85
|
+
buyerPaysSompi: 0n, sellerReceivesSompi: 0n, matcherPaysSompi: 0n,
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
...totals,
|
|
89
|
+
feeVector: feeVector.map(fill => ({
|
|
90
|
+
protocolFeeSompi: fill.protocolFeeSompi,
|
|
91
|
+
creatorFeeSompi: fill.creatorFeeSompi,
|
|
92
|
+
})),
|
|
93
|
+
receiptValueSompi: add(totals.protocolFeeSompi, totals.creatorFeeSompi),
|
|
94
|
+
requiresFeeOutput: totals.protocolFeeSompi + totals.creatorFeeSompi > 0n,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function id(value) {
|
|
98
|
+
if (typeof value !== "string" || !/^[0-9a-fA-F]{64}$/.test(value))
|
|
99
|
+
throw new Error("identity must be 32-byte hex");
|
|
100
|
+
return value.toLowerCase();
|
|
101
|
+
}
|
|
102
|
+
/** Computes a single claim's conservation amounts, without authorizing a spend. */
|
|
103
|
+
function calculateKcc20FeeClaim(receipts, party) {
|
|
104
|
+
if (party !== "protocol" && party !== "creator")
|
|
105
|
+
throw new Error("unknown claiming party");
|
|
106
|
+
if (!Array.isArray(receipts) || receipts.length < 1 || receipts.length > exports.KCC20_ESCROW_MAX_CLAIM_RECEIPTS) {
|
|
107
|
+
throw new Error("claim must select between one and five receipts");
|
|
108
|
+
}
|
|
109
|
+
const seen = new Set();
|
|
110
|
+
let group;
|
|
111
|
+
let protocol = 0n;
|
|
112
|
+
let creator = 0n;
|
|
113
|
+
let consumed = 0n;
|
|
114
|
+
for (const receipt of receipts) {
|
|
115
|
+
const txid = id(receipt.outpoint.transactionId);
|
|
116
|
+
if (!Number.isInteger(receipt.outpoint.index) || receipt.outpoint.index < 0 || receipt.outpoint.index > 0xffffffff) {
|
|
117
|
+
throw new Error("outpoint index must be uint32");
|
|
118
|
+
}
|
|
119
|
+
const outpoint = `${txid}:${receipt.outpoint.index}`;
|
|
120
|
+
if (seen.has(outpoint))
|
|
121
|
+
throw new Error("duplicate receipt outpoint");
|
|
122
|
+
seen.add(outpoint);
|
|
123
|
+
const identity = [receipt.tokenId, receipt.marketId, receipt.policyId, receipt.protocolAccountId, receipt.creatorAccountId].map(id).join(":");
|
|
124
|
+
const zero = "0".repeat(64);
|
|
125
|
+
if ([receipt.tokenId, receipt.marketId, receipt.policyId, receipt.protocolAccountId].some(value => id(value) === zero)) {
|
|
126
|
+
throw new Error("token, market, policy and protocol account must be nonzero");
|
|
127
|
+
}
|
|
128
|
+
if (id(receipt.protocolAccountId) === id(receipt.creatorAccountId))
|
|
129
|
+
throw new Error("fee accounts must differ");
|
|
130
|
+
if (id(receipt.creatorAccountId) === zero && receipt.creatorSompi !== 0n)
|
|
131
|
+
throw new Error("disabled creator account cannot hold fees");
|
|
132
|
+
if (group !== undefined && identity !== group)
|
|
133
|
+
throw new Error("receipts must share token, market, policy and accounts");
|
|
134
|
+
group = identity;
|
|
135
|
+
const p = amount(receipt.protocolSompi, "protocolSompi");
|
|
136
|
+
const c = amount(receipt.creatorSompi, "creatorSompi");
|
|
137
|
+
const value = amount(receipt.valueSompi, "valueSompi");
|
|
138
|
+
if (value === 0n || value !== add(p, c))
|
|
139
|
+
throw new Error("receipt value must equal nonzero entitlements");
|
|
140
|
+
if ((p > 0n && p < exports.KCC20_ESCROW_MIN_FEE_SOMPI) || (c > 0n && c < exports.KCC20_ESCROW_MIN_FEE_SOMPI)) {
|
|
141
|
+
throw new Error("nonzero entitlement is below the policy minimum");
|
|
142
|
+
}
|
|
143
|
+
if ((party === "protocol" ? p : c) === 0n)
|
|
144
|
+
throw new Error("receipt has no entitlement for claimant");
|
|
145
|
+
protocol = add(protocol, p);
|
|
146
|
+
creator = add(creator, c);
|
|
147
|
+
consumed = add(consumed, value);
|
|
148
|
+
}
|
|
149
|
+
const claimSompi = party === "protocol" ? protocol : creator;
|
|
150
|
+
const remainingProtocolSompi = party === "protocol" ? 0n : protocol;
|
|
151
|
+
const remainingCreatorSompi = party === "creator" ? 0n : creator;
|
|
152
|
+
return { claimSompi, remainingProtocolSompi, remainingCreatorSompi, consumedSompi: consumed,
|
|
153
|
+
remainderSompi: add(remainingProtocolSompi, remainingCreatorSompi) };
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=escrow-fee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-fee.js","sourceRoot":"","sources":["../../src/escrow-fee.ts"],"names":[],"mappings":";;;AAiCA,4DAcC;AAID,gEAmBC;AAID,gEAsCC;AAqBD,wDA+CC;AApLD,+EAA+E;AAClE,QAAA,2BAA2B,GAAG,CAAU,CAAC;AACzC,QAAA,yBAAyB,GAAG,GAAG,CAAC;AAChC,QAAA,4BAA4B,GAAG,GAAG,CAAC;AACnC,QAAA,0BAA0B,GAAG,SAAW,CAAC;AACzC,QAAA,+BAA+B,GAAG,CAAC,CAAC;AACpC,QAAA,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,4BAAoB,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,6CAA6C,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,GAAG,CAAC,IAAY,EAAE,KAAa;IACtC,OAAO,MAAM,CAAC,IAAI,GAAG,KAAK,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,GAAG,CAAC,KAAa,EAAE,GAAW;IACrC,0EAA0E;IAC1E,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACzB,MAAM,UAAU,GAAG,CAAC,KAAK,GAAG,MAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,KAAK,GAAG,MAAO,CAAC,GAAG,IAAI,CAAC,GAAG,MAAO,CAAC;IACnF,OAAO,UAAU,GAAG,kCAA0B,CAAC,CAAC,CAAC,kCAA0B,CAAC,CAAC,CAAC,UAAU,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C,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,72 @@
|
|
|
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;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeKcc20EscrowPolicy = encodeKcc20EscrowPolicy;
|
|
4
|
+
exports.decodeKcc20EscrowPolicy = decodeKcc20EscrowPolicy;
|
|
5
|
+
exports.kcc20EscrowPolicyId = kcc20EscrowPolicyId;
|
|
6
|
+
exports.kcc20CreatorFeeConsent = kcc20CreatorFeeConsent;
|
|
7
|
+
exports.kcc20FeeClaimCommitment = kcc20FeeClaimCommitment;
|
|
8
|
+
const blake3_1 = require("@noble/hashes/blake3");
|
|
9
|
+
const blake2b_1 = require("@noble/hashes/blake2b");
|
|
10
|
+
const escrow_fee_js_1 = require("./escrow-fee.js");
|
|
11
|
+
const ZERO = "0".repeat(64);
|
|
12
|
+
function hex32(value, allowZero = false) {
|
|
13
|
+
if (typeof value !== "string" || !/^[0-9a-fA-F]{64}$/.test(value) || (!allowZero && value === ZERO)) {
|
|
14
|
+
throw new Error("expected nonzero 32-byte identity");
|
|
15
|
+
}
|
|
16
|
+
return Uint8Array.from(value.match(/../g).map(byte => Number.parseInt(byte, 16)));
|
|
17
|
+
}
|
|
18
|
+
function hex(value) {
|
|
19
|
+
return Array.from(value, byte => byte.toString(16).padStart(2, "0")).join("");
|
|
20
|
+
}
|
|
21
|
+
function int64(value) {
|
|
22
|
+
if (typeof value !== "bigint" || value < 0n || value > 0x7fffffffffffffffn)
|
|
23
|
+
throw new Error("expected nonnegative int64");
|
|
24
|
+
const result = new Uint8Array(8);
|
|
25
|
+
new DataView(result.buffer).setBigUint64(0, value, true);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
function concat(...parts) {
|
|
29
|
+
const result = new Uint8Array(parts.reduce((length, part) => length + part.length, 0));
|
|
30
|
+
let offset = 0;
|
|
31
|
+
for (const part of parts) {
|
|
32
|
+
result.set(part, offset);
|
|
33
|
+
offset += part.length;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
function template(value) {
|
|
38
|
+
for (const length of [value.prefixLength, value.suffixLength]) {
|
|
39
|
+
if (!Number.isSafeInteger(length) || length <= 0)
|
|
40
|
+
throw new Error("template lengths must be positive safe integers");
|
|
41
|
+
}
|
|
42
|
+
return concat(hex32(value.hash), int64(BigInt(value.prefixLength)), int64(BigInt(value.suffixLength)));
|
|
43
|
+
}
|
|
44
|
+
function encodeKcc20EscrowPolicy(policy) {
|
|
45
|
+
if (policy.version !== 1)
|
|
46
|
+
throw new Error("unsupported fee policy version");
|
|
47
|
+
if (!Number.isInteger(policy.creatorFeeBps) || policy.creatorFeeBps < 0 || policy.creatorFeeBps > 500)
|
|
48
|
+
throw new Error("creator rate must be 0 to 500 bps");
|
|
49
|
+
const protocol = hex32(policy.protocolAccountId);
|
|
50
|
+
const creator = hex32(policy.creatorAccountId, policy.creatorFeeBps === 0);
|
|
51
|
+
if (hex(protocol) === hex(creator))
|
|
52
|
+
throw new Error("fee account identities must differ");
|
|
53
|
+
if ((policy.creatorFeeBps === 0) !== (hex(creator) === ZERO))
|
|
54
|
+
throw new Error("creator rate and account do not match");
|
|
55
|
+
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));
|
|
56
|
+
}
|
|
57
|
+
function decodeKcc20EscrowPolicy(bytes) {
|
|
58
|
+
if (!(bytes instanceof Uint8Array) || bytes.length !== 361 || bytes[0] !== 1)
|
|
59
|
+
throw new Error("invalid fee policy encoding");
|
|
60
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
61
|
+
const integer = (offset) => {
|
|
62
|
+
const value = view.getBigUint64(offset, true);
|
|
63
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER))
|
|
64
|
+
throw new Error("noncanonical or oversized policy integer");
|
|
65
|
+
return Number(value);
|
|
66
|
+
};
|
|
67
|
+
const readTemplate = (offset) => ({ hash: hex(bytes.slice(offset, offset + 32)),
|
|
68
|
+
prefixLength: integer(offset + 32), suffixLength: integer(offset + 40) });
|
|
69
|
+
const policy = {
|
|
70
|
+
version: 1, creatorFeeBps: integer(1),
|
|
71
|
+
protocolAccountId: hex(bytes.slice(9, 41)), creatorAccountId: hex(bytes.slice(41, 73)),
|
|
72
|
+
receiptTemplate: readTemplate(73), rootTemplate: readTemplate(121),
|
|
73
|
+
holderTemplate: readTemplate(169), askTemplate: readTemplate(217),
|
|
74
|
+
bidTemplate: readTemplate(265), ticketTemplate: readTemplate(313),
|
|
75
|
+
};
|
|
76
|
+
encodeKcc20EscrowPolicy(policy);
|
|
77
|
+
return policy;
|
|
78
|
+
}
|
|
79
|
+
function kcc20EscrowPolicyId(input) {
|
|
80
|
+
if (typeof input.priceScale !== "bigint" || input.priceScale <= 0n)
|
|
81
|
+
throw new Error("priceScale must be positive");
|
|
82
|
+
return hex((0, blake3_1.blake3)(concat(hex32(input.tokenId), hex32(input.feeTicketId, true), int64(input.priceScale), encodeKcc20EscrowPolicy(input.policy))));
|
|
83
|
+
}
|
|
84
|
+
/** Public consent can be reused only for this TN10 market and fixed fee policy.
|
|
85
|
+
* Send `message` to the wallet's standard personal-message signing API. A wallet
|
|
86
|
+
* signature is still required; creating this payload does not establish authority.
|
|
87
|
+
*/
|
|
88
|
+
function kcc20CreatorFeeConsent(input) {
|
|
89
|
+
if (typeof input.priceScale !== "bigint" || input.priceScale <= 0n)
|
|
90
|
+
throw new Error("priceScale must be positive");
|
|
91
|
+
const policy = encodeKcc20EscrowPolicy(input.policy);
|
|
92
|
+
if (input.policy.creatorFeeBps === 0)
|
|
93
|
+
throw new Error("creator consent is only used when creator fees are enabled");
|
|
94
|
+
const commitment = hex((0, blake3_1.blake3)(concat(Uint8Array.of(0xc1), hex32(input.tokenId), hex32(input.marketId), hex32(input.feeTicketId, true), int64(input.priceScale), policy)));
|
|
95
|
+
const message = `KCC20 creator fee consent v1 (TN10)\n${commitment}`;
|
|
96
|
+
const encoder = new TextEncoder();
|
|
97
|
+
const personalMessageHash = hex((0, blake2b_1.blake2b)(encoder.encode(message), {
|
|
98
|
+
dkLen: 32, key: encoder.encode("PersonalMessageSigningHash"),
|
|
99
|
+
}));
|
|
100
|
+
return { commitment, message, personalMessageHash };
|
|
101
|
+
}
|
|
102
|
+
function outpoint(value) {
|
|
103
|
+
if (!Number.isInteger(value.index) || value.index < 0 || value.index > 0xffffffff)
|
|
104
|
+
throw new Error("outpoint index must be uint32");
|
|
105
|
+
return concat(hex32(value.transactionId, true), int64(BigInt(value.index)));
|
|
106
|
+
}
|
|
107
|
+
/** Input order must match the covenant family's consensus input order. */
|
|
108
|
+
function kcc20FeeClaimCommitment(input) {
|
|
109
|
+
const amounts = (0, escrow_fee_js_1.calculateKcc20FeeClaim)(input.receipts, input.party);
|
|
110
|
+
if (!(input.payoutScriptPublicKey instanceof Uint8Array) || input.payoutScriptPublicKey.length < 3)
|
|
111
|
+
throw new Error("serialized payout ScriptPublicKey is required");
|
|
112
|
+
let receiptHash = new Uint8Array(32);
|
|
113
|
+
for (const receipt of input.receipts)
|
|
114
|
+
receiptHash = (0, blake3_1.blake3)(concat(receiptHash, outpoint(receipt.outpoint)));
|
|
115
|
+
const first = input.receipts[0];
|
|
116
|
+
return hex((0, blake3_1.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), (0, blake3_1.blake3)(input.payoutScriptPublicKey))));
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=escrow-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-policy.js","sourceRoot":"","sources":["../../src/escrow-policy.ts"],"names":[],"mappings":";;AA+CA,0DAUC;AAED,0DAmBC;AAED,kDAMC;AAMD,wDAcC;AAQD,0DAeC;AAjID,iDAA8C;AAC9C,mDAAgD;AAChD,mDAAsF;AAgBtF,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC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,KAAK,CAAC,QAAQ,CAAC,EAC9G,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACxF,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,IAAA,eAAM,EAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC;AACrG,CAAC"}
|
package/dist/cjs/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/cjs/index.js
CHANGED
|
@@ -35,6 +35,8 @@ __exportStar(require("./paid-mint-amount.js"), exports);
|
|
|
35
35
|
__exportStar(require("./token-amount.js"), exports);
|
|
36
36
|
__exportStar(require("./token-operation.js"), exports);
|
|
37
37
|
__exportStar(require("./trade-fee.js"), exports);
|
|
38
|
+
__exportStar(require("./escrow-fee.js"), exports);
|
|
39
|
+
__exportStar(require("./escrow-policy.js"), exports);
|
|
38
40
|
__exportStar(require("./trading-operation.js"), exports);
|
|
39
41
|
__exportStar(require("./protocol.js"), exports);
|
|
40
42
|
__exportStar(require("./runtime.js"), exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,sDAAoC;AACpC,gEAA8C;AAC9C,8DA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AEzC,wDAAsC;AACtC,wDAAsC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Fee arithmetic for new escrow markets only. Legacy trading is unchanged. */
|
|
2
|
+
export declare const KCC20_ESCROW_POLICY_VERSION: 1;
|
|
3
|
+
export declare const KCC20_ESCROW_PROTOCOL_BPS = 100;
|
|
4
|
+
export declare const KCC20_ESCROW_MAX_CREATOR_BPS = 500;
|
|
5
|
+
export declare const KCC20_ESCROW_MIN_FEE_SOMPI = 50000000n;
|
|
6
|
+
export declare const KCC20_ESCROW_MAX_CLAIM_RECEIPTS = 5;
|
|
7
|
+
export declare const KCC20_ESCROW_MAX_INT = 9223372036854775807n;
|
|
8
|
+
export interface Kcc20EscrowFeeAmounts {
|
|
9
|
+
protocolFeeSompi: bigint;
|
|
10
|
+
creatorFeeSompi: bigint;
|
|
11
|
+
totalFeeSompi: bigint;
|
|
12
|
+
}
|
|
13
|
+
/** A waiver here is a quote assumption, never proof of FeeTicket eligibility. */
|
|
14
|
+
export declare function calculateKcc20EscrowFees(input: {
|
|
15
|
+
grossSompi: bigint;
|
|
16
|
+
creatorFeeBps: number;
|
|
17
|
+
protocolWaived: boolean;
|
|
18
|
+
}): Kcc20EscrowFeeAmounts;
|
|
19
|
+
/** Trading-price components only; excludes network fees and storage deposits.
|
|
20
|
+
* One matched ask/bid is one fill. Call separately for independent fills. */
|
|
21
|
+
export declare function quoteKcc20EscrowSettlement(input: {
|
|
22
|
+
grossSompi: bigint;
|
|
23
|
+
creatorFeeBps: number;
|
|
24
|
+
protocolWaived: boolean;
|
|
25
|
+
kind: "take-ask" | "fill-bid" | "cross-match";
|
|
26
|
+
}): {
|
|
27
|
+
grossSompi: bigint;
|
|
28
|
+
buyerPaysSompi: bigint;
|
|
29
|
+
sellerReceivesSompi: bigint;
|
|
30
|
+
matcherPaysSompi: bigint;
|
|
31
|
+
requiresFeeOutput: boolean;
|
|
32
|
+
protocolFeeSompi: bigint;
|
|
33
|
+
creatorFeeSompi: bigint;
|
|
34
|
+
totalFeeSompi: bigint;
|
|
35
|
+
};
|
|
36
|
+
/** Arithmetic for one atomic trade group. Artifact and UTXO checks belong to
|
|
37
|
+
* the signed transaction builder; this quote does not authorize a FeeTicket. */
|
|
38
|
+
export declare function quoteKcc20EscrowTradeGroup(input: {
|
|
39
|
+
kind: "take-ask" | "fill-bid" | "cross-match";
|
|
40
|
+
fillGrossSompi: readonly bigint[];
|
|
41
|
+
creatorFeeBps: number;
|
|
42
|
+
protocolWaived: boolean;
|
|
43
|
+
}): {
|
|
44
|
+
feeVector: {
|
|
45
|
+
protocolFeeSompi: bigint;
|
|
46
|
+
creatorFeeSompi: bigint;
|
|
47
|
+
}[];
|
|
48
|
+
receiptValueSompi: bigint;
|
|
49
|
+
requiresFeeOutput: boolean;
|
|
50
|
+
grossSompi: bigint;
|
|
51
|
+
protocolFeeSompi: bigint;
|
|
52
|
+
creatorFeeSompi: bigint;
|
|
53
|
+
buyerPaysSompi: bigint;
|
|
54
|
+
sellerReceivesSompi: bigint;
|
|
55
|
+
matcherPaysSompi: bigint;
|
|
56
|
+
};
|
|
57
|
+
/** Accounting description only. The transaction builder must authenticate scripts and live UTXOs. */
|
|
58
|
+
export interface Kcc20FeeReceiptAmounts {
|
|
59
|
+
outpoint: {
|
|
60
|
+
transactionId: string;
|
|
61
|
+
index: number;
|
|
62
|
+
};
|
|
63
|
+
tokenId: string;
|
|
64
|
+
marketId: string;
|
|
65
|
+
policyId: string;
|
|
66
|
+
protocolAccountId: string;
|
|
67
|
+
creatorAccountId: string;
|
|
68
|
+
valueSompi: bigint;
|
|
69
|
+
protocolSompi: bigint;
|
|
70
|
+
creatorSompi: bigint;
|
|
71
|
+
}
|
|
72
|
+
/** Computes a single claim's conservation amounts, without authorizing a spend. */
|
|
73
|
+
export declare function calculateKcc20FeeClaim(receipts: readonly Kcc20FeeReceiptAmounts[], party: "protocol" | "creator"): {
|
|
74
|
+
claimSompi: bigint;
|
|
75
|
+
remainingProtocolSompi: bigint;
|
|
76
|
+
remainingCreatorSompi: bigint;
|
|
77
|
+
consumedSompi: bigint;
|
|
78
|
+
remainderSompi: bigint;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=escrow-fee.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escrow-fee.d.ts","sourceRoot":"","sources":["../src/escrow-fee.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,eAAO,MAAM,2BAA2B,EAAG,CAAU,CAAC;AACtD,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAC7C,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,0BAA0B,YAAc,CAAC;AACtD,eAAO,MAAM,+BAA+B,IAAI,CAAC;AACjD,eAAO,MAAM,oBAAoB,uBAA6B,CAAC;AAE/D,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;CACvB;AAoBD,iFAAiF;AACjF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;CACzB,GAAG,qBAAqB,CAUxB;AAED;6EAC6E;AAC7E,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,aAAa,CAAC;CAC/C;;;;;;sBA/CmB,MAAM;qBACP,MAAM;mBACR,MAAM;EA2DtB;AAED;gFACgF;AAChF,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IAChD,IAAI,EAAE,UAAU,GAAG,UAAU,GAAG,aAAa,CAAC;IAC9C,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,aAAa,E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