@hyperbridge/sdk 2.8.11 → 2.8.12

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.
@@ -20557,8 +20557,52 @@ var IntentGateway = class _IntentGateway {
20557
20557
  }
20558
20558
  }
20559
20559
  };
20560
-
20561
- // src/protocols/intents/phantom-aggregation.ts
20560
+ function rpcFetch() {
20561
+ const f = globalThis.fetch;
20562
+ if (typeof f !== "function") {
20563
+ throw new Error("No fetch available; call setAggregationFetch() before using the aggregation helpers");
20564
+ }
20565
+ return f;
20566
+ }
20567
+ var PhantomRpcError = class extends Error {
20568
+ constructor(message, cause) {
20569
+ super(message);
20570
+ this.cause = cause;
20571
+ this.name = "PhantomRpcError";
20572
+ }
20573
+ cause;
20574
+ };
20575
+ async function rpcCall(url, payload) {
20576
+ let lastErr;
20577
+ for (let attempt = 0; attempt < 4; attempt++) {
20578
+ if (attempt > 0) await new Promise((resolve) => setTimeout(resolve, 150 * attempt));
20579
+ let timer;
20580
+ try {
20581
+ const timeout = new Promise((_, reject) => {
20582
+ timer = setTimeout(() => reject(new Error(`rpc timeout: ${url}`)), 12e3);
20583
+ });
20584
+ const response = await Promise.race([
20585
+ rpcFetch()(url, {
20586
+ method: "POST",
20587
+ headers: { accept: "application/json", "content-type": "application/json" },
20588
+ body: JSON.stringify(payload)
20589
+ }),
20590
+ timeout
20591
+ ]);
20592
+ const body = await response.json();
20593
+ if (body?.error) {
20594
+ lastErr = new Error(`rpc error: ${JSON.stringify(body.error).slice(0, 200)}`);
20595
+ continue;
20596
+ }
20597
+ return body;
20598
+ } catch (err) {
20599
+ lastErr = err;
20600
+ } finally {
20601
+ if (timer) clearTimeout(timer);
20602
+ }
20603
+ }
20604
+ throw new PhantomRpcError(`RPC call failed after 4 attempts: ${url}`, lastErr);
20605
+ }
20562
20606
  var FILL_ORDER_ABI = IntentGatewayV2_default.ABI;
20563
20607
  var DECLARATION_V1 = 1;
20564
20608
  var DECLARATION_V2 = 2;
@@ -20647,15 +20691,35 @@ function decodeAcceptedSourceChains(paymasterAndData) {
20647
20691
  return decodePhantomBidDeclaration(paymasterAndData).acceptedSources;
20648
20692
  }
20649
20693
  var UNISWAP_QUOTE_HAIRCUT_BPS = 10n;
20650
- var PHANTOM_QUOTE_HAIRCUT_BPS = 5n;
20651
20694
  function haircut(amount, bps) {
20652
20695
  return amount * (10000n - bps) / 10000n;
20653
20696
  }
20654
20697
  function applyUniswapQuoteHaircut(amount) {
20655
20698
  return haircut(amount, UNISWAP_QUOTE_HAIRCUT_BPS);
20656
20699
  }
20657
- function applyPhantomQuoteHaircut(amount) {
20658
- return haircut(amount, PHANTOM_QUOTE_HAIRCUT_BPS);
20700
+ var SELECTOR_GATEWAY_PARAMS = "0xcff0ab96";
20701
+ var GATEWAY_PARAMS_WORDS = 6;
20702
+ var GATEWAY_PARAMS_FEE_WORD = 4;
20703
+ async function readProtocolFeeHaircutBps(evmRpcUrl, gatewayAddress) {
20704
+ const result = await rpcCall(evmRpcUrl, {
20705
+ id: 1,
20706
+ jsonrpc: "2.0",
20707
+ method: "eth_call",
20708
+ params: [{ to: gatewayAddress, data: SELECTOR_GATEWAY_PARAMS }, "latest"]
20709
+ });
20710
+ const hex = result.result;
20711
+ if (typeof hex !== "string" || hex.length < 2 + 64 * GATEWAY_PARAMS_WORDS) {
20712
+ throw new PhantomRpcError(`IntentGateway.params() returned no usable result from ${gatewayAddress} on ${evmRpcUrl}`);
20713
+ }
20714
+ const start = 2 + 64 * GATEWAY_PARAMS_FEE_WORD;
20715
+ const protocolFeeBps = BigInt(`0x${hex.slice(start, start + 64)}`);
20716
+ if (protocolFeeBps >= 10000n) {
20717
+ throw new PhantomRpcError(`IntentGateway ${gatewayAddress} reports an implausible protocol fee: ${protocolFeeBps} bps`);
20718
+ }
20719
+ return protocolFeeBps;
20720
+ }
20721
+ function applyProtocolFeeHaircut(amount, protocolFeeBps) {
20722
+ return haircut(amount, protocolFeeBps);
20659
20723
  }
20660
20724
  FILL_ORDER_ABI.find(
20661
20725
  (item) => item?.type === "function" && item?.name === "fillOrder"
@@ -25165,7 +25229,6 @@ exports.ORDER_V2_PARAM_TYPE = ORDER_V2_PARAM_TYPE;
25165
25229
  exports.OrderStatus = OrderStatus;
25166
25230
  exports.OrderStatusChecker = OrderStatusChecker;
25167
25231
  exports.PACKED_USEROP_TYPEHASH = PACKED_USEROP_TYPEHASH;
25168
- exports.PHANTOM_QUOTE_HAIRCUT_BPS = PHANTOM_QUOTE_HAIRCUT_BPS;
25169
25232
  exports.PLACE_ORDER_SELECTOR = PLACE_ORDER_SELECTOR;
25170
25233
  exports.PhantomSnapshotUnavailableError = PhantomSnapshotUnavailableError;
25171
25234
  exports.PharosChain = PharosChain;
@@ -25194,7 +25257,7 @@ exports.UnsupportedLiquidityChainError = UnsupportedLiquidityChainError;
25194
25257
  exports.WrappedHyperFungibleTokenABI = WrappedHyperFungibleTokenABI;
25195
25258
  exports.__test = __test;
25196
25259
  exports.adjustDecimals = adjustDecimals;
25197
- exports.applyPhantomQuoteHaircut = applyPhantomQuoteHaircut;
25260
+ exports.applyProtocolFeeHaircut = applyProtocolFeeHaircut;
25198
25261
  exports.applyUniswapQuoteHaircut = applyUniswapQuoteHaircut;
25199
25262
  exports.bytes20ToBytes32 = bytes20ToBytes32;
25200
25263
  exports.bytes32ToBytes20 = bytes32ToBytes20;
@@ -25265,6 +25328,7 @@ exports.queryAssetTeleported = queryAssetTeleported;
25265
25328
  exports.queryGetRequest = queryGetRequest;
25266
25329
  exports.queryPostRequest = queryPostRequest;
25267
25330
  exports.quoteUniswap = quoteUniswap;
25331
+ exports.readProtocolFeeHaircutBps = readProtocolFeeHaircutBps;
25268
25332
  exports.requestCommitmentKey = requestCommitmentKey;
25269
25333
  exports.resetFillOptionsVersionCache = resetFillOptionsVersionCache;
25270
25334
  exports.responseCommitmentKey = responseCommitmentKey;