@integraledger/profile-facilitator 0.4.0 → 0.5.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 (90) hide show
  1. package/README.md +642 -456
  2. package/dist/answers.d.ts +11 -4
  3. package/dist/answers.js +24 -0
  4. package/dist/core.d.ts +51 -0
  5. package/dist/core.js +758 -0
  6. package/dist/http.d.ts +20 -3
  7. package/dist/http.js +32 -7
  8. package/dist/index.d.ts +12 -36
  9. package/dist/index.js +9 -162
  10. package/dist/module.d.ts +372 -0
  11. package/dist/module.js +13 -0
  12. package/dist/modules/algorand/index.d.ts +22 -0
  13. package/dist/modules/algorand/index.js +247 -0
  14. package/dist/modules/algorand/own.d.ts +26 -0
  15. package/dist/modules/algorand/own.js +231 -0
  16. package/dist/modules/aptos/index.d.ts +23 -0
  17. package/dist/modules/aptos/index.js +232 -0
  18. package/dist/modules/cardano/index.d.ts +18 -0
  19. package/dist/modules/cardano/index.js +124 -0
  20. package/dist/modules/casper/index.d.ts +120 -0
  21. package/dist/modules/casper/index.js +442 -0
  22. package/dist/modules/concordium/index.d.ts +16 -0
  23. package/dist/modules/concordium/index.js +77 -0
  24. package/dist/modules/erc7710/index.d.ts +26 -0
  25. package/dist/modules/erc7710/index.js +220 -0
  26. package/dist/modules/evm/forms.d.ts +74 -0
  27. package/dist/modules/evm/forms.js +182 -0
  28. package/dist/modules/evm/index.d.ts +40 -0
  29. package/dist/modules/evm/index.js +148 -0
  30. package/dist/modules/evm/node.d.ts +29 -0
  31. package/dist/modules/evm/node.js +222 -0
  32. package/dist/modules/hedera/executor.d.ts +63 -0
  33. package/dist/modules/hedera/executor.js +343 -0
  34. package/dist/modules/hedera/index.d.ts +23 -0
  35. package/dist/modules/hedera/index.js +136 -0
  36. package/dist/modules/hedera/mirror.d.ts +32 -0
  37. package/dist/modules/hedera/mirror.js +111 -0
  38. package/dist/modules/index.d.ts +23 -0
  39. package/dist/modules/index.js +24 -0
  40. package/dist/modules/lnbtc/index.d.ts +10 -0
  41. package/dist/modules/lnbtc/index.js +111 -0
  42. package/dist/modules/near/index.d.ts +18 -0
  43. package/dist/modules/near/index.js +246 -0
  44. package/dist/modules/polkadot/index.d.ts +12 -0
  45. package/dist/modules/polkadot/index.js +149 -0
  46. package/dist/modules/polkadot/rail.d.ts +40 -0
  47. package/dist/{polkadot.js → modules/polkadot/rail.js} +214 -288
  48. package/dist/modules/solana/index.d.ts +60 -0
  49. package/dist/modules/solana/index.js +304 -0
  50. package/dist/modules/solana/reader.d.ts +25 -0
  51. package/dist/modules/solana/reader.js +194 -0
  52. package/dist/modules/solana/state.d.ts +6 -0
  53. package/dist/modules/solana/state.js +103 -0
  54. package/dist/modules/starknet/index.d.ts +35 -0
  55. package/dist/modules/starknet/index.js +541 -0
  56. package/dist/modules/starknet/node.d.ts +78 -0
  57. package/dist/modules/starknet/node.js +339 -0
  58. package/dist/modules/stellar/index.d.ts +44 -0
  59. package/dist/modules/stellar/index.js +481 -0
  60. package/dist/modules/stellar/node.d.ts +57 -0
  61. package/dist/modules/stellar/node.js +151 -0
  62. package/dist/modules/sui/index.d.ts +16 -0
  63. package/dist/modules/sui/index.js +309 -0
  64. package/dist/modules/sui/node.d.ts +49 -0
  65. package/dist/modules/sui/node.js +197 -0
  66. package/dist/modules/ton/index.d.ts +16 -0
  67. package/dist/modules/ton/index.js +73 -0
  68. package/dist/modules/tron/index.d.ts +12 -0
  69. package/dist/modules/tron/index.js +120 -0
  70. package/dist/modules/tron/rail.d.ts +32 -0
  71. package/dist/{tron.js → modules/tron/rail.js} +206 -195
  72. package/dist/modules/xrpl/index.d.ts +28 -0
  73. package/dist/modules/xrpl/index.js +299 -0
  74. package/dist/modules/xrpl/node.d.ts +52 -0
  75. package/dist/modules/xrpl/node.js +231 -0
  76. package/dist/modules/xrpl/upto.d.ts +5 -0
  77. package/dist/modules/xrpl/upto.js +269 -0
  78. package/dist/record.d.ts +131 -0
  79. package/dist/record.js +330 -0
  80. package/dist/unexpected.d.ts +3 -2
  81. package/dist/unexpected.js +2 -1
  82. package/dist/wrapper.d.ts +68 -0
  83. package/dist/wrapper.js +126 -0
  84. package/package.json +47 -12
  85. package/dist/polkadot.d.ts +0 -21
  86. package/dist/store.d.ts +0 -59
  87. package/dist/store.js +0 -103
  88. package/dist/tron.d.ts +0 -12
  89. /package/dist/{base58check.d.ts → modules/tron/base58check.d.ts} +0 -0
  90. /package/dist/{base58check.js → modules/tron/base58check.js} +0 -0
