@hyperbridge/sdk 2.8.12 → 2.8.13

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.
@@ -1,4 +1,4 @@
1
- export { bR as AggregationLogger, bS as BidNonceKeyFn, bT as BidSignature, bU as ENTRY_POINT_V08_ADDRESS, bV as FILL_ORDER_ABI, ai as FILL_ORDER_V1_ABI, bW as FetchLike, bX as FillData, bY as HexString, bZ as IntentGatewayV2, b_ as LpBalance, b$ as OrderCommitmentFn, c0 as PhantomAggregation, c1 as PhantomLegAggregation, c2 as PhantomLegBidder, c3 as PoolAndPositionInfo, c4 as RecoverBidSigner, c5 as RpcBidInfo, c6 as SolverBalanceReader, c7 as SolverV4Position, be as UNISWAP_QUOTE_HAIRCUT_BPS, c8 as UniswapV4Contracts, c9 as V4PositionState, ca as YieldVaultMap, cb as aggregatePhantomBids, bg as applyProtocolFeeHaircut, bh as applyUniswapQuoteHaircut, bq as decodeAcceptedSourceChains, br as decodeERC7821ExecuteBatch, bt as decodePhantomBidDeclaration, bu as decodeUserOpScale, bw as encodeAcceptedSourceChains, bx as encodeERC7821ExecuteBatch, bA as encodePhantomBidDeclaration, bB as encodeUserOpScale, cc as extractFillData, cd as fetchBidsForOrder, ce as getTotalSolverBalance, cf as memoizedSolverBalance, cg as orderCommitmentFromDecoded, bL as poolSlug, ch as positionAmountOfToken, bM as readProtocolFeeHaircutBps, ci as readV4Position, cj as recoverBidSignerViem, ck as setAggregationFetch, bO as sortPoolSymbols, cl as splitBidSignature, cm as weightedMedian, cn as zipFillLegs } from './intents-helpers-C9PJp8rx.cjs';
1
+ export { bW as AggregationLogger, bX as BidNonceKeyFn, bY as BidSignature, bZ as ENTRY_POINT_V08_ADDRESS, b_ as FILL_ORDER_ABI, ai as FILL_ORDER_V1_ABI, b$ as FetchLike, c0 as FillData, c1 as HexString, c2 as IntentGatewayV2, c3 as LpBalance, c4 as OrderCommitmentFn, aN as PERMIT2_SPONSORSHIP_BYTES, c5 as PhantomAggregation, aR as PhantomBidDeclaration, aT as PhantomBidPaymasterAndData, aU as PhantomBidSponsorship, c6 as PhantomLegAggregation, c7 as PhantomLegBidder, c8 as PoolAndPositionInfo, c9 as RecoverBidSigner, ca as RpcBidInfo, cb as SolverBalanceReader, cc as SolverV4Position, bh as UNISWAP_QUOTE_HAIRCUT_BPS, cd as UniswapV4Contracts, ce as V4PositionState, cf as YieldVaultMap, cg as aggregatePhantomBids, bj as applyProtocolFeeHaircut, bk as applyUniswapQuoteHaircut, bt as decodeAcceptedSourceChains, bu as decodeERC7821ExecuteBatch, bw as decodePhantomBidDeclaration, bx as decodePhantomBidPaymasterAndData, by as decodeUserOpScale, bA as encodeAcceptedSourceChains, bB as encodeERC7821ExecuteBatch, bE as encodePhantomBidDeclaration, bF as encodePhantomBidPaymasterAndData, bG as encodeUserOpScale, ch as extractFillData, ci as fetchBidsForOrder, cj as getTotalSolverBalance, ck as memoizedSolverBalance, cl as orderCommitmentFromDecoded, bQ as poolSlug, cm as positionAmountOfToken, bR as readProtocolFeeHaircutBps, cn as readV4Position, co as recoverBidSignerViem, cp as setAggregationFetch, bT as sortPoolSymbols, cq as splitBidSignature, cr as weightedMedian, cs as zipFillLegs } from './intents-helpers-fntBuoYM.cjs';
2
2
  import 'consola';
