@avow-finance/spec 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +119 -2
  3. package/dist/agent-connect.d.ts +90 -0
  4. package/dist/agent-connect.d.ts.map +1 -0
  5. package/dist/agent-connect.js +102 -0
  6. package/dist/agent-connect.js.map +1 -0
  7. package/dist/agent-session.d.ts +791 -0
  8. package/dist/agent-session.d.ts.map +1 -0
  9. package/dist/agent-session.js +176 -0
  10. package/dist/agent-session.js.map +1 -0
  11. package/dist/ap2.d.ts +79 -0
  12. package/dist/ap2.d.ts.map +1 -0
  13. package/dist/ap2.js +151 -0
  14. package/dist/ap2.js.map +1 -0
  15. package/dist/api-request.d.ts +144 -0
  16. package/dist/api-request.d.ts.map +1 -0
  17. package/dist/api-request.js +246 -0
  18. package/dist/api-request.js.map +1 -0
  19. package/dist/api.d.ts +288 -0
  20. package/dist/api.d.ts.map +1 -0
  21. package/dist/api.js +332 -0
  22. package/dist/api.js.map +1 -0
  23. package/dist/canonical.d.ts +22 -0
  24. package/dist/canonical.d.ts.map +1 -0
  25. package/dist/canonical.js +66 -0
  26. package/dist/canonical.js.map +1 -0
  27. package/dist/commitment-card.d.ts +78 -0
  28. package/dist/commitment-card.d.ts.map +1 -0
  29. package/dist/commitment-card.js +224 -0
  30. package/dist/commitment-card.js.map +1 -0
  31. package/dist/commitment.d.ts +185 -0
  32. package/dist/commitment.d.ts.map +1 -0
  33. package/dist/commitment.js +148 -0
  34. package/dist/commitment.js.map +1 -0
  35. package/dist/compute-offers.d.ts +128 -0
  36. package/dist/compute-offers.d.ts.map +1 -0
  37. package/dist/compute-offers.js +111 -0
  38. package/dist/compute-offers.js.map +1 -0
  39. package/dist/contest.d.ts +88 -0
  40. package/dist/contest.d.ts.map +1 -0
  41. package/dist/contest.js +131 -0
  42. package/dist/contest.js.map +1 -0
  43. package/dist/demo.d.ts +69 -0
  44. package/dist/demo.d.ts.map +1 -0
  45. package/dist/demo.js +152 -0
  46. package/dist/demo.js.map +1 -0
  47. package/dist/dependencies.d.ts +308 -0
  48. package/dist/dependencies.d.ts.map +1 -0
  49. package/dist/dependencies.js +133 -0
  50. package/dist/dependencies.js.map +1 -0
  51. package/dist/eip712.d.ts +1569 -0
  52. package/dist/eip712.d.ts.map +1 -0
  53. package/dist/eip712.js +550 -0
  54. package/dist/eip712.js.map +1 -0
  55. package/dist/elided-terms.d.ts +37 -0
  56. package/dist/elided-terms.d.ts.map +1 -0
  57. package/dist/elided-terms.js +48 -0
  58. package/dist/elided-terms.js.map +1 -0
  59. package/dist/erc8183.d.ts +78 -0
  60. package/dist/erc8183.d.ts.map +1 -0
  61. package/dist/erc8183.js +88 -0
  62. package/dist/erc8183.js.map +1 -0
  63. package/dist/facts.d.ts +70 -0
  64. package/dist/facts.d.ts.map +1 -0
  65. package/dist/facts.js +33 -0
  66. package/dist/facts.js.map +1 -0
  67. package/dist/gpu-reservation.d.ts +79 -0
  68. package/dist/gpu-reservation.d.ts.map +1 -0
  69. package/dist/gpu-reservation.js +135 -0
  70. package/dist/gpu-reservation.js.map +1 -0
  71. package/dist/index.d.ts +49 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +49 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/job-session.d.ts +981 -0
  76. package/dist/job-session.d.ts.map +1 -0
  77. package/dist/job-session.js +170 -0
  78. package/dist/job-session.js.map +1 -0
  79. package/dist/job-verification.d.ts +244 -0
  80. package/dist/job-verification.d.ts.map +1 -0
  81. package/dist/job-verification.js +89 -0
  82. package/dist/job-verification.js.map +1 -0
  83. package/dist/job-wording.d.ts +48 -0
  84. package/dist/job-wording.d.ts.map +1 -0
  85. package/dist/job-wording.js +134 -0
  86. package/dist/job-wording.js.map +1 -0
  87. package/dist/job.d.ts +117 -0
  88. package/dist/job.d.ts.map +1 -0
  89. package/dist/job.js +166 -0
  90. package/dist/job.js.map +1 -0
  91. package/dist/json-fields.d.ts +13 -0
  92. package/dist/json-fields.d.ts.map +1 -0
  93. package/dist/json-fields.js +30 -0
  94. package/dist/json-fields.js.map +1 -0
  95. package/dist/keychain.d.ts +51 -0
  96. package/dist/keychain.d.ts.map +1 -0
  97. package/dist/keychain.js +133 -0
  98. package/dist/keychain.js.map +1 -0
  99. package/dist/mailbox.d.ts +1650 -0
  100. package/dist/mailbox.d.ts.map +1 -0
  101. package/dist/mailbox.js +87 -0
  102. package/dist/mailbox.js.map +1 -0
  103. package/dist/mandate.d.ts +53 -0
  104. package/dist/mandate.d.ts.map +1 -0
  105. package/dist/mandate.js +97 -0
  106. package/dist/mandate.js.map +1 -0
  107. package/dist/networks.d.ts +18 -0
  108. package/dist/networks.d.ts.map +1 -0
  109. package/dist/networks.js +24 -0
  110. package/dist/networks.js.map +1 -0
  111. package/dist/profiles.d.ts +31 -0
  112. package/dist/profiles.d.ts.map +1 -0
  113. package/dist/profiles.js +33 -0
  114. package/dist/profiles.js.map +1 -0
  115. package/dist/rail.d.ts +48 -0
  116. package/dist/rail.d.ts.map +1 -0
  117. package/dist/rail.js +28 -0
  118. package/dist/rail.js.map +1 -0
  119. package/dist/reasons.d.ts +173 -0
  120. package/dist/reasons.d.ts.map +1 -0
  121. package/dist/reasons.js +174 -0
  122. package/dist/reasons.js.map +1 -0
  123. package/dist/reference-link.d.ts +23 -0
  124. package/dist/reference-link.d.ts.map +1 -0
  125. package/dist/reference-link.js +56 -0
  126. package/dist/reference-link.js.map +1 -0
  127. package/dist/references.d.ts +125 -0
  128. package/dist/references.d.ts.map +1 -0
  129. package/dist/references.js +108 -0
  130. package/dist/references.js.map +1 -0
  131. package/dist/replay.d.ts +30 -0
  132. package/dist/replay.d.ts.map +1 -0
  133. package/dist/replay.js +27 -0
  134. package/dist/replay.js.map +1 -0
  135. package/dist/sandbox-registration.d.ts +200 -0
  136. package/dist/sandbox-registration.d.ts.map +1 -0
  137. package/dist/sandbox-registration.js +172 -0
  138. package/dist/sandbox-registration.js.map +1 -0
  139. package/dist/sandbox.d.ts +3478 -0
  140. package/dist/sandbox.d.ts.map +1 -0
  141. package/dist/sandbox.js +316 -0
  142. package/dist/sandbox.js.map +1 -0
  143. package/dist/session-fields.d.ts +203 -0
  144. package/dist/session-fields.d.ts.map +1 -0
  145. package/dist/session-fields.js +43 -0
  146. package/dist/session-fields.js.map +1 -0
  147. package/dist/supplier-adapter.d.ts +65 -0
  148. package/dist/supplier-adapter.d.ts.map +1 -0
  149. package/dist/supplier-adapter.js +91 -0
  150. package/dist/supplier-adapter.js.map +1 -0
  151. package/dist/terms-v1.d.ts +74 -0
  152. package/dist/terms-v1.d.ts.map +1 -0
  153. package/dist/terms-v1.js +156 -0
  154. package/dist/terms-v1.js.map +1 -0
  155. package/dist/terms.d.ts +341 -0
  156. package/dist/terms.d.ts.map +1 -0
  157. package/dist/terms.js +715 -0
  158. package/dist/terms.js.map +1 -0
  159. package/dist/test-customer.d.ts +1525 -0
  160. package/dist/test-customer.d.ts.map +1 -0
  161. package/dist/test-customer.js +260 -0
  162. package/dist/test-customer.js.map +1 -0
  163. package/dist/types.d.ts +272 -0
  164. package/dist/types.d.ts.map +1 -0
  165. package/dist/types.js +32 -0
  166. package/dist/types.js.map +1 -0
  167. package/dist/version.d.ts +51 -0
  168. package/dist/version.d.ts.map +1 -0
  169. package/dist/version.js +66 -0
  170. package/dist/version.js.map +1 -0
  171. package/dist/wire.d.ts +2698 -0
  172. package/dist/wire.d.ts.map +1 -0
  173. package/dist/wire.js +678 -0
  174. package/dist/wire.js.map +1 -0
  175. package/package.json +37 -3
  176. package/vectors/api-request-v1.json +53 -0
  177. package/vectors/contest-statement-v1.json +42 -0
  178. package/vectors/terms-v2.json +398 -0
  179. package/vectors/terms-v3.json +2103 -0
