@hyperbridge/sdk 2.7.2 → 2.8.2
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 +524 -407
- package/dist/browser/index.js +178 -50
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +178 -48
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +3 -3
- package/dist/node/index.d.ts +3 -3
- package/dist/node/index.js +178 -50
- package/dist/node/index.js.map +1 -1
- package/dist/node/{IntentGatewayV2-MxUcNZNs.d.cts → intents-helpers-D_km9I2f.d.cts} +1943 -242
- package/dist/node/{IntentGatewayV2-MxUcNZNs.d.ts → intents-helpers-D_km9I2f.d.ts} +1943 -242
- package/dist/node/intents-helpers.cjs +124 -19
- package/dist/node/intents-helpers.cjs.map +1 -1
- package/dist/node/intents-helpers.d.cts +3 -1506
- package/dist/node/intents-helpers.d.ts +3 -1506
- package/dist/node/intents-helpers.js +122 -21
- package/dist/node/intents-helpers.js.map +1 -1
- package/package.json +1 -1
|
@@ -1610,6 +1610,24 @@ var ABI2 = [
|
|
|
1610
1610
|
internalType: "uint256"
|
|
1611
1611
|
}
|
|
1612
1612
|
]
|
|
1613
|
+
},
|
|
1614
|
+
{
|
|
1615
|
+
name: "predispatchCall",
|
|
1616
|
+
type: "bytes",
|
|
1617
|
+
indexed: false,
|
|
1618
|
+
internalType: "bytes"
|
|
1619
|
+
},
|
|
1620
|
+
{
|
|
1621
|
+
name: "outputCall",
|
|
1622
|
+
type: "bytes",
|
|
1623
|
+
indexed: false,
|
|
1624
|
+
internalType: "bytes"
|
|
1625
|
+
},
|
|
1626
|
+
{
|
|
1627
|
+
name: "graffiti",
|
|
1628
|
+
type: "bytes32",
|
|
1629
|
+
indexed: false,
|
|
1630
|
+
internalType: "bytes32"
|
|
1613
1631
|
}
|
|
1614
1632
|
],
|
|
1615
1633
|
anonymous: false
|
|
@@ -2340,6 +2358,49 @@ async function rpcCall(url, payload) {
|
|
|
2340
2358
|
throw lastErr;
|
|
2341
2359
|
}
|
|
2342
2360
|
var FILL_ORDER_ABI = IntentGatewayV2_default.ABI;
|
|
2361
|
+
var DECLARATION_VERSION = 1;
|
|
2362
|
+
var MAX_DECLARED_CHAINS = 255;
|
|
2363
|
+
function encodeAcceptedSourceChains(chains) {
|
|
2364
|
+
if (chains.length > MAX_DECLARED_CHAINS) {
|
|
2365
|
+
throw new Error(`Cannot declare more than ${MAX_DECLARED_CHAINS} source chains`);
|
|
2366
|
+
}
|
|
2367
|
+
const bytes = [DECLARATION_VERSION, chains.length];
|
|
2368
|
+
for (const chain of chains) {
|
|
2369
|
+
const encoded = util.stringToU8a(chain);
|
|
2370
|
+
if (encoded.length === 0 || encoded.length > 255) {
|
|
2371
|
+
throw new Error(`Invalid state machine id in source chain declaration: ${chain}`);
|
|
2372
|
+
}
|
|
2373
|
+
bytes.push(encoded.length, ...encoded);
|
|
2374
|
+
}
|
|
2375
|
+
return util.u8aToHex(new Uint8Array(bytes));
|
|
2376
|
+
}
|
|
2377
|
+
function decodeAcceptedSourceChains(paymasterAndData) {
|
|
2378
|
+
if (!paymasterAndData || !util.isHex(paymasterAndData)) return null;
|
|
2379
|
+
const bytes = util.hexToU8a(paymasterAndData);
|
|
2380
|
+
if (bytes.length < 2 || bytes[0] !== DECLARATION_VERSION) return null;
|
|
2381
|
+
const count = bytes[1];
|
|
2382
|
+
const chains = [];
|
|
2383
|
+
let offset = 2;
|
|
2384
|
+
for (let entry = 0; entry < count; entry++) {
|
|
2385
|
+
if (offset >= bytes.length) return null;
|
|
2386
|
+
const length = bytes[offset];
|
|
2387
|
+
offset += 1;
|
|
2388
|
+
if (length === 0 || offset + length > bytes.length) return null;
|
|
2389
|
+
chains.push(util.u8aToString(bytes.subarray(offset, offset + length)));
|
|
2390
|
+
offset += length;
|
|
2391
|
+
}
|
|
2392
|
+
if (offset !== bytes.length) return null;
|
|
2393
|
+
return chains;
|
|
2394
|
+
}
|
|
2395
|
+
function zipFillLegs(assets, outputs) {
|
|
2396
|
+
return assets.map((asset, index) => {
|
|
2397
|
+
const rawAmount = outputs[index]?.amount;
|
|
2398
|
+
return {
|
|
2399
|
+
outputToken: asset.token,
|
|
2400
|
+
solverAmount: rawAmount === void 0 || rawAmount === null ? 0n : BigInt(rawAmount.toString())
|
|
2401
|
+
};
|
|
2402
|
+
});
|
|
2403
|
+
}
|
|
2343
2404
|
function weightedMedian(entries) {
|
|
2344
2405
|
const sorted = [...entries].sort((a, b) => a.price < b.price ? -1 : a.price > b.price ? 1 : 0);
|
|
2345
2406
|
const totalWeight = sorted.reduce((acc, e) => e.weight > 0n ? acc + e.weight : acc, 0n);
|
|
@@ -2365,10 +2426,10 @@ function extractFillData(callData, gatewayAddress) {
|
|
|
2365
2426
|
if (decoded.functionName !== "fillOrder" || !decoded.args || decoded.args.length < 2) continue;
|
|
2366
2427
|
const order = decoded.args[0];
|
|
2367
2428
|
const options = decoded.args[1];
|
|
2368
|
-
const
|
|
2429
|
+
const assets = order?.output?.assets;
|
|
2369
2430
|
const outputs = options?.outputs;
|
|
2370
|
-
if (!
|
|
2371
|
-
return { order, options,
|
|
2431
|
+
if (!assets?.length || !outputs?.length) continue;
|
|
2432
|
+
return { order, options, legs: zipFillLegs(assets, outputs) };
|
|
2372
2433
|
} catch {
|
|
2373
2434
|
continue;
|
|
2374
2435
|
}
|
|
@@ -2486,13 +2547,25 @@ async function getTotalSolverBalance(evmRpcUrl, chain, token, solver, yieldVault
|
|
|
2486
2547
|
);
|
|
2487
2548
|
return vaultBalances.reduce((acc, b) => acc + b, raw);
|
|
2488
2549
|
}
|
|
2489
|
-
|
|
2550
|
+
function memoizedSolverBalance(yieldVaults) {
|
|
2551
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2552
|
+
return (evmRpcUrl, chain, token, solver) => {
|
|
2553
|
+
const key = `${chain}|${token.toLowerCase()}|${solver.toLowerCase()}`;
|
|
2554
|
+
let pending = cache.get(key);
|
|
2555
|
+
if (!pending) {
|
|
2556
|
+
pending = getTotalSolverBalance(evmRpcUrl, chain, token, solver, yieldVaults);
|
|
2557
|
+
cache.set(key, pending);
|
|
2558
|
+
}
|
|
2559
|
+
return pending;
|
|
2560
|
+
};
|
|
2561
|
+
}
|
|
2562
|
+
async function sweepSolverLiquidity(evmRpcUrls, yieldVaults, solver, getBalance) {
|
|
2490
2563
|
const balances = [];
|
|
2491
2564
|
for (const [chain, tokens] of Object.entries(yieldVaults)) {
|
|
2492
2565
|
const url = evmRpcUrls[chain];
|
|
2493
2566
|
if (!url) continue;
|
|
2494
2567
|
for (const token of Object.keys(tokens)) {
|
|
2495
|
-
const balance = await
|
|
2568
|
+
const balance = await getBalance(url, chain, token, solver);
|
|
2496
2569
|
if (balance === 0n) continue;
|
|
2497
2570
|
balances.push({ solver, chain, tokenAddress: token, balance });
|
|
2498
2571
|
}
|
|
@@ -2519,7 +2592,8 @@ async function aggregatePhantomBids(params) {
|
|
|
2519
2592
|
}
|
|
2520
2593
|
const bids = await fetchBidsForOrder(nodeUrl, commitment);
|
|
2521
2594
|
if (bids.length === 0) return null;
|
|
2522
|
-
const
|
|
2595
|
+
const getBalance = params.getBalance ?? memoizedSolverBalance(yieldVaults);
|
|
2596
|
+
const quotesByLeg = /* @__PURE__ */ new Map();
|
|
2523
2597
|
const lpBalances = [];
|
|
2524
2598
|
const countedSolvers = /* @__PURE__ */ new Set();
|
|
2525
2599
|
for (const bid of bids) {
|
|
@@ -2557,39 +2631,70 @@ async function aggregatePhantomBids(params) {
|
|
|
2557
2631
|
continue;
|
|
2558
2632
|
}
|
|
2559
2633
|
countedSolvers.add(normalizedSolver);
|
|
2560
|
-
const
|
|
2561
|
-
const
|
|
2562
|
-
|
|
2563
|
-
|
|
2634
|
+
const acceptedSources = decodeAcceptedSourceChains(decoded.paymasterAndData);
|
|
2635
|
+
const quotedLegs = [...fillData.legs.entries()].filter(([, leg]) => leg.solverAmount !== 0n);
|
|
2636
|
+
const weights = await Promise.all(
|
|
2637
|
+
// Price influence: the solver's liquidity in THIS leg's output token on the destination
|
|
2638
|
+
// chain, so a leg is weighted by the inventory that actually backs it.
|
|
2639
|
+
quotedLegs.map(([, leg]) => getBalance(destUrl, chain, toAddress(leg.outputToken), solver))
|
|
2640
|
+
);
|
|
2641
|
+
for (const [position, [legIndex, leg]] of quotedLegs.entries()) {
|
|
2642
|
+
const weight = weights[position];
|
|
2643
|
+
const entry = quotesByLeg.get(legIndex) ?? { outputToken: leg.outputToken, quotes: [], bidders: [] };
|
|
2644
|
+
entry.quotes.push({ price: leg.solverAmount, weight });
|
|
2645
|
+
entry.bidders.push({ solver: normalizedSolver, weight, acceptedSources });
|
|
2646
|
+
quotesByLeg.set(legIndex, entry);
|
|
2647
|
+
}
|
|
2648
|
+
lpBalances.push(...await sweepSolverLiquidity(evmRpcUrls, yieldVaults, solver, getBalance));
|
|
2564
2649
|
} catch (err) {
|
|
2565
2650
|
logger?.warn({ err, filler: bid.filler }, "Failed to process bid for price snapshot");
|
|
2566
2651
|
}
|
|
2567
2652
|
}
|
|
2568
|
-
if (
|
|
2569
|
-
const
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2653
|
+
if (quotesByLeg.size === 0) return null;
|
|
2654
|
+
const legs = [...quotesByLeg.entries()].sort(([a], [b]) => a - b).flatMap(([legIndex, { outputToken, quotes, bidders }]) => {
|
|
2655
|
+
const backedQuotes = quotes.filter((quote) => quote.weight > 0n);
|
|
2656
|
+
const backedBidders = bidders.filter((bidder) => bidder.weight > 0n);
|
|
2657
|
+
if (backedQuotes.length === 0) {
|
|
2658
|
+
logger?.warn(
|
|
2659
|
+
{ commitment, chain, legIndex, outputToken, quotes: quotes.length },
|
|
2660
|
+
"Dropping phantom leg: no bidder holds the output token on this chain, so no quote is backed"
|
|
2661
|
+
);
|
|
2662
|
+
return [];
|
|
2663
|
+
}
|
|
2664
|
+
const medianPrice = weightedMedian(backedQuotes);
|
|
2665
|
+
return [
|
|
2666
|
+
{
|
|
2667
|
+
legIndex,
|
|
2668
|
+
outputToken,
|
|
2669
|
+
lowestPrice: medianPrice,
|
|
2670
|
+
highestPrice: medianPrice,
|
|
2671
|
+
medianPrice,
|
|
2672
|
+
bidCount: backedQuotes.length,
|
|
2673
|
+
bidders: backedBidders
|
|
2674
|
+
}
|
|
2675
|
+
];
|
|
2676
|
+
});
|
|
2677
|
+
return { legs, lpBalances };
|
|
2577
2678
|
}
|
|
2578
2679
|
|
|
2579
2680
|
exports.ENTRY_POINT_V08_ADDRESS = ENTRY_POINT_V08_ADDRESS;
|
|
2580
2681
|
exports.FILL_ORDER_ABI = FILL_ORDER_ABI;
|
|
2581
2682
|
exports.IntentGatewayV2 = IntentGatewayV2_default;
|
|
2582
2683
|
exports.aggregatePhantomBids = aggregatePhantomBids;
|
|
2684
|
+
exports.decodeAcceptedSourceChains = decodeAcceptedSourceChains;
|
|
2583
2685
|
exports.decodeERC7821ExecuteBatch = decodeERC7821ExecuteBatch;
|
|
2584
2686
|
exports.decodeUserOpScale = decodeUserOpScale;
|
|
2687
|
+
exports.encodeAcceptedSourceChains = encodeAcceptedSourceChains;
|
|
2585
2688
|
exports.encodeERC7821ExecuteBatch = encodeERC7821ExecuteBatch;
|
|
2586
2689
|
exports.encodeUserOpScale = encodeUserOpScale;
|
|
2587
2690
|
exports.extractFillData = extractFillData;
|
|
2588
2691
|
exports.fetchBidsForOrder = fetchBidsForOrder;
|
|
2692
|
+
exports.memoizedSolverBalance = memoizedSolverBalance;
|
|
2589
2693
|
exports.orderCommitmentFromDecoded = orderCommitmentFromDecoded;
|
|
2590
2694
|
exports.recoverBidSignerViem = recoverBidSignerViem;
|
|
2591
2695
|
exports.setAggregationFetch = setAggregationFetch;
|
|
2592
2696
|
exports.splitBidSignature = splitBidSignature;
|
|
2593
2697
|
exports.weightedMedian = weightedMedian;
|
|
2698
|
+
exports.zipFillLegs = zipFillLegs;
|
|
2594
2699
|
//# sourceMappingURL=intents-helpers.cjs.map
|
|
2595
2700
|
//# sourceMappingURL=intents-helpers.cjs.map
|