@avow-finance/spec 0.6.0 → 0.8.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/agent-connect.d.ts +11 -3
- package/dist/agent-connect.d.ts.map +1 -1
- package/dist/agent-connect.js +4 -4
- package/dist/agent-connect.js.map +1 -1
- package/dist/agent-session.d.ts +10 -0
- package/dist/agent-session.d.ts.map +1 -1
- package/dist/api.d.ts +607 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +109 -77
- package/dist/api.js.map +1 -1
- package/dist/dependencies.d.ts.map +1 -1
- package/dist/dependencies.js +8 -2
- package/dist/dependencies.js.map +1 -1
- package/dist/eip712.d.ts +429 -16
- package/dist/eip712.d.ts.map +1 -1
- package/dist/eip712.js +97 -27
- package/dist/eip712.js.map +1 -1
- package/dist/gpu-reservation.d.ts.map +1 -1
- package/dist/gpu-reservation.js +1 -1
- package/dist/gpu-reservation.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/job-session.d.ts +20 -0
- package/dist/job-session.d.ts.map +1 -1
- package/dist/job.d.ts.map +1 -1
- package/dist/job.js +1 -1
- package/dist/job.js.map +1 -1
- package/dist/json-fields.d.ts +2 -0
- package/dist/json-fields.d.ts.map +1 -1
- package/dist/json-fields.js +2 -0
- package/dist/json-fields.js.map +1 -1
- package/dist/mailbox.d.ts +77 -104
- package/dist/mailbox.d.ts.map +1 -1
- package/dist/mailbox.js +8 -30
- package/dist/mailbox.js.map +1 -1
- package/dist/mandate-chain.d.ts +58 -0
- package/dist/mandate-chain.d.ts.map +1 -0
- package/dist/mandate-chain.js +79 -0
- package/dist/mandate-chain.js.map +1 -0
- package/dist/mandate-proof.d.ts +8 -4
- package/dist/mandate-proof.d.ts.map +1 -1
- package/dist/mandate-proof.js +16 -3
- package/dist/mandate-proof.js.map +1 -1
- package/dist/negotiation.d.ts +514 -0
- package/dist/negotiation.d.ts.map +1 -0
- package/dist/negotiation.js +490 -0
- package/dist/negotiation.js.map +1 -0
- package/dist/offer-search.d.ts +282 -0
- package/dist/offer-search.d.ts.map +1 -0
- package/dist/offer-search.js +252 -0
- package/dist/offer-search.js.map +1 -0
- package/dist/openapi.d.ts +47 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +571 -0
- package/dist/openapi.js.map +1 -0
- package/dist/order-wire.d.ts +73 -0
- package/dist/order-wire.d.ts.map +1 -0
- package/dist/order-wire.js +33 -0
- package/dist/order-wire.js.map +1 -0
- package/dist/reasons.d.ts +12 -2
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +12 -2
- package/dist/reasons.js.map +1 -1
- package/dist/sandbox.d.ts +104 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +25 -0
- package/dist/sandbox.js.map +1 -1
- package/dist/service-order.d.ts +747 -0
- package/dist/service-order.d.ts.map +1 -0
- package/dist/service-order.js +182 -0
- package/dist/service-order.js.map +1 -0
- package/dist/service.d.ts +248 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +379 -0
- package/dist/service.js.map +1 -0
- package/dist/session-fields.d.ts +10 -0
- package/dist/session-fields.d.ts.map +1 -1
- package/dist/terms.d.ts +7 -4
- package/dist/terms.d.ts.map +1 -1
- package/dist/terms.js +12 -5
- package/dist/terms.js.map +1 -1
- package/dist/test-customer.d.ts +20 -0
- package/dist/test-customer.d.ts.map +1 -1
- package/dist/text.d.ts +5 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +5 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +24 -5
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -3
- package/dist/types.js.map +1 -1
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +9 -1
- package/dist/version.js.map +1 -1
- package/dist/wire.d.ts +313 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +29 -1
- package/dist/wire.js.map +1 -1
- package/package.json +1 -1
package/dist/service.js
ADDED
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { encodeAbiParameters, keccak256 } from 'viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { canonicalJson } from './canonical.js';
|
|
4
|
+
import { u64, u256 } from './json-fields.js';
|
|
5
|
+
import { isFilled } from './text.js';
|
|
6
|
+
import { AMOUNT_DECIMALS, CURRENCIES, TERMS_VERSION, } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* A service sold by quantity at a fixed price per unit, delivered by a deadline. Version 1 takes
|
|
9
|
+
* one-off services only. Subscriptions, usage billing and physical shipping aren't services under
|
|
10
|
+
* it, and a supplier that sells them doesn't list them. Its meaning is fixed, and a change of
|
|
11
|
+
* meaning would be `service/2`.
|
|
12
|
+
*
|
|
13
|
+
* The terms book one version of a supplier's offer, which `serviceOfferTerms` turns into terms,
|
|
14
|
+
* and `serviceTermsMatchOffer` says whether terms are exactly the ones that version gives. The
|
|
15
|
+
* buyer's reserve backs only what the buyer owes if it cancels late or isn't there to take
|
|
16
|
+
* delivery. The price is the consideration, which the lock never reads. It's paid by the route and
|
|
17
|
+
* deadline the terms name, and the reserve doesn't secure it.
|
|
18
|
+
*/
|
|
19
|
+
export const SERVICE = 'service/1';
|
|
20
|
+
/**
|
|
21
|
+
* The mandate category every service booking falls under. A mandate allows services by naming
|
|
22
|
+
* it, and service terms under any other category are refused as `terms.category_mismatch`.
|
|
23
|
+
*/
|
|
24
|
+
export const SERVICE_CATEGORY = 'service';
|
|
25
|
+
/** The unit a service's price is charged per, one of the quantity the terms name. */
|
|
26
|
+
export const SERVICE_UNIT = 'unit';
|
|
27
|
+
/** The longest item name a service names. */
|
|
28
|
+
export const SERVICE_NAME_MAX = 120;
|
|
29
|
+
/** The longest summary, or description of delivery evidence, a service names. */
|
|
30
|
+
export const SERVICE_TEXT_MAX = 280;
|
|
31
|
+
/** The most units one booking of a service can take. */
|
|
32
|
+
export const SERVICE_QUANTITY_MAX = 1_000_000;
|
|
33
|
+
/** The longest a supplier's business id is in an offer. */
|
|
34
|
+
const SUPPLIER_ID_MAX = 100;
|
|
35
|
+
/**
|
|
36
|
+
* How the buyer pays the price, which the lock never reads. `transfer` is a transfer of the
|
|
37
|
+
* terms' currency to the supplier's payee on the commitment's chain. `invoice` is the supplier
|
|
38
|
+
* billing by its own means, which nothing on chain shows.
|
|
39
|
+
*/
|
|
40
|
+
export const PAYMENT_ROUTES = ['transfer', 'invoice'];
|
|
41
|
+
const isPaymentRoute = (v) => PAYMENT_ROUTES.includes(v);
|
|
42
|
+
/** The whole price of a number of units at a unit price, the one rule terms and quotes share. */
|
|
43
|
+
const totalOf = (unitPrice, quantity) => unitPrice * BigInt(quantity);
|
|
44
|
+
/** The reserve a service booking takes, its larger charge, the one rule terms and quotes share. */
|
|
45
|
+
const reserveOf = (lateCancellation, noShow) => lateCancellation > noShow ? lateCancellation : noShow;
|
|
46
|
+
/**
|
|
47
|
+
* Builds service terms. A late cancellation can be charged from the free-cancellation deadline and
|
|
48
|
+
* a no-show from the delivery deadline. A charge set to zero is left out, and the reserve is the
|
|
49
|
+
* largest charge.
|
|
50
|
+
*/
|
|
51
|
+
export function serviceTerms(input) {
|
|
52
|
+
const charges = [];
|
|
53
|
+
if (input.lateCancellation > 0n) {
|
|
54
|
+
charges.push({
|
|
55
|
+
kind: 'lateCancellation',
|
|
56
|
+
amount: input.lateCancellation,
|
|
57
|
+
earliest: input.freeCancelBy,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (input.noShow > 0n) {
|
|
61
|
+
charges.push({ kind: 'noShow', amount: input.noShow, earliest: input.deliverBy });
|
|
62
|
+
}
|
|
63
|
+
const reserve = reserveOf(input.lateCancellation, input.noShow);
|
|
64
|
+
return {
|
|
65
|
+
version: TERMS_VERSION,
|
|
66
|
+
template: SERVICE,
|
|
67
|
+
currency: input.currency,
|
|
68
|
+
amountDecimals: AMOUNT_DECIMALS,
|
|
69
|
+
subject: {
|
|
70
|
+
offer: input.offer,
|
|
71
|
+
item: { ...input.item },
|
|
72
|
+
quantity: input.quantity,
|
|
73
|
+
delivery: { by: input.deliverBy, evidence: input.evidence },
|
|
74
|
+
payment: { ...input.payment },
|
|
75
|
+
},
|
|
76
|
+
consideration: { kind: 'rate', amount: input.unitPrice, unit: SERVICE_UNIT },
|
|
77
|
+
remedies: {
|
|
78
|
+
acceptBy: input.acceptBy,
|
|
79
|
+
freeCancelBy: input.freeCancelBy,
|
|
80
|
+
charges,
|
|
81
|
+
chargeDeadline: input.chargeDeadline,
|
|
82
|
+
},
|
|
83
|
+
resolution: {
|
|
84
|
+
contestWindow: input.contestWindow,
|
|
85
|
+
arbiter: input.arbiter,
|
|
86
|
+
day90SupplierShareBps: input.day90SupplierShareBps,
|
|
87
|
+
},
|
|
88
|
+
backing: { kind: 'reserve', side: 'buyer', amount: reserve, releaseDate: input.releaseDate },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** A 32-byte id in lower-case hex, so the same offer never hashes two ways. */
|
|
92
|
+
const OFFER_ID = /^0x[0-9a-f]{64}$/;
|
|
93
|
+
/**
|
|
94
|
+
* What's wrong with a service's subject on its own, or null when nothing is. The offer is a
|
|
95
|
+
* lower-case 32-byte id, the item has a name and a summary of bounded length, the quantity is a
|
|
96
|
+
* whole number of units from 1 up, delivery names its evidence and a deadline, and payment names a
|
|
97
|
+
* route this version knows and a deadline (`terms.template_invalid`). A subject of any other shape
|
|
98
|
+
* is refused here, so nothing that reads it after this throws.
|
|
99
|
+
*/
|
|
100
|
+
export function serviceSubjectProblem(s) {
|
|
101
|
+
if (typeof s !== 'object' || s === null)
|
|
102
|
+
return 'terms.template_invalid';
|
|
103
|
+
if (typeof s.offer !== 'string' || !OFFER_ID.test(s.offer))
|
|
104
|
+
return 'terms.template_invalid';
|
|
105
|
+
const item = s.item;
|
|
106
|
+
const delivery = s.delivery;
|
|
107
|
+
const payment = s.payment;
|
|
108
|
+
if (typeof item !== 'object' || item === null)
|
|
109
|
+
return 'terms.template_invalid';
|
|
110
|
+
if (!isFilled(item.name, SERVICE_NAME_MAX) || !isFilled(item.summary, SERVICE_TEXT_MAX)) {
|
|
111
|
+
return 'terms.template_invalid';
|
|
112
|
+
}
|
|
113
|
+
if (!Number.isSafeInteger(s.quantity) || s.quantity < 1 || s.quantity > SERVICE_QUANTITY_MAX) {
|
|
114
|
+
return 'terms.template_invalid';
|
|
115
|
+
}
|
|
116
|
+
if (typeof delivery !== 'object' || delivery === null)
|
|
117
|
+
return 'terms.template_invalid';
|
|
118
|
+
if (typeof delivery.by !== 'bigint' || !isFilled(delivery.evidence, SERVICE_TEXT_MAX)) {
|
|
119
|
+
return 'terms.template_invalid';
|
|
120
|
+
}
|
|
121
|
+
if (typeof payment !== 'object' || payment === null)
|
|
122
|
+
return 'terms.template_invalid';
|
|
123
|
+
if (!isPaymentRoute(payment.route) || typeof payment.dueBy !== 'bigint') {
|
|
124
|
+
return 'terms.template_invalid';
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The template's own rules, which a reader checks after the core's. The subject passes
|
|
130
|
+
* `serviceSubjectProblem`, and the consideration is a price above zero per unit. The supplier
|
|
131
|
+
* accepts and free cancellation ends by the delivery deadline, which falls by the charge deadline,
|
|
132
|
+
* and payment is due at or after delivery. A late cancellation is chargeable from the
|
|
133
|
+
* free-cancellation deadline, and a no-show from the delivery deadline or later. No other charge
|
|
134
|
+
* applies to a service.
|
|
135
|
+
*/
|
|
136
|
+
export function validateService(t) {
|
|
137
|
+
const { subject: s, remedies: r, consideration: c } = t;
|
|
138
|
+
const subject = serviceSubjectProblem(s);
|
|
139
|
+
if (subject)
|
|
140
|
+
return subject;
|
|
141
|
+
if (c.kind !== 'rate' || c.unit !== SERVICE_UNIT || c.amount <= 0n) {
|
|
142
|
+
return 'terms.template_invalid';
|
|
143
|
+
}
|
|
144
|
+
const by = s.delivery.by;
|
|
145
|
+
if (r.acceptBy > by || r.freeCancelBy > by || by > r.chargeDeadline) {
|
|
146
|
+
return 'terms.deadlines_out_of_order';
|
|
147
|
+
}
|
|
148
|
+
if (s.payment.dueBy < by)
|
|
149
|
+
return 'terms.deadlines_out_of_order';
|
|
150
|
+
for (const charge of r.charges) {
|
|
151
|
+
if (charge.kind === 'lateCancellation') {
|
|
152
|
+
if (charge.earliest !== r.freeCancelBy)
|
|
153
|
+
return 'terms.template_invalid';
|
|
154
|
+
}
|
|
155
|
+
else if (charge.kind === 'noShow') {
|
|
156
|
+
if (charge.earliest < by)
|
|
157
|
+
return 'terms.deadlines_out_of_order';
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
return 'terms.template_invalid';
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
/** What a service's price comes to for the quantity booked, in micros. */
|
|
166
|
+
export const servicePrice = (t) => totalOf(t.consideration.amount, t.subject.quantity);
|
|
167
|
+
/** How long a supplier has to accept a service booking, in seconds. */
|
|
168
|
+
export const SERVICE_ACCEPT_WITHIN = 15n * 60n;
|
|
169
|
+
/** How long after the delivery deadline a supplier can report a charge, in seconds. */
|
|
170
|
+
export const SERVICE_CHARGE_AFTER = 24n * 60n * 60n;
|
|
171
|
+
/** The contest window of a service booking on the testnet, in seconds, as for compute. */
|
|
172
|
+
const SERVICE_CONTEST_WINDOW = 10n * 60n;
|
|
173
|
+
const whole = (n, max) => Number.isSafeInteger(n) && n >= 1 && n <= max;
|
|
174
|
+
const share = (bps) => Number.isSafeInteger(bps) && bps >= 0 && bps <= 10_000;
|
|
175
|
+
/**
|
|
176
|
+
* What's wrong with an offer version, in words for the person setting it, or null when nothing
|
|
177
|
+
* is. The supplier and item are named, the price is above zero, the lead time leaves the supplier
|
|
178
|
+
* its time to accept, free cancellation is off or outlasts that time and ends by delivery, a
|
|
179
|
+
* booking takes 1 to `SERVICE_QUANTITY_MAX` units, capacity is at least one booking a day, each
|
|
180
|
+
* charge is a share from 0 to 100%, and at least one is above zero, since a reserve with nothing to
|
|
181
|
+
* charge backs nothing. Every field has its declared type, so a version that passes hashes one way
|
|
182
|
+
* only.
|
|
183
|
+
*/
|
|
184
|
+
export function serviceOfferProblem(v) {
|
|
185
|
+
if (!isFilled(v.supplier, SUPPLIER_ID_MAX))
|
|
186
|
+
return "Name the supplier's business.";
|
|
187
|
+
if (!isFilled(v.item?.name, SERVICE_NAME_MAX)) {
|
|
188
|
+
return `Name the item in 1 to ${SERVICE_NAME_MAX} characters.`;
|
|
189
|
+
}
|
|
190
|
+
if (!isFilled(v.item?.summary, SERVICE_TEXT_MAX)) {
|
|
191
|
+
return `Say what the item is in 1 to ${SERVICE_TEXT_MAX} characters.`;
|
|
192
|
+
}
|
|
193
|
+
if (!CURRENCIES.includes(v.currency))
|
|
194
|
+
return 'Choose a currency.';
|
|
195
|
+
if (typeof v.unitPrice !== 'bigint' || v.unitPrice <= 0n) {
|
|
196
|
+
return 'The price has to be more than zero.';
|
|
197
|
+
}
|
|
198
|
+
const r = v.rules;
|
|
199
|
+
if (typeof r !== 'object' || r === null)
|
|
200
|
+
return 'Set the rules for booking.';
|
|
201
|
+
if (!isFilled(r.evidence, SERVICE_TEXT_MAX))
|
|
202
|
+
return 'Say what counts as delivery.';
|
|
203
|
+
if (typeof r.leadTime !== 'bigint' || r.leadTime < SERVICE_ACCEPT_WITHIN) {
|
|
204
|
+
return 'The lead time has to be at least 15 minutes, so you have time to accept.';
|
|
205
|
+
}
|
|
206
|
+
if (typeof r.freeCancelWindow !== 'bigint' ||
|
|
207
|
+
(r.freeCancelWindow !== 0n &&
|
|
208
|
+
(r.freeCancelWindow < SERVICE_ACCEPT_WITHIN || r.freeCancelWindow > r.leadTime))) {
|
|
209
|
+
return 'Free cancellation is off, or lasts from 15 minutes to the lead time.';
|
|
210
|
+
}
|
|
211
|
+
if (!whole(r.maxPerBooking, SERVICE_QUANTITY_MAX)) {
|
|
212
|
+
return `A booking takes from 1 to ${SERVICE_QUANTITY_MAX} units.`;
|
|
213
|
+
}
|
|
214
|
+
if (!whole(r.dailyCapacity, SERVICE_QUANTITY_MAX)) {
|
|
215
|
+
return 'Capacity is at least one booking a day.';
|
|
216
|
+
}
|
|
217
|
+
if (!share(r.lateCancellationBps) || !share(r.noShowBps)) {
|
|
218
|
+
return 'A charge is a share of the price from 0 to 100%.';
|
|
219
|
+
}
|
|
220
|
+
if (r.lateCancellationBps === 0 && r.noShowBps === 0) {
|
|
221
|
+
return 'Set a late-cancellation or no-show charge, or the reserve backs nothing.';
|
|
222
|
+
}
|
|
223
|
+
if (typeof r.payment !== 'object' || r.payment === null || !isPaymentRoute(r.payment.route)) {
|
|
224
|
+
return 'Choose how the buyer pays.';
|
|
225
|
+
}
|
|
226
|
+
if (typeof r.payment.dueAfterDelivery !== 'bigint' || r.payment.dueAfterDelivery < 0n) {
|
|
227
|
+
return 'Payment is due at or after delivery.';
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
const text = (max) => z.string().min(1).max(max);
|
|
232
|
+
/** An offer version as JSON, with amounts and times as decimal strings and nothing else in it. */
|
|
233
|
+
export const serviceOfferVersionJson = z.strictObject({
|
|
234
|
+
supplier: text(SUPPLIER_ID_MAX),
|
|
235
|
+
item: z.strictObject({ name: text(SERVICE_NAME_MAX), summary: text(SERVICE_TEXT_MAX) }),
|
|
236
|
+
currency: z.enum(CURRENCIES),
|
|
237
|
+
unitPrice: u256,
|
|
238
|
+
rules: z.strictObject({
|
|
239
|
+
evidence: text(SERVICE_TEXT_MAX),
|
|
240
|
+
leadTime: u64,
|
|
241
|
+
maxPerBooking: z.number().int(),
|
|
242
|
+
dailyCapacity: z.number().int(),
|
|
243
|
+
freeCancelWindow: u64,
|
|
244
|
+
lateCancellationBps: z.number().int(),
|
|
245
|
+
noShowBps: z.number().int(),
|
|
246
|
+
payment: z.strictObject({ route: z.enum(PAYMENT_ROUTES), dueAfterDelivery: u64 }),
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
/** Reads an offer version from JSON, refusing one `serviceOfferProblem` finds anything wrong with. */
|
|
250
|
+
export function parseServiceOfferVersion(json) {
|
|
251
|
+
const parsed = serviceOfferVersionJson.safeParse(json);
|
|
252
|
+
if (!parsed.success)
|
|
253
|
+
return { ok: false, reason: 'message.invalid' };
|
|
254
|
+
const version = parsed.data;
|
|
255
|
+
return serviceOfferProblem(version) === null
|
|
256
|
+
? { ok: true, value: version }
|
|
257
|
+
: { ok: false, reason: 'message.invalid' };
|
|
258
|
+
}
|
|
259
|
+
/** The label an offer version's id is hashed under, so it can't be read as any other hash. */
|
|
260
|
+
const OFFER_VERSION_LABEL = 'avow:offer:service/1';
|
|
261
|
+
/**
|
|
262
|
+
* An offer version's id: keccak256 of the ABI encoding of `avow:offer:service/1` and the
|
|
263
|
+
* version's canonical JSON as a string. It hashes exactly the fields a version has, so the same
|
|
264
|
+
* version always has the same id, and it throws for a version `serviceOfferProblem` refuses rather
|
|
265
|
+
* than give one an id.
|
|
266
|
+
*/
|
|
267
|
+
export function offerVersionId(version) {
|
|
268
|
+
const problem = serviceOfferProblem(version);
|
|
269
|
+
if (problem)
|
|
270
|
+
throw new RangeError(problem);
|
|
271
|
+
const { supplier, item, currency, unitPrice, rules: r } = version;
|
|
272
|
+
const hashed = {
|
|
273
|
+
supplier,
|
|
274
|
+
item: { name: item.name, summary: item.summary },
|
|
275
|
+
currency,
|
|
276
|
+
unitPrice,
|
|
277
|
+
rules: {
|
|
278
|
+
evidence: r.evidence,
|
|
279
|
+
leadTime: r.leadTime,
|
|
280
|
+
maxPerBooking: r.maxPerBooking,
|
|
281
|
+
dailyCapacity: r.dailyCapacity,
|
|
282
|
+
freeCancelWindow: r.freeCancelWindow,
|
|
283
|
+
lateCancellationBps: r.lateCancellationBps,
|
|
284
|
+
noShowBps: r.noShowBps,
|
|
285
|
+
payment: { route: r.payment.route, dueAfterDelivery: r.payment.dueAfterDelivery },
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
return keccak256(encodeAbiParameters([{ type: 'string' }, { type: 'string' }], [OFFER_VERSION_LABEL, canonicalJson(hashed)]));
|
|
289
|
+
}
|
|
290
|
+
const BPS = 10000n;
|
|
291
|
+
/**
|
|
292
|
+
* What booking `quantity` units of an offer version costs. A search prices an offer with it and
|
|
293
|
+
* `serviceOfferTerms` builds terms from it, so the price an agent is shown is the price it books.
|
|
294
|
+
* Throws for a version `serviceOfferProblem` refuses, a quantity the version doesn't take, or a
|
|
295
|
+
* price so small that every charge rounds to zero.
|
|
296
|
+
*/
|
|
297
|
+
export function serviceOfferQuote(version, quantity) {
|
|
298
|
+
const problem = serviceOfferProblem(version);
|
|
299
|
+
if (problem)
|
|
300
|
+
throw new RangeError(problem);
|
|
301
|
+
const { rules } = version;
|
|
302
|
+
if (!whole(quantity, rules.maxPerBooking)) {
|
|
303
|
+
throw new RangeError(`The offer takes 1 to ${rules.maxPerBooking} units a booking`);
|
|
304
|
+
}
|
|
305
|
+
const total = totalOf(version.unitPrice, quantity);
|
|
306
|
+
const lateCancellation = (total * BigInt(rules.lateCancellationBps)) / BPS;
|
|
307
|
+
const noShow = (total * BigInt(rules.noShowBps)) / BPS;
|
|
308
|
+
if (lateCancellation === 0n && noShow === 0n) {
|
|
309
|
+
throw new RangeError('At this price and quantity every charge rounds to zero');
|
|
310
|
+
}
|
|
311
|
+
return { total, lateCancellation, noShow, reserve: reserveOf(lateCancellation, noShow) };
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* The service terms for booking `quantity` units of an offer version at `now`. Delivery is due the
|
|
315
|
+
* lead time after `now`, free cancellation lasts the version's window from `now`, and the supplier
|
|
316
|
+
* accepts within `SERVICE_ACCEPT_WITHIN`. A late cancellation and a no-show cost their shares of the
|
|
317
|
+
* whole price, charges can be reported until `SERVICE_CHARGE_AFTER` past the delivery deadline,
|
|
318
|
+
* when the reserve comes back, and the contest window is ten minutes. Payment is due the version's
|
|
319
|
+
* interval after the delivery deadline. The arbiter and the day-90 share are the deployment's,
|
|
320
|
+
* which Avow's approvals name. Throws for a version `serviceOfferProblem` refuses, a quantity the
|
|
321
|
+
* version doesn't take, or a price so small that every charge rounds to zero.
|
|
322
|
+
*/
|
|
323
|
+
export function serviceOfferTerms(version, quantity, now, settlement) {
|
|
324
|
+
const offer = offerVersionId(version);
|
|
325
|
+
const { rules } = version;
|
|
326
|
+
const { lateCancellation, noShow } = serviceOfferQuote(version, quantity);
|
|
327
|
+
const deliverBy = now + rules.leadTime;
|
|
328
|
+
const chargeDeadline = deliverBy + SERVICE_CHARGE_AFTER;
|
|
329
|
+
const terms = serviceTerms({
|
|
330
|
+
offer,
|
|
331
|
+
item: version.item,
|
|
332
|
+
quantity,
|
|
333
|
+
currency: version.currency,
|
|
334
|
+
unitPrice: version.unitPrice,
|
|
335
|
+
deliverBy,
|
|
336
|
+
evidence: rules.evidence,
|
|
337
|
+
payment: { route: rules.payment.route, dueBy: deliverBy + rules.payment.dueAfterDelivery },
|
|
338
|
+
acceptBy: now + SERVICE_ACCEPT_WITHIN,
|
|
339
|
+
freeCancelBy: now + rules.freeCancelWindow,
|
|
340
|
+
lateCancellation,
|
|
341
|
+
noShow,
|
|
342
|
+
chargeDeadline,
|
|
343
|
+
contestWindow: SERVICE_CONTEST_WINDOW,
|
|
344
|
+
releaseDate: chargeDeadline,
|
|
345
|
+
arbiter: settlement.arbiter,
|
|
346
|
+
day90SupplierShareBps: settlement.day90SupplierShareBps,
|
|
347
|
+
});
|
|
348
|
+
// The version passed every rule above, so its terms pass the template's.
|
|
349
|
+
const problem = validateService(terms);
|
|
350
|
+
if (problem)
|
|
351
|
+
throw new Error(`The offer built terms its template refuses, ${problem}`);
|
|
352
|
+
return terms;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Whether service terms are exactly the ones `serviceOfferTerms` builds from this version for
|
|
356
|
+
* their quantity, at the moment their delivery deadline implies, under their own arbiter and
|
|
357
|
+
* day-90 share. A booking that passes names the version's id and carries its item, price,
|
|
358
|
+
* evidence, payment, deadlines and charges unchanged, so a supplier or Avow can tell the price a
|
|
359
|
+
* buyer signed is the version's price.
|
|
360
|
+
*/
|
|
361
|
+
export function serviceTermsMatchOffer(terms, version) {
|
|
362
|
+
if (serviceOfferProblem(version) !== null || serviceSubjectProblem(terms.subject) !== null) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
if (terms.subject.offer !== offerVersionId(version))
|
|
366
|
+
return false;
|
|
367
|
+
let expected;
|
|
368
|
+
try {
|
|
369
|
+
expected = serviceOfferTerms(version, terms.subject.quantity, terms.subject.delivery.by - version.rules.leadTime, {
|
|
370
|
+
arbiter: terms.resolution.arbiter,
|
|
371
|
+
day90SupplierShareBps: terms.resolution.day90SupplierShareBps,
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
return canonicalJson(expected) === canonicalJson(terms);
|
|
378
|
+
}
|
|
379
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,mBAAmB,EAAY,SAAS,EAAE,MAAM,MAAM,CAAA;AAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EACL,eAAe,EACf,UAAU,EAGV,aAAa,GAEd,MAAM,YAAY,CAAA;AAGnB;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,WAAoB,CAAA;AAE3C;;;GAGG;AACH,MAAM,CAA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,CAAC,qBAAqB;SAC9D,CACF,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,aAAa,CAAC,QAAQ,CAAC,KAAK,aAAa,CAAC,KAAK,CAAC,CAAA;AACzD,CAAC"}
|
package/dist/session-fields.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export declare const reasonCodeJson: z.ZodEnum<{
|
|
|
58
58
|
"business.test_data": "business.test_data";
|
|
59
59
|
"business.unknown": "business.unknown";
|
|
60
60
|
"business.unverified": "business.unverified";
|
|
61
|
+
"capacity.exhausted": "capacity.exhausted";
|
|
61
62
|
"chain.acceptance_reverted": "chain.acceptance_reverted";
|
|
62
63
|
"chain.agent_key_inactive": "chain.agent_key_inactive";
|
|
63
64
|
"chain.approval_mismatch": "chain.approval_mismatch";
|
|
@@ -84,6 +85,7 @@ export declare const reasonCodeJson: z.ZodEnum<{
|
|
|
84
85
|
"contest.statement_invalid": "contest.statement_invalid";
|
|
85
86
|
"contest.statement_mismatch": "contest.statement_mismatch";
|
|
86
87
|
"contest.window_closed": "contest.window_closed";
|
|
88
|
+
"counterparty.not_eligible": "counterparty.not_eligible";
|
|
87
89
|
"dependency.cancellable": "dependency.cancellable";
|
|
88
90
|
"dependency.charge_pending": "dependency.charge_pending";
|
|
89
91
|
"dependency.disclosure_invalid": "dependency.disclosure_invalid";
|
|
@@ -104,6 +106,7 @@ export declare const reasonCodeJson: z.ZodEnum<{
|
|
|
104
106
|
"mandate.action_not_permitted": "mandate.action_not_permitted";
|
|
105
107
|
"mandate.ap2_mismatch": "mandate.ap2_mismatch";
|
|
106
108
|
"mandate.category_not_allowed": "mandate.category_not_allowed";
|
|
109
|
+
"mandate.change_pending": "mandate.change_pending";
|
|
107
110
|
"mandate.currency_not_allowed": "mandate.currency_not_allowed";
|
|
108
111
|
"mandate.ends_before_window": "mandate.ends_before_window";
|
|
109
112
|
"mandate.expired": "mandate.expired";
|
|
@@ -112,6 +115,7 @@ export declare const reasonCodeJson: z.ZodEnum<{
|
|
|
112
115
|
"mandate.over_commitment_cap": "mandate.over_commitment_cap";
|
|
113
116
|
"mandate.over_open_reserves_cap": "mandate.over_open_reserves_cap";
|
|
114
117
|
"mandate.over_payment_limit": "mandate.over_payment_limit";
|
|
118
|
+
"mandate.replaces_mismatch": "mandate.replaces_mismatch";
|
|
115
119
|
"mandate.revoked": "mandate.revoked";
|
|
116
120
|
"mandate.signature_invalid": "mandate.signature_invalid";
|
|
117
121
|
"mandate.supplier_not_allowed": "mandate.supplier_not_allowed";
|
|
@@ -125,6 +129,9 @@ export declare const reasonCodeJson: z.ZodEnum<{
|
|
|
125
129
|
"message.validity_too_long": "message.validity_too_long";
|
|
126
130
|
"message.wrong_chain": "message.wrong_chain";
|
|
127
131
|
"message.wrong_contract": "message.wrong_contract";
|
|
132
|
+
"negotiation.rounds_exhausted": "negotiation.rounds_exhausted";
|
|
133
|
+
"offer.superseded": "offer.superseded";
|
|
134
|
+
"offer.withdrawn": "offer.withdrawn";
|
|
128
135
|
"order.commitment_mismatch": "order.commitment_mismatch";
|
|
129
136
|
"order.limit_reached": "order.limit_reached";
|
|
130
137
|
"order.out_of_step": "order.out_of_step";
|
|
@@ -142,6 +149,8 @@ export declare const reasonCodeJson: z.ZodEnum<{
|
|
|
142
149
|
"payment.sender_mismatch": "payment.sender_mismatch";
|
|
143
150
|
"payment.token_mismatch": "payment.token_mismatch";
|
|
144
151
|
"payment.token_not_accepted": "payment.token_not_accepted";
|
|
152
|
+
"proposal.unacceptable": "proposal.unacceptable";
|
|
153
|
+
"quantity.out_of_range": "quantity.out_of_range";
|
|
145
154
|
"reference.commitment_mismatch": "reference.commitment_mismatch";
|
|
146
155
|
"reference.unreadable": "reference.unreadable";
|
|
147
156
|
"report.amount_invalid": "report.amount_invalid";
|
|
@@ -195,6 +204,7 @@ export declare const reasonCodeJson: z.ZodEnum<{
|
|
|
195
204
|
"terms.hash_mismatch": "terms.hash_mismatch";
|
|
196
205
|
"terms.incomplete": "terms.incomplete";
|
|
197
206
|
"terms.invalid": "terms.invalid";
|
|
207
|
+
"terms.not_negotiable": "terms.not_negotiable";
|
|
198
208
|
"terms.reserve_mismatch": "terms.reserve_mismatch";
|
|
199
209
|
"terms.template_invalid": "terms.template_invalid";
|
|
200
210
|
"terms.template_unknown": "terms.template_unknown";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-fields.d.ts","sourceRoot":"","sources":["../src/session-fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB;;;GAGG;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa,YAAI,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAU,CAAA;AAClE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAExD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,YACzB,SAAS,EACT,KAAK,EACL,MAAM,EACN,UAAU,EACV,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,SAAS,CACD,CAAA;AACV,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1D,mEAAmE;AACnE,eAAO,MAAM,OAAO,aAA6C,CAAA;AAEjE,eAAO,MAAM,eAAe;;;;EAAwB,CAAA;AAEpD,wCAAwC;AACxC,eAAO,MAAM,cAAc
|
|
1
|
+
{"version":3,"file":"session-fields.d.ts","sourceRoot":"","sources":["../src/session-fields.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB;;;GAGG;AAEH;;;;GAIG;AACH,eAAO,MAAM,aAAa,YAAI,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAU,CAAA;AAClE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAExD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,YACzB,SAAS,EACT,KAAK,EACL,MAAM,EACN,UAAU,EACV,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,SAAS,CACD,CAAA;AACV,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAE1D,mEAAmE;AACnE,eAAO,MAAM,OAAO,aAA6C,CAAA;AAEjE,eAAO,MAAM,eAAe;;;;EAAwB,CAAA;AAEpD,wCAAwC;AACxC,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAqE,CAAA"}
|
package/dist/terms.d.ts
CHANGED
|
@@ -331,10 +331,13 @@ export interface ApprovalMandate {
|
|
|
331
331
|
fundingKeys: readonly Address[];
|
|
332
332
|
}
|
|
333
333
|
/**
|
|
334
|
-
* Checks that an approval names the buyer's mandate,
|
|
335
|
-
*
|
|
336
|
-
* one the approval names, so other values would
|
|
337
|
-
*
|
|
334
|
+
* Checks that an approval names the buyer's mandate, its cap per commitment, an open-reserves cap
|
|
335
|
+
* no higher than the mandate's, and a funding key the caller allows. The lock enforces the caps and
|
|
336
|
+
* checks the key that funds the reserve against the one the approval names, so other values would
|
|
337
|
+
* let through a reserve the mandate doesn't allow. The open-reserves cap may be lower because the
|
|
338
|
+
* lock counts open reserves per mandate hash: after a mandate replaces another, Avow signs the new
|
|
339
|
+
* limit less what the earlier mandates still hold, so the lock holds the agent to the combined
|
|
340
|
+
* limit. Returns `approval.mandate_mismatch` when any of them differs, or null.
|
|
338
341
|
*/
|
|
339
342
|
export declare function approvalMandateProblem(approval: Pick<Approval, 'mandateHash' | 'capPerCommitment' | 'capOpenReserves' | 'fundingKey'>, expected: ApprovalMandate): ReasonCode | null;
|
|
340
343
|
export {};
|
package/dist/terms.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terms.d.ts","sourceRoot":"","sources":["../src/terms.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,OAAO,EAGZ,KAAK,GAAG,EAQT,MAAM,MAAM,CAAA;AAEb,OAAO,EAEL,KAAK,eAAe,EAGrB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAEL,KAAK,QAAQ,EAEb,KAAK,MAAM,EAEZ,MAAM,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"terms.d.ts","sourceRoot":"","sources":["../src/terms.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,OAAO,EAGZ,KAAK,GAAG,EAQT,MAAM,MAAM,CAAA;AAEb,OAAO,EAEL,KAAK,eAAe,EAGrB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAEL,KAAK,QAAQ,EAEb,KAAK,MAAM,EAEZ,MAAM,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EACL,KAAK,cAAc,EAKpB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,IAAI,EACT,KAAK,eAAe,EAEpB,aAAa,EACb,KAAK,UAAU,EACf,KAAK,KAAK,EACX,MAAM,YAAY,CAAA;AAEnB;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,c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UAAU,GAAG,gBAAgB,GAAG,OAAO,CAAC,EACjE,OAAO,EAAE,eAAe,GACvB,UAAU,GAAG,IAAI,CAMnB;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,EACjC,KAAK,EAAE,OAAO,GACb,UAAU,GAAG,IAAI,CAEnB;AAED,4DAA4D;AAC5D,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,iBAAiB,CAAC,CAAA;AAEjF;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAAC,EAC9D,QAAQ,EAAE,MAAM,GACf,YAAY,CAKd;AAED,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC9B,iDAAiD;IACjD,WAAW,EAAE,GAAG,CAAA;IAChB,yEAAyE;IACzE,IAAI,EAAE,YAAY,CAAA;IAClB,kGAAkG;IAClG,WAAW,EAAE,SAAS,OAAO,EAAE,CAAA;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,aAAa,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,YAAY,CAAC,EAC/F,QAAQ,EAAE,eAAe,GACxB,UAAU,GAAG,IAAI,CAOnB"}
|
package/dist/terms.js
CHANGED
|
@@ -7,6 +7,7 @@ import { APPROVAL_TYPES, CHARGE_KINDS, } from './eip712.js';
|
|
|
7
7
|
import { validateGpuReservation } from './gpu-reservation.js';
|
|
8
8
|
import { JOB_CATEGORY, validateJob } from './job.js';
|
|
9
9
|
import { toTokenUnits } from './rail.js';
|
|
10
|
+
import { SERVICE_CATEGORY, validateService } from './service.js';
|
|
10
11
|
import { isTermsV1, termsChargesV1, termsHashV1, validateTermsV1, } from './terms-v1.js';
|
|
11
12
|
import { AMOUNT_DECIMALS, CHAINED_TERMS_VERSION, DEPENDENCY_CHECKS_ALLOWED, TEMPLATE_IDS, TERMS_VERSION, } from './types.js';
|
|
12
13
|
/** The five sections of version 2 terms, in the order the terms hash takes their hashes. */
|
|
@@ -329,6 +330,7 @@ export function checkSectionDisclosure(d, expected) {
|
|
|
329
330
|
const TEMPLATE_RULES = {
|
|
330
331
|
'gpu-reservation/1': (t) => validateGpuReservation(t),
|
|
331
332
|
'job/1': (t) => validateJob(t),
|
|
333
|
+
'service/1': (t) => validateService(t),
|
|
332
334
|
};
|
|
333
335
|
/**
|
|
334
336
|
* The one mandate category each template's bookings fall under, or null when the request names
|
|
@@ -337,6 +339,7 @@ const TEMPLATE_RULES = {
|
|
|
337
339
|
const TEMPLATE_CATEGORIES = {
|
|
338
340
|
'gpu-reservation/1': null,
|
|
339
341
|
'job/1': JOB_CATEGORY,
|
|
342
|
+
'service/1': SERVICE_CATEGORY,
|
|
340
343
|
};
|
|
341
344
|
/**
|
|
342
345
|
* Why terms can't be booked under this mandate category, or null when they can. A template with
|
|
@@ -356,6 +359,7 @@ export function templateCategoryProblem(terms, category) {
|
|
|
356
359
|
const RELIES_ON_A_BOOKING = {
|
|
357
360
|
'gpu-reservation/1': false,
|
|
358
361
|
'job/1': true,
|
|
362
|
+
'service/1': false,
|
|
359
363
|
};
|
|
360
364
|
/** Charges come in the order of the lock's codes, at most one of each kind, each with an amount. */
|
|
361
365
|
function checkCharges(charges) {
|
|
@@ -700,15 +704,18 @@ export function approvalCaps(mandate, decimals) {
|
|
|
700
704
|
};
|
|
701
705
|
}
|
|
702
706
|
/**
|
|
703
|
-
* Checks that an approval names the buyer's mandate,
|
|
704
|
-
*
|
|
705
|
-
* one the approval names, so other values would
|
|
706
|
-
*
|
|
707
|
+
* Checks that an approval names the buyer's mandate, its cap per commitment, an open-reserves cap
|
|
708
|
+
* no higher than the mandate's, and a funding key the caller allows. The lock enforces the caps and
|
|
709
|
+
* checks the key that funds the reserve against the one the approval names, so other values would
|
|
710
|
+
* let through a reserve the mandate doesn't allow. The open-reserves cap may be lower because the
|
|
711
|
+
* lock counts open reserves per mandate hash: after a mandate replaces another, Avow signs the new
|
|
712
|
+
* limit less what the earlier mandates still hold, so the lock holds the agent to the combined
|
|
713
|
+
* limit. Returns `approval.mandate_mismatch` when any of them differs, or null.
|
|
707
714
|
*/
|
|
708
715
|
export function approvalMandateProblem(approval, expected) {
|
|
709
716
|
const named = approval.mandateHash.toLowerCase() === expected.mandateHash.toLowerCase() &&
|
|
710
717
|
approval.capPerCommitment === expected.caps.capPerCommitment &&
|
|
711
|
-
approval.capOpenReserves
|
|
718
|
+
approval.capOpenReserves <= expected.caps.capOpenReserves &&
|
|
712
719
|
expected.fundingKeys.some((k) => sameAddress(approval.fundingKey, k));
|
|
713
720
|
return named ? null : 'approval.mandate_mismatch';
|
|
714
721
|
}
|