@gibs/bridge-sdk 1.13.0 → 1.17.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 +244 -18
- package/abis/package.json +6 -0
- package/bridge-limits/package.json +6 -0
- package/chain-info/package.json +6 -0
- package/chain-names/package.json +6 -0
- package/chains/package.json +6 -0
- package/claims/package.json +6 -0
- package/config/package.json +6 -0
- package/consolidated-quote/package.json +6 -0
- package/destination-calldata/package.json +6 -0
- package/dist/chain-info.d.ts +1 -1
- package/dist/chain-info.js +11 -12
- package/dist/chains.d.ts +25 -0
- package/dist/chains.js +55 -20
- package/dist/cjs/abis.d.ts +1 -0
- package/dist/cjs/abis.js +19 -0
- package/dist/cjs/bridge-limits.d.ts +103 -0
- package/dist/cjs/bridge-limits.js +89 -0
- package/dist/cjs/chain-info.d.ts +169 -0
- package/dist/cjs/chain-info.js +452 -0
- package/dist/cjs/chain-names.d.ts +160 -0
- package/dist/cjs/chain-names.js +207 -0
- package/dist/cjs/chains.d.ts +90 -0
- package/dist/cjs/chains.js +357 -0
- package/dist/cjs/claims.d.ts +198 -0
- package/dist/cjs/claims.js +182 -0
- package/dist/cjs/config.d.ts +240 -0
- package/dist/cjs/config.js +537 -0
- package/dist/cjs/consolidated-quote.d.ts +648 -0
- package/dist/cjs/consolidated-quote.js +1048 -0
- package/dist/cjs/destination-calldata.d.ts +118 -0
- package/dist/cjs/destination-calldata.js +156 -0
- package/dist/cjs/ecosystems.d.ts +217 -0
- package/dist/cjs/ecosystems.js +298 -0
- package/dist/cjs/execution.d.ts +346 -0
- package/dist/cjs/execution.js +468 -0
- package/dist/cjs/fee-type.d.ts +10 -0
- package/dist/cjs/fee-type.js +10 -0
- package/dist/cjs/hyperliquid-execution.d.ts +152 -0
- package/dist/cjs/hyperliquid-execution.js +175 -0
- package/dist/cjs/image-links.d.ts +117 -0
- package/dist/cjs/image-links.js +153 -0
- package/dist/cjs/index.d.ts +23 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/lifi-execution-guard.d.ts +210 -0
- package/dist/cjs/lifi-execution-guard.js +409 -0
- package/dist/cjs/near-intents-conformance.d.ts +85 -0
- package/dist/cjs/near-intents-conformance.js +337 -0
- package/dist/cjs/near-intents-route.d.ts +47 -0
- package/dist/cjs/near-intents-route.js +303 -0
- package/dist/cjs/near-intents.d.ts +524 -0
- package/dist/cjs/near-intents.js +1071 -0
- package/dist/cjs/origin-deposit.d.ts +326 -0
- package/dist/cjs/origin-deposit.js +82 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pre-quote.d.ts +198 -0
- package/dist/cjs/pre-quote.js +180 -0
- package/dist/cjs/prices.d.ts +107 -0
- package/dist/cjs/prices.js +172 -0
- package/dist/cjs/providers.d.ts +238 -0
- package/dist/cjs/providers.js +171 -0
- package/dist/cjs/quote-fees.d.ts +102 -0
- package/dist/cjs/quote-fees.js +201 -0
- package/dist/cjs/referral.d.ts +85 -0
- package/dist/cjs/referral.js +85 -0
- package/dist/cjs/relay-currencies.d.ts +47 -0
- package/dist/cjs/relay-currencies.js +95 -0
- package/dist/cjs/relay-depository.d.ts +2 -0
- package/dist/cjs/relay-depository.js +85 -0
- package/dist/cjs/relay-quote.d.ts +301 -0
- package/dist/cjs/relay-quote.js +996 -0
- package/dist/cjs/route-steps.d.ts +138 -0
- package/dist/cjs/route-steps.js +310 -0
- package/dist/cjs/routing/amounts.d.ts +80 -0
- package/dist/cjs/routing/amounts.js +126 -0
- package/dist/cjs/routing/candidate-route.d.ts +43 -0
- package/dist/cjs/routing/candidate-route.js +50 -0
- package/dist/cjs/routing/candidate.d.ts +237 -0
- package/dist/cjs/routing/candidate.js +100 -0
- package/dist/cjs/routing/carriers/ask-answer.d.ts +77 -0
- package/dist/cjs/routing/carriers/ask-answer.js +2 -0
- package/dist/cjs/routing/carriers/omnibridge.d.ts +137 -0
- package/dist/cjs/routing/carriers/omnibridge.js +459 -0
- package/dist/cjs/routing/carriers/pulsex-paths.d.ts +80 -0
- package/dist/cjs/routing/carriers/pulsex-paths.js +97 -0
- package/dist/cjs/routing/carriers/pulsex-split.d.ts +175 -0
- package/dist/cjs/routing/carriers/pulsex-split.js +193 -0
- package/dist/cjs/routing/carriers/pulsex.d.ts +159 -0
- package/dist/cjs/routing/carriers/pulsex.js +565 -0
- package/dist/cjs/routing/carriers/wrap.d.ts +25 -0
- package/dist/cjs/routing/carriers/wrap.js +119 -0
- package/dist/cjs/routing/composed-route-quality.d.ts +125 -0
- package/dist/cjs/routing/composed-route-quality.js +144 -0
- package/dist/cjs/routing/entry-chain-anchor.d.ts +88 -0
- package/dist/cjs/routing/entry-chain-anchor.js +59 -0
- package/dist/cjs/routing/format.d.ts +31 -0
- package/dist/cjs/routing/format.js +64 -0
- package/dist/cjs/routing/index.d.ts +38 -0
- package/dist/cjs/routing/index.js +134 -0
- package/dist/cjs/routing/producers.d.ts +770 -0
- package/dist/cjs/routing/producers.js +1617 -0
- package/dist/cjs/routing/providers.d.ts +31 -0
- package/dist/cjs/routing/providers.js +48 -0
- package/dist/cjs/routing/route-data.d.ts +355 -0
- package/dist/cjs/routing/route-data.js +2 -0
- package/dist/cjs/routing/search/compose.d.ts +168 -0
- package/dist/cjs/routing/search/compose.js +104 -0
- package/dist/cjs/routing/search/graph.d.ts +668 -0
- package/dist/cjs/routing/search/graph.js +461 -0
- package/dist/cjs/routing/search/plan-route-data.d.ts +269 -0
- package/dist/cjs/routing/search/plan-route-data.js +848 -0
- package/dist/cjs/routing/search/score.d.ts +356 -0
- package/dist/cjs/routing/search/score.js +445 -0
- package/dist/cjs/routing/swap-transactions.d.ts +91 -0
- package/dist/cjs/routing/swap-transactions.js +131 -0
- package/dist/cjs/routing/usd-value.d.ts +17 -0
- package/dist/cjs/routing/usd-value.js +29 -0
- package/dist/cjs/settings.d.ts +785 -0
- package/dist/cjs/settings.js +1074 -0
- package/dist/cjs/ton-connect.d.ts +98 -0
- package/dist/cjs/ton-connect.js +206 -0
- package/dist/cjs/ton-execution.d.ts +7 -0
- package/dist/cjs/ton-execution.js +23 -0
- package/dist/cjs/ton.d.ts +37 -0
- package/dist/cjs/ton.js +83 -0
- package/dist/cjs/tron-execution.d.ts +146 -0
- package/dist/cjs/tron-execution.js +248 -0
- package/dist/cjs/types.d.ts +51 -0
- package/dist/cjs/types.js +2 -0
- package/dist/claims.d.ts +198 -0
- package/dist/claims.js +140 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +39 -5
- package/dist/consolidated-quote.d.ts +109 -15
- package/dist/consolidated-quote.js +310 -52
- package/dist/execution.d.ts +346 -0
- package/dist/execution.js +428 -0
- package/dist/hyperliquid-execution.js +2 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/lifi-execution-guard.d.ts +13 -2
- package/dist/lifi-execution-guard.js +4 -0
- package/dist/near-intents.js +2 -3
- package/dist/pre-quote.d.ts +6 -6
- package/dist/pre-quote.js +10 -14
- package/dist/providers.d.ts +17 -0
- package/dist/providers.js +6 -0
- package/dist/referral.d.ts +12 -4
- package/dist/referral.js +12 -4
- package/dist/relay-depository.d.ts +2 -0
- package/dist/relay-depository.js +82 -0
- package/dist/relay-quote.js +2 -3
- package/dist/routing/candidate.d.ts +3 -3
- package/dist/routing/candidate.js +3 -3
- package/dist/routing/carriers/ask-answer.d.ts +19 -0
- package/dist/routing/carriers/omnibridge.js +23 -21
- package/dist/routing/carriers/pulsex-paths.d.ts +80 -0
- package/dist/routing/carriers/pulsex-paths.js +92 -0
- package/dist/routing/carriers/pulsex-split.d.ts +175 -0
- package/dist/routing/carriers/pulsex-split.js +185 -0
- package/dist/routing/carriers/pulsex.d.ts +69 -21
- package/dist/routing/carriers/pulsex.js +184 -65
- package/dist/routing/composed-route-quality.d.ts +28 -6
- package/dist/routing/composed-route-quality.js +36 -5
- package/dist/routing/entry-chain-anchor.d.ts +1 -1
- package/dist/routing/entry-chain-anchor.js +1 -1
- package/dist/routing/index.d.ts +7 -3
- package/dist/routing/index.js +7 -3
- package/dist/routing/producers.js +1 -1
- package/dist/routing/providers.d.ts +5 -0
- package/dist/routing/providers.js +5 -0
- package/dist/routing/search/graph.d.ts +29 -0
- package/dist/routing/search/plan-route-data.d.ts +25 -0
- package/dist/routing/search/plan-route-data.js +43 -7
- package/dist/routing/search/score.d.ts +33 -1
- package/dist/routing/search/score.js +41 -6
- package/dist/routing/swap-transactions.d.ts +91 -0
- package/dist/routing/swap-transactions.js +125 -0
- package/dist/settings.d.ts +94 -1
- package/dist/settings.js +95 -3
- package/dist/ton-connect.d.ts +98 -0
- package/dist/ton-connect.js +200 -0
- package/dist/ton-execution.d.ts +4 -114
- package/dist/ton-execution.js +4 -244
- package/dist/ton.d.ts +37 -0
- package/dist/ton.js +65 -0
- package/docs/examples/example-a-ether-to-pulse.ts +300 -0
- package/docs/examples/example-b-token-pulsechain-to-ethereum.ts +270 -0
- package/docs/examples/shared.ts +261 -0
- package/docs/examples/tsconfig.json +18 -0
- package/docs/integration-guide.md +617 -0
- package/ecosystems/package.json +6 -0
- package/execution/package.json +6 -0
- package/fee-type/package.json +6 -0
- package/hyperliquid-execution/package.json +6 -0
- package/image-links/package.json +6 -0
- package/lifi-execution-guard/package.json +6 -0
- package/llms.txt +234 -0
- package/near-intents/package.json +6 -0
- package/near-intents-route/package.json +6 -0
- package/origin-deposit/package.json +6 -0
- package/package.json +818 -10
- package/pre-quote/package.json +6 -0
- package/prices/package.json +6 -0
- package/providers/package.json +6 -0
- package/quote-fees/package.json +6 -0
- package/referral/package.json +6 -0
- package/relay-currencies/package.json +6 -0
- package/relay-quote/package.json +6 -0
- package/route-steps/package.json +6 -0
- package/routing/package.json +6 -0
- package/settings/package.json +6 -0
- package/ton/package.json +6 -0
- package/ton-connect/package.json +6 -0
- package/ton-execution/package.json +6 -0
- package/tron-execution/package.json +6 -0
- package/types/package.json +6 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseLifiPreQuote = exports.parseRelayPreQuote = exports.buildLifiPreQuoteRequest = exports.buildRelayPreQuoteRequest = exports.lifiRequestHeaders = exports.lifiQuoteUrl = void 0;
|
|
4
|
+
const url_1 = require("@gibs/common/url");
|
|
5
|
+
const consolidated_quote_js_1 = require("./consolidated-quote.js");
|
|
6
|
+
const referral_js_1 = require("./referral.js");
|
|
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
|
+
var consolidated_quote_js_2 = require("./consolidated-quote.js");
|
|
15
|
+
Object.defineProperty(exports, "lifiQuoteUrl", { enumerable: true, get: function () { return consolidated_quote_js_2.lifiQuoteUrl; } });
|
|
16
|
+
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
|
+
const buildRelayPreQuoteRequest = (request) => {
|
|
44
|
+
if (request.amount <= 0n) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
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
|
+
const recipient = nonEthereumOrigin ? request.recipient : (request.recipient ?? request.fromAddress);
|
|
52
|
+
if (recipient === undefined) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
user: request.fromAddress,
|
|
57
|
+
originChainId: request.fromChainId,
|
|
58
|
+
originCurrency: request.fromTokenAddress,
|
|
59
|
+
destinationChainId: request.toChainId,
|
|
60
|
+
destinationCurrency: request.toTokenAddress,
|
|
61
|
+
amount: request.amount.toString(),
|
|
62
|
+
tradeType: 'EXACT_INPUT',
|
|
63
|
+
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
|
+
refundTo: request.fromAddress,
|
|
69
|
+
...(0, relay_quote_js_1.relayReferrerField)(request),
|
|
70
|
+
...(request.slippage === undefined
|
|
71
|
+
? {}
|
|
72
|
+
: { slippageTolerance: (0, relay_quote_js_1.slippageToBasisPoints)(request.slippage) }),
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
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
|
+
const buildLifiPreQuoteRequest = (request) => {
|
|
88
|
+
if (request.amount <= 0n) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
if ((0, consolidated_quote_js_1.isNonEthereumVirtualMachineOrigin)(request)) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
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
|
+
const integrator = (0, referral_js_1.resolveAttribution)(request.lifiIntegrator, undefined);
|
|
98
|
+
return (0, url_1.buildQuery)({
|
|
99
|
+
fromChain: request.fromChainId.toString(),
|
|
100
|
+
toChain: request.toChainId.toString(),
|
|
101
|
+
fromToken: request.fromTokenAddress,
|
|
102
|
+
toToken: request.toTokenAddress,
|
|
103
|
+
fromAmount: request.amount.toString(),
|
|
104
|
+
fromAddress: request.fromAddress,
|
|
105
|
+
// Each optional parameter is left out when it is undefined.
|
|
106
|
+
integrator,
|
|
107
|
+
slippage: request.slippage?.toString(),
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
exports.buildLifiPreQuoteRequest = buildLifiPreQuoteRequest;
|
|
111
|
+
const asRecord = (value) => {
|
|
112
|
+
if (typeof value !== 'object' || value === null) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return value;
|
|
116
|
+
};
|
|
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
|
+
const parseAmount = (value) => {
|
|
123
|
+
if (typeof value !== 'string' || value === '') {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return BigInt(value);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
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
|
+
const toPreQuoteResult = (expected, minimum) => {
|
|
141
|
+
const expectedAmount = parseAmount(expected);
|
|
142
|
+
if (expectedAmount === null) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
const minimumAmount = parseAmount(minimum);
|
|
146
|
+
return {
|
|
147
|
+
expectedAmount,
|
|
148
|
+
minimumAmount: minimumAmount ?? expectedAmount,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
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
|
+
const parseRelayPreQuote = (payload) => {
|
|
159
|
+
const currencyOut = asRecord(asRecord(asRecord(payload)?.details)?.currencyOut);
|
|
160
|
+
if (!currencyOut) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
return toPreQuoteResult(currencyOut.amount, currencyOut.minimumAmount);
|
|
164
|
+
};
|
|
165
|
+
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
|
+
const parseLifiPreQuote = (payload) => {
|
|
174
|
+
const estimate = asRecord(asRecord(payload)?.estimate);
|
|
175
|
+
if (!estimate) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
return toPreQuoteResult(estimate.toAmount, estimate.toAmountMin);
|
|
179
|
+
};
|
|
180
|
+
exports.parseLifiPreQuote = parseLifiPreQuote;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { type Hex } from 'viem';
|
|
2
|
+
import type { Token } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* PulseChain mainnet numeric chain id (`Chains.PLS` = `0x171`). Tokens on this
|
|
5
|
+
* chain (and its testnet sibling below) are priced on-chain via PulseX rather
|
|
6
|
+
* than from an off-chain price feed.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PULSECHAIN_CHAIN_ID: number;
|
|
9
|
+
/**
|
|
10
|
+
* PulseChain V4 testnet numeric chain id (`Chains.V4PLS` = `0x3af`). Shares the
|
|
11
|
+
* PulseX on-chain pricing path with mainnet.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PULSECHAIN_TESTNET_CHAIN_ID: number;
|
|
14
|
+
/**
|
|
15
|
+
* Bridged DAI on PulseChain (18 decimals) — the USD anchor stablecoin for
|
|
16
|
+
* on-chain PulseX pricing. One token's `getAmountsOut` ending in this address
|
|
17
|
+
* yields that token's USD price directly (DAI is treated as exactly $1).
|
|
18
|
+
*
|
|
19
|
+
* Kept as an exported constant so the anchor can be swapped without touching the
|
|
20
|
+
* pricing math. Mirrors `DAI_ADDRESS` in `packages/tx-report/src/server/prices.ts`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const PULSECHAIN_USD_ANCHOR_ADDRESS: Hex;
|
|
23
|
+
/** Decimals of the {@link PULSECHAIN_USD_ANCHOR_ADDRESS} stablecoin. */
|
|
24
|
+
export declare const PULSECHAIN_USD_ANCHOR_DECIMALS = 18;
|
|
25
|
+
/** Wrapped PLS on PulseChain — the routing intermediary for PulseX paths. */
|
|
26
|
+
export declare const WPLS_ADDRESS: `0x${string}`;
|
|
27
|
+
/** Lowercases an address for case-insensitive map keys and comparisons. */
|
|
28
|
+
export declare const lowercaseAddress: (address: string) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Map key for a foreign (LI.FI-priced) token: `${chainId}-${lowercased address}`.
|
|
31
|
+
* Matches the key the UI builds when assembling the LI.FI price map.
|
|
32
|
+
*/
|
|
33
|
+
export declare const lifiPriceKey: (chainId: number, address: string) => string;
|
|
34
|
+
/** True when a chain id is priced on-chain via PulseX (mainnet or V4 testnet). */
|
|
35
|
+
export declare const isPulsechain: (chainId: number) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The PulseChain-origin address a bridged token backs out to, when the token's
|
|
38
|
+
* `extensions.bridgeInfo` records a PulseChain counterpart. Bridged tokens are
|
|
39
|
+
* 1:1 with their origin, so the origin's PulseX price is the token's USD value.
|
|
40
|
+
*
|
|
41
|
+
* @param token - the token whose PulseChain-origin link to resolve
|
|
42
|
+
* @returns the PulseChain origin address, or null when the token has no such link
|
|
43
|
+
*/
|
|
44
|
+
export declare const pulsechainOriginAddress: (token: Token) => Hex | null;
|
|
45
|
+
/**
|
|
46
|
+
* The set of PulseX swap paths to price one whole unit of `token` into the USD
|
|
47
|
+
* anchor stablecoin. Edge cases collapse to shorter paths:
|
|
48
|
+
*
|
|
49
|
+
* - `token` is the stablecoin itself -> no swap needed (priced as exactly 1).
|
|
50
|
+
* - `token` is WPLS (or the native zero-address) -> `[WPLS, stable]` only.
|
|
51
|
+
* - otherwise -> both `[token, WPLS, stable]` and `[token, stable]`.
|
|
52
|
+
*
|
|
53
|
+
* Returned addresses are always concrete (the native sentinel is rewritten to
|
|
54
|
+
* WPLS) so they can be fed straight into `getAmountsOut`.
|
|
55
|
+
*
|
|
56
|
+
* @param options.token - the token (only its address is read) to build paths for
|
|
57
|
+
* @param options.wpls - the wrapped-native intermediary (defaults to {@link WPLS_ADDRESS})
|
|
58
|
+
* @param options.stable - the USD anchor (defaults to {@link PULSECHAIN_USD_ANCHOR_ADDRESS})
|
|
59
|
+
* @returns `{ paths }` — the candidate paths; empty when the token is the stablecoin
|
|
60
|
+
*/
|
|
61
|
+
export declare const pulsexPricePaths: ({ token, wpls, stable, }: {
|
|
62
|
+
token: Pick<Token, "address">;
|
|
63
|
+
wpls?: Hex;
|
|
64
|
+
stable?: Hex;
|
|
65
|
+
}) => {
|
|
66
|
+
paths: Hex[][];
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* A single `getAmountsOut` outcome: the decoded `bigint[]` on success, or raw
|
|
70
|
+
* `Hex` return data when the (allowFailure) call reverted. Mirrors the
|
|
71
|
+
* `multicallRead` return shape so results can be passed in untransformed.
|
|
72
|
+
*/
|
|
73
|
+
export type AmountsOutResult = bigint[] | Hex;
|
|
74
|
+
/**
|
|
75
|
+
* Reduces every `getAmountsOut` result (across all paths and all routers for one
|
|
76
|
+
* token) to a single USD price by taking the MAX final output, then scaling out
|
|
77
|
+
* of the stablecoin's decimals. Failed/empty results are dropped; when none
|
|
78
|
+
* succeed the price is null (no liquidity).
|
|
79
|
+
*
|
|
80
|
+
* @param options.results - the `getAmountsOut` outcomes for the token's paths/routers
|
|
81
|
+
* @param options.stableDecimals - decimals of the anchor (defaults to {@link PULSECHAIN_USD_ANCHOR_DECIMALS})
|
|
82
|
+
* @returns the USD price as a number, or null when no path produced a value
|
|
83
|
+
*/
|
|
84
|
+
export declare const computeUsdPriceFromAmountsOut: ({ results, stableDecimals, }: {
|
|
85
|
+
results: readonly AmountsOutResult[];
|
|
86
|
+
stableDecimals?: number;
|
|
87
|
+
}) => number | null;
|
|
88
|
+
/**
|
|
89
|
+
* Resolves a token's USD price using pre-fetched price maps, following the
|
|
90
|
+
* co-designed precedence:
|
|
91
|
+
*
|
|
92
|
+
* 1. PulseChain (mainnet or V4 testnet): the token's own PulseX price.
|
|
93
|
+
* 2. Bridged PulseChain-origin token: the origin's PulseX price (1:1 value).
|
|
94
|
+
* 3. Genuinely foreign token: the LI.FI inline price.
|
|
95
|
+
*
|
|
96
|
+
* The stablecoin anchor itself resolves to exactly 1. All address lookups are
|
|
97
|
+
* case-insensitive (maps are keyed by lowercased address).
|
|
98
|
+
*
|
|
99
|
+
* @param token - the token to price
|
|
100
|
+
* @param options.pulsexPrices - lowercased PulseChain address -> USD price
|
|
101
|
+
* @param options.lifiPrices - `${chainId}-${lowercased address}` -> USD price
|
|
102
|
+
* @returns the USD price as a number, or null when no source can price it
|
|
103
|
+
*/
|
|
104
|
+
export declare const resolveTokenPriceUsd: (token: Token, { pulsexPrices, lifiPrices, }: {
|
|
105
|
+
pulsexPrices: Map<string, number>;
|
|
106
|
+
lifiPrices: Map<string, number>;
|
|
107
|
+
}) => number | null;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
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
|
+
const viem_1 = require("viem");
|
|
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
|
+
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
|
+
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
|
+
exports.PULSECHAIN_USD_ANCHOR_ADDRESS = '0xefd766ccb38eaf1dfd701853bfce31359239f305';
|
|
26
|
+
/** Decimals of the {@link PULSECHAIN_USD_ANCHOR_ADDRESS} stablecoin. */
|
|
27
|
+
exports.PULSECHAIN_USD_ANCHOR_DECIMALS = 18;
|
|
28
|
+
/** Wrapped PLS on PulseChain — the routing intermediary for PulseX paths. */
|
|
29
|
+
exports.WPLS_ADDRESS = config_js_1.nativeAssetOut[config_js_1.Chains.PLS];
|
|
30
|
+
/** The native (gas) token sentinel address used across the dapp. */
|
|
31
|
+
const NATIVE_TOKEN_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
32
|
+
/** Lowercases an address for case-insensitive map keys and comparisons. */
|
|
33
|
+
const lowercaseAddress = (address) => address.toLowerCase();
|
|
34
|
+
exports.lowercaseAddress = lowercaseAddress;
|
|
35
|
+
/** True when two addresses are equal ignoring case (and 0x-checksum casing). */
|
|
36
|
+
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
|
+
const lifiPriceKey = (chainId, address) => `${chainId}-${(0, exports.lowercaseAddress)(address)}`;
|
|
42
|
+
exports.lifiPriceKey = lifiPriceKey;
|
|
43
|
+
/** True when a chain id is priced on-chain via PulseX (mainnet or V4 testnet). */
|
|
44
|
+
const isPulsechain = (chainId) => chainId === exports.PULSECHAIN_CHAIN_ID || chainId === exports.PULSECHAIN_TESTNET_CHAIN_ID;
|
|
45
|
+
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
|
+
const pulsechainOriginAddress = (token) => {
|
|
55
|
+
const link = token.extensions?.bridgeInfo?.[exports.PULSECHAIN_CHAIN_ID];
|
|
56
|
+
if (!link) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return link.tokenAddress;
|
|
60
|
+
};
|
|
61
|
+
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
|
+
const pulsexPricePaths = ({ token, wpls = exports.WPLS_ADDRESS, stable = exports.PULSECHAIN_USD_ANCHOR_ADDRESS, }) => {
|
|
79
|
+
const address = sameAddress(token.address, NATIVE_TOKEN_ADDRESS) ? wpls : token.address;
|
|
80
|
+
if (sameAddress(address, stable)) {
|
|
81
|
+
return { paths: [] };
|
|
82
|
+
}
|
|
83
|
+
if (sameAddress(address, wpls)) {
|
|
84
|
+
return { paths: [[wpls, stable]] };
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
paths: [
|
|
88
|
+
[address, wpls, stable],
|
|
89
|
+
[address, stable],
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
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
|
+
const finalOutput = (result) => {
|
|
100
|
+
if (typeof result === 'string') {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (result.length === 0) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return result[result.length - 1];
|
|
107
|
+
};
|
|
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
|
+
const computeUsdPriceFromAmountsOut = ({ results, stableDecimals = exports.PULSECHAIN_USD_ANCHOR_DECIMALS, }) => {
|
|
119
|
+
const outputs = results.flatMap((result) => {
|
|
120
|
+
const output = finalOutput(result);
|
|
121
|
+
return output === null ? [] : [output];
|
|
122
|
+
});
|
|
123
|
+
if (outputs.length === 0) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const maxOutput = outputs.reduce((max, current) => (current > max ? current : max), 0n);
|
|
127
|
+
if (maxOutput === 0n) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return Number((0, viem_1.formatUnits)(maxOutput, stableDecimals));
|
|
131
|
+
};
|
|
132
|
+
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
|
+
const resolveTokenPriceUsd = (token, { pulsexPrices, lifiPrices, }) => {
|
|
150
|
+
if ((0, exports.isPulsechain)(token.chainId)) {
|
|
151
|
+
if (sameAddress(token.address, exports.PULSECHAIN_USD_ANCHOR_ADDRESS)) {
|
|
152
|
+
return 1;
|
|
153
|
+
}
|
|
154
|
+
return pulsexPrices.get((0, exports.lowercaseAddress)(token.address)) ?? null;
|
|
155
|
+
}
|
|
156
|
+
const origin = (0, exports.pulsechainOriginAddress)(token);
|
|
157
|
+
if (origin) {
|
|
158
|
+
if (sameAddress(origin, exports.PULSECHAIN_USD_ANCHOR_ADDRESS)) {
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
// Prefer the bridged origin's on-chain PulseX price. Fall back to the token's
|
|
162
|
+
// OWN home-chain LI.FI inline price when PulseX cannot price it — a bridged
|
|
163
|
+
// major (e.g. wrapped ether / wrapped binance coin) whose PulseChain pool path
|
|
164
|
+
// returns nothing would otherwise resolve to null despite a well-known market
|
|
165
|
+
// price on its home chain.
|
|
166
|
+
return (pulsexPrices.get((0, exports.lowercaseAddress)(origin)) ??
|
|
167
|
+
lifiPrices.get((0, exports.lifiPriceKey)(token.chainId, token.address)) ??
|
|
168
|
+
null);
|
|
169
|
+
}
|
|
170
|
+
return lifiPrices.get((0, exports.lifiPriceKey)(token.chainId, token.address)) ?? null;
|
|
171
|
+
};
|
|
172
|
+
exports.resolveTokenPriceUsd = resolveTokenPriceUsd;
|