@esseyonsui/sui-sdk-v3 0.1.9 → 0.2.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/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +1 -0
- package/dist/essey.d.ts +177 -55
- package/dist/essey.d.ts.map +1 -1
- package/dist/essey.js +549 -233
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/network.d.ts +8 -0
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +23 -0
- package/dist/v3/collateral/math.d.ts +6 -0
- package/dist/v3/collateral/math.d.ts.map +1 -1
- package/dist/v3/collateral/math.js +12 -0
- package/dist/v3/credential/membership.d.ts +2 -0
- package/dist/v3/credential/membership.d.ts.map +1 -1
- package/dist/v3/credential/membership.js +4 -0
- package/dist/v3/fees.d.ts +6 -0
- package/dist/v3/fees.d.ts.map +1 -1
- package/dist/v3/loans/offer-plan.d.ts +1 -1
- package/dist/v3/loans/offer-plan.d.ts.map +1 -1
- package/dist/v3/loans/offer-plan.js +5 -4
- package/dist/v3/loans/open-plan.d.ts +7 -3
- package/dist/v3/loans/open-plan.d.ts.map +1 -1
- package/dist/v3/loans/open-plan.js +11 -3
- package/dist/v3/notes/derive.d.ts +7 -0
- package/dist/v3/notes/derive.d.ts.map +1 -1
- package/dist/v3/notes/derive.js +10 -0
- package/dist/v3/notes/opening.d.ts +22 -1
- package/dist/v3/notes/opening.d.ts.map +1 -1
- package/dist/v3/notes/opening.js +55 -22
- package/dist/v3/notes/scan.d.ts +20 -3
- package/dist/v3/notes/scan.d.ts.map +1 -1
- package/dist/v3/notes/scan.js +59 -16
- package/dist/v3/notes/withdraw.d.ts +2 -0
- package/dist/v3/notes/withdraw.d.ts.map +1 -1
- package/dist/v3/notes/withdraw.js +9 -0
- package/dist/v3/pace.d.ts +1 -1
- package/dist/v3/pace.js +1 -1
- package/dist/v3/stage1.d.ts +5 -2
- package/dist/v3/stage1.d.ts.map +1 -1
- package/dist/v3/stage1.js +17 -6
- package/dist/v3/time-grid.d.ts +22 -2
- package/dist/v3/time-grid.d.ts.map +1 -1
- package/dist/v3/time-grid.js +44 -8
- package/package.json +1 -1
package/dist/v3/notes/scan.js
CHANGED
|
@@ -2,7 +2,7 @@ import { EsseyError } from "../../errors.js";
|
|
|
2
2
|
import { R } from "../domains.js";
|
|
3
3
|
import { noteCommitment, noteNullifier, notePk } from "./keys.js";
|
|
4
4
|
import { deriveNoteKey } from "./derive.js";
|
|
5
|
-
import {
|
|
5
|
+
import { openAny, receiveTag } from "./opening.js";
|
|
6
6
|
/** The leaves in index order. A gap means the reader missed an event, and every path would be wrong. */
|
|
7
7
|
export function orderedLeaves(events) {
|
|
8
8
|
const leaves = [...events.commitments].sort((a, b) => (a.index < b.index ? -1 : 1));
|
|
@@ -12,18 +12,46 @@ export function orderedLeaves(events) {
|
|
|
12
12
|
});
|
|
13
13
|
return leaves.map((c) => c.commitment);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/** SCOPE-PRV34 D3: how far past the highest index known a `v3note2:` payment is looked for. */
|
|
16
|
+
export const RECEIVE_WINDOW = 256;
|
|
17
|
+
function rebuilt(c, seed, o, index) {
|
|
18
|
+
const { sk } = deriveNoteKey(seed, index);
|
|
19
|
+
if (noteCommitment(o.value, notePk(sk), o.blinding) !== c.commitment)
|
|
18
20
|
return null;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
return { value: o.value, blinding: o.blinding, index, sk };
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* One ECDH per commitment (`openAny`). A tagged opening maps to its index through a table over [0, next + W); the
|
|
25
|
+
* table grows until no opening sits within W of its end (gap limit), so a lost state still finds every payment.
|
|
26
|
+
*/
|
|
27
|
+
function openAll(events, seed, encKey, next) {
|
|
28
|
+
const sealed = events.commitments.flatMap((c) => {
|
|
29
|
+
const o = openAny(c.enc, encKey);
|
|
30
|
+
return o ? [{ c, o }] : [];
|
|
31
|
+
});
|
|
32
|
+
const tags = new Map();
|
|
33
|
+
const tagged = sealed.some(({ o }) => "tag" in o);
|
|
34
|
+
for (let upTo = next + RECEIVE_WINDOW;;) {
|
|
35
|
+
if (tagged)
|
|
36
|
+
for (let i = tags.size; i < upTo; i++)
|
|
37
|
+
tags.set(receiveTag(notePk(deriveNoteKey(seed, i).sk)), i);
|
|
38
|
+
const found = new Map();
|
|
39
|
+
for (const { c, o } of sealed) {
|
|
40
|
+
const index = "index" in o ? o.index : tags.get(o.tag);
|
|
41
|
+
const opened = index === undefined ? null : rebuilt(c, seed, o, index);
|
|
42
|
+
if (opened)
|
|
43
|
+
found.set(c, opened);
|
|
44
|
+
}
|
|
45
|
+
const top = Math.max(next, ...[...found.values()].map((o) => o.index + 1));
|
|
46
|
+
if (!tagged || top + RECEIVE_WINDOW <= upTo)
|
|
47
|
+
return found;
|
|
48
|
+
upTo = top + RECEIVE_WINDOW;
|
|
49
|
+
}
|
|
23
50
|
}
|
|
24
51
|
/** The key index of every commitment this seed made, spent or not, including a zero-value change. */
|
|
25
|
-
export function usedIndices(events, seed, encKey) {
|
|
26
|
-
|
|
52
|
+
export function usedIndices(events, seed, encKey, next = 0) {
|
|
53
|
+
const found = openAll(events, seed, encKey, next);
|
|
54
|
+
return events.commitments.flatMap((c) => found.get(c)?.index ?? []);
|
|
27
55
|
}
|
|
28
56
|
/** A nullifier as a field, whether the reader sent a bigint, a decimal, `0x` hex, or 1..32 big-endian bytes. */
|
|
29
57
|
export function asNullifier(value) {
|
|
@@ -43,17 +71,32 @@ export function asNullifier(value) {
|
|
|
43
71
|
return null;
|
|
44
72
|
return n;
|
|
45
73
|
}
|
|
46
|
-
|
|
47
|
-
export function ownOpenings(events, seed, encKey) {
|
|
48
|
-
orderedLeaves(events);
|
|
74
|
+
function spentSet(events) {
|
|
49
75
|
const spent = new Set();
|
|
50
76
|
for (const raw of events.nullifiers) {
|
|
51
77
|
const n = asNullifier(raw);
|
|
52
78
|
if (n !== null)
|
|
53
79
|
spent.add(n);
|
|
54
80
|
}
|
|
81
|
+
return spent;
|
|
82
|
+
}
|
|
83
|
+
/** "absent" also covers a leaf at `index` that is not this note: only the events' own leaf counts. */
|
|
84
|
+
export function heldStatus(events, seed, held) {
|
|
85
|
+
const { sk } = deriveNoteKey(seed, held.key);
|
|
86
|
+
const commitment = noteCommitment(held.value, notePk(sk), held.blinding);
|
|
87
|
+
const leaf = events.commitments.find((c) => c.index === BigInt(held.index));
|
|
88
|
+
if (leaf === undefined || BigInt(leaf.commitment) !== commitment)
|
|
89
|
+
return { status: "absent", sk };
|
|
90
|
+
const spent = spentSet(events).has(noteNullifier(commitment, sk, leaf.index));
|
|
91
|
+
return { status: spent ? "spent" : "live", sk };
|
|
92
|
+
}
|
|
93
|
+
/** Trial-opens every ciphertext and keeps the ones whose commitment rebuilds under this seed's key. */
|
|
94
|
+
export function ownOpenings(events, seed, encKey, next = 0) {
|
|
95
|
+
orderedLeaves(events);
|
|
96
|
+
const spent = spentSet(events);
|
|
97
|
+
const found = openAll(events, seed, encKey, next);
|
|
55
98
|
return events.commitments.flatMap((c) => {
|
|
56
|
-
const opened =
|
|
99
|
+
const opened = found.get(c);
|
|
57
100
|
if (!opened)
|
|
58
101
|
return [];
|
|
59
102
|
return {
|
|
@@ -67,8 +110,8 @@ export function ownOpenings(events, seed, encKey) {
|
|
|
67
110
|
});
|
|
68
111
|
}
|
|
69
112
|
/** `ownOpenings` without the spent and the empty. */
|
|
70
|
-
export function ownNotes(events, seed, encKey) {
|
|
71
|
-
return ownOpenings(events, seed, encKey)
|
|
113
|
+
export function ownNotes(events, seed, encKey, next = 0) {
|
|
114
|
+
return ownOpenings(events, seed, encKey, next)
|
|
72
115
|
.filter((n) => !n.spent && n.value !== 0n)
|
|
73
116
|
.map(({ value, sk, blinding, index }) => ({ value, sk, blinding, index }));
|
|
74
117
|
}
|
|
@@ -22,6 +22,8 @@ export declare function withdrawPieces(amount: bigint, list: string[]): bigint[]
|
|
|
22
22
|
/** Each piece pays its own fees, so fewer, larger pieces can fit where a larger sum of smaller ones does not. */
|
|
23
23
|
export declare function exitPieces(total: bigint, list: string[], rates: FeeRates, relayerFee: bigint): bigint[];
|
|
24
24
|
export declare const exitKept: (total: bigint, pieces: bigint[], rates: FeeRates, relayerFee: bigint) => bigint;
|
|
25
|
+
/** PRV-11: how the state file remembers a paid address, a keyed hash under the note seed, so it names no payee. */
|
|
26
|
+
export declare function paidTag(seed: Uint8Array, to: string): string;
|
|
25
27
|
export declare function piecePayees(pieces: number, to: string[]): string[];
|
|
26
28
|
/** Each piece is its own js4 of at most two notes into one change note (`pickInputs`), so all are planned first. */
|
|
27
29
|
export declare function refuseUncovered(owned: OwnNote[], pieces: bigint[], rates: FeeRates, relayerFee: bigint): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withdraw.d.ts","sourceRoot":"","sources":["../../../src/v3/notes/withdraw.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"withdraw.d.ts","sourceRoot":"","sources":["../../../src/v3/notes/withdraw.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,MAAM,QAAQ,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,eAAO,MAAM,YAAY,GAAI,IAAI,MAAM,EAAE,OAAO,QAAQ,EAAE,YAAY,MAAM,WACvB,CAAC;AAgBtD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG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AAU,EAAE,MAAM,GACjB,IAAI,CAQN"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { hkdf } from "@noble/hashes/hkdf.js";
|
|
2
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
3
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
1
4
|
import { EsseyError } from "../../errors.js";
|
|
2
5
|
import { feeOf } from "../fees.js";
|
|
3
6
|
import { denominationFloor, MAX_SPLIT_PIECES, pieceCount, splitDenominations } from "./denominations.js";
|
|
@@ -93,6 +96,12 @@ export function exitPieces(total, list, rates, relayerFee) {
|
|
|
93
96
|
return refuse("refused: the notes do not cover the smallest denomination and its fees; pass force: true to exit them exactly");
|
|
94
97
|
}
|
|
95
98
|
export const exitKept = (total, pieces, rates, relayerFee) => total - costOf(pieces, rates, relayerFee);
|
|
99
|
+
const utf8 = (s) => new TextEncoder().encode(s);
|
|
100
|
+
/** PRV-11: how the state file remembers a paid address, a keyed hash under the note seed, so it names no payee. */
|
|
101
|
+
export function paidTag(seed, to) {
|
|
102
|
+
const key = hkdf(sha256, seed, undefined, utf8("essey-v3 paid payees v1"), 32);
|
|
103
|
+
return Buffer.from(hmac(sha256, key, utf8(to))).toString("hex");
|
|
104
|
+
}
|
|
96
105
|
export function piecePayees(pieces, to) {
|
|
97
106
|
if (new Set(to).size !== to.length)
|
|
98
107
|
refuse("refused: to lists an address twice; each piece goes to a different address; nothing was sent");
|
package/dist/v3/pace.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const PACED: {
|
|
|
18
18
|
readonly topup: "short";
|
|
19
19
|
readonly liquidate: "short";
|
|
20
20
|
readonly fault: "short";
|
|
21
|
-
readonly withdraw_piece: "
|
|
21
|
+
readonly withdraw_piece: "long";
|
|
22
22
|
};
|
|
23
23
|
export type PacedAction = keyof typeof PACED;
|
|
24
24
|
export declare const PACE_RANGES_MS: Record<PaceClass, readonly [number, number]>;
|
package/dist/v3/pace.js
CHANGED
package/dist/v3/stage1.d.ts
CHANGED
|
@@ -108,7 +108,8 @@ export type SaleOpenParams = {
|
|
|
108
108
|
coin: CoinKey;
|
|
109
109
|
minPrice: bigint;
|
|
110
110
|
maxPrice: bigint;
|
|
111
|
-
|
|
111
|
+
/** How long bids are taken, on the deployment's bid-window set (`v3/time-grid.ts` assertSaleGrid). */
|
|
112
|
+
bidWindowMs: number;
|
|
112
113
|
finishWindowMs: number;
|
|
113
114
|
maxBids: number;
|
|
114
115
|
/** Absent: the relayer pays when one with an address is set up, else `submitSaleOpen` does. */
|
|
@@ -192,7 +193,9 @@ export declare function assertSaleOpen(p: SaleOpenParams): SaleOpenParams;
|
|
|
192
193
|
* The room the sponsor named is this open: same coin pool, close, finish window and max bids
|
|
193
194
|
* (`sale_room.move:181-193`).
|
|
194
195
|
*/
|
|
195
|
-
export declare function assertRoomMatches(config: V3Config, open: SaleOpenParams,
|
|
196
|
+
export declare function assertRoomMatches(config: V3Config, open: Pick<SaleOpenParams, "coin" | "finishWindowMs" | "maxBids"> & {
|
|
197
|
+
closeMs: number;
|
|
198
|
+
}, row: {
|
|
196
199
|
id: string;
|
|
197
200
|
json: unknown;
|
|
198
201
|
}): void;
|
package/dist/v3/stage1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage1.d.ts","sourceRoot":"","sources":["../../src/v3/stage1.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGlE,OAAO,EAAE,SAAS,EAAW,cAAc,EAAiB,MAAM,sBAAsB,CAAC;AAEzF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AAErC,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;A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AAE,EACvF,GAAG,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GACjC,IAAI,CAUN;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG,gBAAgB,CA6BvE"}
|
package/dist/v3/stage1.js
CHANGED
|
@@ -10,7 +10,7 @@ import { DOM_BOUNDS, R } from "./domains.js";
|
|
|
10
10
|
import { deriveNoteKey, noteEncKey } from "./notes/derive.js";
|
|
11
11
|
import { noteCommitment, noteNullifier, notePk } from "./notes/keys.js";
|
|
12
12
|
import { openOpening } from "./notes/opening.js";
|
|
13
|
-
import { asNullifier, ownNotes } from "./notes/scan.js";
|
|
13
|
+
import { asNullifier, ownNotes, ownOpenings } from "./notes/scan.js";
|
|
14
14
|
/**
|
|
15
15
|
* D-SPEC §6.2:589. `lifecycle` is the loan's state (`loan.move:26-34`).
|
|
16
16
|
* `opened` is `request` while that state still keeps the bid in `req_commit`
|
|
@@ -190,7 +190,9 @@ function opened(coin, index, events, seed) {
|
|
|
190
190
|
if (!leaf)
|
|
191
191
|
unknown("no note at this index");
|
|
192
192
|
const openedNote = openOpening(leaf.enc, noteEncKey(seed).encKey);
|
|
193
|
-
if (!openedNote
|
|
193
|
+
if (!openedNote)
|
|
194
|
+
return received(coin, leaf, events, seed);
|
|
195
|
+
if (openedNote.index !== index)
|
|
194
196
|
unknown("the note does not open under this seed");
|
|
195
197
|
const { sk } = deriveNoteKey(seed, openedNote.index);
|
|
196
198
|
if (noteCommitment(openedNote.value, notePk(sk), openedNote.blinding) !== leaf.commitment)
|
|
@@ -201,6 +203,15 @@ function opened(coin, index, events, seed) {
|
|
|
201
203
|
unknown("the note is spent or empty");
|
|
202
204
|
return { coin, index, value: openedNote.value, commitment: leaf.commitment };
|
|
203
205
|
}
|
|
206
|
+
/** PRV-34: a `v3note2:` payment names no counter, so its index comes from the scan's tag table. */
|
|
207
|
+
function received(coin, leaf, events, seed) {
|
|
208
|
+
const own = ownOpenings(events, seed, noteEncKey(seed).encKey).find((o) => BigInt(o.index) === leaf.index);
|
|
209
|
+
if (!own)
|
|
210
|
+
unknown("the note does not open under this seed");
|
|
211
|
+
if (own.value === 0n || own.spent)
|
|
212
|
+
unknown("the note is spent or empty");
|
|
213
|
+
return { coin, index: own.index, value: own.value, commitment: leaf.commitment };
|
|
214
|
+
}
|
|
204
215
|
/** D-SPEC §6.2:582. Opens one ciphertext. A commitment that does not rebuild is tampered. */
|
|
205
216
|
export function openPosition(coin, index, events, seed) {
|
|
206
217
|
const view = opened(coin, index, events, seed);
|
|
@@ -510,11 +521,11 @@ export function assertSaleOpen(p) {
|
|
|
510
521
|
throw new EsseyError("INVALID_ARGUMENT", "itemType is not a Move type");
|
|
511
522
|
if (open.minPrice <= 0n || open.minPrice > open.maxPrice)
|
|
512
523
|
throw new EsseyError("INVALID_ARGUMENT", "price bounds are empty");
|
|
513
|
-
if (!Number.isInteger(open.
|
|
514
|
-
open.
|
|
524
|
+
if (!Number.isInteger(open.bidWindowMs) ||
|
|
525
|
+
open.bidWindowMs <= 0 ||
|
|
515
526
|
!Number.isInteger(open.finishWindowMs) ||
|
|
516
527
|
open.finishWindowMs <= 0)
|
|
517
|
-
throw new EsseyError("INVALID_ARGUMENT", "the
|
|
528
|
+
throw new EsseyError("INVALID_ARGUMENT", "the bid and finish windows must be above 0");
|
|
518
529
|
if (!Number.isInteger(open.maxBids) || open.maxBids < 1 || open.maxBids > MAX_BIDS)
|
|
519
530
|
throw new EsseyError("INVALID_ARGUMENT", "maxBids is not 1..16");
|
|
520
531
|
return open;
|
|
@@ -529,7 +540,7 @@ function snapshotSale(p) {
|
|
|
529
540
|
coin,
|
|
530
541
|
minPrice: ownBigint(o, "minPrice"),
|
|
531
542
|
maxPrice: ownBigint(o, "maxPrice"),
|
|
532
|
-
|
|
543
|
+
bidWindowMs: ownInt(o, "bidWindowMs"),
|
|
533
544
|
finishWindowMs: ownInt(o, "finishWindowMs"),
|
|
534
545
|
maxBids: ownInt(o, "maxBids"),
|
|
535
546
|
sponsored: ownFlag(o, "sponsored"),
|
package/dist/v3/time-grid.d.ts
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export declare
|
|
1
|
+
/** PRV-27: offer windows and terms, in the deployment's close steps (an hour by default). */
|
|
2
|
+
export declare const OFFER_WINDOW_STEPS: readonly [1, 6, 24, 72];
|
|
3
|
+
export declare const TERM_STEPS: readonly [1, 24, 168, 720, 2160];
|
|
4
|
+
/** FOLLOWUPS #10: sale bid and finish windows, in close steps. 6 steps is 30 min at testnet's 5-minute step, `sale_room.move:67`'s floor. */
|
|
5
|
+
export declare const BID_WINDOW_STEPS: readonly [1, 6, 24, 72];
|
|
6
|
+
export declare const FINISH_WINDOW_STEPS: readonly [6, 24, 72];
|
|
7
|
+
/** `now_s` for a default claim: down to the settle step, inside `liquidation.move:400`'s 120 s window. */
|
|
8
|
+
export declare function defaultNowS(nowMs: number): bigint;
|
|
3
9
|
/** `now_s` for a settle: down to the step, never before the round's close (`move/v3/loan/sources/settle.move:129-135`). */
|
|
4
10
|
export declare function settleNowS(nowMs: number, closeMs: bigint): bigint;
|
|
11
|
+
/** Refuses a window or term off this deployment's public sets, so neither tells one member's loan from another. */
|
|
12
|
+
export declare function assertLoanGrid(p: {
|
|
13
|
+
termMs: number;
|
|
14
|
+
offerWindowMs: number;
|
|
15
|
+
}, stepMs: number): void;
|
|
16
|
+
/** FOLLOWUPS #11: a lender offers only on a request whose public close is on this deployment's step. */
|
|
17
|
+
export declare function assertRequestClose(closeMs: bigint, stepMs: number): void;
|
|
18
|
+
/** FOLLOWUPS #11: and whose sealed term, once opened, is on the term set. */
|
|
19
|
+
export declare function assertRequestTerm(termMs: bigint, stepMs: number): void;
|
|
20
|
+
/** A sale's bid and finish windows off this deployment's sets would tell one seller's room from another. */
|
|
21
|
+
export declare function assertSaleGrid(p: {
|
|
22
|
+
bidWindowMs: number;
|
|
23
|
+
finishWindowMs: number;
|
|
24
|
+
}, stepMs: number): void;
|
|
5
25
|
//# sourceMappingURL=time-grid.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-grid.d.ts","sourceRoot":"","sources":["../../src/v3/time-grid.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"time-grid.d.ts","sourceRoot":"","sources":["../../src/v3/time-grid.ts"],"names":[],"mappings":"AAKA,6FAA6F;AAC7F,eAAO,MAAM,kBAAkB,yBAA0B,CAAC;AAC1D,eAAO,MAAM,UAAU,kCAAmC,CAAC;AAE3D,6IAA6I;AAC7I,eAAO,MAAM,gBAAgB,yBAA0B,CAAC;AACxD,eAAO,MAAM,mBAAmB,sBAAuB,CAAC;AAExD,0GAA0G;AAC1G,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGjD;AAED,2HAA2H;AAC3H,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAIjE;AAeD,mHAAmH;AACnH,wBAAgB,cAAc,CAAC,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,MAAM,QAG1F;AAQD,wGAAwG;AACxG,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAEjE;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAE/D;AAED,4GAA4G;AAC5G,wBAAgB,cAAc,CAAC,CAAC,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,MAAM,QAGhG"}
|
package/dist/v3/time-grid.js
CHANGED
|
@@ -1,15 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { EsseyError } from "../errors.js";
|
|
2
|
+
/** PRV-06: a client-chosen time on chain is a clock reading; this grid leaves only the step. */
|
|
3
3
|
const NOW_STEP_S = 15n;
|
|
4
|
-
/**
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/** PRV-27: offer windows and terms, in the deployment's close steps (an hour by default). */
|
|
5
|
+
export const OFFER_WINDOW_STEPS = [1, 6, 24, 72];
|
|
6
|
+
export const TERM_STEPS = [1, 24, 168, 720, 2160];
|
|
7
|
+
/** FOLLOWUPS #10: sale bid and finish windows, in close steps. 6 steps is 30 min at testnet's 5-minute step, `sale_room.move:67`'s floor. */
|
|
8
|
+
export const BID_WINDOW_STEPS = [1, 6, 24, 72];
|
|
9
|
+
export const FINISH_WINDOW_STEPS = [6, 24, 72];
|
|
10
|
+
/** `now_s` for a default claim: down to the settle step, inside `liquidation.move:400`'s 120 s window. */
|
|
11
|
+
export function defaultNowS(nowMs) {
|
|
12
|
+
const s = BigInt(Math.floor(nowMs / 1000));
|
|
13
|
+
return s - (s % NOW_STEP_S);
|
|
8
14
|
}
|
|
9
15
|
/** `now_s` for a settle: down to the step, never before the round's close (`move/v3/loan/sources/settle.move:129-135`). */
|
|
10
16
|
export function settleNowS(nowMs, closeMs) {
|
|
11
|
-
const
|
|
12
|
-
const snapped = s - (s % NOW_STEP_S);
|
|
17
|
+
const snapped = defaultNowS(nowMs);
|
|
13
18
|
const close = (closeMs + 999n) / 1000n;
|
|
14
19
|
return snapped > close ? snapped : close;
|
|
15
20
|
}
|
|
21
|
+
const label = (ms) => ms % 86_400_000 === 0
|
|
22
|
+
? `${ms / 86_400_000} d`
|
|
23
|
+
: ms % 3_600_000 === 0
|
|
24
|
+
? `${ms / 3_600_000} h`
|
|
25
|
+
: `${ms / 60_000} min`;
|
|
26
|
+
function onGrid(what, ms, steps, stepMs) {
|
|
27
|
+
const allowed = steps.map((n) => n * stepMs);
|
|
28
|
+
if (!allowed.includes(ms))
|
|
29
|
+
throw new EsseyError("INVALID_ARGUMENT", `${what} must be one of ${allowed.map(label).join(", ")}`);
|
|
30
|
+
}
|
|
31
|
+
/** Refuses a window or term off this deployment's public sets, so neither tells one member's loan from another. */
|
|
32
|
+
export function assertLoanGrid(p, stepMs) {
|
|
33
|
+
onGrid("the offer window", p.offerWindowMs, OFFER_WINDOW_STEPS, stepMs);
|
|
34
|
+
onGrid("the term", p.termMs, TERM_STEPS, stepMs);
|
|
35
|
+
}
|
|
36
|
+
const customClient = (what) => new EsseyError("INVALID_ARGUMENT", `refused: the request's ${what}, which marks a custom client; nothing was sent`);
|
|
37
|
+
/** FOLLOWUPS #11: a lender offers only on a request whose public close is on this deployment's step. */
|
|
38
|
+
export function assertRequestClose(closeMs, stepMs) {
|
|
39
|
+
if (closeMs % BigInt(stepMs) !== 0n)
|
|
40
|
+
throw customClient("close is off the close step");
|
|
41
|
+
}
|
|
42
|
+
/** FOLLOWUPS #11: and whose sealed term, once opened, is on the term set. */
|
|
43
|
+
export function assertRequestTerm(termMs, stepMs) {
|
|
44
|
+
if (!TERM_STEPS.some((n) => BigInt(n * stepMs) === termMs))
|
|
45
|
+
throw customClient("term is off the term set");
|
|
46
|
+
}
|
|
47
|
+
/** A sale's bid and finish windows off this deployment's sets would tell one seller's room from another. */
|
|
48
|
+
export function assertSaleGrid(p, stepMs) {
|
|
49
|
+
onGrid("the bid window", p.bidWindowMs, BID_WINDOW_STEPS, stepMs);
|
|
50
|
+
onGrid("the finish window", p.finishWindowMs, FINISH_WINDOW_STEPS, stepMs);
|
|
51
|
+
}
|