@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.js
CHANGED
|
@@ -2797,7 +2797,7 @@ var chainConfigs = {
|
|
|
2797
2797
|
// "Usdt0Oft": Not available on BSC
|
|
2798
2798
|
},
|
|
2799
2799
|
rpcEnvKey: "BSC_MAINNET",
|
|
2800
|
-
defaultRpcUrl: "https://
|
|
2800
|
+
defaultRpcUrl: "https://bsc-rpc.publicnode.com",
|
|
2801
2801
|
consensusStateId: "BSC0",
|
|
2802
2802
|
coingeckoId: "binance-smart-chain",
|
|
2803
2803
|
erc4626Vaults: [
|
|
@@ -7991,7 +7991,15 @@ var IntentsCoprocessor = class _IntentsCoprocessor {
|
|
|
7991
7991
|
if (!this.httpApi) {
|
|
7992
7992
|
const httpUrl = deriveHttpUrl(this.wsEndpoint());
|
|
7993
7993
|
const api = new ApiPromise({
|
|
7994
|
-
|
|
7994
|
+
// Response cache off (third argument, capacity 0). polkadot-js caches every request that
|
|
7995
|
+
// names a block hash — `chain_getHeader(hash)`, `state_getRuntimeVersion(hash)`, storage
|
|
7996
|
+
// reads at a hash — by storing the request promise itself, a rejected one included, for a
|
|
7997
|
+
// 30s TTL that every hit refreshes. The phantom poll retries the block it failed on with
|
|
7998
|
+
// identical parameters every tick, so one reset connection became the same rejection
|
|
7999
|
+
// replayed from memory on every tick, faster than the TTL could lapse, and the node never
|
|
8000
|
+
// saw a second request. The cache bought nothing here anyway: the poll reads each block
|
|
8001
|
+
// once, and `api.at(hash)` reuses registries at the api layer regardless.
|
|
8002
|
+
provider: new HttpProvider(httpUrl, {}, 0),
|
|
7995
8003
|
typesBundle: HYPERBRIDGE_TYPES_BUNDLE,
|
|
7996
8004
|
// A second connection to the node the ws api already reported on; its init warnings
|
|
7997
8005
|
// would just be duplicates.
|
|
@@ -12082,40 +12090,17 @@ query AvailableLiquidity(
|
|
|
12082
12090
|
}
|
|
12083
12091
|
}`;
|
|
12084
12092
|
var BUY_AND_SELL_RATES = `
|
|
12085
|
-
query
|
|
12086
|
-
|
|
12087
|
-
$directChain: String!
|
|
12088
|
-
$directDirection: String!
|
|
12089
|
-
$reverseChain: String!
|
|
12090
|
-
$reverseDirection: String!
|
|
12091
|
-
) {
|
|
12092
|
-
direct: poolChainLiquidities(
|
|
12093
|
-
filter: {
|
|
12094
|
-
and: [
|
|
12095
|
-
{ poolId: { equalToInsensitive: $poolId } }
|
|
12096
|
-
{ chain: { equalTo: $directChain } }
|
|
12097
|
-
{ direction: { equalTo: $directDirection } }
|
|
12098
|
-
]
|
|
12099
|
-
}
|
|
12100
|
-
first: 1
|
|
12101
|
-
) {
|
|
12102
|
-
nodes {
|
|
12103
|
-
rate
|
|
12104
|
-
lastUpdatedAt
|
|
12105
|
-
}
|
|
12106
|
-
}
|
|
12107
|
-
reverse: poolChainLiquidities(
|
|
12108
|
-
filter: {
|
|
12109
|
-
and: [
|
|
12110
|
-
{ poolId: { equalToInsensitive: $poolId } }
|
|
12111
|
-
{ chain: { equalTo: $reverseChain } }
|
|
12112
|
-
{ direction: { equalTo: $reverseDirection } }
|
|
12113
|
-
]
|
|
12114
|
-
}
|
|
12093
|
+
query GetLiquidityPoolRate($poolId: String!) {
|
|
12094
|
+
liquidityPools(
|
|
12115
12095
|
first: 1
|
|
12096
|
+
filter: { id: { equalToInsensitive: $poolId } }
|
|
12116
12097
|
) {
|
|
12117
12098
|
nodes {
|
|
12118
|
-
|
|
12099
|
+
id
|
|
12100
|
+
token0Symbol
|
|
12101
|
+
token1Symbol
|
|
12102
|
+
sellRate
|
|
12103
|
+
buyRate
|
|
12119
12104
|
lastUpdatedAt
|
|
12120
12105
|
}
|
|
12121
12106
|
}
|
|
@@ -18327,29 +18312,29 @@ var LiquidityEngine = class {
|
|
|
18327
18312
|
};
|
|
18328
18313
|
}
|
|
18329
18314
|
/**
|
|
18330
|
-
* Returns
|
|
18331
|
-
* per one base token.
|
|
18315
|
+
* Returns the indexed pool's aggregate buy and sell rates in less-valued
|
|
18316
|
+
* quote-token units per one base token.
|
|
18332
18317
|
*
|
|
18333
|
-
* The
|
|
18334
|
-
*
|
|
18335
|
-
*
|
|
18318
|
+
* The indexer depth-weights fresh per-chain samples into the pool rates. The
|
|
18319
|
+
* source and destination chains remain part of the result because they define
|
|
18320
|
+
* the cross-chain route whose configured token symbols were resolved.
|
|
18336
18321
|
*/
|
|
18337
18322
|
async getBuyAndSellRates(params) {
|
|
18338
18323
|
const pool = resolveLiquidityPool(params.tokenInSymbol, params.tokenOutSymbol);
|
|
18339
|
-
const directDirection = params.tokenInSymbol.toLowerCase() === pool.token0Symbol.toLowerCase() ? SELL : BUY;
|
|
18340
|
-
const reverseDirection = directDirection === SELL ? BUY : SELL;
|
|
18341
18324
|
const response = await this.queryClient.request(BUY_AND_SELL_RATES, {
|
|
18342
|
-
poolId: pool.poolId
|
|
18343
|
-
directChain: params.destinationChain,
|
|
18344
|
-
directDirection,
|
|
18345
|
-
reverseChain: params.sourceChain,
|
|
18346
|
-
reverseDirection
|
|
18325
|
+
poolId: pool.poolId
|
|
18347
18326
|
});
|
|
18348
|
-
if (!response?.
|
|
18349
|
-
throw new InvalidLiquidityIndexerResponseError("
|
|
18350
|
-
}
|
|
18351
|
-
const
|
|
18352
|
-
|
|
18327
|
+
if (!response?.liquidityPools?.nodes) {
|
|
18328
|
+
throw new InvalidLiquidityIndexerResponseError("liquidity pool connection is missing");
|
|
18329
|
+
}
|
|
18330
|
+
const indexedPool = response.liquidityPools.nodes[0];
|
|
18331
|
+
if (!indexedPool) return void 0;
|
|
18332
|
+
validateIndexedPool(indexedPool, pool);
|
|
18333
|
+
const sell = readIndexedRate(indexedPool.sellRate, indexedPool.lastUpdatedAt, "pool sell rate");
|
|
18334
|
+
const buy = readIndexedRate(indexedPool.buyRate, indexedPool.lastUpdatedAt, "pool buy rate");
|
|
18335
|
+
const inputIsToken0 = params.tokenInSymbol.toLowerCase() === pool.token0Symbol.toLowerCase();
|
|
18336
|
+
const direct = inputIsToken0 ? sell : buy;
|
|
18337
|
+
const reverse = inputIsToken0 ? buy : sell;
|
|
18353
18338
|
if (!direct && !reverse) return void 0;
|
|
18354
18339
|
const quoteTokenSymbol = resolveQuoteTokenSymbol(
|
|
18355
18340
|
params.tokenInSymbol,
|
|
@@ -18358,17 +18343,17 @@ var LiquidityEngine = class {
|
|
|
18358
18343
|
reverse?.scaledRate
|
|
18359
18344
|
);
|
|
18360
18345
|
const quoteIsTokenOut = quoteTokenSymbol === params.tokenOutSymbol;
|
|
18361
|
-
const
|
|
18362
|
-
const
|
|
18346
|
+
const orientedBuy = quoteIsTokenOut ? direct : reverse;
|
|
18347
|
+
const orientedSell = quoteIsTokenOut ? reverse : direct;
|
|
18363
18348
|
return {
|
|
18364
18349
|
baseTokenSymbol: quoteIsTokenOut ? params.tokenInSymbol : params.tokenOutSymbol,
|
|
18365
18350
|
quoteTokenSymbol,
|
|
18366
18351
|
sourceChain: params.sourceChain,
|
|
18367
18352
|
destinationChain: params.destinationChain,
|
|
18368
|
-
buyRate:
|
|
18369
|
-
sellRate:
|
|
18370
|
-
buyRateUpdatedAt:
|
|
18371
|
-
sellRateUpdatedAt:
|
|
18353
|
+
buyRate: orientedBuy ? formatUnits(orientedBuy.scaledRate, INDEXER_FIXED_POINT_DECIMALS) : null,
|
|
18354
|
+
sellRate: orientedSell ? formatUnits(reciprocalRate(orientedSell.scaledRate, "sell rate"), INDEXER_FIXED_POINT_DECIMALS) : null,
|
|
18355
|
+
buyRateUpdatedAt: orientedBuy?.updatedAt ?? null,
|
|
18356
|
+
sellRateUpdatedAt: orientedSell?.updatedAt ?? null
|
|
18372
18357
|
};
|
|
18373
18358
|
}
|
|
18374
18359
|
};
|
|
@@ -18410,20 +18395,25 @@ function readIndexerDate(value, label) {
|
|
|
18410
18395
|
if (Number.isNaN(date.getTime())) throw new InvalidLiquidityIndexerResponseError(`${label} is invalid`);
|
|
18411
18396
|
return date;
|
|
18412
18397
|
}
|
|
18413
|
-
function readIndexedRate(
|
|
18414
|
-
if (
|
|
18398
|
+
function readIndexedRate(value, lastUpdatedAt, label) {
|
|
18399
|
+
if (value === null) return void 0;
|
|
18415
18400
|
try {
|
|
18416
|
-
const scaledRate = BigInt(
|
|
18401
|
+
const scaledRate = BigInt(value);
|
|
18417
18402
|
if (scaledRate <= 0n) throw new Error();
|
|
18418
18403
|
return {
|
|
18419
18404
|
scaledRate,
|
|
18420
|
-
updatedAt: readIndexerDate(
|
|
18405
|
+
updatedAt: readIndexerDate(lastUpdatedAt, `${label} lastUpdatedAt`)
|
|
18421
18406
|
};
|
|
18422
18407
|
} catch (error) {
|
|
18423
18408
|
if (error instanceof InvalidLiquidityIndexerResponseError) throw error;
|
|
18424
18409
|
throw new InvalidLiquidityIndexerResponseError(`${label} is not a positive integer`);
|
|
18425
18410
|
}
|
|
18426
18411
|
}
|
|
18412
|
+
function validateIndexedPool(indexedPool, expected) {
|
|
18413
|
+
if (indexedPool.id.toLowerCase() !== expected.poolId.toLowerCase() || indexedPool.token0Symbol.toLowerCase() !== expected.token0Symbol.toLowerCase() || indexedPool.token1Symbol.toLowerCase() !== expected.token1Symbol.toLowerCase()) {
|
|
18414
|
+
throw new InvalidLiquidityIndexerResponseError(`pool identity does not match ${expected.poolId}`);
|
|
18415
|
+
}
|
|
18416
|
+
}
|
|
18427
18417
|
function resolveQuoteTokenSymbol(tokenInSymbol, tokenOutSymbol, directRate, reverseRate) {
|
|
18428
18418
|
const inputIsUsdStable = USD_STABLE_SYMBOLS.has(tokenInSymbol);
|
|
18429
18419
|
const outputIsUsdStable = USD_STABLE_SYMBOLS.has(tokenOutSymbol);
|
|
@@ -18433,7 +18423,8 @@ function resolveQuoteTokenSymbol(tokenInSymbol, tokenOutSymbol, directRate, reve
|
|
|
18433
18423
|
throw new InvalidLiquidityIndexerResponseError("cannot orient an empty rate pair");
|
|
18434
18424
|
}
|
|
18435
18425
|
function reciprocalRate(rate, label) {
|
|
18436
|
-
const
|
|
18426
|
+
const numerator = POOL_RATE_SCALE * POOL_RATE_SCALE;
|
|
18427
|
+
const reciprocal = (numerator + rate - 1n) / rate;
|
|
18437
18428
|
if (reciprocal <= 0n) throw new InvalidLiquidityIndexerResponseError(`${label} reciprocal underflowed`);
|
|
18438
18429
|
return reciprocal;
|
|
18439
18430
|
}
|
|
@@ -18465,6 +18456,20 @@ var InvalidPhantomSnapshotError = class extends Error {
|
|
|
18465
18456
|
this.name = "InvalidPhantomSnapshotError";
|
|
18466
18457
|
}
|
|
18467
18458
|
};
|
|
18459
|
+
var IndexedRateUnavailableError = class extends Error {
|
|
18460
|
+
constructor(params) {
|
|
18461
|
+
const route = params.source && params.destination && params.tokenIn && params.tokenOut ? ` for ${params.tokenIn} -> ${params.tokenOut} on ${params.source} -> ${params.destination}` : "";
|
|
18462
|
+
const side = params.side ? ` ${params.side}` : "";
|
|
18463
|
+
super(`No indexed${side} rate available${route}`);
|
|
18464
|
+
this.name = "IndexedRateUnavailableError";
|
|
18465
|
+
}
|
|
18466
|
+
};
|
|
18467
|
+
var InvalidIndexedRateError = class extends Error {
|
|
18468
|
+
constructor(reason) {
|
|
18469
|
+
super(`Invalid indexed intent rate: ${reason}`);
|
|
18470
|
+
this.name = "InvalidIndexedRateError";
|
|
18471
|
+
}
|
|
18472
|
+
};
|
|
18468
18473
|
var BPS_DENOMINATOR = 10000n;
|
|
18469
18474
|
function validateQuoteParams(params) {
|
|
18470
18475
|
const hasAmountIn = params.amountIn !== void 0;
|
|
@@ -18831,6 +18836,128 @@ function isSupportedSnapshotPair(tokenA, tokenB) {
|
|
|
18831
18836
|
function isConfiguredAddress(address) {
|
|
18832
18837
|
return Boolean(address && address !== "0x" && !/^0x0{40}$/i.test(address));
|
|
18833
18838
|
}
|
|
18839
|
+
var INDEXED_RATE_DECIMALS = 18;
|
|
18840
|
+
var INDEXED_RATE_SCALE = 10n ** BigInt(INDEXED_RATE_DECIMALS);
|
|
18841
|
+
var IndexedRateIntentQuoteStrategy = class {
|
|
18842
|
+
constructor(chainConfigService, getQueryClient) {
|
|
18843
|
+
this.chainConfigService = chainConfigService;
|
|
18844
|
+
this.getQueryClient = getQueryClient;
|
|
18845
|
+
}
|
|
18846
|
+
chainConfigService;
|
|
18847
|
+
getQueryClient;
|
|
18848
|
+
async quote(params, source, destination) {
|
|
18849
|
+
validateQuoteParams(params);
|
|
18850
|
+
const sourceConfig = getConfigByStateMachineId(source.stateMachineId);
|
|
18851
|
+
const destinationConfig = getConfigByStateMachineId(destination.stateMachineId);
|
|
18852
|
+
if (!sourceConfig) throw new UnsupportedLiquidityChainError(source.stateMachineId);
|
|
18853
|
+
if (!destinationConfig) throw new UnsupportedLiquidityChainError(destination.stateMachineId);
|
|
18854
|
+
const tokenIn = this.resolveAsset(sourceConfig.stateMachineId, params.tokenIn);
|
|
18855
|
+
const tokenOut = this.resolveAsset(destinationConfig.stateMachineId, params.tokenOut);
|
|
18856
|
+
const [protocolFeeBps, rates] = await Promise.all([
|
|
18857
|
+
readProtocolFeeBps(this.chainConfigService, source),
|
|
18858
|
+
new LiquidityEngine(this.getQueryClient()).getBuyAndSellRates({
|
|
18859
|
+
sourceChain: sourceConfig.stateMachineId,
|
|
18860
|
+
destinationChain: destinationConfig.stateMachineId,
|
|
18861
|
+
tokenInSymbol: tokenIn.symbol,
|
|
18862
|
+
tokenOutSymbol: tokenOut.symbol
|
|
18863
|
+
})
|
|
18864
|
+
]);
|
|
18865
|
+
if (!rates) {
|
|
18866
|
+
throw new IndexedRateUnavailableError({
|
|
18867
|
+
source: sourceConfig.stateMachineId,
|
|
18868
|
+
destination: destinationConfig.stateMachineId,
|
|
18869
|
+
tokenIn: tokenIn.symbol,
|
|
18870
|
+
tokenOut: tokenOut.symbol
|
|
18871
|
+
});
|
|
18872
|
+
}
|
|
18873
|
+
const selectedRate = selectIndexedRate(rates, tokenIn.symbol, tokenOut.symbol);
|
|
18874
|
+
return quoteWithIndexedRate(params, tokenIn, tokenOut, selectedRate, rates, protocolFeeBps);
|
|
18875
|
+
}
|
|
18876
|
+
resolveAsset(chain, address) {
|
|
18877
|
+
const asset = this.chainConfigService.getAssetMetadataByAddress(chain, address);
|
|
18878
|
+
if (!asset) throw new UnsupportedLiquidityAssetError(chain, address);
|
|
18879
|
+
const { decimals } = asset;
|
|
18880
|
+
if (decimals === void 0 || !Number.isSafeInteger(decimals) || decimals < 0) {
|
|
18881
|
+
throw new InvalidIndexedRateError(`decimals are not configured for ${asset.symbol} on ${chain}`);
|
|
18882
|
+
}
|
|
18883
|
+
return { ...asset, decimals };
|
|
18884
|
+
}
|
|
18885
|
+
};
|
|
18886
|
+
function selectIndexedRate(rates, tokenInSymbol, tokenOutSymbol) {
|
|
18887
|
+
if (tokenInSymbol === rates.baseTokenSymbol && tokenOutSymbol === rates.quoteTokenSymbol) {
|
|
18888
|
+
return readIndexedRate2(
|
|
18889
|
+
"buy",
|
|
18890
|
+
rates.buyRate,
|
|
18891
|
+
rates.buyRateUpdatedAt,
|
|
18892
|
+
rates,
|
|
18893
|
+
tokenInSymbol,
|
|
18894
|
+
tokenOutSymbol
|
|
18895
|
+
);
|
|
18896
|
+
}
|
|
18897
|
+
if (tokenInSymbol === rates.quoteTokenSymbol && tokenOutSymbol === rates.baseTokenSymbol) {
|
|
18898
|
+
return readIndexedRate2(
|
|
18899
|
+
"sell",
|
|
18900
|
+
rates.sellRate,
|
|
18901
|
+
rates.sellRateUpdatedAt,
|
|
18902
|
+
rates,
|
|
18903
|
+
tokenInSymbol,
|
|
18904
|
+
tokenOutSymbol
|
|
18905
|
+
);
|
|
18906
|
+
}
|
|
18907
|
+
throw new InvalidIndexedRateError(
|
|
18908
|
+
`indexed pair ${rates.baseTokenSymbol}/${rates.quoteTokenSymbol} does not match ${tokenInSymbol}/${tokenOutSymbol}`
|
|
18909
|
+
);
|
|
18910
|
+
}
|
|
18911
|
+
function readIndexedRate2(side, rate, updatedAt, rates, tokenInSymbol, tokenOutSymbol) {
|
|
18912
|
+
if (!rate || !updatedAt) {
|
|
18913
|
+
throw new IndexedRateUnavailableError({
|
|
18914
|
+
source: rates.sourceChain,
|
|
18915
|
+
destination: rates.destinationChain,
|
|
18916
|
+
tokenIn: tokenInSymbol,
|
|
18917
|
+
tokenOut: tokenOutSymbol,
|
|
18918
|
+
side
|
|
18919
|
+
});
|
|
18920
|
+
}
|
|
18921
|
+
try {
|
|
18922
|
+
const scaledRate = parseUnits(rate, INDEXED_RATE_DECIMALS);
|
|
18923
|
+
if (scaledRate <= 0n || Number.isNaN(updatedAt.getTime())) throw new Error();
|
|
18924
|
+
return { side, rate, scaledRate, updatedAt };
|
|
18925
|
+
} catch {
|
|
18926
|
+
throw new InvalidIndexedRateError(`${side} rate or timestamp is invalid`);
|
|
18927
|
+
}
|
|
18928
|
+
}
|
|
18929
|
+
function quoteWithIndexedRate(params, tokenIn, tokenOut, selectedRate, rates, protocolFeeBps) {
|
|
18930
|
+
const inputUnit = 10n ** BigInt(tokenIn.decimals);
|
|
18931
|
+
const outputUnit = 10n ** BigInt(tokenOut.decimals);
|
|
18932
|
+
if (params.amountIn !== void 0) {
|
|
18933
|
+
const netAmountIn2 = deductProtocolFee(params.amountIn, protocolFeeBps);
|
|
18934
|
+
const amountOut = selectedRate.side === "buy" ? netAmountIn2 * selectedRate.scaledRate * outputUnit / (inputUnit * INDEXED_RATE_SCALE) : netAmountIn2 * outputUnit * INDEXED_RATE_SCALE / (inputUnit * selectedRate.scaledRate);
|
|
18935
|
+
if (amountOut <= 0n) throw new InvalidIndexedRateError("quote rounds down to zero output");
|
|
18936
|
+
return buildResult("EXACT_INPUT", params.amountIn, amountOut, selectedRate, rates, protocolFeeBps);
|
|
18937
|
+
}
|
|
18938
|
+
if (params.amountOut === void 0) throw new Error("Quote amount is missing after validation");
|
|
18939
|
+
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);
|
|
18940
|
+
const amountIn = grossUpForProtocolFee(netAmountIn, protocolFeeBps);
|
|
18941
|
+
return buildResult("EXACT_OUTPUT", amountIn, params.amountOut, selectedRate, rates, protocolFeeBps);
|
|
18942
|
+
}
|
|
18943
|
+
function buildResult(tradeType, amountIn, amountOut, selectedRate, rates, protocolFeeBps) {
|
|
18944
|
+
return {
|
|
18945
|
+
strategy: "indexed_rates",
|
|
18946
|
+
tradeType,
|
|
18947
|
+
amountIn,
|
|
18948
|
+
amountOut,
|
|
18949
|
+
quoteMetadata: {
|
|
18950
|
+
sourceChain: rates.sourceChain,
|
|
18951
|
+
destinationChain: rates.destinationChain,
|
|
18952
|
+
baseTokenSymbol: rates.baseTokenSymbol,
|
|
18953
|
+
quoteTokenSymbol: rates.quoteTokenSymbol,
|
|
18954
|
+
rateSide: selectedRate.side,
|
|
18955
|
+
rate: selectedRate.rate,
|
|
18956
|
+
rateUpdatedAt: selectedRate.updatedAt,
|
|
18957
|
+
protocolFeeBps
|
|
18958
|
+
}
|
|
18959
|
+
};
|
|
18960
|
+
}
|
|
18834
18961
|
|
|
18835
18962
|
// src/protocols/intents/IntentGateway.ts
|
|
18836
18963
|
var CROSS_CHAIN_ORDER_FEE_GAS_PRICE_BUMP_PERCENT = 10n;
|
|
@@ -18905,6 +19032,10 @@ var IntentGateway = class _IntentGateway {
|
|
|
18905
19032
|
this.gasEstimator = gasEstimator;
|
|
18906
19033
|
this._crypto = crypto;
|
|
18907
19034
|
this.quoteStrategies = {
|
|
19035
|
+
indexed_rates: new IndexedRateIntentQuoteStrategy(
|
|
19036
|
+
dest.configService,
|
|
19037
|
+
() => this.requireIndexer().queryClient
|
|
19038
|
+
),
|
|
18908
19039
|
phantom_snapshot: new PhantomSnapshotIntentQuoteStrategy(
|
|
18909
19040
|
dest.configService,
|
|
18910
19041
|
() => this.requireIndexer().queryClient
|
|
@@ -18958,26 +19089,26 @@ var IntentGateway = class _IntentGateway {
|
|
|
18958
19089
|
/**
|
|
18959
19090
|
* Quotes an intent between this gateway's source and destination chains.
|
|
18960
19091
|
*
|
|
18961
|
-
* Uses the latest directional
|
|
18962
|
-
*
|
|
18963
|
-
* requesting a
|
|
19092
|
+
* Uses the indexer's latest aggregate directional pool rate by default. Pass
|
|
19093
|
+
* `strategy: "phantom_snapshot"` or `strategy: "uniswap_v4"` only when
|
|
19094
|
+
* explicitly requesting a legacy quote source. Provide exactly one of
|
|
19095
|
+
* `amountIn` or `amountOut`.
|
|
18964
19096
|
*
|
|
18965
|
-
*
|
|
18966
|
-
*
|
|
19097
|
+
* The gateway's source and destination chains resolve the configured order
|
|
19098
|
+
* tokens; the indexer supplies the depth-weighted pool rate. Returned
|
|
18967
19099
|
* `amountIn`/`amountOut` already account for the gateway's protocol fee
|
|
18968
|
-
* (`quoteMetadata.protocolFeeBps`), which the gateway deducts from order
|
|
18969
|
-
* inputs; use the returned amounts directly when placing the order.
|
|
19100
|
+
* (`quoteMetadata.protocolFeeBps`), which the gateway deducts from order inputs.
|
|
18970
19101
|
*
|
|
18971
19102
|
* @param params - Token pair, amount, and optional strategy/pool overrides.
|
|
18972
19103
|
* @returns The quoted amounts plus strategy-specific metadata.
|
|
18973
19104
|
* @throws {UnsupportedIntentQuoteStrategyError} For unknown strategies.
|
|
18974
19105
|
* @throws {UnsupportedIntentQuotePairError} When the selected strategy does not support the pair.
|
|
18975
|
-
* @throws {
|
|
19106
|
+
* @throws {IndexedRateUnavailableError} When the requested direction has no indexed rate.
|
|
18976
19107
|
*/
|
|
18977
19108
|
async quoteIntent(params) {
|
|
18978
19109
|
const source = { stateMachineId: this.source.config.stateMachineId, client: this.source.client };
|
|
18979
19110
|
const destination = { stateMachineId: this.dest.config.stateMachineId, client: this.dest.client };
|
|
18980
|
-
const strategy = params.strategy ?? "
|
|
19111
|
+
const strategy = params.strategy ?? "indexed_rates";
|
|
18981
19112
|
const handler = this.quoteStrategies[strategy];
|
|
18982
19113
|
if (!handler) throw new UnsupportedIntentQuoteStrategyError(strategy);
|
|
18983
19114
|
return handler.quote({ ...params, strategy }, source, destination);
|
|
@@ -19017,9 +19148,9 @@ var IntentGateway = class _IntentGateway {
|
|
|
19017
19148
|
});
|
|
19018
19149
|
}
|
|
19019
19150
|
/**
|
|
19020
|
-
* Returns
|
|
19021
|
-
* without requiring token addresses. Symbols are matched
|
|
19022
|
-
* chain IDs
|
|
19151
|
+
* Returns aggregate indexed pool buy and sell rates in less-valued quote-token
|
|
19152
|
+
* units without requiring token addresses. Symbols are matched
|
|
19153
|
+
* case-insensitively; chain IDs resolve configured token deployments.
|
|
19023
19154
|
*/
|
|
19024
19155
|
async queryBuyAndSellRates(params) {
|
|
19025
19156
|
const { queryClient } = this.requireIndexer();
|
|
@@ -19667,6 +19798,10 @@ function encodeAcceptedSourceChains(chains2) {
|
|
|
19667
19798
|
function decodeAcceptedSourceChains(paymasterAndData) {
|
|
19668
19799
|
return decodePhantomBidDeclaration(paymasterAndData).acceptedSources;
|
|
19669
19800
|
}
|
|
19801
|
+
var UNISWAP_QUOTE_HAIRCUT_BPS = 30n;
|
|
19802
|
+
function applyUniswapQuoteHaircut(amount) {
|
|
19803
|
+
return amount * (10000n - UNISWAP_QUOTE_HAIRCUT_BPS) / 10000n;
|
|
19804
|
+
}
|
|
19670
19805
|
FILL_ORDER_ABI.find(
|
|
19671
19806
|
(item) => item?.type === "function" && item?.name === "fillOrder"
|
|
19672
19807
|
)?.inputs?.[0];
|
|
@@ -24140,6 +24275,6 @@ async function teleportDot(param_) {
|
|
|
24140
24275
|
return stream;
|
|
24141
24276
|
}
|
|
24142
24277
|
|
|
24143
|
-
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, ChainConfigService, Chains, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, INCLUSION_TIMEOUT_MS, IntentGateway, ABI3 as IntentGatewayABI, IntentOrderStatus, IntentsCoprocessor, InvalidLiquidityIndexerResponseError, InvalidPhantomSnapshotError, IsmpClient, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, OrderStatus, OrderStatusChecker, PACKED_USEROP_TYPEHASH, PLACE_ORDER_SELECTOR, PhantomSnapshotUnavailableError, PharosChain, PolkadotHubChain, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, SubstrateChain, Swap, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, TronChain, USE_ETHERSCAN_CHAINS, UnsupportedIntentQuotePairError, UnsupportedIntentQuoteStrategyError, UnsupportedLiquidityAssetError, UnsupportedLiquidityChainError, WrappedHyperFungibleTokenABI, __test, adjustDecimals, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeAcceptedSourceChains, decodeERC7821ExecuteBatch, decodePhantomBidDeclaration, decodeUserOpScale, deriveHttpUrl, encodeAcceptedSourceChains, encodeERC7821ExecuteBatch, encodeISMPMessage, encodePhantomBidDeclaration, encodeStateMachineId, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getContractCallInputs, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, normalizeAddressForEvmBytes32, normalizeAddressForStateMachine, normalizeEvmAddress, normalizeEvmChainId, normalizeStateMachineId, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, polkadotHubMainnet, poolSlug, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, quoteUniswap, requestCommitmentKey, responseCommitmentKey, retryPromise, sortPoolSymbols, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
24278
|
+
export { ADDRESS_ZERO2 as ADDRESS_ZERO, BundlerMethod, ChainConfigService, Chains, CryptoUtils, DEFAULT_ADDRESS, DEFAULT_GRAFFITI, DOMAIN_TYPEHASH, DUMMY_PRIVATE_KEY, ERC20Method, ERC7821_BATCH_MODE, EvmChain, ABI as EvmHostABI, EvmLanguage, HyperClientStatus, HyperFungibleToken, HyperFungibleTokenABI, INCLUSION_TIMEOUT_MS, IndexedRateUnavailableError, IntentGateway, ABI3 as IntentGatewayABI, IntentOrderStatus, IntentsCoprocessor, InvalidIndexedRateError, InvalidLiquidityIndexerResponseError, InvalidPhantomSnapshotError, IsmpClient, MOCK_ADDRESS, ORDER_V2_PARAM_TYPE, OrderStatus, OrderStatusChecker, PACKED_USEROP_TYPEHASH, PLACE_ORDER_SELECTOR, PhantomSnapshotUnavailableError, PharosChain, PolkadotHubChain, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, RequestKind, RequestStatus, SELECT_SOLVER_TYPEHASH, STATE_COMMITMENTS_SLOT, SubstrateChain, Swap, TESTNET_CHAINS, TeleportStatus, TimeoutStatus, TokenGateway, TronChain, UNISWAP_QUOTE_HAIRCUT_BPS, USE_ETHERSCAN_CHAINS, UnsupportedIntentQuotePairError, UnsupportedIntentQuoteStrategyError, UnsupportedLiquidityAssetError, UnsupportedLiquidityChainError, WrappedHyperFungibleTokenABI, __test, adjustDecimals, applyUniswapQuoteHaircut, bytes20ToBytes32, bytes32ToBytes20, calculateAllowanceMappingLocation, calculateBalanceMappingLocation, chainConfigs, constructRedeemEscrowRequestBody, constructRefundEscrowRequestBody, convertCodecToIGetRequest, convertCodecToIProof, convertIGetRequestToCodec, convertIProofToCodec, convertStateIdToStateMachineId, convertStateMachineEnumToString, convertStateMachineIdToEnum, createEvmChain, createQueryClient, decodeAcceptedSourceChains, decodeERC7821ExecuteBatch, decodePhantomBidDeclaration, decodeUserOpScale, deriveHttpUrl, encodeAcceptedSourceChains, encodeERC7821ExecuteBatch, encodeISMPMessage, encodePhantomBidDeclaration, encodeStateMachineId, encodeUserOpScale, encodeWithdrawalRequest, estimateGasForPost, fetchPrice, fetchSourceProof, generateRootWithProof, getChainId, getConfigByStateMachineId, getContractCallInput, getContractCallInputs, getGasPriceFromEtherscan, getOrFetchStorageSlot, getOrderPlacedFromTx, getPostRequestEventFromTx, getPostResponseEventFromTx, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, getViemChain, hexToString, hyperbridgeAddress, maxBigInt, normalizeAddressForEvmBytes32, normalizeAddressForStateMachine, normalizeEvmAddress, normalizeEvmChainId, normalizeStateMachineId, orderCommitment, parseStateMachineId, pharosAtlantic, pharosMainnet, polkadotAssetHubPaseo, polkadotHubMainnet, poolSlug, postRequestCommitment, queryAssetTeleported, queryGetRequest, queryPostRequest, quoteUniswap, requestCommitmentKey, responseCommitmentKey, retryPromise, sortPoolSymbols, teleport, teleportDot, transformOrderForContract, tronChainIds, tronNile };
|
|
24144
24279
|
//# sourceMappingURL=index.js.map
|
|
24145
24280
|
//# sourceMappingURL=index.js.map
|