3
3
  import 'decimal.js';
4
4
  import 'graphql-request';
@@ -1,4 +1,4 @@
1
- export { bR as AggregationLogger, bS as BidNonceKeyFn, bT as BidSignature, bU as ENTRY_POINT_V08_ADDRESS, bV as FILL_ORDER_ABI, ai as FILL_ORDER_V1_ABI, bW as FetchLike, bX as FillData, bY as HexString, bZ as IntentGatewayV2, b_ as LpBalance, b$ as OrderCommitmentFn, c0 as PhantomAggregation, c1 as PhantomLegAggregation, c2 as PhantomLegBidder, c3 as PoolAndPositionInfo, c4 as RecoverBidSigner, c5 as RpcBidInfo, c6 as SolverBalanceReader, c7 as SolverV4Position, be as UNISWAP_QUOTE_HAIRCUT_BPS, c8 as UniswapV4Contracts, c9 as V4PositionState, ca as YieldVaultMap, cb as aggregatePhantomBids, bg as applyProtocolFeeHaircut, bh as applyUniswapQuoteHaircut, bq as decodeAcceptedSourceChains, br as decodeERC7821ExecuteBatch, bt as decodePhantomBidDeclaration, bu as decodeUserOpScale, bw as encodeAcceptedSourceChains, bx as encodeERC7821ExecuteBatch, bA as encodePhantomBidDeclaration, bB as encodeUserOpScale, cc as extractFillData, cd as fetchBidsForOrder, ce as getTotalSolverBalance, cf as memoizedSolverBalance, cg as orderCommitmentFromDecoded, bL as poolSlug, ch as positionAmountOfToken, bM as readProtocolFeeHaircutBps, ci as readV4Position, cj as recoverBidSignerViem, ck as setAggregationFetch, bO as sortPoolSymbols, cl as splitBidSignature, cm as weightedMedian, cn as zipFillLegs } from './intents-helpers-C9PJp8rx.js';
1
+ export { bW as AggregationLogger, bX as BidNonceKeyFn, bY as BidSignature, bZ as ENTRY_POINT_V08_ADDRESS, b_ as FILL_ORDER_ABI, ai as FILL_ORDER_V1_ABI, b$ as FetchLike, c0 as FillData, c1 as HexString, c2 as IntentGatewayV2, c3 as LpBalance, c4 as OrderCommitmentFn, aN as PERMIT2_SPONSORSHIP_BYTES, c5 as PhantomAggregation, aR as PhantomBidDeclaration, aT as PhantomBidPaymasterAndData, aU as PhantomBidSponsorship, c6 as PhantomLegAggregation, c7 as PhantomLegBidder, c8 as PoolAndPositionInfo, c9 as RecoverBidSigner, ca as RpcBidInfo, cb as SolverBalanceReader, cc as SolverV4Position, bh as UNISWAP_QUOTE_HAIRCUT_BPS, cd as UniswapV4Contracts, ce as V4PositionState, cf as YieldVaultMap, cg as aggregatePhantomBids, bj as applyProtocolFeeHaircut, bk as applyUniswapQuoteHaircut, bt as decodeAcceptedSourceChains, bu as decodeERC7821ExecuteBatch, bw as decodePhantomBidDeclaration, bx as decodePhantomBidPaymasterAndData, by as decodeUserOpScale, bA as encodeAcceptedSourceChains, bB as encodeERC7821ExecuteBatch, bE as encodePhantomBidDeclaration, bF as encodePhantomBidPaymasterAndData, bG as encodeUserOpScale, ch as extractFillData, ci as fetchBidsForOrder, cj as getTotalSolverBalance, ck as memoizedSolverBalance, cl as orderCommitmentFromDecoded, bQ as poolSlug, cm as positionAmountOfToken, bR as readProtocolFeeHaircutBps, cn as readV4Position, co as recoverBidSignerViem, cp as setAggregationFetch, bT as sortPoolSymbols, cq as splitBidSignature, cr as weightedMedian, cs as zipFillLegs } from './intents-helpers-fntBuoYM.js';
2
2
  import 'consola';
