@hyperbridge/sdk 2.8.6 → 2.8.8
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 +68 -23
- package/dist/browser/index.js +209 -74
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +212 -73
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +55 -22
- package/dist/node/index.d.ts +55 -22
- package/dist/node/index.js +209 -74
- package/dist/node/index.js.map +1 -1
- package/dist/node/{intents-helpers-BFc6YnD3.d.cts → intents-helpers-BCsIHRts.d.cts} +16 -4
- package/dist/node/{intents-helpers-BFc6YnD3.d.ts → intents-helpers-BCsIHRts.d.ts} +16 -4
- package/dist/node/intents-helpers.cjs +10 -1
- package/dist/node/intents-helpers.cjs.map +1 -1
- package/dist/node/intents-helpers.d.cts +1 -1
- package/dist/node/intents-helpers.d.ts +1 -1
- package/dist/node/intents-helpers.js +9 -2
- package/dist/node/intents-helpers.js.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -2808,7 +2808,7 @@ var chainConfigs = {
|
|
|
2808
2808
|
// "Usdt0Oft": Not available on BSC
|
|
2809
2809
|
},
|
|
2810
2810
|
rpcEnvKey: "BSC_MAINNET",
|
|
2811
|
-
defaultRpcUrl: "https://
|
|
2811
|
+
defaultRpcUrl: "https://bsc-rpc.publicnode.com",
|
|
2812
2812
|
consensusStateId: "BSC0",
|
|
2813
2813
|
coingeckoId: "binance-smart-chain",
|
|
2814
2814
|
erc4626Vaults: [
|
|
@@ -8002,7 +8002,15 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
8002
8002
|
if (!this.httpApi) {
|
|
8003
8003
|
const httpUrl = deriveHttpUrl(this.wsEndpoint());
|
|
8004
8004
|
const api$1 = new api.ApiPromise({
|
|
8005
|
-
|
|
8005
|
+
// Response cache off (third argument, capacity 0). polkadot-js caches every request that
|
|
8006
|
+
// names a block hash — `chain_getHeader(hash)`, `state_getRuntimeVersion(hash)`, storage
|
|
8007
|
+
// reads at a hash — by storing the request promise itself, a rejected one included, for a
|
|
8008
|
+
// 30s TTL that every hit refreshes. The phantom poll retries the block it failed on with
|
|
8009
|
+
// identical parameters every tick, so one reset connection became the same rejection
|
|
8010
|
+
// replayed from memory on every tick, faster than the TTL could lapse, and the node never
|
|
8011
|
+
// saw a second request. The cache bought nothing here anyway: the poll reads each block
|
|
8012
|
+
// once, and `api.at(hash)` reuses registries at the api layer regardless.
|
|
8013
|
+
provider: new api.HttpProvider(httpUrl, {}, 0),
|
|
8006
8014
|
typesBundle: HYPERBRIDGE_TYPES_BUNDLE,
|
|
8007
8015
|
// A second connection to the node the ws api already reported on; its init warnings
|
|
8008
8016
|
// would just be duplicates.
|
|
@@ -12093,40 +12101,17 @@ query AvailableLiquidity(
|
|
|
12093
12101
|
}
|
|
12094
12102
|
}`;
|
|
12095
12103
|
var BUY_AND_SELL_RATES = `
|
|
12096
|
-
query
|
|
12097
|
-
|
|
12098
|
-
$directChain: String!
|
|
12099
|
-
$directDirection: String!
|
|
12100
|
-
$reverseChain: String!
|
|
12101
|
-
$reverseDirection: String!
|
|
12102
|
-
) {
|
|
12103
|
-
direct: poolChainLiquidities(
|
|
12104
|
-
filter: {
|
|
12105
|
-
and: [
|
|
12106
|
-
{ poolId: { equalToInsensitive: $poolId } }
|
|
12107
|
-
{ chain: { equalTo: $directChain } }
|
|
12108
|
-
{ direction: { equalTo: $directDirection } }
|
|
12109
|
-
]
|
|
12110
|
-
}
|
|
12111
|
-
first: 1
|
|
12112
|
-
) {
|
|
12113
|
-
nodes {
|
|
12114
|
-
rate
|
|
12115
|
-
lastUpdatedAt
|
|
12116
|
-
}
|
|
12117
|
-
}
|
|
12118
|
-
reverse: poolChainLiquidities(
|
|
12119
|
-
filter: {
|
|
12120
|
-
and: [
|
|
12121
|
-
{ poolId: { equalToInsensitive: $poolId } }
|
|
12122
|
-
{ chain: { equalTo: $reverseChain } }
|
|
12123
|
-
{ direction: { equalTo: $reverseDirection } }
|
|
12124
|
-
]
|
|
12125
|
-
}
|
|
12104
|
+
query GetLiquidityPoolRate($poolId: String!) {
|
|
12105
|
+
liquidityPools(
|
|
12126
12106
|
first: 1
|
|
12107
|
+
filter: { id: { equalToInsensitive: $poolId } }
|
|
12127
12108
|
) {
|
|
12128
12109
|
nodes {
|
|
12129
|
-
|
|
12110
|
+
id
|
|
12111
|
+
token0Symbol
|
|
12112
|
+
token1Symbol
|
|
12113
|
+
sellRate
|
|
12114
|
+
buyRate
|
|
12130
12115
|
lastUpdatedAt
|
|
12131
12116
|
}
|
|
12132
12117
|
}
|
|
@@ -18338,29 +18323,29 @@ var LiquidityEngine = class {
|
|
|
18338
18323
|
};
|
|
18339
18324
|
}
|
|
18340
18325
|
/**
|
|
18341
|
-
* Returns
|
|
18342
|
-
* per one base token.
|
|
18326
|
+
* Returns the indexed pool's aggregate buy and sell rates in less-valued
|
|
18327
|
+
* quote-token units per one base token.
|
|
18343
18328
|
*
|
|
18344
|
-
* The
|
|
18345
|
-
*
|
|
18346
|
-
*
|
|
18329
|
+
* The indexer depth-weights fresh per-chain samples into the pool rates. The
|
|
18330
|
+
* source and destination chains remain part of the result because they define
|
|
18331
|
+
* the cross-chain route whose configured token symbols were resolved.
|
|
18347
18332
|
*/
|
|
18348
18333
|
async getBuyAndSellRates(params) {
|
|
18349
18334
|
const pool = resolveLiquidityPool(params.tokenInSymbol, params.tokenOutSymbol);
|
|
18350
|
-
const directDirection = params.tokenInSymbol.toLowerCase() === pool.token0Symbol.toLowerCase() ? SELL : BUY;
|
|
18351
|
-
const reverseDirection = directDirection === SELL ? BUY : SELL;
|
|
18352
18335
|
const response = await this.queryClient.request(BUY_AND_SELL_RATES, {
|
|
18353
|
-
poolId: pool.poolId
|
|
18354
|
-
directChain: params.destinationChain,
|
|
18355
|
-
directDirection,
|
|
18356
|
-
reverseChain: params.sourceChain,
|
|
18357
|
-
reverseDirection
|
|
18336
|
+
poolId: pool.poolId
|
|
18358
18337
|
});
|
|
18359
|
-
if (!response?.
|
|
18360
|
-
throw new InvalidLiquidityIndexerResponseError("
|
|
18361
|
-
}
|
|
18362
|
-
const
|
|
18363
|
-
|
|
18338
|
+
if (!response?.liquidityPools?.nodes) {
|
|
18339
|
+
throw new InvalidLiquidityIndexerResponseError("liquidity pool connection is missing");
|
|
18340
|
+
}
|
|
18341
|
+
const indexedPool = response.liquidityPools.nodes[0];
|
|
18342
|
+
if (!indexedPool) return void 0;
|
|
18343
|
+
validateIndexedPool(indexedPool, pool);
|
|
18344
|
+
const sell = readIndexedRate(indexedPool.sellRate, indexedPool.lastUpdatedAt, "pool sell rate");
|
|
18345
|
+
const buy = readIndexedRate(indexedPool.buyRate, indexedPool.lastUpdatedAt, "pool buy rate");
|
|
18346
|
+
const inputIsToken0 = params.tokenInSymbol.toLowerCase() === pool.token0Symbol.toLowerCase();
|
|
18347
|
+
const direct = inputIsToken0 ? sell : buy;
|
|
18348
|
+
const reverse = inputIsToken0 ? buy : sell;
|
|
18364
18349
|
if (!direct && !reverse) return void 0;
|
|
18365
18350
|
const quoteTokenSymbol = resolveQuoteTokenSymbol(
|
|
18366
18351
|
params.tokenInSymbol,
|
|
@@ -18369,17 +18354,17 @@ var LiquidityEngine = class {
|
|
|
18369
18354
|
reverse?.scaledRate
|
|
18370
18355
|
);
|
|
18371
18356
|
const quoteIsTokenOut = quoteTokenSymbol === params.tokenOutSymbol;
|
|
18372
|
-
const
|
|
18373
|
-
const
|
|
18357
|
+
const orientedBuy = quoteIsTokenOut ? direct : reverse;
|
|
18358
|
+
const orientedSell = quoteIsTokenOut ? reverse : direct;
|
|
18374
18359
|
return {
|
|
18375
18360
|
baseTokenSymbol: quoteIsTokenOut ? params.tokenInSymbol : params.tokenOutSymbol,
|
|
18376
18361
|
quoteTokenSymbol,
|
|
18377
18362
|
sourceChain: params.sourceChain,
|
|
18378
18363
|
destinationChain: params.destinationChain,
|
|
18379
|
-
buyRate:
|
|
18380
|
-
sellRate:
|
|
18381
|
-
buyRateUpdatedAt:
|
|
18382
|
-
sellRateUpdatedAt:
|
|
18364
|
+
buyRate: orientedBuy ? viem.formatUnits(orientedBuy.scaledRate, INDEXER_FIXED_POINT_DECIMALS) : null,
|
|
18365
|
+
sellRate: orientedSell ? viem.formatUnits(reciprocalRate(orientedSell.scaledRate, "sell rate"), INDEXER_FIXED_POINT_DECIMALS) : null,
|
|
18366
|
+
buyRateUpdatedAt: orientedBuy?.updatedAt ?? null,
|
|
18367
|
+
sellRateUpdatedAt: orientedSell?.updatedAt ?? null
|
|
18383
18368
|
};
|
|
18384
18369
|
}
|
|
18385
18370
|
};
|
|
@@ -18421,20 +18406,25 @@ function readIndexerDate(value, label) {
|
|
|
18421
18406
|
if (Number.isNaN(date.getTime())) throw new InvalidLiquidityIndexerResponseError(`${label} is invalid`);
|
|
18422
18407
|
return date;
|
|
18423
18408
|
}
|
|
18424
|
-
function readIndexedRate(
|
|
18425
|
-
if (
|
|
18409
|
+
function readIndexedRate(value, lastUpdatedAt, label) {
|
|
18410
|
+
if (value === null) return void 0;
|
|
18426
18411
|
try {
|
|
18427
|
-
const scaledRate = BigInt(
|
|
18412
|
+
const scaledRate = BigInt(value);
|
|
18428
18413
|
if (scaledRate <= 0n) throw new Error();
|
|
18429
18414
|
return {
|
|
18430
18415
|
scaledRate,
|
|
18431
|
-
updatedAt: readIndexerDate(
|
|
18416
|
+
updatedAt: readIndexerDate(lastUpdatedAt, `${label} lastUpdatedAt`)
|
|
18432
18417
|
};
|
|
18433
18418
|
} catch (error) {
|
|
18434
18419
|
if (error instanceof InvalidLiquidityIndexerResponseError) throw error;
|
|
18435
18420
|
throw new InvalidLiquidityIndexerResponseError(`${label} is not a positive integer`);
|
|
18436
18421
|
}
|
|
18437
18422
|
}
|
|
18423
|
+
function validateIndexedPool(indexedPool, expected) {
|
|
18424
|
+
if (indexedPool.id.toLowerCase() !== expected.poolId.toLowerCase() || indexedPool.token0Symbol.toLowerCase() !== expected.token0Symbol.toLowerCase() || indexedPool.token1Symbol.toLowerCase() !== expected.token1Symbol.toLowerCase()) {
|
|
18425
|
+
throw new InvalidLiquidityIndexerResponseError(`pool identity does not match ${expected.poolId}`);
|
|
18426
|
+
}
|
|
18427
|
+
}
|
|
18438
18428
|
function resolveQuoteTokenSymbol(tokenInSymbol, tokenOutSymbol, directRate, reverseRate) {
|
|
18439
18429
|
const inputIsUsdStable = USD_STABLE_SYMBOLS.has(tokenInSymbol);
|
|
18440
18430
|
const outputIsUsdStable = USD_STABLE_SYMBOLS.has(tokenOutSymbol);
|
|
@@ -18444,7 +18434,8 @@ function resolveQuoteTokenSymbol(tokenInSymbol, tokenOutSymbol, directRate, reve
|
|
|
18444
18434
|
throw new InvalidLiquidityIndexerResponseError("cannot orient an empty rate pair");
|
|
18445
18435
|
}
|
|
18446
18436
|
function reciprocalRate(rate, label) {
|
|
18447
|
-
const
|
|
18437
|
+
const numerator = POOL_RATE_SCALE * POOL_RATE_SCALE;
|
|
18438
|
+
const reciprocal = (numerator + rate - 1n) / rate;
|
|
18448
18439
|
if (reciprocal <= 0n) throw new InvalidLiquidityIndexerResponseError(`${label} reciprocal underflowed`);
|
|
18449
18440
|
return reciprocal;
|
|
18450
18441
|
}
|
|
@@ -18476,6 +18467,20 @@ var InvalidPhantomSnapshotError = class extends Error {
|
|
|
18476
18467
|
this.name = "InvalidPhantomSnapshotError";
|
|
18477
18468
|
}
|
|
18478
18469
|
};
|
|
18470
|
+
var IndexedRateUnavailableError = class extends Error {
|
|
18471
|
+
constructor(params) {
|
|
18472
|
+
const route = params.source && params.destination && params.tokenIn && params.tokenOut ? ` for ${params.tokenIn} -> ${params.tokenOut} on ${params.source} -> ${params.destination}` : "";
|
|
18473
|
+
const side = params.side ? ` ${params.side}` : "";
|
|
18474
|
+
super(`No indexed${side} rate available${route}`);
|
|
18475
|
+
this.name = "IndexedRateUnavailableError";
|
|
18476
|
+
}
|
|
18477
|
+
};
|
|
18478
|
+
var InvalidIndexedRateError = class extends Error {
|
|
18479
|
+
constructor(reason) {
|
|
18480
|
+
super(`Invalid indexed intent rate: ${reason}`);
|
|
18481
|
+
this.name = "InvalidIndexedRateError";
|
|
18482
|
+
}
|
|
18483
|
+
};
|
|
18479
18484
|
var BPS_DENOMINATOR = 10000n;
|
|
18480
18485
|
function validateQuoteParams(params) {
|
|
18481
18486
|
const hasAmountIn = params.amountIn !== void 0;
|
|
@@ -18842,6 +18847,128 @@ function isSupportedSnapshotPair(tokenA, tokenB) {
|
|
|
18842
18847
|
function isConfiguredAddress(address) {
|
|
18843
18848
|
return Boolean(address && address !== "0x" && !/^0x0{40}$/i.test(address));
|
|
18844
18849
|
}
|
|
18850
|
+
var INDEXED_RATE_DECIMALS = 18;
|
|
18851
|
+
var INDEXED_RATE_SCALE = 10n ** BigInt(INDEXED_RATE_DECIMALS);
|
|
18852
|
+
var IndexedRateIntentQuoteStrategy = class {
|
|
18853
|
+
constructor(chainConfigService, getQueryClient) {
|
|
18854
|
+
this.chainConfigService = chainConfigService;
|
|
18855
|
+
this.getQueryClient = getQueryClient;
|
|
18856
|
+
}
|
|
18857
|
+
chainConfigService;
|
|
18858
|
+
getQueryClient;
|
|
18859
|
+
async quote(params, source, destination) {
|
|
18860
|
+
validateQuoteParams(params);
|
|
18861
|
+
const sourceConfig = getConfigByStateMachineId(source.stateMachineId);
|
|
18862
|
+
const destinationConfig = getConfigByStateMachineId(destination.stateMachineId);
|
|
18863
|
+
if (!sourceConfig) throw new UnsupportedLiquidityChainError(source.stateMachineId);
|
|
18864
|
+
if (!destinationConfig) throw new UnsupportedLiquidityChainError(destination.stateMachineId);
|
|
18865
|
+
const tokenIn = this.resolveAsset(sourceConfig.stateMachineId, params.tokenIn);
|
|
18866
|
+
const tokenOut = this.resolveAsset(destinationConfig.stateMachineId, params.tokenOut);
|
|
18867
|
+
const [protocolFeeBps, rates] = await Promise.all([
|
|
18868
|
+
readProtocolFeeBps(this.chainConfigService, source),
|
|
18869
|
+
new LiquidityEngine(this.getQueryClient()).getBuyAndSellRates({
|
|
18870
|
+
sourceChain: sourceConfig.stateMachineId,
|
|
18871
|
+
destinationChain: destinationConfig.stateMachineId,
|
|
18872
|
+
tokenInSymbol: tokenIn.symbol,
|
|
18873
|
+
tokenOutSymbol: tokenOut.symbol
|
|
18874
|
+
})
|
|
18875
|
+
]);
|
|
18876
|
+
if (!rates) {
|
|
18877
|
+
throw new IndexedRateUnavailableError({
|
|
18878
|
+
source: sourceConfig.stateMachineId,
|
|
18879
|
+
destination: destinationConfig.stateMachineId,
|
|
18880
|
+
tokenIn: tokenIn.symbol,
|
|
18881
|
+
tokenOut: tokenOut.symbol
|
|
18882
|
+
});
|
|
18883
|
+
}
|
|
18884
|
+
const selectedRate = selectIndexedRate(rates, tokenIn.symbol, tokenOut.symbol);
|
|
18885
|
+
return quoteWithIndexedRate(params, tokenIn, tokenOut, selectedRate, rates, protocolFeeBps);
|
|
18886
|
+
}
|
|
18887
|
+
resolveAsset(chain, address) {
|
|
18888
|
+
const asset = this.chainConfigService.getAssetMetadataByAddress(chain, address);
|
|
18889
|
+
if (!asset) throw new UnsupportedLiquidityAssetError(chain, address);
|
|
18890
|
+
const { decimals } = asset;
|
|
18891
|
+
if (decimals === void 0 || !Number.isSafeInteger(decimals) || decimals < 0) {
|
|
18892
|
+
throw new InvalidIndexedRateError(`decimals are not configured for ${asset.symbol} on ${chain}`);
|
|
18893
|
+
}
|
|
18894
|
+
return { ...asset, decimals };
|
|
18895
|
+
}
|
|
18896
|
+
};
|
|
18897
|
+
function selectIndexedRate(rates, tokenInSymbol, tokenOutSymbol) {
|
|
18898
|
+
if (tokenInSymbol === rates.baseTokenSymbol && tokenOutSymbol === rates.quoteTokenSymbol) {
|
|
18899
|
+
return readIndexedRate2(
|
|
18900
|
+
"buy",
|
|
18901
|
+
rates.buyRate,
|
|
18902
|
+
rates.buyRateUpdatedAt,
|
|
18903
|
+
rates,
|
|
18904
|
+
tokenInSymbol,
|
|
18905
|
+
tokenOutSymbol
|
|
18906
|
+
);
|
|
18907
|
+
}
|
|
18908
|
+
if (tokenInSymbol === rates.quoteTokenSymbol && tokenOutSymbol === rates.baseTokenSymbol) {
|
|
18909
|
+
return readIndexedRate2(
|
|
18910
|
+
"sell",
|
|
18911
|
+
rates.sellRate,
|
|
18912
|
+
rates.sellRateUpdatedAt,
|
|
18913
|
+
rates,
|
|
18914
|
+
tokenInSymbol,
|
|
18915
|
+
tokenOutSymbol
|
|
18916
|
+
);
|
|
18917
|
+
}
|
|
18918
|
+
throw new InvalidIndexedRateError(
|
|
18919
|
+
`indexed pair ${rates.baseTokenSymbol}/${rates.quoteTokenSymbol} does not match ${tokenInSymbol}/${tokenOutSymbol}`
|
|
18920
|
+
);
|
|
18921
|
+
}
|
|
18922
|
+
function readIndexedRate2(side, rate, updatedAt, rates, tokenInSymbol, tokenOutSymbol) {
|
|
18923
|
+
if (!rate || !updatedAt) {
|
|
18924
|
+
throw new IndexedRateUnavailableError({
|
|
18925
|
+
source: rates.sourceChain,
|
|
18926
|
+
destination: rates.destinationChain,
|
|
18927
|
+
tokenIn: tokenInSymbol,
|
|
18928
|
+
tokenOut: tokenOutSymbol,
|
|
18929
|
+
side
|
|
18930
|
+
});
|
|
18931
|
+
}
|
|
18932
|
+
try {
|
|
18933
|
+
const scaledRate = viem.parseUnits(rate, INDEXED_RATE_DECIMALS);
|
|
18934
|
+
if (scaledRate <= 0n || Number.isNaN(updatedAt.getTime())) throw new Error();
|
|
18935
|
+
return { side, rate, scaledRate, updatedAt };
|
|
18936
|
+
} catch {
|
|
18937
|
+
throw new InvalidIndexedRateError(`${side} rate or timestamp is invalid`);
|
|
18938
|
+
}
|
|
18939
|
+
}
|
|
18940
|
+
function quoteWithIndexedRate(params, tokenIn, tokenOut, selectedRate, rates, protocolFeeBps) {
|
|
18941
|
+
const inputUnit = 10n ** BigInt(tokenIn.decimals);
|
|
18942
|
+
const outputUnit = 10n ** BigInt(tokenOut.decimals);
|
|
18943
|
+
if (params.amountIn !== void 0) {
|
|
18944
|
+
const netAmountIn2 = deductProtocolFee(params.amountIn, protocolFeeBps);
|
|
18945
|
+
const amountOut = selectedRate.side === "buy" ? netAmountIn2 * selectedRate.scaledRate * outputUnit / (inputUnit * INDEXED_RATE_SCALE) : netAmountIn2 * outputUnit * INDEXED_RATE_SCALE / (inputUnit * selectedRate.scaledRate);
|
|
18946
|
+
if (amountOut <= 0n) throw new InvalidIndexedRateError("quote rounds down to zero output");
|
|
18947
|
+
return buildResult("EXACT_INPUT", params.amountIn, amountOut, selectedRate, rates, protocolFeeBps);
|
|
18948
|
+
}
|
|
18949
|
+
if (params.amountOut === void 0) throw new Error("Quote amount is missing after validation");
|
|
18950
|
+
const netAmountIn = selectedRate.side === "buy" ? divCeil(params.amountOut * inputUnit * INDEXED_RATE_SCALE, selectedRate.scaledRate * outputUnit) : divCeil(params.amountOut * inputUnit * selectedRate.scaledRate, outputUnit * INDEXED_RATE_SCALE);
|
|
18951
|
+
const amountIn = grossUpForProtocolFee(netAmountIn, protocolFeeBps);
|
|
18952
|
+
return buildResult("EXACT_OUTPUT", amountIn, params.amountOut, selectedRate, rates, protocolFeeBps);
|
|
18953
|
+
}
|
|
18954
|
+
function buildResult(tradeType, amountIn, amountOut, selectedRate, rates, protocolFeeBps) {
|
|
18955
|
+
return {
|
|
18956
|
+
strategy: "indexed_rates",
|
|
18957
|
+
tradeType,
|
|
18958
|
+
amountIn,
|
|
18959
|
+
amountOut,
|
|
18960
|
+
quoteMetadata: {
|
|
18961
|
+
sourceChain: rates.sourceChain,
|
|
18962
|
+
destinationChain: rates.destinationChain,
|
|
18963
|
+
baseTokenSymbol: rates.baseTokenSymbol,
|
|
18964
|
+
quoteTokenSymbol: rates.quoteTokenSymbol,
|
|
18965
|
+
rateSide: selectedRate.side,
|
|
18966
|
+
rate: selectedRate.rate,
|
|
18967
|
+
rateUpdatedAt: selectedRate.updatedAt,
|
|
18968
|
+
protocolFeeBps
|
|
18969
|
+
}
|
|
18970
|
+
};
|
|
18971
|
+
}
|
|
18845
18972
|
|
|
18846
18973
|
// src/protocols/intents/IntentGateway.ts
|
|
18847
18974
|
var CROSS_CHAIN_ORDER_FEE_GAS_PRICE_BUMP_PERCENT = 10n;
|
|
@@ -18916,6 +19043,10 @@ var IntentGateway = class _IntentGateway {
|
|
|
18916
19043
|
this.gasEstimator = gasEstimator;
|
|
18917
19044
|
this._crypto = crypto;
|
|
18918
19045
|
this.quoteStrategies = {
|
|
19046
|
+
indexed_rates: new IndexedRateIntentQuoteStrategy(
|
|
19047
|
+
dest.configService,
|
|
19048
|
+
() => this.requireIndexer().queryClient
|
|
19049
|
+
),
|
|
18919
19050
|
phantom_snapshot: new PhantomSnapshotIntentQuoteStrategy(
|
|
18920
19051
|
dest.configService,
|
|
18921
19052
|
() => this.requireIndexer().queryClient
|
|
@@ -18969,26 +19100,26 @@ var IntentGateway = class _IntentGateway {
|
|
|
18969
19100
|
/**
|
|
18970
19101
|
* Quotes an intent between this gateway's source and destination chains.
|
|
18971
19102
|
*
|
|
18972
|
-
* Uses the latest directional
|
|
18973
|
-
*
|
|
18974
|
-
* requesting a
|
|
19103
|
+
* Uses the indexer's latest aggregate directional pool rate by default. Pass
|
|
19104
|
+
* `strategy: "phantom_snapshot"` or `strategy: "uniswap_v4"` only when
|
|
19105
|
+
* explicitly requesting a legacy quote source. Provide exactly one of
|
|
19106
|
+
* `amountIn` or `amountOut`.
|
|
18975
19107
|
*
|
|
18976
|
-
*
|
|
18977
|
-
*
|
|
19108
|
+
* The gateway's source and destination chains resolve the configured order
|
|
19109
|
+
* tokens; the indexer supplies the depth-weighted pool rate. Returned
|
|
18978
19110
|
* `amountIn`/`amountOut` already account for the gateway's protocol fee
|
|
18979
|
-
* (`quoteMetadata.protocolFeeBps`), which the gateway deducts from order
|
|
18980
|
-
* inputs; use the returned amounts directly when placing the order.
|
|
19111
|
+
* (`quoteMetadata.protocolFeeBps`), which the gateway deducts from order inputs.
|
|
18981
19112
|
*
|
|
18982
19113
|
* @param params - Token pair, amount, and optional strategy/pool overrides.
|
|
18983
19114
|
* @returns The quoted amounts plus strategy-specific metadata.
|
|
18984
19115
|
* @throws {UnsupportedIntentQuoteStrategyError} For unknown strategies.
|
|
18985
19116
|
* @throws {UnsupportedIntentQuotePairError} When the selected strategy does not support the pair.
|
|
18986
|
-
* @throws {
|
|
19117
|
+
* @throws {IndexedRateUnavailableError} When the requested direction has no indexed rate.
|
|
18987
19118
|
*/
|
|
18988
19119
|
async quoteIntent(params) {
|
|
18989
19120
|
const source = { stateMachineId: this.source.config.stateMachineId, client: this.source.client };
|
|
18990
19121
|
const destination = { stateMachineId: this.dest.config.stateMachineId, client: this.dest.client };
|
|
18991
|
-
const strategy = params.strategy ?? "
|
|
19122
|
+
const strategy = params.strategy ?? "indexed_rates";
|
|
18992
19123
|
const handler = this.quoteStrategies[strategy];
|
|
18993
19124
|
if (!handler) throw new UnsupportedIntentQuoteStrategyError(strategy);
|
|
18994
19125
|
return handler.quote({ ...params, strategy }, source, destination);
|
|
@@ -19028,9 +19159,9 @@ var IntentGateway = class _IntentGateway {
|
|
|
19028
19159
|
});
|
|
19029
19160
|
}
|
|
19030
19161
|
/**
|
|
19031
|
-
* Returns
|
|
19032
|
-
* without requiring token addresses. Symbols are matched
|
|
19033
|
-
* chain IDs
|
|
19162
|
+
* Returns aggregate indexed pool buy and sell rates in less-valued quote-token
|
|
19163
|
+
* units without requiring token addresses. Symbols are matched
|
|
19164
|
+
* case-insensitively; chain IDs resolve configured token deployments.
|
|
19034
19165
|
*/
|
|
19035
19166
|
async queryBuyAndSellRates(params) {
|
|
19036
19167
|
const { queryClient } = this.requireIndexer();
|
|
@@ -19678,6 +19809,10 @@ function encodeAcceptedSourceChains(chains2) {
|
|
|
19678
19809
|
function decodeAcceptedSourceChains(paymasterAndData) {
|
|
19679
19810
|
return decodePhantomBidDeclaration(paymasterAndData).acceptedSources;
|
|
19680
19811
|
}
|
|
19812
|
+
var UNISWAP_QUOTE_HAIRCUT_BPS = 30n;
|
|
19813
|
+
function applyUniswapQuoteHaircut(amount) {
|
|
19814
|
+
return amount * (10000n - UNISWAP_QUOTE_HAIRCUT_BPS) / 10000n;
|
|
19815
|
+
}
|
|
19681
19816
|
FILL_ORDER_ABI.find(
|
|
19682
19817
|
(item) => item?.type === "function" && item?.name === "fillOrder"
|
|
19683
19818
|
)?.inputs?.[0];
|
|
@@ -24169,10 +24304,12 @@ exports.HyperClientStatus = HyperClientStatus;
|
|
|
24169
24304
|
exports.HyperFungibleToken = HyperFungibleToken;
|
|
24170
24305
|
exports.HyperFungibleTokenABI = HyperFungibleTokenABI;
|
|
24171
24306
|
exports.INCLUSION_TIMEOUT_MS = INCLUSION_TIMEOUT_MS;
|
|
24307
|
+
exports.IndexedRateUnavailableError = IndexedRateUnavailableError;
|
|
24172
24308
|
exports.IntentGateway = IntentGateway;
|
|
24173
24309
|
exports.IntentGatewayABI = ABI3;
|
|
24174
24310
|
exports.IntentOrderStatus = IntentOrderStatus;
|
|
24175
24311
|
exports.IntentsCoprocessor = IntentsCoprocessor;
|
|
24312
|
+
exports.InvalidIndexedRateError = InvalidIndexedRateError;
|
|
24176
24313
|
exports.InvalidLiquidityIndexerResponseError = InvalidLiquidityIndexerResponseError;
|
|
24177
24314
|
exports.InvalidPhantomSnapshotError = InvalidPhantomSnapshotError;
|
|
24178
24315
|
exports.IsmpClient = IsmpClient;
|
|
@@ -24200,6 +24337,7 @@ exports.TeleportStatus = TeleportStatus;
|
|
|
24200
24337
|
exports.TimeoutStatus = TimeoutStatus;
|
|
24201
24338
|
exports.TokenGateway = TokenGateway;
|
|
24202
24339
|
exports.TronChain = TronChain;
|
|
24340
|
+
exports.UNISWAP_QUOTE_HAIRCUT_BPS = UNISWAP_QUOTE_HAIRCUT_BPS;
|
|
24203
24341
|
exports.USE_ETHERSCAN_CHAINS = USE_ETHERSCAN_CHAINS;
|
|
24204
24342
|
exports.UnsupportedIntentQuotePairError = UnsupportedIntentQuotePairError;
|
|
24205
24343
|
exports.UnsupportedIntentQuoteStrategyError = UnsupportedIntentQuoteStrategyError;
|
|
@@ -24208,6 +24346,7 @@ exports.UnsupportedLiquidityChainError = UnsupportedLiquidityChainError;
|
|
|
24208
24346
|
exports.WrappedHyperFungibleTokenABI = WrappedHyperFungibleTokenABI;
|
|
24209
24347
|
exports.__test = __test;
|
|
24210
24348
|
exports.adjustDecimals = adjustDecimals;
|
|
24349
|
+
exports.applyUniswapQuoteHaircut = applyUniswapQuoteHaircut;
|
|
24211
24350
|
exports.bytes20ToBytes32 = bytes20ToBytes32;
|
|
24212
24351
|
exports.bytes32ToBytes20 = bytes32ToBytes20;
|
|
24213
24352
|
exports.calculateAllowanceMappingLocation = calculateAllowanceMappingLocation;
|