@esseyonsui/sui-sdk-v3 0.3.2 → 0.4.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 +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -0
- package/dist/essey.d.ts +157 -131
- package/dist/essey.d.ts.map +1 -1
- package/dist/essey.js +641 -823
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/network.d.ts +2 -0
- package/dist/network.d.ts.map +1 -1
- package/dist/network.js +17 -3
- package/dist/v3/collateral/bodies.d.ts +23 -14
- package/dist/v3/collateral/bodies.d.ts.map +1 -1
- package/dist/v3/collateral/bodies.js +42 -35
- package/dist/v3/collateral/ext.d.ts +18 -13
- package/dist/v3/collateral/ext.d.ts.map +1 -1
- package/dist/v3/collateral/ext.js +5 -6
- package/dist/v3/collateral/health.d.ts +16 -10
- package/dist/v3/collateral/health.d.ts.map +1 -1
- package/dist/v3/collateral/health.js +55 -30
- package/dist/v3/collateral/math.d.ts +0 -2
- package/dist/v3/collateral/math.d.ts.map +1 -1
- package/dist/v3/collateral/math.js +0 -5
- package/dist/v3/collateral/openings.d.ts +5 -1
- package/dist/v3/collateral/openings.d.ts.map +1 -1
- package/dist/v3/collateral/openings.js +7 -12
- package/dist/v3/credential/membership.d.ts +16 -2
- package/dist/v3/credential/membership.d.ts.map +1 -1
- package/dist/v3/credential/membership.js +36 -3
- package/dist/v3/domains.d.ts +9 -0
- package/dist/v3/domains.d.ts.map +1 -1
- package/dist/v3/domains.js +5 -0
- package/dist/v3/fees.d.ts +13 -1
- package/dist/v3/fees.d.ts.map +1 -1
- package/dist/v3/fees.js +32 -2
- package/dist/v3/funds.d.ts +34 -0
- package/dist/v3/funds.d.ts.map +1 -0
- package/dist/v3/funds.js +60 -0
- package/dist/v3/keeper-payload.d.ts +29 -7
- package/dist/v3/keeper-payload.d.ts.map +1 -1
- package/dist/v3/keeper-payload.js +33 -22
- package/dist/v3/kinds.d.ts +6 -6
- package/dist/v3/kinds.d.ts.map +1 -1
- package/dist/v3/kinds.js +5 -13
- package/dist/v3/loans/bodies.d.ts +40 -68
- package/dist/v3/loans/bodies.d.ts.map +1 -1
- package/dist/v3/loans/bodies.js +50 -73
- package/dist/v3/loans/offer-payload.d.ts +109 -0
- package/dist/v3/loans/offer-payload.d.ts.map +1 -0
- package/dist/v3/loans/offer-payload.js +207 -0
- package/dist/v3/loans/offer-plan.d.ts +8 -60
- package/dist/v3/loans/offer-plan.d.ts.map +1 -1
- package/dist/v3/loans/offer-plan.js +19 -95
- package/dist/v3/loans/open-plan.d.ts +15 -5
- package/dist/v3/loans/open-plan.d.ts.map +1 -1
- package/dist/v3/loans/open-plan.js +18 -7
- package/dist/v3/loans/reclaim-plan.d.ts +31 -15
- package/dist/v3/loans/reclaim-plan.d.ts.map +1 -1
- package/dist/v3/loans/reclaim-plan.js +63 -32
- package/dist/v3/loans/refi-plan.d.ts +8 -34
- package/dist/v3/loans/refi-plan.d.ts.map +1 -1
- package/dist/v3/loans/refi-plan.js +30 -111
- package/dist/v3/loans/repay-plan.d.ts.map +1 -1
- package/dist/v3/loans/repay-plan.js +2 -2
- package/dist/v3/loans/settle-plan.d.ts +88 -53
- package/dist/v3/loans/settle-plan.d.ts.map +1 -1
- package/dist/v3/loans/settle-plan.js +141 -150
- package/dist/v3/locks.d.ts +21 -0
- package/dist/v3/locks.d.ts.map +1 -0
- package/dist/v3/locks.js +15 -0
- package/dist/v3/memo.d.ts +14 -4
- package/dist/v3/memo.d.ts.map +1 -1
- package/dist/v3/memo.js +14 -7
- package/dist/v3/notes/derive.d.ts +5 -0
- package/dist/v3/notes/derive.d.ts.map +1 -1
- package/dist/v3/notes/derive.js +5 -0
- package/dist/v3/pace.d.ts +0 -1
- package/dist/v3/pace.d.ts.map +1 -1
- package/dist/v3/pace.js +0 -1
- package/dist/v3/pads.d.ts +15 -0
- package/dist/v3/pads.d.ts.map +1 -0
- package/dist/v3/pads.js +25 -0
- package/dist/v3/prover.d.ts +1 -1
- package/dist/v3/prover.d.ts.map +1 -1
- package/dist/v3/prover.js +1 -0
- package/dist/v3/relay/client.d.ts.map +1 -1
- package/dist/v3/relay/client.js +2 -2
- package/dist/v3/sales/auctioneer.d.ts +32 -27
- package/dist/v3/sales/auctioneer.d.ts.map +1 -1
- package/dist/v3/sales/auctioneer.js +67 -108
- package/dist/v3/sales/bid.d.ts +20 -49
- package/dist/v3/sales/bid.d.ts.map +1 -1
- package/dist/v3/sales/bid.js +28 -83
- package/dist/v3/sales/bodies.d.ts +4 -54
- package/dist/v3/sales/bodies.d.ts.map +1 -1
- package/dist/v3/sales/bodies.js +10 -52
- package/dist/v3/sales/claim.d.ts +0 -2
- package/dist/v3/sales/claim.d.ts.map +1 -1
- package/dist/v3/sales/claim.js +6 -8
- package/dist/v3/sales/index.d.ts +0 -1
- package/dist/v3/sales/index.d.ts.map +1 -1
- package/dist/v3/sales/index.js +0 -1
- package/dist/v3/sales/listing.d.ts +8 -6
- package/dist/v3/sales/listing.d.ts.map +1 -1
- package/dist/v3/sales/listing.js +27 -9
- package/dist/v3/sales/open-kind.d.ts +1 -3
- package/dist/v3/sales/open-kind.d.ts.map +1 -1
- package/dist/v3/sales/open-kind.js +2 -3
- package/dist/v3/sales/outcome.d.ts +5 -8
- package/dist/v3/sales/outcome.d.ts.map +1 -1
- package/dist/v3/sales/outcome.js +5 -9
- package/dist/v3/sales/package-gate.d.ts +3 -4
- package/dist/v3/sales/package-gate.d.ts.map +1 -1
- package/dist/v3/sales/package-gate.js +9 -7
- package/dist/v3/sales/rows.d.ts +9 -49
- package/dist/v3/sales/rows.d.ts.map +1 -1
- package/dist/v3/sales/rows.js +17 -91
- package/dist/v3/sales/seller.d.ts +2 -6
- package/dist/v3/sales/seller.d.ts.map +1 -1
- package/dist/v3/sales/seller.js +4 -11
- package/dist/v3/stage1.d.ts +8 -21
- package/dist/v3/stage1.d.ts.map +1 -1
- package/dist/v3/stage1.js +8 -76
- package/package.json +1 -1
- package/dist/v3/loans/lock-round.d.ts +0 -22
- package/dist/v3/loans/lock-round.d.ts.map +0 -1
- package/dist/v3/loans/lock-round.js +0 -20
- package/dist/v3/sales/reclaim.d.ts +0 -46
- package/dist/v3/sales/reclaim.d.ts.map +0 -1
- package/dist/v3/sales/reclaim.js +0 -57
|
@@ -2,10 +2,11 @@ import { poseidonHash } from "@mysten/sui/zklogin";
|
|
|
2
2
|
import { EsseyError } from "../../errors.js";
|
|
3
3
|
import { MODE_OPEN, MODE_TOPUP } from "../ext.js";
|
|
4
4
|
import { R } from "../domains.js";
|
|
5
|
-
import { BPS_DENOM, assertU64, ecdhBlind, feeLane,
|
|
5
|
+
import { BPS_DENOM, assertU64, ecdhBlind, feeLane, fieldAdd } from "../fees.js";
|
|
6
6
|
import { noteCommitment } from "../notes/keys.js";
|
|
7
|
+
import { dummyNull } from "../pads.js";
|
|
7
8
|
import { GRACE_S, collFor, overLine, valueAt } from "./math.js";
|
|
8
|
-
import { collLockPk, outputBlind, requestCommit,
|
|
9
|
+
import { collLockPk, outputBlind, requestCommit, termsOuter, termsRest, } from "./openings.js";
|
|
9
10
|
export const MODE = {
|
|
10
11
|
OPEN: MODE_OPEN,
|
|
11
12
|
HEARTBEAT: 2,
|
|
@@ -15,7 +16,7 @@ export const MODE = {
|
|
|
15
16
|
RELEASE: 6,
|
|
16
17
|
FAULT: 7,
|
|
17
18
|
};
|
|
18
|
-
export const HEALTH_VERSION =
|
|
19
|
+
export const HEALTH_VERSION = 2n;
|
|
19
20
|
/**
|
|
20
21
|
* Outside TOPUP the lender delivery runs on Base8 and its rows are the identity (`health.circom:383-394`), so
|
|
21
22
|
* the scalar hides nothing. This is the one every stored fixture proves with (`circuits/v3/health/ref.mjs:49`).
|
|
@@ -43,7 +44,7 @@ export async function lenderAmount(encSk, [lEx, lEy, lCt]) {
|
|
|
43
44
|
const { sx } = await ecdhBlind(lEx, lEy, encSk);
|
|
44
45
|
return (lCt - lenderMask(sx) + R) % R;
|
|
45
46
|
}
|
|
46
|
-
/** A seize inserts `[out 0, out 3, out 1, out 2]` (
|
|
47
|
+
/** A seize inserts `[out 0, out 3, out 1, out 2]` (Z1-LEAF-MAP.md, seizure row). */
|
|
47
48
|
const SEIZE_LEAF_AT = { 0: 0, 1: 2 };
|
|
48
49
|
/** Whether the pool's last leaf is still the one closing the seize that inserted output `out` at `index`. */
|
|
49
50
|
export function seizeIsLast(leafCount, index, out) {
|
|
@@ -52,17 +53,17 @@ export function seizeIsLast(leafCount, index, out) {
|
|
|
52
53
|
/**
|
|
53
54
|
* A seizure's split of the lock (B §5.5, `health.circom:303-346`): what the seizer proves, and what the lender and the
|
|
54
55
|
* borrower recompute afterwards from the claimed `p_spot` the seizing call took. FAULT seizes the whole lock and runs
|
|
55
|
-
* the price chain on (debt 0, price 1), so pass `owed` 0 and `pSpot` 1 with it.
|
|
56
|
+
* the price chain on (debt 0, price 1), so pass `owed` 0 and `pSpot` 1 with it. Seizures pay no protocol fee (Erik
|
|
57
|
+
* FLAT-FEE row; `health.circom` `lane.base <== 0`).
|
|
56
58
|
*/
|
|
57
59
|
export function seizeSplit(p) {
|
|
58
60
|
const prodT = p.owed * (BPS_DENOM + p.risk.bonusBps);
|
|
59
61
|
const target = prodT / BPS_DENOM;
|
|
60
62
|
const seizeR = collFor(target, p.pSpot, { cDec: p.risk.cDec, lDec: p.risk.lDec, expo: p.expo });
|
|
61
63
|
const seize = p.fault || seizeR.q >= p.avail ? p.avail : seizeR.q;
|
|
62
|
-
const pf = feeOf({ base: seize, bps: p.fee.bps, min: p.fee.min, max: p.fee.max }).fee;
|
|
63
64
|
const prodK = seize * p.risk.keeperBps;
|
|
64
65
|
const kf = prodK / BPS_DENOM;
|
|
65
|
-
return { prodT, target, seizeR, seize,
|
|
66
|
+
return { prodT, target, seizeR, seize, prodK, kf, toLender: seize - kf, surplus: p.avail - seize };
|
|
66
67
|
}
|
|
67
68
|
/** `loan::keeper_bps`: the liquidation rate in LIQUIDATE and FAULT, the default rate in DEFAULT, or 0. */
|
|
68
69
|
export function loanRisk(rates, decimals, mode) {
|
|
@@ -91,6 +92,9 @@ function assertRanges(p, principal, terms, addAmount) {
|
|
|
91
92
|
for (const [name, value] of Object.entries({ ltvBps, liqBps, bonusBps, keeperBps }))
|
|
92
93
|
if (value < 0n || value > MAX_BPS)
|
|
93
94
|
throw new Error(`${name} is not in 0..10000`);
|
|
95
|
+
for (const [name, value] of Object.entries({ dummySeed0: p.dummySeeds[0], dummySeed1: p.dummySeeds[1] }))
|
|
96
|
+
if (value < 0n || value >= R)
|
|
97
|
+
throw new Error(`${name} is not a field element`);
|
|
94
98
|
}
|
|
95
99
|
/** The per-mode constraints of `health.circom:281-299`: a witness that breaks one has no proof. */
|
|
96
100
|
function assertProvable(p, principal, terms, spot, ema) {
|
|
@@ -110,6 +114,15 @@ function assertProvable(p, principal, terms, spot, ema) {
|
|
|
110
114
|
if (mode === MODE.DEFAULT && p.timeS < due)
|
|
111
115
|
refuse("INVALID_ARGUMENT", "maturity plus grace has not passed");
|
|
112
116
|
}
|
|
117
|
+
/** TOPUP opens `hRest` (`health.circom` `s3 * (hRest - rest.out) === 0`); a stated one must agree. */
|
|
118
|
+
function restOf(p, terms) {
|
|
119
|
+
if (p.mode === MODE.OPEN)
|
|
120
|
+
return 0n;
|
|
121
|
+
const opened = termsRest(terms);
|
|
122
|
+
if (p.mode === MODE.TOPUP && p.hRest !== undefined && p.hRest !== opened)
|
|
123
|
+
refuse("INVALID_ARGUMENT", "a top-up's terms do not open the stated hRest");
|
|
124
|
+
return p.hRest ?? opened;
|
|
125
|
+
}
|
|
113
126
|
function feeInputs(fee, eph, lane) {
|
|
114
127
|
return {
|
|
115
128
|
fee_bps: fee.bps.toString(),
|
|
@@ -135,7 +148,8 @@ export async function health(p) {
|
|
|
135
148
|
const request = p.mode === MODE.OPEN ? p.request : NO_REQUEST;
|
|
136
149
|
const principal = p.mode === MODE.OPEN ? request.principal : terms.principal;
|
|
137
150
|
const add = p.mode === MODE.TOPUP ? p.add : { amount: 0n, blinding: 0n, ephL: IDLE_EPH_L };
|
|
138
|
-
const
|
|
151
|
+
const [pad1, pad2] = p.pads;
|
|
152
|
+
const out2Key = seizing ? p.keeper : pad2;
|
|
139
153
|
assertRanges(p, principal, terms, add.amount);
|
|
140
154
|
if (priced && price.spot === 0n)
|
|
141
155
|
refuse("INVALID_ARGUMENT", "a seizure needs a spot price");
|
|
@@ -147,33 +161,35 @@ export async function health(p) {
|
|
|
147
161
|
refuse("INVALID_ARGUMENT", "the fee and keeper rates exceed the bonus");
|
|
148
162
|
const lockPk = collLockPk(o.loanKey, o.borrowerPk);
|
|
149
163
|
const note = noteCommitment(o.amount, lockPk, o.blinding);
|
|
150
|
-
const
|
|
164
|
+
const hRest = restOf(p, terms);
|
|
165
|
+
const commitIn = mode === MODE.OPEN ? requestCommit(request, o.borrowerPk, note) : termsOuter(terms, o.borrowerPk, hRest);
|
|
151
166
|
const { prodT, target, seizeR, seize, prodK, kf } = seizeSplit({
|
|
152
167
|
owed: priced ? terms.owed : 0n,
|
|
153
168
|
avail: seizing ? o.amount : 0n,
|
|
154
169
|
pSpot: priced ? price.spot : 1n,
|
|
155
170
|
expo: price.expo,
|
|
156
171
|
risk,
|
|
157
|
-
fee: p.fee,
|
|
158
172
|
fault: mode === MODE.FAULT,
|
|
159
173
|
});
|
|
160
|
-
const lane = await feeLane({ ...p.fee, base:
|
|
161
|
-
const toLender = seize -
|
|
162
|
-
if (toLender < 0n)
|
|
163
|
-
refuse("INVALID_ARGUMENT", "the fee and the keeper fee exceed the seized amount");
|
|
174
|
+
const lane = await feeLane({ ...p.fee, base: 0n, eph: p.eph });
|
|
175
|
+
const toLender = seize - kf;
|
|
164
176
|
const avail = o.amount + add.amount;
|
|
165
177
|
assertU64("collAmt + addAmt", avail);
|
|
166
178
|
const bD0 = outputBlind(o.blinding, 0, o.nonce);
|
|
167
|
-
|
|
179
|
+
const padNotes = [
|
|
180
|
+
{ amount: 0n, pk: pad1.pk, blinding: pad1.blinding },
|
|
181
|
+
{ amount: 0n, pk: out2Key.pk, blinding: out2Key.blinding },
|
|
182
|
+
];
|
|
183
|
+
let notes = [NO_NOTE, ...padNotes];
|
|
168
184
|
if (mode === MODE.HEARTBEAT || mode === MODE.TOPUP)
|
|
169
|
-
notes = [{ amount: avail, pk: lockPk, blinding: bD0 },
|
|
185
|
+
notes = [{ amount: avail, pk: lockPk, blinding: bD0 }, ...padNotes];
|
|
170
186
|
if (mode === MODE.RELEASE)
|
|
171
|
-
notes = [{ amount: avail, pk: o.borrowerPk, blinding: bD0 },
|
|
187
|
+
notes = [{ amount: avail, pk: o.borrowerPk, blinding: bD0 }, ...padNotes];
|
|
172
188
|
if (seizing)
|
|
173
189
|
notes = [
|
|
174
190
|
{ amount: toLender, pk: terms.lenderPk, blinding: bD0 },
|
|
175
191
|
{ amount: avail - seize, pk: o.borrowerPk, blinding: outputBlind(o.blinding, 1, o.nonce) },
|
|
176
|
-
{ amount: kf, pk:
|
|
192
|
+
{ amount: kf, pk: out2Key.pk, blinding: out2Key.blinding },
|
|
177
193
|
];
|
|
178
194
|
const [out0, out1, out2] = notes.map((n) => noteCommitment(n.amount, n.pk, n.blinding));
|
|
179
195
|
const addCommit = mode === MODE.TOPUP ? noteCommitment(add.amount, lockPk, add.blinding) : 0n;
|
|
@@ -182,28 +198,32 @@ export async function health(p) {
|
|
|
182
198
|
const k = await ecdhBlind(terms.lenderEncX, terms.lenderEncY, add.ephL);
|
|
183
199
|
lender = [k.ephX, k.ephY, fieldAdd(notes[0].amount, lenderMask(k.sx))];
|
|
184
200
|
}
|
|
201
|
+
const hP = poseidonHash([
|
|
202
|
+
risk.cDec,
|
|
203
|
+
risk.lDec,
|
|
204
|
+
risk.ltvBps,
|
|
205
|
+
risk.liqBps,
|
|
206
|
+
risk.bonusBps,
|
|
207
|
+
risk.keeperBps,
|
|
208
|
+
p.timeS,
|
|
209
|
+
o.nonce,
|
|
210
|
+
]);
|
|
185
211
|
const s = [
|
|
186
212
|
BigInt(mode),
|
|
187
213
|
o.loanKey,
|
|
188
214
|
note,
|
|
189
215
|
commitIn,
|
|
190
216
|
addCommit,
|
|
191
|
-
risk.cDec,
|
|
192
|
-
risk.lDec,
|
|
193
|
-
risk.ltvBps,
|
|
194
|
-
risk.liqBps,
|
|
195
|
-
risk.bonusBps,
|
|
196
217
|
lane.fee_commit,
|
|
197
|
-
risk.keeperBps,
|
|
198
218
|
p.fee.version,
|
|
199
219
|
p.extHash,
|
|
200
|
-
|
|
201
|
-
o.nonce,
|
|
220
|
+
hP,
|
|
202
221
|
];
|
|
203
222
|
const outs = [out0, out1, out2, lane.fee_note];
|
|
204
|
-
const
|
|
223
|
+
const dummies = p.dummySeeds.map(dummyNull);
|
|
224
|
+
const delivery = [lane.ephX, lane.ephY, lane.fee_ct, ...lender, ...dummies];
|
|
205
225
|
const a = [price.spot, price.ema, price.expo, ...outs, HEALTH_VERSION];
|
|
206
|
-
const d = [...delivery
|
|
226
|
+
const d = [...delivery];
|
|
207
227
|
const input = {
|
|
208
228
|
mode: mode.toString(),
|
|
209
229
|
loanKey: o.loanKey.toString(),
|
|
@@ -218,6 +238,7 @@ export async function health(p) {
|
|
|
218
238
|
lenderEncX: terms.lenderEncX.toString(),
|
|
219
239
|
lenderEncY: terms.lenderEncY.toString(),
|
|
220
240
|
salt_t: terms.salt.toString(),
|
|
241
|
+
hRest: hRest.toString(),
|
|
221
242
|
max_rate_bps: request.maxRateBps.toString(),
|
|
222
243
|
term_ms: request.termMs.toString(),
|
|
223
244
|
salt_req: request.salt.toString(),
|
|
@@ -235,8 +256,12 @@ export async function health(p) {
|
|
|
235
256
|
p_ema: price.ema.toString(),
|
|
236
257
|
time_s: p.timeS.toString(),
|
|
237
258
|
nonce: o.nonce.toString(),
|
|
238
|
-
keeperPk:
|
|
239
|
-
keeperBlind:
|
|
259
|
+
keeperPk: out2Key.pk.toString(),
|
|
260
|
+
keeperBlind: out2Key.blinding.toString(),
|
|
261
|
+
padPk1: pad1.pk.toString(),
|
|
262
|
+
padBlind1: pad1.blinding.toString(),
|
|
263
|
+
dummySeed0: p.dummySeeds[0].toString(),
|
|
264
|
+
dummySeed1: p.dummySeeds[1].toString(),
|
|
240
265
|
extHash: p.extHash.toString(),
|
|
241
266
|
eL: add.ephL.toString(),
|
|
242
267
|
q_spot: spot.q.toString(),
|
|
@@ -28,8 +28,6 @@ export declare function collFor(value: bigint, price: bigint, s: Scale): {
|
|
|
28
28
|
};
|
|
29
29
|
/** `heartbeat_floor` (`liquidation.move:475-484`): floor(rung(min(spot, ema)) · (10000 - 500) / 10000). */
|
|
30
30
|
export declare const heartbeatFloor: (r: Pick<Reading, "spot" | "ema">) => bigint;
|
|
31
|
-
/** DECISION-R1-MIGRATION A: a retired-package loan's floor, the pre-R1 `heartbeat_floor` at bucket 1, unsnapped. */
|
|
32
|
-
export declare function legacyHeartbeatFloor(r: Pick<Reading, "spot" | "ema">): bigint;
|
|
33
31
|
/** `liquidation.move` `HB_EXPIRY_STEP_MS`: a heartbeat expiry is on this step (43_005). */
|
|
34
32
|
export declare const COVER_STEP_MS = 300000n;
|
|
35
33
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/v3/collateral/math.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,OAAO,CAAC;AAC5B,eAAO,MAAM,WAAW,OAAO,CAAC;AA+ChC,yGAAyG;AACzG,MAAM,MAAM,KAAK,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAA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,EAAE,MAAM,CAAA;CAAE,CAKzF;AAED,+EAA+E;AAC/E,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM,EAAE,MAAM,MAAM,EAAE,KAAK,MAAM,YAAmC,CAAC;AAErG;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAMxF;AAYD,2GAA2G;AAC3G,eAAO,MAAM,cAAc,GAAI,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,KAAG,MACV,CAAC;AAEzD,2FAA2F;AAC3F,eAAO,MAAM,aAAa,UAAW,CAAC;AAGtC;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAIpE;AAED,kIAAkI;AAClI,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGvE"}
|
|
@@ -82,11 +82,6 @@ function floorRung(r) {
|
|
|
82
82
|
}
|
|
83
83
|
/** `heartbeat_floor` (`liquidation.move:475-484`): floor(rung(min(spot, ema)) · (10000 - 500) / 10000). */
|
|
84
84
|
export const heartbeatFloor = (r) => (floorRung(r) * (BPS_DENOM - HB_STEP_BPS)) / BPS_DENOM;
|
|
85
|
-
/** DECISION-R1-MIGRATION A: a retired-package loan's floor, the pre-R1 `heartbeat_floor` at bucket 1, unsnapped. */
|
|
86
|
-
export function legacyHeartbeatFloor(r) {
|
|
87
|
-
const low = r.spot < r.ema ? r.spot : r.ema;
|
|
88
|
-
return (low * (BPS_DENOM - HB_STEP_BPS)) / BPS_DENOM;
|
|
89
|
-
}
|
|
90
85
|
/** `liquidation.move` `HB_EXPIRY_STEP_MS`: a heartbeat expiry is on this step (43_005). */
|
|
91
86
|
export const COVER_STEP_MS = 300000n;
|
|
92
87
|
const COVER_AHEAD_MS = 82800000n;
|
|
@@ -18,7 +18,11 @@ export declare const collLockPk: (loanKey: bigint, borrowerPk: bigint) => bigint
|
|
|
18
18
|
export declare const collNote: (o: Omit<CollOpening, "nonce">) => bigint;
|
|
19
19
|
/** `OutBlind(i)` of `health.circom:45-56`: a borrower or lender can always recompute an output's blinding. */
|
|
20
20
|
export declare const outputBlind: (collBlind: bigint, i: 0 | 1, nonce: bigint) => bigint;
|
|
21
|
-
/** `
|
|
21
|
+
/** `lib/terms2.circom` TermsRest: the half of the terms a keeper never opens (freeze D4a). */
|
|
22
|
+
export declare const termsRest: (t: Pick<KeeperTerms, "principal" | "rateBps" | "lenderEncX" | "lenderEncY" | "salt">) => bigint;
|
|
23
|
+
/** `lib/terms2.circom` TermsOuter over `hRest`. */
|
|
24
|
+
export declare const termsOuter: (t: Pick<KeeperTerms, "owed" | "maturityS" | "lenderPk">, borrowerPk: bigint, hRest: bigint) => bigint;
|
|
25
|
+
/** `lib/terms2.circom` Terms2. */
|
|
22
26
|
export declare const termsCommit: (t: KeeperTerms, borrowerPk: bigint) => bigint;
|
|
23
27
|
/** `health.circom:238-244`. */
|
|
24
28
|
export declare const requestCommit: (q: ReqOpening, borrowerPk: bigint, note: bigint) => bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openings.d.ts","sourceRoot":"","sources":["../../../src/v3/collateral/openings.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,kFAAkF;AAClF,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IAAE,SAAS,EAAE,M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C9F,eAAO,MAAM,SAAS,GACpB,GAAG,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,GAAG,YAAY,GAAG,YAAY,GAAG,MAAM,CAAC,WACoB,CAAC;AAE3G,mDAAmD;AACnD,eAAO,MAAM,UAAU,GACrB,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,CAAC,EACvD,YAAY,MAAM,EAClB,OAAO,MAAM,WACmE,CAAC;AAEnF,kCAAkC;AAClC,eAAO,MAAM,WAAW,GAAI,GAAG,WAAW,EAAE,YAAY,MAAM,WAA4C,CAAC;AAE3G,+BAA+B;AAC/B,eAAO,MAAM,aAAa,GAAI,GAAG,UAAU,EAAE,YAAY,MAAM,EAAE,MAAM,MAAM,WACE,CAAC;AAEhF,4FAA4F;AAC5F,eAAO,MAAM,QAAQ,GAAI,GAAG,WAAW,EAAE,cAAU,KAAG,WAKpD,CAAC"}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import { poseidonHash } from "@mysten/sui/zklogin";
|
|
2
|
-
import { DOM_BLIND, DOM_LOCK_COLL } from "../domains.js";
|
|
2
|
+
import { DOM_BLIND, DOM_LOCK_COLL, DOM_TERMS, DOM_TREST } from "../domains.js";
|
|
3
3
|
import { noteCommitment } from "../notes/keys.js";
|
|
4
4
|
/** E-1 (`circuits/v3/lib/lock.circom` CollLockNote): a pk nobody holds a key for. */
|
|
5
5
|
export const collLockPk = (loanKey, borrowerPk) => poseidonHash([DOM_LOCK_COLL, loanKey, borrowerPk, 0n]);
|
|
6
6
|
export const collNote = (o) => noteCommitment(o.amount, collLockPk(o.loanKey, o.borrowerPk), o.blinding);
|
|
7
7
|
/** `OutBlind(i)` of `health.circom:45-56`: a borrower or lender can always recompute an output's blinding. */
|
|
8
8
|
export const outputBlind = (collBlind, i, nonce) => poseidonHash([DOM_BLIND, collBlind, BigInt(i), nonce]);
|
|
9
|
-
/** `
|
|
10
|
-
export const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
borrowerPk,
|
|
16
|
-
t.lenderPk,
|
|
17
|
-
poseidonHash([t.lenderEncX, t.lenderEncY]),
|
|
18
|
-
t.salt,
|
|
19
|
-
]);
|
|
9
|
+
/** `lib/terms2.circom` TermsRest: the half of the terms a keeper never opens (freeze D4a). */
|
|
10
|
+
export const termsRest = (t) => poseidonHash([DOM_TREST, t.principal, t.rateBps, poseidonHash([t.lenderEncX, t.lenderEncY]), t.salt]);
|
|
11
|
+
/** `lib/terms2.circom` TermsOuter over `hRest`. */
|
|
12
|
+
export const termsOuter = (t, borrowerPk, hRest) => poseidonHash([DOM_TERMS, t.owed, t.maturityS, borrowerPk, t.lenderPk, hRest]);
|
|
13
|
+
/** `lib/terms2.circom` Terms2. */
|
|
14
|
+
export const termsCommit = (t, borrowerPk) => termsOuter(t, borrowerPk, termsRest(t));
|
|
20
15
|
/** `health.circom:238-244`. */
|
|
21
16
|
export const requestCommit = (q, borrowerPk, note) => poseidonHash([q.principal, q.maxRateBps, q.termMs, borrowerPk, note, q.salt]);
|
|
22
17
|
/** The lock a HEARTBEAT, or a TOPUP of `added`, leaves behind (`health.circom:354-373`). */
|
|
@@ -33,7 +33,21 @@ export declare function offerRoom(loanKey: bigint, round: bigint): string;
|
|
|
33
33
|
export declare function memberCommitment(s: MemberSecrets): bigint;
|
|
34
34
|
export declare function credentialMessage(commitment: bigint, expiryMs: bigint, epoch: bigint, role: Credential["role"]): bigint;
|
|
35
35
|
export declare function memberTag(nullSecret: bigint, room: string, nonce?: bigint): bigint;
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* PRV-33, Erik's rate-lane row: `lane = window * 2^16 + slot` with `slot < RATE_K`, so one member has exactly K
|
|
38
|
+
* unlinkable fee-params tags per hour. Strict v3api refuses a lane outside the current or previous window and a
|
|
39
|
+
* repeated tag.
|
|
40
|
+
*/
|
|
41
|
+
export declare const RATE_K = 60;
|
|
42
|
+
export declare const RATE_WINDOW_MS = 3600000;
|
|
43
|
+
export declare function rateLane(nowMs: number, slot: number): bigint;
|
|
44
|
+
/** Memory only. Slots are drawn without repeat, so the slot v3api sees says nothing about how many came before. */
|
|
45
|
+
export declare class RateSlots {
|
|
46
|
+
private readonly draw;
|
|
47
|
+
private window;
|
|
48
|
+
private free;
|
|
49
|
+
constructor(draw?: (below: number) => number);
|
|
50
|
+
take(nowMs: number): bigint;
|
|
51
|
+
}
|
|
38
52
|
export declare function passCtx(domain: bigint, room: string, bind: string): bigint;
|
|
39
53
|
//# sourceMappingURL=membership.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membership.d.ts","sourceRoot":"","sources":["../../../src/v3/credential/membership.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"membership.d.ts","sourceRoot":"","sources":["../../../src/v3/credential/membership.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,wFAAwF;AACxF,MAAM,MAAM,aAAa,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,4DAA4D;AAC5D,MAAM,MAAM,UAAU,GAAG;IACvB,GAAG,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACrC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC3B,CAAC;AAEF,8GAA8G;AAC9G,eAAO,MAAM,eAAe,QAAyD,CAAC;AAEtF,kGAAkG;AAClG,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAGtD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,aAAa,GAAG,MAAM,CAEzD;AAKD,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,GACvB,MAAM,CAER;AAED,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAE9E;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,KAAK,CAAC;AACzB,eAAO,MAAM,cAAc,UAAY,CAAC;AAGxC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED,mHAAmH;AACnH,qBAAa,SAAS;IAIR,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,IAAI,CAAgB;gBAEC,IAAI,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAoC;IAE1F,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAW5B;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1E"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { randomInt } from "node:crypto";
|
|
1
2
|
import { poseidonHash } from "@mysten/sui/zklogin";
|
|
3
|
+
import { EsseyError } from "../../errors.js";
|
|
2
4
|
import { DOM_ROUND, FEE_PARAMS_DOMAIN } from "../domains.js";
|
|
3
5
|
export const DOMAIN_SENDER = 1n;
|
|
4
6
|
export const DOMAIN_SPEND = 2n;
|
|
@@ -29,9 +31,40 @@ export function credentialMessage(commitment, expiryMs, epoch, role) {
|
|
|
29
31
|
export function memberTag(nullSecret, room, nonce = 0n) {
|
|
30
32
|
return poseidonHash([nullSecret, ...halves(room), nonce]);
|
|
31
33
|
}
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* PRV-33, Erik's rate-lane row: `lane = window * 2^16 + slot` with `slot < RATE_K`, so one member has exactly K
|
|
36
|
+
* unlinkable fee-params tags per hour. Strict v3api refuses a lane outside the current or previous window and a
|
|
37
|
+
* repeated tag.
|
|
38
|
+
*/
|
|
39
|
+
export const RATE_K = 60;
|
|
40
|
+
export const RATE_WINDOW_MS = 3_600_000;
|
|
41
|
+
const SLOT_BITS = 16n;
|
|
42
|
+
export function rateLane(nowMs, slot) {
|
|
43
|
+
if (!Number.isSafeInteger(nowMs) || nowMs < 0)
|
|
44
|
+
throw new Error("nowMs is not a time");
|
|
45
|
+
if (!Number.isInteger(slot) || slot < 0 || slot >= RATE_K)
|
|
46
|
+
throw new Error("slot is not a rate slot");
|
|
47
|
+
return (BigInt(Math.floor(nowMs / RATE_WINDOW_MS)) << SLOT_BITS) + BigInt(slot);
|
|
48
|
+
}
|
|
49
|
+
/** Memory only. Slots are drawn without repeat, so the slot v3api sees says nothing about how many came before. */
|
|
50
|
+
export class RateSlots {
|
|
51
|
+
draw;
|
|
52
|
+
window = -1;
|
|
53
|
+
free = [];
|
|
54
|
+
constructor(draw = (below) => randomInt(below)) {
|
|
55
|
+
this.draw = draw;
|
|
56
|
+
}
|
|
57
|
+
take(nowMs) {
|
|
58
|
+
const window = Math.floor(nowMs / RATE_WINDOW_MS);
|
|
59
|
+
if (window !== this.window) {
|
|
60
|
+
this.window = window;
|
|
61
|
+
this.free = Array.from({ length: RATE_K }, (_, i) => i);
|
|
62
|
+
}
|
|
63
|
+
if (this.free.length === 0)
|
|
64
|
+
throw new EsseyError("RATE_LIMITED", `refused: all ${RATE_K} fee-params lanes of this hour are used`);
|
|
65
|
+
const [slot] = this.free.splice(this.draw(this.free.length), 1);
|
|
66
|
+
return rateLane(nowMs, slot);
|
|
67
|
+
}
|
|
35
68
|
}
|
|
36
69
|
export function passCtx(domain, room, bind) {
|
|
37
70
|
return poseidonHash([domain, ...halves(room), ...halves(bind)]);
|
package/dist/v3/domains.d.ts
CHANGED
|
@@ -100,6 +100,15 @@ export declare const DOM_CL: bigint;
|
|
|
100
100
|
export declare const DOM_KPR: bigint;
|
|
101
101
|
export declare const DOM_SALEKEY: bigint;
|
|
102
102
|
export declare const DOM_CNULL: bigint;
|
|
103
|
+
/** `circuits/v3/lib/domains_z1.circom`: Terms2's two tags and the lock blind's (freeze §2, ruling R5). */
|
|
104
|
+
export declare const Z1_TAGS: {
|
|
105
|
+
readonly DOM_TERMS: "ess3/terms";
|
|
106
|
+
readonly DOM_TREST: "ess3/trest";
|
|
107
|
+
readonly DOM_LOCKB: "ess3/lockb";
|
|
108
|
+
};
|
|
109
|
+
export declare const DOM_TERMS: bigint;
|
|
110
|
+
export declare const DOM_TREST: bigint;
|
|
111
|
+
export declare const DOM_LOCKB: bigint;
|
|
103
112
|
export declare const DOMAINS: {
|
|
104
113
|
readonly DOM_LOCK: bigint;
|
|
105
114
|
readonly DOM_LNULL: bigint;
|
package/dist/v3/domains.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domains.d.ts","sourceRoot":"","sources":["../../src/v3/domains.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,CAAC,iFAAQ,CAAC;AAGvB,eAAO,MAAM,WAAW,QAAQ,CAAC;AAEjC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,iFACkD,CAAC;AAEjF;;;;GAIG;AACH,eAAO,MAAM,aAAa,iFAAiF,CAAC;AAE5G;;;GAGG;AACH,eAAO,MAA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O,MAAM,OAAO,QAA2B,CAAC;AAChD,eAAO,MAAM,WAAW,QAA+B,CAAC;AACxD,eAAO,MAAM,SAAS,QAA6B,CAAC;AAEpD,0GAA0G;AAC1G,eAAO,MAAM,OAAO;;;;CAAyF,CAAC;AAC9G,eAAO,MAAM,SAAS,QAAgC,CAAC;AACvD,eAAO,MAAM,SAAS,QAAgC,CAAC;AACvD,eAAO,MAAM,SAAS,QAAgC,CAAC;AAEvD,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCV,CAAC;AAEX,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAI5C"}
|
package/dist/v3/domains.js
CHANGED
|
@@ -113,6 +113,11 @@ export const DOM_CL = tagToField(TAGS.DOM_CL);
|
|
|
113
113
|
export const DOM_KPR = tagToField(TAGS.DOM_KPR);
|
|
114
114
|
export const DOM_SALEKEY = tagToField(TAGS.DOM_SALEKEY);
|
|
115
115
|
export const DOM_CNULL = tagToField(TAGS.DOM_CNULL);
|
|
116
|
+
/** `circuits/v3/lib/domains_z1.circom`: Terms2's two tags and the lock blind's (freeze §2, ruling R5). */
|
|
117
|
+
export const Z1_TAGS = { DOM_TERMS: "ess3/terms", DOM_TREST: "ess3/trest", DOM_LOCKB: "ess3/lockb" };
|
|
118
|
+
export const DOM_TERMS = tagToField(Z1_TAGS.DOM_TERMS);
|
|
119
|
+
export const DOM_TREST = tagToField(Z1_TAGS.DOM_TREST);
|
|
120
|
+
export const DOM_LOCKB = tagToField(Z1_TAGS.DOM_LOCKB);
|
|
116
121
|
export const DOMAINS = {
|
|
117
122
|
DOM_LOCK,
|
|
118
123
|
DOM_LNULL,
|
package/dist/v3/fees.d.ts
CHANGED
|
@@ -42,10 +42,22 @@ export type FeeLaneResult = FeeOf & {
|
|
|
42
42
|
};
|
|
43
43
|
export declare function assertU64(name: string, n: bigint): void;
|
|
44
44
|
export declare function feeOf({ base, bps, min, max }: FeeRates): FeeOf;
|
|
45
|
-
export declare function assertFeeConfig(bps: bigint, min: bigint, max: bigint): void;
|
|
45
|
+
export declare function assertFeeConfig(bps: bigint, min: bigint, max: bigint, lane?: FeeLane): void;
|
|
46
|
+
/** The smallest principal, refinance principal, sale price or early-reclaimed lock a hidden fee config proves. */
|
|
47
|
+
export declare const minHiddenBase: (fee: Pick<FeeCommitInput, "bps" | "min">) => bigint;
|
|
46
48
|
export declare function feeCommit(input: FeeCommitInput): bigint;
|
|
47
49
|
export declare function fieldAdd(a: bigint, b: bigint): bigint;
|
|
48
50
|
export declare function feeLane(input: FeeLaneInput): Promise<FeeLaneResult>;
|
|
51
|
+
/**
|
|
52
|
+
* `lib/fee_flat.circom` FeeFlat (Z1 PRV-02 O1): F is `fee_min` of the opening, charged when `on` and the rate flag
|
|
53
|
+
* are both set. A live opening with `min != max` has no witness, and the 10% rule makes `10 F` the smallest base.
|
|
54
|
+
*/
|
|
55
|
+
export declare function flatFeeOf({ on, base, bps, min, max }: FeeRates & {
|
|
56
|
+
on: boolean;
|
|
57
|
+
}): FeeOf;
|
|
58
|
+
export declare function flatFeeLane(input: FeeLaneInput & {
|
|
59
|
+
on?: boolean;
|
|
60
|
+
}): Promise<FeeLaneResult>;
|
|
49
61
|
/**
|
|
50
62
|
* `circuits/v3/lib/ecdh_blind.circom` outside the fee lane: `E = e·Base8` and `S = e·Pub`, refused where that
|
|
51
63
|
* circuit has no witness. Health TOPUP delivers the new collateral amount to the lender through it.
|
package/dist/v3/fees.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fees.d.ts","sourceRoot":"","sources":["../../src/v3/fees.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,WAAW,EAAK,MAAM,cAAc,CAAC;AAKnE,eAAO,MAAM,SAAS,SAAU,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,CAAC;AACvB,eAAO,MAAM,WAAW,OAAO,CAAC;AAKhC,MAAM,MAAM,QAAQ,GA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,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAcrD;AAED,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,CAKvF;AAED;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAExC,oGAAoG;AACpG,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,GAAG,cAAc,CAoB3F"}
|
package/dist/v3/fees.js
CHANGED
|
@@ -50,16 +50,25 @@ export function feeOf({ base, bps, min, max }) {
|
|
|
50
50
|
// floor(base * bps / 10000). That holds if bps is 0 (the fee is forced to 0),
|
|
51
51
|
// max is 0 (the cap is 0), or min is 0 (the clamp never raises q).
|
|
52
52
|
// Any other triple takes the whole base on base = 1, which is above 10%.
|
|
53
|
-
|
|
53
|
+
// The hidden lane is FeeFlat (Z1 PRV-02 O1): a live config is flat (min == max = F) and the 10% rule refuses a
|
|
54
|
+
// base under 10 F instead of the config (`minHiddenBase`).
|
|
55
|
+
export function assertFeeConfig(bps, min, max, lane = "edge") {
|
|
54
56
|
assertU64("fee_bps", bps);
|
|
55
57
|
assertU64("fee_min", min);
|
|
56
58
|
assertU64("fee_max", max);
|
|
57
59
|
if (bps > MAX_FEE_BPS)
|
|
58
60
|
throw new Error("refused: fee rate above 1000");
|
|
61
|
+
if (lane === "hidden") {
|
|
62
|
+
if (bps > 0n && min !== max)
|
|
63
|
+
throw new Error("refused: a live hidden fee config is not flat");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
59
66
|
if (bps > 0n && min > 0n && max > 0n) {
|
|
60
67
|
throw new Error("refused: fee min and max can push the fee above the rate cap");
|
|
61
68
|
}
|
|
62
69
|
}
|
|
70
|
+
/** The smallest principal, refinance principal, sale price or early-reclaimed lock a hidden fee config proves. */
|
|
71
|
+
export const minHiddenBase = (fee) => fee.bps === 0n ? 0n : 10n * fee.min;
|
|
63
72
|
// Poseidon9(DOM_FEE, bps, min, max, pk, tX, tY, salt, version). Hash only.
|
|
64
73
|
// The point is not checked here, so a commit can be compared with the chain
|
|
65
74
|
// even when the circuit would refuse the point.
|
|
@@ -91,6 +100,28 @@ export function fieldAdd(a, b) {
|
|
|
91
100
|
// identity ephemeral, which covers a zero scalar and the subgroup order.
|
|
92
101
|
// Boris decision Nov 10: zero ephemeral rejected.
|
|
93
102
|
export async function feeLane(input) {
|
|
103
|
+
return laneOf(input, feeOf(input));
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* `lib/fee_flat.circom` FeeFlat (Z1 PRV-02 O1): F is `fee_min` of the opening, charged when `on` and the rate flag
|
|
107
|
+
* are both set. A live opening with `min != max` has no witness, and the 10% rule makes `10 F` the smallest base.
|
|
108
|
+
*/
|
|
109
|
+
export function flatFeeOf({ on, base, bps, min, max }) {
|
|
110
|
+
assertU64("base", base);
|
|
111
|
+
assertU64("fee_min", min);
|
|
112
|
+
assertU64("fee_max", max);
|
|
113
|
+
if (bps < 0n || bps > MAX_FEE_BPS)
|
|
114
|
+
throw new Error("fee_bps is above 1000");
|
|
115
|
+
const live = on && bps !== 0n;
|
|
116
|
+
if (live && min !== max)
|
|
117
|
+
throw new Error("refused: a live hidden fee needs fee_min == fee_max");
|
|
118
|
+
const fee = live ? min : 0n;
|
|
119
|
+
return { q: 0n, r: 0n, fee, cap: fee, lo: fee };
|
|
120
|
+
}
|
|
121
|
+
export async function flatFeeLane(input) {
|
|
122
|
+
return laneOf(input, flatFeeOf({ ...input, on: input.on ?? true }));
|
|
123
|
+
}
|
|
124
|
+
async function laneOf(input, math) {
|
|
94
125
|
assertField("eph", input.eph);
|
|
95
126
|
if (input.eph === 0n)
|
|
96
127
|
throw new Error("ephemeral is zero");
|
|
@@ -100,7 +131,6 @@ export async function feeLane(input) {
|
|
|
100
131
|
const subOrder = BigInt(curve.subOrder.toString());
|
|
101
132
|
if (input.eph % subOrder === 0n)
|
|
102
133
|
throw new Error("ephemeral is a multiple of the subgroup order");
|
|
103
|
-
const math = feeOf(input);
|
|
104
134
|
if (math.fee * BPS_DENOM > input.base * MAX_FEE_BPS)
|
|
105
135
|
throw new Error("fee is above the rate cap");
|
|
106
136
|
const pub = [curve.F.e(input.tx), curve.F.e(input.ty)];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type FeeCommitInput } from "./fees.ts";
|
|
2
|
+
import type { CircuitInput } from "./inputs.ts";
|
|
3
|
+
export declare const FUNDS_READ_KIND = 31;
|
|
4
|
+
export declare const FUNDS_LEVELS = 20;
|
|
5
|
+
/** `membership::funds_bind`: blake2b256("essey-v3/seal/funds" ‖ seal bind ‖ bcs(nonce)); lo = bytes 16..32, hi = 0..16. */
|
|
6
|
+
export declare function fundsBind(sealBind: Uint8Array, nonce: bigint): {
|
|
7
|
+
bindLo: bigint;
|
|
8
|
+
bindHi: bigint;
|
|
9
|
+
};
|
|
10
|
+
/** The floor `funds_read.circom` holds a note to: `10 * fee_min` of the opening the policy's fee commit binds. */
|
|
11
|
+
export declare const fundsFloor: (fee: Pick<FeeCommitInput, "min">) => bigint;
|
|
12
|
+
/** The largest own note at or over the floor, or null: a member without one is refused before any proof. */
|
|
13
|
+
export declare function fundsNote<N extends {
|
|
14
|
+
value: bigint;
|
|
15
|
+
}>(owned: N[], floor: bigint): N | null;
|
|
16
|
+
export type FundsReadParams = {
|
|
17
|
+
note: {
|
|
18
|
+
amount: bigint;
|
|
19
|
+
sk: bigint;
|
|
20
|
+
blinding: bigint;
|
|
21
|
+
index: number;
|
|
22
|
+
};
|
|
23
|
+
path: bigint[];
|
|
24
|
+
root: bigint;
|
|
25
|
+
fee: FeeCommitInput;
|
|
26
|
+
sealBind: Uint8Array;
|
|
27
|
+
nonce: bigint;
|
|
28
|
+
};
|
|
29
|
+
/** Witness for `circuits/v3/funds_read/funds_read.circom` (freeze §3.9). Publics: root, fee_commit, bindLo, bindHi. */
|
|
30
|
+
export declare function fundsRead(p: FundsReadParams): {
|
|
31
|
+
input: CircuitInput;
|
|
32
|
+
publics: bigint[];
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=funds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funds.d.ts","sourceRoot":"","sources":["../../src/v3/funds.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,YAAY,KAAK,CAAC;AAS/B,2HAA2H;AAC3H,wBAAgB,SAAS,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAIjG;AAED,kHAAkH;AAClH,eAAO,MAAM,UAAU,GAAI,KAAK,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,WAAkB,CAAC;AAE9E,4GAA4G;AAC5G,wBAAgB,SAAS,CAAC,CAAC,SAAS;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAG1F;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,cAAc,CAAC;IACpB,QAAQ,EAAE,UAAU,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,uHAAuH;AACvH,wBAAgB,SAAS,CAAC,CAAC,EAAE,eAAe,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAgCxF"}
|
package/dist/v3/funds.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { blake2b } from "@noble/hashes/blake2.js";
|
|
2
|
+
import { poseidonHash } from "@mysten/sui/zklogin";
|
|
3
|
+
import { feeCommit } from "./fees.js";
|
|
4
|
+
import { noteCommitment, notePk } from "./notes/keys.js";
|
|
5
|
+
export const FUNDS_READ_KIND = 31;
|
|
6
|
+
export const FUNDS_LEVELS = 20;
|
|
7
|
+
const SEAL_FUNDS = new TextEncoder().encode("essey-v3/seal/funds");
|
|
8
|
+
const beNum = (b) => BigInt(`0x${Buffer.from(b).toString("hex")}`);
|
|
9
|
+
function u256le(x) {
|
|
10
|
+
return Uint8Array.from({ length: 32 }, (_, i) => Number((x >> BigInt(8 * i)) & 0xffn));
|
|
11
|
+
}
|
|
12
|
+
/** `membership::funds_bind`: blake2b256("essey-v3/seal/funds" ‖ seal bind ‖ bcs(nonce)); lo = bytes 16..32, hi = 0..16. */
|
|
13
|
+
export function fundsBind(sealBind, nonce) {
|
|
14
|
+
if (sealBind.length !== 32)
|
|
15
|
+
throw new Error("the seal bind is not 32 bytes");
|
|
16
|
+
const d = blake2b(Uint8Array.from([...SEAL_FUNDS, ...sealBind, ...u256le(nonce)]), { dkLen: 32 });
|
|
17
|
+
return { bindLo: beNum(d.subarray(16, 32)), bindHi: beNum(d.subarray(0, 16)) };
|
|
18
|
+
}
|
|
19
|
+
/** The floor `funds_read.circom` holds a note to: `10 * fee_min` of the opening the policy's fee commit binds. */
|
|
20
|
+
export const fundsFloor = (fee) => 10n * fee.min;
|
|
21
|
+
/** The largest own note at or over the floor, or null: a member without one is refused before any proof. */
|
|
22
|
+
export function fundsNote(owned, floor) {
|
|
23
|
+
const fit = owned.filter((n) => n.value > 0n && n.value >= floor);
|
|
24
|
+
return fit.reduce((best, n) => (best === null || n.value > best.value ? n : best), null);
|
|
25
|
+
}
|
|
26
|
+
/** Witness for `circuits/v3/funds_read/funds_read.circom` (freeze §3.9). Publics: root, fee_commit, bindLo, bindHi. */
|
|
27
|
+
export function fundsRead(p) {
|
|
28
|
+
if (p.path.length !== FUNDS_LEVELS)
|
|
29
|
+
throw new Error("the path is not 20 levels");
|
|
30
|
+
if (p.note.amount === 0n)
|
|
31
|
+
throw new Error("refused: a zero note proves no funds");
|
|
32
|
+
if (p.note.amount < fundsFloor(p.fee))
|
|
33
|
+
throw new Error("refused: no note of at least 10 F in this coin");
|
|
34
|
+
const commit = feeCommit(p.fee);
|
|
35
|
+
const { bindLo, bindHi } = fundsBind(p.sealBind, p.nonce);
|
|
36
|
+
const leaf = noteCommitment(p.note.amount, notePk(p.note.sk), p.note.blinding);
|
|
37
|
+
const top = p.path.reduce((node, sib, k) => ((p.note.index >> k) & 1 ? poseidonHash([sib, node]) : poseidonHash([node, sib])), leaf);
|
|
38
|
+
if (top !== p.root)
|
|
39
|
+
throw new Error("the note is not under the root");
|
|
40
|
+
const input = {
|
|
41
|
+
root: p.root.toString(),
|
|
42
|
+
fee_commit: commit.toString(),
|
|
43
|
+
bindLo: bindLo.toString(),
|
|
44
|
+
bindHi: bindHi.toString(),
|
|
45
|
+
amount: p.note.amount.toString(),
|
|
46
|
+
sk: p.note.sk.toString(),
|
|
47
|
+
blinding: p.note.blinding.toString(),
|
|
48
|
+
pathIndices: p.note.index.toString(),
|
|
49
|
+
pathElements: p.path.map(String),
|
|
50
|
+
fee_bps: p.fee.bps.toString(),
|
|
51
|
+
fee_min: p.fee.min.toString(),
|
|
52
|
+
fee_max: p.fee.max.toString(),
|
|
53
|
+
fee_pk: p.fee.pk.toString(),
|
|
54
|
+
tX: p.fee.tx.toString(),
|
|
55
|
+
tY: p.fee.ty.toString(),
|
|
56
|
+
fee_salt: p.fee.salt.toString(),
|
|
57
|
+
cfg_version: p.fee.version.toString(),
|
|
58
|
+
};
|
|
59
|
+
return { input, publics: [p.root, commit, bindLo, bindHi] };
|
|
60
|
+
}
|