@gibs/bridge-client 1.30.1 → 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.
- package/coinbase-accept-list/package.json +6 -0
- package/dist/cjs/client.d.ts +9 -1
- package/dist/cjs/client.js +8 -5
- package/dist/cjs/coinbase-accept-list.d.ts +101 -0
- package/dist/cjs/coinbase-accept-list.js +97 -0
- package/dist/cjs/crossing-decision.d.ts +166 -0
- package/dist/cjs/crossing-decision.js +169 -0
- package/dist/cjs/crossing-vector-guard.d.ts +45 -0
- package/dist/cjs/crossing-vector-guard.js +139 -0
- package/dist/cjs/exchange-deposit-board.d.ts +50 -0
- package/dist/cjs/exchange-deposit-board.js +70 -0
- package/dist/cjs/exchange-deposit-chain.d.ts +146 -0
- package/dist/cjs/exchange-deposit-chain.js +228 -0
- package/dist/cjs/exchange-deposit-constants.d.ts +10 -0
- package/dist/cjs/exchange-deposit-constants.js +6 -0
- package/dist/cjs/exchange-deposit-factory-calls.d.ts +245 -0
- package/dist/cjs/exchange-deposit-factory-calls.js +103 -0
- package/dist/cjs/exchange-deposit-factory.d.ts +87 -0
- package/dist/cjs/exchange-deposit-factory.js +110 -0
- package/dist/cjs/exchange-deposit-fake.d.ts +67 -0
- package/dist/cjs/exchange-deposit-fake.js +179 -0
- package/dist/cjs/exchange-deposit-index.d.ts +77 -0
- package/dist/cjs/exchange-deposit-index.js +40 -0
- package/dist/cjs/exchange-deposit-issuance.d.ts +327 -0
- package/dist/cjs/exchange-deposit-issuance.js +244 -0
- package/dist/cjs/exchange-deposit-path.d.ts +16 -0
- package/dist/cjs/exchange-deposit-path.js +15 -0
- package/dist/cjs/exchange-deposit-pow.d.ts +163 -0
- package/dist/cjs/exchange-deposit-pow.js +101 -0
- package/dist/cjs/exchange-deposit-recipient.d.ts +66 -0
- package/dist/cjs/exchange-deposit-recipient.js +35 -0
- package/dist/cjs/exchange-deposit-self-cross.d.ts +163 -0
- package/dist/cjs/exchange-deposit-self-cross.js +60 -0
- package/dist/cjs/exchange-deposit-signin.d.ts +275 -0
- package/dist/cjs/exchange-deposit-signin.js +166 -0
- package/dist/cjs/exchange-deposit-watch.d.ts +133 -0
- package/dist/cjs/exchange-deposit-watch.js +58 -0
- package/dist/cjs/exchange-deposit.d.ts +440 -0
- package/dist/cjs/exchange-deposit.js +154 -0
- package/dist/cjs/exchange-sender-guides.d.ts +29 -0
- package/dist/cjs/exchange-sender-guides.js +25 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +24 -1
- package/dist/cjs/kraken-accept-list.d.ts +70 -0
- package/dist/cjs/kraken-accept-list.js +24 -0
- package/dist/client.d.ts +9 -1
- package/dist/client.js +8 -5
- package/dist/coinbase-accept-list.d.ts +101 -0
- package/dist/coinbase-accept-list.js +89 -0
- package/dist/crossing-decision.d.ts +166 -0
- package/dist/crossing-decision.js +162 -0
- package/dist/crossing-vector-guard.d.ts +45 -0
- package/dist/crossing-vector-guard.js +134 -0
- package/dist/exchange-deposit-board.d.ts +50 -0
- package/dist/exchange-deposit-board.js +28 -0
- package/dist/exchange-deposit-chain.d.ts +146 -0
- package/dist/exchange-deposit-chain.js +218 -0
- package/dist/exchange-deposit-constants.d.ts +10 -0
- package/dist/exchange-deposit-constants.js +3 -0
- package/dist/exchange-deposit-factory-calls.d.ts +245 -0
- package/dist/exchange-deposit-factory-calls.js +97 -0
- package/dist/exchange-deposit-factory.d.ts +87 -0
- package/dist/exchange-deposit-factory.js +104 -0
- package/dist/exchange-deposit-fake.d.ts +67 -0
- package/dist/exchange-deposit-fake.js +171 -0
- package/dist/exchange-deposit-index.d.ts +77 -0
- package/dist/exchange-deposit-index.js +34 -0
- package/dist/exchange-deposit-issuance.d.ts +327 -0
- package/dist/exchange-deposit-issuance.js +224 -0
- package/dist/exchange-deposit-path.d.ts +16 -0
- package/dist/exchange-deposit-path.js +11 -0
- package/dist/exchange-deposit-pow.d.ts +163 -0
- package/dist/exchange-deposit-pow.js +93 -0
- package/dist/exchange-deposit-recipient.d.ts +66 -0
- package/dist/exchange-deposit-recipient.js +28 -0
- package/dist/exchange-deposit-self-cross.d.ts +163 -0
- package/dist/exchange-deposit-self-cross.js +46 -0
- package/dist/exchange-deposit-signin.d.ts +275 -0
- package/dist/exchange-deposit-signin.js +147 -0
- package/dist/exchange-deposit-watch.d.ts +133 -0
- package/dist/exchange-deposit-watch.js +44 -0
- package/dist/exchange-deposit.d.ts +440 -0
- package/dist/exchange-deposit.js +138 -0
- package/dist/exchange-sender-guides.d.ts +29 -0
- package/dist/exchange-sender-guides.js +21 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kraken-accept-list.d.ts +70 -0
- package/dist/kraken-accept-list.js +17 -0
- package/exchange-deposit/package.json +6 -0
- package/exchange-deposit-board/package.json +6 -0
- package/exchange-deposit-chain/package.json +6 -0
- package/exchange-deposit-factory/package.json +6 -0
- package/exchange-deposit-fake/package.json +6 -0
- package/exchange-deposit-issuance/package.json +6 -0
- package/exchange-deposit-path/package.json +6 -0
- package/exchange-deposit-pow/package.json +6 -0
- package/exchange-deposit-recipient/package.json +6 -0
- package/exchange-deposit-self-cross/package.json +6 -0
- package/exchange-deposit-signin/package.json +6 -0
- package/exchange-deposit-watch/package.json +6 -0
- package/exchange-sender-guides/package.json +6 -0
- package/kraken-accept-list/package.json +6 -0
- package/package.json +429 -4
|
@@ -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;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exchangeDepositNetworkViewOf = exports.exchangeDepositSourceFor = exports.exchangeDepositEntryOf = exports.FAKE_EXCHANGE_DEPOSIT_NETWORK_NAME = exports.sepoliaExchangeDepositSource = exports.chainExchangeDepositSource = exports.codeKindOf = exports.EXCHANGE_DEPOSIT_READ_ATTEMPT_TIMEOUT_MS = exports.exchangeDepositFlushRequest = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const client_js_1 = require("./client.js");
|
|
6
|
+
const exchange_deposit_js_1 = require("./exchange-deposit.js");
|
|
7
|
+
const exchange_deposit_factory_js_1 = require("./exchange-deposit-factory.js");
|
|
8
|
+
const exchange_deposit_factory_calls_js_1 = require("./exchange-deposit-factory-calls.js");
|
|
9
|
+
const exchange_deposit_index_js_1 = require("./exchange-deposit-index.js");
|
|
10
|
+
var exchange_deposit_factory_calls_js_2 = require("./exchange-deposit-factory-calls.js");
|
|
11
|
+
Object.defineProperty(exports, "exchangeDepositFlushRequest", { enumerable: true, get: function () { return exchange_deposit_factory_calls_js_2.exchangeDepositFlushRequest; } });
|
|
12
|
+
exports.EXCHANGE_DEPOSIT_READ_ATTEMPT_TIMEOUT_MS = 4_000;
|
|
13
|
+
const readClientOfChain = (chainId) => (0, client_js_1.clientFromChain)(Number(chainId), { attemptTimeoutMs: exports.EXCHANGE_DEPOSIT_READ_ATTEMPT_TIMEOUT_MS });
|
|
14
|
+
const SAFETY_MULTIPLE_THOUSANDTHS = 2000n;
|
|
15
|
+
const DELEGATION_CODE_PATTERN = /^0xef0100[0-9a-f]{40}$/i;
|
|
16
|
+
const codeKindOf = (code) => {
|
|
17
|
+
if (code === undefined || code === '0x')
|
|
18
|
+
return 'no-code';
|
|
19
|
+
if (DELEGATION_CODE_PATTERN.test(code))
|
|
20
|
+
return 'delegation';
|
|
21
|
+
return 'contract';
|
|
22
|
+
};
|
|
23
|
+
exports.codeKindOf = codeKindOf;
|
|
24
|
+
const chainExchangeDepositSource = ({ chainId, client, clientOfChain, }) => {
|
|
25
|
+
const factory = (0, exchange_deposit_factory_js_1.exchangeDepositFactoryOf)(chainId);
|
|
26
|
+
const tokenOf = (tokenAddress) => {
|
|
27
|
+
const found = factory.tokens.find((candidate) => candidate.address.toLowerCase() === tokenAddress.toLowerCase());
|
|
28
|
+
if (found === undefined)
|
|
29
|
+
throw new Error(`token ${tokenAddress} is not offered on chain ${chainId}`);
|
|
30
|
+
return found;
|
|
31
|
+
};
|
|
32
|
+
const feeLimits = async () => {
|
|
33
|
+
try {
|
|
34
|
+
const [maximumFeeRateE18, maximumPartnerRateE18] = await Promise.all([
|
|
35
|
+
client.readContract({
|
|
36
|
+
address: factory.address,
|
|
37
|
+
abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_ABI,
|
|
38
|
+
functionName: 'MAXIMUM_FEE_RATE_E18',
|
|
39
|
+
}),
|
|
40
|
+
client.readContract({
|
|
41
|
+
address: factory.address,
|
|
42
|
+
abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_ABI,
|
|
43
|
+
functionName: 'MAXIMUM_PARTNER_RATE_E18',
|
|
44
|
+
}),
|
|
45
|
+
]);
|
|
46
|
+
return { maximumFeeRateE18, maximumPartnerRateE18 };
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error(`${exchange_deposit_js_1.EXCHANGE_DEPOSIT_FEE_LIMITS_UNREADABLE} Cause: ${error.message}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const minimumKeyOf = (token) => token.contractGroup === 'ether' ? factory.wrappedEtherAddress : token.address;
|
|
53
|
+
const minimumPerTxByAddressOf = async () => {
|
|
54
|
+
const mediator = await client.readContract({
|
|
55
|
+
address: factory.address,
|
|
56
|
+
abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_ABI,
|
|
57
|
+
functionName: 'mediator',
|
|
58
|
+
});
|
|
59
|
+
const minimums = await Promise.all(factory.tokens.map((token) => client.readContract({
|
|
60
|
+
address: mediator,
|
|
61
|
+
abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_MEDIATOR_ABI,
|
|
62
|
+
functionName: 'minPerTx',
|
|
63
|
+
args: [minimumKeyOf(token)],
|
|
64
|
+
})));
|
|
65
|
+
return Object.fromEntries(factory.tokens.map((token, index) => [token.address.toLowerCase(), minimums[index]]));
|
|
66
|
+
};
|
|
67
|
+
const readBalance = (token, address) => token.contractGroup === 'ether'
|
|
68
|
+
? client.getBalance({ address })
|
|
69
|
+
: client.readContract({ address: token.address, abi: viem_1.erc20Abi, functionName: 'balanceOf', args: [address] });
|
|
70
|
+
const hasFactoryEventOf = async (factoryEntry, address) => {
|
|
71
|
+
const logs = await Promise.all(exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_USAGE_EVENTS.map((event) => client.getLogs({
|
|
72
|
+
address: factoryEntry.address,
|
|
73
|
+
event,
|
|
74
|
+
args: { depositAddress: address },
|
|
75
|
+
fromBlock: factoryEntry.deployedBlock,
|
|
76
|
+
toBlock: 'latest',
|
|
77
|
+
})));
|
|
78
|
+
return logs.some((found) => found.length > 0);
|
|
79
|
+
};
|
|
80
|
+
const probeWithLimits = async (request, limits) => {
|
|
81
|
+
const token = tokenOf(request.tokenAddress);
|
|
82
|
+
(0, exchange_deposit_js_1.assertFeeRatesWithinLimits)({
|
|
83
|
+
feeRateE18: request.feeRateE18,
|
|
84
|
+
partnerRateE18: 0n,
|
|
85
|
+
limits,
|
|
86
|
+
});
|
|
87
|
+
const settings = {
|
|
88
|
+
recipient: request.recipient,
|
|
89
|
+
tokenAddress: request.tokenAddress,
|
|
90
|
+
feeRateE18: request.feeRateE18,
|
|
91
|
+
unwrapToNativePls: false,
|
|
92
|
+
counter: request.counter,
|
|
93
|
+
index: (0, exchange_deposit_index_js_1.factoryIndexOf)({
|
|
94
|
+
seed: request.seed,
|
|
95
|
+
tokenAddress: request.tokenAddress,
|
|
96
|
+
feeRateE18: request.feeRateE18,
|
|
97
|
+
counter: request.counter,
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
const address = await client.readContract({
|
|
101
|
+
address: factory.address,
|
|
102
|
+
abi: exchange_deposit_factory_calls_js_1.EXCHANGE_DEPOSIT_FACTORY_ABI,
|
|
103
|
+
functionName: 'depositAddress',
|
|
104
|
+
args: [(0, exchange_deposit_factory_calls_js_1.factorySettingsTupleOf)({ settings, token })],
|
|
105
|
+
});
|
|
106
|
+
const balance = await readBalance(token, address);
|
|
107
|
+
return { address, token, balance, settings };
|
|
108
|
+
};
|
|
109
|
+
const probe = async (request) => probeWithLimits(request, await feeLimits());
|
|
110
|
+
return {
|
|
111
|
+
listTokens: async () => factory.tokens,
|
|
112
|
+
feeLimits,
|
|
113
|
+
addressFor: async (request) => {
|
|
114
|
+
const { address, token, settings, balance } = await probe(request);
|
|
115
|
+
const result = {
|
|
116
|
+
origin: 'derived',
|
|
117
|
+
address,
|
|
118
|
+
settings,
|
|
119
|
+
token,
|
|
120
|
+
waiting: balance,
|
|
121
|
+
crossing: null,
|
|
122
|
+
};
|
|
123
|
+
return result;
|
|
124
|
+
},
|
|
125
|
+
nextCounterFor: async ({ startCounter, ...request }) => {
|
|
126
|
+
const limits = await feeLimits();
|
|
127
|
+
return (0, exchange_deposit_index_js_1.firstUnusedIndexFrom)({
|
|
128
|
+
start: startCounter,
|
|
129
|
+
isUsed: async (counter) => {
|
|
130
|
+
const { address, balance } = await probeWithLimits({ ...request, counter }, limits);
|
|
131
|
+
const hasFactoryEvent = await hasFactoryEventOf(factory, address);
|
|
132
|
+
return (0, exchange_deposit_index_js_1.exchangeDepositAddressIsUsed)({ balance, hasFactoryEvent });
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
crossingConditions: async () => {
|
|
137
|
+
const [block, fees, minimumPerTxByAddress] = await Promise.all([
|
|
138
|
+
client.getBlock({ blockTag: 'latest' }),
|
|
139
|
+
client.estimateFeesPerGas(),
|
|
140
|
+
minimumPerTxByAddressOf(),
|
|
141
|
+
]);
|
|
142
|
+
if (block.baseFeePerGas === null)
|
|
143
|
+
throw new Error(`chain ${chainId} reports no base fee`);
|
|
144
|
+
return {
|
|
145
|
+
gasTable: (0, exchange_deposit_js_1.exchangeDepositGasTableOf)(chainId),
|
|
146
|
+
baseFeeWei: block.baseFeePerGas,
|
|
147
|
+
priorityFeeWei: fees.maxPriorityFeePerGas,
|
|
148
|
+
multipleThousandths: SAFETY_MULTIPLE_THOUSANDTHS,
|
|
149
|
+
weiPerWholeTokenByAddress: factory.weiPerWholeTokenByAddress,
|
|
150
|
+
minimumPerTxByAddress,
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
signerCodeKind: async (signer) => (0, exports.codeKindOf)(await client.getCode({ address: signer })),
|
|
154
|
+
recipientHasCode: async (recipient) => {
|
|
155
|
+
const destination = clientOfChain(factory.destinationChainId);
|
|
156
|
+
return (0, exports.codeKindOf)(await destination.getCode({ address: recipient })) === 'contract';
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
exports.chainExchangeDepositSource = chainExchangeDepositSource;
|
|
161
|
+
const sepoliaExchangeDepositSource = () => (0, exports.chainExchangeDepositSource)({
|
|
162
|
+
chainId: exchange_deposit_js_1.SEPOLIA_CHAIN_ID,
|
|
163
|
+
client: readClientOfChain(exchange_deposit_js_1.SEPOLIA_CHAIN_ID),
|
|
164
|
+
clientOfChain: readClientOfChain,
|
|
165
|
+
});
|
|
166
|
+
exports.sepoliaExchangeDepositSource = sepoliaExchangeDepositSource;
|
|
167
|
+
exports.FAKE_EXCHANGE_DEPOSIT_NETWORK_NAME = 'fake';
|
|
168
|
+
const chainIdOfAddressBarName = ({ name, factories, }) => {
|
|
169
|
+
if (name === null)
|
|
170
|
+
return null;
|
|
171
|
+
const match = [...factories].find(([, entry]) => entry.addressBarName === name);
|
|
172
|
+
return match === undefined ? null : match[0];
|
|
173
|
+
};
|
|
174
|
+
const exchangeDepositEntryOf = (options) => {
|
|
175
|
+
const { requestedNetwork, connectedChainId, fakeSource, factories = exchange_deposit_factory_js_1.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN } = options;
|
|
176
|
+
const fakeOrNothing = fakeSource === 'offered' ? { kind: 'fake' } : { kind: 'unavailable' };
|
|
177
|
+
if (requestedNetwork === exports.FAKE_EXCHANGE_DEPOSIT_NETWORK_NAME)
|
|
178
|
+
return { kind: 'ready', network: fakeOrNothing };
|
|
179
|
+
const namedChainId = chainIdOfAddressBarName({ name: requestedNetwork, factories });
|
|
180
|
+
if (namedChainId !== null && namedChainId !== exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID) {
|
|
181
|
+
return { kind: 'ready', network: namedChainIdOrNothing({ namedChainId, connectedChainId }) };
|
|
182
|
+
}
|
|
183
|
+
if (namedChainId === null && connectedChainId === null && fakeSource === 'offered') {
|
|
184
|
+
return { kind: 'ready', network: { kind: 'fake' } };
|
|
185
|
+
}
|
|
186
|
+
return mainnetEntryOf({ connectedChainId, factories });
|
|
187
|
+
};
|
|
188
|
+
exports.exchangeDepositEntryOf = exchangeDepositEntryOf;
|
|
189
|
+
const mainnetEntryOf = ({ connectedChainId, factories, }) => {
|
|
190
|
+
if (!factories.has(exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID))
|
|
191
|
+
return { kind: 'ready', network: { kind: 'unavailable' } };
|
|
192
|
+
if (connectedChainId === null)
|
|
193
|
+
return { kind: 'needs-connect', chainId: exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID };
|
|
194
|
+
if (BigInt(connectedChainId) !== exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID)
|
|
195
|
+
return { kind: 'needs-switch', chainId: exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID };
|
|
196
|
+
return { kind: 'ready', network: { kind: 'factory', chainId: exchange_deposit_js_1.ETHEREUM_MAINNET_CHAIN_ID } };
|
|
197
|
+
};
|
|
198
|
+
const namedChainIdOrNothing = ({ namedChainId, connectedChainId, }) => {
|
|
199
|
+
if (connectedChainId === null)
|
|
200
|
+
return { kind: 'unavailable' };
|
|
201
|
+
if (BigInt(connectedChainId) !== namedChainId)
|
|
202
|
+
return { kind: 'unavailable' };
|
|
203
|
+
return { kind: 'factory', chainId: namedChainId };
|
|
204
|
+
};
|
|
205
|
+
const exchangeDepositSourceFor = ({ network, scenario, fakeSourceOf, }) => {
|
|
206
|
+
if (network.kind === 'factory') {
|
|
207
|
+
return (0, exports.chainExchangeDepositSource)({
|
|
208
|
+
chainId: network.chainId,
|
|
209
|
+
client: readClientOfChain(network.chainId),
|
|
210
|
+
clientOfChain: readClientOfChain,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (network.kind === 'fake' && fakeSourceOf !== null)
|
|
214
|
+
return fakeSourceOf(scenario);
|
|
215
|
+
throw new Error('no deposit source is available for this network');
|
|
216
|
+
};
|
|
217
|
+
exports.exchangeDepositSourceFor = exchangeDepositSourceFor;
|
|
218
|
+
const exchangeDepositNetworkViewOf = (network, factories = exchange_deposit_factory_js_1.EXCHANGE_DEPOSIT_FACTORY_BY_CHAIN) => {
|
|
219
|
+
if (network.kind === 'unavailable')
|
|
220
|
+
return null;
|
|
221
|
+
if (network.kind === 'fake')
|
|
222
|
+
return { chainId: exchange_deposit_js_1.SEPOLIA_CHAIN_ID, chainName: 'Sepolia', isTestNetwork: true };
|
|
223
|
+
const entry = factories.get(network.chainId);
|
|
224
|
+
if (entry === undefined)
|
|
225
|
+
return null;
|
|
226
|
+
return { chainId: network.chainId, chainName: entry.chainName, isTestNetwork: entry.isTestNetwork };
|
|
227
|
+
};
|
|
228
|
+
exports.exchangeDepositNetworkViewOf = exchangeDepositNetworkViewOf;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Two numbers the deposit modules share. They live in their own module, so the factory map and the bridge entry can
|
|
3
|
+
* read them without loading the whole deposit module into the first load. `exchange-deposit.ts` re-exports both.
|
|
4
|
+
*/
|
|
5
|
+
/** Wei in one ether. */
|
|
6
|
+
export declare const WEI_PER_ETHER: bigint;
|
|
7
|
+
/** The chain id of the Sepolia test network. */
|
|
8
|
+
export declare const SEPOLIA_CHAIN_ID = 11155111n;
|
|
9
|
+
/** The chain id of Ethereum mainnet. */
|
|
10
|
+
export declare const ETHEREUM_MAINNET_CHAIN_ID = 1n;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ETHEREUM_MAINNET_CHAIN_ID = exports.SEPOLIA_CHAIN_ID = exports.WEI_PER_ETHER = void 0;
|
|
4
|
+
exports.WEI_PER_ETHER = 10n ** 18n;
|
|
5
|
+
exports.SEPOLIA_CHAIN_ID = 11155111n;
|
|
6
|
+
exports.ETHEREUM_MAINNET_CHAIN_ID = 1n;
|