@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,36 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.depositFamilyOf = exports.isUnreservedDeposit = exports.isDepositAddressDeposit = exports.isHyperliquidDeposit = exports.isTonDeposit = exports.isTronDeposit = exports.isBitcoinDeposit = exports.isSolanaSerializedDeposit = exports.isSolanaInstructionsDeposit = exports.isSolanaDeposit = exports.isEvmDeposit = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* The ecosystem whose signer a deposit needs, or null for a deposit that needs
|
|
6
|
-
* no signer at all.
|
|
7
|
-
*
|
|
8
|
-
* THE ONE PLACE THE ECOSYSTEM TAG IS READ. A {@link DepositAddressDeposit} has
|
|
9
|
-
* no `ecosystem`, so every guard below asks through this instead of reading the
|
|
10
|
-
* field directly — which also means no ecosystem guard can ever answer true for
|
|
11
|
-
* a deposit the reader pays by hand.
|
|
12
|
-
*
|
|
13
|
-
* TYPED `Ecosystem | null`, NOT `string | null`. A `string` return let a typo
|
|
14
|
-
* such as `signerEcosystemOf(deposit) === 'hypvm'` compile silently — the
|
|
15
|
-
* comparison is just false forever, so `isHyperliquidDeposit` would always
|
|
16
|
-
* answer false and every Hyperliquid deposit would fall through to the
|
|
17
|
-
* Ethereum branch. Typed on the union, the same typo fails to compile instead.
|
|
18
|
-
*/
|
|
19
4
|
const signerEcosystemOf = (deposit) => 'ecosystem' in deposit ? deposit.ecosystem : null;
|
|
20
5
|
const isEvmDeposit = (deposit) => signerEcosystemOf(deposit) === 'evm';
|
|
21
6
|
exports.isEvmDeposit = isEvmDeposit;
|
|
22
7
|
const isSolanaDeposit = (deposit) => signerEcosystemOf(deposit) === 'svm';
|
|
23
8
|
exports.isSolanaDeposit = isSolanaDeposit;
|
|
24
|
-
/**
|
|
25
|
-
* Narrows a Solana deposit to the instruction form, which must be compiled
|
|
26
|
-
* before it can be signed.
|
|
27
|
-
*/
|
|
28
9
|
const isSolanaInstructionsDeposit = (deposit) => deposit.form === 'instructions';
|
|
29
10
|
exports.isSolanaInstructionsDeposit = isSolanaInstructionsDeposit;
|
|
30
|
-
/**
|
|
31
|
-
* Narrows a Solana deposit to the pre-compiled form, which must be signed
|
|
32
|
-
* as-is.
|
|
33
|
-
*/
|
|
34
11
|
const isSolanaSerializedDeposit = (deposit) => deposit.form === 'serialized';
|
|
35
12
|
exports.isSolanaSerializedDeposit = isSolanaSerializedDeposit;
|
|
36
13
|
const isBitcoinDeposit = (deposit) => signerEcosystemOf(deposit) === 'bvm';
|
|
@@ -41,42 +18,9 @@ const isTonDeposit = (deposit) => signerEcosystemOf(deposit) === 'tonvm';
|
|
|
41
18
|
exports.isTonDeposit = isTonDeposit;
|
|
42
19
|
const isHyperliquidDeposit = (deposit) => signerEcosystemOf(deposit) === 'hypevm';
|
|
43
20
|
exports.isHyperliquidDeposit = isHyperliquidDeposit;
|
|
44
|
-
/**
|
|
45
|
-
* Narrows a deposit to the pay-by-hand shape: an address, an amount, and
|
|
46
|
-
* nothing to sign.
|
|
47
|
-
*
|
|
48
|
-
* THE GUARD EVERY EXECUTION PATH MUST ASK FIRST. A surface that falls through
|
|
49
|
-
* to a signer with one of these has no transaction to give it, and a surface
|
|
50
|
-
* that asks the reader to connect a wallet is asking for one that does not
|
|
51
|
-
* exist for this chain.
|
|
52
|
-
*
|
|
53
|
-
* @param deposit - any origin deposit
|
|
54
|
-
* @returns whether the reader pays this one by hand
|
|
55
|
-
*/
|
|
56
21
|
const isDepositAddressDeposit = (deposit) => 'kind' in deposit && deposit.kind === 'deposit-address';
|
|
57
22
|
exports.isDepositAddressDeposit = isDepositAddressDeposit;
|
|
58
|
-
/**
|
|
59
|
-
* Narrows a deposit to the priced-but-not-reserved shape: a route on display,
|
|
60
|
-
* with nothing to pay until a live quote replaces it.
|
|
61
|
-
*
|
|
62
|
-
* @param deposit - any origin deposit
|
|
63
|
-
* @returns whether the route must be quoted live before anything is paid
|
|
64
|
-
*/
|
|
65
23
|
const isUnreservedDeposit = (deposit) => 'kind' in deposit && deposit.kind === 'unreserved';
|
|
66
24
|
exports.isUnreservedDeposit = isUnreservedDeposit;
|
|
67
|
-
/**
|
|
68
|
-
* Names a deposit's family for a message shown to someone: its ecosystem, or
|
|
69
|
-
* its `kind` for a deposit that has none — a {@link DepositAddressDeposit}
|
|
70
|
-
* reads as `"deposit-address"`, an {@link UnreservedDeposit} as `"unreserved"`.
|
|
71
|
-
*
|
|
72
|
-
* THE ONE COPY. The same `'ecosystem' in deposit ? deposit.ecosystem :
|
|
73
|
-
* deposit.kind` expression used to be written out separately in
|
|
74
|
-
* `consolidated-quote.ts` and in the interface's `consolidated-execute.ts`;
|
|
75
|
-
* each copy was a chance for the two to describe the same deposit
|
|
76
|
-
* differently. Import this instead of restating the expression.
|
|
77
|
-
*
|
|
78
|
-
* @param deposit - any origin deposit
|
|
79
|
-
* @returns the ecosystem name, or the deposit's `kind` when it has none
|
|
80
|
-
*/
|
|
81
25
|
const depositFamilyOf = (deposit) => 'ecosystem' in deposit ? deposit.ecosystem : deposit.kind;
|
|
82
26
|
exports.depositFamilyOf = depositFamilyOf;
|
package/dist/cjs/pre-quote.js
CHANGED
|
@@ -5,49 +5,14 @@ const url_1 = require("@gibs/common/url");
|
|
|
5
5
|
const consolidated_quote_js_1 = require("./consolidated-quote.js");
|
|
6
6
|
const referral_js_1 = require("./referral.js");
|
|
7
7
|
const relay_quote_js_1 = require("./relay-quote.js");
|
|
8
|
-
/**
|
|
9
|
-
* Plain LI.FI swap quote endpoint (forward-solving), re-exported from
|
|
10
|
-
* `consolidated-quote.js` rather than redeclared here — both modules must
|
|
11
|
-
* agree on the same address, and a second literal would be free to drift from
|
|
12
|
-
* it.
|
|
13
|
-
*/
|
|
14
8
|
var consolidated_quote_js_2 = require("./consolidated-quote.js");
|
|
15
9
|
Object.defineProperty(exports, "lifiQuoteUrl", { enumerable: true, get: function () { return consolidated_quote_js_2.lifiQuoteUrl; } });
|
|
16
10
|
Object.defineProperty(exports, "lifiRequestHeaders", { enumerable: true, get: function () { return consolidated_quote_js_2.lifiRequestHeaders; } });
|
|
17
|
-
/**
|
|
18
|
-
* Builds the Relay EXACT_INPUT swap pre-quote body for a fixed input. NO `txs`
|
|
19
|
-
* are attached: Relay solves FORWARD and reports the delivered anchor amount.
|
|
20
|
-
*
|
|
21
|
-
* `recipient` and `refundTo` name TWO DIFFERENT chains and must never be
|
|
22
|
-
* conflated. `refundTo` is always the user's OWN origin-chain address — Relay
|
|
23
|
-
* refunds a failed (or, here, never-run) swap on the origin chain, and an
|
|
24
|
-
* Ethereum fallback address could not receive one there. `recipient` names
|
|
25
|
-
* where the swap lands on the ENTRY chain (`toChainId`), which is always
|
|
26
|
-
* Ethereum Virtual Machine — for an Ethereum origin the user's own address
|
|
27
|
-
* already satisfies that and is the default; for a non-Ethereum origin
|
|
28
|
-
* (Solana base58, Bitcoin bech32, ...) it does NOT, and Relay's `/quote/v2`
|
|
29
|
-
* validates the recipient's FORMAT against `toChainId` even though this
|
|
30
|
-
* pre-quote never executes. Sending the origin account there — as an earlier
|
|
31
|
-
* version of this builder did, reasoning that an unexecuted quote's recipient
|
|
32
|
-
* is "informational" — gets Relay's `400 INVALID_ADDRESS` on every
|
|
33
|
-
* non-Ethereum-origin pre-quote, which starves `fetchBestEntryAnchorPreQuote`
|
|
34
|
-
* of its only capable provider and surfaces as "No route available" for the
|
|
35
|
-
* whole non-Ethereum-origin flow. `request.recipient` (an explicit
|
|
36
|
-
* Ethereum-format address the caller supplies) is therefore REQUIRED for a
|
|
37
|
-
* non-Ethereum origin; without it this returns null.
|
|
38
|
-
*
|
|
39
|
-
* @param request - the provider-agnostic pre-quote request
|
|
40
|
-
* @returns the request body, or null when the input amount is non-positive or
|
|
41
|
-
* a non-Ethereum origin has no explicit Ethereum-format `recipient`
|
|
42
|
-
*/
|
|
43
11
|
const buildRelayPreQuoteRequest = (request) => {
|
|
44
12
|
if (request.amount <= 0n) {
|
|
45
13
|
return null;
|
|
46
14
|
}
|
|
47
15
|
const nonEthereumOrigin = (0, consolidated_quote_js_1.isNonEthereumVirtualMachineOrigin)(request);
|
|
48
|
-
// A non-Ethereum origin's own address cannot stand in for an entry-chain
|
|
49
|
-
// recipient; it must be supplied explicitly. An Ethereum origin's own
|
|
50
|
-
// address already IS a valid entry-chain address, so it remains the default.
|
|
51
16
|
const recipient = nonEthereumOrigin ? request.recipient : (request.recipient ?? request.fromAddress);
|
|
52
17
|
if (recipient === undefined) {
|
|
53
18
|
return null;
|
|
@@ -61,10 +26,6 @@ const buildRelayPreQuoteRequest = (request) => {
|
|
|
61
26
|
amount: request.amount.toString(),
|
|
62
27
|
tradeType: 'EXACT_INPUT',
|
|
63
28
|
recipient,
|
|
64
|
-
// Relay always refunds on the ORIGIN chain, so the origin's own address
|
|
65
|
-
// is the correct refund target regardless of ecosystem — unlike
|
|
66
|
-
// `recipient` above, this one is deliberately NOT Ethereum-format for a
|
|
67
|
-
// non-Ethereum origin.
|
|
68
29
|
refundTo: request.fromAddress,
|
|
69
30
|
...(0, relay_quote_js_1.relayReferrerField)(request),
|
|
70
31
|
...(request.slippage === undefined
|
|
@@ -73,17 +34,6 @@ const buildRelayPreQuoteRequest = (request) => {
|
|
|
73
34
|
};
|
|
74
35
|
};
|
|
75
36
|
exports.buildRelayPreQuoteRequest = buildRelayPreQuoteRequest;
|
|
76
|
-
/**
|
|
77
|
-
* Builds the plain LI.FI swap pre-quote as a query string for `GET /v1/quote`.
|
|
78
|
-
* LI.FI's plain `/quote` is forward-solving by construction (`fromAmount` in,
|
|
79
|
-
* `estimate.toAmount` out), so no trade-type flag is needed.
|
|
80
|
-
*
|
|
81
|
-
* Returns null for a non-Ethereum origin (LI.FI cannot bridge across
|
|
82
|
-
* virtual-machine ecosystems) and for a non-positive input amount.
|
|
83
|
-
*
|
|
84
|
-
* @param request - the provider-agnostic pre-quote request
|
|
85
|
-
* @returns the URL query string (without a leading `?`), or null
|
|
86
|
-
*/
|
|
87
37
|
const buildLifiPreQuoteRequest = (request) => {
|
|
88
38
|
if (request.amount <= 0n) {
|
|
89
39
|
return null;
|
|
@@ -91,9 +41,6 @@ const buildLifiPreQuoteRequest = (request) => {
|
|
|
91
41
|
if ((0, consolidated_quote_js_1.isNonEthereumVirtualMachineOrigin)(request)) {
|
|
92
42
|
return null;
|
|
93
43
|
}
|
|
94
|
-
// Left out or `null` OMITS the query parameter (LI.FI's own schema marks it
|
|
95
|
-
// optional); a string is sent as-is. No package default: attribution is the
|
|
96
|
-
// caller's to choose. See `PreQuoteRequest.lifiIntegrator`'s doc.
|
|
97
44
|
const integrator = (0, referral_js_1.resolveAttribution)(request.lifiIntegrator, undefined);
|
|
98
45
|
return (0, url_1.buildQuery)({
|
|
99
46
|
fromChain: request.fromChainId.toString(),
|
|
@@ -102,7 +49,6 @@ const buildLifiPreQuoteRequest = (request) => {
|
|
|
102
49
|
toToken: request.toTokenAddress,
|
|
103
50
|
fromAmount: request.amount.toString(),
|
|
104
51
|
fromAddress: request.fromAddress,
|
|
105
|
-
// Each optional parameter is left out when it is undefined.
|
|
106
52
|
integrator,
|
|
107
53
|
slippage: request.slippage?.toString(),
|
|
108
54
|
});
|
|
@@ -114,11 +60,6 @@ const asRecord = (value) => {
|
|
|
114
60
|
}
|
|
115
61
|
return value;
|
|
116
62
|
};
|
|
117
|
-
/**
|
|
118
|
-
* Parses a decimal-string amount into a bigint.
|
|
119
|
-
*
|
|
120
|
-
* @returns the bigint value, or null when the input is not a parseable amount
|
|
121
|
-
*/
|
|
122
63
|
const parseAmount = (value) => {
|
|
123
64
|
if (typeof value !== 'string' || value === '') {
|
|
124
65
|
return null;
|
|
@@ -130,13 +71,6 @@ const parseAmount = (value) => {
|
|
|
130
71
|
return null;
|
|
131
72
|
}
|
|
132
73
|
};
|
|
133
|
-
/**
|
|
134
|
-
* Assembles the expected/minimum pair, defaulting the minimum to the expected
|
|
135
|
-
* amount when the provider omits a guaranteed floor. Shared by both parsers so
|
|
136
|
-
* the fallback rule lives in exactly one place.
|
|
137
|
-
*
|
|
138
|
-
* @returns the result, or null when the expected amount is absent
|
|
139
|
-
*/
|
|
140
74
|
const toPreQuoteResult = (expected, minimum) => {
|
|
141
75
|
const expectedAmount = parseAmount(expected);
|
|
142
76
|
if (expectedAmount === null) {
|
|
@@ -148,13 +82,6 @@ const toPreQuoteResult = (expected, minimum) => {
|
|
|
148
82
|
minimumAmount: minimumAmount ?? expectedAmount,
|
|
149
83
|
};
|
|
150
84
|
};
|
|
151
|
-
/**
|
|
152
|
-
* Parses a Relay EXACT_INPUT pre-quote response. The delivered anchor figures
|
|
153
|
-
* live under `details.currencyOut`: `amount` (expected) and `minimumAmount`
|
|
154
|
-
* (guaranteed slippage floor). Verified live against `api.relay.link/quote/v2`.
|
|
155
|
-
*
|
|
156
|
-
* @returns the delivered amounts, or null when the payload shape is unexpected
|
|
157
|
-
*/
|
|
158
85
|
const parseRelayPreQuote = (payload) => {
|
|
159
86
|
const currencyOut = asRecord(asRecord(asRecord(payload)?.details)?.currencyOut);
|
|
160
87
|
if (!currencyOut) {
|
|
@@ -163,13 +90,6 @@ const parseRelayPreQuote = (payload) => {
|
|
|
163
90
|
return toPreQuoteResult(currencyOut.amount, currencyOut.minimumAmount);
|
|
164
91
|
};
|
|
165
92
|
exports.parseRelayPreQuote = parseRelayPreQuote;
|
|
166
|
-
/**
|
|
167
|
-
* Parses a plain LI.FI `/quote` response. The delivered anchor figures live
|
|
168
|
-
* under `estimate`: `toAmount` (expected) and `toAmountMin` (guaranteed minimum
|
|
169
|
-
* after slippage) — the same estimate shape the route-step normalizer reads.
|
|
170
|
-
*
|
|
171
|
-
* @returns the delivered amounts, or null when the payload shape is unexpected
|
|
172
|
-
*/
|
|
173
93
|
const parseLifiPreQuote = (payload) => {
|
|
174
94
|
const estimate = asRecord(asRecord(payload)?.estimate);
|
|
175
95
|
if (!estimate) {
|
package/dist/cjs/prices.js
CHANGED
|
@@ -3,54 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.sameChainWrappedNative = exports.resolveTokenPriceUsd = exports.computeUsdPriceFromAmountsOut = exports.pulsexPricePaths = exports.pulsechainOriginAddress = exports.isPulsechain = exports.lifiPriceKey = exports.lowercaseAddress = exports.WPLS_ADDRESS = exports.PULSECHAIN_USD_ANCHOR_DECIMALS = exports.PULSECHAIN_USD_ANCHOR_ADDRESS = exports.PULSECHAIN_TESTNET_CHAIN_ID = exports.PULSECHAIN_CHAIN_ID = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
5
|
const config_js_1 = require("./config.js");
|
|
6
|
-
/**
|
|
7
|
-
* PulseChain mainnet numeric chain id (`Chains.PLS` = `0x171`). Tokens on this
|
|
8
|
-
* chain (and its testnet sibling below) are priced on-chain via PulseX rather
|
|
9
|
-
* than from an off-chain price feed.
|
|
10
|
-
*/
|
|
11
6
|
exports.PULSECHAIN_CHAIN_ID = Number(config_js_1.Chains.PLS);
|
|
12
|
-
/**
|
|
13
|
-
* PulseChain V4 testnet numeric chain id (`Chains.V4PLS` = `0x3af`). Shares the
|
|
14
|
-
* PulseX on-chain pricing path with mainnet.
|
|
15
|
-
*/
|
|
16
7
|
exports.PULSECHAIN_TESTNET_CHAIN_ID = Number(config_js_1.Chains.V4PLS);
|
|
17
|
-
/**
|
|
18
|
-
* Bridged DAI on PulseChain (18 decimals) — the USD anchor stablecoin for
|
|
19
|
-
* on-chain PulseX pricing. One token's `getAmountsOut` ending in this address
|
|
20
|
-
* yields that token's USD price directly (DAI is treated as exactly $1).
|
|
21
|
-
*
|
|
22
|
-
* Kept as an exported constant so the anchor can be swapped without touching the
|
|
23
|
-
* pricing math. Mirrors `DAI_ADDRESS` in `packages/tx-report/src/server/prices.ts`.
|
|
24
|
-
*/
|
|
25
8
|
exports.PULSECHAIN_USD_ANCHOR_ADDRESS = '0xefd766ccb38eaf1dfd701853bfce31359239f305';
|
|
26
|
-
/** Decimals of the {@link PULSECHAIN_USD_ANCHOR_ADDRESS} stablecoin. */
|
|
27
9
|
exports.PULSECHAIN_USD_ANCHOR_DECIMALS = 18;
|
|
28
|
-
/** Wrapped PLS on PulseChain — the routing intermediary for PulseX paths. */
|
|
29
10
|
exports.WPLS_ADDRESS = config_js_1.nativeAssetOut[config_js_1.Chains.PLS];
|
|
30
|
-
/** The native (gas) token sentinel address used across the dapp. */
|
|
31
11
|
const NATIVE_TOKEN_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
32
|
-
/** Lowercases an address for case-insensitive map keys and comparisons. */
|
|
33
12
|
const lowercaseAddress = (address) => address.toLowerCase();
|
|
34
13
|
exports.lowercaseAddress = lowercaseAddress;
|
|
35
|
-
/** True when two addresses are equal ignoring case (and 0x-checksum casing). */
|
|
36
14
|
const sameAddress = (left, right) => (0, exports.lowercaseAddress)(left) === (0, exports.lowercaseAddress)(right);
|
|
37
|
-
/**
|
|
38
|
-
* Map key for a foreign (LI.FI-priced) token: `${chainId}-${lowercased address}`.
|
|
39
|
-
* Matches the key the UI builds when assembling the LI.FI price map.
|
|
40
|
-
*/
|
|
41
15
|
const lifiPriceKey = (chainId, address) => `${chainId}-${(0, exports.lowercaseAddress)(address)}`;
|
|
42
16
|
exports.lifiPriceKey = lifiPriceKey;
|
|
43
|
-
/** True when a chain id is priced on-chain via PulseX (mainnet or V4 testnet). */
|
|
44
17
|
const isPulsechain = (chainId) => chainId === exports.PULSECHAIN_CHAIN_ID || chainId === exports.PULSECHAIN_TESTNET_CHAIN_ID;
|
|
45
18
|
exports.isPulsechain = isPulsechain;
|
|
46
|
-
/**
|
|
47
|
-
* The PulseChain-origin address a bridged token backs out to, when the token's
|
|
48
|
-
* `extensions.bridgeInfo` records a PulseChain counterpart. Bridged tokens are
|
|
49
|
-
* 1:1 with their origin, so the origin's PulseX price is the token's USD value.
|
|
50
|
-
*
|
|
51
|
-
* @param token - the token whose PulseChain-origin link to resolve
|
|
52
|
-
* @returns the PulseChain origin address, or null when the token has no such link
|
|
53
|
-
*/
|
|
54
19
|
const pulsechainOriginAddress = (token) => {
|
|
55
20
|
const link = token.extensions?.bridgeInfo?.[exports.PULSECHAIN_CHAIN_ID];
|
|
56
21
|
if (!link) {
|
|
@@ -59,22 +24,6 @@ const pulsechainOriginAddress = (token) => {
|
|
|
59
24
|
return link.tokenAddress;
|
|
60
25
|
};
|
|
61
26
|
exports.pulsechainOriginAddress = pulsechainOriginAddress;
|
|
62
|
-
/**
|
|
63
|
-
* The set of PulseX swap paths to price one whole unit of `token` into the USD
|
|
64
|
-
* anchor stablecoin. Edge cases collapse to shorter paths:
|
|
65
|
-
*
|
|
66
|
-
* - `token` is the stablecoin itself -> no swap needed (priced as exactly 1).
|
|
67
|
-
* - `token` is WPLS (or the native zero-address) -> `[WPLS, stable]` only.
|
|
68
|
-
* - otherwise -> both `[token, WPLS, stable]` and `[token, stable]`.
|
|
69
|
-
*
|
|
70
|
-
* Returned addresses are always concrete (the native sentinel is rewritten to
|
|
71
|
-
* WPLS) so they can be fed straight into `getAmountsOut`.
|
|
72
|
-
*
|
|
73
|
-
* @param options.token - the token (only its address is read) to build paths for
|
|
74
|
-
* @param options.wpls - the wrapped-native intermediary (defaults to {@link WPLS_ADDRESS})
|
|
75
|
-
* @param options.stable - the USD anchor (defaults to {@link PULSECHAIN_USD_ANCHOR_ADDRESS})
|
|
76
|
-
* @returns `{ paths }` — the candidate paths; empty when the token is the stablecoin
|
|
77
|
-
*/
|
|
78
27
|
const pulsexPricePaths = ({ token, wpls = exports.WPLS_ADDRESS, stable = exports.PULSECHAIN_USD_ANCHOR_ADDRESS, }) => {
|
|
79
28
|
const address = sameAddress(token.address, NATIVE_TOKEN_ADDRESS) ? wpls : token.address;
|
|
80
29
|
if (sameAddress(address, stable)) {
|
|
@@ -91,11 +40,6 @@ const pulsexPricePaths = ({ token, wpls = exports.WPLS_ADDRESS, stable = exports
|
|
|
91
40
|
};
|
|
92
41
|
};
|
|
93
42
|
exports.pulsexPricePaths = pulsexPricePaths;
|
|
94
|
-
/**
|
|
95
|
-
* The final output amount of one `getAmountsOut` result, or null when the call
|
|
96
|
-
* failed (Hex) or returned an empty array. The last element of a `bigint[]`
|
|
97
|
-
* `getAmountsOut` is the output-token amount.
|
|
98
|
-
*/
|
|
99
43
|
const finalOutput = (result) => {
|
|
100
44
|
if (typeof result === 'string') {
|
|
101
45
|
return null;
|
|
@@ -105,16 +49,6 @@ const finalOutput = (result) => {
|
|
|
105
49
|
}
|
|
106
50
|
return result[result.length - 1];
|
|
107
51
|
};
|
|
108
|
-
/**
|
|
109
|
-
* Reduces every `getAmountsOut` result (across all paths and all routers for one
|
|
110
|
-
* token) to a single USD price by taking the MAX final output, then scaling out
|
|
111
|
-
* of the stablecoin's decimals. Failed/empty results are dropped; when none
|
|
112
|
-
* succeed the price is null (no liquidity).
|
|
113
|
-
*
|
|
114
|
-
* @param options.results - the `getAmountsOut` outcomes for the token's paths/routers
|
|
115
|
-
* @param options.stableDecimals - decimals of the anchor (defaults to {@link PULSECHAIN_USD_ANCHOR_DECIMALS})
|
|
116
|
-
* @returns the USD price as a number, or null when no path produced a value
|
|
117
|
-
*/
|
|
118
52
|
const computeUsdPriceFromAmountsOut = ({ results, stableDecimals = exports.PULSECHAIN_USD_ANCHOR_DECIMALS, }) => {
|
|
119
53
|
const outputs = results.flatMap((result) => {
|
|
120
54
|
const output = finalOutput(result);
|
|
@@ -130,22 +64,6 @@ const computeUsdPriceFromAmountsOut = ({ results, stableDecimals = exports.PULSE
|
|
|
130
64
|
return Number((0, viem_1.formatUnits)(maxOutput, stableDecimals));
|
|
131
65
|
};
|
|
132
66
|
exports.computeUsdPriceFromAmountsOut = computeUsdPriceFromAmountsOut;
|
|
133
|
-
/**
|
|
134
|
-
* Resolves a token's USD price using pre-fetched price maps, following the
|
|
135
|
-
* co-designed precedence:
|
|
136
|
-
*
|
|
137
|
-
* 1. PulseChain (mainnet or V4 testnet): the token's own PulseX price.
|
|
138
|
-
* 2. Bridged PulseChain-origin token: the origin's PulseX price (1:1 value).
|
|
139
|
-
* 3. Genuinely foreign token: the LI.FI inline price.
|
|
140
|
-
*
|
|
141
|
-
* The stablecoin anchor itself resolves to exactly 1. All address lookups are
|
|
142
|
-
* case-insensitive (maps are keyed by lowercased address).
|
|
143
|
-
*
|
|
144
|
-
* @param token - the token to price
|
|
145
|
-
* @param options.pulsexPrices - lowercased PulseChain address -> USD price
|
|
146
|
-
* @param options.lifiPrices - `${chainId}-${lowercased address}` -> USD price
|
|
147
|
-
* @returns the USD price as a number, or null when no source can price it
|
|
148
|
-
*/
|
|
149
67
|
const resolveTokenPriceUsd = (token, { pulsexPrices, lifiPrices, }) => {
|
|
150
68
|
const wrappedNative = (0, exports.sameChainWrappedNative)(token);
|
|
151
69
|
if (wrappedNative !== null) {
|
|
@@ -154,15 +72,6 @@ const resolveTokenPriceUsd = (token, { pulsexPrices, lifiPrices, }) => {
|
|
|
154
72
|
return resolveOwnPriceUsd(token, { pulsexPrices, lifiPrices });
|
|
155
73
|
};
|
|
156
74
|
exports.resolveTokenPriceUsd = resolveTokenPriceUsd;
|
|
157
|
-
/**
|
|
158
|
-
* The chain's canonical wrapped native address when `token` is the native
|
|
159
|
-
* coin (zero address) or that wrapper itself, and null for every other token.
|
|
160
|
-
* Only the SAME chain's pair is returned: a bridged copy of a wrapper on
|
|
161
|
-
* another chain is a different token and keeps its own price.
|
|
162
|
-
*
|
|
163
|
-
* @param token - the token to test
|
|
164
|
-
* @returns the wrapped native address on the token's own chain, or null
|
|
165
|
-
*/
|
|
166
75
|
const sameChainWrappedNative = (token) => {
|
|
167
76
|
const wrapped = config_js_1.nativeAssetOut[(0, config_js_1.toChain)(token.chainId)];
|
|
168
77
|
if (wrapped === undefined) {
|
|
@@ -172,22 +81,6 @@ const sameChainWrappedNative = (token) => {
|
|
|
172
81
|
return isNativeCoin || sameAddress(token.address, wrapped) ? wrapped : null;
|
|
173
82
|
};
|
|
174
83
|
exports.sameChainWrappedNative = sameChainWrappedNative;
|
|
175
|
-
/**
|
|
176
|
-
* One price for a native coin and its canonical wrapper. The contract wraps
|
|
177
|
-
* and unwraps 1:1, so two prices would show a value loss on a wrap step that
|
|
178
|
-
* loses nothing.
|
|
179
|
-
*
|
|
180
|
-
* Off PulseChain the native coin's market feed (LI.FI) wins. The wrapper's
|
|
181
|
-
* own price there is the PulseX price of its bridged copy (it carries a
|
|
182
|
-
* PulseChain origin link), which is a derivative market with its own
|
|
183
|
-
* premium or discount. The coin's feed prices the underlying asset. When the
|
|
184
|
-
* feed has no native price, the wrapper's feed price, then its own resolved
|
|
185
|
-
* price, stand in.
|
|
186
|
-
*
|
|
187
|
-
* On PulseChain both are priced by PulseX through the WPLS path, so the
|
|
188
|
-
* wrapper's entry is used and the coin's entry stands in when the wrapper was
|
|
189
|
-
* not in the priced set.
|
|
190
|
-
*/
|
|
191
84
|
const resolveNativeFamilyPriceUsd = (token, wrappedNative, maps) => {
|
|
192
85
|
const wrapped = { ...token, address: wrappedNative };
|
|
193
86
|
if ((0, exports.isPulsechain)(token.chainId)) {
|
|
@@ -198,7 +91,6 @@ const resolveNativeFamilyPriceUsd = (token, wrappedNative, maps) => {
|
|
|
198
91
|
maps.lifiPrices.get((0, exports.lifiPriceKey)(token.chainId, wrappedNative)) ??
|
|
199
92
|
resolveOwnPriceUsd(wrapped, maps));
|
|
200
93
|
};
|
|
201
|
-
/** The token's price by its own address, with no native-wrapper pairing. */
|
|
202
94
|
const resolveOwnPriceUsd = (token, { pulsexPrices, lifiPrices, }) => {
|
|
203
95
|
if ((0, exports.isPulsechain)(token.chainId)) {
|
|
204
96
|
if (sameAddress(token.address, exports.PULSECHAIN_USD_ANCHOR_ADDRESS)) {
|
|
@@ -211,11 +103,6 @@ const resolveOwnPriceUsd = (token, { pulsexPrices, lifiPrices, }) => {
|
|
|
211
103
|
if (sameAddress(origin, exports.PULSECHAIN_USD_ANCHOR_ADDRESS)) {
|
|
212
104
|
return 1;
|
|
213
105
|
}
|
|
214
|
-
// Prefer the bridged origin's on-chain PulseX price. Fall back to the token's
|
|
215
|
-
// OWN home-chain LI.FI inline price when PulseX cannot price it — a bridged
|
|
216
|
-
// major (e.g. wrapped ether / wrapped binance coin) whose PulseChain pool path
|
|
217
|
-
// returns nothing would otherwise resolve to null despite a well-known market
|
|
218
|
-
// price on its home chain.
|
|
219
106
|
return (pulsexPrices.get((0, exports.lowercaseAddress)(origin)) ??
|
|
220
107
|
lifiPrices.get((0, exports.lifiPriceKey)(token.chainId, token.address)) ??
|
|
221
108
|
null);
|
package/dist/cjs/providers.js
CHANGED
|
@@ -10,11 +10,9 @@ const lifiDescriptor = {
|
|
|
10
10
|
id: 'lifi',
|
|
11
11
|
label: 'LI.FI',
|
|
12
12
|
supportedSourceEcosystems: ['evm'],
|
|
13
|
-
// Its contract-calls endpoint exists to deliver and then call something.
|
|
14
13
|
executesDestinationCalls: true,
|
|
15
14
|
destinationCallOriginChainIds: [Number(config_js_1.Chains.ETH)],
|
|
16
15
|
destinationCallCarriesNativeValue: false,
|
|
17
|
-
// Its quote names the Diamond as `estimate.approvalAddress`.
|
|
18
16
|
originTokenSpend: 'allowance',
|
|
19
17
|
preQuote: {
|
|
20
18
|
method: 'GET',
|
|
@@ -30,15 +28,10 @@ const lifiDescriptor = {
|
|
|
30
28
|
const relayDescriptor = {
|
|
31
29
|
id: 'relay',
|
|
32
30
|
label: 'Relay',
|
|
33
|
-
// Relay carries every origin family the registry models. Listed explicitly
|
|
34
|
-
// rather than derived from the registry so that registering a future
|
|
35
|
-
// ecosystem does not silently claim Relay support the integration lacks.
|
|
36
31
|
supportedSourceEcosystems: ['evm', 'svm', 'bvm', 'tvm', 'tonvm', 'hypevm'],
|
|
37
|
-
// Its solver performs the `txs` attached to a quote on arrival.
|
|
38
32
|
executesDestinationCalls: true,
|
|
39
33
|
destinationCallOriginChainIds: 'any',
|
|
40
34
|
destinationCallCarriesNativeValue: true,
|
|
41
|
-
// Its quote carries an approve step; the parser lifts its spender.
|
|
42
35
|
originTokenSpend: 'allowance',
|
|
43
36
|
preQuote: {
|
|
44
37
|
method: 'POST',
|
|
@@ -54,21 +47,10 @@ const relayDescriptor = {
|
|
|
54
47
|
const nearIntentsDescriptor = {
|
|
55
48
|
id: 'near-intents',
|
|
56
49
|
label: 'NEAR Intents',
|
|
57
|
-
// ETHEREUM ORIGINS, AND THE CHAINS A READER PAYS BY HAND. The service
|
|
58
|
-
// carries Solana, Bitcoin, Tron, The Open Network and more, but it returns a
|
|
59
|
-
// deposit ADDRESS and no transaction. For a wallet-connected origin the
|
|
60
|
-
// transfer that funds a route has to be composed on this side, and only the
|
|
61
|
-
// Ethereum one is composed today (`nearIntentsOriginDeposit`); claiming a
|
|
62
|
-
// family whose transfer nothing here can build would offer a route that
|
|
63
|
-
// dead-ends at the signing step. A pay-by-hand chain needs nothing composed:
|
|
64
|
-
// the address and the amount ARE the deposit (`DepositAddressDeposit`).
|
|
65
50
|
supportedSourceEcosystems: ['evm', 'zcash'],
|
|
66
|
-
// The measured answer, and the reason this provider's routes take two
|
|
67
|
-
// signatures. See the head of `near-intents.ts`.
|
|
68
51
|
executesDestinationCalls: false,
|
|
69
52
|
destinationCallOriginChainIds: [],
|
|
70
53
|
destinationCallCarriesNativeValue: false,
|
|
71
|
-
// The reader sends the token to a deposit address.
|
|
72
54
|
originTokenSpend: 'transfer',
|
|
73
55
|
preQuote: {
|
|
74
56
|
method: 'POST',
|
|
@@ -81,39 +63,14 @@ const nearIntentsDescriptor = {
|
|
|
81
63
|
parse: near_intents_js_1.parseNearIntentsQuote,
|
|
82
64
|
},
|
|
83
65
|
};
|
|
84
|
-
/**
|
|
85
|
-
* Every integrated provider. LI.FI is first: the interface preserves this order
|
|
86
|
-
* in its active lists, and LI.FI-first is the existing tie-break that prefers
|
|
87
|
-
* the verified provider on an equal-cost quote. NEAR Intents is last, so it
|
|
88
|
-
* wins a tie against neither — appropriate for the one provider whose route
|
|
89
|
-
* costs the reader a second signature.
|
|
90
|
-
*/
|
|
91
66
|
exports.providerRegistry = [
|
|
92
67
|
lifiDescriptor,
|
|
93
68
|
relayDescriptor,
|
|
94
69
|
nearIntentsDescriptor,
|
|
95
70
|
];
|
|
96
71
|
const byId = new Map(exports.providerRegistry.map((descriptor) => [descriptor.id, descriptor]));
|
|
97
|
-
/**
|
|
98
|
-
* Looks up a provider descriptor for ANY carrier id, answering null for an id
|
|
99
|
-
* the registry does not hold. The route-search engine carries hops for
|
|
100
|
-
* carriers that are not providers at all (a local wrap, a pool swap, a
|
|
101
|
-
* host's own plug-in), so a caller holding an open carrier id must ask this,
|
|
102
|
-
* never cast the id to {@link ProviderId} and call {@link providerById}, which
|
|
103
|
-
* throws for such an id.
|
|
104
|
-
*
|
|
105
|
-
* @param id - any carrier id
|
|
106
|
-
* @returns the descriptor, or null when no provider is registered under `id`
|
|
107
|
-
*/
|
|
108
72
|
const findProviderById = (id) => byId.get(id) ?? null;
|
|
109
73
|
exports.findProviderById = findProviderById;
|
|
110
|
-
/**
|
|
111
|
-
* Looks up a provider descriptor. Total over the `ProviderId` union; throws only
|
|
112
|
-
* if the registry is left incomplete.
|
|
113
|
-
*
|
|
114
|
-
* @param id - the provider key
|
|
115
|
-
* @returns the descriptor whose `id` equals `id`
|
|
116
|
-
*/
|
|
117
74
|
const providerById = (id) => {
|
|
118
75
|
const descriptor = byId.get(id);
|
|
119
76
|
if (descriptor === undefined) {
|
|
@@ -122,50 +79,10 @@ const providerById = (id) => {
|
|
|
122
79
|
return descriptor;
|
|
123
80
|
};
|
|
124
81
|
exports.providerById = providerById;
|
|
125
|
-
/**
|
|
126
|
-
* The providers that can originate a route from `ecosystem`, in registry order.
|
|
127
|
-
* This is the data that used to be the hand-written capability conditional.
|
|
128
|
-
*
|
|
129
|
-
* @param ecosystem - the source ecosystem
|
|
130
|
-
* @returns the descriptors whose `supportedSourceEcosystems` include `ecosystem`
|
|
131
|
-
*/
|
|
132
82
|
const providersForOrigin = (ecosystem) => exports.providerRegistry.filter((descriptor) => descriptor.supportedSourceEcosystems.includes(ecosystem));
|
|
133
83
|
exports.providersForOrigin = providersForOrigin;
|
|
134
|
-
/**
|
|
135
|
-
* The providers that may bid in the entry-anchor pre-quote for an origin.
|
|
136
|
-
*
|
|
137
|
-
* A STRICTER LIST THAN {@link providersForOrigin}, AND THE DIFFERENCE IS NOT
|
|
138
|
-
* COSMETIC. The pre-quote exists for one purpose: to learn, for the reader's
|
|
139
|
-
* fixed input, how much anchor an entry really delivers, so that figure can
|
|
140
|
-
* become the exact-output target of the execution quote. The winner is whoever
|
|
141
|
-
* delivers MOST.
|
|
142
|
-
*
|
|
143
|
-
* A provider that cannot execute the entry call can still win that comparison —
|
|
144
|
-
* it has one less thing to pay for. Its number then becomes a target handed to
|
|
145
|
-
* the providers that must actually fill it, and they cannot, so the whole entry
|
|
146
|
-
* produces no route. The failure is silent and looks like an absent quote.
|
|
147
|
-
*
|
|
148
|
-
* So the pre-quote is restricted to providers that execute. This is not a
|
|
149
|
-
* judgement about quality; it is that a pre-quote and an execution quote have
|
|
150
|
-
* to be answerable by the same provider for the handoff between them to mean
|
|
151
|
-
* anything.
|
|
152
|
-
*
|
|
153
|
-
* @param ecosystem - the source ecosystem
|
|
154
|
-
* @returns the descriptors that may pre-quote this origin, in registry order
|
|
155
|
-
*/
|
|
156
84
|
const preQuoteProvidersForOrigin = (ecosystem) => (0, exports.providersForOrigin)(ecosystem).filter((descriptor) => descriptor.executesDestinationCalls);
|
|
157
85
|
exports.preQuoteProvidersForOrigin = preQuoteProvidersForOrigin;
|
|
158
|
-
// A request with no origin family is the existing-caller shape and is treated as
|
|
159
|
-
// Ethereum, preserving the original single-ecosystem default.
|
|
160
86
|
const ecosystemOf = (request) => request.originVmType ?? 'evm';
|
|
161
|
-
/**
|
|
162
|
-
* Whether a provider can quote a request's origin ecosystem, derived from the
|
|
163
|
-
* registry. Equivalent to `providersForOrigin(...).some(...)`, kept as a named
|
|
164
|
-
* predicate for the call sites that ask about one provider at a time.
|
|
165
|
-
*
|
|
166
|
-
* @param provider - the aggregator under consideration
|
|
167
|
-
* @param request - the request whose origin is being checked
|
|
168
|
-
* @returns true when the provider supports the request's origin ecosystem
|
|
169
|
-
*/
|
|
170
87
|
const providerSupportsOrigin = (provider, request) => (0, exports.providerById)(provider).supportedSourceEcosystems.includes(ecosystemOf(request));
|
|
171
88
|
exports.providerSupportsOrigin = providerSupportsOrigin;
|