@inversealtruism/cairnx-core 0.1.36 → 0.1.37
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/CONVENTION.md +125 -3
- package/dist/index.cjs +255 -29
- package/dist/index.d.cts +101 -14
- package/dist/index.d.ts +101 -14
- package/dist/index.js +234 -21
- package/package.json +2 -2
- package/test/vectors/cases.json +787 -1
package/dist/index.cjs
CHANGED
|
@@ -36,22 +36,27 @@ __export(index_exports, {
|
|
|
36
36
|
DEPLOY_FEE: () => DEPLOY_FEE,
|
|
37
37
|
DEPLOY_KEYS: () => DEPLOY_KEYS,
|
|
38
38
|
DOMAIN: () => DOMAIN,
|
|
39
|
-
EPOCH_LEN: () =>
|
|
39
|
+
EPOCH_LEN: () => import_csd_codec5.EPOCH_LEN,
|
|
40
|
+
FCLAIM_KEYS: () => FCLAIM_KEYS,
|
|
41
|
+
FCLAIM_MAX_EPOCH_AHEAD: () => FCLAIM_MAX_EPOCH_AHEAD,
|
|
40
42
|
FEE_BPS: () => FEE_BPS,
|
|
41
43
|
FEE_BPS_V16: () => FEE_BPS_V16,
|
|
42
44
|
FEE_GATE_MARGIN_BLOCKS: () => FEE_GATE_MARGIN_BLOCKS,
|
|
45
|
+
FILL_TIP_MARGIN: () => FILL_TIP_MARGIN,
|
|
43
46
|
FINALIZE_TIP_MARGIN: () => FINALIZE_TIP_MARGIN,
|
|
44
|
-
|
|
47
|
+
GAP_NEEDED: () => GAP_NEEDED,
|
|
48
|
+
HALVING_INTERVAL: () => import_csd_codec5.HALVING_INTERVAL,
|
|
45
49
|
HASH_RE: () => HASH_RE,
|
|
46
|
-
INITIAL_REWARD: () =>
|
|
50
|
+
INITIAL_REWARD: () => import_csd_codec5.INITIAL_REWARD,
|
|
47
51
|
MAX_ACTIVE_CLAIMS: () => MAX_ACTIVE_CLAIMS,
|
|
48
52
|
MAX_AMOUNT: () => MAX_AMOUNT,
|
|
49
53
|
MAX_OFFER_EPOCHS: () => MAX_OFFER_EPOCHS,
|
|
50
54
|
MAX_PENDING_REG: () => MAX_PENDING_REG,
|
|
51
55
|
MAX_RECORD_BYTES: () => MAX_RECORD_BYTES,
|
|
56
|
+
MAX_SCAN: () => MAX_SCAN,
|
|
52
57
|
MINT_KEYS: () => MINT_KEYS,
|
|
53
|
-
MIN_FEE_ATTEST: () =>
|
|
54
|
-
MIN_FEE_PROPOSE: () =>
|
|
58
|
+
MIN_FEE_ATTEST: () => import_csd_codec5.MIN_FEE_ATTEST,
|
|
59
|
+
MIN_FEE_PROPOSE: () => import_csd_codec5.MIN_FEE_PROPOSE,
|
|
55
60
|
NAME_FEE_LEN3_V24: () => NAME_FEE_LEN3_V24,
|
|
56
61
|
NAME_FEE_LEN4_V24: () => NAME_FEE_LEN4_V24,
|
|
57
62
|
NAME_FEE_LONG_V24: () => NAME_FEE_LONG_V24,
|
|
@@ -76,6 +81,7 @@ __export(index_exports, {
|
|
|
76
81
|
REG_FINALIZE_GRACE_BLOCKS: () => REG_FINALIZE_GRACE_BLOCKS,
|
|
77
82
|
RESERVED_NAMES: () => RESERVED_NAMES,
|
|
78
83
|
SALT_RE: () => SALT_RE,
|
|
84
|
+
SCAN_MARGIN: () => SCAN_MARGIN,
|
|
79
85
|
SCORE_CANCEL: () => SCORE_CANCEL,
|
|
80
86
|
SCORE_CLAIM: () => SCORE_CLAIM,
|
|
81
87
|
SCORE_FILL: () => SCORE_FILL,
|
|
@@ -99,12 +105,13 @@ __export(index_exports, {
|
|
|
99
105
|
V25_HEIGHT: () => V25_HEIGHT,
|
|
100
106
|
V26_HEIGHT: () => V26_HEIGHT,
|
|
101
107
|
V27_HEIGHT: () => V27_HEIGHT,
|
|
108
|
+
V28_HEIGHT: () => V28_HEIGHT,
|
|
102
109
|
ZERO_ADDR: () => ZERO_ADDR,
|
|
103
110
|
bid: () => bid,
|
|
104
|
-
blockReward: () =>
|
|
111
|
+
blockReward: () => import_csd_codec5.blockReward,
|
|
105
112
|
buildFeeHeight: () => buildFeeHeight,
|
|
106
113
|
buildRecord: () => buildRecord,
|
|
107
|
-
canonicalJson: () =>
|
|
114
|
+
canonicalJson: () => import_csd_codec5.canonicalJson,
|
|
108
115
|
canonicalState: () => canonicalState,
|
|
109
116
|
claimGraceOf: () => claimGraceOf,
|
|
110
117
|
claimWindowAt: () => claimWindowAt,
|
|
@@ -112,7 +119,11 @@ __export(index_exports, {
|
|
|
112
119
|
deploy: () => deploy,
|
|
113
120
|
epochOf: () => epochOf,
|
|
114
121
|
expiredClaimFee: () => expiredClaimFee,
|
|
122
|
+
fclaim: () => fclaim,
|
|
123
|
+
fclaimEpochFor: () => fclaimEpochFor,
|
|
124
|
+
fclaimHoldEnd: () => fclaimHoldEnd,
|
|
115
125
|
fillIsSafe: () => fillIsSafe,
|
|
126
|
+
fillTargetId: () => fillTargetId,
|
|
116
127
|
finalizeWinnerCheck: () => finalizeWinnerCheck,
|
|
117
128
|
hasLiveClaim: () => hasLiveClaim,
|
|
118
129
|
isName: () => isName,
|
|
@@ -136,16 +147,18 @@ __export(index_exports, {
|
|
|
136
147
|
paidToFromOutputs: () => paidToFromOutputs,
|
|
137
148
|
parseAmount: () => parseAmount,
|
|
138
149
|
parseRecord: () => parseRecord,
|
|
139
|
-
payloadHash: () =>
|
|
150
|
+
payloadHash: () => import_csd_codec5.payloadHash,
|
|
140
151
|
pickPrimaryName: () => pickPrimaryName,
|
|
141
152
|
previewFill: () => previewFill,
|
|
142
153
|
primaryRankBefore: () => primaryRankBefore,
|
|
154
|
+
replayLiveHold: () => replayLiveHold,
|
|
143
155
|
requiredClaimDepth: () => requiredClaimDepth,
|
|
144
156
|
requiredFillOutputs: () => requiredFillOutputs,
|
|
145
157
|
resolve: () => resolve,
|
|
146
158
|
tokenMeta: () => tokenMeta,
|
|
147
159
|
tradeFee: () => tradeFee,
|
|
148
|
-
transfer: () => transfer
|
|
160
|
+
transfer: () => transfer,
|
|
161
|
+
verifyFillSpv: () => verifyFillSpv
|
|
149
162
|
});
|
|
150
163
|
module.exports = __toCommonJS(index_exports);
|
|
151
164
|
|
|
@@ -181,6 +194,8 @@ var CLAIM_WINDOW_BLOCKS_V20 = 40;
|
|
|
181
194
|
var CLAIM_FILL_GRACE_BLOCKS = 5;
|
|
182
195
|
var MAX_ACTIVE_CLAIMS = 3;
|
|
183
196
|
var CLAIM_COOLDOWN_BLOCKS = 15;
|
|
197
|
+
var FCLAIM_MAX_EPOCH_AHEAD = 2;
|
|
198
|
+
var FILL_TIP_MARGIN = 2;
|
|
184
199
|
var CONF_TOKEN_FILL = 1e6;
|
|
185
200
|
var TREASURY_ADDR = "0x6b09ce74e6070ebc982ab0fb793a211c4d24f016";
|
|
186
201
|
var FEE_BPS = 100;
|
|
@@ -239,10 +254,13 @@ var MAX_PENDING_REG = 3;
|
|
|
239
254
|
var FINALIZE_TIP_MARGIN = 2;
|
|
240
255
|
var V26_HEIGHT = 46480;
|
|
241
256
|
var V27_HEIGHT = 46520;
|
|
257
|
+
var V28_HEIGHT = 6e4;
|
|
242
258
|
var epochOf = (height) => Math.floor(height / import_csd_codec.EPOCH_LEN);
|
|
243
259
|
var claimWindowAt = (height) => height >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
|
|
244
260
|
var claimWindowOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_WINDOW_BLOCKS_V20 : CLAIM_WINDOW_BLOCKS;
|
|
245
|
-
var claimGraceOf = (claimUntilHeight) => claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
|
|
261
|
+
var claimGraceOf = (claimUntilHeight, claimTxid) => claimTxid !== void 0 ? 0 : claimUntilHeight - CLAIM_WINDOW_BLOCKS_V20 >= V20_HEIGHT ? CLAIM_FILL_GRACE_BLOCKS : 0;
|
|
262
|
+
var fclaimEpochFor = (tipHeight, offerExpiresEpoch) => Math.min(epochOf(tipHeight + CLAIM_WINDOW_BLOCKS_V20 + CLAIM_FILL_GRACE_BLOCKS), offerExpiresEpoch);
|
|
263
|
+
var fclaimHoldEnd = (expiresEpoch) => (expiresEpoch + 1) * import_csd_codec.EPOCH_LEN - 1;
|
|
246
264
|
var offerExpiryHeightOf = (expiresEpoch, anchorHeight) => {
|
|
247
265
|
const raw = (Number(expiresEpoch ?? 0) + 1) * import_csd_codec.EPOCH_LEN;
|
|
248
266
|
if (anchorHeight >= V22_HEIGHT) return raw;
|
|
@@ -303,6 +321,7 @@ var BID_KEYS = /* @__PURE__ */ new Set(["v", "t", "want", "give", "memo", "ts"])
|
|
|
303
321
|
var NAME_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "salt"]);
|
|
304
322
|
var NFINALIZE_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "salt"]);
|
|
305
323
|
var NPROFILE_KEYS = /* @__PURE__ */ new Set(["v", "t", "name", "p"]);
|
|
324
|
+
var FCLAIM_KEYS = /* @__PURE__ */ new Set(["v", "t", "offer"]);
|
|
306
325
|
function parseRecord(uri, payloadHashHex) {
|
|
307
326
|
if (new TextEncoder().encode(uri).length > MAX_RECORD_BYTES) return null;
|
|
308
327
|
let obj;
|
|
@@ -456,6 +475,11 @@ function parseRecord(uri, payloadHashHex) {
|
|
|
456
475
|
if (Object.keys(r).length !== 4) return null;
|
|
457
476
|
return r;
|
|
458
477
|
}
|
|
478
|
+
case "fclaim": {
|
|
479
|
+
if (!onlyKeys(r, FCLAIM_KEYS)) return null;
|
|
480
|
+
if (!isHash(r.offer)) return null;
|
|
481
|
+
return r;
|
|
482
|
+
}
|
|
459
483
|
default:
|
|
460
484
|
return null;
|
|
461
485
|
}
|
|
@@ -481,6 +505,7 @@ var nameSet = (r) => buildRecord({ v: 1, t: "nset", ...r });
|
|
|
481
505
|
var nameRenew = (r) => buildRecord({ v: 1, t: "nrenew", ...r });
|
|
482
506
|
var tokenMeta = (r) => buildRecord({ v: 1, t: "tmeta", ...r });
|
|
483
507
|
var nameProfile = (r) => buildRecord({ v: 1, t: "nprofile", ...r });
|
|
508
|
+
var fclaim = (r) => buildRecord({ v: 1, t: "fclaim", ...r });
|
|
484
509
|
|
|
485
510
|
// src/resolve.ts
|
|
486
511
|
function ptAmt(v) {
|
|
@@ -502,6 +527,7 @@ function resolve(events, tipHeight) {
|
|
|
502
527
|
const offers = /* @__PURE__ */ new Map();
|
|
503
528
|
const offerLock = /* @__PURE__ */ new Map();
|
|
504
529
|
const bids = /* @__PURE__ */ new Map();
|
|
530
|
+
const fclaims = /* @__PURE__ */ new Map();
|
|
505
531
|
const log = [];
|
|
506
532
|
let feesPaid = 0n;
|
|
507
533
|
let pendingCancels = [];
|
|
@@ -565,18 +591,20 @@ function resolve(events, tipHeight) {
|
|
|
565
591
|
const b = bids.get(o.bid);
|
|
566
592
|
if (b && b.status === "open" && b.bidder === buyer) b.status = "done";
|
|
567
593
|
};
|
|
568
|
-
const voidOpenNameOffers = (name) => {
|
|
594
|
+
const voidOpenNameOffers = (name, height) => {
|
|
569
595
|
for (const o of offers.values()) if (o.status === "open" && isNameGive(o.give) && o.give.name === name) {
|
|
596
|
+
if (height >= V28_HEIGHT && o.claimTxid !== void 0 && claimHeld(o, height)) continue;
|
|
570
597
|
releaseGive(o);
|
|
571
598
|
o.status = "cancelled";
|
|
572
599
|
}
|
|
573
600
|
};
|
|
574
601
|
const earlierAnchor = (effHeight, pos, id, inc) => effHeight < inc.effHeight || effHeight === inc.effHeight && (pos < inc.pos || pos === inc.pos && id < inc.id);
|
|
575
|
-
const claimGrace = (o) => o.claimUntilHeight !== void 0 ? claimGraceOf(o.claimUntilHeight) : 0;
|
|
602
|
+
const claimGrace = (o) => o.claimUntilHeight !== void 0 ? claimGraceOf(o.claimUntilHeight, o.claimTxid) : 0;
|
|
576
603
|
const claimHeld = (o, height) => o.claimedBy !== void 0 && o.claimUntilHeight !== void 0 && height < o.claimUntilHeight + claimGrace(o);
|
|
577
|
-
const openFillReject = (o, height, who) => {
|
|
604
|
+
const openFillReject = (o, height, who, targetId) => {
|
|
578
605
|
if (!(height >= V13_HEIGHT && !o.taker)) return void 0;
|
|
579
606
|
if (height < V17_HEIGHT) return "v1.3: open CSD-quoted fills disabled (offer must be taker-bound)";
|
|
607
|
+
if (height >= V28_HEIGHT && o.claimTxid !== void 0 && targetId === o.id) return "v2.8: fill the fclaim txid, not the offer";
|
|
580
608
|
if (!(claimHeld(o, height) && who === o.claimedBy)) return "v1.7: open offer \u2014 claim it first (no live claim by you)";
|
|
581
609
|
return void 0;
|
|
582
610
|
};
|
|
@@ -741,7 +769,7 @@ function resolve(events, tipHeight) {
|
|
|
741
769
|
note(ev, ev.id, "name", false, "lapsed-name claim fee unpaid (decaying premium)");
|
|
742
770
|
continue;
|
|
743
771
|
}
|
|
744
|
-
voidOpenNameOffers(rec.name);
|
|
772
|
+
voidOpenNameOffers(rec.name, ev.height);
|
|
745
773
|
names.set(rec.name, { owner: who, effHeight, pos: ev.pos, id: ev.id, height: ev.height, locked: false, viaFill: true, paidThroughEpoch: epClaim + NAME_TERM_EPOCHS });
|
|
746
774
|
feesPaid += fee;
|
|
747
775
|
note(ev, ev.id, "name", true, "lapsed lease re-claimed (premium)");
|
|
@@ -764,7 +792,7 @@ function resolve(events, tipHeight) {
|
|
|
764
792
|
continue;
|
|
765
793
|
}
|
|
766
794
|
if (curActive) {
|
|
767
|
-
voidOpenNameOffers(rec.name);
|
|
795
|
+
voidOpenNameOffers(rec.name, ev.height);
|
|
768
796
|
}
|
|
769
797
|
names.set(rec.name, { owner: who, effHeight, pos: ev.pos, id: ev.id, height: ev.height, locked: false, pending: true, finalizeBy: effHeight + REG_COMMIT_MAX_BLOCKS + REG_FINALIZE_GRACE_BLOCKS });
|
|
770
798
|
note(ev, ev.id, "name", true, curActive ? "reserved (displaced prior reservation)" : "reserved (pending finalize)");
|
|
@@ -789,7 +817,7 @@ function resolve(events, tipHeight) {
|
|
|
789
817
|
continue;
|
|
790
818
|
}
|
|
791
819
|
if (curActive) {
|
|
792
|
-
voidOpenNameOffers(rec.name);
|
|
820
|
+
voidOpenNameOffers(rec.name, ev.height);
|
|
793
821
|
}
|
|
794
822
|
names.set(rec.name, cand);
|
|
795
823
|
feesPaid += nameRegFee(rec.name, ev.height);
|
|
@@ -852,7 +880,7 @@ function resolve(events, tipHeight) {
|
|
|
852
880
|
note(ev, ev.id, "nfinalize", false, "recapture premium unpaid (decaying)");
|
|
853
881
|
continue;
|
|
854
882
|
}
|
|
855
|
-
voidOpenNameOffers(rec.name);
|
|
883
|
+
voidOpenNameOffers(rec.name, ev.height);
|
|
856
884
|
names.set(rec.name, { owner: who, effHeight: r.effHeight, pos: r.pos, id: r.id, height: r.height, locked: false, paidThroughEpoch: ep + NAME_TERM_EPOCHS });
|
|
857
885
|
recaptures.delete(rec.name);
|
|
858
886
|
feesPaid += fee;
|
|
@@ -1043,6 +1071,7 @@ function resolve(events, tipHeight) {
|
|
|
1043
1071
|
const targets = [];
|
|
1044
1072
|
for (const o of offers.values()) {
|
|
1045
1073
|
if (o.status !== "open" || o.seller !== who) continue;
|
|
1074
|
+
if (o.taker !== void 0 && o.height >= V28_HEIGHT) continue;
|
|
1046
1075
|
if (rec.ticker !== void 0 && !(!isNameGive(o.give) && o.give.ticker === rec.ticker)) continue;
|
|
1047
1076
|
if (rec.name !== void 0 && !(isNameGive(o.give) && o.give.name === rec.name)) continue;
|
|
1048
1077
|
targets.push(o);
|
|
@@ -1050,10 +1079,13 @@ function resolve(events, tipHeight) {
|
|
|
1050
1079
|
if (ev.height >= V14_HEIGHT) {
|
|
1051
1080
|
pendingCancels.push(() => {
|
|
1052
1081
|
let n = 0;
|
|
1053
|
-
for (const o of targets)
|
|
1054
|
-
|
|
1055
|
-
o.status
|
|
1056
|
-
|
|
1082
|
+
for (const o of targets) {
|
|
1083
|
+
if (ev.height >= V28_HEIGHT && o.claimTxid !== void 0 && claimHeld(o, ev.height)) continue;
|
|
1084
|
+
if (o.status === "open") {
|
|
1085
|
+
releaseGive(o);
|
|
1086
|
+
o.status = "cancelled";
|
|
1087
|
+
n++;
|
|
1088
|
+
}
|
|
1057
1089
|
}
|
|
1058
1090
|
note(ev, ev.id, "ocancel", true, `${n} cancelled (deferred past same-block fills)`);
|
|
1059
1091
|
});
|
|
@@ -1106,11 +1138,80 @@ function resolve(events, tipHeight) {
|
|
|
1106
1138
|
}
|
|
1107
1139
|
tok.meta.tmeta = rec.hash;
|
|
1108
1140
|
note(ev, ev.id, "tmeta", true);
|
|
1141
|
+
} else if (rec.t === "fclaim") {
|
|
1142
|
+
if (ev.height < V28_HEIGHT) {
|
|
1143
|
+
note(ev, ev.id, "fclaim", false, "fclaim needs v2.8");
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
1146
|
+
const target = offers.get(rec.offer);
|
|
1147
|
+
const E = ev.expiresEpoch;
|
|
1148
|
+
const deny = (why) => {
|
|
1149
|
+
fclaims.set(ev.id, { offer: rec.offer, proposer: who, expiresEpoch: E, height: ev.height, granted: false });
|
|
1150
|
+
note(ev, ev.id, "fclaim", false, why);
|
|
1151
|
+
};
|
|
1152
|
+
if (!target) {
|
|
1153
|
+
deny("unknown offer");
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
if (target.status !== "open") {
|
|
1157
|
+
deny(`offer ${target.status}`);
|
|
1158
|
+
continue;
|
|
1159
|
+
}
|
|
1160
|
+
if (target.taker) {
|
|
1161
|
+
deny("taker-bound offer needs no claim");
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
if (isTokenWant(target.want)) {
|
|
1165
|
+
deny("claims are for CSD-priced offers");
|
|
1166
|
+
continue;
|
|
1167
|
+
}
|
|
1168
|
+
if (E > effExpiry(target, ev.height)) {
|
|
1169
|
+
deny("hold would outlive the offer expiry");
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1172
|
+
if (E > epochOf(ev.height) + FCLAIM_MAX_EPOCH_AHEAD) {
|
|
1173
|
+
deny("hold too far ahead (anti-squat)");
|
|
1174
|
+
continue;
|
|
1175
|
+
}
|
|
1176
|
+
if (epochOf(ev.height) > E) {
|
|
1177
|
+
deny("expiry already in the past");
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
if (claimHeld(target, ev.height)) {
|
|
1181
|
+
deny("offer already claimed (hold live)");
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
if (target.claimedBy === who && target.claimUntilHeight !== void 0 && ev.height < target.claimUntilHeight + claimGrace(target) + CLAIM_COOLDOWN_BLOCKS) {
|
|
1185
|
+
deny("claim cooldown (you just held this offer)");
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
let liveN = 0;
|
|
1189
|
+
for (const x of offers.values()) if (x.claimedBy === who && claimHeld(x, ev.height)) liveN++;
|
|
1190
|
+
if (liveN >= MAX_ACTIVE_CLAIMS) {
|
|
1191
|
+
deny(`max ${MAX_ACTIVE_CLAIMS} live claims per address`);
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
target.claimedBy = who;
|
|
1195
|
+
target.claimUntilHeight = (E + 1) * import_csd_codec.EPOCH_LEN;
|
|
1196
|
+
target.claimTxid = ev.id;
|
|
1197
|
+
fclaims.set(ev.id, { offer: rec.offer, proposer: who, expiresEpoch: E, height: ev.height, granted: true });
|
|
1198
|
+
note(ev, ev.id, "fclaim", true);
|
|
1109
1199
|
}
|
|
1110
1200
|
} else {
|
|
1111
|
-
const o = offers.get(ev.proposalId);
|
|
1112
1201
|
const who = ev.attester.toLowerCase();
|
|
1202
|
+
let o = offers.get(ev.proposalId);
|
|
1203
|
+
if (!o && ev.height >= V28_HEIGHT && ev.score === SCORE_FILL) {
|
|
1204
|
+
const fc = fclaims.get(ev.proposalId);
|
|
1205
|
+
if (fc && fc.granted) {
|
|
1206
|
+
const linked = offers.get(fc.offer);
|
|
1207
|
+
if (linked && linked.claimTxid === ev.proposalId) o = linked;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1113
1210
|
if (!o) {
|
|
1211
|
+
if (ev.height >= V28_HEIGHT && ev.score === SCORE_FILL && fclaims.has(ev.proposalId)) {
|
|
1212
|
+
note(ev, ev.txid, "fill", false, "fclaim not current (denied or superseded): no delivery, denied-fclaim fill");
|
|
1213
|
+
continue;
|
|
1214
|
+
}
|
|
1114
1215
|
const b = bids.get(ev.proposalId);
|
|
1115
1216
|
if (b && ev.score === SCORE_CANCEL) {
|
|
1116
1217
|
if (who !== b.bidder) {
|
|
@@ -1135,8 +1236,16 @@ function resolve(events, tipHeight) {
|
|
|
1135
1236
|
note(ev, ev.txid, "cancel", false, `offer ${o.status}`);
|
|
1136
1237
|
continue;
|
|
1137
1238
|
}
|
|
1239
|
+
if (o.taker !== void 0 && o.height >= V28_HEIGHT) {
|
|
1240
|
+
note(ev, ev.txid, "cancel", false, "v2.8: taker-bound offers are firm quotes (uncancellable)");
|
|
1241
|
+
continue;
|
|
1242
|
+
}
|
|
1138
1243
|
if (ev.height >= V14_HEIGHT) {
|
|
1139
1244
|
pendingCancels.push(() => {
|
|
1245
|
+
if (ev.height >= V28_HEIGHT && o.claimTxid !== void 0 && claimHeld(o, ev.height)) {
|
|
1246
|
+
note(ev, ev.txid, "cancel", false, "v2.8: frozen (fclaim hold live)");
|
|
1247
|
+
return;
|
|
1248
|
+
}
|
|
1140
1249
|
if (o.status === "open") {
|
|
1141
1250
|
releaseGive(o);
|
|
1142
1251
|
o.status = "cancelled";
|
|
@@ -1200,7 +1309,7 @@ function resolve(events, tipHeight) {
|
|
|
1200
1309
|
note(ev, ev.txid, "fill", false, "taker-bound offer");
|
|
1201
1310
|
continue;
|
|
1202
1311
|
}
|
|
1203
|
-
const blk = openFillReject(o, ev.height, who);
|
|
1312
|
+
const blk = openFillReject(o, ev.height, who, ev.proposalId);
|
|
1204
1313
|
if (blk) {
|
|
1205
1314
|
note(ev, ev.txid, "fill", false, blk);
|
|
1206
1315
|
continue;
|
|
@@ -1260,7 +1369,7 @@ function resolve(events, tipHeight) {
|
|
|
1260
1369
|
note(ev, ev.txid, "fill", false, "taker-bound offer");
|
|
1261
1370
|
continue;
|
|
1262
1371
|
}
|
|
1263
|
-
const blk = openFillReject(o, ev.height, who);
|
|
1372
|
+
const blk = openFillReject(o, ev.height, who, ev.proposalId);
|
|
1264
1373
|
if (blk) {
|
|
1265
1374
|
note(ev, ev.txid, "fill", false, blk);
|
|
1266
1375
|
continue;
|
|
@@ -1306,6 +1415,10 @@ function resolve(events, tipHeight) {
|
|
|
1306
1415
|
markBidDone(o, who);
|
|
1307
1416
|
note(ev, ev.txid, "fill", true);
|
|
1308
1417
|
} else if (ev.height >= V17_HEIGHT && ev.score === SCORE_CLAIM) {
|
|
1418
|
+
if (ev.height >= V28_HEIGHT) {
|
|
1419
|
+
note(ev, ev.txid, "claim", false, "v2.8: claims are fclaim proposals now");
|
|
1420
|
+
continue;
|
|
1421
|
+
}
|
|
1309
1422
|
if (o.status !== "open") {
|
|
1310
1423
|
note(ev, ev.txid, "claim", false, `offer ${o.status}`);
|
|
1311
1424
|
continue;
|
|
@@ -1383,7 +1496,9 @@ function resolve(events, tipHeight) {
|
|
|
1383
1496
|
for (const [id, b] of [...bids.entries()].sort(([a], [b2]) => ord(a, b2))) bidsOut[id] = b;
|
|
1384
1497
|
const recapturesOut = {};
|
|
1385
1498
|
for (const [nm, r] of [...recaptures.entries()].sort(([a], [b]) => ord(a, b))) recapturesOut[nm] = { owner: r.owner, effectiveHeight: r.effHeight, finalizeBy: r.finalizeBy };
|
|
1386
|
-
|
|
1499
|
+
const fclaimsOut = {};
|
|
1500
|
+
for (const [txid, fc] of [...fclaims.entries()].sort(([a], [b]) => ord(a, b))) if (fc.granted) fclaimsOut[txid] = { offer: fc.offer, proposer: fc.proposer, expiresEpoch: fc.expiresEpoch, height: fc.height };
|
|
1501
|
+
return { tipHeight, tokens: tokensOut, balances: balancesOut, names: namesOut, offers: offersOut, bids: bidsOut, recaptures: recapturesOut, fclaims: fclaimsOut, events: log, feesPaid: feesPaid.toString() };
|
|
1387
1502
|
}
|
|
1388
1503
|
function canonicalState(s) {
|
|
1389
1504
|
const sortKeys = (v) => {
|
|
@@ -1393,7 +1508,7 @@ function canonicalState(s) {
|
|
|
1393
1508
|
}
|
|
1394
1509
|
return v;
|
|
1395
1510
|
};
|
|
1396
|
-
const { events: _events, recaptures: _recaptures, ...data } = s;
|
|
1511
|
+
const { events: _events, recaptures: _recaptures, fclaims: _fclaims, ...data } = s;
|
|
1397
1512
|
return JSON.stringify(sortKeys(data));
|
|
1398
1513
|
}
|
|
1399
1514
|
|
|
@@ -1473,9 +1588,13 @@ function hasLiveClaim(offer2, me, tip) {
|
|
|
1473
1588
|
if (tip < V17_HEIGHT) return false;
|
|
1474
1589
|
if (offer2.claimedBy === void 0 || offer2.claimUntilHeight === void 0) return false;
|
|
1475
1590
|
if (offer2.claimedBy.toLowerCase() !== me.toLowerCase()) return false;
|
|
1476
|
-
const grace = claimGraceOf(offer2.claimUntilHeight);
|
|
1591
|
+
const grace = claimGraceOf(offer2.claimUntilHeight, offer2.claimTxid);
|
|
1477
1592
|
return tip < offer2.claimUntilHeight + grace;
|
|
1478
1593
|
}
|
|
1594
|
+
function fillTargetId(offer2, tip) {
|
|
1595
|
+
if (tip >= V28_HEIGHT && offer2.claimTxid !== void 0 && offer2.claimUntilHeight !== void 0 && tip < offer2.claimUntilHeight) return offer2.claimTxid;
|
|
1596
|
+
return offer2.id;
|
|
1597
|
+
}
|
|
1479
1598
|
function fillIsSafe(offer2, me, pay, tip) {
|
|
1480
1599
|
const preview = previewFill(offer2, pay);
|
|
1481
1600
|
if (offer2.status !== "open") return { safe: false, reason: `offer is ${offer2.status}`, preview };
|
|
@@ -1523,6 +1642,100 @@ function pickPrimaryName(names, a) {
|
|
|
1523
1642
|
return best ? best.name : null;
|
|
1524
1643
|
}
|
|
1525
1644
|
|
|
1645
|
+
// src/verifyfill.ts
|
|
1646
|
+
var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
1647
|
+
var GAP_NEEDED = import_csd_codec.EPOCH_LEN * (FCLAIM_MAX_EPOCH_AHEAD + 1) - 1 + CLAIM_COOLDOWN_BLOCKS;
|
|
1648
|
+
var SCAN_MARGIN = import_csd_codec.EPOCH_LEN;
|
|
1649
|
+
var MAX_SCAN = GAP_NEEDED + SCAN_MARGIN;
|
|
1650
|
+
function bindRecord(ev) {
|
|
1651
|
+
const rec = parseRecord(ev.uri, ev.payloadHash);
|
|
1652
|
+
if (!rec) return null;
|
|
1653
|
+
if ((0, import_csd_codec4.payloadHash)(rec).toLowerCase() !== String(ev.payloadHash).toLowerCase()) return null;
|
|
1654
|
+
return rec;
|
|
1655
|
+
}
|
|
1656
|
+
function replayLiveHold(proven, offerId, fclaimTxid, me, evalHeight) {
|
|
1657
|
+
const events = proven.map(({ depth: _depth, ...e }) => e);
|
|
1658
|
+
const state = resolve(events, evalHeight);
|
|
1659
|
+
const offer2 = state.offers[offerId.toLowerCase()] ?? state.offers[offerId];
|
|
1660
|
+
const granted = state.fclaims[fclaimTxid.toLowerCase()] !== void 0 || state.fclaims[fclaimTxid] !== void 0;
|
|
1661
|
+
const routed = !!offer2 && offer2.claimTxid !== void 0 && offer2.claimTxid.toLowerCase() === fclaimTxid.toLowerCase();
|
|
1662
|
+
const heldByMe = !!offer2 && offer2.status === "open" && hasLiveClaim(offer2, me, evalHeight);
|
|
1663
|
+
return { state, offer: offer2, granted, routed, heldByMe };
|
|
1664
|
+
}
|
|
1665
|
+
async function verifyFillSpv(offerId, fclaimTxid, me, io, opts) {
|
|
1666
|
+
const no = (reason) => ({ safe: false, reason });
|
|
1667
|
+
let tip;
|
|
1668
|
+
try {
|
|
1669
|
+
tip = Number(await io.tip());
|
|
1670
|
+
} catch {
|
|
1671
|
+
return no("could not read a PoW-verified tip");
|
|
1672
|
+
}
|
|
1673
|
+
if (!Number.isFinite(tip)) return no("no PoW-verified tip");
|
|
1674
|
+
const depthOf = (ev) => Math.min(Number(ev.depth), tip - Number(ev.height) + 1);
|
|
1675
|
+
let hintIds;
|
|
1676
|
+
try {
|
|
1677
|
+
hintIds = await io.offerEventIds(offerId, fclaimTxid);
|
|
1678
|
+
} catch {
|
|
1679
|
+
return no("could not enumerate the offer's events");
|
|
1680
|
+
}
|
|
1681
|
+
const want = /* @__PURE__ */ new Set([offerId.toLowerCase(), fclaimTxid.toLowerCase(), ...(hintIds ?? []).map((x) => String(x).toLowerCase())]);
|
|
1682
|
+
const proven = [];
|
|
1683
|
+
for (const wid of want) {
|
|
1684
|
+
let ev;
|
|
1685
|
+
try {
|
|
1686
|
+
ev = await io.provenEvent(wid);
|
|
1687
|
+
} catch {
|
|
1688
|
+
ev = null;
|
|
1689
|
+
}
|
|
1690
|
+
if (ev && (ev.kind === "propose" ? ev.id : ev.txid).toLowerCase() === wid) proven.push(ev);
|
|
1691
|
+
}
|
|
1692
|
+
const isProp = (e) => e.kind === "propose";
|
|
1693
|
+
const offerEv = proven.find((e) => isProp(e) && e.id.toLowerCase() === offerId.toLowerCase());
|
|
1694
|
+
const fclaimEv = proven.find((e) => isProp(e) && e.id.toLowerCase() === fclaimTxid.toLowerCase());
|
|
1695
|
+
if (!offerEv) return no("offer not merkle-proven (no PoW-verified offer Propose)");
|
|
1696
|
+
if (!fclaimEv) return no("fclaim not merkle-proven (no PoW-verified fclaim Propose)");
|
|
1697
|
+
if (fclaimEv.height < V28_HEIGHT) return no("fclaim mined below the V28 gate (no fclaim lane there)");
|
|
1698
|
+
const offerRec = bindRecord(offerEv);
|
|
1699
|
+
const fclaimRec = bindRecord(fclaimEv);
|
|
1700
|
+
if (!offerRec || offerRec.t !== "offer") return no("offer record does not bind to its on-chain commitment");
|
|
1701
|
+
if (!fclaimRec || fclaimRec.t !== "fclaim") return no("fclaim record does not bind to its on-chain commitment");
|
|
1702
|
+
if (fclaimRec.offer.toLowerCase() !== offerId.toLowerCase()) return no("fclaim does not reference this offer");
|
|
1703
|
+
if (isTokenWant(offerRec.want)) return no("the fclaim lane is CSD-priced offers only");
|
|
1704
|
+
const wantValue = BigInt(offerRec.want.value);
|
|
1705
|
+
const E = Number(fclaimEv.expiresEpoch);
|
|
1706
|
+
const need = requiredClaimDepth(wantValue, offerEv.height).depth;
|
|
1707
|
+
if (!(depthOf(offerEv) >= need)) return no(`offer not buried deep enough yet (${depthOf(offerEv)} < ${need}) - wait`);
|
|
1708
|
+
if (!(depthOf(fclaimEv) >= need)) return no(`fclaim not buried deep enough yet (${depthOf(fclaimEv)} < ${need}) - wait`);
|
|
1709
|
+
const laneIds = /* @__PURE__ */ new Set([offerId.toLowerCase()]);
|
|
1710
|
+
for (const e of proven) {
|
|
1711
|
+
if (!isProp(e)) continue;
|
|
1712
|
+
const r2 = e.id.toLowerCase() === fclaimTxid.toLowerCase() ? fclaimRec : bindRecord(e);
|
|
1713
|
+
if (r2 && r2.t === "fclaim" && r2.offer.toLowerCase() === offerId.toLowerCase()) laneIds.add(e.id.toLowerCase());
|
|
1714
|
+
}
|
|
1715
|
+
for (const e of proven) {
|
|
1716
|
+
if (e.kind === "attest" && e.score === SCORE_FILL && laneIds.has(e.proposalId.toLowerCase()) && !(depthOf(e) >= need))
|
|
1717
|
+
return no(`an earlier fill-basis event is not buried deep enough yet (${depthOf(e)} < ${need}) - wait`);
|
|
1718
|
+
}
|
|
1719
|
+
const r = replayLiveHold(proven, offerId, fclaimTxid, me, tip);
|
|
1720
|
+
if (!r.offer) return no("the offer does not resolve from the proven events (unknown/rejected offer)");
|
|
1721
|
+
if (!Number.isInteger(opts.myLiveHoldsAtGrant) || opts.myLiveHoldsAtGrant < 0)
|
|
1722
|
+
return no("the caller must assert myLiveHoldsAtGrant (the buyer's concurrent other-offer live-hold count) for the cap check");
|
|
1723
|
+
if (opts.myLiveHoldsAtGrant >= MAX_ACTIVE_CLAIMS) return no("you held the max active claims when this fclaim was granted - the resolver denied it on the cap, refusing (the payment would burn)");
|
|
1724
|
+
if (!(r.routed && r.granted)) return no("this fclaim is not the live granted hold (denied or superseded) - refusing, the payment would burn");
|
|
1725
|
+
if (!r.heldByMe) return no("no live claim by you on an open offer (cancelled, lapsed, or not your hold) - refusing");
|
|
1726
|
+
let pay;
|
|
1727
|
+
try {
|
|
1728
|
+
pay = opts.pay !== void 0 ? BigInt(opts.pay) : wantValue;
|
|
1729
|
+
} catch {
|
|
1730
|
+
return no("invalid pay amount");
|
|
1731
|
+
}
|
|
1732
|
+
const dp = previewFill({ ...r.offer, status: "open" }, pay);
|
|
1733
|
+
if (!dp.deliverable || dp.got < 1n) return no("this fill would deliver 0 units - refusing (the CSD would be lost)");
|
|
1734
|
+
const holdEnd = fclaimHoldEnd(E);
|
|
1735
|
+
if (holdEnd < tip + FILL_TIP_MARGIN) return no(`too close to the hold deadline (holdEnd ${holdEnd}, tip ${tip}) - would strand`);
|
|
1736
|
+
return { safe: true, reason: "ok" };
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1526
1739
|
// src/paidto.ts
|
|
1527
1740
|
function paidToFromOutputs(outputs) {
|
|
1528
1741
|
const m = /* @__PURE__ */ Object.create(null);
|
|
@@ -1534,7 +1747,7 @@ function paidToFromOutputs(outputs) {
|
|
|
1534
1747
|
}
|
|
1535
1748
|
|
|
1536
1749
|
// src/index.ts
|
|
1537
|
-
var
|
|
1750
|
+
var import_csd_codec5 = require("@inversealtruism/csd-codec");
|
|
1538
1751
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1539
1752
|
0 && (module.exports = {
|
|
1540
1753
|
ACTIVATION_HEIGHT,
|
|
@@ -1554,10 +1767,14 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1554
1767
|
DEPLOY_KEYS,
|
|
1555
1768
|
DOMAIN,
|
|
1556
1769
|
EPOCH_LEN,
|
|
1770
|
+
FCLAIM_KEYS,
|
|
1771
|
+
FCLAIM_MAX_EPOCH_AHEAD,
|
|
1557
1772
|
FEE_BPS,
|
|
1558
1773
|
FEE_BPS_V16,
|
|
1559
1774
|
FEE_GATE_MARGIN_BLOCKS,
|
|
1775
|
+
FILL_TIP_MARGIN,
|
|
1560
1776
|
FINALIZE_TIP_MARGIN,
|
|
1777
|
+
GAP_NEEDED,
|
|
1561
1778
|
HALVING_INTERVAL,
|
|
1562
1779
|
HASH_RE,
|
|
1563
1780
|
INITIAL_REWARD,
|
|
@@ -1566,6 +1783,7 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1566
1783
|
MAX_OFFER_EPOCHS,
|
|
1567
1784
|
MAX_PENDING_REG,
|
|
1568
1785
|
MAX_RECORD_BYTES,
|
|
1786
|
+
MAX_SCAN,
|
|
1569
1787
|
MINT_KEYS,
|
|
1570
1788
|
MIN_FEE_ATTEST,
|
|
1571
1789
|
MIN_FEE_PROPOSE,
|
|
@@ -1593,6 +1811,7 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1593
1811
|
REG_FINALIZE_GRACE_BLOCKS,
|
|
1594
1812
|
RESERVED_NAMES,
|
|
1595
1813
|
SALT_RE,
|
|
1814
|
+
SCAN_MARGIN,
|
|
1596
1815
|
SCORE_CANCEL,
|
|
1597
1816
|
SCORE_CLAIM,
|
|
1598
1817
|
SCORE_FILL,
|
|
@@ -1616,6 +1835,7 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1616
1835
|
V25_HEIGHT,
|
|
1617
1836
|
V26_HEIGHT,
|
|
1618
1837
|
V27_HEIGHT,
|
|
1838
|
+
V28_HEIGHT,
|
|
1619
1839
|
ZERO_ADDR,
|
|
1620
1840
|
bid,
|
|
1621
1841
|
blockReward,
|
|
@@ -1629,7 +1849,11 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1629
1849
|
deploy,
|
|
1630
1850
|
epochOf,
|
|
1631
1851
|
expiredClaimFee,
|
|
1852
|
+
fclaim,
|
|
1853
|
+
fclaimEpochFor,
|
|
1854
|
+
fclaimHoldEnd,
|
|
1632
1855
|
fillIsSafe,
|
|
1856
|
+
fillTargetId,
|
|
1633
1857
|
finalizeWinnerCheck,
|
|
1634
1858
|
hasLiveClaim,
|
|
1635
1859
|
isName,
|
|
@@ -1657,10 +1881,12 @@ var import_csd_codec4 = require("@inversealtruism/csd-codec");
|
|
|
1657
1881
|
pickPrimaryName,
|
|
1658
1882
|
previewFill,
|
|
1659
1883
|
primaryRankBefore,
|
|
1884
|
+
replayLiveHold,
|
|
1660
1885
|
requiredClaimDepth,
|
|
1661
1886
|
requiredFillOutputs,
|
|
1662
1887
|
resolve,
|
|
1663
1888
|
tokenMeta,
|
|
1664
1889
|
tradeFee,
|
|
1665
|
-
transfer
|
|
1890
|
+
transfer,
|
|
1891
|
+
verifyFillSpv
|
|
1666
1892
|
});
|