@esseyonsui/sui-sdk-v3 0.0.0-stage → 0.1.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 (197) hide show
  1. package/README.md +45 -2
  2. package/dist/config.d.ts +82 -0
  3. package/dist/config.d.ts.map +1 -0
  4. package/dist/config.js +180 -0
  5. package/dist/errors.d.ts +38 -0
  6. package/dist/errors.d.ts.map +1 -0
  7. package/dist/errors.js +32 -0
  8. package/dist/essey.d.ts +866 -0
  9. package/dist/essey.d.ts.map +1 -0
  10. package/dist/essey.js +3592 -0
  11. package/dist/index.d.ts +9 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +4 -0
  14. package/dist/keeper.d.ts +54 -0
  15. package/dist/keeper.d.ts.map +1 -0
  16. package/dist/keeper.js +44 -0
  17. package/dist/network.d.ts +17 -0
  18. package/dist/network.d.ts.map +1 -0
  19. package/dist/network.js +62 -0
  20. package/dist/v3/addr-field.d.ts +3 -0
  21. package/dist/v3/addr-field.d.ts.map +1 -0
  22. package/dist/v3/addr-field.js +10 -0
  23. package/dist/v3/bodies.d.ts +54 -0
  24. package/dist/v3/bodies.d.ts.map +1 -0
  25. package/dist/v3/bodies.js +68 -0
  26. package/dist/v3/body-args.d.ts +29 -0
  27. package/dist/v3/body-args.d.ts.map +1 -0
  28. package/dist/v3/body-args.js +78 -0
  29. package/dist/v3/collateral/bodies.d.ts +78 -0
  30. package/dist/v3/collateral/bodies.d.ts.map +1 -0
  31. package/dist/v3/collateral/bodies.js +136 -0
  32. package/dist/v3/collateral/ext.d.ts +21 -0
  33. package/dist/v3/collateral/ext.d.ts.map +1 -0
  34. package/dist/v3/collateral/ext.js +19 -0
  35. package/dist/v3/collateral/health.d.ts +115 -0
  36. package/dist/v3/collateral/health.d.ts.map +1 -0
  37. package/dist/v3/collateral/health.js +255 -0
  38. package/dist/v3/collateral/index.d.ts +9 -0
  39. package/dist/v3/collateral/index.d.ts.map +1 -0
  40. package/dist/v3/collateral/index.js +8 -0
  41. package/dist/v3/collateral/local-health.d.ts +23 -0
  42. package/dist/v3/collateral/local-health.d.ts.map +1 -0
  43. package/dist/v3/collateral/local-health.js +27 -0
  44. package/dist/v3/collateral/math.d.ts +33 -0
  45. package/dist/v3/collateral/math.d.ts.map +1 -0
  46. package/dist/v3/collateral/math.js +38 -0
  47. package/dist/v3/collateral/openings.d.ts +27 -0
  48. package/dist/v3/collateral/openings.d.ts.map +1 -0
  49. package/dist/v3/collateral/openings.js +28 -0
  50. package/dist/v3/collateral/scan.d.ts +41 -0
  51. package/dist/v3/collateral/scan.d.ts.map +1 -0
  52. package/dist/v3/collateral/scan.js +76 -0
  53. package/dist/v3/collateral/seal.d.ts +31 -0
  54. package/dist/v3/collateral/seal.d.ts.map +1 -0
  55. package/dist/v3/collateral/seal.js +59 -0
  56. package/dist/v3/credential/issue.d.ts +27 -0
  57. package/dist/v3/credential/issue.d.ts.map +1 -0
  58. package/dist/v3/credential/issue.js +109 -0
  59. package/dist/v3/credential/membership.d.ts +37 -0
  60. package/dist/v3/credential/membership.d.ts.map +1 -0
  61. package/dist/v3/credential/membership.js +34 -0
  62. package/dist/v3/credential/pow.d.ts +10 -0
  63. package/dist/v3/credential/pow.d.ts.map +1 -0
  64. package/dist/v3/credential/pow.js +22 -0
  65. package/dist/v3/domains.d.ts +141 -0
  66. package/dist/v3/domains.d.ts.map +1 -0
  67. package/dist/v3/domains.js +158 -0
  68. package/dist/v3/ext.d.ts +29 -0
  69. package/dist/v3/ext.d.ts.map +1 -0
  70. package/dist/v3/ext.js +82 -0
  71. package/dist/v3/faucet.d.ts +66 -0
  72. package/dist/v3/faucet.d.ts.map +1 -0
  73. package/dist/v3/faucet.js +64 -0
  74. package/dist/v3/fee-witness.d.ts +5 -0
  75. package/dist/v3/fee-witness.d.ts.map +1 -0
  76. package/dist/v3/fee-witness.js +18 -0
  77. package/dist/v3/fees.d.ts +78 -0
  78. package/dist/v3/fees.d.ts.map +1 -0
  79. package/dist/v3/fees.js +190 -0
  80. package/dist/v3/index.d.ts +24 -0
  81. package/dist/v3/index.d.ts.map +1 -0
  82. package/dist/v3/index.js +23 -0
  83. package/dist/v3/inputs.d.ts +89 -0
  84. package/dist/v3/inputs.d.ts.map +1 -0
  85. package/dist/v3/inputs.js +152 -0
  86. package/dist/v3/keeper-badge.d.ts +48 -0
  87. package/dist/v3/keeper-badge.d.ts.map +1 -0
  88. package/dist/v3/keeper-badge.js +49 -0
  89. package/dist/v3/keeper-payload.d.ts +36 -0
  90. package/dist/v3/keeper-payload.d.ts.map +1 -0
  91. package/dist/v3/keeper-payload.js +116 -0
  92. package/dist/v3/kinds.d.ts +23 -0
  93. package/dist/v3/kinds.d.ts.map +1 -0
  94. package/dist/v3/kinds.js +50 -0
  95. package/dist/v3/loans/bodies.d.ts +215 -0
  96. package/dist/v3/loans/bodies.d.ts.map +1 -0
  97. package/dist/v3/loans/bodies.js +255 -0
  98. package/dist/v3/loans/offer-plan.d.ts +66 -0
  99. package/dist/v3/loans/offer-plan.d.ts.map +1 -0
  100. package/dist/v3/loans/offer-plan.js +141 -0
  101. package/dist/v3/loans/open-plan.d.ts +62 -0
  102. package/dist/v3/loans/open-plan.d.ts.map +1 -0
  103. package/dist/v3/loans/open-plan.js +92 -0
  104. package/dist/v3/loans/reclaim-plan.d.ts +65 -0
  105. package/dist/v3/loans/reclaim-plan.d.ts.map +1 -0
  106. package/dist/v3/loans/reclaim-plan.js +125 -0
  107. package/dist/v3/loans/refi-plan.d.ts +62 -0
  108. package/dist/v3/loans/refi-plan.d.ts.map +1 -0
  109. package/dist/v3/loans/refi-plan.js +157 -0
  110. package/dist/v3/loans/repay-plan.d.ts +40 -0
  111. package/dist/v3/loans/repay-plan.d.ts.map +1 -0
  112. package/dist/v3/loans/repay-plan.js +77 -0
  113. package/dist/v3/loans/settle-plan.d.ts +152 -0
  114. package/dist/v3/loans/settle-plan.d.ts.map +1 -0
  115. package/dist/v3/loans/settle-plan.js +210 -0
  116. package/dist/v3/market.d.ts +38 -0
  117. package/dist/v3/market.d.ts.map +1 -0
  118. package/dist/v3/market.js +30 -0
  119. package/dist/v3/notes/denominations.d.ts +13 -0
  120. package/dist/v3/notes/denominations.d.ts.map +1 -0
  121. package/dist/v3/notes/denominations.js +35 -0
  122. package/dist/v3/notes/deposit.d.ts +57 -0
  123. package/dist/v3/notes/deposit.d.ts.map +1 -0
  124. package/dist/v3/notes/deposit.js +103 -0
  125. package/dist/v3/notes/derive.d.ts +16 -0
  126. package/dist/v3/notes/derive.d.ts.map +1 -0
  127. package/dist/v3/notes/derive.js +34 -0
  128. package/dist/v3/notes/faucet.d.ts +3 -0
  129. package/dist/v3/notes/faucet.d.ts.map +1 -0
  130. package/dist/v3/notes/faucet.js +8 -0
  131. package/dist/v3/notes/index.d.ts +9 -0
  132. package/dist/v3/notes/index.d.ts.map +1 -0
  133. package/dist/v3/notes/index.js +8 -0
  134. package/dist/v3/notes/keys.d.ts +5 -0
  135. package/dist/v3/notes/keys.d.ts.map +1 -0
  136. package/dist/v3/notes/keys.js +11 -0
  137. package/dist/v3/notes/opening.d.ts +16 -0
  138. package/dist/v3/notes/opening.d.ts.map +1 -0
  139. package/dist/v3/notes/opening.js +62 -0
  140. package/dist/v3/notes/scan.d.ts +32 -0
  141. package/dist/v3/notes/scan.d.ts.map +1 -0
  142. package/dist/v3/notes/scan.js +71 -0
  143. package/dist/v3/notes/tree.d.ts +9 -0
  144. package/dist/v3/notes/tree.d.ts.map +1 -0
  145. package/dist/v3/notes/tree.js +31 -0
  146. package/dist/v3/notes/withdraw.d.ts +12 -0
  147. package/dist/v3/notes/withdraw.d.ts.map +1 -0
  148. package/dist/v3/notes/withdraw.js +27 -0
  149. package/dist/v3/proof-bytes.d.ts +4 -0
  150. package/dist/v3/proof-bytes.d.ts.map +1 -0
  151. package/dist/v3/proof-bytes.js +22 -0
  152. package/dist/v3/prover.d.ts +34 -0
  153. package/dist/v3/prover.d.ts.map +1 -0
  154. package/dist/v3/prover.js +76 -0
  155. package/dist/v3/relay/client.d.ts +57 -0
  156. package/dist/v3/relay/client.d.ts.map +1 -0
  157. package/dist/v3/relay/client.js +80 -0
  158. package/dist/v3/relay/possession.d.ts +21 -0
  159. package/dist/v3/relay/possession.d.ts.map +1 -0
  160. package/dist/v3/relay/possession.js +45 -0
  161. package/dist/v3/sales/auctioneer.d.ts +60 -0
  162. package/dist/v3/sales/auctioneer.d.ts.map +1 -0
  163. package/dist/v3/sales/auctioneer.js +130 -0
  164. package/dist/v3/sales/bcs.d.ts +4 -0
  165. package/dist/v3/sales/bcs.d.ts.map +1 -0
  166. package/dist/v3/sales/bcs.js +16 -0
  167. package/dist/v3/sales/bid.d.ts +51 -0
  168. package/dist/v3/sales/bid.d.ts.map +1 -0
  169. package/dist/v3/sales/bid.js +85 -0
  170. package/dist/v3/sales/bodies.d.ts +83 -0
  171. package/dist/v3/sales/bodies.d.ts.map +1 -0
  172. package/dist/v3/sales/bodies.js +78 -0
  173. package/dist/v3/sales/claim.d.ts +40 -0
  174. package/dist/v3/sales/claim.d.ts.map +1 -0
  175. package/dist/v3/sales/claim.js +44 -0
  176. package/dist/v3/sales/index.d.ts +10 -0
  177. package/dist/v3/sales/index.d.ts.map +1 -0
  178. package/dist/v3/sales/index.js +9 -0
  179. package/dist/v3/sales/open-kind.d.ts +42 -0
  180. package/dist/v3/sales/open-kind.d.ts.map +1 -0
  181. package/dist/v3/sales/open-kind.js +43 -0
  182. package/dist/v3/sales/outcome.d.ts +20 -0
  183. package/dist/v3/sales/outcome.d.ts.map +1 -0
  184. package/dist/v3/sales/outcome.js +21 -0
  185. package/dist/v3/sales/reclaim.d.ts +46 -0
  186. package/dist/v3/sales/reclaim.d.ts.map +1 -0
  187. package/dist/v3/sales/reclaim.js +57 -0
  188. package/dist/v3/sales/rows.d.ts +55 -0
  189. package/dist/v3/sales/rows.d.ts.map +1 -0
  190. package/dist/v3/sales/rows.js +98 -0
  191. package/dist/v3/sales/seller.d.ts +39 -0
  192. package/dist/v3/sales/seller.d.ts.map +1 -0
  193. package/dist/v3/sales/seller.js +67 -0
  194. package/dist/v3/stage1.d.ts +204 -0
  195. package/dist/v3/stage1.d.ts.map +1 -0
  196. package/dist/v3/stage1.js +575 -0
  197. package/package.json +33 -4
