@kaspacom/kcc20-tx-builder 0.6.2 → 0.7.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 +8 -0
- package/RELEASING.md +1 -1
- package/artifacts/KCC20SnapshotBootstrap.placeholder.json +14577 -7985
- package/artifacts/KCC20SnapshotController.placeholder.json +978 -813
- package/dist/abi.d.ts.map +1 -1
- package/dist/abi.js +32 -1
- package/dist/abi.js.map +1 -1
- package/dist/artifacts.d.ts +7 -7
- package/dist/artifacts.js +7 -7
- package/dist/cjs/abi.js +32 -1
- package/dist/cjs/abi.js.map +1 -1
- package/dist/cjs/artifacts.d.ts +7 -7
- package/dist/cjs/artifacts.js +7 -7
- package/dist/cjs/engine.js +22 -22
- package/dist/cjs/engine.js.map +1 -1
- package/dist/cjs/snapshot-deployment.js +2 -1
- package/dist/cjs/snapshot-deployment.js.map +1 -1
- package/dist/cjs/snapshot-operation.js +17 -1
- package/dist/cjs/snapshot-operation.js.map +1 -1
- package/dist/cjs/snapshot-signerless.js +26 -6
- package/dist/cjs/snapshot-signerless.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +22 -22
- package/dist/engine.js.map +1 -1
- package/dist/snapshot-deployment.d.ts.map +1 -1
- package/dist/snapshot-deployment.js +2 -1
- package/dist/snapshot-deployment.js.map +1 -1
- package/dist/snapshot-operation.d.ts.map +1 -1
- package/dist/snapshot-operation.js +17 -1
- package/dist/snapshot-operation.js.map +1 -1
- package/dist/snapshot-signerless.d.ts.map +1 -1
- package/dist/snapshot-signerless.js +26 -6
- package/dist/snapshot-signerless.js.map +1 -1
- package/docs/COMPATIBILITY.json +26 -14
- package/package.json +4 -2
- package/src/abi.ts +46 -6
- package/src/artifacts.ts +7 -7
- package/src/engine.ts +42 -2
- package/src/snapshot-deployment.ts +2 -1
- package/src/snapshot-operation.ts +17 -1
- package/src/snapshot-signerless.ts +30 -6
- package/artifacts/kcc20-snapshot-bootstrap/KCC20SnapshotBootstrap.placeholder.json +0 -101678
- package/artifacts/kcc20-snapshot-controller/KCC20SnapshotController.placeholder.json +0 -46548
|
@@ -618,7 +618,7 @@ export function createKcc20SnapshotPsktBuilder(
|
|
|
618
618
|
params.holderExtensionCommitment,
|
|
619
619
|
"holder extension commitment",
|
|
620
620
|
),
|
|
621
|
-
totalSupply:
|
|
621
|
+
totalSupply: positiveWideAmount(params.totalSupply, "total supply"),
|
|
622
622
|
claimNotBeforeDaaScore: positiveI64(
|
|
623
623
|
params.claimNotBeforeDaaScore,
|
|
624
624
|
"claim-not-before DAA score",
|
|
@@ -1830,6 +1830,22 @@ export function createKcc20SnapshotPsktBuilder(
|
|
|
1830
1830
|
return amount;
|
|
1831
1831
|
}
|
|
1832
1832
|
|
|
1833
|
+
function positiveWideAmount(value, label) {
|
|
1834
|
+
let amount;
|
|
1835
|
+
try {
|
|
1836
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
1837
|
+
throw new Error("unsafe integer");
|
|
1838
|
+
}
|
|
1839
|
+
amount = BigInt(value);
|
|
1840
|
+
} catch {
|
|
1841
|
+
throw new Error(`${label} must be a positive unsigned two-limb integer`);
|
|
1842
|
+
}
|
|
1843
|
+
if (amount <= 0n || amount > (1n << 126n) - 1n) {
|
|
1844
|
+
throw new Error(`${label} must be a positive unsigned two-limb integer`);
|
|
1845
|
+
}
|
|
1846
|
+
return amount;
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1833
1849
|
function nonnegativeI64(value, label) {
|
|
1834
1850
|
let amount;
|
|
1835
1851
|
try {
|
|
@@ -37,9 +37,9 @@ export function buildSnapshotTokenMetadata({
|
|
|
37
37
|
protocolFeeRecipient,
|
|
38
38
|
protocolFeeBps = 0n,
|
|
39
39
|
}) {
|
|
40
|
-
const amount =
|
|
40
|
+
const amount = positiveWideAmount(totalAllocation, "total allocation");
|
|
41
41
|
const extension = {
|
|
42
|
-
kind: 1,
|
|
42
|
+
kind: amount > MAX_I64 ? 2 : 1,
|
|
43
43
|
creator: bytes32(creator, "creator"),
|
|
44
44
|
ticker: bytes32(ticker, "ticker"),
|
|
45
45
|
name: bytes32(name, "name"),
|
|
@@ -164,13 +164,15 @@ export function snapshotStartPlanCommitment({
|
|
|
164
164
|
shards,
|
|
165
165
|
}) {
|
|
166
166
|
const normalized = normalizeStartShards(shards, false);
|
|
167
|
+
const supply = wideAmountLimbs(totalSupply, "total supply");
|
|
167
168
|
return hash256(
|
|
168
169
|
Uint8Array.of(0x22),
|
|
169
170
|
bytes32(migrationCommitment, "migration commitment"),
|
|
170
171
|
bytes32(manifestCommitment, "manifest commitment"),
|
|
171
172
|
bytes32(extensionCommitment, "holder extension commitment"),
|
|
172
173
|
nonzeroBytes32(tokenId, "token id"),
|
|
173
|
-
leI64(
|
|
174
|
+
leI64(supply.high),
|
|
175
|
+
leI64(supply.low),
|
|
174
176
|
leI64(claimActivation(claimNotBeforeDaaScore).lockTime),
|
|
175
177
|
leI64(normalized.length),
|
|
176
178
|
...normalized.flatMap(shardPlanParts),
|
|
@@ -202,7 +204,7 @@ export function buildBootstrapGenesisPlan({
|
|
|
202
204
|
"holder extension commitment",
|
|
203
205
|
);
|
|
204
206
|
const token = nonzeroBytes32(expectedTokenId, "expected token id");
|
|
205
|
-
const supply =
|
|
207
|
+
const supply = positiveWideAmount(totalSupply, "total supply");
|
|
206
208
|
const activation = claimActivation(claimNotBeforeDaaScore).lockTime;
|
|
207
209
|
const bootstrapTemplate = templateParts(bootstrapArtifact);
|
|
208
210
|
validateStartShards(normalized, {
|
|
@@ -816,7 +818,8 @@ export function encodeSnapshotBootstrapState(state) {
|
|
|
816
818
|
push(value.migrationId),
|
|
817
819
|
push(value.manifestCommitment),
|
|
818
820
|
push(value.holderExtensionCommitment),
|
|
819
|
-
push(leI64(value.
|
|
821
|
+
push(leI64(value.totalSupplyHigh)),
|
|
822
|
+
push(leI64(value.totalSupplyLow)),
|
|
820
823
|
push(leI64(value.claimNotBeforeDaaScore)),
|
|
821
824
|
push(value.expectedTokenId),
|
|
822
825
|
push(value.kcc20TemplateHash),
|
|
@@ -1159,7 +1162,7 @@ function normalizeBootstrapState(state) {
|
|
|
1159
1162
|
state.holderExtensionCommitment,
|
|
1160
1163
|
"holder extension commitment",
|
|
1161
1164
|
),
|
|
1162
|
-
totalSupply:
|
|
1165
|
+
totalSupply: positiveWideAmount(state.totalSupply, "total supply"),
|
|
1163
1166
|
claimNotBeforeDaaScore: positiveI64(
|
|
1164
1167
|
state.claimNotBeforeDaaScore,
|
|
1165
1168
|
"claim-not-before DAA score",
|
|
@@ -1217,6 +1220,9 @@ function normalizeBootstrapState(state) {
|
|
|
1217
1220
|
"start plan commitment",
|
|
1218
1221
|
),
|
|
1219
1222
|
};
|
|
1223
|
+
const supplyLimbs = wideAmountLimbs(value.totalSupply, "total supply");
|
|
1224
|
+
value.totalSupplyHigh = supplyLimbs.high;
|
|
1225
|
+
value.totalSupplyLow = supplyLimbs.low;
|
|
1220
1226
|
if (
|
|
1221
1227
|
value.claimNotBeforeDaaScore >= LOCK_TIME_THRESHOLD ||
|
|
1222
1228
|
value.shardCount > BigInt(MAX_SNAPSHOT_SHARDS) ||
|
|
@@ -1503,6 +1509,24 @@ function positiveI64(value, label) {
|
|
|
1503
1509
|
return number;
|
|
1504
1510
|
}
|
|
1505
1511
|
|
|
1512
|
+
function positiveWideAmount(value, label) {
|
|
1513
|
+
if (typeof value === "number" && !Number.isSafeInteger(value)) {
|
|
1514
|
+
throw new Error(`${label} must not be an unsafe JavaScript number`);
|
|
1515
|
+
}
|
|
1516
|
+
const number = BigInt(value);
|
|
1517
|
+
const maximum = (1n << 126n) - 1n;
|
|
1518
|
+
if (number <= 0n || number > maximum) {
|
|
1519
|
+
throw new Error(`${label} must be a positive unsigned two-limb integer`);
|
|
1520
|
+
}
|
|
1521
|
+
return number;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
function wideAmountLimbs(value, label) {
|
|
1525
|
+
const amount = positiveWideAmount(value, label);
|
|
1526
|
+
const base = 1n << 63n;
|
|
1527
|
+
return { high: amount / base, low: amount % base };
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1506
1530
|
function equalBytes(a, b) {
|
|
1507
1531
|
const left = Uint8Array.from(a ?? []);
|
|
1508
1532
|
const right = Uint8Array.from(b ?? []);
|