@@ -0,0 +1,128 @@
1
+ import { z } from 'zod';
2
+ import { type GpuReservationTerms } from './gpu-reservation.js';
3
+ import type { SandboxDeployment } from './sandbox.js';
4
+ import type { Parsed } from './wire.js';
5
+ /**
6
+ * A GPU supplier's offers of compute for a job, which its adapter lists at
7
+ * `SUPPLIER_ADAPTER_PATHS.offers` for the window a job needs. An agent compares them and books one
8
+ * with terms `computeOfferTerms` builds, so the agent and the supplier build the same terms from
9
+ * the same offer. The supplier still decides what it signs.
10
+ *
11
+ * An offer is firm when its free cancellation had ended by the time it was listed, so a booking of
12
+ * it can't be cancelled at no charge, and flexible when it ends later. Usage is paid separately at
13
+ * the offer's rate and the reserve doesn't secure it. The reserve covers what the booking's terms
14
+ * let the supplier charge if the buyer walks away.
15
+ */
16
+ export interface ComputeOffer {
17
+ id: string;
18
+ /** The supplier's business id. */
19
+ supplier: string;
20
+ gpu: string;
21
+ region: string;
22
+ sku: string;
23
+ /** How many GPUs one booking of the offer can take. */
24
+ gpus: {
25
+ min: number;
26
+ max: number;
27
+ };
28
+ /** How long the window lasts, in whole minutes. */
29
+ minutes: number;
30
+ /** When the window starts, in unix seconds. */
31
+ startsAt: bigint;
32
+ /** Until this moment a booking can be cancelled at no charge. At or before `listedAt`, firm. */
33
+ freeCancelBy: bigint;
34
+ /** Usage per GPU-hour, in micros, paid apart from the reserve and never secured by it. */
35
+ pricePerGpuHour: bigint;
36
+ /** The reserve a booking needs for each GPU, in micros. */
37
+ reservePerGpu: bigint;
38
+ /**
39
+ * When the offer lapses, in unix seconds. It says when the listing stops standing. The supplier
40
+ * keeps no record of its listings and signs any terms within its own limits.
41
+ */
42
+ expiry: bigint;
43
+ }
44
+ /** What a GPU supplier's adapter lists for a job's window. */
45
+ export interface ComputeOffers {
46
+ supplier: string;
47
+ /** When the supplier listed these offers, in unix seconds. */
48
+ listedAt: bigint;
49
+ offers: ComputeOffer[];
50
+ }
51
+ /** The most offers one listing holds. */
52
+ export declare const MAX_COMPUTE_OFFERS = 16;
53
+ /**
54
+ * The path that lists a supplier's offers for the window a job needs, from its start to its
55
+ * deadline, an unsigned GET under the supplier's adapter.
56
+ */
57
+ export declare function computeOffersPath(window: {
58
+ startsAt: bigint;
59
+ deliverBy: bigint;
60
+ }): string;
61
+ /** Whether an offer was firm when it was listed: its free cancellation had already ended. */
62
+ export declare const isFirmOffer: (offer: ComputeOffer, listedAt: bigint) => boolean;
63
+ /** An offer's window in seconds. */
64
+ export declare const offerSeconds: (offer: Pick<ComputeOffer, 'minutes'>) => bigint;
65
+ /** Whether one booking of the offer can take this many GPUs. */
66
+ export declare const offerTakes: (offer: Pick<ComputeOffer, 'gpus'>, gpus: number) => boolean;
67
+ /**
68
+ * What booking `gpus` of an offer costs: the usage price for its whole window, paid apart from the
69
+ * reserve, and the reserve the booking needs, both in micros. Throws for a count the offer doesn't
70
+ * take.
71
+ */
72
+ export declare function computeOfferCost(offer: ComputeOffer, gpus: number): {
73
+ price: bigint;
74
+ reserve: bigint;
75
+ };
76
+ /**
77
+ * The GPU reservation terms for booking `gpus` of an offer. The window and the free-cancellation
78
+ * deadline are the offer's, the rate is its price per GPU-hour, and the reserve is its reserve per
79
+ * GPU times the count. A no-show costs the whole reserve after the grace period, two minutes or
80
+ * half the window when that's shorter, and a late cancellation half of it. Charges can be reported
81
+ * until the window ends, the contest window is ten minutes, and the reserve comes back at the
82
+ * window's end. The arbiter and the day-90 share are the deployment's, which Avow's approvals name.
83
+ * Throws for a count the offer doesn't take.
84
+ */
85
+ export declare function computeOfferTerms(offer: ComputeOffer, gpus: number, settlement: Pick<SandboxDeployment, 'arbiter' | 'day90SupplierShareBps'>): GpuReservationTerms;
86
+ /** An offer as JSON, with amounts and times as decimal strings. */
87
+ export declare const computeOfferJson: z.ZodObject<{
88
+ id: z.ZodString;
89
+ supplier: z.ZodString;
90
+ gpu: z.ZodString;
91
+ region: z.ZodString;
92
+ sku: z.ZodString;
93
+ gpus: z.ZodObject<{
94
+ min: z.ZodNumber;
95
+ max: z.ZodNumber;
96
+ }, z.core.$strict>;
97
+ minutes: z.ZodNumber;
98
+ startsAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
99
+ freeCancelBy: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
100
+ pricePerGpuHour: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
101
+ reservePerGpu: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
102
+ expiry: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
103
+ }, z.core.$strict>;
104
+ /** A supplier's listing as JSON. */
105
+ export declare const computeOffersJson: z.ZodObject<{
106
+ supplier: z.ZodString;
107
+ listedAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
108
+ offers: z.ZodArray<z.ZodObject<{
109
+ id: z.ZodString;
110
+ supplier: z.ZodString;
111
+ gpu: z.ZodString;
112
+ region: z.ZodString;
113
+ sku: z.ZodString;
114
+ gpus: z.ZodObject<{
115
+ min: z.ZodNumber;
116
+ max: z.ZodNumber;
117
+ }, z.core.$strict>;
118
+ minutes: z.ZodNumber;
119
+ startsAt: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
120
+ freeCancelBy: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
121
+ pricePerGpuHour: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
122
+ reservePerGpu: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
123
+ expiry: z.ZodPipe<z.ZodString, z.ZodTransform<bigint, string>>;
124
+ }, z.core.$strict>>;
125
+ }, z.core.$strict>;
126
+ /** Reads a supplier's listing of offers, refusing ids listed twice or another supplier's offer. */
127
+ export declare function parseComputeOffers(json: unknown): Parsed<ComputeOffers>;
128
+ //# sourceMappingURL=compute-offers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute-offers.d.ts","sourceRoot":"","sources":["../src/compute-offers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,KAAK,mBAAmB,EAAuB,MAAM,sBAAsB,CAAA;AAEpF,OAAO,KAAK,EAAE,iBA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,MAAM,UAAU,UAAW,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,QAAQ,MAAM,KAAG,OACG,CAAA;AAEhF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CASpC;AAID;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,uBAAuB,CAAC,GACvE,mBAAmB,CAqBrB;AAID,mEAAmE;AACnE,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;kBAuBwD,CAAA;AAErF,oCAAoC;AACpC,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;kBAI5B,CAAA;AAEF,mGAAmG;AACnG,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,CASvE"}
@@ -0,0 +1,111 @@
1
+ import { z } from 'zod';
2
+ import { gpuReservationTerms } from './gpu-reservation.js';
3
+ import { u64, u256 } from './json-fields.js';
4
+ import { SUPPLIER_ADAPTER_PATHS } from './supplier-adapter.js';
5
+ /** The most offers one listing holds. */
6
+ export const MAX_COMPUTE_OFFERS = 16;
7
+ /**
8
+ * The path that lists a supplier's offers for the window a job needs, from its start to its
9
+ * deadline, an unsigned GET under the supplier's adapter.
10
+ */
11
+ export function computeOffersPath(window) {
12
+ return `${SUPPLIER_ADAPTER_PATHS.offers}?startsAt=${window.startsAt}&deliverBy=${window.deliverBy}`;
13
+ }
14
+ /** Whether an offer was firm when it was listed: its free cancellation had already ended. */
15
+ export const isFirmOffer = (offer, listedAt) => offer.freeCancelBy <= listedAt;
16
+ /** An offer's window in seconds. */
17
+ export const offerSeconds = (offer) => BigInt(offer.minutes) * 60n;
18
+ /** Whether one booking of the offer can take this many GPUs. */
19
+ export const offerTakes = (offer, gpus) => Number.isSafeInteger(gpus) && gpus >= offer.gpus.min && gpus <= offer.gpus.max;
20
+ /**
21
+ * What booking `gpus` of an offer costs: the usage price for its whole window, paid apart from the
22
+ * reserve, and the reserve the booking needs, both in micros. Throws for a count the offer doesn't
23
+ * take.
24
+ */
25
+ export function computeOfferCost(offer, gpus) {
26
+ if (!offerTakes(offer, gpus)) {
27
+ throw new RangeError(`Offer ${offer.id} takes ${offer.gpus.min} to ${offer.gpus.max} GPUs`);
28
+ }
29
+ const n = BigInt(gpus);
30
+ return {
31
+ price: (offer.pricePerGpuHour * n * offerSeconds(offer)) / 3600n,
32
+ reserve: offer.reservePerGpu * n,
33
+ };
34
+ }
35
+ const MINUTE = 60n;
36
+ /**
37
+ * The GPU reservation terms for booking `gpus` of an offer. The window and the free-cancellation
38
+ * deadline are the offer's, the rate is its price per GPU-hour, and the reserve is its reserve per
39
+ * GPU times the count. A no-show costs the whole reserve after the grace period, two minutes or
40
+ * half the window when that's shorter, and a late cancellation half of it. Charges can be reported
41
+ * until the window ends, the contest window is ten minutes, and the reserve comes back at the
42
+ * window's end. The arbiter and the day-90 share are the deployment's, which Avow's approvals name.
43
+ * Throws for a count the offer doesn't take.
44
+ */
45
+ export function computeOfferTerms(offer, gpus, settlement) {
46
+ const { reserve } = computeOfferCost(offer, gpus);
47
+ const windowDuration = offerSeconds(offer);
48
+ const windowEnd = offer.startsAt + windowDuration;
49
+ const half = windowDuration / 2n;
50
+ return gpuReservationTerms({
51
+ resource: { gpu: offer.gpu, count: gpus, region: offer.region, sku: offer.sku },
52
+ currency: 'USD',
53
+ windowStart: offer.startsAt,
54
+ windowDuration,
55
+ pricePerGpuHour: offer.pricePerGpuHour,
56
+ freeCancelBy: offer.freeCancelBy,
57
+ lateCancellation: reserve / 2n,
58
+ noShow: reserve,
59
+ gracePeriod: half < 2n * MINUTE ? half : 2n * MINUTE,
60
+ chargeDeadline: windowEnd,
61
+ contestWindow: 10n * MINUTE,
62
+ releaseDate: windowEnd,
63
+ arbiter: settlement.arbiter,
64
+ day90SupplierShareBps: settlement.day90SupplierShareBps,
65
+ });
66
+ }
67
+ const text = (max) => z.string().min(1).max(max);
68
+ /** An offer as JSON, with amounts and times as decimal strings. */
69
+ export const computeOfferJson = z
70
+ .strictObject({
71
+ id: z.string().regex(/^[A-Za-z0-9_.-]{1,64}$/),
72
+ supplier: text(100),
73
+ gpu: text(64),
74
+ region: text(64),
75
+ sku: text(64),
76
+ gpus: z.strictObject({
77
+ min: z.number().int().min(1).max(1024),
78
+ max: z.number().int().min(1).max(1024),
79
+ }),
80
+ minutes: z
81
+ .number()
82
+ .int()
83
+ .min(1)
84
+ .max(7 * 24 * 60),
85
+ startsAt: u64,
86
+ freeCancelBy: u64,
87
+ pricePerGpuHour: u256,
88
+ reservePerGpu: u256,
89
+ expiry: u64,
90
+ })
91
+ .refine((o) => o.gpus.min <= o.gpus.max, 'gpus.min is at most gpus.max')
92
+ .refine((o) => o.freeCancelBy <= o.startsAt, 'free cancellation ends by the start');
93
+ /** A supplier's listing as JSON. */
94
+ export const computeOffersJson = z.strictObject({
95
+ supplier: text(100),
96
+ listedAt: u64,
97
+ offers: z.array(computeOfferJson).min(1).max(MAX_COMPUTE_OFFERS),
98
+ });
99
+ /** Reads a supplier's listing of offers, refusing ids listed twice or another supplier's offer. */
100
+ export function parseComputeOffers(json) {
101
+ const parsed = computeOffersJson.safeParse(json);
102
+ if (!parsed.success)
103
+ return { ok: false, reason: 'message.invalid' };
104
+ const listing = parsed.data;
105
+ const ids = new Set(listing.offers.map((o) => o.id));
106
+ const theirs = listing.offers.every((o) => o.supplier === listing.supplier);
107
+ return ids.size === listing.offers.length && theirs
108
+ ? { ok: true, value: listing }
109
+ : { ok: false, reason: 'message.invalid' };
110
+ }
111
+ //# sourceMappingURL=compute-offers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compute-offers.js","sourceRoot":"","sources":["../src/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,iBAAiB,EAAE,CAAA;AAC9C,CAAC"}
@@ -0,0 +1,88 @@
1
+ import { type Hex } from 'viem';
2
+ import { type ChargeKind } from './eip712.js';
3
+ import type { Side } from './types.js';
4
+ import type { Parsed } from './wire.js';
5
+ /**
6
+ * Why a business contests a charge, each reason by the code the lock's `contest` takes and logs in
7
+ * its `Paused` event, with the kinds of charge it answers and a sentence for a person. Code 0 is no
8
+ * reason, so every contest names one. Two reasons answer a late cancellation, two answer a no-show,
9
+ * and `wrong_charge` and `other` answer any kind, so every charge has a reason that fits it.
10
+ */
11
+ export declare const CONTEST_REASONS: {
12
+ readonly never_cancelled: {
13
+ readonly code: 1;
14
+ readonly answers: readonly ["lateCancellation"];
15
+ readonly says: 'The business never cancelled';
16
+ };
17
+ readonly cancelled_in_time: {
18
+ readonly code: 2;
19
+ readonly answers: readonly ["lateCancellation"];
20
+ readonly says: 'The business cancelled before free cancellation ended';
21
+ };
22
+ readonly job_started: {
23
+ readonly code: 3;
24
+ readonly answers: readonly ["noShow"];
25
+ readonly says: 'The business showed up and the job started';
26
+ };
27
+ readonly supplier_did_not_provide: {
28
+ readonly code: 4;
29
+ readonly answers: readonly ["noShow"];
30
+ readonly says: "The supplier didn't provide what the terms promise";
31
+ };
32
+ readonly wrong_charge: {
33
+ readonly code: 5;
34
+ readonly answers: 'any';
35
+ readonly says: 'The charge is the wrong kind or the wrong amount';
36
+ };
37
+ readonly other: {
38
+ readonly code: 6;
39
+ readonly answers: 'any';
40
+ readonly says: 'Another reason, which the statement sets out';
41
+ };
42
+ };
43
+ export type ContestReason = keyof typeof CONTEST_REASONS;
44
+ /** Every reason's name, in the order of their codes. */
45
+ export declare const CONTEST_REASON_NAMES: [ContestReason, ...ContestReason[]];
46
+ /** Whether a reason answers a charge of this kind. */
47
+ export declare function answersCharge(reason: ContestReason, kind: ChargeKind): boolean;
48
+ /** The reason a lock's code stands for, or null for a code that names none, such as 0. */
49
+ export declare function contestReasonOf(code: number): ContestReason | null;
50
+ /**
51
+ * What a business says when it contests a charge: the commitment, the side and the report it
52
+ * contests, its reason, and its own account in its own words. The contest carries the statement's
53
+ * hash, `contestStatementHash`, which the lock logs as its `Paused` event's `evidenceHash`, so
54
+ * anyone holding the text can check it's the statement the business contested with.
55
+ */
56
+ export interface ContestStatement {
57
+ commitmentId: Hex;
58
+ /** The side the charge is on. This release reserves only the buyer's. */
59
+ side: Side;
60
+ /** The report the contest names, which is the lock's `reportCount` when the business contests. */
61
+ reportNumber: number;
62
+ reason: ContestReason;
63
+ /** The business's account in its own words, in at most `CONTEST_TEXT_MAX_BYTES` of UTF-8. */
64
+ text: string;
65
+ }
66
+ /** The most text a statement carries, in bytes of UTF-8, which is about 600 words of English. */
67
+ export declare const CONTEST_TEXT_MAX_BYTES = 4000;
68
+ /** The label every statement hash starts from, which names the statement format's version. */
69
+ export declare const CONTEST_STATEMENT_LABEL = "avow:contest-statement:v1";
70
+ /**
71
+ * Parses a contest statement. A statement of another shape, such as one naming a reason that isn't
72
+ * one of the six or a report the lock can't hold, is refused as invalid, and one whose text the
73
+ * format doesn't take with `contest.statement_invalid`. The commitment id reads in lower case.
74
+ */
75
+ export declare function parseContestStatement(json: unknown): Parsed<ContestStatement>;
76
+ /**
77
+ * A statement's canonical JSON, the one encoding its hash covers: RFC 8785, as the terms use, with
78
+ * exactly the statement's five fields and the commitment id in lower case. Throws on a statement
79
+ * `parseContestStatement` refuses, so nothing outside the format is ever hashed.
80
+ */
81
+ export declare function encodeContestStatement(s: ContestStatement): string;
82
+ /**
83
+ * The hash a contest carries to the lock as its statement hash:
84
+ * `keccak256(abi.encode(string "avow:contest-statement:v1", string canonicalJson))`. The label
85
+ * keeps a statement's hash from ever matching a hash of the terms or of another format.
86
+ */
87
+ export declare function contestStatementHash(s: ContestStatement): Hex;
88
+ //# sourceMappingURL=contest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contest.d.ts","sourceRoot":"","sources":["../src/contest.ts"],"names":[],"mappings":"AAAA,OAAO,EA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C7F,IAAI,EAAE,MAAM,CAAA;CACb;AAED,iGAAiG;AACjG,eAAO,MAAM,sBAAsB,OAAO,CAAA;AAE1C,8FAA8F;AAC9F,eAAO,MAAM,uBAAuB,8BAA8B,CAAA;AAyClE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAK7E;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAUlE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,gBAAgB,GAAG,GAAG,CAO7D"}
@@ -0,0 +1,131 @@
1
+ import { encodeAbiParameters, keccak256 } from 'viem';
2
+ import { z } from 'zod';
3
+ import { canonicalJson, isWellFormedText } from './canonical.js';
4
+ import { MAX_REPORTS } from './eip712.js';
5
+ import { bytes32, side } from './json-fields.js';
6
+ /**
7
+ * Why a business contests a charge, each reason by the code the lock's `contest` takes and logs in
8
+ * its `Paused` event, with the kinds of charge it answers and a sentence for a person. Code 0 is no
9
+ * reason, so every contest names one. Two reasons answer a late cancellation, two answer a no-show,
10
+ * and `wrong_charge` and `other` answer any kind, so every charge has a reason that fits it.
11
+ */
12
+ export const CONTEST_REASONS = {
13
+ never_cancelled: {
14
+ code: 1,
15
+ answers: ['lateCancellation'],
16
+ says: 'The business never cancelled',
17
+ },
18
+ cancelled_in_time: {
19
+ code: 2,
20
+ answers: ['lateCancellation'],
21
+ says: 'The business cancelled before free cancellation ended',
22
+ },
23
+ job_started: {
24
+ code: 3,
25
+ answers: ['noShow'],
26
+ says: 'The business showed up and the job started',
27
+ },
28
+ supplier_did_not_provide: {
29
+ code: 4,
30
+ answers: ['noShow'],
31
+ says: "The supplier didn't provide what the terms promise",
32
+ },
33
+ wrong_charge: {
34
+ code: 5,
35
+ answers: 'any',
36
+ says: 'The charge is the wrong kind or the wrong amount',
37
+ },
38
+ other: {
39
+ code: 6,
40
+ answers: 'any',
41
+ says: 'Another reason, which the statement sets out',
42
+ },
43
+ };
44
+ /** Every reason's name, in the order of their codes. */
45
+ export const CONTEST_REASON_NAMES = Object.keys(CONTEST_REASONS);
46
+ /** Whether a reason answers a charge of this kind. */
47
+ export function answersCharge(reason, kind) {
48
+ const { answers } = CONTEST_REASONS[reason];
49
+ return answers === 'any' || answers.includes(kind);
50
+ }
51
+ /** The reason a lock's code stands for, or null for a code that names none, such as 0. */
52
+ export function contestReasonOf(code) {
53
+ return CONTEST_REASON_NAMES.find((r) => CONTEST_REASONS[r].code === code) ?? null;
54
+ }
55
+ /** The most text a statement carries, in bytes of UTF-8, which is about 600 words of English. */
56
+ export const CONTEST_TEXT_MAX_BYTES = 4000;
57
+ /** The label every statement hash starts from, which names the statement format's version. */
58
+ export const CONTEST_STATEMENT_LABEL = 'avow:contest-statement:v1';
59
+ /** A control character, C0, DEL or C1, other than tab, line feed and carriage return. */
60
+ const CONTROL = /(?![\t\n\r])\p{Cc}/u;
61
+ /**
62
+ * Whether text holds a Unicode noncharacter, which I-JSON (RFC 7493) forbids: U+FDD0 to U+FDEF,
63
+ * and the last two code points of every plane, U+FFFE and U+FFFF up to U+10FFFE and U+10FFFF.
64
+ */
65
+ function hasNoncharacter(text) {
66
+ for (const ch of text) {
67
+ const c = ch.codePointAt(0) ?? 0;
68
+ if ((c >= 0xfdd0 && c <= 0xfdef) || (c & 0xfffe) === 0xfffe)
69
+ return true;
70
+ }
71
+ return false;
72
+ }
73
+ /**
74
+ * Whether a statement's text is one the format takes: some character that isn't white space, no
75
+ * control character but tab, line feed and carriage return, no noncharacter, well-formed Unicode,
76
+ * and at most `CONTEST_TEXT_MAX_BYTES` of UTF-8. The text is hashed exactly as written, with no
77
+ * trimming or normalizing.
78
+ */
79
+ function textFits(text) {
80
+ return (/\S/.test(text) &&
81
+ !CONTROL.test(text) &&
82
+ isWellFormedText(text) &&
83
+ !hasNoncharacter(text) &&
84
+ new TextEncoder().encode(text).length <= CONTEST_TEXT_MAX_BYTES);
85
+ }
86
+ const statementJson = z.strictObject({
87
+ commitmentId: bytes32,
88
+ side,
89
+ reportNumber: z.number().int().min(1).max(MAX_REPORTS),
90
+ reason: z.enum(CONTEST_REASON_NAMES),
91
+ text: z.string(),
92
+ });
93
+ /**
94
+ * Parses a contest statement. A statement of another shape, such as one naming a reason that isn't
95
+ * one of the six or a report the lock can't hold, is refused as invalid, and one whose text the
96
+ * format doesn't take with `contest.statement_invalid`. The commitment id reads in lower case.
97
+ */
98
+ export function parseContestStatement(json) {
99
+ const parsed = statementJson.safeParse(json);
100
+ if (!parsed.success)
101
+ return { ok: false, reason: 'message.invalid' };
102
+ if (!textFits(parsed.data.text))
103
+ return { ok: false, reason: 'contest.statement_invalid' };
104
+ return { ok: true, value: parsed.data };
105
+ }
106
+ /**
107
+ * A statement's canonical JSON, the one encoding its hash covers: RFC 8785, as the terms use, with
108
+ * exactly the statement's five fields and the commitment id in lower case. Throws on a statement
109
+ * `parseContestStatement` refuses, so nothing outside the format is ever hashed.
110
+ */
111
+ export function encodeContestStatement(s) {
112
+ const parsed = parseContestStatement({
113
+ commitmentId: s.commitmentId,
114
+ side: s.side,
115
+ reportNumber: s.reportNumber,
116
+ reason: s.reason,
117
+ text: s.text,
118
+ });
119
+ if (!parsed.ok)
120
+ throw new TypeError(`The statement can't be encoded (${parsed.reason})`);
121
+ return canonicalJson(parsed.value);
122
+ }
123
+ /**
124
+ * The hash a contest carries to the lock as its statement hash:
125
+ * `keccak256(abi.encode(string "avow:contest-statement:v1", string canonicalJson))`. The label
126
+ * keeps a statement's hash from ever matching a hash of the terms or of another format.
127
+ */
128
+ export function contestStatementHash(s) {
129
+ return keccak256(encodeAbiParameters([{ type: 'string' }, { type: 'string' }], [CONTEST_STATEMENT_LABEL, encodeContestStatement(s)]));
130
+ }
131
+ //# sourceMappingURL=contest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contest.js","sourceRoot":"","sources":["../src/contest.ts"],"names":[],"mappings":"A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OAAO,SAAS,CACd,mBAAmB,CACjB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EACxC,CAAC,uBAAuB,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC,CACrD,CACF,CAAA;AACH,CAAC"}
package/dist/demo.d.ts ADDED
@@ -0,0 +1,69 @@
1
+ import type { Address } from 'viem';
2
+ import type { ComputeOffers } from './compute-offers.js';
3
+ import { type GpuReservationTerms } from './gpu-reservation.js';
4
+ import { type JobTerms } from './job.js';
5
+ /** Whole dollars in micros. */
6
+ export declare function dollars(n: number): bigint;
7
+ /**
8
+ * Demo terms for 8 H100s under the GPU reservation template: a $500 reserve, free cancellation
9
+ * until 24 hours before the start, $250 for a late cancellation, $500 for a no-show after 30
10
+ * minutes' grace and a 72-hour contest window. Usage is $3 per GPU-hour, paid separately. A
11
+ * dispute nobody rules on by day 90 splits a confirmed charge evenly, and the caller names the
12
+ * arbiter.
13
+ */
14
+ export declare function demoTerms(windowStart: bigint, arbiter: Address): GpuReservationTerms;
15
+ /**
16
+ * The same terms run in minutes for testnet: a 30-minute window, free cancellation until 10
17
+ * minutes before, 2 minutes' grace and a 10-minute contest window, which only the testnet demo
18
+ * profile accepts.
19
+ */
20
+ export declare function testnetDemoTerms(windowStart: bigint, arbiter: Address): GpuReservationTerms;
21
+ /**
22
+ * A job on testnet as Avow's test customer proposes one: a ten-minute fine-tuning run on one H100
23
+ * in the demo region, starting at `startsAt`, for $40 paid on delivery. Its reserve backs a late
24
+ * cancellation after work has started, up to $10, and a no-show, up to $6, two minutes after the
25
+ * start. Charges can be reported until ten minutes after the deadline, and the reserve comes back
26
+ * then.
27
+ */
28
+ export declare function testnetDemoJobTerms(startsAt: bigint, arbiter: Address): JobTerms;
29
+ /**
30
+ * How the demo job's clock runs from its offer, in seconds. Avow's test customer keeps an offer
31
+ * open for `quote` seconds by default, which leaves the developer's agent time to compare compute,
32
+ * book it and quote. Work starts `accept` seconds after the offer lapses, which leaves the customer
33
+ * time to verify the quote and fund its reserve, and the developer time to accept before the start.
34
+ * A scripted agent quotes in about ten seconds and the rest takes about fifteen, so both leave room
35
+ * for a slower model and a slow block.
36
+ */
37
+ export declare const DEMO_JOB_TIMING: {
38
+ readonly quote: 60n;
39
+ readonly accept: 60n;
40
+ };
41
+ /** The demo GPU supplier's business id on testnet. */
42
+ export declare const DEMO_GPU_SUPPLIER = "avow-demo-gpu";
43
+ /**
44
+ * The four offers Avow's demo GPU supplier lists for a job's window, each reserving $40 a GPU, so
45
+ * the agent has a real choice. Under the starter's defaults, a $3.00 budget per GPU-hour and $500
46
+ * of authority for a job on one H100, one is clearly best and each other fails a check that names
47
+ * why.
48
+ *
49
+ * - `h100-firm` takes 1 to 16 GPUs at $2.40, firm, over the job's whole run. It's the one that fits.
50
+ * - `h100-flex` is cheaper at $1.60 and flexible. Its window and its free cancellation both start
51
+ * and end at the job's start, so it can never pass the customer's check before the job starts,
52
+ * and the customer refuses it as still cancellable (`dependency.cancellable`).
53
+ * - `h100-later` starts after the job's deadline, so it doesn't hold the job's run
54
+ * (`dependency.does_not_fit`).
55
+ * - `h100-x16` takes exactly 16 GPUs at $2.00, which reserves $640, more than the mandate allows for
56
+ * one commitment (`mandate.over_commitment_cap`). Sixteen GPUs of `h100-firm` reserve the same.
57
+ *
58
+ * Each window but the later one starts when the job does, and each ends five minutes after its
59
+ * deadline. An offer lapses ten minutes after it's listed, or the test customer's acceptance window
60
+ * before the job starts if that comes first. That's when the job's own offer lapses, so the agent
61
+ * books compute by the time it has to quote, and the supplier has that window to accept before its
62
+ * booking starts. The supplier itself signs any GPU terms within its limits, whatever it listed.
63
+ */
64
+ export declare function demoComputeOffers(job: {
65
+ startsAt: bigint;
66
+ deliverBy: bigint;
67
+ listedAt: bigint;
68
+ }): ComputeOffers;
69
+ //# sourceMappingURL=demo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"demo.d.ts","sourceRoot":"","sources":["../src/demo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,EAAE,KAAK,mBAAmB,EAAuB,MAAM,sBAAsB,CAAA;AACpF,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,UAAU,CAAA;AAElD,+BAA+B;AAC/B,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGzC;AAKD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAkBpF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,mBAAmB,CAkB3F;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,QAAQ,CAkBhF;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe;aAAK,KAAK,EAAE,GAAG;aAAE,MAAM,EAAE,GAAG;CAAW,CAAA;AAEnE,sDAAsD;AACtD,eAAO,MAAM,iBAAiB,kBAAkB,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG,aAAa,CAgChB"}