@gibs/bridge-sdk 1.18.0 → 1.20.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/README.md +33 -0
- package/dist/abis.js +0 -2
- package/dist/bridge-limits.js +0 -38
- package/dist/chain-info.js +0 -116
- package/dist/chain-names.js +0 -151
- package/dist/chains.js +0 -198
- package/dist/cjs/abis.js +0 -2
- package/dist/cjs/bridge-limits.js +0 -38
- package/dist/cjs/chain-info.js +0 -116
- package/dist/cjs/chain-names.js +0 -151
- package/dist/cjs/chains.js +0 -198
- package/dist/cjs/claims.js +0 -60
- package/dist/cjs/config.js +1 -208
- package/dist/cjs/consolidated-quote.js +2 -464
- package/dist/cjs/destination-calldata.js +0 -71
- package/dist/cjs/ecosystems.js +0 -183
- package/dist/cjs/execution.js +0 -92
- package/dist/cjs/fee-type.js +0 -1
- package/dist/cjs/hyperliquid-execution.js +0 -98
- package/dist/cjs/image-links.js +0 -108
- package/dist/cjs/lifi-execution-guard.js +65 -172
- package/dist/cjs/near-intents-conformance.js +0 -110
- package/dist/cjs/near-intents-route.d.ts +13 -0
- package/dist/cjs/near-intents-route.js +7 -140
- package/dist/cjs/near-intents.js +0 -562
- package/dist/cjs/origin-deposit.js +0 -56
- package/dist/cjs/pre-quote.js +0 -80
- package/dist/cjs/prices.js +0 -113
- package/dist/cjs/providers.js +0 -83
- package/dist/cjs/quote-fees.js +0 -80
- package/dist/cjs/referral.js +0 -75
- package/dist/cjs/relay-currencies.js +0 -31
- package/dist/cjs/relay-depository.js +52 -77
- package/dist/cjs/relay-quote.js +0 -394
- package/dist/cjs/route-steps.js +0 -100
- package/dist/cjs/routing/amounts.js +0 -83
- package/dist/cjs/routing/candidate-route.d.ts +46 -1
- package/dist/cjs/routing/candidate-route.js +12 -40
- package/dist/cjs/routing/candidate.js +0 -46
- package/dist/cjs/routing/carrier-provider-key.js +0 -27
- package/dist/cjs/routing/carriers/omnibridge.js +0 -120
- package/dist/cjs/routing/carriers/pulsex-paths.js +0 -57
- package/dist/cjs/routing/carriers/pulsex-split.js +0 -92
- package/dist/cjs/routing/carriers/pulsex.js +0 -279
- package/dist/cjs/routing/carriers/wrap.js +0 -57
- package/dist/cjs/routing/composed-route-quality.js +0 -95
- package/dist/cjs/routing/entry-chain-anchor.js +0 -27
- package/dist/cjs/routing/format.js +0 -50
- package/dist/cjs/routing/index.d.ts +1 -1
- package/dist/cjs/routing/index.js +3 -30
- package/dist/cjs/routing/producers.js +0 -854
- package/dist/cjs/routing/providers.js +0 -27
- package/dist/cjs/routing/search/compose.js +0 -56
- package/dist/cjs/routing/search/graph.js +0 -364
- package/dist/cjs/routing/search/plan-route-data.js +5 -510
- package/dist/cjs/routing/search/score.js +0 -344
- package/dist/cjs/routing/swap-transactions.js +0 -74
- package/dist/cjs/routing/usd-value.js +0 -12
- package/dist/cjs/settings.js +1 -456
- package/dist/cjs/swap-venues.js +0 -17
- package/dist/cjs/ton-connect.js +0 -82
- package/dist/cjs/ton-execution.js +0 -6
- package/dist/cjs/ton.js +0 -42
- package/dist/cjs/tron-execution.js +0 -145
- package/dist/cjs/types.d.ts +8 -0
- package/dist/claims.js +0 -60
- package/dist/config.js +1 -211
- package/dist/consolidated-quote.js +2 -464
- package/dist/destination-calldata.js +0 -71
- package/dist/ecosystems.js +0 -183
- package/dist/execution.js +0 -92
- package/dist/fee-type.js +0 -2
- package/dist/hyperliquid-execution.js +0 -98
- package/dist/image-links.js +0 -108
- package/dist/lifi-execution-guard.js +65 -172
- package/dist/near-intents-conformance.js +0 -110
- package/dist/near-intents-route.d.ts +13 -0
- package/dist/near-intents-route.js +5 -139
- package/dist/near-intents.js +0 -562
- package/dist/origin-deposit.js +0 -56
- package/dist/pre-quote.js +0 -80
- package/dist/prices.js +0 -113
- package/dist/providers.js +0 -83
- package/dist/quote-fees.js +0 -80
- package/dist/referral.js +0 -75
- package/dist/relay-currencies.js +0 -31
- package/dist/relay-depository.js +52 -77
- package/dist/relay-quote.js +0 -394
- package/dist/route-steps.js +0 -100
- package/dist/routing/amounts.js +0 -83
- package/dist/routing/candidate-route.d.ts +46 -1
- package/dist/routing/candidate-route.js +10 -39
- package/dist/routing/candidate.js +0 -46
- package/dist/routing/carrier-provider-key.js +0 -27
- package/dist/routing/carriers/omnibridge.js +0 -120
- package/dist/routing/carriers/pulsex-paths.js +0 -57
- package/dist/routing/carriers/pulsex-split.js +0 -92
- package/dist/routing/carriers/pulsex.js +0 -279
- package/dist/routing/carriers/wrap.js +0 -57
- package/dist/routing/composed-route-quality.js +0 -95
- package/dist/routing/entry-chain-anchor.js +0 -27
- package/dist/routing/format.js +0 -50
- package/dist/routing/index.d.ts +1 -1
- package/dist/routing/index.js +1 -29
- package/dist/routing/producers.js +0 -854
- package/dist/routing/providers.js +0 -27
- package/dist/routing/search/compose.js +0 -56
- package/dist/routing/search/graph.js +0 -364
- package/dist/routing/search/plan-route-data.js +6 -511
- package/dist/routing/search/score.js +0 -344
- package/dist/routing/swap-transactions.js +0 -74
- package/dist/routing/usd-value.js +0 -12
- package/dist/settings.js +1 -456
- package/dist/swap-venues.js +0 -17
- package/dist/ton-connect.js +0 -82
- package/dist/ton-execution.js +0 -6
- package/dist/ton.js +0 -42
- package/dist/tron-execution.js +0 -145
- package/dist/types.d.ts +8 -0
- package/package.json +3 -3
|
@@ -1,35 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Does the live service still answer in the shape this repository parses?
|
|
3
|
-
*
|
|
4
|
-
* THIS EXISTS BECAUSE NEAR INTENTS HAS NO TEST NETWORK. The vendor states it
|
|
5
|
-
* four times in its own current material, most plainly in its list of common
|
|
6
|
-
* questions: "There is no testnet deployment and no plans for one. We
|
|
7
|
-
* recommend testing on NEAR mainnet using separate dev/test NEAR accounts."
|
|
8
|
-
* So there is no safe copy of the service to check an integration against, and
|
|
9
|
-
* the only honest substitute is a priced request against production that
|
|
10
|
-
* reserves nothing — a dry quote. See `docs/near-intents-capability-survey.md`.
|
|
11
|
-
*
|
|
12
|
-
* WHAT THIS CLOSES THAT THE FIXTURES CANNOT. `near-intents.test.ts` runs
|
|
13
|
-
* against real captures taken on 2026-09-17. A capture is a photograph: it
|
|
14
|
-
* proves the parser reads what the service sent that day, and it goes on
|
|
15
|
-
* proving that forever, including after the service stops sending it. Every
|
|
16
|
-
* parser here is tolerant by design — it returns null rather than throwing —
|
|
17
|
-
* so a field that changes type does not break a test, it removes a provider
|
|
18
|
-
* from the interface with no message anywhere. `amountOut` arriving as a
|
|
19
|
-
* number instead of a string is the whole failure: 37 green tests, and NEAR
|
|
20
|
-
* Intents silently never bids again.
|
|
21
|
-
*
|
|
22
|
-
* So these functions name every field the parsers actually depend on and
|
|
23
|
-
* report what is missing, rather than returning a normalized value. Handed a
|
|
24
|
-
* live response they answer "has production drifted away from the captures".
|
|
25
|
-
* Handed a capture they answer "is this capture still a fair stand-in".
|
|
26
|
-
*
|
|
27
|
-
* They are deliberately NOT parsers. A parser answers "can I use this"; these
|
|
28
|
-
* answer "is this what I was written against", which is a different question
|
|
29
|
-
* and needs the failures enumerated rather than collapsed into a null.
|
|
30
|
-
*/
|
|
31
1
|
import { chainIdByNearIntentsChain } from './near-intents.js';
|
|
32
|
-
/** Which parser depends on a field, so a finding says what will break. */
|
|
33
2
|
const describe = (value) => {
|
|
34
3
|
if (value === undefined) {
|
|
35
4
|
return 'absent';
|
|
@@ -45,13 +14,6 @@ const describe = (value) => {
|
|
|
45
14
|
const asRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
46
15
|
? value
|
|
47
16
|
: null;
|
|
48
|
-
/**
|
|
49
|
-
* Checks one field and returns a finding when it is not the required type.
|
|
50
|
-
*
|
|
51
|
-
* A base-unit amount must be a NON-EMPTY string, because that is what
|
|
52
|
-
* `parseAmount` in `near-intents.ts` requires: it refuses an empty string and
|
|
53
|
-
* refuses a number, so either one silently collapses the whole quote to null.
|
|
54
|
-
*/
|
|
55
17
|
const requireField = ({ container, key, path, kind, }) => {
|
|
56
18
|
const value = container[key];
|
|
57
19
|
if (kind === 'amount') {
|
|
@@ -73,21 +35,6 @@ const requireField = ({ container, key, path, kind, }) => {
|
|
|
73
35
|
: { path, expected: 'a non-empty string', found: describe(value) };
|
|
74
36
|
};
|
|
75
37
|
const compact = (findings) => findings.filter((finding) => finding !== null);
|
|
76
|
-
/**
|
|
77
|
-
* Checks a `POST /v0/quote` answer against everything the quote parsers read.
|
|
78
|
-
*
|
|
79
|
-
* THE DOLLAR FIGURES ARE CHECKED THOUGH THE PARSER TOLERATES THEIR ABSENCE.
|
|
80
|
-
* `parseNearIntentsQuote` turns a missing `amountInUsd` into null and carries
|
|
81
|
-
* on, which is right for a quote and wrong for a conformance check: losing the
|
|
82
|
-
* dollar figure leaves the reader a route with no price beside it, and nothing
|
|
83
|
-
* else in the system would report that the service stopped sending one.
|
|
84
|
-
*
|
|
85
|
-
* @param payload - the raw JSON body the service answered with
|
|
86
|
-
* @param options.expectDepositAddress - true for an executable (`dry: false`)
|
|
87
|
-
* answer, false for a dry one. A dry answer omits the deposit address by
|
|
88
|
-
* design, so requiring it there would report a finding on a healthy service
|
|
89
|
-
* @returns every departure from the expected shape; empty means conformant
|
|
90
|
-
*/
|
|
91
38
|
export const nearIntentsQuoteShapeFindings = (payload, { expectDepositAddress }) => {
|
|
92
39
|
const body = asRecord(payload);
|
|
93
40
|
if (!body) {
|
|
@@ -141,17 +88,6 @@ export const nearIntentsQuoteShapeFindings = (payload, { expectDepositAddress })
|
|
|
141
88
|
]);
|
|
142
89
|
return [...findings, ...nearIntentsAppFeeFindings(body.quoteRequest)];
|
|
143
90
|
};
|
|
144
|
-
/**
|
|
145
|
-
* Checks the echoed request for the surcharge a key-less caller is charged.
|
|
146
|
-
*
|
|
147
|
-
* THE SERVICE INSERTS THIS, NOT US. Nothing in this repository asks for an
|
|
148
|
-
* `appFees` entry, and the fee parser only finds the twenty-five-basis-point
|
|
149
|
-
* charge because the service writes it into the request it echoes back. If it
|
|
150
|
-
* ever stops echoing it, the charge does not stop — it disappears from the
|
|
151
|
-
* fee rows and the reader is shown a route that costs a quarter of a percent
|
|
152
|
-
* more than the interface says. That is a silent understatement of cost, so it
|
|
153
|
-
* is a finding rather than a tolerated absence.
|
|
154
|
-
*/
|
|
155
91
|
const nearIntentsAppFeeFindings = (quoteRequest) => {
|
|
156
92
|
const request = asRecord(quoteRequest);
|
|
157
93
|
if (!request) {
|
|
@@ -189,23 +125,6 @@ const nearIntentsAppFeeFindings = (quoteRequest) => {
|
|
|
189
125
|
});
|
|
190
126
|
}));
|
|
191
127
|
};
|
|
192
|
-
/**
|
|
193
|
-
* Checks a `GET /v0/tokens` answer, including the chain names we map by hand.
|
|
194
|
-
*
|
|
195
|
-
* AN UNMAPPED CHAIN NAME IS THE DRIFT MOST LIKELY TO HAPPEN AND LEAST LIKELY
|
|
196
|
-
* TO BE NOTICED. `chainIdByNearIntentsChain` is a hand-written table, and
|
|
197
|
-
* `findNearIntentsAsset` matches through it — so if the service renames a
|
|
198
|
-
* chain or adds one, every asset on that chain becomes invisible to this
|
|
199
|
-
* repository while the asset list parses perfectly and every test stays green.
|
|
200
|
-
* The names are reported rather than the assets, because a new chain we do not
|
|
201
|
-
* carry is ordinary and a renamed chain we DO carry is the emergency.
|
|
202
|
-
*
|
|
203
|
-
* @param payload - the raw JSON body from the asset endpoint
|
|
204
|
-
* @param options.requiredChains - the service's own names for the chains this
|
|
205
|
-
* repository must keep reaching. A name missing from the answer means the
|
|
206
|
-
* service renamed or dropped it
|
|
207
|
-
* @returns every departure from the expected shape; empty means conformant
|
|
208
|
-
*/
|
|
209
128
|
export const nearIntentsTokenListShapeFindings = (payload, { requiredChains }) => {
|
|
210
129
|
if (!Array.isArray(payload)) {
|
|
211
130
|
return [{ path: '', expected: 'an array of assets', found: describe(payload) }];
|
|
@@ -259,26 +178,9 @@ export const nearIntentsTokenListShapeFindings = (payload, { requiredChains }) =
|
|
|
259
178
|
}
|
|
260
179
|
return findings;
|
|
261
180
|
};
|
|
262
|
-
/**
|
|
263
|
-
* The service's own names for every chain this repository maps to a chain
|
|
264
|
-
* identifier, which is exactly the set whose renaming would be invisible.
|
|
265
|
-
*/
|
|
266
181
|
export const nearIntentsMappedChainNames = () => [
|
|
267
182
|
...chainIdByNearIntentsChain.keys(),
|
|
268
183
|
];
|
|
269
|
-
/**
|
|
270
|
-
* Checks a `GET /v0/status` answer against what the status parser reads.
|
|
271
|
-
*
|
|
272
|
-
* THE DELIVERY HASH IS NOT REQUIRED, and that is not laxity. A route awaiting
|
|
273
|
-
* its deposit has genuinely not produced one, and the captured
|
|
274
|
-
* `status-pending-deposit.json` is exactly that case — so requiring it would
|
|
275
|
-
* report a finding on a perfectly healthy in-flight transfer. What is required
|
|
276
|
-
* is that the ARRAY exists, because its absence is the difference between "no
|
|
277
|
-
* hash yet" and "the service stopped telling us where the funds landed".
|
|
278
|
-
*
|
|
279
|
-
* @param payload - the raw JSON body from the status endpoint
|
|
280
|
-
* @returns every departure from the expected shape; empty means conformant
|
|
281
|
-
*/
|
|
282
184
|
export const nearIntentsStatusShapeFindings = (payload) => {
|
|
283
185
|
const body = asRecord(payload);
|
|
284
186
|
if (!body) {
|
|
@@ -306,18 +208,6 @@ export const nearIntentsStatusShapeFindings = (payload) => {
|
|
|
306
208
|
]),
|
|
307
209
|
];
|
|
308
210
|
};
|
|
309
|
-
/**
|
|
310
|
-
* Checks a refusal body carries the message the refusal parser reads.
|
|
311
|
-
*
|
|
312
|
-
* BOTH SIZE FLOORS ARRIVE ONLY AS PROSE IN THIS FIELD. There is no code, no
|
|
313
|
-
* limits endpoint and no structured figure — `parseNearIntentsQuoteRefusal`
|
|
314
|
-
* runs a regular expression over the sentence. So if the wording changes, a
|
|
315
|
-
* refusal that should withdraw the route from the competition instead reads as
|
|
316
|
-
* `other`, and the reader waits for a bid that will never come.
|
|
317
|
-
*
|
|
318
|
-
* @param payload - the raw JSON body of a refused quote
|
|
319
|
-
* @returns every departure from the expected shape; empty means conformant
|
|
320
|
-
*/
|
|
321
211
|
export const nearIntentsRefusalShapeFindings = (payload) => {
|
|
322
212
|
const body = asRecord(payload);
|
|
323
213
|
if (!body) {
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { DeferredCrossing, RouteCandidate } from './routing/candidate.js';
|
|
2
2
|
import type { RouteData } from './routing/route-data.js';
|
|
3
|
+
/**
|
|
4
|
+
* The name of a step that starts on one chain and ends on another (or the same).
|
|
5
|
+
*
|
|
6
|
+
* A step whose two chains differ is "Send to {end chain}". A step that never
|
|
7
|
+
* leaves its chain is a swap, so it is "Swap on {chain}". "Send to Ethereum"
|
|
8
|
+
* on a swap that starts and ends on Ethereum names a crossing that never
|
|
9
|
+
* happens.
|
|
10
|
+
*
|
|
11
|
+
* @param startChainId - the chain the step starts on
|
|
12
|
+
* @param endChainId - the chain the step ends on
|
|
13
|
+
* @returns the step's English label
|
|
14
|
+
*/
|
|
15
|
+
export declare const sendOrSwapLabel: (startChainId: number, endChainId: number) => string;
|
|
3
16
|
/**
|
|
4
17
|
* Builds the two-signature route for a candidate whose aggregator cannot
|
|
5
18
|
* execute the omnibridge entry call.
|
|
@@ -3,63 +3,17 @@ import { BRIDGE_SETTLEMENT_ETA_MINUTES, providerDisplayName, pulsechainChainId,
|
|
|
3
3
|
import { providerById } from './providers.js';
|
|
4
4
|
import { usdValueOfAmount } from './routing/usd-value.js';
|
|
5
5
|
import { chainDisplayName } from './chain-names.js';
|
|
6
|
-
/**
|
|
7
|
-
* The route shape for an aggregator that cannot execute on the chain it
|
|
8
|
-
* delivers to.
|
|
9
|
-
*
|
|
10
|
-
* WHY THIS EXISTS AT ALL. Every other consolidated route in this repository is
|
|
11
|
-
* ONE signature: the aggregator carries the reader's funds to an omnibridge
|
|
12
|
-
* entry chain and its executor performs the entry call on arrival, so the
|
|
13
|
-
* crossing into PulseChain happens inside the same transaction the reader
|
|
14
|
-
* already signed. NEAR Intents cannot do that — it delivers tokens to an
|
|
15
|
-
* address and runs nothing — and no arrangement of recipients works around it,
|
|
16
|
-
* because every omnibridge entry point learns who the reader is from a data
|
|
17
|
-
* field and a plain token transfer has none. See the head of `near-intents.ts`.
|
|
18
|
-
*
|
|
19
|
-
* So the crossing becomes TWO signatures, and the honest thing is to draw it
|
|
20
|
-
* that way. The aggregator lands the anchor token in the reader's OWN wallet on
|
|
21
|
-
* the entry chain; the reader then signs the ordinary omnibridge call
|
|
22
|
-
* themselves. The interface already renders exactly this shape — a section
|
|
23
|
-
* marked `deferred` draws "You sign this later" on the route itself rather than
|
|
24
|
-
* hiding the fact in a tooltip — so nothing new had to be invented to show it.
|
|
25
|
-
*
|
|
26
|
-
* WHAT THIS MUST NEVER DO is present the second signature as optional, or let
|
|
27
|
-
* the route claim a delivered amount as though it were settled. The reader is
|
|
28
|
-
* mid-journey until they sign again, and a route that implies otherwise is
|
|
29
|
-
* selling a single-signature experience it does not deliver.
|
|
30
|
-
*/
|
|
31
|
-
/**
|
|
32
|
-
* Turns a token into the display node the route strip draws, resolving its logo
|
|
33
|
-
* here rather than in the view.
|
|
34
|
-
*
|
|
35
|
-
* Pre-resolved deliberately: a view-layer image fallback reaches only the nodes
|
|
36
|
-
* a builder left unset, so a builder that sets the field and a builder that
|
|
37
|
-
* does not produce different pictures for the same token.
|
|
38
|
-
*
|
|
39
|
-
* The chain badge goes through `networkOrPseudo`, not `network` — a deposit-
|
|
40
|
-
* address origin (Zcash) carries a local, invented chain id the numeric
|
|
41
|
-
* endpoint 404s on. See that helper's own note for why this lives in
|
|
42
|
-
* `image-links.ts` rather than the richer client-side resolver.
|
|
43
|
-
*/
|
|
44
6
|
const tokenNode = (token, chainId) => ({
|
|
45
7
|
symbol: token.symbol,
|
|
46
8
|
address: token.address,
|
|
47
9
|
chainId,
|
|
48
10
|
decimals: token.decimals,
|
|
49
|
-
// `tokenImageOrChainFallback`, NOT `image` — the ANCHOR node this call also
|
|
50
|
-
// draws can reach here before its exact address is known (the deferred
|
|
51
|
-
// crossing has not settled yet), and `image` either throws on an address it
|
|
52
|
-
// cannot checksum or draws nothing at all. See that helper's own note.
|
|
53
11
|
logoUri: imageLinks.tokenImageOrChainFallback(token),
|
|
54
12
|
chainLogoUri: imageLinks.networkOrPseudo(chainId),
|
|
55
13
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* They arrive as decimal strings. A figure that will not parse becomes null
|
|
60
|
-
* rather than zero, because zero is a real value that reads as "this leg is
|
|
61
|
-
* free" — which is the one thing a cost figure must never say by accident.
|
|
62
|
-
*/
|
|
14
|
+
export const sendOrSwapLabel = (startChainId, endChainId) => startChainId === endChainId
|
|
15
|
+
? `Swap on ${chainDisplayName(endChainId)}`
|
|
16
|
+
: `Send to ${chainDisplayName(endChainId)}`;
|
|
63
17
|
const usdNumber = (value) => {
|
|
64
18
|
if (typeof value !== 'string' || value === '') {
|
|
65
19
|
return null;
|
|
@@ -67,41 +21,11 @@ const usdNumber = (value) => {
|
|
|
67
21
|
const parsed = Number(value);
|
|
68
22
|
return Number.isFinite(parsed) ? parsed : null;
|
|
69
23
|
};
|
|
70
|
-
/**
|
|
71
|
-
* Builds the two-signature route for a candidate whose aggregator cannot
|
|
72
|
-
* execute the omnibridge entry call.
|
|
73
|
-
*
|
|
74
|
-
* The result has exactly two sections, and the order carries the meaning:
|
|
75
|
-
*
|
|
76
|
-
* 1. The aggregator's leg, signed NOW. It ends with the anchor token sitting
|
|
77
|
-
* in the reader's own wallet on the entry chain.
|
|
78
|
-
* 2. The omnibridge crossing, marked `deferred`, signed LATER by the reader.
|
|
79
|
-
*
|
|
80
|
-
* COSTS ARE SPLIT BETWEEN THE SECTIONS RATHER THAN POOLED, because a reader
|
|
81
|
-
* deciding whether to accept a second signature needs to know what each half
|
|
82
|
-
* costs. The first section's spread is the difference between the aggregator's
|
|
83
|
-
* own paid and delivered figures — both from the one answer that priced them,
|
|
84
|
-
* never from two feeds. The second section's cost is the omnibridge crossing
|
|
85
|
-
* fee, computed from the known on-chain rate.
|
|
86
|
-
*
|
|
87
|
-
* THE DELIVERED FIGURE IS AN ESTIMATE AND THE INTERFACE KNOWS IT. A route whose
|
|
88
|
-
* last section is deferred has not been quoted end to end, so
|
|
89
|
-
* `outputAmountIsUnsettled` blanks the received-amount field on the reader's
|
|
90
|
-
* behalf. The figure is still carried — the conversion route sets its estimate
|
|
91
|
-
* the same way — so the route can be ranked and compared.
|
|
92
|
-
*
|
|
93
|
-
* @param candidate - the route candidate, which must carry a `deferredCrossing`
|
|
94
|
-
* @returns the two-section route, or null when the candidate names no deferred
|
|
95
|
-
* crossing or no omnibridge provider to perform it
|
|
96
|
-
*/
|
|
97
24
|
export const buildNearIntentsTwoStepRouteData = (candidate) => {
|
|
98
25
|
const deferredCrossing = candidate.deferredCrossing;
|
|
99
26
|
if (!deferredCrossing) {
|
|
100
27
|
return null;
|
|
101
28
|
}
|
|
102
|
-
// No omnibridge leg means there is no second signature, which means this is
|
|
103
|
-
// not the shape being built. A route the aggregator carries end to end is an
|
|
104
|
-
// ordinary one-signature route and belongs to `buildCandidateRouteData`.
|
|
105
29
|
const omnibridgeProviderKey = candidate.omnibridgeProvider;
|
|
106
30
|
if (omnibridgeProviderKey === null) {
|
|
107
31
|
return null;
|
|
@@ -113,9 +37,6 @@ export const buildNearIntentsTwoStepRouteData = (candidate) => {
|
|
|
113
37
|
const destinationNode = tokenNode(destinationToken, pulsechainChainId);
|
|
114
38
|
const paidUsd = usdNumber(candidate.quote.fromAmountUsd);
|
|
115
39
|
const landedUsd = usdNumber(anchorUsdValue);
|
|
116
|
-
// The aggregator's spread on its own leg: what the reader paid, less what the
|
|
117
|
-
// aggregator says arrives. Both figures come from the same answer, so the
|
|
118
|
-
// difference is the route and nothing else.
|
|
119
40
|
const aggregatorFeeUsd = subtractUsdValues(paidUsd, landedUsd);
|
|
120
41
|
const crossingFeeUsd = usdValueOfAmount({
|
|
121
42
|
balance: candidate.omnibridgeFeeAmount,
|
|
@@ -127,35 +48,20 @@ export const buildNearIntentsTwoStepRouteData = (candidate) => {
|
|
|
127
48
|
? Math.ceil(candidate.quote.executionDurationSeconds / 60)
|
|
128
49
|
: null;
|
|
129
50
|
const aggregatorHop = {
|
|
130
|
-
// THIS HOP IS THE AGGREGATOR, NOT THE OMNIBRIDGE — `providerDisplayName`
|
|
131
|
-
// (used for the crossing hop below) is keyed only on `Providers.PULSECHAIN`
|
|
132
|
-
// / `Providers.TOKENSEX` and falls back to the generic "Omnibridge" for
|
|
133
|
-
// anything else. Run through it here, `candidate.quote.provider` (a
|
|
134
|
-
// `ProviderId` — 'lifi' | 'relay' | 'near-intents') had no entry, so a
|
|
135
|
-
// NEAR Intents two-step route named its first leg "Omnibridge" — the
|
|
136
|
-
// bridge, not the aggregator that actually carried it. `providerById` is
|
|
137
|
-
// total over `ProviderId` and throws on an unregistered one rather than
|
|
138
|
-
// silently naming a different provider.
|
|
139
51
|
providerName: providerById(candidate.quote.provider).label,
|
|
140
52
|
providerKey: candidate.quote.provider,
|
|
141
|
-
title:
|
|
53
|
+
title: sendOrSwapLabel(originToken.chainId, candidate.entryChainId),
|
|
142
54
|
conversion: `→ ${anchorToken.symbol}`,
|
|
143
55
|
fromToken: originNode,
|
|
144
56
|
toToken: anchorNode,
|
|
145
57
|
feeUsdValue: aggregatorFeeUsd,
|
|
146
|
-
// The reader's own signature starts this leg; nothing runs inside it.
|
|
147
58
|
automatic: false,
|
|
148
59
|
};
|
|
149
60
|
const aggregatorSection = {
|
|
150
61
|
id: `${candidate.id}-signature-1`,
|
|
151
|
-
|
|
152
|
-
// PulseChain": this signature does not reach PulseChain and a label that
|
|
153
|
-
// said so would be the single-signature claim this route exists to avoid.
|
|
154
|
-
label: `Send to ${chainDisplayName(candidate.entryChainId)}`,
|
|
62
|
+
label: sendOrSwapLabel(originToken.chainId, candidate.entryChainId),
|
|
155
63
|
providerKey: candidate.quote.provider,
|
|
156
64
|
tokenFlow: [originNode, anchorNode],
|
|
157
|
-
// WHAT THE READER IS LEFT HOLDING between the two signatures, in their own
|
|
158
|
-
// wallet on the entry chain. This is the step's whole point.
|
|
159
65
|
landing: {
|
|
160
66
|
amount: anchorAmount,
|
|
161
67
|
decimals: anchorToken.decimals,
|
|
@@ -176,9 +82,6 @@ export const buildNearIntentsTwoStepRouteData = (candidate) => {
|
|
|
176
82
|
fromToken: anchorNode,
|
|
177
83
|
toToken: destinationNode,
|
|
178
84
|
feeUsdValue: crossingFeeUsd,
|
|
179
|
-
// NOT automatic, and this is the difference the whole route turns on. On a
|
|
180
|
-
// one-signature route the aggregator's executor makes this call; here the
|
|
181
|
-
// reader does, by hand, after the anchor lands.
|
|
182
85
|
automatic: false,
|
|
183
86
|
};
|
|
184
87
|
const crossingSection = {
|
|
@@ -193,23 +96,8 @@ export const buildNearIntentsTwoStepRouteData = (candidate) => {
|
|
|
193
96
|
usdValue: subtractUsdValues(landedUsd, crossingFeeUsd),
|
|
194
97
|
},
|
|
195
98
|
feeUsdValue: crossingFeeUsd,
|
|
196
|
-
// THE FLAG THAT MAKES THE ROUTE HONEST. It is what draws "You sign this
|
|
197
|
-
// later" on the step, what makes the primary button name the step it
|
|
198
|
-
// actually signs, and what stops any surface stating the delivered amount
|
|
199
|
-
// as settled. Removing it would turn this into a route that silently
|
|
200
|
-
// promises one signature and asks for two.
|
|
201
99
|
deferred: true,
|
|
202
|
-
// `sectionDescription` in the route strip reads `section.deferredNote ??
|
|
203
|
-
// defaultDeferredNote()`, so a note supplied HERE replaces the default
|
|
204
|
-
// sentence outright rather than adding to it. The default sentence is
|
|
205
|
-
// "Fee is approximate — quoted when you return." — the one fact that
|
|
206
|
-
// tells the reader the output figure they are looking at is not settled.
|
|
207
|
-
// A note that names only the second signature and drops that fact leaves
|
|
208
|
-
// a settled-looking figure on screen with nothing anywhere saying
|
|
209
|
-
// otherwise, so this note must carry BOTH facts itself.
|
|
210
100
|
deferredNote: `The bridge crossing is a second signature you make once the funds arrive on ${chainDisplayName(candidate.entryChainId)}. The amount shown is approximate and is quoted again when you return.`,
|
|
211
|
-
// The crossing's own settlement wait, which is the long part of the journey
|
|
212
|
-
// and has nothing to do with the aggregator's estimate above.
|
|
213
101
|
etaMinutes: BRIDGE_SETTLEMENT_ETA_MINUTES,
|
|
214
102
|
hops: [crossingHop],
|
|
215
103
|
};
|
|
@@ -219,41 +107,19 @@ export const buildNearIntentsTwoStepRouteData = (candidate) => {
|
|
|
219
107
|
return {
|
|
220
108
|
kind: 'aggregated',
|
|
221
109
|
entryChainId: candidate.entryChainId,
|
|
222
|
-
// Named after the omnibridge, matching the one-signature route: a route is
|
|
223
|
-
// named for the thing that performs its defining leg.
|
|
224
110
|
headlineProviderKey: omnibridgeProviderKey,
|
|
225
111
|
sections: [aggregatorSection, crossingSection],
|
|
226
112
|
output: {
|
|
227
113
|
amount: candidate.deliveredAmount,
|
|
228
114
|
decimals: destinationToken.decimals,
|
|
229
115
|
symbol: destinationToken.symbol,
|
|
230
|
-
// The source basis, carried the whole way: what was paid, less what each
|
|
231
|
-
// leg costs. Re-pricing the delivered token against its own feed would
|
|
232
|
-
// state this route's cost twice and the two would not agree.
|
|
233
116
|
usdValue: subtractUsdValues(paidUsd, totalCostUsdValue),
|
|
234
117
|
},
|
|
235
118
|
totalCostUsdValue,
|
|
236
|
-
// Ranked on the same net figure as every other route: delivered value less
|
|
237
|
-
// everything the journey costs.
|
|
238
119
|
netValueUsd: subtractUsdValues(paidUsd, totalCostUsdValue),
|
|
239
|
-
// The reader's wait is BOTH legs, not the aggregator's leg alone. A route
|
|
240
|
-
// that reported only the first would claim to finish before its second
|
|
241
|
-
// signature had even been asked for.
|
|
242
120
|
etaMinutes: (etaMinutes ?? 0) + BRIDGE_SETTLEMENT_ETA_MINUTES,
|
|
243
121
|
};
|
|
244
122
|
};
|
|
245
|
-
/**
|
|
246
|
-
* Describes the anchor a two-signature route leaves the reader holding.
|
|
247
|
-
*
|
|
248
|
-
* A small constructor rather than an inline object literal at the call site,
|
|
249
|
-
* so the three fields are named and documented in one place and a caller
|
|
250
|
-
* cannot quietly pair one aggregator's amount with another's valuation.
|
|
251
|
-
*
|
|
252
|
-
* @param options.anchorToken - the entry-chain token the aggregator delivers
|
|
253
|
-
* @param options.anchorAmount - how much of it lands, in its base units
|
|
254
|
-
* @param options.anchorUsdValue - the AGGREGATOR'S own valuation of that landing
|
|
255
|
-
* @returns the deferred-crossing record, or null when no amount is known
|
|
256
|
-
*/
|
|
257
123
|
export const describeDeferredCrossing = ({ anchorToken, anchorAmount, anchorUsdValue, }) => {
|
|
258
124
|
if (anchorToken === null) {
|
|
259
125
|
return null;
|