@hyperbridge/sdk 2.8.10 → 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.
@@ -73,7 +73,7 @@ var ABI2 = [
73
73
  type: "constructor",
74
74
  inputs: [
75
75
  {
76
- name: "admin",
76
+ name: "owner",
77
77
  type: "address",
78
78
  internalType: "address"
79
79
  }
@@ -148,25 +148,6 @@ var ABI2 = [
148
148
  ],
149
149
  stateMutability: "view"
150
150
  },
151
- {
152
- type: "function",
153
- name: "_instances",
154
- inputs: [
155
- {
156
- name: "",
157
- type: "bytes32",
158
- internalType: "bytes32"
159
- }
160
- ],
161
- outputs: [
162
- {
163
- name: "",
164
- type: "address",
165
- internalType: "address"
166
- }
167
- ],
168
- stateMutability: "view"
169
- },
170
151
  {
171
152
  type: "function",
172
153
  name: "_nonce",
@@ -204,6 +185,19 @@ var ABI2 = [
204
185
  ],
205
186
  stateMutability: "view"
206
187
  },
188
+ {
189
+ type: "function",
190
+ name: "_owner",
191
+ inputs: [],
192
+ outputs: [
193
+ {
194
+ name: "",
195
+ type: "address",
196
+ internalType: "address"
197
+ }
198
+ ],
199
+ stateMutability: "view"
200
+ },
207
201
  {
208
202
  type: "function",
209
203
  name: "_partialFills",
@@ -619,6 +613,61 @@ var ABI2 = [
619
613
  ],
620
614
  stateMutability: "view"
621
615
  },
616
+ {
617
+ type: "function",
618
+ name: "initialize",
619
+ inputs: [
620
+ {
621
+ name: "p",
622
+ type: "tuple",
623
+ internalType: "struct Params",
624
+ components: [
625
+ {
626
+ name: "host",
627
+ type: "address",
628
+ internalType: "address"
629
+ },
630
+ {
631
+ name: "dispatcher",
632
+ type: "address",
633
+ internalType: "address"
634
+ },
635
+ {
636
+ name: "solverSelection",
637
+ type: "bool",
638
+ internalType: "bool"
639
+ },
640
+ {
641
+ name: "surplusShareBps",
642
+ type: "uint256",
643
+ internalType: "uint256"
644
+ },
645
+ {
646
+ name: "protocolFeeBps",
647
+ type: "uint256",
648
+ internalType: "uint256"
649
+ },
650
+ {
651
+ name: "priceOracle",
652
+ type: "address",
653
+ internalType: "address"
654
+ }
655
+ ]
656
+ },
657
+ {
658
+ name: "peerChains",
659
+ type: "bytes[]",
660
+ internalType: "bytes[]"
661
+ },
662
+ {
663
+ name: "relayer",
664
+ type: "address",
665
+ internalType: "address"
666
+ }
667
+ ],
668
+ outputs: [],
669
+ stateMutability: "nonpayable"
670
+ },
622
671
  {
623
672
  type: "function",
624
673
  name: "instance",
@@ -638,6 +687,19 @@ var ABI2 = [
638
687
  ],
639
688
  stateMutability: "view"
640
689
  },
690
+ {
691
+ type: "function",
692
+ name: "migrate",
693
+ inputs: [
694
+ {
695
+ name: "relayer",
696
+ type: "address",
697
+ internalType: "address"
698
+ }
699
+ ],
700
+ outputs: [],
701
+ stateMutability: "nonpayable"
702
+ },
641
703
  {
642
704
  type: "function",
643
705
  name: "onAccept",
@@ -1149,7 +1211,7 @@ var ABI2 = [
1149
1211
  internalType: "uint256"
1150
1212
  }
1151
1213
  ],
1152
- stateMutability: "view"
1214
+ stateMutability: "nonpayable"
1153
1215
  },
1154
1216
  {
1155
1217
  type: "function",
@@ -1205,6 +1267,19 @@ var ABI2 = [
1205
1267
  internalType: "uint256"
1206
1268
  }
1207
1269
  ],
