@hyperbridge/sdk 2.8.17 → 2.8.18
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/dist/browser/index.d.ts +12 -21
- package/dist/browser/index.js +11 -25
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +10 -25
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +12 -21
- package/dist/node/index.d.ts +12 -21
- package/dist/node/index.js +11 -25
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -18961,18 +18961,6 @@ var OrderbookQuoteNotConvergedError = class extends Error {
|
|
|
18961
18961
|
rounds;
|
|
18962
18962
|
lastAmountIn;
|
|
18963
18963
|
};
|
|
18964
|
-
var InsufficientOrderbookLiquidityError = class extends Error {
|
|
18965
|
-
constructor(route, maxFillableIn) {
|
|
18966
|
-
super(
|
|
18967
|
-
`The HyperFX orderbook cannot fill ${route.tokenIn} -> ${route.tokenOut} on ${route.sourceChain} -> ${route.destinationChain}; max fillable input is ${maxFillableIn} raw units`
|
|
18968
|
-
);
|
|
18969
|
-
this.route = route;
|
|
18970
|
-
this.maxFillableIn = maxFillableIn;
|
|
18971
|
-
this.name = "InsufficientOrderbookLiquidityError";
|
|
18972
|
-
}
|
|
18973
|
-
route;
|
|
18974
|
-
maxFillableIn;
|
|
18975
|
-
};
|
|
18976
18964
|
|
|
18977
18965
|
// src/protocols/intents/orderbook/market.ts
|
|
18978
18966
|
var MAX_EXACT_OUTPUT_ROUNDS = 16;
|
|
@@ -19028,8 +19016,9 @@ var OrderbookMarket = class {
|
|
|
19028
19016
|
};
|
|
19029
19017
|
}
|
|
19030
19018
|
/**
|
|
19031
|
-
* The
|
|
19032
|
-
* exact output, with the assets it trades.
|
|
19019
|
+
* The orderbook's quote for an exact input, or for the input found to deliver
|
|
19020
|
+
* an exact output, with the assets it trades. A route that cannot fill the
|
|
19021
|
+
* trade answers with an unfillable quote rather than an error.
|
|
19033
19022
|
*/
|
|
19034
19023
|
async priceIntent(params, sourceChain, destinationChain, price, totals) {
|
|
19035
19024
|
validateQuoteParams(params);
|
|
@@ -19038,10 +19027,7 @@ var OrderbookMarket = class {
|
|
|
19038
19027
|
const route = toRoute(tokenIn, tokenOut);
|
|
19039
19028
|
if (params.amountIn !== void 0) {
|
|
19040
19029
|
const quote2 = await price(route, toOrderbookAmount(params.amountIn, tokenIn.decimals));
|
|
19041
|
-
|
|
19042
|
-
if (!fillable || fromOrderbookAmount(amountOut, tokenOut.decimals) === 0n) {
|
|
19043
|
-
throw this.insufficient(route, maxFillableIn, tokenIn);
|
|
19044
|
-
}
|
|
19030
|
+
totals(quote2);
|
|
19045
19031
|
return { quote: quote2, tokenIn, tokenOut };
|
|
19046
19032
|
}
|
|
19047
19033
|
const targetOut = toOrderbookAmount(params.amountOut, tokenOut.decimals);
|
|
@@ -19103,18 +19089,21 @@ var OrderbookMarket = class {
|
|
|
19103
19089
|
* filled better than its worst rate and re-pricing the rest of `targetOut` at
|
|
19104
19090
|
* the input-to-output ratio that part filled at, until a quote delivers it.
|
|
19105
19091
|
* That ratio is the orderbook's own, with the protocol fee already taken off.
|
|
19092
|
+
*
|
|
19093
|
+
* An output the route cannot deliver is answered by quoting an input past its
|
|
19094
|
+
* `maxFillableIn`, which the orderbook serves as unfillable: the smallest such
|
|
19095
|
+
* input guessed from the best rate, or one raw unit when no order serves it.
|
|
19106
19096
|
*/
|
|
19107
19097
|
async quoteExactOutput(route, targetOut, tokenIn, price, totals) {
|
|
19108
19098
|
const liquidity = await this.orderbook().routeLiquidity(route);
|
|
19109
|
-
if (liquidity.bestRate === null) throw this.insufficient(route, 0n, tokenIn);
|
|
19110
19099
|
const inputUnit = toOrderbookAmount(1n, tokenIn.decimals);
|
|
19111
|
-
let amountIn = roundUpTo(requiredInput(liquidity.side, targetOut, liquidity.bestRate), inputUnit);
|
|
19100
|
+
let amountIn = liquidity.bestRate === null ? inputUnit : roundUpTo(requiredInput(liquidity.side, targetOut, liquidity.bestRate), inputUnit);
|
|
19112
19101
|
let lastAmountIn = amountIn;
|
|
19113
19102
|
for (let round = 0; round < MAX_EXACT_OUTPUT_ROUNDS; round++) {
|
|
19114
|
-
if (amountIn > liquidity.maxFillableIn) throw this.insufficient(route, liquidity.maxFillableIn, tokenIn);
|
|
19115
19103
|
const served = await price(route, amountIn);
|
|
19116
19104
|
const quote = totals(served);
|
|
19117
19105
|
if (quote.fillable && quote.amountOut >= targetOut) return served;
|
|
19106
|
+
if (!quote.fillable && amountIn > liquidity.maxFillableIn) return served;
|
|
19118
19107
|
lastAmountIn = amountIn;
|
|
19119
19108
|
const betterIn = quote.amountIn - quote.worstIn;
|
|
19120
19109
|
const betterOut = quote.amountOut - quote.worstOut;
|
|
@@ -19127,9 +19116,6 @@ var OrderbookMarket = class {
|
|
|
19127
19116
|
fromOrderbookAmount(lastAmountIn, tokenIn.decimals)
|
|
19128
19117
|
);
|
|
19129
19118
|
}
|
|
19130
|
-
insufficient(route, maxFillableIn, tokenIn) {
|
|
19131
|
-
return new InsufficientOrderbookLiquidityError(route, fromOrderbookAmount(maxFillableIn, tokenIn.decimals));
|
|
19132
|
-
}
|
|
19133
19119
|
assetByAddress(chain, address) {
|
|
19134
19120
|
const resolvedChain = resolveChain(chain);
|
|
19135
19121
|
return withDecimals(
|
|
@@ -24680,7 +24666,6 @@ exports.HyperFungibleToken = HyperFungibleToken;
|
|
|
24680
24666
|
exports.HyperFungibleTokenABI = HyperFungibleTokenABI;
|
|
24681
24667
|
exports.HyperFxOrderbook = HyperFxOrderbook;
|
|
24682
24668
|
exports.INCLUSION_TIMEOUT_MS = INCLUSION_TIMEOUT_MS;
|
|
24683
|
-
exports.InsufficientOrderbookLiquidityError = InsufficientOrderbookLiquidityError;
|
|
24684
24669
|
exports.IntentGateway = IntentGateway;
|
|
24685
24670
|
exports.IntentGatewayABI = ABI3;
|
|
24686
24671
|
exports.IntentOrderStatus = IntentOrderStatus;
|