3
3
  import 'decimal.js';
4
4
  import 'graphql-request';
@@ -1,6 +1,6 @@
1
1
  import { keccak256, toHex, encodeAbiParameters, encodeFunctionData, decodeFunctionData, decodeAbiParameters, numberToBytes, bytesToBigInt, recoverAddress, parseAbiParameters, concat, encodePacked, pad } from 'viem';
2
2
  import '@polkadot/api';
3
- import { u8aToHex, u8aConcat, hexToU8a, stringToU8a, isHex, u8aToString } from '@polkadot/util';
3
+ import { u8aToHex, u8aConcat, hexToU8a, isHex } from '@polkadot/util';
4
4
  import { xxhashAsU8a } from '@polkadot/util-crypto';
5
5
  import { Struct, Vector, u8, Bytes } from 'scale-ts';
6
6
  import 'p-queue';
@@ -2729,8 +2729,67 @@ async function rpcCall(url, payload) {
2729
2729
  var FILL_ORDER_ABI = IntentGatewayV2_default.ABI;
2730
2730
  var DECLARATION_V1 = 1;
2731
2731
  var DECLARATION_V2 = 2;
2732
+ var PAYMASTER_ADDRESS_BYTES = 20;
2733
+ var PAYMASTER_GAS_LIMIT_BYTES = 16;
2734
+ var PAYMASTER_DATA_OFFSET = PAYMASTER_ADDRESS_BYTES + 2 * PAYMASTER_GAS_LIMIT_BYTES;
2735
+ var SIMPLEX_MODE_PERMIT2 = 2;
2736
+ var PERMIT2_DATA_BYTES = 1 + 20 + 32 + 32 + 32 + 1 + 32 + 32;
2737
+ var PERMIT2_SPONSORSHIP_BYTES = PAYMASTER_DATA_OFFSET + PERMIT2_DATA_BYTES;
2732
2738
  var MAX_DECLARED_ENTRIES = 255;
2733
2739
  var MAX_TOKEN_ID_BYTES = 32;
2740
+ function utf8Encode(text) {
2741
+ const bytes = [];
2742
+ for (const char of text) {
2743
+ const codePoint = char.codePointAt(0);
2744
+ if (codePoint < 128) bytes.push(codePoint);
2745
+ else if (codePoint < 2048) bytes.push(192 | codePoint >> 6, 128 | codePoint & 63);
2746
+ else if (codePoint < 65536) {
2747
+ bytes.push(224 | codePoint >> 12, 128 | codePoint >> 6 & 63, 128 | codePoint & 63);
2748
+ } else {
2749
+ bytes.push(
2750
+ 240 | codePoint >> 18,
2751
+ 128 | codePoint >> 12 & 63,
2752
+ 128 | codePoint >> 6 & 63,
2753
+ 128 | codePoint & 63
2754
+ );
2755
+ }
2756
+ }
2757
+ return bytes;
2758
+ }
2759
+ function utf8Decode(bytes) {
2760
+ let text = "";
2761
+ for (let offset = 0; offset < bytes.length; ) {
2762
+ const lead = bytes[offset];
2763
+ let codePoint;
2764
+ let continuations;
2765
+ if (lead < 128) {
2766
+ codePoint = lead;
2767
+ continuations = 0;
2768
+ } else if ((lead & 224) === 192) {
2769
+ codePoint = lead & 31;
2770
+ continuations = 1;
2771
+ } else if ((lead & 240) === 224) {
2772
+ codePoint = lead & 15;
2773
+ continuations = 2;
2774
+ } else if ((lead & 248) === 240) {
2775
+ codePoint = lead & 7;
2776
+ continuations = 3;
2777
+ } else {
2778
+ return null;
2779
+ }
2780
+ if (offset + continuations >= bytes.length) return null;
2781
+ for (let index = 1; index <= continuations; index++) {
2782
+ const byte = bytes[offset + index];
2783
+ if ((byte & 192) !== 128) return null;
2784
+ codePoint = codePoint << 6 | byte & 63;
2785
+ }
2786
+ const overlong = continuations === 1 && codePoint < 128 || continuations === 2 && codePoint < 2048 || continuations === 3 && codePoint < 65536;
2787
+ if (overlong || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343) return null;
2788
+ text += String.fromCodePoint(codePoint);
2789
+ offset += continuations + 1;
2790
+ }
2791
+ return text;
2792
+ }
2734
2793
  function tokenIdToBytes(tokenId) {
2735
2794
  if (tokenId < 0n) throw new Error(`Uniswap V4 tokenId cannot be negative: ${tokenId}`);
2736
2795
  const bytes = [];
@@ -2753,7 +2812,7 @@ function encodePhantomBidDeclaration(declaration) {
2753
2812
  const version = positions.length > 0 ? DECLARATION_V2 : DECLARATION_V1;
2754
2813
  const bytes = [version, chains.length];
2755
2814
  for (const chain of chains) {
2756
- const encoded = stringToU8a(chain);
2815
+ const encoded = utf8Encode(chain);
2757
2816
  if (encoded.length === 0 || encoded.length > 255) {
2758
2817
  throw new Error(`Invalid state machine id in source chain declaration: ${chain}`);
2759
2818
  }
@@ -2771,42 +2830,94 @@ function encodePhantomBidDeclaration(declaration) {
2771
2830
  }
2772
2831
  return u8aToHex(new Uint8Array(bytes));
2773
2832
  }
2774
- function decodePhantomBidDeclaration(paymasterAndData) {
2775
- const absent = { acceptedSources: null, uniswapV4Positions: [] };
2776
- if (!paymasterAndData || !isHex(paymasterAndData)) return absent;
2777
- const bytes = hexToU8a(paymasterAndData);
2778
- if (bytes.length < 2) return absent;
2779
- const version = bytes[0];
2780
- if (version !== DECLARATION_V1 && version !== DECLARATION_V2) return absent;
2833
+ function parseDeclaration(bytes, start) {
2834
+ if (bytes.length - start < 2) return null;
2835
+ const version = bytes[start];
2836
+ if (version !== DECLARATION_V1 && version !== DECLARATION_V2) return null;
2781
2837
  const chains = [];
2782
- let offset = 2;
2783
- for (let entry = 0; entry < bytes[1]; entry++) {
2784
- if (offset >= bytes.length) return absent;
2838
+ let offset = start + 2;
2839
+ for (let entry = 0; entry < bytes[start + 1]; entry++) {
2840
+ if (offset >= bytes.length) return null;
2785
2841
  const length = bytes[offset];
2786
2842
  offset += 1;
2787
- if (length === 0 || offset + length > bytes.length) return absent;
2788
- chains.push(u8aToString(bytes.subarray(offset, offset + length)));
2843
+ if (length === 0 || offset + length > bytes.length) return null;
2844
+ const chain = utf8Decode(bytes.subarray(offset, offset + length));
2845
+ if (chain === null) return null;
2846
+ chains.push(chain);
2789
2847
  offset += length;
2790
2848
  }
2791
2849
  const positions = [];
2792
2850
  if (version === DECLARATION_V2) {
2793
- if (offset >= bytes.length) return absent;
2851
+ if (offset >= bytes.length) return null;
2794
2852
  const count = bytes[offset];
2795
2853
  offset += 1;
2796
2854
  for (let entry = 0; entry < count; entry++) {
2797
- if (offset >= bytes.length) return absent;
2855
+ if (offset >= bytes.length) return null;
2798
2856
  const length = bytes[offset];
2799
2857
  offset += 1;
2800
- if (length === 0 || length > MAX_TOKEN_ID_BYTES || offset + length > bytes.length) return absent;
2801
- let tokenId = 0n;
2802
- for (const byte of bytes.subarray(offset, offset + length)) tokenId = tokenId << 8n | BigInt(byte);
2803
- positions.push(tokenId);
2858
+ if (length === 0 || length > MAX_TOKEN_ID_BYTES || offset + length > bytes.length) return null;
2859
+ positions.push(bytesToBigInt2(bytes.subarray(offset, offset + length)));
2804
2860
  offset += length;
2805
2861
  }
2806
2862
  }
2807
- if (offset !== bytes.length) return absent;
2863
+ if (offset !== bytes.length) return null;
2808
2864
  return { acceptedSources: chains, uniswapV4Positions: positions };
2809
2865
  }
2866
+ function bytesToBigInt2(bytes) {
2867
+ let value = 0n;
2868
+ for (const byte of bytes) value = value << 8n | BigInt(byte);
2869
+ return value;
2870
+ }
2871
+ function bytesToAddress(bytes) {
2872
+ return u8aToHex(bytes);
2873
+ }
2874
+ function hasPermit2Sponsorship(bytes) {
2875
+ return bytes.length >= PERMIT2_SPONSORSHIP_BYTES && bytes[PAYMASTER_DATA_OFFSET] === SIMPLEX_MODE_PERMIT2;
2876
+ }
2877
+ function parseSponsorship(bytes) {
2878
+ let offset = 0;
2879
+ const take = (length) => {
2880
+ const slice = bytes.subarray(offset, offset + length);
2881
+ offset += length;
2882
+ return slice;
2883
+ };
2884
+ const paymaster = bytesToAddress(take(PAYMASTER_ADDRESS_BYTES));
2885
+ take(2 * PAYMASTER_GAS_LIMIT_BYTES);
2886
+ take(1);
2887
+ const token = bytesToAddress(take(20));
2888
+ const permitAmount = bytesToBigInt2(take(32));
2889
+ const nonce = bytesToBigInt2(take(32));
2890
+ const deadline = bytesToBigInt2(take(32));
2891
+ return { paymaster, token, permitAmount, nonce, deadline };
2892
+ }
2893
+ var absentDeclaration = () => ({ acceptedSources: null, uniswapV4Positions: [] });
2894
+ function decodePhantomBidPaymasterAndData(paymasterAndData) {
2895
+ const none = { mode: "none", declaration: absentDeclaration(), sponsorship: null };
2896
+ if (!paymasterAndData || !isHex(paymasterAndData)) return none;
2897
+ const bytes = hexToU8a(paymasterAndData);
2898
+ const bare = parseDeclaration(bytes, 0);
2899
+ if (bare) return { mode: "declaration", declaration: bare, sponsorship: null };
2900
+ if (!hasPermit2Sponsorship(bytes)) return none;
2901
+ const sponsorship = parseSponsorship(bytes);
2902
+ const tail = bytes.length > PERMIT2_SPONSORSHIP_BYTES ? parseDeclaration(bytes, PERMIT2_SPONSORSHIP_BYTES) : null;
2903
+ return { mode: "permit2", declaration: tail ?? absentDeclaration(), sponsorship };
2904
+ }
2905
+ function decodePhantomBidDeclaration(paymasterAndData) {
2906
+ return decodePhantomBidPaymasterAndData(paymasterAndData).declaration;
2907
+ }
2908
+ function encodePhantomBidPaymasterAndData(bid) {
2909
+ const declaration = encodePhantomBidDeclaration(bid);
2910
+ const sponsorship = bid.sponsorship;
2911
+ if (!sponsorship || sponsorship === "0x") return declaration;
2912
+ if (!isHex(sponsorship)) throw new Error("Phantom bid sponsorship is not hex");
2913
+ const bytes = hexToU8a(sponsorship);
2914
+ if (bytes.length !== PERMIT2_SPONSORSHIP_BYTES || !hasPermit2Sponsorship(bytes)) {
2915
+ throw new Error(
2916
+ `Phantom bid sponsorship must be a ${PERMIT2_SPONSORSHIP_BYTES}-byte Permit2-mode paymasterAndData, got ${bytes.length} bytes`
2917
+ );
2918
+ }
2919
+ return `${sponsorship}${declaration.slice(2)}`;
2920
+ }
2810
2921
  function encodeAcceptedSourceChains(chains) {
2811
2922
  return encodePhantomBidDeclaration({ acceptedSourceChains: chains });
2812
2923
  }
@@ -3217,7 +3328,7 @@ async function runAggregation(params, isDelegated) {
3217
3328
  continue;
3218
3329
  }
3219
3330
  countedSolvers.add(normalizedSolver);
3220
- const declaration = decodePhantomBidDeclaration(decoded.paymasterAndData);
3331
+ const { declaration } = decodePhantomBidPaymasterAndData(decoded.paymasterAndData);
3221
3332
  const acceptedSources = declaration.acceptedSources;
3222
3333
  const poolPriced = declaration.uniswapV4Positions.length > 0;
3223
3334
  const applyHaircut = (amount) => poolPriced ? applyUniswapQuoteHaircut(amount) : applyProtocolFeeHaircut(amount, protocolFeeHaircutBps);
@@ -3308,6 +3419,6 @@ async function runAggregation(params, isDelegated) {
3308
3419
  return { legs, lpBalances, positions: verifiedPositions, solvers: [...countedSolvers] };
3309
3420
  }
3310
3421
 
3311
- export { ENTRY_POINT_V08_ADDRESS, FILL_ORDER_ABI, FILL_ORDER_V1_ABI, IntentGatewayV2_default as IntentGatewayV2, UNISWAP_QUOTE_HAIRCUT_BPS, aggregatePhantomBids, applyProtocolFeeHaircut, applyUniswapQuoteHaircut, decodeAcceptedSourceChains, decodeERC7821ExecuteBatch, decodePhantomBidDeclaration, decodeUserOpScale, encodeAcceptedSourceChains, encodeERC7821ExecuteBatch, encodePhantomBidDeclaration, encodeUserOpScale, extractFillData, fetchBidsForOrder, getTotalSolverBalance, memoizedSolverBalance, orderCommitmentFromDecoded, poolSlug, positionAmountOfToken, readProtocolFeeHaircutBps, readV4Position, recoverBidSignerViem, setAggregationFetch, sortPoolSymbols, splitBidSignature, weightedMedian, zipFillLegs };
3422
+ export { ENTRY_POINT_V08_ADDRESS, FILL_ORDER_ABI, FILL_ORDER_V1_ABI, IntentGatewayV2_default as IntentGatewayV2, PERMIT2_SPONSORSHIP_BYTES, UNISWAP_QUOTE_HAIRCUT_BPS, aggregatePhantomBids, applyProtocolFeeHaircut, applyUniswapQuoteHaircut, decodeAcceptedSourceChains, decodeERC7821ExecuteBatch, decodePhantomBidDeclaration, decodePhantomBidPaymasterAndData, decodeUserOpScale, encodeAcceptedSourceChains, encodeERC7821ExecuteBatch, encodePhantomBidDeclaration, encodePhantomBidPaymasterAndData, encodeUserOpScale, extractFillData, fetchBidsForOrder, getTotalSolverBalance, memoizedSolverBalance, orderCommitmentFromDecoded, poolSlug, positionAmountOfToken, readProtocolFeeHaircutBps, readV4Position, recoverBidSignerViem, setAggregationFetch, sortPoolSymbols, splitBidSignature, weightedMedian, zipFillLegs };
3312
3423
  //# sourceMappingURL=intents-helpers.js.map
3313
3424
  //# sourceMappingURL=intents-helpers.js.map