1270
+ stateMutability: "nonpayable"
1271
+ },
1272
+ {
1273
+ type: "function",
1274
+ name: "relayer",
1275
+ inputs: [],
1276
+ outputs: [
1277
+ {
1278
+ name: "",
1279
+ type: "address",
1280
+ internalType: "address"
1281
+ }
1282
+ ],
1208
1283
  stateMutability: "view"
1209
1284
  },
1210
1285
  {
@@ -1245,66 +1320,67 @@ var ABI2 = [
1245
1320
  },
1246
1321
  {
1247
1322
  type: "function",
1248
- name: "init",
1323
+ name: "setRelayer",
1249
1324
  inputs: [
1250
1325
  {
1251
- name: "p",
1252
- type: "tuple",
1253
- internalType: "struct Params",
1254
- components: [
1255
- {
1256
- name: "host",
1257
- type: "address",
1258
- internalType: "address"
1259
- },
1260
- {
1261
- name: "dispatcher",
1262
- type: "address",
1263
- internalType: "address"
1264
- },
1265
- {
1266
- name: "solverSelection",
1267
- type: "bool",
1268
- internalType: "bool"
1269
- },
1270
- {
1271
- name: "surplusShareBps",
1272
- type: "uint256",
1273
- internalType: "uint256"
1274
- },
1275
- {
1276
- name: "protocolFeeBps",
1277
- type: "uint256",
1278
- internalType: "uint256"
1279
- },
1280
- {
1281
- name: "priceOracle",
1282
- type: "address",
1283
- internalType: "address"
1284
- }
1285
- ]
1326
+ name: "relayer",
1327
+ type: "address",
1328
+ internalType: "address"
1329
+ }
1330
+ ],
1331
+ outputs: [],
1332
+ stateMutability: "nonpayable"
1333
+ },
1334
+ {
1335
+ type: "function",
1336
+ name: "upgradeToAndCall",
1337
+ inputs: [
1338
+ {
1339
+ name: "newImplementation",
1340
+ type: "address",
1341
+ internalType: "address"
1286
1342
  },
1287
1343
  {
1288
- name: "deployments",
1289
- type: "tuple[]",
1290
- internalType: "struct Deployment[]",
1291
- components: [
1292
- {
1293
- name: "chain",
1294
- type: "bytes",
1295
- internalType: "bytes"
1296
- },
1297
- {
1298
- name: "gateway",
1299
- type: "address",
1300
- internalType: "address"
1301
- }
1302
- ]
1344
+ name: "data",
1345
+ type: "bytes",
1346
+ internalType: "bytes"
1303
1347
  }
1304
1348
  ],
1305
1349
  outputs: [],
1306
1350
  stateMutability: "nonpayable"
1307
1351
  },
1352
+ {
1353
+ type: "function",
1354
+ name: "version",
1355
+ inputs: [],
1356
+ outputs: [
1357
+ {
1358
+ name: "",
1359
+ type: "uint64",
1360
+ internalType: "uint64"
1361
+ }
1362
+ ],
1363
+ stateMutability: "view"
1364
+ },
1365
+ {
1366
+ type: "event",
1367
+ name: "DeploymentAdded",
1368
+ inputs: [
1369
+ {
1370
+ name: "chain",
1371
+ type: "string",
1372
+ indexed: false,
1373
+ internalType: "string"
1374
+ },
1375
+ {
1376
+ name: "gateway",
1377
+ type: "address",
1378
+ indexed: false,
1379
+ internalType: "address"
1380
+ }
1381
+ ],
1382
+ anonymous: false
1383
+ },
1308
1384
  {
1309
1385
  type: "event",
1310
1386
  name: "DestinationProtocolFeeUpdated",
@@ -1438,16 +1514,29 @@ var ABI2 = [
1438
1514
  },
1439
1515
  {
1440
1516
  type: "event",
1441
- name: "DeploymentAdded",
1517
+ name: "Initialized",
1442
1518
  inputs: [
1443
1519
  {
1444
- name: "chain",
1445
- type: "string",
1520
+ name: "version",
1521
+ type: "uint64",
1446
1522
  indexed: false,
1447
- internalType: "string"
1523
+ internalType: "uint64"
1524
+ }
1525
+ ],
1526
+ anonymous: false
1527
+ },
1528
+ {
1529
+ type: "event",
1530
+ name: "OrderCancelled",
1531
+ inputs: [
1532
+ {
1533
+ name: "commitment",
1534
+ type: "bytes32",
1535
+ indexed: true,
1536
+ internalType: "bytes32"
1448
1537
  },
1449
1538
  {
1450
- name: "gateway",
1539
+ name: "canceller",
1451
1540
  type: "address",
1452
1541
  indexed: false,
1453
1542
  internalType: "address"
@@ -1775,14 +1864,52 @@ var ABI2 = [
1775
1864
  ],
1776
1865
  anonymous: false
1777
1866
  },
1867
+ {
1868
+ type: "event",
1869
+ name: "RelayerUpdated",
1870
+ inputs: [
1871
+ {
1872
+ name: "previous",
1873
+ type: "address",
1874
+ indexed: false,
1875
+ internalType: "address"
1876
+ },
1877
+ {
1878
+ name: "current",
1879
+ type: "address",
1880
+ indexed: false,
1881
+ internalType: "address"
1882
+ }
1883
+ ],
1884
+ anonymous: false
1885
+ },
1886
+ {
1887
+ type: "event",
1888
+ name: "Upgraded",
1889
+ inputs: [
1890
+ {
1891
+ name: "implementation",
1892
+ type: "address",
1893
+ indexed: true,
1894
+ internalType: "address"
1895
+ }
1896
+ ],
1897
+ anonymous: false
1898
+ },
1778
1899
  {
1779
1900
  type: "error",
1780
- name: "Cancelled",
1781
- inputs: []
1901
+ name: "AddressEmptyCode",
1902
+ inputs: [
1903
+ {
1904
+ name: "target",
1905
+ type: "address",
1906
+ internalType: "address"
1907
+ }
1908
+ ]
1782
1909
  },
1783
1910
  {
1784
1911
  type: "error",
1785
- name: "UnknownInstance",
1912
+ name: "Cancelled",
1786
1913
  inputs: []
1787
1914
  },
1788
1915
  {
@@ -1812,11 +1939,37 @@ var ABI2 = [
1812
1939
  }
1813
1940
  ]
1814
1941
  },
1942
+ {
1943
+ type: "error",
1944
+ name: "ERC1967InvalidImplementation",
1945
+ inputs: [
1946
+ {
1947
+ name: "implementation",
1948
+ type: "address",
1949
+ internalType: "address"
1950
+ }
1951
+ ]
1952
+ },
1953
+ {
1954
+ type: "error",
1955
+ name: "ERC1967NonPayable",
1956
+ inputs: []
1957
+ },
1815
1958
  {
1816
1959
  type: "error",
1817
1960
  name: "Expired",
1818
1961
  inputs: []
1819
1962
  },
1963
+ {
1964
+ type: "error",
1965
+ name: "FailedCall",
1966
+ inputs: []
1967
+ },
1968
+ {
1969
+ type: "error",
1970
+ name: "FillExpired",
1971
+ inputs: []
1972
+ },
1820
1973
  {
1821
1974
  type: "error",
1822
1975
  name: "Filled",
@@ -1827,6 +1980,11 @@ var ABI2 = [
1827
1980
  name: "InsufficientNativeToken",
1828
1981
  inputs: []
1829
1982
  },
1983
+ {
1984
+ type: "error",
1985
+ name: "InvalidInitialization",
1986
+ inputs: []
1987
+ },
1830
1988
  {
1831
1989
  type: "error",
1832
1990
  name: "InvalidInput",
@@ -1842,6 +2000,21 @@ var ABI2 = [
1842
2000
  name: "NotExpired",
1843
2001
  inputs: []
1844
2002
  },
2003
+ {
2004
+ type: "error",
2005
+ name: "NotInitializing",
2006
+ inputs: []
2007
+ },
2008
+ {
2009
+ type: "error",
2010
+ name: "PartialFillNotAllowed",
2011
+ inputs: []
2012
+ },
2013
+ {
2014
+ type: "error",
2015
+ name: "ReentrancyGuardReentrantCall",
2016
+ inputs: []
2017
+ },
1845
2018
  {
1846
2019
  type: "error",
1847
2020
  name: "SafeERC20FailedOperation",
@@ -1879,6 +2052,11 @@ var ABI2 = [
1879
2052
  name: "UnexpectedCall",
1880
2053
  inputs: []
1881
2054
  },
2055
+ {
2056
+ type: "error",
2057
+ name: "UnknownInstance",
2058
+ inputs: []
2059
+ },
1882
2060
  {
1883
2061
  type: "error",
1884
2062
  name: "UnknownOrder",
@@ -2647,15 +2825,35 @@ function zipFillLegs(assets, outputs) {
2647
2825
  });
2648
2826
  }
2649
2827
  var UNISWAP_QUOTE_HAIRCUT_BPS = 10n;
2650
- var PHANTOM_QUOTE_HAIRCUT_BPS = 5n;
2651
2828
  function haircut(amount, bps) {
2652
2829
  return amount * (10000n - bps) / 10000n;
2653
2830
  }
2654
2831
  function applyUniswapQuoteHaircut(amount) {
2655
2832
  return haircut(amount, UNISWAP_QUOTE_HAIRCUT_BPS);
2656
2833
  }
2657
- function applyPhantomQuoteHaircut(amount) {
2658
- return haircut(amount, PHANTOM_QUOTE_HAIRCUT_BPS);
2834
+ var SELECTOR_GATEWAY_PARAMS = "0xcff0ab96";
2835
+ var GATEWAY_PARAMS_WORDS = 6;
2836
+ var GATEWAY_PARAMS_FEE_WORD = 4;
2837
+ async function readProtocolFeeHaircutBps(evmRpcUrl, gatewayAddress) {
2838
+ const result = await rpcCall(evmRpcUrl, {
2839
+ id: 1,
2840
+ jsonrpc: "2.0",
2841
+ method: "eth_call",
2842
+ params: [{ to: gatewayAddress, data: SELECTOR_GATEWAY_PARAMS }, "latest"]
2843
+ });
2844
+ const hex = result.result;
2845
+ if (typeof hex !== "string" || hex.length < 2 + 64 * GATEWAY_PARAMS_WORDS) {
2846
+ throw new PhantomRpcError(`IntentGateway.params() returned no usable result from ${gatewayAddress} on ${evmRpcUrl}`);
2847
+ }
2848
+ const start = 2 + 64 * GATEWAY_PARAMS_FEE_WORD;
2849
+ const protocolFeeBps = BigInt(`0x${hex.slice(start, start + 64)}`);
2850
+ if (protocolFeeBps >= 10000n) {
2851
+ throw new PhantomRpcError(`IntentGateway ${gatewayAddress} reports an implausible protocol fee: ${protocolFeeBps} bps`);
2852
+ }
2853
+ return protocolFeeBps;
2854
+ }
2855
+ function applyProtocolFeeHaircut(amount, protocolFeeBps) {
2856
+ return haircut(amount, protocolFeeBps);
2659
2857
  }
2660
2858
  function weightedMedian(entries) {
2661
2859
  const sorted = [...entries].sort((a, b) => a.price < b.price ? -1 : a.price > b.price ? 1 : 0);
@@ -2724,7 +2922,7 @@ var recoverBidSignerViem = async (userOp, entryPoint, chainId, solverSignature)
2724
2922
  }
2725
2923
  };
2726
2924
  var DELEGATION_INDICATOR_PREFIX = "0xef0100";
2727
- async function isDelegatedToSolverAccount(evmRpcUrl, account, solverAccount) {
2925
+ async function isDelegatedToSolverAccount(evmRpcUrl, account, solverAccounts) {
2728
2926
  const response = await rpcCall(evmRpcUrl, {
2729
2927
  id: 1,
2730
2928
  jsonrpc: "2.0",
@@ -2736,15 +2934,17 @@ async function isDelegatedToSolverAccount(evmRpcUrl, account, solverAccount) {
2736
2934
  }
2737
2935
  const code = response.result.toLowerCase();
2738
2936
  if (!code.startsWith(DELEGATION_INDICATOR_PREFIX)) return false;
2739
- return `0x${code.slice(DELEGATION_INDICATOR_PREFIX.length)}` === solverAccount.toLowerCase();
2937
+ const delegate = `0x${code.slice(DELEGATION_INDICATOR_PREFIX.length)}`;
2938
+ return solverAccounts.some((solverAccount) => solverAccount.toLowerCase() === delegate);
2740
2939
  }
2741
2940
  function memoizedDelegationCheck() {
2742
2941
  const cache = /* @__PURE__ */ new Map();
2743
- return (evmRpcUrl, account, solverAccount) => {
2744
- const key = `${evmRpcUrl}|${account.toLowerCase()}|${solverAccount.toLowerCase()}`;
2942
+ return (evmRpcUrl, account, solverAccounts) => {
2943
+ const targets = solverAccounts.map((a) => a.toLowerCase()).sort().join(",");
2944
+ const key = `${evmRpcUrl}|${account.toLowerCase()}|${targets}`;
2745
2945
  let pending = cache.get(key);
2746
2946
  if (!pending) {
2747
- pending = isDelegatedToSolverAccount(evmRpcUrl, account, solverAccount).catch((err) => {
2947
+ pending = isDelegatedToSolverAccount(evmRpcUrl, account, solverAccounts).catch((err) => {
2748
2948
  cache.delete(key);
2749
2949
  throw err;
2750
2950
  });
@@ -2764,7 +2964,7 @@ async function isVerifiedSolverBid(params) {
2764
2964
  commitment,
2765
2965
  sessionKey,
2766
2966
  chainId,
2767
- solverAccount,
2967
+ solverAccounts,
2768
2968
  evmRpcUrl,
2769
2969
  recoverSigner,
2770
2970
  bidNonceKey,
@@ -2793,8 +2993,8 @@ async function isVerifiedSolverBid(params) {
2793
2993
  logger?.warn({ solver, commitment, signer }, "Rejecting phantom bid: signature does not recover to the sender");
2794
2994
  return false;
2795
2995
  }
2796
- if (!await isDelegated(evmRpcUrl, solver, solverAccount)) {
2797
- logger?.warn({ solver, commitment, solverAccount }, "Rejecting phantom bid: sender is not a delegated solver");
2996
+ if (!await isDelegated(evmRpcUrl, solver, solverAccounts)) {
2997
+ logger?.warn({ solver, commitment, solverAccounts }, "Rejecting phantom bid: sender is not a delegated solver");
2798
2998
  return false;
2799
2999
  }
2800
3000
  return true;
@@ -2958,7 +3158,10 @@ async function aggregatePhantomBids(params) {
2958
3158
  }
2959
3159
  var AGGREGATION_ATTEMPTS = 5;
2960
3160
  async function runAggregation(params, isDelegated) {
2961
- const { nodeUrl, evmRpcUrls, chain, gatewayAddress, commitment, yieldVaults, solverAccount, logger } = params;
3161
+ const { nodeUrl, evmRpcUrls, chain, gatewayAddress, commitment, yieldVaults, logger } = params;
3162
+ const solverAccounts = (Array.isArray(params.solverAccount) ? params.solverAccount : [params.solverAccount]).filter(
3163
+ (a) => typeof a === "string" && a.length > 0
3164
+ );
2962
3165
  const extractFill = params.extractFill ?? extractFillData;
2963
3166
  const recoverSigner = params.recoverSigner ?? recoverBidSignerViem;
2964
3167
  const bidNonceKey = params.bidNonceKey ?? CryptoUtils.bidNonceKey;
@@ -2966,12 +3169,13 @@ async function runAggregation(params, isDelegated) {
2966
3169
  const destUrl = evmRpcUrls[chain];
2967
3170
  if (!destUrl) return null;
2968
3171
  const chainId = evmChainId(chain);
2969
- if (!solverAccount || chainId === null) {
3172
+ if (solverAccounts.length === 0 || chainId === null) {
2970
3173
  logger?.warn({ chain, commitment }, "Cannot verify phantom bids: no SolverAccount or chain id for chain");
2971
3174
  return null;
2972
3175
  }
2973
3176
  const bids = await fetchBidsForOrder(nodeUrl, commitment);
2974
3177
  if (bids.length === 0) return null;
3178
+ const protocolFeeHaircutBps = await readProtocolFeeHaircutBps(destUrl, gatewayAddress);
2975
3179
  const v4Contracts = params.uniswapV4?.[chain];
2976
3180
  const readPosition = memoizedV4Position(params.keccak ?? viem.keccak256, logger);
2977
3181
  const getBalance = params.getBalance ?? memoizedSolverBalance(yieldVaults);
@@ -3001,7 +3205,7 @@ async function runAggregation(params, isDelegated) {
3001
3205
  commitment,
3002
3206
  sessionKey,
3003
3207
  chainId,
3004
- solverAccount,
3208
+ solverAccounts,
3005
3209
  evmRpcUrl: destUrl,
3006
3210
  recoverSigner,
3007
3211
  bidNonceKey,
@@ -3018,7 +3222,7 @@ async function runAggregation(params, isDelegated) {
3018
3222
  const declaration = decodePhantomBidDeclaration(decoded.paymasterAndData);
3019
3223
  const acceptedSources = declaration.acceptedSources;
3020
3224
  const poolPriced = declaration.uniswapV4Positions.length > 0;
3021
- const applyHaircut = poolPriced ? applyUniswapQuoteHaircut : applyPhantomQuoteHaircut;
3225
+ const applyHaircut = (amount) => poolPriced ? applyUniswapQuoteHaircut(amount) : applyProtocolFeeHaircut(amount, protocolFeeHaircutBps);
3022
3226
  const quotedLegs = [...fillData.legs.entries()].map(([legIndex, leg]) => [
3023
3227
  legIndex,
3024
3228
  { ...leg, solverAmount: applyHaircut(leg.solverAmount) }
@@ -3110,10 +3314,9 @@ exports.ENTRY_POINT_V08_ADDRESS = ENTRY_POINT_V08_ADDRESS;
3110
3314
  exports.FILL_ORDER_ABI = FILL_ORDER_ABI;
3111
3315
  exports.FILL_ORDER_V1_ABI = FILL_ORDER_V1_ABI;
3112
3316
  exports.IntentGatewayV2 = IntentGatewayV2_default;
3113
- exports.PHANTOM_QUOTE_HAIRCUT_BPS = PHANTOM_QUOTE_HAIRCUT_BPS;
3114
3317
  exports.UNISWAP_QUOTE_HAIRCUT_BPS = UNISWAP_QUOTE_HAIRCUT_BPS;
3115
3318
  exports.aggregatePhantomBids = aggregatePhantomBids;
3116
- exports.applyPhantomQuoteHaircut = applyPhantomQuoteHaircut;
3319
+ exports.applyProtocolFeeHaircut = applyProtocolFeeHaircut;
3117
3320
  exports.applyUniswapQuoteHaircut = applyUniswapQuoteHaircut;
3118
3321
  exports.decodeAcceptedSourceChains = decodeAcceptedSourceChains;
3119
3322
  exports.decodeERC7821ExecuteBatch = decodeERC7821ExecuteBatch;
@@ -3130,6 +3333,7 @@ exports.memoizedSolverBalance = memoizedSolverBalance;
3130
3333
  exports.orderCommitmentFromDecoded = orderCommitmentFromDecoded;
3131
3334
  exports.poolSlug = poolSlug;
3132
3335
  exports.positionAmountOfToken = positionAmountOfToken;
3336
+ exports.readProtocolFeeHaircutBps = readProtocolFeeHaircutBps;
3133
3337
  exports.readV4Position = readV4Position;
3134
3338
  exports.recoverBidSignerViem = recoverBidSignerViem;
3135
3339
  exports.setAggregationFetch = setAggregationFetch;