@@ -0,0 +1,9 @@
1
+ export { COINS, parseConfig, type CoinKey, type V3Config } from "./config.ts";
2
+ export { ESSEY_ERROR_CODES, EsseyError, isEsseyError, type EsseyErrorCode } from "./errors.ts";
3
+ export { Essey, type ConnectOptions, type CredentialInfo, type EsseyIo, type OpenQuote, type Recovered, type SaleOpenTx, type SaleRecord, } from "./essey.ts";
4
+ export type { KeeperActions, KeeperBadge, KeeperIo, KeeperQueue, KeeperSection, KeeperVerdict, KeeperVia, Unjudged, } from "./keeper.ts";
5
+ export type { Landed, Queued, RelayerInfo, TicketState } from "./v3/relay/client.ts";
6
+ export type { NoteSummary, PoolCommitment, PoolEvents } from "./v3/notes/scan.ts";
7
+ export type { LoanOpening, LoanOpenParams, MyLoanView, MySaleView, OpenRequest, OpenSale, PoolPosition, PoolView, PublicLoanStatus, PublicLoanView, SaleOpenParams, } from "./v3/stage1.ts";
8
+ export * as v3 from "./v3/index.ts";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/F,OAAO,EACL,KAAK,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,UAAU,GAChB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,aAAa,EACb,WAAW,EACX,QAAQ,EACR,WAAW,EACX,aAAa,EACb,aAAa,EACb,SAAS,EACT,QAAQ,GACT,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACrF,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAClF,YAAY,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,UAAU,EACV,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { COINS, parseConfig } from "./config.js";
2
+ export { ESSEY_ERROR_CODES, EsseyError, isEsseyError } from "./errors.js";
3
+ export { Essey, } from "./essey.js";
4
+ export * as v3 from "./v3/index.js";
@@ -0,0 +1,54 @@
1
+ import { type EsseyErrorCode } from "./errors.ts";
2
+ import type { Reading } from "./v3/collateral/math.ts";
3
+ import { type Coverage, type LoanReader, type ScanStop } from "./v3/collateral/scan.ts";
4
+ /** Chain reads the caller supplies. `reading` is the one the loan's market accepts (`keeper.move:161-169`). */
5
+ export type KeeperIo = {
6
+ read: LoanReader;
7
+ reading(loanId: string): Promise<Reading>;
8
+ };
9
+ /** A loan that needs a price and could not be judged: no reading, an invalid one, or one its floor cannot be compared with. */
10
+ export type Unjudged = {
11
+ loan: Coverage;
12
+ code: EsseyErrorCode | "UNKNOWN";
13
+ };
14
+ /** `refused` names why the scan stopped early; the loans found until then are kept. */
15
+ export type KeeperQueue = {
16
+ uncovered: Coverage[];
17
+ unjudged: Unjudged[];
18
+ refused: ScanStop;
19
+ };
20
+ export type KeeperSection = {
21
+ queue(): Promise<KeeperQueue>;
22
+ };
23
+ /** How a keeper's Seal read is approved: its KEEPER pass (`seal_approve_keeper_proof`) or its badge (`seal_approve_keeper`). */
24
+ export type KeeperVia = "pass" | "badge";
25
+ /** `holder` is the seed-derived address the badge is bound to; only a Seal session it makes passes `check_badge`. */
26
+ export type KeeperBadge = {
27
+ badge: string;
28
+ holder: string;
29
+ expiresMs: bigint;
30
+ };
31
+ /**
32
+ * What a keeper can do with an uncovered loan, from its own Seal read. "fault": the current keeper ciphertext is the
33
+ * retained borrower one and does not open. "third-party-ct": it does not open but a top-up wrote it, so no fault
34
+ * is provable (`collateral.move:171-177`).
35
+ */
36
+ export type KeeperVerdict = {
37
+ action: "liquidate" | "fault";
38
+ } | {
39
+ action: "skip";
40
+ reason: "healthy" | "third-party-ct";
41
+ };
42
+ export type KeeperActions = {
43
+ /** Mints a badge through the relayer's sponsor to a fresh seed-derived sender, and keeps it for `via: "badge"`. */
44
+ mintBadge(): Promise<KeeperBadge & {
45
+ digest: string;
46
+ }>;
47
+ badge(): KeeperBadge | null;
48
+ judge(p: {
49
+ loan: string;
50
+ via?: KeeperVia;
51
+ }): Promise<KeeperVerdict>;
52
+ };
53
+ export declare function keeperSection(io: KeeperIo | undefined, now: () => number): KeeperSection;
54
+ //# sourceMappingURL=keeper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keeper.d.ts","sourceRoot":"","sources":["../src/keeper.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,QAAQ,EACd,MAAM,yBAAyB,CAAC;AAKjC,+GAA+G;AAC/G,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE,CAAC;AAEvF,+HAA+H;AAC/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
@@ -0,0 +1,44 @@
1
+ import { EsseyError, isEsseyError } from "./errors.js";
2
+ import { covered, scanCoverage, } from "./v3/collateral/scan.js";
3
+ /** ACTIVE and REFI_BIDDING (`loan.move:28,34`): the states `keeper.move:152` accepts. */
4
+ const SEIZABLE_STATES = new Set([2, 8]);
5
+ /** `keeper.move:155` tests these two before the price, so such a loan is listed with `io.reading` never called. */
6
+ const uncoveredAtAnyPrice = (c, nowMs) => nowMs >= c.hbExpiryMs || c.floorPrice === 0n;
7
+ async function reading(io, loanId) {
8
+ const r = await io.reading(loanId);
9
+ if (typeof r.spot !== "bigint" || typeof r.ema !== "bigint" || r.spot <= 0n || r.ema <= 0n)
10
+ throw new EsseyError("INVALID_ARGUMENT", "reading.spot or .ema is not a bigint above 0 (price.move:47)");
11
+ return r;
12
+ }
13
+ const codeOf = (err) => (isEsseyError(err) ? err.code : "UNKNOWN");
14
+ export function keeperSection(io, now) {
15
+ return {
16
+ async queue() {
17
+ if (!io)
18
+ throw new EsseyError("NOT_SET_UP", "no chain reader: connect with io.keeper to read loans");
19
+ const nowMs = BigInt(now());
20
+ const uncovered = [];
21
+ const unjudged = [];
22
+ const scan = scanCoverage(io.read);
23
+ for (;;) {
24
+ const step = await scan.next();
25
+ if (step.done)
26
+ return { uncovered, unjudged, refused: step.value };
27
+ const c = step.value;
28
+ if (!SEIZABLE_STATES.has(c.state))
29
+ continue;
30
+ if (uncoveredAtAnyPrice(c, nowMs)) {
31
+ uncovered.push(c);
32
+ continue;
33
+ }
34
+ try {
35
+ if (!covered(c, await reading(io, c.loanId), nowMs))
36
+ uncovered.push(c);
37
+ }
38
+ catch (err) {
39
+ unjudged.push({ loan: c, code: codeOf(err) });
40
+ }
41
+ }
42
+ },
43
+ };
44
+ }
@@ -0,0 +1,17 @@
1
+ export declare const TESTNET: {
2
+ readonly chainId: "4c78adac";
3
+ readonly chainIdentifier: "69WiPg3DAQiwdxfncX6wYQ2siKwAe6L9BZthQea3JNMD";
4
+ };
5
+ export type Fetch = (url: string, init?: RequestInit) => Promise<Response>;
6
+ export type JsonReply = {
7
+ status: number;
8
+ body: Record<string, unknown>;
9
+ };
10
+ export declare function assertTestnet(network: unknown): asserts network is "testnet";
11
+ /** https anywhere, http on this machine only. A `.onion` host is refused: this build has no Tor transport. */
12
+ export declare function serviceUrl(raw: string, what: string): URL;
13
+ export declare const getJson: (fetch: Fetch, url: string) => Promise<JsonReply>;
14
+ export declare const postJson: (fetch: Fetch, url: string, body: unknown) => Promise<JsonReply>;
15
+ export declare function decimal(value: unknown, what: string): bigint;
16
+ export declare function address(raw: string, what: string): string;
17
+ //# sourceMappingURL=network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO;;;CAGV,CAAC;AAEX,MAAM,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE3E,MAAM,MAAM,SAAS,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAAC;AAE1E,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,SAAS,CAE5E;AAED,8GAA8G;AAC9G,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,GAAG,CAazD;AAoBD,eAAO,MAAM,OAAO,GAAI,OAAO,KAAK,EAAE,KAAK,MAAM,uBAAwC,CAAC;AAE1F,eAAO,MAAM,QAAQ,GAAI,OAAO,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,OAAO,uBAK7D,CAAC;AAEL,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5D;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIzD"}
@@ -0,0 +1,62 @@
1
+ import { EsseyError } from "./errors.js";
2
+ export const TESTNET = {
3
+ chainId: "4c78adac",
4
+ chainIdentifier: "69WiPg3DAQiwdxfncX6wYQ2siKwAe6L9BZthQea3JNMD",
5
+ };
6
+ export function assertTestnet(network) {
7
+ if (network !== "testnet")
8
+ throw new EsseyError("NETWORK_REFUSED", "refused: V3 runs on testnet only");
9
+ }
10
+ /** https anywhere, http on this machine only. A `.onion` host is refused: this build has no Tor transport. */
11
+ export function serviceUrl(raw, what) {
12
+ let url;
13
+ try {
14
+ url = new URL(raw);
15
+ }
16
+ catch {
17
+ throw new EsseyError("INVALID_ARGUMENT", `${what} is not a URL`);
18
+ }
19
+ if (url.hostname.endsWith(".onion"))
20
+ throw new EsseyError("ONION_UNAVAILABLE", `${what}: no Tor transport in this build`);
21
+ const local = url.hostname === "127.0.0.1" || url.hostname === "localhost";
22
+ if (url.protocol !== "https:" && !(local && url.protocol === "http:"))
23
+ throw new EsseyError("INVALID_ARGUMENT", `${what} must be https`);
24
+ return url;
25
+ }
26
+ async function call(fetch, url, init) {
27
+ let res;
28
+ try {
29
+ res = await fetch(url, init);
30
+ }
31
+ catch {
32
+ throw new EsseyError("SERVICE_UNREACHABLE", "service did not answer");
33
+ }
34
+ try {
35
+ const body = await res.json();
36
+ if (body === null || typeof body !== "object" || Array.isArray(body))
37
+ throw new Error("shape");
38
+ return { status: res.status, body: body };
39
+ }
40
+ catch {
41
+ throw new EsseyError("SERVICE_UNREACHABLE", "service answer is not a JSON object", {
42
+ status: res.status,
43
+ });
44
+ }
45
+ }
46
+ export const getJson = (fetch, url) => call(fetch, url, { method: "GET" });
47
+ export const postJson = (fetch, url, body) => call(fetch, url, {
48
+ method: "POST",
49
+ headers: { "content-type": "application/json" },
50
+ body: JSON.stringify(body),
51
+ });
52
+ export function decimal(value, what) {
53
+ if (typeof value !== "string" || !/^(0|[1-9][0-9]*)$/.test(value))
54
+ throw new EsseyError("INVALID_ARGUMENT", `${what} is not a canonical decimal string`);
55
+ return BigInt(value);
56
+ }
57
+ export function address(raw, what) {
58
+ const hex = raw.replace(/^0x/i, "").toLowerCase();
59
+ if (!/^[0-9a-f]{1,64}$/.test(hex))
60
+ throw new EsseyError("INVALID_ARGUMENT", `${what} is not an address`);
61
+ return `0x${hex.padStart(64, "0")}`;
62
+ }
@@ -0,0 +1,3 @@
1
+ /** `essey_v3_config::domains::addr_field`. BCS of an address is its 32 raw bytes. */
2
+ export declare function addrField(address: string): bigint;
3
+ //# sourceMappingURL=addr-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addr-field.d.ts","sourceRoot":"","sources":["../../src/v3/addr-field.ts"],"names":[],"mappings":"AAIA,qFAAqF;AACrF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKjD"}
@@ -0,0 +1,10 @@
1
+ import { keccak_256 } from "@noble/hashes/sha3.js";
2
+ import { R } from "./domains.js";
3
+ /** `essey_v3_config::domains::addr_field`. BCS of an address is its 32 raw bytes. */
4
+ export function addrField(address) {
5
+ const hex = address.replace(/^0x/i, "");
6
+ if (!/^[0-9a-fA-F]{1,64}$/.test(hex))
7
+ throw new Error("address must be 32 bytes");
8
+ const digest = keccak_256(Uint8Array.from(Buffer.from(hex.padStart(64, "0"), "hex")));
9
+ return BigInt(`0x${Buffer.from(digest).toString("hex")}`) % R;
10
+ }
@@ -0,0 +1,54 @@
1
+ import type { CoinKey } from "../config.ts";
2
+ import type { Js4Statement } from "./inputs.ts";
3
+ import { type RelayKind } from "./kinds.ts";
4
+ /** A snarkjs Groth16 proof as `groth16.fullProve` returns it. */
5
+ export type SnarkProof = {
6
+ pi_a: string[];
7
+ pi_b: string[][];
8
+ pi_c: string[];
9
+ protocol: string;
10
+ curve: string;
11
+ };
12
+ export type Proved = {
13
+ proof: SnarkProof;
14
+ publicSignals: string[];
15
+ };
16
+ /** `vk` is the verifier kind id as a canonical decimal string, the form the relayer parses. */
17
+ export type WireProof = {
18
+ vk: string;
19
+ proof: SnarkProof & {
20
+ publicSignals: string[];
21
+ };
22
+ };
23
+ /** The `POST /v3/relay` envelope of master §2.6. Every value is a canonical decimal or lowercase 0x-hex. */
24
+ export type RelayBody = {
25
+ v: 3;
26
+ kind: RelayKind;
27
+ pool: CoinKey;
28
+ proofs: WireProof[];
29
+ args: Record<string, string>;
30
+ relayerFee: string;
31
+ wait: boolean;
32
+ };
33
+ export type Encs = [string, string, string, string];
34
+ export type SpendBody = {
35
+ pool: CoinKey;
36
+ proved: Proved;
37
+ statement: Js4Statement;
38
+ /** One 128-byte ciphertext per inserted leaf, in leaf order. */
39
+ encs: Encs;
40
+ relayerFee: bigint;
41
+ wait: boolean;
42
+ };
43
+ export declare function wireProof(vk: number, { proof, publicSignals }: Proved): WireProof;
44
+ /** A membership pass proof as v3api parses it: snarkjs's projective third coordinate dropped. */
45
+ export type PassProof = {
46
+ pi_a: string[];
47
+ pi_b: string[][];
48
+ pi_c: string[];
49
+ };
50
+ export declare function passProof({ proof }: Proved): PassProof;
51
+ export declare function ciphertext(ct: string): string;
52
+ export declare function transfer(p: SpendBody): RelayBody;
53
+ export declare function withdraw(p: SpendBody): RelayBody;
54
+ //# sourceMappingURL=bodies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bodies.d.ts","sourceRoot":"","sources":["../../src/v3/bodies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAI5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAE3D,iEAAiE;AACjE,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;IACjB,IAAI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AAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAE7E,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,GAAG,SAAS,CAEtD;AAID,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAG7C;AAoCD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,CAGhD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,CAOhD"}
@@ -0,0 +1,68 @@
1
+ import { EsseyError } from "../errors.js";
2
+ import { address } from "../network.js";
3
+ import { ENC_BYTES, VK } from "./kinds.js";
4
+ const invalid = (what) => {
5
+ throw new EsseyError("INVALID_ARGUMENT", what);
6
+ };
7
+ export function wireProof(vk, { proof, publicSignals }) {
8
+ if (proof.protocol !== "groth16" || proof.curve !== "bn128")
9
+ invalid("proof is not groth16 on bn128");
10
+ const { pi_a, pi_b, pi_c } = proof;
11
+ return { vk: String(vk), proof: { pi_a, pi_b, pi_c, protocol: "groth16", curve: "bn128", publicSignals } };
12
+ }
13
+ export function passProof({ proof }) {
14
+ return { pi_a: proof.pi_a.slice(0, 2), pi_b: proof.pi_b.slice(0, 2), pi_c: proof.pi_c.slice(0, 2) };
15
+ }
16
+ const ENC_HEX = new RegExp(`^0x[0-9a-f]{${ENC_BYTES * 2}}$`);
17
+ export function ciphertext(ct) {
18
+ if (!ENC_HEX.test(ct))
19
+ invalid("a note ciphertext is 128 lowercase hex bytes");
20
+ return ct;
21
+ }
22
+ function spendArgs(s, encs) {
23
+ if (encs.length !== 4)
24
+ invalid("a spend carries 4 ciphertexts");
25
+ encs.forEach(ciphertext);
26
+ return {
27
+ root: s.root.toString(),
28
+ nullifier0: s.n0.toString(),
29
+ nullifier1: s.n1.toString(),
30
+ commitment0: s.leaves[0].toString(),
31
+ commitment1: s.leaves[1].toString(),
32
+ commitment2: s.leaves[2].toString(),
33
+ commitment3: s.leaves[3].toString(),
34
+ ephX: s.ephX.toString(),
35
+ ephY: s.ephY.toString(),
36
+ feeCt: s.feeCt.toString(),
37
+ feeCommit: s.feeCommit.toString(),
38
+ enc0: encs[0],
39
+ enc1: encs[1],
40
+ enc2: encs[2],
41
+ enc3: encs[3],
42
+ };
43
+ }
44
+ function envelope(kind, p, args) {
45
+ return {
46
+ v: 3,
47
+ kind,
48
+ pool: p.pool,
49
+ proofs: [wireProof(VK.js4, p.proved)],
50
+ args,
51
+ relayerFee: p.relayerFee.toString(),
52
+ wait: p.wait,
53
+ };
54
+ }
55
+ export function transfer(p) {
56
+ if (p.statement.amount !== 0n)
57
+ invalid("a transfer statement moves no public amount");
58
+ return envelope("transfer", p, spendArgs(p.statement, p.encs));
59
+ }
60
+ export function withdraw(p) {
61
+ if (p.statement.amount <= 0n)
62
+ invalid("a withdraw statement needs an amount");
63
+ return envelope("withdraw", p, {
64
+ ...spendArgs(p.statement, p.encs),
65
+ amount: p.statement.amount.toString(),
66
+ recipient: address(p.statement.recipient, "recipient"),
67
+ });
68
+ }
@@ -0,0 +1,29 @@
1
+ import { type CoinKey } from "../config.ts";
2
+ import { type Proved, type RelayBody, type WireProof } from "./bodies.ts";
3
+ import { type RelayKind } from "./kinds.ts";
4
+ export type Args = Record<string, string>;
5
+ export declare const invalid: (what: string) => never;
6
+ export declare const hex: (bytes: Uint8Array) => string;
7
+ export declare function bytesOf(bytes: Uint8Array, what: string, min: number, max: number): string;
8
+ export declare function encOf(bytes: Uint8Array, what: string): string;
9
+ export declare function fieldOf(n: bigint, what: string): string;
10
+ export declare function u64Of(n: bigint, what: string): string;
11
+ /** The relayer accepts 1..8 canonical field decimals (`payload.ts` `parseProof`). */
12
+ export declare function proofOf(vk: number, proved: Proved): WireProof;
13
+ export declare function envelope(kind: RelayKind, pool: CoinKey, proofs: WireProof[], args: Args, relayerFee: bigint, wait: boolean): RelayBody;
14
+ export type Pass = {
15
+ proved: Proved;
16
+ tag: bigint;
17
+ expiryMs: bigint;
18
+ n0: bigint;
19
+ };
20
+ export declare function passArgs(pass: Pass): Args;
21
+ /** Threshold many: each pinned server's slot (`seal_servers::public_keys` order) and the 48-byte G1 key it derived. */
22
+ export type DerivedKeys = {
23
+ index: number;
24
+ key: Uint8Array;
25
+ }[];
26
+ export declare function keyArgs(keys: DerivedKeys): {
27
+ [x: string]: string;
28
+ };
29
+ //# sourceMappingURL=body-args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-args.d.ts","sourceRoot":"","sources":["../../src/v3/body-args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,EAAa,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAErF,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvD,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE1C,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,KAAG,KAEtC,CAAC;AAEF,eAAO,MAAM,GAAG,GAAI,OAAO,UAAU,WAA8C,CAAC;AAEpF,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIzF;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI7D;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAGrD;AAYD,qFAAqF;AACrF,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAS7D;AAED,wBAAgB,QAAQ,CACtB,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,SAAS,EAAE,EACnB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,OAAO,GACZ,SAAS,CAUX;AAED,MAAM,MAAM,IAAI,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAMzC;AAED,uHAAuH;AACvH,MAAM,MAAM,WAAW,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,UAAU,CAAA;CAAE,EAAE,CAAC;AAE/D,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW;;EAMxC"}
@@ -0,0 +1,78 @@
1
+ import { COINS } from "../config.js";
2
+ import { EsseyError } from "../errors.js";
3
+ import { wireProof } from "./bodies.js";
4
+ import { R } from "./domains.js";
5
+ import { ENC_BYTES } from "./kinds.js";
6
+ const U64 = 1n << 64n;
7
+ const SIGNALS = 8;
8
+ export const invalid = (what) => {
9
+ throw new EsseyError("INVALID_ARGUMENT", what);
10
+ };
11
+ export const hex = (bytes) => `0x${Buffer.from(bytes).toString("hex")}`;
12
+ export function bytesOf(bytes, what, min, max) {
13
+ if (!(bytes instanceof Uint8Array) || bytes.length < min || bytes.length > max)
14
+ invalid(`${what} is not ${min}..${max} bytes`);
15
+ return hex(bytes);
16
+ }
17
+ export function encOf(bytes, what) {
18
+ if (!(bytes instanceof Uint8Array) || bytes.length !== ENC_BYTES)
19
+ invalid(`${what} is not a 128-byte note ciphertext`);
20
+ return hex(bytes);
21
+ }
22
+ export function fieldOf(n, what) {
23
+ if (typeof n !== "bigint" || n < 0n || n >= R)
24
+ invalid(`${what} is not a field element`);
25
+ return n.toString();
26
+ }
27
+ export function u64Of(n, what) {
28
+ if (typeof n !== "bigint" || n < 0n || n >= U64)
29
+ invalid(`${what} is not a u64`);
30
+ return n.toString();
31
+ }
32
+ function poolOf(pool) {
33
+ if (!COINS.includes(pool))
34
+ invalid("pool is not tusdsui, usdc or sui");
35
+ return pool;
36
+ }
37
+ function waitOf(wait) {
38
+ if (typeof wait !== "boolean")
39
+ invalid("wait is not a boolean");
40
+ return wait;
41
+ }
42
+ /** The relayer accepts 1..8 canonical field decimals (`payload.ts` `parseProof`). */
43
+ export function proofOf(vk, proved) {
44
+ const signals = proved.publicSignals;
45
+ if (!Array.isArray(signals) || signals.length < 1 || signals.length > SIGNALS)
46
+ invalid("public signals must be 1..8");
47
+ signals.forEach((s, i) => {
48
+ if (typeof s !== "string" || !/^(0|[1-9][0-9]*)$/.test(s) || BigInt(s) >= R)
49
+ invalid(`publicSignals[${i}] is not a canonical field`);
50
+ });
51
+ return wireProof(vk, proved);
52
+ }
53
+ export function envelope(kind, pool, proofs, args, relayerFee, wait) {
54
+ return {
55
+ v: 3,
56
+ kind,
57
+ pool: poolOf(pool),
58
+ proofs,
59
+ args,
60
+ relayerFee: u64Of(relayerFee, "relayerFee"),
61
+ wait: waitOf(wait),
62
+ };
63
+ }
64
+ export function passArgs(pass) {
65
+ return {
66
+ tag: fieldOf(pass.tag, "tag"),
67
+ expiryMs: u64Of(pass.expiryMs, "expiryMs"),
68
+ passN0: fieldOf(pass.n0, "passN0"),
69
+ };
70
+ }
71
+ export function keyArgs(keys) {
72
+ if (keys.length !== 2)
73
+ invalid("exactly two derived keys");
74
+ return {
75
+ ...Object.fromEntries(keys.map((k, i) => [`keyIndex${i}`, u64Of(BigInt(k.index), `keyIndex${i}`)])),
76
+ ...Object.fromEntries(keys.map((k, i) => [`derivedKey${i}`, bytesOf(k.key, `derivedKey${i}`, 48, 48)])),
77
+ };
78
+ }
@@ -0,0 +1,78 @@
1
+ import type { CoinKey } from "../../config.ts";
2
+ import { type Proved, type RelayBody } from "../bodies.ts";
3
+ import type { SeizeEncs } from "./ext.ts";
4
+ import type { HealthStatement } from "./health.ts";
5
+ type Args = Record<string, string>;
6
+ /** What a CollLock proof spends and makes: `note` is the collateral note at open and the added note in a top-up. */
7
+ export type CollLockSpend = {
8
+ root: bigint;
9
+ n0: bigint;
10
+ n1: bigint;
11
+ note: bigint;
12
+ change: bigint;
13
+ feeNote: bigint;
14
+ ephX: bigint;
15
+ ephY: bigint;
16
+ feeCt: bigint;
17
+ };
18
+ /** No relayer fee: only `lock_collateral` pays one (`liquidation.move:4-6`). */
19
+ export type HealthBody = {
20
+ pool: CoinKey;
21
+ loan: string;
22
+ market: string;
23
+ proved: Proved;
24
+ statement: HealthStatement;
25
+ wait: boolean;
26
+ };
27
+ /**
28
+ * The `liquidation::lock_collateral` slice of a `loan_open` envelope (`liquidation.move:62-87`): the CollLock
29
+ * spend, the keeper ciphertext, the claimed price and the Health OPEN rows. The request half is the loans module's.
30
+ */
31
+ export declare function openLockArgs(p: {
32
+ lock: CollLockSpend;
33
+ encs: [Uint8Array, Uint8Array];
34
+ keeperCt: Uint8Array;
35
+ pClaim: bigint;
36
+ statement: HealthStatement;
37
+ priceUpdate: Uint8Array;
38
+ }): Args;
39
+ /** `encs` pairs with `[out0, fee_note]`. */
40
+ export declare function release(p: HealthBody & {
41
+ encs: [Uint8Array, Uint8Array];
42
+ }): RelayBody;
43
+ export declare function heartbeat(p: HealthBody & {
44
+ encs: [Uint8Array, Uint8Array];
45
+ k: number;
46
+ expiryMs: bigint;
47
+ priceUpdate: Uint8Array;
48
+ }): RelayBody;
49
+ /** `lockEncs` pairs with the spend's `[change, fee_note]`, `encs` with the re-locked `[out0, fee_note]`. */
50
+ export declare function topup(p: HealthBody & {
51
+ lock: CollLockSpend;
52
+ lockProved: Proved;
53
+ lockEncs: [Uint8Array, Uint8Array];
54
+ keeperCt: Uint8Array;
55
+ encs: [Uint8Array, Uint8Array];
56
+ }): RelayBody;
57
+ /** `loan_topup_borrower`: the borrower pass (proof 0, `tag`, `expiryMs`, `passN0`), then `topup` unchanged. */
58
+ export declare function topupBorrower(p: Parameters<typeof topup>[0] & {
59
+ pass: {
60
+ proved: Proved;
61
+ tag: bigint;
62
+ expiryMs: bigint;
63
+ n0: bigint;
64
+ };
65
+ }): RelayBody;
66
+ type SeizeBody = HealthBody & {
67
+ encs: SeizeEncs;
68
+ pSpot: bigint;
69
+ pEma: bigint;
70
+ priceUpdate: Uint8Array;
71
+ };
72
+ export declare const liquidate: (p: SeizeBody) => RelayBody;
73
+ export declare const faultLiquidate: (p: SeizeBody) => RelayBody;
74
+ export declare const claimDefault: (p: SeizeBody & {
75
+ nowS: bigint;
76
+ }) => RelayBody;
77
+ export {};
78
+ //# sourceMappingURL=bodies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bodies.d.ts","sourceRoot":"","sources":["../../../src/v3/collateral/bodies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAa,KAAK,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAItE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAMnD,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAGnC,oHAAoH;AACpH,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,gFAAgF;AAChF,MAAM,MAA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