@avow-finance/spec 0.7.0 → 0.9.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-session.d.ts +8 -0
- package/dist/agent-session.d.ts.map +1 -1
- package/dist/api.d.ts +24 -0
- package/dist/api.d.ts.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 +212 -1
- package/dist/eip712.d.ts.map +1 -1
- package/dist/eip712.js +34 -0
- 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 +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/job-session.d.ts +16 -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/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.map +1 -1
- package/dist/openapi.js +2 -1
- package/dist/openapi.js.map +1 -1
- 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 +10 -2
- package/dist/reasons.d.ts.map +1 -1
- package/dist/reasons.js +10 -2
- package/dist/reasons.js.map +1 -1
- package/dist/sandbox.d.ts +81 -0
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +18 -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 +8 -0
- package/dist/session-fields.d.ts.map +1 -1
- package/dist/terms.d.ts.map +1 -1
- package/dist/terms.js +4 -0
- package/dist/terms.js.map +1 -1
- package/dist/test-customer.d.ts +16 -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 +7 -4
- 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 +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -1
- package/dist/wire.d.ts +312 -0
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +28 -1
- package/dist/wire.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { digestOf, MOVE_KINDS, negotiationMoveTypedData, } from './eip712.js';
|
|
3
|
+
import { address, bytes32, hexBytes, sameHex as same, side, u64, u256 } from './json-fields.js';
|
|
4
|
+
import { businessIdJson, readOrNull } from './order-wire.js';
|
|
5
|
+
import { offerVersionId, SERVICE_QUANTITY_MAX, serviceOfferProblem, serviceOfferQuote, serviceOfferTerms, serviceOfferVersionJson, } from './service.js';
|
|
6
|
+
import { leavesTimeToAccept, SERVICE_ORDER_CLOCK_SKEW, serviceAgreementProblem, } from './service-order.js';
|
|
7
|
+
import { termsAgreementJson } from './wire.js';
|
|
8
|
+
/**
|
|
9
|
+
* A negotiation thread: the signed moves two businesses' agents make about one prospective
|
|
10
|
+
* commitment, from the buyer's first proposal to an agreement or a decline. A fixed-price order is
|
|
11
|
+
* the shortest thread, a proposal the supplier accepts.
|
|
12
|
+
*
|
|
13
|
+
* A thread is about one base offer version, which never changes. A proposal states a quantity, a
|
|
14
|
+
* unit price and a lead time against that base, and the terms are the ones `serviceOfferTerms`
|
|
15
|
+
* builds from the base with those three in place. Everything else in the terms comes from the
|
|
16
|
+
* base, so no move can change the item, what counts as delivery, a charge's share or how the
|
|
17
|
+
* price is paid.
|
|
18
|
+
*
|
|
19
|
+
* Either side accepts the other's open proposal. A supplier's proposal or acceptance carries its
|
|
20
|
+
* signed agreement to the terms' hash. The buyer signs that hash only when it accepts a supplier's
|
|
21
|
+
* proposal. When the supplier accepts the buyer's, the buyer has signed the quantity, the price,
|
|
22
|
+
* the lead time and the build moment, and it has signed no hash. Its signature doesn't cover the
|
|
23
|
+
* arbiter or the day-90 share the terms are built with, so the buyer builds the terms itself and
|
|
24
|
+
* compares their hash with the supplier's before it reserves.
|
|
25
|
+
*
|
|
26
|
+
* An accepted proposal is an agreed thread, and it is no commitment yet. Nothing is reserved until
|
|
27
|
+
* the buyer's lock takes the reserve, and the commitment exists only once the supplier's
|
|
28
|
+
* acceptance is on that lock. Until then either side can walk away. A decline shows which side
|
|
29
|
+
* ended the thread. A thread that ran out of time shows only that no move followed, and never
|
|
30
|
+
* whose fault that was.
|
|
31
|
+
*
|
|
32
|
+
* This module holds the moves and what makes each one valid where it stands. It reads no lock and
|
|
33
|
+
* checks no signature, so a caller establishes who signed a move before it asks whether the move
|
|
34
|
+
* fits. Nothing here says a move is within either side's authority, which is the mandates' part.
|
|
35
|
+
*/
|
|
36
|
+
/** The most proposals and counter-offers one thread takes. Accepting and declining don't count. */
|
|
37
|
+
export const THREAD_PROPOSALS_MAX = 6;
|
|
38
|
+
/**
|
|
39
|
+
* The longest one move stands, in seconds. A reader allows `SERVICE_ORDER_CLOCK_SKEW` on top for a
|
|
40
|
+
* sender whose clock runs ahead, so a move can stand a minute longer by the reader's clock.
|
|
41
|
+
*/
|
|
42
|
+
export const THREAD_MOVE_SECONDS = 5n * 60n;
|
|
43
|
+
/** The longest a thread runs from the moment its first proposal is built, in seconds. */
|
|
44
|
+
export const THREAD_SECONDS = 30n * 60n;
|
|
45
|
+
/** The most moves a thread holds: every proposal and counter, an acceptance, and a decline. */
|
|
46
|
+
export const THREAD_MOVES_MAX = THREAD_PROPOSALS_MAX + 2;
|
|
47
|
+
/** The furthest past a thread's first build moment a decline can say to ask again, in seconds. */
|
|
48
|
+
export const DECLINE_RETRY_MAX = 7n * 24n * 60n * 60n;
|
|
49
|
+
const ZERO = `0x${'00'.repeat(32)}`;
|
|
50
|
+
const other = (s) => (s === 'buyer' ? 'supplier' : 'buyer');
|
|
51
|
+
/**
|
|
52
|
+
* Every reason a move can decline with. A reason about the offer or the supplier's capacity is the
|
|
53
|
+
* supplier's to give, and only `offer.superseded` names another offer version, which it has to.
|
|
54
|
+
*/
|
|
55
|
+
export const DECLINE_RULES = {
|
|
56
|
+
'offer.superseded': { next: 'change_order', by: 'supplier', retryAt: false, available: false },
|
|
57
|
+
'offer.withdrawn': { next: 'choose_another', by: 'supplier', retryAt: false, available: false },
|
|
58
|
+
'capacity.exhausted': { next: 'retry_later', by: 'supplier', retryAt: true, available: true },
|
|
59
|
+
'quantity.out_of_range': {
|
|
60
|
+
next: 'change_order',
|
|
61
|
+
by: 'supplier',
|
|
62
|
+
retryAt: false,
|
|
63
|
+
available: true,
|
|
64
|
+
},
|
|
65
|
+
'terms.not_negotiable': { next: 'change_order', by: 'either', retryAt: false, available: false },
|
|
66
|
+
'proposal.unacceptable': { next: 'change_order', by: 'either', retryAt: false, available: false },
|
|
67
|
+
'counterparty.not_eligible': {
|
|
68
|
+
next: 'choose_another',
|
|
69
|
+
by: 'either',
|
|
70
|
+
retryAt: false,
|
|
71
|
+
available: false,
|
|
72
|
+
},
|
|
73
|
+
'approval.human_required': { next: 'retry_later', by: 'either', retryAt: true, available: false },
|
|
74
|
+
'negotiation.rounds_exhausted': {
|
|
75
|
+
next: 'choose_another',
|
|
76
|
+
by: 'either',
|
|
77
|
+
retryAt: false,
|
|
78
|
+
available: false,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
export const isDeclineReason = (reason) => Object.hasOwn(DECLINE_RULES, reason);
|
|
82
|
+
/**
|
|
83
|
+
* The rules a thread about this offer runs under. No offer opens a term to bargaining yet, since
|
|
84
|
+
* an offer version has no field to say so. So today a thread's one proposal carries the offer's
|
|
85
|
+
* own price and lead time, and a counter-offer is refused. A later version of the offer format
|
|
86
|
+
* names its open terms, and this reads them.
|
|
87
|
+
*
|
|
88
|
+
* Two things are to settle before any term opens. Terms built from a proposal that moves the price
|
|
89
|
+
* or the lead time name the id of the base as amended, and nothing in them names the base itself.
|
|
90
|
+
* And a proposed lead time has the offer template's lower bound and no upper one.
|
|
91
|
+
*/
|
|
92
|
+
export function negotiationRules(_base) {
|
|
93
|
+
return { open: [], proposalsMax: THREAD_PROPOSALS_MAX };
|
|
94
|
+
}
|
|
95
|
+
/** The digest a move is signed over, which the move after it names as `previous`. */
|
|
96
|
+
export const moveDigest = (move, domain) => digestOf(negotiationMoveTypedData(move, domain));
|
|
97
|
+
const proposes = (kind) => kind === 'propose' || kind === 'counter';
|
|
98
|
+
/**
|
|
99
|
+
* Where a thread stands at `now`. It trusts the moves, so a thread from anywhere else goes through
|
|
100
|
+
* `threadProblem` first. It throws for moves that could never have passed that check: none at
|
|
101
|
+
* all, none that proposes, or a decline whose reason isn't one of `DECLINE_RULES`.
|
|
102
|
+
*/
|
|
103
|
+
export function threadStateAt(thread, now) {
|
|
104
|
+
const moves = thread.moves.map((signed) => signed.move);
|
|
105
|
+
const first = moves[0];
|
|
106
|
+
const last = moves.at(-1);
|
|
107
|
+
const proposals = moves.filter((m) => proposes(m.kind));
|
|
108
|
+
// An acceptance always follows the proposal it accepts, so the newest proposal is the one.
|
|
109
|
+
const head = proposals.at(-1);
|
|
110
|
+
if (!first || !last || !head)
|
|
111
|
+
throw new RangeError('A thread opens with a proposal');
|
|
112
|
+
if (last.kind === 'decline') {
|
|
113
|
+
if (!isDeclineReason(last.reason)) {
|
|
114
|
+
throw new RangeError('A decline gives one of the reasons a thread takes');
|
|
115
|
+
}
|
|
116
|
+
return { status: 'closed', why: 'declined', reason: last.reason, by: last.side };
|
|
117
|
+
}
|
|
118
|
+
if (last.kind === 'accept') {
|
|
119
|
+
if (now >= last.expiry)
|
|
120
|
+
return { status: 'closed', why: 'lapsed' };
|
|
121
|
+
return { status: 'agreed', proposal: head, termsHash: last.termsHash, until: last.expiry };
|
|
122
|
+
}
|
|
123
|
+
if (now >= head.expiry || now >= first.builtAt + THREAD_SECONDS) {
|
|
124
|
+
return { status: 'closed', why: 'expired' };
|
|
125
|
+
}
|
|
126
|
+
return { status: 'open', head, turn: other(head.side), proposals: proposals.length };
|
|
127
|
+
}
|
|
128
|
+
/** The offer version a proposal asks for: the base with the proposal's price and lead time. */
|
|
129
|
+
export function proposedVersion(base, proposal) {
|
|
130
|
+
return {
|
|
131
|
+
...base,
|
|
132
|
+
unitPrice: proposal.unitPrice,
|
|
133
|
+
rules: { ...base.rules, leadTime: proposal.leadTime },
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The terms a proposal builds, which the supplier's agreement signs the hash of. Throws for a
|
|
138
|
+
* proposal the template refuses, which `moveProblem` never lets into a thread.
|
|
139
|
+
*/
|
|
140
|
+
export function proposalTerms(base, proposal, settlement) {
|
|
141
|
+
return serviceOfferTerms(proposedVersion(base, proposal), proposal.quantity, proposal.builtAt, settlement);
|
|
142
|
+
}
|
|
143
|
+
/** The terms a proposal sets differently from the offer, or from the proposal it answers. */
|
|
144
|
+
function moved(base, proposal, answered) {
|
|
145
|
+
const terms = [];
|
|
146
|
+
if (proposal.unitPrice !== base.unitPrice)
|
|
147
|
+
terms.push('unitPrice');
|
|
148
|
+
if (proposal.leadTime !== base.rules.leadTime)
|
|
149
|
+
terms.push('leadTime');
|
|
150
|
+
// The buyer's first proposal sets the quantity, and only a counter can move it.
|
|
151
|
+
if (answered && proposal.quantity !== answered.quantity)
|
|
152
|
+
terms.push('quantity');
|
|
153
|
+
return terms;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The most proposals and counters a thread under these rules takes, from 1 to
|
|
157
|
+
* `THREAD_PROPOSALS_MAX`. A limit that isn't a whole number allows the opening proposal only.
|
|
158
|
+
*/
|
|
159
|
+
function proposalLimit(rules) {
|
|
160
|
+
const { proposalsMax } = rules;
|
|
161
|
+
if (!Number.isSafeInteger(proposalsMax))
|
|
162
|
+
return 1;
|
|
163
|
+
return Math.max(1, Math.min(proposalsMax, THREAD_PROPOSALS_MAX));
|
|
164
|
+
}
|
|
165
|
+
/** Why a proposing move can't stand, or null. */
|
|
166
|
+
function proposalProblem(base, next, answered, rules, now) {
|
|
167
|
+
if (next.builtAt > now + SERVICE_ORDER_CLOCK_SKEW)
|
|
168
|
+
return 'message.invalid';
|
|
169
|
+
if (next.expiry <= next.builtAt)
|
|
170
|
+
return 'message.invalid';
|
|
171
|
+
// A proposal accepted at its last moment still leaves the supplier time to accept on the lock.
|
|
172
|
+
if (!leavesTimeToAccept(next.expiry, next.builtAt))
|
|
173
|
+
return 'message.validity_too_long';
|
|
174
|
+
// A supplier's proposal carries its agreement's terms hash, and a buyer's has none to carry.
|
|
175
|
+
if ((next.side === 'supplier') === same(next.termsHash, ZERO))
|
|
176
|
+
return 'message.invalid';
|
|
177
|
+
if (answered &&
|
|
178
|
+
next.quantity === answered.quantity &&
|
|
179
|
+
next.unitPrice === answered.unitPrice &&
|
|
180
|
+
next.leadTime === answered.leadTime) {
|
|
181
|
+
// A counter that repeats the proposal it answers is an acceptance written as a counter.
|
|
182
|
+
return 'message.invalid';
|
|
183
|
+
}
|
|
184
|
+
if (moved(base, next, answered).some((term) => !rules.open.includes(term))) {
|
|
185
|
+
return 'terms.not_negotiable';
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
serviceOfferQuote(proposedVersion(base, next), next.quantity);
|
|
189
|
+
}
|
|
190
|
+
catch {
|
|
191
|
+
return 'terms.template_invalid';
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Why a declining move can't stand, or null. It holds no proposal and no times of its own, a
|
|
197
|
+
* reason its side can give, and only the fields that reason allows.
|
|
198
|
+
*/
|
|
199
|
+
function declineProblem(next, first, baseId) {
|
|
200
|
+
if (!isDeclineReason(next.reason))
|
|
201
|
+
return 'message.invalid';
|
|
202
|
+
const rule = DECLINE_RULES[next.reason];
|
|
203
|
+
if (rule.by === 'supplier' && next.side !== 'supplier')
|
|
204
|
+
return 'message.invalid';
|
|
205
|
+
if (next.quantity !== 0 || next.unitPrice !== 0n || next.leadTime !== 0n)
|
|
206
|
+
return 'message.invalid';
|
|
207
|
+
if (next.builtAt !== 0n || !same(next.termsHash, ZERO))
|
|
208
|
+
return 'message.invalid';
|
|
209
|
+
// A decline ends the thread, so nothing waits on it and it has no expiry to give.
|
|
210
|
+
if (next.expiry !== 0n)
|
|
211
|
+
return 'message.invalid';
|
|
212
|
+
if (next.retryAt !== 0n) {
|
|
213
|
+
// The time is measured from the thread's own first moment, so every reader judges it alike.
|
|
214
|
+
if (!rule.retryAt || next.retryAt <= first.builtAt)
|
|
215
|
+
return 'message.invalid';
|
|
216
|
+
if (next.retryAt > first.builtAt + DECLINE_RETRY_MAX)
|
|
217
|
+
return 'message.invalid';
|
|
218
|
+
}
|
|
219
|
+
if (next.available !== 0) {
|
|
220
|
+
if (!rule.available)
|
|
221
|
+
return 'message.invalid';
|
|
222
|
+
if (next.available < 0 || next.available > SERVICE_QUANTITY_MAX)
|
|
223
|
+
return 'message.invalid';
|
|
224
|
+
}
|
|
225
|
+
// A decline for a replaced offer names the version that replaced it, and no other decline does.
|
|
226
|
+
const names = !same(next.currentOffer, ZERO);
|
|
227
|
+
if (names !== (next.reason === 'offer.superseded'))
|
|
228
|
+
return 'message.invalid';
|
|
229
|
+
if (names && same(next.currentOffer, baseId))
|
|
230
|
+
return 'message.invalid';
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Why `next` can't be the thread's next move at `now`, or null when it can. `moves` are the
|
|
235
|
+
* thread's moves so far, each of which passed this check, and none for a first proposal.
|
|
236
|
+
*
|
|
237
|
+
* A move takes the next number and names the digest of the move before it, so one copy of a
|
|
238
|
+
* thread holds one chain. This can't stop a key signing two different moves for one number. Avow's
|
|
239
|
+
* copy takes the first, and the two signatures together prove the key signed both. The buyer opens
|
|
240
|
+
* with a proposal. After that the side a proposal waits on counters or accepts, and either side
|
|
241
|
+
* declines at any point before the thread closes. A proposal or an acceptance stands for
|
|
242
|
+
* `THREAD_MOVE_SECONDS` at most, and none outlasts `THREAD_SECONDS` from the first proposal. A
|
|
243
|
+
* buyer's acceptance stands no longer than the supplier's proposal it accepts.
|
|
244
|
+
*
|
|
245
|
+
* The caller checks the signature and that its signer is the side the move names. This checks
|
|
246
|
+
* neither, and it doesn't read a supplier's quote, which `threadQuoteProblem` does.
|
|
247
|
+
*/
|
|
248
|
+
export function moveProblem(thread, next, domain, now, rules = negotiationRules(thread.base)) {
|
|
249
|
+
const { base } = thread;
|
|
250
|
+
const moves = thread.moves.map((signed) => signed.move);
|
|
251
|
+
const first = moves[0] ?? null;
|
|
252
|
+
const last = moves.at(-1) ?? null;
|
|
253
|
+
let baseId;
|
|
254
|
+
try {
|
|
255
|
+
baseId = offerVersionId(base);
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
return 'terms.template_invalid';
|
|
259
|
+
}
|
|
260
|
+
if (!same(next.baseOffer, baseId))
|
|
261
|
+
return 'message.invalid';
|
|
262
|
+
if (same(next.thread, ZERO) || same(next.commitmentId, ZERO))
|
|
263
|
+
return 'message.invalid';
|
|
264
|
+
if (next.kind !== 'decline') {
|
|
265
|
+
if (next.expiry <= now)
|
|
266
|
+
return 'message.expired';
|
|
267
|
+
if (next.expiry > now + THREAD_MOVE_SECONDS + SERVICE_ORDER_CLOCK_SKEW) {
|
|
268
|
+
return 'message.validity_too_long';
|
|
269
|
+
}
|
|
270
|
+
// Only a decline says why, when to ask again, how many units or which version.
|
|
271
|
+
if (next.reason !== '' || next.retryAt !== 0n || next.available !== 0)
|
|
272
|
+
return 'message.invalid';
|
|
273
|
+
if (!same(next.currentOffer, ZERO))
|
|
274
|
+
return 'message.invalid';
|
|
275
|
+
}
|
|
276
|
+
// The move takes the next place in the chain, after the move this thread ends with.
|
|
277
|
+
if (next.seq !== moves.length)
|
|
278
|
+
return 'order.out_of_step';
|
|
279
|
+
if (!same(next.previous, last ? moveDigest(last, domain) : ZERO))
|
|
280
|
+
return 'order.out_of_step';
|
|
281
|
+
if (!first) {
|
|
282
|
+
if (next.kind !== 'propose' || next.side !== 'buyer')
|
|
283
|
+
return 'order.out_of_step';
|
|
284
|
+
return proposalProblem(base, next, null, rules, now);
|
|
285
|
+
}
|
|
286
|
+
if (!same(next.thread, first.thread))
|
|
287
|
+
return 'message.invalid';
|
|
288
|
+
if (!same(next.commitmentId, first.commitmentId))
|
|
289
|
+
return 'order.commitment_mismatch';
|
|
290
|
+
if (next.kind === 'propose')
|
|
291
|
+
return 'order.out_of_step';
|
|
292
|
+
let state;
|
|
293
|
+
try {
|
|
294
|
+
state = threadStateAt(thread, now);
|
|
295
|
+
}
|
|
296
|
+
catch {
|
|
297
|
+
// Moves no thread could hold, from a copy nobody replayed with `threadProblem`.
|
|
298
|
+
return 'message.invalid';
|
|
299
|
+
}
|
|
300
|
+
if (state.status === 'closed') {
|
|
301
|
+
return state.why === 'declined' ? 'order.out_of_step' : 'message.expired';
|
|
302
|
+
}
|
|
303
|
+
if (next.kind === 'decline')
|
|
304
|
+
return declineProblem(next, first, baseId);
|
|
305
|
+
// A counter or an acceptance answers the open proposal, and only the side it waits on answers.
|
|
306
|
+
if (state.status !== 'open' || next.side !== state.turn)
|
|
307
|
+
return 'order.out_of_step';
|
|
308
|
+
if (next.expiry > first.builtAt + THREAD_SECONDS)
|
|
309
|
+
return 'message.validity_too_long';
|
|
310
|
+
if (next.kind === 'counter') {
|
|
311
|
+
// Rules can lower the most proposals a thread takes, and never raise it.
|
|
312
|
+
if (state.proposals >= proposalLimit(rules)) {
|
|
313
|
+
return 'negotiation.rounds_exhausted';
|
|
314
|
+
}
|
|
315
|
+
return proposalProblem(base, next, state.head, rules, now);
|
|
316
|
+
}
|
|
317
|
+
// An acceptance restates the proposal it accepts, so its signature covers what was agreed.
|
|
318
|
+
const { head } = state;
|
|
319
|
+
if (next.quantity !== head.quantity ||
|
|
320
|
+
next.unitPrice !== head.unitPrice ||
|
|
321
|
+
next.leadTime !== head.leadTime ||
|
|
322
|
+
next.builtAt !== head.builtAt) {
|
|
323
|
+
return 'order.terms_changed';
|
|
324
|
+
}
|
|
325
|
+
// The supplier accepts with its own agreement's hash, and the buyer with the supplier's.
|
|
326
|
+
if (same(next.termsHash, ZERO))
|
|
327
|
+
return 'message.invalid';
|
|
328
|
+
if (next.side === 'buyer') {
|
|
329
|
+
if (!same(next.termsHash, head.termsHash))
|
|
330
|
+
return 'terms.hash_mismatch';
|
|
331
|
+
// The supplier's agreement is sure to stand only as long as its proposal, so the buyer's
|
|
332
|
+
// acceptance gives no more time to reserve than that.
|
|
333
|
+
if (next.expiry > head.expiry)
|
|
334
|
+
return 'message.validity_too_long';
|
|
335
|
+
}
|
|
336
|
+
if (!leavesTimeToAccept(next.expiry, head.builtAt))
|
|
337
|
+
return 'message.validity_too_long';
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Why a supplier's quote doesn't agree to a proposal's terms, or null when it does. The quote's
|
|
342
|
+
* agreement has to carry the hash of the terms the proposal builds with the thread's settlement,
|
|
343
|
+
* under the quote's salt, for the thread's commitment, the base offer's supplier, the thread's
|
|
344
|
+
* buyer and a service. That hash is the one the supplier's move states.
|
|
345
|
+
*
|
|
346
|
+
* It leaves the supplier's signature to Avow, as `serviceQuoteProblem` does, and how long the
|
|
347
|
+
* agreement stands to `signedMoveProblem`. It never throws.
|
|
348
|
+
*/
|
|
349
|
+
export function threadQuoteProblem(thread, proposal, stated, quote) {
|
|
350
|
+
let terms;
|
|
351
|
+
try {
|
|
352
|
+
terms = proposalTerms(thread.base, proposal, thread.settlement);
|
|
353
|
+
}
|
|
354
|
+
catch {
|
|
355
|
+
return 'terms.template_invalid';
|
|
356
|
+
}
|
|
357
|
+
const problem = serviceAgreementProblem({ commitmentId: proposal.commitmentId, supplier: thread.base.supplier, buyer: thread.buyer }, terms, quote);
|
|
358
|
+
if (problem)
|
|
359
|
+
return problem;
|
|
360
|
+
return same(quote.agreement.termsHash, stated) ? null : 'terms.hash_mismatch';
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Why a signed move, with what it brings along, can't be the thread's next at `now`, or null when
|
|
364
|
+
* it can. It runs `moveProblem`, then checks what travels beside the move. A supplier's proposal
|
|
365
|
+
* or acceptance brings its quote, which has to agree to the proposal's terms under the hash the
|
|
366
|
+
* move states, and stand at least as long as the move does. A decline for a replaced offer brings
|
|
367
|
+
* the replacing version whole, from the same supplier, for the same item, under the id the move
|
|
368
|
+
* names. Nothing else brings either.
|
|
369
|
+
*
|
|
370
|
+
* The caller still checks the move's signature, and Avow checks the quote's.
|
|
371
|
+
*/
|
|
372
|
+
export function signedMoveProblem(thread, next, domain, now, rules = negotiationRules(thread.base)) {
|
|
373
|
+
const problem = moveProblem(thread, next.move, domain, now, rules);
|
|
374
|
+
if (problem)
|
|
375
|
+
return problem;
|
|
376
|
+
const { move } = next;
|
|
377
|
+
const quotes = move.side === 'supplier' && move.kind !== 'decline';
|
|
378
|
+
if (quotes !== (next.quote !== null))
|
|
379
|
+
return 'message.invalid';
|
|
380
|
+
if (next.quote) {
|
|
381
|
+
const unagreed = threadQuoteProblem(thread, move, move.termsHash, next.quote);
|
|
382
|
+
if (unagreed)
|
|
383
|
+
return unagreed;
|
|
384
|
+
// An agreement that lapses before its move does would leave the buyer agreed to nothing.
|
|
385
|
+
if (next.quote.agreement.expiry < move.expiry)
|
|
386
|
+
return 'message.invalid';
|
|
387
|
+
}
|
|
388
|
+
const names = !same(move.currentOffer, ZERO);
|
|
389
|
+
if (names !== (next.current !== null))
|
|
390
|
+
return 'message.invalid';
|
|
391
|
+
if (next.current) {
|
|
392
|
+
if (next.current.supplier !== thread.base.supplier)
|
|
393
|
+
return 'message.invalid';
|
|
394
|
+
// The replacement is a newer version of the item ordered, and never some other item.
|
|
395
|
+
if (next.current.item.name !== thread.base.item.name)
|
|
396
|
+
return 'message.invalid';
|
|
397
|
+
try {
|
|
398
|
+
if (!same(offerVersionId(next.current), move.currentOffer))
|
|
399
|
+
return 'message.invalid';
|
|
400
|
+
}
|
|
401
|
+
catch {
|
|
402
|
+
return 'terms.template_invalid';
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
const latest = (...times) => times.reduce((a, b) => (a > b ? a : b), 0n);
|
|
408
|
+
/**
|
|
409
|
+
* Why a thread from anywhere else isn't one its moves could have made, or null when it is. Run it
|
|
410
|
+
* on every thread read from the wire before `threadStateAt` or anything else trusts the moves.
|
|
411
|
+
*
|
|
412
|
+
* It replays the thread from its first move with `signedMoveProblem`, each move at the earliest
|
|
413
|
+
* moment it could have been sent, given its own times and the moves before it. A thread whose
|
|
414
|
+
* moves were each taken in turn always passes, since a move valid when it was sent is valid at
|
|
415
|
+
* that earlier moment too. No move carries the moment it was sent, so the replay shows only that
|
|
416
|
+
* each move could have arrived in time. When it did arrive is known only to whoever took it in,
|
|
417
|
+
* and the copy that whoever keeps the thread holds decides. It checks no signature.
|
|
418
|
+
*/
|
|
419
|
+
export function threadProblem(thread, domain, rules = negotiationRules(thread.base)) {
|
|
420
|
+
if (thread.moves.length === 0 || thread.moves.length > THREAD_MOVES_MAX)
|
|
421
|
+
return 'message.invalid';
|
|
422
|
+
let at = 0n;
|
|
423
|
+
for (const [index, signed] of thread.moves.entries()) {
|
|
424
|
+
const { move } = signed;
|
|
425
|
+
if (move.kind !== 'decline') {
|
|
426
|
+
at = latest(at, move.expiry - (THREAD_MOVE_SECONDS + SERVICE_ORDER_CLOCK_SKEW), proposes(move.kind) ? move.builtAt - SERVICE_ORDER_CLOCK_SKEW : 0n);
|
|
427
|
+
}
|
|
428
|
+
const soFar = { ...thread, moves: thread.moves.slice(0, index) };
|
|
429
|
+
const problem = signedMoveProblem(soFar, signed, domain, at, rules);
|
|
430
|
+
if (problem)
|
|
431
|
+
return problem;
|
|
432
|
+
}
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
const moveKind = z.enum(Object.keys(MOVE_KINDS));
|
|
436
|
+
const units = z.number().int().min(0).max(SERVICE_QUANTITY_MAX);
|
|
437
|
+
export const negotiationMoveJson = z.strictObject({
|
|
438
|
+
thread: bytes32,
|
|
439
|
+
commitmentId: bytes32,
|
|
440
|
+
seq: z
|
|
441
|
+
.number()
|
|
442
|
+
.int()
|
|
443
|
+
.min(0)
|
|
444
|
+
.max(THREAD_MOVES_MAX - 1),
|
|
445
|
+
previous: bytes32,
|
|
446
|
+
side,
|
|
447
|
+
kind: moveKind,
|
|
448
|
+
baseOffer: bytes32,
|
|
449
|
+
quantity: units,
|
|
450
|
+
unitPrice: u256,
|
|
451
|
+
leadTime: u64,
|
|
452
|
+
builtAt: u64,
|
|
453
|
+
termsHash: bytes32,
|
|
454
|
+
// A reason is a code, never a sentence, so it's short and holds no spaces.
|
|
455
|
+
reason: z
|
|
456
|
+
.string()
|
|
457
|
+
.regex(/^([a-z0-9_]+(\.[a-z0-9_]+)+)?$/)
|
|
458
|
+
.max(64),
|
|
459
|
+
retryAt: u64,
|
|
460
|
+
available: units,
|
|
461
|
+
currentOffer: bytes32,
|
|
462
|
+
expiry: u64,
|
|
463
|
+
});
|
|
464
|
+
export const threadQuoteJson = z.strictObject({
|
|
465
|
+
salt: bytes32,
|
|
466
|
+
agreement: termsAgreementJson,
|
|
467
|
+
supplierSignature: hexBytes,
|
|
468
|
+
});
|
|
469
|
+
export const signedMoveJson = z.strictObject({
|
|
470
|
+
move: negotiationMoveJson,
|
|
471
|
+
signature: hexBytes,
|
|
472
|
+
quote: threadQuoteJson.nullable(),
|
|
473
|
+
current: serviceOfferVersionJson.nullable(),
|
|
474
|
+
});
|
|
475
|
+
export const negotiationThreadJson = z
|
|
476
|
+
.strictObject({
|
|
477
|
+
base: serviceOfferVersionJson,
|
|
478
|
+
buyer: z.strictObject({ businessId: businessIdJson, mandateHash: bytes32 }),
|
|
479
|
+
settlement: z.strictObject({
|
|
480
|
+
arbiter: address,
|
|
481
|
+
day90SupplierShareBps: z.number().int().min(0).max(10_000),
|
|
482
|
+
}),
|
|
483
|
+
moves: z.array(signedMoveJson).min(1).max(THREAD_MOVES_MAX),
|
|
484
|
+
})
|
|
485
|
+
// An offer the template's rules refuse is refused where the thread is read.
|
|
486
|
+
.refine((thread) => serviceOfferProblem(thread.base) === null);
|
|
487
|
+
export const parseNegotiationMove = readOrNull(negotiationMoveJson);
|
|
488
|
+
export const parseSignedMove = readOrNull(signedMoveJson);
|
|
489
|
+
export const parseNegotiationThread = readOrNull(negotiationThreadJson);
|
|
490
|
+
//# sourceMappingURL=negotiation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"negotiation.js","sourceRoot":"","sources":["../src/negotiation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAEL,QAAQ,EACR,UAAU,EAGV,wBAAwB,GAEzB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,OAA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