@gibs/bridge-sdk 1.12.0 → 1.13.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/LICENSE +15 -0
- package/README.md +234 -432
- package/dist/abis.d.ts +1 -0
- package/dist/bridge-limits.d.ts +103 -0
- package/dist/bridge-limits.js +84 -0
- package/dist/chain-info.d.ts +169 -0
- package/dist/chain-info.js +410 -0
- package/dist/chain-names.d.ts +160 -0
- package/dist/chain-names.js +200 -0
- package/dist/chains.d.ts +65 -0
- package/dist/chains.js +284 -0
- package/dist/config.d.ts +216 -0
- package/dist/config.js +493 -0
- package/dist/consolidated-quote.d.ts +554 -0
- package/dist/consolidated-quote.js +773 -0
- package/dist/destination-calldata.d.ts +118 -0
- package/dist/destination-calldata.js +152 -0
- package/dist/ecosystems.d.ts +217 -0
- package/dist/ecosystems.js +288 -0
- package/dist/fee-type.d.ts +10 -0
- package/dist/fee-type.js +9 -0
- package/dist/hyperliquid-execution.d.ts +152 -0
- package/dist/hyperliquid-execution.js +168 -0
- package/dist/image-links.d.ts +117 -0
- package/dist/image-links.js +142 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +20 -0
- package/dist/lifi-execution-guard.d.ts +199 -0
- package/dist/lifi-execution-guard.js +400 -0
- package/dist/near-intents-conformance.d.ts +85 -0
- package/dist/near-intents-conformance.js +329 -0
- package/dist/near-intents-route.d.ts +47 -0
- package/dist/near-intents-route.js +265 -0
- package/dist/near-intents.d.ts +524 -0
- package/dist/near-intents.js +1055 -0
- package/dist/origin-deposit.d.ts +326 -0
- package/dist/origin-deposit.js +68 -0
- package/dist/pre-quote.d.ts +198 -0
- package/dist/pre-quote.js +175 -0
- package/dist/prices.d.ts +107 -0
- package/dist/prices.js +162 -0
- package/dist/providers.d.ts +221 -0
- package/dist/providers.js +157 -0
- package/dist/quote-fees.d.ts +102 -0
- package/dist/quote-fees.js +195 -0
- package/dist/referral.d.ts +77 -0
- package/dist/referral.js +72 -0
- package/dist/relay-currencies.d.ts +47 -0
- package/dist/relay-currencies.js +89 -0
- package/dist/relay-quote.d.ts +301 -0
- package/dist/relay-quote.js +983 -0
- package/dist/route-steps.d.ts +138 -0
- package/dist/route-steps.js +305 -0
- package/dist/routing/amounts.d.ts +80 -0
- package/dist/routing/amounts.js +120 -0
- package/dist/routing/candidate-route.d.ts +43 -0
- package/dist/routing/candidate-route.js +45 -0
- package/dist/routing/candidate.d.ts +237 -0
- package/dist/routing/candidate.js +96 -0
- package/dist/routing/carriers/ask-answer.d.ts +58 -0
- package/dist/routing/carriers/ask-answer.js +1 -0
- package/dist/routing/carriers/omnibridge.d.ts +137 -0
- package/dist/routing/carriers/omnibridge.js +419 -0
- package/dist/routing/carriers/pulsex.d.ts +111 -0
- package/dist/routing/carriers/pulsex.js +404 -0
- package/dist/routing/carriers/wrap.d.ts +25 -0
- package/dist/routing/carriers/wrap.js +115 -0
- package/dist/routing/composed-route-quality.d.ts +103 -0
- package/dist/routing/composed-route-quality.js +108 -0
- package/dist/routing/entry-chain-anchor.d.ts +88 -0
- package/dist/routing/entry-chain-anchor.js +55 -0
- package/dist/routing/format.d.ts +31 -0
- package/dist/routing/format.js +58 -0
- package/dist/routing/index.d.ts +34 -0
- package/dist/routing/index.js +42 -0
- package/dist/routing/producers.d.ts +770 -0
- package/dist/routing/producers.js +1564 -0
- package/dist/routing/providers.d.ts +26 -0
- package/dist/routing/providers.js +38 -0
- package/dist/routing/route-data.d.ts +355 -0
- package/dist/routing/route-data.js +1 -0
- package/dist/routing/search/compose.d.ts +168 -0
- package/dist/routing/search/compose.js +98 -0
- package/dist/routing/search/graph.d.ts +639 -0
- package/dist/routing/search/graph.js +445 -0
- package/dist/routing/search/plan-route-data.d.ts +244 -0
- package/dist/routing/search/plan-route-data.js +767 -0
- package/dist/routing/search/score.d.ts +324 -0
- package/dist/routing/search/score.js +400 -0
- package/dist/routing/usd-value.d.ts +17 -0
- package/dist/routing/usd-value.js +25 -0
- package/dist/settings.d.ts +692 -0
- package/dist/settings.js +909 -0
- package/dist/ton-execution.d.ts +117 -0
- package/dist/ton-execution.js +247 -0
- package/dist/tron-execution.d.ts +146 -0
- package/dist/tron-execution.js +239 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.js +1 -0
- package/package.json +203 -23
- package/src/chain-info.test.ts +0 -968
- package/src/chain-info.ts +0 -498
- package/src/chains.test.ts +0 -123
- package/src/chains.ts +0 -88
- package/src/config.test.ts +0 -679
- package/src/config.ts +0 -500
- package/src/fee-type.test.ts +0 -45
- package/src/fee-type.ts +0 -14
- package/src/image-links.test.ts +0 -160
- package/src/image-links.ts +0 -65
- package/src/index.ts +0 -8
- package/src/settings.test.ts +0 -2754
- package/src/settings.ts +0 -875
- package/src/types.ts +0 -48
- package/tsconfig.json +0 -17
- package/vitest.config.ts +0 -13
- /package/{src/abis.ts → dist/abis.js} +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { assetNodeKey, combineComposedPathBasis } from './graph.js';
|
|
2
|
+
/** The {@link ComposedPathBasis} one hop's figure contributes: `'quoted'` for a bound quote, its own basis for a `'probeRate'`. */
|
|
3
|
+
export const composableHopBasis = (figure) => figure.kind === 'quote' ? 'quoted' : figure.basis;
|
|
4
|
+
/**
|
|
5
|
+
* Applies one {@link ExchangeRate} to an actual input amount, as an exact
|
|
6
|
+
* bigint multiply-then-divide (floor division — the same rounding direction
|
|
7
|
+
* a real on-chain quote would apply against the reader). Never routes the
|
|
8
|
+
* amount through a float.
|
|
9
|
+
*
|
|
10
|
+
* @param inputAmount - the actual base-unit amount arriving at the hop
|
|
11
|
+
* @param rate - the hop's observed {@link ExchangeRate}
|
|
12
|
+
* @returns the estimated base-unit output
|
|
13
|
+
*/
|
|
14
|
+
const applyExchangeRate = (inputAmount, rate) => (inputAmount * rate.numerator) / rate.denominator;
|
|
15
|
+
/**
|
|
16
|
+
* Composes a path's per-hop figures into one end-to-end estimated delivered
|
|
17
|
+
* amount, applying design section 3's rule: a later hop's output is its
|
|
18
|
+
* probe rate applied to the ACTUAL amount arriving at that hop — never the
|
|
19
|
+
* reference amount the probe itself was taken at.
|
|
20
|
+
*
|
|
21
|
+
* REFUSES RATHER THAN GUESSES in three cases, checked hop by hop so the
|
|
22
|
+
* refusal names the exact hop responsible: the path is empty
|
|
23
|
+
* ({@link ComposeRefusalReason} `'empty-path'`); a hop does not connect to the
|
|
24
|
+
* one before it (`'discontinuous-path'`); two hops disagree about a shared
|
|
25
|
+
* asset's decimals (`'decimals-mismatch'`); or a `'probeRate'` figure names
|
|
26
|
+
* no real ratio (`'missing-rate'`). See {@link ComposeRefusalReason} for why
|
|
27
|
+
* each of these is a refusal and not a best-effort answer.
|
|
28
|
+
*
|
|
29
|
+
* @param inputAmount - the base-unit amount entering the path's first hop
|
|
30
|
+
* @param hops - the path's hops, first to last
|
|
31
|
+
* @returns the composed estimate, or the refusal that stopped composition
|
|
32
|
+
*/
|
|
33
|
+
export const composeRouteDelivery = (inputAmount, hops) => {
|
|
34
|
+
if (hops.length === 0) {
|
|
35
|
+
return { kind: 'refused', reason: 'empty-path', hopIndex: 0 };
|
|
36
|
+
}
|
|
37
|
+
let actualInput = inputAmount;
|
|
38
|
+
let basis = 'quoted';
|
|
39
|
+
for (let hopIndex = 0; hopIndex < hops.length; hopIndex += 1) {
|
|
40
|
+
const hop = hops[hopIndex];
|
|
41
|
+
const continuityFailure = checkContinuity(hops, hopIndex);
|
|
42
|
+
if (continuityFailure !== null) {
|
|
43
|
+
return { kind: 'refused', reason: continuityFailure, hopIndex };
|
|
44
|
+
}
|
|
45
|
+
const outputAmount = hopOutputAmount(hop, actualInput);
|
|
46
|
+
if (outputAmount === null) {
|
|
47
|
+
return { kind: 'refused', reason: 'missing-rate', hopIndex };
|
|
48
|
+
}
|
|
49
|
+
basis = combineComposedPathBasis(basis, composableHopBasis(hop.figure));
|
|
50
|
+
actualInput = outputAmount;
|
|
51
|
+
}
|
|
52
|
+
return { kind: 'estimate', deliveredAmount: actualInput, basis };
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Checks that hop `hopIndex` connects to the hop before it: the same asset,
|
|
56
|
+
* by {@link assetNodeKey}, with the same declared decimals. The first hop has
|
|
57
|
+
* nothing before it and always passes.
|
|
58
|
+
*
|
|
59
|
+
* @param hops - the full path being composed
|
|
60
|
+
* @param hopIndex - the hop to check against its predecessor
|
|
61
|
+
* @returns the refusal reason, or null when the hop connects cleanly
|
|
62
|
+
*/
|
|
63
|
+
const checkContinuity = (hops, hopIndex) => {
|
|
64
|
+
if (hopIndex === 0)
|
|
65
|
+
return null;
|
|
66
|
+
const previousTo = hops[hopIndex - 1].edge.to;
|
|
67
|
+
const currentFrom = hops[hopIndex].edge.from;
|
|
68
|
+
if (assetNodeKey(previousTo) !== assetNodeKey(currentFrom))
|
|
69
|
+
return 'discontinuous-path';
|
|
70
|
+
if (previousTo.decimals !== currentFrom.decimals)
|
|
71
|
+
return 'decimals-mismatch';
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* One hop's output amount for the actual amount arriving at it: the quote's
|
|
76
|
+
* own `outputAmount` when the figure is a real quote, or the probe rate
|
|
77
|
+
* applied to `actualInput` when it is a `'probeRate'`. Returns null — never a
|
|
78
|
+
* guessed number — when a `'probeRate'` figure's rate names no positive
|
|
79
|
+
* denominator.
|
|
80
|
+
*
|
|
81
|
+
* EXPORTED SO `waves.ts` REUSES THIS MATH RATHER THAN RESTATING IT.
|
|
82
|
+
* `recomposePath` (`waves.ts`) needs each hop's OWN output amount, not just
|
|
83
|
+
* the path's final total {@link composeRouteDelivery} returns, to refresh
|
|
84
|
+
* every hop's individual `outcome` — this is the one place that division
|
|
85
|
+
* happens, so both call sites agree by construction instead of by two
|
|
86
|
+
* separately-maintained copies of `numerator * input / denominator`.
|
|
87
|
+
*
|
|
88
|
+
* @param hop - the hop to price
|
|
89
|
+
* @param actualInput - the actual base-unit amount arriving at this hop
|
|
90
|
+
* @returns the hop's output amount, or null when its rate is missing
|
|
91
|
+
*/
|
|
92
|
+
export const hopOutputAmount = (hop, actualInput) => {
|
|
93
|
+
if (hop.figure.kind === 'quote')
|
|
94
|
+
return hop.figure.outputAmount;
|
|
95
|
+
if (hop.figure.rate.denominator <= 0n)
|
|
96
|
+
return null;
|
|
97
|
+
return applyExchangeRate(actualInput, hop.figure.rate);
|
|
98
|
+
};
|