package/dist/store.d.ts DELETED
@@ -1,59 +0,0 @@
1
- import { type OperatorLog, type SettleAnswer } from "./answers.js";
2
- /** The table, and the index the sweep reads: the rows whose answer is final, by `until`. */
3
- export declare const SCHEMA = "CREATE TABLE IF NOT EXISTS settlement (\n network text NOT NULL,\n id text NOT NULL,\n answer jsonb,\n until timestamptz NOT NULL,\n since bigint,\n unread bigint[] NOT NULL DEFAULT '{}',\n PRIMARY KEY (network, id)\n);\nCREATE INDEX IF NOT EXISTS settlement_final_until ON settlement (until) WHERE answer IS NOT NULL AND answer->>'errorReason' IS DISTINCT FROM 'settlement_pending'";
4
- /** The bound on acquiring a connection, on each query as the client waits for it, and on each statement in the server. */
5
- export declare const STORE_TIMEOUT_MS = 5000;
6
- /** How long a row whose answer is final is kept after `until`. */
7
- export declare const KEEP_AFTER_UNTIL_MS: number;
8
- /**
9
- * What the table holds for an id: nothing, a claim whose answer is not written yet, or the answer. `since` is, for a
10
- * Polkadot extrinsic, the first block the scan has not yet read at finality: at the claim, the block after the finalized
11
- * head read before validation (never before the era's birth), and later moved on past the blocks read at finality. It
12
- * is null for Tron. `unread` is, for a Polkadot extrinsic, the finalized blocks below `since` that could not be read:
13
- * none of them is shown to lack the extrinsic, so each is read again. It is empty for Tron.
14
- */
15
- export type Stored = {
16
- state: "none";
17
- } | {
18
- state: "claimed";
19
- since: number | null;
20
- unread: number[];
21
- } | {
22
- state: "answered";
23
- answer: SettleAnswer;
24
- since: number | null;
25
- unread: number[];
26
- };
27
- export interface SettlementStore {
28
- read(network: string, id: string): Promise<Stored>;
29
- /** True when this call inserted the row, and so owns the submission. */
30
- claim(network: string, id: string, until: Date, since?: number): Promise<boolean>;
31
- /** Writes the answer unless the row already holds a final one. True when this call wrote it. */
32
- answer(network: string, id: string, answer: SettleAnswer): Promise<boolean>;
33
- /**
34
- * Moves `since` on to `to`, never back, after a scan that read every finalized block from `from` up to `to` except
35
- * `unread`, and read `resolved`, blocks of the stored `unread` it read again. The stored `unread` gains `unread`,
36
- * and keeps every block this scan did not read: a concurrent scan's record is never lost.
37
- */
38
- advance(network: string, id: string, scan: {
39
- from: number;
40
- to: number;
41
- unread: number[];
42
- resolved: number[];
43
- }): Promise<void>;
44
- /** Drops the rows whose answer is final and whose `until` is more than `KEEP_AFTER_UNTIL_MS` past. */
45
- drop(): Promise<void>;
46
- close(): Promise<void>;
47
- }
48
- /**
49
- * Opens the pool and creates the table. `log` receives an error the pool reports for an idle connection, and a sweep
50
- * that fails; the sweep runs again a minute later.
51
- */
52
- export declare function openStore(url: string, log?: OperatorLog): Promise<SettlementStore>;
53
- /**
54
- * The part of `settleWaitMs` kept for writing the answer once the wait for the chain ends: a second, or a quarter of a
55
- * shorter wait. The node calls and the waits end that much before the deadline, so the answer is stored, then given.
56
- */
57
- export declare function answerReserve(settleWaitMs: number): number;
58
- /** A store call bounded by `STORE_TIMEOUT_MS` and by what is left before `deadline` (a `performance.now()` time). */
59
- export declare function inTime<T>(p: Promise<T>, deadline: number): Promise<T>;
package/dist/store.js DELETED
@@ -1,103 +0,0 @@
1
- /**
2
- * The deduplication table: one row per settled payment, keyed by network and transaction id, holding the answer the
3
- * first `/settle` gave. A row is claimed by one conditional insert, so concurrent settles of one payment submit once,
4
- * and a claim is never removed: a submission the node refuses, or that cannot have reached it, is stored as the row's
5
- * answer. A final answer is never replaced; a pending one is replaced by what a later read of the chain shows, or by
6
- * the stored answer to a broadcast or submission the node refused or never received. A row whose answer is final is
7
- * kept until `KEEP_AFTER_UNTIL_MS` after its validity window has ended, so a repeat in that time reads the stored
8
- * answer before the expiration check and the node reads are made again. A row whose answer is not final (a claim with
9
- * no answer yet, or `settlement_pending`) is kept until a read of the chain, or the answer to a refused or unsent
10
- * broadcast or submission, makes it final, so a repeat never finds its id missing. Every call to the database is
11
- * bounded by `STORE_TIMEOUT_MS`.
12
- */
13
- import pg from "pg";
14
- import { isPending, operatorLine } from "./answers.js";
15
- import { within } from "./http.js";
16
- /** A row's answer is final when it is written and is not `settlement_pending`. */
17
- const FINAL = "answer IS NOT NULL AND answer->>'errorReason' IS DISTINCT FROM 'settlement_pending'";
18
- /** The table, and the index the sweep reads: the rows whose answer is final, by `until`. */
19
- export const SCHEMA = `CREATE TABLE IF NOT EXISTS settlement (
20
- network text NOT NULL,
21
- id text NOT NULL,
22
- answer jsonb,
23
- until timestamptz NOT NULL,
24
- since bigint,
25
- unread bigint[] NOT NULL DEFAULT '{}',
26
- PRIMARY KEY (network, id)
27
- );
28
- CREATE INDEX IF NOT EXISTS settlement_final_until ON settlement (until) WHERE ${FINAL}`;
29
- /** The bound on acquiring a connection, on each query as the client waits for it, and on each statement in the server. */
30
- export const STORE_TIMEOUT_MS = 5_000;
31
- /** How long a row whose answer is final is kept after `until`. */
32
- export const KEEP_AFTER_UNTIL_MS = 24 * 60 * 60 * 1000;
33
- const DROP_EVERY_MS = 60_000;
34
- /**
35
- * Opens the pool and creates the table. `log` receives an error the pool reports for an idle connection, and a sweep
36
- * that fails; the sweep runs again a minute later.
37
- */
38
- export async function openStore(url, log = operatorLine) {
39
- const pool = new pg.Pool({
40
- connectionString: url,
41
- max: 10,
42
- connectionTimeoutMillis: STORE_TIMEOUT_MS,
43
- query_timeout: STORE_TIMEOUT_MS,
44
- statement_timeout: STORE_TIMEOUT_MS,
45
- });
46
- pool.on("error", (e) => log({ event: "store-connection-error" }, e));
47
- await pool.query(SCHEMA);
48
- const store = {
49
- async read(network, id) {
50
- const r = await pool.query("SELECT answer, since, unread FROM settlement WHERE network = $1 AND id = $2", [network, id]);
51
- const row = r.rows[0];
52
- if (row === undefined)
53
- return { state: "none" };
54
- const since = row.since === null ? null : Number(row.since);
55
- const unread = row.unread.map(Number);
56
- return row.answer === null
57
- ? { state: "claimed", since, unread }
58
- : { state: "answered", answer: row.answer, since, unread };
59
- },
60
- async claim(network, id, until, since) {
61
- const r = await pool.query("INSERT INTO settlement (network, id, answer, until, since) VALUES ($1, $2, NULL, $3, $4) ON CONFLICT DO NOTHING", [network, id, until.toISOString(), since ?? null]);
62
- return r.rowCount === 1;
63
- },
64
- async answer(network, id, answer) {
65
- const r = await pool.query(`UPDATE settlement SET answer = $3 WHERE network = $1 AND id = $2
66
- AND (answer IS NULL OR answer->>'errorReason' = 'settlement_pending')${isPending(answer) ? " AND answer IS NULL" : ""}`, [network, id, JSON.stringify(answer)]);
67
- return r.rowCount === 1;
68
- },
69
- async advance(network, id, scan) {
70
- await pool.query(`UPDATE settlement SET since = GREATEST(since, $3),
71
- unread = ARRAY(
72
- SELECT DISTINCT u FROM unnest(unread || $5::bigint[]) AS u
73
- WHERE u = ANY($5::bigint[]) OR NOT (u = ANY($6::bigint[]) OR (u >= $4 AND u < $3))
74
- ORDER BY u)
75
- WHERE network = $1 AND id = $2`, [network, id, scan.to, scan.from, scan.unread, scan.resolved]);
76
- },
77
- async drop() {
78
- await pool.query(`DELETE FROM settlement WHERE until < now() - $1 * interval '1 millisecond' AND ${FINAL}`, [
79
- KEEP_AFTER_UNTIL_MS,
80
- ]);
81
- },
82
- async close() {
83
- clearInterval(timer);
84
- await pool.end();
85
- },
86
- };
87
- const timer = setInterval(() => {
88
- store.drop().catch((e) => log({ event: "store-call-failed", call: "sweep" }, e));
89
- }, DROP_EVERY_MS);
90
- timer.unref();
91
- return store;
92
- }
93
- /**
94
- * The part of `settleWaitMs` kept for writing the answer once the wait for the chain ends: a second, or a quarter of a
95
- * shorter wait. The node calls and the waits end that much before the deadline, so the answer is stored, then given.
96
- */
97
- export function answerReserve(settleWaitMs) {
98
- return Math.min(1_000, settleWaitMs / 4);
99
- }
100
- /** A store call bounded by `STORE_TIMEOUT_MS` and by what is left before `deadline` (a `performance.now()` time). */
101
- export function inTime(p, deadline) {
102
- return within(p, Math.min(STORE_TIMEOUT_MS, deadline - performance.now()));
103
- }
package/dist/tron.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { type FacilitatorRequest, type OperatorLog, type SettleAnswer, type VerifyAnswer } from "./answers.js";
2
- import { type SettlementStore } from "./store.js";
3
- export interface TronNode {
4
- network: `tron:${number}`;
5
- fullNode: string;
6
- solidityNode: string;
7
- }
8
- export declare function createTron(nodes: readonly TronNode[], s: SettlementStore, settleWaitMs: number, log: OperatorLog): {
9
- verify: (r: FacilitatorRequest) => Promise<VerifyAnswer>;
10
- settle: (r: FacilitatorRequest) => Promise<SettleAnswer>;
11
- networks: string[];
12
- };