@gibs/bridge-client 1.29.0 → 1.32.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 (119) hide show
  1. package/block-polling/package.json +6 -0
  2. package/coinbase-accept-list/package.json +6 -0
  3. package/dist/block-polling.d.ts +33 -0
  4. package/dist/block-polling.js +10 -0
  5. package/dist/cjs/block-polling.d.ts +33 -0
  6. package/dist/cjs/block-polling.js +15 -0
  7. package/dist/cjs/client.d.ts +9 -1
  8. package/dist/cjs/client.js +8 -5
  9. package/dist/cjs/coinbase-accept-list.d.ts +101 -0
  10. package/dist/cjs/coinbase-accept-list.js +97 -0
  11. package/dist/cjs/crossing-decision.d.ts +166 -0
  12. package/dist/cjs/crossing-decision.js +169 -0
  13. package/dist/cjs/crossing-vector-guard.d.ts +45 -0
  14. package/dist/cjs/crossing-vector-guard.js +139 -0
  15. package/dist/cjs/exchange-deposit-board.d.ts +50 -0
  16. package/dist/cjs/exchange-deposit-board.js +70 -0
  17. package/dist/cjs/exchange-deposit-chain.d.ts +146 -0
  18. package/dist/cjs/exchange-deposit-chain.js +228 -0
  19. package/dist/cjs/exchange-deposit-constants.d.ts +10 -0
  20. package/dist/cjs/exchange-deposit-constants.js +6 -0
  21. package/dist/cjs/exchange-deposit-factory-calls.d.ts +245 -0
  22. package/dist/cjs/exchange-deposit-factory-calls.js +103 -0
  23. package/dist/cjs/exchange-deposit-factory.d.ts +87 -0
  24. package/dist/cjs/exchange-deposit-factory.js +110 -0
  25. package/dist/cjs/exchange-deposit-fake.d.ts +67 -0
  26. package/dist/cjs/exchange-deposit-fake.js +179 -0
  27. package/dist/cjs/exchange-deposit-index.d.ts +77 -0
  28. package/dist/cjs/exchange-deposit-index.js +40 -0
  29. package/dist/cjs/exchange-deposit-issuance.d.ts +327 -0
  30. package/dist/cjs/exchange-deposit-issuance.js +244 -0
  31. package/dist/cjs/exchange-deposit-path.d.ts +16 -0
  32. package/dist/cjs/exchange-deposit-path.js +15 -0
  33. package/dist/cjs/exchange-deposit-pow.d.ts +163 -0
  34. package/dist/cjs/exchange-deposit-pow.js +101 -0
  35. package/dist/cjs/exchange-deposit-recipient.d.ts +66 -0
  36. package/dist/cjs/exchange-deposit-recipient.js +35 -0
  37. package/dist/cjs/exchange-deposit-self-cross.d.ts +163 -0
  38. package/dist/cjs/exchange-deposit-self-cross.js +60 -0
  39. package/dist/cjs/exchange-deposit-signin.d.ts +275 -0
  40. package/dist/cjs/exchange-deposit-signin.js +166 -0
  41. package/dist/cjs/exchange-deposit-watch.d.ts +133 -0
  42. package/dist/cjs/exchange-deposit-watch.js +58 -0
  43. package/dist/cjs/exchange-deposit.d.ts +440 -0
  44. package/dist/cjs/exchange-deposit.js +154 -0
  45. package/dist/cjs/exchange-sender-guides.d.ts +29 -0
  46. package/dist/cjs/exchange-sender-guides.js +25 -0
  47. package/dist/cjs/image.d.ts +18 -0
  48. package/dist/cjs/image.js +11 -9
  49. package/dist/cjs/index.d.ts +4 -0
  50. package/dist/cjs/index.js +32 -1
  51. package/dist/cjs/kraken-accept-list.d.ts +70 -0
  52. package/dist/cjs/kraken-accept-list.js +24 -0
  53. package/dist/cjs/unlisted-token.d.ts +26 -0
  54. package/dist/cjs/unlisted-token.js +34 -0
  55. package/dist/client.d.ts +9 -1
  56. package/dist/client.js +8 -5
  57. package/dist/coinbase-accept-list.d.ts +101 -0
  58. package/dist/coinbase-accept-list.js +89 -0
  59. package/dist/crossing-decision.d.ts +166 -0
  60. package/dist/crossing-decision.js +162 -0
  61. package/dist/crossing-vector-guard.d.ts +45 -0
  62. package/dist/crossing-vector-guard.js +134 -0
  63. package/dist/exchange-deposit-board.d.ts +50 -0
  64. package/dist/exchange-deposit-board.js +28 -0
  65. package/dist/exchange-deposit-chain.d.ts +146 -0
  66. package/dist/exchange-deposit-chain.js +218 -0
  67. package/dist/exchange-deposit-constants.d.ts +10 -0
  68. package/dist/exchange-deposit-constants.js +3 -0
  69. package/dist/exchange-deposit-factory-calls.d.ts +245 -0
  70. package/dist/exchange-deposit-factory-calls.js +97 -0
  71. package/dist/exchange-deposit-factory.d.ts +87 -0
  72. package/dist/exchange-deposit-factory.js +104 -0
  73. package/dist/exchange-deposit-fake.d.ts +67 -0
  74. package/dist/exchange-deposit-fake.js +171 -0
  75. package/dist/exchange-deposit-index.d.ts +77 -0
  76. package/dist/exchange-deposit-index.js +34 -0
  77. package/dist/exchange-deposit-issuance.d.ts +327 -0
  78. package/dist/exchange-deposit-issuance.js +224 -0
  79. package/dist/exchange-deposit-path.d.ts +16 -0
  80. package/dist/exchange-deposit-path.js +11 -0
  81. package/dist/exchange-deposit-pow.d.ts +163 -0
  82. package/dist/exchange-deposit-pow.js +93 -0
  83. package/dist/exchange-deposit-recipient.d.ts +66 -0
  84. package/dist/exchange-deposit-recipient.js +28 -0
  85. package/dist/exchange-deposit-self-cross.d.ts +163 -0
  86. package/dist/exchange-deposit-self-cross.js +46 -0
  87. package/dist/exchange-deposit-signin.d.ts +275 -0
  88. package/dist/exchange-deposit-signin.js +147 -0
  89. package/dist/exchange-deposit-watch.d.ts +133 -0
  90. package/dist/exchange-deposit-watch.js +44 -0
  91. package/dist/exchange-deposit.d.ts +440 -0
  92. package/dist/exchange-deposit.js +138 -0
  93. package/dist/exchange-sender-guides.d.ts +29 -0
  94. package/dist/exchange-sender-guides.js +21 -0
  95. package/dist/image.d.ts +18 -0
  96. package/dist/image.js +8 -8
  97. package/dist/index.d.ts +4 -0
  98. package/dist/index.js +4 -0
  99. package/dist/kraken-accept-list.d.ts +70 -0
  100. package/dist/kraken-accept-list.js +17 -0
  101. package/dist/unlisted-token.d.ts +26 -0
  102. package/dist/unlisted-token.js +30 -0
  103. package/exchange-deposit/package.json +6 -0
  104. package/exchange-deposit-board/package.json +6 -0
  105. package/exchange-deposit-chain/package.json +6 -0
  106. package/exchange-deposit-factory/package.json +6 -0
  107. package/exchange-deposit-fake/package.json +6 -0
  108. package/exchange-deposit-issuance/package.json +6 -0
  109. package/exchange-deposit-path/package.json +6 -0
  110. package/exchange-deposit-pow/package.json +6 -0
  111. package/exchange-deposit-recipient/package.json +6 -0
  112. package/exchange-deposit-self-cross/package.json +6 -0
  113. package/exchange-deposit-signin/package.json +6 -0
  114. package/exchange-deposit-watch/package.json +6 -0
  115. package/exchange-sender-guides/package.json +6 -0
  116. package/kraken-accept-list/package.json +6 -0
  117. package/llms.txt +1 -0
  118. package/package.json +487 -6
  119. package/unlisted-token/package.json +6 -0
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decideCrossing = exports.gibsFeeOf = exports.requiredIncomeWei = exports.gasTableOf = exports.GAS_TABLES = exports.GAS_TABLE_NAMES = exports.ETHER_TOKEN = exports.CROSSING_SPEC_VERSION = void 0;
4
+ exports.CROSSING_SPEC_VERSION = '7.0.0';
5
+ exports.ETHER_TOKEN = '0x0000000000000000000000000000000000000000';
6
+ const WAD = 10n ** 18n;
7
+ const THOUSAND = 1000n;
8
+ const MAXIMUM_FEE_RATE_E18 = 10n ** 16n;
9
+ const SEARCH_LIMIT = 2n ** 192n;
10
+ exports.GAS_TABLE_NAMES = ['ethereum-prague', 'ethereum-glamsterdam', 'sepolia-glamsterdam'];
11
+ exports.GAS_TABLES = {
12
+ 'ethereum-prague': {
13
+ chainId: 1n,
14
+ gasModel: {
15
+ paid: { tokenFlushGas: 295000n, etherFlushGas: 292000n },
16
+ beforeRefund: { tokenFlushGas: 340000n, etherFlushGas: 352000n },
17
+ },
18
+ },
19
+ 'ethereum-glamsterdam': {
20
+ chainId: 1n,
21
+ gasModel: {
22
+ paid: { tokenFlushGas: 830000n, etherFlushGas: 645000n },
23
+ beforeRefund: { tokenFlushGas: 861000n, etherFlushGas: 675000n },
24
+ },
25
+ },
26
+ 'sepolia-glamsterdam': {
27
+ chainId: 11155111n,
28
+ gasModel: {
29
+ paid: { tokenFlushGas: 832000n, etherFlushGas: 644000n },
30
+ beforeRefund: { tokenFlushGas: 863000n, etherFlushGas: 674000n },
31
+ },
32
+ },
33
+ };
34
+ const gasTableOf = (name, chainId) => {
35
+ if (!Object.hasOwn(exports.GAS_TABLES, name))
36
+ throw new Error(`unknown gas table ${name}`);
37
+ const table = exports.GAS_TABLES[name];
38
+ if (table.chainId !== chainId)
39
+ throw new Error(`gas table ${name} is for chain ${table.chainId}, not chain ${chainId}`);
40
+ return table;
41
+ };
42
+ exports.gasTableOf = gasTableOf;
43
+ const ceilDiv = (numerator, denominator) => (numerator + denominator - 1n) / denominator;
44
+ const requiredIncomeWei = ({ costWei, safetyMultipleThousandths, }) => ceilDiv(costWei * safetyMultipleThousandths, THOUSAND);
45
+ exports.requiredIncomeWei = requiredIncomeWei;
46
+ const gibsFeeOf = ({ amount, feeRateE18 }) => (amount * feeRateE18) / WAD;
47
+ exports.gibsFeeOf = gibsFeeOf;
48
+ const crossableOf = (deposit) => deposit.balance;
49
+ const incomeOf = (amount, deposit) => {
50
+ if (deposit.weiPerWholeToken === null)
51
+ return 0n;
52
+ const delivered = amount - ceilDiv(amount * deposit.entryFeeWad, WAD);
53
+ const fee = (0, exports.gibsFeeOf)({ amount: delivered, feeRateE18: deposit.feeRateE18 });
54
+ return (fee * deposit.weiPerWholeToken) / 10n ** deposit.decimals;
55
+ };
56
+ const flushGasOf = (deposit, figures) => deposit.token === exports.ETHER_TOKEN ? figures.etherFlushGas : figures.tokenFlushGas;
57
+ const feePerGasOf = (conditions) => conditions.baseFeeWei + conditions.priorityFeeWei;
58
+ const costOf = (deposit, conditions) => flushGasOf(deposit, conditions.gasModel.paid) * feePerGasOf(conditions);
59
+ const netOf = (incomeWei, costWei, conditions) => incomeWei * THOUSAND - costWei * conditions.safetyMultipleThousandths;
60
+ const breakEvenOf = (incomeWei, deposit, conditions) => {
61
+ if (incomeWei === null)
62
+ return 0n;
63
+ const paidGas = flushGasOf(deposit, conditions.gasModel.paid);
64
+ return (incomeWei * THOUSAND) / (paidGas * conditions.safetyMultipleThousandths);
65
+ };
66
+ const waits = (reason) => ({ outcome: 'wait', reason });
67
+ const cannot = (reason) => ({ outcome: 'cannot-cross-automatically', reason });
68
+ const refusalOf = (deposit, conditions, amount) => {
69
+ if (deposit.retired)
70
+ return cannot('address-retired');
71
+ if (deposit.crossingInFlight)
72
+ return waits('crossing-in-flight');
73
+ if (amount === 0n)
74
+ return waits('nothing-waiting');
75
+ if (deposit.feeRateE18 === 0n)
76
+ return cannot('zero-fee-rate');
77
+ if (conditions.maximumBaseFeeWei !== null && conditions.baseFeeWei > conditions.maximumBaseFeeWei) {
78
+ return waits('gas-price-above-ceiling');
79
+ }
80
+ if (!deposit.autoCrossAllowed)
81
+ return cannot('token-not-allowed');
82
+ if (deposit.minPerTx === null)
83
+ return waits('limits-unavailable');
84
+ if (amount > deposit.maxPerTx)
85
+ return cannot('above-per-transaction-maximum');
86
+ if (amount < deposit.minPerTx)
87
+ return waits('below-bridge-minimum');
88
+ if (amount > deposit.dailyRemaining)
89
+ return waits('daily-limit-reached');
90
+ if (deposit.weiPerWholeToken === null)
91
+ return waits('price-missing');
92
+ return null;
93
+ };
94
+ const thresholdOf = (deposit, conditions) => {
95
+ const none = { amount: null, aboveMaximum: false };
96
+ if (deposit.retired)
97
+ return none;
98
+ if (deposit.minPerTx === null || deposit.weiPerWholeToken === null)
99
+ return none;
100
+ if (deposit.feeRateE18 === 0n)
101
+ return none;
102
+ const minimum = deposit.minPerTx;
103
+ const costWei = costOf(deposit, conditions);
104
+ const pays = (amount) => netOf(incomeOf(amount, deposit), costWei, conditions) >= 0n;
105
+ const finish = (profitable) => {
106
+ const amount = profitable > minimum ? profitable : minimum;
107
+ return { amount, aboveMaximum: amount > deposit.maxPerTx };
108
+ };
109
+ if (pays(0n))
110
+ return finish(0n);
111
+ let high = 1n;
112
+ while (!pays(high)) {
113
+ high *= 2n;
114
+ if (high > SEARCH_LIMIT)
115
+ return none;
116
+ }
117
+ let low = high / 2n;
118
+ while (high - low > 1n) {
119
+ const middle = (low + high) / 2n;
120
+ if (pays(middle))
121
+ high = middle;
122
+ else
123
+ low = middle;
124
+ }
125
+ return finish(high);
126
+ };
127
+ const assertValid = (input) => {
128
+ if (input.specVersion !== exports.CROSSING_SPEC_VERSION) {
129
+ throw new Error(`the crossing spec is ${exports.CROSSING_SPEC_VERSION}, the input names ${input.specVersion}`);
130
+ }
131
+ const { conditions, deposit } = input;
132
+ if (conditions.safetyMultipleThousandths <= 0n)
133
+ throw new Error('the safety multiple must be above zero');
134
+ const { paid, beforeRefund } = conditions.gasModel;
135
+ const figures = [paid.tokenFlushGas, paid.etherFlushGas, beforeRefund.tokenFlushGas, beforeRefund.etherFlushGas];
136
+ if (figures.some((gas) => gas <= 0n))
137
+ throw new Error('every gas figure must be above zero');
138
+ if (deposit.feeRateE18 < 0n || deposit.feeRateE18 > MAXIMUM_FEE_RATE_E18) {
139
+ throw new Error(`the fee rate must be 0 to ${MAXIMUM_FEE_RATE_E18} (1e18 is 100 percent)`);
140
+ }
141
+ };
142
+ const decideCrossing = (input) => {
143
+ assertValid(input);
144
+ const { conditions, deposit } = input;
145
+ const amount = crossableOf(deposit);
146
+ const costWei = costOf(deposit, conditions);
147
+ const threshold = thresholdOf(deposit, conditions);
148
+ const describe = (outcome, reason, incomeWei) => ({
149
+ specVersion: exports.CROSSING_SPEC_VERSION,
150
+ outcome,
151
+ reason,
152
+ amount,
153
+ incomeWei,
154
+ gasLimit: flushGasOf(deposit, conditions.gasModel.beforeRefund),
155
+ paidGas: flushGasOf(deposit, conditions.gasModel.paid),
156
+ costWei,
157
+ breakEvenFeePerGasWei: breakEvenOf(incomeWei, deposit, conditions),
158
+ thresholdAmount: threshold.amount,
159
+ thresholdAboveMaximum: threshold.aboveMaximum,
160
+ });
161
+ const refusal = refusalOf(deposit, conditions, amount);
162
+ if (refusal !== null)
163
+ return describe(refusal.outcome, refusal.reason, null);
164
+ const incomeWei = incomeOf(amount, deposit);
165
+ if (netOf(incomeWei, costWei, conditions) >= 0n)
166
+ return describe('execute', null, incomeWei);
167
+ return describe('wait', 'below-cost', incomeWei);
168
+ };
169
+ exports.decideCrossing = decideCrossing;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A guard for the boundary vectors of `crossing-vectors.json`. A boundary vector's name says it sits on an edge:
3
+ * one base unit under the threshold, at it, one wei above a break-even fee. When a gas table moves, the edge moves,
4
+ * and a balance or a fee left behind keeps its name but tests nothing. This guard runs the reference decision on
5
+ * each named pair and fails when the pair does not sit on its edge.
6
+ */
7
+ /** The fields of a vector that the guard reads. */
8
+ export type GuardVector = {
9
+ id: string;
10
+ input: unknown;
11
+ expectedError?: string;
12
+ };
13
+ /** The vectors file, as the guard reads it. */
14
+ export type GuardVectorFile = {
15
+ vectors: readonly GuardVector[];
16
+ };
17
+ /** Turns every string made only of digits into a bigint. Addresses start with 0x, so they are safe. */
18
+ export declare const reviveBigints: (value: unknown) => unknown;
19
+ /**
20
+ * The edge that a pair sits on.
21
+ * - `threshold`: the first amount that pays. The lower vector is one base unit under it, the upper one sits on it.
22
+ * - `break-even`: the highest fee per gas that pays. The upper vector is at it, the lower one is one wei above it.
23
+ * - `income`: the least income that pays. The upper vector earns exactly it, the lower one earns one wei less.
24
+ * - `edge`: a limit that is inclusive (a ceiling, a cap, a minimum). Only the outcome is checked.
25
+ */
26
+ export type BoundaryKind = 'threshold' | 'break-even' | 'income' | 'edge';
27
+ /** Two vectors that sit on one edge. The first must execute, the second must not. */
28
+ export type BoundaryPair = {
29
+ kind: BoundaryKind;
30
+ /** The vector id that sits on the edge, as named, and must execute. */
31
+ mustExecute: string;
32
+ /** The vector id one step beyond the edge, which must wait or be refused. */
33
+ mustNotExecute: string;
34
+ };
35
+ /** Every boundary pair of the vectors file. A vector whose name says it is on an edge must appear here. */
36
+ export declare const BOUNDARY_PAIRS: readonly BoundaryPair[];
37
+ /**
38
+ * Every way the boundary vectors fail to sit on their named edges. An empty list means they all do.
39
+ * It fails when a vector named as a boundary is in no pair, when a pair names a vector that is not in the file,
40
+ * and when a pair does not decide as its name says.
41
+ * @param file the vectors file, as parsed from JSON
42
+ * @param pairs the boundary pairs to check, `BOUNDARY_PAIRS` by default
43
+ * @returns one message per failure, empty when none
44
+ */
45
+ export declare const boundaryPairFailures: (file: GuardVectorFile, pairs?: readonly BoundaryPair[]) => string[];
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.boundaryPairFailures = exports.BOUNDARY_PAIRS = exports.reviveBigints = void 0;
4
+ const crossing_decision_js_1 = require("./crossing-decision.js");
5
+ const reviveBigints = (value) => {
6
+ if (typeof value === 'string')
7
+ return /^\d+$/.test(value) ? BigInt(value) : value;
8
+ if (Array.isArray(value))
9
+ return value.map(exports.reviveBigints);
10
+ if (value === null || typeof value !== 'object')
11
+ return value;
12
+ return Object.fromEntries(Object.entries(value).map(([key, inner]) => [key, (0, exports.reviveBigints)(inner)]));
13
+ };
14
+ exports.reviveBigints = reviveBigints;
15
+ exports.BOUNDARY_PAIRS = [
16
+ {
17
+ kind: 'threshold',
18
+ mustNotExecute: '02-one-base-unit-under-threshold',
19
+ mustExecute: '03-exactly-the-threshold',
20
+ },
21
+ {
22
+ kind: 'threshold',
23
+ mustNotExecute: '36-ether-one-wei-under-threshold',
24
+ mustExecute: '37-ether-at-threshold',
25
+ },
26
+ {
27
+ kind: 'threshold',
28
+ mustNotExecute: '42-usdc-ethereum-glamsterdam-under',
29
+ mustExecute: '44-usdc-ethereum-glamsterdam-at',
30
+ },
31
+ {
32
+ kind: 'threshold',
33
+ mustNotExecute: '43-usdc-sepolia-glamsterdam-under',
34
+ mustExecute: '45-usdc-sepolia-glamsterdam-at',
35
+ },
36
+ {
37
+ kind: 'edge',
38
+ mustNotExecute: '14-base-fee-above-ceiling',
39
+ mustExecute: '15-base-fee-at-ceiling',
40
+ },
41
+ { kind: 'edge', mustNotExecute: '19-fee-rate-above-cap', mustExecute: '18-fee-rate-at-cap' },
42
+ {
43
+ kind: 'edge',
44
+ mustNotExecute: '04-below-bridge-minimum',
45
+ mustExecute: '31-free-gas-executes-at-minimum',
46
+ },
47
+ {
48
+ kind: 'break-even',
49
+ mustNotExecute: '49-above-break-even-waits',
50
+ mustExecute: '48-break-even-fee-executes',
51
+ },
52
+ {
53
+ kind: 'income',
54
+ mustNotExecute: '65-income-one-wei-under-the-need',
55
+ mustExecute: '64-income-exactly-equals-the-need',
56
+ },
57
+ ];
58
+ const BOUNDARY_NAME = /under|exactly|break-even|(^|-)at(-|$)/;
59
+ const nameOf = (id) => id.replace(/^\d+-/, '');
60
+ const decisionOf = (vector) => {
61
+ if (vector.expectedError !== undefined)
62
+ return null;
63
+ return (0, crossing_decision_js_1.decideCrossing)((0, exports.reviveBigints)(vector.input));
64
+ };
65
+ const feePerGasOf = (vector) => {
66
+ const { conditions } = (0, exports.reviveBigints)(vector.input);
67
+ return conditions.baseFeeWei + conditions.priorityFeeWei;
68
+ };
69
+ const multipleOf = (vector) => (0, exports.reviveBigints)(vector.input).conditions.safetyMultipleThousandths;
70
+ const edgeFailuresOf = (pair, execute, beyond) => {
71
+ if (pair.kind === 'edge')
72
+ return [];
73
+ if (beyond.decision === null)
74
+ return [`${beyond.vector.id} has no decision, so the ${pair.kind} edge cannot be checked`];
75
+ if (pair.kind === 'threshold') {
76
+ const failures = [];
77
+ if (execute.decision.thresholdAmount !== execute.decision.amount) {
78
+ failures.push(`${execute.vector.id} must hold its threshold exactly, but it holds ${execute.decision.amount}`);
79
+ }
80
+ if (beyond.decision.amount + 1n !== execute.decision.amount) {
81
+ failures.push(`${beyond.vector.id} must hold one base unit under ${execute.vector.id}`);
82
+ }
83
+ return failures;
84
+ }
85
+ if (pair.kind === 'break-even') {
86
+ const failures = [];
87
+ if (feePerGasOf(execute.vector) !== execute.decision.breakEvenFeePerGasWei) {
88
+ failures.push(`${execute.vector.id} must pay exactly the break-even fee ${execute.decision.breakEvenFeePerGasWei}`);
89
+ }
90
+ if (feePerGasOf(beyond.vector) !== feePerGasOf(execute.vector) + 1n) {
91
+ failures.push(`${beyond.vector.id} must pay one wei above the break-even fee`);
92
+ }
93
+ return failures;
94
+ }
95
+ const required = (0, crossing_decision_js_1.requiredIncomeWei)({
96
+ costWei: execute.decision.costWei,
97
+ safetyMultipleThousandths: multipleOf(execute.vector),
98
+ });
99
+ const failures = [];
100
+ if (execute.decision.incomeWei !== required)
101
+ failures.push(`${execute.vector.id} must earn exactly the need ${required}`);
102
+ if (beyond.decision.incomeWei !== required - 1n)
103
+ failures.push(`${beyond.vector.id} must earn one wei under the need`);
104
+ return failures;
105
+ };
106
+ const failuresOfPair = (pair, vectorsById) => {
107
+ const execute = vectorsById.get(pair.mustExecute);
108
+ const beyond = vectorsById.get(pair.mustNotExecute);
109
+ if (execute === undefined || beyond === undefined)
110
+ return [];
111
+ const executeDecision = decisionOf(execute);
112
+ const beyondDecision = decisionOf(beyond);
113
+ const outcomeFailures = [];
114
+ if (executeDecision?.outcome !== 'execute') {
115
+ outcomeFailures.push(`${execute.id} is named as executing on the edge, but its decision is ${executeDecision?.outcome ?? 'a refusal'}`);
116
+ }
117
+ if (beyondDecision?.outcome === 'execute') {
118
+ outcomeFailures.push(`${beyond.id} is named as beyond the edge, but it executes`);
119
+ }
120
+ if (executeDecision === null || executeDecision.outcome !== 'execute')
121
+ return outcomeFailures;
122
+ return [
123
+ ...outcomeFailures,
124
+ ...edgeFailuresOf(pair, { vector: execute, decision: executeDecision }, { vector: beyond, decision: beyondDecision }),
125
+ ];
126
+ };
127
+ const boundaryPairFailures = (file, pairs = exports.BOUNDARY_PAIRS) => {
128
+ const vectorsById = new Map(file.vectors.map((vector) => [vector.id, vector]));
129
+ const declared = new Set(pairs.flatMap((pair) => [pair.mustExecute, pair.mustNotExecute]));
130
+ const undeclared = file.vectors
131
+ .filter((vector) => BOUNDARY_NAME.test(nameOf(vector.id)) && !declared.has(vector.id))
132
+ .map((vector) => `${vector.id} is named as a boundary but is in no boundary pair`);
133
+ const missing = [...declared]
134
+ .filter((id) => !vectorsById.has(id))
135
+ .map((id) => `${id} is named in a boundary pair but is not in the vectors file`);
136
+ const paired = pairs.flatMap((pair) => failuresOfPair(pair, vectorsById));
137
+ return [...undeclared, ...missing, ...paired];
138
+ };
139
+ exports.boundaryPairFailures = boundaryPairFailures;
@@ -0,0 +1,50 @@
1
+ import { type Hex } from 'viem';
2
+ import { type PowProgress, type Stamper } from './exchange-deposit-pow.js';
3
+ /**
4
+ * Posting the sealed issuance records to the msgboard. The record is the ciphertext from `exchange-deposit-issuance.ts`,
5
+ * so the board holds only what the seed can open. Posting is a background step: a failure is the caller's to log, and
6
+ * it never stops a reader from getting an address.
7
+ *
8
+ * THIS FILE IS LOADED LAZILY. It imports the msgboard SDK, which the page must not load on its first render. The page
9
+ * imports this module with a dynamic import, so the SDK stays out of the entry chunk.
10
+ *
11
+ * PROOF OF WORK. A post needs a stamper, and the caller passes the WebAssembly engine's stamper. There is no default:
12
+ * the SDK would otherwise pick the JavaScript grind, which takes minutes. A read passes a stamper that refuses, so a
13
+ * read can never grind.
14
+ *
15
+ * THE BOARD CHAIN. A board serves one chain per node, and the archive indexes the chains that board serves (1, 369 and
16
+ * 943). A Sepolia factory has no board and no archive, so its records stay in the browser only.
17
+ */
18
+ export { PowEngineUnavailableError, POW_ENGINE_WEBASSEMBLY, loadVerifiedEngine, progressOf } from './exchange-deposit-pow.js';
19
+ export type { PowEngineModule, PowProgress, PowWorkerRequest, PowWorkerResponse, Stamp, StampInput, Stamper, VerifiedEngine } from './exchange-deposit-pow.js';
20
+ /** The board chain for the mainnet factory. It is the factory's own chain. */
21
+ export declare const EXCHANGE_DEPOSIT_BOARD_MAINNET_CHAIN_ID = 1n;
22
+ /**
23
+ * Posts one sealed body under a category. It does the proof of work with the given stamper, then submits the message.
24
+ * If the stamper throws, the post rejects with the engine's error. The SDK's JavaScript grind never runs.
25
+ *
26
+ * @param input.rpcUrl - the board's endpoint for the chain
27
+ * @param input.category - the category from `issuanceCategoryOf`
28
+ * @param input.body - the sealed body from `sealIssuedAddressRecord`
29
+ * @param input.stamper - the WebAssembly engine's stamper, from `loadVerifiedStamper`
30
+ * @param input.onProgress - receives the grind's numbers as they change
31
+ * @returns the hash the board returns for the message
32
+ */
33
+ export declare const postIssuedRecordBody: ({ rpcUrl, category, body, stamper, onProgress, }: {
34
+ rpcUrl: string;
35
+ category: Hex;
36
+ body: Hex;
37
+ stamper: Stamper;
38
+ onProgress?: (progress: PowProgress) => void;
39
+ }) => Promise<Hex>;
40
+ /**
41
+ * The bodies the board holds under one category, in the order the board returns them. Used by the live check, which
42
+ * reads back what it posted.
43
+ *
44
+ * @param input.rpcUrl - the board's endpoint for the chain
45
+ * @param input.category - the category to read
46
+ */
47
+ export declare const readIssuedRecordBodies: ({ rpcUrl, category }: {
48
+ rpcUrl: string;
49
+ category: Hex;
50
+ }) => Promise<readonly Hex[]>;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.readIssuedRecordBodies = exports.postIssuedRecordBody = exports.EXCHANGE_DEPOSIT_BOARD_MAINNET_CHAIN_ID = exports.progressOf = exports.loadVerifiedEngine = exports.POW_ENGINE_WEBASSEMBLY = exports.PowEngineUnavailableError = void 0;
37
+ const viem_1 = require("viem");
38
+ const exchange_deposit_pow_js_1 = require("./exchange-deposit-pow.js");
39
+ var exchange_deposit_pow_js_2 = require("./exchange-deposit-pow.js");
40
+ Object.defineProperty(exports, "PowEngineUnavailableError", { enumerable: true, get: function () { return exchange_deposit_pow_js_2.PowEngineUnavailableError; } });
41
+ Object.defineProperty(exports, "POW_ENGINE_WEBASSEMBLY", { enumerable: true, get: function () { return exchange_deposit_pow_js_2.POW_ENGINE_WEBASSEMBLY; } });
42
+ Object.defineProperty(exports, "loadVerifiedEngine", { enumerable: true, get: function () { return exchange_deposit_pow_js_2.loadVerifiedEngine; } });
43
+ Object.defineProperty(exports, "progressOf", { enumerable: true, get: function () { return exchange_deposit_pow_js_2.progressOf; } });
44
+ exports.EXCHANGE_DEPOSIT_BOARD_MAINNET_CHAIN_ID = 1n;
45
+ const refuseGrind = () => {
46
+ throw new Error('a board read never grinds proof of work');
47
+ };
48
+ const boardClientOf = async ({ rpcUrl, stamper }) => {
49
+ const { MsgBoardClient } = await Promise.resolve().then(() => __importStar(require('@msgboard/sdk')));
50
+ const provider = (0, viem_1.createPublicClient)({ transport: (0, viem_1.http)(rpcUrl) });
51
+ return new MsgBoardClient(provider, { stamper });
52
+ };
53
+ const postIssuedRecordBody = async ({ rpcUrl, category, body, stamper, onProgress, }) => {
54
+ let stopBoard = () => undefined;
55
+ const guarded = (0, exchange_deposit_pow_js_1.guardStamper)(stamper, () => stopBoard());
56
+ const board = await boardClientOf({ rpcUrl, stamper: guarded.stamper });
57
+ stopBoard = () => board.cancel();
58
+ board.progressHandler = (stats) => onProgress?.((0, exchange_deposit_pow_js_1.progressOf)(stats));
59
+ const work = await board.grind(category, body).catch((error) => {
60
+ throw guarded.failure() ?? error;
61
+ });
62
+ return board.addMessage(work.message);
63
+ };
64
+ exports.postIssuedRecordBody = postIssuedRecordBody;
65
+ const readIssuedRecordBodies = async ({ rpcUrl, category }) => {
66
+ const board = await boardClientOf({ rpcUrl, stamper: refuseGrind });
67
+ const content = await board.content({ category });
68
+ return (content[category] ?? []).map((message) => message.data);
69
+ };
70
+ exports.readIssuedRecordBodies = readIssuedRecordBodies;
@@ -0,0 +1,146 @@
1
+ import { type PublicClient } from 'viem';
2
+ import { type ExchangeDepositCodeKind, type ExchangeDepositSource } from './exchange-deposit.js';
3
+ import { type ExchangeDepositFactoryEntry } from './exchange-deposit-factory.js';
4
+ import type { FakeExchangeDepositScenario } from './exchange-deposit-fake.js';
5
+ export { exchangeDepositFlushRequest, type ExchangeDepositFlushRequest } from './exchange-deposit-factory-calls.js';
6
+ /**
7
+ * THE REAL SOURCE: the deposit addresses of the deployed factory, read from the chain.
8
+ *
9
+ * Every address comes from the factory's own `depositAddress` view. Nothing here derives an address, so a change to
10
+ * the factory's derivation reaches the interface without a change in this file. The balances are read from the
11
+ * address itself. Whether an address was used is read from the factory's events, because a flushed address ends with
12
+ * no balance and no code. A crossing in progress is not read yet, so no address reports one.
13
+ */
14
+ /** The read calls the real source makes. Any viem public client has them; a test passes a fake. */
15
+ export type ExchangeDepositReadClient = Pick<PublicClient, 'readContract' | 'getBalance' | 'getBlock' | 'estimateFeesPerGas' | 'getLogs' | 'getCode'>;
16
+ /** The one read the recipient check makes, on the destination chain. Any viem public client has it. */
17
+ export type ExchangeDepositDestinationClient = Pick<PublicClient, 'getCode'>;
18
+ /** The read client of a chain, by chain id. The real source passes {@link readClientOfChain}; a test passes a fake. */
19
+ export type ExchangeDepositClientOfChain = (chainId: bigint) => ExchangeDepositDestinationClient;
20
+ /**
21
+ * The longest one remote procedure call endpoint may take to answer a deposit read before the next endpoint is asked, in milliseconds.
22
+ * A dead endpoint otherwise holds each read that the rotation sends to it for the transport's full timeout, and the
23
+ * deposit reads run one after another, so the wait adds up. The bound is set well above a normal answer.
24
+ */
25
+ export declare const EXCHANGE_DEPOSIT_READ_ATTEMPT_TIMEOUT_MS = 4000;
26
+ /**
27
+ * What the code read at an address is. A delegated ordinary key still signs for itself, so it is `delegation`, not
28
+ * `contract`. Any other code is `contract`.
29
+ *
30
+ * @param code - the code read at the address, or undefined when the read gave none
31
+ */
32
+ export declare const codeKindOf: (code: `0x${string}` | undefined) => ExchangeDepositCodeKind;
33
+ /**
34
+ * The real source of one chain with a deployed factory.
35
+ *
36
+ * @param input.chainId - the chain of the factory. Its gas table and prices come from the same chain entry.
37
+ * @param input.client - the read client of the factory's chain
38
+ * @param input.clientOfChain - the read client of any chain, by id. The recipient check reads the destination chain
39
+ * of the factory (where the funds land) through it, and never the factory's own chain.
40
+ * @throws when the chain has no factory in this repository
41
+ */
42
+ export declare const chainExchangeDepositSource: ({ chainId, client, clientOfChain, }: {
43
+ chainId: bigint;
44
+ client: ExchangeDepositReadClient;
45
+ clientOfChain: ExchangeDepositClientOfChain;
46
+ }) => ExchangeDepositSource;
47
+ /** The real source of Sepolia, read through the public client of the chain. */
48
+ export declare const sepoliaExchangeDepositSource: () => ExchangeDepositSource;
49
+ /**
50
+ * The name the address bar gives the fake source. A release build offers no fake source, so it names nothing there.
51
+ */
52
+ export declare const FAKE_EXCHANGE_DEPOSIT_NETWORK_NAME = "fake";
53
+ /**
54
+ * Where the interface reads deposit addresses. `factory` is a deployed deposit factory on a chain, and its addresses
55
+ * are real. `fake` is the development-only stand-in. `unavailable` is no source at all: the interface shows no
56
+ * address, no code and nothing to copy.
57
+ */
58
+ export type ExchangeDepositNetwork = {
59
+ readonly kind: 'factory';
60
+ readonly chainId: bigint;
61
+ } | {
62
+ readonly kind: 'fake';
63
+ } | {
64
+ readonly kind: 'unavailable';
65
+ };
66
+ /**
67
+ * Whether the fake source is on offer. Only a development build offers it, so a release build can never show a fake
68
+ * address to a reader.
69
+ */
70
+ export type FakeSourceOffer = 'offered' | 'withheld';
71
+ /** The options of {@link exchangeDepositEntryOf}. */
72
+ export interface ExchangeDepositNetworkOptions {
73
+ /** The name from the address bar (`?network=`), or null when it names none. */
74
+ readonly requestedNetwork: string | null;
75
+ /** The chain of the connected wallet, or null when no wallet is connected. */
76
+ readonly connectedChainId: number | null;
77
+ /** Whether the fake source is on offer. */
78
+ readonly fakeSource: FakeSourceOffer;
79
+ /** The factories to read. Defaults to the deployed ones. */
80
+ readonly factories?: ReadonlyMap<bigint, ExchangeDepositFactoryEntry>;
81
+ }
82
+ /**
83
+ * What the page does before it reads any address. `ready` reads the network it names. `needs-connect` asks the reader to
84
+ * connect a wallet first. `needs-switch` asks the reader to move the connected wallet to `chainId` first. Neither
85
+ * `needs` state carries a network, so the page cannot show an address before the wallet is on that chain.
86
+ */
87
+ export type ExchangeDepositEntry = {
88
+ readonly kind: 'ready';
89
+ readonly network: ExchangeDepositNetwork;
90
+ } | {
91
+ readonly kind: 'needs-connect';
92
+ readonly chainId: bigint;
93
+ } | {
94
+ readonly kind: 'needs-switch';
95
+ readonly chainId: bigint;
96
+ };
97
+ /**
98
+ * The page's entry state, decided in this order:
99
+ *
100
+ * 1. The address bar names `fake`: the fake source, where it is on offer. Otherwise nothing.
101
+ * 2. The address bar names a test network with a factory (`sepolia`): that factory's real addresses while the connected
102
+ * wallet is on that chain. Any other wallet, or no wallet, reads nothing. The test network is never offered by default.
103
+ * 3. The development fake source is on offer and no wallet is connected: the fake source. A release build never gets this.
104
+ * 4. No wallet is connected: `needs-connect` for Ethereum mainnet, the default network.
105
+ * 5. The connected wallet is on another chain: `needs-switch` to Ethereum mainnet.
106
+ * 6. The connected wallet is on Ethereum mainnet: that factory's real addresses.
107
+ *
108
+ * Ethereum mainnet is the default. A name in the address bar that names mainnet (`ethereum`) or nothing at all leads
109
+ * to rules 3 to 6, and an unknown name is ignored. A chain with no factory never gets a real address.
110
+ *
111
+ * @param options - the address bar name, the wallet chain, the fake offer and the factories
112
+ * @returns the entry state the page shows
113
+ */
114
+ export declare const exchangeDepositEntryOf: (options: ExchangeDepositNetworkOptions) => ExchangeDepositEntry;
115
+ /**
116
+ * The source of a network. The fake source is handed in, so the caller decides whether the fake source exists in the
117
+ * build at all. A release build hands in none, and its fake source is never loaded.
118
+ *
119
+ * @param input.network - which source to read. An unavailable network has no source, so the caller must not ask.
120
+ * @param input.scenario - the situation the fake source acts out
121
+ * @param input.fakeSourceOf - the fake source, or null in a build that offers none
122
+ * @throws when the network is unavailable, or is the fake source with no fake source handed in
123
+ */
124
+ export declare const exchangeDepositSourceFor: ({ network, scenario, fakeSourceOf, }: {
125
+ network: ExchangeDepositNetwork;
126
+ scenario: FakeExchangeDepositScenario;
127
+ fakeSourceOf: ((scenario: FakeExchangeDepositScenario) => ExchangeDepositSource) | null;
128
+ }) => ExchangeDepositSource;
129
+ /** What a reader is told about the network an address is for. */
130
+ export interface ExchangeDepositNetworkView {
131
+ /** The chain the addresses are for. */
132
+ readonly chainId: bigint;
133
+ /** The chain's proper name, such as `Sepolia`. It is never translated. */
134
+ readonly chainName: string;
135
+ /** Whether the chain is a test network. */
136
+ readonly isTestNetwork: boolean;
137
+ }
138
+ /**
139
+ * What the page says about the network in use, or null when there is none to say.
140
+ *
141
+ * The fake source acts out Sepolia, so it reads as a test network. A factory reads its own entry.
142
+ *
143
+ * @param network - the network in use
144
+ * @param factories - the factories to read. Defaults to the deployed ones.
145
+ */
146
+ export declare const exchangeDepositNetworkViewOf: (network: ExchangeDepositNetwork, factories?: ReadonlyMap<bigint, ExchangeDepositFactoryEntry>) => ExchangeDepositNetworkView | null;